Ads by Google

Friday, May 9, 2008

Aligning Text in Emacs Buffers

Surprisingly, I found this a bit hard to do. As an example, I wanted to align

4000 1 2
11 1 44
1 0000 999
as
4000 1 2
11 1 44
1 0000 999

After checking the documentation, I found that align.el is the built-in library that could be used. Trying it as M-x align on the marked text didn't work nor did the regexp option with [[:space:]]. Then I checked the emacswiki for alignment but didn't find an example there that worked with numbers.

Edited the wiki and posted the question and it was quickly answered. From the look of it, it appears that other methods are slightly easier than the solution provided. Especially table-insert function which can be quite easy to create and edit.

1 comment:

Paul Hobbs said...

There's also redshank mode, which has redshank-align-forms-as-columns, which does exactly what you want in this case, or would do s-expressions if you were editing lisp.

Redshank has a lot of other very powerful tools. Check out the screencast, it's there if you google it.