Zap Up To A Character

I was browsing Magnar Sveen’s excellent What the .emacs.d!? blog and came across a post on elisp-slime-nav-mode, a mode that brings a bit of Slime-like navigation to Elisp. It’s not part of the Emacs distribution and Sveen didn’t say where it comes from (it’s available on MELPA) but after a little investigation I discovered that it was written by Steve Purcell. That lead me to Purcell’s emacs.d repository on Git Hub. What a find! Purcell has a ton of really good ideas and code. Doubtless I’ll be discussing some of them later but today I want to talk about zap-to-char.

Everyone agrees that zap-to-char is really useful but at least half the commentary about it complains that it zaps up to and including the specified character. Much more useful, these complaints say, would be to zap up to but not including the character. It turns out that the stock Emacs distribution does include a function that does just that: zap-up-to-char. The problem is that it’s in misc.el, which is not loaded by default, and does not have an autoload associated with it.

Purcell fixes that by simply providing an autoload and then binding zap-up-to-char to 【Meta+z】 and zap-to-char to 【Meta+Z】 on the grounds that zap-up-to-char is more useful and should have the easier key sequence. I’m used to having 【Meta+z】 be zap-to-char so I did it the other away around:

(autoload 'zap-up-to-char "misc"
  "Kill up to, but not including ARGth occurrence of CHAR.")
(global-set-key (kbd "M-Z") 'zap-up-to-char)

Now you can have the best of both worlds. Be sure to check Purcell’s repository out. It’s full of great tips and tricks.

This entry was posted in General and tagged . Bookmark the permalink.