Unified Context Switching

James Dyer has a really interesting post on how he used a bit of Elisp to solve one of his workflow problems. He’d recently abandoned his use of save=desktop in favor of recentf. His reasons for switching don’t really matter—although you can read them in his post—but after opting for recentf he wanted a way to switch to contexts other than files. He wanted to be able to switch to a recent file, a buffer, a bookmark, or a new theme.

All that’s possible out of the box, of course, but Dyer didn’t want to worry about separate keybindings for each of them; he wanted a unified selection method. It took a surprising small amount of Elisp to get this done. A single binding invokes a completing read with all the files, buffers, bookmarks, and themes as possibilities.

Dyer shows the code in his post. It’s amazingly straightforward. The only complicated thing is that he uses some of the more esoteric capabilities of completing read, many of which I didn’t know about.

Even if you’re not interested in building a unified context switching mechanism such as his, his code is worth studying for what it reveals about the features of completing read. It’s a lot more capable than you probably think. As usual, with Dyer’s post, it’s short and won’t take you long to read.

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