-
-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add update_focused_file.exclude #2673
Conversation
…ist to update_focused_file.update_root.ignore_list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, we might have a bit of an issue with filetypes though:
update_focused_file = {
enable = true,
ignore_list = { "config", "one", },
update_root = {
enable = true,
},
exclude = { "foo", "c", },
},
echo "foo" > foo; echo "bar" > bar.md; echo "baz" > baz.c; echo "nil" > nil.txt
Open bar and nil then b#
. No focus file change. Remove "c"
and everything works as intended.
I would like to review all the options at some point. :) |
I'm getting focus change even with focus.mp4 |
Well, that looks great - working as intended. Testing at Is this an issue with matching the absolute path?
|
Yes. They have gotten out of control again. |
Co-authored-by: Alexander Courtis <[email protected]>
Yep that was it. This should fix the issue |
Should partial matches also be excluded or only exact matches? I went with how ignore_list was written which does exclude partial matches |
Works nicely now. |
Well, we're in a lovely mess here. A quick audit of similar lists: exact:
partial:
partial and filetype:
regex:
What I do like is |
This is core functionality that will likely be used by many; I'm definitely going to take adantage of this as it is far superior to the custom filter hack. How about we give full control to the user? Let them match a path or a name or a filetype explicitly. They can optionally use regexes for name/path. buftype doesn't make much sense however we could add it if a use case comes up. Something like: update_focused_file = {
enable = true,
exclude = {
name = {
"gitcommit",
"foo.*",
},
path = {
"/tmp.*",
"/bar/baz",
},
filetype = { "c", "markdown" },
},
}, What do you think @gegoune ? I hear your concerns around options... |
To be aligned with some of the other options should we also accept function returning table? update_focused_file = {
enable = true,
exclude = {
name = fun|table,
path = fun|table,
filetype = fun|table,
},
}, Or is it too much? When would we evaluate that function? I can potentially see use case where user would like to have different behaviours based on CWD perhaps? |
Since v1 is released
is a breaking change. Updating title accordingly. Also, @alex-courtis perhaps when this PR is ready we should wait a bit and take this opportunity to introduce other breaking changes at the same time to avoid multiple major version bumps. Edit: only noticed the legacy thing now. How do we want to treat those, @alex-courtis? Migrating option in the background isn't really breaking after all. |
There are many possible ways a user could use this exclude. A function makes sense. edit: add bufnr How about we only accept a function e.g. update_focused_file = {
enable = true,
exclude = function(node, bufnr)
return node and node.name = "gitcommit" or bufnr and vim.api.nvim_buf_get_option(bufnr, "filetype") == "zig"
end,
},
That was the idea; I think we agreed to keep those forever. See #2679 |
Any updates on this one @ava5627 ? I'm really keen to get this one as it's very useful functionality. I know I will be using it. |
Been more busy at work the past couple weeks and forgot about this for a bit. Exclude now is a function that takes the BufEnter event like this update_focused_file = {
enable = true,
exclude = function(event)
return vim.api.nvim_buf_get_option(event.buf, "filetype") == "gitcommit" or vim.fn.expand("%"):match("site%-packages")
end,
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working nicely for me:
alex-courtis/arch@3095564
Last nits...
lua/nvim-tree.lua
Outdated
enable = false, | ||
ignore_list = {}, | ||
}, | ||
exclude = function() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use false here, rather than a function, following the convention of similar. This keeps the config small.
Please put a new "function" definiton in ACCEPTED_TYPES
so that validation may occur.
You'll need to update help as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working nicely, many thanks for your contribution!
Create option
update_focus_file.exclude
for files that shouldn't be auto focused likegitcommit
files.I also moved
update_focused_file.ignore_list
toupdate_focused_file.update_root.ignore_list
and madeupdate_focused_file.update_root.enable
to differentiate between them and show thatignore_list
is only about not updating the root.resolves #2444