Skip to content

Commit dad106b

Browse files
brammooldouglaskayama
authored andcommitted
updated for version 7.4.689 Problem: On MS-Windows, when 'autochdir' is set, diff mode with files in different directories does not work. (Axel Bender) Solution: Remember the current directory and use it where needed. (Christian Brabandt)
1 parent 4687c4a commit dad106b

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/main.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static void check_tty __ARGS((mparm_T *parmp));
110110
static void read_stdin __ARGS((void));
111111
static void create_windows __ARGS((mparm_T *parmp));
112112
# ifdef FEAT_WINDOWS
113-
static void edit_buffers __ARGS((mparm_T *parmp));
113+
static void edit_buffers __ARGS((mparm_T *parmp, char_u *cwd));
114114
# endif
115115
static void exe_pre_commands __ARGS((mparm_T *parmp));
116116
static void exe_commands __ARGS((mparm_T *parmp));
@@ -168,6 +168,7 @@ main
168168
char_u *fname = NULL; /* file name from command line */
169169
mparm_T params; /* various parameters passed between
170170
* main() and other functions. */
171+
char_u *cwd = NULL; /* current workding dir on startup */
171172
#ifdef STARTUPTIME
172173
int i;
173174
#endif
@@ -419,12 +420,17 @@ main
419420
*/
420421
if (!params.literal)
421422
{
423+
cwd = alloc(MAXPATHL);
424+
if (cwd != NULL)
425+
mch_dirname(cwd, MAXPATHL);
422426
/* Temporarily add '(' and ')' to 'isfname'. These are valid
423427
* filename characters but are excluded from 'isfname' to make
424428
* "gf" work on a file name in parenthesis (e.g.: see vim.h). */
425429
do_cmdline_cmd((char_u *)":set isf+=(,)");
426430
alist_expand(NULL, 0);
427431
do_cmdline_cmd((char_u *)":set isf&");
432+
if (cwd != NULL)
433+
mch_chdir((char *)cwd);
428434
}
429435
#endif
430436
fname = alist_name(&GARGLIST[0]);
@@ -450,6 +456,8 @@ main
450456
* If the cd fails, it doesn't matter.
451457
*/
452458
(void)vim_chdirfile(fname);
459+
if (cwd != NULL)
460+
mch_dirnamem(cwd, MAXPATHL);
453461
}
454462
#endif
455463
TIME_MSG("expanding arguments");
@@ -504,6 +512,8 @@ main
504512
expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
505513
vim_chdir(NameBuff);
506514
}
515+
if (cwd != NULL)
516+
mch_dirname(cwd, MAXPATHL);
507517
}
508518
}
509519
#endif
@@ -943,8 +953,9 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
943953
* If opened more than one window, start editing files in the other
944954
* windows.
945955
*/
946-
edit_buffers(&params);
956+
edit_buffers(&params, cwd);
947957
#endif
958+
vim_free(cwd);
948959

949960
#ifdef FEAT_DIFF
950961
if (params.diff_mode)
@@ -2809,8 +2820,9 @@ create_windows(parmp)
28092820
* windows. make_windows() has already opened the windows.
28102821
*/
28112822
static void
2812-
edit_buffers(parmp)
2823+
edit_buffers(parmp, cwd)
28132824
mparm_T *parmp;
2825+
char_u *cwd; /* current working dir */
28142826
{
28152827
int arg_idx; /* index in argument list */
28162828
int i;
@@ -2835,6 +2847,8 @@ edit_buffers(parmp)
28352847
arg_idx = 1;
28362848
for (i = 1; i < parmp->window_count; ++i)
28372849
{
2850+
if (cwd != NULL)
2851+
mch_chdir((char *)cwd);
28382852
/* When w_arg_idx is -1 remove the window (see create_windows()). */
28392853
if (curwin->w_arg_idx == -1)
28402854
{

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ static char *(features[]) =
756756

757757
static int included_patches[] =
758758
{ /* Add new patch number below this line */
759+
/**/
760+
689,
759761
/**/
760762
688,
761763
/**/

0 commit comments

Comments
 (0)