emacs 24 feature: electric-pair-mode

Perm URL with updates: http://xahlee.org/emacs/emacs24_features.html


new minor mode electric-pair-mode. When on, typing any left bracket automatically insert the right matching bracket. Brackets includes the ASCII ones: "double" 'single' () {} [], but also any unicode ones: «» ‹› “curly” ‘single’ 「」 『』 〈〉 《》 〔〕 【】…. (➲ Matching Brackets in Unicode)

Deleting one bracket doesn't delete the other. (If you want that, install autopairs package. (➲ A Guide on Emacs Package System))

Exactly which brackets are auto-closed depends on the current major mode's syntax table. (You can call describe-syntax to see current syntax table. (info "(elisp) Syntax Tables"))

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 (i.e. a list of cons pairs. (info "(elisp) Association Lists")).

For example, the curly bracket {} isn't auto-closed when in emacs-lisp-mode. But if you put the following in your emacs init:

;; setting for auto-close brackets for electric-pair-mode regardless of current major mode syntax table
(setq electric-pair-pairs '(
                            (?\" . ?\")
                            (?\{ . ?\})
                            ) )

Now, {} will always be auto-closed.

See also:

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs