aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-06-07 13:13:52 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-06-18 18:01:41 -0400
commita5bde56b371e199e36840ceb4a27e0440cbad60d (patch)
treed1f2b6775c30e53fba69a6c493706b0708529168
parent70d4b31b834395fe36f4886e43b63fd4dc62ded1 (diff)
downloadrneovim-a5bde56b371e199e36840ceb4a27e0440cbad60d.tar.gz
rneovim-a5bde56b371e199e36840ceb4a27e0440cbad60d.tar.bz2
rneovim-a5bde56b371e199e36840ceb4a27e0440cbad60d.zip
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
-rw-r--r--runtime/doc/starting.txt1
-rw-r--r--src/nvim/main.c53
-rw-r--r--src/nvim/main.h34
-rw-r--r--src/nvim/option.c17
-rw-r--r--test/functional/core/startup_spec.lua9
-rw-r--r--test/unit/helpers.lua2
6 files changed, 71 insertions, 45 deletions
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
index af7d233619..0ded6a9060 100644
--- a/runtime/doc/starting.txt
+++ b/runtime/doc/starting.txt
@@ -90,6 +90,7 @@ argument.
--clean Equivalent to "-u NONE -i NONE":
- Skips initializations from files and environment variables.
- No 'shada' file is read or written.
+ - Excludes user directories from 'runtimepath'
*--noplugin*
--noplugin Skip loading plugins. Resets the 'loadplugins' option.
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(&params);
+ // 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(&params);
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;
diff --git a/src/nvim/main.h b/src/nvim/main.h
index 86d25fe657..61252f2bce 100644
--- a/src/nvim/main.h
+++ b/src/nvim/main.h
@@ -4,8 +4,42 @@
#include "nvim/normal.h"
#include "nvim/event/loop.h"
+// Maximum number of commands from + or -c arguments.
+#define MAX_ARG_CMDS 10
+
extern Loop main_loop;
+// Struct for various parameters passed between main() and other functions.
+typedef struct {
+ int argc;
+ char **argv;
+
+ char *use_vimrc; // vimrc from -u argument
+ bool clean; // --clean 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;
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "main.h.generated.h"
#endif
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 96f8e1529a..55ae0b7003 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -524,11 +524,17 @@ char *get_lib_dir(void)
///
/// Windows: Uses "…/nvim-data" for kXDGDataHome to avoid storing
/// configuration and data files in the same path. #4403
-static void set_runtimepath_default(void)
+///
+/// If "clean_arg" is true, Nvim was started with --clean.
+static void set_runtimepath_default(bool clean_arg)
{
size_t rtp_size = 0;
- char *const data_home = stdpaths_get_xdg_var(kXDGDataHome);
- char *const config_home = stdpaths_get_xdg_var(kXDGConfigHome);
+ char *const data_home = clean_arg
+ ? NULL
+ : stdpaths_get_xdg_var(kXDGDataHome);
+ char *const config_home = clean_arg
+ ? NULL
+ : stdpaths_get_xdg_var(kXDGConfigHome);
char *const vimruntime = vim_getenv("VIMRUNTIME");
char *const libdir = get_lib_dir();
char *const data_dirs = stdpaths_get_xdg_var(kXDGDataDirs);
@@ -622,7 +628,8 @@ static void set_runtimepath_default(void)
/// Initialize the options, first part.
///
/// Called only once from main(), just after creating the first buffer.
-void set_init_1(void)
+/// If "clean_arg" is true, Nvim was started with --clean.
+void set_init_1(bool clean_arg)
{
int opt_idx;
@@ -765,7 +772,7 @@ void set_init_1(void)
true);
// Set default for &runtimepath. All necessary expansions are performed in
// this function.
- set_runtimepath_default();
+ set_runtimepath_default(clean_arg);
/*
* Set all the options (except the terminal options) to their default
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
index 3269fbc68d..394eb73187 100644
--- a/test/functional/core/startup_spec.lua
+++ b/test/functional/core/startup_spec.lua
@@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local command = helpers.command
+local ok = helpers.ok
local eq = helpers.eq
local matches = helpers.matches
local eval = helpers.eval
@@ -17,6 +18,7 @@ local rmdir = helpers.rmdir
local sleep = helpers.sleep
local iswin = helpers.iswin
local write_file = helpers.write_file
+local meths = helpers.meths
describe('startup', function()
before_each(function()
@@ -357,3 +359,10 @@ describe('sysinit', function()
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))'))
end)
end)
+
+describe('clean', function()
+ clear()
+ ok(string.match(meths.get_option('runtimepath'), funcs.stdpath('config')) ~= nil)
+ clear('--clean')
+ ok(string.match(meths.get_option('runtimepath'), funcs.stdpath('config')) == nil)
+end)
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index a77a089763..465b553693 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -96,8 +96,8 @@ local init = only_separate(function()
c.func(unpack(c.args))
end
libnvim.time_init()
- libnvim.early_init()
libnvim.event_init()
+ libnvim.early_init(nil)
if child_calls_mod then
for _, c in ipairs(child_calls_mod) do
c.func(unpack(c.args))