xref: /vim-8.2.3635/src/option.c (revision 723d165c)
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 #endif
257 #ifdef FEAT_SIGNS
258 # define PV_SCL		OPT_WIN(WV_SCL)
259 #endif
260 
261 /* WV_ and BV_ values get typecasted to this for the "indir" field */
262 typedef enum
263 {
264     PV_NONE = 0,
265     PV_MAXVAL = 0xffff    /* to avoid warnings for value out of range */
266 } idopt_T;
267 
268 /*
269  * Options local to a window have a value local to a buffer and global to all
270  * buffers.  Indicate this by setting "var" to VAR_WIN.
271  */
272 #define VAR_WIN ((char_u *)-1)
273 
274 /*
275  * These are the global values for options which are also local to a buffer.
276  * Only to be used in option.c!
277  */
278 static int	p_ai;
279 static int	p_bin;
280 static int	p_bomb;
281 static char_u	*p_bh;
282 static char_u	*p_bt;
283 static int	p_bl;
284 static int	p_ci;
285 #ifdef FEAT_CINDENT
286 static int	p_cin;
287 static char_u	*p_cink;
288 static char_u	*p_cino;
289 #endif
290 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
291 static char_u	*p_cinw;
292 #endif
293 #ifdef FEAT_COMMENTS
294 static char_u	*p_com;
295 #endif
296 #ifdef FEAT_FOLDING
297 static char_u	*p_cms;
298 #endif
299 #ifdef FEAT_INS_EXPAND
300 static char_u	*p_cpt;
301 #endif
302 #ifdef FEAT_COMPL_FUNC
303 static char_u	*p_cfu;
304 static char_u	*p_ofu;
305 #endif
306 static int	p_eol;
307 static int	p_fixeol;
308 static int	p_et;
309 static char_u	*p_fenc;
310 static char_u	*p_ff;
311 static char_u	*p_fo;
312 static char_u	*p_flp;
313 static char_u	*p_ft;
314 static long	p_iminsert;
315 static long	p_imsearch;
316 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
317 static char_u	*p_inex;
318 #endif
319 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
320 static char_u	*p_inde;
321 static char_u	*p_indk;
322 #endif
323 #if defined(FEAT_EVAL)
324 static char_u	*p_fex;
325 #endif
326 static int	p_inf;
327 static char_u	*p_isk;
328 #ifdef FEAT_CRYPT
329 static char_u	*p_key;
330 #endif
331 #ifdef FEAT_LISP
332 static int	p_lisp;
333 #endif
334 static int	p_ml;
335 static int	p_ma;
336 static int	p_mod;
337 static char_u	*p_mps;
338 static char_u	*p_nf;
339 static int	p_pi;
340 #ifdef FEAT_TEXTOBJ
341 static char_u	*p_qe;
342 #endif
343 static int	p_ro;
344 #ifdef FEAT_SMARTINDENT
345 static int	p_si;
346 #endif
347 static int	p_sn;
348 static long	p_sts;
349 #if defined(FEAT_SEARCHPATH)
350 static char_u	*p_sua;
351 #endif
352 static long	p_sw;
353 static int	p_swf;
354 #ifdef FEAT_SYN_HL
355 static long	p_smc;
356 static char_u	*p_syn;
357 #endif
358 #ifdef FEAT_SPELL
359 static char_u	*p_spc;
360 static char_u	*p_spf;
361 static char_u	*p_spl;
362 #endif
363 static long	p_ts;
364 static long	p_tw;
365 static int	p_tx;
366 #ifdef FEAT_PERSISTENT_UNDO
367 static int	p_udf;
368 #endif
369 static long	p_wm;
370 #ifdef FEAT_VARTABS
371 static char_u	*p_vsts;
372 static char_u	*p_vts;
373 #endif
374 #ifdef FEAT_KEYMAP
375 static char_u	*p_keymap;
376 #endif
377 #ifdef FEAT_TERMINAL
378 static long	p_twsl;		/* 'termwinscroll' */
379 #endif
380 
381 /* Saved values for when 'bin' is set. */
382 static int	p_et_nobin;
383 static int	p_ml_nobin;
384 static long	p_tw_nobin;
385 static long	p_wm_nobin;
386 
387 /* Saved values for when 'paste' is set */
388 static int	p_ai_nopaste;
389 static int	p_et_nopaste;
390 static long	p_sts_nopaste;
391 static long	p_tw_nopaste;
392 static long	p_wm_nopaste;
393 #ifdef FEAT_VARTABS
394 static char_u	*p_vsts_nopaste;
395 #endif
396 
397 struct vimoption
398 {
399     char	*fullname;	// full option name
400     char	*shortname;	// permissible abbreviation
401     long_u	flags;		// see below
402     char_u	*var;		// global option: pointer to variable;
403 				// window-local option: VAR_WIN;
404 				// buffer-local option: global value
405     idopt_T	indir;		// global option: PV_NONE;
406 				// local option: indirect option index
407     char_u	*def_val[2];	// default values for variable (vi and vim)
408 #ifdef FEAT_EVAL
409     sctx_T	script_ctx;	// script context where the option was last set
410 # define SCTX_INIT , {0, 0, 0}
411 #else
412 # define SCTX_INIT
413 #endif
414 };
415 
416 #define VI_DEFAULT  0	    /* def_val[VI_DEFAULT] is Vi default value */
417 #define VIM_DEFAULT 1	    /* def_val[VIM_DEFAULT] is Vim default value */
418 
419 /*
420  * Flags
421  */
422 #define P_BOOL		0x01	/* the option is boolean */
423 #define P_NUM		0x02	/* the option is numeric */
424 #define P_STRING	0x04	/* the option is a string */
425 #define P_ALLOCED	0x08	/* the string option is in allocated memory,
426 				   must use free_string_option() when
427 				   assigning new value. Not set if default is
428 				   the same. */
429 #define P_EXPAND	0x10	/* environment expansion.  NOTE: P_EXPAND can
430 				   never be used for local or hidden options! */
431 #define P_NODEFAULT	0x40	/* don't set to default value */
432 #define P_DEF_ALLOCED	0x80	/* default value is in allocated memory, must
433 				    use vim_free() when assigning new value */
434 #define P_WAS_SET	0x100	/* option has been set/reset */
435 #define P_NO_MKRC	0x200	/* don't include in :mkvimrc output */
436 #define P_VI_DEF	0x400	/* Use Vi default for Vim */
437 #define P_VIM		0x800	/* Vim option, reset when 'cp' set */
438 
439 				/* when option changed, what to display: */
440 #define P_RSTAT		0x1000	/* redraw status lines */
441 #define P_RWIN		0x2000	/* redraw current window and recompute text */
442 #define P_RBUF		0x4000	/* redraw current buffer and recompute text */
443 #define P_RALL		0x6000	/* redraw all windows */
444 #define P_RCLR		0x7000	/* clear and redraw all */
445 
446 #define P_COMMA		 0x8000	 /* comma separated list */
447 #define P_ONECOMMA	0x18000L /* P_COMMA and cannot have two consecutive
448 				  * commas */
449 #define P_NODUP		0x20000L /* don't allow duplicate strings */
450 #define P_FLAGLIST	0x40000L /* list of single-char flags */
451 
452 #define P_SECURE	0x80000L /* cannot change in modeline or secure mode */
453 #define P_GETTEXT      0x100000L /* expand default value with _() */
454 #define P_NOGLOB       0x200000L /* do not use local value for global vimrc */
455 #define P_NFNAME       0x400000L /* only normal file name chars allowed */
456 #define P_INSECURE     0x800000L /* option was set from a modeline */
457 #define P_PRI_MKRC    0x1000000L /* priority for :mkvimrc (setting option has
458 				    side effects) */
459 #define P_NO_ML       0x2000000L /* not allowed in modeline */
460 #define P_CURSWANT    0x4000000L /* update curswant required; not needed when
461 				  * there is a redraw flag */
462 #define P_NDNAME      0x8000000L /* only normal dir name chars allowed */
463 #define P_RWINONLY   0x10000000L /* only redraw current window */
464 
465 #define ISK_LATIN1  (char_u *)"@,48-57,_,192-255"
466 
467 /* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
468  * for the currency sign. */
469 #if defined(MSWIN)
470 # define ISP_LATIN1 (char_u *)"@,~-255"
471 #else
472 # define ISP_LATIN1 (char_u *)"@,161-255"
473 #endif
474 
475 # 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"
476 
477 /* Default python version for pyx* commands */
478 #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
479 # define DEFAULT_PYTHON_VER	0
480 #elif defined(FEAT_PYTHON3)
481 # define DEFAULT_PYTHON_VER	3
482 #elif defined(FEAT_PYTHON)
483 # define DEFAULT_PYTHON_VER	2
484 #else
485 # define DEFAULT_PYTHON_VER	0
486 #endif
487 
488 // used for 'cinkeys' and 'indentkeys'
489 #define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
490 
491 /*
492  * options[] is initialized here.
493  * The order of the options MUST be alphabetic for ":set all" and findoption().
494  * All option names MUST start with a lowercase letter (for findoption()).
495  * Exception: "t_" options are at the end.
496  * The options with a NULL variable are 'hidden': a set command for them is
497  * ignored and they are not printed.
498  */
499 static struct vimoption options[] =
500 {
501     {"aleph",	    "al",   P_NUM|P_VI_DEF|P_CURSWANT,
502 #ifdef FEAT_RIGHTLEFT
503 			    (char_u *)&p_aleph, PV_NONE,
504 #else
505 			    (char_u *)NULL, PV_NONE,
506 #endif
507 			    {
508 #if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
509 			    (char_u *)128L,
510 #else
511 			    (char_u *)224L,
512 #endif
513 					    (char_u *)0L} SCTX_INIT},
514     {"antialias",   "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
515 #if defined(FEAT_GUI_MAC)
516 			    (char_u *)&p_antialias, PV_NONE,
517 			    {(char_u *)FALSE, (char_u *)FALSE}
518 #else
519 			    (char_u *)NULL, PV_NONE,
520 			    {(char_u *)FALSE, (char_u *)FALSE}
521 #endif
522 			    SCTX_INIT},
523     {"arabic",	    "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
524 #ifdef FEAT_ARABIC
525 			    (char_u *)VAR_WIN, PV_ARAB,
526 #else
527 			    (char_u *)NULL, PV_NONE,
528 #endif
529 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
530     {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
531 #ifdef FEAT_ARABIC
532 			    (char_u *)&p_arshape, PV_NONE,
533 #else
534 			    (char_u *)NULL, PV_NONE,
535 #endif
536 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
537     {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
538 #ifdef FEAT_RIGHTLEFT
539 			    (char_u *)&p_ari, PV_NONE,
540 #else
541 			    (char_u *)NULL, PV_NONE,
542 #endif
543 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
544     {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
545 			    (char_u *)NULL, PV_NONE,
546 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
547     {"ambiwidth",  "ambw",  P_STRING|P_VI_DEF|P_RCLR,
548 			    (char_u *)&p_ambw, PV_NONE,
549 			    {(char_u *)"single", (char_u *)0L}
550 			    SCTX_INIT},
551     {"autochdir",  "acd",   P_BOOL|P_VI_DEF,
552 #ifdef FEAT_AUTOCHDIR
553 			    (char_u *)&p_acd, PV_NONE,
554 			    {(char_u *)FALSE, (char_u *)0L}
555 #else
556 			    (char_u *)NULL, PV_NONE,
557 			    {(char_u *)0L, (char_u *)0L}
558 #endif
559 			    SCTX_INIT},
560     {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
561 			    (char_u *)&p_ai, PV_AI,
562 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
563     {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
564 			    (char_u *)NULL, PV_NONE,
565 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
566     {"autoread",    "ar",   P_BOOL|P_VI_DEF,
567 			    (char_u *)&p_ar, PV_AR,
568 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
569     {"autowrite",   "aw",   P_BOOL|P_VI_DEF,
570 			    (char_u *)&p_aw, PV_NONE,
571 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
572     {"autowriteall","awa",  P_BOOL|P_VI_DEF,
573 			    (char_u *)&p_awa, PV_NONE,
574 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
575     {"background",  "bg",   P_STRING|P_VI_DEF|P_RCLR,
576 			    (char_u *)&p_bg, PV_NONE,
577 			    {
578 #if (defined(MSWIN)) && !defined(FEAT_GUI)
579 			    (char_u *)"dark",
580 #else
581 			    (char_u *)"light",
582 #endif
583 					    (char_u *)0L} SCTX_INIT},
584     {"backspace",   "bs",   P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
585 			    (char_u *)&p_bs, PV_NONE,
586 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
587     {"backup",	    "bk",   P_BOOL|P_VI_DEF|P_VIM,
588 			    (char_u *)&p_bk, PV_NONE,
589 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
590     {"backupcopy",  "bkc",  P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
591 			    (char_u *)&p_bkc, PV_BKC,
592 #ifdef UNIX
593 			    {(char_u *)"yes", (char_u *)"auto"}
594 #else
595 			    {(char_u *)"auto", (char_u *)"auto"}
596 #endif
597 			    SCTX_INIT},
598     {"backupdir",   "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
599 							    |P_NODUP|P_SECURE,
600 			    (char_u *)&p_bdir, PV_NONE,
601 			    {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
602     {"backupext",   "bex",  P_STRING|P_VI_DEF|P_NFNAME,
603 			    (char_u *)&p_bex, PV_NONE,
604 			    {
605 #ifdef VMS
606 			    (char_u *)"_",
607 #else
608 			    (char_u *)"~",
609 #endif
610 					    (char_u *)0L} SCTX_INIT},
611     {"backupskip",  "bsk",  P_STRING|P_VI_DEF|P_ONECOMMA,
612 #ifdef FEAT_WILDIGN
613 			    (char_u *)&p_bsk, PV_NONE,
614 			    {(char_u *)"", (char_u *)0L}
615 #else
616 			    (char_u *)NULL, PV_NONE,
617 			    {(char_u *)0L, (char_u *)0L}
618 #endif
619 			    SCTX_INIT},
620     {"balloondelay","bdlay",P_NUM|P_VI_DEF,
621 #ifdef FEAT_BEVAL
622 			    (char_u *)&p_bdlay, PV_NONE,
623 			    {(char_u *)600L, (char_u *)0L}
624 #else
625 			    (char_u *)NULL, PV_NONE,
626 			    {(char_u *)0L, (char_u *)0L}
627 #endif
628 			    SCTX_INIT},
629     {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
630 #ifdef FEAT_BEVAL_GUI
631 			    (char_u *)&p_beval, PV_NONE,
632 			    {(char_u *)FALSE, (char_u *)0L}
633 #else
634 			    (char_u *)NULL, PV_NONE,
635 			    {(char_u *)0L, (char_u *)0L}
636 #endif
637 			    SCTX_INIT},
638     {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
639 #ifdef FEAT_BEVAL_TERM
640 			    (char_u *)&p_bevalterm, PV_NONE,
641 			    {(char_u *)FALSE, (char_u *)0L}
642 #else
643 			    (char_u *)NULL, PV_NONE,
644 			    {(char_u *)0L, (char_u *)0L}
645 #endif
646 			    SCTX_INIT},
647     {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
648 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
649 			    (char_u *)&p_bexpr, PV_BEXPR,
650 			    {(char_u *)"", (char_u *)0L}
651 #else
652 			    (char_u *)NULL, PV_NONE,
653 			    {(char_u *)0L, (char_u *)0L}
654 #endif
655 			    SCTX_INIT},
656     {"beautify",    "bf",   P_BOOL|P_VI_DEF,
657 			    (char_u *)NULL, PV_NONE,
658 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
659     {"belloff",      "bo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
660 			    (char_u *)&p_bo, PV_NONE,
661 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
662     {"binary",	    "bin",  P_BOOL|P_VI_DEF|P_RSTAT,
663 			    (char_u *)&p_bin, PV_BIN,
664 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
665     {"bioskey",	    "biosk",P_BOOL|P_VI_DEF,
666 			    (char_u *)NULL, PV_NONE,
667 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
668     {"bomb",	    NULL,   P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
669 			    (char_u *)&p_bomb, PV_BOMB,
670 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
671     {"breakat",	    "brk",  P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
672 #ifdef FEAT_LINEBREAK
673 			    (char_u *)&p_breakat, PV_NONE,
674 			    {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
675 #else
676 			    (char_u *)NULL, PV_NONE,
677 			    {(char_u *)0L, (char_u *)0L}
678 #endif
679 			    SCTX_INIT},
680     {"breakindent",   "bri",  P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
681 #ifdef FEAT_LINEBREAK
682 			    (char_u *)VAR_WIN, PV_BRI,
683 			    {(char_u *)FALSE, (char_u *)0L}
684 #else
685 			    (char_u *)NULL, PV_NONE,
686 			    {(char_u *)0L, (char_u *)0L}
687 #endif
688 			    SCTX_INIT},
689     {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
690 						  |P_ONECOMMA|P_NODUP,
691 #ifdef FEAT_LINEBREAK
692 			    (char_u *)VAR_WIN, PV_BRIOPT,
693 			    {(char_u *)"", (char_u *)NULL}
694 #else
695 			    (char_u *)NULL, PV_NONE,
696 			    {(char_u *)"", (char_u *)NULL}
697 #endif
698 			    SCTX_INIT},
699     {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
700 #ifdef FEAT_BROWSE
701 			    (char_u *)&p_bsdir, PV_NONE,
702 			    {(char_u *)"last", (char_u *)0L}
703 #else
704 			    (char_u *)NULL, PV_NONE,
705 			    {(char_u *)0L, (char_u *)0L}
706 #endif
707 			    SCTX_INIT},
708     {"bufhidden",   "bh",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
709 			    (char_u *)&p_bh, PV_BH,
710 			    {(char_u *)"", (char_u *)0L}
711 			    SCTX_INIT},
712     {"buflisted",   "bl",   P_BOOL|P_VI_DEF|P_NOGLOB,
713 			    (char_u *)&p_bl, PV_BL,
714 			    {(char_u *)1L, (char_u *)0L}
715 			    SCTX_INIT},
716     {"buftype",	    "bt",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
717 			    (char_u *)&p_bt, PV_BT,
718 			    {(char_u *)"", (char_u *)0L}
719 			    SCTX_INIT},
720     {"casemap",	    "cmp",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
721 			    (char_u *)&p_cmp, PV_NONE,
722 			    {(char_u *)"internal,keepascii", (char_u *)0L}
723 			    SCTX_INIT},
724     {"cdpath",	    "cd",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
725 #ifdef FEAT_SEARCHPATH
726 			    (char_u *)&p_cdpath, PV_NONE,
727 			    {(char_u *)",,", (char_u *)0L}
728 #else
729 			    (char_u *)NULL, PV_NONE,
730 			    {(char_u *)0L, (char_u *)0L}
731 #endif
732 			    SCTX_INIT},
733     {"cedit",	    NULL,   P_STRING,
734 #ifdef FEAT_CMDWIN
735 			    (char_u *)&p_cedit, PV_NONE,
736 			    {(char_u *)"", (char_u *)CTRL_F_STR}
737 #else
738 			    (char_u *)NULL, PV_NONE,
739 			    {(char_u *)0L, (char_u *)0L}
740 #endif
741 			    SCTX_INIT},
742     {"charconvert",  "ccv", P_STRING|P_VI_DEF|P_SECURE,
743 #if defined(FEAT_EVAL)
744 			    (char_u *)&p_ccv, PV_NONE,
745 			    {(char_u *)"", (char_u *)0L}
746 #else
747 			    (char_u *)NULL, PV_NONE,
748 			    {(char_u *)0L, (char_u *)0L}
749 #endif
750 			    SCTX_INIT},
751     {"cindent",	    "cin",  P_BOOL|P_VI_DEF|P_VIM,
752 #ifdef FEAT_CINDENT
753 			    (char_u *)&p_cin, PV_CIN,
754 #else
755 			    (char_u *)NULL, PV_NONE,
756 #endif
757 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
758     {"cinkeys",	    "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
759 #ifdef FEAT_CINDENT
760 			    (char_u *)&p_cink, PV_CINK,
761 			    {INDENTKEYS_DEFAULT, (char_u *)0L}
762 #else
763 			    (char_u *)NULL, PV_NONE,
764 			    {(char_u *)0L, (char_u *)0L}
765 #endif
766 			    SCTX_INIT},
767     {"cinoptions",  "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
768 #ifdef FEAT_CINDENT
769 			    (char_u *)&p_cino, PV_CINO,
770 #else
771 			    (char_u *)NULL, PV_NONE,
772 #endif
773 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
774     {"cinwords",    "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
775 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
776 			    (char_u *)&p_cinw, PV_CINW,
777 			    {(char_u *)"if,else,while,do,for,switch",
778 				(char_u *)0L}
779 #else
780 			    (char_u *)NULL, PV_NONE,
781 			    {(char_u *)0L, (char_u *)0L}
782 #endif
783 			    SCTX_INIT},
784     {"clipboard",   "cb",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
785 #ifdef FEAT_CLIPBOARD
786 			    (char_u *)&p_cb, PV_NONE,
787 # ifdef FEAT_XCLIPBOARD
788 			    {(char_u *)"autoselect,exclude:cons\\|linux",
789 							       (char_u *)0L}
790 # else
791 			    {(char_u *)"", (char_u *)0L}
792 # endif
793 #else
794 			    (char_u *)NULL, PV_NONE,
795 			    {(char_u *)"", (char_u *)0L}
796 #endif
797 			    SCTX_INIT},
798     {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
799 			    (char_u *)&p_ch, PV_NONE,
800 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
801     {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
802 #ifdef FEAT_CMDWIN
803 			    (char_u *)&p_cwh, PV_NONE,
804 #else
805 			    (char_u *)NULL, PV_NONE,
806 #endif
807 			    {(char_u *)7L, (char_u *)0L} SCTX_INIT},
808     {"colorcolumn", "cc",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
809 #ifdef FEAT_SYN_HL
810 			    (char_u *)VAR_WIN, PV_CC,
811 #else
812 			    (char_u *)NULL, PV_NONE,
813 #endif
814 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
815     {"columns",	    "co",   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
816 			    (char_u *)&Columns, PV_NONE,
817 			    {(char_u *)80L, (char_u *)0L} SCTX_INIT},
818     {"comments",    "com",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
819 							  |P_NODUP|P_CURSWANT,
820 #ifdef FEAT_COMMENTS
821 			    (char_u *)&p_com, PV_COM,
822 			    {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
823 				(char_u *)0L}
824 #else
825 			    (char_u *)NULL, PV_NONE,
826 			    {(char_u *)0L, (char_u *)0L}
827 #endif
828 			    SCTX_INIT},
829     {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
830 #ifdef FEAT_FOLDING
831 			    (char_u *)&p_cms, PV_CMS,
832 			    {(char_u *)"/*%s*/", (char_u *)0L}
833 #else
834 			    (char_u *)NULL, PV_NONE,
835 			    {(char_u *)0L, (char_u *)0L}
836 #endif
837 			    SCTX_INIT},
838 			    /* P_PRI_MKRC isn't needed here, optval_default()
839 			     * always returns TRUE for 'compatible' */
840     {"compatible",  "cp",   P_BOOL|P_RALL,
841 			    (char_u *)&p_cp, PV_NONE,
842 			    {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
843     {"complete",    "cpt",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
844 #ifdef FEAT_INS_EXPAND
845 			    (char_u *)&p_cpt, PV_CPT,
846 			    {(char_u *)".,w,b,u,t,i", (char_u *)0L}
847 #else
848 			    (char_u *)NULL, PV_NONE,
849 			    {(char_u *)0L, (char_u *)0L}
850 #endif
851 			    SCTX_INIT},
852     {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
853 #ifdef FEAT_CONCEAL
854 			    (char_u *)VAR_WIN, PV_COCU,
855 			    {(char_u *)"", (char_u *)NULL}
856 #else
857 			    (char_u *)NULL, PV_NONE,
858 			    {(char_u *)NULL, (char_u *)0L}
859 #endif
860 			    SCTX_INIT},
861     {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
862 #ifdef FEAT_CONCEAL
863 			    (char_u *)VAR_WIN, PV_COLE,
864 #else
865 			    (char_u *)NULL, PV_NONE,
866 #endif
867 			    {(char_u *)0L, (char_u *)0L}
868 			    SCTX_INIT},
869     {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
870 #ifdef FEAT_COMPL_FUNC
871 			    (char_u *)&p_cfu, PV_CFU,
872 			    {(char_u *)"", (char_u *)0L}
873 #else
874 			    (char_u *)NULL, PV_NONE,
875 			    {(char_u *)0L, (char_u *)0L}
876 #endif
877 			    SCTX_INIT},
878     {"completeopt",   "cot",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
879 #ifdef FEAT_INS_EXPAND
880 			    (char_u *)&p_cot, PV_NONE,
881 			    {(char_u *)"menu,preview", (char_u *)0L}
882 #else
883 			    (char_u *)NULL, PV_NONE,
884 			    {(char_u *)0L, (char_u *)0L}
885 #endif
886 			    SCTX_INIT},
887     {"confirm",     "cf",   P_BOOL|P_VI_DEF,
888 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
889 			    (char_u *)&p_confirm, PV_NONE,
890 #else
891 			    (char_u *)NULL, PV_NONE,
892 #endif
893 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
894     {"conskey",	    "consk",P_BOOL|P_VI_DEF,
895 			    (char_u *)NULL, PV_NONE,
896 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
897     {"copyindent",  "ci",   P_BOOL|P_VI_DEF|P_VIM,
898 			    (char_u *)&p_ci, PV_CI,
899 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
900     {"cpoptions",   "cpo",  P_STRING|P_VIM|P_RALL|P_FLAGLIST,
901 			    (char_u *)&p_cpo, PV_NONE,
902 			    {(char_u *)CPO_VI, (char_u *)CPO_VIM}
903 			    SCTX_INIT},
904     {"cryptmethod", "cm",   P_STRING|P_ALLOCED|P_VI_DEF,
905 #ifdef FEAT_CRYPT
906 			    (char_u *)&p_cm, PV_CM,
907 			    {(char_u *)"blowfish2", (char_u *)0L}
908 #else
909 			    (char_u *)NULL, PV_NONE,
910 			    {(char_u *)0L, (char_u *)0L}
911 #endif
912 			    SCTX_INIT},
913     {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
914 #ifdef FEAT_CSCOPE
915 			    (char_u *)&p_cspc, PV_NONE,
916 #else
917 			    (char_u *)NULL, PV_NONE,
918 #endif
919 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
920     {"cscopeprg",   "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
921 #ifdef FEAT_CSCOPE
922 			    (char_u *)&p_csprg, PV_NONE,
923 			    {(char_u *)"cscope", (char_u *)0L}
924 #else
925 			    (char_u *)NULL, PV_NONE,
926 			    {(char_u *)0L, (char_u *)0L}
927 #endif
928 			    SCTX_INIT},
929     {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
930 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
931 			    (char_u *)&p_csqf, PV_NONE,
932 			    {(char_u *)"", (char_u *)0L}
933 #else
934 			    (char_u *)NULL, PV_NONE,
935 			    {(char_u *)0L, (char_u *)0L}
936 #endif
937 			    SCTX_INIT},
938     {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
939 #ifdef FEAT_CSCOPE
940 			    (char_u *)&p_csre, PV_NONE,
941 #else
942 			    (char_u *)NULL, PV_NONE,
943 #endif
944 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
945     {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
946 #ifdef FEAT_CSCOPE
947 			    (char_u *)&p_cst, PV_NONE,
948 #else
949 			    (char_u *)NULL, PV_NONE,
950 #endif
951 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
952     {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
953 #ifdef FEAT_CSCOPE
954 			    (char_u *)&p_csto, PV_NONE,
955 #else
956 			    (char_u *)NULL, PV_NONE,
957 #endif
958 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
959     {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
960 #ifdef FEAT_CSCOPE
961 			    (char_u *)&p_csverbose, PV_NONE,
962 #else
963 			    (char_u *)NULL, PV_NONE,
964 #endif
965 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
966     {"cursorbind",  "crb",  P_BOOL|P_VI_DEF,
967 			    (char_u *)VAR_WIN, PV_CRBIND,
968 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
969     {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
970 #ifdef FEAT_SYN_HL
971 			    (char_u *)VAR_WIN, PV_CUC,
972 #else
973 			    (char_u *)NULL, PV_NONE,
974 #endif
975 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
976     {"cursorline",   "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
977 #ifdef FEAT_SYN_HL
978 			    (char_u *)VAR_WIN, PV_CUL,
979 #else
980 			    (char_u *)NULL, PV_NONE,
981 #endif
982 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
983     {"debug",	    NULL,   P_STRING|P_VI_DEF,
984 			    (char_u *)&p_debug, PV_NONE,
985 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
986     {"define",	    "def",  P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
987 #ifdef FEAT_FIND_ID
988 			    (char_u *)&p_def, PV_DEF,
989 			    {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
990 #else
991 			    (char_u *)NULL, PV_NONE,
992 			    {(char_u *)NULL, (char_u *)0L}
993 #endif
994 			    SCTX_INIT},
995     {"delcombine", "deco",  P_BOOL|P_VI_DEF|P_VIM,
996 			    (char_u *)&p_deco, PV_NONE,
997 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
998     {"dictionary",  "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
999 #ifdef FEAT_INS_EXPAND
1000 			    (char_u *)&p_dict, PV_DICT,
1001 #else
1002 			    (char_u *)NULL, PV_NONE,
1003 #endif
1004 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1005     {"diff",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1006 #ifdef FEAT_DIFF
1007 			    (char_u *)VAR_WIN, PV_DIFF,
1008 #else
1009 			    (char_u *)NULL, PV_NONE,
1010 #endif
1011 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1012     {"diffexpr",    "dex",  P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
1013 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1014 			    (char_u *)&p_dex, PV_NONE,
1015 			    {(char_u *)"", (char_u *)0L}
1016 #else
1017 			    (char_u *)NULL, PV_NONE,
1018 			    {(char_u *)0L, (char_u *)0L}
1019 #endif
1020 			    SCTX_INIT},
1021     {"diffopt",	    "dip",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1022 								     |P_NODUP,
1023 #ifdef FEAT_DIFF
1024 			    (char_u *)&p_dip, PV_NONE,
1025 			    {(char_u *)"internal,filler", (char_u *)NULL}
1026 #else
1027 			    (char_u *)NULL, PV_NONE,
1028 			    {(char_u *)"", (char_u *)NULL}
1029 #endif
1030 			    SCTX_INIT},
1031     {"digraph",	    "dg",   P_BOOL|P_VI_DEF|P_VIM,
1032 #ifdef FEAT_DIGRAPHS
1033 			    (char_u *)&p_dg, PV_NONE,
1034 #else
1035 			    (char_u *)NULL, PV_NONE,
1036 #endif
1037 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1038     {"directory",   "dir",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1039 							    |P_NODUP|P_SECURE,
1040 			    (char_u *)&p_dir, PV_NONE,
1041 			    {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
1042     {"display",	    "dy",   P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
1043 			    (char_u *)&p_dy, PV_NONE,
1044 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1045     {"eadirection", "ead",  P_STRING|P_VI_DEF,
1046 			    (char_u *)&p_ead, PV_NONE,
1047 			    {(char_u *)"both", (char_u *)0L}
1048 			    SCTX_INIT},
1049     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
1050 			    (char_u *)&p_ed, PV_NONE,
1051 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1052     {"emoji",  "emo",	    P_BOOL|P_VI_DEF|P_RCLR,
1053 			    (char_u *)&p_emoji, PV_NONE,
1054 			    {(char_u *)TRUE, (char_u *)0L}
1055 			    SCTX_INIT},
1056     {"encoding",    "enc",  P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
1057 			    (char_u *)&p_enc, PV_NONE,
1058 			    {(char_u *)ENC_DFLT, (char_u *)0L}
1059 			    SCTX_INIT},
1060     {"endofline",   "eol",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1061 			    (char_u *)&p_eol, PV_EOL,
1062 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1063     {"equalalways", "ea",   P_BOOL|P_VI_DEF|P_RALL,
1064 			    (char_u *)&p_ea, PV_NONE,
1065 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1066     {"equalprg",    "ep",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1067 			    (char_u *)&p_ep, PV_EP,
1068 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1069     {"errorbells",  "eb",   P_BOOL|P_VI_DEF,
1070 			    (char_u *)&p_eb, PV_NONE,
1071 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1072     {"errorfile",   "ef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1073 #ifdef FEAT_QUICKFIX
1074 			    (char_u *)&p_ef, PV_NONE,
1075 			    {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1076 #else
1077 			    (char_u *)NULL, PV_NONE,
1078 			    {(char_u *)NULL, (char_u *)0L}
1079 #endif
1080 			    SCTX_INIT},
1081     {"errorformat", "efm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1082 #ifdef FEAT_QUICKFIX
1083 			    (char_u *)&p_efm, PV_EFM,
1084 			    {(char_u *)DFLT_EFM, (char_u *)0L}
1085 #else
1086 			    (char_u *)NULL, PV_NONE,
1087 			    {(char_u *)NULL, (char_u *)0L}
1088 #endif
1089 			    SCTX_INIT},
1090     {"esckeys",	    "ek",   P_BOOL|P_VIM,
1091 			    (char_u *)&p_ek, PV_NONE,
1092 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
1093     {"eventignore", "ei",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1094 			    (char_u *)&p_ei, PV_NONE,
1095 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1096     {"expandtab",   "et",   P_BOOL|P_VI_DEF|P_VIM,
1097 			    (char_u *)&p_et, PV_ET,
1098 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1099     {"exrc",	    "ex",   P_BOOL|P_VI_DEF|P_SECURE,
1100 			    (char_u *)&p_exrc, PV_NONE,
1101 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1102     {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1103 								   |P_NO_MKRC,
1104 			    (char_u *)&p_fenc, PV_FENC,
1105 			    {(char_u *)"", (char_u *)0L}
1106 			    SCTX_INIT},
1107     {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
1108 			    (char_u *)&p_fencs, PV_NONE,
1109 			    {(char_u *)"ucs-bom", (char_u *)0L}
1110 			    SCTX_INIT},
1111     {"fileformat",  "ff",   P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1112 								  |P_CURSWANT,
1113 			    (char_u *)&p_ff, PV_FF,
1114 			    {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
1115     {"fileformats", "ffs",  P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
1116 			    (char_u *)&p_ffs, PV_NONE,
1117 			    {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1118 			    SCTX_INIT},
1119     {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1120 			    (char_u *)&p_fic, PV_NONE,
1121 			    {
1122 #ifdef CASE_INSENSITIVE_FILENAME
1123 				    (char_u *)TRUE,
1124 #else
1125 				    (char_u *)FALSE,
1126 #endif
1127 					(char_u *)0L} SCTX_INIT},
1128     {"filetype",    "ft",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
1129 			    (char_u *)&p_ft, PV_FT,
1130 			    {(char_u *)"", (char_u *)0L}
1131 			    SCTX_INIT},
1132     {"fillchars",   "fcs",  P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
1133 			    (char_u *)&p_fcs, PV_NONE,
1134 			    {(char_u *)"vert:|,fold:-", (char_u *)0L}
1135 			    SCTX_INIT},
1136     {"fixendofline",  "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1137 			    (char_u *)&p_fixeol, PV_FIXEOL,
1138 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1139     {"fkmap",	    "fk",   P_BOOL|P_VI_DEF,
1140 			    (char_u *)NULL, PV_NONE,
1141 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1142     {"flash",	    "fl",   P_BOOL|P_VI_DEF,
1143 			    (char_u *)NULL, PV_NONE,
1144 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1145     {"foldclose",   "fcl",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
1146 #ifdef FEAT_FOLDING
1147 			    (char_u *)&p_fcl, PV_NONE,
1148 			    {(char_u *)"", (char_u *)0L}
1149 #else
1150 			    (char_u *)NULL, PV_NONE,
1151 			    {(char_u *)NULL, (char_u *)0L}
1152 #endif
1153 			    SCTX_INIT},
1154     {"foldcolumn",  "fdc",  P_NUM|P_VI_DEF|P_RWIN,
1155 #ifdef FEAT_FOLDING
1156 			    (char_u *)VAR_WIN, PV_FDC,
1157 			    {(char_u *)FALSE, (char_u *)0L}
1158 #else
1159 			    (char_u *)NULL, PV_NONE,
1160 			    {(char_u *)NULL, (char_u *)0L}
1161 #endif
1162 			    SCTX_INIT},
1163     {"foldenable",  "fen",  P_BOOL|P_VI_DEF|P_RWIN,
1164 #ifdef FEAT_FOLDING
1165 			    (char_u *)VAR_WIN, PV_FEN,
1166 			    {(char_u *)TRUE, (char_u *)0L}
1167 #else
1168 			    (char_u *)NULL, PV_NONE,
1169 			    {(char_u *)NULL, (char_u *)0L}
1170 #endif
1171 			    SCTX_INIT},
1172     {"foldexpr",    "fde",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1173 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1174 			    (char_u *)VAR_WIN, PV_FDE,
1175 			    {(char_u *)"0", (char_u *)NULL}
1176 #else
1177 			    (char_u *)NULL, PV_NONE,
1178 			    {(char_u *)NULL, (char_u *)0L}
1179 #endif
1180 			    SCTX_INIT},
1181     {"foldignore",  "fdi",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1182 #ifdef FEAT_FOLDING
1183 			    (char_u *)VAR_WIN, PV_FDI,
1184 			    {(char_u *)"#", (char_u *)NULL}
1185 #else
1186 			    (char_u *)NULL, PV_NONE,
1187 			    {(char_u *)NULL, (char_u *)0L}
1188 #endif
1189 			    SCTX_INIT},
1190     {"foldlevel",   "fdl",  P_NUM|P_VI_DEF|P_RWIN,
1191 #ifdef FEAT_FOLDING
1192 			    (char_u *)VAR_WIN, PV_FDL,
1193 			    {(char_u *)0L, (char_u *)0L}
1194 #else
1195 			    (char_u *)NULL, PV_NONE,
1196 			    {(char_u *)NULL, (char_u *)0L}
1197 #endif
1198 			    SCTX_INIT},
1199     {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
1200 #ifdef FEAT_FOLDING
1201 			    (char_u *)&p_fdls, PV_NONE,
1202 			    {(char_u *)-1L, (char_u *)0L}
1203 #else
1204 			    (char_u *)NULL, PV_NONE,
1205 			    {(char_u *)NULL, (char_u *)0L}
1206 #endif
1207 			    SCTX_INIT},
1208     {"foldmarker",  "fmr",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1209 						    P_RWIN|P_ONECOMMA|P_NODUP,
1210 #ifdef FEAT_FOLDING
1211 			    (char_u *)VAR_WIN, PV_FMR,
1212 			    {(char_u *)"{{{,}}}", (char_u *)NULL}
1213 #else
1214 			    (char_u *)NULL, PV_NONE,
1215 			    {(char_u *)NULL, (char_u *)0L}
1216 #endif
1217 			    SCTX_INIT},
1218     {"foldmethod",  "fdm",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219 #ifdef FEAT_FOLDING
1220 			    (char_u *)VAR_WIN, PV_FDM,
1221 			    {(char_u *)"manual", (char_u *)NULL}
1222 #else
1223 			    (char_u *)NULL, PV_NONE,
1224 			    {(char_u *)NULL, (char_u *)0L}
1225 #endif
1226 			    SCTX_INIT},
1227     {"foldminlines","fml",  P_NUM|P_VI_DEF|P_RWIN,
1228 #ifdef FEAT_FOLDING
1229 			    (char_u *)VAR_WIN, PV_FML,
1230 			    {(char_u *)1L, (char_u *)0L}
1231 #else
1232 			    (char_u *)NULL, PV_NONE,
1233 			    {(char_u *)NULL, (char_u *)0L}
1234 #endif
1235 			    SCTX_INIT},
1236     {"foldnestmax", "fdn",  P_NUM|P_VI_DEF|P_RWIN,
1237 #ifdef FEAT_FOLDING
1238 			    (char_u *)VAR_WIN, PV_FDN,
1239 			    {(char_u *)20L, (char_u *)0L}
1240 #else
1241 			    (char_u *)NULL, PV_NONE,
1242 			    {(char_u *)NULL, (char_u *)0L}
1243 #endif
1244 			    SCTX_INIT},
1245     {"foldopen",    "fdo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1246 #ifdef FEAT_FOLDING
1247 			    (char_u *)&p_fdo, PV_NONE,
1248 		 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1249 						 (char_u *)0L}
1250 #else
1251 			    (char_u *)NULL, PV_NONE,
1252 			    {(char_u *)NULL, (char_u *)0L}
1253 #endif
1254 			    SCTX_INIT},
1255     {"foldtext",    "fdt",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1256 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1257 			    (char_u *)VAR_WIN, PV_FDT,
1258 			    {(char_u *)"foldtext()", (char_u *)NULL}
1259 #else
1260 			    (char_u *)NULL, PV_NONE,
1261 			    {(char_u *)NULL, (char_u *)0L}
1262 #endif
1263 			    SCTX_INIT},
1264     {"formatexpr", "fex",   P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1265 #ifdef FEAT_EVAL
1266 			    (char_u *)&p_fex, PV_FEX,
1267 			    {(char_u *)"", (char_u *)0L}
1268 #else
1269 			    (char_u *)NULL, PV_NONE,
1270 			    {(char_u *)0L, (char_u *)0L}
1271 #endif
1272 			    SCTX_INIT},
1273     {"formatoptions","fo",  P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1274 			    (char_u *)&p_fo, PV_FO,
1275 			    {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1276 			    SCTX_INIT},
1277     {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1278 			    (char_u *)&p_flp, PV_FLP,
1279 			    {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1280 						 (char_u *)0L} SCTX_INIT},
1281     {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1282 			    (char_u *)&p_fp, PV_FP,
1283 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1284     {"fsync",       "fs",   P_BOOL|P_SECURE|P_VI_DEF,
1285 #ifdef HAVE_FSYNC
1286 			    (char_u *)&p_fs, PV_NONE,
1287 			    {(char_u *)TRUE, (char_u *)0L}
1288 #else
1289 			    (char_u *)NULL, PV_NONE,
1290 			    {(char_u *)FALSE, (char_u *)0L}
1291 #endif
1292 			    SCTX_INIT},
1293     {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
1294 			    (char_u *)&p_gd, PV_NONE,
1295 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1296     {"graphic",	    "gr",   P_BOOL|P_VI_DEF,
1297 			    (char_u *)NULL, PV_NONE,
1298 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1299     {"grepformat",  "gfm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1300 #ifdef FEAT_QUICKFIX
1301 			    (char_u *)&p_gefm, PV_NONE,
1302 			    {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
1303 #else
1304 			    (char_u *)NULL, PV_NONE,
1305 			    {(char_u *)NULL, (char_u *)0L}
1306 #endif
1307 			    SCTX_INIT},
1308     {"grepprg",	    "gp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1309 #ifdef FEAT_QUICKFIX
1310 			    (char_u *)&p_gp, PV_GP,
1311 			    {
1312 # ifdef MSWIN
1313 			    /* may be changed to "grep -n" in os_win32.c */
1314 			    (char_u *)"findstr /n",
1315 # else
1316 #  ifdef UNIX
1317 			    /* Add an extra file name so that grep will always
1318 			     * insert a file name in the match line. */
1319 			    (char_u *)"grep -n $* /dev/null",
1320 #  else
1321 #   ifdef VMS
1322 			    (char_u *)"SEARCH/NUMBERS ",
1323 #   else
1324 			    (char_u *)"grep -n ",
1325 #   endif
1326 #  endif
1327 # endif
1328 			    (char_u *)0L}
1329 #else
1330 			    (char_u *)NULL, PV_NONE,
1331 			    {(char_u *)NULL, (char_u *)0L}
1332 #endif
1333 			    SCTX_INIT},
1334     {"guicursor",    "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1335 #ifdef CURSOR_SHAPE
1336 			    (char_u *)&p_guicursor, PV_NONE,
1337 			    {
1338 # ifdef FEAT_GUI
1339 				(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",
1340 # else	/* Win32 console */
1341 				(char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1342 # endif
1343 				    (char_u *)0L}
1344 #else
1345 			    (char_u *)NULL, PV_NONE,
1346 			    {(char_u *)NULL, (char_u *)0L}
1347 #endif
1348 			    SCTX_INIT},
1349     {"guifont",	    "gfn",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1350 #ifdef FEAT_GUI
1351 			    (char_u *)&p_guifont, PV_NONE,
1352 			    {(char_u *)"", (char_u *)0L}
1353 #else
1354 			    (char_u *)NULL, PV_NONE,
1355 			    {(char_u *)NULL, (char_u *)0L}
1356 #endif
1357 			    SCTX_INIT},
1358     {"guifontset",  "gfs",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
1359 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1360 			    (char_u *)&p_guifontset, 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     {"guifontwide", "gfw",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1368 #if defined(FEAT_GUI)
1369 			    (char_u *)&p_guifontwide, 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     {"guiheadroom", "ghr",  P_NUM|P_VI_DEF,
1377 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
1378 			    (char_u *)&p_ghr, PV_NONE,
1379 #else
1380 			    (char_u *)NULL, PV_NONE,
1381 #endif
1382 			    {(char_u *)50L, (char_u *)0L} SCTX_INIT},
1383     {"guioptions",  "go",   P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
1384 #if defined(FEAT_GUI)
1385 			    (char_u *)&p_go, PV_NONE,
1386 # if defined(UNIX) && !defined(FEAT_GUI_MAC)
1387 			    {(char_u *)"aegimrLtT", (char_u *)0L}
1388 # else
1389 			    {(char_u *)"egmrLtT", (char_u *)0L}
1390 # endif
1391 #else
1392 			    (char_u *)NULL, PV_NONE,
1393 			    {(char_u *)NULL, (char_u *)0L}
1394 #endif
1395 			    SCTX_INIT},
1396     {"guipty",	    NULL,   P_BOOL|P_VI_DEF,
1397 #if defined(FEAT_GUI)
1398 			    (char_u *)&p_guipty, PV_NONE,
1399 #else
1400 			    (char_u *)NULL, PV_NONE,
1401 #endif
1402 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1403     {"guitablabel",  "gtl", P_STRING|P_VI_DEF|P_RWIN,
1404 #if defined(FEAT_GUI_TABLINE)
1405 			    (char_u *)&p_gtl, PV_NONE,
1406 			    {(char_u *)"", (char_u *)0L}
1407 #else
1408 			    (char_u *)NULL, PV_NONE,
1409 			    {(char_u *)NULL, (char_u *)0L}
1410 #endif
1411 			    SCTX_INIT},
1412     {"guitabtooltip",  "gtt", P_STRING|P_VI_DEF|P_RWIN,
1413 #if defined(FEAT_GUI_TABLINE)
1414 			    (char_u *)&p_gtt, 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     {"hardtabs",    "ht",   P_NUM|P_VI_DEF,
1422 			    (char_u *)NULL, PV_NONE,
1423 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
1424     {"helpfile",    "hf",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1425 			    (char_u *)&p_hf, PV_NONE,
1426 			    {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1427 			    SCTX_INIT},
1428     {"helpheight",  "hh",   P_NUM|P_VI_DEF,
1429 			    (char_u *)&p_hh, PV_NONE,
1430 			    {(char_u *)20L, (char_u *)0L} SCTX_INIT},
1431     {"helplang",    "hlg",  P_STRING|P_VI_DEF|P_ONECOMMA,
1432 #ifdef FEAT_MULTI_LANG
1433 			    (char_u *)&p_hlg, PV_NONE,
1434 			    {(char_u *)"", (char_u *)0L}
1435 #else
1436 			    (char_u *)NULL, PV_NONE,
1437 			    {(char_u *)0L, (char_u *)0L}
1438 #endif
1439 			    SCTX_INIT},
1440     {"hidden",	    "hid",  P_BOOL|P_VI_DEF,
1441 			    (char_u *)&p_hid, PV_NONE,
1442 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1443     {"highlight",   "hl",   P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1444 			    (char_u *)&p_hl, PV_NONE,
1445 			    {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1446 			    SCTX_INIT},
1447     {"history",	    "hi",   P_NUM|P_VIM,
1448 			    (char_u *)&p_hi, PV_NONE,
1449 			    {(char_u *)0L, (char_u *)50L} SCTX_INIT},
1450     {"hkmap",	    "hk",   P_BOOL|P_VI_DEF|P_VIM,
1451 #ifdef FEAT_RIGHTLEFT
1452 			    (char_u *)&p_hkmap, PV_NONE,
1453 #else
1454 			    (char_u *)NULL, PV_NONE,
1455 #endif
1456 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1457     {"hkmapp",	    "hkp",  P_BOOL|P_VI_DEF|P_VIM,
1458 #ifdef FEAT_RIGHTLEFT
1459 			    (char_u *)&p_hkmapp, PV_NONE,
1460 #else
1461 			    (char_u *)NULL, PV_NONE,
1462 #endif
1463 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1464     {"hlsearch",    "hls",  P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1465 			    (char_u *)&p_hls, PV_NONE,
1466 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1467     {"icon",	    NULL,   P_BOOL|P_VI_DEF,
1468 #ifdef FEAT_TITLE
1469 			    (char_u *)&p_icon, PV_NONE,
1470 #else
1471 			    (char_u *)NULL, PV_NONE,
1472 #endif
1473 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1474     {"iconstring",  NULL,   P_STRING|P_VI_DEF,
1475 #ifdef FEAT_TITLE
1476 			    (char_u *)&p_iconstring, PV_NONE,
1477 #else
1478 			    (char_u *)NULL, PV_NONE,
1479 #endif
1480 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1481     {"ignorecase",  "ic",   P_BOOL|P_VI_DEF,
1482 			    (char_u *)&p_ic, PV_NONE,
1483 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1484     {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1485 #if defined(FEAT_EVAL)
1486 			    (char_u *)&p_imaf, PV_NONE,
1487 			    {(char_u *)"", (char_u *)NULL}
1488 # else
1489 			    (char_u *)NULL, PV_NONE,
1490 			    {(char_u *)NULL, (char_u *)0L}
1491 # endif
1492 			    SCTX_INIT},
1493     {"imactivatekey","imak",P_STRING|P_VI_DEF,
1494 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1495 			    (char_u *)&p_imak, PV_NONE,
1496 #else
1497 			    (char_u *)NULL, PV_NONE,
1498 #endif
1499 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1500     {"imcmdline",   "imc",  P_BOOL|P_VI_DEF,
1501 			    (char_u *)&p_imcmdline, PV_NONE,
1502 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1503     {"imdisable",   "imd",  P_BOOL|P_VI_DEF,
1504 			    (char_u *)&p_imdisable, PV_NONE,
1505 #ifdef __sgi
1506 			    {(char_u *)TRUE, (char_u *)0L}
1507 #else
1508 			    {(char_u *)FALSE, (char_u *)0L}
1509 #endif
1510 			    SCTX_INIT},
1511     {"iminsert",    "imi",  P_NUM|P_VI_DEF,
1512 			    (char_u *)&p_iminsert, PV_IMI,
1513 			    {(char_u *)B_IMODE_NONE, (char_u *)0L}
1514 			    SCTX_INIT},
1515     {"imsearch",    "ims",  P_NUM|P_VI_DEF,
1516 			    (char_u *)&p_imsearch, PV_IMS,
1517 			    {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
1518 			    SCTX_INIT},
1519     {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
1520 #if defined(FEAT_EVAL)
1521 			    (char_u *)&p_imsf, PV_NONE,
1522 			    {(char_u *)"", (char_u *)NULL}
1523 #else
1524 			    (char_u *)NULL, PV_NONE,
1525 			    {(char_u *)NULL, (char_u *)0L}
1526 #endif
1527 			    SCTX_INIT},
1528     {"imstyle",	    "imst", P_NUM|P_VI_DEF|P_SECURE,
1529 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1530 			    (char_u *)&p_imst, PV_NONE,
1531 			    {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1532 #else
1533 			    (char_u *)NULL, PV_NONE,
1534 			    {(char_u *)0L, (char_u *)0L}
1535 #endif
1536 			    SCTX_INIT},
1537     {"include",	    "inc",  P_STRING|P_ALLOCED|P_VI_DEF,
1538 #ifdef FEAT_FIND_ID
1539 			    (char_u *)&p_inc, PV_INC,
1540 			    {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1541 #else
1542 			    (char_u *)NULL, PV_NONE,
1543 			    {(char_u *)0L, (char_u *)0L}
1544 #endif
1545 			    SCTX_INIT},
1546     {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1547 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1548 			    (char_u *)&p_inex, PV_INEX,
1549 			    {(char_u *)"", (char_u *)0L}
1550 #else
1551 			    (char_u *)NULL, PV_NONE,
1552 			    {(char_u *)0L, (char_u *)0L}
1553 #endif
1554 			    SCTX_INIT},
1555     {"incsearch",   "is",   P_BOOL|P_VI_DEF|P_VIM,
1556 			    (char_u *)&p_is, PV_NONE,
1557 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1558     {"indentexpr", "inde",  P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1559 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1560 			    (char_u *)&p_inde, PV_INDE,
1561 			    {(char_u *)"", (char_u *)0L}
1562 #else
1563 			    (char_u *)NULL, PV_NONE,
1564 			    {(char_u *)0L, (char_u *)0L}
1565 #endif
1566 			    SCTX_INIT},
1567     {"indentkeys", "indk",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1568 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1569 			    (char_u *)&p_indk, PV_INDK,
1570 			    {INDENTKEYS_DEFAULT, (char_u *)0L}
1571 #else
1572 			    (char_u *)NULL, PV_NONE,
1573 			    {(char_u *)0L, (char_u *)0L}
1574 #endif
1575 			    SCTX_INIT},
1576     {"infercase",   "inf",  P_BOOL|P_VI_DEF,
1577 			    (char_u *)&p_inf, PV_INF,
1578 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1579     {"insertmode",  "im",   P_BOOL|P_VI_DEF|P_VIM,
1580 			    (char_u *)&p_im, PV_NONE,
1581 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1582     {"isfname",	    "isf",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1583 			    (char_u *)&p_isf, PV_NONE,
1584 			    {
1585 #ifdef BACKSLASH_IN_FILENAME
1586 				/* Excluded are: & and ^ are special in cmd.exe
1587 				 * ( and ) are used in text separating fnames */
1588 			    (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1589 #else
1590 # ifdef AMIGA
1591 			    (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1592 # else
1593 #  ifdef VMS
1594 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1595 #  else /* UNIX et al. */
1596 #   ifdef EBCDIC
1597 			    (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1598 #   else
1599 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1600 #   endif
1601 #  endif
1602 # endif
1603 #endif
1604 				(char_u *)0L} SCTX_INIT},
1605     {"isident",	    "isi",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1606 			    (char_u *)&p_isi, PV_NONE,
1607 			    {
1608 #if defined(MSWIN)
1609 			    (char_u *)"@,48-57,_,128-167,224-235",
1610 #else
1611 # ifdef EBCDIC
1612 			    /* TODO: EBCDIC Check this! @ == isalpha()*/
1613 			    (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1614 				    "112-120,128,140-142,156,158,172,"
1615 				    "174,186,191,203-207,219-225,235-239,"
1616 				    "251-254",
1617 # else
1618 			    (char_u *)"@,48-57,_,192-255",
1619 # endif
1620 #endif
1621 				(char_u *)0L} SCTX_INIT},
1622     {"iskeyword",   "isk",  P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1623 			    (char_u *)&p_isk, PV_ISK,
1624 			    {
1625 #ifdef EBCDIC
1626 			     (char_u *)"@,240-249,_",
1627 			     /* TODO: EBCDIC Check this! @ == isalpha()*/
1628 			     (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1629 				    "112-120,128,140-142,156,158,172,"
1630 				    "174,186,191,203-207,219-225,235-239,"
1631 				    "251-254",
1632 #else
1633 				(char_u *)"@,48-57,_",
1634 # if defined(MSWIN)
1635 				(char_u *)"@,48-57,_,128-167,224-235"
1636 # else
1637 				ISK_LATIN1
1638 # endif
1639 #endif
1640 			    } SCTX_INIT},
1641     {"isprint",	    "isp",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1642 			    (char_u *)&p_isp, PV_NONE,
1643 			    {
1644 #if defined(MSWIN) || defined(VMS)
1645 			    (char_u *)"@,~-255",
1646 #else
1647 # ifdef EBCDIC
1648 			    /* all chars above 63 are printable */
1649 			    (char_u *)"63-255",
1650 # else
1651 			    ISP_LATIN1,
1652 # endif
1653 #endif
1654 				(char_u *)0L} SCTX_INIT},
1655     {"joinspaces",  "js",   P_BOOL|P_VI_DEF|P_VIM,
1656 			    (char_u *)&p_js, PV_NONE,
1657 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1658     {"key",	    NULL,   P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1659 #ifdef FEAT_CRYPT
1660 			    (char_u *)&p_key, PV_KEY,
1661 			    {(char_u *)"", (char_u *)0L}
1662 #else
1663 			    (char_u *)NULL, PV_NONE,
1664 			    {(char_u *)0L, (char_u *)0L}
1665 #endif
1666 			    SCTX_INIT},
1667     {"keymap",	    "kmp",  P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
1668 #ifdef FEAT_KEYMAP
1669 			    (char_u *)&p_keymap, PV_KMAP,
1670 			    {(char_u *)"", (char_u *)0L}
1671 #else
1672 			    (char_u *)NULL, PV_NONE,
1673 			    {(char_u *)"", (char_u *)0L}
1674 #endif
1675 			    SCTX_INIT},
1676     {"keymodel",    "km",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1677 			    (char_u *)&p_km, PV_NONE,
1678 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1679     {"keywordprg",  "kp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1680 			    (char_u *)&p_kp, PV_KP,
1681 			    {
1682 #ifdef MSWIN
1683 			    (char_u *)":help",
1684 #else
1685 # ifdef VMS
1686 			    (char_u *)"help",
1687 # else
1688 #  ifdef USEMAN_S
1689 			    (char_u *)"man -s",
1690 #  else
1691 			    (char_u *)"man",
1692 #  endif
1693 # endif
1694 #endif
1695 				(char_u *)0L} SCTX_INIT},
1696     {"langmap",     "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
1697 #ifdef FEAT_LANGMAP
1698 			    (char_u *)&p_langmap, PV_NONE,
1699 			    {(char_u *)"", (char_u *)0L}
1700 #else
1701 			    (char_u *)NULL, PV_NONE,
1702 			    {(char_u *)NULL, (char_u *)0L}
1703 #endif
1704 			    SCTX_INIT},
1705     {"langmenu",    "lm",   P_STRING|P_VI_DEF|P_NFNAME,
1706 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1707 			    (char_u *)&p_lm, PV_NONE,
1708 #else
1709 			    (char_u *)NULL, PV_NONE,
1710 #endif
1711 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1712     {"langnoremap",  "lnr",   P_BOOL|P_VI_DEF,
1713 #ifdef FEAT_LANGMAP
1714 			    (char_u *)&p_lnr, PV_NONE,
1715 #else
1716 			    (char_u *)NULL, PV_NONE,
1717 #endif
1718 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1719     {"langremap",  "lrm",   P_BOOL|P_VI_DEF,
1720 #ifdef FEAT_LANGMAP
1721 			    (char_u *)&p_lrm, PV_NONE,
1722 #else
1723 			    (char_u *)NULL, PV_NONE,
1724 #endif
1725 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1726     {"laststatus",  "ls",   P_NUM|P_VI_DEF|P_RALL,
1727 			    (char_u *)&p_ls, PV_NONE,
1728 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
1729     {"lazyredraw",  "lz",   P_BOOL|P_VI_DEF,
1730 			    (char_u *)&p_lz, PV_NONE,
1731 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1732     {"linebreak",   "lbr",  P_BOOL|P_VI_DEF|P_RWIN,
1733 #ifdef FEAT_LINEBREAK
1734 			    (char_u *)VAR_WIN, PV_LBR,
1735 #else
1736 			    (char_u *)NULL, PV_NONE,
1737 #endif
1738 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1739     {"lines",	    NULL,   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1740 			    (char_u *)&Rows, PV_NONE,
1741 			    {
1742 #if defined(MSWIN)
1743 			    (char_u *)25L,
1744 #else
1745 			    (char_u *)24L,
1746 #endif
1747 					    (char_u *)0L} SCTX_INIT},
1748     {"linespace",   "lsp",  P_NUM|P_VI_DEF|P_RCLR,
1749 #ifdef FEAT_GUI
1750 			    (char_u *)&p_linespace, PV_NONE,
1751 #else
1752 			    (char_u *)NULL, PV_NONE,
1753 #endif
1754 #ifdef FEAT_GUI_MSWIN
1755 			    {(char_u *)1L, (char_u *)0L}
1756 #else
1757 			    {(char_u *)0L, (char_u *)0L}
1758 #endif
1759 			    SCTX_INIT},
1760     {"lisp",	    NULL,   P_BOOL|P_VI_DEF,
1761 #ifdef FEAT_LISP
1762 			    (char_u *)&p_lisp, PV_LISP,
1763 #else
1764 			    (char_u *)NULL, PV_NONE,
1765 #endif
1766 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1767     {"lispwords",   "lw",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1768 #ifdef FEAT_LISP
1769 			    (char_u *)&p_lispwords, PV_LW,
1770 			    {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1771 #else
1772 			    (char_u *)NULL, PV_NONE,
1773 			    {(char_u *)"", (char_u *)0L}
1774 #endif
1775 			    SCTX_INIT},
1776     {"list",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
1777 			    (char_u *)VAR_WIN, PV_LIST,
1778 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1779     {"listchars",   "lcs",  P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
1780 			    (char_u *)&p_lcs, PV_NONE,
1781 			    {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
1782     {"loadplugins", "lpl",  P_BOOL|P_VI_DEF,
1783 			    (char_u *)&p_lpl, PV_NONE,
1784 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1785     {"luadll",      NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1786 #if defined(DYNAMIC_LUA)
1787 			    (char_u *)&p_luadll, PV_NONE,
1788 			    {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1789 #else
1790 			    (char_u *)NULL, PV_NONE,
1791 			    {(char_u *)"", (char_u *)0L}
1792 #endif
1793 			    SCTX_INIT},
1794     {"macatsui",    NULL,   P_BOOL|P_VI_DEF|P_RCLR,
1795 #ifdef FEAT_GUI_MAC
1796 			    (char_u *)&p_macatsui, PV_NONE,
1797 			    {(char_u *)TRUE, (char_u *)0L}
1798 #else
1799 			    (char_u *)NULL, PV_NONE,
1800 			    {(char_u *)"", (char_u *)0L}
1801 #endif
1802 			    SCTX_INIT},
1803     {"magic",	    NULL,   P_BOOL|P_VI_DEF,
1804 			    (char_u *)&p_magic, PV_NONE,
1805 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1806     {"makeef",	    "mef",  P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1807 #ifdef FEAT_QUICKFIX
1808 			    (char_u *)&p_mef, PV_NONE,
1809 			    {(char_u *)"", (char_u *)0L}
1810 #else
1811 			    (char_u *)NULL, PV_NONE,
1812 			    {(char_u *)NULL, (char_u *)0L}
1813 #endif
1814 			    SCTX_INIT},
1815     {"makeencoding","menc", P_STRING|P_VI_DEF,
1816 			    (char_u *)&p_menc, PV_MENC,
1817 			    {(char_u *)"", (char_u *)0L}
1818 			    SCTX_INIT},
1819     {"makeprg",	    "mp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1820 #ifdef FEAT_QUICKFIX
1821 			    (char_u *)&p_mp, PV_MP,
1822 # ifdef VMS
1823 			    {(char_u *)"MMS", (char_u *)0L}
1824 # else
1825 			    {(char_u *)"make", (char_u *)0L}
1826 # endif
1827 #else
1828 			    (char_u *)NULL, PV_NONE,
1829 			    {(char_u *)NULL, (char_u *)0L}
1830 #endif
1831 			    SCTX_INIT},
1832     {"matchpairs",  "mps",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1833 			    (char_u *)&p_mps, PV_MPS,
1834 			    {(char_u *)"(:),{:},[:]", (char_u *)0L}
1835 			    SCTX_INIT},
1836     {"matchtime",   "mat",  P_NUM|P_VI_DEF,
1837 			    (char_u *)&p_mat, PV_NONE,
1838 			    {(char_u *)5L, (char_u *)0L} SCTX_INIT},
1839     {"maxcombine",  "mco",  P_NUM|P_VI_DEF|P_CURSWANT,
1840 			    (char_u *)&p_mco, PV_NONE,
1841 			    {(char_u *)2, (char_u *)0L} SCTX_INIT},
1842     {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1843 #ifdef FEAT_EVAL
1844 			    (char_u *)&p_mfd, PV_NONE,
1845 #else
1846 			    (char_u *)NULL, PV_NONE,
1847 #endif
1848 			    {(char_u *)100L, (char_u *)0L} SCTX_INIT},
1849     {"maxmapdepth", "mmd",  P_NUM|P_VI_DEF,
1850 			    (char_u *)&p_mmd, PV_NONE,
1851 			    {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
1852     {"maxmem",	    "mm",   P_NUM|P_VI_DEF,
1853 			    (char_u *)&p_mm, PV_NONE,
1854 			    {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1855 			    SCTX_INIT},
1856     {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1857 			    (char_u *)&p_mmp, PV_NONE,
1858 			    {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
1859     {"maxmemtot",   "mmt",  P_NUM|P_VI_DEF,
1860 			    (char_u *)&p_mmt, PV_NONE,
1861 			    {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1862 			    SCTX_INIT},
1863     {"menuitems",   "mis",  P_NUM|P_VI_DEF,
1864 #ifdef FEAT_MENU
1865 			    (char_u *)&p_mis, PV_NONE,
1866 #else
1867 			    (char_u *)NULL, PV_NONE,
1868 #endif
1869 			    {(char_u *)25L, (char_u *)0L} SCTX_INIT},
1870     {"mesg",	    NULL,   P_BOOL|P_VI_DEF,
1871 			    (char_u *)NULL, PV_NONE,
1872 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1873     {"mkspellmem",  "msm",  P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
1874 #ifdef FEAT_SPELL
1875 			    (char_u *)&p_msm, PV_NONE,
1876 			    {(char_u *)"460000,2000,500", (char_u *)0L}
1877 #else
1878 			    (char_u *)NULL, PV_NONE,
1879 			    {(char_u *)0L, (char_u *)0L}
1880 #endif
1881 			    SCTX_INIT},
1882     {"modeline",    "ml",   P_BOOL|P_VIM,
1883 			    (char_u *)&p_ml, PV_ML,
1884 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
1885     {"modelines",   "mls",  P_NUM|P_VI_DEF,
1886 			    (char_u *)&p_mls, PV_NONE,
1887 			    {(char_u *)5L, (char_u *)0L} SCTX_INIT},
1888     {"modifiable",  "ma",   P_BOOL|P_VI_DEF|P_NOGLOB,
1889 			    (char_u *)&p_ma, PV_MA,
1890 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1891     {"modified",    "mod",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1892 			    (char_u *)&p_mod, PV_MOD,
1893 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1894     {"more",	    NULL,   P_BOOL|P_VIM,
1895 			    (char_u *)&p_more, PV_NONE,
1896 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
1897     {"mouse",	    NULL,   P_STRING|P_VI_DEF|P_FLAGLIST,
1898 			    (char_u *)&p_mouse, PV_NONE,
1899 			    {
1900 #if defined(MSWIN)
1901 				(char_u *)"a",
1902 #else
1903 				(char_u *)"",
1904 #endif
1905 				(char_u *)0L} SCTX_INIT},
1906     {"mousefocus",   "mousef", P_BOOL|P_VI_DEF,
1907 #ifdef FEAT_GUI
1908 			    (char_u *)&p_mousef, PV_NONE,
1909 #else
1910 			    (char_u *)NULL, PV_NONE,
1911 #endif
1912 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1913     {"mousehide",   "mh",   P_BOOL|P_VI_DEF,
1914 #ifdef FEAT_GUI
1915 			    (char_u *)&p_mh, PV_NONE,
1916 #else
1917 			    (char_u *)NULL, PV_NONE,
1918 #endif
1919 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1920     {"mousemodel",  "mousem", P_STRING|P_VI_DEF,
1921 			    (char_u *)&p_mousem, PV_NONE,
1922 			    {
1923 #if defined(MSWIN)
1924 				(char_u *)"popup",
1925 #else
1926 # if defined(MACOS_X)
1927 				(char_u *)"popup_setpos",
1928 # else
1929 				(char_u *)"extend",
1930 # endif
1931 #endif
1932 				(char_u *)0L} SCTX_INIT},
1933     {"mouseshape",  "mouses",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1934 #ifdef FEAT_MOUSESHAPE
1935 			    (char_u *)&p_mouseshape, PV_NONE,
1936 			    {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1937 #else
1938 			    (char_u *)NULL, PV_NONE,
1939 			    {(char_u *)NULL, (char_u *)0L}
1940 #endif
1941 			    SCTX_INIT},
1942     {"mousetime",   "mouset",	P_NUM|P_VI_DEF,
1943 			    (char_u *)&p_mouset, PV_NONE,
1944 			    {(char_u *)500L, (char_u *)0L} SCTX_INIT},
1945     {"mzschemedll", NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1946 #if defined(DYNAMIC_MZSCHEME)
1947 			    (char_u *)&p_mzschemedll, PV_NONE,
1948 			    {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1949 #else
1950 			    (char_u *)NULL, PV_NONE,
1951 			    {(char_u *)"", (char_u *)0L}
1952 #endif
1953 			    SCTX_INIT},
1954     {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1955 #if defined(DYNAMIC_MZSCHEME)
1956 			    (char_u *)&p_mzschemegcdll, PV_NONE,
1957 			    {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1958 #else
1959 			    (char_u *)NULL, PV_NONE,
1960 			    {(char_u *)"", (char_u *)0L}
1961 #endif
1962 			    SCTX_INIT},
1963     {"mzquantum",  "mzq",   P_NUM,
1964 #ifdef FEAT_MZSCHEME
1965 			    (char_u *)&p_mzq, PV_NONE,
1966 #else
1967 			    (char_u *)NULL, PV_NONE,
1968 #endif
1969 			    {(char_u *)100L, (char_u *)100L} SCTX_INIT},
1970     {"novice",	    NULL,   P_BOOL|P_VI_DEF,
1971 			    (char_u *)NULL, PV_NONE,
1972 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1973     {"nrformats",   "nf",   P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1974 			    (char_u *)&p_nf, PV_NF,
1975 			    {(char_u *)"bin,octal,hex", (char_u *)0L}
1976 			    SCTX_INIT},
1977     {"number",	    "nu",   P_BOOL|P_VI_DEF|P_RWIN,
1978 			    (char_u *)VAR_WIN, PV_NU,
1979 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1980     {"numberwidth", "nuw",  P_NUM|P_RWIN|P_VIM,
1981 #ifdef FEAT_LINEBREAK
1982 			    (char_u *)VAR_WIN, PV_NUW,
1983 #else
1984 			    (char_u *)NULL, PV_NONE,
1985 #endif
1986 			    {(char_u *)8L, (char_u *)4L} SCTX_INIT},
1987     {"omnifunc",    "ofu",  P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
1988 #ifdef FEAT_COMPL_FUNC
1989 			    (char_u *)&p_ofu, PV_OFU,
1990 			    {(char_u *)"", (char_u *)0L}
1991 #else
1992 			    (char_u *)NULL, PV_NONE,
1993 			    {(char_u *)0L, (char_u *)0L}
1994 #endif
1995 			    SCTX_INIT},
1996     {"open",	    NULL,   P_BOOL|P_VI_DEF,
1997 			    (char_u *)NULL, PV_NONE,
1998 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1999     {"opendevice",  "odev", P_BOOL|P_VI_DEF,
2000 #if defined(MSWIN)
2001 			    (char_u *)&p_odev, PV_NONE,
2002 #else
2003 			    (char_u *)NULL, PV_NONE,
2004 #endif
2005 			    {(char_u *)FALSE, (char_u *)FALSE}
2006 			    SCTX_INIT},
2007     {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2008 			    (char_u *)&p_opfunc, PV_NONE,
2009 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2010     {"optimize",    "opt",  P_BOOL|P_VI_DEF,
2011 			    (char_u *)NULL, PV_NONE,
2012 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2013     {"osfiletype",  "oft",  P_STRING|P_ALLOCED|P_VI_DEF,
2014 			    (char_u *)NULL, PV_NONE,
2015 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2016     {"packpath",    "pp",   P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2017 								    |P_SECURE,
2018 			    (char_u *)&p_pp, PV_NONE,
2019 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2020 			    SCTX_INIT},
2021     {"paragraphs",  "para", P_STRING|P_VI_DEF,
2022 			    (char_u *)&p_para, PV_NONE,
2023 			    {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
2024 				(char_u *)0L} SCTX_INIT},
2025     {"paste",	    NULL,   P_BOOL|P_VI_DEF|P_PRI_MKRC,
2026 			    (char_u *)&p_paste, PV_NONE,
2027 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2028     {"pastetoggle", "pt",   P_STRING|P_VI_DEF,
2029 			    (char_u *)&p_pt, PV_NONE,
2030 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2031     {"patchexpr",   "pex",  P_STRING|P_VI_DEF|P_SECURE,
2032 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2033 			    (char_u *)&p_pex, PV_NONE,
2034 			    {(char_u *)"", (char_u *)0L}
2035 #else
2036 			    (char_u *)NULL, PV_NONE,
2037 			    {(char_u *)0L, (char_u *)0L}
2038 #endif
2039 			    SCTX_INIT},
2040     {"patchmode",   "pm",   P_STRING|P_VI_DEF|P_NFNAME,
2041 			    (char_u *)&p_pm, PV_NONE,
2042 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2043     {"path",	    "pa",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2044 			    (char_u *)&p_path, PV_PATH,
2045 			    {
2046 #if defined(AMIGA) || defined(MSWIN)
2047 			    (char_u *)".,,",
2048 #else
2049 			    (char_u *)".,/usr/include,,",
2050 #endif
2051 				(char_u *)0L} SCTX_INIT},
2052     {"perldll",     NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2053 #if defined(DYNAMIC_PERL)
2054 			    (char_u *)&p_perldll, PV_NONE,
2055 			    {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2056 #else
2057 			    (char_u *)NULL, PV_NONE,
2058 			    {(char_u *)0L, (char_u *)0L}
2059 #endif
2060 			    SCTX_INIT},
2061     {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2062 			    (char_u *)&p_pi, PV_PI,
2063 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2064     {"previewheight", "pvh", P_NUM|P_VI_DEF,
2065 #if defined(FEAT_QUICKFIX)
2066 			    (char_u *)&p_pvh, PV_NONE,
2067 #else
2068 			    (char_u *)NULL, PV_NONE,
2069 #endif
2070 			    {(char_u *)12L, (char_u *)0L} SCTX_INIT},
2071     {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2072 #if defined(FEAT_QUICKFIX)
2073 			    (char_u *)VAR_WIN, PV_PVW,
2074 #else
2075 			    (char_u *)NULL, PV_NONE,
2076 #endif
2077 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2078     {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
2079 #ifdef FEAT_PRINTER
2080 			    (char_u *)&p_pdev, PV_NONE,
2081 			    {(char_u *)"", (char_u *)0L}
2082 #else
2083 			    (char_u *)NULL, PV_NONE,
2084 			    {(char_u *)NULL, (char_u *)0L}
2085 #endif
2086 			    SCTX_INIT},
2087     {"printencoding", "penc", P_STRING|P_VI_DEF,
2088 #ifdef FEAT_POSTSCRIPT
2089 			    (char_u *)&p_penc, 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     {"printexpr", "pexpr",  P_STRING|P_VI_DEF|P_SECURE,
2097 #ifdef FEAT_POSTSCRIPT
2098 			    (char_u *)&p_pexpr, 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     {"printfont", "pfn",    P_STRING|P_VI_DEF,
2106 #ifdef FEAT_PRINTER
2107 			    (char_u *)&p_pfn, PV_NONE,
2108 			    {
2109 # ifdef MSWIN
2110 				(char_u *)"Courier_New:h10",
2111 # else
2112 				(char_u *)"courier",
2113 # endif
2114 				(char_u *)0L}
2115 #else
2116 			    (char_u *)NULL, PV_NONE,
2117 			    {(char_u *)NULL, (char_u *)0L}
2118 #endif
2119 			    SCTX_INIT},
2120     {"printheader", "pheader",  P_STRING|P_VI_DEF|P_GETTEXT,
2121 #ifdef FEAT_PRINTER
2122 			    (char_u *)&p_header, PV_NONE,
2123 			    /* untranslated to avoid problems when 'encoding'
2124 			     * is changed */
2125 			    {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
2126 #else
2127 			    (char_u *)NULL, PV_NONE,
2128 			    {(char_u *)NULL, (char_u *)0L}
2129 #endif
2130 			    SCTX_INIT},
2131    {"printmbcharset", "pmbcs",  P_STRING|P_VI_DEF,
2132 #if defined(FEAT_POSTSCRIPT)
2133 			    (char_u *)&p_pmcs, PV_NONE,
2134 			    {(char_u *)"", (char_u *)0L}
2135 #else
2136 			    (char_u *)NULL, PV_NONE,
2137 			    {(char_u *)NULL, (char_u *)0L}
2138 #endif
2139 			    SCTX_INIT},
2140     {"printmbfont", "pmbfn",  P_STRING|P_VI_DEF,
2141 #if defined(FEAT_POSTSCRIPT)
2142 			    (char_u *)&p_pmfn, 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     {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2150 #ifdef FEAT_PRINTER
2151 			    (char_u *)&p_popt, 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     {"prompt",	    NULL,   P_BOOL|P_VI_DEF,
2159 			    (char_u *)&p_prompt, PV_NONE,
2160 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2161     {"pumheight",   "ph",   P_NUM|P_VI_DEF,
2162 #ifdef FEAT_INS_EXPAND
2163 			    (char_u *)&p_ph, PV_NONE,
2164 #else
2165 			    (char_u *)NULL, PV_NONE,
2166 #endif
2167 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2168     {"pumwidth",    "pw",   P_NUM|P_VI_DEF,
2169 #ifdef FEAT_INS_EXPAND
2170 			    (char_u *)&p_pw, PV_NONE,
2171 #else
2172 			    (char_u *)NULL, PV_NONE,
2173 #endif
2174 			    {(char_u *)15L, (char_u *)15L} SCTX_INIT},
2175     {"pythonthreedll",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2176 #if defined(DYNAMIC_PYTHON3)
2177 			    (char_u *)&p_py3dll, PV_NONE,
2178 			    {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2179 #else
2180 			    (char_u *)NULL, PV_NONE,
2181 			    {(char_u *)NULL, (char_u *)0L}
2182 #endif
2183 			    SCTX_INIT},
2184     {"pythonthreehome", NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2185 #if defined(FEAT_PYTHON3)
2186 			    (char_u *)&p_py3home, PV_NONE,
2187 			    {(char_u *)"", (char_u *)0L}
2188 #else
2189 			    (char_u *)NULL, PV_NONE,
2190 			    {(char_u *)NULL, (char_u *)0L}
2191 #endif
2192 			    SCTX_INIT},
2193     {"pythondll",   NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2194 #if defined(DYNAMIC_PYTHON)
2195 			    (char_u *)&p_pydll, PV_NONE,
2196 			    {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2197 #else
2198 			    (char_u *)NULL, PV_NONE,
2199 			    {(char_u *)NULL, (char_u *)0L}
2200 #endif
2201 			    SCTX_INIT},
2202     {"pythonhome",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2203 #if defined(FEAT_PYTHON)
2204 			    (char_u *)&p_pyhome, PV_NONE,
2205 			    {(char_u *)"", (char_u *)0L}
2206 #else
2207 			    (char_u *)NULL, PV_NONE,
2208 			    {(char_u *)NULL, (char_u *)0L}
2209 #endif
2210 			    SCTX_INIT},
2211     {"pyxversion", "pyx",   P_NUM|P_VI_DEF|P_SECURE,
2212 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2213 			    (char_u *)&p_pyx, PV_NONE,
2214 #else
2215 			    (char_u *)NULL, PV_NONE,
2216 #endif
2217 			    {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2218 			    SCTX_INIT},
2219     {"quoteescape", "qe",   P_STRING|P_ALLOCED|P_VI_DEF,
2220 #ifdef FEAT_TEXTOBJ
2221 			    (char_u *)&p_qe, PV_QE,
2222 			    {(char_u *)"\\", (char_u *)0L}
2223 #else
2224 			    (char_u *)NULL, PV_NONE,
2225 			    {(char_u *)NULL, (char_u *)0L}
2226 #endif
2227 			    SCTX_INIT},
2228     {"readonly",    "ro",   P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2229 			    (char_u *)&p_ro, PV_RO,
2230 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2231     {"redraw",	    NULL,   P_BOOL|P_VI_DEF,
2232 			    (char_u *)NULL, PV_NONE,
2233 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2234     {"redrawtime",  "rdt",  P_NUM|P_VI_DEF,
2235 #ifdef FEAT_RELTIME
2236 			    (char_u *)&p_rdt, PV_NONE,
2237 #else
2238 			    (char_u *)NULL, PV_NONE,
2239 #endif
2240 			    {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
2241     {"regexpengine", "re",  P_NUM|P_VI_DEF,
2242 			    (char_u *)&p_re, PV_NONE,
2243 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2244     {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2245 			    (char_u *)VAR_WIN, PV_RNU,
2246 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2247     {"remap",	    NULL,   P_BOOL|P_VI_DEF,
2248 			    (char_u *)&p_remap, PV_NONE,
2249 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2250     {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
2251 #ifdef FEAT_RENDER_OPTIONS
2252 			    (char_u *)&p_rop, PV_NONE,
2253 			    {(char_u *)"", (char_u *)0L}
2254 #else
2255 			    (char_u *)NULL, PV_NONE,
2256 			    {(char_u *)NULL, (char_u *)0L}
2257 #endif
2258 			    SCTX_INIT},
2259     {"report",	    NULL,   P_NUM|P_VI_DEF,
2260 			    (char_u *)&p_report, PV_NONE,
2261 			    {(char_u *)2L, (char_u *)0L} SCTX_INIT},
2262     {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2263 #ifdef MSWIN
2264 			    (char_u *)&p_rs, PV_NONE,
2265 #else
2266 			    (char_u *)NULL, PV_NONE,
2267 #endif
2268 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2269     {"revins",	    "ri",   P_BOOL|P_VI_DEF|P_VIM,
2270 #ifdef FEAT_RIGHTLEFT
2271 			    (char_u *)&p_ri, PV_NONE,
2272 #else
2273 			    (char_u *)NULL, PV_NONE,
2274 #endif
2275 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2276     {"rightleft",   "rl",   P_BOOL|P_VI_DEF|P_RWIN,
2277 #ifdef FEAT_RIGHTLEFT
2278 			    (char_u *)VAR_WIN, PV_RL,
2279 #else
2280 			    (char_u *)NULL, PV_NONE,
2281 #endif
2282 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2283     {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2284 #ifdef FEAT_RIGHTLEFT
2285 			    (char_u *)VAR_WIN, PV_RLC,
2286 			    {(char_u *)"search", (char_u *)NULL}
2287 #else
2288 			    (char_u *)NULL, PV_NONE,
2289 			    {(char_u *)NULL, (char_u *)0L}
2290 #endif
2291 			    SCTX_INIT},
2292     {"rubydll",     NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2293 #if defined(DYNAMIC_RUBY)
2294 			    (char_u *)&p_rubydll, PV_NONE,
2295 			    {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2296 #else
2297 			    (char_u *)NULL, PV_NONE,
2298 			    {(char_u *)NULL, (char_u *)0L}
2299 #endif
2300 			    SCTX_INIT},
2301     {"ruler",	    "ru",   P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2302 #ifdef FEAT_CMDL_INFO
2303 			    (char_u *)&p_ru, PV_NONE,
2304 #else
2305 			    (char_u *)NULL, PV_NONE,
2306 #endif
2307 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2308     {"rulerformat", "ruf",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2309 #ifdef FEAT_STL_OPT
2310 			    (char_u *)&p_ruf, PV_NONE,
2311 #else
2312 			    (char_u *)NULL, PV_NONE,
2313 #endif
2314 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2315     {"runtimepath", "rtp",  P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2316 								    |P_SECURE,
2317 			    (char_u *)&p_rtp, PV_NONE,
2318 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2319 			    SCTX_INIT},
2320     {"scroll",	    "scr",  P_NUM|P_NO_MKRC|P_VI_DEF,
2321 			    (char_u *)VAR_WIN, PV_SCROLL,
2322 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2323     {"scrollbind",  "scb",  P_BOOL|P_VI_DEF,
2324 			    (char_u *)VAR_WIN, PV_SCBIND,
2325 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2326     {"scrolljump",  "sj",   P_NUM|P_VI_DEF|P_VIM,
2327 			    (char_u *)&p_sj, PV_NONE,
2328 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
2329     {"scrolloff",   "so",   P_NUM|P_VI_DEF|P_VIM|P_RALL,
2330 			    (char_u *)&p_so, PV_SO,
2331 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2332     {"scrollopt",   "sbo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2333 			    (char_u *)&p_sbo, PV_NONE,
2334 			    {(char_u *)"ver,jump", (char_u *)0L}
2335 			    SCTX_INIT},
2336     {"sections",    "sect", P_STRING|P_VI_DEF,
2337 			    (char_u *)&p_sections, PV_NONE,
2338 			    {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2339 			    SCTX_INIT},
2340     {"secure",	    NULL,   P_BOOL|P_VI_DEF|P_SECURE,
2341 			    (char_u *)&p_secure, PV_NONE,
2342 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2343     {"selection",   "sel",  P_STRING|P_VI_DEF,
2344 			    (char_u *)&p_sel, PV_NONE,
2345 			    {(char_u *)"inclusive", (char_u *)0L}
2346 			    SCTX_INIT},
2347     {"selectmode",  "slm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2348 			    (char_u *)&p_slm, PV_NONE,
2349 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2350     {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2351 #ifdef FEAT_SESSION
2352 			    (char_u *)&p_ssop, PV_NONE,
2353 	 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
2354 							       (char_u *)0L}
2355 #else
2356 			    (char_u *)NULL, PV_NONE,
2357 			    {(char_u *)0L, (char_u *)0L}
2358 #endif
2359 			    SCTX_INIT},
2360     {"shell",	    "sh",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2361 			    (char_u *)&p_sh, PV_NONE,
2362 			    {
2363 #ifdef VMS
2364 			    (char_u *)"-",
2365 #else
2366 # if defined(MSWIN)
2367 			    (char_u *)"",	/* set in set_init_1() */
2368 # else
2369 			    (char_u *)"sh",
2370 # endif
2371 #endif /* VMS */
2372 				(char_u *)0L} SCTX_INIT},
2373     {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2374 			    (char_u *)&p_shcf, PV_NONE,
2375 			    {
2376 #if defined(MSWIN)
2377 			    (char_u *)"/c",
2378 #else
2379 			    (char_u *)"-c",
2380 #endif
2381 				(char_u *)0L} SCTX_INIT},
2382     {"shellpipe",   "sp",   P_STRING|P_VI_DEF|P_SECURE,
2383 #ifdef FEAT_QUICKFIX
2384 			    (char_u *)&p_sp, PV_NONE,
2385 			    {
2386 #if defined(UNIX)
2387 			    (char_u *)"| tee",
2388 #else
2389 			    (char_u *)">",
2390 #endif
2391 				(char_u *)0L}
2392 #else
2393 			    (char_u *)NULL, PV_NONE,
2394 			    {(char_u *)0L, (char_u *)0L}
2395 #endif
2396 			    SCTX_INIT},
2397     {"shellquote",  "shq",  P_STRING|P_VI_DEF|P_SECURE,
2398 			    (char_u *)&p_shq, PV_NONE,
2399 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2400     {"shellredir",  "srr",  P_STRING|P_VI_DEF|P_SECURE,
2401 			    (char_u *)&p_srr, PV_NONE,
2402 			    {(char_u *)">", (char_u *)0L} SCTX_INIT},
2403     {"shellslash",  "ssl",   P_BOOL|P_VI_DEF,
2404 #ifdef BACKSLASH_IN_FILENAME
2405 			    (char_u *)&p_ssl, PV_NONE,
2406 #else
2407 			    (char_u *)NULL, PV_NONE,
2408 #endif
2409 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2410     {"shelltemp",   "stmp", P_BOOL,
2411 			    (char_u *)&p_stmp, PV_NONE,
2412 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
2413     {"shelltype",   "st",   P_NUM|P_VI_DEF,
2414 #ifdef AMIGA
2415 			    (char_u *)&p_st, PV_NONE,
2416 #else
2417 			    (char_u *)NULL, PV_NONE,
2418 #endif
2419 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2420     {"shellxquote", "sxq",  P_STRING|P_VI_DEF|P_SECURE,
2421 			    (char_u *)&p_sxq, PV_NONE,
2422 			    {
2423 #if defined(UNIX) && defined(USE_SYSTEM)
2424 			    (char_u *)"\"",
2425 #else
2426 			    (char_u *)"",
2427 #endif
2428 				(char_u *)0L} SCTX_INIT},
2429     {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2430 			    (char_u *)&p_sxe, PV_NONE,
2431 			    {
2432 #if defined(MSWIN)
2433 			    (char_u *)"\"&|<>()@^",
2434 #else
2435 			    (char_u *)"",
2436 #endif
2437 				(char_u *)0L} SCTX_INIT},
2438     {"shiftround",  "sr",   P_BOOL|P_VI_DEF|P_VIM,
2439 			    (char_u *)&p_sr, PV_NONE,
2440 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2441     {"shiftwidth",  "sw",   P_NUM|P_VI_DEF,
2442 			    (char_u *)&p_sw, PV_SW,
2443 			    {(char_u *)8L, (char_u *)0L} SCTX_INIT},
2444     {"shortmess",   "shm",  P_STRING|P_VIM|P_FLAGLIST,
2445 			    (char_u *)&p_shm, PV_NONE,
2446 			    {(char_u *)"", (char_u *)"filnxtToO"}
2447 			    SCTX_INIT},
2448     {"shortname",   "sn",   P_BOOL|P_VI_DEF,
2449 			    (char_u *)&p_sn, PV_SN,
2450 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2451     {"showbreak",   "sbr",  P_STRING|P_VI_DEF|P_RALL,
2452 #ifdef FEAT_LINEBREAK
2453 			    (char_u *)&p_sbr, PV_NONE,
2454 #else
2455 			    (char_u *)NULL, PV_NONE,
2456 #endif
2457 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2458     {"showcmd",	    "sc",   P_BOOL|P_VIM,
2459 #ifdef FEAT_CMDL_INFO
2460 			    (char_u *)&p_sc, PV_NONE,
2461 #else
2462 			    (char_u *)NULL, PV_NONE,
2463 #endif
2464 			    {(char_u *)FALSE,
2465 #ifdef UNIX
2466 				(char_u *)FALSE
2467 #else
2468 				(char_u *)TRUE
2469 #endif
2470 				} SCTX_INIT},
2471     {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
2472 			    (char_u *)&p_sft, PV_NONE,
2473 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2474     {"showmatch",   "sm",   P_BOOL|P_VI_DEF,
2475 			    (char_u *)&p_sm, PV_NONE,
2476 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2477     {"showmode",    "smd",  P_BOOL|P_VIM,
2478 			    (char_u *)&p_smd, PV_NONE,
2479 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
2480     {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2481 			    (char_u *)&p_stal, PV_NONE,
2482 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
2483     {"sidescroll",  "ss",   P_NUM|P_VI_DEF,
2484 			    (char_u *)&p_ss, PV_NONE,
2485 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2486     {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2487 			    (char_u *)&p_siso, PV_SISO,
2488 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2489     {"signcolumn",   "scl",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2490 #ifdef FEAT_SIGNS
2491 			    (char_u *)VAR_WIN, PV_SCL,
2492 			    {(char_u *)"auto", (char_u *)0L}
2493 #else
2494 			    (char_u *)NULL, PV_NONE,
2495 			    {(char_u *)NULL, (char_u *)0L}
2496 #endif
2497 			    SCTX_INIT},
2498     {"slowopen",    "slow", P_BOOL|P_VI_DEF,
2499 			    (char_u *)NULL, PV_NONE,
2500 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2501     {"smartcase",   "scs",  P_BOOL|P_VI_DEF|P_VIM,
2502 			    (char_u *)&p_scs, PV_NONE,
2503 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2504     {"smartindent", "si",   P_BOOL|P_VI_DEF|P_VIM,
2505 #ifdef FEAT_SMARTINDENT
2506 			    (char_u *)&p_si, PV_SI,
2507 #else
2508 			    (char_u *)NULL, PV_NONE,
2509 #endif
2510 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2511     {"smarttab",    "sta",  P_BOOL|P_VI_DEF|P_VIM,
2512 			    (char_u *)&p_sta, PV_NONE,
2513 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2514     {"softtabstop", "sts",  P_NUM|P_VI_DEF|P_VIM,
2515 			    (char_u *)&p_sts, PV_STS,
2516 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2517     {"sourceany",   NULL,   P_BOOL|P_VI_DEF,
2518 			    (char_u *)NULL, PV_NONE,
2519 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2520     {"spell",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
2521 #ifdef FEAT_SPELL
2522 			    (char_u *)VAR_WIN, PV_SPELL,
2523 #else
2524 			    (char_u *)NULL, PV_NONE,
2525 #endif
2526 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2527     {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
2528 #ifdef FEAT_SPELL
2529 			    (char_u *)&p_spc, PV_SPC,
2530 			    {(char_u *)"[.?!]\\_[\\])'\"	 ]\\+", (char_u *)0L}
2531 #else
2532 			    (char_u *)NULL, PV_NONE,
2533 			    {(char_u *)0L, (char_u *)0L}
2534 #endif
2535 			    SCTX_INIT},
2536     {"spellfile",   "spf",  P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2537 								  |P_ONECOMMA,
2538 #ifdef FEAT_SPELL
2539 			    (char_u *)&p_spf, PV_SPF,
2540 			    {(char_u *)"", (char_u *)0L}
2541 #else
2542 			    (char_u *)NULL, PV_NONE,
2543 			    {(char_u *)0L, (char_u *)0L}
2544 #endif
2545 			    SCTX_INIT},
2546     {"spelllang",   "spl",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2547 							     |P_RBUF|P_EXPAND,
2548 #ifdef FEAT_SPELL
2549 			    (char_u *)&p_spl, PV_SPL,
2550 			    {(char_u *)"en", (char_u *)0L}
2551 #else
2552 			    (char_u *)NULL, PV_NONE,
2553 			    {(char_u *)0L, (char_u *)0L}
2554 #endif
2555 			    SCTX_INIT},
2556     {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
2557 #ifdef FEAT_SPELL
2558 			    (char_u *)&p_sps, PV_NONE,
2559 			    {(char_u *)"best", (char_u *)0L}
2560 #else
2561 			    (char_u *)NULL, PV_NONE,
2562 			    {(char_u *)0L, (char_u *)0L}
2563 #endif
2564 			    SCTX_INIT},
2565     {"splitbelow",  "sb",   P_BOOL|P_VI_DEF,
2566 			    (char_u *)&p_sb, PV_NONE,
2567 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2568     {"splitright",  "spr",  P_BOOL|P_VI_DEF,
2569 			    (char_u *)&p_spr, PV_NONE,
2570 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2571     {"startofline", "sol",  P_BOOL|P_VI_DEF|P_VIM,
2572 			    (char_u *)&p_sol, PV_NONE,
2573 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2574     {"statusline"  ,"stl",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2575 #ifdef FEAT_STL_OPT
2576 			    (char_u *)&p_stl, PV_STL,
2577 #else
2578 			    (char_u *)NULL, PV_NONE,
2579 #endif
2580 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2581     {"suffixes",    "su",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2582 			    (char_u *)&p_su, PV_NONE,
2583 			    {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2584 				(char_u *)0L} SCTX_INIT},
2585     {"suffixesadd", "sua",  P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
2586 #ifdef FEAT_SEARCHPATH
2587 			    (char_u *)&p_sua, PV_SUA,
2588 			    {(char_u *)"", (char_u *)0L}
2589 #else
2590 			    (char_u *)NULL, PV_NONE,
2591 			    {(char_u *)0L, (char_u *)0L}
2592 #endif
2593 			    SCTX_INIT},
2594     {"swapfile",    "swf",  P_BOOL|P_VI_DEF|P_RSTAT,
2595 			    (char_u *)&p_swf, PV_SWF,
2596 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2597     {"swapsync",    "sws",  P_STRING|P_VI_DEF,
2598 			    (char_u *)&p_sws, PV_NONE,
2599 			    {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
2600     {"switchbuf",   "swb",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2601 			    (char_u *)&p_swb, PV_NONE,
2602 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2603     {"synmaxcol",   "smc",  P_NUM|P_VI_DEF|P_RBUF,
2604 #ifdef FEAT_SYN_HL
2605 			    (char_u *)&p_smc, PV_SMC,
2606 			    {(char_u *)3000L, (char_u *)0L}
2607 #else
2608 			    (char_u *)NULL, PV_NONE,
2609 			    {(char_u *)0L, (char_u *)0L}
2610 #endif
2611 			    SCTX_INIT},
2612     {"syntax",	    "syn",  P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
2613 #ifdef FEAT_SYN_HL
2614 			    (char_u *)&p_syn, PV_SYN,
2615 			    {(char_u *)"", (char_u *)0L}
2616 #else
2617 			    (char_u *)NULL, PV_NONE,
2618 			    {(char_u *)0L, (char_u *)0L}
2619 #endif
2620 			    SCTX_INIT},
2621     {"tabline",	    "tal",  P_STRING|P_VI_DEF|P_RALL,
2622 #ifdef FEAT_STL_OPT
2623 			    (char_u *)&p_tal, PV_NONE,
2624 #else
2625 			    (char_u *)NULL, PV_NONE,
2626 #endif
2627 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2628     {"tabpagemax",  "tpm",  P_NUM|P_VI_DEF,
2629 			    (char_u *)&p_tpm, PV_NONE,
2630 			    {(char_u *)10L, (char_u *)0L} SCTX_INIT},
2631     {"tabstop",	    "ts",   P_NUM|P_VI_DEF|P_RBUF,
2632 			    (char_u *)&p_ts, PV_TS,
2633 			    {(char_u *)8L, (char_u *)0L} SCTX_INIT},
2634     {"tagbsearch",  "tbs",   P_BOOL|P_VI_DEF,
2635 			    (char_u *)&p_tbs, PV_NONE,
2636 #ifdef VMS	/* binary searching doesn't appear to work on VMS */
2637 			    {(char_u *)0L, (char_u *)0L}
2638 #else
2639 			    {(char_u *)TRUE, (char_u *)0L}
2640 #endif
2641 			    SCTX_INIT},
2642     {"tagcase",	    "tc",   P_STRING|P_VIM,
2643 			    (char_u *)&p_tc, PV_TC,
2644 			    {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
2645     {"taglength",   "tl",   P_NUM|P_VI_DEF,
2646 			    (char_u *)&p_tl, PV_NONE,
2647 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2648     {"tagrelative", "tr",   P_BOOL|P_VIM,
2649 			    (char_u *)&p_tr, PV_NONE,
2650 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
2651     {"tags",	    "tag",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
2652 			    (char_u *)&p_tags, PV_TAGS,
2653 			    {
2654 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2655 			    (char_u *)"./tags,./TAGS,tags,TAGS",
2656 #else
2657 			    (char_u *)"./tags,tags",
2658 #endif
2659 				(char_u *)0L} SCTX_INIT},
2660     {"tagstack",    "tgst", P_BOOL|P_VI_DEF,
2661 			    (char_u *)&p_tgst, PV_NONE,
2662 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2663     {"tcldll",      NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2664 #if defined(DYNAMIC_TCL)
2665 			    (char_u *)&p_tcldll, PV_NONE,
2666 			    {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2667 #else
2668 			    (char_u *)NULL, PV_NONE,
2669 			    {(char_u *)0L, (char_u *)0L}
2670 #endif
2671 			    SCTX_INIT},
2672     {"term",	    NULL,   P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2673 			    (char_u *)&T_NAME, PV_NONE,
2674 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2675     {"termbidi", "tbidi",   P_BOOL|P_VI_DEF,
2676 #ifdef FEAT_ARABIC
2677 			    (char_u *)&p_tbidi, PV_NONE,
2678 #else
2679 			    (char_u *)NULL, PV_NONE,
2680 #endif
2681 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2682     {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2683 			    (char_u *)&p_tenc, PV_NONE,
2684 			    {(char_u *)"", (char_u *)0L}
2685 			    SCTX_INIT},
2686     {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2687 #ifdef FEAT_TERMGUICOLORS
2688 			    (char_u *)&p_tgc, PV_NONE,
2689 			    {(char_u *)FALSE, (char_u *)FALSE}
2690 #else
2691 			    (char_u*)NULL, PV_NONE,
2692 			    {(char_u *)FALSE, (char_u *)FALSE}
2693 #endif
2694 			    SCTX_INIT},
2695     {"termwinkey", "twk",   P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2696 #ifdef FEAT_TERMINAL
2697 			    (char_u *)VAR_WIN, PV_TWK,
2698 			    {(char_u *)"", (char_u *)NULL}
2699 #else
2700 			    (char_u *)NULL, PV_NONE,
2701 			    {(char_u *)NULL, (char_u *)0L}
2702 #endif
2703 			    SCTX_INIT},
2704     {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2705 #ifdef FEAT_TERMINAL
2706 			    (char_u *)&p_twsl, PV_TWSL,
2707 			    {(char_u *)10000L, (char_u *)10000L}
2708 #else
2709 			    (char_u *)NULL, PV_NONE,
2710 			    {(char_u *)NULL, (char_u *)0L}
2711 #endif
2712 			    SCTX_INIT},
2713     {"termwinsize", "tws",  P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2714 #ifdef FEAT_TERMINAL
2715 			    (char_u *)VAR_WIN, PV_TWS,
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     {"termwintype", "twt",  P_STRING|P_ALLOCED|P_VI_DEF,
2723 #if defined(MSWIN) && defined(FEAT_TERMINAL)
2724 			    (char_u *)&p_twt, PV_NONE,
2725 			    {(char_u *)"", (char_u *)NULL}
2726 #else
2727 			    (char_u *)NULL, PV_NONE,
2728 			    {(char_u *)NULL, (char_u *)0L}
2729 #endif
2730 			    SCTX_INIT},
2731     {"terse",	    NULL,   P_BOOL|P_VI_DEF,
2732 			    (char_u *)&p_terse, PV_NONE,
2733 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2734     {"textauto",    "ta",   P_BOOL|P_VIM,
2735 			    (char_u *)&p_ta, PV_NONE,
2736 			    {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2737 			    SCTX_INIT},
2738     {"textmode",    "tx",   P_BOOL|P_VI_DEF|P_NO_MKRC,
2739 			    (char_u *)&p_tx, PV_TX,
2740 			    {
2741 #ifdef USE_CRNL
2742 			    (char_u *)TRUE,
2743 #else
2744 			    (char_u *)FALSE,
2745 #endif
2746 				(char_u *)0L} SCTX_INIT},
2747     {"textwidth",   "tw",   P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2748 			    (char_u *)&p_tw, PV_TW,
2749 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2750     {"thesaurus",   "tsr",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
2751 #ifdef FEAT_INS_EXPAND
2752 			    (char_u *)&p_tsr, PV_TSR,
2753 #else
2754 			    (char_u *)NULL, PV_NONE,
2755 #endif
2756 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2757     {"tildeop",	    "top",  P_BOOL|P_VI_DEF|P_VIM,
2758 			    (char_u *)&p_to, PV_NONE,
2759 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2760     {"timeout",	    "to",   P_BOOL|P_VI_DEF,
2761 			    (char_u *)&p_timeout, PV_NONE,
2762 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2763     {"timeoutlen",  "tm",   P_NUM|P_VI_DEF,
2764 			    (char_u *)&p_tm, PV_NONE,
2765 			    {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
2766     {"title",	    NULL,   P_BOOL|P_VI_DEF,
2767 #ifdef FEAT_TITLE
2768 			    (char_u *)&p_title, PV_NONE,
2769 #else
2770 			    (char_u *)NULL, PV_NONE,
2771 #endif
2772 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2773     {"titlelen",    NULL,   P_NUM|P_VI_DEF,
2774 #ifdef FEAT_TITLE
2775 			    (char_u *)&p_titlelen, PV_NONE,
2776 #else
2777 			    (char_u *)NULL, PV_NONE,
2778 #endif
2779 			    {(char_u *)85L, (char_u *)0L} SCTX_INIT},
2780     {"titleold",    NULL,   P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
2781 #ifdef FEAT_TITLE
2782 			    (char_u *)&p_titleold, PV_NONE,
2783 			    {(char_u *)N_("Thanks for flying Vim"),
2784 							       (char_u *)0L}
2785 #else
2786 			    (char_u *)NULL, PV_NONE,
2787 			    {(char_u *)0L, (char_u *)0L}
2788 #endif
2789 			    SCTX_INIT},
2790     {"titlestring", NULL,   P_STRING|P_VI_DEF,
2791 #ifdef FEAT_TITLE
2792 			    (char_u *)&p_titlestring, PV_NONE,
2793 #else
2794 			    (char_u *)NULL, PV_NONE,
2795 #endif
2796 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2797     {"toolbar",     "tb",   P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
2798 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
2799 			    (char_u *)&p_toolbar, PV_NONE,
2800 			    {(char_u *)"icons,tooltips", (char_u *)0L}
2801 #else
2802 			    (char_u *)NULL, PV_NONE,
2803 			    {(char_u *)0L, (char_u *)0L}
2804 #endif
2805 			    SCTX_INIT},
2806     {"toolbariconsize",	"tbis", P_STRING|P_VI_DEF,
2807 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
2808 			    (char_u *)&p_tbis, PV_NONE,
2809 			    {(char_u *)"small", (char_u *)0L}
2810 #else
2811 			    (char_u *)NULL, PV_NONE,
2812 			    {(char_u *)0L, (char_u *)0L}
2813 #endif
2814 			    SCTX_INIT},
2815     {"ttimeout",    NULL,   P_BOOL|P_VI_DEF|P_VIM,
2816 			    (char_u *)&p_ttimeout, PV_NONE,
2817 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2818     {"ttimeoutlen", "ttm",  P_NUM|P_VI_DEF,
2819 			    (char_u *)&p_ttm, PV_NONE,
2820 			    {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
2821     {"ttybuiltin",  "tbi",  P_BOOL|P_VI_DEF,
2822 			    (char_u *)&p_tbi, PV_NONE,
2823 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2824     {"ttyfast",	    "tf",   P_BOOL|P_NO_MKRC|P_VI_DEF,
2825 			    (char_u *)&p_tf, PV_NONE,
2826 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2827     {"ttymouse",    "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2828 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2829 			    (char_u *)&p_ttym, PV_NONE,
2830 #else
2831 			    (char_u *)NULL, PV_NONE,
2832 #endif
2833 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2834     {"ttyscroll",   "tsl",  P_NUM|P_VI_DEF,
2835 			    (char_u *)&p_ttyscroll, PV_NONE,
2836 			    {(char_u *)999L, (char_u *)0L} SCTX_INIT},
2837     {"ttytype",	    "tty",  P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2838 			    (char_u *)&T_NAME, PV_NONE,
2839 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2840     {"undodir",     "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2841 								    |P_VI_DEF,
2842 #ifdef FEAT_PERSISTENT_UNDO
2843 			    (char_u *)&p_udir, PV_NONE,
2844 			    {(char_u *)".", (char_u *)0L}
2845 #else
2846 			    (char_u *)NULL, PV_NONE,
2847 			    {(char_u *)0L, (char_u *)0L}
2848 #endif
2849 			    SCTX_INIT},
2850     {"undofile",    "udf",  P_BOOL|P_VI_DEF|P_VIM,
2851 #ifdef FEAT_PERSISTENT_UNDO
2852 			    (char_u *)&p_udf, PV_UDF,
2853 #else
2854 			    (char_u *)NULL, PV_NONE,
2855 #endif
2856 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2857     {"undolevels",  "ul",   P_NUM|P_VI_DEF,
2858 			    (char_u *)&p_ul, PV_UL,
2859 			    {
2860 #if defined(UNIX) || defined(MSWIN) || defined(VMS)
2861 			    (char_u *)1000L,
2862 #else
2863 			    (char_u *)100L,
2864 #endif
2865 				(char_u *)0L} SCTX_INIT},
2866     {"undoreload",  "ur",   P_NUM|P_VI_DEF,
2867 			    (char_u *)&p_ur, PV_NONE,
2868 			    { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
2869     {"updatecount", "uc",   P_NUM|P_VI_DEF,
2870 			    (char_u *)&p_uc, PV_NONE,
2871 			    {(char_u *)200L, (char_u *)0L} SCTX_INIT},
2872     {"updatetime",  "ut",   P_NUM|P_VI_DEF,
2873 			    (char_u *)&p_ut, PV_NONE,
2874 			    {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
2875     {"varsofttabstop", "vsts",  P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2876 #ifdef FEAT_VARTABS
2877 			    (char_u *)&p_vsts, PV_VSTS,
2878 			    {(char_u *)"", (char_u *)0L}
2879 #else
2880 			    (char_u *)NULL, PV_NONE,
2881 			    {(char_u *)"", (char_u *)NULL}
2882 #endif
2883 			    SCTX_INIT},
2884     {"vartabstop",  "vts",  P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2885 #ifdef FEAT_VARTABS
2886 			    (char_u *)&p_vts, PV_VTS,
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     {"verbose",	    "vbs",  P_NUM|P_VI_DEF,
2894 			    (char_u *)&p_verbose, PV_NONE,
2895 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2896     {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2897 			    (char_u *)&p_vfile, PV_NONE,
2898 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2899     {"viewdir",     "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2900 #ifdef FEAT_SESSION
2901 			    (char_u *)&p_vdir, PV_NONE,
2902 			    {(char_u *)DFLT_VDIR, (char_u *)0L}
2903 #else
2904 			    (char_u *)NULL, PV_NONE,
2905 			    {(char_u *)0L, (char_u *)0L}
2906 #endif
2907 			    SCTX_INIT},
2908     {"viewoptions", "vop",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2909 #ifdef FEAT_SESSION
2910 			    (char_u *)&p_vop, PV_NONE,
2911 			    {(char_u *)"folds,options,cursor,curdir",
2912 								  (char_u *)0L}
2913 #else
2914 			    (char_u *)NULL, PV_NONE,
2915 			    {(char_u *)0L, (char_u *)0L}
2916 #endif
2917 			    SCTX_INIT},
2918     {"viminfo",	    "vi",   P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
2919 #ifdef FEAT_VIMINFO
2920 			    (char_u *)&p_viminfo, PV_NONE,
2921 #if defined(MSWIN)
2922 			    {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
2923 #else
2924 # ifdef AMIGA
2925 			    {(char_u *)"",
2926 				 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2927 # else
2928 			    {(char_u *)"", (char_u *)"'100,<50,s10,h"}
2929 # endif
2930 #endif
2931 #else
2932 			    (char_u *)NULL, PV_NONE,
2933 			    {(char_u *)0L, (char_u *)0L}
2934 #endif
2935 			    SCTX_INIT},
2936     {"viminfofile", "vif",  P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2937 							    |P_SECURE|P_VI_DEF,
2938 #ifdef FEAT_VIMINFO
2939 			    (char_u *)&p_viminfofile, PV_NONE,
2940 			    {(char_u *)"", (char_u *)0L}
2941 #else
2942 			    (char_u *)NULL, PV_NONE,
2943 			    {(char_u *)0L, (char_u *)0L}
2944 #endif
2945 			    SCTX_INIT},
2946     {"virtualedit", "ve",   P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2947 							    |P_VIM|P_CURSWANT,
2948 			    (char_u *)&p_ve, PV_NONE,
2949 			    {(char_u *)"", (char_u *)""}
2950 			    SCTX_INIT},
2951     {"visualbell",  "vb",   P_BOOL|P_VI_DEF,
2952 			    (char_u *)&p_vb, PV_NONE,
2953 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2954     {"w300",	    NULL,   P_NUM|P_VI_DEF,
2955 			    (char_u *)NULL, PV_NONE,
2956 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2957     {"w1200",	    NULL,   P_NUM|P_VI_DEF,
2958 			    (char_u *)NULL, PV_NONE,
2959 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2960     {"w9600",	    NULL,   P_NUM|P_VI_DEF,
2961 			    (char_u *)NULL, PV_NONE,
2962 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2963     {"warn",	    NULL,   P_BOOL|P_VI_DEF,
2964 			    (char_u *)&p_warn, PV_NONE,
2965 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2966     {"weirdinvert", "wiv",  P_BOOL|P_VI_DEF|P_RCLR,
2967 			    (char_u *)&p_wiv, PV_NONE,
2968 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2969     {"whichwrap",   "ww",   P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
2970 			    (char_u *)&p_ww, PV_NONE,
2971 			    {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
2972     {"wildchar",    "wc",   P_NUM|P_VIM,
2973 			    (char_u *)&p_wc, PV_NONE,
2974 			    {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2975 			    SCTX_INIT},
2976     {"wildcharm",   "wcm",  P_NUM|P_VI_DEF,
2977 			    (char_u *)&p_wcm, PV_NONE,
2978 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2979     {"wildignore",  "wig",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2980 #ifdef FEAT_WILDIGN
2981 			    (char_u *)&p_wig, PV_NONE,
2982 #else
2983 			    (char_u *)NULL, PV_NONE,
2984 #endif
2985 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2986     {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2987 			    (char_u *)&p_wic, PV_NONE,
2988 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2989     {"wildmenu",    "wmnu", P_BOOL|P_VI_DEF,
2990 #ifdef FEAT_WILDMENU
2991 			    (char_u *)&p_wmnu, PV_NONE,
2992 #else
2993 			    (char_u *)NULL, PV_NONE,
2994 #endif
2995 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2996     {"wildmode",    "wim",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2997 			    (char_u *)&p_wim, PV_NONE,
2998 			    {(char_u *)"full", (char_u *)0L} SCTX_INIT},
2999     {"wildoptions", "wop",  P_STRING|P_VI_DEF,
3000 #ifdef FEAT_CMDL_COMPL
3001 			    (char_u *)&p_wop, PV_NONE,
3002 			    {(char_u *)"", (char_u *)0L}
3003 #else
3004 			    (char_u *)NULL, PV_NONE,
3005 			    {(char_u *)NULL, (char_u *)0L}
3006 #endif
3007 			    SCTX_INIT},
3008     {"winaltkeys",  "wak",  P_STRING|P_VI_DEF,
3009 #ifdef FEAT_WAK
3010 			    (char_u *)&p_wak, PV_NONE,
3011 			    {(char_u *)"menu", (char_u *)0L}
3012 #else
3013 			    (char_u *)NULL, PV_NONE,
3014 			    {(char_u *)NULL, (char_u *)0L}
3015 #endif
3016 			    SCTX_INIT},
3017     {"window",	    "wi",   P_NUM|P_VI_DEF,
3018 			    (char_u *)&p_window, PV_NONE,
3019 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
3020     {"winheight",   "wh",   P_NUM|P_VI_DEF,
3021 			    (char_u *)&p_wh, PV_NONE,
3022 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
3023     {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
3024 			    (char_u *)VAR_WIN, PV_WFH,
3025 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
3026     {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
3027 			    (char_u *)VAR_WIN, PV_WFW,
3028 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
3029     {"winminheight", "wmh", P_NUM|P_VI_DEF,
3030 			    (char_u *)&p_wmh, PV_NONE,
3031 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
3032     {"winminwidth", "wmw", P_NUM|P_VI_DEF,
3033 			    (char_u *)&p_wmw, PV_NONE,
3034 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
3035     {"winptydll", NULL,	    P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
3036 #if defined(MSWIN) && defined(FEAT_TERMINAL)
3037 			    (char_u *)&p_winptydll, PV_NONE, {
3038 # ifdef _WIN64
3039 			    (char_u *)"winpty64.dll",
3040 # else
3041 			    (char_u *)"winpty32.dll",
3042 # endif
3043 				(char_u *)0L}
3044 #else
3045 			    (char_u *)NULL, PV_NONE,
3046 			    {(char_u *)0L, (char_u *)0L}
3047 #endif
3048 			    SCTX_INIT},
3049     {"winwidth",   "wiw",   P_NUM|P_VI_DEF,
3050 			    (char_u *)&p_wiw, PV_NONE,
3051 			    {(char_u *)20L, (char_u *)0L} SCTX_INIT},
3052     {"wrap",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
3053 			    (char_u *)VAR_WIN, PV_WRAP,
3054 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
3055     {"wrapmargin",  "wm",   P_NUM|P_VI_DEF,
3056 			    (char_u *)&p_wm, PV_WM,
3057 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
3058     {"wrapscan",    "ws",   P_BOOL|P_VI_DEF,
3059 			    (char_u *)&p_ws, PV_NONE,
3060 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
3061     {"write",	    NULL,   P_BOOL|P_VI_DEF,
3062 			    (char_u *)&p_write, PV_NONE,
3063 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
3064     {"writeany",    "wa",   P_BOOL|P_VI_DEF,
3065 			    (char_u *)&p_wa, PV_NONE,
3066 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
3067     {"writebackup", "wb",   P_BOOL|P_VI_DEF|P_VIM,
3068 			    (char_u *)&p_wb, PV_NONE,
3069 			    {
3070 #ifdef FEAT_WRITEBACKUP
3071 			    (char_u *)TRUE,
3072 #else
3073 			    (char_u *)FALSE,
3074 #endif
3075 				(char_u *)0L} SCTX_INIT},
3076     {"writedelay",  "wd",   P_NUM|P_VI_DEF,
3077 			    (char_u *)&p_wd, PV_NONE,
3078 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
3079 
3080 /* terminal output codes */
3081 #define p_term(sss, vvv)   {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
3082 			    (char_u *)&vvv, PV_NONE, \
3083 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
3084 
3085     p_term("t_AB", T_CAB)
3086     p_term("t_AF", T_CAF)
3087     p_term("t_AL", T_CAL)
3088     p_term("t_al", T_AL)
3089     p_term("t_bc", T_BC)
3090     p_term("t_BE", T_BE)
3091     p_term("t_BD", T_BD)
3092     p_term("t_cd", T_CD)
3093     p_term("t_ce", T_CE)
3094     p_term("t_cl", T_CL)
3095     p_term("t_cm", T_CM)
3096     p_term("t_Ce", T_UCE)
3097     p_term("t_Co", T_CCO)
3098     p_term("t_CS", T_CCS)
3099     p_term("t_Cs", T_UCS)
3100     p_term("t_cs", T_CS)
3101     p_term("t_CV", T_CSV)
3102     p_term("t_da", T_DA)
3103     p_term("t_db", T_DB)
3104     p_term("t_DL", T_CDL)
3105     p_term("t_dl", T_DL)
3106     p_term("t_EC", T_CEC)
3107     p_term("t_EI", T_CEI)
3108     p_term("t_fs", T_FS)
3109     p_term("t_GP", T_CGP)
3110     p_term("t_IE", T_CIE)
3111     p_term("t_IS", T_CIS)
3112     p_term("t_ke", T_KE)
3113     p_term("t_ks", T_KS)
3114     p_term("t_le", T_LE)
3115     p_term("t_mb", T_MB)
3116     p_term("t_md", T_MD)
3117     p_term("t_me", T_ME)
3118     p_term("t_mr", T_MR)
3119     p_term("t_ms", T_MS)
3120     p_term("t_nd", T_ND)
3121     p_term("t_op", T_OP)
3122     p_term("t_RF", T_RFG)
3123     p_term("t_RB", T_RBG)
3124     p_term("t_RC", T_CRC)
3125     p_term("t_RI", T_CRI)
3126     p_term("t_Ri", T_SRI)
3127     p_term("t_RS", T_CRS)
3128     p_term("t_RT", T_CRT)
3129     p_term("t_RV", T_CRV)
3130     p_term("t_Sb", T_CSB)
3131     p_term("t_SC", T_CSC)
3132     p_term("t_se", T_SE)
3133     p_term("t_Sf", T_CSF)
3134     p_term("t_SH", T_CSH)
3135     p_term("t_SI", T_CSI)
3136     p_term("t_Si", T_SSI)
3137     p_term("t_so", T_SO)
3138     p_term("t_SR", T_CSR)
3139     p_term("t_sr", T_SR)
3140     p_term("t_ST", T_CST)
3141     p_term("t_Te", T_STE)
3142     p_term("t_te", T_TE)
3143     p_term("t_ti", T_TI)
3144     p_term("t_Ts", T_STS)
3145     p_term("t_ts", T_TS)
3146     p_term("t_u7", T_U7)
3147     p_term("t_ue", T_UE)
3148     p_term("t_us", T_US)
3149     p_term("t_ut", T_UT)
3150     p_term("t_vb", T_VB)
3151     p_term("t_ve", T_VE)
3152     p_term("t_vi", T_VI)
3153     p_term("t_VS", T_CVS)
3154     p_term("t_vs", T_VS)
3155     p_term("t_WP", T_CWP)
3156     p_term("t_WS", T_CWS)
3157     p_term("t_xn", T_XN)
3158     p_term("t_xs", T_XS)
3159     p_term("t_ZH", T_CZH)
3160     p_term("t_ZR", T_CZR)
3161     p_term("t_8f", T_8F)
3162     p_term("t_8b", T_8B)
3163 
3164 /* terminal key codes are not in here */
3165 
3166     /* end marker */
3167     {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
3168 };
3169 
3170 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3171 
3172 static char *(p_ambw_values[]) = {"single", "double", NULL};
3173 static char *(p_bg_values[]) = {"light", "dark", NULL};
3174 static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
3175 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
3176 #ifdef FEAT_CRYPT
3177 static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
3178 #endif
3179 #ifdef FEAT_CMDL_COMPL
3180 static char *(p_wop_values[]) = {"tagfile", NULL};
3181 #endif
3182 #ifdef FEAT_WAK
3183 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3184 #endif
3185 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
3186 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3187 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
3188 static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
3189 #ifdef FEAT_BROWSE
3190 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3191 #endif
3192 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3193 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
3194 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3195 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
3196 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3197 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3198 #ifdef FEAT_FOLDING
3199 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
3200 # ifdef FEAT_DIFF
3201 				"diff",
3202 # endif
3203 				NULL};
3204 static char *(p_fcl_values[]) = {"all", NULL};
3205 #endif
3206 #ifdef FEAT_INS_EXPAND
3207 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
3208 #endif
3209 #ifdef FEAT_SIGNS
3210 static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3211 #endif
3212 #if defined(MSWIN) && defined(FEAT_TERMINAL)
3213 static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
3214 #endif
3215 
3216 static void set_options_default(int opt_flags);
3217 static void set_string_default_esc(char *name, char_u *val, int escape);
3218 static char_u *term_bg_default(void);
3219 static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
3220 static char_u *option_expand(int opt_idx, char_u *val);
3221 static void didset_options(void);
3222 static void didset_options2(void);
3223 static void check_string_option(char_u **pp);
3224 #if defined(FEAT_EVAL) || defined(PROTO)
3225 static long_u *insecure_flag(int opt_idx, int opt_flags);
3226 #else
3227 # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3228 #endif
3229 static void set_string_option_global(int opt_idx, char_u **varp);
3230 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);
3231 static char *set_chars_option(char_u **varp);
3232 #ifdef FEAT_CLIPBOARD
3233 static char *check_clipboard_option(void);
3234 #endif
3235 #ifdef FEAT_SPELL
3236 static char *did_set_spell_option(int is_spellfile);
3237 static char *compile_cap_prog(synblock_T *synblock);
3238 #endif
3239 #ifdef FEAT_EVAL
3240 static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
3241 #endif
3242 static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3243 static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags);
3244 static void check_redraw(long_u flags);
3245 static int findoption(char_u *);
3246 static int find_key_option(char_u *arg_arg, int has_lt);
3247 static void showoptions(int all, int opt_flags);
3248 static int optval_default(struct vimoption *, char_u *varp);
3249 static void showoneopt(struct vimoption *, int opt_flags);
3250 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
3251 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3252 static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3253 static int  istermoption(struct vimoption *);
3254 static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3255 static char_u *get_varp(struct vimoption *);
3256 static void option_value2string(struct vimoption *, int opt_flags);
3257 static void check_winopt(winopt_T *wop);
3258 static int wc_use_keyname(char_u *varp, long *wcp);
3259 #ifdef FEAT_LANGMAP
3260 static void langmap_init(void);
3261 static void langmap_set(void);
3262 #endif
3263 static void paste_option_changed(void);
3264 static void compatible_set(void);
3265 #ifdef FEAT_LINEBREAK
3266 static void fill_breakat_flags(void);
3267 #endif
3268 static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3269 static int check_opt_strings(char_u *val, char **values, int);
3270 static int check_opt_wim(void);
3271 #ifdef FEAT_LINEBREAK
3272 static int briopt_check(win_T *wp);
3273 #endif
3274 
3275 /*
3276  * Initialize the options, first part.
3277  *
3278  * Called only once from main(), just after creating the first buffer.
3279  * If "clean_arg" is TRUE Vim was started with --clean.
3280  */
3281     void
3282 set_init_1(int clean_arg)
3283 {
3284     char_u	*p;
3285     int		opt_idx;
3286     long_u	n;
3287 
3288 #ifdef FEAT_LANGMAP
3289     langmap_init();
3290 #endif
3291 
3292     /* Be Vi compatible by default */
3293     p_cp = TRUE;
3294 
3295     /* Use POSIX compatibility when $VIM_POSIX is set. */
3296     if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
3297     {
3298 	set_string_default("cpo", (char_u *)CPO_ALL);
3299 	set_string_default("shm", (char_u *)"A");
3300     }
3301 
3302     /*
3303      * Find default value for 'shell' option.
3304      * Don't use it if it is empty.
3305      */
3306     if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
3307 #if defined(MSWIN)
3308 	    || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
3309 # ifdef MSWIN
3310 	    || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
3311 # endif
3312 #endif
3313 	    )
3314 	set_string_default_esc("sh", p, TRUE);
3315 
3316 #ifdef FEAT_WILDIGN
3317     /*
3318      * Set the default for 'backupskip' to include environment variables for
3319      * temp files.
3320      */
3321     {
3322 # ifdef UNIX
3323 	static char	*(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3324 # else
3325 	static char	*(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3326 # endif
3327 	int		len;
3328 	garray_T	ga;
3329 	int		mustfree;
3330 
3331 	ga_init2(&ga, 1, 100);
3332 	for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3333 	{
3334 	    mustfree = FALSE;
3335 # ifdef UNIX
3336 	    if (*names[n] == NUL)
3337 #  ifdef MACOS_X
3338 		p = (char_u *)"/private/tmp";
3339 #  else
3340 		p = (char_u *)"/tmp";
3341 #  endif
3342 	    else
3343 # endif
3344 		p = vim_getenv((char_u *)names[n], &mustfree);
3345 	    if (p != NULL && *p != NUL)
3346 	    {
3347 		/* First time count the NUL, otherwise count the ','. */
3348 		len = (int)STRLEN(p) + 3;
3349 		if (ga_grow(&ga, len) == OK)
3350 		{
3351 		    if (ga.ga_len > 0)
3352 			STRCAT(ga.ga_data, ",");
3353 		    STRCAT(ga.ga_data, p);
3354 		    add_pathsep(ga.ga_data);
3355 		    STRCAT(ga.ga_data, "*");
3356 		    ga.ga_len += len;
3357 		}
3358 	    }
3359 	    if (mustfree)
3360 		vim_free(p);
3361 	}
3362 	if (ga.ga_data != NULL)
3363 	{
3364 	    set_string_default("bsk", ga.ga_data);
3365 	    vim_free(ga.ga_data);
3366 	}
3367     }
3368 #endif
3369 
3370     /*
3371      * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3372      */
3373     opt_idx = findoption((char_u *)"maxmemtot");
3374     if (opt_idx >= 0)
3375     {
3376 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3377 	if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3378 #endif
3379 	{
3380 #ifdef HAVE_AVAIL_MEM
3381 	    /* Use amount of memory available at this moment. */
3382 	    n = (mch_avail_mem(FALSE) >> 1);
3383 #else
3384 # ifdef HAVE_TOTAL_MEM
3385 	    /* Use amount of memory available to Vim. */
3386 	    n = (mch_total_mem(FALSE) >> 1);
3387 # else
3388 	    n = (0x7fffffff >> 11);
3389 # endif
3390 #endif
3391 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3392 	    opt_idx = findoption((char_u *)"maxmem");
3393 	    if (opt_idx >= 0)
3394 	    {
3395 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3396 		if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3397 		  || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3398 #endif
3399 		    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3400 	    }
3401 	}
3402     }
3403 
3404 #ifdef FEAT_SEARCHPATH
3405     {
3406 	char_u	*cdpath;
3407 	char_u	*buf;
3408 	int	i;
3409 	int	j;
3410 	int	mustfree = FALSE;
3411 
3412 	/* Initialize the 'cdpath' option's default value. */
3413 	cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
3414 	if (cdpath != NULL)
3415 	{
3416 	    buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3417 	    if (buf != NULL)
3418 	    {
3419 		buf[0] = ',';	    /* start with ",", current dir first */
3420 		j = 1;
3421 		for (i = 0; cdpath[i] != NUL; ++i)
3422 		{
3423 		    if (vim_ispathlistsep(cdpath[i]))
3424 			buf[j++] = ',';
3425 		    else
3426 		    {
3427 			if (cdpath[i] == ' ' || cdpath[i] == ',')
3428 			    buf[j++] = '\\';
3429 			buf[j++] = cdpath[i];
3430 		    }
3431 		}
3432 		buf[j] = NUL;
3433 		opt_idx = findoption((char_u *)"cdpath");
3434 		if (opt_idx >= 0)
3435 		{
3436 		    options[opt_idx].def_val[VI_DEFAULT] = buf;
3437 		    options[opt_idx].flags |= P_DEF_ALLOCED;
3438 		}
3439 		else
3440 		    vim_free(buf); /* cannot happen */
3441 	    }
3442 	    if (mustfree)
3443 		vim_free(cdpath);
3444 	}
3445     }
3446 #endif
3447 
3448 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3449     /* Set print encoding on platforms that don't default to latin1 */
3450     set_string_default("penc",
3451 # if defined(MSWIN)
3452 		       (char_u *)"cp1252"
3453 # else
3454 #  ifdef VMS
3455 		       (char_u *)"dec-mcs"
3456 #  else
3457 #   ifdef EBCDIC
3458 		       (char_u *)"ebcdic-uk"
3459 #   else
3460 #    ifdef MAC
3461 		       (char_u *)"mac-roman"
3462 #    else /* HPUX */
3463 		       (char_u *)"hp-roman8"
3464 #    endif
3465 #   endif
3466 #  endif
3467 # endif
3468 		       );
3469 #endif
3470 
3471 #ifdef FEAT_POSTSCRIPT
3472     /* 'printexpr' must be allocated to be able to evaluate it. */
3473     set_string_default("pexpr",
3474 # if defined(MSWIN)
3475 	    (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
3476 # else
3477 #  ifdef VMS
3478 	    (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3479 
3480 #  else
3481 	    (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3482 #  endif
3483 # endif
3484 	    );
3485 #endif
3486 
3487     /*
3488      * Set all the options (except the terminal options) to their default
3489      * value.  Also set the global value for local options.
3490      */
3491     set_options_default(0);
3492 
3493 #ifdef CLEAN_RUNTIMEPATH
3494     if (clean_arg)
3495     {
3496 	opt_idx = findoption((char_u *)"runtimepath");
3497 	if (opt_idx >= 0)
3498 	{
3499 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3500 	    p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3501 	}
3502 	opt_idx = findoption((char_u *)"packpath");
3503 	if (opt_idx >= 0)
3504 	{
3505 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3506 	    p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3507 	}
3508     }
3509 #endif
3510 
3511 #ifdef FEAT_GUI
3512     if (found_reverse_arg)
3513 	set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3514 #endif
3515 
3516     curbuf->b_p_initialized = TRUE;
3517     curbuf->b_p_ar = -1;	/* no local 'autoread' value */
3518     curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
3519     check_buf_options(curbuf);
3520     check_win_options(curwin);
3521     check_options();
3522 
3523     /* Must be before option_expand(), because that one needs vim_isIDc() */
3524     didset_options();
3525 
3526 #ifdef FEAT_SPELL
3527     /* Use the current chartab for the generic chartab. This is not in
3528      * didset_options() because it only depends on 'encoding'. */
3529     init_spell_chartab();
3530 #endif
3531 
3532     /*
3533      * Expand environment variables and things like "~" for the defaults.
3534      * If option_expand() returns non-NULL the variable is expanded.  This can
3535      * only happen for non-indirect options.
3536      * Also set the default to the expanded value, so ":set" does not list
3537      * them.
3538      * Don't set the P_ALLOCED flag, because we don't want to free the
3539      * default.
3540      */
3541     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3542     {
3543 	if ((options[opt_idx].flags & P_GETTEXT)
3544 					      && options[opt_idx].var != NULL)
3545 	    p = (char_u *)_(*(char **)options[opt_idx].var);
3546 	else
3547 	    p = option_expand(opt_idx, NULL);
3548 	if (p != NULL && (p = vim_strsave(p)) != NULL)
3549 	{
3550 	    *(char_u **)options[opt_idx].var = p;
3551 	    /* VIMEXP
3552 	     * Defaults for all expanded options are currently the same for Vi
3553 	     * and Vim.  When this changes, add some code here!  Also need to
3554 	     * split P_DEF_ALLOCED in two.
3555 	     */
3556 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
3557 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3558 	    options[opt_idx].def_val[VI_DEFAULT] = p;
3559 	    options[opt_idx].flags |= P_DEF_ALLOCED;
3560 	}
3561     }
3562 
3563     save_file_ff(curbuf);	/* Buffer is unchanged */
3564 
3565 #if defined(FEAT_ARABIC)
3566     /* Detect use of mlterm.
3567      * Mlterm is a terminal emulator akin to xterm that has some special
3568      * abilities (bidi namely).
3569      * NOTE: mlterm's author is being asked to 'set' a variable
3570      *       instead of an environment variable due to inheritance.
3571      */
3572     if (mch_getenv((char_u *)"MLTERM") != NULL)
3573 	set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3574 #endif
3575 
3576     didset_options2();
3577 
3578 # if defined(MSWIN) && defined(FEAT_GETTEXT)
3579     /*
3580      * If $LANG isn't set, try to get a good value for it.  This makes the
3581      * right language be used automatically.  Don't do this for English.
3582      */
3583     if (mch_getenv((char_u *)"LANG") == NULL)
3584     {
3585 	char	buf[20];
3586 
3587 	/* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3588 	 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3589 	 * only the first two. */
3590 	n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3591 							     (LPTSTR)buf, 20);
3592 	if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3593 	{
3594 	    /* There are a few exceptions (probably more) */
3595 	    if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3596 		STRCPY(buf, "zh_TW");
3597 	    else if (STRNICMP(buf, "chs", 3) == 0
3598 					      || STRNICMP(buf, "zhc", 3) == 0)
3599 		STRCPY(buf, "zh_CN");
3600 	    else if (STRNICMP(buf, "jp", 2) == 0)
3601 		STRCPY(buf, "ja");
3602 	    else
3603 		buf[2] = NUL;		/* truncate to two-letter code */
3604 	    vim_setenv((char_u *)"LANG", (char_u *)buf);
3605 	}
3606     }
3607 # else
3608 #  ifdef MACOS_CONVERT
3609     /* Moved to os_mac_conv.c to avoid dependency problems. */
3610     mac_lang_init();
3611 #  endif
3612 # endif
3613 
3614     /* enc_locale() will try to find the encoding of the current locale. */
3615     p = enc_locale();
3616     if (p != NULL)
3617     {
3618 	char_u *save_enc;
3619 
3620 	/* Try setting 'encoding' and check if the value is valid.
3621 	 * If not, go back to the default "latin1". */
3622 	save_enc = p_enc;
3623 	p_enc = p;
3624 	if (STRCMP(p_enc, "gb18030") == 0)
3625 	{
3626 	    /* We don't support "gb18030", but "cp936" is a good substitute
3627 	     * for practical purposes, thus use that.  It's not an alias to
3628 	     * still support conversion between gb18030 and utf-8. */
3629 	    p_enc = vim_strsave((char_u *)"cp936");
3630 	    vim_free(p);
3631 	}
3632 	if (mb_init() == NULL)
3633 	{
3634 	    opt_idx = findoption((char_u *)"encoding");
3635 	    if (opt_idx >= 0)
3636 	    {
3637 		options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3638 		options[opt_idx].flags |= P_DEF_ALLOCED;
3639 	    }
3640 
3641 #if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
3642 	    if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
3643 	    {
3644 		/* Adjust the default for 'isprint' and 'iskeyword' to match
3645 		 * latin1.  Also set the defaults for when 'nocompatible' is
3646 		 * set. */
3647 		set_string_option_direct((char_u *)"isp", -1,
3648 					      ISP_LATIN1, OPT_FREE, SID_NONE);
3649 		set_string_option_direct((char_u *)"isk", -1,
3650 					      ISK_LATIN1, OPT_FREE, SID_NONE);
3651 		opt_idx = findoption((char_u *)"isp");
3652 		if (opt_idx >= 0)
3653 		    options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
3654 		opt_idx = findoption((char_u *)"isk");
3655 		if (opt_idx >= 0)
3656 		    options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
3657 		(void)init_chartab();
3658 	    }
3659 #endif
3660 
3661 #if defined(MSWIN) && !defined(FEAT_GUI)
3662 	    /* Win32 console: When GetACP() returns a different value from
3663 	     * GetConsoleCP() set 'termencoding'. */
3664 	    if (GetACP() != GetConsoleCP())
3665 	    {
3666 		char	buf[50];
3667 
3668 		/* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3669 		 * Use an alternative value. */
3670 		if (GetConsoleCP() == 0)
3671 		    sprintf(buf, "cp%ld", (long)GetACP());
3672 		else
3673 		    sprintf(buf, "cp%ld", (long)GetConsoleCP());
3674 		p_tenc = vim_strsave((char_u *)buf);
3675 		if (p_tenc != NULL)
3676 		{
3677 		    opt_idx = findoption((char_u *)"termencoding");
3678 		    if (opt_idx >= 0)
3679 		    {
3680 			options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3681 			options[opt_idx].flags |= P_DEF_ALLOCED;
3682 		    }
3683 		    convert_setup(&input_conv, p_tenc, p_enc);
3684 		    convert_setup(&output_conv, p_enc, p_tenc);
3685 		}
3686 		else
3687 		    p_tenc = empty_option;
3688 	    }
3689 #endif
3690 #if defined(MSWIN)
3691 	    /* $HOME may have characters in active code page. */
3692 	    init_homedir();
3693 #endif
3694 	}
3695 	else
3696 	{
3697 	    vim_free(p_enc);
3698 	    p_enc = save_enc;
3699 	}
3700     }
3701 
3702 #ifdef FEAT_MULTI_LANG
3703     /* Set the default for 'helplang'. */
3704     set_helplang_default(get_mess_lang());
3705 #endif
3706 }
3707 
3708 /*
3709  * Set an option to its default value.
3710  * This does not take care of side effects!
3711  */
3712     static void
3713 set_option_default(
3714     int		opt_idx,
3715     int		opt_flags,	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3716     int		compatible)	/* use Vi default value */
3717 {
3718     char_u	*varp;		/* pointer to variable for current option */
3719     int		dvi;		/* index in def_val[] */
3720     long_u	flags;
3721     long_u	*flagsp;
3722     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3723 
3724     varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3725     flags = options[opt_idx].flags;
3726     if (varp != NULL)	    /* skip hidden option, nothing to do for it */
3727     {
3728 	dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3729 	if (flags & P_STRING)
3730 	{
3731 	    /* Use set_string_option_direct() for local options to handle
3732 	     * freeing and allocating the value. */
3733 	    if (options[opt_idx].indir != PV_NONE)
3734 		set_string_option_direct(NULL, opt_idx,
3735 				 options[opt_idx].def_val[dvi], opt_flags, 0);
3736 	    else
3737 	    {
3738 		if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3739 		    free_string_option(*(char_u **)(varp));
3740 		*(char_u **)varp = options[opt_idx].def_val[dvi];
3741 		options[opt_idx].flags &= ~P_ALLOCED;
3742 	    }
3743 	}
3744 	else if (flags & P_NUM)
3745 	{
3746 	    if (options[opt_idx].indir == PV_SCROLL)
3747 		win_comp_scroll(curwin);
3748 	    else
3749 	    {
3750 		long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3751 
3752 		if ((long *)varp == &curwin->w_p_so
3753 			|| (long *)varp == &curwin->w_p_siso)
3754 		    // 'scrolloff' and 'sidescrolloff' local values have a
3755 		    // different default value than the global default.
3756 		    *(long *)varp = -1;
3757 		else
3758 		    *(long *)varp = def_val;
3759 		/* May also set global value for local option. */
3760 		if (both)
3761 		    *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3762 								def_val;
3763 	    }
3764 	}
3765 	else	/* P_BOOL */
3766 	{
3767 	    /* the cast to long is required for Manx C, long_i is needed for
3768 	     * MSVC */
3769 	    *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
3770 #ifdef UNIX
3771 	    /* 'modeline' defaults to off for root */
3772 	    if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3773 		*(int *)varp = FALSE;
3774 #endif
3775 	    /* May also set global value for local option. */
3776 	    if (both)
3777 		*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3778 								*(int *)varp;
3779 	}
3780 
3781 	/* The default value is not insecure. */
3782 	flagsp = insecure_flag(opt_idx, opt_flags);
3783 	*flagsp = *flagsp & ~P_INSECURE;
3784     }
3785 
3786 #ifdef FEAT_EVAL
3787     set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
3788 #endif
3789 }
3790 
3791 /*
3792  * Set all options (except terminal options) to their default value.
3793  * When "opt_flags" is non-zero skip 'encoding'.
3794  */
3795     static void
3796 set_options_default(
3797     int		opt_flags)	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3798 {
3799     int		i;
3800     win_T	*wp;
3801     tabpage_T	*tp;
3802 
3803     for (i = 0; !istermoption(&options[i]); i++)
3804 	if (!(options[i].flags & P_NODEFAULT)
3805 		&& (opt_flags == 0
3806 		    || (options[i].var != (char_u *)&p_enc
3807 # if defined(FEAT_CRYPT)
3808 			&& options[i].var != (char_u *)&p_cm
3809 			&& options[i].var != (char_u *)&p_key
3810 # endif
3811 			)))
3812 	    set_option_default(i, opt_flags, p_cp);
3813 
3814     /* The 'scroll' option must be computed for all windows. */
3815     FOR_ALL_TAB_WINDOWS(tp, wp)
3816 	win_comp_scroll(wp);
3817 #ifdef FEAT_CINDENT
3818     parse_cino(curbuf);
3819 #endif
3820 }
3821 
3822 /*
3823  * Set the Vi-default value of a string option.
3824  * Used for 'sh', 'backupskip' and 'term'.
3825  * When "escape" is TRUE escape spaces with a backslash.
3826  */
3827     static void
3828 set_string_default_esc(char *name, char_u *val, int escape)
3829 {
3830     char_u	*p;
3831     int		opt_idx;
3832 
3833     if (escape && vim_strchr(val, ' ') != NULL)
3834 	p = vim_strsave_escaped(val, (char_u *)" ");
3835     else
3836 	p = vim_strsave(val);
3837     if (p != NULL)		/* we don't want a NULL */
3838     {
3839 	opt_idx = findoption((char_u *)name);
3840 	if (opt_idx >= 0)
3841 	{
3842 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
3843 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3844 	    options[opt_idx].def_val[VI_DEFAULT] = p;
3845 	    options[opt_idx].flags |= P_DEF_ALLOCED;
3846 	}
3847     }
3848 }
3849 
3850     void
3851 set_string_default(char *name, char_u *val)
3852 {
3853     set_string_default_esc(name, val, FALSE);
3854 }
3855 
3856 /*
3857  * Set the Vi-default value of a number option.
3858  * Used for 'lines' and 'columns'.
3859  */
3860     void
3861 set_number_default(char *name, long val)
3862 {
3863     int		opt_idx;
3864 
3865     opt_idx = findoption((char_u *)name);
3866     if (opt_idx >= 0)
3867 	options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3868 }
3869 
3870 #if defined(EXITFREE) || defined(PROTO)
3871 /*
3872  * Free all options.
3873  */
3874     void
3875 free_all_options(void)
3876 {
3877     int		i;
3878 
3879     for (i = 0; !istermoption(&options[i]); i++)
3880     {
3881 	if (options[i].indir == PV_NONE)
3882 	{
3883 	    /* global option: free value and default value. */
3884 	    if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
3885 		free_string_option(*(char_u **)options[i].var);
3886 	    if (options[i].flags & P_DEF_ALLOCED)
3887 		free_string_option(options[i].def_val[VI_DEFAULT]);
3888 	}
3889 	else if (options[i].var != VAR_WIN
3890 		&& (options[i].flags & P_STRING))
3891 	    /* buffer-local option: free global value */
3892 	    free_string_option(*(char_u **)options[i].var);
3893     }
3894 }
3895 #endif
3896 
3897 
3898 /*
3899  * Initialize the options, part two: After getting Rows and Columns and
3900  * setting 'term'.
3901  */
3902     void
3903 set_init_2(void)
3904 {
3905     int		idx;
3906 
3907     /*
3908      * 'scroll' defaults to half the window height. The stored default is zero,
3909      * which results in the actual value computed from the window height.
3910      */
3911     idx = findoption((char_u *)"scroll");
3912     if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3913 	set_option_default(idx, OPT_LOCAL, p_cp);
3914     comp_col();
3915 
3916     /*
3917      * 'window' is only for backwards compatibility with Vi.
3918      * Default is Rows - 1.
3919      */
3920     if (!option_was_set((char_u *)"window"))
3921 	p_window = Rows - 1;
3922     set_number_default("window", Rows - 1);
3923 
3924     /* For DOS console the default is always black. */
3925 #if !((defined(MSWIN)) && !defined(FEAT_GUI))
3926     /*
3927      * If 'background' wasn't set by the user, try guessing the value,
3928      * depending on the terminal name.  Only need to check for terminals
3929      * with a dark background, that can handle color.
3930      */
3931     idx = findoption((char_u *)"bg");
3932     if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3933 						 && *term_bg_default() == 'd')
3934     {
3935 	set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
3936 	/* don't mark it as set, when starting the GUI it may be
3937 	 * changed again */
3938 	options[idx].flags &= ~P_WAS_SET;
3939     }
3940 #endif
3941 
3942 #ifdef CURSOR_SHAPE
3943     parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3944 #endif
3945 #ifdef FEAT_MOUSESHAPE
3946     parse_shape_opt(SHAPE_MOUSE);  /* set mouse shapes from 'mouseshape' */
3947 #endif
3948 #ifdef FEAT_PRINTER
3949     (void)parse_printoptions();	    /* parse 'printoptions' default value */
3950 #endif
3951 }
3952 
3953 /*
3954  * Return "dark" or "light" depending on the kind of terminal.
3955  * This is just guessing!  Recognized are:
3956  * "linux"	    Linux console
3957  * "screen.linux"   Linux console with screen
3958  * "cygwin.*"	    Cygwin shell
3959  * "putty.*"	    Putty program
3960  * We also check the COLORFGBG environment variable, which is set by
3961  * rxvt and derivatives. This variable contains either two or three
3962  * values separated by semicolons; we want the last value in either
3963  * case. If this value is 0-6 or 8, our background is dark.
3964  */
3965     static char_u *
3966 term_bg_default(void)
3967 {
3968 #if defined(MSWIN)
3969     /* DOS console is nearly always black */
3970     return (char_u *)"dark";
3971 #else
3972     char_u	*p;
3973 
3974     if (STRCMP(T_NAME, "linux") == 0
3975 	    || STRCMP(T_NAME, "screen.linux") == 0
3976 	    || STRNCMP(T_NAME, "cygwin", 6) == 0
3977 	    || STRNCMP(T_NAME, "putty", 5) == 0
3978 	    || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3979 		&& (p = vim_strrchr(p, ';')) != NULL
3980 		&& ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3981 		&& p[2] == NUL))
3982 	return (char_u *)"dark";
3983     return (char_u *)"light";
3984 #endif
3985 }
3986 
3987 /*
3988  * Initialize the options, part three: After reading the .vimrc
3989  */
3990     void
3991 set_init_3(void)
3992 {
3993 #if defined(UNIX) || defined(MSWIN)
3994 /*
3995  * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3996  * This is done after other initializations, where 'shell' might have been
3997  * set, but only if they have not been set before.
3998  */
3999     char_u  *p;
4000     int	    idx_srr;
4001     int	    do_srr;
4002 # ifdef FEAT_QUICKFIX
4003     int	    idx_sp;
4004     int	    do_sp;
4005 # endif
4006 
4007     idx_srr = findoption((char_u *)"srr");
4008     if (idx_srr < 0)
4009 	do_srr = FALSE;
4010     else
4011 	do_srr = !(options[idx_srr].flags & P_WAS_SET);
4012 # ifdef FEAT_QUICKFIX
4013     idx_sp = findoption((char_u *)"sp");
4014     if (idx_sp < 0)
4015 	do_sp = FALSE;
4016     else
4017 	do_sp = !(options[idx_sp].flags & P_WAS_SET);
4018 # endif
4019     p = get_isolated_shell_name();
4020     if (p != NULL)
4021     {
4022 	/*
4023 	 * Default for p_sp is "| tee", for p_srr is ">".
4024 	 * For known shells it is changed here to include stderr.
4025 	 */
4026 	if (	   fnamecmp(p, "csh") == 0
4027 		|| fnamecmp(p, "tcsh") == 0
4028 # if defined(MSWIN)	// also check with .exe extension
4029 		|| fnamecmp(p, "csh.exe") == 0
4030 		|| fnamecmp(p, "tcsh.exe") == 0
4031 # endif
4032 	   )
4033 	{
4034 # if defined(FEAT_QUICKFIX)
4035 	    if (do_sp)
4036 	    {
4037 #  ifdef MSWIN
4038 		p_sp = (char_u *)">&";
4039 #  else
4040 		p_sp = (char_u *)"|& tee";
4041 #  endif
4042 		options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4043 	    }
4044 # endif
4045 	    if (do_srr)
4046 	    {
4047 		p_srr = (char_u *)">&";
4048 		options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4049 	    }
4050 	}
4051 	else
4052 	    /* Always use bourne shell style redirection if we reach this */
4053 	    if (       fnamecmp(p, "sh") == 0
4054 		    || fnamecmp(p, "ksh") == 0
4055 		    || fnamecmp(p, "mksh") == 0
4056 		    || fnamecmp(p, "pdksh") == 0
4057 		    || fnamecmp(p, "zsh") == 0
4058 		    || fnamecmp(p, "zsh-beta") == 0
4059 		    || fnamecmp(p, "bash") == 0
4060 		    || fnamecmp(p, "fish") == 0
4061 # ifdef MSWIN
4062 		    || fnamecmp(p, "cmd") == 0
4063 		    || fnamecmp(p, "sh.exe") == 0
4064 		    || fnamecmp(p, "ksh.exe") == 0
4065 		    || fnamecmp(p, "mksh.exe") == 0
4066 		    || fnamecmp(p, "pdksh.exe") == 0
4067 		    || fnamecmp(p, "zsh.exe") == 0
4068 		    || fnamecmp(p, "zsh-beta.exe") == 0
4069 		    || fnamecmp(p, "bash.exe") == 0
4070 		    || fnamecmp(p, "cmd.exe") == 0
4071 # endif
4072 		    )
4073 	    {
4074 # if defined(FEAT_QUICKFIX)
4075 		if (do_sp)
4076 		{
4077 #  ifdef MSWIN
4078 		    p_sp = (char_u *)">%s 2>&1";
4079 #  else
4080 		    p_sp = (char_u *)"2>&1| tee";
4081 #  endif
4082 		    options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4083 		}
4084 # endif
4085 		if (do_srr)
4086 		{
4087 		    p_srr = (char_u *)">%s 2>&1";
4088 		    options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4089 		}
4090 	    }
4091 	vim_free(p);
4092     }
4093 #endif
4094 
4095 #if defined(MSWIN)
4096     /*
4097      * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4098      * 'shell' option.
4099      * This is done after other initializations, where 'shell' might have been
4100      * set, but only if they have not been set before.  Default for p_shcf is
4101      * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
4102      * "-c" and "\"".  And for Win32 we need to set p_sxq instead.
4103      */
4104     if (strstr((char *)gettail(p_sh), "sh") != NULL)
4105     {
4106 	int	idx3;
4107 
4108 	idx3 = findoption((char_u *)"shcf");
4109 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4110 	{
4111 	    p_shcf = (char_u *)"-c";
4112 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
4113 	}
4114 
4115 	/* Somehow Win32 requires the quotes around the redirection too */
4116 	idx3 = findoption((char_u *)"sxq");
4117 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4118 	{
4119 	    p_sxq = (char_u *)"\"";
4120 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
4121 	}
4122     }
4123     else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4124     {
4125 	int	idx3;
4126 
4127 	/*
4128 	 * cmd.exe on Windows will strip the first and last double quote given
4129 	 * on the command line, e.g. most of the time things like:
4130 	 *   cmd /c "my path/to/echo" "my args to echo"
4131 	 * become:
4132 	 *   my path/to/echo" "my args to echo
4133 	 * when executed.
4134 	 *
4135 	 * To avoid this, set shellxquote to surround the command in
4136 	 * parenthesis.  This appears to make most commands work, without
4137 	 * breaking commands that worked previously, such as
4138 	 * '"path with spaces/cmd" "a&b"'.
4139 	 */
4140 	idx3 = findoption((char_u *)"sxq");
4141 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4142 	{
4143 	    p_sxq = (char_u *)"(";
4144 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
4145 	}
4146 
4147 	idx3 = findoption((char_u *)"shcf");
4148 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4149 	{
4150 	    p_shcf = (char_u *)"/c";
4151 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
4152 	}
4153     }
4154 #endif
4155 
4156     if (BUFEMPTY())
4157     {
4158 	int idx_ffs = findoption((char_u *)"ffs");
4159 
4160 	/* Apply the first entry of 'fileformats' to the initial buffer. */
4161 	if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4162 	    set_fileformat(default_fileformat(), OPT_LOCAL);
4163     }
4164 
4165 #ifdef FEAT_TITLE
4166     set_title_defaults();
4167 #endif
4168 }
4169 
4170 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
4171 /*
4172  * When 'helplang' is still at its default value, set it to "lang".
4173  * Only the first two characters of "lang" are used.
4174  */
4175     void
4176 set_helplang_default(char_u *lang)
4177 {
4178     int		idx;
4179 
4180     if (lang == NULL || STRLEN(lang) < 2)	/* safety check */
4181 	return;
4182     idx = findoption((char_u *)"hlg");
4183     if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
4184     {
4185 	if (options[idx].flags & P_ALLOCED)
4186 	    free_string_option(p_hlg);
4187 	p_hlg = vim_strsave(lang);
4188 	if (p_hlg == NULL)
4189 	    p_hlg = empty_option;
4190 	else
4191 	{
4192 	    // zh_CN becomes "cn", zh_TW becomes "tw"
4193 	    if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4194 	    {
4195 		p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4196 		p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4197 	    }
4198 	    // any C like setting, such as C.UTF-8, becomes "en"
4199 	    else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4200 	    {
4201 		p_hlg[0] = 'e';
4202 		p_hlg[1] = 'n';
4203 	    }
4204 	    p_hlg[2] = NUL;
4205 	}
4206 	options[idx].flags |= P_ALLOCED;
4207     }
4208 }
4209 #endif
4210 
4211 #ifdef FEAT_GUI
4212     static char_u *
4213 gui_bg_default(void)
4214 {
4215     if (gui_get_lightness(gui.back_pixel) < 127)
4216 	return (char_u *)"dark";
4217     return (char_u *)"light";
4218 }
4219 
4220 /*
4221  * Option initializations that can only be done after opening the GUI window.
4222  */
4223     void
4224 init_gui_options(void)
4225 {
4226     /* Set the 'background' option according to the lightness of the
4227      * background color, unless the user has set it already. */
4228     if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4229     {
4230 	set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4231 	highlight_changed();
4232     }
4233 }
4234 #endif
4235 
4236 #ifdef FEAT_TITLE
4237 /*
4238  * 'title' and 'icon' only default to true if they have not been set or reset
4239  * in .vimrc and we can read the old value.
4240  * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4241  * they can be reset.  This reduces startup time when using X on a remote
4242  * machine.
4243  */
4244     void
4245 set_title_defaults(void)
4246 {
4247     int	    idx1;
4248     long    val;
4249 
4250     /*
4251      * If GUI is (going to be) used, we can always set the window title and
4252      * icon name.  Saves a bit of time, because the X11 display server does
4253      * not need to be contacted.
4254      */
4255     idx1 = findoption((char_u *)"title");
4256     if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4257     {
4258 #ifdef FEAT_GUI
4259 	if (gui.starting || gui.in_use)
4260 	    val = TRUE;
4261 	else
4262 #endif
4263 	    val = mch_can_restore_title();
4264 	options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4265 	p_title = val;
4266     }
4267     idx1 = findoption((char_u *)"icon");
4268     if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4269     {
4270 #ifdef FEAT_GUI
4271 	if (gui.starting || gui.in_use)
4272 	    val = TRUE;
4273 	else
4274 #endif
4275 	    val = mch_can_restore_icon();
4276 	options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4277 	p_icon = val;
4278     }
4279 }
4280 #endif
4281 
4282 #if defined(FEAT_EVAL)
4283     static void
4284 trigger_optionsset_string(
4285 	int	opt_idx,
4286 	int	opt_flags,
4287 	char_u *oldval,
4288 	char_u *newval)
4289 {
4290     // Don't do this recursively.
4291     if (oldval != NULL && newval != NULL
4292 				    && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
4293     {
4294 	char_u buf_type[7];
4295 
4296 	sprintf((char *)buf_type, "%s",
4297 	    (opt_flags & OPT_LOCAL) ? "local" : "global");
4298 	set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4299 	set_vim_var_string(VV_OPTION_NEW, newval, -1);
4300 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4301 	apply_autocmds(EVENT_OPTIONSET,
4302 		       (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4303 	reset_v_option_vars();
4304     }
4305 }
4306 #endif
4307 
4308 /*
4309  * Parse 'arg' for option settings.
4310  *
4311  * 'arg' may be IObuff, but only when no errors can be present and option
4312  * does not need to be expanded with option_expand().
4313  * "opt_flags":
4314  * 0 for ":set"
4315  * OPT_GLOBAL   for ":setglobal"
4316  * OPT_LOCAL    for ":setlocal" and a modeline
4317  * OPT_MODELINE for a modeline
4318  * OPT_WINONLY  to only set window-local options
4319  * OPT_NOWIN	to skip setting window-local options
4320  *
4321  * returns FAIL if an error is detected, OK otherwise
4322  */
4323     int
4324 do_set(
4325     char_u	*arg,		/* option string (may be written to!) */
4326     int		opt_flags)
4327 {
4328     int		opt_idx;
4329     char	*errmsg;
4330     char	errbuf[80];
4331     char_u	*startarg;
4332     int		prefix;	/* 1: nothing, 0: "no", 2: "inv" in front of name */
4333     int		nextchar;	    /* next non-white char after option name */
4334     int		afterchar;	    /* character just after option name */
4335     int		len;
4336     int		i;
4337     varnumber_T	value;
4338     int		key;
4339     long_u	flags;		    /* flags for current option */
4340     char_u	*varp = NULL;	    /* pointer to variable for current option */
4341     int		did_show = FALSE;   /* already showed one value */
4342     int		adding;		    /* "opt+=arg" */
4343     int		prepending;	    /* "opt^=arg" */
4344     int		removing;	    /* "opt-=arg" */
4345     int		cp_val = 0;
4346     char_u	key_name[2];
4347 
4348     if (*arg == NUL)
4349     {
4350 	showoptions(0, opt_flags);
4351 	did_show = TRUE;
4352 	goto theend;
4353     }
4354 
4355     while (*arg != NUL)		/* loop to process all options */
4356     {
4357 	errmsg = NULL;
4358 	startarg = arg;		/* remember for error message */
4359 
4360 	if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4361 						&& !(opt_flags & OPT_MODELINE))
4362 	{
4363 	    /*
4364 	     * ":set all"  show all options.
4365 	     * ":set all&" set all options to their default value.
4366 	     */
4367 	    arg += 3;
4368 	    if (*arg == '&')
4369 	    {
4370 		++arg;
4371 		/* Only for :set command set global value of local options. */
4372 		set_options_default(OPT_FREE | opt_flags);
4373 		didset_options();
4374 		didset_options2();
4375 		redraw_all_later(CLEAR);
4376 	    }
4377 	    else
4378 	    {
4379 		showoptions(1, opt_flags);
4380 		did_show = TRUE;
4381 	    }
4382 	}
4383 	else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
4384 	{
4385 	    showoptions(2, opt_flags);
4386 	    show_termcodes();
4387 	    did_show = TRUE;
4388 	    arg += 7;
4389 	}
4390 	else
4391 	{
4392 	    prefix = 1;
4393 	    if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
4394 	    {
4395 		prefix = 0;
4396 		arg += 2;
4397 	    }
4398 	    else if (STRNCMP(arg, "inv", 3) == 0)
4399 	    {
4400 		prefix = 2;
4401 		arg += 3;
4402 	    }
4403 
4404 	    /* find end of name */
4405 	    key = 0;
4406 	    if (*arg == '<')
4407 	    {
4408 		opt_idx = -1;
4409 		/* look out for <t_>;> */
4410 		if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4411 		    len = 5;
4412 		else
4413 		{
4414 		    len = 1;
4415 		    while (arg[len] != NUL && arg[len] != '>')
4416 			++len;
4417 		}
4418 		if (arg[len] != '>')
4419 		{
4420 		    errmsg = e_invarg;
4421 		    goto skip;
4422 		}
4423 		arg[len] = NUL;			    /* put NUL after name */
4424 		if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4425 		    opt_idx = findoption(arg + 1);
4426 		arg[len++] = '>';		    /* restore '>' */
4427 		if (opt_idx == -1)
4428 		    key = find_key_option(arg + 1, TRUE);
4429 	    }
4430 	    else
4431 	    {
4432 		len = 0;
4433 		/*
4434 		 * The two characters after "t_" may not be alphanumeric.
4435 		 */
4436 		if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4437 		    len = 4;
4438 		else
4439 		    while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4440 			++len;
4441 		nextchar = arg[len];
4442 		arg[len] = NUL;			    /* put NUL after name */
4443 		opt_idx = findoption(arg);
4444 		arg[len] = nextchar;		    /* restore nextchar */
4445 		if (opt_idx == -1)
4446 		    key = find_key_option(arg, FALSE);
4447 	    }
4448 
4449 	    /* remember character after option name */
4450 	    afterchar = arg[len];
4451 
4452 	    /* skip white space, allow ":set ai  ?" */
4453 	    while (VIM_ISWHITE(arg[len]))
4454 		++len;
4455 
4456 	    adding = FALSE;
4457 	    prepending = FALSE;
4458 	    removing = FALSE;
4459 	    if (arg[len] != NUL && arg[len + 1] == '=')
4460 	    {
4461 		if (arg[len] == '+')
4462 		{
4463 		    adding = TRUE;		/* "+=" */
4464 		    ++len;
4465 		}
4466 		else if (arg[len] == '^')
4467 		{
4468 		    prepending = TRUE;		/* "^=" */
4469 		    ++len;
4470 		}
4471 		else if (arg[len] == '-')
4472 		{
4473 		    removing = TRUE;		/* "-=" */
4474 		    ++len;
4475 		}
4476 	    }
4477 	    nextchar = arg[len];
4478 
4479 	    if (opt_idx == -1 && key == 0)	/* found a mismatch: skip */
4480 	    {
4481 		errmsg = N_("E518: Unknown option");
4482 		goto skip;
4483 	    }
4484 
4485 	    if (opt_idx >= 0)
4486 	    {
4487 		if (options[opt_idx].var == NULL)   /* hidden option: skip */
4488 		{
4489 		    /* Only give an error message when requesting the value of
4490 		     * a hidden option, ignore setting it. */
4491 		    if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4492 			    && (!(options[opt_idx].flags & P_BOOL)
4493 				|| nextchar == '?'))
4494 			errmsg = N_("E519: Option not supported");
4495 		    goto skip;
4496 		}
4497 
4498 		flags = options[opt_idx].flags;
4499 		varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4500 	    }
4501 	    else
4502 	    {
4503 		flags = P_STRING;
4504 		if (key < 0)
4505 		{
4506 		    key_name[0] = KEY2TERMCAP0(key);
4507 		    key_name[1] = KEY2TERMCAP1(key);
4508 		}
4509 		else
4510 		{
4511 		    key_name[0] = KS_KEY;
4512 		    key_name[1] = (key & 0xff);
4513 		}
4514 	    }
4515 
4516 	    /* Skip all options that are not window-local (used when showing
4517 	     * an already loaded buffer in a window). */
4518 	    if ((opt_flags & OPT_WINONLY)
4519 			  && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4520 		goto skip;
4521 
4522 	    /* Skip all options that are window-local (used for :vimgrep). */
4523 	    if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4524 					   && options[opt_idx].var == VAR_WIN)
4525 		goto skip;
4526 
4527 	    /* Disallow changing some options from modelines. */
4528 	    if (opt_flags & OPT_MODELINE)
4529 	    {
4530 		if (flags & (P_SECURE | P_NO_ML))
4531 		{
4532 		    errmsg = _("E520: Not allowed in a modeline");
4533 		    goto skip;
4534 		}
4535 #ifdef FEAT_DIFF
4536 		/* In diff mode some options are overruled.  This avoids that
4537 		 * 'foldmethod' becomes "marker" instead of "diff" and that
4538 		 * "wrap" gets set. */
4539 		if (curwin->w_p_diff
4540 			&& opt_idx >= 0  /* shut up coverity warning */
4541 			&& (
4542 #ifdef FEAT_FOLDING
4543 			    options[opt_idx].indir == PV_FDM ||
4544 #endif
4545 			    options[opt_idx].indir == PV_WRAP))
4546 		    goto skip;
4547 #endif
4548 	    }
4549 
4550 #ifdef HAVE_SANDBOX
4551 	    /* Disallow changing some options in the sandbox */
4552 	    if (sandbox != 0 && (flags & P_SECURE))
4553 	    {
4554 		errmsg = _(e_sandbox);
4555 		goto skip;
4556 	    }
4557 #endif
4558 
4559 	    if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4560 	    {
4561 		arg += len;
4562 		cp_val = p_cp;
4563 		if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4564 		{
4565 		    if (arg[3] == 'm')	/* "opt&vim": set to Vim default */
4566 		    {
4567 			cp_val = FALSE;
4568 			arg += 3;
4569 		    }
4570 		    else		/* "opt&vi": set to Vi default */
4571 		    {
4572 			cp_val = TRUE;
4573 			arg += 2;
4574 		    }
4575 		}
4576 		if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4577 			&& arg[1] != NUL && !VIM_ISWHITE(arg[1]))
4578 		{
4579 		    errmsg = e_trailing;
4580 		    goto skip;
4581 		}
4582 	    }
4583 
4584 	    /*
4585 	     * allow '=' and ':' for hystorical reasons (MSDOS command.com
4586 	     * allows only one '=' character per "set" command line. grrr. (jw)
4587 	     */
4588 	    if (nextchar == '?'
4589 		    || (prefix == 1
4590 			&& vim_strchr((char_u *)"=:&<", nextchar) == NULL
4591 			&& !(flags & P_BOOL)))
4592 	    {
4593 		/*
4594 		 * print value
4595 		 */
4596 		if (did_show)
4597 		    msg_putchar('\n');	    /* cursor below last one */
4598 		else
4599 		{
4600 		    gotocmdline(TRUE);	    /* cursor at status line */
4601 		    did_show = TRUE;	    /* remember that we did a line */
4602 		}
4603 		if (opt_idx >= 0)
4604 		{
4605 		    showoneopt(&options[opt_idx], opt_flags);
4606 #ifdef FEAT_EVAL
4607 		    if (p_verbose > 0)
4608 		    {
4609 			/* Mention where the option was last set. */
4610 			if (varp == options[opt_idx].var)
4611 			    last_set_msg(options[opt_idx].script_ctx);
4612 			else if ((int)options[opt_idx].indir & PV_WIN)
4613 			    last_set_msg(curwin->w_p_script_ctx[
4614 				      (int)options[opt_idx].indir & PV_MASK]);
4615 			else if ((int)options[opt_idx].indir & PV_BUF)
4616 			    last_set_msg(curbuf->b_p_script_ctx[
4617 				      (int)options[opt_idx].indir & PV_MASK]);
4618 		    }
4619 #endif
4620 		}
4621 		else
4622 		{
4623 		    char_u	    *p;
4624 
4625 		    p = find_termcode(key_name);
4626 		    if (p == NULL)
4627 		    {
4628 			errmsg = N_("E846: Key code not set");
4629 			goto skip;
4630 		    }
4631 		    else
4632 			(void)show_one_termcode(key_name, p, TRUE);
4633 		}
4634 		if (nextchar != '?'
4635 			&& nextchar != NUL && !VIM_ISWHITE(afterchar))
4636 		    errmsg = e_trailing;
4637 	    }
4638 	    else
4639 	    {
4640 		int value_is_replaced = !prepending && !adding && !removing;
4641 		int value_checked = FALSE;
4642 
4643 		if (flags & P_BOOL)		    /* boolean */
4644 		{
4645 		    if (nextchar == '=' || nextchar == ':')
4646 		    {
4647 			errmsg = e_invarg;
4648 			goto skip;
4649 		    }
4650 
4651 		    /*
4652 		     * ":set opt!": invert
4653 		     * ":set opt&": reset to default value
4654 		     * ":set opt<": reset to global value
4655 		     */
4656 		    if (nextchar == '!')
4657 			value = *(int *)(varp) ^ 1;
4658 		    else if (nextchar == '&')
4659 			value = (int)(long)(long_i)options[opt_idx].def_val[
4660 						((flags & P_VI_DEF) || cp_val)
4661 						 ?  VI_DEFAULT : VIM_DEFAULT];
4662 		    else if (nextchar == '<')
4663 		    {
4664 			/* For 'autoread' -1 means to use global value. */
4665 			if ((int *)varp == &curbuf->b_p_ar
4666 						    && opt_flags == OPT_LOCAL)
4667 			    value = -1;
4668 			else
4669 			    value = *(int *)get_varp_scope(&(options[opt_idx]),
4670 								  OPT_GLOBAL);
4671 		    }
4672 		    else
4673 		    {
4674 			/*
4675 			 * ":set invopt": invert
4676 			 * ":set opt" or ":set noopt": set or reset
4677 			 */
4678 			if (nextchar != NUL && !VIM_ISWHITE(afterchar))
4679 			{
4680 			    errmsg = e_trailing;
4681 			    goto skip;
4682 			}
4683 			if (prefix == 2)	/* inv */
4684 			    value = *(int *)(varp) ^ 1;
4685 			else
4686 			    value = prefix;
4687 		    }
4688 
4689 		    errmsg = set_bool_option(opt_idx, varp, (int)value,
4690 								   opt_flags);
4691 		}
4692 		else				    /* numeric or string */
4693 		{
4694 		    if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4695 							       || prefix != 1)
4696 		    {
4697 			errmsg = e_invarg;
4698 			goto skip;
4699 		    }
4700 
4701 		    if (flags & P_NUM)		    /* numeric */
4702 		    {
4703 			/*
4704 			 * Different ways to set a number option:
4705 			 * &	    set to default value
4706 			 * <	    set to global value
4707 			 * <xx>	    accept special key codes for 'wildchar'
4708 			 * c	    accept any non-digit for 'wildchar'
4709 			 * [-]0-9   set number
4710 			 * other    error
4711 			 */
4712 			++arg;
4713 			if (nextchar == '&')
4714 			    value = (long)(long_i)options[opt_idx].def_val[
4715 						((flags & P_VI_DEF) || cp_val)
4716 						 ?  VI_DEFAULT : VIM_DEFAULT];
4717 			else if (nextchar == '<')
4718 			{
4719 			    /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4720 			     * use the global value. */
4721 			    if ((long *)varp == &curbuf->b_p_ul
4722 						    && opt_flags == OPT_LOCAL)
4723 				value = NO_LOCAL_UNDOLEVEL;
4724 			    else
4725 				value = *(long *)get_varp_scope(
4726 					     &(options[opt_idx]), OPT_GLOBAL);
4727 			}
4728 			else if (((long *)varp == &p_wc
4729 				    || (long *)varp == &p_wcm)
4730 				&& (*arg == '<'
4731 				    || *arg == '^'
4732 				    || (*arg != NUL
4733 					&& (!arg[1] || VIM_ISWHITE(arg[1]))
4734 					&& !VIM_ISDIGIT(*arg))))
4735 			{
4736 			    value = string_to_key(arg, FALSE);
4737 			    if (value == 0 && (long *)varp != &p_wcm)
4738 			    {
4739 				errmsg = e_invarg;
4740 				goto skip;
4741 			    }
4742 			}
4743 			else if (*arg == '-' || VIM_ISDIGIT(*arg))
4744 			{
4745 			    /* Allow negative (for 'undolevels'), octal and
4746 			     * hex numbers. */
4747 			    vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4748 							     &value, NULL, 0);
4749 			    if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
4750 			    {
4751 				errmsg = e_invarg;
4752 				goto skip;
4753 			    }
4754 			}
4755 			else
4756 			{
4757 			    errmsg = N_("E521: Number required after =");
4758 			    goto skip;
4759 			}
4760 
4761 			if (adding)
4762 			    value = *(long *)varp + value;
4763 			if (prepending)
4764 			    value = *(long *)varp * value;
4765 			if (removing)
4766 			    value = *(long *)varp - value;
4767 			errmsg = set_num_option(opt_idx, varp, value,
4768 					   errbuf, sizeof(errbuf), opt_flags);
4769 		    }
4770 		    else if (opt_idx >= 0)		    /* string */
4771 		    {
4772 			char_u	  *save_arg = NULL;
4773 			char_u	  *s = NULL;
4774 			char_u	  *oldval = NULL; /* previous value if *varp */
4775 			char_u	  *newval;
4776 			char_u	  *origval = NULL;
4777 #if defined(FEAT_EVAL)
4778 			char_u	  *saved_origval = NULL;
4779 			char_u	  *saved_newval = NULL;
4780 #endif
4781 			unsigned  newlen;
4782 			int	  comma;
4783 			int	  bs;
4784 			int	  new_value_alloced;	/* new string option
4785 							   was allocated */
4786 
4787 			/* When using ":set opt=val" for a global option
4788 			 * with a local value the local value will be
4789 			 * reset, use the global value here. */
4790 			if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4791 				&& ((int)options[opt_idx].indir & PV_BOTH))
4792 			    varp = options[opt_idx].var;
4793 
4794 			/* The old value is kept until we are sure that the
4795 			 * new value is valid. */
4796 			oldval = *(char_u **)varp;
4797 
4798 			/* When setting the local value of a global
4799 			 * option, the old value may be the global value. */
4800 			if (((int)options[opt_idx].indir & PV_BOTH)
4801 					       && (opt_flags & OPT_LOCAL))
4802 			    origval = *(char_u **)get_varp(
4803 						       &options[opt_idx]);
4804 			else
4805 			    origval = oldval;
4806 
4807 			if (nextchar == '&')	/* set to default val */
4808 			{
4809 			    newval = options[opt_idx].def_val[
4810 						((flags & P_VI_DEF) || cp_val)
4811 						 ?  VI_DEFAULT : VIM_DEFAULT];
4812 			    if ((char_u **)varp == &p_bg)
4813 			    {
4814 				/* guess the value of 'background' */
4815 #ifdef FEAT_GUI
4816 				if (gui.in_use)
4817 				    newval = gui_bg_default();
4818 				else
4819 #endif
4820 				    newval = term_bg_default();
4821 			    }
4822 
4823 			    /* expand environment variables and ~ (since the
4824 			     * default value was already expanded, only
4825 			     * required when an environment variable was set
4826 			     * later */
4827 			    if (newval == NULL)
4828 				newval = empty_option;
4829 			    else
4830 			    {
4831 				s = option_expand(opt_idx, newval);
4832 				if (s == NULL)
4833 				    s = newval;
4834 				newval = vim_strsave(s);
4835 			    }
4836 			    new_value_alloced = TRUE;
4837 			}
4838 			else if (nextchar == '<')	/* set to global val */
4839 			{
4840 			    newval = vim_strsave(*(char_u **)get_varp_scope(
4841 					     &(options[opt_idx]), OPT_GLOBAL));
4842 			    new_value_alloced = TRUE;
4843 			}
4844 			else
4845 			{
4846 			    ++arg;	/* jump to after the '=' or ':' */
4847 
4848 			    /*
4849 			     * Set 'keywordprg' to ":help" if an empty
4850 			     * value was passed to :set by the user.
4851 			     * Misuse errbuf[] for the resulting string.
4852 			     */
4853 			    if (varp == (char_u *)&p_kp
4854 					      && (*arg == NUL || *arg == ' '))
4855 			    {
4856 				STRCPY(errbuf, ":help");
4857 				save_arg = arg;
4858 				arg = (char_u *)errbuf;
4859 			    }
4860 			    /*
4861 			     * Convert 'backspace' number to string, for
4862 			     * adding, prepending and removing string.
4863 			     */
4864 			    else if (varp == (char_u *)&p_bs
4865 					 && VIM_ISDIGIT(**(char_u **)varp))
4866 			    {
4867 				i = getdigits((char_u **)varp);
4868 				switch (i)
4869 				{
4870 				    case 0:
4871 					*(char_u **)varp = empty_option;
4872 					break;
4873 				    case 1:
4874 					*(char_u **)varp = vim_strsave(
4875 						      (char_u *)"indent,eol");
4876 					break;
4877 				    case 2:
4878 					*(char_u **)varp = vim_strsave(
4879 						(char_u *)"indent,eol,start");
4880 					break;
4881 				}
4882 				vim_free(oldval);
4883 				if (origval == oldval)
4884 				    origval = *(char_u **)varp;
4885 				oldval = *(char_u **)varp;
4886 			    }
4887 			    /*
4888 			     * Convert 'whichwrap' number to string, for
4889 			     * backwards compatibility with Vim 3.0.
4890 			     * Misuse errbuf[] for the resulting string.
4891 			     */
4892 			    else if (varp == (char_u *)&p_ww
4893 							 && VIM_ISDIGIT(*arg))
4894 			    {
4895 				*errbuf = NUL;
4896 				i = getdigits(&arg);
4897 				if (i & 1)
4898 				    STRCAT(errbuf, "b,");
4899 				if (i & 2)
4900 				    STRCAT(errbuf, "s,");
4901 				if (i & 4)
4902 				    STRCAT(errbuf, "h,l,");
4903 				if (i & 8)
4904 				    STRCAT(errbuf, "<,>,");
4905 				if (i & 16)
4906 				    STRCAT(errbuf, "[,],");
4907 				if (*errbuf != NUL)	/* remove trailing , */
4908 				    errbuf[STRLEN(errbuf) - 1] = NUL;
4909 				save_arg = arg;
4910 				arg = (char_u *)errbuf;
4911 			    }
4912 			    /*
4913 			     * Remove '>' before 'dir' and 'bdir', for
4914 			     * backwards compatibility with version 3.0
4915 			     */
4916 			    else if (  *arg == '>'
4917 				    && (varp == (char_u *)&p_dir
4918 					    || varp == (char_u *)&p_bdir))
4919 			    {
4920 				++arg;
4921 			    }
4922 
4923 			    /*
4924 			     * Copy the new string into allocated memory.
4925 			     * Can't use set_string_option_direct(), because
4926 			     * we need to remove the backslashes.
4927 			     */
4928 			    /* get a bit too much */
4929 			    newlen = (unsigned)STRLEN(arg) + 1;
4930 			    if (adding || prepending || removing)
4931 				newlen += (unsigned)STRLEN(origval) + 1;
4932 			    newval = alloc(newlen);
4933 			    if (newval == NULL)  /* out of mem, don't change */
4934 				break;
4935 			    s = newval;
4936 
4937 			    /*
4938 			     * Copy the string, skip over escaped chars.
4939 			     * For MS-DOS and WIN32 backslashes before normal
4940 			     * file name characters are not removed, and keep
4941 			     * backslash at start, for "\\machine\path", but
4942 			     * do remove it for "\\\\machine\\path".
4943 			     * The reverse is found in ExpandOldSetting().
4944 			     */
4945 			    while (*arg && !VIM_ISWHITE(*arg))
4946 			    {
4947 				if (*arg == '\\' && arg[1] != NUL
4948 #ifdef BACKSLASH_IN_FILENAME
4949 					&& !((flags & P_EXPAND)
4950 						&& vim_isfilec(arg[1])
4951 						&& (arg[1] != '\\'
4952 						    || (s == newval
4953 							&& arg[2] != '\\')))
4954 #endif
4955 								    )
4956 				    ++arg;	/* remove backslash */
4957 				if (has_mbyte
4958 					&& (i = (*mb_ptr2len)(arg)) > 1)
4959 				{
4960 				    /* copy multibyte char */
4961 				    mch_memmove(s, arg, (size_t)i);
4962 				    arg += i;
4963 				    s += i;
4964 				}
4965 				else
4966 				    *s++ = *arg++;
4967 			    }
4968 			    *s = NUL;
4969 
4970 			    /*
4971 			     * Expand environment variables and ~.
4972 			     * Don't do it when adding without inserting a
4973 			     * comma.
4974 			     */
4975 			    if (!(adding || prepending || removing)
4976 							 || (flags & P_COMMA))
4977 			    {
4978 				s = option_expand(opt_idx, newval);
4979 				if (s != NULL)
4980 				{
4981 				    vim_free(newval);
4982 				    newlen = (unsigned)STRLEN(s) + 1;
4983 				    if (adding || prepending || removing)
4984 					newlen += (unsigned)STRLEN(origval) + 1;
4985 				    newval = alloc(newlen);
4986 				    if (newval == NULL)
4987 					break;
4988 				    STRCPY(newval, s);
4989 				}
4990 			    }
4991 
4992 			    /* locate newval[] in origval[] when removing it
4993 			     * and when adding to avoid duplicates */
4994 			    i = 0;	/* init for GCC */
4995 			    if (removing || (flags & P_NODUP))
4996 			    {
4997 				i = (int)STRLEN(newval);
4998 				bs = 0;
4999 				for (s = origval; *s; ++s)
5000 				{
5001 				    if ((!(flags & P_COMMA)
5002 						|| s == origval
5003 						|| (s[-1] == ',' && !(bs & 1)))
5004 					    && STRNCMP(s, newval, i) == 0
5005 					    && (!(flags & P_COMMA)
5006 						|| s[i] == ','
5007 						|| s[i] == NUL))
5008 					break;
5009 				    /* Count backslashes.  Only a comma with an
5010 				     * even number of backslashes or a single
5011 				     * backslash preceded by a comma before it
5012 				     * is recognized as a separator */
5013 				    if ((s > origval + 1
5014 						&& s[-1] == '\\'
5015 						&& s[-2] != ',')
5016 					    || (s == origval + 1
5017 						&& s[-1] == '\\'))
5018 
5019 					++bs;
5020 				    else
5021 					bs = 0;
5022 				}
5023 
5024 				/* do not add if already there */
5025 				if ((adding || prepending) && *s)
5026 				{
5027 				    prepending = FALSE;
5028 				    adding = FALSE;
5029 				    STRCPY(newval, origval);
5030 				}
5031 			    }
5032 
5033 			    /* concatenate the two strings; add a ',' if
5034 			     * needed */
5035 			    if (adding || prepending)
5036 			    {
5037 				comma = ((flags & P_COMMA) && *origval != NUL
5038 							   && *newval != NUL);
5039 				if (adding)
5040 				{
5041 				    i = (int)STRLEN(origval);
5042 				    /* strip a trailing comma, would get 2 */
5043 				    if (comma && i > 1
5044 					  && (flags & P_ONECOMMA) == P_ONECOMMA
5045 					  && origval[i - 1] == ','
5046 					  && origval[i - 2] != '\\')
5047 					i--;
5048 				    mch_memmove(newval + i + comma, newval,
5049 							  STRLEN(newval) + 1);
5050 				    mch_memmove(newval, origval, (size_t)i);
5051 				}
5052 				else
5053 				{
5054 				    i = (int)STRLEN(newval);
5055 				    STRMOVE(newval + i + comma, origval);
5056 				}
5057 				if (comma)
5058 				    newval[i] = ',';
5059 			    }
5060 
5061 			    /* Remove newval[] from origval[]. (Note: "i" has
5062 			     * been set above and is used here). */
5063 			    if (removing)
5064 			    {
5065 				STRCPY(newval, origval);
5066 				if (*s)
5067 				{
5068 				    /* may need to remove a comma */
5069 				    if (flags & P_COMMA)
5070 				    {
5071 					if (s == origval)
5072 					{
5073 					    /* include comma after string */
5074 					    if (s[i] == ',')
5075 						++i;
5076 					}
5077 					else
5078 					{
5079 					    /* include comma before string */
5080 					    --s;
5081 					    ++i;
5082 					}
5083 				    }
5084 				    STRMOVE(newval + (s - origval), s + i);
5085 				}
5086 			    }
5087 
5088 			    if (flags & P_FLAGLIST)
5089 			    {
5090 				/* Remove flags that appear twice. */
5091 				for (s = newval; *s;)
5092 				{
5093 				    /* if options have P_FLAGLIST and
5094 				     * P_ONECOMMA such as 'whichwrap' */
5095 				    if (flags & P_ONECOMMA)
5096 				    {
5097 					if (*s != ',' && *(s + 1) == ','
5098 					      && vim_strchr(s + 2, *s) != NULL)
5099 					{
5100 					    /* Remove the duplicated value and
5101 					     * the next comma. */
5102 					    STRMOVE(s, s + 2);
5103 					    continue;
5104 					}
5105 				    }
5106 				    else
5107 				    {
5108 					if ((!(flags & P_COMMA) || *s != ',')
5109 					      && vim_strchr(s + 1, *s) != NULL)
5110 					{
5111 					    STRMOVE(s, s + 1);
5112 					    continue;
5113 					}
5114 				    }
5115 				    ++s;
5116 				}
5117 			    }
5118 
5119 			    if (save_arg != NULL)   /* number for 'whichwrap' */
5120 				arg = save_arg;
5121 			    new_value_alloced = TRUE;
5122 			}
5123 
5124 			/*
5125 			 * Set the new value.
5126 			 */
5127 			*(char_u **)(varp) = newval;
5128 
5129 #if defined(FEAT_EVAL)
5130 			if (!starting
5131 # ifdef FEAT_CRYPT
5132 				&& options[opt_idx].indir != PV_KEY
5133 # endif
5134 					  && origval != NULL && newval != NULL)
5135 			{
5136 			    /* origval may be freed by
5137 			     * did_set_string_option(), make a copy. */
5138 			    saved_origval = vim_strsave(origval);
5139 			    /* newval (and varp) may become invalid if the
5140 			     * buffer is closed by autocommands. */
5141 			    saved_newval = vim_strsave(newval);
5142 			}
5143 #endif
5144 
5145 			{
5146 			    long_u *p = insecure_flag(opt_idx, opt_flags);
5147 			    int	    secure_saved = secure;
5148 
5149 			    // When an option is set in the sandbox, from a
5150 			    // modeline or in secure mode, then deal with side
5151 			    // effects in secure mode.  Also when the value was
5152 			    // set with the P_INSECURE flag and is not
5153 			    // completely replaced.
5154 			    if ((opt_flags & OPT_MODELINE)
5155 #ifdef HAVE_SANDBOX
5156 				  || sandbox != 0
5157 #endif
5158 				  || (!value_is_replaced && (*p & P_INSECURE)))
5159 				secure = 1;
5160 
5161 			    // Handle side effects, and set the global value
5162 			    // for ":set" on local options. Note: when setting
5163 			    // 'syntax' or 'filetype' autocommands may be
5164 			    // triggered that can cause havoc.
5165 			    errmsg = did_set_string_option(
5166 				    opt_idx, (char_u **)varp,
5167 				    new_value_alloced, oldval, errbuf,
5168 				    opt_flags, &value_checked);
5169 
5170 			    secure = secure_saved;
5171 			}
5172 
5173 #if defined(FEAT_EVAL)
5174 			if (errmsg == NULL)
5175 			    trigger_optionsset_string(opt_idx, opt_flags,
5176 						  saved_origval, saved_newval);
5177 			vim_free(saved_origval);
5178 			vim_free(saved_newval);
5179 #endif
5180 			/* If error detected, print the error message. */
5181 			if (errmsg != NULL)
5182 			    goto skip;
5183 		    }
5184 		    else	    /* key code option */
5185 		    {
5186 			char_u	    *p;
5187 
5188 			if (nextchar == '&')
5189 			{
5190 			    if (add_termcap_entry(key_name, TRUE) == FAIL)
5191 				errmsg = N_("E522: Not found in termcap");
5192 			}
5193 			else
5194 			{
5195 			    ++arg; /* jump to after the '=' or ':' */
5196 			    for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
5197 				if (*p == '\\' && p[1] != NUL)
5198 				    ++p;
5199 			    nextchar = *p;
5200 			    *p = NUL;
5201 			    add_termcode(key_name, arg, FALSE);
5202 			    *p = nextchar;
5203 			}
5204 			if (full_screen)
5205 			    ttest(FALSE);
5206 			redraw_all_later(CLEAR);
5207 		    }
5208 		}
5209 
5210 		if (opt_idx >= 0)
5211 		    did_set_option(
5212 			 opt_idx, opt_flags, value_is_replaced, value_checked);
5213 	    }
5214 
5215 skip:
5216 	    /*
5217 	     * Advance to next argument.
5218 	     * - skip until a blank found, taking care of backslashes
5219 	     * - skip blanks
5220 	     * - skip one "=val" argument (for hidden options ":set gfn =xx")
5221 	     */
5222 	    for (i = 0; i < 2 ; ++i)
5223 	    {
5224 		while (*arg != NUL && !VIM_ISWHITE(*arg))
5225 		    if (*arg++ == '\\' && *arg != NUL)
5226 			++arg;
5227 		arg = skipwhite(arg);
5228 		if (*arg != '=')
5229 		    break;
5230 	    }
5231 	}
5232 
5233 	if (errmsg != NULL)
5234 	{
5235 	    vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
5236 	    i = (int)STRLEN(IObuff) + 2;
5237 	    if (i + (arg - startarg) < IOSIZE)
5238 	    {
5239 		/* append the argument with the error */
5240 		STRCAT(IObuff, ": ");
5241 		mch_memmove(IObuff + i, startarg, (arg - startarg));
5242 		IObuff[i + (arg - startarg)] = NUL;
5243 	    }
5244 	    /* make sure all characters are printable */
5245 	    trans_characters(IObuff, IOSIZE);
5246 
5247 	    ++no_wait_return;		// wait_return done later
5248 	    emsg((char *)IObuff);	// show error highlighted
5249 	    --no_wait_return;
5250 
5251 	    return FAIL;
5252 	}
5253 
5254 	arg = skipwhite(arg);
5255     }
5256 
5257 theend:
5258     if (silent_mode && did_show)
5259     {
5260 	/* After displaying option values in silent mode. */
5261 	silent_mode = FALSE;
5262 	info_message = TRUE;	/* use mch_msg(), not mch_errmsg() */
5263 	msg_putchar('\n');
5264 	cursor_on();		/* msg_start() switches it off */
5265 	out_flush();
5266 	silent_mode = TRUE;
5267 	info_message = FALSE;	/* use mch_msg(), not mch_errmsg() */
5268     }
5269 
5270     return OK;
5271 }
5272 
5273 /*
5274  * Call this when an option has been given a new value through a user command.
5275  * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5276  */
5277     static void
5278 did_set_option(
5279     int	    opt_idx,
5280     int	    opt_flags,	    // possibly with OPT_MODELINE
5281     int	    new_value,	    // value was replaced completely
5282     int	    value_checked)  // value was checked to be safe, no need to set the
5283 			    // P_INSECURE flag.
5284 {
5285     long_u	*p;
5286 
5287     options[opt_idx].flags |= P_WAS_SET;
5288 
5289     /* When an option is set in the sandbox, from a modeline or in secure mode
5290      * set the P_INSECURE flag.  Otherwise, if a new value is stored reset the
5291      * flag. */
5292     p = insecure_flag(opt_idx, opt_flags);
5293     if (!value_checked && (secure
5294 #ifdef HAVE_SANDBOX
5295 	    || sandbox != 0
5296 #endif
5297 	    || (opt_flags & OPT_MODELINE)))
5298 	*p = *p | P_INSECURE;
5299     else if (new_value)
5300 	*p = *p & ~P_INSECURE;
5301 }
5302 
5303     static char *
5304 illegal_char(char *errbuf, int c)
5305 {
5306     if (errbuf == NULL)
5307 	return "";
5308     sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
5309 							(char *)transchar(c));
5310     return errbuf;
5311 }
5312 
5313 /*
5314  * Convert a key name or string into a key value.
5315  * Used for 'wildchar' and 'cedit' options.
5316  * When "multi_byte" is TRUE allow for multi-byte characters.
5317  */
5318     int
5319 string_to_key(char_u *arg, int multi_byte)
5320 {
5321     if (*arg == '<')
5322 	return find_key_option(arg + 1, TRUE);
5323     if (*arg == '^')
5324 	return Ctrl_chr(arg[1]);
5325     if (multi_byte)
5326 	return PTR2CHAR(arg);
5327     return *arg;
5328 }
5329 
5330 #ifdef FEAT_CMDWIN
5331 /*
5332  * Check value of 'cedit' and set cedit_key.
5333  * Returns NULL if value is OK, error message otherwise.
5334  */
5335     static char *
5336 check_cedit(void)
5337 {
5338     int n;
5339 
5340     if (*p_cedit == NUL)
5341 	cedit_key = -1;
5342     else
5343     {
5344 	n = string_to_key(p_cedit, FALSE);
5345 	if (vim_isprintc(n))
5346 	    return e_invarg;
5347 	cedit_key = n;
5348     }
5349     return NULL;
5350 }
5351 #endif
5352 
5353 #ifdef FEAT_TITLE
5354 /*
5355  * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5356  * maketitle() to create and display it.
5357  * When switching the title or icon off, call mch_restore_title() to get
5358  * the old value back.
5359  */
5360     static void
5361 did_set_title(void)
5362 {
5363     if (starting != NO_SCREEN
5364 #ifdef FEAT_GUI
5365 	    && !gui.starting
5366 #endif
5367 				)
5368 	maketitle();
5369 }
5370 #endif
5371 
5372 /*
5373  * set_options_bin -  called when 'bin' changes value.
5374  */
5375     void
5376 set_options_bin(
5377     int		oldval,
5378     int		newval,
5379     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
5380 {
5381     /*
5382      * The option values that are changed when 'bin' changes are
5383      * copied when 'bin is set and restored when 'bin' is reset.
5384      */
5385     if (newval)
5386     {
5387 	if (!oldval)		/* switched on */
5388 	{
5389 	    if (!(opt_flags & OPT_GLOBAL))
5390 	    {
5391 		curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5392 		curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5393 		curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5394 		curbuf->b_p_et_nobin = curbuf->b_p_et;
5395 	    }
5396 	    if (!(opt_flags & OPT_LOCAL))
5397 	    {
5398 		p_tw_nobin = p_tw;
5399 		p_wm_nobin = p_wm;
5400 		p_ml_nobin = p_ml;
5401 		p_et_nobin = p_et;
5402 	    }
5403 	}
5404 
5405 	if (!(opt_flags & OPT_GLOBAL))
5406 	{
5407 	    curbuf->b_p_tw = 0;	/* no automatic line wrap */
5408 	    curbuf->b_p_wm = 0;	/* no automatic line wrap */
5409 	    curbuf->b_p_ml = 0;	/* no modelines */
5410 	    curbuf->b_p_et = 0;	/* no expandtab */
5411 	}
5412 	if (!(opt_flags & OPT_LOCAL))
5413 	{
5414 	    p_tw = 0;
5415 	    p_wm = 0;
5416 	    p_ml = FALSE;
5417 	    p_et = FALSE;
5418 	    p_bin = TRUE;	/* needed when called for the "-b" argument */
5419 	}
5420     }
5421     else if (oldval)		/* switched off */
5422     {
5423 	if (!(opt_flags & OPT_GLOBAL))
5424 	{
5425 	    curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5426 	    curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5427 	    curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5428 	    curbuf->b_p_et = curbuf->b_p_et_nobin;
5429 	}
5430 	if (!(opt_flags & OPT_LOCAL))
5431 	{
5432 	    p_tw = p_tw_nobin;
5433 	    p_wm = p_wm_nobin;
5434 	    p_ml = p_ml_nobin;
5435 	    p_et = p_et_nobin;
5436 	}
5437     }
5438 }
5439 
5440 #ifdef FEAT_VIMINFO
5441 /*
5442  * Find the parameter represented by the given character (eg ', :, ", or /),
5443  * and return its associated value in the 'viminfo' string.
5444  * Only works for number parameters, not for 'r' or 'n'.
5445  * If the parameter is not specified in the string or there is no following
5446  * number, return -1.
5447  */
5448     int
5449 get_viminfo_parameter(int type)
5450 {
5451     char_u  *p;
5452 
5453     p = find_viminfo_parameter(type);
5454     if (p != NULL && VIM_ISDIGIT(*p))
5455 	return atoi((char *)p);
5456     return -1;
5457 }
5458 
5459 /*
5460  * Find the parameter represented by the given character (eg ''', ':', '"', or
5461  * '/') in the 'viminfo' option and return a pointer to the string after it.
5462  * Return NULL if the parameter is not specified in the string.
5463  */
5464     char_u *
5465 find_viminfo_parameter(int type)
5466 {
5467     char_u  *p;
5468 
5469     for (p = p_viminfo; *p; ++p)
5470     {
5471 	if (*p == type)
5472 	    return p + 1;
5473 	if (*p == 'n')		    /* 'n' is always the last one */
5474 	    break;
5475 	p = vim_strchr(p, ',');	    /* skip until next ',' */
5476 	if (p == NULL)		    /* hit the end without finding parameter */
5477 	    break;
5478     }
5479     return NULL;
5480 }
5481 #endif
5482 
5483 /*
5484  * Expand environment variables for some string options.
5485  * These string options cannot be indirect!
5486  * If "val" is NULL expand the current value of the option.
5487  * Return pointer to NameBuff, or NULL when not expanded.
5488  */
5489     static char_u *
5490 option_expand(int opt_idx, char_u *val)
5491 {
5492     /* if option doesn't need expansion nothing to do */
5493     if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5494 	return NULL;
5495 
5496     /* If val is longer than MAXPATHL no meaningful expansion can be done,
5497      * expand_env() would truncate the string. */
5498     if (val != NULL && STRLEN(val) > MAXPATHL)
5499 	return NULL;
5500 
5501     if (val == NULL)
5502 	val = *(char_u **)options[opt_idx].var;
5503 
5504     /*
5505      * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5506      * Escape spaces when expanding 'tags', they are used to separate file
5507      * names.
5508      * For 'spellsuggest' expand after "file:".
5509      */
5510     expand_env_esc(val, NameBuff, MAXPATHL,
5511 	    (char_u **)options[opt_idx].var == &p_tags, FALSE,
5512 #ifdef FEAT_SPELL
5513 	    (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5514 #endif
5515 				  NULL);
5516     if (STRCMP(NameBuff, val) == 0)   /* they are the same */
5517 	return NULL;
5518 
5519     return NameBuff;
5520 }
5521 
5522 /*
5523  * After setting various option values: recompute variables that depend on
5524  * option values.
5525  */
5526     static void
5527 didset_options(void)
5528 {
5529     /* initialize the table for 'iskeyword' et.al. */
5530     (void)init_chartab();
5531 
5532     (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5533     (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5534     (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
5535 #ifdef FEAT_SESSION
5536     (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5537     (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5538 #endif
5539 #ifdef FEAT_FOLDING
5540     (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5541 #endif
5542     (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5543     (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
5544     (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5545 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5546     (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5547 #endif
5548 #ifdef FEAT_SPELL
5549     (void)spell_check_msm();
5550     (void)spell_check_sps();
5551     (void)compile_cap_prog(curwin->w_s);
5552     (void)did_set_spell_option(TRUE);
5553 #endif
5554 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
5555     (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5556 #endif
5557 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
5558     (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5559 #endif
5560 #ifdef FEAT_CMDWIN
5561     /* set cedit_key */
5562     (void)check_cedit();
5563 #endif
5564 #ifdef FEAT_LINEBREAK
5565     briopt_check(curwin);
5566 #endif
5567 #ifdef FEAT_LINEBREAK
5568     /* initialize the table for 'breakat'. */
5569     fill_breakat_flags();
5570 #endif
5571 
5572 }
5573 
5574 /*
5575  * More side effects of setting options.
5576  */
5577     static void
5578 didset_options2(void)
5579 {
5580     /* Initialize the highlight_attr[] table. */
5581     (void)highlight_changed();
5582 
5583     /* Parse default for 'wildmode'  */
5584     check_opt_wim();
5585 
5586     (void)set_chars_option(&p_lcs);
5587     /* Parse default for 'fillchars'. */
5588     (void)set_chars_option(&p_fcs);
5589 
5590 #ifdef FEAT_CLIPBOARD
5591     /* Parse default for 'clipboard' */
5592     (void)check_clipboard_option();
5593 #endif
5594 #ifdef FEAT_VARTABS
5595     vim_free(curbuf->b_p_vsts_array);
5596     tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5597     vim_free(curbuf->b_p_vts_array);
5598     tabstop_set(curbuf->b_p_vts,  &curbuf->b_p_vts_array);
5599 #endif
5600 }
5601 
5602 /*
5603  * Check for string options that are NULL (normally only termcap options).
5604  */
5605     void
5606 check_options(void)
5607 {
5608     int		opt_idx;
5609 
5610     for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5611 	if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5612 	    check_string_option((char_u **)get_varp(&(options[opt_idx])));
5613 }
5614 
5615 /*
5616  * Check string options in a buffer for NULL value.
5617  */
5618     void
5619 check_buf_options(buf_T *buf)
5620 {
5621     check_string_option(&buf->b_p_bh);
5622     check_string_option(&buf->b_p_bt);
5623     check_string_option(&buf->b_p_fenc);
5624     check_string_option(&buf->b_p_ff);
5625 #ifdef FEAT_FIND_ID
5626     check_string_option(&buf->b_p_def);
5627     check_string_option(&buf->b_p_inc);
5628 # ifdef FEAT_EVAL
5629     check_string_option(&buf->b_p_inex);
5630 # endif
5631 #endif
5632 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5633     check_string_option(&buf->b_p_inde);
5634     check_string_option(&buf->b_p_indk);
5635 #endif
5636 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5637     check_string_option(&buf->b_p_bexpr);
5638 #endif
5639 #if defined(FEAT_CRYPT)
5640     check_string_option(&buf->b_p_cm);
5641 #endif
5642     check_string_option(&buf->b_p_fp);
5643 #if defined(FEAT_EVAL)
5644     check_string_option(&buf->b_p_fex);
5645 #endif
5646 #ifdef FEAT_CRYPT
5647     check_string_option(&buf->b_p_key);
5648 #endif
5649     check_string_option(&buf->b_p_kp);
5650     check_string_option(&buf->b_p_mps);
5651     check_string_option(&buf->b_p_fo);
5652     check_string_option(&buf->b_p_flp);
5653     check_string_option(&buf->b_p_isk);
5654 #ifdef FEAT_COMMENTS
5655     check_string_option(&buf->b_p_com);
5656 #endif
5657 #ifdef FEAT_FOLDING
5658     check_string_option(&buf->b_p_cms);
5659 #endif
5660     check_string_option(&buf->b_p_nf);
5661 #ifdef FEAT_TEXTOBJ
5662     check_string_option(&buf->b_p_qe);
5663 #endif
5664 #ifdef FEAT_SYN_HL
5665     check_string_option(&buf->b_p_syn);
5666     check_string_option(&buf->b_s.b_syn_isk);
5667 #endif
5668 #ifdef FEAT_SPELL
5669     check_string_option(&buf->b_s.b_p_spc);
5670     check_string_option(&buf->b_s.b_p_spf);
5671     check_string_option(&buf->b_s.b_p_spl);
5672 #endif
5673 #ifdef FEAT_SEARCHPATH
5674     check_string_option(&buf->b_p_sua);
5675 #endif
5676 #ifdef FEAT_CINDENT
5677     check_string_option(&buf->b_p_cink);
5678     check_string_option(&buf->b_p_cino);
5679     parse_cino(buf);
5680 #endif
5681     check_string_option(&buf->b_p_ft);
5682 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5683     check_string_option(&buf->b_p_cinw);
5684 #endif
5685 #ifdef FEAT_INS_EXPAND
5686     check_string_option(&buf->b_p_cpt);
5687 #endif
5688 #ifdef FEAT_COMPL_FUNC
5689     check_string_option(&buf->b_p_cfu);
5690     check_string_option(&buf->b_p_ofu);
5691 #endif
5692 #ifdef FEAT_KEYMAP
5693     check_string_option(&buf->b_p_keymap);
5694 #endif
5695 #ifdef FEAT_QUICKFIX
5696     check_string_option(&buf->b_p_gp);
5697     check_string_option(&buf->b_p_mp);
5698     check_string_option(&buf->b_p_efm);
5699 #endif
5700     check_string_option(&buf->b_p_ep);
5701     check_string_option(&buf->b_p_path);
5702     check_string_option(&buf->b_p_tags);
5703     check_string_option(&buf->b_p_tc);
5704 #ifdef FEAT_INS_EXPAND
5705     check_string_option(&buf->b_p_dict);
5706     check_string_option(&buf->b_p_tsr);
5707 #endif
5708 #ifdef FEAT_LISP
5709     check_string_option(&buf->b_p_lw);
5710 #endif
5711     check_string_option(&buf->b_p_bkc);
5712     check_string_option(&buf->b_p_menc);
5713 #ifdef FEAT_VARTABS
5714     check_string_option(&buf->b_p_vsts);
5715     check_string_option(&buf->b_p_vts);
5716 #endif
5717 }
5718 
5719 /*
5720  * Free the string allocated for an option.
5721  * Checks for the string being empty_option. This may happen if we're out of
5722  * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5723  * check_options().
5724  * Does NOT check for P_ALLOCED flag!
5725  */
5726     void
5727 free_string_option(char_u *p)
5728 {
5729     if (p != empty_option)
5730 	vim_free(p);
5731 }
5732 
5733     void
5734 clear_string_option(char_u **pp)
5735 {
5736     if (*pp != empty_option)
5737 	vim_free(*pp);
5738     *pp = empty_option;
5739 }
5740 
5741     static void
5742 check_string_option(char_u **pp)
5743 {
5744     if (*pp == NULL)
5745 	*pp = empty_option;
5746 }
5747 
5748 /*
5749  * Return the option index found by a pointer into term_strings[].
5750  * Return -1 if not found.
5751  */
5752     int
5753 get_term_opt_idx(char_u **p)
5754 {
5755     int opt_idx;
5756 
5757     for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5758 	if (options[opt_idx].var == (char_u *)p)
5759 	    return opt_idx;
5760     return -1; // cannot happen: didn't find it!
5761 }
5762 
5763 /*
5764  * Mark a terminal option as allocated, found by a pointer into term_strings[].
5765  * Return the option index or -1 if not found.
5766  */
5767     int
5768 set_term_option_alloced(char_u **p)
5769 {
5770     int		opt_idx = get_term_opt_idx(p);
5771 
5772     if (opt_idx >= 0)
5773 	options[opt_idx].flags |= P_ALLOCED;
5774     return opt_idx;
5775 }
5776 
5777 #if defined(FEAT_EVAL) || defined(PROTO)
5778 /*
5779  * Return TRUE when option "opt" was set from a modeline or in secure mode.
5780  * Return FALSE when it wasn't.
5781  * Return -1 for an unknown option.
5782  */
5783     int
5784 was_set_insecurely(char_u *opt, int opt_flags)
5785 {
5786     int	    idx = findoption(opt);
5787     long_u  *flagp;
5788 
5789     if (idx >= 0)
5790     {
5791 	flagp = insecure_flag(idx, opt_flags);
5792 	return (*flagp & P_INSECURE) != 0;
5793     }
5794     internal_error("was_set_insecurely()");
5795     return -1;
5796 }
5797 
5798 /*
5799  * Get a pointer to the flags used for the P_INSECURE flag of option
5800  * "opt_idx".  For some local options a local flags field is used.
5801  */
5802     static long_u *
5803 insecure_flag(int opt_idx, int opt_flags)
5804 {
5805     if (opt_flags & OPT_LOCAL)
5806 	switch ((int)options[opt_idx].indir)
5807 	{
5808 #ifdef FEAT_STL_OPT
5809 	    case PV_STL:	return &curwin->w_p_stl_flags;
5810 #endif
5811 #ifdef FEAT_EVAL
5812 # ifdef FEAT_FOLDING
5813 	    case PV_FDE:	return &curwin->w_p_fde_flags;
5814 	    case PV_FDT:	return &curwin->w_p_fdt_flags;
5815 # endif
5816 # ifdef FEAT_BEVAL
5817 	    case PV_BEXPR:	return &curbuf->b_p_bexpr_flags;
5818 # endif
5819 # if defined(FEAT_CINDENT)
5820 	    case PV_INDE:	return &curbuf->b_p_inde_flags;
5821 # endif
5822 	    case PV_FEX:	return &curbuf->b_p_fex_flags;
5823 # ifdef FEAT_FIND_ID
5824 	    case PV_INEX:	return &curbuf->b_p_inex_flags;
5825 # endif
5826 #endif
5827 	}
5828 
5829     /* Nothing special, return global flags field. */
5830     return &options[opt_idx].flags;
5831 }
5832 #endif
5833 
5834 #ifdef FEAT_TITLE
5835 /*
5836  * Redraw the window title and/or tab page text later.
5837  */
5838 static void redraw_titles(void)
5839 {
5840     need_maketitle = TRUE;
5841     redraw_tabline = TRUE;
5842 }
5843 #endif
5844 
5845 /*
5846  * Set a string option to a new value (without checking the effect).
5847  * The string is copied into allocated memory.
5848  * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
5849  * When "set_sid" is zero set the scriptID to current_sctx.sc_sid.  When
5850  * "set_sid" is SID_NONE don't set the scriptID.  Otherwise set the scriptID to
5851  * "set_sid".
5852  */
5853     void
5854 set_string_option_direct(
5855     char_u	*name,
5856     int		opt_idx,
5857     char_u	*val,
5858     int		opt_flags,	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5859     int		set_sid UNUSED)
5860 {
5861     char_u	*s;
5862     char_u	**varp;
5863     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5864     int		idx = opt_idx;
5865 
5866     if (idx == -1)		/* use name */
5867     {
5868 	idx = findoption(name);
5869 	if (idx < 0)	/* not found (should not happen) */
5870 	{
5871 	    semsg(_(e_intern2), "set_string_option_direct()");
5872 	    siemsg(_("For option %s"), name);
5873 	    return;
5874 	}
5875     }
5876 
5877     if (options[idx].var == NULL)	/* can't set hidden option */
5878 	return;
5879 
5880     s = vim_strsave(val);
5881     if (s != NULL)
5882     {
5883 	varp = (char_u **)get_varp_scope(&(options[idx]),
5884 					       both ? OPT_LOCAL : opt_flags);
5885 	if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
5886 	    free_string_option(*varp);
5887 	*varp = s;
5888 
5889 	/* For buffer/window local option may also set the global value. */
5890 	if (both)
5891 	    set_string_option_global(idx, varp);
5892 
5893 	options[idx].flags |= P_ALLOCED;
5894 
5895 	/* When setting both values of a global option with a local value,
5896 	 * make the local value empty, so that the global value is used. */
5897 	if (((int)options[idx].indir & PV_BOTH) && both)
5898 	{
5899 	    free_string_option(*varp);
5900 	    *varp = empty_option;
5901 	}
5902 # ifdef FEAT_EVAL
5903 	if (set_sid != SID_NONE)
5904 	{
5905 	    sctx_T script_ctx;
5906 
5907 	    if (set_sid == 0)
5908 		script_ctx = current_sctx;
5909 	    else
5910 	    {
5911 		script_ctx.sc_sid = set_sid;
5912 		script_ctx.sc_seq = 0;
5913 		script_ctx.sc_lnum = 0;
5914 	    }
5915 	    set_option_sctx_idx(idx, opt_flags, script_ctx);
5916 	}
5917 # endif
5918     }
5919 }
5920 
5921 /*
5922  * Set global value for string option when it's a local option.
5923  */
5924     static void
5925 set_string_option_global(
5926     int		opt_idx,	/* option index */
5927     char_u	**varp)		/* pointer to option variable */
5928 {
5929     char_u	**p, *s;
5930 
5931     /* the global value is always allocated */
5932     if (options[opt_idx].var == VAR_WIN)
5933 	p = (char_u **)GLOBAL_WO(varp);
5934     else
5935 	p = (char_u **)options[opt_idx].var;
5936     if (options[opt_idx].indir != PV_NONE
5937 	    && p != varp
5938 	    && (s = vim_strsave(*varp)) != NULL)
5939     {
5940 	free_string_option(*p);
5941 	*p = s;
5942     }
5943 }
5944 
5945 /*
5946  * Set a string option to a new value, and handle the effects.
5947  *
5948  * Returns NULL on success or error message on error.
5949  */
5950     static char *
5951 set_string_option(
5952     int		opt_idx,
5953     char_u	*value,
5954     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
5955 {
5956     char_u	*s;
5957     char_u	**varp;
5958     char_u	*oldval;
5959 #if defined(FEAT_EVAL)
5960     char_u	*saved_oldval = NULL;
5961     char_u	*saved_newval = NULL;
5962 #endif
5963     char	*r = NULL;
5964     int		value_checked = FALSE;
5965 
5966     if (options[opt_idx].var == NULL)	/* don't set hidden option */
5967 	return NULL;
5968 
5969     s = vim_strsave(value);
5970     if (s != NULL)
5971     {
5972 	varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5973 		(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5974 		    ? (((int)options[opt_idx].indir & PV_BOTH)
5975 			? OPT_GLOBAL : OPT_LOCAL)
5976 		    : opt_flags);
5977 	oldval = *varp;
5978 	*varp = s;
5979 
5980 #if defined(FEAT_EVAL)
5981 	if (!starting
5982 # ifdef FEAT_CRYPT
5983 		&& options[opt_idx].indir != PV_KEY
5984 # endif
5985 		)
5986 	{
5987 	    saved_oldval = vim_strsave(oldval);
5988 	    saved_newval = vim_strsave(s);
5989 	}
5990 #endif
5991 	if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5992 					   opt_flags, &value_checked)) == NULL)
5993 	    did_set_option(opt_idx, opt_flags, TRUE, value_checked);
5994 
5995 #if defined(FEAT_EVAL)
5996 	/* call autocommand after handling side effects */
5997 	if (r == NULL)
5998 	    trigger_optionsset_string(opt_idx, opt_flags,
5999 						   saved_oldval, saved_newval);
6000 	vim_free(saved_oldval);
6001 	vim_free(saved_newval);
6002 #endif
6003     }
6004     return r;
6005 }
6006 
6007 /*
6008  * Return TRUE if "val" is a valid 'filetype' name.
6009  * Also used for 'syntax' and 'keymap'.
6010  */
6011     static int
6012 valid_filetype(char_u *val)
6013 {
6014     char_u *s;
6015 
6016     for (s = val; *s != NUL; ++s)
6017 	if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6018 	    return FALSE;
6019     return TRUE;
6020 }
6021 
6022 /*
6023  * Handle string options that need some action to perform when changed.
6024  * Returns NULL for success, or an error message for an error.
6025  */
6026     static char *
6027 did_set_string_option(
6028     int		opt_idx,		// index in options[] table
6029     char_u	**varp,			// pointer to the option variable
6030     int		new_value_alloced,	// new value was allocated
6031     char_u	*oldval,		// previous value of the option
6032     char	*errbuf,		// buffer for errors, or NULL
6033     int		opt_flags,		// OPT_LOCAL and/or OPT_GLOBAL
6034     int		*value_checked)		// value was checked to be save, no
6035 					// need to set P_INSECURE
6036 {
6037     char	*errmsg = NULL;
6038     char_u	*s, *p;
6039     int		did_chartab = FALSE;
6040     char_u	**gvarp;
6041     long_u	free_oldval = (options[opt_idx].flags & P_ALLOCED);
6042 #ifdef FEAT_GUI
6043     /* set when changing an option that only requires a redraw in the GUI */
6044     int		redraw_gui_only = FALSE;
6045 #endif
6046     int		value_changed = FALSE;
6047 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6048     int		did_swaptcap = FALSE;
6049 #endif
6050 
6051     /* Get the global option to compare with, otherwise we would have to check
6052      * two values for all local options. */
6053     gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6054 
6055     /* Disallow changing some options from secure mode */
6056     if ((secure
6057 #ifdef HAVE_SANDBOX
6058 		|| sandbox != 0
6059 #endif
6060 		) && (options[opt_idx].flags & P_SECURE))
6061     {
6062 	errmsg = e_secure;
6063     }
6064 
6065     // Check for a "normal" directory or file name in some options.  Disallow a
6066     // path separator (slash and/or backslash), wildcards and characters that
6067     // are often illegal in a file name. Be more permissive if "secure" is off.
6068     else if (((options[opt_idx].flags & P_NFNAME)
6069 		    && vim_strpbrk(*varp, (char_u *)(secure
6070 			    ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
6071 	  || ((options[opt_idx].flags & P_NDNAME)
6072 		    && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
6073     {
6074 	errmsg = e_invarg;
6075     }
6076 
6077     /* 'term' */
6078     else if (varp == &T_NAME)
6079     {
6080 	if (T_NAME[0] == NUL)
6081 	    errmsg = N_("E529: Cannot set 'term' to empty string");
6082 #ifdef FEAT_GUI
6083 	if (gui.in_use)
6084 	    errmsg = N_("E530: Cannot change term in GUI");
6085 	else if (term_is_gui(T_NAME))
6086 	    errmsg = N_("E531: Use \":gui\" to start the GUI");
6087 #endif
6088 	else if (set_termname(T_NAME) == FAIL)
6089 	    errmsg = N_("E522: Not found in termcap");
6090 	else
6091 	{
6092 	    /* Screen colors may have changed. */
6093 	    redraw_later_clear();
6094 
6095 	    /* Both 'term' and 'ttytype' point to T_NAME, only set the
6096 	     * P_ALLOCED flag on 'term'. */
6097 	    opt_idx = findoption((char_u *)"term");
6098 	    free_oldval = (options[opt_idx].flags & P_ALLOCED);
6099 	}
6100     }
6101 
6102     /* 'backupcopy' */
6103     else if (gvarp == &p_bkc)
6104     {
6105 	char_u		*bkc = p_bkc;
6106 	unsigned int	*flags = &bkc_flags;
6107 
6108 	if (opt_flags & OPT_LOCAL)
6109 	{
6110 	    bkc = curbuf->b_p_bkc;
6111 	    flags = &curbuf->b_bkc_flags;
6112 	}
6113 
6114 	if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6115 	    /* make the local value empty: use the global value */
6116 	    *flags = 0;
6117 	else
6118 	{
6119 	    if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6120 		errmsg = e_invarg;
6121 	    if ((((int)*flags & BKC_AUTO) != 0)
6122 		    + (((int)*flags & BKC_YES) != 0)
6123 		    + (((int)*flags & BKC_NO) != 0) != 1)
6124 	    {
6125 		/* Must have exactly one of "auto", "yes"  and "no". */
6126 		(void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6127 		errmsg = e_invarg;
6128 	    }
6129 	}
6130     }
6131 
6132     /* 'backupext' and 'patchmode' */
6133     else if (varp == &p_bex || varp == &p_pm)
6134     {
6135 	if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6136 		     *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6137 	    errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
6138     }
6139 #ifdef FEAT_LINEBREAK
6140     /* 'breakindentopt' */
6141     else if (varp == &curwin->w_p_briopt)
6142     {
6143 	if (briopt_check(curwin) == FAIL)
6144 	    errmsg = e_invarg;
6145     }
6146 #endif
6147 
6148     /*
6149      * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
6150      * If the new option is invalid, use old value.  'lisp' option: refill
6151      * g_chartab[] for '-' char
6152      */
6153     else if (  varp == &p_isi
6154 	    || varp == &(curbuf->b_p_isk)
6155 	    || varp == &p_isp
6156 	    || varp == &p_isf)
6157     {
6158 	if (init_chartab() == FAIL)
6159 	{
6160 	    did_chartab = TRUE;	    /* need to restore it below */
6161 	    errmsg = e_invarg;	    /* error in value */
6162 	}
6163     }
6164 
6165     /* 'helpfile' */
6166     else if (varp == &p_hf)
6167     {
6168 	/* May compute new values for $VIM and $VIMRUNTIME */
6169 	if (didset_vim)
6170 	{
6171 	    vim_setenv((char_u *)"VIM", (char_u *)"");
6172 	    didset_vim = FALSE;
6173 	}
6174 	if (didset_vimruntime)
6175 	{
6176 	    vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6177 	    didset_vimruntime = FALSE;
6178 	}
6179     }
6180 
6181 #ifdef FEAT_SYN_HL
6182     /* 'colorcolumn' */
6183     else if (varp == &curwin->w_p_cc)
6184 	errmsg = check_colorcolumn(curwin);
6185 #endif
6186 
6187 #ifdef FEAT_MULTI_LANG
6188     /* 'helplang' */
6189     else if (varp == &p_hlg)
6190     {
6191 	/* Check for "", "ab", "ab,cd", etc. */
6192 	for (s = p_hlg; *s != NUL; s += 3)
6193 	{
6194 	    if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6195 	    {
6196 		errmsg = e_invarg;
6197 		break;
6198 	    }
6199 	    if (s[2] == NUL)
6200 		break;
6201 	}
6202     }
6203 #endif
6204 
6205     /* 'highlight' */
6206     else if (varp == &p_hl)
6207     {
6208 	if (highlight_changed() == FAIL)
6209 	    errmsg = e_invarg;	/* invalid flags */
6210     }
6211 
6212     /* 'nrformats' */
6213     else if (gvarp == &p_nf)
6214     {
6215 	if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6216 	    errmsg = e_invarg;
6217     }
6218 
6219 #ifdef FEAT_SESSION
6220     /* 'sessionoptions' */
6221     else if (varp == &p_ssop)
6222     {
6223 	if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6224 	    errmsg = e_invarg;
6225 	if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6226 	{
6227 	    /* Don't allow both "sesdir" and "curdir". */
6228 	    (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6229 	    errmsg = e_invarg;
6230 	}
6231     }
6232     /* 'viewoptions' */
6233     else if (varp == &p_vop)
6234     {
6235 	if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6236 	    errmsg = e_invarg;
6237     }
6238 #endif
6239 
6240     /* 'scrollopt' */
6241     else if (varp == &p_sbo)
6242     {
6243 	if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6244 	    errmsg = e_invarg;
6245     }
6246 
6247     /* 'ambiwidth' */
6248     else if (varp == &p_ambw || varp == &p_emoji)
6249     {
6250 	if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6251 	    errmsg = e_invarg;
6252 	else if (set_chars_option(&p_lcs) != NULL)
6253 	    errmsg = _("E834: Conflicts with value of 'listchars'");
6254 	else if (set_chars_option(&p_fcs) != NULL)
6255 	    errmsg = _("E835: Conflicts with value of 'fillchars'");
6256     }
6257 
6258     /* 'background' */
6259     else if (varp == &p_bg)
6260     {
6261 	if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6262 	{
6263 #ifdef FEAT_EVAL
6264 	    int dark = (*p_bg == 'd');
6265 #endif
6266 
6267 	    init_highlight(FALSE, FALSE);
6268 
6269 #ifdef FEAT_EVAL
6270 	    if (dark != (*p_bg == 'd')
6271 			  && get_var_value((char_u *)"g:colors_name") != NULL)
6272 	    {
6273 		/* The color scheme must have set 'background' back to another
6274 		 * value, that's not what we want here.  Disable the color
6275 		 * scheme and set the colors again. */
6276 		do_unlet((char_u *)"g:colors_name", TRUE);
6277 		free_string_option(p_bg);
6278 		p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6279 		check_string_option(&p_bg);
6280 		init_highlight(FALSE, FALSE);
6281 	    }
6282 #endif
6283 	}
6284 	else
6285 	    errmsg = e_invarg;
6286     }
6287 
6288     /* 'wildmode' */
6289     else if (varp == &p_wim)
6290     {
6291 	if (check_opt_wim() == FAIL)
6292 	    errmsg = e_invarg;
6293     }
6294 
6295 #ifdef FEAT_CMDL_COMPL
6296     /* 'wildoptions' */
6297     else if (varp == &p_wop)
6298     {
6299 	if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6300 	    errmsg = e_invarg;
6301     }
6302 #endif
6303 
6304 #ifdef FEAT_WAK
6305     /* 'winaltkeys' */
6306     else if (varp == &p_wak)
6307     {
6308 	if (*p_wak == NUL
6309 		|| check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6310 	    errmsg = e_invarg;
6311 # ifdef FEAT_MENU
6312 #  ifdef FEAT_GUI_MOTIF
6313 	else if (gui.in_use)
6314 	    gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6315 #  else
6316 #   ifdef FEAT_GUI_GTK
6317 	else if (gui.in_use)
6318 	    gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6319 #   endif
6320 #  endif
6321 # endif
6322     }
6323 #endif
6324 
6325     /* 'eventignore' */
6326     else if (varp == &p_ei)
6327     {
6328 	if (check_ei() == FAIL)
6329 	    errmsg = e_invarg;
6330     }
6331 
6332     /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6333     else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6334 							   || gvarp == &p_menc)
6335     {
6336 	if (gvarp == &p_fenc)
6337 	{
6338 	    if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
6339 		errmsg = e_modifiable;
6340 	    else if (vim_strchr(*varp, ',') != NULL)
6341 		/* No comma allowed in 'fileencoding'; catches confusing it
6342 		 * with 'fileencodings'. */
6343 		errmsg = e_invarg;
6344 	    else
6345 	    {
6346 #ifdef FEAT_TITLE
6347 		/* May show a "+" in the title now. */
6348 		redraw_titles();
6349 #endif
6350 		/* Add 'fileencoding' to the swap file. */
6351 		ml_setflags(curbuf);
6352 	    }
6353 	}
6354 	if (errmsg == NULL)
6355 	{
6356 	    /* canonize the value, so that STRCMP() can be used on it */
6357 	    p = enc_canonize(*varp);
6358 	    if (p != NULL)
6359 	    {
6360 		vim_free(*varp);
6361 		*varp = p;
6362 	    }
6363 	    if (varp == &p_enc)
6364 	    {
6365 		errmsg = mb_init();
6366 #ifdef FEAT_TITLE
6367 		redraw_titles();
6368 #endif
6369 	    }
6370 	}
6371 
6372 #if defined(FEAT_GUI_GTK)
6373 	if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6374 	{
6375 	    /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6376 	    if (STRCMP(p_tenc, "utf-8") != 0)
6377 		errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
6378 	}
6379 #endif
6380 
6381 	if (errmsg == NULL)
6382 	{
6383 #ifdef FEAT_KEYMAP
6384 	    /* When 'keymap' is used and 'encoding' changes, reload the keymap
6385 	     * (with another encoding). */
6386 	    if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6387 		(void)keymap_init();
6388 #endif
6389 
6390 	    /* When 'termencoding' is not empty and 'encoding' changes or when
6391 	     * 'termencoding' changes, need to setup for keyboard input and
6392 	     * display output conversion. */
6393 	    if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6394 	    {
6395 		if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6396 			|| convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6397 		{
6398 		    semsg(_("E950: Cannot convert between %s and %s"),
6399 			    p_tenc, p_enc);
6400 		    errmsg = e_invarg;
6401 		}
6402 	    }
6403 
6404 #if defined(MSWIN)
6405 	    /* $HOME may have characters in active code page. */
6406 	    if (varp == &p_enc)
6407 		init_homedir();
6408 #endif
6409 	}
6410     }
6411 
6412 #if defined(FEAT_POSTSCRIPT)
6413     else if (varp == &p_penc)
6414     {
6415 	/* Canonize printencoding if VIM standard one */
6416 	p = enc_canonize(p_penc);
6417 	if (p != NULL)
6418 	{
6419 	    vim_free(p_penc);
6420 	    p_penc = p;
6421 	}
6422 	else
6423 	{
6424 	    /* Ensure lower case and '-' for '_' */
6425 	    for (s = p_penc; *s != NUL; s++)
6426 	    {
6427 		if (*s == '_')
6428 		    *s = '-';
6429 		else
6430 		    *s = TOLOWER_ASC(*s);
6431 	    }
6432 	}
6433     }
6434 #endif
6435 
6436 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
6437     else if (varp == &p_imak)
6438     {
6439 	if (!im_xim_isvalid_imactivate())
6440 	    errmsg = e_invarg;
6441     }
6442 #endif
6443 
6444 #ifdef FEAT_KEYMAP
6445     else if (varp == &curbuf->b_p_keymap)
6446     {
6447 	if (!valid_filetype(*varp))
6448 	    errmsg = e_invarg;
6449 	else
6450 	{
6451 	    int	    secure_save = secure;
6452 
6453 	    // Reset the secure flag, since the value of 'keymap' has
6454 	    // been checked to be safe.
6455 	    secure = 0;
6456 
6457 	    // load or unload key mapping tables
6458 	    errmsg = keymap_init();
6459 
6460 	    secure = secure_save;
6461 
6462 	    // Since we check the value, there is no need to set P_INSECURE,
6463 	    // even when the value comes from a modeline.
6464 	    *value_checked = TRUE;
6465 	}
6466 
6467 	if (errmsg == NULL)
6468 	{
6469 	    if (*curbuf->b_p_keymap != NUL)
6470 	    {
6471 		/* Installed a new keymap, switch on using it. */
6472 		curbuf->b_p_iminsert = B_IMODE_LMAP;
6473 		if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6474 		    curbuf->b_p_imsearch = B_IMODE_LMAP;
6475 	    }
6476 	    else
6477 	    {
6478 		/* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6479 		if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6480 		    curbuf->b_p_iminsert = B_IMODE_NONE;
6481 		if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6482 		    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6483 	    }
6484 	    if ((opt_flags & OPT_LOCAL) == 0)
6485 	    {
6486 		set_iminsert_global();
6487 		set_imsearch_global();
6488 	    }
6489 	    status_redraw_curbuf();
6490 	}
6491     }
6492 #endif
6493 
6494     /* 'fileformat' */
6495     else if (gvarp == &p_ff)
6496     {
6497 	if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6498 	    errmsg = e_modifiable;
6499 	else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6500 	    errmsg = e_invarg;
6501 	else
6502 	{
6503 	    /* may also change 'textmode' */
6504 	    if (get_fileformat(curbuf) == EOL_DOS)
6505 		curbuf->b_p_tx = TRUE;
6506 	    else
6507 		curbuf->b_p_tx = FALSE;
6508 #ifdef FEAT_TITLE
6509 	    redraw_titles();
6510 #endif
6511 	    /* update flag in swap file */
6512 	    ml_setflags(curbuf);
6513 	    /* Redraw needed when switching to/from "mac": a CR in the text
6514 	     * will be displayed differently. */
6515 	    if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6516 		redraw_curbuf_later(NOT_VALID);
6517 	}
6518     }
6519 
6520     /* 'fileformats' */
6521     else if (varp == &p_ffs)
6522     {
6523 	if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6524 	    errmsg = e_invarg;
6525 	else
6526 	{
6527 	    /* also change 'textauto' */
6528 	    if (*p_ffs == NUL)
6529 		p_ta = FALSE;
6530 	    else
6531 		p_ta = TRUE;
6532 	}
6533     }
6534 
6535 #if defined(FEAT_CRYPT)
6536     /* 'cryptkey' */
6537     else if (gvarp == &p_key)
6538     {
6539 # if defined(FEAT_CMDHIST)
6540 	/* Make sure the ":set" command doesn't show the new value in the
6541 	 * history. */
6542 	remove_key_from_history();
6543 # endif
6544 	if (STRCMP(curbuf->b_p_key, oldval) != 0)
6545 	    /* Need to update the swapfile. */
6546 	    ml_set_crypt_key(curbuf, oldval,
6547 			      *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
6548     }
6549 
6550     else if (gvarp == &p_cm)
6551     {
6552 	if (opt_flags & OPT_LOCAL)
6553 	    p = curbuf->b_p_cm;
6554 	else
6555 	    p = p_cm;
6556 	if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6557 	    errmsg = e_invarg;
6558 	else if (crypt_self_test() == FAIL)
6559 	    errmsg = e_invarg;
6560 	else
6561 	{
6562 	    /* When setting the global value to empty, make it "zip". */
6563 	    if (*p_cm == NUL)
6564 	    {
6565 		if (new_value_alloced)
6566 		    free_string_option(p_cm);
6567 		p_cm = vim_strsave((char_u *)"zip");
6568 		new_value_alloced = TRUE;
6569 	    }
6570 	    /* When using ":set cm=name" the local value is going to be empty.
6571 	     * Do that here, otherwise the crypt functions will still use the
6572 	     * local value. */
6573 	    if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6574 	    {
6575 		free_string_option(curbuf->b_p_cm);
6576 		curbuf->b_p_cm = empty_option;
6577 	    }
6578 
6579 	    /* Need to update the swapfile when the effective method changed.
6580 	     * Set "s" to the effective old value, "p" to the effective new
6581 	     * method and compare. */
6582 	    if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6583 		s = p_cm;  /* was previously using the global value */
6584 	    else
6585 		s = oldval;
6586 	    if (*curbuf->b_p_cm == NUL)
6587 		p = p_cm;  /* is now using the global value */
6588 	    else
6589 		p = curbuf->b_p_cm;
6590 	    if (STRCMP(s, p) != 0)
6591 		ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
6592 
6593 	    /* If the global value changes need to update the swapfile for all
6594 	     * buffers using that value. */
6595 	    if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6596 	    {
6597 		buf_T	*buf;
6598 
6599 		FOR_ALL_BUFFERS(buf)
6600 		    if (buf != curbuf && *buf->b_p_cm == NUL)
6601 			ml_set_crypt_key(buf, buf->b_p_key, oldval);
6602 	    }
6603 	}
6604     }
6605 #endif
6606 
6607     /* 'matchpairs' */
6608     else if (gvarp == &p_mps)
6609     {
6610 	if (has_mbyte)
6611 	{
6612 	    for (p = *varp; *p != NUL; ++p)
6613 	    {
6614 		int x2 = -1;
6615 		int x3 = -1;
6616 
6617 		if (*p != NUL)
6618 		    p += mb_ptr2len(p);
6619 		if (*p != NUL)
6620 		    x2 = *p++;
6621 		if (*p != NUL)
6622 		{
6623 		    x3 = mb_ptr2char(p);
6624 		    p += mb_ptr2len(p);
6625 		}
6626 		if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
6627 		{
6628 		    errmsg = e_invarg;
6629 		    break;
6630 		}
6631 		if (*p == NUL)
6632 		    break;
6633 	    }
6634 	}
6635 	else
6636 	{
6637 	    /* Check for "x:y,x:y" */
6638 	    for (p = *varp; *p != NUL; p += 4)
6639 	    {
6640 		if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6641 		{
6642 		    errmsg = e_invarg;
6643 		    break;
6644 		}
6645 		if (p[3] == NUL)
6646 		    break;
6647 	    }
6648 	}
6649     }
6650 
6651 #ifdef FEAT_COMMENTS
6652     /* 'comments' */
6653     else if (gvarp == &p_com)
6654     {
6655 	for (s = *varp; *s; )
6656 	{
6657 	    while (*s && *s != ':')
6658 	    {
6659 		if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6660 					     && !VIM_ISDIGIT(*s) && *s != '-')
6661 		{
6662 		    errmsg = illegal_char(errbuf, *s);
6663 		    break;
6664 		}
6665 		++s;
6666 	    }
6667 	    if (*s++ == NUL)
6668 		errmsg = N_("E524: Missing colon");
6669 	    else if (*s == ',' || *s == NUL)
6670 		errmsg = N_("E525: Zero length string");
6671 	    if (errmsg != NULL)
6672 		break;
6673 	    while (*s && *s != ',')
6674 	    {
6675 		if (*s == '\\' && s[1] != NUL)
6676 		    ++s;
6677 		++s;
6678 	    }
6679 	    s = skip_to_option_part(s);
6680 	}
6681     }
6682 #endif
6683 
6684     /* 'listchars' */
6685     else if (varp == &p_lcs)
6686     {
6687 	errmsg = set_chars_option(varp);
6688     }
6689 
6690     /* 'fillchars' */
6691     else if (varp == &p_fcs)
6692     {
6693 	errmsg = set_chars_option(varp);
6694     }
6695 
6696 #ifdef FEAT_CMDWIN
6697     /* 'cedit' */
6698     else if (varp == &p_cedit)
6699     {
6700 	errmsg = check_cedit();
6701     }
6702 #endif
6703 
6704     /* 'verbosefile' */
6705     else if (varp == &p_vfile)
6706     {
6707 	verbose_stop();
6708 	if (*p_vfile != NUL && verbose_open() == FAIL)
6709 	    errmsg = e_invarg;
6710     }
6711 
6712 #ifdef FEAT_VIMINFO
6713     /* 'viminfo' */
6714     else if (varp == &p_viminfo)
6715     {
6716 	for (s = p_viminfo; *s;)
6717 	{
6718 	    /* Check it's a valid character */
6719 	    if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6720 	    {
6721 		errmsg = illegal_char(errbuf, *s);
6722 		break;
6723 	    }
6724 	    if (*s == 'n')	/* name is always last one */
6725 	    {
6726 		break;
6727 	    }
6728 	    else if (*s == 'r') /* skip until next ',' */
6729 	    {
6730 		while (*++s && *s != ',')
6731 		    ;
6732 	    }
6733 	    else if (*s == '%')
6734 	    {
6735 		/* optional number */
6736 		while (vim_isdigit(*++s))
6737 		    ;
6738 	    }
6739 	    else if (*s == '!' || *s == 'h' || *s == 'c')
6740 		++s;		/* no extra chars */
6741 	    else		/* must have a number */
6742 	    {
6743 		while (vim_isdigit(*++s))
6744 		    ;
6745 
6746 		if (!VIM_ISDIGIT(*(s - 1)))
6747 		{
6748 		    if (errbuf != NULL)
6749 		    {
6750 			sprintf(errbuf, _("E526: Missing number after <%s>"),
6751 						    transchar_byte(*(s - 1)));
6752 			errmsg = errbuf;
6753 		    }
6754 		    else
6755 			errmsg = "";
6756 		    break;
6757 		}
6758 	    }
6759 	    if (*s == ',')
6760 		++s;
6761 	    else if (*s)
6762 	    {
6763 		if (errbuf != NULL)
6764 		    errmsg = N_("E527: Missing comma");
6765 		else
6766 		    errmsg = "";
6767 		break;
6768 	    }
6769 	}
6770 	if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6771 	    errmsg = N_("E528: Must specify a ' value");
6772     }
6773 #endif /* FEAT_VIMINFO */
6774 
6775     /* terminal options */
6776     else if (istermoption(&options[opt_idx]) && full_screen)
6777     {
6778 	/* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6779 	if (varp == &T_CCO)
6780 	{
6781 	    int colors = atoi((char *)T_CCO);
6782 
6783 	    /* Only reinitialize colors if t_Co value has really changed to
6784 	     * avoid expensive reload of colorscheme if t_Co is set to the
6785 	     * same value multiple times. */
6786 	    if (colors != t_colors)
6787 	    {
6788 		t_colors = colors;
6789 		if (t_colors <= 1)
6790 		{
6791 		    if (new_value_alloced)
6792 			vim_free(T_CCO);
6793 		    T_CCO = empty_option;
6794 		}
6795 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6796 		if (is_term_win32())
6797 		{
6798 		    swap_tcap();
6799 		    did_swaptcap = TRUE;
6800 		}
6801 #endif
6802 		/* We now have a different color setup, initialize it again. */
6803 		init_highlight(TRUE, FALSE);
6804 	    }
6805 	}
6806 	ttest(FALSE);
6807 	if (varp == &T_ME)
6808 	{
6809 	    out_str(T_ME);
6810 	    redraw_later(CLEAR);
6811 #if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
6812 	    /* Since t_me has been set, this probably means that the user
6813 	     * wants to use this as default colors.  Need to reset default
6814 	     * background/foreground colors. */
6815 	    mch_set_normal_colors();
6816 #endif
6817 	}
6818 	if (varp == &T_BE && termcap_active)
6819 	{
6820 	    if (*T_BE == NUL)
6821 		/* When clearing t_BE we assume the user no longer wants
6822 		 * bracketed paste, thus disable it by writing t_BD. */
6823 		out_str(T_BD);
6824 	    else
6825 		out_str(T_BE);
6826 	}
6827     }
6828 
6829 #ifdef FEAT_LINEBREAK
6830     /* 'showbreak' */
6831     else if (varp == &p_sbr)
6832     {
6833 	for (s = p_sbr; *s; )
6834 	{
6835 	    if (ptr2cells(s) != 1)
6836 		errmsg = N_("E595: contains unprintable or wide character");
6837 	    MB_PTR_ADV(s);
6838 	}
6839     }
6840 #endif
6841 
6842 #ifdef FEAT_GUI
6843     /* 'guifont' */
6844     else if (varp == &p_guifont)
6845     {
6846 	if (gui.in_use)
6847 	{
6848 	    p = p_guifont;
6849 # if defined(FEAT_GUI_GTK)
6850 	    /*
6851 	     * Put up a font dialog and let the user select a new value.
6852 	     * If this is cancelled go back to the old value but don't
6853 	     * give an error message.
6854 	     */
6855 	    if (STRCMP(p, "*") == 0)
6856 	    {
6857 		p = gui_mch_font_dialog(oldval);
6858 
6859 		if (new_value_alloced)
6860 		    free_string_option(p_guifont);
6861 
6862 		p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6863 		new_value_alloced = TRUE;
6864 	    }
6865 # endif
6866 	    if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6867 	    {
6868 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6869 		if (STRCMP(p_guifont, "*") == 0)
6870 		{
6871 		    /* Dialog was cancelled: Keep the old value without giving
6872 		     * an error message. */
6873 		    if (new_value_alloced)
6874 			free_string_option(p_guifont);
6875 		    p_guifont = vim_strsave(oldval);
6876 		    new_value_alloced = TRUE;
6877 		}
6878 		else
6879 # endif
6880 		    errmsg = N_("E596: Invalid font(s)");
6881 	    }
6882 	}
6883 	redraw_gui_only = TRUE;
6884     }
6885 # ifdef FEAT_XFONTSET
6886     else if (varp == &p_guifontset)
6887     {
6888 	if (STRCMP(p_guifontset, "*") == 0)
6889 	    errmsg = N_("E597: can't select fontset");
6890 	else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6891 	    errmsg = N_("E598: Invalid fontset");
6892 	redraw_gui_only = TRUE;
6893     }
6894 # endif
6895     else if (varp == &p_guifontwide)
6896     {
6897 	if (STRCMP(p_guifontwide, "*") == 0)
6898 	    errmsg = N_("E533: can't select wide font");
6899 	else if (gui_get_wide_font() == FAIL)
6900 	    errmsg = N_("E534: Invalid wide font");
6901 	redraw_gui_only = TRUE;
6902     }
6903 #endif
6904 
6905 #ifdef CURSOR_SHAPE
6906     /* 'guicursor' */
6907     else if (varp == &p_guicursor)
6908 	errmsg = parse_shape_opt(SHAPE_CURSOR);
6909 #endif
6910 
6911 #ifdef FEAT_MOUSESHAPE
6912     /* 'mouseshape' */
6913     else if (varp == &p_mouseshape)
6914     {
6915 	errmsg = parse_shape_opt(SHAPE_MOUSE);
6916 	update_mouseshape(-1);
6917     }
6918 #endif
6919 
6920 #ifdef FEAT_PRINTER
6921     else if (varp == &p_popt)
6922 	errmsg = parse_printoptions();
6923 # if defined(FEAT_POSTSCRIPT)
6924     else if (varp == &p_pmfn)
6925 	errmsg = parse_printmbfont();
6926 # endif
6927 #endif
6928 
6929 #ifdef FEAT_LANGMAP
6930     /* 'langmap' */
6931     else if (varp == &p_langmap)
6932 	langmap_set();
6933 #endif
6934 
6935 #ifdef FEAT_LINEBREAK
6936     /* 'breakat' */
6937     else if (varp == &p_breakat)
6938 	fill_breakat_flags();
6939 #endif
6940 
6941 #ifdef FEAT_TITLE
6942     /* 'titlestring' and 'iconstring' */
6943     else if (varp == &p_titlestring || varp == &p_iconstring)
6944     {
6945 # ifdef FEAT_STL_OPT
6946 	int	flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6947 
6948 	/* NULL => statusline syntax */
6949 	if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6950 	    stl_syntax |= flagval;
6951 	else
6952 	    stl_syntax &= ~flagval;
6953 # endif
6954 	did_set_title();
6955     }
6956 #endif
6957 
6958 #ifdef FEAT_GUI
6959     /* 'guioptions' */
6960     else if (varp == &p_go)
6961     {
6962 	gui_init_which_components(oldval);
6963 	redraw_gui_only = TRUE;
6964     }
6965 #endif
6966 
6967 #if defined(FEAT_GUI_TABLINE)
6968     /* 'guitablabel' */
6969     else if (varp == &p_gtl)
6970     {
6971 	redraw_tabline = TRUE;
6972 	redraw_gui_only = TRUE;
6973     }
6974     /* 'guitabtooltip' */
6975     else if (varp == &p_gtt)
6976     {
6977 	redraw_gui_only = TRUE;
6978     }
6979 #endif
6980 
6981 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6982     /* 'ttymouse' */
6983     else if (varp == &p_ttym)
6984     {
6985 	/* Switch the mouse off before changing the escape sequences used for
6986 	 * that. */
6987 	mch_setmouse(FALSE);
6988 	if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6989 	    errmsg = e_invarg;
6990 	else
6991 	    check_mouse_termcode();
6992 	if (termcap_active)
6993 	    setmouse();		/* may switch it on again */
6994     }
6995 #endif
6996 
6997     /* 'selection' */
6998     else if (varp == &p_sel)
6999     {
7000 	if (*p_sel == NUL
7001 		|| check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7002 	    errmsg = e_invarg;
7003     }
7004 
7005     /* 'selectmode' */
7006     else if (varp == &p_slm)
7007     {
7008 	if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7009 	    errmsg = e_invarg;
7010     }
7011 
7012 #ifdef FEAT_BROWSE
7013     /* 'browsedir' */
7014     else if (varp == &p_bsdir)
7015     {
7016 	if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7017 		&& !mch_isdir(p_bsdir))
7018 	    errmsg = e_invarg;
7019     }
7020 #endif
7021 
7022     /* 'keymodel' */
7023     else if (varp == &p_km)
7024     {
7025 	if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7026 	    errmsg = e_invarg;
7027 	else
7028 	{
7029 	    km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7030 	    km_startsel = (vim_strchr(p_km, 'a') != NULL);
7031 	}
7032     }
7033 
7034     /* 'mousemodel' */
7035     else if (varp == &p_mousem)
7036     {
7037 	if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7038 	    errmsg = e_invarg;
7039 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7040 	else if (*p_mousem != *oldval)
7041 	    /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7042 	     * to create or delete the popup menus. */
7043 	    gui_motif_update_mousemodel(root_menu);
7044 #endif
7045     }
7046 
7047     /* 'switchbuf' */
7048     else if (varp == &p_swb)
7049     {
7050 	if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
7051 	    errmsg = e_invarg;
7052     }
7053 
7054     /* 'debug' */
7055     else if (varp == &p_debug)
7056     {
7057 	if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
7058 	    errmsg = e_invarg;
7059     }
7060 
7061     /* 'display' */
7062     else if (varp == &p_dy)
7063     {
7064 	if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7065 	    errmsg = e_invarg;
7066 	else
7067 	    (void)init_chartab();
7068 
7069     }
7070 
7071     /* 'eadirection' */
7072     else if (varp == &p_ead)
7073     {
7074 	if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7075 	    errmsg = e_invarg;
7076     }
7077 
7078 #ifdef FEAT_CLIPBOARD
7079     /* 'clipboard' */
7080     else if (varp == &p_cb)
7081 	errmsg = check_clipboard_option();
7082 #endif
7083 
7084 #ifdef FEAT_SPELL
7085     /* When 'spelllang' or 'spellfile' is set and there is a window for this
7086      * buffer in which 'spell' is set load the wordlists. */
7087     else if (varp == &(curwin->w_s->b_p_spl)
7088 	    || varp == &(curwin->w_s->b_p_spf))
7089     {
7090 	errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
7091     }
7092     /* When 'spellcapcheck' is set compile the regexp program. */
7093     else if (varp == &(curwin->w_s->b_p_spc))
7094     {
7095 	errmsg = compile_cap_prog(curwin->w_s);
7096     }
7097     /* 'spellsuggest' */
7098     else if (varp == &p_sps)
7099     {
7100 	if (spell_check_sps() != OK)
7101 	    errmsg = e_invarg;
7102     }
7103     /* 'mkspellmem' */
7104     else if (varp == &p_msm)
7105     {
7106 	if (spell_check_msm() != OK)
7107 	    errmsg = e_invarg;
7108     }
7109 #endif
7110 
7111     /* When 'bufhidden' is set, check for valid value. */
7112     else if (gvarp == &p_bh)
7113     {
7114 	if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7115 	    errmsg = e_invarg;
7116     }
7117 
7118     /* When 'buftype' is set, check for valid value. */
7119     else if (gvarp == &p_bt)
7120     {
7121 	if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7122 	    errmsg = e_invarg;
7123 	else
7124 	{
7125 	    if (curwin->w_status_height)
7126 	    {
7127 		curwin->w_redr_status = TRUE;
7128 		redraw_later(VALID);
7129 	    }
7130 	    curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
7131 #ifdef FEAT_TITLE
7132 	    redraw_titles();
7133 #endif
7134 	}
7135     }
7136 
7137 #ifdef FEAT_STL_OPT
7138     /* 'statusline' or 'rulerformat' */
7139     else if (gvarp == &p_stl || varp == &p_ruf)
7140     {
7141 	int wid;
7142 
7143 	if (varp == &p_ruf)	/* reset ru_wid first */
7144 	    ru_wid = 0;
7145 	s = *varp;
7146 	if (varp == &p_ruf && *s == '%')
7147 	{
7148 	    /* set ru_wid if 'ruf' starts with "%99(" */
7149 	    if (*++s == '-')	/* ignore a '-' */
7150 		s++;
7151 	    wid = getdigits(&s);
7152 	    if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7153 		ru_wid = wid;
7154 	    else
7155 		errmsg = check_stl_option(p_ruf);
7156 	}
7157 	/* check 'statusline' only if it doesn't start with "%!" */
7158 	else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
7159 	    errmsg = check_stl_option(s);
7160 	if (varp == &p_ruf && errmsg == NULL)
7161 	    comp_col();
7162     }
7163 #endif
7164 
7165 #ifdef FEAT_INS_EXPAND
7166     /* check if it is a valid value for 'complete' -- Acevedo */
7167     else if (gvarp == &p_cpt)
7168     {
7169 	for (s = *varp; *s;)
7170 	{
7171 	    while (*s == ',' || *s == ' ')
7172 		s++;
7173 	    if (!*s)
7174 		break;
7175 	    if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7176 	    {
7177 		errmsg = illegal_char(errbuf, *s);
7178 		break;
7179 	    }
7180 	    if (*++s != NUL && *s != ',' && *s != ' ')
7181 	    {
7182 		if (s[-1] == 'k' || s[-1] == 's')
7183 		{
7184 		    /* skip optional filename after 'k' and 's' */
7185 		    while (*s && *s != ',' && *s != ' ')
7186 		    {
7187 			if (*s == '\\' && s[1] != NUL)
7188 			    ++s;
7189 			++s;
7190 		    }
7191 		}
7192 		else
7193 		{
7194 		    if (errbuf != NULL)
7195 		    {
7196 			sprintf((char *)errbuf,
7197 				     _("E535: Illegal character after <%c>"),
7198 				     *--s);
7199 			errmsg = errbuf;
7200 		    }
7201 		    else
7202 			errmsg = "";
7203 		    break;
7204 		}
7205 	    }
7206 	}
7207     }
7208 
7209     /* 'completeopt' */
7210     else if (varp == &p_cot)
7211     {
7212 	if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7213 	    errmsg = e_invarg;
7214 	else
7215 	    completeopt_was_set();
7216     }
7217 #endif /* FEAT_INS_EXPAND */
7218 
7219 #ifdef FEAT_SIGNS
7220     /* 'signcolumn' */
7221     else if (varp == &curwin->w_p_scl)
7222     {
7223 	if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7224 	    errmsg = e_invarg;
7225     }
7226 #endif
7227 
7228 
7229 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
7230     /* 'toolbar' */
7231     else if (varp == &p_toolbar)
7232     {
7233 	if (opt_strings_flags(p_toolbar, p_toolbar_values,
7234 			      &toolbar_flags, TRUE) != OK)
7235 	    errmsg = e_invarg;
7236 	else
7237 	{
7238 	    out_flush();
7239 	    gui_mch_show_toolbar((toolbar_flags &
7240 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7241 	}
7242     }
7243 #endif
7244 
7245 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
7246     /* 'toolbariconsize': GTK+ 2 only */
7247     else if (varp == &p_tbis)
7248     {
7249 	if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7250 	    errmsg = e_invarg;
7251 	else
7252 	{
7253 	    out_flush();
7254 	    gui_mch_show_toolbar((toolbar_flags &
7255 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7256 	}
7257     }
7258 #endif
7259 
7260     /* 'pastetoggle': translate key codes like in a mapping */
7261     else if (varp == &p_pt)
7262     {
7263 	if (*p_pt)
7264 	{
7265 	    (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
7266 	    if (p != NULL)
7267 	    {
7268 		if (new_value_alloced)
7269 		    free_string_option(p_pt);
7270 		p_pt = p;
7271 		new_value_alloced = TRUE;
7272 	    }
7273 	}
7274     }
7275 
7276     /* 'backspace' */
7277     else if (varp == &p_bs)
7278     {
7279 	if (VIM_ISDIGIT(*p_bs))
7280 	{
7281 	    if (*p_bs > '2' || p_bs[1] != NUL)
7282 		errmsg = e_invarg;
7283 	}
7284 	else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7285 	    errmsg = e_invarg;
7286     }
7287     else if (varp == &p_bo)
7288     {
7289 	if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7290 	    errmsg = e_invarg;
7291     }
7292 
7293     /* 'tagcase' */
7294     else if (gvarp == &p_tc)
7295     {
7296 	unsigned int	*flags;
7297 
7298 	if (opt_flags & OPT_LOCAL)
7299 	{
7300 	    p = curbuf->b_p_tc;
7301 	    flags = &curbuf->b_tc_flags;
7302 	}
7303 	else
7304 	{
7305 	    p = p_tc;
7306 	    flags = &tc_flags;
7307 	}
7308 
7309 	if ((opt_flags & OPT_LOCAL) && *p == NUL)
7310 	    /* make the local value empty: use the global value */
7311 	    *flags = 0;
7312 	else if (*p == NUL
7313 		|| opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7314 	    errmsg = e_invarg;
7315     }
7316 
7317     /* 'casemap' */
7318     else if (varp == &p_cmp)
7319     {
7320 	if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7321 	    errmsg = e_invarg;
7322     }
7323 
7324 #ifdef FEAT_DIFF
7325     /* 'diffopt' */
7326     else if (varp == &p_dip)
7327     {
7328 	if (diffopt_changed() == FAIL)
7329 	    errmsg = e_invarg;
7330     }
7331 #endif
7332 
7333 #ifdef FEAT_FOLDING
7334     /* 'foldmethod' */
7335     else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7336     {
7337 	if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7338 		|| *curwin->w_p_fdm == NUL)
7339 	    errmsg = e_invarg;
7340 	else
7341 	{
7342 	    foldUpdateAll(curwin);
7343 	    if (foldmethodIsDiff(curwin))
7344 		newFoldLevel();
7345 	}
7346     }
7347 # ifdef FEAT_EVAL
7348     /* 'foldexpr' */
7349     else if (varp == &curwin->w_p_fde)
7350     {
7351 	if (foldmethodIsExpr(curwin))
7352 	    foldUpdateAll(curwin);
7353     }
7354 # endif
7355     /* 'foldmarker' */
7356     else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7357     {
7358 	p = vim_strchr(*varp, ',');
7359 	if (p == NULL)
7360 	    errmsg = N_("E536: comma required");
7361 	else if (p == *varp || p[1] == NUL)
7362 	    errmsg = e_invarg;
7363 	else if (foldmethodIsMarker(curwin))
7364 	    foldUpdateAll(curwin);
7365     }
7366     /* 'commentstring' */
7367     else if (gvarp == &p_cms)
7368     {
7369 	if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7370 	    errmsg = N_("E537: 'commentstring' must be empty or contain %s");
7371     }
7372     /* 'foldopen' */
7373     else if (varp == &p_fdo)
7374     {
7375 	if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7376 	    errmsg = e_invarg;
7377     }
7378     /* 'foldclose' */
7379     else if (varp == &p_fcl)
7380     {
7381 	if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7382 	    errmsg = e_invarg;
7383     }
7384     /* 'foldignore' */
7385     else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7386     {
7387 	if (foldmethodIsIndent(curwin))
7388 	    foldUpdateAll(curwin);
7389     }
7390 #endif
7391 
7392     /* 'virtualedit' */
7393     else if (varp == &p_ve)
7394     {
7395 	if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7396 	    errmsg = e_invarg;
7397 	else if (STRCMP(p_ve, oldval) != 0)
7398 	{
7399 	    /* Recompute cursor position in case the new 've' setting
7400 	     * changes something. */
7401 	    validate_virtcol();
7402 	    coladvance(curwin->w_virtcol);
7403 	}
7404     }
7405 
7406 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7407     else if (varp == &p_csqf)
7408     {
7409 	if (p_csqf != NULL)
7410 	{
7411 	    p = p_csqf;
7412 	    while (*p != NUL)
7413 	    {
7414 		if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7415 			|| p[1] == NUL
7416 			|| vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7417 			|| (p[2] != NUL && p[2] != ','))
7418 		{
7419 		    errmsg = e_invarg;
7420 		    break;
7421 		}
7422 		else if (p[2] == NUL)
7423 		    break;
7424 		else
7425 		    p += 3;
7426 	    }
7427 	}
7428     }
7429 #endif
7430 
7431 #ifdef FEAT_CINDENT
7432     /* 'cinoptions' */
7433     else if (gvarp == &p_cino)
7434     {
7435 	/* TODO: recognize errors */
7436 	parse_cino(curbuf);
7437     }
7438 #endif
7439 
7440 #if defined(FEAT_RENDER_OPTIONS)
7441     /* 'renderoptions' */
7442     else if (varp == &p_rop)
7443     {
7444 	if (!gui_mch_set_rendering_options(p_rop))
7445 	    errmsg = e_invarg;
7446     }
7447 #endif
7448 
7449     else if (gvarp == &p_ft)
7450     {
7451 	if (!valid_filetype(*varp))
7452 	    errmsg = e_invarg;
7453 	else
7454 	{
7455 	    value_changed = STRCMP(oldval, *varp) != 0;
7456 
7457 	    // Since we check the value, there is no need to set P_INSECURE,
7458 	    // even when the value comes from a modeline.
7459 	    *value_checked = TRUE;
7460 	}
7461     }
7462 
7463 #ifdef FEAT_SYN_HL
7464     else if (gvarp == &p_syn)
7465     {
7466 	if (!valid_filetype(*varp))
7467 	    errmsg = e_invarg;
7468 	else
7469 	{
7470 	    value_changed = STRCMP(oldval, *varp) != 0;
7471 
7472 	    // Since we check the value, there is no need to set P_INSECURE,
7473 	    // even when the value comes from a modeline.
7474 	    *value_checked = TRUE;
7475 	}
7476     }
7477 #endif
7478 
7479 #ifdef FEAT_TERMINAL
7480     // 'termwinkey'
7481     else if (varp == &curwin->w_p_twk)
7482     {
7483 	if (*curwin->w_p_twk != NUL
7484 				  && string_to_key(curwin->w_p_twk, TRUE) == 0)
7485 	    errmsg = e_invarg;
7486     }
7487     // 'termwinsize'
7488     else if (varp == &curwin->w_p_tws)
7489     {
7490 	if (*curwin->w_p_tws != NUL)
7491 	{
7492 	    p = skipdigits(curwin->w_p_tws);
7493 	    if (p == curwin->w_p_tws
7494 		    || (*p != 'x' && *p != '*')
7495 		    || *skipdigits(p + 1) != NUL)
7496 		errmsg = e_invarg;
7497 	}
7498     }
7499 # if defined(MSWIN)
7500     // 'termwintype'
7501     else if (varp == &p_twt)
7502     {
7503 	if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
7504 	    errmsg = e_invarg;
7505     }
7506 # endif
7507 #endif
7508 
7509 #ifdef FEAT_VARTABS
7510     /* 'varsofttabstop' */
7511     else if (varp == &(curbuf->b_p_vsts))
7512     {
7513 	char_u *cp;
7514 
7515 	if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7516 	{
7517 	    if (curbuf->b_p_vsts_array)
7518 	    {
7519 		vim_free(curbuf->b_p_vsts_array);
7520 		curbuf->b_p_vsts_array = 0;
7521 	    }
7522 	}
7523 	else
7524 	{
7525 	    for (cp = *varp; *cp; ++cp)
7526 	    {
7527 		if (vim_isdigit(*cp))
7528 		    continue;
7529 		if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7530 		    continue;
7531 		errmsg = e_invarg;
7532 		break;
7533 	    }
7534 	    if (errmsg == NULL)
7535 	    {
7536 		int *oldarray = curbuf->b_p_vsts_array;
7537 		if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7538 		{
7539 		    if (oldarray)
7540 			vim_free(oldarray);
7541 		}
7542 		else
7543 		    errmsg = e_invarg;
7544 	    }
7545 	}
7546     }
7547 
7548     /* 'vartabstop' */
7549     else if (varp == &(curbuf->b_p_vts))
7550     {
7551 	char_u *cp;
7552 
7553 	if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7554 	{
7555 	    if (curbuf->b_p_vts_array)
7556 	    {
7557 		vim_free(curbuf->b_p_vts_array);
7558 		curbuf->b_p_vts_array = NULL;
7559 	    }
7560 	}
7561 	else
7562 	{
7563 	    for (cp = *varp; *cp; ++cp)
7564 	    {
7565 		if (vim_isdigit(*cp))
7566 		    continue;
7567 		if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7568 		    continue;
7569 		errmsg = e_invarg;
7570 		break;
7571 	    }
7572 	    if (errmsg == NULL)
7573 	    {
7574 		int *oldarray = curbuf->b_p_vts_array;
7575 
7576 		if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7577 		{
7578 		    vim_free(oldarray);
7579 #ifdef FEAT_FOLDING
7580 		    if (foldmethodIsIndent(curwin))
7581 			foldUpdateAll(curwin);
7582 #endif
7583 		}
7584 		else
7585 		    errmsg = e_invarg;
7586 	    }
7587 	}
7588     }
7589 #endif
7590 
7591     /* Options that are a list of flags. */
7592     else
7593     {
7594 	p = NULL;
7595 	if (varp == &p_ww) /* 'whichwrap' */
7596 	    p = (char_u *)WW_ALL;
7597 	if (varp == &p_shm) /* 'shortmess' */
7598 	    p = (char_u *)SHM_ALL;
7599 	else if (varp == &(p_cpo)) /* 'cpoptions' */
7600 	    p = (char_u *)CPO_ALL;
7601 	else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
7602 	    p = (char_u *)FO_ALL;
7603 #ifdef FEAT_CONCEAL
7604 	else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
7605 	    p = (char_u *)COCU_ALL;
7606 #endif
7607 	else if (varp == &p_mouse) /* 'mouse' */
7608 	{
7609 #ifdef FEAT_MOUSE
7610 	    p = (char_u *)MOUSE_ALL;
7611 #else
7612 	    if (*p_mouse != NUL)
7613 		errmsg = N_("E538: No mouse support");
7614 #endif
7615 	}
7616 #if defined(FEAT_GUI)
7617 	else if (varp == &p_go) /* 'guioptions' */
7618 	    p = (char_u *)GO_ALL;
7619 #endif
7620 	if (p != NULL)
7621 	{
7622 	    for (s = *varp; *s; ++s)
7623 		if (vim_strchr(p, *s) == NULL)
7624 		{
7625 		    errmsg = illegal_char(errbuf, *s);
7626 		    break;
7627 		}
7628 	}
7629     }
7630 
7631     /*
7632      * If error detected, restore the previous value.
7633      */
7634     if (errmsg != NULL)
7635     {
7636 	if (new_value_alloced)
7637 	    free_string_option(*varp);
7638 	*varp = oldval;
7639 	/*
7640 	 * When resetting some values, need to act on it.
7641 	 */
7642 	if (did_chartab)
7643 	    (void)init_chartab();
7644 	if (varp == &p_hl)
7645 	    (void)highlight_changed();
7646     }
7647     else
7648     {
7649 #ifdef FEAT_EVAL
7650 	/* Remember where the option was set. */
7651 	set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
7652 #endif
7653 	/*
7654 	 * Free string options that are in allocated memory.
7655 	 * Use "free_oldval", because recursiveness may change the flags under
7656 	 * our fingers (esp. init_highlight()).
7657 	 */
7658 	if (free_oldval)
7659 	    free_string_option(oldval);
7660 	if (new_value_alloced)
7661 	    options[opt_idx].flags |= P_ALLOCED;
7662 	else
7663 	    options[opt_idx].flags &= ~P_ALLOCED;
7664 
7665 	if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
7666 		&& ((int)options[opt_idx].indir & PV_BOTH))
7667 	{
7668 	    /* global option with local value set to use global value; free
7669 	     * the local value and make it empty */
7670 	    p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7671 	    free_string_option(*(char_u **)p);
7672 	    *(char_u **)p = empty_option;
7673 	}
7674 
7675 	/* May set global value for local option. */
7676 	else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7677 	    set_string_option_global(opt_idx, varp);
7678 
7679 	/*
7680 	 * Trigger the autocommand only after setting the flags.
7681 	 */
7682 #ifdef FEAT_SYN_HL
7683 	/* When 'syntax' is set, load the syntax of that name */
7684 	if (varp == &(curbuf->b_p_syn))
7685 	{
7686 	    static int syn_recursive = 0;
7687 
7688 	    ++syn_recursive;
7689 	    // Only pass TRUE for "force" when the value changed or not used
7690 	    // recursively, to avoid endless recurrence.
7691 	    apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7692 		    value_changed || syn_recursive == 1, curbuf);
7693 	    --syn_recursive;
7694 	}
7695 #endif
7696 	else if (varp == &(curbuf->b_p_ft))
7697 	{
7698 	    /* 'filetype' is set, trigger the FileType autocommand.
7699 	     * Skip this when called from a modeline and the filetype was
7700 	     * already set to this value. */
7701 	    if (!(opt_flags & OPT_MODELINE) || value_changed)
7702 	    {
7703 		static int  ft_recursive = 0;
7704 		int	    secure_save = secure;
7705 
7706 		// Reset the secure flag, since the value of 'filetype' has
7707 		// been checked to be safe.
7708 		secure = 0;
7709 
7710 		++ft_recursive;
7711 		did_filetype = TRUE;
7712 		// Only pass TRUE for "force" when the value changed or not
7713 		// used recursively, to avoid endless recurrence.
7714 		apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7715 				   value_changed || ft_recursive == 1, curbuf);
7716 		--ft_recursive;
7717 		/* Just in case the old "curbuf" is now invalid. */
7718 		if (varp != &(curbuf->b_p_ft))
7719 		    varp = NULL;
7720 
7721 		secure = secure_save;
7722 	    }
7723 	}
7724 #ifdef FEAT_SPELL
7725 	if (varp == &(curwin->w_s->b_p_spl))
7726 	{
7727 	    char_u	fname[200];
7728 	    char_u	*q = curwin->w_s->b_p_spl;
7729 
7730 	    /* Skip the first name if it is "cjk". */
7731 	    if (STRNCMP(q, "cjk,", 4) == 0)
7732 		q += 4;
7733 
7734 	    /*
7735 	     * Source the spell/LANG.vim in 'runtimepath'.
7736 	     * They could set 'spellcapcheck' depending on the language.
7737 	     * Use the first name in 'spelllang' up to '_region' or
7738 	     * '.encoding'.
7739 	     */
7740 	    for (p = q; *p != NUL; ++p)
7741 		if (!ASCII_ISALNUM(*p) && *p != '-')
7742 		    break;
7743 	    if (p > q)
7744 	    {
7745 		vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7746 		source_runtime(fname, DIP_ALL);
7747 	    }
7748 	}
7749 #endif
7750     }
7751 
7752 #ifdef FEAT_MOUSE
7753     if (varp == &p_mouse)
7754     {
7755 # ifdef FEAT_MOUSE_TTY
7756 	if (*p_mouse == NUL)
7757 	    mch_setmouse(FALSE);    /* switch mouse off */
7758 	else
7759 # endif
7760 	    setmouse();		    /* in case 'mouse' changed */
7761     }
7762 #endif
7763 
7764     if (curwin->w_curswant != MAXCOL
7765 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
7766 	curwin->w_set_curswant = TRUE;
7767 
7768 #ifdef FEAT_GUI
7769     /* check redraw when it's not a GUI option or the GUI is active. */
7770     if (!redraw_gui_only || gui.in_use)
7771 #endif
7772 	check_redraw(options[opt_idx].flags);
7773 
7774 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7775     if (did_swaptcap)
7776     {
7777 	set_termname((char_u *)"win32");
7778 	init_highlight(TRUE, FALSE);
7779     }
7780 #endif
7781 
7782     return errmsg;
7783 }
7784 
7785 #if defined(FEAT_SYN_HL) || defined(PROTO)
7786 /*
7787  * Simple int comparison function for use with qsort()
7788  */
7789     static int
7790 int_cmp(const void *a, const void *b)
7791 {
7792     return *(const int *)a - *(const int *)b;
7793 }
7794 
7795 /*
7796  * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7797  * Returns error message, NULL if it's OK.
7798  */
7799     char *
7800 check_colorcolumn(win_T *wp)
7801 {
7802     char_u	*s;
7803     int		col;
7804     int		count = 0;
7805     int		color_cols[256];
7806     int		i;
7807     int		j = 0;
7808 
7809     if (wp->w_buffer == NULL)
7810 	return NULL;  /* buffer was closed */
7811 
7812     for (s = wp->w_p_cc; *s != NUL && count < 255;)
7813     {
7814 	if (*s == '-' || *s == '+')
7815 	{
7816 	    /* -N and +N: add to 'textwidth' */
7817 	    col = (*s == '-') ? -1 : 1;
7818 	    ++s;
7819 	    if (!VIM_ISDIGIT(*s))
7820 		return e_invarg;
7821 	    col = col * getdigits(&s);
7822 	    if (wp->w_buffer->b_p_tw == 0)
7823 		goto skip;  /* 'textwidth' not set, skip this item */
7824 	    col += wp->w_buffer->b_p_tw;
7825 	    if (col < 0)
7826 		goto skip;
7827 	}
7828 	else if (VIM_ISDIGIT(*s))
7829 	    col = getdigits(&s);
7830 	else
7831 	    return e_invarg;
7832 	color_cols[count++] = col - 1;  /* 1-based to 0-based */
7833 skip:
7834 	if (*s == NUL)
7835 	    break;
7836 	if (*s != ',')
7837 	    return e_invarg;
7838 	if (*++s == NUL)
7839 	    return e_invarg;  /* illegal trailing comma as in "set cc=80," */
7840     }
7841 
7842     vim_free(wp->w_p_cc_cols);
7843     if (count == 0)
7844 	wp->w_p_cc_cols = NULL;
7845     else
7846     {
7847 	wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7848 	if (wp->w_p_cc_cols != NULL)
7849 	{
7850 	    /* sort the columns for faster usage on screen redraw inside
7851 	     * win_line() */
7852 	    qsort(color_cols, count, sizeof(int), int_cmp);
7853 
7854 	    for (i = 0; i < count; ++i)
7855 		/* skip duplicates */
7856 		if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7857 		    wp->w_p_cc_cols[j++] = color_cols[i];
7858 	    wp->w_p_cc_cols[j] = -1;  /* end marker */
7859 	}
7860     }
7861 
7862     return NULL;  /* no error */
7863 }
7864 #endif
7865 
7866 /*
7867  * Handle setting 'listchars' or 'fillchars'.
7868  * Returns error message, NULL if it's OK.
7869  */
7870     static char *
7871 set_chars_option(char_u **varp)
7872 {
7873     int		round, i, len, entries;
7874     char_u	*p, *s;
7875     int		c1 = 0, c2 = 0, c3 = 0;
7876     struct charstab
7877     {
7878 	int	*cp;
7879 	char	*name;
7880     };
7881     static struct charstab filltab[] =
7882     {
7883 	{&fill_stl,	"stl"},
7884 	{&fill_stlnc,	"stlnc"},
7885 	{&fill_vert,	"vert"},
7886 	{&fill_fold,	"fold"},
7887 	{&fill_diff,	"diff"},
7888     };
7889     static struct charstab lcstab[] =
7890     {
7891 	{&lcs_eol,	"eol"},
7892 	{&lcs_ext,	"extends"},
7893 	{&lcs_nbsp,	"nbsp"},
7894 	{&lcs_prec,	"precedes"},
7895 	{&lcs_space,	"space"},
7896 	{&lcs_tab2,	"tab"},
7897 	{&lcs_trail,	"trail"},
7898 #ifdef FEAT_CONCEAL
7899 	{&lcs_conceal,	"conceal"},
7900 #else
7901 	{NULL,		"conceal"},
7902 #endif
7903     };
7904     struct charstab *tab;
7905 
7906     if (varp == &p_lcs)
7907     {
7908 	tab = lcstab;
7909 	entries = sizeof(lcstab) / sizeof(struct charstab);
7910     }
7911     else
7912     {
7913 	tab = filltab;
7914 	entries = sizeof(filltab) / sizeof(struct charstab);
7915     }
7916 
7917     /* first round: check for valid value, second round: assign values */
7918     for (round = 0; round <= 1; ++round)
7919     {
7920 	if (round > 0)
7921 	{
7922 	    /* After checking that the value is valid: set defaults: space for
7923 	     * 'fillchars', NUL for 'listchars' */
7924 	    for (i = 0; i < entries; ++i)
7925 		if (tab[i].cp != NULL)
7926 		    *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
7927 
7928 	    if (varp == &p_lcs)
7929 	    {
7930 		lcs_tab1 = NUL;
7931 		lcs_tab3 = NUL;
7932 	    }
7933 	    else
7934 		fill_diff = '-';
7935 	}
7936 	p = *varp;
7937 	while (*p)
7938 	{
7939 	    for (i = 0; i < entries; ++i)
7940 	    {
7941 		len = (int)STRLEN(tab[i].name);
7942 		if (STRNCMP(p, tab[i].name, len) == 0
7943 			&& p[len] == ':'
7944 			&& p[len + 1] != NUL)
7945 		{
7946 		    c2 = c3 = 0;
7947 		    s = p + len + 1;
7948 		    c1 = mb_ptr2char_adv(&s);
7949 		    if (mb_char2cells(c1) > 1)
7950 			continue;
7951 		    if (tab[i].cp == &lcs_tab2)
7952 		    {
7953 			if (*s == NUL)
7954 			    continue;
7955 			c2 = mb_ptr2char_adv(&s);
7956 			if (mb_char2cells(c2) > 1)
7957 			    continue;
7958 			if (!(*s == ',' || *s == NUL))
7959 			{
7960 			    c3 = mb_ptr2char_adv(&s);
7961 			    if (mb_char2cells(c3) > 1)
7962 				continue;
7963 			}
7964 		    }
7965 
7966 		    if (*s == ',' || *s == NUL)
7967 		    {
7968 			if (round)
7969 			{
7970 			    if (tab[i].cp == &lcs_tab2)
7971 			    {
7972 				lcs_tab1 = c1;
7973 				lcs_tab2 = c2;
7974 				lcs_tab3 = c3;
7975 			    }
7976 			    else if (tab[i].cp != NULL)
7977 				*(tab[i].cp) = c1;
7978 
7979 			}
7980 			p = s;
7981 			break;
7982 		    }
7983 		}
7984 	    }
7985 
7986 	    if (i == entries)
7987 		return e_invarg;
7988 	    if (*p == ',')
7989 		++p;
7990 	}
7991     }
7992 
7993     return NULL;	/* no error */
7994 }
7995 
7996 #ifdef FEAT_STL_OPT
7997 /*
7998  * Check validity of options with the 'statusline' format.
7999  * Return error message or NULL.
8000  */
8001     char *
8002 check_stl_option(char_u *s)
8003 {
8004     int		itemcnt = 0;
8005     int		groupdepth = 0;
8006     static char errbuf[80];
8007 
8008     while (*s && itemcnt < STL_MAX_ITEM)
8009     {
8010 	/* Check for valid keys after % sequences */
8011 	while (*s && *s != '%')
8012 	    s++;
8013 	if (!*s)
8014 	    break;
8015 	s++;
8016 	if (*s != '%' && *s != ')')
8017 	    ++itemcnt;
8018 	if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8019 	{
8020 	    s++;
8021 	    continue;
8022 	}
8023 	if (*s == ')')
8024 	{
8025 	    s++;
8026 	    if (--groupdepth < 0)
8027 		break;
8028 	    continue;
8029 	}
8030 	if (*s == '-')
8031 	    s++;
8032 	while (VIM_ISDIGIT(*s))
8033 	    s++;
8034 	if (*s == STL_USER_HL)
8035 	    continue;
8036 	if (*s == '.')
8037 	{
8038 	    s++;
8039 	    while (*s && VIM_ISDIGIT(*s))
8040 		s++;
8041 	}
8042 	if (*s == '(')
8043 	{
8044 	    groupdepth++;
8045 	    continue;
8046 	}
8047 	if (vim_strchr(STL_ALL, *s) == NULL)
8048 	{
8049 	    return illegal_char(errbuf, *s);
8050 	}
8051 	if (*s == '{')
8052 	{
8053 	    s++;
8054 	    while (*s != '}' && *s)
8055 		s++;
8056 	    if (*s != '}')
8057 		return N_("E540: Unclosed expression sequence");
8058 	}
8059     }
8060     if (itemcnt >= STL_MAX_ITEM)
8061 	return N_("E541: too many items");
8062     if (groupdepth != 0)
8063 	return N_("E542: unbalanced groups");
8064     return NULL;
8065 }
8066 #endif
8067 
8068 #ifdef FEAT_CLIPBOARD
8069 /*
8070  * Extract the items in the 'clipboard' option and set global values.
8071  * Return an error message or NULL for success.
8072  */
8073     static char *
8074 check_clipboard_option(void)
8075 {
8076     int		new_unnamed = 0;
8077     int		new_autoselect_star = FALSE;
8078     int		new_autoselect_plus = FALSE;
8079     int		new_autoselectml = FALSE;
8080     int		new_html = FALSE;
8081     regprog_T	*new_exclude_prog = NULL;
8082     char	*errmsg = NULL;
8083     char_u	*p;
8084 
8085     for (p = p_cb; *p != NUL; )
8086     {
8087 	if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8088 	{
8089 	    new_unnamed |= CLIP_UNNAMED;
8090 	    p += 7;
8091 	}
8092 	else if (STRNCMP(p, "unnamedplus", 11) == 0
8093 					    && (p[11] == ',' || p[11] == NUL))
8094 	{
8095 	    new_unnamed |= CLIP_UNNAMED_PLUS;
8096 	    p += 11;
8097 	}
8098 	else if (STRNCMP(p, "autoselect", 10) == 0
8099 					    && (p[10] == ',' || p[10] == NUL))
8100 	{
8101 	    new_autoselect_star = TRUE;
8102 	    p += 10;
8103 	}
8104 	else if (STRNCMP(p, "autoselectplus", 14) == 0
8105 					    && (p[14] == ',' || p[14] == NUL))
8106 	{
8107 	    new_autoselect_plus = TRUE;
8108 	    p += 14;
8109 	}
8110 	else if (STRNCMP(p, "autoselectml", 12) == 0
8111 					    && (p[12] == ',' || p[12] == NUL))
8112 	{
8113 	    new_autoselectml = TRUE;
8114 	    p += 12;
8115 	}
8116 	else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8117 	{
8118 	    new_html = TRUE;
8119 	    p += 4;
8120 	}
8121 	else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8122 	{
8123 	    p += 8;
8124 	    new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8125 	    if (new_exclude_prog == NULL)
8126 		errmsg = e_invarg;
8127 	    break;
8128 	}
8129 	else
8130 	{
8131 	    errmsg = e_invarg;
8132 	    break;
8133 	}
8134 	if (*p == ',')
8135 	    ++p;
8136     }
8137     if (errmsg == NULL)
8138     {
8139 	clip_unnamed = new_unnamed;
8140 	clip_autoselect_star = new_autoselect_star;
8141 	clip_autoselect_plus = new_autoselect_plus;
8142 	clip_autoselectml = new_autoselectml;
8143 	clip_html = new_html;
8144 	vim_regfree(clip_exclude_prog);
8145 	clip_exclude_prog = new_exclude_prog;
8146 #ifdef FEAT_GUI_GTK
8147 	if (gui.in_use)
8148 	{
8149 	    gui_gtk_set_selection_targets();
8150 	    gui_gtk_set_dnd_targets();
8151 	}
8152 #endif
8153     }
8154     else
8155 	vim_regfree(new_exclude_prog);
8156 
8157     return errmsg;
8158 }
8159 #endif
8160 
8161 #ifdef FEAT_SPELL
8162 /*
8163  * Handle side effects of setting 'spell'.
8164  * Return an error message or NULL for success.
8165  */
8166     static char *
8167 did_set_spell_option(int is_spellfile)
8168 {
8169     char    *errmsg = NULL;
8170     win_T   *wp;
8171     int	    l;
8172 
8173     if (is_spellfile)
8174     {
8175 	l = (int)STRLEN(curwin->w_s->b_p_spf);
8176 	if (l > 0 && (l < 4
8177 			|| STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8178 	    errmsg = e_invarg;
8179     }
8180 
8181     if (errmsg == NULL)
8182     {
8183 	FOR_ALL_WINDOWS(wp)
8184 	    if (wp->w_buffer == curbuf && wp->w_p_spell)
8185 	    {
8186 		errmsg = did_set_spelllang(wp);
8187 		break;
8188 	    }
8189     }
8190     return errmsg;
8191 }
8192 
8193 /*
8194  * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8195  * Return error message when failed, NULL when OK.
8196  */
8197     static char *
8198 compile_cap_prog(synblock_T *synblock)
8199 {
8200     regprog_T   *rp = synblock->b_cap_prog;
8201     char_u	*re;
8202 
8203     if (*synblock->b_p_spc == NUL)
8204 	synblock->b_cap_prog = NULL;
8205     else
8206     {
8207 	/* Prepend a ^ so that we only match at one column */
8208 	re = concat_str((char_u *)"^", synblock->b_p_spc);
8209 	if (re != NULL)
8210 	{
8211 	    synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
8212 	    vim_free(re);
8213 	    if (synblock->b_cap_prog == NULL)
8214 	    {
8215 		synblock->b_cap_prog = rp; /* restore the previous program */
8216 		return e_invarg;
8217 	    }
8218 	}
8219     }
8220 
8221     vim_regfree(rp);
8222     return NULL;
8223 }
8224 #endif
8225 
8226 #if defined(FEAT_EVAL) || defined(PROTO)
8227 /*
8228  * Set the script_ctx for an option, taking care of setting the buffer- or
8229  * window-local value.
8230  */
8231     static void
8232 set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
8233 {
8234     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8235     int		indir = (int)options[opt_idx].indir;
8236     sctx_T	new_script_ctx = script_ctx;
8237 
8238     new_script_ctx.sc_lnum += sourcing_lnum;
8239 
8240     /* Remember where the option was set.  For local options need to do that
8241      * in the buffer or window structure. */
8242     if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
8243 	options[opt_idx].script_ctx = new_script_ctx;
8244     if (both || (opt_flags & OPT_LOCAL))
8245     {
8246 	if (indir & PV_BUF)
8247 	    curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
8248 	else if (indir & PV_WIN)
8249 	    curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
8250     }
8251 }
8252 
8253 /*
8254  * Set the script_ctx for a termcap option.
8255  * "name" must be the two character code, e.g. "RV".
8256  * When "name" is NULL use "opt_idx".
8257  */
8258     void
8259 set_term_option_sctx_idx(char *name, int opt_idx)
8260 {
8261     char_u  buf[5];
8262     int	    idx;
8263 
8264     if (name == NULL)
8265 	idx = opt_idx;
8266     else
8267     {
8268 	buf[0] = 't';
8269 	buf[1] = '_';
8270 	buf[2] = name[0];
8271 	buf[3] = name[1];
8272 	buf[4] = 0;
8273 	idx = findoption(buf);
8274     }
8275     if (idx >= 0)
8276 	set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8277 }
8278 #endif
8279 
8280 /*
8281  * Set the value of a boolean option, and take care of side effects.
8282  * Returns NULL for success, or an error message for an error.
8283  */
8284     static char *
8285 set_bool_option(
8286     int		opt_idx,		/* index in options[] table */
8287     char_u	*varp,			/* pointer to the option variable */
8288     int		value,			/* new value */
8289     int		opt_flags)		/* OPT_LOCAL and/or OPT_GLOBAL */
8290 {
8291     int		old_value = *(int *)varp;
8292 
8293     /* Disallow changing some options from secure mode */
8294     if ((secure
8295 #ifdef HAVE_SANDBOX
8296 		|| sandbox != 0
8297 #endif
8298 		) && (options[opt_idx].flags & P_SECURE))
8299 	return e_secure;
8300 
8301     *(int *)varp = value;	    /* set the new value */
8302 #ifdef FEAT_EVAL
8303     /* Remember where the option was set. */
8304     set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
8305 #endif
8306 
8307 #ifdef FEAT_GUI
8308     need_mouse_correct = TRUE;
8309 #endif
8310 
8311     /* May set global value for local option. */
8312     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8313 	*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8314 
8315     /*
8316      * Handle side effects of changing a bool option.
8317      */
8318 
8319     /* 'compatible' */
8320     if ((int *)varp == &p_cp)
8321     {
8322 	compatible_set();
8323     }
8324 
8325 #ifdef FEAT_LANGMAP
8326     if ((int *)varp == &p_lrm)
8327 	/* 'langremap' -> !'langnoremap' */
8328 	p_lnr = !p_lrm;
8329     else if ((int *)varp == &p_lnr)
8330 	/* 'langnoremap' -> !'langremap' */
8331 	p_lrm = !p_lnr;
8332 #endif
8333 
8334 #ifdef FEAT_SYN_HL
8335     else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8336 	reset_cursorline();
8337 #endif
8338 
8339 #ifdef FEAT_PERSISTENT_UNDO
8340     /* 'undofile' */
8341     else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8342     {
8343 	/* Only take action when the option was set. When reset we do not
8344 	 * delete the undo file, the option may be set again without making
8345 	 * any changes in between. */
8346 	if (curbuf->b_p_udf || p_udf)
8347 	{
8348 	    char_u	hash[UNDO_HASH_SIZE];
8349 	    buf_T	*save_curbuf = curbuf;
8350 
8351 	    FOR_ALL_BUFFERS(curbuf)
8352 	    {
8353 		/* When 'undofile' is set globally: for every buffer, otherwise
8354 		 * only for the current buffer: Try to read in the undofile,
8355 		 * if one exists, the buffer wasn't changed and the buffer was
8356 		 * loaded */
8357 		if ((curbuf == save_curbuf
8358 				|| (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8359 			&& !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8360 		{
8361 		    u_compute_hash(hash);
8362 		    u_read_undo(NULL, hash, curbuf->b_fname);
8363 		}
8364 	    }
8365 	    curbuf = save_curbuf;
8366 	}
8367     }
8368 #endif
8369 
8370     else if ((int *)varp == &curbuf->b_p_ro)
8371     {
8372 	/* when 'readonly' is reset globally, also reset readonlymode */
8373 	if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8374 	    readonlymode = FALSE;
8375 
8376 	/* when 'readonly' is set may give W10 again */
8377 	if (curbuf->b_p_ro)
8378 	    curbuf->b_did_warn = FALSE;
8379 
8380 #ifdef FEAT_TITLE
8381 	redraw_titles();
8382 #endif
8383     }
8384 
8385 #ifdef FEAT_GUI
8386     else if ((int *)varp == &p_mh)
8387     {
8388 	if (!p_mh)
8389 	    gui_mch_mousehide(FALSE);
8390     }
8391 #endif
8392 
8393     /* when 'modifiable' is changed, redraw the window title */
8394     else if ((int *)varp == &curbuf->b_p_ma)
8395     {
8396 # ifdef FEAT_TERMINAL
8397 	/* Cannot set 'modifiable' when in Terminal mode. */
8398 	if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8399 		      && curbuf->b_term != NULL && !term_is_finished(curbuf))))
8400 	{
8401 	    curbuf->b_p_ma = FALSE;
8402 	    return N_("E946: Cannot make a terminal with running job modifiable");
8403 	}
8404 # endif
8405 # ifdef FEAT_TITLE
8406 	redraw_titles();
8407 # endif
8408     }
8409 #ifdef FEAT_TITLE
8410     /* when 'endofline' is changed, redraw the window title */
8411     else if ((int *)varp == &curbuf->b_p_eol)
8412     {
8413 	redraw_titles();
8414     }
8415     /* when 'fixeol' is changed, redraw the window title */
8416     else if ((int *)varp == &curbuf->b_p_fixeol)
8417     {
8418 	redraw_titles();
8419     }
8420     /* when 'bomb' is changed, redraw the window title and tab page text */
8421     else if ((int *)varp == &curbuf->b_p_bomb)
8422     {
8423 	redraw_titles();
8424     }
8425 #endif
8426 
8427     /* when 'bin' is set also set some other options */
8428     else if ((int *)varp == &curbuf->b_p_bin)
8429     {
8430 	set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8431 #ifdef FEAT_TITLE
8432 	redraw_titles();
8433 #endif
8434     }
8435 
8436     /* when 'buflisted' changes, trigger autocommands */
8437     else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8438     {
8439 	apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8440 						    NULL, NULL, TRUE, curbuf);
8441     }
8442 
8443     /* when 'swf' is set, create swapfile, when reset remove swapfile */
8444     else if ((int *)varp == &curbuf->b_p_swf)
8445     {
8446 	if (curbuf->b_p_swf && p_uc)
8447 	    ml_open_file(curbuf);		/* create the swap file */
8448 	else
8449 	    /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8450 	     * buf->b_p_swf */
8451 	    mf_close_file(curbuf, TRUE);	/* remove the swap file */
8452     }
8453 
8454     /* when 'terse' is set change 'shortmess' */
8455     else if ((int *)varp == &p_terse)
8456     {
8457 	char_u	*p;
8458 
8459 	p = vim_strchr(p_shm, SHM_SEARCH);
8460 
8461 	/* insert 's' in p_shm */
8462 	if (p_terse && p == NULL)
8463 	{
8464 	    STRCPY(IObuff, p_shm);
8465 	    STRCAT(IObuff, "s");
8466 	    set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
8467 	}
8468 	/* remove 's' from p_shm */
8469 	else if (!p_terse && p != NULL)
8470 	    STRMOVE(p, p + 1);
8471     }
8472 
8473     /* when 'paste' is set or reset also change other options */
8474     else if ((int *)varp == &p_paste)
8475     {
8476 	paste_option_changed();
8477     }
8478 
8479     /* when 'insertmode' is set from an autocommand need to do work here */
8480     else if ((int *)varp == &p_im)
8481     {
8482 	if (p_im)
8483 	{
8484 	    if ((State & INSERT) == 0)
8485 		need_start_insertmode = TRUE;
8486 	    stop_insert_mode = FALSE;
8487 	}
8488 	/* only reset if it was set previously */
8489 	else if (old_value)
8490 	{
8491 	    need_start_insertmode = FALSE;
8492 	    stop_insert_mode = TRUE;
8493 	    if (restart_edit != 0 && mode_displayed)
8494 		clear_cmdline = TRUE;	/* remove "(insert)" */
8495 	    restart_edit = 0;
8496 	}
8497     }
8498 
8499     /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8500     else if ((int *)varp == &p_ic && p_hls)
8501     {
8502 	redraw_all_later(SOME_VALID);
8503     }
8504 
8505 #ifdef FEAT_SEARCH_EXTRA
8506     /* when 'hlsearch' is set or reset: reset no_hlsearch */
8507     else if ((int *)varp == &p_hls)
8508     {
8509 	set_no_hlsearch(FALSE);
8510     }
8511 #endif
8512 
8513     /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8514      * at the end of normal_cmd() */
8515     else if ((int *)varp == &curwin->w_p_scb)
8516     {
8517 	if (curwin->w_p_scb)
8518 	{
8519 	    do_check_scrollbind(FALSE);
8520 	    curwin->w_scbind_pos = curwin->w_topline;
8521 	}
8522     }
8523 
8524 #if defined(FEAT_QUICKFIX)
8525     /* There can be only one window with 'previewwindow' set. */
8526     else if ((int *)varp == &curwin->w_p_pvw)
8527     {
8528 	if (curwin->w_p_pvw)
8529 	{
8530 	    win_T	*win;
8531 
8532 	    FOR_ALL_WINDOWS(win)
8533 		if (win->w_p_pvw && win != curwin)
8534 		{
8535 		    curwin->w_p_pvw = FALSE;
8536 		    return N_("E590: A preview window already exists");
8537 		}
8538 	}
8539     }
8540 #endif
8541 
8542     /* when 'textmode' is set or reset also change 'fileformat' */
8543     else if ((int *)varp == &curbuf->b_p_tx)
8544     {
8545 	set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8546     }
8547 
8548     /* when 'textauto' is set or reset also change 'fileformats' */
8549     else if ((int *)varp == &p_ta)
8550 	set_string_option_direct((char_u *)"ffs", -1,
8551 				 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
8552 						     OPT_FREE | opt_flags, 0);
8553 
8554     /*
8555      * When 'lisp' option changes include/exclude '-' in
8556      * keyword characters.
8557      */
8558 #ifdef FEAT_LISP
8559     else if (varp == (char_u *)&(curbuf->b_p_lisp))
8560     {
8561 	(void)buf_init_chartab(curbuf, FALSE);	    /* ignore errors */
8562     }
8563 #endif
8564 
8565 #ifdef FEAT_TITLE
8566     /* when 'title' changed, may need to change the title; same for 'icon' */
8567     else if ((int *)varp == &p_title || (int *)varp == &p_icon)
8568     {
8569 	did_set_title();
8570     }
8571 #endif
8572 
8573     else if ((int *)varp == &curbuf->b_changed)
8574     {
8575 	if (!value)
8576 	    save_file_ff(curbuf);	/* Buffer is unchanged */
8577 #ifdef FEAT_TITLE
8578 	redraw_titles();
8579 #endif
8580 	modified_was_set = value;
8581     }
8582 
8583 #ifdef BACKSLASH_IN_FILENAME
8584     else if ((int *)varp == &p_ssl)
8585     {
8586 	if (p_ssl)
8587 	{
8588 	    psepc = '/';
8589 	    psepcN = '\\';
8590 	    pseps[0] = '/';
8591 	}
8592 	else
8593 	{
8594 	    psepc = '\\';
8595 	    psepcN = '/';
8596 	    pseps[0] = '\\';
8597 	}
8598 
8599 	/* need to adjust the file name arguments and buffer names. */
8600 	buflist_slash_adjust();
8601 	alist_slash_adjust();
8602 # ifdef FEAT_EVAL
8603 	scriptnames_slash_adjust();
8604 # endif
8605     }
8606 #endif
8607 
8608     /* If 'wrap' is set, set w_leftcol to zero. */
8609     else if ((int *)varp == &curwin->w_p_wrap)
8610     {
8611 	if (curwin->w_p_wrap)
8612 	    curwin->w_leftcol = 0;
8613     }
8614 
8615     else if ((int *)varp == &p_ea)
8616     {
8617 	if (p_ea && !old_value)
8618 	    win_equal(curwin, FALSE, 0);
8619     }
8620 
8621     else if ((int *)varp == &p_wiv)
8622     {
8623 	/*
8624 	 * When 'weirdinvert' changed, set/reset 't_xs'.
8625 	 * Then set 'weirdinvert' according to value of 't_xs'.
8626 	 */
8627 	if (p_wiv && !old_value)
8628 	    T_XS = (char_u *)"y";
8629 	else if (!p_wiv && old_value)
8630 	    T_XS = empty_option;
8631 	p_wiv = (*T_XS != NUL);
8632     }
8633 
8634 #ifdef FEAT_BEVAL_GUI
8635     else if ((int *)varp == &p_beval)
8636     {
8637 	if (!balloonEvalForTerm)
8638 	{
8639 	    if (p_beval && !old_value)
8640 		gui_mch_enable_beval_area(balloonEval);
8641 	    else if (!p_beval && old_value)
8642 		gui_mch_disable_beval_area(balloonEval);
8643 	}
8644     }
8645 #endif
8646 #ifdef FEAT_BEVAL_TERM
8647     else if ((int *)varp == &p_bevalterm)
8648     {
8649 	mch_bevalterm_changed();
8650     }
8651 #endif
8652 
8653 #ifdef FEAT_AUTOCHDIR
8654     else if ((int *)varp == &p_acd)
8655     {
8656 	/* Change directories when the 'acd' option is set now. */
8657 	DO_AUTOCHDIR;
8658     }
8659 #endif
8660 
8661 #ifdef FEAT_DIFF
8662     /* 'diff' */
8663     else if ((int *)varp == &curwin->w_p_diff)
8664     {
8665 	/* May add or remove the buffer from the list of diff buffers. */
8666 	diff_buf_adjust(curwin);
8667 # ifdef FEAT_FOLDING
8668 	if (foldmethodIsDiff(curwin))
8669 	    foldUpdateAll(curwin);
8670 # endif
8671     }
8672 #endif
8673 
8674 #ifdef HAVE_INPUT_METHOD
8675     /* 'imdisable' */
8676     else if ((int *)varp == &p_imdisable)
8677     {
8678 	/* Only de-activate it here, it will be enabled when changing mode. */
8679 	if (p_imdisable)
8680 	    im_set_active(FALSE);
8681 	else if (State & INSERT)
8682 	    /* When the option is set from an autocommand, it may need to take
8683 	     * effect right away. */
8684 	    im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
8685     }
8686 #endif
8687 
8688 #ifdef FEAT_SPELL
8689     /* 'spell' */
8690     else if ((int *)varp == &curwin->w_p_spell)
8691     {
8692 	if (curwin->w_p_spell)
8693 	{
8694 	    char	*errmsg = did_set_spelllang(curwin);
8695 
8696 	    if (errmsg != NULL)
8697 		emsg(_(errmsg));
8698 	}
8699     }
8700 #endif
8701 
8702 #ifdef FEAT_ARABIC
8703     if ((int *)varp == &curwin->w_p_arab)
8704     {
8705 	if (curwin->w_p_arab)
8706 	{
8707 	    /*
8708 	     * 'arabic' is set, handle various sub-settings.
8709 	     */
8710 	    if (!p_tbidi)
8711 	    {
8712 		/* set rightleft mode */
8713 		if (!curwin->w_p_rl)
8714 		{
8715 		    curwin->w_p_rl = TRUE;
8716 		    changed_window_setting();
8717 		}
8718 
8719 		/* Enable Arabic shaping (major part of what Arabic requires) */
8720 		if (!p_arshape)
8721 		{
8722 		    p_arshape = TRUE;
8723 		    redraw_later_clear();
8724 		}
8725 	    }
8726 
8727 	    /* Arabic requires a utf-8 encoding, inform the user if its not
8728 	     * set. */
8729 	    if (STRCMP(p_enc, "utf-8") != 0)
8730 	    {
8731 		static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8732 
8733 		msg_source(HL_ATTR(HLF_W));
8734 		msg_attr(_(w_arabic), HL_ATTR(HLF_W));
8735 #ifdef FEAT_EVAL
8736 		set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8737 #endif
8738 	    }
8739 
8740 	    /* set 'delcombine' */
8741 	    p_deco = TRUE;
8742 
8743 # ifdef FEAT_KEYMAP
8744 	    /* Force-set the necessary keymap for arabic */
8745 	    set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8746 								   OPT_LOCAL);
8747 # endif
8748 	}
8749 	else
8750 	{
8751 	    /*
8752 	     * 'arabic' is reset, handle various sub-settings.
8753 	     */
8754 	    if (!p_tbidi)
8755 	    {
8756 		/* reset rightleft mode */
8757 		if (curwin->w_p_rl)
8758 		{
8759 		    curwin->w_p_rl = FALSE;
8760 		    changed_window_setting();
8761 		}
8762 
8763 		/* 'arabicshape' isn't reset, it is a global option and
8764 		 * another window may still need it "on". */
8765 	    }
8766 
8767 	    /* 'delcombine' isn't reset, it is a global option and another
8768 	     * window may still want it "on". */
8769 
8770 # ifdef FEAT_KEYMAP
8771 	    /* Revert to the default keymap */
8772 	    curbuf->b_p_iminsert = B_IMODE_NONE;
8773 	    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8774 # endif
8775 	}
8776     }
8777 
8778 #endif
8779 
8780 #ifdef FEAT_TERMGUICOLORS
8781     /* 'termguicolors' */
8782     else if ((int *)varp == &p_tgc)
8783     {
8784 # ifdef FEAT_VTP
8785 	/* Do not turn on 'tgc' when 24-bit colors are not supported. */
8786 	if (!has_vtp_working())
8787 	{
8788 	    p_tgc = 0;
8789 	    return N_("E954: 24-bit colors are not supported on this environment");
8790 	}
8791 	if (is_term_win32())
8792 	    swap_tcap();
8793 # endif
8794 # ifdef FEAT_GUI
8795 	if (!gui.in_use && !gui.starting)
8796 # endif
8797 	    highlight_gui_started();
8798 # ifdef FEAT_VTP
8799 	/* reset t_Co */
8800 	if (is_term_win32())
8801 	{
8802 	    control_console_color_rgb();
8803 	    set_termname(T_NAME);
8804 	    init_highlight(TRUE, FALSE);
8805 	}
8806 # endif
8807     }
8808 #endif
8809 
8810     /*
8811      * End of handling side effects for bool options.
8812      */
8813 
8814     /* after handling side effects, call autocommand */
8815 
8816     options[opt_idx].flags |= P_WAS_SET;
8817 
8818 #if defined(FEAT_EVAL)
8819     // Don't do this while starting up or recursively.
8820     if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
8821     {
8822 	char_u buf_old[2], buf_new[2], buf_type[7];
8823 
8824 	vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8825 	vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8826 	vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
8827 	set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8828 	set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8829 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8830 	apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8831 	reset_v_option_vars();
8832     }
8833 #endif
8834 
8835     comp_col();			    /* in case 'ruler' or 'showcmd' changed */
8836     if (curwin->w_curswant != MAXCOL
8837 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
8838 	curwin->w_set_curswant = TRUE;
8839     check_redraw(options[opt_idx].flags);
8840 
8841     return NULL;
8842 }
8843 
8844 /*
8845  * Set the value of a number option, and take care of side effects.
8846  * Returns NULL for success, or an error message for an error.
8847  */
8848     static char *
8849 set_num_option(
8850     int		opt_idx,		/* index in options[] table */
8851     char_u	*varp,			/* pointer to the option variable */
8852     long	value,			/* new value */
8853     char	*errbuf,		/* buffer for error messages */
8854     size_t	errbuflen,		/* length of "errbuf" */
8855     int		opt_flags)		/* OPT_LOCAL, OPT_GLOBAL and
8856 					   OPT_MODELINE */
8857 {
8858     char	*errmsg = NULL;
8859     long	old_value = *(long *)varp;
8860     long	old_Rows = Rows;	/* remember old Rows */
8861     long	old_Columns = Columns;	/* remember old Columns */
8862     long	*pp = (long *)varp;
8863 
8864     /* Disallow changing some options from secure mode. */
8865     if ((secure
8866 #ifdef HAVE_SANDBOX
8867 		|| sandbox != 0
8868 #endif
8869 		) && (options[opt_idx].flags & P_SECURE))
8870 	return e_secure;
8871 
8872     *pp = value;
8873 #ifdef FEAT_EVAL
8874     /* Remember where the option was set. */
8875     set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
8876 #endif
8877 #ifdef FEAT_GUI
8878     need_mouse_correct = TRUE;
8879 #endif
8880 
8881     if (curbuf->b_p_sw < 0)
8882     {
8883 	errmsg = e_positive;
8884 #ifdef FEAT_VARTABS
8885 	// Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8886 	curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8887 	               ? tabstop_first(curbuf->b_p_vts_array)
8888 		       : curbuf->b_p_ts;
8889 #else
8890 	curbuf->b_p_sw = curbuf->b_p_ts;
8891 #endif
8892     }
8893 
8894     /*
8895      * Number options that need some action when changed
8896      */
8897     if (pp == &p_wh || pp == &p_hh)
8898     {
8899 	// 'winheight' and 'helpheight'
8900 	if (p_wh < 1)
8901 	{
8902 	    errmsg = e_positive;
8903 	    p_wh = 1;
8904 	}
8905 	if (p_wmh > p_wh)
8906 	{
8907 	    errmsg = e_winheight;
8908 	    p_wh = p_wmh;
8909 	}
8910 	if (p_hh < 0)
8911 	{
8912 	    errmsg = e_positive;
8913 	    p_hh = 0;
8914 	}
8915 
8916 	/* Change window height NOW */
8917 	if (!ONE_WINDOW)
8918 	{
8919 	    if (pp == &p_wh && curwin->w_height < p_wh)
8920 		win_setheight((int)p_wh);
8921 	    if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8922 		win_setheight((int)p_hh);
8923 	}
8924     }
8925     else if (pp == &p_wmh)
8926     {
8927 	// 'winminheight'
8928 	if (p_wmh < 0)
8929 	{
8930 	    errmsg = e_positive;
8931 	    p_wmh = 0;
8932 	}
8933 	if (p_wmh > p_wh)
8934 	{
8935 	    errmsg = e_winheight;
8936 	    p_wmh = p_wh;
8937 	}
8938 	win_setminheight();
8939     }
8940     else if (pp == &p_wiw)
8941     {
8942 	// 'winwidth'
8943 	if (p_wiw < 1)
8944 	{
8945 	    errmsg = e_positive;
8946 	    p_wiw = 1;
8947 	}
8948 	if (p_wmw > p_wiw)
8949 	{
8950 	    errmsg = e_winwidth;
8951 	    p_wiw = p_wmw;
8952 	}
8953 
8954 	/* Change window width NOW */
8955 	if (!ONE_WINDOW && curwin->w_width < p_wiw)
8956 	    win_setwidth((int)p_wiw);
8957     }
8958     else if (pp == &p_wmw)
8959     {
8960 	// 'winminwidth'
8961 	if (p_wmw < 0)
8962 	{
8963 	    errmsg = e_positive;
8964 	    p_wmw = 0;
8965 	}
8966 	if (p_wmw > p_wiw)
8967 	{
8968 	    errmsg = e_winwidth;
8969 	    p_wmw = p_wiw;
8970 	}
8971 	win_setminwidth();
8972     }
8973 
8974     /* (re)set last window status line */
8975     else if (pp == &p_ls)
8976     {
8977 	last_status(FALSE);
8978     }
8979 
8980     /* (re)set tab page line */
8981     else if (pp == &p_stal)
8982     {
8983 	shell_new_rows();	/* recompute window positions and heights */
8984     }
8985 
8986 #ifdef FEAT_GUI
8987     else if (pp == &p_linespace)
8988     {
8989 	/* Recompute gui.char_height and resize the Vim window to keep the
8990 	 * same number of lines. */
8991 	if (gui.in_use && gui_mch_adjust_charheight() == OK)
8992 	    gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
8993     }
8994 #endif
8995 
8996 #ifdef FEAT_FOLDING
8997     /* 'foldlevel' */
8998     else if (pp == &curwin->w_p_fdl)
8999     {
9000 	if (curwin->w_p_fdl < 0)
9001 	    curwin->w_p_fdl = 0;
9002 	newFoldLevel();
9003     }
9004 
9005     /* 'foldminlines' */
9006     else if (pp == &curwin->w_p_fml)
9007     {
9008 	foldUpdateAll(curwin);
9009     }
9010 
9011     /* 'foldnestmax' */
9012     else if (pp == &curwin->w_p_fdn)
9013     {
9014 	if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9015 	    foldUpdateAll(curwin);
9016     }
9017 
9018     /* 'foldcolumn' */
9019     else if (pp == &curwin->w_p_fdc)
9020     {
9021 	if (curwin->w_p_fdc < 0)
9022 	{
9023 	    errmsg = e_positive;
9024 	    curwin->w_p_fdc = 0;
9025 	}
9026 	else if (curwin->w_p_fdc > 12)
9027 	{
9028 	    errmsg = e_invarg;
9029 	    curwin->w_p_fdc = 12;
9030 	}
9031     }
9032 #endif /* FEAT_FOLDING */
9033 
9034 #if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
9035     /* 'shiftwidth' or 'tabstop' */
9036     else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9037     {
9038 # ifdef FEAT_FOLDING
9039 	if (foldmethodIsIndent(curwin))
9040 	    foldUpdateAll(curwin);
9041 # endif
9042 # ifdef FEAT_CINDENT
9043 	/* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9044 	 * parse 'cinoptions'. */
9045 	if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9046 	    parse_cino(curbuf);
9047 # endif
9048     }
9049 #endif
9050 
9051     /* 'maxcombine' */
9052     else if (pp == &p_mco)
9053     {
9054 	if (p_mco > MAX_MCO)
9055 	    p_mco = MAX_MCO;
9056 	else if (p_mco < 0)
9057 	    p_mco = 0;
9058 	screenclear();	    /* will re-allocate the screen */
9059     }
9060 
9061     else if (pp == &curbuf->b_p_iminsert)
9062     {
9063 	if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9064 	{
9065 	    errmsg = e_invarg;
9066 	    curbuf->b_p_iminsert = B_IMODE_NONE;
9067 	}
9068 	p_iminsert = curbuf->b_p_iminsert;
9069 	if (termcap_active)	/* don't do this in the alternate screen */
9070 	    showmode();
9071 #if defined(FEAT_KEYMAP)
9072 	/* Show/unshow value of 'keymap' in status lines. */
9073 	status_redraw_curbuf();
9074 #endif
9075     }
9076 
9077 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9078     /* 'imstyle' */
9079     else if (pp == &p_imst)
9080     {
9081 	if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9082 	    errmsg = e_invarg;
9083     }
9084 #endif
9085 
9086     else if (pp == &p_window)
9087     {
9088 	if (p_window < 1)
9089 	    p_window = 1;
9090 	else if (p_window >= Rows)
9091 	    p_window = Rows - 1;
9092     }
9093 
9094     else if (pp == &curbuf->b_p_imsearch)
9095     {
9096 	if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9097 	{
9098 	    errmsg = e_invarg;
9099 	    curbuf->b_p_imsearch = B_IMODE_NONE;
9100 	}
9101 	p_imsearch = curbuf->b_p_imsearch;
9102     }
9103 
9104 #ifdef FEAT_TITLE
9105     /* if 'titlelen' has changed, redraw the title */
9106     else if (pp == &p_titlelen)
9107     {
9108 	if (p_titlelen < 0)
9109 	{
9110 	    errmsg = e_positive;
9111 	    p_titlelen = 85;
9112 	}
9113 	if (starting != NO_SCREEN && old_value != p_titlelen)
9114 	    need_maketitle = TRUE;
9115     }
9116 #endif
9117 
9118     /* if p_ch changed value, change the command line height */
9119     else if (pp == &p_ch)
9120     {
9121 	if (p_ch < 1)
9122 	{
9123 	    errmsg = e_positive;
9124 	    p_ch = 1;
9125 	}
9126 	if (p_ch > Rows - min_rows() + 1)
9127 	    p_ch = Rows - min_rows() + 1;
9128 
9129 	/* Only compute the new window layout when startup has been
9130 	 * completed. Otherwise the frame sizes may be wrong. */
9131 	if (p_ch != old_value && full_screen
9132 #ifdef FEAT_GUI
9133 		&& !gui.starting
9134 #endif
9135 	   )
9136 	    command_height();
9137     }
9138 
9139     /* when 'updatecount' changes from zero to non-zero, open swap files */
9140     else if (pp == &p_uc)
9141     {
9142 	if (p_uc < 0)
9143 	{
9144 	    errmsg = e_positive;
9145 	    p_uc = 100;
9146 	}
9147 	if (p_uc && !old_value)
9148 	    ml_open_files();
9149     }
9150 #ifdef FEAT_CONCEAL
9151     else if (pp == &curwin->w_p_cole)
9152     {
9153 	if (curwin->w_p_cole < 0)
9154 	{
9155 	    errmsg = e_positive;
9156 	    curwin->w_p_cole = 0;
9157 	}
9158 	else if (curwin->w_p_cole > 3)
9159 	{
9160 	    errmsg = e_invarg;
9161 	    curwin->w_p_cole = 3;
9162 	}
9163     }
9164 #endif
9165 #ifdef MZSCHEME_GUI_THREADS
9166     else if (pp == &p_mzq)
9167 	mzvim_reset_timer();
9168 #endif
9169 
9170 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9171     /* 'pyxversion' */
9172     else if (pp == &p_pyx)
9173     {
9174 	if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9175 	    errmsg = e_invarg;
9176     }
9177 #endif
9178 
9179     /* sync undo before 'undolevels' changes */
9180     else if (pp == &p_ul)
9181     {
9182 	/* use the old value, otherwise u_sync() may not work properly */
9183 	p_ul = old_value;
9184 	u_sync(TRUE);
9185 	p_ul = value;
9186     }
9187     else if (pp == &curbuf->b_p_ul)
9188     {
9189 	/* use the old value, otherwise u_sync() may not work properly */
9190 	curbuf->b_p_ul = old_value;
9191 	u_sync(TRUE);
9192 	curbuf->b_p_ul = value;
9193     }
9194 
9195 #ifdef FEAT_LINEBREAK
9196     /* 'numberwidth' must be positive */
9197     else if (pp == &curwin->w_p_nuw)
9198     {
9199 	if (curwin->w_p_nuw < 1)
9200 	{
9201 	    errmsg = e_positive;
9202 	    curwin->w_p_nuw = 1;
9203 	}
9204 	if (curwin->w_p_nuw > 10)
9205 	{
9206 	    errmsg = e_invarg;
9207 	    curwin->w_p_nuw = 10;
9208 	}
9209 	curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
9210     }
9211 #endif
9212 
9213     else if (pp == &curbuf->b_p_tw)
9214     {
9215 	if (curbuf->b_p_tw < 0)
9216 	{
9217 	    errmsg = e_positive;
9218 	    curbuf->b_p_tw = 0;
9219 	}
9220 #ifdef FEAT_SYN_HL
9221 	{
9222 	    win_T	*wp;
9223 	    tabpage_T	*tp;
9224 
9225 	    FOR_ALL_TAB_WINDOWS(tp, wp)
9226 		check_colorcolumn(wp);
9227 	}
9228 #endif
9229     }
9230 
9231     /*
9232      * Check the bounds for numeric options here
9233      */
9234     if (Rows < min_rows() && full_screen)
9235     {
9236 	if (errbuf != NULL)
9237 	{
9238 	    vim_snprintf((char *)errbuf, errbuflen,
9239 			       _("E593: Need at least %d lines"), min_rows());
9240 	    errmsg = errbuf;
9241 	}
9242 	Rows = min_rows();
9243     }
9244     if (Columns < MIN_COLUMNS && full_screen)
9245     {
9246 	if (errbuf != NULL)
9247 	{
9248 	    vim_snprintf((char *)errbuf, errbuflen,
9249 			    _("E594: Need at least %d columns"), MIN_COLUMNS);
9250 	    errmsg = errbuf;
9251 	}
9252 	Columns = MIN_COLUMNS;
9253     }
9254     limit_screen_size();
9255 
9256     /*
9257      * If the screen (shell) height has been changed, assume it is the
9258      * physical screenheight.
9259      */
9260     if (old_Rows != Rows || old_Columns != Columns)
9261     {
9262 	/* Changing the screen size is not allowed while updating the screen. */
9263 	if (updating_screen)
9264 	    *pp = old_value;
9265 	else if (full_screen
9266 #ifdef FEAT_GUI
9267 		&& !gui.starting
9268 #endif
9269 	    )
9270 	    set_shellsize((int)Columns, (int)Rows, TRUE);
9271 	else
9272 	{
9273 	    /* Postpone the resizing; check the size and cmdline position for
9274 	     * messages. */
9275 	    check_shellsize();
9276 	    if (cmdline_row > Rows - p_ch && Rows > p_ch)
9277 		cmdline_row = Rows - p_ch;
9278 	}
9279 	if (p_window >= Rows || !option_was_set((char_u *)"window"))
9280 	    p_window = Rows - 1;
9281     }
9282 
9283     if (curbuf->b_p_ts <= 0)
9284     {
9285 	errmsg = e_positive;
9286 	curbuf->b_p_ts = 8;
9287     }
9288     if (p_tm < 0)
9289     {
9290 	errmsg = e_positive;
9291 	p_tm = 0;
9292     }
9293     if ((curwin->w_p_scr <= 0
9294 		|| (curwin->w_p_scr > curwin->w_height
9295 		    && curwin->w_height > 0))
9296 	    && full_screen)
9297     {
9298 	if (pp == &(curwin->w_p_scr))
9299 	{
9300 	    if (curwin->w_p_scr != 0)
9301 		errmsg = e_scroll;
9302 	    win_comp_scroll(curwin);
9303 	}
9304 	/* If 'scroll' became invalid because of a side effect silently adjust
9305 	 * it. */
9306 	else if (curwin->w_p_scr <= 0)
9307 	    curwin->w_p_scr = 1;
9308 	else /* curwin->w_p_scr > curwin->w_height */
9309 	    curwin->w_p_scr = curwin->w_height;
9310     }
9311     if (p_hi < 0)
9312     {
9313 	errmsg = e_positive;
9314 	p_hi = 0;
9315     }
9316     else if (p_hi > 10000)
9317     {
9318 	errmsg = e_invarg;
9319 	p_hi = 10000;
9320     }
9321     if (p_re < 0 || p_re > 2)
9322     {
9323 	errmsg = e_invarg;
9324 	p_re = 0;
9325     }
9326     if (p_report < 0)
9327     {
9328 	errmsg = e_positive;
9329 	p_report = 1;
9330     }
9331     if ((p_sj < -100 || p_sj >= Rows) && full_screen)
9332     {
9333 	if (Rows != old_Rows)	/* Rows changed, just adjust p_sj */
9334 	    p_sj = Rows / 2;
9335 	else
9336 	{
9337 	    errmsg = e_scroll;
9338 	    p_sj = 1;
9339 	}
9340     }
9341     if (p_so < 0 && full_screen)
9342     {
9343 	errmsg = e_positive;
9344 	p_so = 0;
9345     }
9346     if (p_siso < 0 && full_screen)
9347     {
9348 	errmsg = e_positive;
9349 	p_siso = 0;
9350     }
9351 #ifdef FEAT_CMDWIN
9352     if (p_cwh < 1)
9353     {
9354 	errmsg = e_positive;
9355 	p_cwh = 1;
9356     }
9357 #endif
9358     if (p_ut < 0)
9359     {
9360 	errmsg = e_positive;
9361 	p_ut = 2000;
9362     }
9363     if (p_ss < 0)
9364     {
9365 	errmsg = e_positive;
9366 	p_ss = 0;
9367     }
9368 
9369     /* May set global value for local option. */
9370     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9371 	*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9372 
9373     options[opt_idx].flags |= P_WAS_SET;
9374 
9375 #if defined(FEAT_EVAL)
9376     // Don't do this while starting up, failure or recursively.
9377     if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
9378     {
9379 	char_u buf_old[11], buf_new[11], buf_type[7];
9380 
9381 	vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9382 	vim_snprintf((char *)buf_new, 10, "%ld", value);
9383 	vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
9384 	set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9385 	set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9386 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9387 	apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9388 	reset_v_option_vars();
9389     }
9390 #endif
9391 
9392     comp_col();			    /* in case 'columns' or 'ls' changed */
9393     if (curwin->w_curswant != MAXCOL
9394 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
9395 	curwin->w_set_curswant = TRUE;
9396     check_redraw(options[opt_idx].flags);
9397 
9398     return errmsg;
9399 }
9400 
9401 /*
9402  * Called after an option changed: check if something needs to be redrawn.
9403  */
9404     static void
9405 check_redraw(long_u flags)
9406 {
9407     /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
9408     int		doclear = (flags & P_RCLR) == P_RCLR;
9409     int		all = ((flags & P_RALL) == P_RALL || doclear);
9410 
9411     if ((flags & P_RSTAT) || all)	/* mark all status lines dirty */
9412 	status_redraw_all();
9413 
9414     if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9415 	changed_window_setting();
9416     if (flags & P_RBUF)
9417 	redraw_curbuf_later(NOT_VALID);
9418     if (flags & P_RWINONLY)
9419 	redraw_later(NOT_VALID);
9420     if (doclear)
9421 	redraw_all_later(CLEAR);
9422     else if (all)
9423 	redraw_all_later(NOT_VALID);
9424 }
9425 
9426 /*
9427  * Find index for option 'arg'.
9428  * Return -1 if not found.
9429  */
9430     static int
9431 findoption(char_u *arg)
9432 {
9433     int		    opt_idx;
9434     char	    *s, *p;
9435     static short    quick_tab[27] = {0, 0};	/* quick access table */
9436     int		    is_term_opt;
9437 
9438     /*
9439      * For first call: Initialize the quick-access table.
9440      * It contains the index for the first option that starts with a certain
9441      * letter.  There are 26 letters, plus the first "t_" option.
9442      */
9443     if (quick_tab[1] == 0)
9444     {
9445 	p = options[0].fullname;
9446 	for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9447 	{
9448 	    if (s[0] != p[0])
9449 	    {
9450 		if (s[0] == 't' && s[1] == '_')
9451 		    quick_tab[26] = opt_idx;
9452 		else
9453 		    quick_tab[CharOrdLow(s[0])] = opt_idx;
9454 	    }
9455 	    p = s;
9456 	}
9457     }
9458 
9459     /*
9460      * Check for name starting with an illegal character.
9461      */
9462 #ifdef EBCDIC
9463     if (!islower(arg[0]))
9464 #else
9465     if (arg[0] < 'a' || arg[0] > 'z')
9466 #endif
9467 	return -1;
9468 
9469     is_term_opt = (arg[0] == 't' && arg[1] == '_');
9470     if (is_term_opt)
9471 	opt_idx = quick_tab[26];
9472     else
9473 	opt_idx = quick_tab[CharOrdLow(arg[0])];
9474     for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9475     {
9476 	if (STRCMP(arg, s) == 0)		    /* match full name */
9477 	    break;
9478     }
9479     if (s == NULL && !is_term_opt)
9480     {
9481 	opt_idx = quick_tab[CharOrdLow(arg[0])];
9482 	for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9483 	{
9484 	    s = options[opt_idx].shortname;
9485 	    if (s != NULL && STRCMP(arg, s) == 0)   /* match short name */
9486 		break;
9487 	    s = NULL;
9488 	}
9489     }
9490     if (s == NULL)
9491 	opt_idx = -1;
9492     return opt_idx;
9493 }
9494 
9495 #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
9496 /*
9497  * Get the value for an option.
9498  *
9499  * Returns:
9500  * Number or Toggle option: 1, *numval gets value.
9501  *	     String option: 0, *stringval gets allocated string.
9502  * Hidden Number or Toggle option: -1.
9503  *	     hidden String option: -2.
9504  *		   unknown option: -3.
9505  */
9506     int
9507 get_option_value(
9508     char_u	*name,
9509     long	*numval,
9510     char_u	**stringval,	    /* NULL when only checking existence */
9511     int		opt_flags)
9512 {
9513     int		opt_idx;
9514     char_u	*varp;
9515 
9516     opt_idx = findoption(name);
9517     if (opt_idx < 0)		    /* unknown option */
9518     {
9519 	int key;
9520 
9521 	if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9522 		&& (key = find_key_option(name, FALSE)) != 0)
9523 	{
9524 	    char_u key_name[2];
9525 	    char_u *p;
9526 
9527 	    if (key < 0)
9528 	    {
9529 		key_name[0] = KEY2TERMCAP0(key);
9530 		key_name[1] = KEY2TERMCAP1(key);
9531 	    }
9532 	    else
9533 	    {
9534 		key_name[0] = KS_KEY;
9535 		key_name[1] = (key & 0xff);
9536 	    }
9537 	    p = find_termcode(key_name);
9538 	    if (p != NULL)
9539 	    {
9540 		if (stringval != NULL)
9541 		    *stringval = vim_strsave(p);
9542 		return 0;
9543 	    }
9544 	}
9545 	return -3;
9546     }
9547 
9548     varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9549 
9550     if (options[opt_idx].flags & P_STRING)
9551     {
9552 	if (varp == NULL)		    /* hidden option */
9553 	    return -2;
9554 	if (stringval != NULL)
9555 	{
9556 #ifdef FEAT_CRYPT
9557 	    /* never return the value of the crypt key */
9558 	    if ((char_u **)varp == &curbuf->b_p_key
9559 						&& **(char_u **)(varp) != NUL)
9560 		*stringval = vim_strsave((char_u *)"*****");
9561 	    else
9562 #endif
9563 		*stringval = vim_strsave(*(char_u **)(varp));
9564 	}
9565 	return 0;
9566     }
9567 
9568     if (varp == NULL)		    /* hidden option */
9569 	return -1;
9570     if (options[opt_idx].flags & P_NUM)
9571 	*numval = *(long *)varp;
9572     else
9573     {
9574 	/* Special case: 'modified' is b_changed, but we also want to consider
9575 	 * it set when 'ff' or 'fenc' changed. */
9576 	if ((int *)varp == &curbuf->b_changed)
9577 	    *numval = curbufIsChanged();
9578 	else
9579 	    *numval = (long) *(int *)varp;
9580     }
9581     return 1;
9582 }
9583 #endif
9584 
9585 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
9586 /*
9587  * Returns the option attributes and its value. Unlike the above function it
9588  * will return either global value or local value of the option depending on
9589  * what was requested, but it will never return global value if it was
9590  * requested to return local one and vice versa. Neither it will return
9591  * buffer-local value if it was requested to return window-local one.
9592  *
9593  * Pretends that option is absent if it is not present in the requested scope
9594  * (i.e. has no global, window-local or buffer-local value depending on
9595  * opt_type). Uses
9596  *
9597  * Returned flags:
9598  *       0 hidden or unknown option, also option that does not have requested
9599  *	   type (see SREQ_* in vim.h)
9600  *  see SOPT_* in vim.h for other flags
9601  *
9602  * Possible opt_type values: see SREQ_* in vim.h
9603  */
9604     int
9605 get_option_value_strict(
9606     char_u	*name,
9607     long	*numval,
9608     char_u	**stringval,	    /* NULL when only obtaining attributes */
9609     int		opt_type,
9610     void	*from)
9611 {
9612     int		opt_idx;
9613     char_u	*varp = NULL;
9614     struct vimoption *p;
9615     int		r = 0;
9616 
9617     opt_idx = findoption(name);
9618     if (opt_idx < 0)
9619 	return 0;
9620 
9621     p = &(options[opt_idx]);
9622 
9623     /* Hidden option */
9624     if (p->var == NULL)
9625 	return 0;
9626 
9627     if (p->flags & P_BOOL)
9628 	r |= SOPT_BOOL;
9629     else if (p->flags & P_NUM)
9630 	r |= SOPT_NUM;
9631     else if (p->flags & P_STRING)
9632 	r |= SOPT_STRING;
9633 
9634     if (p->indir == PV_NONE)
9635     {
9636 	if (opt_type == SREQ_GLOBAL)
9637 	    r |= SOPT_GLOBAL;
9638 	else
9639 	    return 0; /* Did not request global-only option */
9640     }
9641     else
9642     {
9643 	if (p->indir & PV_BOTH)
9644 	    r |= SOPT_GLOBAL;
9645 	else if (opt_type == SREQ_GLOBAL)
9646 	    return 0; /* Requested global option */
9647 
9648 	if (p->indir & PV_WIN)
9649 	{
9650 	    if (opt_type == SREQ_BUF)
9651 		return 0; /* Did not request window-local option */
9652 	    else
9653 		r |= SOPT_WIN;
9654 	}
9655 	else if (p->indir & PV_BUF)
9656 	{
9657 	    if (opt_type == SREQ_WIN)
9658 		return 0; /* Did not request buffer-local option */
9659 	    else
9660 		r |= SOPT_BUF;
9661 	}
9662     }
9663 
9664     if (stringval == NULL)
9665 	return r;
9666 
9667     if (opt_type == SREQ_GLOBAL)
9668 	varp = p->var;
9669     else
9670     {
9671 	if (opt_type == SREQ_BUF)
9672 	{
9673 	    /* Special case: 'modified' is b_changed, but we also want to
9674 	     * consider it set when 'ff' or 'fenc' changed. */
9675 	    if (p->indir == PV_MOD)
9676 	    {
9677 		*numval = bufIsChanged((buf_T *)from);
9678 		varp = NULL;
9679 	    }
9680 #ifdef FEAT_CRYPT
9681 	    else if (p->indir == PV_KEY)
9682 	    {
9683 		/* never return the value of the crypt key */
9684 		*stringval = NULL;
9685 		varp = NULL;
9686 	    }
9687 #endif
9688 	    else
9689 	    {
9690 		buf_T *save_curbuf = curbuf;
9691 
9692 		// only getting a pointer, no need to use aucmd_prepbuf()
9693 		curbuf = (buf_T *)from;
9694 		curwin->w_buffer = curbuf;
9695 		varp = get_varp(p);
9696 		curbuf = save_curbuf;
9697 		curwin->w_buffer = curbuf;
9698 	    }
9699 	}
9700 	else if (opt_type == SREQ_WIN)
9701 	{
9702 	    win_T	*save_curwin = curwin;
9703 
9704 	    curwin = (win_T *)from;
9705 	    curbuf = curwin->w_buffer;
9706 	    varp = get_varp(p);
9707 	    curwin = save_curwin;
9708 	    curbuf = curwin->w_buffer;
9709 	}
9710 	if (varp == p->var)
9711 	    return (r | SOPT_UNSET);
9712     }
9713 
9714     if (varp != NULL)
9715     {
9716 	if (p->flags & P_STRING)
9717 	    *stringval = vim_strsave(*(char_u **)(varp));
9718 	else if (p->flags & P_NUM)
9719 	    *numval = *(long *) varp;
9720 	else
9721 	    *numval = *(int *)varp;
9722     }
9723 
9724     return r;
9725 }
9726 
9727 /*
9728  * Iterate over options. First argument is a pointer to a pointer to a
9729  * structure inside options[] array, second is option type like in the above
9730  * function.
9731  *
9732  * If first argument points to NULL it is assumed that iteration just started
9733  * and caller needs the very first value.
9734  * If first argument points to the end marker function returns NULL and sets
9735  * first argument to NULL.
9736  *
9737  * Returns full option name for current option on each call.
9738  */
9739     char_u *
9740 option_iter_next(void **option, int opt_type)
9741 {
9742     struct vimoption	*ret = NULL;
9743     do
9744     {
9745 	if (*option == NULL)
9746 	    *option = (void *) options;
9747 	else if (((struct vimoption *) (*option))->fullname == NULL)
9748 	{
9749 	    *option = NULL;
9750 	    return NULL;
9751 	}
9752 	else
9753 	    *option = (void *) (((struct vimoption *) (*option)) + 1);
9754 
9755 	ret = ((struct vimoption *) (*option));
9756 
9757 	/* Hidden option */
9758 	if (ret->var == NULL)
9759 	{
9760 	    ret = NULL;
9761 	    continue;
9762 	}
9763 
9764 	switch (opt_type)
9765 	{
9766 	    case SREQ_GLOBAL:
9767 		if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9768 		    ret = NULL;
9769 		break;
9770 	    case SREQ_BUF:
9771 		if (!(ret->indir & PV_BUF))
9772 		    ret = NULL;
9773 		break;
9774 	    case SREQ_WIN:
9775 		if (!(ret->indir & PV_WIN))
9776 		    ret = NULL;
9777 		break;
9778 	    default:
9779 		internal_error("option_iter_next()");
9780 		return NULL;
9781 	}
9782     }
9783     while (ret == NULL);
9784 
9785     return (char_u *)ret->fullname;
9786 }
9787 #endif
9788 
9789 /*
9790  * Set the value of option "name".
9791  * Use "string" for string options, use "number" for other options.
9792  *
9793  * Returns NULL on success or error message on error.
9794  */
9795     char *
9796 set_option_value(
9797     char_u	*name,
9798     long	number,
9799     char_u	*string,
9800     int		opt_flags)	/* OPT_LOCAL or 0 (both) */
9801 {
9802     int		opt_idx;
9803     char_u	*varp;
9804     long_u	flags;
9805 
9806     opt_idx = findoption(name);
9807     if (opt_idx < 0)
9808     {
9809 	int key;
9810 
9811 	if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9812 		&& (key = find_key_option(name, FALSE)) != 0)
9813 	{
9814 	    char_u key_name[2];
9815 
9816 	    if (key < 0)
9817 	    {
9818 		key_name[0] = KEY2TERMCAP0(key);
9819 		key_name[1] = KEY2TERMCAP1(key);
9820 	    }
9821 	    else
9822 	    {
9823 		key_name[0] = KS_KEY;
9824 		key_name[1] = (key & 0xff);
9825 	    }
9826 	    add_termcode(key_name, string, FALSE);
9827 	    if (full_screen)
9828 		ttest(FALSE);
9829 	    redraw_all_later(CLEAR);
9830 	    return NULL;
9831 	}
9832 
9833 	semsg(_("E355: Unknown option: %s"), name);
9834     }
9835     else
9836     {
9837 	flags = options[opt_idx].flags;
9838 #ifdef HAVE_SANDBOX
9839 	/* Disallow changing some options in the sandbox */
9840 	if (sandbox > 0 && (flags & P_SECURE))
9841 	{
9842 	    emsg(_(e_sandbox));
9843 	    return NULL;
9844 	}
9845 #endif
9846 	if (flags & P_STRING)
9847 	    return set_string_option(opt_idx, string, opt_flags);
9848 	else
9849 	{
9850 	    varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9851 	    if (varp != NULL)	/* hidden option is not changed */
9852 	    {
9853 		if (number == 0 && string != NULL)
9854 		{
9855 		    int idx;
9856 
9857 		    /* Either we are given a string or we are setting option
9858 		     * to zero. */
9859 		    for (idx = 0; string[idx] == '0'; ++idx)
9860 			;
9861 		    if (string[idx] != NUL || idx == 0)
9862 		    {
9863 			/* There's another character after zeros or the string
9864 			 * is empty.  In both cases, we are trying to set a
9865 			 * num option using a string. */
9866 			semsg(_("E521: Number required: &%s = '%s'"),
9867 								name, string);
9868 			return NULL;     /* do nothing as we hit an error */
9869 
9870 		    }
9871 		}
9872 		if (flags & P_NUM)
9873 		    return set_num_option(opt_idx, varp, number,
9874 							  NULL, 0, opt_flags);
9875 		else
9876 		    return set_bool_option(opt_idx, varp, (int)number,
9877 								   opt_flags);
9878 	    }
9879 	}
9880     }
9881     return NULL;
9882 }
9883 
9884 /*
9885  * Get the terminal code for a terminal option.
9886  * Returns NULL when not found.
9887  */
9888     char_u *
9889 get_term_code(char_u *tname)
9890 {
9891     int	    opt_idx;
9892     char_u  *varp;
9893 
9894     if (tname[0] != 't' || tname[1] != '_' ||
9895 	    tname[2] == NUL || tname[3] == NUL)
9896 	return NULL;
9897     if ((opt_idx = findoption(tname)) >= 0)
9898     {
9899 	varp = get_varp(&(options[opt_idx]));
9900 	if (varp != NULL)
9901 	    varp = *(char_u **)(varp);
9902 	return varp;
9903     }
9904     return find_termcode(tname + 2);
9905 }
9906 
9907     char_u *
9908 get_highlight_default(void)
9909 {
9910     int i;
9911 
9912     i = findoption((char_u *)"hl");
9913     if (i >= 0)
9914 	return options[i].def_val[VI_DEFAULT];
9915     return (char_u *)NULL;
9916 }
9917 
9918     char_u *
9919 get_encoding_default(void)
9920 {
9921     int i;
9922 
9923     i = findoption((char_u *)"enc");
9924     if (i >= 0)
9925 	return options[i].def_val[VI_DEFAULT];
9926     return (char_u *)NULL;
9927 }
9928 
9929 /*
9930  * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9931  * When "has_lt" is true there is a '<' before "*arg_arg".
9932  * Returns 0 when the key is not recognized.
9933  */
9934     static int
9935 find_key_option(char_u *arg_arg, int has_lt)
9936 {
9937     int		key = 0;
9938     int		modifiers;
9939     char_u	*arg = arg_arg;
9940 
9941     /*
9942      * Don't use get_special_key_code() for t_xx, we don't want it to call
9943      * add_termcap_entry().
9944      */
9945     if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9946 	key = TERMCAP2KEY(arg[2], arg[3]);
9947     else if (has_lt)
9948     {
9949 	--arg;			    /* put arg at the '<' */
9950 	modifiers = 0;
9951 	key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
9952 	if (modifiers)		    /* can't handle modifiers here */
9953 	    key = 0;
9954     }
9955     return key;
9956 }
9957 
9958 /*
9959  * if 'all' == 0: show changed options
9960  * if 'all' == 1: show all normal options
9961  * if 'all' == 2: show all terminal options
9962  */
9963     static void
9964 showoptions(
9965     int		all,
9966     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
9967 {
9968     struct vimoption	*p;
9969     int			col;
9970     int			isterm;
9971     char_u		*varp;
9972     struct vimoption	**items;
9973     int			item_count;
9974     int			run;
9975     int			row, rows;
9976     int			cols;
9977     int			i;
9978     int			len;
9979 
9980 #define INC 20
9981 #define GAP 3
9982 
9983     items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9984 								PARAM_COUNT));
9985     if (items == NULL)
9986 	return;
9987 
9988     /* Highlight title */
9989     if (all == 2)
9990 	msg_puts_title(_("\n--- Terminal codes ---"));
9991     else if (opt_flags & OPT_GLOBAL)
9992 	msg_puts_title(_("\n--- Global option values ---"));
9993     else if (opt_flags & OPT_LOCAL)
9994 	msg_puts_title(_("\n--- Local option values ---"));
9995     else
9996 	msg_puts_title(_("\n--- Options ---"));
9997 
9998     /*
9999      * do the loop two times:
10000      * 1. display the short items
10001      * 2. display the long items (only strings and numbers)
10002      */
10003     for (run = 1; run <= 2 && !got_int; ++run)
10004     {
10005 	/*
10006 	 * collect the items in items[]
10007 	 */
10008 	item_count = 0;
10009 	for (p = &options[0]; p->fullname != NULL; p++)
10010 	{
10011 	    // apply :filter /pat/
10012 	    if (message_filtered((char_u *) p->fullname))
10013 		continue;
10014 
10015 	    varp = NULL;
10016 	    isterm = istermoption(p);
10017 	    if (opt_flags != 0)
10018 	    {
10019 		if (p->indir != PV_NONE && !isterm)
10020 		    varp = get_varp_scope(p, opt_flags);
10021 	    }
10022 	    else
10023 		varp = get_varp(p);
10024 	    if (varp != NULL
10025 		    && ((all == 2 && isterm)
10026 			|| (all == 1 && !isterm)
10027 			|| (all == 0 && !optval_default(p, varp))))
10028 	    {
10029 		if (p->flags & P_BOOL)
10030 		    len = 1;		/* a toggle option fits always */
10031 		else
10032 		{
10033 		    option_value2string(p, opt_flags);
10034 		    len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10035 		}
10036 		if ((len <= INC - GAP && run == 1) ||
10037 						(len > INC - GAP && run == 2))
10038 		    items[item_count++] = p;
10039 	    }
10040 	}
10041 
10042 	/*
10043 	 * display the items
10044 	 */
10045 	if (run == 1)
10046 	{
10047 	    cols = (Columns + GAP - 3) / INC;
10048 	    if (cols == 0)
10049 		cols = 1;
10050 	    rows = (item_count + cols - 1) / cols;
10051 	}
10052 	else	/* run == 2 */
10053 	    rows = item_count;
10054 	for (row = 0; row < rows && !got_int; ++row)
10055 	{
10056 	    msg_putchar('\n');			/* go to next line */
10057 	    if (got_int)			/* 'q' typed in more */
10058 		break;
10059 	    col = 0;
10060 	    for (i = row; i < item_count; i += rows)
10061 	    {
10062 		msg_col = col;			/* make columns */
10063 		showoneopt(items[i], opt_flags);
10064 		col += INC;
10065 	    }
10066 	    out_flush();
10067 	    ui_breakcheck();
10068 	}
10069     }
10070     vim_free(items);
10071 }
10072 
10073 /*
10074  * Return TRUE if option "p" has its default value.
10075  */
10076     static int
10077 optval_default(struct vimoption *p, char_u *varp)
10078 {
10079     int		dvi;
10080 
10081     if (varp == NULL)
10082 	return TRUE;	    /* hidden option is always at default */
10083     dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10084     if (p->flags & P_NUM)
10085 	return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
10086     if (p->flags & P_BOOL)
10087 			/* the cast to long is required for Manx C, long_i is
10088 			 * needed for MSVC */
10089 	return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
10090     /* P_STRING */
10091     return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10092 }
10093 
10094 /*
10095  * showoneopt: show the value of one option
10096  * must not be called with a hidden option!
10097  */
10098     static void
10099 showoneopt(
10100     struct vimoption	*p,
10101     int			opt_flags)	/* OPT_LOCAL or OPT_GLOBAL */
10102 {
10103     char_u	*varp;
10104     int		save_silent = silent_mode;
10105 
10106     silent_mode = FALSE;
10107     info_message = TRUE;	/* use mch_msg(), not mch_errmsg() */
10108 
10109     varp = get_varp_scope(p, opt_flags);
10110 
10111     /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10112     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10113 					? !curbufIsChanged() : !*(int *)varp))
10114 	msg_puts("no");
10115     else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10116 	msg_puts("--");
10117     else
10118 	msg_puts("  ");
10119     msg_puts(p->fullname);
10120     if (!(p->flags & P_BOOL))
10121     {
10122 	msg_putchar('=');
10123 	/* put value string in NameBuff */
10124 	option_value2string(p, opt_flags);
10125 	msg_outtrans(NameBuff);
10126     }
10127 
10128     silent_mode = save_silent;
10129     info_message = FALSE;
10130 }
10131 
10132 /*
10133  * Write modified options as ":set" commands to a file.
10134  *
10135  * There are three values for "opt_flags":
10136  * OPT_GLOBAL:		   Write global option values and fresh values of
10137  *			   buffer-local options (used for start of a session
10138  *			   file).
10139  * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10140  *			   curwin (used for a vimrc file).
10141  * OPT_LOCAL:		   Write buffer-local option values for curbuf, fresh
10142  *			   and local values for window-local options of
10143  *			   curwin.  Local values are also written when at the
10144  *			   default value, because a modeline or autocommand
10145  *			   may have set them when doing ":edit file" and the
10146  *			   user has set them back at the default or fresh
10147  *			   value.
10148  *			   When "local_only" is TRUE, don't write fresh
10149  *			   values, only local values (for ":mkview").
10150  * (fresh value = value used for a new buffer or window for a local option).
10151  *
10152  * Return FAIL on error, OK otherwise.
10153  */
10154     int
10155 makeset(FILE *fd, int opt_flags, int local_only)
10156 {
10157     struct vimoption	*p;
10158     char_u		*varp;			/* currently used value */
10159     char_u		*varp_fresh;		/* local value */
10160     char_u		*varp_local = NULL;	/* fresh value */
10161     char		*cmd;
10162     int			round;
10163     int			pri;
10164 
10165     /*
10166      * The options that don't have a default (terminal name, columns, lines)
10167      * are never written.  Terminal options are also not written.
10168      * Do the loop over "options[]" twice: once for options with the
10169      * P_PRI_MKRC flag and once without.
10170      */
10171     for (pri = 1; pri >= 0; --pri)
10172     {
10173       for (p = &options[0]; !istermoption(p); p++)
10174 	if (!(p->flags & P_NO_MKRC)
10175 		&& !istermoption(p)
10176 		&& ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
10177 	{
10178 	    /* skip global option when only doing locals */
10179 	    if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10180 		continue;
10181 
10182 	    /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10183 	     * file, they are always buffer-specific. */
10184 	    if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10185 		continue;
10186 
10187 	    /* Global values are only written when not at the default value. */
10188 	    varp = get_varp_scope(p, opt_flags);
10189 	    if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10190 		continue;
10191 
10192 	    round = 2;
10193 	    if (p->indir != PV_NONE)
10194 	    {
10195 		if (p->var == VAR_WIN)
10196 		{
10197 		    /* skip window-local option when only doing globals */
10198 		    if (!(opt_flags & OPT_LOCAL))
10199 			continue;
10200 		    /* When fresh value of window-local option is not at the
10201 		     * default, need to write it too. */
10202 		    if (!(opt_flags & OPT_GLOBAL) && !local_only)
10203 		    {
10204 			varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10205 			if (!optval_default(p, varp_fresh))
10206 			{
10207 			    round = 1;
10208 			    varp_local = varp;
10209 			    varp = varp_fresh;
10210 			}
10211 		    }
10212 		}
10213 	    }
10214 
10215 	    /* Round 1: fresh value for window-local options.
10216 	     * Round 2: other values */
10217 	    for ( ; round <= 2; varp = varp_local, ++round)
10218 	    {
10219 		if (round == 1 || (opt_flags & OPT_GLOBAL))
10220 		    cmd = "set";
10221 		else
10222 		    cmd = "setlocal";
10223 
10224 		if (p->flags & P_BOOL)
10225 		{
10226 		    if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10227 			return FAIL;
10228 		}
10229 		else if (p->flags & P_NUM)
10230 		{
10231 		    if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10232 			return FAIL;
10233 		}
10234 		else    /* P_STRING */
10235 		{
10236 		    int		do_endif = FALSE;
10237 
10238 		    /* Don't set 'syntax' and 'filetype' again if the value is
10239 		     * already right, avoids reloading the syntax file. */
10240 		    if (
10241 #if defined(FEAT_SYN_HL)
10242 			    p->indir == PV_SYN ||
10243 #endif
10244 			    p->indir == PV_FT)
10245 		    {
10246 			if (fprintf(fd, "if &%s != '%s'", p->fullname,
10247 						       *(char_u **)(varp)) < 0
10248 				|| put_eol(fd) < 0)
10249 			    return FAIL;
10250 			do_endif = TRUE;
10251 		    }
10252 		    if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10253 							     p->flags) == FAIL)
10254 			return FAIL;
10255 		    if (do_endif)
10256 		    {
10257 			if (put_line(fd, "endif") == FAIL)
10258 			    return FAIL;
10259 		    }
10260 		}
10261 	    }
10262 	}
10263     }
10264     return OK;
10265 }
10266 
10267 #if defined(FEAT_FOLDING) || defined(PROTO)
10268 /*
10269  * Generate set commands for the local fold options only.  Used when
10270  * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10271  */
10272     int
10273 makefoldset(FILE *fd)
10274 {
10275     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
10276 # ifdef FEAT_EVAL
10277 	    || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
10278 								       == FAIL
10279 # endif
10280 	    || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
10281 								       == FAIL
10282 	    || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
10283 								       == FAIL
10284 	    || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10285 	    || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10286 	    || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10287 	    || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10288 	    )
10289 	return FAIL;
10290 
10291     return OK;
10292 }
10293 #endif
10294 
10295     static int
10296 put_setstring(
10297     FILE	*fd,
10298     char	*cmd,
10299     char	*name,
10300     char_u	**valuep,
10301     long_u	flags)
10302 {
10303     char_u	*s;
10304     char_u	*buf = NULL;
10305     char_u	*part = NULL;
10306     char_u	*p;
10307 
10308     if (fprintf(fd, "%s %s=", cmd, name) < 0)
10309 	return FAIL;
10310     if (*valuep != NULL)
10311     {
10312 	/* Output 'pastetoggle' as key names.  For other
10313 	 * options some characters have to be escaped with
10314 	 * CTRL-V or backslash */
10315 	if (valuep == &p_pt)
10316 	{
10317 	    s = *valuep;
10318 	    while (*s != NUL)
10319 		if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
10320 		    return FAIL;
10321 	}
10322 	// expand the option value, replace $HOME by ~
10323 	else if ((flags & P_EXPAND) != 0)
10324 	{
10325 	    int  size = (int)STRLEN(*valuep) + 1;
10326 
10327 	    // replace home directory in the whole option value into "buf"
10328 	    buf = alloc(size);
10329 	    if (buf == NULL)
10330 		goto fail;
10331 	    home_replace(NULL, *valuep, buf, size, FALSE);
10332 
10333 	    // If the option value is longer than MAXPATHL, we need to append
10334 	    // earch comma separated part of the option separately, so that it
10335 	    // can be expanded when read back.
10336 	    if (size >= MAXPATHL && (flags & P_COMMA) != 0
10337 					   && vim_strchr(*valuep, ',') != NULL)
10338 	    {
10339 		part = alloc(size);
10340 		if (part == NULL)
10341 		    goto fail;
10342 
10343 		// write line break to clear the option, e.g. ':set rtp='
10344 		if (put_eol(fd) == FAIL)
10345 		    goto fail;
10346 
10347 		p = buf;
10348 		while (*p != NUL)
10349 		{
10350 		    // for each comma separated option part, append value to
10351 		    // the option, :set rtp+=value
10352 		    if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10353 			goto fail;
10354 		    (void)copy_option_part(&p, part, size,  ",");
10355 		    if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10356 			goto fail;
10357 		}
10358 		vim_free(buf);
10359 		vim_free(part);
10360 		return OK;
10361 	    }
10362 	    if (put_escstr(fd, buf, 2) == FAIL)
10363 	    {
10364 		vim_free(buf);
10365 		return FAIL;
10366 	    }
10367 	    vim_free(buf);
10368 	}
10369 	else if (put_escstr(fd, *valuep, 2) == FAIL)
10370 	    return FAIL;
10371     }
10372     if (put_eol(fd) < 0)
10373 	return FAIL;
10374     return OK;
10375 fail:
10376     vim_free(buf);
10377     vim_free(part);
10378     return FAIL;
10379 }
10380 
10381     static int
10382 put_setnum(
10383     FILE	*fd,
10384     char	*cmd,
10385     char	*name,
10386     long	*valuep)
10387 {
10388     long	wc;
10389 
10390     if (fprintf(fd, "%s %s=", cmd, name) < 0)
10391 	return FAIL;
10392     if (wc_use_keyname((char_u *)valuep, &wc))
10393     {
10394 	/* print 'wildchar' and 'wildcharm' as a key name */
10395 	if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10396 	    return FAIL;
10397     }
10398     else if (fprintf(fd, "%ld", *valuep) < 0)
10399 	return FAIL;
10400     if (put_eol(fd) < 0)
10401 	return FAIL;
10402     return OK;
10403 }
10404 
10405     static int
10406 put_setbool(
10407     FILE	*fd,
10408     char	*cmd,
10409     char	*name,
10410     int		value)
10411 {
10412     if (value < 0)	/* global/local option using global value */
10413 	return OK;
10414     if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10415 	    || put_eol(fd) < 0)
10416 	return FAIL;
10417     return OK;
10418 }
10419 
10420 /*
10421  * Clear all the terminal options.
10422  * If the option has been allocated, free the memory.
10423  * Terminal options are never hidden or indirect.
10424  */
10425     void
10426 clear_termoptions(void)
10427 {
10428     /*
10429      * Reset a few things before clearing the old options. This may cause
10430      * outputting a few things that the terminal doesn't understand, but the
10431      * screen will be cleared later, so this is OK.
10432      */
10433 #ifdef FEAT_MOUSE_TTY
10434     mch_setmouse(FALSE);	    /* switch mouse off */
10435 #endif
10436 #ifdef FEAT_TITLE
10437     mch_restore_title(SAVE_RESTORE_BOTH);    /* restore window titles */
10438 #endif
10439 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10440     /* When starting the GUI close the display opened for the clipboard.
10441      * After restoring the title, because that will need the display. */
10442     if (gui.starting)
10443 	clear_xterm_clip();
10444 #endif
10445     stoptermcap();			/* stop termcap mode */
10446 
10447     free_termoptions();
10448 }
10449 
10450     void
10451 free_termoptions(void)
10452 {
10453     struct vimoption   *p;
10454 
10455     for (p = options; p->fullname != NULL; p++)
10456 	if (istermoption(p))
10457 	{
10458 	    if (p->flags & P_ALLOCED)
10459 		free_string_option(*(char_u **)(p->var));
10460 	    if (p->flags & P_DEF_ALLOCED)
10461 		free_string_option(p->def_val[VI_DEFAULT]);
10462 	    *(char_u **)(p->var) = empty_option;
10463 	    p->def_val[VI_DEFAULT] = empty_option;
10464 	    p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10465 #ifdef FEAT_EVAL
10466 	    // remember where the option was cleared
10467 	    set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10468 #endif
10469 	}
10470     clear_termcodes();
10471 }
10472 
10473 /*
10474  * Free the string for one term option, if it was allocated.
10475  * Set the string to empty_option and clear allocated flag.
10476  * "var" points to the option value.
10477  */
10478     void
10479 free_one_termoption(char_u *var)
10480 {
10481     struct vimoption   *p;
10482 
10483     for (p = &options[0]; p->fullname != NULL; p++)
10484 	if (p->var == var)
10485 	{
10486 	    if (p->flags & P_ALLOCED)
10487 		free_string_option(*(char_u **)(p->var));
10488 	    *(char_u **)(p->var) = empty_option;
10489 	    p->flags &= ~P_ALLOCED;
10490 	    break;
10491 	}
10492 }
10493 
10494 /*
10495  * Set the terminal option defaults to the current value.
10496  * Used after setting the terminal name.
10497  */
10498     void
10499 set_term_defaults(void)
10500 {
10501     struct vimoption   *p;
10502 
10503     for (p = &options[0]; p->fullname != NULL; p++)
10504     {
10505 	if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10506 	{
10507 	    if (p->flags & P_DEF_ALLOCED)
10508 	    {
10509 		free_string_option(p->def_val[VI_DEFAULT]);
10510 		p->flags &= ~P_DEF_ALLOCED;
10511 	    }
10512 	    p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10513 	    if (p->flags & P_ALLOCED)
10514 	    {
10515 		p->flags |= P_DEF_ALLOCED;
10516 		p->flags &= ~P_ALLOCED;	 /* don't free the value now */
10517 	    }
10518 	}
10519     }
10520 }
10521 
10522 /*
10523  * return TRUE if 'p' starts with 't_'
10524  */
10525     static int
10526 istermoption(struct vimoption *p)
10527 {
10528     return (p->fullname[0] == 't' && p->fullname[1] == '_');
10529 }
10530 
10531 /*
10532  * Compute columns for ruler and shown command. 'sc_col' is also used to
10533  * decide what the maximum length of a message on the status line can be.
10534  * If there is a status line for the last window, 'sc_col' is independent
10535  * of 'ru_col'.
10536  */
10537 
10538 #define COL_RULER 17	    /* columns needed by standard ruler */
10539 
10540     void
10541 comp_col(void)
10542 {
10543 #if defined(FEAT_CMDL_INFO)
10544     int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
10545 
10546     sc_col = 0;
10547     ru_col = 0;
10548     if (p_ru)
10549     {
10550 # ifdef FEAT_STL_OPT
10551 	ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10552 # else
10553 	ru_col = COL_RULER + 1;
10554 # endif
10555 	/* no last status line, adjust sc_col */
10556 	if (!last_has_status)
10557 	    sc_col = ru_col;
10558     }
10559     if (p_sc)
10560     {
10561 	sc_col += SHOWCMD_COLS;
10562 	if (!p_ru || last_has_status)	    /* no need for separating space */
10563 	    ++sc_col;
10564     }
10565     sc_col = Columns - sc_col;
10566     ru_col = Columns - ru_col;
10567     if (sc_col <= 0)		/* screen too narrow, will become a mess */
10568 	sc_col = 1;
10569     if (ru_col <= 0)
10570 	ru_col = 1;
10571 #else
10572     sc_col = Columns;
10573     ru_col = Columns;
10574 #endif
10575 }
10576 
10577 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
10578 /*
10579  * Unset local option value, similar to ":set opt<".
10580  */
10581     void
10582 unset_global_local_option(char_u *name, void *from)
10583 {
10584     struct vimoption *p;
10585     int		opt_idx;
10586     buf_T	*buf = (buf_T *)from;
10587 
10588     opt_idx = findoption(name);
10589     if (opt_idx < 0)
10590 	return;
10591     p = &(options[opt_idx]);
10592 
10593     switch ((int)p->indir)
10594     {
10595 	/* global option with local value: use local value if it's been set */
10596 	case PV_EP:
10597 	    clear_string_option(&buf->b_p_ep);
10598 	    break;
10599 	case PV_KP:
10600 	    clear_string_option(&buf->b_p_kp);
10601 	    break;
10602 	case PV_PATH:
10603 	    clear_string_option(&buf->b_p_path);
10604 	    break;
10605 	case PV_AR:
10606 	    buf->b_p_ar = -1;
10607 	    break;
10608 	case PV_BKC:
10609 	    clear_string_option(&buf->b_p_bkc);
10610 	    buf->b_bkc_flags = 0;
10611 	    break;
10612 	case PV_TAGS:
10613 	    clear_string_option(&buf->b_p_tags);
10614 	    break;
10615 	case PV_TC:
10616 	    clear_string_option(&buf->b_p_tc);
10617 	    buf->b_tc_flags = 0;
10618 	    break;
10619         case PV_SISO:
10620             curwin->w_p_siso = -1;
10621             break;
10622         case PV_SO:
10623             curwin->w_p_so = -1;
10624             break;
10625 #ifdef FEAT_FIND_ID
10626 	case PV_DEF:
10627 	    clear_string_option(&buf->b_p_def);
10628 	    break;
10629 	case PV_INC:
10630 	    clear_string_option(&buf->b_p_inc);
10631 	    break;
10632 #endif
10633 #ifdef FEAT_INS_EXPAND
10634 	case PV_DICT:
10635 	    clear_string_option(&buf->b_p_dict);
10636 	    break;
10637 	case PV_TSR:
10638 	    clear_string_option(&buf->b_p_tsr);
10639 	    break;
10640 #endif
10641 	case PV_FP:
10642 	    clear_string_option(&buf->b_p_fp);
10643 	    break;
10644 #ifdef FEAT_QUICKFIX
10645 	case PV_EFM:
10646 	    clear_string_option(&buf->b_p_efm);
10647 	    break;
10648 	case PV_GP:
10649 	    clear_string_option(&buf->b_p_gp);
10650 	    break;
10651 	case PV_MP:
10652 	    clear_string_option(&buf->b_p_mp);
10653 	    break;
10654 #endif
10655 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10656 	case PV_BEXPR:
10657 	    clear_string_option(&buf->b_p_bexpr);
10658 	    break;
10659 #endif
10660 #if defined(FEAT_CRYPT)
10661 	case PV_CM:
10662 	    clear_string_option(&buf->b_p_cm);
10663 	    break;
10664 #endif
10665 #ifdef FEAT_STL_OPT
10666 	case PV_STL:
10667 	    clear_string_option(&((win_T *)from)->w_p_stl);
10668 	    break;
10669 #endif
10670 	case PV_UL:
10671 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10672 	    break;
10673 #ifdef FEAT_LISP
10674 	case PV_LW:
10675 	    clear_string_option(&buf->b_p_lw);
10676 	    break;
10677 #endif
10678 	case PV_MENC:
10679 	    clear_string_option(&buf->b_p_menc);
10680 	    break;
10681     }
10682 }
10683 #endif
10684 
10685 /*
10686  * Get pointer to option variable, depending on local or global scope.
10687  */
10688     static char_u *
10689 get_varp_scope(struct vimoption *p, int opt_flags)
10690 {
10691     if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10692     {
10693 	if (p->var == VAR_WIN)
10694 	    return (char_u *)GLOBAL_WO(get_varp(p));
10695 	return p->var;
10696     }
10697     if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
10698     {
10699 	switch ((int)p->indir)
10700 	{
10701 	    case PV_FP:   return (char_u *)&(curbuf->b_p_fp);
10702 #ifdef FEAT_QUICKFIX
10703 	    case PV_EFM:  return (char_u *)&(curbuf->b_p_efm);
10704 	    case PV_GP:   return (char_u *)&(curbuf->b_p_gp);
10705 	    case PV_MP:   return (char_u *)&(curbuf->b_p_mp);
10706 #endif
10707 	    case PV_EP:   return (char_u *)&(curbuf->b_p_ep);
10708 	    case PV_KP:   return (char_u *)&(curbuf->b_p_kp);
10709 	    case PV_PATH: return (char_u *)&(curbuf->b_p_path);
10710 	    case PV_AR:   return (char_u *)&(curbuf->b_p_ar);
10711 	    case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
10712 	    case PV_TC:   return (char_u *)&(curbuf->b_p_tc);
10713             case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10714             case PV_SO:   return (char_u *)&(curwin->w_p_so);
10715 #ifdef FEAT_FIND_ID
10716 	    case PV_DEF:  return (char_u *)&(curbuf->b_p_def);
10717 	    case PV_INC:  return (char_u *)&(curbuf->b_p_inc);
10718 #endif
10719 #ifdef FEAT_INS_EXPAND
10720 	    case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10721 	    case PV_TSR:  return (char_u *)&(curbuf->b_p_tsr);
10722 #endif
10723 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10724 	    case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10725 #endif
10726 #if defined(FEAT_CRYPT)
10727 	    case PV_CM:	  return (char_u *)&(curbuf->b_p_cm);
10728 #endif
10729 #ifdef FEAT_STL_OPT
10730 	    case PV_STL:  return (char_u *)&(curwin->w_p_stl);
10731 #endif
10732 	    case PV_UL:   return (char_u *)&(curbuf->b_p_ul);
10733 #ifdef FEAT_LISP
10734 	    case PV_LW:   return (char_u *)&(curbuf->b_p_lw);
10735 #endif
10736 	    case PV_BKC:  return (char_u *)&(curbuf->b_p_bkc);
10737 	    case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10738 	}
10739 	return NULL; /* "cannot happen" */
10740     }
10741     return get_varp(p);
10742 }
10743 
10744 /*
10745  * Get pointer to option variable.
10746  */
10747     static char_u *
10748 get_varp(struct vimoption *p)
10749 {
10750     /* hidden option, always return NULL */
10751     if (p->var == NULL)
10752 	return NULL;
10753 
10754     switch ((int)p->indir)
10755     {
10756 	case PV_NONE:	return p->var;
10757 
10758 	/* global option with local value: use local value if it's been set */
10759 	case PV_EP:	return *curbuf->b_p_ep != NUL
10760 				    ? (char_u *)&curbuf->b_p_ep : p->var;
10761 	case PV_KP:	return *curbuf->b_p_kp != NUL
10762 				    ? (char_u *)&curbuf->b_p_kp : p->var;
10763 	case PV_PATH:	return *curbuf->b_p_path != NUL
10764 				    ? (char_u *)&(curbuf->b_p_path) : p->var;
10765 	case PV_AR:	return curbuf->b_p_ar >= 0
10766 				    ? (char_u *)&(curbuf->b_p_ar) : p->var;
10767 	case PV_TAGS:	return *curbuf->b_p_tags != NUL
10768 				    ? (char_u *)&(curbuf->b_p_tags) : p->var;
10769 	case PV_TC:	return *curbuf->b_p_tc != NUL
10770 				    ? (char_u *)&(curbuf->b_p_tc) : p->var;
10771 	case PV_BKC:	return *curbuf->b_p_bkc != NUL
10772 				    ? (char_u *)&(curbuf->b_p_bkc) : p->var;
10773 	case PV_SISO:	return curwin->w_p_siso >= 0
10774 				    ? (char_u *)&(curwin->w_p_siso) : p->var;
10775 	case PV_SO:	return curwin->w_p_so >= 0
10776 				    ? (char_u *)&(curwin->w_p_so) : p->var;
10777 #ifdef FEAT_FIND_ID
10778 	case PV_DEF:	return *curbuf->b_p_def != NUL
10779 				    ? (char_u *)&(curbuf->b_p_def) : p->var;
10780 	case PV_INC:	return *curbuf->b_p_inc != NUL
10781 				    ? (char_u *)&(curbuf->b_p_inc) : p->var;
10782 #endif
10783 #ifdef FEAT_INS_EXPAND
10784 	case PV_DICT:	return *curbuf->b_p_dict != NUL
10785 				    ? (char_u *)&(curbuf->b_p_dict) : p->var;
10786 	case PV_TSR:	return *curbuf->b_p_tsr != NUL
10787 				    ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10788 #endif
10789 	case PV_FP:	return *curbuf->b_p_fp != NUL
10790 				    ? (char_u *)&(curbuf->b_p_fp) : p->var;
10791 #ifdef FEAT_QUICKFIX
10792 	case PV_EFM:	return *curbuf->b_p_efm != NUL
10793 				    ? (char_u *)&(curbuf->b_p_efm) : p->var;
10794 	case PV_GP:	return *curbuf->b_p_gp != NUL
10795 				    ? (char_u *)&(curbuf->b_p_gp) : p->var;
10796 	case PV_MP:	return *curbuf->b_p_mp != NUL
10797 				    ? (char_u *)&(curbuf->b_p_mp) : p->var;
10798 #endif
10799 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10800 	case PV_BEXPR:	return *curbuf->b_p_bexpr != NUL
10801 				    ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10802 #endif
10803 #if defined(FEAT_CRYPT)
10804 	case PV_CM:	return *curbuf->b_p_cm != NUL
10805 				    ? (char_u *)&(curbuf->b_p_cm) : p->var;
10806 #endif
10807 #ifdef FEAT_STL_OPT
10808 	case PV_STL:	return *curwin->w_p_stl != NUL
10809 				    ? (char_u *)&(curwin->w_p_stl) : p->var;
10810 #endif
10811 	case PV_UL:	return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10812 				    ? (char_u *)&(curbuf->b_p_ul) : p->var;
10813 #ifdef FEAT_LISP
10814 	case PV_LW:	return *curbuf->b_p_lw != NUL
10815 				    ? (char_u *)&(curbuf->b_p_lw) : p->var;
10816 #endif
10817 	case PV_MENC:	return *curbuf->b_p_menc != NUL
10818 				    ? (char_u *)&(curbuf->b_p_menc) : p->var;
10819 
10820 #ifdef FEAT_ARABIC
10821 	case PV_ARAB:	return (char_u *)&(curwin->w_p_arab);
10822 #endif
10823 	case PV_LIST:	return (char_u *)&(curwin->w_p_list);
10824 #ifdef FEAT_SPELL
10825 	case PV_SPELL:	return (char_u *)&(curwin->w_p_spell);
10826 #endif
10827 #ifdef FEAT_SYN_HL
10828 	case PV_CUC:	return (char_u *)&(curwin->w_p_cuc);
10829 	case PV_CUL:	return (char_u *)&(curwin->w_p_cul);
10830 	case PV_CC:	return (char_u *)&(curwin->w_p_cc);
10831 #endif
10832 #ifdef FEAT_DIFF
10833 	case PV_DIFF:	return (char_u *)&(curwin->w_p_diff);
10834 #endif
10835 #ifdef FEAT_FOLDING
10836 	case PV_FDC:	return (char_u *)&(curwin->w_p_fdc);
10837 	case PV_FEN:	return (char_u *)&(curwin->w_p_fen);
10838 	case PV_FDI:	return (char_u *)&(curwin->w_p_fdi);
10839 	case PV_FDL:	return (char_u *)&(curwin->w_p_fdl);
10840 	case PV_FDM:	return (char_u *)&(curwin->w_p_fdm);
10841 	case PV_FML:	return (char_u *)&(curwin->w_p_fml);
10842 	case PV_FDN:	return (char_u *)&(curwin->w_p_fdn);
10843 # ifdef FEAT_EVAL
10844 	case PV_FDE:	return (char_u *)&(curwin->w_p_fde);
10845 	case PV_FDT:	return (char_u *)&(curwin->w_p_fdt);
10846 # endif
10847 	case PV_FMR:	return (char_u *)&(curwin->w_p_fmr);
10848 #endif
10849 	case PV_NU:	return (char_u *)&(curwin->w_p_nu);
10850 	case PV_RNU:	return (char_u *)&(curwin->w_p_rnu);
10851 #ifdef FEAT_LINEBREAK
10852 	case PV_NUW:	return (char_u *)&(curwin->w_p_nuw);
10853 #endif
10854 	case PV_WFH:	return (char_u *)&(curwin->w_p_wfh);
10855 	case PV_WFW:	return (char_u *)&(curwin->w_p_wfw);
10856 #if defined(FEAT_QUICKFIX)
10857 	case PV_PVW:	return (char_u *)&(curwin->w_p_pvw);
10858 #endif
10859 #ifdef FEAT_RIGHTLEFT
10860 	case PV_RL:	return (char_u *)&(curwin->w_p_rl);
10861 	case PV_RLC:	return (char_u *)&(curwin->w_p_rlc);
10862 #endif
10863 	case PV_SCROLL:	return (char_u *)&(curwin->w_p_scr);
10864 	case PV_WRAP:	return (char_u *)&(curwin->w_p_wrap);
10865 #ifdef FEAT_LINEBREAK
10866 	case PV_LBR:	return (char_u *)&(curwin->w_p_lbr);
10867 	case PV_BRI:	return (char_u *)&(curwin->w_p_bri);
10868 	case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
10869 #endif
10870 	case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10871 	case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10872 #ifdef FEAT_CONCEAL
10873 	case PV_COCU:   return (char_u *)&(curwin->w_p_cocu);
10874 	case PV_COLE:   return (char_u *)&(curwin->w_p_cole);
10875 #endif
10876 #ifdef FEAT_TERMINAL
10877 	case PV_TWK:    return (char_u *)&(curwin->w_p_twk);
10878 	case PV_TWS:    return (char_u *)&(curwin->w_p_tws);
10879 	case PV_TWSL:	return (char_u *)&(curbuf->b_p_twsl);
10880 #endif
10881 
10882 	case PV_AI:	return (char_u *)&(curbuf->b_p_ai);
10883 	case PV_BIN:	return (char_u *)&(curbuf->b_p_bin);
10884 	case PV_BOMB:	return (char_u *)&(curbuf->b_p_bomb);
10885 	case PV_BH:	return (char_u *)&(curbuf->b_p_bh);
10886 	case PV_BT:	return (char_u *)&(curbuf->b_p_bt);
10887 	case PV_BL:	return (char_u *)&(curbuf->b_p_bl);
10888 	case PV_CI:	return (char_u *)&(curbuf->b_p_ci);
10889 #ifdef FEAT_CINDENT
10890 	case PV_CIN:	return (char_u *)&(curbuf->b_p_cin);
10891 	case PV_CINK:	return (char_u *)&(curbuf->b_p_cink);
10892 	case PV_CINO:	return (char_u *)&(curbuf->b_p_cino);
10893 #endif
10894 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10895 	case PV_CINW:	return (char_u *)&(curbuf->b_p_cinw);
10896 #endif
10897 #ifdef FEAT_COMMENTS
10898 	case PV_COM:	return (char_u *)&(curbuf->b_p_com);
10899 #endif
10900 #ifdef FEAT_FOLDING
10901 	case PV_CMS:	return (char_u *)&(curbuf->b_p_cms);
10902 #endif
10903 #ifdef FEAT_INS_EXPAND
10904 	case PV_CPT:	return (char_u *)&(curbuf->b_p_cpt);
10905 #endif
10906 #ifdef FEAT_COMPL_FUNC
10907 	case PV_CFU:	return (char_u *)&(curbuf->b_p_cfu);
10908 	case PV_OFU:	return (char_u *)&(curbuf->b_p_ofu);
10909 #endif
10910 	case PV_EOL:	return (char_u *)&(curbuf->b_p_eol);
10911 	case PV_FIXEOL:	return (char_u *)&(curbuf->b_p_fixeol);
10912 	case PV_ET:	return (char_u *)&(curbuf->b_p_et);
10913 	case PV_FENC:	return (char_u *)&(curbuf->b_p_fenc);
10914 	case PV_FF:	return (char_u *)&(curbuf->b_p_ff);
10915 	case PV_FT:	return (char_u *)&(curbuf->b_p_ft);
10916 	case PV_FO:	return (char_u *)&(curbuf->b_p_fo);
10917 	case PV_FLP:	return (char_u *)&(curbuf->b_p_flp);
10918 	case PV_IMI:	return (char_u *)&(curbuf->b_p_iminsert);
10919 	case PV_IMS:	return (char_u *)&(curbuf->b_p_imsearch);
10920 	case PV_INF:	return (char_u *)&(curbuf->b_p_inf);
10921 	case PV_ISK:	return (char_u *)&(curbuf->b_p_isk);
10922 #ifdef FEAT_FIND_ID
10923 # ifdef FEAT_EVAL
10924 	case PV_INEX:	return (char_u *)&(curbuf->b_p_inex);
10925 # endif
10926 #endif
10927 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10928 	case PV_INDE:	return (char_u *)&(curbuf->b_p_inde);
10929 	case PV_INDK:	return (char_u *)&(curbuf->b_p_indk);
10930 #endif
10931 #ifdef FEAT_EVAL
10932 	case PV_FEX:	return (char_u *)&(curbuf->b_p_fex);
10933 #endif
10934 #ifdef FEAT_CRYPT
10935 	case PV_KEY:	return (char_u *)&(curbuf->b_p_key);
10936 #endif
10937 #ifdef FEAT_LISP
10938 	case PV_LISP:	return (char_u *)&(curbuf->b_p_lisp);
10939 #endif
10940 	case PV_ML:	return (char_u *)&(curbuf->b_p_ml);
10941 	case PV_MPS:	return (char_u *)&(curbuf->b_p_mps);
10942 	case PV_MA:	return (char_u *)&(curbuf->b_p_ma);
10943 	case PV_MOD:	return (char_u *)&(curbuf->b_changed);
10944 	case PV_NF:	return (char_u *)&(curbuf->b_p_nf);
10945 	case PV_PI:	return (char_u *)&(curbuf->b_p_pi);
10946 #ifdef FEAT_TEXTOBJ
10947 	case PV_QE:	return (char_u *)&(curbuf->b_p_qe);
10948 #endif
10949 	case PV_RO:	return (char_u *)&(curbuf->b_p_ro);
10950 #ifdef FEAT_SMARTINDENT
10951 	case PV_SI:	return (char_u *)&(curbuf->b_p_si);
10952 #endif
10953 	case PV_SN:	return (char_u *)&(curbuf->b_p_sn);
10954 	case PV_STS:	return (char_u *)&(curbuf->b_p_sts);
10955 #ifdef FEAT_SEARCHPATH
10956 	case PV_SUA:	return (char_u *)&(curbuf->b_p_sua);
10957 #endif
10958 	case PV_SWF:	return (char_u *)&(curbuf->b_p_swf);
10959 #ifdef FEAT_SYN_HL
10960 	case PV_SMC:	return (char_u *)&(curbuf->b_p_smc);
10961 	case PV_SYN:	return (char_u *)&(curbuf->b_p_syn);
10962 #endif
10963 #ifdef FEAT_SPELL
10964 	case PV_SPC:	return (char_u *)&(curwin->w_s->b_p_spc);
10965 	case PV_SPF:	return (char_u *)&(curwin->w_s->b_p_spf);
10966 	case PV_SPL:	return (char_u *)&(curwin->w_s->b_p_spl);
10967 #endif
10968 	case PV_SW:	return (char_u *)&(curbuf->b_p_sw);
10969 	case PV_TS:	return (char_u *)&(curbuf->b_p_ts);
10970 	case PV_TW:	return (char_u *)&(curbuf->b_p_tw);
10971 	case PV_TX:	return (char_u *)&(curbuf->b_p_tx);
10972 #ifdef FEAT_PERSISTENT_UNDO
10973 	case PV_UDF:	return (char_u *)&(curbuf->b_p_udf);
10974 #endif
10975 	case PV_WM:	return (char_u *)&(curbuf->b_p_wm);
10976 #ifdef FEAT_KEYMAP
10977 	case PV_KMAP:	return (char_u *)&(curbuf->b_p_keymap);
10978 #endif
10979 #ifdef FEAT_SIGNS
10980 	case PV_SCL:	return (char_u *)&(curwin->w_p_scl);
10981 #endif
10982 #ifdef FEAT_VARTABS
10983 	case PV_VSTS:	return (char_u *)&(curbuf->b_p_vsts);
10984 	case PV_VTS:	return (char_u *)&(curbuf->b_p_vts);
10985 #endif
10986 	default:	iemsg(_("E356: get_varp ERROR"));
10987     }
10988     /* always return a valid pointer to avoid a crash! */
10989     return (char_u *)&(curbuf->b_p_wm);
10990 }
10991 
10992 /*
10993  * Get the value of 'equalprg', either the buffer-local one or the global one.
10994  */
10995     char_u *
10996 get_equalprg(void)
10997 {
10998     if (*curbuf->b_p_ep == NUL)
10999 	return p_ep;
11000     return curbuf->b_p_ep;
11001 }
11002 
11003 /*
11004  * Copy options from one window to another.
11005  * Used when splitting a window.
11006  */
11007     void
11008 win_copy_options(win_T *wp_from, win_T *wp_to)
11009 {
11010     copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11011     copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11012 #if defined(FEAT_LINEBREAK)
11013     briopt_check(wp_to);
11014 #endif
11015 }
11016 
11017 /*
11018  * Copy the options from one winopt_T to another.
11019  * Doesn't free the old option values in "to", use clear_winopt() for that.
11020  * The 'scroll' option is not copied, because it depends on the window height.
11021  * The 'previewwindow' option is reset, there can be only one preview window.
11022  */
11023     void
11024 copy_winopt(winopt_T *from, winopt_T *to)
11025 {
11026 #ifdef FEAT_ARABIC
11027     to->wo_arab = from->wo_arab;
11028 #endif
11029     to->wo_list = from->wo_list;
11030     to->wo_nu = from->wo_nu;
11031     to->wo_rnu = from->wo_rnu;
11032 #ifdef FEAT_LINEBREAK
11033     to->wo_nuw = from->wo_nuw;
11034 #endif
11035 #ifdef FEAT_RIGHTLEFT
11036     to->wo_rl  = from->wo_rl;
11037     to->wo_rlc = vim_strsave(from->wo_rlc);
11038 #endif
11039 #ifdef FEAT_STL_OPT
11040     to->wo_stl = vim_strsave(from->wo_stl);
11041 #endif
11042     to->wo_wrap = from->wo_wrap;
11043 #ifdef FEAT_DIFF
11044     to->wo_wrap_save = from->wo_wrap_save;
11045 #endif
11046 #ifdef FEAT_LINEBREAK
11047     to->wo_lbr = from->wo_lbr;
11048     to->wo_bri = from->wo_bri;
11049     to->wo_briopt = vim_strsave(from->wo_briopt);
11050 #endif
11051     to->wo_scb = from->wo_scb;
11052     to->wo_scb_save = from->wo_scb_save;
11053     to->wo_crb = from->wo_crb;
11054     to->wo_crb_save = from->wo_crb_save;
11055 #ifdef FEAT_SPELL
11056     to->wo_spell = from->wo_spell;
11057 #endif
11058 #ifdef FEAT_SYN_HL
11059     to->wo_cuc = from->wo_cuc;
11060     to->wo_cul = from->wo_cul;
11061     to->wo_cc = vim_strsave(from->wo_cc);
11062 #endif
11063 #ifdef FEAT_DIFF
11064     to->wo_diff = from->wo_diff;
11065     to->wo_diff_saved = from->wo_diff_saved;
11066 #endif
11067 #ifdef FEAT_CONCEAL
11068     to->wo_cocu = vim_strsave(from->wo_cocu);
11069     to->wo_cole = from->wo_cole;
11070 #endif
11071 #ifdef FEAT_TERMINAL
11072     to->wo_twk = vim_strsave(from->wo_twk);
11073     to->wo_tws = vim_strsave(from->wo_tws);
11074 #endif
11075 #ifdef FEAT_FOLDING
11076     to->wo_fdc = from->wo_fdc;
11077     to->wo_fdc_save = from->wo_fdc_save;
11078     to->wo_fen = from->wo_fen;
11079     to->wo_fen_save = from->wo_fen_save;
11080     to->wo_fdi = vim_strsave(from->wo_fdi);
11081     to->wo_fml = from->wo_fml;
11082     to->wo_fdl = from->wo_fdl;
11083     to->wo_fdl_save = from->wo_fdl_save;
11084     to->wo_fdm = vim_strsave(from->wo_fdm);
11085     to->wo_fdm_save = from->wo_diff_saved
11086 			      ? vim_strsave(from->wo_fdm_save) : empty_option;
11087     to->wo_fdn = from->wo_fdn;
11088 # ifdef FEAT_EVAL
11089     to->wo_fde = vim_strsave(from->wo_fde);
11090     to->wo_fdt = vim_strsave(from->wo_fdt);
11091 # endif
11092     to->wo_fmr = vim_strsave(from->wo_fmr);
11093 #endif
11094 #ifdef FEAT_SIGNS
11095     to->wo_scl = vim_strsave(from->wo_scl);
11096 #endif
11097     check_winopt(to);		/* don't want NULL pointers */
11098 }
11099 
11100 /*
11101  * Check string options in a window for a NULL value.
11102  */
11103     void
11104 check_win_options(win_T *win)
11105 {
11106     check_winopt(&win->w_onebuf_opt);
11107     check_winopt(&win->w_allbuf_opt);
11108 }
11109 
11110 /*
11111  * Check for NULL pointers in a winopt_T and replace them with empty_option.
11112  */
11113     static void
11114 check_winopt(winopt_T *wop UNUSED)
11115 {
11116 #ifdef FEAT_FOLDING
11117     check_string_option(&wop->wo_fdi);
11118     check_string_option(&wop->wo_fdm);
11119     check_string_option(&wop->wo_fdm_save);
11120 # ifdef FEAT_EVAL
11121     check_string_option(&wop->wo_fde);
11122     check_string_option(&wop->wo_fdt);
11123 # endif
11124     check_string_option(&wop->wo_fmr);
11125 #endif
11126 #ifdef FEAT_SIGNS
11127     check_string_option(&wop->wo_scl);
11128 #endif
11129 #ifdef FEAT_RIGHTLEFT
11130     check_string_option(&wop->wo_rlc);
11131 #endif
11132 #ifdef FEAT_STL_OPT
11133     check_string_option(&wop->wo_stl);
11134 #endif
11135 #ifdef FEAT_SYN_HL
11136     check_string_option(&wop->wo_cc);
11137 #endif
11138 #ifdef FEAT_CONCEAL
11139     check_string_option(&wop->wo_cocu);
11140 #endif
11141 #ifdef FEAT_TERMINAL
11142     check_string_option(&wop->wo_twk);
11143     check_string_option(&wop->wo_tws);
11144 #endif
11145 #ifdef FEAT_LINEBREAK
11146     check_string_option(&wop->wo_briopt);
11147 #endif
11148 }
11149 
11150 /*
11151  * Free the allocated memory inside a winopt_T.
11152  */
11153     void
11154 clear_winopt(winopt_T *wop UNUSED)
11155 {
11156 #ifdef FEAT_FOLDING
11157     clear_string_option(&wop->wo_fdi);
11158     clear_string_option(&wop->wo_fdm);
11159     clear_string_option(&wop->wo_fdm_save);
11160 # ifdef FEAT_EVAL
11161     clear_string_option(&wop->wo_fde);
11162     clear_string_option(&wop->wo_fdt);
11163 # endif
11164     clear_string_option(&wop->wo_fmr);
11165 #endif
11166 #ifdef FEAT_SIGNS
11167     clear_string_option(&wop->wo_scl);
11168 #endif
11169 #ifdef FEAT_LINEBREAK
11170     clear_string_option(&wop->wo_briopt);
11171 #endif
11172 #ifdef FEAT_RIGHTLEFT
11173     clear_string_option(&wop->wo_rlc);
11174 #endif
11175 #ifdef FEAT_STL_OPT
11176     clear_string_option(&wop->wo_stl);
11177 #endif
11178 #ifdef FEAT_SYN_HL
11179     clear_string_option(&wop->wo_cc);
11180 #endif
11181 #ifdef FEAT_CONCEAL
11182     clear_string_option(&wop->wo_cocu);
11183 #endif
11184 #ifdef FEAT_TERMINAL
11185     clear_string_option(&wop->wo_twk);
11186     clear_string_option(&wop->wo_tws);
11187 #endif
11188 }
11189 
11190 /*
11191  * Copy global option values to local options for one buffer.
11192  * Used when creating a new buffer and sometimes when entering a buffer.
11193  * flags:
11194  * BCO_ENTER	We will enter the buf buffer.
11195  * BCO_ALWAYS	Always copy the options, but only set b_p_initialized when
11196  *		appropriate.
11197  * BCO_NOHELP	Don't copy the values to a help buffer.
11198  */
11199     void
11200 buf_copy_options(buf_T *buf, int flags)
11201 {
11202     int		should_copy = TRUE;
11203     char_u	*save_p_isk = NULL;	    /* init for GCC */
11204     int		dont_do_help;
11205     int		did_isk = FALSE;
11206 
11207     /*
11208      * Skip this when the option defaults have not been set yet.  Happens when
11209      * main() allocates the first buffer.
11210      */
11211     if (p_cpo != NULL)
11212     {
11213 	/*
11214 	 * Always copy when entering and 'cpo' contains 'S'.
11215 	 * Don't copy when already initialized.
11216 	 * Don't copy when 'cpo' contains 's' and not entering.
11217 	 * 'S'	BCO_ENTER  initialized	's'  should_copy
11218 	 * yes	  yes	       X	 X	TRUE
11219 	 * yes	  no	      yes	 X	FALSE
11220 	 * no	   X	      yes	 X	FALSE
11221 	 *  X	  no	      no	yes	FALSE
11222 	 *  X	  no	      no	no	TRUE
11223 	 * no	  yes	      no	 X	TRUE
11224 	 */
11225 	if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11226 		&& (buf->b_p_initialized
11227 		    || (!(flags & BCO_ENTER)
11228 			&& vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11229 	    should_copy = FALSE;
11230 
11231 	if (should_copy || (flags & BCO_ALWAYS))
11232 	{
11233 	    /* Don't copy the options specific to a help buffer when
11234 	     * BCO_NOHELP is given or the options were initialized already
11235 	     * (jumping back to a help file with CTRL-T or CTRL-O) */
11236 	    dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11237 						       || buf->b_p_initialized;
11238 	    if (dont_do_help)		/* don't free b_p_isk */
11239 	    {
11240 		save_p_isk = buf->b_p_isk;
11241 		buf->b_p_isk = NULL;
11242 	    }
11243 	    /*
11244 	     * Always free the allocated strings.  If not already initialized,
11245 	     * reset 'readonly' and copy 'fileformat'.
11246 	     */
11247 	    if (!buf->b_p_initialized)
11248 	    {
11249 		free_buf_options(buf, TRUE);
11250 		buf->b_p_ro = FALSE;		/* don't copy readonly */
11251 		buf->b_p_tx = p_tx;
11252 		buf->b_p_fenc = vim_strsave(p_fenc);
11253 		switch (*p_ffs)
11254 		{
11255 		    case 'm':
11256 			buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11257 		    case 'd':
11258 			buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11259 		    case 'u':
11260 			buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11261 		    default:
11262 			buf->b_p_ff = vim_strsave(p_ff);
11263 		}
11264 		if (buf->b_p_ff != NULL)
11265 		    buf->b_start_ffc = *buf->b_p_ff;
11266 		buf->b_p_bh = empty_option;
11267 		buf->b_p_bt = empty_option;
11268 	    }
11269 	    else
11270 		free_buf_options(buf, FALSE);
11271 
11272 	    buf->b_p_ai = p_ai;
11273 	    buf->b_p_ai_nopaste = p_ai_nopaste;
11274 	    buf->b_p_sw = p_sw;
11275 	    buf->b_p_tw = p_tw;
11276 	    buf->b_p_tw_nopaste = p_tw_nopaste;
11277 	    buf->b_p_tw_nobin = p_tw_nobin;
11278 	    buf->b_p_wm = p_wm;
11279 	    buf->b_p_wm_nopaste = p_wm_nopaste;
11280 	    buf->b_p_wm_nobin = p_wm_nobin;
11281 	    buf->b_p_bin = p_bin;
11282 	    buf->b_p_bomb = p_bomb;
11283 	    buf->b_p_fixeol = p_fixeol;
11284 	    buf->b_p_et = p_et;
11285 	    buf->b_p_et_nobin = p_et_nobin;
11286 	    buf->b_p_et_nopaste = p_et_nopaste;
11287 	    buf->b_p_ml = p_ml;
11288 	    buf->b_p_ml_nobin = p_ml_nobin;
11289 	    buf->b_p_inf = p_inf;
11290 	    buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
11291 #ifdef FEAT_INS_EXPAND
11292 	    buf->b_p_cpt = vim_strsave(p_cpt);
11293 #endif
11294 #ifdef FEAT_COMPL_FUNC
11295 	    buf->b_p_cfu = vim_strsave(p_cfu);
11296 	    buf->b_p_ofu = vim_strsave(p_ofu);
11297 #endif
11298 	    buf->b_p_sts = p_sts;
11299 	    buf->b_p_sts_nopaste = p_sts_nopaste;
11300 #ifdef FEAT_VARTABS
11301 	    buf->b_p_vsts = vim_strsave(p_vsts);
11302 	    if (p_vsts && p_vsts != empty_option)
11303 		tabstop_set(p_vsts, &buf->b_p_vsts_array);
11304 	    else
11305 		buf->b_p_vsts_array = 0;
11306 	    buf->b_p_vsts_nopaste = p_vsts_nopaste
11307 				 ? vim_strsave(p_vsts_nopaste) : NULL;
11308 #endif
11309 	    buf->b_p_sn = p_sn;
11310 #ifdef FEAT_COMMENTS
11311 	    buf->b_p_com = vim_strsave(p_com);
11312 #endif
11313 #ifdef FEAT_FOLDING
11314 	    buf->b_p_cms = vim_strsave(p_cms);
11315 #endif
11316 	    buf->b_p_fo = vim_strsave(p_fo);
11317 	    buf->b_p_flp = vim_strsave(p_flp);
11318 	    buf->b_p_nf = vim_strsave(p_nf);
11319 	    buf->b_p_mps = vim_strsave(p_mps);
11320 #ifdef FEAT_SMARTINDENT
11321 	    buf->b_p_si = p_si;
11322 #endif
11323 	    buf->b_p_ci = p_ci;
11324 #ifdef FEAT_CINDENT
11325 	    buf->b_p_cin = p_cin;
11326 	    buf->b_p_cink = vim_strsave(p_cink);
11327 	    buf->b_p_cino = vim_strsave(p_cino);
11328 #endif
11329 	    /* Don't copy 'filetype', it must be detected */
11330 	    buf->b_p_ft = empty_option;
11331 	    buf->b_p_pi = p_pi;
11332 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11333 	    buf->b_p_cinw = vim_strsave(p_cinw);
11334 #endif
11335 #ifdef FEAT_LISP
11336 	    buf->b_p_lisp = p_lisp;
11337 #endif
11338 #ifdef FEAT_SYN_HL
11339 	    /* Don't copy 'syntax', it must be set */
11340 	    buf->b_p_syn = empty_option;
11341 	    buf->b_p_smc = p_smc;
11342 	    buf->b_s.b_syn_isk = empty_option;
11343 #endif
11344 #ifdef FEAT_SPELL
11345 	    buf->b_s.b_p_spc = vim_strsave(p_spc);
11346 	    (void)compile_cap_prog(&buf->b_s);
11347 	    buf->b_s.b_p_spf = vim_strsave(p_spf);
11348 	    buf->b_s.b_p_spl = vim_strsave(p_spl);
11349 #endif
11350 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11351 	    buf->b_p_inde = vim_strsave(p_inde);
11352 	    buf->b_p_indk = vim_strsave(p_indk);
11353 #endif
11354 	    buf->b_p_fp = empty_option;
11355 #if defined(FEAT_EVAL)
11356 	    buf->b_p_fex = vim_strsave(p_fex);
11357 #endif
11358 #ifdef FEAT_CRYPT
11359 	    buf->b_p_key = vim_strsave(p_key);
11360 #endif
11361 #ifdef FEAT_SEARCHPATH
11362 	    buf->b_p_sua = vim_strsave(p_sua);
11363 #endif
11364 #ifdef FEAT_KEYMAP
11365 	    buf->b_p_keymap = vim_strsave(p_keymap);
11366 	    buf->b_kmap_state |= KEYMAP_INIT;
11367 #endif
11368 #ifdef FEAT_TERMINAL
11369 	    buf->b_p_twsl = p_twsl;
11370 #endif
11371 	    /* This isn't really an option, but copying the langmap and IME
11372 	     * state from the current buffer is better than resetting it. */
11373 	    buf->b_p_iminsert = p_iminsert;
11374 	    buf->b_p_imsearch = p_imsearch;
11375 
11376 	    /* options that are normally global but also have a local value
11377 	     * are not copied, start using the global value */
11378 	    buf->b_p_ar = -1;
11379 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
11380 	    buf->b_p_bkc = empty_option;
11381 	    buf->b_bkc_flags = 0;
11382 #ifdef FEAT_QUICKFIX
11383 	    buf->b_p_gp = empty_option;
11384 	    buf->b_p_mp = empty_option;
11385 	    buf->b_p_efm = empty_option;
11386 #endif
11387 	    buf->b_p_ep = empty_option;
11388 	    buf->b_p_kp = empty_option;
11389 	    buf->b_p_path = empty_option;
11390 	    buf->b_p_tags = empty_option;
11391 	    buf->b_p_tc = empty_option;
11392 	    buf->b_tc_flags = 0;
11393 #ifdef FEAT_FIND_ID
11394 	    buf->b_p_def = empty_option;
11395 	    buf->b_p_inc = empty_option;
11396 # ifdef FEAT_EVAL
11397 	    buf->b_p_inex = vim_strsave(p_inex);
11398 # endif
11399 #endif
11400 #ifdef FEAT_INS_EXPAND
11401 	    buf->b_p_dict = empty_option;
11402 	    buf->b_p_tsr = empty_option;
11403 #endif
11404 #ifdef FEAT_TEXTOBJ
11405 	    buf->b_p_qe = vim_strsave(p_qe);
11406 #endif
11407 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11408 	    buf->b_p_bexpr = empty_option;
11409 #endif
11410 #if defined(FEAT_CRYPT)
11411 	    buf->b_p_cm = empty_option;
11412 #endif
11413 #ifdef FEAT_PERSISTENT_UNDO
11414 	    buf->b_p_udf = p_udf;
11415 #endif
11416 #ifdef FEAT_LISP
11417 	    buf->b_p_lw = empty_option;
11418 #endif
11419 	    buf->b_p_menc = empty_option;
11420 
11421 	    /*
11422 	     * Don't copy the options set by ex_help(), use the saved values,
11423 	     * when going from a help buffer to a non-help buffer.
11424 	     * Don't touch these at all when BCO_NOHELP is used and going from
11425 	     * or to a help buffer.
11426 	     */
11427 	    if (dont_do_help)
11428 	    {
11429 		buf->b_p_isk = save_p_isk;
11430 #ifdef FEAT_VARTABS
11431 		if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11432 		    tabstop_set(p_vts, &buf->b_p_vts_array);
11433 		else
11434 		    buf->b_p_vts_array = NULL;
11435 #endif
11436 	    }
11437 	    else
11438 	    {
11439 		buf->b_p_isk = vim_strsave(p_isk);
11440 		did_isk = TRUE;
11441 		buf->b_p_ts = p_ts;
11442 #ifdef FEAT_VARTABS
11443 		buf->b_p_vts = vim_strsave(p_vts);
11444 		if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11445 		    tabstop_set(p_vts, &buf->b_p_vts_array);
11446 		else
11447 		    buf->b_p_vts_array = NULL;
11448 #endif
11449 		buf->b_help = FALSE;
11450 		if (buf->b_p_bt[0] == 'h')
11451 		    clear_string_option(&buf->b_p_bt);
11452 		buf->b_p_ma = p_ma;
11453 	    }
11454 	}
11455 
11456 	/*
11457 	 * When the options should be copied (ignoring BCO_ALWAYS), set the
11458 	 * flag that indicates that the options have been initialized.
11459 	 */
11460 	if (should_copy)
11461 	    buf->b_p_initialized = TRUE;
11462     }
11463 
11464     check_buf_options(buf);	    /* make sure we don't have NULLs */
11465     if (did_isk)
11466 	(void)buf_init_chartab(buf, FALSE);
11467 }
11468 
11469 /*
11470  * Reset the 'modifiable' option and its default value.
11471  */
11472     void
11473 reset_modifiable(void)
11474 {
11475     int		opt_idx;
11476 
11477     curbuf->b_p_ma = FALSE;
11478     p_ma = FALSE;
11479     opt_idx = findoption((char_u *)"ma");
11480     if (opt_idx >= 0)
11481 	options[opt_idx].def_val[VI_DEFAULT] = FALSE;
11482 }
11483 
11484 /*
11485  * Set the global value for 'iminsert' to the local value.
11486  */
11487     void
11488 set_iminsert_global(void)
11489 {
11490     p_iminsert = curbuf->b_p_iminsert;
11491 }
11492 
11493 /*
11494  * Set the global value for 'imsearch' to the local value.
11495  */
11496     void
11497 set_imsearch_global(void)
11498 {
11499     p_imsearch = curbuf->b_p_imsearch;
11500 }
11501 
11502 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11503 static int expand_option_idx = -1;
11504 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11505 static int expand_option_flags = 0;
11506 
11507     void
11508 set_context_in_set_cmd(
11509     expand_T	*xp,
11510     char_u	*arg,
11511     int		opt_flags)	/* OPT_GLOBAL and/or OPT_LOCAL */
11512 {
11513     int		nextchar;
11514     long_u	flags = 0;	/* init for GCC */
11515     int		opt_idx = 0;	/* init for GCC */
11516     char_u	*p;
11517     char_u	*s;
11518     int		is_term_option = FALSE;
11519     int		key;
11520 
11521     expand_option_flags = opt_flags;
11522 
11523     xp->xp_context = EXPAND_SETTINGS;
11524     if (*arg == NUL)
11525     {
11526 	xp->xp_pattern = arg;
11527 	return;
11528     }
11529     p = arg + STRLEN(arg) - 1;
11530     if (*p == ' ' && *(p - 1) != '\\')
11531     {
11532 	xp->xp_pattern = p + 1;
11533 	return;
11534     }
11535     while (p > arg)
11536     {
11537 	s = p;
11538 	/* count number of backslashes before ' ' or ',' */
11539 	if (*p == ' ' || *p == ',')
11540 	{
11541 	    while (s > arg && *(s - 1) == '\\')
11542 		--s;
11543 	}
11544 	/* break at a space with an even number of backslashes */
11545 	if (*p == ' ' && ((p - s) & 1) == 0)
11546 	{
11547 	    ++p;
11548 	    break;
11549 	}
11550 	--p;
11551     }
11552     if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
11553     {
11554 	xp->xp_context = EXPAND_BOOL_SETTINGS;
11555 	p += 2;
11556     }
11557     if (STRNCMP(p, "inv", 3) == 0)
11558     {
11559 	xp->xp_context = EXPAND_BOOL_SETTINGS;
11560 	p += 3;
11561     }
11562     xp->xp_pattern = arg = p;
11563     if (*arg == '<')
11564     {
11565 	while (*p != '>')
11566 	    if (*p++ == NUL)	    /* expand terminal option name */
11567 		return;
11568 	key = get_special_key_code(arg + 1);
11569 	if (key == 0)		    /* unknown name */
11570 	{
11571 	    xp->xp_context = EXPAND_NOTHING;
11572 	    return;
11573 	}
11574 	nextchar = *++p;
11575 	is_term_option = TRUE;
11576 	expand_option_name[2] = KEY2TERMCAP0(key);
11577 	expand_option_name[3] = KEY2TERMCAP1(key);
11578     }
11579     else
11580     {
11581 	if (p[0] == 't' && p[1] == '_')
11582 	{
11583 	    p += 2;
11584 	    if (*p != NUL)
11585 		++p;
11586 	    if (*p == NUL)
11587 		return;		/* expand option name */
11588 	    nextchar = *++p;
11589 	    is_term_option = TRUE;
11590 	    expand_option_name[2] = p[-2];
11591 	    expand_option_name[3] = p[-1];
11592 	}
11593 	else
11594 	{
11595 		/* Allow * wildcard */
11596 	    while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11597 		p++;
11598 	    if (*p == NUL)
11599 		return;
11600 	    nextchar = *p;
11601 	    *p = NUL;
11602 	    opt_idx = findoption(arg);
11603 	    *p = nextchar;
11604 	    if (opt_idx == -1 || options[opt_idx].var == NULL)
11605 	    {
11606 		xp->xp_context = EXPAND_NOTHING;
11607 		return;
11608 	    }
11609 	    flags = options[opt_idx].flags;
11610 	    if (flags & P_BOOL)
11611 	    {
11612 		xp->xp_context = EXPAND_NOTHING;
11613 		return;
11614 	    }
11615 	}
11616     }
11617     /* handle "-=" and "+=" */
11618     if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11619     {
11620 	++p;
11621 	nextchar = '=';
11622     }
11623     if ((nextchar != '=' && nextchar != ':')
11624 				    || xp->xp_context == EXPAND_BOOL_SETTINGS)
11625     {
11626 	xp->xp_context = EXPAND_UNSUCCESSFUL;
11627 	return;
11628     }
11629     if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11630     {
11631 	xp->xp_context = EXPAND_OLD_SETTING;
11632 	if (is_term_option)
11633 	    expand_option_idx = -1;
11634 	else
11635 	    expand_option_idx = opt_idx;
11636 	xp->xp_pattern = p + 1;
11637 	return;
11638     }
11639     xp->xp_context = EXPAND_NOTHING;
11640     if (is_term_option || (flags & P_NUM))
11641 	return;
11642 
11643     xp->xp_pattern = p + 1;
11644 
11645     if (flags & P_EXPAND)
11646     {
11647 	p = options[opt_idx].var;
11648 	if (p == (char_u *)&p_bdir
11649 		|| p == (char_u *)&p_dir
11650 		|| p == (char_u *)&p_path
11651 		|| p == (char_u *)&p_pp
11652 		|| p == (char_u *)&p_rtp
11653 #ifdef FEAT_SEARCHPATH
11654 		|| p == (char_u *)&p_cdpath
11655 #endif
11656 #ifdef FEAT_SESSION
11657 		|| p == (char_u *)&p_vdir
11658 #endif
11659 		)
11660 	{
11661 	    xp->xp_context = EXPAND_DIRECTORIES;
11662 	    if (p == (char_u *)&p_path
11663 #ifdef FEAT_SEARCHPATH
11664 		    || p == (char_u *)&p_cdpath
11665 #endif
11666 		   )
11667 		xp->xp_backslash = XP_BS_THREE;
11668 	    else
11669 		xp->xp_backslash = XP_BS_ONE;
11670 	}
11671 	else
11672 	{
11673 	    xp->xp_context = EXPAND_FILES;
11674 	    /* for 'tags' need three backslashes for a space */
11675 	    if (p == (char_u *)&p_tags)
11676 		xp->xp_backslash = XP_BS_THREE;
11677 	    else
11678 		xp->xp_backslash = XP_BS_ONE;
11679 	}
11680     }
11681 
11682     /* For an option that is a list of file names, find the start of the
11683      * last file name. */
11684     for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11685     {
11686 	/* count number of backslashes before ' ' or ',' */
11687 	if (*p == ' ' || *p == ',')
11688 	{
11689 	    s = p;
11690 	    while (s > xp->xp_pattern && *(s - 1) == '\\')
11691 		--s;
11692 	    if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11693 		    || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11694 	    {
11695 		xp->xp_pattern = p + 1;
11696 		break;
11697 	    }
11698 	}
11699 
11700 #ifdef FEAT_SPELL
11701 	/* for 'spellsuggest' start at "file:" */
11702 	if (options[opt_idx].var == (char_u *)&p_sps
11703 					       && STRNCMP(p, "file:", 5) == 0)
11704 	{
11705 	    xp->xp_pattern = p + 5;
11706 	    break;
11707 	}
11708 #endif
11709     }
11710 
11711     return;
11712 }
11713 
11714     int
11715 ExpandSettings(
11716     expand_T	*xp,
11717     regmatch_T	*regmatch,
11718     int		*num_file,
11719     char_u	***file)
11720 {
11721     int		num_normal = 0;	    /* Nr of matching non-term-code settings */
11722     int		num_term = 0;	    /* Nr of matching terminal code settings */
11723     int		opt_idx;
11724     int		match;
11725     int		count = 0;
11726     char_u	*str;
11727     int		loop;
11728     int		is_term_opt;
11729     char_u	name_buf[MAX_KEY_NAME_LEN];
11730     static char *(names[]) = {"all", "termcap"};
11731     int		ic = regmatch->rm_ic;	/* remember the ignore-case flag */
11732 
11733     /* do this loop twice:
11734      * loop == 0: count the number of matching options
11735      * loop == 1: copy the matching options into allocated memory
11736      */
11737     for (loop = 0; loop <= 1; ++loop)
11738     {
11739 	regmatch->rm_ic = ic;
11740 	if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11741 	{
11742 	    for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11743 								      ++match)
11744 		if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11745 		{
11746 		    if (loop == 0)
11747 			num_normal++;
11748 		    else
11749 			(*file)[count++] = vim_strsave((char_u *)names[match]);
11750 		}
11751 	}
11752 	for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11753 								    opt_idx++)
11754 	{
11755 	    if (options[opt_idx].var == NULL)
11756 		continue;
11757 	    if (xp->xp_context == EXPAND_BOOL_SETTINGS
11758 	      && !(options[opt_idx].flags & P_BOOL))
11759 		continue;
11760 	    is_term_opt = istermoption(&options[opt_idx]);
11761 	    if (is_term_opt && num_normal > 0)
11762 		continue;
11763 	    match = FALSE;
11764 	    if (vim_regexec(regmatch, str, (colnr_T)0)
11765 		    || (options[opt_idx].shortname != NULL
11766 			&& vim_regexec(regmatch,
11767 			   (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11768 		match = TRUE;
11769 	    else if (is_term_opt)
11770 	    {
11771 		name_buf[0] = '<';
11772 		name_buf[1] = 't';
11773 		name_buf[2] = '_';
11774 		name_buf[3] = str[2];
11775 		name_buf[4] = str[3];
11776 		name_buf[5] = '>';
11777 		name_buf[6] = NUL;
11778 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11779 		{
11780 		    match = TRUE;
11781 		    str = name_buf;
11782 		}
11783 	    }
11784 	    if (match)
11785 	    {
11786 		if (loop == 0)
11787 		{
11788 		    if (is_term_opt)
11789 			num_term++;
11790 		    else
11791 			num_normal++;
11792 		}
11793 		else
11794 		    (*file)[count++] = vim_strsave(str);
11795 	    }
11796 	}
11797 	/*
11798 	 * Check terminal key codes, these are not in the option table
11799 	 */
11800 	if (xp->xp_context != EXPAND_BOOL_SETTINGS  && num_normal == 0)
11801 	{
11802 	    for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11803 	    {
11804 		if (!isprint(str[0]) || !isprint(str[1]))
11805 		    continue;
11806 
11807 		name_buf[0] = 't';
11808 		name_buf[1] = '_';
11809 		name_buf[2] = str[0];
11810 		name_buf[3] = str[1];
11811 		name_buf[4] = NUL;
11812 
11813 		match = FALSE;
11814 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11815 		    match = TRUE;
11816 		else
11817 		{
11818 		    name_buf[0] = '<';
11819 		    name_buf[1] = 't';
11820 		    name_buf[2] = '_';
11821 		    name_buf[3] = str[0];
11822 		    name_buf[4] = str[1];
11823 		    name_buf[5] = '>';
11824 		    name_buf[6] = NUL;
11825 
11826 		    if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11827 			match = TRUE;
11828 		}
11829 		if (match)
11830 		{
11831 		    if (loop == 0)
11832 			num_term++;
11833 		    else
11834 			(*file)[count++] = vim_strsave(name_buf);
11835 		}
11836 	    }
11837 
11838 	    /*
11839 	     * Check special key names.
11840 	     */
11841 	    regmatch->rm_ic = TRUE;		/* ignore case here */
11842 	    for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11843 	    {
11844 		name_buf[0] = '<';
11845 		STRCPY(name_buf + 1, str);
11846 		STRCAT(name_buf, ">");
11847 
11848 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11849 		{
11850 		    if (loop == 0)
11851 			num_term++;
11852 		    else
11853 			(*file)[count++] = vim_strsave(name_buf);
11854 		}
11855 	    }
11856 	}
11857 	if (loop == 0)
11858 	{
11859 	    if (num_normal > 0)
11860 		*num_file = num_normal;
11861 	    else if (num_term > 0)
11862 		*num_file = num_term;
11863 	    else
11864 		return OK;
11865 	    *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11866 	    if (*file == NULL)
11867 	    {
11868 		*file = (char_u **)"";
11869 		return FAIL;
11870 	    }
11871 	}
11872     }
11873     return OK;
11874 }
11875 
11876     int
11877 ExpandOldSetting(int *num_file, char_u ***file)
11878 {
11879     char_u  *var = NULL;	/* init for GCC */
11880     char_u  *buf;
11881 
11882     *num_file = 0;
11883     *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11884     if (*file == NULL)
11885 	return FAIL;
11886 
11887     /*
11888      * For a terminal key code expand_option_idx is < 0.
11889      */
11890     if (expand_option_idx < 0)
11891     {
11892 	var = find_termcode(expand_option_name + 2);
11893 	if (var == NULL)
11894 	    expand_option_idx = findoption(expand_option_name);
11895     }
11896 
11897     if (expand_option_idx >= 0)
11898     {
11899 	/* put string of option value in NameBuff */
11900 	option_value2string(&options[expand_option_idx], expand_option_flags);
11901 	var = NameBuff;
11902     }
11903     else if (var == NULL)
11904 	var = (char_u *)"";
11905 
11906     /* A backslash is required before some characters.  This is the reverse of
11907      * what happens in do_set(). */
11908     buf = vim_strsave_escaped(var, escape_chars);
11909 
11910     if (buf == NULL)
11911     {
11912 	VIM_CLEAR(*file);
11913 	return FAIL;
11914     }
11915 
11916 #ifdef BACKSLASH_IN_FILENAME
11917     /* For MS-Windows et al. we don't double backslashes at the start and
11918      * before a file name character. */
11919     for (var = buf; *var != NUL; MB_PTR_ADV(var))
11920 	if (var[0] == '\\' && var[1] == '\\'
11921 		&& expand_option_idx >= 0
11922 		&& (options[expand_option_idx].flags & P_EXPAND)
11923 		&& vim_isfilec(var[2])
11924 		&& (var[2] != '\\' || (var == buf && var[4] != '\\')))
11925 	    STRMOVE(var, var + 1);
11926 #endif
11927 
11928     *file[0] = buf;
11929     *num_file = 1;
11930     return OK;
11931 }
11932 #endif
11933 
11934 /*
11935  * Get the value for the numeric or string option *opp in a nice format into
11936  * NameBuff[].  Must not be called with a hidden option!
11937  */
11938     static void
11939 option_value2string(
11940     struct vimoption	*opp,
11941     int			opt_flags)	/* OPT_GLOBAL and/or OPT_LOCAL */
11942 {
11943     char_u	*varp;
11944 
11945     varp = get_varp_scope(opp, opt_flags);
11946 
11947     if (opp->flags & P_NUM)
11948     {
11949 	long wc = 0;
11950 
11951 	if (wc_use_keyname(varp, &wc))
11952 	    STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11953 	else if (wc != 0)
11954 	    STRCPY(NameBuff, transchar((int)wc));
11955 	else
11956 	    sprintf((char *)NameBuff, "%ld", *(long *)varp);
11957     }
11958     else    /* P_STRING */
11959     {
11960 	varp = *(char_u **)(varp);
11961 	if (varp == NULL)		    /* just in case */
11962 	    NameBuff[0] = NUL;
11963 #ifdef FEAT_CRYPT
11964 	/* don't show the actual value of 'key', only that it's set */
11965 	else if (opp->var == (char_u *)&p_key && *varp)
11966 	    STRCPY(NameBuff, "*****");
11967 #endif
11968 	else if (opp->flags & P_EXPAND)
11969 	    home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11970 	/* Translate 'pastetoggle' into special key names */
11971 	else if ((char_u **)opp->var == &p_pt)
11972 	    str2specialbuf(p_pt, NameBuff, MAXPATHL);
11973 	else
11974 	    vim_strncpy(NameBuff, varp, MAXPATHL - 1);
11975     }
11976 }
11977 
11978 /*
11979  * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11980  * printed as a keyname.
11981  * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11982  */
11983     static int
11984 wc_use_keyname(char_u *varp, long *wcp)
11985 {
11986     if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11987     {
11988 	*wcp = *(long *)varp;
11989 	if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11990 	    return TRUE;
11991     }
11992     return FALSE;
11993 }
11994 
11995 #if defined(FEAT_LANGMAP) || defined(PROTO)
11996 /*
11997  * Any character has an equivalent 'langmap' character.  This is used for
11998  * keyboards that have a special language mode that sends characters above
11999  * 128 (although other characters can be translated too).  The "to" field is a
12000  * Vim command character.  This avoids having to switch the keyboard back to
12001  * ASCII mode when leaving Insert mode.
12002  *
12003  * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12004  * commands.
12005  * langmap_mapga.ga_data is a sorted table of langmap_entry_T.  This does the
12006  * same as langmap_mapchar[] for characters >= 256.
12007  *
12008  * Use growarray for 'langmap' chars >= 256
12009  */
12010 typedef struct
12011 {
12012     int	    from;
12013     int     to;
12014 } langmap_entry_T;
12015 
12016 static garray_T langmap_mapga;
12017 
12018 /*
12019  * Search for an entry in "langmap_mapga" for "from".  If found set the "to"
12020  * field.  If not found insert a new entry at the appropriate location.
12021  */
12022     static void
12023 langmap_set_entry(int from, int to)
12024 {
12025     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12026     int		    a = 0;
12027     int		    b = langmap_mapga.ga_len;
12028 
12029     /* Do a binary search for an existing entry. */
12030     while (a != b)
12031     {
12032 	int i = (a + b) / 2;
12033 	int d = entries[i].from - from;
12034 
12035 	if (d == 0)
12036 	{
12037 	    entries[i].to = to;
12038 	    return;
12039 	}
12040 	if (d < 0)
12041 	    a = i + 1;
12042 	else
12043 	    b = i;
12044     }
12045 
12046     if (ga_grow(&langmap_mapga, 1) != OK)
12047 	return;  /* out of memory */
12048 
12049     /* insert new entry at position "a" */
12050     entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12051     mch_memmove(entries + 1, entries,
12052 			(langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12053     ++langmap_mapga.ga_len;
12054     entries[0].from = from;
12055     entries[0].to = to;
12056 }
12057 
12058 /*
12059  * Apply 'langmap' to multi-byte character "c" and return the result.
12060  */
12061     int
12062 langmap_adjust_mb(int c)
12063 {
12064     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12065     int a = 0;
12066     int b = langmap_mapga.ga_len;
12067 
12068     while (a != b)
12069     {
12070 	int i = (a + b) / 2;
12071 	int d = entries[i].from - c;
12072 
12073 	if (d == 0)
12074 	    return entries[i].to;  /* found matching entry */
12075 	if (d < 0)
12076 	    a = i + 1;
12077 	else
12078 	    b = i;
12079     }
12080     return c;  /* no entry found, return "c" unmodified */
12081 }
12082 
12083     static void
12084 langmap_init(void)
12085 {
12086     int i;
12087 
12088     for (i = 0; i < 256; i++)
12089 	langmap_mapchar[i] = i;	 /* we init with a one-to-one map */
12090     ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
12091 }
12092 
12093 /*
12094  * Called when langmap option is set; the language map can be
12095  * changed at any time!
12096  */
12097     static void
12098 langmap_set(void)
12099 {
12100     char_u  *p;
12101     char_u  *p2;
12102     int	    from, to;
12103 
12104     ga_clear(&langmap_mapga);		    /* clear the previous map first */
12105     langmap_init();			    /* back to one-to-one map */
12106 
12107     for (p = p_langmap; p[0] != NUL; )
12108     {
12109 	for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
12110 							       MB_PTR_ADV(p2))
12111 	{
12112 	    if (p2[0] == '\\' && p2[1] != NUL)
12113 		++p2;
12114 	}
12115 	if (p2[0] == ';')
12116 	    ++p2;	    /* abcd;ABCD form, p2 points to A */
12117 	else
12118 	    p2 = NULL;	    /* aAbBcCdD form, p2 is NULL */
12119 	while (p[0])
12120 	{
12121 	    if (p[0] == ',')
12122 	    {
12123 		++p;
12124 		break;
12125 	    }
12126 	    if (p[0] == '\\' && p[1] != NUL)
12127 		++p;
12128 	    from = (*mb_ptr2char)(p);
12129 	    to = NUL;
12130 	    if (p2 == NULL)
12131 	    {
12132 		MB_PTR_ADV(p);
12133 		if (p[0] != ',')
12134 		{
12135 		    if (p[0] == '\\')
12136 			++p;
12137 		    to = (*mb_ptr2char)(p);
12138 		}
12139 	    }
12140 	    else
12141 	    {
12142 		if (p2[0] != ',')
12143 		{
12144 		    if (p2[0] == '\\')
12145 			++p2;
12146 		    to = (*mb_ptr2char)(p2);
12147 		}
12148 	    }
12149 	    if (to == NUL)
12150 	    {
12151 		semsg(_("E357: 'langmap': Matching character missing for %s"),
12152 							     transchar(from));
12153 		return;
12154 	    }
12155 
12156 	    if (from >= 256)
12157 		langmap_set_entry(from, to);
12158 	    else
12159 		langmap_mapchar[from & 255] = to;
12160 
12161 	    /* Advance to next pair */
12162 	    MB_PTR_ADV(p);
12163 	    if (p2 != NULL)
12164 	    {
12165 		MB_PTR_ADV(p2);
12166 		if (*p == ';')
12167 		{
12168 		    p = p2;
12169 		    if (p[0] != NUL)
12170 		    {
12171 			if (p[0] != ',')
12172 			{
12173 			    semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12174 			    return;
12175 			}
12176 			++p;
12177 		    }
12178 		    break;
12179 		}
12180 	    }
12181 	}
12182     }
12183 }
12184 #endif
12185 
12186 /*
12187  * Return TRUE if format option 'x' is in effect.
12188  * Take care of no formatting when 'paste' is set.
12189  */
12190     int
12191 has_format_option(int x)
12192 {
12193     if (p_paste)
12194 	return FALSE;
12195     return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12196 }
12197 
12198 /*
12199  * Return TRUE if "x" is present in 'shortmess' option, or
12200  * 'shortmess' contains 'a' and "x" is present in SHM_A.
12201  */
12202     int
12203 shortmess(int x)
12204 {
12205     return p_shm != NULL &&
12206 	    (   vim_strchr(p_shm, x) != NULL
12207 	    || (vim_strchr(p_shm, 'a') != NULL
12208 		&& vim_strchr((char_u *)SHM_A, x) != NULL));
12209 }
12210 
12211 /*
12212  * paste_option_changed() - Called after p_paste was set or reset.
12213  */
12214     static void
12215 paste_option_changed(void)
12216 {
12217     static int	old_p_paste = FALSE;
12218     static int	save_sm = 0;
12219     static int	save_sta = 0;
12220 #ifdef FEAT_CMDL_INFO
12221     static int	save_ru = 0;
12222 #endif
12223 #ifdef FEAT_RIGHTLEFT
12224     static int	save_ri = 0;
12225     static int	save_hkmap = 0;
12226 #endif
12227     buf_T	*buf;
12228 
12229     if (p_paste)
12230     {
12231 	/*
12232 	 * Paste switched from off to on.
12233 	 * Save the current values, so they can be restored later.
12234 	 */
12235 	if (!old_p_paste)
12236 	{
12237 	    /* save options for each buffer */
12238 	    FOR_ALL_BUFFERS(buf)
12239 	    {
12240 		buf->b_p_tw_nopaste = buf->b_p_tw;
12241 		buf->b_p_wm_nopaste = buf->b_p_wm;
12242 		buf->b_p_sts_nopaste = buf->b_p_sts;
12243 		buf->b_p_ai_nopaste = buf->b_p_ai;
12244 		buf->b_p_et_nopaste = buf->b_p_et;
12245 #ifdef FEAT_VARTABS
12246 		if (buf->b_p_vsts_nopaste)
12247 		    vim_free(buf->b_p_vsts_nopaste);
12248 		buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12249 				     ? vim_strsave(buf->b_p_vsts) : NULL;
12250 #endif
12251 	    }
12252 
12253 	    /* save global options */
12254 	    save_sm = p_sm;
12255 	    save_sta = p_sta;
12256 #ifdef FEAT_CMDL_INFO
12257 	    save_ru = p_ru;
12258 #endif
12259 #ifdef FEAT_RIGHTLEFT
12260 	    save_ri = p_ri;
12261 	    save_hkmap = p_hkmap;
12262 #endif
12263 	    /* save global values for local buffer options */
12264 	    p_ai_nopaste = p_ai;
12265 	    p_et_nopaste = p_et;
12266 	    p_sts_nopaste = p_sts;
12267 	    p_tw_nopaste = p_tw;
12268 	    p_wm_nopaste = p_wm;
12269 #ifdef FEAT_VARTABS
12270 	    if (p_vsts_nopaste)
12271 		vim_free(p_vsts_nopaste);
12272 	    p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12273 #endif
12274 	}
12275 
12276 	/*
12277 	 * Always set the option values, also when 'paste' is set when it is
12278 	 * already on.
12279 	 */
12280 	/* set options for each buffer */
12281 	FOR_ALL_BUFFERS(buf)
12282 	{
12283 	    buf->b_p_tw = 0;	    /* textwidth is 0 */
12284 	    buf->b_p_wm = 0;	    /* wrapmargin is 0 */
12285 	    buf->b_p_sts = 0;	    /* softtabstop is 0 */
12286 	    buf->b_p_ai = 0;	    /* no auto-indent */
12287 	    buf->b_p_et = 0;	    /* no expandtab */
12288 #ifdef FEAT_VARTABS
12289 	    if (buf->b_p_vsts)
12290 		free_string_option(buf->b_p_vsts);
12291 	    buf->b_p_vsts = empty_option;
12292 	    if (buf->b_p_vsts_array)
12293 		vim_free(buf->b_p_vsts_array);
12294 	    buf->b_p_vsts_array = 0;
12295 #endif
12296 	}
12297 
12298 	/* set global options */
12299 	p_sm = 0;		    /* no showmatch */
12300 	p_sta = 0;		    /* no smarttab */
12301 #ifdef FEAT_CMDL_INFO
12302 	if (p_ru)
12303 	    status_redraw_all();    /* redraw to remove the ruler */
12304 	p_ru = 0;		    /* no ruler */
12305 #endif
12306 #ifdef FEAT_RIGHTLEFT
12307 	p_ri = 0;		    /* no reverse insert */
12308 	p_hkmap = 0;		    /* no Hebrew keyboard */
12309 #endif
12310 	/* set global values for local buffer options */
12311 	p_tw = 0;
12312 	p_wm = 0;
12313 	p_sts = 0;
12314 	p_ai = 0;
12315 #ifdef FEAT_VARTABS
12316 	if (p_vsts)
12317 	    free_string_option(p_vsts);
12318 	p_vsts = empty_option;
12319 #endif
12320     }
12321 
12322     /*
12323      * Paste switched from on to off: Restore saved values.
12324      */
12325     else if (old_p_paste)
12326     {
12327 	/* restore options for each buffer */
12328 	FOR_ALL_BUFFERS(buf)
12329 	{
12330 	    buf->b_p_tw = buf->b_p_tw_nopaste;
12331 	    buf->b_p_wm = buf->b_p_wm_nopaste;
12332 	    buf->b_p_sts = buf->b_p_sts_nopaste;
12333 	    buf->b_p_ai = buf->b_p_ai_nopaste;
12334 	    buf->b_p_et = buf->b_p_et_nopaste;
12335 #ifdef FEAT_VARTABS
12336 	    if (buf->b_p_vsts)
12337 		free_string_option(buf->b_p_vsts);
12338 	    buf->b_p_vsts = buf->b_p_vsts_nopaste
12339 			 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12340 	    if (buf->b_p_vsts_array)
12341 		vim_free(buf->b_p_vsts_array);
12342 	    if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12343 		tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12344 	    else
12345 		buf->b_p_vsts_array = 0;
12346 #endif
12347 	}
12348 
12349 	/* restore global options */
12350 	p_sm = save_sm;
12351 	p_sta = save_sta;
12352 #ifdef FEAT_CMDL_INFO
12353 	if (p_ru != save_ru)
12354 	    status_redraw_all();    /* redraw to draw the ruler */
12355 	p_ru = save_ru;
12356 #endif
12357 #ifdef FEAT_RIGHTLEFT
12358 	p_ri = save_ri;
12359 	p_hkmap = save_hkmap;
12360 #endif
12361 	/* set global values for local buffer options */
12362 	p_ai = p_ai_nopaste;
12363 	p_et = p_et_nopaste;
12364 	p_sts = p_sts_nopaste;
12365 	p_tw = p_tw_nopaste;
12366 	p_wm = p_wm_nopaste;
12367 #ifdef FEAT_VARTABS
12368 	if (p_vsts)
12369 	    free_string_option(p_vsts);
12370 	p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12371 #endif
12372     }
12373 
12374     old_p_paste = p_paste;
12375 }
12376 
12377 /*
12378  * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12379  *
12380  * Reset 'compatible' and set the values for options that didn't get set yet
12381  * to the Vim defaults.
12382  * Don't do this if the 'compatible' option has been set or reset before.
12383  * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
12384  */
12385     void
12386 vimrc_found(char_u *fname, char_u *envname)
12387 {
12388     int		opt_idx;
12389     int		dofree = FALSE;
12390     char_u	*p;
12391 
12392     if (!option_was_set((char_u *)"cp"))
12393     {
12394 	p_cp = FALSE;
12395 	for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12396 	    if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12397 		set_option_default(opt_idx, OPT_FREE, FALSE);
12398 	didset_options();
12399 	didset_options2();
12400     }
12401 
12402     if (fname != NULL)
12403     {
12404 	p = vim_getenv(envname, &dofree);
12405 	if (p == NULL)
12406 	{
12407 	    /* Set $MYVIMRC to the first vimrc file found. */
12408 	    p = FullName_save(fname, FALSE);
12409 	    if (p != NULL)
12410 	    {
12411 		vim_setenv(envname, p);
12412 		vim_free(p);
12413 	    }
12414 	}
12415 	else if (dofree)
12416 	    vim_free(p);
12417     }
12418 }
12419 
12420 /*
12421  * Set 'compatible' on or off.  Called for "-C" and "-N" command line arg.
12422  */
12423     void
12424 change_compatible(int on)
12425 {
12426     int	    opt_idx;
12427 
12428     if (p_cp != on)
12429     {
12430 	p_cp = on;
12431 	compatible_set();
12432     }
12433     opt_idx = findoption((char_u *)"cp");
12434     if (opt_idx >= 0)
12435 	options[opt_idx].flags |= P_WAS_SET;
12436 }
12437 
12438 /*
12439  * Return TRUE when option "name" has been set.
12440  * Only works correctly for global options.
12441  */
12442     int
12443 option_was_set(char_u *name)
12444 {
12445     int idx;
12446 
12447     idx = findoption(name);
12448     if (idx < 0)	/* unknown option */
12449 	return FALSE;
12450     if (options[idx].flags & P_WAS_SET)
12451 	return TRUE;
12452     return FALSE;
12453 }
12454 
12455 /*
12456  * Reset the flag indicating option "name" was set.
12457  */
12458     int
12459 reset_option_was_set(char_u *name)
12460 {
12461     int idx = findoption(name);
12462 
12463     if (idx >= 0)
12464     {
12465 	options[idx].flags &= ~P_WAS_SET;
12466 	return OK;
12467     }
12468     return FAIL;
12469 }
12470 
12471 /*
12472  * compatible_set() - Called when 'compatible' has been set or unset.
12473  *
12474  * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12475  * flag) to a Vi compatible value.
12476  * When 'compatible' is unset: Set all options that have a different default
12477  * for Vim (without the P_VI_DEF flag) to that default.
12478  */
12479     static void
12480 compatible_set(void)
12481 {
12482     int	    opt_idx;
12483 
12484     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12485 	if (	   ((options[opt_idx].flags & P_VIM) && p_cp)
12486 		|| (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12487 	    set_option_default(opt_idx, OPT_FREE, p_cp);
12488     didset_options();
12489     didset_options2();
12490 }
12491 
12492 #ifdef FEAT_LINEBREAK
12493 
12494 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12495    /* Borland C++ screws up loop optimisation here (negri) */
12496   #pragma option -O-l
12497 # endif
12498 
12499 /*
12500  * fill_breakat_flags() -- called when 'breakat' changes value.
12501  */
12502     static void
12503 fill_breakat_flags(void)
12504 {
12505     char_u	*p;
12506     int		i;
12507 
12508     for (i = 0; i < 256; i++)
12509 	breakat_flags[i] = FALSE;
12510 
12511     if (p_breakat != NULL)
12512 	for (p = p_breakat; *p; p++)
12513 	    breakat_flags[*p] = TRUE;
12514 }
12515 
12516 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12517   #pragma option -O.l
12518 # endif
12519 
12520 #endif
12521 
12522 /*
12523  * Check an option that can be a range of string values.
12524  *
12525  * Return OK for correct value, FAIL otherwise.
12526  * Empty is always OK.
12527  */
12528     static int
12529 check_opt_strings(
12530     char_u	*val,
12531     char	**values,
12532     int		list)	    /* when TRUE: accept a list of values */
12533 {
12534     return opt_strings_flags(val, values, NULL, list);
12535 }
12536 
12537 /*
12538  * Handle an option that can be a range of string values.
12539  * Set a flag in "*flagp" for each string present.
12540  *
12541  * Return OK for correct value, FAIL otherwise.
12542  * Empty is always OK.
12543  */
12544     static int
12545 opt_strings_flags(
12546     char_u	*val,		/* new value */
12547     char	**values,	/* array of valid string values */
12548     unsigned	*flagp,
12549     int		list)		/* when TRUE: accept a list of values */
12550 {
12551     int		i;
12552     int		len;
12553     unsigned	new_flags = 0;
12554 
12555     while (*val)
12556     {
12557 	for (i = 0; ; ++i)
12558 	{
12559 	    if (values[i] == NULL)	/* val not found in values[] */
12560 		return FAIL;
12561 
12562 	    len = (int)STRLEN(values[i]);
12563 	    if (STRNCMP(values[i], val, len) == 0
12564 		    && ((list && val[len] == ',') || val[len] == NUL))
12565 	    {
12566 		val += len + (val[len] == ',');
12567 		new_flags |= (1 << i);
12568 		break;		/* check next item in val list */
12569 	    }
12570 	}
12571     }
12572     if (flagp != NULL)
12573 	*flagp = new_flags;
12574 
12575     return OK;
12576 }
12577 
12578 /*
12579  * Read the 'wildmode' option, fill wim_flags[].
12580  */
12581     static int
12582 check_opt_wim(void)
12583 {
12584     char_u	new_wim_flags[4];
12585     char_u	*p;
12586     int		i;
12587     int		idx = 0;
12588 
12589     for (i = 0; i < 4; ++i)
12590 	new_wim_flags[i] = 0;
12591 
12592     for (p = p_wim; *p; ++p)
12593     {
12594 	for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12595 	    ;
12596 	if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12597 	    return FAIL;
12598 	if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12599 	    new_wim_flags[idx] |= WIM_LONGEST;
12600 	else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12601 	    new_wim_flags[idx] |= WIM_FULL;
12602 	else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12603 	    new_wim_flags[idx] |= WIM_LIST;
12604 	else
12605 	    return FAIL;
12606 	p += i;
12607 	if (*p == NUL)
12608 	    break;
12609 	if (*p == ',')
12610 	{
12611 	    if (idx == 3)
12612 		return FAIL;
12613 	    ++idx;
12614 	}
12615     }
12616 
12617     /* fill remaining entries with last flag */
12618     while (idx < 3)
12619     {
12620 	new_wim_flags[idx + 1] = new_wim_flags[idx];
12621 	++idx;
12622     }
12623 
12624     /* only when there are no errors, wim_flags[] is changed */
12625     for (i = 0; i < 4; ++i)
12626 	wim_flags[i] = new_wim_flags[i];
12627     return OK;
12628 }
12629 
12630 /*
12631  * Check if backspacing over something is allowed.
12632  */
12633     int
12634 can_bs(
12635     int		what)	    /* BS_INDENT, BS_EOL or BS_START */
12636 {
12637 #ifdef FEAT_JOB_CHANNEL
12638     if (what == BS_START && bt_prompt(curbuf))
12639 	return FALSE;
12640 #endif
12641     switch (*p_bs)
12642     {
12643 	case '2':	return TRUE;
12644 	case '1':	return (what != BS_START);
12645 	case '0':	return FALSE;
12646     }
12647     return vim_strchr(p_bs, what) != NULL;
12648 }
12649 
12650 /*
12651  * Save the current values of 'fileformat' and 'fileencoding', so that we know
12652  * the file must be considered changed when the value is different.
12653  */
12654     void
12655 save_file_ff(buf_T *buf)
12656 {
12657     buf->b_start_ffc = *buf->b_p_ff;
12658     buf->b_start_eol = buf->b_p_eol;
12659     buf->b_start_bomb = buf->b_p_bomb;
12660 
12661     /* Only use free/alloc when necessary, they take time. */
12662     if (buf->b_start_fenc == NULL
12663 			     || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12664     {
12665 	vim_free(buf->b_start_fenc);
12666 	buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12667     }
12668 }
12669 
12670 /*
12671  * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12672  * from when editing started (save_file_ff() called).
12673  * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12674  * changed and 'binary' is not set.
12675  * Also when 'endofline' was changed and 'fixeol' is not set.
12676  * When "ignore_empty" is true don't consider a new, empty buffer to be
12677  * changed.
12678  */
12679     int
12680 file_ff_differs(buf_T *buf, int ignore_empty)
12681 {
12682     /* In a buffer that was never loaded the options are not valid. */
12683     if (buf->b_flags & BF_NEVERLOADED)
12684 	return FALSE;
12685     if (ignore_empty
12686 	    && (buf->b_flags & BF_NEW)
12687 	    && buf->b_ml.ml_line_count == 1
12688 	    && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12689 	return FALSE;
12690     if (buf->b_start_ffc != *buf->b_p_ff)
12691 	return TRUE;
12692     if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
12693 	return TRUE;
12694     if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12695 	return TRUE;
12696     if (buf->b_start_fenc == NULL)
12697 	return (*buf->b_p_fenc != NUL);
12698     return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12699 }
12700 
12701 /*
12702  * return OK if "p" is a valid fileformat name, FAIL otherwise.
12703  */
12704     int
12705 check_ff_value(char_u *p)
12706 {
12707     return check_opt_strings(p, p_ff_values, FALSE);
12708 }
12709 
12710 #if defined(FEAT_VARTABS) || defined(PROTO)
12711 
12712 /*
12713  * Set the integer values corresponding to the string setting of 'vartabstop'.
12714  * "array" will be set, caller must free it if needed.
12715  */
12716     int
12717 tabstop_set(char_u *var, int **array)
12718 {
12719     int valcount = 1;
12720     int t;
12721     char_u *cp;
12722 
12723     if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
12724     {
12725 	*array = NULL;
12726 	return TRUE;
12727     }
12728 
12729     for (cp = var; *cp != NUL; ++cp)
12730     {
12731 	if (cp == var || cp[-1] == ',')
12732 	{
12733 	    char_u *end;
12734 
12735 	    if (strtol((char *)cp, (char **)&end, 10) <= 0)
12736 	    {
12737 		if (cp != end)
12738 		    emsg(_(e_positive));
12739 		else
12740 		    emsg(_(e_invarg));
12741 		return FALSE;
12742 	    }
12743 	}
12744 
12745 	if (VIM_ISDIGIT(*cp))
12746 	    continue;
12747 	if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
12748 	{
12749 	    ++valcount;
12750 	    continue;
12751 	}
12752 	emsg(_(e_invarg));
12753 	return FALSE;
12754     }
12755 
12756     *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
12757     if (*array == NULL)
12758 	return FALSE;
12759     (*array)[0] = valcount;
12760 
12761     t = 1;
12762     for (cp = var; *cp != NUL;)
12763     {
12764 	(*array)[t++] = atoi((char *)cp);
12765 	while (*cp  != NUL && *cp != ',')
12766 	    ++cp;
12767 	if (*cp != NUL)
12768 	    ++cp;
12769     }
12770 
12771     return TRUE;
12772 }
12773 
12774 /*
12775  * Calculate the number of screen spaces a tab will occupy.
12776  * If "vts" is set then the tab widths are taken from that array,
12777  * otherwise the value of ts is used.
12778  */
12779     int
12780 tabstop_padding(colnr_T col, int ts_arg, int *vts)
12781 {
12782     int		ts = ts_arg == 0 ? 8 : ts_arg;
12783     int		tabcount;
12784     colnr_T	tabcol = 0;
12785     int		t;
12786     int		padding = 0;
12787 
12788     if (vts == NULL || vts[0] == 0)
12789 	return ts - (col % ts);
12790 
12791     tabcount = vts[0];
12792 
12793     for (t = 1; t <= tabcount; ++t)
12794     {
12795 	tabcol += vts[t];
12796 	if (tabcol > col)
12797 	{
12798 	    padding = (int)(tabcol - col);
12799 	    break;
12800 	}
12801     }
12802     if (t > tabcount)
12803 	padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12804 
12805     return padding;
12806 }
12807 
12808 /*
12809  * Find the size of the tab that covers a particular column.
12810  */
12811     int
12812 tabstop_at(colnr_T col, int ts, int *vts)
12813 {
12814     int		tabcount;
12815     colnr_T	tabcol = 0;
12816     int		t;
12817     int		tab_size = 0;
12818 
12819     if (vts == 0 || vts[0] == 0)
12820 	return ts;
12821 
12822     tabcount = vts[0];
12823     for (t = 1; t <= tabcount; ++t)
12824     {
12825 	tabcol += vts[t];
12826 	if (tabcol > col)
12827 	{
12828 	    tab_size = vts[t];
12829 	    break;
12830 	}
12831     }
12832     if (t > tabcount)
12833 	tab_size = vts[tabcount];
12834 
12835     return tab_size;
12836 }
12837 
12838 /*
12839  * Find the column on which a tab starts.
12840  */
12841     colnr_T
12842 tabstop_start(colnr_T col, int ts, int *vts)
12843 {
12844     int		tabcount;
12845     colnr_T	tabcol = 0;
12846     int		t;
12847     int         excess;
12848 
12849     if (vts == NULL || vts[0] == 0)
12850 	return (col / ts) * ts;
12851 
12852     tabcount = vts[0];
12853     for (t = 1; t <= tabcount; ++t)
12854     {
12855 	tabcol += vts[t];
12856 	if (tabcol > col)
12857 	    return tabcol - vts[t];
12858     }
12859 
12860     excess = tabcol % vts[tabcount];
12861     return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12862 }
12863 
12864 /*
12865  * Find the number of tabs and spaces necessary to get from one column
12866  * to another.
12867  */
12868     void
12869 tabstop_fromto(
12870 	colnr_T start_col,
12871 	colnr_T end_col,
12872 	int	ts_arg,
12873 	int	*vts,
12874 	int	*ntabs,
12875 	int	*nspcs)
12876 {
12877     int		spaces = end_col - start_col;
12878     colnr_T	tabcol = 0;
12879     int		padding = 0;
12880     int		tabcount;
12881     int		t;
12882     int		ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
12883 
12884     if (vts == NULL || vts[0] == 0)
12885     {
12886 	int tabs = 0;
12887 	int initspc = 0;
12888 
12889 	initspc = ts - (start_col % ts);
12890 	if (spaces >= initspc)
12891 	{
12892 	    spaces -= initspc;
12893 	    tabs++;
12894 	}
12895 	tabs += spaces / ts;
12896 	spaces -= (spaces / ts) * ts;
12897 
12898 	*ntabs = tabs;
12899 	*nspcs = spaces;
12900 	return;
12901     }
12902 
12903     /* Find the padding needed to reach the next tabstop. */
12904     tabcount = vts[0];
12905     for (t = 1; t <= tabcount; ++t)
12906     {
12907 	tabcol += vts[t];
12908 	if (tabcol > start_col)
12909 	{
12910 	    padding = (int)(tabcol - start_col);
12911 	    break;
12912 	}
12913     }
12914     if (t > tabcount)
12915 	padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12916 
12917     /* If the space needed is less than the padding no tabs can be used. */
12918     if (spaces < padding)
12919     {
12920 	*ntabs = 0;
12921 	*nspcs = spaces;
12922 	return;
12923     }
12924 
12925     *ntabs = 1;
12926     spaces -= padding;
12927 
12928     /* At least one tab has been used. See if any more will fit. */
12929     while (spaces != 0 && ++t <= tabcount)
12930     {
12931 	padding = vts[t];
12932 	if (spaces < padding)
12933 	{
12934 	    *nspcs = spaces;
12935 	    return;
12936 	}
12937 	++*ntabs;
12938 	spaces -= padding;
12939     }
12940 
12941     *ntabs += spaces / vts[tabcount];
12942     *nspcs =  spaces % vts[tabcount];
12943 }
12944 
12945 /*
12946  * See if two tabstop arrays contain the same values.
12947  */
12948     int
12949 tabstop_eq(int *ts1, int *ts2)
12950 {
12951     int		t;
12952 
12953     if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
12954 	return FALSE;
12955     if (ts1 == ts2)
12956 	return TRUE;
12957     if (ts1[0] != ts2[0])
12958 	return FALSE;
12959 
12960     for (t = 1; t <= ts1[0]; ++t)
12961 	if (ts1[t] != ts2[t])
12962 	    return FALSE;
12963 
12964     return TRUE;
12965 }
12966 
12967 #if defined(FEAT_BEVAL) || defined(PROTO)
12968 /*
12969  * Copy a tabstop array, allocating space for the new array.
12970  */
12971     int *
12972 tabstop_copy(int *oldts)
12973 {
12974     int		*newts;
12975     int		t;
12976 
12977     if (oldts == 0)
12978 	return 0;
12979 
12980     newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
12981     for (t = 0; t <= oldts[0]; ++t)
12982 	newts[t] = oldts[t];
12983 
12984     return newts;
12985 }
12986 #endif
12987 
12988 /*
12989  * Return a count of the number of tabstops.
12990  */
12991     int
12992 tabstop_count(int *ts)
12993 {
12994     return ts != NULL ? ts[0] : 0;
12995 }
12996 
12997 /*
12998  * Return the first tabstop, or 8 if there are no tabstops defined.
12999  */
13000     int
13001 tabstop_first(int *ts)
13002 {
13003     return ts != NULL ? ts[1] : 8;
13004 }
13005 
13006 #endif
13007 
13008 /*
13009  * Return the effective shiftwidth value for current buffer, using the
13010  * 'tabstop' value when 'shiftwidth' is zero.
13011  */
13012     long
13013 get_sw_value(buf_T *buf)
13014 {
13015     return get_sw_value_col(buf, 0);
13016 }
13017 
13018 /*
13019  * Idem, using the first non-black in the current line.
13020  */
13021     long
13022 get_sw_value_indent(buf_T *buf)
13023 {
13024     pos_T pos = curwin->w_cursor;
13025 
13026     pos.col = getwhitecols_curline();
13027     return get_sw_value_pos(buf, &pos);
13028 }
13029 
13030 /*
13031  * Idem, using "pos".
13032  */
13033     long
13034 get_sw_value_pos(buf_T *buf, pos_T *pos)
13035 {
13036     pos_T save_cursor = curwin->w_cursor;
13037     long sw_value;
13038 
13039     curwin->w_cursor = *pos;
13040     sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13041     curwin->w_cursor = save_cursor;
13042     return sw_value;
13043 }
13044 
13045 /*
13046  * Idem, using virtual column "col".
13047  */
13048     long
13049 get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13050 {
13051     return buf->b_p_sw ? buf->b_p_sw :
13052  #ifdef FEAT_VARTABS
13053 	tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13054  #else
13055 	buf->b_p_ts;
13056  #endif
13057 }
13058 
13059 /*
13060  * Return the effective softtabstop value for the current buffer, using the
13061  * 'shiftwidth' value when 'softtabstop' is negative.
13062  */
13063     long
13064 get_sts_value(void)
13065 {
13066     return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
13067 }
13068 
13069 /*
13070  * Return the effective 'scrolloff' value for the current window, using the
13071  * global value when appropriate.
13072  */
13073     long
13074 get_scrolloff_value(void)
13075 {
13076     return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13077 }
13078 
13079 /*
13080  * Return the effective 'sidescrolloff' value for the current window, using the
13081  * global value when appropriate.
13082  */
13083     long
13084 get_sidescrolloff_value(void)
13085 {
13086     return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13087 }
13088 
13089 /*
13090  * Check matchpairs option for "*initc".
13091  * If there is a match set "*initc" to the matching character and "*findc" to
13092  * the opposite character.  Set "*backwards" to the direction.
13093  * When "switchit" is TRUE swap the direction.
13094  */
13095     void
13096 find_mps_values(
13097     int	    *initc,
13098     int	    *findc,
13099     int	    *backwards,
13100     int	    switchit)
13101 {
13102     char_u	*ptr;
13103 
13104     ptr = curbuf->b_p_mps;
13105     while (*ptr != NUL)
13106     {
13107 	if (has_mbyte)
13108 	{
13109 	    char_u *prev;
13110 
13111 	    if (mb_ptr2char(ptr) == *initc)
13112 	    {
13113 		if (switchit)
13114 		{
13115 		    *findc = *initc;
13116 		    *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13117 		    *backwards = TRUE;
13118 		}
13119 		else
13120 		{
13121 		    *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13122 		    *backwards = FALSE;
13123 		}
13124 		return;
13125 	    }
13126 	    prev = ptr;
13127 	    ptr += mb_ptr2len(ptr) + 1;
13128 	    if (mb_ptr2char(ptr) == *initc)
13129 	    {
13130 		if (switchit)
13131 		{
13132 		    *findc = *initc;
13133 		    *initc = mb_ptr2char(prev);
13134 		    *backwards = FALSE;
13135 		}
13136 		else
13137 		{
13138 		    *findc = mb_ptr2char(prev);
13139 		    *backwards = TRUE;
13140 		}
13141 		return;
13142 	    }
13143 	    ptr += mb_ptr2len(ptr);
13144 	}
13145 	else
13146 	{
13147 	    if (*ptr == *initc)
13148 	    {
13149 		if (switchit)
13150 		{
13151 		    *backwards = TRUE;
13152 		    *findc = *initc;
13153 		    *initc = ptr[2];
13154 		}
13155 		else
13156 		{
13157 		    *backwards = FALSE;
13158 		    *findc = ptr[2];
13159 		}
13160 		return;
13161 	    }
13162 	    ptr += 2;
13163 	    if (*ptr == *initc)
13164 	    {
13165 		if (switchit)
13166 		{
13167 		    *backwards = FALSE;
13168 		    *findc = *initc;
13169 		    *initc = ptr[-2];
13170 		}
13171 		else
13172 		{
13173 		    *backwards = TRUE;
13174 		    *findc =  ptr[-2];
13175 		}
13176 		return;
13177 	    }
13178 	    ++ptr;
13179 	}
13180 	if (*ptr == ',')
13181 	    ++ptr;
13182     }
13183 }
13184 
13185 #if defined(FEAT_LINEBREAK) || defined(PROTO)
13186 /*
13187  * This is called when 'breakindentopt' is changed and when a window is
13188  * initialized.
13189  */
13190     static int
13191 briopt_check(win_T *wp)
13192 {
13193     char_u	*p;
13194     int		bri_shift = 0;
13195     long	bri_min = 20;
13196     int		bri_sbr = FALSE;
13197 
13198     p = wp->w_p_briopt;
13199     while (*p != NUL)
13200     {
13201 	if (STRNCMP(p, "shift:", 6) == 0
13202 		 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13203 	{
13204 	    p += 6;
13205 	    bri_shift = getdigits(&p);
13206 	}
13207 	else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13208 	{
13209 	    p += 4;
13210 	    bri_min = getdigits(&p);
13211 	}
13212 	else if (STRNCMP(p, "sbr", 3) == 0)
13213 	{
13214 	    p += 3;
13215 	    bri_sbr = TRUE;
13216 	}
13217 	if (*p != ',' && *p != NUL)
13218 	    return FAIL;
13219 	if (*p == ',')
13220 	    ++p;
13221     }
13222 
13223     wp->w_p_brishift = bri_shift;
13224     wp->w_p_brimin   = bri_min;
13225     wp->w_p_brisbr   = bri_sbr;
13226 
13227     return OK;
13228 }
13229 #endif
13230 
13231 /*
13232  * Get the local or global value of 'backupcopy'.
13233  */
13234     unsigned int
13235 get_bkc_value(buf_T *buf)
13236 {
13237     return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13238 }
13239 
13240 #if defined(FEAT_SIGNS) || defined(PROTO)
13241 /*
13242  * Return TRUE when window "wp" has a column to draw signs in.
13243  */
13244      int
13245 signcolumn_on(win_T *wp)
13246 {
13247     if (*wp->w_p_scl == 'n')
13248 	return FALSE;
13249     if (*wp->w_p_scl == 'y')
13250 	return TRUE;
13251     return (wp->w_buffer->b_signlist != NULL
13252 # ifdef FEAT_NETBEANS_INTG
13253 			|| wp->w_buffer->b_has_sign_column
13254 # endif
13255 		    );
13256 }
13257 #endif
13258 
13259 #if defined(FEAT_EVAL) || defined(PROTO)
13260 /*
13261  * Get window or buffer local options.
13262  */
13263     dict_T *
13264 get_winbuf_options(int bufopt)
13265 {
13266     dict_T	*d;
13267     int		opt_idx;
13268 
13269     d = dict_alloc();
13270     if (d == NULL)
13271 	return NULL;
13272 
13273     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13274     {
13275 	struct vimoption *opt = &options[opt_idx];
13276 
13277 	if ((bufopt && (opt->indir & PV_BUF))
13278 					 || (!bufopt && (opt->indir & PV_WIN)))
13279 	{
13280 	    char_u *varp = get_varp(opt);
13281 
13282 	    if (varp != NULL)
13283 	    {
13284 		if (opt->flags & P_STRING)
13285 		    dict_add_string(d, opt->fullname, *(char_u **)varp);
13286 		else if (opt->flags & P_NUM)
13287 		    dict_add_number(d, opt->fullname, *(long *)varp);
13288 		else
13289 		    dict_add_number(d, opt->fullname, *(int *)varp);
13290 	    }
13291 	}
13292     }
13293 
13294     return d;
13295 }
13296 #endif
13297