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.

5c71994f4e
This commit is contained in:
Shougo Matsushita
2016-12-10 18:33:55 +09:00
parent c5f4b92ff9
commit 0c43479979
8 changed files with 36 additions and 3 deletions

View File

@@ -1330,7 +1330,7 @@ void enter_buffer(buf_T *buf)
void do_autochdir(void) void do_autochdir(void)
{ {
if (p_acd) { if (p_acd) {
if (starting == 0 if ((starting == 0 || test_autochdir)
&& curbuf->b_ffname != NULL && curbuf->b_ffname != NULL
&& vim_chdirfile(curbuf->b_ffname) == OK) { && vim_chdirfile(curbuf->b_ffname) == OK) {
shorten_fnames(true); shorten_fnames(true);

View File

@@ -17159,6 +17159,12 @@ static void f_tempname(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_string = vim_tempname(); 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 // "termopen(cmd[, cwd])" function
static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{ {

View File

@@ -301,6 +301,7 @@ return {
tan={args=1, func="float_op_wrapper", data="&tan"}, tan={args=1, func="float_op_wrapper", data="&tan"},
tanh={args=1, func="float_op_wrapper", data="&tanh"}, tanh={args=1, func="float_op_wrapper", data="&tanh"},
tempname={}, tempname={},
test_autochdir={},
termopen={args={1, 2}}, termopen={args={1, 2}},
test={args=1}, test={args=1},
timer_start={args={2,3}}, timer_start={args={2,3}},

View File

@@ -1611,6 +1611,7 @@ int do_write(exarg_T *eap)
int retval = FAIL; int retval = FAIL;
char_u *free_fname = NULL; char_u *free_fname = NULL;
buf_T *alt_buf = NULL; buf_T *alt_buf = NULL;
int name_was_missing;
if (not_writing()) /* check 'write' option */ if (not_writing()) /* check 'write' option */
return FAIL; return FAIL;
@@ -1734,6 +1735,7 @@ int do_write(exarg_T *eap)
fname = curbuf->b_sfname; fname = curbuf->b_sfname;
} }
name_was_missing = curbuf->b_ffname == NULL;
retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2,
eap, eap->append, eap->forceit, TRUE, FALSE); eap, eap->append, eap->forceit, TRUE, FALSE);
@@ -1743,7 +1745,11 @@ int do_write(exarg_T *eap)
curbuf->b_p_ro = FALSE; curbuf->b_p_ro = FALSE;
redraw_tabline = TRUE; 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(); do_autochdir();
} }
} }

View File

@@ -641,6 +641,8 @@ EXTERN volatile int full_screen INIT(= FALSE);
/* TRUE when doing full-screen output /* TRUE when doing full-screen output
* otherwise only writing some messages */ * otherwise only writing some messages */
EXTERN int test_autochdir INIT(= FALSE);
EXTERN int restricted INIT(= FALSE); EXTERN int restricted INIT(= FALSE);
// TRUE when started in restricted mode (-Z) // TRUE when started in restricted mode (-Z)
EXTERN int secure INIT(= FALSE); EXTERN int secure INIT(= FALSE);

View File

@@ -3,6 +3,7 @@
source test_assign.vim source test_assign.vim
source test_autocmd.vim source test_autocmd.vim
source test_autochdir.vim
source test_cursor_func.vim source test_cursor_func.vim
source test_ex_undo.vim source test_ex_undo.vim
source test_expr.vim source test_expr.vim

View File

@@ -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

View File

@@ -425,7 +425,7 @@ static int included_patches[] = {
// 2018, // 2018,
// 2017, // 2017,
// 2016 NA // 2016 NA
// 2015, 2015,
2014, 2014,
2013, 2013,
2012, 2012,