Description
Description
Hello,
I registered an autocmd on the OptionSet
event with pattern = "cursorline"
and noticed that nvim-tree triggers that event when opening the tree. The expected behaviour is that no events are triggered when setting an option.
Nvim has the ex command :noautocmd <cmd>
which would supress that events are fired. However I'm not aware of an LUA API call with the same effect.
nvim-tree
sets the cursorline here:
nvim-tree.lua/lua/nvim-tree/view.lua
Line 130 in 7944e47
A possible fix would be:
-- Create a temporary wrapper function
function _G.tmp()
vim.opt_local[k] = v
end
-- Fire the wrapper function from vimscript with `noautocmd`
vim.cmd('noautocmd call v:lua.tmp()')
-- Delete the wrapper function
_G.tmp = nil
This workaround is not very elegant but I can't think of a better way since :noautocmd only existst as ex-command
However I'm not sure if that has any sideeffects in general. I greped the repo for the OptionSet
event and could not find anything. So I guess nvim-tree
does not rely on events triggerd by setlocal
, so I guess this change should be fine
Neovim version
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Operating system and version
macOS 10.15.7
nvim-tree version
Minimal config
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup {
{
"wbthomason/packer.nvim",
"nvim-tree/nvim-tree.lua",
"nvim-tree/nvim-web-devicons",
-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
},
config = {
package_root = package_root,
compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true },
},
}
end
if vim.fn.isdirectory(install_path) == 0 then
print "Installing nvim-tree and dependencies."
vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true
-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
require("nvim-tree").setup {}
end
local autocmd = vim.api.nvim_create_autocmd
local augroup = vim.api.nvim_create_augroup
local group = augroup('Test', { clear = true })
autocmd('OptionSet', {
pattern = 'cursorline',
callback = function()
print('set cursorline option triggered')
end,
group = group,
})
Steps to reproduce
nvim -nu /tmp/nvt-min.lua
:NvimTreeOpen
:messages
- Investigate output
Expected behavior
The event should not be triggered
Actual behavior
The event is triggered