martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.27k stars 261 forks source link

Lua API: let plugins read the values of options #803

Closed ingolemo closed 1 year ago

ingolemo commented 4 years ago

Plugins should be able to read the values of options from lua somehow. Currently options can be set with vis:command, but they cannot be read. I specifically want to be able to read expandtab and tabwidth, but I think a more generic mechanism is needed. It's worth noting that vis already exposes the syntax option with vis.syntax and vis:set_syntax.

There's a possible issue with a unified api, in that some options are tied to specific windows and other acting globally.

adigitoleo commented 2 years ago

Option introspection would be nice to have in general. I would like to see the ability to run :set ignorecase and have the current value printed as an info message. We already have toggle capability via ! for non-visual boolean options like that, but e.g. for ignorecase, without testing a search pattern it is not easy to know what the result of :set ignorecase! is.

There's a possible issue with a unified api, in that some options are tied to specific windows and other acting globally.

This should be fine, window-specific options can be at vis.win.option where global options can be vis.option, etc. Looks like that's already the case, with some other namespaces like file and ui as well:

http://martanne.github.io/vis/doc/

I guess we just need to decide where the remaining options should go. Could require some refactoring and new drawing logic if we want to make more things window-local (which can quickly get overcomplicated):

That's the most obvious stuff I could see in https://github.com/martanne/vis/blob/master/vis-core.h, although some of the other things may be interesting to expose for some advanced plugins, I suppose.