Emacs returns to the indentation of the line of code when it presses the return key

I am using emacs 22.2.1 and Ubuntu 9.04

I did this in a .emacs file. Which indents and creates a new line every time I press ';' or '{}'

if(success == 0) { printf("Success\n"); <---- if I press return key here it will go <-- to here, and I have to tab to go to the code line. 

However, if I press the return key, this will lead me to column 0, and not to the indentation input line that I am working on ie

 (require 'cc-mode) ;; Auto indent on insertion of a curly brace (add-hook 'c-mode-hook '(lambda() (c-toggle-auto-state t))) ;; Set coding style to indent 4 spaces (setq c-default-style "bsd" c-basic-offset 4) 
+4
source share
2 answers
 (add-hook 'c-mode-hook '(lambda () (define-key c-mode-map "\Cm" 'newline-and-indent))) 

cards are returned to a new line + indent. Or, if you want, you can make it a habit to inject Cj instead of returning, since Cj is already mapped to this function.

+9
source

Way to find it

  • know that Cj does what you want
  • use Ch k Cj to find out that Cj maps to newline-and-indent
  • Find updated keys in EMACS information.
+2
source

All Articles