1 /* vi:set ts=8 sts=4 sw=4 noet:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
11 * optionstr.c: Functions related to string options
16 static char_u shm_buf[SHM_LEN];
17 static int set_shm_recursive = 0;
19 static char *(p_ambw_values[]) = {"single", "double", NULL};
20 static char *(p_bg_values[]) = {"light", "dark", NULL};
21 static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
22 static char *(p_bo_values[]) = {"all", "backspace", "cursor", "complete",
23 "copy", "ctrlg", "error", "esc", "ex",
24 "hangul", "insertmode", "lang", "mess",
25 "showmatch", "operator", "register", "shell",
26 "spell", "term", "wildmode", NULL};
27 static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", "unsigned", NULL};
28 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
30 static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2",
36 static char *(p_cmp_values[]) = {"internal", "keepascii", NULL};
37 static char *(p_dy_values[]) = {"lastline", "truncate", "uhex", NULL};
39 static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent",
40 "quickfix", "search", "tag", "insert",
41 "undo", "jump", NULL};
44 // Also used for 'viewoptions'! Keep in sync with SSOP_ flags.
45 static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize",
46 "localoptions", "options", "help", "blank", "globals", "slash", "unix",
47 "sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", "skiprtp",
50 // Keep in sync with SWB_ flags in option.h
51 static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", "uselast", NULL};
52 static char *(p_spk_values[]) = {"cursor", "screen", "topline", NULL};
53 static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL};
54 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
55 static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL};
57 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
58 static char *(p_tbis_values[]) = {"tiny", "small", "medium", "large", "huge", "giant", NULL};
60 #if defined(UNIX) || defined(VMS)
61 static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL};
63 static char *(p_ve_values[]) = {"block", "insert", "all", "onemore", "none", "NONE", NULL};
64 static char *(p_wop_values[]) = {"fuzzy", "tagfile", "pum", NULL};
66 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
68 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
69 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
70 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
71 static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
73 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
75 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
76 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
77 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
78 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
79 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
80 static char *(p_bs_values[]) = {"indent", "eol", "start", "nostop", NULL};
82 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
87 static char *(p_fcl_values[]) = {"all", NULL};
89 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "popuphidden", "noinsert", "noselect", NULL};
90 #ifdef BACKSLASH_IN_FILENAME
91 static char *(p_csl_values[]) = {"slash", "backslash", NULL};
94 static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
96 #if defined(MSWIN) && defined(FEAT_TERMINAL)
97 static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
99 static char *(p_sloc_values[]) = {"last", "statusline", "tabline", NULL};
100 static char *(p_sws_values[]) = {"fsync", "sync", NULL};
102 static int check_opt_strings(char_u *val, char **values, int list);
103 static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
106 * After setting various option values: recompute variables that depend on
110 didset_string_options(void)
112 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
113 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
114 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
116 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
117 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
120 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
122 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
123 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
124 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
125 #if defined(UNIX) || defined(VMS)
126 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
128 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
129 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
131 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
132 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
134 (void)opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE);
137 #if defined(FEAT_EVAL)
139 * Trigger the OptionSet autocommand.
140 * "opt_idx" is the index of the option being set.
141 * "opt_flags" can be OPT_LOCAL etc.
142 * "oldval" the old value
143 * "oldval_l" the old local value (only non-NULL if global and local value
145 * "oldval_g" the old global value (only non-NULL if global and local value
147 * "newval" the new value
150 trigger_optionset_string(
158 // Don't do this recursively.
159 if (oldval == NULL || newval == NULL
160 || *get_vim_var_str(VV_OPTION_TYPE) != NUL)
165 sprintf((char *)buf_type, "%s",
166 (opt_flags & OPT_LOCAL) ? "local" : "global");
167 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
168 set_vim_var_string(VV_OPTION_NEW, newval, -1);
169 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
170 if (opt_flags & OPT_LOCAL)
172 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
173 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
175 if (opt_flags & OPT_GLOBAL)
177 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
178 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
180 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
182 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
183 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
184 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
186 if (opt_flags & OPT_MODELINE)
188 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
189 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
191 apply_autocmds(EVENT_OPTIONSET,
192 get_option_fullname(opt_idx), NULL, FALSE,
194 reset_v_option_vars();
199 illegal_char(char *errbuf, int c)
203 sprintf((char *)errbuf, _(e_illegal_character_str), (char *)transchar(c));
208 * Check string options in a buffer for NULL value.
211 check_buf_options(buf_T *buf)
213 check_string_option(&buf->b_p_bh);
214 check_string_option(&buf->b_p_bt);
215 check_string_option(&buf->b_p_fenc);
216 check_string_option(&buf->b_p_ff);
218 check_string_option(&buf->b_p_def);
219 check_string_option(&buf->b_p_inc);
221 check_string_option(&buf->b_p_inex);
224 #if defined(FEAT_EVAL)
225 check_string_option(&buf->b_p_inde);
226 check_string_option(&buf->b_p_indk);
228 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
229 check_string_option(&buf->b_p_bexpr);
231 #if defined(FEAT_CRYPT)
232 check_string_option(&buf->b_p_cm);
234 check_string_option(&buf->b_p_fp);
235 #if defined(FEAT_EVAL)
236 check_string_option(&buf->b_p_fex);
239 check_string_option(&buf->b_p_key);
241 check_string_option(&buf->b_p_kp);
242 check_string_option(&buf->b_p_mps);
243 check_string_option(&buf->b_p_fo);
244 check_string_option(&buf->b_p_flp);
245 check_string_option(&buf->b_p_isk);
246 check_string_option(&buf->b_p_com);
248 check_string_option(&buf->b_p_cms);
250 check_string_option(&buf->b_p_nf);
251 check_string_option(&buf->b_p_qe);
253 check_string_option(&buf->b_p_syn);
254 check_string_option(&buf->b_s.b_syn_isk);
257 check_string_option(&buf->b_s.b_p_spc);
258 check_string_option(&buf->b_s.b_p_spf);
259 check_string_option(&buf->b_s.b_p_spl);
260 check_string_option(&buf->b_s.b_p_spo);
262 check_string_option(&buf->b_p_sua);
263 check_string_option(&buf->b_p_cink);
264 check_string_option(&buf->b_p_cino);
265 check_string_option(&buf->b_p_cinsd);
267 check_string_option(&buf->b_p_lop);
268 check_string_option(&buf->b_p_ft);
269 check_string_option(&buf->b_p_cinw);
270 check_string_option(&buf->b_p_cpt);
271 #ifdef FEAT_COMPL_FUNC
272 check_string_option(&buf->b_p_cfu);
273 check_string_option(&buf->b_p_ofu);
274 check_string_option(&buf->b_p_tsrfu);
277 check_string_option(&buf->b_p_tfu);
280 check_string_option(&buf->b_p_keymap);
283 check_string_option(&buf->b_p_gp);
284 check_string_option(&buf->b_p_mp);
285 check_string_option(&buf->b_p_efm);
287 check_string_option(&buf->b_p_ep);
288 check_string_option(&buf->b_p_path);
289 check_string_option(&buf->b_p_tags);
290 check_string_option(&buf->b_p_tc);
291 check_string_option(&buf->b_p_dict);
292 check_string_option(&buf->b_p_tsr);
293 check_string_option(&buf->b_p_lw);
294 check_string_option(&buf->b_p_bkc);
295 check_string_option(&buf->b_p_menc);
297 check_string_option(&buf->b_p_vsts);
298 check_string_option(&buf->b_p_vts);
303 * Free the string allocated for an option.
304 * Checks for the string being empty_option. This may happen if we're out of
305 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
307 * Does NOT check for P_ALLOCED flag!
310 free_string_option(char_u *p)
312 if (p != empty_option)
317 clear_string_option(char_u **pp)
319 if (*pp != empty_option)
325 check_string_option(char_u **pp)
332 * Set global value for string option when it's a local option.
335 set_string_option_global(
336 int opt_idx, // option index
337 char_u **varp) // pointer to option variable
341 // the global value is always allocated
342 if (is_window_local_option(opt_idx))
343 p = (char_u **)GLOBAL_WO(varp);
345 p = (char_u **)get_option_var(opt_idx);
346 if (!is_global_option(opt_idx)
348 && (s = vim_strsave(*varp)) != NULL)
350 free_string_option(*p);
356 * Set a string option to a new value (without checking the effect).
357 * The string is copied into allocated memory.
358 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
359 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
360 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
364 set_string_option_direct(
368 int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL
373 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
376 if (idx == -1) // use name
378 idx = findoption(name);
379 if (idx < 0) // not found (should not happen)
381 semsg(_(e_internal_error_str), "set_string_option_direct()");
382 siemsg(_("For option %s"), name);
387 if (is_hidden_option(idx)) // can't set hidden option
390 s = vim_strsave(val);
394 varp = (char_u **)get_option_varp_scope(idx,
395 both ? OPT_LOCAL : opt_flags);
396 if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED))
397 free_string_option(*varp);
400 // For buffer/window local option may also set the global value.
402 set_string_option_global(idx, varp);
404 set_option_flag(idx, P_ALLOCED);
406 // When setting both values of a global option with a local value,
407 // make the local value empty, so that the global value is used.
408 if (is_global_local_option(idx) && both)
410 free_string_option(*varp);
411 *varp = empty_option;
414 if (set_sid != SID_NONE)
419 script_ctx = current_sctx;
422 script_ctx.sc_sid = set_sid;
423 script_ctx.sc_seq = 0;
424 script_ctx.sc_lnum = 0;
425 script_ctx.sc_version = 1;
427 set_option_sctx_idx(idx, opt_flags, script_ctx);
433 * Like set_string_option_direct(), but for a window-local option in "wp".
434 * Blocks autocommands to avoid the old curwin becoming invalid.
437 set_string_option_direct_in_win(
445 win_T *save_curwin = curwin;
449 curbuf = curwin->w_buffer;
450 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
451 curwin = save_curwin;
452 curbuf = curwin->w_buffer;
456 #if defined(FEAT_PROP_POPUP) || defined(PROTO)
458 * Like set_string_option_direct(), but for a buffer-local option in "buf".
459 * Blocks autocommands to avoid the old curbuf becoming invalid.
462 set_string_option_direct_in_buf(
470 buf_T *save_curbuf = curbuf;
474 curwin->w_buffer = curbuf;
475 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
476 curbuf = save_curbuf;
477 curwin->w_buffer = curbuf;
483 * Set a string option to a new value, and handle the effects.
485 * Returns NULL on success or an untranslated error message on error.
491 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
497 #if defined(FEAT_EVAL)
498 char_u *oldval_l = NULL;
499 char_u *oldval_g = NULL;
500 char_u *saved_oldval = NULL;
501 char_u *saved_oldval_l = NULL;
502 char_u *saved_oldval_g = NULL;
503 char_u *saved_newval = NULL;
506 int value_checked = FALSE;
508 if (is_hidden_option(opt_idx)) // don't set hidden option
511 s = vim_strsave(value == NULL ? (char_u *)"" : value);
515 varp = (char_u **)get_option_varp_scope(opt_idx,
516 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
517 ? (is_global_local_option(opt_idx)
518 ? OPT_GLOBAL : OPT_LOCAL)
521 #if defined(FEAT_EVAL)
522 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
524 oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL);
525 oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
530 #if defined(FEAT_EVAL)
533 && !is_crypt_key_option(opt_idx)
537 if (oldval_l != NULL)
538 saved_oldval_l = vim_strsave(oldval_l);
539 if (oldval_g != NULL)
540 saved_oldval_g = vim_strsave(oldval_g);
541 saved_oldval = vim_strsave(oldval);
542 saved_newval = vim_strsave(s);
545 if ((errmsg = did_set_string_option(opt_idx, varp, oldval, value, errbuf,
546 opt_flags, &value_checked)) == NULL)
547 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
549 #if defined(FEAT_EVAL)
550 // call autocommand after handling side effects
552 trigger_optionset_string(opt_idx, opt_flags,
553 saved_oldval, saved_oldval_l,
554 saved_oldval_g, saved_newval);
555 vim_free(saved_oldval);
556 vim_free(saved_oldval_l);
557 vim_free(saved_oldval_g);
558 vim_free(saved_newval);
564 * Return TRUE if "val" is a valid 'filetype' name.
565 * Also used for 'syntax' and 'keymap'.
568 valid_filetype(char_u *val)
570 return valid_name(val, ".-_");
575 * Check validity of options with the 'statusline' format.
576 * Return an untranslated error message or NULL.
579 check_stl_option(char_u *s)
582 static char errbuf[80];
586 // Check for valid keys after % sequences
587 while (*s && *s != '%')
592 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_SEPARATE)
600 if (--groupdepth < 0)
606 while (VIM_ISDIGIT(*s))
608 if (*s == STL_USER_HL)
613 while (*s && VIM_ISDIGIT(*s))
621 if (vim_strchr(STL_ALL, *s) == NULL)
623 return illegal_char(errbuf, *s);
627 int reevaluate = (*++s == '%');
629 if (reevaluate && *++s == '}')
630 // "}" is not allowed immediately after "%{%"
631 return illegal_char(errbuf, '}');
632 while ((*s != '}' || (reevaluate && s[-1] != '%')) && *s)
635 return e_unclosed_expression_sequence;
639 return e_unbalanced_groups;
645 * Check for a "normal" directory or file name in some options. Disallow a
646 * path separator (slash and/or backslash), wildcards and characters that are
647 * often illegal in a file name. Be more permissive if "secure" is off.
650 check_illegal_path_names(int opt_idx, char_u **varp)
652 return (((get_option_flags(opt_idx) & P_NFNAME)
653 && vim_strpbrk(*varp, (char_u *)(secure
654 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
655 || ((get_option_flags(opt_idx) & P_NDNAME)
656 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL));
660 * The 'term' option is changed.
663 did_set_term(int *opt_idx, long_u *free_oldval)
667 if (T_NAME[0] == NUL)
668 errmsg = e_cannot_set_term_to_empty_string;
671 errmsg = e_cannot_change_term_in_GUI;
672 else if (term_is_gui(T_NAME))
673 errmsg = e_use_gui_to_start_GUI;
675 else if (set_termname(T_NAME) == FAIL)
676 errmsg = e_not_found_in_termcap;
679 // Screen colors may have changed.
680 redraw_later_clear();
682 // Both 'term' and 'ttytype' point to T_NAME, only set the
683 // P_ALLOCED flag on 'term'.
684 *opt_idx = findoption((char_u *)"term");
686 *free_oldval = (get_option_flags(*opt_idx) & P_ALLOCED);
693 * The 'backupcopy' option is changed.
696 did_set_backupcopy(optset_T *args)
699 unsigned int *flags = &bkc_flags;
702 if (args->os_flags & OPT_LOCAL)
704 bkc = curbuf->b_p_bkc;
705 flags = &curbuf->b_bkc_flags;
708 if ((args->os_flags & OPT_LOCAL) && *bkc == NUL)
709 // make the local value empty: use the global value
713 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
714 errmsg = e_invalid_argument;
715 if ((((int)*flags & BKC_AUTO) != 0)
716 + (((int)*flags & BKC_YES) != 0)
717 + (((int)*flags & BKC_NO) != 0) != 1)
719 // Must have exactly one of "auto", "yes" and "no".
720 (void)opt_strings_flags(args->os_oldval.string, p_bkc_values,
722 errmsg = e_invalid_argument;
730 * The 'backupext' or the 'patchmode' option is changed.
733 did_set_backupext_or_patchmode(optset_T *args UNUSED)
735 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
736 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
737 return e_backupext_and_patchmode_are_equal;
742 #if defined(FEAT_LINEBREAK) || defined(PROTO)
744 * The 'breakindentopt' option is changed.
747 did_set_breakindentopt(optset_T *args UNUSED)
751 if (briopt_check(curwin) == FAIL)
752 errmsg = e_invalid_argument;
753 // list setting requires a redraw
754 if (curwin->w_briopt_list)
755 redraw_all_later(UPD_NOT_VALID);
762 * The 'isident' or the 'iskeyword' or the 'isprint' or the 'isfname' option is
766 did_set_isopt(optset_T *args)
768 // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
769 // If the new option is invalid, use old value.
770 // 'lisp' option: refill g_chartab[] for '-' char.
771 if (init_chartab() == FAIL)
773 args->os_restore_chartab = TRUE;// need to restore the chartab.
774 return e_invalid_argument; // error in value
781 * The 'helpfile' option is changed.
784 did_set_helpfile(optset_T *args UNUSED)
786 // May compute new values for $VIM and $VIMRUNTIME
788 vim_unsetenv_ext((char_u *)"VIM");
789 if (didset_vimruntime)
790 vim_unsetenv_ext((char_u *)"VIMRUNTIME");
794 #if defined(FEAT_SYN_HL) || defined(PROTO)
796 * The 'colorcolumn' option is changed.
799 did_set_colorcolumn(optset_T *args UNUSED)
801 return check_colorcolumn(curwin);
805 * The 'cursorlineopt' option is changed.
808 did_set_cursorlineopt(optset_T *args)
810 if (*args->os_varp == NUL
811 || fill_culopt_flags(args->os_varp, curwin) != OK)
812 return e_invalid_argument;
818 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
820 * The 'helplang' option is changed.
823 did_set_helplang(optset_T *args UNUSED)
827 // Check for "", "ab", "ab,cd", etc.
828 for (char_u *s = p_hlg; *s != NUL; s += 3)
830 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
832 errmsg = e_invalid_argument;
844 * The 'highlight' option is changed.
847 did_set_highlight(optset_T *args UNUSED)
849 if (highlight_changed() == FAIL)
850 return e_invalid_argument; // invalid flags
856 * An option that accepts a list of flags is changed.
857 * e.g. 'viewoptions', 'switchbuf', 'casemap', etc.
860 did_set_opt_flags(char_u *val, char **values, unsigned *flagp, int list)
862 if (opt_strings_flags(val, values, flagp, list) == FAIL)
863 return e_invalid_argument;
869 * An option that accepts a list of string values is changed.
870 * e.g. 'nrformats', 'scrollopt', 'wildoptions', etc.
873 did_set_opt_strings(char_u *val, char **values, int list)
875 return did_set_opt_flags(val, values, NULL, list);
879 * The 'belloff' option is changed.
882 did_set_belloff(optset_T *args UNUSED)
884 return did_set_opt_flags(p_bo, p_bo_values, &bo_flags, TRUE);
888 * The 'casemap' option is changed.
891 did_set_casemap(optset_T *args UNUSED)
893 return did_set_opt_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
897 * The 'scrollopt' option is changed.
900 did_set_scrollopt(optset_T *args UNUSED)
902 return did_set_opt_strings(p_sbo, p_scbopt_values, TRUE);
906 * The 'selectmode' option is changed.
909 did_set_selectmode(optset_T *args UNUSED)
911 return did_set_opt_strings(p_slm, p_slm_values, TRUE);
915 * The 'showcmdloc' option is changed.
918 did_set_showcmdloc(optset_T *args UNUSED)
920 return did_set_opt_strings(p_sloc, p_sloc_values, FALSE);
924 * The 'splitkeep' option is changed.
927 did_set_splitkeep(optset_T *args UNUSED)
929 return did_set_opt_strings(p_spk, p_spk_values, FALSE);
933 * The 'swapsync' option is changed.
936 did_set_swapsync(optset_T *args UNUSED)
938 return did_set_opt_strings(p_sws, p_sws_values, FALSE);
942 * The 'switchbuf' option is changed.
945 did_set_switchbuf(optset_T *args UNUSED)
947 return did_set_opt_flags(p_swb, p_swb_values, &swb_flags, TRUE);
950 #if defined(FEAT_SESSION) || defined(PROTO)
952 * The 'sessionoptions' option is changed.
955 did_set_sessionoptions(optset_T *args)
957 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
958 return e_invalid_argument;
959 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
961 // Don't allow both "sesdir" and "curdir".
962 (void)opt_strings_flags(args->os_oldval.string, p_ssop_values,
964 return e_invalid_argument;
971 * The 'viewoptions' option is changed.
974 did_set_viewoptions(optset_T *args UNUSED)
976 return did_set_opt_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
981 * The 'ambiwidth' option is changed.
984 did_set_ambiwidth(optset_T *args UNUSED)
986 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
987 return e_invalid_argument;
989 return check_chars_options();
993 * The 'background' option is changed.
996 did_set_background(optset_T *args UNUSED)
998 if (check_opt_strings(p_bg, p_bg_values, FALSE) == FAIL)
999 return e_invalid_argument;
1002 int dark = (*p_bg == 'd');
1005 init_highlight(FALSE, FALSE);
1008 if (dark != (*p_bg == 'd')
1009 && get_var_value((char_u *)"g:colors_name") != NULL)
1011 // The color scheme must have set 'background' back to another
1012 // value, that's not what we want here. Disable the color
1013 // scheme and set the colors again.
1014 do_unlet((char_u *)"g:colors_name", TRUE);
1015 free_string_option(p_bg);
1016 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
1017 check_string_option(&p_bg);
1018 init_highlight(FALSE, FALSE);
1021 #ifdef FEAT_TERMINAL
1022 term_update_colors_all();
1029 * The 'wildmode' option is changed.
1032 did_set_wildmode(optset_T *args UNUSED)
1034 if (check_opt_wim() == FAIL)
1035 return e_invalid_argument;
1040 * The 'wildoptions' option is changed.
1043 did_set_wildoptions(optset_T *args UNUSED)
1045 return did_set_opt_strings(p_wop, p_wop_values, TRUE);
1048 #if defined(FEAT_WAK) || defined(PROTO)
1050 * The 'winaltkeys' option is changed.
1053 did_set_winaltkeys(optset_T *args UNUSED)
1055 char *errmsg = NULL;
1058 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
1059 errmsg = e_invalid_argument;
1061 # if defined(FEAT_GUI_MOTIF)
1062 else if (gui.in_use)
1063 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
1064 # elif defined(FEAT_GUI_GTK)
1065 else if (gui.in_use)
1066 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
1074 * The 'wincolor' option is changed.
1077 did_set_wincolor(optset_T *args UNUSED)
1079 #ifdef FEAT_TERMINAL
1080 term_update_wincolor(curwin);
1086 * The 'eadirection' option is changed.
1089 did_set_eadirection(optset_T *args UNUSED)
1091 return did_set_opt_strings(p_ead, p_ead_values, FALSE);
1095 * The 'eventignore' option is changed.
1098 did_set_eventignore(optset_T *args UNUSED)
1100 if (check_ei() == FAIL)
1101 return e_invalid_argument;
1106 * One of the 'encoding', 'fileencoding', 'termencoding' or 'makeencoding'
1107 * options is changed.
1110 did_set_encoding(char_u **varp, char_u **gvarp, int opt_flags)
1112 char *errmsg = NULL;
1115 if (gvarp == &p_fenc)
1117 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
1118 errmsg = e_cannot_make_changes_modifiable_is_off;
1119 else if (vim_strchr(*varp, ',') != NULL)
1120 // No comma allowed in 'fileencoding'; catches confusing it
1121 // with 'fileencodings'.
1122 errmsg = e_invalid_argument;
1125 // May show a "+" in the title now.
1127 // Add 'fileencoding' to the swap file.
1128 ml_setflags(curbuf);
1133 // canonize the value, so that STRCMP() can be used on it
1134 p = enc_canonize(*varp);
1147 #if defined(FEAT_GUI_GTK)
1148 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
1150 // GTK uses only a single encoding, and that is UTF-8.
1151 if (STRCMP(p_tenc, "utf-8") != 0)
1152 errmsg = e_cannot_be_changed_in_gtk_GUI;
1159 // When 'keymap' is used and 'encoding' changes, reload the keymap
1160 // (with another encoding).
1161 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
1162 (void)keymap_init();
1165 // When 'termencoding' is not empty and 'encoding' changes or when
1166 // 'termencoding' changes, need to setup for keyboard input and
1167 // display output conversion.
1168 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
1170 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
1171 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
1173 semsg(_(e_cannot_convert_between_str_and_str),
1175 errmsg = e_invalid_argument;
1180 // $HOME, $VIM and $VIMRUNTIME may have characters in active code page.
1192 #if defined(FEAT_POSTSCRIPT) || defined(PROTO)
1194 * The 'printencoding' option is changed.
1197 did_set_printencoding(optset_T *args UNUSED)
1201 // Canonize 'printencoding' if VIM standard one
1202 p = enc_canonize(p_penc);
1210 // Ensure lower case and '-' for '_'
1211 for (s = p_penc; *s != NUL; s++)
1216 *s = TOLOWER_ASC(*s);
1224 #if (defined(FEAT_XIM) && defined(FEAT_GUI_GTK)) || defined(PROTO)
1226 * The 'imactivatekey' option is changed.
1229 did_set_imactivatekey(optset_T *args UNUSED)
1231 if (!im_xim_isvalid_imactivate())
1232 return e_invalid_argument;
1237 #if defined(FEAT_KEYMAP) || defined(PROTO)
1239 * The 'keymap' option is changed.
1242 did_set_keymap(optset_T *args)
1244 char *errmsg = NULL;
1246 if (!valid_filetype(args->os_varp))
1247 errmsg = e_invalid_argument;
1250 int secure_save = secure;
1252 // Reset the secure flag, since the value of 'keymap' has
1253 // been checked to be safe.
1256 // load or unload key mapping tables
1257 errmsg = keymap_init();
1259 secure = secure_save;
1261 // Since we check the value, there is no need to set P_INSECURE,
1262 // even when the value comes from a modeline.
1263 args->os_value_checked = TRUE;
1268 if (*curbuf->b_p_keymap != NUL)
1270 // Installed a new keymap, switch on using it.
1271 curbuf->b_p_iminsert = B_IMODE_LMAP;
1272 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
1273 curbuf->b_p_imsearch = B_IMODE_LMAP;
1277 // Cleared the keymap, may reset 'iminsert' and 'imsearch'.
1278 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
1279 curbuf->b_p_iminsert = B_IMODE_NONE;
1280 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
1281 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
1283 if ((args->os_flags & OPT_LOCAL) == 0)
1285 set_iminsert_global();
1286 set_imsearch_global();
1288 status_redraw_curbuf();
1296 * The 'fileformat' option is changed.
1299 did_set_fileformat(optset_T *args)
1301 if (!curbuf->b_p_ma && !(args->os_flags & OPT_GLOBAL))
1302 return e_cannot_make_changes_modifiable_is_off;
1303 else if (check_opt_strings(args->os_varp, p_ff_values, FALSE) != OK)
1304 return e_invalid_argument;
1306 // may also change 'textmode'
1307 if (get_fileformat(curbuf) == EOL_DOS)
1308 curbuf->b_p_tx = TRUE;
1310 curbuf->b_p_tx = FALSE;
1312 // update flag in swap file
1313 ml_setflags(curbuf);
1314 // Redraw needed when switching to/from "mac": a CR in the text
1315 // will be displayed differently.
1316 if (get_fileformat(curbuf) == EOL_MAC || *args->os_oldval.string == 'm')
1317 redraw_curbuf_later(UPD_NOT_VALID);
1323 * The 'fileformats' option is changed.
1326 did_set_fileformats(optset_T *args UNUSED)
1328 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
1329 return e_invalid_argument;
1331 // also change 'textauto'
1340 #if defined(FEAT_CRYPT) || defined(PROTO)
1342 * The 'cryptkey' option is changed.
1345 did_set_cryptkey(optset_T *args)
1347 // Make sure the ":set" command doesn't show the new value in the
1349 remove_key_from_history();
1351 if (STRCMP(curbuf->b_p_key, args->os_oldval.string) != 0)
1353 // Need to update the swapfile.
1354 ml_set_crypt_key(curbuf, args->os_oldval.string,
1355 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
1363 * The 'cryptmethod' option is changed.
1366 did_set_cryptmethod(optset_T *args)
1371 if (args->os_flags & OPT_LOCAL)
1375 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
1376 return e_invalid_argument;
1377 else if (crypt_self_test() == FAIL)
1378 return e_invalid_argument;
1380 // When setting the global value to empty, make it "zip".
1383 free_string_option(p_cm);
1384 p_cm = vim_strsave((char_u *)"zip");
1386 // When using ":set cm=name" the local value is going to be empty.
1387 // Do that here, otherwise the crypt functions will still use the
1389 if ((args->os_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
1391 free_string_option(curbuf->b_p_cm);
1392 curbuf->b_p_cm = empty_option;
1395 // Need to update the swapfile when the effective method changed.
1396 // Set "s" to the effective old value, "p" to the effective new
1397 // method and compare.
1398 if ((args->os_flags & OPT_LOCAL) && *args->os_oldval.string == NUL)
1399 s = p_cm; // was previously using the global value
1401 s = args->os_oldval.string;
1402 if (*curbuf->b_p_cm == NUL)
1403 p = p_cm; // is now using the global value
1406 if (STRCMP(s, p) != 0)
1407 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
1409 // If the global value changes need to update the swapfile for all
1410 // buffers using that value.
1411 if ((args->os_flags & OPT_GLOBAL)
1412 && STRCMP(p_cm, args->os_oldval.string) != 0)
1416 FOR_ALL_BUFFERS(buf)
1417 if (buf != curbuf && *buf->b_p_cm == NUL)
1418 ml_set_crypt_key(buf, buf->b_p_key, args->os_oldval.string);
1425 * The 'matchpairs' option is changed.
1428 did_set_matchpairs(optset_T *args)
1434 for (p = args->os_varp; *p != NUL; ++p)
1444 x3 = mb_ptr2char(p);
1447 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
1448 return e_invalid_argument;
1455 // Check for "x:y,x:y"
1456 for (p = args->os_varp; *p != NUL; p += 4)
1458 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
1459 return e_invalid_argument;
1469 * The 'comments' option is changed.
1472 did_set_comments(optset_T *args)
1475 char *errmsg = NULL;
1477 for (s = args->os_varp; *s; )
1479 while (*s && *s != ':')
1481 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
1482 && !VIM_ISDIGIT(*s) && *s != '-')
1484 errmsg = illegal_char(args->os_errbuf, *s);
1490 errmsg = e_missing_colon;
1491 else if (*s == ',' || *s == NUL)
1492 errmsg = e_zero_length_string;
1495 while (*s && *s != ',')
1497 if (*s == '\\' && s[1] != NUL)
1501 s = skip_to_option_part(s);
1508 * The global 'listchars' or 'fillchars' option is changed.
1511 did_set_global_listfillchars(char_u **varp, int opt_flags)
1513 char *errmsg = NULL;
1514 char_u **local_ptr = varp == &p_lcs
1515 ? &curwin->w_p_lcs : &curwin->w_p_fcs;
1517 // only apply the global value to "curwin" when it does not have a
1519 errmsg = set_chars_option(curwin, varp,
1520 **local_ptr == NUL || !(opt_flags & OPT_GLOBAL));
1527 // If the current window is set to use the global
1528 // 'listchars'/'fillchars' value, clear the window-local value.
1529 if (!(opt_flags & OPT_GLOBAL))
1530 clear_string_option(local_ptr);
1531 FOR_ALL_TAB_WINDOWS(tp, wp)
1533 // If the current window has a local value need to apply it
1534 // again, it was changed when setting the global value.
1535 // If no error was returned above, we don't expect an error
1536 // here, so ignore the return value.
1537 local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs;
1538 if (**local_ptr == NUL)
1539 (void)set_chars_option(wp, local_ptr, TRUE);
1542 redraw_all_later(UPD_NOT_VALID);
1548 * The 'verbosefile' option is changed.
1551 did_set_verbosefile(optset_T *args UNUSED)
1554 if (*p_vfile != NUL && verbose_open() == FAIL)
1555 return e_invalid_argument;
1560 #if defined(FEAT_VIMINFO) || defined(PROTO)
1562 * The 'viminfo' option is changed.
1565 did_set_viminfo(optset_T *args)
1568 char *errmsg = NULL;
1570 for (s = p_viminfo; *s;)
1572 // Check it's a valid character
1573 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
1575 errmsg = illegal_char(args->os_errbuf, *s);
1578 if (*s == 'n') // name is always last one
1580 else if (*s == 'r') // skip until next ','
1582 while (*++s && *s != ',')
1588 while (vim_isdigit(*++s))
1591 else if (*s == '!' || *s == 'h' || *s == 'c')
1592 ++s; // no extra chars
1593 else // must have a number
1595 while (vim_isdigit(*++s))
1598 if (!VIM_ISDIGIT(*(s - 1)))
1600 if (args->os_errbuf != NULL)
1602 sprintf(args->os_errbuf,
1603 _(e_missing_number_after_angle_str_angle),
1604 transchar_byte(*(s - 1)));
1605 errmsg = args->os_errbuf;
1616 if (args->os_errbuf != NULL)
1617 errmsg = e_missing_comma;
1623 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
1624 errmsg = e_must_specify_a_value;
1631 * Some terminal option (t_xxx) is changed
1634 did_set_term_option(char_u **varp, int *did_swaptcap UNUSED)
1636 // ":set t_Co=0" and ":set t_Co=1" do ":set t_Co="
1639 int colors = atoi((char *)T_CCO);
1641 // Only reinitialize colors if t_Co value has really changed to
1642 // avoid expensive reload of colorscheme if t_Co is set to the
1643 // same value multiple times.
1644 if (colors != t_colors)
1650 T_CCO = empty_option;
1652 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
1653 if (is_term_win32())
1656 *did_swaptcap = TRUE;
1659 // We now have a different color setup, initialize it again.
1660 init_highlight(TRUE, FALSE);
1667 redraw_later(UPD_CLEAR);
1668 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
1669 // Since t_me has been set, this probably means that the user
1670 // wants to use this as default colors. Need to reset default
1671 // background/foreground colors.
1673 if (!gui.in_use && !gui.starting)
1675 mch_set_normal_colors();
1678 if (varp == &T_BE && termcap_active)
1680 MAY_WANT_TO_LOG_THIS;
1683 // When clearing t_BE we assume the user no longer wants
1684 // bracketed paste, thus disable it by writing t_BD.
1691 #if defined(FEAT_LINEBREAK) || defined(PROTO)
1693 * The 'showbreak' option is changed.
1696 did_set_showbreak(optset_T *args)
1700 for (s = args->os_varp; *s; )
1702 if (ptr2cells(s) != 1)
1703 return e_showbreak_contains_unprintable_or_wide_character;
1711 #if defined(CURSOR_SHAPE) || defined(PROTO)
1713 * The 'guicursor' option is changed.
1716 did_set_guicursor(optset_T *args UNUSED)
1718 return parse_shape_opt(SHAPE_CURSOR);
1722 #if defined(FEAT_GUI) || defined(PROTO)
1724 * The 'guifont' option is changed.
1727 did_set_guifont(optset_T *args UNUSED)
1730 char *errmsg = NULL;
1735 # if defined(FEAT_GUI_GTK)
1736 // Put up a font dialog and let the user select a new value.
1737 // If this is cancelled go back to the old value but don't
1738 // give an error message.
1739 if (STRCMP(p, "*") == 0)
1741 p = gui_mch_font_dialog(args->os_oldval.string);
1742 free_string_option(p_guifont);
1743 p_guifont = (p != NULL) ? p : vim_strsave(args->os_oldval.string);
1746 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
1748 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
1749 if (STRCMP(p_guifont, "*") == 0)
1751 // Dialog was cancelled: Keep the old value without giving
1752 // an error message.
1753 free_string_option(p_guifont);
1754 p_guifont = vim_strsave(args->os_oldval.string);
1758 errmsg = e_invalid_fonts;
1765 # if defined(FEAT_XFONTSET) || defined(PROTO)
1767 * The 'guifontset' option is changed.
1770 did_set_guifontset(optset_T *args UNUSED)
1772 char *errmsg = NULL;
1774 if (STRCMP(p_guifontset, "*") == 0)
1775 errmsg = e_cant_select_fontset;
1776 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
1777 errmsg = e_invalid_fontset;
1784 * The 'guifontwide' option is changed.
1787 did_set_guifontwide(optset_T *args UNUSED)
1789 char *errmsg = NULL;
1791 if (STRCMP(p_guifontwide, "*") == 0)
1792 errmsg = e_cant_select_wide_font;
1793 else if (gui_get_wide_font() == FAIL)
1794 errmsg = e_invalid_wide_font;
1800 #if defined(FEAT_GUI_GTK) || defined(PROTO)
1802 * The 'guiligatures' option is changed.
1805 did_set_guiligatures(optset_T *args UNUSED)
1807 gui_set_ligatures();
1812 #if defined(FEAT_MOUSESHAPE) || defined(PROTO)
1814 did_set_mouseshape(optset_T *args UNUSED)
1816 char *errmsg = NULL;
1818 errmsg = parse_shape_opt(SHAPE_MOUSE);
1819 update_mouseshape(-1);
1826 * The 'titlestring' or the 'iconstring' option is changed.
1829 did_set_titleiconstring(optset_T *args UNUSED, int flagval UNUSED)
1832 // NULL => statusline syntax
1833 if (vim_strchr(args->os_varp, '%')
1834 && check_stl_option(args->os_varp) == NULL)
1835 stl_syntax |= flagval;
1837 stl_syntax &= ~flagval;
1845 * The 'titlestring' option is changed.
1848 did_set_titlestring(optset_T *args)
1853 flagval = STL_IN_TITLE;
1855 return did_set_titleiconstring(args, flagval);
1859 * The 'iconstring' option is changed.
1862 did_set_iconstring(optset_T *args)
1867 flagval = STL_IN_ICON;
1870 return did_set_titleiconstring(args, flagval);
1874 * An option which is a list of flags is set. Valid values are in 'flags'.
1877 did_set_option_listflag(char_u *varp, char_u *flags, char *errbuf)
1881 for (s = varp; *s; ++s)
1882 if (vim_strchr(flags, *s) == NULL)
1883 return illegal_char(errbuf, *s);
1888 #if defined(FEAT_GUI) || defined(PROTO)
1890 * The 'guioptions' option is changed.
1893 did_set_guioptions(optset_T *args)
1897 errmsg = did_set_option_listflag(args->os_varp, (char_u *)GO_ALL,
1902 gui_init_which_components(args->os_oldval.string);
1907 #if defined(FEAT_GUI_TABLINE)
1909 * The 'guitablabel' option is changed.
1912 did_set_guitablabel(optset_T *args UNUSED)
1914 redraw_tabline = TRUE;
1919 #if defined(UNIX) || defined(VMS) || defined(PROTO)
1921 * The 'ttymouse' option is changed.
1924 did_set_ttymouse(optset_T *args UNUSED)
1926 char *errmsg = NULL;
1928 // Switch the mouse off before changing the escape sequences used for
1930 mch_setmouse(FALSE);
1931 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
1932 errmsg = e_invalid_argument;
1934 check_mouse_termcode();
1936 setmouse(); // may switch it on again
1943 * The 'selection' option is changed.
1946 did_set_selection(optset_T *args UNUSED)
1949 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
1950 return e_invalid_argument;
1955 #if defined(FEAT_BROWSE) || defined(PROTO)
1957 * The 'browsedir' option is changed.
1960 did_set_browsedir(optset_T *args UNUSED)
1962 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
1963 && !mch_isdir(p_bsdir))
1964 return e_invalid_argument;
1971 * The 'keymodel' option is changed.
1974 did_set_keymodel(optset_T *args UNUSED)
1976 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
1977 return e_invalid_argument;
1979 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
1980 km_startsel = (vim_strchr(p_km, 'a') != NULL);
1985 * The 'keyprotocol' option is changed.
1988 did_set_keyprotocol(optset_T *args UNUSED)
1990 if (match_keyprotocol(NULL) == KEYPROTOCOL_FAIL)
1991 return e_invalid_argument;
1997 * The 'mousemodel' option is changed.
2000 did_set_mousemodel(optset_T *args UNUSED)
2002 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
2003 return e_invalid_argument;
2004 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
2005 else if (*p_mousem != *oldval)
2006 // Changed from "extend" to "popup" or "popup_setpos" or vv: need
2007 // to create or delete the popup menus.
2008 gui_motif_update_mousemodel(root_menu);
2015 * The 'debug' option is changed.
2018 did_set_debug(optset_T *args UNUSED)
2020 return did_set_opt_strings(p_debug, p_debug_values, TRUE);
2024 * The 'display' option is changed.
2027 did_set_display(optset_T *args UNUSED)
2029 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
2030 return e_invalid_argument;
2032 (void)init_chartab();
2036 #if defined(FEAT_SPELL) || defined(PROTO)
2038 * The 'spellfile' option is changed.
2041 did_set_spellfile(optset_T *args)
2043 if (!valid_spellfile(args->os_varp))
2044 return e_invalid_argument;
2046 // If there is a window for this buffer in which 'spell' is set load the
2048 return did_set_spell_option(TRUE);
2052 * The 'spell' option is changed.
2055 did_set_spelllang(optset_T *args)
2057 if (!valid_spelllang(args->os_varp))
2058 return e_invalid_argument;
2060 // If there is a window for this buffer in which 'spell' is set load the
2062 return did_set_spell_option(FALSE);
2066 * The 'spellcapcheck' option is changed.
2069 did_set_spellcapcheck(optset_T *args UNUSED)
2071 // compile the regexp program.
2072 return compile_cap_prog(curwin->w_s);
2076 * The 'spelloptions' option is changed.
2079 did_set_spelloptions(optset_T *args)
2081 if (*args->os_varp != NUL && STRCMP("camel", args->os_varp) != 0)
2082 return e_invalid_argument;
2088 * The 'spellsuggest' option is changed.
2091 did_set_spellsuggest(optset_T *args UNUSED)
2093 if (spell_check_sps() != OK)
2094 return e_invalid_argument;
2100 * The 'mkspellmem' option is changed.
2103 did_set_mkspellmem(optset_T *args UNUSED)
2105 if (spell_check_msm() != OK)
2106 return e_invalid_argument;
2113 * The 'nrformats' option is changed.
2116 did_set_nrformats(optset_T *args)
2118 return did_set_opt_strings(args->os_varp, p_nf_values, TRUE);
2122 * The 'buftype' option is changed.
2125 did_set_buftype(optset_T *args UNUSED)
2127 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
2128 return e_invalid_argument;
2130 if (curwin->w_status_height)
2132 curwin->w_redr_status = TRUE;
2133 redraw_later(UPD_VALID);
2135 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
2141 #if defined(FEAT_STL_OPT) || defined(PROTO)
2143 * The 'statusline' or the 'tabline' or the 'rulerformat' option is changed.
2144 * "rulerformat" is TRUE if the 'rulerformat' option is changed.
2147 did_set_statustabline_rulerformat(optset_T *args, int rulerformat)
2150 char *errmsg = NULL;
2153 if (rulerformat) // reset ru_wid first
2156 if (rulerformat && *s == '%')
2158 // set ru_wid if 'ruf' starts with "%99("
2159 if (*++s == '-') // ignore a '-'
2161 wid = getdigits(&s);
2162 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
2165 errmsg = check_stl_option(p_ruf);
2167 // check 'statusline' or 'tabline' only if it doesn't start with "%!"
2168 else if (rulerformat || s[0] != '%' || s[1] != '!')
2169 errmsg = check_stl_option(s);
2170 if (rulerformat && errmsg == NULL)
2177 * The 'statusline' option is changed.
2180 did_set_statusline(optset_T *args)
2182 return did_set_statustabline_rulerformat(args, FALSE);
2186 * The 'tabline' option is changed.
2189 did_set_tabline(optset_T *args)
2191 return did_set_statustabline_rulerformat(args, FALSE);
2196 * The 'rulerformat' option is changed.
2199 did_set_rulerformat(optset_T *args)
2201 return did_set_statustabline_rulerformat(args, TRUE);
2206 * The 'complete' option is changed.
2209 did_set_complete(optset_T *args)
2213 // check if it is a valid value for 'complete' -- Acevedo
2214 for (s = args->os_varp; *s;)
2216 while (*s == ',' || *s == ' ')
2220 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
2221 return illegal_char(args->os_errbuf, *s);
2222 if (*++s != NUL && *s != ',' && *s != ' ')
2224 if (s[-1] == 'k' || s[-1] == 's')
2226 // skip optional filename after 'k' and 's'
2227 while (*s && *s != ',' && *s != ' ')
2229 if (*s == '\\' && s[1] != NUL)
2236 if (args->os_errbuf != NULL)
2238 sprintf((char *)args->os_errbuf,
2239 _(e_illegal_character_after_chr), *--s);
2240 return args->os_errbuf;
2251 * The 'completeopt' option is changed.
2254 did_set_completeopt(optset_T *args UNUSED)
2256 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
2257 return e_invalid_argument;
2259 completeopt_was_set();
2263 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
2265 * The 'completeslash' option is changed.
2268 did_set_completeslash(optset_T *args UNUSED)
2270 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
2271 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
2272 return e_invalid_argument;
2278 #if defined(FEAT_SIGNS) || defined(PROTO)
2280 * The 'signcolumn' option is changed.
2283 did_set_signcolumn(optset_T *args)
2285 if (check_opt_strings(args->os_varp, p_scl_values, FALSE) != OK)
2286 return e_invalid_argument;
2287 // When changing the 'signcolumn' to or from 'number', recompute the
2288 // width of the number column if 'number' or 'relativenumber' is set.
2289 if (((*args->os_oldval.string == 'n' && args->os_oldval.string[1] == 'u')
2290 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
2291 && (curwin->w_p_nu || curwin->w_p_rnu))
2292 curwin->w_nrwidth_line_count = 0;
2298 #if (defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)) || defined(PROTO)
2300 * The 'toolbar' option is changed.
2303 did_set_toolbar(optset_T *args UNUSED)
2305 if (opt_strings_flags(p_toolbar, p_toolbar_values,
2306 &toolbar_flags, TRUE) != OK)
2307 return e_invalid_argument;
2310 gui_mch_show_toolbar((toolbar_flags &
2311 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
2316 #if (defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)) || defined(PROTO)
2318 * The 'toolbariconsize' option is changed. GTK+ 2 only.
2321 did_set_toolbariconsize(optset_T *args UNUSED)
2323 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
2324 return e_invalid_argument;
2327 gui_mch_show_toolbar((toolbar_flags &
2328 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
2334 * The 'pastetoggle' option is changed.
2337 did_set_pastetoggle(optset_T *args UNUSED)
2341 // translate key codes like in a mapping
2344 (void)replace_termcodes(p_pt, &p,
2345 REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
2348 free_string_option(p_pt);
2357 * The 'backspace' option is changed.
2360 did_set_backspace(optset_T *args UNUSED)
2362 if (VIM_ISDIGIT(*p_bs))
2364 if (*p_bs > '3' || p_bs[1] != NUL)
2365 return e_invalid_argument;
2367 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
2368 return e_invalid_argument;
2374 * The 'bufhidden' option is changed.
2377 did_set_bufhidden(optset_T *args UNUSED)
2379 return did_set_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE);
2383 * The 'tagcase' option is changed.
2386 did_set_tagcase(optset_T *args)
2388 unsigned int *flags;
2391 if (args->os_flags & OPT_LOCAL)
2394 flags = &curbuf->b_tc_flags;
2402 if ((args->os_flags & OPT_LOCAL) && *p == NUL)
2403 // make the local value empty: use the global value
2406 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
2407 return e_invalid_argument;
2412 #if defined(FEAT_DIFF) || defined(PROTO)
2414 * The 'diffopt' option is changed.
2417 did_set_diffopt(optset_T *args UNUSED)
2419 if (diffopt_changed() == FAIL)
2420 return e_invalid_argument;
2426 #if defined(FEAT_FOLDING) || defined(PROTO)
2428 * The 'foldmethod' option is changed.
2431 did_set_foldmethod(optset_T *args)
2433 if (check_opt_strings(args->os_varp, p_fdm_values, FALSE) != OK
2434 || *curwin->w_p_fdm == NUL)
2435 return e_invalid_argument;
2437 foldUpdateAll(curwin);
2438 if (foldmethodIsDiff(curwin))
2444 * The 'foldmarker' option is changed.
2447 did_set_foldmarker(optset_T *args)
2451 p = vim_strchr(args->os_varp, ',');
2453 return e_comma_required;
2454 else if (p == args->os_varp || p[1] == NUL)
2455 return e_invalid_argument;
2456 else if (foldmethodIsMarker(curwin))
2457 foldUpdateAll(curwin);
2463 * The 'commentstring' option is changed.
2466 did_set_commentstring(optset_T *args)
2468 if (*args->os_varp != NUL && strstr((char *)args->os_varp, "%s") == NULL)
2469 return e_commentstring_must_be_empty_or_contain_str;
2475 * The 'foldignore' option is changed.
2478 did_set_foldignore(optset_T *args UNUSED)
2480 if (foldmethodIsIndent(curwin))
2481 foldUpdateAll(curwin);
2486 * The 'foldclose' option is changed.
2489 did_set_foldclose(optset_T *args UNUSED)
2491 return did_set_opt_strings(p_fcl, p_fcl_values, TRUE);
2495 * The 'foldopen' option is changed.
2498 did_set_foldopen(optset_T *args UNUSED)
2500 return did_set_opt_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
2505 * The 'virtualedit' option is changed.
2508 did_set_virtualedit(optset_T *args)
2511 unsigned int *flags = &ve_flags;
2513 if (args->os_flags & OPT_LOCAL)
2515 ve = curwin->w_p_ve;
2516 flags = &curwin->w_ve_flags;
2519 if ((args->os_flags & OPT_LOCAL) && *ve == NUL)
2520 // make the local value empty: use the global value
2524 if (opt_strings_flags(ve, p_ve_values, flags, TRUE) != OK)
2525 return e_invalid_argument;
2526 else if (STRCMP(ve, args->os_oldval.string) != 0)
2528 // Recompute cursor position in case the new 've' setting
2529 // changes something.
2531 coladvance(curwin->w_virtcol);
2538 #if (defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)) || defined(PROTO)
2540 * The 'cscopequickfix' option is changed.
2543 did_set_cscopequickfix(optset_T *args UNUSED)
2553 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
2555 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
2556 || (p[2] != NUL && p[2] != ','))
2557 return e_invalid_argument;
2558 else if (p[2] == NUL)
2569 * The 'cinoptions' option is changed.
2572 did_set_cinoptions(optset_T *args UNUSED)
2574 // TODO: recognize errors
2581 * The 'lispoptions' option is changed.
2584 did_set_lispoptions(optset_T *args)
2586 if (*args->os_varp != NUL
2587 && STRCMP(args->os_varp, "expr:0") != 0
2588 && STRCMP(args->os_varp, "expr:1") != 0)
2589 return e_invalid_argument;
2594 #if defined(FEAT_RENDER_OPTIONS) || defined(PROTO)
2596 * The 'renderoptions' option is changed.
2599 did_set_renderoptions(optset_T *args UNUSED)
2601 if (!gui_mch_set_rendering_options(p_rop))
2602 return e_invalid_argument;
2608 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
2610 * The 'rightleftcmd' option is changed.
2613 did_set_rightleftcmd(optset_T *args)
2615 // Currently only "search" is a supported value.
2616 if (*args->os_varp != NUL && STRCMP(args->os_varp, "search") != 0)
2617 return e_invalid_argument;
2624 * The 'filetype' or the 'syntax' option is changed.
2627 did_set_filetype_or_syntax(optset_T *args)
2629 if (!valid_filetype(args->os_varp))
2630 return e_invalid_argument;
2632 args->os_value_changed =
2633 STRCMP(args->os_oldval.string, args->os_varp) != 0;
2635 // Since we check the value, there is no need to set P_INSECURE,
2636 // even when the value comes from a modeline.
2637 args->os_value_checked = TRUE;
2642 #if defined(FEAT_TERMINAL) || defined(PROTO)
2644 * The 'termwinkey' option is changed.
2647 did_set_termwinkey(optset_T *args UNUSED)
2649 if (*curwin->w_p_twk != NUL
2650 && string_to_key(curwin->w_p_twk, TRUE) == 0)
2651 return e_invalid_argument;
2657 * The 'termwinsize' option is changed.
2660 did_set_termwinsize(optset_T *args UNUSED)
2664 if (*curwin->w_p_tws == NUL)
2667 p = skipdigits(curwin->w_p_tws);
2668 if (p == curwin->w_p_tws
2669 || (*p != 'x' && *p != '*')
2670 || *skipdigits(p + 1) != NUL)
2671 return e_invalid_argument;
2676 # if defined(MSWIN) || defined(PROTO)
2678 * The 'termwintype' option is changed.
2681 did_set_termwintype(optset_T *args UNUSED)
2683 return did_set_opt_strings(p_twt, p_twt_values, FALSE);
2688 #if defined(FEAT_VARTABS) || defined(PROTO)
2690 * The 'varsofttabstop' option is changed.
2693 did_set_varsofttabstop(optset_T *args)
2697 if (!(args->os_varp[0]) || (args->os_varp[0] == '0' && !(args->os_varp[1])))
2699 if (curbuf->b_p_vsts_array)
2701 vim_free(curbuf->b_p_vsts_array);
2702 curbuf->b_p_vsts_array = 0;
2707 for (cp = args->os_varp; *cp; ++cp)
2709 if (vim_isdigit(*cp))
2711 if (*cp == ',' && cp > args->os_varp && *(cp-1) != ',')
2713 return e_invalid_argument;
2716 int *oldarray = curbuf->b_p_vsts_array;
2717 if (tabstop_set(args->os_varp, &(curbuf->b_p_vsts_array)) == OK)
2723 return e_invalid_argument;
2730 * The 'vartabstop' option is changed.
2733 did_set_vartabstop(optset_T *args)
2737 if (!(args->os_varp[0]) || (args->os_varp[0] == '0' && !(args->os_varp[1])))
2739 if (curbuf->b_p_vts_array)
2741 vim_free(curbuf->b_p_vts_array);
2742 curbuf->b_p_vts_array = NULL;
2747 for (cp = args->os_varp; *cp; ++cp)
2749 if (vim_isdigit(*cp))
2751 if (*cp == ',' && cp > args->os_varp && *(cp-1) != ',')
2753 return e_invalid_argument;
2756 int *oldarray = curbuf->b_p_vts_array;
2758 if (tabstop_set(args->os_varp, &(curbuf->b_p_vts_array)) == OK)
2761 # ifdef FEAT_FOLDING
2762 if (foldmethodIsIndent(curwin))
2763 foldUpdateAll(curwin);
2767 return e_invalid_argument;
2774 #if defined(FEAT_PROP_POPUP) || defined(PROTO)
2776 * The 'previewpopup' option is changed.
2779 did_set_previewpopup(optset_T *args UNUSED)
2781 if (parse_previewpopup(NULL) == FAIL)
2782 return e_invalid_argument;
2787 # if defined(FEAT_QUICKFIX) || defined(PROTO)
2789 * The 'completepopup' option is changed.
2792 did_set_completepopup(optset_T *args UNUSED)
2794 if (parse_completepopup(NULL) == FAIL)
2795 return e_invalid_argument;
2803 #if defined(FEAT_EVAL) || defined(PROTO)
2805 * Returns TRUE if the option pointed by "varp" or "gvarp" is one of the
2806 * '*expr' options: 'balloonexpr', 'diffexpr', 'foldexpr', 'foldtext',
2807 * 'formatexpr', 'includeexpr', 'indentexpr', 'patchexpr', 'printexpr' or
2811 is_expr_option(char_u **varp, char_u **gvarp)
2815 varp == &p_bexpr || // 'balloonexpr'
2818 varp == &p_dex || // 'diffexpr'
2820 # ifdef FEAT_FOLDING
2821 gvarp == &curwin->w_allbuf_opt.wo_fde || // 'foldexpr'
2822 gvarp == &curwin->w_allbuf_opt.wo_fdt || // 'foldtext'
2824 gvarp == &p_fex || // 'formatexpr'
2825 # ifdef FEAT_FIND_ID
2826 gvarp == &p_inex || // 'includeexpr'
2828 gvarp == &p_inde || // 'indentexpr'
2830 varp == &p_pex || // 'patchexpr'
2832 # ifdef FEAT_POSTSCRIPT
2833 varp == &p_pexpr || // 'printexpr'
2835 varp == &p_ccv); // 'charconvert'
2839 * One of the '*expr' options is changed: 'balloonexpr', 'diffexpr',
2840 * 'foldexpr', 'foldtext', 'formatexpr', 'includeexpr', 'indentexpr',
2841 * 'patchexpr', 'printexpr' and 'charconvert'.
2845 did_set_optexpr(optset_T *args)
2847 // If the option value starts with <SID> or s:, then replace that with
2848 // the script identifier.
2849 char_u *name = get_scriptlocal_funcname(args->os_varp);
2852 free_string_option(args->os_varp);
2853 args->os_varp = name;
2859 # if defined(FEAT_FOLDING) || defined(PROTO)
2861 * The 'foldexpr' option is changed.
2864 did_set_foldexpr(optset_T *args)
2866 (void)did_set_optexpr(args);
2867 if (foldmethodIsExpr(curwin))
2868 foldUpdateAll(curwin);
2874 #if defined(FEAT_CONCEAL) || defined(PROTO)
2876 * The 'concealcursor' option is changed.
2879 did_set_concealcursor(optset_T *args)
2881 return did_set_option_listflag(args->os_varp, (char_u *)COCU_ALL,
2887 * The 'cpoptions' option is changed.
2890 did_set_cpoptions(optset_T *args)
2892 return did_set_option_listflag(args->os_varp, (char_u *)CPO_ALL,
2897 * The 'formatoptions' option is changed.
2900 did_set_formatoptions(optset_T *args)
2902 return did_set_option_listflag(args->os_varp, (char_u *)FO_ALL,
2907 * The 'mouse' option is changed.
2910 did_set_mouse(optset_T *args)
2912 return did_set_option_listflag(args->os_varp, (char_u *)MOUSE_ALL,
2917 * The 'shortmess' option is changed.
2920 did_set_shortmess(optset_T *args)
2922 return did_set_option_listflag(args->os_varp, (char_u *)SHM_ALL,
2927 * The 'whichwrap' option is changed.
2930 did_set_whichwrap(optset_T *args)
2932 return did_set_option_listflag(args->os_varp, (char_u *)WW_ALL,
2938 * When the 'syntax' option is set, load the syntax of that name.
2941 do_syntax_autocmd(int value_changed)
2943 static int syn_recursive = 0;
2946 // Only pass TRUE for "force" when the value changed or not used
2947 // recursively, to avoid endless recurrence.
2948 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
2949 value_changed || syn_recursive == 1, curbuf);
2950 curbuf->b_flags |= BF_SYN_SET;
2956 * When the 'filetype' option is set, trigger the FileType autocommand.
2959 do_filetype_autocmd(char_u **varp, int opt_flags, int value_changed)
2961 // Skip this when called from a modeline and the filetype was already set
2963 if ((opt_flags & OPT_MODELINE) && !value_changed)
2966 static int ft_recursive = 0;
2967 int secure_save = secure;
2969 // Reset the secure flag, since the value of 'filetype' has
2970 // been checked to be safe.
2974 did_filetype = TRUE;
2975 // Only pass TRUE for "force" when the value changed or not
2976 // used recursively, to avoid endless recurrence.
2977 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
2978 value_changed || ft_recursive == 1, curbuf);
2980 // Just in case the old "curbuf" is now invalid.
2981 if (varp != &(curbuf->b_p_ft))
2984 secure = secure_save;
2989 * When the 'spelllang' option is set, source the spell/LANG.vim file in
2993 do_spelllang_source(void)
2997 char_u *q = curwin->w_s->b_p_spl;
2999 // Skip the first name if it is "cjk".
3000 if (STRNCMP(q, "cjk,", 4) == 0)
3003 // They could set 'spellcapcheck' depending on the language. Use the first
3004 // name in 'spelllang' up to '_region' or '.encoding'.
3005 for (p = q; *p != NUL; ++p)
3006 if (!ASCII_ISALNUM(*p) && *p != '-')
3010 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
3012 source_runtime(fname, DIP_ALL);
3018 * Handle string options that need some action to perform when changed.
3019 * The new value must be allocated.
3020 * Returns NULL for success, or an untranslated error message for an error.
3023 did_set_string_option(
3024 int opt_idx, // index in options[] table
3025 char_u **varp, // pointer to the option variable
3026 char_u *oldval, // previous value of the option
3027 char_u *value, // new value of the option
3028 char *errbuf, // buffer for errors, or NULL
3029 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
3030 int *value_checked) // value was checked to be safe, no
3031 // need to set P_INSECURE
3033 char *errmsg = NULL;
3034 int restore_chartab = FALSE;
3036 long_u free_oldval = (get_option_flags(opt_idx) & P_ALLOCED);
3037 int value_changed = FALSE;
3038 int did_swaptcap = FALSE;
3039 opt_did_set_cb_T did_set_cb = get_option_did_set_cb(opt_idx);
3041 // Get the global option to compare with, otherwise we would have to check
3042 // two values for all local options.
3043 gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
3045 // Disallow changing some options from secure mode
3050 ) && (get_option_flags(opt_idx) & P_SECURE))
3051 errmsg = e_not_allowed_here;
3052 // Check for a "normal" directory or file name in some options.
3053 else if (check_illegal_path_names(opt_idx, varp))
3054 errmsg = e_invalid_argument;
3055 else if (did_set_cb != NULL)
3059 args.os_varp = *varp;
3060 args.os_flags = opt_flags;
3061 args.os_oldval.string = oldval;
3062 args.os_newval.string = value;
3063 args.os_value_checked = FALSE;
3064 args.os_value_changed = FALSE;
3065 args.os_restore_chartab = FALSE;
3066 args.os_errbuf = errbuf;
3067 // Invoke the option specific callback function to validate and apply
3068 // the new option value.
3069 errmsg = did_set_cb(&args);
3072 // The '*expr' option (e.g. diffexpr, foldexpr, etc.), callback
3073 // functions may modify '*varp'.
3074 if (errmsg == NULL && is_expr_option(varp, gvarp))
3075 *varp = args.os_varp;
3077 // The 'filetype' and 'syntax' option callback functions may change
3078 // the os_value_changed field.
3079 value_changed = args.os_value_changed;
3080 // The 'keymap', 'filetype' and 'syntax' option callback functions
3081 // may change the os_value_checked field.
3082 *value_checked = args.os_value_checked;
3083 // The 'isident', 'iskeyword', 'isprint' and 'isfname' options may
3084 // change the character table. On failure, this needs to be restored.
3085 restore_chartab = args.os_restore_chartab;
3087 else if (varp == &T_NAME) // 'term'
3088 errmsg = did_set_term(&opt_idx, &free_oldval);
3089 else if ( varp == &p_enc // 'encoding'
3090 || gvarp == &p_fenc // 'fileencoding'
3091 || varp == &p_tenc // 'termencoding'
3092 || gvarp == &p_menc) // 'makeencoding'
3093 errmsg = did_set_encoding(varp, gvarp, opt_flags);
3094 else if ( varp == &p_lcs // global 'listchars'
3095 || varp == &p_fcs) // global 'fillchars'
3096 errmsg = did_set_global_listfillchars(varp, opt_flags);
3097 else if (varp == &curwin->w_p_lcs) // local 'listchars'
3098 errmsg = set_chars_option(curwin, varp, TRUE);
3099 else if (varp == &curwin->w_p_fcs) // local 'fillchars'
3100 errmsg = set_chars_option(curwin, varp, TRUE);
3102 else if (istermoption_idx(opt_idx) && full_screen)
3103 did_set_term_option(varp, &did_swaptcap);
3105 // If an error is detected, restore the previous value.
3108 free_string_option(*varp);
3110 // When resetting some values, need to act on it.
3111 if (restore_chartab)
3112 (void)init_chartab();
3114 (void)highlight_changed();
3119 // Remember where the option was set.
3120 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
3122 // Free string options that are in allocated memory.
3123 // Use "free_oldval", because recursiveness may change the flags under
3124 // our fingers (esp. init_highlight()).
3126 free_string_option(oldval);
3127 set_option_flag(opt_idx, P_ALLOCED);
3129 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
3130 && is_global_local_option(opt_idx))
3132 // global option with local value set to use global value; free
3133 // the local value and make it empty
3134 char_u *p = get_option_varp_scope(opt_idx, OPT_LOCAL);
3135 free_string_option(*(char_u **)p);
3136 *(char_u **)p = empty_option;
3139 // May set global value for local option.
3140 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
3141 set_string_option_global(opt_idx, varp);
3143 // Trigger the autocommand only after setting the flags.
3145 if (varp == &(curbuf->b_p_syn))
3146 do_syntax_autocmd(value_changed);
3148 else if (varp == &(curbuf->b_p_ft))
3149 do_filetype_autocmd(varp, opt_flags, value_changed);
3151 if (varp == &(curwin->w_s->b_p_spl))
3152 do_spelllang_source();
3156 if (varp == &p_mouse)
3158 if (*p_mouse == NUL)
3159 mch_setmouse(FALSE); // switch mouse off
3161 setmouse(); // in case 'mouse' changed
3164 #if defined(FEAT_LUA) || defined(PROTO)
3166 update_package_paths_in_lua();
3169 #if defined(FEAT_LINEBREAK)
3170 // Changing Formatlistpattern when briopt includes the list setting:
3172 if ((varp == &p_flp || varp == &(curbuf->b_p_flp))
3173 && curwin->w_briopt_list)
3174 redraw_all_later(UPD_NOT_VALID);
3177 if (curwin->w_curswant != MAXCOL
3178 && (get_option_flags(opt_idx) & (P_CURSWANT | P_RALL)) != 0)
3179 curwin->w_set_curswant = TRUE;
3181 if ((opt_flags & OPT_NO_REDRAW) == 0)
3184 // set when changing an option that only requires a redraw in the GUI
3185 int redraw_gui_only = FALSE;
3187 if (varp == &p_go // 'guioptions'
3188 || varp == &p_guifont // 'guifont'
3189 # ifdef FEAT_GUI_TABLINE
3190 || varp == &p_gtl // 'guitablabel'
3191 || varp == &p_gtt // 'guitabtooltip'
3193 # ifdef FEAT_XFONTSET
3194 || varp == &p_guifontset // 'guifontset'
3196 || varp == &p_guifontwide // 'guifontwide'
3197 # ifdef FEAT_GUI_GTK
3198 || varp == &p_guiligatures // 'guiligatures'
3201 redraw_gui_only = TRUE;
3203 // check redraw when it's not a GUI option or the GUI is active.
3204 if (!redraw_gui_only || gui.in_use)
3206 check_redraw(get_option_flags(opt_idx));
3209 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
3212 set_termname((char_u *)"win32");
3213 init_highlight(TRUE, FALSE);
3221 * Check an option that can be a range of string values.
3223 * Return OK for correct value, FAIL otherwise.
3224 * Empty is always OK.
3230 int list) // when TRUE: accept a list of values
3232 return opt_strings_flags(val, values, NULL, list);
3236 * Handle an option that can be a range of string values.
3237 * Set a flag in "*flagp" for each string present.
3239 * Return OK for correct value, FAIL otherwise.
3240 * Empty is always OK.
3244 char_u *val, // new value
3245 char **values, // array of valid string values
3247 int list) // when TRUE: accept a list of values
3251 unsigned new_flags = 0;
3257 if (values[i] == NULL) // val not found in values[]
3260 len = (int)STRLEN(values[i]);
3261 if (STRNCMP(values[i], val, len) == 0
3262 && ((list && val[len] == ',') || val[len] == NUL))
3264 val += len + (val[len] == ',');
3265 new_flags |= (1 << i);
3266 break; // check next item in val list
3277 * return OK if "p" is a valid fileformat name, FAIL otherwise.
3280 check_ff_value(char_u *p)
3282 return check_opt_strings(p, p_ff_values, FALSE);
3286 * Save the actual shortmess Flags and clear them temporarily to avoid that
3287 * file messages overwrites any output from the following commands.
3289 * Caller must make sure to first call save_clear_shm_value() and then
3290 * restore_shm_value() exactly the same number of times.
3293 save_clear_shm_value(void)
3295 if (STRLEN(p_shm) >= SHM_LEN)
3297 iemsg(e_internal_error_shortmess_too_long);
3301 if (++set_shm_recursive == 1)
3303 STRCPY(shm_buf, p_shm);
3304 set_option_value_give_err((char_u *)"shm", 0L, (char_u *)"", 0);
3309 * Restore the shortmess Flags set from the save_clear_shm_value() function.
3312 restore_shm_value(void)
3314 if (--set_shm_recursive == 0)
3316 set_option_value_give_err((char_u *)"shm", 0L, shm_buf, 0);
3317 vim_memset(shm_buf, 0, SHM_LEN);