- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 634
Closed
Labels
PR pleasenvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciatednvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciatedbugSomething isn't workingSomething isn't workingreproducedIssue confirmedIssue confirmed
Description
Description
I have a separate plugin (neoclip), which listens to TextYankPost events.
When the handler is run in neoclip, it requires regcontents to be set. neoclip code
However, looking at the nvim-tree code
It doesn't seem to set those values that are documented for the TextYankPost event.
Neovim version
NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1699801871
Operating system and version
macOS 13.6.2
Windows variant
No response
nvim-tree version
Clean room replication
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
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
"AckslD/nvim-neoclip.lua"
},
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("neoclip").setup({ default_register = { "\"", "+", "*" } })
require("nvim-tree").setup {}
end
-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.
-- Requires diagnostics.enable = true in setup.
--[[
vim.api.nvim_create_autocmd("FileType", {
pattern = "lua",
callback = function()
vim.lsp.start { cmd = { "lua-language-server" } }
end,
})
]]Steps to reproduce
- nvim -nu /tmp/nvt-min.lua
- :NvimTreeOpen
- Navigate to a file in the tree
- In normal mode, press 'y' to attempt to yank file
- Error with neoclip saying regcontents is empty
Expected behavior
Open nvim-tree, for a file in the tree, try to yank the filename with 'y'. There are no error messages that show up for handlers that read regcontents from the event.
Actual behavior
Open nvim-tree, for a file in the tree, try to yank the filename with 'y'.
Error detected while processing TextYankPost Autocommands for "*":
E5108: Error executing lua ...hare/nvim/lazy/nvim-neoclip.lua/lua/neoclip/handlers.lua:9: attempt to get length of field 'regcontents' (a nil value)
stack traceback:
...hare/nvim/lazy/nvim-neoclip.lua/lua/neoclip/handlers.lua:9: in function 'should_add'
...hare/nvim/lazy/nvim-neoclip.lua/lua/neoclip/handlers.lua:45: in function 'handle_yank_post'
[string ":lua"]:1: in main chunk
[C]: in function 'nvim_exec_autocmds'
...zy/nvim-tree.lua/lua/nvim-tree/actions/fs/copy-paste.lua:266: in function 'fn'
...ocal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/api.lua:49: in function <...ocal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/api.lua:46>
xuyangyuio and awerebea
Metadata
Metadata
Assignees
Labels
PR pleasenvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciatednvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciatedbugSomething isn't workingSomething isn't workingreproducedIssue confirmedIssue confirmed
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
alex-courtis commentedon Nov 19, 2023
Many thanks for the detailed investigation and report. It appears that we do need to populate all the things.
We can hardcode most of it, perhaps something like:
{ inclusive = false, operator = "y", regcontents = { "$FOOBAR" }, regname = "", --unnamed regtype = "v", --we're not yanking the whole line visual = false }I'd be most grateful if you could submit a PR @aalvarado1919 - you have all the knowledge and a good test setup...
aalvarado1919 commentedon Nov 28, 2023
Yes, I can take a look this week @alex-courtis.
Aljendro commentedon Dec 1, 2023
I don't actually know how I would set the v:event variable. Seems to be readonly and trying to pass any arguments to
Did not seem to work.
I've asked a question on SO here. If I can get an answer, I will be able to create the PR
gegoune commentedon Dec 1, 2023
According to help:
event "sets it", not consumers.
Confirmed with:
and yanking in regular buffer, this will print:
{ inclusive = true, operator = "y", regcontents = { "ction(event)" }, regname = "", regtype = "v", visual = false }Yanking
yin nvim-tree will print:That explains reported error.
Issue explained by this line of help quoted above:
and that's exactly what nvim-tree does:
https://github.com/nvim-tree/nvim-tree.lua/blob/master/lua/nvim-tree/actions/fs/copy-paste.lua#L256-L264
gegoune commentedon Dec 3, 2023
I wonder if
vim.cmd.let(string:format("@+=%s", content))would be sufficient to fix the issue, @aalvarado1919 would you mind giving it a quick test?Aljendro commentedon Dec 5, 2023
@gegoune Had to set with
but that still does not fire the TextYankPost autocmd on its own
zyd2001 commentedon Mar 30, 2024
I also encountered the same problem. I did some investigation and I believe currently there is no way to trigger TextYankPost with custom v:event without internal change of vim since both :doautocmd and nvim_exec_autocmds() just use empty v:event. I think it is reasonable to make :doautocmd accept custom v:event. I will see whether I can make an PR for this to vim.
I think currently our best solution we can have is to write the content somewhere and use vim command to do real copy then delete those text.
fix(#2535): TextYankPost event sends vim.v.event (#2734)