mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 02:16:31 +00:00
vim-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 vim/vim#4113)
647e24ba3d
This commit is contained in:

committed by
zeertzjq

parent
6c26ab71ce
commit
163ec00f44
@@ -6019,6 +6019,15 @@ static int qf_winid(qf_info_T *qi)
|
||||
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(const qf_info_T *qi, dict_T *retdict)
|
||||
FUNC_ATTR_NONNULL_ARG(2)
|
||||
{
|
||||
return tv_dict_add_nr(retdict, S_LEN("qfbufnr"),
|
||||
(qi == NULL) ? 0 : qi->qf_bufnr);
|
||||
}
|
||||
|
||||
/// Convert the keys in 'what' to quickfix list property flags.
|
||||
static int qf_getprop_keys2flags(const dict_T *what, bool loclist)
|
||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
@@ -6062,6 +6071,9 @@ static int qf_getprop_keys2flags(const dict_T *what, bool loclist)
|
||||
if (loclist && tv_dict_find(what, S_LEN("filewinid")) != NULL) {
|
||||
flags |= QF_GETLIST_FILEWINID;
|
||||
}
|
||||
if (tv_dict_find(what, S_LEN("qfbufnr")) != NULL) {
|
||||
flags |= QF_GETLIST_QFBUFNR;
|
||||
}
|
||||
if (tv_dict_find(what, S_LEN("quickfixtextfunc")) != NULL) {
|
||||
flags |= QF_GETLIST_QFTF;
|
||||
}
|
||||
@@ -6153,6 +6165,9 @@ static int qf_getprop_defaults(qf_info_T *qi, int flags, int locstack, dict_T *r
|
||||
if ((status == OK) && locstack && (flags & QF_GETLIST_FILEWINID)) {
|
||||
status = tv_dict_add_nr(retdict, S_LEN("filewinid"), 0);
|
||||
}
|
||||
if ((status == OK) && (flags & QF_GETLIST_QFBUFNR)) {
|
||||
status = qf_getprop_qfbufnr(qi, retdict);
|
||||
}
|
||||
if ((status == OK) && (flags & QF_GETLIST_QFTF)) {
|
||||
status = tv_dict_add_str(retdict, S_LEN("quickfixtextfunc"), "");
|
||||
}
|
||||
@@ -6322,6 +6337,9 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
|
||||
if ((status == OK) && (wp != NULL) && (flags & QF_GETLIST_FILEWINID)) {
|
||||
status = qf_getprop_filewinid(wp, qi, retdict);
|
||||
}
|
||||
if ((status == OK) && (flags & QF_GETLIST_QFBUFNR)) {
|
||||
status = qf_getprop_qfbufnr(qi, retdict);
|
||||
}
|
||||
if ((status == OK) && (flags & QF_GETLIST_QFTF)) {
|
||||
status = qf_getprop_qftf(qfl, retdict);
|
||||
}
|
||||
|
@@ -3548,20 +3548,21 @@ func Xgetlist_empty_tests(cchar)
|
||||
call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
|
||||
if a:cchar == 'c'
|
||||
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,
|
||||
\ 'quickfixtextfunc' : ''}, g:Xgetlist({'all' : 0}))
|
||||
else
|
||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
|
||||
\ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
|
||||
\ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
|
||||
\ 'quickfixtextfunc' : ''},
|
||||
\ 'qfbufnr' : 0, 'quickfixtextfunc' : ''},
|
||||
\ g:Xgetlist({'all' : 0}))
|
||||
endif
|
||||
|
||||
" Quickfix window with empty stack
|
||||
silent! Xopen
|
||||
let qfwinid = (a:cchar == 'c') ? win_getid() : 0
|
||||
let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
|
||||
call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
|
||||
Xclose
|
||||
|
||||
@@ -3593,12 +3594,12 @@ func Xgetlist_empty_tests(cchar)
|
||||
if a:cchar == 'c'
|
||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
||||
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
||||
\ 'quickfixtextfunc' : '',
|
||||
\ 'qfbufnr' : qfbufnr, 'quickfixtextfunc' : '',
|
||||
\ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
|
||||
else
|
||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
||||
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
||||
\ 'changedtick' : 0, 'filewinid' : 0,
|
||||
\ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0,
|
||||
\ 'quickfixtextfunc' : ''},
|
||||
\ g:Xgetlist({'id' : qfid, 'all' : 0}))
|
||||
endif
|
||||
@@ -3616,12 +3617,12 @@ func Xgetlist_empty_tests(cchar)
|
||||
if a:cchar == 'c'
|
||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
||||
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
||||
\ 'changedtick' : 0,
|
||||
\ 'changedtick' : 0, 'qfbufnr' : qfbufnr,
|
||||
\ 'quickfixtextfunc' : ''}, g:Xgetlist({'nr' : 5, 'all' : 0}))
|
||||
else
|
||||
call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
|
||||
\ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
|
||||
\ 'changedtick' : 0, 'filewinid' : 0,
|
||||
\ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0,
|
||||
\ 'quickfixtextfunc' : ''}, g:Xgetlist({'nr' : 5, 'all' : 0}))
|
||||
endif
|
||||
endfunc
|
||||
@@ -4456,6 +4457,7 @@ func Xqfbuf_test(cchar)
|
||||
Xclose
|
||||
" Even after the quickfix window is closed, the buffer should be loaded
|
||||
call assert_true(bufloaded(qfbnum))
|
||||
call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
|
||||
Xopen
|
||||
" Buffer should be reused when opening the window again
|
||||
call assert_equal(qfbnum, bufnr(''))
|
||||
@@ -4474,7 +4476,7 @@ func Xqfbuf_test(cchar)
|
||||
close
|
||||
" When the location list window is closed, the buffer name should not
|
||||
" 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))
|
||||
|
||||
" After deleting a location list buffer using ":bdelete", opening the
|
||||
@@ -4491,6 +4493,7 @@ func Xqfbuf_test(cchar)
|
||||
" removed
|
||||
call setloclist(0, [], 'f')
|
||||
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
|
||||
" location list buffer should not be lost. It should be reused when the
|
||||
|
@@ -2596,6 +2596,11 @@ int win_close(win_T *win, bool free_buf, bool force)
|
||||
reset_synblock(win);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* Close the link to the buffer.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user