Emacs: Semi-automatic alignment of symbol: value pairs in Ruby and CoffeeScript
I like to keep my symbol value pairs aligned, like this:
# CoffeeScript
root:
key1: 1
otherKey: 'value'
To do that, I'd select the lines, then do C-u M-x align-regexp
, use :\(\s-*\)
as the regexp, hit <RET>
a couple of times, then n
. It turns out there is a much easier way. Add the following to your Emacs config:
(add-hook
'align-load-hook
(lambda ()
(add-to-list
'align-rules-list
'(symbol-value-alignment
(regexp . ":\\(\\s-*\\)")
(group . 1)
(modes . '(ruby-mode coffee-mode))
(repeat . nil)))))
Then, select the lines you want to align, and simply do M-x align
(or even better, bind that to a key combination).
Emacs' alignment facilities are really powerful. To learn more, see http://emacswiki.org/emacs/AlignCommands
Written by David Leal
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#