]> granicus.if.org Git - vim/commitdiff
patch 8.0.1386: cannot select modified buffers with getbufinfo() v8.0.1386
authorBram Moolenaar <Bram@vim.org>
Sun, 10 Dec 2017 20:06:22 +0000 (21:06 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 10 Dec 2017 20:06:22 +0000 (21:06 +0100)
Problem:    Cannot select modified buffers with getbufinfo().
Solution:   Add the "bufmodified" flag. (Yegappan Lakshmanan, closes #2431)

runtime/doc/eval.txt
src/evalfunc.c
src/testdir/test_bufwintabinfo.vim
src/version.c

index 93e818a44295d9f063a902a53b75d2b2be397e55..3afd675518b8a5d75e77fe185e2779385217ec6f 100644 (file)
@@ -4173,6 +4173,7 @@ getbufinfo([{dict}])
                be specified in {dict}:
                        buflisted       include only listed buffers.
                        bufloaded       include only loaded buffers.
+                       bufmodified     include only modified buffers.
 
                Otherwise, {expr} specifies a particular buffer to return
                information for.  For the use of {expr}, see |bufname()|
index 72690847276185481fc54c81eae62936d294dbda..9aacd30786735759d777154940af80ff2f36d52f 100644 (file)
@@ -4137,6 +4137,7 @@ f_getbufinfo(typval_T *argvars, typval_T *rettv)
     int                filtered = FALSE;
     int                sel_buflisted = FALSE;
     int                sel_bufloaded = FALSE;
+    int                sel_bufmodified = FALSE;
 
     if (rettv_list_alloc(rettv) != OK)
        return;
@@ -4159,6 +4160,10 @@ f_getbufinfo(typval_T *argvars, typval_T *rettv)
            di = dict_find(sel_d, (char_u *)"bufloaded", -1);
            if (di != NULL && get_tv_number(&di->di_tv))
                sel_bufloaded = TRUE;
+
+           di = dict_find(sel_d, (char_u *)"bufmodified", -1);
+           if (di != NULL && get_tv_number(&di->di_tv))
+               sel_bufmodified = TRUE;
        }
     }
     else if (argvars[0].v_type != VAR_UNKNOWN)
@@ -4178,7 +4183,8 @@ f_getbufinfo(typval_T *argvars, typval_T *rettv)
        if (argbuf != NULL && argbuf != buf)
            continue;
        if (filtered && ((sel_bufloaded && buf->b_ml.ml_mfp == NULL)
-                                          || (sel_buflisted && !buf->b_p_bl)))
+                       || (sel_buflisted && !buf->b_p_bl)
+                       || (sel_bufmodified && !buf->b_changed)))
            continue;
 
        d = get_buffer_info(buf);
index a592cd7b11abecc99da5c97b05d1cb57a4d5dc52..31b46500259c6bfe6fec806935f7dda8cd4865ce 100644 (file)
@@ -20,6 +20,13 @@ function Test_getbufwintabinfo()
     call assert_equal('vim', l[0].variables.editor)
     call assert_notequal(-1, index(l[0].windows, bufwinid('%')))
 
+    " Test for getbufinfo() with 'bufmodified'
+    call assert_equal(0, len(getbufinfo({'bufmodified' : 1})))
+    call setbufline('Xtestfile1', 1, ["Line1"])
+    let l = getbufinfo({'bufmodified' : 1})
+    call assert_equal(1, len(l))
+    call assert_equal(bufnr('Xtestfile1'), l[0].bufnr)
+
     if has('signs')
        call append(0, ['Linux', 'Windows', 'Mac'])
        sign define Mark text=>> texthl=Search
index 7c55df074cb1622c5a60d800e433391027eb3fb6..e96e672e7de5c5918e811cc366487dd8a54951e1 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1386,
 /**/
     1385,
 /**/