Closed rnpnr closed 10 months ago
Note: I mostly made this patch to familize myself more with how the Lua-C
interface works. For instance this patch could have its size split in
half if people think that vis:command("set ...")
is sufficient.
I do think that the ability to read the options from Lua is useful and would like to merge at least that part.
I like this. It's much more ergonomic to have a lua api for these settings. Code looks good on quick read as well.
In that case I can also add the ability to set the options with a table. For example:
vis.options = { expandtab = true, tabwidth = 4 }
It will be a very minor modification.
One other thing to note is that I had to rename some options to be valid
in lua (eg. show-tabs -> showtabs
). I think I should probably rename the
options elsewhere to keep everything consistent.
I implemented the ability to set options from a table, for example:
vis.options = { autoindent = true, expandtab = false }
This ended up being slightly more complicated than I originally thought so I had to move the string parsing to separate functions so that it could be reused. I am still quite happy with result.
Additionally the options I needed to rename were also changed in sam.c
so that everything is consistent.
While this is a big patch I think its overall a net positive. It will also
mean that there will be no more requests for exposing single options that
people need for writing plugins and that we won't need to make a breaking
API change when we get sick of all the options being assigned to the top
level vis
and win
tables (ie. vis.tabwidth
, vis.autoindent
etc).
I am afraid this doesn't apply at all on the top of #675.
Its applied fine in my local testing branch. I think the problem is that
later tonight.
For those that want this behavior in their current version of vis, see https://github.com/milhnl/vis-options-backport
the first point of this commit is to allow all options to be read from lua. this has a number of uses for plugin writers. they are grouped into a couple of tables depending on what they control:
vis.options
: table with global configurationwin.options
: table with window specific configurationthe second point is to allow you to set all these options as if they were simply lua variables. technically this is already possible by using
vis:command("set ...")
but personally I think this interface is cleaner. Note that this already possible for some things like the current mode (eg. vis.mode = vis.modes.VISUAL). examples:vis.options.ai = true
vis.options.brk = " !?."
there are a number of related issues and pull requests: closes #803: Lua API: let plugins read the values of options closes #812: Window layout property supersedes/closes #717: Add ability to access tabwidth from Lua supersedes/closes #1066: expose UI layout and allow it to be set from lua API