diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-03-31 13:49:54 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-03-31 13:49:54 +0200 |
| commit | c5594e156e6088c791060f5a4839b89f0906d4d1 (patch) | |
| tree | 252e3476cddb164440f120f9ef2e4ea9c22a4842 | |
| parent | dc5f5a45a2315011ebeeb0a56a7434ead292dc96 (diff) | |
| download | vis-c5594e156e6088c791060f5a4839b89f0906d4d1.tar.gz vis-c5594e156e6088c791060f5a4839b89f0906d4d1.tar.xz | |
vis: improve tab completion in command prompt
At some point it should probably be possible to add command prompt
bindings from within Lua. Currently there is no easy/realiable way
to detect the prompt window.
Should improve #526.
| -rw-r--r-- | lua/plugins/complete-filename.lua | 31 | ||||
| -rw-r--r-- | vis-prompt.c | 7 |
2 files changed, 37 insertions, 1 deletions
diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua index 824e33a..3648efe 100644 --- a/lua/plugins/complete-filename.lua +++ b/lua/plugins/complete-filename.lua @@ -1,4 +1,4 @@ --- complete file name at primary cursor location using vis-complete(1) +-- complete file path at primary cursor location using vis-complete(1) vis:map(vis.modes.INSERT, "<C-x><C-f>", function() local win = vis.win @@ -20,4 +20,33 @@ vis:map(vis.modes.INSERT, "<C-x><C-f>", function() end file:insert(pos, out) win.cursor.pos = pos + #out +end, "Complete file path") + +-- complete file path at primary cursor location using vis-open(1) + +vis:map(vis.modes.INSERT, "<C-x><C-o>", function() + local win = vis.win + local file = win.file + local pos = win.cursor.pos + if not pos then return end + 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 + local prefix = file:content(range) + if not prefix then return end + if prefix:match("^%s*$") then + prefix = "" + range.start = pos + range.finish = pos + end + local cmd = string.format("vis-open -- '%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 + out = out:gsub("\n$", "") + file:delete(range) + file:insert(range.start, out) + win.cursor.pos = range.start + #out end, "Complete file name") diff --git a/vis-prompt.c b/vis-prompt.c index 3cddc47..a08a19f 100644 --- a/vis-prompt.c +++ b/vis-prompt.c @@ -154,6 +154,11 @@ static const KeyBinding prompt_up_binding = { }, }; +static const KeyBinding prompt_tab_binding = { + .key = "<Tab>", + .alias = "<C-x><C-o>", +}; + void vis_prompt_show(Vis *vis, const char *title) { Win *active = vis->win; Win *prompt = window_new_file(vis, title[0] == ':' ? vis->command_file : vis->search_file, @@ -173,6 +178,8 @@ void vis_prompt_show(Vis *vis, const char *title) { vis_window_mode_map(prompt, VIS_MODE_VISUAL, true, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Escape>", &prompt_esc_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Up>", &prompt_up_binding); + if (CONFIG_LUA) + vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Tab>", &prompt_tab_binding); vis_mode_switch(vis, VIS_MODE_INSERT); } |
