summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-07 07:40:58 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-07 07:40:58 +0200
commite3f1bcecae5e4ab08e5cd7c58ee163fab6635ea4 (patch)
treeed2bd8ce712fba17175d18caf49d7beca5a1f11b /degesch.c
parent85baf5ecec9710d2a4410a38875575da88364aa2 (diff)
downloadxK-e3f1bcecae5e4ab08e5cd7c58ee163fab6635ea4.tar.gz
xK-e3f1bcecae5e4ab08e5cd7c58ee163fab6635ea4.tar.xz
xK-e3f1bcecae5e4ab08e5cd7c58ee163fab6635ea4.zip
degesch: further libedit cleanup
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/degesch.c b/degesch.c
index 9f17678..8b4a30b 100644
--- a/degesch.c
+++ b/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