blob: 08b9ebcfb45e7047e8891c69029f7ce0b1c1c3b6 [file] [log] [blame]
Bram Moolenaardac13472019-09-16 21:06:21 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
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.
8 */
9
10/*
11 * optionstr.c: Functions related to string options
12 */
13
14#include "vim.h"
15
16static char *(p_ambw_values[]) = {"single", "double", NULL};
17static char *(p_bg_values[]) = {"light", "dark", NULL};
18static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
19static char *(p_bo_values[]) = {"all", "backspace", "cursor", "complete",
20 "copy", "ctrlg", "error", "esc", "ex",
21 "hangul", "insertmode", "lang", "mess",
22 "showmatch", "operator", "register", "shell",
LemonBoy77771d32022-04-13 11:47:25 +010023 "spell", "term", "wildmode", NULL};
Bram Moolenaaraaad9952020-05-31 15:08:59 +020024static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", "unsigned", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020025static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
26#ifdef FEAT_CRYPT
Christian Brabandtf573c6e2021-06-20 14:02:16 +020027static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2",
28 # ifdef FEAT_SODIUM
29 "xchacha20",
30 # endif
31 NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020032#endif
33static char *(p_cmp_values[]) = {"internal", "keepascii", NULL};
34static char *(p_dy_values[]) = {"lastline", "truncate", "uhex", NULL};
35#ifdef FEAT_FOLDING
36static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent",
37 "quickfix", "search", "tag", "insert",
38 "undo", "jump", NULL};
39#endif
40#ifdef FEAT_SESSION
Bram Moolenaar635bd602021-04-16 19:58:22 +020041// Also used for 'viewoptions'! Keep in sync with SSOP_ flags.
Bram Moolenaardac13472019-09-16 21:06:21 +020042static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize",
43 "localoptions", "options", "help", "blank", "globals", "slash", "unix",
Bram Moolenaar635bd602021-04-16 19:58:22 +020044 "sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", "skiprtp",
45 NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020046#endif
Bram Moolenaar539aa6b2019-11-17 18:09:38 +010047// Keep in sync with SWB_ flags in option.h
48static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", "uselast", NULL};
Luuk van Baal13ece2a2022-10-03 15:28:08 +010049static char *(p_spk_values[]) = {"cursor", "screen", "topline", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020050static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL};
51#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
52static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL};
53#endif
54#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
55static char *(p_tbis_values[]) = {"tiny", "small", "medium", "large", "huge", "giant", NULL};
56#endif
Bram Moolenaara1cb1d12019-10-17 23:00:07 +020057#if defined(UNIX) || defined(VMS)
Bram Moolenaardac13472019-09-16 21:06:21 +020058static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL};
59#endif
Gary Johnson53ba05b2021-07-26 22:19:10 +020060static char *(p_ve_values[]) = {"block", "insert", "all", "onemore", "none", "NONE", NULL};
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +000061static char *(p_wop_values[]) = {"fuzzy", "tagfile", "pum", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020062#ifdef FEAT_WAK
63static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
64#endif
65static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
66static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
67static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
68static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
69#ifdef FEAT_BROWSE
70static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
71#endif
72static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
73static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
74static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
75static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
76static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaaraa0489e2020-04-17 19:41:21 +020077static char *(p_bs_values[]) = {"indent", "eol", "start", "nostop", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020078#ifdef FEAT_FOLDING
79static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
80# ifdef FEAT_DIFF
81 "diff",
82# endif
83 NULL};
84static char *(p_fcl_values[]) = {"all", NULL};
85#endif
Bram Moolenaardca7abe2019-10-20 18:17:57 +020086static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "popuphidden", "noinsert", "noselect", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020087#ifdef BACKSLASH_IN_FILENAME
88static char *(p_csl_values[]) = {"slash", "backslash", NULL};
89#endif
90#ifdef FEAT_SIGNS
91static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
92#endif
93#if defined(MSWIN) && defined(FEAT_TERMINAL)
94static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
95#endif
Luuk van Baalba936f62022-12-15 13:15:39 +000096static char *(p_sloc_values[]) = {"last", "statusline", "tabline", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020097
98static int check_opt_strings(char_u *val, char **values, int list);
99static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
100
101/*
102 * After setting various option values: recompute variables that depend on
103 * option values.
104 */
105 void
106didset_string_options(void)
107{
108 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
109 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
110 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
111#ifdef FEAT_SESSION
112 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
113 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
114#endif
115#ifdef FEAT_FOLDING
116 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
117#endif
118 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
119 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
120 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaara1cb1d12019-10-17 23:00:07 +0200121#if defined(UNIX) || defined(VMS)
Bram Moolenaardac13472019-09-16 21:06:21 +0200122 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
123#endif
124#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
125 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
126#endif
127#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
128 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
129#endif
Sean Dewar39c46b42022-05-12 17:44:29 +0100130 (void)opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE);
Bram Moolenaardac13472019-09-16 21:06:21 +0200131}
132
133#if defined(FEAT_EVAL)
134/*
135 * Trigger the OptionSet autocommand.
136 * "opt_idx" is the index of the option being set.
137 * "opt_flags" can be OPT_LOCAL etc.
138 * "oldval" the old value
139 * "oldval_l" the old local value (only non-NULL if global and local value
140 * are set)
141 * "oldval_g" the old global value (only non-NULL if global and local value
142 * are set)
143 * "newval" the new value
144 */
145 void
zeertzjq269aa2b2022-11-28 11:36:50 +0000146trigger_optionset_string(
Bram Moolenaardac13472019-09-16 21:06:21 +0200147 int opt_idx,
148 int opt_flags,
149 char_u *oldval,
150 char_u *oldval_l,
151 char_u *oldval_g,
152 char_u *newval)
153{
154 // Don't do this recursively.
155 if (oldval != NULL && newval != NULL
156 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
157 {
158 char_u buf_type[7];
159
160 sprintf((char *)buf_type, "%s",
161 (opt_flags & OPT_LOCAL) ? "local" : "global");
162 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
163 set_vim_var_string(VV_OPTION_NEW, newval, -1);
164 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
165 if (opt_flags & OPT_LOCAL)
166 {
167 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
168 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
169 }
170 if (opt_flags & OPT_GLOBAL)
171 {
172 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
173 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
174 }
175 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
176 {
177 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
178 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
179 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
180 }
181 if (opt_flags & OPT_MODELINE)
182 {
183 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
184 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
185 }
186 apply_autocmds(EVENT_OPTIONSET,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +0000187 get_option_fullname(opt_idx), NULL, FALSE,
Bram Moolenaardac13472019-09-16 21:06:21 +0200188 NULL);
189 reset_v_option_vars();
190 }
191}
192#endif
193
194 static char *
195illegal_char(char *errbuf, int c)
196{
197 if (errbuf == NULL)
198 return "";
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000199 sprintf((char *)errbuf, _(e_illegal_character_str), (char *)transchar(c));
Bram Moolenaardac13472019-09-16 21:06:21 +0200200 return errbuf;
201}
202
203/*
204 * Check string options in a buffer for NULL value.
205 */
206 void
207check_buf_options(buf_T *buf)
208{
209 check_string_option(&buf->b_p_bh);
210 check_string_option(&buf->b_p_bt);
211 check_string_option(&buf->b_p_fenc);
212 check_string_option(&buf->b_p_ff);
213#ifdef FEAT_FIND_ID
214 check_string_option(&buf->b_p_def);
215 check_string_option(&buf->b_p_inc);
216# ifdef FEAT_EVAL
217 check_string_option(&buf->b_p_inex);
218# endif
219#endif
Bram Moolenaar8e145b82022-05-21 20:17:31 +0100220#if defined(FEAT_EVAL)
Bram Moolenaardac13472019-09-16 21:06:21 +0200221 check_string_option(&buf->b_p_inde);
222 check_string_option(&buf->b_p_indk);
223#endif
224#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
225 check_string_option(&buf->b_p_bexpr);
226#endif
227#if defined(FEAT_CRYPT)
228 check_string_option(&buf->b_p_cm);
229#endif
230 check_string_option(&buf->b_p_fp);
231#if defined(FEAT_EVAL)
232 check_string_option(&buf->b_p_fex);
233#endif
234#ifdef FEAT_CRYPT
235 check_string_option(&buf->b_p_key);
236#endif
237 check_string_option(&buf->b_p_kp);
238 check_string_option(&buf->b_p_mps);
239 check_string_option(&buf->b_p_fo);
240 check_string_option(&buf->b_p_flp);
241 check_string_option(&buf->b_p_isk);
Bram Moolenaardac13472019-09-16 21:06:21 +0200242 check_string_option(&buf->b_p_com);
Bram Moolenaardac13472019-09-16 21:06:21 +0200243#ifdef FEAT_FOLDING
244 check_string_option(&buf->b_p_cms);
245#endif
246 check_string_option(&buf->b_p_nf);
Bram Moolenaardac13472019-09-16 21:06:21 +0200247 check_string_option(&buf->b_p_qe);
Bram Moolenaardac13472019-09-16 21:06:21 +0200248#ifdef FEAT_SYN_HL
249 check_string_option(&buf->b_p_syn);
250 check_string_option(&buf->b_s.b_syn_isk);
251#endif
252#ifdef FEAT_SPELL
253 check_string_option(&buf->b_s.b_p_spc);
254 check_string_option(&buf->b_s.b_p_spf);
255 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar362b44b2020-06-10 21:47:00 +0200256 check_string_option(&buf->b_s.b_p_spo);
Bram Moolenaardac13472019-09-16 21:06:21 +0200257#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200258 check_string_option(&buf->b_p_sua);
Bram Moolenaardac13472019-09-16 21:06:21 +0200259 check_string_option(&buf->b_p_cink);
260 check_string_option(&buf->b_p_cino);
Tom Praschan3506cf32022-04-07 12:39:08 +0100261 check_string_option(&buf->b_p_cinsd);
Bram Moolenaardac13472019-09-16 21:06:21 +0200262 parse_cino(buf);
Bram Moolenaar49846fb2022-10-15 16:05:33 +0100263 check_string_option(&buf->b_p_lop);
Bram Moolenaardac13472019-09-16 21:06:21 +0200264 check_string_option(&buf->b_p_ft);
Bram Moolenaardac13472019-09-16 21:06:21 +0200265 check_string_option(&buf->b_p_cinw);
Bram Moolenaardac13472019-09-16 21:06:21 +0200266 check_string_option(&buf->b_p_cpt);
267#ifdef FEAT_COMPL_FUNC
268 check_string_option(&buf->b_p_cfu);
269 check_string_option(&buf->b_p_ofu);
Bram Moolenaard4c4bfa2021-10-16 21:14:11 +0100270 check_string_option(&buf->b_p_tsrfu);
Bram Moolenaardac13472019-09-16 21:06:21 +0200271#endif
272#ifdef FEAT_EVAL
273 check_string_option(&buf->b_p_tfu);
274#endif
275#ifdef FEAT_KEYMAP
276 check_string_option(&buf->b_p_keymap);
277#endif
278#ifdef FEAT_QUICKFIX
279 check_string_option(&buf->b_p_gp);
280 check_string_option(&buf->b_p_mp);
281 check_string_option(&buf->b_p_efm);
282#endif
283 check_string_option(&buf->b_p_ep);
284 check_string_option(&buf->b_p_path);
285 check_string_option(&buf->b_p_tags);
286 check_string_option(&buf->b_p_tc);
287 check_string_option(&buf->b_p_dict);
288 check_string_option(&buf->b_p_tsr);
Bram Moolenaardac13472019-09-16 21:06:21 +0200289 check_string_option(&buf->b_p_lw);
Bram Moolenaardac13472019-09-16 21:06:21 +0200290 check_string_option(&buf->b_p_bkc);
291 check_string_option(&buf->b_p_menc);
292#ifdef FEAT_VARTABS
293 check_string_option(&buf->b_p_vsts);
294 check_string_option(&buf->b_p_vts);
295#endif
296}
297
298/*
299 * Free the string allocated for an option.
300 * Checks for the string being empty_option. This may happen if we're out of
301 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
302 * check_options().
303 * Does NOT check for P_ALLOCED flag!
304 */
305 void
306free_string_option(char_u *p)
307{
308 if (p != empty_option)
309 vim_free(p);
310}
311
312 void
313clear_string_option(char_u **pp)
314{
315 if (*pp != empty_option)
316 vim_free(*pp);
317 *pp = empty_option;
318}
319
320 void
321check_string_option(char_u **pp)
322{
323 if (*pp == NULL)
324 *pp = empty_option;
325}
326
327/*
328 * Set global value for string option when it's a local option.
329 */
330 static void
331set_string_option_global(
332 int opt_idx, // option index
333 char_u **varp) // pointer to option variable
334{
335 char_u **p, *s;
336
337 // the global value is always allocated
338 if (is_window_local_option(opt_idx))
339 p = (char_u **)GLOBAL_WO(varp);
340 else
341 p = (char_u **)get_option_var(opt_idx);
342 if (!is_global_option(opt_idx)
343 && p != varp
344 && (s = vim_strsave(*varp)) != NULL)
345 {
346 free_string_option(*p);
347 *p = s;
348 }
349}
350
351/*
352 * Set a string option to a new value (without checking the effect).
353 * The string is copied into allocated memory.
354 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
355 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
356 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
357 * "set_sid".
358 */
359 void
360set_string_option_direct(
361 char_u *name,
362 int opt_idx,
363 char_u *val,
364 int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL
365 int set_sid UNUSED)
366{
367 char_u *s;
368 char_u **varp;
369 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
370 int idx = opt_idx;
371
372 if (idx == -1) // use name
373 {
374 idx = findoption(name);
375 if (idx < 0) // not found (should not happen)
376 {
Bram Moolenaar460ae5d2022-01-01 14:19:49 +0000377 semsg(_(e_internal_error_str), "set_string_option_direct()");
Bram Moolenaardac13472019-09-16 21:06:21 +0200378 siemsg(_("For option %s"), name);
379 return;
380 }
381 }
382
383 if (is_hidden_option(idx)) // can't set hidden option
384 return;
385
386 s = vim_strsave(val);
387 if (s != NULL)
388 {
389 varp = (char_u **)get_option_varp_scope(idx,
390 both ? OPT_LOCAL : opt_flags);
391 if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED))
392 free_string_option(*varp);
393 *varp = s;
394
395 // For buffer/window local option may also set the global value.
396 if (both)
397 set_string_option_global(idx, varp);
398
399 set_option_flag(idx, P_ALLOCED);
400
401 // When setting both values of a global option with a local value,
402 // make the local value empty, so that the global value is used.
403 if (is_global_local_option(idx) && both)
404 {
405 free_string_option(*varp);
406 *varp = empty_option;
407 }
408# ifdef FEAT_EVAL
409 if (set_sid != SID_NONE)
410 {
411 sctx_T script_ctx;
412
413 if (set_sid == 0)
414 script_ctx = current_sctx;
415 else
416 {
417 script_ctx.sc_sid = set_sid;
418 script_ctx.sc_seq = 0;
419 script_ctx.sc_lnum = 0;
420 script_ctx.sc_version = 1;
421 }
422 set_option_sctx_idx(idx, opt_flags, script_ctx);
423 }
424# endif
425 }
426}
427
428/*
429 * Like set_string_option_direct(), but for a window-local option in "wp".
430 * Blocks autocommands to avoid the old curwin becoming invalid.
431 */
432 void
433set_string_option_direct_in_win(
434 win_T *wp,
435 char_u *name,
436 int opt_idx,
437 char_u *val,
438 int opt_flags,
439 int set_sid)
440{
441 win_T *save_curwin = curwin;
442
443 block_autocmds();
444 curwin = wp;
445 curbuf = curwin->w_buffer;
446 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
447 curwin = save_curwin;
448 curbuf = curwin->w_buffer;
449 unblock_autocmds();
450}
451
Dominique Pelle748b3082022-01-08 12:41:16 +0000452#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaardac13472019-09-16 21:06:21 +0200453/*
454 * Like set_string_option_direct(), but for a buffer-local option in "buf".
455 * Blocks autocommands to avoid the old curbuf becoming invalid.
456 */
457 void
458set_string_option_direct_in_buf(
459 buf_T *buf,
460 char_u *name,
461 int opt_idx,
462 char_u *val,
463 int opt_flags,
464 int set_sid)
465{
466 buf_T *save_curbuf = curbuf;
467
468 block_autocmds();
469 curbuf = buf;
470 curwin->w_buffer = curbuf;
471 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
472 curbuf = save_curbuf;
473 curwin->w_buffer = curbuf;
474 unblock_autocmds();
475}
Dominique Pelle748b3082022-01-08 12:41:16 +0000476#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200477
478/*
479 * Set a string option to a new value, and handle the effects.
480 *
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100481 * Returns NULL on success or an untranslated error message on error.
Bram Moolenaardac13472019-09-16 21:06:21 +0200482 */
483 char *
484set_string_option(
485 int opt_idx,
486 char_u *value,
487 int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL
488{
489 char_u *s;
490 char_u **varp;
491 char_u *oldval;
492#if defined(FEAT_EVAL)
493 char_u *oldval_l = NULL;
494 char_u *oldval_g = NULL;
495 char_u *saved_oldval = NULL;
496 char_u *saved_oldval_l = NULL;
497 char_u *saved_oldval_g = NULL;
498 char_u *saved_newval = NULL;
499#endif
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100500 char *errmsg = NULL;
Bram Moolenaardac13472019-09-16 21:06:21 +0200501 int value_checked = FALSE;
502
503 if (is_hidden_option(opt_idx)) // don't set hidden option
504 return NULL;
505
Bram Moolenaar7f009df2020-03-16 20:27:38 +0100506 s = vim_strsave(value == NULL ? (char_u *)"" : value);
Bram Moolenaardac13472019-09-16 21:06:21 +0200507 if (s != NULL)
508 {
509 varp = (char_u **)get_option_varp_scope(opt_idx,
510 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
511 ? (is_global_local_option(opt_idx)
512 ? OPT_GLOBAL : OPT_LOCAL)
513 : opt_flags);
514 oldval = *varp;
515#if defined(FEAT_EVAL)
516 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
517 {
518 oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL);
519 oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
520 }
521#endif
522 *varp = s;
523
524#if defined(FEAT_EVAL)
525 if (!starting
526# ifdef FEAT_CRYPT
527 && !is_crypt_key_option(opt_idx)
528# endif
529 )
530 {
531 if (oldval_l != NULL)
532 saved_oldval_l = vim_strsave(oldval_l);
533 if (oldval_g != NULL)
534 saved_oldval_g = vim_strsave(oldval_g);
535 saved_oldval = vim_strsave(oldval);
536 saved_newval = vim_strsave(s);
537 }
538#endif
zeertzjqf6782732022-07-27 18:26:03 +0100539 if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL,
Bram Moolenaardac13472019-09-16 21:06:21 +0200540 opt_flags, &value_checked)) == NULL)
541 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
542
543#if defined(FEAT_EVAL)
544 // call autocommand after handling side effects
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100545 if (errmsg == NULL)
zeertzjq269aa2b2022-11-28 11:36:50 +0000546 trigger_optionset_string(opt_idx, opt_flags,
Bram Moolenaardac13472019-09-16 21:06:21 +0200547 saved_oldval, saved_oldval_l,
548 saved_oldval_g, saved_newval);
549 vim_free(saved_oldval);
550 vim_free(saved_oldval_l);
551 vim_free(saved_oldval_g);
552 vim_free(saved_newval);
553#endif
554 }
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100555 return errmsg;
Bram Moolenaardac13472019-09-16 21:06:21 +0200556}
557
558/*
559 * Return TRUE if "val" is a valid 'filetype' name.
560 * Also used for 'syntax' and 'keymap'.
561 */
562 static int
563valid_filetype(char_u *val)
564{
565 return valid_name(val, ".-_");
566}
567
568#ifdef FEAT_STL_OPT
569/*
570 * Check validity of options with the 'statusline' format.
zeertzjq5dc294a2022-04-15 13:17:57 +0100571 * Return an untranslated error message or NULL.
Bram Moolenaardac13472019-09-16 21:06:21 +0200572 */
573 static char *
574check_stl_option(char_u *s)
575{
Bram Moolenaardac13472019-09-16 21:06:21 +0200576 int groupdepth = 0;
577 static char errbuf[80];
578
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100579 while (*s)
Bram Moolenaardac13472019-09-16 21:06:21 +0200580 {
581 // Check for valid keys after % sequences
582 while (*s && *s != '%')
583 s++;
584 if (!*s)
585 break;
586 s++;
Bram Moolenaardac13472019-09-16 21:06:21 +0200587 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
588 {
589 s++;
590 continue;
591 }
592 if (*s == ')')
593 {
594 s++;
595 if (--groupdepth < 0)
596 break;
597 continue;
598 }
599 if (*s == '-')
600 s++;
601 while (VIM_ISDIGIT(*s))
602 s++;
603 if (*s == STL_USER_HL)
604 continue;
605 if (*s == '.')
606 {
607 s++;
608 while (*s && VIM_ISDIGIT(*s))
609 s++;
610 }
611 if (*s == '(')
612 {
613 groupdepth++;
614 continue;
615 }
616 if (vim_strchr(STL_ALL, *s) == NULL)
617 {
618 return illegal_char(errbuf, *s);
619 }
620 if (*s == '{')
621 {
zeertzjq5dc294a2022-04-15 13:17:57 +0100622 int reevaluate = (*++s == '%');
shadmansaleh30e3de22021-05-15 17:23:28 +0200623
zeertzjq5dc294a2022-04-15 13:17:57 +0100624 if (reevaluate && *++s == '}')
625 // "}" is not allowed immediately after "%{%"
626 return illegal_char(errbuf, '}');
shadmansaleh30e3de22021-05-15 17:23:28 +0200627 while ((*s != '}' || (reevaluate && s[-1] != '%')) && *s)
Bram Moolenaardac13472019-09-16 21:06:21 +0200628 s++;
629 if (*s != '}')
zeertzjq5dc294a2022-04-15 13:17:57 +0100630 return e_unclosed_expression_sequence;
Bram Moolenaardac13472019-09-16 21:06:21 +0200631 }
632 }
Bram Moolenaardac13472019-09-16 21:06:21 +0200633 if (groupdepth != 0)
zeertzjq5dc294a2022-04-15 13:17:57 +0100634 return e_unbalanced_groups;
Bram Moolenaardac13472019-09-16 21:06:21 +0200635 return NULL;
636}
637#endif
638
639/*
640 * Handle string options that need some action to perform when changed.
zeertzjqf6782732022-07-27 18:26:03 +0100641 * The new value must be allocated.
LemonBoy77142312022-04-15 20:50:46 +0100642 * Returns NULL for success, or an unstranslated error message for an error.
Bram Moolenaardac13472019-09-16 21:06:21 +0200643 */
644 char *
645did_set_string_option(
646 int opt_idx, // index in options[] table
647 char_u **varp, // pointer to the option variable
Bram Moolenaardac13472019-09-16 21:06:21 +0200648 char_u *oldval, // previous value of the option
649 char *errbuf, // buffer for errors, or NULL
650 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
651 int *value_checked) // value was checked to be save, no
652 // need to set P_INSECURE
653{
654 char *errmsg = NULL;
655 char_u *s, *p;
656 int did_chartab = FALSE;
657 char_u **gvarp;
658 long_u free_oldval = (get_option_flags(opt_idx) & P_ALLOCED);
659#ifdef FEAT_GUI
660 // set when changing an option that only requires a redraw in the GUI
661 int redraw_gui_only = FALSE;
662#endif
663 int value_changed = FALSE;
664#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
665 int did_swaptcap = FALSE;
666#endif
667
668 // Get the global option to compare with, otherwise we would have to check
669 // two values for all local options.
670 gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
671
672 // Disallow changing some options from secure mode
673 if ((secure
674#ifdef HAVE_SANDBOX
675 || sandbox != 0
676#endif
677 ) && (get_option_flags(opt_idx) & P_SECURE))
Bram Moolenaar74409f62022-01-01 15:58:22 +0000678 errmsg = e_not_allowed_here;
Bram Moolenaardac13472019-09-16 21:06:21 +0200679
680 // Check for a "normal" directory or file name in some options. Disallow a
681 // path separator (slash and/or backslash), wildcards and characters that
682 // are often illegal in a file name. Be more permissive if "secure" is off.
683 else if (((get_option_flags(opt_idx) & P_NFNAME)
684 && vim_strpbrk(*varp, (char_u *)(secure
685 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
686 || ((get_option_flags(opt_idx) & P_NDNAME)
687 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000688 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200689
690 // 'term'
691 else if (varp == &T_NAME)
692 {
693 if (T_NAME[0] == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000694 errmsg = e_cannot_set_term_to_empty_string;
Bram Moolenaardac13472019-09-16 21:06:21 +0200695#ifdef FEAT_GUI
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100696 else if (gui.in_use)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000697 errmsg = e_cannot_change_term_in_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +0200698 else if (term_is_gui(T_NAME))
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000699 errmsg = e_use_gui_to_start_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +0200700#endif
701 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000702 errmsg = e_not_found_in_termcap;
Bram Moolenaardac13472019-09-16 21:06:21 +0200703 else
704 {
705 // Screen colors may have changed.
706 redraw_later_clear();
707
708 // Both 'term' and 'ttytype' point to T_NAME, only set the
709 // P_ALLOCED flag on 'term'.
710 opt_idx = findoption((char_u *)"term");
711 free_oldval = (get_option_flags(opt_idx) & P_ALLOCED);
712 }
713 }
714
715 // 'backupcopy'
716 else if (gvarp == &p_bkc)
717 {
718 char_u *bkc = p_bkc;
719 unsigned int *flags = &bkc_flags;
720
721 if (opt_flags & OPT_LOCAL)
722 {
723 bkc = curbuf->b_p_bkc;
724 flags = &curbuf->b_bkc_flags;
725 }
726
727 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
728 // make the local value empty: use the global value
729 *flags = 0;
730 else
731 {
732 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000733 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200734 if ((((int)*flags & BKC_AUTO) != 0)
735 + (((int)*flags & BKC_YES) != 0)
736 + (((int)*flags & BKC_NO) != 0) != 1)
737 {
738 // Must have exactly one of "auto", "yes" and "no".
739 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000740 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200741 }
742 }
743 }
744
745 // 'backupext' and 'patchmode'
746 else if (varp == &p_bex || varp == &p_pm)
747 {
748 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
749 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100750 errmsg = e_backupext_and_patchmode_are_equal;
Bram Moolenaardac13472019-09-16 21:06:21 +0200751 }
752#ifdef FEAT_LINEBREAK
753 // 'breakindentopt'
754 else if (varp == &curwin->w_p_briopt)
755 {
756 if (briopt_check(curwin) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000757 errmsg = e_invalid_argument;
Bram Moolenaarb2d85e32022-01-07 16:55:32 +0000758 // list setting requires a redraw
759 if (curwin->w_briopt_list)
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100760 redraw_all_later(UPD_NOT_VALID);
Bram Moolenaardac13472019-09-16 21:06:21 +0200761 }
762#endif
763
764 // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
765 // If the new option is invalid, use old value. 'lisp' option: refill
766 // g_chartab[] for '-' char
767 else if ( varp == &p_isi
768 || varp == &(curbuf->b_p_isk)
769 || varp == &p_isp
770 || varp == &p_isf)
771 {
772 if (init_chartab() == FAIL)
773 {
774 did_chartab = TRUE; // need to restore it below
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000775 errmsg = e_invalid_argument; // error in value
Bram Moolenaardac13472019-09-16 21:06:21 +0200776 }
777 }
778
779 // 'helpfile'
780 else if (varp == &p_hf)
781 {
782 // May compute new values for $VIM and $VIMRUNTIME
783 if (didset_vim)
LemonBoy77142312022-04-15 20:50:46 +0100784 vim_unsetenv_ext((char_u *)"VIM");
Bram Moolenaardac13472019-09-16 21:06:21 +0200785 if (didset_vimruntime)
LemonBoy77142312022-04-15 20:50:46 +0100786 vim_unsetenv_ext((char_u *)"VIMRUNTIME");
Bram Moolenaardac13472019-09-16 21:06:21 +0200787 }
788
789#ifdef FEAT_SYN_HL
790 // 'cursorlineopt'
791 else if (varp == &curwin->w_p_culopt
792 || gvarp == &curwin->w_allbuf_opt.wo_culopt)
793 {
794 if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000795 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200796 }
797
798 // 'colorcolumn'
799 else if (varp == &curwin->w_p_cc)
800 errmsg = check_colorcolumn(curwin);
801#endif
802
803#ifdef FEAT_MULTI_LANG
804 // 'helplang'
805 else if (varp == &p_hlg)
806 {
807 // Check for "", "ab", "ab,cd", etc.
808 for (s = p_hlg; *s != NUL; s += 3)
809 {
810 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
811 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000812 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200813 break;
814 }
815 if (s[2] == NUL)
816 break;
817 }
818 }
819#endif
820
821 // 'highlight'
822 else if (varp == &p_hl)
823 {
824 if (highlight_changed() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000825 errmsg = e_invalid_argument; // invalid flags
Bram Moolenaardac13472019-09-16 21:06:21 +0200826 }
827
828 // 'nrformats'
829 else if (gvarp == &p_nf)
830 {
831 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000832 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200833 }
834
835#ifdef FEAT_SESSION
836 // 'sessionoptions'
837 else if (varp == &p_ssop)
838 {
839 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000840 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200841 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
842 {
843 // Don't allow both "sesdir" and "curdir".
844 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000845 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200846 }
847 }
848 // 'viewoptions'
849 else if (varp == &p_vop)
850 {
851 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000852 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200853 }
854#endif
855
856 // 'scrollopt'
857 else if (varp == &p_sbo)
858 {
859 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000860 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200861 }
862
863 // 'ambiwidth'
864 else if (varp == &p_ambw || varp == &p_emoji)
865 {
866 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000867 errmsg = e_invalid_argument;
Bram Moolenaareed9d462021-02-15 20:38:25 +0100868 else
zeertzjq8ca29b62022-08-09 12:53:14 +0100869 errmsg = check_chars_options();
Bram Moolenaardac13472019-09-16 21:06:21 +0200870 }
871
872 // 'background'
873 else if (varp == &p_bg)
874 {
875 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
876 {
877#ifdef FEAT_EVAL
878 int dark = (*p_bg == 'd');
879#endif
880
881 init_highlight(FALSE, FALSE);
882
883#ifdef FEAT_EVAL
884 if (dark != (*p_bg == 'd')
885 && get_var_value((char_u *)"g:colors_name") != NULL)
886 {
887 // The color scheme must have set 'background' back to another
888 // value, that's not what we want here. Disable the color
889 // scheme and set the colors again.
890 do_unlet((char_u *)"g:colors_name", TRUE);
891 free_string_option(p_bg);
892 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
893 check_string_option(&p_bg);
894 init_highlight(FALSE, FALSE);
895 }
896#endif
Bram Moolenaarad431992021-05-03 20:40:38 +0200897#ifdef FEAT_TERMINAL
898 term_update_colors_all();
899#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200900 }
901 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000902 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200903 }
904
905 // 'wildmode'
906 else if (varp == &p_wim)
907 {
908 if (check_opt_wim() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000909 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200910 }
911
912 // 'wildoptions'
913 else if (varp == &p_wop)
914 {
915 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000916 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200917 }
918
919#ifdef FEAT_WAK
920 // 'winaltkeys'
921 else if (varp == &p_wak)
922 {
923 if (*p_wak == NUL
924 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000925 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200926# ifdef FEAT_MENU
ichizok02560422022-04-05 14:18:44 +0100927# if defined(FEAT_GUI_MOTIF)
Bram Moolenaardac13472019-09-16 21:06:21 +0200928 else if (gui.in_use)
929 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
ichizok02560422022-04-05 14:18:44 +0100930# elif defined(FEAT_GUI_GTK)
Bram Moolenaardac13472019-09-16 21:06:21 +0200931 else if (gui.in_use)
932 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
Bram Moolenaardac13472019-09-16 21:06:21 +0200933# endif
934# endif
935 }
936#endif
937
938 // 'eventignore'
939 else if (varp == &p_ei)
940 {
941 if (check_ei() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000942 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200943 }
944
945 // 'encoding', 'fileencoding', 'termencoding' and 'makeencoding'
946 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
947 || gvarp == &p_menc)
948 {
949 if (gvarp == &p_fenc)
950 {
951 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar108010a2021-06-27 22:03:33 +0200952 errmsg = e_cannot_make_changes_modifiable_is_off;
Bram Moolenaardac13472019-09-16 21:06:21 +0200953 else if (vim_strchr(*varp, ',') != NULL)
954 // No comma allowed in 'fileencoding'; catches confusing it
955 // with 'fileencodings'.
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000956 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200957 else
958 {
Bram Moolenaardac13472019-09-16 21:06:21 +0200959 // May show a "+" in the title now.
960 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +0200961 // Add 'fileencoding' to the swap file.
962 ml_setflags(curbuf);
963 }
964 }
965 if (errmsg == NULL)
966 {
967 // canonize the value, so that STRCMP() can be used on it
968 p = enc_canonize(*varp);
969 if (p != NULL)
970 {
971 vim_free(*varp);
972 *varp = p;
973 }
974 if (varp == &p_enc)
975 {
976 errmsg = mb_init();
Bram Moolenaardac13472019-09-16 21:06:21 +0200977 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +0200978 }
979 }
980
981#if defined(FEAT_GUI_GTK)
982 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
983 {
Bram Moolenaard88be5b2022-01-04 19:57:55 +0000984 // GTK uses only a single encoding, and that is UTF-8.
Bram Moolenaardac13472019-09-16 21:06:21 +0200985 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaard88be5b2022-01-04 19:57:55 +0000986 errmsg = e_cannot_be_changed_in_gtk_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +0200987 }
988#endif
989
990 if (errmsg == NULL)
991 {
992#ifdef FEAT_KEYMAP
993 // When 'keymap' is used and 'encoding' changes, reload the keymap
994 // (with another encoding).
995 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
996 (void)keymap_init();
997#endif
998
999 // When 'termencoding' is not empty and 'encoding' changes or when
1000 // 'termencoding' changes, need to setup for keyboard input and
1001 // display output conversion.
1002 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
1003 {
1004 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
1005 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
1006 {
Bram Moolenaard82a47d2022-01-05 20:24:39 +00001007 semsg(_(e_cannot_convert_between_str_and_str),
1008 p_tenc, p_enc);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001009 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001010 }
1011 }
1012
1013#if defined(MSWIN)
1014 // $HOME may have characters in active code page.
1015 if (varp == &p_enc)
1016 init_homedir();
1017#endif
1018 }
1019 }
1020
1021#if defined(FEAT_POSTSCRIPT)
1022 else if (varp == &p_penc)
1023 {
1024 // Canonize printencoding if VIM standard one
1025 p = enc_canonize(p_penc);
1026 if (p != NULL)
1027 {
1028 vim_free(p_penc);
1029 p_penc = p;
1030 }
1031 else
1032 {
1033 // Ensure lower case and '-' for '_'
1034 for (s = p_penc; *s != NUL; s++)
1035 {
1036 if (*s == '_')
1037 *s = '-';
1038 else
1039 *s = TOLOWER_ASC(*s);
1040 }
1041 }
1042 }
1043#endif
1044
1045#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1046 else if (varp == &p_imak)
1047 {
1048 if (!im_xim_isvalid_imactivate())
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001049 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001050 }
1051#endif
1052
1053#ifdef FEAT_KEYMAP
1054 else if (varp == &curbuf->b_p_keymap)
1055 {
1056 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001057 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001058 else
1059 {
1060 int secure_save = secure;
1061
1062 // Reset the secure flag, since the value of 'keymap' has
1063 // been checked to be safe.
1064 secure = 0;
1065
1066 // load or unload key mapping tables
1067 errmsg = keymap_init();
1068
1069 secure = secure_save;
1070
1071 // Since we check the value, there is no need to set P_INSECURE,
1072 // even when the value comes from a modeline.
1073 *value_checked = TRUE;
1074 }
1075
1076 if (errmsg == NULL)
1077 {
1078 if (*curbuf->b_p_keymap != NUL)
1079 {
1080 // Installed a new keymap, switch on using it.
1081 curbuf->b_p_iminsert = B_IMODE_LMAP;
1082 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
1083 curbuf->b_p_imsearch = B_IMODE_LMAP;
1084 }
1085 else
1086 {
1087 // Cleared the keymap, may reset 'iminsert' and 'imsearch'.
1088 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
1089 curbuf->b_p_iminsert = B_IMODE_NONE;
1090 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
1091 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
1092 }
1093 if ((opt_flags & OPT_LOCAL) == 0)
1094 {
1095 set_iminsert_global();
1096 set_imsearch_global();
1097 }
1098 status_redraw_curbuf();
1099 }
1100 }
1101#endif
1102
1103 // 'fileformat'
1104 else if (gvarp == &p_ff)
1105 {
1106 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
Bram Moolenaar108010a2021-06-27 22:03:33 +02001107 errmsg = e_cannot_make_changes_modifiable_is_off;
Bram Moolenaardac13472019-09-16 21:06:21 +02001108 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001109 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001110 else
1111 {
1112 // may also change 'textmode'
1113 if (get_fileformat(curbuf) == EOL_DOS)
1114 curbuf->b_p_tx = TRUE;
1115 else
1116 curbuf->b_p_tx = FALSE;
Bram Moolenaardac13472019-09-16 21:06:21 +02001117 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +02001118 // update flag in swap file
1119 ml_setflags(curbuf);
1120 // Redraw needed when switching to/from "mac": a CR in the text
1121 // will be displayed differently.
1122 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001123 redraw_curbuf_later(UPD_NOT_VALID);
Bram Moolenaardac13472019-09-16 21:06:21 +02001124 }
1125 }
1126
1127 // 'fileformats'
1128 else if (varp == &p_ffs)
1129 {
1130 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001131 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001132 else
1133 {
1134 // also change 'textauto'
1135 if (*p_ffs == NUL)
1136 p_ta = FALSE;
1137 else
1138 p_ta = TRUE;
1139 }
1140 }
1141
1142#if defined(FEAT_CRYPT)
1143 // 'cryptkey'
1144 else if (gvarp == &p_key)
1145 {
1146 // Make sure the ":set" command doesn't show the new value in the
1147 // history.
1148 remove_key_from_history();
1149
1150 if (STRCMP(curbuf->b_p_key, oldval) != 0)
1151 // Need to update the swapfile.
Bram Moolenaar76cb6832020-05-15 22:30:38 +02001152 {
Bram Moolenaardac13472019-09-16 21:06:21 +02001153 ml_set_crypt_key(curbuf, oldval,
1154 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar76cb6832020-05-15 22:30:38 +02001155 changed_internal();
1156 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001157 }
1158
1159 else if (gvarp == &p_cm)
1160 {
1161 if (opt_flags & OPT_LOCAL)
1162 p = curbuf->b_p_cm;
1163 else
1164 p = p_cm;
1165 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001166 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001167 else if (crypt_self_test() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001168 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001169 else
1170 {
1171 // When setting the global value to empty, make it "zip".
1172 if (*p_cm == NUL)
1173 {
zeertzjqf6782732022-07-27 18:26:03 +01001174 free_string_option(p_cm);
Bram Moolenaardac13472019-09-16 21:06:21 +02001175 p_cm = vim_strsave((char_u *)"zip");
Bram Moolenaardac13472019-09-16 21:06:21 +02001176 }
1177 // When using ":set cm=name" the local value is going to be empty.
1178 // Do that here, otherwise the crypt functions will still use the
1179 // local value.
1180 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
1181 {
1182 free_string_option(curbuf->b_p_cm);
1183 curbuf->b_p_cm = empty_option;
1184 }
1185
1186 // Need to update the swapfile when the effective method changed.
1187 // Set "s" to the effective old value, "p" to the effective new
1188 // method and compare.
1189 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
1190 s = p_cm; // was previously using the global value
1191 else
1192 s = oldval;
1193 if (*curbuf->b_p_cm == NUL)
1194 p = p_cm; // is now using the global value
1195 else
1196 p = curbuf->b_p_cm;
1197 if (STRCMP(s, p) != 0)
1198 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
1199
1200 // If the global value changes need to update the swapfile for all
1201 // buffers using that value.
1202 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
1203 {
1204 buf_T *buf;
1205
1206 FOR_ALL_BUFFERS(buf)
1207 if (buf != curbuf && *buf->b_p_cm == NUL)
1208 ml_set_crypt_key(buf, buf->b_p_key, oldval);
1209 }
1210 }
1211 }
1212#endif
1213
1214 // 'matchpairs'
1215 else if (gvarp == &p_mps)
1216 {
1217 if (has_mbyte)
1218 {
1219 for (p = *varp; *p != NUL; ++p)
1220 {
1221 int x2 = -1;
1222 int x3 = -1;
1223
=?UTF-8?q?Dundar=20G=C3=B6c?=b8366582022-04-14 20:43:56 +01001224 p += mb_ptr2len(p);
Bram Moolenaardac13472019-09-16 21:06:21 +02001225 if (*p != NUL)
1226 x2 = *p++;
1227 if (*p != NUL)
1228 {
1229 x3 = mb_ptr2char(p);
1230 p += mb_ptr2len(p);
1231 }
1232 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
1233 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001234 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001235 break;
1236 }
1237 if (*p == NUL)
1238 break;
1239 }
1240 }
1241 else
1242 {
1243 // Check for "x:y,x:y"
1244 for (p = *varp; *p != NUL; p += 4)
1245 {
1246 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
1247 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001248 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001249 break;
1250 }
1251 if (p[3] == NUL)
1252 break;
1253 }
1254 }
1255 }
1256
Bram Moolenaardac13472019-09-16 21:06:21 +02001257 // 'comments'
1258 else if (gvarp == &p_com)
1259 {
1260 for (s = *varp; *s; )
1261 {
1262 while (*s && *s != ':')
1263 {
1264 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
1265 && !VIM_ISDIGIT(*s) && *s != '-')
1266 {
1267 errmsg = illegal_char(errbuf, *s);
1268 break;
1269 }
1270 ++s;
1271 }
1272 if (*s++ == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001273 errmsg = e_missing_colon;
Bram Moolenaardac13472019-09-16 21:06:21 +02001274 else if (*s == ',' || *s == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001275 errmsg = e_zero_length_string;
Bram Moolenaardac13472019-09-16 21:06:21 +02001276 if (errmsg != NULL)
1277 break;
1278 while (*s && *s != ',')
1279 {
1280 if (*s == '\\' && s[1] != NUL)
1281 ++s;
1282 ++s;
1283 }
1284 s = skip_to_option_part(s);
1285 }
1286 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001287
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001288 // global 'listchars' or 'fillchars'
1289 else if (varp == &p_lcs || varp == &p_fcs)
Bram Moolenaardac13472019-09-16 21:06:21 +02001290 {
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001291 char_u **local_ptr = varp == &p_lcs
1292 ? &curwin->w_p_lcs : &curwin->w_p_fcs;
1293
1294 // only apply the global value to "curwin" when it does not have a
1295 // local value
1296 errmsg = set_chars_option(curwin, varp,
1297 **local_ptr == NUL || !(opt_flags & OPT_GLOBAL));
Bram Moolenaareed9d462021-02-15 20:38:25 +01001298 if (errmsg == NULL)
1299 {
1300 tabpage_T *tp;
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001301 win_T *wp;
Bram Moolenaareed9d462021-02-15 20:38:25 +01001302
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001303 // If the current window is set to use the global
1304 // 'listchars'/'fillchars' value, clear the window-local value.
Bram Moolenaareed9d462021-02-15 20:38:25 +01001305 if (!(opt_flags & OPT_GLOBAL))
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001306 clear_string_option(local_ptr);
Bram Moolenaareed9d462021-02-15 20:38:25 +01001307 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001308 {
Bram Moolenaar5ed26fa2022-07-04 18:05:51 +01001309 // If the current window has a local value need to apply it
1310 // again, it was changed when setting the global value.
Bram Moolenaar606efc72021-11-12 19:52:47 +00001311 // If no error was returned above, we don't expect an error
1312 // here, so ignore the return value.
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001313 local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs;
1314 if (**local_ptr == NUL)
1315 (void)set_chars_option(wp, local_ptr, TRUE);
1316 }
Bram Moolenaar606efc72021-11-12 19:52:47 +00001317
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001318 redraw_all_later(UPD_NOT_VALID);
Bram Moolenaareed9d462021-02-15 20:38:25 +01001319 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001320 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01001321 // local 'listchars'
1322 else if (varp == &curwin->w_p_lcs)
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001323 errmsg = set_chars_option(curwin, varp, TRUE);
Bram Moolenaareed9d462021-02-15 20:38:25 +01001324
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001325 // local 'fillchars'
1326 else if (varp == &curwin->w_p_fcs)
1327 {
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001328 errmsg = set_chars_option(curwin, varp, TRUE);
Bram Moolenaardac13472019-09-16 21:06:21 +02001329 }
1330
Bram Moolenaardac13472019-09-16 21:06:21 +02001331 // 'cedit'
1332 else if (varp == &p_cedit)
1333 {
1334 errmsg = check_cedit();
1335 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001336
1337 // 'verbosefile'
1338 else if (varp == &p_vfile)
1339 {
1340 verbose_stop();
1341 if (*p_vfile != NUL && verbose_open() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001342 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001343 }
1344
1345#ifdef FEAT_VIMINFO
1346 // 'viminfo'
1347 else if (varp == &p_viminfo)
1348 {
1349 for (s = p_viminfo; *s;)
1350 {
1351 // Check it's a valid character
1352 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
1353 {
1354 errmsg = illegal_char(errbuf, *s);
1355 break;
1356 }
1357 if (*s == 'n') // name is always last one
1358 break;
1359 else if (*s == 'r') // skip until next ','
1360 {
1361 while (*++s && *s != ',')
1362 ;
1363 }
1364 else if (*s == '%')
1365 {
1366 // optional number
1367 while (vim_isdigit(*++s))
1368 ;
1369 }
1370 else if (*s == '!' || *s == 'h' || *s == 'c')
1371 ++s; // no extra chars
1372 else // must have a number
1373 {
1374 while (vim_isdigit(*++s))
1375 ;
1376
1377 if (!VIM_ISDIGIT(*(s - 1)))
1378 {
1379 if (errbuf != NULL)
1380 {
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001381 sprintf(errbuf,
1382 _(e_missing_number_after_angle_str_angle),
Bram Moolenaardac13472019-09-16 21:06:21 +02001383 transchar_byte(*(s - 1)));
1384 errmsg = errbuf;
1385 }
1386 else
1387 errmsg = "";
1388 break;
1389 }
1390 }
1391 if (*s == ',')
1392 ++s;
1393 else if (*s)
1394 {
1395 if (errbuf != NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001396 errmsg = e_missing_comma;
Bram Moolenaardac13472019-09-16 21:06:21 +02001397 else
1398 errmsg = "";
1399 break;
1400 }
1401 }
1402 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001403 errmsg = e_must_specify_a_value;
Bram Moolenaardac13472019-09-16 21:06:21 +02001404 }
1405#endif // FEAT_VIMINFO
1406
1407 // terminal options
1408 else if (istermoption_idx(opt_idx) && full_screen)
1409 {
1410 // ":set t_Co=0" and ":set t_Co=1" do ":set t_Co="
1411 if (varp == &T_CCO)
1412 {
1413 int colors = atoi((char *)T_CCO);
1414
1415 // Only reinitialize colors if t_Co value has really changed to
1416 // avoid expensive reload of colorscheme if t_Co is set to the
1417 // same value multiple times.
1418 if (colors != t_colors)
1419 {
1420 t_colors = colors;
1421 if (t_colors <= 1)
1422 {
zeertzjqf6782732022-07-27 18:26:03 +01001423 vim_free(T_CCO);
Bram Moolenaardac13472019-09-16 21:06:21 +02001424 T_CCO = empty_option;
1425 }
1426#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
1427 if (is_term_win32())
1428 {
1429 swap_tcap();
1430 did_swaptcap = TRUE;
1431 }
1432#endif
1433 // We now have a different color setup, initialize it again.
1434 init_highlight(TRUE, FALSE);
1435 }
1436 }
1437 ttest(FALSE);
1438 if (varp == &T_ME)
1439 {
1440 out_str(T_ME);
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001441 redraw_later(UPD_CLEAR);
Bram Moolenaardac13472019-09-16 21:06:21 +02001442#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
1443 // Since t_me has been set, this probably means that the user
1444 // wants to use this as default colors. Need to reset default
1445 // background/foreground colors.
1446# ifdef VIMDLL
1447 if (!gui.in_use && !gui.starting)
1448# endif
1449 mch_set_normal_colors();
1450#endif
1451 }
1452 if (varp == &T_BE && termcap_active)
1453 {
Bram Moolenaar1d97db32022-06-04 22:15:54 +01001454 MAY_WANT_TO_LOG_THIS;
1455
Bram Moolenaardac13472019-09-16 21:06:21 +02001456 if (*T_BE == NUL)
1457 // When clearing t_BE we assume the user no longer wants
1458 // bracketed paste, thus disable it by writing t_BD.
1459 out_str(T_BD);
1460 else
1461 out_str(T_BE);
1462 }
1463 }
1464
1465#ifdef FEAT_LINEBREAK
1466 // 'showbreak'
Bram Moolenaaree857022019-11-09 23:26:40 +01001467 else if (gvarp == &p_sbr)
Bram Moolenaardac13472019-09-16 21:06:21 +02001468 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001469 for (s = *varp; *s; )
Bram Moolenaardac13472019-09-16 21:06:21 +02001470 {
1471 if (ptr2cells(s) != 1)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001472 errmsg = e_showbreak_contains_unprintable_or_wide_character;
Bram Moolenaardac13472019-09-16 21:06:21 +02001473 MB_PTR_ADV(s);
1474 }
1475 }
1476#endif
1477
1478#ifdef FEAT_GUI
1479 // 'guifont'
1480 else if (varp == &p_guifont)
1481 {
1482 if (gui.in_use)
1483 {
1484 p = p_guifont;
1485# if defined(FEAT_GUI_GTK)
1486 // Put up a font dialog and let the user select a new value.
1487 // If this is cancelled go back to the old value but don't
1488 // give an error message.
1489 if (STRCMP(p, "*") == 0)
1490 {
1491 p = gui_mch_font_dialog(oldval);
zeertzjqf6782732022-07-27 18:26:03 +01001492 free_string_option(p_guifont);
Bram Moolenaardac13472019-09-16 21:06:21 +02001493 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
Bram Moolenaardac13472019-09-16 21:06:21 +02001494 }
1495# endif
1496 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
1497 {
1498# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
1499 if (STRCMP(p_guifont, "*") == 0)
1500 {
1501 // Dialog was cancelled: Keep the old value without giving
1502 // an error message.
zeertzjqf6782732022-07-27 18:26:03 +01001503 free_string_option(p_guifont);
Bram Moolenaardac13472019-09-16 21:06:21 +02001504 p_guifont = vim_strsave(oldval);
Bram Moolenaardac13472019-09-16 21:06:21 +02001505 }
1506 else
1507# endif
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001508 errmsg = e_invalid_fonts;
Bram Moolenaardac13472019-09-16 21:06:21 +02001509 }
1510 }
1511 redraw_gui_only = TRUE;
1512 }
1513# ifdef FEAT_XFONTSET
1514 else if (varp == &p_guifontset)
1515 {
1516 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001517 errmsg = e_cant_select_fontset;
Bram Moolenaardac13472019-09-16 21:06:21 +02001518 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001519 errmsg = e_invalid_fontset;
Bram Moolenaardac13472019-09-16 21:06:21 +02001520 redraw_gui_only = TRUE;
1521 }
1522# endif
1523 else if (varp == &p_guifontwide)
1524 {
1525 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001526 errmsg = e_cant_select_wide_font;
Bram Moolenaardac13472019-09-16 21:06:21 +02001527 else if (gui_get_wide_font() == FAIL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001528 errmsg = e_invalid_wide_font;
Bram Moolenaardac13472019-09-16 21:06:21 +02001529 redraw_gui_only = TRUE;
1530 }
1531#endif
Dusan Popovic4eeedc02021-10-16 20:52:05 +01001532# if defined(FEAT_GUI_GTK)
1533 else if (varp == &p_guiligatures)
1534 {
1535 gui_set_ligatures();
1536 redraw_gui_only = TRUE;
1537 }
1538# endif
Bram Moolenaardac13472019-09-16 21:06:21 +02001539
1540#ifdef CURSOR_SHAPE
1541 // 'guicursor'
1542 else if (varp == &p_guicursor)
1543 errmsg = parse_shape_opt(SHAPE_CURSOR);
1544#endif
1545
1546#ifdef FEAT_MOUSESHAPE
1547 // 'mouseshape'
1548 else if (varp == &p_mouseshape)
1549 {
1550 errmsg = parse_shape_opt(SHAPE_MOUSE);
1551 update_mouseshape(-1);
1552 }
1553#endif
1554
1555#ifdef FEAT_PRINTER
1556 else if (varp == &p_popt)
1557 errmsg = parse_printoptions();
1558# if defined(FEAT_POSTSCRIPT)
1559 else if (varp == &p_pmfn)
1560 errmsg = parse_printmbfont();
1561# endif
1562#endif
1563
1564#ifdef FEAT_LANGMAP
1565 // 'langmap'
1566 else if (varp == &p_langmap)
1567 langmap_set();
1568#endif
1569
1570#ifdef FEAT_LINEBREAK
1571 // 'breakat'
1572 else if (varp == &p_breakat)
1573 fill_breakat_flags();
1574#endif
1575
Bram Moolenaardac13472019-09-16 21:06:21 +02001576 // 'titlestring' and 'iconstring'
1577 else if (varp == &p_titlestring || varp == &p_iconstring)
1578 {
Bram Moolenaar651fca82021-11-29 20:39:38 +00001579#ifdef FEAT_STL_OPT
Bram Moolenaardac13472019-09-16 21:06:21 +02001580 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
1581
1582 // NULL => statusline syntax
1583 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
1584 stl_syntax |= flagval;
1585 else
1586 stl_syntax &= ~flagval;
Bram Moolenaar651fca82021-11-29 20:39:38 +00001587#endif
Bram Moolenaardac13472019-09-16 21:06:21 +02001588 did_set_title();
1589 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001590
1591#ifdef FEAT_GUI
1592 // 'guioptions'
1593 else if (varp == &p_go)
1594 {
1595 gui_init_which_components(oldval);
1596 redraw_gui_only = TRUE;
1597 }
1598#endif
1599
1600#if defined(FEAT_GUI_TABLINE)
1601 // 'guitablabel'
1602 else if (varp == &p_gtl)
1603 {
1604 redraw_tabline = TRUE;
1605 redraw_gui_only = TRUE;
1606 }
1607 // 'guitabtooltip'
1608 else if (varp == &p_gtt)
1609 {
1610 redraw_gui_only = TRUE;
1611 }
1612#endif
1613
Bram Moolenaara1cb1d12019-10-17 23:00:07 +02001614#if defined(UNIX) || defined(VMS)
Bram Moolenaardac13472019-09-16 21:06:21 +02001615 // 'ttymouse'
1616 else if (varp == &p_ttym)
1617 {
1618 // Switch the mouse off before changing the escape sequences used for
1619 // that.
1620 mch_setmouse(FALSE);
1621 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001622 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001623 else
1624 check_mouse_termcode();
1625 if (termcap_active)
1626 setmouse(); // may switch it on again
1627 }
1628#endif
1629
1630 // 'selection'
1631 else if (varp == &p_sel)
1632 {
1633 if (*p_sel == NUL
1634 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001635 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001636 }
1637
1638 // 'selectmode'
1639 else if (varp == &p_slm)
1640 {
1641 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001642 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001643 }
1644
1645#ifdef FEAT_BROWSE
1646 // 'browsedir'
1647 else if (varp == &p_bsdir)
1648 {
1649 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
1650 && !mch_isdir(p_bsdir))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001651 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001652 }
1653#endif
1654
1655 // 'keymodel'
1656 else if (varp == &p_km)
1657 {
1658 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001659 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001660 else
1661 {
1662 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
1663 km_startsel = (vim_strchr(p_km, 'a') != NULL);
1664 }
1665 }
1666
Bram Moolenaar63a2e362022-11-23 20:20:18 +00001667 // 'keyprotocol'
1668 else if (varp == &p_kpc)
1669 {
1670 if (match_keyprotocol(NULL) == KEYPROTOCOL_FAIL)
1671 errmsg = e_invalid_argument;
1672 }
1673
Bram Moolenaardac13472019-09-16 21:06:21 +02001674 // 'mousemodel'
1675 else if (varp == &p_mousem)
1676 {
1677 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001678 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001679#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
1680 else if (*p_mousem != *oldval)
1681 // Changed from "extend" to "popup" or "popup_setpos" or vv: need
1682 // to create or delete the popup menus.
1683 gui_motif_update_mousemodel(root_menu);
1684#endif
1685 }
1686
1687 // 'switchbuf'
1688 else if (varp == &p_swb)
1689 {
1690 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001691 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001692 }
1693
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001694 // 'splitkeep'
1695 else if (varp == &p_spk)
1696 {
1697 if (check_opt_strings(p_spk, p_spk_values, FALSE) != OK)
1698 errmsg = e_invalid_argument;
1699 }
1700
Bram Moolenaardac13472019-09-16 21:06:21 +02001701 // 'debug'
1702 else if (varp == &p_debug)
1703 {
1704 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001705 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001706 }
1707
1708 // 'display'
1709 else if (varp == &p_dy)
1710 {
1711 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001712 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001713 else
1714 (void)init_chartab();
1715
1716 }
1717
1718 // 'eadirection'
1719 else if (varp == &p_ead)
1720 {
1721 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001722 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001723 }
1724
1725#ifdef FEAT_CLIPBOARD
1726 // 'clipboard'
1727 else if (varp == &p_cb)
1728 errmsg = check_clipboard_option();
1729#endif
1730
1731#ifdef FEAT_SPELL
1732 // When 'spelllang' or 'spellfile' is set and there is a window for this
1733 // buffer in which 'spell' is set load the wordlists.
1734 else if (varp == &(curwin->w_s->b_p_spl)
1735 || varp == &(curwin->w_s->b_p_spf))
1736 {
1737 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
1738
1739 if ((is_spellfile && !valid_spellfile(*varp))
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001740 || (!is_spellfile && !valid_spelllang(*varp)))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001741 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001742 else
1743 errmsg = did_set_spell_option(is_spellfile);
1744 }
1745 // When 'spellcapcheck' is set compile the regexp program.
1746 else if (varp == &(curwin->w_s->b_p_spc))
1747 {
1748 errmsg = compile_cap_prog(curwin->w_s);
1749 }
Bram Moolenaar362b44b2020-06-10 21:47:00 +02001750 // 'spelloptions'
1751 else if (varp == &(curwin->w_s->b_p_spo))
1752 {
1753 if (**varp != NUL && STRCMP("camel", *varp) != 0)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001754 errmsg = e_invalid_argument;
Bram Moolenaar362b44b2020-06-10 21:47:00 +02001755 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001756 // 'spellsuggest'
1757 else if (varp == &p_sps)
1758 {
1759 if (spell_check_sps() != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001760 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001761 }
1762 // 'mkspellmem'
1763 else if (varp == &p_msm)
1764 {
1765 if (spell_check_msm() != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001766 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001767 }
1768#endif
1769
1770 // When 'bufhidden' is set, check for valid value.
1771 else if (gvarp == &p_bh)
1772 {
1773 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001774 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001775 }
1776
1777 // When 'buftype' is set, check for valid value.
1778 else if (gvarp == &p_bt)
1779 {
1780 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001781 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001782 else
1783 {
1784 if (curwin->w_status_height)
1785 {
1786 curwin->w_redr_status = TRUE;
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001787 redraw_later(UPD_VALID);
Bram Moolenaardac13472019-09-16 21:06:21 +02001788 }
1789 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaardac13472019-09-16 21:06:21 +02001790 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +02001791 }
1792 }
1793
1794#ifdef FEAT_STL_OPT
zeertzjq5dc294a2022-04-15 13:17:57 +01001795 // 'statusline', 'tabline' or 'rulerformat'
1796 else if (gvarp == &p_stl || varp == &p_tal || varp == &p_ruf)
Bram Moolenaardac13472019-09-16 21:06:21 +02001797 {
1798 int wid;
1799
1800 if (varp == &p_ruf) // reset ru_wid first
1801 ru_wid = 0;
1802 s = *varp;
1803 if (varp == &p_ruf && *s == '%')
1804 {
1805 // set ru_wid if 'ruf' starts with "%99("
1806 if (*++s == '-') // ignore a '-'
1807 s++;
1808 wid = getdigits(&s);
1809 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
1810 ru_wid = wid;
1811 else
1812 errmsg = check_stl_option(p_ruf);
1813 }
zeertzjq5dc294a2022-04-15 13:17:57 +01001814 // check 'statusline' or 'tabline' only if it doesn't start with "%!"
Bram Moolenaardac13472019-09-16 21:06:21 +02001815 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
1816 errmsg = check_stl_option(s);
1817 if (varp == &p_ruf && errmsg == NULL)
1818 comp_col();
1819 }
1820#endif
1821
1822 // check if it is a valid value for 'complete' -- Acevedo
1823 else if (gvarp == &p_cpt)
1824 {
1825 for (s = *varp; *s;)
1826 {
1827 while (*s == ',' || *s == ' ')
1828 s++;
1829 if (!*s)
1830 break;
1831 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
1832 {
1833 errmsg = illegal_char(errbuf, *s);
1834 break;
1835 }
1836 if (*++s != NUL && *s != ',' && *s != ' ')
1837 {
1838 if (s[-1] == 'k' || s[-1] == 's')
1839 {
1840 // skip optional filename after 'k' and 's'
1841 while (*s && *s != ',' && *s != ' ')
1842 {
1843 if (*s == '\\' && s[1] != NUL)
1844 ++s;
1845 ++s;
1846 }
1847 }
1848 else
1849 {
1850 if (errbuf != NULL)
1851 {
1852 sprintf((char *)errbuf,
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001853 _(e_illegal_character_after_chr), *--s);
Bram Moolenaardac13472019-09-16 21:06:21 +02001854 errmsg = errbuf;
1855 }
1856 else
1857 errmsg = "";
1858 break;
1859 }
1860 }
1861 }
1862 }
1863
1864 // 'completeopt'
1865 else if (varp == &p_cot)
1866 {
1867 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001868 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001869 else
1870 completeopt_was_set();
1871 }
1872
1873#ifdef BACKSLASH_IN_FILENAME
1874 // 'completeslash'
1875 else if (gvarp == &p_csl)
1876 {
1877 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
1878 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001879 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001880 }
1881#endif
1882
1883#ifdef FEAT_SIGNS
1884 // 'signcolumn'
1885 else if (varp == &curwin->w_p_scl)
1886 {
1887 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001888 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001889 // When changing the 'signcolumn' to or from 'number', recompute the
1890 // width of the number column if 'number' or 'relativenumber' is set.
1891 if (((*oldval == 'n' && *(oldval + 1) == 'u')
1892 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
1893 && (curwin->w_p_nu || curwin->w_p_rnu))
1894 curwin->w_nrwidth_line_count = 0;
1895 }
1896#endif
1897
Luuk van Baalba936f62022-12-15 13:15:39 +00001898 // 'showcmdloc'
1899 else if (varp == &p_sloc)
1900 {
1901 if (check_opt_strings(p_sloc, p_sloc_values, FALSE) != OK)
1902 errmsg = e_invalid_argument;
1903 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001904
1905#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
1906 // 'toolbar'
1907 else if (varp == &p_toolbar)
1908 {
1909 if (opt_strings_flags(p_toolbar, p_toolbar_values,
1910 &toolbar_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001911 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001912 else
1913 {
1914 out_flush();
1915 gui_mch_show_toolbar((toolbar_flags &
1916 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
1917 }
1918 }
1919#endif
1920
1921#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
1922 // 'toolbariconsize': GTK+ 2 only
1923 else if (varp == &p_tbis)
1924 {
1925 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001926 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001927 else
1928 {
1929 out_flush();
1930 gui_mch_show_toolbar((toolbar_flags &
1931 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
1932 }
1933 }
1934#endif
1935
1936 // 'pastetoggle': translate key codes like in a mapping
1937 else if (varp == &p_pt)
1938 {
1939 if (*p_pt)
1940 {
Bram Moolenaar1e7b52a2019-10-13 16:59:08 +02001941 (void)replace_termcodes(p_pt, &p,
1942 REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
Bram Moolenaardac13472019-09-16 21:06:21 +02001943 if (p != NULL)
1944 {
zeertzjqf6782732022-07-27 18:26:03 +01001945 free_string_option(p_pt);
Bram Moolenaardac13472019-09-16 21:06:21 +02001946 p_pt = p;
Bram Moolenaardac13472019-09-16 21:06:21 +02001947 }
1948 }
1949 }
1950
1951 // 'backspace'
1952 else if (varp == &p_bs)
1953 {
1954 if (VIM_ISDIGIT(*p_bs))
1955 {
Bram Moolenaaraa0489e2020-04-17 19:41:21 +02001956 if (*p_bs > '3' || p_bs[1] != NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001957 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001958 }
1959 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001960 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001961 }
1962 else if (varp == &p_bo)
1963 {
1964 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001965 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001966 }
1967
1968 // 'tagcase'
1969 else if (gvarp == &p_tc)
1970 {
1971 unsigned int *flags;
1972
1973 if (opt_flags & OPT_LOCAL)
1974 {
1975 p = curbuf->b_p_tc;
1976 flags = &curbuf->b_tc_flags;
1977 }
1978 else
1979 {
1980 p = p_tc;
1981 flags = &tc_flags;
1982 }
1983
1984 if ((opt_flags & OPT_LOCAL) && *p == NUL)
1985 // make the local value empty: use the global value
1986 *flags = 0;
1987 else if (*p == NUL
1988 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001989 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001990 }
1991
1992 // 'casemap'
1993 else if (varp == &p_cmp)
1994 {
1995 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001996 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001997 }
1998
1999#ifdef FEAT_DIFF
2000 // 'diffopt'
2001 else if (varp == &p_dip)
2002 {
2003 if (diffopt_changed() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002004 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002005 }
2006#endif
2007
2008#ifdef FEAT_FOLDING
2009 // 'foldmethod'
2010 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
2011 {
2012 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
2013 || *curwin->w_p_fdm == NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002014 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002015 else
2016 {
2017 foldUpdateAll(curwin);
2018 if (foldmethodIsDiff(curwin))
2019 newFoldLevel();
2020 }
2021 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002022 // 'foldmarker'
2023 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
2024 {
2025 p = vim_strchr(*varp, ',');
2026 if (p == NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00002027 errmsg = e_comma_required;
Bram Moolenaardac13472019-09-16 21:06:21 +02002028 else if (p == *varp || p[1] == NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002029 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002030 else if (foldmethodIsMarker(curwin))
2031 foldUpdateAll(curwin);
2032 }
2033 // 'commentstring'
2034 else if (gvarp == &p_cms)
2035 {
2036 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00002037 errmsg = e_commentstring_must_be_empty_or_contain_str;
Bram Moolenaardac13472019-09-16 21:06:21 +02002038 }
2039 // 'foldopen'
2040 else if (varp == &p_fdo)
2041 {
2042 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002043 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002044 }
2045 // 'foldclose'
2046 else if (varp == &p_fcl)
2047 {
2048 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002049 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002050 }
2051 // 'foldignore'
2052 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
2053 {
2054 if (foldmethodIsIndent(curwin))
2055 foldUpdateAll(curwin);
2056 }
2057#endif
2058
2059 // 'virtualedit'
Gary Johnson53ba05b2021-07-26 22:19:10 +02002060 else if (gvarp == &p_ve)
Bram Moolenaardac13472019-09-16 21:06:21 +02002061 {
Gary Johnson53ba05b2021-07-26 22:19:10 +02002062 char_u *ve = p_ve;
2063 unsigned int *flags = &ve_flags;
2064
2065 if (opt_flags & OPT_LOCAL)
Bram Moolenaardac13472019-09-16 21:06:21 +02002066 {
Gary Johnson51ad8502021-08-03 18:33:08 +02002067 ve = curwin->w_p_ve;
2068 flags = &curwin->w_ve_flags;
Gary Johnson53ba05b2021-07-26 22:19:10 +02002069 }
2070
2071 if ((opt_flags & OPT_LOCAL) && *ve == NUL)
2072 // make the local value empty: use the global value
2073 *flags = 0;
2074 else
2075 {
2076 if (opt_strings_flags(ve, p_ve_values, flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002077 errmsg = e_invalid_argument;
Gary Johnson53ba05b2021-07-26 22:19:10 +02002078 else if (STRCMP(p_ve, oldval) != 0)
2079 {
2080 // Recompute cursor position in case the new 've' setting
2081 // changes something.
2082 validate_virtcol();
2083 coladvance(curwin->w_virtcol);
2084 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002085 }
2086 }
2087
2088#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
2089 else if (varp == &p_csqf)
2090 {
2091 if (p_csqf != NULL)
2092 {
2093 p = p_csqf;
2094 while (*p != NUL)
2095 {
2096 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
2097 || p[1] == NUL
2098 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
2099 || (p[2] != NUL && p[2] != ','))
2100 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002101 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002102 break;
2103 }
2104 else if (p[2] == NUL)
2105 break;
2106 else
2107 p += 3;
2108 }
2109 }
2110 }
2111#endif
2112
Bram Moolenaardac13472019-09-16 21:06:21 +02002113 // 'cinoptions'
2114 else if (gvarp == &p_cino)
2115 {
2116 // TODO: recognize errors
2117 parse_cino(curbuf);
2118 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002119
Bram Moolenaar49846fb2022-10-15 16:05:33 +01002120 // 'lispoptions'
2121 else if (gvarp == &p_lop)
2122 {
2123 if (**varp != NUL && STRCMP(*varp, "expr:0") != 0
2124 && STRCMP(*varp, "expr:1") != 0)
2125 errmsg = e_invalid_argument;
2126 }
2127
Bram Moolenaardac13472019-09-16 21:06:21 +02002128#if defined(FEAT_RENDER_OPTIONS)
2129 // 'renderoptions'
2130 else if (varp == &p_rop)
2131 {
2132 if (!gui_mch_set_rendering_options(p_rop))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002133 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002134 }
2135#endif
2136
2137 else if (gvarp == &p_ft)
2138 {
2139 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002140 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002141 else
2142 {
2143 value_changed = STRCMP(oldval, *varp) != 0;
2144
2145 // Since we check the value, there is no need to set P_INSECURE,
2146 // even when the value comes from a modeline.
2147 *value_checked = TRUE;
2148 }
2149 }
2150
2151#ifdef FEAT_SYN_HL
2152 else if (gvarp == &p_syn)
2153 {
2154 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002155 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002156 else
2157 {
2158 value_changed = STRCMP(oldval, *varp) != 0;
2159
2160 // Since we check the value, there is no need to set P_INSECURE,
2161 // even when the value comes from a modeline.
2162 *value_checked = TRUE;
2163 }
2164 }
2165#endif
2166
2167#ifdef FEAT_TERMINAL
2168 // 'termwinkey'
2169 else if (varp == &curwin->w_p_twk)
2170 {
2171 if (*curwin->w_p_twk != NUL
2172 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002173 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002174 }
2175 // 'termwinsize'
2176 else if (varp == &curwin->w_p_tws)
2177 {
2178 if (*curwin->w_p_tws != NUL)
2179 {
2180 p = skipdigits(curwin->w_p_tws);
2181 if (p == curwin->w_p_tws
2182 || (*p != 'x' && *p != '*')
2183 || *skipdigits(p + 1) != NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002184 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002185 }
2186 }
Bram Moolenaar219c7d02020-02-01 21:57:29 +01002187 // 'wincolor'
2188 else if (varp == &curwin->w_p_wcr)
Bram Moolenaar87fd0922021-11-20 13:47:45 +00002189 term_update_wincolor(curwin);
Bram Moolenaardac13472019-09-16 21:06:21 +02002190# if defined(MSWIN)
2191 // 'termwintype'
2192 else if (varp == &p_twt)
2193 {
2194 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002195 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002196 }
2197# endif
2198#endif
2199
2200#ifdef FEAT_VARTABS
2201 // 'varsofttabstop'
2202 else if (varp == &(curbuf->b_p_vsts))
2203 {
2204 char_u *cp;
2205
2206 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
2207 {
2208 if (curbuf->b_p_vsts_array)
2209 {
2210 vim_free(curbuf->b_p_vsts_array);
2211 curbuf->b_p_vsts_array = 0;
2212 }
2213 }
2214 else
2215 {
2216 for (cp = *varp; *cp; ++cp)
2217 {
2218 if (vim_isdigit(*cp))
2219 continue;
2220 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
2221 continue;
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002222 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002223 break;
2224 }
2225 if (errmsg == NULL)
2226 {
2227 int *oldarray = curbuf->b_p_vsts_array;
Bram Moolenaarb7081e12021-09-04 18:47:28 +02002228 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)) == OK)
Bram Moolenaardac13472019-09-16 21:06:21 +02002229 {
2230 if (oldarray)
2231 vim_free(oldarray);
2232 }
2233 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002234 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002235 }
2236 }
2237 }
2238
2239 // 'vartabstop'
2240 else if (varp == &(curbuf->b_p_vts))
2241 {
2242 char_u *cp;
2243
2244 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
2245 {
2246 if (curbuf->b_p_vts_array)
2247 {
2248 vim_free(curbuf->b_p_vts_array);
2249 curbuf->b_p_vts_array = NULL;
2250 }
2251 }
2252 else
2253 {
2254 for (cp = *varp; *cp; ++cp)
2255 {
2256 if (vim_isdigit(*cp))
2257 continue;
2258 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
2259 continue;
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002260 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002261 break;
2262 }
2263 if (errmsg == NULL)
2264 {
2265 int *oldarray = curbuf->b_p_vts_array;
2266
Bram Moolenaarb7081e12021-09-04 18:47:28 +02002267 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)) == OK)
Bram Moolenaardac13472019-09-16 21:06:21 +02002268 {
2269 vim_free(oldarray);
2270#ifdef FEAT_FOLDING
2271 if (foldmethodIsIndent(curwin))
2272 foldUpdateAll(curwin);
2273#endif
2274 }
2275 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002276 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002277 }
2278 }
2279 }
2280#endif
2281
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002282#ifdef FEAT_PROP_POPUP
Bram Moolenaardac13472019-09-16 21:06:21 +02002283 // 'previewpopup'
2284 else if (varp == &p_pvp)
2285 {
2286 if (parse_previewpopup(NULL) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002287 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002288 }
2289# ifdef FEAT_QUICKFIX
2290 // 'completepopup'
2291 else if (varp == &p_cpp)
2292 {
2293 if (parse_completepopup(NULL) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002294 errmsg = e_invalid_argument;
Bram Moolenaar447bfba2020-07-18 16:07:16 +02002295 else
2296 popup_close_info();
Bram Moolenaardac13472019-09-16 21:06:21 +02002297 }
2298# endif
2299#endif
2300
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002301#ifdef FEAT_EVAL
2302 // '*expr' options
2303 else if (
2304# ifdef FEAT_BEVAL
2305 varp == &p_bexpr ||
2306# endif
2307# ifdef FEAT_DIFF
2308 varp == &p_dex ||
2309# endif
2310# ifdef FEAT_FOLDING
2311 varp == &curwin->w_p_fde ||
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002312 varp == &curwin->w_p_fdt ||
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002313# endif
2314 gvarp == &p_fex ||
2315# ifdef FEAT_FIND_ID
2316 gvarp == &p_inex ||
2317# endif
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002318 gvarp == &p_inde ||
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002319# ifdef FEAT_DIFF
2320 varp == &p_pex ||
2321# endif
2322# ifdef FEAT_POSTSCRIPT
2323 varp == &p_pexpr ||
2324# endif
Bram Moolenaarf4e88f22022-01-23 14:17:28 +00002325 varp == &p_ccv)
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002326 {
2327 char_u **p_opt = NULL;
2328 char_u *name;
2329
2330 // If the option value starts with <SID> or s:, then replace that with
2331 // the script identifier.
2332# ifdef FEAT_BEVAL
2333 if (varp == &p_bexpr) // 'balloonexpr'
2334 p_opt = (opt_flags & OPT_LOCAL) ? &curbuf->b_p_bexpr : &p_bexpr;
2335# endif
2336# ifdef FEAT_DIFF
2337 if (varp == &p_dex) // 'diffexpr'
2338 p_opt = &p_dex;
2339# endif
2340# ifdef FEAT_FOLDING
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002341 if (varp == &curwin->w_p_fde) // 'foldexpr'
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002342 p_opt = &curwin->w_p_fde;
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002343 if (varp == &curwin->w_p_fdt) // 'foldtext'
2344 p_opt = &curwin->w_p_fdt;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002345# endif
2346 if (gvarp == &p_fex) // 'formatexpr'
2347 p_opt = &curbuf->b_p_fex;
2348# ifdef FEAT_FIND_ID
2349 if (gvarp == &p_inex) // 'includeexpr'
2350 p_opt = &curbuf->b_p_inex;
2351# endif
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002352 if (gvarp == &p_inde) // 'indentexpr'
2353 p_opt = &curbuf->b_p_inde;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002354# ifdef FEAT_DIFF
2355 if (varp == &p_pex) // 'patchexpr'
2356 p_opt = &p_pex;
2357# endif
2358# ifdef FEAT_POSTSCRIPT
2359 if (varp == &p_pexpr) // 'printexpr'
2360 p_opt = &p_pexpr;
2361# endif
Bram Moolenaarf4e88f22022-01-23 14:17:28 +00002362 if (varp == &p_ccv) // 'charconvert'
2363 p_opt = &p_ccv;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002364
2365 if (p_opt != NULL)
2366 {
2367 name = get_scriptlocal_funcname(*p_opt);
2368 if (name != NULL)
2369 {
zeertzjqf6782732022-07-27 18:26:03 +01002370 free_string_option(*p_opt);
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002371 *p_opt = name;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002372 }
2373 }
2374
2375# ifdef FEAT_FOLDING
2376 if (varp == &curwin->w_p_fde && foldmethodIsExpr(curwin))
2377 foldUpdateAll(curwin);
2378# endif
2379 }
2380#endif
2381
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002382#ifdef FEAT_COMPL_FUNC
2383 // 'completefunc'
2384 else if (gvarp == &p_cfu)
2385 {
2386 if (set_completefunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002387 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002388 }
2389
2390 // 'omnifunc'
2391 else if (gvarp == &p_ofu)
2392 {
2393 if (set_omnifunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002394 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002395 }
2396
2397 // 'thesaurusfunc'
2398 else if (gvarp == &p_tsrfu)
2399 {
2400 if (set_thesaurusfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002401 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002402 }
2403#endif
2404
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002405#if defined(FEAT_EVAL) && \
2406 (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL))
2407 // 'imactivatefunc'
2408 else if (gvarp == &p_imaf)
2409 {
2410 if (set_imactivatefunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002411 errmsg = e_invalid_argument;
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002412 }
2413
2414 // 'imstatusfunc'
2415 else if (gvarp == &p_imsf)
2416 {
2417 if (set_imstatusfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002418 errmsg = e_invalid_argument;
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002419 }
2420#endif
2421
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002422 // 'operatorfunc'
2423 else if (varp == &p_opfunc)
2424 {
2425 if (set_operatorfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002426 errmsg = e_invalid_argument;
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002427 }
2428
Bram Moolenaard43906d2020-07-20 21:31:32 +02002429#ifdef FEAT_QUICKFIX
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002430 // 'quickfixtextfunc'
Bram Moolenaard43906d2020-07-20 21:31:32 +02002431 else if (varp == &p_qftf)
2432 {
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002433 if (qf_process_qftf_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002434 errmsg = e_invalid_argument;
Bram Moolenaard43906d2020-07-20 21:31:32 +02002435 }
2436#endif
2437
Yegappan Lakshmanan19916a82021-11-24 16:32:55 +00002438#ifdef FEAT_EVAL
2439 // 'tagfunc'
2440 else if (gvarp == &p_tfu)
2441 {
2442 if (set_tagfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002443 errmsg = e_invalid_argument;
Yegappan Lakshmanan19916a82021-11-24 16:32:55 +00002444 }
2445#endif
2446
Bram Moolenaardac13472019-09-16 21:06:21 +02002447 // Options that are a list of flags.
2448 else
2449 {
2450 p = NULL;
2451 if (varp == &p_ww) // 'whichwrap'
2452 p = (char_u *)WW_ALL;
2453 if (varp == &p_shm) // 'shortmess'
2454 p = (char_u *)SHM_ALL;
2455 else if (varp == &(p_cpo)) // 'cpoptions'
2456 p = (char_u *)CPO_ALL;
2457 else if (varp == &(curbuf->b_p_fo)) // 'formatoptions'
2458 p = (char_u *)FO_ALL;
2459#ifdef FEAT_CONCEAL
2460 else if (varp == &curwin->w_p_cocu) // 'concealcursor'
2461 p = (char_u *)COCU_ALL;
2462#endif
2463 else if (varp == &p_mouse) // 'mouse'
2464 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002465 p = (char_u *)MOUSE_ALL;
Bram Moolenaardac13472019-09-16 21:06:21 +02002466 }
2467#if defined(FEAT_GUI)
2468 else if (varp == &p_go) // 'guioptions'
2469 p = (char_u *)GO_ALL;
2470#endif
2471 if (p != NULL)
2472 {
2473 for (s = *varp; *s; ++s)
2474 if (vim_strchr(p, *s) == NULL)
2475 {
2476 errmsg = illegal_char(errbuf, *s);
2477 break;
2478 }
2479 }
2480 }
2481
2482 // If error detected, restore the previous value.
2483 if (errmsg != NULL)
2484 {
zeertzjqf6782732022-07-27 18:26:03 +01002485 free_string_option(*varp);
Bram Moolenaardac13472019-09-16 21:06:21 +02002486 *varp = oldval;
2487 // When resetting some values, need to act on it.
2488 if (did_chartab)
2489 (void)init_chartab();
2490 if (varp == &p_hl)
2491 (void)highlight_changed();
2492 }
2493 else
2494 {
2495#ifdef FEAT_EVAL
2496 // Remember where the option was set.
2497 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
2498#endif
2499 // Free string options that are in allocated memory.
2500 // Use "free_oldval", because recursiveness may change the flags under
2501 // our fingers (esp. init_highlight()).
2502 if (free_oldval)
2503 free_string_option(oldval);
zeertzjqf6782732022-07-27 18:26:03 +01002504 set_option_flag(opt_idx, P_ALLOCED);
Bram Moolenaardac13472019-09-16 21:06:21 +02002505
2506 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
2507 && is_global_local_option(opt_idx))
2508 {
2509 // global option with local value set to use global value; free
2510 // the local value and make it empty
2511 p = get_option_varp_scope(opt_idx, OPT_LOCAL);
2512 free_string_option(*(char_u **)p);
2513 *(char_u **)p = empty_option;
2514 }
2515
2516 // May set global value for local option.
2517 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
2518 set_string_option_global(opt_idx, varp);
2519
2520 // Trigger the autocommand only after setting the flags.
2521#ifdef FEAT_SYN_HL
2522 // When 'syntax' is set, load the syntax of that name
2523 if (varp == &(curbuf->b_p_syn))
2524 {
2525 static int syn_recursive = 0;
2526
2527 ++syn_recursive;
2528 // Only pass TRUE for "force" when the value changed or not used
2529 // recursively, to avoid endless recurrence.
2530 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
2531 value_changed || syn_recursive == 1, curbuf);
2532 curbuf->b_flags |= BF_SYN_SET;
2533 --syn_recursive;
2534 }
2535#endif
2536 else if (varp == &(curbuf->b_p_ft))
2537 {
2538 // 'filetype' is set, trigger the FileType autocommand.
2539 // Skip this when called from a modeline and the filetype was
2540 // already set to this value.
2541 if (!(opt_flags & OPT_MODELINE) || value_changed)
2542 {
2543 static int ft_recursive = 0;
2544 int secure_save = secure;
2545
2546 // Reset the secure flag, since the value of 'filetype' has
2547 // been checked to be safe.
2548 secure = 0;
2549
2550 ++ft_recursive;
2551 did_filetype = TRUE;
2552 // Only pass TRUE for "force" when the value changed or not
2553 // used recursively, to avoid endless recurrence.
2554 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
2555 value_changed || ft_recursive == 1, curbuf);
2556 --ft_recursive;
2557 // Just in case the old "curbuf" is now invalid.
2558 if (varp != &(curbuf->b_p_ft))
2559 varp = NULL;
2560
2561 secure = secure_save;
2562 }
2563 }
2564#ifdef FEAT_SPELL
2565 if (varp == &(curwin->w_s->b_p_spl))
2566 {
2567 char_u fname[200];
2568 char_u *q = curwin->w_s->b_p_spl;
2569
2570 // Skip the first name if it is "cjk".
2571 if (STRNCMP(q, "cjk,", 4) == 0)
2572 q += 4;
2573
2574 // Source the spell/LANG.vim in 'runtimepath'.
2575 // They could set 'spellcapcheck' depending on the language.
2576 // Use the first name in 'spelllang' up to '_region' or
2577 // '.encoding'.
2578 for (p = q; *p != NUL; ++p)
2579 if (!ASCII_ISALNUM(*p) && *p != '-')
2580 break;
2581 if (p > q)
2582 {
2583 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
2584 (int)(p - q), q);
2585 source_runtime(fname, DIP_ALL);
2586 }
2587 }
2588#endif
2589 }
2590
Bram Moolenaardac13472019-09-16 21:06:21 +02002591 if (varp == &p_mouse)
2592 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002593 if (*p_mouse == NUL)
2594 mch_setmouse(FALSE); // switch mouse off
2595 else
Bram Moolenaardac13472019-09-16 21:06:21 +02002596 setmouse(); // in case 'mouse' changed
2597 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002598
Bram Moolenaar788fbb42020-05-31 14:08:12 +02002599#if defined(FEAT_LUA) || defined(PROTO)
2600 if (varp == &p_rtp)
2601 update_package_paths_in_lua();
2602#endif
2603
Bram Moolenaarb2d85e32022-01-07 16:55:32 +00002604#if defined(FEAT_LINEBREAK)
2605 // Changing Formatlistpattern when briopt includes the list setting:
2606 // redraw
2607 if ((varp == &p_flp || varp == &(curbuf->b_p_flp))
2608 && curwin->w_briopt_list)
Bram Moolenaara4d158b2022-08-14 14:17:45 +01002609 redraw_all_later(UPD_NOT_VALID);
Bram Moolenaarb2d85e32022-01-07 16:55:32 +00002610#endif
2611
Bram Moolenaardac13472019-09-16 21:06:21 +02002612 if (curwin->w_curswant != MAXCOL
Bram Moolenaara1cb1d12019-10-17 23:00:07 +02002613 && (get_option_flags(opt_idx) & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaardac13472019-09-16 21:06:21 +02002614 curwin->w_set_curswant = TRUE;
2615
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002616 if ((opt_flags & OPT_NO_REDRAW) == 0)
2617 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002618#ifdef FEAT_GUI
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002619 // check redraw when it's not a GUI option or the GUI is active.
2620 if (!redraw_gui_only || gui.in_use)
Bram Moolenaardac13472019-09-16 21:06:21 +02002621#endif
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002622 check_redraw(get_option_flags(opt_idx));
2623 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002624
2625#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
2626 if (did_swaptcap)
2627 {
2628 set_termname((char_u *)"win32");
2629 init_highlight(TRUE, FALSE);
2630 }
2631#endif
2632
2633 return errmsg;
2634}
2635
2636/*
2637 * Check an option that can be a range of string values.
2638 *
2639 * Return OK for correct value, FAIL otherwise.
2640 * Empty is always OK.
2641 */
2642 static int
2643check_opt_strings(
2644 char_u *val,
2645 char **values,
2646 int list) // when TRUE: accept a list of values
2647{
2648 return opt_strings_flags(val, values, NULL, list);
2649}
2650
2651/*
2652 * Handle an option that can be a range of string values.
2653 * Set a flag in "*flagp" for each string present.
2654 *
2655 * Return OK for correct value, FAIL otherwise.
2656 * Empty is always OK.
2657 */
2658 static int
2659opt_strings_flags(
2660 char_u *val, // new value
2661 char **values, // array of valid string values
2662 unsigned *flagp,
2663 int list) // when TRUE: accept a list of values
2664{
2665 int i;
2666 int len;
2667 unsigned new_flags = 0;
2668
2669 while (*val)
2670 {
2671 for (i = 0; ; ++i)
2672 {
2673 if (values[i] == NULL) // val not found in values[]
2674 return FAIL;
2675
2676 len = (int)STRLEN(values[i]);
2677 if (STRNCMP(values[i], val, len) == 0
2678 && ((list && val[len] == ',') || val[len] == NUL))
2679 {
2680 val += len + (val[len] == ',');
2681 new_flags |= (1 << i);
2682 break; // check next item in val list
2683 }
2684 }
2685 }
2686 if (flagp != NULL)
2687 *flagp = new_flags;
2688
2689 return OK;
2690}
2691
2692/*
2693 * return OK if "p" is a valid fileformat name, FAIL otherwise.
2694 */
2695 int
2696check_ff_value(char_u *p)
2697{
2698 return check_opt_strings(p, p_ff_values, FALSE);
2699}