all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Rafal Kurcz <pawlaczus@yahoo.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Indentation for "{" and "}"
Date: Sun, 29 Jul 2007 18:08:24 +0000	[thread overview]
Message-ID: <20070729180824.GC1955@muc.de> (raw)
In-Reply-To: <1185729825.415156.320980@g4g2000hsf.googlegroups.com>

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	other threads:[~2007-07-29 18:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-29 17:23 Indentation for "{" and "}" Rafal Kurcz
2007-07-29 18:08 ` Alan Mackenzie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070729180824.GC1955@muc.de \
    --to=acm@muc.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=pawlaczus@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.