help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Aligning colums


From: Stefan Reichör
Subject: Re: Aligning colums
Date: 20 Jan 2005 21:16:13 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

roy@panix.com (Roy Smith) writes:

> I've got a bunch of text that looks like this:
> 
>        foo ("arg1", "xxxxxxxxxxxxxx", 1, "xxxx", 2)
>        foo ("arg1", "xxxxxxxxx", 1, "xxx", 2)
>        foo ("arg1", "xxxxxxxxxxx", 1, "xxxxxxxx", 2)
>        foo ("arg1", "xxxxxxxx", 1, "xxxxxx", 2)
>        foo ("arg1", "xxxxxxxxxx", 1, "xxxxxxx", 2)
> 
> I want to get the arguments lined up so it looks like:
> 
>        foo ("arg1", "xxxxxxxxxxxxxx",  1, "xxxx",       2)
>        foo ("arg1", "xxxxxxxxx",       1, "xxx",        2)
>        foo ("arg1", "xxxxxxxxxxx",     1, "xxxxxxxx",   2)
>        foo ("arg1", "xxxxxxxx",        1, "xxxxxx",     2)
>        foo ("arg1", "xxxxxxxxxx",      1, "xxxxxxx",    2)
> 
> What's the best way to do that?  I suspect M-X align is what I want, I
> can't make heads or tails out of the on-line help.
> 
> Note, the above text looks like C code, but I seem to run into things
> like this is various languages, not just C, so I'm looking for a
> general solution.

You could use my progr-align.el package:
www.xsteve.at/prg/emacs/progr-align.el

You specify a header line that matches the columns and the needed widths:

// #palign "\w" 4, "(\"\w+\"" 9, "\"" 19, "[0-9]+" 17, "[0-9]+"

Then you can put the cursor on a line or mark a region and call
M-x progr-align. That aligns the above code the way you wanted it.

Let me explain the #palign line:
"\w" matches foo, the column should be 4 characters wide
"(\"\w+\"" matches "arg1", columnwidth: 9 characters
"\"" matches "xxx", columnwidth: 19
"[0-9]+" matches 1, columnwidth: 17
"[0-9]+" matches 2, last column, no width needed


Stefan.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]