Search code examples
emacsalignment

Align to columns in emacs?


I have a .dat file which looks like this:

NGC0448 A3D:2010B g:o,r:o,i:o
NGC0474 A3D:2011A,2013A g:o,r:o,i:o,u:o

Now I want to align them to be in this form:

NGC0448    A3D:2010B          g:o,r:o,i:o
NGC0474    A3D:2011A,2013A    g:o,r:o,i:o,u:o

I tried with C-u M-X align and M-x align-regexp with= but neither works. Can someone come up with a solution?


Solution

  • Why did you try to align on = ?? There isn't a single = in that example text.

    Assuming your example is representative, you can align on the spaces. I'll use \s- (whitespace syntax) instead of an actual space, as the latter is harder to see.

    C-uM-x align-regexp RET

    • Complex align using regexp: \(\s-*\)\s-
    • Parenthesis group to modify (justify if negative): 1
    • Amount of spacing (or column if negative): 3
    • Repeat throughout line? (y or n) y