Function: electric-pair-mode
electric-pair-mode is an autoloaded, interactive and byte-compiled
function defined in elec-pair.el.gz.
Signature
(electric-pair-mode &optional ARG)
Documentation
Toggle automatic parens pairing (Electric Pair mode).
Electric Pair mode is a global minor mode. When enabled, typing an open parenthesis automatically inserts the corresponding closing parenthesis, and vice versa. (Likewise for brackets, etc.). If the region is active, the parentheses (brackets, etc.) are inserted around the region instead.
To toggle the mode in a single buffer, use electric-pair-local-mode.
This is a global minor mode. If called interactively, toggle the
Electric-Pair mode mode. If the prefix argument is positive,
enable the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is toggle. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate (default-value \=electric-pair-mode)'.
The mode's hook is called both when the mode is enabled and when it is disabled.
Probably introduced at or before Emacs version 24.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/elec-pair.el.gz
;;;###autoload
(define-minor-mode electric-pair-mode
"Toggle automatic parens pairing (Electric Pair mode).
Electric Pair mode is a global minor mode. When enabled, typing
an open parenthesis automatically inserts the corresponding
closing parenthesis, and vice versa. (Likewise for brackets, etc.).
If the region is active, the parentheses (brackets, etc.) are
inserted around the region instead.
To toggle the mode in a single buffer, use `electric-pair-local-mode'."
:global t :group 'electricity
(if electric-pair-mode
(progn
(add-hook 'post-self-insert-hook
#'electric-pair-post-self-insert-function
;; Prioritize this to kick in after
;; `electric-layout-post-self-insert-function': that
;; considerably simplifies interoperation when
;; `electric-pair-mode', `electric-layout-mode' and
;; `electric-indent-mode' are used together.
;; Use `vc-region-history' on these lines for more info.
50)
(add-hook 'post-self-insert-hook
#'electric-pair-open-newline-between-pairs-psif
50)
(add-hook 'self-insert-uses-region-functions
#'electric-pair-will-use-region))
(remove-hook 'post-self-insert-hook
#'electric-pair-post-self-insert-function)
(remove-hook 'post-self-insert-hook
#'electric-pair-open-newline-between-pairs-psif)
(remove-hook 'self-insert-uses-region-functions
#'electric-pair-will-use-region)))