From bee12d3686c19b1aaddf18ca58a2556fd7c200f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 5 Mar 2017 11:04:38 +0100 Subject: lua: reimplement word and file name completion in lua The file name completion does not yet behave the same way as the previous C code because the completion prefix is currently simply calculated using the `iw` text object which does not handle common path elements (e.g. `.`, `/`, `~`, etc). --- lua/plugins/complete-filename.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lua/plugins/complete-filename.lua (limited to 'lua/plugins/complete-filename.lua') diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua new file mode 100644 index 0000000..824e33a --- /dev/null +++ b/lua/plugins/complete-filename.lua @@ -0,0 +1,23 @@ +-- complete file name at primary cursor location using vis-complete(1) + +vis:map(vis.modes.INSERT, "", function() + local win = vis.win + local file = win.file + local pos = win.cursor.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); + 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 + 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 + if err then vis:info(err) end + return + end + file:insert(pos, out) + win.cursor.pos = pos + #out +end, "Complete file name") -- cgit v1.2.3