Skip to content

Commit

Permalink
remove the vis->initialized member
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rnpnr committed May 30, 2024
1 parent 70fa1e8 commit 9bfb31f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 34 deletions.
5 changes: 0 additions & 5 deletions event-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
46 changes: 24 additions & 22 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion vis-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 1 addition & 6 deletions vis-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 9bfb31f

Please sign in to comment.