As procrastination for writing my book, I wrote a Neovim plugin to generate word counts per section in a document.
Neovim lets you use an
extmark on a position to add virtual text. So the idea was to set an
extmark on each header line with the word count, but I didn't quite figure out how the
extmark actually moves around with the text. It feels somewhat unintuitive, but there are probably some subtleties that I haven't figured out yet.
Instead of dealing with that, instead I set up my plugin as a "decoration provider." This lets you just set an ephemeral
extmark which only lasts for the draw cycle, and then next time a line is redrawn you just create it again (or not). This ended up being a bit more code, but much simpler since I now only have to track the word count and where the headers are, and not worry about if an
extmark is still on the right line or not.
Overall Lua feels nice, if rather barebones. I'm definitely missing the functional programming idioms afforded by most modern languages. But the Neovim APIs are very easy to use.
If you're interested in using this, you can get it on Github.