Improve Electric Pair mode documentation (bug#78021)

* doc/emacs/programs.texi (Matching): Clarify and improve
documentation of Electric Pair mode.

* lisp/elec-pair.el: Improve description in header line.  Add text
and a reference to the Emacs user manual in the Commentary section.
(electric-pair-skip-self, electric-pair-inhibit-predicate)
(electric-pair-preserve-balance)
(electric-pair-delete-adjacent-pairs)
(electric-pair-open-newline-between-pairs)
(electric-pair-skip-whitespace)
(electric-pair-skip-whitespace-function)
(electric-pair-analyze-conversion)
(electric-pair--skip-whitespace)
(electric-pair-text-syntax-table, electric-pair--with-syntax)
(electric-pair-syntax-info, electric-pair--insert)
(electric-pair--syntax-ppss, electric-pair--balance-info)
(electric-pair-inhibit-if-helps-balance)
(electric-pair-skip-if-helps-balance)
(electric-pair-open-newline-between-pairs-psif)
(electric-pair-mode): Clarify and improve doc strings and some comments.
(electric-pair-post-self-insert-function): Restructure doc string
to shorten overlong first line, and reformat overlong lines of code.
This commit is contained in:
Stephen Berman 2025-05-10 16:25:05 +02:00
parent 0d493864ce
commit bb73533165
2 changed files with 177 additions and 102 deletions

View file

@ -1063,52 +1063,95 @@ nonblank line.
@cindex Electric Pair mode @cindex Electric Pair mode
@cindex inserting matching parentheses @cindex inserting matching parentheses
@findex electric-pair-mode @findex electric-pair-mode
Electric Pair mode, a global minor mode, provides a way to easily Electric Pair mode is a minor mode that provides a way to easily
insert matching delimiters: parentheses, braces, brackets, etc. insert pairs of matching delimiters: parentheses, braces, brackets,
Whenever you insert an opening delimiter, the matching closing delimiter quotes, etc.@: (what counts as matching delimiters depends on the major
is automatically inserted as well, leaving point between the two. mode). To toggle Electric Pair mode globally, type @w{@kbd{M-x
However, if you insert a closing delimiter where one already exists electric-pair-mode}}. To toggle it only in the current buffer, type
(probably a mistake, since typing the opening delimiter inserted the @w{@kbd{M-x electric-pair-local-mode}}.
closing one for you), Emacs simply moves point to after the closing
delimiter, skipping the insertion. If the region is active
(@pxref{Mark}), insertion of a delimiter operates on the region: the
characters in the region are enclosed in a pair of matching delimiters,
leaving point after the delimiter you typed. If you provide a prefix
argument when inserting a delimiter, the numeric value of that prefix
argument specifies the number of pairs to insert.
These variables control additional features of Electric Pair mode: When this mode is enabled, typing an opening delimiter inserts both
that character and, immediately following it, the matching closing
delimiter, leaving point between the two. This makes it unnecessary to
type a matching closing delimiter in most cases. If you type one
nonetheless, Emacs simply inserts that character, unless point is
immediately before a closing delimiter of the same type; in that case,
point moves to immediately after the closing delimiter and no additional
closing delimiter is inserted. Thus, typing the sequence <opening
delimiter>, <matching closing delimiter> is a perhaps more convenient
alternative to the sequence <opening delimiter>, @kbd{C-f}.
With an active region (@pxref{Mark}), Electric Pair mode operates
differently: inserting either an opening or a closing delimiter encloses
the characters in the region within the resulting pair of matching
delimiters, leaving point after the delimiter you typed (this
facilitates continuing to type either before the text following the
opening delimiter or after the closing delimiter).
There are several user options for modifying the behavior of Electric
Pair mode:
@itemize @bullet @itemize @bullet
@item @item
@vindex electric-pair-preserve-balance @vindex electric-pair-preserve-balance
@code{electric-pair-preserve-balance}, when non-@code{nil}, makes the @code{electric-pair-preserve-balance}, when non-@code{nil} (the
default pairing logic balance out the number of opening and closing default), makes typing a delimiter preserve the balance between opening
delimiters. and closing delimiters. Thus, if you type an opening delimiter and
there is an unpaired matching closing delimiter later in the buffer,
then only the opening delimiter gets inserted (and not a matching
closing delimiter immediately following it); likewise, if there is an
unpaired opening delimiter, then typing a matching closing delimiter
later in the buffer inserts this character even when the following
character is another matching closing delimiter.
When set to @code{nil}, typing an opening delimiter inserts only this
character, but only when point is either immediately before or
immediately after a matching opening delimiter, or immediately before a
letter or digit; in all other positions inserting an opening delimiter
automatically inserts a matching closing delimiter immediately following
it, even if there is an unpaired matching closing delimiter later in the
buffer. And typing a closing delimiter immediately before another
closing delimiter of the same type does not insert that character but
moves point as described above, even when there is an unpaired matching
opening delimiter earlier in the buffer.
If there is an active region, this variable has no effect.
@item @item
@vindex electric-pair-delete-adjacent-pairs @vindex electric-pair-delete-adjacent-pairs
@code{electric-pair-delete-adjacent-pairs}, when non-@code{nil}, makes @code{electric-pair-delete-adjacent-pairs}, when non-@code{nil} (the
backspacing between two adjacent delimiters also automatically delete default), makes deleting an opening delimiter by typing the @key{DEL}
the closing delimiter. key (which is normally the @key{BACKSPACE} key; @pxref{DEL Does Not
Delete}) automatically also delete an immediately following matching
closing delimiter (but not if there are any characters---including just
whitespace---between the paired delimiters). When set to @code{nil},
typing @key{BACKSPACE} deletes only the opening delimiter. (Typing
@key{BACKSPACE} to delete a closing delimiter always deletes only this
character.)
@item @item
@vindex electric-pair-open-newline-between-pairs @vindex electric-pair-open-newline-between-pairs
@code{electric-pair-open-newline-between-pairs}, when non-@code{nil}, When @code{electric-pair-open-newline-between-pairs} is non-@code{nil}
makes inserting a newline between two adjacent pairs also (the default) and point is between an opening delimiter and an
automatically open an extra newline after point. immediately following matching closing delimiter, then typing a newline
automatically inserts an extra newline after point (possibly indenting
the empty line point is on, depending on the major mode). When set to
@code{nil}, typing a newline inserts only one newline before point, as
usual.
@item @item
@vindex electric-pair-skip-whitespace @vindex electric-pair-skip-whitespace
@code{electric-pair-skip-whitespace}, when non-@code{nil}, causes the minor When @code{electric-pair-skip-whitespace} has its default non-@code{nil}
mode to skip whitespace forward before deciding whether to skip over value and point is separated from a closing delimiter only by
the closing delimiter. whitespace, then typing a closing delimiter of the same type does not
insert that character but instead moves point to immediately after the
already present closing delimiter. You can also set this option to
additionally delete any whitespace that point moves over. When set to
@code{nil}, typing a closing delimiter simply inserts that character
(even when this makes the following closing delimiter of the same type
unbalanced).
@end itemize @end itemize
To toggle Electric Pair mode, type @kbd{M-x electric-pair-mode}. To
toggle the mode in a single buffer, use @kbd{M-x
electric-pair-local-mode}.
@node Comments @node Comments
@section Manipulating Comments @section Manipulating Comments
@cindex comments @cindex comments

View file

@ -1,4 +1,4 @@
;;; elec-pair.el --- Automatic parenthesis pairing -*- lexical-binding:t -*- ;;; elec-pair.el --- Automatically insert matching delimiters -*- lexical-binding:t -*-
;; Copyright (C) 2013-2025 Free Software Foundation, Inc. ;; Copyright (C) 2013-2025 Free Software Foundation, Inc.
@ -21,6 +21,11 @@
;;; Commentary: ;;; Commentary:
;; This library provides a way to easily insert pairs of matching
;; delimiters (parentheses, braces, brackets, quotes, etc.) and
;; optionally preserve or override the balance of delimiters. It is
;; documented in the Emacs user manual node "(emacs) Matching".
;;; Code: ;;; Code:
(require 'electric) (require 'electric)
@ -59,15 +64,16 @@ defined in `electric-pair-text-syntax-table'."
(defcustom electric-pair-skip-self #'electric-pair-default-skip-self (defcustom electric-pair-skip-self #'electric-pair-default-skip-self
"If non-nil, skip char instead of inserting a second closing paren. "If non-nil, skip char instead of inserting a second closing paren.
When inserting a closing paren character right before the same character, When inserting a closing delimiter right before the same character, just
just skip that character instead, so that hitting ( followed by ) results skip that character instead, so that, for example, consecutively
in \"()\" rather than \"())\". typing `(' and `)' results in \"()\" rather than \"())\".
This can be convenient for people who find it easier to hit ) than \\[forward-char]. This can be convenient for people who find it easier to type `)' than
\\[forward-char].
Can also be a function of one argument (the closer char just Can also be a function of one argument (the closing delimiter just
inserted), in which case that function's return value is inserted), in which case that function's return value is considered
considered instead." instead."
:version "24.1" :version "24.1"
:group 'electricity :group 'electricity
:type '(choice :type '(choice
@ -80,9 +86,9 @@ considered instead."
#'electric-pair-default-inhibit #'electric-pair-default-inhibit
"Predicate to prevent insertion of a matching pair. "Predicate to prevent insertion of a matching pair.
The function is called with a single char (the opening char just inserted). The function is called with a single char (the opening delimiter just
If it returns non-nil, then `electric-pair-mode' will not insert a matching inserted). If it returns non-nil, then `electric-pair-mode' will not
closer." insert a matching closing delimiter."
:version "24.4" :version "24.4"
:group 'electricity :group 'electricity
:type '(choice :type '(choice
@ -92,22 +98,32 @@ closer."
function)) function))
(defcustom electric-pair-preserve-balance t (defcustom electric-pair-preserve-balance t
"Non-nil if default pairing and skipping should help balance parentheses. "Whether to keep matching delimiters balanced.
When non-nil, typing a delimiter inserts only this character if there is
a unpaired matching delimiter later (if the latter is a closing
delimiter) or earlier (if the latter is a opening delimiter) in the
buffer. When nil, inserting a delimiter disregards unpaired matching
delimiters.
The default values of `electric-pair-inhibit-predicate' and Whether this variable takes effect depends on the variables
`electric-pair-skip-self' check this variable before delegating to other `electric-pair-inhibit-predicate' and `electric-pair-skip-self', which
predicates responsible for making decisions on whether to pair/skip some check the value of this variable before delegating to other predicates
characters based on the actual state of the buffer's parentheses and responsible for making decisions on whether to pair/skip some characters
quotes." based on the actual state of the buffer's delimiters. In addition, this
variable has no effect if there is an active region."
:version "24.4" :version "24.4"
:group 'electricity :group 'electricity
:type 'boolean) :type 'boolean)
(defcustom electric-pair-delete-adjacent-pairs t (defcustom electric-pair-delete-adjacent-pairs t
"If non-nil, backspacing an open paren also deletes adjacent closer. "Whether to automatically delete a matching delimiter.
If non-nil, then when an opening delimiter immediately precedes a
matching closing delimiter and point is between them, typing DEL (the
backspace key) deletes both delimiters. If nil, only the opening
delimiter is deleted.
Can also be a function of no arguments, in which case that function's The value of this variable can also be a function of no arguments, in
return value is considered instead." which case that function's return value is considered instead."
:version "24.4" :version "24.4"
:group 'electricity :group 'electricity
:type '(choice :type '(choice
@ -116,10 +132,14 @@ return value is considered instead."
function)) function))
(defcustom electric-pair-open-newline-between-pairs t (defcustom electric-pair-open-newline-between-pairs t
"If non-nil, a newline between adjacent parentheses opens an extra one. "Whether to insert an extra newline between matching delimiters.
If non-nil, then when an opening delimiter immediately precedes a
matching closing delimiter and point is between them, typing a newline
automatically inserts an extra newline after point. If nil, just one
newline is inserted before point.
Can also be a function of no arguments, in which case that function's The value of this variable can also be a function of no arguments, in
return value is considered instead." which case that function's return value is considered instead."
:version "24.4" :version "24.4"
:group 'electricity :group 'electricity
:type '(choice :type '(choice
@ -128,16 +148,19 @@ return value is considered instead."
function)) function))
(defcustom electric-pair-skip-whitespace t (defcustom electric-pair-skip-whitespace t
"If non-nil skip whitespace when skipping over closing parens. "Whether typing a closing delimiter moves point over whitespace.
If non-nil and point is separated from a closing delimiter only by
whitespace, then typing a closing delimiter of the same type does not
insert that character but instead moves point to immediately after the
already present closing delimiter. If the value of this variable is set
tothe symbol `chomp', then the whitespace moved over is deleted. If the
value is nil, typing a closing delimiter simply inserts it at point.
The specific kind of whitespace skipped is given by the variable The specific kind of whitespace skipped is given by the variable
`electric-pair-skip-whitespace-chars'. `electric-pair-skip-whitespace-chars'.
The symbol `chomp' specifies that the skipped-over whitespace The value of this variable can also be a function of no arguments, in
should be deleted. which case that function's return value is considered instead."
Can also be a function of no arguments, in which case that function's
return value is considered instead."
:version "24.4" :version "24.4"
:group 'electricity :group 'electricity
:type '(choice :type '(choice
@ -157,16 +180,16 @@ return value is considered instead."
(defvar-local electric-pair-skip-whitespace-function (defvar-local electric-pair-skip-whitespace-function
#'electric-pair--skip-whitespace #'electric-pair--skip-whitespace
"Function to use to skip whitespace forward. "Function to use to move point forward over whitespace.
Before attempting a skip, if `electric-pair-skip-whitespace' is Before attempting a skip, if `electric-pair-skip-whitespace' is
non-nil, this function is called. It move point to a new buffer non-nil, this function is called. It moves point to a new buffer
position, presumably skipping only whitespace in between.") position, presumably skipping only whitespace in between.")
(defun electric-pair-analyze-conversion (string) (defun electric-pair-analyze-conversion (string)
"Notice that STRING has been deleted by an input method. "Delete delimiters enclosing the STRING deleted by an input method.
If the last character of STRING is an electric pair character, If the last character of STRING is an electric pair character,
and the character after point is too, then delete that other and the character after point is too, then delete that other
character." character. Called by `analyze-text-conversion'."
(let* ((prev (aref string (1- (length string)))) (let* ((prev (aref string (1- (length string))))
(next (char-after)) (next (char-after))
(syntax-info (electric-pair-syntax-info prev)) (syntax-info (electric-pair-syntax-info prev))
@ -177,7 +200,8 @@ character."
(delete-char 1)))) (delete-char 1))))
(defun electric-pair--skip-whitespace () (defun electric-pair--skip-whitespace ()
"Skip whitespace forward, not crossing comment or string boundaries." "Move point forward over whitespace.
But do not move point if doing so crosses comment or string boundaries."
(let ((saved (point)) (let ((saved (point))
(string-or-comment (nth 8 (syntax-ppss)))) (string-or-comment (nth 8 (syntax-ppss))))
(skip-chars-forward (apply #'string electric-pair-skip-whitespace-chars)) (skip-chars-forward (apply #'string electric-pair-skip-whitespace-chars))
@ -187,9 +211,9 @@ character."
(defvar electric-pair-text-syntax-table prog-mode-syntax-table (defvar electric-pair-text-syntax-table prog-mode-syntax-table
"Syntax table used when pairing inside comments and strings. "Syntax table used when pairing inside comments and strings.
`electric-pair-mode' considers this syntax table only when point in inside `electric-pair-mode' considers this syntax table only when point is
quotes or comments. If lookup fails here, `electric-pair-text-pairs' will within text marked as a comment or enclosed within quotes. If lookup
be considered.") fails here, `electric-pair-text-pairs' will be considered.")
(defun electric-pair-conservative-inhibit (char) (defun electric-pair-conservative-inhibit (char)
(or (or
@ -206,7 +230,7 @@ be considered.")
"Run BODY with appropriate syntax table active. "Run BODY with appropriate syntax table active.
STRING-OR-COMMENT is the start position of the string/comment STRING-OR-COMMENT is the start position of the string/comment
in which we are, if applicable. in which we are, if applicable.
Uses the text-mode syntax table if within a string or a comment." Uses the `text-mode' syntax table if within a string or a comment."
(declare (debug t) (indent 1)) (declare (debug t) (indent 1))
`(electric-pair--with-syntax-1 ,string-or-comment (lambda () ,@body))) `(electric-pair--with-syntax-1 ,string-or-comment (lambda () ,@body)))
@ -229,11 +253,11 @@ Uses the text-mode syntax table if within a string or a comment."
(defun electric-pair-syntax-info (command-event) (defun electric-pair-syntax-info (command-event)
"Calculate a list (SYNTAX PAIR UNCONDITIONAL STRING-OR-COMMENT-START). "Calculate a list (SYNTAX PAIR UNCONDITIONAL STRING-OR-COMMENT-START).
SYNTAX is COMMAND-EVENT's syntax character. PAIR is SYNTAX is COMMAND-EVENT's syntax character. PAIR is COMMAND-EVENT's
COMMAND-EVENT's pair. UNCONDITIONAL indicates the variables pair. UNCONDITIONAL indicates that the variables `electric-pair-pairs'
`electric-pair-pairs' or `electric-pair-text-pairs' were used to or `electric-pair-text-pairs' were used to look up syntax.
lookup syntax. STRING-OR-COMMENT-START indicates that point is STRING-OR-COMMENT-START indicates that point is inside a comment or
inside a comment or string." string."
(let* ((pre-string-or-comment (or (bobp) (let* ((pre-string-or-comment (or (bobp)
(nth 8 (save-excursion (nth 8 (save-excursion
(syntax-ppss (1- (point))))))) (syntax-ppss (1- (point)))))))
@ -264,20 +288,20 @@ inside a comment or string."
(let ((last-command-event char) (let ((last-command-event char)
(blink-matching-paren nil) (blink-matching-paren nil)
(electric-pair-mode nil) (electric-pair-mode nil)
;; When adding the "closer" delimiter, a job his function is ;; When adding a closing delimiter, a job this function is
;; frequently used for, we don't want to munch any extra ;; frequently used for, we don't want to munch any extra
;; newlines above us. That would be the default behavior of ;; newlines above us. That would be the default behavior of
;; `electric-layout-mode', which potentially kicked in before ;; `electric-layout-mode', which potentially kicked in before us
;; us to add these newlines, and is probably about to kick in ;; to add these newlines, and is probably about to kick in again
;; again after we add the closer. ;; after we add the closer.
(electric-layout-allow-duplicate-newlines t)) (electric-layout-allow-duplicate-newlines t))
(self-insert-command 1))) (self-insert-command 1)))
(defun electric-pair--syntax-ppss (&optional pos where) (defun electric-pair--syntax-ppss (&optional pos where)
"Like `syntax-ppss', but sometimes fallback to `parse-partial-sexp'. "Like `syntax-ppss', but maybe fall back to `parse-partial-sexp'.
WHERE is a list defaulting to \\='(string comment) and indicates WHERE is a list defaulting to \\='(string comment) and indicates
when to fallback to `parse-partial-sexp'." when to fall back to `parse-partial-sexp'."
(let* ((pos (or pos (point))) (let* ((pos (or pos (point)))
(where (or where '(string comment))) (where (or where '(string comment)))
(quick-ppss (syntax-ppss pos)) (quick-ppss (syntax-ppss pos))
@ -298,12 +322,12 @@ when to fallback to `parse-partial-sexp'."
(parse-partial-sexp (point-min) pos) (parse-partial-sexp (point-min) pos)
quick-ppss)))) quick-ppss))))
;; Balancing means controlling pairing and skipping of parentheses ;; Balancing means controlling pairing and skipping of delimiters
;; so that, if possible, the buffer ends up at least as balanced as ;; so that, if possible, the buffer ends up at least as balanced as
;; before, if not more. The algorithm is slightly complex because ;; before, if not more. The algorithm is slightly complex because
;; some situations like "()))" need pairing to occur at the end but ;; some situations like "()))" need pairing to occur at the end but
;; not at the beginning. Balancing should also happen independently ;; not at the beginning. Balancing should also happen independently
;; for different types of parentheses, so that having your {}'s ;; for different types of delimiter, so that having your {}'s
;; unbalanced doesn't keep `electric-pair-mode' from balancing your ;; unbalanced doesn't keep `electric-pair-mode' from balancing your
;; ()'s and your []'s. ;; ()'s and your []'s.
(defun electric-pair--balance-info (direction string-or-comment) (defun electric-pair--balance-info (direction string-or-comment)
@ -322,7 +346,7 @@ If point is not enclosed by any lists, return ((t) . (t))."
(let* (innermost (let* (innermost
outermost outermost
(at-top-level-or-equivalent-fn (at-top-level-or-equivalent-fn
;; called when `scan-sexps' ran perfectly, when it found ;; Called when `scan-sexps' ran perfectly, when it found
;; a parenthesis pointing in the direction of travel. ;; a parenthesis pointing in the direction of travel.
;; Also when travel started inside a comment and exited it. ;; Also when travel started inside a comment and exited it.
(lambda () (lambda ()
@ -330,7 +354,7 @@ If point is not enclosed by any lists, return ((t) . (t))."
(unless innermost (unless innermost
(setq innermost (list t))))) (setq innermost (list t)))))
(ended-prematurely-fn (ended-prematurely-fn
;; called when `scan-sexps' crashed against a parenthesis ;; Called when `scan-sexps' crashed against a parenthesis
;; pointing opposite the direction of travel. After ;; pointing opposite the direction of travel. After
;; traversing that character, the idea is to travel one sexp ;; traversing that character, the idea is to travel one sexp
;; in the opposite direction looking for a matching ;; in the opposite direction looking for a matching
@ -381,7 +405,7 @@ If point is not enclosed by any lists, return ((t) . (t))."
(funcall at-top-level-or-equivalent-fn)) (funcall at-top-level-or-equivalent-fn))
(scan-error (scan-error
(cond ((or (cond ((or
;; some error happened and it is not of the "ended ;; Some error happened and it is not of the "ended
;; prematurely" kind... ;; prematurely" kind...
(not (string-match "ends prematurely" (nth 1 err))) (not (string-match "ends prematurely" (nth 1 err)))
;; ... or we were in a comment and just came out of ;; ... or we were in a comment and just came out of
@ -390,7 +414,7 @@ If point is not enclosed by any lists, return ((t) . (t))."
(not (nth 8 (syntax-ppss))))) (not (nth 8 (syntax-ppss)))))
(funcall at-top-level-or-equivalent-fn)) (funcall at-top-level-or-equivalent-fn))
(t (t
;; exit the sexp ;; Exit the sexp.
(goto-char (nth 3 err)) (goto-char (nth 3 err))
(funcall ended-prematurely-fn))))))) (funcall ended-prematurely-fn)))))))
(cons innermost outermost))) (cons innermost outermost)))
@ -440,7 +464,7 @@ strings."
(unwind-protect (progn ,@body) (goto-char ,point))))) (unwind-protect (progn ,@body) (goto-char ,point)))))
(defun electric-pair-inhibit-if-helps-balance (char) (defun electric-pair-inhibit-if-helps-balance (char)
"Return non-nil if auto-pairing of CHAR would hurt parentheses' balance. "Return non-nil if auto-pairing of CHAR unbalances delimiters.
Works by first removing the character from the buffer, then doing Works by first removing the character from the buffer, then doing
some list calculations, finally restoring the situation as if nothing some list calculations, finally restoring the situation as if nothing
@ -470,7 +494,7 @@ happened."
(electric-pair--unbalanced-strings-p char))))))))) (electric-pair--unbalanced-strings-p char)))))))))
(defun electric-pair-skip-if-helps-balance (char) (defun electric-pair-skip-if-helps-balance (char)
"Return non-nil if skipping CHAR would benefit parentheses' balance. "Return non-nil if skipping CHAR preserves balance of delimiters.
Works by first removing the character from the buffer, then doing Works by first removing the character from the buffer, then doing
some list calculations, finally restoring the situation as if nothing some list calculations, finally restoring the situation as if nothing
happened." happened."
@ -505,7 +529,10 @@ happened."
(electric-pair-conservative-inhibit char))) (electric-pair-conservative-inhibit char)))
(defun electric-pair-post-self-insert-function () (defun electric-pair-post-self-insert-function ()
"Member of `post-self-insert-hook'. Do main work for `electric-pair-mode'. "Do main work for `electric-pair-mode'.
This function is added to `post-self-insert-hook' when
`electric-pair-mode' is enabled.
If the newly inserted character C has delimiter syntax, this If the newly inserted character C has delimiter syntax, this
function may decide to insert additional paired delimiters, or function may decide to insert additional paired delimiters, or
skip the insertion of the new character altogether by jumping skip the insertion of the new character altogether by jumping
@ -561,13 +588,17 @@ The decision is taken by order of preference:
(if (functionp electric-pair-skip-self) (if (functionp electric-pair-skip-self)
(electric-pair--save-literal-point-excursion (electric-pair--save-literal-point-excursion
(goto-char pos) (goto-char pos)
(funcall electric-pair-skip-self last-command-event)) (funcall electric-pair-skip-self
last-command-event))
electric-pair-skip-self)) electric-pair-skip-self))
(save-excursion (save-excursion
(when (and (not (and unconditional (when (and
(eq syntax ?\"))) (not (and unconditional (eq syntax ?\")))
(setq skip-whitespace-info (setq skip-whitespace-info
(if (and (not (eq electric-pair-skip-whitespace 'chomp)) (if (and
(not
(eq electric-pair-skip-whitespace
'chomp))
(functionp electric-pair-skip-whitespace)) (functionp electric-pair-skip-whitespace))
(funcall electric-pair-skip-whitespace) (funcall electric-pair-skip-whitespace)
electric-pair-skip-whitespace))) electric-pair-skip-whitespace)))
@ -596,7 +627,8 @@ The decision is taken by order of preference:
(defun electric-pair-open-newline-between-pairs-psif () (defun electric-pair-open-newline-between-pairs-psif ()
"Honor `electric-pair-open-newline-between-pairs'. "Honor `electric-pair-open-newline-between-pairs'.
Member of `post-self-insert-hook' if `electric-pair-mode' is on." This function is added to `post-self-insert-hook' when
`electric-pair-mode' is enabled."
(when (and (if (functionp electric-pair-open-newline-between-pairs) (when (and (if (functionp electric-pair-open-newline-between-pairs)
(funcall electric-pair-open-newline-between-pairs) (funcall electric-pair-open-newline-between-pairs)
electric-pair-open-newline-between-pairs) electric-pair-open-newline-between-pairs)
@ -646,15 +678,15 @@ ARG and KILLP are passed directly to
;;;###autoload ;;;###autoload
(define-minor-mode electric-pair-mode (define-minor-mode electric-pair-mode
"Toggle automatic parens pairing (Electric Pair mode). "Toggle automatic pairing of delimiters (Electric Pair mode).
Electric Pair mode is a global minor mode. When enabled, typing Electric Pair mode is a global minor mode. When enabled, typing an
an open parenthesis automatically inserts the corresponding opening delimiter (parenthesis, bracket, etc.) automatically inserts the
closing parenthesis, and vice versa. (Likewise for brackets, etc.). corresponding closing delimiter. If the region is active, the
If the region is active, the parentheses (brackets, etc.) are delimiters are inserted around the region instead.
inserted around the region instead.
To toggle the mode in a single buffer, use `electric-pair-local-mode'." To toggle the mode only in the current buffer, use
`electric-pair-local-mode'."
:global t :group 'electricity :global t :group 'electricity
(if electric-pair-mode (if electric-pair-mode
(progn (progn