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
[RFC] autocmds: add WinClosed command #9066
Conversation
Also need to test for "recursion", i.e. the case where
If it's before closing, it should be named Is there a reason for doing it before closing (that implies it's possible the window does not close for some reason)? Will users also want a "after closing" event? |
* Add test to make sure event just fires once * Update documentation to clarify when event is fired
I will think about that
|
|
Hi @justinmk, I just added a test for the recursive case (https://github.com/neovim/neovim/pull/9066/files#diff-bdc18dc18b088a1cc092d1fce6face23R65) and the second level event is not fired. Could you check if I understood your remark about recursive events correctly? |
It seems to break ci tests, even though they pass on my system. Most of other tests call bufwinnr directly instead of eval'ing it.
The remaining failed builds seem to be unrelated to my PR |
This failure is related (or it exposes an existing bug):
|
Likely that failure is because recursion isn't prevented. Look at
But as mentioned in #3338 |
src/nvim/window.c
Outdated
|
||
// If autocommands closed the window, there's nothing else to do | ||
if (!win_valid(win)) { | ||
return FAIL; |
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.
Can you explain this? How could autocommands close the window during a WinClosed
event for that very window? If we disable recursion (see other comments), perhaps this case is avoided.
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.
Yes, I'm trying to avoid recursion. But as I said before, I do not see where/how is recursive
defined.
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.
You need to introduce a function-local static int recursive
, see do_autocmd_dirchanged
for example.
src/nvim/window.c
Outdated
win->w_buffer->b_fname, false, win->w_buffer); | ||
|
||
// If autocommands closed the window, there's nothing else to do | ||
if (!win_valid_any_tab(win)) { |
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.
same comments as for the win_close
case.
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.
The same comment as before
This is looking pretty good, just need to figure out these last questions :) |
WinClosed is not a command
Yes, it was introduced by the commits just after that comment... I saw I was missing some cases. Still working on them. |
I got what you mean now! I will test it :) |
I did some tests... but I'm not sure about which kinds of recursion you want to forbid here. should we forbid it? |
Then only the first WinClose is triggered. No recursion (call it "cascading" if that helps).
We need a new function (see
|
Hello, I just pushed a first take on that. The only missing point for me is the role of the field |
still a ASAN failure. search the travis log for "AddressSanitizer" . |
It looks like ASAN errors are not related to the new autocmd but to the bdelete ex cmd that seems to break related to the deleted buffer.
To make sure it won't try to use already freed resources on an autocmd.
This reverts commit bebfd6b.
We may be on a different tab after autocmd runs
Hello the ASAN error should be fixed now. |
continued at #11331 (you will still get author credit) |
Fixes #3338