]> granicus.if.org Git - vim/commitdiff
patch 8.0.0177: BufEnter autocommand not fired for a directory v8.0.0177
authorBram Moolenaar <Bram@vim.org>
Fri, 13 Jan 2017 21:01:02 +0000 (22:01 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 13 Jan 2017 21:01:02 +0000 (22:01 +0100)
Problem:    When opening a buffer on a directory and inside a try/catch then
            the BufEnter event is not triggered.
Solution:   Return NOTDONE from readfile() for a directory and deal with the
            three possible return values. (Justin M. Keyes, closes #1375,
            closes #1353)

src/buffer.c
src/ex_cmds.c
src/ex_docmd.c
src/fileio.c
src/memline.c
src/testdir/test_autocmd.vim
src/version.c

index e77fc04976fa58929848c28e10944e397564b044..b79e277a0108aa9439171c8be739d215140c6569 100644 (file)
@@ -113,16 +113,19 @@ read_buffer(
         * it can be changed there. */
        if (!readonlymode && !bufempty())
            changed();
-       else if (retval != FAIL)
+       else if (retval == OK)
            unchanged(curbuf, FALSE);
 
 #ifdef FEAT_AUTOCMD
+       if (retval == OK)
+       {
 # ifdef FEAT_EVAL
-       apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
+           apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
                                                        curbuf, &retval);
 # else
-       apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf);
+           apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf);
 # endif
+       }
 #endif
     }
     return retval;
@@ -294,7 +297,7 @@ open_buffer(
 #endif
        )
        changed();
-    else if (retval != FAIL && !read_stdin && !read_fifo)
+    else if (retval == OK && !read_stdin && !read_fifo)
        unchanged(curbuf, FALSE);
     save_file_ff(curbuf);              /* keep this fileformat */
 
@@ -328,7 +331,7 @@ open_buffer(
 # endif
 #endif
 
-    if (retval != FAIL)
+    if (retval == OK)
     {
 #ifdef FEAT_AUTOCMD
        /*
index 484a22c74a33a4ea4e67b1624334f9a621f5c946..00cac92565c11a5bc797e5aa758aab2a22540114 100644 (file)
@@ -1313,7 +1313,7 @@ do_filter(
        if (otmp != NULL)
        {
            if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM,
-                                                   eap, READ_FILTER) == FAIL)
+                                                   eap, READ_FILTER) != OK)
            {
 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
                if (!aborting())
index 134a4883842c2abb0302be0431e4bbf7964a2161..295e53960f68fc66235296c4c3b6b2f4f3b2108b 100644 (file)
@@ -8857,7 +8857,7 @@ ex_read(exarg_T *eap)
                          eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
 
        }
-       if (i == FAIL)
+       if (i != OK)
        {
 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
            if (!aborting())
index bcb8fef8b1a90ae433d8256e0302fdbcc8efe247..aeb53b593d14a3d95bf88afa622454d352036b30 100644 (file)
@@ -210,7 +210,7 @@ filemess(
  * READ_KEEP_UNDO  don't clear undo info or read it from a file
  * READ_FIFO   read from fifo/socket instead of a file
  *
- * return FAIL for failure, OK otherwise
+ * return FAIL for failure, NOTDONE for directory (failure), or OK
  */
     int
 readfile(
@@ -450,13 +450,18 @@ readfile(
 # endif
                                                )
        {
+           int retval = FAIL;
+
            if (S_ISDIR(perm))
+           {
                filemess(curbuf, fname, (char_u *)_("is a directory"), 0);
+               retval = NOTDONE;
+           }
            else
                filemess(curbuf, fname, (char_u *)_("is not a file"), 0);
            msg_end();
            msg_scroll = msg_save;
-           return FAIL;
+           return retval;
        }
 #endif
 #if defined(MSWIN)
@@ -7136,7 +7141,7 @@ buf_reload(buf_T *buf, int orig_mode)
 #endif
            if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0,
                        (linenr_T)0,
-                       (linenr_T)MAXLNUM, &ea, flags) == FAIL)
+                       (linenr_T)MAXLNUM, &ea, flags) != OK)
            {
 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
                if (!aborting())
index e3a4bdbc62c74b2015cec78d41a479ada43b5403..244e69277f3793a7d82a3eded4ba94bab5de003a 100644 (file)
@@ -1519,7 +1519,7 @@ ml_recover(void)
                            line_count = pp->pb_pointer[idx].pe_line_count;
                            if (readfile(curbuf->b_ffname, NULL, lnum,
                                        pp->pb_pointer[idx].pe_old_lnum - 1,
-                                       line_count, NULL, 0) == FAIL)
+                                       line_count, NULL, 0) != OK)
                                cannot_open = TRUE;
                            else
                                lnum += line_count;
index 6ebfee45e7e3bfcda65c1aa7cdb7e7bc7232034b..566a07c6f5aa66d0b6d7c5a32fb4732eaae4e358 100644 (file)
@@ -322,3 +322,22 @@ func Test_three_windows()
   call delete('Xtestje2')
   call delete('Xtestje3')
 endfunc
+
+func Test_BufEnter()
+  au! BufEnter
+  au Bufenter * let val = val . '+'
+  let g:val = ''
+  split NewFile
+  call assert_equal('+', g:val)
+  bwipe!
+  call assert_equal('++', g:val)
+
+  " Also get BufEnter when editing a directory
+  call mkdir('Xdir')
+  split Xdir
+  call assert_equal('+++', g:val)
+  bwipe!
+
+  call delete('Xdir', 'd')
+  au! BufEnter
+endfunc
index c7e47fa41c9795e6e59156cc6e4bd56d4d1f3e4f..a0887dd6f4727277c6c66aae1f63a9b32025bc04 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    177,
 /**/
     176,
 /**/