Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs C++-mode incorrect indentation?

I'm running emacs 23 with c++-mode and having some indentation problems. Suppose I have this code:

void foo() {    if (cond)      { <---         int i;         ...      } <--- } 

This seems to be the default behavior of the automatic indentation. However I'd like to change it so it'll be like this:

void foo() {    if (cond)    {       int i;       ...    } } 

Is there a way to do this easily by configuring c++ mode or my .emacs file?

like image 465
Idan K Avatar asked Mar 19 '09 19:03

Idan K


1 Answers

I have the following in my .emacs file:

(defun my-c++-mode-hook ()   (setq c-basic-offset 4)   (c-set-offset 'substatement-open 0)) (add-hook 'c++-mode-hook 'my-c++-mode-hook) 

You can determine which offset to edit by hitting [ctrl-c ctrl-s] on any line. On the first line with a brace after the if it will say substatement-open.

like image 185
Alex B Avatar answered Sep 19 '22 18:09

Alex B