elfs: (Default)
[personal profile] elfs

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

Date: 2010-03-08 04:07 am (UTC)
From: [identity profile] http://users.livejournal.com/_candide_/
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. ^_^)

Profile

elfs: (Default)
Elf Sternberg

May 2025

S M T W T F S
    123
45678910
111213141516 17
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 27th, 2025 09:42 pm
Powered by Dreamwidth Studios