]> git.neil.brown.name Git - edlib.git/commitdiff
complete: allow an attribute to be requested.
authorNeilBrown <neil@brown.name>
Tue, 31 Jan 2023 23:06:48 +0000 (10:06 +1100)
committerNeilBrown <neil@brown.name>
Mon, 6 Feb 2023 05:48:18 +0000 (16:48 +1100)
Rendering a fill line is slower than just getting an attribute.
So getting the (new) format:plain attribute is preferred there
it makes sense.

So allow render-complete to be given an attr to use, and do that for
file completion.

Signed-off-by: NeilBrown <neil@brown.name>
mode-emacs.c
render-complete.c

index 650b2c48333b9e17f818943d66751a4392f5f7e2..c23e3dcd8b007e120f140e32535104a72404a226 100644 (file)
@@ -1526,7 +1526,8 @@ REDEF_CMD(emacs_file_complete)
        p = call_ret(pane, "attach-render-complete", par, 0, NULL, "format");
        if (!p)
                return Efail;
-       cr = call_ret(all, "Complete:prefix", p, 1, NULL, b);
+       cr = call_ret(all, "Complete:prefix", p, 1, NULL, b,
+                     0, NULL, "format:plain");
        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 ae0d00797aac631cbaf75e149454de34df5df412..a365d0f51cb68bbbb489bcfa367d5bdcedca9604 100644 (file)
@@ -28,6 +28,7 @@
 
 struct complete_data {
        char *orig;
+       char *attr;
        struct stk {
                struct stk *prev;
                const char *substr safe;
@@ -158,6 +159,7 @@ DEF_CMD(complete_free)
                free(t);
        }
 
+       free(cd->attr);
        unalloc(cd, pane);
        return 1;
 }
@@ -219,7 +221,8 @@ DEF_CMD(complete_char)
        np = malloc(pl + strlen(suffix) + 1);
        strcpy(np, cd->stk->substr);
        strcpy(np+pl, suffix);
-       call("Complete:prefix", ci->focus, !cd->prefix_only, NULL, np);
+       call("Complete:prefix", ci->focus, !cd->prefix_only, NULL, np,
+            0, NULL, cd->attr);
        free(np);
        return 1;
 }
@@ -240,7 +243,8 @@ DEF_CMD(complete_bs)
                free((void*)stk->substr);
                free(stk);
        }
-       call("Complete:prefix", ci->home, 0, NULL, NULL, 1);
+       call("Complete:prefix", ci->home, 0, NULL, NULL, 1,
+            NULL, cd->attr);
        return 1;
 }
 
@@ -403,14 +407,19 @@ DEF_CMD(complete_set_prefix)
        } else {
                cb.ss = cd->stk->substr;
        }
+       if (ci->str2 && (!cd->attr || strcmp(cd->attr, ci->str2) != 0)) {
+               free(cd->attr);
+               cd->attr = strdup(ci->str2);
+       }
 
        call_comm("Filter:set", ci->focus, &cb.c,
-                 cd->prefix_only ? 3 : 2, NULL, cb.ss);
+                 cd->prefix_only ? 3 : 2, NULL, cb.ss, 0, NULL, cd->attr);
 
        if (cb.cnt <= 0) {
                /* Revert */
                call("Filter:set", ci->focus,
-                    cd->prefix_only ? 3 : 2, NULL, cd->stk->substr);
+                    cd->prefix_only ? 3 : 2, NULL, cd->stk->substr,
+                    0, NULL, cd->attr);
                if (m)
                        call("Move-to", ci->focus, 0, m);
        }
@@ -425,7 +434,8 @@ DEF_CMD(complete_set_prefix)
                cd->stk = stk;
                cb.common_pre = NULL;
                call("Filter:set", ci->focus,
-                    cd->prefix_only ? 3 : 2, NULL, cd->stk->substr);
+                    cd->prefix_only ? 3 : 2, NULL, cd->stk->substr,
+                         0, NULL, cd->attr);
                comm_call(ci->comm2, "callback:prefix", ci->focus, cb.cnt,
                          NULL, cd->stk->substr);
                if (!cd->orig)