1 /* vi:set ts=8 sts=4 sw=4: 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 * Code to handle user-settable options. This is all pretty much table- 12 * driven. Checklist for adding a new option: 13 * - Put it in the options array below (copy an existing entry). 14 * - For a global option: Add a variable for it in option.h. 15 * - For a buffer or window local option: 16 * - Add a PV_XX entry to the enum below. 17 * - Add a variable to the window or buffer struct in structs.h. 18 * - For a window option, add some code to copy_winopt(). 19 * - For a buffer option, add some code to buf_copy_options(). 20 * - For a buffer string option, add code to check_buf_options(). 21 * - If it's a numeric option, add any necessary bounds checks to do_set(). 22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL. 23 * - When adding an option with expansion (P_EXPAND), but with a different 24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP. 25 * - Add documentation! One line in doc/help.txt, full description in 26 * options.txt, and any other related places. 27 * - Add an entry in runtime/optwin.vim. 28 * When making changes: 29 * - Adjust the help for the option in doc/option.txt. 30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a 31 * comment at the help for the 'compatible' option. 32 */ 33 34 #define IN_OPTION_C 35 #include "vim.h" 36 37 /* 38 * The options that are local to a window or buffer have "indir" set to one of 39 * these values. Special values: 40 * PV_NONE: global option. 41 * PV_BOTH is added: global option which also has a local value. 42 */ 43 #define PV_BOTH 0x1000 44 #define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x)) 45 46 typedef enum 47 { 48 PV_NONE = 0 49 , PV_AI 50 , PV_AR 51 , PV_ARAB 52 , PV_BH 53 , PV_BIN 54 , PV_BL 55 , PV_BOMB 56 , PV_BT 57 , PV_CI 58 , PV_CIN 59 , PV_CINK 60 , PV_CINO 61 , PV_CINW 62 , PV_CMS 63 , PV_COM 64 , PV_CPT 65 , PV_DEF 66 , PV_DICT 67 , PV_DIFF 68 , PV_EFM 69 , PV_EOL 70 , PV_EP 71 , PV_ET 72 , PV_FDC 73 , PV_FDE 74 , PV_FDI 75 , PV_FDL 76 , PV_FDM 77 , PV_FDN 78 , PV_FDT 79 , PV_FEN 80 , PV_FENC 81 , PV_FF 82 , PV_FML 83 , PV_FMR 84 , PV_FO 85 , PV_FT 86 , PV_GP 87 , PV_IMI 88 , PV_IMS 89 , PV_INC 90 , PV_INDE 91 , PV_INDK 92 , PV_INEX 93 , PV_INF 94 , PV_ISK 95 , PV_KEY 96 , PV_KMAP 97 , PV_KP 98 , PV_LBR 99 , PV_LISP 100 , PV_LIST 101 , PV_MA 102 , PV_ML 103 , PV_MOD 104 , PV_MP 105 , PV_MPS 106 , PV_NF 107 , PV_NU 108 , PV_OFT 109 , PV_PATH 110 , PV_PI 111 , PV_PVW 112 , PV_RL 113 , PV_RLC 114 , PV_RO 115 , PV_SCBIND 116 , PV_SCROLL 117 , PV_SI 118 , PV_SN 119 , PV_STS 120 , PV_SUA 121 , PV_SW 122 , PV_SWF 123 , PV_SYN 124 , PV_TAGS 125 , PV_TS 126 , PV_TSR 127 , PV_TW 128 , PV_TX 129 , PV_WFH 130 , PV_WM 131 , PV_WRAP 132 } idopt_T; 133 134 /* 135 * Options local to a window have a value local to a buffer and global to all 136 * buffers. Indicate this by setting "var" to VAR_WIN. 137 */ 138 #define VAR_WIN ((char_u *)-1) 139 140 /* 141 * These the global values for options which are also local to a buffer. 142 * Only to be used in option.c! 143 */ 144 static int p_ai; 145 static int p_bin; 146 #ifdef FEAT_MBYTE 147 static int p_bomb; 148 #endif 149 #if defined(FEAT_QUICKFIX) 150 static char_u *p_bh; 151 static char_u *p_bt; 152 #endif 153 static int p_bl; 154 static int p_ci; 155 #ifdef FEAT_CINDENT 156 static int p_cin; 157 static char_u *p_cink; 158 static char_u *p_cino; 159 #endif 160 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 161 static char_u *p_cinw; 162 #endif 163 #ifdef FEAT_COMMENTS 164 static char_u *p_com; 165 #endif 166 #ifdef FEAT_FOLDING 167 static char_u *p_cms; 168 #endif 169 #ifdef FEAT_INS_EXPAND 170 static char_u *p_cpt; 171 #endif 172 static int p_eol; 173 static int p_et; 174 #ifdef FEAT_MBYTE 175 static char_u *p_fenc; 176 #endif 177 static char_u *p_ff; 178 static char_u *p_fo; 179 #ifdef FEAT_AUTOCMD 180 static char_u *p_ft; 181 #endif 182 static long p_iminsert; 183 static long p_imsearch; 184 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) 185 static char_u *p_inex; 186 #endif 187 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 188 static char_u *p_inde; 189 static char_u *p_indk; 190 #endif 191 static int p_inf; 192 static char_u *p_isk; 193 #ifdef FEAT_CRYPT 194 static char_u *p_key; 195 #endif 196 #ifdef FEAT_LISP 197 static int p_lisp; 198 #endif 199 static int p_ml; 200 static int p_ma; 201 static int p_mod; 202 static char_u *p_mps; 203 static char_u *p_nf; 204 #ifdef FEAT_OSFILETYPE 205 static char_u *p_oft; 206 #endif 207 static int p_pi; 208 static int p_ro; 209 #ifdef FEAT_SMARTINDENT 210 static int p_si; 211 #endif 212 #ifndef SHORT_FNAME 213 static int p_sn; 214 #endif 215 static long p_sts; 216 #if defined(FEAT_SEARCHPATH) 217 static char_u *p_sua; 218 #endif 219 static long p_sw; 220 static int p_swf; 221 #ifdef FEAT_SYN_HL 222 static char_u *p_syn; 223 #endif 224 static long p_ts; 225 static long p_tw; 226 static int p_tx; 227 static long p_wm; 228 #ifdef FEAT_KEYMAP 229 static char_u *p_keymap; 230 #endif 231 232 /* Saved values for when 'bin' is set. */ 233 static int p_et_nobin; 234 static int p_ml_nobin; 235 static long p_tw_nobin; 236 static long p_wm_nobin; 237 238 /* Saved values for when 'paste' is set */ 239 static long p_tw_nopaste; 240 static long p_wm_nopaste; 241 static long p_sts_nopaste; 242 static int p_ai_nopaste; 243 244 struct vimoption 245 { 246 char *fullname; /* full option name */ 247 char *shortname; /* permissible abbreviation */ 248 long_u flags; /* see below */ 249 char_u *var; /* global option: pointer to variable; 250 * window-local option: VAR_WIN; 251 * buffer-local option: global value */ 252 idopt_T indir; /* global option: PV_NONE; 253 * local option: indirect option index */ 254 char_u *def_val[2]; /* default values for variable (vi and vim) */ 255 #ifdef FEAT_EVAL 256 scid_T scriptID; /* script in which the option was last set */ 257 #endif 258 }; 259 260 #define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */ 261 #define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */ 262 263 /* 264 * Flags 265 */ 266 #define P_BOOL 0x01 /* the option is boolean */ 267 #define P_NUM 0x02 /* the option is numeric */ 268 #define P_STRING 0x04 /* the option is a string */ 269 #define P_ALLOCED 0x08 /* the string option is in allocated memory, 270 must use vim_free() when assigning new 271 value. Not set if default is the same. */ 272 #define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can 273 never be used for local or hidden options! */ 274 #define P_NODEFAULT 0x40 /* don't set to default value */ 275 #define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must 276 use vim_free() when assigning new value */ 277 #define P_WAS_SET 0x100 /* option has been set/reset */ 278 #define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */ 279 #define P_VI_DEF 0x400 /* Use Vi default for Vim */ 280 #define P_VIM 0x800 /* Vim option, reset when 'cp' set */ 281 282 /* when option changed, what to display: */ 283 #define P_RSTAT 0x1000 /* redraw status lines */ 284 #define P_RWIN 0x2000 /* redraw current window */ 285 #define P_RBUF 0x4000 /* redraw current buffer */ 286 #define P_RALL 0x6000 /* redraw all windows */ 287 #define P_RCLR 0x7000 /* clear and redraw all */ 288 289 #define P_COMMA 0x8000 /* comma separated list */ 290 #define P_NODUP 0x10000L/* don't allow duplicate strings */ 291 #define P_FLAGLIST 0x20000L/* list of single-char flags */ 292 293 #define P_SECURE 0x40000L/* cannot change in modeline or secure mode */ 294 #define P_GETTEXT 0x80000L/* expand default value with _() */ 295 #define P_NOGLOB 0x100000L/* do not use local value for global vimrc */ 296 297 /* 298 * options[] is initialized here. 299 * The order of the options MUST be alphabetic for ":set all" and findoption(). 300 * All option names MUST start with a lowercase letter (for findoption()). 301 * Exception: "t_" options are at the end. 302 * The options with a NULL variable are 'hidden': a set command for them is 303 * ignored and they are not printed. 304 */ 305 static struct vimoption 306 #ifdef FEAT_GUI_W16 307 _far 308 #endif 309 options[] = 310 { 311 {"aleph", "al", P_NUM|P_VI_DEF, 312 #ifdef FEAT_RIGHTLEFT 313 (char_u *)&p_aleph, PV_NONE, 314 #else 315 (char_u *)NULL, PV_NONE, 316 #endif 317 { 318 #if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32) 319 (char_u *)128L, 320 #else 321 (char_u *)224L, 322 #endif 323 (char_u *)0L}}, 324 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, 325 #if defined(FEAT_GUI) && defined(MACOS_X) 326 (char_u *)&p_antialias, PV_NONE, 327 {(char_u *)FALSE, (char_u *)FALSE} 328 #else 329 (char_u *)NULL, PV_NONE, 330 {(char_u *)FALSE, (char_u *)FALSE} 331 #endif 332 }, 333 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM, 334 #ifdef FEAT_ARABIC 335 (char_u *)VAR_WIN, PV_ARAB, 336 #else 337 (char_u *)NULL, PV_NONE, 338 #endif 339 {(char_u *)FALSE, (char_u *)0L}}, 340 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, 341 #ifdef FEAT_ARABIC 342 (char_u *)&p_arshape, PV_NONE, 343 #else 344 (char_u *)NULL, PV_NONE, 345 #endif 346 {(char_u *)TRUE, (char_u *)0L}}, 347 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM, 348 #ifdef FEAT_RIGHTLEFT 349 (char_u *)&p_ari, PV_NONE, 350 #else 351 (char_u *)NULL, PV_NONE, 352 #endif 353 {(char_u *)FALSE, (char_u *)0L}}, 354 {"altkeymap", "akm", P_BOOL|P_VI_DEF, 355 #ifdef FEAT_FKMAP 356 (char_u *)&p_altkeymap, PV_NONE, 357 #else 358 (char_u *)NULL, PV_NONE, 359 #endif 360 {(char_u *)FALSE, (char_u *)0L}}, 361 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR, 362 #if defined(FEAT_MBYTE) 363 (char_u *)&p_ambw, PV_NONE, 364 {(char_u *)"single", (char_u *)0L} 365 #else 366 (char_u *)NULL, PV_NONE, 367 {(char_u *)0L, (char_u *)0L} 368 #endif 369 }, 370 #if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP) 371 {"autochdir", "acd", P_BOOL|P_VI_DEF, 372 (char_u *)&p_acd, PV_NONE, 373 {(char_u *)FALSE, (char_u *)0L}}, 374 #endif 375 {"autoindent", "ai", P_BOOL|P_VI_DEF, 376 (char_u *)&p_ai, PV_AI, 377 {(char_u *)FALSE, (char_u *)0L}}, 378 {"autoprint", "ap", P_BOOL|P_VI_DEF, 379 (char_u *)NULL, PV_NONE, 380 {(char_u *)FALSE, (char_u *)0L}}, 381 {"autoread", "ar", P_BOOL|P_VI_DEF, 382 (char_u *)&p_ar, OPT_BOTH(PV_AR), 383 {(char_u *)FALSE, (char_u *)0L}}, 384 {"autowrite", "aw", P_BOOL|P_VI_DEF, 385 (char_u *)&p_aw, PV_NONE, 386 {(char_u *)FALSE, (char_u *)0L}}, 387 {"autowriteall","awa", P_BOOL|P_VI_DEF, 388 (char_u *)&p_awa, PV_NONE, 389 {(char_u *)FALSE, (char_u *)0L}}, 390 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR, 391 (char_u *)&p_bg, PV_NONE, 392 { 393 #if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI) 394 (char_u *)"dark", 395 #else 396 (char_u *)"light", 397 #endif 398 (char_u *)0L}}, 399 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP, 400 (char_u *)&p_bs, PV_NONE, 401 {(char_u *)"", (char_u *)0L}}, 402 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM, 403 (char_u *)&p_bk, PV_NONE, 404 {(char_u *)FALSE, (char_u *)0L}}, 405 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP, 406 (char_u *)&p_bkc, PV_NONE, 407 #ifdef UNIX 408 {(char_u *)"yes", (char_u *)"auto"} 409 #else 410 {(char_u *)"auto", (char_u *)"auto"} 411 #endif 412 }, 413 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE, 414 (char_u *)&p_bdir, PV_NONE, 415 {(char_u *)DFLT_BDIR, (char_u *)0L}}, 416 {"backupext", "bex", P_STRING|P_VI_DEF, 417 (char_u *)&p_bex, PV_NONE, 418 { 419 #ifdef VMS 420 (char_u *)"_", 421 #else 422 (char_u *)"~", 423 #endif 424 (char_u *)0L}}, 425 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA, 426 #ifdef FEAT_WILDIGN 427 (char_u *)&p_bsk, PV_NONE, 428 {(char_u *)"", (char_u *)0L} 429 #else 430 (char_u *)NULL, PV_NONE, 431 {(char_u *)0L, (char_u *)0L} 432 #endif 433 }, 434 #ifdef FEAT_BEVAL 435 {"balloondelay","bdlay",P_NUM|P_VI_DEF, 436 (char_u *)&p_bdlay, PV_NONE, 437 {(char_u *)600L, (char_u *)0L}}, 438 #endif 439 #if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \ 440 || defined(FEAT_NETBEANS_INTG)) 441 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC, 442 (char_u *)&p_beval, PV_NONE, 443 {(char_u*)FALSE, (char_u *)0L}}, 444 #endif 445 {"beautify", "bf", P_BOOL|P_VI_DEF, 446 (char_u *)NULL, PV_NONE, 447 {(char_u *)FALSE, (char_u *)0L}}, 448 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT, 449 (char_u *)&p_bin, PV_BIN, 450 {(char_u *)FALSE, (char_u *)0L}}, 451 {"bioskey", "biosk",P_BOOL|P_VI_DEF, 452 #ifdef MSDOS 453 (char_u *)&p_biosk, PV_NONE, 454 #else 455 (char_u *)NULL, PV_NONE, 456 #endif 457 {(char_u *)TRUE, (char_u *)0L}}, 458 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT, 459 #ifdef FEAT_MBYTE 460 (char_u *)&p_bomb, PV_BOMB, 461 #else 462 (char_u *)NULL, PV_NONE, 463 #endif 464 {(char_u *)FALSE, (char_u *)0L}}, 465 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST, 466 #ifdef FEAT_LINEBREAK 467 (char_u *)&p_breakat, PV_NONE, 468 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L} 469 #else 470 (char_u *)NULL, PV_NONE, 471 {(char_u *)0L, (char_u *)0L} 472 #endif 473 }, 474 {"browsedir", "bsdir",P_STRING|P_VI_DEF, 475 #ifdef FEAT_BROWSE 476 (char_u *)&p_bsdir, PV_NONE, 477 {(char_u *)"last", (char_u *)0L} 478 #else 479 (char_u *)NULL, PV_NONE, 480 {(char_u *)0L, (char_u *)0L} 481 #endif 482 }, 483 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB, 484 #if defined(FEAT_QUICKFIX) 485 (char_u *)&p_bh, PV_BH, 486 {(char_u *)"", (char_u *)0L} 487 #else 488 (char_u *)NULL, PV_NONE, 489 {(char_u *)0L, (char_u *)0L} 490 #endif 491 }, 492 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB, 493 (char_u *)&p_bl, PV_BL, 494 {(char_u *)1L, (char_u *)0L} 495 }, 496 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB, 497 #if defined(FEAT_QUICKFIX) 498 (char_u *)&p_bt, PV_BT, 499 {(char_u *)"", (char_u *)0L} 500 #else 501 (char_u *)NULL, PV_NONE, 502 {(char_u *)0L, (char_u *)0L} 503 #endif 504 }, 505 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 506 (char_u *)&p_cmp, PV_NONE, 507 {(char_u *)"internal,keepascii", (char_u *)0L} 508 }, 509 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP, 510 #ifdef FEAT_SEARCHPATH 511 (char_u *)&p_cdpath, PV_NONE, 512 {(char_u *)",,", (char_u *)0L} 513 #else 514 (char_u *)NULL, PV_NONE, 515 {(char_u *)0L, (char_u *)0L} 516 #endif 517 }, 518 {"cedit", NULL, P_STRING, 519 #ifdef FEAT_CMDWIN 520 (char_u *)&p_cedit, PV_NONE, 521 {(char_u *)"", (char_u *)CTRL_F_STR} 522 #else 523 (char_u *)NULL, PV_NONE, 524 {(char_u *)0L, (char_u *)0L} 525 #endif 526 }, 527 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE, 528 #if defined(FEAT_MBYTE) && defined(FEAT_EVAL) 529 (char_u *)&p_ccv, PV_NONE, 530 {(char_u *)"", (char_u *)0L} 531 #else 532 (char_u *)NULL, PV_NONE, 533 {(char_u *)0L, (char_u *)0L} 534 #endif 535 }, 536 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM, 537 #ifdef FEAT_CINDENT 538 (char_u *)&p_cin, PV_CIN, 539 #else 540 (char_u *)NULL, PV_NONE, 541 #endif 542 {(char_u *)FALSE, (char_u *)0L}}, 543 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 544 #ifdef FEAT_CINDENT 545 (char_u *)&p_cink, PV_CINK, 546 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L} 547 #else 548 (char_u *)NULL, PV_NONE, 549 {(char_u *)0L, (char_u *)0L} 550 #endif 551 }, 552 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 553 #ifdef FEAT_CINDENT 554 (char_u *)&p_cino, PV_CINO, 555 #else 556 (char_u *)NULL, PV_NONE, 557 #endif 558 {(char_u *)"", (char_u *)0L}}, 559 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 560 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 561 (char_u *)&p_cinw, PV_CINW, 562 {(char_u *)"if,else,while,do,for,switch", 563 (char_u *)0L} 564 #else 565 (char_u *)NULL, PV_NONE, 566 {(char_u *)0L, (char_u *)0L} 567 #endif 568 }, 569 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 570 #ifdef FEAT_CLIPBOARD 571 (char_u *)&p_cb, PV_NONE, 572 # ifdef FEAT_XCLIPBOARD 573 {(char_u *)"autoselect,exclude:cons\\|linux", 574 (char_u *)0L} 575 # else 576 {(char_u *)"", (char_u *)0L} 577 # endif 578 #else 579 (char_u *)NULL, PV_NONE, 580 {(char_u *)"", (char_u *)0L} 581 #endif 582 }, 583 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL, 584 (char_u *)&p_ch, PV_NONE, 585 {(char_u *)1L, (char_u *)0L}}, 586 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF, 587 #ifdef FEAT_CMDWIN 588 (char_u *)&p_cwh, PV_NONE, 589 #else 590 (char_u *)NULL, PV_NONE, 591 #endif 592 {(char_u *)7L, (char_u *)0L}}, 593 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR, 594 (char_u *)&Columns, PV_NONE, 595 {(char_u *)80L, (char_u *)0L}}, 596 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 597 #ifdef FEAT_COMMENTS 598 (char_u *)&p_com, PV_COM, 599 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-", 600 (char_u *)0L} 601 #else 602 (char_u *)NULL, PV_NONE, 603 {(char_u *)0L, (char_u *)0L} 604 #endif 605 }, 606 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF, 607 #ifdef FEAT_FOLDING 608 (char_u *)&p_cms, PV_CMS, 609 {(char_u *)"/*%s*/", (char_u *)0L} 610 #else 611 (char_u *)NULL, PV_NONE, 612 {(char_u *)0L, (char_u *)0L} 613 #endif 614 }, 615 {"compatible", "cp", P_BOOL|P_RALL, 616 (char_u *)&p_cp, PV_NONE, 617 {(char_u *)TRUE, (char_u *)FALSE}}, 618 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 619 #ifdef FEAT_INS_EXPAND 620 (char_u *)&p_cpt, PV_CPT, 621 {(char_u *)".,w,b,u,t,i", (char_u *)0L} 622 #else 623 (char_u *)NULL, PV_NONE, 624 {(char_u *)0L, (char_u *)0L} 625 #endif 626 }, 627 {"confirm", "cf", P_BOOL|P_VI_DEF, 628 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) 629 (char_u *)&p_confirm, PV_NONE, 630 #else 631 (char_u *)NULL, PV_NONE, 632 #endif 633 {(char_u *)FALSE, (char_u *)0L}}, 634 {"conskey", "consk",P_BOOL|P_VI_DEF, 635 #ifdef MSDOS 636 (char_u *)&p_consk, PV_NONE, 637 #else 638 (char_u *)NULL, PV_NONE, 639 #endif 640 {(char_u *)FALSE, (char_u *)0L}}, 641 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM, 642 (char_u *)&p_ci, PV_CI, 643 {(char_u *)FALSE, (char_u *)0L}}, 644 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST, 645 (char_u *)&p_cpo, PV_NONE, 646 {(char_u *)CPO_ALL, (char_u *)CPO_DEFAULT}}, 647 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM, 648 #ifdef FEAT_CSCOPE 649 (char_u *)&p_cspc, PV_NONE, 650 #else 651 (char_u *)NULL, PV_NONE, 652 #endif 653 {(char_u *)0L, (char_u *)0L}}, 654 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 655 #ifdef FEAT_CSCOPE 656 (char_u *)&p_csprg, PV_NONE, 657 {(char_u *)"cscope", (char_u *)0L} 658 #else 659 (char_u *)NULL, PV_NONE, 660 {(char_u *)0L, (char_u *)0L} 661 #endif 662 }, 663 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 664 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX) 665 (char_u *)&p_csqf, PV_NONE, 666 {(char_u *)"", (char_u *)0L} 667 #else 668 (char_u *)NULL, PV_NONE, 669 {(char_u *)0L, (char_u *)0L} 670 #endif 671 }, 672 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM, 673 #ifdef FEAT_CSCOPE 674 (char_u *)&p_cst, PV_NONE, 675 #else 676 (char_u *)NULL, PV_NONE, 677 #endif 678 {(char_u *)0L, (char_u *)0L}}, 679 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM, 680 #ifdef FEAT_CSCOPE 681 (char_u *)&p_csto, PV_NONE, 682 #else 683 (char_u *)NULL, PV_NONE, 684 #endif 685 {(char_u *)0L, (char_u *)0L}}, 686 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM, 687 #ifdef FEAT_CSCOPE 688 (char_u *)&p_csverbose, PV_NONE, 689 #else 690 (char_u *)NULL, PV_NONE, 691 #endif 692 {(char_u *)0L, (char_u *)0L}}, 693 {"debug", NULL, P_STRING|P_VI_DEF, 694 (char_u *)&p_debug, PV_NONE, 695 {(char_u *)"", (char_u *)0L}}, 696 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF, 697 #ifdef FEAT_FIND_ID 698 (char_u *)&p_def, OPT_BOTH(PV_DEF), 699 {(char_u *)"^\\s#\\s*define", (char_u *)0L} 700 #else 701 (char_u *)NULL, PV_NONE, 702 {(char_u *)NULL, (char_u *)0L} 703 #endif 704 }, 705 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM, 706 #ifdef FEAT_MBYTE 707 (char_u *)&p_deco, PV_NONE, 708 #else 709 (char_u *)NULL, PV_NONE, 710 #endif 711 {(char_u *)FALSE, (char_u *)0L} 712 }, 713 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP, 714 #ifdef FEAT_INS_EXPAND 715 (char_u *)&p_dict, OPT_BOTH(PV_DICT), 716 #else 717 (char_u *)NULL, PV_NONE, 718 #endif 719 {(char_u *)"", (char_u *)0L}}, 720 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB, 721 #ifdef FEAT_DIFF 722 (char_u *)VAR_WIN, PV_DIFF, 723 #else 724 (char_u *)NULL, PV_NONE, 725 #endif 726 {(char_u *)FALSE, (char_u *)0L}}, 727 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE, 728 #if defined(FEAT_DIFF) && defined(FEAT_EVAL) 729 (char_u *)&p_dex, PV_NONE, 730 {(char_u *)"", (char_u *)0L} 731 #else 732 (char_u *)NULL, PV_NONE, 733 {(char_u *)0L, (char_u *)0L} 734 #endif 735 }, 736 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP, 737 #ifdef FEAT_DIFF 738 (char_u *)&p_dip, PV_NONE, 739 {(char_u *)"filler", (char_u *)NULL} 740 #else 741 (char_u *)NULL, PV_NONE, 742 {(char_u *)"", (char_u *)NULL} 743 #endif 744 }, 745 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM, 746 #ifdef FEAT_DIGRAPHS 747 (char_u *)&p_dg, PV_NONE, 748 #else 749 (char_u *)NULL, PV_NONE, 750 #endif 751 {(char_u *)FALSE, (char_u *)0L}}, 752 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE, 753 (char_u *)&p_dir, PV_NONE, 754 {(char_u *)DFLT_DIR, (char_u *)0L}}, 755 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP, 756 (char_u *)&p_dy, PV_NONE, 757 {(char_u *)"", (char_u *)0L}}, 758 {"eadirection", "ead", P_STRING|P_VI_DEF, 759 #ifdef FEAT_VERTSPLIT 760 (char_u *)&p_ead, PV_NONE, 761 {(char_u *)"both", (char_u *)0L} 762 #else 763 (char_u *)NULL, PV_NONE, 764 {(char_u *)NULL, (char_u *)0L} 765 #endif 766 }, 767 {"edcompatible","ed", P_BOOL|P_VI_DEF, 768 (char_u *)&p_ed, PV_NONE, 769 {(char_u *)FALSE, (char_u *)0L}}, 770 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR, 771 #ifdef FEAT_MBYTE 772 (char_u *)&p_enc, PV_NONE, 773 {(char_u *)ENC_DFLT, (char_u *)0L} 774 #else 775 (char_u *)NULL, PV_NONE, 776 {(char_u *)0L, (char_u *)0L} 777 #endif 778 }, 779 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT, 780 (char_u *)&p_eol, PV_EOL, 781 {(char_u *)TRUE, (char_u *)0L}}, 782 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL, 783 (char_u *)&p_ea, PV_NONE, 784 {(char_u *)TRUE, (char_u *)0L}}, 785 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 786 (char_u *)&p_ep, OPT_BOTH(PV_EP), 787 {(char_u *)"", (char_u *)0L}}, 788 {"errorbells", "eb", P_BOOL|P_VI_DEF, 789 (char_u *)&p_eb, PV_NONE, 790 {(char_u *)FALSE, (char_u *)0L}}, 791 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 792 #ifdef FEAT_QUICKFIX 793 (char_u *)&p_ef, PV_NONE, 794 {(char_u *)DFLT_ERRORFILE, (char_u *)0L} 795 #else 796 (char_u *)NULL, PV_NONE, 797 {(char_u *)NULL, (char_u *)0L} 798 #endif 799 }, 800 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 801 #ifdef FEAT_QUICKFIX 802 (char_u *)&p_efm, OPT_BOTH(PV_EFM), 803 {(char_u *)DFLT_EFM, (char_u *)0L}, 804 #else 805 (char_u *)NULL, PV_NONE, 806 {(char_u *)NULL, (char_u *)0L} 807 #endif 808 }, 809 {"esckeys", "ek", P_BOOL|P_VIM, 810 (char_u *)&p_ek, PV_NONE, 811 {(char_u *)FALSE, (char_u *)TRUE}}, 812 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 813 #ifdef FEAT_AUTOCMD 814 (char_u *)&p_ei, PV_NONE, 815 #else 816 (char_u *)NULL, PV_NONE, 817 #endif 818 {(char_u *)"", (char_u *)0L}}, 819 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM, 820 (char_u *)&p_et, PV_ET, 821 {(char_u *)FALSE, (char_u *)0L}}, 822 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE, 823 (char_u *)&p_exrc, PV_NONE, 824 {(char_u *)FALSE, (char_u *)0L}}, 825 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC, 826 #ifdef FEAT_MBYTE 827 (char_u *)&p_fenc, PV_FENC, 828 {(char_u *)"", (char_u *)0L} 829 #else 830 (char_u *)NULL, PV_NONE, 831 {(char_u *)0L, (char_u *)0L} 832 #endif 833 }, 834 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA, 835 #ifdef FEAT_MBYTE 836 (char_u *)&p_fencs, PV_NONE, 837 {(char_u *)"ucs-bom", (char_u *)0L} 838 #else 839 (char_u *)NULL, PV_NONE, 840 {(char_u *)0L, (char_u *)0L} 841 #endif 842 }, 843 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC, 844 (char_u *)&p_ff, PV_FF, 845 {(char_u *)DFLT_FF, (char_u *)0L}}, 846 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP, 847 (char_u *)&p_ffs, PV_NONE, 848 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}}, 849 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB, 850 #ifdef FEAT_AUTOCMD 851 (char_u *)&p_ft, PV_FT, 852 {(char_u *)"", (char_u *)0L} 853 #else 854 (char_u *)NULL, PV_NONE, 855 {(char_u *)0L, (char_u *)0L} 856 #endif 857 }, 858 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP, 859 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING) 860 (char_u *)&p_fcs, PV_NONE, 861 {(char_u *)"vert:|,fold:-", (char_u *)0L} 862 #else 863 (char_u *)NULL, PV_NONE, 864 {(char_u *)"", (char_u *)0L} 865 #endif 866 }, 867 {"fkmap", "fk", P_BOOL|P_VI_DEF, 868 #ifdef FEAT_FKMAP 869 (char_u *)&p_fkmap, PV_NONE, 870 #else 871 (char_u *)NULL, PV_NONE, 872 #endif 873 {(char_u *)FALSE, (char_u *)0L}}, 874 {"flash", "fl", P_BOOL|P_VI_DEF, 875 (char_u *)NULL, PV_NONE, 876 {(char_u *)FALSE, (char_u *)0L}}, 877 #ifdef FEAT_FOLDING 878 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN, 879 (char_u *)&p_fcl, PV_NONE, 880 {(char_u *)"", (char_u *)0L}}, 881 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN, 882 (char_u *)VAR_WIN, PV_FDC, 883 {(char_u *)FALSE, (char_u *)0L}}, 884 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN, 885 (char_u *)VAR_WIN, PV_FEN, 886 {(char_u *)TRUE, (char_u *)0L}}, 887 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN, 888 # ifdef FEAT_EVAL 889 (char_u *)VAR_WIN, PV_FDE, 890 {(char_u *)"0", (char_u *)NULL} 891 # else 892 (char_u *)NULL, PV_NONE, 893 {(char_u *)NULL, (char_u *)0L} 894 # endif 895 }, 896 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN, 897 (char_u *)VAR_WIN, PV_FDI, 898 {(char_u *)"#", (char_u *)NULL}}, 899 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN, 900 (char_u *)VAR_WIN, PV_FDL, 901 {(char_u *)0L, (char_u *)0L}}, 902 {"foldlevelstart","fdls", P_NUM|P_VI_DEF, 903 (char_u *)&p_fdls, PV_NONE, 904 {(char_u *)-1L, (char_u *)0L}}, 905 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF| 906 P_RWIN|P_COMMA|P_NODUP, 907 (char_u *)VAR_WIN, PV_FMR, 908 {(char_u *)"{{{,}}}", (char_u *)NULL}}, 909 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN, 910 (char_u *)VAR_WIN, PV_FDM, 911 {(char_u *)"manual", (char_u *)NULL}}, 912 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN, 913 (char_u *)VAR_WIN, PV_FML, 914 {(char_u *)1L, (char_u *)0L}}, 915 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN, 916 (char_u *)VAR_WIN, PV_FDN, 917 {(char_u *)20L, (char_u *)0L}}, 918 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 919 (char_u *)&p_fdo, PV_NONE, 920 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo", 921 (char_u *)0L}}, 922 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN, 923 # ifdef FEAT_EVAL 924 (char_u *)VAR_WIN, PV_FDT, 925 {(char_u *)"foldtext()", (char_u *)NULL} 926 #else 927 (char_u *)NULL, PV_NONE, 928 {(char_u *)NULL, (char_u *)0L} 929 #endif 930 }, 931 #endif 932 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST, 933 (char_u *)&p_fo, PV_FO, 934 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}}, 935 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 936 (char_u *)&p_fp, PV_NONE, 937 {(char_u *)"", (char_u *)0L}}, 938 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM, 939 (char_u *)&p_gd, PV_NONE, 940 {(char_u *)FALSE, (char_u *)0L}}, 941 {"graphic", "gr", P_BOOL|P_VI_DEF, 942 (char_u *)NULL, PV_NONE, 943 {(char_u *)FALSE, (char_u *)0L}}, 944 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 945 #ifdef FEAT_QUICKFIX 946 (char_u *)&p_gefm, PV_NONE, 947 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}, 948 #else 949 (char_u *)NULL, PV_NONE, 950 {(char_u *)NULL, (char_u *)0L} 951 #endif 952 }, 953 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 954 #ifdef FEAT_QUICKFIX 955 (char_u *)&p_gp, OPT_BOTH(PV_GP), 956 { 957 # ifdef WIN3264 958 /* may be changed to "grep -n" in os_win32.c */ 959 (char_u *)"findstr /n", 960 # else 961 # ifdef UNIX 962 /* Add an extra file name so that grep will always 963 * insert a file name in the match line. */ 964 (char_u *)"grep -n $* /dev/null", 965 # else 966 # ifdef VMS 967 (char_u *)"SEARCH/NUMBERS ", 968 # else 969 (char_u *)"grep -n ", 970 #endif 971 #endif 972 # endif 973 (char_u *)0L}, 974 #else 975 (char_u *)NULL, PV_NONE, 976 {(char_u *)NULL, (char_u *)0L} 977 #endif 978 }, 979 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 980 #ifdef CURSOR_SHAPE 981 (char_u *)&p_guicursor, PV_NONE, 982 { 983 # ifdef FEAT_GUI 984 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175", 985 # else /* MSDOS or Win32 console */ 986 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block", 987 # endif 988 (char_u *)0L} 989 #else 990 (char_u *)NULL, PV_NONE, 991 {(char_u *)NULL, (char_u *)0L} 992 #endif 993 }, 994 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP, 995 #ifdef FEAT_GUI 996 (char_u *)&p_guifont, PV_NONE, 997 {(char_u *)"", (char_u *)0L} 998 #else 999 (char_u *)NULL, PV_NONE, 1000 {(char_u *)NULL, (char_u *)0L} 1001 #endif 1002 }, 1003 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA, 1004 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET) 1005 (char_u *)&p_guifontset, PV_NONE, 1006 {(char_u *)"", (char_u *)0L} 1007 #else 1008 (char_u *)NULL, PV_NONE, 1009 {(char_u *)NULL, (char_u *)0L} 1010 #endif 1011 }, 1012 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP, 1013 #if defined(FEAT_GUI) && defined(FEAT_MBYTE) 1014 (char_u *)&p_guifontwide, PV_NONE, 1015 {(char_u *)"", (char_u *)0L} 1016 #else 1017 (char_u *)NULL, PV_NONE, 1018 {(char_u *)NULL, (char_u *)0L} 1019 #endif 1020 }, 1021 {"guiheadroom", "ghr", P_NUM|P_VI_DEF, 1022 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) 1023 (char_u *)&p_ghr, PV_NONE, 1024 #else 1025 (char_u *)NULL, PV_NONE, 1026 #endif 1027 {(char_u *)50L, (char_u *)0L}}, 1028 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST, 1029 #if defined(FEAT_GUI) 1030 (char_u *)&p_go, PV_NONE, 1031 # if defined(UNIX) && !defined(MACOS) 1032 {(char_u *)"agimrLtT", (char_u *)0L} 1033 # else 1034 {(char_u *)"gmrLtT", (char_u *)0L} 1035 # endif 1036 #else 1037 (char_u *)NULL, PV_NONE, 1038 {(char_u *)NULL, (char_u *)0L} 1039 #endif 1040 }, 1041 {"guipty", NULL, P_BOOL|P_VI_DEF, 1042 #if defined(FEAT_GUI) 1043 (char_u *)&p_guipty, PV_NONE, 1044 #else 1045 (char_u *)NULL, PV_NONE, 1046 #endif 1047 {(char_u *)TRUE, (char_u *)0L}}, 1048 {"hardtabs", "ht", P_NUM|P_VI_DEF, 1049 (char_u *)NULL, PV_NONE, 1050 {(char_u *)0L, (char_u *)0L}}, 1051 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1052 (char_u *)&p_hf, PV_NONE, 1053 {(char_u *)DFLT_HELPFILE, (char_u *)0L}}, 1054 {"helpheight", "hh", P_NUM|P_VI_DEF, 1055 #ifdef FEAT_WINDOWS 1056 (char_u *)&p_hh, PV_NONE, 1057 #else 1058 (char_u *)NULL, PV_NONE, 1059 #endif 1060 {(char_u *)20L, (char_u *)0L}}, 1061 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA, 1062 #ifdef FEAT_MULTI_LANG 1063 (char_u *)&p_hlg, PV_NONE, 1064 {(char_u *)"", (char_u *)0L} 1065 #else 1066 (char_u *)NULL, PV_NONE, 1067 {(char_u *)0L, (char_u *)0L} 1068 #endif 1069 }, 1070 {"hidden", "hid", P_BOOL|P_VI_DEF, 1071 (char_u *)&p_hid, PV_NONE, 1072 {(char_u *)FALSE, (char_u *)0L}}, 1073 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP, 1074 (char_u *)&p_hl, PV_NONE, 1075 {(char_u *)"8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn", 1076 (char_u *)0L}}, 1077 {"history", "hi", P_NUM|P_VIM, 1078 (char_u *)&p_hi, PV_NONE, 1079 {(char_u *)0L, (char_u *)20L}}, 1080 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM, 1081 #ifdef FEAT_RIGHTLEFT 1082 (char_u *)&p_hkmap, PV_NONE, 1083 #else 1084 (char_u *)NULL, PV_NONE, 1085 #endif 1086 {(char_u *)FALSE, (char_u *)0L}}, 1087 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM, 1088 #ifdef FEAT_RIGHTLEFT 1089 (char_u *)&p_hkmapp, PV_NONE, 1090 #else 1091 (char_u *)NULL, PV_NONE, 1092 #endif 1093 {(char_u *)FALSE, (char_u *)0L}}, 1094 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL, 1095 (char_u *)&p_hls, PV_NONE, 1096 {(char_u *)FALSE, (char_u *)0L}}, 1097 {"icon", NULL, P_BOOL|P_VI_DEF, 1098 #ifdef FEAT_TITLE 1099 (char_u *)&p_icon, PV_NONE, 1100 #else 1101 (char_u *)NULL, PV_NONE, 1102 #endif 1103 {(char_u *)FALSE, (char_u *)0L}}, 1104 {"iconstring", NULL, P_STRING|P_VI_DEF, 1105 #ifdef FEAT_TITLE 1106 (char_u *)&p_iconstring, PV_NONE, 1107 #else 1108 (char_u *)NULL, PV_NONE, 1109 #endif 1110 {(char_u *)"", (char_u *)0L}}, 1111 {"ignorecase", "ic", P_BOOL|P_VI_DEF, 1112 (char_u *)&p_ic, PV_NONE, 1113 {(char_u *)FALSE, (char_u *)0L}}, 1114 {"imactivatekey","imak",P_STRING|P_VI_DEF, 1115 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) 1116 (char_u *)&p_imak, PV_NONE, 1117 #else 1118 (char_u *)NULL, PV_NONE, 1119 #endif 1120 {(char_u *)"", (char_u *)0L}}, 1121 {"imcmdline", "imc", P_BOOL|P_VI_DEF, 1122 #ifdef USE_IM_CONTROL 1123 (char_u *)&p_imcmdline, PV_NONE, 1124 #else 1125 (char_u *)NULL, PV_NONE, 1126 #endif 1127 {(char_u *)FALSE, (char_u *)0L}}, 1128 {"imdisable", "imd", P_BOOL|P_VI_DEF, 1129 #ifdef USE_IM_CONTROL 1130 (char_u *)&p_imdisable, PV_NONE, 1131 #else 1132 (char_u *)NULL, PV_NONE, 1133 #endif 1134 #ifdef __sgi 1135 {(char_u *)TRUE, (char_u *)0L} 1136 #else 1137 {(char_u *)FALSE, (char_u *)0L} 1138 #endif 1139 }, 1140 {"iminsert", "imi", P_NUM|P_VI_DEF, 1141 (char_u *)&p_iminsert, PV_IMI, 1142 #ifdef B_IMODE_IM 1143 {(char_u *)B_IMODE_IM, (char_u *)0L} 1144 #else 1145 {(char_u *)B_IMODE_NONE, (char_u *)0L} 1146 #endif 1147 }, 1148 {"imsearch", "ims", P_NUM|P_VI_DEF, 1149 (char_u *)&p_imsearch, PV_IMS, 1150 #ifdef B_IMODE_IM 1151 {(char_u *)B_IMODE_IM, (char_u *)0L} 1152 #else 1153 {(char_u *)B_IMODE_NONE, (char_u *)0L} 1154 #endif 1155 }, 1156 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF, 1157 #ifdef FEAT_FIND_ID 1158 (char_u *)&p_inc, OPT_BOTH(PV_INC), 1159 {(char_u *)"^\\s*#\\s*include", (char_u *)0L} 1160 #else 1161 (char_u *)NULL, PV_NONE, 1162 {(char_u *)0L, (char_u *)0L} 1163 #endif 1164 }, 1165 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF, 1166 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) 1167 (char_u *)&p_inex, PV_INEX, 1168 {(char_u *)"", (char_u *)0L} 1169 #else 1170 (char_u *)NULL, PV_NONE, 1171 {(char_u *)0L, (char_u *)0L} 1172 #endif 1173 }, 1174 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM, 1175 (char_u *)&p_is, PV_NONE, 1176 {(char_u *)FALSE, (char_u *)0L}}, 1177 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM, 1178 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 1179 (char_u *)&p_inde, PV_INDE, 1180 {(char_u *)"", (char_u *)0L} 1181 #else 1182 (char_u *)NULL, PV_NONE, 1183 {(char_u *)0L, (char_u *)0L} 1184 #endif 1185 }, 1186 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 1187 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 1188 (char_u *)&p_indk, PV_INDK, 1189 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L} 1190 #else 1191 (char_u *)NULL, PV_NONE, 1192 {(char_u *)0L, (char_u *)0L} 1193 #endif 1194 }, 1195 {"infercase", "inf", P_BOOL|P_VI_DEF, 1196 (char_u *)&p_inf, PV_INF, 1197 {(char_u *)FALSE, (char_u *)0L}}, 1198 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM, 1199 (char_u *)&p_im, PV_NONE, 1200 {(char_u *)FALSE, (char_u *)0L}}, 1201 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1202 (char_u *)&p_isf, PV_NONE, 1203 { 1204 #ifdef BACKSLASH_IN_FILENAME 1205 /* Excluded are: & and ^ are special in cmd.exe 1206 * ( and ) are used in text separating fnames */ 1207 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=", 1208 #else 1209 # ifdef AMIGA 1210 (char_u *)"@,48-57,/,.,-,_,+,,,$,:", 1211 # else 1212 # ifdef VMS 1213 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~", 1214 # else /* UNIX et al. */ 1215 # ifdef EBCDIC 1216 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=", 1217 # else 1218 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=", 1219 # endif 1220 # endif 1221 # endif 1222 #endif 1223 (char_u *)0L}}, 1224 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1225 (char_u *)&p_isi, PV_NONE, 1226 { 1227 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) 1228 (char_u *)"@,48-57,_,128-167,224-235", 1229 #else 1230 # ifdef EBCDIC 1231 /* TODO: EBCDIC Check this! @ == isalpha()*/ 1232 (char_u *)"@,240-249,_,66-73,81-89,98-105," 1233 "112-120,128,140-142,156,158,172," 1234 "174,186,191,203-207,219-225,235-239," 1235 "251-254", 1236 # else 1237 (char_u *)"@,48-57,_,192-255", 1238 # endif 1239 #endif 1240 (char_u *)0L}}, 1241 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP, 1242 (char_u *)&p_isk, PV_ISK, 1243 { 1244 #ifdef EBCDIC 1245 (char_u *)"@,240-249,_", 1246 /* TODO: EBCDIC Check this! @ == isalpha()*/ 1247 (char_u *)"@,240-249,_,66-73,81-89,98-105," 1248 "112-120,128,140-142,156,158,172," 1249 "174,186,191,203-207,219-225,235-239," 1250 "251-254", 1251 #else 1252 (char_u *)"@,48-57,_", 1253 # if defined(MSDOS) || defined(MSWIN) || defined(OS2) 1254 (char_u *)"@,48-57,_,128-167,224-235" 1255 # else 1256 (char_u *)"@,48-57,_,192-255" 1257 # endif 1258 #endif 1259 }}, 1260 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP, 1261 (char_u *)&p_isp, PV_NONE, 1262 { 1263 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \ 1264 || defined(VMS) 1265 (char_u *)"@,~-255", 1266 #else 1267 # ifdef EBCDIC 1268 /* all chars above 63 are printable */ 1269 (char_u *)"63-255", 1270 # else 1271 (char_u *)"@,161-255", 1272 # endif 1273 #endif 1274 (char_u *)0L}}, 1275 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM, 1276 (char_u *)&p_js, PV_NONE, 1277 {(char_u *)TRUE, (char_u *)0L}}, 1278 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC, 1279 #ifdef FEAT_CRYPT 1280 (char_u *)&p_key, PV_KEY, 1281 {(char_u *)"", (char_u *)0L} 1282 #else 1283 (char_u *)NULL, PV_NONE, 1284 {(char_u *)0L, (char_u *)0L} 1285 #endif 1286 }, 1287 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT, 1288 #ifdef FEAT_KEYMAP 1289 (char_u *)&p_keymap, PV_KMAP, 1290 {(char_u *)"", (char_u *)0L} 1291 #else 1292 (char_u *)NULL, PV_NONE, 1293 {(char_u *)"", (char_u *)0L} 1294 #endif 1295 }, 1296 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1297 #ifdef FEAT_VISUAL 1298 (char_u *)&p_km, PV_NONE, 1299 #else 1300 (char_u *)NULL, PV_NONE, 1301 #endif 1302 {(char_u *)"", (char_u *)0L}}, 1303 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1304 (char_u *)&p_kp, OPT_BOTH(PV_KP), 1305 { 1306 #if defined(MSDOS) || defined(MSWIN) 1307 (char_u *)":help", 1308 #else 1309 #ifdef VMS 1310 (char_u *)"help", 1311 #else 1312 # if defined(OS2) 1313 (char_u *)"view /", 1314 # else 1315 # ifdef USEMAN_S 1316 (char_u *)"man -s", 1317 # else 1318 (char_u *)"man", 1319 # endif 1320 # endif 1321 #endif 1322 #endif 1323 (char_u *)0L}}, 1324 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1325 #ifdef FEAT_LANGMAP 1326 (char_u *)&p_langmap, PV_NONE, 1327 {(char_u *)"", /* unmatched } */ 1328 #else 1329 (char_u *)NULL, PV_NONE, 1330 {(char_u *)NULL, 1331 #endif 1332 (char_u *)0L}}, 1333 {"langmenu", "lm", P_STRING|P_VI_DEF, 1334 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG) 1335 (char_u *)&p_lm, PV_NONE, 1336 #else 1337 (char_u *)NULL, PV_NONE, 1338 #endif 1339 {(char_u *)"", (char_u *)0L}}, 1340 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL, 1341 #ifdef FEAT_WINDOWS 1342 (char_u *)&p_ls, PV_NONE, 1343 #else 1344 (char_u *)NULL, PV_NONE, 1345 #endif 1346 {(char_u *)1L, (char_u *)0L}}, 1347 {"lazyredraw", "lz", P_BOOL|P_VI_DEF, 1348 (char_u *)&p_lz, PV_NONE, 1349 {(char_u *)FALSE, (char_u *)0L}}, 1350 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN, 1351 #ifdef FEAT_LINEBREAK 1352 (char_u *)VAR_WIN, PV_LBR, 1353 #else 1354 (char_u *)NULL, PV_NONE, 1355 #endif 1356 {(char_u *)FALSE, (char_u *)0L}}, 1357 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR, 1358 (char_u *)&Rows, PV_NONE, 1359 { 1360 #if defined(MSDOS) || defined(WIN3264) || defined(OS2) 1361 (char_u *)25L, 1362 #else 1363 (char_u *)24L, 1364 #endif 1365 (char_u *)0L}}, 1366 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR, 1367 #ifdef FEAT_GUI 1368 (char_u *)&p_linespace, PV_NONE, 1369 #else 1370 (char_u *)NULL, PV_NONE, 1371 #endif 1372 #ifdef FEAT_GUI_W32 1373 {(char_u *)1L, (char_u *)0L} 1374 #else 1375 {(char_u *)0L, (char_u *)0L} 1376 #endif 1377 }, 1378 {"lisp", NULL, P_BOOL|P_VI_DEF, 1379 #ifdef FEAT_LISP 1380 (char_u *)&p_lisp, PV_LISP, 1381 #else 1382 (char_u *)NULL, PV_NONE, 1383 #endif 1384 {(char_u *)FALSE, (char_u *)0L}}, 1385 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1386 #ifdef FEAT_LISP 1387 (char_u *)&p_lispwords, PV_NONE, 1388 {(char_u *)LISPWORD_VALUE, (char_u *)0L} 1389 #else 1390 (char_u *)NULL, PV_NONE, 1391 {(char_u *)"", (char_u *)0L} 1392 #endif 1393 }, 1394 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN, 1395 (char_u *)VAR_WIN, PV_LIST, 1396 {(char_u *)FALSE, (char_u *)0L}}, 1397 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP, 1398 (char_u *)&p_lcs, PV_NONE, 1399 {(char_u *)"eol:$", (char_u *)0L}}, 1400 {"loadplugins", "lpl", P_BOOL|P_VI_DEF, 1401 (char_u *)&p_lpl, PV_NONE, 1402 {(char_u *)TRUE, (char_u *)0L}}, 1403 {"magic", NULL, P_BOOL|P_VI_DEF, 1404 (char_u *)&p_magic, PV_NONE, 1405 {(char_u *)TRUE, (char_u *)0L}}, 1406 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1407 #ifdef FEAT_QUICKFIX 1408 (char_u *)&p_mef, PV_NONE, 1409 {(char_u *)"", (char_u *)0L} 1410 #else 1411 (char_u *)NULL, PV_NONE, 1412 {(char_u *)NULL, (char_u *)0L} 1413 #endif 1414 }, 1415 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1416 #ifdef FEAT_QUICKFIX 1417 (char_u *)&p_mp, OPT_BOTH(PV_MP), 1418 # ifdef VMS 1419 {(char_u *)"MMS", (char_u *)0L} 1420 # else 1421 {(char_u *)"make", (char_u *)0L} 1422 # endif 1423 #else 1424 (char_u *)NULL, PV_NONE, 1425 {(char_u *)NULL, (char_u *)0L} 1426 #endif 1427 }, 1428 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 1429 (char_u *)&p_mps, PV_MPS, 1430 {(char_u *)"(:),{:},[:]", (char_u *)0L}}, 1431 {"matchtime", "mat", P_NUM|P_VI_DEF, 1432 (char_u *)&p_mat, PV_NONE, 1433 {(char_u *)5L, (char_u *)0L}}, 1434 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF, 1435 #ifdef FEAT_EVAL 1436 (char_u *)&p_mfd, PV_NONE, 1437 #else 1438 (char_u *)NULL, PV_NONE, 1439 #endif 1440 {(char_u *)100L, (char_u *)0L}}, 1441 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF, 1442 (char_u *)&p_mmd, PV_NONE, 1443 {(char_u *)1000L, (char_u *)0L}}, 1444 {"maxmem", "mm", P_NUM|P_VI_DEF, 1445 (char_u *)&p_mm, PV_NONE, 1446 {(char_u *)DFLT_MAXMEM, (char_u *)0L}}, 1447 {"maxmemtot", "mmt", P_NUM|P_VI_DEF, 1448 (char_u *)&p_mmt, PV_NONE, 1449 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}}, 1450 {"menuitems", "mis", P_NUM|P_VI_DEF, 1451 #ifdef FEAT_MENU 1452 (char_u *)&p_mis, PV_NONE, 1453 #else 1454 (char_u *)NULL, PV_NONE, 1455 #endif 1456 {(char_u *)25L, (char_u *)0L}}, 1457 {"mesg", NULL, P_BOOL|P_VI_DEF, 1458 (char_u *)NULL, PV_NONE, 1459 {(char_u *)FALSE, (char_u *)0L}}, 1460 {"modeline", "ml", P_BOOL|P_VIM, 1461 (char_u *)&p_ml, PV_ML, 1462 {(char_u *)FALSE, (char_u *)TRUE}}, 1463 {"modelines", "mls", P_NUM|P_VI_DEF, 1464 (char_u *)&p_mls, PV_NONE, 1465 {(char_u *)5L, (char_u *)0L}}, 1466 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB, 1467 (char_u *)&p_ma, PV_MA, 1468 {(char_u *)TRUE, (char_u *)0L}}, 1469 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT, 1470 (char_u *)&p_mod, PV_MOD, 1471 {(char_u *)FALSE, (char_u *)0L}}, 1472 {"more", NULL, P_BOOL|P_VIM, 1473 (char_u *)&p_more, PV_NONE, 1474 {(char_u *)FALSE, (char_u *)TRUE}}, 1475 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST, 1476 (char_u *)&p_mouse, PV_NONE, 1477 { 1478 #if defined(MSDOS) || defined(WIN3264) 1479 (char_u *)"a", 1480 #else 1481 (char_u *)"", 1482 #endif 1483 (char_u *)0L}}, 1484 {"mousefocus", "mousef", P_BOOL|P_VI_DEF, 1485 #ifdef FEAT_GUI 1486 (char_u *)&p_mousef, PV_NONE, 1487 #else 1488 (char_u *)NULL, PV_NONE, 1489 #endif 1490 {(char_u *)FALSE, (char_u *)0L}}, 1491 {"mousehide", "mh", P_BOOL|P_VI_DEF, 1492 #ifdef FEAT_GUI 1493 (char_u *)&p_mh, PV_NONE, 1494 #else 1495 (char_u *)NULL, PV_NONE, 1496 #endif 1497 {(char_u *)TRUE, (char_u *)0L}}, 1498 {"mousemodel", "mousem", P_STRING|P_VI_DEF, 1499 (char_u *)&p_mousem, PV_NONE, 1500 { 1501 #if defined(MSDOS) || defined(MSWIN) 1502 (char_u *)"popup", 1503 #else 1504 # if defined(MACOS) 1505 (char_u *)"popup_setpos", 1506 # else 1507 (char_u *)"extend", 1508 # endif 1509 #endif 1510 (char_u *)0L}}, 1511 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1512 #ifdef FEAT_MOUSESHAPE 1513 (char_u *)&p_mouseshape, PV_NONE, 1514 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L} 1515 #else 1516 (char_u *)NULL, PV_NONE, 1517 {(char_u *)NULL, (char_u *)0L} 1518 #endif 1519 }, 1520 {"mousetime", "mouset", P_NUM|P_VI_DEF, 1521 (char_u *)&p_mouset, PV_NONE, 1522 {(char_u *)500L, (char_u *)0L}}, 1523 {"novice", NULL, P_BOOL|P_VI_DEF, 1524 (char_u *)NULL, PV_NONE, 1525 {(char_u *)FALSE, (char_u *)0L}}, 1526 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 1527 (char_u *)&p_nf, PV_NF, 1528 {(char_u *)"octal,hex", (char_u *)0L}}, 1529 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN, 1530 (char_u *)VAR_WIN, PV_NU, 1531 {(char_u *)FALSE, (char_u *)0L}}, 1532 {"open", NULL, P_BOOL|P_VI_DEF, 1533 (char_u *)NULL, PV_NONE, 1534 {(char_u *)FALSE, (char_u *)0L}}, 1535 {"optimize", "opt", P_BOOL|P_VI_DEF, 1536 (char_u *)NULL, PV_NONE, 1537 {(char_u *)FALSE, (char_u *)0L}}, 1538 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF, 1539 #ifdef FEAT_OSFILETYPE 1540 (char_u *)&p_oft, PV_OFT, 1541 {(char_u *)DFLT_OFT, (char_u *)0L} 1542 #else 1543 (char_u *)NULL, PV_NONE, 1544 {(char_u *)0L, (char_u *)0L} 1545 #endif 1546 }, 1547 {"paragraphs", "para", P_STRING|P_VI_DEF, 1548 (char_u *)&p_para, PV_NONE, 1549 {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}}, 1550 {"paste", NULL, P_BOOL|P_VI_DEF, 1551 (char_u *)&p_paste, PV_NONE, 1552 {(char_u *)FALSE, (char_u *)0L}}, 1553 {"pastetoggle", "pt", P_STRING|P_VI_DEF, 1554 (char_u *)&p_pt, PV_NONE, 1555 {(char_u *)"", (char_u *)0L}}, 1556 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE, 1557 #if defined(FEAT_DIFF) && defined(FEAT_EVAL) 1558 (char_u *)&p_pex, PV_NONE, 1559 {(char_u *)"", (char_u *)0L} 1560 #else 1561 (char_u *)NULL, PV_NONE, 1562 {(char_u *)0L, (char_u *)0L} 1563 #endif 1564 }, 1565 {"patchmode", "pm", P_STRING|P_VI_DEF, 1566 (char_u *)&p_pm, PV_NONE, 1567 {(char_u *)"", (char_u *)0L}}, 1568 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP, 1569 (char_u *)&p_path, OPT_BOTH(PV_PATH), 1570 { 1571 #if defined AMIGA || defined MSDOS || defined MSWIN 1572 (char_u *)".,,", 1573 #else 1574 # if defined(__EMX__) 1575 (char_u *)".,/emx/include,,", 1576 # else /* Unix, probably */ 1577 (char_u *)".,/usr/include,,", 1578 # endif 1579 #endif 1580 (char_u *)0L}}, 1581 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM, 1582 (char_u *)&p_pi, PV_PI, 1583 {(char_u *)FALSE, (char_u *)0L}}, 1584 {"previewheight", "pvh",P_NUM|P_VI_DEF, 1585 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) 1586 (char_u *)&p_pvh, PV_NONE, 1587 #else 1588 (char_u *)NULL, PV_NONE, 1589 #endif 1590 {(char_u *)12L, (char_u *)0L}}, 1591 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB, 1592 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) 1593 (char_u *)VAR_WIN, PV_PVW, 1594 #else 1595 (char_u *)NULL, PV_NONE, 1596 #endif 1597 {(char_u *)FALSE, (char_u *)0L}}, 1598 {"printdevice", "pdev", P_STRING|P_VI_DEF, 1599 #ifdef FEAT_PRINTER 1600 (char_u *)&p_pdev, PV_NONE, 1601 {(char_u *)"", (char_u *)0L} 1602 #else 1603 (char_u *)NULL, PV_NONE, 1604 {(char_u *)NULL, (char_u *)0L} 1605 #endif 1606 }, 1607 {"printencoding", "penc", P_STRING|P_VI_DEF, 1608 #ifdef FEAT_POSTSCRIPT 1609 (char_u *)&p_penc, PV_NONE, 1610 {(char_u *)"", (char_u *)0L} 1611 #else 1612 (char_u *)NULL, PV_NONE, 1613 {(char_u *)NULL, (char_u *)0L} 1614 #endif 1615 }, 1616 {"printexpr", "pexpr", P_STRING|P_VI_DEF, 1617 #ifdef FEAT_POSTSCRIPT 1618 (char_u *)&p_pexpr, PV_NONE, 1619 {(char_u *)"", (char_u *)0L} 1620 #else 1621 (char_u *)NULL, PV_NONE, 1622 {(char_u *)NULL, (char_u *)0L} 1623 #endif 1624 }, 1625 {"printfont", "pfn", P_STRING|P_VI_DEF, 1626 #ifdef FEAT_PRINTER 1627 (char_u *)&p_pfn, PV_NONE, 1628 { 1629 # ifdef MSWIN 1630 (char_u *)"Courier_New:h10", 1631 # else 1632 (char_u *)"courier", 1633 # endif 1634 (char_u *)0L} 1635 #else 1636 (char_u *)NULL, PV_NONE, 1637 {(char_u *)NULL, (char_u *)0L} 1638 #endif 1639 }, 1640 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT, 1641 #ifdef FEAT_PRINTER 1642 (char_u *)&p_header, PV_NONE, 1643 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L} 1644 #else 1645 (char_u *)NULL, PV_NONE, 1646 {(char_u *)NULL, (char_u *)0L} 1647 #endif 1648 }, 1649 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1650 #ifdef FEAT_PRINTER 1651 (char_u *)&p_popt, PV_NONE, 1652 {(char_u *)"", (char_u *)0L} 1653 #else 1654 (char_u *)NULL, PV_NONE, 1655 {(char_u *)NULL, (char_u *)0L} 1656 #endif 1657 }, 1658 {"prompt", NULL, P_BOOL|P_VI_DEF, 1659 (char_u *)NULL, PV_NONE, 1660 {(char_u *)FALSE, (char_u *)0L}}, 1661 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB, 1662 (char_u *)&p_ro, PV_RO, 1663 {(char_u *)FALSE, (char_u *)0L}}, 1664 {"redraw", NULL, P_BOOL|P_VI_DEF, 1665 (char_u *)NULL, PV_NONE, 1666 {(char_u *)FALSE, (char_u *)0L}}, 1667 {"remap", NULL, P_BOOL|P_VI_DEF, 1668 (char_u *)&p_remap, PV_NONE, 1669 {(char_u *)TRUE, (char_u *)0L}}, 1670 {"report", NULL, P_NUM|P_VI_DEF, 1671 (char_u *)&p_report, PV_NONE, 1672 {(char_u *)2L, (char_u *)0L}}, 1673 {"restorescreen", "rs", P_BOOL|P_VI_DEF, 1674 #ifdef WIN3264 1675 (char_u *)&p_rs, PV_NONE, 1676 #else 1677 (char_u *)NULL, PV_NONE, 1678 #endif 1679 {(char_u *)TRUE, (char_u *)0L}}, 1680 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM, 1681 #ifdef FEAT_RIGHTLEFT 1682 (char_u *)&p_ri, PV_NONE, 1683 #else 1684 (char_u *)NULL, PV_NONE, 1685 #endif 1686 {(char_u *)FALSE, (char_u *)0L}}, 1687 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN, 1688 #ifdef FEAT_RIGHTLEFT 1689 (char_u *)VAR_WIN, PV_RL, 1690 #else 1691 (char_u *)NULL, PV_NONE, 1692 #endif 1693 {(char_u *)FALSE, (char_u *)0L}}, 1694 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN, 1695 #ifdef FEAT_RIGHTLEFT 1696 (char_u *)VAR_WIN, PV_RLC, 1697 {(char_u *)"search", (char_u *)NULL} 1698 #else 1699 (char_u *)NULL, PV_NONE, 1700 {(char_u *)NULL, (char_u *)0L} 1701 #endif 1702 }, 1703 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT, 1704 #ifdef FEAT_CMDL_INFO 1705 (char_u *)&p_ru, PV_NONE, 1706 #else 1707 (char_u *)NULL, PV_NONE, 1708 #endif 1709 {(char_u *)FALSE, (char_u *)0L}}, 1710 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT, 1711 #ifdef FEAT_STL_OPT 1712 (char_u *)&p_ruf, PV_NONE, 1713 #else 1714 (char_u *)NULL, PV_NONE, 1715 #endif 1716 {(char_u *)"", (char_u *)0L}}, 1717 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE, 1718 (char_u *)&p_rtp, PV_NONE, 1719 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}}, 1720 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF, 1721 (char_u *)VAR_WIN, PV_SCROLL, 1722 {(char_u *)12L, (char_u *)0L}}, 1723 {"scrollbind", "scb", P_BOOL|P_VI_DEF, 1724 #ifdef FEAT_SCROLLBIND 1725 (char_u *)VAR_WIN, PV_SCBIND, 1726 #else 1727 (char_u *)NULL, PV_NONE, 1728 #endif 1729 {(char_u *)FALSE, (char_u *)0L}}, 1730 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM, 1731 (char_u *)&p_sj, PV_NONE, 1732 {(char_u *)1L, (char_u *)0L}}, 1733 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL, 1734 (char_u *)&p_so, PV_NONE, 1735 {(char_u *)0L, (char_u *)0L}}, 1736 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1737 #ifdef FEAT_SCROLLBIND 1738 (char_u *)&p_sbo, PV_NONE, 1739 {(char_u *)"ver,jump", (char_u *)0L} 1740 #else 1741 (char_u *)NULL, PV_NONE, 1742 {(char_u *)0L, (char_u *)0L} 1743 #endif 1744 }, 1745 {"sections", "sect", P_STRING|P_VI_DEF, 1746 (char_u *)&p_sections, PV_NONE, 1747 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}}, 1748 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE, 1749 (char_u *)&p_secure, PV_NONE, 1750 {(char_u *)FALSE, (char_u *)0L}}, 1751 {"selection", "sel", P_STRING|P_VI_DEF, 1752 #ifdef FEAT_VISUAL 1753 (char_u *)&p_sel, PV_NONE, 1754 #else 1755 (char_u *)NULL, PV_NONE, 1756 #endif 1757 {(char_u *)"inclusive", (char_u *)0L}}, 1758 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1759 #ifdef FEAT_VISUAL 1760 (char_u *)&p_slm, PV_NONE, 1761 #else 1762 (char_u *)NULL, PV_NONE, 1763 #endif 1764 {(char_u *)"", (char_u *)0L}}, 1765 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1766 #ifdef FEAT_SESSION 1767 (char_u *)&p_ssop, PV_NONE, 1768 {(char_u *)"blank,buffers,curdir,folds,help,options,winsize", 1769 (char_u *)0L} 1770 #else 1771 (char_u *)NULL, PV_NONE, 1772 {(char_u *)0L, (char_u *)0L} 1773 #endif 1774 }, 1775 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1776 (char_u *)&p_sh, PV_NONE, 1777 { 1778 #ifdef VMS 1779 (char_u *)"-", 1780 #else 1781 # if defined(MSDOS) 1782 (char_u *)"command", 1783 # else 1784 # if defined(WIN16) 1785 (char_u *)"command.com", 1786 # else 1787 # if defined(WIN3264) 1788 (char_u *)"", /* set in set_init_1() */ 1789 # else 1790 # if defined(OS2) 1791 (char_u *)"cmd.exe", 1792 # else 1793 # if defined(ARCHIE) 1794 (char_u *)"gos", 1795 # else 1796 (char_u *)"sh", 1797 # endif 1798 # endif 1799 # endif 1800 # endif 1801 # endif 1802 #endif /* VMS */ 1803 (char_u *)0L}}, 1804 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE, 1805 (char_u *)&p_shcf, PV_NONE, 1806 { 1807 #if defined(MSDOS) || defined(MSWIN) 1808 (char_u *)"/c", 1809 #else 1810 # if defined(OS2) 1811 (char_u *)"/c", 1812 # else 1813 (char_u *)"-c", 1814 # endif 1815 #endif 1816 (char_u *)0L}}, 1817 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE, 1818 #ifdef FEAT_QUICKFIX 1819 (char_u *)&p_sp, PV_NONE, 1820 { 1821 #if defined(UNIX) || defined(OS2) 1822 # ifdef ARCHIE 1823 (char_u *)"2>", 1824 # else 1825 (char_u *)"| tee", 1826 # endif 1827 #else 1828 (char_u *)">", 1829 #endif 1830 (char_u *)0L} 1831 #else 1832 (char_u *)NULL, PV_NONE, 1833 {(char_u *)0L, (char_u *)0L} 1834 #endif 1835 }, 1836 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE, 1837 (char_u *)&p_shq, PV_NONE, 1838 {(char_u *)"", (char_u *)0L}}, 1839 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE, 1840 (char_u *)&p_srr, PV_NONE, 1841 {(char_u *)">", (char_u *)0L}}, 1842 {"shellslash", "ssl", P_BOOL|P_VI_DEF, 1843 #ifdef BACKSLASH_IN_FILENAME 1844 (char_u *)&p_ssl, PV_NONE, 1845 #else 1846 (char_u *)NULL, PV_NONE, 1847 #endif 1848 {(char_u *)FALSE, (char_u *)0L}}, 1849 {"shelltype", "st", P_NUM|P_VI_DEF, 1850 #ifdef AMIGA 1851 (char_u *)&p_st, PV_NONE, 1852 #else 1853 (char_u *)NULL, PV_NONE, 1854 #endif 1855 {(char_u *)0L, (char_u *)0L}}, 1856 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE, 1857 (char_u *)&p_sxq, PV_NONE, 1858 { 1859 #if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__) 1860 (char_u *)"\"", 1861 #else 1862 (char_u *)"", 1863 #endif 1864 (char_u *)0L}}, 1865 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM, 1866 (char_u *)&p_sr, PV_NONE, 1867 {(char_u *)FALSE, (char_u *)0L}}, 1868 {"shiftwidth", "sw", P_NUM|P_VI_DEF, 1869 (char_u *)&p_sw, PV_SW, 1870 {(char_u *)8L, (char_u *)0L}}, 1871 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST, 1872 (char_u *)&p_shm, PV_NONE, 1873 {(char_u *)"", (char_u *)"filnxtToO"}}, 1874 {"shortname", "sn", P_BOOL|P_VI_DEF, 1875 #ifdef SHORT_FNAME 1876 (char_u *)NULL, PV_NONE, 1877 #else 1878 (char_u *)&p_sn, PV_SN, 1879 #endif 1880 {(char_u *)FALSE, (char_u *)0L}}, 1881 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL, 1882 #ifdef FEAT_LINEBREAK 1883 (char_u *)&p_sbr, PV_NONE, 1884 #else 1885 (char_u *)NULL, PV_NONE, 1886 #endif 1887 {(char_u *)"", (char_u *)0L}}, 1888 {"showcmd", "sc", P_BOOL|P_VIM, 1889 #ifdef FEAT_CMDL_INFO 1890 (char_u *)&p_sc, PV_NONE, 1891 #else 1892 (char_u *)NULL, PV_NONE, 1893 #endif 1894 {(char_u *)FALSE, 1895 #ifdef UNIX 1896 (char_u *)FALSE 1897 #else 1898 (char_u *)TRUE 1899 #endif 1900 }}, 1901 {"showfulltag", "sft", P_BOOL|P_VI_DEF, 1902 (char_u *)&p_sft, PV_NONE, 1903 {(char_u *)FALSE, (char_u *)0L}}, 1904 {"showmatch", "sm", P_BOOL|P_VI_DEF, 1905 (char_u *)&p_sm, PV_NONE, 1906 {(char_u *)FALSE, (char_u *)0L}}, 1907 {"showmode", "smd", P_BOOL|P_VIM, 1908 (char_u *)&p_smd, PV_NONE, 1909 {(char_u *)FALSE, (char_u *)TRUE}}, 1910 {"sidescroll", "ss", P_NUM|P_VI_DEF, 1911 (char_u *)&p_ss, PV_NONE, 1912 {(char_u *)0L, (char_u *)0L}}, 1913 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF, 1914 (char_u *)&p_siso, PV_NONE, 1915 {(char_u *)0L, (char_u *)0L}}, 1916 {"slowopen", "slow", P_BOOL|P_VI_DEF, 1917 (char_u *)NULL, PV_NONE, 1918 {(char_u *)FALSE, (char_u *)0L}}, 1919 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM, 1920 (char_u *)&p_scs, PV_NONE, 1921 {(char_u *)FALSE, (char_u *)0L}}, 1922 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM, 1923 #ifdef FEAT_SMARTINDENT 1924 (char_u *)&p_si, PV_SI, 1925 #else 1926 (char_u *)NULL, PV_NONE, 1927 #endif 1928 {(char_u *)FALSE, (char_u *)0L}}, 1929 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM, 1930 (char_u *)&p_sta, PV_NONE, 1931 {(char_u *)FALSE, (char_u *)0L}}, 1932 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM, 1933 (char_u *)&p_sts, PV_STS, 1934 {(char_u *)0L, (char_u *)0L}}, 1935 {"sourceany", NULL, P_BOOL|P_VI_DEF, 1936 (char_u *)NULL, PV_NONE, 1937 {(char_u *)FALSE, (char_u *)0L}}, 1938 {"splitbelow", "sb", P_BOOL|P_VI_DEF, 1939 #ifdef FEAT_WINDOWS 1940 (char_u *)&p_sb, PV_NONE, 1941 #else 1942 (char_u *)NULL, PV_NONE, 1943 #endif 1944 {(char_u *)FALSE, (char_u *)0L}}, 1945 {"splitright", "spr", P_BOOL|P_VI_DEF, 1946 #ifdef FEAT_VERTSPLIT 1947 (char_u *)&p_spr, PV_NONE, 1948 #else 1949 (char_u *)NULL, PV_NONE, 1950 #endif 1951 {(char_u *)FALSE, (char_u *)0L}}, 1952 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM, 1953 (char_u *)&p_sol, PV_NONE, 1954 {(char_u *)TRUE, (char_u *)0L}}, 1955 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT, 1956 #ifdef FEAT_STL_OPT 1957 (char_u *)&p_stl, PV_NONE, 1958 #else 1959 (char_u *)NULL, PV_NONE, 1960 #endif 1961 {(char_u *)"", (char_u *)0L}}, 1962 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1963 (char_u *)&p_su, PV_NONE, 1964 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj", 1965 (char_u *)0L}}, 1966 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP, 1967 #if defined(FEAT_SEARCHPATH) 1968 (char_u *)&p_sua, PV_SUA, 1969 {(char_u *)"", (char_u *)0L} 1970 #else 1971 (char_u *)NULL, PV_NONE, 1972 {(char_u *)0L, (char_u *)0L} 1973 #endif 1974 }, 1975 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT, 1976 (char_u *)&p_swf, PV_SWF, 1977 {(char_u *)TRUE, (char_u *)0L}}, 1978 {"swapsync", "sws", P_STRING|P_VI_DEF, 1979 (char_u *)&p_sws, PV_NONE, 1980 {(char_u *)"fsync", (char_u *)0L}}, 1981 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1982 (char_u *)&p_swb, PV_NONE, 1983 {(char_u *)"", (char_u *)0L}}, 1984 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB, 1985 #ifdef FEAT_SYN_HL 1986 (char_u *)&p_syn, PV_SYN, 1987 {(char_u *)"", (char_u *)0L} 1988 #else 1989 (char_u *)NULL, PV_NONE, 1990 {(char_u *)0L, (char_u *)0L} 1991 #endif 1992 }, 1993 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF, 1994 (char_u *)&p_ts, PV_TS, 1995 {(char_u *)8L, (char_u *)0L}}, 1996 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF, 1997 (char_u *)&p_tbs, PV_NONE, 1998 #ifdef VMS /* binary searching doesn't appear to work on VMS */ 1999 {(char_u *)0L, (char_u *)0L} 2000 #else 2001 {(char_u *)TRUE, (char_u *)0L} 2002 #endif 2003 }, 2004 {"taglength", "tl", P_NUM|P_VI_DEF, 2005 (char_u *)&p_tl, PV_NONE, 2006 {(char_u *)0L, (char_u *)0L}}, 2007 {"tagrelative", "tr", P_BOOL|P_VIM, 2008 (char_u *)&p_tr, PV_NONE, 2009 {(char_u *)FALSE, (char_u *)TRUE}}, 2010 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP, 2011 (char_u *)&p_tags, OPT_BOTH(PV_TAGS), 2012 { 2013 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME) 2014 (char_u *)"./tags,./TAGS,tags,TAGS", 2015 #else 2016 (char_u *)"./tags,tags", 2017 #endif 2018 (char_u *)0L}}, 2019 {"tagstack", "tgst", P_BOOL|P_VI_DEF, 2020 (char_u *)&p_tgst, PV_NONE, 2021 {(char_u *)TRUE, (char_u *)0L}}, 2022 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL, 2023 (char_u *)&T_NAME, PV_NONE, 2024 {(char_u *)"", (char_u *)0L}}, 2025 {"termbidi", "tbidi", P_BOOL|P_VI_DEF, 2026 #ifdef FEAT_ARABIC 2027 (char_u *)&p_tbidi, PV_NONE, 2028 #else 2029 (char_u *)NULL, PV_NONE, 2030 #endif 2031 {(char_u *)FALSE, (char_u *)0L}}, 2032 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR, 2033 #ifdef FEAT_MBYTE 2034 (char_u *)&p_tenc, PV_NONE, 2035 {(char_u *)"", (char_u *)0L} 2036 #else 2037 (char_u *)NULL, PV_NONE, 2038 {(char_u *)0L, (char_u *)0L} 2039 #endif 2040 }, 2041 {"terse", NULL, P_BOOL|P_VI_DEF, 2042 (char_u *)&p_terse, PV_NONE, 2043 {(char_u *)FALSE, (char_u *)0L}}, 2044 {"textauto", "ta", P_BOOL|P_VIM, 2045 (char_u *)&p_ta, PV_NONE, 2046 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}}, 2047 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC, 2048 (char_u *)&p_tx, PV_TX, 2049 { 2050 #ifdef USE_CRNL 2051 (char_u *)TRUE, 2052 #else 2053 (char_u *)FALSE, 2054 #endif 2055 (char_u *)0L}}, 2056 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM, 2057 (char_u *)&p_tw, PV_TW, 2058 {(char_u *)0L, (char_u *)0L}}, 2059 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP, 2060 #ifdef FEAT_INS_EXPAND 2061 (char_u *)&p_tsr, OPT_BOTH(PV_TSR), 2062 #else 2063 (char_u *)NULL, PV_NONE, 2064 #endif 2065 {(char_u *)"", (char_u *)0L}}, 2066 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM, 2067 (char_u *)&p_to, PV_NONE, 2068 {(char_u *)FALSE, (char_u *)0L}}, 2069 {"timeout", "to", P_BOOL|P_VI_DEF, 2070 (char_u *)&p_timeout, PV_NONE, 2071 {(char_u *)TRUE, (char_u *)0L}}, 2072 {"timeoutlen", "tm", P_NUM|P_VI_DEF, 2073 (char_u *)&p_tm, PV_NONE, 2074 {(char_u *)1000L, (char_u *)0L}}, 2075 {"title", NULL, P_BOOL|P_VI_DEF, 2076 #ifdef FEAT_TITLE 2077 (char_u *)&p_title, PV_NONE, 2078 #else 2079 (char_u *)NULL, PV_NONE, 2080 #endif 2081 {(char_u *)FALSE, (char_u *)0L}}, 2082 {"titlelen", NULL, P_NUM|P_VI_DEF, 2083 #ifdef FEAT_TITLE 2084 (char_u *)&p_titlelen, PV_NONE, 2085 #else 2086 (char_u *)NULL, PV_NONE, 2087 #endif 2088 {(char_u *)85L, (char_u *)0L}}, 2089 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT, 2090 #ifdef FEAT_TITLE 2091 (char_u *)&p_titleold, PV_NONE, 2092 {(char_u *)N_("Thanks for flying Vim"), 2093 (char_u *)0L} 2094 #else 2095 (char_u *)NULL, PV_NONE, 2096 {(char_u *)0L, (char_u *)0L} 2097 #endif 2098 }, 2099 {"titlestring", NULL, P_STRING|P_VI_DEF, 2100 #ifdef FEAT_TITLE 2101 (char_u *)&p_titlestring, PV_NONE, 2102 #else 2103 (char_u *)NULL, PV_NONE, 2104 #endif 2105 {(char_u *)"", (char_u *)0L}}, 2106 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) 2107 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP, 2108 (char_u *)&p_toolbar, PV_NONE, 2109 {(char_u *)"icons,tooltips", (char_u *)0L}}, 2110 #endif 2111 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2) 2112 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF, 2113 (char_u *)&p_tbis, PV_NONE, 2114 {(char_u *)"small", (char_u *)0L}}, 2115 #endif 2116 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM, 2117 (char_u *)&p_ttimeout, PV_NONE, 2118 {(char_u *)FALSE, (char_u *)0L}}, 2119 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF, 2120 (char_u *)&p_ttm, PV_NONE, 2121 {(char_u *)-1L, (char_u *)0L}}, 2122 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF, 2123 (char_u *)&p_tbi, PV_NONE, 2124 {(char_u *)TRUE, (char_u *)0L}}, 2125 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF, 2126 (char_u *)&p_tf, PV_NONE, 2127 {(char_u *)FALSE, (char_u *)0L}}, 2128 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF, 2129 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) 2130 (char_u *)&p_ttym, PV_NONE, 2131 #else 2132 (char_u *)NULL, PV_NONE, 2133 #endif 2134 {(char_u *)"", (char_u *)0L}}, 2135 {"ttyscroll", "tsl", P_NUM|P_VI_DEF, 2136 (char_u *)&p_ttyscroll, PV_NONE, 2137 {(char_u *)999L, (char_u *)0L}}, 2138 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL, 2139 (char_u *)&T_NAME, PV_NONE, 2140 {(char_u *)"", (char_u *)0L}}, 2141 {"undolevels", "ul", P_NUM|P_VI_DEF, 2142 (char_u *)&p_ul, PV_NONE, 2143 { 2144 #if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS) 2145 (char_u *)1000L, 2146 #else 2147 (char_u *)100L, 2148 #endif 2149 (char_u *)0L}}, 2150 {"updatecount", "uc", P_NUM|P_VI_DEF, 2151 (char_u *)&p_uc, PV_NONE, 2152 {(char_u *)200L, (char_u *)0L}}, 2153 {"updatetime", "ut", P_NUM|P_VI_DEF, 2154 (char_u *)&p_ut, PV_NONE, 2155 {(char_u *)4000L, (char_u *)0L}}, 2156 {"verbose", "vbs", P_NUM|P_VI_DEF, 2157 (char_u *)&p_verbose, PV_NONE, 2158 {(char_u *)0L, (char_u *)0L}}, 2159 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2160 #ifdef FEAT_SESSION 2161 (char_u *)&p_vdir, PV_NONE, 2162 {(char_u *)DFLT_VDIR, (char_u *)0L} 2163 #else 2164 (char_u *)NULL, PV_NONE, 2165 {(char_u *)0L, (char_u *)0L} 2166 #endif 2167 }, 2168 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 2169 #ifdef FEAT_SESSION 2170 (char_u *)&p_vop, PV_NONE, 2171 {(char_u *)"folds,options,cursor", (char_u *)0L} 2172 #else 2173 (char_u *)NULL, PV_NONE, 2174 {(char_u *)0L, (char_u *)0L} 2175 #endif 2176 }, 2177 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE, 2178 #ifdef FEAT_VIMINFO 2179 (char_u *)&p_viminfo, PV_NONE, 2180 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) 2181 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"} 2182 #else 2183 # ifdef AMIGA 2184 {(char_u *)"", 2185 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"} 2186 # else 2187 {(char_u *)"", (char_u *)"'20,<50,s10,h"} 2188 # endif 2189 #endif 2190 #else 2191 (char_u *)NULL, PV_NONE, 2192 {(char_u *)0L, (char_u *)0L} 2193 #endif 2194 }, 2195 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM, 2196 #ifdef FEAT_VIRTUALEDIT 2197 (char_u *)&p_ve, PV_NONE, 2198 {(char_u *)"", (char_u *)""} 2199 #else 2200 (char_u *)NULL, PV_NONE, 2201 {(char_u *)0L, (char_u *)0L} 2202 #endif 2203 }, 2204 {"visualbell", "vb", P_BOOL|P_VI_DEF, 2205 (char_u *)&p_vb, PV_NONE, 2206 {(char_u *)FALSE, (char_u *)0L}}, 2207 {"w300", NULL, P_NUM|P_VI_DEF, 2208 (char_u *)NULL, PV_NONE, 2209 {(char_u *)0L, (char_u *)0L}}, 2210 {"w1200", NULL, P_NUM|P_VI_DEF, 2211 (char_u *)NULL, PV_NONE, 2212 {(char_u *)0L, (char_u *)0L}}, 2213 {"w9600", NULL, P_NUM|P_VI_DEF, 2214 (char_u *)NULL, PV_NONE, 2215 {(char_u *)0L, (char_u *)0L}}, 2216 {"warn", NULL, P_BOOL|P_VI_DEF, 2217 (char_u *)&p_warn, PV_NONE, 2218 {(char_u *)TRUE, (char_u *)0L}}, 2219 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR, 2220 (char_u *)&p_wiv, PV_NONE, 2221 {(char_u *)FALSE, (char_u *)0L}}, 2222 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST, 2223 (char_u *)&p_ww, PV_NONE, 2224 {(char_u *)"", (char_u *)"b,s"}}, 2225 {"wildchar", "wc", P_NUM|P_VIM, 2226 (char_u *)&p_wc, PV_NONE, 2227 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}}, 2228 {"wildcharm", "wcm", P_NUM|P_VI_DEF, 2229 (char_u *)&p_wcm, PV_NONE, 2230 {(char_u *)0L, (char_u *)0L}}, 2231 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 2232 #ifdef FEAT_WILDIGN 2233 (char_u *)&p_wig, PV_NONE, 2234 #else 2235 (char_u *)NULL, PV_NONE, 2236 #endif 2237 {(char_u *)"", (char_u *)0L}}, 2238 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF, 2239 #ifdef FEAT_WILDMENU 2240 (char_u *)&p_wmnu, PV_NONE, 2241 #else 2242 (char_u *)NULL, PV_NONE, 2243 #endif 2244 {(char_u *)FALSE, (char_u *)0L}}, 2245 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 2246 (char_u *)&p_wim, PV_NONE, 2247 {(char_u *)"full", (char_u *)0L}}, 2248 {"winaltkeys", "wak", P_STRING|P_VI_DEF, 2249 #ifdef FEAT_WAK 2250 (char_u *)&p_wak, PV_NONE, 2251 {(char_u *)"menu", (char_u *)0L} 2252 #else 2253 (char_u *)NULL, PV_NONE, 2254 {(char_u *)NULL, (char_u *)0L} 2255 #endif 2256 }, 2257 {"window", "wi", P_NUM|P_VI_DEF, 2258 (char_u *)NULL, PV_NONE, 2259 {(char_u *)0L, (char_u *)0L}}, 2260 {"winheight", "wh", P_NUM|P_VI_DEF, 2261 #ifdef FEAT_WINDOWS 2262 (char_u *)&p_wh, PV_NONE, 2263 #else 2264 (char_u *)NULL, PV_NONE, 2265 #endif 2266 {(char_u *)1L, (char_u *)0L}}, 2267 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT, 2268 #if defined(FEAT_WINDOWS) 2269 (char_u *)VAR_WIN, PV_WFH, 2270 #else 2271 (char_u *)NULL, PV_NONE, 2272 #endif 2273 {(char_u *)FALSE, (char_u *)0L}}, 2274 {"winminheight", "wmh", P_NUM|P_VI_DEF, 2275 #ifdef FEAT_WINDOWS 2276 (char_u *)&p_wmh, PV_NONE, 2277 #else 2278 (char_u *)NULL, PV_NONE, 2279 #endif 2280 {(char_u *)1L, (char_u *)0L}}, 2281 {"winminwidth", "wmw", P_NUM|P_VI_DEF, 2282 #ifdef FEAT_VERTSPLIT 2283 (char_u *)&p_wmw, PV_NONE, 2284 #else 2285 (char_u *)NULL, PV_NONE, 2286 #endif 2287 {(char_u *)1L, (char_u *)0L}}, 2288 {"winwidth", "wiw", P_NUM|P_VI_DEF, 2289 #ifdef FEAT_VERTSPLIT 2290 (char_u *)&p_wiw, PV_NONE, 2291 #else 2292 (char_u *)NULL, PV_NONE, 2293 #endif 2294 {(char_u *)20L, (char_u *)0L}}, 2295 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN, 2296 (char_u *)VAR_WIN, PV_WRAP, 2297 {(char_u *)TRUE, (char_u *)0L}}, 2298 {"wrapmargin", "wm", P_NUM|P_VI_DEF, 2299 (char_u *)&p_wm, PV_WM, 2300 {(char_u *)0L, (char_u *)0L}}, 2301 {"wrapscan", "ws", P_BOOL|P_VI_DEF, 2302 (char_u *)&p_ws, PV_NONE, 2303 {(char_u *)TRUE, (char_u *)0L}}, 2304 {"write", NULL, P_BOOL|P_VI_DEF, 2305 (char_u *)&p_write, PV_NONE, 2306 {(char_u *)TRUE, (char_u *)0L}}, 2307 {"writeany", "wa", P_BOOL|P_VI_DEF, 2308 (char_u *)&p_wa, PV_NONE, 2309 {(char_u *)FALSE, (char_u *)0L}}, 2310 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM, 2311 (char_u *)&p_wb, PV_NONE, 2312 { 2313 #ifdef FEAT_WRITEBACKUP 2314 (char_u *)TRUE, 2315 #else 2316 (char_u *)FALSE, 2317 #endif 2318 (char_u *)0L}}, 2319 {"writedelay", "wd", P_NUM|P_VI_DEF, 2320 (char_u *)&p_wd, PV_NONE, 2321 {(char_u *)0L, (char_u *)0L}}, 2322 2323 /* terminal output codes */ 2324 #define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL, \ 2325 (char_u *)&vvv, PV_NONE, \ 2326 {(char_u *)"", (char_u *)0L}}, 2327 2328 p_term("t_AB", T_CAB) 2329 p_term("t_AF", T_CAF) 2330 p_term("t_AL", T_CAL) 2331 p_term("t_al", T_AL) 2332 p_term("t_bc", T_BC) 2333 p_term("t_cd", T_CD) 2334 p_term("t_ce", T_CE) 2335 p_term("t_cl", T_CL) 2336 p_term("t_cm", T_CM) 2337 p_term("t_Co", T_CCO) 2338 p_term("t_CS", T_CCS) 2339 p_term("t_cs", T_CS) 2340 #ifdef FEAT_VERTSPLIT 2341 p_term("t_CV", T_CSV) 2342 #endif 2343 p_term("t_ut", T_UT) 2344 p_term("t_da", T_DA) 2345 p_term("t_db", T_DB) 2346 p_term("t_DL", T_CDL) 2347 p_term("t_dl", T_DL) 2348 p_term("t_fs", T_FS) 2349 p_term("t_IE", T_CIE) 2350 p_term("t_IS", T_CIS) 2351 p_term("t_ke", T_KE) 2352 p_term("t_ks", T_KS) 2353 p_term("t_le", T_LE) 2354 p_term("t_mb", T_MB) 2355 p_term("t_md", T_MD) 2356 p_term("t_me", T_ME) 2357 p_term("t_mr", T_MR) 2358 p_term("t_ms", T_MS) 2359 p_term("t_nd", T_ND) 2360 p_term("t_op", T_OP) 2361 p_term("t_RI", T_CRI) 2362 p_term("t_RV", T_CRV) 2363 p_term("t_Sb", T_CSB) 2364 p_term("t_Sf", T_CSF) 2365 p_term("t_se", T_SE) 2366 p_term("t_so", T_SO) 2367 p_term("t_sr", T_SR) 2368 p_term("t_ts", T_TS) 2369 p_term("t_te", T_TE) 2370 p_term("t_ti", T_TI) 2371 p_term("t_ue", T_UE) 2372 p_term("t_us", T_US) 2373 p_term("t_vb", T_VB) 2374 p_term("t_ve", T_VE) 2375 p_term("t_vi", T_VI) 2376 p_term("t_vs", T_VS) 2377 p_term("t_WP", T_CWP) 2378 p_term("t_WS", T_CWS) 2379 p_term("t_xs", T_XS) 2380 p_term("t_ZH", T_CZH) 2381 p_term("t_ZR", T_CZR) 2382 2383 /* terminal key codes are not in here */ 2384 2385 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */ 2386 }; 2387 2388 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption)) 2389 2390 #ifdef FEAT_MBYTE 2391 static char *(p_ambw_values[]) = {"single", "double", NULL}; 2392 #endif 2393 static char *(p_bg_values[]) = {"light", "dark", NULL}; 2394 static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL}; 2395 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; 2396 #ifdef FEAT_WAK 2397 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; 2398 #endif 2399 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL}; 2400 #ifdef FEAT_VISUAL 2401 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL}; 2402 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL}; 2403 #endif 2404 #ifdef FEAT_VISUAL 2405 static char *(p_km_values[]) = {"startsel", "stopsel", NULL}; 2406 #endif 2407 #ifdef FEAT_BROWSE 2408 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL}; 2409 #endif 2410 #ifdef FEAT_SCROLLBIND 2411 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL}; 2412 #endif 2413 static char *(p_swb_values[]) = {"useopen", "split", NULL}; 2414 static char *(p_debug_values[]) = {"msg", NULL}; 2415 #ifdef FEAT_VERTSPLIT 2416 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; 2417 #endif 2418 #if defined(FEAT_QUICKFIX) 2419 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL}; 2420 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL}; 2421 #endif 2422 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL}; 2423 #ifdef FEAT_FOLDING 2424 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", 2425 #ifdef FEAT_DIFF 2426 "diff", 2427 #endif 2428 NULL}; 2429 static char *(p_fcl_values[]) = {"all", NULL}; 2430 #endif 2431 2432 static void set_option_default __ARGS((int, int opt_flags, int compatible)); 2433 static void set_options_default __ARGS((int opt_flags)); 2434 static char_u *illegal_char __ARGS((char_u *, int)); 2435 static int string_to_key __ARGS((char_u *arg)); 2436 #ifdef FEAT_CMDWIN 2437 static char_u *check_cedit __ARGS((void)); 2438 #endif 2439 #ifdef FEAT_TITLE 2440 static void did_set_title __ARGS((int icon)); 2441 #endif 2442 static char_u *option_expand __ARGS((int opt_idx, char_u *val)); 2443 static void didset_options __ARGS((void)); 2444 static void check_string_option __ARGS((char_u **pp)); 2445 static void set_string_option_global __ARGS((int opt_idx, char_u **varp)); 2446 static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags)); 2447 static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags)); 2448 static char_u *set_chars_option __ARGS((char_u **varp)); 2449 #ifdef FEAT_CLIPBOARD 2450 static char_u *check_clipboard_option __ARGS((void)); 2451 #endif 2452 static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags)); 2453 static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, int opt_flags)); 2454 static void check_redraw __ARGS((long_u flags)); 2455 static int findoption __ARGS((char_u *)); 2456 static int find_key_option __ARGS((char_u *)); 2457 static void showoptions __ARGS((int all, int opt_flags)); 2458 static int optval_default __ARGS((struct vimoption *, char_u *varp)); 2459 static void showoneopt __ARGS((struct vimoption *, int opt_flags)); 2460 static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand)); 2461 static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep)); 2462 static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value)); 2463 static int istermoption __ARGS((struct vimoption *)); 2464 static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags)); 2465 static char_u *get_varp __ARGS((struct vimoption *)); 2466 static void option_value2string __ARGS((struct vimoption *, int opt_flags)); 2467 static int wc_use_keyname __ARGS((char_u *varp, long *wcp)); 2468 #ifdef FEAT_LANGMAP 2469 static void langmap_init __ARGS((void)); 2470 static void langmap_set __ARGS((void)); 2471 #endif 2472 static void paste_option_changed __ARGS((void)); 2473 static void compatible_set __ARGS((void)); 2474 #ifdef FEAT_LINEBREAK 2475 static void fill_breakat_flags __ARGS((void)); 2476 #endif 2477 static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list)); 2478 static int check_opt_strings __ARGS((char_u *val, char **values, int)); 2479 static int check_opt_wim __ARGS((void)); 2480 2481 /* 2482 * Initialize the options, first part. 2483 * 2484 * Called only once from main(), just after creating the first buffer. 2485 */ 2486 void 2487 set_init_1() 2488 { 2489 char_u *p; 2490 int opt_idx; 2491 long n; 2492 2493 #ifdef FEAT_LANGMAP 2494 langmap_init(); 2495 #endif 2496 2497 /* Be Vi compatible by default */ 2498 p_cp = TRUE; 2499 2500 /* 2501 * Find default value for 'shell' option. 2502 */ 2503 if ((p = mch_getenv((char_u *)"SHELL")) != NULL 2504 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) 2505 # ifdef __EMX__ 2506 || (p = mch_getenv((char_u *)"EMXSHELL")) != NULL 2507 # endif 2508 || (p = mch_getenv((char_u *)"COMSPEC")) != NULL 2509 # ifdef WIN3264 2510 || (p = default_shell()) != NULL 2511 # endif 2512 #endif 2513 ) 2514 set_string_default("sh", p); 2515 2516 #ifdef FEAT_WILDIGN 2517 /* 2518 * Set the default for 'backupskip' to include environment variables for 2519 * temp files. 2520 */ 2521 { 2522 # ifdef UNIX 2523 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"}; 2524 # else 2525 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"}; 2526 # endif 2527 int len; 2528 garray_T ga; 2529 2530 ga_init2(&ga, 1, 100); 2531 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n) 2532 { 2533 # ifdef UNIX 2534 if (*names[n] == NUL) 2535 p = (char_u *)"/tmp"; 2536 else 2537 # endif 2538 p = mch_getenv((char_u *)names[n]); 2539 if (p != NULL && *p != NUL) 2540 { 2541 /* First time count the NUL, otherwise count the ','. */ 2542 len = STRLEN(p) + 3; 2543 if (ga_grow(&ga, len) == OK) 2544 { 2545 if (ga.ga_len > 0) 2546 STRCAT(ga.ga_data, ","); 2547 STRCAT(ga.ga_data, p); 2548 add_pathsep(ga.ga_data); 2549 STRCAT(ga.ga_data, "*"); 2550 ga.ga_room -= len; 2551 ga.ga_len += len; 2552 } 2553 } 2554 } 2555 if (ga.ga_data != NULL) 2556 { 2557 set_string_default("bsk", ga.ga_data); 2558 vim_free(ga.ga_data); 2559 } 2560 } 2561 #endif 2562 2563 /* 2564 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory 2565 */ 2566 opt_idx = findoption((char_u *)"maxmemtot"); 2567 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) 2568 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L) 2569 #endif 2570 { 2571 #ifdef HAVE_AVAIL_MEM 2572 /* Use amount of memory available at this moment. */ 2573 n = (mch_avail_mem(FALSE) >> 11); 2574 #else 2575 # ifdef HAVE_TOTAL_MEM 2576 /* Use amount of memory available to Vim. */ 2577 n = (mch_total_mem(FALSE) >> 11); 2578 # else 2579 n = (0x7fffffff >> 11); 2580 # endif 2581 #endif 2582 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; 2583 opt_idx = findoption((char_u *)"maxmem"); 2584 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) 2585 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n 2586 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L) 2587 #endif 2588 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; 2589 } 2590 2591 #ifdef FEAT_GUI_W32 2592 /* force 'shortname' for Win32s */ 2593 if (gui_is_win32s()) 2594 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] = 2595 (char_u *)TRUE; 2596 #endif 2597 2598 #ifdef FEAT_SEARCHPATH 2599 { 2600 char_u *cdpath; 2601 char_u *buf; 2602 int i; 2603 int j; 2604 2605 /* Initialize the 'cdpath' option's default value. */ 2606 cdpath = mch_getenv((char_u *)"CDPATH"); 2607 if (cdpath != NULL) 2608 { 2609 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2)); 2610 if (buf != NULL) 2611 { 2612 buf[0] = ','; /* start with ",", current dir first */ 2613 j = 1; 2614 for (i = 0; cdpath[i] != NUL; ++i) 2615 { 2616 if (vim_ispathlistsep(cdpath[i])) 2617 buf[j++] = ','; 2618 else 2619 { 2620 if (cdpath[i] == ' ' || cdpath[i] == ',') 2621 buf[j++] = '\\'; 2622 buf[j++] = cdpath[i]; 2623 } 2624 } 2625 buf[j] = NUL; 2626 opt_idx = findoption((char_u *)"cdpath"); 2627 options[opt_idx].def_val[VI_DEFAULT] = buf; 2628 options[opt_idx].flags |= P_DEF_ALLOCED; 2629 } 2630 } 2631 } 2632 #endif 2633 2634 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux)) 2635 /* Set print encoding on platforms that don't default to latin1 */ 2636 set_string_default("penc", 2637 # if defined(MSWIN) || defined(OS2) 2638 (char_u *)"cp1252" 2639 # else 2640 # ifdef VMS 2641 (char_u *)"dec-mcs" 2642 # else 2643 # ifdef EBCDIC 2644 (char_u *)"ebcdic-uk" 2645 # else 2646 # ifdef MAC 2647 (char_u *)"mac-roman" 2648 # else /* HPUX */ 2649 (char_u *)"hp-roman8" 2650 # endif 2651 # endif 2652 # endif 2653 # endif 2654 ); 2655 #endif 2656 2657 #ifdef FEAT_POSTSCRIPT 2658 /* 'printexpr' must be allocated to be able to evaluate it. */ 2659 set_string_default("pexpr", 2660 # if defined(MSWIN) || defined(MSDOS) || defined(OS2) 2661 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)" 2662 # else 2663 # ifdef VMS 2664 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)" 2665 2666 # else 2667 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error" 2668 # endif 2669 # endif 2670 ); 2671 #endif 2672 2673 /* 2674 * Set all the options (except the terminal options) to their default 2675 * value. Also set the global value for local options. 2676 */ 2677 set_options_default(0); 2678 2679 #ifdef FEAT_GUI 2680 if (found_reverse_arg) 2681 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0); 2682 #endif 2683 2684 curbuf->b_p_initialized = TRUE; 2685 curbuf->b_p_ar = -1; /* no local 'autoread' value */ 2686 check_buf_options(curbuf); 2687 check_win_options(curwin); 2688 check_options(); 2689 2690 /* Must be before option_expand(), because that one needs vim_isIDc() */ 2691 didset_options(); 2692 2693 #ifdef FEAT_LINEBREAK 2694 /* 2695 * initialize the table for 'breakat'. 2696 */ 2697 fill_breakat_flags(); 2698 #endif 2699 2700 /* 2701 * Expand environment variables and things like "~" for the defaults. 2702 * If option_expand() returns non-NULL the variable is expanded. This can 2703 * only happen for non-indirect options. 2704 * Also set the default to the expanded value, so ":set" does not list 2705 * them. 2706 * Don't set the P_ALLOCED flag, because we don't want to free the 2707 * default. 2708 */ 2709 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) 2710 { 2711 if ((options[opt_idx].flags & P_GETTEXT) 2712 && options[opt_idx].var != NULL) 2713 p = (char_u *)_(*(char **)options[opt_idx].var); 2714 else 2715 p = option_expand(opt_idx, NULL); 2716 if (p != NULL && (p = vim_strsave(p)) != NULL) 2717 { 2718 *(char_u **)options[opt_idx].var = p; 2719 /* VIMEXP 2720 * Defaults for all expanded options are currently the same for Vi 2721 * and Vim. When this changes, add some code here! Also need to 2722 * split P_DEF_ALLOCED in two. 2723 */ 2724 if (options[opt_idx].flags & P_DEF_ALLOCED) 2725 vim_free(options[opt_idx].def_val[VI_DEFAULT]); 2726 options[opt_idx].def_val[VI_DEFAULT] = p; 2727 options[opt_idx].flags |= P_DEF_ALLOCED; 2728 } 2729 } 2730 2731 /* Initialize the highlight_attr[] table. */ 2732 highlight_changed(); 2733 2734 save_file_ff(curbuf); /* Buffer is unchanged */ 2735 2736 /* Parse default for 'wildmode' */ 2737 check_opt_wim(); 2738 2739 #if defined(FEAT_ARABIC) 2740 /* Detect use of mlterm. 2741 * Mlterm is a terminal emulator akin to xterm that has some special 2742 * abilities (bidi namely). 2743 * NOTE: mlterm's author is being asked to 'set' a variable 2744 * instead of an environment variable due to inheritance. 2745 */ 2746 if (mch_getenv((char_u *)"MLTERM") != NULL) 2747 set_option_value((char_u *)"tbidi", 1L, NULL, 0); 2748 #endif 2749 2750 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING) 2751 /* Parse default for 'fillchars'. */ 2752 (void)set_chars_option(&p_fcs); 2753 #endif 2754 2755 #ifdef FEAT_CLIPBOARD 2756 /* Parse default for 'clipboard' */ 2757 (void)check_clipboard_option(); 2758 #endif 2759 2760 #ifdef FEAT_MBYTE 2761 # if defined(WIN3264) && defined(FEAT_GETTEXT) 2762 /* 2763 * If $LANG isn't set, try to get a good value for it. This makes the 2764 * right language be used automatically. Don't do this for English. 2765 */ 2766 if (mch_getenv((char_u *)"LANG") == NULL) 2767 { 2768 char buf[20]; 2769 2770 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95. 2771 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use 2772 * only the first two. */ 2773 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, 2774 (LPTSTR)buf, 20); 2775 if (n >= 2 && STRNICMP(buf, "en", 2) != 0) 2776 { 2777 /* There are a few exceptions (probably more) */ 2778 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0) 2779 STRCPY(buf, "zh_TW"); 2780 else if (STRNICMP(buf, "chs", 3) == 0 2781 || STRNICMP(buf, "zhc", 3) == 0) 2782 STRCPY(buf, "zh_CN"); 2783 else if (STRNICMP(buf, "jp", 2) == 0) 2784 STRCPY(buf, "ja"); 2785 else 2786 buf[2] = NUL; /* truncate to two-letter code */ 2787 vim_setenv("LANG", buf); 2788 } 2789 } 2790 # endif 2791 2792 /* enc_locale() will try to find the encoding of the current locale. */ 2793 p = enc_locale(); 2794 if (p != NULL) 2795 { 2796 char_u *save_enc; 2797 2798 /* Try setting 'encoding' and check if the value is valid. 2799 * If not, go back to the default "latin1". */ 2800 save_enc = p_enc; 2801 p_enc = p; 2802 if (mb_init() == NULL) 2803 { 2804 opt_idx = findoption((char_u *)"encoding"); 2805 options[opt_idx].def_val[VI_DEFAULT] = p_enc; 2806 options[opt_idx].flags |= P_DEF_ALLOCED; 2807 2808 # if defined(WIN3264) && !defined(FEAT_GUI) 2809 /* Win32 console: When GetACP() returns a different value from 2810 * GetConsoleCP() set 'termencoding'. */ 2811 if (GetACP() != GetConsoleCP()) 2812 { 2813 char buf[50]; 2814 2815 sprintf(buf, "cp%ld", (long)GetConsoleCP()); 2816 p_tenc = vim_strsave((char_u *)buf); 2817 if (p_tenc != NULL) 2818 { 2819 opt_idx = findoption((char_u *)"termencoding"); 2820 options[opt_idx].def_val[VI_DEFAULT] = p_tenc; 2821 options[opt_idx].flags |= P_DEF_ALLOCED; 2822 convert_setup(&input_conv, p_tenc, p_enc); 2823 convert_setup(&output_conv, p_enc, p_tenc); 2824 } 2825 else 2826 p_tenc = empty_option; 2827 } 2828 # endif 2829 } 2830 else 2831 { 2832 vim_free(p_enc); 2833 p_enc = save_enc; 2834 } 2835 } 2836 #endif 2837 2838 #ifdef FEAT_MULTI_LANG 2839 /* Set the default for 'helplang'. */ 2840 set_helplang_default(get_mess_lang()); 2841 #endif 2842 } 2843 2844 /* 2845 * Set an option to its default value. 2846 * This does not take care of side effects! 2847 */ 2848 static void 2849 set_option_default(opt_idx, opt_flags, compatible) 2850 int opt_idx; 2851 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ 2852 int compatible; /* use Vi default value */ 2853 { 2854 char_u *varp; /* pointer to variable for current option */ 2855 int dvi; /* index in def_val[] */ 2856 long_u flags; 2857 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; 2858 2859 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); 2860 flags = options[opt_idx].flags; 2861 if (varp != NULL) /* nothing to do for hidden option */ 2862 { 2863 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; 2864 if (flags & P_STRING) 2865 { 2866 /* Use set_string_option_direct() for local options to handle 2867 * freeing and allocating the value. */ 2868 if (options[opt_idx].indir != PV_NONE) 2869 set_string_option_direct(NULL, opt_idx, 2870 options[opt_idx].def_val[dvi], opt_flags); 2871 else 2872 { 2873 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) 2874 free_string_option(*(char_u **)(varp)); 2875 *(char_u **)varp = options[opt_idx].def_val[dvi]; 2876 options[opt_idx].flags &= ~P_ALLOCED; 2877 } 2878 } 2879 else if (flags & P_NUM) 2880 { 2881 if (varp == (char_u *)PV_SCROLL) 2882 win_comp_scroll(curwin); 2883 else 2884 { 2885 *(long *)varp = (long)options[opt_idx].def_val[dvi]; 2886 /* May also set global value for local option. */ 2887 if (both) 2888 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = 2889 *(long *)varp; 2890 } 2891 } 2892 else /* P_BOOL */ 2893 { 2894 /* the cast to long is required for Manx C */ 2895 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi]; 2896 /* May also set global value for local option. */ 2897 if (both) 2898 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = 2899 *(int *)varp; 2900 } 2901 } 2902 2903 #ifdef FEAT_EVAL 2904 /* Remember where the option was set. */ 2905 options[opt_idx].scriptID = current_SID; 2906 #endif 2907 } 2908 2909 /* 2910 * Set all options (except terminal options) to their default value. 2911 */ 2912 static void 2913 set_options_default(opt_flags) 2914 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ 2915 { 2916 int i; 2917 #ifdef FEAT_WINDOWS 2918 win_T *wp; 2919 #endif 2920 2921 for (i = 0; !istermoption(&options[i]); i++) 2922 if (!(options[i].flags & P_NODEFAULT)) 2923 set_option_default(i, opt_flags, p_cp); 2924 2925 #ifdef FEAT_WINDOWS 2926 /* The 'scroll' option must be computed for all windows. */ 2927 for (wp = firstwin; wp != NULL; wp = wp->w_next) 2928 win_comp_scroll(wp); 2929 #else 2930 win_comp_scroll(curwin); 2931 #endif 2932 } 2933 2934 /* 2935 * Set the Vi-default value of a string option. 2936 * Used for 'sh', 'backupskip' and 'term'. 2937 */ 2938 void 2939 set_string_default(name, val) 2940 char *name; 2941 char_u *val; 2942 { 2943 char_u *p; 2944 int opt_idx; 2945 2946 p = vim_strsave(val); 2947 if (p != NULL) /* we don't want a NULL */ 2948 { 2949 opt_idx = findoption((char_u *)name); 2950 if (options[opt_idx].flags & P_DEF_ALLOCED) 2951 vim_free(options[opt_idx].def_val[VI_DEFAULT]); 2952 options[opt_idx].def_val[VI_DEFAULT] = p; 2953 options[opt_idx].flags |= P_DEF_ALLOCED; 2954 } 2955 } 2956 2957 /* 2958 * Set the Vi-default value of a number option. 2959 * Used for 'lines' and 'columns'. 2960 */ 2961 void 2962 set_number_default(name, val) 2963 char *name; 2964 long val; 2965 { 2966 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val; 2967 } 2968 2969 /* 2970 * Initialize the options, part two: After getting Rows and Columns and 2971 * setting 'term'. 2972 */ 2973 void 2974 set_init_2() 2975 { 2976 /* 2977 * 'scroll' defaults to half the window height. Note that this default is 2978 * wrong when the window height changes. 2979 */ 2980 options[findoption((char_u *)"scroll")].def_val[VI_DEFAULT] 2981 = (char_u *)((long_u)Rows >> 1); 2982 comp_col(); 2983 2984 #if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)) 2985 { 2986 int idx4; 2987 2988 /* 2989 * If 'background' wasn't set by the user, try guessing the value, 2990 * depending on the terminal name. Only need to check for terminals 2991 * with a dark background, that can handle color. Only "linux" 2992 * console at the moment. 2993 */ 2994 idx4 = findoption((char_u *)"bg"); 2995 if (!(options[idx4].flags & P_WAS_SET) && STRCMP(T_NAME, "linux") == 0) 2996 { 2997 set_string_option_direct(NULL, idx4, (char_u *)"dark", OPT_FREE); 2998 /* don't mark it as set, when starting the GUI it may be changed 2999 * again */ 3000 options[idx4].flags &= ~P_WAS_SET; 3001 } 3002 } 3003 #endif 3004 } 3005 3006 /* 3007 * Initialize the options, part three: After reading the .vimrc 3008 */ 3009 void 3010 set_init_3() 3011 { 3012 #if defined(UNIX) || defined(OS2) || defined(WIN3264) 3013 /* 3014 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option. 3015 * This is done after other initializations, where 'shell' might have been 3016 * set, but only if they have not been set before. 3017 */ 3018 char_u *p; 3019 int idx_srr; 3020 int do_srr; 3021 #ifdef FEAT_QUICKFIX 3022 int idx_sp; 3023 int do_sp; 3024 #endif 3025 3026 idx_srr = findoption((char_u *)"srr"); 3027 do_srr = !(options[idx_srr].flags & P_WAS_SET); 3028 #ifdef FEAT_QUICKFIX 3029 idx_sp = findoption((char_u *)"sp"); 3030 do_sp = !(options[idx_sp].flags & P_WAS_SET); 3031 #endif 3032 3033 /* 3034 * Isolate the name of the shell: 3035 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f". 3036 * - Remove any argument. E.g., "csh -f" -> "csh". 3037 */ 3038 p = gettail(p_sh); 3039 p = vim_strnsave(p, (int)(skiptowhite(p) - p)); 3040 if (p != NULL) 3041 { 3042 /* 3043 * Default for p_sp is "| tee", for p_srr is ">". 3044 * For known shells it is changed here to include stderr. 3045 */ 3046 if ( fnamecmp(p, "csh") == 0 3047 || fnamecmp(p, "tcsh") == 0 3048 # if defined(OS2) || defined(WIN3264) /* also check with .exe extension */ 3049 || fnamecmp(p, "csh.exe") == 0 3050 || fnamecmp(p, "tcsh.exe") == 0 3051 # endif 3052 ) 3053 { 3054 #if defined(FEAT_QUICKFIX) 3055 if (do_sp) 3056 { 3057 # ifdef WIN3264 3058 p_sp = (char_u *)">&"; 3059 # else 3060 p_sp = (char_u *)"|& tee"; 3061 # endif 3062 options[idx_sp].def_val[VI_DEFAULT] = p_sp; 3063 } 3064 #endif 3065 if (do_srr) 3066 { 3067 p_srr = (char_u *)">&"; 3068 options[idx_srr].def_val[VI_DEFAULT] = p_srr; 3069 } 3070 } 3071 else 3072 # ifndef OS2 /* Always use bourne shell style redirection if we reach this */ 3073 if ( fnamecmp(p, "sh") == 0 3074 || fnamecmp(p, "ksh") == 0 3075 || fnamecmp(p, "zsh") == 0 3076 || fnamecmp(p, "bash") == 0 3077 # ifdef WIN3264 3078 || fnamecmp(p, "cmd") == 0 3079 || fnamecmp(p, "sh.exe") == 0 3080 || fnamecmp(p, "ksh.exe") == 0 3081 || fnamecmp(p, "zsh.exe") == 0 3082 || fnamecmp(p, "bash.exe") == 0 3083 || fnamecmp(p, "cmd.exe") == 0 3084 # endif 3085 ) 3086 # endif 3087 { 3088 #if defined(FEAT_QUICKFIX) 3089 if (do_sp) 3090 { 3091 # ifdef WIN3264 3092 p_sp = (char_u *)">%s 2>&1"; 3093 # else 3094 p_sp = (char_u *)"2>&1| tee"; 3095 # endif 3096 options[idx_sp].def_val[VI_DEFAULT] = p_sp; 3097 } 3098 #endif 3099 if (do_srr) 3100 { 3101 p_srr = (char_u *)">%s 2>&1"; 3102 options[idx_srr].def_val[VI_DEFAULT] = p_srr; 3103 } 3104 } 3105 vim_free(p); 3106 } 3107 #endif 3108 3109 #if defined(MSDOS) || defined(WIN3264) || defined(OS2) 3110 /* 3111 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option. 3112 * This is done after other initializations, where 'shell' might have been 3113 * set, but only if they have not been set before. Default for p_shcf is 3114 * "/c", for p_shq is "". For "sh" like shells it is changed here to 3115 * "-c" and "\"", but not for DJGPP, because it starts the shell without 3116 * command.com. And for Win32 we need to set p_sxq instead. 3117 */ 3118 if (strstr((char *)gettail(p_sh), "sh") != NULL) 3119 { 3120 int idx3; 3121 3122 idx3 = findoption((char_u *)"shcf"); 3123 if (!(options[idx3].flags & P_WAS_SET)) 3124 { 3125 p_shcf = (char_u *)"-c"; 3126 options[idx3].def_val[VI_DEFAULT] = p_shcf; 3127 } 3128 3129 # ifndef DJGPP 3130 # ifdef WIN3264 3131 /* Somehow Win32 requires the quotes around the redirection too */ 3132 idx3 = findoption((char_u *)"sxq"); 3133 if (!(options[idx3].flags & P_WAS_SET)) 3134 { 3135 p_sxq = (char_u *)"\""; 3136 options[idx3].def_val[VI_DEFAULT] = p_sxq; 3137 } 3138 # else 3139 idx3 = findoption((char_u *)"shq"); 3140 if (!(options[idx3].flags & P_WAS_SET)) 3141 { 3142 p_shq = (char_u *)"\""; 3143 options[idx3].def_val[VI_DEFAULT] = p_shq; 3144 } 3145 # endif 3146 # endif 3147 } 3148 #endif 3149 3150 #ifdef FEAT_TITLE 3151 set_title_defaults(); 3152 #endif 3153 } 3154 3155 #if defined(FEAT_MULTI_LANG) || defined(PROTO) 3156 /* 3157 * When 'helplang' is still at its default value, set it to "lang". 3158 * Only the first two characters of "lang" are used. 3159 */ 3160 void 3161 set_helplang_default(lang) 3162 char_u *lang; 3163 { 3164 int idx; 3165 3166 if (lang == NULL || STRLEN(lang) < 2) /* safety check */ 3167 return; 3168 idx = findoption((char_u *)"hlg"); 3169 if (!(options[idx].flags & P_WAS_SET)) 3170 { 3171 if (options[idx].flags & P_ALLOCED) 3172 free_string_option(p_hlg); 3173 p_hlg = vim_strsave(lang); 3174 if (p_hlg == NULL) 3175 p_hlg = empty_option; 3176 else 3177 p_hlg[2] = NUL; 3178 options[idx].flags |= P_ALLOCED; 3179 } 3180 } 3181 #endif 3182 3183 #ifdef FEAT_GUI 3184 static char_u *gui_bg_default __ARGS((void)); 3185 3186 static char_u * 3187 gui_bg_default() 3188 { 3189 if (gui_get_lightness(gui.back_pixel) < 127) 3190 return (char_u *)"dark"; 3191 return (char_u *)"light"; 3192 } 3193 3194 /* 3195 * Option initializations that can only be done after opening the GUI window. 3196 */ 3197 void 3198 init_gui_options() 3199 { 3200 /* Set the 'background' option according to the lightness of the 3201 * background color, unless the user has set it already. */ 3202 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0) 3203 { 3204 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0); 3205 highlight_changed(); 3206 } 3207 } 3208 #endif 3209 3210 #ifdef FEAT_TITLE 3211 /* 3212 * 'title' and 'icon' only default to true if they have not been set or reset 3213 * in .vimrc and we can read the old value. 3214 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if 3215 * they can be reset. This reduces startup time when using X on a remote 3216 * machine. 3217 */ 3218 void 3219 set_title_defaults() 3220 { 3221 int idx1; 3222 long val; 3223 3224 /* 3225 * If GUI is (going to be) used, we can always set the window title and 3226 * icon name. Saves a bit of time, because the X11 display server does 3227 * not need to be contacted. 3228 */ 3229 idx1 = findoption((char_u *)"title"); 3230 if (!(options[idx1].flags & P_WAS_SET)) 3231 { 3232 #ifdef FEAT_GUI 3233 if (gui.starting || gui.in_use) 3234 val = TRUE; 3235 else 3236 #endif 3237 val = mch_can_restore_title(); 3238 options[idx1].def_val[VI_DEFAULT] = (char_u *)val; 3239 p_title = val; 3240 } 3241 idx1 = findoption((char_u *)"icon"); 3242 if (!(options[idx1].flags & P_WAS_SET)) 3243 { 3244 #ifdef FEAT_GUI 3245 if (gui.starting || gui.in_use) 3246 val = TRUE; 3247 else 3248 #endif 3249 val = mch_can_restore_icon(); 3250 options[idx1].def_val[VI_DEFAULT] = (char_u *)val; 3251 p_icon = val; 3252 } 3253 } 3254 #endif 3255 3256 /* 3257 * Parse 'arg' for option settings. 3258 * 3259 * 'arg' may be IObuff, but only when no errors can be present and option 3260 * does not need to be expanded with option_expand(). 3261 * "opt_flags": 3262 * 0 for ":set" 3263 * OPT_GLOBAL for ":setglobal" 3264 * OPT_LOCAL for ":setlocal" and a modeline 3265 * OPT_MODELINE for a modeline 3266 * 3267 * returns FAIL if an error is detected, OK otherwise 3268 */ 3269 int 3270 do_set(arg, opt_flags) 3271 char_u *arg; /* option string (may be written to!) */ 3272 int opt_flags; 3273 { 3274 int opt_idx; 3275 char_u *errmsg; 3276 char_u errbuf[80]; 3277 char_u *startarg; 3278 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */ 3279 int nextchar; /* next non-white char after option name */ 3280 int afterchar; /* character just after option name */ 3281 int len; 3282 int i; 3283 long value; 3284 int key; 3285 long_u flags; /* flags for current option */ 3286 char_u *varp = NULL; /* pointer to variable for current option */ 3287 int did_show = FALSE; /* already showed one value */ 3288 int adding; /* "opt+=arg" */ 3289 int prepending; /* "opt^=arg" */ 3290 int removing; /* "opt-=arg" */ 3291 int cp_val = 0; 3292 char_u key_name[2]; 3293 3294 if (*arg == NUL) 3295 { 3296 showoptions(0, opt_flags); 3297 return OK; 3298 } 3299 3300 while (*arg != NUL) /* loop to process all options */ 3301 { 3302 errmsg = NULL; 3303 startarg = arg; /* remember for error message */ 3304 3305 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])) 3306 { 3307 /* 3308 * ":set all" show all options. 3309 * ":set all&" set all options to their default value. 3310 */ 3311 arg += 3; 3312 if (*arg == '&') 3313 { 3314 ++arg; 3315 /* Only for :set command set global value of local options. */ 3316 set_options_default(OPT_FREE | opt_flags); 3317 } 3318 else 3319 showoptions(1, opt_flags); 3320 } 3321 else if (STRNCMP(arg, "termcap", 7) == 0) 3322 { 3323 showoptions(2, opt_flags); 3324 show_termcodes(); 3325 arg += 7; 3326 } 3327 else 3328 { 3329 prefix = 1; 3330 if (STRNCMP(arg, "no", 2) == 0) 3331 { 3332 prefix = 0; 3333 arg += 2; 3334 } 3335 else if (STRNCMP(arg, "inv", 3) == 0) 3336 { 3337 prefix = 2; 3338 arg += 3; 3339 } 3340 3341 /* find end of name */ 3342 key = 0; 3343 if (*arg == '<') 3344 { 3345 nextchar = 0; 3346 opt_idx = -1; 3347 /* look out for <t_>;> */ 3348 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) 3349 len = 5; 3350 else 3351 { 3352 len = 1; 3353 while (arg[len] != NUL && arg[len] != '>') 3354 ++len; 3355 } 3356 if (arg[len] != '>') 3357 { 3358 errmsg = e_invarg; 3359 goto skip; 3360 } 3361 arg[len] = NUL; /* put NUL after name */ 3362 if (arg[1] == 't' && arg[2] == '_') /* could be term code */ 3363 opt_idx = findoption(arg + 1); 3364 arg[len++] = '>'; /* restore '>' */ 3365 if (opt_idx == -1) 3366 key = find_key_option(arg + 1); 3367 } 3368 else 3369 { 3370 len = 0; 3371 /* 3372 * The two characters after "t_" may not be alphanumeric. 3373 */ 3374 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) 3375 len = 4; 3376 else 3377 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') 3378 ++len; 3379 nextchar = arg[len]; 3380 arg[len] = NUL; /* put NUL after name */ 3381 opt_idx = findoption(arg); 3382 arg[len] = nextchar; /* restore nextchar */ 3383 if (opt_idx == -1) 3384 key = find_key_option(arg); 3385 } 3386 3387 /* remember character after option name */ 3388 afterchar = arg[len]; 3389 3390 /* skip white space, allow ":set ai ?" */ 3391 while (vim_iswhite(arg[len])) 3392 ++len; 3393 3394 adding = FALSE; 3395 prepending = FALSE; 3396 removing = FALSE; 3397 if (arg[len] != NUL && arg[len + 1] == '=') 3398 { 3399 if (arg[len] == '+') 3400 { 3401 adding = TRUE; /* "+=" */ 3402 ++len; 3403 } 3404 else if (arg[len] == '^') 3405 { 3406 prepending = TRUE; /* "^=" */ 3407 ++len; 3408 } 3409 else if (arg[len] == '-') 3410 { 3411 removing = TRUE; /* "-=" */ 3412 ++len; 3413 } 3414 } 3415 nextchar = arg[len]; 3416 3417 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */ 3418 { 3419 errmsg = (char_u *)N_("E518: Unknown option"); 3420 goto skip; 3421 } 3422 3423 if (opt_idx >= 0) 3424 { 3425 if (options[opt_idx].var == NULL) /* hidden option: skip */ 3426 { 3427 /* Only give an error message when requesting the value of 3428 * a hidden option, ignore setting it. */ 3429 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL 3430 && (!(options[opt_idx].flags & P_BOOL) 3431 || nextchar == '?')) 3432 errmsg = (char_u *)N_("E519: Option not supported"); 3433 goto skip; 3434 } 3435 3436 flags = options[opt_idx].flags; 3437 varp = get_varp_scope(&(options[opt_idx]), opt_flags); 3438 } 3439 else 3440 { 3441 flags = P_STRING; 3442 if (key < 0) 3443 { 3444 key_name[0] = KEY2TERMCAP0(key); 3445 key_name[1] = KEY2TERMCAP1(key); 3446 } 3447 else 3448 { 3449 key_name[0] = KS_KEY; 3450 key_name[1] = (key & 0xff); 3451 } 3452 } 3453 3454 /* Disallow changing some options from modelines */ 3455 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE)) 3456 { 3457 errmsg = (char_u *)_("E520: Not allowed in a modeline"); 3458 goto skip; 3459 } 3460 3461 #ifdef HAVE_SANDBOX 3462 /* Disallow changing some options in the sandbox */ 3463 if (sandbox > 0 && (flags & P_SECURE)) 3464 { 3465 errmsg = (char_u *)_(e_sandbox); 3466 goto skip; 3467 } 3468 #endif 3469 3470 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL) 3471 { 3472 arg += len; 3473 cp_val = p_cp; 3474 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') 3475 { 3476 if (arg[3] == 'm') /* "opt&vim": set to Vim default */ 3477 { 3478 cp_val = FALSE; 3479 arg += 3; 3480 } 3481 else /* "opt&vi": set to Vi default */ 3482 { 3483 cp_val = TRUE; 3484 arg += 2; 3485 } 3486 } 3487 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL 3488 && arg[1] != NUL && !vim_iswhite(arg[1])) 3489 { 3490 errmsg = e_trailing; 3491 goto skip; 3492 } 3493 } 3494 3495 /* 3496 * allow '=' and ':' as MSDOS command.com allows only one 3497 * '=' character per "set" command line. grrr. (jw) 3498 */ 3499 if (nextchar == '?' 3500 || (prefix == 1 3501 && vim_strchr((char_u *)"=:&<", nextchar) == NULL 3502 && !(flags & P_BOOL))) 3503 { 3504 /* 3505 * print value 3506 */ 3507 if (did_show) 3508 msg_putchar('\n'); /* cursor below last one */ 3509 else 3510 { 3511 gotocmdline(TRUE); /* cursor at status line */ 3512 did_show = TRUE; /* remember that we did a line */ 3513 } 3514 if (opt_idx >= 0) 3515 { 3516 showoneopt(&options[opt_idx], opt_flags); 3517 #ifdef FEAT_EVAL 3518 if (p_verbose > 0) 3519 { 3520 if (options[opt_idx].scriptID != 0) 3521 { 3522 MSG_PUTS(_("\n\tLast set from ")); 3523 MSG_PUTS(get_scriptname(options[opt_idx].scriptID)); 3524 } 3525 } 3526 #endif 3527 } 3528 else 3529 { 3530 char_u *p; 3531 3532 p = find_termcode(key_name); 3533 if (p == NULL) 3534 { 3535 errmsg = (char_u *)N_("E518: Unknown option"); 3536 goto skip; 3537 } 3538 else 3539 (void)show_one_termcode(key_name, p, TRUE); 3540 } 3541 if (nextchar != '?' 3542 && nextchar != NUL && !vim_iswhite(afterchar)) 3543 errmsg = e_trailing; 3544 } 3545 else 3546 { 3547 if (flags & P_BOOL) /* boolean */ 3548 { 3549 if (nextchar == '=' || nextchar == ':') 3550 { 3551 errmsg = e_invarg; 3552 goto skip; 3553 } 3554 3555 /* 3556 * ":set opt!": invert 3557 * ":set opt&": reset to default value 3558 * ":set opt<": reset to global value 3559 */ 3560 if (nextchar == '!') 3561 value = *(int *)(varp) ^ 1; 3562 else if (nextchar == '&') 3563 value = (int)(long)options[opt_idx].def_val[ 3564 ((flags & P_VI_DEF) || cp_val) 3565 ? VI_DEFAULT : VIM_DEFAULT]; 3566 else if (nextchar == '<') 3567 { 3568 /* For 'autoread' -1 means to use global value. */ 3569 if ((int *)varp == &curbuf->b_p_ar 3570 && opt_flags == OPT_LOCAL) 3571 value = -1; 3572 else 3573 value = *(int *)get_varp_scope(&(options[opt_idx]), 3574 OPT_GLOBAL); 3575 } 3576 else 3577 { 3578 /* 3579 * ":set invopt": invert 3580 * ":set opt" or ":set noopt": set or reset 3581 */ 3582 if (nextchar != NUL && !vim_iswhite(afterchar)) 3583 { 3584 errmsg = e_trailing; 3585 goto skip; 3586 } 3587 if (prefix == 2) /* inv */ 3588 value = *(int *)(varp) ^ 1; 3589 else 3590 value = prefix; 3591 } 3592 3593 errmsg = set_bool_option(opt_idx, varp, (int)value, 3594 opt_flags); 3595 } 3596 else /* numeric or string */ 3597 { 3598 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL 3599 || prefix != 1) 3600 { 3601 errmsg = e_invarg; 3602 goto skip; 3603 } 3604 3605 if (flags & P_NUM) /* numeric */ 3606 { 3607 /* 3608 * Different ways to set a number option: 3609 * & set to default value 3610 * < set to global value 3611 * <xx> accept special key codes for 'wildchar' 3612 * c accept any non-digit for 'wildchar' 3613 * [-]0-9 set number 3614 * other error 3615 */ 3616 ++arg; 3617 if (nextchar == '&') 3618 value = (long)options[opt_idx].def_val[ 3619 ((flags & P_VI_DEF) || cp_val) 3620 ? VI_DEFAULT : VIM_DEFAULT]; 3621 else if (nextchar == '<') 3622 value = *(long *)get_varp_scope(&(options[opt_idx]), 3623 OPT_GLOBAL); 3624 else if (((long *)varp == &p_wc 3625 || (long *)varp == &p_wcm) 3626 && (*arg == '<' 3627 || *arg == '^' 3628 || ((!arg[1] || vim_iswhite(arg[1])) 3629 && !VIM_ISDIGIT(*arg)))) 3630 { 3631 value = string_to_key(arg); 3632 if (value == 0 && (long *)varp != &p_wcm) 3633 { 3634 errmsg = e_invarg; 3635 goto skip; 3636 } 3637 } 3638 /* allow negative numbers (for 'undolevels') */ 3639 else if (*arg == '-' || VIM_ISDIGIT(*arg)) 3640 { 3641 i = 0; 3642 if (*arg == '-') 3643 i = 1; 3644 #ifdef HAVE_STRTOL 3645 value = strtol((char *)arg, NULL, 0); 3646 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x') 3647 i += 2; 3648 #else 3649 value = atol((char *)arg); 3650 #endif 3651 while (VIM_ISDIGIT(arg[i])) 3652 ++i; 3653 if (arg[i] != NUL && !vim_iswhite(arg[i])) 3654 { 3655 errmsg = e_invarg; 3656 goto skip; 3657 } 3658 } 3659 else 3660 { 3661 errmsg = (char_u *)N_("E521: Number required after ="); 3662 goto skip; 3663 } 3664 3665 if (adding) 3666 value = *(long *)varp + value; 3667 if (prepending) 3668 value = *(long *)varp * value; 3669 if (removing) 3670 value = *(long *)varp - value; 3671 errmsg = set_num_option(opt_idx, varp, value, 3672 errbuf, opt_flags); 3673 } 3674 else if (opt_idx >= 0) /* string */ 3675 { 3676 char_u *save_arg = NULL; 3677 char_u *s = NULL; 3678 char_u *oldval; /* previous value if *varp */ 3679 char_u *newval; 3680 char_u *origval; 3681 unsigned newlen; 3682 int comma; 3683 int bs; 3684 int new_value_alloced; /* new string option 3685 was allocated */ 3686 3687 /* When using ":set opt=val" for a global option 3688 * with a local value the local value will be 3689 * reset, use the global value here. */ 3690 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 3691 && (int)options[opt_idx].indir >= PV_BOTH) 3692 varp = options[opt_idx].var; 3693 3694 /* The old value is kept until we are sure that the 3695 * new value is valid. */ 3696 oldval = *(char_u **)varp; 3697 if (nextchar == '&') /* set to default val */ 3698 { 3699 newval = options[opt_idx].def_val[ 3700 ((flags & P_VI_DEF) || cp_val) 3701 ? VI_DEFAULT : VIM_DEFAULT]; 3702 if ((char_u **)varp == &p_bg) 3703 { 3704 /* guess the value of 'background' */ 3705 #ifdef FEAT_GUI 3706 if (gui.in_use) 3707 newval = gui_bg_default(); 3708 else 3709 #endif 3710 if (STRCMP(T_NAME, "linux") == 0) 3711 newval = (char_u *)"dark"; 3712 } 3713 3714 /* expand environment variables and ~ (since the 3715 * default value was already expanded, only 3716 * required when an environment variable was set 3717 * later */ 3718 if (newval == NULL) 3719 newval = empty_option; 3720 else 3721 { 3722 s = option_expand(opt_idx, newval); 3723 if (s == NULL) 3724 s = newval; 3725 newval = vim_strsave(s); 3726 } 3727 new_value_alloced = TRUE; 3728 } 3729 else if (nextchar == '<') /* set to global val */ 3730 { 3731 newval = vim_strsave(*(char_u **)get_varp_scope( 3732 &(options[opt_idx]), OPT_GLOBAL)); 3733 new_value_alloced = TRUE; 3734 } 3735 else 3736 { 3737 ++arg; /* jump to after the '=' or ':' */ 3738 3739 /* 3740 * Set 'keywordprg' to ":help" if an empty 3741 * value was passed to :set by the user. 3742 * Misuse errbuf[] for the resulting string. 3743 */ 3744 if (varp == (char_u *)&p_kp 3745 && (*arg == NUL || *arg == ' ')) 3746 { 3747 STRCPY(errbuf, ":help"); 3748 save_arg = arg; 3749 arg = errbuf; 3750 } 3751 /* 3752 * Convert 'whichwrap' number to string, for 3753 * backwards compatibility with Vim 3.0. 3754 * Misuse errbuf[] for the resulting string. 3755 */ 3756 else if (varp == (char_u *)&p_ww 3757 && VIM_ISDIGIT(*arg)) 3758 { 3759 *errbuf = NUL; 3760 i = getdigits(&arg); 3761 if (i & 1) 3762 STRCAT(errbuf, "b,"); 3763 if (i & 2) 3764 STRCAT(errbuf, "s,"); 3765 if (i & 4) 3766 STRCAT(errbuf, "h,l,"); 3767 if (i & 8) 3768 STRCAT(errbuf, "<,>,"); 3769 if (i & 16) 3770 STRCAT(errbuf, "[,],"); 3771 if (*errbuf != NUL) /* remove trailing , */ 3772 errbuf[STRLEN(errbuf) - 1] = NUL; 3773 save_arg = arg; 3774 arg = errbuf; 3775 } 3776 /* 3777 * Remove '>' before 'dir' and 'bdir', for 3778 * backwards compatibility with version 3.0 3779 */ 3780 else if ( *arg == '>' 3781 && (varp == (char_u *)&p_dir 3782 || varp == (char_u *)&p_bdir)) 3783 { 3784 ++arg; 3785 } 3786 3787 /* When setting the local value of a global 3788 * option, the old value may be the global value. */ 3789 if ((int)options[opt_idx].indir >= PV_BOTH 3790 && (opt_flags & OPT_LOCAL)) 3791 origval = *(char_u **)get_varp( 3792 &options[opt_idx]); 3793 else 3794 origval = oldval; 3795 3796 /* 3797 * Copy the new string into allocated memory. 3798 * Can't use set_string_option_direct(), because 3799 * we need to remove the backslashes. 3800 */ 3801 /* get a bit too much */ 3802 newlen = (unsigned)STRLEN(arg) + 1; 3803 if (adding || prepending || removing) 3804 newlen += (unsigned)STRLEN(origval) + 1; 3805 newval = alloc(newlen); 3806 if (newval == NULL) /* out of mem, don't change */ 3807 break; 3808 s = newval; 3809 3810 /* 3811 * Copy the string, skip over escaped chars. 3812 * For MS-DOS and WIN32 backslashes before normal 3813 * file name characters are not removed, and keep 3814 * backslash at start, for "\\machine\path", but 3815 * do remove it for "\\\\machine\\path". 3816 * The reverse is found in ExpandOldSetting(). 3817 */ 3818 while (*arg && !vim_iswhite(*arg)) 3819 { 3820 if (*arg == '\\' && arg[1] != NUL 3821 #ifdef BACKSLASH_IN_FILENAME 3822 && !((flags & P_EXPAND) 3823 && vim_isfilec(arg[1]) 3824 && (arg[1] != '\\' 3825 || (s == newval 3826 && arg[2] != '\\'))) 3827 #endif 3828 ) 3829 ++arg; /* remove backslash */ 3830 #ifdef FEAT_MBYTE 3831 if (has_mbyte 3832 && (i = (*mb_ptr2len_check)(arg)) > 1) 3833 { 3834 /* copy multibyte char */ 3835 mch_memmove(s, arg, (size_t)i); 3836 arg += i; 3837 s += i; 3838 } 3839 else 3840 #endif 3841 *s++ = *arg++; 3842 } 3843 *s = NUL; 3844 3845 /* 3846 * Expand environment variables and ~. 3847 * Don't do it when adding without inserting a 3848 * comma. 3849 */ 3850 if (!(adding || prepending || removing) 3851 || (flags & P_COMMA)) 3852 { 3853 s = option_expand(opt_idx, newval); 3854 if (s != NULL) 3855 { 3856 vim_free(newval); 3857 newlen = (unsigned)STRLEN(s) + 1; 3858 if (adding || prepending || removing) 3859 newlen += (unsigned)STRLEN(origval) + 1; 3860 newval = alloc(newlen); 3861 if (newval == NULL) 3862 break; 3863 STRCPY(newval, s); 3864 } 3865 } 3866 3867 /* locate newval[] in origval[] when removing it 3868 * and when adding to avoid duplicates */ 3869 i = 0; /* init for GCC */ 3870 if (removing || (flags & P_NODUP)) 3871 { 3872 i = (int)STRLEN(newval); 3873 bs = 0; 3874 for (s = origval; *s; ++s) 3875 { 3876 if ((!(flags & P_COMMA) 3877 || s == origval 3878 || (s[-1] == ',' && !(bs & 1))) 3879 && STRNCMP(s, newval, i) == 0 3880 && (!(flags & P_COMMA) 3881 || s[i] == ',' 3882 || s[i] == NUL)) 3883 break; 3884 /* Count backspaces. Only a comma with an 3885 * even number of backspaces before it is 3886 * recognized as a separator */ 3887 if (s > origval && s[-1] == '\\') 3888 ++bs; 3889 else 3890 bs = 0; 3891 } 3892 3893 /* do not add if already there */ 3894 if ((adding || prepending) && *s) 3895 { 3896 prepending = FALSE; 3897 adding = FALSE; 3898 STRCPY(newval, origval); 3899 } 3900 } 3901 3902 /* concatenate the two strings; add a ',' if 3903 * needed */ 3904 if (adding || prepending) 3905 { 3906 comma = ((flags & P_COMMA) && *origval != NUL 3907 && *newval != NUL); 3908 if (adding) 3909 { 3910 i = (int)STRLEN(origval); 3911 mch_memmove(newval + i + comma, newval, 3912 STRLEN(newval) + 1); 3913 mch_memmove(newval, origval, (size_t)i); 3914 } 3915 else 3916 { 3917 i = (int)STRLEN(newval); 3918 mch_memmove(newval + i + comma, origval, 3919 STRLEN(origval) + 1); 3920 } 3921 if (comma) 3922 newval[i] = ','; 3923 } 3924 3925 /* Remove newval[] from origval[]. (Note: "i" has 3926 * been set above and is used here). */ 3927 if (removing) 3928 { 3929 STRCPY(newval, origval); 3930 if (*s) 3931 { 3932 /* may need to remove a comma */ 3933 if (flags & P_COMMA) 3934 { 3935 if (s == origval) 3936 { 3937 /* include comma after string */ 3938 if (s[i] == ',') 3939 ++i; 3940 } 3941 else 3942 { 3943 /* include comma before string */ 3944 --s; 3945 ++i; 3946 } 3947 } 3948 mch_memmove(newval + (s - origval), s + i, 3949 STRLEN(s + i) + 1); 3950 } 3951 } 3952 3953 if (flags & P_FLAGLIST) 3954 { 3955 /* Remove flags that appear twice. */ 3956 for (s = newval; *s; ++s) 3957 if ((!(flags & P_COMMA) || *s != ',') 3958 && vim_strchr(s + 1, *s) != NULL) 3959 { 3960 STRCPY(s, s + 1); 3961 --s; 3962 } 3963 } 3964 3965 if (save_arg != NULL) /* number for 'whichwrap' */ 3966 arg = save_arg; 3967 new_value_alloced = TRUE; 3968 } 3969 3970 /* Set the new value. */ 3971 *(char_u **)(varp) = newval; 3972 3973 /* Handle side effects, and set the global value for 3974 * ":set" on local options. */ 3975 errmsg = did_set_string_option(opt_idx, (char_u **)varp, 3976 new_value_alloced, oldval, errbuf, opt_flags); 3977 3978 /* If error detected, print the error message. */ 3979 if (errmsg != NULL) 3980 goto skip; 3981 } 3982 else /* key code option */ 3983 { 3984 char_u *p; 3985 3986 if (nextchar == '&') 3987 { 3988 if (add_termcap_entry(key_name, TRUE) == FAIL) 3989 errmsg = (char_u *)N_("E522: Not found in termcap"); 3990 } 3991 else 3992 { 3993 ++arg; /* jump to after the '=' or ':' */ 3994 for (p = arg; *p && !vim_iswhite(*p); ++p) 3995 if (*p == '\\' && p[1] != NUL) 3996 ++p; 3997 nextchar = *p; 3998 *p = NUL; 3999 add_termcode(key_name, arg, FALSE); 4000 *p = nextchar; 4001 } 4002 if (full_screen) 4003 ttest(FALSE); 4004 redraw_all_later(CLEAR); 4005 } 4006 } 4007 if (opt_idx >= 0) 4008 options[opt_idx].flags |= P_WAS_SET; 4009 } 4010 4011 skip: 4012 /* 4013 * Advance to next argument. 4014 * - skip until a blank found, taking care of backslashes 4015 * - skip blanks 4016 * - skip one "=val" argument (for hidden options ":set gfn =xx") 4017 */ 4018 for (i = 0; i < 2 ; ++i) 4019 { 4020 while (*arg != NUL && !vim_iswhite(*arg)) 4021 if (*arg++ == '\\' && *arg != NUL) 4022 ++arg; 4023 arg = skipwhite(arg); 4024 if (*arg != '=') 4025 break; 4026 } 4027 } 4028 4029 if (errmsg != NULL) 4030 { 4031 STRNCPY(IObuff, _(errmsg), IOSIZE - 1); 4032 IObuff[IOSIZE - 1] = NUL; 4033 i = STRLEN(IObuff) + 2; 4034 if (i + (arg - startarg) < IOSIZE) 4035 { 4036 /* append the argument with the error */ 4037 STRCAT(IObuff, ": "); 4038 mch_memmove(IObuff + i, startarg, (arg - startarg)); 4039 IObuff[i + (arg - startarg)] = NUL; 4040 } 4041 /* make sure all characters are printable */ 4042 trans_characters(IObuff, IOSIZE); 4043 4044 ++no_wait_return; /* wait_return done later */ 4045 emsg(IObuff); /* show error highlighted */ 4046 --no_wait_return; 4047 4048 return FAIL; 4049 } 4050 4051 arg = skipwhite(arg); 4052 } 4053 4054 return OK; 4055 } 4056 4057 static char_u * 4058 illegal_char(errbuf, c) 4059 char_u *errbuf; 4060 int c; 4061 { 4062 if (errbuf == NULL) 4063 return (char_u *)""; 4064 sprintf((char *)errbuf, _("E539: Illegal character <%s>"), 4065 (char *)transchar(c)); 4066 return errbuf; 4067 } 4068 4069 /* 4070 * Convert a key name or string into a key value. 4071 * Used for 'wildchar' and 'cedit' options. 4072 */ 4073 static int 4074 string_to_key(arg) 4075 char_u *arg; 4076 { 4077 if (*arg == '<') 4078 return find_key_option(arg + 1); 4079 if (*arg == '^') 4080 return Ctrl_chr(arg[1]); 4081 return *arg; 4082 } 4083 4084 #ifdef FEAT_CMDWIN 4085 /* 4086 * Check value of 'cedit' and set cedit_key. 4087 * Returns NULL if value is OK, error message otherwise. 4088 */ 4089 static char_u * 4090 check_cedit() 4091 { 4092 int n; 4093 4094 if (*p_cedit == NUL) 4095 cedit_key = -1; 4096 else 4097 { 4098 n = string_to_key(p_cedit); 4099 if (vim_isprintc(n)) 4100 return e_invarg; 4101 cedit_key = n; 4102 } 4103 return NULL; 4104 } 4105 #endif 4106 4107 #ifdef FEAT_TITLE 4108 /* 4109 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call 4110 * maketitle() to create and display it. 4111 * When switching the title or icon off, call mch_restore_title() to get 4112 * the old value back. 4113 */ 4114 static void 4115 did_set_title(icon) 4116 int icon; /* Did set icon instead of title */ 4117 { 4118 if (starting != NO_SCREEN 4119 #ifdef FEAT_GUI 4120 && !gui.starting 4121 #endif 4122 ) 4123 { 4124 maketitle(); 4125 if (icon) 4126 { 4127 if (!p_icon) 4128 mch_restore_title(2); 4129 } 4130 else 4131 { 4132 if (!p_title) 4133 mch_restore_title(1); 4134 } 4135 } 4136 } 4137 #endif 4138 4139 /* 4140 * set_options_bin - called when 'bin' changes value. 4141 */ 4142 void 4143 set_options_bin(oldval, newval, opt_flags) 4144 int oldval; 4145 int newval; 4146 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */ 4147 { 4148 /* 4149 * The option values that are changed when 'bin' changes are 4150 * copied when 'bin is set and restored when 'bin' is reset. 4151 */ 4152 if (newval) 4153 { 4154 if (!oldval) /* switched on */ 4155 { 4156 if (!(opt_flags & OPT_GLOBAL)) 4157 { 4158 curbuf->b_p_tw_nobin = curbuf->b_p_tw; 4159 curbuf->b_p_wm_nobin = curbuf->b_p_wm; 4160 curbuf->b_p_ml_nobin = curbuf->b_p_ml; 4161 curbuf->b_p_et_nobin = curbuf->b_p_et; 4162 } 4163 if (!(opt_flags & OPT_LOCAL)) 4164 { 4165 p_tw_nobin = p_tw; 4166 p_wm_nobin = p_wm; 4167 p_ml_nobin = p_ml; 4168 p_et_nobin = p_et; 4169 } 4170 } 4171 4172 if (!(opt_flags & OPT_GLOBAL)) 4173 { 4174 curbuf->b_p_tw = 0; /* no automatic line wrap */ 4175 curbuf->b_p_wm = 0; /* no automatic line wrap */ 4176 curbuf->b_p_ml = 0; /* no modelines */ 4177 curbuf->b_p_et = 0; /* no expandtab */ 4178 } 4179 if (!(opt_flags & OPT_LOCAL)) 4180 { 4181 p_tw = 0; 4182 p_wm = 0; 4183 p_ml = FALSE; 4184 p_et = FALSE; 4185 p_bin = TRUE; /* needed when called for the "-b" argument */ 4186 } 4187 } 4188 else if (oldval) /* switched off */ 4189 { 4190 if (!(opt_flags & OPT_GLOBAL)) 4191 { 4192 curbuf->b_p_tw = curbuf->b_p_tw_nobin; 4193 curbuf->b_p_wm = curbuf->b_p_wm_nobin; 4194 curbuf->b_p_ml = curbuf->b_p_ml_nobin; 4195 curbuf->b_p_et = curbuf->b_p_et_nobin; 4196 } 4197 if (!(opt_flags & OPT_LOCAL)) 4198 { 4199 p_tw = p_tw_nobin; 4200 p_wm = p_wm_nobin; 4201 p_ml = p_ml_nobin; 4202 p_et = p_et_nobin; 4203 } 4204 } 4205 } 4206 4207 #ifdef FEAT_VIMINFO 4208 /* 4209 * Find the parameter represented by the given character (eg ', :, ", or /), 4210 * and return its associated value in the 'viminfo' string. 4211 * Only works for number parameters, not for 'r' or 'n'. 4212 * If the parameter is not specified in the string, return -1. 4213 */ 4214 int 4215 get_viminfo_parameter(type) 4216 int type; 4217 { 4218 char_u *p; 4219 4220 p = find_viminfo_parameter(type); 4221 if (p != NULL && VIM_ISDIGIT(*p)) 4222 return atoi((char *)p); 4223 return -1; 4224 } 4225 4226 /* 4227 * Find the parameter represented by the given character (eg ''', ':', '"', or 4228 * '/') in the 'viminfo' option and return a pointer to the string after it. 4229 * Return NULL if the parameter is not specified in the string. 4230 */ 4231 char_u * 4232 find_viminfo_parameter(type) 4233 int type; 4234 { 4235 char_u *p; 4236 4237 for (p = p_viminfo; *p; ++p) 4238 { 4239 if (*p == type) 4240 return p + 1; 4241 if (*p == 'n') /* 'n' is always the last one */ 4242 break; 4243 p = vim_strchr(p, ','); /* skip until next ',' */ 4244 if (p == NULL) /* hit the end without finding parameter */ 4245 break; 4246 } 4247 return NULL; 4248 } 4249 #endif 4250 4251 /* 4252 * Expand environment variables for some string options. 4253 * These string options cannot be indirect! 4254 * If "val" is NULL expand the current value of the option. 4255 * Return pointer to NameBuff, or NULL when not expanded. 4256 */ 4257 static char_u * 4258 option_expand(opt_idx, val) 4259 int opt_idx; 4260 char_u *val; 4261 { 4262 /* if option doesn't need expansion nothing to do */ 4263 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) 4264 return NULL; 4265 4266 /* If val is longer than MAXPATHL no meaningful expansion can be done, 4267 * expand_env() would truncate the string. */ 4268 if (val != NULL && STRLEN(val) > MAXPATHL) 4269 return NULL; 4270 4271 if (val == NULL) 4272 val = *(char_u **)options[opt_idx].var; 4273 4274 /* 4275 * Expanding this with NameBuff, expand_env() must not be passed IObuff. 4276 * Escape spaces when expanding 'tags', they are used to separate file 4277 * names. 4278 */ 4279 expand_env_esc(val, NameBuff, MAXPATHL, 4280 (char_u **)options[opt_idx].var == &p_tags); 4281 if (STRCMP(NameBuff, val) == 0) /* they are the same */ 4282 return NULL; 4283 4284 return NameBuff; 4285 } 4286 4287 /* 4288 * After setting various option values: recompute variables that depend on 4289 * option values. 4290 */ 4291 static void 4292 didset_options() 4293 { 4294 /* initialize the table for 'iskeyword' et.al. */ 4295 (void)init_chartab(); 4296 4297 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE); 4298 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE); 4299 #ifdef FEAT_SESSION 4300 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE); 4301 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE); 4302 #endif 4303 #ifdef FEAT_FOLDING 4304 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE); 4305 #endif 4306 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE); 4307 #ifdef FEAT_VIRTUALEDIT 4308 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE); 4309 #endif 4310 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) 4311 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE); 4312 #endif 4313 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) 4314 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE); 4315 #endif 4316 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2) 4317 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE); 4318 #endif 4319 #ifdef FEAT_CMDWIN 4320 /* set cedit_key */ 4321 (void)check_cedit(); 4322 #endif 4323 } 4324 4325 /* 4326 * Check for string options that are NULL (normally only termcap options). 4327 */ 4328 void 4329 check_options() 4330 { 4331 int opt_idx; 4332 4333 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) 4334 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) 4335 check_string_option((char_u **)get_varp(&(options[opt_idx]))); 4336 } 4337 4338 /* 4339 * Check string options in a buffer for NULL value. 4340 */ 4341 void 4342 check_buf_options(buf) 4343 buf_T *buf; 4344 { 4345 #if defined(FEAT_QUICKFIX) 4346 check_string_option(&buf->b_p_bh); 4347 check_string_option(&buf->b_p_bt); 4348 #endif 4349 #ifdef FEAT_MBYTE 4350 check_string_option(&buf->b_p_fenc); 4351 #endif 4352 check_string_option(&buf->b_p_ff); 4353 #ifdef FEAT_FIND_ID 4354 check_string_option(&buf->b_p_def); 4355 check_string_option(&buf->b_p_inc); 4356 # ifdef FEAT_EVAL 4357 check_string_option(&buf->b_p_inex); 4358 # endif 4359 #endif 4360 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 4361 check_string_option(&buf->b_p_inde); 4362 check_string_option(&buf->b_p_indk); 4363 #endif 4364 #ifdef FEAT_CRYPT 4365 check_string_option(&buf->b_p_key); 4366 #endif 4367 check_string_option(&buf->b_p_kp); 4368 check_string_option(&buf->b_p_mps); 4369 check_string_option(&buf->b_p_fo); 4370 check_string_option(&buf->b_p_isk); 4371 #ifdef FEAT_COMMENTS 4372 check_string_option(&buf->b_p_com); 4373 #endif 4374 #ifdef FEAT_FOLDING 4375 check_string_option(&buf->b_p_cms); 4376 #endif 4377 check_string_option(&buf->b_p_nf); 4378 #ifdef FEAT_SYN_HL 4379 check_string_option(&buf->b_p_syn); 4380 #endif 4381 #ifdef FEAT_SEARCHPATH 4382 check_string_option(&buf->b_p_sua); 4383 #endif 4384 #ifdef FEAT_CINDENT 4385 check_string_option(&buf->b_p_cink); 4386 check_string_option(&buf->b_p_cino); 4387 #endif 4388 #ifdef FEAT_AUTOCMD 4389 check_string_option(&buf->b_p_ft); 4390 #endif 4391 #ifdef FEAT_OSFILETYPE 4392 check_string_option(&buf->b_p_oft); 4393 #endif 4394 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 4395 check_string_option(&buf->b_p_cinw); 4396 #endif 4397 #ifdef FEAT_INS_EXPAND 4398 check_string_option(&buf->b_p_cpt); 4399 #endif 4400 #ifdef FEAT_KEYMAP 4401 check_string_option(&buf->b_p_keymap); 4402 #endif 4403 #ifdef FEAT_QUICKFIX 4404 check_string_option(&buf->b_p_gp); 4405 check_string_option(&buf->b_p_mp); 4406 check_string_option(&buf->b_p_efm); 4407 #endif 4408 check_string_option(&buf->b_p_ep); 4409 check_string_option(&buf->b_p_path); 4410 check_string_option(&buf->b_p_tags); 4411 #ifdef FEAT_INS_EXPAND 4412 check_string_option(&buf->b_p_dict); 4413 check_string_option(&buf->b_p_tsr); 4414 #endif 4415 } 4416 4417 /* 4418 * Free the string allocated for an option. 4419 * Checks for the string being empty_option. This may happen if we're out of 4420 * memory, vim_strsave() returned NULL, which was replaced by empty_option by 4421 * check_options(). 4422 * Does NOT check for P_ALLOCED flag! 4423 */ 4424 void 4425 free_string_option(p) 4426 char_u *p; 4427 { 4428 if (p != empty_option) 4429 vim_free(p); 4430 } 4431 4432 void 4433 clear_string_option(pp) 4434 char_u **pp; 4435 { 4436 if (*pp != empty_option) 4437 vim_free(*pp); 4438 *pp = empty_option; 4439 } 4440 4441 static void 4442 check_string_option(pp) 4443 char_u **pp; 4444 { 4445 if (*pp == NULL) 4446 *pp = empty_option; 4447 } 4448 4449 /* 4450 * Mark a terminal option as allocated, found by a pointer into term_strings[]. 4451 */ 4452 void 4453 set_term_option_alloced(p) 4454 char_u **p; 4455 { 4456 int opt_idx; 4457 4458 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++) 4459 if (options[opt_idx].var == (char_u *)p) 4460 { 4461 options[opt_idx].flags |= P_ALLOCED; 4462 return; 4463 } 4464 return; /* cannot happen: didn't find it! */ 4465 } 4466 4467 /* 4468 * Set a string option to a new value (without checking the effect). 4469 * The string is copied into allocated memory. 4470 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used. 4471 */ 4472 void 4473 set_string_option_direct(name, opt_idx, val, opt_flags) 4474 char_u *name; 4475 int opt_idx; 4476 char_u *val; 4477 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ 4478 { 4479 char_u *s; 4480 char_u **varp; 4481 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; 4482 4483 if (opt_idx == -1) /* use name */ 4484 { 4485 opt_idx = findoption(name); 4486 if (opt_idx == -1) /* not found (should not happen) */ 4487 return; 4488 } 4489 4490 if (options[opt_idx].var == NULL) /* can't set hidden option */ 4491 return; 4492 4493 s = vim_strsave(val); 4494 if (s != NULL) 4495 { 4496 varp = (char_u **)get_varp_scope(&(options[opt_idx]), 4497 both ? OPT_LOCAL : opt_flags); 4498 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED)) 4499 free_string_option(*varp); 4500 *varp = s; 4501 4502 /* For buffer/window local option may also set the global value. */ 4503 if (both) 4504 set_string_option_global(opt_idx, varp); 4505 4506 options[opt_idx].flags |= P_ALLOCED; 4507 4508 /* When setting both values of a global option with a local value, 4509 * make the local value empty, so that the global value is used. */ 4510 if ((int)options[opt_idx].indir >= PV_BOTH && both) 4511 { 4512 free_string_option(*varp); 4513 *varp = empty_option; 4514 } 4515 } 4516 } 4517 4518 /* 4519 * Set global value for string option when it's a local option. 4520 */ 4521 static void 4522 set_string_option_global(opt_idx, varp) 4523 int opt_idx; /* option index */ 4524 char_u **varp; /* pointer to option variable */ 4525 { 4526 char_u **p, *s; 4527 4528 /* the global value is always allocated */ 4529 if (options[opt_idx].var == VAR_WIN) 4530 p = (char_u **)GLOBAL_WO(varp); 4531 else 4532 p = (char_u **)options[opt_idx].var; 4533 if (options[opt_idx].indir != PV_NONE 4534 && p != varp 4535 && (s = vim_strsave(*varp)) != NULL) 4536 { 4537 free_string_option(*p); 4538 *p = s; 4539 } 4540 } 4541 4542 /* 4543 * Set a string option to a new value, and handle the effects. 4544 */ 4545 static void 4546 set_string_option(opt_idx, value, opt_flags) 4547 int opt_idx; 4548 char_u *value; 4549 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */ 4550 { 4551 char_u *s; 4552 char_u **varp; 4553 char_u *oldval; 4554 4555 if (options[opt_idx].var == NULL) /* don't set hidden option */ 4556 return; 4557 4558 s = vim_strsave(value); 4559 if (s != NULL) 4560 { 4561 varp = (char_u **)get_varp_scope(&(options[opt_idx]), 4562 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 4563 ? ((int)options[opt_idx].indir >= PV_BOTH 4564 ? OPT_GLOBAL : OPT_LOCAL) 4565 : opt_flags); 4566 oldval = *varp; 4567 *varp = s; 4568 options[opt_idx].flags |= P_WAS_SET; 4569 (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, 4570 opt_flags); 4571 } 4572 } 4573 4574 /* 4575 * Handle string options that need some action to perform when changed. 4576 * Returns NULL for success, or an error message for an error. 4577 */ 4578 static char_u * 4579 did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf, 4580 opt_flags) 4581 int opt_idx; /* index in options[] table */ 4582 char_u **varp; /* pointer to the option variable */ 4583 int new_value_alloced; /* new value was allocated */ 4584 char_u *oldval; /* previous value of the option */ 4585 char_u *errbuf; /* buffer for errors, or NULL */ 4586 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */ 4587 { 4588 char_u *errmsg = NULL; 4589 char_u *s, *p; 4590 int did_chartab = FALSE; 4591 char_u **gvarp; 4592 4593 /* Get the global option to compare with, otherwise we would have to check 4594 * two values for all local options. */ 4595 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); 4596 4597 /* Disallow changing some options from secure mode */ 4598 if ((secure 4599 #ifdef HAVE_SANDBOX 4600 || sandbox != 0 4601 #endif 4602 ) && (options[opt_idx].flags & P_SECURE)) 4603 { 4604 errmsg = e_secure; 4605 } 4606 4607 /* 'term' */ 4608 else if (varp == &T_NAME) 4609 { 4610 if (T_NAME[0] == NUL) 4611 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string"); 4612 #ifdef FEAT_GUI 4613 if (gui.in_use) 4614 errmsg = (char_u *)N_("E530: Cannot change term in GUI"); 4615 else if (term_is_gui(T_NAME)) 4616 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI"); 4617 #endif 4618 else if (set_termname(T_NAME) == FAIL) 4619 errmsg = (char_u *)N_("E522: Not found in termcap"); 4620 else 4621 /* Screen colors may have changed. */ 4622 redraw_later_clear(); 4623 } 4624 4625 /* 'backupcopy' */ 4626 else if (varp == &p_bkc) 4627 { 4628 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK) 4629 errmsg = e_invarg; 4630 if (((bkc_flags & BKC_AUTO) != 0) 4631 + ((bkc_flags & BKC_YES) != 0) 4632 + ((bkc_flags & BKC_NO) != 0) != 1) 4633 { 4634 /* Must have exactly one of "auto", "yes" and "no". */ 4635 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE); 4636 errmsg = e_invarg; 4637 } 4638 } 4639 4640 /* 'backupext' and 'patchmode' */ 4641 else if (varp == &p_bex || varp == &p_pm) 4642 { 4643 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, 4644 *p_pm == '.' ? p_pm + 1 : p_pm) == 0) 4645 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal"); 4646 } 4647 4648 /* 4649 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[] 4650 * If the new option is invalid, use old value. 'lisp' option: refill 4651 * chartab[] for '-' char 4652 */ 4653 else if ( varp == &p_isi 4654 || varp == &(curbuf->b_p_isk) 4655 || varp == &p_isp 4656 || varp == &p_isf) 4657 { 4658 if (init_chartab() == FAIL) 4659 { 4660 did_chartab = TRUE; /* need to restore it below */ 4661 errmsg = e_invarg; /* error in value */ 4662 } 4663 } 4664 4665 /* 'helpfile' */ 4666 else if (varp == &p_hf) 4667 { 4668 /* May compute new values for $VIM and $VIMRUNTIME */ 4669 if (didset_vim) 4670 { 4671 vim_setenv((char_u *)"VIM", (char_u *)""); 4672 didset_vim = FALSE; 4673 } 4674 if (didset_vimruntime) 4675 { 4676 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)""); 4677 didset_vimruntime = FALSE; 4678 } 4679 } 4680 4681 #ifdef FEAT_MULTI_LANG 4682 /* 'helplang' */ 4683 else if (varp == &p_hlg) 4684 { 4685 /* Check for "", "ab", "ab,cd", etc. */ 4686 for (s = p_hlg; *s != NUL; s += 3) 4687 { 4688 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) 4689 { 4690 errmsg = e_invarg; 4691 break; 4692 } 4693 if (s[2] == NUL) 4694 break; 4695 } 4696 } 4697 #endif 4698 4699 /* 'highlight' */ 4700 else if (varp == &p_hl) 4701 { 4702 if (highlight_changed() == FAIL) 4703 errmsg = e_invarg; /* invalid flags */ 4704 } 4705 4706 /* 'nrformats' */ 4707 else if (gvarp == &p_nf) 4708 { 4709 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK) 4710 errmsg = e_invarg; 4711 } 4712 4713 #ifdef FEAT_SESSION 4714 /* 'sessionoptions' */ 4715 else if (varp == &p_ssop) 4716 { 4717 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK) 4718 errmsg = e_invarg; 4719 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) 4720 { 4721 /* Don't allow both "sesdir" and "curdir". */ 4722 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE); 4723 errmsg = e_invarg; 4724 } 4725 } 4726 /* 'viewoptions' */ 4727 else if (varp == &p_vop) 4728 { 4729 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK) 4730 errmsg = e_invarg; 4731 } 4732 #endif 4733 4734 /* 'scrollopt' */ 4735 #ifdef FEAT_SCROLLBIND 4736 else if (varp == &p_sbo) 4737 { 4738 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK) 4739 errmsg = e_invarg; 4740 } 4741 #endif 4742 4743 /* 'ambiwidth' */ 4744 #ifdef FEAT_MBYTE 4745 else if (varp == &p_ambw) 4746 { 4747 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) 4748 errmsg = e_invarg; 4749 } 4750 #endif 4751 4752 /* 'background' */ 4753 else if (varp == &p_bg) 4754 { 4755 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK) 4756 { 4757 #ifdef FEAT_EVAL 4758 int dark = (*p_bg == 'd'); 4759 #endif 4760 4761 init_highlight(FALSE, FALSE); 4762 4763 #ifdef FEAT_EVAL 4764 if (dark != (*p_bg == 'd') 4765 && get_var_value((char_u *)"g:colors_name") != NULL) 4766 { 4767 /* The color scheme must have set 'background' back to another 4768 * value, that's not what we want here. Disable the color 4769 * scheme and set the colors again. */ 4770 do_unlet((char_u *)"g:colors_name"); 4771 free_string_option(p_bg); 4772 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); 4773 check_string_option(&p_bg); 4774 init_highlight(FALSE, FALSE); 4775 } 4776 #endif 4777 } 4778 else 4779 errmsg = e_invarg; 4780 } 4781 4782 /* 'wildmode' */ 4783 else if (varp == &p_wim) 4784 { 4785 if (check_opt_wim() == FAIL) 4786 errmsg = e_invarg; 4787 } 4788 4789 #ifdef FEAT_WAK 4790 /* 'winaltkeys' */ 4791 else if (varp == &p_wak) 4792 { 4793 if (*p_wak == NUL 4794 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK) 4795 errmsg = e_invarg; 4796 # ifdef FEAT_MENU 4797 # ifdef FEAT_GUI_MOTIF 4798 else if (gui.in_use) 4799 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); 4800 # else 4801 # ifdef FEAT_GUI_GTK 4802 else if (gui.in_use) 4803 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); 4804 # endif 4805 # endif 4806 # endif 4807 } 4808 #endif 4809 4810 #ifdef FEAT_AUTOCMD 4811 /* 'eventignore' */ 4812 else if (varp == &p_ei) 4813 { 4814 if (check_ei() == FAIL) 4815 errmsg = e_invarg; 4816 } 4817 #endif 4818 4819 #ifdef FEAT_MBYTE 4820 /* 'encoding' and 'fileencoding' */ 4821 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc) 4822 { 4823 if (gvarp == &p_fenc) 4824 { 4825 if (!curbuf->b_p_ma) 4826 errmsg = e_modifiable; 4827 else if (vim_strchr(*varp, ',') != NULL) 4828 /* No comma allowed in 'fileencoding'; catches confusing it 4829 * with 'fileencodings'. */ 4830 errmsg = e_invarg; 4831 # ifdef FEAT_TITLE 4832 else 4833 /* May show a "+" in the title now. */ 4834 need_maketitle = TRUE; 4835 # endif 4836 } 4837 if (errmsg == NULL) 4838 { 4839 /* canonize the value, so that STRCMP() can be used on it */ 4840 p = enc_canonize(*varp); 4841 if (p != NULL) 4842 { 4843 vim_free(*varp); 4844 *varp = p; 4845 } 4846 if (varp == &p_enc) 4847 { 4848 errmsg = mb_init(); 4849 # ifdef FEAT_TITLE 4850 need_maketitle = TRUE; 4851 # endif 4852 } 4853 } 4854 4855 # if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2) 4856 if (errmsg == NULL && varp == &p_tenc && gui.in_use) 4857 { 4858 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */ 4859 if (STRCMP(p_tenc, "utf-8") != 0) 4860 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI"); 4861 } 4862 # endif 4863 4864 if (errmsg == NULL) 4865 { 4866 # ifdef FEAT_KEYMAP 4867 /* When 'keymap' is used and 'encoding' changes, reload the keymap 4868 * (with another encoding). */ 4869 if (varp == &p_enc && *curbuf->b_p_keymap != NUL) 4870 (void)keymap_init(); 4871 # endif 4872 4873 /* When 'termencoding' is not empty and 'encoding' changes or when 4874 * 'termencoding' changes, need to setup for keyboard input and 4875 * display output conversion. */ 4876 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc)) 4877 { 4878 convert_setup(&input_conv, p_tenc, p_enc); 4879 convert_setup(&output_conv, p_enc, p_tenc); 4880 } 4881 } 4882 } 4883 #endif 4884 4885 #if defined(FEAT_POSTSCRIPT) 4886 else if (varp == &p_penc) 4887 { 4888 /* Canonize printencoding if VIM standard one */ 4889 p = enc_canonize(p_penc); 4890 if (p != NULL) 4891 { 4892 vim_free(p_penc); 4893 p_penc = p; 4894 } 4895 else 4896 { 4897 /* Ensure lower case and '-' for '_' */ 4898 for (s = p_penc; *s != NUL; s++) 4899 { 4900 if (*s == '_') 4901 *s = '-'; 4902 else 4903 *s = TOLOWER_ASC(*s); 4904 } 4905 } 4906 } 4907 #endif 4908 4909 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) 4910 else if (varp == &p_imak) 4911 { 4912 if (gui.in_use && !im_xim_isvalid_imactivate()) 4913 errmsg = e_invarg; 4914 } 4915 #endif 4916 4917 #ifdef FEAT_KEYMAP 4918 else if (varp == &curbuf->b_p_keymap) 4919 { 4920 /* load or unload key mapping tables */ 4921 errmsg = keymap_init(); 4922 4923 /* When successfully installed a new keymap switch on using it. */ 4924 if (*curbuf->b_p_keymap != NUL && errmsg == NULL) 4925 { 4926 curbuf->b_p_iminsert = B_IMODE_LMAP; 4927 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) 4928 curbuf->b_p_imsearch = B_IMODE_LMAP; 4929 set_iminsert_global(); 4930 set_imsearch_global(); 4931 # ifdef FEAT_WINDOWS 4932 status_redraw_curbuf(); 4933 # endif 4934 } 4935 } 4936 #endif 4937 4938 /* 'fileformat' */ 4939 else if (gvarp == &p_ff) 4940 { 4941 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) 4942 errmsg = e_modifiable; 4943 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) 4944 errmsg = e_invarg; 4945 else 4946 { 4947 /* may also change 'textmode' */ 4948 if (get_fileformat(curbuf) == EOL_DOS) 4949 curbuf->b_p_tx = TRUE; 4950 else 4951 curbuf->b_p_tx = FALSE; 4952 #ifdef FEAT_TITLE 4953 need_maketitle = TRUE; 4954 #endif 4955 } 4956 } 4957 4958 /* 'fileformats' */ 4959 else if (varp == &p_ffs) 4960 { 4961 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) 4962 errmsg = e_invarg; 4963 else 4964 { 4965 /* also change 'textauto' */ 4966 if (*p_ffs == NUL) 4967 p_ta = FALSE; 4968 else 4969 p_ta = TRUE; 4970 } 4971 } 4972 4973 #if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST) 4974 /* 'cryptkey' */ 4975 else if (gvarp == &p_key) 4976 { 4977 /* Make sure the ":set" command doesn't show the new value in the 4978 * history. */ 4979 remove_key_from_history(); 4980 } 4981 #endif 4982 4983 /* 'matchpairs' */ 4984 else if (gvarp == &p_mps) 4985 { 4986 /* Check for "x:y,x:y" */ 4987 for (p = *varp; *p != NUL; p += 4) 4988 { 4989 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) 4990 { 4991 errmsg = e_invarg; 4992 break; 4993 } 4994 if (p[3] == NUL) 4995 break; 4996 } 4997 } 4998 4999 #ifdef FEAT_COMMENTS 5000 /* 'comments' */ 5001 else if (gvarp == &p_com) 5002 { 5003 for (s = *varp; *s; ) 5004 { 5005 while (*s && *s != ':') 5006 { 5007 if (vim_strchr((char_u *)COM_ALL, *s) == NULL 5008 && !VIM_ISDIGIT(*s) && *s != '-') 5009 { 5010 errmsg = illegal_char(errbuf, *s); 5011 break; 5012 } 5013 ++s; 5014 } 5015 if (*s++ == NUL) 5016 errmsg = (char_u *)N_("E524: Missing colon"); 5017 else if (*s == ',' || *s == NUL) 5018 errmsg = (char_u *)N_("E525: Zero length string"); 5019 if (errmsg != NULL) 5020 break; 5021 while (*s && *s != ',') 5022 { 5023 if (*s == '\\' && s[1] != NUL) 5024 ++s; 5025 ++s; 5026 } 5027 s = skip_to_option_part(s); 5028 } 5029 } 5030 #endif 5031 5032 /* 'listchars' */ 5033 else if (varp == &p_lcs) 5034 { 5035 errmsg = set_chars_option(varp); 5036 } 5037 5038 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING) 5039 /* 'fillchars' */ 5040 else if (varp == &p_fcs) 5041 { 5042 errmsg = set_chars_option(varp); 5043 } 5044 #endif 5045 5046 #ifdef FEAT_CMDWIN 5047 /* 'cedit' */ 5048 else if (varp == &p_cedit) 5049 { 5050 errmsg = check_cedit(); 5051 } 5052 #endif 5053 5054 #ifdef FEAT_VIMINFO 5055 /* 'viminfo' */ 5056 else if (varp == &p_viminfo) 5057 { 5058 for (s = p_viminfo; *s;) 5059 { 5060 /* Check it's a valid character */ 5061 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL) 5062 { 5063 errmsg = illegal_char(errbuf, *s); 5064 break; 5065 } 5066 if (*s == 'n') /* name is always last one */ 5067 { 5068 break; 5069 } 5070 else if (*s == 'r') /* skip until next ',' */ 5071 { 5072 while (*++s && *s != ',') 5073 ; 5074 } 5075 else if (*s == '%' || *s == '!' || *s == 'h' || *s == 'c') 5076 ++s; /* no extra chars */ 5077 else /* must have a number */ 5078 { 5079 while (vim_isdigit(*++s)) 5080 ; 5081 5082 if (!VIM_ISDIGIT(*(s - 1))) 5083 { 5084 if (errbuf != NULL) 5085 { 5086 sprintf((char *)errbuf, _("E526: Missing number after <%s>"), 5087 transchar_byte(*(s - 1))); 5088 errmsg = errbuf; 5089 } 5090 else 5091 errmsg = (char_u *)""; 5092 break; 5093 } 5094 } 5095 if (*s == ',') 5096 ++s; 5097 else if (*s) 5098 { 5099 if (errbuf != NULL) 5100 errmsg = (char_u *)N_("E527: Missing comma"); 5101 else 5102 errmsg = (char_u *)""; 5103 break; 5104 } 5105 } 5106 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0) 5107 errmsg = (char_u *)N_("E528: Must specify a ' value"); 5108 } 5109 #endif /* FEAT_VIMINFO */ 5110 5111 /* terminal options */ 5112 else if (istermoption(&options[opt_idx]) && full_screen) 5113 { 5114 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */ 5115 if (varp == &T_CCO) 5116 { 5117 t_colors = atoi((char *)T_CCO); 5118 if (t_colors <= 1) 5119 { 5120 if (new_value_alloced) 5121 vim_free(T_CCO); 5122 T_CCO = empty_option; 5123 } 5124 /* We now have a different color setup, initialize it again. */ 5125 init_highlight(TRUE, FALSE); 5126 } 5127 ttest(FALSE); 5128 if (varp == &T_ME) 5129 { 5130 out_str(T_ME); 5131 redraw_later(CLEAR); 5132 #if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32)) 5133 /* Since t_me has been set, this probably means that the user 5134 * wants to use this as default colors. Need to reset default 5135 * background/foreground colors. */ 5136 mch_set_normal_colors(); 5137 #endif 5138 } 5139 } 5140 5141 #ifdef FEAT_LINEBREAK 5142 /* 'showbreak' */ 5143 else if (varp == &p_sbr) 5144 { 5145 for (s = p_sbr; *s; ) 5146 { 5147 if (ptr2cells(s) != 1) 5148 errmsg = (char_u *)N_("E595: contains unprintable or wide character"); 5149 # ifdef FEAT_MBYTE 5150 if (has_mbyte) 5151 s += (*mb_ptr2len_check)(s); 5152 else 5153 # endif 5154 ++s; 5155 } 5156 } 5157 #endif 5158 5159 #ifdef FEAT_GUI 5160 /* 'guifont' */ 5161 else if (varp == &p_guifont) 5162 { 5163 if (gui.in_use) 5164 { 5165 p = p_guifont; 5166 # ifdef FEAT_GUI_GTK 5167 /* 5168 * Put up a font dialog and let the user select a new value. 5169 * If this is cancelled go back to the old value but don't 5170 * give an error message. 5171 */ 5172 if (STRCMP(p, "*") == 0) 5173 { 5174 p = gui_mch_font_dialog(oldval); 5175 5176 if (new_value_alloced) 5177 free_string_option(p_guifont); 5178 5179 p_guifont = (p != NULL) ? p : vim_strsave(oldval); 5180 new_value_alloced = TRUE; 5181 } 5182 # endif 5183 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK) 5184 { 5185 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON) 5186 if (STRCMP(p_guifont, "*") == 0) 5187 { 5188 /* Dialog was cancelled: Keep the old value without giving 5189 * an error message. */ 5190 if (new_value_alloced) 5191 free_string_option(p_guifont); 5192 p_guifont = vim_strsave(oldval); 5193 new_value_alloced = TRUE; 5194 } 5195 else 5196 # endif 5197 errmsg = (char_u *)N_("E596: Invalid font(s)"); 5198 } 5199 } 5200 } 5201 # ifdef FEAT_XFONTSET 5202 else if (varp == &p_guifontset) 5203 { 5204 if (STRCMP(p_guifontset, "*") == 0) 5205 errmsg = (char_u *)N_("E597: can't select fontset"); 5206 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK) 5207 errmsg = (char_u *)N_("E598: Invalid fontset"); 5208 } 5209 # endif 5210 # ifdef FEAT_MBYTE 5211 else if (varp == &p_guifontwide) 5212 { 5213 if (STRCMP(p_guifontwide, "*") == 0) 5214 errmsg = (char_u *)N_("E533: can't select wide font"); 5215 else if (gui_get_wide_font() == FAIL) 5216 errmsg = (char_u *)N_("E534: Invalid wide font"); 5217 } 5218 # endif 5219 #endif 5220 5221 #ifdef CURSOR_SHAPE 5222 /* 'guicursor' */ 5223 else if (varp == &p_guicursor) 5224 errmsg = parse_shape_opt(SHAPE_CURSOR); 5225 #endif 5226 5227 #ifdef FEAT_MOUSESHAPE 5228 /* 'mouseshape' */ 5229 else if (varp == &p_mouseshape) 5230 { 5231 errmsg = parse_shape_opt(SHAPE_MOUSE); 5232 update_mouseshape(-1); 5233 } 5234 #endif 5235 5236 #ifdef FEAT_PRINTER 5237 else if (varp == &p_popt) 5238 errmsg = parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS); 5239 #endif 5240 5241 #ifdef FEAT_LANGMAP 5242 /* 'langmap' */ 5243 else if (varp == &p_langmap) 5244 langmap_set(); 5245 #endif 5246 5247 #ifdef FEAT_LINEBREAK 5248 /* 'breakat' */ 5249 else if (varp == &p_breakat) 5250 fill_breakat_flags(); 5251 #endif 5252 5253 #ifdef FEAT_TITLE 5254 /* 'titlestring' and 'iconstring' */ 5255 else if (varp == &p_titlestring || varp == &p_iconstring) 5256 { 5257 # ifdef FEAT_STL_OPT 5258 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON; 5259 5260 /* NULL => statusline syntax */ 5261 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL) 5262 stl_syntax |= flagval; 5263 else 5264 stl_syntax &= ~flagval; 5265 # endif 5266 did_set_title(varp == &p_iconstring); 5267 5268 } 5269 #endif 5270 5271 #ifdef FEAT_GUI 5272 /* 'guioptions' */ 5273 else if (varp == &p_go) 5274 gui_init_which_components(oldval); 5275 #endif 5276 5277 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS)) 5278 /* 'ttymouse' */ 5279 else if (varp == &p_ttym) 5280 { 5281 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK) 5282 errmsg = e_invarg; 5283 else 5284 check_mouse_termcode(); 5285 } 5286 #endif 5287 5288 #ifdef FEAT_VISUAL 5289 /* 'selection' */ 5290 else if (varp == &p_sel) 5291 { 5292 if (*p_sel == NUL 5293 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK) 5294 errmsg = e_invarg; 5295 } 5296 5297 /* 'selectmode' */ 5298 else if (varp == &p_slm) 5299 { 5300 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK) 5301 errmsg = e_invarg; 5302 } 5303 #endif 5304 5305 #ifdef FEAT_BROWSE 5306 /* 'browsedir' */ 5307 else if (varp == &p_bsdir) 5308 { 5309 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK 5310 && !mch_isdir(p_bsdir)) 5311 errmsg = e_invarg; 5312 } 5313 #endif 5314 5315 #ifdef FEAT_VISUAL 5316 /* 'keymodel' */ 5317 else if (varp == &p_km) 5318 { 5319 if (check_opt_strings(p_km, p_km_values, TRUE) != OK) 5320 errmsg = e_invarg; 5321 else 5322 { 5323 km_stopsel = (vim_strchr(p_km, 'o') != NULL); 5324 km_startsel = (vim_strchr(p_km, 'a') != NULL); 5325 } 5326 } 5327 #endif 5328 5329 /* 'mousemodel' */ 5330 else if (varp == &p_mousem) 5331 { 5332 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK) 5333 errmsg = e_invarg; 5334 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002) 5335 else if (*p_mousem != *oldval) 5336 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need 5337 * to create or delete the popup menus. */ 5338 gui_motif_update_mousemodel(root_menu); 5339 #endif 5340 } 5341 5342 /* 'switchbuf' */ 5343 else if (varp == &p_swb) 5344 { 5345 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK) 5346 errmsg = e_invarg; 5347 } 5348 5349 /* 'debug' */ 5350 else if (varp == &p_debug) 5351 { 5352 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK) 5353 errmsg = e_invarg; 5354 } 5355 5356 /* 'display' */ 5357 else if (varp == &p_dy) 5358 { 5359 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK) 5360 errmsg = e_invarg; 5361 else 5362 (void)init_chartab(); 5363 5364 } 5365 5366 #ifdef FEAT_VERTSPLIT 5367 /* 'eadirection' */ 5368 else if (varp == &p_ead) 5369 { 5370 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK) 5371 errmsg = e_invarg; 5372 } 5373 #endif 5374 5375 #ifdef FEAT_CLIPBOARD 5376 /* 'clipboard' */ 5377 else if (varp == &p_cb) 5378 errmsg = check_clipboard_option(); 5379 #endif 5380 5381 #ifdef FEAT_AUTOCMD 5382 # ifdef FEAT_SYN_HL 5383 /* When 'syntax' is set, load the syntax of that name */ 5384 else if (varp == &(curbuf->b_p_syn)) 5385 { 5386 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, 5387 curbuf->b_fname, TRUE, curbuf); 5388 } 5389 # endif 5390 5391 /* When 'filetype' is set, trigger the FileType autocommands of that name */ 5392 else if (varp == &(curbuf->b_p_ft)) 5393 { 5394 did_filetype = TRUE; 5395 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, 5396 curbuf->b_fname, TRUE, curbuf); 5397 } 5398 #endif 5399 5400 #ifdef FEAT_QUICKFIX 5401 /* When 'bufhidden' is set, check for valid value. */ 5402 else if (gvarp == &p_bh) 5403 { 5404 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK) 5405 errmsg = e_invarg; 5406 } 5407 5408 /* When 'buftype' is set, check for valid value. */ 5409 else if (gvarp == &p_bt) 5410 { 5411 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK) 5412 errmsg = e_invarg; 5413 else 5414 { 5415 # ifdef FEAT_WINDOWS 5416 if (curwin->w_status_height) 5417 { 5418 curwin->w_redr_status = TRUE; 5419 redraw_later(VALID); 5420 } 5421 # endif 5422 curbuf->b_help = (curbuf->b_p_bt[0] == 'h'); 5423 } 5424 } 5425 #endif 5426 5427 #ifdef FEAT_STL_OPT 5428 /* 'statusline' or 'rulerformat' */ 5429 else if (varp == &p_stl || varp == &p_ruf) 5430 { 5431 int wid; 5432 5433 if (varp == &p_ruf) /* reset ru_wid first */ 5434 ru_wid = 0; 5435 s = *varp; 5436 if (varp == &p_ruf && *s == '%') 5437 { 5438 /* set ru_wid if 'ruf' starts with "%99(" */ 5439 if (*++s == '-') /* ignore a '-' */ 5440 s++; 5441 wid = getdigits(&s); 5442 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) 5443 ru_wid = wid; 5444 else 5445 errmsg = check_stl_option(p_ruf); 5446 } 5447 else 5448 errmsg = check_stl_option(s); 5449 if (varp == &(p_ruf) && errmsg == NULL) 5450 comp_col(); 5451 } 5452 #endif 5453 5454 #ifdef FEAT_INS_EXPAND 5455 /* check if it is a valid value for 'complete' -- Acevedo */ 5456 else if (gvarp == &p_cpt) 5457 { 5458 for (s = *varp; *s;) 5459 { 5460 while(*s == ',' || *s == ' ') 5461 s++; 5462 if (!*s) 5463 break; 5464 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL) 5465 { 5466 errmsg = illegal_char(errbuf, *s); 5467 break; 5468 } 5469 if (*++s != NUL && *s != ',' && *s != ' ') 5470 { 5471 if (s[-1] == 'k' || s[-1] == 's') 5472 { 5473 /* skip optional filename after 'k' and 's' */ 5474 while (*s && *s != ',' && *s != ' ') 5475 { 5476 if (*s == '\\') 5477 ++s; 5478 ++s; 5479 } 5480 } 5481 else 5482 { 5483 if (errbuf != NULL) 5484 { 5485 sprintf((char *)errbuf, 5486 _("E535: Illegal character after <%c>"), 5487 *--s); 5488 errmsg = errbuf; 5489 } 5490 else 5491 errmsg = (char_u *)""; 5492 break; 5493 } 5494 } 5495 } 5496 } 5497 #endif /* FEAT_INS_EXPAND */ 5498 5499 5500 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) 5501 else if (varp == &p_toolbar) 5502 { 5503 if (opt_strings_flags(p_toolbar, p_toolbar_values, 5504 &toolbar_flags, TRUE) != OK) 5505 errmsg = e_invarg; 5506 else 5507 { 5508 out_flush(); 5509 gui_mch_show_toolbar((toolbar_flags & 5510 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); 5511 } 5512 } 5513 #endif 5514 5515 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2) 5516 /* 'toolbariconsize': GTK+ 2 only */ 5517 else if (varp == &p_tbis) 5518 { 5519 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK) 5520 errmsg = e_invarg; 5521 else 5522 { 5523 out_flush(); 5524 gui_mch_show_toolbar((toolbar_flags & 5525 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); 5526 } 5527 } 5528 #endif 5529 5530 /* 'pastetoggle': translate key codes like in a mapping */ 5531 else if (varp == &p_pt) 5532 { 5533 if (*p_pt) 5534 { 5535 (void)replace_termcodes(p_pt, &p, TRUE, TRUE); 5536 if (p != NULL) 5537 { 5538 if (new_value_alloced) 5539 free_string_option(p_pt); 5540 p_pt = p; 5541 new_value_alloced = TRUE; 5542 } 5543 } 5544 } 5545 5546 /* 'backspace' */ 5547 else if (varp == &p_bs) 5548 { 5549 if (VIM_ISDIGIT(*p_bs)) 5550 { 5551 if (*p_bs >'2' || p_bs[1] != NUL) 5552 errmsg = e_invarg; 5553 } 5554 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK) 5555 errmsg = e_invarg; 5556 } 5557 5558 /* 'casemap' */ 5559 else if (varp == &p_cmp) 5560 { 5561 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK) 5562 errmsg = e_invarg; 5563 } 5564 5565 #ifdef FEAT_DIFF 5566 /* 'diffopt' */ 5567 else if (varp == &p_dip) 5568 { 5569 if (diffopt_changed() == FAIL) 5570 errmsg = e_invarg; 5571 } 5572 #endif 5573 5574 #ifdef FEAT_FOLDING 5575 /* 'foldmethod' */ 5576 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) 5577 { 5578 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK 5579 || *curwin->w_p_fdm == NUL) 5580 errmsg = e_invarg; 5581 else 5582 foldUpdateAll(curwin); 5583 } 5584 # ifdef FEAT_EVAL 5585 /* 'foldexpr' */ 5586 else if (varp == &curwin->w_p_fde) 5587 { 5588 if (foldmethodIsExpr(curwin)) 5589 foldUpdateAll(curwin); 5590 } 5591 # endif 5592 /* 'foldmarker' */ 5593 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) 5594 { 5595 p = vim_strchr(*varp, ','); 5596 if (p == NULL) 5597 errmsg = (char_u *)N_("E536: comma required"); 5598 else if (p == *varp || p[1] == NUL) 5599 errmsg = e_invarg; 5600 else if (foldmethodIsMarker(curwin)) 5601 foldUpdateAll(curwin); 5602 } 5603 /* 'commentstring' */ 5604 else if (gvarp == &p_cms) 5605 { 5606 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL) 5607 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s"); 5608 } 5609 /* 'foldopen' */ 5610 else if (varp == &p_fdo) 5611 { 5612 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK) 5613 errmsg = e_invarg; 5614 } 5615 /* 'foldclose' */ 5616 else if (varp == &p_fcl) 5617 { 5618 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK) 5619 errmsg = e_invarg; 5620 } 5621 #endif 5622 5623 #ifdef FEAT_VIRTUALEDIT 5624 /* 'virtualedit' */ 5625 else if (varp == &p_ve) 5626 { 5627 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK) 5628 errmsg = e_invarg; 5629 else if (STRCMP(p_ve, oldval) != 0) 5630 { 5631 /* Recompute cursor position in case the new 've' setting 5632 * changes something. */ 5633 validate_virtcol(); 5634 coladvance(curwin->w_virtcol); 5635 } 5636 } 5637 #endif 5638 5639 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX) 5640 else if (varp == &p_csqf) 5641 { 5642 if (p_csqf != NULL) 5643 { 5644 p = p_csqf; 5645 while (*p != NUL) 5646 { 5647 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL 5648 || p[1] == NUL 5649 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL 5650 || (p[2] != NUL && p[2] != ',')) 5651 { 5652 errmsg = e_invarg; 5653 break; 5654 } 5655 else if (p[2] == NUL) 5656 break; 5657 else 5658 p += 3; 5659 } 5660 } 5661 } 5662 #endif 5663 5664 /* Options that are a list of flags. */ 5665 else 5666 { 5667 p = NULL; 5668 if (varp == &p_ww) 5669 p = (char_u *)WW_ALL; 5670 if (varp == &p_shm) 5671 p = (char_u *)SHM_ALL; 5672 else if (varp == &(p_cpo)) 5673 p = (char_u *)CPO_ALL; 5674 else if (varp == &(curbuf->b_p_fo)) 5675 p = (char_u *)FO_ALL; 5676 else if (varp == &p_mouse) 5677 { 5678 #ifdef FEAT_MOUSE 5679 p = (char_u *)MOUSE_ALL; 5680 #else 5681 if (*p_mouse != NUL) 5682 errmsg = (char_u *)N_("E538: No mouse support"); 5683 #endif 5684 } 5685 #if defined(FEAT_GUI) 5686 else if (varp == &p_go) 5687 p = (char_u *)GO_ALL; 5688 #endif 5689 if (p != NULL) 5690 { 5691 for (s = *varp; *s; ++s) 5692 if (vim_strchr(p, *s) == NULL) 5693 { 5694 errmsg = illegal_char(errbuf, *s); 5695 break; 5696 } 5697 } 5698 } 5699 5700 /* 5701 * If error detected, restore the previous value. 5702 */ 5703 if (errmsg != NULL) 5704 { 5705 if (new_value_alloced) 5706 free_string_option(*varp); 5707 *varp = oldval; 5708 /* 5709 * When resetting some values, need to act on it. 5710 */ 5711 if (did_chartab) 5712 (void)init_chartab(); 5713 if (varp == &p_hl) 5714 (void)highlight_changed(); 5715 } 5716 else 5717 { 5718 #ifdef FEAT_EVAL 5719 /* Remember where the option was set. */ 5720 options[opt_idx].scriptID = current_SID; 5721 #endif 5722 /* 5723 * Free string options that are in allocated memory. 5724 */ 5725 if (options[opt_idx].flags & P_ALLOCED) 5726 free_string_option(oldval); 5727 if (new_value_alloced) 5728 options[opt_idx].flags |= P_ALLOCED; 5729 else 5730 options[opt_idx].flags &= ~P_ALLOCED; 5731 5732 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 5733 && (int)options[opt_idx].indir >= PV_BOTH) 5734 { 5735 /* global option with local value set to use global value; free 5736 * the local value and make it empty */ 5737 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL); 5738 free_string_option(*(char_u **)p); 5739 *(char_u **)p = empty_option; 5740 } 5741 5742 /* May set global value for local option. */ 5743 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL) 5744 set_string_option_global(opt_idx, varp); 5745 } 5746 5747 #ifdef FEAT_MOUSE 5748 if (varp == &p_mouse) 5749 { 5750 # ifdef FEAT_MOUSE_TTY 5751 if (*p_mouse == NUL) 5752 mch_setmouse(FALSE); /* switch mouse off */ 5753 else 5754 # endif 5755 setmouse(); /* in case 'mouse' changed */ 5756 } 5757 #endif 5758 5759 if (curwin->w_curswant != MAXCOL) 5760 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */ 5761 check_redraw(options[opt_idx].flags); 5762 5763 return errmsg; 5764 } 5765 5766 /* 5767 * Handle setting 'listchars' or 'fillchars'. 5768 * Returns error message, NULL if it's OK. 5769 */ 5770 static char_u * 5771 set_chars_option(varp) 5772 char_u **varp; 5773 { 5774 int round, i, len, entries; 5775 char_u *p, *s; 5776 int c1, c2 = 0; 5777 struct charstab 5778 { 5779 int *cp; 5780 char *name; 5781 }; 5782 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING) 5783 static struct charstab filltab[] = 5784 { 5785 {&fill_stl, "stl"}, 5786 {&fill_stlnc, "stlnc"}, 5787 {&fill_vert, "vert"}, 5788 {&fill_fold, "fold"}, 5789 {&fill_diff, "diff"}, 5790 }; 5791 #endif 5792 static struct charstab lcstab[] = 5793 { 5794 {&lcs_eol, "eol"}, 5795 {&lcs_ext, "extends"}, 5796 {&lcs_prec, "precedes"}, 5797 {&lcs_tab2, "tab"}, 5798 {&lcs_trail, "trail"}, 5799 }; 5800 struct charstab *tab; 5801 5802 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING) 5803 if (varp == &p_lcs) 5804 #endif 5805 { 5806 tab = lcstab; 5807 entries = sizeof(lcstab) / sizeof(struct charstab); 5808 } 5809 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING) 5810 else 5811 { 5812 tab = filltab; 5813 entries = sizeof(filltab) / sizeof(struct charstab); 5814 } 5815 #endif 5816 5817 /* first round: check for valid value, second round: assign values */ 5818 for (round = 0; round <= 1; ++round) 5819 { 5820 if (round) 5821 { 5822 /* After checking that the value is valid: set defaults: space for 5823 * 'fillchars', NUL for 'listchars' */ 5824 for (i = 0; i < entries; ++i) 5825 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' '); 5826 if (varp == &p_lcs) 5827 lcs_tab1 = NUL; 5828 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING) 5829 else 5830 fill_diff = '-'; 5831 #endif 5832 } 5833 p = *varp; 5834 while (*p) 5835 { 5836 for (i = 0; i < entries; ++i) 5837 { 5838 len = (int)STRLEN(tab[i].name); 5839 if (STRNCMP(p, tab[i].name, len) == 0 5840 && p[len] == ':' 5841 && p[len + 1] != NUL) 5842 { 5843 s = p + len + 1; 5844 #ifdef FEAT_MBYTE 5845 c1 = mb_ptr2char_adv(&s); 5846 #else 5847 c1 = *s++; 5848 #endif 5849 if (tab[i].cp == &lcs_tab2) 5850 { 5851 if (*s == NUL) 5852 continue; 5853 #ifdef FEAT_MBYTE 5854 c2 = mb_ptr2char_adv(&s); 5855 #else 5856 c2 = *s++; 5857 #endif 5858 } 5859 if (*s == ',' || *s == NUL) 5860 { 5861 if (round) 5862 { 5863 if (tab[i].cp == &lcs_tab2) 5864 { 5865 lcs_tab1 = c1; 5866 lcs_tab2 = c2; 5867 } 5868 else 5869 *(tab[i].cp) = c1; 5870 5871 } 5872 p = s; 5873 break; 5874 } 5875 } 5876 } 5877 5878 if (i == entries) 5879 return e_invarg; 5880 if (*p == ',') 5881 ++p; 5882 } 5883 } 5884 5885 return NULL; /* no error */ 5886 } 5887 5888 #ifdef FEAT_STL_OPT 5889 /* 5890 * Check validity of options with the 'statusline' format. 5891 * Return error message or NULL. 5892 */ 5893 char_u * 5894 check_stl_option(s) 5895 char_u *s; 5896 { 5897 int itemcnt = 0; 5898 int groupdepth = 0; 5899 static char_u errbuf[80]; 5900 5901 while (*s && itemcnt < STL_MAX_ITEM) 5902 { 5903 /* Check for valid keys after % sequences */ 5904 while (*s && *s != '%') 5905 s++; 5906 if (!*s) 5907 break; 5908 s++; 5909 if (*s != '%' && *s != ')') 5910 ++itemcnt; 5911 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK) 5912 { 5913 s++; 5914 continue; 5915 } 5916 if (*s == ')') 5917 { 5918 s++; 5919 if (--groupdepth < 0) 5920 break; 5921 continue; 5922 } 5923 if (*s == '-') 5924 s++; 5925 while (VIM_ISDIGIT(*s)) 5926 s++; 5927 if (*s == STL_HIGHLIGHT) 5928 continue; 5929 if (*s == '.') 5930 { 5931 s++; 5932 while (*s && VIM_ISDIGIT(*s)) 5933 s++; 5934 } 5935 if (*s == '(') 5936 { 5937 groupdepth++; 5938 continue; 5939 } 5940 if (vim_strchr(STL_ALL, *s) == NULL) 5941 { 5942 return illegal_char(errbuf, *s); 5943 } 5944 if (*s == '{') 5945 { 5946 s++; 5947 while (*s != '}' && *s) 5948 s++; 5949 if (*s != '}') 5950 return (char_u *)N_("E540: Unclosed expression sequence"); 5951 } 5952 } 5953 if (itemcnt >= STL_MAX_ITEM) 5954 return (char_u *)N_("E541: too many items"); 5955 if (groupdepth != 0) 5956 return (char_u *)N_("E542: unbalanced groups"); 5957 return NULL; 5958 } 5959 #endif 5960 5961 #ifdef FEAT_CLIPBOARD 5962 /* 5963 * Extract the items in the 'clipboard' option and set global values. 5964 */ 5965 static char_u * 5966 check_clipboard_option() 5967 { 5968 int new_unnamed = FALSE; 5969 int new_autoselect = FALSE; 5970 int new_autoselectml = FALSE; 5971 regprog_T *new_exclude_prog = NULL; 5972 char_u *errmsg = NULL; 5973 char_u *p; 5974 5975 for (p = p_cb; *p != NUL; ) 5976 { 5977 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL)) 5978 { 5979 new_unnamed = TRUE; 5980 p += 7; 5981 } 5982 else if (STRNCMP(p, "autoselect", 10) == 0 5983 && (p[10] == ',' || p[10] == NUL)) 5984 { 5985 new_autoselect = TRUE; 5986 p += 10; 5987 } 5988 else if (STRNCMP(p, "autoselectml", 12) == 0 5989 && (p[12] == ',' || p[12] == NUL)) 5990 { 5991 new_autoselectml = TRUE; 5992 p += 12; 5993 } 5994 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL) 5995 { 5996 p += 8; 5997 new_exclude_prog = vim_regcomp(p, RE_MAGIC); 5998 if (new_exclude_prog == NULL) 5999 errmsg = e_invarg; 6000 break; 6001 } 6002 else 6003 { 6004 errmsg = e_invarg; 6005 break; 6006 } 6007 if (*p == ',') 6008 ++p; 6009 } 6010 if (errmsg == NULL) 6011 { 6012 clip_unnamed = new_unnamed; 6013 clip_autoselect = new_autoselect; 6014 clip_autoselectml = new_autoselectml; 6015 vim_free(clip_exclude_prog); 6016 clip_exclude_prog = new_exclude_prog; 6017 } 6018 else 6019 vim_free(new_exclude_prog); 6020 6021 return errmsg; 6022 } 6023 #endif 6024 6025 /* 6026 * Set the value of a boolean option, and take care of side effects. 6027 * Returns NULL for success, or an error message for an error. 6028 */ 6029 static char_u * 6030 set_bool_option(opt_idx, varp, value, opt_flags) 6031 int opt_idx; /* index in options[] table */ 6032 char_u *varp; /* pointer to the option variable */ 6033 int value; /* new value */ 6034 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */ 6035 { 6036 int old_value = *(int *)varp; 6037 6038 #ifdef FEAT_GUI 6039 need_mouse_correct = TRUE; 6040 #endif 6041 6042 /* Disallow changing some options from secure mode */ 6043 if ((secure 6044 #ifdef HAVE_SANDBOX 6045 || sandbox != 0 6046 #endif 6047 ) && (options[opt_idx].flags & P_SECURE)) 6048 return e_secure; 6049 6050 *(int *)varp = value; /* set the new value */ 6051 #ifdef FEAT_EVAL 6052 /* Remember where the option was set. */ 6053 options[opt_idx].scriptID = current_SID; 6054 #endif 6055 6056 /* May set global value for local option. */ 6057 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) 6058 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; 6059 6060 /* 6061 * Handle side effects of changing a bool option. 6062 */ 6063 6064 /* 'compatible' */ 6065 if ((int *)varp == &p_cp) 6066 { 6067 compatible_set(); 6068 } 6069 6070 /* when 'readonly' is reset globally, also reset readonlymode */ 6071 else if ((int *)varp == &curbuf->b_p_ro) 6072 { 6073 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0) 6074 readonlymode = FALSE; 6075 #ifdef FEAT_TITLE 6076 need_maketitle = TRUE; 6077 #endif 6078 } 6079 6080 #ifdef FEAT_TITLE 6081 /* when 'modifiable' is changed, redraw the window title */ 6082 else if ((int *)varp == &curbuf->b_p_ma) 6083 need_maketitle = TRUE; 6084 /* when 'endofline' is changed, redraw the window title */ 6085 else if ((int *)varp == &curbuf->b_p_eol) 6086 need_maketitle = TRUE; 6087 #endif 6088 6089 /* when 'bin' is set also set some other options */ 6090 else if ((int *)varp == &curbuf->b_p_bin) 6091 { 6092 set_options_bin(old_value, curbuf->b_p_bin, opt_flags); 6093 #ifdef FEAT_TITLE 6094 need_maketitle = TRUE; 6095 #endif 6096 } 6097 6098 #ifdef FEAT_AUTOCMD 6099 /* when 'buflisted' changes, trigger autocommands */ 6100 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl) 6101 { 6102 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE, 6103 NULL, NULL, TRUE, curbuf); 6104 } 6105 #endif 6106 6107 /* when 'swf' is set, create swapfile, when reset remove swapfile */ 6108 else if ((int *)varp == &curbuf->b_p_swf) 6109 { 6110 if (curbuf->b_p_swf && p_uc) 6111 ml_open_file(curbuf); /* create the swap file */ 6112 else 6113 mf_close_file(curbuf, TRUE); /* remove the swap file */ 6114 } 6115 6116 /* when 'terse' is set change 'shortmess' */ 6117 else if ((int *)varp == &p_terse) 6118 { 6119 char_u *p; 6120 6121 p = vim_strchr(p_shm, SHM_SEARCH); 6122 6123 /* insert 's' in p_shm */ 6124 if (p_terse && p == NULL) 6125 { 6126 STRCPY(IObuff, p_shm); 6127 STRCAT(IObuff, "s"); 6128 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE); 6129 } 6130 /* remove 's' from p_shm */ 6131 else if (!p_terse && p != NULL) 6132 mch_memmove(p, p + 1, STRLEN(p)); 6133 } 6134 6135 /* when 'paste' is set or reset also change other options */ 6136 else if ((int *)varp == &p_paste) 6137 { 6138 paste_option_changed(); 6139 } 6140 6141 /* when 'insertmode' is set from an autocommand need to do work here */ 6142 else if ((int *)varp == &p_im) 6143 { 6144 if (p_im) 6145 { 6146 if ((State & INSERT) == 0) 6147 need_start_insertmode = TRUE; 6148 stop_insert_mode = FALSE; 6149 } 6150 else 6151 { 6152 need_start_insertmode = FALSE; 6153 stop_insert_mode = TRUE; 6154 if (p_smd && restart_edit != 0) 6155 clear_cmdline = TRUE; /* remove "(insert)" */ 6156 restart_edit = 0; 6157 } 6158 } 6159 6160 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */ 6161 else if ((int *)varp == &p_ic && p_hls) 6162 { 6163 redraw_all_later(NOT_VALID); 6164 } 6165 6166 #ifdef FEAT_SEARCH_EXTRA 6167 /* when 'hlsearch' is set or reset: reset no_hlsearch */ 6168 else if ((int *)varp == &p_hls) 6169 { 6170 no_hlsearch = FALSE; 6171 } 6172 #endif 6173 6174 #ifdef FEAT_SCROLLBIND 6175 /* when 'scrollbind' is set: snapshot the current position to avoid a jump 6176 * at the end of normal_cmd() */ 6177 else if ((int *)varp == &curwin->w_p_scb) 6178 { 6179 if (curwin->w_p_scb) 6180 do_check_scrollbind(FALSE); 6181 } 6182 #endif 6183 6184 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) 6185 /* There can be only one window with 'previewwindow' set. */ 6186 else if ((int *)varp == &curwin->w_p_pvw) 6187 { 6188 if (curwin->w_p_pvw) 6189 { 6190 win_T *win; 6191 6192 for (win = firstwin; win != NULL; win = win->w_next) 6193 if (win->w_p_pvw && win != curwin) 6194 { 6195 curwin->w_p_pvw = FALSE; 6196 return (char_u *)N_("E590: A preview window already exists"); 6197 } 6198 } 6199 } 6200 #endif 6201 6202 /* when 'textmode' is set or reset also change 'fileformat' */ 6203 else if ((int *)varp == &curbuf->b_p_tx) 6204 { 6205 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags); 6206 } 6207 6208 /* when 'textauto' is set or reset also change 'fileformats' */ 6209 else if ((int *)varp == &p_ta) 6210 { 6211 set_string_option_direct((char_u *)"ffs", -1, 6212 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"", 6213 OPT_FREE | opt_flags); 6214 } 6215 6216 /* 6217 * When 'lisp' option changes include/exclude '-' in 6218 * keyword characters. 6219 */ 6220 #ifdef FEAT_LISP 6221 else if (varp == (char_u *)&(curbuf->b_p_lisp)) 6222 { 6223 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */ 6224 } 6225 #endif 6226 6227 #ifdef FEAT_TITLE 6228 /* when 'title' changed, may need to change the title; same for 'icon' */ 6229 else if ((int *)varp == &p_title) 6230 { 6231 did_set_title(FALSE); 6232 } 6233 6234 else if ((int *)varp == &p_icon) 6235 { 6236 did_set_title(TRUE); 6237 } 6238 #endif 6239 6240 else if ((int *)varp == &curbuf->b_changed) 6241 { 6242 if (!value) 6243 save_file_ff(curbuf); /* Buffer is unchanged */ 6244 #ifdef FEAT_TITLE 6245 need_maketitle = TRUE; 6246 #endif 6247 #ifdef FEAT_AUTOCMD 6248 modified_was_set = value; 6249 #endif 6250 } 6251 6252 #ifdef BACKSLASH_IN_FILENAME 6253 else if ((int *)varp == &p_ssl) 6254 { 6255 if (p_ssl) 6256 { 6257 psepc = '/'; 6258 psepcN = '\\'; 6259 pseps[0] = '/'; 6260 psepsN[0] = '\\'; 6261 } 6262 else 6263 { 6264 psepc = '\\'; 6265 psepcN = '/'; 6266 pseps[0] = '\\'; 6267 psepsN[0] = '/'; 6268 } 6269 6270 /* need to adjust the file name arguments and buffer names. */ 6271 buflist_slash_adjust(); 6272 alist_slash_adjust(); 6273 # ifdef FEAT_EVAL 6274 scriptnames_slash_adjust(); 6275 # endif 6276 } 6277 #endif 6278 6279 /* If 'wrap' is set, set w_leftcol to zero. */ 6280 else if ((int *)varp == &curwin->w_p_wrap) 6281 { 6282 if (curwin->w_p_wrap) 6283 curwin->w_leftcol = 0; 6284 } 6285 6286 #ifdef FEAT_WINDOWS 6287 else if ((int *)varp == &p_ea) 6288 { 6289 if (p_ea && !old_value) 6290 win_equal(curwin, FALSE, 0); 6291 } 6292 #endif 6293 6294 else if ((int *)varp == &p_wiv) 6295 { 6296 /* 6297 * When 'weirdinvert' changed, set/reset 't_xs'. 6298 * Then set 'weirdinvert' according to value of 't_xs'. 6299 */ 6300 if (p_wiv && !old_value) 6301 T_XS = (char_u *)"y"; 6302 else if (!p_wiv && old_value) 6303 T_XS = empty_option; 6304 p_wiv = (*T_XS != NUL); 6305 } 6306 6307 #if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \ 6308 || defined(FEAT_NETBEANS_INTG)) 6309 else if ((int *)varp == &p_beval) 6310 { 6311 extern BalloonEval *balloonEval; 6312 6313 if (p_beval == TRUE) 6314 gui_mch_enable_beval_area(balloonEval); 6315 else 6316 gui_mch_disable_beval_area(balloonEval); 6317 } 6318 6319 else if ((int *)varp == &p_acd) 6320 { 6321 if (p_acd && curbuf->b_ffname != NULL 6322 && vim_chdirfile(curbuf->b_ffname) == OK) 6323 shorten_fnames(TRUE); 6324 } 6325 #endif 6326 6327 #ifdef FEAT_DIFF 6328 /* 'diff' */ 6329 else if ((int *)varp == &curwin->w_p_diff) 6330 { 6331 win_T *wp; 6332 6333 if (!curwin->w_p_diff) 6334 { 6335 /* When there is no window showing a diff for this buffer, remove 6336 * it from the diffs. */ 6337 for (wp = firstwin; wp != NULL; wp = wp->w_next) 6338 if (wp->w_buffer == curwin->w_buffer && wp->w_p_diff) 6339 break; 6340 if (wp == NULL) 6341 diff_buf_delete(curwin->w_buffer); 6342 } 6343 else 6344 diff_buf_add(curwin->w_buffer); 6345 #ifdef FEAT_FOLDING 6346 if (foldmethodIsDiff(curwin)) 6347 foldUpdateAll(curwin); 6348 #endif 6349 } 6350 #endif 6351 6352 #ifdef USE_IM_CONTROL 6353 /* 'imdisable' */ 6354 else if ((int *)varp == &p_imdisable) 6355 { 6356 /* Only de-activate it here, it will be enabled when changing mode. */ 6357 if (p_imdisable) 6358 im_set_active(FALSE); 6359 } 6360 #endif 6361 6362 #ifdef FEAT_FKMAP 6363 else if ((int *)varp == &p_altkeymap) 6364 { 6365 if (old_value != p_altkeymap) 6366 { 6367 if (!p_altkeymap) 6368 { 6369 p_hkmap = p_fkmap; 6370 p_fkmap = 0; 6371 } 6372 else 6373 { 6374 p_fkmap = p_hkmap; 6375 p_hkmap = 0; 6376 } 6377 (void)init_chartab(); 6378 } 6379 } 6380 6381 /* 6382 * In case some second language keymapping options have changed, check 6383 * and correct the setting in a consistent way. 6384 */ 6385 6386 /* 6387 * If hkmap or fkmap are set, reset Arabic keymapping. 6388 */ 6389 if ((p_hkmap || p_fkmap) && p_altkeymap) 6390 { 6391 p_altkeymap = p_fkmap; 6392 # ifdef FEAT_ARABIC 6393 curwin->w_p_arab = FALSE; 6394 # endif 6395 (void)init_chartab(); 6396 } 6397 6398 /* 6399 * If hkmap set, reset Farsi keymapping. 6400 */ 6401 if (p_hkmap && p_altkeymap) 6402 { 6403 p_altkeymap = 0; 6404 p_fkmap = 0; 6405 # ifdef FEAT_ARABIC 6406 curwin->w_p_arab = FALSE; 6407 # endif 6408 (void)init_chartab(); 6409 } 6410 6411 /* 6412 * If fkmap set, reset Hebrew keymapping. 6413 */ 6414 if (p_fkmap && !p_altkeymap) 6415 { 6416 p_altkeymap = 1; 6417 p_hkmap = 0; 6418 # ifdef FEAT_ARABIC 6419 curwin->w_p_arab = FALSE; 6420 # endif 6421 (void)init_chartab(); 6422 } 6423 #endif 6424 6425 #ifdef FEAT_ARABIC 6426 if ((int *)varp == &curwin->w_p_arab) 6427 { 6428 if (curwin->w_p_arab) 6429 { 6430 /* 6431 * 'arabic' is set, handle various sub-settings. 6432 */ 6433 if (!p_tbidi) 6434 { 6435 /* set rightleft mode */ 6436 if (!curwin->w_p_rl) 6437 { 6438 curwin->w_p_rl = TRUE; 6439 changed_window_setting(); 6440 } 6441 6442 /* Enable Arabic shaping (major part of what Arabic requires) */ 6443 if (!p_arshape) 6444 { 6445 p_arshape = TRUE; 6446 redraw_later_clear(); 6447 } 6448 } 6449 6450 /* Arabic requires a utf-8 encoding, inform the user if its not 6451 * set. */ 6452 if (STRCMP(p_enc, "utf-8") != 0) 6453 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"), 6454 hl_attr(HLF_W)); 6455 6456 # ifdef FEAT_MBYTE 6457 /* set 'delcombine' */ 6458 p_deco = TRUE; 6459 # endif 6460 6461 # ifdef FEAT_KEYMAP 6462 /* Force-set the necessary keymap for arabic */ 6463 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", 6464 OPT_LOCAL); 6465 # endif 6466 # ifdef FEAT_FKMAP 6467 p_altkeymap = 0; 6468 p_hkmap = 0; 6469 p_fkmap = 0; 6470 (void)init_chartab(); 6471 # endif 6472 } 6473 else 6474 { 6475 /* 6476 * 'arabic' is reset, handle various sub-settings. 6477 */ 6478 if (!p_tbidi) 6479 { 6480 /* reset rightleft mode */ 6481 if (curwin->w_p_rl) 6482 { 6483 curwin->w_p_rl = FALSE; 6484 changed_window_setting(); 6485 } 6486 6487 /* 'arabicshape' isn't reset, it is a global option and 6488 * another window may still need it "on". */ 6489 } 6490 6491 /* 'delcombine' isn't reset, it is a global option and another 6492 * window may still want it "on". */ 6493 6494 # ifdef FEAT_KEYMAP 6495 /* Revert to the default keymap */ 6496 curbuf->b_p_iminsert = B_IMODE_NONE; 6497 curbuf->b_p_imsearch = B_IMODE_USE_INSERT; 6498 # endif 6499 } 6500 } 6501 #endif 6502 6503 /* 6504 * End of handling side effects for bool options. 6505 */ 6506 6507 options[opt_idx].flags |= P_WAS_SET; 6508 6509 comp_col(); /* in case 'ruler' or 'showcmd' changed */ 6510 if (curwin->w_curswant != MAXCOL) 6511 curwin->w_set_curswant = TRUE; /* in case 'list' changed */ 6512 check_redraw(options[opt_idx].flags); 6513 6514 return NULL; 6515 } 6516 6517 /* 6518 * Set the value of a number option, and take care of side effects. 6519 * Returns NULL for success, or an error message for an error. 6520 */ 6521 static char_u * 6522 set_num_option(opt_idx, varp, value, errbuf, opt_flags) 6523 int opt_idx; /* index in options[] table */ 6524 char_u *varp; /* pointer to the option variable */ 6525 long value; /* new value */ 6526 char_u *errbuf; /* buffer for error messages */ 6527 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and 6528 OPT_MODELINE */ 6529 { 6530 char_u *errmsg = NULL; 6531 long old_value = *(long *)varp; 6532 long old_Rows = Rows; /* remember old Rows */ 6533 long old_Columns = Columns; /* remember old Columns */ 6534 long *pp = (long *)varp; 6535 6536 #ifdef FEAT_GUI 6537 need_mouse_correct = TRUE; 6538 #endif 6539 6540 *pp = value; 6541 #ifdef FEAT_EVAL 6542 /* Remember where the option was set. */ 6543 options[opt_idx].scriptID = current_SID; 6544 #endif 6545 6546 if (curbuf->b_p_sw <= 0) 6547 { 6548 errmsg = e_positive; 6549 curbuf->b_p_sw = curbuf->b_p_ts; 6550 } 6551 6552 /* 6553 * Number options that need some action when changed 6554 */ 6555 #ifdef FEAT_WINDOWS 6556 if (pp == &p_wh || pp == &p_hh) 6557 { 6558 if (p_wh < 1) 6559 { 6560 errmsg = e_positive; 6561 p_wh = 1; 6562 } 6563 if (p_wmh > p_wh) 6564 { 6565 errmsg = e_winheight; 6566 p_wh = p_wmh; 6567 } 6568 if (p_hh < 0) 6569 { 6570 errmsg = e_positive; 6571 p_hh = 0; 6572 } 6573 6574 /* Change window height NOW */ 6575 if (lastwin != firstwin) 6576 { 6577 if (pp == &p_wh && curwin->w_height < p_wh) 6578 win_setheight((int)p_wh); 6579 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) 6580 win_setheight((int)p_hh); 6581 } 6582 } 6583 6584 /* 'winminheight' */ 6585 else if (pp == &p_wmh) 6586 { 6587 if (p_wmh < 0) 6588 { 6589 errmsg = e_positive; 6590 p_wmh = 0; 6591 } 6592 if (p_wmh > p_wh) 6593 { 6594 errmsg = e_winheight; 6595 p_wmh = p_wh; 6596 } 6597 win_setminheight(); 6598 } 6599 6600 # ifdef FEAT_VERTSPLIT 6601 if (pp == &p_wiw) 6602 { 6603 if (p_wiw < 1) 6604 { 6605 errmsg = e_positive; 6606 p_wiw = 1; 6607 } 6608 if (p_wmw > p_wiw) 6609 { 6610 errmsg = e_winwidth; 6611 p_wiw = p_wmw; 6612 } 6613 6614 /* Change window width NOW */ 6615 if (lastwin != firstwin && curwin->w_width < p_wiw) 6616 win_setwidth((int)p_wiw); 6617 } 6618 6619 /* 'winminwidth' */ 6620 else if (pp == &p_wmw) 6621 { 6622 if (p_wmw < 0) 6623 { 6624 errmsg = e_positive; 6625 p_wmw = 0; 6626 } 6627 if (p_wmw > p_wiw) 6628 { 6629 errmsg = e_winwidth; 6630 p_wmw = p_wiw; 6631 } 6632 win_setminheight(); 6633 } 6634 # endif 6635 6636 #endif 6637 6638 #ifdef FEAT_WINDOWS 6639 /* (re)set last window status line */ 6640 else if (pp == &p_ls) 6641 { 6642 last_status(FALSE); 6643 } 6644 #endif 6645 6646 #ifdef FEAT_GUI 6647 else if (pp == &p_linespace) 6648 { 6649 if (gui.in_use && gui_mch_adjust_charsize() == OK) 6650 gui_set_shellsize(FALSE, FALSE); 6651 } 6652 #endif 6653 6654 #ifdef FEAT_FOLDING 6655 /* 'foldlevel' */ 6656 else if (pp == &curwin->w_p_fdl) 6657 { 6658 if (curwin->w_p_fdl < 0) 6659 curwin->w_p_fdl = 0; 6660 newFoldLevel(); 6661 } 6662 6663 /* 'foldminlevel' */ 6664 else if (pp == &curwin->w_p_fml) 6665 { 6666 foldUpdateAll(curwin); 6667 } 6668 6669 /* 'foldnestmax' */ 6670 else if (pp == &curwin->w_p_fdn) 6671 { 6672 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) 6673 foldUpdateAll(curwin); 6674 } 6675 6676 /* 'foldcolumn' */ 6677 else if (pp == &curwin->w_p_fdc) 6678 { 6679 if (curwin->w_p_fdc < 0) 6680 { 6681 errmsg = e_positive; 6682 curwin->w_p_fdc = 0; 6683 } 6684 else if (curwin->w_p_fdc > 12) 6685 { 6686 errmsg = e_invarg; 6687 curwin->w_p_fdc = 12; 6688 } 6689 } 6690 6691 /* 'shiftwidth' or 'tabstop' */ 6692 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) 6693 { 6694 if (foldmethodIsIndent(curwin)) 6695 foldUpdateAll(curwin); 6696 } 6697 #endif /* FEAT_FOLDING */ 6698 6699 else if (pp == &curbuf->b_p_iminsert) 6700 { 6701 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) 6702 { 6703 errmsg = e_invarg; 6704 curbuf->b_p_iminsert = B_IMODE_NONE; 6705 } 6706 p_iminsert = curbuf->b_p_iminsert; 6707 if (termcap_active) /* don't do this in the alternate screen */ 6708 showmode(); 6709 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP) 6710 /* Show/unshow value of 'keymap' in status lines. */ 6711 status_redraw_curbuf(); 6712 #endif 6713 } 6714 6715 else if (pp == &curbuf->b_p_imsearch) 6716 { 6717 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) 6718 { 6719 errmsg = e_invarg; 6720 curbuf->b_p_imsearch = B_IMODE_NONE; 6721 } 6722 p_imsearch = curbuf->b_p_imsearch; 6723 } 6724 6725 #ifdef FEAT_TITLE 6726 /* if 'titlelen' has changed, redraw the title */ 6727 else if (pp == &p_titlelen) 6728 { 6729 if (p_titlelen < 0) 6730 { 6731 errmsg = e_positive; 6732 p_titlelen = 85; 6733 } 6734 if (starting != NO_SCREEN && old_value != p_titlelen) 6735 need_maketitle = TRUE; 6736 } 6737 #endif 6738 6739 /* if p_ch changed value, change the command line height */ 6740 else if (pp == &p_ch) 6741 { 6742 if (p_ch < 1) 6743 { 6744 errmsg = e_positive; 6745 p_ch = 1; 6746 } 6747 6748 /* Only compute the new window layout when startup has been 6749 * completed. Otherwise the frame sizes may be wrong. */ 6750 if (p_ch != old_value && full_screen 6751 #ifdef FEAT_GUI 6752 && !gui.starting 6753 #endif 6754 ) 6755 command_height(old_value); 6756 } 6757 6758 /* when 'updatecount' changes from zero to non-zero, open swap files */ 6759 else if (pp == &p_uc) 6760 { 6761 if (p_uc < 0) 6762 { 6763 errmsg = e_positive; 6764 p_uc = 100; 6765 } 6766 if (p_uc && !old_value) 6767 ml_open_files(); 6768 } 6769 6770 /* sync undo before 'undolevels' changes */ 6771 else if (pp == &p_ul) 6772 { 6773 /* use the old value, otherwise u_sync() may not work properly */ 6774 p_ul = old_value; 6775 u_sync(); 6776 p_ul = value; 6777 } 6778 6779 /* 6780 * Check the bounds for numeric options here 6781 */ 6782 if (Rows < min_rows() && full_screen) 6783 { 6784 if (errbuf != NULL) 6785 { 6786 sprintf((char *)errbuf, _("E593: Need at least %d lines"), 6787 min_rows()); 6788 errmsg = errbuf; 6789 } 6790 Rows = min_rows(); 6791 } 6792 if (Columns < MIN_COLUMNS && full_screen) 6793 { 6794 if (errbuf != NULL) 6795 { 6796 sprintf((char *)errbuf, _("E594: Need at least %d columns"), 6797 MIN_COLUMNS); 6798 errmsg = errbuf; 6799 } 6800 Columns = MIN_COLUMNS; 6801 } 6802 6803 #ifdef DJGPP 6804 /* avoid a crash by checking for a too large value of 'columns' */ 6805 if (old_Columns != Columns && full_screen && term_console) 6806 mch_check_columns(); 6807 #endif 6808 6809 /* 6810 * If the screen (shell) height has been changed, assume it is the 6811 * physical screenheight. 6812 */ 6813 if (old_Rows != Rows || old_Columns != Columns) 6814 { 6815 /* Changing the screen size is not allowed while updating the screen. */ 6816 if (updating_screen) 6817 *pp = old_value; 6818 else if (full_screen 6819 #ifdef FEAT_GUI 6820 && !gui.starting 6821 #endif 6822 ) 6823 set_shellsize((int)Columns, (int)Rows, TRUE); 6824 else 6825 { 6826 /* Postpone the resizing; check the size and cmdline position for 6827 * messages. */ 6828 check_shellsize(); 6829 if (cmdline_row > Rows - p_ch && Rows > p_ch) 6830 cmdline_row = Rows - p_ch; 6831 } 6832 } 6833 6834 if (curbuf->b_p_sts < 0) 6835 { 6836 errmsg = e_positive; 6837 curbuf->b_p_sts = 0; 6838 } 6839 if (curbuf->b_p_ts <= 0) 6840 { 6841 errmsg = e_positive; 6842 curbuf->b_p_ts = 8; 6843 } 6844 if (curbuf->b_p_tw < 0) 6845 { 6846 errmsg = e_positive; 6847 curbuf->b_p_tw = 0; 6848 } 6849 if (p_tm < 0) 6850 { 6851 errmsg = e_positive; 6852 p_tm = 0; 6853 } 6854 if ((curwin->w_p_scr <= 0 6855 || (curwin->w_p_scr > curwin->w_height 6856 && curwin->w_height > 0)) 6857 && full_screen) 6858 { 6859 if (pp == &(curwin->w_p_scr)) 6860 { 6861 if (curwin->w_p_scr != 0) 6862 errmsg = e_scroll; 6863 win_comp_scroll(curwin); 6864 } 6865 /* If 'scroll' became invalid because of a side effect silently adjust 6866 * it. */ 6867 else if (curwin->w_p_scr <= 0) 6868 curwin->w_p_scr = 1; 6869 else /* curwin->w_p_scr > curwin->w_height */ 6870 curwin->w_p_scr = curwin->w_height; 6871 } 6872 if (p_report < 0) 6873 { 6874 errmsg = e_positive; 6875 p_report = 1; 6876 } 6877 if ((p_sj < 0 || p_sj >= Rows) && full_screen) 6878 { 6879 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */ 6880 p_sj = Rows / 2; 6881 else 6882 { 6883 errmsg = e_scroll; 6884 p_sj = 1; 6885 } 6886 } 6887 if (p_so < 0 && full_screen) 6888 { 6889 errmsg = e_scroll; 6890 p_so = 0; 6891 } 6892 if (p_siso < 0 && full_screen) 6893 { 6894 errmsg = e_positive; 6895 p_siso = 0; 6896 } 6897 #ifdef FEAT_CMDWIN 6898 if (p_cwh < 1) 6899 { 6900 errmsg = e_positive; 6901 p_cwh = 1; 6902 } 6903 #endif 6904 if (p_ut < 0) 6905 { 6906 errmsg = e_positive; 6907 p_ut = 2000; 6908 } 6909 if (p_ss < 0) 6910 { 6911 errmsg = e_positive; 6912 p_ss = 0; 6913 } 6914 6915 /* May set global value for local option. */ 6916 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) 6917 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; 6918 6919 options[opt_idx].flags |= P_WAS_SET; 6920 6921 comp_col(); /* in case 'columns' or 'ls' changed */ 6922 if (curwin->w_curswant != MAXCOL) 6923 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */ 6924 check_redraw(options[opt_idx].flags); 6925 6926 return errmsg; 6927 } 6928 6929 /* 6930 * Called after an option changed: check if something needs to be redrawn. 6931 */ 6932 static void 6933 check_redraw(flags) 6934 long_u flags; 6935 { 6936 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */ 6937 int clear = (flags & P_RCLR) == P_RCLR; 6938 int all = ((flags & P_RALL) == P_RALL || clear); 6939 6940 #ifdef FEAT_WINDOWS 6941 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */ 6942 status_redraw_all(); 6943 #endif 6944 6945 if ((flags & P_RBUF) || (flags & P_RWIN) || all) 6946 changed_window_setting(); 6947 if (flags & P_RBUF) 6948 redraw_curbuf_later(NOT_VALID); 6949 if (clear) 6950 redraw_all_later(CLEAR); 6951 else if (all) 6952 redraw_all_later(NOT_VALID); 6953 } 6954 6955 /* 6956 * Find index for option 'arg'. 6957 * Return -1 if not found. 6958 */ 6959 static int 6960 findoption(arg) 6961 char_u *arg; 6962 { 6963 int opt_idx; 6964 char *s, *p; 6965 static short quick_tab[27] = {0, 0}; /* quick access table */ 6966 int is_term_opt; 6967 6968 /* 6969 * For first call: Initialize the quick-access table. 6970 * It contains the index for the first option that starts with a certain 6971 * letter. There are 26 letters, plus the first "t_" option. 6972 */ 6973 if (quick_tab[1] == 0) 6974 { 6975 p = options[0].fullname; 6976 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++) 6977 { 6978 if (s[0] != p[0]) 6979 { 6980 if (s[0] == 't' && s[1] == '_') 6981 quick_tab[26] = opt_idx; 6982 else 6983 quick_tab[CharOrdLow(s[0])] = opt_idx; 6984 } 6985 p = s; 6986 } 6987 } 6988 6989 /* 6990 * Check for name starting with an illegal character. 6991 */ 6992 #ifdef EBCDIC 6993 if (!islower(arg[0])) 6994 #else 6995 if (arg[0] < 'a' || arg[0] > 'z') 6996 #endif 6997 return -1; 6998 6999 is_term_opt = (arg[0] == 't' && arg[1] == '_'); 7000 if (is_term_opt) 7001 opt_idx = quick_tab[26]; 7002 else 7003 opt_idx = quick_tab[CharOrdLow(arg[0])]; 7004 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++) 7005 { 7006 if (STRCMP(arg, s) == 0) /* match full name */ 7007 break; 7008 } 7009 if (s == NULL && !is_term_opt) 7010 { 7011 opt_idx = quick_tab[CharOrdLow(arg[0])]; 7012 for ( ; options[opt_idx].fullname != NULL; opt_idx++) 7013 { 7014 s = options[opt_idx].shortname; 7015 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */ 7016 break; 7017 s = NULL; 7018 } 7019 } 7020 if (s == NULL) 7021 opt_idx = -1; 7022 return opt_idx; 7023 } 7024 7025 #if defined(FEAT_EVAL) || defined(FEAT_TCL) 7026 /* 7027 * Get the value for an option. 7028 * 7029 * Returns: 7030 * Number or Toggle option: 1, *numval gets value. 7031 * String option: 0, *stringval gets allocated string. 7032 * Hidden Number or Toggle option: -1. 7033 * hidden String option: -2. 7034 * unknown option: -3. 7035 */ 7036 int 7037 get_option_value(name, numval, stringval, opt_flags) 7038 char_u *name; 7039 long *numval; 7040 char_u **stringval; /* NULL when only checking existance */ 7041 int opt_flags; 7042 { 7043 int opt_idx; 7044 char_u *varp; 7045 7046 opt_idx = findoption(name); 7047 if (opt_idx < 0) /* unknown option */ 7048 return -3; 7049 7050 varp = get_varp_scope(&(options[opt_idx]), opt_flags); 7051 7052 if (options[opt_idx].flags & P_STRING) 7053 { 7054 if (varp == NULL) /* hidden option */ 7055 return -2; 7056 if (stringval != NULL) 7057 { 7058 #ifdef FEAT_CRYPT 7059 /* never return the value of the crypt key */ 7060 if ((char_u **)varp == &curbuf->b_p_key) 7061 *stringval = vim_strsave((char_u *)"*****"); 7062 else 7063 #endif 7064 *stringval = vim_strsave(*(char_u **)(varp)); 7065 } 7066 return 0; 7067 } 7068 7069 if (varp == NULL) /* hidden option */ 7070 return -1; 7071 if (options[opt_idx].flags & P_NUM) 7072 *numval = *(long *)varp; 7073 else 7074 { 7075 /* Special case: 'modified' is b_changed, but we also want to consider 7076 * it set when 'ff' or 'fenc' changed. */ 7077 if ((int *)varp == &curbuf->b_changed) 7078 *numval = curbufIsChanged(); 7079 else 7080 *numval = *(int *)varp; 7081 } 7082 return 1; 7083 } 7084 #endif 7085 7086 /* 7087 * Set the value of option "name". 7088 * Use "string" for string options, use "number" for other options. 7089 */ 7090 void 7091 set_option_value(name, number, string, opt_flags) 7092 char_u *name; 7093 long number; 7094 char_u *string; 7095 int opt_flags; /* OPT_LOCAL or 0 (both) */ 7096 { 7097 int opt_idx; 7098 char_u *varp; 7099 int flags; 7100 7101 opt_idx = findoption(name); 7102 if (opt_idx == -1) 7103 EMSG2(_("E355: Unknown option: %s"), name); 7104 else 7105 { 7106 flags = options[opt_idx].flags; 7107 #ifdef HAVE_SANDBOX 7108 /* Disallow changing some options in the sandbox */ 7109 if (sandbox > 0 && (flags & P_SECURE)) 7110 EMSG(_(e_sandbox)); 7111 else 7112 #endif 7113 if (flags & P_STRING) 7114 set_string_option(opt_idx, string, opt_flags); 7115 else 7116 { 7117 varp = get_varp(&options[opt_idx]); 7118 if (varp != NULL) /* hidden option is not changed */ 7119 { 7120 if (flags & P_NUM) 7121 (void)set_num_option(opt_idx, varp, number, NULL, opt_flags); 7122 else 7123 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags); 7124 } 7125 } 7126 } 7127 } 7128 7129 /* 7130 * Get the terminal code for a terminal option. 7131 * Returns NULL when not found. 7132 */ 7133 char_u * 7134 get_term_code(tname) 7135 char_u *tname; 7136 { 7137 int opt_idx; 7138 char_u *varp; 7139 7140 if (tname[0] != 't' || tname[1] != '_' || 7141 tname[2] == NUL || tname[3] == NUL) 7142 return NULL; 7143 if ((opt_idx = findoption(tname)) >= 0) 7144 { 7145 varp = get_varp(&(options[opt_idx])); 7146 if (varp != NULL) 7147 varp = *(char_u **)(varp); 7148 return varp; 7149 } 7150 return find_termcode(tname + 2); 7151 } 7152 7153 char_u * 7154 get_highlight_default() 7155 { 7156 int i; 7157 7158 i = findoption((char_u *)"hl"); 7159 if (i >= 0) 7160 return options[i].def_val[VI_DEFAULT]; 7161 return (char_u *)NULL; 7162 } 7163 7164 /* 7165 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number. 7166 */ 7167 static int 7168 find_key_option(arg) 7169 char_u *arg; 7170 { 7171 int key; 7172 int modifiers; 7173 7174 /* 7175 * Don't use get_special_key_code() for t_xx, we don't want it to call 7176 * add_termcap_entry(). 7177 */ 7178 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) 7179 key = TERMCAP2KEY(arg[2], arg[3]); 7180 else 7181 { 7182 --arg; /* put arg at the '<' */ 7183 modifiers = 0; 7184 key = find_special_key(&arg, &modifiers, TRUE); 7185 if (modifiers) /* can't handle modifiers here */ 7186 key = 0; 7187 } 7188 return key; 7189 } 7190 7191 /* 7192 * if 'all' == 0: show changed options 7193 * if 'all' == 1: show all normal options 7194 * if 'all' == 2: show all terminal options 7195 */ 7196 static void 7197 showoptions(all, opt_flags) 7198 int all; 7199 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */ 7200 { 7201 struct vimoption *p; 7202 int col; 7203 int isterm; 7204 char_u *varp; 7205 struct vimoption **items; 7206 int item_count; 7207 int run; 7208 int row, rows; 7209 int cols; 7210 int i; 7211 int len; 7212 7213 #define INC 20 7214 #define GAP 3 7215 7216 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) * 7217 PARAM_COUNT)); 7218 if (items == NULL) 7219 return; 7220 7221 /* Highlight title */ 7222 if (all == 2) 7223 MSG_PUTS_TITLE(_("\n--- Terminal codes ---")); 7224 else if (opt_flags & OPT_GLOBAL) 7225 MSG_PUTS_TITLE(_("\n--- Global option values ---")); 7226 else if (opt_flags & OPT_LOCAL) 7227 MSG_PUTS_TITLE(_("\n--- Local option values ---")); 7228 else 7229 MSG_PUTS_TITLE(_("\n--- Options ---")); 7230 7231 /* 7232 * do the loop two times: 7233 * 1. display the short items 7234 * 2. display the long items (only strings and numbers) 7235 */ 7236 for (run = 1; run <= 2 && !got_int; ++run) 7237 { 7238 /* 7239 * collect the items in items[] 7240 */ 7241 item_count = 0; 7242 for (p = &options[0]; p->fullname != NULL; p++) 7243 { 7244 varp = NULL; 7245 isterm = istermoption(p); 7246 if (opt_flags != 0) 7247 { 7248 if (p->indir != PV_NONE && !isterm) 7249 varp = get_varp_scope(p, opt_flags); 7250 } 7251 else 7252 varp = get_varp(p); 7253 if (varp != NULL 7254 && ((all == 2 && isterm) 7255 || (all == 1 && !isterm) 7256 || (all == 0 && !optval_default(p, varp)))) 7257 { 7258 if (p->flags & P_BOOL) 7259 len = 1; /* a toggle option fits always */ 7260 else 7261 { 7262 option_value2string(p, opt_flags); 7263 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1; 7264 } 7265 if ((len <= INC - GAP && run == 1) || 7266 (len > INC - GAP && run == 2)) 7267 items[item_count++] = p; 7268 } 7269 } 7270 7271 /* 7272 * display the items 7273 */ 7274 if (run == 1) 7275 { 7276 cols = (Columns + GAP - 3) / INC; 7277 if (cols == 0) 7278 cols = 1; 7279 rows = (item_count + cols - 1) / cols; 7280 } 7281 else /* run == 2 */ 7282 rows = item_count; 7283 for (row = 0; row < rows && !got_int; ++row) 7284 { 7285 msg_putchar('\n'); /* go to next line */ 7286 if (got_int) /* 'q' typed in more */ 7287 break; 7288 col = 0; 7289 for (i = row; i < item_count; i += rows) 7290 { 7291 msg_col = col; /* make columns */ 7292 showoneopt(items[i], opt_flags); 7293 col += INC; 7294 } 7295 out_flush(); 7296 ui_breakcheck(); 7297 } 7298 } 7299 vim_free(items); 7300 } 7301 7302 /* 7303 * Return TRUE if option "p" has its default value. 7304 */ 7305 static int 7306 optval_default(p, varp) 7307 struct vimoption *p; 7308 char_u *varp; 7309 { 7310 int dvi; 7311 7312 if (varp == NULL) 7313 return TRUE; /* hidden option is always at default */ 7314 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT; 7315 if (p->flags & P_NUM) 7316 return (*(long *)varp == (long)p->def_val[dvi]); 7317 if (p->flags & P_BOOL) 7318 /* the cast to long is required for Manx C */ 7319 return (*(int *)varp == (int)(long)p->def_val[dvi]); 7320 /* P_STRING */ 7321 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0); 7322 } 7323 7324 /* 7325 * showoneopt: show the value of one option 7326 * must not be called with a hidden option! 7327 */ 7328 static void 7329 showoneopt(p, opt_flags) 7330 struct vimoption *p; 7331 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */ 7332 { 7333 char_u *varp; 7334 7335 varp = get_varp_scope(p, opt_flags); 7336 7337 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */ 7338 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed 7339 ? !curbufIsChanged() : !*(int *)varp)) 7340 MSG_PUTS("no"); 7341 else if ((p->flags & P_BOOL) && *(int *)varp < 0) 7342 MSG_PUTS("--"); 7343 else 7344 MSG_PUTS(" "); 7345 MSG_PUTS(p->fullname); 7346 if (!(p->flags & P_BOOL)) 7347 { 7348 msg_putchar('='); 7349 /* put value string in NameBuff */ 7350 option_value2string(p, opt_flags); 7351 msg_outtrans(NameBuff); 7352 } 7353 } 7354 7355 /* 7356 * Write modified options as ":set" commands to a file. 7357 * 7358 * There are three values for "opt_flags": 7359 * OPT_GLOBAL: Write global option values and fresh values of 7360 * buffer-local options (used for start of a session 7361 * file). 7362 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for 7363 * curwin (used for a vimrc file). 7364 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh 7365 * and local values for window-local options of 7366 * curwin. Local values are also written when at the 7367 * default value, because a modeline or autocommand 7368 * may have set them when doing ":edit file" and the 7369 * user has set them back at the default or fresh 7370 * value. 7371 * When "local_only" is TRUE, don't write fresh 7372 * values, only local values (for ":mkview"). 7373 * (fresh value = value used for a new buffer or window for a local option). 7374 * 7375 * Return FAIL on error, OK otherwise. 7376 */ 7377 int 7378 makeset(fd, opt_flags, local_only) 7379 FILE *fd; 7380 int opt_flags; 7381 int local_only; 7382 { 7383 struct vimoption *p; 7384 char_u *varp; /* currently used value */ 7385 char_u *varp_fresh; /* local value */ 7386 char_u *varp_local = NULL; /* fresh value */ 7387 char *cmd; 7388 int round; 7389 7390 /* 7391 * The options that don't have a default (terminal name, columns, lines) 7392 * are never written. Terminal options are also not written. 7393 */ 7394 for (p = &options[0]; !istermoption(p); p++) 7395 if (!(p->flags & P_NO_MKRC) && !istermoption(p)) 7396 { 7397 /* skip global option when only doing locals */ 7398 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) 7399 continue; 7400 7401 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc 7402 * file, they are always buffer-specific. */ 7403 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) 7404 continue; 7405 7406 /* Global values are only written when not at the default value. */ 7407 varp = get_varp_scope(p, opt_flags); 7408 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp)) 7409 continue; 7410 7411 round = 2; 7412 if (p->indir != PV_NONE) 7413 { 7414 if (p->var == VAR_WIN) 7415 { 7416 /* skip window-local option when only doing globals */ 7417 if (!(opt_flags & OPT_LOCAL)) 7418 continue; 7419 /* When fresh value of window-local option is not at the 7420 * default, need to write it too. */ 7421 if (!(opt_flags & OPT_GLOBAL) && !local_only) 7422 { 7423 varp_fresh = get_varp_scope(p, OPT_GLOBAL); 7424 if (!optval_default(p, varp_fresh)) 7425 { 7426 round = 1; 7427 varp_local = varp; 7428 varp = varp_fresh; 7429 } 7430 } 7431 } 7432 } 7433 7434 /* Round 1: fresh value for window-local options. 7435 * Round 2: other values */ 7436 for ( ; round <= 2; varp = varp_local, ++round) 7437 { 7438 if (round == 1 || (opt_flags & OPT_GLOBAL)) 7439 cmd = "set"; 7440 else 7441 cmd = "setlocal"; 7442 7443 if (p->flags & P_BOOL) 7444 { 7445 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL) 7446 return FAIL; 7447 } 7448 else if (p->flags & P_NUM) 7449 { 7450 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL) 7451 return FAIL; 7452 } 7453 else /* P_STRING */ 7454 { 7455 /* Don't set 'syntax' and 'filetype' again if the value is 7456 * already right, avoids reloading the syntax file. */ 7457 if (p->indir == PV_SYN || p->indir == PV_FT) 7458 { 7459 if (fprintf(fd, "if &%s != '%s'", p->fullname, 7460 *(char_u **)(varp)) < 0 7461 || put_eol(fd) < 0) 7462 return FAIL; 7463 } 7464 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, 7465 (p->flags & P_EXPAND) != 0) == FAIL) 7466 return FAIL; 7467 if (p->indir == PV_SYN || p->indir == PV_FT) 7468 { 7469 if (put_line(fd, "endif") == FAIL) 7470 return FAIL; 7471 } 7472 } 7473 } 7474 } 7475 return OK; 7476 } 7477 7478 #if defined(FEAT_FOLDING) || defined(PROTO) 7479 /* 7480 * Generate set commands for the local fold options only. Used when 7481 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options". 7482 */ 7483 int 7484 makefoldset(fd) 7485 FILE *fd; 7486 { 7487 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL 7488 # ifdef FEAT_EVAL 7489 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE) 7490 == FAIL 7491 # endif 7492 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE) 7493 == FAIL 7494 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE) 7495 == FAIL 7496 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL 7497 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL 7498 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL 7499 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL 7500 ) 7501 return FAIL; 7502 7503 return OK; 7504 } 7505 #endif 7506 7507 static int 7508 put_setstring(fd, cmd, name, valuep, expand) 7509 FILE *fd; 7510 char *cmd; 7511 char *name; 7512 char_u **valuep; 7513 int expand; 7514 { 7515 char_u *s; 7516 char_u buf[MAXPATHL]; 7517 7518 if (fprintf(fd, "%s %s=", cmd, name) < 0) 7519 return FAIL; 7520 if (*valuep != NULL) 7521 { 7522 /* Output 'pastetoggle' as key names. For other 7523 * options some characters have to be escaped with 7524 * CTRL-V or backslash */ 7525 if (valuep == &p_pt) 7526 { 7527 s = *valuep; 7528 while (*s != NUL) 7529 if (fputs((char *)str2special(&s, FALSE), fd) < 0) 7530 return FAIL; 7531 } 7532 else if (expand) 7533 { 7534 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE); 7535 if (put_escstr(fd, buf, 2) == FAIL) 7536 return FAIL; 7537 } 7538 else if (put_escstr(fd, *valuep, 2) == FAIL) 7539 return FAIL; 7540 } 7541 if (put_eol(fd) < 0) 7542 return FAIL; 7543 return OK; 7544 } 7545 7546 static int 7547 put_setnum(fd, cmd, name, valuep) 7548 FILE *fd; 7549 char *cmd; 7550 char *name; 7551 long *valuep; 7552 { 7553 long wc; 7554 7555 if (fprintf(fd, "%s %s=", cmd, name) < 0) 7556 return FAIL; 7557 if (wc_use_keyname((char_u *)valuep, &wc)) 7558 { 7559 /* print 'wildchar' and 'wildcharm' as a key name */ 7560 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) 7561 return FAIL; 7562 } 7563 else if (fprintf(fd, "%ld", *valuep) < 0) 7564 return FAIL; 7565 if (put_eol(fd) < 0) 7566 return FAIL; 7567 return OK; 7568 } 7569 7570 static int 7571 put_setbool(fd, cmd, name, value) 7572 FILE *fd; 7573 char *cmd; 7574 char *name; 7575 int value; 7576 { 7577 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0 7578 || put_eol(fd) < 0) 7579 return FAIL; 7580 return OK; 7581 } 7582 7583 /* 7584 * Clear all the terminal options. 7585 * If the option has been allocated, free the memory. 7586 * Terminal options are never hidden or indirect. 7587 */ 7588 void 7589 clear_termoptions() 7590 { 7591 struct vimoption *p; 7592 7593 /* 7594 * Reset a few things before clearing the old options. This may cause 7595 * outputting a few things that the terminal doesn't understand, but the 7596 * screen will be cleared later, so this is OK. 7597 */ 7598 #ifdef FEAT_MOUSE_TTY 7599 mch_setmouse(FALSE); /* switch mouse off */ 7600 #endif 7601 #ifdef FEAT_TITLE 7602 mch_restore_title(3); /* restore window titles */ 7603 #endif 7604 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI) 7605 /* When starting the GUI close the display opened for the clipboard. 7606 * After restoring the title, because that will need the display. */ 7607 if (gui.starting) 7608 clear_xterm_clip(); 7609 #endif 7610 #ifdef WIN3264 7611 /* 7612 * Check if this is allowed now. 7613 */ 7614 if (can_end_termcap_mode(FALSE) == TRUE) 7615 #endif 7616 stoptermcap(); /* stop termcap mode */ 7617 7618 for (p = &options[0]; p->fullname != NULL; p++) 7619 if (istermoption(p)) 7620 { 7621 if (p->flags & P_ALLOCED) 7622 free_string_option(*(char_u **)(p->var)); 7623 if (p->flags & P_DEF_ALLOCED) 7624 free_string_option(p->def_val[VI_DEFAULT]); 7625 *(char_u **)(p->var) = empty_option; 7626 p->def_val[VI_DEFAULT] = empty_option; 7627 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED); 7628 } 7629 clear_termcodes(); 7630 } 7631 7632 /* 7633 * Set the terminal option defaults to the current value. 7634 * Used after setting the terminal name. 7635 */ 7636 void 7637 set_term_defaults() 7638 { 7639 struct vimoption *p; 7640 7641 for (p = &options[0]; p->fullname != NULL; p++) 7642 { 7643 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) 7644 { 7645 if (p->flags & P_DEF_ALLOCED) 7646 { 7647 free_string_option(p->def_val[VI_DEFAULT]); 7648 p->flags &= ~P_DEF_ALLOCED; 7649 } 7650 p->def_val[VI_DEFAULT] = *(char_u **)(p->var); 7651 if (p->flags & P_ALLOCED) 7652 { 7653 p->flags |= P_DEF_ALLOCED; 7654 p->flags &= ~P_ALLOCED; /* don't free the value now */ 7655 } 7656 } 7657 } 7658 } 7659 7660 /* 7661 * return TRUE if 'p' starts with 't_' 7662 */ 7663 static int 7664 istermoption(p) 7665 struct vimoption *p; 7666 { 7667 return (p->fullname[0] == 't' && p->fullname[1] == '_'); 7668 } 7669 7670 /* 7671 * Compute columns for ruler and shown command. 'sc_col' is also used to 7672 * decide what the maximum length of a message on the status line can be. 7673 * If there is a status line for the last window, 'sc_col' is independent 7674 * of 'ru_col'. 7675 */ 7676 7677 #define COL_RULER 17 /* columns needed by standard ruler */ 7678 7679 void 7680 comp_col() 7681 { 7682 #if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS) 7683 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin)); 7684 7685 sc_col = 0; 7686 ru_col = 0; 7687 if (p_ru) 7688 { 7689 #ifdef FEAT_STL_OPT 7690 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1; 7691 #else 7692 ru_col = COL_RULER + 1; 7693 #endif 7694 /* no last status line, adjust sc_col */ 7695 if (!last_has_status) 7696 sc_col = ru_col; 7697 } 7698 if (p_sc) 7699 { 7700 sc_col += SHOWCMD_COLS; 7701 if (!p_ru || last_has_status) /* no need for separating space */ 7702 ++sc_col; 7703 } 7704 sc_col = Columns - sc_col; 7705 ru_col = Columns - ru_col; 7706 if (sc_col <= 0) /* screen too narrow, will become a mess */ 7707 sc_col = 1; 7708 if (ru_col <= 0) 7709 ru_col = 1; 7710 #else 7711 sc_col = Columns; 7712 ru_col = Columns; 7713 #endif 7714 } 7715 7716 /* 7717 * Get pointer to option variable, depending on local or global scope. 7718 */ 7719 static char_u * 7720 get_varp_scope(p, opt_flags) 7721 struct vimoption *p; 7722 int opt_flags; 7723 { 7724 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) 7725 { 7726 if (p->var == VAR_WIN) 7727 return (char_u *)GLOBAL_WO(get_varp(p)); 7728 return p->var; 7729 } 7730 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH) 7731 { 7732 switch ((int)p->indir) 7733 { 7734 #ifdef FEAT_QUICKFIX 7735 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp); 7736 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp); 7737 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm); 7738 #endif 7739 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep); 7740 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp); 7741 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path); 7742 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar); 7743 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags); 7744 #ifdef FEAT_FIND_ID 7745 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def); 7746 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc); 7747 #endif 7748 #ifdef FEAT_INS_EXPAND 7749 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict); 7750 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr); 7751 #endif 7752 } 7753 return NULL; /* "cannot happen" */ 7754 } 7755 return get_varp(p); 7756 } 7757 7758 /* 7759 * Get pointer to option variable. 7760 */ 7761 static char_u * 7762 get_varp(p) 7763 struct vimoption *p; 7764 { 7765 /* hidden option, always return NULL */ 7766 if (p->var == NULL) 7767 return NULL; 7768 7769 switch ((int)p->indir) 7770 { 7771 case PV_NONE: return p->var; 7772 7773 /* global option with local value: use local value if it's been set */ 7774 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL 7775 ? (char_u *)&curbuf->b_p_ep : p->var; 7776 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL 7777 ? (char_u *)&curbuf->b_p_kp : p->var; 7778 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL 7779 ? (char_u *)&(curbuf->b_p_path) : p->var; 7780 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0 7781 ? (char_u *)&(curbuf->b_p_ar) : p->var; 7782 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL 7783 ? (char_u *)&(curbuf->b_p_tags) : p->var; 7784 #ifdef FEAT_FIND_ID 7785 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL 7786 ? (char_u *)&(curbuf->b_p_def) : p->var; 7787 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL 7788 ? (char_u *)&(curbuf->b_p_inc) : p->var; 7789 #endif 7790 #ifdef FEAT_INS_EXPAND 7791 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL 7792 ? (char_u *)&(curbuf->b_p_dict) : p->var; 7793 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL 7794 ? (char_u *)&(curbuf->b_p_tsr) : p->var; 7795 #endif 7796 #ifdef FEAT_QUICKFIX 7797 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL 7798 ? (char_u *)&(curbuf->b_p_gp) : p->var; 7799 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL 7800 ? (char_u *)&(curbuf->b_p_mp) : p->var; 7801 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL 7802 ? (char_u *)&(curbuf->b_p_efm) : p->var; 7803 #endif 7804 7805 #ifdef FEAT_ARABIC 7806 case PV_ARAB: return (char_u *)&(curwin->w_p_arab); 7807 #endif 7808 case PV_LIST: return (char_u *)&(curwin->w_p_list); 7809 #ifdef FEAT_DIFF 7810 case PV_DIFF: return (char_u *)&(curwin->w_p_diff); 7811 #endif 7812 #ifdef FEAT_FOLDING 7813 case PV_FDC: return (char_u *)&(curwin->w_p_fdc); 7814 case PV_FEN: return (char_u *)&(curwin->w_p_fen); 7815 case PV_FDI: return (char_u *)&(curwin->w_p_fdi); 7816 case PV_FDL: return (char_u *)&(curwin->w_p_fdl); 7817 case PV_FDM: return (char_u *)&(curwin->w_p_fdm); 7818 case PV_FML: return (char_u *)&(curwin->w_p_fml); 7819 case PV_FDN: return (char_u *)&(curwin->w_p_fdn); 7820 # ifdef FEAT_EVAL 7821 case PV_FDE: return (char_u *)&(curwin->w_p_fde); 7822 case PV_FDT: return (char_u *)&(curwin->w_p_fdt); 7823 # endif 7824 case PV_FMR: return (char_u *)&(curwin->w_p_fmr); 7825 #endif 7826 case PV_NU: return (char_u *)&(curwin->w_p_nu); 7827 #if defined(FEAT_WINDOWS) 7828 case PV_WFH: return (char_u *)&(curwin->w_p_wfh); 7829 #endif 7830 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) 7831 case PV_PVW: return (char_u *)&(curwin->w_p_pvw); 7832 #endif 7833 #ifdef FEAT_RIGHTLEFT 7834 case PV_RL: return (char_u *)&(curwin->w_p_rl); 7835 case PV_RLC: return (char_u *)&(curwin->w_p_rlc); 7836 #endif 7837 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr); 7838 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap); 7839 #ifdef FEAT_LINEBREAK 7840 case PV_LBR: return (char_u *)&(curwin->w_p_lbr); 7841 #endif 7842 #ifdef FEAT_SCROLLBIND 7843 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb); 7844 #endif 7845 7846 case PV_AI: return (char_u *)&(curbuf->b_p_ai); 7847 case PV_BIN: return (char_u *)&(curbuf->b_p_bin); 7848 #ifdef FEAT_MBYTE 7849 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb); 7850 #endif 7851 #if defined(FEAT_QUICKFIX) 7852 case PV_BH: return (char_u *)&(curbuf->b_p_bh); 7853 case PV_BT: return (char_u *)&(curbuf->b_p_bt); 7854 #endif 7855 case PV_BL: return (char_u *)&(curbuf->b_p_bl); 7856 case PV_CI: return (char_u *)&(curbuf->b_p_ci); 7857 #ifdef FEAT_CINDENT 7858 case PV_CIN: return (char_u *)&(curbuf->b_p_cin); 7859 case PV_CINK: return (char_u *)&(curbuf->b_p_cink); 7860 case PV_CINO: return (char_u *)&(curbuf->b_p_cino); 7861 #endif 7862 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 7863 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); 7864 #endif 7865 #ifdef FEAT_COMMENTS 7866 case PV_COM: return (char_u *)&(curbuf->b_p_com); 7867 #endif 7868 #ifdef FEAT_FOLDING 7869 case PV_CMS: return (char_u *)&(curbuf->b_p_cms); 7870 #endif 7871 #ifdef FEAT_INS_EXPAND 7872 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); 7873 #endif 7874 case PV_EOL: return (char_u *)&(curbuf->b_p_eol); 7875 case PV_ET: return (char_u *)&(curbuf->b_p_et); 7876 #ifdef FEAT_MBYTE 7877 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc); 7878 #endif 7879 case PV_FF: return (char_u *)&(curbuf->b_p_ff); 7880 #ifdef FEAT_AUTOCMD 7881 case PV_FT: return (char_u *)&(curbuf->b_p_ft); 7882 #endif 7883 case PV_FO: return (char_u *)&(curbuf->b_p_fo); 7884 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert); 7885 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch); 7886 case PV_INF: return (char_u *)&(curbuf->b_p_inf); 7887 case PV_ISK: return (char_u *)&(curbuf->b_p_isk); 7888 #ifdef FEAT_FIND_ID 7889 # ifdef FEAT_EVAL 7890 case PV_INEX: return (char_u *)&(curbuf->b_p_inex); 7891 # endif 7892 #endif 7893 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 7894 case PV_INDE: return (char_u *)&(curbuf->b_p_inde); 7895 case PV_INDK: return (char_u *)&(curbuf->b_p_indk); 7896 #endif 7897 #ifdef FEAT_CRYPT 7898 case PV_KEY: return (char_u *)&(curbuf->b_p_key); 7899 #endif 7900 #ifdef FEAT_LISP 7901 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); 7902 #endif 7903 case PV_ML: return (char_u *)&(curbuf->b_p_ml); 7904 case PV_MPS: return (char_u *)&(curbuf->b_p_mps); 7905 case PV_MA: return (char_u *)&(curbuf->b_p_ma); 7906 case PV_MOD: return (char_u *)&(curbuf->b_changed); 7907 case PV_NF: return (char_u *)&(curbuf->b_p_nf); 7908 #ifdef FEAT_OSFILETYPE 7909 case PV_OFT: return (char_u *)&(curbuf->b_p_oft); 7910 #endif 7911 case PV_PI: return (char_u *)&(curbuf->b_p_pi); 7912 case PV_RO: return (char_u *)&(curbuf->b_p_ro); 7913 #ifdef FEAT_SMARTINDENT 7914 case PV_SI: return (char_u *)&(curbuf->b_p_si); 7915 #endif 7916 #ifndef SHORT_FNAME 7917 case PV_SN: return (char_u *)&(curbuf->b_p_sn); 7918 #endif 7919 case PV_STS: return (char_u *)&(curbuf->b_p_sts); 7920 #ifdef FEAT_SEARCHPATH 7921 case PV_SUA: return (char_u *)&(curbuf->b_p_sua); 7922 #endif 7923 case PV_SWF: return (char_u *)&(curbuf->b_p_swf); 7924 #ifdef FEAT_SYN_HL 7925 case PV_SYN: return (char_u *)&(curbuf->b_p_syn); 7926 #endif 7927 case PV_SW: return (char_u *)&(curbuf->b_p_sw); 7928 case PV_TS: return (char_u *)&(curbuf->b_p_ts); 7929 case PV_TW: return (char_u *)&(curbuf->b_p_tw); 7930 case PV_TX: return (char_u *)&(curbuf->b_p_tx); 7931 case PV_WM: return (char_u *)&(curbuf->b_p_wm); 7932 #ifdef FEAT_KEYMAP 7933 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap); 7934 #endif 7935 default: EMSG(_("E356: get_varp ERROR")); 7936 } 7937 /* always return a valid pointer to avoid a crash! */ 7938 return (char_u *)&(curbuf->b_p_wm); 7939 } 7940 7941 /* 7942 * Get the value of 'equalprg', either the buffer-local one or the global one. 7943 */ 7944 char_u * 7945 get_equalprg() 7946 { 7947 if (*curbuf->b_p_ep == NUL) 7948 return p_ep; 7949 return curbuf->b_p_ep; 7950 } 7951 7952 #if defined(FEAT_WINDOWS) || defined(PROTO) 7953 /* 7954 * Copy options from one window to another. 7955 * Used when splitting a window. 7956 */ 7957 void 7958 win_copy_options(wp_from, wp_to) 7959 win_T *wp_from; 7960 win_T *wp_to; 7961 { 7962 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt); 7963 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt); 7964 # ifdef FEAT_RIGHTLEFT 7965 # ifdef FEAT_FKMAP 7966 /* Is this right? */ 7967 wp_to->w_farsi = wp_from->w_farsi; 7968 # endif 7969 # endif 7970 } 7971 #endif 7972 7973 /* 7974 * Copy the options from one winopt_T to another. 7975 * Doesn't free the old option values in "to", use clear_winopt() for that. 7976 * The 'scroll' option is not copied, because it depends on the window height. 7977 * The 'previewwindow' option is reset, there can be only one preview window. 7978 */ 7979 void 7980 copy_winopt(from, to) 7981 winopt_T *from; 7982 winopt_T *to; 7983 { 7984 #ifdef FEAT_ARABIC 7985 to->wo_arab = from->wo_arab; 7986 #endif 7987 to->wo_list = from->wo_list; 7988 to->wo_nu = from->wo_nu; 7989 #ifdef FEAT_RIGHTLEFT 7990 to->wo_rl = from->wo_rl; 7991 to->wo_rlc = vim_strsave(from->wo_rlc); 7992 #endif 7993 to->wo_wrap = from->wo_wrap; 7994 #ifdef FEAT_LINEBREAK 7995 to->wo_lbr = from->wo_lbr; 7996 #endif 7997 #ifdef FEAT_SCROLLBIND 7998 to->wo_scb = from->wo_scb; 7999 #endif 8000 #ifdef FEAT_DIFF 8001 to->wo_diff = from->wo_diff; 8002 #endif 8003 #ifdef FEAT_FOLDING 8004 to->wo_fdc = from->wo_fdc; 8005 to->wo_fen = from->wo_fen; 8006 to->wo_fdi = vim_strsave(from->wo_fdi); 8007 to->wo_fml = from->wo_fml; 8008 to->wo_fdl = from->wo_fdl; 8009 to->wo_fdm = vim_strsave(from->wo_fdm); 8010 to->wo_fdn = from->wo_fdn; 8011 # ifdef FEAT_EVAL 8012 to->wo_fde = vim_strsave(from->wo_fde); 8013 to->wo_fdt = vim_strsave(from->wo_fdt); 8014 # endif 8015 to->wo_fmr = vim_strsave(from->wo_fmr); 8016 #endif 8017 check_winopt(to); /* don't want NULL pointers */ 8018 } 8019 8020 /* 8021 * Check string options in a window for a NULL value. 8022 */ 8023 void 8024 check_win_options(win) 8025 win_T *win; 8026 { 8027 check_winopt(&win->w_onebuf_opt); 8028 check_winopt(&win->w_allbuf_opt); 8029 } 8030 8031 /* 8032 * Check for NULL pointers in a winopt_T and replace them with empty_option. 8033 */ 8034 /*ARGSUSED*/ 8035 void 8036 check_winopt(wop) 8037 winopt_T *wop; 8038 { 8039 #ifdef FEAT_FOLDING 8040 check_string_option(&wop->wo_fdi); 8041 check_string_option(&wop->wo_fdm); 8042 # ifdef FEAT_EVAL 8043 check_string_option(&wop->wo_fde); 8044 check_string_option(&wop->wo_fdt); 8045 # endif 8046 check_string_option(&wop->wo_fmr); 8047 #endif 8048 #ifdef FEAT_RIGHTLEFT 8049 check_string_option(&wop->wo_rlc); 8050 #endif 8051 } 8052 8053 /* 8054 * Free the allocated memory inside a winopt_T. 8055 */ 8056 /*ARGSUSED*/ 8057 void 8058 clear_winopt(wop) 8059 winopt_T *wop; 8060 { 8061 #ifdef FEAT_FOLDING 8062 clear_string_option(&wop->wo_fdi); 8063 clear_string_option(&wop->wo_fdm); 8064 # ifdef FEAT_EVAL 8065 clear_string_option(&wop->wo_fde); 8066 clear_string_option(&wop->wo_fdt); 8067 # endif 8068 clear_string_option(&wop->wo_fmr); 8069 #endif 8070 #ifdef FEAT_RIGHTLEFT 8071 clear_string_option(&wop->wo_rlc); 8072 #endif 8073 } 8074 8075 /* 8076 * Copy global option values to local options for one buffer. 8077 * Used when creating a new buffer and sometimes when entering a buffer. 8078 * flags: 8079 * BCO_ENTER We will enter the buf buffer. 8080 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when 8081 * appropriate. 8082 * BCO_NOHELP Don't copy the values to a help buffer. 8083 */ 8084 void 8085 buf_copy_options(buf, flags) 8086 buf_T *buf; 8087 int flags; 8088 { 8089 int should_copy = TRUE; 8090 char_u *save_p_isk = NULL; /* init for GCC */ 8091 int dont_do_help; 8092 int did_isk = FALSE; 8093 8094 /* 8095 * Don't do anything of the buffer is invalid. 8096 */ 8097 if (buf == NULL || !buf_valid(buf)) 8098 return; 8099 8100 /* 8101 * Skip this when the option defaults have not been set yet. Happens when 8102 * main() allocates the first buffer. 8103 */ 8104 if (p_cpo != NULL) 8105 { 8106 /* 8107 * Always copy when entering and 'cpo' contains 'S'. 8108 * Don't copy when already initialized. 8109 * Don't copy when 'cpo' contains 's' and not entering. 8110 * 'S' BCO_ENTER initialized 's' should_copy 8111 * yes yes X X TRUE 8112 * yes no yes X FALSE 8113 * no X yes X FALSE 8114 * X no no yes FALSE 8115 * X no no no TRUE 8116 * no yes no X TRUE 8117 */ 8118 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER)) 8119 && (buf->b_p_initialized 8120 || (!(flags & BCO_ENTER) 8121 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) 8122 should_copy = FALSE; 8123 8124 if (should_copy || (flags & BCO_ALWAYS)) 8125 { 8126 /* Don't copy the options specific to a help buffer when 8127 * BCO_NOHELP is given or the options were initialized already 8128 * (jumping back to a help file with CTRL-T or CTRL-O) */ 8129 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) 8130 || buf->b_p_initialized; 8131 if (dont_do_help) /* don't free b_p_isk */ 8132 { 8133 save_p_isk = buf->b_p_isk; 8134 buf->b_p_isk = NULL; 8135 } 8136 /* 8137 * Always free the allocated strings. 8138 * If not already initialized, set 'readonly' and copy 'fileformat'. 8139 */ 8140 if (!buf->b_p_initialized) 8141 { 8142 free_buf_options(buf, TRUE); 8143 buf->b_p_ro = FALSE; /* don't copy readonly */ 8144 buf->b_p_tx = p_tx; 8145 #ifdef FEAT_MBYTE 8146 buf->b_p_fenc = vim_strsave(p_fenc); 8147 #endif 8148 buf->b_p_ff = vim_strsave(p_ff); 8149 #if defined(FEAT_QUICKFIX) 8150 buf->b_p_bh = empty_option; 8151 buf->b_p_bt = empty_option; 8152 #endif 8153 } 8154 else 8155 free_buf_options(buf, FALSE); 8156 8157 buf->b_p_ai = p_ai; 8158 buf->b_p_ai_nopaste = p_ai_nopaste; 8159 buf->b_p_sw = p_sw; 8160 buf->b_p_tw = p_tw; 8161 buf->b_p_tw_nopaste = p_tw_nopaste; 8162 buf->b_p_tw_nobin = p_tw_nobin; 8163 buf->b_p_wm = p_wm; 8164 buf->b_p_wm_nopaste = p_wm_nopaste; 8165 buf->b_p_wm_nobin = p_wm_nobin; 8166 buf->b_p_bin = p_bin; 8167 buf->b_p_et = p_et; 8168 buf->b_p_et_nobin = p_et_nobin; 8169 buf->b_p_ml = p_ml; 8170 buf->b_p_ml_nobin = p_ml_nobin; 8171 buf->b_p_inf = p_inf; 8172 buf->b_p_swf = p_swf; 8173 #ifdef FEAT_INS_EXPAND 8174 buf->b_p_cpt = vim_strsave(p_cpt); 8175 #endif 8176 buf->b_p_sts = p_sts; 8177 buf->b_p_sts_nopaste = p_sts_nopaste; 8178 #ifndef SHORT_FNAME 8179 buf->b_p_sn = p_sn; 8180 #endif 8181 #ifdef FEAT_COMMENTS 8182 buf->b_p_com = vim_strsave(p_com); 8183 #endif 8184 #ifdef FEAT_FOLDING 8185 buf->b_p_cms = vim_strsave(p_cms); 8186 #endif 8187 buf->b_p_fo = vim_strsave(p_fo); 8188 buf->b_p_nf = vim_strsave(p_nf); 8189 buf->b_p_mps = vim_strsave(p_mps); 8190 #ifdef FEAT_SMARTINDENT 8191 buf->b_p_si = p_si; 8192 #endif 8193 buf->b_p_ci = p_ci; 8194 #ifdef FEAT_CINDENT 8195 buf->b_p_cin = p_cin; 8196 buf->b_p_cink = vim_strsave(p_cink); 8197 buf->b_p_cino = vim_strsave(p_cino); 8198 #endif 8199 #ifdef FEAT_AUTOCMD 8200 /* Don't copy 'filetype', it must be detected */ 8201 buf->b_p_ft = empty_option; 8202 #endif 8203 #ifdef FEAT_OSFILETYPE 8204 buf->b_p_oft = vim_strsave(p_oft); 8205 #endif 8206 buf->b_p_pi = p_pi; 8207 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 8208 buf->b_p_cinw = vim_strsave(p_cinw); 8209 #endif 8210 #ifdef FEAT_LISP 8211 buf->b_p_lisp = p_lisp; 8212 #endif 8213 #ifdef FEAT_SYN_HL 8214 /* Don't copy 'syntax', it must be set */ 8215 buf->b_p_syn = empty_option; 8216 #endif 8217 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 8218 buf->b_p_inde = vim_strsave(p_inde); 8219 buf->b_p_indk = vim_strsave(p_indk); 8220 #endif 8221 #ifdef FEAT_CRYPT 8222 buf->b_p_key = vim_strsave(p_key); 8223 #endif 8224 #ifdef FEAT_SEARCHPATH 8225 buf->b_p_sua = vim_strsave(p_sua); 8226 #endif 8227 #ifdef FEAT_KEYMAP 8228 buf->b_p_keymap = vim_strsave(p_keymap); 8229 buf->b_kmap_state |= KEYMAP_INIT; 8230 #endif 8231 /* This isn't really an option, but copying the langmap and IME 8232 * state from the current buffer is better than resetting it. */ 8233 buf->b_p_iminsert = p_iminsert; 8234 buf->b_p_imsearch = p_imsearch; 8235 8236 /* options that are normally global but also have a local value 8237 * are not copied, start using the global value */ 8238 buf->b_p_ar = -1; 8239 #ifdef FEAT_QUICKFIX 8240 buf->b_p_gp = empty_option; 8241 buf->b_p_mp = empty_option; 8242 buf->b_p_efm = empty_option; 8243 #endif 8244 buf->b_p_ep = empty_option; 8245 buf->b_p_kp = empty_option; 8246 buf->b_p_path = empty_option; 8247 buf->b_p_tags = empty_option; 8248 #ifdef FEAT_FIND_ID 8249 buf->b_p_def = empty_option; 8250 buf->b_p_inc = empty_option; 8251 # ifdef FEAT_EVAL 8252 buf->b_p_inex = vim_strsave(p_inex); 8253 # endif 8254 #endif 8255 #ifdef FEAT_INS_EXPAND 8256 buf->b_p_dict = empty_option; 8257 buf->b_p_tsr = empty_option; 8258 #endif 8259 8260 /* 8261 * Don't copy the options set by ex_help(), use the saved values, 8262 * when going from a help buffer to a non-help buffer. 8263 * Don't touch these at all when BCO_NOHELP is used and going from 8264 * or to a help buffer. 8265 */ 8266 if (dont_do_help) 8267 buf->b_p_isk = save_p_isk; 8268 else 8269 { 8270 buf->b_p_isk = vim_strsave(p_isk); 8271 did_isk = TRUE; 8272 buf->b_p_ts = p_ts; 8273 buf->b_help = FALSE; 8274 #ifdef FEAT_QUICKFIX 8275 if (buf->b_p_bt[0] == 'h') 8276 clear_string_option(&buf->b_p_bt); 8277 #endif 8278 buf->b_p_ma = p_ma; 8279 } 8280 } 8281 8282 /* 8283 * When the options should be copied (ignoring BCO_ALWAYS), set the 8284 * flag that indicates that the options have been initialized. 8285 */ 8286 if (should_copy) 8287 buf->b_p_initialized = TRUE; 8288 } 8289 8290 check_buf_options(buf); /* make sure we don't have NULLs */ 8291 if (did_isk) 8292 (void)buf_init_chartab(buf, FALSE); 8293 } 8294 8295 /* 8296 * Reset the 'modifiable' option and its default value. 8297 */ 8298 void 8299 reset_modifiable() 8300 { 8301 int opt_idx; 8302 8303 curbuf->b_p_ma = FALSE; 8304 p_ma = FALSE; 8305 opt_idx = findoption((char_u *)"ma"); 8306 options[opt_idx].def_val[VI_DEFAULT] = FALSE; 8307 } 8308 8309 /* 8310 * Set the global value for 'iminsert' to the local value. 8311 */ 8312 void 8313 set_iminsert_global() 8314 { 8315 p_iminsert = curbuf->b_p_iminsert; 8316 } 8317 8318 /* 8319 * Set the global value for 'imsearch' to the local value. 8320 */ 8321 void 8322 set_imsearch_global() 8323 { 8324 p_imsearch = curbuf->b_p_imsearch; 8325 } 8326 8327 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) 8328 static int expand_option_idx = -1; 8329 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL}; 8330 static int expand_option_flags = 0; 8331 8332 void 8333 set_context_in_set_cmd(xp, arg, opt_flags) 8334 expand_T *xp; 8335 char_u *arg; 8336 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */ 8337 { 8338 int nextchar; 8339 long_u flags = 0; /* init for GCC */ 8340 int opt_idx = 0; /* init for GCC */ 8341 char_u *p; 8342 char_u *s; 8343 int is_term_option = FALSE; 8344 int key; 8345 8346 expand_option_flags = opt_flags; 8347 8348 xp->xp_context = EXPAND_SETTINGS; 8349 if (*arg == NUL) 8350 { 8351 xp->xp_pattern = arg; 8352 return; 8353 } 8354 p = arg + STRLEN(arg) - 1; 8355 if (*p == ' ' && *(p - 1) != '\\') 8356 { 8357 xp->xp_pattern = p + 1; 8358 return; 8359 } 8360 while (p > arg) 8361 { 8362 s = p; 8363 /* count number of backslashes before ' ' or ',' */ 8364 if (*p == ' ' || *p == ',') 8365 { 8366 while (s > arg && *(s - 1) == '\\') 8367 --s; 8368 } 8369 /* break at a space with an even number of backslashes */ 8370 if (*p == ' ' && ((p - s) & 1) == 0) 8371 { 8372 ++p; 8373 break; 8374 } 8375 --p; 8376 } 8377 if (STRNCMP(p, "no", 2) == 0) 8378 { 8379 xp->xp_context = EXPAND_BOOL_SETTINGS; 8380 p += 2; 8381 } 8382 if (STRNCMP(p, "inv", 3) == 0) 8383 { 8384 xp->xp_context = EXPAND_BOOL_SETTINGS; 8385 p += 3; 8386 } 8387 xp->xp_pattern = arg = p; 8388 if (*arg == '<') 8389 { 8390 while (*p != '>') 8391 if (*p++ == NUL) /* expand terminal option name */ 8392 return; 8393 key = get_special_key_code(arg + 1); 8394 if (key == 0) /* unknown name */ 8395 { 8396 xp->xp_context = EXPAND_NOTHING; 8397 return; 8398 } 8399 nextchar = *++p; 8400 is_term_option = TRUE; 8401 expand_option_name[2] = KEY2TERMCAP0(key); 8402 expand_option_name[3] = KEY2TERMCAP1(key); 8403 } 8404 else 8405 { 8406 if (p[0] == 't' && p[1] == '_') 8407 { 8408 p += 2; 8409 if (*p != NUL) 8410 ++p; 8411 if (*p == NUL) 8412 return; /* expand option name */ 8413 nextchar = *++p; 8414 is_term_option = TRUE; 8415 expand_option_name[2] = p[-2]; 8416 expand_option_name[3] = p[-1]; 8417 } 8418 else 8419 { 8420 /* Allow * wildcard */ 8421 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') 8422 p++; 8423 if (*p == NUL) 8424 return; 8425 nextchar = *p; 8426 *p = NUL; 8427 opt_idx = findoption(arg); 8428 *p = nextchar; 8429 if (opt_idx == -1 || options[opt_idx].var == NULL) 8430 { 8431 xp->xp_context = EXPAND_NOTHING; 8432 return; 8433 } 8434 flags = options[opt_idx].flags; 8435 if (flags & P_BOOL) 8436 { 8437 xp->xp_context = EXPAND_NOTHING; 8438 return; 8439 } 8440 } 8441 } 8442 /* handle "-=" and "+=" */ 8443 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=') 8444 { 8445 ++p; 8446 nextchar = '='; 8447 } 8448 if ((nextchar != '=' && nextchar != ':') 8449 || xp->xp_context == EXPAND_BOOL_SETTINGS) 8450 { 8451 xp->xp_context = EXPAND_UNSUCCESSFUL; 8452 return; 8453 } 8454 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL) 8455 { 8456 xp->xp_context = EXPAND_OLD_SETTING; 8457 if (is_term_option) 8458 expand_option_idx = -1; 8459 else 8460 expand_option_idx = opt_idx; 8461 xp->xp_pattern = p + 1; 8462 return; 8463 } 8464 xp->xp_context = EXPAND_NOTHING; 8465 if (is_term_option || (flags & P_NUM)) 8466 return; 8467 8468 xp->xp_pattern = p + 1; 8469 8470 if (flags & P_EXPAND) 8471 { 8472 p = options[opt_idx].var; 8473 if (p == (char_u *)&p_bdir 8474 || p == (char_u *)&p_dir 8475 || p == (char_u *)&p_path 8476 || p == (char_u *)&p_rtp 8477 #ifdef FEAT_SEARCHPATH 8478 || p == (char_u *)&p_cdpath 8479 #endif 8480 #ifdef FEAT_SESSION 8481 || p == (char_u *)&p_vdir 8482 #endif 8483 ) 8484 { 8485 xp->xp_context = EXPAND_DIRECTORIES; 8486 if (p == (char_u *)&p_path 8487 #ifdef FEAT_SEARCHPATH 8488 || p == (char_u *)&p_cdpath 8489 #endif 8490 ) 8491 xp->xp_backslash = XP_BS_THREE; 8492 else 8493 xp->xp_backslash = XP_BS_ONE; 8494 } 8495 else 8496 { 8497 xp->xp_context = EXPAND_FILES; 8498 /* for 'tags' need three backslashes for a space */ 8499 if (p == (char_u *)&p_tags) 8500 xp->xp_backslash = XP_BS_THREE; 8501 else 8502 xp->xp_backslash = XP_BS_ONE; 8503 } 8504 } 8505 8506 /* For an option that is a list of file names, find the start of the 8507 * last file name. */ 8508 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p) 8509 { 8510 /* count number of backslashes before ' ' or ',' */ 8511 if (*p == ' ' || *p == ',') 8512 { 8513 s = p; 8514 while (s > xp->xp_pattern && *(s - 1) == '\\') 8515 --s; 8516 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3)) 8517 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0)) 8518 { 8519 xp->xp_pattern = p + 1; 8520 break; 8521 } 8522 } 8523 } 8524 8525 return; 8526 } 8527 8528 int 8529 ExpandSettings(xp, regmatch, num_file, file) 8530 expand_T *xp; 8531 regmatch_T *regmatch; 8532 int *num_file; 8533 char_u ***file; 8534 { 8535 int num_normal = 0; /* Nr of matching non-term-code settings */ 8536 int num_term = 0; /* Nr of matching terminal code settings */ 8537 int opt_idx; 8538 int match; 8539 int count = 0; 8540 char_u *str; 8541 int loop; 8542 int is_term_opt; 8543 char_u name_buf[MAX_KEY_NAME_LEN]; 8544 static char *(names[]) = {"all", "termcap"}; 8545 int ic = regmatch->rm_ic; /* remember the ignore-case flag */ 8546 8547 /* do this loop twice: 8548 * loop == 0: count the number of matching options 8549 * loop == 1: copy the matching options into allocated memory 8550 */ 8551 for (loop = 0; loop <= 1; ++loop) 8552 { 8553 regmatch->rm_ic = ic; 8554 if (xp->xp_context != EXPAND_BOOL_SETTINGS) 8555 { 8556 for (match = 0; match < sizeof(names) / sizeof(char *); ++match) 8557 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0)) 8558 { 8559 if (loop == 0) 8560 num_normal++; 8561 else 8562 (*file)[count++] = vim_strsave((char_u *)names[match]); 8563 } 8564 } 8565 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; 8566 opt_idx++) 8567 { 8568 if (options[opt_idx].var == NULL) 8569 continue; 8570 if (xp->xp_context == EXPAND_BOOL_SETTINGS 8571 && !(options[opt_idx].flags & P_BOOL)) 8572 continue; 8573 is_term_opt = istermoption(&options[opt_idx]); 8574 if (is_term_opt && num_normal > 0) 8575 continue; 8576 match = FALSE; 8577 if (vim_regexec(regmatch, str, (colnr_T)0) 8578 || (options[opt_idx].shortname != NULL 8579 && vim_regexec(regmatch, 8580 (char_u *)options[opt_idx].shortname, (colnr_T)0))) 8581 match = TRUE; 8582 else if (is_term_opt) 8583 { 8584 name_buf[0] = '<'; 8585 name_buf[1] = 't'; 8586 name_buf[2] = '_'; 8587 name_buf[3] = str[2]; 8588 name_buf[4] = str[3]; 8589 name_buf[5] = '>'; 8590 name_buf[6] = NUL; 8591 if (vim_regexec(regmatch, name_buf, (colnr_T)0)) 8592 { 8593 match = TRUE; 8594 str = name_buf; 8595 } 8596 } 8597 if (match) 8598 { 8599 if (loop == 0) 8600 { 8601 if (is_term_opt) 8602 num_term++; 8603 else 8604 num_normal++; 8605 } 8606 else 8607 (*file)[count++] = vim_strsave(str); 8608 } 8609 } 8610 /* 8611 * Check terminal key codes, these are not in the option table 8612 */ 8613 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0) 8614 { 8615 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++) 8616 { 8617 if (!isprint(str[0]) || !isprint(str[1])) 8618 continue; 8619 8620 name_buf[0] = 't'; 8621 name_buf[1] = '_'; 8622 name_buf[2] = str[0]; 8623 name_buf[3] = str[1]; 8624 name_buf[4] = NUL; 8625 8626 match = FALSE; 8627 if (vim_regexec(regmatch, name_buf, (colnr_T)0)) 8628 match = TRUE; 8629 else 8630 { 8631 name_buf[0] = '<'; 8632 name_buf[1] = 't'; 8633 name_buf[2] = '_'; 8634 name_buf[3] = str[0]; 8635 name_buf[4] = str[1]; 8636 name_buf[5] = '>'; 8637 name_buf[6] = NUL; 8638 8639 if (vim_regexec(regmatch, name_buf, (colnr_T)0)) 8640 match = TRUE; 8641 } 8642 if (match) 8643 { 8644 if (loop == 0) 8645 num_term++; 8646 else 8647 (*file)[count++] = vim_strsave(name_buf); 8648 } 8649 } 8650 8651 /* 8652 * Check special key names. 8653 */ 8654 regmatch->rm_ic = TRUE; /* ignore case here */ 8655 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) 8656 { 8657 name_buf[0] = '<'; 8658 STRCPY(name_buf + 1, str); 8659 STRCAT(name_buf, ">"); 8660 8661 if (vim_regexec(regmatch, name_buf, (colnr_T)0)) 8662 { 8663 if (loop == 0) 8664 num_term++; 8665 else 8666 (*file)[count++] = vim_strsave(name_buf); 8667 } 8668 } 8669 } 8670 if (loop == 0) 8671 { 8672 if (num_normal > 0) 8673 *num_file = num_normal; 8674 else if (num_term > 0) 8675 *num_file = num_term; 8676 else 8677 return OK; 8678 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *))); 8679 if (*file == NULL) 8680 { 8681 *file = (char_u **)""; 8682 return FAIL; 8683 } 8684 } 8685 } 8686 return OK; 8687 } 8688 8689 int 8690 ExpandOldSetting(num_file, file) 8691 int *num_file; 8692 char_u ***file; 8693 { 8694 char_u *var = NULL; /* init for GCC */ 8695 char_u *buf; 8696 8697 *num_file = 0; 8698 *file = (char_u **)alloc((unsigned)sizeof(char_u *)); 8699 if (*file == NULL) 8700 return FAIL; 8701 8702 /* 8703 * For a terminal key code expand_option_idx is < 0. 8704 */ 8705 if (expand_option_idx < 0) 8706 { 8707 var = find_termcode(expand_option_name + 2); 8708 if (var == NULL) 8709 expand_option_idx = findoption(expand_option_name); 8710 } 8711 8712 if (expand_option_idx >= 0) 8713 { 8714 /* put string of option value in NameBuff */ 8715 option_value2string(&options[expand_option_idx], expand_option_flags); 8716 var = NameBuff; 8717 } 8718 else if (var == NULL) 8719 var = (char_u *)""; 8720 8721 /* A backslash is required before some characters. This is the reverse of 8722 * what happens in do_set(). */ 8723 buf = vim_strsave_escaped(var, escape_chars); 8724 8725 if (buf == NULL) 8726 { 8727 vim_free(*file); 8728 *file = NULL; 8729 return FAIL; 8730 } 8731 8732 #ifdef BACKSLASH_IN_FILENAME 8733 /* For MS-Windows et al. we don't double backslashes at the start and 8734 * before a file name character. */ 8735 for (var = buf; *var != NUL; ) 8736 { 8737 if (var[0] == '\\' && var[1] == '\\' 8738 && expand_option_idx >= 0 8739 && (options[expand_option_idx].flags & P_EXPAND) 8740 && vim_isfilec(var[2]) 8741 && (var[2] != '\\' || (var == buf && var[4] != '\\'))) 8742 mch_memmove(var, var + 1, STRLEN(var)); 8743 #ifdef FEAT_MBYTE 8744 else if (has_mbyte) 8745 var += (*mb_ptr2len_check)(var) - 1; 8746 #endif 8747 ++var; 8748 } 8749 #endif 8750 8751 *file[0] = buf; 8752 *num_file = 1; 8753 return OK; 8754 } 8755 #endif 8756 8757 /* 8758 * Get the value for the numeric or string option *opp in a nice format into 8759 * NameBuff[]. Must not be called with a hidden option! 8760 */ 8761 static void 8762 option_value2string(opp, opt_flags) 8763 struct vimoption *opp; 8764 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */ 8765 { 8766 char_u *varp; 8767 8768 varp = get_varp_scope(opp, opt_flags); 8769 8770 if (opp->flags & P_NUM) 8771 { 8772 long wc = 0; 8773 8774 if (wc_use_keyname(varp, &wc)) 8775 STRCPY(NameBuff, get_special_key_name((int)wc, 0)); 8776 else if (wc != 0) 8777 STRCPY(NameBuff, transchar((int)wc)); 8778 else 8779 sprintf((char *)NameBuff, "%ld", *(long *)varp); 8780 } 8781 else /* P_STRING */ 8782 { 8783 varp = *(char_u **)(varp); 8784 if (varp == NULL) /* just in case */ 8785 NameBuff[0] = NUL; 8786 #ifdef FEAT_CRYPT 8787 /* don't show the actual value of 'key', only that it's set */ 8788 if (opp->var == (char_u *)&p_key && *varp) 8789 STRCPY(NameBuff, "*****"); 8790 #endif 8791 else if (opp->flags & P_EXPAND) 8792 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); 8793 /* Translate 'pastetoggle' into special key names */ 8794 else if ((char_u **)opp->var == &p_pt) 8795 str2specialbuf(p_pt, NameBuff, MAXPATHL); 8796 else 8797 STRNCPY(NameBuff, varp, MAXPATHL); 8798 } 8799 } 8800 8801 /* 8802 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be 8803 * printed as a keyname. 8804 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'. 8805 */ 8806 static int 8807 wc_use_keyname(varp, wcp) 8808 char_u *varp; 8809 long *wcp; 8810 { 8811 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) 8812 { 8813 *wcp = *(long *)varp; 8814 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0) 8815 return TRUE; 8816 } 8817 return FALSE; 8818 } 8819 8820 #ifdef FEAT_LANGMAP 8821 /* 8822 * Any character has an equivalent character. This is used for keyboards that 8823 * have a special language mode that sends characters above 128 (although 8824 * other characters can be translated too). 8825 */ 8826 8827 /* 8828 * char_u langmap_mapchar[256]; 8829 * Normally maps each of the 128 upper chars to an <128 ascii char; used to 8830 * "translate" native lang chars in normal mode or some cases of 8831 * insert mode without having to tediously switch lang mode back&forth. 8832 */ 8833 8834 static void 8835 langmap_init() 8836 { 8837 int i; 8838 8839 for (i = 0; i < 256; i++) /* we init with a-one-to one map */ 8840 langmap_mapchar[i] = i; 8841 } 8842 8843 /* 8844 * Called when langmap option is set; the language map can be 8845 * changed at any time! 8846 */ 8847 static void 8848 langmap_set() 8849 { 8850 char_u *p; 8851 char_u *p2; 8852 int from, to; 8853 8854 langmap_init(); /* back to one-to-one map first */ 8855 8856 for (p = p_langmap; p[0] != NUL; ) 8857 { 8858 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; ++p2) 8859 { 8860 if (p2[0] == '\\' && p2[1] != NUL) 8861 ++p2; 8862 #ifdef FEAT_MBYTE 8863 p2 += (*mb_ptr2len_check)(p2) - 1; 8864 #endif 8865 } 8866 if (p2[0] == ';') 8867 ++p2; /* abcd;ABCD form, p2 points to A */ 8868 else 8869 p2 = NULL; /* aAbBcCdD form, p2 is NULL */ 8870 while (p[0]) 8871 { 8872 if (p[0] == '\\' && p[1] != NUL) 8873 ++p; 8874 #ifdef FEAT_MBYTE 8875 from = (*mb_ptr2char)(p); 8876 #else 8877 from = p[0]; 8878 #endif 8879 if (p2 == NULL) 8880 { 8881 #ifdef FEAT_MBYTE 8882 p += (*mb_ptr2len_check)(p); 8883 #else 8884 ++p; 8885 #endif 8886 if (p[0] == '\\') 8887 ++p; 8888 #ifdef FEAT_MBYTE 8889 to = (*mb_ptr2char)(p); 8890 #else 8891 to = p[0]; 8892 #endif 8893 } 8894 else 8895 { 8896 if (p2[0] == '\\') 8897 ++p2; 8898 #ifdef FEAT_MBYTE 8899 to = (*mb_ptr2char)(p2); 8900 #else 8901 to = p2[0]; 8902 #endif 8903 } 8904 if (to == NUL) 8905 { 8906 EMSG2(_("E357: 'langmap': Matching character missing for %s"), 8907 transchar(from)); 8908 return; 8909 } 8910 langmap_mapchar[from & 255] = to; 8911 8912 /* Advance to next pair */ 8913 #ifdef FEAT_MBYTE 8914 p += (*mb_ptr2len_check)(p); 8915 #else 8916 ++p; 8917 #endif 8918 if (p2 == NULL) 8919 { 8920 if (p[0] == ',') 8921 { 8922 ++p; 8923 break; 8924 } 8925 } 8926 else 8927 { 8928 #ifdef FEAT_MBYTE 8929 p2 += (*mb_ptr2len_check)(p2); 8930 #else 8931 ++p2; 8932 #endif 8933 if (*p == ';') 8934 { 8935 p = p2; 8936 if (p[0] != NUL) 8937 { 8938 if (p[0] != ',') 8939 { 8940 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p); 8941 return; 8942 } 8943 ++p; 8944 } 8945 break; 8946 } 8947 } 8948 } 8949 } 8950 } 8951 #endif 8952 8953 /* 8954 * Return TRUE if format option 'x' is in effect. 8955 * Take care of no formatting when 'paste' is set. 8956 */ 8957 int 8958 has_format_option(x) 8959 int x; 8960 { 8961 if (p_paste) 8962 return FALSE; 8963 return (vim_strchr(curbuf->b_p_fo, x) != NULL); 8964 } 8965 8966 /* 8967 * Return TRUE if "x" is present in 'shortmess' option, or 8968 * 'shortmess' contains 'a' and "x" is present in SHM_A. 8969 */ 8970 int 8971 shortmess(x) 8972 int x; 8973 { 8974 return ( vim_strchr(p_shm, x) != NULL 8975 || (vim_strchr(p_shm, 'a') != NULL 8976 && vim_strchr((char_u *)SHM_A, x) != NULL)); 8977 } 8978 8979 /* 8980 * paste_option_changed() - Called after p_paste was set or reset. 8981 */ 8982 static void 8983 paste_option_changed() 8984 { 8985 static int old_p_paste = FALSE; 8986 static int save_sm = 0; 8987 #ifdef FEAT_CMDL_INFO 8988 static int save_ru = 0; 8989 #endif 8990 #ifdef FEAT_RIGHTLEFT 8991 static int save_ri = 0; 8992 static int save_hkmap = 0; 8993 #endif 8994 buf_T *buf; 8995 8996 if (p_paste) 8997 { 8998 /* 8999 * Paste switched from off to on. 9000 * Save the current values, so they can be restored later. 9001 */ 9002 if (!old_p_paste) 9003 { 9004 /* save options for each buffer */ 9005 for (buf = firstbuf; buf != NULL; buf = buf->b_next) 9006 { 9007 buf->b_p_tw_nopaste = buf->b_p_tw; 9008 buf->b_p_wm_nopaste = buf->b_p_wm; 9009 buf->b_p_sts_nopaste = buf->b_p_sts; 9010 buf->b_p_ai_nopaste = buf->b_p_ai; 9011 } 9012 9013 /* save global options */ 9014 save_sm = p_sm; 9015 #ifdef FEAT_CMDL_INFO 9016 save_ru = p_ru; 9017 #endif 9018 #ifdef FEAT_RIGHTLEFT 9019 save_ri = p_ri; 9020 save_hkmap = p_hkmap; 9021 #endif 9022 /* save global values for local buffer options */ 9023 p_tw_nopaste = p_tw; 9024 p_wm_nopaste = p_wm; 9025 p_sts_nopaste = p_sts; 9026 p_ai_nopaste = p_ai; 9027 } 9028 9029 /* 9030 * Always set the option values, also when 'paste' is set when it is 9031 * already on. 9032 */ 9033 /* set options for each buffer */ 9034 for (buf = firstbuf; buf != NULL; buf = buf->b_next) 9035 { 9036 buf->b_p_tw = 0; /* textwidth is 0 */ 9037 buf->b_p_wm = 0; /* wrapmargin is 0 */ 9038 buf->b_p_sts = 0; /* softtabstop is 0 */ 9039 buf->b_p_ai = 0; /* no auto-indent */ 9040 } 9041 9042 /* set global options */ 9043 p_sm = 0; /* no showmatch */ 9044 #ifdef FEAT_CMDL_INFO 9045 # ifdef FEAT_WINDOWS 9046 if (p_ru) 9047 status_redraw_all(); /* redraw to remove the ruler */ 9048 # endif 9049 p_ru = 0; /* no ruler */ 9050 #endif 9051 #ifdef FEAT_RIGHTLEFT 9052 p_ri = 0; /* no reverse insert */ 9053 p_hkmap = 0; /* no Hebrew keyboard */ 9054 #endif 9055 /* set global values for local buffer options */ 9056 p_tw = 0; 9057 p_wm = 0; 9058 p_sts = 0; 9059 p_ai = 0; 9060 } 9061 9062 /* 9063 * Paste switched from on to off: Restore saved values. 9064 */ 9065 else if (old_p_paste) 9066 { 9067 /* restore options for each buffer */ 9068 for (buf = firstbuf; buf != NULL; buf = buf->b_next) 9069 { 9070 buf->b_p_tw = buf->b_p_tw_nopaste; 9071 buf->b_p_wm = buf->b_p_wm_nopaste; 9072 buf->b_p_sts = buf->b_p_sts_nopaste; 9073 buf->b_p_ai = buf->b_p_ai_nopaste; 9074 } 9075 9076 /* restore global options */ 9077 p_sm = save_sm; 9078 #ifdef FEAT_CMDL_INFO 9079 # ifdef FEAT_WINDOWS 9080 if (p_ru != save_ru) 9081 status_redraw_all(); /* redraw to draw the ruler */ 9082 # endif 9083 p_ru = save_ru; 9084 #endif 9085 #ifdef FEAT_RIGHTLEFT 9086 p_ri = save_ri; 9087 p_hkmap = save_hkmap; 9088 #endif 9089 /* set global values for local buffer options */ 9090 p_tw = p_tw_nopaste; 9091 p_wm = p_wm_nopaste; 9092 p_sts = p_sts_nopaste; 9093 p_ai = p_ai_nopaste; 9094 } 9095 9096 old_p_paste = p_paste; 9097 } 9098 9099 /* 9100 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found. 9101 * 9102 * Reset 'compatible' and set the values for options that didn't get set yet 9103 * to the Vim defaults. 9104 * Don't do this if the 'compatible' option has been set or reset before. 9105 */ 9106 void 9107 vimrc_found() 9108 { 9109 int opt_idx; 9110 9111 if (!option_was_set((char_u *)"cp")) 9112 { 9113 p_cp = FALSE; 9114 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) 9115 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF))) 9116 set_option_default(opt_idx, OPT_FREE, FALSE); 9117 didset_options(); 9118 } 9119 } 9120 9121 /* 9122 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg. 9123 */ 9124 void 9125 change_compatible(on) 9126 int on; 9127 { 9128 if (p_cp != on) 9129 { 9130 p_cp = on; 9131 compatible_set(); 9132 } 9133 options[findoption((char_u *)"cp")].flags |= P_WAS_SET; 9134 } 9135 9136 /* 9137 * Return TRUE when option "name" has been set. 9138 */ 9139 int 9140 option_was_set(name) 9141 char_u *name; 9142 { 9143 int idx; 9144 9145 idx = findoption(name); 9146 if (idx < 0) /* unknown option */ 9147 return FALSE; 9148 if (options[idx].flags & P_WAS_SET) 9149 return TRUE; 9150 return FALSE; 9151 } 9152 9153 /* 9154 * compatible_set() - Called when 'compatible' has been set or unset. 9155 * 9156 * When 'compatible' set: Set all relevant options (those that have the P_VIM) 9157 * flag) to a Vi compatible value. 9158 * When 'compatible' is unset: Set all options that have a different default 9159 * for Vim (without the P_VI_DEF flag) to that default. 9160 */ 9161 static void 9162 compatible_set() 9163 { 9164 int opt_idx; 9165 9166 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) 9167 if ( ((options[opt_idx].flags & P_VIM) && p_cp) 9168 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp)) 9169 set_option_default(opt_idx, OPT_FREE, p_cp); 9170 didset_options(); 9171 } 9172 9173 #ifdef FEAT_LINEBREAK 9174 9175 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) 9176 /* Borland C++ screws up loop optimisation here (negri) */ 9177 # pragma option -O-l 9178 # endif 9179 9180 /* 9181 * fill_breakat_flags() -- called when 'breakat' changes value. 9182 */ 9183 static void 9184 fill_breakat_flags() 9185 { 9186 char_u *c; 9187 int i; 9188 9189 for (i = 0; i < 256; i++) 9190 breakat_flags[i] = FALSE; 9191 9192 if (p_breakat != NULL) 9193 for (c = p_breakat; *c; c++) 9194 breakat_flags[*c] = TRUE; 9195 } 9196 9197 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) 9198 # pragma option -O.l 9199 # endif 9200 9201 #endif 9202 9203 /* 9204 * Check an option that can be a range of string values. 9205 * 9206 * Return OK for correct value, FAIL otherwise. 9207 * Empty is always OK. 9208 */ 9209 static int 9210 check_opt_strings(val, values, list) 9211 char_u *val; 9212 char **values; 9213 int list; /* when TRUE: accept a list of values */ 9214 { 9215 return opt_strings_flags(val, values, NULL, list); 9216 } 9217 9218 /* 9219 * Handle an option that can be a range of string values. 9220 * Set a flag in "*flagp" for each string present. 9221 * 9222 * Return OK for correct value, FAIL otherwise. 9223 * Empty is always OK. 9224 */ 9225 static int 9226 opt_strings_flags(val, values, flagp, list) 9227 char_u *val; /* new value */ 9228 char **values; /* array of valid string values */ 9229 unsigned *flagp; 9230 int list; /* when TRUE: accept a list of values */ 9231 { 9232 int i; 9233 int len; 9234 unsigned new_flags = 0; 9235 9236 while (*val) 9237 { 9238 for (i = 0; ; ++i) 9239 { 9240 if (values[i] == NULL) /* val not found in values[] */ 9241 return FAIL; 9242 9243 len = (int)STRLEN(values[i]); 9244 if (STRNCMP(values[i], val, len) == 0 9245 && ((list && val[len] == ',') || val[len] == NUL)) 9246 { 9247 val += len + (val[len] == ','); 9248 new_flags |= (1 << i); 9249 break; /* check next item in val list */ 9250 } 9251 } 9252 } 9253 if (flagp != NULL) 9254 *flagp = new_flags; 9255 9256 return OK; 9257 } 9258 9259 /* 9260 * Read the 'wildmode' option, fill wim_flags[]. 9261 */ 9262 static int 9263 check_opt_wim() 9264 { 9265 char_u new_wim_flags[4]; 9266 char_u *p; 9267 int i; 9268 int idx = 0; 9269 9270 for (i = 0; i < 4; ++i) 9271 new_wim_flags[i] = 0; 9272 9273 for (p = p_wim; *p; ++p) 9274 { 9275 for (i = 0; ASCII_ISALPHA(p[i]); ++i) 9276 ; 9277 if (p[i] != NUL && p[i] != ',' && p[i] != ':') 9278 return FAIL; 9279 if (i == 7 && STRNCMP(p, "longest", 7) == 0) 9280 new_wim_flags[idx] |= WIM_LONGEST; 9281 else if (i == 4 && STRNCMP(p, "full", 4) == 0) 9282 new_wim_flags[idx] |= WIM_FULL; 9283 else if (i == 4 && STRNCMP(p, "list", 4) == 0) 9284 new_wim_flags[idx] |= WIM_LIST; 9285 else 9286 return FAIL; 9287 p += i; 9288 if (*p == NUL) 9289 break; 9290 if (*p == ',') 9291 { 9292 if (idx == 3) 9293 return FAIL; 9294 ++idx; 9295 } 9296 } 9297 9298 /* fill remaining entries with last flag */ 9299 while (idx < 3) 9300 { 9301 new_wim_flags[idx + 1] = new_wim_flags[idx]; 9302 ++idx; 9303 } 9304 9305 /* only when there are no errors, wim_flags[] is changed */ 9306 for (i = 0; i < 4; ++i) 9307 wim_flags[i] = new_wim_flags[i]; 9308 return OK; 9309 } 9310 9311 /* 9312 * Check if backspacing over something is allowed. 9313 */ 9314 int 9315 can_bs(what) 9316 int what; /* BS_INDENT, BS_EOL or BS_START */ 9317 { 9318 switch (*p_bs) 9319 { 9320 case '2': return TRUE; 9321 case '1': return (what != BS_START); 9322 case '0': return FALSE; 9323 } 9324 return vim_strchr(p_bs, what) != NULL; 9325 } 9326 9327 /* 9328 * Save the current values of 'fileformat' and 'fileencoding', so that we know 9329 * the file must be considered changed when the value is different. 9330 */ 9331 void 9332 save_file_ff(buf) 9333 buf_T *buf; 9334 { 9335 buf->b_start_ffc = *buf->b_p_ff; 9336 buf->b_start_eol = buf->b_p_eol; 9337 #ifdef FEAT_MBYTE 9338 /* Only use free/alloc when necessary, they take time. */ 9339 if (buf->b_start_fenc == NULL 9340 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) 9341 { 9342 vim_free(buf->b_start_fenc); 9343 buf->b_start_fenc = vim_strsave(buf->b_p_fenc); 9344 } 9345 #endif 9346 } 9347 9348 /* 9349 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value 9350 * from when editing started (save_file_ff() called). 9351 * Also when 'endofline' was changed and 'binary' is set. 9352 * Don't consider a new, empty buffer to be changed. 9353 */ 9354 int 9355 file_ff_differs(buf) 9356 buf_T *buf; 9357 { 9358 if ((buf->b_flags & BF_NEW) 9359 && buf->b_ml.ml_line_count == 1 9360 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL) 9361 return FALSE; 9362 if (buf->b_start_ffc != *buf->b_p_ff) 9363 return TRUE; 9364 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol) 9365 return TRUE; 9366 #ifdef FEAT_MBYTE 9367 if (buf->b_start_fenc == NULL) 9368 return (*buf->b_p_fenc != NUL); 9369 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0); 9370 #else 9371 return FALSE; 9372 #endif 9373 } 9374 9375 /* 9376 * return OK if "p" is a valid fileformat name, FAIL otherwise. 9377 */ 9378 int 9379 check_ff_value(p) 9380 char_u *p; 9381 { 9382 return check_opt_strings(p, p_ff_values, FALSE); 9383 } 9384