]> git.neil.brown.name Git - edlib.git/commitdiff
Introduce global-set-command-prefix
authorNeilBrown <neil@brown.name>
Sun, 18 Jun 2023 22:35:37 +0000 (08:35 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:41 +0000 (17:51 +1000)
"global-set-command-prefix" is an analog of key_add_prefix()

Signed-off-by: NeilBrown <neil@brown.name>
core-editor.c
doc-docs.c
lib-aspell.c
lib-charset.c
lib-colourmap.c

index 4013e74d83040f8bab9301bb8ce0c1a106f1cff6..262063acb1d68007a6c62d40f730b4d6ab7f66c5 100644 (file)
@@ -58,10 +58,15 @@ DEF_CMD(global_set_command)
 {
        struct ed_info *ei = ci->home->data;
        struct map *map = ei->map;
+       bool prefix = strcmp(ci->key, "global-set-command-prefix") == 0;
 
        if (!ci->str)
                return Enoarg;
-       if (ci->str2)
+       if (prefix) {
+               char *e = strconcat(NULL, ci->str, "\xFF\xFF\xFF\xFF");
+               key_add_range(map, ci->str, e, ci->comm2);
+               free(e);
+       } else if (ci->str2)
                key_add_range(map, ci->str, ci->str2, ci->comm2);
        else
                key_add(map, ci->str, ci->comm2);
@@ -495,6 +500,7 @@ struct pane *editor_new(void)
                ed_map = key_alloc();
                key_add(ed_map, "global-set-attr", &global_set_attr);
                key_add(ed_map, "global-set-command", &global_set_command);
+               key_add(ed_map, "global-set-command-prefix", &global_set_command);
                key_add(ed_map, "global-get-command", &global_get_command);
                key_add(ed_map, "global-load-module", &editor_load_module);
                key_add(ed_map, "global-config-dir", &global_config_dir);
index f94fce134bd08dac33d97927cdced3c518dd73d5..4621ca4826450865d02b38467dab9cbac918fe36 100644 (file)
@@ -833,9 +833,8 @@ DEF_CMD(docs_close)
 {
        struct docs *docs = ci->home->data;
 
-       call_comm("global-set-command", ci->home, &edlib_noop,
-                 0, NULL, "docs:",
-                 0, NULL, "docs;");
+       call_comm("global-set-command-prefix", ci->home, &edlib_noop,
+                 0, NULL, "docs:");
        call_comm("global-set-command", ci->home, &edlib_noop,
                  0, NULL, "doc:appeared-docs-register");
        pane_close(docs->collection);
@@ -937,9 +936,8 @@ DEF_CMD(attach_docs)
        doc->collection = paux;
 
        doc->callback = docs_callback_lookup;
-       call_comm("global-set-command", ci->home, &doc->callback,
-                 0, NULL, "docs:",
-                 0, NULL, "docs;");
+       call_comm("global-set-command-prefix", ci->home, &doc->callback,
+                 0, NULL, "docs:");
        call_comm("global-set-command", ci->home, &doc->callback,
                  0, NULL, "doc:appeared-docs-register");
 
index abded1fd0653d0ad3956764a0ae3db94fe9c2b6a..2be4e3dbcf2bb57f73b40b07875f986b05e412b6 100644 (file)
@@ -333,9 +333,8 @@ void edlib_init(struct pane *ed safe)
        call_comm("global-set-command", ed, &spell_save,
                  0, NULL, "Spell:Save");
 
-       call_comm("global-set-command", ed, &spell_dict,
-                 0, NULL, "interactive-cmd-dict-",
-                 0, NULL, "interactive-cmd-dict-~");
+       call_comm("global-set-command-prefix", ed, &spell_dict,
+                 0, NULL, "interactive-cmd-dict-");
 
        aspell_map = key_alloc();
        key_add(aspell_map, "Close", &aspell_close);
index 7a140f31993d0cf698708e3a18731ee12dc1709a..406416246ecc8a67f09c6fefdcaa0944d153ab6f 100644 (file)
@@ -1513,12 +1513,10 @@ void edlib_init(struct pane *ed safe)
        /* No doc:content-bytes - that wouldn't make sense */
 
        /* Use 1251 for any unknown 'windows' charset */
-       call_comm("global-set-command", ed, &win1251_attach, 0, NULL,
-                 "attach-charset-windows-", 0, NULL,
-                 "attach-charset-windows.");
-       call_comm("global-set-command", ed, &win1251_to_utf8, 0, NULL,
-                 "charset-to-utf8-windows-", 0, NULL,
-                 "charset-to-utf8-windows.");
+       call_comm("global-set-command-prefix", ed, &win1251_attach,
+                 0, NULL, "attach-charset-windows-");
+       call_comm("global-set-command-prefix", ed, &win1251_to_utf8,
+                 0, NULL, "charset-to-utf8-windows-");
 
        call_comm("global-set-command", ed, &win1252_attach, 0, NULL,
                "attach-charset-windows-1252");
@@ -1526,12 +1524,10 @@ void edlib_init(struct pane *ed safe)
                "charset-to-utf8-windows-1252");
 
        /* Use iso-8859-15 for any unknown iso-8859, and for ascii */
-       call_comm("global-set-command", ed, &iso8859_15_attach, 0, NULL,
-                 "attach-charset-iso-8859-", 0, NULL,
-                 "attach-charset-iso-8859.");
-       call_comm("global-set-command", ed, &iso8859_15_to_utf8, 0, NULL,
-                 "charset-to-utf8-iso-8859-", 0, NULL,
-                 "charset-to-utf8-iso-8859.");
+       call_comm("global-set-command-prefix", ed, &iso8859_15_attach,
+                 0, NULL, "attach-charset-iso-8859-");
+       call_comm("global-set-command-prefix", ed, &iso8859_15_to_utf8,
+                 0, NULL, "charset-to-utf8-iso-8859-");
 
        call_comm("global-set-command", ed, &iso8859_15_attach, 0, NULL,
                "attach-charset-us-ascii");
index 4e82d938f3a670f2fc3cc49f4622b32702598565..ac842542680c35ac255e739af956b65a777e47f5 100644 (file)
@@ -136,6 +136,7 @@ DEF_CMD(colour_map)
 void edlib_init(struct pane *ed safe)
 {
        call_comm("global-set-command", ed, &colour_map,
-                 0, NULL, "colour:map",
-                 0, NULL, "colour:map;");
+                 0, NULL, "colour:map");
+       call_comm("global-set-command-prefix", ed, &colour_map,
+                 0, NULL, "colour:map:");
 }