option: Also escape commas in options other then &runtimepath

This commit is contained in:
ZyX
2016-06-26 18:16:23 +03:00
parent 1a92585e32
commit 5fc72882cc
3 changed files with 27 additions and 12 deletions

View File

@@ -677,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();

View File

@@ -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 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;
}

View File

@@ -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;