itchyny / lightline.vim

A light and configurable statusline/tabline plugin for Vim
MIT License
6.75k stars 315 forks source link

How to ignore expanded components #378

Closed sethen closed 5 years ago

sethen commented 5 years ago

I see the last time this question was asked was approximately 3 years ago, but that issue didn't really solve my problem.

Essentially when I use component_function I am able to write specific methods that can look at the filetype using &ft and decide when I want to and show hide certain components. This isn't the same for component_expand. I want to hide the lineinfo when I have things up like NERDTree or help documents because it doesn't really help me at all in those times. You can take a look at https://github.com/sethen/dotfiles/blob/master/os/init.vim#L203 to see how I am doing this in component_functions -- I want to do the same for component_expand for certain things.

Is there any way to write functions in component_expand and hide them in specific situations or is just an all or nothing approach?

itchyny commented 5 years ago

If the function returns empty string, the component should be hided. This should behave as same with component_expand. By the way I'm afraid the function LightlineLineInfo is missing in your configuration.

sethen commented 5 years ago

If the function returns empty string, the component should be hided. This should behave as same with component_expand. By the way I'm afraid the function LightlineLineInfo is missing in your configuration.

Right, it's not there because when I wrote the function and put it in component_expand it didn't work correctly. Let me write the function and push it up and I will update this issue with the new method so you can see.

sethen commented 5 years ago

@itchyny Okay, so here is the missing method: https://github.com/sethen/dotfiles/blob/master/os/init.vim#L317

If you were to use this in nvim, the lineinfo gets shown in places where it shouldn't be shown. All of the other methods that are in component_function work fine in regards to hiding things by returning an empty string and not showing them in NERDTree, help and startify.

Applying the same logic with component_expand does not work. When I am focused on the buffer where the lineinfo should be shown I am able to see lineinfo in an inactive state that should be hidden in NERDTree, help and startify.

itchyny commented 5 years ago

If you want to hide the lineinfo component using component_function, try

function! LightlineLineInfo()
  if IsIgnoringStatus()
    return ''
  endif

  return printf('%d:%-2d', line('.'), col('.'))
endfunction

I think you don't need to use expanded component for hiding the lineinfo in specific buffers.

The functions in component_expand are evaluated before setting to &statusline and never be re-evaluated until some window focus changes. The functions are called on windows are created so it might not work when you use filetype information, which may be set after lightline sets the statusline. You can call lightline#update() to re-evaluate them.

sethen commented 5 years ago

Ah, I see! Well the code you provided is working so I thank you for that. I wasn't aware of the lightline lifecycle so thank you for bringing that to my attention! All is good!