Skip to content
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

Error detected while processing BufEnter Autocommands for "*" with the "Close the tab if NERDTree is the only window remaining in it." config #1411

Closed
8 tasks
lafrech opened this issue Mar 6, 2024 · 9 comments · Fixed by #1417
Labels

Comments

@lafrech
Copy link

lafrech commented Mar 6, 2024

Environment

Nope, I removed all plugins.

  • Provide a minimal .vimrc file that will reproduce the issue.
" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

Steps to Reproduce the Issue

Open a file, open NERDTree, open another file, open NERDTree, close a file.

Current Behavior (Include screenshots where appropriate.)

I get this error message

Error detected while processing BufEnter Autocommands for "*":

Press ENTER or type command to continue

and NERDTree is still open.

Expected Result

Tab closes.


This reminds me of jistr/vim-nerdtree-tabs#102.

I'm trying to get rid of vim-nerdtree-tabs because it is unmaintained and because I realized what I'm using it for should be achievable using the sample config lines from NERDTree README.

I'm surprised I'm getting that same error.

I removed all plugins and kept that single line in the config file, which makes me wonder how come no one else is affected. I don't see anything specific in my setup.

@lafrech lafrech added the bug label Mar 6, 2024
@rzvxa
Copy link
Member

rzvxa commented Mar 6, 2024

Hi, I've tried to reproduce the issue on my machine with no result.
Among things that can be different between our setups, the version of Vim and NERDTree seems most relevant to me.
I'm currently using neovim, But earlier versions of Vim9 had some rough edges that got patched out in subsequent releases. Could you update both your Vim and NERDTree?

In case there are any more details in the error message you are receiving please send them here. Try using the :messages command to see if there is any error that gets flushed before you get this message.

@lafrech
Copy link
Author

lafrech commented Mar 6, 2024

Thank you for your answer.

I thought I was using latest NERDTree version. Perhaps an issue with scroolose vs. preservim. Anyway I updated to latest NERDTree and I'm still facing this issue.

I'm using vi from Debian repo. I shall try to see if I can install from testing or any other repo without screwing up my system.

I can also try neovim 0.7.2 but that's pretty old.

Here's what I get from the :messages command:

Error detected while processing BufEnter Autocommands for "*":
E1312: Not allowed to change the window layout in this autocmd

Searching with that latest line, I found @mb6ockatf's #1354. Same issue, closed just after opening.

@rzvxa
Copy link
Member

rzvxa commented Mar 6, 2024

Ok, I found the issue, It took a bit of digging but it seems like Vim9 from this patch onward won't allow changing the layout which is a breaking change. Since this snippet was from a FAQ section most people probably didn't use it and that's why it went unnoticed for more than 2 years. Neovim being backward compatible also didn't help it.

The one time that it came up the author of the issue closed it which is most probably because they found out about this change and used a new workaround for their case.

According to this mailing list thread you can use call feedkeys(":quit\<CR>:\<BS>") to achieve what quit command did before in the context of autocommands.
I've only tested it on neovim since I don't have Vim9 on this machine, Can you confirm that this would also work on Vim9?

" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | call feedkeys(":quit\<CR>:\<BS>") | endif

@lafrech
Copy link
Author

lafrech commented Mar 6, 2024

Works a treat! Thank you so much!

This was frustrating and I'm totally illiterate when it comes to Vim scripts.

Indeed, that ML thread was referred to in the issue I linked to in OP.

Thanks again for sorting this out.

(Still wondering how people live without this config line. Not saying it should be default. Just surprised the issue didn't come up earlier.)

@rzvxa
Copy link
Member

rzvxa commented Mar 6, 2024

That's great to hear!
I'll keep this issue open as a reminder so we go through the FAQ snippets and update them. I'm not sure how far back the feedkeys function goes, I've never used it in my code so it has to wait until we figure out the compatibility side of things.

@lafrech
Copy link
Author

lafrech commented Mar 6, 2024

OK, I'll be using this on a daily basis from now on and I'll be sure to report back if anything happens (which I'm sure won't happen).
Thanks again.

datMaffin added a commit to datMaffin/my-vimrc-installer that referenced this issue May 12, 2024
Solve weird occasional error message.
See also: preservim/nerdtree#1411
@hippie68
Copy link

hippie68 commented May 14, 2024

I can confirm that this bug exists using the current version of both NERDTree and Vim and that the suggested fix works. I believe it is time that someone with write access updates the README.md file by replacing the defunct command with the fixed one or at least adding the fixed one while making it clear the fix is necessary for Vim 9.

@rzvxa
Copy link
Member

rzvxa commented May 14, 2024

I can confirm that this bug exists using the current version of both NERDTree and Vim and that the suggested fix works. I believe it is time that someone with write access updates the README.md file by replacing the defunct command with the fixed one or at least adding the fixed one while making it clear the fix is necessary for Vim 9.

Yes, you are totally right, I didn't intend this change to take so long. In the last few months, I was too caught up in a deadline and I forgot about changing this. In retrospect closing this issue as you've mentioned wasn't the brightest idea of mine - although I meant good - Leave it to me.

I'll update the FAQ section tonight.

@rzvxa
Copy link
Member

rzvxa commented May 14, 2024

@hippie68 Other than quit is there any other command that is problematic to you? I can also provide some fixes for them while updating the FAQ.

Right now I mostly use neovim so some of these issues might go unnoticed for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants