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

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

Re: indent-region to indent comments


From: Peter Milliken
Subject: Re: indent-region to indent comments
Date: Thu, 11 Dec 2003 07:30:25 +1100

indent-region only works on indenting the beginnings of lines. It knows
nothing about comments on the end of lines or the contents of the lines
after the first character.

To achieve what you want, you need to use a lovely little utility called
align.el. Then you could get this:

int main(int argc, char **argv)
{
   int    a = 5;                // first comment
   double b = 5.0;              // second comment
   long   c = 3;                // third comment

   b = a + c;                   // so as not to get unused variable error

   return 0;
}

Note that the declarations are aligned as well :-) Align.el has tremendous
power and works off a set of relatively simple rules. You can create your
own alignment rules quite easily.

Peter




"Suhas Pai" <address@hidden> wrote in message
news:address@hidden
>
> If I mark a region and indent it, I find that it
> only idents the source lines and not the comment lines.
> If my comment-column is set, why the indenting skips
> comments?  This will save me ton of time having to
> do each one using "esc ;".  I could always write a macro
> but I don't know how to bind a macro to a key.
>
> Please help.
>
> Before:
> -------
>
> int main(int argc, char **argv)
> {
>    int a = 5;           // first comment
>    double b = 5.0;   // second comment
>    long c = 3;   // third comment
>    b = a + c; // so as not to get unused variable error
>
>    return 0;
> }
>
> Expect after ident-region:
> --------------------------
> int main(int argc, char **argv)
> {
>    int a = 5;         // first comment
>    double b = 5.0;    // second comment
>    long c = 3;        // third comment
>    b = a + c;         // so as not to get unused variable error
>
>    return 0;
> }
>
>
> Thanks,
> Suhas
>
>




reply via email to

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