[Top][All Lists]

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

Re: ratliff indentation style, peculiar indentation of close brace

From: Alan Mackenzie
Subject: Re: ratliff indentation style, peculiar indentation of close brace
Date: Fri, 5 Aug 2016 18:59:30 +0000 (UTC)
User-agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.3-RELEASE-p4 (amd64))

Hello, Jim

Jim Newton <address@hidden> wrote:
> I'm working on an open source project which uses Ratliff style
> indentation for C++ code.  I'm not a particular fan but I want to obey
> the coding guidelines.  I don't find anything with a google search.
> Can emacs c++ indentation support this style.

Indeed it can, but you'll have to specify this style since it doesn't
currently exist in CC Mode.

> The curious thing about this style is that it aligns the close brace
> with the indentation as follows.

> while (something)
>     do_something();
>     do_something_else();
>     } ;; brace is commented like this.

I think there might be an opening brace missing in there, somewhere.  ;-)

> Does someone know of a way to make c++ indentation do this?

Please read the CC Mode manual, which has a vast section on configuring
indentation, and also a sample configuration on page "Sample .emacs File"
to help get you started.

Now go to line 4, and type C-c C-s.  This will display something like
"((block-close 40))", and will highlight (for up to 20 seconds) the
"anchor point" at buffer position 40.  You will notice that this is the
start of the "while" keyword.

Now do C-c C-o on the line, interactively to change the "offset" for the
"syntactic symbol" block-close.  Following the prompts, replace the
offset "0" with "+" (all without the quote marks).  Typing <tab> on the
line to indent it should now do what you want.

You will now want to configure that permanently so that you don't need to
go through all of that each time you start Emacs.  I would recommend you
to create a CC Mode "ratliff style" by inheriting from, say, "k&r" style,
then setting the "offset" for block-close with a line something like:

    (c-offsets-alist    .  ((block-close . +)))

in the appropriate place in the style definition (see the "Sample .emacs
File" page in the CC Mode manual, also other pages like "Adding Styles").

Having got that done, you might want to set up auto-newline, so that, for
example, typing a closing brace after "do_something_else();" would
automatically insert a newline and indent the brace correctly.
Incidentally, I don't use this, it drives me crazy, but some people like

> Thanks if anyone can help.

If anything remains unclear, just ask again.  Best of luck!

Alan Mackenzie (Nuremberg, Germany).

reply via email to

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