Patch 7.4.1558
Problem: It is not easy to find out what windows display a buffer.
Solution: Add win_findbuf().
Files: src/eval.c, src/window.c, src/proto/window.pro,
src/testdir/test_window_id.vim, runtime/doc/eval.txt
*** ../vim-7.4.1557/src/eval.c 2016-03-13 18:06:59.528803729 +0100
--- src/eval.c 2016-03-13 18:35:15.843427789 +0100
***************
*** 807,812 ****
--- 807,813 ----
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,8393 ****
--- 8389,8395 ----
{"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},
***************
*** 12669,12674 ****
--- 12671,12686 ----
}
/*
+ * "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
*/
static void
*** ../vim-7.4.1557/src/window.c 2016-03-13 18:06:59.524803771 +0100
--- src/window.c 2016-03-13 18:43:57.906073860 +0100
***************
*** 7297,7300 ****
--- 7297,7315 ----
}
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
*** ../vim-7.4.1557/src/proto/window.pro 2016-03-13 18:06:59.528803729
+0100
--- src/proto/window.pro 2016-03-13 18:38:41.877315186 +0100
***************
*** 87,90 ****
--- 87,91 ----
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 : */
*** ../vim-7.4.1557/src/testdir/test_window_id.vim 2016-03-13
18:06:59.528803729 +0100
--- src/testdir/test_window_id.vim 2016-03-13 18:48:12.851458310 +0100
***************
*** 5,10 ****
--- 5,11 ----
let id1 = win_getid()
split two
let id2 = win_getid()
+ let bufnr2 = bufnr('%')
split three
let id3 = win_getid()
tabnew
***************
*** 12,17 ****
--- 13,19 ----
let id4 = win_getid()
split five
let id5 = win_getid()
+ let bufnr5 = bufnr('%')
tabnext
wincmd w
***************
*** 67,71 ****
--- 69,79 ----
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
*** ../vim-7.4.1557/runtime/doc/eval.txt 2016-03-13 18:06:59.532803689
+0100
--- runtime/doc/eval.txt 2016-03-13 18:34:02.124183568 +0100
***************
*** 2133,2138 ****
--- 2149,2155 ----
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
***************
*** 7076,7081 ****
--- 7177,7186 ----
(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.
*** ../vim-7.4.1557/src/version.c 2016-03-13 18:06:59.532803689 +0100
--- src/version.c 2016-03-13 18:36:20.314766771 +0100
***************
*** 745,746 ****
--- 745,748 ----
{ /* Add new patch number below this line */
+ /**/
+ 1558,
/**/
--
hundred-and-one symptoms of being an internet addict:
36. You miss more than five meals a week downloading the latest games from
Apogee.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.