Skip to content

Commit

Permalink
[exmode] Introduced 10 macro config options. macro.0 to macro.9 . Refs
Browse files Browse the repository at this point in the history
…#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"
  • Loading branch information
rkd77 committed Nov 13, 2022
1 parent b6271ba commit 5fa0552
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/config/actions-main.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/config/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
47 changes: 45 additions & 2 deletions src/config/options.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.")),
Expand Down
27 changes: 27 additions & 0 deletions src/dialogs/exmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/exmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
60 changes: 60 additions & 0 deletions src/viewer/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5fa0552

Please sign in to comment.