Emacs: Auto Close Brackets, electric-pair-mode
electric-pair-mode
electric-pair-mode
- toggle auto insert of bracket pairs.
When on, typing any left bracket automatically insert the right matching bracket.
New in emacs 24. [see Emacs 24.1 Features (released 2012-06)]
To have it on always, Put this in your Emacs Init File:
;; auto close bracket insertion. New in emacs 24 (electric-pair-mode 1)
Brackets includes ASCII and Unicode brackets or quotation marks: " ' “” ‘’ () {} [] «» ‹› 「」 and more [see Matching Brackets in Unicode]
Deleting one bracket doesn't delete the other.
Exactly which brackets are auto-closed depends on the current Major Mode 's Syntax Table.
If you always want certain brackets be inserted in pairs, you can customize the variable electric-pair-pairs. Its value should be a Association List.
For example, the curly bracket {} isn't auto-closed when in emacs-lisp-mode
. You can make it do so, like this:
;; make electric-pair-mode work on more brackets (setq electric-pair-pairs '( (?\" . ?\") (?\{ . ?\})))