Erlang Alignment in Emacs

Just realized that the default align function in Emacs is quite capable. To indent, for example, a list of tuples with data, add the following alignment rule to your .emacs-file:

(add-hook 'align-load-hook
          (lambda ()
            (add-to-list 'align-rules-list
                         '(erlang-align
                           (regexp . ",\\(\\s-+\\)")
                           (repeat . t)
                           (modes quote (erlang-mode))))))

This will add a new alignment rule that aligns comma separated regions with whitespace. It will align all occurrences over all lines in the region, and only be enabled in the Erlang mode.

The alignment will transform this:

[{a, 19, "test", <<0,0>>},
 {abc, 2, "a", <<12,19,28,11>>}].

Into this:

[{a,   19, "test", <<0,0>>},
 {abc, 2,  "a",    <<12,19,28,11>>}].

I set it to Ctrl+E in my .emacs-file:

(global-set-key (read-kbd-macro "C-E") 'align)

I can also recommend the align-repeat macro from Align Commands on Emacs Wiki. I set it to Ctrl+Shift+E.

19 notes

Show

  1. wactbprot reblogged this from eproxus and added:
    see full post!
  2. eproxus posted this

Blog comments powered by Disqus