C/C++ for/while indentation change request

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

C/C++ for/while indentation change request

Lukas Ruf
Dear all,

to start with: maybe I have not found what I am looking for although
it already exists.

Often I make use of illustrative variable names to support me
re-reading my code later.  Intendation in vim, generally, works like a
charm however it does not im some circumstances.

What I would like to have changed in C/C++ indentation is how
parenthesises and their arguments are indented irrespective of their
context.  However, I do not know how to achieve that.

My rule of thumb:
- the opening and the closing parenthesises are
  at the same indentdation level as it works for the 'if' statement.
- indentation of the arguments ar indented by one (as in the 'if'
  statement).

Examples:

    /* what I would like for 'for', 'while' too */
      form1:              | form2:
    | if (condition1 &&   | if (
    |     condition2 ||   |     (
    |     condition3      |      condition1 &&
    |    )                |      condition2
    |                     |     )
    |                     |     ||
    |                     |     (
    |                     |      condition3 &&
    |                     |      condition4
    |                     |     )
    |                     |    )


with the 'for' statement, however,

      what I get:           what I want:
    | for (init;          |   for (init;
    |     endcondition;   |        endcondition;
    |     increment       |        increment
    |     )               |       )

alternative:
    | for (               | for (
    |     init;                  init;
    |     (               |      (
    |      condition1 &&  |       condition1 &&
    |      condition2     |       condition2
    |     )               |      )
    |     || condition3;  |      || condition3;
    |     end             |      end
    |     )               |     )

Thus, it is possible to configure the 'if'-mode of indentation for
'for' and 'while' too?

If so, where do I need to add which changes?  If not, does it require
a modification and re-compilation of vim due to the built-in
'cindent'?

I am using vim on Debian unstable:

  uccellina:cgiComment!85> vim --version
  VIM - Vi IMproved 6.3 (2004 June 7, compiled Sep  1 2005 16:58:37)
  Included patches: 1-86
  Compiled by Norbert Tretkowski <[hidden email]>

Thanks for any hint.

wbr,
Lukas
--
Lukas Ruf   <http://www.lpr.ch> | Ad Personam
rbacs      <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP   <http://www.rawip.org> | Low Level Network Programming
Style  <http://email.rawip.org> | How to write emails
Reply | Threaded
Open this post in threaded view
|

Re: C/C++ for/while indentation change request

Dominic Evans
'cinoptions' is what you want to be looking at.

Do :help cinoptions-values in vim :)

Best of luck,
Dom

On 05/09/05, Lukas Ruf <[hidden email]> wrote:

> Dear all,
>
> to start with: maybe I have not found what I am looking for although
> it already exists.
>
> Often I make use of illustrative variable names to support me
> re-reading my code later.  Intendation in vim, generally, works like a
> charm however it does not im some circumstances.
>
> What I would like to have changed in C/C++ indentation is how
> parenthesises and their arguments are indented irrespective of their
> context.  However, I do not know how to achieve that.
>
> My rule of thumb:
> - the opening and the closing parenthesises are
>   at the same indentdation level as it works for the 'if' statement.
> - indentation of the arguments ar indented by one (as in the 'if'
>   statement).
>
> Examples:
>
>     /* what I would like for 'for', 'while' too */
>       form1:              | form2:
>     | if (condition1 &&   | if (
>     |     condition2 ||   |     (
>     |     condition3      |      condition1 &&
>     |    )                |      condition2
>     |                     |     )
>     |                     |     ||
>     |                     |     (
>     |                     |      condition3 &&
>     |                     |      condition4
>     |                     |     )
>     |                     |    )
>
>
> with the 'for' statement, however,
>
>       what I get:           what I want:
>     | for (init;          |   for (init;
>     |     endcondition;   |        endcondition;
>     |     increment       |        increment
>     |     )               |       )
>
> alternative:
>     | for (               | for (
>     |     init;                  init;
>     |     (               |      (
>     |      condition1 &&  |       condition1 &&
>     |      condition2     |       condition2
>     |     )               |      )
>     |     || condition3;  |      || condition3;
>     |     end             |      end
>     |     )               |     )
>
> Thus, it is possible to configure the 'if'-mode of indentation for
> 'for' and 'while' too?
>
> If so, where do I need to add which changes?  If not, does it require
> a modification and re-compilation of vim due to the built-in
> 'cindent'?
>
> I am using vim on Debian unstable:
>
>   uccellina:cgiComment!85> vim --version
>   VIM - Vi IMproved 6.3 (2004 June 7, compiled Sep  1 2005 16:58:37)
>   Included patches: 1-86
>   Compiled by Norbert Tretkowski <[hidden email]>
>
> Thanks for any hint.
>
> wbr,
> Lukas
> --
> Lukas Ruf   <http://www.lpr.ch> | Ad Personam
> rbacs      <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
> Raw IP   <http://www.rawip.org> | Low Level Network Programming
> Style  <http://email.rawip.org> | How to write emails
>
Reply | Threaded
Open this post in threaded view
|

Re: C/C++ for/while indentation change request

Lukas Ruf
> Dominic Evans <[hidden email]> [2005-09-05 09:55]:
>
> 'cinoptions' is what you want to be looking at.
>
> Do :help cinoptions-values in vim :)
>

perfect!  Thanks.  I've started reading ;)

wbr,
Lukas
--
Lukas Ruf   <http://www.lpr.ch> | Ad Personam
rbacs      <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP   <http://www.rawip.org> | Low Level Network Programming
Style  <http://email.rawip.org> | How to write emails
Reply | Threaded
Open this post in threaded view
|

Re: C/C++ for/while indentation change request

Lukas Ruf
> Lukas Ruf <[hidden email]> [2005-09-05 13:00]:
>
> > Dominic Evans <[hidden email]> [2005-09-05 09:55]:
> >
> > 'cinoptions' is what you want to be looking at.
> >
> > Do :help cinoptions-values in vim :)
> >
>
> perfect!  Thanks.  I've started reading ;)
>

I read ..... and tried many combinations.....

what seems to solve my problems is the following setting:

  /* set cinoptions=(0,u0,w1 */
  for (
       i = 1;
       i < newPath->pathLength;
       i++
      ) ;

  if (foo &&
      bla ||
      (
       bar &&
       (
        !foo
       )
      )
     )

Thanks again!

wbr,
Lukas
--
Lukas Ruf   <http://www.lpr.ch> | Ad Personam
rbacs      <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP   <http://www.rawip.org> | Low Level Network Programming
Style  <http://email.rawip.org> | How to write emails
Reply | Threaded
Open this post in threaded view
|

Re: C/C++ for/while indentation change request

Lukas Ruf
> Lukas Ruf <[hidden email]> [2005-09-05 14:53]:
>
>
> what seems to solve my problems is the following setting:
>
>   /* set cinoptions=(0,u0,w1 */

sigh, I forgot: How can I configure brackets '[' ']'?  Reading
help 'cinoptions-values' has not helped me solving this problem.

Is it possible to configure analogously to the parentheses

    very_important_array
        [
         very_long_indexing_expression1 *
         very_long_indexing_expression2 +
         very_long_indexing_expression3
/*->     <- 2*shiftwidth + 1 */
        ]
/*->    <- 2*shiftwidth */

thanks for any further help!

wbr,
Lukas
--
Lukas Ruf   <http://www.lpr.ch> | Ad Personam
rbacs      <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP   <http://www.rawip.org> | Low Level Network Programming
Style  <http://email.rawip.org> | How to write emails