6

Before Emacs 24.4, indentation in c-mode happened after typing things like ;, , and so on and I like this behavior.

But in Emacs 24.4, c-mode also indents on RET. This causes a lot of problems for me because if I want to insert a blank line, I need to press RET and then delete any spaces or tabs that electric- inserts.

So I would like to disable indent on RET, but keep all other electric-indent functionality, like indent on ;.

How can I achieve this?

I tried calling (electric-indent-local-mode -1) in c-mode hooks, but this disabled not only indent on RET, but also indent on ;, , and so on.

fghj
  • 193
  • 7
  • FWIW, the way I do it is that I hit RET either at the beginning of the next line, or at the of the previous line, depending on whether I just want to insert a blank line, or intend to actualy type text after thi RET. – Stefan Nov 07 '14 at 14:22
  • FWIW, the [news for release 24.4](http://www.gnu.org/software/emacs/news/NEWS.24.4) notes that `electric-indent-mode` is now enabled by default; `RET` now inserts a newline and indents, while `C-j` inserts a newline but does not indent (basically swapping the functionality of `RET` and `C-j` from previous versions). – Dan Nov 07 '14 at 14:36

3 Answers3

4

You could rebind RET to electric-indent-just-newline like this:

(add-hook 'c-mode-hook
          (lambda() (local-set-key (kbd "<RET>") 'electric-indent-just-newline)))
paprika
  • 1,944
  • 19
  • 26
4

You want to do:

 (add-hook 'c-mode-hook
           (lambda ()
             (setq-local electric-indent-chars
                         (remq ?\n electric-indent-chars))))
Stefan
  • 26,154
  • 3
  • 46
  • 84
0

Can't you simply use C-j to insert empty lines on Emacs 24.4?