1
0
forked from aniani/vim

patch 7.4.2215

Problem:    It's not easy to find out if a window is a quickfix or location
            list window.
Solution:   Add "loclist" and "quickfix" entries to the dict returnec by
            getwininfo(). (Yegappan Lakshmanan)
This commit is contained in:
Bram Moolenaar
2016-08-15 22:16:25 +02:00
parent 16350cb979
commit 386600f0cb
4 changed files with 73 additions and 17 deletions

View File

@@ -4584,14 +4584,16 @@ getwininfo([{winid}]) *getwininfo()*
pages is returned. pages is returned.
Each List item is a Dictionary with the following entries: Each List item is a Dictionary with the following entries:
nr window number. bufnum number of buffer in the window
tpnr tab page number. height window height
winid window ID. loclist 1 if showing a location list
height window height. nr window number
width window width. options dictionary of window local options
bufnum number of buffer in the window. quickfix 1 if quickfix or location list window
options dictionary of window local options. tpnr tab page number
variables dictionary of window local variables. variables dictionary of window local variables
width window width
winid window ID
getwinvar({winnr}, {varname} [, {def}]) *getwinvar()* getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
Like |gettabwinvar()| for the current tabpage. Like |gettabwinvar()| for the current tabpage.

View File

@@ -4027,7 +4027,7 @@ f_getbufinfo(typval_T *argvars, typval_T *rettv)
} }
/* Return information about all the buffers or a specified buffer */ /* Return information about all the buffers or a specified buffer */
for (buf = firstbuf; buf != NULL; buf = buf->b_next) FOR_ALL_BUFFERS(buf)
{ {
if (argbuf != NULL && argbuf != buf) if (argbuf != NULL && argbuf != buf)
continue; continue;
@@ -5030,7 +5030,7 @@ f_gettabinfo(typval_T *argvars, typval_T *rettv)
#ifdef FEAT_WINDOWS #ifdef FEAT_WINDOWS
tabpage_T *tp, *tparg = NULL; tabpage_T *tp, *tparg = NULL;
dict_T *d; dict_T *d;
int tpnr = 1; int tpnr = 0;
if (rettv_list_alloc(rettv) != OK) if (rettv_list_alloc(rettv) != OK)
return; return;
@@ -5044,8 +5044,9 @@ f_gettabinfo(typval_T *argvars, typval_T *rettv)
} }
/* Get information about a specific tab page or all tab pages */ /* Get information about a specific tab page or all tab pages */
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, tpnr++) FOR_ALL_TABPAGES(tp)
{ {
tpnr++;
if (tparg != NULL && tp != tparg) if (tparg != NULL && tp != tparg)
continue; continue;
d = get_tabpage_info(tp, tpnr); d = get_tabpage_info(tp, tpnr);
@@ -5131,6 +5132,12 @@ get_win_info(win_T *wp, short tpnr, short winnr)
dict_add_nr_str(dict, "width", wp->w_width, NULL); dict_add_nr_str(dict, "width", wp->w_width, NULL);
dict_add_nr_str(dict, "bufnum", wp->w_buffer->b_fnum, NULL); dict_add_nr_str(dict, "bufnum", wp->w_buffer->b_fnum, NULL);
#ifdef FEAT_QUICKFIX
dict_add_nr_str(dict, "quickfix", bt_quickfix(wp->w_buffer), NULL);
dict_add_nr_str(dict, "loclist",
(bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL), NULL);
#endif
/* Copy window variables */ /* Copy window variables */
vars = dict_copy(wp->w_vars, TRUE, 0); vars = dict_copy(wp->w_vars, TRUE, 0);
if (vars != NULL) if (vars != NULL)
@@ -5155,7 +5162,7 @@ f_getwininfo(typval_T *argvars, typval_T *rettv)
tabpage_T *tp; tabpage_T *tp;
win_T *wp = NULL, *wparg = NULL; win_T *wp = NULL, *wparg = NULL;
dict_T *d; dict_T *d;
short tabnr, winnr; short tabnr = 0, winnr;
#endif #endif
if (rettv_list_alloc(rettv) != OK) if (rettv_list_alloc(rettv) != OK)
@@ -5172,13 +5179,13 @@ f_getwininfo(typval_T *argvars, typval_T *rettv)
/* Collect information about either all the windows across all the tab /* Collect information about either all the windows across all the tab
* pages or one particular window. * pages or one particular window.
*/ */
tabnr = 1; FOR_ALL_TABPAGES(tp)
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, tabnr++)
{ {
wp = (tp == curtab) ? firstwin : tp->tp_firstwin; tabnr++;
winnr = 1; winnr = 0;
for (; wp; wp = wp->w_next, winnr++) FOR_ALL_WINDOWS_IN_TAB(tp, wp)
{ {
winnr++;
if (wparg != NULL && wp != wparg) if (wparg != NULL && wp != wparg)
continue; continue;
d = get_win_info(wp, tabnr, winnr); d = get_win_info(wp, tabnr, winnr);

View File

@@ -14,6 +14,27 @@ function Test_getbufwintabinfo()
hide enew hide enew
call assert_equal(3, len(getbufinfo({'bufloaded':1}))) call assert_equal(3, len(getbufinfo({'bufloaded':1})))
set tabstop&vim
let b:editor = 'vim'
let l = getbufinfo('%')
call assert_equal(bufnr('%'), l[0].nr)
call assert_equal(8, l[0].options.tabstop)
call assert_equal('vim', l[0].variables.editor)
call assert_notequal(-1, index(l[0].windows, bufwinid('%')))
if has('signs')
call append(0, ['Linux', 'Windows', 'Mac'])
sign define Mark text=>> texthl=Search
exe "sign place 2 line=3 name=Mark buffer=" . bufnr('%')
let l = getbufinfo('%')
call assert_equal(2, l[0].signs[0].id)
call assert_equal(3, l[0].signs[0].lnum)
call assert_equal('Mark', l[0].signs[0].name)
sign unplace *
sign undefine Mark
enew!
endif
only only
let w1_id = win_getid() let w1_id = win_getid()
new new
@@ -21,18 +42,42 @@ function Test_getbufwintabinfo()
tabnew | let w3_id = win_getid() tabnew | let w3_id = win_getid()
new | let w4_id = win_getid() new | let w4_id = win_getid()
new | let w5_id = win_getid() new | let w5_id = win_getid()
call setwinvar(0, 'signal', 'green')
tabfirst tabfirst
let winlist = getwininfo() let winlist = getwininfo()
call assert_equal(5, len(winlist)) call assert_equal(5, len(winlist))
call assert_equal(winbufnr(2), winlist[1].bufnum)
call assert_equal(winheight(2), winlist[1].height)
call assert_equal(1, winlist[2].nr)
call assert_equal('auto', winlist[0].options.signcolumn)
call assert_equal(2, winlist[3].tpnr) call assert_equal(2, winlist[3].tpnr)
call assert_equal('green', winlist[2].variables.signal)
call assert_equal(winwidth(1), winlist[0].width)
call assert_equal(w4_id, winlist[3].winid)
let winfo = getwininfo(w5_id)[0] let winfo = getwininfo(w5_id)[0]
call assert_equal(2, winfo.tpnr) call assert_equal(2, winfo.tpnr)
call assert_equal([], getwininfo(3)) call assert_equal([], getwininfo(3))
call settabvar(1, 'space', 'build')
let tablist = gettabinfo() let tablist = gettabinfo()
call assert_equal(2, len(tablist)) call assert_equal(2, len(tablist))
call assert_equal(3, len(tablist[1].windows)) call assert_equal(3, len(tablist[1].windows))
call assert_equal(2, tablist[1].nr)
call assert_equal('build', tablist[0].variables.space)
call assert_equal(w2_id, tablist[0].windows[0])
call assert_equal([], gettabinfo(3)) call assert_equal([], gettabinfo(3))
tabonly | only tabonly | only
lexpr ''
lopen
copen
let winlist = getwininfo()
call assert_false(winlist[0].quickfix)
call assert_false(winlist[0].loclist)
call assert_true(winlist[1].quickfix)
call assert_true(winlist[1].loclist)
call assert_true(winlist[2].quickfix)
call assert_false(winlist[2].loclist)
wincmd t | only
endfunction endfunction

View File

@@ -763,6 +763,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 */
/**/
2215,
/**/ /**/
2214, 2214,
/**/ /**/