align C variable declarations in emacs without including * chars

advertisements

I like using align-current in emacs. For variable declarations it does this:

my_function(
    int         *foo,
    double     **pfoo,
    int          bar)
               ^
1234567890123456

(align-to-tab-stop is t, and c-basic-offset is 4)

But I'd prefer the variable names to be aligned to the tab stop, ignoring the pointer *'s, like this:

my_function(
    int       *foo,
    double   **pfoo,
    int        bar)
               ^
1234567890123456

I can't figure out how to change the c-variable-declaration alignment rule to get this. In my style the *'s are always next to the variable name, so it's ok for the solution to work only for that case. (And actually I want to do this for C++, so I want to ignore both *'s and `&'s.)


You can try variation of align-regexp. M-x align-entire should do.