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.c165
1 files changed, 98 insertions, 67 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index c11e22703e..0f6874e941 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -168,11 +168,12 @@ static int p_ml_nobin;
static long p_tw_nobin;
static long p_wm_nobin;
-/* Saved values for when 'paste' is set */
+// Saved values for when 'paste' is set.
+static int p_ai_nopaste;
+static int p_et_nopaste;
+static long p_sts_nopaste;
static long p_tw_nopaste;
static long p_wm_nopaste;
-static long p_sts_nopaste;
-static int p_ai_nopaste;
typedef struct vimoption {
char *fullname; /* full option name */
@@ -710,15 +711,11 @@ void set_init_1(void)
/* Must be before option_expand(), because that one needs vim_isIDc() */
didset_options();
- /* Use the current chartab for the generic chartab. */
+ // Use the current chartab for the generic chartab. This is not in
+ // didset_options() because it only depends on 'encoding'.
init_spell_chartab();
/*
- * initialize the table for 'breakat'.
- */
- fill_breakat_flags();
-
- /*
* Expand environment variables and things like "~" for the defaults.
* If option_expand() returns non-NULL the variable is expanded. This can
* only happen for non-indirect options.
@@ -750,14 +747,8 @@ void set_init_1(void)
}
}
- /* Initialize the highlight_attr[] table. */
- highlight_changed();
-
save_file_ff(curbuf); /* Buffer is unchanged */
- /* Parse default for 'wildmode' */
- check_opt_wim();
-
/* Detect use of mlterm.
* Mlterm is a terminal emulator akin to xterm that has some special
* abilities (bidi namely).
@@ -767,11 +758,7 @@ void set_init_1(void)
if (os_env_exists("MLTERM"))
set_option_value((char_u *)"tbidi", 1L, NULL, 0);
- /* Parse default for 'fillchars'. */
- (void)set_chars_option(&p_fcs);
-
- /* Parse default for 'listchars'. */
- (void)set_chars_option(&p_lcs);
+ didset_options2();
// enc_locale() will try to find the encoding of the current locale.
// This will be used when 'default' is used as encoding specifier
@@ -1150,9 +1137,12 @@ do_set (
*/
arg += 3;
if (*arg == '&') {
- ++arg;
- /* Only for :set command set global value of local options. */
+ arg++;
+ // Only for :set command set global value of local options.
set_options_default(OPT_FREE | opt_flags);
+ didset_options();
+ didset_options2();
+ redraw_all_later(CLEAR);
} else {
showoptions(1, opt_flags);
did_show = TRUE;
@@ -2072,9 +2062,31 @@ static void didset_options(void)
(void)spell_check_msm();
(void)spell_check_sps();
(void)compile_cap_prog(curwin->w_s);
- /* set cedit_key */
+ (void)did_set_spell_option(true);
+ // set cedit_key
(void)check_cedit();
briopt_check(curwin);
+ // initialize the table for 'breakat'.
+ fill_breakat_flags();
+}
+
+// More side effects of setting options.
+static void didset_options2(void)
+{
+ // Initialize the highlight_attr[] table.
+ (void)highlight_changed();
+
+ // Parse default for 'clipboard'.
+ (void)opt_strings_flags(p_cb, p_cb_values, &cb_flags, true);
+
+ // Parse default for 'fillchars'.
+ (void)set_chars_option(&p_fcs);
+
+ // Parse default for 'listchars'.
+ (void)set_chars_option(&p_lcs);
+
+ // Parse default for 'wildmode'.
+ check_opt_wim();
}
/*
@@ -2853,22 +2865,7 @@ did_set_string_option (
|| varp == &(curwin->w_s->b_p_spf)) {
// When 'spelllang' or 'spellfile' is set and there is a window for this
// buffer in which 'spell' is set load the wordlists.
- if (varp == &(curwin->w_s->b_p_spf)) {
- int l = (int)STRLEN(curwin->w_s->b_p_spf);
- if (l > 0
- && (l < 4 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0)) {
- errmsg = e_invarg;
- }
- }
-
- if (errmsg == NULL) {
- FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
- if (wp->w_buffer == curbuf && wp->w_p_spell) {
- errmsg = did_set_spelllang(wp);
- break;
- }
- }
- }
+ errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
}
/* When 'spellcapcheck' is set compile the regexp program. */
else if (varp == &(curwin->w_s->b_p_spc)) {
@@ -3424,6 +3421,30 @@ char_u *check_stl_option(char_u *s)
return NULL;
}
+static char_u *did_set_spell_option(bool is_spellfile)
+{
+ char_u *errmsg = NULL;
+
+ if (is_spellfile) {
+ int l = (int)STRLEN(curwin->w_s->b_p_spf);
+ if (l > 0
+ && (l < 4 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0)) {
+ errmsg = e_invarg;
+ }
+ }
+
+ if (errmsg == NULL) {
+ FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
+ if (wp->w_buffer == curbuf && wp->w_p_spell) {
+ errmsg = did_set_spelllang(wp);
+ break;
+ }
+ }
+ }
+
+ return errmsg;
+}
+
/*
* Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
* Return error message when failed, NULL when OK.
@@ -5503,6 +5524,7 @@ void buf_copy_options(buf_T *buf, int flags)
buf->b_p_et = p_et;
buf->b_p_fixeol = p_fixeol;
buf->b_p_et_nobin = p_et_nobin;
+ buf->b_p_et_nopaste = p_et_nopaste;
buf->b_p_ml = p_ml;
buf->b_p_ml_nobin = p_ml_nobin;
buf->b_p_inf = p_inf;
@@ -6160,6 +6182,7 @@ static void paste_option_changed(void)
{
static int old_p_paste = FALSE;
static int save_sm = 0;
+ static int save_sta = 0;
static int save_ru = 0;
static int save_ri = 0;
static int save_hkmap = 0;
@@ -6176,40 +6199,44 @@ static void paste_option_changed(void)
buf->b_p_wm_nopaste = buf->b_p_wm;
buf->b_p_sts_nopaste = buf->b_p_sts;
buf->b_p_ai_nopaste = buf->b_p_ai;
+ buf->b_p_et_nopaste = buf->b_p_et;
}
- /* save global options */
+ // save global options
save_sm = p_sm;
+ save_sta = p_sta;
save_ru = p_ru;
save_ri = p_ri;
save_hkmap = p_hkmap;
- /* save global values for local buffer options */
+ // save global values for local buffer options
+ p_ai_nopaste = p_ai;
+ p_et_nopaste = p_et;
+ p_sts_nopaste = p_sts;
p_tw_nopaste = p_tw;
p_wm_nopaste = p_wm;
- p_sts_nopaste = p_sts;
- p_ai_nopaste = p_ai;
}
- /*
- * Always set the option values, also when 'paste' is set when it is
- * already on.
- */
- /* set options for each buffer */
+ // Always set the option values, also when 'paste' is set when it is
+ // already on.
+ // set options for each buffer
FOR_ALL_BUFFERS(buf) {
- buf->b_p_tw = 0; /* textwidth is 0 */
- buf->b_p_wm = 0; /* wrapmargin is 0 */
- buf->b_p_sts = 0; /* softtabstop is 0 */
- buf->b_p_ai = 0; /* no auto-indent */
- }
-
- /* set global options */
- p_sm = 0; /* no showmatch */
- if (p_ru)
- status_redraw_all(); /* redraw to remove the ruler */
- p_ru = 0; /* no ruler */
- p_ri = 0; /* no reverse insert */
- p_hkmap = 0; /* no Hebrew keyboard */
- /* set global values for local buffer options */
+ buf->b_p_tw = 0; // textwidth is 0
+ buf->b_p_wm = 0; // wrapmargin is 0
+ buf->b_p_sts = 0; // softtabstop is 0
+ buf->b_p_ai = 0; // no auto-indent
+ buf->b_p_et = 0; // no expandtab
+ }
+
+ // set global options
+ p_sm = 0; // no showmatch
+ p_sta = 0; // no smarttab
+ if (p_ru) {
+ status_redraw_all(); // redraw to remove the ruler
+ }
+ p_ru = 0; // no ruler
+ p_ri = 0; // no reverse insert
+ p_hkmap = 0; // no Hebrew keyboard
+ // set global values for local buffer options
p_tw = 0;
p_wm = 0;
p_sts = 0;
@@ -6225,20 +6252,24 @@ static void paste_option_changed(void)
buf->b_p_wm = buf->b_p_wm_nopaste;
buf->b_p_sts = buf->b_p_sts_nopaste;
buf->b_p_ai = buf->b_p_ai_nopaste;
+ buf->b_p_et = buf->b_p_et_nopaste;
}
/* restore global options */
p_sm = save_sm;
- if (p_ru != save_ru)
- status_redraw_all(); /* redraw to draw the ruler */
+ p_sta = save_sta;
+ if (p_ru != save_ru) {
+ status_redraw_all(); // redraw to draw the ruler
+ }
p_ru = save_ru;
p_ri = save_ri;
p_hkmap = save_hkmap;
- /* set global values for local buffer options */
+ // set global values for local buffer options
+ p_ai = p_ai_nopaste;
+ p_et = p_et_nopaste;
+ p_sts = p_sts_nopaste;
p_tw = p_tw_nopaste;
p_wm = p_wm_nopaste;
- p_sts = p_sts_nopaste;
- p_ai = p_ai_nopaste;
}
old_p_paste = p_paste;