From 5b1a6479951bc6152373ef2db57e391036a60125 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 19 Jun 2023 08:35:37 +1000 Subject: [PATCH] Introduce global-set-command-prefix "global-set-command-prefix" is an analog of key_add_prefix() Signed-off-by: NeilBrown --- core-editor.c | 8 +++++++- doc-docs.c | 10 ++++------ lib-aspell.c | 5 ++--- lib-charset.c | 20 ++++++++------------ lib-colourmap.c | 5 +++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/core-editor.c b/core-editor.c index 4013e74d..262063ac 100644 --- a/core-editor.c +++ b/core-editor.c @@ -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); diff --git a/doc-docs.c b/doc-docs.c index f94fce13..4621ca48 100644 --- a/doc-docs.c +++ b/doc-docs.c @@ -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"); diff --git a/lib-aspell.c b/lib-aspell.c index abded1fd..2be4e3db 100644 --- a/lib-aspell.c +++ b/lib-aspell.c @@ -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); diff --git a/lib-charset.c b/lib-charset.c index 7a140f31..40641624 100644 --- a/lib-charset.c +++ b/lib-charset.c @@ -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"); diff --git a/lib-colourmap.c b/lib-colourmap.c index 4e82d938..ac842542 100644 --- a/lib-colourmap.c +++ b/lib-colourmap.c @@ -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:"); } -- 2.39.5