Module: Rvim::Lua::Opt
- Defined in:
- lib/rvim/lua/opt.rb
Overview
vim.opt / vim.bo / vim.wo / vim.go — option proxies.
NeoVim differentiates by scope:
vim.opt.{name} — set both global + local effective value
vim.go.{name} — global only
vim.bo.{name} — buffer-local
vim.wo.{name} — window-local
Plugins that write ‘vim.opt.tabstop = 4` and read `vim.opt.tabstop:get()` must round-trip cleanly. We expose `:get()` as a tiny accessor; for v3.1 we don’t yet implement the OptionInfo chain (append/prepend/remove on list-style options) — that’s a later ship if a plugin needs it.
Class Method Summary collapse
Class Method Details
.coerce_to_setting(value) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/rvim/lua/opt.rb', line 68 def coerce_to_setting(value) case value when Float then value == value.to_i ? value.to_i : value else value end end |
.install(state, editor, _runtime) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rvim/lua/opt.rb', line 20 def install(state, editor, _runtime) # Global setter/getter — used by both vim.opt and vim.go. state.function '_rvim_opt_set' do |name, value| coerced = coerce_to_setting(value) editor.settings.set(name.to_s, coerced) end state.function '_rvim_opt_get' do |name| editor.settings.get(name.to_s) end # Buffer-local setter/getter. state.function '_rvim_bo_set' do |name, value| coerced = coerce_to_setting(value) editor.settings.set(name.to_s, coerced, buffer: editor.current_buffer) end state.function '_rvim_bo_get' do |name| editor.settings.get(name.to_s, buffer: editor.current_buffer) end state.eval(<<~LUA) local function make_opt(setter, getter) return setmetatable({}, { __index = function(_, name) local value = getter(name) return setmetatable({ _name = name, _value = value }, { __index = function(self, key) if key == 'get' then return function() return getter(self._name) end end return rawget(self, key) end, }) end, __newindex = function(_, name, value) setter(name, value) end, }) end vim.opt = make_opt(_rvim_opt_set, _rvim_opt_get) vim.go = make_opt(_rvim_opt_set, _rvim_opt_get) vim.bo = make_opt(_rvim_bo_set, _rvim_bo_get) vim.wo = make_opt(_rvim_opt_set, _rvim_opt_get) -- window-local stubs to global LUA end |