all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ratliff indentation style, peculiar indentation of close brace
@ 2016-08-04 14:49 Jim Newton
  2016-08-05 18:59 ` Alan Mackenzie
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Newton @ 2016-08-04 14:49 UTC (permalink / raw)
  To: help-gnu-emacs

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.

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.


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

Thanks if anyone can help.


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

* Re: ratliff indentation style, peculiar indentation of close brace
  2016-08-04 14:49 ratliff indentation style, peculiar indentation of close brace Jim Newton
@ 2016-08-05 18:59 ` Alan Mackenzie
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Mackenzie @ 2016-08-05 18:59 UTC (permalink / raw)
  To: help-gnu-emacs

Hello, Jim

Jim Newton <jimka.issy@gmail.com> 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
it.

> Thanks if anyone can help.

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

-- 
Alan Mackenzie (Nuremberg, Germany).



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

end of thread, other threads:[~2016-08-05 18:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-04 14:49 ratliff indentation style, peculiar indentation of close brace Jim Newton
2016-08-05 18:59 ` Alan Mackenzie

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.