]> git.neil.brown.name Git - edlib.git/commitdiff
Filename completion: don't include trailing slash unless only match.
authorNeilBrown <neil@brown.name>
Thu, 19 Oct 2023 09:11:51 +0000 (20:11 +1100)
committerNeilBrown <neil@brown.name>
Thu, 19 Oct 2023 09:11:51 +0000 (20:11 +1100)
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 <neil@brown.name>
DOC/TODO.md
mode-emacs.c
render-complete.c

index 9048c77a3ae1404a75f64717c0a089958173c5e9..9d642095a9ad0e0c04dabe63222793dbea8b2427 100644 (file)
@@ -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
index 6d4248dd8aece55d2852a98df20ca9caf90f46e5..469eaef8e133b82ed6d286d8b4e25cb11ea50153 100644 (file)
@@ -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.
index c2da85a24032833345e99a0f1a116517be82e71f..38a654b35d70ec3412c78c6f120d01fc4961a0c9 100644 (file)
@@ -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;
 }