I used to use a short code "match-paren" (http://grok2.tripod.com/) when I program, especially in Lisp where parentheses are everywhere. I like this piece of code, for its simplicity and usefulness: if you bind this code to something like M-[, and when you press M-[ on a "(", the cursor goes to the matching ")" automatically. This also works when mark is activated, so you can highlight the region between two matching "(" and ")" very easily. The original code is as follows:
(defun match-paren (arg)
"Go to the matching paren if on a paren."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))))
Then sometimes I found that the code does not always work intuitively, especially when I want to highlight a region with the matching "(" and ")", so I did the following hack:
(1) when you keep hitting the key-binding, e.g., M-[, the cursor jump back and forth between its original locations, not like the original code
(2) when the mark is active, the cursor jump to the matching parenthesis and move forward one step after reaching ")" or backward one step after reaching "(", so the highlighted region contains everything between (and including) the matching "(" and ")". I found this especially useful when you want to cut a list out when programming in Lisp.
Here is my hack.
(defun da-match-paren (arg)
"Go to the matching paren if on a paren."
(interactive "p")
(cond ((and mark-active (looking-at "\\s\(")) (forward-list 1))
((and mark-active (looking-back "\\s\)")) (backward-list 1))
((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
))
(global-set-key (kbd "M-[") ‘da-match-paren)