0

Recently I've been playing with my statusline and I'm coming to a point where I want to set a different highlighting group for the statusline of my quickfix window, location list window, and the other windows.

To do so I need to programmatically determine what type of buffer I am in. To differentiate between the "regular" buffers and the quickfix/location buffers I can easily test if &buftype returns quickfix.

The problem is to differentiate quickfix and location list since &buftype returns quickfix for both buffers.

I've seen this SO question which provides three solutions that don't satisfy me:

  • The w:quickfix_title variable tells you what command was used to generate the list displayed in the window. This is not what I'm looking for since I can open my location list with different commands other than lopen (SyntasticCheck would be an example)
  • Parsing the output of ls, matching the buffer number and checking if the name of the buffer matches Location List or Quickfix List. That could be a solution but I use different versions of Vim in different languages, so matching against all the possible names (e.g. Location List and Liste des emplacements) is not ideal.
  • The third answer is about closing and reopening the windows to test if you were in one of them, this is really not convenient for a statusline setting.

So here are my two questions:

  • Is there another way to easily differentiate the quickfix buffer from the location list one?
  • If not what would be the best way to set a statusline background depending on the type of quickfix window you're in?
2

Ah ah. I've just implemented a function on the subject very recently: https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/qf.vim#L125

If your version of Vim is recent enough, the discriminating information is stored in getwininfo()[some_winnr].loclist.

Otherwise, you'll have to execute :ls! and check whether you see "[Quickfix List]" or "[Locsomething List]" after the buffer number.

If you have i18n issues (does this means I've missed this problem because my vim flavours are much too recent?), again, in my library plugin, you'll find lh#po#context(...).translate(...) -- that won't work on Windows though :(

  • Damn I should have read :h getwininfo() it was all I needed! About the I18N my version is a vim 8.0 patch 1376 and ls returns a name in French I don't know if that was changed in later versions. – statox Jun 27 '18 at 13:22
  • I force $LANG & all to be in English as I can't stand g++ speaking French. But something is odd, while LANG=fr_FR.UTF-8 TEXTDOMAINDIR=$HOME/local/rh7/vim/share/vim/vim81/lang TEXTDOMAIN=vim bash -c 'echo $"[Quickfix List]"' works fine. (export LANG=fr_FR.UTF-8; export TEXTDOMAINDIR=$HOME/local/rh7/vim/share/vim/vim81/lang ; export TEXTDOMAIN=vim; echo $"[Quickfix List]") doesn't... I guess I'll have to fix my routines. – Luc Hermitte Jun 27 '18 at 13:39
  • Weird indeed... I have to say that I got used to ugly French messages because I didn't have the motivation to mess with my language settings :) – statox Jun 27 '18 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.