aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandy Palamar <randy@rnpnr.xyz>2024-05-28 07:54:34 -0600
committerRandy Palamar <randy@rnpnr.xyz>2024-05-30 05:30:10 -0600
commit9bfb31fcbee028eaecce75a743f2a0bd50b5807c (patch)
tree00c36f8595fbd42636ed00c2c199d5b9c8454f62
parent70fa1e8594be04c203179e8249a27ae648a81e71 (diff)
downloadvis-9bfb31fcbee028eaecce75a743f2a0bd50b5807c.tar.gz
vis-9bfb31fcbee028eaecce75a743f2a0bd50b5807c.tar.xz
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.
-rw-r--r--event-basic.c5
-rw-r--r--main.c46
-rw-r--r--vis-core.h1
-rw-r--r--vis-lua.c7
-rw-r--r--vis.c1
5 files changed, 26 insertions, 34 deletions
diff --git a/event-basic.c b/event-basic.c
index d59ef8a..e070522 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 85330cb..3e9d9ab 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 bc9736e..182c537 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 629886f..e3e85c3 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 ed16f79..7d3dd6a 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]);