willothy / nvim-cokeline

:nose: A Neovim bufferline for people with addictive personalities
MIT License
554 stars 38 forks source link

nil value errors when there are no listed buffers #9

Closed cseickel closed 3 years ago

cseickel commented 3 years ago

If I don't set hide_when_one_buffer = true, and I open nvim without a file, I get errors about nil values and cokeline fails to load properly. I use Startify and normally open nvim without arguments and then launch a session from Startify (which is an unlisted buffer) so I hit that every time.

Here is the error I get: E5108: Error executing lua ...ack/packer/start/cokeline.nvim/lua/cokeline/cokeline.lua:83: attempt to perform arithmetic on field 'width' (a nil value)

I worked around the issue by adding this check to _G.cokeline() in init.lua:

... 

function _G.cokeline() 
    state.buffers = buffers.get_listed(state.order) 
    if #state.buffers < 1 then
        opt.showtabline = 0
        return
    end

...

I'm not sure if that's the ideal solution for everyone or not, but it works for me.

cseickel commented 3 years ago

Actually, that solution is not good because it disabled the tabline permanently. A better workaround is to return an empty string just before the cokeline:render function if there are no listed buffers.

noib3 commented 3 years ago

c430ab62d7038adae282935558f5962d989c3715 should fix this. Could you test it?

cseickel commented 3 years ago

That is working perfectly now, thanks!