From 1ecbfd19db9c45d25c6793cedf019e30bf4a30a3 Mon Sep 17 00:00:00 2001 From: watiko Date: Thu, 4 Feb 2016 03:47:55 +0900 Subject: [PATCH] vim-patch: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) https://github.com/vim/vim/commit/d87c36ea5eae50580f3c733734669250cc969019 --- see: "autochdir + encoding=utf8 messes up diff" https://groups.google.com/d/msg/vim_dev/QrE4Y2LMJR8/uxigns5KGxYJ --- src/nvim/main.c | 42 +++++++++++++++++++++++++----------------- src/nvim/version.c | 2 +- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/nvim/main.c b/src/nvim/main.c index cef10d12d5..a8c2cebbbd 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -219,9 +219,10 @@ int main(int argc, char **argv) { argv0 = (char *)path_tail((char_u *)argv[0]); - char_u *fname = NULL; /* file name from command line */ - mparm_T params; /* various parameters passed between - * main() and other functions. */ + char_u *fname = NULL; // file name from command line + mparm_T params; // various parameters passed between + // main() and other functions. + char_u *cwd = NULL; // current workding dir on startup time_init(); /* Many variables are in "params" so that we can pass them to invoked @@ -461,11 +462,10 @@ int main(int argc, char **argv) TIME_MSG("jump to first error"); } - /* - * If opened more than one window, start editing files in the other - * windows. - */ - edit_buffers(¶ms); + // If opened more than one window, start editing files in the other + // windows. + edit_buffers(¶ms, cwd); + xfree(cwd); if (params.diff_mode) { /* set options in each window for "nvim -d". */ @@ -1182,12 +1182,19 @@ static char_u *get_fname(mparm_T *parmp) * Expand wildcards in file names. */ if (!parmp->literal) { - /* Temporarily add '(' and ')' to 'isfname'. These are valid - * filename characters but are excluded from 'isfname' to make - * "gf" work on a file name in parenthesis (e.g.: see vim.h). */ + cwd = xmalloc(MAXPATHL); + if (cwd != NULL) { + os_dirname(cwd, MAXPATHL); + } + // Temporarily add '(' and ')' to 'isfname'. These are valid + // filename characters but are excluded from 'isfname' to make + // "gf" work on a file name in parenthesis (e.g.: see vim.h). do_cmdline_cmd(":set isf+=(,)"); alist_expand(NULL, 0); do_cmdline_cmd(":set isf&"); + if (cwd != NULL) { + os_chdir((char *)cwd); + } } #endif return alist_name(&GARGLIST[0]); @@ -1417,11 +1424,9 @@ static void create_windows(mparm_T *parmp) } } -/* - * If opened more than one window, start editing files in the other - * windows. make_windows() has already opened the windows. - */ -static void edit_buffers(mparm_T *parmp) +/// If opened more than one window, start editing files in the other +/// windows. make_windows() has already opened the windows. +static void edit_buffers(mparm_T *parmp, char_u *cwd) { int arg_idx; /* index in argument list */ int i; @@ -1442,7 +1447,10 @@ static void edit_buffers(mparm_T *parmp) arg_idx = 1; for (i = 1; i < parmp->window_count; ++i) { - /* When w_arg_idx is -1 remove the window (see create_windows()). */ + if (cwd != NULL) { + os_chdir((char *)cwd); + } + // When w_arg_idx is -1 remove the window (see create_windows()). if (curwin->w_arg_idx == -1) { ++arg_idx; win_close(curwin, TRUE); diff --git a/src/nvim/version.c b/src/nvim/version.c index 70600bf57b..2ff66c5756 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -599,7 +599,7 @@ static int included_patches[] = { // 692 NA // 691 NA 690, - // 689, + 689, 688, // 687 NA 686,