aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/main.c')
-rw-r--r--src/nvim/main.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 71a972e8f6..c7a60d07c1 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -30,7 +30,6 @@
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/log.h"
#include "nvim/memory.h"
@@ -58,13 +57,13 @@
#include "nvim/event/loop.h"
#include "nvim/os/signal.h"
#include "nvim/event/process.h"
-#include "nvim/msgpack_rpc/defs.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/msgpack_rpc/server.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/handle.h"
+#include "nvim/api/private/dispatch.h"
/* Maximum number of commands from + or -c arguments. */
#define MAX_ARG_CMDS 10
@@ -120,6 +119,8 @@ typedef struct {
# include "main.c.generated.h"
#endif
+Loop main_loop;
+
static char *argv0;
// Error messages
@@ -133,7 +134,7 @@ static const char *err_extra_cmd =
void event_init(void)
{
- loop_init(&loop, NULL);
+ loop_init(&main_loop, NULL);
// early msgpack-rpc initialization
msgpack_rpc_init_method_table();
msgpack_rpc_helpers_init();
@@ -151,19 +152,20 @@ void event_init(void)
void event_teardown(void)
{
- if (!loop.events) {
+ if (!main_loop.events) {
return;
}
- queue_process_events(loop.events);
+ multiqueue_process_events(main_loop.events);
input_stop();
channel_teardown();
- process_teardown(&loop);
+ process_teardown(&main_loop);
+ timer_teardown();
server_teardown();
signal_teardown();
terminal_teardown();
- loop_close(&loop);
+ loop_close(&main_loop, true);
}
/// Performs early initialization.
@@ -175,7 +177,6 @@ void early_init(void)
fs_init();
handle_init();
- (void)mb_init(); // init mb_bytelen_tab[] to ones
eval_init(); // init global variables
// Init the table of Normal mode commands.
@@ -248,8 +249,9 @@ int main(int argc, char **argv)
*/
command_line_scan(&params);
- if (GARGCOUNT > 0)
- fname = get_fname(&params);
+ if (GARGCOUNT > 0) {
+ fname = get_fname(&params, cwd);
+ }
TIME_MSG("expanding arguments");
@@ -267,13 +269,7 @@ int main(int argc, char **argv)
setbuf(stdout, NULL);
- /* This message comes before term inits, but after setting "silent_mode"
- * when the input is not a tty. */
- if (GARGCOUNT > 1 && !silent_mode)
- printf(_("%d files to edit\n"), GARGCOUNT);
-
full_screen = true;
- t_colors = 256;
check_tty(&params);
/*
@@ -318,14 +314,18 @@ int main(int argc, char **argv)
// open terminals when opening files that start with term://
#define PROTO "term://"
+ do_cmdline_cmd("augroup nvim_terminal");
+ do_cmdline_cmd("autocmd!");
do_cmdline_cmd("autocmd BufReadCmd " PROTO "* nested "
- ":call termopen( "
+ ":if !exists('b:term_title')|call termopen( "
// Capture the command string
"matchstr(expand(\"<amatch>\"), "
"'\\c\\m" PROTO "\\%(.\\{-}//\\%(\\d\\+:\\)\\?\\)\\?\\zs.*'), "
// capture the working directory
"{'cwd': get(matchlist(expand(\"<amatch>\"), "
- "'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, '')})");
+ "'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, '')})"
+ "|endif");
+ do_cmdline_cmd("augroup END");
#undef PROTO
/* Execute --cmd arguments. */
@@ -504,11 +504,15 @@ int main(int argc, char **argv)
no_wait_return = FALSE;
starting = 0;
+ // 'autochdir' has been postponed.
+ do_autochdir();
+
/* start in insert mode */
if (p_im)
need_start_insertmode = TRUE;
- apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf);
+ set_vim_var_nr(VV_VIM_DID_ENTER, 1L);
+ apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf);
TIME_MSG("VimEnter autocommands");
/* When a startup script or session file setup for diff'ing and
@@ -530,7 +534,7 @@ int main(int argc, char **argv)
}
TIME_MSG("before starting main loop");
- ILOG("Starting Neovim main loop.");
+ ILOG("starting main loop");
/*
* Call the main command loop. This never returns.
@@ -553,6 +557,8 @@ void getout(int exitval)
if (exmode_active)
exitval += ex_exitval;
+ set_vim_var_nr(VV_EXITING, exitval);
+
/* Position the cursor on the last screen line, below all the text */
ui_cursor_goto((int)Rows - 1, 0);
@@ -665,8 +671,8 @@ static void init_locale(void)
{
char_u *p;
- /* expand_env() doesn't work yet, because chartab[] is not initialized
- * yet, call vim_getenv() directly */
+ // expand_env() doesn't work yet, because g_chartab[] is not
+ // initialized yet, call vim_getenv() directly
p = (char_u *)vim_getenv("VIMRUNTIME");
if (p != NULL && *p != NUL) {
vim_snprintf((char *)NameBuff, MAXPATHL, "%s/lang", p);
@@ -1191,7 +1197,7 @@ static void check_and_set_isatty(mparm_T *paramp)
/*
* Get filename from command line, given that there is one.
*/
-static char_u *get_fname(mparm_T *parmp)
+static char_u *get_fname(mparm_T *parmp, char_u *cwd)
{
#if !defined(UNIX)
/*
@@ -1236,8 +1242,11 @@ static void set_window_layout(mparm_T *paramp)
static void load_plugins(void)
{
if (p_lpl) {
- source_runtime((char_u *)"plugin/**/*.vim", TRUE);
+ source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL); // NOLINT
TIME_MSG("loading plugins");
+
+ ex_packloadall(NULL);
+ TIME_MSG("loading packages");
}
}
@@ -1665,8 +1674,6 @@ static bool do_user_initialization(void)
}
/// Source startup scripts
-///
-/// @param[in]
static void source_startup_scripts(const mparm_T *const parmp)
FUNC_ATTR_NONNULL_ALL
{
@@ -1756,7 +1763,7 @@ static int process_env(char *env, bool is_viminit)
do_cmdline_cmd((char *)initstr);
sourcing_name = save_sourcing_name;
sourcing_lnum = save_sourcing_lnum;
- current_SID = save_sid;;
+ current_SID = save_sid;
return OK;
}
return FAIL;