mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 7.4.1893
Problem: Cannot easily get the window ID for a buffer. Solution: Add bufwinid().
This commit is contained in:
@@ -1862,6 +1862,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}
|
||||
@@ -2557,6 +2558,16 @@ bufnr({expr} [, {create}])
|
||||
*last_buffer_nr()*
|
||||
Obsolete name for bufnr("$"): last_buffer_nr().
|
||||
|
||||
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},
|
||||
|
30
src/eval.c
30
src/eval.c
@@ -500,6 +500,7 @@ static void f_buflisted(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufloaded(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufname(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufnr(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufwinid(typval_T *argvars, typval_T *rettv);
|
||||
static void f_bufwinnr(typval_T *argvars, typval_T *rettv);
|
||||
static void f_byte2line(typval_T *argvars, typval_T *rettv);
|
||||
static void byteidx(typval_T *argvars, typval_T *rettv, int comp);
|
||||
@@ -8488,6 +8489,7 @@ static struct fst
|
||||
{"bufloaded", 1, 1, f_bufloaded},
|
||||
{"bufname", 1, 1, f_bufname},
|
||||
{"bufnr", 1, 2, f_bufnr},
|
||||
{"bufwinid", 1, 1, f_bufwinid},
|
||||
{"bufwinnr", 1, 1, f_bufwinnr},
|
||||
{"byte2line", 1, 1, f_byte2line},
|
||||
{"byteidx", 2, 2, f_byteidx},
|
||||
@@ -10213,11 +10215,8 @@ f_bufnr(typval_T *argvars, typval_T *rettv)
|
||||
rettv->vval.v_number = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* "bufwinnr(nr)" function
|
||||
*/
|
||||
static void
|
||||
f_bufwinnr(typval_T *argvars, typval_T *rettv)
|
||||
buf_win_common(typval_T *argvars, typval_T *rettv, int get_nr)
|
||||
{
|
||||
#ifdef FEAT_WINDOWS
|
||||
win_T *wp;
|
||||
@@ -10235,13 +10234,32 @@ f_bufwinnr(typval_T *argvars, typval_T *rettv)
|
||||
if (wp->w_buffer == buf)
|
||||
break;
|
||||
}
|
||||
rettv->vval.v_number = (wp != NULL ? winnr : -1);
|
||||
rettv->vval.v_number = (wp != NULL ? (get_nr ? winnr : wp->w_id) : -1);
|
||||
#else
|
||||
rettv->vval.v_number = (curwin->w_buffer == buf ? 1 : -1);
|
||||
rettv->vval.v_number = (curwin->w_buffer == buf
|
||||
? (get_nr ? 1 : curwin->w_id) : -1);
|
||||
#endif
|
||||
--emsg_off;
|
||||
}
|
||||
|
||||
/*
|
||||
* "bufwinid(nr)" function
|
||||
*/
|
||||
static void
|
||||
f_bufwinid(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
buf_win_common(argvars, rettv, FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* "bufwinnr(nr)" function
|
||||
*/
|
||||
static void
|
||||
f_bufwinnr(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
buf_win_common(argvars, rettv, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* "byte2line(byte)" function
|
||||
*/
|
||||
|
@@ -753,6 +753,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1893,
|
||||
/**/
|
||||
1892,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user