aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/option.c42
-rw-r--r--src/nvim/option.h23
-rw-r--r--src/nvim/options.lua10
-rw-r--r--src/nvim/os/stdpaths.c26
-rw-r--r--src/nvim/shada.c2
5 files changed, 64 insertions, 39 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index de53b0b1f4..6baf8c65ce 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -236,6 +236,7 @@ typedef struct vimoption {
#define P_NO_ML 0x2000000U ///< not allowed in modeline
#define P_CURSWANT 0x4000000U ///< update curswant required; not needed
///< when there is a redraw flag
+#define P_NO_DEF_EXP 0x8000000U ///< Do not expand default value.
#define HIGHLIGHT_INIT \
"8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \
@@ -676,15 +677,18 @@ void set_init_1(void)
#endif
false);
- char *backupdir = stdpaths_user_data_subpath("backup", 0);
+ char *backupdir = stdpaths_user_data_subpath("backup", 0, true);
const size_t backupdir_len = strlen(backupdir);
backupdir = xrealloc(backupdir, backupdir_len + 3);
memmove(backupdir + 2, backupdir, backupdir_len + 1);
memmove(backupdir, ".,", 2);
- set_string_default("viewdir", stdpaths_user_data_subpath("view", 0), true);
+ set_string_default("viewdir", stdpaths_user_data_subpath("view", 0, true),
+ true);
set_string_default("backupdir", backupdir, true);
- set_string_default("directory", stdpaths_user_data_subpath("swap", 2), true);
- set_string_default("undodir", stdpaths_user_data_subpath("undo", 0), true);
+ set_string_default("directory", stdpaths_user_data_subpath("swap", 2, true),
+ true);
+ set_string_default("undodir", stdpaths_user_data_subpath("undo", 0, true),
+ true);
// Set default for &runtimepath. All necessary expansions are performed in
// this function.
set_runtimepath_default();
@@ -726,6 +730,9 @@ void set_init_1(void)
* default.
*/
for (opt_idx = 0; options[opt_idx].fullname; opt_idx++) {
+ if (options[opt_idx].flags & P_NO_DEF_EXP) {
+ continue;
+ }
char *p;
if ((options[opt_idx].flags & P_GETTEXT)
&& options[opt_idx].var != NULL) {
@@ -1473,16 +1480,19 @@ do_set (
* default value was already expanded, only
* required when an environment variable was set
* later */
- if (newval == NULL)
+ new_value_alloced = true;
+ if (newval == NULL) {
newval = empty_option;
- else {
+ } else if (!(options[opt_idx].flags | P_NO_DEF_EXP)) {
s = option_expand(opt_idx, newval);
- if (s == NULL)
+ if (s == NULL) {
s = newval;
+ }
newval = vim_strsave(s);
+ } else {
+ newval = (char_u *)xstrdup((char *)newval);
}
- new_value_alloced = TRUE;
- } else if (nextchar == '<') { /* set to global val */
+ } else if (nextchar == '<') { // set to global val
newval = vim_strsave(*(char_u **)get_varp_scope(
&(options[opt_idx]), OPT_GLOBAL));
new_value_alloced = TRUE;
@@ -2020,13 +2030,15 @@ static char_u *option_expand(int opt_idx, char_u *val)
if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
return NULL;
- /* If val is longer than MAXPATHL no meaningful expansion can be done,
- * expand_env() would truncate the string. */
- if (val != NULL && STRLEN(val) > MAXPATHL)
- return NULL;
-
- if (val == NULL)
+ if (val == NULL) {
val = *(char_u **)options[opt_idx].var;
+ }
+
+ // If val is longer than MAXPATHL no meaningful expansion can be done,
+ // expand_env() would truncate the string.
+ if (val == NULL || STRLEN(val) > MAXPATHL) {
+ return NULL;
+ }
/*
* Expanding this with NameBuff, expand_env() must not be passed IObuff.
diff --git a/src/nvim/option.h b/src/nvim/option.h
index 5c2b2662b5..3a43b859a8 100644
--- a/src/nvim/option.h
+++ b/src/nvim/option.h
@@ -6,17 +6,18 @@
#define BCO_ALWAYS 2 /* always copy the options */
#define BCO_NOHELP 4 /* don't touch the help related options */
-/*
- * "flags" values for option-setting functions.
- * When OPT_GLOBAL and OPT_LOCAL are both missing, set both local and global
- * values, get local value.
- */
-#define OPT_FREE 1 /* free old value if it was allocated */
-#define OPT_GLOBAL 2 /* use global value */
-#define OPT_LOCAL 4 /* use local value */
-#define OPT_MODELINE 8 /* option in modeline */
-#define OPT_WINONLY 16 /* only set window-local options */
-#define OPT_NOWIN 32 /* don't set window-local options */
+/// Flags for option-setting functions
+///
+/// When OPT_GLOBAL and OPT_LOCAL are both missing, set both local and global
+/// values, get local value.
+typedef enum {
+ OPT_FREE = 1, ///< Free old value if it was allocated.
+ OPT_GLOBAL = 2, ///< Use global value.
+ OPT_LOCAL = 4, ///< Use local value.
+ OPT_MODELINE = 8, ///< Option in modeline.
+ OPT_WINONLY = 16, ///< Only set window-local options.
+ OPT_NOWIN = 32, ///< Don’t set window-local options.
+} OptionFlags;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "option.h.generated.h"
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index d19af4f73f..060ec8c1e1 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -165,7 +165,7 @@ return {
deny_duplicates=true,
secure=true,
vi_def=true,
- expand=true,
+ expand='nodefault',
varname='p_bdir',
defaults={if_true={vi=''}}
},
@@ -616,7 +616,7 @@ return {
deny_duplicates=true,
secure=true,
vi_def=true,
- expand=true,
+ expand='nodefault',
varname='p_dir',
defaults={if_true={vi=''}}
},
@@ -1891,7 +1891,7 @@ return {
deny_duplicates=true,
secure=true,
vi_def=true,
- expand=true,
+ expand='nodefault',
varname='p_rtp',
defaults={if_true={vi=''}}
},
@@ -2507,7 +2507,7 @@ return {
deny_duplicates=true,
secure=true,
vi_def=true,
- expand=true,
+ expand='nodefault',
varname='p_udir',
defaults={if_true={vi=''}}
},
@@ -2568,7 +2568,7 @@ return {
type='string', scope={'global'},
secure=true,
vi_def=true,
- expand=true,
+ expand='nodefault',
varname='p_vdir',
defaults={if_true={vi=''}}
},
diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c
index 81ceb919c4..10b3f4c091 100644
--- a/src/nvim/os/stdpaths.c
+++ b/src/nvim/os/stdpaths.c
@@ -100,18 +100,30 @@ char *stdpaths_user_conf_subpath(const char *fname)
///
/// @param[in] fname New component of the path.
/// @param[in] trailing_pathseps Amount of trailing path separators to add.
+/// @param[in] escape_commas If true, all commas will be escaped.
///
-/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}`
+/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}`.
char *stdpaths_user_data_subpath(const char *fname,
- const size_t trailing_pathseps)
+ const size_t trailing_pathseps,
+ const bool escape_commas)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{
char *ret = concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true);
- if (trailing_pathseps) {
- const size_t len = strlen(ret);
- ret = xrealloc(ret, len + trailing_pathseps + 1);
- memset(ret + len, PATHSEP, trailing_pathseps);
- ret[len + trailing_pathseps] = NUL;
+ const size_t len = strlen(ret);
+ const size_t numcommas = (escape_commas ? memcnt(ret, ',', len) : 0);
+ if (numcommas || trailing_pathseps) {
+ ret = xrealloc(ret, len + trailing_pathseps + numcommas + 1);
+ for (size_t i = 0 ; i < len + numcommas ; i++) {
+ if (ret[i] == ',') {
+ memmove(ret + i + 1, ret + i, len - i + numcommas);
+ ret[i] = '\\';
+ i++;
+ }
+ }
+ if (trailing_pathseps) {
+ memset(ret + len + numcommas, PATHSEP, trailing_pathseps);
+ }
+ ret[len + trailing_pathseps + numcommas] = NUL;
}
return ret;
}
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index b5921eb810..fe62f06e59 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -1524,7 +1524,7 @@ static const char *shada_get_default_file(void)
FUNC_ATTR_WARN_UNUSED_RESULT
{
if (default_shada_file == NULL) {
- char *shada_dir = stdpaths_user_data_subpath("shada", 0);
+ char *shada_dir = stdpaths_user_data_subpath("shada", 0, false);
default_shada_file = concat_fnames_realloc(shada_dir, "main.shada", true);
}
return default_shada_file;