Subject: bug#4187: Bug with indentation / parens matching in C++-mode

From: Alan Mackenzie <[email-masked]>
Date: Fri, 21 Aug 2009 14:56:54 +0000

Hi, Tobias!

On Tue, Aug 18, 2009 at 02:04:21PM +0200, Tobias.Schlueter wrote:

> In GNU Emacs 21.4.1 (i686-redhat-linux-gnu, X toolkit, Xaw3d scroll bars)
>  of 2008-01-04 on norob.fnal.gov

OK, Emacs 21.4.  That's very old.  Emacs 22 was released in June 2007.
Emacs 23 was released a few weeks ago, on 30th July.  You could do worse
than upgrading (or persuading your sysadmins to upgrade).  Emacs 21
contained CC Mode 28, which is so old as to be barely supportable.  If
you can't upgrade your Emacs, you could certainly install a newer version
of CC Mode in one of your own directories (see
<http://cc-mode.sf.net/release.php>).

> Type the following into a buffer which is in C++ mode.

What version of CC Mode are you using (M-x c-version)?  Have you or
anybody else customised CC Mode at all?  It might well help to see your
complete CC Mode configuration (C-c C-b from within your C++ buffer,
followed by cutting and pasting).

> Try to get correct indentation for the second line of the while
> condition or the line following it by hitting the TAB key.  In my case
> this fails miserably.  Modifying the while condition to fix this
> behaves rather erratically, adding parentheses at least doesn't fix it.

Just as a suggestion, it might help things if you put a proper function
header before the opening "{".  It might not, though.

People's opinions differ on what "correct" indentation is, which is why
you can (and, sadly, MUST) configure it.  So could you please say how you
would like the line to be indented.

One thing you could do is, with point on the "&& count" line, C-c C-s.
This will give the syntactic analysis of the line, something like:

    Syntactic analysis: ((arglist-cont-nonempty 347 355))

.  This says "the line is a continued argument list whose "anchor points"
are at buffer positions 347 and 355".  This is explained in the CC Mode
manual in full detail.

Now try C-c C-o.  It will prompt you with something like:

    Syntactic symbol to change: arglist-cont-nonempty

, and when you hit <CR>, you'll get, say,:

    arglist-cont-nonempty offset (default (c-lineup-gcc-asm-reg c-lineup-arglist)):

, where you can type the new "offset" that you want.  Try entering "+",
or "++" or "*" or "-" here, just to get an idea of how this works.  Then
hit the <tab> key.  Again, the full details of all this stuff are in the
CC Mode manual.  I can give you better help once you've replied with the
details I've asked for.

> {
>   do {
>   } while (fabs(chi2 - oldChi2) > 0
>       && count < iterMax);
> x= 1;
> }

> You can reach me under [email-masked], I don't know if this
> interface will place the right sender address on the mail.

It didn't, but I have.  :-)  I've also directed your reply to
[email-masked], which is a more specific mailing list.

> I guess the stuff emacs put below will not be of much help, so I'm
> cutting it (recent input, the bug appears independent of my input).

Thanks!

> Cheers,
> - Tobias Schlüter

Schöne Grüße aus Nürnberg!

-- 
Alan Mackenzie.