diff options
Diffstat (limited to 'src/nvim/main.c')
-rw-r--r-- | src/nvim/main.c | 89 |
1 files changed, 62 insertions, 27 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 6b382ae320..af54e62393 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -23,6 +23,7 @@ #include "nvim/fold.h" #include "nvim/getchar.h" #include "nvim/hashtab.h" +#include "nvim/highlight.h" #include "nvim/iconv.h" #include "nvim/if_cscope.h" #ifdef HAVE_LOCALE_H @@ -64,6 +65,7 @@ #include "nvim/msgpack_rpc/helpers.h" #include "nvim/msgpack_rpc/server.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/api/ui.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/handle.h" @@ -160,6 +162,7 @@ bool event_teardown(void) } multiqueue_process_events(main_loop.events); + loop_poll_events(&main_loop, 0); // Drain thread_events, fast_events. input_stop(); channel_teardown(); process_teardown(&main_loop); @@ -182,6 +185,7 @@ void early_init(void) eval_init(); // init global variables init_path(argv0 ? argv0 : "nvim"); init_normal_cmds(); // Init the table of Normal mode commands. + highlight_init(); #if defined(HAVE_LOCALE_H) // Setup to use the current locale (for ctype() and many other things). @@ -254,6 +258,14 @@ int main(int argc, char **argv) // Process the command line arguments. File names are put in the global // argument list "global_alist". command_line_scan(¶ms); + + if (embedded_mode) { + const char *err; + if (!channel_from_stdio(true, CALLBACK_READER_INIT, &err)) { + abort(); + } + } + server_init(params.listen_addr); if (GARGCOUNT > 0) { @@ -301,6 +313,7 @@ int main(int argc, char **argv) // Read ex-commands if invoked with "-es". // bool reading_tty = !headless_mode + && !embedded_mode && !silent_mode && (params.input_isatty || params.output_isatty || params.err_isatty); @@ -341,6 +354,22 @@ int main(int argc, char **argv) p_lpl = false; } + // give embedders a chance to set up nvim, by processing a request before + // startup. This allows an external UI to show messages and prompts from + // --cmd and buffer loading (e.g. swap files) + bool early_ui = false; + if (embedded_mode && !headless_mode) { + TIME_MSG("waiting for embedder to make request"); + remote_ui_wait_for_attach(); + TIME_MSG("done waiting for embedder"); + + // prepare screen now, so external UIs can display messages + starting = NO_BUFFERS; + screenclear(); + early_ui = true; + TIME_MSG("initialized screen early for embedder"); + } + // Execute --cmd arguments. exe_pre_commands(¶ms); @@ -446,16 +475,17 @@ int main(int argc, char **argv) wait_return(true); } - if (!headless_mode && !silent_mode) { + if (!headless_mode && !embedded_mode && !silent_mode) { input_stop(); // Stop reading input, let the UI take over. ui_builtin_start(); } setmouse(); // may start using the mouse - ui_reset_scroll_region(); // In case Rows changed - if (exmode_active) { - must_redraw = CLEAR; // Don't clear the screen when starting in Ex mode. + if (exmode_active || early_ui) { + // Don't clear the screen when starting in Ex mode, or when an + // embedding UI might have displayed messages + must_redraw = CLEAR; } else { screenclear(); // clear screen TIME_MSG("clearing screen"); @@ -604,9 +634,14 @@ void getout(int exitval) buf_T *buf = wp->w_buffer; if (buf_get_changedtick(buf) != -1) { + bufref_T bufref; + + set_bufref(&bufref, buf); apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, false, buf); - buf_set_changedtick(buf, -1); // note that we did it already + if (bufref_valid(&bufref)) { + buf_set_changedtick(buf, -1); // note that we did it already + } // start all over, autocommands may mess up the lists next_tp = first_tabpage; break; @@ -805,7 +840,7 @@ static void command_line_scan(mparm_T *parmp) } if (p == NULL) { - emsgf(_(e_outofmem)); + EMSG(_(e_outofmem)); } Object md = DICTIONARY_OBJ(api_metadata()); @@ -821,11 +856,6 @@ static void command_line_scan(mparm_T *parmp) headless_mode = true; } else if (STRICMP(argv[0] + argv_idx, "embed") == 0) { embedded_mode = true; - headless_mode = true; - const char *err; - if (!channel_from_stdio(true, CALLBACK_READER_INIT, &err)) { - abort(); - } } else if (STRNICMP(argv[0] + argv_idx, "listen", 6) == 0) { want_argument = true; argv_idx += 6; @@ -886,6 +916,7 @@ static void command_line_scan(mparm_T *parmp) set_option_value("rl", 1L, NULL, 0); break; } + case '?': // "-?" give help message (for MS-Windows) case 'h': { // "-h" give help message usage(); mch_exit(0); @@ -902,7 +933,8 @@ static void command_line_scan(mparm_T *parmp) } case 'M': { // "-M" no changes or writing of files reset_modifiable(); - } // FALLTHROUGH + FALLTHROUGH; + } case 'm': { // "-m" no writing of files p_write = false; break; @@ -1017,7 +1049,8 @@ static void command_line_scan(mparm_T *parmp) argv_idx = -1; break; } - } // FALLTHROUGH + FALLTHROUGH; + } case 'S': // "-S {file}" execute Vim script case 'i': // "-i {shada}" use for ShaDa file case 'u': // "-u {vimrc}" vim inits file @@ -1161,7 +1194,8 @@ scripterror: argv_idx = -1; break; } - } // FALLTHROUGH + FALLTHROUGH; + } case 'W': { // "-W {scriptout}" overwrite script file if (scriptout != NULL) { goto scripterror; @@ -1372,7 +1406,7 @@ static void handle_quickfix(mparm_T *paramp) paramp->use_ef, OPT_FREE, SID_CARG); vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef); if (qf_init(NULL, p_ef, p_efm, true, IObuff, p_menc) < 0) { - ui_linefeed(); + msg_putchar('\n'); mch_exit(3); } TIME_MSG("reading errorfile"); @@ -1533,7 +1567,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) { int arg_idx; /* index in argument list */ int i; - int advance = TRUE; + bool advance = true; win_T *win; /* @@ -1544,8 +1578,8 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) /* When w_arg_idx is -1 remove the window (see create_windows()). */ if (curwin->w_arg_idx == -1) { - win_close(curwin, TRUE); - advance = FALSE; + win_close(curwin, true); + advance = false; } arg_idx = 1; @@ -1555,9 +1589,9 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) } // When w_arg_idx is -1 remove the window (see create_windows()). if (curwin->w_arg_idx == -1) { - ++arg_idx; - win_close(curwin, TRUE); - advance = FALSE; + arg_idx++; + win_close(curwin, true); + advance = false; continue; } @@ -1572,7 +1606,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) win_enter(curwin->w_next, false); } } - advance = TRUE; + advance = true; // Only open the file if there is no file in this window yet (that can // happen when vimrc contains ":sall"). @@ -1591,12 +1625,13 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) did_emsg = FALSE; /* avoid hit-enter prompt */ getout(1); } - win_close(curwin, TRUE); - advance = FALSE; + win_close(curwin, true); + advance = false; + } + if (arg_idx == GARGCOUNT - 1) { + arg_had_last = true; } - if (arg_idx == GARGCOUNT - 1) - arg_had_last = TRUE; - ++arg_idx; + arg_idx++; } os_breakcheck(); if (got_int) { |