help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Indentation for "{" and "}"


From: Alan Mackenzie
Subject: Re: Indentation for "{" and "}"
Date: Sun, 29 Jul 2007 18:08:24 +0000
User-agent: Mutt/1.5.9i

Hi, Rafal!

On Sun, Jul 29, 2007 at 10:23:45AM -0700, Rafal Kurcz wrote:
> Hello

> I want my C++ code to look as follows:

> void function()
> {
>   printf ( "hello" );
> }

> and not look as follows:

> void function()
>   {
>     pirntf ( "hello" );
>   }

The code above is formatted in "gnu" style, the default for the GNU
project and the default within Emacs.  No, I don't like it either.  ;-)
What you need to do is to change that style to one you like better (or,
in the extreme, to create your own style which is perfect.)

Put the following line in your .emacs, fairly early on (before any C
files can be loaded):

    (setq c-default-style "bsd")

This is described in the CC Mode manual on the page "Getting Started".
If "bsd" isn't quite your style, pick one of those listed on the page
"Built-in Styles".  It wouldn't do any harm to read the general stuff
about styles in the manual.  ;-)

You might find C-c . (that's "Control-C dot") useful for trying out
styles.

> I added the following setting to my ~/.emacs file:
> (global-set-key "\C-m" 'newline-and-indent)

> It works fine for all lines but "{".
> How to tell emacs not to indent the lines with "{" and "}"

That's got nothing to do with your "{ problem" (see above).  As a matter
of interest, you might find 'c-context-line-break a better binding for
<CR> in C Mode, since this does the Right Thing inside comments and
macros too.  This is also described in the CC Manual page "Getting
Started", but basically if you want this binding, put the following into
your .emacs early on:

    (defun my-make-CR-do-indent ()
      (define-key c-mode-base-map "\C-m" 'c-context-line-break))
    (add-hook 'c-initialization-hook 'my-make-CR-do-indent)
 
> Thanks for help

No problem!  Have fun!

-- 
Alan Mackenzie (Ittersbach, Germany).




reply via email to

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