indent

Peter Selinger selinger at mathstat.dal.ca
Fri Mar 9 01:21:21 EST 2007


I also recommend

  -T ExampleType

for every 'typedef', so that you get:

  example(int foo, char *bar, ExampleType *aligned_here)

and not

  example(int foo, char *bar, ExampleType * aligned_here)

-- Peter

David Hampton wrote:
> 
> There's been some discussion on IRC about using the indent program to
> reformat the sources into something consistent from file to file.  I'd
> like to propose the following options as a starting point for
> discussion.  I think some of these options will be agreed upon by all,
> and I'm sure others will be contentious.  :-)
> 
> Indentation
> 
> -nut    No tabs. Indentation is done with spaces.
> -i4     Add four spaces for each indent level
> -ci4    Continuation lines are indented by four spaces
> -cli4   Case labels are indented by four spaces
> -ppi4   Nested pre-processor defines are indented by four spaces
> -nbc    Do not force newlines after commas in declarations (default)
> -nbfda  Don´t put each argument in a function declaration
>         on a separate line (default)
> -lp     Line up continued lines at parentheses (default)
> -psl    Put the type of a procedure on the line before its name.
> -bbo    Prefer to break long lines before boolean operators.
> 
> Blank Lines
> 
> -nsob   Do not swallow optional blank lines (default)
> -bad    Force a blank line after a declaration.
> -bbb    Force a blank line before a block comment.
> -bap    Force blank lines after procedure bodies.
> 
> Comments
> 
> -fca    Reformat all comments except those starting in column 1
> -fc1    Reformat comments starting in column 1
> -sc     Continuation lines in a comments start with a '*'
> 
> Statements
> 
> -npcs   Do not put space after the function in function calls.
> -nprs   Do not put a space after every ´(´ and before every ´)´.
> 
> -ncs    Do not put a space after cast operators.
> -saf    Put a space after each for.
> -sai    Put a space after each if.
> -saw    Put a space after each while.
> 
> -brs    Put braces on struct declaration line.
> -br     Put braces on line with if, etc.
> -ce     Cuddle else and preceeding `}´.
> -cdw    Cuddle while of do {} while; and preceeding `}´.
> 
> Other
> 
> -l80    Line width of 80.
> 
> Attached is a small source file formatted with the above options.
> 
> Let the discussion begin. :-)
> 
> Of the above list of options, the ones I feel strongly about are lining
> up continued lines at parentheses (-lp), the space-after-keyword group
> (saf, -sai, -saw), and the cuddling-of-braces group (-br, -ce, -cdw).  I
> feel most strongly about this last group.  The parts of an if/then/else
> statement are clearly delineated by the indentation of the keywords vs.
> the indentation of the code blocks.  I believe it a complete waste to
> additionally add vertical separation my making the "else" take up three
> lines.  One for a closing parenthesis, one for the word "else", and one
> for an opening parenthesis.  Maybe that's just me.
> 
> What do the rest of the developers think?
> 
> David
>  
> 
> #ifdef A
> #    ifdef B
> #        define C
> #    else
> #        define D
> #    endif
> #else
> #    define E
> #endif
> 
> 
> /***
>  * *
>  ***/
> struct foo {
>     int i, j;
>     char *s;
> };
> 
> char *a;
> char *b;
> 
> /* kssf */
> char *g;
> 
> 
> /* 
>  * Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
>  * tempor incididunt ut labore et dolore magna aliqua.
>  . */
> static void
> example(int foo, char *bar, ExampleType * aligned_here)
> {
>     Foo *bar = { 1, "foo" };    /* lorem ipsum */
> 
>     for (int i = 0; i < 10; i++) {
>         if (is_is_a_reasonable_value(i)
>             && (i < 10 || i < 11)) {
>             // ...
>         } else {
>             break;
>         }
>     }
> 
>     this_is_a_long_function_name(and_this, function, has_a_very, large,
>                                  number_of, arguments);
> 
>     switch (foobar) {
>         case 0:
>             z = is_is_a_reasonable_value(i);
>             break;
>         default:
>             z = !is_is_a_reasonable_value(i);
>             break;
>     }
> 
>     while (TRUE) {
>         // ...
>     }
> 
>     do {
>         // ...
>     } while (TRUE);
> }
> 
> static void
> another_example(int and_this, char *function, ExampleType * has_a_very,
>                 char *large, double number_of, int arguments)
> {
> }


More information about the gnucash-devel mailing list