diff options
| author | Silvan Jegen <s.jegen@gmail.com> | 2016-05-16 13:00:59 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-05-18 15:09:18 +0200 |
| commit | 8696abbe1df9bcc3abe3926a0ea6c9788ae94f58 (patch) | |
| tree | 701831b48b7d62c979f3a6b1ff3e15bfc8540ea2 /main.c | |
| parent | 7ffbf62469d1ed3bc82f0cf56d91b3ebef7b7338 (diff) | |
| download | vis-8696abbe1df9bcc3abe3926a0ea6c9788ae94f58.tar.gz vis-8696abbe1df9bcc3abe3926a0ea6c9788ae94f58.tar.xz | |
vis: add completion for file names in current directory via <C-x><C-f>
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -127,6 +127,8 @@ static const char *number_increment_decrement(Vis*, const char *keys, const Arg static const char *open_file_under_cursor(Vis*, const char *keys, const Arg *arg); /* complete input text at cursor based on the words in the current file */ static const char *complete_word(Vis*, const char *keys, const Arg *arg); +/* complete input text at cursor based on file names of the current directory */ +static const char *complete_filename(Vis*, const char *keys, const Arg *arg); enum { VIS_ACTION_EDITOR_SUSPEND, @@ -310,6 +312,7 @@ enum { VIS_ACTION_OPEN_FILE_UNDER_CURSOR, VIS_ACTION_OPEN_FILE_UNDER_CURSOR_NEW_WINDOW, VIS_ACTION_COMPLETE_WORD, + VIS_ACTION_COMPLETE_FILENAME, VIS_ACTION_NOP, }; @@ -1219,6 +1222,11 @@ static const KeyAction vis_action[] = { "Complete word in file", complete_word, }, + [VIS_ACTION_COMPLETE_FILENAME] = { + "complete-filename", + "Complete file name", + complete_filename, + }, [VIS_ACTION_NOP] = { "nop", "Ignore key, do nothing", @@ -2149,6 +2157,20 @@ static const char *complete_word(Vis *vis, const char *keys, const Arg *arg) { return keys; } +static const char *complete_filename(Vis *vis, const char *keys, const Arg *arg) { + Buffer cmd; + buffer_init(&cmd); + char *prefix = get_completion_prefix(vis); + if (prefix && buffer_printf(&cmd, "ls | grep '^%s' | sort | " VIS_MENU + " | tr -d '\n' | sed 's/%s//'", prefix, prefix)) { + Filerange empty = text_range_new(0, 0); + insert_dialog_selection(vis, &empty, (const char*[]){ buffer_content0(&cmd), NULL }); + } + buffer_release(&cmd); + free(prefix); + return keys; +} + static Vis *vis; static void signal_handler(int signum, siginfo_t *siginfo, void *context) { |
