diff options
Diffstat (limited to 'src/option.c')
-rw-r--r-- | src/option.c | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/src/option.c b/src/option.c index 8123a2a..0cd2823 100644 --- a/src/option.c +++ b/src/option.c @@ -364,6 +364,68 @@ set_init_clean_rtp(void) } #endif +#ifdef UNIX +/* + * Change 'runtimepath' and 'packdir' to '$XDG_CONFIG_HOME/vim' if the only + * vimrc found is located in '$XDG_CONFIG_HOME/vim/vimrc'. + * In case the '$XDG_CONFIG_HOME' variable is not set, '$HOME/.config' is used + * as a fallback as is defined in the XDG base dir specification: + * <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html> + */ + static void +set_init_xdg_rtp(void) +{ + int opt_idx; + int has_xdg_env = TRUE; + int should_free_xdg_dir = FALSE; + char_u *vimrc1 = NULL; + char_u *vimrc2 = NULL; + char_u *xdg_dir = NULL; + char_u *xdg_rtp = NULL; + char_u *vimrc_xdg = NULL; + + // initialize chartab, so we can expand $HOME + (void)init_chartab(); + vimrc1 = expand_env_save((char_u *)USR_VIMRC_FILE); + vimrc2 = expand_env_save((char_u *)USR_VIMRC_FILE2); + + xdg_dir = mch_getenv("XDG_CONFIG_HOME"); + if (!xdg_dir) + { + xdg_dir = expand_env_save((char_u *)"~/.config"); + should_free_xdg_dir = TRUE; + has_xdg_env = FALSE; + } + vimrc_xdg = concat_fnames(xdg_dir, (char_u *)"vim/vimrc", TRUE); + + if (file_is_readable(vimrc1) || file_is_readable(vimrc2) || + !file_is_readable(vimrc_xdg)) + goto theend; + + xdg_rtp = has_xdg_env ? (char_u *)XDG_RUNTIMEPATH + : (char_u *)XDG_RUNTIMEPATH_FB; + + if ((opt_idx = findoption((char_u *)"runtimepath")) < 0) + goto theend; + + options[opt_idx].def_val[VI_DEFAULT] = xdg_rtp; + p_rtp = xdg_rtp; + + if ((opt_idx = findoption((char_u *)"packpath")) < 0) + goto theend; + + options[opt_idx].def_val[VI_DEFAULT] = xdg_rtp; + p_pp = xdg_rtp; + +theend: + vim_free(vimrc1); + vim_free(vimrc2); + vim_free(vimrc_xdg); + if (should_free_xdg_dir) + vim_free(xdg_dir); +} +#endif + /* * Expand environment variables and things like "~" for the defaults. * If option_expand() returns non-NULL the variable is expanded. This can @@ -588,6 +650,7 @@ set_init_1(int clean_arg) set_options_default(0); #ifdef UNIX + set_init_xdg_rtp(); set_init_restricted_mode(); #endif @@ -792,7 +855,10 @@ set_string_default_esc(char *name, char_u *val, int escape) opt_idx = findoption((char_u *)name); if (opt_idx < 0) + { + vim_free(p); return; + } if (options[opt_idx].flags & P_DEF_ALLOCED) vim_free(options[opt_idx].def_val[VI_DEFAULT]); @@ -3678,7 +3744,7 @@ did_set_modified(optset_T *args) if (!args->os_newval.boolean) save_file_ff(curbuf); // Buffer is unchanged redraw_titles(); - modified_was_set = args->os_newval.boolean; + curbuf->b_modified_was_set = args->os_newval.boolean; return NULL; } |