Friday, August 30, 2013

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

On 30 August 2013, Kent <kent.yuan@gmail.com> 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?

There is no good way to do that. As a partial workaround, you might
try calling getloclist(0), it should return [] if the current buffer is
a quickfix list, and something non-empty if it's a loclist. But this
may or may not work from an autocmd. Also, the filetype of the quickfix
buffer may be empty at that point if the quickfix has just been created.

[...]
> Did I miss some function/flag/variable ?

Not really. Working with loclists is one of the darker corners of
Vim, using them for anything else than the built-in make, grep, and
friends is a huge pain.

[...]
> one answer from @romainl suggested using the variable w:quickfix_title.
> check if the command was beginning with ":l(L)"
[...]

That's even less reliable: if you create loclists with setloclist()
w:quickfix_title can be empty, or ':setloclist()', or something entirely
different.

/lcd

--
--
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: