aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeerthan Jaic <jckeerthan@gmail.com>2015-08-04 21:41:38 -0400
committerZyX <kp-pav@yandex.ru>2015-10-23 14:54:09 +0300
commitc2dd07448ff1b2922e8ea14f909a9cbde481e5fc (patch)
tree747efd028186695c226327a724fdc1fa72ed5dad
parente38cbb93670272d0da15c60222a123b88ec55002 (diff)
downloadrneovim-c2dd07448ff1b2922e8ea14f909a9cbde481e5fc.tar.gz
rneovim-c2dd07448ff1b2922e8ea14f909a9cbde481e5fc.tar.bz2
rneovim-c2dd07448ff1b2922e8ea14f909a9cbde481e5fc.zip
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.
-rw-r--r--src/nvim/main.c23
-rw-r--r--src/nvim/option.c15
-rw-r--r--src/nvim/options.lua10
-rw-r--r--src/nvim/os/os.h1
-rw-r--r--src/nvim/os/stdpaths.c100
-rw-r--r--src/nvim/os/unix_defs.h29
-rw-r--r--src/nvim/os/win_defs.h1
-rw-r--r--src/nvim/version.c15
8 files changed, 125 insertions, 69 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index d865260295..c1a8d3ad75 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1840,16 +1840,9 @@ static void source_startup_scripts(mparm_T *parmp)
* - second user exrc file ($VIM/.exrc for Dos)
* 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 (do_source((char_u *)USR_VIMRC_FILE, 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
+ if (do_source(user_vimrc, true, DOSO_VIMRC) == FAIL
&& process_env("EXINIT", FALSE) == FAIL
&& do_source((char_u *)USR_EXRC_FILE, FALSE, DOSO_NONE) == FAIL) {
#ifdef USR_EXRC_FILE2
@@ -1875,16 +1868,8 @@ static void source_startup_scripts(mparm_T *parmp)
secure = p_secure;
i = FAIL;
- if (path_full_compare((char_u *)USR_VIMRC_FILE,
- (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
+ if (path_full_compare(user_vimrc,
+ (char_u *)VIMRC_FILE, false) != kEqualFiles
#ifdef SYS_VIMRC_FILE
&& path_full_compare((char_u *)SYS_VIMRC_FILE,
(char_u *)VIMRC_FILE, FALSE) != kEqualFiles
diff --git a/src/nvim/option.c b/src/nvim/option.c
index a578f2bb01..c419e58f7e 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -301,6 +301,15 @@ static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview",
# include "option.c.generated.h"
#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.
*
@@ -437,6 +446,12 @@ void set_init_1(void)
"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
* value. Also set the global value for local options.
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 842b0a7c82..633eabab60 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -176,7 +176,7 @@ return {
vi_def=true,
expand=true,
varname='p_bdir',
- defaults={if_true={vi=macros('DFLT_BDIR')}}
+ defaults={if_true={vi=''}}
},
{
full_name='backupext', abbreviation='bex',
@@ -627,7 +627,7 @@ return {
vi_def=true,
expand=true,
varname='p_dir',
- defaults={if_true={vi=macros('DFLT_DIR')}}
+ defaults={if_true={vi=''}}
},
{
full_name='display', abbreviation='dy',
@@ -1916,7 +1916,7 @@ return {
vi_def=true,
expand=true,
varname='p_rtp',
- defaults={if_true={vi=macros('DFLT_RUNTIMEPATH')}}
+ defaults={if_true={vi=''}}
},
{
full_name='scroll', abbreviation='scr',
@@ -2524,7 +2524,7 @@ return {
vi_def=true,
expand=true,
varname='p_udir',
- defaults={if_true={vi="."}}
+ defaults={if_true={vi=''}}
},
{
full_name='undofile', abbreviation='udf',
@@ -2585,7 +2585,7 @@ return {
vi_def=true,
expand=true,
varname='p_vdir',
- defaults={if_true={vi=macros('DFLT_VDIR')}}
+ defaults={if_true={vi=''}}
},
{
full_name='viewoptions', abbreviation='vop',
diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h
index 69bd1ff4fd..198f9ae897 100644
--- a/src/nvim/os/os.h
+++ b/src/nvim/os/os.h
@@ -12,6 +12,7 @@
# include "os/mem.h.generated.h"
# include "os/env.h.generated.h"
# include "os/users.h.generated.h"
+# include "os/stdpaths.h.generated.h"
#endif
#endif // NVIM_OS_OS_H
diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c
new file mode 100644
index 0000000000..230e760d7d
--- /dev/null
+++ b/src/nvim/os/stdpaths.c
@@ -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;
+}
diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h
index 949973bf40..83c6752ff7 100644
--- a/src/nvim/os/unix_defs.h
+++ b/src/nvim/os/unix_defs.h
@@ -31,12 +31,6 @@
#ifndef USR_EXRC_FILE
# define USR_EXRC_FILE "~/.exrc"
#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
# define EXRC_FILE ".exrc"
#endif
@@ -47,27 +41,4 @@
# define SHADA_FILE "~/.nvim/shada/main.shada"
#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
diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h
index b7ec50a109..62889a7d2f 100644
--- a/src/nvim/os/win_defs.h
+++ b/src/nvim/os/win_defs.h
@@ -8,7 +8,6 @@
// Defines needed to fix the build on Windows:
// - USR_EXRC_FILE
-// - USR_VIMRC_FILE
// - SHADA_FILE
// - DFLT_DIR
// - DFLT_BDIR
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 961c017bd5..9cfda96c16 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -1067,21 +1067,6 @@ void list_version(void)
version_msg(SYS_VIMRC_FILE);
version_msg("\"\n");
#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
version_msg(_(" user exrc file: \""));
version_msg(USR_EXRC_FILE);