From 8b86f1103a54882416d4ac626884d3d8a7e02c63 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Fri, 22 Jan 2016 17:49:39 +0100 Subject: [PATCH 1/4] vim-patch:7.4.642 Problem: When using "gf" escaped spaces are not handled. Solution: Recognize escaped spaces. https://github.com/vim/vim/commit/d45c07ac7499358c5cb096cadb675ce74ae3eaf6 --- src/nvim/file_search.c | 9 +++++++++ src/nvim/version.c | 2 +- src/nvim/window.c | 16 ++++++++++------ src/nvim/window.h | 1 + 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 4f345158cf..b213a42c52 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1340,6 +1340,7 @@ void free_findfile(void) * * options: * FNAME_MESS give error message when not found + * FNAME_UNESC unescape backslashes * * Uses NameBuff[]! * @@ -1385,6 +1386,14 @@ find_file_in_path_option ( xfree(ff_file_to_find); ff_file_to_find = vim_strsave(NameBuff); + if (options & FNAME_UNESC) { + // Change all "\ " to " ". + for (ptr = ff_file_to_find; *ptr != NUL; ++ptr) { + if (ptr[0] == '\\' && ptr[1] == ' ') { + memmove(ptr, ptr + 1, STRLEN(ptr)); + } + } + } } rel_to_curdir = (ff_file_to_find[0] == '.' diff --git a/src/nvim/version.c b/src/nvim/version.c index 9b4c191d89..2d0d52268d 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -482,7 +482,7 @@ static int included_patches[] = { 645, // 644 NA // 643, - // 642, + 642, // 641 NA 640, // 639, diff --git a/src/nvim/window.c b/src/nvim/window.c index 16ff7dfb14..7a21b22d28 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4837,17 +4837,16 @@ static void frame_add_height(frame_T *frp, int n) */ char_u *grab_file_name(long count, linenr_T *file_lnum) { + int options = FNAME_MESS|FNAME_EXP|FNAME_REL|FNAME_UNESC; if (VIsual_active) { size_t len; char_u *ptr; if (get_visual_text(NULL, &ptr, &len) == FAIL) return NULL; - return find_file_name_in_path(ptr, len, - FNAME_MESS|FNAME_EXP|FNAME_REL, + return find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); } - return file_name_at_cursor(FNAME_MESS|FNAME_HYP|FNAME_EXP|FNAME_REL, count, - file_lnum); + return file_name_at_cursor(options|FNAME_HYP, count, file_lnum); } /* @@ -4918,12 +4917,17 @@ file_name_in_line ( * Also allow "://" when ':' is not in 'isfname'. */ len = 0; - while (vim_isfilec(ptr[len]) - || ((options & FNAME_HYP) && path_is_url((char *)ptr + len))) + while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ') + || ((options & FNAME_HYP) && path_is_url((char *)ptr + len))) { + if (ptr[len] == '\\') { + // Skip over the "\" in "\ ". + ++len; + } if (has_mbyte) len += (size_t)(*mb_ptr2len)(ptr + len); else ++len; + } /* * If there is trailing punctuation, remove it. diff --git a/src/nvim/window.h b/src/nvim/window.h index eccc7835a8..67e1d2106d 100644 --- a/src/nvim/window.h +++ b/src/nvim/window.h @@ -10,6 +10,7 @@ #define FNAME_INCL 8 /* apply 'includeexpr' */ #define FNAME_REL 16 /* ".." and "./" are relative to the (current) file instead of the current directory */ +#define FNAME_UNESC 32 /* remove backslashes used for escaping */ /* * arguments for win_split() From b8ed507e3b2da70c5d0d948aaf6abe773b61c6d8 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Fri, 22 Jan 2016 18:32:27 +0100 Subject: [PATCH 2/4] window: Fix linter errors. --- src/nvim/window.c | 5 +++-- src/nvim/window.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nvim/window.c b/src/nvim/window.c index 7a21b22d28..2542c7a11e 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4923,10 +4923,11 @@ file_name_in_line ( // Skip over the "\" in "\ ". ++len; } - if (has_mbyte) + if (has_mbyte) { len += (size_t)(*mb_ptr2len)(ptr + len); - else + } else { ++len; + } } /* diff --git a/src/nvim/window.h b/src/nvim/window.h index 67e1d2106d..2ac4c00c28 100644 --- a/src/nvim/window.h +++ b/src/nvim/window.h @@ -10,7 +10,7 @@ #define FNAME_INCL 8 /* apply 'includeexpr' */ #define FNAME_REL 16 /* ".." and "./" are relative to the (current) file instead of the current directory */ -#define FNAME_UNESC 32 /* remove backslashes used for escaping */ +#define FNAME_UNESC 32 // remove backslashes used for escaping /* * arguments for win_split() From 34904efd9daca8cc4dc6f78932cacf9195710756 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Fri, 22 Jan 2016 19:48:52 +0100 Subject: [PATCH 3/4] window: Fix code style. --- src/nvim/window.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/nvim/window.c b/src/nvim/window.c index 2542c7a11e..62f27a80e0 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4837,16 +4837,15 @@ static void frame_add_height(frame_T *frp, int n) */ char_u *grab_file_name(long count, linenr_T *file_lnum) { - int options = FNAME_MESS|FNAME_EXP|FNAME_REL|FNAME_UNESC; + int options = FNAME_MESS | FNAME_EXP | FNAME_REL | FNAME_UNESC; if (VIsual_active) { size_t len; char_u *ptr; if (get_visual_text(NULL, &ptr, &len) == FAIL) return NULL; - return find_file_name_in_path(ptr, len, options, - count, curbuf->b_ffname); + return find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); } - return file_name_at_cursor(options|FNAME_HYP, count, file_lnum); + return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); } /* From ce17037e3ebbfb9f181c40f26bc601780e3f17a5 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Fri, 22 Jan 2016 21:06:20 +0100 Subject: [PATCH 4/4] window: Skip backslash only if followed by space --- src/nvim/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/window.c b/src/nvim/window.c index 62f27a80e0..f0c6cacdf0 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4918,7 +4918,7 @@ file_name_in_line ( len = 0; while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ') || ((options & FNAME_HYP) && path_is_url((char *)ptr + len))) { - if (ptr[len] == '\\') { + if (ptr[len] == '\\' && ptr[len + 1] == ' ') { // Skip over the "\" in "\ ". ++len; }