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 (face-background 'default)) (set-face-foreground 'show-paren-match-face "#def") (set-face-attribute 'show-paren-match-face 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 when `
‘show-paren-mode’’ is enabled, but then only directly after typing a closing paren. If you use the above code, the information will show up every time the point is placed behind a closing paren.