Set the variable
c-basic-offset. See Getting Started.
Emacs's convention is that RET just adds a newline, and that
C-j adds a newline and indents it. You can make RET do this
too by adding this to your
(define-key c-mode-base-map "\C-m" 'c-context-line-break)
See Getting Started. This is a very common question. If you want this to be the default behavior, don't lobby us, lobby RMS! :-)
Deactivate “electric minor mode” with C-c C-l. See Getting Started.
Visit the file and hit C-x h to mark the whole buffer. Then hit C-M-\. See Indentation Commands.
First move to the brace which opens the block with C-M-u, then reindent that expression with C-M-q. See Indentation Commands.
(c-set-offset 'substatement-open 0)in my .emacs file but I get an error saying that
c-set-offset's function definition is void. What's wrong?
This means that CC Mode hasn't yet been loaded into your Emacs
session by the time the
c-set-offset call is reached, most
likely because CC Mode is being autoloaded. Instead of putting the
c-set-offset line in your top-level .emacs file, put it
c-initialization-hook (see CC Hooks), or simply
(setq c-offsets-alist '((substatement-open . 0)))
It's due to the ad-hoc rule in (X)Emacs that such open parens always start defuns (which translates to functions, classes, namespaces or any other top-level block constructs in the CC Mode languages). See Left Margin Paren, for details (See Defuns, in the Emacs 20 manual).
This heuristic is built into the core syntax analysis routines in (X)Emacs, so it's not really a CC Mode issue. However, in Emacs 21.1 it became possible to turn it off1 and CC Mode does so there since it's got its own system to keep track of blocks.
 Using the variable