Next: , Previous: , Up: Programs   [Contents][Index]


21.5 Automatic Display of Matching Parentheses

The Emacs parenthesis-matching feature shows you automatically how parentheses match in the text. Whenever a self-inserting character that is a closing delimiter is typed, the cursor moves momentarily to the location of the matching opening delimiter, provided that is visible on the screen. If it is not on the screen, some text starting with that opening delimiter is displayed in the echo area. Either way, you see the grouping you are closing off.

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

If the opening delimiter and closing delimiter are mismatched—as in ‘[x)’—the echo area displays a warning message. The correct matches are specified in the syntax table.

Two variables control parenthesis matching displays. blink-matching-paren turns the feature on or off. The default is t (match display is on); nil turns it off. blink-matching-paren-distance specifies how many characters back Emacs searches to find a matching opening delimiter. If the match is not found in the specified region, scanning stops, and nothing is displayed. This prevents wasting lots of time scanning when there is no match. The default is 4000.