Previous | Next

Matching parens in emacs

From "Emacs for vi programmers", http://grok2.tripod.com/:

(defun match-paren (arg)
  "Go to the matching paren if on a paren;
   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)))))
(global-set-key "\C-x%" 'match-paren)