From fe074611cd5b3319a3f639f68289df6a718e64eb Mon Sep 17 00:00:00 2001 From: Jurica Bradarić Date: Sun, 6 Oct 2019 05:35:48 +0200 Subject: vim-patch:8.1.1371: cannot recover from a swap file #11081 Problem: Cannot recover from a swap file. Solution: Do not expand environment variables in the swap file name. Do not check the extension when we already know a file is a swap file. (Ken Takata, closes 4415, closes vim/vim#4369) https://github.com/vim/vim/commit/99499b1c05f85f83876b828eea3f6e14f0f407b4 --- src/nvim/main.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index be1f08bb46..ba15dcedad 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1460,12 +1460,13 @@ static void create_windows(mparm_T *parmp) } else parmp->window_count = 1; - if (recoverymode) { /* do recover */ - msg_scroll = TRUE; /* scroll message up */ - ml_recover(); - if (curbuf->b_ml.ml_mfp == NULL) /* failed */ + if (recoverymode) { // do recover + msg_scroll = true; // scroll message up + ml_recover(true); + if (curbuf->b_ml.ml_mfp == NULL) { // failed getout(1); - do_modelines(0); /* do modelines */ + } + do_modelines(0); // do modelines } else { // Open a buffer for windows that don't have one yet. // Commands in the vimrc might have loaded a file or split the window. @@ -1778,7 +1779,8 @@ static bool do_user_initialization(void) if (do_source(user_vimrc, true, DOSO_VIMRC) != FAIL) { do_exrc = p_exrc; if (do_exrc) { - do_exrc = (path_full_compare((char_u *)VIMRC_FILE, user_vimrc, false) + do_exrc = (path_full_compare((char_u *)VIMRC_FILE, user_vimrc, + false, true) != kEqualFiles); } xfree(user_vimrc); @@ -1805,7 +1807,7 @@ static bool do_user_initialization(void) do_exrc = p_exrc; if (do_exrc) { do_exrc = (path_full_compare((char_u *)VIMRC_FILE, (char_u *)vimrc, - false) != kEqualFiles); + false, true) != kEqualFiles); } xfree(vimrc); xfree(config_dirs); -- cgit From 9af0fe529d2d91640e4d3388ab9f28159553f14c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 11 Oct 2019 19:17:11 +0200 Subject: recovery mode (-r/-L): use headless_mode (#11187) Fixes https://github.com/neovim/neovim/issues/11181. --- src/nvim/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index ba15dcedad..e0a1e60fc0 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -957,6 +957,7 @@ static void command_line_scan(mparm_T *parmp) case 'r': // "-r" recovery mode case 'L': { // "-L" recovery mode recoverymode = 1; + headless_mode = true; break; } case 's': { -- cgit From 474d0bcbf724c7eed740f60391a0ed35d651e1d3 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 27 Oct 2019 20:49:03 +0100 Subject: lua: vim.rpcrequest, vim.rpcnotify, vim.NIL --- src/nvim/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index e0a1e60fc0..e39eec4038 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -27,6 +27,7 @@ #include "nvim/highlight.h" #include "nvim/iconv.h" #include "nvim/if_cscope.h" +#include "nvim/lua/executor.h" #ifdef HAVE_LOCALE_H # include #endif -- cgit From 8819b5c06eea1f47d6a8f2c00498e55a580d5519 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 24 Nov 2019 23:10:25 -0500 Subject: vim-patch:8.1.0461: quickfix: change comment style #11453 Problem: Quickfix code uses too many /* */ comments. Solution: Change to // comments. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/00bf8cd2115be7c14258aee48c0a7568147c9cd7 --- src/nvim/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index e39eec4038..c8959d9ad1 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1516,7 +1516,7 @@ static void create_windows(mparm_T *parmp) /* We can't close the window, it would disturb what * happens next. Clear the file name and set the arg * index to -1 to delete it later. */ - setfname(curbuf, NULL, NULL, FALSE); + setfname(curbuf, NULL, NULL, false); curwin->w_arg_idx = -1; swap_exists_action = SEA_NONE; } else -- cgit From 22b52dd462e5dc9d5429305215bfb20aa20517c5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 2 Dec 2019 22:21:15 +0100 Subject: log_init: call log_path_init (#11501) This has to be done after `init_homedir` for XDG default and `set_init_1` for lookup from env, which could be done earlier likely (to help with https://github.com/neovim/neovim/issues/10937), but this keeps it in sync with Vim. Fixes https://github.com/neovim/neovim/issues/11499. --- src/nvim/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index c8959d9ad1..c7011f4f4e 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -144,7 +144,6 @@ static const char *err_extra_cmd = void event_init(void) { - log_init(); loop_init(&main_loop, NULL); resize_events = multiqueue_new_child(main_loop.events); @@ -220,6 +219,7 @@ void early_init(void) // First find out the home directory, needed to expand "~" in options. init_homedir(); // find real value of $HOME set_init_1(); + log_init(); TIME_MSG("inits 1"); set_lang_var(); // set v:lang and v:ctype -- cgit From 5355cee77d7b3b62917036281406726832b6d7dc Mon Sep 17 00:00:00 2001 From: erw7 Date: Sat, 9 Nov 2019 15:46:12 +0900 Subject: Change to use ConPTY, if available --- src/nvim/main.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index c7011f4f4e..33c0466e1a 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -46,6 +46,9 @@ #include "nvim/option.h" #include "nvim/os_unix.h" #include "nvim/os/os_defs.h" +#ifdef WIN32 +# include "nvim/os/os_win_conpty.h" +#endif #include "nvim/path.h" #include "nvim/profile.h" #include "nvim/popupmnu.h" @@ -226,6 +229,9 @@ void early_init(void) init_signs(); ui_comp_syn_init(); +#ifdef WIN32 + os_dyn_conpty_init(); +#endif } #ifdef MAKE_LIB -- cgit From 59ae38a9196d596e2fe511eeb216e314bfc3dac7 Mon Sep 17 00:00:00 2001 From: erw7 Date: Sat, 16 Nov 2019 12:59:07 +0900 Subject: Change to use TriState instead of bool Co-Authored-By: Justin M. Keyes --- src/nvim/main.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index 33c0466e1a..c7011f4f4e 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -46,9 +46,6 @@ #include "nvim/option.h" #include "nvim/os_unix.h" #include "nvim/os/os_defs.h" -#ifdef WIN32 -# include "nvim/os/os_win_conpty.h" -#endif #include "nvim/path.h" #include "nvim/profile.h" #include "nvim/popupmnu.h" @@ -229,9 +226,6 @@ void early_init(void) init_signs(); ui_comp_syn_init(); -#ifdef WIN32 - os_dyn_conpty_init(); -#endif } #ifdef MAKE_LIB -- cgit From 2c8016c7048051da9afd809b580cf8f2d2c69614 Mon Sep 17 00:00:00 2001 From: erw7 Date: Sat, 16 Nov 2019 13:45:37 +0900 Subject: Add stdin, stdout replacement functions --- src/nvim/main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index c7011f4f4e..be279b449a 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -64,6 +64,9 @@ #include "nvim/os/os.h" #include "nvim/os/time.h" #include "nvim/os/fileio.h" +#ifdef WIN32 +# include "nvim/os/os_win_console.h" +#endif #include "nvim/event/loop.h" #include "nvim/os/signal.h" #include "nvim/event/process.h" @@ -1120,13 +1123,7 @@ scripterror: const int stdin_dup_fd = os_dup(STDIN_FILENO); #ifdef WIN32 // Replace the original stdin with the console input handle. - close(STDIN_FILENO); - const HANDLE conin_handle = - CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, - OPEN_EXISTING, 0, (HANDLE)NULL); - const int conin_fd = _open_osfhandle(conin_handle, _O_RDONLY); - assert(conin_fd == STDIN_FILENO); + os_replace_stdin_to_conin(); #endif FileDescriptor *const stdin_dup = file_open_fd_new( &error, stdin_dup_fd, kFileReadOnly|kFileNonBlocking); -- cgit From c6ff23d7a0d5ccf0d8995e3204c18df55d28fc7f Mon Sep 17 00:00:00 2001 From: Chris LaRose Date: Sun, 26 Jan 2020 00:24:42 -0800 Subject: terminal: absolute CWD in term:// URI #11289 This makes it possible to restore the working directory of :terminal buffers when reading those buffers from a session file. Fixes #11288 Co-authored-by: Justin M. Keyes --- src/nvim/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index be279b449a..a816221a9e 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -339,8 +339,8 @@ int main(int argc, char **argv) "matchstr(expand(\"\"), " "'\\c\\m" PROTO "\\%(.\\{-}//\\%(\\d\\+:\\)\\?\\)\\?\\zs.*'), " // capture the working directory - "{'cwd': get(matchlist(expand(\"\"), " - "'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, '')})" + "{'cwd': expand(get(matchlist(expand(\"\"), " + "'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, ''))})" "|endif"); do_cmdline_cmd("augroup END"); #undef PROTO -- cgit From efa5af904387d8ece68c84a568d60e071350c6cb Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 2 Feb 2020 21:56:47 -0800 Subject: refactor: rename mch_exit => os_exit - No code changes - Move it to main.c --- src/nvim/main.c | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index a816221a9e..bdaa20773c 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -207,7 +207,7 @@ void early_init(void) // Allocate the first window and buffer. // Can't do anything without it, exit when it fails. if (!win_alloc_first()) { - mch_exit(0); + os_exit(0); } init_yank(); // init yank buffers @@ -400,7 +400,7 @@ int main(int argc, char **argv) */ if (recoverymode && fname == NULL) { recover_names(NULL, TRUE, 0, NULL); - mch_exit(0); + os_exit(0); } // Set some option defaults after reading vimrc files. @@ -585,6 +585,31 @@ int main(int argc, char **argv) return 0; } +void os_exit(int r) + FUNC_ATTR_NORETURN +{ + exiting = true; + + ui_flush(); + ui_call_stop(); + ml_close_all(true); // remove all memfiles + + if (!event_teardown() && r == 0) { + r = 1; // Exit with error if main_loop did not teardown gracefully. + } + if (input_global_fd() >= 0) { + stream_set_blocking(input_global_fd(), true); // normalize stream (#2598) + } + + ILOG("Nvim exit: %d", r); + +#ifdef EXITFREE + free_all_mem(); +#endif + + exit(r); +} + /// Exit properly void getout(int exitval) FUNC_ATTR_NORETURN @@ -679,7 +704,7 @@ void getout(int exitval) garbage_collect(false); } - mch_exit(exitval); + os_exit(exitval); } /// Gets the integer value of a numeric command line argument if given, @@ -799,10 +824,10 @@ static void command_line_scan(mparm_T *parmp) // "--cmd " execute cmd before vimrc if (STRICMP(argv[0] + argv_idx, "help") == 0) { usage(); - mch_exit(0); + os_exit(0); } else if (STRICMP(argv[0] + argv_idx, "version") == 0) { version(); - mch_exit(0); + os_exit(0); } else if (STRICMP(argv[0] + argv_idx, "api-info") == 0) { FileDescriptor fp; const int fof_ret = file_open_fd(&fp, STDOUT_FILENO, @@ -825,7 +850,7 @@ static void command_line_scan(mparm_T *parmp) if (ff_ret < 0) { msgpack_file_write_error(ff_ret); } - mch_exit(0); + os_exit(0); } else if (STRICMP(argv[0] + argv_idx, "headless") == 0) { headless_mode = true; } else if (STRICMP(argv[0] + argv_idx, "embed") == 0) { @@ -891,7 +916,7 @@ static void command_line_scan(mparm_T *parmp) case '?': // "-?" give help message (for MS-Windows) case 'h': { // "-h" give help message usage(); - mch_exit(0); + os_exit(0); } case 'H': { // "-H" start in Hebrew mode: rl + hkmap set. p_hkmap = true; @@ -988,7 +1013,7 @@ static void command_line_scan(mparm_T *parmp) } case 'v': { version(); - mch_exit(0); + os_exit(0); } case 'V': { // "-V{N}" Verbose level // default is 10: a little bit verbose @@ -1116,7 +1141,7 @@ scripterror: _("Attempt to open script file again: \"%s %s\"\n"), argv[-1], argv[0]); mch_errmsg((const char *)IObuff); - mch_exit(2); + os_exit(2); } int error; if (strequal(argv[0], "-")) { @@ -1135,7 +1160,7 @@ scripterror: _("Cannot open for reading: \"%s\": %s\n"), argv[0], os_strerror(error)); mch_errmsg((const char *)IObuff); - mch_exit(2); + os_exit(2); } save_typebuf(); break; @@ -1173,7 +1198,7 @@ scripterror: mch_errmsg(_("Cannot open for script output: \"")); mch_errmsg(argv[0]); mch_errmsg("\"\n"); - mch_exit(2); + os_exit(2); } break; } @@ -1380,7 +1405,7 @@ static void handle_quickfix(mparm_T *paramp) vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef); if (qf_init(NULL, p_ef, p_efm, true, IObuff, p_menc) < 0) { msg_putchar('\n'); - mch_exit(3); + os_exit(3); } TIME_MSG("reading errorfile"); } @@ -1943,7 +1968,7 @@ static void mainerr(const char *errstr, const char *str) mch_errmsg(prgname); mch_errmsg(" -h\"\n"); - mch_exit(1); + os_exit(1); } /// Prints version information for "nvim -v" or "nvim --version". -- cgit From 2af04e199740d5d2eaab38e272ecf1f9146335f5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 2 Feb 2020 22:07:16 -0800 Subject: lint --- src/nvim/main.c | 94 +++++++++++++++++++++++++-------------------------------- 1 file changed, 41 insertions(+), 53 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index bdaa20773c..56d9030a7f 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -293,8 +293,8 @@ int main(int argc, char **argv) if (params.diff_mode && params.window_count == -1) params.window_count = 0; /* open up to 3 windows */ - /* Don't redraw until much later. */ - ++RedrawingDisabled; + // Don't redraw until much later. + RedrawingDisabled++; setbuf(stdout, NULL); @@ -384,22 +384,16 @@ int main(int argc, char **argv) syn_maybe_on(); } - /* - * Read all the plugin files. - * Only when compiled with +eval, since most plugins need it. - */ + // Read all the plugin files. load_plugins(); // Decide about window layout for diff mode after reading vimrc. set_window_layout(¶ms); - /* - * Recovery mode without a file name: List swap files. - * This uses the 'dir' option, therefore it must be after the - * initializations. - */ + // Recovery mode without a file name: List swap files. + // Uses the 'dir' option, therefore it must be after the initializations. if (recoverymode && fname == NULL) { - recover_names(NULL, TRUE, 0, NULL); + recover_names(NULL, true, 0, NULL); os_exit(0); } @@ -431,17 +425,15 @@ int main(int argc, char **argv) set_vim_var_list(VV_OLDFILES, tv_list_alloc(0)); } - /* - * "-q errorfile": Load the error file now. - * If the error file can't be read, exit before doing anything else. - */ + // "-q errorfile": Load the error file now. + // If the error file can't be read, exit before doing anything else. handle_quickfix(¶ms); - /* - * Start putting things on the screen. - * Scroll screen down before drawing over it - * Clear screen now, so file message will not be cleared. - */ + // + // Start putting things on the screen. + // Scroll screen down before drawing over it + // Clear screen now, so file message will not be cleared. + // starting = NO_BUFFERS; no_wait_return = false; if (!exmode_active) { @@ -473,27 +465,26 @@ int main(int argc, char **argv) no_wait_return = true; - /* - * Create the requested number of windows and edit buffers in them. - * Also does recovery if "recoverymode" set. - */ + // + // Create the requested number of windows and edit buffers in them. + // Also does recovery if "recoverymode" set. + // create_windows(¶ms); TIME_MSG("opening buffers"); - /* clear v:swapcommand */ + // Clear v:swapcommand set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); - /* Ex starts at last line of the file */ - if (exmode_active) + // Ex starts at last line of the file. + if (exmode_active) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; + } apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); TIME_MSG("BufEnter autocommands"); setpcmark(); - /* - * When started with "-q errorfile" jump to first error now. - */ + // When started with "-q errorfile" jump to first error now. if (params.edit_type == EDIT_QF) { qf_jump(NULL, 0, 0, FALSE); TIME_MSG("jump to first error"); @@ -505,26 +496,23 @@ int main(int argc, char **argv) xfree(cwd); if (params.diff_mode) { - /* set options in each window for "nvim -d". */ + // set options in each window for "nvim -d". FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { diff_win_options(wp, TRUE); } } - /* - * Shorten any of the filenames, but only when absolute. - */ - shorten_fnames(FALSE); + // Shorten any of the filenames, but only when absolute. + shorten_fnames(false); - /* - * Need to jump to the tag before executing the '-c command'. - * Makes "vim -c '/return' -t main" work. - */ + // Need to jump to the tag before executing the '-c command'. + // Makes "vim -c '/return' -t main" work. handle_tag(params.tagname); - /* Execute any "+", "-c" and "-S" arguments. */ - if (params.n_commands > 0) + // Execute any "+", "-c" and "-S" arguments. + if (params.n_commands > 0) { exe_commands(¶ms); + } starting = 0; @@ -535,9 +523,10 @@ int main(int argc, char **argv) // 'autochdir' has been postponed. do_autochdir(); - /* start in insert mode */ - if (p_im) - need_start_insertmode = TRUE; + // start in insert mode + if (p_im) { + need_start_insertmode = true; + } set_vim_var_nr(VV_VIM_DID_ENTER, 1L); apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf); @@ -553,18 +542,19 @@ int main(int argc, char **argv) // main loop. set_reg_var(get_default_register_name()); - /* When a startup script or session file setup for diff'ing and - * scrollbind, sync the scrollbind now. */ + // When a startup script or session file setup for diff'ing and + // scrollbind, sync the scrollbind now. if (curwin->w_p_diff && curwin->w_p_scb) { update_topline(); check_scrollbind((linenr_T)0, 0L); TIME_MSG("diff scrollbinding"); } - /* If ":startinsert" command used, stuff a dummy command to be able to - * call normal_cmd(), which will then start Insert mode. */ - if (restart_edit != 0) + // If ":startinsert" command used, stuff a dummy command to be able to + // call normal_cmd(), which will then start Insert mode. + if (restart_edit != 0) { stuffcharReadbuff(K_NOP); + } // WORKAROUND(mhi): #3023 if (cb_flags & CB_UNNAMEDMASK) { @@ -574,9 +564,7 @@ int main(int argc, char **argv) TIME_MSG("before starting main loop"); ILOG("starting main loop"); - /* - * Call the main command loop. This never returns. - */ + // Main loop: never returns. normal_enter(false, false); #if defined(WIN32) && !defined(MAKE_LIB) -- cgit From 823b2104c3e579e8c3db8baab263dca0aa9d48bc Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 17 Feb 2020 17:29:12 +0100 Subject: nvim: Correctly setup global channels As gcc10 uses -fno-common by default, global variables declared with the same name more than once is not allowed anymore revealing this issue. We need to define it as extern to access it. See also https://bugzilla.redhat.com/show_bug.cgi?id=1799680 --- src/nvim/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index 56d9030a7f..4a9f2371a2 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -10,6 +10,7 @@ #include #include "nvim/ascii.h" +#include "nvim/channel.h" #include "nvim/vim.h" #include "nvim/main.h" #include "nvim/aucmd.h" -- cgit From e89462d9855eef7718d482df7f92da4279a1c5c3 Mon Sep 17 00:00:00 2001 From: kuuote <36663503+kuuote@users.noreply.github.com> Date: Mon, 25 May 2020 03:45:25 +0900 Subject: vim-patch:8.1.2233: cannot get the Vim command line arguments (#12117) Problem: Cannot get the Vim command line arguments. Solution: Add v:argv. (Dmitri Vereshchagin, closes vim/vim#1322) https://github.com/vim/vim/commit/69bf634858a2a75f2984e42b1e4017bc529a040a --- src/nvim/main.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index 4a9f2371a2..6ac9cdfbae 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -269,6 +269,8 @@ int main(int argc, char **argv) early_init(); + set_argv_var(argv, argc); // set v:argv + // Check if we have an interactive window. check_and_set_isatty(¶ms); -- cgit From 64a2884d4cc78e3bbf1632cfe18d9e60a787a93e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 31 May 2020 15:53:37 -0400 Subject: vim-patch:8.0.1564: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate the +autocmd feature. Takes away 450 #ifdefs and increases code size of tiny Vim by only 40 Kbyte. https://github.com/vim/vim/commit/f2bd8ef2b4507d02c6043affff8f7e85e3414d5f --- src/nvim/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index 6ac9cdfbae..b3a903cbe3 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -621,7 +621,7 @@ void getout(int exitval) /* Optionally print hashtable efficiency. */ hash_debug_results(); - if (get_vim_var_nr(VV_DYING) <= 1) { + if (v_dying <= 1) { const tabpage_T *next_tp; // Trigger BufWinLeave for all windows, but only once per buffer. @@ -670,8 +670,9 @@ void getout(int exitval) shada_write_file(NULL, false); } - if (get_vim_var_nr(VV_DYING) <= 1) - apply_autocmds(EVENT_VIMLEAVE, NULL, NULL, FALSE, curbuf); + if (v_dying <= 1) { + apply_autocmds(EVENT_VIMLEAVE, NULL, NULL, false, curbuf); + } profile_dump(); -- cgit From a5bde56b371e199e36840ceb4a27e0440cbad60d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 7 Jun 2020 13:13:52 -0400 Subject: vim-patch:8.0.1554: custom plugins loaded with --clean Problem: Custom plugins loaded with --clean. Solution: Do not include the home directory in 'runtimepath'. https://github.com/vim/vim/commit/072687032683b1994d25a114893d9a6f8bc36612 --- src/nvim/main.c | 53 ++++++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index b3a903cbe3..8d5b91ec91 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -84,44 +84,11 @@ #endif #include "nvim/api/vim.h" -// Maximum number of commands from + or -c arguments. -#define MAX_ARG_CMDS 10 - // values for "window_layout" #define WIN_HOR 1 // "-o" horizontally split windows #define WIN_VER 2 // "-O" vertically split windows #define WIN_TABS 3 // "-p" windows on tab pages -// Struct for various parameters passed between main() and other functions. -typedef struct { - int argc; - char **argv; - - char *use_vimrc; // vimrc from -u argument - - int n_commands; // no. of commands from + or -c - char *commands[MAX_ARG_CMDS]; // commands from + or -c arg - char_u cmds_tofree[MAX_ARG_CMDS]; // commands that need free() - int n_pre_commands; // no. of commands from --cmd - char *pre_commands[MAX_ARG_CMDS]; // commands from --cmd argument - - int edit_type; // type of editing to do - char_u *tagname; // tag from -t argument - char_u *use_ef; // 'errorfile' from -q argument - - bool input_isatty; // stdin is a terminal - bool output_isatty; // stdout is a terminal - bool err_isatty; // stderr is a terminal - int no_swap_file; // "-n" argument used - int use_debug_break_level; - int window_count; // number of windows to use - int window_layout; // 0, WIN_HOR, WIN_VER or WIN_TABS - - int diff_mode; // start with 'diff' set - - char *listen_addr; // --listen {address} -} mparm_T; - // Values for edit_type. #define EDIT_NONE 0 // no edit type yet #define EDIT_FILE 1 // file name argument[s] given, use argument list @@ -188,7 +155,7 @@ bool event_teardown(void) /// Performs early initialization. /// /// Needed for unit tests. Must be called after `time_init()`. -void early_init(void) +void early_init(mparm_T *paramp) { env_init(); fs_init(); @@ -222,7 +189,7 @@ void early_init(void) // msg_outtrans_len_attr(). // First find out the home directory, needed to expand "~" in options. init_homedir(); // find real value of $HOME - set_init_1(); + set_init_1(paramp != NULL ? paramp->clean : false); log_init(); TIME_MSG("inits 1"); @@ -265,9 +232,17 @@ int main(int argc, char **argv) init_startuptime(¶ms); + // Need to find "--clean" before actually parsing arguments. + for (int i = 1; i < params.argc; i++) { + if (STRICMP(params.argv[i], "--clean") == 0) { + params.clean = true; + break; + } + } + event_init(); - early_init(); + early_init(¶ms); set_argv_var(argv, argc); // set v:argv @@ -862,6 +837,7 @@ static void command_line_scan(mparm_T *parmp) argv_idx += 11; } else if (STRNICMP(argv[0] + argv_idx, "clean", 5) == 0) { parmp->use_vimrc = "NONE"; + parmp->clean = true; set_option_value("shadafile", 0L, "NONE", 0); } else { if (argv[0][argv_idx]) @@ -1277,9 +1253,8 @@ static void init_params(mparm_T *paramp, int argc, char **argv) /// Initialize global startuptime file if "--startuptime" passed as an argument. static void init_startuptime(mparm_T *paramp) { - for (int i = 1; i < paramp->argc; i++) { - if (STRICMP(paramp->argv[i], "--startuptime") == 0 - && i + 1 < paramp->argc) { + for (int i = 1; i < paramp->argc - 1; i++) { + if (STRICMP(paramp->argv[i], "--startuptime") == 0) { time_fd = os_fopen(paramp->argv[i + 1], "a"); time_start("--- NVIM STARTING ---"); break; -- cgit From 1619410a059fd008b3f248ea81aca30036a0fb90 Mon Sep 17 00:00:00 2001 From: erw7 Date: Tue, 23 Jun 2020 06:04:34 +0900 Subject: main.c: fix hang issue with recoverymode (#12496) In the case of recoverymode, the headlessmode was true, causing the UI to hang without starting. Fix this problem by setting headlessmode to true for List swap files only. --- src/nvim/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index 8d5b91ec91..ae64046d07 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -266,6 +266,12 @@ int main(int argc, char **argv) fname = get_fname(¶ms, cwd); } + // Recovery mode without a file name: List swap files. + // In this case, no UI is needed. + if (recoverymode && fname == NULL) { + headless_mode = true; + } + TIME_MSG("expanding arguments"); if (params.diff_mode && params.window_count == -1) @@ -954,7 +960,6 @@ static void command_line_scan(mparm_T *parmp) case 'r': // "-r" recovery mode case 'L': { // "-L" recovery mode recoverymode = 1; - headless_mode = true; break; } case 's': { -- cgit From 8e350c1c6922f9c678e83d97227e7edd84967571 Mon Sep 17 00:00:00 2001 From: erw7 Date: Mon, 20 Jul 2020 00:44:22 +0900 Subject: startup: fix stall issue with -D options (#12652) fixes #12647. --- src/nvim/main.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src/nvim/main.c') diff --git a/src/nvim/main.c b/src/nvim/main.c index ae64046d07..f79fb57eae 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -313,6 +313,26 @@ int main(int argc, char **argv) input_start(STDIN_FILENO); } + // Wait for UIs to set up Nvim or show early messages + // and prompts (--cmd, swapfile dialog, …). + bool use_remote_ui = (embedded_mode && !headless_mode); + bool use_builtin_ui = (!headless_mode && !embedded_mode && !silent_mode); + if (use_remote_ui || use_builtin_ui) { + TIME_MSG("waiting for UI"); + if (use_remote_ui) { + remote_ui_wait_for_attach(); + } else { + ui_builtin_start(); + } + TIME_MSG("done waiting for UI"); + + // prepare screen now, so external UIs can display messages + starting = NO_BUFFERS; + screenclear(); + TIME_MSG("initialized screen early for UI"); + } + + // open terminals when opening files that start with term:// #define PROTO "term://" do_cmdline_cmd("augroup nvim_terminal"); @@ -335,25 +355,6 @@ int main(int argc, char **argv) p_lpl = false; } - // Wait for UIs to set up Nvim or show early messages - // and prompts (--cmd, swapfile dialog, …). - bool use_remote_ui = (embedded_mode && !headless_mode); - bool use_builtin_ui = (!headless_mode && !embedded_mode && !silent_mode); - if (use_remote_ui || use_builtin_ui) { - TIME_MSG("waiting for UI"); - if (use_remote_ui) { - remote_ui_wait_for_attach(); - } else { - ui_builtin_start(); - } - TIME_MSG("done waiting for UI"); - - // prepare screen now, so external UIs can display messages - starting = NO_BUFFERS; - screenclear(); - TIME_MSG("initialized screen early for UI"); - } - // Execute --cmd arguments. exe_pre_commands(¶ms); -- cgit