mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.1.1015: quickfix buffer shows up in list, can't get buffer number
Problem: Quickfix buffer shows up in list, can't get buffer number. Solution: Make the quickfix buffer unlisted when the quickfix window is closed. get the quickfix buffer number with getqflist(). (Yegappan Lakshmanan, closes #4113)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
*eval.txt* For Vim version 8.1. Last change: 2019 Feb 22
|
*eval.txt* For Vim version 8.1. Last change: 2019 Mar 02
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@@ -3538,7 +3538,7 @@ complete_check() *complete_check()*
|
|||||||
|
|
||||||
*confirm()*
|
*confirm()*
|
||||||
confirm({msg} [, {choices} [, {default} [, {type}]]])
|
confirm({msg} [, {choices} [, {default} [, {type}]]])
|
||||||
Confirm() offers the user a dialog, from which a choice can be
|
confirm() offers the user a dialog, from which a choice can be
|
||||||
made. It returns the number of the choice. For the first
|
made. It returns the number of the choice. For the first
|
||||||
choice this is 1.
|
choice this is 1.
|
||||||
Note: confirm() is only supported when compiled with dialog
|
Note: confirm() is only supported when compiled with dialog
|
||||||
@@ -4061,7 +4061,7 @@ expand({expr} [, {nosuf} [, {list}]]) *expand()*
|
|||||||
all "README" files in the current directory and below: >
|
all "README" files in the current directory and below: >
|
||||||
:echo expand("**/README")
|
:echo expand("**/README")
|
||||||
<
|
<
|
||||||
Expand() can also be used to expand variables and environment
|
expand() can also be used to expand variables and environment
|
||||||
variables that are only known in a shell. But this can be
|
variables that are only known in a shell. But this can be
|
||||||
slow, because a shell may be used to do the expansion. See
|
slow, because a shell may be used to do the expansion. See
|
||||||
|expr-env-expand|.
|
|expr-env-expand|.
|
||||||
@@ -4964,10 +4964,16 @@ getloclist({nr} [, {what}]) *getloclist()*
|
|||||||
If the optional {what} dictionary argument is supplied, then
|
If the optional {what} dictionary argument is supplied, then
|
||||||
returns the items listed in {what} as a dictionary. Refer to
|
returns the items listed in {what} as a dictionary. Refer to
|
||||||
|getqflist()| for the supported items in {what}.
|
|getqflist()| for the supported items in {what}.
|
||||||
If {what} contains 'filewinid', then returns the id of the
|
|
||||||
window used to display files from the location list. This
|
In addition to the items supported by |getqflist()| in {what},
|
||||||
field is applicable only when called from a location list
|
the following item is supported by |getloclist()|:
|
||||||
window. See |location-list-file-window| for more details.
|
|
||||||
|
filewinid id of the window used to display files
|
||||||
|
from the location list. This field is
|
||||||
|
applicable only when called from a
|
||||||
|
location list window. See
|
||||||
|
|location-list-file-window| for more
|
||||||
|
details.
|
||||||
|
|
||||||
getmatches() *getmatches()*
|
getmatches() *getmatches()*
|
||||||
Returns a |List| with all matches previously defined by
|
Returns a |List| with all matches previously defined by
|
||||||
@@ -5069,6 +5075,9 @@ getqflist([{what}]) *getqflist()*
|
|||||||
nr get information for this quickfix list; zero
|
nr get information for this quickfix list; zero
|
||||||
means the current quickfix list and "$" means
|
means the current quickfix list and "$" means
|
||||||
the last quickfix list
|
the last quickfix list
|
||||||
|
qfbufnr number of the buffer displayed in the quickfix
|
||||||
|
window. Returns 0 if the quickfix buffer is
|
||||||
|
not present. See |quickfix-buffer|.
|
||||||
size number of entries in the quickfix list
|
size number of entries in the quickfix list
|
||||||
title get the list title |quickfix-title|
|
title get the list title |quickfix-title|
|
||||||
winid get the quickfix |window-ID|
|
winid get the quickfix |window-ID|
|
||||||
@@ -5097,6 +5106,8 @@ getqflist([{what}]) *getqflist()*
|
|||||||
items quickfix list entries. If not present, set to
|
items quickfix list entries. If not present, set to
|
||||||
an empty list.
|
an empty list.
|
||||||
nr quickfix list number. If not present, set to 0
|
nr quickfix list number. If not present, set to 0
|
||||||
|
qfbufnr number of the buffer displayed in the quickfix
|
||||||
|
window. If not present, set to 0.
|
||||||
size number of entries in the quickfix list. If not
|
size number of entries in the quickfix list. If not
|
||||||
present, set to 0.
|
present, set to 0.
|
||||||
title quickfix list title text. If not present, set
|
title quickfix list title text. If not present, set
|
||||||
@@ -11203,14 +11214,14 @@ This does NOT work: >
|
|||||||
commands are skipped.
|
commands are skipped.
|
||||||
When {pattern} is omitted all errors are caught.
|
When {pattern} is omitted all errors are caught.
|
||||||
Examples: >
|
Examples: >
|
||||||
:catch /^Vim:Interrupt$/ " catch interrupts (CTRL-C)
|
:catch /^Vim:Interrupt$/ " catch interrupts (CTRL-C)
|
||||||
:catch /^Vim\%((\a\+)\)\=:E/ " catch all Vim errors
|
:catch /^Vim\%((\a\+)\)\=:E/ " catch all Vim errors
|
||||||
:catch /^Vim\%((\a\+)\)\=:/ " catch errors and interrupts
|
:catch /^Vim\%((\a\+)\)\=:/ " catch errors and interrupts
|
||||||
:catch /^Vim(write):/ " catch all errors in :write
|
:catch /^Vim(write):/ " catch all errors in :write
|
||||||
:catch /^Vim\%((\a\+)\)\=:E123/ " catch error E123
|
:catch /^Vim\%((\a\+)\)\=:E123:/ " catch error E123
|
||||||
:catch /my-exception/ " catch user exception
|
:catch /my-exception/ " catch user exception
|
||||||
:catch /.*/ " catch everything
|
:catch /.*/ " catch everything
|
||||||
:catch " same as /.*/
|
:catch " same as /.*/
|
||||||
<
|
<
|
||||||
Another character can be used instead of / around the
|
Another character can be used instead of / around the
|
||||||
{pattern}, so long as it does not have a special
|
{pattern}, so long as it does not have a special
|
||||||
|
@@ -496,6 +496,7 @@ EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST:
|
|||||||
second quickfix window. If [height] is given the
|
second quickfix window. If [height] is given the
|
||||||
existing window will be resized to it.
|
existing window will be resized to it.
|
||||||
|
|
||||||
|
*quickfix-buffer*
|
||||||
The window will contain a special buffer, with
|
The window will contain a special buffer, with
|
||||||
'buftype' equal to "quickfix". Don't change this!
|
'buftype' equal to "quickfix". Don't change this!
|
||||||
The window will have the w:quickfix_title variable set
|
The window will have the w:quickfix_title variable set
|
||||||
@@ -504,7 +505,11 @@ EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST:
|
|||||||
status line if the value of 'statusline' is adjusted
|
status line if the value of 'statusline' is adjusted
|
||||||
properly. Whenever this buffer is modified by a
|
properly. Whenever this buffer is modified by a
|
||||||
quickfix command or function, the |b:changedtick|
|
quickfix command or function, the |b:changedtick|
|
||||||
variable is incremented.
|
variable is incremented. You can get the number of
|
||||||
|
this buffer using the getqflist() and getloclist()
|
||||||
|
functions by passing the 'qfbufnr' item. For a
|
||||||
|
location list, this buffer is wiped out when the
|
||||||
|
location list is removed.
|
||||||
|
|
||||||
*:lop* *:lopen*
|
*:lop* *:lopen*
|
||||||
:lop[en] [height] Open a window to show the location list for the
|
:lop[en] [height] Open a window to show the location list for the
|
||||||
@@ -670,12 +675,18 @@ using these functions are below:
|
|||||||
" get the quickfix list window id
|
" get the quickfix list window id
|
||||||
:echo getqflist({'winid' : 0}).winid
|
:echo getqflist({'winid' : 0}).winid
|
||||||
|
|
||||||
|
" get the quickfix list window buffer number
|
||||||
|
:echo getqflist({'qfbufnr' : 0}).qfbufnr
|
||||||
|
|
||||||
" get the context of the current location list
|
" get the context of the current location list
|
||||||
:echo getloclist(0, {'context' : 0}).context
|
:echo getloclist(0, {'context' : 0}).context
|
||||||
|
|
||||||
" get the location list window id of the third window
|
" get the location list window id of the third window
|
||||||
:echo getloclist(3, {'winid' : 0}).winid
|
:echo getloclist(3, {'winid' : 0}).winid
|
||||||
|
|
||||||
|
" get the location list window buffer number of the third window
|
||||||
|
:echo getloclist(3, {'qfbufnr' : 0}).qfbufnr
|
||||||
|
|
||||||
" get the file window id of a location list window (winnr: 4)
|
" get the file window id of a location list window (winnr: 4)
|
||||||
:echo getloclist(4, {'filewinid' : 0}).filewinid
|
:echo getloclist(4, {'filewinid' : 0}).filewinid
|
||||||
<
|
<
|
||||||
|
@@ -5907,7 +5907,8 @@ enum {
|
|||||||
QF_GETLIST_SIZE = 0x80,
|
QF_GETLIST_SIZE = 0x80,
|
||||||
QF_GETLIST_TICK = 0x100,
|
QF_GETLIST_TICK = 0x100,
|
||||||
QF_GETLIST_FILEWINID = 0x200,
|
QF_GETLIST_FILEWINID = 0x200,
|
||||||
QF_GETLIST_ALL = 0x3FF,
|
QF_GETLIST_QFBUFNR = 0x400,
|
||||||
|
QF_GETLIST_ALL = 0x7FF,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -5976,6 +5977,17 @@ qf_winid(qf_info_T *qi)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the number of the buffer displayed in the quickfix/location list
|
||||||
|
* window. If there is no buffer associated with the list, then returns 0.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
qf_getprop_qfbufnr(qf_info_T *qi, dict_T *retdict)
|
||||||
|
{
|
||||||
|
return dict_add_number(retdict, "qfbufnr",
|
||||||
|
(qi == NULL) ? 0 : qi->qf_bufnr);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert the keys in 'what' to quickfix list property flags.
|
* Convert the keys in 'what' to quickfix list property flags.
|
||||||
*/
|
*/
|
||||||
@@ -6022,6 +6034,9 @@ qf_getprop_keys2flags(dict_T *what, int loclist)
|
|||||||
if (loclist && dict_find(what, (char_u *)"filewinid", -1) != NULL)
|
if (loclist && dict_find(what, (char_u *)"filewinid", -1) != NULL)
|
||||||
flags |= QF_GETLIST_FILEWINID;
|
flags |= QF_GETLIST_FILEWINID;
|
||||||
|
|
||||||
|
if (dict_find(what, (char_u *)"qfbufnr", -1) != NULL)
|
||||||
|
flags |= QF_GETLIST_QFBUFNR;
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6114,6 +6129,8 @@ qf_getprop_defaults(qf_info_T *qi, int flags, int locstack, dict_T *retdict)
|
|||||||
status = dict_add_number(retdict, "changedtick", 0);
|
status = dict_add_number(retdict, "changedtick", 0);
|
||||||
if ((status == OK) && locstack && (flags & QF_GETLIST_FILEWINID))
|
if ((status == OK) && locstack && (flags & QF_GETLIST_FILEWINID))
|
||||||
status = dict_add_number(retdict, "filewinid", 0);
|
status = dict_add_number(retdict, "filewinid", 0);
|
||||||
|
if ((status == OK) && (flags & QF_GETLIST_QFBUFNR))
|
||||||
|
status = qf_getprop_qfbufnr(qi, retdict);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -6259,6 +6276,8 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
|
|||||||
status = dict_add_number(retdict, "changedtick", qfl->qf_changedtick);
|
status = dict_add_number(retdict, "changedtick", qfl->qf_changedtick);
|
||||||
if ((status == OK) && (wp != NULL) && (flags & QF_GETLIST_FILEWINID))
|
if ((status == OK) && (wp != NULL) && (flags & QF_GETLIST_FILEWINID))
|
||||||
status = qf_getprop_filewinid(wp, qi, retdict);
|
status = qf_getprop_filewinid(wp, qi, retdict);
|
||||||
|
if ((status == OK) && (flags & QF_GETLIST_QFBUFNR))
|
||||||
|
status = qf_getprop_qfbufnr(qi, retdict);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@@ -3110,19 +3110,21 @@ func Xgetlist_empty_tests(cchar)
|
|||||||
call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
|
call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
|
||||||
if a:cchar == 'c'
|
if a:cchar == 'c'
|
||||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
|
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
|
||||||
\ 'items' : [], 'nr' : 0, 'size' : 0,
|
\ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
|
||||||
\ 'title' : '', 'winid' : 0, 'changedtick': 0},
|
\ 'title' : '', 'winid' : 0, 'changedtick': 0},
|
||||||
\ g:Xgetlist({'all' : 0}))
|
\ g:Xgetlist({'all' : 0}))
|
||||||
else
|
else
|
||||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
|
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
|
||||||
\ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
|
\ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
|
||||||
\ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0},
|
\ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
|
||||||
|
\ 'qfbufnr' : 0},
|
||||||
\ g:Xgetlist({'all' : 0}))
|
\ g:Xgetlist({'all' : 0}))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Quickfix window with empty stack
|
" Quickfix window with empty stack
|
||||||
silent! Xopen
|
silent! Xopen
|
||||||
let qfwinid = (a:cchar == 'c') ? win_getid() : 0
|
let qfwinid = (a:cchar == 'c') ? win_getid() : 0
|
||||||
|
let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
|
||||||
call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
|
call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
|
||||||
Xclose
|
Xclose
|
||||||
|
|
||||||
@@ -3154,11 +3156,12 @@ func Xgetlist_empty_tests(cchar)
|
|||||||
if a:cchar == 'c'
|
if a:cchar == 'c'
|
||||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
||||||
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
||||||
|
\ 'qfbufnr' : qfbufnr,
|
||||||
\ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
|
\ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
|
||||||
else
|
else
|
||||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
||||||
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
||||||
\ 'changedtick' : 0, 'filewinid' : 0},
|
\ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
|
||||||
\ g:Xgetlist({'id' : qfid, 'all' : 0}))
|
\ g:Xgetlist({'id' : qfid, 'all' : 0}))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -3175,11 +3178,12 @@ func Xgetlist_empty_tests(cchar)
|
|||||||
if a:cchar == 'c'
|
if a:cchar == 'c'
|
||||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
||||||
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
||||||
\ 'changedtick' : 0}, g:Xgetlist({'nr' : 5, 'all' : 0}))
|
\ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
|
||||||
|
\ g:Xgetlist({'nr' : 5, 'all' : 0}))
|
||||||
else
|
else
|
||||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
||||||
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
||||||
\ 'changedtick' : 0, 'filewinid' : 0},
|
\ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
|
||||||
\ g:Xgetlist({'nr' : 5, 'all' : 0}))
|
\ g:Xgetlist({'nr' : 5, 'all' : 0}))
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
@@ -3912,6 +3916,7 @@ func Xqfbuf_test(cchar)
|
|||||||
Xclose
|
Xclose
|
||||||
" Even after the quickfix window is closed, the buffer should be loaded
|
" Even after the quickfix window is closed, the buffer should be loaded
|
||||||
call assert_true(bufloaded(qfbnum))
|
call assert_true(bufloaded(qfbnum))
|
||||||
|
call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
|
||||||
Xopen
|
Xopen
|
||||||
" Buffer should be reused when opening the window again
|
" Buffer should be reused when opening the window again
|
||||||
call assert_equal(qfbnum, bufnr(''))
|
call assert_equal(qfbnum, bufnr(''))
|
||||||
@@ -3930,7 +3935,7 @@ func Xqfbuf_test(cchar)
|
|||||||
close
|
close
|
||||||
" When the location list window is closed, the buffer name should not
|
" When the location list window is closed, the buffer name should not
|
||||||
" change to 'Quickfix List'
|
" change to 'Quickfix List'
|
||||||
call assert_match(qfbnum . ' h- "\[Location List]"', execute('ls'))
|
call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
|
||||||
call assert_true(bufloaded(qfbnum))
|
call assert_true(bufloaded(qfbnum))
|
||||||
|
|
||||||
" After deleting a location list buffer using ":bdelete", opening the
|
" After deleting a location list buffer using ":bdelete", opening the
|
||||||
@@ -3947,6 +3952,7 @@ func Xqfbuf_test(cchar)
|
|||||||
" removed
|
" removed
|
||||||
call setloclist(0, [], 'f')
|
call setloclist(0, [], 'f')
|
||||||
call assert_false(bufexists(qfbnum))
|
call assert_false(bufexists(qfbnum))
|
||||||
|
call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
|
||||||
|
|
||||||
" When the location list is freed with the location list window open, the
|
" When the location list is freed with the location list window open, the
|
||||||
" location list buffer should not be lost. It should be reused when the
|
" location list buffer should not be lost. It should be reused when the
|
||||||
|
@@ -779,6 +779,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1015,
|
||||||
/**/
|
/**/
|
||||||
1014,
|
1014,
|
||||||
/**/
|
/**/
|
||||||
|
12
src/window.c
12
src/window.c
@@ -2382,18 +2382,24 @@ win_close(win_T *win, int free_buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEAT_GUI
|
#ifdef FEAT_GUI
|
||||||
/* Avoid trouble with scrollbars that are going to be deleted in
|
// Avoid trouble with scrollbars that are going to be deleted in
|
||||||
* win_free(). */
|
// win_free().
|
||||||
if (gui.in_use)
|
if (gui.in_use)
|
||||||
out_flush();
|
out_flush();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
/* Free independent synblock before the buffer is freed. */
|
// Free independent synblock before the buffer is freed.
|
||||||
if (win->w_buffer != NULL)
|
if (win->w_buffer != NULL)
|
||||||
reset_synblock(win);
|
reset_synblock(win);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEAT_QUICKFIX
|
||||||
|
// When the quickfix/location list window is closed, unlist the buffer.
|
||||||
|
if (win->w_buffer != NULL && bt_quickfix(win->w_buffer))
|
||||||
|
win->w_buffer->b_p_bl = FALSE;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close the link to the buffer.
|
* Close the link to the buffer.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user