Splitting An Org Block

Kaushal Modi has a nice post on how to split an Org block. That comes up in the context of, say, writing a literate program and deciding you want to insert some commentary in the middle of the block. A simple keypress and the block is split in two and the cursor is positioned between the two parts.

The notion of “block” is general. The splitting will work with any type of Org block so its use extends beyond the simple case above. You wouldn’t think this would be too complicated but, in fact, it’s a bit fiddly. There’s no built-in predicate to tell you when you’re inside any Org block so Modi had write that first. The rest is mostly diddling around with regexes but there’s still the problem of deciding where to split the block.

Modi shows all his code and has a nice commentary on what he’s doing so it’s easy to follow along. There’s also a pointer to his setup-org.el file where you can see all the code at once. This is a nice post and Modi’s code may be useful to those of you who frequently use Org blocks in your writing. It’s also another wonderful example of how Emacs lets you scratch just about any itch.

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