Vi’s “paren bounce” feature for Emacs

Mar 05, 2010 23:13


I need to make clear that I did not invent the code below. I’m not sure who did, but the topic of making vi’s “paren bounce” feature work in Emacs came up in a conversation I had the other day, and I’m posting the chunk of code that’s lived in my .emacs file since, oh heck, must have been back in my days at F5 Networks.  This code creates a new function, “paren-bounce”, and binds it to the key sequence “CTRL-%” (I know, that’s probably not a real control code, but Emacs Doesn’t Care).

(defun paren-bounce () (interactive) (let ((prev-char (char-to-string (preceding-char))) (next-char (char-to-string (following-char)))) (cond ((string-match "[[{(<]" next-char) (forward-sexp 1)) ((string-match "[\]})>]" prev-char) (backward-sexp 1)) (t (error "%s" "Not an expression boundary."))))) (global-set-key [(control ?%)] 'paren-bounce)
Similar solutions can be found here and here. I suspect the latter is where I got mine from- there are minor differences, but his page hasn’t been updated since 2001, so that’s about right.
This entry was automatically cross-posted from Elf's technical journal, ElfSternberg.com

uncategorized

Previous post Next post
Up