all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Indentation for "{" and "}"
@ 2007-07-29 17:23 Rafal Kurcz
  2007-07-29 18:08 ` Alan Mackenzie
  0 siblings, 1 reply; 2+ messages in thread
From: Rafal Kurcz @ 2007-07-29 17:23 UTC (permalink / raw)
  To: help-gnu-emacs

Hello

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

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

and not look as follows:

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

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 "}"

Thanks for help

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

* Re: Indentation for "{" and "}"
  2007-07-29 17:23 Indentation for "{" and "}" Rafal Kurcz
@ 2007-07-29 18:08 ` Alan Mackenzie
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Mackenzie @ 2007-07-29 18:08 UTC (permalink / raw)
  To: Rafal Kurcz; +Cc: help-gnu-emacs

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).

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

end of thread, other threads:[~2007-07-29 18:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-29 17:23 Indentation for "{" and "}" Rafal Kurcz
2007-07-29 18:08 ` 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.