From 5fa0552ab07a6b7f36e6423e5b5fd878da372bf4 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 13 Nov 2022 15:12:21 +0100 Subject: [PATCH] [exmode] Introduced 10 macro config options. macro.0 to macro.9 . Refs #196 They can be bind to keys. For example set macro.0 = "set ui.show_title_bar = 0" set macro.1 = "set ui.show_title_bar = 1" bind "main" "z" = "macro-0" bind "main" "Z" = "macro-1" --- src/config/actions-main.inc | 10 +++++++ src/config/dialogs.c | 2 +- src/config/options.inc | 47 +++++++++++++++++++++++++++-- src/dialogs/exmode.c | 27 +++++++++++++++++ src/dialogs/exmode.h | 1 + src/viewer/action.cpp | 60 +++++++++++++++++++++++++++++++++++++ 6 files changed, 144 insertions(+), 3 deletions(-) diff --git a/src/config/actions-main.inc b/src/config/actions-main.inc index 0c73cebe..f59417dc 100644 --- a/src/config/actions-main.inc +++ b/src/config/actions-main.inc @@ -51,6 +51,16 @@ ACTION_(MAIN, "link-info", LINK_INFO, N__("Show information about current link") ACTION_(MAIN, "link-menu", LINK_MENU, N__("Open the link context menu"), ACTION_REQUIRE_VIEW_STATE | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK), ACTION_(MAIN, "link-form-menu", LINK_FORM_MENU, N__("Open the form fields menu"), ACTION_REQUIRE_VIEW_STATE | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK | ACTION_REQUIRE_FORM), ACTION_(MAIN, "lua-console", LUA_CONSOLE, N__("Open a Lua console"), ACTION_RESTRICT_ANONYMOUS), +ACTION_(MAIN, "macro-0", MACRO_0, N__("Macro 0"), 0), +ACTION_(MAIN, "macro-1", MACRO_1, N__("Macro 1"), 0), +ACTION_(MAIN, "macro-2", MACRO_2, N__("Macro 2"), 0), +ACTION_(MAIN, "macro-3", MACRO_3, N__("Macro 3"), 0), +ACTION_(MAIN, "macro-4", MACRO_4, N__("Macro 4"), 0), +ACTION_(MAIN, "macro-5", MACRO_5, N__("Macro 5"), 0), +ACTION_(MAIN, "macro-6", MACRO_6, N__("Macro 6"), 0), +ACTION_(MAIN, "macro-7", MACRO_7, N__("Macro 7"), 0), +ACTION_(MAIN, "macro-8", MACRO_8, N__("Macro 8"), 0), +ACTION_(MAIN, "macro-9", MACRO_9, N__("Macro 9"), 0), ACTION_(MAIN, "mark-clipboard", MARK_CLIPBOARD, N__("Mark a corner of the clipboard rectangle"), ACTION_REQUIRE_VIEW_STATE | ACTION_REQUIRE_LOCATION), ACTION_(MAIN, "mark-goto", MARK_GOTO, N__("Go at a specified mark"), ACTION_REQUIRE_VIEW_STATE), ACTION_(MAIN, "mark-set", MARK_SET, N__("Set a mark"), ACTION_REQUIRE_VIEW_STATE), diff --git a/src/config/dialogs.c b/src/config/dialogs.c index 846d6df6..ec4fe75b 100644 --- a/src/config/dialogs.c +++ b/src/config/dialogs.c @@ -532,7 +532,7 @@ static int keybinding_text_toggle; /* XXX: ACTION_BOX_SIZE is just a quick hack, we ought to allocate * the sub-arrays separately. --pasky */ -#define ACTION_BOX_SIZE 128 +#define ACTION_BOX_SIZE 138 static struct listbox_item *action_box_items[KEYMAP_MAX][ACTION_BOX_SIZE]; struct listbox_item * diff --git a/src/config/options.inc b/src/config/options.inc index 01ef1593..02e7a725 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -934,10 +934,53 @@ static union option_info config_options_info[] = { "data to permanent storage. This is optional for those who " "wish to avoid excessive disk I/O.")), +#ifdef CONFIG_EXMODE + INIT_OPT_TREE("", N_("Macros"), + "macro", OPT_SORT, + N_("Macros for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 0"), + "0", OPT_ZERO, "", + N_("Macro 0 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 1"), + "1", OPT_ZERO, "", + N_("Macro 1 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 2"), + "2", OPT_ZERO, "", + N_("Macro 2 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 3"), + "3", OPT_ZERO, "", + N_("Macro 3 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 4"), + "4", OPT_ZERO, "", + N_("Macro 4 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 5"), + "5", OPT_ZERO, "", + N_("Macro 5 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 6"), + "6", OPT_ZERO, "", + N_("Macro 6 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 7"), + "7", OPT_ZERO, "", + N_("Macro 7 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 8"), + "8", OPT_ZERO, "", + N_("Macro 8 for exmode.")), + + INIT_OPT_STRING("macro", N_("Macro 9"), + "9", OPT_ZERO, "", + N_("Macro 9 for exmode.")), +#endif /* Keep options in alphabetical order. */ - - INIT_OPT_TREE("", N_("Terminals"), "terminal", OPT_AUTOCREATE, N_("Terminal options.")), diff --git a/src/dialogs/exmode.c b/src/dialogs/exmode.c index 7ed14851..8d4d5291 100644 --- a/src/dialogs/exmode.c +++ b/src/dialogs/exmode.c @@ -109,6 +109,33 @@ exmode_exec(struct session *ses, char buffer[INPUT_LINE_BUFFER_SIZE]) } } +void +try_exmode_exec(struct session *ses, const char *val) +{ + char *buffer = stracpy(val); + + if (!buffer) { + return; + } + + char *command = buffer; + char *args = command; + int i; + + while (*command == ':') command++; + + if (!*command) return; + + skip_nonspace(args); + if (*args) *args++ = 0; + + for (i = 0; exmode_handlers[i]; i++) { + if (exmode_handlers[i](ses, command, args)) + break; + } + + mem_free(buffer); +} static enum input_line_code exmode_input_handler(struct input_line *input_line, int action_id) diff --git a/src/dialogs/exmode.h b/src/dialogs/exmode.h index 00401f90..55407753 100644 --- a/src/dialogs/exmode.h +++ b/src/dialogs/exmode.h @@ -12,6 +12,7 @@ struct session; extern struct module exmode_module; void exmode_start(struct session *ses); +void try_exmode_exec(struct session *ses, const char *val); #ifdef __cplusplus } diff --git a/src/viewer/action.cpp b/src/viewer/action.cpp index 9d9ea00a..28a45225 100644 --- a/src/viewer/action.cpp +++ b/src/viewer/action.cpp @@ -322,6 +322,66 @@ do_action(struct session *ses, main_action_T action_id, int verbose) #endif break; + case ACT_MAIN_MACRO_0: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.0", ses)); +#endif + break; + + case ACT_MAIN_MACRO_1: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.1", ses)); +#endif + break; + + case ACT_MAIN_MACRO_2: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.2", ses)); +#endif + break; + + case ACT_MAIN_MACRO_3: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.3", ses)); +#endif + break; + + case ACT_MAIN_MACRO_4: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.4", ses)); +#endif + break; + + case ACT_MAIN_MACRO_5: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.5", ses)); +#endif + break; + + case ACT_MAIN_MACRO_6: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.6", ses)); +#endif + break; + + case ACT_MAIN_MACRO_7: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.7", ses)); +#endif + break; + + case ACT_MAIN_MACRO_8: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.8", ses)); +#endif + break; + + case ACT_MAIN_MACRO_9: +#ifdef CONFIG_EXMODE + try_exmode_exec(ses, get_opt_str("macro.9", ses)); +#endif + break; + case ACT_MAIN_MARK_CLIPBOARD: status = mark_clipboard(ses, doc_view); break;