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