degesch: further libedit cleanup
This commit is contained in:
parent
85baf5ecec
commit
e3f1bcecae
38
degesch.c
38
degesch.c
|
@ -5586,7 +5586,6 @@ on_editline_complete (EditLine *editline, int key)
|
|||
(void) editline;
|
||||
|
||||
struct app_context *ctx = g_ctx;
|
||||
unsigned char result = CC_REFRESH_BEEP;
|
||||
|
||||
// First prepare what Readline would have normally done for us...
|
||||
const LineInfo *info_mb = el_line (editline);
|
||||
|
@ -5600,35 +5599,34 @@ on_editline_complete (EditLine *editline, int key)
|
|||
el_start--;
|
||||
|
||||
char **completions = make_completions (ctx, copy, el_start, el_end);
|
||||
if (!completions)
|
||||
goto out;
|
||||
|
||||
// The most basic autocompletion. I'm not sure if Readline's
|
||||
// menu-complete can at all be implemented with Editline.
|
||||
|
||||
// Remove the original word. Editline needs it in wide characters...
|
||||
// XXX: possibly incorrect wrt. shift state encodings
|
||||
copy[el_end] = '\0';
|
||||
el_wdeletestr (editline, mbstowcs (NULL, copy + el_start, 0));
|
||||
int el_len = mbstowcs (NULL, copy + el_start, 0);
|
||||
free (copy);
|
||||
|
||||
if (!completions)
|
||||
return CC_REFRESH_BEEP;
|
||||
|
||||
// Remove the original word
|
||||
el_wdeletestr (editline, el_len);
|
||||
|
||||
// Insert the best match instead
|
||||
el_insertstr (editline, completions[0]);
|
||||
if (!completions[1])
|
||||
{
|
||||
// If it is the only match, don't beep at the user
|
||||
// but finish the word instead
|
||||
el_insertstr (editline, " ");
|
||||
result = CC_REFRESH;
|
||||
}
|
||||
|
||||
// Free the vector of matches
|
||||
bool only_match = !completions[1];
|
||||
for (char **p = completions; *p; p++)
|
||||
free (*p);
|
||||
free (completions);
|
||||
|
||||
out:
|
||||
free (copy);
|
||||
return result;
|
||||
// I'm not sure if Readline's menu-complete can at all be implemented
|
||||
// with Editline. Spamming the terminal with possible completions
|
||||
// probably isn't what the user wants.
|
||||
if (!only_match)
|
||||
return CC_REFRESH_BEEP;
|
||||
|
||||
// But if there actually is just one match, finish the word
|
||||
el_insertstr (editline, " ");
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
static unsigned char
|
||||
|
|
Loading…
Reference in New Issue