unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* formatting function argument list
@ 2003-05-25 20:47 Timur Aydin
  2003-05-25 21:13 ` Benjamin Rutt
  0 siblings, 1 reply; 2+ messages in thread
From: Timur Aydin @ 2003-05-25 20:47 UTC (permalink / raw)



Hi,

There are many functions in our C/C++ source tree which have their
argument lists messed up in terms of formatting/alignment. Part of the
problem is that both tabs and spaces have been used. For example:

int func(   int                a,
          int        b,
           size_t c)
{
   /* Function body (currently fubar in terms of indentation) */
}

After marking the whole function and doing C-M-\, here is what I get:

int func(int                a,
         char        b,
         size_t c)
{
   /* Function body (nicely indented) */
}

The function body is formatted appropriately and all tabs are
gone. But the whitespace in the function argument list still needs to
be dealt with. Any suggestions on how to format it? Here are some
examples that I can think of:


/* All arguments in one line, one space between type and argument */
int func(int a, char b, size_t c)
{
   /* Function body (nicely indented) */
}

/* One argument per line, one space between type and argument */
int func(int a,
         char b,
         size_t c)
{
   /* Function body (nicely indented) */
}


/* One argument per line, arguments aligned. */
int func(int    a,
         char   b,
         size_t c)
{
   /* Function body (nicely indented) */
}

-- 
Timur Aydin

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: formatting function argument list
  2003-05-25 20:47 formatting function argument list Timur Aydin
@ 2003-05-25 21:13 ` Benjamin Rutt
  0 siblings, 0 replies; 2+ messages in thread
From: Benjamin Rutt @ 2003-05-25 21:13 UTC (permalink / raw)


Timur Aydin <ta@taydin.org> writes:

> /* All arguments in one line, one space between type and argument */
> int func(int a, char b, size_t c)
> {
>    /* Function body (nicely indented) */
> }

Nice, except it won't scale for many-argument functions.

[...]

> /* One argument per line, arguments aligned. */
> int func(int    a,
>          char   b,
>          size_t c)
> {
>    /* Function body (nicely indented) */
> }

This style can be achieved automagically if you M-x align the region.
Note:  once you start doing this, you will wish to use it everywhere.
Very addictive!
-- 
Benjamin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-05-25 21:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-25 20:47 formatting function argument list Timur Aydin
2003-05-25 21:13 ` Benjamin Rutt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).