Tuesday, September 3, 2013

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

On Friday, August 30, 2013 4:37:15 PM UTC-5, Kent wrote:
> Hi all,
>
>
>
>
> 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, 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.
>
>
>
>
> the location list and qf list both could be empty or both were filled with data.
>
>
>
>
> Did I miss some function/flag/variable ?
>
>
>
>
>
>
> In fact I've asked the question at SO:
> http://stackoverflow.com/questions/18522086/what-is-the-best-way-to-distinguish-the-current-buffer-is-location-list-or-quick
>
>
>
>
>
> one answer from @romainl suggested using the variable w:quickfix_title. check if the command was beginning with ":l(L)" after I tested a little there are some cases need to be careful:
>
>
>
>
> - the qf/loc list was filled by a script, (using setqflist()/setloclist()), the value of the variable would be the function name. so this could be checked too
> - if user manually open an empty quickfixlist, e.g. :copen , reading the variable will throw exception. it could be ok too, because it seems that we cannot manually open an empty location list by :lopen.
>
>
>
>
> - I don't know if there are other (corner) situations, will break the check.
>
>
>
>
> what would be the best way to detect, which list window I am in?
>
>
>
>
> thanx in advance
>
>
>
>
> Kent

The only reliable way I've found, is to store the current window number, then issue a :copen command. If the active window number changes, you were in the location list and not the quickfix list. If it doesn't change, you were already in the quickfix list.

You also want to store the number of open windows, and compare that to the new number of open windows. Then you can close the quickfix window if it wasn't already open.

Finally you can jump back to the location list (if needed) using the stored window number and "wincmd w".

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment