Lightline.vim: component_expand in tabline not working as expected

Created on 13 Mar 2016  路  9Comments  路  Source: itchyny/lightline.vim

When I assign a component_expand function in tabline, it only seems to be called on tab operations (e.g. :tabnew, :tabnext), whereas if the same function is declared as a component_function it gets called as expected (e.g. on :enew).

Here bufferline is only updated on tab operations:

let g:lightline = {
      \ 'tabline': {
      \   'left': [ ['tabs'], ['bufferline'] ],
      \   'right': [ [ 'close' ] ]
      \ },
      \ 'component_expand': {
      \   'bufferline': 'MyBufferline',
      \ },
      \ 'component_type': {
      \   'bufferline': 'tabsel',
      \ },

Here bufferline is updated as expected (although highlighting is broken, which is why I want to use component_expand)

let g:lightline = {
      \ 'tabline': {
      \   'left': [ ['tabs'], ['bufferline'] ],
      \   'right': [ [ 'close' ] ]
      \ },
      \ 'component_function': {
      \   'bufferline': 'MyBufferline',
      \ },

Here's the bufferline function, if it matters:

function! MyBufferline()
  call bufferline#refresh_status()
  let rlen = 4*tabpagenr('$') + len(&fenc) + 8
  call bufferline#trim_status_info(&columns - rlen)

  " If using component_function
  return bufferline#get_echo_string()

  " If using component_expand
  "return [ g:bufferline_status_info.before, g:bufferline_status_info.current, g:bufferline_status_info.after]
endfunction
configuration enhancement

Most helpful comment

Thank you for your detailed issue report. I changed the logic of lightline and confirmed the following configuration works, keeping the performance for user who does not configure the tabline.

let g:lightline = {
      \ 'tabline': {
      \   'left': [ ['bufferline'] ]
      \ },
      \ 'component_expand': {
      \   'bufferline': 'LightlineBufferline',
      \ },
      \ 'component_type': {
      \   'bufferline': 'tabsel',
      \ },
      \ }

function! LightlineBufferline()
  call bufferline#refresh_status()
  return [ g:bufferline_status_info.before, g:bufferline_status_info.current, g:bufferline_status_info.after]
endfunction

All 9 comments

Thank you for your detailed issue report. I changed the logic of lightline and confirmed the following configuration works, keeping the performance for user who does not configure the tabline.

let g:lightline = {
      \ 'tabline': {
      \   'left': [ ['bufferline'] ]
      \ },
      \ 'component_expand': {
      \   'bufferline': 'LightlineBufferline',
      \ },
      \ 'component_type': {
      \   'bufferline': 'tabsel',
      \ },
      \ }

function! LightlineBufferline()
  call bufferline#refresh_status()
  return [ g:bufferline_status_info.before, g:bufferline_status_info.current, g:bufferline_status_info.after]
endfunction

Thanks for fixing this so quickly!

Trying to understand if I am missing something.

I pasted the config into vimrc and all I get is a blank bar and the close button. Clicking on the bar does switch buffers, double clicking adds a new one, and double clicking on the X closes them. Is the bar supposed to be blank though? I tried copying the bar and it's just spaces, so it's not a colorscheme issue.

I forgot about that. Thanks. The other issue now is that it breaks the colorschemes. No matter what I set it to, it defaults. Taking out the code above restores the chosen scheme.

Please let me see your configuration. I don't understand what actually configuration you mean by what I set it to.

Basically if I add this, my colorschemes won't load:

let g:lightline = {
      \ 'tabline': {
      \   'left': [ ['bufferline'] ]
      \ },
      \ 'component_expand': {
      \   'bufferline': 'LightlineBufferline',
      \ },
      \ 'component_type': {
      \   'bufferline': 'tabsel',
      \ },
      \ }

function! LightlineBufferline()
  call bufferline#refresh_status()
  return [ g:bufferline_status_info.before, g:bufferline_status_info.current, g:bufferline_status_info.after]
endfunction

Deleting that restores my colors.

And by setting it, I mean setting the colorscheme by placing this in vimrc:

let g:lightline = {
    \ 'colorscheme': 'wombat',
    \ }

I can paste the whole vimrc if you want, but it's a really long file.

let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ 'tabline': {
      \   'left': [ ['bufferline'] ]
      \ },
      \ 'component_expand': {
      \   'bufferline': 'LightlineBufferline',
      \ },
      \ 'component_type': {
      \   'bufferline': 'tabsel',
      \ },
      \ }

Oh I see. Basically I overrode the colorscheme when I set g:lightline twice. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmedelgabri picture ahmedelgabri  路  3Comments

dessaya picture dessaya  路  3Comments

mrbig033 picture mrbig033  路  4Comments

kbc8090 picture kbc8090  路  3Comments

8i8 picture 8i8  路  3Comments