lilibyte

tabhula: context based tabout for nvim and my thoughts on lua
2022-03-23
project, software

I spent a day working on what has amounted to being my first completed (or at least releasable) project of the year. It's a Neovim plugin called Tabhula that enables tab out functionality based on custom pattern matching. I've published it on GitHub already. Not sure whether there will be any further changes. I wrote this because I wanted something better than the shitty vimscript lines I was using for this functionality before, and because tabout.nvim didn't really suite me.

Here's the introduction from the readme, so you get the idea:


Tabhula is a Neovim plugin for tinkerers wanting context-based functionality. The whole concept is derived from simply wanting to use the tab character to exit quotes, brackets, parentheses, or any other character, under certain circumstances only.

For example, if you want to use > as a tab out character, but only be able to tab out of the line #include <stdio.h> and not affect a line such as 10 > 11, you can create a custom function using Lua pattern matching:

>
    [">"] = function(line) return line:match("^(%s*)#(%s*)include(%s*)<(%g*)>(%s*)$") ~= nil end
<

This way, when the cursor (|) is in front of a forward character (see |tabhula-usage|) you can reach the end of the line by pressing <Tab>:

>
    // before
    #in(|)clude <stdio.h>

    // after
    #include <stdio.h>(|)
<

Tab out enables quickly navigating lines without the need to exit insert mode (:help insert-mode).

Because of the manual nature of this plugin, it will not be suitable for someone looking for advanced functionality but who doesn't understand scripting logic well enough to write basic Lua. Ultimately, I've created this plugin for my own personal use and being easy to use is not the goal. If you want more thoroughly customizable logic, consider forking the project and modifying it as you need. Tabhula is completely free/libre.


Working on Lua for this project was a little disappointing because I really thought that there was a fair chance I'd take a liking to the language, but from my limited experience with it so far I must say I find it super intuitive. How to iterate over a string? Just call a method to create a pattern that matches the entire string and iterate over that instead!. Nah, I don't think so. It's kind of obligatory every time Lua is mentioned, but the 1-based "indexing" of tables is another thing I don't like.

More than anything else it's really just the syntax that I find annoying. It doesn't have the visual simplicity of Python, nor the eloquence of C-style braced languages. end end end end ahhh I get it already!

I think it would be fun to create a language of my own and a corresponding interpreter as a project I can do in C. The K&R book already has exercises for making syntax error parsers and a reverse Polish notation calculator so I have a pretty clear idea as to where to start. I'll make a post about it if I actually see that through, but we'll see.

I have a ton of other project ideas to work on too, and I'm very much enjoying learning and getting better at C. I also hope to post more often on my site soon. I've also slowly put together a redesign I might flesh out before too long as well. If I don't end up liking the change I can always go back to how it is now.