vim-patch:7.4.1893

Problem:    Cannot easily get the window ID for a buffer.
Solution:   Add bufwinid().

b3619a90ea
This commit is contained in:
Jurica Bradaric 2016-08-27 17:35:54 +02:00
parent b6300742d2
commit d8079e5ab7
4 changed files with 32 additions and 11 deletions

View File

@ -1813,6 +1813,7 @@ buflisted({expr}) Number TRUE if buffer {expr} is listed
bufloaded({expr}) Number TRUE if buffer {expr} is loaded
bufname({expr}) String Name of the buffer {expr}
bufnr({expr} [, {create}]) Number Number of the buffer {expr}
bufwinid({expr}) Number window ID of buffer {expr}
bufwinnr({expr}) Number window number of buffer {expr}
byte2line({byte}) Number line number at byte count {byte}
byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
@ -2468,6 +2469,16 @@ bufnr({expr} [, {create}])
number necessarily exist, because ":bwipeout" may have removed
them. Use bufexists() to test for the existence of a buffer.
bufwinid({expr}) *bufwinid()*
The result is a Number, which is the window ID of the first
window associated with buffer {expr}. For the use of {expr},
see |bufname()| above. If buffer {expr} doesn't exist or
there is no such window, -1 is returned. Example: >
echo "A window containing buffer 1 is " . (bufwinid(1))
<
Only deals with the current tab page.
bufwinnr({expr}) *bufwinnr()*
The result is a Number, which is the number of the first
window associated with buffer {expr}. For the use of {expr},

View File

@ -6709,7 +6709,6 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
# include "funcs.generated.h"
#endif
/*
* Function given to ExpandGeneric() to obtain the list of internal
* or user defined function names.
@ -7712,26 +7711,36 @@ static void f_bufnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_number = -1;
}
/*
* "bufwinnr(nr)" function
*/
static void f_bufwinnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
static void buf_win_common(typval_T *argvars, typval_T *rettv, bool get_nr)
{
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
++emsg_off;
(void)get_tv_number(&argvars[0]); // issue errmsg if type error
emsg_off++;
buf_T *buf = get_buf_tv(&argvars[0], TRUE);
int winnr = 0;
int winid;
bool found_buf = false;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
++winnr;
winnr++;
if (wp->w_buffer == buf) {
found_buf = true;
winid = wp->handle;
break;
}
}
rettv->vval.v_number = (found_buf ? winnr : -1);
--emsg_off;
rettv->vval.v_number = (found_buf ? (get_nr ? winnr : winid) : -1);
emsg_off--;
}
/// "bufwinid(nr)" function
static void f_bufwinid(typval_T *argvars, typval_T *rettv, FunPtr fptr) {
buf_win_common(argvars, rettv, false);
}
/// "bufwinnr(nr)" function
static void f_bufwinnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_win_common(argvars, rettv, true);
}
/*

View File

@ -45,6 +45,7 @@ return {
bufloaded={args=1},
bufname={args=1},
bufnr={args={1, 2}},
bufwinid={args=1},
bufwinnr={args=1},
byte2line={args=1},
byteidx={args=2},

View File

@ -548,7 +548,7 @@ static int included_patches[] = {
1896,
// 1895,
// 1894 NA
// 1893,
1893,
// 1892 NA
// 1891 NA
// 1890 NA