summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2015-12-05 18:26:37 +0100
committerToby Goodwin <toby@paccrat.org>2018-04-26 06:52:32 +0100
commita50b93cd6790c95a85c7647829c14a0ccd166f31 (patch)
treef042fa8eebbfd210ffc46961894b944e6a029eac
parent68fc1605e7d3a317477abf1afc6410581724b72d (diff)
Custom readline commands for explicit completions
New commands: - rc-complete-command, per default bound to "M-!" - rc-complete-filename, "M-/" - rc-complete-variable, "M-$" These commands are useful, if one wants a specific type of completion which is not performed by the context-senstive default one, e.g. filename completion at the beginning of the line or command completion for the second word (after sudo). The readline code now also sets the application name to "rc", making it possible to specify different bindings for these commands in ~/.inputrc: $if rc "\C-x\C-[": rc-complete-command "\C-[\C-x": rc-complete-filename "\C-x\C-v": rc-complete-variable $endif
-rw-r--r--edit-readline.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/edit-readline.c b/edit-readline.c
index 9737e3e..fb9044e 100644
--- a/edit-readline.c
+++ b/edit-readline.c
@@ -94,15 +94,38 @@ static rl_compentry_func_t *compl_func(const char *text, int start, int end) {
return NULL;
}
-static char **rc_completion(const char *text, int start, int end) {
- rl_compentry_func_t *func = compl_func(text, start, end);
+static rl_compentry_func_t *compentry_func;
+static char **rc_completion(const char *text, int start, int end) {
+ rl_compentry_func_t *func;
+
+ if (compentry_func != NULL) {
+ func = compentry_func;
+ compentry_func = NULL;
+ rl_attempted_completion_over = 1;
+ } else
+ func = compl_func(text, start, end);
if (func != NULL)
return rl_completion_matches(text, func);
else
return NULL;
}
+static int rc_complete_command(int count, int key) {
+ compentry_func = compl_extcmd;
+ return rl_complete(count, key);
+}
+
+static int rc_complete_filename(int count, int key) {
+ compentry_func = rl_filename_completion_function;
+ return rl_complete(count, key);
+}
+
+static int rc_complete_variable(int count, int key) {
+ compentry_func = compl_var;
+ return rl_complete(count, key);
+}
+
void *edit_begin(int fd) {
List *hist;
struct cookie *c;
@@ -112,6 +135,14 @@ void *edit_begin(int fd) {
rl_catch_signals = 0;
rl_completer_quote_characters = "'";
rl_filename_quote_characters = "\t\n !#$&'()*;<=>?@[\\]^`{|}~";
+ rl_readline_name = "rc";
+
+ rl_add_funmap_entry("rc-complete-command", rc_complete_command);
+ rl_add_funmap_entry("rc-complete-filename", rc_complete_filename);
+ rl_add_funmap_entry("rc-complete-variable", rc_complete_variable);
+ rl_bind_keyseq("\e!", rc_complete_command);
+ rl_bind_keyseq("\e/", rc_complete_filename);
+ rl_bind_keyseq("\e$", rc_complete_variable);
hist = varlookup("history");
if (hist != NULL)