Emacs Tip #1: Paranthesis matching

Emacs has so many ways to match the paranthesis in your code. There is the paren-mode and there are many other hacks. They are all fine, I like the way how vi does it. In vi, you place your cursor on a paranthesis and press % key and it will jump to the matching paranthesis.

To enable this feature, put the following code in your ~/.emacs file and restart.

(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)))))

Advertisements
Explore posts in the same categories: Emacs

Tags: ,

You can comment below, or link to this permanent URL from your own site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: