aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/option.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r--src/nvim/option.c452
1 files changed, 398 insertions, 54 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index a578f2bb01..486f2083a6 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* Code to handle user-settable options. This is all pretty much table-
* driven. Checklist for adding a new option:
* - Put it in the options array below (copy an existing entry).
@@ -30,7 +22,6 @@
#define IN_OPTION_C
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
@@ -131,6 +122,7 @@ static char_u *p_cpt;
static char_u *p_cfu;
static char_u *p_ofu;
static int p_eol;
+static int p_fixeol;
static int p_et;
static char_u *p_fenc;
static char_u *p_ff;
@@ -301,6 +293,243 @@ static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview",
# include "option.c.generated.h"
#endif
+/// Append string with escaped commas
+static char *strcpy_comma_escaped(char *dest, const char *src, const size_t len)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
+{
+ size_t shift = 0;
+ for (size_t i = 0; i < len; i++) {
+ if (src[i] == ',') {
+ dest[i + shift++] = '\\';
+ }
+ dest[i + shift] = src[i];
+ }
+ return &dest[len + shift];
+}
+
+/// Compute length of a colon-separated value, doubled and with some suffixes
+///
+/// @param[in] val Colon-separated array value.
+/// @param[in] common_suf_len Length of the common suffix which is appended to
+/// each item in the array, twice.
+/// @param[in] single_suf_len Length of the suffix which is appended to each
+/// item in the array once.
+///
+/// @return Length of the comma-separated string array that contains each item
+/// in the original array twice with suffixes with given length
+/// (common_suf is present after each new item, single_suf is present
+/// after half of the new items) and with commas after each item, commas
+/// inside the values are escaped.
+static inline size_t compute_double_colon_len(const char *const val,
+ const size_t common_suf_len,
+ const size_t single_suf_len)
+ FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
+{
+ if (val == NULL || *val == NUL) {
+ return 0;
+ }
+ size_t ret = 0;
+ 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) {
+ ret += ((dir_len + memcnt(dir, ',', dir_len) + common_suf_len
+ + !after_pathsep(dir, dir + dir_len)) * 2
+ + single_suf_len);
+ }
+ } while (iter != NULL);
+ return ret;
+}
+
+#define NVIM_SIZE (sizeof("nvim") - 1)
+
+/// Add directories to a comma-separated array from a colon-separated one
+///
+/// Commas are escaped in process. To each item PATHSEP "nvim" is appended in
+/// addition to suf1 and suf2.
+///
+/// @param[in,out] dest Destination comma-separated array.
+/// @param[in] val Source colon-separated array.
+/// @param[in] suf1 If not NULL, suffix appended to destination. Prior to it
+/// directory separator is appended. Suffix must not contain
+/// commas.
+/// @param[in] len1 Length of the suf1.
+/// @param[in] suf2 If not NULL, another suffix appended to destination. Again
+/// with directory separator behind. Suffix must not contain
+/// commas.
+/// @param[in] len2 Length of the suf2.
+/// @param[in] forward If true, iterate over val in forward direction.
+/// Otherwise in reverse.
+///
+/// @return (dest + appended_characters_length)
+static inline char *add_colon_dirs(char *dest, const char *const val,
+ const char *const suf1, const size_t len1,
+ const char *const suf2, const size_t len2,
+ const bool forward)
+ FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1)
+{
+ if (val == NULL || *val == NUL) {
+ return dest;
+ }
+ const void *iter = NULL;
+ do {
+ size_t dir_len;
+ const char *dir;
+ iter = (forward ? vim_colon_env_iter : vim_colon_env_iter_rev)(
+ val, iter, &dir, &dir_len);
+ if (dir != NULL && dir_len > 0) {
+ dest = strcpy_comma_escaped(dest, dir, dir_len);
+ if (!after_pathsep(dest - 1, dest)) {
+ *dest++ = PATHSEP;
+ }
+ memmove(dest, "nvim", NVIM_SIZE);
+ dest += NVIM_SIZE;
+ if (suf1 != NULL) {
+ *dest++ = PATHSEP;
+ memmove(dest, suf1, len1);
+ dest += len1;
+ if (suf2 != NULL) {
+ *dest++ = PATHSEP;
+ memmove(dest, suf2, len2);
+ dest += len2;
+ }
+ }
+ *dest++ = ',';
+ }
+ } while (iter != NULL);
+ return dest;
+}
+
+/// Add directory to a comma-separated list of directories
+///
+/// In the added directory comma is escaped.
+///
+/// @param[in,out] dest Destination comma-separated array.
+/// @param[in] dir Directory to append.
+/// @param[in] append_nvim If true, append "nvim" as the very first suffix.
+/// @param[in] suf1 If not NULL, suffix appended to destination. Prior to it
+/// directory separator is appended. Suffix must not contain
+/// commas.
+/// @param[in] len1 Length of the suf1.
+/// @param[in] suf2 If not NULL, another suffix appended to destination. Again
+/// with directory separator behind. Suffix must not contain
+/// commas.
+/// @param[in] len2 Length of the suf2.
+/// @param[in] forward If true, iterate over val in forward direction.
+/// Otherwise in reverse.
+///
+/// @return (dest + appended_characters_length)
+static inline char *add_dir(char *dest, const char *const dir,
+ const size_t dir_len, const bool append_nvim,
+ const char *const suf1, const size_t len1,
+ const char *const suf2, const size_t len2)
+ FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
+{
+ if (dir == NULL || dir_len == 0) {
+ return dest;
+ }
+ dest = strcpy_comma_escaped(dest, dir, dir_len);
+ if (append_nvim) {
+ if (!after_pathsep(dest - 1, dest)) {
+ *dest++ = PATHSEP;
+ }
+ memmove(dest, "nvim", NVIM_SIZE);
+ dest += NVIM_SIZE;
+ if (suf1 != NULL) {
+ *dest++ = PATHSEP;
+ memmove(dest, suf1, len1);
+ dest += len1;
+ if (suf2 != NULL) {
+ *dest++ = PATHSEP;
+ memmove(dest, suf2, len2);
+ dest += len2;
+ }
+ }
+ }
+ *dest++ = ',';
+ return dest;
+}
+
+/// Set &runtimepath to default value
+static void set_runtimepath_default(void)
+{
+ size_t rtp_size = 0;
+ char *const data_home = stdpaths_get_xdg_var(kXDGDataHome);
+ char *const config_home = stdpaths_get_xdg_var(kXDGConfigHome);
+ char *const vimruntime = vim_getenv("VIMRUNTIME");
+ char *const data_dirs = stdpaths_get_xdg_var(kXDGDataDirs);
+ char *const config_dirs = stdpaths_get_xdg_var(kXDGConfigDirs);
+#define SITE_SIZE (sizeof("site") - 1)
+#define AFTER_SIZE (sizeof("after") - 1)
+ size_t data_len = 0;
+ size_t config_len = 0;
+ size_t vimruntime_len = 0;
+ if (data_home != NULL) {
+ data_len = strlen(data_home);
+ if (data_len != 0) {
+ rtp_size += ((data_len + memcnt(data_home, ',', data_len)
+ + NVIM_SIZE + 1 + SITE_SIZE + 1
+ + !after_pathsep(data_home, data_home + data_len)) * 2
+ + AFTER_SIZE + 1);
+ }
+ }
+ if (config_home != NULL) {
+ config_len = strlen(config_home);
+ if (config_len != 0) {
+ rtp_size += ((config_len + memcnt(config_home, ',', config_len)
+ + NVIM_SIZE + 1
+ + !after_pathsep(config_home, config_home + config_len)) * 2
+ + AFTER_SIZE + 1);
+ }
+ }
+ if (vimruntime != NULL) {
+ vimruntime_len = strlen(vimruntime);
+ if (vimruntime_len != 0) {
+ rtp_size += vimruntime_len + memcnt(vimruntime, ',', vimruntime_len) + 1;
+ }
+ }
+ rtp_size += compute_double_colon_len(data_dirs, NVIM_SIZE + 1 + SITE_SIZE + 1,
+ AFTER_SIZE + 1);
+ rtp_size += compute_double_colon_len(config_dirs, NVIM_SIZE + 1,
+ AFTER_SIZE + 1);
+ if (rtp_size == 0) {
+ return;
+ }
+ char *const rtp = xmalloc(rtp_size);
+ char *rtp_cur = rtp;
+ rtp_cur = add_dir(rtp_cur, config_home, config_len, true, NULL, 0, NULL, 0);
+ rtp_cur = add_colon_dirs(rtp_cur, config_dirs, NULL, 0, NULL, 0, true);
+ rtp_cur = add_dir(rtp_cur, data_home, data_len, true, "site", SITE_SIZE,
+ NULL, 0);
+ rtp_cur = add_colon_dirs(rtp_cur, data_dirs, "site", SITE_SIZE, NULL, 0,
+ true);
+ rtp_cur = add_dir(rtp_cur, vimruntime, vimruntime_len, false, NULL, 0,
+ NULL, 0);
+ rtp_cur = add_colon_dirs(rtp_cur, data_dirs, "site", SITE_SIZE,
+ "after", AFTER_SIZE, false);
+ rtp_cur = add_dir(rtp_cur, data_home, data_len, true, "site", SITE_SIZE,
+ "after", AFTER_SIZE);
+ rtp_cur = add_colon_dirs(rtp_cur, config_dirs, "after", AFTER_SIZE, NULL, 0,
+ false);
+ rtp_cur = add_dir(rtp_cur, config_home, config_len, true,
+ "after", AFTER_SIZE, NULL, 0);
+ // Strip trailing comma.
+ rtp_cur[-1] = NUL;
+ assert((size_t) (rtp_cur - rtp) == rtp_size);
+#undef SITE_SIZE
+#undef AFTER_SIZE
+ set_string_default("runtimepath", rtp, true);
+ xfree(data_dirs);
+ xfree(config_dirs);
+ xfree(data_home);
+ xfree(config_home);
+ xfree(vimruntime);
+}
+
+#undef NVIM_SIZE
+
/*
* Initialize the options, first part.
*
@@ -308,7 +537,6 @@ static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview",
*/
void set_init_1(void)
{
- char_u *p;
int opt_idx;
langmap_init();
@@ -320,8 +548,12 @@ void set_init_1(void)
* Find default value for 'shell' option.
* Don't use it if it is empty.
*/
- if ((p = (char_u *)os_getenv("SHELL")) != NULL)
- set_string_default("sh", p);
+ {
+ const char *shell = os_getenv("SHELL");
+ if (shell != NULL) {
+ set_string_default("sh", (char *) shell, false);
+ }
+ }
/*
* Set the default for 'backupskip' to include environment variables for
@@ -339,17 +571,18 @@ void set_init_1(void)
ga_init(&ga, 1, 100);
for (size_t n = 0; n < ARRAY_SIZE(names); ++n) {
bool mustfree = true;
+ char *p;
# ifdef UNIX
if (*names[n] == NUL) {
- p = (char_u *)"/tmp";
+ p = "/tmp";
mustfree = false;
}
else
# endif
- p = (char_u *)vim_getenv(names[n]);
+ p = vim_getenv(names[n]);
if (p != NULL && *p != NUL) {
// First time count the NUL, otherwise count the ','.
- len = (int)STRLEN(p) + 3;
+ len = (int)strlen(p) + 3;
ga_grow(&ga, len);
if (!GA_EMPTY(&ga))
STRCAT(ga.ga_data, ",");
@@ -363,8 +596,7 @@ void set_init_1(void)
}
}
if (ga.ga_data != NULL) {
- set_string_default("bsk", ga.ga_data);
- xfree(ga.ga_data);
+ set_string_default("bsk", ga.ga_data, true);
}
}
@@ -425,17 +657,38 @@ void set_init_1(void)
#if defined(MSWIN) || defined(MAC)
/* Set print encoding on platforms that don't default to latin1 */
- set_string_default("penc",
- (char_u *)"hp-roman8"
- );
+ set_string_default("printencoding", "hp-roman8", false);
#endif
- /* 'printexpr' must be allocated to be able to evaluate it. */
- set_string_default(
- "pexpr",
- (char_u *)
- "system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
- );
+ // 'printexpr' must be allocated to be able to evaluate it.
+ set_string_default("printexpr",
+#ifdef UNIX
+ "system(['lpr'] "
+ "+ (empty(&printdevice)?[]:['-P', &printdevice]) "
+ "+ [v:fname_in])"
+ ". delete(v:fname_in)"
+ "+ v:shell_error",
+#elif defined(MSWIN)
+ "system(['copy', v:fname_in, "
+ "empty(&printdevice)?'LPT1':&printdevice])"
+ ". delete(v:fname_in)",
+#else
+ "",
+#endif
+ false);
+
+ char *backupdir = stdpaths_user_data_subpath("backup", 0);
+ 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("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 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
@@ -478,14 +731,16 @@ void set_init_1(void)
* default.
*/
for (opt_idx = 0; options[opt_idx].fullname; opt_idx++) {
+ char *p;
if ((options[opt_idx].flags & P_GETTEXT)
- && options[opt_idx].var != NULL)
- p = (char_u *)_(*(char **)options[opt_idx].var);
- else
- p = option_expand(opt_idx, NULL);
+ && options[opt_idx].var != NULL) {
+ p = _(*(char **)options[opt_idx].var);
+ } else {
+ p = (char *) option_expand(opt_idx, NULL);
+ }
if (p != NULL) {
- p = vim_strsave(p);
- *(char_u **)options[opt_idx].var = p;
+ p = xstrdup(p);
+ *(char **)options[opt_idx].var = p;
/* VIMEXP
* Defaults for all expanded options are currently the same for Vi
* and Vim. When this changes, add some code here! Also need to
@@ -493,7 +748,7 @@ void set_init_1(void)
*/
if (options[opt_idx].flags & P_DEF_ALLOCED)
xfree(options[opt_idx].def_val[VI_DEFAULT]);
- options[opt_idx].def_val[VI_DEFAULT] = p;
+ options[opt_idx].def_val[VI_DEFAULT] = (char_u *) p;
options[opt_idx].flags |= P_DEF_ALLOCED;
}
}
@@ -522,14 +777,14 @@ void set_init_1(void)
(void)set_chars_option(&p_lcs);
/* enc_locale() will try to find the encoding of the current locale. */
- p = enc_locale();
+ char_u *p = enc_locale();
if (p != NULL) {
char_u *save_enc;
/* Try setting 'encoding' and check if the value is valid.
* If not, go back to the default "utf-8". */
save_enc = p_enc;
- p_enc = p;
+ p_enc = (char_u *) p;
if (STRCMP(p_enc, "gb18030") == 0) {
/* We don't support "gb18030", but "cp936" is a good substitute
* for practical purposes, thus use that. It's not an alias to
@@ -674,7 +929,9 @@ set_options_default (
///
/// @param name The name of the option
/// @param val The value of the option
-void set_string_default(const char *name, const char_u *val)
+/// @param allocated If true, do not copy default as it was already allocated.
+static void set_string_default(const char *name, char *val, bool allocated)
+ FUNC_ATTR_NONNULL_ALL
{
int opt_idx = findoption((char_u *)name);
if (opt_idx >= 0) {
@@ -682,7 +939,10 @@ void set_string_default(const char *name, const char_u *val)
xfree(options[opt_idx].def_val[VI_DEFAULT]);
}
- options[opt_idx].def_val[VI_DEFAULT] = (char_u *) xstrdup((char *) val);
+ options[opt_idx].def_val[VI_DEFAULT] = (char_u *) (
+ allocated
+ ? (char_u *) val
+ : (char_u *) xstrdup(val));
options[opt_idx].flags |= P_DEF_ALLOCED;
}
}
@@ -759,12 +1019,9 @@ void set_init_2(void)
*/
void set_init_3(void)
{
-#if defined(UNIX) || defined(WIN3264)
- /*
- * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
- * This is done after other initializations, where 'shell' might have been
- * set, but only if they have not been set before.
- */
+ // Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
+ // This is done after other initializations, where 'shell' might have been
+ // set, but only if they have not been set before.
int idx_srr;
int do_srr;
int idx_sp;
@@ -821,8 +1078,6 @@ void set_init_3(void)
}
xfree(p);
}
-#endif
-
set_title_defaults();
}
@@ -1244,9 +1499,10 @@ do_set (
} else if (opt_idx >= 0) { /* string */
char_u *save_arg = NULL;
char_u *s = NULL;
- char_u *oldval; /* previous value if *varp */
+ char_u *oldval = NULL; // previous value if *varp
char_u *newval;
- char_u *origval;
+ char_u *origval = NULL;
+ char_u *saved_origval = NULL;
unsigned newlen;
int comma;
int bs;
@@ -1513,14 +1769,37 @@ do_set (
/* Set the new value. */
*(char_u **)(varp) = newval;
+ if (!starting && origval != NULL) {
+ // origval may be freed by
+ // did_set_string_option(), make a copy.
+ saved_origval = vim_strsave(origval);
+ }
+
/* Handle side effects, and set the global value for
* ":set" on local options. */
errmsg = did_set_string_option(opt_idx, (char_u **)varp,
new_value_alloced, oldval, errbuf, opt_flags);
- /* If error detected, print the error message. */
- if (errmsg != NULL)
+ // If error detected, print the error message.
+ if (errmsg != NULL) {
+ xfree(saved_origval);
goto skip;
+ }
+
+ if (saved_origval != NULL) {
+ char_u buf_type[7];
+ vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s",
+ (opt_flags & OPT_LOCAL) ? "local" : "global");
+ set_vim_var_string(VV_OPTION_NEW,
+ *(char_u **)varp, -1);
+ set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
+ set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+ apply_autocmds(EVENT_OPTIONSET,
+ (char_u *)options[opt_idx].fullname,
+ NULL, false, NULL);
+ reset_v_option_vars();
+ xfree(saved_origval);
+ }
} else {
// key code option(FIXME(tarruda): Show a warning or something
// similar)
@@ -2070,6 +2349,7 @@ set_string_option (
char_u *s;
char_u **varp;
char_u *oldval;
+ char_u *saved_oldval = NULL;
char_u *r = NULL;
if (options[opt_idx].var == NULL) /* don't set hidden option */
@@ -2083,10 +2363,30 @@ set_string_option (
: opt_flags);
oldval = *varp;
*varp = s;
- if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
+
+ if (!starting) {
+ saved_oldval = vim_strsave(oldval);
+ }
+
+ if ((r = did_set_string_option(opt_idx, varp, (int)true, oldval, NULL,
opt_flags)) == NULL)
did_set_option(opt_idx, opt_flags, TRUE);
+ // call autocommand after handling side effects
+ if (saved_oldval != NULL) {
+ char_u buf_type[7];
+ vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s",
+ (opt_flags & OPT_LOCAL) ? "local" : "global");
+ set_vim_var_string(VV_OPTION_NEW, *varp, -1);
+ set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
+ set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+ apply_autocmds(EVENT_OPTIONSET,
+ (char_u *)options[opt_idx].fullname,
+ NULL, false, NULL);
+ reset_v_option_vars();
+ xfree(saved_oldval);
+ }
+
return r;
}
@@ -3288,6 +3588,9 @@ set_bool_option (
/* when 'endofline' is changed, redraw the window title */
else if ((int *)varp == &curbuf->b_p_eol) {
redraw_titles();
+ } else if ((int *)varp == &curbuf->b_p_fixeol) {
+ // when 'fixeol' is changed, redraw the window title
+ redraw_titles();
}
/* when 'bomb' is changed, redraw the window title and tab page text */
else if ((int *)varp == &curbuf->b_p_bomb) {
@@ -3555,8 +3858,29 @@ set_bool_option (
* End of handling side effects for bool options.
*/
+ // after handling side effects, call autocommand
+
options[opt_idx].flags |= P_WAS_SET;
+ if (!starting) {
+ char_u buf_old[2];
+ char_u buf_new[2];
+ char_u buf_type[7];
+ vim_snprintf((char *)buf_old, ARRAY_SIZE(buf_old), "%d",
+ old_value ? true: false);
+ vim_snprintf((char *)buf_new, ARRAY_SIZE(buf_new), "%d",
+ value ? true: false);
+ vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s",
+ (opt_flags & OPT_LOCAL) ? "local" : "global");
+ set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
+ set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
+ set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+ apply_autocmds(EVENT_OPTIONSET,
+ (char_u *) options[opt_idx].fullname,
+ NULL, false, NULL);
+ reset_v_option_vars();
+ }
+
comp_col(); /* in case 'ruler' or 'showcmd' changed */
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
@@ -3928,6 +4252,23 @@ set_num_option (
options[opt_idx].flags |= P_WAS_SET;
+ if (!starting && errmsg == NULL) {
+ char_u buf_old[NUMBUFLEN];
+ char_u buf_new[NUMBUFLEN];
+ char_u buf_type[7];
+ vim_snprintf((char *)buf_old, ARRAY_SIZE(buf_old), "%ld", old_value);
+ vim_snprintf((char *)buf_new, ARRAY_SIZE(buf_new), "%ld", value);
+ vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s",
+ (opt_flags & OPT_LOCAL) ? "local" : "global");
+ set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
+ set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
+ set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+ apply_autocmds(EVENT_OPTIONSET,
+ (char_u *) options[opt_idx].fullname,
+ NULL, false, NULL);
+ reset_v_option_vars();
+ }
+
comp_col(); /* in case 'columns' or 'ls' changed */
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
@@ -4962,6 +5303,7 @@ static char_u *get_varp(vimoption_T *p)
case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
+ case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
case PV_ET: return (char_u *)&(curbuf->b_p_et);
case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
case PV_FF: return (char_u *)&(curbuf->b_p_ff);
@@ -5206,6 +5548,7 @@ void buf_copy_options(buf_T *buf, int flags)
buf->b_p_bin = p_bin;
buf->b_p_bomb = p_bomb;
buf->b_p_et = p_et;
+ buf->b_p_fixeol = p_fixeol;
buf->b_p_et_nobin = p_et_nobin;
buf->b_p_ml = p_ml;
buf->b_p_ml_nobin = p_ml_nobin;
@@ -5948,7 +6291,7 @@ static void paste_option_changed(void)
old_p_paste = p_paste;
}
-/// vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
+/// vimrc_found() - Called when a vimrc or "VIMINIT" has been found.
///
/// Set the values for options that didn't get set yet to the Vim defaults.
/// When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
@@ -6141,6 +6484,7 @@ void save_file_ff(buf_T *buf)
* from when editing started (save_file_ff() called).
* Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
* changed and 'binary' is not set.
+ * Also when 'endofline' was changed and 'fixeol' is not set.
* When "ignore_empty" is true don't consider a new, empty buffer to be
* changed.
*/
@@ -6155,9 +6499,9 @@ bool file_ff_differs(buf_T *buf, bool ignore_empty)
&& *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
return FALSE;
if (buf->b_start_ffc != *buf->b_p_ff)
- return TRUE;
- if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
- return TRUE;
+ return true;
+ if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
+ return true;
if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
return TRUE;
if (buf->b_start_fenc == NULL)