From df4ca745807852be4e7588a41fe311c12f41ddb4 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Sat, 30 Oct 2021 08:28:05 +0200 Subject: xC: make libedit autocomplete less miserable Omitting even this hack was a huge hit to overall usability. --- xC.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/xC.c b/xC.c index 37783b7..1f4ff0f 100644 --- a/xC.c +++ b/xC.c @@ -13698,19 +13698,33 @@ on_editline_complete (EditLine *editline, int key) // Insert the best match instead el_insertstr (editline, completions[0]); + + // I'm not sure if Readline's menu-complete can at all be implemented + // with Editline--we have no way of detecting what the last executed handler + // was. Employ the formatter's wrapping feature to spew all options. bool only_match = !completions[1]; + if (!only_match) + { + CALL (ctx->input, hide); + redraw_screen (ctx); + + struct formatter f = formatter_make (ctx, NULL); + for (char **p = completions; *++p; ) + formatter_add (&f, " #l", *p); + formatter_add (&f, "\n"); + formatter_flush (&f, stdout, 0); + formatter_free (&f); + + CALL (ctx->input, show); + } + for (char **p = completions; *p; p++) free (*p); free (completions); - - // 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 and we have no way of detecting - // what the last executed handler was. if (!only_match) return CC_REFRESH_BEEP; - // But if there actually is just one match, finish the word + // If there actually is just one match, finish the word el_insertstr (editline, " "); return CC_REFRESH; } -- cgit v1.2.3-70-g09d2