A little while ago I wrote about Martin Fowler's post on InternalReprogrammability that celebrated Emacs reprogrammability and its recapitulation of the Lisp Machine environment. That capability is of more than theoretical importance as I, once again, discovered.
Long time readers know that the fancy 【Key】display on this blog is produced by a combination of CSS for the <kbd> tag and some Elisp that converts text such as
ctrl+x b into
【@<kbd>Ctrl@</kbd>+@<kbd>x@</kbd> @<kbd>b@</kbd>】 (the
@ in front of the tags is an Org mode thing that tells Org mode to export the tag that follows as raw HTML) which gets displayed as【Ctrl+x b】. The Elisp has some regular expression-based combining rules that handle minimally complex expressions such as
ctrl+x b or
ctrl+x ctrl+s. Recently—probably as a result of all the VimGolf in Emacs posts I've been doing—I've run into cases that the Elisp didn't handle correctly. That's not a big deal because I can just go in and fix the markup by hand. Indeed, I even have a chord,
<>, that inserts
@<> into the buffer so that I can easily insert the
The other day I was busy doing a bunch of those fix ups when, just as Fowler, I realized that I'd been dealing with this problem by doing more work than necessary. So I wrote a little Elisp
(defun enkey () "Wrap the next word with (org-mode) <kbd> tags." (interactive) (insert "@<kbd>") (forward-word) (insert "@</kbd>"))
to do the wrapping of words (or singleton characters) in the <kbd> tags automatically. Now I just put the point before any word or character that didn't get handled correctly by the conversion code, call
enkey, and move on to the next problem.
It's easy to forget—even when you write about it occasionally—how simple it is to fix minor editing annoyances with Emacs. A little bit of Elisp and the problem is solved.
Another small annoyance that I hadn't gotten around to dealing with is the inability to join the current line with the next one; you must move down and then combine the two lines with 【Meta+^】. Happily, that was an itch that also bothered Magnar Sveen so he fixed it. It's another example of how Emacs lets you have it your way.
Update 【Meta+v】 → 【Meta+^】