Snippets With Abbrev Mode

I’m a big user of yasnippet. I invoke it several times a day in various contexts. I also use the builtin Emacs abbrev-mode for some simpler text substitutions: “ra” for “→” for instance. Again, I usually use this facility several times a day.

One of the endlessly entertaining things about Emacs is that it’s always surprising you with capabilities you didn’t know about. Just the other day, I learned about delete-pair and have been using it ever since. Today, I learned something else that I had no idea existed. You can use abbrev mode in the same way as yasnippet.

Rahul M. Juliato has a very interesting post about how to use abbrev-mode like yasnippet. It turns out that you can specify a function after the substitution part of the abbrev definition and it will operate on the substituted text.

Juliato first shows a simple function that repositions the point. He uses that to implement source code blocks for Markdown and Org mode. But there are no real restrictions on the function so he shows how to implement replacement placeholders as in yasnippet.

All of this is really interesting but a case can be made that yasnippet can already do this and more easily. The thing is, though, as I said, there are no restrictions on the functions that work on the replacement text so you can do pretty much anything you can imagine. To be sure, you’re going to have to write some Elisp but depending on the application, it may be worth it.

You may never have occasion to use this capability but it’s wonderful to know it’s there.

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