?

Log in

entries friends calendar profile Elf Sternberg's Pendorwright Projects Previous Previous Next Next
Elf M. Sternberg - Vi’s “paren bounce” feature for Emacs
elfs
elfs
Vi’s “paren bounce” feature for Emacs

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

Tags:

1 comment or Leave a comment
Comments
_candide_ From: _candide_ Date: March 8th, 2010 04:07 am (UTC) (Link)
Eh, I just use C-M-f and C-M-b … when I remember that forward-sexp and backward-sexp are there, that is.

(As it turns out, I also bound these two to C-M-Right and C-M-Left, respectively. But I periodically forget that I did that, too. ^_^)
1 comment or Leave a comment