Previous: Moving by Parens, Up: Parentheses
Emacs has a number of parenthesis matching features, which make it easy to see how and whether parentheses (or other delimiters) match up.
Whenever you type a self-inserting character that is a closing delimiter, Emacs briefly indicates the location of the matching opening delimiter, provided that is on the screen. If it is not on the screen, Emacs displays some of the text near it in the echo area. Either way, you can tell which grouping you are closing off. If the opening delimiter and closing delimiter are mismatched—such as in ‘[x)’—a warning message is displayed in the echo area.
Three variables control the display of matching parentheses:
blink-matching-paren
turns the feature on or off: nil
disables it, but the default is t
to enable it. Set it to
jump
to make indication work by momentarily moving the cursor
to the matching opening delimiter.
blink-matching-delay
says how many seconds to keep indicating
the matching opening delimiter. This may be an integer or
floating-point number; the default is 1.
blink-matching-paren-distance
specifies how many characters
back to search to find the matching opening delimiter. If the match
is not found in that distance, Emacs stops scanning and nothing is
displayed. The default is 102400.
Show Paren mode, a global minor mode, provides a more powerful kind of automatic matching. Whenever point is before an opening delimiter or after a closing delimiter, both that delimiter and its opposite delimiter are highlighted. To toggle Show Paren mode, type M-x show-paren-mode.
Electric Pair mode, a global minor mode, provides a way to easily insert matching delimiters. Whenever you insert an opening delimiter, the matching closing delimiter is automatically inserted as well, leaving point between the two. Conversely, when you insert a closing delimiter over an existing one, no inserting takes places and that position is simply skipped over. These variables control additional features of Electric Pair mode:
electric-pair-preserve-balance
, when non-nil
, makes the
default pairing logic balance out the number of opening and closing
delimiters.
electric-pair-delete-adjacent-pairs
, when non-nil
, makes
backspacing between two adjacent delimiters also automatically delete
the closing delimiter.
electric-pair-open-newline-between-pairs
, when non-nil
,
makes inserting inserting a newline between two adjacent pairs also
automatically open and extra newline after point.
electric-pair-skip-whitespace
, when non-nil
, causes the minor
mode to skip whitespace forward before deciding whether to skip over
the closing delimiter.
To toggle Electric Pair mode, type M-x electric-pair-mode.