We can't handle type which it's quickfix or location-list.

253 views
Skip to first unread message

mattn

unread,
Dec 10, 2014, 12:15:27 AM12/10/14
to vim...@googlegroups.com
Hi, list.

We don't have a way to check that the buffer is quickfix or location-list.
Below's patch add "b:qflisttype" to be possible to check the type.

https://gist.github.com/mattn/6c8942fa063c2f3953bc

Please check this.

This patch is based on Hirohito Higashi (a.k.a h_east), he wrote help file too. Thanks.

- Yasuhiro Matsumoto

Enno

unread,
Dec 10, 2014, 3:33:12 AM12/10/14
to vim...@googlegroups.com
Thank you Yasuhiro,

This was lacking ever since.

h_east

unread,
Dec 10, 2014, 4:33:34 AM12/10/14
to vim...@googlegroups.com
Hi mattn!

2014/12/10(Wed) 14:15:27 UTC+9 mattn:
Please update your Gist.
(https://github.com/vim-jp/issues/issues/12)

Best regards,
Hirohito Higashi (a.k.a h_east)

mattn

unread,
Dec 10, 2014, 5:42:39 AM12/10/14
to vim...@googlegroups.com
Done! Thank u

Daniel Hahler

unread,
Dec 11, 2014, 9:42:47 AM12/11/14
to vim...@googlegroups.com
Am Mittwoch, 10. Dezember 2014 06:15:27 UTC+1 schrieb mattn:

> We don't have a way to check that the buffer is quickfix or location-list.
> Below's patch add "b:qflisttype" to be possible to check the type.
>
> https://gist.github.com/mattn/6c8942fa063c2f3953bc


Thanks.

This would have been useful here: https://github.com/bling/vim-airline/pull/656


Regards,
Daniel.

Enno

unread,
Feb 4, 2015, 6:42:57 AM2/4/15
to vim...@googlegroups.com
How about

let b:isLoc = len(getloclist(0)) > 0 ? 1 : 0

inside of a qf filetype window. See :h getloclist() that explains

For a location list window, the displayed location list is returned.

All credit to romainl at https://github.com/romainl/dotvim/blob/44e87b3fbb829145a23bd5b2be1807cc958308e5/bundle/qf/after/ftplugin/qf.vim

h_east

unread,
Feb 4, 2015, 11:12:19 PM2/4/15
to vim...@googlegroups.com
Hi Enno,

2015/2/4(Wed) 20:42:57 UTC+9 Enno:
A location list can be associated with a quickfix window.
In this case, it can not be determined correctly in this work-around.

Try this:
- move Vim source-code directory.
$ cd vim/src
- run vim (no vimrc, no plugin)
$ vim -N -u NONE screen.c

:vimgrep screen *.c
:copen
:echo len(getloclist(0)) " on quickfix window
0 " Correct
:lvimgrep update_screen *.c
:wincmd w
:lopen
:echo len(getloclist(0)) " on location list window
75 " Correct
:wincmd k
:echo len(getloclist(0)) " on quickfix window
75 " Not correct!


Our patch always returns correct value.
Thanks for the response.

Enno

unread,
Feb 5, 2015, 4:25:49 AM2/5/15
to vim...@googlegroups.com
Hello Hirohito,

Yep, this check has several issues. Yours stands, as well as that it fails when the qflist is empty.

More stable seems the following workaround attachched below, originally from

https://groups.google.com/forum/#!msg/vim_use/sfRlnrOwN2M/JAdzwHe51qYJ

but at the same time, it shows that this patch is called for.

--

In ~/.vim/ftplugin/qf.vim:

if exists('s:processing')
finish
endif
let listbufnr = bufnr("%")
let numwindows = winnr('$')
let altwin = winnr('#')
let curwin = winnr()
let s:processing = 1
copen
if curwin == winnr()
call setbufvar(listbufnr, 'isQuickfix', '1')
endif
" close the quickfix list if it was closed when we began
if numwindows != winnr('$')
cclose
endif
" return to quickfix/location list
exe altwin 'wincmd w'
exe curwin 'wincmd w'
unlet s:processing

Then a buffer of file type qf is a quickfix list if b:isQuickfix exists.

h_east

unread,
Feb 5, 2015, 9:46:01 AM2/5/15
to vim...@googlegroups.com
Hi Enno,

2015/2/5(Thu) 18:25:49 UTC+9 Enno:
I like simple way.
I dislike work-around.
I dislike complex way.

Our patch is very simple.
In fact, This patch is only two line.

> set_internal_string_var("b:qflisttype", (curwin->w_llist_ref
> == NULL) ? "quickfix" : "location");

What's dislike you this patch?

Let's go the simple way :-)

Enno

unread,
Feb 5, 2015, 10:15:02 AM2/5/15
to vim...@googlegroups.com
Hello Hirohito,

Your patch is perfect. In fact, by

"... it (= the below code) shows that this patch is called for"

I meant what you just wrote.

The sole value of the Vim script could be as a crutch (= awkward
and complex work-around) for Vim versions without your patch.

Enno
Message has been deleted

Daniel Hahler

unread,
Apr 9, 2016, 10:47:55 AM4/9/16
to vim_dev
Just for information/reference: I've gone ahead and created an issue for Neovim to include this useful patch: https://github.com/neovim/neovim/issues/4550

Nikolay Aleksandrovich Pavlov

unread,
Apr 9, 2016, 12:16:31 PM4/9/16
to vim_dev
You forgot documentation. I guess this will add at least five lines
(empty line, tag, description (two lines), empty line). More with
examples. See `:h b:current_syntax-variable`, but this should be put
somewhere in quickfix.c: e.g. somewhere under `:h w:quickfix_title`,
but please attach tag to the paragraph with description, *not* to the
:copen command like w:quickfix_title (e.g. I would suggest using
b:current_syntax as a reference, but place it where w:quickfix_title
is placed).

>
>> set_internal_string_var("b:qflisttype", (curwin->w_llist_ref

And also tests. I am not familiar with that part of Vim, but
`curwin->w_llist_ref == NULL` looks suspicious: what if you *first*
create a location list and then from the same window create a location
list? This and the opposite (first quickfix) should be tested.

>> == NULL) ? "quickfix" : "location");
>
> What's dislike you this patch?
>
> Let's go the simple way :-)

There is also a question whether this shoud be `b:qflisttype` or
`w:qflisttype`. w:quickfix_title is attached to the window.

>
> Best regards,
> Hirohito Higashi (a.k.a h_east)
>
> --
> --
> You received this message from the "vim_dev" 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_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

h_east

unread,
Apr 9, 2016, 1:10:01 PM4/9/16
to vim_dev
Hi Mr.Emotionless precise machine!

2016-4-10(Sun) 1:16:31 UTC+9 ZyX:
Huh? Is this your humor?
It's not so much fun.

Thanks.

Nikolay Aleksandrovich Pavlov

unread,
Apr 9, 2016, 1:18:18 PM4/9/16
to vim_dev
It is not only a humor. Your “two-line patch” is missing tests and
documentation and thus can be included in neither Vim nor Neovim. And
with them it will no longer be two-line.

h_east

unread,
Apr 9, 2016, 1:30:49 PM4/9/16
to vim_dev
2016-4-10(Sun) 2:18:18 UTC+9 ZyX:
> with them it will no longer be two-line.]

"Core part of" patch is two-lines.
Does not matter.
Reply all
Reply to author
Forward
0 new messages