Structured Emacs Editing With Builtin Commands

Bozhidar Batsov has an excellent post that considers structured editing using builtin Emacs commands. It turns out that all those commands (like forward-sexp) that you think of as Lisp-specific commands work in many other modes. The secret is that the target mode has to tell the commands how to find structure boundaries.

There are several ways of doing that. The oldest is to use the mode’s syntax table but that doesn’t work if the structure is bounded by things like structureend. The more modern method is to provide functions that can find these boundaries and, of course, the most modern is to use Tree-sitter with an actual grammar of the target language.

Pay particular attention to the Ctrl+Meta commands. If you’ve done any Lisp programming, they’ll be familiar but they’re useful for a lot of other languages—even plane text. For example, I use Ctrl+Meta+Space all the time to progressively mark words in a text buffer. It’s a bit easier than using Ctrl+Space and then some motion command to do the same thing.

As Batsov says, the Ctrl+Meta commands keep getting smarter as more major modes teach them about their syntax. His post is full of good information that I haven’t mentioned here so be sure to head over and read it.

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