Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to distinguish the current buffer is location list or quickfix list?

Tags:

vim

I have an autocmd, if ft is qf, it is gonna call some functions to modify the quickfix list by get/setqflist()

I know there are another pair of functions get/setloclist(), to handle the location list.

My problem is, how to know if the current buffer is qf-list or location-list (They both have filetype qf) so that I know which functions should be called?

so far what I can think of is, assume both loc and qf lists are not empty, do some change on qf-list, and compare with current buffer, if the current buffer is changed too, it is qf-list, otherwise it should be location list. Finally roll back the changes. But I feel it is stupid... there should be better way to make the decision.

Did I miss some function/flag/variable ?

like image 982
Kent Avatar asked Aug 29 '13 22:08

Kent


2 Answers

Just for new comers: as of now, there is getwininfo() which returns dicts containing key quickfix which can be used for the check. Also note the loclist key.

Since getwininfo returns a list of dict, you may use:

getwininfo(win_getid())[0]['quickfix']

which is 1 when it is a quickfix or location list window. And

getwininfo(win_getid())[0]['loclist']

which is 1 only when it is a location list.

like image 89
doraemon Avatar answered Oct 02 '22 20:10

doraemon


The w:quickfix_title variable tells you what command was used to generate the list displayed in the window. If the first letter after the colon is an l you are in location list.

like image 32
romainl Avatar answered Oct 02 '22 19:10

romainl