1 /* vi:set ts=8 sts=4 sw=4 noet: 2 * 3 * VIM - Vi IMproved by Bram Moolenaar 4 * 5 * Do ":help uganda" in Vim to read copying and usage conditions. 6 * Do ":help credits" in Vim to see a list of people who contributed. 7 * See README.txt for an overview of the Vim source code. 8 */ 9 10 /* 11 * 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/quickref.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_WIN is added: window-local option 42 * PV_BUF is added: buffer-local option 43 * PV_BOTH is added: global option which also has a local value. 44 */ 45 #define PV_BOTH 0x1000 46 #define PV_WIN 0x2000 47 #define PV_BUF 0x4000 48 #define PV_MASK 0x0fff 49 #define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x)) 50 #define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x)) 51 #define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x)) 52 53 /* 54 * Definition of the PV_ values for buffer-local options. 55 * The BV_ values are defined in option.h. 56 */ 57 #define PV_AI OPT_BUF(BV_AI) 58 #define PV_AR OPT_BOTH(OPT_BUF(BV_AR)) 59 #define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC)) 60 #define PV_BH OPT_BUF(BV_BH) 61 #define PV_BT OPT_BUF(BV_BT) 62 #ifdef FEAT_QUICKFIX 63 # define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM)) 64 # define PV_GP OPT_BOTH(OPT_BUF(BV_GP)) 65 # define PV_MP OPT_BOTH(OPT_BUF(BV_MP)) 66 #endif 67 #define PV_BIN OPT_BUF(BV_BIN) 68 #define PV_BL OPT_BUF(BV_BL) 69 #define PV_BOMB OPT_BUF(BV_BOMB) 70 #define PV_CI OPT_BUF(BV_CI) 71 #ifdef FEAT_CINDENT 72 # define PV_CIN OPT_BUF(BV_CIN) 73 # define PV_CINK OPT_BUF(BV_CINK) 74 # define PV_CINO OPT_BUF(BV_CINO) 75 #endif 76 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 77 # define PV_CINW OPT_BUF(BV_CINW) 78 #endif 79 #define PV_CM OPT_BOTH(OPT_BUF(BV_CM)) 80 #ifdef FEAT_FOLDING 81 # define PV_CMS OPT_BUF(BV_CMS) 82 #endif 83 #ifdef FEAT_COMMENTS 84 # define PV_COM OPT_BUF(BV_COM) 85 #endif 86 #ifdef FEAT_INS_EXPAND 87 # define PV_CPT OPT_BUF(BV_CPT) 88 # define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT)) 89 # define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR)) 90 #endif 91 #ifdef FEAT_COMPL_FUNC 92 # define PV_CFU OPT_BUF(BV_CFU) 93 #endif 94 #ifdef FEAT_FIND_ID 95 # define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF)) 96 # define PV_INC OPT_BOTH(OPT_BUF(BV_INC)) 97 #endif 98 #define PV_EOL OPT_BUF(BV_EOL) 99 #define PV_FIXEOL OPT_BUF(BV_FIXEOL) 100 #define PV_EP OPT_BOTH(OPT_BUF(BV_EP)) 101 #define PV_ET OPT_BUF(BV_ET) 102 #define PV_FENC OPT_BUF(BV_FENC) 103 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) 104 # define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR)) 105 #endif 106 #define PV_FP OPT_BOTH(OPT_BUF(BV_FP)) 107 #ifdef FEAT_EVAL 108 # define PV_FEX OPT_BUF(BV_FEX) 109 #endif 110 #define PV_FF OPT_BUF(BV_FF) 111 #define PV_FLP OPT_BUF(BV_FLP) 112 #define PV_FO OPT_BUF(BV_FO) 113 #define PV_FT OPT_BUF(BV_FT) 114 #define PV_IMI OPT_BUF(BV_IMI) 115 #define PV_IMS OPT_BUF(BV_IMS) 116 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 117 # define PV_INDE OPT_BUF(BV_INDE) 118 # define PV_INDK OPT_BUF(BV_INDK) 119 #endif 120 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) 121 # define PV_INEX OPT_BUF(BV_INEX) 122 #endif 123 #define PV_INF OPT_BUF(BV_INF) 124 #define PV_ISK OPT_BUF(BV_ISK) 125 #ifdef FEAT_CRYPT 126 # define PV_KEY OPT_BUF(BV_KEY) 127 #endif 128 #ifdef FEAT_KEYMAP 129 # define PV_KMAP OPT_BUF(BV_KMAP) 130 #endif 131 #define PV_KP OPT_BOTH(OPT_BUF(BV_KP)) 132 #ifdef FEAT_LISP 133 # define PV_LISP OPT_BUF(BV_LISP) 134 # define PV_LW OPT_BOTH(OPT_BUF(BV_LW)) 135 #endif 136 #define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC)) 137 #define PV_MA OPT_BUF(BV_MA) 138 #define PV_ML OPT_BUF(BV_ML) 139 #define PV_MOD OPT_BUF(BV_MOD) 140 #define PV_MPS OPT_BUF(BV_MPS) 141 #define PV_NF OPT_BUF(BV_NF) 142 #ifdef FEAT_COMPL_FUNC 143 # define PV_OFU OPT_BUF(BV_OFU) 144 #endif 145 #define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH)) 146 #define PV_PI OPT_BUF(BV_PI) 147 #ifdef FEAT_TEXTOBJ 148 # define PV_QE OPT_BUF(BV_QE) 149 #endif 150 #define PV_RO OPT_BUF(BV_RO) 151 #ifdef FEAT_SMARTINDENT 152 # define PV_SI OPT_BUF(BV_SI) 153 #endif 154 #define PV_SN OPT_BUF(BV_SN) 155 #ifdef FEAT_SYN_HL 156 # define PV_SMC OPT_BUF(BV_SMC) 157 # define PV_SYN OPT_BUF(BV_SYN) 158 #endif 159 #ifdef FEAT_SPELL 160 # define PV_SPC OPT_BUF(BV_SPC) 161 # define PV_SPF OPT_BUF(BV_SPF) 162 # define PV_SPL OPT_BUF(BV_SPL) 163 #endif 164 #define PV_STS OPT_BUF(BV_STS) 165 #ifdef FEAT_SEARCHPATH 166 # define PV_SUA OPT_BUF(BV_SUA) 167 #endif 168 #define PV_SW OPT_BUF(BV_SW) 169 #define PV_SWF OPT_BUF(BV_SWF) 170 #define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS)) 171 #define PV_TC OPT_BOTH(OPT_BUF(BV_TC)) 172 #define PV_TS OPT_BUF(BV_TS) 173 #define PV_TW OPT_BUF(BV_TW) 174 #define PV_TX OPT_BUF(BV_TX) 175 #ifdef FEAT_PERSISTENT_UNDO 176 # define PV_UDF OPT_BUF(BV_UDF) 177 #endif 178 #define PV_WM OPT_BUF(BV_WM) 179 #ifdef FEAT_VARTABS 180 # define PV_VSTS OPT_BUF(BV_VSTS) 181 # define PV_VTS OPT_BUF(BV_VTS) 182 #endif 183 184 /* 185 * Definition of the PV_ values for window-local options. 186 * The WV_ values are defined in option.h. 187 */ 188 #define PV_LIST OPT_WIN(WV_LIST) 189 #ifdef FEAT_ARABIC 190 # define PV_ARAB OPT_WIN(WV_ARAB) 191 #endif 192 #ifdef FEAT_LINEBREAK 193 # define PV_BRI OPT_WIN(WV_BRI) 194 # define PV_BRIOPT OPT_WIN(WV_BRIOPT) 195 #endif 196 #ifdef FEAT_DIFF 197 # define PV_DIFF OPT_WIN(WV_DIFF) 198 #endif 199 #ifdef FEAT_FOLDING 200 # define PV_FDC OPT_WIN(WV_FDC) 201 # define PV_FEN OPT_WIN(WV_FEN) 202 # define PV_FDI OPT_WIN(WV_FDI) 203 # define PV_FDL OPT_WIN(WV_FDL) 204 # define PV_FDM OPT_WIN(WV_FDM) 205 # define PV_FML OPT_WIN(WV_FML) 206 # define PV_FDN OPT_WIN(WV_FDN) 207 # ifdef FEAT_EVAL 208 # define PV_FDE OPT_WIN(WV_FDE) 209 # define PV_FDT OPT_WIN(WV_FDT) 210 # endif 211 # define PV_FMR OPT_WIN(WV_FMR) 212 #endif 213 #ifdef FEAT_LINEBREAK 214 # define PV_LBR OPT_WIN(WV_LBR) 215 #endif 216 #define PV_NU OPT_WIN(WV_NU) 217 #define PV_RNU OPT_WIN(WV_RNU) 218 #ifdef FEAT_LINEBREAK 219 # define PV_NUW OPT_WIN(WV_NUW) 220 #endif 221 #if defined(FEAT_QUICKFIX) 222 # define PV_PVW OPT_WIN(WV_PVW) 223 #endif 224 #ifdef FEAT_RIGHTLEFT 225 # define PV_RL OPT_WIN(WV_RL) 226 # define PV_RLC OPT_WIN(WV_RLC) 227 #endif 228 #define PV_SCBIND OPT_WIN(WV_SCBIND) 229 #define PV_SCROLL OPT_WIN(WV_SCROLL) 230 #define PV_SISO OPT_BOTH(OPT_WIN(WV_SISO)) 231 #define PV_SO OPT_BOTH(OPT_WIN(WV_SO)) 232 #ifdef FEAT_SPELL 233 # define PV_SPELL OPT_WIN(WV_SPELL) 234 #endif 235 #ifdef FEAT_SYN_HL 236 # define PV_CUC OPT_WIN(WV_CUC) 237 # define PV_CUL OPT_WIN(WV_CUL) 238 # define PV_CC OPT_WIN(WV_CC) 239 #endif 240 #ifdef FEAT_STL_OPT 241 # define PV_STL OPT_BOTH(OPT_WIN(WV_STL)) 242 #endif 243 #define PV_UL OPT_BOTH(OPT_BUF(BV_UL)) 244 # define PV_WFH OPT_WIN(WV_WFH) 245 # define PV_WFW OPT_WIN(WV_WFW) 246 #define PV_WRAP OPT_WIN(WV_WRAP) 247 #define PV_CRBIND OPT_WIN(WV_CRBIND) 248 #ifdef FEAT_CONCEAL 249 # define PV_COCU OPT_WIN(WV_COCU) 250 # define PV_COLE OPT_WIN(WV_COLE) 251 #endif 252 #ifdef FEAT_TERMINAL 253 # define PV_TWK OPT_WIN(WV_TWK) 254 # define PV_TWS OPT_WIN(WV_TWS) 255 # define PV_TWSL OPT_BUF(BV_TWSL) 256 # define PV_TMOD OPT_WIN(WV_TMOD) 257 #endif 258 #ifdef FEAT_SIGNS 259 # define PV_SCL OPT_WIN(WV_SCL) 260 #endif 261 262 /* WV_ and BV_ values get typecasted to this for the "indir" field */ 263 typedef enum 264 { 265 PV_NONE = 0, 266 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */ 267 } idopt_T; 268 269 /* 270 * Options local to a window have a value local to a buffer and global to all 271 * buffers. Indicate this by setting "var" to VAR_WIN. 272 */ 273 #define VAR_WIN ((char_u *)-1) 274 275 /* 276 * These are the global values for options which are also local to a buffer. 277 * Only to be used in option.c! 278 */ 279 static int p_ai; 280 static int p_bin; 281 static int p_bomb; 282 static char_u *p_bh; 283 static char_u *p_bt; 284 static int p_bl; 285 static int p_ci; 286 #ifdef FEAT_CINDENT 287 static int p_cin; 288 static char_u *p_cink; 289 static char_u *p_cino; 290 #endif 291 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 292 static char_u *p_cinw; 293 #endif 294 #ifdef FEAT_COMMENTS 295 static char_u *p_com; 296 #endif 297 #ifdef FEAT_FOLDING 298 static char_u *p_cms; 299 #endif 300 #ifdef FEAT_INS_EXPAND 301 static char_u *p_cpt; 302 #endif 303 #ifdef FEAT_COMPL_FUNC 304 static char_u *p_cfu; 305 static char_u *p_ofu; 306 #endif 307 static int p_eol; 308 static int p_fixeol; 309 static int p_et; 310 static char_u *p_fenc; 311 static char_u *p_ff; 312 static char_u *p_fo; 313 static char_u *p_flp; 314 static char_u *p_ft; 315 static long p_iminsert; 316 static long p_imsearch; 317 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) 318 static char_u *p_inex; 319 #endif 320 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 321 static char_u *p_inde; 322 static char_u *p_indk; 323 #endif 324 #if defined(FEAT_EVAL) 325 static char_u *p_fex; 326 #endif 327 static int p_inf; 328 static char_u *p_isk; 329 #ifdef FEAT_CRYPT 330 static char_u *p_key; 331 #endif 332 #ifdef FEAT_LISP 333 static int p_lisp; 334 #endif 335 static int p_ml; 336 static int p_ma; 337 static int p_mod; 338 static char_u *p_mps; 339 static char_u *p_nf; 340 static int p_pi; 341 #ifdef FEAT_TEXTOBJ 342 static char_u *p_qe; 343 #endif 344 static int p_ro; 345 #ifdef FEAT_SMARTINDENT 346 static int p_si; 347 #endif 348 static int p_sn; 349 static long p_sts; 350 #if defined(FEAT_SEARCHPATH) 351 static char_u *p_sua; 352 #endif 353 static long p_sw; 354 static int p_swf; 355 #ifdef FEAT_SYN_HL 356 static long p_smc; 357 static char_u *p_syn; 358 #endif 359 #ifdef FEAT_SPELL 360 static char_u *p_spc; 361 static char_u *p_spf; 362 static char_u *p_spl; 363 #endif 364 static long p_ts; 365 static long p_tw; 366 static int p_tx; 367 #ifdef FEAT_PERSISTENT_UNDO 368 static int p_udf; 369 #endif 370 static long p_wm; 371 #ifdef FEAT_VARTABS 372 static char_u *p_vsts; 373 static char_u *p_vts; 374 #endif 375 #ifdef FEAT_KEYMAP 376 static char_u *p_keymap; 377 #endif 378 #ifdef FEAT_TERMINAL 379 static long p_twsl; /* 'termwinscroll' */ 380 #endif 381 382 /* Saved values for when 'bin' is set. */ 383 static int p_et_nobin; 384 static int p_ml_nobin; 385 static long p_tw_nobin; 386 static long p_wm_nobin; 387 388 /* Saved values for when 'paste' is set */ 389 static int p_ai_nopaste; 390 static int p_et_nopaste; 391 static long p_sts_nopaste; 392 static long p_tw_nopaste; 393 static long p_wm_nopaste; 394 #ifdef FEAT_VARTABS 395 static char_u *p_vsts_nopaste; 396 #endif 397 398 struct vimoption 399 { 400 char *fullname; // full option name 401 char *shortname; // permissible abbreviation 402 long_u flags; // see below 403 char_u *var; // global option: pointer to variable; 404 // window-local option: VAR_WIN; 405 // buffer-local option: global value 406 idopt_T indir; // global option: PV_NONE; 407 // local option: indirect option index 408 char_u *def_val[2]; // default values for variable (vi and vim) 409 #ifdef FEAT_EVAL 410 sctx_T script_ctx; // script context where the option was last set 411 # define SCTX_INIT , {0, 0, 0} 412 #else 413 # define SCTX_INIT 414 #endif 415 }; 416 417 #define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */ 418 #define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */ 419 420 /* 421 * Flags 422 */ 423 #define P_BOOL 0x01 /* the option is boolean */ 424 #define P_NUM 0x02 /* the option is numeric */ 425 #define P_STRING 0x04 /* the option is a string */ 426 #define P_ALLOCED 0x08 /* the string option is in allocated memory, 427 must use free_string_option() when 428 assigning new value. Not set if default is 429 the same. */ 430 #define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can 431 never be used for local or hidden options! */ 432 #define P_NODEFAULT 0x40 /* don't set to default value */ 433 #define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must 434 use vim_free() when assigning new value */ 435 #define P_WAS_SET 0x100 /* option has been set/reset */ 436 #define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */ 437 #define P_VI_DEF 0x400 /* Use Vi default for Vim */ 438 #define P_VIM 0x800 /* Vim option, reset when 'cp' set */ 439 440 /* when option changed, what to display: */ 441 #define P_RSTAT 0x1000 /* redraw status lines */ 442 #define P_RWIN 0x2000 /* redraw current window and recompute text */ 443 #define P_RBUF 0x4000 /* redraw current buffer and recompute text */ 444 #define P_RALL 0x6000 /* redraw all windows */ 445 #define P_RCLR 0x7000 /* clear and redraw all */ 446 447 #define P_COMMA 0x8000 /* comma separated list */ 448 #define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive 449 * commas */ 450 #define P_NODUP 0x20000L /* don't allow duplicate strings */ 451 #define P_FLAGLIST 0x40000L /* list of single-char flags */ 452 453 #define P_SECURE 0x80000L /* cannot change in modeline or secure mode */ 454 #define P_GETTEXT 0x100000L /* expand default value with _() */ 455 #define P_NOGLOB 0x200000L /* do not use local value for global vimrc */ 456 #define P_NFNAME 0x400000L /* only normal file name chars allowed */ 457 #define P_INSECURE 0x800000L /* option was set from a modeline */ 458 #define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has 459 side effects) */ 460 #define P_NO_ML 0x2000000L /* not allowed in modeline */ 461 #define P_CURSWANT 0x4000000L /* update curswant required; not needed when 462 * there is a redraw flag */ 463 #define P_NDNAME 0x8000000L /* only normal dir name chars allowed */ 464 #define P_RWINONLY 0x10000000L /* only redraw current window */ 465 466 #define ISK_LATIN1 (char_u *)"@,48-57,_,192-255" 467 468 /* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used 469 * for the currency sign. */ 470 #if defined(MSWIN) 471 # define ISP_LATIN1 (char_u *)"@,~-255" 472 #else 473 # define ISP_LATIN1 (char_u *)"@,161-255" 474 #endif 475 476 # define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,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,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC" 477 478 /* Default python version for pyx* commands */ 479 #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) 480 # define DEFAULT_PYTHON_VER 0 481 #elif defined(FEAT_PYTHON3) 482 # define DEFAULT_PYTHON_VER 3 483 #elif defined(FEAT_PYTHON) 484 # define DEFAULT_PYTHON_VER 2 485 #else 486 # define DEFAULT_PYTHON_VER 0 487 #endif 488 489 // used for 'cinkeys' and 'indentkeys' 490 #define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e" 491 492 /* 493 * options[] is initialized here. 494 * The order of the options MUST be alphabetic for ":set all" and findoption(). 495 * All option names MUST start with a lowercase letter (for findoption()). 496 * Exception: "t_" options are at the end. 497 * The options with a NULL variable are 'hidden': a set command for them is 498 * ignored and they are not printed. 499 */ 500 static struct vimoption options[] = 501 { 502 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT, 503 #ifdef FEAT_RIGHTLEFT 504 (char_u *)&p_aleph, PV_NONE, 505 #else 506 (char_u *)NULL, PV_NONE, 507 #endif 508 { 509 #if (defined(WIN3264)) && !defined(FEAT_GUI_W32) 510 (char_u *)128L, 511 #else 512 (char_u *)224L, 513 #endif 514 (char_u *)0L} SCTX_INIT}, 515 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, 516 #if defined(FEAT_GUI_MAC) 517 (char_u *)&p_antialias, PV_NONE, 518 {(char_u *)FALSE, (char_u *)FALSE} 519 #else 520 (char_u *)NULL, PV_NONE, 521 {(char_u *)FALSE, (char_u *)FALSE} 522 #endif 523 SCTX_INIT}, 524 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT, 525 #ifdef FEAT_ARABIC 526 (char_u *)VAR_WIN, PV_ARAB, 527 #else 528 (char_u *)NULL, PV_NONE, 529 #endif 530 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 531 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, 532 #ifdef FEAT_ARABIC 533 (char_u *)&p_arshape, PV_NONE, 534 #else 535 (char_u *)NULL, PV_NONE, 536 #endif 537 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 538 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM, 539 #ifdef FEAT_RIGHTLEFT 540 (char_u *)&p_ari, PV_NONE, 541 #else 542 (char_u *)NULL, PV_NONE, 543 #endif 544 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 545 {"altkeymap", "akm", P_BOOL|P_VI_DEF, 546 #ifdef FEAT_FKMAP 547 (char_u *)&p_altkeymap, PV_NONE, 548 #else 549 (char_u *)NULL, PV_NONE, 550 #endif 551 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 552 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR, 553 (char_u *)&p_ambw, PV_NONE, 554 {(char_u *)"single", (char_u *)0L} 555 SCTX_INIT}, 556 {"autochdir", "acd", P_BOOL|P_VI_DEF, 557 #ifdef FEAT_AUTOCHDIR 558 (char_u *)&p_acd, PV_NONE, 559 {(char_u *)FALSE, (char_u *)0L} 560 #else 561 (char_u *)NULL, PV_NONE, 562 {(char_u *)0L, (char_u *)0L} 563 #endif 564 SCTX_INIT}, 565 {"autoindent", "ai", P_BOOL|P_VI_DEF, 566 (char_u *)&p_ai, PV_AI, 567 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 568 {"autoprint", "ap", P_BOOL|P_VI_DEF, 569 (char_u *)NULL, PV_NONE, 570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 571 {"autoread", "ar", P_BOOL|P_VI_DEF, 572 (char_u *)&p_ar, PV_AR, 573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 574 {"autowrite", "aw", P_BOOL|P_VI_DEF, 575 (char_u *)&p_aw, PV_NONE, 576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 577 {"autowriteall","awa", P_BOOL|P_VI_DEF, 578 (char_u *)&p_awa, PV_NONE, 579 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 580 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR, 581 (char_u *)&p_bg, PV_NONE, 582 { 583 #if (defined(WIN3264)) && !defined(FEAT_GUI) 584 (char_u *)"dark", 585 #else 586 (char_u *)"light", 587 #endif 588 (char_u *)0L} SCTX_INIT}, 589 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP, 590 (char_u *)&p_bs, PV_NONE, 591 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 592 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM, 593 (char_u *)&p_bk, PV_NONE, 594 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 595 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP, 596 (char_u *)&p_bkc, PV_BKC, 597 #ifdef UNIX 598 {(char_u *)"yes", (char_u *)"auto"} 599 #else 600 {(char_u *)"auto", (char_u *)"auto"} 601 #endif 602 SCTX_INIT}, 603 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA 604 |P_NODUP|P_SECURE, 605 (char_u *)&p_bdir, PV_NONE, 606 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT}, 607 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME, 608 (char_u *)&p_bex, PV_NONE, 609 { 610 #ifdef VMS 611 (char_u *)"_", 612 #else 613 (char_u *)"~", 614 #endif 615 (char_u *)0L} SCTX_INIT}, 616 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA, 617 #ifdef FEAT_WILDIGN 618 (char_u *)&p_bsk, PV_NONE, 619 {(char_u *)"", (char_u *)0L} 620 #else 621 (char_u *)NULL, PV_NONE, 622 {(char_u *)0L, (char_u *)0L} 623 #endif 624 SCTX_INIT}, 625 {"balloondelay","bdlay",P_NUM|P_VI_DEF, 626 #ifdef FEAT_BEVAL 627 (char_u *)&p_bdlay, PV_NONE, 628 {(char_u *)600L, (char_u *)0L} 629 #else 630 (char_u *)NULL, PV_NONE, 631 {(char_u *)0L, (char_u *)0L} 632 #endif 633 SCTX_INIT}, 634 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC, 635 #ifdef FEAT_BEVAL_GUI 636 (char_u *)&p_beval, PV_NONE, 637 {(char_u *)FALSE, (char_u *)0L} 638 #else 639 (char_u *)NULL, PV_NONE, 640 {(char_u *)0L, (char_u *)0L} 641 #endif 642 SCTX_INIT}, 643 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC, 644 #ifdef FEAT_BEVAL_TERM 645 (char_u *)&p_bevalterm, PV_NONE, 646 {(char_u *)FALSE, (char_u *)0L} 647 #else 648 (char_u *)NULL, PV_NONE, 649 {(char_u *)0L, (char_u *)0L} 650 #endif 651 SCTX_INIT}, 652 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM, 653 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) 654 (char_u *)&p_bexpr, PV_BEXPR, 655 {(char_u *)"", (char_u *)0L} 656 #else 657 (char_u *)NULL, PV_NONE, 658 {(char_u *)0L, (char_u *)0L} 659 #endif 660 SCTX_INIT}, 661 {"beautify", "bf", P_BOOL|P_VI_DEF, 662 (char_u *)NULL, PV_NONE, 663 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 664 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 665 (char_u *)&p_bo, PV_NONE, 666 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 667 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT, 668 (char_u *)&p_bin, PV_BIN, 669 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 670 {"bioskey", "biosk",P_BOOL|P_VI_DEF, 671 (char_u *)NULL, PV_NONE, 672 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 673 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT, 674 (char_u *)&p_bomb, PV_BOMB, 675 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 676 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST, 677 #ifdef FEAT_LINEBREAK 678 (char_u *)&p_breakat, PV_NONE, 679 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L} 680 #else 681 (char_u *)NULL, PV_NONE, 682 {(char_u *)0L, (char_u *)0L} 683 #endif 684 SCTX_INIT}, 685 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN, 686 #ifdef FEAT_LINEBREAK 687 (char_u *)VAR_WIN, PV_BRI, 688 {(char_u *)FALSE, (char_u *)0L} 689 #else 690 (char_u *)NULL, PV_NONE, 691 {(char_u *)0L, (char_u *)0L} 692 #endif 693 SCTX_INIT}, 694 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF 695 |P_ONECOMMA|P_NODUP, 696 #ifdef FEAT_LINEBREAK 697 (char_u *)VAR_WIN, PV_BRIOPT, 698 {(char_u *)"", (char_u *)NULL} 699 #else 700 (char_u *)NULL, PV_NONE, 701 {(char_u *)"", (char_u *)NULL} 702 #endif 703 SCTX_INIT}, 704 {"browsedir", "bsdir",P_STRING|P_VI_DEF, 705 #ifdef FEAT_BROWSE 706 (char_u *)&p_bsdir, PV_NONE, 707 {(char_u *)"last", (char_u *)0L} 708 #else 709 (char_u *)NULL, PV_NONE, 710 {(char_u *)0L, (char_u *)0L} 711 #endif 712 SCTX_INIT}, 713 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB, 714 (char_u *)&p_bh, PV_BH, 715 {(char_u *)"", (char_u *)0L} 716 SCTX_INIT}, 717 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB, 718 (char_u *)&p_bl, PV_BL, 719 {(char_u *)1L, (char_u *)0L} 720 SCTX_INIT}, 721 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB, 722 (char_u *)&p_bt, PV_BT, 723 {(char_u *)"", (char_u *)0L} 724 SCTX_INIT}, 725 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 726 (char_u *)&p_cmp, PV_NONE, 727 {(char_u *)"internal,keepascii", (char_u *)0L} 728 SCTX_INIT}, 729 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP, 730 #ifdef FEAT_SEARCHPATH 731 (char_u *)&p_cdpath, PV_NONE, 732 {(char_u *)",,", (char_u *)0L} 733 #else 734 (char_u *)NULL, PV_NONE, 735 {(char_u *)0L, (char_u *)0L} 736 #endif 737 SCTX_INIT}, 738 {"cedit", NULL, P_STRING, 739 #ifdef FEAT_CMDWIN 740 (char_u *)&p_cedit, PV_NONE, 741 {(char_u *)"", (char_u *)CTRL_F_STR} 742 #else 743 (char_u *)NULL, PV_NONE, 744 {(char_u *)0L, (char_u *)0L} 745 #endif 746 SCTX_INIT}, 747 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE, 748 #if defined(FEAT_EVAL) 749 (char_u *)&p_ccv, PV_NONE, 750 {(char_u *)"", (char_u *)0L} 751 #else 752 (char_u *)NULL, PV_NONE, 753 {(char_u *)0L, (char_u *)0L} 754 #endif 755 SCTX_INIT}, 756 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM, 757 #ifdef FEAT_CINDENT 758 (char_u *)&p_cin, PV_CIN, 759 #else 760 (char_u *)NULL, PV_NONE, 761 #endif 762 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 763 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP, 764 #ifdef FEAT_CINDENT 765 (char_u *)&p_cink, PV_CINK, 766 {INDENTKEYS_DEFAULT, (char_u *)0L} 767 #else 768 (char_u *)NULL, PV_NONE, 769 {(char_u *)0L, (char_u *)0L} 770 #endif 771 SCTX_INIT}, 772 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP, 773 #ifdef FEAT_CINDENT 774 (char_u *)&p_cino, PV_CINO, 775 #else 776 (char_u *)NULL, PV_NONE, 777 #endif 778 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 779 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP, 780 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 781 (char_u *)&p_cinw, PV_CINW, 782 {(char_u *)"if,else,while,do,for,switch", 783 (char_u *)0L} 784 #else 785 (char_u *)NULL, PV_NONE, 786 {(char_u *)0L, (char_u *)0L} 787 #endif 788 SCTX_INIT}, 789 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 790 #ifdef FEAT_CLIPBOARD 791 (char_u *)&p_cb, PV_NONE, 792 # ifdef FEAT_XCLIPBOARD 793 {(char_u *)"autoselect,exclude:cons\\|linux", 794 (char_u *)0L} 795 # else 796 {(char_u *)"", (char_u *)0L} 797 # endif 798 #else 799 (char_u *)NULL, PV_NONE, 800 {(char_u *)"", (char_u *)0L} 801 #endif 802 SCTX_INIT}, 803 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL, 804 (char_u *)&p_ch, PV_NONE, 805 {(char_u *)1L, (char_u *)0L} SCTX_INIT}, 806 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF, 807 #ifdef FEAT_CMDWIN 808 (char_u *)&p_cwh, PV_NONE, 809 #else 810 (char_u *)NULL, PV_NONE, 811 #endif 812 {(char_u *)7L, (char_u *)0L} SCTX_INIT}, 813 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN, 814 #ifdef FEAT_SYN_HL 815 (char_u *)VAR_WIN, PV_CC, 816 #else 817 (char_u *)NULL, PV_NONE, 818 #endif 819 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 820 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR, 821 (char_u *)&Columns, PV_NONE, 822 {(char_u *)80L, (char_u *)0L} SCTX_INIT}, 823 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA 824 |P_NODUP|P_CURSWANT, 825 #ifdef FEAT_COMMENTS 826 (char_u *)&p_com, PV_COM, 827 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-", 828 (char_u *)0L} 829 #else 830 (char_u *)NULL, PV_NONE, 831 {(char_u *)0L, (char_u *)0L} 832 #endif 833 SCTX_INIT}, 834 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT, 835 #ifdef FEAT_FOLDING 836 (char_u *)&p_cms, PV_CMS, 837 {(char_u *)"/*%s*/", (char_u *)0L} 838 #else 839 (char_u *)NULL, PV_NONE, 840 {(char_u *)0L, (char_u *)0L} 841 #endif 842 SCTX_INIT}, 843 /* P_PRI_MKRC isn't needed here, optval_default() 844 * always returns TRUE for 'compatible' */ 845 {"compatible", "cp", P_BOOL|P_RALL, 846 (char_u *)&p_cp, PV_NONE, 847 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT}, 848 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP, 849 #ifdef FEAT_INS_EXPAND 850 (char_u *)&p_cpt, PV_CPT, 851 {(char_u *)".,w,b,u,t,i", (char_u *)0L} 852 #else 853 (char_u *)NULL, PV_NONE, 854 {(char_u *)0L, (char_u *)0L} 855 #endif 856 SCTX_INIT}, 857 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF, 858 #ifdef FEAT_CONCEAL 859 (char_u *)VAR_WIN, PV_COCU, 860 {(char_u *)"", (char_u *)NULL} 861 #else 862 (char_u *)NULL, PV_NONE, 863 {(char_u *)NULL, (char_u *)0L} 864 #endif 865 SCTX_INIT}, 866 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF, 867 #ifdef FEAT_CONCEAL 868 (char_u *)VAR_WIN, PV_COLE, 869 #else 870 (char_u *)NULL, PV_NONE, 871 #endif 872 {(char_u *)0L, (char_u *)0L} 873 SCTX_INIT}, 874 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE, 875 #ifdef FEAT_COMPL_FUNC 876 (char_u *)&p_cfu, PV_CFU, 877 {(char_u *)"", (char_u *)0L} 878 #else 879 (char_u *)NULL, PV_NONE, 880 {(char_u *)0L, (char_u *)0L} 881 #endif 882 SCTX_INIT}, 883 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 884 #ifdef FEAT_INS_EXPAND 885 (char_u *)&p_cot, PV_NONE, 886 {(char_u *)"menu,preview", (char_u *)0L} 887 #else 888 (char_u *)NULL, PV_NONE, 889 {(char_u *)0L, (char_u *)0L} 890 #endif 891 SCTX_INIT}, 892 {"confirm", "cf", P_BOOL|P_VI_DEF, 893 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) 894 (char_u *)&p_confirm, PV_NONE, 895 #else 896 (char_u *)NULL, PV_NONE, 897 #endif 898 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 899 {"conskey", "consk",P_BOOL|P_VI_DEF, 900 (char_u *)NULL, PV_NONE, 901 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 902 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM, 903 (char_u *)&p_ci, PV_CI, 904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 905 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST, 906 (char_u *)&p_cpo, PV_NONE, 907 {(char_u *)CPO_VI, (char_u *)CPO_VIM} 908 SCTX_INIT}, 909 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF, 910 #ifdef FEAT_CRYPT 911 (char_u *)&p_cm, PV_CM, 912 {(char_u *)"blowfish2", (char_u *)0L} 913 #else 914 (char_u *)NULL, PV_NONE, 915 {(char_u *)0L, (char_u *)0L} 916 #endif 917 SCTX_INIT}, 918 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM, 919 #ifdef FEAT_CSCOPE 920 (char_u *)&p_cspc, PV_NONE, 921 #else 922 (char_u *)NULL, PV_NONE, 923 #endif 924 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 925 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 926 #ifdef FEAT_CSCOPE 927 (char_u *)&p_csprg, PV_NONE, 928 {(char_u *)"cscope", (char_u *)0L} 929 #else 930 (char_u *)NULL, PV_NONE, 931 {(char_u *)0L, (char_u *)0L} 932 #endif 933 SCTX_INIT}, 934 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 935 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX) 936 (char_u *)&p_csqf, PV_NONE, 937 {(char_u *)"", (char_u *)0L} 938 #else 939 (char_u *)NULL, PV_NONE, 940 {(char_u *)0L, (char_u *)0L} 941 #endif 942 SCTX_INIT}, 943 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM, 944 #ifdef FEAT_CSCOPE 945 (char_u *)&p_csre, PV_NONE, 946 #else 947 (char_u *)NULL, PV_NONE, 948 #endif 949 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 950 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM, 951 #ifdef FEAT_CSCOPE 952 (char_u *)&p_cst, PV_NONE, 953 #else 954 (char_u *)NULL, PV_NONE, 955 #endif 956 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 957 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM, 958 #ifdef FEAT_CSCOPE 959 (char_u *)&p_csto, PV_NONE, 960 #else 961 (char_u *)NULL, PV_NONE, 962 #endif 963 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 964 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM, 965 #ifdef FEAT_CSCOPE 966 (char_u *)&p_csverbose, PV_NONE, 967 #else 968 (char_u *)NULL, PV_NONE, 969 #endif 970 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 971 {"cursorbind", "crb", P_BOOL|P_VI_DEF, 972 (char_u *)VAR_WIN, PV_CRBIND, 973 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 974 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY, 975 #ifdef FEAT_SYN_HL 976 (char_u *)VAR_WIN, PV_CUC, 977 #else 978 (char_u *)NULL, PV_NONE, 979 #endif 980 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 981 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY, 982 #ifdef FEAT_SYN_HL 983 (char_u *)VAR_WIN, PV_CUL, 984 #else 985 (char_u *)NULL, PV_NONE, 986 #endif 987 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 988 {"debug", NULL, P_STRING|P_VI_DEF, 989 (char_u *)&p_debug, PV_NONE, 990 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 991 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT, 992 #ifdef FEAT_FIND_ID 993 (char_u *)&p_def, PV_DEF, 994 {(char_u *)"^\\s*#\\s*define", (char_u *)0L} 995 #else 996 (char_u *)NULL, PV_NONE, 997 {(char_u *)NULL, (char_u *)0L} 998 #endif 999 SCTX_INIT}, 1000 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM, 1001 (char_u *)&p_deco, PV_NONE, 1002 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1003 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME, 1004 #ifdef FEAT_INS_EXPAND 1005 (char_u *)&p_dict, PV_DICT, 1006 #else 1007 (char_u *)NULL, PV_NONE, 1008 #endif 1009 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1010 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB, 1011 #ifdef FEAT_DIFF 1012 (char_u *)VAR_WIN, PV_DIFF, 1013 #else 1014 (char_u *)NULL, PV_NONE, 1015 #endif 1016 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1017 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT, 1018 #if defined(FEAT_DIFF) && defined(FEAT_EVAL) 1019 (char_u *)&p_dex, PV_NONE, 1020 {(char_u *)"", (char_u *)0L} 1021 #else 1022 (char_u *)NULL, PV_NONE, 1023 {(char_u *)0L, (char_u *)0L} 1024 #endif 1025 SCTX_INIT}, 1026 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA 1027 |P_NODUP, 1028 #ifdef FEAT_DIFF 1029 (char_u *)&p_dip, PV_NONE, 1030 {(char_u *)"internal,filler", (char_u *)NULL} 1031 #else 1032 (char_u *)NULL, PV_NONE, 1033 {(char_u *)"", (char_u *)NULL} 1034 #endif 1035 SCTX_INIT}, 1036 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM, 1037 #ifdef FEAT_DIGRAPHS 1038 (char_u *)&p_dg, PV_NONE, 1039 #else 1040 (char_u *)NULL, PV_NONE, 1041 #endif 1042 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1043 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA 1044 |P_NODUP|P_SECURE, 1045 (char_u *)&p_dir, PV_NONE, 1046 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT}, 1047 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP, 1048 (char_u *)&p_dy, PV_NONE, 1049 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1050 {"eadirection", "ead", P_STRING|P_VI_DEF, 1051 (char_u *)&p_ead, PV_NONE, 1052 {(char_u *)"both", (char_u *)0L} 1053 SCTX_INIT}, 1054 {"edcompatible","ed", P_BOOL|P_VI_DEF, 1055 (char_u *)&p_ed, PV_NONE, 1056 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1057 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR, 1058 (char_u *)&p_emoji, PV_NONE, 1059 {(char_u *)TRUE, (char_u *)0L} 1060 SCTX_INIT}, 1061 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML, 1062 (char_u *)&p_enc, PV_NONE, 1063 {(char_u *)ENC_DFLT, (char_u *)0L} 1064 SCTX_INIT}, 1065 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT, 1066 (char_u *)&p_eol, PV_EOL, 1067 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1068 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL, 1069 (char_u *)&p_ea, PV_NONE, 1070 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1071 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1072 (char_u *)&p_ep, PV_EP, 1073 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1074 {"errorbells", "eb", P_BOOL|P_VI_DEF, 1075 (char_u *)&p_eb, PV_NONE, 1076 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1077 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1078 #ifdef FEAT_QUICKFIX 1079 (char_u *)&p_ef, PV_NONE, 1080 {(char_u *)DFLT_ERRORFILE, (char_u *)0L} 1081 #else 1082 (char_u *)NULL, PV_NONE, 1083 {(char_u *)NULL, (char_u *)0L} 1084 #endif 1085 SCTX_INIT}, 1086 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 1087 #ifdef FEAT_QUICKFIX 1088 (char_u *)&p_efm, PV_EFM, 1089 {(char_u *)DFLT_EFM, (char_u *)0L} 1090 #else 1091 (char_u *)NULL, PV_NONE, 1092 {(char_u *)NULL, (char_u *)0L} 1093 #endif 1094 SCTX_INIT}, 1095 {"esckeys", "ek", P_BOOL|P_VIM, 1096 (char_u *)&p_ek, PV_NONE, 1097 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT}, 1098 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 1099 (char_u *)&p_ei, PV_NONE, 1100 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1101 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM, 1102 (char_u *)&p_et, PV_ET, 1103 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1104 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE, 1105 (char_u *)&p_exrc, PV_NONE, 1106 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1107 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF 1108 |P_NO_MKRC, 1109 (char_u *)&p_fenc, PV_FENC, 1110 {(char_u *)"", (char_u *)0L} 1111 SCTX_INIT}, 1112 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA, 1113 (char_u *)&p_fencs, PV_NONE, 1114 {(char_u *)"ucs-bom", (char_u *)0L} 1115 SCTX_INIT}, 1116 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC 1117 |P_CURSWANT, 1118 (char_u *)&p_ff, PV_FF, 1119 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT}, 1120 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP, 1121 (char_u *)&p_ffs, PV_NONE, 1122 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM} 1123 SCTX_INIT}, 1124 {"fileignorecase", "fic", P_BOOL|P_VI_DEF, 1125 (char_u *)&p_fic, PV_NONE, 1126 { 1127 #ifdef CASE_INSENSITIVE_FILENAME 1128 (char_u *)TRUE, 1129 #else 1130 (char_u *)FALSE, 1131 #endif 1132 (char_u *)0L} SCTX_INIT}, 1133 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME, 1134 (char_u *)&p_ft, PV_FT, 1135 {(char_u *)"", (char_u *)0L} 1136 SCTX_INIT}, 1137 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP, 1138 (char_u *)&p_fcs, PV_NONE, 1139 {(char_u *)"vert:|,fold:-", (char_u *)0L} 1140 SCTX_INIT}, 1141 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT, 1142 (char_u *)&p_fixeol, PV_FIXEOL, 1143 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1144 {"fkmap", "fk", P_BOOL|P_VI_DEF, 1145 #ifdef FEAT_FKMAP 1146 (char_u *)&p_fkmap, PV_NONE, 1147 #else 1148 (char_u *)NULL, PV_NONE, 1149 #endif 1150 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1151 {"flash", "fl", P_BOOL|P_VI_DEF, 1152 (char_u *)NULL, PV_NONE, 1153 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1154 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN, 1155 #ifdef FEAT_FOLDING 1156 (char_u *)&p_fcl, PV_NONE, 1157 {(char_u *)"", (char_u *)0L} 1158 #else 1159 (char_u *)NULL, PV_NONE, 1160 {(char_u *)NULL, (char_u *)0L} 1161 #endif 1162 SCTX_INIT}, 1163 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN, 1164 #ifdef FEAT_FOLDING 1165 (char_u *)VAR_WIN, PV_FDC, 1166 {(char_u *)FALSE, (char_u *)0L} 1167 #else 1168 (char_u *)NULL, PV_NONE, 1169 {(char_u *)NULL, (char_u *)0L} 1170 #endif 1171 SCTX_INIT}, 1172 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN, 1173 #ifdef FEAT_FOLDING 1174 (char_u *)VAR_WIN, PV_FEN, 1175 {(char_u *)TRUE, (char_u *)0L} 1176 #else 1177 (char_u *)NULL, PV_NONE, 1178 {(char_u *)NULL, (char_u *)0L} 1179 #endif 1180 SCTX_INIT}, 1181 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN, 1182 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL) 1183 (char_u *)VAR_WIN, PV_FDE, 1184 {(char_u *)"0", (char_u *)NULL} 1185 #else 1186 (char_u *)NULL, PV_NONE, 1187 {(char_u *)NULL, (char_u *)0L} 1188 #endif 1189 SCTX_INIT}, 1190 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN, 1191 #ifdef FEAT_FOLDING 1192 (char_u *)VAR_WIN, PV_FDI, 1193 {(char_u *)"#", (char_u *)NULL} 1194 #else 1195 (char_u *)NULL, PV_NONE, 1196 {(char_u *)NULL, (char_u *)0L} 1197 #endif 1198 SCTX_INIT}, 1199 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN, 1200 #ifdef FEAT_FOLDING 1201 (char_u *)VAR_WIN, PV_FDL, 1202 {(char_u *)0L, (char_u *)0L} 1203 #else 1204 (char_u *)NULL, PV_NONE, 1205 {(char_u *)NULL, (char_u *)0L} 1206 #endif 1207 SCTX_INIT}, 1208 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT, 1209 #ifdef FEAT_FOLDING 1210 (char_u *)&p_fdls, PV_NONE, 1211 {(char_u *)-1L, (char_u *)0L} 1212 #else 1213 (char_u *)NULL, PV_NONE, 1214 {(char_u *)NULL, (char_u *)0L} 1215 #endif 1216 SCTX_INIT}, 1217 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF| 1218 P_RWIN|P_ONECOMMA|P_NODUP, 1219 #ifdef FEAT_FOLDING 1220 (char_u *)VAR_WIN, PV_FMR, 1221 {(char_u *)"{{{,}}}", (char_u *)NULL} 1222 #else 1223 (char_u *)NULL, PV_NONE, 1224 {(char_u *)NULL, (char_u *)0L} 1225 #endif 1226 SCTX_INIT}, 1227 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN, 1228 #ifdef FEAT_FOLDING 1229 (char_u *)VAR_WIN, PV_FDM, 1230 {(char_u *)"manual", (char_u *)NULL} 1231 #else 1232 (char_u *)NULL, PV_NONE, 1233 {(char_u *)NULL, (char_u *)0L} 1234 #endif 1235 SCTX_INIT}, 1236 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN, 1237 #ifdef FEAT_FOLDING 1238 (char_u *)VAR_WIN, PV_FML, 1239 {(char_u *)1L, (char_u *)0L} 1240 #else 1241 (char_u *)NULL, PV_NONE, 1242 {(char_u *)NULL, (char_u *)0L} 1243 #endif 1244 SCTX_INIT}, 1245 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN, 1246 #ifdef FEAT_FOLDING 1247 (char_u *)VAR_WIN, PV_FDN, 1248 {(char_u *)20L, (char_u *)0L} 1249 #else 1250 (char_u *)NULL, PV_NONE, 1251 {(char_u *)NULL, (char_u *)0L} 1252 #endif 1253 SCTX_INIT}, 1254 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT, 1255 #ifdef FEAT_FOLDING 1256 (char_u *)&p_fdo, PV_NONE, 1257 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo", 1258 (char_u *)0L} 1259 #else 1260 (char_u *)NULL, PV_NONE, 1261 {(char_u *)NULL, (char_u *)0L} 1262 #endif 1263 SCTX_INIT}, 1264 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN, 1265 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL) 1266 (char_u *)VAR_WIN, PV_FDT, 1267 {(char_u *)"foldtext()", (char_u *)NULL} 1268 #else 1269 (char_u *)NULL, PV_NONE, 1270 {(char_u *)NULL, (char_u *)0L} 1271 #endif 1272 SCTX_INIT}, 1273 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM, 1274 #ifdef FEAT_EVAL 1275 (char_u *)&p_fex, PV_FEX, 1276 {(char_u *)"", (char_u *)0L} 1277 #else 1278 (char_u *)NULL, PV_NONE, 1279 {(char_u *)0L, (char_u *)0L} 1280 #endif 1281 SCTX_INIT}, 1282 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST, 1283 (char_u *)&p_fo, PV_FO, 1284 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM} 1285 SCTX_INIT}, 1286 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF, 1287 (char_u *)&p_flp, PV_FLP, 1288 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*", 1289 (char_u *)0L} SCTX_INIT}, 1290 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1291 (char_u *)&p_fp, PV_FP, 1292 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1293 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF, 1294 #ifdef HAVE_FSYNC 1295 (char_u *)&p_fs, PV_NONE, 1296 {(char_u *)TRUE, (char_u *)0L} 1297 #else 1298 (char_u *)NULL, PV_NONE, 1299 {(char_u *)FALSE, (char_u *)0L} 1300 #endif 1301 SCTX_INIT}, 1302 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM, 1303 (char_u *)&p_gd, PV_NONE, 1304 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1305 {"graphic", "gr", P_BOOL|P_VI_DEF, 1306 (char_u *)NULL, PV_NONE, 1307 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1308 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 1309 #ifdef FEAT_QUICKFIX 1310 (char_u *)&p_gefm, PV_NONE, 1311 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L} 1312 #else 1313 (char_u *)NULL, PV_NONE, 1314 {(char_u *)NULL, (char_u *)0L} 1315 #endif 1316 SCTX_INIT}, 1317 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1318 #ifdef FEAT_QUICKFIX 1319 (char_u *)&p_gp, PV_GP, 1320 { 1321 # ifdef WIN3264 1322 /* may be changed to "grep -n" in os_win32.c */ 1323 (char_u *)"findstr /n", 1324 # else 1325 # ifdef UNIX 1326 /* Add an extra file name so that grep will always 1327 * insert a file name in the match line. */ 1328 (char_u *)"grep -n $* /dev/null", 1329 # else 1330 # ifdef VMS 1331 (char_u *)"SEARCH/NUMBERS ", 1332 # else 1333 (char_u *)"grep -n ", 1334 # endif 1335 # endif 1336 # endif 1337 (char_u *)0L} 1338 #else 1339 (char_u *)NULL, PV_NONE, 1340 {(char_u *)NULL, (char_u *)0L} 1341 #endif 1342 SCTX_INIT}, 1343 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 1344 #ifdef CURSOR_SHAPE 1345 (char_u *)&p_guicursor, PV_NONE, 1346 { 1347 # ifdef FEAT_GUI 1348 (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", 1349 # else /* Win32 console */ 1350 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block", 1351 # endif 1352 (char_u *)0L} 1353 #else 1354 (char_u *)NULL, PV_NONE, 1355 {(char_u *)NULL, (char_u *)0L} 1356 #endif 1357 SCTX_INIT}, 1358 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP, 1359 #ifdef FEAT_GUI 1360 (char_u *)&p_guifont, PV_NONE, 1361 {(char_u *)"", (char_u *)0L} 1362 #else 1363 (char_u *)NULL, PV_NONE, 1364 {(char_u *)NULL, (char_u *)0L} 1365 #endif 1366 SCTX_INIT}, 1367 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA, 1368 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET) 1369 (char_u *)&p_guifontset, PV_NONE, 1370 {(char_u *)"", (char_u *)0L} 1371 #else 1372 (char_u *)NULL, PV_NONE, 1373 {(char_u *)NULL, (char_u *)0L} 1374 #endif 1375 SCTX_INIT}, 1376 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP, 1377 #if defined(FEAT_GUI) 1378 (char_u *)&p_guifontwide, PV_NONE, 1379 {(char_u *)"", (char_u *)0L} 1380 #else 1381 (char_u *)NULL, PV_NONE, 1382 {(char_u *)NULL, (char_u *)0L} 1383 #endif 1384 SCTX_INIT}, 1385 {"guiheadroom", "ghr", P_NUM|P_VI_DEF, 1386 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) 1387 (char_u *)&p_ghr, PV_NONE, 1388 #else 1389 (char_u *)NULL, PV_NONE, 1390 #endif 1391 {(char_u *)50L, (char_u *)0L} SCTX_INIT}, 1392 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST, 1393 #if defined(FEAT_GUI) 1394 (char_u *)&p_go, PV_NONE, 1395 # if defined(UNIX) && !defined(FEAT_GUI_MAC) 1396 {(char_u *)"aegimrLtT", (char_u *)0L} 1397 # else 1398 {(char_u *)"egmrLtT", (char_u *)0L} 1399 # endif 1400 #else 1401 (char_u *)NULL, PV_NONE, 1402 {(char_u *)NULL, (char_u *)0L} 1403 #endif 1404 SCTX_INIT}, 1405 {"guipty", NULL, P_BOOL|P_VI_DEF, 1406 #if defined(FEAT_GUI) 1407 (char_u *)&p_guipty, PV_NONE, 1408 #else 1409 (char_u *)NULL, PV_NONE, 1410 #endif 1411 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1412 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN, 1413 #if defined(FEAT_GUI_TABLINE) 1414 (char_u *)&p_gtl, PV_NONE, 1415 {(char_u *)"", (char_u *)0L} 1416 #else 1417 (char_u *)NULL, PV_NONE, 1418 {(char_u *)NULL, (char_u *)0L} 1419 #endif 1420 SCTX_INIT}, 1421 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN, 1422 #if defined(FEAT_GUI_TABLINE) 1423 (char_u *)&p_gtt, PV_NONE, 1424 {(char_u *)"", (char_u *)0L} 1425 #else 1426 (char_u *)NULL, PV_NONE, 1427 {(char_u *)NULL, (char_u *)0L} 1428 #endif 1429 SCTX_INIT}, 1430 {"hardtabs", "ht", P_NUM|P_VI_DEF, 1431 (char_u *)NULL, PV_NONE, 1432 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 1433 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1434 (char_u *)&p_hf, PV_NONE, 1435 {(char_u *)DFLT_HELPFILE, (char_u *)0L} 1436 SCTX_INIT}, 1437 {"helpheight", "hh", P_NUM|P_VI_DEF, 1438 (char_u *)&p_hh, PV_NONE, 1439 {(char_u *)20L, (char_u *)0L} SCTX_INIT}, 1440 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA, 1441 #ifdef FEAT_MULTI_LANG 1442 (char_u *)&p_hlg, PV_NONE, 1443 {(char_u *)"", (char_u *)0L} 1444 #else 1445 (char_u *)NULL, PV_NONE, 1446 {(char_u *)0L, (char_u *)0L} 1447 #endif 1448 SCTX_INIT}, 1449 {"hidden", "hid", P_BOOL|P_VI_DEF, 1450 (char_u *)&p_hid, PV_NONE, 1451 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1452 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP, 1453 (char_u *)&p_hl, PV_NONE, 1454 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L} 1455 SCTX_INIT}, 1456 {"history", "hi", P_NUM|P_VIM, 1457 (char_u *)&p_hi, PV_NONE, 1458 {(char_u *)0L, (char_u *)50L} SCTX_INIT}, 1459 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM, 1460 #ifdef FEAT_RIGHTLEFT 1461 (char_u *)&p_hkmap, PV_NONE, 1462 #else 1463 (char_u *)NULL, PV_NONE, 1464 #endif 1465 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1466 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM, 1467 #ifdef FEAT_RIGHTLEFT 1468 (char_u *)&p_hkmapp, PV_NONE, 1469 #else 1470 (char_u *)NULL, PV_NONE, 1471 #endif 1472 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1473 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL, 1474 (char_u *)&p_hls, PV_NONE, 1475 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1476 {"icon", NULL, P_BOOL|P_VI_DEF, 1477 #ifdef FEAT_TITLE 1478 (char_u *)&p_icon, PV_NONE, 1479 #else 1480 (char_u *)NULL, PV_NONE, 1481 #endif 1482 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1483 {"iconstring", NULL, P_STRING|P_VI_DEF, 1484 #ifdef FEAT_TITLE 1485 (char_u *)&p_iconstring, PV_NONE, 1486 #else 1487 (char_u *)NULL, PV_NONE, 1488 #endif 1489 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1490 {"ignorecase", "ic", P_BOOL|P_VI_DEF, 1491 (char_u *)&p_ic, PV_NONE, 1492 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1493 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE, 1494 #if defined(FEAT_EVAL) 1495 (char_u *)&p_imaf, PV_NONE, 1496 {(char_u *)"", (char_u *)NULL} 1497 # else 1498 (char_u *)NULL, PV_NONE, 1499 {(char_u *)NULL, (char_u *)0L} 1500 # endif 1501 SCTX_INIT}, 1502 {"imactivatekey","imak",P_STRING|P_VI_DEF, 1503 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) 1504 (char_u *)&p_imak, PV_NONE, 1505 #else 1506 (char_u *)NULL, PV_NONE, 1507 #endif 1508 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1509 {"imcmdline", "imc", P_BOOL|P_VI_DEF, 1510 (char_u *)&p_imcmdline, PV_NONE, 1511 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1512 {"imdisable", "imd", P_BOOL|P_VI_DEF, 1513 (char_u *)&p_imdisable, PV_NONE, 1514 #ifdef __sgi 1515 {(char_u *)TRUE, (char_u *)0L} 1516 #else 1517 {(char_u *)FALSE, (char_u *)0L} 1518 #endif 1519 SCTX_INIT}, 1520 {"iminsert", "imi", P_NUM|P_VI_DEF, 1521 (char_u *)&p_iminsert, PV_IMI, 1522 {(char_u *)B_IMODE_NONE, (char_u *)0L} 1523 SCTX_INIT}, 1524 {"imsearch", "ims", P_NUM|P_VI_DEF, 1525 (char_u *)&p_imsearch, PV_IMS, 1526 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L} 1527 SCTX_INIT}, 1528 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE, 1529 #if defined(FEAT_EVAL) 1530 (char_u *)&p_imsf, PV_NONE, 1531 {(char_u *)"", (char_u *)NULL} 1532 #else 1533 (char_u *)NULL, PV_NONE, 1534 {(char_u *)NULL, (char_u *)0L} 1535 #endif 1536 SCTX_INIT}, 1537 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE, 1538 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) 1539 (char_u *)&p_imst, PV_NONE, 1540 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L} 1541 #else 1542 (char_u *)NULL, PV_NONE, 1543 {(char_u *)0L, (char_u *)0L} 1544 #endif 1545 SCTX_INIT}, 1546 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF, 1547 #ifdef FEAT_FIND_ID 1548 (char_u *)&p_inc, PV_INC, 1549 {(char_u *)"^\\s*#\\s*include", (char_u *)0L} 1550 #else 1551 (char_u *)NULL, PV_NONE, 1552 {(char_u *)0L, (char_u *)0L} 1553 #endif 1554 SCTX_INIT}, 1555 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF, 1556 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) 1557 (char_u *)&p_inex, PV_INEX, 1558 {(char_u *)"", (char_u *)0L} 1559 #else 1560 (char_u *)NULL, PV_NONE, 1561 {(char_u *)0L, (char_u *)0L} 1562 #endif 1563 SCTX_INIT}, 1564 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM, 1565 (char_u *)&p_is, PV_NONE, 1566 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1567 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM, 1568 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 1569 (char_u *)&p_inde, PV_INDE, 1570 {(char_u *)"", (char_u *)0L} 1571 #else 1572 (char_u *)NULL, PV_NONE, 1573 {(char_u *)0L, (char_u *)0L} 1574 #endif 1575 SCTX_INIT}, 1576 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP, 1577 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 1578 (char_u *)&p_indk, PV_INDK, 1579 {INDENTKEYS_DEFAULT, (char_u *)0L} 1580 #else 1581 (char_u *)NULL, PV_NONE, 1582 {(char_u *)0L, (char_u *)0L} 1583 #endif 1584 SCTX_INIT}, 1585 {"infercase", "inf", P_BOOL|P_VI_DEF, 1586 (char_u *)&p_inf, PV_INF, 1587 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1588 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM, 1589 (char_u *)&p_im, PV_NONE, 1590 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1591 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1592 (char_u *)&p_isf, PV_NONE, 1593 { 1594 #ifdef BACKSLASH_IN_FILENAME 1595 /* Excluded are: & and ^ are special in cmd.exe 1596 * ( and ) are used in text separating fnames */ 1597 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=", 1598 #else 1599 # ifdef AMIGA 1600 (char_u *)"@,48-57,/,.,-,_,+,,,$,:", 1601 # else 1602 # ifdef VMS 1603 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~", 1604 # else /* UNIX et al. */ 1605 # ifdef EBCDIC 1606 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=", 1607 # else 1608 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=", 1609 # endif 1610 # endif 1611 # endif 1612 #endif 1613 (char_u *)0L} SCTX_INIT}, 1614 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP, 1615 (char_u *)&p_isi, PV_NONE, 1616 { 1617 #if defined(MSWIN) 1618 (char_u *)"@,48-57,_,128-167,224-235", 1619 #else 1620 # ifdef EBCDIC 1621 /* TODO: EBCDIC Check this! @ == isalpha()*/ 1622 (char_u *)"@,240-249,_,66-73,81-89,98-105," 1623 "112-120,128,140-142,156,158,172," 1624 "174,186,191,203-207,219-225,235-239," 1625 "251-254", 1626 # else 1627 (char_u *)"@,48-57,_,192-255", 1628 # endif 1629 #endif 1630 (char_u *)0L} SCTX_INIT}, 1631 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP, 1632 (char_u *)&p_isk, PV_ISK, 1633 { 1634 #ifdef EBCDIC 1635 (char_u *)"@,240-249,_", 1636 /* TODO: EBCDIC Check this! @ == isalpha()*/ 1637 (char_u *)"@,240-249,_,66-73,81-89,98-105," 1638 "112-120,128,140-142,156,158,172," 1639 "174,186,191,203-207,219-225,235-239," 1640 "251-254", 1641 #else 1642 (char_u *)"@,48-57,_", 1643 # if defined(MSWIN) 1644 (char_u *)"@,48-57,_,128-167,224-235" 1645 # else 1646 ISK_LATIN1 1647 # endif 1648 #endif 1649 } SCTX_INIT}, 1650 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP, 1651 (char_u *)&p_isp, PV_NONE, 1652 { 1653 #if defined(MSWIN) || defined(VMS) 1654 (char_u *)"@,~-255", 1655 #else 1656 # ifdef EBCDIC 1657 /* all chars above 63 are printable */ 1658 (char_u *)"63-255", 1659 # else 1660 ISP_LATIN1, 1661 # endif 1662 #endif 1663 (char_u *)0L} SCTX_INIT}, 1664 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM, 1665 (char_u *)&p_js, PV_NONE, 1666 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1667 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC, 1668 #ifdef FEAT_CRYPT 1669 (char_u *)&p_key, PV_KEY, 1670 {(char_u *)"", (char_u *)0L} 1671 #else 1672 (char_u *)NULL, PV_NONE, 1673 {(char_u *)0L, (char_u *)0L} 1674 #endif 1675 SCTX_INIT}, 1676 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC, 1677 #ifdef FEAT_KEYMAP 1678 (char_u *)&p_keymap, PV_KMAP, 1679 {(char_u *)"", (char_u *)0L} 1680 #else 1681 (char_u *)NULL, PV_NONE, 1682 {(char_u *)"", (char_u *)0L} 1683 #endif 1684 SCTX_INIT}, 1685 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 1686 (char_u *)&p_km, PV_NONE, 1687 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1688 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1689 (char_u *)&p_kp, PV_KP, 1690 { 1691 #ifdef MSWIN 1692 (char_u *)":help", 1693 #else 1694 # ifdef VMS 1695 (char_u *)"help", 1696 # else 1697 # ifdef USEMAN_S 1698 (char_u *)"man -s", 1699 # else 1700 (char_u *)"man", 1701 # endif 1702 # endif 1703 #endif 1704 (char_u *)0L} SCTX_INIT}, 1705 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE, 1706 #ifdef FEAT_LANGMAP 1707 (char_u *)&p_langmap, PV_NONE, 1708 {(char_u *)"", (char_u *)0L} 1709 #else 1710 (char_u *)NULL, PV_NONE, 1711 {(char_u *)NULL, (char_u *)0L} 1712 #endif 1713 SCTX_INIT}, 1714 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME, 1715 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG) 1716 (char_u *)&p_lm, PV_NONE, 1717 #else 1718 (char_u *)NULL, PV_NONE, 1719 #endif 1720 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 1721 {"langnoremap", "lnr", P_BOOL|P_VI_DEF, 1722 #ifdef FEAT_LANGMAP 1723 (char_u *)&p_lnr, PV_NONE, 1724 #else 1725 (char_u *)NULL, PV_NONE, 1726 #endif 1727 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1728 {"langremap", "lrm", P_BOOL|P_VI_DEF, 1729 #ifdef FEAT_LANGMAP 1730 (char_u *)&p_lrm, PV_NONE, 1731 #else 1732 (char_u *)NULL, PV_NONE, 1733 #endif 1734 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1735 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL, 1736 (char_u *)&p_ls, PV_NONE, 1737 {(char_u *)1L, (char_u *)0L} SCTX_INIT}, 1738 {"lazyredraw", "lz", P_BOOL|P_VI_DEF, 1739 (char_u *)&p_lz, PV_NONE, 1740 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1741 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN, 1742 #ifdef FEAT_LINEBREAK 1743 (char_u *)VAR_WIN, PV_LBR, 1744 #else 1745 (char_u *)NULL, PV_NONE, 1746 #endif 1747 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1748 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR, 1749 (char_u *)&Rows, PV_NONE, 1750 { 1751 #if defined(WIN3264) 1752 (char_u *)25L, 1753 #else 1754 (char_u *)24L, 1755 #endif 1756 (char_u *)0L} SCTX_INIT}, 1757 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR, 1758 #ifdef FEAT_GUI 1759 (char_u *)&p_linespace, PV_NONE, 1760 #else 1761 (char_u *)NULL, PV_NONE, 1762 #endif 1763 #ifdef FEAT_GUI_W32 1764 {(char_u *)1L, (char_u *)0L} 1765 #else 1766 {(char_u *)0L, (char_u *)0L} 1767 #endif 1768 SCTX_INIT}, 1769 {"lisp", NULL, P_BOOL|P_VI_DEF, 1770 #ifdef FEAT_LISP 1771 (char_u *)&p_lisp, PV_LISP, 1772 #else 1773 (char_u *)NULL, PV_NONE, 1774 #endif 1775 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1776 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 1777 #ifdef FEAT_LISP 1778 (char_u *)&p_lispwords, PV_LW, 1779 {(char_u *)LISPWORD_VALUE, (char_u *)0L} 1780 #else 1781 (char_u *)NULL, PV_NONE, 1782 {(char_u *)"", (char_u *)0L} 1783 #endif 1784 SCTX_INIT}, 1785 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN, 1786 (char_u *)VAR_WIN, PV_LIST, 1787 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1788 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP, 1789 (char_u *)&p_lcs, PV_NONE, 1790 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT}, 1791 {"loadplugins", "lpl", P_BOOL|P_VI_DEF, 1792 (char_u *)&p_lpl, PV_NONE, 1793 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1794 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1795 #if defined(DYNAMIC_LUA) 1796 (char_u *)&p_luadll, PV_NONE, 1797 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L} 1798 #else 1799 (char_u *)NULL, PV_NONE, 1800 {(char_u *)"", (char_u *)0L} 1801 #endif 1802 SCTX_INIT}, 1803 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR, 1804 #ifdef FEAT_GUI_MAC 1805 (char_u *)&p_macatsui, PV_NONE, 1806 {(char_u *)TRUE, (char_u *)0L} 1807 #else 1808 (char_u *)NULL, PV_NONE, 1809 {(char_u *)"", (char_u *)0L} 1810 #endif 1811 SCTX_INIT}, 1812 {"magic", NULL, P_BOOL|P_VI_DEF, 1813 (char_u *)&p_magic, PV_NONE, 1814 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1815 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1816 #ifdef FEAT_QUICKFIX 1817 (char_u *)&p_mef, PV_NONE, 1818 {(char_u *)"", (char_u *)0L} 1819 #else 1820 (char_u *)NULL, PV_NONE, 1821 {(char_u *)NULL, (char_u *)0L} 1822 #endif 1823 SCTX_INIT}, 1824 {"makeencoding","menc", P_STRING|P_VI_DEF, 1825 (char_u *)&p_menc, PV_MENC, 1826 {(char_u *)"", (char_u *)0L} 1827 SCTX_INIT}, 1828 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1829 #ifdef FEAT_QUICKFIX 1830 (char_u *)&p_mp, PV_MP, 1831 # ifdef VMS 1832 {(char_u *)"MMS", (char_u *)0L} 1833 # else 1834 {(char_u *)"make", (char_u *)0L} 1835 # endif 1836 #else 1837 (char_u *)NULL, PV_NONE, 1838 {(char_u *)NULL, (char_u *)0L} 1839 #endif 1840 SCTX_INIT}, 1841 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP, 1842 (char_u *)&p_mps, PV_MPS, 1843 {(char_u *)"(:),{:},[:]", (char_u *)0L} 1844 SCTX_INIT}, 1845 {"matchtime", "mat", P_NUM|P_VI_DEF, 1846 (char_u *)&p_mat, PV_NONE, 1847 {(char_u *)5L, (char_u *)0L} SCTX_INIT}, 1848 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT, 1849 (char_u *)&p_mco, PV_NONE, 1850 {(char_u *)2, (char_u *)0L} SCTX_INIT}, 1851 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF, 1852 #ifdef FEAT_EVAL 1853 (char_u *)&p_mfd, PV_NONE, 1854 #else 1855 (char_u *)NULL, PV_NONE, 1856 #endif 1857 {(char_u *)100L, (char_u *)0L} SCTX_INIT}, 1858 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF, 1859 (char_u *)&p_mmd, PV_NONE, 1860 {(char_u *)1000L, (char_u *)0L} SCTX_INIT}, 1861 {"maxmem", "mm", P_NUM|P_VI_DEF, 1862 (char_u *)&p_mm, PV_NONE, 1863 {(char_u *)DFLT_MAXMEM, (char_u *)0L} 1864 SCTX_INIT}, 1865 {"maxmempattern","mmp", P_NUM|P_VI_DEF, 1866 (char_u *)&p_mmp, PV_NONE, 1867 {(char_u *)1000L, (char_u *)0L} SCTX_INIT}, 1868 {"maxmemtot", "mmt", P_NUM|P_VI_DEF, 1869 (char_u *)&p_mmt, PV_NONE, 1870 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L} 1871 SCTX_INIT}, 1872 {"menuitems", "mis", P_NUM|P_VI_DEF, 1873 #ifdef FEAT_MENU 1874 (char_u *)&p_mis, PV_NONE, 1875 #else 1876 (char_u *)NULL, PV_NONE, 1877 #endif 1878 {(char_u *)25L, (char_u *)0L} SCTX_INIT}, 1879 {"mesg", NULL, P_BOOL|P_VI_DEF, 1880 (char_u *)NULL, PV_NONE, 1881 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1882 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE, 1883 #ifdef FEAT_SPELL 1884 (char_u *)&p_msm, PV_NONE, 1885 {(char_u *)"460000,2000,500", (char_u *)0L} 1886 #else 1887 (char_u *)NULL, PV_NONE, 1888 {(char_u *)0L, (char_u *)0L} 1889 #endif 1890 SCTX_INIT}, 1891 {"modeline", "ml", P_BOOL|P_VIM, 1892 (char_u *)&p_ml, PV_ML, 1893 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT}, 1894 {"modelines", "mls", P_NUM|P_VI_DEF, 1895 (char_u *)&p_mls, PV_NONE, 1896 {(char_u *)5L, (char_u *)0L} SCTX_INIT}, 1897 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB, 1898 (char_u *)&p_ma, PV_MA, 1899 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1900 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT, 1901 (char_u *)&p_mod, PV_MOD, 1902 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1903 {"more", NULL, P_BOOL|P_VIM, 1904 (char_u *)&p_more, PV_NONE, 1905 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT}, 1906 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST, 1907 (char_u *)&p_mouse, PV_NONE, 1908 { 1909 #if defined(WIN3264) 1910 (char_u *)"a", 1911 #else 1912 (char_u *)"", 1913 #endif 1914 (char_u *)0L} SCTX_INIT}, 1915 {"mousefocus", "mousef", P_BOOL|P_VI_DEF, 1916 #ifdef FEAT_GUI 1917 (char_u *)&p_mousef, PV_NONE, 1918 #else 1919 (char_u *)NULL, PV_NONE, 1920 #endif 1921 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1922 {"mousehide", "mh", P_BOOL|P_VI_DEF, 1923 #ifdef FEAT_GUI 1924 (char_u *)&p_mh, PV_NONE, 1925 #else 1926 (char_u *)NULL, PV_NONE, 1927 #endif 1928 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 1929 {"mousemodel", "mousem", P_STRING|P_VI_DEF, 1930 (char_u *)&p_mousem, PV_NONE, 1931 { 1932 #if defined(MSWIN) 1933 (char_u *)"popup", 1934 #else 1935 # if defined(MACOS_X) 1936 (char_u *)"popup_setpos", 1937 # else 1938 (char_u *)"extend", 1939 # endif 1940 #endif 1941 (char_u *)0L} SCTX_INIT}, 1942 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 1943 #ifdef FEAT_MOUSESHAPE 1944 (char_u *)&p_mouseshape, PV_NONE, 1945 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L} 1946 #else 1947 (char_u *)NULL, PV_NONE, 1948 {(char_u *)NULL, (char_u *)0L} 1949 #endif 1950 SCTX_INIT}, 1951 {"mousetime", "mouset", P_NUM|P_VI_DEF, 1952 (char_u *)&p_mouset, PV_NONE, 1953 {(char_u *)500L, (char_u *)0L} SCTX_INIT}, 1954 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1955 #if defined(DYNAMIC_MZSCHEME) 1956 (char_u *)&p_mzschemedll, PV_NONE, 1957 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L} 1958 #else 1959 (char_u *)NULL, PV_NONE, 1960 {(char_u *)"", (char_u *)0L} 1961 #endif 1962 SCTX_INIT}, 1963 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 1964 #if defined(DYNAMIC_MZSCHEME) 1965 (char_u *)&p_mzschemegcdll, PV_NONE, 1966 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L} 1967 #else 1968 (char_u *)NULL, PV_NONE, 1969 {(char_u *)"", (char_u *)0L} 1970 #endif 1971 SCTX_INIT}, 1972 {"mzquantum", "mzq", P_NUM, 1973 #ifdef FEAT_MZSCHEME 1974 (char_u *)&p_mzq, PV_NONE, 1975 #else 1976 (char_u *)NULL, PV_NONE, 1977 #endif 1978 {(char_u *)100L, (char_u *)100L} SCTX_INIT}, 1979 {"novice", NULL, P_BOOL|P_VI_DEF, 1980 (char_u *)NULL, PV_NONE, 1981 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1982 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP, 1983 (char_u *)&p_nf, PV_NF, 1984 {(char_u *)"bin,octal,hex", (char_u *)0L} 1985 SCTX_INIT}, 1986 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN, 1987 (char_u *)VAR_WIN, PV_NU, 1988 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 1989 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM, 1990 #ifdef FEAT_LINEBREAK 1991 (char_u *)VAR_WIN, PV_NUW, 1992 #else 1993 (char_u *)NULL, PV_NONE, 1994 #endif 1995 {(char_u *)8L, (char_u *)4L} SCTX_INIT}, 1996 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE, 1997 #ifdef FEAT_COMPL_FUNC 1998 (char_u *)&p_ofu, PV_OFU, 1999 {(char_u *)"", (char_u *)0L} 2000 #else 2001 (char_u *)NULL, PV_NONE, 2002 {(char_u *)0L, (char_u *)0L} 2003 #endif 2004 SCTX_INIT}, 2005 {"open", NULL, P_BOOL|P_VI_DEF, 2006 (char_u *)NULL, PV_NONE, 2007 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2008 {"opendevice", "odev", P_BOOL|P_VI_DEF, 2009 #if defined(MSWIN) 2010 (char_u *)&p_odev, PV_NONE, 2011 #else 2012 (char_u *)NULL, PV_NONE, 2013 #endif 2014 {(char_u *)FALSE, (char_u *)FALSE} 2015 SCTX_INIT}, 2016 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE, 2017 (char_u *)&p_opfunc, PV_NONE, 2018 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2019 {"optimize", "opt", P_BOOL|P_VI_DEF, 2020 (char_u *)NULL, PV_NONE, 2021 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2022 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF, 2023 (char_u *)NULL, PV_NONE, 2024 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2025 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP 2026 |P_SECURE, 2027 (char_u *)&p_pp, PV_NONE, 2028 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L} 2029 SCTX_INIT}, 2030 {"paragraphs", "para", P_STRING|P_VI_DEF, 2031 (char_u *)&p_para, PV_NONE, 2032 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp", 2033 (char_u *)0L} SCTX_INIT}, 2034 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC, 2035 (char_u *)&p_paste, PV_NONE, 2036 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2037 {"pastetoggle", "pt", P_STRING|P_VI_DEF, 2038 (char_u *)&p_pt, PV_NONE, 2039 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2040 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE, 2041 #if defined(FEAT_DIFF) && defined(FEAT_EVAL) 2042 (char_u *)&p_pex, PV_NONE, 2043 {(char_u *)"", (char_u *)0L} 2044 #else 2045 (char_u *)NULL, PV_NONE, 2046 {(char_u *)0L, (char_u *)0L} 2047 #endif 2048 SCTX_INIT}, 2049 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME, 2050 (char_u *)&p_pm, PV_NONE, 2051 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2052 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP, 2053 (char_u *)&p_path, PV_PATH, 2054 { 2055 #if defined(AMIGA) || defined(MSWIN) 2056 (char_u *)".,,", 2057 #else 2058 (char_u *)".,/usr/include,,", 2059 #endif 2060 (char_u *)0L} SCTX_INIT}, 2061 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2062 #if defined(DYNAMIC_PERL) 2063 (char_u *)&p_perldll, PV_NONE, 2064 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L} 2065 #else 2066 (char_u *)NULL, PV_NONE, 2067 {(char_u *)0L, (char_u *)0L} 2068 #endif 2069 SCTX_INIT}, 2070 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM, 2071 (char_u *)&p_pi, PV_PI, 2072 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2073 {"previewheight", "pvh", P_NUM|P_VI_DEF, 2074 #if defined(FEAT_QUICKFIX) 2075 (char_u *)&p_pvh, PV_NONE, 2076 #else 2077 (char_u *)NULL, PV_NONE, 2078 #endif 2079 {(char_u *)12L, (char_u *)0L} SCTX_INIT}, 2080 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB, 2081 #if defined(FEAT_QUICKFIX) 2082 (char_u *)VAR_WIN, PV_PVW, 2083 #else 2084 (char_u *)NULL, PV_NONE, 2085 #endif 2086 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2087 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE, 2088 #ifdef FEAT_PRINTER 2089 (char_u *)&p_pdev, PV_NONE, 2090 {(char_u *)"", (char_u *)0L} 2091 #else 2092 (char_u *)NULL, PV_NONE, 2093 {(char_u *)NULL, (char_u *)0L} 2094 #endif 2095 SCTX_INIT}, 2096 {"printencoding", "penc", P_STRING|P_VI_DEF, 2097 #ifdef FEAT_POSTSCRIPT 2098 (char_u *)&p_penc, PV_NONE, 2099 {(char_u *)"", (char_u *)0L} 2100 #else 2101 (char_u *)NULL, PV_NONE, 2102 {(char_u *)NULL, (char_u *)0L} 2103 #endif 2104 SCTX_INIT}, 2105 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE, 2106 #ifdef FEAT_POSTSCRIPT 2107 (char_u *)&p_pexpr, PV_NONE, 2108 {(char_u *)"", (char_u *)0L} 2109 #else 2110 (char_u *)NULL, PV_NONE, 2111 {(char_u *)NULL, (char_u *)0L} 2112 #endif 2113 SCTX_INIT}, 2114 {"printfont", "pfn", P_STRING|P_VI_DEF, 2115 #ifdef FEAT_PRINTER 2116 (char_u *)&p_pfn, PV_NONE, 2117 { 2118 # ifdef MSWIN 2119 (char_u *)"Courier_New:h10", 2120 # else 2121 (char_u *)"courier", 2122 # endif 2123 (char_u *)0L} 2124 #else 2125 (char_u *)NULL, PV_NONE, 2126 {(char_u *)NULL, (char_u *)0L} 2127 #endif 2128 SCTX_INIT}, 2129 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT, 2130 #ifdef FEAT_PRINTER 2131 (char_u *)&p_header, PV_NONE, 2132 /* untranslated to avoid problems when 'encoding' 2133 * is changed */ 2134 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L} 2135 #else 2136 (char_u *)NULL, PV_NONE, 2137 {(char_u *)NULL, (char_u *)0L} 2138 #endif 2139 SCTX_INIT}, 2140 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF, 2141 #if defined(FEAT_POSTSCRIPT) 2142 (char_u *)&p_pmcs, PV_NONE, 2143 {(char_u *)"", (char_u *)0L} 2144 #else 2145 (char_u *)NULL, PV_NONE, 2146 {(char_u *)NULL, (char_u *)0L} 2147 #endif 2148 SCTX_INIT}, 2149 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF, 2150 #if defined(FEAT_POSTSCRIPT) 2151 (char_u *)&p_pmfn, PV_NONE, 2152 {(char_u *)"", (char_u *)0L} 2153 #else 2154 (char_u *)NULL, PV_NONE, 2155 {(char_u *)NULL, (char_u *)0L} 2156 #endif 2157 SCTX_INIT}, 2158 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 2159 #ifdef FEAT_PRINTER 2160 (char_u *)&p_popt, PV_NONE, 2161 {(char_u *)"", (char_u *)0L} 2162 #else 2163 (char_u *)NULL, PV_NONE, 2164 {(char_u *)NULL, (char_u *)0L} 2165 #endif 2166 SCTX_INIT}, 2167 {"prompt", NULL, P_BOOL|P_VI_DEF, 2168 (char_u *)&p_prompt, PV_NONE, 2169 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2170 {"pumheight", "ph", P_NUM|P_VI_DEF, 2171 #ifdef FEAT_INS_EXPAND 2172 (char_u *)&p_ph, PV_NONE, 2173 #else 2174 (char_u *)NULL, PV_NONE, 2175 #endif 2176 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2177 {"pumwidth", "pw", P_NUM|P_VI_DEF, 2178 #ifdef FEAT_INS_EXPAND 2179 (char_u *)&p_pw, PV_NONE, 2180 #else 2181 (char_u *)NULL, PV_NONE, 2182 #endif 2183 {(char_u *)15L, (char_u *)15L} SCTX_INIT}, 2184 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2185 #if defined(DYNAMIC_PYTHON3) 2186 (char_u *)&p_py3dll, PV_NONE, 2187 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L} 2188 #else 2189 (char_u *)NULL, PV_NONE, 2190 {(char_u *)NULL, (char_u *)0L} 2191 #endif 2192 SCTX_INIT}, 2193 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2194 #if defined(FEAT_PYTHON3) 2195 (char_u *)&p_py3home, PV_NONE, 2196 {(char_u *)"", (char_u *)0L} 2197 #else 2198 (char_u *)NULL, PV_NONE, 2199 {(char_u *)NULL, (char_u *)0L} 2200 #endif 2201 SCTX_INIT}, 2202 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2203 #if defined(DYNAMIC_PYTHON) 2204 (char_u *)&p_pydll, PV_NONE, 2205 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L} 2206 #else 2207 (char_u *)NULL, PV_NONE, 2208 {(char_u *)NULL, (char_u *)0L} 2209 #endif 2210 SCTX_INIT}, 2211 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2212 #if defined(FEAT_PYTHON) 2213 (char_u *)&p_pyhome, PV_NONE, 2214 {(char_u *)"", (char_u *)0L} 2215 #else 2216 (char_u *)NULL, PV_NONE, 2217 {(char_u *)NULL, (char_u *)0L} 2218 #endif 2219 SCTX_INIT}, 2220 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE, 2221 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) 2222 (char_u *)&p_pyx, PV_NONE, 2223 #else 2224 (char_u *)NULL, PV_NONE, 2225 #endif 2226 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L} 2227 SCTX_INIT}, 2228 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF, 2229 #ifdef FEAT_TEXTOBJ 2230 (char_u *)&p_qe, PV_QE, 2231 {(char_u *)"\\", (char_u *)0L} 2232 #else 2233 (char_u *)NULL, PV_NONE, 2234 {(char_u *)NULL, (char_u *)0L} 2235 #endif 2236 SCTX_INIT}, 2237 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB, 2238 (char_u *)&p_ro, PV_RO, 2239 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2240 {"redraw", NULL, P_BOOL|P_VI_DEF, 2241 (char_u *)NULL, PV_NONE, 2242 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2243 {"redrawtime", "rdt", P_NUM|P_VI_DEF, 2244 #ifdef FEAT_RELTIME 2245 (char_u *)&p_rdt, PV_NONE, 2246 #else 2247 (char_u *)NULL, PV_NONE, 2248 #endif 2249 {(char_u *)2000L, (char_u *)0L} SCTX_INIT}, 2250 {"regexpengine", "re", P_NUM|P_VI_DEF, 2251 (char_u *)&p_re, PV_NONE, 2252 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2253 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN, 2254 (char_u *)VAR_WIN, PV_RNU, 2255 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2256 {"remap", NULL, P_BOOL|P_VI_DEF, 2257 (char_u *)&p_remap, PV_NONE, 2258 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2259 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF, 2260 #ifdef FEAT_RENDER_OPTIONS 2261 (char_u *)&p_rop, PV_NONE, 2262 {(char_u *)"", (char_u *)0L} 2263 #else 2264 (char_u *)NULL, PV_NONE, 2265 {(char_u *)NULL, (char_u *)0L} 2266 #endif 2267 SCTX_INIT}, 2268 {"report", NULL, P_NUM|P_VI_DEF, 2269 (char_u *)&p_report, PV_NONE, 2270 {(char_u *)2L, (char_u *)0L} SCTX_INIT}, 2271 {"restorescreen", "rs", P_BOOL|P_VI_DEF, 2272 #ifdef WIN3264 2273 (char_u *)&p_rs, PV_NONE, 2274 #else 2275 (char_u *)NULL, PV_NONE, 2276 #endif 2277 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2278 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM, 2279 #ifdef FEAT_RIGHTLEFT 2280 (char_u *)&p_ri, PV_NONE, 2281 #else 2282 (char_u *)NULL, PV_NONE, 2283 #endif 2284 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2285 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN, 2286 #ifdef FEAT_RIGHTLEFT 2287 (char_u *)VAR_WIN, PV_RL, 2288 #else 2289 (char_u *)NULL, PV_NONE, 2290 #endif 2291 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2292 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN, 2293 #ifdef FEAT_RIGHTLEFT 2294 (char_u *)VAR_WIN, PV_RLC, 2295 {(char_u *)"search", (char_u *)NULL} 2296 #else 2297 (char_u *)NULL, PV_NONE, 2298 {(char_u *)NULL, (char_u *)0L} 2299 #endif 2300 SCTX_INIT}, 2301 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2302 #if defined(DYNAMIC_RUBY) 2303 (char_u *)&p_rubydll, PV_NONE, 2304 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L} 2305 #else 2306 (char_u *)NULL, PV_NONE, 2307 {(char_u *)NULL, (char_u *)0L} 2308 #endif 2309 SCTX_INIT}, 2310 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT, 2311 #ifdef FEAT_CMDL_INFO 2312 (char_u *)&p_ru, PV_NONE, 2313 #else 2314 (char_u *)NULL, PV_NONE, 2315 #endif 2316 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2317 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT, 2318 #ifdef FEAT_STL_OPT 2319 (char_u *)&p_ruf, PV_NONE, 2320 #else 2321 (char_u *)NULL, PV_NONE, 2322 #endif 2323 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2324 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP 2325 |P_SECURE, 2326 (char_u *)&p_rtp, PV_NONE, 2327 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L} 2328 SCTX_INIT}, 2329 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF, 2330 (char_u *)VAR_WIN, PV_SCROLL, 2331 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2332 {"scrollbind", "scb", P_BOOL|P_VI_DEF, 2333 (char_u *)VAR_WIN, PV_SCBIND, 2334 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2335 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM, 2336 (char_u *)&p_sj, PV_NONE, 2337 {(char_u *)1L, (char_u *)0L} SCTX_INIT}, 2338 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL, 2339 (char_u *)&p_so, PV_SO, 2340 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2341 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 2342 (char_u *)&p_sbo, PV_NONE, 2343 {(char_u *)"ver,jump", (char_u *)0L} 2344 SCTX_INIT}, 2345 {"sections", "sect", P_STRING|P_VI_DEF, 2346 (char_u *)&p_sections, PV_NONE, 2347 {(char_u *)"SHNHH HUnhsh", (char_u *)0L} 2348 SCTX_INIT}, 2349 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE, 2350 (char_u *)&p_secure, PV_NONE, 2351 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2352 {"selection", "sel", P_STRING|P_VI_DEF, 2353 (char_u *)&p_sel, PV_NONE, 2354 {(char_u *)"inclusive", (char_u *)0L} 2355 SCTX_INIT}, 2356 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 2357 (char_u *)&p_slm, PV_NONE, 2358 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2359 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 2360 #ifdef FEAT_SESSION 2361 (char_u *)&p_ssop, PV_NONE, 2362 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal", 2363 (char_u *)0L} 2364 #else 2365 (char_u *)NULL, PV_NONE, 2366 {(char_u *)0L, (char_u *)0L} 2367 #endif 2368 SCTX_INIT}, 2369 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2370 (char_u *)&p_sh, PV_NONE, 2371 { 2372 #ifdef VMS 2373 (char_u *)"-", 2374 #else 2375 # if defined(WIN3264) 2376 (char_u *)"", /* set in set_init_1() */ 2377 # else 2378 (char_u *)"sh", 2379 # endif 2380 #endif /* VMS */ 2381 (char_u *)0L} SCTX_INIT}, 2382 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE, 2383 (char_u *)&p_shcf, PV_NONE, 2384 { 2385 #if defined(MSWIN) 2386 (char_u *)"/c", 2387 #else 2388 (char_u *)"-c", 2389 #endif 2390 (char_u *)0L} SCTX_INIT}, 2391 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE, 2392 #ifdef FEAT_QUICKFIX 2393 (char_u *)&p_sp, PV_NONE, 2394 { 2395 #if defined(UNIX) 2396 (char_u *)"| tee", 2397 #else 2398 (char_u *)">", 2399 #endif 2400 (char_u *)0L} 2401 #else 2402 (char_u *)NULL, PV_NONE, 2403 {(char_u *)0L, (char_u *)0L} 2404 #endif 2405 SCTX_INIT}, 2406 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE, 2407 (char_u *)&p_shq, PV_NONE, 2408 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2409 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE, 2410 (char_u *)&p_srr, PV_NONE, 2411 {(char_u *)">", (char_u *)0L} SCTX_INIT}, 2412 {"shellslash", "ssl", P_BOOL|P_VI_DEF, 2413 #ifdef BACKSLASH_IN_FILENAME 2414 (char_u *)&p_ssl, PV_NONE, 2415 #else 2416 (char_u *)NULL, PV_NONE, 2417 #endif 2418 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2419 {"shelltemp", "stmp", P_BOOL, 2420 (char_u *)&p_stmp, PV_NONE, 2421 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT}, 2422 {"shelltype", "st", P_NUM|P_VI_DEF, 2423 #ifdef AMIGA 2424 (char_u *)&p_st, PV_NONE, 2425 #else 2426 (char_u *)NULL, PV_NONE, 2427 #endif 2428 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2429 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE, 2430 (char_u *)&p_sxq, PV_NONE, 2431 { 2432 #if defined(UNIX) && defined(USE_SYSTEM) 2433 (char_u *)"\"", 2434 #else 2435 (char_u *)"", 2436 #endif 2437 (char_u *)0L} SCTX_INIT}, 2438 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE, 2439 (char_u *)&p_sxe, PV_NONE, 2440 { 2441 #if defined(WIN3264) 2442 (char_u *)"\"&|<>()@^", 2443 #else 2444 (char_u *)"", 2445 #endif 2446 (char_u *)0L} SCTX_INIT}, 2447 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM, 2448 (char_u *)&p_sr, PV_NONE, 2449 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2450 {"shiftwidth", "sw", P_NUM|P_VI_DEF, 2451 (char_u *)&p_sw, PV_SW, 2452 {(char_u *)8L, (char_u *)0L} SCTX_INIT}, 2453 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST, 2454 (char_u *)&p_shm, PV_NONE, 2455 {(char_u *)"", (char_u *)"filnxtToO"} 2456 SCTX_INIT}, 2457 {"shortname", "sn", P_BOOL|P_VI_DEF, 2458 (char_u *)&p_sn, PV_SN, 2459 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2460 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL, 2461 #ifdef FEAT_LINEBREAK 2462 (char_u *)&p_sbr, PV_NONE, 2463 #else 2464 (char_u *)NULL, PV_NONE, 2465 #endif 2466 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2467 {"showcmd", "sc", P_BOOL|P_VIM, 2468 #ifdef FEAT_CMDL_INFO 2469 (char_u *)&p_sc, PV_NONE, 2470 #else 2471 (char_u *)NULL, PV_NONE, 2472 #endif 2473 {(char_u *)FALSE, 2474 #ifdef UNIX 2475 (char_u *)FALSE 2476 #else 2477 (char_u *)TRUE 2478 #endif 2479 } SCTX_INIT}, 2480 {"showfulltag", "sft", P_BOOL|P_VI_DEF, 2481 (char_u *)&p_sft, PV_NONE, 2482 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2483 {"showmatch", "sm", P_BOOL|P_VI_DEF, 2484 (char_u *)&p_sm, PV_NONE, 2485 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2486 {"showmode", "smd", P_BOOL|P_VIM, 2487 (char_u *)&p_smd, PV_NONE, 2488 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT}, 2489 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL, 2490 (char_u *)&p_stal, PV_NONE, 2491 {(char_u *)1L, (char_u *)0L} SCTX_INIT}, 2492 {"sidescroll", "ss", P_NUM|P_VI_DEF, 2493 (char_u *)&p_ss, PV_NONE, 2494 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2495 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF, 2496 (char_u *)&p_siso, PV_SISO, 2497 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2498 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN, 2499 #ifdef FEAT_SIGNS 2500 (char_u *)VAR_WIN, PV_SCL, 2501 {(char_u *)"auto", (char_u *)0L} 2502 #else 2503 (char_u *)NULL, PV_NONE, 2504 {(char_u *)NULL, (char_u *)0L} 2505 #endif 2506 SCTX_INIT}, 2507 {"slowopen", "slow", P_BOOL|P_VI_DEF, 2508 (char_u *)NULL, PV_NONE, 2509 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2510 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM, 2511 (char_u *)&p_scs, PV_NONE, 2512 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2513 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM, 2514 #ifdef FEAT_SMARTINDENT 2515 (char_u *)&p_si, PV_SI, 2516 #else 2517 (char_u *)NULL, PV_NONE, 2518 #endif 2519 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2520 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM, 2521 (char_u *)&p_sta, PV_NONE, 2522 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2523 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM, 2524 (char_u *)&p_sts, PV_STS, 2525 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2526 {"sourceany", NULL, P_BOOL|P_VI_DEF, 2527 (char_u *)NULL, PV_NONE, 2528 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2529 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN, 2530 #ifdef FEAT_SPELL 2531 (char_u *)VAR_WIN, PV_SPELL, 2532 #else 2533 (char_u *)NULL, PV_NONE, 2534 #endif 2535 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2536 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF, 2537 #ifdef FEAT_SPELL 2538 (char_u *)&p_spc, PV_SPC, 2539 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L} 2540 #else 2541 (char_u *)NULL, PV_NONE, 2542 {(char_u *)0L, (char_u *)0L} 2543 #endif 2544 SCTX_INIT}, 2545 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE 2546 |P_ONECOMMA, 2547 #ifdef FEAT_SPELL 2548 (char_u *)&p_spf, PV_SPF, 2549 {(char_u *)"", (char_u *)0L} 2550 #else 2551 (char_u *)NULL, PV_NONE, 2552 {(char_u *)0L, (char_u *)0L} 2553 #endif 2554 SCTX_INIT}, 2555 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA 2556 |P_RBUF|P_EXPAND, 2557 #ifdef FEAT_SPELL 2558 (char_u *)&p_spl, PV_SPL, 2559 {(char_u *)"en", (char_u *)0L} 2560 #else 2561 (char_u *)NULL, PV_NONE, 2562 {(char_u *)0L, (char_u *)0L} 2563 #endif 2564 SCTX_INIT}, 2565 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA, 2566 #ifdef FEAT_SPELL 2567 (char_u *)&p_sps, PV_NONE, 2568 {(char_u *)"best", (char_u *)0L} 2569 #else 2570 (char_u *)NULL, PV_NONE, 2571 {(char_u *)0L, (char_u *)0L} 2572 #endif 2573 SCTX_INIT}, 2574 {"splitbelow", "sb", P_BOOL|P_VI_DEF, 2575 (char_u *)&p_sb, PV_NONE, 2576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2577 {"splitright", "spr", P_BOOL|P_VI_DEF, 2578 (char_u *)&p_spr, PV_NONE, 2579 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2580 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM, 2581 (char_u *)&p_sol, PV_NONE, 2582 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2583 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT, 2584 #ifdef FEAT_STL_OPT 2585 (char_u *)&p_stl, PV_STL, 2586 #else 2587 (char_u *)NULL, PV_NONE, 2588 #endif 2589 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2590 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 2591 (char_u *)&p_su, PV_NONE, 2592 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj", 2593 (char_u *)0L} SCTX_INIT}, 2594 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP, 2595 #ifdef FEAT_SEARCHPATH 2596 (char_u *)&p_sua, PV_SUA, 2597 {(char_u *)"", (char_u *)0L} 2598 #else 2599 (char_u *)NULL, PV_NONE, 2600 {(char_u *)0L, (char_u *)0L} 2601 #endif 2602 SCTX_INIT}, 2603 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT, 2604 (char_u *)&p_swf, PV_SWF, 2605 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2606 {"swapsync", "sws", P_STRING|P_VI_DEF, 2607 (char_u *)&p_sws, PV_NONE, 2608 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT}, 2609 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 2610 (char_u *)&p_swb, PV_NONE, 2611 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2612 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF, 2613 #ifdef FEAT_SYN_HL 2614 (char_u *)&p_smc, PV_SMC, 2615 {(char_u *)3000L, (char_u *)0L} 2616 #else 2617 (char_u *)NULL, PV_NONE, 2618 {(char_u *)0L, (char_u *)0L} 2619 #endif 2620 SCTX_INIT}, 2621 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME, 2622 #ifdef FEAT_SYN_HL 2623 (char_u *)&p_syn, PV_SYN, 2624 {(char_u *)"", (char_u *)0L} 2625 #else 2626 (char_u *)NULL, PV_NONE, 2627 {(char_u *)0L, (char_u *)0L} 2628 #endif 2629 SCTX_INIT}, 2630 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL, 2631 #ifdef FEAT_STL_OPT 2632 (char_u *)&p_tal, PV_NONE, 2633 #else 2634 (char_u *)NULL, PV_NONE, 2635 #endif 2636 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2637 {"tabpagemax", "tpm", P_NUM|P_VI_DEF, 2638 (char_u *)&p_tpm, PV_NONE, 2639 {(char_u *)10L, (char_u *)0L} SCTX_INIT}, 2640 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF, 2641 (char_u *)&p_ts, PV_TS, 2642 {(char_u *)8L, (char_u *)0L} SCTX_INIT}, 2643 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF, 2644 (char_u *)&p_tbs, PV_NONE, 2645 #ifdef VMS /* binary searching doesn't appear to work on VMS */ 2646 {(char_u *)0L, (char_u *)0L} 2647 #else 2648 {(char_u *)TRUE, (char_u *)0L} 2649 #endif 2650 SCTX_INIT}, 2651 {"tagcase", "tc", P_STRING|P_VIM, 2652 (char_u *)&p_tc, PV_TC, 2653 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT}, 2654 {"taglength", "tl", P_NUM|P_VI_DEF, 2655 (char_u *)&p_tl, PV_NONE, 2656 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2657 {"tagrelative", "tr", P_BOOL|P_VIM, 2658 (char_u *)&p_tr, PV_NONE, 2659 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT}, 2660 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP, 2661 (char_u *)&p_tags, PV_TAGS, 2662 { 2663 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME) 2664 (char_u *)"./tags,./TAGS,tags,TAGS", 2665 #else 2666 (char_u *)"./tags,tags", 2667 #endif 2668 (char_u *)0L} SCTX_INIT}, 2669 {"tagstack", "tgst", P_BOOL|P_VI_DEF, 2670 (char_u *)&p_tgst, PV_NONE, 2671 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2672 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2673 #if defined(DYNAMIC_TCL) 2674 (char_u *)&p_tcldll, PV_NONE, 2675 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L} 2676 #else 2677 (char_u *)NULL, PV_NONE, 2678 {(char_u *)0L, (char_u *)0L} 2679 #endif 2680 SCTX_INIT}, 2681 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL, 2682 (char_u *)&T_NAME, PV_NONE, 2683 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2684 {"termbidi", "tbidi", P_BOOL|P_VI_DEF, 2685 #ifdef FEAT_ARABIC 2686 (char_u *)&p_tbidi, PV_NONE, 2687 #else 2688 (char_u *)NULL, PV_NONE, 2689 #endif 2690 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2691 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR, 2692 (char_u *)&p_tenc, PV_NONE, 2693 {(char_u *)"", (char_u *)0L} 2694 SCTX_INIT}, 2695 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, 2696 #ifdef FEAT_TERMGUICOLORS 2697 (char_u *)&p_tgc, PV_NONE, 2698 {(char_u *)FALSE, (char_u *)FALSE} 2699 #else 2700 (char_u*)NULL, PV_NONE, 2701 {(char_u *)FALSE, (char_u *)FALSE} 2702 #endif 2703 SCTX_INIT}, 2704 {"termmode", "tmod", P_STRING|P_ALLOCED|P_VI_DEF, 2705 #ifdef FEAT_TERMINAL 2706 (char_u *)VAR_WIN, PV_TMOD, 2707 {(char_u *)"", (char_u *)NULL} 2708 #else 2709 (char_u *)NULL, PV_NONE, 2710 {(char_u *)NULL, (char_u *)0L} 2711 #endif 2712 SCTX_INIT}, 2713 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF, 2714 #ifdef FEAT_TERMINAL 2715 (char_u *)VAR_WIN, PV_TWK, 2716 {(char_u *)"", (char_u *)NULL} 2717 #else 2718 (char_u *)NULL, PV_NONE, 2719 {(char_u *)NULL, (char_u *)0L} 2720 #endif 2721 SCTX_INIT}, 2722 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF, 2723 #ifdef FEAT_TERMINAL 2724 (char_u *)&p_twsl, PV_TWSL, 2725 {(char_u *)10000L, (char_u *)10000L} 2726 #else 2727 (char_u *)NULL, PV_NONE, 2728 {(char_u *)NULL, (char_u *)0L} 2729 #endif 2730 SCTX_INIT}, 2731 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF, 2732 #ifdef FEAT_TERMINAL 2733 (char_u *)VAR_WIN, PV_TWS, 2734 {(char_u *)"", (char_u *)NULL} 2735 #else 2736 (char_u *)NULL, PV_NONE, 2737 {(char_u *)NULL, (char_u *)0L} 2738 #endif 2739 SCTX_INIT}, 2740 {"terse", NULL, P_BOOL|P_VI_DEF, 2741 (char_u *)&p_terse, PV_NONE, 2742 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2743 {"textauto", "ta", P_BOOL|P_VIM, 2744 (char_u *)&p_ta, PV_NONE, 2745 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE} 2746 SCTX_INIT}, 2747 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC, 2748 (char_u *)&p_tx, PV_TX, 2749 { 2750 #ifdef USE_CRNL 2751 (char_u *)TRUE, 2752 #else 2753 (char_u *)FALSE, 2754 #endif 2755 (char_u *)0L} SCTX_INIT}, 2756 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF, 2757 (char_u *)&p_tw, PV_TW, 2758 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2759 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME, 2760 #ifdef FEAT_INS_EXPAND 2761 (char_u *)&p_tsr, PV_TSR, 2762 #else 2763 (char_u *)NULL, PV_NONE, 2764 #endif 2765 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2766 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM, 2767 (char_u *)&p_to, PV_NONE, 2768 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2769 {"timeout", "to", P_BOOL|P_VI_DEF, 2770 (char_u *)&p_timeout, PV_NONE, 2771 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2772 {"timeoutlen", "tm", P_NUM|P_VI_DEF, 2773 (char_u *)&p_tm, PV_NONE, 2774 {(char_u *)1000L, (char_u *)0L} SCTX_INIT}, 2775 {"title", NULL, P_BOOL|P_VI_DEF, 2776 #ifdef FEAT_TITLE 2777 (char_u *)&p_title, PV_NONE, 2778 #else 2779 (char_u *)NULL, PV_NONE, 2780 #endif 2781 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2782 {"titlelen", NULL, P_NUM|P_VI_DEF, 2783 #ifdef FEAT_TITLE 2784 (char_u *)&p_titlelen, PV_NONE, 2785 #else 2786 (char_u *)NULL, PV_NONE, 2787 #endif 2788 {(char_u *)85L, (char_u *)0L} SCTX_INIT}, 2789 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC, 2790 #ifdef FEAT_TITLE 2791 (char_u *)&p_titleold, PV_NONE, 2792 {(char_u *)N_("Thanks for flying Vim"), 2793 (char_u *)0L} 2794 #else 2795 (char_u *)NULL, PV_NONE, 2796 {(char_u *)0L, (char_u *)0L} 2797 #endif 2798 SCTX_INIT}, 2799 {"titlestring", NULL, P_STRING|P_VI_DEF, 2800 #ifdef FEAT_TITLE 2801 (char_u *)&p_titlestring, PV_NONE, 2802 #else 2803 (char_u *)NULL, PV_NONE, 2804 #endif 2805 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2806 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP, 2807 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) 2808 (char_u *)&p_toolbar, PV_NONE, 2809 {(char_u *)"icons,tooltips", (char_u *)0L} 2810 #else 2811 (char_u *)NULL, PV_NONE, 2812 {(char_u *)0L, (char_u *)0L} 2813 #endif 2814 SCTX_INIT}, 2815 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF, 2816 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) 2817 (char_u *)&p_tbis, PV_NONE, 2818 {(char_u *)"small", (char_u *)0L} 2819 #else 2820 (char_u *)NULL, PV_NONE, 2821 {(char_u *)0L, (char_u *)0L} 2822 #endif 2823 SCTX_INIT}, 2824 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM, 2825 (char_u *)&p_ttimeout, PV_NONE, 2826 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2827 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF, 2828 (char_u *)&p_ttm, PV_NONE, 2829 {(char_u *)-1L, (char_u *)0L} SCTX_INIT}, 2830 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF, 2831 (char_u *)&p_tbi, PV_NONE, 2832 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2833 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF, 2834 (char_u *)&p_tf, PV_NONE, 2835 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2836 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF, 2837 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) 2838 (char_u *)&p_ttym, PV_NONE, 2839 #else 2840 (char_u *)NULL, PV_NONE, 2841 #endif 2842 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2843 {"ttyscroll", "tsl", P_NUM|P_VI_DEF, 2844 (char_u *)&p_ttyscroll, PV_NONE, 2845 {(char_u *)999L, (char_u *)0L} SCTX_INIT}, 2846 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL, 2847 (char_u *)&T_NAME, PV_NONE, 2848 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2849 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE 2850 |P_VI_DEF, 2851 #ifdef FEAT_PERSISTENT_UNDO 2852 (char_u *)&p_udir, PV_NONE, 2853 {(char_u *)".", (char_u *)0L} 2854 #else 2855 (char_u *)NULL, PV_NONE, 2856 {(char_u *)0L, (char_u *)0L} 2857 #endif 2858 SCTX_INIT}, 2859 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM, 2860 #ifdef FEAT_PERSISTENT_UNDO 2861 (char_u *)&p_udf, PV_UDF, 2862 #else 2863 (char_u *)NULL, PV_NONE, 2864 #endif 2865 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2866 {"undolevels", "ul", P_NUM|P_VI_DEF, 2867 (char_u *)&p_ul, PV_UL, 2868 { 2869 #if defined(UNIX) || defined(WIN3264) || defined(VMS) 2870 (char_u *)1000L, 2871 #else 2872 (char_u *)100L, 2873 #endif 2874 (char_u *)0L} SCTX_INIT}, 2875 {"undoreload", "ur", P_NUM|P_VI_DEF, 2876 (char_u *)&p_ur, PV_NONE, 2877 { (char_u *)10000L, (char_u *)0L} SCTX_INIT}, 2878 {"updatecount", "uc", P_NUM|P_VI_DEF, 2879 (char_u *)&p_uc, PV_NONE, 2880 {(char_u *)200L, (char_u *)0L} SCTX_INIT}, 2881 {"updatetime", "ut", P_NUM|P_VI_DEF, 2882 (char_u *)&p_ut, PV_NONE, 2883 {(char_u *)4000L, (char_u *)0L} SCTX_INIT}, 2884 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA, 2885 #ifdef FEAT_VARTABS 2886 (char_u *)&p_vsts, PV_VSTS, 2887 {(char_u *)"", (char_u *)0L} 2888 #else 2889 (char_u *)NULL, PV_NONE, 2890 {(char_u *)"", (char_u *)NULL} 2891 #endif 2892 SCTX_INIT}, 2893 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA, 2894 #ifdef FEAT_VARTABS 2895 (char_u *)&p_vts, PV_VTS, 2896 {(char_u *)"", (char_u *)0L} 2897 #else 2898 (char_u *)NULL, PV_NONE, 2899 {(char_u *)"", (char_u *)NULL} 2900 #endif 2901 SCTX_INIT}, 2902 {"verbose", "vbs", P_NUM|P_VI_DEF, 2903 (char_u *)&p_verbose, PV_NONE, 2904 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2905 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2906 (char_u *)&p_vfile, PV_NONE, 2907 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2908 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 2909 #ifdef FEAT_SESSION 2910 (char_u *)&p_vdir, PV_NONE, 2911 {(char_u *)DFLT_VDIR, (char_u *)0L} 2912 #else 2913 (char_u *)NULL, PV_NONE, 2914 {(char_u *)0L, (char_u *)0L} 2915 #endif 2916 SCTX_INIT}, 2917 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 2918 #ifdef FEAT_SESSION 2919 (char_u *)&p_vop, PV_NONE, 2920 {(char_u *)"folds,options,cursor,curdir", 2921 (char_u *)0L} 2922 #else 2923 (char_u *)NULL, PV_NONE, 2924 {(char_u *)0L, (char_u *)0L} 2925 #endif 2926 SCTX_INIT}, 2927 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE, 2928 #ifdef FEAT_VIMINFO 2929 (char_u *)&p_viminfo, PV_NONE, 2930 #if defined(MSWIN) 2931 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"} 2932 #else 2933 # ifdef AMIGA 2934 {(char_u *)"", 2935 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"} 2936 # else 2937 {(char_u *)"", (char_u *)"'100,<50,s10,h"} 2938 # endif 2939 #endif 2940 #else 2941 (char_u *)NULL, PV_NONE, 2942 {(char_u *)0L, (char_u *)0L} 2943 #endif 2944 SCTX_INIT}, 2945 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP 2946 |P_SECURE|P_VI_DEF, 2947 #ifdef FEAT_VIMINFO 2948 (char_u *)&p_viminfofile, PV_NONE, 2949 {(char_u *)"", (char_u *)0L} 2950 #else 2951 (char_u *)NULL, PV_NONE, 2952 {(char_u *)0L, (char_u *)0L} 2953 #endif 2954 SCTX_INIT}, 2955 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF 2956 |P_VIM|P_CURSWANT, 2957 (char_u *)&p_ve, PV_NONE, 2958 {(char_u *)"", (char_u *)""} 2959 SCTX_INIT}, 2960 {"visualbell", "vb", P_BOOL|P_VI_DEF, 2961 (char_u *)&p_vb, PV_NONE, 2962 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2963 {"w300", NULL, P_NUM|P_VI_DEF, 2964 (char_u *)NULL, PV_NONE, 2965 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2966 {"w1200", NULL, P_NUM|P_VI_DEF, 2967 (char_u *)NULL, PV_NONE, 2968 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2969 {"w9600", NULL, P_NUM|P_VI_DEF, 2970 (char_u *)NULL, PV_NONE, 2971 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2972 {"warn", NULL, P_BOOL|P_VI_DEF, 2973 (char_u *)&p_warn, PV_NONE, 2974 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 2975 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR, 2976 (char_u *)&p_wiv, PV_NONE, 2977 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2978 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST, 2979 (char_u *)&p_ww, PV_NONE, 2980 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT}, 2981 {"wildchar", "wc", P_NUM|P_VIM, 2982 (char_u *)&p_wc, PV_NONE, 2983 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB} 2984 SCTX_INIT}, 2985 {"wildcharm", "wcm", P_NUM|P_VI_DEF, 2986 (char_u *)&p_wcm, PV_NONE, 2987 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 2988 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 2989 #ifdef FEAT_WILDIGN 2990 (char_u *)&p_wig, PV_NONE, 2991 #else 2992 (char_u *)NULL, PV_NONE, 2993 #endif 2994 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 2995 {"wildignorecase", "wic", P_BOOL|P_VI_DEF, 2996 (char_u *)&p_wic, PV_NONE, 2997 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 2998 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF, 2999 #ifdef FEAT_WILDMENU 3000 (char_u *)&p_wmnu, PV_NONE, 3001 #else 3002 (char_u *)NULL, PV_NONE, 3003 #endif 3004 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 3005 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, 3006 (char_u *)&p_wim, PV_NONE, 3007 {(char_u *)"full", (char_u *)0L} SCTX_INIT}, 3008 {"wildoptions", "wop", P_STRING|P_VI_DEF, 3009 #ifdef FEAT_CMDL_COMPL 3010 (char_u *)&p_wop, PV_NONE, 3011 {(char_u *)"", (char_u *)0L} 3012 #else 3013 (char_u *)NULL, PV_NONE, 3014 {(char_u *)NULL, (char_u *)0L} 3015 #endif 3016 SCTX_INIT}, 3017 {"winaltkeys", "wak", P_STRING|P_VI_DEF, 3018 #ifdef FEAT_WAK 3019 (char_u *)&p_wak, PV_NONE, 3020 {(char_u *)"menu", (char_u *)0L} 3021 #else 3022 (char_u *)NULL, PV_NONE, 3023 {(char_u *)NULL, (char_u *)0L} 3024 #endif 3025 SCTX_INIT}, 3026 {"window", "wi", P_NUM|P_VI_DEF, 3027 (char_u *)&p_window, PV_NONE, 3028 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 3029 {"winheight", "wh", P_NUM|P_VI_DEF, 3030 (char_u *)&p_wh, PV_NONE, 3031 {(char_u *)1L, (char_u *)0L} SCTX_INIT}, 3032 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT, 3033 (char_u *)VAR_WIN, PV_WFH, 3034 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 3035 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT, 3036 (char_u *)VAR_WIN, PV_WFW, 3037 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 3038 {"winminheight", "wmh", P_NUM|P_VI_DEF, 3039 (char_u *)&p_wmh, PV_NONE, 3040 {(char_u *)1L, (char_u *)0L} SCTX_INIT}, 3041 {"winminwidth", "wmw", P_NUM|P_VI_DEF, 3042 (char_u *)&p_wmw, PV_NONE, 3043 {(char_u *)1L, (char_u *)0L} SCTX_INIT}, 3044 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, 3045 #if defined(WIN3264) && defined(FEAT_TERMINAL) 3046 (char_u *)&p_winptydll, PV_NONE, { 3047 # ifdef _WIN64 3048 (char_u *)"winpty64.dll", 3049 # else 3050 (char_u *)"winpty32.dll", 3051 # endif 3052 (char_u *)0L} 3053 #else 3054 (char_u *)NULL, PV_NONE, 3055 {(char_u *)0L, (char_u *)0L} 3056 #endif 3057 SCTX_INIT}, 3058 {"winwidth", "wiw", P_NUM|P_VI_DEF, 3059 (char_u *)&p_wiw, PV_NONE, 3060 {(char_u *)20L, (char_u *)0L} SCTX_INIT}, 3061 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN, 3062 (char_u *)VAR_WIN, PV_WRAP, 3063 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 3064 {"wrapmargin", "wm", P_NUM|P_VI_DEF, 3065 (char_u *)&p_wm, PV_WM, 3066 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 3067 {"wrapscan", "ws", P_BOOL|P_VI_DEF, 3068 (char_u *)&p_ws, PV_NONE, 3069 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 3070 {"write", NULL, P_BOOL|P_VI_DEF, 3071 (char_u *)&p_write, PV_NONE, 3072 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, 3073 {"writeany", "wa", P_BOOL|P_VI_DEF, 3074 (char_u *)&p_wa, PV_NONE, 3075 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, 3076 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM, 3077 (char_u *)&p_wb, PV_NONE, 3078 { 3079 #ifdef FEAT_WRITEBACKUP 3080 (char_u *)TRUE, 3081 #else 3082 (char_u *)FALSE, 3083 #endif 3084 (char_u *)0L} SCTX_INIT}, 3085 {"writedelay", "wd", P_NUM|P_VI_DEF, 3086 (char_u *)&p_wd, PV_NONE, 3087 {(char_u *)0L, (char_u *)0L} SCTX_INIT}, 3088 3089 /* terminal output codes */ 3090 #define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \ 3091 (char_u *)&vvv, PV_NONE, \ 3092 {(char_u *)"", (char_u *)0L} SCTX_INIT}, 3093 3094 p_term("t_AB", T_CAB) 3095 p_term("t_AF", T_CAF) 3096 p_term("t_AL", T_CAL) 3097 p_term("t_al", T_AL) 3098 p_term("t_bc", T_BC) 3099 p_term("t_BE", T_BE) 3100 p_term("t_BD", T_BD) 3101 p_term("t_cd", T_CD) 3102 p_term("t_ce", T_CE) 3103 p_term("t_cl", T_CL) 3104 p_term("t_cm", T_CM) 3105 p_term("t_Ce", T_UCE) 3106 p_term("t_Co", T_CCO) 3107 p_term("t_CS", T_CCS) 3108 p_term("t_Cs", T_UCS) 3109 p_term("t_cs", T_CS) 3110 p_term("t_CV", T_CSV) 3111 p_term("t_da", T_DA) 3112 p_term("t_db", T_DB) 3113 p_term("t_DL", T_CDL) 3114 p_term("t_dl", T_DL) 3115 p_term("t_EC", T_CEC) 3116 p_term("t_EI", T_CEI) 3117 p_term("t_fs", T_FS) 3118 p_term("t_GP", T_CGP) 3119 p_term("t_IE", T_CIE) 3120 p_term("t_IS", T_CIS) 3121 p_term("t_ke", T_KE) 3122 p_term("t_ks", T_KS) 3123 p_term("t_le", T_LE) 3124 p_term("t_mb", T_MB) 3125 p_term("t_md", T_MD) 3126 p_term("t_me", T_ME) 3127 p_term("t_mr", T_MR) 3128 p_term("t_ms", T_MS) 3129 p_term("t_nd", T_ND) 3130 p_term("t_op", T_OP) 3131 p_term("t_RF", T_RFG) 3132 p_term("t_RB", T_RBG) 3133 p_term("t_RC", T_CRC) 3134 p_term("t_RI", T_CRI) 3135 p_term("t_Ri", T_SRI) 3136 p_term("t_RS", T_CRS) 3137 p_term("t_RT", T_CRT) 3138 p_term("t_RV", T_CRV) 3139 p_term("t_Sb", T_CSB) 3140 p_term("t_SC", T_CSC) 3141 p_term("t_se", T_SE) 3142 p_term("t_Sf", T_CSF) 3143 p_term("t_SH", T_CSH) 3144 p_term("t_SI", T_CSI) 3145 p_term("t_Si", T_SSI) 3146 p_term("t_so", T_SO) 3147 p_term("t_SR", T_CSR) 3148 p_term("t_sr", T_SR) 3149 p_term("t_ST", T_CST) 3150 p_term("t_Te", T_STE) 3151 p_term("t_te", T_TE) 3152 p_term("t_ti", T_TI) 3153 p_term("t_Ts", T_STS) 3154 p_term("t_ts", T_TS) 3155 p_term("t_u7", T_U7) 3156 p_term("t_ue", T_UE) 3157 p_term("t_us", T_US) 3158 p_term("t_ut", T_UT) 3159 p_term("t_vb", T_VB) 3160 p_term("t_ve", T_VE) 3161 p_term("t_vi", T_VI) 3162 p_term("t_VS", T_CVS) 3163 p_term("t_vs", T_VS) 3164 p_term("t_WP", T_CWP) 3165 p_term("t_WS", T_CWS) 3166 p_term("t_xn", T_XN) 3167 p_term("t_xs", T_XS) 3168 p_term("t_ZH", T_CZH) 3169 p_term("t_ZR", T_CZR) 3170 p_term("t_8f", T_8F) 3171 p_term("t_8b", T_8B) 3172 3173 /* terminal key codes are not in here */ 3174 3175 /* end marker */ 3176 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT} 3177 }; 3178 3179 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption)) 3180 3181 static char *(p_ambw_values[]) = {"single", "double", NULL}; 3182 static char *(p_bg_values[]) = {"light", "dark", NULL}; 3183 static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL}; 3184 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; 3185 #ifdef FEAT_CRYPT 3186 static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL}; 3187 #endif 3188 #ifdef FEAT_CMDL_COMPL 3189 static char *(p_wop_values[]) = {"tagfile", NULL}; 3190 #endif 3191 #ifdef FEAT_WAK 3192 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; 3193 #endif 3194 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL}; 3195 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL}; 3196 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL}; 3197 static char *(p_km_values[]) = {"startsel", "stopsel", NULL}; 3198 #ifdef FEAT_BROWSE 3199 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL}; 3200 #endif 3201 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL}; 3202 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL}; 3203 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; 3204 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL}; 3205 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL}; 3206 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL}; 3207 #ifdef FEAT_FOLDING 3208 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", 3209 # ifdef FEAT_DIFF 3210 "diff", 3211 # endif 3212 NULL}; 3213 static char *(p_fcl_values[]) = {"all", NULL}; 3214 #endif 3215 #ifdef FEAT_INS_EXPAND 3216 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL}; 3217 #endif 3218 #ifdef FEAT_SIGNS 3219 static char *(p_scl_values[]) = {"yes", "no", "auto", NULL}; 3220 #endif 3221 #ifdef FEAT_TERMINAL 3222 static char *(p_tmod_values[]) = {"winpty", "conpty", "", NULL}; 3223 #endif 3224 3225 static void set_options_default(int opt_flags); 3226 static void set_string_default_esc(char *name, char_u *val, int escape); 3227 static char_u *term_bg_default(void); 3228 static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked); 3229 static char_u *option_expand(int opt_idx, char_u *val); 3230 static void didset_options(void); 3231 static void didset_options2(void); 3232 static void check_string_option(char_u **pp); 3233 #if defined(FEAT_EVAL) || defined(PROTO) 3234 static long_u *insecure_flag(int opt_idx, int opt_flags); 3235 #else 3236 # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags) 3237 #endif 3238 static void set_string_option_global(int opt_idx, char_u **varp); 3239 static char *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char *errbuf, int opt_flags, int *value_checked); 3240 static char *set_chars_option(char_u **varp); 3241 #ifdef FEAT_CLIPBOARD 3242 static char *check_clipboard_option(void); 3243 #endif 3244 #ifdef FEAT_SPELL 3245 static char *did_set_spell_option(int is_spellfile); 3246 static char *compile_cap_prog(synblock_T *synblock); 3247 #endif 3248 #ifdef FEAT_EVAL 3249 static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx); 3250 #endif 3251 static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags); 3252 static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags); 3253 static void check_redraw(long_u flags); 3254 static int findoption(char_u *); 3255 static int find_key_option(char_u *arg_arg, int has_lt); 3256 static void showoptions(int all, int opt_flags); 3257 static int optval_default(struct vimoption *, char_u *varp); 3258 static void showoneopt(struct vimoption *, int opt_flags); 3259 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags); 3260 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep); 3261 static int put_setbool(FILE *fd, char *cmd, char *name, int value); 3262 static int istermoption(struct vimoption *); 3263 static char_u *get_varp_scope(struct vimoption *p, int opt_flags); 3264 static char_u *get_varp(struct vimoption *); 3265 static void option_value2string(struct vimoption *, int opt_flags); 3266 static void check_winopt(winopt_T *wop); 3267 static int wc_use_keyname(char_u *varp, long *wcp); 3268 #ifdef FEAT_LANGMAP 3269 static void langmap_init(void); 3270 static void langmap_set(void); 3271 #endif 3272 static void paste_option_changed(void); 3273 static void compatible_set(void); 3274 #ifdef FEAT_LINEBREAK 3275 static void fill_breakat_flags(void); 3276 #endif 3277 static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list); 3278 static int check_opt_strings(char_u *val, char **values, int); 3279 static int check_opt_wim(void); 3280 #ifdef FEAT_LINEBREAK 3281 static int briopt_check(win_T *wp); 3282 #endif 3283 3284 /* 3285 * Initialize the options, first part. 3286 * 3287 * Called only once from main(), just after creating the first buffer. 3288 * If "clean_arg" is TRUE Vim was started with --clean. 3289 */ 3290 void 3291 set_init_1(int clean_arg) 3292 { 3293 char_u *p; 3294 int opt_idx; 3295 long_u n; 3296 3297 #ifdef FEAT_LANGMAP 3298 langmap_init(); 3299 #endif 3300 3301 /* Be Vi compatible by default */ 3302 p_cp = TRUE; 3303 3304 /* Use POSIX compatibility when $VIM_POSIX is set. */ 3305 if (mch_getenv((char_u *)"VIM_POSIX") != NULL) 3306 { 3307 set_string_default("cpo", (char_u *)CPO_ALL); 3308 set_string_default("shm", (char_u *)"A"); 3309 } 3310 3311 /* 3312 * Find default value for 'shell' option. 3313 * Don't use it if it is empty. 3314 */ 3315 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL) 3316 #if defined(MSWIN) 3317 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL) 3318 # ifdef WIN3264 3319 || ((p = (char_u *)default_shell()) != NULL && *p != NUL) 3320 # endif 3321 #endif 3322 ) 3323 set_string_default_esc("sh", p, TRUE); 3324 3325 #ifdef FEAT_WILDIGN 3326 /* 3327 * Set the default for 'backupskip' to include environment variables for 3328 * temp files. 3329 */ 3330 { 3331 # ifdef UNIX 3332 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"}; 3333 # else 3334 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"}; 3335 # endif 3336 int len; 3337 garray_T ga; 3338 int mustfree; 3339 3340 ga_init2(&ga, 1, 100); 3341 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n) 3342 { 3343 mustfree = FALSE; 3344 # ifdef UNIX 3345 if (*names[n] == NUL) 3346 # ifdef MACOS_X 3347 p = (char_u *)"/private/tmp"; 3348 # else 3349 p = (char_u *)"/tmp"; 3350 # endif 3351 else 3352 # endif 3353 p = vim_getenv((char_u *)names[n], &mustfree); 3354 if (p != NULL && *p != NUL) 3355 { 3356 /* First time count the NUL, otherwise count the ','. */ 3357 len = (int)STRLEN(p) + 3; 3358 if (ga_grow(&ga, len) == OK) 3359 { 3360 if (ga.ga_len > 0) 3361 STRCAT(ga.ga_data, ","); 3362 STRCAT(ga.ga_data, p); 3363 add_pathsep(ga.ga_data); 3364 STRCAT(ga.ga_data, "*"); 3365 ga.ga_len += len; 3366 } 3367 } 3368 if (mustfree) 3369 vim_free(p); 3370 } 3371 if (ga.ga_data != NULL) 3372 { 3373 set_string_default("bsk", ga.ga_data); 3374 vim_free(ga.ga_data); 3375 } 3376 } 3377 #endif 3378 3379 /* 3380 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory 3381 */ 3382 opt_idx = findoption((char_u *)"maxmemtot"); 3383 if (opt_idx >= 0) 3384 { 3385 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) 3386 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L) 3387 #endif 3388 { 3389 #ifdef HAVE_AVAIL_MEM 3390 /* Use amount of memory available at this moment. */ 3391 n = (mch_avail_mem(FALSE) >> 1); 3392 #else 3393 # ifdef HAVE_TOTAL_MEM 3394 /* Use amount of memory available to Vim. */ 3395 n = (mch_total_mem(FALSE) >> 1); 3396 # else 3397 n = (0x7fffffff >> 11); 3398 # endif 3399 #endif 3400 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; 3401 opt_idx = findoption((char_u *)"maxmem"); 3402 if (opt_idx >= 0) 3403 { 3404 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM) 3405 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n 3406 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L) 3407 #endif 3408 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; 3409 } 3410 } 3411 } 3412 3413 #ifdef FEAT_SEARCHPATH 3414 { 3415 char_u *cdpath; 3416 char_u *buf; 3417 int i; 3418 int j; 3419 int mustfree = FALSE; 3420 3421 /* Initialize the 'cdpath' option's default value. */ 3422 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree); 3423 if (cdpath != NULL) 3424 { 3425 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2)); 3426 if (buf != NULL) 3427 { 3428 buf[0] = ','; /* start with ",", current dir first */ 3429 j = 1; 3430 for (i = 0; cdpath[i] != NUL; ++i) 3431 { 3432 if (vim_ispathlistsep(cdpath[i])) 3433 buf[j++] = ','; 3434 else 3435 { 3436 if (cdpath[i] == ' ' || cdpath[i] == ',') 3437 buf[j++] = '\\'; 3438 buf[j++] = cdpath[i]; 3439 } 3440 } 3441 buf[j] = NUL; 3442 opt_idx = findoption((char_u *)"cdpath"); 3443 if (opt_idx >= 0) 3444 { 3445 options[opt_idx].def_val[VI_DEFAULT] = buf; 3446 options[opt_idx].flags |= P_DEF_ALLOCED; 3447 } 3448 else 3449 vim_free(buf); /* cannot happen */ 3450 } 3451 if (mustfree) 3452 vim_free(cdpath); 3453 } 3454 } 3455 #endif 3456 3457 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux)) 3458 /* Set print encoding on platforms that don't default to latin1 */ 3459 set_string_default("penc", 3460 # if defined(MSWIN) 3461 (char_u *)"cp1252" 3462 # else 3463 # ifdef VMS 3464 (char_u *)"dec-mcs" 3465 # else 3466 # ifdef EBCDIC 3467 (char_u *)"ebcdic-uk" 3468 # else 3469 # ifdef MAC 3470 (char_u *)"mac-roman" 3471 # else /* HPUX */ 3472 (char_u *)"hp-roman8" 3473 # endif 3474 # endif 3475 # endif 3476 # endif 3477 ); 3478 #endif 3479 3480 #ifdef FEAT_POSTSCRIPT 3481 /* 'printexpr' must be allocated to be able to evaluate it. */ 3482 set_string_default("pexpr", 3483 # if defined(MSWIN) 3484 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)" 3485 # else 3486 # ifdef VMS 3487 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)" 3488 3489 # else 3490 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error" 3491 # endif 3492 # endif 3493 ); 3494 #endif 3495 3496 /* 3497 * Set all the options (except the terminal options) to their default 3498 * value. Also set the global value for local options. 3499 */ 3500 set_options_default(0); 3501 3502 #ifdef CLEAN_RUNTIMEPATH 3503 if (clean_arg) 3504 { 3505 opt_idx = findoption((char_u *)"runtimepath"); 3506 if (opt_idx >= 0) 3507 { 3508 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; 3509 p_rtp = (char_u *)CLEAN_RUNTIMEPATH; 3510 } 3511 opt_idx = findoption((char_u *)"packpath"); 3512 if (opt_idx >= 0) 3513 { 3514 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH; 3515 p_pp = (char_u *)CLEAN_RUNTIMEPATH; 3516 } 3517 } 3518 #endif 3519 3520 #ifdef FEAT_GUI 3521 if (found_reverse_arg) 3522 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0); 3523 #endif 3524 3525 curbuf->b_p_initialized = TRUE; 3526 curbuf->b_p_ar = -1; /* no local 'autoread' value */ 3527 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL; 3528 check_buf_options(curbuf); 3529 check_win_options(curwin); 3530 check_options(); 3531 3532 /* Must be before option_expand(), because that one needs vim_isIDc() */ 3533 didset_options(); 3534 3535 #ifdef FEAT_SPELL 3536 /* Use the current chartab for the generic chartab. This is not in 3537 * didset_options() because it only depends on 'encoding'. */ 3538 init_spell_chartab(); 3539 #endif 3540 3541 /* 3542 * Expand environment variables and things like "~" for the defaults. 3543 * If option_expand() returns non-NULL the variable is expanded. This can 3544 * only happen for non-indirect options. 3545 * Also set the default to the expanded value, so ":set" does not list 3546 * them. 3547 * Don't set the P_ALLOCED flag, because we don't want to free the 3548 * default. 3549 */ 3550 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) 3551 { 3552 if ((options[opt_idx].flags & P_GETTEXT) 3553 && options[opt_idx].var != NULL) 3554 p = (char_u *)_(*(char **)options[opt_idx].var); 3555 else 3556 p = option_expand(opt_idx, NULL); 3557 if (p != NULL && (p = vim_strsave(p)) != NULL) 3558 { 3559 *(char_u **)options[opt_idx].var = p; 3560 /* VIMEXP 3561 * Defaults for all expanded options are currently the same for Vi 3562 * and Vim. When this changes, add some code here! Also need to 3563 * split P_DEF_ALLOCED in two. 3564 */ 3565 if (options[opt_idx].flags & P_DEF_ALLOCED) 3566 vim_free(options[opt_idx].def_val[VI_DEFAULT]); 3567 options[opt_idx].def_val[VI_DEFAULT] = p; 3568 options[opt_idx].flags |= P_DEF_ALLOCED; 3569 } 3570 } 3571 3572 save_file_ff(curbuf); /* Buffer is unchanged */ 3573 3574 #if defined(FEAT_ARABIC) 3575 /* Detect use of mlterm. 3576 * Mlterm is a terminal emulator akin to xterm that has some special 3577 * abilities (bidi namely). 3578 * NOTE: mlterm's author is being asked to 'set' a variable 3579 * instead of an environment variable due to inheritance. 3580 */ 3581 if (mch_getenv((char_u *)"MLTERM") != NULL) 3582 set_option_value((char_u *)"tbidi", 1L, NULL, 0); 3583 #endif 3584 3585 didset_options2(); 3586 3587 # if defined(WIN3264) && defined(FEAT_GETTEXT) 3588 /* 3589 * If $LANG isn't set, try to get a good value for it. This makes the 3590 * right language be used automatically. Don't do this for English. 3591 */ 3592 if (mch_getenv((char_u *)"LANG") == NULL) 3593 { 3594 char buf[20]; 3595 3596 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95. 3597 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use 3598 * only the first two. */ 3599 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, 3600 (LPTSTR)buf, 20); 3601 if (n >= 2 && STRNICMP(buf, "en", 2) != 0) 3602 { 3603 /* There are a few exceptions (probably more) */ 3604 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0) 3605 STRCPY(buf, "zh_TW"); 3606 else if (STRNICMP(buf, "chs", 3) == 0 3607 || STRNICMP(buf, "zhc", 3) == 0) 3608 STRCPY(buf, "zh_CN"); 3609 else if (STRNICMP(buf, "jp", 2) == 0) 3610 STRCPY(buf, "ja"); 3611 else 3612 buf[2] = NUL; /* truncate to two-letter code */ 3613 vim_setenv((char_u *)"LANG", (char_u *)buf); 3614 } 3615 } 3616 # else 3617 # ifdef MACOS_CONVERT 3618 /* Moved to os_mac_conv.c to avoid dependency problems. */ 3619 mac_lang_init(); 3620 # endif 3621 # endif 3622 3623 /* enc_locale() will try to find the encoding of the current locale. */ 3624 p = enc_locale(); 3625 if (p != NULL) 3626 { 3627 char_u *save_enc; 3628 3629 /* Try setting 'encoding' and check if the value is valid. 3630 * If not, go back to the default "latin1". */ 3631 save_enc = p_enc; 3632 p_enc = p; 3633 if (STRCMP(p_enc, "gb18030") == 0) 3634 { 3635 /* We don't support "gb18030", but "cp936" is a good substitute 3636 * for practical purposes, thus use that. It's not an alias to 3637 * still support conversion between gb18030 and utf-8. */ 3638 p_enc = vim_strsave((char_u *)"cp936"); 3639 vim_free(p); 3640 } 3641 if (mb_init() == NULL) 3642 { 3643 opt_idx = findoption((char_u *)"encoding"); 3644 if (opt_idx >= 0) 3645 { 3646 options[opt_idx].def_val[VI_DEFAULT] = p_enc; 3647 options[opt_idx].flags |= P_DEF_ALLOCED; 3648 } 3649 3650 #if defined(MSWIN) || defined(MACOS_X) || defined(VMS) 3651 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8) 3652 { 3653 /* Adjust the default for 'isprint' and 'iskeyword' to match 3654 * latin1. Also set the defaults for when 'nocompatible' is 3655 * set. */ 3656 set_string_option_direct((char_u *)"isp", -1, 3657 ISP_LATIN1, OPT_FREE, SID_NONE); 3658 set_string_option_direct((char_u *)"isk", -1, 3659 ISK_LATIN1, OPT_FREE, SID_NONE); 3660 opt_idx = findoption((char_u *)"isp"); 3661 if (opt_idx >= 0) 3662 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1; 3663 opt_idx = findoption((char_u *)"isk"); 3664 if (opt_idx >= 0) 3665 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1; 3666 (void)init_chartab(); 3667 } 3668 #endif 3669 3670 #if defined(WIN3264) && !defined(FEAT_GUI) 3671 /* Win32 console: When GetACP() returns a different value from 3672 * GetConsoleCP() set 'termencoding'. */ 3673 if (GetACP() != GetConsoleCP()) 3674 { 3675 char buf[50]; 3676 3677 /* Win32 console: In ConPTY, GetConsoleCP() returns zero. 3678 * Use an alternative value. */ 3679 if (GetConsoleCP() == 0) 3680 sprintf(buf, "cp%ld", (long)GetACP()); 3681 else 3682 sprintf(buf, "cp%ld", (long)GetConsoleCP()); 3683 p_tenc = vim_strsave((char_u *)buf); 3684 if (p_tenc != NULL) 3685 { 3686 opt_idx = findoption((char_u *)"termencoding"); 3687 if (opt_idx >= 0) 3688 { 3689 options[opt_idx].def_val[VI_DEFAULT] = p_tenc; 3690 options[opt_idx].flags |= P_DEF_ALLOCED; 3691 } 3692 convert_setup(&input_conv, p_tenc, p_enc); 3693 convert_setup(&output_conv, p_enc, p_tenc); 3694 } 3695 else 3696 p_tenc = empty_option; 3697 } 3698 #endif 3699 #if defined(WIN3264) 3700 /* $HOME may have characters in active code page. */ 3701 init_homedir(); 3702 #endif 3703 } 3704 else 3705 { 3706 vim_free(p_enc); 3707 p_enc = save_enc; 3708 } 3709 } 3710 3711 #ifdef FEAT_MULTI_LANG 3712 /* Set the default for 'helplang'. */ 3713 set_helplang_default(get_mess_lang()); 3714 #endif 3715 } 3716 3717 /* 3718 * Set an option to its default value. 3719 * This does not take care of side effects! 3720 */ 3721 static void 3722 set_option_default( 3723 int opt_idx, 3724 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ 3725 int compatible) /* use Vi default value */ 3726 { 3727 char_u *varp; /* pointer to variable for current option */ 3728 int dvi; /* index in def_val[] */ 3729 long_u flags; 3730 long_u *flagsp; 3731 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; 3732 3733 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); 3734 flags = options[opt_idx].flags; 3735 if (varp != NULL) /* skip hidden option, nothing to do for it */ 3736 { 3737 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; 3738 if (flags & P_STRING) 3739 { 3740 /* Use set_string_option_direct() for local options to handle 3741 * freeing and allocating the value. */ 3742 if (options[opt_idx].indir != PV_NONE) 3743 set_string_option_direct(NULL, opt_idx, 3744 options[opt_idx].def_val[dvi], opt_flags, 0); 3745 else 3746 { 3747 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) 3748 free_string_option(*(char_u **)(varp)); 3749 *(char_u **)varp = options[opt_idx].def_val[dvi]; 3750 options[opt_idx].flags &= ~P_ALLOCED; 3751 } 3752 } 3753 else if (flags & P_NUM) 3754 { 3755 if (options[opt_idx].indir == PV_SCROLL) 3756 win_comp_scroll(curwin); 3757 else 3758 { 3759 long def_val = (long)(long_i)options[opt_idx].def_val[dvi]; 3760 3761 if ((long *)varp == &curwin->w_p_so 3762 || (long *)varp == &curwin->w_p_siso) 3763 // 'scrolloff' and 'sidescrolloff' local values have a 3764 // different default value than the global default. 3765 *(long *)varp = -1; 3766 else 3767 *(long *)varp = def_val; 3768 /* May also set global value for local option. */ 3769 if (both) 3770 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = 3771 def_val; 3772 } 3773 } 3774 else /* P_BOOL */ 3775 { 3776 /* the cast to long is required for Manx C, long_i is needed for 3777 * MSVC */ 3778 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi]; 3779 #ifdef UNIX 3780 /* 'modeline' defaults to off for root */ 3781 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) 3782 *(int *)varp = FALSE; 3783 #endif 3784 /* May also set global value for local option. */ 3785 if (both) 3786 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = 3787 *(int *)varp; 3788 } 3789 3790 /* The default value is not insecure. */ 3791 flagsp = insecure_flag(opt_idx, opt_flags); 3792 *flagsp = *flagsp & ~P_INSECURE; 3793 } 3794 3795 #ifdef FEAT_EVAL 3796 set_option_sctx_idx(opt_idx, opt_flags, current_sctx); 3797 #endif 3798 } 3799 3800 /* 3801 * Set all options (except terminal options) to their default value. 3802 * When "opt_flags" is non-zero skip 'encoding'. 3803 */ 3804 static void 3805 set_options_default( 3806 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ 3807 { 3808 int i; 3809 win_T *wp; 3810 tabpage_T *tp; 3811 3812 for (i = 0; !istermoption(&options[i]); i++) 3813 if (!(options[i].flags & P_NODEFAULT) 3814 && (opt_flags == 0 3815 || (options[i].var != (char_u *)&p_enc 3816 # if defined(FEAT_CRYPT) 3817 && options[i].var != (char_u *)&p_cm 3818 && options[i].var != (char_u *)&p_key 3819 # endif 3820 ))) 3821 set_option_default(i, opt_flags, p_cp); 3822 3823 /* The 'scroll' option must be computed for all windows. */ 3824 FOR_ALL_TAB_WINDOWS(tp, wp) 3825 win_comp_scroll(wp); 3826 #ifdef FEAT_CINDENT 3827 parse_cino(curbuf); 3828 #endif 3829 } 3830 3831 /* 3832 * Set the Vi-default value of a string option. 3833 * Used for 'sh', 'backupskip' and 'term'. 3834 * When "escape" is TRUE escape spaces with a backslash. 3835 */ 3836 static void 3837 set_string_default_esc(char *name, char_u *val, int escape) 3838 { 3839 char_u *p; 3840 int opt_idx; 3841 3842 if (escape && vim_strchr(val, ' ') != NULL) 3843 p = vim_strsave_escaped(val, (char_u *)" "); 3844 else 3845 p = vim_strsave(val); 3846 if (p != NULL) /* we don't want a NULL */ 3847 { 3848 opt_idx = findoption((char_u *)name); 3849 if (opt_idx >= 0) 3850 { 3851 if (options[opt_idx].flags & P_DEF_ALLOCED) 3852 vim_free(options[opt_idx].def_val[VI_DEFAULT]); 3853 options[opt_idx].def_val[VI_DEFAULT] = p; 3854 options[opt_idx].flags |= P_DEF_ALLOCED; 3855 } 3856 } 3857 } 3858 3859 void 3860 set_string_default(char *name, char_u *val) 3861 { 3862 set_string_default_esc(name, val, FALSE); 3863 } 3864 3865 /* 3866 * Set the Vi-default value of a number option. 3867 * Used for 'lines' and 'columns'. 3868 */ 3869 void 3870 set_number_default(char *name, long val) 3871 { 3872 int opt_idx; 3873 3874 opt_idx = findoption((char_u *)name); 3875 if (opt_idx >= 0) 3876 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val; 3877 } 3878 3879 #if defined(EXITFREE) || defined(PROTO) 3880 /* 3881 * Free all options. 3882 */ 3883 void 3884 free_all_options(void) 3885 { 3886 int i; 3887 3888 for (i = 0; !istermoption(&options[i]); i++) 3889 { 3890 if (options[i].indir == PV_NONE) 3891 { 3892 /* global option: free value and default value. */ 3893 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) 3894 free_string_option(*(char_u **)options[i].var); 3895 if (options[i].flags & P_DEF_ALLOCED) 3896 free_string_option(options[i].def_val[VI_DEFAULT]); 3897 } 3898 else if (options[i].var != VAR_WIN 3899 && (options[i].flags & P_STRING)) 3900 /* buffer-local option: free global value */ 3901 free_string_option(*(char_u **)options[i].var); 3902 } 3903 } 3904 #endif 3905 3906 3907 /* 3908 * Initialize the options, part two: After getting Rows and Columns and 3909 * setting 'term'. 3910 */ 3911 void 3912 set_init_2(void) 3913 { 3914 int idx; 3915 3916 /* 3917 * 'scroll' defaults to half the window height. The stored default is zero, 3918 * which results in the actual value computed from the window height. 3919 */ 3920 idx = findoption((char_u *)"scroll"); 3921 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) 3922 set_option_default(idx, OPT_LOCAL, p_cp); 3923 comp_col(); 3924 3925 /* 3926 * 'window' is only for backwards compatibility with Vi. 3927 * Default is Rows - 1. 3928 */ 3929 if (!option_was_set((char_u *)"window")) 3930 p_window = Rows - 1; 3931 set_number_default("window", Rows - 1); 3932 3933 /* For DOS console the default is always black. */ 3934 #if !((defined(WIN3264)) && !defined(FEAT_GUI)) 3935 /* 3936 * If 'background' wasn't set by the user, try guessing the value, 3937 * depending on the terminal name. Only need to check for terminals 3938 * with a dark background, that can handle color. 3939 */ 3940 idx = findoption((char_u *)"bg"); 3941 if (idx >= 0 && !(options[idx].flags & P_WAS_SET) 3942 && *term_bg_default() == 'd') 3943 { 3944 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0); 3945 /* don't mark it as set, when starting the GUI it may be 3946 * changed again */ 3947 options[idx].flags &= ~P_WAS_SET; 3948 } 3949 #endif 3950 3951 #ifdef CURSOR_SHAPE 3952 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */ 3953 #endif 3954 #ifdef FEAT_MOUSESHAPE 3955 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */ 3956 #endif 3957 #ifdef FEAT_PRINTER 3958 (void)parse_printoptions(); /* parse 'printoptions' default value */ 3959 #endif 3960 } 3961 3962 /* 3963 * Return "dark" or "light" depending on the kind of terminal. 3964 * This is just guessing! Recognized are: 3965 * "linux" Linux console 3966 * "screen.linux" Linux console with screen 3967 * "cygwin.*" Cygwin shell 3968 * "putty.*" Putty program 3969 * We also check the COLORFGBG environment variable, which is set by 3970 * rxvt and derivatives. This variable contains either two or three 3971 * values separated by semicolons; we want the last value in either 3972 * case. If this value is 0-6 or 8, our background is dark. 3973 */ 3974 static char_u * 3975 term_bg_default(void) 3976 { 3977 #if defined(WIN3264) 3978 /* DOS console is nearly always black */ 3979 return (char_u *)"dark"; 3980 #else 3981 char_u *p; 3982 3983 if (STRCMP(T_NAME, "linux") == 0 3984 || STRCMP(T_NAME, "screen.linux") == 0 3985 || STRNCMP(T_NAME, "cygwin", 6) == 0 3986 || STRNCMP(T_NAME, "putty", 5) == 0 3987 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL 3988 && (p = vim_strrchr(p, ';')) != NULL 3989 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8') 3990 && p[2] == NUL)) 3991 return (char_u *)"dark"; 3992 return (char_u *)"light"; 3993 #endif 3994 } 3995 3996 /* 3997 * Initialize the options, part three: After reading the .vimrc 3998 */ 3999 void 4000 set_init_3(void) 4001 { 4002 #if defined(UNIX) || defined(WIN3264) 4003 /* 4004 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option. 4005 * This is done after other initializations, where 'shell' might have been 4006 * set, but only if they have not been set before. 4007 */ 4008 char_u *p; 4009 int idx_srr; 4010 int do_srr; 4011 # ifdef FEAT_QUICKFIX 4012 int idx_sp; 4013 int do_sp; 4014 # endif 4015 4016 idx_srr = findoption((char_u *)"srr"); 4017 if (idx_srr < 0) 4018 do_srr = FALSE; 4019 else 4020 do_srr = !(options[idx_srr].flags & P_WAS_SET); 4021 # ifdef FEAT_QUICKFIX 4022 idx_sp = findoption((char_u *)"sp"); 4023 if (idx_sp < 0) 4024 do_sp = FALSE; 4025 else 4026 do_sp = !(options[idx_sp].flags & P_WAS_SET); 4027 # endif 4028 p = get_isolated_shell_name(); 4029 if (p != NULL) 4030 { 4031 /* 4032 * Default for p_sp is "| tee", for p_srr is ">". 4033 * For known shells it is changed here to include stderr. 4034 */ 4035 if ( fnamecmp(p, "csh") == 0 4036 || fnamecmp(p, "tcsh") == 0 4037 # if defined(WIN3264) /* also check with .exe extension */ 4038 || fnamecmp(p, "csh.exe") == 0 4039 || fnamecmp(p, "tcsh.exe") == 0 4040 # endif 4041 ) 4042 { 4043 # if defined(FEAT_QUICKFIX) 4044 if (do_sp) 4045 { 4046 # ifdef WIN3264 4047 p_sp = (char_u *)">&"; 4048 # else 4049 p_sp = (char_u *)"|& tee"; 4050 # endif 4051 options[idx_sp].def_val[VI_DEFAULT] = p_sp; 4052 } 4053 # endif 4054 if (do_srr) 4055 { 4056 p_srr = (char_u *)">&"; 4057 options[idx_srr].def_val[VI_DEFAULT] = p_srr; 4058 } 4059 } 4060 else 4061 /* Always use bourne shell style redirection if we reach this */ 4062 if ( fnamecmp(p, "sh") == 0 4063 || fnamecmp(p, "ksh") == 0 4064 || fnamecmp(p, "mksh") == 0 4065 || fnamecmp(p, "pdksh") == 0 4066 || fnamecmp(p, "zsh") == 0 4067 || fnamecmp(p, "zsh-beta") == 0 4068 || fnamecmp(p, "bash") == 0 4069 || fnamecmp(p, "fish") == 0 4070 # ifdef WIN3264 4071 || fnamecmp(p, "cmd") == 0 4072 || fnamecmp(p, "sh.exe") == 0 4073 || fnamecmp(p, "ksh.exe") == 0 4074 || fnamecmp(p, "mksh.exe") == 0 4075 || fnamecmp(p, "pdksh.exe") == 0 4076 || fnamecmp(p, "zsh.exe") == 0 4077 || fnamecmp(p, "zsh-beta.exe") == 0 4078 || fnamecmp(p, "bash.exe") == 0 4079 || fnamecmp(p, "cmd.exe") == 0 4080 # endif 4081 ) 4082 { 4083 # if defined(FEAT_QUICKFIX) 4084 if (do_sp) 4085 { 4086 # ifdef WIN3264 4087 p_sp = (char_u *)">%s 2>&1"; 4088 # else 4089 p_sp = (char_u *)"2>&1| tee"; 4090 # endif 4091 options[idx_sp].def_val[VI_DEFAULT] = p_sp; 4092 } 4093 # endif 4094 if (do_srr) 4095 { 4096 p_srr = (char_u *)">%s 2>&1"; 4097 options[idx_srr].def_val[VI_DEFAULT] = p_srr; 4098 } 4099 } 4100 vim_free(p); 4101 } 4102 #endif 4103 4104 #if defined(WIN3264) 4105 /* 4106 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the 4107 * 'shell' option. 4108 * This is done after other initializations, where 'shell' might have been 4109 * set, but only if they have not been set before. Default for p_shcf is 4110 * "/c", for p_shq is "". For "sh" like shells it is changed here to 4111 * "-c" and "\"". And for Win32 we need to set p_sxq instead. 4112 */ 4113 if (strstr((char *)gettail(p_sh), "sh") != NULL) 4114 { 4115 int idx3; 4116 4117 idx3 = findoption((char_u *)"shcf"); 4118 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) 4119 { 4120 p_shcf = (char_u *)"-c"; 4121 options[idx3].def_val[VI_DEFAULT] = p_shcf; 4122 } 4123 4124 /* Somehow Win32 requires the quotes around the redirection too */ 4125 idx3 = findoption((char_u *)"sxq"); 4126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) 4127 { 4128 p_sxq = (char_u *)"\""; 4129 options[idx3].def_val[VI_DEFAULT] = p_sxq; 4130 } 4131 } 4132 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL) 4133 { 4134 int idx3; 4135 4136 /* 4137 * cmd.exe on Windows will strip the first and last double quote given 4138 * on the command line, e.g. most of the time things like: 4139 * cmd /c "my path/to/echo" "my args to echo" 4140 * become: 4141 * my path/to/echo" "my args to echo 4142 * when executed. 4143 * 4144 * To avoid this, set shellxquote to surround the command in 4145 * parenthesis. This appears to make most commands work, without 4146 * breaking commands that worked previously, such as 4147 * '"path with spaces/cmd" "a&b"'. 4148 */ 4149 idx3 = findoption((char_u *)"sxq"); 4150 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) 4151 { 4152 p_sxq = (char_u *)"("; 4153 options[idx3].def_val[VI_DEFAULT] = p_sxq; 4154 } 4155 4156 idx3 = findoption((char_u *)"shcf"); 4157 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET)) 4158 { 4159 p_shcf = (char_u *)"/c"; 4160 options[idx3].def_val[VI_DEFAULT] = p_shcf; 4161 } 4162 } 4163 #endif 4164 4165 if (BUFEMPTY()) 4166 { 4167 int idx_ffs = findoption((char_u *)"ffs"); 4168 4169 /* Apply the first entry of 'fileformats' to the initial buffer. */ 4170 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET)) 4171 set_fileformat(default_fileformat(), OPT_LOCAL); 4172 } 4173 4174 #ifdef FEAT_TITLE 4175 set_title_defaults(); 4176 #endif 4177 } 4178 4179 #if defined(FEAT_MULTI_LANG) || defined(PROTO) 4180 /* 4181 * When 'helplang' is still at its default value, set it to "lang". 4182 * Only the first two characters of "lang" are used. 4183 */ 4184 void 4185 set_helplang_default(char_u *lang) 4186 { 4187 int idx; 4188 4189 if (lang == NULL || STRLEN(lang) < 2) /* safety check */ 4190 return; 4191 idx = findoption((char_u *)"hlg"); 4192 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) 4193 { 4194 if (options[idx].flags & P_ALLOCED) 4195 free_string_option(p_hlg); 4196 p_hlg = vim_strsave(lang); 4197 if (p_hlg == NULL) 4198 p_hlg = empty_option; 4199 else 4200 { 4201 // zh_CN becomes "cn", zh_TW becomes "tw" 4202 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) 4203 { 4204 p_hlg[0] = TOLOWER_ASC(p_hlg[3]); 4205 p_hlg[1] = TOLOWER_ASC(p_hlg[4]); 4206 } 4207 // any C like setting, such as C.UTF-8, becomes "en" 4208 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C') 4209 { 4210 p_hlg[0] = 'e'; 4211 p_hlg[1] = 'n'; 4212 } 4213 p_hlg[2] = NUL; 4214 } 4215 options[idx].flags |= P_ALLOCED; 4216 } 4217 } 4218 #endif 4219 4220 #ifdef FEAT_GUI 4221 static char_u * 4222 gui_bg_default(void) 4223 { 4224 if (gui_get_lightness(gui.back_pixel) < 127) 4225 return (char_u *)"dark"; 4226 return (char_u *)"light"; 4227 } 4228 4229 /* 4230 * Option initializations that can only be done after opening the GUI window. 4231 */ 4232 void 4233 init_gui_options(void) 4234 { 4235 /* Set the 'background' option according to the lightness of the 4236 * background color, unless the user has set it already. */ 4237 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0) 4238 { 4239 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0); 4240 highlight_changed(); 4241 } 4242 } 4243 #endif 4244 4245 #ifdef FEAT_TITLE 4246 /* 4247 * 'title' and 'icon' only default to true if they have not been set or reset 4248 * in .vimrc and we can read the old value. 4249 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if 4250 * they can be reset. This reduces startup time when using X on a remote 4251 * machine. 4252 */ 4253 void 4254 set_title_defaults(void) 4255 { 4256 int idx1; 4257 long val; 4258 4259 /* 4260 * If GUI is (going to be) used, we can always set the window title and 4261 * icon name. Saves a bit of time, because the X11 display server does 4262 * not need to be contacted. 4263 */ 4264 idx1 = findoption((char_u *)"title"); 4265 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) 4266 { 4267 #ifdef FEAT_GUI 4268 if (gui.starting || gui.in_use) 4269 val = TRUE; 4270 else 4271 #endif 4272 val = mch_can_restore_title(); 4273 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; 4274 p_title = val; 4275 } 4276 idx1 = findoption((char_u *)"icon"); 4277 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) 4278 { 4279 #ifdef FEAT_GUI 4280 if (gui.starting || gui.in_use) 4281 val = TRUE; 4282 else 4283 #endif 4284 val = mch_can_restore_icon(); 4285 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val; 4286 p_icon = val; 4287 } 4288 } 4289 #endif 4290 4291 #if defined(FEAT_EVAL) 4292 static void 4293 trigger_optionsset_string( 4294 int opt_idx, 4295 int opt_flags, 4296 char_u *oldval, 4297 char_u *newval) 4298 { 4299 // Don't do this recursively. 4300 if (oldval != NULL && newval != NULL 4301 && *get_vim_var_str(VV_OPTION_TYPE) == NUL) 4302 { 4303 char_u buf_type[7]; 4304 4305 sprintf((char *)buf_type, "%s", 4306 (opt_flags & OPT_LOCAL) ? "local" : "global"); 4307 set_vim_var_string(VV_OPTION_OLD, oldval, -1); 4308 set_vim_var_string(VV_OPTION_NEW, newval, -1); 4309 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); 4310 apply_autocmds(EVENT_OPTIONSET, 4311 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL); 4312 reset_v_option_vars(); 4313 } 4314 } 4315 #endif 4316 4317 /* 4318 * Parse 'arg' for option settings. 4319 * 4320 * 'arg' may be IObuff, but only when no errors can be present and option 4321 * does not need to be expanded with option_expand(). 4322 * "opt_flags": 4323 * 0 for ":set" 4324 * OPT_GLOBAL for ":setglobal" 4325 * OPT_LOCAL for ":setlocal" and a modeline 4326 * OPT_MODELINE for a modeline 4327 * OPT_WINONLY to only set window-local options 4328 * OPT_NOWIN to skip setting window-local options 4329 * 4330 * returns FAIL if an error is detected, OK otherwise 4331 */ 4332 int 4333 do_set( 4334 char_u *arg, /* option string (may be written to!) */ 4335 int opt_flags) 4336 { 4337 int opt_idx; 4338 char *errmsg; 4339 char errbuf[80]; 4340 char_u *startarg; 4341 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */ 4342 int nextchar; /* next non-white char after option name */ 4343 int afterchar; /* character just after option name */ 4344 int len; 4345 int i; 4346 varnumber_T value; 4347 int key; 4348 long_u flags; /* flags for current option */ 4349 char_u *varp = NULL; /* pointer to variable for current option */ 4350 int did_show = FALSE; /* already showed one value */ 4351 int adding; /* "opt+=arg" */ 4352 int prepending; /* "opt^=arg" */ 4353 int removing; /* "opt-=arg" */ 4354 int cp_val = 0; 4355 char_u key_name[2]; 4356 4357 if (*arg == NUL) 4358 { 4359 showoptions(0, opt_flags); 4360 did_show = TRUE; 4361 goto theend; 4362 } 4363 4364 while (*arg != NUL) /* loop to process all options */ 4365 { 4366 errmsg = NULL; 4367 startarg = arg; /* remember for error message */ 4368 4369 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) 4370 && !(opt_flags & OPT_MODELINE)) 4371 { 4372 /* 4373 * ":set all" show all options. 4374 * ":set all&" set all options to their default value. 4375 */ 4376 arg += 3; 4377 if (*arg == '&') 4378 { 4379 ++arg; 4380 /* Only for :set command set global value of local options. */ 4381 set_options_default(OPT_FREE | opt_flags); 4382 didset_options(); 4383 didset_options2(); 4384 redraw_all_later(CLEAR); 4385 } 4386 else 4387 { 4388 showoptions(1, opt_flags); 4389 did_show = TRUE; 4390 } 4391 } 4392 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE)) 4393 { 4394 showoptions(2, opt_flags); 4395 show_termcodes(); 4396 did_show = TRUE; 4397 arg += 7; 4398 } 4399 else 4400 { 4401 prefix = 1; 4402 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0) 4403 { 4404 prefix = 0; 4405 arg += 2; 4406 } 4407 else if (STRNCMP(arg, "inv", 3) == 0) 4408 { 4409 prefix = 2; 4410 arg += 3; 4411 } 4412 4413 /* find end of name */ 4414 key = 0; 4415 if (*arg == '<') 4416 { 4417 nextchar = 0; 4418 opt_idx = -1; 4419 /* look out for <t_>;> */ 4420 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4]) 4421 len = 5; 4422 else 4423 { 4424 len = 1; 4425 while (arg[len] != NUL && arg[len] != '>') 4426 ++len; 4427 } 4428 if (arg[len] != '>') 4429 { 4430 errmsg = e_invarg; 4431 goto skip; 4432 } 4433 arg[len] = NUL; /* put NUL after name */ 4434 if (arg[1] == 't' && arg[2] == '_') /* could be term code */ 4435 opt_idx = findoption(arg + 1); 4436 arg[len++] = '>'; /* restore '>' */ 4437 if (opt_idx == -1) 4438 key = find_key_option(arg + 1, TRUE); 4439 } 4440 else 4441 { 4442 len = 0; 4443 /* 4444 * The two characters after "t_" may not be alphanumeric. 4445 */ 4446 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) 4447 len = 4; 4448 else 4449 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') 4450 ++len; 4451 nextchar = arg[len]; 4452 arg[len] = NUL; /* put NUL after name */ 4453 opt_idx = findoption(arg); 4454 arg[len] = nextchar; /* restore nextchar */ 4455 if (opt_idx == -1) 4456 key = find_key_option(arg, FALSE); 4457 } 4458 4459 /* remember character after option name */ 4460 afterchar = arg[len]; 4461 4462 /* skip white space, allow ":set ai ?" */ 4463 while (VIM_ISWHITE(arg[len])) 4464 ++len; 4465 4466 adding = FALSE; 4467 prepending = FALSE; 4468 removing = FALSE; 4469 if (arg[len] != NUL && arg[len + 1] == '=') 4470 { 4471 if (arg[len] == '+') 4472 { 4473 adding = TRUE; /* "+=" */ 4474 ++len; 4475 } 4476 else if (arg[len] == '^') 4477 { 4478 prepending = TRUE; /* "^=" */ 4479 ++len; 4480 } 4481 else if (arg[len] == '-') 4482 { 4483 removing = TRUE; /* "-=" */ 4484 ++len; 4485 } 4486 } 4487 nextchar = arg[len]; 4488 4489 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */ 4490 { 4491 errmsg = N_("E518: Unknown option"); 4492 goto skip; 4493 } 4494 4495 if (opt_idx >= 0) 4496 { 4497 if (options[opt_idx].var == NULL) /* hidden option: skip */ 4498 { 4499 /* Only give an error message when requesting the value of 4500 * a hidden option, ignore setting it. */ 4501 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL 4502 && (!(options[opt_idx].flags & P_BOOL) 4503 || nextchar == '?')) 4504 errmsg = N_("E519: Option not supported"); 4505 goto skip; 4506 } 4507 4508 flags = options[opt_idx].flags; 4509 varp = get_varp_scope(&(options[opt_idx]), opt_flags); 4510 } 4511 else 4512 { 4513 flags = P_STRING; 4514 if (key < 0) 4515 { 4516 key_name[0] = KEY2TERMCAP0(key); 4517 key_name[1] = KEY2TERMCAP1(key); 4518 } 4519 else 4520 { 4521 key_name[0] = KS_KEY; 4522 key_name[1] = (key & 0xff); 4523 } 4524 } 4525 4526 /* Skip all options that are not window-local (used when showing 4527 * an already loaded buffer in a window). */ 4528 if ((opt_flags & OPT_WINONLY) 4529 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) 4530 goto skip; 4531 4532 /* Skip all options that are window-local (used for :vimgrep). */ 4533 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 4534 && options[opt_idx].var == VAR_WIN) 4535 goto skip; 4536 4537 /* Disallow changing some options from modelines. */ 4538 if (opt_flags & OPT_MODELINE) 4539 { 4540 if (flags & (P_SECURE | P_NO_ML)) 4541 { 4542 errmsg = _("E520: Not allowed in a modeline"); 4543 goto skip; 4544 } 4545 #ifdef FEAT_DIFF 4546 /* In diff mode some options are overruled. This avoids that 4547 * 'foldmethod' becomes "marker" instead of "diff" and that 4548 * "wrap" gets set. */ 4549 if (curwin->w_p_diff 4550 && opt_idx >= 0 /* shut up coverity warning */ 4551 && ( 4552 #ifdef FEAT_FOLDING 4553 options[opt_idx].indir == PV_FDM || 4554 #endif 4555 options[opt_idx].indir == PV_WRAP)) 4556 goto skip; 4557 #endif 4558 } 4559 4560 #ifdef HAVE_SANDBOX 4561 /* Disallow changing some options in the sandbox */ 4562 if (sandbox != 0 && (flags & P_SECURE)) 4563 { 4564 errmsg = _(e_sandbox); 4565 goto skip; 4566 } 4567 #endif 4568 4569 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL) 4570 { 4571 arg += len; 4572 cp_val = p_cp; 4573 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') 4574 { 4575 if (arg[3] == 'm') /* "opt&vim": set to Vim default */ 4576 { 4577 cp_val = FALSE; 4578 arg += 3; 4579 } 4580 else /* "opt&vi": set to Vi default */ 4581 { 4582 cp_val = TRUE; 4583 arg += 2; 4584 } 4585 } 4586 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL 4587 && arg[1] != NUL && !VIM_ISWHITE(arg[1])) 4588 { 4589 errmsg = e_trailing; 4590 goto skip; 4591 } 4592 } 4593 4594 /* 4595 * allow '=' and ':' for hystorical reasons (MSDOS command.com 4596 * allows only one '=' character per "set" command line. grrr. (jw) 4597 */ 4598 if (nextchar == '?' 4599 || (prefix == 1 4600 && vim_strchr((char_u *)"=:&<", nextchar) == NULL 4601 && !(flags & P_BOOL))) 4602 { 4603 /* 4604 * print value 4605 */ 4606 if (did_show) 4607 msg_putchar('\n'); /* cursor below last one */ 4608 else 4609 { 4610 gotocmdline(TRUE); /* cursor at status line */ 4611 did_show = TRUE; /* remember that we did a line */ 4612 } 4613 if (opt_idx >= 0) 4614 { 4615 showoneopt(&options[opt_idx], opt_flags); 4616 #ifdef FEAT_EVAL 4617 if (p_verbose > 0) 4618 { 4619 /* Mention where the option was last set. */ 4620 if (varp == options[opt_idx].var) 4621 last_set_msg(options[opt_idx].script_ctx); 4622 else if ((int)options[opt_idx].indir & PV_WIN) 4623 last_set_msg(curwin->w_p_script_ctx[ 4624 (int)options[opt_idx].indir & PV_MASK]); 4625 else if ((int)options[opt_idx].indir & PV_BUF) 4626 last_set_msg(curbuf->b_p_script_ctx[ 4627 (int)options[opt_idx].indir & PV_MASK]); 4628 } 4629 #endif 4630 } 4631 else 4632 { 4633 char_u *p; 4634 4635 p = find_termcode(key_name); 4636 if (p == NULL) 4637 { 4638 errmsg = N_("E846: Key code not set"); 4639 goto skip; 4640 } 4641 else 4642 (void)show_one_termcode(key_name, p, TRUE); 4643 } 4644 if (nextchar != '?' 4645 && nextchar != NUL && !VIM_ISWHITE(afterchar)) 4646 errmsg = e_trailing; 4647 } 4648 else 4649 { 4650 int value_is_replaced = !prepending && !adding && !removing; 4651 int value_checked = FALSE; 4652 4653 if (flags & P_BOOL) /* boolean */ 4654 { 4655 if (nextchar == '=' || nextchar == ':') 4656 { 4657 errmsg = e_invarg; 4658 goto skip; 4659 } 4660 4661 /* 4662 * ":set opt!": invert 4663 * ":set opt&": reset to default value 4664 * ":set opt<": reset to global value 4665 */ 4666 if (nextchar == '!') 4667 value = *(int *)(varp) ^ 1; 4668 else if (nextchar == '&') 4669 value = (int)(long)(long_i)options[opt_idx].def_val[ 4670 ((flags & P_VI_DEF) || cp_val) 4671 ? VI_DEFAULT : VIM_DEFAULT]; 4672 else if (nextchar == '<') 4673 { 4674 /* For 'autoread' -1 means to use global value. */ 4675 if ((int *)varp == &curbuf->b_p_ar 4676 && opt_flags == OPT_LOCAL) 4677 value = -1; 4678 else 4679 value = *(int *)get_varp_scope(&(options[opt_idx]), 4680 OPT_GLOBAL); 4681 } 4682 else 4683 { 4684 /* 4685 * ":set invopt": invert 4686 * ":set opt" or ":set noopt": set or reset 4687 */ 4688 if (nextchar != NUL && !VIM_ISWHITE(afterchar)) 4689 { 4690 errmsg = e_trailing; 4691 goto skip; 4692 } 4693 if (prefix == 2) /* inv */ 4694 value = *(int *)(varp) ^ 1; 4695 else 4696 value = prefix; 4697 } 4698 4699 errmsg = set_bool_option(opt_idx, varp, (int)value, 4700 opt_flags); 4701 } 4702 else /* numeric or string */ 4703 { 4704 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL 4705 || prefix != 1) 4706 { 4707 errmsg = e_invarg; 4708 goto skip; 4709 } 4710 4711 if (flags & P_NUM) /* numeric */ 4712 { 4713 /* 4714 * Different ways to set a number option: 4715 * & set to default value 4716 * < set to global value 4717 * <xx> accept special key codes for 'wildchar' 4718 * c accept any non-digit for 'wildchar' 4719 * [-]0-9 set number 4720 * other error 4721 */ 4722 ++arg; 4723 if (nextchar == '&') 4724 value = (long)(long_i)options[opt_idx].def_val[ 4725 ((flags & P_VI_DEF) || cp_val) 4726 ? VI_DEFAULT : VIM_DEFAULT]; 4727 else if (nextchar == '<') 4728 { 4729 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to 4730 * use the global value. */ 4731 if ((long *)varp == &curbuf->b_p_ul 4732 && opt_flags == OPT_LOCAL) 4733 value = NO_LOCAL_UNDOLEVEL; 4734 else 4735 value = *(long *)get_varp_scope( 4736 &(options[opt_idx]), OPT_GLOBAL); 4737 } 4738 else if (((long *)varp == &p_wc 4739 || (long *)varp == &p_wcm) 4740 && (*arg == '<' 4741 || *arg == '^' 4742 || (*arg != NUL 4743 && (!arg[1] || VIM_ISWHITE(arg[1])) 4744 && !VIM_ISDIGIT(*arg)))) 4745 { 4746 value = string_to_key(arg, FALSE); 4747 if (value == 0 && (long *)varp != &p_wcm) 4748 { 4749 errmsg = e_invarg; 4750 goto skip; 4751 } 4752 } 4753 else if (*arg == '-' || VIM_ISDIGIT(*arg)) 4754 { 4755 /* Allow negative (for 'undolevels'), octal and 4756 * hex numbers. */ 4757 vim_str2nr(arg, NULL, &i, STR2NR_ALL, 4758 &value, NULL, 0); 4759 if (arg[i] != NUL && !VIM_ISWHITE(arg[i])) 4760 { 4761 errmsg = e_invarg; 4762 goto skip; 4763 } 4764 } 4765 else 4766 { 4767 errmsg = N_("E521: Number required after ="); 4768 goto skip; 4769 } 4770 4771 if (adding) 4772 value = *(long *)varp + value; 4773 if (prepending) 4774 value = *(long *)varp * value; 4775 if (removing) 4776 value = *(long *)varp - value; 4777 errmsg = set_num_option(opt_idx, varp, value, 4778 errbuf, sizeof(errbuf), opt_flags); 4779 } 4780 else if (opt_idx >= 0) /* string */ 4781 { 4782 char_u *save_arg = NULL; 4783 char_u *s = NULL; 4784 char_u *oldval = NULL; /* previous value if *varp */ 4785 char_u *newval; 4786 char_u *origval = NULL; 4787 #if defined(FEAT_EVAL) 4788 char_u *saved_origval = NULL; 4789 char_u *saved_newval = NULL; 4790 #endif 4791 unsigned newlen; 4792 int comma; 4793 int bs; 4794 int new_value_alloced; /* new string option 4795 was allocated */ 4796 4797 /* When using ":set opt=val" for a global option 4798 * with a local value the local value will be 4799 * reset, use the global value here. */ 4800 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 4801 && ((int)options[opt_idx].indir & PV_BOTH)) 4802 varp = options[opt_idx].var; 4803 4804 /* The old value is kept until we are sure that the 4805 * new value is valid. */ 4806 oldval = *(char_u **)varp; 4807 4808 /* When setting the local value of a global 4809 * option, the old value may be the global value. */ 4810 if (((int)options[opt_idx].indir & PV_BOTH) 4811 && (opt_flags & OPT_LOCAL)) 4812 origval = *(char_u **)get_varp( 4813 &options[opt_idx]); 4814 else 4815 origval = oldval; 4816 4817 if (nextchar == '&') /* set to default val */ 4818 { 4819 newval = options[opt_idx].def_val[ 4820 ((flags & P_VI_DEF) || cp_val) 4821 ? VI_DEFAULT : VIM_DEFAULT]; 4822 if ((char_u **)varp == &p_bg) 4823 { 4824 /* guess the value of 'background' */ 4825 #ifdef FEAT_GUI 4826 if (gui.in_use) 4827 newval = gui_bg_default(); 4828 else 4829 #endif 4830 newval = term_bg_default(); 4831 } 4832 4833 /* expand environment variables and ~ (since the 4834 * default value was already expanded, only 4835 * required when an environment variable was set 4836 * later */ 4837 if (newval == NULL) 4838 newval = empty_option; 4839 else 4840 { 4841 s = option_expand(opt_idx, newval); 4842 if (s == NULL) 4843 s = newval; 4844 newval = vim_strsave(s); 4845 } 4846 new_value_alloced = TRUE; 4847 } 4848 else if (nextchar == '<') /* set to global val */ 4849 { 4850 newval = vim_strsave(*(char_u **)get_varp_scope( 4851 &(options[opt_idx]), OPT_GLOBAL)); 4852 new_value_alloced = TRUE; 4853 } 4854 else 4855 { 4856 ++arg; /* jump to after the '=' or ':' */ 4857 4858 /* 4859 * Set 'keywordprg' to ":help" if an empty 4860 * value was passed to :set by the user. 4861 * Misuse errbuf[] for the resulting string. 4862 */ 4863 if (varp == (char_u *)&p_kp 4864 && (*arg == NUL || *arg == ' ')) 4865 { 4866 STRCPY(errbuf, ":help"); 4867 save_arg = arg; 4868 arg = (char_u *)errbuf; 4869 } 4870 /* 4871 * Convert 'backspace' number to string, for 4872 * adding, prepending and removing string. 4873 */ 4874 else if (varp == (char_u *)&p_bs 4875 && VIM_ISDIGIT(**(char_u **)varp)) 4876 { 4877 i = getdigits((char_u **)varp); 4878 switch (i) 4879 { 4880 case 0: 4881 *(char_u **)varp = empty_option; 4882 break; 4883 case 1: 4884 *(char_u **)varp = vim_strsave( 4885 (char_u *)"indent,eol"); 4886 break; 4887 case 2: 4888 *(char_u **)varp = vim_strsave( 4889 (char_u *)"indent,eol,start"); 4890 break; 4891 } 4892 vim_free(oldval); 4893 if (origval == oldval) 4894 origval = *(char_u **)varp; 4895 oldval = *(char_u **)varp; 4896 } 4897 /* 4898 * Convert 'whichwrap' number to string, for 4899 * backwards compatibility with Vim 3.0. 4900 * Misuse errbuf[] for the resulting string. 4901 */ 4902 else if (varp == (char_u *)&p_ww 4903 && VIM_ISDIGIT(*arg)) 4904 { 4905 *errbuf = NUL; 4906 i = getdigits(&arg); 4907 if (i & 1) 4908 STRCAT(errbuf, "b,"); 4909 if (i & 2) 4910 STRCAT(errbuf, "s,"); 4911 if (i & 4) 4912 STRCAT(errbuf, "h,l,"); 4913 if (i & 8) 4914 STRCAT(errbuf, "<,>,"); 4915 if (i & 16) 4916 STRCAT(errbuf, "[,],"); 4917 if (*errbuf != NUL) /* remove trailing , */ 4918 errbuf[STRLEN(errbuf) - 1] = NUL; 4919 save_arg = arg; 4920 arg = (char_u *)errbuf; 4921 } 4922 /* 4923 * Remove '>' before 'dir' and 'bdir', for 4924 * backwards compatibility with version 3.0 4925 */ 4926 else if ( *arg == '>' 4927 && (varp == (char_u *)&p_dir 4928 || varp == (char_u *)&p_bdir)) 4929 { 4930 ++arg; 4931 } 4932 4933 /* 4934 * Copy the new string into allocated memory. 4935 * Can't use set_string_option_direct(), because 4936 * we need to remove the backslashes. 4937 */ 4938 /* get a bit too much */ 4939 newlen = (unsigned)STRLEN(arg) + 1; 4940 if (adding || prepending || removing) 4941 newlen += (unsigned)STRLEN(origval) + 1; 4942 newval = alloc(newlen); 4943 if (newval == NULL) /* out of mem, don't change */ 4944 break; 4945 s = newval; 4946 4947 /* 4948 * Copy the string, skip over escaped chars. 4949 * For MS-DOS and WIN32 backslashes before normal 4950 * file name characters are not removed, and keep 4951 * backslash at start, for "\\machine\path", but 4952 * do remove it for "\\\\machine\\path". 4953 * The reverse is found in ExpandOldSetting(). 4954 */ 4955 while (*arg && !VIM_ISWHITE(*arg)) 4956 { 4957 if (*arg == '\\' && arg[1] != NUL 4958 #ifdef BACKSLASH_IN_FILENAME 4959 && !((flags & P_EXPAND) 4960 && vim_isfilec(arg[1]) 4961 && (arg[1] != '\\' 4962 || (s == newval 4963 && arg[2] != '\\'))) 4964 #endif 4965 ) 4966 ++arg; /* remove backslash */ 4967 if (has_mbyte 4968 && (i = (*mb_ptr2len)(arg)) > 1) 4969 { 4970 /* copy multibyte char */ 4971 mch_memmove(s, arg, (size_t)i); 4972 arg += i; 4973 s += i; 4974 } 4975 else 4976 *s++ = *arg++; 4977 } 4978 *s = NUL; 4979 4980 /* 4981 * Expand environment variables and ~. 4982 * Don't do it when adding without inserting a 4983 * comma. 4984 */ 4985 if (!(adding || prepending || removing) 4986 || (flags & P_COMMA)) 4987 { 4988 s = option_expand(opt_idx, newval); 4989 if (s != NULL) 4990 { 4991 vim_free(newval); 4992 newlen = (unsigned)STRLEN(s) + 1; 4993 if (adding || prepending || removing) 4994 newlen += (unsigned)STRLEN(origval) + 1; 4995 newval = alloc(newlen); 4996 if (newval == NULL) 4997 break; 4998 STRCPY(newval, s); 4999 } 5000 } 5001 5002 /* locate newval[] in origval[] when removing it 5003 * and when adding to avoid duplicates */ 5004 i = 0; /* init for GCC */ 5005 if (removing || (flags & P_NODUP)) 5006 { 5007 i = (int)STRLEN(newval); 5008 bs = 0; 5009 for (s = origval; *s; ++s) 5010 { 5011 if ((!(flags & P_COMMA) 5012 || s == origval 5013 || (s[-1] == ',' && !(bs & 1))) 5014 && STRNCMP(s, newval, i) == 0 5015 && (!(flags & P_COMMA) 5016 || s[i] == ',' 5017 || s[i] == NUL)) 5018 break; 5019 /* Count backslashes. Only a comma with an 5020 * even number of backslashes or a single 5021 * backslash preceded by a comma before it 5022 * is recognized as a separator */ 5023 if ((s > origval + 1 5024 && s[-1] == '\\' 5025 && s[-2] != ',') 5026 || (s == origval + 1 5027 && s[-1] == '\\')) 5028 5029 ++bs; 5030 else 5031 bs = 0; 5032 } 5033 5034 /* do not add if already there */ 5035 if ((adding || prepending) && *s) 5036 { 5037 prepending = FALSE; 5038 adding = FALSE; 5039 STRCPY(newval, origval); 5040 } 5041 } 5042 5043 /* concatenate the two strings; add a ',' if 5044 * needed */ 5045 if (adding || prepending) 5046 { 5047 comma = ((flags & P_COMMA) && *origval != NUL 5048 && *newval != NUL); 5049 if (adding) 5050 { 5051 i = (int)STRLEN(origval); 5052 /* strip a trailing comma, would get 2 */ 5053 if (comma && i > 1 5054 && (flags & P_ONECOMMA) == P_ONECOMMA 5055 && origval[i - 1] == ',' 5056 && origval[i - 2] != '\\') 5057 i--; 5058 mch_memmove(newval + i + comma, newval, 5059 STRLEN(newval) + 1); 5060 mch_memmove(newval, origval, (size_t)i); 5061 } 5062 else 5063 { 5064 i = (int)STRLEN(newval); 5065 STRMOVE(newval + i + comma, origval); 5066 } 5067 if (comma) 5068 newval[i] = ','; 5069 } 5070 5071 /* Remove newval[] from origval[]. (Note: "i" has 5072 * been set above and is used here). */ 5073 if (removing) 5074 { 5075 STRCPY(newval, origval); 5076 if (*s) 5077 { 5078 /* may need to remove a comma */ 5079 if (flags & P_COMMA) 5080 { 5081 if (s == origval) 5082 { 5083 /* include comma after string */ 5084 if (s[i] == ',') 5085 ++i; 5086 } 5087 else 5088 { 5089 /* include comma before string */ 5090 --s; 5091 ++i; 5092 } 5093 } 5094 STRMOVE(newval + (s - origval), s + i); 5095 } 5096 } 5097 5098 if (flags & P_FLAGLIST) 5099 { 5100 /* Remove flags that appear twice. */ 5101 for (s = newval; *s;) 5102 { 5103 /* if options have P_FLAGLIST and 5104 * P_ONECOMMA such as 'whichwrap' */ 5105 if (flags & P_ONECOMMA) 5106 { 5107 if (*s != ',' && *(s + 1) == ',' 5108 && vim_strchr(s + 2, *s) != NULL) 5109 { 5110 /* Remove the duplicated value and 5111 * the next comma. */ 5112 STRMOVE(s, s + 2); 5113 continue; 5114 } 5115 } 5116 else 5117 { 5118 if ((!(flags & P_COMMA) || *s != ',') 5119 && vim_strchr(s + 1, *s) != NULL) 5120 { 5121 STRMOVE(s, s + 1); 5122 continue; 5123 } 5124 } 5125 ++s; 5126 } 5127 } 5128 5129 if (save_arg != NULL) /* number for 'whichwrap' */ 5130 arg = save_arg; 5131 new_value_alloced = TRUE; 5132 } 5133 5134 /* 5135 * Set the new value. 5136 */ 5137 *(char_u **)(varp) = newval; 5138 5139 #if defined(FEAT_EVAL) 5140 if (!starting 5141 # ifdef FEAT_CRYPT 5142 && options[opt_idx].indir != PV_KEY 5143 # endif 5144 && origval != NULL && newval != NULL) 5145 { 5146 /* origval may be freed by 5147 * did_set_string_option(), make a copy. */ 5148 saved_origval = vim_strsave(origval); 5149 /* newval (and varp) may become invalid if the 5150 * buffer is closed by autocommands. */ 5151 saved_newval = vim_strsave(newval); 5152 } 5153 #endif 5154 5155 { 5156 long_u *p = insecure_flag(opt_idx, opt_flags); 5157 int secure_saved = secure; 5158 5159 // When an option is set in the sandbox, from a 5160 // modeline or in secure mode, then deal with side 5161 // effects in secure mode. Also when the value was 5162 // set with the P_INSECURE flag and is not 5163 // completely replaced. 5164 if (secure 5165 #ifdef HAVE_SANDBOX 5166 || sandbox != 0 5167 #endif 5168 || (opt_flags & OPT_MODELINE) 5169 || (!value_is_replaced && (*p & P_INSECURE))) 5170 ++secure; 5171 5172 // Handle side effects, and set the global value 5173 // for ":set" on local options. Note: when setting 5174 // 'syntax' or 'filetype' autocommands may be 5175 // triggered that can cause havoc. 5176 errmsg = did_set_string_option( 5177 opt_idx, (char_u **)varp, 5178 new_value_alloced, oldval, errbuf, 5179 opt_flags, &value_checked); 5180 5181 secure = secure_saved; 5182 } 5183 5184 #if defined(FEAT_EVAL) 5185 if (errmsg == NULL) 5186 trigger_optionsset_string(opt_idx, opt_flags, 5187 saved_origval, saved_newval); 5188 vim_free(saved_origval); 5189 vim_free(saved_newval); 5190 #endif 5191 /* If error detected, print the error message. */ 5192 if (errmsg != NULL) 5193 goto skip; 5194 } 5195 else /* key code option */ 5196 { 5197 char_u *p; 5198 5199 if (nextchar == '&') 5200 { 5201 if (add_termcap_entry(key_name, TRUE) == FAIL) 5202 errmsg = N_("E522: Not found in termcap"); 5203 } 5204 else 5205 { 5206 ++arg; /* jump to after the '=' or ':' */ 5207 for (p = arg; *p && !VIM_ISWHITE(*p); ++p) 5208 if (*p == '\\' && p[1] != NUL) 5209 ++p; 5210 nextchar = *p; 5211 *p = NUL; 5212 add_termcode(key_name, arg, FALSE); 5213 *p = nextchar; 5214 } 5215 if (full_screen) 5216 ttest(FALSE); 5217 redraw_all_later(CLEAR); 5218 } 5219 } 5220 5221 if (opt_idx >= 0) 5222 did_set_option( 5223 opt_idx, opt_flags, value_is_replaced, value_checked); 5224 } 5225 5226 skip: 5227 /* 5228 * Advance to next argument. 5229 * - skip until a blank found, taking care of backslashes 5230 * - skip blanks 5231 * - skip one "=val" argument (for hidden options ":set gfn =xx") 5232 */ 5233 for (i = 0; i < 2 ; ++i) 5234 { 5235 while (*arg != NUL && !VIM_ISWHITE(*arg)) 5236 if (*arg++ == '\\' && *arg != NUL) 5237 ++arg; 5238 arg = skipwhite(arg); 5239 if (*arg != '=') 5240 break; 5241 } 5242 } 5243 5244 if (errmsg != NULL) 5245 { 5246 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1); 5247 i = (int)STRLEN(IObuff) + 2; 5248 if (i + (arg - startarg) < IOSIZE) 5249 { 5250 /* append the argument with the error */ 5251 STRCAT(IObuff, ": "); 5252 mch_memmove(IObuff + i, startarg, (arg - startarg)); 5253 IObuff[i + (arg - startarg)] = NUL; 5254 } 5255 /* make sure all characters are printable */ 5256 trans_characters(IObuff, IOSIZE); 5257 5258 ++no_wait_return; // wait_return done later 5259 emsg((char *)IObuff); // show error highlighted 5260 --no_wait_return; 5261 5262 return FAIL; 5263 } 5264 5265 arg = skipwhite(arg); 5266 } 5267 5268 theend: 5269 if (silent_mode && did_show) 5270 { 5271 /* After displaying option values in silent mode. */ 5272 silent_mode = FALSE; 5273 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ 5274 msg_putchar('\n'); 5275 cursor_on(); /* msg_start() switches it off */ 5276 out_flush(); 5277 silent_mode = TRUE; 5278 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */ 5279 } 5280 5281 return OK; 5282 } 5283 5284 /* 5285 * Call this when an option has been given a new value through a user command. 5286 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag. 5287 */ 5288 static void 5289 did_set_option( 5290 int opt_idx, 5291 int opt_flags, // possibly with OPT_MODELINE 5292 int new_value, // value was replaced completely 5293 int value_checked) // value was checked to be safe, no need to set the 5294 // P_INSECURE flag. 5295 { 5296 long_u *p; 5297 5298 options[opt_idx].flags |= P_WAS_SET; 5299 5300 /* When an option is set in the sandbox, from a modeline or in secure mode 5301 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the 5302 * flag. */ 5303 p = insecure_flag(opt_idx, opt_flags); 5304 if (!value_checked && (secure 5305 #ifdef HAVE_SANDBOX 5306 || sandbox != 0 5307 #endif 5308 || (opt_flags & OPT_MODELINE))) 5309 *p = *p | P_INSECURE; 5310 else if (new_value) 5311 *p = *p & ~P_INSECURE; 5312 } 5313 5314 static char * 5315 illegal_char(char *errbuf, int c) 5316 { 5317 if (errbuf == NULL) 5318 return ""; 5319 sprintf((char *)errbuf, _("E539: Illegal character <%s>"), 5320 (char *)transchar(c)); 5321 return errbuf; 5322 } 5323 5324 /* 5325 * Convert a key name or string into a key value. 5326 * Used for 'wildchar' and 'cedit' options. 5327 * When "multi_byte" is TRUE allow for multi-byte characters. 5328 */ 5329 int 5330 string_to_key(char_u *arg, int multi_byte) 5331 { 5332 if (*arg == '<') 5333 return find_key_option(arg + 1, TRUE); 5334 if (*arg == '^') 5335 return Ctrl_chr(arg[1]); 5336 if (multi_byte) 5337 return PTR2CHAR(arg); 5338 return *arg; 5339 } 5340 5341 #ifdef FEAT_CMDWIN 5342 /* 5343 * Check value of 'cedit' and set cedit_key. 5344 * Returns NULL if value is OK, error message otherwise. 5345 */ 5346 static char * 5347 check_cedit(void) 5348 { 5349 int n; 5350 5351 if (*p_cedit == NUL) 5352 cedit_key = -1; 5353 else 5354 { 5355 n = string_to_key(p_cedit, FALSE); 5356 if (vim_isprintc(n)) 5357 return e_invarg; 5358 cedit_key = n; 5359 } 5360 return NULL; 5361 } 5362 #endif 5363 5364 #ifdef FEAT_TITLE 5365 /* 5366 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call 5367 * maketitle() to create and display it. 5368 * When switching the title or icon off, call mch_restore_title() to get 5369 * the old value back. 5370 */ 5371 static void 5372 did_set_title(void) 5373 { 5374 if (starting != NO_SCREEN 5375 #ifdef FEAT_GUI 5376 && !gui.starting 5377 #endif 5378 ) 5379 maketitle(); 5380 } 5381 #endif 5382 5383 /* 5384 * set_options_bin - called when 'bin' changes value. 5385 */ 5386 void 5387 set_options_bin( 5388 int oldval, 5389 int newval, 5390 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ 5391 { 5392 /* 5393 * The option values that are changed when 'bin' changes are 5394 * copied when 'bin is set and restored when 'bin' is reset. 5395 */ 5396 if (newval) 5397 { 5398 if (!oldval) /* switched on */ 5399 { 5400 if (!(opt_flags & OPT_GLOBAL)) 5401 { 5402 curbuf->b_p_tw_nobin = curbuf->b_p_tw; 5403 curbuf->b_p_wm_nobin = curbuf->b_p_wm; 5404 curbuf->b_p_ml_nobin = curbuf->b_p_ml; 5405 curbuf->b_p_et_nobin = curbuf->b_p_et; 5406 } 5407 if (!(opt_flags & OPT_LOCAL)) 5408 { 5409 p_tw_nobin = p_tw; 5410 p_wm_nobin = p_wm; 5411 p_ml_nobin = p_ml; 5412 p_et_nobin = p_et; 5413 } 5414 } 5415 5416 if (!(opt_flags & OPT_GLOBAL)) 5417 { 5418 curbuf->b_p_tw = 0; /* no automatic line wrap */ 5419 curbuf->b_p_wm = 0; /* no automatic line wrap */ 5420 curbuf->b_p_ml = 0; /* no modelines */ 5421 curbuf->b_p_et = 0; /* no expandtab */ 5422 } 5423 if (!(opt_flags & OPT_LOCAL)) 5424 { 5425 p_tw = 0; 5426 p_wm = 0; 5427 p_ml = FALSE; 5428 p_et = FALSE; 5429 p_bin = TRUE; /* needed when called for the "-b" argument */ 5430 } 5431 } 5432 else if (oldval) /* switched off */ 5433 { 5434 if (!(opt_flags & OPT_GLOBAL)) 5435 { 5436 curbuf->b_p_tw = curbuf->b_p_tw_nobin; 5437 curbuf->b_p_wm = curbuf->b_p_wm_nobin; 5438 curbuf->b_p_ml = curbuf->b_p_ml_nobin; 5439 curbuf->b_p_et = curbuf->b_p_et_nobin; 5440 } 5441 if (!(opt_flags & OPT_LOCAL)) 5442 { 5443 p_tw = p_tw_nobin; 5444 p_wm = p_wm_nobin; 5445 p_ml = p_ml_nobin; 5446 p_et = p_et_nobin; 5447 } 5448 } 5449 } 5450 5451 #ifdef FEAT_VIMINFO 5452 /* 5453 * Find the parameter represented by the given character (eg ', :, ", or /), 5454 * and return its associated value in the 'viminfo' string. 5455 * Only works for number parameters, not for 'r' or 'n'. 5456 * If the parameter is not specified in the string or there is no following 5457 * number, return -1. 5458 */ 5459 int 5460 get_viminfo_parameter(int type) 5461 { 5462 char_u *p; 5463 5464 p = find_viminfo_parameter(type); 5465 if (p != NULL && VIM_ISDIGIT(*p)) 5466 return atoi((char *)p); 5467 return -1; 5468 } 5469 5470 /* 5471 * Find the parameter represented by the given character (eg ''', ':', '"', or 5472 * '/') in the 'viminfo' option and return a pointer to the string after it. 5473 * Return NULL if the parameter is not specified in the string. 5474 */ 5475 char_u * 5476 find_viminfo_parameter(int type) 5477 { 5478 char_u *p; 5479 5480 for (p = p_viminfo; *p; ++p) 5481 { 5482 if (*p == type) 5483 return p + 1; 5484 if (*p == 'n') /* 'n' is always the last one */ 5485 break; 5486 p = vim_strchr(p, ','); /* skip until next ',' */ 5487 if (p == NULL) /* hit the end without finding parameter */ 5488 break; 5489 } 5490 return NULL; 5491 } 5492 #endif 5493 5494 /* 5495 * Expand environment variables for some string options. 5496 * These string options cannot be indirect! 5497 * If "val" is NULL expand the current value of the option. 5498 * Return pointer to NameBuff, or NULL when not expanded. 5499 */ 5500 static char_u * 5501 option_expand(int opt_idx, char_u *val) 5502 { 5503 /* if option doesn't need expansion nothing to do */ 5504 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) 5505 return NULL; 5506 5507 /* If val is longer than MAXPATHL no meaningful expansion can be done, 5508 * expand_env() would truncate the string. */ 5509 if (val != NULL && STRLEN(val) > MAXPATHL) 5510 return NULL; 5511 5512 if (val == NULL) 5513 val = *(char_u **)options[opt_idx].var; 5514 5515 /* 5516 * Expanding this with NameBuff, expand_env() must not be passed IObuff. 5517 * Escape spaces when expanding 'tags', they are used to separate file 5518 * names. 5519 * For 'spellsuggest' expand after "file:". 5520 */ 5521 expand_env_esc(val, NameBuff, MAXPATHL, 5522 (char_u **)options[opt_idx].var == &p_tags, FALSE, 5523 #ifdef FEAT_SPELL 5524 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" : 5525 #endif 5526 NULL); 5527 if (STRCMP(NameBuff, val) == 0) /* they are the same */ 5528 return NULL; 5529 5530 return NameBuff; 5531 } 5532 5533 /* 5534 * After setting various option values: recompute variables that depend on 5535 * option values. 5536 */ 5537 static void 5538 didset_options(void) 5539 { 5540 /* initialize the table for 'iskeyword' et.al. */ 5541 (void)init_chartab(); 5542 5543 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE); 5544 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE); 5545 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE); 5546 #ifdef FEAT_SESSION 5547 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE); 5548 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE); 5549 #endif 5550 #ifdef FEAT_FOLDING 5551 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE); 5552 #endif 5553 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE); 5554 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE); 5555 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE); 5556 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) 5557 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE); 5558 #endif 5559 #ifdef FEAT_SPELL 5560 (void)spell_check_msm(); 5561 (void)spell_check_sps(); 5562 (void)compile_cap_prog(curwin->w_s); 5563 (void)did_set_spell_option(TRUE); 5564 #endif 5565 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) 5566 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE); 5567 #endif 5568 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) 5569 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE); 5570 #endif 5571 #ifdef FEAT_CMDWIN 5572 /* set cedit_key */ 5573 (void)check_cedit(); 5574 #endif 5575 #ifdef FEAT_LINEBREAK 5576 briopt_check(curwin); 5577 #endif 5578 #ifdef FEAT_LINEBREAK 5579 /* initialize the table for 'breakat'. */ 5580 fill_breakat_flags(); 5581 #endif 5582 5583 } 5584 5585 /* 5586 * More side effects of setting options. 5587 */ 5588 static void 5589 didset_options2(void) 5590 { 5591 /* Initialize the highlight_attr[] table. */ 5592 (void)highlight_changed(); 5593 5594 /* Parse default for 'wildmode' */ 5595 check_opt_wim(); 5596 5597 (void)set_chars_option(&p_lcs); 5598 /* Parse default for 'fillchars'. */ 5599 (void)set_chars_option(&p_fcs); 5600 5601 #ifdef FEAT_CLIPBOARD 5602 /* Parse default for 'clipboard' */ 5603 (void)check_clipboard_option(); 5604 #endif 5605 #ifdef FEAT_VARTABS 5606 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); 5607 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); 5608 #endif 5609 } 5610 5611 /* 5612 * Check for string options that are NULL (normally only termcap options). 5613 */ 5614 void 5615 check_options(void) 5616 { 5617 int opt_idx; 5618 5619 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) 5620 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) 5621 check_string_option((char_u **)get_varp(&(options[opt_idx]))); 5622 } 5623 5624 /* 5625 * Check string options in a buffer for NULL value. 5626 */ 5627 void 5628 check_buf_options(buf_T *buf) 5629 { 5630 check_string_option(&buf->b_p_bh); 5631 check_string_option(&buf->b_p_bt); 5632 check_string_option(&buf->b_p_fenc); 5633 check_string_option(&buf->b_p_ff); 5634 #ifdef FEAT_FIND_ID 5635 check_string_option(&buf->b_p_def); 5636 check_string_option(&buf->b_p_inc); 5637 # ifdef FEAT_EVAL 5638 check_string_option(&buf->b_p_inex); 5639 # endif 5640 #endif 5641 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 5642 check_string_option(&buf->b_p_inde); 5643 check_string_option(&buf->b_p_indk); 5644 #endif 5645 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) 5646 check_string_option(&buf->b_p_bexpr); 5647 #endif 5648 #if defined(FEAT_CRYPT) 5649 check_string_option(&buf->b_p_cm); 5650 #endif 5651 check_string_option(&buf->b_p_fp); 5652 #if defined(FEAT_EVAL) 5653 check_string_option(&buf->b_p_fex); 5654 #endif 5655 #ifdef FEAT_CRYPT 5656 check_string_option(&buf->b_p_key); 5657 #endif 5658 check_string_option(&buf->b_p_kp); 5659 check_string_option(&buf->b_p_mps); 5660 check_string_option(&buf->b_p_fo); 5661 check_string_option(&buf->b_p_flp); 5662 check_string_option(&buf->b_p_isk); 5663 #ifdef FEAT_COMMENTS 5664 check_string_option(&buf->b_p_com); 5665 #endif 5666 #ifdef FEAT_FOLDING 5667 check_string_option(&buf->b_p_cms); 5668 #endif 5669 check_string_option(&buf->b_p_nf); 5670 #ifdef FEAT_TEXTOBJ 5671 check_string_option(&buf->b_p_qe); 5672 #endif 5673 #ifdef FEAT_SYN_HL 5674 check_string_option(&buf->b_p_syn); 5675 check_string_option(&buf->b_s.b_syn_isk); 5676 #endif 5677 #ifdef FEAT_SPELL 5678 check_string_option(&buf->b_s.b_p_spc); 5679 check_string_option(&buf->b_s.b_p_spf); 5680 check_string_option(&buf->b_s.b_p_spl); 5681 #endif 5682 #ifdef FEAT_SEARCHPATH 5683 check_string_option(&buf->b_p_sua); 5684 #endif 5685 #ifdef FEAT_CINDENT 5686 check_string_option(&buf->b_p_cink); 5687 check_string_option(&buf->b_p_cino); 5688 parse_cino(buf); 5689 #endif 5690 check_string_option(&buf->b_p_ft); 5691 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 5692 check_string_option(&buf->b_p_cinw); 5693 #endif 5694 #ifdef FEAT_INS_EXPAND 5695 check_string_option(&buf->b_p_cpt); 5696 #endif 5697 #ifdef FEAT_COMPL_FUNC 5698 check_string_option(&buf->b_p_cfu); 5699 check_string_option(&buf->b_p_ofu); 5700 #endif 5701 #ifdef FEAT_KEYMAP 5702 check_string_option(&buf->b_p_keymap); 5703 #endif 5704 #ifdef FEAT_QUICKFIX 5705 check_string_option(&buf->b_p_gp); 5706 check_string_option(&buf->b_p_mp); 5707 check_string_option(&buf->b_p_efm); 5708 #endif 5709 check_string_option(&buf->b_p_ep); 5710 check_string_option(&buf->b_p_path); 5711 check_string_option(&buf->b_p_tags); 5712 check_string_option(&buf->b_p_tc); 5713 #ifdef FEAT_INS_EXPAND 5714 check_string_option(&buf->b_p_dict); 5715 check_string_option(&buf->b_p_tsr); 5716 #endif 5717 #ifdef FEAT_LISP 5718 check_string_option(&buf->b_p_lw); 5719 #endif 5720 check_string_option(&buf->b_p_bkc); 5721 check_string_option(&buf->b_p_menc); 5722 #ifdef FEAT_VARTABS 5723 check_string_option(&buf->b_p_vsts); 5724 check_string_option(&buf->b_p_vts); 5725 #endif 5726 } 5727 5728 /* 5729 * Free the string allocated for an option. 5730 * Checks for the string being empty_option. This may happen if we're out of 5731 * memory, vim_strsave() returned NULL, which was replaced by empty_option by 5732 * check_options(). 5733 * Does NOT check for P_ALLOCED flag! 5734 */ 5735 void 5736 free_string_option(char_u *p) 5737 { 5738 if (p != empty_option) 5739 vim_free(p); 5740 } 5741 5742 void 5743 clear_string_option(char_u **pp) 5744 { 5745 if (*pp != empty_option) 5746 vim_free(*pp); 5747 *pp = empty_option; 5748 } 5749 5750 static void 5751 check_string_option(char_u **pp) 5752 { 5753 if (*pp == NULL) 5754 *pp = empty_option; 5755 } 5756 5757 /* 5758 * Return the option index found by a pointer into term_strings[]. 5759 * Return -1 if not found. 5760 */ 5761 int 5762 get_term_opt_idx(char_u **p) 5763 { 5764 int opt_idx; 5765 5766 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++) 5767 if (options[opt_idx].var == (char_u *)p) 5768 return opt_idx; 5769 return -1; // cannot happen: didn't find it! 5770 } 5771 5772 /* 5773 * Mark a terminal option as allocated, found by a pointer into term_strings[]. 5774 * Return the option index or -1 if not found. 5775 */ 5776 int 5777 set_term_option_alloced(char_u **p) 5778 { 5779 int opt_idx = get_term_opt_idx(p); 5780 5781 if (opt_idx >= 0) 5782 options[opt_idx].flags |= P_ALLOCED; 5783 return opt_idx; 5784 } 5785 5786 #if defined(FEAT_EVAL) || defined(PROTO) 5787 /* 5788 * Return TRUE when option "opt" was set from a modeline or in secure mode. 5789 * Return FALSE when it wasn't. 5790 * Return -1 for an unknown option. 5791 */ 5792 int 5793 was_set_insecurely(char_u *opt, int opt_flags) 5794 { 5795 int idx = findoption(opt); 5796 long_u *flagp; 5797 5798 if (idx >= 0) 5799 { 5800 flagp = insecure_flag(idx, opt_flags); 5801 return (*flagp & P_INSECURE) != 0; 5802 } 5803 internal_error("was_set_insecurely()"); 5804 return -1; 5805 } 5806 5807 /* 5808 * Get a pointer to the flags used for the P_INSECURE flag of option 5809 * "opt_idx". For some local options a local flags field is used. 5810 */ 5811 static long_u * 5812 insecure_flag(int opt_idx, int opt_flags) 5813 { 5814 if (opt_flags & OPT_LOCAL) 5815 switch ((int)options[opt_idx].indir) 5816 { 5817 #ifdef FEAT_STL_OPT 5818 case PV_STL: return &curwin->w_p_stl_flags; 5819 #endif 5820 #ifdef FEAT_EVAL 5821 # ifdef FEAT_FOLDING 5822 case PV_FDE: return &curwin->w_p_fde_flags; 5823 case PV_FDT: return &curwin->w_p_fdt_flags; 5824 # endif 5825 # ifdef FEAT_BEVAL 5826 case PV_BEXPR: return &curbuf->b_p_bexpr_flags; 5827 # endif 5828 # if defined(FEAT_CINDENT) 5829 case PV_INDE: return &curbuf->b_p_inde_flags; 5830 # endif 5831 case PV_FEX: return &curbuf->b_p_fex_flags; 5832 # ifdef FEAT_FIND_ID 5833 case PV_INEX: return &curbuf->b_p_inex_flags; 5834 # endif 5835 #endif 5836 } 5837 5838 /* Nothing special, return global flags field. */ 5839 return &options[opt_idx].flags; 5840 } 5841 #endif 5842 5843 #ifdef FEAT_TITLE 5844 /* 5845 * Redraw the window title and/or tab page text later. 5846 */ 5847 static void redraw_titles(void) 5848 { 5849 need_maketitle = TRUE; 5850 redraw_tabline = TRUE; 5851 } 5852 #endif 5853 5854 /* 5855 * Set a string option to a new value (without checking the effect). 5856 * The string is copied into allocated memory. 5857 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used. 5858 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When 5859 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to 5860 * "set_sid". 5861 */ 5862 void 5863 set_string_option_direct( 5864 char_u *name, 5865 int opt_idx, 5866 char_u *val, 5867 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ 5868 int set_sid UNUSED) 5869 { 5870 char_u *s; 5871 char_u **varp; 5872 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; 5873 int idx = opt_idx; 5874 5875 if (idx == -1) /* use name */ 5876 { 5877 idx = findoption(name); 5878 if (idx < 0) /* not found (should not happen) */ 5879 { 5880 semsg(_(e_intern2), "set_string_option_direct()"); 5881 siemsg(_("For option %s"), name); 5882 return; 5883 } 5884 } 5885 5886 if (options[idx].var == NULL) /* can't set hidden option */ 5887 return; 5888 5889 s = vim_strsave(val); 5890 if (s != NULL) 5891 { 5892 varp = (char_u **)get_varp_scope(&(options[idx]), 5893 both ? OPT_LOCAL : opt_flags); 5894 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED)) 5895 free_string_option(*varp); 5896 *varp = s; 5897 5898 /* For buffer/window local option may also set the global value. */ 5899 if (both) 5900 set_string_option_global(idx, varp); 5901 5902 options[idx].flags |= P_ALLOCED; 5903 5904 /* When setting both values of a global option with a local value, 5905 * make the local value empty, so that the global value is used. */ 5906 if (((int)options[idx].indir & PV_BOTH) && both) 5907 { 5908 free_string_option(*varp); 5909 *varp = empty_option; 5910 } 5911 # ifdef FEAT_EVAL 5912 if (set_sid != SID_NONE) 5913 { 5914 sctx_T script_ctx; 5915 5916 if (set_sid == 0) 5917 script_ctx = current_sctx; 5918 else 5919 { 5920 script_ctx.sc_sid = set_sid; 5921 script_ctx.sc_seq = 0; 5922 script_ctx.sc_lnum = 0; 5923 } 5924 set_option_sctx_idx(idx, opt_flags, script_ctx); 5925 } 5926 # endif 5927 } 5928 } 5929 5930 /* 5931 * Set global value for string option when it's a local option. 5932 */ 5933 static void 5934 set_string_option_global( 5935 int opt_idx, /* option index */ 5936 char_u **varp) /* pointer to option variable */ 5937 { 5938 char_u **p, *s; 5939 5940 /* the global value is always allocated */ 5941 if (options[opt_idx].var == VAR_WIN) 5942 p = (char_u **)GLOBAL_WO(varp); 5943 else 5944 p = (char_u **)options[opt_idx].var; 5945 if (options[opt_idx].indir != PV_NONE 5946 && p != varp 5947 && (s = vim_strsave(*varp)) != NULL) 5948 { 5949 free_string_option(*p); 5950 *p = s; 5951 } 5952 } 5953 5954 /* 5955 * Set a string option to a new value, and handle the effects. 5956 * 5957 * Returns NULL on success or error message on error. 5958 */ 5959 static char * 5960 set_string_option( 5961 int opt_idx, 5962 char_u *value, 5963 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ 5964 { 5965 char_u *s; 5966 char_u **varp; 5967 char_u *oldval; 5968 #if defined(FEAT_EVAL) 5969 char_u *saved_oldval = NULL; 5970 char_u *saved_newval = NULL; 5971 #endif 5972 char *r = NULL; 5973 int value_checked = FALSE; 5974 5975 if (options[opt_idx].var == NULL) /* don't set hidden option */ 5976 return NULL; 5977 5978 s = vim_strsave(value); 5979 if (s != NULL) 5980 { 5981 varp = (char_u **)get_varp_scope(&(options[opt_idx]), 5982 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 5983 ? (((int)options[opt_idx].indir & PV_BOTH) 5984 ? OPT_GLOBAL : OPT_LOCAL) 5985 : opt_flags); 5986 oldval = *varp; 5987 *varp = s; 5988 5989 #if defined(FEAT_EVAL) 5990 if (!starting 5991 # ifdef FEAT_CRYPT 5992 && options[opt_idx].indir != PV_KEY 5993 # endif 5994 ) 5995 { 5996 saved_oldval = vim_strsave(oldval); 5997 saved_newval = vim_strsave(s); 5998 } 5999 #endif 6000 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, 6001 opt_flags, &value_checked)) == NULL) 6002 did_set_option(opt_idx, opt_flags, TRUE, value_checked); 6003 6004 #if defined(FEAT_EVAL) 6005 /* call autocommand after handling side effects */ 6006 if (r == NULL) 6007 trigger_optionsset_string(opt_idx, opt_flags, 6008 saved_oldval, saved_newval); 6009 vim_free(saved_oldval); 6010 vim_free(saved_newval); 6011 #endif 6012 } 6013 return r; 6014 } 6015 6016 /* 6017 * Return TRUE if "val" is a valid 'filetype' name. 6018 * Also used for 'syntax' and 'keymap'. 6019 */ 6020 static int 6021 valid_filetype(char_u *val) 6022 { 6023 char_u *s; 6024 6025 for (s = val; *s != NUL; ++s) 6026 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL) 6027 return FALSE; 6028 return TRUE; 6029 } 6030 6031 /* 6032 * Handle string options that need some action to perform when changed. 6033 * Returns NULL for success, or an error message for an error. 6034 */ 6035 static char * 6036 did_set_string_option( 6037 int opt_idx, // index in options[] table 6038 char_u **varp, // pointer to the option variable 6039 int new_value_alloced, // new value was allocated 6040 char_u *oldval, // previous value of the option 6041 char *errbuf, // buffer for errors, or NULL 6042 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL 6043 int *value_checked) // value was checked to be save, no 6044 // need to set P_INSECURE 6045 { 6046 char *errmsg = NULL; 6047 char_u *s, *p; 6048 int did_chartab = FALSE; 6049 char_u **gvarp; 6050 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED); 6051 #ifdef FEAT_GUI 6052 /* set when changing an option that only requires a redraw in the GUI */ 6053 int redraw_gui_only = FALSE; 6054 #endif 6055 int value_changed = FALSE; 6056 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) 6057 int did_swaptcap = FALSE; 6058 #endif 6059 6060 /* Get the global option to compare with, otherwise we would have to check 6061 * two values for all local options. */ 6062 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); 6063 6064 /* Disallow changing some options from secure mode */ 6065 if ((secure 6066 #ifdef HAVE_SANDBOX 6067 || sandbox != 0 6068 #endif 6069 ) && (options[opt_idx].flags & P_SECURE)) 6070 { 6071 errmsg = e_secure; 6072 } 6073 6074 // Check for a "normal" directory or file name in some options. Disallow a 6075 // path separator (slash and/or backslash), wildcards and characters that 6076 // are often illegal in a file name. Be more permissive if "secure" is off. 6077 else if (((options[opt_idx].flags & P_NFNAME) 6078 && vim_strpbrk(*varp, (char_u *)(secure 6079 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL) 6080 || ((options[opt_idx].flags & P_NDNAME) 6081 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) 6082 { 6083 errmsg = e_invarg; 6084 } 6085 6086 /* 'term' */ 6087 else if (varp == &T_NAME) 6088 { 6089 if (T_NAME[0] == NUL) 6090 errmsg = N_("E529: Cannot set 'term' to empty string"); 6091 #ifdef FEAT_GUI 6092 if (gui.in_use) 6093 errmsg = N_("E530: Cannot change term in GUI"); 6094 else if (term_is_gui(T_NAME)) 6095 errmsg = N_("E531: Use \":gui\" to start the GUI"); 6096 #endif 6097 else if (set_termname(T_NAME) == FAIL) 6098 errmsg = N_("E522: Not found in termcap"); 6099 else 6100 { 6101 /* Screen colors may have changed. */ 6102 redraw_later_clear(); 6103 6104 /* Both 'term' and 'ttytype' point to T_NAME, only set the 6105 * P_ALLOCED flag on 'term'. */ 6106 opt_idx = findoption((char_u *)"term"); 6107 free_oldval = (options[opt_idx].flags & P_ALLOCED); 6108 } 6109 } 6110 6111 /* 'backupcopy' */ 6112 else if (gvarp == &p_bkc) 6113 { 6114 char_u *bkc = p_bkc; 6115 unsigned int *flags = &bkc_flags; 6116 6117 if (opt_flags & OPT_LOCAL) 6118 { 6119 bkc = curbuf->b_p_bkc; 6120 flags = &curbuf->b_bkc_flags; 6121 } 6122 6123 if ((opt_flags & OPT_LOCAL) && *bkc == NUL) 6124 /* make the local value empty: use the global value */ 6125 *flags = 0; 6126 else 6127 { 6128 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) 6129 errmsg = e_invarg; 6130 if ((((int)*flags & BKC_AUTO) != 0) 6131 + (((int)*flags & BKC_YES) != 0) 6132 + (((int)*flags & BKC_NO) != 0) != 1) 6133 { 6134 /* Must have exactly one of "auto", "yes" and "no". */ 6135 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); 6136 errmsg = e_invarg; 6137 } 6138 } 6139 } 6140 6141 /* 'backupext' and 'patchmode' */ 6142 else if (varp == &p_bex || varp == &p_pm) 6143 { 6144 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, 6145 *p_pm == '.' ? p_pm + 1 : p_pm) == 0) 6146 errmsg = N_("E589: 'backupext' and 'patchmode' are equal"); 6147 } 6148 #ifdef FEAT_LINEBREAK 6149 /* 'breakindentopt' */ 6150 else if (varp == &curwin->w_p_briopt) 6151 { 6152 if (briopt_check(curwin) == FAIL) 6153 errmsg = e_invarg; 6154 } 6155 #endif 6156 6157 /* 6158 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] 6159 * If the new option is invalid, use old value. 'lisp' option: refill 6160 * g_chartab[] for '-' char 6161 */ 6162 else if ( varp == &p_isi 6163 || varp == &(curbuf->b_p_isk) 6164 || varp == &p_isp 6165 || varp == &p_isf) 6166 { 6167 if (init_chartab() == FAIL) 6168 { 6169 did_chartab = TRUE; /* need to restore it below */ 6170 errmsg = e_invarg; /* error in value */ 6171 } 6172 } 6173 6174 /* 'helpfile' */ 6175 else if (varp == &p_hf) 6176 { 6177 /* May compute new values for $VIM and $VIMRUNTIME */ 6178 if (didset_vim) 6179 { 6180 vim_setenv((char_u *)"VIM", (char_u *)""); 6181 didset_vim = FALSE; 6182 } 6183 if (didset_vimruntime) 6184 { 6185 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)""); 6186 didset_vimruntime = FALSE; 6187 } 6188 } 6189 6190 #ifdef FEAT_SYN_HL 6191 /* 'colorcolumn' */ 6192 else if (varp == &curwin->w_p_cc) 6193 errmsg = check_colorcolumn(curwin); 6194 #endif 6195 6196 #ifdef FEAT_MULTI_LANG 6197 /* 'helplang' */ 6198 else if (varp == &p_hlg) 6199 { 6200 /* Check for "", "ab", "ab,cd", etc. */ 6201 for (s = p_hlg; *s != NUL; s += 3) 6202 { 6203 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) 6204 { 6205 errmsg = e_invarg; 6206 break; 6207 } 6208 if (s[2] == NUL) 6209 break; 6210 } 6211 } 6212 #endif 6213 6214 /* 'highlight' */ 6215 else if (varp == &p_hl) 6216 { 6217 if (highlight_changed() == FAIL) 6218 errmsg = e_invarg; /* invalid flags */ 6219 } 6220 6221 /* 'nrformats' */ 6222 else if (gvarp == &p_nf) 6223 { 6224 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK) 6225 errmsg = e_invarg; 6226 } 6227 6228 #ifdef FEAT_SESSION 6229 /* 'sessionoptions' */ 6230 else if (varp == &p_ssop) 6231 { 6232 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK) 6233 errmsg = e_invarg; 6234 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) 6235 { 6236 /* Don't allow both "sesdir" and "curdir". */ 6237 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE); 6238 errmsg = e_invarg; 6239 } 6240 } 6241 /* 'viewoptions' */ 6242 else if (varp == &p_vop) 6243 { 6244 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK) 6245 errmsg = e_invarg; 6246 } 6247 #endif 6248 6249 /* 'scrollopt' */ 6250 else if (varp == &p_sbo) 6251 { 6252 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK) 6253 errmsg = e_invarg; 6254 } 6255 6256 /* 'ambiwidth' */ 6257 else if (varp == &p_ambw || varp == &p_emoji) 6258 { 6259 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) 6260 errmsg = e_invarg; 6261 else if (set_chars_option(&p_lcs) != NULL) 6262 errmsg = _("E834: Conflicts with value of 'listchars'"); 6263 else if (set_chars_option(&p_fcs) != NULL) 6264 errmsg = _("E835: Conflicts with value of 'fillchars'"); 6265 } 6266 6267 /* 'background' */ 6268 else if (varp == &p_bg) 6269 { 6270 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK) 6271 { 6272 #ifdef FEAT_EVAL 6273 int dark = (*p_bg == 'd'); 6274 #endif 6275 6276 init_highlight(FALSE, FALSE); 6277 6278 #ifdef FEAT_EVAL 6279 if (dark != (*p_bg == 'd') 6280 && get_var_value((char_u *)"g:colors_name") != NULL) 6281 { 6282 /* The color scheme must have set 'background' back to another 6283 * value, that's not what we want here. Disable the color 6284 * scheme and set the colors again. */ 6285 do_unlet((char_u *)"g:colors_name", TRUE); 6286 free_string_option(p_bg); 6287 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); 6288 check_string_option(&p_bg); 6289 init_highlight(FALSE, FALSE); 6290 } 6291 #endif 6292 } 6293 else 6294 errmsg = e_invarg; 6295 } 6296 6297 /* 'wildmode' */ 6298 else if (varp == &p_wim) 6299 { 6300 if (check_opt_wim() == FAIL) 6301 errmsg = e_invarg; 6302 } 6303 6304 #ifdef FEAT_CMDL_COMPL 6305 /* 'wildoptions' */ 6306 else if (varp == &p_wop) 6307 { 6308 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK) 6309 errmsg = e_invarg; 6310 } 6311 #endif 6312 6313 #ifdef FEAT_WAK 6314 /* 'winaltkeys' */ 6315 else if (varp == &p_wak) 6316 { 6317 if (*p_wak == NUL 6318 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK) 6319 errmsg = e_invarg; 6320 # ifdef FEAT_MENU 6321 # ifdef FEAT_GUI_MOTIF 6322 else if (gui.in_use) 6323 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); 6324 # else 6325 # ifdef FEAT_GUI_GTK 6326 else if (gui.in_use) 6327 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); 6328 # endif 6329 # endif 6330 # endif 6331 } 6332 #endif 6333 6334 /* 'eventignore' */ 6335 else if (varp == &p_ei) 6336 { 6337 if (check_ei() == FAIL) 6338 errmsg = e_invarg; 6339 } 6340 6341 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */ 6342 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc 6343 || gvarp == &p_menc) 6344 { 6345 if (gvarp == &p_fenc) 6346 { 6347 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL) 6348 errmsg = e_modifiable; 6349 else if (vim_strchr(*varp, ',') != NULL) 6350 /* No comma allowed in 'fileencoding'; catches confusing it 6351 * with 'fileencodings'. */ 6352 errmsg = e_invarg; 6353 else 6354 { 6355 #ifdef FEAT_TITLE 6356 /* May show a "+" in the title now. */ 6357 redraw_titles(); 6358 #endif 6359 /* Add 'fileencoding' to the swap file. */ 6360 ml_setflags(curbuf); 6361 } 6362 } 6363 if (errmsg == NULL) 6364 { 6365 /* canonize the value, so that STRCMP() can be used on it */ 6366 p = enc_canonize(*varp); 6367 if (p != NULL) 6368 { 6369 vim_free(*varp); 6370 *varp = p; 6371 } 6372 if (varp == &p_enc) 6373 { 6374 errmsg = mb_init(); 6375 #ifdef FEAT_TITLE 6376 redraw_titles(); 6377 #endif 6378 } 6379 } 6380 6381 #if defined(FEAT_GUI_GTK) 6382 if (errmsg == NULL && varp == &p_tenc && gui.in_use) 6383 { 6384 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */ 6385 if (STRCMP(p_tenc, "utf-8") != 0) 6386 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI"); 6387 } 6388 #endif 6389 6390 if (errmsg == NULL) 6391 { 6392 #ifdef FEAT_KEYMAP 6393 /* When 'keymap' is used and 'encoding' changes, reload the keymap 6394 * (with another encoding). */ 6395 if (varp == &p_enc && *curbuf->b_p_keymap != NUL) 6396 (void)keymap_init(); 6397 #endif 6398 6399 /* When 'termencoding' is not empty and 'encoding' changes or when 6400 * 'termencoding' changes, need to setup for keyboard input and 6401 * display output conversion. */ 6402 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc)) 6403 { 6404 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL 6405 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL) 6406 { 6407 semsg(_("E950: Cannot convert between %s and %s"), 6408 p_tenc, p_enc); 6409 errmsg = e_invarg; 6410 } 6411 } 6412 6413 #if defined(WIN3264) 6414 /* $HOME may have characters in active code page. */ 6415 if (varp == &p_enc) 6416 init_homedir(); 6417 #endif 6418 } 6419 } 6420 6421 #if defined(FEAT_POSTSCRIPT) 6422 else if (varp == &p_penc) 6423 { 6424 /* Canonize printencoding if VIM standard one */ 6425 p = enc_canonize(p_penc); 6426 if (p != NULL) 6427 { 6428 vim_free(p_penc); 6429 p_penc = p; 6430 } 6431 else 6432 { 6433 /* Ensure lower case and '-' for '_' */ 6434 for (s = p_penc; *s != NUL; s++) 6435 { 6436 if (*s == '_') 6437 *s = '-'; 6438 else 6439 *s = TOLOWER_ASC(*s); 6440 } 6441 } 6442 } 6443 #endif 6444 6445 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) 6446 else if (varp == &p_imak) 6447 { 6448 if (!im_xim_isvalid_imactivate()) 6449 errmsg = e_invarg; 6450 } 6451 #endif 6452 6453 #ifdef FEAT_KEYMAP 6454 else if (varp == &curbuf->b_p_keymap) 6455 { 6456 if (!valid_filetype(*varp)) 6457 errmsg = e_invarg; 6458 else 6459 { 6460 int secure_save = secure; 6461 6462 // Reset the secure flag, since the value of 'keymap' has 6463 // been checked to be safe. 6464 secure = 0; 6465 6466 // load or unload key mapping tables 6467 errmsg = keymap_init(); 6468 6469 secure = secure_save; 6470 6471 // Since we check the value, there is no need to set P_INSECURE, 6472 // even when the value comes from a modeline. 6473 *value_checked = TRUE; 6474 } 6475 6476 if (errmsg == NULL) 6477 { 6478 if (*curbuf->b_p_keymap != NUL) 6479 { 6480 /* Installed a new keymap, switch on using it. */ 6481 curbuf->b_p_iminsert = B_IMODE_LMAP; 6482 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) 6483 curbuf->b_p_imsearch = B_IMODE_LMAP; 6484 } 6485 else 6486 { 6487 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */ 6488 if (curbuf->b_p_iminsert == B_IMODE_LMAP) 6489 curbuf->b_p_iminsert = B_IMODE_NONE; 6490 if (curbuf->b_p_imsearch == B_IMODE_LMAP) 6491 curbuf->b_p_imsearch = B_IMODE_USE_INSERT; 6492 } 6493 if ((opt_flags & OPT_LOCAL) == 0) 6494 { 6495 set_iminsert_global(); 6496 set_imsearch_global(); 6497 } 6498 status_redraw_curbuf(); 6499 } 6500 } 6501 #endif 6502 6503 /* 'fileformat' */ 6504 else if (gvarp == &p_ff) 6505 { 6506 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) 6507 errmsg = e_modifiable; 6508 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) 6509 errmsg = e_invarg; 6510 else 6511 { 6512 /* may also change 'textmode' */ 6513 if (get_fileformat(curbuf) == EOL_DOS) 6514 curbuf->b_p_tx = TRUE; 6515 else 6516 curbuf->b_p_tx = FALSE; 6517 #ifdef FEAT_TITLE 6518 redraw_titles(); 6519 #endif 6520 /* update flag in swap file */ 6521 ml_setflags(curbuf); 6522 /* Redraw needed when switching to/from "mac": a CR in the text 6523 * will be displayed differently. */ 6524 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm') 6525 redraw_curbuf_later(NOT_VALID); 6526 } 6527 } 6528 6529 /* 'fileformats' */ 6530 else if (varp == &p_ffs) 6531 { 6532 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) 6533 errmsg = e_invarg; 6534 else 6535 { 6536 /* also change 'textauto' */ 6537 if (*p_ffs == NUL) 6538 p_ta = FALSE; 6539 else 6540 p_ta = TRUE; 6541 } 6542 } 6543 6544 #if defined(FEAT_CRYPT) 6545 /* 'cryptkey' */ 6546 else if (gvarp == &p_key) 6547 { 6548 # if defined(FEAT_CMDHIST) 6549 /* Make sure the ":set" command doesn't show the new value in the 6550 * history. */ 6551 remove_key_from_history(); 6552 # endif 6553 if (STRCMP(curbuf->b_p_key, oldval) != 0) 6554 /* Need to update the swapfile. */ 6555 ml_set_crypt_key(curbuf, oldval, 6556 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm); 6557 } 6558 6559 else if (gvarp == &p_cm) 6560 { 6561 if (opt_flags & OPT_LOCAL) 6562 p = curbuf->b_p_cm; 6563 else 6564 p = p_cm; 6565 if (check_opt_strings(p, p_cm_values, TRUE) != OK) 6566 errmsg = e_invarg; 6567 else if (crypt_self_test() == FAIL) 6568 errmsg = e_invarg; 6569 else 6570 { 6571 /* When setting the global value to empty, make it "zip". */ 6572 if (*p_cm == NUL) 6573 { 6574 if (new_value_alloced) 6575 free_string_option(p_cm); 6576 p_cm = vim_strsave((char_u *)"zip"); 6577 new_value_alloced = TRUE; 6578 } 6579 /* When using ":set cm=name" the local value is going to be empty. 6580 * Do that here, otherwise the crypt functions will still use the 6581 * local value. */ 6582 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) 6583 { 6584 free_string_option(curbuf->b_p_cm); 6585 curbuf->b_p_cm = empty_option; 6586 } 6587 6588 /* Need to update the swapfile when the effective method changed. 6589 * Set "s" to the effective old value, "p" to the effective new 6590 * method and compare. */ 6591 if ((opt_flags & OPT_LOCAL) && *oldval == NUL) 6592 s = p_cm; /* was previously using the global value */ 6593 else 6594 s = oldval; 6595 if (*curbuf->b_p_cm == NUL) 6596 p = p_cm; /* is now using the global value */ 6597 else 6598 p = curbuf->b_p_cm; 6599 if (STRCMP(s, p) != 0) 6600 ml_set_crypt_key(curbuf, curbuf->b_p_key, s); 6601 6602 /* If the global value changes need to update the swapfile for all 6603 * buffers using that value. */ 6604 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0) 6605 { 6606 buf_T *buf; 6607 6608 FOR_ALL_BUFFERS(buf) 6609 if (buf != curbuf && *buf->b_p_cm == NUL) 6610 ml_set_crypt_key(buf, buf->b_p_key, oldval); 6611 } 6612 } 6613 } 6614 #endif 6615 6616 /* 'matchpairs' */ 6617 else if (gvarp == &p_mps) 6618 { 6619 if (has_mbyte) 6620 { 6621 for (p = *varp; *p != NUL; ++p) 6622 { 6623 int x2 = -1; 6624 int x3 = -1; 6625 6626 if (*p != NUL) 6627 p += mb_ptr2len(p); 6628 if (*p != NUL) 6629 x2 = *p++; 6630 if (*p != NUL) 6631 { 6632 x3 = mb_ptr2char(p); 6633 p += mb_ptr2len(p); 6634 } 6635 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) 6636 { 6637 errmsg = e_invarg; 6638 break; 6639 } 6640 if (*p == NUL) 6641 break; 6642 } 6643 } 6644 else 6645 { 6646 /* Check for "x:y,x:y" */ 6647 for (p = *varp; *p != NUL; p += 4) 6648 { 6649 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) 6650 { 6651 errmsg = e_invarg; 6652 break; 6653 } 6654 if (p[3] == NUL) 6655 break; 6656 } 6657 } 6658 } 6659 6660 #ifdef FEAT_COMMENTS 6661 /* 'comments' */ 6662 else if (gvarp == &p_com) 6663 { 6664 for (s = *varp; *s; ) 6665 { 6666 while (*s && *s != ':') 6667 { 6668 if (vim_strchr((char_u *)COM_ALL, *s) == NULL 6669 && !VIM_ISDIGIT(*s) && *s != '-') 6670 { 6671 errmsg = illegal_char(errbuf, *s); 6672 break; 6673 } 6674 ++s; 6675 } 6676 if (*s++ == NUL) 6677 errmsg = N_("E524: Missing colon"); 6678 else if (*s == ',' || *s == NUL) 6679 errmsg = N_("E525: Zero length string"); 6680 if (errmsg != NULL) 6681 break; 6682 while (*s && *s != ',') 6683 { 6684 if (*s == '\\' && s[1] != NUL) 6685 ++s; 6686 ++s; 6687 } 6688 s = skip_to_option_part(s); 6689 } 6690 } 6691 #endif 6692 6693 /* 'listchars' */ 6694 else if (varp == &p_lcs) 6695 { 6696 errmsg = set_chars_option(varp); 6697 } 6698 6699 /* 'fillchars' */ 6700 else if (varp == &p_fcs) 6701 { 6702 errmsg = set_chars_option(varp); 6703 } 6704 6705 #ifdef FEAT_CMDWIN 6706 /* 'cedit' */ 6707 else if (varp == &p_cedit) 6708 { 6709 errmsg = check_cedit(); 6710 } 6711 #endif 6712 6713 /* 'verbosefile' */ 6714 else if (varp == &p_vfile) 6715 { 6716 verbose_stop(); 6717 if (*p_vfile != NUL && verbose_open() == FAIL) 6718 errmsg = e_invarg; 6719 } 6720 6721 #ifdef FEAT_VIMINFO 6722 /* 'viminfo' */ 6723 else if (varp == &p_viminfo) 6724 { 6725 for (s = p_viminfo; *s;) 6726 { 6727 /* Check it's a valid character */ 6728 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL) 6729 { 6730 errmsg = illegal_char(errbuf, *s); 6731 break; 6732 } 6733 if (*s == 'n') /* name is always last one */ 6734 { 6735 break; 6736 } 6737 else if (*s == 'r') /* skip until next ',' */ 6738 { 6739 while (*++s && *s != ',') 6740 ; 6741 } 6742 else if (*s == '%') 6743 { 6744 /* optional number */ 6745 while (vim_isdigit(*++s)) 6746 ; 6747 } 6748 else if (*s == '!' || *s == 'h' || *s == 'c') 6749 ++s; /* no extra chars */ 6750 else /* must have a number */ 6751 { 6752 while (vim_isdigit(*++s)) 6753 ; 6754 6755 if (!VIM_ISDIGIT(*(s - 1))) 6756 { 6757 if (errbuf != NULL) 6758 { 6759 sprintf(errbuf, _("E526: Missing number after <%s>"), 6760 transchar_byte(*(s - 1))); 6761 errmsg = errbuf; 6762 } 6763 else 6764 errmsg = ""; 6765 break; 6766 } 6767 } 6768 if (*s == ',') 6769 ++s; 6770 else if (*s) 6771 { 6772 if (errbuf != NULL) 6773 errmsg = N_("E527: Missing comma"); 6774 else 6775 errmsg = ""; 6776 break; 6777 } 6778 } 6779 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0) 6780 errmsg = N_("E528: Must specify a ' value"); 6781 } 6782 #endif /* FEAT_VIMINFO */ 6783 6784 /* terminal options */ 6785 else if (istermoption(&options[opt_idx]) && full_screen) 6786 { 6787 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */ 6788 if (varp == &T_CCO) 6789 { 6790 int colors = atoi((char *)T_CCO); 6791 6792 /* Only reinitialize colors if t_Co value has really changed to 6793 * avoid expensive reload of colorscheme if t_Co is set to the 6794 * same value multiple times. */ 6795 if (colors != t_colors) 6796 { 6797 t_colors = colors; 6798 if (t_colors <= 1) 6799 { 6800 if (new_value_alloced) 6801 vim_free(T_CCO); 6802 T_CCO = empty_option; 6803 } 6804 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) 6805 if (is_term_win32()) 6806 { 6807 swap_tcap(); 6808 did_swaptcap = TRUE; 6809 } 6810 #endif 6811 /* We now have a different color setup, initialize it again. */ 6812 init_highlight(TRUE, FALSE); 6813 } 6814 } 6815 ttest(FALSE); 6816 if (varp == &T_ME) 6817 { 6818 out_str(T_ME); 6819 redraw_later(CLEAR); 6820 #if defined(WIN3264) && !defined(FEAT_GUI_W32) 6821 /* Since t_me has been set, this probably means that the user 6822 * wants to use this as default colors. Need to reset default 6823 * background/foreground colors. */ 6824 mch_set_normal_colors(); 6825 #endif 6826 } 6827 if (varp == &T_BE && termcap_active) 6828 { 6829 if (*T_BE == NUL) 6830 /* When clearing t_BE we assume the user no longer wants 6831 * bracketed paste, thus disable it by writing t_BD. */ 6832 out_str(T_BD); 6833 else 6834 out_str(T_BE); 6835 } 6836 } 6837 6838 #ifdef FEAT_LINEBREAK 6839 /* 'showbreak' */ 6840 else if (varp == &p_sbr) 6841 { 6842 for (s = p_sbr; *s; ) 6843 { 6844 if (ptr2cells(s) != 1) 6845 errmsg = N_("E595: contains unprintable or wide character"); 6846 MB_PTR_ADV(s); 6847 } 6848 } 6849 #endif 6850 6851 #ifdef FEAT_GUI 6852 /* 'guifont' */ 6853 else if (varp == &p_guifont) 6854 { 6855 if (gui.in_use) 6856 { 6857 p = p_guifont; 6858 # if defined(FEAT_GUI_GTK) 6859 /* 6860 * Put up a font dialog and let the user select a new value. 6861 * If this is cancelled go back to the old value but don't 6862 * give an error message. 6863 */ 6864 if (STRCMP(p, "*") == 0) 6865 { 6866 p = gui_mch_font_dialog(oldval); 6867 6868 if (new_value_alloced) 6869 free_string_option(p_guifont); 6870 6871 p_guifont = (p != NULL) ? p : vim_strsave(oldval); 6872 new_value_alloced = TRUE; 6873 } 6874 # endif 6875 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK) 6876 { 6877 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON) 6878 if (STRCMP(p_guifont, "*") == 0) 6879 { 6880 /* Dialog was cancelled: Keep the old value without giving 6881 * an error message. */ 6882 if (new_value_alloced) 6883 free_string_option(p_guifont); 6884 p_guifont = vim_strsave(oldval); 6885 new_value_alloced = TRUE; 6886 } 6887 else 6888 # endif 6889 errmsg = N_("E596: Invalid font(s)"); 6890 } 6891 } 6892 redraw_gui_only = TRUE; 6893 } 6894 # ifdef FEAT_XFONTSET 6895 else if (varp == &p_guifontset) 6896 { 6897 if (STRCMP(p_guifontset, "*") == 0) 6898 errmsg = N_("E597: can't select fontset"); 6899 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK) 6900 errmsg = N_("E598: Invalid fontset"); 6901 redraw_gui_only = TRUE; 6902 } 6903 # endif 6904 else if (varp == &p_guifontwide) 6905 { 6906 if (STRCMP(p_guifontwide, "*") == 0) 6907 errmsg = N_("E533: can't select wide font"); 6908 else if (gui_get_wide_font() == FAIL) 6909 errmsg = N_("E534: Invalid wide font"); 6910 redraw_gui_only = TRUE; 6911 } 6912 #endif 6913 6914 #ifdef CURSOR_SHAPE 6915 /* 'guicursor' */ 6916 else if (varp == &p_guicursor) 6917 errmsg = parse_shape_opt(SHAPE_CURSOR); 6918 #endif 6919 6920 #ifdef FEAT_MOUSESHAPE 6921 /* 'mouseshape' */ 6922 else if (varp == &p_mouseshape) 6923 { 6924 errmsg = parse_shape_opt(SHAPE_MOUSE); 6925 update_mouseshape(-1); 6926 } 6927 #endif 6928 6929 #ifdef FEAT_PRINTER 6930 else if (varp == &p_popt) 6931 errmsg = parse_printoptions(); 6932 # if defined(FEAT_POSTSCRIPT) 6933 else if (varp == &p_pmfn) 6934 errmsg = parse_printmbfont(); 6935 # endif 6936 #endif 6937 6938 #ifdef FEAT_LANGMAP 6939 /* 'langmap' */ 6940 else if (varp == &p_langmap) 6941 langmap_set(); 6942 #endif 6943 6944 #ifdef FEAT_LINEBREAK 6945 /* 'breakat' */ 6946 else if (varp == &p_breakat) 6947 fill_breakat_flags(); 6948 #endif 6949 6950 #ifdef FEAT_TITLE 6951 /* 'titlestring' and 'iconstring' */ 6952 else if (varp == &p_titlestring || varp == &p_iconstring) 6953 { 6954 # ifdef FEAT_STL_OPT 6955 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON; 6956 6957 /* NULL => statusline syntax */ 6958 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL) 6959 stl_syntax |= flagval; 6960 else 6961 stl_syntax &= ~flagval; 6962 # endif 6963 did_set_title(); 6964 } 6965 #endif 6966 6967 #ifdef FEAT_GUI 6968 /* 'guioptions' */ 6969 else if (varp == &p_go) 6970 { 6971 gui_init_which_components(oldval); 6972 redraw_gui_only = TRUE; 6973 } 6974 #endif 6975 6976 #if defined(FEAT_GUI_TABLINE) 6977 /* 'guitablabel' */ 6978 else if (varp == &p_gtl) 6979 { 6980 redraw_tabline = TRUE; 6981 redraw_gui_only = TRUE; 6982 } 6983 /* 'guitabtooltip' */ 6984 else if (varp == &p_gtt) 6985 { 6986 redraw_gui_only = TRUE; 6987 } 6988 #endif 6989 6990 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS)) 6991 /* 'ttymouse' */ 6992 else if (varp == &p_ttym) 6993 { 6994 /* Switch the mouse off before changing the escape sequences used for 6995 * that. */ 6996 mch_setmouse(FALSE); 6997 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK) 6998 errmsg = e_invarg; 6999 else 7000 check_mouse_termcode(); 7001 if (termcap_active) 7002 setmouse(); /* may switch it on again */ 7003 } 7004 #endif 7005 7006 /* 'selection' */ 7007 else if (varp == &p_sel) 7008 { 7009 if (*p_sel == NUL 7010 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK) 7011 errmsg = e_invarg; 7012 } 7013 7014 /* 'selectmode' */ 7015 else if (varp == &p_slm) 7016 { 7017 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK) 7018 errmsg = e_invarg; 7019 } 7020 7021 #ifdef FEAT_BROWSE 7022 /* 'browsedir' */ 7023 else if (varp == &p_bsdir) 7024 { 7025 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK 7026 && !mch_isdir(p_bsdir)) 7027 errmsg = e_invarg; 7028 } 7029 #endif 7030 7031 /* 'keymodel' */ 7032 else if (varp == &p_km) 7033 { 7034 if (check_opt_strings(p_km, p_km_values, TRUE) != OK) 7035 errmsg = e_invarg; 7036 else 7037 { 7038 km_stopsel = (vim_strchr(p_km, 'o') != NULL); 7039 km_startsel = (vim_strchr(p_km, 'a') != NULL); 7040 } 7041 } 7042 7043 /* 'mousemodel' */ 7044 else if (varp == &p_mousem) 7045 { 7046 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK) 7047 errmsg = e_invarg; 7048 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002) 7049 else if (*p_mousem != *oldval) 7050 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need 7051 * to create or delete the popup menus. */ 7052 gui_motif_update_mousemodel(root_menu); 7053 #endif 7054 } 7055 7056 /* 'switchbuf' */ 7057 else if (varp == &p_swb) 7058 { 7059 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK) 7060 errmsg = e_invarg; 7061 } 7062 7063 /* 'debug' */ 7064 else if (varp == &p_debug) 7065 { 7066 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK) 7067 errmsg = e_invarg; 7068 } 7069 7070 /* 'display' */ 7071 else if (varp == &p_dy) 7072 { 7073 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK) 7074 errmsg = e_invarg; 7075 else 7076 (void)init_chartab(); 7077 7078 } 7079 7080 /* 'eadirection' */ 7081 else if (varp == &p_ead) 7082 { 7083 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK) 7084 errmsg = e_invarg; 7085 } 7086 7087 #ifdef FEAT_CLIPBOARD 7088 /* 'clipboard' */ 7089 else if (varp == &p_cb) 7090 errmsg = check_clipboard_option(); 7091 #endif 7092 7093 #ifdef FEAT_SPELL 7094 /* When 'spelllang' or 'spellfile' is set and there is a window for this 7095 * buffer in which 'spell' is set load the wordlists. */ 7096 else if (varp == &(curwin->w_s->b_p_spl) 7097 || varp == &(curwin->w_s->b_p_spf)) 7098 { 7099 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf)); 7100 } 7101 /* When 'spellcapcheck' is set compile the regexp program. */ 7102 else if (varp == &(curwin->w_s->b_p_spc)) 7103 { 7104 errmsg = compile_cap_prog(curwin->w_s); 7105 } 7106 /* 'spellsuggest' */ 7107 else if (varp == &p_sps) 7108 { 7109 if (spell_check_sps() != OK) 7110 errmsg = e_invarg; 7111 } 7112 /* 'mkspellmem' */ 7113 else if (varp == &p_msm) 7114 { 7115 if (spell_check_msm() != OK) 7116 errmsg = e_invarg; 7117 } 7118 #endif 7119 7120 /* When 'bufhidden' is set, check for valid value. */ 7121 else if (gvarp == &p_bh) 7122 { 7123 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK) 7124 errmsg = e_invarg; 7125 } 7126 7127 /* When 'buftype' is set, check for valid value. */ 7128 else if (gvarp == &p_bt) 7129 { 7130 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK) 7131 errmsg = e_invarg; 7132 else 7133 { 7134 if (curwin->w_status_height) 7135 { 7136 curwin->w_redr_status = TRUE; 7137 redraw_later(VALID); 7138 } 7139 curbuf->b_help = (curbuf->b_p_bt[0] == 'h'); 7140 #ifdef FEAT_TITLE 7141 redraw_titles(); 7142 #endif 7143 } 7144 } 7145 7146 #ifdef FEAT_STL_OPT 7147 /* 'statusline' or 'rulerformat' */ 7148 else if (gvarp == &p_stl || varp == &p_ruf) 7149 { 7150 int wid; 7151 7152 if (varp == &p_ruf) /* reset ru_wid first */ 7153 ru_wid = 0; 7154 s = *varp; 7155 if (varp == &p_ruf && *s == '%') 7156 { 7157 /* set ru_wid if 'ruf' starts with "%99(" */ 7158 if (*++s == '-') /* ignore a '-' */ 7159 s++; 7160 wid = getdigits(&s); 7161 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) 7162 ru_wid = wid; 7163 else 7164 errmsg = check_stl_option(p_ruf); 7165 } 7166 /* check 'statusline' only if it doesn't start with "%!" */ 7167 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!') 7168 errmsg = check_stl_option(s); 7169 if (varp == &p_ruf && errmsg == NULL) 7170 comp_col(); 7171 } 7172 #endif 7173 7174 #ifdef FEAT_INS_EXPAND 7175 /* check if it is a valid value for 'complete' -- Acevedo */ 7176 else if (gvarp == &p_cpt) 7177 { 7178 for (s = *varp; *s;) 7179 { 7180 while (*s == ',' || *s == ' ') 7181 s++; 7182 if (!*s) 7183 break; 7184 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL) 7185 { 7186 errmsg = illegal_char(errbuf, *s); 7187 break; 7188 } 7189 if (*++s != NUL && *s != ',' && *s != ' ') 7190 { 7191 if (s[-1] == 'k' || s[-1] == 's') 7192 { 7193 /* skip optional filename after 'k' and 's' */ 7194 while (*s && *s != ',' && *s != ' ') 7195 { 7196 if (*s == '\\' && s[1] != NUL) 7197 ++s; 7198 ++s; 7199 } 7200 } 7201 else 7202 { 7203 if (errbuf != NULL) 7204 { 7205 sprintf((char *)errbuf, 7206 _("E535: Illegal character after <%c>"), 7207 *--s); 7208 errmsg = errbuf; 7209 } 7210 else 7211 errmsg = ""; 7212 break; 7213 } 7214 } 7215 } 7216 } 7217 7218 /* 'completeopt' */ 7219 else if (varp == &p_cot) 7220 { 7221 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK) 7222 errmsg = e_invarg; 7223 else 7224 completeopt_was_set(); 7225 } 7226 #endif /* FEAT_INS_EXPAND */ 7227 7228 #ifdef FEAT_SIGNS 7229 /* 'signcolumn' */ 7230 else if (varp == &curwin->w_p_scl) 7231 { 7232 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK) 7233 errmsg = e_invarg; 7234 } 7235 #endif 7236 7237 7238 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) 7239 /* 'toolbar' */ 7240 else if (varp == &p_toolbar) 7241 { 7242 if (opt_strings_flags(p_toolbar, p_toolbar_values, 7243 &toolbar_flags, TRUE) != OK) 7244 errmsg = e_invarg; 7245 else 7246 { 7247 out_flush(); 7248 gui_mch_show_toolbar((toolbar_flags & 7249 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); 7250 } 7251 } 7252 #endif 7253 7254 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) 7255 /* 'toolbariconsize': GTK+ 2 only */ 7256 else if (varp == &p_tbis) 7257 { 7258 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK) 7259 errmsg = e_invarg; 7260 else 7261 { 7262 out_flush(); 7263 gui_mch_show_toolbar((toolbar_flags & 7264 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); 7265 } 7266 } 7267 #endif 7268 7269 /* 'pastetoggle': translate key codes like in a mapping */ 7270 else if (varp == &p_pt) 7271 { 7272 if (*p_pt) 7273 { 7274 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE); 7275 if (p != NULL) 7276 { 7277 if (new_value_alloced) 7278 free_string_option(p_pt); 7279 p_pt = p; 7280 new_value_alloced = TRUE; 7281 } 7282 } 7283 } 7284 7285 /* 'backspace' */ 7286 else if (varp == &p_bs) 7287 { 7288 if (VIM_ISDIGIT(*p_bs)) 7289 { 7290 if (*p_bs > '2' || p_bs[1] != NUL) 7291 errmsg = e_invarg; 7292 } 7293 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK) 7294 errmsg = e_invarg; 7295 } 7296 else if (varp == &p_bo) 7297 { 7298 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK) 7299 errmsg = e_invarg; 7300 } 7301 7302 /* 'tagcase' */ 7303 else if (gvarp == &p_tc) 7304 { 7305 unsigned int *flags; 7306 7307 if (opt_flags & OPT_LOCAL) 7308 { 7309 p = curbuf->b_p_tc; 7310 flags = &curbuf->b_tc_flags; 7311 } 7312 else 7313 { 7314 p = p_tc; 7315 flags = &tc_flags; 7316 } 7317 7318 if ((opt_flags & OPT_LOCAL) && *p == NUL) 7319 /* make the local value empty: use the global value */ 7320 *flags = 0; 7321 else if (*p == NUL 7322 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK) 7323 errmsg = e_invarg; 7324 } 7325 7326 /* 'casemap' */ 7327 else if (varp == &p_cmp) 7328 { 7329 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK) 7330 errmsg = e_invarg; 7331 } 7332 7333 #ifdef FEAT_DIFF 7334 /* 'diffopt' */ 7335 else if (varp == &p_dip) 7336 { 7337 if (diffopt_changed() == FAIL) 7338 errmsg = e_invarg; 7339 } 7340 #endif 7341 7342 #ifdef FEAT_FOLDING 7343 /* 'foldmethod' */ 7344 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) 7345 { 7346 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK 7347 || *curwin->w_p_fdm == NUL) 7348 errmsg = e_invarg; 7349 else 7350 { 7351 foldUpdateAll(curwin); 7352 if (foldmethodIsDiff(curwin)) 7353 newFoldLevel(); 7354 } 7355 } 7356 # ifdef FEAT_EVAL 7357 /* 'foldexpr' */ 7358 else if (varp == &curwin->w_p_fde) 7359 { 7360 if (foldmethodIsExpr(curwin)) 7361 foldUpdateAll(curwin); 7362 } 7363 # endif 7364 /* 'foldmarker' */ 7365 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) 7366 { 7367 p = vim_strchr(*varp, ','); 7368 if (p == NULL) 7369 errmsg = N_("E536: comma required"); 7370 else if (p == *varp || p[1] == NUL) 7371 errmsg = e_invarg; 7372 else if (foldmethodIsMarker(curwin)) 7373 foldUpdateAll(curwin); 7374 } 7375 /* 'commentstring' */ 7376 else if (gvarp == &p_cms) 7377 { 7378 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL) 7379 errmsg = N_("E537: 'commentstring' must be empty or contain %s"); 7380 } 7381 /* 'foldopen' */ 7382 else if (varp == &p_fdo) 7383 { 7384 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK) 7385 errmsg = e_invarg; 7386 } 7387 /* 'foldclose' */ 7388 else if (varp == &p_fcl) 7389 { 7390 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK) 7391 errmsg = e_invarg; 7392 } 7393 /* 'foldignore' */ 7394 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi) 7395 { 7396 if (foldmethodIsIndent(curwin)) 7397 foldUpdateAll(curwin); 7398 } 7399 #endif 7400 7401 /* 'virtualedit' */ 7402 else if (varp == &p_ve) 7403 { 7404 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK) 7405 errmsg = e_invarg; 7406 else if (STRCMP(p_ve, oldval) != 0) 7407 { 7408 /* Recompute cursor position in case the new 've' setting 7409 * changes something. */ 7410 validate_virtcol(); 7411 coladvance(curwin->w_virtcol); 7412 } 7413 } 7414 7415 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX) 7416 else if (varp == &p_csqf) 7417 { 7418 if (p_csqf != NULL) 7419 { 7420 p = p_csqf; 7421 while (*p != NUL) 7422 { 7423 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL 7424 || p[1] == NUL 7425 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL 7426 || (p[2] != NUL && p[2] != ',')) 7427 { 7428 errmsg = e_invarg; 7429 break; 7430 } 7431 else if (p[2] == NUL) 7432 break; 7433 else 7434 p += 3; 7435 } 7436 } 7437 } 7438 #endif 7439 7440 #ifdef FEAT_CINDENT 7441 /* 'cinoptions' */ 7442 else if (gvarp == &p_cino) 7443 { 7444 /* TODO: recognize errors */ 7445 parse_cino(curbuf); 7446 } 7447 #endif 7448 7449 #if defined(FEAT_RENDER_OPTIONS) 7450 /* 'renderoptions' */ 7451 else if (varp == &p_rop) 7452 { 7453 if (!gui_mch_set_rendering_options(p_rop)) 7454 errmsg = e_invarg; 7455 } 7456 #endif 7457 7458 else if (gvarp == &p_ft) 7459 { 7460 if (!valid_filetype(*varp)) 7461 errmsg = e_invarg; 7462 else 7463 { 7464 value_changed = STRCMP(oldval, *varp) != 0; 7465 7466 // Since we check the value, there is no need to set P_INSECURE, 7467 // even when the value comes from a modeline. 7468 *value_checked = TRUE; 7469 } 7470 } 7471 7472 #ifdef FEAT_SYN_HL 7473 else if (gvarp == &p_syn) 7474 { 7475 if (!valid_filetype(*varp)) 7476 errmsg = e_invarg; 7477 else 7478 { 7479 value_changed = STRCMP(oldval, *varp) != 0; 7480 7481 // Since we check the value, there is no need to set P_INSECURE, 7482 // even when the value comes from a modeline. 7483 *value_checked = TRUE; 7484 } 7485 } 7486 #endif 7487 7488 #ifdef FEAT_TERMINAL 7489 // 'termwinkey' 7490 else if (varp == &curwin->w_p_twk) 7491 { 7492 if (*curwin->w_p_twk != NUL 7493 && string_to_key(curwin->w_p_twk, TRUE) == 0) 7494 errmsg = e_invarg; 7495 } 7496 // 'termwinsize' 7497 else if (varp == &curwin->w_p_tws) 7498 { 7499 if (*curwin->w_p_tws != NUL) 7500 { 7501 p = skipdigits(curwin->w_p_tws); 7502 if (p == curwin->w_p_tws 7503 || (*p != 'x' && *p != '*') 7504 || *skipdigits(p + 1) != NUL) 7505 errmsg = e_invarg; 7506 } 7507 } 7508 // 'termmode' 7509 else if (varp == &curwin->w_p_tmod) 7510 { 7511 if (check_opt_strings(*varp, p_tmod_values, FALSE) != OK) 7512 errmsg = e_invarg; 7513 } 7514 #endif 7515 7516 #ifdef FEAT_VARTABS 7517 /* 'varsofttabstop' */ 7518 else if (varp == &(curbuf->b_p_vsts)) 7519 { 7520 char_u *cp; 7521 7522 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) 7523 { 7524 if (curbuf->b_p_vsts_array) 7525 { 7526 vim_free(curbuf->b_p_vsts_array); 7527 curbuf->b_p_vsts_array = 0; 7528 } 7529 } 7530 else 7531 { 7532 for (cp = *varp; *cp; ++cp) 7533 { 7534 if (vim_isdigit(*cp)) 7535 continue; 7536 if (*cp == ',' && cp > *varp && *(cp-1) != ',') 7537 continue; 7538 errmsg = e_invarg; 7539 break; 7540 } 7541 if (errmsg == NULL) 7542 { 7543 int *oldarray = curbuf->b_p_vsts_array; 7544 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array))) 7545 { 7546 if (oldarray) 7547 vim_free(oldarray); 7548 } 7549 else 7550 errmsg = e_invarg; 7551 } 7552 } 7553 } 7554 7555 /* 'vartabstop' */ 7556 else if (varp == &(curbuf->b_p_vts)) 7557 { 7558 char_u *cp; 7559 7560 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) 7561 { 7562 if (curbuf->b_p_vts_array) 7563 { 7564 vim_free(curbuf->b_p_vts_array); 7565 curbuf->b_p_vts_array = NULL; 7566 } 7567 } 7568 else 7569 { 7570 for (cp = *varp; *cp; ++cp) 7571 { 7572 if (vim_isdigit(*cp)) 7573 continue; 7574 if (*cp == ',' && cp > *varp && *(cp-1) != ',') 7575 continue; 7576 errmsg = e_invarg; 7577 break; 7578 } 7579 if (errmsg == NULL) 7580 { 7581 int *oldarray = curbuf->b_p_vts_array; 7582 if (tabstop_set(*varp, &(curbuf->b_p_vts_array))) 7583 { 7584 if (oldarray) 7585 vim_free(oldarray); 7586 #ifdef FEAT_FOLDING 7587 if (foldmethodIsIndent(curwin)) 7588 foldUpdateAll(curwin); 7589 #endif /* FEAT_FOLDING */ 7590 } 7591 else 7592 errmsg = e_invarg; 7593 } 7594 } 7595 } 7596 #endif 7597 7598 /* Options that are a list of flags. */ 7599 else 7600 { 7601 p = NULL; 7602 if (varp == &p_ww) /* 'whichwrap' */ 7603 p = (char_u *)WW_ALL; 7604 if (varp == &p_shm) /* 'shortmess' */ 7605 p = (char_u *)SHM_ALL; 7606 else if (varp == &(p_cpo)) /* 'cpoptions' */ 7607 p = (char_u *)CPO_ALL; 7608 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */ 7609 p = (char_u *)FO_ALL; 7610 #ifdef FEAT_CONCEAL 7611 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */ 7612 p = (char_u *)COCU_ALL; 7613 #endif 7614 else if (varp == &p_mouse) /* 'mouse' */ 7615 { 7616 #ifdef FEAT_MOUSE 7617 p = (char_u *)MOUSE_ALL; 7618 #else 7619 if (*p_mouse != NUL) 7620 errmsg = N_("E538: No mouse support"); 7621 #endif 7622 } 7623 #if defined(FEAT_GUI) 7624 else if (varp == &p_go) /* 'guioptions' */ 7625 p = (char_u *)GO_ALL; 7626 #endif 7627 if (p != NULL) 7628 { 7629 for (s = *varp; *s; ++s) 7630 if (vim_strchr(p, *s) == NULL) 7631 { 7632 errmsg = illegal_char(errbuf, *s); 7633 break; 7634 } 7635 } 7636 } 7637 7638 /* 7639 * If error detected, restore the previous value. 7640 */ 7641 if (errmsg != NULL) 7642 { 7643 if (new_value_alloced) 7644 free_string_option(*varp); 7645 *varp = oldval; 7646 /* 7647 * When resetting some values, need to act on it. 7648 */ 7649 if (did_chartab) 7650 (void)init_chartab(); 7651 if (varp == &p_hl) 7652 (void)highlight_changed(); 7653 } 7654 else 7655 { 7656 #ifdef FEAT_EVAL 7657 /* Remember where the option was set. */ 7658 set_option_sctx_idx(opt_idx, opt_flags, current_sctx); 7659 #endif 7660 /* 7661 * Free string options that are in allocated memory. 7662 * Use "free_oldval", because recursiveness may change the flags under 7663 * our fingers (esp. init_highlight()). 7664 */ 7665 if (free_oldval) 7666 free_string_option(oldval); 7667 if (new_value_alloced) 7668 options[opt_idx].flags |= P_ALLOCED; 7669 else 7670 options[opt_idx].flags &= ~P_ALLOCED; 7671 7672 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 7673 && ((int)options[opt_idx].indir & PV_BOTH)) 7674 { 7675 /* global option with local value set to use global value; free 7676 * the local value and make it empty */ 7677 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL); 7678 free_string_option(*(char_u **)p); 7679 *(char_u **)p = empty_option; 7680 } 7681 7682 /* May set global value for local option. */ 7683 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL) 7684 set_string_option_global(opt_idx, varp); 7685 7686 /* 7687 * Trigger the autocommand only after setting the flags. 7688 */ 7689 #ifdef FEAT_SYN_HL 7690 /* When 'syntax' is set, load the syntax of that name */ 7691 if (varp == &(curbuf->b_p_syn)) 7692 { 7693 static int syn_recursive = 0; 7694 7695 ++syn_recursive; 7696 // Only pass TRUE for "force" when the value changed or not used 7697 // recursively, to avoid endless recurrence. 7698 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, 7699 value_changed || syn_recursive == 1, curbuf); 7700 --syn_recursive; 7701 } 7702 #endif 7703 else if (varp == &(curbuf->b_p_ft)) 7704 { 7705 /* 'filetype' is set, trigger the FileType autocommand. 7706 * Skip this when called from a modeline and the filetype was 7707 * already set to this value. */ 7708 if (!(opt_flags & OPT_MODELINE) || value_changed) 7709 { 7710 static int ft_recursive = 0; 7711 int secure_save = secure; 7712 7713 // Reset the secure flag, since the value of 'filetype' has 7714 // been checked to be safe. 7715 secure = 0; 7716 7717 ++ft_recursive; 7718 did_filetype = TRUE; 7719 // Only pass TRUE for "force" when the value changed or not 7720 // used recursively, to avoid endless recurrence. 7721 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname, 7722 value_changed || ft_recursive == 1, curbuf); 7723 --ft_recursive; 7724 /* Just in case the old "curbuf" is now invalid. */ 7725 if (varp != &(curbuf->b_p_ft)) 7726 varp = NULL; 7727 7728 secure = secure_save; 7729 } 7730 } 7731 #ifdef FEAT_SPELL 7732 if (varp == &(curwin->w_s->b_p_spl)) 7733 { 7734 char_u fname[200]; 7735 char_u *q = curwin->w_s->b_p_spl; 7736 7737 /* Skip the first name if it is "cjk". */ 7738 if (STRNCMP(q, "cjk,", 4) == 0) 7739 q += 4; 7740 7741 /* 7742 * Source the spell/LANG.vim in 'runtimepath'. 7743 * They could set 'spellcapcheck' depending on the language. 7744 * Use the first name in 'spelllang' up to '_region' or 7745 * '.encoding'. 7746 */ 7747 for (p = q; *p != NUL; ++p) 7748 if (!ASCII_ISALNUM(*p) && *p != '-') 7749 break; 7750 if (p > q) 7751 { 7752 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q); 7753 source_runtime(fname, DIP_ALL); 7754 } 7755 } 7756 #endif 7757 } 7758 7759 #ifdef FEAT_MOUSE 7760 if (varp == &p_mouse) 7761 { 7762 # ifdef FEAT_MOUSE_TTY 7763 if (*p_mouse == NUL) 7764 mch_setmouse(FALSE); /* switch mouse off */ 7765 else 7766 # endif 7767 setmouse(); /* in case 'mouse' changed */ 7768 } 7769 #endif 7770 7771 if (curwin->w_curswant != MAXCOL 7772 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) 7773 curwin->w_set_curswant = TRUE; 7774 7775 #ifdef FEAT_GUI 7776 /* check redraw when it's not a GUI option or the GUI is active. */ 7777 if (!redraw_gui_only || gui.in_use) 7778 #endif 7779 check_redraw(options[opt_idx].flags); 7780 7781 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) 7782 if (did_swaptcap) 7783 { 7784 set_termname((char_u *)"win32"); 7785 init_highlight(TRUE, FALSE); 7786 } 7787 #endif 7788 7789 return errmsg; 7790 } 7791 7792 #if defined(FEAT_SYN_HL) || defined(PROTO) 7793 /* 7794 * Simple int comparison function for use with qsort() 7795 */ 7796 static int 7797 int_cmp(const void *a, const void *b) 7798 { 7799 return *(const int *)a - *(const int *)b; 7800 } 7801 7802 /* 7803 * Handle setting 'colorcolumn' or 'textwidth' in window "wp". 7804 * Returns error message, NULL if it's OK. 7805 */ 7806 char * 7807 check_colorcolumn(win_T *wp) 7808 { 7809 char_u *s; 7810 int col; 7811 int count = 0; 7812 int color_cols[256]; 7813 int i; 7814 int j = 0; 7815 7816 if (wp->w_buffer == NULL) 7817 return NULL; /* buffer was closed */ 7818 7819 for (s = wp->w_p_cc; *s != NUL && count < 255;) 7820 { 7821 if (*s == '-' || *s == '+') 7822 { 7823 /* -N and +N: add to 'textwidth' */ 7824 col = (*s == '-') ? -1 : 1; 7825 ++s; 7826 if (!VIM_ISDIGIT(*s)) 7827 return e_invarg; 7828 col = col * getdigits(&s); 7829 if (wp->w_buffer->b_p_tw == 0) 7830 goto skip; /* 'textwidth' not set, skip this item */ 7831 col += wp->w_buffer->b_p_tw; 7832 if (col < 0) 7833 goto skip; 7834 } 7835 else if (VIM_ISDIGIT(*s)) 7836 col = getdigits(&s); 7837 else 7838 return e_invarg; 7839 color_cols[count++] = col - 1; /* 1-based to 0-based */ 7840 skip: 7841 if (*s == NUL) 7842 break; 7843 if (*s != ',') 7844 return e_invarg; 7845 if (*++s == NUL) 7846 return e_invarg; /* illegal trailing comma as in "set cc=80," */ 7847 } 7848 7849 vim_free(wp->w_p_cc_cols); 7850 if (count == 0) 7851 wp->w_p_cc_cols = NULL; 7852 else 7853 { 7854 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1)); 7855 if (wp->w_p_cc_cols != NULL) 7856 { 7857 /* sort the columns for faster usage on screen redraw inside 7858 * win_line() */ 7859 qsort(color_cols, count, sizeof(int), int_cmp); 7860 7861 for (i = 0; i < count; ++i) 7862 /* skip duplicates */ 7863 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i]) 7864 wp->w_p_cc_cols[j++] = color_cols[i]; 7865 wp->w_p_cc_cols[j] = -1; /* end marker */ 7866 } 7867 } 7868 7869 return NULL; /* no error */ 7870 } 7871 #endif 7872 7873 /* 7874 * Handle setting 'listchars' or 'fillchars'. 7875 * Returns error message, NULL if it's OK. 7876 */ 7877 static char * 7878 set_chars_option(char_u **varp) 7879 { 7880 int round, i, len, entries; 7881 char_u *p, *s; 7882 int c1 = 0, c2 = 0, c3 = 0; 7883 struct charstab 7884 { 7885 int *cp; 7886 char *name; 7887 }; 7888 static struct charstab filltab[] = 7889 { 7890 {&fill_stl, "stl"}, 7891 {&fill_stlnc, "stlnc"}, 7892 {&fill_vert, "vert"}, 7893 {&fill_fold, "fold"}, 7894 {&fill_diff, "diff"}, 7895 }; 7896 static struct charstab lcstab[] = 7897 { 7898 {&lcs_eol, "eol"}, 7899 {&lcs_ext, "extends"}, 7900 {&lcs_nbsp, "nbsp"}, 7901 {&lcs_prec, "precedes"}, 7902 {&lcs_space, "space"}, 7903 {&lcs_tab2, "tab"}, 7904 {&lcs_trail, "trail"}, 7905 #ifdef FEAT_CONCEAL 7906 {&lcs_conceal, "conceal"}, 7907 #else 7908 {NULL, "conceal"}, 7909 #endif 7910 }; 7911 struct charstab *tab; 7912 7913 if (varp == &p_lcs) 7914 { 7915 tab = lcstab; 7916 entries = sizeof(lcstab) / sizeof(struct charstab); 7917 } 7918 else 7919 { 7920 tab = filltab; 7921 entries = sizeof(filltab) / sizeof(struct charstab); 7922 } 7923 7924 /* first round: check for valid value, second round: assign values */ 7925 for (round = 0; round <= 1; ++round) 7926 { 7927 if (round > 0) 7928 { 7929 /* After checking that the value is valid: set defaults: space for 7930 * 'fillchars', NUL for 'listchars' */ 7931 for (i = 0; i < entries; ++i) 7932 if (tab[i].cp != NULL) 7933 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' '); 7934 7935 if (varp == &p_lcs) 7936 { 7937 lcs_tab1 = NUL; 7938 lcs_tab3 = NUL; 7939 } 7940 else 7941 fill_diff = '-'; 7942 } 7943 p = *varp; 7944 while (*p) 7945 { 7946 for (i = 0; i < entries; ++i) 7947 { 7948 len = (int)STRLEN(tab[i].name); 7949 if (STRNCMP(p, tab[i].name, len) == 0 7950 && p[len] == ':' 7951 && p[len + 1] != NUL) 7952 { 7953 c1 = c2 = c3 = 0; 7954 s = p + len + 1; 7955 c1 = mb_ptr2char_adv(&s); 7956 if (mb_char2cells(c1) > 1) 7957 continue; 7958 if (tab[i].cp == &lcs_tab2) 7959 { 7960 if (*s == NUL) 7961 continue; 7962 c2 = mb_ptr2char_adv(&s); 7963 if (mb_char2cells(c2) > 1) 7964 continue; 7965 if (!(*s == ',' || *s == NUL)) 7966 { 7967 c3 = mb_ptr2char_adv(&s); 7968 if (mb_char2cells(c3) > 1) 7969 continue; 7970 } 7971 } 7972 7973 if (*s == ',' || *s == NUL) 7974 { 7975 if (round) 7976 { 7977 if (tab[i].cp == &lcs_tab2) 7978 { 7979 lcs_tab1 = c1; 7980 lcs_tab2 = c2; 7981 lcs_tab3 = c3; 7982 } 7983 else if (tab[i].cp != NULL) 7984 *(tab[i].cp) = c1; 7985 7986 } 7987 p = s; 7988 break; 7989 } 7990 } 7991 } 7992 7993 if (i == entries) 7994 return e_invarg; 7995 if (*p == ',') 7996 ++p; 7997 } 7998 } 7999 8000 return NULL; /* no error */ 8001 } 8002 8003 #ifdef FEAT_STL_OPT 8004 /* 8005 * Check validity of options with the 'statusline' format. 8006 * Return error message or NULL. 8007 */ 8008 char * 8009 check_stl_option(char_u *s) 8010 { 8011 int itemcnt = 0; 8012 int groupdepth = 0; 8013 static char errbuf[80]; 8014 8015 while (*s && itemcnt < STL_MAX_ITEM) 8016 { 8017 /* Check for valid keys after % sequences */ 8018 while (*s && *s != '%') 8019 s++; 8020 if (!*s) 8021 break; 8022 s++; 8023 if (*s != '%' && *s != ')') 8024 ++itemcnt; 8025 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK) 8026 { 8027 s++; 8028 continue; 8029 } 8030 if (*s == ')') 8031 { 8032 s++; 8033 if (--groupdepth < 0) 8034 break; 8035 continue; 8036 } 8037 if (*s == '-') 8038 s++; 8039 while (VIM_ISDIGIT(*s)) 8040 s++; 8041 if (*s == STL_USER_HL) 8042 continue; 8043 if (*s == '.') 8044 { 8045 s++; 8046 while (*s && VIM_ISDIGIT(*s)) 8047 s++; 8048 } 8049 if (*s == '(') 8050 { 8051 groupdepth++; 8052 continue; 8053 } 8054 if (vim_strchr(STL_ALL, *s) == NULL) 8055 { 8056 return illegal_char(errbuf, *s); 8057 } 8058 if (*s == '{') 8059 { 8060 s++; 8061 while (*s != '}' && *s) 8062 s++; 8063 if (*s != '}') 8064 return N_("E540: Unclosed expression sequence"); 8065 } 8066 } 8067 if (itemcnt >= STL_MAX_ITEM) 8068 return N_("E541: too many items"); 8069 if (groupdepth != 0) 8070 return N_("E542: unbalanced groups"); 8071 return NULL; 8072 } 8073 #endif 8074 8075 #ifdef FEAT_CLIPBOARD 8076 /* 8077 * Extract the items in the 'clipboard' option and set global values. 8078 * Return an error message or NULL for success. 8079 */ 8080 static char * 8081 check_clipboard_option(void) 8082 { 8083 int new_unnamed = 0; 8084 int new_autoselect_star = FALSE; 8085 int new_autoselect_plus = FALSE; 8086 int new_autoselectml = FALSE; 8087 int new_html = FALSE; 8088 regprog_T *new_exclude_prog = NULL; 8089 char *errmsg = NULL; 8090 char_u *p; 8091 8092 for (p = p_cb; *p != NUL; ) 8093 { 8094 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL)) 8095 { 8096 new_unnamed |= CLIP_UNNAMED; 8097 p += 7; 8098 } 8099 else if (STRNCMP(p, "unnamedplus", 11) == 0 8100 && (p[11] == ',' || p[11] == NUL)) 8101 { 8102 new_unnamed |= CLIP_UNNAMED_PLUS; 8103 p += 11; 8104 } 8105 else if (STRNCMP(p, "autoselect", 10) == 0 8106 && (p[10] == ',' || p[10] == NUL)) 8107 { 8108 new_autoselect_star = TRUE; 8109 p += 10; 8110 } 8111 else if (STRNCMP(p, "autoselectplus", 14) == 0 8112 && (p[14] == ',' || p[14] == NUL)) 8113 { 8114 new_autoselect_plus = TRUE; 8115 p += 14; 8116 } 8117 else if (STRNCMP(p, "autoselectml", 12) == 0 8118 && (p[12] == ',' || p[12] == NUL)) 8119 { 8120 new_autoselectml = TRUE; 8121 p += 12; 8122 } 8123 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL)) 8124 { 8125 new_html = TRUE; 8126 p += 4; 8127 } 8128 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL) 8129 { 8130 p += 8; 8131 new_exclude_prog = vim_regcomp(p, RE_MAGIC); 8132 if (new_exclude_prog == NULL) 8133 errmsg = e_invarg; 8134 break; 8135 } 8136 else 8137 { 8138 errmsg = e_invarg; 8139 break; 8140 } 8141 if (*p == ',') 8142 ++p; 8143 } 8144 if (errmsg == NULL) 8145 { 8146 clip_unnamed = new_unnamed; 8147 clip_autoselect_star = new_autoselect_star; 8148 clip_autoselect_plus = new_autoselect_plus; 8149 clip_autoselectml = new_autoselectml; 8150 clip_html = new_html; 8151 vim_regfree(clip_exclude_prog); 8152 clip_exclude_prog = new_exclude_prog; 8153 #ifdef FEAT_GUI_GTK 8154 if (gui.in_use) 8155 { 8156 gui_gtk_set_selection_targets(); 8157 gui_gtk_set_dnd_targets(); 8158 } 8159 #endif 8160 } 8161 else 8162 vim_regfree(new_exclude_prog); 8163 8164 return errmsg; 8165 } 8166 #endif 8167 8168 #ifdef FEAT_SPELL 8169 /* 8170 * Handle side effects of setting 'spell'. 8171 * Return an error message or NULL for success. 8172 */ 8173 static char * 8174 did_set_spell_option(int is_spellfile) 8175 { 8176 char *errmsg = NULL; 8177 win_T *wp; 8178 int l; 8179 8180 if (is_spellfile) 8181 { 8182 l = (int)STRLEN(curwin->w_s->b_p_spf); 8183 if (l > 0 && (l < 4 8184 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0)) 8185 errmsg = e_invarg; 8186 } 8187 8188 if (errmsg == NULL) 8189 { 8190 FOR_ALL_WINDOWS(wp) 8191 if (wp->w_buffer == curbuf && wp->w_p_spell) 8192 { 8193 errmsg = did_set_spelllang(wp); 8194 break; 8195 } 8196 } 8197 return errmsg; 8198 } 8199 8200 /* 8201 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'. 8202 * Return error message when failed, NULL when OK. 8203 */ 8204 static char * 8205 compile_cap_prog(synblock_T *synblock) 8206 { 8207 regprog_T *rp = synblock->b_cap_prog; 8208 char_u *re; 8209 8210 if (*synblock->b_p_spc == NUL) 8211 synblock->b_cap_prog = NULL; 8212 else 8213 { 8214 /* Prepend a ^ so that we only match at one column */ 8215 re = concat_str((char_u *)"^", synblock->b_p_spc); 8216 if (re != NULL) 8217 { 8218 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); 8219 vim_free(re); 8220 if (synblock->b_cap_prog == NULL) 8221 { 8222 synblock->b_cap_prog = rp; /* restore the previous program */ 8223 return e_invarg; 8224 } 8225 } 8226 } 8227 8228 vim_regfree(rp); 8229 return NULL; 8230 } 8231 #endif 8232 8233 #if defined(FEAT_EVAL) || defined(PROTO) 8234 /* 8235 * Set the script_ctx for an option, taking care of setting the buffer- or 8236 * window-local value. 8237 */ 8238 static void 8239 set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx) 8240 { 8241 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; 8242 int indir = (int)options[opt_idx].indir; 8243 sctx_T new_script_ctx = script_ctx; 8244 8245 new_script_ctx.sc_lnum += sourcing_lnum; 8246 8247 /* Remember where the option was set. For local options need to do that 8248 * in the buffer or window structure. */ 8249 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) 8250 options[opt_idx].script_ctx = new_script_ctx; 8251 if (both || (opt_flags & OPT_LOCAL)) 8252 { 8253 if (indir & PV_BUF) 8254 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx; 8255 else if (indir & PV_WIN) 8256 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx; 8257 } 8258 } 8259 8260 /* 8261 * Set the script_ctx for a termcap option. 8262 * "name" must be the two character code, e.g. "RV". 8263 * When "name" is NULL use "opt_idx". 8264 */ 8265 void 8266 set_term_option_sctx_idx(char *name, int opt_idx) 8267 { 8268 char_u buf[5]; 8269 int idx; 8270 8271 if (name == NULL) 8272 idx = opt_idx; 8273 else 8274 { 8275 buf[0] = 't'; 8276 buf[1] = '_'; 8277 buf[2] = name[0]; 8278 buf[3] = name[1]; 8279 buf[4] = 0; 8280 idx = findoption(buf); 8281 } 8282 if (idx >= 0) 8283 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx); 8284 } 8285 #endif 8286 8287 /* 8288 * Set the value of a boolean option, and take care of side effects. 8289 * Returns NULL for success, or an error message for an error. 8290 */ 8291 static char * 8292 set_bool_option( 8293 int opt_idx, /* index in options[] table */ 8294 char_u *varp, /* pointer to the option variable */ 8295 int value, /* new value */ 8296 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ 8297 { 8298 int old_value = *(int *)varp; 8299 8300 /* Disallow changing some options from secure mode */ 8301 if ((secure 8302 #ifdef HAVE_SANDBOX 8303 || sandbox != 0 8304 #endif 8305 ) && (options[opt_idx].flags & P_SECURE)) 8306 return e_secure; 8307 8308 *(int *)varp = value; /* set the new value */ 8309 #ifdef FEAT_EVAL 8310 /* Remember where the option was set. */ 8311 set_option_sctx_idx(opt_idx, opt_flags, current_sctx); 8312 #endif 8313 8314 #ifdef FEAT_GUI 8315 need_mouse_correct = TRUE; 8316 #endif 8317 8318 /* May set global value for local option. */ 8319 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) 8320 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value; 8321 8322 /* 8323 * Handle side effects of changing a bool option. 8324 */ 8325 8326 /* 'compatible' */ 8327 if ((int *)varp == &p_cp) 8328 { 8329 compatible_set(); 8330 } 8331 8332 #ifdef FEAT_LANGMAP 8333 if ((int *)varp == &p_lrm) 8334 /* 'langremap' -> !'langnoremap' */ 8335 p_lnr = !p_lrm; 8336 else if ((int *)varp == &p_lnr) 8337 /* 'langnoremap' -> !'langremap' */ 8338 p_lrm = !p_lnr; 8339 #endif 8340 8341 #ifdef FEAT_SYN_HL 8342 else if ((int *)varp == &curwin->w_p_cul && !value && old_value) 8343 reset_cursorline(); 8344 #endif 8345 8346 #ifdef FEAT_PERSISTENT_UNDO 8347 /* 'undofile' */ 8348 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf) 8349 { 8350 /* Only take action when the option was set. When reset we do not 8351 * delete the undo file, the option may be set again without making 8352 * any changes in between. */ 8353 if (curbuf->b_p_udf || p_udf) 8354 { 8355 char_u hash[UNDO_HASH_SIZE]; 8356 buf_T *save_curbuf = curbuf; 8357 8358 FOR_ALL_BUFFERS(curbuf) 8359 { 8360 /* When 'undofile' is set globally: for every buffer, otherwise 8361 * only for the current buffer: Try to read in the undofile, 8362 * if one exists, the buffer wasn't changed and the buffer was 8363 * loaded */ 8364 if ((curbuf == save_curbuf 8365 || (opt_flags & OPT_GLOBAL) || opt_flags == 0) 8366 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL) 8367 { 8368 u_compute_hash(hash); 8369 u_read_undo(NULL, hash, curbuf->b_fname); 8370 } 8371 } 8372 curbuf = save_curbuf; 8373 } 8374 } 8375 #endif 8376 8377 else if ((int *)varp == &curbuf->b_p_ro) 8378 { 8379 /* when 'readonly' is reset globally, also reset readonlymode */ 8380 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0) 8381 readonlymode = FALSE; 8382 8383 /* when 'readonly' is set may give W10 again */ 8384 if (curbuf->b_p_ro) 8385 curbuf->b_did_warn = FALSE; 8386 8387 #ifdef FEAT_TITLE 8388 redraw_titles(); 8389 #endif 8390 } 8391 8392 #ifdef FEAT_GUI 8393 else if ((int *)varp == &p_mh) 8394 { 8395 if (!p_mh) 8396 gui_mch_mousehide(FALSE); 8397 } 8398 #endif 8399 8400 /* when 'modifiable' is changed, redraw the window title */ 8401 else if ((int *)varp == &curbuf->b_p_ma) 8402 { 8403 # ifdef FEAT_TERMINAL 8404 /* Cannot set 'modifiable' when in Terminal mode. */ 8405 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf) 8406 && curbuf->b_term != NULL && !term_is_finished(curbuf)))) 8407 { 8408 curbuf->b_p_ma = FALSE; 8409 return N_("E946: Cannot make a terminal with running job modifiable"); 8410 } 8411 # endif 8412 # ifdef FEAT_TITLE 8413 redraw_titles(); 8414 # endif 8415 } 8416 #ifdef FEAT_TITLE 8417 /* when 'endofline' is changed, redraw the window title */ 8418 else if ((int *)varp == &curbuf->b_p_eol) 8419 { 8420 redraw_titles(); 8421 } 8422 /* when 'fixeol' is changed, redraw the window title */ 8423 else if ((int *)varp == &curbuf->b_p_fixeol) 8424 { 8425 redraw_titles(); 8426 } 8427 /* when 'bomb' is changed, redraw the window title and tab page text */ 8428 else if ((int *)varp == &curbuf->b_p_bomb) 8429 { 8430 redraw_titles(); 8431 } 8432 #endif 8433 8434 /* when 'bin' is set also set some other options */ 8435 else if ((int *)varp == &curbuf->b_p_bin) 8436 { 8437 set_options_bin(old_value, curbuf->b_p_bin, opt_flags); 8438 #ifdef FEAT_TITLE 8439 redraw_titles(); 8440 #endif 8441 } 8442 8443 /* when 'buflisted' changes, trigger autocommands */ 8444 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl) 8445 { 8446 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE, 8447 NULL, NULL, TRUE, curbuf); 8448 } 8449 8450 /* when 'swf' is set, create swapfile, when reset remove swapfile */ 8451 else if ((int *)varp == &curbuf->b_p_swf) 8452 { 8453 if (curbuf->b_p_swf && p_uc) 8454 ml_open_file(curbuf); /* create the swap file */ 8455 else 8456 /* no need to reset curbuf->b_may_swap, ml_open_file() will check 8457 * buf->b_p_swf */ 8458 mf_close_file(curbuf, TRUE); /* remove the swap file */ 8459 } 8460 8461 /* when 'terse' is set change 'shortmess' */ 8462 else if ((int *)varp == &p_terse) 8463 { 8464 char_u *p; 8465 8466 p = vim_strchr(p_shm, SHM_SEARCH); 8467 8468 /* insert 's' in p_shm */ 8469 if (p_terse && p == NULL) 8470 { 8471 STRCPY(IObuff, p_shm); 8472 STRCAT(IObuff, "s"); 8473 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0); 8474 } 8475 /* remove 's' from p_shm */ 8476 else if (!p_terse && p != NULL) 8477 STRMOVE(p, p + 1); 8478 } 8479 8480 /* when 'paste' is set or reset also change other options */ 8481 else if ((int *)varp == &p_paste) 8482 { 8483 paste_option_changed(); 8484 } 8485 8486 /* when 'insertmode' is set from an autocommand need to do work here */ 8487 else if ((int *)varp == &p_im) 8488 { 8489 if (p_im) 8490 { 8491 if ((State & INSERT) == 0) 8492 need_start_insertmode = TRUE; 8493 stop_insert_mode = FALSE; 8494 } 8495 /* only reset if it was set previously */ 8496 else if (old_value) 8497 { 8498 need_start_insertmode = FALSE; 8499 stop_insert_mode = TRUE; 8500 if (restart_edit != 0 && mode_displayed) 8501 clear_cmdline = TRUE; /* remove "(insert)" */ 8502 restart_edit = 0; 8503 } 8504 } 8505 8506 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */ 8507 else if ((int *)varp == &p_ic && p_hls) 8508 { 8509 redraw_all_later(SOME_VALID); 8510 } 8511 8512 #ifdef FEAT_SEARCH_EXTRA 8513 /* when 'hlsearch' is set or reset: reset no_hlsearch */ 8514 else if ((int *)varp == &p_hls) 8515 { 8516 set_no_hlsearch(FALSE); 8517 } 8518 #endif 8519 8520 /* when 'scrollbind' is set: snapshot the current position to avoid a jump 8521 * at the end of normal_cmd() */ 8522 else if ((int *)varp == &curwin->w_p_scb) 8523 { 8524 if (curwin->w_p_scb) 8525 { 8526 do_check_scrollbind(FALSE); 8527 curwin->w_scbind_pos = curwin->w_topline; 8528 } 8529 } 8530 8531 #if defined(FEAT_QUICKFIX) 8532 /* There can be only one window with 'previewwindow' set. */ 8533 else if ((int *)varp == &curwin->w_p_pvw) 8534 { 8535 if (curwin->w_p_pvw) 8536 { 8537 win_T *win; 8538 8539 FOR_ALL_WINDOWS(win) 8540 if (win->w_p_pvw && win != curwin) 8541 { 8542 curwin->w_p_pvw = FALSE; 8543 return N_("E590: A preview window already exists"); 8544 } 8545 } 8546 } 8547 #endif 8548 8549 /* when 'textmode' is set or reset also change 'fileformat' */ 8550 else if ((int *)varp == &curbuf->b_p_tx) 8551 { 8552 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags); 8553 } 8554 8555 /* when 'textauto' is set or reset also change 'fileformats' */ 8556 else if ((int *)varp == &p_ta) 8557 set_string_option_direct((char_u *)"ffs", -1, 8558 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"", 8559 OPT_FREE | opt_flags, 0); 8560 8561 /* 8562 * When 'lisp' option changes include/exclude '-' in 8563 * keyword characters. 8564 */ 8565 #ifdef FEAT_LISP 8566 else if (varp == (char_u *)&(curbuf->b_p_lisp)) 8567 { 8568 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */ 8569 } 8570 #endif 8571 8572 #ifdef FEAT_TITLE 8573 /* when 'title' changed, may need to change the title; same for 'icon' */ 8574 else if ((int *)varp == &p_title || (int *)varp == &p_icon) 8575 { 8576 did_set_title(); 8577 } 8578 #endif 8579 8580 else if ((int *)varp == &curbuf->b_changed) 8581 { 8582 if (!value) 8583 save_file_ff(curbuf); /* Buffer is unchanged */ 8584 #ifdef FEAT_TITLE 8585 redraw_titles(); 8586 #endif 8587 modified_was_set = value; 8588 } 8589 8590 #ifdef BACKSLASH_IN_FILENAME 8591 else if ((int *)varp == &p_ssl) 8592 { 8593 if (p_ssl) 8594 { 8595 psepc = '/'; 8596 psepcN = '\\'; 8597 pseps[0] = '/'; 8598 } 8599 else 8600 { 8601 psepc = '\\'; 8602 psepcN = '/'; 8603 pseps[0] = '\\'; 8604 } 8605 8606 /* need to adjust the file name arguments and buffer names. */ 8607 buflist_slash_adjust(); 8608 alist_slash_adjust(); 8609 # ifdef FEAT_EVAL 8610 scriptnames_slash_adjust(); 8611 # endif 8612 } 8613 #endif 8614 8615 /* If 'wrap' is set, set w_leftcol to zero. */ 8616 else if ((int *)varp == &curwin->w_p_wrap) 8617 { 8618 if (curwin->w_p_wrap) 8619 curwin->w_leftcol = 0; 8620 } 8621 8622 else if ((int *)varp == &p_ea) 8623 { 8624 if (p_ea && !old_value) 8625 win_equal(curwin, FALSE, 0); 8626 } 8627 8628 else if ((int *)varp == &p_wiv) 8629 { 8630 /* 8631 * When 'weirdinvert' changed, set/reset 't_xs'. 8632 * Then set 'weirdinvert' according to value of 't_xs'. 8633 */ 8634 if (p_wiv && !old_value) 8635 T_XS = (char_u *)"y"; 8636 else if (!p_wiv && old_value) 8637 T_XS = empty_option; 8638 p_wiv = (*T_XS != NUL); 8639 } 8640 8641 #ifdef FEAT_BEVAL_GUI 8642 else if ((int *)varp == &p_beval) 8643 { 8644 if (!balloonEvalForTerm) 8645 { 8646 if (p_beval && !old_value) 8647 gui_mch_enable_beval_area(balloonEval); 8648 else if (!p_beval && old_value) 8649 gui_mch_disable_beval_area(balloonEval); 8650 } 8651 } 8652 #endif 8653 #ifdef FEAT_BEVAL_TERM 8654 else if ((int *)varp == &p_bevalterm) 8655 { 8656 mch_bevalterm_changed(); 8657 } 8658 #endif 8659 8660 #ifdef FEAT_AUTOCHDIR 8661 else if ((int *)varp == &p_acd) 8662 { 8663 /* Change directories when the 'acd' option is set now. */ 8664 DO_AUTOCHDIR; 8665 } 8666 #endif 8667 8668 #ifdef FEAT_DIFF 8669 /* 'diff' */ 8670 else if ((int *)varp == &curwin->w_p_diff) 8671 { 8672 /* May add or remove the buffer from the list of diff buffers. */ 8673 diff_buf_adjust(curwin); 8674 # ifdef FEAT_FOLDING 8675 if (foldmethodIsDiff(curwin)) 8676 foldUpdateAll(curwin); 8677 # endif 8678 } 8679 #endif 8680 8681 #ifdef HAVE_INPUT_METHOD 8682 /* 'imdisable' */ 8683 else if ((int *)varp == &p_imdisable) 8684 { 8685 /* Only de-activate it here, it will be enabled when changing mode. */ 8686 if (p_imdisable) 8687 im_set_active(FALSE); 8688 else if (State & INSERT) 8689 /* When the option is set from an autocommand, it may need to take 8690 * effect right away. */ 8691 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); 8692 } 8693 #endif 8694 8695 #ifdef FEAT_SPELL 8696 /* 'spell' */ 8697 else if ((int *)varp == &curwin->w_p_spell) 8698 { 8699 if (curwin->w_p_spell) 8700 { 8701 char *errmsg = did_set_spelllang(curwin); 8702 8703 if (errmsg != NULL) 8704 emsg(_(errmsg)); 8705 } 8706 } 8707 #endif 8708 8709 #ifdef FEAT_FKMAP 8710 else if ((int *)varp == &p_altkeymap) 8711 { 8712 if (old_value != p_altkeymap) 8713 { 8714 if (!p_altkeymap) 8715 { 8716 p_hkmap = p_fkmap; 8717 p_fkmap = 0; 8718 } 8719 else 8720 { 8721 p_fkmap = p_hkmap; 8722 p_hkmap = 0; 8723 } 8724 (void)init_chartab(); 8725 } 8726 } 8727 8728 /* 8729 * In case some second language keymapping options have changed, check 8730 * and correct the setting in a consistent way. 8731 */ 8732 8733 /* 8734 * If hkmap or fkmap are set, reset Arabic keymapping. 8735 */ 8736 if ((p_hkmap || p_fkmap) && p_altkeymap) 8737 { 8738 p_altkeymap = p_fkmap; 8739 # ifdef FEAT_ARABIC 8740 curwin->w_p_arab = FALSE; 8741 # endif 8742 (void)init_chartab(); 8743 } 8744 8745 /* 8746 * If hkmap set, reset Farsi keymapping. 8747 */ 8748 if (p_hkmap && p_altkeymap) 8749 { 8750 p_altkeymap = 0; 8751 p_fkmap = 0; 8752 # ifdef FEAT_ARABIC 8753 curwin->w_p_arab = FALSE; 8754 # endif 8755 (void)init_chartab(); 8756 } 8757 8758 /* 8759 * If fkmap set, reset Hebrew keymapping. 8760 */ 8761 if (p_fkmap && !p_altkeymap) 8762 { 8763 p_altkeymap = 1; 8764 p_hkmap = 0; 8765 # ifdef FEAT_ARABIC 8766 curwin->w_p_arab = FALSE; 8767 # endif 8768 (void)init_chartab(); 8769 } 8770 #endif 8771 8772 #ifdef FEAT_ARABIC 8773 if ((int *)varp == &curwin->w_p_arab) 8774 { 8775 if (curwin->w_p_arab) 8776 { 8777 /* 8778 * 'arabic' is set, handle various sub-settings. 8779 */ 8780 if (!p_tbidi) 8781 { 8782 /* set rightleft mode */ 8783 if (!curwin->w_p_rl) 8784 { 8785 curwin->w_p_rl = TRUE; 8786 changed_window_setting(); 8787 } 8788 8789 /* Enable Arabic shaping (major part of what Arabic requires) */ 8790 if (!p_arshape) 8791 { 8792 p_arshape = TRUE; 8793 redraw_later_clear(); 8794 } 8795 } 8796 8797 /* Arabic requires a utf-8 encoding, inform the user if its not 8798 * set. */ 8799 if (STRCMP(p_enc, "utf-8") != 0) 8800 { 8801 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); 8802 8803 msg_source(HL_ATTR(HLF_W)); 8804 msg_attr(_(w_arabic), HL_ATTR(HLF_W)); 8805 #ifdef FEAT_EVAL 8806 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1); 8807 #endif 8808 } 8809 8810 /* set 'delcombine' */ 8811 p_deco = TRUE; 8812 8813 # ifdef FEAT_KEYMAP 8814 /* Force-set the necessary keymap for arabic */ 8815 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", 8816 OPT_LOCAL); 8817 # endif 8818 # ifdef FEAT_FKMAP 8819 p_altkeymap = 0; 8820 p_hkmap = 0; 8821 p_fkmap = 0; 8822 (void)init_chartab(); 8823 # endif 8824 } 8825 else 8826 { 8827 /* 8828 * 'arabic' is reset, handle various sub-settings. 8829 */ 8830 if (!p_tbidi) 8831 { 8832 /* reset rightleft mode */ 8833 if (curwin->w_p_rl) 8834 { 8835 curwin->w_p_rl = FALSE; 8836 changed_window_setting(); 8837 } 8838 8839 /* 'arabicshape' isn't reset, it is a global option and 8840 * another window may still need it "on". */ 8841 } 8842 8843 /* 'delcombine' isn't reset, it is a global option and another 8844 * window may still want it "on". */ 8845 8846 # ifdef FEAT_KEYMAP 8847 /* Revert to the default keymap */ 8848 curbuf->b_p_iminsert = B_IMODE_NONE; 8849 curbuf->b_p_imsearch = B_IMODE_USE_INSERT; 8850 # endif 8851 } 8852 } 8853 8854 #endif 8855 8856 #ifdef FEAT_TERMGUICOLORS 8857 /* 'termguicolors' */ 8858 else if ((int *)varp == &p_tgc) 8859 { 8860 # ifdef FEAT_VTP 8861 /* Do not turn on 'tgc' when 24-bit colors are not supported. */ 8862 if (!has_vtp_working()) 8863 { 8864 p_tgc = 0; 8865 return N_("E954: 24-bit colors are not supported on this environment"); 8866 } 8867 if (is_term_win32()) 8868 swap_tcap(); 8869 # endif 8870 # ifdef FEAT_GUI 8871 if (!gui.in_use && !gui.starting) 8872 # endif 8873 highlight_gui_started(); 8874 # ifdef FEAT_VTP 8875 /* reset t_Co */ 8876 if (is_term_win32()) 8877 { 8878 control_console_color_rgb(); 8879 set_termname(T_NAME); 8880 init_highlight(TRUE, FALSE); 8881 } 8882 # endif 8883 } 8884 #endif 8885 8886 /* 8887 * End of handling side effects for bool options. 8888 */ 8889 8890 /* after handling side effects, call autocommand */ 8891 8892 options[opt_idx].flags |= P_WAS_SET; 8893 8894 #if defined(FEAT_EVAL) 8895 // Don't do this while starting up or recursively. 8896 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL) 8897 { 8898 char_u buf_old[2], buf_new[2], buf_type[7]; 8899 8900 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE); 8901 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE); 8902 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global"); 8903 set_vim_var_string(VV_OPTION_NEW, buf_new, -1); 8904 set_vim_var_string(VV_OPTION_OLD, buf_old, -1); 8905 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); 8906 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL); 8907 reset_v_option_vars(); 8908 } 8909 #endif 8910 8911 comp_col(); /* in case 'ruler' or 'showcmd' changed */ 8912 if (curwin->w_curswant != MAXCOL 8913 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) 8914 curwin->w_set_curswant = TRUE; 8915 check_redraw(options[opt_idx].flags); 8916 8917 return NULL; 8918 } 8919 8920 /* 8921 * Set the value of a number option, and take care of side effects. 8922 * Returns NULL for success, or an error message for an error. 8923 */ 8924 static char * 8925 set_num_option( 8926 int opt_idx, /* index in options[] table */ 8927 char_u *varp, /* pointer to the option variable */ 8928 long value, /* new value */ 8929 char *errbuf, /* buffer for error messages */ 8930 size_t errbuflen, /* length of "errbuf" */ 8931 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and 8932 OPT_MODELINE */ 8933 { 8934 char *errmsg = NULL; 8935 long old_value = *(long *)varp; 8936 long old_Rows = Rows; /* remember old Rows */ 8937 long old_Columns = Columns; /* remember old Columns */ 8938 long *pp = (long *)varp; 8939 8940 /* Disallow changing some options from secure mode. */ 8941 if ((secure 8942 #ifdef HAVE_SANDBOX 8943 || sandbox != 0 8944 #endif 8945 ) && (options[opt_idx].flags & P_SECURE)) 8946 return e_secure; 8947 8948 *pp = value; 8949 #ifdef FEAT_EVAL 8950 /* Remember where the option was set. */ 8951 set_option_sctx_idx(opt_idx, opt_flags, current_sctx); 8952 #endif 8953 #ifdef FEAT_GUI 8954 need_mouse_correct = TRUE; 8955 #endif 8956 8957 if (curbuf->b_p_sw < 0) 8958 { 8959 errmsg = e_positive; 8960 #ifdef FEAT_VARTABS 8961 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use. 8962 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0 8963 ? tabstop_first(curbuf->b_p_vts_array) 8964 : curbuf->b_p_ts; 8965 #else 8966 curbuf->b_p_sw = curbuf->b_p_ts; 8967 #endif 8968 } 8969 8970 /* 8971 * Number options that need some action when changed 8972 */ 8973 if (pp == &p_wh || pp == &p_hh) 8974 { 8975 // 'winheight' and 'helpheight' 8976 if (p_wh < 1) 8977 { 8978 errmsg = e_positive; 8979 p_wh = 1; 8980 } 8981 if (p_wmh > p_wh) 8982 { 8983 errmsg = e_winheight; 8984 p_wh = p_wmh; 8985 } 8986 if (p_hh < 0) 8987 { 8988 errmsg = e_positive; 8989 p_hh = 0; 8990 } 8991 8992 /* Change window height NOW */ 8993 if (!ONE_WINDOW) 8994 { 8995 if (pp == &p_wh && curwin->w_height < p_wh) 8996 win_setheight((int)p_wh); 8997 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) 8998 win_setheight((int)p_hh); 8999 } 9000 } 9001 else if (pp == &p_wmh) 9002 { 9003 // 'winminheight' 9004 if (p_wmh < 0) 9005 { 9006 errmsg = e_positive; 9007 p_wmh = 0; 9008 } 9009 if (p_wmh > p_wh) 9010 { 9011 errmsg = e_winheight; 9012 p_wmh = p_wh; 9013 } 9014 win_setminheight(); 9015 } 9016 else if (pp == &p_wiw) 9017 { 9018 // 'winwidth' 9019 if (p_wiw < 1) 9020 { 9021 errmsg = e_positive; 9022 p_wiw = 1; 9023 } 9024 if (p_wmw > p_wiw) 9025 { 9026 errmsg = e_winwidth; 9027 p_wiw = p_wmw; 9028 } 9029 9030 /* Change window width NOW */ 9031 if (!ONE_WINDOW && curwin->w_width < p_wiw) 9032 win_setwidth((int)p_wiw); 9033 } 9034 else if (pp == &p_wmw) 9035 { 9036 // 'winminwidth' 9037 if (p_wmw < 0) 9038 { 9039 errmsg = e_positive; 9040 p_wmw = 0; 9041 } 9042 if (p_wmw > p_wiw) 9043 { 9044 errmsg = e_winwidth; 9045 p_wmw = p_wiw; 9046 } 9047 win_setminwidth(); 9048 } 9049 9050 /* (re)set last window status line */ 9051 else if (pp == &p_ls) 9052 { 9053 last_status(FALSE); 9054 } 9055 9056 /* (re)set tab page line */ 9057 else if (pp == &p_stal) 9058 { 9059 shell_new_rows(); /* recompute window positions and heights */ 9060 } 9061 9062 #ifdef FEAT_GUI 9063 else if (pp == &p_linespace) 9064 { 9065 /* Recompute gui.char_height and resize the Vim window to keep the 9066 * same number of lines. */ 9067 if (gui.in_use && gui_mch_adjust_charheight() == OK) 9068 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); 9069 } 9070 #endif 9071 9072 #ifdef FEAT_FOLDING 9073 /* 'foldlevel' */ 9074 else if (pp == &curwin->w_p_fdl) 9075 { 9076 if (curwin->w_p_fdl < 0) 9077 curwin->w_p_fdl = 0; 9078 newFoldLevel(); 9079 } 9080 9081 /* 'foldminlines' */ 9082 else if (pp == &curwin->w_p_fml) 9083 { 9084 foldUpdateAll(curwin); 9085 } 9086 9087 /* 'foldnestmax' */ 9088 else if (pp == &curwin->w_p_fdn) 9089 { 9090 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) 9091 foldUpdateAll(curwin); 9092 } 9093 9094 /* 'foldcolumn' */ 9095 else if (pp == &curwin->w_p_fdc) 9096 { 9097 if (curwin->w_p_fdc < 0) 9098 { 9099 errmsg = e_positive; 9100 curwin->w_p_fdc = 0; 9101 } 9102 else if (curwin->w_p_fdc > 12) 9103 { 9104 errmsg = e_invarg; 9105 curwin->w_p_fdc = 12; 9106 } 9107 } 9108 #endif /* FEAT_FOLDING */ 9109 9110 #if defined(FEAT_FOLDING) || defined(FEAT_CINDENT) 9111 /* 'shiftwidth' or 'tabstop' */ 9112 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) 9113 { 9114 # ifdef FEAT_FOLDING 9115 if (foldmethodIsIndent(curwin)) 9116 foldUpdateAll(curwin); 9117 # endif 9118 # ifdef FEAT_CINDENT 9119 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes: 9120 * parse 'cinoptions'. */ 9121 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) 9122 parse_cino(curbuf); 9123 # endif 9124 } 9125 #endif 9126 9127 /* 'maxcombine' */ 9128 else if (pp == &p_mco) 9129 { 9130 if (p_mco > MAX_MCO) 9131 p_mco = MAX_MCO; 9132 else if (p_mco < 0) 9133 p_mco = 0; 9134 screenclear(); /* will re-allocate the screen */ 9135 } 9136 9137 else if (pp == &curbuf->b_p_iminsert) 9138 { 9139 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) 9140 { 9141 errmsg = e_invarg; 9142 curbuf->b_p_iminsert = B_IMODE_NONE; 9143 } 9144 p_iminsert = curbuf->b_p_iminsert; 9145 if (termcap_active) /* don't do this in the alternate screen */ 9146 showmode(); 9147 #if defined(FEAT_KEYMAP) 9148 /* Show/unshow value of 'keymap' in status lines. */ 9149 status_redraw_curbuf(); 9150 #endif 9151 } 9152 9153 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) 9154 /* 'imstyle' */ 9155 else if (pp == &p_imst) 9156 { 9157 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT) 9158 errmsg = e_invarg; 9159 } 9160 #endif 9161 9162 else if (pp == &p_window) 9163 { 9164 if (p_window < 1) 9165 p_window = 1; 9166 else if (p_window >= Rows) 9167 p_window = Rows - 1; 9168 } 9169 9170 else if (pp == &curbuf->b_p_imsearch) 9171 { 9172 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) 9173 { 9174 errmsg = e_invarg; 9175 curbuf->b_p_imsearch = B_IMODE_NONE; 9176 } 9177 p_imsearch = curbuf->b_p_imsearch; 9178 } 9179 9180 #ifdef FEAT_TITLE 9181 /* if 'titlelen' has changed, redraw the title */ 9182 else if (pp == &p_titlelen) 9183 { 9184 if (p_titlelen < 0) 9185 { 9186 errmsg = e_positive; 9187 p_titlelen = 85; 9188 } 9189 if (starting != NO_SCREEN && old_value != p_titlelen) 9190 need_maketitle = TRUE; 9191 } 9192 #endif 9193 9194 /* if p_ch changed value, change the command line height */ 9195 else if (pp == &p_ch) 9196 { 9197 if (p_ch < 1) 9198 { 9199 errmsg = e_positive; 9200 p_ch = 1; 9201 } 9202 if (p_ch > Rows - min_rows() + 1) 9203 p_ch = Rows - min_rows() + 1; 9204 9205 /* Only compute the new window layout when startup has been 9206 * completed. Otherwise the frame sizes may be wrong. */ 9207 if (p_ch != old_value && full_screen 9208 #ifdef FEAT_GUI 9209 && !gui.starting 9210 #endif 9211 ) 9212 command_height(); 9213 } 9214 9215 /* when 'updatecount' changes from zero to non-zero, open swap files */ 9216 else if (pp == &p_uc) 9217 { 9218 if (p_uc < 0) 9219 { 9220 errmsg = e_positive; 9221 p_uc = 100; 9222 } 9223 if (p_uc && !old_value) 9224 ml_open_files(); 9225 } 9226 #ifdef FEAT_CONCEAL 9227 else if (pp == &curwin->w_p_cole) 9228 { 9229 if (curwin->w_p_cole < 0) 9230 { 9231 errmsg = e_positive; 9232 curwin->w_p_cole = 0; 9233 } 9234 else if (curwin->w_p_cole > 3) 9235 { 9236 errmsg = e_invarg; 9237 curwin->w_p_cole = 3; 9238 } 9239 } 9240 #endif 9241 #ifdef MZSCHEME_GUI_THREADS 9242 else if (pp == &p_mzq) 9243 mzvim_reset_timer(); 9244 #endif 9245 9246 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) 9247 /* 'pyxversion' */ 9248 else if (pp == &p_pyx) 9249 { 9250 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) 9251 errmsg = e_invarg; 9252 } 9253 #endif 9254 9255 /* sync undo before 'undolevels' changes */ 9256 else if (pp == &p_ul) 9257 { 9258 /* use the old value, otherwise u_sync() may not work properly */ 9259 p_ul = old_value; 9260 u_sync(TRUE); 9261 p_ul = value; 9262 } 9263 else if (pp == &curbuf->b_p_ul) 9264 { 9265 /* use the old value, otherwise u_sync() may not work properly */ 9266 curbuf->b_p_ul = old_value; 9267 u_sync(TRUE); 9268 curbuf->b_p_ul = value; 9269 } 9270 9271 #ifdef FEAT_LINEBREAK 9272 /* 'numberwidth' must be positive */ 9273 else if (pp == &curwin->w_p_nuw) 9274 { 9275 if (curwin->w_p_nuw < 1) 9276 { 9277 errmsg = e_positive; 9278 curwin->w_p_nuw = 1; 9279 } 9280 if (curwin->w_p_nuw > 10) 9281 { 9282 errmsg = e_invarg; 9283 curwin->w_p_nuw = 10; 9284 } 9285 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */ 9286 } 9287 #endif 9288 9289 else if (pp == &curbuf->b_p_tw) 9290 { 9291 if (curbuf->b_p_tw < 0) 9292 { 9293 errmsg = e_positive; 9294 curbuf->b_p_tw = 0; 9295 } 9296 #ifdef FEAT_SYN_HL 9297 { 9298 win_T *wp; 9299 tabpage_T *tp; 9300 9301 FOR_ALL_TAB_WINDOWS(tp, wp) 9302 check_colorcolumn(wp); 9303 } 9304 #endif 9305 } 9306 9307 /* 9308 * Check the bounds for numeric options here 9309 */ 9310 if (Rows < min_rows() && full_screen) 9311 { 9312 if (errbuf != NULL) 9313 { 9314 vim_snprintf((char *)errbuf, errbuflen, 9315 _("E593: Need at least %d lines"), min_rows()); 9316 errmsg = errbuf; 9317 } 9318 Rows = min_rows(); 9319 } 9320 if (Columns < MIN_COLUMNS && full_screen) 9321 { 9322 if (errbuf != NULL) 9323 { 9324 vim_snprintf((char *)errbuf, errbuflen, 9325 _("E594: Need at least %d columns"), MIN_COLUMNS); 9326 errmsg = errbuf; 9327 } 9328 Columns = MIN_COLUMNS; 9329 } 9330 limit_screen_size(); 9331 9332 /* 9333 * If the screen (shell) height has been changed, assume it is the 9334 * physical screenheight. 9335 */ 9336 if (old_Rows != Rows || old_Columns != Columns) 9337 { 9338 /* Changing the screen size is not allowed while updating the screen. */ 9339 if (updating_screen) 9340 *pp = old_value; 9341 else if (full_screen 9342 #ifdef FEAT_GUI 9343 && !gui.starting 9344 #endif 9345 ) 9346 set_shellsize((int)Columns, (int)Rows, TRUE); 9347 else 9348 { 9349 /* Postpone the resizing; check the size and cmdline position for 9350 * messages. */ 9351 check_shellsize(); 9352 if (cmdline_row > Rows - p_ch && Rows > p_ch) 9353 cmdline_row = Rows - p_ch; 9354 } 9355 if (p_window >= Rows || !option_was_set((char_u *)"window")) 9356 p_window = Rows - 1; 9357 } 9358 9359 if (curbuf->b_p_ts <= 0) 9360 { 9361 errmsg = e_positive; 9362 curbuf->b_p_ts = 8; 9363 } 9364 if (p_tm < 0) 9365 { 9366 errmsg = e_positive; 9367 p_tm = 0; 9368 } 9369 if ((curwin->w_p_scr <= 0 9370 || (curwin->w_p_scr > curwin->w_height 9371 && curwin->w_height > 0)) 9372 && full_screen) 9373 { 9374 if (pp == &(curwin->w_p_scr)) 9375 { 9376 if (curwin->w_p_scr != 0) 9377 errmsg = e_scroll; 9378 win_comp_scroll(curwin); 9379 } 9380 /* If 'scroll' became invalid because of a side effect silently adjust 9381 * it. */ 9382 else if (curwin->w_p_scr <= 0) 9383 curwin->w_p_scr = 1; 9384 else /* curwin->w_p_scr > curwin->w_height */ 9385 curwin->w_p_scr = curwin->w_height; 9386 } 9387 if (p_hi < 0) 9388 { 9389 errmsg = e_positive; 9390 p_hi = 0; 9391 } 9392 else if (p_hi > 10000) 9393 { 9394 errmsg = e_invarg; 9395 p_hi = 10000; 9396 } 9397 if (p_re < 0 || p_re > 2) 9398 { 9399 errmsg = e_invarg; 9400 p_re = 0; 9401 } 9402 if (p_report < 0) 9403 { 9404 errmsg = e_positive; 9405 p_report = 1; 9406 } 9407 if ((p_sj < -100 || p_sj >= Rows) && full_screen) 9408 { 9409 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */ 9410 p_sj = Rows / 2; 9411 else 9412 { 9413 errmsg = e_scroll; 9414 p_sj = 1; 9415 } 9416 } 9417 if (p_so < 0 && full_screen) 9418 { 9419 errmsg = e_positive; 9420 p_so = 0; 9421 } 9422 if (p_siso < 0 && full_screen) 9423 { 9424 errmsg = e_positive; 9425 p_siso = 0; 9426 } 9427 #ifdef FEAT_CMDWIN 9428 if (p_cwh < 1) 9429 { 9430 errmsg = e_positive; 9431 p_cwh = 1; 9432 } 9433 #endif 9434 if (p_ut < 0) 9435 { 9436 errmsg = e_positive; 9437 p_ut = 2000; 9438 } 9439 if (p_ss < 0) 9440 { 9441 errmsg = e_positive; 9442 p_ss = 0; 9443 } 9444 9445 /* May set global value for local option. */ 9446 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) 9447 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; 9448 9449 options[opt_idx].flags |= P_WAS_SET; 9450 9451 #if defined(FEAT_EVAL) 9452 // Don't do this while starting up, failure or recursively. 9453 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL) 9454 { 9455 char_u buf_old[11], buf_new[11], buf_type[7]; 9456 vim_snprintf((char *)buf_old, 10, "%ld", old_value); 9457 vim_snprintf((char *)buf_new, 10, "%ld", value); 9458 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global"); 9459 set_vim_var_string(VV_OPTION_NEW, buf_new, -1); 9460 set_vim_var_string(VV_OPTION_OLD, buf_old, -1); 9461 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); 9462 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL); 9463 reset_v_option_vars(); 9464 } 9465 #endif 9466 9467 comp_col(); /* in case 'columns' or 'ls' changed */ 9468 if (curwin->w_curswant != MAXCOL 9469 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) 9470 curwin->w_set_curswant = TRUE; 9471 check_redraw(options[opt_idx].flags); 9472 9473 return errmsg; 9474 } 9475 9476 /* 9477 * Called after an option changed: check if something needs to be redrawn. 9478 */ 9479 static void 9480 check_redraw(long_u flags) 9481 { 9482 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */ 9483 int doclear = (flags & P_RCLR) == P_RCLR; 9484 int all = ((flags & P_RALL) == P_RALL || doclear); 9485 9486 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */ 9487 status_redraw_all(); 9488 9489 if ((flags & P_RBUF) || (flags & P_RWIN) || all) 9490 changed_window_setting(); 9491 if (flags & P_RBUF) 9492 redraw_curbuf_later(NOT_VALID); 9493 if (flags & P_RWINONLY) 9494 redraw_later(NOT_VALID); 9495 if (doclear) 9496 redraw_all_later(CLEAR); 9497 else if (all) 9498 redraw_all_later(NOT_VALID); 9499 } 9500 9501 /* 9502 * Find index for option 'arg'. 9503 * Return -1 if not found. 9504 */ 9505 static int 9506 findoption(char_u *arg) 9507 { 9508 int opt_idx; 9509 char *s, *p; 9510 static short quick_tab[27] = {0, 0}; /* quick access table */ 9511 int is_term_opt; 9512 9513 /* 9514 * For first call: Initialize the quick-access table. 9515 * It contains the index for the first option that starts with a certain 9516 * letter. There are 26 letters, plus the first "t_" option. 9517 */ 9518 if (quick_tab[1] == 0) 9519 { 9520 p = options[0].fullname; 9521 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++) 9522 { 9523 if (s[0] != p[0]) 9524 { 9525 if (s[0] == 't' && s[1] == '_') 9526 quick_tab[26] = opt_idx; 9527 else 9528 quick_tab[CharOrdLow(s[0])] = opt_idx; 9529 } 9530 p = s; 9531 } 9532 } 9533 9534 /* 9535 * Check for name starting with an illegal character. 9536 */ 9537 #ifdef EBCDIC 9538 if (!islower(arg[0])) 9539 #else 9540 if (arg[0] < 'a' || arg[0] > 'z') 9541 #endif 9542 return -1; 9543 9544 is_term_opt = (arg[0] == 't' && arg[1] == '_'); 9545 if (is_term_opt) 9546 opt_idx = quick_tab[26]; 9547 else 9548 opt_idx = quick_tab[CharOrdLow(arg[0])]; 9549 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++) 9550 { 9551 if (STRCMP(arg, s) == 0) /* match full name */ 9552 break; 9553 } 9554 if (s == NULL && !is_term_opt) 9555 { 9556 opt_idx = quick_tab[CharOrdLow(arg[0])]; 9557 for ( ; options[opt_idx].fullname != NULL; opt_idx++) 9558 { 9559 s = options[opt_idx].shortname; 9560 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */ 9561 break; 9562 s = NULL; 9563 } 9564 } 9565 if (s == NULL) 9566 opt_idx = -1; 9567 return opt_idx; 9568 } 9569 9570 #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME) 9571 /* 9572 * Get the value for an option. 9573 * 9574 * Returns: 9575 * Number or Toggle option: 1, *numval gets value. 9576 * String option: 0, *stringval gets allocated string. 9577 * Hidden Number or Toggle option: -1. 9578 * hidden String option: -2. 9579 * unknown option: -3. 9580 */ 9581 int 9582 get_option_value( 9583 char_u *name, 9584 long *numval, 9585 char_u **stringval, /* NULL when only checking existence */ 9586 int opt_flags) 9587 { 9588 int opt_idx; 9589 char_u *varp; 9590 9591 opt_idx = findoption(name); 9592 if (opt_idx < 0) /* unknown option */ 9593 { 9594 int key; 9595 9596 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' 9597 && (key = find_key_option(name, FALSE)) != 0) 9598 { 9599 char_u key_name[2]; 9600 char_u *p; 9601 9602 if (key < 0) 9603 { 9604 key_name[0] = KEY2TERMCAP0(key); 9605 key_name[1] = KEY2TERMCAP1(key); 9606 } 9607 else 9608 { 9609 key_name[0] = KS_KEY; 9610 key_name[1] = (key & 0xff); 9611 } 9612 p = find_termcode(key_name); 9613 if (p != NULL) 9614 { 9615 if (stringval != NULL) 9616 *stringval = vim_strsave(p); 9617 return 0; 9618 } 9619 } 9620 return -3; 9621 } 9622 9623 varp = get_varp_scope(&(options[opt_idx]), opt_flags); 9624 9625 if (options[opt_idx].flags & P_STRING) 9626 { 9627 if (varp == NULL) /* hidden option */ 9628 return -2; 9629 if (stringval != NULL) 9630 { 9631 #ifdef FEAT_CRYPT 9632 /* never return the value of the crypt key */ 9633 if ((char_u **)varp == &curbuf->b_p_key 9634 && **(char_u **)(varp) != NUL) 9635 *stringval = vim_strsave((char_u *)"*****"); 9636 else 9637 #endif 9638 *stringval = vim_strsave(*(char_u **)(varp)); 9639 } 9640 return 0; 9641 } 9642 9643 if (varp == NULL) /* hidden option */ 9644 return -1; 9645 if (options[opt_idx].flags & P_NUM) 9646 *numval = *(long *)varp; 9647 else 9648 { 9649 /* Special case: 'modified' is b_changed, but we also want to consider 9650 * it set when 'ff' or 'fenc' changed. */ 9651 if ((int *)varp == &curbuf->b_changed) 9652 *numval = curbufIsChanged(); 9653 else 9654 *numval = (long) *(int *)varp; 9655 } 9656 return 1; 9657 } 9658 #endif 9659 9660 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) 9661 /* 9662 * Returns the option attributes and its value. Unlike the above function it 9663 * will return either global value or local value of the option depending on 9664 * what was requested, but it will never return global value if it was 9665 * requested to return local one and vice versa. Neither it will return 9666 * buffer-local value if it was requested to return window-local one. 9667 * 9668 * Pretends that option is absent if it is not present in the requested scope 9669 * (i.e. has no global, window-local or buffer-local value depending on 9670 * opt_type). Uses 9671 * 9672 * Returned flags: 9673 * 0 hidden or unknown option, also option that does not have requested 9674 * type (see SREQ_* in vim.h) 9675 * see SOPT_* in vim.h for other flags 9676 * 9677 * Possible opt_type values: see SREQ_* in vim.h 9678 */ 9679 int 9680 get_option_value_strict( 9681 char_u *name, 9682 long *numval, 9683 char_u **stringval, /* NULL when only obtaining attributes */ 9684 int opt_type, 9685 void *from) 9686 { 9687 int opt_idx; 9688 char_u *varp = NULL; 9689 struct vimoption *p; 9690 int r = 0; 9691 9692 opt_idx = findoption(name); 9693 if (opt_idx < 0) 9694 return 0; 9695 9696 p = &(options[opt_idx]); 9697 9698 /* Hidden option */ 9699 if (p->var == NULL) 9700 return 0; 9701 9702 if (p->flags & P_BOOL) 9703 r |= SOPT_BOOL; 9704 else if (p->flags & P_NUM) 9705 r |= SOPT_NUM; 9706 else if (p->flags & P_STRING) 9707 r |= SOPT_STRING; 9708 9709 if (p->indir == PV_NONE) 9710 { 9711 if (opt_type == SREQ_GLOBAL) 9712 r |= SOPT_GLOBAL; 9713 else 9714 return 0; /* Did not request global-only option */ 9715 } 9716 else 9717 { 9718 if (p->indir & PV_BOTH) 9719 r |= SOPT_GLOBAL; 9720 else if (opt_type == SREQ_GLOBAL) 9721 return 0; /* Requested global option */ 9722 9723 if (p->indir & PV_WIN) 9724 { 9725 if (opt_type == SREQ_BUF) 9726 return 0; /* Did not request window-local option */ 9727 else 9728 r |= SOPT_WIN; 9729 } 9730 else if (p->indir & PV_BUF) 9731 { 9732 if (opt_type == SREQ_WIN) 9733 return 0; /* Did not request buffer-local option */ 9734 else 9735 r |= SOPT_BUF; 9736 } 9737 } 9738 9739 if (stringval == NULL) 9740 return r; 9741 9742 if (opt_type == SREQ_GLOBAL) 9743 varp = p->var; 9744 else 9745 { 9746 if (opt_type == SREQ_BUF) 9747 { 9748 /* Special case: 'modified' is b_changed, but we also want to 9749 * consider it set when 'ff' or 'fenc' changed. */ 9750 if (p->indir == PV_MOD) 9751 { 9752 *numval = bufIsChanged((buf_T *)from); 9753 varp = NULL; 9754 } 9755 #ifdef FEAT_CRYPT 9756 else if (p->indir == PV_KEY) 9757 { 9758 /* never return the value of the crypt key */ 9759 *stringval = NULL; 9760 varp = NULL; 9761 } 9762 #endif 9763 else 9764 { 9765 buf_T *save_curbuf = curbuf; 9766 9767 // only getting a pointer, no need to use aucmd_prepbuf() 9768 curbuf = (buf_T *)from; 9769 curwin->w_buffer = curbuf; 9770 varp = get_varp(p); 9771 curbuf = save_curbuf; 9772 curwin->w_buffer = curbuf; 9773 } 9774 } 9775 else if (opt_type == SREQ_WIN) 9776 { 9777 win_T *save_curwin = curwin; 9778 9779 curwin = (win_T *)from; 9780 curbuf = curwin->w_buffer; 9781 varp = get_varp(p); 9782 curwin = save_curwin; 9783 curbuf = curwin->w_buffer; 9784 } 9785 if (varp == p->var) 9786 return (r | SOPT_UNSET); 9787 } 9788 9789 if (varp != NULL) 9790 { 9791 if (p->flags & P_STRING) 9792 *stringval = vim_strsave(*(char_u **)(varp)); 9793 else if (p->flags & P_NUM) 9794 *numval = *(long *) varp; 9795 else 9796 *numval = *(int *)varp; 9797 } 9798 9799 return r; 9800 } 9801 9802 /* 9803 * Iterate over options. First argument is a pointer to a pointer to a 9804 * structure inside options[] array, second is option type like in the above 9805 * function. 9806 * 9807 * If first argument points to NULL it is assumed that iteration just started 9808 * and caller needs the very first value. 9809 * If first argument points to the end marker function returns NULL and sets 9810 * first argument to NULL. 9811 * 9812 * Returns full option name for current option on each call. 9813 */ 9814 char_u * 9815 option_iter_next(void **option, int opt_type) 9816 { 9817 struct vimoption *ret = NULL; 9818 do 9819 { 9820 if (*option == NULL) 9821 *option = (void *) options; 9822 else if (((struct vimoption *) (*option))->fullname == NULL) 9823 { 9824 *option = NULL; 9825 return NULL; 9826 } 9827 else 9828 *option = (void *) (((struct vimoption *) (*option)) + 1); 9829 9830 ret = ((struct vimoption *) (*option)); 9831 9832 /* Hidden option */ 9833 if (ret->var == NULL) 9834 { 9835 ret = NULL; 9836 continue; 9837 } 9838 9839 switch (opt_type) 9840 { 9841 case SREQ_GLOBAL: 9842 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH)) 9843 ret = NULL; 9844 break; 9845 case SREQ_BUF: 9846 if (!(ret->indir & PV_BUF)) 9847 ret = NULL; 9848 break; 9849 case SREQ_WIN: 9850 if (!(ret->indir & PV_WIN)) 9851 ret = NULL; 9852 break; 9853 default: 9854 internal_error("option_iter_next()"); 9855 return NULL; 9856 } 9857 } 9858 while (ret == NULL); 9859 9860 return (char_u *)ret->fullname; 9861 } 9862 #endif 9863 9864 /* 9865 * Set the value of option "name". 9866 * Use "string" for string options, use "number" for other options. 9867 * 9868 * Returns NULL on success or error message on error. 9869 */ 9870 char * 9871 set_option_value( 9872 char_u *name, 9873 long number, 9874 char_u *string, 9875 int opt_flags) /* OPT_LOCAL or 0 (both) */ 9876 { 9877 int opt_idx; 9878 char_u *varp; 9879 long_u flags; 9880 9881 opt_idx = findoption(name); 9882 if (opt_idx < 0) 9883 { 9884 int key; 9885 9886 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_' 9887 && (key = find_key_option(name, FALSE)) != 0) 9888 { 9889 char_u key_name[2]; 9890 9891 if (key < 0) 9892 { 9893 key_name[0] = KEY2TERMCAP0(key); 9894 key_name[1] = KEY2TERMCAP1(key); 9895 } 9896 else 9897 { 9898 key_name[0] = KS_KEY; 9899 key_name[1] = (key & 0xff); 9900 } 9901 add_termcode(key_name, string, FALSE); 9902 if (full_screen) 9903 ttest(FALSE); 9904 redraw_all_later(CLEAR); 9905 return NULL; 9906 } 9907 9908 semsg(_("E355: Unknown option: %s"), name); 9909 } 9910 else 9911 { 9912 flags = options[opt_idx].flags; 9913 #ifdef HAVE_SANDBOX 9914 /* Disallow changing some options in the sandbox */ 9915 if (sandbox > 0 && (flags & P_SECURE)) 9916 { 9917 emsg(_(e_sandbox)); 9918 return NULL; 9919 } 9920 #endif 9921 if (flags & P_STRING) 9922 return set_string_option(opt_idx, string, opt_flags); 9923 else 9924 { 9925 varp = get_varp_scope(&(options[opt_idx]), opt_flags); 9926 if (varp != NULL) /* hidden option is not changed */ 9927 { 9928 if (number == 0 && string != NULL) 9929 { 9930 int idx; 9931 9932 /* Either we are given a string or we are setting option 9933 * to zero. */ 9934 for (idx = 0; string[idx] == '0'; ++idx) 9935 ; 9936 if (string[idx] != NUL || idx == 0) 9937 { 9938 /* There's another character after zeros or the string 9939 * is empty. In both cases, we are trying to set a 9940 * num option using a string. */ 9941 semsg(_("E521: Number required: &%s = '%s'"), 9942 name, string); 9943 return NULL; /* do nothing as we hit an error */ 9944 9945 } 9946 } 9947 if (flags & P_NUM) 9948 return set_num_option(opt_idx, varp, number, 9949 NULL, 0, opt_flags); 9950 else 9951 return set_bool_option(opt_idx, varp, (int)number, 9952 opt_flags); 9953 } 9954 } 9955 } 9956 return NULL; 9957 } 9958 9959 /* 9960 * Get the terminal code for a terminal option. 9961 * Returns NULL when not found. 9962 */ 9963 char_u * 9964 get_term_code(char_u *tname) 9965 { 9966 int opt_idx; 9967 char_u *varp; 9968 9969 if (tname[0] != 't' || tname[1] != '_' || 9970 tname[2] == NUL || tname[3] == NUL) 9971 return NULL; 9972 if ((opt_idx = findoption(tname)) >= 0) 9973 { 9974 varp = get_varp(&(options[opt_idx])); 9975 if (varp != NULL) 9976 varp = *(char_u **)(varp); 9977 return varp; 9978 } 9979 return find_termcode(tname + 2); 9980 } 9981 9982 char_u * 9983 get_highlight_default(void) 9984 { 9985 int i; 9986 9987 i = findoption((char_u *)"hl"); 9988 if (i >= 0) 9989 return options[i].def_val[VI_DEFAULT]; 9990 return (char_u *)NULL; 9991 } 9992 9993 char_u * 9994 get_encoding_default(void) 9995 { 9996 int i; 9997 9998 i = findoption((char_u *)"enc"); 9999 if (i >= 0) 10000 return options[i].def_val[VI_DEFAULT]; 10001 return (char_u *)NULL; 10002 } 10003 10004 /* 10005 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number. 10006 * When "has_lt" is true there is a '<' before "*arg_arg". 10007 * Returns 0 when the key is not recognized. 10008 */ 10009 static int 10010 find_key_option(char_u *arg_arg, int has_lt) 10011 { 10012 int key = 0; 10013 int modifiers; 10014 char_u *arg = arg_arg; 10015 10016 /* 10017 * Don't use get_special_key_code() for t_xx, we don't want it to call 10018 * add_termcap_entry(). 10019 */ 10020 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) 10021 key = TERMCAP2KEY(arg[2], arg[3]); 10022 else if (has_lt) 10023 { 10024 --arg; /* put arg at the '<' */ 10025 modifiers = 0; 10026 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE); 10027 if (modifiers) /* can't handle modifiers here */ 10028 key = 0; 10029 } 10030 return key; 10031 } 10032 10033 /* 10034 * if 'all' == 0: show changed options 10035 * if 'all' == 1: show all normal options 10036 * if 'all' == 2: show all terminal options 10037 */ 10038 static void 10039 showoptions( 10040 int all, 10041 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ 10042 { 10043 struct vimoption *p; 10044 int col; 10045 int isterm; 10046 char_u *varp; 10047 struct vimoption **items; 10048 int item_count; 10049 int run; 10050 int row, rows; 10051 int cols; 10052 int i; 10053 int len; 10054 10055 #define INC 20 10056 #define GAP 3 10057 10058 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) * 10059 PARAM_COUNT)); 10060 if (items == NULL) 10061 return; 10062 10063 /* Highlight title */ 10064 if (all == 2) 10065 msg_puts_title(_("\n--- Terminal codes ---")); 10066 else if (opt_flags & OPT_GLOBAL) 10067 msg_puts_title(_("\n--- Global option values ---")); 10068 else if (opt_flags & OPT_LOCAL) 10069 msg_puts_title(_("\n--- Local option values ---")); 10070 else 10071 msg_puts_title(_("\n--- Options ---")); 10072 10073 /* 10074 * do the loop two times: 10075 * 1. display the short items 10076 * 2. display the long items (only strings and numbers) 10077 */ 10078 for (run = 1; run <= 2 && !got_int; ++run) 10079 { 10080 /* 10081 * collect the items in items[] 10082 */ 10083 item_count = 0; 10084 for (p = &options[0]; p->fullname != NULL; p++) 10085 { 10086 // apply :filter /pat/ 10087 if (message_filtered((char_u *) p->fullname)) 10088 continue; 10089 10090 varp = NULL; 10091 isterm = istermoption(p); 10092 if (opt_flags != 0) 10093 { 10094 if (p->indir != PV_NONE && !isterm) 10095 varp = get_varp_scope(p, opt_flags); 10096 } 10097 else 10098 varp = get_varp(p); 10099 if (varp != NULL 10100 && ((all == 2 && isterm) 10101 || (all == 1 && !isterm) 10102 || (all == 0 && !optval_default(p, varp)))) 10103 { 10104 if (p->flags & P_BOOL) 10105 len = 1; /* a toggle option fits always */ 10106 else 10107 { 10108 option_value2string(p, opt_flags); 10109 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1; 10110 } 10111 if ((len <= INC - GAP && run == 1) || 10112 (len > INC - GAP && run == 2)) 10113 items[item_count++] = p; 10114 } 10115 } 10116 10117 /* 10118 * display the items 10119 */ 10120 if (run == 1) 10121 { 10122 cols = (Columns + GAP - 3) / INC; 10123 if (cols == 0) 10124 cols = 1; 10125 rows = (item_count + cols - 1) / cols; 10126 } 10127 else /* run == 2 */ 10128 rows = item_count; 10129 for (row = 0; row < rows && !got_int; ++row) 10130 { 10131 msg_putchar('\n'); /* go to next line */ 10132 if (got_int) /* 'q' typed in more */ 10133 break; 10134 col = 0; 10135 for (i = row; i < item_count; i += rows) 10136 { 10137 msg_col = col; /* make columns */ 10138 showoneopt(items[i], opt_flags); 10139 col += INC; 10140 } 10141 out_flush(); 10142 ui_breakcheck(); 10143 } 10144 } 10145 vim_free(items); 10146 } 10147 10148 /* 10149 * Return TRUE if option "p" has its default value. 10150 */ 10151 static int 10152 optval_default(struct vimoption *p, char_u *varp) 10153 { 10154 int dvi; 10155 10156 if (varp == NULL) 10157 return TRUE; /* hidden option is always at default */ 10158 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT; 10159 if (p->flags & P_NUM) 10160 return (*(long *)varp == (long)(long_i)p->def_val[dvi]); 10161 if (p->flags & P_BOOL) 10162 /* the cast to long is required for Manx C, long_i is 10163 * needed for MSVC */ 10164 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]); 10165 /* P_STRING */ 10166 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0); 10167 } 10168 10169 /* 10170 * showoneopt: show the value of one option 10171 * must not be called with a hidden option! 10172 */ 10173 static void 10174 showoneopt( 10175 struct vimoption *p, 10176 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */ 10177 { 10178 char_u *varp; 10179 int save_silent = silent_mode; 10180 10181 silent_mode = FALSE; 10182 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ 10183 10184 varp = get_varp_scope(p, opt_flags); 10185 10186 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */ 10187 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed 10188 ? !curbufIsChanged() : !*(int *)varp)) 10189 msg_puts("no"); 10190 else if ((p->flags & P_BOOL) && *(int *)varp < 0) 10191 msg_puts("--"); 10192 else 10193 msg_puts(" "); 10194 msg_puts(p->fullname); 10195 if (!(p->flags & P_BOOL)) 10196 { 10197 msg_putchar('='); 10198 /* put value string in NameBuff */ 10199 option_value2string(p, opt_flags); 10200 msg_outtrans(NameBuff); 10201 } 10202 10203 silent_mode = save_silent; 10204 info_message = FALSE; 10205 } 10206 10207 /* 10208 * Write modified options as ":set" commands to a file. 10209 * 10210 * There are three values for "opt_flags": 10211 * OPT_GLOBAL: Write global option values and fresh values of 10212 * buffer-local options (used for start of a session 10213 * file). 10214 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for 10215 * curwin (used for a vimrc file). 10216 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh 10217 * and local values for window-local options of 10218 * curwin. Local values are also written when at the 10219 * default value, because a modeline or autocommand 10220 * may have set them when doing ":edit file" and the 10221 * user has set them back at the default or fresh 10222 * value. 10223 * When "local_only" is TRUE, don't write fresh 10224 * values, only local values (for ":mkview"). 10225 * (fresh value = value used for a new buffer or window for a local option). 10226 * 10227 * Return FAIL on error, OK otherwise. 10228 */ 10229 int 10230 makeset(FILE *fd, int opt_flags, int local_only) 10231 { 10232 struct vimoption *p; 10233 char_u *varp; /* currently used value */ 10234 char_u *varp_fresh; /* local value */ 10235 char_u *varp_local = NULL; /* fresh value */ 10236 char *cmd; 10237 int round; 10238 int pri; 10239 10240 /* 10241 * The options that don't have a default (terminal name, columns, lines) 10242 * are never written. Terminal options are also not written. 10243 * Do the loop over "options[]" twice: once for options with the 10244 * P_PRI_MKRC flag and once without. 10245 */ 10246 for (pri = 1; pri >= 0; --pri) 10247 { 10248 for (p = &options[0]; !istermoption(p); p++) 10249 if (!(p->flags & P_NO_MKRC) 10250 && !istermoption(p) 10251 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) 10252 { 10253 /* skip global option when only doing locals */ 10254 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) 10255 continue; 10256 10257 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc 10258 * file, they are always buffer-specific. */ 10259 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB)) 10260 continue; 10261 10262 /* Global values are only written when not at the default value. */ 10263 varp = get_varp_scope(p, opt_flags); 10264 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp)) 10265 continue; 10266 10267 round = 2; 10268 if (p->indir != PV_NONE) 10269 { 10270 if (p->var == VAR_WIN) 10271 { 10272 /* skip window-local option when only doing globals */ 10273 if (!(opt_flags & OPT_LOCAL)) 10274 continue; 10275 /* When fresh value of window-local option is not at the 10276 * default, need to write it too. */ 10277 if (!(opt_flags & OPT_GLOBAL) && !local_only) 10278 { 10279 varp_fresh = get_varp_scope(p, OPT_GLOBAL); 10280 if (!optval_default(p, varp_fresh)) 10281 { 10282 round = 1; 10283 varp_local = varp; 10284 varp = varp_fresh; 10285 } 10286 } 10287 } 10288 } 10289 10290 /* Round 1: fresh value for window-local options. 10291 * Round 2: other values */ 10292 for ( ; round <= 2; varp = varp_local, ++round) 10293 { 10294 if (round == 1 || (opt_flags & OPT_GLOBAL)) 10295 cmd = "set"; 10296 else 10297 cmd = "setlocal"; 10298 10299 if (p->flags & P_BOOL) 10300 { 10301 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL) 10302 return FAIL; 10303 } 10304 else if (p->flags & P_NUM) 10305 { 10306 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL) 10307 return FAIL; 10308 } 10309 else /* P_STRING */ 10310 { 10311 int do_endif = FALSE; 10312 10313 /* Don't set 'syntax' and 'filetype' again if the value is 10314 * already right, avoids reloading the syntax file. */ 10315 if ( 10316 #if defined(FEAT_SYN_HL) 10317 p->indir == PV_SYN || 10318 #endif 10319 p->indir == PV_FT) 10320 { 10321 if (fprintf(fd, "if &%s != '%s'", p->fullname, 10322 *(char_u **)(varp)) < 0 10323 || put_eol(fd) < 0) 10324 return FAIL; 10325 do_endif = TRUE; 10326 } 10327 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, 10328 p->flags) == FAIL) 10329 return FAIL; 10330 if (do_endif) 10331 { 10332 if (put_line(fd, "endif") == FAIL) 10333 return FAIL; 10334 } 10335 } 10336 } 10337 } 10338 } 10339 return OK; 10340 } 10341 10342 #if defined(FEAT_FOLDING) || defined(PROTO) 10343 /* 10344 * Generate set commands for the local fold options only. Used when 10345 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options". 10346 */ 10347 int 10348 makefoldset(FILE *fd) 10349 { 10350 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL 10351 # ifdef FEAT_EVAL 10352 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) 10353 == FAIL 10354 # endif 10355 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) 10356 == FAIL 10357 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) 10358 == FAIL 10359 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL 10360 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL 10361 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL 10362 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL 10363 ) 10364 return FAIL; 10365 10366 return OK; 10367 } 10368 #endif 10369 10370 static int 10371 put_setstring( 10372 FILE *fd, 10373 char *cmd, 10374 char *name, 10375 char_u **valuep, 10376 long_u flags) 10377 { 10378 char_u *s; 10379 char_u *buf = NULL; 10380 char_u *part = NULL; 10381 char_u *p; 10382 10383 if (fprintf(fd, "%s %s=", cmd, name) < 0) 10384 return FAIL; 10385 if (*valuep != NULL) 10386 { 10387 /* Output 'pastetoggle' as key names. For other 10388 * options some characters have to be escaped with 10389 * CTRL-V or backslash */ 10390 if (valuep == &p_pt) 10391 { 10392 s = *valuep; 10393 while (*s != NUL) 10394 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL) 10395 return FAIL; 10396 } 10397 // expand the option value, replace $HOME by ~ 10398 else if ((flags & P_EXPAND) != 0) 10399 { 10400 int size = (int)STRLEN(*valuep) + 1; 10401 10402 // replace home directory in the whole option value into "buf" 10403 buf = alloc(size); 10404 if (buf == NULL) 10405 goto fail; 10406 home_replace(NULL, *valuep, buf, size, FALSE); 10407 10408 // If the option value is longer than MAXPATHL, we need to append 10409 // earch comma separated part of the option separately, so that it 10410 // can be expanded when read back. 10411 if (size >= MAXPATHL && (flags & P_COMMA) != 0 10412 && vim_strchr(*valuep, ',') != NULL) 10413 { 10414 part = alloc(size); 10415 if (part == NULL) 10416 goto fail; 10417 10418 // write line break to clear the option, e.g. ':set rtp=' 10419 if (put_eol(fd) == FAIL) 10420 goto fail; 10421 10422 p = buf; 10423 while (*p != NUL) 10424 { 10425 // for each comma separated option part, append value to 10426 // the option, :set rtp+=value 10427 if (fprintf(fd, "%s %s+=", cmd, name) < 0) 10428 goto fail; 10429 (void)copy_option_part(&p, part, size, ","); 10430 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) 10431 goto fail; 10432 } 10433 vim_free(buf); 10434 vim_free(part); 10435 return OK; 10436 } 10437 if (put_escstr(fd, buf, 2) == FAIL) 10438 { 10439 vim_free(buf); 10440 return FAIL; 10441 } 10442 vim_free(buf); 10443 } 10444 else if (put_escstr(fd, *valuep, 2) == FAIL) 10445 return FAIL; 10446 } 10447 if (put_eol(fd) < 0) 10448 return FAIL; 10449 return OK; 10450 fail: 10451 vim_free(buf); 10452 vim_free(part); 10453 return FAIL; 10454 } 10455 10456 static int 10457 put_setnum( 10458 FILE *fd, 10459 char *cmd, 10460 char *name, 10461 long *valuep) 10462 { 10463 long wc; 10464 10465 if (fprintf(fd, "%s %s=", cmd, name) < 0) 10466 return FAIL; 10467 if (wc_use_keyname((char_u *)valuep, &wc)) 10468 { 10469 /* print 'wildchar' and 'wildcharm' as a key name */ 10470 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) 10471 return FAIL; 10472 } 10473 else if (fprintf(fd, "%ld", *valuep) < 0) 10474 return FAIL; 10475 if (put_eol(fd) < 0) 10476 return FAIL; 10477 return OK; 10478 } 10479 10480 static int 10481 put_setbool( 10482 FILE *fd, 10483 char *cmd, 10484 char *name, 10485 int value) 10486 { 10487 if (value < 0) /* global/local option using global value */ 10488 return OK; 10489 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0 10490 || put_eol(fd) < 0) 10491 return FAIL; 10492 return OK; 10493 } 10494 10495 /* 10496 * Clear all the terminal options. 10497 * If the option has been allocated, free the memory. 10498 * Terminal options are never hidden or indirect. 10499 */ 10500 void 10501 clear_termoptions(void) 10502 { 10503 /* 10504 * Reset a few things before clearing the old options. This may cause 10505 * outputting a few things that the terminal doesn't understand, but the 10506 * screen will be cleared later, so this is OK. 10507 */ 10508 #ifdef FEAT_MOUSE_TTY 10509 mch_setmouse(FALSE); /* switch mouse off */ 10510 #endif 10511 #ifdef FEAT_TITLE 10512 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */ 10513 #endif 10514 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI) 10515 /* When starting the GUI close the display opened for the clipboard. 10516 * After restoring the title, because that will need the display. */ 10517 if (gui.starting) 10518 clear_xterm_clip(); 10519 #endif 10520 stoptermcap(); /* stop termcap mode */ 10521 10522 free_termoptions(); 10523 } 10524 10525 void 10526 free_termoptions(void) 10527 { 10528 struct vimoption *p; 10529 10530 for (p = options; p->fullname != NULL; p++) 10531 if (istermoption(p)) 10532 { 10533 if (p->flags & P_ALLOCED) 10534 free_string_option(*(char_u **)(p->var)); 10535 if (p->flags & P_DEF_ALLOCED) 10536 free_string_option(p->def_val[VI_DEFAULT]); 10537 *(char_u **)(p->var) = empty_option; 10538 p->def_val[VI_DEFAULT] = empty_option; 10539 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED); 10540 #ifdef FEAT_EVAL 10541 // remember where the option was cleared 10542 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx); 10543 #endif 10544 } 10545 clear_termcodes(); 10546 } 10547 10548 /* 10549 * Free the string for one term option, if it was allocated. 10550 * Set the string to empty_option and clear allocated flag. 10551 * "var" points to the option value. 10552 */ 10553 void 10554 free_one_termoption(char_u *var) 10555 { 10556 struct vimoption *p; 10557 10558 for (p = &options[0]; p->fullname != NULL; p++) 10559 if (p->var == var) 10560 { 10561 if (p->flags & P_ALLOCED) 10562 free_string_option(*(char_u **)(p->var)); 10563 *(char_u **)(p->var) = empty_option; 10564 p->flags &= ~P_ALLOCED; 10565 break; 10566 } 10567 } 10568 10569 /* 10570 * Set the terminal option defaults to the current value. 10571 * Used after setting the terminal name. 10572 */ 10573 void 10574 set_term_defaults(void) 10575 { 10576 struct vimoption *p; 10577 10578 for (p = &options[0]; p->fullname != NULL; p++) 10579 { 10580 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) 10581 { 10582 if (p->flags & P_DEF_ALLOCED) 10583 { 10584 free_string_option(p->def_val[VI_DEFAULT]); 10585 p->flags &= ~P_DEF_ALLOCED; 10586 } 10587 p->def_val[VI_DEFAULT] = *(char_u **)(p->var); 10588 if (p->flags & P_ALLOCED) 10589 { 10590 p->flags |= P_DEF_ALLOCED; 10591 p->flags &= ~P_ALLOCED; /* don't free the value now */ 10592 } 10593 } 10594 } 10595 } 10596 10597 /* 10598 * return TRUE if 'p' starts with 't_' 10599 */ 10600 static int 10601 istermoption(struct vimoption *p) 10602 { 10603 return (p->fullname[0] == 't' && p->fullname[1] == '_'); 10604 } 10605 10606 /* 10607 * Compute columns for ruler and shown command. 'sc_col' is also used to 10608 * decide what the maximum length of a message on the status line can be. 10609 * If there is a status line for the last window, 'sc_col' is independent 10610 * of 'ru_col'. 10611 */ 10612 10613 #define COL_RULER 17 /* columns needed by standard ruler */ 10614 10615 void 10616 comp_col(void) 10617 { 10618 #if defined(FEAT_CMDL_INFO) 10619 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW)); 10620 10621 sc_col = 0; 10622 ru_col = 0; 10623 if (p_ru) 10624 { 10625 # ifdef FEAT_STL_OPT 10626 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1; 10627 # else 10628 ru_col = COL_RULER + 1; 10629 # endif 10630 /* no last status line, adjust sc_col */ 10631 if (!last_has_status) 10632 sc_col = ru_col; 10633 } 10634 if (p_sc) 10635 { 10636 sc_col += SHOWCMD_COLS; 10637 if (!p_ru || last_has_status) /* no need for separating space */ 10638 ++sc_col; 10639 } 10640 sc_col = Columns - sc_col; 10641 ru_col = Columns - ru_col; 10642 if (sc_col <= 0) /* screen too narrow, will become a mess */ 10643 sc_col = 1; 10644 if (ru_col <= 0) 10645 ru_col = 1; 10646 #else 10647 sc_col = Columns; 10648 ru_col = Columns; 10649 #endif 10650 } 10651 10652 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) 10653 /* 10654 * Unset local option value, similar to ":set opt<". 10655 */ 10656 void 10657 unset_global_local_option(char_u *name, void *from) 10658 { 10659 struct vimoption *p; 10660 int opt_idx; 10661 buf_T *buf = (buf_T *)from; 10662 10663 opt_idx = findoption(name); 10664 if (opt_idx < 0) 10665 return; 10666 p = &(options[opt_idx]); 10667 10668 switch ((int)p->indir) 10669 { 10670 /* global option with local value: use local value if it's been set */ 10671 case PV_EP: 10672 clear_string_option(&buf->b_p_ep); 10673 break; 10674 case PV_KP: 10675 clear_string_option(&buf->b_p_kp); 10676 break; 10677 case PV_PATH: 10678 clear_string_option(&buf->b_p_path); 10679 break; 10680 case PV_AR: 10681 buf->b_p_ar = -1; 10682 break; 10683 case PV_BKC: 10684 clear_string_option(&buf->b_p_bkc); 10685 buf->b_bkc_flags = 0; 10686 break; 10687 case PV_TAGS: 10688 clear_string_option(&buf->b_p_tags); 10689 break; 10690 case PV_TC: 10691 clear_string_option(&buf->b_p_tc); 10692 buf->b_tc_flags = 0; 10693 break; 10694 case PV_SISO: 10695 curwin->w_p_siso = -1; 10696 break; 10697 case PV_SO: 10698 curwin->w_p_so = -1; 10699 break; 10700 #ifdef FEAT_FIND_ID 10701 case PV_DEF: 10702 clear_string_option(&buf->b_p_def); 10703 break; 10704 case PV_INC: 10705 clear_string_option(&buf->b_p_inc); 10706 break; 10707 #endif 10708 #ifdef FEAT_INS_EXPAND 10709 case PV_DICT: 10710 clear_string_option(&buf->b_p_dict); 10711 break; 10712 case PV_TSR: 10713 clear_string_option(&buf->b_p_tsr); 10714 break; 10715 #endif 10716 case PV_FP: 10717 clear_string_option(&buf->b_p_fp); 10718 break; 10719 #ifdef FEAT_QUICKFIX 10720 case PV_EFM: 10721 clear_string_option(&buf->b_p_efm); 10722 break; 10723 case PV_GP: 10724 clear_string_option(&buf->b_p_gp); 10725 break; 10726 case PV_MP: 10727 clear_string_option(&buf->b_p_mp); 10728 break; 10729 #endif 10730 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) 10731 case PV_BEXPR: 10732 clear_string_option(&buf->b_p_bexpr); 10733 break; 10734 #endif 10735 #if defined(FEAT_CRYPT) 10736 case PV_CM: 10737 clear_string_option(&buf->b_p_cm); 10738 break; 10739 #endif 10740 #ifdef FEAT_STL_OPT 10741 case PV_STL: 10742 clear_string_option(&((win_T *)from)->w_p_stl); 10743 break; 10744 #endif 10745 case PV_UL: 10746 buf->b_p_ul = NO_LOCAL_UNDOLEVEL; 10747 break; 10748 #ifdef FEAT_LISP 10749 case PV_LW: 10750 clear_string_option(&buf->b_p_lw); 10751 break; 10752 #endif 10753 case PV_MENC: 10754 clear_string_option(&buf->b_p_menc); 10755 break; 10756 } 10757 } 10758 #endif 10759 10760 /* 10761 * Get pointer to option variable, depending on local or global scope. 10762 */ 10763 static char_u * 10764 get_varp_scope(struct vimoption *p, int opt_flags) 10765 { 10766 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) 10767 { 10768 if (p->var == VAR_WIN) 10769 return (char_u *)GLOBAL_WO(get_varp(p)); 10770 return p->var; 10771 } 10772 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) 10773 { 10774 switch ((int)p->indir) 10775 { 10776 case PV_FP: return (char_u *)&(curbuf->b_p_fp); 10777 #ifdef FEAT_QUICKFIX 10778 case PV_EFM: return (char_u *)&(curbuf->b_p_efm); 10779 case PV_GP: return (char_u *)&(curbuf->b_p_gp); 10780 case PV_MP: return (char_u *)&(curbuf->b_p_mp); 10781 #endif 10782 case PV_EP: return (char_u *)&(curbuf->b_p_ep); 10783 case PV_KP: return (char_u *)&(curbuf->b_p_kp); 10784 case PV_PATH: return (char_u *)&(curbuf->b_p_path); 10785 case PV_AR: return (char_u *)&(curbuf->b_p_ar); 10786 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags); 10787 case PV_TC: return (char_u *)&(curbuf->b_p_tc); 10788 case PV_SISO: return (char_u *)&(curwin->w_p_siso); 10789 case PV_SO: return (char_u *)&(curwin->w_p_so); 10790 #ifdef FEAT_FIND_ID 10791 case PV_DEF: return (char_u *)&(curbuf->b_p_def); 10792 case PV_INC: return (char_u *)&(curbuf->b_p_inc); 10793 #endif 10794 #ifdef FEAT_INS_EXPAND 10795 case PV_DICT: return (char_u *)&(curbuf->b_p_dict); 10796 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr); 10797 #endif 10798 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) 10799 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr); 10800 #endif 10801 #if defined(FEAT_CRYPT) 10802 case PV_CM: return (char_u *)&(curbuf->b_p_cm); 10803 #endif 10804 #ifdef FEAT_STL_OPT 10805 case PV_STL: return (char_u *)&(curwin->w_p_stl); 10806 #endif 10807 case PV_UL: return (char_u *)&(curbuf->b_p_ul); 10808 #ifdef FEAT_LISP 10809 case PV_LW: return (char_u *)&(curbuf->b_p_lw); 10810 #endif 10811 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); 10812 case PV_MENC: return (char_u *)&(curbuf->b_p_menc); 10813 } 10814 return NULL; /* "cannot happen" */ 10815 } 10816 return get_varp(p); 10817 } 10818 10819 /* 10820 * Get pointer to option variable. 10821 */ 10822 static char_u * 10823 get_varp(struct vimoption *p) 10824 { 10825 /* hidden option, always return NULL */ 10826 if (p->var == NULL) 10827 return NULL; 10828 10829 switch ((int)p->indir) 10830 { 10831 case PV_NONE: return p->var; 10832 10833 /* global option with local value: use local value if it's been set */ 10834 case PV_EP: return *curbuf->b_p_ep != NUL 10835 ? (char_u *)&curbuf->b_p_ep : p->var; 10836 case PV_KP: return *curbuf->b_p_kp != NUL 10837 ? (char_u *)&curbuf->b_p_kp : p->var; 10838 case PV_PATH: return *curbuf->b_p_path != NUL 10839 ? (char_u *)&(curbuf->b_p_path) : p->var; 10840 case PV_AR: return curbuf->b_p_ar >= 0 10841 ? (char_u *)&(curbuf->b_p_ar) : p->var; 10842 case PV_TAGS: return *curbuf->b_p_tags != NUL 10843 ? (char_u *)&(curbuf->b_p_tags) : p->var; 10844 case PV_TC: return *curbuf->b_p_tc != NUL 10845 ? (char_u *)&(curbuf->b_p_tc) : p->var; 10846 case PV_BKC: return *curbuf->b_p_bkc != NUL 10847 ? (char_u *)&(curbuf->b_p_bkc) : p->var; 10848 case PV_SISO: return curwin->w_p_siso >= 0 10849 ? (char_u *)&(curwin->w_p_siso) : p->var; 10850 case PV_SO: return curwin->w_p_so >= 0 10851 ? (char_u *)&(curwin->w_p_so) : p->var; 10852 #ifdef FEAT_FIND_ID 10853 case PV_DEF: return *curbuf->b_p_def != NUL 10854 ? (char_u *)&(curbuf->b_p_def) : p->var; 10855 case PV_INC: return *curbuf->b_p_inc != NUL 10856 ? (char_u *)&(curbuf->b_p_inc) : p->var; 10857 #endif 10858 #ifdef FEAT_INS_EXPAND 10859 case PV_DICT: return *curbuf->b_p_dict != NUL 10860 ? (char_u *)&(curbuf->b_p_dict) : p->var; 10861 case PV_TSR: return *curbuf->b_p_tsr != NUL 10862 ? (char_u *)&(curbuf->b_p_tsr) : p->var; 10863 #endif 10864 case PV_FP: return *curbuf->b_p_fp != NUL 10865 ? (char_u *)&(curbuf->b_p_fp) : p->var; 10866 #ifdef FEAT_QUICKFIX 10867 case PV_EFM: return *curbuf->b_p_efm != NUL 10868 ? (char_u *)&(curbuf->b_p_efm) : p->var; 10869 case PV_GP: return *curbuf->b_p_gp != NUL 10870 ? (char_u *)&(curbuf->b_p_gp) : p->var; 10871 case PV_MP: return *curbuf->b_p_mp != NUL 10872 ? (char_u *)&(curbuf->b_p_mp) : p->var; 10873 #endif 10874 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) 10875 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL 10876 ? (char_u *)&(curbuf->b_p_bexpr) : p->var; 10877 #endif 10878 #if defined(FEAT_CRYPT) 10879 case PV_CM: return *curbuf->b_p_cm != NUL 10880 ? (char_u *)&(curbuf->b_p_cm) : p->var; 10881 #endif 10882 #ifdef FEAT_STL_OPT 10883 case PV_STL: return *curwin->w_p_stl != NUL 10884 ? (char_u *)&(curwin->w_p_stl) : p->var; 10885 #endif 10886 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL 10887 ? (char_u *)&(curbuf->b_p_ul) : p->var; 10888 #ifdef FEAT_LISP 10889 case PV_LW: return *curbuf->b_p_lw != NUL 10890 ? (char_u *)&(curbuf->b_p_lw) : p->var; 10891 #endif 10892 case PV_MENC: return *curbuf->b_p_menc != NUL 10893 ? (char_u *)&(curbuf->b_p_menc) : p->var; 10894 10895 #ifdef FEAT_ARABIC 10896 case PV_ARAB: return (char_u *)&(curwin->w_p_arab); 10897 #endif 10898 case PV_LIST: return (char_u *)&(curwin->w_p_list); 10899 #ifdef FEAT_SPELL 10900 case PV_SPELL: return (char_u *)&(curwin->w_p_spell); 10901 #endif 10902 #ifdef FEAT_SYN_HL 10903 case PV_CUC: return (char_u *)&(curwin->w_p_cuc); 10904 case PV_CUL: return (char_u *)&(curwin->w_p_cul); 10905 case PV_CC: return (char_u *)&(curwin->w_p_cc); 10906 #endif 10907 #ifdef FEAT_DIFF 10908 case PV_DIFF: return (char_u *)&(curwin->w_p_diff); 10909 #endif 10910 #ifdef FEAT_FOLDING 10911 case PV_FDC: return (char_u *)&(curwin->w_p_fdc); 10912 case PV_FEN: return (char_u *)&(curwin->w_p_fen); 10913 case PV_FDI: return (char_u *)&(curwin->w_p_fdi); 10914 case PV_FDL: return (char_u *)&(curwin->w_p_fdl); 10915 case PV_FDM: return (char_u *)&(curwin->w_p_fdm); 10916 case PV_FML: return (char_u *)&(curwin->w_p_fml); 10917 case PV_FDN: return (char_u *)&(curwin->w_p_fdn); 10918 # ifdef FEAT_EVAL 10919 case PV_FDE: return (char_u *)&(curwin->w_p_fde); 10920 case PV_FDT: return (char_u *)&(curwin->w_p_fdt); 10921 # endif 10922 case PV_FMR: return (char_u *)&(curwin->w_p_fmr); 10923 #endif 10924 case PV_NU: return (char_u *)&(curwin->w_p_nu); 10925 case PV_RNU: return (char_u *)&(curwin->w_p_rnu); 10926 #ifdef FEAT_LINEBREAK 10927 case PV_NUW: return (char_u *)&(curwin->w_p_nuw); 10928 #endif 10929 case PV_WFH: return (char_u *)&(curwin->w_p_wfh); 10930 case PV_WFW: return (char_u *)&(curwin->w_p_wfw); 10931 #if defined(FEAT_QUICKFIX) 10932 case PV_PVW: return (char_u *)&(curwin->w_p_pvw); 10933 #endif 10934 #ifdef FEAT_RIGHTLEFT 10935 case PV_RL: return (char_u *)&(curwin->w_p_rl); 10936 case PV_RLC: return (char_u *)&(curwin->w_p_rlc); 10937 #endif 10938 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr); 10939 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap); 10940 #ifdef FEAT_LINEBREAK 10941 case PV_LBR: return (char_u *)&(curwin->w_p_lbr); 10942 case PV_BRI: return (char_u *)&(curwin->w_p_bri); 10943 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt); 10944 #endif 10945 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb); 10946 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb); 10947 #ifdef FEAT_CONCEAL 10948 case PV_COCU: return (char_u *)&(curwin->w_p_cocu); 10949 case PV_COLE: return (char_u *)&(curwin->w_p_cole); 10950 #endif 10951 #ifdef FEAT_TERMINAL 10952 case PV_TWK: return (char_u *)&(curwin->w_p_twk); 10953 case PV_TWS: return (char_u *)&(curwin->w_p_tws); 10954 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl); 10955 case PV_TMOD: return (char_u *)&(curwin->w_p_tmod); 10956 #endif 10957 10958 case PV_AI: return (char_u *)&(curbuf->b_p_ai); 10959 case PV_BIN: return (char_u *)&(curbuf->b_p_bin); 10960 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb); 10961 case PV_BH: return (char_u *)&(curbuf->b_p_bh); 10962 case PV_BT: return (char_u *)&(curbuf->b_p_bt); 10963 case PV_BL: return (char_u *)&(curbuf->b_p_bl); 10964 case PV_CI: return (char_u *)&(curbuf->b_p_ci); 10965 #ifdef FEAT_CINDENT 10966 case PV_CIN: return (char_u *)&(curbuf->b_p_cin); 10967 case PV_CINK: return (char_u *)&(curbuf->b_p_cink); 10968 case PV_CINO: return (char_u *)&(curbuf->b_p_cino); 10969 #endif 10970 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 10971 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); 10972 #endif 10973 #ifdef FEAT_COMMENTS 10974 case PV_COM: return (char_u *)&(curbuf->b_p_com); 10975 #endif 10976 #ifdef FEAT_FOLDING 10977 case PV_CMS: return (char_u *)&(curbuf->b_p_cms); 10978 #endif 10979 #ifdef FEAT_INS_EXPAND 10980 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); 10981 #endif 10982 #ifdef FEAT_COMPL_FUNC 10983 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); 10984 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); 10985 #endif 10986 case PV_EOL: return (char_u *)&(curbuf->b_p_eol); 10987 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol); 10988 case PV_ET: return (char_u *)&(curbuf->b_p_et); 10989 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc); 10990 case PV_FF: return (char_u *)&(curbuf->b_p_ff); 10991 case PV_FT: return (char_u *)&(curbuf->b_p_ft); 10992 case PV_FO: return (char_u *)&(curbuf->b_p_fo); 10993 case PV_FLP: return (char_u *)&(curbuf->b_p_flp); 10994 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert); 10995 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch); 10996 case PV_INF: return (char_u *)&(curbuf->b_p_inf); 10997 case PV_ISK: return (char_u *)&(curbuf->b_p_isk); 10998 #ifdef FEAT_FIND_ID 10999 # ifdef FEAT_EVAL 11000 case PV_INEX: return (char_u *)&(curbuf->b_p_inex); 11001 # endif 11002 #endif 11003 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 11004 case PV_INDE: return (char_u *)&(curbuf->b_p_inde); 11005 case PV_INDK: return (char_u *)&(curbuf->b_p_indk); 11006 #endif 11007 #ifdef FEAT_EVAL 11008 case PV_FEX: return (char_u *)&(curbuf->b_p_fex); 11009 #endif 11010 #ifdef FEAT_CRYPT 11011 case PV_KEY: return (char_u *)&(curbuf->b_p_key); 11012 #endif 11013 #ifdef FEAT_LISP 11014 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); 11015 #endif 11016 case PV_ML: return (char_u *)&(curbuf->b_p_ml); 11017 case PV_MPS: return (char_u *)&(curbuf->b_p_mps); 11018 case PV_MA: return (char_u *)&(curbuf->b_p_ma); 11019 case PV_MOD: return (char_u *)&(curbuf->b_changed); 11020 case PV_NF: return (char_u *)&(curbuf->b_p_nf); 11021 case PV_PI: return (char_u *)&(curbuf->b_p_pi); 11022 #ifdef FEAT_TEXTOBJ 11023 case PV_QE: return (char_u *)&(curbuf->b_p_qe); 11024 #endif 11025 case PV_RO: return (char_u *)&(curbuf->b_p_ro); 11026 #ifdef FEAT_SMARTINDENT 11027 case PV_SI: return (char_u *)&(curbuf->b_p_si); 11028 #endif 11029 case PV_SN: return (char_u *)&(curbuf->b_p_sn); 11030 case PV_STS: return (char_u *)&(curbuf->b_p_sts); 11031 #ifdef FEAT_SEARCHPATH 11032 case PV_SUA: return (char_u *)&(curbuf->b_p_sua); 11033 #endif 11034 case PV_SWF: return (char_u *)&(curbuf->b_p_swf); 11035 #ifdef FEAT_SYN_HL 11036 case PV_SMC: return (char_u *)&(curbuf->b_p_smc); 11037 case PV_SYN: return (char_u *)&(curbuf->b_p_syn); 11038 #endif 11039 #ifdef FEAT_SPELL 11040 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc); 11041 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf); 11042 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl); 11043 #endif 11044 case PV_SW: return (char_u *)&(curbuf->b_p_sw); 11045 case PV_TS: return (char_u *)&(curbuf->b_p_ts); 11046 case PV_TW: return (char_u *)&(curbuf->b_p_tw); 11047 case PV_TX: return (char_u *)&(curbuf->b_p_tx); 11048 #ifdef FEAT_PERSISTENT_UNDO 11049 case PV_UDF: return (char_u *)&(curbuf->b_p_udf); 11050 #endif 11051 case PV_WM: return (char_u *)&(curbuf->b_p_wm); 11052 #ifdef FEAT_KEYMAP 11053 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap); 11054 #endif 11055 #ifdef FEAT_SIGNS 11056 case PV_SCL: return (char_u *)&(curwin->w_p_scl); 11057 #endif 11058 #ifdef FEAT_VARTABS 11059 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts); 11060 case PV_VTS: return (char_u *)&(curbuf->b_p_vts); 11061 #endif 11062 default: iemsg(_("E356: get_varp ERROR")); 11063 } 11064 /* always return a valid pointer to avoid a crash! */ 11065 return (char_u *)&(curbuf->b_p_wm); 11066 } 11067 11068 /* 11069 * Get the value of 'equalprg', either the buffer-local one or the global one. 11070 */ 11071 char_u * 11072 get_equalprg(void) 11073 { 11074 if (*curbuf->b_p_ep == NUL) 11075 return p_ep; 11076 return curbuf->b_p_ep; 11077 } 11078 11079 /* 11080 * Copy options from one window to another. 11081 * Used when splitting a window. 11082 */ 11083 void 11084 win_copy_options(win_T *wp_from, win_T *wp_to) 11085 { 11086 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt); 11087 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt); 11088 # ifdef FEAT_RIGHTLEFT 11089 # ifdef FEAT_FKMAP 11090 /* Is this right? */ 11091 wp_to->w_farsi = wp_from->w_farsi; 11092 # endif 11093 # endif 11094 #if defined(FEAT_LINEBREAK) 11095 briopt_check(wp_to); 11096 #endif 11097 } 11098 11099 /* 11100 * Copy the options from one winopt_T to another. 11101 * Doesn't free the old option values in "to", use clear_winopt() for that. 11102 * The 'scroll' option is not copied, because it depends on the window height. 11103 * The 'previewwindow' option is reset, there can be only one preview window. 11104 */ 11105 void 11106 copy_winopt(winopt_T *from, winopt_T *to) 11107 { 11108 #ifdef FEAT_ARABIC 11109 to->wo_arab = from->wo_arab; 11110 #endif 11111 to->wo_list = from->wo_list; 11112 to->wo_nu = from->wo_nu; 11113 to->wo_rnu = from->wo_rnu; 11114 #ifdef FEAT_LINEBREAK 11115 to->wo_nuw = from->wo_nuw; 11116 #endif 11117 #ifdef FEAT_RIGHTLEFT 11118 to->wo_rl = from->wo_rl; 11119 to->wo_rlc = vim_strsave(from->wo_rlc); 11120 #endif 11121 #ifdef FEAT_STL_OPT 11122 to->wo_stl = vim_strsave(from->wo_stl); 11123 #endif 11124 to->wo_wrap = from->wo_wrap; 11125 #ifdef FEAT_DIFF 11126 to->wo_wrap_save = from->wo_wrap_save; 11127 #endif 11128 #ifdef FEAT_LINEBREAK 11129 to->wo_lbr = from->wo_lbr; 11130 to->wo_bri = from->wo_bri; 11131 to->wo_briopt = vim_strsave(from->wo_briopt); 11132 #endif 11133 to->wo_scb = from->wo_scb; 11134 to->wo_scb_save = from->wo_scb_save; 11135 to->wo_crb = from->wo_crb; 11136 to->wo_crb_save = from->wo_crb_save; 11137 #ifdef FEAT_SPELL 11138 to->wo_spell = from->wo_spell; 11139 #endif 11140 #ifdef FEAT_SYN_HL 11141 to->wo_cuc = from->wo_cuc; 11142 to->wo_cul = from->wo_cul; 11143 to->wo_cc = vim_strsave(from->wo_cc); 11144 #endif 11145 #ifdef FEAT_DIFF 11146 to->wo_diff = from->wo_diff; 11147 to->wo_diff_saved = from->wo_diff_saved; 11148 #endif 11149 #ifdef FEAT_CONCEAL 11150 to->wo_cocu = vim_strsave(from->wo_cocu); 11151 to->wo_cole = from->wo_cole; 11152 #endif 11153 #ifdef FEAT_TERMINAL 11154 to->wo_twk = vim_strsave(from->wo_twk); 11155 to->wo_tws = vim_strsave(from->wo_tws); 11156 to->wo_tmod = vim_strsave(from->wo_tmod); 11157 #endif 11158 #ifdef FEAT_FOLDING 11159 to->wo_fdc = from->wo_fdc; 11160 to->wo_fdc_save = from->wo_fdc_save; 11161 to->wo_fen = from->wo_fen; 11162 to->wo_fen_save = from->wo_fen_save; 11163 to->wo_fdi = vim_strsave(from->wo_fdi); 11164 to->wo_fml = from->wo_fml; 11165 to->wo_fdl = from->wo_fdl; 11166 to->wo_fdl_save = from->wo_fdl_save; 11167 to->wo_fdm = vim_strsave(from->wo_fdm); 11168 to->wo_fdm_save = from->wo_diff_saved 11169 ? vim_strsave(from->wo_fdm_save) : empty_option; 11170 to->wo_fdn = from->wo_fdn; 11171 # ifdef FEAT_EVAL 11172 to->wo_fde = vim_strsave(from->wo_fde); 11173 to->wo_fdt = vim_strsave(from->wo_fdt); 11174 # endif 11175 to->wo_fmr = vim_strsave(from->wo_fmr); 11176 #endif 11177 #ifdef FEAT_SIGNS 11178 to->wo_scl = vim_strsave(from->wo_scl); 11179 #endif 11180 check_winopt(to); /* don't want NULL pointers */ 11181 } 11182 11183 /* 11184 * Check string options in a window for a NULL value. 11185 */ 11186 void 11187 check_win_options(win_T *win) 11188 { 11189 check_winopt(&win->w_onebuf_opt); 11190 check_winopt(&win->w_allbuf_opt); 11191 } 11192 11193 /* 11194 * Check for NULL pointers in a winopt_T and replace them with empty_option. 11195 */ 11196 static void 11197 check_winopt(winopt_T *wop UNUSED) 11198 { 11199 #ifdef FEAT_FOLDING 11200 check_string_option(&wop->wo_fdi); 11201 check_string_option(&wop->wo_fdm); 11202 check_string_option(&wop->wo_fdm_save); 11203 # ifdef FEAT_EVAL 11204 check_string_option(&wop->wo_fde); 11205 check_string_option(&wop->wo_fdt); 11206 # endif 11207 check_string_option(&wop->wo_fmr); 11208 #endif 11209 #ifdef FEAT_SIGNS 11210 check_string_option(&wop->wo_scl); 11211 #endif 11212 #ifdef FEAT_RIGHTLEFT 11213 check_string_option(&wop->wo_rlc); 11214 #endif 11215 #ifdef FEAT_STL_OPT 11216 check_string_option(&wop->wo_stl); 11217 #endif 11218 #ifdef FEAT_SYN_HL 11219 check_string_option(&wop->wo_cc); 11220 #endif 11221 #ifdef FEAT_CONCEAL 11222 check_string_option(&wop->wo_cocu); 11223 #endif 11224 #ifdef FEAT_TERMINAL 11225 check_string_option(&wop->wo_twk); 11226 check_string_option(&wop->wo_tws); 11227 check_string_option(&wop->wo_tmod); 11228 #endif 11229 #ifdef FEAT_LINEBREAK 11230 check_string_option(&wop->wo_briopt); 11231 #endif 11232 } 11233 11234 /* 11235 * Free the allocated memory inside a winopt_T. 11236 */ 11237 void 11238 clear_winopt(winopt_T *wop UNUSED) 11239 { 11240 #ifdef FEAT_FOLDING 11241 clear_string_option(&wop->wo_fdi); 11242 clear_string_option(&wop->wo_fdm); 11243 clear_string_option(&wop->wo_fdm_save); 11244 # ifdef FEAT_EVAL 11245 clear_string_option(&wop->wo_fde); 11246 clear_string_option(&wop->wo_fdt); 11247 # endif 11248 clear_string_option(&wop->wo_fmr); 11249 #endif 11250 #ifdef FEAT_SIGNS 11251 clear_string_option(&wop->wo_scl); 11252 #endif 11253 #ifdef FEAT_LINEBREAK 11254 clear_string_option(&wop->wo_briopt); 11255 #endif 11256 #ifdef FEAT_RIGHTLEFT 11257 clear_string_option(&wop->wo_rlc); 11258 #endif 11259 #ifdef FEAT_STL_OPT 11260 clear_string_option(&wop->wo_stl); 11261 #endif 11262 #ifdef FEAT_SYN_HL 11263 clear_string_option(&wop->wo_cc); 11264 #endif 11265 #ifdef FEAT_CONCEAL 11266 clear_string_option(&wop->wo_cocu); 11267 #endif 11268 #ifdef FEAT_TERMINAL 11269 clear_string_option(&wop->wo_twk); 11270 clear_string_option(&wop->wo_tws); 11271 clear_string_option(&wop->wo_tmod); 11272 #endif 11273 } 11274 11275 /* 11276 * Copy global option values to local options for one buffer. 11277 * Used when creating a new buffer and sometimes when entering a buffer. 11278 * flags: 11279 * BCO_ENTER We will enter the buf buffer. 11280 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when 11281 * appropriate. 11282 * BCO_NOHELP Don't copy the values to a help buffer. 11283 */ 11284 void 11285 buf_copy_options(buf_T *buf, int flags) 11286 { 11287 int should_copy = TRUE; 11288 char_u *save_p_isk = NULL; /* init for GCC */ 11289 int dont_do_help; 11290 int did_isk = FALSE; 11291 11292 /* 11293 * Skip this when the option defaults have not been set yet. Happens when 11294 * main() allocates the first buffer. 11295 */ 11296 if (p_cpo != NULL) 11297 { 11298 /* 11299 * Always copy when entering and 'cpo' contains 'S'. 11300 * Don't copy when already initialized. 11301 * Don't copy when 'cpo' contains 's' and not entering. 11302 * 'S' BCO_ENTER initialized 's' should_copy 11303 * yes yes X X TRUE 11304 * yes no yes X FALSE 11305 * no X yes X FALSE 11306 * X no no yes FALSE 11307 * X no no no TRUE 11308 * no yes no X TRUE 11309 */ 11310 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER)) 11311 && (buf->b_p_initialized 11312 || (!(flags & BCO_ENTER) 11313 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) 11314 should_copy = FALSE; 11315 11316 if (should_copy || (flags & BCO_ALWAYS)) 11317 { 11318 /* Don't copy the options specific to a help buffer when 11319 * BCO_NOHELP is given or the options were initialized already 11320 * (jumping back to a help file with CTRL-T or CTRL-O) */ 11321 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) 11322 || buf->b_p_initialized; 11323 if (dont_do_help) /* don't free b_p_isk */ 11324 { 11325 save_p_isk = buf->b_p_isk; 11326 buf->b_p_isk = NULL; 11327 } 11328 /* 11329 * Always free the allocated strings. If not already initialized, 11330 * reset 'readonly' and copy 'fileformat'. 11331 */ 11332 if (!buf->b_p_initialized) 11333 { 11334 free_buf_options(buf, TRUE); 11335 buf->b_p_ro = FALSE; /* don't copy readonly */ 11336 buf->b_p_tx = p_tx; 11337 buf->b_p_fenc = vim_strsave(p_fenc); 11338 switch (*p_ffs) 11339 { 11340 case 'm': 11341 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break; 11342 case 'd': 11343 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break; 11344 case 'u': 11345 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break; 11346 default: 11347 buf->b_p_ff = vim_strsave(p_ff); 11348 } 11349 if (buf->b_p_ff != NULL) 11350 buf->b_start_ffc = *buf->b_p_ff; 11351 buf->b_p_bh = empty_option; 11352 buf->b_p_bt = empty_option; 11353 } 11354 else 11355 free_buf_options(buf, FALSE); 11356 11357 buf->b_p_ai = p_ai; 11358 buf->b_p_ai_nopaste = p_ai_nopaste; 11359 buf->b_p_sw = p_sw; 11360 buf->b_p_tw = p_tw; 11361 buf->b_p_tw_nopaste = p_tw_nopaste; 11362 buf->b_p_tw_nobin = p_tw_nobin; 11363 buf->b_p_wm = p_wm; 11364 buf->b_p_wm_nopaste = p_wm_nopaste; 11365 buf->b_p_wm_nobin = p_wm_nobin; 11366 buf->b_p_bin = p_bin; 11367 buf->b_p_bomb = p_bomb; 11368 buf->b_p_fixeol = p_fixeol; 11369 buf->b_p_et = p_et; 11370 buf->b_p_et_nobin = p_et_nobin; 11371 buf->b_p_et_nopaste = p_et_nopaste; 11372 buf->b_p_ml = p_ml; 11373 buf->b_p_ml_nobin = p_ml_nobin; 11374 buf->b_p_inf = p_inf; 11375 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf; 11376 #ifdef FEAT_INS_EXPAND 11377 buf->b_p_cpt = vim_strsave(p_cpt); 11378 #endif 11379 #ifdef FEAT_COMPL_FUNC 11380 buf->b_p_cfu = vim_strsave(p_cfu); 11381 buf->b_p_ofu = vim_strsave(p_ofu); 11382 #endif 11383 buf->b_p_sts = p_sts; 11384 buf->b_p_sts_nopaste = p_sts_nopaste; 11385 #ifdef FEAT_VARTABS 11386 buf->b_p_vsts = vim_strsave(p_vsts); 11387 if (p_vsts && p_vsts != empty_option) 11388 tabstop_set(p_vsts, &buf->b_p_vsts_array); 11389 else 11390 buf->b_p_vsts_array = 0; 11391 buf->b_p_vsts_nopaste = p_vsts_nopaste 11392 ? vim_strsave(p_vsts_nopaste) : NULL; 11393 #endif 11394 buf->b_p_sn = p_sn; 11395 #ifdef FEAT_COMMENTS 11396 buf->b_p_com = vim_strsave(p_com); 11397 #endif 11398 #ifdef FEAT_FOLDING 11399 buf->b_p_cms = vim_strsave(p_cms); 11400 #endif 11401 buf->b_p_fo = vim_strsave(p_fo); 11402 buf->b_p_flp = vim_strsave(p_flp); 11403 buf->b_p_nf = vim_strsave(p_nf); 11404 buf->b_p_mps = vim_strsave(p_mps); 11405 #ifdef FEAT_SMARTINDENT 11406 buf->b_p_si = p_si; 11407 #endif 11408 buf->b_p_ci = p_ci; 11409 #ifdef FEAT_CINDENT 11410 buf->b_p_cin = p_cin; 11411 buf->b_p_cink = vim_strsave(p_cink); 11412 buf->b_p_cino = vim_strsave(p_cino); 11413 #endif 11414 /* Don't copy 'filetype', it must be detected */ 11415 buf->b_p_ft = empty_option; 11416 buf->b_p_pi = p_pi; 11417 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) 11418 buf->b_p_cinw = vim_strsave(p_cinw); 11419 #endif 11420 #ifdef FEAT_LISP 11421 buf->b_p_lisp = p_lisp; 11422 #endif 11423 #ifdef FEAT_SYN_HL 11424 /* Don't copy 'syntax', it must be set */ 11425 buf->b_p_syn = empty_option; 11426 buf->b_p_smc = p_smc; 11427 buf->b_s.b_syn_isk = empty_option; 11428 #endif 11429 #ifdef FEAT_SPELL 11430 buf->b_s.b_p_spc = vim_strsave(p_spc); 11431 (void)compile_cap_prog(&buf->b_s); 11432 buf->b_s.b_p_spf = vim_strsave(p_spf); 11433 buf->b_s.b_p_spl = vim_strsave(p_spl); 11434 #endif 11435 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) 11436 buf->b_p_inde = vim_strsave(p_inde); 11437 buf->b_p_indk = vim_strsave(p_indk); 11438 #endif 11439 buf->b_p_fp = empty_option; 11440 #if defined(FEAT_EVAL) 11441 buf->b_p_fex = vim_strsave(p_fex); 11442 #endif 11443 #ifdef FEAT_CRYPT 11444 buf->b_p_key = vim_strsave(p_key); 11445 #endif 11446 #ifdef FEAT_SEARCHPATH 11447 buf->b_p_sua = vim_strsave(p_sua); 11448 #endif 11449 #ifdef FEAT_KEYMAP 11450 buf->b_p_keymap = vim_strsave(p_keymap); 11451 buf->b_kmap_state |= KEYMAP_INIT; 11452 #endif 11453 #ifdef FEAT_TERMINAL 11454 buf->b_p_twsl = p_twsl; 11455 #endif 11456 /* This isn't really an option, but copying the langmap and IME 11457 * state from the current buffer is better than resetting it. */ 11458 buf->b_p_iminsert = p_iminsert; 11459 buf->b_p_imsearch = p_imsearch; 11460 11461 /* options that are normally global but also have a local value 11462 * are not copied, start using the global value */ 11463 buf->b_p_ar = -1; 11464 buf->b_p_ul = NO_LOCAL_UNDOLEVEL; 11465 buf->b_p_bkc = empty_option; 11466 buf->b_bkc_flags = 0; 11467 #ifdef FEAT_QUICKFIX 11468 buf->b_p_gp = empty_option; 11469 buf->b_p_mp = empty_option; 11470 buf->b_p_efm = empty_option; 11471 #endif 11472 buf->b_p_ep = empty_option; 11473 buf->b_p_kp = empty_option; 11474 buf->b_p_path = empty_option; 11475 buf->b_p_tags = empty_option; 11476 buf->b_p_tc = empty_option; 11477 buf->b_tc_flags = 0; 11478 #ifdef FEAT_FIND_ID 11479 buf->b_p_def = empty_option; 11480 buf->b_p_inc = empty_option; 11481 # ifdef FEAT_EVAL 11482 buf->b_p_inex = vim_strsave(p_inex); 11483 # endif 11484 #endif 11485 #ifdef FEAT_INS_EXPAND 11486 buf->b_p_dict = empty_option; 11487 buf->b_p_tsr = empty_option; 11488 #endif 11489 #ifdef FEAT_TEXTOBJ 11490 buf->b_p_qe = vim_strsave(p_qe); 11491 #endif 11492 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) 11493 buf->b_p_bexpr = empty_option; 11494 #endif 11495 #if defined(FEAT_CRYPT) 11496 buf->b_p_cm = empty_option; 11497 #endif 11498 #ifdef FEAT_PERSISTENT_UNDO 11499 buf->b_p_udf = p_udf; 11500 #endif 11501 #ifdef FEAT_LISP 11502 buf->b_p_lw = empty_option; 11503 #endif 11504 buf->b_p_menc = empty_option; 11505 11506 /* 11507 * Don't copy the options set by ex_help(), use the saved values, 11508 * when going from a help buffer to a non-help buffer. 11509 * Don't touch these at all when BCO_NOHELP is used and going from 11510 * or to a help buffer. 11511 */ 11512 if (dont_do_help) 11513 { 11514 buf->b_p_isk = save_p_isk; 11515 #ifdef FEAT_VARTABS 11516 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) 11517 tabstop_set(p_vts, &buf->b_p_vts_array); 11518 else 11519 buf->b_p_vts_array = NULL; 11520 #endif 11521 } 11522 else 11523 { 11524 buf->b_p_isk = vim_strsave(p_isk); 11525 did_isk = TRUE; 11526 buf->b_p_ts = p_ts; 11527 #ifdef FEAT_VARTABS 11528 buf->b_p_vts = vim_strsave(p_vts); 11529 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) 11530 tabstop_set(p_vts, &buf->b_p_vts_array); 11531 else 11532 buf->b_p_vts_array = NULL; 11533 #endif 11534 buf->b_help = FALSE; 11535 if (buf->b_p_bt[0] == 'h') 11536 clear_string_option(&buf->b_p_bt); 11537 buf->b_p_ma = p_ma; 11538 } 11539 } 11540 11541 /* 11542 * When the options should be copied (ignoring BCO_ALWAYS), set the 11543 * flag that indicates that the options have been initialized. 11544 */ 11545 if (should_copy) 11546 buf->b_p_initialized = TRUE; 11547 } 11548 11549 check_buf_options(buf); /* make sure we don't have NULLs */ 11550 if (did_isk) 11551 (void)buf_init_chartab(buf, FALSE); 11552 } 11553 11554 /* 11555 * Reset the 'modifiable' option and its default value. 11556 */ 11557 void 11558 reset_modifiable(void) 11559 { 11560 int opt_idx; 11561 11562 curbuf->b_p_ma = FALSE; 11563 p_ma = FALSE; 11564 opt_idx = findoption((char_u *)"ma"); 11565 if (opt_idx >= 0) 11566 options[opt_idx].def_val[VI_DEFAULT] = FALSE; 11567 } 11568 11569 /* 11570 * Set the global value for 'iminsert' to the local value. 11571 */ 11572 void 11573 set_iminsert_global(void) 11574 { 11575 p_iminsert = curbuf->b_p_iminsert; 11576 } 11577 11578 /* 11579 * Set the global value for 'imsearch' to the local value. 11580 */ 11581 void 11582 set_imsearch_global(void) 11583 { 11584 p_imsearch = curbuf->b_p_imsearch; 11585 } 11586 11587 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) 11588 static int expand_option_idx = -1; 11589 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL}; 11590 static int expand_option_flags = 0; 11591 11592 void 11593 set_context_in_set_cmd( 11594 expand_T *xp, 11595 char_u *arg, 11596 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */ 11597 { 11598 int nextchar; 11599 long_u flags = 0; /* init for GCC */ 11600 int opt_idx = 0; /* init for GCC */ 11601 char_u *p; 11602 char_u *s; 11603 int is_term_option = FALSE; 11604 int key; 11605 11606 expand_option_flags = opt_flags; 11607 11608 xp->xp_context = EXPAND_SETTINGS; 11609 if (*arg == NUL) 11610 { 11611 xp->xp_pattern = arg; 11612 return; 11613 } 11614 p = arg + STRLEN(arg) - 1; 11615 if (*p == ' ' && *(p - 1) != '\\') 11616 { 11617 xp->xp_pattern = p + 1; 11618 return; 11619 } 11620 while (p > arg) 11621 { 11622 s = p; 11623 /* count number of backslashes before ' ' or ',' */ 11624 if (*p == ' ' || *p == ',') 11625 { 11626 while (s > arg && *(s - 1) == '\\') 11627 --s; 11628 } 11629 /* break at a space with an even number of backslashes */ 11630 if (*p == ' ' && ((p - s) & 1) == 0) 11631 { 11632 ++p; 11633 break; 11634 } 11635 --p; 11636 } 11637 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0) 11638 { 11639 xp->xp_context = EXPAND_BOOL_SETTINGS; 11640 p += 2; 11641 } 11642 if (STRNCMP(p, "inv", 3) == 0) 11643 { 11644 xp->xp_context = EXPAND_BOOL_SETTINGS; 11645 p += 3; 11646 } 11647 xp->xp_pattern = arg = p; 11648 if (*arg == '<') 11649 { 11650 while (*p != '>') 11651 if (*p++ == NUL) /* expand terminal option name */ 11652 return; 11653 key = get_special_key_code(arg + 1); 11654 if (key == 0) /* unknown name */ 11655 { 11656 xp->xp_context = EXPAND_NOTHING; 11657 return; 11658 } 11659 nextchar = *++p; 11660 is_term_option = TRUE; 11661 expand_option_name[2] = KEY2TERMCAP0(key); 11662 expand_option_name[3] = KEY2TERMCAP1(key); 11663 } 11664 else 11665 { 11666 if (p[0] == 't' && p[1] == '_') 11667 { 11668 p += 2; 11669 if (*p != NUL) 11670 ++p; 11671 if (*p == NUL) 11672 return; /* expand option name */ 11673 nextchar = *++p; 11674 is_term_option = TRUE; 11675 expand_option_name[2] = p[-2]; 11676 expand_option_name[3] = p[-1]; 11677 } 11678 else 11679 { 11680 /* Allow * wildcard */ 11681 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') 11682 p++; 11683 if (*p == NUL) 11684 return; 11685 nextchar = *p; 11686 *p = NUL; 11687 opt_idx = findoption(arg); 11688 *p = nextchar; 11689 if (opt_idx == -1 || options[opt_idx].var == NULL) 11690 { 11691 xp->xp_context = EXPAND_NOTHING; 11692 return; 11693 } 11694 flags = options[opt_idx].flags; 11695 if (flags & P_BOOL) 11696 { 11697 xp->xp_context = EXPAND_NOTHING; 11698 return; 11699 } 11700 } 11701 } 11702 /* handle "-=" and "+=" */ 11703 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=') 11704 { 11705 ++p; 11706 nextchar = '='; 11707 } 11708 if ((nextchar != '=' && nextchar != ':') 11709 || xp->xp_context == EXPAND_BOOL_SETTINGS) 11710 { 11711 xp->xp_context = EXPAND_UNSUCCESSFUL; 11712 return; 11713 } 11714 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL) 11715 { 11716 xp->xp_context = EXPAND_OLD_SETTING; 11717 if (is_term_option) 11718 expand_option_idx = -1; 11719 else 11720 expand_option_idx = opt_idx; 11721 xp->xp_pattern = p + 1; 11722 return; 11723 } 11724 xp->xp_context = EXPAND_NOTHING; 11725 if (is_term_option || (flags & P_NUM)) 11726 return; 11727 11728 xp->xp_pattern = p + 1; 11729 11730 if (flags & P_EXPAND) 11731 { 11732 p = options[opt_idx].var; 11733 if (p == (char_u *)&p_bdir 11734 || p == (char_u *)&p_dir 11735 || p == (char_u *)&p_path 11736 || p == (char_u *)&p_pp 11737 || p == (char_u *)&p_rtp 11738 #ifdef FEAT_SEARCHPATH 11739 || p == (char_u *)&p_cdpath 11740 #endif 11741 #ifdef FEAT_SESSION 11742 || p == (char_u *)&p_vdir 11743 #endif 11744 ) 11745 { 11746 xp->xp_context = EXPAND_DIRECTORIES; 11747 if (p == (char_u *)&p_path 11748 #ifdef FEAT_SEARCHPATH 11749 || p == (char_u *)&p_cdpath 11750 #endif 11751 ) 11752 xp->xp_backslash = XP_BS_THREE; 11753 else 11754 xp->xp_backslash = XP_BS_ONE; 11755 } 11756 else 11757 { 11758 xp->xp_context = EXPAND_FILES; 11759 /* for 'tags' need three backslashes for a space */ 11760 if (p == (char_u *)&p_tags) 11761 xp->xp_backslash = XP_BS_THREE; 11762 else 11763 xp->xp_backslash = XP_BS_ONE; 11764 } 11765 } 11766 11767 /* For an option that is a list of file names, find the start of the 11768 * last file name. */ 11769 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p) 11770 { 11771 /* count number of backslashes before ' ' or ',' */ 11772 if (*p == ' ' || *p == ',') 11773 { 11774 s = p; 11775 while (s > xp->xp_pattern && *(s - 1) == '\\') 11776 --s; 11777 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3)) 11778 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0)) 11779 { 11780 xp->xp_pattern = p + 1; 11781 break; 11782 } 11783 } 11784 11785 #ifdef FEAT_SPELL 11786 /* for 'spellsuggest' start at "file:" */ 11787 if (options[opt_idx].var == (char_u *)&p_sps 11788 && STRNCMP(p, "file:", 5) == 0) 11789 { 11790 xp->xp_pattern = p + 5; 11791 break; 11792 } 11793 #endif 11794 } 11795 11796 return; 11797 } 11798 11799 int 11800 ExpandSettings( 11801 expand_T *xp, 11802 regmatch_T *regmatch, 11803 int *num_file, 11804 char_u ***file) 11805 { 11806 int num_normal = 0; /* Nr of matching non-term-code settings */ 11807 int num_term = 0; /* Nr of matching terminal code settings */ 11808 int opt_idx; 11809 int match; 11810 int count = 0; 11811 char_u *str; 11812 int loop; 11813 int is_term_opt; 11814 char_u name_buf[MAX_KEY_NAME_LEN]; 11815 static char *(names[]) = {"all", "termcap"}; 11816 int ic = regmatch->rm_ic; /* remember the ignore-case flag */ 11817 11818 /* do this loop twice: 11819 * loop == 0: count the number of matching options 11820 * loop == 1: copy the matching options into allocated memory 11821 */ 11822 for (loop = 0; loop <= 1; ++loop) 11823 { 11824 regmatch->rm_ic = ic; 11825 if (xp->xp_context != EXPAND_BOOL_SETTINGS) 11826 { 11827 for (match = 0; match < (int)(sizeof(names) / sizeof(char *)); 11828 ++match) 11829 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0)) 11830 { 11831 if (loop == 0) 11832 num_normal++; 11833 else 11834 (*file)[count++] = vim_strsave((char_u *)names[match]); 11835 } 11836 } 11837 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; 11838 opt_idx++) 11839 { 11840 if (options[opt_idx].var == NULL) 11841 continue; 11842 if (xp->xp_context == EXPAND_BOOL_SETTINGS 11843 && !(options[opt_idx].flags & P_BOOL)) 11844 continue; 11845 is_term_opt = istermoption(&options[opt_idx]); 11846 if (is_term_opt && num_normal > 0) 11847 continue; 11848 match = FALSE; 11849 if (vim_regexec(regmatch, str, (colnr_T)0) 11850 || (options[opt_idx].shortname != NULL 11851 && vim_regexec(regmatch, 11852 (char_u *)options[opt_idx].shortname, (colnr_T)0))) 11853 match = TRUE; 11854 else if (is_term_opt) 11855 { 11856 name_buf[0] = '<'; 11857 name_buf[1] = 't'; 11858 name_buf[2] = '_'; 11859 name_buf[3] = str[2]; 11860 name_buf[4] = str[3]; 11861 name_buf[5] = '>'; 11862 name_buf[6] = NUL; 11863 if (vim_regexec(regmatch, name_buf, (colnr_T)0)) 11864 { 11865 match = TRUE; 11866 str = name_buf; 11867 } 11868 } 11869 if (match) 11870 { 11871 if (loop == 0) 11872 { 11873 if (is_term_opt) 11874 num_term++; 11875 else 11876 num_normal++; 11877 } 11878 else 11879 (*file)[count++] = vim_strsave(str); 11880 } 11881 } 11882 /* 11883 * Check terminal key codes, these are not in the option table 11884 */ 11885 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0) 11886 { 11887 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++) 11888 { 11889 if (!isprint(str[0]) || !isprint(str[1])) 11890 continue; 11891 11892 name_buf[0] = 't'; 11893 name_buf[1] = '_'; 11894 name_buf[2] = str[0]; 11895 name_buf[3] = str[1]; 11896 name_buf[4] = NUL; 11897 11898 match = FALSE; 11899 if (vim_regexec(regmatch, name_buf, (colnr_T)0)) 11900 match = TRUE; 11901 else 11902 { 11903 name_buf[0] = '<'; 11904 name_buf[1] = 't'; 11905 name_buf[2] = '_'; 11906 name_buf[3] = str[0]; 11907 name_buf[4] = str[1]; 11908 name_buf[5] = '>'; 11909 name_buf[6] = NUL; 11910 11911 if (vim_regexec(regmatch, name_buf, (colnr_T)0)) 11912 match = TRUE; 11913 } 11914 if (match) 11915 { 11916 if (loop == 0) 11917 num_term++; 11918 else 11919 (*file)[count++] = vim_strsave(name_buf); 11920 } 11921 } 11922 11923 /* 11924 * Check special key names. 11925 */ 11926 regmatch->rm_ic = TRUE; /* ignore case here */ 11927 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) 11928 { 11929 name_buf[0] = '<'; 11930 STRCPY(name_buf + 1, str); 11931 STRCAT(name_buf, ">"); 11932 11933 if (vim_regexec(regmatch, name_buf, (colnr_T)0)) 11934 { 11935 if (loop == 0) 11936 num_term++; 11937 else 11938 (*file)[count++] = vim_strsave(name_buf); 11939 } 11940 } 11941 } 11942 if (loop == 0) 11943 { 11944 if (num_normal > 0) 11945 *num_file = num_normal; 11946 else if (num_term > 0) 11947 *num_file = num_term; 11948 else 11949 return OK; 11950 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *))); 11951 if (*file == NULL) 11952 { 11953 *file = (char_u **)""; 11954 return FAIL; 11955 } 11956 } 11957 } 11958 return OK; 11959 } 11960 11961 int 11962 ExpandOldSetting(int *num_file, char_u ***file) 11963 { 11964 char_u *var = NULL; /* init for GCC */ 11965 char_u *buf; 11966 11967 *num_file = 0; 11968 *file = (char_u **)alloc((unsigned)sizeof(char_u *)); 11969 if (*file == NULL) 11970 return FAIL; 11971 11972 /* 11973 * For a terminal key code expand_option_idx is < 0. 11974 */ 11975 if (expand_option_idx < 0) 11976 { 11977 var = find_termcode(expand_option_name + 2); 11978 if (var == NULL) 11979 expand_option_idx = findoption(expand_option_name); 11980 } 11981 11982 if (expand_option_idx >= 0) 11983 { 11984 /* put string of option value in NameBuff */ 11985 option_value2string(&options[expand_option_idx], expand_option_flags); 11986 var = NameBuff; 11987 } 11988 else if (var == NULL) 11989 var = (char_u *)""; 11990 11991 /* A backslash is required before some characters. This is the reverse of 11992 * what happens in do_set(). */ 11993 buf = vim_strsave_escaped(var, escape_chars); 11994 11995 if (buf == NULL) 11996 { 11997 VIM_CLEAR(*file); 11998 return FAIL; 11999 } 12000 12001 #ifdef BACKSLASH_IN_FILENAME 12002 /* For MS-Windows et al. we don't double backslashes at the start and 12003 * before a file name character. */ 12004 for (var = buf; *var != NUL; MB_PTR_ADV(var)) 12005 if (var[0] == '\\' && var[1] == '\\' 12006 && expand_option_idx >= 0 12007 && (options[expand_option_idx].flags & P_EXPAND) 12008 && vim_isfilec(var[2]) 12009 && (var[2] != '\\' || (var == buf && var[4] != '\\'))) 12010 STRMOVE(var, var + 1); 12011 #endif 12012 12013 *file[0] = buf; 12014 *num_file = 1; 12015 return OK; 12016 } 12017 #endif 12018 12019 /* 12020 * Get the value for the numeric or string option *opp in a nice format into 12021 * NameBuff[]. Must not be called with a hidden option! 12022 */ 12023 static void 12024 option_value2string( 12025 struct vimoption *opp, 12026 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */ 12027 { 12028 char_u *varp; 12029 12030 varp = get_varp_scope(opp, opt_flags); 12031 12032 if (opp->flags & P_NUM) 12033 { 12034 long wc = 0; 12035 12036 if (wc_use_keyname(varp, &wc)) 12037 STRCPY(NameBuff, get_special_key_name((int)wc, 0)); 12038 else if (wc != 0) 12039 STRCPY(NameBuff, transchar((int)wc)); 12040 else 12041 sprintf((char *)NameBuff, "%ld", *(long *)varp); 12042 } 12043 else /* P_STRING */ 12044 { 12045 varp = *(char_u **)(varp); 12046 if (varp == NULL) /* just in case */ 12047 NameBuff[0] = NUL; 12048 #ifdef FEAT_CRYPT 12049 /* don't show the actual value of 'key', only that it's set */ 12050 else if (opp->var == (char_u *)&p_key && *varp) 12051 STRCPY(NameBuff, "*****"); 12052 #endif 12053 else if (opp->flags & P_EXPAND) 12054 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); 12055 /* Translate 'pastetoggle' into special key names */ 12056 else if ((char_u **)opp->var == &p_pt) 12057 str2specialbuf(p_pt, NameBuff, MAXPATHL); 12058 else 12059 vim_strncpy(NameBuff, varp, MAXPATHL - 1); 12060 } 12061 } 12062 12063 /* 12064 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be 12065 * printed as a keyname. 12066 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'. 12067 */ 12068 static int 12069 wc_use_keyname(char_u *varp, long *wcp) 12070 { 12071 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) 12072 { 12073 *wcp = *(long *)varp; 12074 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0) 12075 return TRUE; 12076 } 12077 return FALSE; 12078 } 12079 12080 #if defined(FEAT_LANGMAP) || defined(PROTO) 12081 /* 12082 * Any character has an equivalent 'langmap' character. This is used for 12083 * keyboards that have a special language mode that sends characters above 12084 * 128 (although other characters can be translated too). The "to" field is a 12085 * Vim command character. This avoids having to switch the keyboard back to 12086 * ASCII mode when leaving Insert mode. 12087 * 12088 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim 12089 * commands. 12090 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the 12091 * same as langmap_mapchar[] for characters >= 256. 12092 * 12093 * Use growarray for 'langmap' chars >= 256 12094 */ 12095 typedef struct 12096 { 12097 int from; 12098 int to; 12099 } langmap_entry_T; 12100 12101 static garray_T langmap_mapga; 12102 12103 /* 12104 * Search for an entry in "langmap_mapga" for "from". If found set the "to" 12105 * field. If not found insert a new entry at the appropriate location. 12106 */ 12107 static void 12108 langmap_set_entry(int from, int to) 12109 { 12110 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data); 12111 int a = 0; 12112 int b = langmap_mapga.ga_len; 12113 12114 /* Do a binary search for an existing entry. */ 12115 while (a != b) 12116 { 12117 int i = (a + b) / 2; 12118 int d = entries[i].from - from; 12119 12120 if (d == 0) 12121 { 12122 entries[i].to = to; 12123 return; 12124 } 12125 if (d < 0) 12126 a = i + 1; 12127 else 12128 b = i; 12129 } 12130 12131 if (ga_grow(&langmap_mapga, 1) != OK) 12132 return; /* out of memory */ 12133 12134 /* insert new entry at position "a" */ 12135 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a; 12136 mch_memmove(entries + 1, entries, 12137 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T)); 12138 ++langmap_mapga.ga_len; 12139 entries[0].from = from; 12140 entries[0].to = to; 12141 } 12142 12143 /* 12144 * Apply 'langmap' to multi-byte character "c" and return the result. 12145 */ 12146 int 12147 langmap_adjust_mb(int c) 12148 { 12149 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data); 12150 int a = 0; 12151 int b = langmap_mapga.ga_len; 12152 12153 while (a != b) 12154 { 12155 int i = (a + b) / 2; 12156 int d = entries[i].from - c; 12157 12158 if (d == 0) 12159 return entries[i].to; /* found matching entry */ 12160 if (d < 0) 12161 a = i + 1; 12162 else 12163 b = i; 12164 } 12165 return c; /* no entry found, return "c" unmodified */ 12166 } 12167 12168 static void 12169 langmap_init(void) 12170 { 12171 int i; 12172 12173 for (i = 0; i < 256; i++) 12174 langmap_mapchar[i] = i; /* we init with a one-to-one map */ 12175 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8); 12176 } 12177 12178 /* 12179 * Called when langmap option is set; the language map can be 12180 * changed at any time! 12181 */ 12182 static void 12183 langmap_set(void) 12184 { 12185 char_u *p; 12186 char_u *p2; 12187 int from, to; 12188 12189 ga_clear(&langmap_mapga); /* clear the previous map first */ 12190 langmap_init(); /* back to one-to-one map */ 12191 12192 for (p = p_langmap; p[0] != NUL; ) 12193 { 12194 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; 12195 MB_PTR_ADV(p2)) 12196 { 12197 if (p2[0] == '\\' && p2[1] != NUL) 12198 ++p2; 12199 } 12200 if (p2[0] == ';') 12201 ++p2; /* abcd;ABCD form, p2 points to A */ 12202 else 12203 p2 = NULL; /* aAbBcCdD form, p2 is NULL */ 12204 while (p[0]) 12205 { 12206 if (p[0] == ',') 12207 { 12208 ++p; 12209 break; 12210 } 12211 if (p[0] == '\\' && p[1] != NUL) 12212 ++p; 12213 from = (*mb_ptr2char)(p); 12214 to = NUL; 12215 if (p2 == NULL) 12216 { 12217 MB_PTR_ADV(p); 12218 if (p[0] != ',') 12219 { 12220 if (p[0] == '\\') 12221 ++p; 12222 to = (*mb_ptr2char)(p); 12223 } 12224 } 12225 else 12226 { 12227 if (p2[0] != ',') 12228 { 12229 if (p2[0] == '\\') 12230 ++p2; 12231 to = (*mb_ptr2char)(p2); 12232 } 12233 } 12234 if (to == NUL) 12235 { 12236 semsg(_("E357: 'langmap': Matching character missing for %s"), 12237 transchar(from)); 12238 return; 12239 } 12240 12241 if (from >= 256) 12242 langmap_set_entry(from, to); 12243 else 12244 langmap_mapchar[from & 255] = to; 12245 12246 /* Advance to next pair */ 12247 MB_PTR_ADV(p); 12248 if (p2 != NULL) 12249 { 12250 MB_PTR_ADV(p2); 12251 if (*p == ';') 12252 { 12253 p = p2; 12254 if (p[0] != NUL) 12255 { 12256 if (p[0] != ',') 12257 { 12258 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p); 12259 return; 12260 } 12261 ++p; 12262 } 12263 break; 12264 } 12265 } 12266 } 12267 } 12268 } 12269 #endif 12270 12271 /* 12272 * Return TRUE if format option 'x' is in effect. 12273 * Take care of no formatting when 'paste' is set. 12274 */ 12275 int 12276 has_format_option(int x) 12277 { 12278 if (p_paste) 12279 return FALSE; 12280 return (vim_strchr(curbuf->b_p_fo, x) != NULL); 12281 } 12282 12283 /* 12284 * Return TRUE if "x" is present in 'shortmess' option, or 12285 * 'shortmess' contains 'a' and "x" is present in SHM_A. 12286 */ 12287 int 12288 shortmess(int x) 12289 { 12290 return p_shm != NULL && 12291 ( vim_strchr(p_shm, x) != NULL 12292 || (vim_strchr(p_shm, 'a') != NULL 12293 && vim_strchr((char_u *)SHM_A, x) != NULL)); 12294 } 12295 12296 /* 12297 * paste_option_changed() - Called after p_paste was set or reset. 12298 */ 12299 static void 12300 paste_option_changed(void) 12301 { 12302 static int old_p_paste = FALSE; 12303 static int save_sm = 0; 12304 static int save_sta = 0; 12305 #ifdef FEAT_CMDL_INFO 12306 static int save_ru = 0; 12307 #endif 12308 #ifdef FEAT_RIGHTLEFT 12309 static int save_ri = 0; 12310 static int save_hkmap = 0; 12311 #endif 12312 buf_T *buf; 12313 12314 if (p_paste) 12315 { 12316 /* 12317 * Paste switched from off to on. 12318 * Save the current values, so they can be restored later. 12319 */ 12320 if (!old_p_paste) 12321 { 12322 /* save options for each buffer */ 12323 FOR_ALL_BUFFERS(buf) 12324 { 12325 buf->b_p_tw_nopaste = buf->b_p_tw; 12326 buf->b_p_wm_nopaste = buf->b_p_wm; 12327 buf->b_p_sts_nopaste = buf->b_p_sts; 12328 buf->b_p_ai_nopaste = buf->b_p_ai; 12329 buf->b_p_et_nopaste = buf->b_p_et; 12330 #ifdef FEAT_VARTABS 12331 if (buf->b_p_vsts_nopaste) 12332 vim_free(buf->b_p_vsts_nopaste); 12333 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option 12334 ? vim_strsave(buf->b_p_vsts) : NULL; 12335 #endif 12336 } 12337 12338 /* save global options */ 12339 save_sm = p_sm; 12340 save_sta = p_sta; 12341 #ifdef FEAT_CMDL_INFO 12342 save_ru = p_ru; 12343 #endif 12344 #ifdef FEAT_RIGHTLEFT 12345 save_ri = p_ri; 12346 save_hkmap = p_hkmap; 12347 #endif 12348 /* save global values for local buffer options */ 12349 p_ai_nopaste = p_ai; 12350 p_et_nopaste = p_et; 12351 p_sts_nopaste = p_sts; 12352 p_tw_nopaste = p_tw; 12353 p_wm_nopaste = p_wm; 12354 #ifdef FEAT_VARTABS 12355 if (p_vsts_nopaste) 12356 vim_free(p_vsts_nopaste); 12357 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL; 12358 #endif 12359 } 12360 12361 /* 12362 * Always set the option values, also when 'paste' is set when it is 12363 * already on. 12364 */ 12365 /* set options for each buffer */ 12366 FOR_ALL_BUFFERS(buf) 12367 { 12368 buf->b_p_tw = 0; /* textwidth is 0 */ 12369 buf->b_p_wm = 0; /* wrapmargin is 0 */ 12370 buf->b_p_sts = 0; /* softtabstop is 0 */ 12371 buf->b_p_ai = 0; /* no auto-indent */ 12372 buf->b_p_et = 0; /* no expandtab */ 12373 #ifdef FEAT_VARTABS 12374 if (buf->b_p_vsts) 12375 free_string_option(buf->b_p_vsts); 12376 buf->b_p_vsts = empty_option; 12377 if (buf->b_p_vsts_array) 12378 vim_free(buf->b_p_vsts_array); 12379 buf->b_p_vsts_array = 0; 12380 #endif 12381 } 12382 12383 /* set global options */ 12384 p_sm = 0; /* no showmatch */ 12385 p_sta = 0; /* no smarttab */ 12386 #ifdef FEAT_CMDL_INFO 12387 if (p_ru) 12388 status_redraw_all(); /* redraw to remove the ruler */ 12389 p_ru = 0; /* no ruler */ 12390 #endif 12391 #ifdef FEAT_RIGHTLEFT 12392 p_ri = 0; /* no reverse insert */ 12393 p_hkmap = 0; /* no Hebrew keyboard */ 12394 #endif 12395 /* set global values for local buffer options */ 12396 p_tw = 0; 12397 p_wm = 0; 12398 p_sts = 0; 12399 p_ai = 0; 12400 #ifdef FEAT_VARTABS 12401 if (p_vsts) 12402 free_string_option(p_vsts); 12403 p_vsts = empty_option; 12404 #endif 12405 } 12406 12407 /* 12408 * Paste switched from on to off: Restore saved values. 12409 */ 12410 else if (old_p_paste) 12411 { 12412 /* restore options for each buffer */ 12413 FOR_ALL_BUFFERS(buf) 12414 { 12415 buf->b_p_tw = buf->b_p_tw_nopaste; 12416 buf->b_p_wm = buf->b_p_wm_nopaste; 12417 buf->b_p_sts = buf->b_p_sts_nopaste; 12418 buf->b_p_ai = buf->b_p_ai_nopaste; 12419 buf->b_p_et = buf->b_p_et_nopaste; 12420 #ifdef FEAT_VARTABS 12421 if (buf->b_p_vsts) 12422 free_string_option(buf->b_p_vsts); 12423 buf->b_p_vsts = buf->b_p_vsts_nopaste 12424 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option; 12425 if (buf->b_p_vsts_array) 12426 vim_free(buf->b_p_vsts_array); 12427 if (buf->b_p_vsts && buf->b_p_vsts != empty_option) 12428 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); 12429 else 12430 buf->b_p_vsts_array = 0; 12431 #endif 12432 } 12433 12434 /* restore global options */ 12435 p_sm = save_sm; 12436 p_sta = save_sta; 12437 #ifdef FEAT_CMDL_INFO 12438 if (p_ru != save_ru) 12439 status_redraw_all(); /* redraw to draw the ruler */ 12440 p_ru = save_ru; 12441 #endif 12442 #ifdef FEAT_RIGHTLEFT 12443 p_ri = save_ri; 12444 p_hkmap = save_hkmap; 12445 #endif 12446 /* set global values for local buffer options */ 12447 p_ai = p_ai_nopaste; 12448 p_et = p_et_nopaste; 12449 p_sts = p_sts_nopaste; 12450 p_tw = p_tw_nopaste; 12451 p_wm = p_wm_nopaste; 12452 #ifdef FEAT_VARTABS 12453 if (p_vsts) 12454 free_string_option(p_vsts); 12455 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option; 12456 #endif 12457 } 12458 12459 old_p_paste = p_paste; 12460 } 12461 12462 /* 12463 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found. 12464 * 12465 * Reset 'compatible' and set the values for options that didn't get set yet 12466 * to the Vim defaults. 12467 * Don't do this if the 'compatible' option has been set or reset before. 12468 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet. 12469 */ 12470 void 12471 vimrc_found(char_u *fname, char_u *envname) 12472 { 12473 int opt_idx; 12474 int dofree = FALSE; 12475 char_u *p; 12476 12477 if (!option_was_set((char_u *)"cp")) 12478 { 12479 p_cp = FALSE; 12480 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) 12481 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF))) 12482 set_option_default(opt_idx, OPT_FREE, FALSE); 12483 didset_options(); 12484 didset_options2(); 12485 } 12486 12487 if (fname != NULL) 12488 { 12489 p = vim_getenv(envname, &dofree); 12490 if (p == NULL) 12491 { 12492 /* Set $MYVIMRC to the first vimrc file found. */ 12493 p = FullName_save(fname, FALSE); 12494 if (p != NULL) 12495 { 12496 vim_setenv(envname, p); 12497 vim_free(p); 12498 } 12499 } 12500 else if (dofree) 12501 vim_free(p); 12502 } 12503 } 12504 12505 /* 12506 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg. 12507 */ 12508 void 12509 change_compatible(int on) 12510 { 12511 int opt_idx; 12512 12513 if (p_cp != on) 12514 { 12515 p_cp = on; 12516 compatible_set(); 12517 } 12518 opt_idx = findoption((char_u *)"cp"); 12519 if (opt_idx >= 0) 12520 options[opt_idx].flags |= P_WAS_SET; 12521 } 12522 12523 /* 12524 * Return TRUE when option "name" has been set. 12525 * Only works correctly for global options. 12526 */ 12527 int 12528 option_was_set(char_u *name) 12529 { 12530 int idx; 12531 12532 idx = findoption(name); 12533 if (idx < 0) /* unknown option */ 12534 return FALSE; 12535 if (options[idx].flags & P_WAS_SET) 12536 return TRUE; 12537 return FALSE; 12538 } 12539 12540 /* 12541 * Reset the flag indicating option "name" was set. 12542 */ 12543 int 12544 reset_option_was_set(char_u *name) 12545 { 12546 int idx = findoption(name); 12547 12548 if (idx >= 0) 12549 { 12550 options[idx].flags &= ~P_WAS_SET; 12551 return OK; 12552 } 12553 return FAIL; 12554 } 12555 12556 /* 12557 * compatible_set() - Called when 'compatible' has been set or unset. 12558 * 12559 * When 'compatible' set: Set all relevant options (those that have the P_VIM) 12560 * flag) to a Vi compatible value. 12561 * When 'compatible' is unset: Set all options that have a different default 12562 * for Vim (without the P_VI_DEF flag) to that default. 12563 */ 12564 static void 12565 compatible_set(void) 12566 { 12567 int opt_idx; 12568 12569 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) 12570 if ( ((options[opt_idx].flags & P_VIM) && p_cp) 12571 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp)) 12572 set_option_default(opt_idx, OPT_FREE, p_cp); 12573 didset_options(); 12574 didset_options2(); 12575 } 12576 12577 #ifdef FEAT_LINEBREAK 12578 12579 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) 12580 /* Borland C++ screws up loop optimisation here (negri) */ 12581 #pragma option -O-l 12582 # endif 12583 12584 /* 12585 * fill_breakat_flags() -- called when 'breakat' changes value. 12586 */ 12587 static void 12588 fill_breakat_flags(void) 12589 { 12590 char_u *p; 12591 int i; 12592 12593 for (i = 0; i < 256; i++) 12594 breakat_flags[i] = FALSE; 12595 12596 if (p_breakat != NULL) 12597 for (p = p_breakat; *p; p++) 12598 breakat_flags[*p] = TRUE; 12599 } 12600 12601 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) 12602 #pragma option -O.l 12603 # endif 12604 12605 #endif 12606 12607 /* 12608 * Check an option that can be a range of string values. 12609 * 12610 * Return OK for correct value, FAIL otherwise. 12611 * Empty is always OK. 12612 */ 12613 static int 12614 check_opt_strings( 12615 char_u *val, 12616 char **values, 12617 int list) /* when TRUE: accept a list of values */ 12618 { 12619 return opt_strings_flags(val, values, NULL, list); 12620 } 12621 12622 /* 12623 * Handle an option that can be a range of string values. 12624 * Set a flag in "*flagp" for each string present. 12625 * 12626 * Return OK for correct value, FAIL otherwise. 12627 * Empty is always OK. 12628 */ 12629 static int 12630 opt_strings_flags( 12631 char_u *val, /* new value */ 12632 char **values, /* array of valid string values */ 12633 unsigned *flagp, 12634 int list) /* when TRUE: accept a list of values */ 12635 { 12636 int i; 12637 int len; 12638 unsigned new_flags = 0; 12639 12640 while (*val) 12641 { 12642 for (i = 0; ; ++i) 12643 { 12644 if (values[i] == NULL) /* val not found in values[] */ 12645 return FAIL; 12646 12647 len = (int)STRLEN(values[i]); 12648 if (STRNCMP(values[i], val, len) == 0 12649 && ((list && val[len] == ',') || val[len] == NUL)) 12650 { 12651 val += len + (val[len] == ','); 12652 new_flags |= (1 << i); 12653 break; /* check next item in val list */ 12654 } 12655 } 12656 } 12657 if (flagp != NULL) 12658 *flagp = new_flags; 12659 12660 return OK; 12661 } 12662 12663 /* 12664 * Read the 'wildmode' option, fill wim_flags[]. 12665 */ 12666 static int 12667 check_opt_wim(void) 12668 { 12669 char_u new_wim_flags[4]; 12670 char_u *p; 12671 int i; 12672 int idx = 0; 12673 12674 for (i = 0; i < 4; ++i) 12675 new_wim_flags[i] = 0; 12676 12677 for (p = p_wim; *p; ++p) 12678 { 12679 for (i = 0; ASCII_ISALPHA(p[i]); ++i) 12680 ; 12681 if (p[i] != NUL && p[i] != ',' && p[i] != ':') 12682 return FAIL; 12683 if (i == 7 && STRNCMP(p, "longest", 7) == 0) 12684 new_wim_flags[idx] |= WIM_LONGEST; 12685 else if (i == 4 && STRNCMP(p, "full", 4) == 0) 12686 new_wim_flags[idx] |= WIM_FULL; 12687 else if (i == 4 && STRNCMP(p, "list", 4) == 0) 12688 new_wim_flags[idx] |= WIM_LIST; 12689 else 12690 return FAIL; 12691 p += i; 12692 if (*p == NUL) 12693 break; 12694 if (*p == ',') 12695 { 12696 if (idx == 3) 12697 return FAIL; 12698 ++idx; 12699 } 12700 } 12701 12702 /* fill remaining entries with last flag */ 12703 while (idx < 3) 12704 { 12705 new_wim_flags[idx + 1] = new_wim_flags[idx]; 12706 ++idx; 12707 } 12708 12709 /* only when there are no errors, wim_flags[] is changed */ 12710 for (i = 0; i < 4; ++i) 12711 wim_flags[i] = new_wim_flags[i]; 12712 return OK; 12713 } 12714 12715 /* 12716 * Check if backspacing over something is allowed. 12717 */ 12718 int 12719 can_bs( 12720 int what) /* BS_INDENT, BS_EOL or BS_START */ 12721 { 12722 #ifdef FEAT_JOB_CHANNEL 12723 if (what == BS_START && bt_prompt(curbuf)) 12724 return FALSE; 12725 #endif 12726 switch (*p_bs) 12727 { 12728 case '2': return TRUE; 12729 case '1': return (what != BS_START); 12730 case '0': return FALSE; 12731 } 12732 return vim_strchr(p_bs, what) != NULL; 12733 } 12734 12735 /* 12736 * Save the current values of 'fileformat' and 'fileencoding', so that we know 12737 * the file must be considered changed when the value is different. 12738 */ 12739 void 12740 save_file_ff(buf_T *buf) 12741 { 12742 buf->b_start_ffc = *buf->b_p_ff; 12743 buf->b_start_eol = buf->b_p_eol; 12744 buf->b_start_bomb = buf->b_p_bomb; 12745 12746 /* Only use free/alloc when necessary, they take time. */ 12747 if (buf->b_start_fenc == NULL 12748 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) 12749 { 12750 vim_free(buf->b_start_fenc); 12751 buf->b_start_fenc = vim_strsave(buf->b_p_fenc); 12752 } 12753 } 12754 12755 /* 12756 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value 12757 * from when editing started (save_file_ff() called). 12758 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was 12759 * changed and 'binary' is not set. 12760 * Also when 'endofline' was changed and 'fixeol' is not set. 12761 * When "ignore_empty" is true don't consider a new, empty buffer to be 12762 * changed. 12763 */ 12764 int 12765 file_ff_differs(buf_T *buf, int ignore_empty) 12766 { 12767 /* In a buffer that was never loaded the options are not valid. */ 12768 if (buf->b_flags & BF_NEVERLOADED) 12769 return FALSE; 12770 if (ignore_empty 12771 && (buf->b_flags & BF_NEW) 12772 && buf->b_ml.ml_line_count == 1 12773 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL) 12774 return FALSE; 12775 if (buf->b_start_ffc != *buf->b_p_ff) 12776 return TRUE; 12777 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol) 12778 return TRUE; 12779 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb) 12780 return TRUE; 12781 if (buf->b_start_fenc == NULL) 12782 return (*buf->b_p_fenc != NUL); 12783 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0); 12784 } 12785 12786 /* 12787 * return OK if "p" is a valid fileformat name, FAIL otherwise. 12788 */ 12789 int 12790 check_ff_value(char_u *p) 12791 { 12792 return check_opt_strings(p, p_ff_values, FALSE); 12793 } 12794 12795 #ifdef FEAT_VARTABS 12796 12797 /* 12798 * Set the integer values corresponding to the string setting of 'vartabstop'. 12799 */ 12800 int 12801 tabstop_set(char_u *var, int **array) 12802 { 12803 int valcount = 1; 12804 int t; 12805 char_u *cp; 12806 12807 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL)) 12808 { 12809 *array = NULL; 12810 return TRUE; 12811 } 12812 12813 for (cp = var; *cp != NUL; ++cp) 12814 { 12815 if (cp == var || cp[-1] == ',') 12816 { 12817 char_u *end; 12818 12819 if (strtol((char *)cp, (char **)&end, 10) <= 0) 12820 { 12821 if (cp != end) 12822 emsg(_(e_positive)); 12823 else 12824 emsg(_(e_invarg)); 12825 return FALSE; 12826 } 12827 } 12828 12829 if (VIM_ISDIGIT(*cp)) 12830 continue; 12831 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL) 12832 { 12833 ++valcount; 12834 continue; 12835 } 12836 emsg(_(e_invarg)); 12837 return FALSE; 12838 } 12839 12840 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int))); 12841 (*array)[0] = valcount; 12842 12843 t = 1; 12844 for (cp = var; *cp != NUL;) 12845 { 12846 (*array)[t++] = atoi((char *)cp); 12847 while (*cp != NUL && *cp != ',') 12848 ++cp; 12849 if (*cp != NUL) 12850 ++cp; 12851 } 12852 12853 return TRUE; 12854 } 12855 12856 /* 12857 * Calculate the number of screen spaces a tab will occupy. 12858 * If "vts" is set then the tab widths are taken from that array, 12859 * otherwise the value of ts is used. 12860 */ 12861 int 12862 tabstop_padding(colnr_T col, int ts_arg, int *vts) 12863 { 12864 int ts = ts_arg == 0 ? 8 : ts_arg; 12865 int tabcount; 12866 colnr_T tabcol = 0; 12867 int t; 12868 int padding = 0; 12869 12870 if (vts == NULL || vts[0] == 0) 12871 return ts - (col % ts); 12872 12873 tabcount = vts[0]; 12874 12875 for (t = 1; t <= tabcount; ++t) 12876 { 12877 tabcol += vts[t]; 12878 if (tabcol > col) 12879 { 12880 padding = (int)(tabcol - col); 12881 break; 12882 } 12883 } 12884 if (t > tabcount) 12885 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]); 12886 12887 return padding; 12888 } 12889 12890 /* 12891 * Find the size of the tab that covers a particular column. 12892 */ 12893 int 12894 tabstop_at(colnr_T col, int ts, int *vts) 12895 { 12896 int tabcount; 12897 colnr_T tabcol = 0; 12898 int t; 12899 int tab_size = 0; 12900 12901 if (vts == 0 || vts[0] == 0) 12902 return ts; 12903 12904 tabcount = vts[0]; 12905 for (t = 1; t <= tabcount; ++t) 12906 { 12907 tabcol += vts[t]; 12908 if (tabcol > col) 12909 { 12910 tab_size = vts[t]; 12911 break; 12912 } 12913 } 12914 if (t > tabcount) 12915 tab_size = vts[tabcount]; 12916 12917 return tab_size; 12918 } 12919 12920 /* 12921 * Find the column on which a tab starts. 12922 */ 12923 colnr_T 12924 tabstop_start(colnr_T col, int ts, int *vts) 12925 { 12926 int tabcount; 12927 colnr_T tabcol = 0; 12928 int t; 12929 int excess; 12930 12931 if (vts == NULL || vts[0] == 0) 12932 return (col / ts) * ts; 12933 12934 tabcount = vts[0]; 12935 for (t = 1; t <= tabcount; ++t) 12936 { 12937 tabcol += vts[t]; 12938 if (tabcol > col) 12939 return tabcol - vts[t]; 12940 } 12941 12942 excess = tabcol % vts[tabcount]; 12943 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount]; 12944 } 12945 12946 /* 12947 * Find the number of tabs and spaces necessary to get from one column 12948 * to another. 12949 */ 12950 void 12951 tabstop_fromto( 12952 colnr_T start_col, 12953 colnr_T end_col, 12954 int ts_arg, 12955 int *vts, 12956 int *ntabs, 12957 int *nspcs) 12958 { 12959 int spaces = end_col - start_col; 12960 colnr_T tabcol = 0; 12961 int padding = 0; 12962 int tabcount; 12963 int t; 12964 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg; 12965 12966 if (vts == NULL || vts[0] == 0) 12967 { 12968 int tabs = 0; 12969 int initspc = 0; 12970 12971 initspc = ts - (start_col % ts); 12972 if (spaces >= initspc) 12973 { 12974 spaces -= initspc; 12975 tabs++; 12976 } 12977 tabs += spaces / ts; 12978 spaces -= (spaces / ts) * ts; 12979 12980 *ntabs = tabs; 12981 *nspcs = spaces; 12982 return; 12983 } 12984 12985 /* Find the padding needed to reach the next tabstop. */ 12986 tabcount = vts[0]; 12987 for (t = 1; t <= tabcount; ++t) 12988 { 12989 tabcol += vts[t]; 12990 if (tabcol > start_col) 12991 { 12992 padding = (int)(tabcol - start_col); 12993 break; 12994 } 12995 } 12996 if (t > tabcount) 12997 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]); 12998 12999 /* If the space needed is less than the padding no tabs can be used. */ 13000 if (spaces < padding) 13001 { 13002 *ntabs = 0; 13003 *nspcs = spaces; 13004 return; 13005 } 13006 13007 *ntabs = 1; 13008 spaces -= padding; 13009 13010 /* At least one tab has been used. See if any more will fit. */ 13011 while (spaces != 0 && ++t <= tabcount) 13012 { 13013 padding = vts[t]; 13014 if (spaces < padding) 13015 { 13016 *nspcs = spaces; 13017 return; 13018 } 13019 ++*ntabs; 13020 spaces -= padding; 13021 } 13022 13023 *ntabs += spaces / vts[tabcount]; 13024 *nspcs = spaces % vts[tabcount]; 13025 } 13026 13027 /* 13028 * See if two tabstop arrays contain the same values. 13029 */ 13030 int 13031 tabstop_eq(int *ts1, int *ts2) 13032 { 13033 int t; 13034 13035 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0)) 13036 return FALSE; 13037 if (ts1 == ts2) 13038 return TRUE; 13039 if (ts1[0] != ts2[0]) 13040 return FALSE; 13041 13042 for (t = 1; t <= ts1[0]; ++t) 13043 if (ts1[t] != ts2[t]) 13044 return FALSE; 13045 13046 return TRUE; 13047 } 13048 13049 #if defined(FEAT_BEVAL) || defined(PROTO) 13050 /* 13051 * Copy a tabstop array, allocating space for the new array. 13052 */ 13053 int * 13054 tabstop_copy(int *oldts) 13055 { 13056 int *newts; 13057 int t; 13058 13059 if (oldts == 0) 13060 return 0; 13061 13062 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int))); 13063 for (t = 0; t <= oldts[0]; ++t) 13064 newts[t] = oldts[t]; 13065 13066 return newts; 13067 } 13068 #endif 13069 13070 /* 13071 * Return a count of the number of tabstops. 13072 */ 13073 int 13074 tabstop_count(int *ts) 13075 { 13076 return ts != NULL ? ts[0] : 0; 13077 } 13078 13079 /* 13080 * Return the first tabstop, or 8 if there are no tabstops defined. 13081 */ 13082 int 13083 tabstop_first(int *ts) 13084 { 13085 return ts != NULL ? ts[1] : 8; 13086 } 13087 13088 #endif 13089 13090 /* 13091 * Return the effective shiftwidth value for current buffer, using the 13092 * 'tabstop' value when 'shiftwidth' is zero. 13093 */ 13094 long 13095 get_sw_value(buf_T *buf) 13096 { 13097 return get_sw_value_col(buf, 0); 13098 } 13099 13100 /* 13101 * Idem, using the first non-black in the current line. 13102 */ 13103 long 13104 get_sw_value_indent(buf_T *buf) 13105 { 13106 pos_T pos = curwin->w_cursor; 13107 13108 pos.col = getwhitecols_curline(); 13109 return get_sw_value_pos(buf, &pos); 13110 } 13111 13112 /* 13113 * Idem, using "pos". 13114 */ 13115 long 13116 get_sw_value_pos(buf_T *buf, pos_T *pos) 13117 { 13118 pos_T save_cursor = curwin->w_cursor; 13119 long sw_value; 13120 13121 curwin->w_cursor = *pos; 13122 sw_value = get_sw_value_col(buf, get_nolist_virtcol()); 13123 curwin->w_cursor = save_cursor; 13124 return sw_value; 13125 } 13126 13127 /* 13128 * Idem, using virtual column "col". 13129 */ 13130 long 13131 get_sw_value_col(buf_T *buf, colnr_T col UNUSED) 13132 { 13133 return buf->b_p_sw ? buf->b_p_sw : 13134 #ifdef FEAT_VARTABS 13135 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array); 13136 #else 13137 buf->b_p_ts; 13138 #endif 13139 } 13140 13141 /* 13142 * Return the effective softtabstop value for the current buffer, using the 13143 * 'shiftwidth' value when 'softtabstop' is negative. 13144 */ 13145 long 13146 get_sts_value(void) 13147 { 13148 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts; 13149 } 13150 13151 /* 13152 * Return the effective 'scrolloff' value for the current window, using the 13153 * global value when appropriate. 13154 */ 13155 long 13156 get_scrolloff_value(void) 13157 { 13158 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so; 13159 } 13160 13161 /* 13162 * Return the effective 'sidescrolloff' value for the current window, using the 13163 * global value when appropriate. 13164 */ 13165 long 13166 get_sidescrolloff_value(void) 13167 { 13168 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso; 13169 } 13170 13171 /* 13172 * Check matchpairs option for "*initc". 13173 * If there is a match set "*initc" to the matching character and "*findc" to 13174 * the opposite character. Set "*backwards" to the direction. 13175 * When "switchit" is TRUE swap the direction. 13176 */ 13177 void 13178 find_mps_values( 13179 int *initc, 13180 int *findc, 13181 int *backwards, 13182 int switchit) 13183 { 13184 char_u *ptr; 13185 13186 ptr = curbuf->b_p_mps; 13187 while (*ptr != NUL) 13188 { 13189 if (has_mbyte) 13190 { 13191 char_u *prev; 13192 13193 if (mb_ptr2char(ptr) == *initc) 13194 { 13195 if (switchit) 13196 { 13197 *findc = *initc; 13198 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1); 13199 *backwards = TRUE; 13200 } 13201 else 13202 { 13203 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1); 13204 *backwards = FALSE; 13205 } 13206 return; 13207 } 13208 prev = ptr; 13209 ptr += mb_ptr2len(ptr) + 1; 13210 if (mb_ptr2char(ptr) == *initc) 13211 { 13212 if (switchit) 13213 { 13214 *findc = *initc; 13215 *initc = mb_ptr2char(prev); 13216 *backwards = FALSE; 13217 } 13218 else 13219 { 13220 *findc = mb_ptr2char(prev); 13221 *backwards = TRUE; 13222 } 13223 return; 13224 } 13225 ptr += mb_ptr2len(ptr); 13226 } 13227 else 13228 { 13229 if (*ptr == *initc) 13230 { 13231 if (switchit) 13232 { 13233 *backwards = TRUE; 13234 *findc = *initc; 13235 *initc = ptr[2]; 13236 } 13237 else 13238 { 13239 *backwards = FALSE; 13240 *findc = ptr[2]; 13241 } 13242 return; 13243 } 13244 ptr += 2; 13245 if (*ptr == *initc) 13246 { 13247 if (switchit) 13248 { 13249 *backwards = FALSE; 13250 *findc = *initc; 13251 *initc = ptr[-2]; 13252 } 13253 else 13254 { 13255 *backwards = TRUE; 13256 *findc = ptr[-2]; 13257 } 13258 return; 13259 } 13260 ++ptr; 13261 } 13262 if (*ptr == ',') 13263 ++ptr; 13264 } 13265 } 13266 13267 #if defined(FEAT_LINEBREAK) || defined(PROTO) 13268 /* 13269 * This is called when 'breakindentopt' is changed and when a window is 13270 * initialized. 13271 */ 13272 static int 13273 briopt_check(win_T *wp) 13274 { 13275 char_u *p; 13276 int bri_shift = 0; 13277 long bri_min = 20; 13278 int bri_sbr = FALSE; 13279 13280 p = wp->w_p_briopt; 13281 while (*p != NUL) 13282 { 13283 if (STRNCMP(p, "shift:", 6) == 0 13284 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6]))) 13285 { 13286 p += 6; 13287 bri_shift = getdigits(&p); 13288 } 13289 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4])) 13290 { 13291 p += 4; 13292 bri_min = getdigits(&p); 13293 } 13294 else if (STRNCMP(p, "sbr", 3) == 0) 13295 { 13296 p += 3; 13297 bri_sbr = TRUE; 13298 } 13299 if (*p != ',' && *p != NUL) 13300 return FAIL; 13301 if (*p == ',') 13302 ++p; 13303 } 13304 13305 wp->w_p_brishift = bri_shift; 13306 wp->w_p_brimin = bri_min; 13307 wp->w_p_brisbr = bri_sbr; 13308 13309 return OK; 13310 } 13311 #endif 13312 13313 /* 13314 * Get the local or global value of 'backupcopy'. 13315 */ 13316 unsigned int 13317 get_bkc_value(buf_T *buf) 13318 { 13319 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags; 13320 } 13321 13322 #if defined(FEAT_SIGNS) || defined(PROTO) 13323 /* 13324 * Return TRUE when window "wp" has a column to draw signs in. 13325 */ 13326 int 13327 signcolumn_on(win_T *wp) 13328 { 13329 if (*wp->w_p_scl == 'n') 13330 return FALSE; 13331 if (*wp->w_p_scl == 'y') 13332 return TRUE; 13333 return (wp->w_buffer->b_signlist != NULL 13334 # ifdef FEAT_NETBEANS_INTG 13335 || wp->w_buffer->b_has_sign_column 13336 # endif 13337 ); 13338 } 13339 #endif 13340 13341 #if defined(FEAT_EVAL) || defined(PROTO) 13342 /* 13343 * Get window or buffer local options. 13344 */ 13345 dict_T * 13346 get_winbuf_options(int bufopt) 13347 { 13348 dict_T *d; 13349 int opt_idx; 13350 13351 d = dict_alloc(); 13352 if (d == NULL) 13353 return NULL; 13354 13355 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) 13356 { 13357 struct vimoption *opt = &options[opt_idx]; 13358 13359 if ((bufopt && (opt->indir & PV_BUF)) 13360 || (!bufopt && (opt->indir & PV_WIN))) 13361 { 13362 char_u *varp = get_varp(opt); 13363 13364 if (varp != NULL) 13365 { 13366 if (opt->flags & P_STRING) 13367 dict_add_string(d, opt->fullname, *(char_u **)varp); 13368 else if (opt->flags & P_NUM) 13369 dict_add_number(d, opt->fullname, *(long *)varp); 13370 else 13371 dict_add_number(d, opt->fullname, *(int *)varp); 13372 } 13373 } 13374 } 13375 13376 return d; 13377 } 13378 #endif 13379