vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 7807fa6b16b1c5675f0936a3780f2327fab66c53 parent 1f01b3596e04ead1856f3d910254333dc80b7d10 Author: Randy Palamar <randy@rnpnr.xyz> Date: Tue, 28 May 2024 07:54:34 -0600 remove the vis->initialized member I already fixed the reason that this even existed (vis_event_emit getting called at random times when the editor wasn't ready). The option checking in main() was moved up because I noticed it was in the wrong place while thinking about where to emit the INIT event. There is no reason to do a bunch of useless work just to print the version. Diffstat:
| M | event-basic.c | | | 5 | ----- |
| M | main.c | | | 46 | ++++++++++++++++++++++++---------------------- |
| M | vis-core.h | | | 1 | - |
| M | vis-lua.c | | | 7 | +------ |
| M | vis.c | | | 1 | + |
5 files changed, 26 insertions(+), 34 deletions(-)
diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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]);