diff options
| author | Toby Goodwin <toby@paccrat.org> | 2015-04-07 23:54:45 +0100 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:23:25 +0100 |
| commit | ab7361a7ff91a9a79bd02e06f20ded42ee2a5bcc (patch) | |
| tree | 22d0620d3b130c55590473ae37be51df1d2f42dd /edit-readline.c | |
| parent | 535d086f6efb24eeaf9a0b2d8269e97a88c12f29 (diff) | |
readline completion: now mainly working
Diffstat (limited to 'edit-readline.c')
| -rw-r--r-- | edit-readline.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/edit-readline.c b/edit-readline.c index 6a997c5..c562c62 100644 --- a/edit-readline.c +++ b/edit-readline.c @@ -14,13 +14,61 @@ struct cookie { char *buffer; }; +/* teach readline how to quote a filename in rc */ +static char *quote(char *text, int type, char *qp) { + char *p, *r; + + /* worst case: string is entirely quote characters each of which will + * be doubled, plus space for initial and final quotes and \0 */ + p = r = malloc(strlen(text) * 2 + 3); + if (!r) return 0; + /* supply opening quote unless already there */ + if (*qp != '\'') + *p++ = '\''; + while (*text) { + if (*text == '\'') + *p++ = '\''; /* double existing quote */ + *p++ = *text++; + } + if (type == SINGLE_MATCH) + *p++ = '\''; + *p = '\0'; + return r; +} + +char *unquote(char *text, int unused) { + char *p, *r; + + p = r = malloc(strlen(text) + 1); + if (!r) return 0; + while (*text) { + *p++ = *text++; + if (*(text - 1) == '\'' && *text == '\'') ++text; + } + *p = '\0'; + return r; +} +static char **complete(const char *text, int start, int end) { + //fprintf(stderr, "completer called on %s with %d and %d", text, start, end); + /* we can look at rl_line_buffer to see whether to complete as a + * command or a filename (should we do variables too?). for now, assume + * it's a filename */ + /* it's a filename: let readline do it's default thing */ + return 0; +} + void *edit_begin(int fd) { List *hist; struct cookie *c; rl_catch_signals = 0; rl_completer_quote_characters = "'"; + rl_basic_word_break_characters = " \t\n`@$><=;|&{("; + rl_basic_quote_characters = ""; rl_filename_quote_characters = "\t\n !#$&'()*;<=>?@[\\]^`{|}~"; + rl_filename_quoting_function = quote; + rl_filename_dequoting_function = unquote; + rl_attempted_completion_function = complete; hist = varlookup("history"); if (hist != NULL) |