24.6. Automatic Display Of Matching Parentheses

The Emacs parenthesis-matching feature is designed to show automatically how parentheses match in the text. Whenever you type a self-inserting character that is a closing delimiter, the cursor moves momentarily to the location of the matching opening delimiter, provided that is on the screen. If it is not on the screen, some text near it is displayed in the echo area. Either way, you can tell what grouping is being closed off.

In Lisp, automatic matching applies only to parentheses. In C, it applies to braces and brackets too. Emacs knows which characters to regard as matching delimiters based on the syntax table, which is set by the major mode. Section 32.6.

If the opening delimiter and closing delimiter are mismatched--such as in [x)--a warning message is displayed in the echo area. The correct matches are specified in the syntax table.

Three variables control parenthesis match display. blink-matching-paren turns the feature on or off; nil turns it off, but the default is t to turn match display on. blink-matching-delay says how many seconds to wait; the default is 1, but on some systems it is useful to specify a fraction of a second. 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 far, scanning stops, and nothing is displayed. This is to prevent scanning for the matching delimiter from wasting lots of time when there is no match. The default is 12,000.

Show Paren mode provides a more powerful kind of automatic parenthesis matching. Whenever point is after a close parenthesis, the close parenthesis and its matching open parenthesis are both highlighted; otherwise, if point is before an open parenthesis, the matching close parenthesis is highlighted. (There is no need to highlight the open parenthesis after point because the cursor appears on top of that character.) Use the command M-x show-paren-mode to enable or disable this mode.

By default, show-paren-mode uses colors to highlight the parentheses. However, if your display doesn't support colors, you can customize the faces show-paren-match-face and show-paren-mismatch-face to use other attributes, such as bold or underline. Section