summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-06-04 17:58:52 +0200
committerBram Moolenaar <Bram@vim.org>2016-06-04 17:58:52 +0200
commitb3619a90eae2702553ff9494ecc4c9b20c13c224 (patch)
tree6543f198d050488857475dc5630998517b9c5a79
parentc9721bdc63378cc6123e775ffe43e9cba30322b3 (diff)
downloadvim-git-b3619a90eae2702553ff9494ecc4c9b20c13c224.tar.gz
patch 7.4.1893v7.4.1893
Problem: Cannot easily get the window ID for a buffer. Solution: Add bufwinid().
-rw-r--r--runtime/doc/eval.txt11
-rw-r--r--src/eval.c30
-rw-r--r--src/version.c2
3 files changed, 37 insertions, 6 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index cb5fa4343..b3262b21c 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -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},
diff --git a/src/eval.c b/src/eval.c
index 2ca661184..66cf3a0cc 100644
--- a/src/eval.c
+++ b/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,14 +10234,33 @@ 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
*/
static void
diff --git a/src/version.c b/src/version.c
index 5aa8a2afe..36b5ed773 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1893,
+/**/
1892,
/**/
1891,