mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 23:38:17 +00:00
option,main: Partial support of XDG base directory specification
- Add functions that are able to query XDG. - Replace defaults for - &runtimepath. Does not follow #78. - &viewdir. - &undodir. - &directory. - &backupdir. Does not follow #78. - vimrc location. - Remove user vimrc file line from :version message.
This commit is contained in:
@@ -1840,16 +1840,9 @@ static void source_startup_scripts(mparm_T *parmp)
|
|||||||
* - second user exrc file ($VIM/.exrc for Dos)
|
* - second user exrc file ($VIM/.exrc for Dos)
|
||||||
* The first that exists is used, the rest is ignored.
|
* The first that exists is used, the rest is ignored.
|
||||||
*/
|
*/
|
||||||
|
char_u *user_vimrc = (char_u *)get_from_user_conf("init.vim");
|
||||||
if (process_env("VIMINIT", true) != OK) {
|
if (process_env("VIMINIT", true) != OK) {
|
||||||
if (do_source((char_u *)USR_VIMRC_FILE, TRUE, DOSO_VIMRC) == FAIL
|
if (do_source(user_vimrc, true, DOSO_VIMRC) == FAIL
|
||||||
#ifdef USR_VIMRC_FILE2
|
|
||||||
&& do_source((char_u *)USR_VIMRC_FILE2, TRUE,
|
|
||||||
DOSO_VIMRC) == FAIL
|
|
||||||
#endif
|
|
||||||
#ifdef USR_VIMRC_FILE3
|
|
||||||
&& do_source((char_u *)USR_VIMRC_FILE3, TRUE,
|
|
||||||
DOSO_VIMRC) == FAIL
|
|
||||||
#endif
|
|
||||||
&& process_env("EXINIT", FALSE) == FAIL
|
&& process_env("EXINIT", FALSE) == FAIL
|
||||||
&& do_source((char_u *)USR_EXRC_FILE, FALSE, DOSO_NONE) == FAIL) {
|
&& do_source((char_u *)USR_EXRC_FILE, FALSE, DOSO_NONE) == FAIL) {
|
||||||
#ifdef USR_EXRC_FILE2
|
#ifdef USR_EXRC_FILE2
|
||||||
@@ -1875,16 +1868,8 @@ static void source_startup_scripts(mparm_T *parmp)
|
|||||||
secure = p_secure;
|
secure = p_secure;
|
||||||
|
|
||||||
i = FAIL;
|
i = FAIL;
|
||||||
if (path_full_compare((char_u *)USR_VIMRC_FILE,
|
if (path_full_compare(user_vimrc,
|
||||||
(char_u *)VIMRC_FILE, FALSE) != kEqualFiles
|
(char_u *)VIMRC_FILE, false) != kEqualFiles
|
||||||
#ifdef USR_VIMRC_FILE2
|
|
||||||
&& path_full_compare((char_u *)USR_VIMRC_FILE2,
|
|
||||||
(char_u *)VIMRC_FILE, FALSE) != kEqualFiles
|
|
||||||
#endif
|
|
||||||
#ifdef USR_VIMRC_FILE3
|
|
||||||
&& path_full_compare((char_u *)USR_VIMRC_FILE3,
|
|
||||||
(char_u *)VIMRC_FILE, FALSE) != kEqualFiles
|
|
||||||
#endif
|
|
||||||
#ifdef SYS_VIMRC_FILE
|
#ifdef SYS_VIMRC_FILE
|
||||||
&& path_full_compare((char_u *)SYS_VIMRC_FILE,
|
&& path_full_compare((char_u *)SYS_VIMRC_FILE,
|
||||||
(char_u *)VIMRC_FILE, FALSE) != kEqualFiles
|
(char_u *)VIMRC_FILE, FALSE) != kEqualFiles
|
||||||
|
@@ -301,6 +301,15 @@ static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview",
|
|||||||
# include "option.c.generated.h"
|
# include "option.c.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void set_runtimepath_default(void)
|
||||||
|
{
|
||||||
|
garray_T rtp_ga;
|
||||||
|
ga_init(&rtp_ga, (int)sizeof(const char *), 1);
|
||||||
|
GA_APPEND(const char *, &rtp_ga, get_user_conf_dir());
|
||||||
|
GA_APPEND(const char *, &rtp_ga, concat_fnames(get_user_conf_dir(), "after", true));
|
||||||
|
set_string_default("runtimepath", ga_concat_strings(&rtp_ga));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the options, first part.
|
* Initialize the options, first part.
|
||||||
*
|
*
|
||||||
@@ -437,6 +446,12 @@ void set_init_1(void)
|
|||||||
"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
|
"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
set_string_default("viewdir", (char_u *)get_from_user_data("view"));
|
||||||
|
set_string_default("backupdir", (char_u *)get_from_user_data("backup"));
|
||||||
|
set_string_default("directory", (char_u *)get_from_user_data("swap"));
|
||||||
|
set_string_default("undodir", (char_u *)get_from_user_data("undo"));
|
||||||
|
set_runtimepath_default();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set all the options (except the terminal options) to their default
|
* Set all the options (except the terminal options) to their default
|
||||||
* value. Also set the global value for local options.
|
* value. Also set the global value for local options.
|
||||||
|
@@ -176,7 +176,7 @@ return {
|
|||||||
vi_def=true,
|
vi_def=true,
|
||||||
expand=true,
|
expand=true,
|
||||||
varname='p_bdir',
|
varname='p_bdir',
|
||||||
defaults={if_true={vi=macros('DFLT_BDIR')}}
|
defaults={if_true={vi=''}}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
full_name='backupext', abbreviation='bex',
|
full_name='backupext', abbreviation='bex',
|
||||||
@@ -627,7 +627,7 @@ return {
|
|||||||
vi_def=true,
|
vi_def=true,
|
||||||
expand=true,
|
expand=true,
|
||||||
varname='p_dir',
|
varname='p_dir',
|
||||||
defaults={if_true={vi=macros('DFLT_DIR')}}
|
defaults={if_true={vi=''}}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
full_name='display', abbreviation='dy',
|
full_name='display', abbreviation='dy',
|
||||||
@@ -1916,7 +1916,7 @@ return {
|
|||||||
vi_def=true,
|
vi_def=true,
|
||||||
expand=true,
|
expand=true,
|
||||||
varname='p_rtp',
|
varname='p_rtp',
|
||||||
defaults={if_true={vi=macros('DFLT_RUNTIMEPATH')}}
|
defaults={if_true={vi=''}}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
full_name='scroll', abbreviation='scr',
|
full_name='scroll', abbreviation='scr',
|
||||||
@@ -2524,7 +2524,7 @@ return {
|
|||||||
vi_def=true,
|
vi_def=true,
|
||||||
expand=true,
|
expand=true,
|
||||||
varname='p_udir',
|
varname='p_udir',
|
||||||
defaults={if_true={vi="."}}
|
defaults={if_true={vi=''}}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
full_name='undofile', abbreviation='udf',
|
full_name='undofile', abbreviation='udf',
|
||||||
@@ -2585,7 +2585,7 @@ return {
|
|||||||
vi_def=true,
|
vi_def=true,
|
||||||
expand=true,
|
expand=true,
|
||||||
varname='p_vdir',
|
varname='p_vdir',
|
||||||
defaults={if_true={vi=macros('DFLT_VDIR')}}
|
defaults={if_true={vi=''}}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
full_name='viewoptions', abbreviation='vop',
|
full_name='viewoptions', abbreviation='vop',
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
# include "os/mem.h.generated.h"
|
# include "os/mem.h.generated.h"
|
||||||
# include "os/env.h.generated.h"
|
# include "os/env.h.generated.h"
|
||||||
# include "os/users.h.generated.h"
|
# include "os/users.h.generated.h"
|
||||||
|
# include "os/stdpaths.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // NVIM_OS_OS_H
|
#endif // NVIM_OS_OS_H
|
||||||
|
100
src/nvim/os/stdpaths.c
Normal file
100
src/nvim/os/stdpaths.c
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
#include "nvim/os/os.h"
|
||||||
|
#include "nvim/strings.h"
|
||||||
|
#include "nvim/path.h"
|
||||||
|
#include "nvim/garray.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
kXDGConfigHome,
|
||||||
|
kXDGDataHome,
|
||||||
|
kXDGCacheHome,
|
||||||
|
kXDGRuntimeDir,
|
||||||
|
kXDGConfigDirs,
|
||||||
|
kXDGDataDirs,
|
||||||
|
} XDGDirType;
|
||||||
|
|
||||||
|
static const char *xdg_env_vars[] = {
|
||||||
|
[kXDGConfigHome] = "XDG_CONFIG_HOME",
|
||||||
|
[kXDGDataHome] = "XDG_DATA_HOME",
|
||||||
|
[kXDGCacheHome] = "XDG_CACHE_HOME",
|
||||||
|
[kXDGRuntimeDir] = "XDG_RUNTIME_DIR",
|
||||||
|
[kXDGConfigDirs] = "XDG_CONFIG_DIRS",
|
||||||
|
[kXDGDataDirs] = "XDG_DATA_DIRS",
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *const xdg_defaults[] = {
|
||||||
|
// Windows, Apple stuff are just shims right now
|
||||||
|
#ifdef WIN32
|
||||||
|
// Windows
|
||||||
|
#elif APPLE
|
||||||
|
// Apple (this includes iOS, which we might need to handle differently)
|
||||||
|
[kXDGConfigHome] = "~/Library/Preferences",
|
||||||
|
[kXDGDataHome] = "~/Library/Application Support",
|
||||||
|
[kXDGCacheHome] = "~/Library/Caches",
|
||||||
|
[kXDGRuntimeDir] = "~/Library/Application Support",
|
||||||
|
[kXDGConfigDirs] = "/Library/Application Support",
|
||||||
|
[kXDGDataDirs] = "/Library/Application Support",
|
||||||
|
#else
|
||||||
|
// Linux, BSD, CYGWIN
|
||||||
|
[kXDGConfigHome] = "~/.config",
|
||||||
|
[kXDGDataHome] = "~/.local/share",
|
||||||
|
[kXDGCacheHome] = "~/.cache",
|
||||||
|
[kXDGRuntimeDir] = "",
|
||||||
|
[kXDGConfigDirs] = "/etc/xdg/",
|
||||||
|
[kXDGDataDirs] = "/usr/local/share/:/usr/share/",
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const char *get_xdg(XDGDirType idx)
|
||||||
|
{
|
||||||
|
const char *env = xdg_env_vars[idx];
|
||||||
|
const char *fallback = xdg_defaults[idx];
|
||||||
|
|
||||||
|
const char *ret = os_getenv(env);
|
||||||
|
if (!ret && fallback) {
|
||||||
|
ret = (const char *)expand_env_save((char_u *)fallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *get_xdg_home(XDGDirType idx)
|
||||||
|
{
|
||||||
|
const char *dir = get_xdg(idx);
|
||||||
|
if (dir) {
|
||||||
|
dir = (const char *)concat_fnames(dir, "nvim", true);
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void create_dir(const char *dir, int mode, const char *suffix)
|
||||||
|
{
|
||||||
|
char *failed;
|
||||||
|
if (!os_mkdir_recurse(dir, mode, &failed)) {
|
||||||
|
// TODO: Create a folder in $TMPDIR instead
|
||||||
|
DLOG("Create dir failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *get_user_conf_dir(void)
|
||||||
|
{
|
||||||
|
return get_xdg_home(kXDGConfigHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *get_from_user_conf(const char * fname)
|
||||||
|
{
|
||||||
|
return (const char *)concat_fnames(get_user_conf_dir(), fname, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *get_user_data_dir(void)
|
||||||
|
{
|
||||||
|
return get_xdg_home(kXDGDataHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *get_from_user_data(const char * fname)
|
||||||
|
{
|
||||||
|
const char *dir = (const char *)concat_fnames(get_user_data_dir(), fname, true);
|
||||||
|
if (!os_isdir((char_u *)dir)) {
|
||||||
|
create_dir(dir, 0755, fname);
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
@@ -31,12 +31,6 @@
|
|||||||
#ifndef USR_EXRC_FILE
|
#ifndef USR_EXRC_FILE
|
||||||
# define USR_EXRC_FILE "~/.exrc"
|
# define USR_EXRC_FILE "~/.exrc"
|
||||||
#endif
|
#endif
|
||||||
#ifndef USR_VIMRC_FILE
|
|
||||||
# define USR_VIMRC_FILE "~/.nvimrc"
|
|
||||||
#endif
|
|
||||||
#ifndef USR_VIMRC_FILE2
|
|
||||||
# define USR_VIMRC_FILE2 "~/.nvim/nvimrc"
|
|
||||||
#endif
|
|
||||||
#ifndef EXRC_FILE
|
#ifndef EXRC_FILE
|
||||||
# define EXRC_FILE ".exrc"
|
# define EXRC_FILE ".exrc"
|
||||||
#endif
|
#endif
|
||||||
@@ -47,27 +41,4 @@
|
|||||||
# define SHADA_FILE "~/.nvim/shada/main.shada"
|
# define SHADA_FILE "~/.nvim/shada/main.shada"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Default for 'backupdir'.
|
|
||||||
#ifndef DFLT_BDIR
|
|
||||||
# define DFLT_BDIR ".,~/tmp,~/"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Default for 'directory'.
|
|
||||||
#ifndef DFLT_DIR
|
|
||||||
# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Default for 'viewdir'.
|
|
||||||
#ifndef DFLT_VDIR
|
|
||||||
# define DFLT_VDIR "~/.nvim/view"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RUNTIME_GLOBAL
|
|
||||||
# define DFLT_RUNTIMEPATH "~/.nvim," RUNTIME_GLOBAL ",$VIMRUNTIME," \
|
|
||||||
RUNTIME_GLOBAL "/after,~/.nvim/after"
|
|
||||||
#else
|
|
||||||
# define DFLT_RUNTIMEPATH \
|
|
||||||
"~/.nvim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.nvim/after"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // NVIM_OS_UNIX_DEFS_H
|
#endif // NVIM_OS_UNIX_DEFS_H
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
// Defines needed to fix the build on Windows:
|
// Defines needed to fix the build on Windows:
|
||||||
// - USR_EXRC_FILE
|
// - USR_EXRC_FILE
|
||||||
// - USR_VIMRC_FILE
|
|
||||||
// - SHADA_FILE
|
// - SHADA_FILE
|
||||||
// - DFLT_DIR
|
// - DFLT_DIR
|
||||||
// - DFLT_BDIR
|
// - DFLT_BDIR
|
||||||
|
@@ -1067,21 +1067,6 @@ void list_version(void)
|
|||||||
version_msg(SYS_VIMRC_FILE);
|
version_msg(SYS_VIMRC_FILE);
|
||||||
version_msg("\"\n");
|
version_msg("\"\n");
|
||||||
#endif // ifdef SYS_VIMRC_FILE
|
#endif // ifdef SYS_VIMRC_FILE
|
||||||
#ifdef USR_VIMRC_FILE
|
|
||||||
version_msg(_(" user vimrc file: \""));
|
|
||||||
version_msg(USR_VIMRC_FILE);
|
|
||||||
version_msg("\"\n");
|
|
||||||
#endif // ifdef USR_VIMRC_FILE
|
|
||||||
#ifdef USR_VIMRC_FILE2
|
|
||||||
version_msg(_(" 2nd user vimrc file: \""));
|
|
||||||
version_msg(USR_VIMRC_FILE2);
|
|
||||||
version_msg("\"\n");
|
|
||||||
#endif // ifdef USR_VIMRC_FILE2
|
|
||||||
#ifdef USR_VIMRC_FILE3
|
|
||||||
version_msg(_(" 3rd user vimrc file: \""));
|
|
||||||
version_msg(USR_VIMRC_FILE3);
|
|
||||||
version_msg("\"\n");
|
|
||||||
#endif // ifdef USR_VIMRC_FILE3
|
|
||||||
#ifdef USR_EXRC_FILE
|
#ifdef USR_EXRC_FILE
|
||||||
version_msg(_(" user exrc file: \""));
|
version_msg(_(" user exrc file: \""));
|
||||||
version_msg(USR_EXRC_FILE);
|
version_msg(USR_EXRC_FILE);
|
||||||
|
Reference in New Issue
Block a user