diff options
author | Munif Tanjim <hello@muniftanjim.dev> | 2022-12-19 22:33:47 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-19 09:33:47 -0700 |
commit | 23d8f5b870ab2a12882ba20e32d24b31c137f6a9 (patch) | |
tree | 1b750709ab3b152f23044ad967893ba6e8d7081d /src | |
parent | f4d8e992bfcd6e9d0097b9d7a022060bd32f2069 (diff) | |
download | rneovim-23d8f5b870ab2a12882ba20e32d24b31c137f6a9.tar.gz rneovim-23d8f5b870ab2a12882ba20e32d24b31c137f6a9.tar.bz2 rneovim-23d8f5b870ab2a12882ba20e32d24b31c137f6a9.zip |
feat(exrc): support .nvim.lua (#21436)
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/globals.h | 4 | ||||
-rw-r--r-- | src/nvim/main.c | 51 |
2 files changed, 40 insertions, 15 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 0169b62188..bce81b376b 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -75,6 +75,10 @@ # define VIMRC_FILE ".nvimrc" #endif +#ifndef VIMRC_LUA_FILE +# define VIMRC_LUA_FILE ".nvim.lua" +#endif + EXTERN struct nvim_stats_s { int64_t fsync; int64_t redraw; diff --git a/src/nvim/main.c b/src/nvim/main.c index 29d50801bb..a7f07af1a8 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1987,6 +1987,41 @@ static bool do_user_initialization(void) return do_exrc; } +// Read initialization commands from ".nvim.lua", ".nvimrc", or ".exrc" in +// current directory. This is only done if the 'exrc' option is set. +// Only do this if VIMRC_FILE is not the same as vimrc file sourced in +// do_user_initialization. +static void do_exrc_initialization(void) +{ + char *str; + + if (os_path_exists(VIMRC_LUA_FILE)) { + str = nlua_read_secure(VIMRC_LUA_FILE); + if (str != NULL) { + Error err = ERROR_INIT; + nlua_exec(cstr_as_string(str), (Array)ARRAY_DICT_INIT, &err); + xfree(str); + if (ERROR_SET(&err)) { + semsg("Error detected while processing %s:", VIMRC_LUA_FILE); + semsg_multiline(err.msg); + api_clear_error(&err); + } + } + } else if (os_path_exists(VIMRC_FILE)) { + str = nlua_read_secure(VIMRC_FILE); + if (str != NULL) { + do_source_str(str, VIMRC_FILE); + xfree(str); + } + } else if (os_path_exists(EXRC_FILE)) { + str = nlua_read_secure(EXRC_FILE); + if (str != NULL) { + do_source_str(str, EXRC_FILE); + xfree(str); + } + } +} + /// Source startup scripts static void source_startup_scripts(const mparm_T *const parmp) FUNC_ATTR_NONNULL_ALL @@ -2005,21 +2040,7 @@ static void source_startup_scripts(const mparm_T *const parmp) do_system_initialization(); if (do_user_initialization()) { - // Read initialization commands from ".nvimrc" or ".exrc" in current - // directory. This is only done if the 'exrc' option is set. - // Only do this if VIMRC_FILE is not the same as vimrc file sourced in - // do_user_initialization. - char *str = nlua_read_secure(VIMRC_FILE); - if (str != NULL) { - do_source_str(str, VIMRC_FILE); - xfree(str); - } else { - str = nlua_read_secure(EXRC_FILE); - if (str != NULL) { - do_source_str(str, EXRC_FILE); - xfree(str); - } - } + do_exrc_initialization(); } } TIME_MSG("sourcing vimrc file(s)"); |