missing buffer auto command for buffer number 1
smartding opened this issue · comments
Buffer auto commands are missing for the first file I open after starting neovim.
I've setup some buffer auto commands as follows:
local file_icon = subscribe.buf_autocmd(
"el_file_icon",
"BufEnter",
function(win, buf)
local icon = extensions.file_icon(win, buf)
return icon and icon .. ' ' or ''
end
)
local git_branch = subscribe.buf_autocmd(
"el_git_branch",
"BufEnter",
function(win, buf)
local branch = extensions.git_branch(win, buf)
if branch then
return ' ' .. extensions.git_icon() .. ' ' .. branch
end
end
)
Now I start neovim without opening any file, this means I've opened a "no name" buffer with buffer number 1.
We can see the buffer auto commands are correctly set up for this buffer in the following screenshot:
and the status line is showing the correct git branch info and file icon:
Now if I open a file, the git branch name and file icon are missing in status line in the following screenshot:
I list the buffers with the :buffers
command, I can see this new buffer has buffer number 1, but there's no buffer auto commands setup for it.
This problem only happens for the first file I open, which has buffer number 1. If I open a second file, it will have a different buffer number and all the git branch info, file icon are correctly shown in the status line.
This issue has happened to others too, in #31
I think I've found the reason why this happens.
When I open the first file, neovim re-uses the buffer number 1 because I didn't touch the "No Name" buffer,
When neovim wipes out the "No Name" buffer, it deletes all the buffer auto commands associated with it.
When I enter the new buffer, express_line believes it has already setup buffer auto commands for the new buffer, because it has the same buffer number. This is how you end up with a buffer without the buffer auto commands to show the git branch and file icon.
The solution is to reset buffer auto command subscription for a buffer when we notice something is wrong, so that new buffer auto commands will be setup again by require('el.sections').buf_autocmd
next time it's called.
I'll open a pr later.