OptionSet
autocmd can be used to detect change for an option. But there is no way to narrow it down for a specific window, or know for which window that option was changed.
Is there any other possible way to do this?
For example: Let’s say I want a function to be called whenever the winhighlight
option changes for a specific floating window.
Would something like this work? (replacing local win=...
and 'number'
with desired):
local win=vim.api.nvim_get_current_win()
CACHE=vim.api.nvim_win_get_option(win,'number')
vim.api.nvim_create_autocmd('OptionSet',{callback=function()
if CACHE~=vim.api.nvim_win_get_option(win,'number') then
CACHE=vim.api.nvim_win_get_option(win,'number')
--add wanted command here
end
end})
Hmm… Yeah, that would get the work done.
But it’s a bit wasteful, it will get triggered whenever number
is changed, doesn’t matter for which window.
I wish autocmds had more fine grained control.