mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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:
		| @@ -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); | ||||
|   | ||||
| @@ -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) | ||||
| { | ||||
|   | ||||
| @@ -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}}, | ||||
|   | ||||
| @@ -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(); | ||||
|     } | ||||
|   } | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
							
								
								
									
										17
									
								
								src/nvim/testdir/test_autochdir.vim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/nvim/testdir/test_autochdir.vim
									
									
									
									
									
										Normal 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 | ||||
| @@ -425,7 +425,7 @@ static int included_patches[] = { | ||||
|   // 2018, | ||||
|   // 2017, | ||||
|   // 2016 NA | ||||
|   // 2015, | ||||
|   2015, | ||||
|   2014, | ||||
|   2013, | ||||
|   2012, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shougo Matsushita
					Shougo Matsushita