diff src/ex_cmds.c @ 9469:38e2fc4ee4ef v7.4.2015

commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 9 23:40:45 2016 +0200 patch 7.4.2015 Problem: When a file gets a name when writing it 'acd' is not effective. (Dan Church) Solution: Invoke DO_AUTOCHDIR after writing the file. (Allen Haim, closes #777, closes #803) Add test_autochdir() to enable 'acd' before "starting" is reset.
author Christian Brabandt <cb@256bit.org>
date Sat, 09 Jul 2016 23:45:05 +0200
parents 1003973c99df
children 7520696c14b0
line wrap: on
line diff
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3059,6 +3059,7 @@ do_write(exarg_T *eap)
     char_u	*browse_file = NULL;
 #endif
     buf_T	*alt_buf = NULL;
+    int		name_was_missing;
 
     if (not_writing())		/* check 'write' option */
 	return FAIL;
@@ -3226,6 +3227,8 @@ do_write(exarg_T *eap)
 #endif
 	}
 
+	name_was_missing = curbuf->b_ffname == NULL;
+
 	retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2,
 				 eap, eap->append, eap->forceit, TRUE, FALSE);
 
@@ -3239,7 +3242,12 @@ do_write(exarg_T *eap)
 		redraw_tabline = TRUE;
 #endif
 	    }
-	    /* Change directories when the 'acd' option is set. */
+	}
+
+	/* Change directories when the 'acd' option is set and the file name
+	 * got changed or set. */
+	if (eap->cmdidx == CMD_saveas || name_was_missing)
+	{
 	    DO_AUTOCHDIR
 	}
     }