1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-26 01:15:37 +00:00

[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"
This commit is contained in:
Witold Filipczyk 2022-11-13 15:12:21 +01:00
parent b6271bae85
commit 5fa0552ab0
6 changed files with 144 additions and 3 deletions

View File

@ -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),

View File

@ -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 *

View File

@ -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.")),

View File

@ -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)

View File

@ -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
}

View File

@ -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;