fix(buffer): close the harpoon window when opening netrw inside it #489
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #480.
Explanation of the code:
Note that this explanation talks only about netrw, but some other things could be causing the same problem as well.
First of all the
BufLeave
autocmd does not work in this case (honestly I don't know why, my guess is it has to do something with the harpoon beingscratch
,unlisted
buffer, couldn't find much in the docs). A possible solution would be to use theBufHidden
autocmd. I tried, but it doesn't work, again probably because ofscratch
/unlisted
properties of the buffer. So the hacky solution is to useFileType
autocmd and look for the buffers that satisfy the following conditions:If such a buffer exists, we want to close the harpoon window and buffer (ui:toggle_qucik_menu()). It would look something like this:
But then the new problem emerges, the netrw text gets 'merged' with the buffer that we were supposed to go to after closing the harpoon window. My guess (I could be totally wrong on this one) is that the following happens:
FileType
autocmd closes the window when thefiletype
option for netrw has been set (theFileType
event fires when thefiletype
option is set, according to the docs)So the final solution looks the same as the above autocmd but the callback is wrapped inside
vim.schedule
. Again I could be totally wrong but I guess that whatvim.schedule
does is wait for neovim's main event loop (according to the docs), which gets free after it handles the loading of the netrw buffer, and then calls the function we specified. netrw gets loaded inside of the harpoon window -> the harpoon window closes -> it looks like it's instant and everyone is happy.I had the same problem in one of my projects, so if you need any additional info on this problem:
If someone who ackchyually knows this stuff comes here and tells me that my guesses were completely wrong then I guess at least I tried to help and the solution does the job. BUT if I'm right... Oh, boy I'm the f'ing genius.