Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1 | /* 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 | |
| 16 | static char *(p_ambw_values[]) = {"single", "double", NULL}; |
| 17 | static char *(p_bg_values[]) = {"light", "dark", NULL}; |
| 18 | static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL}; |
| 19 | static char *(p_bo_values[]) = {"all", "backspace", "cursor", "complete", |
| 20 | "copy", "ctrlg", "error", "esc", "ex", |
| 21 | "hangul", "insertmode", "lang", "mess", |
| 22 | "showmatch", "operator", "register", "shell", |
LemonBoy | 77771d3 | 2022-04-13 11:47:25 +0100 | [diff] [blame] | 23 | "spell", "term", "wildmode", NULL}; |
Bram Moolenaar | aaad995 | 2020-05-31 15:08:59 +0200 | [diff] [blame] | 24 | static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", "unsigned", NULL}; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 25 | static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; |
| 26 | #ifdef FEAT_CRYPT |
Christian Brabandt | f573c6e | 2021-06-20 14:02:16 +0200 | [diff] [blame] | 27 | static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", |
| 28 | # ifdef FEAT_SODIUM |
| 29 | "xchacha20", |
| 30 | # endif |
| 31 | NULL}; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 32 | #endif |
| 33 | static char *(p_cmp_values[]) = {"internal", "keepascii", NULL}; |
| 34 | static char *(p_dy_values[]) = {"lastline", "truncate", "uhex", NULL}; |
| 35 | #ifdef FEAT_FOLDING |
| 36 | static 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 Moolenaar | 635bd60 | 2021-04-16 19:58:22 +0200 | [diff] [blame] | 41 | // Also used for 'viewoptions'! Keep in sync with SSOP_ flags. |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 42 | static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize", |
| 43 | "localoptions", "options", "help", "blank", "globals", "slash", "unix", |
Bram Moolenaar | 635bd60 | 2021-04-16 19:58:22 +0200 | [diff] [blame] | 44 | "sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", "skiprtp", |
| 45 | NULL}; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 46 | #endif |
Bram Moolenaar | 539aa6b | 2019-11-17 18:09:38 +0100 | [diff] [blame] | 47 | // Keep in sync with SWB_ flags in option.h |
| 48 | static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", "uselast", NULL}; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 49 | static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL}; |
| 50 | #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) |
| 51 | static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL}; |
| 52 | #endif |
| 53 | #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) |
| 54 | static char *(p_tbis_values[]) = {"tiny", "small", "medium", "large", "huge", "giant", NULL}; |
| 55 | #endif |
Bram Moolenaar | a1cb1d1 | 2019-10-17 23:00:07 +0200 | [diff] [blame] | 56 | #if defined(UNIX) || defined(VMS) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 57 | static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL}; |
| 58 | #endif |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 59 | static char *(p_ve_values[]) = {"block", "insert", "all", "onemore", "none", "NONE", NULL}; |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 60 | static char *(p_wop_values[]) = {"fuzzy", "tagfile", "pum", NULL}; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 61 | #ifdef FEAT_WAK |
| 62 | static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; |
| 63 | #endif |
| 64 | static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL}; |
| 65 | static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL}; |
| 66 | static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL}; |
| 67 | static char *(p_km_values[]) = {"startsel", "stopsel", NULL}; |
| 68 | #ifdef FEAT_BROWSE |
| 69 | static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL}; |
| 70 | #endif |
| 71 | static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL}; |
| 72 | static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL}; |
| 73 | static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; |
| 74 | static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL}; |
| 75 | static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL}; |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 76 | static char *(p_bs_values[]) = {"indent", "eol", "start", "nostop", NULL}; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 77 | #ifdef FEAT_FOLDING |
| 78 | static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", |
| 79 | # ifdef FEAT_DIFF |
| 80 | "diff", |
| 81 | # endif |
| 82 | NULL}; |
| 83 | static char *(p_fcl_values[]) = {"all", NULL}; |
| 84 | #endif |
Bram Moolenaar | dca7abe | 2019-10-20 18:17:57 +0200 | [diff] [blame] | 85 | static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "popuphidden", "noinsert", "noselect", NULL}; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 86 | #ifdef BACKSLASH_IN_FILENAME |
| 87 | static char *(p_csl_values[]) = {"slash", "backslash", NULL}; |
| 88 | #endif |
| 89 | #ifdef FEAT_SIGNS |
| 90 | static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL}; |
| 91 | #endif |
| 92 | #if defined(MSWIN) && defined(FEAT_TERMINAL) |
| 93 | static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL}; |
| 94 | #endif |
| 95 | |
| 96 | static int check_opt_strings(char_u *val, char **values, int list); |
| 97 | static 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 |
| 104 | didset_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 Moolenaar | a1cb1d1 | 2019-10-17 23:00:07 +0200 | [diff] [blame] | 119 | #if defined(UNIX) || defined(VMS) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 120 | (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 |
| 128 | } |
| 129 | |
| 130 | #if defined(FEAT_EVAL) |
| 131 | /* |
| 132 | * Trigger the OptionSet autocommand. |
| 133 | * "opt_idx" is the index of the option being set. |
| 134 | * "opt_flags" can be OPT_LOCAL etc. |
| 135 | * "oldval" the old value |
| 136 | * "oldval_l" the old local value (only non-NULL if global and local value |
| 137 | * are set) |
| 138 | * "oldval_g" the old global value (only non-NULL if global and local value |
| 139 | * are set) |
| 140 | * "newval" the new value |
| 141 | */ |
| 142 | void |
| 143 | trigger_optionsset_string( |
| 144 | int opt_idx, |
| 145 | int opt_flags, |
| 146 | char_u *oldval, |
| 147 | char_u *oldval_l, |
| 148 | char_u *oldval_g, |
| 149 | char_u *newval) |
| 150 | { |
| 151 | // Don't do this recursively. |
| 152 | if (oldval != NULL && newval != NULL |
| 153 | && *get_vim_var_str(VV_OPTION_TYPE) == NUL) |
| 154 | { |
| 155 | char_u buf_type[7]; |
| 156 | |
| 157 | sprintf((char *)buf_type, "%s", |
| 158 | (opt_flags & OPT_LOCAL) ? "local" : "global"); |
| 159 | set_vim_var_string(VV_OPTION_OLD, oldval, -1); |
| 160 | set_vim_var_string(VV_OPTION_NEW, newval, -1); |
| 161 | set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); |
| 162 | if (opt_flags & OPT_LOCAL) |
| 163 | { |
| 164 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); |
| 165 | set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); |
| 166 | } |
| 167 | if (opt_flags & OPT_GLOBAL) |
| 168 | { |
| 169 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); |
| 170 | set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1); |
| 171 | } |
| 172 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 173 | { |
| 174 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); |
| 175 | set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1); |
| 176 | set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1); |
| 177 | } |
| 178 | if (opt_flags & OPT_MODELINE) |
| 179 | { |
| 180 | set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); |
| 181 | set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); |
| 182 | } |
| 183 | apply_autocmds(EVENT_OPTIONSET, |
=?UTF-8?q?Dundar=20G=C3=B6c?= | 420fabc | 2022-01-28 15:28:04 +0000 | [diff] [blame] | 184 | get_option_fullname(opt_idx), NULL, FALSE, |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 185 | NULL); |
| 186 | reset_v_option_vars(); |
| 187 | } |
| 188 | } |
| 189 | #endif |
| 190 | |
| 191 | static char * |
| 192 | illegal_char(char *errbuf, int c) |
| 193 | { |
| 194 | if (errbuf == NULL) |
| 195 | return ""; |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 196 | sprintf((char *)errbuf, _(e_illegal_character_str), (char *)transchar(c)); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 197 | return errbuf; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Check string options in a buffer for NULL value. |
| 202 | */ |
| 203 | void |
| 204 | check_buf_options(buf_T *buf) |
| 205 | { |
| 206 | check_string_option(&buf->b_p_bh); |
| 207 | check_string_option(&buf->b_p_bt); |
| 208 | check_string_option(&buf->b_p_fenc); |
| 209 | check_string_option(&buf->b_p_ff); |
| 210 | #ifdef FEAT_FIND_ID |
| 211 | check_string_option(&buf->b_p_def); |
| 212 | check_string_option(&buf->b_p_inc); |
| 213 | # ifdef FEAT_EVAL |
| 214 | check_string_option(&buf->b_p_inex); |
| 215 | # endif |
| 216 | #endif |
| 217 | #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) |
| 218 | check_string_option(&buf->b_p_inde); |
| 219 | check_string_option(&buf->b_p_indk); |
| 220 | #endif |
| 221 | #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
| 222 | check_string_option(&buf->b_p_bexpr); |
| 223 | #endif |
| 224 | #if defined(FEAT_CRYPT) |
| 225 | check_string_option(&buf->b_p_cm); |
| 226 | #endif |
| 227 | check_string_option(&buf->b_p_fp); |
| 228 | #if defined(FEAT_EVAL) |
| 229 | check_string_option(&buf->b_p_fex); |
| 230 | #endif |
| 231 | #ifdef FEAT_CRYPT |
| 232 | check_string_option(&buf->b_p_key); |
| 233 | #endif |
| 234 | check_string_option(&buf->b_p_kp); |
| 235 | check_string_option(&buf->b_p_mps); |
| 236 | check_string_option(&buf->b_p_fo); |
| 237 | check_string_option(&buf->b_p_flp); |
| 238 | check_string_option(&buf->b_p_isk); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 239 | check_string_option(&buf->b_p_com); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 240 | #ifdef FEAT_FOLDING |
| 241 | check_string_option(&buf->b_p_cms); |
| 242 | #endif |
| 243 | check_string_option(&buf->b_p_nf); |
| 244 | #ifdef FEAT_TEXTOBJ |
| 245 | check_string_option(&buf->b_p_qe); |
| 246 | #endif |
| 247 | #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 Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 255 | check_string_option(&buf->b_s.b_p_spo); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 256 | #endif |
| 257 | #ifdef FEAT_SEARCHPATH |
| 258 | check_string_option(&buf->b_p_sua); |
| 259 | #endif |
| 260 | #ifdef FEAT_CINDENT |
| 261 | check_string_option(&buf->b_p_cink); |
| 262 | check_string_option(&buf->b_p_cino); |
Tom Praschan | 3506cf3 | 2022-04-07 12:39:08 +0100 | [diff] [blame] | 263 | check_string_option(&buf->b_p_cinsd); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 264 | parse_cino(buf); |
| 265 | #endif |
| 266 | check_string_option(&buf->b_p_ft); |
| 267 | #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) |
| 268 | check_string_option(&buf->b_p_cinw); |
| 269 | #endif |
| 270 | check_string_option(&buf->b_p_cpt); |
| 271 | #ifdef FEAT_COMPL_FUNC |
| 272 | check_string_option(&buf->b_p_cfu); |
| 273 | check_string_option(&buf->b_p_ofu); |
Bram Moolenaar | d4c4bfa | 2021-10-16 21:14:11 +0100 | [diff] [blame] | 274 | check_string_option(&buf->b_p_tsrfu); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 275 | #endif |
| 276 | #ifdef FEAT_EVAL |
| 277 | check_string_option(&buf->b_p_tfu); |
| 278 | #endif |
| 279 | #ifdef FEAT_KEYMAP |
| 280 | check_string_option(&buf->b_p_keymap); |
| 281 | #endif |
| 282 | #ifdef FEAT_QUICKFIX |
| 283 | check_string_option(&buf->b_p_gp); |
| 284 | check_string_option(&buf->b_p_mp); |
| 285 | check_string_option(&buf->b_p_efm); |
| 286 | #endif |
| 287 | check_string_option(&buf->b_p_ep); |
| 288 | check_string_option(&buf->b_p_path); |
| 289 | check_string_option(&buf->b_p_tags); |
| 290 | check_string_option(&buf->b_p_tc); |
| 291 | check_string_option(&buf->b_p_dict); |
| 292 | check_string_option(&buf->b_p_tsr); |
| 293 | #ifdef FEAT_LISP |
| 294 | check_string_option(&buf->b_p_lw); |
| 295 | #endif |
| 296 | check_string_option(&buf->b_p_bkc); |
| 297 | check_string_option(&buf->b_p_menc); |
| 298 | #ifdef FEAT_VARTABS |
| 299 | check_string_option(&buf->b_p_vsts); |
| 300 | check_string_option(&buf->b_p_vts); |
| 301 | #endif |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * Free the string allocated for an option. |
| 306 | * Checks for the string being empty_option. This may happen if we're out of |
| 307 | * memory, vim_strsave() returned NULL, which was replaced by empty_option by |
| 308 | * check_options(). |
| 309 | * Does NOT check for P_ALLOCED flag! |
| 310 | */ |
| 311 | void |
| 312 | free_string_option(char_u *p) |
| 313 | { |
| 314 | if (p != empty_option) |
| 315 | vim_free(p); |
| 316 | } |
| 317 | |
| 318 | void |
| 319 | clear_string_option(char_u **pp) |
| 320 | { |
| 321 | if (*pp != empty_option) |
| 322 | vim_free(*pp); |
| 323 | *pp = empty_option; |
| 324 | } |
| 325 | |
| 326 | void |
| 327 | check_string_option(char_u **pp) |
| 328 | { |
| 329 | if (*pp == NULL) |
| 330 | *pp = empty_option; |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Set global value for string option when it's a local option. |
| 335 | */ |
| 336 | static void |
| 337 | set_string_option_global( |
| 338 | int opt_idx, // option index |
| 339 | char_u **varp) // pointer to option variable |
| 340 | { |
| 341 | char_u **p, *s; |
| 342 | |
| 343 | // the global value is always allocated |
| 344 | if (is_window_local_option(opt_idx)) |
| 345 | p = (char_u **)GLOBAL_WO(varp); |
| 346 | else |
| 347 | p = (char_u **)get_option_var(opt_idx); |
| 348 | if (!is_global_option(opt_idx) |
| 349 | && p != varp |
| 350 | && (s = vim_strsave(*varp)) != NULL) |
| 351 | { |
| 352 | free_string_option(*p); |
| 353 | *p = s; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * Set a string option to a new value (without checking the effect). |
| 359 | * The string is copied into allocated memory. |
| 360 | * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used. |
| 361 | * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When |
| 362 | * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to |
| 363 | * "set_sid". |
| 364 | */ |
| 365 | void |
| 366 | set_string_option_direct( |
| 367 | char_u *name, |
| 368 | int opt_idx, |
| 369 | char_u *val, |
| 370 | int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL |
| 371 | int set_sid UNUSED) |
| 372 | { |
| 373 | char_u *s; |
| 374 | char_u **varp; |
| 375 | int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; |
| 376 | int idx = opt_idx; |
| 377 | |
| 378 | if (idx == -1) // use name |
| 379 | { |
| 380 | idx = findoption(name); |
| 381 | if (idx < 0) // not found (should not happen) |
| 382 | { |
Bram Moolenaar | 460ae5d | 2022-01-01 14:19:49 +0000 | [diff] [blame] | 383 | semsg(_(e_internal_error_str), "set_string_option_direct()"); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 384 | siemsg(_("For option %s"), name); |
| 385 | return; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | if (is_hidden_option(idx)) // can't set hidden option |
| 390 | return; |
| 391 | |
| 392 | s = vim_strsave(val); |
| 393 | if (s != NULL) |
| 394 | { |
| 395 | varp = (char_u **)get_option_varp_scope(idx, |
| 396 | both ? OPT_LOCAL : opt_flags); |
| 397 | if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED)) |
| 398 | free_string_option(*varp); |
| 399 | *varp = s; |
| 400 | |
| 401 | // For buffer/window local option may also set the global value. |
| 402 | if (both) |
| 403 | set_string_option_global(idx, varp); |
| 404 | |
| 405 | set_option_flag(idx, P_ALLOCED); |
| 406 | |
| 407 | // When setting both values of a global option with a local value, |
| 408 | // make the local value empty, so that the global value is used. |
| 409 | if (is_global_local_option(idx) && both) |
| 410 | { |
| 411 | free_string_option(*varp); |
| 412 | *varp = empty_option; |
| 413 | } |
| 414 | # ifdef FEAT_EVAL |
| 415 | if (set_sid != SID_NONE) |
| 416 | { |
| 417 | sctx_T script_ctx; |
| 418 | |
| 419 | if (set_sid == 0) |
| 420 | script_ctx = current_sctx; |
| 421 | else |
| 422 | { |
| 423 | script_ctx.sc_sid = set_sid; |
| 424 | script_ctx.sc_seq = 0; |
| 425 | script_ctx.sc_lnum = 0; |
| 426 | script_ctx.sc_version = 1; |
| 427 | } |
| 428 | set_option_sctx_idx(idx, opt_flags, script_ctx); |
| 429 | } |
| 430 | # endif |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | /* |
| 435 | * Like set_string_option_direct(), but for a window-local option in "wp". |
| 436 | * Blocks autocommands to avoid the old curwin becoming invalid. |
| 437 | */ |
| 438 | void |
| 439 | set_string_option_direct_in_win( |
| 440 | win_T *wp, |
| 441 | char_u *name, |
| 442 | int opt_idx, |
| 443 | char_u *val, |
| 444 | int opt_flags, |
| 445 | int set_sid) |
| 446 | { |
| 447 | win_T *save_curwin = curwin; |
| 448 | |
| 449 | block_autocmds(); |
| 450 | curwin = wp; |
| 451 | curbuf = curwin->w_buffer; |
| 452 | set_string_option_direct(name, opt_idx, val, opt_flags, set_sid); |
| 453 | curwin = save_curwin; |
| 454 | curbuf = curwin->w_buffer; |
| 455 | unblock_autocmds(); |
| 456 | } |
| 457 | |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 458 | #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 459 | /* |
| 460 | * Like set_string_option_direct(), but for a buffer-local option in "buf". |
| 461 | * Blocks autocommands to avoid the old curbuf becoming invalid. |
| 462 | */ |
| 463 | void |
| 464 | set_string_option_direct_in_buf( |
| 465 | buf_T *buf, |
| 466 | char_u *name, |
| 467 | int opt_idx, |
| 468 | char_u *val, |
| 469 | int opt_flags, |
| 470 | int set_sid) |
| 471 | { |
| 472 | buf_T *save_curbuf = curbuf; |
| 473 | |
| 474 | block_autocmds(); |
| 475 | curbuf = buf; |
| 476 | curwin->w_buffer = curbuf; |
| 477 | set_string_option_direct(name, opt_idx, val, opt_flags, set_sid); |
| 478 | curbuf = save_curbuf; |
| 479 | curwin->w_buffer = curbuf; |
| 480 | unblock_autocmds(); |
| 481 | } |
Dominique Pelle | 748b308 | 2022-01-08 12:41:16 +0000 | [diff] [blame] | 482 | #endif |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 483 | |
| 484 | /* |
| 485 | * Set a string option to a new value, and handle the effects. |
| 486 | * |
| 487 | * Returns NULL on success or error message on error. |
| 488 | */ |
| 489 | char * |
| 490 | set_string_option( |
| 491 | int opt_idx, |
| 492 | char_u *value, |
| 493 | int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL |
| 494 | { |
| 495 | char_u *s; |
| 496 | char_u **varp; |
| 497 | char_u *oldval; |
| 498 | #if defined(FEAT_EVAL) |
| 499 | char_u *oldval_l = NULL; |
| 500 | char_u *oldval_g = NULL; |
| 501 | char_u *saved_oldval = NULL; |
| 502 | char_u *saved_oldval_l = NULL; |
| 503 | char_u *saved_oldval_g = NULL; |
| 504 | char_u *saved_newval = NULL; |
| 505 | #endif |
| 506 | char *r = NULL; |
| 507 | int value_checked = FALSE; |
| 508 | |
| 509 | if (is_hidden_option(opt_idx)) // don't set hidden option |
| 510 | return NULL; |
| 511 | |
Bram Moolenaar | 7f009df | 2020-03-16 20:27:38 +0100 | [diff] [blame] | 512 | s = vim_strsave(value == NULL ? (char_u *)"" : value); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 513 | if (s != NULL) |
| 514 | { |
| 515 | varp = (char_u **)get_option_varp_scope(opt_idx, |
| 516 | (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 |
| 517 | ? (is_global_local_option(opt_idx) |
| 518 | ? OPT_GLOBAL : OPT_LOCAL) |
| 519 | : opt_flags); |
| 520 | oldval = *varp; |
| 521 | #if defined(FEAT_EVAL) |
| 522 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 523 | { |
| 524 | oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL); |
| 525 | oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); |
| 526 | } |
| 527 | #endif |
| 528 | *varp = s; |
| 529 | |
| 530 | #if defined(FEAT_EVAL) |
| 531 | if (!starting |
| 532 | # ifdef FEAT_CRYPT |
| 533 | && !is_crypt_key_option(opt_idx) |
| 534 | # endif |
| 535 | ) |
| 536 | { |
| 537 | if (oldval_l != NULL) |
| 538 | saved_oldval_l = vim_strsave(oldval_l); |
| 539 | if (oldval_g != NULL) |
| 540 | saved_oldval_g = vim_strsave(oldval_g); |
| 541 | saved_oldval = vim_strsave(oldval); |
| 542 | saved_newval = vim_strsave(s); |
| 543 | } |
| 544 | #endif |
| 545 | if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, |
| 546 | opt_flags, &value_checked)) == NULL) |
| 547 | did_set_option(opt_idx, opt_flags, TRUE, value_checked); |
| 548 | |
| 549 | #if defined(FEAT_EVAL) |
| 550 | // call autocommand after handling side effects |
| 551 | if (r == NULL) |
| 552 | trigger_optionsset_string(opt_idx, opt_flags, |
| 553 | saved_oldval, saved_oldval_l, |
| 554 | saved_oldval_g, saved_newval); |
| 555 | vim_free(saved_oldval); |
| 556 | vim_free(saved_oldval_l); |
| 557 | vim_free(saved_oldval_g); |
| 558 | vim_free(saved_newval); |
| 559 | #endif |
| 560 | } |
| 561 | return r; |
| 562 | } |
| 563 | |
| 564 | /* |
| 565 | * Return TRUE if "val" is a valid 'filetype' name. |
| 566 | * Also used for 'syntax' and 'keymap'. |
| 567 | */ |
| 568 | static int |
| 569 | valid_filetype(char_u *val) |
| 570 | { |
| 571 | return valid_name(val, ".-_"); |
| 572 | } |
| 573 | |
| 574 | #ifdef FEAT_STL_OPT |
| 575 | /* |
| 576 | * Check validity of options with the 'statusline' format. |
| 577 | * Return error message or NULL. |
| 578 | */ |
| 579 | static char * |
| 580 | check_stl_option(char_u *s) |
| 581 | { |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 582 | int groupdepth = 0; |
| 583 | static char errbuf[80]; |
| 584 | |
Bram Moolenaar | 8133cc6 | 2020-10-26 21:05:27 +0100 | [diff] [blame] | 585 | while (*s) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 586 | { |
| 587 | // Check for valid keys after % sequences |
| 588 | while (*s && *s != '%') |
| 589 | s++; |
| 590 | if (!*s) |
| 591 | break; |
| 592 | s++; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 593 | if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK) |
| 594 | { |
| 595 | s++; |
| 596 | continue; |
| 597 | } |
| 598 | if (*s == ')') |
| 599 | { |
| 600 | s++; |
| 601 | if (--groupdepth < 0) |
| 602 | break; |
| 603 | continue; |
| 604 | } |
| 605 | if (*s == '-') |
| 606 | s++; |
| 607 | while (VIM_ISDIGIT(*s)) |
| 608 | s++; |
| 609 | if (*s == STL_USER_HL) |
| 610 | continue; |
| 611 | if (*s == '.') |
| 612 | { |
| 613 | s++; |
| 614 | while (*s && VIM_ISDIGIT(*s)) |
| 615 | s++; |
| 616 | } |
| 617 | if (*s == '(') |
| 618 | { |
| 619 | groupdepth++; |
| 620 | continue; |
| 621 | } |
| 622 | if (vim_strchr(STL_ALL, *s) == NULL) |
| 623 | { |
| 624 | return illegal_char(errbuf, *s); |
| 625 | } |
| 626 | if (*s == '{') |
| 627 | { |
shadmansaleh | 30e3de2 | 2021-05-15 17:23:28 +0200 | [diff] [blame] | 628 | int reevaluate = (*s == '%'); |
| 629 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 630 | s++; |
shadmansaleh | 30e3de2 | 2021-05-15 17:23:28 +0200 | [diff] [blame] | 631 | while ((*s != '}' || (reevaluate && s[-1] != '%')) && *s) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 632 | s++; |
| 633 | if (*s != '}') |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 634 | return N_(e_unclosed_expression_sequence); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 635 | } |
| 636 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 637 | if (groupdepth != 0) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 638 | return N_(e_unbalanced_groups); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 639 | return NULL; |
| 640 | } |
| 641 | #endif |
| 642 | |
| 643 | /* |
| 644 | * Handle string options that need some action to perform when changed. |
| 645 | * Returns NULL for success, or an error message for an error. |
| 646 | */ |
| 647 | char * |
| 648 | did_set_string_option( |
| 649 | int opt_idx, // index in options[] table |
| 650 | char_u **varp, // pointer to the option variable |
| 651 | int new_value_alloced, // new value was allocated |
| 652 | char_u *oldval, // previous value of the option |
| 653 | char *errbuf, // buffer for errors, or NULL |
| 654 | int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL |
| 655 | int *value_checked) // value was checked to be save, no |
| 656 | // need to set P_INSECURE |
| 657 | { |
| 658 | char *errmsg = NULL; |
| 659 | char_u *s, *p; |
| 660 | int did_chartab = FALSE; |
| 661 | char_u **gvarp; |
| 662 | long_u free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); |
| 663 | #ifdef FEAT_GUI |
| 664 | // set when changing an option that only requires a redraw in the GUI |
| 665 | int redraw_gui_only = FALSE; |
| 666 | #endif |
| 667 | int value_changed = FALSE; |
| 668 | #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) |
| 669 | int did_swaptcap = FALSE; |
| 670 | #endif |
| 671 | |
| 672 | // Get the global option to compare with, otherwise we would have to check |
| 673 | // two values for all local options. |
| 674 | gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); |
| 675 | |
| 676 | // Disallow changing some options from secure mode |
| 677 | if ((secure |
| 678 | #ifdef HAVE_SANDBOX |
| 679 | || sandbox != 0 |
| 680 | #endif |
| 681 | ) && (get_option_flags(opt_idx) & P_SECURE)) |
Bram Moolenaar | 74409f6 | 2022-01-01 15:58:22 +0000 | [diff] [blame] | 682 | errmsg = e_not_allowed_here; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 683 | |
| 684 | // Check for a "normal" directory or file name in some options. Disallow a |
| 685 | // path separator (slash and/or backslash), wildcards and characters that |
| 686 | // are often illegal in a file name. Be more permissive if "secure" is off. |
| 687 | else if (((get_option_flags(opt_idx) & P_NFNAME) |
| 688 | && vim_strpbrk(*varp, (char_u *)(secure |
| 689 | ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL) |
| 690 | || ((get_option_flags(opt_idx) & P_NDNAME) |
| 691 | && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 692 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 693 | |
| 694 | // 'term' |
| 695 | else if (varp == &T_NAME) |
| 696 | { |
| 697 | if (T_NAME[0] == NUL) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 698 | errmsg = e_cannot_set_term_to_empty_string; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 699 | #ifdef FEAT_GUI |
Bram Moolenaar | 5daa911 | 2021-02-01 18:39:47 +0100 | [diff] [blame] | 700 | else if (gui.in_use) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 701 | errmsg = e_cannot_change_term_in_GUI; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 702 | else if (term_is_gui(T_NAME)) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 703 | errmsg = e_use_gui_to_start_GUI; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 704 | #endif |
| 705 | else if (set_termname(T_NAME) == FAIL) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 706 | errmsg = e_not_found_in_termcap; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 707 | else |
| 708 | { |
| 709 | // Screen colors may have changed. |
| 710 | redraw_later_clear(); |
| 711 | |
| 712 | // Both 'term' and 'ttytype' point to T_NAME, only set the |
| 713 | // P_ALLOCED flag on 'term'. |
| 714 | opt_idx = findoption((char_u *)"term"); |
| 715 | free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | // 'backupcopy' |
| 720 | else if (gvarp == &p_bkc) |
| 721 | { |
| 722 | char_u *bkc = p_bkc; |
| 723 | unsigned int *flags = &bkc_flags; |
| 724 | |
| 725 | if (opt_flags & OPT_LOCAL) |
| 726 | { |
| 727 | bkc = curbuf->b_p_bkc; |
| 728 | flags = &curbuf->b_bkc_flags; |
| 729 | } |
| 730 | |
| 731 | if ((opt_flags & OPT_LOCAL) && *bkc == NUL) |
| 732 | // make the local value empty: use the global value |
| 733 | *flags = 0; |
| 734 | else |
| 735 | { |
| 736 | if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 737 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 738 | if ((((int)*flags & BKC_AUTO) != 0) |
| 739 | + (((int)*flags & BKC_YES) != 0) |
| 740 | + (((int)*flags & BKC_NO) != 0) != 1) |
| 741 | { |
| 742 | // Must have exactly one of "auto", "yes" and "no". |
| 743 | (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 744 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | // 'backupext' and 'patchmode' |
| 750 | else if (varp == &p_bex || varp == &p_pm) |
| 751 | { |
| 752 | if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, |
| 753 | *p_pm == '.' ? p_pm + 1 : p_pm) == 0) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 754 | errmsg = N_(e_backupext_and_patchmode_are_equal); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 755 | } |
| 756 | #ifdef FEAT_LINEBREAK |
| 757 | // 'breakindentopt' |
| 758 | else if (varp == &curwin->w_p_briopt) |
| 759 | { |
| 760 | if (briopt_check(curwin) == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 761 | errmsg = e_invalid_argument; |
Bram Moolenaar | b2d85e3 | 2022-01-07 16:55:32 +0000 | [diff] [blame] | 762 | // list setting requires a redraw |
| 763 | if (curwin->w_briopt_list) |
| 764 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 765 | } |
| 766 | #endif |
| 767 | |
| 768 | // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] |
| 769 | // If the new option is invalid, use old value. 'lisp' option: refill |
| 770 | // g_chartab[] for '-' char |
| 771 | else if ( varp == &p_isi |
| 772 | || varp == &(curbuf->b_p_isk) |
| 773 | || varp == &p_isp |
| 774 | || varp == &p_isf) |
| 775 | { |
| 776 | if (init_chartab() == FAIL) |
| 777 | { |
| 778 | did_chartab = TRUE; // need to restore it below |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 779 | errmsg = e_invalid_argument; // error in value |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
| 783 | // 'helpfile' |
| 784 | else if (varp == &p_hf) |
| 785 | { |
| 786 | // May compute new values for $VIM and $VIMRUNTIME |
| 787 | if (didset_vim) |
| 788 | { |
| 789 | vim_setenv((char_u *)"VIM", (char_u *)""); |
| 790 | didset_vim = FALSE; |
| 791 | } |
| 792 | if (didset_vimruntime) |
| 793 | { |
| 794 | vim_setenv((char_u *)"VIMRUNTIME", (char_u *)""); |
| 795 | didset_vimruntime = FALSE; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | #ifdef FEAT_SYN_HL |
| 800 | // 'cursorlineopt' |
| 801 | else if (varp == &curwin->w_p_culopt |
| 802 | || gvarp == &curwin->w_allbuf_opt.wo_culopt) |
| 803 | { |
| 804 | if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 805 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | // 'colorcolumn' |
| 809 | else if (varp == &curwin->w_p_cc) |
| 810 | errmsg = check_colorcolumn(curwin); |
| 811 | #endif |
| 812 | |
| 813 | #ifdef FEAT_MULTI_LANG |
| 814 | // 'helplang' |
| 815 | else if (varp == &p_hlg) |
| 816 | { |
| 817 | // Check for "", "ab", "ab,cd", etc. |
| 818 | for (s = p_hlg; *s != NUL; s += 3) |
| 819 | { |
| 820 | if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) |
| 821 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 822 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 823 | break; |
| 824 | } |
| 825 | if (s[2] == NUL) |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | #endif |
| 830 | |
| 831 | // 'highlight' |
| 832 | else if (varp == &p_hl) |
| 833 | { |
| 834 | if (highlight_changed() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 835 | errmsg = e_invalid_argument; // invalid flags |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | // 'nrformats' |
| 839 | else if (gvarp == &p_nf) |
| 840 | { |
| 841 | if (check_opt_strings(*varp, p_nf_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 842 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | #ifdef FEAT_SESSION |
| 846 | // 'sessionoptions' |
| 847 | else if (varp == &p_ssop) |
| 848 | { |
| 849 | if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 850 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 851 | if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) |
| 852 | { |
| 853 | // Don't allow both "sesdir" and "curdir". |
| 854 | (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE); |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 855 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | // 'viewoptions' |
| 859 | else if (varp == &p_vop) |
| 860 | { |
| 861 | if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 862 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 863 | } |
| 864 | #endif |
| 865 | |
| 866 | // 'scrollopt' |
| 867 | else if (varp == &p_sbo) |
| 868 | { |
| 869 | if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 870 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | // 'ambiwidth' |
| 874 | else if (varp == &p_ambw || varp == &p_emoji) |
| 875 | { |
| 876 | if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 877 | errmsg = e_invalid_argument; |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 878 | else if (set_chars_option(curwin, &p_fcs) != NULL) |
zeertzjq | 94358a1 | 2021-10-20 11:01:15 +0100 | [diff] [blame] | 879 | errmsg = _(e_conflicts_with_value_of_fillchars); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 880 | else |
| 881 | { |
| 882 | tabpage_T *tp; |
| 883 | win_T *wp; |
| 884 | |
| 885 | FOR_ALL_TAB_WINDOWS(tp, wp) |
| 886 | { |
| 887 | if (set_chars_option(wp, &wp->w_p_lcs) != NULL) |
| 888 | { |
zeertzjq | 94358a1 | 2021-10-20 11:01:15 +0100 | [diff] [blame] | 889 | errmsg = _(e_conflicts_with_value_of_listchars); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 890 | goto ambw_end; |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | ambw_end: |
| 895 | {} |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | // 'background' |
| 899 | else if (varp == &p_bg) |
| 900 | { |
| 901 | if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK) |
| 902 | { |
| 903 | #ifdef FEAT_EVAL |
| 904 | int dark = (*p_bg == 'd'); |
| 905 | #endif |
| 906 | |
| 907 | init_highlight(FALSE, FALSE); |
| 908 | |
| 909 | #ifdef FEAT_EVAL |
| 910 | if (dark != (*p_bg == 'd') |
| 911 | && get_var_value((char_u *)"g:colors_name") != NULL) |
| 912 | { |
| 913 | // The color scheme must have set 'background' back to another |
| 914 | // value, that's not what we want here. Disable the color |
| 915 | // scheme and set the colors again. |
| 916 | do_unlet((char_u *)"g:colors_name", TRUE); |
| 917 | free_string_option(p_bg); |
| 918 | p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); |
| 919 | check_string_option(&p_bg); |
| 920 | init_highlight(FALSE, FALSE); |
| 921 | } |
| 922 | #endif |
Bram Moolenaar | ad43199 | 2021-05-03 20:40:38 +0200 | [diff] [blame] | 923 | #ifdef FEAT_TERMINAL |
| 924 | term_update_colors_all(); |
| 925 | #endif |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 926 | } |
| 927 | else |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 928 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // 'wildmode' |
| 932 | else if (varp == &p_wim) |
| 933 | { |
| 934 | if (check_opt_wim() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 935 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | // 'wildoptions' |
| 939 | else if (varp == &p_wop) |
| 940 | { |
| 941 | if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 942 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | #ifdef FEAT_WAK |
| 946 | // 'winaltkeys' |
| 947 | else if (varp == &p_wak) |
| 948 | { |
| 949 | if (*p_wak == NUL |
| 950 | || check_opt_strings(p_wak, p_wak_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 951 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 952 | # ifdef FEAT_MENU |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 953 | # if defined(FEAT_GUI_MOTIF) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 954 | else if (gui.in_use) |
| 955 | gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); |
ichizok | 0256042 | 2022-04-05 14:18:44 +0100 | [diff] [blame] | 956 | # elif defined(FEAT_GUI_GTK) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 957 | else if (gui.in_use) |
| 958 | gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 959 | # endif |
| 960 | # endif |
| 961 | } |
| 962 | #endif |
| 963 | |
| 964 | // 'eventignore' |
| 965 | else if (varp == &p_ei) |
| 966 | { |
| 967 | if (check_ei() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 968 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | // 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' |
| 972 | else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc |
| 973 | || gvarp == &p_menc) |
| 974 | { |
| 975 | if (gvarp == &p_fenc) |
| 976 | { |
| 977 | if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL) |
Bram Moolenaar | 108010a | 2021-06-27 22:03:33 +0200 | [diff] [blame] | 978 | errmsg = e_cannot_make_changes_modifiable_is_off; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 979 | else if (vim_strchr(*varp, ',') != NULL) |
| 980 | // No comma allowed in 'fileencoding'; catches confusing it |
| 981 | // with 'fileencodings'. |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 982 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 983 | else |
| 984 | { |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 985 | // May show a "+" in the title now. |
| 986 | redraw_titles(); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 987 | // Add 'fileencoding' to the swap file. |
| 988 | ml_setflags(curbuf); |
| 989 | } |
| 990 | } |
| 991 | if (errmsg == NULL) |
| 992 | { |
| 993 | // canonize the value, so that STRCMP() can be used on it |
| 994 | p = enc_canonize(*varp); |
| 995 | if (p != NULL) |
| 996 | { |
| 997 | vim_free(*varp); |
| 998 | *varp = p; |
| 999 | } |
| 1000 | if (varp == &p_enc) |
| 1001 | { |
| 1002 | errmsg = mb_init(); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1003 | redraw_titles(); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | #if defined(FEAT_GUI_GTK) |
| 1008 | if (errmsg == NULL && varp == &p_tenc && gui.in_use) |
| 1009 | { |
Bram Moolenaar | d88be5b | 2022-01-04 19:57:55 +0000 | [diff] [blame] | 1010 | // GTK uses only a single encoding, and that is UTF-8. |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1011 | if (STRCMP(p_tenc, "utf-8") != 0) |
Bram Moolenaar | d88be5b | 2022-01-04 19:57:55 +0000 | [diff] [blame] | 1012 | errmsg = e_cannot_be_changed_in_gtk_GUI; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1013 | } |
| 1014 | #endif |
| 1015 | |
| 1016 | if (errmsg == NULL) |
| 1017 | { |
| 1018 | #ifdef FEAT_KEYMAP |
| 1019 | // When 'keymap' is used and 'encoding' changes, reload the keymap |
| 1020 | // (with another encoding). |
| 1021 | if (varp == &p_enc && *curbuf->b_p_keymap != NUL) |
| 1022 | (void)keymap_init(); |
| 1023 | #endif |
| 1024 | |
| 1025 | // When 'termencoding' is not empty and 'encoding' changes or when |
| 1026 | // 'termencoding' changes, need to setup for keyboard input and |
| 1027 | // display output conversion. |
| 1028 | if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc)) |
| 1029 | { |
| 1030 | if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL |
| 1031 | || convert_setup(&output_conv, p_enc, p_tenc) == FAIL) |
| 1032 | { |
Bram Moolenaar | d82a47d | 2022-01-05 20:24:39 +0000 | [diff] [blame] | 1033 | semsg(_(e_cannot_convert_between_str_and_str), |
| 1034 | p_tenc, p_enc); |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1035 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | #if defined(MSWIN) |
| 1040 | // $HOME may have characters in active code page. |
| 1041 | if (varp == &p_enc) |
| 1042 | init_homedir(); |
| 1043 | #endif |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | #if defined(FEAT_POSTSCRIPT) |
| 1048 | else if (varp == &p_penc) |
| 1049 | { |
| 1050 | // Canonize printencoding if VIM standard one |
| 1051 | p = enc_canonize(p_penc); |
| 1052 | if (p != NULL) |
| 1053 | { |
| 1054 | vim_free(p_penc); |
| 1055 | p_penc = p; |
| 1056 | } |
| 1057 | else |
| 1058 | { |
| 1059 | // Ensure lower case and '-' for '_' |
| 1060 | for (s = p_penc; *s != NUL; s++) |
| 1061 | { |
| 1062 | if (*s == '_') |
| 1063 | *s = '-'; |
| 1064 | else |
| 1065 | *s = TOLOWER_ASC(*s); |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | #endif |
| 1070 | |
| 1071 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
| 1072 | else if (varp == &p_imak) |
| 1073 | { |
| 1074 | if (!im_xim_isvalid_imactivate()) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1075 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1076 | } |
| 1077 | #endif |
| 1078 | |
| 1079 | #ifdef FEAT_KEYMAP |
| 1080 | else if (varp == &curbuf->b_p_keymap) |
| 1081 | { |
| 1082 | if (!valid_filetype(*varp)) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1083 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1084 | else |
| 1085 | { |
| 1086 | int secure_save = secure; |
| 1087 | |
| 1088 | // Reset the secure flag, since the value of 'keymap' has |
| 1089 | // been checked to be safe. |
| 1090 | secure = 0; |
| 1091 | |
| 1092 | // load or unload key mapping tables |
| 1093 | errmsg = keymap_init(); |
| 1094 | |
| 1095 | secure = secure_save; |
| 1096 | |
| 1097 | // Since we check the value, there is no need to set P_INSECURE, |
| 1098 | // even when the value comes from a modeline. |
| 1099 | *value_checked = TRUE; |
| 1100 | } |
| 1101 | |
| 1102 | if (errmsg == NULL) |
| 1103 | { |
| 1104 | if (*curbuf->b_p_keymap != NUL) |
| 1105 | { |
| 1106 | // Installed a new keymap, switch on using it. |
| 1107 | curbuf->b_p_iminsert = B_IMODE_LMAP; |
| 1108 | if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) |
| 1109 | curbuf->b_p_imsearch = B_IMODE_LMAP; |
| 1110 | } |
| 1111 | else |
| 1112 | { |
| 1113 | // Cleared the keymap, may reset 'iminsert' and 'imsearch'. |
| 1114 | if (curbuf->b_p_iminsert == B_IMODE_LMAP) |
| 1115 | curbuf->b_p_iminsert = B_IMODE_NONE; |
| 1116 | if (curbuf->b_p_imsearch == B_IMODE_LMAP) |
| 1117 | curbuf->b_p_imsearch = B_IMODE_USE_INSERT; |
| 1118 | } |
| 1119 | if ((opt_flags & OPT_LOCAL) == 0) |
| 1120 | { |
| 1121 | set_iminsert_global(); |
| 1122 | set_imsearch_global(); |
| 1123 | } |
| 1124 | status_redraw_curbuf(); |
| 1125 | } |
| 1126 | } |
| 1127 | #endif |
| 1128 | |
| 1129 | // 'fileformat' |
| 1130 | else if (gvarp == &p_ff) |
| 1131 | { |
| 1132 | if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) |
Bram Moolenaar | 108010a | 2021-06-27 22:03:33 +0200 | [diff] [blame] | 1133 | errmsg = e_cannot_make_changes_modifiable_is_off; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1134 | else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1135 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1136 | else |
| 1137 | { |
| 1138 | // may also change 'textmode' |
| 1139 | if (get_fileformat(curbuf) == EOL_DOS) |
| 1140 | curbuf->b_p_tx = TRUE; |
| 1141 | else |
| 1142 | curbuf->b_p_tx = FALSE; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1143 | redraw_titles(); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1144 | // update flag in swap file |
| 1145 | ml_setflags(curbuf); |
| 1146 | // Redraw needed when switching to/from "mac": a CR in the text |
| 1147 | // will be displayed differently. |
| 1148 | if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm') |
| 1149 | redraw_curbuf_later(NOT_VALID); |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | // 'fileformats' |
| 1154 | else if (varp == &p_ffs) |
| 1155 | { |
| 1156 | if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1157 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1158 | else |
| 1159 | { |
| 1160 | // also change 'textauto' |
| 1161 | if (*p_ffs == NUL) |
| 1162 | p_ta = FALSE; |
| 1163 | else |
| 1164 | p_ta = TRUE; |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | #if defined(FEAT_CRYPT) |
| 1169 | // 'cryptkey' |
| 1170 | else if (gvarp == &p_key) |
| 1171 | { |
| 1172 | // Make sure the ":set" command doesn't show the new value in the |
| 1173 | // history. |
| 1174 | remove_key_from_history(); |
| 1175 | |
| 1176 | if (STRCMP(curbuf->b_p_key, oldval) != 0) |
| 1177 | // Need to update the swapfile. |
Bram Moolenaar | 76cb683 | 2020-05-15 22:30:38 +0200 | [diff] [blame] | 1178 | { |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1179 | ml_set_crypt_key(curbuf, oldval, |
| 1180 | *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm); |
Bram Moolenaar | 76cb683 | 2020-05-15 22:30:38 +0200 | [diff] [blame] | 1181 | changed_internal(); |
| 1182 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | else if (gvarp == &p_cm) |
| 1186 | { |
| 1187 | if (opt_flags & OPT_LOCAL) |
| 1188 | p = curbuf->b_p_cm; |
| 1189 | else |
| 1190 | p = p_cm; |
| 1191 | if (check_opt_strings(p, p_cm_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1192 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1193 | else if (crypt_self_test() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1194 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1195 | else |
| 1196 | { |
| 1197 | // When setting the global value to empty, make it "zip". |
| 1198 | if (*p_cm == NUL) |
| 1199 | { |
| 1200 | if (new_value_alloced) |
| 1201 | free_string_option(p_cm); |
| 1202 | p_cm = vim_strsave((char_u *)"zip"); |
| 1203 | new_value_alloced = TRUE; |
| 1204 | } |
| 1205 | // When using ":set cm=name" the local value is going to be empty. |
| 1206 | // Do that here, otherwise the crypt functions will still use the |
| 1207 | // local value. |
| 1208 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
| 1209 | { |
| 1210 | free_string_option(curbuf->b_p_cm); |
| 1211 | curbuf->b_p_cm = empty_option; |
| 1212 | } |
| 1213 | |
| 1214 | // Need to update the swapfile when the effective method changed. |
| 1215 | // Set "s" to the effective old value, "p" to the effective new |
| 1216 | // method and compare. |
| 1217 | if ((opt_flags & OPT_LOCAL) && *oldval == NUL) |
| 1218 | s = p_cm; // was previously using the global value |
| 1219 | else |
| 1220 | s = oldval; |
| 1221 | if (*curbuf->b_p_cm == NUL) |
| 1222 | p = p_cm; // is now using the global value |
| 1223 | else |
| 1224 | p = curbuf->b_p_cm; |
| 1225 | if (STRCMP(s, p) != 0) |
| 1226 | ml_set_crypt_key(curbuf, curbuf->b_p_key, s); |
| 1227 | |
| 1228 | // If the global value changes need to update the swapfile for all |
| 1229 | // buffers using that value. |
| 1230 | if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0) |
| 1231 | { |
| 1232 | buf_T *buf; |
| 1233 | |
| 1234 | FOR_ALL_BUFFERS(buf) |
| 1235 | if (buf != curbuf && *buf->b_p_cm == NUL) |
| 1236 | ml_set_crypt_key(buf, buf->b_p_key, oldval); |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | #endif |
| 1241 | |
| 1242 | // 'matchpairs' |
| 1243 | else if (gvarp == &p_mps) |
| 1244 | { |
| 1245 | if (has_mbyte) |
| 1246 | { |
| 1247 | for (p = *varp; *p != NUL; ++p) |
| 1248 | { |
| 1249 | int x2 = -1; |
| 1250 | int x3 = -1; |
| 1251 | |
=?UTF-8?q?Dundar=20G=C3=B6c?= | b836658 | 2022-04-14 20:43:56 +0100 | [diff] [blame] | 1252 | p += mb_ptr2len(p); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1253 | if (*p != NUL) |
| 1254 | x2 = *p++; |
| 1255 | if (*p != NUL) |
| 1256 | { |
| 1257 | x3 = mb_ptr2char(p); |
| 1258 | p += mb_ptr2len(p); |
| 1259 | } |
| 1260 | if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) |
| 1261 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1262 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1263 | break; |
| 1264 | } |
| 1265 | if (*p == NUL) |
| 1266 | break; |
| 1267 | } |
| 1268 | } |
| 1269 | else |
| 1270 | { |
| 1271 | // Check for "x:y,x:y" |
| 1272 | for (p = *varp; *p != NUL; p += 4) |
| 1273 | { |
| 1274 | if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) |
| 1275 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1276 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1277 | break; |
| 1278 | } |
| 1279 | if (p[3] == NUL) |
| 1280 | break; |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1285 | // 'comments' |
| 1286 | else if (gvarp == &p_com) |
| 1287 | { |
| 1288 | for (s = *varp; *s; ) |
| 1289 | { |
| 1290 | while (*s && *s != ':') |
| 1291 | { |
| 1292 | if (vim_strchr((char_u *)COM_ALL, *s) == NULL |
| 1293 | && !VIM_ISDIGIT(*s) && *s != '-') |
| 1294 | { |
| 1295 | errmsg = illegal_char(errbuf, *s); |
| 1296 | break; |
| 1297 | } |
| 1298 | ++s; |
| 1299 | } |
| 1300 | if (*s++ == NUL) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1301 | errmsg = e_missing_colon; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1302 | else if (*s == ',' || *s == NUL) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1303 | errmsg = e_zero_length_string; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1304 | if (errmsg != NULL) |
| 1305 | break; |
| 1306 | while (*s && *s != ',') |
| 1307 | { |
| 1308 | if (*s == '\\' && s[1] != NUL) |
| 1309 | ++s; |
| 1310 | ++s; |
| 1311 | } |
| 1312 | s = skip_to_option_part(s); |
| 1313 | } |
| 1314 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1315 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1316 | // global 'listchars' |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1317 | else if (varp == &p_lcs) |
| 1318 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1319 | errmsg = set_chars_option(curwin, varp); |
| 1320 | if (errmsg == NULL) |
| 1321 | { |
| 1322 | tabpage_T *tp; |
| 1323 | win_T *wp; |
| 1324 | |
| 1325 | // The current window is set to use the global 'listchars' value. |
| 1326 | // So clear the window-local value. |
| 1327 | if (!(opt_flags & OPT_GLOBAL)) |
| 1328 | clear_string_option(&curwin->w_p_lcs); |
| 1329 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 606efc7 | 2021-11-12 19:52:47 +0000 | [diff] [blame] | 1330 | // If no error was returned above, we don't expect an error |
| 1331 | // here, so ignore the return value. |
| 1332 | (void)set_chars_option(wp, &wp->w_p_lcs); |
| 1333 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1334 | redraw_all_later(NOT_VALID); |
| 1335 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1336 | } |
| 1337 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1338 | // local 'listchars' |
| 1339 | else if (varp == &curwin->w_p_lcs) |
| 1340 | errmsg = set_chars_option(curwin, varp); |
| 1341 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1342 | // 'fillchars' |
| 1343 | else if (varp == &p_fcs) |
| 1344 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1345 | errmsg = set_chars_option(curwin, varp); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | #ifdef FEAT_CMDWIN |
| 1349 | // 'cedit' |
| 1350 | else if (varp == &p_cedit) |
| 1351 | { |
| 1352 | errmsg = check_cedit(); |
| 1353 | } |
| 1354 | #endif |
| 1355 | |
| 1356 | // 'verbosefile' |
| 1357 | else if (varp == &p_vfile) |
| 1358 | { |
| 1359 | verbose_stop(); |
| 1360 | if (*p_vfile != NUL && verbose_open() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1361 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | #ifdef FEAT_VIMINFO |
| 1365 | // 'viminfo' |
| 1366 | else if (varp == &p_viminfo) |
| 1367 | { |
| 1368 | for (s = p_viminfo; *s;) |
| 1369 | { |
| 1370 | // Check it's a valid character |
| 1371 | if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL) |
| 1372 | { |
| 1373 | errmsg = illegal_char(errbuf, *s); |
| 1374 | break; |
| 1375 | } |
| 1376 | if (*s == 'n') // name is always last one |
| 1377 | break; |
| 1378 | else if (*s == 'r') // skip until next ',' |
| 1379 | { |
| 1380 | while (*++s && *s != ',') |
| 1381 | ; |
| 1382 | } |
| 1383 | else if (*s == '%') |
| 1384 | { |
| 1385 | // optional number |
| 1386 | while (vim_isdigit(*++s)) |
| 1387 | ; |
| 1388 | } |
| 1389 | else if (*s == '!' || *s == 'h' || *s == 'c') |
| 1390 | ++s; // no extra chars |
| 1391 | else // must have a number |
| 1392 | { |
| 1393 | while (vim_isdigit(*++s)) |
| 1394 | ; |
| 1395 | |
| 1396 | if (!VIM_ISDIGIT(*(s - 1))) |
| 1397 | { |
| 1398 | if (errbuf != NULL) |
| 1399 | { |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1400 | sprintf(errbuf, |
| 1401 | _(e_missing_number_after_angle_str_angle), |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1402 | transchar_byte(*(s - 1))); |
| 1403 | errmsg = errbuf; |
| 1404 | } |
| 1405 | else |
| 1406 | errmsg = ""; |
| 1407 | break; |
| 1408 | } |
| 1409 | } |
| 1410 | if (*s == ',') |
| 1411 | ++s; |
| 1412 | else if (*s) |
| 1413 | { |
| 1414 | if (errbuf != NULL) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1415 | errmsg = e_missing_comma; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1416 | else |
| 1417 | errmsg = ""; |
| 1418 | break; |
| 1419 | } |
| 1420 | } |
| 1421 | if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1422 | errmsg = e_must_specify_a_value; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1423 | } |
| 1424 | #endif // FEAT_VIMINFO |
| 1425 | |
| 1426 | // terminal options |
| 1427 | else if (istermoption_idx(opt_idx) && full_screen) |
| 1428 | { |
| 1429 | // ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" |
| 1430 | if (varp == &T_CCO) |
| 1431 | { |
| 1432 | int colors = atoi((char *)T_CCO); |
| 1433 | |
| 1434 | // Only reinitialize colors if t_Co value has really changed to |
| 1435 | // avoid expensive reload of colorscheme if t_Co is set to the |
| 1436 | // same value multiple times. |
| 1437 | if (colors != t_colors) |
| 1438 | { |
| 1439 | t_colors = colors; |
| 1440 | if (t_colors <= 1) |
| 1441 | { |
| 1442 | if (new_value_alloced) |
| 1443 | vim_free(T_CCO); |
| 1444 | T_CCO = empty_option; |
| 1445 | } |
| 1446 | #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) |
| 1447 | if (is_term_win32()) |
| 1448 | { |
| 1449 | swap_tcap(); |
| 1450 | did_swaptcap = TRUE; |
| 1451 | } |
| 1452 | #endif |
| 1453 | // We now have a different color setup, initialize it again. |
| 1454 | init_highlight(TRUE, FALSE); |
| 1455 | } |
| 1456 | } |
| 1457 | ttest(FALSE); |
| 1458 | if (varp == &T_ME) |
| 1459 | { |
| 1460 | out_str(T_ME); |
| 1461 | redraw_later(CLEAR); |
| 1462 | #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
| 1463 | // Since t_me has been set, this probably means that the user |
| 1464 | // wants to use this as default colors. Need to reset default |
| 1465 | // background/foreground colors. |
| 1466 | # ifdef VIMDLL |
| 1467 | if (!gui.in_use && !gui.starting) |
| 1468 | # endif |
| 1469 | mch_set_normal_colors(); |
| 1470 | #endif |
| 1471 | } |
| 1472 | if (varp == &T_BE && termcap_active) |
| 1473 | { |
Bram Moolenaar | 86394aa | 2020-09-05 14:27:24 +0200 | [diff] [blame] | 1474 | #ifdef FEAT_JOB_CHANNEL |
| 1475 | ch_log_output = TRUE; |
| 1476 | #endif |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1477 | if (*T_BE == NUL) |
| 1478 | // When clearing t_BE we assume the user no longer wants |
| 1479 | // bracketed paste, thus disable it by writing t_BD. |
| 1480 | out_str(T_BD); |
| 1481 | else |
| 1482 | out_str(T_BE); |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | #ifdef FEAT_LINEBREAK |
| 1487 | // 'showbreak' |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 1488 | else if (gvarp == &p_sbr) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1489 | { |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 1490 | for (s = *varp; *s; ) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1491 | { |
| 1492 | if (ptr2cells(s) != 1) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1493 | errmsg = N_(e_showbreak_contains_unprintable_or_wide_character); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1494 | MB_PTR_ADV(s); |
| 1495 | } |
| 1496 | } |
| 1497 | #endif |
| 1498 | |
| 1499 | #ifdef FEAT_GUI |
| 1500 | // 'guifont' |
| 1501 | else if (varp == &p_guifont) |
| 1502 | { |
| 1503 | if (gui.in_use) |
| 1504 | { |
| 1505 | p = p_guifont; |
| 1506 | # if defined(FEAT_GUI_GTK) |
| 1507 | // Put up a font dialog and let the user select a new value. |
| 1508 | // If this is cancelled go back to the old value but don't |
| 1509 | // give an error message. |
| 1510 | if (STRCMP(p, "*") == 0) |
| 1511 | { |
| 1512 | p = gui_mch_font_dialog(oldval); |
| 1513 | |
| 1514 | if (new_value_alloced) |
| 1515 | free_string_option(p_guifont); |
| 1516 | |
| 1517 | p_guifont = (p != NULL) ? p : vim_strsave(oldval); |
| 1518 | new_value_alloced = TRUE; |
| 1519 | } |
| 1520 | # endif |
| 1521 | if (p != NULL && gui_init_font(p_guifont, FALSE) != OK) |
| 1522 | { |
| 1523 | # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON) |
| 1524 | if (STRCMP(p_guifont, "*") == 0) |
| 1525 | { |
| 1526 | // Dialog was cancelled: Keep the old value without giving |
| 1527 | // an error message. |
| 1528 | if (new_value_alloced) |
| 1529 | free_string_option(p_guifont); |
| 1530 | p_guifont = vim_strsave(oldval); |
| 1531 | new_value_alloced = TRUE; |
| 1532 | } |
| 1533 | else |
| 1534 | # endif |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1535 | errmsg = N_(e_invalid_fonts); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | redraw_gui_only = TRUE; |
| 1539 | } |
| 1540 | # ifdef FEAT_XFONTSET |
| 1541 | else if (varp == &p_guifontset) |
| 1542 | { |
| 1543 | if (STRCMP(p_guifontset, "*") == 0) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1544 | errmsg = N_(e_cant_select_fontset); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1545 | else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1546 | errmsg = N_(e_invalid_fontset); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1547 | redraw_gui_only = TRUE; |
| 1548 | } |
| 1549 | # endif |
| 1550 | else if (varp == &p_guifontwide) |
| 1551 | { |
| 1552 | if (STRCMP(p_guifontwide, "*") == 0) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1553 | errmsg = e_cant_select_wide_font; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1554 | else if (gui_get_wide_font() == FAIL) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1555 | errmsg = e_invalid_wide_font; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1556 | redraw_gui_only = TRUE; |
| 1557 | } |
| 1558 | #endif |
Dusan Popovic | 4eeedc0 | 2021-10-16 20:52:05 +0100 | [diff] [blame] | 1559 | # if defined(FEAT_GUI_GTK) |
| 1560 | else if (varp == &p_guiligatures) |
| 1561 | { |
| 1562 | gui_set_ligatures(); |
| 1563 | redraw_gui_only = TRUE; |
| 1564 | } |
| 1565 | # endif |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1566 | |
| 1567 | #ifdef CURSOR_SHAPE |
| 1568 | // 'guicursor' |
| 1569 | else if (varp == &p_guicursor) |
| 1570 | errmsg = parse_shape_opt(SHAPE_CURSOR); |
| 1571 | #endif |
| 1572 | |
| 1573 | #ifdef FEAT_MOUSESHAPE |
| 1574 | // 'mouseshape' |
| 1575 | else if (varp == &p_mouseshape) |
| 1576 | { |
| 1577 | errmsg = parse_shape_opt(SHAPE_MOUSE); |
| 1578 | update_mouseshape(-1); |
| 1579 | } |
| 1580 | #endif |
| 1581 | |
| 1582 | #ifdef FEAT_PRINTER |
| 1583 | else if (varp == &p_popt) |
| 1584 | errmsg = parse_printoptions(); |
| 1585 | # if defined(FEAT_POSTSCRIPT) |
| 1586 | else if (varp == &p_pmfn) |
| 1587 | errmsg = parse_printmbfont(); |
| 1588 | # endif |
| 1589 | #endif |
| 1590 | |
| 1591 | #ifdef FEAT_LANGMAP |
| 1592 | // 'langmap' |
| 1593 | else if (varp == &p_langmap) |
| 1594 | langmap_set(); |
| 1595 | #endif |
| 1596 | |
| 1597 | #ifdef FEAT_LINEBREAK |
| 1598 | // 'breakat' |
| 1599 | else if (varp == &p_breakat) |
| 1600 | fill_breakat_flags(); |
| 1601 | #endif |
| 1602 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1603 | // 'titlestring' and 'iconstring' |
| 1604 | else if (varp == &p_titlestring || varp == &p_iconstring) |
| 1605 | { |
Bram Moolenaar | 651fca8 | 2021-11-29 20:39:38 +0000 | [diff] [blame] | 1606 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1607 | int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON; |
| 1608 | |
| 1609 | // NULL => statusline syntax |
| 1610 | if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL) |
| 1611 | stl_syntax |= flagval; |
| 1612 | else |
| 1613 | stl_syntax &= ~flagval; |
Bram Moolenaar | 651fca8 | 2021-11-29 20:39:38 +0000 | [diff] [blame] | 1614 | #endif |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1615 | did_set_title(); |
| 1616 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1617 | |
| 1618 | #ifdef FEAT_GUI |
| 1619 | // 'guioptions' |
| 1620 | else if (varp == &p_go) |
| 1621 | { |
| 1622 | gui_init_which_components(oldval); |
| 1623 | redraw_gui_only = TRUE; |
| 1624 | } |
| 1625 | #endif |
| 1626 | |
| 1627 | #if defined(FEAT_GUI_TABLINE) |
| 1628 | // 'guitablabel' |
| 1629 | else if (varp == &p_gtl) |
| 1630 | { |
| 1631 | redraw_tabline = TRUE; |
| 1632 | redraw_gui_only = TRUE; |
| 1633 | } |
| 1634 | // 'guitabtooltip' |
| 1635 | else if (varp == &p_gtt) |
| 1636 | { |
| 1637 | redraw_gui_only = TRUE; |
| 1638 | } |
| 1639 | #endif |
| 1640 | |
Bram Moolenaar | a1cb1d1 | 2019-10-17 23:00:07 +0200 | [diff] [blame] | 1641 | #if defined(UNIX) || defined(VMS) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1642 | // 'ttymouse' |
| 1643 | else if (varp == &p_ttym) |
| 1644 | { |
| 1645 | // Switch the mouse off before changing the escape sequences used for |
| 1646 | // that. |
| 1647 | mch_setmouse(FALSE); |
| 1648 | if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1649 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1650 | else |
| 1651 | check_mouse_termcode(); |
| 1652 | if (termcap_active) |
| 1653 | setmouse(); // may switch it on again |
| 1654 | } |
| 1655 | #endif |
| 1656 | |
| 1657 | // 'selection' |
| 1658 | else if (varp == &p_sel) |
| 1659 | { |
| 1660 | if (*p_sel == NUL |
| 1661 | || check_opt_strings(p_sel, p_sel_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1662 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | // 'selectmode' |
| 1666 | else if (varp == &p_slm) |
| 1667 | { |
| 1668 | if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1669 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | #ifdef FEAT_BROWSE |
| 1673 | // 'browsedir' |
| 1674 | else if (varp == &p_bsdir) |
| 1675 | { |
| 1676 | if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK |
| 1677 | && !mch_isdir(p_bsdir)) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1678 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1679 | } |
| 1680 | #endif |
| 1681 | |
| 1682 | // 'keymodel' |
| 1683 | else if (varp == &p_km) |
| 1684 | { |
| 1685 | if (check_opt_strings(p_km, p_km_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1686 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1687 | else |
| 1688 | { |
| 1689 | km_stopsel = (vim_strchr(p_km, 'o') != NULL); |
| 1690 | km_startsel = (vim_strchr(p_km, 'a') != NULL); |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | // 'mousemodel' |
| 1695 | else if (varp == &p_mousem) |
| 1696 | { |
| 1697 | if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1698 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1699 | #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002) |
| 1700 | else if (*p_mousem != *oldval) |
| 1701 | // Changed from "extend" to "popup" or "popup_setpos" or vv: need |
| 1702 | // to create or delete the popup menus. |
| 1703 | gui_motif_update_mousemodel(root_menu); |
| 1704 | #endif |
| 1705 | } |
| 1706 | |
| 1707 | // 'switchbuf' |
| 1708 | else if (varp == &p_swb) |
| 1709 | { |
| 1710 | if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1711 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | // 'debug' |
| 1715 | else if (varp == &p_debug) |
| 1716 | { |
| 1717 | if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1718 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | // 'display' |
| 1722 | else if (varp == &p_dy) |
| 1723 | { |
| 1724 | if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1725 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1726 | else |
| 1727 | (void)init_chartab(); |
| 1728 | |
| 1729 | } |
| 1730 | |
| 1731 | // 'eadirection' |
| 1732 | else if (varp == &p_ead) |
| 1733 | { |
| 1734 | if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1735 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | #ifdef FEAT_CLIPBOARD |
| 1739 | // 'clipboard' |
| 1740 | else if (varp == &p_cb) |
| 1741 | errmsg = check_clipboard_option(); |
| 1742 | #endif |
| 1743 | |
| 1744 | #ifdef FEAT_SPELL |
| 1745 | // When 'spelllang' or 'spellfile' is set and there is a window for this |
| 1746 | // buffer in which 'spell' is set load the wordlists. |
| 1747 | else if (varp == &(curwin->w_s->b_p_spl) |
| 1748 | || varp == &(curwin->w_s->b_p_spf)) |
| 1749 | { |
| 1750 | int is_spellfile = varp == &(curwin->w_s->b_p_spf); |
| 1751 | |
| 1752 | if ((is_spellfile && !valid_spellfile(*varp)) |
Bram Moolenaar | f154f3a | 2020-06-08 18:54:49 +0200 | [diff] [blame] | 1753 | || (!is_spellfile && !valid_spelllang(*varp))) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1754 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1755 | else |
| 1756 | errmsg = did_set_spell_option(is_spellfile); |
| 1757 | } |
| 1758 | // When 'spellcapcheck' is set compile the regexp program. |
| 1759 | else if (varp == &(curwin->w_s->b_p_spc)) |
| 1760 | { |
| 1761 | errmsg = compile_cap_prog(curwin->w_s); |
| 1762 | } |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 1763 | // 'spelloptions' |
| 1764 | else if (varp == &(curwin->w_s->b_p_spo)) |
| 1765 | { |
| 1766 | if (**varp != NUL && STRCMP("camel", *varp) != 0) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1767 | errmsg = e_invalid_argument; |
Bram Moolenaar | 362b44b | 2020-06-10 21:47:00 +0200 | [diff] [blame] | 1768 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1769 | // 'spellsuggest' |
| 1770 | else if (varp == &p_sps) |
| 1771 | { |
| 1772 | if (spell_check_sps() != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1773 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1774 | } |
| 1775 | // 'mkspellmem' |
| 1776 | else if (varp == &p_msm) |
| 1777 | { |
| 1778 | if (spell_check_msm() != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1779 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1780 | } |
| 1781 | #endif |
| 1782 | |
| 1783 | // When 'bufhidden' is set, check for valid value. |
| 1784 | else if (gvarp == &p_bh) |
| 1785 | { |
| 1786 | if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1787 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | // When 'buftype' is set, check for valid value. |
| 1791 | else if (gvarp == &p_bt) |
| 1792 | { |
| 1793 | if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1794 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1795 | else |
| 1796 | { |
| 1797 | if (curwin->w_status_height) |
| 1798 | { |
| 1799 | curwin->w_redr_status = TRUE; |
| 1800 | redraw_later(VALID); |
| 1801 | } |
| 1802 | curbuf->b_help = (curbuf->b_p_bt[0] == 'h'); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1803 | redraw_titles(); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | #ifdef FEAT_STL_OPT |
| 1808 | // 'statusline' or 'rulerformat' |
| 1809 | else if (gvarp == &p_stl || varp == &p_ruf) |
| 1810 | { |
| 1811 | int wid; |
| 1812 | |
| 1813 | if (varp == &p_ruf) // reset ru_wid first |
| 1814 | ru_wid = 0; |
| 1815 | s = *varp; |
| 1816 | if (varp == &p_ruf && *s == '%') |
| 1817 | { |
| 1818 | // set ru_wid if 'ruf' starts with "%99(" |
| 1819 | if (*++s == '-') // ignore a '-' |
| 1820 | s++; |
| 1821 | wid = getdigits(&s); |
| 1822 | if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) |
| 1823 | ru_wid = wid; |
| 1824 | else |
| 1825 | errmsg = check_stl_option(p_ruf); |
| 1826 | } |
| 1827 | // check 'statusline' only if it doesn't start with "%!" |
| 1828 | else if (varp == &p_ruf || s[0] != '%' || s[1] != '!') |
| 1829 | errmsg = check_stl_option(s); |
| 1830 | if (varp == &p_ruf && errmsg == NULL) |
| 1831 | comp_col(); |
| 1832 | } |
| 1833 | #endif |
| 1834 | |
| 1835 | // check if it is a valid value for 'complete' -- Acevedo |
| 1836 | else if (gvarp == &p_cpt) |
| 1837 | { |
| 1838 | for (s = *varp; *s;) |
| 1839 | { |
| 1840 | while (*s == ',' || *s == ' ') |
| 1841 | s++; |
| 1842 | if (!*s) |
| 1843 | break; |
| 1844 | if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL) |
| 1845 | { |
| 1846 | errmsg = illegal_char(errbuf, *s); |
| 1847 | break; |
| 1848 | } |
| 1849 | if (*++s != NUL && *s != ',' && *s != ' ') |
| 1850 | { |
| 1851 | if (s[-1] == 'k' || s[-1] == 's') |
| 1852 | { |
| 1853 | // skip optional filename after 'k' and 's' |
| 1854 | while (*s && *s != ',' && *s != ' ') |
| 1855 | { |
| 1856 | if (*s == '\\' && s[1] != NUL) |
| 1857 | ++s; |
| 1858 | ++s; |
| 1859 | } |
| 1860 | } |
| 1861 | else |
| 1862 | { |
| 1863 | if (errbuf != NULL) |
| 1864 | { |
| 1865 | sprintf((char *)errbuf, |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 1866 | _(e_illegal_character_after_chr), *--s); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1867 | errmsg = errbuf; |
| 1868 | } |
| 1869 | else |
| 1870 | errmsg = ""; |
| 1871 | break; |
| 1872 | } |
| 1873 | } |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | // 'completeopt' |
| 1878 | else if (varp == &p_cot) |
| 1879 | { |
| 1880 | if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1881 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1882 | else |
| 1883 | completeopt_was_set(); |
| 1884 | } |
| 1885 | |
| 1886 | #ifdef BACKSLASH_IN_FILENAME |
| 1887 | // 'completeslash' |
| 1888 | else if (gvarp == &p_csl) |
| 1889 | { |
| 1890 | if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK |
| 1891 | || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1892 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1893 | } |
| 1894 | #endif |
| 1895 | |
| 1896 | #ifdef FEAT_SIGNS |
| 1897 | // 'signcolumn' |
| 1898 | else if (varp == &curwin->w_p_scl) |
| 1899 | { |
| 1900 | if (check_opt_strings(*varp, p_scl_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1901 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1902 | // When changing the 'signcolumn' to or from 'number', recompute the |
| 1903 | // width of the number column if 'number' or 'relativenumber' is set. |
| 1904 | if (((*oldval == 'n' && *(oldval + 1) == 'u') |
| 1905 | || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u')) |
| 1906 | && (curwin->w_p_nu || curwin->w_p_rnu)) |
| 1907 | curwin->w_nrwidth_line_count = 0; |
| 1908 | } |
| 1909 | #endif |
| 1910 | |
| 1911 | |
| 1912 | #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) |
| 1913 | // 'toolbar' |
| 1914 | else if (varp == &p_toolbar) |
| 1915 | { |
| 1916 | if (opt_strings_flags(p_toolbar, p_toolbar_values, |
| 1917 | &toolbar_flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1918 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1919 | else |
| 1920 | { |
| 1921 | out_flush(); |
| 1922 | gui_mch_show_toolbar((toolbar_flags & |
| 1923 | (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); |
| 1924 | } |
| 1925 | } |
| 1926 | #endif |
| 1927 | |
| 1928 | #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) |
| 1929 | // 'toolbariconsize': GTK+ 2 only |
| 1930 | else if (varp == &p_tbis) |
| 1931 | { |
| 1932 | if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1933 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1934 | else |
| 1935 | { |
| 1936 | out_flush(); |
| 1937 | gui_mch_show_toolbar((toolbar_flags & |
| 1938 | (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); |
| 1939 | } |
| 1940 | } |
| 1941 | #endif |
| 1942 | |
| 1943 | // 'pastetoggle': translate key codes like in a mapping |
| 1944 | else if (varp == &p_pt) |
| 1945 | { |
| 1946 | if (*p_pt) |
| 1947 | { |
Bram Moolenaar | 1e7b52a | 2019-10-13 16:59:08 +0200 | [diff] [blame] | 1948 | (void)replace_termcodes(p_pt, &p, |
| 1949 | REPTERM_FROM_PART | REPTERM_DO_LT, NULL); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1950 | if (p != NULL) |
| 1951 | { |
| 1952 | if (new_value_alloced) |
| 1953 | free_string_option(p_pt); |
| 1954 | p_pt = p; |
| 1955 | new_value_alloced = TRUE; |
| 1956 | } |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | // 'backspace' |
| 1961 | else if (varp == &p_bs) |
| 1962 | { |
| 1963 | if (VIM_ISDIGIT(*p_bs)) |
| 1964 | { |
Bram Moolenaar | aa0489e | 2020-04-17 19:41:21 +0200 | [diff] [blame] | 1965 | if (*p_bs > '3' || p_bs[1] != NUL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1966 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1967 | } |
| 1968 | else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1969 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1970 | } |
| 1971 | else if (varp == &p_bo) |
| 1972 | { |
| 1973 | if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1974 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | // 'tagcase' |
| 1978 | else if (gvarp == &p_tc) |
| 1979 | { |
| 1980 | unsigned int *flags; |
| 1981 | |
| 1982 | if (opt_flags & OPT_LOCAL) |
| 1983 | { |
| 1984 | p = curbuf->b_p_tc; |
| 1985 | flags = &curbuf->b_tc_flags; |
| 1986 | } |
| 1987 | else |
| 1988 | { |
| 1989 | p = p_tc; |
| 1990 | flags = &tc_flags; |
| 1991 | } |
| 1992 | |
| 1993 | if ((opt_flags & OPT_LOCAL) && *p == NUL) |
| 1994 | // make the local value empty: use the global value |
| 1995 | *flags = 0; |
| 1996 | else if (*p == NUL |
| 1997 | || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 1998 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | // 'casemap' |
| 2002 | else if (varp == &p_cmp) |
| 2003 | { |
| 2004 | if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2005 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | #ifdef FEAT_DIFF |
| 2009 | // 'diffopt' |
| 2010 | else if (varp == &p_dip) |
| 2011 | { |
| 2012 | if (diffopt_changed() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2013 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2014 | } |
| 2015 | #endif |
| 2016 | |
| 2017 | #ifdef FEAT_FOLDING |
| 2018 | // 'foldmethod' |
| 2019 | else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) |
| 2020 | { |
| 2021 | if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK |
| 2022 | || *curwin->w_p_fdm == NUL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2023 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2024 | else |
| 2025 | { |
| 2026 | foldUpdateAll(curwin); |
| 2027 | if (foldmethodIsDiff(curwin)) |
| 2028 | newFoldLevel(); |
| 2029 | } |
| 2030 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2031 | // 'foldmarker' |
| 2032 | else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) |
| 2033 | { |
| 2034 | p = vim_strchr(*varp, ','); |
| 2035 | if (p == NULL) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 2036 | errmsg = e_comma_required; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2037 | else if (p == *varp || p[1] == NUL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2038 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2039 | else if (foldmethodIsMarker(curwin)) |
| 2040 | foldUpdateAll(curwin); |
| 2041 | } |
| 2042 | // 'commentstring' |
| 2043 | else if (gvarp == &p_cms) |
| 2044 | { |
| 2045 | if (**varp != NUL && strstr((char *)*varp, "%s") == NULL) |
Bram Moolenaar | 1d423ef | 2022-01-02 21:26:16 +0000 | [diff] [blame] | 2046 | errmsg = e_commentstring_must_be_empty_or_contain_str; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2047 | } |
| 2048 | // 'foldopen' |
| 2049 | else if (varp == &p_fdo) |
| 2050 | { |
| 2051 | if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2052 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2053 | } |
| 2054 | // 'foldclose' |
| 2055 | else if (varp == &p_fcl) |
| 2056 | { |
| 2057 | if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2058 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2059 | } |
| 2060 | // 'foldignore' |
| 2061 | else if (gvarp == &curwin->w_allbuf_opt.wo_fdi) |
| 2062 | { |
| 2063 | if (foldmethodIsIndent(curwin)) |
| 2064 | foldUpdateAll(curwin); |
| 2065 | } |
| 2066 | #endif |
| 2067 | |
| 2068 | // 'virtualedit' |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 2069 | else if (gvarp == &p_ve) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2070 | { |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 2071 | char_u *ve = p_ve; |
| 2072 | unsigned int *flags = &ve_flags; |
| 2073 | |
| 2074 | if (opt_flags & OPT_LOCAL) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2075 | { |
Gary Johnson | 51ad850 | 2021-08-03 18:33:08 +0200 | [diff] [blame] | 2076 | ve = curwin->w_p_ve; |
| 2077 | flags = &curwin->w_ve_flags; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | if ((opt_flags & OPT_LOCAL) && *ve == NUL) |
| 2081 | // make the local value empty: use the global value |
| 2082 | *flags = 0; |
| 2083 | else |
| 2084 | { |
| 2085 | if (opt_strings_flags(ve, p_ve_values, flags, TRUE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2086 | errmsg = e_invalid_argument; |
Gary Johnson | 53ba05b | 2021-07-26 22:19:10 +0200 | [diff] [blame] | 2087 | else if (STRCMP(p_ve, oldval) != 0) |
| 2088 | { |
| 2089 | // Recompute cursor position in case the new 've' setting |
| 2090 | // changes something. |
| 2091 | validate_virtcol(); |
| 2092 | coladvance(curwin->w_virtcol); |
| 2093 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX) |
| 2098 | else if (varp == &p_csqf) |
| 2099 | { |
| 2100 | if (p_csqf != NULL) |
| 2101 | { |
| 2102 | p = p_csqf; |
| 2103 | while (*p != NUL) |
| 2104 | { |
| 2105 | if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL |
| 2106 | || p[1] == NUL |
| 2107 | || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL |
| 2108 | || (p[2] != NUL && p[2] != ',')) |
| 2109 | { |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2110 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2111 | break; |
| 2112 | } |
| 2113 | else if (p[2] == NUL) |
| 2114 | break; |
| 2115 | else |
| 2116 | p += 3; |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | #endif |
| 2121 | |
| 2122 | #ifdef FEAT_CINDENT |
| 2123 | // 'cinoptions' |
| 2124 | else if (gvarp == &p_cino) |
| 2125 | { |
| 2126 | // TODO: recognize errors |
| 2127 | parse_cino(curbuf); |
| 2128 | } |
| 2129 | #endif |
| 2130 | |
| 2131 | #if defined(FEAT_RENDER_OPTIONS) |
| 2132 | // 'renderoptions' |
| 2133 | else if (varp == &p_rop) |
| 2134 | { |
| 2135 | if (!gui_mch_set_rendering_options(p_rop)) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2136 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2137 | } |
| 2138 | #endif |
| 2139 | |
| 2140 | else if (gvarp == &p_ft) |
| 2141 | { |
| 2142 | if (!valid_filetype(*varp)) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2143 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2144 | else |
| 2145 | { |
| 2146 | value_changed = STRCMP(oldval, *varp) != 0; |
| 2147 | |
| 2148 | // Since we check the value, there is no need to set P_INSECURE, |
| 2149 | // even when the value comes from a modeline. |
| 2150 | *value_checked = TRUE; |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | #ifdef FEAT_SYN_HL |
| 2155 | else if (gvarp == &p_syn) |
| 2156 | { |
| 2157 | if (!valid_filetype(*varp)) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2158 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2159 | else |
| 2160 | { |
| 2161 | value_changed = STRCMP(oldval, *varp) != 0; |
| 2162 | |
| 2163 | // Since we check the value, there is no need to set P_INSECURE, |
| 2164 | // even when the value comes from a modeline. |
| 2165 | *value_checked = TRUE; |
| 2166 | } |
| 2167 | } |
| 2168 | #endif |
| 2169 | |
| 2170 | #ifdef FEAT_TERMINAL |
| 2171 | // 'termwinkey' |
| 2172 | else if (varp == &curwin->w_p_twk) |
| 2173 | { |
| 2174 | if (*curwin->w_p_twk != NUL |
| 2175 | && string_to_key(curwin->w_p_twk, TRUE) == 0) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2176 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2177 | } |
| 2178 | // 'termwinsize' |
| 2179 | else if (varp == &curwin->w_p_tws) |
| 2180 | { |
| 2181 | if (*curwin->w_p_tws != NUL) |
| 2182 | { |
| 2183 | p = skipdigits(curwin->w_p_tws); |
| 2184 | if (p == curwin->w_p_tws |
| 2185 | || (*p != 'x' && *p != '*') |
| 2186 | || *skipdigits(p + 1) != NUL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2187 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2188 | } |
| 2189 | } |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2190 | // 'wincolor' |
| 2191 | else if (varp == &curwin->w_p_wcr) |
Bram Moolenaar | 87fd092 | 2021-11-20 13:47:45 +0000 | [diff] [blame] | 2192 | term_update_wincolor(curwin); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2193 | # if defined(MSWIN) |
| 2194 | // 'termwintype' |
| 2195 | else if (varp == &p_twt) |
| 2196 | { |
| 2197 | if (check_opt_strings(*varp, p_twt_values, FALSE) != OK) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2198 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2199 | } |
| 2200 | # endif |
| 2201 | #endif |
| 2202 | |
| 2203 | #ifdef FEAT_VARTABS |
| 2204 | // 'varsofttabstop' |
| 2205 | else if (varp == &(curbuf->b_p_vsts)) |
| 2206 | { |
| 2207 | char_u *cp; |
| 2208 | |
| 2209 | if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) |
| 2210 | { |
| 2211 | if (curbuf->b_p_vsts_array) |
| 2212 | { |
| 2213 | vim_free(curbuf->b_p_vsts_array); |
| 2214 | curbuf->b_p_vsts_array = 0; |
| 2215 | } |
| 2216 | } |
| 2217 | else |
| 2218 | { |
| 2219 | for (cp = *varp; *cp; ++cp) |
| 2220 | { |
| 2221 | if (vim_isdigit(*cp)) |
| 2222 | continue; |
| 2223 | if (*cp == ',' && cp > *varp && *(cp-1) != ',') |
| 2224 | continue; |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2225 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2226 | break; |
| 2227 | } |
| 2228 | if (errmsg == NULL) |
| 2229 | { |
| 2230 | int *oldarray = curbuf->b_p_vsts_array; |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2231 | if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)) == OK) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2232 | { |
| 2233 | if (oldarray) |
| 2234 | vim_free(oldarray); |
| 2235 | } |
| 2236 | else |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2237 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2238 | } |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | // 'vartabstop' |
| 2243 | else if (varp == &(curbuf->b_p_vts)) |
| 2244 | { |
| 2245 | char_u *cp; |
| 2246 | |
| 2247 | if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) |
| 2248 | { |
| 2249 | if (curbuf->b_p_vts_array) |
| 2250 | { |
| 2251 | vim_free(curbuf->b_p_vts_array); |
| 2252 | curbuf->b_p_vts_array = NULL; |
| 2253 | } |
| 2254 | } |
| 2255 | else |
| 2256 | { |
| 2257 | for (cp = *varp; *cp; ++cp) |
| 2258 | { |
| 2259 | if (vim_isdigit(*cp)) |
| 2260 | continue; |
| 2261 | if (*cp == ',' && cp > *varp && *(cp-1) != ',') |
| 2262 | continue; |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2263 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2264 | break; |
| 2265 | } |
| 2266 | if (errmsg == NULL) |
| 2267 | { |
| 2268 | int *oldarray = curbuf->b_p_vts_array; |
| 2269 | |
Bram Moolenaar | b7081e1 | 2021-09-04 18:47:28 +0200 | [diff] [blame] | 2270 | if (tabstop_set(*varp, &(curbuf->b_p_vts_array)) == OK) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2271 | { |
| 2272 | vim_free(oldarray); |
| 2273 | #ifdef FEAT_FOLDING |
| 2274 | if (foldmethodIsIndent(curwin)) |
| 2275 | foldUpdateAll(curwin); |
| 2276 | #endif |
| 2277 | } |
| 2278 | else |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2279 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | } |
| 2283 | #endif |
| 2284 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2285 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2286 | // 'previewpopup' |
| 2287 | else if (varp == &p_pvp) |
| 2288 | { |
| 2289 | if (parse_previewpopup(NULL) == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2290 | errmsg = e_invalid_argument; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2291 | } |
| 2292 | # ifdef FEAT_QUICKFIX |
| 2293 | // 'completepopup' |
| 2294 | else if (varp == &p_cpp) |
| 2295 | { |
| 2296 | if (parse_completepopup(NULL) == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2297 | errmsg = e_invalid_argument; |
Bram Moolenaar | 447bfba | 2020-07-18 16:07:16 +0200 | [diff] [blame] | 2298 | else |
| 2299 | popup_close_info(); |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2300 | } |
| 2301 | # endif |
| 2302 | #endif |
| 2303 | |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 2304 | #ifdef FEAT_EVAL |
| 2305 | // '*expr' options |
| 2306 | else if ( |
| 2307 | # ifdef FEAT_BEVAL |
| 2308 | varp == &p_bexpr || |
| 2309 | # endif |
| 2310 | # ifdef FEAT_DIFF |
| 2311 | varp == &p_dex || |
| 2312 | # endif |
| 2313 | # ifdef FEAT_FOLDING |
| 2314 | varp == &curwin->w_p_fde || |
Yegappan Lakshmanan | 27708e6 | 2021-12-26 21:54:43 +0000 | [diff] [blame] | 2315 | varp == &curwin->w_p_fdt || |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 2316 | # endif |
| 2317 | gvarp == &p_fex || |
| 2318 | # ifdef FEAT_FIND_ID |
| 2319 | gvarp == &p_inex || |
| 2320 | # endif |
| 2321 | # ifdef FEAT_CINDENT |
| 2322 | gvarp == &p_inde || |
| 2323 | # endif |
| 2324 | # ifdef FEAT_DIFF |
| 2325 | varp == &p_pex || |
| 2326 | # endif |
| 2327 | # ifdef FEAT_POSTSCRIPT |
| 2328 | varp == &p_pexpr || |
| 2329 | # endif |
Bram Moolenaar | f4e88f2 | 2022-01-23 14:17:28 +0000 | [diff] [blame] | 2330 | varp == &p_ccv) |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 2331 | { |
| 2332 | char_u **p_opt = NULL; |
| 2333 | char_u *name; |
| 2334 | |
| 2335 | // If the option value starts with <SID> or s:, then replace that with |
| 2336 | // the script identifier. |
| 2337 | # ifdef FEAT_BEVAL |
| 2338 | if (varp == &p_bexpr) // 'balloonexpr' |
| 2339 | p_opt = (opt_flags & OPT_LOCAL) ? &curbuf->b_p_bexpr : &p_bexpr; |
| 2340 | # endif |
| 2341 | # ifdef FEAT_DIFF |
| 2342 | if (varp == &p_dex) // 'diffexpr' |
| 2343 | p_opt = &p_dex; |
| 2344 | # endif |
| 2345 | # ifdef FEAT_FOLDING |
Yegappan Lakshmanan | 27708e6 | 2021-12-26 21:54:43 +0000 | [diff] [blame] | 2346 | if (varp == &curwin->w_p_fde) // 'foldexpr' |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 2347 | p_opt = &curwin->w_p_fde; |
Yegappan Lakshmanan | 27708e6 | 2021-12-26 21:54:43 +0000 | [diff] [blame] | 2348 | if (varp == &curwin->w_p_fdt) // 'foldtext' |
| 2349 | p_opt = &curwin->w_p_fdt; |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 2350 | # endif |
| 2351 | if (gvarp == &p_fex) // 'formatexpr' |
| 2352 | p_opt = &curbuf->b_p_fex; |
| 2353 | # ifdef FEAT_FIND_ID |
| 2354 | if (gvarp == &p_inex) // 'includeexpr' |
| 2355 | p_opt = &curbuf->b_p_inex; |
| 2356 | # endif |
| 2357 | # ifdef FEAT_CINDENT |
| 2358 | if (gvarp == &p_inde) // 'indentexpr' |
| 2359 | p_opt = &curbuf->b_p_inde; |
| 2360 | # endif |
| 2361 | # ifdef FEAT_DIFF |
| 2362 | if (varp == &p_pex) // 'patchexpr' |
| 2363 | p_opt = &p_pex; |
| 2364 | # endif |
| 2365 | # ifdef FEAT_POSTSCRIPT |
| 2366 | if (varp == &p_pexpr) // 'printexpr' |
| 2367 | p_opt = &p_pexpr; |
| 2368 | # endif |
Bram Moolenaar | f4e88f2 | 2022-01-23 14:17:28 +0000 | [diff] [blame] | 2369 | if (varp == &p_ccv) // 'charconvert' |
| 2370 | p_opt = &p_ccv; |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 2371 | |
| 2372 | if (p_opt != NULL) |
| 2373 | { |
| 2374 | name = get_scriptlocal_funcname(*p_opt); |
| 2375 | if (name != NULL) |
| 2376 | { |
| 2377 | if (new_value_alloced) |
| 2378 | free_string_option(*p_opt); |
| 2379 | *p_opt = name; |
| 2380 | new_value_alloced = TRUE; |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | # ifdef FEAT_FOLDING |
| 2385 | if (varp == &curwin->w_p_fde && foldmethodIsExpr(curwin)) |
| 2386 | foldUpdateAll(curwin); |
| 2387 | # endif |
| 2388 | } |
| 2389 | #endif |
| 2390 | |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 2391 | #ifdef FEAT_COMPL_FUNC |
| 2392 | // 'completefunc' |
| 2393 | else if (gvarp == &p_cfu) |
| 2394 | { |
| 2395 | if (set_completefunc_option() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2396 | errmsg = e_invalid_argument; |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | // 'omnifunc' |
| 2400 | else if (gvarp == &p_ofu) |
| 2401 | { |
| 2402 | if (set_omnifunc_option() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2403 | errmsg = e_invalid_argument; |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | // 'thesaurusfunc' |
| 2407 | else if (gvarp == &p_tsrfu) |
| 2408 | { |
| 2409 | if (set_thesaurusfunc_option() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2410 | errmsg = e_invalid_argument; |
Yegappan Lakshmanan | 8658c75 | 2021-12-03 11:09:29 +0000 | [diff] [blame] | 2411 | } |
| 2412 | #endif |
| 2413 | |
Yegappan Lakshmanan | 7645da5 | 2021-12-04 14:02:30 +0000 | [diff] [blame] | 2414 | #if defined(FEAT_EVAL) && \ |
| 2415 | (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL)) |
| 2416 | // 'imactivatefunc' |
| 2417 | else if (gvarp == &p_imaf) |
| 2418 | { |
| 2419 | if (set_imactivatefunc_option() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2420 | errmsg = e_invalid_argument; |
Yegappan Lakshmanan | 7645da5 | 2021-12-04 14:02:30 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | // 'imstatusfunc' |
| 2424 | else if (gvarp == &p_imsf) |
| 2425 | { |
| 2426 | if (set_imstatusfunc_option() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2427 | errmsg = e_invalid_argument; |
Yegappan Lakshmanan | 7645da5 | 2021-12-04 14:02:30 +0000 | [diff] [blame] | 2428 | } |
| 2429 | #endif |
| 2430 | |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 2431 | // 'operatorfunc' |
| 2432 | else if (varp == &p_opfunc) |
| 2433 | { |
| 2434 | if (set_operatorfunc_option() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2435 | errmsg = e_invalid_argument; |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 2438 | #ifdef FEAT_QUICKFIX |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 2439 | // 'quickfixtextfunc' |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 2440 | else if (varp == &p_qftf) |
| 2441 | { |
Yegappan Lakshmanan | 777175b | 2021-11-18 22:08:57 +0000 | [diff] [blame] | 2442 | if (qf_process_qftf_option() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2443 | errmsg = e_invalid_argument; |
Bram Moolenaar | d43906d | 2020-07-20 21:31:32 +0200 | [diff] [blame] | 2444 | } |
| 2445 | #endif |
| 2446 | |
Yegappan Lakshmanan | 19916a8 | 2021-11-24 16:32:55 +0000 | [diff] [blame] | 2447 | #ifdef FEAT_EVAL |
| 2448 | // 'tagfunc' |
| 2449 | else if (gvarp == &p_tfu) |
| 2450 | { |
| 2451 | if (set_tagfunc_option() == FAIL) |
Bram Moolenaar | 436b5ad | 2021-12-31 22:49:24 +0000 | [diff] [blame] | 2452 | errmsg = e_invalid_argument; |
Yegappan Lakshmanan | 19916a8 | 2021-11-24 16:32:55 +0000 | [diff] [blame] | 2453 | } |
| 2454 | #endif |
| 2455 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2456 | // Options that are a list of flags. |
| 2457 | else |
| 2458 | { |
| 2459 | p = NULL; |
| 2460 | if (varp == &p_ww) // 'whichwrap' |
| 2461 | p = (char_u *)WW_ALL; |
| 2462 | if (varp == &p_shm) // 'shortmess' |
| 2463 | p = (char_u *)SHM_ALL; |
| 2464 | else if (varp == &(p_cpo)) // 'cpoptions' |
| 2465 | p = (char_u *)CPO_ALL; |
| 2466 | else if (varp == &(curbuf->b_p_fo)) // 'formatoptions' |
| 2467 | p = (char_u *)FO_ALL; |
| 2468 | #ifdef FEAT_CONCEAL |
| 2469 | else if (varp == &curwin->w_p_cocu) // 'concealcursor' |
| 2470 | p = (char_u *)COCU_ALL; |
| 2471 | #endif |
| 2472 | else if (varp == &p_mouse) // 'mouse' |
| 2473 | { |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2474 | p = (char_u *)MOUSE_ALL; |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2475 | } |
| 2476 | #if defined(FEAT_GUI) |
| 2477 | else if (varp == &p_go) // 'guioptions' |
| 2478 | p = (char_u *)GO_ALL; |
| 2479 | #endif |
| 2480 | if (p != NULL) |
| 2481 | { |
| 2482 | for (s = *varp; *s; ++s) |
| 2483 | if (vim_strchr(p, *s) == NULL) |
| 2484 | { |
| 2485 | errmsg = illegal_char(errbuf, *s); |
| 2486 | break; |
| 2487 | } |
| 2488 | } |
| 2489 | } |
| 2490 | |
| 2491 | // If error detected, restore the previous value. |
| 2492 | if (errmsg != NULL) |
| 2493 | { |
| 2494 | if (new_value_alloced) |
| 2495 | free_string_option(*varp); |
| 2496 | *varp = oldval; |
| 2497 | // When resetting some values, need to act on it. |
| 2498 | if (did_chartab) |
| 2499 | (void)init_chartab(); |
| 2500 | if (varp == &p_hl) |
| 2501 | (void)highlight_changed(); |
| 2502 | } |
| 2503 | else |
| 2504 | { |
| 2505 | #ifdef FEAT_EVAL |
| 2506 | // Remember where the option was set. |
| 2507 | set_option_sctx_idx(opt_idx, opt_flags, current_sctx); |
| 2508 | #endif |
| 2509 | // Free string options that are in allocated memory. |
| 2510 | // Use "free_oldval", because recursiveness may change the flags under |
| 2511 | // our fingers (esp. init_highlight()). |
| 2512 | if (free_oldval) |
| 2513 | free_string_option(oldval); |
| 2514 | if (new_value_alloced) |
| 2515 | set_option_flag(opt_idx, P_ALLOCED); |
| 2516 | else |
| 2517 | clear_option_flag(opt_idx, P_ALLOCED); |
| 2518 | |
| 2519 | if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 |
| 2520 | && is_global_local_option(opt_idx)) |
| 2521 | { |
| 2522 | // global option with local value set to use global value; free |
| 2523 | // the local value and make it empty |
| 2524 | p = get_option_varp_scope(opt_idx, OPT_LOCAL); |
| 2525 | free_string_option(*(char_u **)p); |
| 2526 | *(char_u **)p = empty_option; |
| 2527 | } |
| 2528 | |
| 2529 | // May set global value for local option. |
| 2530 | else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL) |
| 2531 | set_string_option_global(opt_idx, varp); |
| 2532 | |
| 2533 | // Trigger the autocommand only after setting the flags. |
| 2534 | #ifdef FEAT_SYN_HL |
| 2535 | // When 'syntax' is set, load the syntax of that name |
| 2536 | if (varp == &(curbuf->b_p_syn)) |
| 2537 | { |
| 2538 | static int syn_recursive = 0; |
| 2539 | |
| 2540 | ++syn_recursive; |
| 2541 | // Only pass TRUE for "force" when the value changed or not used |
| 2542 | // recursively, to avoid endless recurrence. |
| 2543 | apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, |
| 2544 | value_changed || syn_recursive == 1, curbuf); |
| 2545 | curbuf->b_flags |= BF_SYN_SET; |
| 2546 | --syn_recursive; |
| 2547 | } |
| 2548 | #endif |
| 2549 | else if (varp == &(curbuf->b_p_ft)) |
| 2550 | { |
| 2551 | // 'filetype' is set, trigger the FileType autocommand. |
| 2552 | // Skip this when called from a modeline and the filetype was |
| 2553 | // already set to this value. |
| 2554 | if (!(opt_flags & OPT_MODELINE) || value_changed) |
| 2555 | { |
| 2556 | static int ft_recursive = 0; |
| 2557 | int secure_save = secure; |
| 2558 | |
| 2559 | // Reset the secure flag, since the value of 'filetype' has |
| 2560 | // been checked to be safe. |
| 2561 | secure = 0; |
| 2562 | |
| 2563 | ++ft_recursive; |
| 2564 | did_filetype = TRUE; |
| 2565 | // Only pass TRUE for "force" when the value changed or not |
| 2566 | // used recursively, to avoid endless recurrence. |
| 2567 | apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname, |
| 2568 | value_changed || ft_recursive == 1, curbuf); |
| 2569 | --ft_recursive; |
| 2570 | // Just in case the old "curbuf" is now invalid. |
| 2571 | if (varp != &(curbuf->b_p_ft)) |
| 2572 | varp = NULL; |
| 2573 | |
| 2574 | secure = secure_save; |
| 2575 | } |
| 2576 | } |
| 2577 | #ifdef FEAT_SPELL |
| 2578 | if (varp == &(curwin->w_s->b_p_spl)) |
| 2579 | { |
| 2580 | char_u fname[200]; |
| 2581 | char_u *q = curwin->w_s->b_p_spl; |
| 2582 | |
| 2583 | // Skip the first name if it is "cjk". |
| 2584 | if (STRNCMP(q, "cjk,", 4) == 0) |
| 2585 | q += 4; |
| 2586 | |
| 2587 | // Source the spell/LANG.vim in 'runtimepath'. |
| 2588 | // They could set 'spellcapcheck' depending on the language. |
| 2589 | // Use the first name in 'spelllang' up to '_region' or |
| 2590 | // '.encoding'. |
| 2591 | for (p = q; *p != NUL; ++p) |
| 2592 | if (!ASCII_ISALNUM(*p) && *p != '-') |
| 2593 | break; |
| 2594 | if (p > q) |
| 2595 | { |
| 2596 | vim_snprintf((char *)fname, 200, "spell/%.*s.vim", |
| 2597 | (int)(p - q), q); |
| 2598 | source_runtime(fname, DIP_ALL); |
| 2599 | } |
| 2600 | } |
| 2601 | #endif |
| 2602 | } |
| 2603 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2604 | if (varp == &p_mouse) |
| 2605 | { |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2606 | if (*p_mouse == NUL) |
| 2607 | mch_setmouse(FALSE); // switch mouse off |
| 2608 | else |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2609 | setmouse(); // in case 'mouse' changed |
| 2610 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2611 | |
Bram Moolenaar | 788fbb4 | 2020-05-31 14:08:12 +0200 | [diff] [blame] | 2612 | #if defined(FEAT_LUA) || defined(PROTO) |
| 2613 | if (varp == &p_rtp) |
| 2614 | update_package_paths_in_lua(); |
| 2615 | #endif |
| 2616 | |
Bram Moolenaar | b2d85e3 | 2022-01-07 16:55:32 +0000 | [diff] [blame] | 2617 | #if defined(FEAT_LINEBREAK) |
| 2618 | // Changing Formatlistpattern when briopt includes the list setting: |
| 2619 | // redraw |
| 2620 | if ((varp == &p_flp || varp == &(curbuf->b_p_flp)) |
| 2621 | && curwin->w_briopt_list) |
| 2622 | redraw_all_later(NOT_VALID); |
| 2623 | #endif |
| 2624 | |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2625 | if (curwin->w_curswant != MAXCOL |
Bram Moolenaar | a1cb1d1 | 2019-10-17 23:00:07 +0200 | [diff] [blame] | 2626 | && (get_option_flags(opt_idx) & (P_CURSWANT | P_RALL)) != 0) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2627 | curwin->w_set_curswant = TRUE; |
| 2628 | |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 2629 | if ((opt_flags & OPT_NO_REDRAW) == 0) |
| 2630 | { |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2631 | #ifdef FEAT_GUI |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 2632 | // check redraw when it's not a GUI option or the GUI is active. |
| 2633 | if (!redraw_gui_only || gui.in_use) |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2634 | #endif |
Bram Moolenaar | 37294bd | 2021-03-10 13:40:08 +0100 | [diff] [blame] | 2635 | check_redraw(get_option_flags(opt_idx)); |
| 2636 | } |
Bram Moolenaar | dac1347 | 2019-09-16 21:06:21 +0200 | [diff] [blame] | 2637 | |
| 2638 | #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) |
| 2639 | if (did_swaptcap) |
| 2640 | { |
| 2641 | set_termname((char_u *)"win32"); |
| 2642 | init_highlight(TRUE, FALSE); |
| 2643 | } |
| 2644 | #endif |
| 2645 | |
| 2646 | return errmsg; |
| 2647 | } |
| 2648 | |
| 2649 | /* |
| 2650 | * Check an option that can be a range of string values. |
| 2651 | * |
| 2652 | * Return OK for correct value, FAIL otherwise. |
| 2653 | * Empty is always OK. |
| 2654 | */ |
| 2655 | static int |
| 2656 | check_opt_strings( |
| 2657 | char_u *val, |
| 2658 | char **values, |
| 2659 | int list) // when TRUE: accept a list of values |
| 2660 | { |
| 2661 | return opt_strings_flags(val, values, NULL, list); |
| 2662 | } |
| 2663 | |
| 2664 | /* |
| 2665 | * Handle an option that can be a range of string values. |
| 2666 | * Set a flag in "*flagp" for each string present. |
| 2667 | * |
| 2668 | * Return OK for correct value, FAIL otherwise. |
| 2669 | * Empty is always OK. |
| 2670 | */ |
| 2671 | static int |
| 2672 | opt_strings_flags( |
| 2673 | char_u *val, // new value |
| 2674 | char **values, // array of valid string values |
| 2675 | unsigned *flagp, |
| 2676 | int list) // when TRUE: accept a list of values |
| 2677 | { |
| 2678 | int i; |
| 2679 | int len; |
| 2680 | unsigned new_flags = 0; |
| 2681 | |
| 2682 | while (*val) |
| 2683 | { |
| 2684 | for (i = 0; ; ++i) |
| 2685 | { |
| 2686 | if (values[i] == NULL) // val not found in values[] |
| 2687 | return FAIL; |
| 2688 | |
| 2689 | len = (int)STRLEN(values[i]); |
| 2690 | if (STRNCMP(values[i], val, len) == 0 |
| 2691 | && ((list && val[len] == ',') || val[len] == NUL)) |
| 2692 | { |
| 2693 | val += len + (val[len] == ','); |
| 2694 | new_flags |= (1 << i); |
| 2695 | break; // check next item in val list |
| 2696 | } |
| 2697 | } |
| 2698 | } |
| 2699 | if (flagp != NULL) |
| 2700 | *flagp = new_flags; |
| 2701 | |
| 2702 | return OK; |
| 2703 | } |
| 2704 | |
| 2705 | /* |
| 2706 | * return OK if "p" is a valid fileformat name, FAIL otherwise. |
| 2707 | */ |
| 2708 | int |
| 2709 | check_ff_value(char_u *p) |
| 2710 | { |
| 2711 | return check_opt_strings(p, p_ff_values, FALSE); |
| 2712 | } |