1
0
forked from aniani/vim

patch 7.4.1558

Problem:    It is not easy to find out what windows display a buffer.
Solution:   Add win_findbuf().
This commit is contained in:
Bram Moolenaar
2016-03-13 19:04:51 +01:00
parent 86edef664e
commit 9cdf86b86f
6 changed files with 43 additions and 0 deletions

View File

@@ -2149,6 +2149,7 @@ values( {dict}) List values in {dict}
virtcol( {expr}) Number screen column of cursor or mark
visualmode( [expr]) String last visual mode used
wildmenumode() Number whether 'wildmenu' mode is active
win_findbuf( {bufnr}) List find windows containing {bufnr}
win_getid( [{win} [, {tab}]]) Number get window ID for {win} in {tab}
win_gotoid( {expr}) Number go to window with ID {expr}
win_id2tabwin( {expr}) List get tab and window nr from window ID
@@ -7176,6 +7177,10 @@ wildmenumode() *wildmenumode()*
(Note, this needs the 'wildcharm' option set appropriately).
win_findbuf({bufnr}) *win_findbuf()*
Returns a list with window IDs for windows that contain buffer
{bufnr}. When there is none the list is empty.
win_getid([{win} [, {tab}]]) *win_getid()*
Get the window ID for the specified window.
When {win} is missing use the current window.

View File

@@ -807,6 +807,7 @@ static void f_values(typval_T *argvars, typval_T *rettv);
static void f_virtcol(typval_T *argvars, typval_T *rettv);
static void f_visualmode(typval_T *argvars, typval_T *rettv);
static void f_wildmenumode(typval_T *argvars, typval_T *rettv);
static void f_win_findbuf(typval_T *argvars, typval_T *rettv);
static void f_win_getid(typval_T *argvars, typval_T *rettv);
static void f_win_gotoid(typval_T *argvars, typval_T *rettv);
static void f_win_id2tabwin(typval_T *argvars, typval_T *rettv);
@@ -8388,6 +8389,7 @@ static struct fst
{"virtcol", 1, 1, f_virtcol},
{"visualmode", 0, 1, f_visualmode},
{"wildmenumode", 0, 0, f_wildmenumode},
{"win_findbuf", 1, 1, f_win_findbuf},
{"win_getid", 0, 2, f_win_getid},
{"win_gotoid", 1, 1, f_win_gotoid},
{"win_id2tabwin", 1, 1, f_win_id2tabwin},
@@ -12668,6 +12670,16 @@ f_getwinposx(typval_T *argvars UNUSED, typval_T *rettv)
#endif
}
/*
* "win_findbuf()" function
*/
static void
f_win_findbuf(typval_T *argvars, typval_T *rettv)
{
if (rettv_list_alloc(rettv) != FAIL)
win_findbuf(argvars, rettv->vval.v_list);
}
/*
* "win_getid()" function
*/

View File

@@ -87,4 +87,5 @@ int win_getid(typval_T *argvars);
int win_gotoid(typval_T *argvars);
void win_id2tabwin(typval_T *argvars, list_T *list);
int win_id2win(typval_T *argvars);
void win_findbuf(typval_T *argvars, list_T *list);
/* vim: set ft=c : */

View File

@@ -5,6 +5,7 @@ func Test_win_getid()
let id1 = win_getid()
split two
let id2 = win_getid()
let bufnr2 = bufnr('%')
split three
let id3 = win_getid()
tabnew
@@ -12,6 +13,7 @@ func Test_win_getid()
let id4 = win_getid()
split five
let id5 = win_getid()
let bufnr5 = bufnr('%')
tabnext
wincmd w
@@ -67,5 +69,11 @@ func Test_win_getid()
call assert_equal([1, nr2], win_id2tabwin(id2))
call assert_equal([2, nr4], win_id2tabwin(id4))
call assert_equal([], win_findbuf(9999))
call assert_equal([id2], win_findbuf(bufnr2))
call win_gotoid(id5)
split
call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
only!
endfunc

View File

@@ -743,6 +743,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1558,
/**/
1557,
/**/

View File

@@ -7297,4 +7297,19 @@ win_id2win(typval_T *argvars)
}
return 0;
}
void
win_findbuf(typval_T *argvars, list_T *list)
{
win_T *wp;
tabpage_T *tp;
int bufnr = get_tv_number(&argvars[0]);
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
wp != NULL; wp = wp->w_next)
if (wp->w_buffer->b_fnum == bufnr)
list_append_number(list, wp->w_id);
}
#endif