47: How do I show which parenthesis matches the one I'm looking at?
Emacs 19 comes with paren.el, which (when loaded) will automatically
highlight matching parentheses whenever point (i.e., the cursor) is
located over one. To load paren automatically, include the line
(require 'paren)
in your .emacs file.
Alternatives to paren include:
* If you're looking at a right parenthesis (or brace or bracket) you can
delete it and reinsert it. Emacs will blink the cursor on the matching
parenthesis.
* M-C-f (forward-sexp) and M-C-b (backward-sexp) will skip over one set
of balanced parentheses, so you can see which parentheses match. (You
can train it to skip over balanced brackets and braces at the same time
by modifying the syntax table.)
* Here is some Emacs Lisp that will make the % key show the matching
parenthesis, like in vi. In addition, if the cursor isn't over a
parenthesis, it simply inserts a % like normal.
;; By an unknown contributor
(global-set-key "%" 'match-paren)
(defun match-paren (arg)
"Go to the matching parenthesis if on parenthesis otherwise insert %."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))