show-paren-mode allows one to see matching pairs of parentheses and other characters. When point is on one of the paired characters, the other is highlighted. Activate it once by running
M-x show-paren-mode RET
or make it permanent by putting the following into your .emacs file:
By default, there’s a small delay before showing a matching parenthesis. It can be deactivated with
(setq show-paren-delay 0)
To make this mode local to the buffer, use
(make-variable-buffer-local 'show-paren-mode) and add something like this to your
(defun lispy-parens () "Setup parens display for lisp modes" (setq show-paren-delay 0) (setq show-paren-style 'parenthesis) (make-variable-buffer-local 'show-paren-mode) (show-paren-mode 1) (set-face-background 'show-paren-match-face (face-background 'default)) (if (boundp 'font-lock-comment-face) (set-face-foreground 'show-paren-match-face (face-foreground 'font-lock-comment-face)) (set-face-foreground 'show-paren-match-face (face-foreground 'default))) (set-face-attribute 'show-paren-match-face nil :weight 'extra-bold))
To change the color/face:
(require 'paren) (set-face-background 'show-paren-match (face-background 'default)) (set-face-foreground 'show-paren-match "#def") (set-face-attribute 'show-paren-match nil :weight 'extra-bold)
When the matching paren is offscreen, show-paren-mode highlights only the paren at point. It is more useful to show the line of matching paren in the minibuffer. Execute the following to get this behavior:
(defadvice show-paren-function (after show-matching-paren-offscreen activate) "If the matching paren is offscreen, show the matching line in the echo area. Has no effect if the character before point is not of the syntax class ')'." (interactive) (let* ((cb (char-before (point))) (matching-text (and cb (char-equal (char-syntax cb) ?\) ) (blink-matching-open)))) (when matching-text (message matching-text))))
This behaviour seems to occur already in my GNU Emacs 184.108.40.206 with (show-paren-mode), but I’m fairly sure it happens in stock GNU Emacs 22 as well, can anyone confirm?
Not in my emacs: 22.2.1. Glad to have it though.
In GNU Emacs 23.2, this information shows up directly after typing a closing paren, independent of whether `
‘show-paren-mode’’ is enabled or not (see ). If you use the above code (and enable `
‘show-paren-mode’’), the information will show up every time the point is placed behind a closing paren.
The information that you are all writing about is from user option
‘blink-matching-paren’, which is by default
‘t’ (i.e., turned on) in all Emacs versions. When it is on and
‘show-paren-mode’ is also on, the information about the matching location off-screen appears (from
‘blink-matching-paren’), but there is no blink: no apparent cursor movement (bounce).
IOW, if you turn on
‘blink-matching-paren’ is on (the default) then you get both highlighting of the matching paren and, when it is off-screen, an echo area description of the match location. If you turn off
‘show-paren-mode’ but you leave on
‘blink-matching-paren’ then you get the echo-area indication and the cursor bounces to the match location. If you turn on
‘show-paren-mode’ and you turn off
‘blink-matching-paren’ then you get only the match highlighting – no echo-area description of an off-screen match location. – DrewAdams