How do I turn off electrical indentation in RET, but still preserve other electrical characters (like "{)?

In Emacs 24.4, the default indentation behavior has been changed to automatically indent newlines. 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 electrical symbols, which is not what I intended.

Is there a way to disable the new behavior when there are characters like '{or': cause indentation?

+3


source to share


2 answers


You want to remove ?\n

from electric-indent-chars

. You can do it globally with:

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

      



or only in a specific mode (like C):

(add-hook 'c-mode-hook
          (lambda ()
            (setq-local electric-indent-chars (remq ?\n electric-indent-chars))))

      

+6


source


While checking the documentation for c-electric-brace

, I found that the behavior of electrical symbols is controlled by a local-buffer variable c-electric-flag

. It worked after I added the following lines to my file .emacs

:



(add-hook 'c-mode-hook
          (lambda ()
            (set 'c-electric-flag t)))

(add-hook 'c++-mode-hook
          (lambda ()
            (set 'c-electric-flag t)))

      

0


source







All Articles