Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable electric indent on RET but still keep other electric characters (e.g., ‘{’)?

In Emacs 24.4, the default indentation behavior has been changed—new lines are now automatically indented. From the release notes:

*** `electric-indent-mode' is now enabled by default.
Typing RET reindents the current line and indents the new line.
`C-j' inserts a newline but does not indent.  In some programming modes,
additional characters are electric (eg `{').

I prefer the old behavior, so I added

(electric-indent-mode 0)

to my .emacs file. However, this disables all electric characters, which is not what I intended.

Is there any way to disable the new behavior while still having characters like ‘{’ or ‘:’ trigger an indentation?

like image 311
user3426575 Avatar asked Mar 18 '23 19:03

user3426575


1 Answers

You want to remove ?\n from electric-indent-chars. You can do this globally with:

(setq electric-indent-chars (remq ?\n electric-indent-chars))

or only in a particular mode (e.g. C):

(add-hook 'c-mode-hook
          (lambda ()
            (setq-local electric-indent-chars (remq ?\n electric-indent-chars))))
like image 72
Stefan Avatar answered Apr 25 '23 07:04

Stefan