From 664b3ee8b72ef815227b9f1fd76ee0ca72f3704a Mon Sep 17 00:00:00 2001 From: Kelsey Judson Date: Mon, 1 Jan 2018 19:52:40 +1300 Subject: vis-open: fix for absolute and non-existent paths When the shell cannot find any matching files, the glob is not expanded, and vis-open will return the absolute path of the current working directory (because dirname outputs '.'), followed by the filename, followed by a literal '*'. This commit checks that the final path actually exists, and if not, exits with status 1. It also uses text_object_longword for the range to match, so that absolute paths are accepted, and replaced properly (else it only works back to the first '/'). --- lua/plugins/complete-filename.lua | 5 +++-- vis-lua.c | 9 +++++++++ vis-open | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua index cb5b361..98e8ec3 100644 --- a/lua/plugins/complete-filename.lua +++ b/lua/plugins/complete-filename.lua @@ -6,7 +6,7 @@ vis:map(vis.modes.INSERT, "", function() local pos = win.selection.pos if not pos then return end -- TODO do something clever here - local range = file:text_object_word(pos > 0 and pos-1 or pos); + local range = file:text_object_longword(pos > 0 and pos-1 or pos); if not range then return end if range.finish > pos then range.finish = pos end if range.start == range.finish then return end @@ -29,7 +29,8 @@ vis:map(vis.modes.INSERT, "", function() local file = win.file local pos = win.selection.pos if not pos then return end - local range = file:text_object_word(pos > 0 and pos-1 or pos); + -- TODO do something clever here + local range = file:text_object_longword(pos > 0 and pos-1 or pos); if not range then return end if range.finish > pos then range.finish = pos end local prefix = file:content(range) diff --git a/vis-lua.c b/vis-lua.c index 3c998e7..124e380 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -2234,6 +2234,14 @@ static int file_mark_get(lua_State *L) { * @treturn Range range the range */ +/*** + * WORD text object. + * + * @function text_object_longword + * @tparam int pos the position which must be part of the word + * @treturn Range range the range + */ + static int file_text_object(lua_State *L) { Filerange range = text_range_empty(); File *file = obj_ref_check(L, 1, VIS_LUA_TYPE_FILE); @@ -2703,6 +2711,7 @@ void vis_lua_init(Vis *vis) { const char *name; } textobjects[] = { { VIS_TEXTOBJECT_INNER_WORD, "text_object_word" }, + { VIS_TEXTOBJECT_INNER_LONGWORD, "text_object_longword" }, }; for (size_t i = 0; i < LENGTH(textobjects); i++) { diff --git a/vis-open b/vis-open index 997aa49..cb81b04 100755 --- a/vis-open +++ b/vis-open @@ -40,6 +40,11 @@ if [ $# -eq 1 -a "$ALLOW_AUTO_SELECT" = 1 ]; then # If there were globs on the command-line, they've expanded to # a single item, so we can just process it. + # If the file or directory does not exist, abort. + if [ ! -e "$1" ]; then + exit 1 + fi + if [ -d "$1" ]; then # Recurse and show the contents of the named directory, # We pass -f to force the next iteration to present the -- cgit v1.2.3 From 0be1e2e70b797e7e3149d777a26bc69966079e07 Mon Sep 17 00:00:00 2001 From: Kelsey Judson Date: Thu, 4 Jan 2018 19:05:28 +1300 Subject: vis-open: fix creating new files in selected directory --- vis-open | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vis-open b/vis-open index cb81b04..920239c 100755 --- a/vis-open +++ b/vis-open @@ -40,11 +40,6 @@ if [ $# -eq 1 -a "$ALLOW_AUTO_SELECT" = 1 ]; then # If there were globs on the command-line, they've expanded to # a single item, so we can just process it. - # If the file or directory does not exist, abort. - if [ ! -e "$1" ]; then - exit 1 - fi - if [ -d "$1" ]; then # Recurse and show the contents of the named directory, # We pass -f to force the next iteration to present the @@ -54,10 +49,15 @@ if [ $# -eq 1 -a "$ALLOW_AUTO_SELECT" = 1 ]; then exec "$0" -p "$VIS_MENU_PROMPT" -f .. $(ls -1) else # We've found a single item, and it's not a directory, - # so it must be a filename (or file-like thing) to open. - cd "$(dirname "$1")" - echo "$(pwd -P)"/"$(basename "$1")" - exit 0 + # so it must be a filename (or file-like thing) to open, + # unless the parent directory does not exist. + if [ -d "$(dirname "$1")" ]; then + cd "$(dirname "$1")" + echo "$(pwd -P)"/"$(basename "$1" | sed 's/\*$//')" + exit 0 + else + exit 1 + fi fi fi -- cgit v1.2.3