diff --git a/event-basic.c b/event-basic.c index d59ef8aa8..e07052281 100644 --- a/event-basic.c +++ b/event-basic.c @@ -4,11 +4,6 @@ #if !CONFIG_LUA bool vis_event_emit(Vis *vis, enum VisEvents id, ...) { - if (!vis->initialized) { - vis->initialized = true; - ui_init(&vis->ui, vis); - } - va_list ap; va_start(ap, id); diff --git a/main.c b/main.c index 85330cbc5..3e9d9ab8b 100644 --- a/main.c +++ b/main.c @@ -2214,10 +2214,34 @@ static void signal_handler(int signum, siginfo_t *siginfo, void *context) { } int main(int argc, char *argv[]) { + for (int i = 1; i < argc; i++) { + if (argv[i][0] != '-') { + continue; + } else if (strcmp(argv[i], "-") == 0) { + continue; + } else if (strcmp(argv[i], "--") == 0) { + break; + } else if (strcmp(argv[i], "-v") == 0) { + printf("vis %s%s%s%s%s%s%s\n", VERSION, + CONFIG_CURSES ? " +curses" : "", + CONFIG_LUA ? " +lua" : "", + CONFIG_LPEG ? " +lpeg" : "", + CONFIG_TRE ? " +tre" : "", + CONFIG_ACL ? " +acl" : "", + CONFIG_SELINUX ? " +selinux" : ""); + return 0; + } else { + fprintf(stderr, "Unknown command option: %s\n", argv[i]); + return 1; + } + } + vis = vis_new(); if (!vis) return EXIT_FAILURE; + vis_event_emit(vis, VIS_EVENT_INIT); + for (int i = 0; i < LENGTH(vis_action); i++) { const KeyAction *action = &vis_action[i]; if (!vis_action_register(vis, action)) @@ -2264,28 +2288,6 @@ int main(int argc, char *argv[]) { if (sigprocmask(SIG_BLOCK, &blockset, NULL) == -1) vis_die(vis, "Failed to block signals\n"); - for (int i = 1; i < argc; i++) { - if (argv[i][0] != '-') { - continue; - } else if (strcmp(argv[i], "-") == 0) { - continue; - } else if (strcmp(argv[i], "--") == 0) { - break; - } else if (strcmp(argv[i], "-v") == 0) { - printf("vis %s%s%s%s%s%s%s\n", VERSION, - CONFIG_CURSES ? " +curses" : "", - CONFIG_LUA ? " +lua" : "", - CONFIG_LPEG ? " +lpeg" : "", - CONFIG_TRE ? " +tre" : "", - CONFIG_ACL ? " +acl" : "", - CONFIG_SELINUX ? " +selinux" : ""); - return 0; - } else { - fprintf(stderr, "Unknown command option: %s\n", argv[i]); - return 1; - } - } - char *cmd = NULL; bool end_of_options = false, win_created = false; diff --git a/vis-core.h b/vis-core.h index bc9736ed1..182c53732 100644 --- a/vis-core.h +++ b/vis-core.h @@ -205,7 +205,6 @@ struct Vis { Action action_prev; /* last operator action used by the repeat (dot) command */ Mode *mode; /* currently active mode, used to search for keybindings */ Mode *mode_prev; /* previously active user mode */ - bool initialized; /* whether UI and Lua integration has been initialized */ int nesting_level; /* parsing state to hold keep track of { } nesting level */ volatile bool running; /* exit main loop once this becomes false */ int exit_status; /* exit status when terminating main loop */ diff --git a/vis-lua.c b/vis-lua.c index 629886f4f..e3e85c345 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -3608,18 +3608,13 @@ static void vis_lua_ui_draw(Vis *vis) { } bool vis_event_emit(Vis *vis, enum VisEvents id, ...) { - if (!vis->initialized) { - vis->initialized = true; - ui_init(&vis->ui, vis); - vis_lua_init(vis); - } - va_list ap; va_start(ap, id); bool ret = true; switch (id) { case VIS_EVENT_INIT: + vis_lua_init(vis); break; case VIS_EVENT_START: vis_lua_start(vis); diff --git a/vis.c b/vis.c index ed16f79f4..7d3dd6a96 100644 --- a/vis.c +++ b/vis.c @@ -573,6 +573,7 @@ Vis *vis_new(void) { free(vis); return NULL; } + ui_init(&vis->ui, vis); vis->change_colors = true; for (size_t i = 0; i < LENGTH(vis->registers); i++) register_init(&vis->registers[i]);