vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 672febbd0d6e0fc7b6497cc9af75d8861d0444b4
parent 360f4eee16cab4501815e13b0b427cd9ce61a4d0
Author: TwoFinger <Two-Finger@users.noreply.github.com>
Date:   Sat, 27 Jan 2018 19:41:14 +0200

vis-complete: send whole paths for completion

text_object_word() was only sending the last part of a pathname to
vis-complete.

text_object_longword() is better, but sometimes may send a bit too much,
so leading delimiters for some languages are stripped additionally.

Diffstat:
Mlua/plugins/complete-filename.lua | 5++++-
Mvis-lua.c | 1+
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua @@ -6,12 +6,15 @@ vis:map(vis.modes.INSERT, "<C-x><C-f>", 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 local prefix = file:content(range) if not prefix then return end + -- Strip leading delimiters for some languages + i, j = string.find(prefix, "[[(<'\"]+") + if j then prefix = prefix:sub(j + 1) end local cmd = string.format("vis-complete --file '%s'", prefix:gsub("'", "'\\''")) local status, out, err = vis:pipe(file, { start = 0, finish = 0 }, cmd) if status ~= 0 or not out then diff --git a/vis-lua.c b/vis-lua.c @@ -2703,6 +2703,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++) {