Living the Lisp Machine Environment

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 @‍<kbd> and @‍</kbd> tags.

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."
  (insert "@<kbd>")
  (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.

UpdateMeta+v】 → 【Meta+^

This entry was posted in Programming and tagged . Bookmark the permalink.
  • Well, the post is interesting as usual. But one thing bothers me: in my (GNU) Emacs, M-v is bound to scroll-down. Did you mean M-^?

    • jcs

      Duh. Of course. Thanks for pointing that out. Fixed.

  • I would have recommended wrap-region for solving your tag-wrapping problem, then I remembered how awesome smartparens is. Although, I don't know how its tag-wrapping functionality might work in Org mode.

    Still, it has user-definable tags, which sound like they'd go a long way towards solving your problem. Select the text you want to wrap with your kbd tag, type in your shorthand, and you're done. Not sure how it handles wrapping a following word, however...