blob: 084b4387039435d21e1f83a6279aa1b2748a571d [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
96
97static int check_opt_strings(char_u *val, char **values, int list);
98static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
99
100/*
101 * After setting various option values: recompute variables that depend on
102 * option values.
103 */
104 void
105didset_string_options(void)
106{
107 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
108 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
109 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
110#ifdef FEAT_SESSION
111 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
112 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
113#endif
114#ifdef FEAT_FOLDING
115 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
116#endif
117 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
118 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
119 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaara1cb1d12019-10-17 23:00:07 +0200120#if defined(UNIX) || defined(VMS)
Bram Moolenaardac13472019-09-16 21:06:21 +0200121 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
122#endif
123#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
124 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
125#endif
126#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
127 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
128#endif
Sean Dewar39c46b42022-05-12 17:44:29 +0100129 (void)opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE);
Bram Moolenaardac13472019-09-16 21:06:21 +0200130}
131
132#if defined(FEAT_EVAL)
133/*
134 * Trigger the OptionSet autocommand.
135 * "opt_idx" is the index of the option being set.
136 * "opt_flags" can be OPT_LOCAL etc.
137 * "oldval" the old value
138 * "oldval_l" the old local value (only non-NULL if global and local value
139 * are set)
140 * "oldval_g" the old global value (only non-NULL if global and local value
141 * are set)
142 * "newval" the new value
143 */
144 void
145trigger_optionsset_string(
146 int opt_idx,
147 int opt_flags,
148 char_u *oldval,
149 char_u *oldval_l,
150 char_u *oldval_g,
151 char_u *newval)
152{
153 // Don't do this recursively.
154 if (oldval != NULL && newval != NULL
155 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
156 {
157 char_u buf_type[7];
158
159 sprintf((char *)buf_type, "%s",
160 (opt_flags & OPT_LOCAL) ? "local" : "global");
161 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
162 set_vim_var_string(VV_OPTION_NEW, newval, -1);
163 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
164 if (opt_flags & OPT_LOCAL)
165 {
166 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
167 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
168 }
169 if (opt_flags & OPT_GLOBAL)
170 {
171 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
172 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
173 }
174 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
175 {
176 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
177 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
178 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
179 }
180 if (opt_flags & OPT_MODELINE)
181 {
182 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
183 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
184 }
185 apply_autocmds(EVENT_OPTIONSET,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +0000186 get_option_fullname(opt_idx), NULL, FALSE,
Bram Moolenaardac13472019-09-16 21:06:21 +0200187 NULL);
188 reset_v_option_vars();
189 }
190}
191#endif
192
193 static char *
194illegal_char(char *errbuf, int c)
195{
196 if (errbuf == NULL)
197 return "";
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000198 sprintf((char *)errbuf, _(e_illegal_character_str), (char *)transchar(c));
Bram Moolenaardac13472019-09-16 21:06:21 +0200199 return errbuf;
200}
201
202/*
203 * Check string options in a buffer for NULL value.
204 */
205 void
206check_buf_options(buf_T *buf)
207{
208 check_string_option(&buf->b_p_bh);
209 check_string_option(&buf->b_p_bt);
210 check_string_option(&buf->b_p_fenc);
211 check_string_option(&buf->b_p_ff);
212#ifdef FEAT_FIND_ID
213 check_string_option(&buf->b_p_def);
214 check_string_option(&buf->b_p_inc);
215# ifdef FEAT_EVAL
216 check_string_option(&buf->b_p_inex);
217# endif
218#endif
Bram Moolenaar8e145b82022-05-21 20:17:31 +0100219#if defined(FEAT_EVAL)
Bram Moolenaardac13472019-09-16 21:06:21 +0200220 check_string_option(&buf->b_p_inde);
221 check_string_option(&buf->b_p_indk);
222#endif
223#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
224 check_string_option(&buf->b_p_bexpr);
225#endif
226#if defined(FEAT_CRYPT)
227 check_string_option(&buf->b_p_cm);
228#endif
229 check_string_option(&buf->b_p_fp);
230#if defined(FEAT_EVAL)
231 check_string_option(&buf->b_p_fex);
232#endif
233#ifdef FEAT_CRYPT
234 check_string_option(&buf->b_p_key);
235#endif
236 check_string_option(&buf->b_p_kp);
237 check_string_option(&buf->b_p_mps);
238 check_string_option(&buf->b_p_fo);
239 check_string_option(&buf->b_p_flp);
240 check_string_option(&buf->b_p_isk);
Bram Moolenaardac13472019-09-16 21:06:21 +0200241 check_string_option(&buf->b_p_com);
Bram Moolenaardac13472019-09-16 21:06:21 +0200242#ifdef FEAT_FOLDING
243 check_string_option(&buf->b_p_cms);
244#endif
245 check_string_option(&buf->b_p_nf);
Bram Moolenaardac13472019-09-16 21:06:21 +0200246 check_string_option(&buf->b_p_qe);
Bram Moolenaardac13472019-09-16 21:06:21 +0200247#ifdef FEAT_SYN_HL
248 check_string_option(&buf->b_p_syn);
249 check_string_option(&buf->b_s.b_syn_isk);
250#endif
251#ifdef FEAT_SPELL
252 check_string_option(&buf->b_s.b_p_spc);
253 check_string_option(&buf->b_s.b_p_spf);
254 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar362b44b2020-06-10 21:47:00 +0200255 check_string_option(&buf->b_s.b_p_spo);
Bram Moolenaardac13472019-09-16 21:06:21 +0200256#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200257 check_string_option(&buf->b_p_sua);
Bram Moolenaardac13472019-09-16 21:06:21 +0200258 check_string_option(&buf->b_p_cink);
259 check_string_option(&buf->b_p_cino);
Tom Praschan3506cf32022-04-07 12:39:08 +0100260 check_string_option(&buf->b_p_cinsd);
Bram Moolenaardac13472019-09-16 21:06:21 +0200261 parse_cino(buf);
Bram Moolenaar49846fb2022-10-15 16:05:33 +0100262 check_string_option(&buf->b_p_lop);
Bram Moolenaardac13472019-09-16 21:06:21 +0200263 check_string_option(&buf->b_p_ft);
Bram Moolenaardac13472019-09-16 21:06:21 +0200264 check_string_option(&buf->b_p_cinw);
Bram Moolenaardac13472019-09-16 21:06:21 +0200265 check_string_option(&buf->b_p_cpt);
266#ifdef FEAT_COMPL_FUNC
267 check_string_option(&buf->b_p_cfu);
268 check_string_option(&buf->b_p_ofu);
Bram Moolenaard4c4bfa2021-10-16 21:14:11 +0100269 check_string_option(&buf->b_p_tsrfu);
Bram Moolenaardac13472019-09-16 21:06:21 +0200270#endif
271#ifdef FEAT_EVAL
272 check_string_option(&buf->b_p_tfu);
273#endif
274#ifdef FEAT_KEYMAP
275 check_string_option(&buf->b_p_keymap);
276#endif
277#ifdef FEAT_QUICKFIX
278 check_string_option(&buf->b_p_gp);
279 check_string_option(&buf->b_p_mp);
280 check_string_option(&buf->b_p_efm);
281#endif
282 check_string_option(&buf->b_p_ep);
283 check_string_option(&buf->b_p_path);
284 check_string_option(&buf->b_p_tags);
285 check_string_option(&buf->b_p_tc);
286 check_string_option(&buf->b_p_dict);
287 check_string_option(&buf->b_p_tsr);
Bram Moolenaardac13472019-09-16 21:06:21 +0200288 check_string_option(&buf->b_p_lw);
Bram Moolenaardac13472019-09-16 21:06:21 +0200289 check_string_option(&buf->b_p_bkc);
290 check_string_option(&buf->b_p_menc);
291#ifdef FEAT_VARTABS
292 check_string_option(&buf->b_p_vsts);
293 check_string_option(&buf->b_p_vts);
294#endif
295}
296
297/*
298 * Free the string allocated for an option.
299 * Checks for the string being empty_option. This may happen if we're out of
300 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
301 * check_options().
302 * Does NOT check for P_ALLOCED flag!
303 */
304 void
305free_string_option(char_u *p)
306{
307 if (p != empty_option)
308 vim_free(p);
309}
310
311 void
312clear_string_option(char_u **pp)
313{
314 if (*pp != empty_option)
315 vim_free(*pp);
316 *pp = empty_option;
317}
318
319 void
320check_string_option(char_u **pp)
321{
322 if (*pp == NULL)
323 *pp = empty_option;
324}
325
326/*
327 * Set global value for string option when it's a local option.
328 */
329 static void
330set_string_option_global(
331 int opt_idx, // option index
332 char_u **varp) // pointer to option variable
333{
334 char_u **p, *s;
335
336 // the global value is always allocated
337 if (is_window_local_option(opt_idx))
338 p = (char_u **)GLOBAL_WO(varp);
339 else
340 p = (char_u **)get_option_var(opt_idx);
341 if (!is_global_option(opt_idx)
342 && p != varp
343 && (s = vim_strsave(*varp)) != NULL)
344 {
345 free_string_option(*p);
346 *p = s;
347 }
348}
349
350/*
351 * Set a string option to a new value (without checking the effect).
352 * The string is copied into allocated memory.
353 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
354 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
355 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
356 * "set_sid".
357 */
358 void
359set_string_option_direct(
360 char_u *name,
361 int opt_idx,
362 char_u *val,
363 int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL
364 int set_sid UNUSED)
365{
366 char_u *s;
367 char_u **varp;
368 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
369 int idx = opt_idx;
370
371 if (idx == -1) // use name
372 {
373 idx = findoption(name);
374 if (idx < 0) // not found (should not happen)
375 {
Bram Moolenaar460ae5d2022-01-01 14:19:49 +0000376 semsg(_(e_internal_error_str), "set_string_option_direct()");
Bram Moolenaardac13472019-09-16 21:06:21 +0200377 siemsg(_("For option %s"), name);
378 return;
379 }
380 }
381
382 if (is_hidden_option(idx)) // can't set hidden option
383 return;
384
385 s = vim_strsave(val);
386 if (s != NULL)
387 {
388 varp = (char_u **)get_option_varp_scope(idx,
389 both ? OPT_LOCAL : opt_flags);
390 if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED))
391 free_string_option(*varp);
392 *varp = s;
393
394 // For buffer/window local option may also set the global value.
395 if (both)
396 set_string_option_global(idx, varp);
397
398 set_option_flag(idx, P_ALLOCED);
399
400 // When setting both values of a global option with a local value,
401 // make the local value empty, so that the global value is used.
402 if (is_global_local_option(idx) && both)
403 {
404 free_string_option(*varp);
405 *varp = empty_option;
406 }
407# ifdef FEAT_EVAL
408 if (set_sid != SID_NONE)
409 {
410 sctx_T script_ctx;
411
412 if (set_sid == 0)
413 script_ctx = current_sctx;
414 else
415 {
416 script_ctx.sc_sid = set_sid;
417 script_ctx.sc_seq = 0;
418 script_ctx.sc_lnum = 0;
419 script_ctx.sc_version = 1;
420 }
421 set_option_sctx_idx(idx, opt_flags, script_ctx);
422 }
423# endif
424 }
425}
426
427/*
428 * Like set_string_option_direct(), but for a window-local option in "wp".
429 * Blocks autocommands to avoid the old curwin becoming invalid.
430 */
431 void
432set_string_option_direct_in_win(
433 win_T *wp,
434 char_u *name,
435 int opt_idx,
436 char_u *val,
437 int opt_flags,
438 int set_sid)
439{
440 win_T *save_curwin = curwin;
441
442 block_autocmds();
443 curwin = wp;
444 curbuf = curwin->w_buffer;
445 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
446 curwin = save_curwin;
447 curbuf = curwin->w_buffer;
448 unblock_autocmds();
449}
450
Dominique Pelle748b3082022-01-08 12:41:16 +0000451#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaardac13472019-09-16 21:06:21 +0200452/*
453 * Like set_string_option_direct(), but for a buffer-local option in "buf".
454 * Blocks autocommands to avoid the old curbuf becoming invalid.
455 */
456 void
457set_string_option_direct_in_buf(
458 buf_T *buf,
459 char_u *name,
460 int opt_idx,
461 char_u *val,
462 int opt_flags,
463 int set_sid)
464{
465 buf_T *save_curbuf = curbuf;
466
467 block_autocmds();
468 curbuf = buf;
469 curwin->w_buffer = curbuf;
470 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
471 curbuf = save_curbuf;
472 curwin->w_buffer = curbuf;
473 unblock_autocmds();
474}
Dominique Pelle748b3082022-01-08 12:41:16 +0000475#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200476
477/*
478 * Set a string option to a new value, and handle the effects.
479 *
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100480 * Returns NULL on success or an untranslated error message on error.
Bram Moolenaardac13472019-09-16 21:06:21 +0200481 */
482 char *
483set_string_option(
484 int opt_idx,
485 char_u *value,
486 int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL
487{
488 char_u *s;
489 char_u **varp;
490 char_u *oldval;
491#if defined(FEAT_EVAL)
492 char_u *oldval_l = NULL;
493 char_u *oldval_g = NULL;
494 char_u *saved_oldval = NULL;
495 char_u *saved_oldval_l = NULL;
496 char_u *saved_oldval_g = NULL;
497 char_u *saved_newval = NULL;
498#endif
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100499 char *errmsg = NULL;
Bram Moolenaardac13472019-09-16 21:06:21 +0200500 int value_checked = FALSE;
501
502 if (is_hidden_option(opt_idx)) // don't set hidden option
503 return NULL;
504
Bram Moolenaar7f009df2020-03-16 20:27:38 +0100505 s = vim_strsave(value == NULL ? (char_u *)"" : value);
Bram Moolenaardac13472019-09-16 21:06:21 +0200506 if (s != NULL)
507 {
508 varp = (char_u **)get_option_varp_scope(opt_idx,
509 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
510 ? (is_global_local_option(opt_idx)
511 ? OPT_GLOBAL : OPT_LOCAL)
512 : opt_flags);
513 oldval = *varp;
514#if defined(FEAT_EVAL)
515 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
516 {
517 oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL);
518 oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
519 }
520#endif
521 *varp = s;
522
523#if defined(FEAT_EVAL)
524 if (!starting
525# ifdef FEAT_CRYPT
526 && !is_crypt_key_option(opt_idx)
527# endif
528 )
529 {
530 if (oldval_l != NULL)
531 saved_oldval_l = vim_strsave(oldval_l);
532 if (oldval_g != NULL)
533 saved_oldval_g = vim_strsave(oldval_g);
534 saved_oldval = vim_strsave(oldval);
535 saved_newval = vim_strsave(s);
536 }
537#endif
zeertzjqf6782732022-07-27 18:26:03 +0100538 if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL,
Bram Moolenaardac13472019-09-16 21:06:21 +0200539 opt_flags, &value_checked)) == NULL)
540 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
541
542#if defined(FEAT_EVAL)
543 // call autocommand after handling side effects
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100544 if (errmsg == NULL)
Bram Moolenaardac13472019-09-16 21:06:21 +0200545 trigger_optionsset_string(opt_idx, opt_flags,
546 saved_oldval, saved_oldval_l,
547 saved_oldval_g, saved_newval);
548 vim_free(saved_oldval);
549 vim_free(saved_oldval_l);
550 vim_free(saved_oldval_g);
551 vim_free(saved_newval);
552#endif
553 }
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100554 return errmsg;
Bram Moolenaardac13472019-09-16 21:06:21 +0200555}
556
557/*
558 * Return TRUE if "val" is a valid 'filetype' name.
559 * Also used for 'syntax' and 'keymap'.
560 */
561 static int
562valid_filetype(char_u *val)
563{
564 return valid_name(val, ".-_");
565}
566
567#ifdef FEAT_STL_OPT
568/*
569 * Check validity of options with the 'statusline' format.
zeertzjq5dc294a2022-04-15 13:17:57 +0100570 * Return an untranslated error message or NULL.
Bram Moolenaardac13472019-09-16 21:06:21 +0200571 */
572 static char *
573check_stl_option(char_u *s)
574{
Bram Moolenaardac13472019-09-16 21:06:21 +0200575 int groupdepth = 0;
576 static char errbuf[80];
577
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100578 while (*s)
Bram Moolenaardac13472019-09-16 21:06:21 +0200579 {
580 // Check for valid keys after % sequences
581 while (*s && *s != '%')
582 s++;
583 if (!*s)
584 break;
585 s++;
Bram Moolenaardac13472019-09-16 21:06:21 +0200586 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
587 {
588 s++;
589 continue;
590 }
591 if (*s == ')')
592 {
593 s++;
594 if (--groupdepth < 0)
595 break;
596 continue;
597 }
598 if (*s == '-')
599 s++;
600 while (VIM_ISDIGIT(*s))
601 s++;
602 if (*s == STL_USER_HL)
603 continue;
604 if (*s == '.')
605 {
606 s++;
607 while (*s && VIM_ISDIGIT(*s))
608 s++;
609 }
610 if (*s == '(')
611 {
612 groupdepth++;
613 continue;
614 }
615 if (vim_strchr(STL_ALL, *s) == NULL)
616 {
617 return illegal_char(errbuf, *s);
618 }
619 if (*s == '{')
620 {
zeertzjq5dc294a2022-04-15 13:17:57 +0100621 int reevaluate = (*++s == '%');
shadmansaleh30e3de22021-05-15 17:23:28 +0200622
zeertzjq5dc294a2022-04-15 13:17:57 +0100623 if (reevaluate && *++s == '}')
624 // "}" is not allowed immediately after "%{%"
625 return illegal_char(errbuf, '}');
shadmansaleh30e3de22021-05-15 17:23:28 +0200626 while ((*s != '}' || (reevaluate && s[-1] != '%')) && *s)
Bram Moolenaardac13472019-09-16 21:06:21 +0200627 s++;
628 if (*s != '}')
zeertzjq5dc294a2022-04-15 13:17:57 +0100629 return e_unclosed_expression_sequence;
Bram Moolenaardac13472019-09-16 21:06:21 +0200630 }
631 }
Bram Moolenaardac13472019-09-16 21:06:21 +0200632 if (groupdepth != 0)
zeertzjq5dc294a2022-04-15 13:17:57 +0100633 return e_unbalanced_groups;
Bram Moolenaardac13472019-09-16 21:06:21 +0200634 return NULL;
635}
636#endif
637
638/*
639 * Handle string options that need some action to perform when changed.
zeertzjqf6782732022-07-27 18:26:03 +0100640 * The new value must be allocated.
LemonBoy77142312022-04-15 20:50:46 +0100641 * Returns NULL for success, or an unstranslated error message for an error.
Bram Moolenaardac13472019-09-16 21:06:21 +0200642 */
643 char *
644did_set_string_option(
645 int opt_idx, // index in options[] table
646 char_u **varp, // pointer to the option variable
Bram Moolenaardac13472019-09-16 21:06:21 +0200647 char_u *oldval, // previous value of the option
648 char *errbuf, // buffer for errors, or NULL
649 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
650 int *value_checked) // value was checked to be save, no
651 // need to set P_INSECURE
652{
653 char *errmsg = NULL;
654 char_u *s, *p;
655 int did_chartab = FALSE;
656 char_u **gvarp;
657 long_u free_oldval = (get_option_flags(opt_idx) & P_ALLOCED);
658#ifdef FEAT_GUI
659 // set when changing an option that only requires a redraw in the GUI
660 int redraw_gui_only = FALSE;
661#endif
662 int value_changed = FALSE;
663#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
664 int did_swaptcap = FALSE;
665#endif
666
667 // Get the global option to compare with, otherwise we would have to check
668 // two values for all local options.
669 gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
670
671 // Disallow changing some options from secure mode
672 if ((secure
673#ifdef HAVE_SANDBOX
674 || sandbox != 0
675#endif
676 ) && (get_option_flags(opt_idx) & P_SECURE))
Bram Moolenaar74409f62022-01-01 15:58:22 +0000677 errmsg = e_not_allowed_here;
Bram Moolenaardac13472019-09-16 21:06:21 +0200678
679 // Check for a "normal" directory or file name in some options. Disallow a
680 // path separator (slash and/or backslash), wildcards and characters that
681 // are often illegal in a file name. Be more permissive if "secure" is off.
682 else if (((get_option_flags(opt_idx) & P_NFNAME)
683 && vim_strpbrk(*varp, (char_u *)(secure
684 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
685 || ((get_option_flags(opt_idx) & P_NDNAME)
686 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000687 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200688
689 // 'term'
690 else if (varp == &T_NAME)
691 {
692 if (T_NAME[0] == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000693 errmsg = e_cannot_set_term_to_empty_string;
Bram Moolenaardac13472019-09-16 21:06:21 +0200694#ifdef FEAT_GUI
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100695 else if (gui.in_use)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000696 errmsg = e_cannot_change_term_in_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +0200697 else if (term_is_gui(T_NAME))
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000698 errmsg = e_use_gui_to_start_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +0200699#endif
700 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000701 errmsg = e_not_found_in_termcap;
Bram Moolenaardac13472019-09-16 21:06:21 +0200702 else
703 {
704 // Screen colors may have changed.
705 redraw_later_clear();
706
707 // Both 'term' and 'ttytype' point to T_NAME, only set the
708 // P_ALLOCED flag on 'term'.
709 opt_idx = findoption((char_u *)"term");
710 free_oldval = (get_option_flags(opt_idx) & P_ALLOCED);
711 }
712 }
713
714 // 'backupcopy'
715 else if (gvarp == &p_bkc)
716 {
717 char_u *bkc = p_bkc;
718 unsigned int *flags = &bkc_flags;
719
720 if (opt_flags & OPT_LOCAL)
721 {
722 bkc = curbuf->b_p_bkc;
723 flags = &curbuf->b_bkc_flags;
724 }
725
726 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
727 // make the local value empty: use the global value
728 *flags = 0;
729 else
730 {
731 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000732 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200733 if ((((int)*flags & BKC_AUTO) != 0)
734 + (((int)*flags & BKC_YES) != 0)
735 + (((int)*flags & BKC_NO) != 0) != 1)
736 {
737 // Must have exactly one of "auto", "yes" and "no".
738 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000739 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200740 }
741 }
742 }
743
744 // 'backupext' and 'patchmode'
745 else if (varp == &p_bex || varp == &p_pm)
746 {
747 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
748 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100749 errmsg = e_backupext_and_patchmode_are_equal;
Bram Moolenaardac13472019-09-16 21:06:21 +0200750 }
751#ifdef FEAT_LINEBREAK
752 // 'breakindentopt'
753 else if (varp == &curwin->w_p_briopt)
754 {
755 if (briopt_check(curwin) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000756 errmsg = e_invalid_argument;
Bram Moolenaarb2d85e32022-01-07 16:55:32 +0000757 // list setting requires a redraw
758 if (curwin->w_briopt_list)
Bram Moolenaara4d158b2022-08-14 14:17:45 +0100759 redraw_all_later(UPD_NOT_VALID);
Bram Moolenaardac13472019-09-16 21:06:21 +0200760 }
761#endif
762
763 // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
764 // If the new option is invalid, use old value. 'lisp' option: refill
765 // g_chartab[] for '-' char
766 else if ( varp == &p_isi
767 || varp == &(curbuf->b_p_isk)
768 || varp == &p_isp
769 || varp == &p_isf)
770 {
771 if (init_chartab() == FAIL)
772 {
773 did_chartab = TRUE; // need to restore it below
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000774 errmsg = e_invalid_argument; // error in value
Bram Moolenaardac13472019-09-16 21:06:21 +0200775 }
776 }
777
778 // 'helpfile'
779 else if (varp == &p_hf)
780 {
781 // May compute new values for $VIM and $VIMRUNTIME
782 if (didset_vim)
LemonBoy77142312022-04-15 20:50:46 +0100783 vim_unsetenv_ext((char_u *)"VIM");
Bram Moolenaardac13472019-09-16 21:06:21 +0200784 if (didset_vimruntime)
LemonBoy77142312022-04-15 20:50:46 +0100785 vim_unsetenv_ext((char_u *)"VIMRUNTIME");
Bram Moolenaardac13472019-09-16 21:06:21 +0200786 }
787
788#ifdef FEAT_SYN_HL
789 // 'cursorlineopt'
790 else if (varp == &curwin->w_p_culopt
791 || gvarp == &curwin->w_allbuf_opt.wo_culopt)
792 {
793 if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000794 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200795 }
796
797 // 'colorcolumn'
798 else if (varp == &curwin->w_p_cc)
799 errmsg = check_colorcolumn(curwin);
800#endif
801
802#ifdef FEAT_MULTI_LANG
803 // 'helplang'
804 else if (varp == &p_hlg)
805 {
806 // Check for "", "ab", "ab,cd", etc.
807 for (s = p_hlg; *s != NUL; s += 3)
808 {
809 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
810 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000811 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200812 break;
813 }
814 if (s[2] == NUL)
815 break;
816 }
817 }
818#endif
819
820 // 'highlight'
821 else if (varp == &p_hl)
822 {
823 if (highlight_changed() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000824 errmsg = e_invalid_argument; // invalid flags
Bram Moolenaardac13472019-09-16 21:06:21 +0200825 }
826
827 // 'nrformats'
828 else if (gvarp == &p_nf)
829 {
830 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000831 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200832 }
833
834#ifdef FEAT_SESSION
835 // 'sessionoptions'
836 else if (varp == &p_ssop)
837 {
838 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000839 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200840 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
841 {
842 // Don't allow both "sesdir" and "curdir".
843 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000844 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200845 }
846 }
847 // 'viewoptions'
848 else if (varp == &p_vop)
849 {
850 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000851 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200852 }
853#endif
854
855 // 'scrollopt'
856 else if (varp == &p_sbo)
857 {
858 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000859 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200860 }
861
862 // 'ambiwidth'
863 else if (varp == &p_ambw || varp == &p_emoji)
864 {
865 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000866 errmsg = e_invalid_argument;
Bram Moolenaareed9d462021-02-15 20:38:25 +0100867 else
zeertzjq8ca29b62022-08-09 12:53:14 +0100868 errmsg = check_chars_options();
Bram Moolenaardac13472019-09-16 21:06:21 +0200869 }
870
871 // 'background'
872 else if (varp == &p_bg)
873 {
874 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
875 {
876#ifdef FEAT_EVAL
877 int dark = (*p_bg == 'd');
878#endif
879
880 init_highlight(FALSE, FALSE);
881
882#ifdef FEAT_EVAL
883 if (dark != (*p_bg == 'd')
884 && get_var_value((char_u *)"g:colors_name") != NULL)
885 {
886 // The color scheme must have set 'background' back to another
887 // value, that's not what we want here. Disable the color
888 // scheme and set the colors again.
889 do_unlet((char_u *)"g:colors_name", TRUE);
890 free_string_option(p_bg);
891 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
892 check_string_option(&p_bg);
893 init_highlight(FALSE, FALSE);
894 }
895#endif
Bram Moolenaarad431992021-05-03 20:40:38 +0200896#ifdef FEAT_TERMINAL
897 term_update_colors_all();
898#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200899 }
900 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000901 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200902 }
903
904 // 'wildmode'
905 else if (varp == &p_wim)
906 {
907 if (check_opt_wim() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000908 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200909 }
910
911 // 'wildoptions'
912 else if (varp == &p_wop)
913 {
914 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000915 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200916 }
917
918#ifdef FEAT_WAK
919 // 'winaltkeys'
920 else if (varp == &p_wak)
921 {
922 if (*p_wak == NUL
923 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000924 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200925# ifdef FEAT_MENU
ichizok02560422022-04-05 14:18:44 +0100926# if defined(FEAT_GUI_MOTIF)
Bram Moolenaardac13472019-09-16 21:06:21 +0200927 else if (gui.in_use)
928 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
ichizok02560422022-04-05 14:18:44 +0100929# elif defined(FEAT_GUI_GTK)
Bram Moolenaardac13472019-09-16 21:06:21 +0200930 else if (gui.in_use)
931 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
Bram Moolenaardac13472019-09-16 21:06:21 +0200932# endif
933# endif
934 }
935#endif
936
937 // 'eventignore'
938 else if (varp == &p_ei)
939 {
940 if (check_ei() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000941 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200942 }
943
944 // 'encoding', 'fileencoding', 'termencoding' and 'makeencoding'
945 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
946 || gvarp == &p_menc)
947 {
948 if (gvarp == &p_fenc)
949 {
950 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar108010a2021-06-27 22:03:33 +0200951 errmsg = e_cannot_make_changes_modifiable_is_off;
Bram Moolenaardac13472019-09-16 21:06:21 +0200952 else if (vim_strchr(*varp, ',') != NULL)
953 // No comma allowed in 'fileencoding'; catches confusing it
954 // with 'fileencodings'.
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000955 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200956 else
957 {
Bram Moolenaardac13472019-09-16 21:06:21 +0200958 // May show a "+" in the title now.
959 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +0200960 // Add 'fileencoding' to the swap file.
961 ml_setflags(curbuf);
962 }
963 }
964 if (errmsg == NULL)
965 {
966 // canonize the value, so that STRCMP() can be used on it
967 p = enc_canonize(*varp);
968 if (p != NULL)
969 {
970 vim_free(*varp);
971 *varp = p;
972 }
973 if (varp == &p_enc)
974 {
975 errmsg = mb_init();
Bram Moolenaardac13472019-09-16 21:06:21 +0200976 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +0200977 }
978 }
979
980#if defined(FEAT_GUI_GTK)
981 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
982 {
Bram Moolenaard88be5b2022-01-04 19:57:55 +0000983 // GTK uses only a single encoding, and that is UTF-8.
Bram Moolenaardac13472019-09-16 21:06:21 +0200984 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaard88be5b2022-01-04 19:57:55 +0000985 errmsg = e_cannot_be_changed_in_gtk_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +0200986 }
987#endif
988
989 if (errmsg == NULL)
990 {
991#ifdef FEAT_KEYMAP
992 // When 'keymap' is used and 'encoding' changes, reload the keymap
993 // (with another encoding).
994 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
995 (void)keymap_init();
996#endif
997
998 // When 'termencoding' is not empty and 'encoding' changes or when
999 // 'termencoding' changes, need to setup for keyboard input and
1000 // display output conversion.
1001 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
1002 {
1003 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
1004 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
1005 {
Bram Moolenaard82a47d2022-01-05 20:24:39 +00001006 semsg(_(e_cannot_convert_between_str_and_str),
1007 p_tenc, p_enc);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001008 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001009 }
1010 }
1011
1012#if defined(MSWIN)
1013 // $HOME may have characters in active code page.
1014 if (varp == &p_enc)
1015 init_homedir();
1016#endif
1017 }
1018 }
1019
1020#if defined(FEAT_POSTSCRIPT)
1021 else if (varp == &p_penc)
1022 {
1023 // Canonize printencoding if VIM standard one
1024 p = enc_canonize(p_penc);
1025 if (p != NULL)
1026 {
1027 vim_free(p_penc);
1028 p_penc = p;
1029 }
1030 else
1031 {
1032 // Ensure lower case and '-' for '_'
1033 for (s = p_penc; *s != NUL; s++)
1034 {
1035 if (*s == '_')
1036 *s = '-';
1037 else
1038 *s = TOLOWER_ASC(*s);
1039 }
1040 }
1041 }
1042#endif
1043
1044#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1045 else if (varp == &p_imak)
1046 {
1047 if (!im_xim_isvalid_imactivate())
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001048 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001049 }
1050#endif
1051
1052#ifdef FEAT_KEYMAP
1053 else if (varp == &curbuf->b_p_keymap)
1054 {
1055 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001056 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001057 else
1058 {
1059 int secure_save = secure;
1060
1061 // Reset the secure flag, since the value of 'keymap' has
1062 // been checked to be safe.
1063 secure = 0;
1064
1065 // load or unload key mapping tables
1066 errmsg = keymap_init();
1067
1068 secure = secure_save;
1069
1070 // Since we check the value, there is no need to set P_INSECURE,
1071 // even when the value comes from a modeline.
1072 *value_checked = TRUE;
1073 }
1074
1075 if (errmsg == NULL)
1076 {
1077 if (*curbuf->b_p_keymap != NUL)
1078 {
1079 // Installed a new keymap, switch on using it.
1080 curbuf->b_p_iminsert = B_IMODE_LMAP;
1081 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
1082 curbuf->b_p_imsearch = B_IMODE_LMAP;
1083 }
1084 else
1085 {
1086 // Cleared the keymap, may reset 'iminsert' and 'imsearch'.
1087 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
1088 curbuf->b_p_iminsert = B_IMODE_NONE;
1089 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
1090 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
1091 }
1092 if ((opt_flags & OPT_LOCAL) == 0)
1093 {
1094 set_iminsert_global();
1095 set_imsearch_global();
1096 }
1097 status_redraw_curbuf();
1098 }
1099 }
1100#endif
1101
1102 // 'fileformat'
1103 else if (gvarp == &p_ff)
1104 {
1105 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
Bram Moolenaar108010a2021-06-27 22:03:33 +02001106 errmsg = e_cannot_make_changes_modifiable_is_off;
Bram Moolenaardac13472019-09-16 21:06:21 +02001107 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001108 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001109 else
1110 {
1111 // may also change 'textmode'
1112 if (get_fileformat(curbuf) == EOL_DOS)
1113 curbuf->b_p_tx = TRUE;
1114 else
1115 curbuf->b_p_tx = FALSE;
Bram Moolenaardac13472019-09-16 21:06:21 +02001116 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +02001117 // update flag in swap file
1118 ml_setflags(curbuf);
1119 // Redraw needed when switching to/from "mac": a CR in the text
1120 // will be displayed differently.
1121 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001122 redraw_curbuf_later(UPD_NOT_VALID);
Bram Moolenaardac13472019-09-16 21:06:21 +02001123 }
1124 }
1125
1126 // 'fileformats'
1127 else if (varp == &p_ffs)
1128 {
1129 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001130 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001131 else
1132 {
1133 // also change 'textauto'
1134 if (*p_ffs == NUL)
1135 p_ta = FALSE;
1136 else
1137 p_ta = TRUE;
1138 }
1139 }
1140
1141#if defined(FEAT_CRYPT)
1142 // 'cryptkey'
1143 else if (gvarp == &p_key)
1144 {
1145 // Make sure the ":set" command doesn't show the new value in the
1146 // history.
1147 remove_key_from_history();
1148
1149 if (STRCMP(curbuf->b_p_key, oldval) != 0)
1150 // Need to update the swapfile.
Bram Moolenaar76cb6832020-05-15 22:30:38 +02001151 {
Bram Moolenaardac13472019-09-16 21:06:21 +02001152 ml_set_crypt_key(curbuf, oldval,
1153 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar76cb6832020-05-15 22:30:38 +02001154 changed_internal();
1155 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001156 }
1157
1158 else if (gvarp == &p_cm)
1159 {
1160 if (opt_flags & OPT_LOCAL)
1161 p = curbuf->b_p_cm;
1162 else
1163 p = p_cm;
1164 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001165 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001166 else if (crypt_self_test() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001167 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001168 else
1169 {
1170 // When setting the global value to empty, make it "zip".
1171 if (*p_cm == NUL)
1172 {
zeertzjqf6782732022-07-27 18:26:03 +01001173 free_string_option(p_cm);
Bram Moolenaardac13472019-09-16 21:06:21 +02001174 p_cm = vim_strsave((char_u *)"zip");
Bram Moolenaardac13472019-09-16 21:06:21 +02001175 }
1176 // When using ":set cm=name" the local value is going to be empty.
1177 // Do that here, otherwise the crypt functions will still use the
1178 // local value.
1179 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
1180 {
1181 free_string_option(curbuf->b_p_cm);
1182 curbuf->b_p_cm = empty_option;
1183 }
1184
1185 // Need to update the swapfile when the effective method changed.
1186 // Set "s" to the effective old value, "p" to the effective new
1187 // method and compare.
1188 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
1189 s = p_cm; // was previously using the global value
1190 else
1191 s = oldval;
1192 if (*curbuf->b_p_cm == NUL)
1193 p = p_cm; // is now using the global value
1194 else
1195 p = curbuf->b_p_cm;
1196 if (STRCMP(s, p) != 0)
1197 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
1198
1199 // If the global value changes need to update the swapfile for all
1200 // buffers using that value.
1201 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
1202 {
1203 buf_T *buf;
1204
1205 FOR_ALL_BUFFERS(buf)
1206 if (buf != curbuf && *buf->b_p_cm == NUL)
1207 ml_set_crypt_key(buf, buf->b_p_key, oldval);
1208 }
1209 }
1210 }
1211#endif
1212
1213 // 'matchpairs'
1214 else if (gvarp == &p_mps)
1215 {
1216 if (has_mbyte)
1217 {
1218 for (p = *varp; *p != NUL; ++p)
1219 {
1220 int x2 = -1;
1221 int x3 = -1;
1222
=?UTF-8?q?Dundar=20G=C3=B6c?=b8366582022-04-14 20:43:56 +01001223 p += mb_ptr2len(p);
Bram Moolenaardac13472019-09-16 21:06:21 +02001224 if (*p != NUL)
1225 x2 = *p++;
1226 if (*p != NUL)
1227 {
1228 x3 = mb_ptr2char(p);
1229 p += mb_ptr2len(p);
1230 }
1231 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
1232 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001233 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001234 break;
1235 }
1236 if (*p == NUL)
1237 break;
1238 }
1239 }
1240 else
1241 {
1242 // Check for "x:y,x:y"
1243 for (p = *varp; *p != NUL; p += 4)
1244 {
1245 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
1246 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001247 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001248 break;
1249 }
1250 if (p[3] == NUL)
1251 break;
1252 }
1253 }
1254 }
1255
Bram Moolenaardac13472019-09-16 21:06:21 +02001256 // 'comments'
1257 else if (gvarp == &p_com)
1258 {
1259 for (s = *varp; *s; )
1260 {
1261 while (*s && *s != ':')
1262 {
1263 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
1264 && !VIM_ISDIGIT(*s) && *s != '-')
1265 {
1266 errmsg = illegal_char(errbuf, *s);
1267 break;
1268 }
1269 ++s;
1270 }
1271 if (*s++ == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001272 errmsg = e_missing_colon;
Bram Moolenaardac13472019-09-16 21:06:21 +02001273 else if (*s == ',' || *s == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001274 errmsg = e_zero_length_string;
Bram Moolenaardac13472019-09-16 21:06:21 +02001275 if (errmsg != NULL)
1276 break;
1277 while (*s && *s != ',')
1278 {
1279 if (*s == '\\' && s[1] != NUL)
1280 ++s;
1281 ++s;
1282 }
1283 s = skip_to_option_part(s);
1284 }
1285 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001286
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001287 // global 'listchars' or 'fillchars'
1288 else if (varp == &p_lcs || varp == &p_fcs)
Bram Moolenaardac13472019-09-16 21:06:21 +02001289 {
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001290 char_u **local_ptr = varp == &p_lcs
1291 ? &curwin->w_p_lcs : &curwin->w_p_fcs;
1292
1293 // only apply the global value to "curwin" when it does not have a
1294 // local value
1295 errmsg = set_chars_option(curwin, varp,
1296 **local_ptr == NUL || !(opt_flags & OPT_GLOBAL));
Bram Moolenaareed9d462021-02-15 20:38:25 +01001297 if (errmsg == NULL)
1298 {
1299 tabpage_T *tp;
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001300 win_T *wp;
Bram Moolenaareed9d462021-02-15 20:38:25 +01001301
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001302 // If the current window is set to use the global
1303 // 'listchars'/'fillchars' value, clear the window-local value.
Bram Moolenaareed9d462021-02-15 20:38:25 +01001304 if (!(opt_flags & OPT_GLOBAL))
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001305 clear_string_option(local_ptr);
Bram Moolenaareed9d462021-02-15 20:38:25 +01001306 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001307 {
Bram Moolenaar5ed26fa2022-07-04 18:05:51 +01001308 // If the current window has a local value need to apply it
1309 // again, it was changed when setting the global value.
Bram Moolenaar606efc72021-11-12 19:52:47 +00001310 // If no error was returned above, we don't expect an error
1311 // here, so ignore the return value.
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001312 local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs;
1313 if (**local_ptr == NUL)
1314 (void)set_chars_option(wp, local_ptr, TRUE);
1315 }
Bram Moolenaar606efc72021-11-12 19:52:47 +00001316
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001317 redraw_all_later(UPD_NOT_VALID);
Bram Moolenaareed9d462021-02-15 20:38:25 +01001318 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001319 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01001320 // local 'listchars'
1321 else if (varp == &curwin->w_p_lcs)
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001322 errmsg = set_chars_option(curwin, varp, TRUE);
Bram Moolenaareed9d462021-02-15 20:38:25 +01001323
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001324 // local 'fillchars'
1325 else if (varp == &curwin->w_p_fcs)
1326 {
Bram Moolenaarb67f0c82022-07-04 21:03:36 +01001327 errmsg = set_chars_option(curwin, varp, TRUE);
Bram Moolenaardac13472019-09-16 21:06:21 +02001328 }
1329
Bram Moolenaardac13472019-09-16 21:06:21 +02001330 // 'cedit'
1331 else if (varp == &p_cedit)
1332 {
1333 errmsg = check_cedit();
1334 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001335
1336 // 'verbosefile'
1337 else if (varp == &p_vfile)
1338 {
1339 verbose_stop();
1340 if (*p_vfile != NUL && verbose_open() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001341 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001342 }
1343
1344#ifdef FEAT_VIMINFO
1345 // 'viminfo'
1346 else if (varp == &p_viminfo)
1347 {
1348 for (s = p_viminfo; *s;)
1349 {
1350 // Check it's a valid character
1351 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
1352 {
1353 errmsg = illegal_char(errbuf, *s);
1354 break;
1355 }
1356 if (*s == 'n') // name is always last one
1357 break;
1358 else if (*s == 'r') // skip until next ','
1359 {
1360 while (*++s && *s != ',')
1361 ;
1362 }
1363 else if (*s == '%')
1364 {
1365 // optional number
1366 while (vim_isdigit(*++s))
1367 ;
1368 }
1369 else if (*s == '!' || *s == 'h' || *s == 'c')
1370 ++s; // no extra chars
1371 else // must have a number
1372 {
1373 while (vim_isdigit(*++s))
1374 ;
1375
1376 if (!VIM_ISDIGIT(*(s - 1)))
1377 {
1378 if (errbuf != NULL)
1379 {
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001380 sprintf(errbuf,
1381 _(e_missing_number_after_angle_str_angle),
Bram Moolenaardac13472019-09-16 21:06:21 +02001382 transchar_byte(*(s - 1)));
1383 errmsg = errbuf;
1384 }
1385 else
1386 errmsg = "";
1387 break;
1388 }
1389 }
1390 if (*s == ',')
1391 ++s;
1392 else if (*s)
1393 {
1394 if (errbuf != NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001395 errmsg = e_missing_comma;
Bram Moolenaardac13472019-09-16 21:06:21 +02001396 else
1397 errmsg = "";
1398 break;
1399 }
1400 }
1401 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001402 errmsg = e_must_specify_a_value;
Bram Moolenaardac13472019-09-16 21:06:21 +02001403 }
1404#endif // FEAT_VIMINFO
1405
1406 // terminal options
1407 else if (istermoption_idx(opt_idx) && full_screen)
1408 {
1409 // ":set t_Co=0" and ":set t_Co=1" do ":set t_Co="
1410 if (varp == &T_CCO)
1411 {
1412 int colors = atoi((char *)T_CCO);
1413
1414 // Only reinitialize colors if t_Co value has really changed to
1415 // avoid expensive reload of colorscheme if t_Co is set to the
1416 // same value multiple times.
1417 if (colors != t_colors)
1418 {
1419 t_colors = colors;
1420 if (t_colors <= 1)
1421 {
zeertzjqf6782732022-07-27 18:26:03 +01001422 vim_free(T_CCO);
Bram Moolenaardac13472019-09-16 21:06:21 +02001423 T_CCO = empty_option;
1424 }
1425#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
1426 if (is_term_win32())
1427 {
1428 swap_tcap();
1429 did_swaptcap = TRUE;
1430 }
1431#endif
1432 // We now have a different color setup, initialize it again.
1433 init_highlight(TRUE, FALSE);
1434 }
1435 }
1436 ttest(FALSE);
1437 if (varp == &T_ME)
1438 {
1439 out_str(T_ME);
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001440 redraw_later(UPD_CLEAR);
Bram Moolenaardac13472019-09-16 21:06:21 +02001441#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
1442 // Since t_me has been set, this probably means that the user
1443 // wants to use this as default colors. Need to reset default
1444 // background/foreground colors.
1445# ifdef VIMDLL
1446 if (!gui.in_use && !gui.starting)
1447# endif
1448 mch_set_normal_colors();
1449#endif
1450 }
1451 if (varp == &T_BE && termcap_active)
1452 {
Bram Moolenaar1d97db32022-06-04 22:15:54 +01001453 MAY_WANT_TO_LOG_THIS;
1454
Bram Moolenaardac13472019-09-16 21:06:21 +02001455 if (*T_BE == NUL)
1456 // When clearing t_BE we assume the user no longer wants
1457 // bracketed paste, thus disable it by writing t_BD.
1458 out_str(T_BD);
1459 else
1460 out_str(T_BE);
1461 }
1462 }
1463
1464#ifdef FEAT_LINEBREAK
1465 // 'showbreak'
Bram Moolenaaree857022019-11-09 23:26:40 +01001466 else if (gvarp == &p_sbr)
Bram Moolenaardac13472019-09-16 21:06:21 +02001467 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001468 for (s = *varp; *s; )
Bram Moolenaardac13472019-09-16 21:06:21 +02001469 {
1470 if (ptr2cells(s) != 1)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001471 errmsg = e_showbreak_contains_unprintable_or_wide_character;
Bram Moolenaardac13472019-09-16 21:06:21 +02001472 MB_PTR_ADV(s);
1473 }
1474 }
1475#endif
1476
1477#ifdef FEAT_GUI
1478 // 'guifont'
1479 else if (varp == &p_guifont)
1480 {
1481 if (gui.in_use)
1482 {
1483 p = p_guifont;
1484# if defined(FEAT_GUI_GTK)
1485 // Put up a font dialog and let the user select a new value.
1486 // If this is cancelled go back to the old value but don't
1487 // give an error message.
1488 if (STRCMP(p, "*") == 0)
1489 {
1490 p = gui_mch_font_dialog(oldval);
zeertzjqf6782732022-07-27 18:26:03 +01001491 free_string_option(p_guifont);
Bram Moolenaardac13472019-09-16 21:06:21 +02001492 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
Bram Moolenaardac13472019-09-16 21:06:21 +02001493 }
1494# endif
1495 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
1496 {
1497# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
1498 if (STRCMP(p_guifont, "*") == 0)
1499 {
1500 // Dialog was cancelled: Keep the old value without giving
1501 // an error message.
zeertzjqf6782732022-07-27 18:26:03 +01001502 free_string_option(p_guifont);
Bram Moolenaardac13472019-09-16 21:06:21 +02001503 p_guifont = vim_strsave(oldval);
Bram Moolenaardac13472019-09-16 21:06:21 +02001504 }
1505 else
1506# endif
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001507 errmsg = e_invalid_fonts;
Bram Moolenaardac13472019-09-16 21:06:21 +02001508 }
1509 }
1510 redraw_gui_only = TRUE;
1511 }
1512# ifdef FEAT_XFONTSET
1513 else if (varp == &p_guifontset)
1514 {
1515 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001516 errmsg = e_cant_select_fontset;
Bram Moolenaardac13472019-09-16 21:06:21 +02001517 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001518 errmsg = e_invalid_fontset;
Bram Moolenaardac13472019-09-16 21:06:21 +02001519 redraw_gui_only = TRUE;
1520 }
1521# endif
1522 else if (varp == &p_guifontwide)
1523 {
1524 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001525 errmsg = e_cant_select_wide_font;
Bram Moolenaardac13472019-09-16 21:06:21 +02001526 else if (gui_get_wide_font() == FAIL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001527 errmsg = e_invalid_wide_font;
Bram Moolenaardac13472019-09-16 21:06:21 +02001528 redraw_gui_only = TRUE;
1529 }
1530#endif
Dusan Popovic4eeedc02021-10-16 20:52:05 +01001531# if defined(FEAT_GUI_GTK)
1532 else if (varp == &p_guiligatures)
1533 {
1534 gui_set_ligatures();
1535 redraw_gui_only = TRUE;
1536 }
1537# endif
Bram Moolenaardac13472019-09-16 21:06:21 +02001538
1539#ifdef CURSOR_SHAPE
1540 // 'guicursor'
1541 else if (varp == &p_guicursor)
1542 errmsg = parse_shape_opt(SHAPE_CURSOR);
1543#endif
1544
1545#ifdef FEAT_MOUSESHAPE
1546 // 'mouseshape'
1547 else if (varp == &p_mouseshape)
1548 {
1549 errmsg = parse_shape_opt(SHAPE_MOUSE);
1550 update_mouseshape(-1);
1551 }
1552#endif
1553
1554#ifdef FEAT_PRINTER
1555 else if (varp == &p_popt)
1556 errmsg = parse_printoptions();
1557# if defined(FEAT_POSTSCRIPT)
1558 else if (varp == &p_pmfn)
1559 errmsg = parse_printmbfont();
1560# endif
1561#endif
1562
1563#ifdef FEAT_LANGMAP
1564 // 'langmap'
1565 else if (varp == &p_langmap)
1566 langmap_set();
1567#endif
1568
1569#ifdef FEAT_LINEBREAK
1570 // 'breakat'
1571 else if (varp == &p_breakat)
1572 fill_breakat_flags();
1573#endif
1574
Bram Moolenaardac13472019-09-16 21:06:21 +02001575 // 'titlestring' and 'iconstring'
1576 else if (varp == &p_titlestring || varp == &p_iconstring)
1577 {
Bram Moolenaar651fca82021-11-29 20:39:38 +00001578#ifdef FEAT_STL_OPT
Bram Moolenaardac13472019-09-16 21:06:21 +02001579 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
1580
1581 // NULL => statusline syntax
1582 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
1583 stl_syntax |= flagval;
1584 else
1585 stl_syntax &= ~flagval;
Bram Moolenaar651fca82021-11-29 20:39:38 +00001586#endif
Bram Moolenaardac13472019-09-16 21:06:21 +02001587 did_set_title();
1588 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001589
1590#ifdef FEAT_GUI
1591 // 'guioptions'
1592 else if (varp == &p_go)
1593 {
1594 gui_init_which_components(oldval);
1595 redraw_gui_only = TRUE;
1596 }
1597#endif
1598
1599#if defined(FEAT_GUI_TABLINE)
1600 // 'guitablabel'
1601 else if (varp == &p_gtl)
1602 {
1603 redraw_tabline = TRUE;
1604 redraw_gui_only = TRUE;
1605 }
1606 // 'guitabtooltip'
1607 else if (varp == &p_gtt)
1608 {
1609 redraw_gui_only = TRUE;
1610 }
1611#endif
1612
Bram Moolenaara1cb1d12019-10-17 23:00:07 +02001613#if defined(UNIX) || defined(VMS)
Bram Moolenaardac13472019-09-16 21:06:21 +02001614 // 'ttymouse'
1615 else if (varp == &p_ttym)
1616 {
1617 // Switch the mouse off before changing the escape sequences used for
1618 // that.
1619 mch_setmouse(FALSE);
1620 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001621 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001622 else
1623 check_mouse_termcode();
1624 if (termcap_active)
1625 setmouse(); // may switch it on again
1626 }
1627#endif
1628
1629 // 'selection'
1630 else if (varp == &p_sel)
1631 {
1632 if (*p_sel == NUL
1633 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001634 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001635 }
1636
1637 // 'selectmode'
1638 else if (varp == &p_slm)
1639 {
1640 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001641 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001642 }
1643
1644#ifdef FEAT_BROWSE
1645 // 'browsedir'
1646 else if (varp == &p_bsdir)
1647 {
1648 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
1649 && !mch_isdir(p_bsdir))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001650 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001651 }
1652#endif
1653
1654 // 'keymodel'
1655 else if (varp == &p_km)
1656 {
1657 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001658 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001659 else
1660 {
1661 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
1662 km_startsel = (vim_strchr(p_km, 'a') != NULL);
1663 }
1664 }
1665
Bram Moolenaar63a2e362022-11-23 20:20:18 +00001666 // 'keyprotocol'
1667 else if (varp == &p_kpc)
1668 {
1669 if (match_keyprotocol(NULL) == KEYPROTOCOL_FAIL)
1670 errmsg = e_invalid_argument;
1671 }
1672
Bram Moolenaardac13472019-09-16 21:06:21 +02001673 // 'mousemodel'
1674 else if (varp == &p_mousem)
1675 {
1676 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001677 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001678#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
1679 else if (*p_mousem != *oldval)
1680 // Changed from "extend" to "popup" or "popup_setpos" or vv: need
1681 // to create or delete the popup menus.
1682 gui_motif_update_mousemodel(root_menu);
1683#endif
1684 }
1685
1686 // 'switchbuf'
1687 else if (varp == &p_swb)
1688 {
1689 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001690 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001691 }
1692
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001693 // 'splitkeep'
1694 else if (varp == &p_spk)
1695 {
1696 if (check_opt_strings(p_spk, p_spk_values, FALSE) != OK)
1697 errmsg = e_invalid_argument;
1698 }
1699
Bram Moolenaardac13472019-09-16 21:06:21 +02001700 // 'debug'
1701 else if (varp == &p_debug)
1702 {
1703 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001704 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001705 }
1706
1707 // 'display'
1708 else if (varp == &p_dy)
1709 {
1710 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001711 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001712 else
1713 (void)init_chartab();
1714
1715 }
1716
1717 // 'eadirection'
1718 else if (varp == &p_ead)
1719 {
1720 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001721 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001722 }
1723
1724#ifdef FEAT_CLIPBOARD
1725 // 'clipboard'
1726 else if (varp == &p_cb)
1727 errmsg = check_clipboard_option();
1728#endif
1729
1730#ifdef FEAT_SPELL
1731 // When 'spelllang' or 'spellfile' is set and there is a window for this
1732 // buffer in which 'spell' is set load the wordlists.
1733 else if (varp == &(curwin->w_s->b_p_spl)
1734 || varp == &(curwin->w_s->b_p_spf))
1735 {
1736 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
1737
1738 if ((is_spellfile && !valid_spellfile(*varp))
Luuk van Baal13ece2a2022-10-03 15:28:08 +01001739 || (!is_spellfile && !valid_spelllang(*varp)))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001740 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001741 else
1742 errmsg = did_set_spell_option(is_spellfile);
1743 }
1744 // When 'spellcapcheck' is set compile the regexp program.
1745 else if (varp == &(curwin->w_s->b_p_spc))
1746 {
1747 errmsg = compile_cap_prog(curwin->w_s);
1748 }
Bram Moolenaar362b44b2020-06-10 21:47:00 +02001749 // 'spelloptions'
1750 else if (varp == &(curwin->w_s->b_p_spo))
1751 {
1752 if (**varp != NUL && STRCMP("camel", *varp) != 0)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001753 errmsg = e_invalid_argument;
Bram Moolenaar362b44b2020-06-10 21:47:00 +02001754 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001755 // 'spellsuggest'
1756 else if (varp == &p_sps)
1757 {
1758 if (spell_check_sps() != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001759 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001760 }
1761 // 'mkspellmem'
1762 else if (varp == &p_msm)
1763 {
1764 if (spell_check_msm() != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001765 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001766 }
1767#endif
1768
1769 // When 'bufhidden' is set, check for valid value.
1770 else if (gvarp == &p_bh)
1771 {
1772 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001773 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001774 }
1775
1776 // When 'buftype' is set, check for valid value.
1777 else if (gvarp == &p_bt)
1778 {
1779 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001780 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001781 else
1782 {
1783 if (curwin->w_status_height)
1784 {
1785 curwin->w_redr_status = TRUE;
Bram Moolenaara4d158b2022-08-14 14:17:45 +01001786 redraw_later(UPD_VALID);
Bram Moolenaardac13472019-09-16 21:06:21 +02001787 }
1788 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaardac13472019-09-16 21:06:21 +02001789 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +02001790 }
1791 }
1792
1793#ifdef FEAT_STL_OPT
zeertzjq5dc294a2022-04-15 13:17:57 +01001794 // 'statusline', 'tabline' or 'rulerformat'
1795 else if (gvarp == &p_stl || varp == &p_tal || varp == &p_ruf)
Bram Moolenaardac13472019-09-16 21:06:21 +02001796 {
1797 int wid;
1798
1799 if (varp == &p_ruf) // reset ru_wid first
1800 ru_wid = 0;
1801 s = *varp;
1802 if (varp == &p_ruf && *s == '%')
1803 {
1804 // set ru_wid if 'ruf' starts with "%99("
1805 if (*++s == '-') // ignore a '-'
1806 s++;
1807 wid = getdigits(&s);
1808 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
1809 ru_wid = wid;
1810 else
1811 errmsg = check_stl_option(p_ruf);
1812 }
zeertzjq5dc294a2022-04-15 13:17:57 +01001813 // check 'statusline' or 'tabline' only if it doesn't start with "%!"
Bram Moolenaardac13472019-09-16 21:06:21 +02001814 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
1815 errmsg = check_stl_option(s);
1816 if (varp == &p_ruf && errmsg == NULL)
1817 comp_col();
1818 }
1819#endif
1820
1821 // check if it is a valid value for 'complete' -- Acevedo
1822 else if (gvarp == &p_cpt)
1823 {
1824 for (s = *varp; *s;)
1825 {
1826 while (*s == ',' || *s == ' ')
1827 s++;
1828 if (!*s)
1829 break;
1830 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
1831 {
1832 errmsg = illegal_char(errbuf, *s);
1833 break;
1834 }
1835 if (*++s != NUL && *s != ',' && *s != ' ')
1836 {
1837 if (s[-1] == 'k' || s[-1] == 's')
1838 {
1839 // skip optional filename after 'k' and 's'
1840 while (*s && *s != ',' && *s != ' ')
1841 {
1842 if (*s == '\\' && s[1] != NUL)
1843 ++s;
1844 ++s;
1845 }
1846 }
1847 else
1848 {
1849 if (errbuf != NULL)
1850 {
1851 sprintf((char *)errbuf,
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001852 _(e_illegal_character_after_chr), *--s);
Bram Moolenaardac13472019-09-16 21:06:21 +02001853 errmsg = errbuf;
1854 }
1855 else
1856 errmsg = "";
1857 break;
1858 }
1859 }
1860 }
1861 }
1862
1863 // 'completeopt'
1864 else if (varp == &p_cot)
1865 {
1866 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001867 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001868 else
1869 completeopt_was_set();
1870 }
1871
1872#ifdef BACKSLASH_IN_FILENAME
1873 // 'completeslash'
1874 else if (gvarp == &p_csl)
1875 {
1876 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
1877 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001878 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001879 }
1880#endif
1881
1882#ifdef FEAT_SIGNS
1883 // 'signcolumn'
1884 else if (varp == &curwin->w_p_scl)
1885 {
1886 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001887 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001888 // When changing the 'signcolumn' to or from 'number', recompute the
1889 // width of the number column if 'number' or 'relativenumber' is set.
1890 if (((*oldval == 'n' && *(oldval + 1) == 'u')
1891 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
1892 && (curwin->w_p_nu || curwin->w_p_rnu))
1893 curwin->w_nrwidth_line_count = 0;
1894 }
1895#endif
1896
1897
1898#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
1899 // 'toolbar'
1900 else if (varp == &p_toolbar)
1901 {
1902 if (opt_strings_flags(p_toolbar, p_toolbar_values,
1903 &toolbar_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001904 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001905 else
1906 {
1907 out_flush();
1908 gui_mch_show_toolbar((toolbar_flags &
1909 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
1910 }
1911 }
1912#endif
1913
1914#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
1915 // 'toolbariconsize': GTK+ 2 only
1916 else if (varp == &p_tbis)
1917 {
1918 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001919 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001920 else
1921 {
1922 out_flush();
1923 gui_mch_show_toolbar((toolbar_flags &
1924 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
1925 }
1926 }
1927#endif
1928
1929 // 'pastetoggle': translate key codes like in a mapping
1930 else if (varp == &p_pt)
1931 {
1932 if (*p_pt)
1933 {
Bram Moolenaar1e7b52a2019-10-13 16:59:08 +02001934 (void)replace_termcodes(p_pt, &p,
1935 REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
Bram Moolenaardac13472019-09-16 21:06:21 +02001936 if (p != NULL)
1937 {
zeertzjqf6782732022-07-27 18:26:03 +01001938 free_string_option(p_pt);
Bram Moolenaardac13472019-09-16 21:06:21 +02001939 p_pt = p;
Bram Moolenaardac13472019-09-16 21:06:21 +02001940 }
1941 }
1942 }
1943
1944 // 'backspace'
1945 else if (varp == &p_bs)
1946 {
1947 if (VIM_ISDIGIT(*p_bs))
1948 {
Bram Moolenaaraa0489e2020-04-17 19:41:21 +02001949 if (*p_bs > '3' || p_bs[1] != NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001950 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001951 }
1952 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001953 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001954 }
1955 else if (varp == &p_bo)
1956 {
1957 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001958 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001959 }
1960
1961 // 'tagcase'
1962 else if (gvarp == &p_tc)
1963 {
1964 unsigned int *flags;
1965
1966 if (opt_flags & OPT_LOCAL)
1967 {
1968 p = curbuf->b_p_tc;
1969 flags = &curbuf->b_tc_flags;
1970 }
1971 else
1972 {
1973 p = p_tc;
1974 flags = &tc_flags;
1975 }
1976
1977 if ((opt_flags & OPT_LOCAL) && *p == NUL)
1978 // make the local value empty: use the global value
1979 *flags = 0;
1980 else if (*p == NUL
1981 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001982 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001983 }
1984
1985 // 'casemap'
1986 else if (varp == &p_cmp)
1987 {
1988 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001989 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001990 }
1991
1992#ifdef FEAT_DIFF
1993 // 'diffopt'
1994 else if (varp == &p_dip)
1995 {
1996 if (diffopt_changed() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001997 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001998 }
1999#endif
2000
2001#ifdef FEAT_FOLDING
2002 // 'foldmethod'
2003 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
2004 {
2005 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
2006 || *curwin->w_p_fdm == NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002007 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002008 else
2009 {
2010 foldUpdateAll(curwin);
2011 if (foldmethodIsDiff(curwin))
2012 newFoldLevel();
2013 }
2014 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002015 // 'foldmarker'
2016 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
2017 {
2018 p = vim_strchr(*varp, ',');
2019 if (p == NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00002020 errmsg = e_comma_required;
Bram Moolenaardac13472019-09-16 21:06:21 +02002021 else if (p == *varp || p[1] == NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002022 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002023 else if (foldmethodIsMarker(curwin))
2024 foldUpdateAll(curwin);
2025 }
2026 // 'commentstring'
2027 else if (gvarp == &p_cms)
2028 {
2029 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00002030 errmsg = e_commentstring_must_be_empty_or_contain_str;
Bram Moolenaardac13472019-09-16 21:06:21 +02002031 }
2032 // 'foldopen'
2033 else if (varp == &p_fdo)
2034 {
2035 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002036 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002037 }
2038 // 'foldclose'
2039 else if (varp == &p_fcl)
2040 {
2041 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002042 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002043 }
2044 // 'foldignore'
2045 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
2046 {
2047 if (foldmethodIsIndent(curwin))
2048 foldUpdateAll(curwin);
2049 }
2050#endif
2051
2052 // 'virtualedit'
Gary Johnson53ba05b2021-07-26 22:19:10 +02002053 else if (gvarp == &p_ve)
Bram Moolenaardac13472019-09-16 21:06:21 +02002054 {
Gary Johnson53ba05b2021-07-26 22:19:10 +02002055 char_u *ve = p_ve;
2056 unsigned int *flags = &ve_flags;
2057
2058 if (opt_flags & OPT_LOCAL)
Bram Moolenaardac13472019-09-16 21:06:21 +02002059 {
Gary Johnson51ad8502021-08-03 18:33:08 +02002060 ve = curwin->w_p_ve;
2061 flags = &curwin->w_ve_flags;
Gary Johnson53ba05b2021-07-26 22:19:10 +02002062 }
2063
2064 if ((opt_flags & OPT_LOCAL) && *ve == NUL)
2065 // make the local value empty: use the global value
2066 *flags = 0;
2067 else
2068 {
2069 if (opt_strings_flags(ve, p_ve_values, flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002070 errmsg = e_invalid_argument;
Gary Johnson53ba05b2021-07-26 22:19:10 +02002071 else if (STRCMP(p_ve, oldval) != 0)
2072 {
2073 // Recompute cursor position in case the new 've' setting
2074 // changes something.
2075 validate_virtcol();
2076 coladvance(curwin->w_virtcol);
2077 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002078 }
2079 }
2080
2081#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
2082 else if (varp == &p_csqf)
2083 {
2084 if (p_csqf != NULL)
2085 {
2086 p = p_csqf;
2087 while (*p != NUL)
2088 {
2089 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
2090 || p[1] == NUL
2091 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
2092 || (p[2] != NUL && p[2] != ','))
2093 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002094 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002095 break;
2096 }
2097 else if (p[2] == NUL)
2098 break;
2099 else
2100 p += 3;
2101 }
2102 }
2103 }
2104#endif
2105
Bram Moolenaardac13472019-09-16 21:06:21 +02002106 // 'cinoptions'
2107 else if (gvarp == &p_cino)
2108 {
2109 // TODO: recognize errors
2110 parse_cino(curbuf);
2111 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002112
Bram Moolenaar49846fb2022-10-15 16:05:33 +01002113 // 'lispoptions'
2114 else if (gvarp == &p_lop)
2115 {
2116 if (**varp != NUL && STRCMP(*varp, "expr:0") != 0
2117 && STRCMP(*varp, "expr:1") != 0)
2118 errmsg = e_invalid_argument;
2119 }
2120
Bram Moolenaardac13472019-09-16 21:06:21 +02002121#if defined(FEAT_RENDER_OPTIONS)
2122 // 'renderoptions'
2123 else if (varp == &p_rop)
2124 {
2125 if (!gui_mch_set_rendering_options(p_rop))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002126 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002127 }
2128#endif
2129
2130 else if (gvarp == &p_ft)
2131 {
2132 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002133 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002134 else
2135 {
2136 value_changed = STRCMP(oldval, *varp) != 0;
2137
2138 // Since we check the value, there is no need to set P_INSECURE,
2139 // even when the value comes from a modeline.
2140 *value_checked = TRUE;
2141 }
2142 }
2143
2144#ifdef FEAT_SYN_HL
2145 else if (gvarp == &p_syn)
2146 {
2147 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002148 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002149 else
2150 {
2151 value_changed = STRCMP(oldval, *varp) != 0;
2152
2153 // Since we check the value, there is no need to set P_INSECURE,
2154 // even when the value comes from a modeline.
2155 *value_checked = TRUE;
2156 }
2157 }
2158#endif
2159
2160#ifdef FEAT_TERMINAL
2161 // 'termwinkey'
2162 else if (varp == &curwin->w_p_twk)
2163 {
2164 if (*curwin->w_p_twk != NUL
2165 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002166 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002167 }
2168 // 'termwinsize'
2169 else if (varp == &curwin->w_p_tws)
2170 {
2171 if (*curwin->w_p_tws != NUL)
2172 {
2173 p = skipdigits(curwin->w_p_tws);
2174 if (p == curwin->w_p_tws
2175 || (*p != 'x' && *p != '*')
2176 || *skipdigits(p + 1) != NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002177 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002178 }
2179 }
Bram Moolenaar219c7d02020-02-01 21:57:29 +01002180 // 'wincolor'
2181 else if (varp == &curwin->w_p_wcr)
Bram Moolenaar87fd0922021-11-20 13:47:45 +00002182 term_update_wincolor(curwin);
Bram Moolenaardac13472019-09-16 21:06:21 +02002183# if defined(MSWIN)
2184 // 'termwintype'
2185 else if (varp == &p_twt)
2186 {
2187 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002188 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002189 }
2190# endif
2191#endif
2192
2193#ifdef FEAT_VARTABS
2194 // 'varsofttabstop'
2195 else if (varp == &(curbuf->b_p_vsts))
2196 {
2197 char_u *cp;
2198
2199 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
2200 {
2201 if (curbuf->b_p_vsts_array)
2202 {
2203 vim_free(curbuf->b_p_vsts_array);
2204 curbuf->b_p_vsts_array = 0;
2205 }
2206 }
2207 else
2208 {
2209 for (cp = *varp; *cp; ++cp)
2210 {
2211 if (vim_isdigit(*cp))
2212 continue;
2213 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
2214 continue;
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002215 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002216 break;
2217 }
2218 if (errmsg == NULL)
2219 {
2220 int *oldarray = curbuf->b_p_vsts_array;
Bram Moolenaarb7081e12021-09-04 18:47:28 +02002221 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)) == OK)
Bram Moolenaardac13472019-09-16 21:06:21 +02002222 {
2223 if (oldarray)
2224 vim_free(oldarray);
2225 }
2226 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002227 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002228 }
2229 }
2230 }
2231
2232 // 'vartabstop'
2233 else if (varp == &(curbuf->b_p_vts))
2234 {
2235 char_u *cp;
2236
2237 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
2238 {
2239 if (curbuf->b_p_vts_array)
2240 {
2241 vim_free(curbuf->b_p_vts_array);
2242 curbuf->b_p_vts_array = NULL;
2243 }
2244 }
2245 else
2246 {
2247 for (cp = *varp; *cp; ++cp)
2248 {
2249 if (vim_isdigit(*cp))
2250 continue;
2251 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
2252 continue;
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002253 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002254 break;
2255 }
2256 if (errmsg == NULL)
2257 {
2258 int *oldarray = curbuf->b_p_vts_array;
2259
Bram Moolenaarb7081e12021-09-04 18:47:28 +02002260 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)) == OK)
Bram Moolenaardac13472019-09-16 21:06:21 +02002261 {
2262 vim_free(oldarray);
2263#ifdef FEAT_FOLDING
2264 if (foldmethodIsIndent(curwin))
2265 foldUpdateAll(curwin);
2266#endif
2267 }
2268 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002269 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002270 }
2271 }
2272 }
2273#endif
2274
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002275#ifdef FEAT_PROP_POPUP
Bram Moolenaardac13472019-09-16 21:06:21 +02002276 // 'previewpopup'
2277 else if (varp == &p_pvp)
2278 {
2279 if (parse_previewpopup(NULL) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002280 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002281 }
2282# ifdef FEAT_QUICKFIX
2283 // 'completepopup'
2284 else if (varp == &p_cpp)
2285 {
2286 if (parse_completepopup(NULL) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002287 errmsg = e_invalid_argument;
Bram Moolenaar447bfba2020-07-18 16:07:16 +02002288 else
2289 popup_close_info();
Bram Moolenaardac13472019-09-16 21:06:21 +02002290 }
2291# endif
2292#endif
2293
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002294#ifdef FEAT_EVAL
2295 // '*expr' options
2296 else if (
2297# ifdef FEAT_BEVAL
2298 varp == &p_bexpr ||
2299# endif
2300# ifdef FEAT_DIFF
2301 varp == &p_dex ||
2302# endif
2303# ifdef FEAT_FOLDING
2304 varp == &curwin->w_p_fde ||
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002305 varp == &curwin->w_p_fdt ||
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002306# endif
2307 gvarp == &p_fex ||
2308# ifdef FEAT_FIND_ID
2309 gvarp == &p_inex ||
2310# endif
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002311 gvarp == &p_inde ||
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002312# ifdef FEAT_DIFF
2313 varp == &p_pex ||
2314# endif
2315# ifdef FEAT_POSTSCRIPT
2316 varp == &p_pexpr ||
2317# endif
Bram Moolenaarf4e88f22022-01-23 14:17:28 +00002318 varp == &p_ccv)
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002319 {
2320 char_u **p_opt = NULL;
2321 char_u *name;
2322
2323 // If the option value starts with <SID> or s:, then replace that with
2324 // the script identifier.
2325# ifdef FEAT_BEVAL
2326 if (varp == &p_bexpr) // 'balloonexpr'
2327 p_opt = (opt_flags & OPT_LOCAL) ? &curbuf->b_p_bexpr : &p_bexpr;
2328# endif
2329# ifdef FEAT_DIFF
2330 if (varp == &p_dex) // 'diffexpr'
2331 p_opt = &p_dex;
2332# endif
2333# ifdef FEAT_FOLDING
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002334 if (varp == &curwin->w_p_fde) // 'foldexpr'
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002335 p_opt = &curwin->w_p_fde;
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002336 if (varp == &curwin->w_p_fdt) // 'foldtext'
2337 p_opt = &curwin->w_p_fdt;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002338# endif
2339 if (gvarp == &p_fex) // 'formatexpr'
2340 p_opt = &curbuf->b_p_fex;
2341# ifdef FEAT_FIND_ID
2342 if (gvarp == &p_inex) // 'includeexpr'
2343 p_opt = &curbuf->b_p_inex;
2344# endif
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002345 if (gvarp == &p_inde) // 'indentexpr'
2346 p_opt = &curbuf->b_p_inde;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002347# ifdef FEAT_DIFF
2348 if (varp == &p_pex) // 'patchexpr'
2349 p_opt = &p_pex;
2350# endif
2351# ifdef FEAT_POSTSCRIPT
2352 if (varp == &p_pexpr) // 'printexpr'
2353 p_opt = &p_pexpr;
2354# endif
Bram Moolenaarf4e88f22022-01-23 14:17:28 +00002355 if (varp == &p_ccv) // 'charconvert'
2356 p_opt = &p_ccv;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002357
2358 if (p_opt != NULL)
2359 {
2360 name = get_scriptlocal_funcname(*p_opt);
2361 if (name != NULL)
2362 {
zeertzjqf6782732022-07-27 18:26:03 +01002363 free_string_option(*p_opt);
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002364 *p_opt = name;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002365 }
2366 }
2367
2368# ifdef FEAT_FOLDING
2369 if (varp == &curwin->w_p_fde && foldmethodIsExpr(curwin))
2370 foldUpdateAll(curwin);
2371# endif
2372 }
2373#endif
2374
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002375#ifdef FEAT_COMPL_FUNC
2376 // 'completefunc'
2377 else if (gvarp == &p_cfu)
2378 {
2379 if (set_completefunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002380 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002381 }
2382
2383 // 'omnifunc'
2384 else if (gvarp == &p_ofu)
2385 {
2386 if (set_omnifunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002387 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002388 }
2389
2390 // 'thesaurusfunc'
2391 else if (gvarp == &p_tsrfu)
2392 {
2393 if (set_thesaurusfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002394 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002395 }
2396#endif
2397
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002398#if defined(FEAT_EVAL) && \
2399 (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL))
2400 // 'imactivatefunc'
2401 else if (gvarp == &p_imaf)
2402 {
2403 if (set_imactivatefunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002404 errmsg = e_invalid_argument;
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002405 }
2406
2407 // 'imstatusfunc'
2408 else if (gvarp == &p_imsf)
2409 {
2410 if (set_imstatusfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002411 errmsg = e_invalid_argument;
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002412 }
2413#endif
2414
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002415 // 'operatorfunc'
2416 else if (varp == &p_opfunc)
2417 {
2418 if (set_operatorfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002419 errmsg = e_invalid_argument;
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002420 }
2421
Bram Moolenaard43906d2020-07-20 21:31:32 +02002422#ifdef FEAT_QUICKFIX
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002423 // 'quickfixtextfunc'
Bram Moolenaard43906d2020-07-20 21:31:32 +02002424 else if (varp == &p_qftf)
2425 {
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002426 if (qf_process_qftf_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002427 errmsg = e_invalid_argument;
Bram Moolenaard43906d2020-07-20 21:31:32 +02002428 }
2429#endif
2430
Yegappan Lakshmanan19916a82021-11-24 16:32:55 +00002431#ifdef FEAT_EVAL
2432 // 'tagfunc'
2433 else if (gvarp == &p_tfu)
2434 {
2435 if (set_tagfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002436 errmsg = e_invalid_argument;
Yegappan Lakshmanan19916a82021-11-24 16:32:55 +00002437 }
2438#endif
2439
Bram Moolenaardac13472019-09-16 21:06:21 +02002440 // Options that are a list of flags.
2441 else
2442 {
2443 p = NULL;
2444 if (varp == &p_ww) // 'whichwrap'
2445 p = (char_u *)WW_ALL;
2446 if (varp == &p_shm) // 'shortmess'
2447 p = (char_u *)SHM_ALL;
2448 else if (varp == &(p_cpo)) // 'cpoptions'
2449 p = (char_u *)CPO_ALL;
2450 else if (varp == &(curbuf->b_p_fo)) // 'formatoptions'
2451 p = (char_u *)FO_ALL;
2452#ifdef FEAT_CONCEAL
2453 else if (varp == &curwin->w_p_cocu) // 'concealcursor'
2454 p = (char_u *)COCU_ALL;
2455#endif
2456 else if (varp == &p_mouse) // 'mouse'
2457 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002458 p = (char_u *)MOUSE_ALL;
Bram Moolenaardac13472019-09-16 21:06:21 +02002459 }
2460#if defined(FEAT_GUI)
2461 else if (varp == &p_go) // 'guioptions'
2462 p = (char_u *)GO_ALL;
2463#endif
2464 if (p != NULL)
2465 {
2466 for (s = *varp; *s; ++s)
2467 if (vim_strchr(p, *s) == NULL)
2468 {
2469 errmsg = illegal_char(errbuf, *s);
2470 break;
2471 }
2472 }
2473 }
2474
2475 // If error detected, restore the previous value.
2476 if (errmsg != NULL)
2477 {
zeertzjqf6782732022-07-27 18:26:03 +01002478 free_string_option(*varp);
Bram Moolenaardac13472019-09-16 21:06:21 +02002479 *varp = oldval;
2480 // When resetting some values, need to act on it.
2481 if (did_chartab)
2482 (void)init_chartab();
2483 if (varp == &p_hl)
2484 (void)highlight_changed();
2485 }
2486 else
2487 {
2488#ifdef FEAT_EVAL
2489 // Remember where the option was set.
2490 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
2491#endif
2492 // Free string options that are in allocated memory.
2493 // Use "free_oldval", because recursiveness may change the flags under
2494 // our fingers (esp. init_highlight()).
2495 if (free_oldval)
2496 free_string_option(oldval);
zeertzjqf6782732022-07-27 18:26:03 +01002497 set_option_flag(opt_idx, P_ALLOCED);
Bram Moolenaardac13472019-09-16 21:06:21 +02002498
2499 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
2500 && is_global_local_option(opt_idx))
2501 {
2502 // global option with local value set to use global value; free
2503 // the local value and make it empty
2504 p = get_option_varp_scope(opt_idx, OPT_LOCAL);
2505 free_string_option(*(char_u **)p);
2506 *(char_u **)p = empty_option;
2507 }
2508
2509 // May set global value for local option.
2510 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
2511 set_string_option_global(opt_idx, varp);
2512
2513 // Trigger the autocommand only after setting the flags.
2514#ifdef FEAT_SYN_HL
2515 // When 'syntax' is set, load the syntax of that name
2516 if (varp == &(curbuf->b_p_syn))
2517 {
2518 static int syn_recursive = 0;
2519
2520 ++syn_recursive;
2521 // Only pass TRUE for "force" when the value changed or not used
2522 // recursively, to avoid endless recurrence.
2523 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
2524 value_changed || syn_recursive == 1, curbuf);
2525 curbuf->b_flags |= BF_SYN_SET;
2526 --syn_recursive;
2527 }
2528#endif
2529 else if (varp == &(curbuf->b_p_ft))
2530 {
2531 // 'filetype' is set, trigger the FileType autocommand.
2532 // Skip this when called from a modeline and the filetype was
2533 // already set to this value.
2534 if (!(opt_flags & OPT_MODELINE) || value_changed)
2535 {
2536 static int ft_recursive = 0;
2537 int secure_save = secure;
2538
2539 // Reset the secure flag, since the value of 'filetype' has
2540 // been checked to be safe.
2541 secure = 0;
2542
2543 ++ft_recursive;
2544 did_filetype = TRUE;
2545 // Only pass TRUE for "force" when the value changed or not
2546 // used recursively, to avoid endless recurrence.
2547 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
2548 value_changed || ft_recursive == 1, curbuf);
2549 --ft_recursive;
2550 // Just in case the old "curbuf" is now invalid.
2551 if (varp != &(curbuf->b_p_ft))
2552 varp = NULL;
2553
2554 secure = secure_save;
2555 }
2556 }
2557#ifdef FEAT_SPELL
2558 if (varp == &(curwin->w_s->b_p_spl))
2559 {
2560 char_u fname[200];
2561 char_u *q = curwin->w_s->b_p_spl;
2562
2563 // Skip the first name if it is "cjk".
2564 if (STRNCMP(q, "cjk,", 4) == 0)
2565 q += 4;
2566
2567 // Source the spell/LANG.vim in 'runtimepath'.
2568 // They could set 'spellcapcheck' depending on the language.
2569 // Use the first name in 'spelllang' up to '_region' or
2570 // '.encoding'.
2571 for (p = q; *p != NUL; ++p)
2572 if (!ASCII_ISALNUM(*p) && *p != '-')
2573 break;
2574 if (p > q)
2575 {
2576 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
2577 (int)(p - q), q);
2578 source_runtime(fname, DIP_ALL);
2579 }
2580 }
2581#endif
2582 }
2583
Bram Moolenaardac13472019-09-16 21:06:21 +02002584 if (varp == &p_mouse)
2585 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002586 if (*p_mouse == NUL)
2587 mch_setmouse(FALSE); // switch mouse off
2588 else
Bram Moolenaardac13472019-09-16 21:06:21 +02002589 setmouse(); // in case 'mouse' changed
2590 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002591
Bram Moolenaar788fbb42020-05-31 14:08:12 +02002592#if defined(FEAT_LUA) || defined(PROTO)
2593 if (varp == &p_rtp)
2594 update_package_paths_in_lua();
2595#endif
2596
Bram Moolenaarb2d85e32022-01-07 16:55:32 +00002597#if defined(FEAT_LINEBREAK)
2598 // Changing Formatlistpattern when briopt includes the list setting:
2599 // redraw
2600 if ((varp == &p_flp || varp == &(curbuf->b_p_flp))
2601 && curwin->w_briopt_list)
Bram Moolenaara4d158b2022-08-14 14:17:45 +01002602 redraw_all_later(UPD_NOT_VALID);
Bram Moolenaarb2d85e32022-01-07 16:55:32 +00002603#endif
2604
Bram Moolenaardac13472019-09-16 21:06:21 +02002605 if (curwin->w_curswant != MAXCOL
Bram Moolenaara1cb1d12019-10-17 23:00:07 +02002606 && (get_option_flags(opt_idx) & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaardac13472019-09-16 21:06:21 +02002607 curwin->w_set_curswant = TRUE;
2608
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002609 if ((opt_flags & OPT_NO_REDRAW) == 0)
2610 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002611#ifdef FEAT_GUI
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002612 // check redraw when it's not a GUI option or the GUI is active.
2613 if (!redraw_gui_only || gui.in_use)
Bram Moolenaardac13472019-09-16 21:06:21 +02002614#endif
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002615 check_redraw(get_option_flags(opt_idx));
2616 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002617
2618#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
2619 if (did_swaptcap)
2620 {
2621 set_termname((char_u *)"win32");
2622 init_highlight(TRUE, FALSE);
2623 }
2624#endif
2625
2626 return errmsg;
2627}
2628
2629/*
2630 * Check an option that can be a range of string values.
2631 *
2632 * Return OK for correct value, FAIL otherwise.
2633 * Empty is always OK.
2634 */
2635 static int
2636check_opt_strings(
2637 char_u *val,
2638 char **values,
2639 int list) // when TRUE: accept a list of values
2640{
2641 return opt_strings_flags(val, values, NULL, list);
2642}
2643
2644/*
2645 * Handle an option that can be a range of string values.
2646 * Set a flag in "*flagp" for each string present.
2647 *
2648 * Return OK for correct value, FAIL otherwise.
2649 * Empty is always OK.
2650 */
2651 static int
2652opt_strings_flags(
2653 char_u *val, // new value
2654 char **values, // array of valid string values
2655 unsigned *flagp,
2656 int list) // when TRUE: accept a list of values
2657{
2658 int i;
2659 int len;
2660 unsigned new_flags = 0;
2661
2662 while (*val)
2663 {
2664 for (i = 0; ; ++i)
2665 {
2666 if (values[i] == NULL) // val not found in values[]
2667 return FAIL;
2668
2669 len = (int)STRLEN(values[i]);
2670 if (STRNCMP(values[i], val, len) == 0
2671 && ((list && val[len] == ',') || val[len] == NUL))
2672 {
2673 val += len + (val[len] == ',');
2674 new_flags |= (1 << i);
2675 break; // check next item in val list
2676 }
2677 }
2678 }
2679 if (flagp != NULL)
2680 *flagp = new_flags;
2681
2682 return OK;
2683}
2684
2685/*
2686 * return OK if "p" is a valid fileformat name, FAIL otherwise.
2687 */
2688 int
2689check_ff_value(char_u *p)
2690{
2691 return check_opt_strings(p, p_ff_values, FALSE);
2692}