main: Initialize event loop before command_line_scan

The call to `event_init()` was too late. `command_line_scan()` in `main()` could
already need the loop initialized. Ref https://github.com/neovim/neovim/issues/3045#issuecomment-123405833.

A consequence of this change is that it was necessary to move the
`channel_from_stdio()` call to `command_line_scan()` when embedded_mode is set.
This commit is contained in:
Thiago de Arruda
2015-08-21 07:58:51 -03:00
parent 1beee0685d
commit cb87670ff8
2 changed files with 3 additions and 7 deletions

View File

@@ -245,6 +245,7 @@ int main(int argc, char **argv)
set_vim_var_string(VV_PROGPATH, (char_u *)argv[0], -1); set_vim_var_string(VV_PROGPATH, (char_u *)argv[0], -1);
set_vim_var_string(VV_PROGNAME, path_tail((char_u *)argv[0]), -1); set_vim_var_string(VV_PROGNAME, path_tail((char_u *)argv[0]), -1);
event_init();
/* /*
* Process the command line arguments. File names are put in the global * Process the command line arguments. File names are put in the global
* argument list "global_alist". * argument list "global_alist".
@@ -275,7 +276,6 @@ int main(int argc, char **argv)
if (GARGCOUNT > 1 && !silent_mode) if (GARGCOUNT > 1 && !silent_mode)
printf(_("%d files to edit\n"), GARGCOUNT); printf(_("%d files to edit\n"), GARGCOUNT);
event_init();
full_screen = true; full_screen = true;
t_colors = 256; t_colors = 256;
check_tty(&params); check_tty(&params);
@@ -963,6 +963,7 @@ static void command_line_scan(mparm_T *parmp)
} else if (STRICMP(argv[0] + argv_idx, "embed") == 0) { } else if (STRICMP(argv[0] + argv_idx, "embed") == 0) {
embedded_mode = true; embedded_mode = true;
parmp->headless = true; parmp->headless = true;
channel_from_stdio();
} else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) { } else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) {
#if !defined(UNIX) #if !defined(UNIX)
parmp->literal = TRUE; parmp->literal = TRUE;

View File

@@ -93,11 +93,6 @@ void channel_init(void)
channels = pmap_new(uint64_t)(); channels = pmap_new(uint64_t)();
event_strings = pmap_new(cstr_t)(); event_strings = pmap_new(cstr_t)();
msgpack_sbuffer_init(&out_buffer); msgpack_sbuffer_init(&out_buffer);
if (embedded_mode) {
channel_from_stdio();
}
remote_ui_init(); remote_ui_init();
} }
@@ -316,7 +311,7 @@ bool channel_close(uint64_t id)
/// Creates an API channel from stdin/stdout. This is used when embedding /// Creates an API channel from stdin/stdout. This is used when embedding
/// Neovim /// Neovim
static void channel_from_stdio(void) void channel_from_stdio(void)
{ {
Channel *channel = register_channel(kChannelTypeStdio); Channel *channel = register_channel(kChannelTypeStdio);
incref(channel); // stdio channels are only closed on exit incref(channel); // stdio channels are only closed on exit