aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2016-12-10 18:33:55 +0900
committerShougo Matsushita <Shougo.Matsu@gmail.com>2017-01-02 10:43:45 +0900
commit0c43479979547ed84b2a898dcc7816767333cc80 (patch)
tree5ba56dc83b674ef81468d909602647d97f3c8ccc
parentc5f4b92ff93a40ec4e77b78d0576903e7a60eefd (diff)
downloadrneovim-0c43479979547ed84b2a898dcc7816767333cc80.tar.gz
rneovim-0c43479979547ed84b2a898dcc7816767333cc80.tar.bz2
rneovim-0c43479979547ed84b2a898dcc7816767333cc80.zip
vim-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 vim/vim#777, closes vim/vim#803) Add test_autochdir() to enable 'acd' before "starting" is reset. https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
-rw-r--r--src/nvim/buffer.c2
-rw-r--r--src/nvim/eval.c6
-rw-r--r--src/nvim/eval.lua1
-rw-r--r--src/nvim/ex_cmds.c8
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/testdir/test_alot.vim1
-rw-r--r--src/nvim/testdir/test_autochdir.vim17
-rw-r--r--src/nvim/version.c2
8 files changed, 36 insertions, 3 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index d9fdc80c60..58ec5dc377 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1330,7 +1330,7 @@ void enter_buffer(buf_T *buf)
void do_autochdir(void)
{
if (p_acd) {
- if (starting == 0
+ if ((starting == 0 || test_autochdir)
&& curbuf->b_ffname != NULL
&& vim_chdirfile(curbuf->b_ffname) == OK) {
shorten_fnames(true);
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 32e1991742..6bcc3ca986 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -17159,6 +17159,12 @@ static void f_tempname(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_string = vim_tempname();
}
+// "test_autochdir()" function
+static void f_test_autochdir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ test_autochdir = TRUE;
+}
+
// "termopen(cmd[, cwd])" function
static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 980a8d2326..9022103c7d 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -301,6 +301,7 @@ return {
tan={args=1, func="float_op_wrapper", data="&tan"},
tanh={args=1, func="float_op_wrapper", data="&tanh"},
tempname={},
+ test_autochdir={},
termopen={args={1, 2}},
test={args=1},
timer_start={args={2,3}},
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index fcaf17a0fc..b1a17e8c44 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1611,6 +1611,7 @@ int do_write(exarg_T *eap)
int retval = FAIL;
char_u *free_fname = NULL;
buf_T *alt_buf = NULL;
+ int name_was_missing;
if (not_writing()) /* check 'write' option */
return FAIL;
@@ -1734,6 +1735,7 @@ int do_write(exarg_T *eap)
fname = curbuf->b_sfname;
}
+ name_was_missing = curbuf->b_ffname == NULL;
retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2,
eap, eap->append, eap->forceit, TRUE, FALSE);
@@ -1743,7 +1745,11 @@ int do_write(exarg_T *eap)
curbuf->b_p_ro = FALSE;
redraw_tabline = TRUE;
}
- /* 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();
}
}
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index fbffc2d44d..bfc6a14ad8 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -641,6 +641,8 @@ EXTERN volatile int full_screen INIT(= FALSE);
/* TRUE when doing full-screen output
* otherwise only writing some messages */
+EXTERN int test_autochdir INIT(= FALSE);
+
EXTERN int restricted INIT(= FALSE);
// TRUE when started in restricted mode (-Z)
EXTERN int secure INIT(= FALSE);
diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim
index 818ff7cf54..54a2795d4a 100644
--- a/src/nvim/testdir/test_alot.vim
+++ b/src/nvim/testdir/test_alot.vim
@@ -3,6 +3,7 @@
source test_assign.vim
source test_autocmd.vim
+source test_autochdir.vim
source test_cursor_func.vim
source test_ex_undo.vim
source test_expr.vim
diff --git a/src/nvim/testdir/test_autochdir.vim b/src/nvim/testdir/test_autochdir.vim
new file mode 100644
index 0000000000..f52e2e668a
--- /dev/null
+++ b/src/nvim/testdir/test_autochdir.vim
@@ -0,0 +1,17 @@
+" Test 'autochdir' behavior
+
+if !exists("+autochdir")
+ finish
+endif
+
+func Test_set_filename()
+ call test_autochdir()
+ set acd
+ new
+ w samples/Xtest
+ call assert_equal("Xtest", expand('%'))
+ call assert_equal("samples", substitute(getcwd(), '.*/\(\k*\)', '\1', ''))
+ bwipe!
+ set noacd
+ call delete('samples/Xtest')
+endfunc
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 9f2b7a26c3..6659eedabb 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -425,7 +425,7 @@ static int included_patches[] = {
// 2018,
// 2017,
// 2016 NA
- // 2015,
+ 2015,
2014,
2013,
2012,