blob: 1f9a0e5d5213de857c8509a0c052dc67b428a24e [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};
Bram Moolenaardac13472019-09-16 21:06:21 +020049static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL};
50#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
51static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL};
52#endif
53#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
54static char *(p_tbis_values[]) = {"tiny", "small", "medium", "large", "huge", "giant", NULL};
55#endif
Bram Moolenaara1cb1d12019-10-17 23:00:07 +020056#if defined(UNIX) || defined(VMS)
Bram Moolenaardac13472019-09-16 21:06:21 +020057static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL};
58#endif
Gary Johnson53ba05b2021-07-26 22:19:10 +020059static char *(p_ve_values[]) = {"block", "insert", "all", "onemore", "none", "NONE", NULL};
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +000060static char *(p_wop_values[]) = {"fuzzy", "tagfile", "pum", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020061#ifdef FEAT_WAK
62static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
63#endif
64static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
65static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
66static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
67static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
68#ifdef FEAT_BROWSE
69static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
70#endif
71static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
72static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
73static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
74static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
75static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaaraa0489e2020-04-17 19:41:21 +020076static char *(p_bs_values[]) = {"indent", "eol", "start", "nostop", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020077#ifdef FEAT_FOLDING
78static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
79# ifdef FEAT_DIFF
80 "diff",
81# endif
82 NULL};
83static char *(p_fcl_values[]) = {"all", NULL};
84#endif
Bram Moolenaardca7abe2019-10-20 18:17:57 +020085static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "popuphidden", "noinsert", "noselect", NULL};
Bram Moolenaardac13472019-09-16 21:06:21 +020086#ifdef BACKSLASH_IN_FILENAME
87static char *(p_csl_values[]) = {"slash", "backslash", NULL};
88#endif
89#ifdef FEAT_SIGNS
90static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
91#endif
92#if defined(MSWIN) && defined(FEAT_TERMINAL)
93static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
94#endif
95
96static int check_opt_strings(char_u *val, char **values, int list);
97static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
98
99/*
100 * After setting various option values: recompute variables that depend on
101 * option values.
102 */
103 void
104didset_string_options(void)
105{
106 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
107 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
108 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
109#ifdef FEAT_SESSION
110 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
111 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
112#endif
113#ifdef FEAT_FOLDING
114 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
115#endif
116 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
117 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
118 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaara1cb1d12019-10-17 23:00:07 +0200119#if defined(UNIX) || defined(VMS)
Bram Moolenaardac13472019-09-16 21:06:21 +0200120 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
121#endif
122#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
123 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
124#endif
125#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
126 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
127#endif
Sean Dewar39c46b42022-05-12 17:44:29 +0100128 (void)opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE);
Bram Moolenaardac13472019-09-16 21:06:21 +0200129}
130
131#if defined(FEAT_EVAL)
132/*
133 * Trigger the OptionSet autocommand.
134 * "opt_idx" is the index of the option being set.
135 * "opt_flags" can be OPT_LOCAL etc.
136 * "oldval" the old value
137 * "oldval_l" the old local value (only non-NULL if global and local value
138 * are set)
139 * "oldval_g" the old global value (only non-NULL if global and local value
140 * are set)
141 * "newval" the new value
142 */
143 void
144trigger_optionsset_string(
145 int opt_idx,
146 int opt_flags,
147 char_u *oldval,
148 char_u *oldval_l,
149 char_u *oldval_g,
150 char_u *newval)
151{
152 // Don't do this recursively.
153 if (oldval != NULL && newval != NULL
154 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
155 {
156 char_u buf_type[7];
157
158 sprintf((char *)buf_type, "%s",
159 (opt_flags & OPT_LOCAL) ? "local" : "global");
160 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
161 set_vim_var_string(VV_OPTION_NEW, newval, -1);
162 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
163 if (opt_flags & OPT_LOCAL)
164 {
165 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
166 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
167 }
168 if (opt_flags & OPT_GLOBAL)
169 {
170 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
171 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
172 }
173 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
174 {
175 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
176 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
177 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
178 }
179 if (opt_flags & OPT_MODELINE)
180 {
181 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
182 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
183 }
184 apply_autocmds(EVENT_OPTIONSET,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +0000185 get_option_fullname(opt_idx), NULL, FALSE,
Bram Moolenaardac13472019-09-16 21:06:21 +0200186 NULL);
187 reset_v_option_vars();
188 }
189}
190#endif
191
192 static char *
193illegal_char(char *errbuf, int c)
194{
195 if (errbuf == NULL)
196 return "";
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000197 sprintf((char *)errbuf, _(e_illegal_character_str), (char *)transchar(c));
Bram Moolenaardac13472019-09-16 21:06:21 +0200198 return errbuf;
199}
200
201/*
202 * Check string options in a buffer for NULL value.
203 */
204 void
205check_buf_options(buf_T *buf)
206{
207 check_string_option(&buf->b_p_bh);
208 check_string_option(&buf->b_p_bt);
209 check_string_option(&buf->b_p_fenc);
210 check_string_option(&buf->b_p_ff);
211#ifdef FEAT_FIND_ID
212 check_string_option(&buf->b_p_def);
213 check_string_option(&buf->b_p_inc);
214# ifdef FEAT_EVAL
215 check_string_option(&buf->b_p_inex);
216# endif
217#endif
Bram Moolenaar8e145b82022-05-21 20:17:31 +0100218#if defined(FEAT_EVAL)
Bram Moolenaardac13472019-09-16 21:06:21 +0200219 check_string_option(&buf->b_p_inde);
220 check_string_option(&buf->b_p_indk);
221#endif
222#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
223 check_string_option(&buf->b_p_bexpr);
224#endif
225#if defined(FEAT_CRYPT)
226 check_string_option(&buf->b_p_cm);
227#endif
228 check_string_option(&buf->b_p_fp);
229#if defined(FEAT_EVAL)
230 check_string_option(&buf->b_p_fex);
231#endif
232#ifdef FEAT_CRYPT
233 check_string_option(&buf->b_p_key);
234#endif
235 check_string_option(&buf->b_p_kp);
236 check_string_option(&buf->b_p_mps);
237 check_string_option(&buf->b_p_fo);
238 check_string_option(&buf->b_p_flp);
239 check_string_option(&buf->b_p_isk);
Bram Moolenaardac13472019-09-16 21:06:21 +0200240 check_string_option(&buf->b_p_com);
Bram Moolenaardac13472019-09-16 21:06:21 +0200241#ifdef FEAT_FOLDING
242 check_string_option(&buf->b_p_cms);
243#endif
244 check_string_option(&buf->b_p_nf);
245#ifdef FEAT_TEXTOBJ
246 check_string_option(&buf->b_p_qe);
247#endif
248#ifdef FEAT_SYN_HL
249 check_string_option(&buf->b_p_syn);
250 check_string_option(&buf->b_s.b_syn_isk);
251#endif
252#ifdef FEAT_SPELL
253 check_string_option(&buf->b_s.b_p_spc);
254 check_string_option(&buf->b_s.b_p_spf);
255 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar362b44b2020-06-10 21:47:00 +0200256 check_string_option(&buf->b_s.b_p_spo);
Bram Moolenaardac13472019-09-16 21:06:21 +0200257#endif
258#ifdef FEAT_SEARCHPATH
259 check_string_option(&buf->b_p_sua);
260#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200261 check_string_option(&buf->b_p_cink);
262 check_string_option(&buf->b_p_cino);
Tom Praschan3506cf32022-04-07 12:39:08 +0100263 check_string_option(&buf->b_p_cinsd);
Bram Moolenaardac13472019-09-16 21:06:21 +0200264 parse_cino(buf);
Bram Moolenaardac13472019-09-16 21:06:21 +0200265 check_string_option(&buf->b_p_ft);
Bram Moolenaardac13472019-09-16 21:06:21 +0200266 check_string_option(&buf->b_p_cinw);
Bram Moolenaardac13472019-09-16 21:06:21 +0200267 check_string_option(&buf->b_p_cpt);
268#ifdef FEAT_COMPL_FUNC
269 check_string_option(&buf->b_p_cfu);
270 check_string_option(&buf->b_p_ofu);
Bram Moolenaard4c4bfa2021-10-16 21:14:11 +0100271 check_string_option(&buf->b_p_tsrfu);
Bram Moolenaardac13472019-09-16 21:06:21 +0200272#endif
273#ifdef FEAT_EVAL
274 check_string_option(&buf->b_p_tfu);
275#endif
276#ifdef FEAT_KEYMAP
277 check_string_option(&buf->b_p_keymap);
278#endif
279#ifdef FEAT_QUICKFIX
280 check_string_option(&buf->b_p_gp);
281 check_string_option(&buf->b_p_mp);
282 check_string_option(&buf->b_p_efm);
283#endif
284 check_string_option(&buf->b_p_ep);
285 check_string_option(&buf->b_p_path);
286 check_string_option(&buf->b_p_tags);
287 check_string_option(&buf->b_p_tc);
288 check_string_option(&buf->b_p_dict);
289 check_string_option(&buf->b_p_tsr);
Bram Moolenaardac13472019-09-16 21:06:21 +0200290 check_string_option(&buf->b_p_lw);
Bram Moolenaardac13472019-09-16 21:06:21 +0200291 check_string_option(&buf->b_p_bkc);
292 check_string_option(&buf->b_p_menc);
293#ifdef FEAT_VARTABS
294 check_string_option(&buf->b_p_vsts);
295 check_string_option(&buf->b_p_vts);
296#endif
297}
298
299/*
300 * Free the string allocated for an option.
301 * Checks for the string being empty_option. This may happen if we're out of
302 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
303 * check_options().
304 * Does NOT check for P_ALLOCED flag!
305 */
306 void
307free_string_option(char_u *p)
308{
309 if (p != empty_option)
310 vim_free(p);
311}
312
313 void
314clear_string_option(char_u **pp)
315{
316 if (*pp != empty_option)
317 vim_free(*pp);
318 *pp = empty_option;
319}
320
321 void
322check_string_option(char_u **pp)
323{
324 if (*pp == NULL)
325 *pp = empty_option;
326}
327
328/*
329 * Set global value for string option when it's a local option.
330 */
331 static void
332set_string_option_global(
333 int opt_idx, // option index
334 char_u **varp) // pointer to option variable
335{
336 char_u **p, *s;
337
338 // the global value is always allocated
339 if (is_window_local_option(opt_idx))
340 p = (char_u **)GLOBAL_WO(varp);
341 else
342 p = (char_u **)get_option_var(opt_idx);
343 if (!is_global_option(opt_idx)
344 && p != varp
345 && (s = vim_strsave(*varp)) != NULL)
346 {
347 free_string_option(*p);
348 *p = s;
349 }
350}
351
352/*
353 * Set a string option to a new value (without checking the effect).
354 * The string is copied into allocated memory.
355 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
356 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
357 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
358 * "set_sid".
359 */
360 void
361set_string_option_direct(
362 char_u *name,
363 int opt_idx,
364 char_u *val,
365 int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL
366 int set_sid UNUSED)
367{
368 char_u *s;
369 char_u **varp;
370 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
371 int idx = opt_idx;
372
373 if (idx == -1) // use name
374 {
375 idx = findoption(name);
376 if (idx < 0) // not found (should not happen)
377 {
Bram Moolenaar460ae5d2022-01-01 14:19:49 +0000378 semsg(_(e_internal_error_str), "set_string_option_direct()");
Bram Moolenaardac13472019-09-16 21:06:21 +0200379 siemsg(_("For option %s"), name);
380 return;
381 }
382 }
383
384 if (is_hidden_option(idx)) // can't set hidden option
385 return;
386
387 s = vim_strsave(val);
388 if (s != NULL)
389 {
390 varp = (char_u **)get_option_varp_scope(idx,
391 both ? OPT_LOCAL : opt_flags);
392 if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED))
393 free_string_option(*varp);
394 *varp = s;
395
396 // For buffer/window local option may also set the global value.
397 if (both)
398 set_string_option_global(idx, varp);
399
400 set_option_flag(idx, P_ALLOCED);
401
402 // When setting both values of a global option with a local value,
403 // make the local value empty, so that the global value is used.
404 if (is_global_local_option(idx) && both)
405 {
406 free_string_option(*varp);
407 *varp = empty_option;
408 }
409# ifdef FEAT_EVAL
410 if (set_sid != SID_NONE)
411 {
412 sctx_T script_ctx;
413
414 if (set_sid == 0)
415 script_ctx = current_sctx;
416 else
417 {
418 script_ctx.sc_sid = set_sid;
419 script_ctx.sc_seq = 0;
420 script_ctx.sc_lnum = 0;
421 script_ctx.sc_version = 1;
422 }
423 set_option_sctx_idx(idx, opt_flags, script_ctx);
424 }
425# endif
426 }
427}
428
429/*
430 * Like set_string_option_direct(), but for a window-local option in "wp".
431 * Blocks autocommands to avoid the old curwin becoming invalid.
432 */
433 void
434set_string_option_direct_in_win(
435 win_T *wp,
436 char_u *name,
437 int opt_idx,
438 char_u *val,
439 int opt_flags,
440 int set_sid)
441{
442 win_T *save_curwin = curwin;
443
444 block_autocmds();
445 curwin = wp;
446 curbuf = curwin->w_buffer;
447 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
448 curwin = save_curwin;
449 curbuf = curwin->w_buffer;
450 unblock_autocmds();
451}
452
Dominique Pelle748b3082022-01-08 12:41:16 +0000453#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaardac13472019-09-16 21:06:21 +0200454/*
455 * Like set_string_option_direct(), but for a buffer-local option in "buf".
456 * Blocks autocommands to avoid the old curbuf becoming invalid.
457 */
458 void
459set_string_option_direct_in_buf(
460 buf_T *buf,
461 char_u *name,
462 int opt_idx,
463 char_u *val,
464 int opt_flags,
465 int set_sid)
466{
467 buf_T *save_curbuf = curbuf;
468
469 block_autocmds();
470 curbuf = buf;
471 curwin->w_buffer = curbuf;
472 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
473 curbuf = save_curbuf;
474 curwin->w_buffer = curbuf;
475 unblock_autocmds();
476}
Dominique Pelle748b3082022-01-08 12:41:16 +0000477#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200478
479/*
480 * Set a string option to a new value, and handle the effects.
481 *
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100482 * Returns NULL on success or an untranslated error message on error.
Bram Moolenaardac13472019-09-16 21:06:21 +0200483 */
484 char *
485set_string_option(
486 int opt_idx,
487 char_u *value,
488 int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL
489{
490 char_u *s;
491 char_u **varp;
492 char_u *oldval;
493#if defined(FEAT_EVAL)
494 char_u *oldval_l = NULL;
495 char_u *oldval_g = NULL;
496 char_u *saved_oldval = NULL;
497 char_u *saved_oldval_l = NULL;
498 char_u *saved_oldval_g = NULL;
499 char_u *saved_newval = NULL;
500#endif
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100501 char *errmsg = NULL;
Bram Moolenaardac13472019-09-16 21:06:21 +0200502 int value_checked = FALSE;
503
504 if (is_hidden_option(opt_idx)) // don't set hidden option
505 return NULL;
506
Bram Moolenaar7f009df2020-03-16 20:27:38 +0100507 s = vim_strsave(value == NULL ? (char_u *)"" : value);
Bram Moolenaardac13472019-09-16 21:06:21 +0200508 if (s != NULL)
509 {
510 varp = (char_u **)get_option_varp_scope(opt_idx,
511 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
512 ? (is_global_local_option(opt_idx)
513 ? OPT_GLOBAL : OPT_LOCAL)
514 : opt_flags);
515 oldval = *varp;
516#if defined(FEAT_EVAL)
517 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
518 {
519 oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL);
520 oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
521 }
522#endif
523 *varp = s;
524
525#if defined(FEAT_EVAL)
526 if (!starting
527# ifdef FEAT_CRYPT
528 && !is_crypt_key_option(opt_idx)
529# endif
530 )
531 {
532 if (oldval_l != NULL)
533 saved_oldval_l = vim_strsave(oldval_l);
534 if (oldval_g != NULL)
535 saved_oldval_g = vim_strsave(oldval_g);
536 saved_oldval = vim_strsave(oldval);
537 saved_newval = vim_strsave(s);
538 }
539#endif
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100540 if ((errmsg = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaardac13472019-09-16 21:06:21 +0200541 opt_flags, &value_checked)) == NULL)
542 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
543
544#if defined(FEAT_EVAL)
545 // call autocommand after handling side effects
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100546 if (errmsg == NULL)
Bram Moolenaardac13472019-09-16 21:06:21 +0200547 trigger_optionsset_string(opt_idx, opt_flags,
548 saved_oldval, saved_oldval_l,
549 saved_oldval_g, saved_newval);
550 vim_free(saved_oldval);
551 vim_free(saved_oldval_l);
552 vim_free(saved_oldval_g);
553 vim_free(saved_newval);
554#endif
555 }
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100556 return errmsg;
Bram Moolenaardac13472019-09-16 21:06:21 +0200557}
558
559/*
560 * Return TRUE if "val" is a valid 'filetype' name.
561 * Also used for 'syntax' and 'keymap'.
562 */
563 static int
564valid_filetype(char_u *val)
565{
566 return valid_name(val, ".-_");
567}
568
569#ifdef FEAT_STL_OPT
570/*
571 * Check validity of options with the 'statusline' format.
zeertzjq5dc294a2022-04-15 13:17:57 +0100572 * Return an untranslated error message or NULL.
Bram Moolenaardac13472019-09-16 21:06:21 +0200573 */
574 static char *
575check_stl_option(char_u *s)
576{
Bram Moolenaardac13472019-09-16 21:06:21 +0200577 int groupdepth = 0;
578 static char errbuf[80];
579
Bram Moolenaar8133cc62020-10-26 21:05:27 +0100580 while (*s)
Bram Moolenaardac13472019-09-16 21:06:21 +0200581 {
582 // Check for valid keys after % sequences
583 while (*s && *s != '%')
584 s++;
585 if (!*s)
586 break;
587 s++;
Bram Moolenaardac13472019-09-16 21:06:21 +0200588 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
589 {
590 s++;
591 continue;
592 }
593 if (*s == ')')
594 {
595 s++;
596 if (--groupdepth < 0)
597 break;
598 continue;
599 }
600 if (*s == '-')
601 s++;
602 while (VIM_ISDIGIT(*s))
603 s++;
604 if (*s == STL_USER_HL)
605 continue;
606 if (*s == '.')
607 {
608 s++;
609 while (*s && VIM_ISDIGIT(*s))
610 s++;
611 }
612 if (*s == '(')
613 {
614 groupdepth++;
615 continue;
616 }
617 if (vim_strchr(STL_ALL, *s) == NULL)
618 {
619 return illegal_char(errbuf, *s);
620 }
621 if (*s == '{')
622 {
zeertzjq5dc294a2022-04-15 13:17:57 +0100623 int reevaluate = (*++s == '%');
shadmansaleh30e3de22021-05-15 17:23:28 +0200624
zeertzjq5dc294a2022-04-15 13:17:57 +0100625 if (reevaluate && *++s == '}')
626 // "}" is not allowed immediately after "%{%"
627 return illegal_char(errbuf, '}');
shadmansaleh30e3de22021-05-15 17:23:28 +0200628 while ((*s != '}' || (reevaluate && s[-1] != '%')) && *s)
Bram Moolenaardac13472019-09-16 21:06:21 +0200629 s++;
630 if (*s != '}')
zeertzjq5dc294a2022-04-15 13:17:57 +0100631 return e_unclosed_expression_sequence;
Bram Moolenaardac13472019-09-16 21:06:21 +0200632 }
633 }
Bram Moolenaardac13472019-09-16 21:06:21 +0200634 if (groupdepth != 0)
zeertzjq5dc294a2022-04-15 13:17:57 +0100635 return e_unbalanced_groups;
Bram Moolenaardac13472019-09-16 21:06:21 +0200636 return NULL;
637}
638#endif
639
640/*
641 * Handle string options that need some action to perform when changed.
LemonBoy77142312022-04-15 20:50:46 +0100642 * Returns NULL for success, or an unstranslated error message for an error.
Bram Moolenaardac13472019-09-16 21:06:21 +0200643 */
644 char *
645did_set_string_option(
646 int opt_idx, // index in options[] table
647 char_u **varp, // pointer to the option variable
648 int new_value_alloced, // new value was allocated
649 char_u *oldval, // previous value of the option
650 char *errbuf, // buffer for errors, or NULL
651 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
652 int *value_checked) // value was checked to be save, no
653 // need to set P_INSECURE
654{
655 char *errmsg = NULL;
656 char_u *s, *p;
657 int did_chartab = FALSE;
658 char_u **gvarp;
659 long_u free_oldval = (get_option_flags(opt_idx) & P_ALLOCED);
660#ifdef FEAT_GUI
661 // set when changing an option that only requires a redraw in the GUI
662 int redraw_gui_only = FALSE;
663#endif
664 int value_changed = FALSE;
665#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
666 int did_swaptcap = FALSE;
667#endif
668
669 // Get the global option to compare with, otherwise we would have to check
670 // two values for all local options.
671 gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL);
672
673 // Disallow changing some options from secure mode
674 if ((secure
675#ifdef HAVE_SANDBOX
676 || sandbox != 0
677#endif
678 ) && (get_option_flags(opt_idx) & P_SECURE))
Bram Moolenaar74409f62022-01-01 15:58:22 +0000679 errmsg = e_not_allowed_here;
Bram Moolenaardac13472019-09-16 21:06:21 +0200680
681 // Check for a "normal" directory or file name in some options. Disallow a
682 // path separator (slash and/or backslash), wildcards and characters that
683 // are often illegal in a file name. Be more permissive if "secure" is off.
684 else if (((get_option_flags(opt_idx) & P_NFNAME)
685 && vim_strpbrk(*varp, (char_u *)(secure
686 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
687 || ((get_option_flags(opt_idx) & P_NDNAME)
688 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000689 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200690
691 // 'term'
692 else if (varp == &T_NAME)
693 {
694 if (T_NAME[0] == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000695 errmsg = e_cannot_set_term_to_empty_string;
Bram Moolenaardac13472019-09-16 21:06:21 +0200696#ifdef FEAT_GUI
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100697 else if (gui.in_use)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000698 errmsg = e_cannot_change_term_in_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +0200699 else if (term_is_gui(T_NAME))
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000700 errmsg = e_use_gui_to_start_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +0200701#endif
702 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +0000703 errmsg = e_not_found_in_termcap;
Bram Moolenaardac13472019-09-16 21:06:21 +0200704 else
705 {
706 // Screen colors may have changed.
707 redraw_later_clear();
708
709 // Both 'term' and 'ttytype' point to T_NAME, only set the
710 // P_ALLOCED flag on 'term'.
711 opt_idx = findoption((char_u *)"term");
712 free_oldval = (get_option_flags(opt_idx) & P_ALLOCED);
713 }
714 }
715
716 // 'backupcopy'
717 else if (gvarp == &p_bkc)
718 {
719 char_u *bkc = p_bkc;
720 unsigned int *flags = &bkc_flags;
721
722 if (opt_flags & OPT_LOCAL)
723 {
724 bkc = curbuf->b_p_bkc;
725 flags = &curbuf->b_bkc_flags;
726 }
727
728 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
729 // make the local value empty: use the global value
730 *flags = 0;
731 else
732 {
733 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000734 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200735 if ((((int)*flags & BKC_AUTO) != 0)
736 + (((int)*flags & BKC_YES) != 0)
737 + (((int)*flags & BKC_NO) != 0) != 1)
738 {
739 // Must have exactly one of "auto", "yes" and "no".
740 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000741 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200742 }
743 }
744 }
745
746 // 'backupext' and 'patchmode'
747 else if (varp == &p_bex || varp == &p_pm)
748 {
749 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
750 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100751 errmsg = e_backupext_and_patchmode_are_equal;
Bram Moolenaardac13472019-09-16 21:06:21 +0200752 }
753#ifdef FEAT_LINEBREAK
754 // 'breakindentopt'
755 else if (varp == &curwin->w_p_briopt)
756 {
757 if (briopt_check(curwin) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000758 errmsg = e_invalid_argument;
Bram Moolenaarb2d85e32022-01-07 16:55:32 +0000759 // list setting requires a redraw
760 if (curwin->w_briopt_list)
761 redraw_all_later(NOT_VALID);
Bram Moolenaardac13472019-09-16 21:06:21 +0200762 }
763#endif
764
765 // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
766 // If the new option is invalid, use old value. 'lisp' option: refill
767 // g_chartab[] for '-' char
768 else if ( varp == &p_isi
769 || varp == &(curbuf->b_p_isk)
770 || varp == &p_isp
771 || varp == &p_isf)
772 {
773 if (init_chartab() == FAIL)
774 {
775 did_chartab = TRUE; // need to restore it below
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000776 errmsg = e_invalid_argument; // error in value
Bram Moolenaardac13472019-09-16 21:06:21 +0200777 }
778 }
779
780 // 'helpfile'
781 else if (varp == &p_hf)
782 {
783 // May compute new values for $VIM and $VIMRUNTIME
784 if (didset_vim)
LemonBoy77142312022-04-15 20:50:46 +0100785 vim_unsetenv_ext((char_u *)"VIM");
Bram Moolenaardac13472019-09-16 21:06:21 +0200786 if (didset_vimruntime)
LemonBoy77142312022-04-15 20:50:46 +0100787 vim_unsetenv_ext((char_u *)"VIMRUNTIME");
Bram Moolenaardac13472019-09-16 21:06:21 +0200788 }
789
790#ifdef FEAT_SYN_HL
791 // 'cursorlineopt'
792 else if (varp == &curwin->w_p_culopt
793 || gvarp == &curwin->w_allbuf_opt.wo_culopt)
794 {
795 if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000796 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200797 }
798
799 // 'colorcolumn'
800 else if (varp == &curwin->w_p_cc)
801 errmsg = check_colorcolumn(curwin);
802#endif
803
804#ifdef FEAT_MULTI_LANG
805 // 'helplang'
806 else if (varp == &p_hlg)
807 {
808 // Check for "", "ab", "ab,cd", etc.
809 for (s = p_hlg; *s != NUL; s += 3)
810 {
811 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
812 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000813 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200814 break;
815 }
816 if (s[2] == NUL)
817 break;
818 }
819 }
820#endif
821
822 // 'highlight'
823 else if (varp == &p_hl)
824 {
825 if (highlight_changed() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000826 errmsg = e_invalid_argument; // invalid flags
Bram Moolenaardac13472019-09-16 21:06:21 +0200827 }
828
829 // 'nrformats'
830 else if (gvarp == &p_nf)
831 {
832 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000833 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200834 }
835
836#ifdef FEAT_SESSION
837 // 'sessionoptions'
838 else if (varp == &p_ssop)
839 {
840 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000841 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200842 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
843 {
844 // Don't allow both "sesdir" and "curdir".
845 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000846 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200847 }
848 }
849 // 'viewoptions'
850 else if (varp == &p_vop)
851 {
852 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000853 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200854 }
855#endif
856
857 // 'scrollopt'
858 else if (varp == &p_sbo)
859 {
860 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000861 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200862 }
863
864 // 'ambiwidth'
865 else if (varp == &p_ambw || varp == &p_emoji)
866 {
867 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000868 errmsg = e_invalid_argument;
Bram Moolenaareed9d462021-02-15 20:38:25 +0100869 else if (set_chars_option(curwin, &p_fcs) != NULL)
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100870 errmsg = e_conflicts_with_value_of_fillchars;
Bram Moolenaareed9d462021-02-15 20:38:25 +0100871 else
872 {
873 tabpage_T *tp;
874 win_T *wp;
875
876 FOR_ALL_TAB_WINDOWS(tp, wp)
877 {
878 if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
879 {
Bram Moolenaar31e5c602022-04-15 13:53:33 +0100880 errmsg = e_conflicts_with_value_of_listchars;
Bram Moolenaareed9d462021-02-15 20:38:25 +0100881 goto ambw_end;
882 }
883 }
884 }
885ambw_end:
886 {}
Bram Moolenaardac13472019-09-16 21:06:21 +0200887 }
888
889 // 'background'
890 else if (varp == &p_bg)
891 {
892 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
893 {
894#ifdef FEAT_EVAL
895 int dark = (*p_bg == 'd');
896#endif
897
898 init_highlight(FALSE, FALSE);
899
900#ifdef FEAT_EVAL
901 if (dark != (*p_bg == 'd')
902 && get_var_value((char_u *)"g:colors_name") != NULL)
903 {
904 // The color scheme must have set 'background' back to another
905 // value, that's not what we want here. Disable the color
906 // scheme and set the colors again.
907 do_unlet((char_u *)"g:colors_name", TRUE);
908 free_string_option(p_bg);
909 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
910 check_string_option(&p_bg);
911 init_highlight(FALSE, FALSE);
912 }
913#endif
Bram Moolenaarad431992021-05-03 20:40:38 +0200914#ifdef FEAT_TERMINAL
915 term_update_colors_all();
916#endif
Bram Moolenaardac13472019-09-16 21:06:21 +0200917 }
918 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000919 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200920 }
921
922 // 'wildmode'
923 else if (varp == &p_wim)
924 {
925 if (check_opt_wim() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000926 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200927 }
928
929 // 'wildoptions'
930 else if (varp == &p_wop)
931 {
932 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000933 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200934 }
935
936#ifdef FEAT_WAK
937 // 'winaltkeys'
938 else if (varp == &p_wak)
939 {
940 if (*p_wak == NUL
941 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000942 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200943# ifdef FEAT_MENU
ichizok02560422022-04-05 14:18:44 +0100944# if defined(FEAT_GUI_MOTIF)
Bram Moolenaardac13472019-09-16 21:06:21 +0200945 else if (gui.in_use)
946 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
ichizok02560422022-04-05 14:18:44 +0100947# elif defined(FEAT_GUI_GTK)
Bram Moolenaardac13472019-09-16 21:06:21 +0200948 else if (gui.in_use)
949 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
Bram Moolenaardac13472019-09-16 21:06:21 +0200950# endif
951# endif
952 }
953#endif
954
955 // 'eventignore'
956 else if (varp == &p_ei)
957 {
958 if (check_ei() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000959 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200960 }
961
962 // 'encoding', 'fileencoding', 'termencoding' and 'makeencoding'
963 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
964 || gvarp == &p_menc)
965 {
966 if (gvarp == &p_fenc)
967 {
968 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar108010a2021-06-27 22:03:33 +0200969 errmsg = e_cannot_make_changes_modifiable_is_off;
Bram Moolenaardac13472019-09-16 21:06:21 +0200970 else if (vim_strchr(*varp, ',') != NULL)
971 // No comma allowed in 'fileencoding'; catches confusing it
972 // with 'fileencodings'.
Bram Moolenaar436b5ad2021-12-31 22:49:24 +0000973 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +0200974 else
975 {
Bram Moolenaardac13472019-09-16 21:06:21 +0200976 // May show a "+" in the title now.
977 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +0200978 // Add 'fileencoding' to the swap file.
979 ml_setflags(curbuf);
980 }
981 }
982 if (errmsg == NULL)
983 {
984 // canonize the value, so that STRCMP() can be used on it
985 p = enc_canonize(*varp);
986 if (p != NULL)
987 {
988 vim_free(*varp);
989 *varp = p;
990 }
991 if (varp == &p_enc)
992 {
993 errmsg = mb_init();
Bram Moolenaardac13472019-09-16 21:06:21 +0200994 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +0200995 }
996 }
997
998#if defined(FEAT_GUI_GTK)
999 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
1000 {
Bram Moolenaard88be5b2022-01-04 19:57:55 +00001001 // GTK uses only a single encoding, and that is UTF-8.
Bram Moolenaardac13472019-09-16 21:06:21 +02001002 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaard88be5b2022-01-04 19:57:55 +00001003 errmsg = e_cannot_be_changed_in_gtk_GUI;
Bram Moolenaardac13472019-09-16 21:06:21 +02001004 }
1005#endif
1006
1007 if (errmsg == NULL)
1008 {
1009#ifdef FEAT_KEYMAP
1010 // When 'keymap' is used and 'encoding' changes, reload the keymap
1011 // (with another encoding).
1012 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
1013 (void)keymap_init();
1014#endif
1015
1016 // When 'termencoding' is not empty and 'encoding' changes or when
1017 // 'termencoding' changes, need to setup for keyboard input and
1018 // display output conversion.
1019 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
1020 {
1021 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
1022 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
1023 {
Bram Moolenaard82a47d2022-01-05 20:24:39 +00001024 semsg(_(e_cannot_convert_between_str_and_str),
1025 p_tenc, p_enc);
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001026 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001027 }
1028 }
1029
1030#if defined(MSWIN)
1031 // $HOME may have characters in active code page.
1032 if (varp == &p_enc)
1033 init_homedir();
1034#endif
1035 }
1036 }
1037
1038#if defined(FEAT_POSTSCRIPT)
1039 else if (varp == &p_penc)
1040 {
1041 // Canonize printencoding if VIM standard one
1042 p = enc_canonize(p_penc);
1043 if (p != NULL)
1044 {
1045 vim_free(p_penc);
1046 p_penc = p;
1047 }
1048 else
1049 {
1050 // Ensure lower case and '-' for '_'
1051 for (s = p_penc; *s != NUL; s++)
1052 {
1053 if (*s == '_')
1054 *s = '-';
1055 else
1056 *s = TOLOWER_ASC(*s);
1057 }
1058 }
1059 }
1060#endif
1061
1062#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1063 else if (varp == &p_imak)
1064 {
1065 if (!im_xim_isvalid_imactivate())
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001066 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001067 }
1068#endif
1069
1070#ifdef FEAT_KEYMAP
1071 else if (varp == &curbuf->b_p_keymap)
1072 {
1073 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001074 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001075 else
1076 {
1077 int secure_save = secure;
1078
1079 // Reset the secure flag, since the value of 'keymap' has
1080 // been checked to be safe.
1081 secure = 0;
1082
1083 // load or unload key mapping tables
1084 errmsg = keymap_init();
1085
1086 secure = secure_save;
1087
1088 // Since we check the value, there is no need to set P_INSECURE,
1089 // even when the value comes from a modeline.
1090 *value_checked = TRUE;
1091 }
1092
1093 if (errmsg == NULL)
1094 {
1095 if (*curbuf->b_p_keymap != NUL)
1096 {
1097 // Installed a new keymap, switch on using it.
1098 curbuf->b_p_iminsert = B_IMODE_LMAP;
1099 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
1100 curbuf->b_p_imsearch = B_IMODE_LMAP;
1101 }
1102 else
1103 {
1104 // Cleared the keymap, may reset 'iminsert' and 'imsearch'.
1105 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
1106 curbuf->b_p_iminsert = B_IMODE_NONE;
1107 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
1108 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
1109 }
1110 if ((opt_flags & OPT_LOCAL) == 0)
1111 {
1112 set_iminsert_global();
1113 set_imsearch_global();
1114 }
1115 status_redraw_curbuf();
1116 }
1117 }
1118#endif
1119
1120 // 'fileformat'
1121 else if (gvarp == &p_ff)
1122 {
1123 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
Bram Moolenaar108010a2021-06-27 22:03:33 +02001124 errmsg = e_cannot_make_changes_modifiable_is_off;
Bram Moolenaardac13472019-09-16 21:06:21 +02001125 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001126 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001127 else
1128 {
1129 // may also change 'textmode'
1130 if (get_fileformat(curbuf) == EOL_DOS)
1131 curbuf->b_p_tx = TRUE;
1132 else
1133 curbuf->b_p_tx = FALSE;
Bram Moolenaardac13472019-09-16 21:06:21 +02001134 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +02001135 // update flag in swap file
1136 ml_setflags(curbuf);
1137 // Redraw needed when switching to/from "mac": a CR in the text
1138 // will be displayed differently.
1139 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
1140 redraw_curbuf_later(NOT_VALID);
1141 }
1142 }
1143
1144 // 'fileformats'
1145 else if (varp == &p_ffs)
1146 {
1147 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001148 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001149 else
1150 {
1151 // also change 'textauto'
1152 if (*p_ffs == NUL)
1153 p_ta = FALSE;
1154 else
1155 p_ta = TRUE;
1156 }
1157 }
1158
1159#if defined(FEAT_CRYPT)
1160 // 'cryptkey'
1161 else if (gvarp == &p_key)
1162 {
1163 // Make sure the ":set" command doesn't show the new value in the
1164 // history.
1165 remove_key_from_history();
1166
1167 if (STRCMP(curbuf->b_p_key, oldval) != 0)
1168 // Need to update the swapfile.
Bram Moolenaar76cb6832020-05-15 22:30:38 +02001169 {
Bram Moolenaardac13472019-09-16 21:06:21 +02001170 ml_set_crypt_key(curbuf, oldval,
1171 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar76cb6832020-05-15 22:30:38 +02001172 changed_internal();
1173 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001174 }
1175
1176 else if (gvarp == &p_cm)
1177 {
1178 if (opt_flags & OPT_LOCAL)
1179 p = curbuf->b_p_cm;
1180 else
1181 p = p_cm;
1182 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001183 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001184 else if (crypt_self_test() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001185 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001186 else
1187 {
1188 // When setting the global value to empty, make it "zip".
1189 if (*p_cm == NUL)
1190 {
1191 if (new_value_alloced)
1192 free_string_option(p_cm);
1193 p_cm = vim_strsave((char_u *)"zip");
1194 new_value_alloced = TRUE;
1195 }
1196 // When using ":set cm=name" the local value is going to be empty.
1197 // Do that here, otherwise the crypt functions will still use the
1198 // local value.
1199 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
1200 {
1201 free_string_option(curbuf->b_p_cm);
1202 curbuf->b_p_cm = empty_option;
1203 }
1204
1205 // Need to update the swapfile when the effective method changed.
1206 // Set "s" to the effective old value, "p" to the effective new
1207 // method and compare.
1208 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
1209 s = p_cm; // was previously using the global value
1210 else
1211 s = oldval;
1212 if (*curbuf->b_p_cm == NUL)
1213 p = p_cm; // is now using the global value
1214 else
1215 p = curbuf->b_p_cm;
1216 if (STRCMP(s, p) != 0)
1217 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
1218
1219 // If the global value changes need to update the swapfile for all
1220 // buffers using that value.
1221 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
1222 {
1223 buf_T *buf;
1224
1225 FOR_ALL_BUFFERS(buf)
1226 if (buf != curbuf && *buf->b_p_cm == NUL)
1227 ml_set_crypt_key(buf, buf->b_p_key, oldval);
1228 }
1229 }
1230 }
1231#endif
1232
1233 // 'matchpairs'
1234 else if (gvarp == &p_mps)
1235 {
1236 if (has_mbyte)
1237 {
1238 for (p = *varp; *p != NUL; ++p)
1239 {
1240 int x2 = -1;
1241 int x3 = -1;
1242
=?UTF-8?q?Dundar=20G=C3=B6c?=b8366582022-04-14 20:43:56 +01001243 p += mb_ptr2len(p);
Bram Moolenaardac13472019-09-16 21:06:21 +02001244 if (*p != NUL)
1245 x2 = *p++;
1246 if (*p != NUL)
1247 {
1248 x3 = mb_ptr2char(p);
1249 p += mb_ptr2len(p);
1250 }
1251 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
1252 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001253 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001254 break;
1255 }
1256 if (*p == NUL)
1257 break;
1258 }
1259 }
1260 else
1261 {
1262 // Check for "x:y,x:y"
1263 for (p = *varp; *p != NUL; p += 4)
1264 {
1265 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
1266 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001267 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001268 break;
1269 }
1270 if (p[3] == NUL)
1271 break;
1272 }
1273 }
1274 }
1275
Bram Moolenaardac13472019-09-16 21:06:21 +02001276 // 'comments'
1277 else if (gvarp == &p_com)
1278 {
1279 for (s = *varp; *s; )
1280 {
1281 while (*s && *s != ':')
1282 {
1283 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
1284 && !VIM_ISDIGIT(*s) && *s != '-')
1285 {
1286 errmsg = illegal_char(errbuf, *s);
1287 break;
1288 }
1289 ++s;
1290 }
1291 if (*s++ == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001292 errmsg = e_missing_colon;
Bram Moolenaardac13472019-09-16 21:06:21 +02001293 else if (*s == ',' || *s == NUL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001294 errmsg = e_zero_length_string;
Bram Moolenaardac13472019-09-16 21:06:21 +02001295 if (errmsg != NULL)
1296 break;
1297 while (*s && *s != ',')
1298 {
1299 if (*s == '\\' && s[1] != NUL)
1300 ++s;
1301 ++s;
1302 }
1303 s = skip_to_option_part(s);
1304 }
1305 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001306
Bram Moolenaareed9d462021-02-15 20:38:25 +01001307 // global 'listchars'
Bram Moolenaardac13472019-09-16 21:06:21 +02001308 else if (varp == &p_lcs)
1309 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001310 errmsg = set_chars_option(curwin, varp);
1311 if (errmsg == NULL)
1312 {
1313 tabpage_T *tp;
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001314 win_T *wp;
Bram Moolenaareed9d462021-02-15 20:38:25 +01001315
Bram Moolenaar5ed26fa2022-07-04 18:05:51 +01001316 // If the current window is set to use the global 'listchars'
1317 // value, clear the window-local value.
Bram Moolenaareed9d462021-02-15 20:38:25 +01001318 if (!(opt_flags & OPT_GLOBAL))
1319 clear_string_option(&curwin->w_p_lcs);
1320 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar5ed26fa2022-07-04 18:05:51 +01001321 // If the current window has a local value need to apply it
1322 // again, it was changed when setting the global value.
Bram Moolenaar606efc72021-11-12 19:52:47 +00001323 // If no error was returned above, we don't expect an error
1324 // here, so ignore the return value.
Bram Moolenaar5ed26fa2022-07-04 18:05:51 +01001325 (void)set_chars_option(wp, &wp->w_p_lcs);
Bram Moolenaar606efc72021-11-12 19:52:47 +00001326
Bram Moolenaareed9d462021-02-15 20:38:25 +01001327 redraw_all_later(NOT_VALID);
1328 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001329 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01001330 // local 'listchars'
1331 else if (varp == &curwin->w_p_lcs)
1332 errmsg = set_chars_option(curwin, varp);
1333
Bram Moolenaardac13472019-09-16 21:06:21 +02001334 // 'fillchars'
1335 else if (varp == &p_fcs)
1336 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001337 errmsg = set_chars_option(curwin, varp);
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001338 if (errmsg == NULL)
1339 {
1340 tabpage_T *tp;
1341 win_T *wp;
1342
Bram Moolenaar5ed26fa2022-07-04 18:05:51 +01001343 // If the current window is set to use the global 'fillchars'
1344 // value clear the window-local value.
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001345 if (!(opt_flags & OPT_GLOBAL))
1346 clear_string_option(&curwin->w_p_fcs);
1347 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar5ed26fa2022-07-04 18:05:51 +01001348 // If the current window has a local value need to apply it
1349 // again, it was changed when setting the global value.
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001350 // If no error was returned above, we don't expect an error
1351 // here, so ignore the return value.
Bram Moolenaar5ed26fa2022-07-04 18:05:51 +01001352 (void)set_chars_option(wp, &wp->w_p_fcs);
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001353
1354 redraw_all_later(NOT_VALID);
1355 }
1356 }
1357 // local 'fillchars'
1358 else if (varp == &curwin->w_p_fcs)
1359 {
1360 errmsg = set_chars_option(curwin, varp);
Bram Moolenaardac13472019-09-16 21:06:21 +02001361 }
1362
1363#ifdef FEAT_CMDWIN
1364 // 'cedit'
1365 else if (varp == &p_cedit)
1366 {
1367 errmsg = check_cedit();
1368 }
1369#endif
1370
1371 // 'verbosefile'
1372 else if (varp == &p_vfile)
1373 {
1374 verbose_stop();
1375 if (*p_vfile != NUL && verbose_open() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001376 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001377 }
1378
1379#ifdef FEAT_VIMINFO
1380 // 'viminfo'
1381 else if (varp == &p_viminfo)
1382 {
1383 for (s = p_viminfo; *s;)
1384 {
1385 // Check it's a valid character
1386 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
1387 {
1388 errmsg = illegal_char(errbuf, *s);
1389 break;
1390 }
1391 if (*s == 'n') // name is always last one
1392 break;
1393 else if (*s == 'r') // skip until next ','
1394 {
1395 while (*++s && *s != ',')
1396 ;
1397 }
1398 else if (*s == '%')
1399 {
1400 // optional number
1401 while (vim_isdigit(*++s))
1402 ;
1403 }
1404 else if (*s == '!' || *s == 'h' || *s == 'c')
1405 ++s; // no extra chars
1406 else // must have a number
1407 {
1408 while (vim_isdigit(*++s))
1409 ;
1410
1411 if (!VIM_ISDIGIT(*(s - 1)))
1412 {
1413 if (errbuf != NULL)
1414 {
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001415 sprintf(errbuf,
1416 _(e_missing_number_after_angle_str_angle),
Bram Moolenaardac13472019-09-16 21:06:21 +02001417 transchar_byte(*(s - 1)));
1418 errmsg = errbuf;
1419 }
1420 else
1421 errmsg = "";
1422 break;
1423 }
1424 }
1425 if (*s == ',')
1426 ++s;
1427 else if (*s)
1428 {
1429 if (errbuf != NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001430 errmsg = e_missing_comma;
Bram Moolenaardac13472019-09-16 21:06:21 +02001431 else
1432 errmsg = "";
1433 break;
1434 }
1435 }
1436 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001437 errmsg = e_must_specify_a_value;
Bram Moolenaardac13472019-09-16 21:06:21 +02001438 }
1439#endif // FEAT_VIMINFO
1440
1441 // terminal options
1442 else if (istermoption_idx(opt_idx) && full_screen)
1443 {
1444 // ":set t_Co=0" and ":set t_Co=1" do ":set t_Co="
1445 if (varp == &T_CCO)
1446 {
1447 int colors = atoi((char *)T_CCO);
1448
1449 // Only reinitialize colors if t_Co value has really changed to
1450 // avoid expensive reload of colorscheme if t_Co is set to the
1451 // same value multiple times.
1452 if (colors != t_colors)
1453 {
1454 t_colors = colors;
1455 if (t_colors <= 1)
1456 {
1457 if (new_value_alloced)
1458 vim_free(T_CCO);
1459 T_CCO = empty_option;
1460 }
1461#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
1462 if (is_term_win32())
1463 {
1464 swap_tcap();
1465 did_swaptcap = TRUE;
1466 }
1467#endif
1468 // We now have a different color setup, initialize it again.
1469 init_highlight(TRUE, FALSE);
1470 }
1471 }
1472 ttest(FALSE);
1473 if (varp == &T_ME)
1474 {
1475 out_str(T_ME);
1476 redraw_later(CLEAR);
1477#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
1478 // Since t_me has been set, this probably means that the user
1479 // wants to use this as default colors. Need to reset default
1480 // background/foreground colors.
1481# ifdef VIMDLL
1482 if (!gui.in_use && !gui.starting)
1483# endif
1484 mch_set_normal_colors();
1485#endif
1486 }
1487 if (varp == &T_BE && termcap_active)
1488 {
Bram Moolenaar1d97db32022-06-04 22:15:54 +01001489 MAY_WANT_TO_LOG_THIS;
1490
Bram Moolenaardac13472019-09-16 21:06:21 +02001491 if (*T_BE == NUL)
1492 // When clearing t_BE we assume the user no longer wants
1493 // bracketed paste, thus disable it by writing t_BD.
1494 out_str(T_BD);
1495 else
1496 out_str(T_BE);
1497 }
1498 }
1499
1500#ifdef FEAT_LINEBREAK
1501 // 'showbreak'
Bram Moolenaaree857022019-11-09 23:26:40 +01001502 else if (gvarp == &p_sbr)
Bram Moolenaardac13472019-09-16 21:06:21 +02001503 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001504 for (s = *varp; *s; )
Bram Moolenaardac13472019-09-16 21:06:21 +02001505 {
1506 if (ptr2cells(s) != 1)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001507 errmsg = e_showbreak_contains_unprintable_or_wide_character;
Bram Moolenaardac13472019-09-16 21:06:21 +02001508 MB_PTR_ADV(s);
1509 }
1510 }
1511#endif
1512
1513#ifdef FEAT_GUI
1514 // 'guifont'
1515 else if (varp == &p_guifont)
1516 {
1517 if (gui.in_use)
1518 {
1519 p = p_guifont;
1520# if defined(FEAT_GUI_GTK)
1521 // Put up a font dialog and let the user select a new value.
1522 // If this is cancelled go back to the old value but don't
1523 // give an error message.
1524 if (STRCMP(p, "*") == 0)
1525 {
1526 p = gui_mch_font_dialog(oldval);
1527
1528 if (new_value_alloced)
1529 free_string_option(p_guifont);
1530
1531 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
1532 new_value_alloced = TRUE;
1533 }
1534# endif
1535 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
1536 {
1537# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
1538 if (STRCMP(p_guifont, "*") == 0)
1539 {
1540 // Dialog was cancelled: Keep the old value without giving
1541 // an error message.
1542 if (new_value_alloced)
1543 free_string_option(p_guifont);
1544 p_guifont = vim_strsave(oldval);
1545 new_value_alloced = TRUE;
1546 }
1547 else
1548# endif
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001549 errmsg = e_invalid_fonts;
Bram Moolenaardac13472019-09-16 21:06:21 +02001550 }
1551 }
1552 redraw_gui_only = TRUE;
1553 }
1554# ifdef FEAT_XFONTSET
1555 else if (varp == &p_guifontset)
1556 {
1557 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001558 errmsg = e_cant_select_fontset;
Bram Moolenaardac13472019-09-16 21:06:21 +02001559 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaar31e5c602022-04-15 13:53:33 +01001560 errmsg = e_invalid_fontset;
Bram Moolenaardac13472019-09-16 21:06:21 +02001561 redraw_gui_only = TRUE;
1562 }
1563# endif
1564 else if (varp == &p_guifontwide)
1565 {
1566 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001567 errmsg = e_cant_select_wide_font;
Bram Moolenaardac13472019-09-16 21:06:21 +02001568 else if (gui_get_wide_font() == FAIL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001569 errmsg = e_invalid_wide_font;
Bram Moolenaardac13472019-09-16 21:06:21 +02001570 redraw_gui_only = TRUE;
1571 }
1572#endif
Dusan Popovic4eeedc02021-10-16 20:52:05 +01001573# if defined(FEAT_GUI_GTK)
1574 else if (varp == &p_guiligatures)
1575 {
1576 gui_set_ligatures();
1577 redraw_gui_only = TRUE;
1578 }
1579# endif
Bram Moolenaardac13472019-09-16 21:06:21 +02001580
1581#ifdef CURSOR_SHAPE
1582 // 'guicursor'
1583 else if (varp == &p_guicursor)
1584 errmsg = parse_shape_opt(SHAPE_CURSOR);
1585#endif
1586
1587#ifdef FEAT_MOUSESHAPE
1588 // 'mouseshape'
1589 else if (varp == &p_mouseshape)
1590 {
1591 errmsg = parse_shape_opt(SHAPE_MOUSE);
1592 update_mouseshape(-1);
1593 }
1594#endif
1595
1596#ifdef FEAT_PRINTER
1597 else if (varp == &p_popt)
1598 errmsg = parse_printoptions();
1599# if defined(FEAT_POSTSCRIPT)
1600 else if (varp == &p_pmfn)
1601 errmsg = parse_printmbfont();
1602# endif
1603#endif
1604
1605#ifdef FEAT_LANGMAP
1606 // 'langmap'
1607 else if (varp == &p_langmap)
1608 langmap_set();
1609#endif
1610
1611#ifdef FEAT_LINEBREAK
1612 // 'breakat'
1613 else if (varp == &p_breakat)
1614 fill_breakat_flags();
1615#endif
1616
Bram Moolenaardac13472019-09-16 21:06:21 +02001617 // 'titlestring' and 'iconstring'
1618 else if (varp == &p_titlestring || varp == &p_iconstring)
1619 {
Bram Moolenaar651fca82021-11-29 20:39:38 +00001620#ifdef FEAT_STL_OPT
Bram Moolenaardac13472019-09-16 21:06:21 +02001621 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
1622
1623 // NULL => statusline syntax
1624 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
1625 stl_syntax |= flagval;
1626 else
1627 stl_syntax &= ~flagval;
Bram Moolenaar651fca82021-11-29 20:39:38 +00001628#endif
Bram Moolenaardac13472019-09-16 21:06:21 +02001629 did_set_title();
1630 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001631
1632#ifdef FEAT_GUI
1633 // 'guioptions'
1634 else if (varp == &p_go)
1635 {
1636 gui_init_which_components(oldval);
1637 redraw_gui_only = TRUE;
1638 }
1639#endif
1640
1641#if defined(FEAT_GUI_TABLINE)
1642 // 'guitablabel'
1643 else if (varp == &p_gtl)
1644 {
1645 redraw_tabline = TRUE;
1646 redraw_gui_only = TRUE;
1647 }
1648 // 'guitabtooltip'
1649 else if (varp == &p_gtt)
1650 {
1651 redraw_gui_only = TRUE;
1652 }
1653#endif
1654
Bram Moolenaara1cb1d12019-10-17 23:00:07 +02001655#if defined(UNIX) || defined(VMS)
Bram Moolenaardac13472019-09-16 21:06:21 +02001656 // 'ttymouse'
1657 else if (varp == &p_ttym)
1658 {
1659 // Switch the mouse off before changing the escape sequences used for
1660 // that.
1661 mch_setmouse(FALSE);
1662 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001663 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001664 else
1665 check_mouse_termcode();
1666 if (termcap_active)
1667 setmouse(); // may switch it on again
1668 }
1669#endif
1670
1671 // 'selection'
1672 else if (varp == &p_sel)
1673 {
1674 if (*p_sel == NUL
1675 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001676 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001677 }
1678
1679 // 'selectmode'
1680 else if (varp == &p_slm)
1681 {
1682 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001683 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001684 }
1685
1686#ifdef FEAT_BROWSE
1687 // 'browsedir'
1688 else if (varp == &p_bsdir)
1689 {
1690 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
1691 && !mch_isdir(p_bsdir))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001692 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001693 }
1694#endif
1695
1696 // 'keymodel'
1697 else if (varp == &p_km)
1698 {
1699 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001700 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001701 else
1702 {
1703 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
1704 km_startsel = (vim_strchr(p_km, 'a') != NULL);
1705 }
1706 }
1707
1708 // 'mousemodel'
1709 else if (varp == &p_mousem)
1710 {
1711 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001712 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001713#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
1714 else if (*p_mousem != *oldval)
1715 // Changed from "extend" to "popup" or "popup_setpos" or vv: need
1716 // to create or delete the popup menus.
1717 gui_motif_update_mousemodel(root_menu);
1718#endif
1719 }
1720
1721 // 'switchbuf'
1722 else if (varp == &p_swb)
1723 {
1724 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001725 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001726 }
1727
1728 // 'debug'
1729 else if (varp == &p_debug)
1730 {
1731 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001732 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001733 }
1734
1735 // 'display'
1736 else if (varp == &p_dy)
1737 {
1738 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001739 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001740 else
1741 (void)init_chartab();
1742
1743 }
1744
1745 // 'eadirection'
1746 else if (varp == &p_ead)
1747 {
1748 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001749 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001750 }
1751
1752#ifdef FEAT_CLIPBOARD
1753 // 'clipboard'
1754 else if (varp == &p_cb)
1755 errmsg = check_clipboard_option();
1756#endif
1757
1758#ifdef FEAT_SPELL
1759 // When 'spelllang' or 'spellfile' is set and there is a window for this
1760 // buffer in which 'spell' is set load the wordlists.
1761 else if (varp == &(curwin->w_s->b_p_spl)
1762 || varp == &(curwin->w_s->b_p_spf))
1763 {
1764 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
1765
1766 if ((is_spellfile && !valid_spellfile(*varp))
Bram Moolenaarf154f3a2020-06-08 18:54:49 +02001767 || (!is_spellfile && !valid_spelllang(*varp)))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001768 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001769 else
1770 errmsg = did_set_spell_option(is_spellfile);
1771 }
1772 // When 'spellcapcheck' is set compile the regexp program.
1773 else if (varp == &(curwin->w_s->b_p_spc))
1774 {
1775 errmsg = compile_cap_prog(curwin->w_s);
1776 }
Bram Moolenaar362b44b2020-06-10 21:47:00 +02001777 // 'spelloptions'
1778 else if (varp == &(curwin->w_s->b_p_spo))
1779 {
1780 if (**varp != NUL && STRCMP("camel", *varp) != 0)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001781 errmsg = e_invalid_argument;
Bram Moolenaar362b44b2020-06-10 21:47:00 +02001782 }
Bram Moolenaardac13472019-09-16 21:06:21 +02001783 // 'spellsuggest'
1784 else if (varp == &p_sps)
1785 {
1786 if (spell_check_sps() != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001787 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001788 }
1789 // 'mkspellmem'
1790 else if (varp == &p_msm)
1791 {
1792 if (spell_check_msm() != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001793 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001794 }
1795#endif
1796
1797 // When 'bufhidden' is set, check for valid value.
1798 else if (gvarp == &p_bh)
1799 {
1800 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001801 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001802 }
1803
1804 // When 'buftype' is set, check for valid value.
1805 else if (gvarp == &p_bt)
1806 {
1807 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001808 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001809 else
1810 {
1811 if (curwin->w_status_height)
1812 {
1813 curwin->w_redr_status = TRUE;
1814 redraw_later(VALID);
1815 }
1816 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaardac13472019-09-16 21:06:21 +02001817 redraw_titles();
Bram Moolenaardac13472019-09-16 21:06:21 +02001818 }
1819 }
1820
1821#ifdef FEAT_STL_OPT
zeertzjq5dc294a2022-04-15 13:17:57 +01001822 // 'statusline', 'tabline' or 'rulerformat'
1823 else if (gvarp == &p_stl || varp == &p_tal || varp == &p_ruf)
Bram Moolenaardac13472019-09-16 21:06:21 +02001824 {
1825 int wid;
1826
1827 if (varp == &p_ruf) // reset ru_wid first
1828 ru_wid = 0;
1829 s = *varp;
1830 if (varp == &p_ruf && *s == '%')
1831 {
1832 // set ru_wid if 'ruf' starts with "%99("
1833 if (*++s == '-') // ignore a '-'
1834 s++;
1835 wid = getdigits(&s);
1836 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
1837 ru_wid = wid;
1838 else
1839 errmsg = check_stl_option(p_ruf);
1840 }
zeertzjq5dc294a2022-04-15 13:17:57 +01001841 // check 'statusline' or 'tabline' only if it doesn't start with "%!"
Bram Moolenaardac13472019-09-16 21:06:21 +02001842 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
1843 errmsg = check_stl_option(s);
1844 if (varp == &p_ruf && errmsg == NULL)
1845 comp_col();
1846 }
1847#endif
1848
1849 // check if it is a valid value for 'complete' -- Acevedo
1850 else if (gvarp == &p_cpt)
1851 {
1852 for (s = *varp; *s;)
1853 {
1854 while (*s == ',' || *s == ' ')
1855 s++;
1856 if (!*s)
1857 break;
1858 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
1859 {
1860 errmsg = illegal_char(errbuf, *s);
1861 break;
1862 }
1863 if (*++s != NUL && *s != ',' && *s != ' ')
1864 {
1865 if (s[-1] == 'k' || s[-1] == 's')
1866 {
1867 // skip optional filename after 'k' and 's'
1868 while (*s && *s != ',' && *s != ' ')
1869 {
1870 if (*s == '\\' && s[1] != NUL)
1871 ++s;
1872 ++s;
1873 }
1874 }
1875 else
1876 {
1877 if (errbuf != NULL)
1878 {
1879 sprintf((char *)errbuf,
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00001880 _(e_illegal_character_after_chr), *--s);
Bram Moolenaardac13472019-09-16 21:06:21 +02001881 errmsg = errbuf;
1882 }
1883 else
1884 errmsg = "";
1885 break;
1886 }
1887 }
1888 }
1889 }
1890
1891 // 'completeopt'
1892 else if (varp == &p_cot)
1893 {
1894 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001895 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001896 else
1897 completeopt_was_set();
1898 }
1899
1900#ifdef BACKSLASH_IN_FILENAME
1901 // 'completeslash'
1902 else if (gvarp == &p_csl)
1903 {
1904 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
1905 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001906 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001907 }
1908#endif
1909
1910#ifdef FEAT_SIGNS
1911 // 'signcolumn'
1912 else if (varp == &curwin->w_p_scl)
1913 {
1914 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001915 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001916 // When changing the 'signcolumn' to or from 'number', recompute the
1917 // width of the number column if 'number' or 'relativenumber' is set.
1918 if (((*oldval == 'n' && *(oldval + 1) == 'u')
1919 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
1920 && (curwin->w_p_nu || curwin->w_p_rnu))
1921 curwin->w_nrwidth_line_count = 0;
1922 }
1923#endif
1924
1925
1926#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
1927 // 'toolbar'
1928 else if (varp == &p_toolbar)
1929 {
1930 if (opt_strings_flags(p_toolbar, p_toolbar_values,
1931 &toolbar_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001932 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001933 else
1934 {
1935 out_flush();
1936 gui_mch_show_toolbar((toolbar_flags &
1937 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
1938 }
1939 }
1940#endif
1941
1942#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
1943 // 'toolbariconsize': GTK+ 2 only
1944 else if (varp == &p_tbis)
1945 {
1946 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001947 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001948 else
1949 {
1950 out_flush();
1951 gui_mch_show_toolbar((toolbar_flags &
1952 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
1953 }
1954 }
1955#endif
1956
1957 // 'pastetoggle': translate key codes like in a mapping
1958 else if (varp == &p_pt)
1959 {
1960 if (*p_pt)
1961 {
Bram Moolenaar1e7b52a2019-10-13 16:59:08 +02001962 (void)replace_termcodes(p_pt, &p,
1963 REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
Bram Moolenaardac13472019-09-16 21:06:21 +02001964 if (p != NULL)
1965 {
1966 if (new_value_alloced)
1967 free_string_option(p_pt);
1968 p_pt = p;
1969 new_value_alloced = TRUE;
1970 }
1971 }
1972 }
1973
1974 // 'backspace'
1975 else if (varp == &p_bs)
1976 {
1977 if (VIM_ISDIGIT(*p_bs))
1978 {
Bram Moolenaaraa0489e2020-04-17 19:41:21 +02001979 if (*p_bs > '3' || p_bs[1] != NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001980 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001981 }
1982 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001983 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001984 }
1985 else if (varp == &p_bo)
1986 {
1987 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00001988 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02001989 }
1990
1991 // 'tagcase'
1992 else if (gvarp == &p_tc)
1993 {
1994 unsigned int *flags;
1995
1996 if (opt_flags & OPT_LOCAL)
1997 {
1998 p = curbuf->b_p_tc;
1999 flags = &curbuf->b_tc_flags;
2000 }
2001 else
2002 {
2003 p = p_tc;
2004 flags = &tc_flags;
2005 }
2006
2007 if ((opt_flags & OPT_LOCAL) && *p == NUL)
2008 // make the local value empty: use the global value
2009 *flags = 0;
2010 else if (*p == NUL
2011 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002012 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002013 }
2014
2015 // 'casemap'
2016 else if (varp == &p_cmp)
2017 {
2018 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002019 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002020 }
2021
2022#ifdef FEAT_DIFF
2023 // 'diffopt'
2024 else if (varp == &p_dip)
2025 {
2026 if (diffopt_changed() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002027 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002028 }
2029#endif
2030
2031#ifdef FEAT_FOLDING
2032 // 'foldmethod'
2033 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
2034 {
2035 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
2036 || *curwin->w_p_fdm == NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002037 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002038 else
2039 {
2040 foldUpdateAll(curwin);
2041 if (foldmethodIsDiff(curwin))
2042 newFoldLevel();
2043 }
2044 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002045 // 'foldmarker'
2046 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
2047 {
2048 p = vim_strchr(*varp, ',');
2049 if (p == NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00002050 errmsg = e_comma_required;
Bram Moolenaardac13472019-09-16 21:06:21 +02002051 else if (p == *varp || p[1] == NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002052 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002053 else if (foldmethodIsMarker(curwin))
2054 foldUpdateAll(curwin);
2055 }
2056 // 'commentstring'
2057 else if (gvarp == &p_cms)
2058 {
2059 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaar1d423ef2022-01-02 21:26:16 +00002060 errmsg = e_commentstring_must_be_empty_or_contain_str;
Bram Moolenaardac13472019-09-16 21:06:21 +02002061 }
2062 // 'foldopen'
2063 else if (varp == &p_fdo)
2064 {
2065 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002066 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002067 }
2068 // 'foldclose'
2069 else if (varp == &p_fcl)
2070 {
2071 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002072 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002073 }
2074 // 'foldignore'
2075 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
2076 {
2077 if (foldmethodIsIndent(curwin))
2078 foldUpdateAll(curwin);
2079 }
2080#endif
2081
2082 // 'virtualedit'
Gary Johnson53ba05b2021-07-26 22:19:10 +02002083 else if (gvarp == &p_ve)
Bram Moolenaardac13472019-09-16 21:06:21 +02002084 {
Gary Johnson53ba05b2021-07-26 22:19:10 +02002085 char_u *ve = p_ve;
2086 unsigned int *flags = &ve_flags;
2087
2088 if (opt_flags & OPT_LOCAL)
Bram Moolenaardac13472019-09-16 21:06:21 +02002089 {
Gary Johnson51ad8502021-08-03 18:33:08 +02002090 ve = curwin->w_p_ve;
2091 flags = &curwin->w_ve_flags;
Gary Johnson53ba05b2021-07-26 22:19:10 +02002092 }
2093
2094 if ((opt_flags & OPT_LOCAL) && *ve == NUL)
2095 // make the local value empty: use the global value
2096 *flags = 0;
2097 else
2098 {
2099 if (opt_strings_flags(ve, p_ve_values, flags, TRUE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002100 errmsg = e_invalid_argument;
Gary Johnson53ba05b2021-07-26 22:19:10 +02002101 else if (STRCMP(p_ve, oldval) != 0)
2102 {
2103 // Recompute cursor position in case the new 've' setting
2104 // changes something.
2105 validate_virtcol();
2106 coladvance(curwin->w_virtcol);
2107 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002108 }
2109 }
2110
2111#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
2112 else if (varp == &p_csqf)
2113 {
2114 if (p_csqf != NULL)
2115 {
2116 p = p_csqf;
2117 while (*p != NUL)
2118 {
2119 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
2120 || p[1] == NUL
2121 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
2122 || (p[2] != NUL && p[2] != ','))
2123 {
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002124 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002125 break;
2126 }
2127 else if (p[2] == NUL)
2128 break;
2129 else
2130 p += 3;
2131 }
2132 }
2133 }
2134#endif
2135
Bram Moolenaardac13472019-09-16 21:06:21 +02002136 // 'cinoptions'
2137 else if (gvarp == &p_cino)
2138 {
2139 // TODO: recognize errors
2140 parse_cino(curbuf);
2141 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002142
2143#if defined(FEAT_RENDER_OPTIONS)
2144 // 'renderoptions'
2145 else if (varp == &p_rop)
2146 {
2147 if (!gui_mch_set_rendering_options(p_rop))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002148 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002149 }
2150#endif
2151
2152 else if (gvarp == &p_ft)
2153 {
2154 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002155 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002156 else
2157 {
2158 value_changed = STRCMP(oldval, *varp) != 0;
2159
2160 // Since we check the value, there is no need to set P_INSECURE,
2161 // even when the value comes from a modeline.
2162 *value_checked = TRUE;
2163 }
2164 }
2165
2166#ifdef FEAT_SYN_HL
2167 else if (gvarp == &p_syn)
2168 {
2169 if (!valid_filetype(*varp))
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002170 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002171 else
2172 {
2173 value_changed = STRCMP(oldval, *varp) != 0;
2174
2175 // Since we check the value, there is no need to set P_INSECURE,
2176 // even when the value comes from a modeline.
2177 *value_checked = TRUE;
2178 }
2179 }
2180#endif
2181
2182#ifdef FEAT_TERMINAL
2183 // 'termwinkey'
2184 else if (varp == &curwin->w_p_twk)
2185 {
2186 if (*curwin->w_p_twk != NUL
2187 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002188 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002189 }
2190 // 'termwinsize'
2191 else if (varp == &curwin->w_p_tws)
2192 {
2193 if (*curwin->w_p_tws != NUL)
2194 {
2195 p = skipdigits(curwin->w_p_tws);
2196 if (p == curwin->w_p_tws
2197 || (*p != 'x' && *p != '*')
2198 || *skipdigits(p + 1) != NUL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002199 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002200 }
2201 }
Bram Moolenaar219c7d02020-02-01 21:57:29 +01002202 // 'wincolor'
2203 else if (varp == &curwin->w_p_wcr)
Bram Moolenaar87fd0922021-11-20 13:47:45 +00002204 term_update_wincolor(curwin);
Bram Moolenaardac13472019-09-16 21:06:21 +02002205# if defined(MSWIN)
2206 // 'termwintype'
2207 else if (varp == &p_twt)
2208 {
2209 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002210 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002211 }
2212# endif
2213#endif
2214
2215#ifdef FEAT_VARTABS
2216 // 'varsofttabstop'
2217 else if (varp == &(curbuf->b_p_vsts))
2218 {
2219 char_u *cp;
2220
2221 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
2222 {
2223 if (curbuf->b_p_vsts_array)
2224 {
2225 vim_free(curbuf->b_p_vsts_array);
2226 curbuf->b_p_vsts_array = 0;
2227 }
2228 }
2229 else
2230 {
2231 for (cp = *varp; *cp; ++cp)
2232 {
2233 if (vim_isdigit(*cp))
2234 continue;
2235 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
2236 continue;
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002237 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002238 break;
2239 }
2240 if (errmsg == NULL)
2241 {
2242 int *oldarray = curbuf->b_p_vsts_array;
Bram Moolenaarb7081e12021-09-04 18:47:28 +02002243 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)) == OK)
Bram Moolenaardac13472019-09-16 21:06:21 +02002244 {
2245 if (oldarray)
2246 vim_free(oldarray);
2247 }
2248 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002249 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002250 }
2251 }
2252 }
2253
2254 // 'vartabstop'
2255 else if (varp == &(curbuf->b_p_vts))
2256 {
2257 char_u *cp;
2258
2259 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
2260 {
2261 if (curbuf->b_p_vts_array)
2262 {
2263 vim_free(curbuf->b_p_vts_array);
2264 curbuf->b_p_vts_array = NULL;
2265 }
2266 }
2267 else
2268 {
2269 for (cp = *varp; *cp; ++cp)
2270 {
2271 if (vim_isdigit(*cp))
2272 continue;
2273 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
2274 continue;
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002275 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002276 break;
2277 }
2278 if (errmsg == NULL)
2279 {
2280 int *oldarray = curbuf->b_p_vts_array;
2281
Bram Moolenaarb7081e12021-09-04 18:47:28 +02002282 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)) == OK)
Bram Moolenaardac13472019-09-16 21:06:21 +02002283 {
2284 vim_free(oldarray);
2285#ifdef FEAT_FOLDING
2286 if (foldmethodIsIndent(curwin))
2287 foldUpdateAll(curwin);
2288#endif
2289 }
2290 else
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002291 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002292 }
2293 }
2294 }
2295#endif
2296
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002297#ifdef FEAT_PROP_POPUP
Bram Moolenaardac13472019-09-16 21:06:21 +02002298 // 'previewpopup'
2299 else if (varp == &p_pvp)
2300 {
2301 if (parse_previewpopup(NULL) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002302 errmsg = e_invalid_argument;
Bram Moolenaardac13472019-09-16 21:06:21 +02002303 }
2304# ifdef FEAT_QUICKFIX
2305 // 'completepopup'
2306 else if (varp == &p_cpp)
2307 {
2308 if (parse_completepopup(NULL) == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002309 errmsg = e_invalid_argument;
Bram Moolenaar447bfba2020-07-18 16:07:16 +02002310 else
2311 popup_close_info();
Bram Moolenaardac13472019-09-16 21:06:21 +02002312 }
2313# endif
2314#endif
2315
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002316#ifdef FEAT_EVAL
2317 // '*expr' options
2318 else if (
2319# ifdef FEAT_BEVAL
2320 varp == &p_bexpr ||
2321# endif
2322# ifdef FEAT_DIFF
2323 varp == &p_dex ||
2324# endif
2325# ifdef FEAT_FOLDING
2326 varp == &curwin->w_p_fde ||
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002327 varp == &curwin->w_p_fdt ||
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002328# endif
2329 gvarp == &p_fex ||
2330# ifdef FEAT_FIND_ID
2331 gvarp == &p_inex ||
2332# endif
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002333 gvarp == &p_inde ||
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002334# ifdef FEAT_DIFF
2335 varp == &p_pex ||
2336# endif
2337# ifdef FEAT_POSTSCRIPT
2338 varp == &p_pexpr ||
2339# endif
Bram Moolenaarf4e88f22022-01-23 14:17:28 +00002340 varp == &p_ccv)
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002341 {
2342 char_u **p_opt = NULL;
2343 char_u *name;
2344
2345 // If the option value starts with <SID> or s:, then replace that with
2346 // the script identifier.
2347# ifdef FEAT_BEVAL
2348 if (varp == &p_bexpr) // 'balloonexpr'
2349 p_opt = (opt_flags & OPT_LOCAL) ? &curbuf->b_p_bexpr : &p_bexpr;
2350# endif
2351# ifdef FEAT_DIFF
2352 if (varp == &p_dex) // 'diffexpr'
2353 p_opt = &p_dex;
2354# endif
2355# ifdef FEAT_FOLDING
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002356 if (varp == &curwin->w_p_fde) // 'foldexpr'
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002357 p_opt = &curwin->w_p_fde;
Yegappan Lakshmanan27708e62021-12-26 21:54:43 +00002358 if (varp == &curwin->w_p_fdt) // 'foldtext'
2359 p_opt = &curwin->w_p_fdt;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002360# endif
2361 if (gvarp == &p_fex) // 'formatexpr'
2362 p_opt = &curbuf->b_p_fex;
2363# ifdef FEAT_FIND_ID
2364 if (gvarp == &p_inex) // 'includeexpr'
2365 p_opt = &curbuf->b_p_inex;
2366# endif
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002367 if (gvarp == &p_inde) // 'indentexpr'
2368 p_opt = &curbuf->b_p_inde;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002369# ifdef FEAT_DIFF
2370 if (varp == &p_pex) // 'patchexpr'
2371 p_opt = &p_pex;
2372# endif
2373# ifdef FEAT_POSTSCRIPT
2374 if (varp == &p_pexpr) // 'printexpr'
2375 p_opt = &p_pexpr;
2376# endif
Bram Moolenaarf4e88f22022-01-23 14:17:28 +00002377 if (varp == &p_ccv) // 'charconvert'
2378 p_opt = &p_ccv;
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00002379
2380 if (p_opt != NULL)
2381 {
2382 name = get_scriptlocal_funcname(*p_opt);
2383 if (name != NULL)
2384 {
2385 if (new_value_alloced)
2386 free_string_option(*p_opt);
2387 *p_opt = name;
2388 new_value_alloced = TRUE;
2389 }
2390 }
2391
2392# ifdef FEAT_FOLDING
2393 if (varp == &curwin->w_p_fde && foldmethodIsExpr(curwin))
2394 foldUpdateAll(curwin);
2395# endif
2396 }
2397#endif
2398
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002399#ifdef FEAT_COMPL_FUNC
2400 // 'completefunc'
2401 else if (gvarp == &p_cfu)
2402 {
2403 if (set_completefunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002404 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002405 }
2406
2407 // 'omnifunc'
2408 else if (gvarp == &p_ofu)
2409 {
2410 if (set_omnifunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002411 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002412 }
2413
2414 // 'thesaurusfunc'
2415 else if (gvarp == &p_tsrfu)
2416 {
2417 if (set_thesaurusfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002418 errmsg = e_invalid_argument;
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00002419 }
2420#endif
2421
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002422#if defined(FEAT_EVAL) && \
2423 (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL))
2424 // 'imactivatefunc'
2425 else if (gvarp == &p_imaf)
2426 {
2427 if (set_imactivatefunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002428 errmsg = e_invalid_argument;
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002429 }
2430
2431 // 'imstatusfunc'
2432 else if (gvarp == &p_imsf)
2433 {
2434 if (set_imstatusfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002435 errmsg = e_invalid_argument;
Yegappan Lakshmanan7645da52021-12-04 14:02:30 +00002436 }
2437#endif
2438
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002439 // 'operatorfunc'
2440 else if (varp == &p_opfunc)
2441 {
2442 if (set_operatorfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002443 errmsg = e_invalid_argument;
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002444 }
2445
Bram Moolenaard43906d2020-07-20 21:31:32 +02002446#ifdef FEAT_QUICKFIX
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002447 // 'quickfixtextfunc'
Bram Moolenaard43906d2020-07-20 21:31:32 +02002448 else if (varp == &p_qftf)
2449 {
Yegappan Lakshmanan777175b2021-11-18 22:08:57 +00002450 if (qf_process_qftf_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002451 errmsg = e_invalid_argument;
Bram Moolenaard43906d2020-07-20 21:31:32 +02002452 }
2453#endif
2454
Yegappan Lakshmanan19916a82021-11-24 16:32:55 +00002455#ifdef FEAT_EVAL
2456 // 'tagfunc'
2457 else if (gvarp == &p_tfu)
2458 {
2459 if (set_tagfunc_option() == FAIL)
Bram Moolenaar436b5ad2021-12-31 22:49:24 +00002460 errmsg = e_invalid_argument;
Yegappan Lakshmanan19916a82021-11-24 16:32:55 +00002461 }
2462#endif
2463
Bram Moolenaardac13472019-09-16 21:06:21 +02002464 // Options that are a list of flags.
2465 else
2466 {
2467 p = NULL;
2468 if (varp == &p_ww) // 'whichwrap'
2469 p = (char_u *)WW_ALL;
2470 if (varp == &p_shm) // 'shortmess'
2471 p = (char_u *)SHM_ALL;
2472 else if (varp == &(p_cpo)) // 'cpoptions'
2473 p = (char_u *)CPO_ALL;
2474 else if (varp == &(curbuf->b_p_fo)) // 'formatoptions'
2475 p = (char_u *)FO_ALL;
2476#ifdef FEAT_CONCEAL
2477 else if (varp == &curwin->w_p_cocu) // 'concealcursor'
2478 p = (char_u *)COCU_ALL;
2479#endif
2480 else if (varp == &p_mouse) // 'mouse'
2481 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002482 p = (char_u *)MOUSE_ALL;
Bram Moolenaardac13472019-09-16 21:06:21 +02002483 }
2484#if defined(FEAT_GUI)
2485 else if (varp == &p_go) // 'guioptions'
2486 p = (char_u *)GO_ALL;
2487#endif
2488 if (p != NULL)
2489 {
2490 for (s = *varp; *s; ++s)
2491 if (vim_strchr(p, *s) == NULL)
2492 {
2493 errmsg = illegal_char(errbuf, *s);
2494 break;
2495 }
2496 }
2497 }
2498
2499 // If error detected, restore the previous value.
2500 if (errmsg != NULL)
2501 {
2502 if (new_value_alloced)
2503 free_string_option(*varp);
2504 *varp = oldval;
2505 // When resetting some values, need to act on it.
2506 if (did_chartab)
2507 (void)init_chartab();
2508 if (varp == &p_hl)
2509 (void)highlight_changed();
2510 }
2511 else
2512 {
2513#ifdef FEAT_EVAL
2514 // Remember where the option was set.
2515 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
2516#endif
2517 // Free string options that are in allocated memory.
2518 // Use "free_oldval", because recursiveness may change the flags under
2519 // our fingers (esp. init_highlight()).
2520 if (free_oldval)
2521 free_string_option(oldval);
2522 if (new_value_alloced)
2523 set_option_flag(opt_idx, P_ALLOCED);
2524 else
2525 clear_option_flag(opt_idx, P_ALLOCED);
2526
2527 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
2528 && is_global_local_option(opt_idx))
2529 {
2530 // global option with local value set to use global value; free
2531 // the local value and make it empty
2532 p = get_option_varp_scope(opt_idx, OPT_LOCAL);
2533 free_string_option(*(char_u **)p);
2534 *(char_u **)p = empty_option;
2535 }
2536
2537 // May set global value for local option.
2538 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
2539 set_string_option_global(opt_idx, varp);
2540
2541 // Trigger the autocommand only after setting the flags.
2542#ifdef FEAT_SYN_HL
2543 // When 'syntax' is set, load the syntax of that name
2544 if (varp == &(curbuf->b_p_syn))
2545 {
2546 static int syn_recursive = 0;
2547
2548 ++syn_recursive;
2549 // Only pass TRUE for "force" when the value changed or not used
2550 // recursively, to avoid endless recurrence.
2551 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
2552 value_changed || syn_recursive == 1, curbuf);
2553 curbuf->b_flags |= BF_SYN_SET;
2554 --syn_recursive;
2555 }
2556#endif
2557 else if (varp == &(curbuf->b_p_ft))
2558 {
2559 // 'filetype' is set, trigger the FileType autocommand.
2560 // Skip this when called from a modeline and the filetype was
2561 // already set to this value.
2562 if (!(opt_flags & OPT_MODELINE) || value_changed)
2563 {
2564 static int ft_recursive = 0;
2565 int secure_save = secure;
2566
2567 // Reset the secure flag, since the value of 'filetype' has
2568 // been checked to be safe.
2569 secure = 0;
2570
2571 ++ft_recursive;
2572 did_filetype = TRUE;
2573 // Only pass TRUE for "force" when the value changed or not
2574 // used recursively, to avoid endless recurrence.
2575 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
2576 value_changed || ft_recursive == 1, curbuf);
2577 --ft_recursive;
2578 // Just in case the old "curbuf" is now invalid.
2579 if (varp != &(curbuf->b_p_ft))
2580 varp = NULL;
2581
2582 secure = secure_save;
2583 }
2584 }
2585#ifdef FEAT_SPELL
2586 if (varp == &(curwin->w_s->b_p_spl))
2587 {
2588 char_u fname[200];
2589 char_u *q = curwin->w_s->b_p_spl;
2590
2591 // Skip the first name if it is "cjk".
2592 if (STRNCMP(q, "cjk,", 4) == 0)
2593 q += 4;
2594
2595 // Source the spell/LANG.vim in 'runtimepath'.
2596 // They could set 'spellcapcheck' depending on the language.
2597 // Use the first name in 'spelllang' up to '_region' or
2598 // '.encoding'.
2599 for (p = q; *p != NUL; ++p)
2600 if (!ASCII_ISALNUM(*p) && *p != '-')
2601 break;
2602 if (p > q)
2603 {
2604 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
2605 (int)(p - q), q);
2606 source_runtime(fname, DIP_ALL);
2607 }
2608 }
2609#endif
2610 }
2611
Bram Moolenaardac13472019-09-16 21:06:21 +02002612 if (varp == &p_mouse)
2613 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002614 if (*p_mouse == NUL)
2615 mch_setmouse(FALSE); // switch mouse off
2616 else
Bram Moolenaardac13472019-09-16 21:06:21 +02002617 setmouse(); // in case 'mouse' changed
2618 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002619
Bram Moolenaar788fbb42020-05-31 14:08:12 +02002620#if defined(FEAT_LUA) || defined(PROTO)
2621 if (varp == &p_rtp)
2622 update_package_paths_in_lua();
2623#endif
2624
Bram Moolenaarb2d85e32022-01-07 16:55:32 +00002625#if defined(FEAT_LINEBREAK)
2626 // Changing Formatlistpattern when briopt includes the list setting:
2627 // redraw
2628 if ((varp == &p_flp || varp == &(curbuf->b_p_flp))
2629 && curwin->w_briopt_list)
2630 redraw_all_later(NOT_VALID);
2631#endif
2632
Bram Moolenaardac13472019-09-16 21:06:21 +02002633 if (curwin->w_curswant != MAXCOL
Bram Moolenaara1cb1d12019-10-17 23:00:07 +02002634 && (get_option_flags(opt_idx) & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaardac13472019-09-16 21:06:21 +02002635 curwin->w_set_curswant = TRUE;
2636
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002637 if ((opt_flags & OPT_NO_REDRAW) == 0)
2638 {
Bram Moolenaardac13472019-09-16 21:06:21 +02002639#ifdef FEAT_GUI
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002640 // check redraw when it's not a GUI option or the GUI is active.
2641 if (!redraw_gui_only || gui.in_use)
Bram Moolenaardac13472019-09-16 21:06:21 +02002642#endif
Bram Moolenaar37294bd2021-03-10 13:40:08 +01002643 check_redraw(get_option_flags(opt_idx));
2644 }
Bram Moolenaardac13472019-09-16 21:06:21 +02002645
2646#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
2647 if (did_swaptcap)
2648 {
2649 set_termname((char_u *)"win32");
2650 init_highlight(TRUE, FALSE);
2651 }
2652#endif
2653
2654 return errmsg;
2655}
2656
2657/*
2658 * Check an option that can be a range of string values.
2659 *
2660 * Return OK for correct value, FAIL otherwise.
2661 * Empty is always OK.
2662 */
2663 static int
2664check_opt_strings(
2665 char_u *val,
2666 char **values,
2667 int list) // when TRUE: accept a list of values
2668{
2669 return opt_strings_flags(val, values, NULL, list);
2670}
2671
2672/*
2673 * Handle an option that can be a range of string values.
2674 * Set a flag in "*flagp" for each string present.
2675 *
2676 * Return OK for correct value, FAIL otherwise.
2677 * Empty is always OK.
2678 */
2679 static int
2680opt_strings_flags(
2681 char_u *val, // new value
2682 char **values, // array of valid string values
2683 unsigned *flagp,
2684 int list) // when TRUE: accept a list of values
2685{
2686 int i;
2687 int len;
2688 unsigned new_flags = 0;
2689
2690 while (*val)
2691 {
2692 for (i = 0; ; ++i)
2693 {
2694 if (values[i] == NULL) // val not found in values[]
2695 return FAIL;
2696
2697 len = (int)STRLEN(values[i]);
2698 if (STRNCMP(values[i], val, len) == 0
2699 && ((list && val[len] == ',') || val[len] == NUL))
2700 {
2701 val += len + (val[len] == ',');
2702 new_flags |= (1 << i);
2703 break; // check next item in val list
2704 }
2705 }
2706 }
2707 if (flagp != NULL)
2708 *flagp = new_flags;
2709
2710 return OK;
2711}
2712
2713/*
2714 * return OK if "p" is a valid fileformat name, FAIL otherwise.
2715 */
2716 int
2717check_ff_value(char_u *p)
2718{
2719 return check_opt_strings(p, p_ff_values, FALSE);
2720}