]> granicus.if.org Git - vim/commitdiff
patch 7.4.1893 v7.4.1893
authorBram Moolenaar <Bram@vim.org>
Sat, 4 Jun 2016 15:58:52 +0000 (17:58 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 4 Jun 2016 15:58:52 +0000 (17:58 +0200)
Problem:    Cannot easily get the window ID for a buffer.
Solution:   Add bufwinid().

runtime/doc/eval.txt
src/eval.c
src/version.c

index cb5fa434388ce9883a5e531c96c44eb420d9c8dc..b3262b21c3c22a07074b7155fe0704d26dffbc51 100644 (file)
@@ -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},
index 2ca6611843a2185681690e48fd195722fc99a700..66cf3a0cc5bb9fc22bb4f0ac7ad24e187e39be22 100644 (file)
@@ -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
  */
index 5aa8a2afed2b7f239c5817c687eb0cde28ab398c..36b5ed773631d7bc54dd15448e0d45388bb4c047 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1893,
 /**/
     1892,
 /**/