Emacs Electric Characters

Created: Mar 7 2025, 20:04 UTC
Last modified: Mar 8 2025, 11:48 UTC

Emacs

Electric characters are characters that trigger a newline and an indent when you type them in, like an opening brace or a semicolon.

You used to have to configure CC mode in emacs to get electric characters, but in emacs 24.1 they introduced electric-indent-mode which I think works with all sorts of text languages?

The electric characters in electric-indent-mode will indent the current line once typed.

Use electric-indent-chars to control which characters count as electric, like this:

(setq electric-indent-chars '(?\n ?;))

The question mark will quote the character as a literal.

Pair this with electric-pair-mode which will inserts pair of certain characters, like brackets.