From 2ebbbafd656460206ebacf1d4ff4531ebc031e53 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 1 Mar 2018 00:53:59 +0100 Subject: [PATCH 1/4] grepper#complete_files: check for whitespace at end of head It seems like this just confused path with head for completing relative files. With "foo " head contains whitespace at the end, but path does not. This fixes completion of relative files basically. --- plugin/grepper.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/grepper.vim b/plugin/grepper.vim index ed3e20d..f76ab51 100644 --- a/plugin/grepper.vim +++ b/plugin/grepper.vim @@ -232,8 +232,8 @@ endfunction " grepper#complete_files() {{{2 function! grepper#complete_files(lead, _line, _pos) let [head, path] = s:extract_path(a:lead) - " handle relative paths - if empty(path) || (path =~ '\s$') + " handle initial relative paths + if empty(path) && head =~# '\s$' return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') " handle sub paths elseif path =~ '^.\/' From 664e41a02992f989b92edabe97804cb495645413 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 1 Mar 2018 01:12:55 +0100 Subject: [PATCH 2/4] complete_files: more fixes - handle '~/' correctly: previously is was even matched by the `=~ '^.\/'`, which turned "~/foo" into "./foo" then! - handle relative paths without prefix at the end - fix issues reported by vint (single quotes) --- plugin/grepper.vim | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugin/grepper.vim b/plugin/grepper.vim index f76ab51..75a53e4 100644 --- a/plugin/grepper.vim +++ b/plugin/grepper.vim @@ -232,15 +232,20 @@ endfunction " grepper#complete_files() {{{2 function! grepper#complete_files(lead, _line, _pos) let [head, path] = s:extract_path(a:lead) - " handle initial relative paths - if empty(path) && head =~# '\s$' - return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') - " handle sub paths - elseif path =~ '^.\/' - return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') + " handle paths in $HOME (~/foo) + if path[0:1] ==# '~/' + let home = expand('~') + let home_len = len(home) + return map(split(globpath(home, path[2:].'*'), '\n'), 'head . ''~'' . v:val[home_len:] . (isdirectory(v:val) ? s:slash : '''')') + " handle (explicit) relative paths + elseif path[0:1] ==# './' + return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . v:val . (isdirectory(v:val) ? s:slash : '''')') " handle absolute paths - elseif path[0] == '/' - return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') + elseif path[0] ==# '/' + return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : '''')') + " handle relative paths + else + return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . ''.'' . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') endif endfunction From 5c3316cbb29c7b7664aff5e3c15f469f7da01ccb Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 14 Mar 2018 00:27:56 +0100 Subject: [PATCH 3/4] fixup! complete_files: more fixes --- plugin/grepper.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/grepper.vim b/plugin/grepper.vim index 75a53e4..2d3b63f 100644 --- a/plugin/grepper.vim +++ b/plugin/grepper.vim @@ -236,16 +236,16 @@ function! grepper#complete_files(lead, _line, _pos) if path[0:1] ==# '~/' let home = expand('~') let home_len = len(home) - return map(split(globpath(home, path[2:].'*'), '\n'), 'head . ''~'' . v:val[home_len:] . (isdirectory(v:val) ? s:slash : '''')') + return map(split(globpath(home, path[2:].'*'), '\n'), "head . '~' . v:val[home_len:] . (isdirectory(v:val) ? s:slash : '')") " handle (explicit) relative paths elseif path[0:1] ==# './' - return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . v:val . (isdirectory(v:val) ? s:slash : '''')') + return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), "head . v:val . (isdirectory(v:val) ? s:slash : '')") " handle absolute paths elseif path[0] ==# '/' - return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : '''')') + return map(split(globpath(s:slash, path.'*'), '\n'), "head . v:val[1:] . (isdirectory(v:val) ? s:slash : '')") " handle relative paths else - return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . ''.'' . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') + return map(split(globpath('.'.s:slash, path.'*'), '\n'), "head . '.' . v:val[1:] . (isdirectory(v:val) ? s:slash : '')") endif endfunction From beaeb9fb62c8e84f9c515db2d54ac4781fe00339 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 14 Mar 2018 00:53:59 +0100 Subject: [PATCH 4/4] fixup! fixup! complete_files: more fixes --- plugin/grepper.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/grepper.vim b/plugin/grepper.vim index 2d3b63f..b9b45dc 100644 --- a/plugin/grepper.vim +++ b/plugin/grepper.vim @@ -235,8 +235,7 @@ function! grepper#complete_files(lead, _line, _pos) " handle paths in $HOME (~/foo) if path[0:1] ==# '~/' let home = expand('~') - let home_len = len(home) - return map(split(globpath(home, path[2:].'*'), '\n'), "head . '~' . v:val[home_len:] . (isdirectory(v:val) ? s:slash : '')") + return map(split(globpath(home, path[2:].'*'), '\n'), "head . '~' . v:val[".len(home).":] . (isdirectory(v:val) ? s:slash : '')") " handle (explicit) relative paths elseif path[0:1] ==# './' return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), "head . v:val . (isdirectory(v:val) ? s:slash : '')")