Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua API: access and set all available options #1114

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

rnpnr
Copy link
Collaborator

@rnpnr rnpnr commented Jul 30, 2023

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 configuration
win.options: table with window specific configuration

the 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

@rnpnr
Copy link
Collaborator Author

rnpnr commented Jul 30, 2023

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.

@ninewise
Copy link
Collaborator

ninewise commented Aug 2, 2023

I like this. It's much more ergonomic to have a lua api for these settings. Code looks good on quick read as well.

@rnpnr
Copy link
Collaborator Author

rnpnr commented Aug 2, 2023

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.

@rnpnr
Copy link
Collaborator Author

rnpnr commented Aug 12, 2023

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).

@mcepl
Copy link
Contributor

mcepl commented Aug 24, 2023

I am afraid this doesn't apply at all on the top of #675.

@rnpnr
Copy link
Collaborator Author

rnpnr commented Aug 24, 2023

Its applied fine in my local testing branch. I think the problem is that
#675 needs to be squashed. I aim to apply that one and possibly this one
later tonight.

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 configuration
`win.options`: table with window specific configuration

The 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`
`win.options.brk = " !?."`
`win.options = { showeof = true, showtabs = true }

There are a number of related issues and pull requests:

closes martanne#803: Lua API: let plugins read the values of options
closes martanne#812: Window layout property
supersedes/closes martanne#717: Add ability to access tabwidth from Lua
supersedes/closes martanne#1066: expose UI layout and allow it to be set from lua API
@rnpnr rnpnr merged commit a35e7ea into martanne:master Aug 25, 2023
24 checks passed
@rnpnr rnpnr deleted the options-from-lua branch August 25, 2023 03:03
@milhnl
Copy link
Contributor

milhnl commented Aug 31, 2023

For those that want this behavior in their current version of vis, see https://github.com/milhnl/vis-options-backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Window layout property Lua API: let plugins read the values of options
4 participants