aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/runtime.c
diff options
context:
space:
mode:
authorGhjuvan Lacambre <code@lacamb.re>2023-02-16 13:15:02 +0100
committerGitHub <noreply@github.com>2023-02-16 04:15:02 -0800
commitd34c64e342dfba9248d1055e702d02620a1b31a8 (patch)
treea685ef816f1621092ec82ea17d22fbd3a8c03957 /src/nvim/runtime.c
parent631775c05d257e5e61af31d20d9fd5be2dba82c2 (diff)
downloadrneovim-d34c64e342dfba9248d1055e702d02620a1b31a8.tar.gz
rneovim-d34c64e342dfba9248d1055e702d02620a1b31a8.tar.bz2
rneovim-d34c64e342dfba9248d1055e702d02620a1b31a8.zip
feat: $NVIM_APPNAME #22128
This commit implements the ability to control all of the XDG paths Neovim should use. This is done by setting an environment variable named NVIM_APPNAME. For example, setting $NVIM_APPNAME makes Neovim look for its configuration directory in $XDG_CONFIG_HOME/$NVIM_APPNAME instead of $XDG_CONFIG_HOME/nvim. If NVIM_APPNAME is not set or is an empty string, "nvim" will be used as default. The usecase for this feature is to enable an easy way to switch from configuration to configuration. One might argue that the various $XDG environment variables can already be used for this usecase. However, setting $XDG environment variables also affects tools spawned by Neovim. For example, while setting $XDG_CONFIG_HOME will enable Neovim to use a different configuration directory, it will also prevent Git from finding its "default" configuration. Closes https://github.com/neovim/neovim/issues/21691
Diffstat (limited to 'src/nvim/runtime.c')
-rw-r--r--src/nvim/runtime.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 9dc213d718..3487a8d7a2 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -1435,7 +1435,6 @@ static inline size_t compute_double_env_sep_len(const char *const val, const siz
return ret;
}
-#define NVIM_SIZE (sizeof("nvim") - 1)
/// Add directories to a ENV_SEPCHAR-separated array from a colon-separated one
///
/// Commas are escaped in process. To each item PATHSEP "nvim" is appended in
@@ -1464,6 +1463,8 @@ static inline char *add_env_sep_dirs(char *dest, const char *const val, const ch
return dest;
}
const void *iter = NULL;
+ const char *appname = get_appname();
+ const size_t appname_len = strlen(appname);
do {
size_t dir_len;
const char *dir;
@@ -1474,8 +1475,8 @@ static inline char *add_env_sep_dirs(char *dest, const char *const val, const ch
if (!after_pathsep(dest - 1, dest)) {
*dest++ = PATHSEP;
}
- memmove(dest, "nvim", NVIM_SIZE);
- dest += NVIM_SIZE;
+ memmove(dest, appname, appname_len);
+ dest += appname_len;
if (suf1 != NULL) {
*dest++ = PATHSEP;
memmove(dest, suf1, len1);
@@ -1529,14 +1530,18 @@ static inline char *add_dir(char *dest, const char *const dir, const size_t dir_
if (!after_pathsep(dest - 1, dest)) {
*dest++ = PATHSEP;
}
+ const char *appname = get_appname();
+ size_t appname_len = strlen(appname);
+ assert(appname_len < (IOSIZE - sizeof("-data")));
+ xstrlcpy(IObuff, appname, appname_len + 1);
#if defined(MSWIN)
- size_t size = (type == kXDGDataHome ? sizeof("nvim-data") - 1 : NVIM_SIZE);
- memmove(dest, (type == kXDGDataHome ? "nvim-data" : "nvim"), size);
- dest += size;
-#else
- memmove(dest, "nvim", NVIM_SIZE);
- dest += NVIM_SIZE;
+ if (type == kXDGDataHome || type == kXDGStateHome) {
+ STRCAT(IObuff, "-data");
+ appname_len += 5;
+ }
#endif
+ xstrlcpy(dest, IObuff, appname_len + 1);
+ dest += appname_len;
if (suf1 != NULL) {
*dest++ = PATHSEP;
memmove(dest, suf1, len1);
@@ -1596,16 +1601,17 @@ char *runtimepath_default(bool clean_arg)
size_t config_len = 0;
size_t vimruntime_len = 0;
size_t libdir_len = 0;
+ const char *appname = get_appname();
+ size_t appname_len = strlen(appname);
if (data_home != NULL) {
data_len = strlen(data_home);
- if (data_len != 0) {
+ size_t nvim_data_size = appname_len;
#if defined(MSWIN)
- size_t nvim_size = (sizeof("nvim-data") - 1);
-#else
- size_t nvim_size = NVIM_SIZE;
+ nvim_data_size += sizeof("-data");
#endif
+ if (data_len != 0) {
rtp_size += ((data_len + memcnt(data_home, ',', data_len)
- + nvim_size + 1 + SITE_SIZE + 1
+ + nvim_data_size + 1 + SITE_SIZE + 1
+ !after_pathsep(data_home, data_home + data_len)) * 2
+ AFTER_SIZE + 1);
}
@@ -1614,7 +1620,7 @@ char *runtimepath_default(bool clean_arg)
config_len = strlen(config_home);
if (config_len != 0) {
rtp_size += ((config_len + memcnt(config_home, ',', config_len)
- + NVIM_SIZE + 1
+ + appname_len + 1
+ !after_pathsep(config_home, config_home + config_len)) * 2
+ AFTER_SIZE + 1);
}
@@ -1632,9 +1638,9 @@ char *runtimepath_default(bool clean_arg)
}
}
rtp_size += compute_double_env_sep_len(data_dirs,
- NVIM_SIZE + 1 + SITE_SIZE + 1,
+ appname_len + 1 + SITE_SIZE + 1,
AFTER_SIZE + 1);
- rtp_size += compute_double_env_sep_len(config_dirs, NVIM_SIZE + 1,
+ rtp_size += compute_double_env_sep_len(config_dirs, appname_len + 1,
AFTER_SIZE + 1);
char *rtp = NULL;
if (rtp_size == 0) {
@@ -1675,7 +1681,6 @@ freeall:
return rtp;
}
-#undef NVIM_SIZE
static void cmd_source(char *fname, exarg_T *eap)
{