aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-05-16 13:00:59 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-05-18 15:09:18 +0200
commit8696abbe1df9bcc3abe3926a0ea6c9788ae94f58 (patch)
tree701831b48b7d62c979f3a6b1ff3e15bfc8540ea2 /main.c
parent7ffbf62469d1ed3bc82f0cf56d91b3ebef7b7338 (diff)
downloadvis-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.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/main.c b/main.c
index 995ac72..6baff3b 100644
--- a/main.c
+++ b/main.c
@@ -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) {