From 0d90ca0d826cad18986bff0515337ec2102c0128 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 19 Oct 2023 20:11:51 +1100 Subject: [PATCH] Filename completion: don't include trailing slash unless only match. Return precise number of matches from the completion code, and when completing a file name, drop the slash if not unique. Otherwise if there are several directory that end with the same string, that can get a '/' added too early. Signed-off-by: NeilBrown --- DOC/TODO.md | 2 +- mode-emacs.c | 3 +++ render-complete.c | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index 9048c77a..9d642095 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -11,7 +11,7 @@ the file. - [X] w3m hangs for CAAmjac0r78WpiYW9FsJK=+E8-FG4MoxD2zkUJS_oCRyNW+=rug@mail.gmail.com It is writing to stdout which is reading very slowly. -- [ ] in filename completion, TAB might add a '/' to a partial name and +- [X] in filename completion, TAB might add a '/' to a partial name and then get confused. - [X] when search succeeds on final line then trying again loops back to there, redraw is strange diff --git a/mode-emacs.c b/mode-emacs.c index 6d4248dd..469eaef8 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -1358,6 +1358,9 @@ REDEF_CMD(emacs_file_complete) return Efail; cr = call_ret(all, "Complete:prefix", p, 1, NULL, b, 0, NULL, "format:plain"); + if (cr.s && cr.ret-1 > 1 && cr.s[strlen(cr.s)-1] == '/') + /* Trailing slash on non-unique name must be removed */ + cr.s[strlen(cr.s)-1] = '\0'; if (cr.s && (strlen(cr.s) <= strlen(b) && cr.ret-1 > 1)) { /* We need the dropdown - delete prefix and drop-down will * insert result. diff --git a/render-complete.c b/render-complete.c index c2da85a2..38a654b3 100644 --- a/render-complete.c +++ b/render-complete.c @@ -455,6 +455,7 @@ DEF_CB(set_cb) cb->common = NULL; free(cb->common_pre); cb->common_pre = NULL; + cb->cnt = 0; } if (this_match == cb->best_match) { @@ -481,8 +482,8 @@ DEF_CB(set_cb) cb->common_pre[match-c] = 0; } else adjust_pre(cb->common_pre, c, match-c); + cb->cnt += 1; } - cb->cnt += 1; return 1; } -- 2.39.5