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