Skip to content

Commit

Permalink
option: Use different default value for &runtimepath
Browse files Browse the repository at this point in the history
  • Loading branch information
ZyX-I committed Aug 1, 2015
1 parent 0a09742 commit b4331ac
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 11 deletions.
87 changes: 87 additions & 0 deletions src/nvim/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,89 @@ static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview",
# include "option.c.generated.h"
#endif

/// Set &runtimepath to default value
static void set_runtimepath_default(void)
{
size_t rtp_size = 0;
char *const data_home = vim_getenv("XDG_DATA_HOME");
char *const config_home = vim_getenv("XDG_CONFIG_HOME");
char *const vimruntime = vim_getenv("VIMRUNTIME");
char *const data_dirs = vim_getenv("XDG_DATA_DIRS");
char *const config_dirs = vim_getenv("XDG_CONFIG_DIRS");
assert(data_home != NULL);
assert(config_home != NULL);
assert(vimruntime != NULL);
assert(data_dirs != NULL);
assert(config_dirs != NULL);
#define NVIM_SIZE (sizeof("/nvim") - 1)
#define AFTER_SIZE (sizeof("/after") - 1)
const size_t data_len = strlen(data_home);
const size_t config_len = strlen(config_home);
const size_t vimruntime_len = strlen(vimruntime);
rtp_size += ((data_len + NVIM_SIZE) * 2 + AFTER_SIZE) + 2;
rtp_size += ((config_len + NVIM_SIZE) * 2 + AFTER_SIZE) + 2;
rtp_size += vimruntime_len;
#define COMPUTE_COLON_LEN(rtp_size, val) \
do { \
const void *iter = NULL; \
do { \
size_t dir_len; \
const char *dir; \
iter = vim_colon_env_iter(val, iter, &dir, &dir_len); \
if (dir != NULL && dir_len > 0) { \
rtp_size += ((dir_len + NVIM_SIZE) * 2 + AFTER_SIZE) + 2; \
} \
} while (iter != NULL); \
} while (0)
COMPUTE_COLON_LEN(rtp_size, data_dirs);
COMPUTE_COLON_LEN(rtp_size, config_dirs);
#undef COMPUTE_COLON_LEN
char *const rtp = xmallocz(rtp_size);
char *rtp_cur = rtp;
#define ADD_STRING(tgt, src, len) \
do { memmove(tgt, src, len); tgt += len; } while (0)
#define ADD_STATIC_STRING(tgt, str) \
ADD_STRING(tgt, str, sizeof(str) - 1)
#define ADD_COLON_DIRS(tgt, val, suffix, revsuffix) \
do { \
const void *iter = NULL; \
do { \
size_t dir_len; \
const char *dir; \
iter = vim_colon_env_iter##revsuffix(val, iter, &dir, &dir_len); \
if (dir != NULL && dir_len > 0) { \
ADD_STRING(rtp_cur, dir, dir_len); \
ADD_STATIC_STRING(rtp_cur, "/nvim" suffix ","); \
} \
} while (iter != NULL); \
} while (0)
ADD_STRING(rtp_cur, config_home, config_len);
ADD_STATIC_STRING(rtp_cur, "/nvim,");
ADD_STRING(rtp_cur, data_home, data_len);
ADD_STATIC_STRING(rtp_cur, "/nvim,");
ADD_COLON_DIRS(rtp_cur, config_dirs, "", );
ADD_COLON_DIRS(rtp_cur, data_dirs, "", );
ADD_STRING(rtp_cur, vimruntime, vimruntime_len);
*rtp_cur++ = ',';
ADD_COLON_DIRS(rtp_cur, data_dirs, "/after", _rev);
ADD_COLON_DIRS(rtp_cur, config_dirs, "/after", _rev);
ADD_STRING(rtp_cur, data_home, data_len);
ADD_STATIC_STRING(rtp_cur, "/nvim/after,");
ADD_STRING(rtp_cur, config_home, config_len);
ADD_STATIC_STRING(rtp_cur, "/nvim/after");
#undef ADD_COLON_DIRS
#undef ADD_STATIC_STRING
#undef ADD_STRING
#undef NVIM_SIZE
#undef AFTER_SIZE
set_string_default("runtimepath", (char_u *)rtp);
xfree(data_dirs);
xfree(config_dirs);
xfree(data_home);
xfree(config_home);
xfree(vimruntime);
}

/*
* Initialize the options, first part.
*
Expand Down Expand Up @@ -437,6 +520,10 @@ void set_init_1(void)
"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
);

// Set default for &runtimepath. All necessary expansions are performed in
// this function.
set_runtimepath_default();

/*
* Set all the options (except the terminal options) to their default
* value. Also set the global value for local options.
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,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',
Expand Down
9 changes: 0 additions & 9 deletions src/nvim/os/unix_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,4 @@
# define DFLT_VDIR "$XDG_DATA_HOME/nvim/view/"
#endif

#ifdef RUNTIME_GLOBAL
# define DFLT_RUNTIMEPATH NVIM_CONF_DIR "," RUNTIME_GLOBAL ",$VIMRUNTIME," \
RUNTIME_GLOBAL "/after," NVIM_CONF_DIR "/after"
#else
# define DFLT_RUNTIMEPATH \
NVIM_CONF_DIR ",$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,"\
NVIM_CONF_DIR "/after"
#endif

#endif // NVIM_OS_UNIX_DEFS_H
1 change: 0 additions & 1 deletion src/nvim/os/win_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// - DFLT_DIR
// - DFLT_BDIR
// - DFLT_VDIR
// - DFLT_RUNTIMEPATH
// - EXRC_FILE
// - VIMRC_FILE
// - SYNTAX_FNAME
Expand Down

0 comments on commit b4331ac

Please sign in to comment.