xref: /vim-8.2.3635/src/option.c (revision a6c27c47)
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 #ifdef FEAT_EVAL
171 # define PV_TFU		OPT_BUF(BV_TFU)
172 #endif
173 #define PV_TAGS		OPT_BOTH(OPT_BUF(BV_TAGS))
174 #define PV_TC		OPT_BOTH(OPT_BUF(BV_TC))
175 #define PV_TS		OPT_BUF(BV_TS)
176 #define PV_TW		OPT_BUF(BV_TW)
177 #define PV_TX		OPT_BUF(BV_TX)
178 #ifdef FEAT_PERSISTENT_UNDO
179 # define PV_UDF		OPT_BUF(BV_UDF)
180 #endif
181 #define PV_WM		OPT_BUF(BV_WM)
182 #ifdef FEAT_VARTABS
183 # define PV_VSTS		OPT_BUF(BV_VSTS)
184 # define PV_VTS		OPT_BUF(BV_VTS)
185 #endif
186 
187 /*
188  * Definition of the PV_ values for window-local options.
189  * The WV_ values are defined in option.h.
190  */
191 #define PV_LIST		OPT_WIN(WV_LIST)
192 #ifdef FEAT_ARABIC
193 # define PV_ARAB	OPT_WIN(WV_ARAB)
194 #endif
195 #ifdef FEAT_LINEBREAK
196 # define PV_BRI		OPT_WIN(WV_BRI)
197 # define PV_BRIOPT	OPT_WIN(WV_BRIOPT)
198 #endif
199 #ifdef FEAT_DIFF
200 # define PV_DIFF	OPT_WIN(WV_DIFF)
201 #endif
202 #ifdef FEAT_FOLDING
203 # define PV_FDC		OPT_WIN(WV_FDC)
204 # define PV_FEN		OPT_WIN(WV_FEN)
205 # define PV_FDI		OPT_WIN(WV_FDI)
206 # define PV_FDL		OPT_WIN(WV_FDL)
207 # define PV_FDM		OPT_WIN(WV_FDM)
208 # define PV_FML		OPT_WIN(WV_FML)
209 # define PV_FDN		OPT_WIN(WV_FDN)
210 # ifdef FEAT_EVAL
211 #  define PV_FDE	OPT_WIN(WV_FDE)
212 #  define PV_FDT	OPT_WIN(WV_FDT)
213 # endif
214 # define PV_FMR		OPT_WIN(WV_FMR)
215 #endif
216 #ifdef FEAT_LINEBREAK
217 # define PV_LBR		OPT_WIN(WV_LBR)
218 #endif
219 #define PV_NU		OPT_WIN(WV_NU)
220 #define PV_RNU		OPT_WIN(WV_RNU)
221 #ifdef FEAT_LINEBREAK
222 # define PV_NUW		OPT_WIN(WV_NUW)
223 #endif
224 #if defined(FEAT_QUICKFIX)
225 # define PV_PVW		OPT_WIN(WV_PVW)
226 #endif
227 #ifdef FEAT_RIGHTLEFT
228 # define PV_RL		OPT_WIN(WV_RL)
229 # define PV_RLC		OPT_WIN(WV_RLC)
230 #endif
231 #define PV_SCBIND	OPT_WIN(WV_SCBIND)
232 #define PV_SCROLL	OPT_WIN(WV_SCROLL)
233 #define PV_SISO		OPT_BOTH(OPT_WIN(WV_SISO))
234 #define PV_SO		OPT_BOTH(OPT_WIN(WV_SO))
235 #ifdef FEAT_SPELL
236 # define PV_SPELL	OPT_WIN(WV_SPELL)
237 #endif
238 #ifdef FEAT_SYN_HL
239 # define PV_CUC		OPT_WIN(WV_CUC)
240 # define PV_CUL		OPT_WIN(WV_CUL)
241 # define PV_CC		OPT_WIN(WV_CC)
242 #endif
243 #ifdef FEAT_STL_OPT
244 # define PV_STL		OPT_BOTH(OPT_WIN(WV_STL))
245 #endif
246 #define PV_UL		OPT_BOTH(OPT_BUF(BV_UL))
247 # define PV_WFH		OPT_WIN(WV_WFH)
248 # define PV_WFW		OPT_WIN(WV_WFW)
249 #define PV_WRAP		OPT_WIN(WV_WRAP)
250 #define PV_CRBIND	OPT_WIN(WV_CRBIND)
251 #ifdef FEAT_CONCEAL
252 # define PV_COCU	OPT_WIN(WV_COCU)
253 # define PV_COLE	OPT_WIN(WV_COLE)
254 #endif
255 #ifdef FEAT_TERMINAL
256 # define PV_TWK		OPT_WIN(WV_TWK)
257 # define PV_TWS		OPT_WIN(WV_TWS)
258 # define PV_TWSL	OPT_BUF(BV_TWSL)
259 #endif
260 #ifdef FEAT_SIGNS
261 # define PV_SCL		OPT_WIN(WV_SCL)
262 #endif
263 
264 /* WV_ and BV_ values get typecasted to this for the "indir" field */
265 typedef enum
266 {
267     PV_NONE = 0,
268     PV_MAXVAL = 0xffff    /* to avoid warnings for value out of range */
269 } idopt_T;
270 
271 /*
272  * Options local to a window have a value local to a buffer and global to all
273  * buffers.  Indicate this by setting "var" to VAR_WIN.
274  */
275 #define VAR_WIN ((char_u *)-1)
276 
277 /*
278  * These are the global values for options which are also local to a buffer.
279  * Only to be used in option.c!
280  */
281 static int	p_ai;
282 static int	p_bin;
283 static int	p_bomb;
284 static char_u	*p_bh;
285 static char_u	*p_bt;
286 static int	p_bl;
287 static int	p_ci;
288 #ifdef FEAT_CINDENT
289 static int	p_cin;
290 static char_u	*p_cink;
291 static char_u	*p_cino;
292 #endif
293 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
294 static char_u	*p_cinw;
295 #endif
296 #ifdef FEAT_COMMENTS
297 static char_u	*p_com;
298 #endif
299 #ifdef FEAT_FOLDING
300 static char_u	*p_cms;
301 #endif
302 #ifdef FEAT_INS_EXPAND
303 static char_u	*p_cpt;
304 #endif
305 #ifdef FEAT_COMPL_FUNC
306 static char_u	*p_cfu;
307 static char_u	*p_ofu;
308 #endif
309 #ifdef FEAT_EVAL
310 static char_u	*p_tfu;
311 #endif
312 static int	p_eol;
313 static int	p_fixeol;
314 static int	p_et;
315 static char_u	*p_fenc;
316 static char_u	*p_ff;
317 static char_u	*p_fo;
318 static char_u	*p_flp;
319 static char_u	*p_ft;
320 static long	p_iminsert;
321 static long	p_imsearch;
322 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
323 static char_u	*p_inex;
324 #endif
325 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
326 static char_u	*p_inde;
327 static char_u	*p_indk;
328 #endif
329 #if defined(FEAT_EVAL)
330 static char_u	*p_fex;
331 #endif
332 static int	p_inf;
333 static char_u	*p_isk;
334 #ifdef FEAT_CRYPT
335 static char_u	*p_key;
336 #endif
337 #ifdef FEAT_LISP
338 static int	p_lisp;
339 #endif
340 static int	p_ml;
341 static int	p_ma;
342 static int	p_mod;
343 static char_u	*p_mps;
344 static char_u	*p_nf;
345 static int	p_pi;
346 #ifdef FEAT_TEXTOBJ
347 static char_u	*p_qe;
348 #endif
349 static int	p_ro;
350 #ifdef FEAT_SMARTINDENT
351 static int	p_si;
352 #endif
353 static int	p_sn;
354 static long	p_sts;
355 #if defined(FEAT_SEARCHPATH)
356 static char_u	*p_sua;
357 #endif
358 static long	p_sw;
359 static int	p_swf;
360 #ifdef FEAT_SYN_HL
361 static long	p_smc;
362 static char_u	*p_syn;
363 #endif
364 #ifdef FEAT_SPELL
365 static char_u	*p_spc;
366 static char_u	*p_spf;
367 static char_u	*p_spl;
368 #endif
369 static long	p_ts;
370 static long	p_tw;
371 static int	p_tx;
372 #ifdef FEAT_PERSISTENT_UNDO
373 static int	p_udf;
374 #endif
375 static long	p_wm;
376 #ifdef FEAT_VARTABS
377 static char_u	*p_vsts;
378 static char_u	*p_vts;
379 #endif
380 #ifdef FEAT_KEYMAP
381 static char_u	*p_keymap;
382 #endif
383 #ifdef FEAT_TERMINAL
384 static long	p_twsl;		/* 'termwinscroll' */
385 #endif
386 
387 /* Saved values for when 'bin' is set. */
388 static int	p_et_nobin;
389 static int	p_ml_nobin;
390 static long	p_tw_nobin;
391 static long	p_wm_nobin;
392 
393 /* Saved values for when 'paste' is set */
394 static int	p_ai_nopaste;
395 static int	p_et_nopaste;
396 static long	p_sts_nopaste;
397 static long	p_tw_nopaste;
398 static long	p_wm_nopaste;
399 #ifdef FEAT_VARTABS
400 static char_u	*p_vsts_nopaste;
401 #endif
402 
403 struct vimoption
404 {
405     char	*fullname;	// full option name
406     char	*shortname;	// permissible abbreviation
407     long_u	flags;		// see below
408     char_u	*var;		// global option: pointer to variable;
409 				// window-local option: VAR_WIN;
410 				// buffer-local option: global value
411     idopt_T	indir;		// global option: PV_NONE;
412 				// local option: indirect option index
413     char_u	*def_val[2];	// default values for variable (vi and vim)
414 #ifdef FEAT_EVAL
415     sctx_T	script_ctx;	// script context where the option was last set
416 # define SCTX_INIT , {0, 0, 0, 1}
417 #else
418 # define SCTX_INIT
419 #endif
420 };
421 
422 #define VI_DEFAULT  0	    /* def_val[VI_DEFAULT] is Vi default value */
423 #define VIM_DEFAULT 1	    /* def_val[VIM_DEFAULT] is Vim default value */
424 
425 /*
426  * Flags
427  */
428 #define P_BOOL		0x01	/* the option is boolean */
429 #define P_NUM		0x02	/* the option is numeric */
430 #define P_STRING	0x04	/* the option is a string */
431 #define P_ALLOCED	0x08	/* the string option is in allocated memory,
432 				   must use free_string_option() when
433 				   assigning new value. Not set if default is
434 				   the same. */
435 #define P_EXPAND	0x10	/* environment expansion.  NOTE: P_EXPAND can
436 				   never be used for local or hidden options! */
437 #define P_NODEFAULT	0x40	/* don't set to default value */
438 #define P_DEF_ALLOCED	0x80	/* default value is in allocated memory, must
439 				    use vim_free() when assigning new value */
440 #define P_WAS_SET	0x100	/* option has been set/reset */
441 #define P_NO_MKRC	0x200	/* don't include in :mkvimrc output */
442 #define P_VI_DEF	0x400	/* Use Vi default for Vim */
443 #define P_VIM		0x800	/* Vim option, reset when 'cp' set */
444 
445 				/* when option changed, what to display: */
446 #define P_RSTAT		0x1000	/* redraw status lines */
447 #define P_RWIN		0x2000	/* redraw current window and recompute text */
448 #define P_RBUF		0x4000	/* redraw current buffer and recompute text */
449 #define P_RALL		0x6000	/* redraw all windows */
450 #define P_RCLR		0x7000	/* clear and redraw all */
451 
452 #define P_COMMA		 0x8000	 /* comma separated list */
453 #define P_ONECOMMA	0x18000L /* P_COMMA and cannot have two consecutive
454 				  * commas */
455 #define P_NODUP		0x20000L /* don't allow duplicate strings */
456 #define P_FLAGLIST	0x40000L /* list of single-char flags */
457 
458 #define P_SECURE	0x80000L /* cannot change in modeline or secure mode */
459 #define P_GETTEXT      0x100000L /* expand default value with _() */
460 #define P_NOGLOB       0x200000L /* do not use local value for global vimrc */
461 #define P_NFNAME       0x400000L /* only normal file name chars allowed */
462 #define P_INSECURE     0x800000L /* option was set from a modeline */
463 #define P_PRI_MKRC    0x1000000L /* priority for :mkvimrc (setting option has
464 				    side effects) */
465 #define P_NO_ML       0x2000000L /* not allowed in modeline */
466 #define P_CURSWANT    0x4000000L /* update curswant required; not needed when
467 				  * there is a redraw flag */
468 #define P_NDNAME      0x8000000L /* only normal dir name chars allowed */
469 #define P_RWINONLY   0x10000000L /* only redraw current window */
470 
471 #define ISK_LATIN1  (char_u *)"@,48-57,_,192-255"
472 
473 /* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
474  * for the currency sign. */
475 #if defined(MSWIN)
476 # define ISP_LATIN1 (char_u *)"@,~-255"
477 #else
478 # define ISP_LATIN1 (char_u *)"@,161-255"
479 #endif
480 
481 # 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"
482 
483 /* Default python version for pyx* commands */
484 #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
485 # define DEFAULT_PYTHON_VER	0
486 #elif defined(FEAT_PYTHON3)
487 # define DEFAULT_PYTHON_VER	3
488 #elif defined(FEAT_PYTHON)
489 # define DEFAULT_PYTHON_VER	2
490 #else
491 # define DEFAULT_PYTHON_VER	0
492 #endif
493 
494 // used for 'cinkeys' and 'indentkeys'
495 #define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
496 
497 /*
498  * options[] is initialized here.
499  * The order of the options MUST be alphabetic for ":set all" and findoption().
500  * All option names MUST start with a lowercase letter (for findoption()).
501  * Exception: "t_" options are at the end.
502  * The options with a NULL variable are 'hidden': a set command for them is
503  * ignored and they are not printed.
504  */
505 static struct vimoption options[] =
506 {
507     {"aleph",	    "al",   P_NUM|P_VI_DEF|P_CURSWANT,
508 #ifdef FEAT_RIGHTLEFT
509 			    (char_u *)&p_aleph, PV_NONE,
510 #else
511 			    (char_u *)NULL, PV_NONE,
512 #endif
513 			    {
514 #if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
515 			    (char_u *)128L,
516 #else
517 			    (char_u *)224L,
518 #endif
519 					    (char_u *)0L} SCTX_INIT},
520     {"antialias",   "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
521 #if defined(FEAT_GUI_MAC)
522 			    (char_u *)&p_antialias, PV_NONE,
523 			    {(char_u *)FALSE, (char_u *)FALSE}
524 #else
525 			    (char_u *)NULL, PV_NONE,
526 			    {(char_u *)FALSE, (char_u *)FALSE}
527 #endif
528 			    SCTX_INIT},
529     {"arabic",	    "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
530 #ifdef FEAT_ARABIC
531 			    (char_u *)VAR_WIN, PV_ARAB,
532 #else
533 			    (char_u *)NULL, PV_NONE,
534 #endif
535 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
536     {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
537 #ifdef FEAT_ARABIC
538 			    (char_u *)&p_arshape, PV_NONE,
539 #else
540 			    (char_u *)NULL, PV_NONE,
541 #endif
542 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
543     {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
544 #ifdef FEAT_RIGHTLEFT
545 			    (char_u *)&p_ari, PV_NONE,
546 #else
547 			    (char_u *)NULL, PV_NONE,
548 #endif
549 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
550     {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
551 			    (char_u *)NULL, PV_NONE,
552 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
553     {"ambiwidth",  "ambw",  P_STRING|P_VI_DEF|P_RCLR,
554 			    (char_u *)&p_ambw, PV_NONE,
555 			    {(char_u *)"single", (char_u *)0L}
556 			    SCTX_INIT},
557     {"autochdir",  "acd",   P_BOOL|P_VI_DEF,
558 #ifdef FEAT_AUTOCHDIR
559 			    (char_u *)&p_acd, PV_NONE,
560 			    {(char_u *)FALSE, (char_u *)0L}
561 #else
562 			    (char_u *)NULL, PV_NONE,
563 			    {(char_u *)0L, (char_u *)0L}
564 #endif
565 			    SCTX_INIT},
566     {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
567 			    (char_u *)&p_ai, PV_AI,
568 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
569     {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
570 			    (char_u *)NULL, PV_NONE,
571 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
572     {"autoread",    "ar",   P_BOOL|P_VI_DEF,
573 			    (char_u *)&p_ar, PV_AR,
574 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
575     {"autowrite",   "aw",   P_BOOL|P_VI_DEF,
576 			    (char_u *)&p_aw, PV_NONE,
577 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
578     {"autowriteall","awa",  P_BOOL|P_VI_DEF,
579 			    (char_u *)&p_awa, PV_NONE,
580 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
581     {"background",  "bg",   P_STRING|P_VI_DEF|P_RCLR,
582 			    (char_u *)&p_bg, PV_NONE,
583 			    {
584 #if (defined(MSWIN)) && !defined(FEAT_GUI)
585 			    (char_u *)"dark",
586 #else
587 			    (char_u *)"light",
588 #endif
589 					    (char_u *)0L} SCTX_INIT},
590     {"backspace",   "bs",   P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
591 			    (char_u *)&p_bs, PV_NONE,
592 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
593     {"backup",	    "bk",   P_BOOL|P_VI_DEF|P_VIM,
594 			    (char_u *)&p_bk, PV_NONE,
595 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
596     {"backupcopy",  "bkc",  P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
597 			    (char_u *)&p_bkc, PV_BKC,
598 #ifdef UNIX
599 			    {(char_u *)"yes", (char_u *)"auto"}
600 #else
601 			    {(char_u *)"auto", (char_u *)"auto"}
602 #endif
603 			    SCTX_INIT},
604     {"backupdir",   "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
605 							    |P_NODUP|P_SECURE,
606 			    (char_u *)&p_bdir, PV_NONE,
607 			    {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
608     {"backupext",   "bex",  P_STRING|P_VI_DEF|P_NFNAME,
609 			    (char_u *)&p_bex, PV_NONE,
610 			    {
611 #ifdef VMS
612 			    (char_u *)"_",
613 #else
614 			    (char_u *)"~",
615 #endif
616 					    (char_u *)0L} SCTX_INIT},
617     {"backupskip",  "bsk",  P_STRING|P_VI_DEF|P_ONECOMMA,
618 #ifdef FEAT_WILDIGN
619 			    (char_u *)&p_bsk, PV_NONE,
620 			    {(char_u *)"", (char_u *)0L}
621 #else
622 			    (char_u *)NULL, PV_NONE,
623 			    {(char_u *)0L, (char_u *)0L}
624 #endif
625 			    SCTX_INIT},
626     {"balloondelay","bdlay",P_NUM|P_VI_DEF,
627 #ifdef FEAT_BEVAL
628 			    (char_u *)&p_bdlay, PV_NONE,
629 			    {(char_u *)600L, (char_u *)0L}
630 #else
631 			    (char_u *)NULL, PV_NONE,
632 			    {(char_u *)0L, (char_u *)0L}
633 #endif
634 			    SCTX_INIT},
635     {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
636 #ifdef FEAT_BEVAL_GUI
637 			    (char_u *)&p_beval, PV_NONE,
638 			    {(char_u *)FALSE, (char_u *)0L}
639 #else
640 			    (char_u *)NULL, PV_NONE,
641 			    {(char_u *)0L, (char_u *)0L}
642 #endif
643 			    SCTX_INIT},
644     {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
645 #ifdef FEAT_BEVAL_TERM
646 			    (char_u *)&p_bevalterm, PV_NONE,
647 			    {(char_u *)FALSE, (char_u *)0L}
648 #else
649 			    (char_u *)NULL, PV_NONE,
650 			    {(char_u *)0L, (char_u *)0L}
651 #endif
652 			    SCTX_INIT},
653     {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
654 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
655 			    (char_u *)&p_bexpr, PV_BEXPR,
656 			    {(char_u *)"", (char_u *)0L}
657 #else
658 			    (char_u *)NULL, PV_NONE,
659 			    {(char_u *)0L, (char_u *)0L}
660 #endif
661 			    SCTX_INIT},
662     {"beautify",    "bf",   P_BOOL|P_VI_DEF,
663 			    (char_u *)NULL, PV_NONE,
664 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
665     {"belloff",      "bo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
666 			    (char_u *)&p_bo, PV_NONE,
667 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
668     {"binary",	    "bin",  P_BOOL|P_VI_DEF|P_RSTAT,
669 			    (char_u *)&p_bin, PV_BIN,
670 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
671     {"bioskey",	    "biosk",P_BOOL|P_VI_DEF,
672 			    (char_u *)NULL, PV_NONE,
673 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
674     {"bomb",	    NULL,   P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
675 			    (char_u *)&p_bomb, PV_BOMB,
676 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
677     {"breakat",	    "brk",  P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
678 #ifdef FEAT_LINEBREAK
679 			    (char_u *)&p_breakat, PV_NONE,
680 			    {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
681 #else
682 			    (char_u *)NULL, PV_NONE,
683 			    {(char_u *)0L, (char_u *)0L}
684 #endif
685 			    SCTX_INIT},
686     {"breakindent",   "bri",  P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
687 #ifdef FEAT_LINEBREAK
688 			    (char_u *)VAR_WIN, PV_BRI,
689 			    {(char_u *)FALSE, (char_u *)0L}
690 #else
691 			    (char_u *)NULL, PV_NONE,
692 			    {(char_u *)0L, (char_u *)0L}
693 #endif
694 			    SCTX_INIT},
695     {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
696 						  |P_ONECOMMA|P_NODUP,
697 #ifdef FEAT_LINEBREAK
698 			    (char_u *)VAR_WIN, PV_BRIOPT,
699 			    {(char_u *)"", (char_u *)NULL}
700 #else
701 			    (char_u *)NULL, PV_NONE,
702 			    {(char_u *)"", (char_u *)NULL}
703 #endif
704 			    SCTX_INIT},
705     {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
706 #ifdef FEAT_BROWSE
707 			    (char_u *)&p_bsdir, PV_NONE,
708 			    {(char_u *)"last", (char_u *)0L}
709 #else
710 			    (char_u *)NULL, PV_NONE,
711 			    {(char_u *)0L, (char_u *)0L}
712 #endif
713 			    SCTX_INIT},
714     {"bufhidden",   "bh",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
715 			    (char_u *)&p_bh, PV_BH,
716 			    {(char_u *)"", (char_u *)0L}
717 			    SCTX_INIT},
718     {"buflisted",   "bl",   P_BOOL|P_VI_DEF|P_NOGLOB,
719 			    (char_u *)&p_bl, PV_BL,
720 			    {(char_u *)1L, (char_u *)0L}
721 			    SCTX_INIT},
722     {"buftype",	    "bt",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
723 			    (char_u *)&p_bt, PV_BT,
724 			    {(char_u *)"", (char_u *)0L}
725 			    SCTX_INIT},
726     {"casemap",	    "cmp",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
727 			    (char_u *)&p_cmp, PV_NONE,
728 			    {(char_u *)"internal,keepascii", (char_u *)0L}
729 			    SCTX_INIT},
730     {"cdpath",	    "cd",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
731 #ifdef FEAT_SEARCHPATH
732 			    (char_u *)&p_cdpath, PV_NONE,
733 			    {(char_u *)",,", (char_u *)0L}
734 #else
735 			    (char_u *)NULL, PV_NONE,
736 			    {(char_u *)0L, (char_u *)0L}
737 #endif
738 			    SCTX_INIT},
739     {"cedit",	    NULL,   P_STRING,
740 #ifdef FEAT_CMDWIN
741 			    (char_u *)&p_cedit, PV_NONE,
742 			    {(char_u *)"", (char_u *)CTRL_F_STR}
743 #else
744 			    (char_u *)NULL, PV_NONE,
745 			    {(char_u *)0L, (char_u *)0L}
746 #endif
747 			    SCTX_INIT},
748     {"charconvert",  "ccv", P_STRING|P_VI_DEF|P_SECURE,
749 #if defined(FEAT_EVAL)
750 			    (char_u *)&p_ccv, PV_NONE,
751 			    {(char_u *)"", (char_u *)0L}
752 #else
753 			    (char_u *)NULL, PV_NONE,
754 			    {(char_u *)0L, (char_u *)0L}
755 #endif
756 			    SCTX_INIT},
757     {"cindent",	    "cin",  P_BOOL|P_VI_DEF|P_VIM,
758 #ifdef FEAT_CINDENT
759 			    (char_u *)&p_cin, PV_CIN,
760 #else
761 			    (char_u *)NULL, PV_NONE,
762 #endif
763 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
764     {"cinkeys",	    "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
765 #ifdef FEAT_CINDENT
766 			    (char_u *)&p_cink, PV_CINK,
767 			    {INDENTKEYS_DEFAULT, (char_u *)0L}
768 #else
769 			    (char_u *)NULL, PV_NONE,
770 			    {(char_u *)0L, (char_u *)0L}
771 #endif
772 			    SCTX_INIT},
773     {"cinoptions",  "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
774 #ifdef FEAT_CINDENT
775 			    (char_u *)&p_cino, PV_CINO,
776 #else
777 			    (char_u *)NULL, PV_NONE,
778 #endif
779 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
780     {"cinwords",    "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
781 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
782 			    (char_u *)&p_cinw, PV_CINW,
783 			    {(char_u *)"if,else,while,do,for,switch",
784 				(char_u *)0L}
785 #else
786 			    (char_u *)NULL, PV_NONE,
787 			    {(char_u *)0L, (char_u *)0L}
788 #endif
789 			    SCTX_INIT},
790     {"clipboard",   "cb",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
791 #ifdef FEAT_CLIPBOARD
792 			    (char_u *)&p_cb, PV_NONE,
793 # ifdef FEAT_XCLIPBOARD
794 			    {(char_u *)"autoselect,exclude:cons\\|linux",
795 							       (char_u *)0L}
796 # else
797 			    {(char_u *)"", (char_u *)0L}
798 # endif
799 #else
800 			    (char_u *)NULL, PV_NONE,
801 			    {(char_u *)"", (char_u *)0L}
802 #endif
803 			    SCTX_INIT},
804     {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
805 			    (char_u *)&p_ch, PV_NONE,
806 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
807     {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
808 #ifdef FEAT_CMDWIN
809 			    (char_u *)&p_cwh, PV_NONE,
810 #else
811 			    (char_u *)NULL, PV_NONE,
812 #endif
813 			    {(char_u *)7L, (char_u *)0L} SCTX_INIT},
814     {"colorcolumn", "cc",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
815 #ifdef FEAT_SYN_HL
816 			    (char_u *)VAR_WIN, PV_CC,
817 #else
818 			    (char_u *)NULL, PV_NONE,
819 #endif
820 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
821     {"columns",	    "co",   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
822 			    (char_u *)&Columns, PV_NONE,
823 			    {(char_u *)80L, (char_u *)0L} SCTX_INIT},
824     {"comments",    "com",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
825 							  |P_NODUP|P_CURSWANT,
826 #ifdef FEAT_COMMENTS
827 			    (char_u *)&p_com, PV_COM,
828 			    {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
829 				(char_u *)0L}
830 #else
831 			    (char_u *)NULL, PV_NONE,
832 			    {(char_u *)0L, (char_u *)0L}
833 #endif
834 			    SCTX_INIT},
835     {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
836 #ifdef FEAT_FOLDING
837 			    (char_u *)&p_cms, PV_CMS,
838 			    {(char_u *)"/*%s*/", (char_u *)0L}
839 #else
840 			    (char_u *)NULL, PV_NONE,
841 			    {(char_u *)0L, (char_u *)0L}
842 #endif
843 			    SCTX_INIT},
844 			    /* P_PRI_MKRC isn't needed here, optval_default()
845 			     * always returns TRUE for 'compatible' */
846     {"compatible",  "cp",   P_BOOL|P_RALL,
847 			    (char_u *)&p_cp, PV_NONE,
848 			    {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
849     {"complete",    "cpt",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
850 #ifdef FEAT_INS_EXPAND
851 			    (char_u *)&p_cpt, PV_CPT,
852 			    {(char_u *)".,w,b,u,t,i", (char_u *)0L}
853 #else
854 			    (char_u *)NULL, PV_NONE,
855 			    {(char_u *)0L, (char_u *)0L}
856 #endif
857 			    SCTX_INIT},
858     {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
859 #ifdef FEAT_CONCEAL
860 			    (char_u *)VAR_WIN, PV_COCU,
861 			    {(char_u *)"", (char_u *)NULL}
862 #else
863 			    (char_u *)NULL, PV_NONE,
864 			    {(char_u *)NULL, (char_u *)0L}
865 #endif
866 			    SCTX_INIT},
867     {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
868 #ifdef FEAT_CONCEAL
869 			    (char_u *)VAR_WIN, PV_COLE,
870 #else
871 			    (char_u *)NULL, PV_NONE,
872 #endif
873 			    {(char_u *)0L, (char_u *)0L}
874 			    SCTX_INIT},
875     {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
876 #ifdef FEAT_COMPL_FUNC
877 			    (char_u *)&p_cfu, PV_CFU,
878 			    {(char_u *)"", (char_u *)0L}
879 #else
880 			    (char_u *)NULL, PV_NONE,
881 			    {(char_u *)0L, (char_u *)0L}
882 #endif
883 			    SCTX_INIT},
884     {"completeopt",   "cot",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
885 #ifdef FEAT_INS_EXPAND
886 			    (char_u *)&p_cot, PV_NONE,
887 			    {(char_u *)"menu,preview", (char_u *)0L}
888 #else
889 			    (char_u *)NULL, PV_NONE,
890 			    {(char_u *)0L, (char_u *)0L}
891 #endif
892 			    SCTX_INIT},
893     {"confirm",     "cf",   P_BOOL|P_VI_DEF,
894 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
895 			    (char_u *)&p_confirm, PV_NONE,
896 #else
897 			    (char_u *)NULL, PV_NONE,
898 #endif
899 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
900     {"conskey",	    "consk",P_BOOL|P_VI_DEF,
901 			    (char_u *)NULL, PV_NONE,
902 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
903     {"copyindent",  "ci",   P_BOOL|P_VI_DEF|P_VIM,
904 			    (char_u *)&p_ci, PV_CI,
905 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
906     {"cpoptions",   "cpo",  P_STRING|P_VIM|P_RALL|P_FLAGLIST,
907 			    (char_u *)&p_cpo, PV_NONE,
908 			    {(char_u *)CPO_VI, (char_u *)CPO_VIM}
909 			    SCTX_INIT},
910     {"cryptmethod", "cm",   P_STRING|P_ALLOCED|P_VI_DEF,
911 #ifdef FEAT_CRYPT
912 			    (char_u *)&p_cm, PV_CM,
913 			    {(char_u *)"blowfish2", (char_u *)0L}
914 #else
915 			    (char_u *)NULL, PV_NONE,
916 			    {(char_u *)0L, (char_u *)0L}
917 #endif
918 			    SCTX_INIT},
919     {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
920 #ifdef FEAT_CSCOPE
921 			    (char_u *)&p_cspc, PV_NONE,
922 #else
923 			    (char_u *)NULL, PV_NONE,
924 #endif
925 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
926     {"cscopeprg",   "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
927 #ifdef FEAT_CSCOPE
928 			    (char_u *)&p_csprg, PV_NONE,
929 			    {(char_u *)"cscope", (char_u *)0L}
930 #else
931 			    (char_u *)NULL, PV_NONE,
932 			    {(char_u *)0L, (char_u *)0L}
933 #endif
934 			    SCTX_INIT},
935     {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
936 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
937 			    (char_u *)&p_csqf, PV_NONE,
938 			    {(char_u *)"", (char_u *)0L}
939 #else
940 			    (char_u *)NULL, PV_NONE,
941 			    {(char_u *)0L, (char_u *)0L}
942 #endif
943 			    SCTX_INIT},
944     {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
945 #ifdef FEAT_CSCOPE
946 			    (char_u *)&p_csre, PV_NONE,
947 #else
948 			    (char_u *)NULL, PV_NONE,
949 #endif
950 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
951     {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
952 #ifdef FEAT_CSCOPE
953 			    (char_u *)&p_cst, PV_NONE,
954 #else
955 			    (char_u *)NULL, PV_NONE,
956 #endif
957 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
958     {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
959 #ifdef FEAT_CSCOPE
960 			    (char_u *)&p_csto, PV_NONE,
961 #else
962 			    (char_u *)NULL, PV_NONE,
963 #endif
964 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
965     {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
966 #ifdef FEAT_CSCOPE
967 			    (char_u *)&p_csverbose, PV_NONE,
968 #else
969 			    (char_u *)NULL, PV_NONE,
970 #endif
971 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
972     {"cursorbind",  "crb",  P_BOOL|P_VI_DEF,
973 			    (char_u *)VAR_WIN, PV_CRBIND,
974 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
975     {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
976 #ifdef FEAT_SYN_HL
977 			    (char_u *)VAR_WIN, PV_CUC,
978 #else
979 			    (char_u *)NULL, PV_NONE,
980 #endif
981 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
982     {"cursorline",   "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
983 #ifdef FEAT_SYN_HL
984 			    (char_u *)VAR_WIN, PV_CUL,
985 #else
986 			    (char_u *)NULL, PV_NONE,
987 #endif
988 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
989     {"debug",	    NULL,   P_STRING|P_VI_DEF,
990 			    (char_u *)&p_debug, PV_NONE,
991 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
992     {"define",	    "def",  P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
993 #ifdef FEAT_FIND_ID
994 			    (char_u *)&p_def, PV_DEF,
995 			    {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
996 #else
997 			    (char_u *)NULL, PV_NONE,
998 			    {(char_u *)NULL, (char_u *)0L}
999 #endif
1000 			    SCTX_INIT},
1001     {"delcombine", "deco",  P_BOOL|P_VI_DEF|P_VIM,
1002 			    (char_u *)&p_deco, PV_NONE,
1003 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1004     {"dictionary",  "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
1005 #ifdef FEAT_INS_EXPAND
1006 			    (char_u *)&p_dict, PV_DICT,
1007 #else
1008 			    (char_u *)NULL, PV_NONE,
1009 #endif
1010 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1011     {"diff",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1012 #ifdef FEAT_DIFF
1013 			    (char_u *)VAR_WIN, PV_DIFF,
1014 #else
1015 			    (char_u *)NULL, PV_NONE,
1016 #endif
1017 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1018     {"diffexpr",    "dex",  P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
1019 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1020 			    (char_u *)&p_dex, PV_NONE,
1021 			    {(char_u *)"", (char_u *)0L}
1022 #else
1023 			    (char_u *)NULL, PV_NONE,
1024 			    {(char_u *)0L, (char_u *)0L}
1025 #endif
1026 			    SCTX_INIT},
1027     {"diffopt",	    "dip",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1028 								     |P_NODUP,
1029 #ifdef FEAT_DIFF
1030 			    (char_u *)&p_dip, PV_NONE,
1031 			    {(char_u *)"internal,filler", (char_u *)NULL}
1032 #else
1033 			    (char_u *)NULL, PV_NONE,
1034 			    {(char_u *)"", (char_u *)NULL}
1035 #endif
1036 			    SCTX_INIT},
1037     {"digraph",	    "dg",   P_BOOL|P_VI_DEF|P_VIM,
1038 #ifdef FEAT_DIGRAPHS
1039 			    (char_u *)&p_dg, PV_NONE,
1040 #else
1041 			    (char_u *)NULL, PV_NONE,
1042 #endif
1043 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1044     {"directory",   "dir",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1045 							    |P_NODUP|P_SECURE,
1046 			    (char_u *)&p_dir, PV_NONE,
1047 			    {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
1048     {"display",	    "dy",   P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
1049 			    (char_u *)&p_dy, PV_NONE,
1050 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1051     {"eadirection", "ead",  P_STRING|P_VI_DEF,
1052 			    (char_u *)&p_ead, PV_NONE,
1053 			    {(char_u *)"both", (char_u *)0L}
1054 			    SCTX_INIT},
1055     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
1056 			    (char_u *)&p_ed, PV_NONE,
1057 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1058     {"emoji",  "emo",	    P_BOOL|P_VI_DEF|P_RCLR,
1059 			    (char_u *)&p_emoji, PV_NONE,
1060 			    {(char_u *)TRUE, (char_u *)0L}
1061 			    SCTX_INIT},
1062     {"encoding",    "enc",  P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
1063 			    (char_u *)&p_enc, PV_NONE,
1064 			    {(char_u *)ENC_DFLT, (char_u *)0L}
1065 			    SCTX_INIT},
1066     {"endofline",   "eol",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1067 			    (char_u *)&p_eol, PV_EOL,
1068 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1069     {"equalalways", "ea",   P_BOOL|P_VI_DEF|P_RALL,
1070 			    (char_u *)&p_ea, PV_NONE,
1071 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1072     {"equalprg",    "ep",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1073 			    (char_u *)&p_ep, PV_EP,
1074 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1075     {"errorbells",  "eb",   P_BOOL|P_VI_DEF,
1076 			    (char_u *)&p_eb, PV_NONE,
1077 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1078     {"errorfile",   "ef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1079 #ifdef FEAT_QUICKFIX
1080 			    (char_u *)&p_ef, PV_NONE,
1081 			    {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1082 #else
1083 			    (char_u *)NULL, PV_NONE,
1084 			    {(char_u *)NULL, (char_u *)0L}
1085 #endif
1086 			    SCTX_INIT},
1087     {"errorformat", "efm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1088 #ifdef FEAT_QUICKFIX
1089 			    (char_u *)&p_efm, PV_EFM,
1090 			    {(char_u *)DFLT_EFM, (char_u *)0L}
1091 #else
1092 			    (char_u *)NULL, PV_NONE,
1093 			    {(char_u *)NULL, (char_u *)0L}
1094 #endif
1095 			    SCTX_INIT},
1096     {"esckeys",	    "ek",   P_BOOL|P_VIM,
1097 			    (char_u *)&p_ek, PV_NONE,
1098 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
1099     {"eventignore", "ei",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1100 			    (char_u *)&p_ei, PV_NONE,
1101 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1102     {"expandtab",   "et",   P_BOOL|P_VI_DEF|P_VIM,
1103 			    (char_u *)&p_et, PV_ET,
1104 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1105     {"exrc",	    "ex",   P_BOOL|P_VI_DEF|P_SECURE,
1106 			    (char_u *)&p_exrc, PV_NONE,
1107 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1108     {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1109 								   |P_NO_MKRC,
1110 			    (char_u *)&p_fenc, PV_FENC,
1111 			    {(char_u *)"", (char_u *)0L}
1112 			    SCTX_INIT},
1113     {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
1114 			    (char_u *)&p_fencs, PV_NONE,
1115 			    {(char_u *)"ucs-bom", (char_u *)0L}
1116 			    SCTX_INIT},
1117     {"fileformat",  "ff",   P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1118 								  |P_CURSWANT,
1119 			    (char_u *)&p_ff, PV_FF,
1120 			    {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
1121     {"fileformats", "ffs",  P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
1122 			    (char_u *)&p_ffs, PV_NONE,
1123 			    {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1124 			    SCTX_INIT},
1125     {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1126 			    (char_u *)&p_fic, PV_NONE,
1127 			    {
1128 #ifdef CASE_INSENSITIVE_FILENAME
1129 				    (char_u *)TRUE,
1130 #else
1131 				    (char_u *)FALSE,
1132 #endif
1133 					(char_u *)0L} SCTX_INIT},
1134     {"filetype",    "ft",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
1135 			    (char_u *)&p_ft, PV_FT,
1136 			    {(char_u *)"", (char_u *)0L}
1137 			    SCTX_INIT},
1138     {"fillchars",   "fcs",  P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
1139 			    (char_u *)&p_fcs, PV_NONE,
1140 			    {(char_u *)"vert:|,fold:-", (char_u *)0L}
1141 			    SCTX_INIT},
1142     {"fixendofline",  "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1143 			    (char_u *)&p_fixeol, PV_FIXEOL,
1144 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1145     {"fkmap",	    "fk",   P_BOOL|P_VI_DEF,
1146 			    (char_u *)NULL, PV_NONE,
1147 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1148     {"flash",	    "fl",   P_BOOL|P_VI_DEF,
1149 			    (char_u *)NULL, PV_NONE,
1150 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1151     {"foldclose",   "fcl",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
1152 #ifdef FEAT_FOLDING
1153 			    (char_u *)&p_fcl, PV_NONE,
1154 			    {(char_u *)"", (char_u *)0L}
1155 #else
1156 			    (char_u *)NULL, PV_NONE,
1157 			    {(char_u *)NULL, (char_u *)0L}
1158 #endif
1159 			    SCTX_INIT},
1160     {"foldcolumn",  "fdc",  P_NUM|P_VI_DEF|P_RWIN,
1161 #ifdef FEAT_FOLDING
1162 			    (char_u *)VAR_WIN, PV_FDC,
1163 			    {(char_u *)FALSE, (char_u *)0L}
1164 #else
1165 			    (char_u *)NULL, PV_NONE,
1166 			    {(char_u *)NULL, (char_u *)0L}
1167 #endif
1168 			    SCTX_INIT},
1169     {"foldenable",  "fen",  P_BOOL|P_VI_DEF|P_RWIN,
1170 #ifdef FEAT_FOLDING
1171 			    (char_u *)VAR_WIN, PV_FEN,
1172 			    {(char_u *)TRUE, (char_u *)0L}
1173 #else
1174 			    (char_u *)NULL, PV_NONE,
1175 			    {(char_u *)NULL, (char_u *)0L}
1176 #endif
1177 			    SCTX_INIT},
1178     {"foldexpr",    "fde",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1179 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1180 			    (char_u *)VAR_WIN, PV_FDE,
1181 			    {(char_u *)"0", (char_u *)NULL}
1182 #else
1183 			    (char_u *)NULL, PV_NONE,
1184 			    {(char_u *)NULL, (char_u *)0L}
1185 #endif
1186 			    SCTX_INIT},
1187     {"foldignore",  "fdi",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1188 #ifdef FEAT_FOLDING
1189 			    (char_u *)VAR_WIN, PV_FDI,
1190 			    {(char_u *)"#", (char_u *)NULL}
1191 #else
1192 			    (char_u *)NULL, PV_NONE,
1193 			    {(char_u *)NULL, (char_u *)0L}
1194 #endif
1195 			    SCTX_INIT},
1196     {"foldlevel",   "fdl",  P_NUM|P_VI_DEF|P_RWIN,
1197 #ifdef FEAT_FOLDING
1198 			    (char_u *)VAR_WIN, PV_FDL,
1199 			    {(char_u *)0L, (char_u *)0L}
1200 #else
1201 			    (char_u *)NULL, PV_NONE,
1202 			    {(char_u *)NULL, (char_u *)0L}
1203 #endif
1204 			    SCTX_INIT},
1205     {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
1206 #ifdef FEAT_FOLDING
1207 			    (char_u *)&p_fdls, PV_NONE,
1208 			    {(char_u *)-1L, (char_u *)0L}
1209 #else
1210 			    (char_u *)NULL, PV_NONE,
1211 			    {(char_u *)NULL, (char_u *)0L}
1212 #endif
1213 			    SCTX_INIT},
1214     {"foldmarker",  "fmr",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1215 						    P_RWIN|P_ONECOMMA|P_NODUP,
1216 #ifdef FEAT_FOLDING
1217 			    (char_u *)VAR_WIN, PV_FMR,
1218 			    {(char_u *)"{{{,}}}", (char_u *)NULL}
1219 #else
1220 			    (char_u *)NULL, PV_NONE,
1221 			    {(char_u *)NULL, (char_u *)0L}
1222 #endif
1223 			    SCTX_INIT},
1224     {"foldmethod",  "fdm",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1225 #ifdef FEAT_FOLDING
1226 			    (char_u *)VAR_WIN, PV_FDM,
1227 			    {(char_u *)"manual", (char_u *)NULL}
1228 #else
1229 			    (char_u *)NULL, PV_NONE,
1230 			    {(char_u *)NULL, (char_u *)0L}
1231 #endif
1232 			    SCTX_INIT},
1233     {"foldminlines","fml",  P_NUM|P_VI_DEF|P_RWIN,
1234 #ifdef FEAT_FOLDING
1235 			    (char_u *)VAR_WIN, PV_FML,
1236 			    {(char_u *)1L, (char_u *)0L}
1237 #else
1238 			    (char_u *)NULL, PV_NONE,
1239 			    {(char_u *)NULL, (char_u *)0L}
1240 #endif
1241 			    SCTX_INIT},
1242     {"foldnestmax", "fdn",  P_NUM|P_VI_DEF|P_RWIN,
1243 #ifdef FEAT_FOLDING
1244 			    (char_u *)VAR_WIN, PV_FDN,
1245 			    {(char_u *)20L, (char_u *)0L}
1246 #else
1247 			    (char_u *)NULL, PV_NONE,
1248 			    {(char_u *)NULL, (char_u *)0L}
1249 #endif
1250 			    SCTX_INIT},
1251     {"foldopen",    "fdo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1252 #ifdef FEAT_FOLDING
1253 			    (char_u *)&p_fdo, PV_NONE,
1254 		 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1255 						 (char_u *)0L}
1256 #else
1257 			    (char_u *)NULL, PV_NONE,
1258 			    {(char_u *)NULL, (char_u *)0L}
1259 #endif
1260 			    SCTX_INIT},
1261     {"foldtext",    "fdt",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1262 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1263 			    (char_u *)VAR_WIN, PV_FDT,
1264 			    {(char_u *)"foldtext()", (char_u *)NULL}
1265 #else
1266 			    (char_u *)NULL, PV_NONE,
1267 			    {(char_u *)NULL, (char_u *)0L}
1268 #endif
1269 			    SCTX_INIT},
1270     {"formatexpr", "fex",   P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1271 #ifdef FEAT_EVAL
1272 			    (char_u *)&p_fex, PV_FEX,
1273 			    {(char_u *)"", (char_u *)0L}
1274 #else
1275 			    (char_u *)NULL, PV_NONE,
1276 			    {(char_u *)0L, (char_u *)0L}
1277 #endif
1278 			    SCTX_INIT},
1279     {"formatoptions","fo",  P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1280 			    (char_u *)&p_fo, PV_FO,
1281 			    {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1282 			    SCTX_INIT},
1283     {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1284 			    (char_u *)&p_flp, PV_FLP,
1285 			    {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1286 						 (char_u *)0L} SCTX_INIT},
1287     {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1288 			    (char_u *)&p_fp, PV_FP,
1289 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1290     {"fsync",       "fs",   P_BOOL|P_SECURE|P_VI_DEF,
1291 #ifdef HAVE_FSYNC
1292 			    (char_u *)&p_fs, PV_NONE,
1293 			    {(char_u *)TRUE, (char_u *)0L}
1294 #else
1295 			    (char_u *)NULL, PV_NONE,
1296 			    {(char_u *)FALSE, (char_u *)0L}
1297 #endif
1298 			    SCTX_INIT},
1299     {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
1300 			    (char_u *)&p_gd, PV_NONE,
1301 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1302     {"graphic",	    "gr",   P_BOOL|P_VI_DEF,
1303 			    (char_u *)NULL, PV_NONE,
1304 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1305     {"grepformat",  "gfm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1306 #ifdef FEAT_QUICKFIX
1307 			    (char_u *)&p_gefm, PV_NONE,
1308 			    {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
1309 #else
1310 			    (char_u *)NULL, PV_NONE,
1311 			    {(char_u *)NULL, (char_u *)0L}
1312 #endif
1313 			    SCTX_INIT},
1314     {"grepprg",	    "gp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1315 #ifdef FEAT_QUICKFIX
1316 			    (char_u *)&p_gp, PV_GP,
1317 			    {
1318 # ifdef MSWIN
1319 			    /* may be changed to "grep -n" in os_win32.c */
1320 			    (char_u *)"findstr /n",
1321 # else
1322 #  ifdef UNIX
1323 			    /* Add an extra file name so that grep will always
1324 			     * insert a file name in the match line. */
1325 			    (char_u *)"grep -n $* /dev/null",
1326 #  else
1327 #   ifdef VMS
1328 			    (char_u *)"SEARCH/NUMBERS ",
1329 #   else
1330 			    (char_u *)"grep -n ",
1331 #   endif
1332 #  endif
1333 # endif
1334 			    (char_u *)0L}
1335 #else
1336 			    (char_u *)NULL, PV_NONE,
1337 			    {(char_u *)NULL, (char_u *)0L}
1338 #endif
1339 			    SCTX_INIT},
1340     {"guicursor",    "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1341 #ifdef CURSOR_SHAPE
1342 			    (char_u *)&p_guicursor, PV_NONE,
1343 			    {
1344 # ifdef FEAT_GUI
1345 				(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",
1346 # else	/* Win32 console */
1347 				(char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1348 # endif
1349 				    (char_u *)0L}
1350 #else
1351 			    (char_u *)NULL, PV_NONE,
1352 			    {(char_u *)NULL, (char_u *)0L}
1353 #endif
1354 			    SCTX_INIT},
1355     {"guifont",	    "gfn",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1356 #ifdef FEAT_GUI
1357 			    (char_u *)&p_guifont, PV_NONE,
1358 			    {(char_u *)"", (char_u *)0L}
1359 #else
1360 			    (char_u *)NULL, PV_NONE,
1361 			    {(char_u *)NULL, (char_u *)0L}
1362 #endif
1363 			    SCTX_INIT},
1364     {"guifontset",  "gfs",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
1365 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1366 			    (char_u *)&p_guifontset, PV_NONE,
1367 			    {(char_u *)"", (char_u *)0L}
1368 #else
1369 			    (char_u *)NULL, PV_NONE,
1370 			    {(char_u *)NULL, (char_u *)0L}
1371 #endif
1372 			    SCTX_INIT},
1373     {"guifontwide", "gfw",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1374 #if defined(FEAT_GUI)
1375 			    (char_u *)&p_guifontwide, PV_NONE,
1376 			    {(char_u *)"", (char_u *)0L}
1377 #else
1378 			    (char_u *)NULL, PV_NONE,
1379 			    {(char_u *)NULL, (char_u *)0L}
1380 #endif
1381 			    SCTX_INIT},
1382     {"guiheadroom", "ghr",  P_NUM|P_VI_DEF,
1383 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
1384 			    (char_u *)&p_ghr, PV_NONE,
1385 #else
1386 			    (char_u *)NULL, PV_NONE,
1387 #endif
1388 			    {(char_u *)50L, (char_u *)0L} SCTX_INIT},
1389     {"guioptions",  "go",   P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
1390 #if defined(FEAT_GUI)
1391 			    (char_u *)&p_go, PV_NONE,
1392 # if defined(UNIX) && !defined(FEAT_GUI_MAC)
1393 			    {(char_u *)"aegimrLtT", (char_u *)0L}
1394 # else
1395 			    {(char_u *)"egmrLtT", (char_u *)0L}
1396 # endif
1397 #else
1398 			    (char_u *)NULL, PV_NONE,
1399 			    {(char_u *)NULL, (char_u *)0L}
1400 #endif
1401 			    SCTX_INIT},
1402     {"guipty",	    NULL,   P_BOOL|P_VI_DEF,
1403 #if defined(FEAT_GUI)
1404 			    (char_u *)&p_guipty, PV_NONE,
1405 #else
1406 			    (char_u *)NULL, PV_NONE,
1407 #endif
1408 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1409     {"guitablabel",  "gtl", P_STRING|P_VI_DEF|P_RWIN,
1410 #if defined(FEAT_GUI_TABLINE)
1411 			    (char_u *)&p_gtl, PV_NONE,
1412 			    {(char_u *)"", (char_u *)0L}
1413 #else
1414 			    (char_u *)NULL, PV_NONE,
1415 			    {(char_u *)NULL, (char_u *)0L}
1416 #endif
1417 			    SCTX_INIT},
1418     {"guitabtooltip",  "gtt", P_STRING|P_VI_DEF|P_RWIN,
1419 #if defined(FEAT_GUI_TABLINE)
1420 			    (char_u *)&p_gtt, PV_NONE,
1421 			    {(char_u *)"", (char_u *)0L}
1422 #else
1423 			    (char_u *)NULL, PV_NONE,
1424 			    {(char_u *)NULL, (char_u *)0L}
1425 #endif
1426 			    SCTX_INIT},
1427     {"hardtabs",    "ht",   P_NUM|P_VI_DEF,
1428 			    (char_u *)NULL, PV_NONE,
1429 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
1430     {"helpfile",    "hf",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1431 			    (char_u *)&p_hf, PV_NONE,
1432 			    {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1433 			    SCTX_INIT},
1434     {"helpheight",  "hh",   P_NUM|P_VI_DEF,
1435 			    (char_u *)&p_hh, PV_NONE,
1436 			    {(char_u *)20L, (char_u *)0L} SCTX_INIT},
1437     {"helplang",    "hlg",  P_STRING|P_VI_DEF|P_ONECOMMA,
1438 #ifdef FEAT_MULTI_LANG
1439 			    (char_u *)&p_hlg, PV_NONE,
1440 			    {(char_u *)"", (char_u *)0L}
1441 #else
1442 			    (char_u *)NULL, PV_NONE,
1443 			    {(char_u *)0L, (char_u *)0L}
1444 #endif
1445 			    SCTX_INIT},
1446     {"hidden",	    "hid",  P_BOOL|P_VI_DEF,
1447 			    (char_u *)&p_hid, PV_NONE,
1448 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1449     {"highlight",   "hl",   P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1450 			    (char_u *)&p_hl, PV_NONE,
1451 			    {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1452 			    SCTX_INIT},
1453     {"history",	    "hi",   P_NUM|P_VIM,
1454 			    (char_u *)&p_hi, PV_NONE,
1455 			    {(char_u *)0L, (char_u *)50L} SCTX_INIT},
1456     {"hkmap",	    "hk",   P_BOOL|P_VI_DEF|P_VIM,
1457 #ifdef FEAT_RIGHTLEFT
1458 			    (char_u *)&p_hkmap, PV_NONE,
1459 #else
1460 			    (char_u *)NULL, PV_NONE,
1461 #endif
1462 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1463     {"hkmapp",	    "hkp",  P_BOOL|P_VI_DEF|P_VIM,
1464 #ifdef FEAT_RIGHTLEFT
1465 			    (char_u *)&p_hkmapp, PV_NONE,
1466 #else
1467 			    (char_u *)NULL, PV_NONE,
1468 #endif
1469 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1470     {"hlsearch",    "hls",  P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1471 			    (char_u *)&p_hls, PV_NONE,
1472 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1473     {"icon",	    NULL,   P_BOOL|P_VI_DEF,
1474 #ifdef FEAT_TITLE
1475 			    (char_u *)&p_icon, PV_NONE,
1476 #else
1477 			    (char_u *)NULL, PV_NONE,
1478 #endif
1479 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1480     {"iconstring",  NULL,   P_STRING|P_VI_DEF,
1481 #ifdef FEAT_TITLE
1482 			    (char_u *)&p_iconstring, PV_NONE,
1483 #else
1484 			    (char_u *)NULL, PV_NONE,
1485 #endif
1486 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1487     {"ignorecase",  "ic",   P_BOOL|P_VI_DEF,
1488 			    (char_u *)&p_ic, PV_NONE,
1489 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1490     {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1491 #if defined(FEAT_EVAL)
1492 			    (char_u *)&p_imaf, PV_NONE,
1493 			    {(char_u *)"", (char_u *)NULL}
1494 # else
1495 			    (char_u *)NULL, PV_NONE,
1496 			    {(char_u *)NULL, (char_u *)0L}
1497 # endif
1498 			    SCTX_INIT},
1499     {"imactivatekey","imak",P_STRING|P_VI_DEF,
1500 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1501 			    (char_u *)&p_imak, PV_NONE,
1502 #else
1503 			    (char_u *)NULL, PV_NONE,
1504 #endif
1505 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1506     {"imcmdline",   "imc",  P_BOOL|P_VI_DEF,
1507 			    (char_u *)&p_imcmdline, PV_NONE,
1508 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1509     {"imdisable",   "imd",  P_BOOL|P_VI_DEF,
1510 			    (char_u *)&p_imdisable, PV_NONE,
1511 #ifdef __sgi
1512 			    {(char_u *)TRUE, (char_u *)0L}
1513 #else
1514 			    {(char_u *)FALSE, (char_u *)0L}
1515 #endif
1516 			    SCTX_INIT},
1517     {"iminsert",    "imi",  P_NUM|P_VI_DEF,
1518 			    (char_u *)&p_iminsert, PV_IMI,
1519 			    {(char_u *)B_IMODE_NONE, (char_u *)0L}
1520 			    SCTX_INIT},
1521     {"imsearch",    "ims",  P_NUM|P_VI_DEF,
1522 			    (char_u *)&p_imsearch, PV_IMS,
1523 			    {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
1524 			    SCTX_INIT},
1525     {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
1526 #if defined(FEAT_EVAL)
1527 			    (char_u *)&p_imsf, PV_NONE,
1528 			    {(char_u *)"", (char_u *)NULL}
1529 #else
1530 			    (char_u *)NULL, PV_NONE,
1531 			    {(char_u *)NULL, (char_u *)0L}
1532 #endif
1533 			    SCTX_INIT},
1534     {"imstyle",	    "imst", P_NUM|P_VI_DEF|P_SECURE,
1535 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1536 			    (char_u *)&p_imst, PV_NONE,
1537 			    {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1538 #else
1539 			    (char_u *)NULL, PV_NONE,
1540 			    {(char_u *)0L, (char_u *)0L}
1541 #endif
1542 			    SCTX_INIT},
1543     {"include",	    "inc",  P_STRING|P_ALLOCED|P_VI_DEF,
1544 #ifdef FEAT_FIND_ID
1545 			    (char_u *)&p_inc, PV_INC,
1546 			    {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1547 #else
1548 			    (char_u *)NULL, PV_NONE,
1549 			    {(char_u *)0L, (char_u *)0L}
1550 #endif
1551 			    SCTX_INIT},
1552     {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1553 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1554 			    (char_u *)&p_inex, PV_INEX,
1555 			    {(char_u *)"", (char_u *)0L}
1556 #else
1557 			    (char_u *)NULL, PV_NONE,
1558 			    {(char_u *)0L, (char_u *)0L}
1559 #endif
1560 			    SCTX_INIT},
1561     {"incsearch",   "is",   P_BOOL|P_VI_DEF|P_VIM,
1562 			    (char_u *)&p_is, PV_NONE,
1563 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1564     {"indentexpr", "inde",  P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1565 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1566 			    (char_u *)&p_inde, PV_INDE,
1567 			    {(char_u *)"", (char_u *)0L}
1568 #else
1569 			    (char_u *)NULL, PV_NONE,
1570 			    {(char_u *)0L, (char_u *)0L}
1571 #endif
1572 			    SCTX_INIT},
1573     {"indentkeys", "indk",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1574 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1575 			    (char_u *)&p_indk, PV_INDK,
1576 			    {INDENTKEYS_DEFAULT, (char_u *)0L}
1577 #else
1578 			    (char_u *)NULL, PV_NONE,
1579 			    {(char_u *)0L, (char_u *)0L}
1580 #endif
1581 			    SCTX_INIT},
1582     {"infercase",   "inf",  P_BOOL|P_VI_DEF,
1583 			    (char_u *)&p_inf, PV_INF,
1584 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1585     {"insertmode",  "im",   P_BOOL|P_VI_DEF|P_VIM,
1586 			    (char_u *)&p_im, PV_NONE,
1587 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1588     {"isfname",	    "isf",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1589 			    (char_u *)&p_isf, PV_NONE,
1590 			    {
1591 #ifdef BACKSLASH_IN_FILENAME
1592 				/* Excluded are: & and ^ are special in cmd.exe
1593 				 * ( and ) are used in text separating fnames */
1594 			    (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1595 #else
1596 # ifdef AMIGA
1597 			    (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1598 # else
1599 #  ifdef VMS
1600 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1601 #  else /* UNIX et al. */
1602 #   ifdef EBCDIC
1603 			    (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1604 #   else
1605 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1606 #   endif
1607 #  endif
1608 # endif
1609 #endif
1610 				(char_u *)0L} SCTX_INIT},
1611     {"isident",	    "isi",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1612 			    (char_u *)&p_isi, PV_NONE,
1613 			    {
1614 #if defined(MSWIN)
1615 			    (char_u *)"@,48-57,_,128-167,224-235",
1616 #else
1617 # ifdef EBCDIC
1618 			    /* TODO: EBCDIC Check this! @ == isalpha()*/
1619 			    (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1620 				    "112-120,128,140-142,156,158,172,"
1621 				    "174,186,191,203-207,219-225,235-239,"
1622 				    "251-254",
1623 # else
1624 			    (char_u *)"@,48-57,_,192-255",
1625 # endif
1626 #endif
1627 				(char_u *)0L} SCTX_INIT},
1628     {"iskeyword",   "isk",  P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1629 			    (char_u *)&p_isk, PV_ISK,
1630 			    {
1631 #ifdef EBCDIC
1632 			     (char_u *)"@,240-249,_",
1633 			     /* TODO: EBCDIC Check this! @ == isalpha()*/
1634 			     (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1635 				    "112-120,128,140-142,156,158,172,"
1636 				    "174,186,191,203-207,219-225,235-239,"
1637 				    "251-254",
1638 #else
1639 				(char_u *)"@,48-57,_",
1640 # if defined(MSWIN)
1641 				(char_u *)"@,48-57,_,128-167,224-235"
1642 # else
1643 				ISK_LATIN1
1644 # endif
1645 #endif
1646 			    } SCTX_INIT},
1647     {"isprint",	    "isp",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1648 			    (char_u *)&p_isp, PV_NONE,
1649 			    {
1650 #if defined(MSWIN) || defined(VMS)
1651 			    (char_u *)"@,~-255",
1652 #else
1653 # ifdef EBCDIC
1654 			    /* all chars above 63 are printable */
1655 			    (char_u *)"63-255",
1656 # else
1657 			    ISP_LATIN1,
1658 # endif
1659 #endif
1660 				(char_u *)0L} SCTX_INIT},
1661     {"joinspaces",  "js",   P_BOOL|P_VI_DEF|P_VIM,
1662 			    (char_u *)&p_js, PV_NONE,
1663 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1664     {"key",	    NULL,   P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1665 #ifdef FEAT_CRYPT
1666 			    (char_u *)&p_key, PV_KEY,
1667 			    {(char_u *)"", (char_u *)0L}
1668 #else
1669 			    (char_u *)NULL, PV_NONE,
1670 			    {(char_u *)0L, (char_u *)0L}
1671 #endif
1672 			    SCTX_INIT},
1673     {"keymap",	    "kmp",  P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
1674 #ifdef FEAT_KEYMAP
1675 			    (char_u *)&p_keymap, PV_KMAP,
1676 			    {(char_u *)"", (char_u *)0L}
1677 #else
1678 			    (char_u *)NULL, PV_NONE,
1679 			    {(char_u *)"", (char_u *)0L}
1680 #endif
1681 			    SCTX_INIT},
1682     {"keymodel",    "km",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1683 			    (char_u *)&p_km, PV_NONE,
1684 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1685     {"keywordprg",  "kp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1686 			    (char_u *)&p_kp, PV_KP,
1687 			    {
1688 #ifdef MSWIN
1689 			    (char_u *)":help",
1690 #else
1691 # ifdef VMS
1692 			    (char_u *)"help",
1693 # else
1694 #  ifdef USEMAN_S
1695 			    (char_u *)"man -s",
1696 #  else
1697 			    (char_u *)"man",
1698 #  endif
1699 # endif
1700 #endif
1701 				(char_u *)0L} SCTX_INIT},
1702     {"langmap",     "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
1703 #ifdef FEAT_LANGMAP
1704 			    (char_u *)&p_langmap, PV_NONE,
1705 			    {(char_u *)"", (char_u *)0L}
1706 #else
1707 			    (char_u *)NULL, PV_NONE,
1708 			    {(char_u *)NULL, (char_u *)0L}
1709 #endif
1710 			    SCTX_INIT},
1711     {"langmenu",    "lm",   P_STRING|P_VI_DEF|P_NFNAME,
1712 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1713 			    (char_u *)&p_lm, PV_NONE,
1714 #else
1715 			    (char_u *)NULL, PV_NONE,
1716 #endif
1717 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
1718     {"langnoremap",  "lnr",   P_BOOL|P_VI_DEF,
1719 #ifdef FEAT_LANGMAP
1720 			    (char_u *)&p_lnr, PV_NONE,
1721 #else
1722 			    (char_u *)NULL, PV_NONE,
1723 #endif
1724 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1725     {"langremap",  "lrm",   P_BOOL|P_VI_DEF,
1726 #ifdef FEAT_LANGMAP
1727 			    (char_u *)&p_lrm, PV_NONE,
1728 #else
1729 			    (char_u *)NULL, PV_NONE,
1730 #endif
1731 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1732     {"laststatus",  "ls",   P_NUM|P_VI_DEF|P_RALL,
1733 			    (char_u *)&p_ls, PV_NONE,
1734 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
1735     {"lazyredraw",  "lz",   P_BOOL|P_VI_DEF,
1736 			    (char_u *)&p_lz, PV_NONE,
1737 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1738     {"linebreak",   "lbr",  P_BOOL|P_VI_DEF|P_RWIN,
1739 #ifdef FEAT_LINEBREAK
1740 			    (char_u *)VAR_WIN, PV_LBR,
1741 #else
1742 			    (char_u *)NULL, PV_NONE,
1743 #endif
1744 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1745     {"lines",	    NULL,   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1746 			    (char_u *)&Rows, PV_NONE,
1747 			    {
1748 #if defined(MSWIN)
1749 			    (char_u *)25L,
1750 #else
1751 			    (char_u *)24L,
1752 #endif
1753 					    (char_u *)0L} SCTX_INIT},
1754     {"linespace",   "lsp",  P_NUM|P_VI_DEF|P_RCLR,
1755 #ifdef FEAT_GUI
1756 			    (char_u *)&p_linespace, PV_NONE,
1757 #else
1758 			    (char_u *)NULL, PV_NONE,
1759 #endif
1760 #ifdef FEAT_GUI_MSWIN
1761 			    {(char_u *)1L, (char_u *)0L}
1762 #else
1763 			    {(char_u *)0L, (char_u *)0L}
1764 #endif
1765 			    SCTX_INIT},
1766     {"lisp",	    NULL,   P_BOOL|P_VI_DEF,
1767 #ifdef FEAT_LISP
1768 			    (char_u *)&p_lisp, PV_LISP,
1769 #else
1770 			    (char_u *)NULL, PV_NONE,
1771 #endif
1772 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1773     {"lispwords",   "lw",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1774 #ifdef FEAT_LISP
1775 			    (char_u *)&p_lispwords, PV_LW,
1776 			    {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1777 #else
1778 			    (char_u *)NULL, PV_NONE,
1779 			    {(char_u *)"", (char_u *)0L}
1780 #endif
1781 			    SCTX_INIT},
1782     {"list",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
1783 			    (char_u *)VAR_WIN, PV_LIST,
1784 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1785     {"listchars",   "lcs",  P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
1786 			    (char_u *)&p_lcs, PV_NONE,
1787 			    {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
1788     {"loadplugins", "lpl",  P_BOOL|P_VI_DEF,
1789 			    (char_u *)&p_lpl, PV_NONE,
1790 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1791     {"luadll",      NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1792 #if defined(DYNAMIC_LUA)
1793 			    (char_u *)&p_luadll, PV_NONE,
1794 			    {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1795 #else
1796 			    (char_u *)NULL, PV_NONE,
1797 			    {(char_u *)"", (char_u *)0L}
1798 #endif
1799 			    SCTX_INIT},
1800     {"macatsui",    NULL,   P_BOOL|P_VI_DEF|P_RCLR,
1801 #ifdef FEAT_GUI_MAC
1802 			    (char_u *)&p_macatsui, PV_NONE,
1803 			    {(char_u *)TRUE, (char_u *)0L}
1804 #else
1805 			    (char_u *)NULL, PV_NONE,
1806 			    {(char_u *)"", (char_u *)0L}
1807 #endif
1808 			    SCTX_INIT},
1809     {"magic",	    NULL,   P_BOOL|P_VI_DEF,
1810 			    (char_u *)&p_magic, PV_NONE,
1811 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1812     {"makeef",	    "mef",  P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1813 #ifdef FEAT_QUICKFIX
1814 			    (char_u *)&p_mef, PV_NONE,
1815 			    {(char_u *)"", (char_u *)0L}
1816 #else
1817 			    (char_u *)NULL, PV_NONE,
1818 			    {(char_u *)NULL, (char_u *)0L}
1819 #endif
1820 			    SCTX_INIT},
1821     {"makeencoding","menc", P_STRING|P_VI_DEF,
1822 			    (char_u *)&p_menc, PV_MENC,
1823 			    {(char_u *)"", (char_u *)0L}
1824 			    SCTX_INIT},
1825     {"makeprg",	    "mp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1826 #ifdef FEAT_QUICKFIX
1827 			    (char_u *)&p_mp, PV_MP,
1828 # ifdef VMS
1829 			    {(char_u *)"MMS", (char_u *)0L}
1830 # else
1831 			    {(char_u *)"make", (char_u *)0L}
1832 # endif
1833 #else
1834 			    (char_u *)NULL, PV_NONE,
1835 			    {(char_u *)NULL, (char_u *)0L}
1836 #endif
1837 			    SCTX_INIT},
1838     {"matchpairs",  "mps",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1839 			    (char_u *)&p_mps, PV_MPS,
1840 			    {(char_u *)"(:),{:},[:]", (char_u *)0L}
1841 			    SCTX_INIT},
1842     {"matchtime",   "mat",  P_NUM|P_VI_DEF,
1843 			    (char_u *)&p_mat, PV_NONE,
1844 			    {(char_u *)5L, (char_u *)0L} SCTX_INIT},
1845     {"maxcombine",  "mco",  P_NUM|P_VI_DEF|P_CURSWANT,
1846 			    (char_u *)&p_mco, PV_NONE,
1847 			    {(char_u *)2, (char_u *)0L} SCTX_INIT},
1848     {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1849 #ifdef FEAT_EVAL
1850 			    (char_u *)&p_mfd, PV_NONE,
1851 #else
1852 			    (char_u *)NULL, PV_NONE,
1853 #endif
1854 			    {(char_u *)100L, (char_u *)0L} SCTX_INIT},
1855     {"maxmapdepth", "mmd",  P_NUM|P_VI_DEF,
1856 			    (char_u *)&p_mmd, PV_NONE,
1857 			    {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
1858     {"maxmem",	    "mm",   P_NUM|P_VI_DEF,
1859 			    (char_u *)&p_mm, PV_NONE,
1860 			    {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1861 			    SCTX_INIT},
1862     {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1863 			    (char_u *)&p_mmp, PV_NONE,
1864 			    {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
1865     {"maxmemtot",   "mmt",  P_NUM|P_VI_DEF,
1866 			    (char_u *)&p_mmt, PV_NONE,
1867 			    {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1868 			    SCTX_INIT},
1869     {"menuitems",   "mis",  P_NUM|P_VI_DEF,
1870 #ifdef FEAT_MENU
1871 			    (char_u *)&p_mis, PV_NONE,
1872 #else
1873 			    (char_u *)NULL, PV_NONE,
1874 #endif
1875 			    {(char_u *)25L, (char_u *)0L} SCTX_INIT},
1876     {"mesg",	    NULL,   P_BOOL|P_VI_DEF,
1877 			    (char_u *)NULL, PV_NONE,
1878 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1879     {"mkspellmem",  "msm",  P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
1880 #ifdef FEAT_SPELL
1881 			    (char_u *)&p_msm, PV_NONE,
1882 			    {(char_u *)"460000,2000,500", (char_u *)0L}
1883 #else
1884 			    (char_u *)NULL, PV_NONE,
1885 			    {(char_u *)0L, (char_u *)0L}
1886 #endif
1887 			    SCTX_INIT},
1888     {"modeline",    "ml",   P_BOOL|P_VIM,
1889 			    (char_u *)&p_ml, PV_ML,
1890 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
1891     {"modelines",   "mls",  P_NUM|P_VI_DEF,
1892 			    (char_u *)&p_mls, PV_NONE,
1893 			    {(char_u *)5L, (char_u *)0L} SCTX_INIT},
1894     {"modifiable",  "ma",   P_BOOL|P_VI_DEF|P_NOGLOB,
1895 			    (char_u *)&p_ma, PV_MA,
1896 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1897     {"modified",    "mod",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1898 			    (char_u *)&p_mod, PV_MOD,
1899 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1900     {"more",	    NULL,   P_BOOL|P_VIM,
1901 			    (char_u *)&p_more, PV_NONE,
1902 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
1903     {"mouse",	    NULL,   P_STRING|P_VI_DEF|P_FLAGLIST,
1904 			    (char_u *)&p_mouse, PV_NONE,
1905 			    {
1906 #if defined(MSWIN)
1907 				(char_u *)"a",
1908 #else
1909 				(char_u *)"",
1910 #endif
1911 				(char_u *)0L} SCTX_INIT},
1912     {"mousefocus",   "mousef", P_BOOL|P_VI_DEF,
1913 #ifdef FEAT_GUI
1914 			    (char_u *)&p_mousef, PV_NONE,
1915 #else
1916 			    (char_u *)NULL, PV_NONE,
1917 #endif
1918 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1919     {"mousehide",   "mh",   P_BOOL|P_VI_DEF,
1920 #ifdef FEAT_GUI
1921 			    (char_u *)&p_mh, PV_NONE,
1922 #else
1923 			    (char_u *)NULL, PV_NONE,
1924 #endif
1925 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
1926     {"mousemodel",  "mousem", P_STRING|P_VI_DEF,
1927 			    (char_u *)&p_mousem, PV_NONE,
1928 			    {
1929 #if defined(MSWIN)
1930 				(char_u *)"popup",
1931 #else
1932 # if defined(MACOS_X)
1933 				(char_u *)"popup_setpos",
1934 # else
1935 				(char_u *)"extend",
1936 # endif
1937 #endif
1938 				(char_u *)0L} SCTX_INIT},
1939     {"mouseshape",  "mouses",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1940 #ifdef FEAT_MOUSESHAPE
1941 			    (char_u *)&p_mouseshape, PV_NONE,
1942 			    {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1943 #else
1944 			    (char_u *)NULL, PV_NONE,
1945 			    {(char_u *)NULL, (char_u *)0L}
1946 #endif
1947 			    SCTX_INIT},
1948     {"mousetime",   "mouset",	P_NUM|P_VI_DEF,
1949 			    (char_u *)&p_mouset, PV_NONE,
1950 			    {(char_u *)500L, (char_u *)0L} SCTX_INIT},
1951     {"mzschemedll", NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1952 #if defined(DYNAMIC_MZSCHEME)
1953 			    (char_u *)&p_mzschemedll, PV_NONE,
1954 			    {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1955 #else
1956 			    (char_u *)NULL, PV_NONE,
1957 			    {(char_u *)"", (char_u *)0L}
1958 #endif
1959 			    SCTX_INIT},
1960     {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1961 #if defined(DYNAMIC_MZSCHEME)
1962 			    (char_u *)&p_mzschemegcdll, PV_NONE,
1963 			    {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1964 #else
1965 			    (char_u *)NULL, PV_NONE,
1966 			    {(char_u *)"", (char_u *)0L}
1967 #endif
1968 			    SCTX_INIT},
1969     {"mzquantum",  "mzq",   P_NUM,
1970 #ifdef FEAT_MZSCHEME
1971 			    (char_u *)&p_mzq, PV_NONE,
1972 #else
1973 			    (char_u *)NULL, PV_NONE,
1974 #endif
1975 			    {(char_u *)100L, (char_u *)100L} SCTX_INIT},
1976     {"novice",	    NULL,   P_BOOL|P_VI_DEF,
1977 			    (char_u *)NULL, PV_NONE,
1978 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1979     {"nrformats",   "nf",   P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1980 			    (char_u *)&p_nf, PV_NF,
1981 			    {(char_u *)"bin,octal,hex", (char_u *)0L}
1982 			    SCTX_INIT},
1983     {"number",	    "nu",   P_BOOL|P_VI_DEF|P_RWIN,
1984 			    (char_u *)VAR_WIN, PV_NU,
1985 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
1986     {"numberwidth", "nuw",  P_NUM|P_RWIN|P_VIM,
1987 #ifdef FEAT_LINEBREAK
1988 			    (char_u *)VAR_WIN, PV_NUW,
1989 #else
1990 			    (char_u *)NULL, PV_NONE,
1991 #endif
1992 			    {(char_u *)8L, (char_u *)4L} SCTX_INIT},
1993     {"omnifunc",    "ofu",  P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
1994 #ifdef FEAT_COMPL_FUNC
1995 			    (char_u *)&p_ofu, PV_OFU,
1996 			    {(char_u *)"", (char_u *)0L}
1997 #else
1998 			    (char_u *)NULL, PV_NONE,
1999 			    {(char_u *)0L, (char_u *)0L}
2000 #endif
2001 			    SCTX_INIT},
2002     {"open",	    NULL,   P_BOOL|P_VI_DEF,
2003 			    (char_u *)NULL, PV_NONE,
2004 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2005     {"opendevice",  "odev", P_BOOL|P_VI_DEF,
2006 #if defined(MSWIN)
2007 			    (char_u *)&p_odev, PV_NONE,
2008 #else
2009 			    (char_u *)NULL, PV_NONE,
2010 #endif
2011 			    {(char_u *)FALSE, (char_u *)FALSE}
2012 			    SCTX_INIT},
2013     {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2014 			    (char_u *)&p_opfunc, PV_NONE,
2015 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2016     {"optimize",    "opt",  P_BOOL|P_VI_DEF,
2017 			    (char_u *)NULL, PV_NONE,
2018 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2019     {"osfiletype",  "oft",  P_STRING|P_ALLOCED|P_VI_DEF,
2020 			    (char_u *)NULL, PV_NONE,
2021 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2022     {"packpath",    "pp",   P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2023 								    |P_SECURE,
2024 			    (char_u *)&p_pp, PV_NONE,
2025 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2026 			    SCTX_INIT},
2027     {"paragraphs",  "para", P_STRING|P_VI_DEF,
2028 			    (char_u *)&p_para, PV_NONE,
2029 			    {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
2030 				(char_u *)0L} SCTX_INIT},
2031     {"paste",	    NULL,   P_BOOL|P_VI_DEF|P_PRI_MKRC,
2032 			    (char_u *)&p_paste, PV_NONE,
2033 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2034     {"pastetoggle", "pt",   P_STRING|P_VI_DEF,
2035 			    (char_u *)&p_pt, PV_NONE,
2036 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2037     {"patchexpr",   "pex",  P_STRING|P_VI_DEF|P_SECURE,
2038 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2039 			    (char_u *)&p_pex, PV_NONE,
2040 			    {(char_u *)"", (char_u *)0L}
2041 #else
2042 			    (char_u *)NULL, PV_NONE,
2043 			    {(char_u *)0L, (char_u *)0L}
2044 #endif
2045 			    SCTX_INIT},
2046     {"patchmode",   "pm",   P_STRING|P_VI_DEF|P_NFNAME,
2047 			    (char_u *)&p_pm, PV_NONE,
2048 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2049     {"path",	    "pa",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2050 			    (char_u *)&p_path, PV_PATH,
2051 			    {
2052 #if defined(AMIGA) || defined(MSWIN)
2053 			    (char_u *)".,,",
2054 #else
2055 			    (char_u *)".,/usr/include,,",
2056 #endif
2057 				(char_u *)0L} SCTX_INIT},
2058     {"perldll",     NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2059 #if defined(DYNAMIC_PERL)
2060 			    (char_u *)&p_perldll, PV_NONE,
2061 			    {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2062 #else
2063 			    (char_u *)NULL, PV_NONE,
2064 			    {(char_u *)0L, (char_u *)0L}
2065 #endif
2066 			    SCTX_INIT},
2067     {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2068 			    (char_u *)&p_pi, PV_PI,
2069 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2070     {"previewheight", "pvh", P_NUM|P_VI_DEF,
2071 #if defined(FEAT_QUICKFIX)
2072 			    (char_u *)&p_pvh, PV_NONE,
2073 #else
2074 			    (char_u *)NULL, PV_NONE,
2075 #endif
2076 			    {(char_u *)12L, (char_u *)0L} SCTX_INIT},
2077     {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2078 #if defined(FEAT_QUICKFIX)
2079 			    (char_u *)VAR_WIN, PV_PVW,
2080 #else
2081 			    (char_u *)NULL, PV_NONE,
2082 #endif
2083 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2084     {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
2085 #ifdef FEAT_PRINTER
2086 			    (char_u *)&p_pdev, PV_NONE,
2087 			    {(char_u *)"", (char_u *)0L}
2088 #else
2089 			    (char_u *)NULL, PV_NONE,
2090 			    {(char_u *)NULL, (char_u *)0L}
2091 #endif
2092 			    SCTX_INIT},
2093     {"printencoding", "penc", P_STRING|P_VI_DEF,
2094 #ifdef FEAT_POSTSCRIPT
2095 			    (char_u *)&p_penc, PV_NONE,
2096 			    {(char_u *)"", (char_u *)0L}
2097 #else
2098 			    (char_u *)NULL, PV_NONE,
2099 			    {(char_u *)NULL, (char_u *)0L}
2100 #endif
2101 			    SCTX_INIT},
2102     {"printexpr", "pexpr",  P_STRING|P_VI_DEF|P_SECURE,
2103 #ifdef FEAT_POSTSCRIPT
2104 			    (char_u *)&p_pexpr, PV_NONE,
2105 			    {(char_u *)"", (char_u *)0L}
2106 #else
2107 			    (char_u *)NULL, PV_NONE,
2108 			    {(char_u *)NULL, (char_u *)0L}
2109 #endif
2110 			    SCTX_INIT},
2111     {"printfont", "pfn",    P_STRING|P_VI_DEF,
2112 #ifdef FEAT_PRINTER
2113 			    (char_u *)&p_pfn, PV_NONE,
2114 			    {
2115 # ifdef MSWIN
2116 				(char_u *)"Courier_New:h10",
2117 # else
2118 				(char_u *)"courier",
2119 # endif
2120 				(char_u *)0L}
2121 #else
2122 			    (char_u *)NULL, PV_NONE,
2123 			    {(char_u *)NULL, (char_u *)0L}
2124 #endif
2125 			    SCTX_INIT},
2126     {"printheader", "pheader",  P_STRING|P_VI_DEF|P_GETTEXT,
2127 #ifdef FEAT_PRINTER
2128 			    (char_u *)&p_header, PV_NONE,
2129 			    /* untranslated to avoid problems when 'encoding'
2130 			     * is changed */
2131 			    {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
2132 #else
2133 			    (char_u *)NULL, PV_NONE,
2134 			    {(char_u *)NULL, (char_u *)0L}
2135 #endif
2136 			    SCTX_INIT},
2137    {"printmbcharset", "pmbcs",  P_STRING|P_VI_DEF,
2138 #if defined(FEAT_POSTSCRIPT)
2139 			    (char_u *)&p_pmcs, PV_NONE,
2140 			    {(char_u *)"", (char_u *)0L}
2141 #else
2142 			    (char_u *)NULL, PV_NONE,
2143 			    {(char_u *)NULL, (char_u *)0L}
2144 #endif
2145 			    SCTX_INIT},
2146     {"printmbfont", "pmbfn",  P_STRING|P_VI_DEF,
2147 #if defined(FEAT_POSTSCRIPT)
2148 			    (char_u *)&p_pmfn, PV_NONE,
2149 			    {(char_u *)"", (char_u *)0L}
2150 #else
2151 			    (char_u *)NULL, PV_NONE,
2152 			    {(char_u *)NULL, (char_u *)0L}
2153 #endif
2154 			    SCTX_INIT},
2155     {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2156 #ifdef FEAT_PRINTER
2157 			    (char_u *)&p_popt, PV_NONE,
2158 			    {(char_u *)"", (char_u *)0L}
2159 #else
2160 			    (char_u *)NULL, PV_NONE,
2161 			    {(char_u *)NULL, (char_u *)0L}
2162 #endif
2163 			    SCTX_INIT},
2164     {"prompt",	    NULL,   P_BOOL|P_VI_DEF,
2165 			    (char_u *)&p_prompt, PV_NONE,
2166 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2167     {"pumheight",   "ph",   P_NUM|P_VI_DEF,
2168 #ifdef FEAT_INS_EXPAND
2169 			    (char_u *)&p_ph, PV_NONE,
2170 #else
2171 			    (char_u *)NULL, PV_NONE,
2172 #endif
2173 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2174     {"pumwidth",    "pw",   P_NUM|P_VI_DEF,
2175 #ifdef FEAT_INS_EXPAND
2176 			    (char_u *)&p_pw, PV_NONE,
2177 #else
2178 			    (char_u *)NULL, PV_NONE,
2179 #endif
2180 			    {(char_u *)15L, (char_u *)15L} SCTX_INIT},
2181     {"pythonthreedll",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2182 #if defined(DYNAMIC_PYTHON3)
2183 			    (char_u *)&p_py3dll, PV_NONE,
2184 			    {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2185 #else
2186 			    (char_u *)NULL, PV_NONE,
2187 			    {(char_u *)NULL, (char_u *)0L}
2188 #endif
2189 			    SCTX_INIT},
2190     {"pythonthreehome", NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2191 #if defined(FEAT_PYTHON3)
2192 			    (char_u *)&p_py3home, PV_NONE,
2193 			    {(char_u *)"", (char_u *)0L}
2194 #else
2195 			    (char_u *)NULL, PV_NONE,
2196 			    {(char_u *)NULL, (char_u *)0L}
2197 #endif
2198 			    SCTX_INIT},
2199     {"pythondll",   NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2200 #if defined(DYNAMIC_PYTHON)
2201 			    (char_u *)&p_pydll, PV_NONE,
2202 			    {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2203 #else
2204 			    (char_u *)NULL, PV_NONE,
2205 			    {(char_u *)NULL, (char_u *)0L}
2206 #endif
2207 			    SCTX_INIT},
2208     {"pythonhome",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2209 #if defined(FEAT_PYTHON)
2210 			    (char_u *)&p_pyhome, PV_NONE,
2211 			    {(char_u *)"", (char_u *)0L}
2212 #else
2213 			    (char_u *)NULL, PV_NONE,
2214 			    {(char_u *)NULL, (char_u *)0L}
2215 #endif
2216 			    SCTX_INIT},
2217     {"pyxversion", "pyx",   P_NUM|P_VI_DEF|P_SECURE,
2218 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2219 			    (char_u *)&p_pyx, PV_NONE,
2220 #else
2221 			    (char_u *)NULL, PV_NONE,
2222 #endif
2223 			    {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2224 			    SCTX_INIT},
2225     {"quoteescape", "qe",   P_STRING|P_ALLOCED|P_VI_DEF,
2226 #ifdef FEAT_TEXTOBJ
2227 			    (char_u *)&p_qe, PV_QE,
2228 			    {(char_u *)"\\", (char_u *)0L}
2229 #else
2230 			    (char_u *)NULL, PV_NONE,
2231 			    {(char_u *)NULL, (char_u *)0L}
2232 #endif
2233 			    SCTX_INIT},
2234     {"readonly",    "ro",   P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2235 			    (char_u *)&p_ro, PV_RO,
2236 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2237     {"redraw",	    NULL,   P_BOOL|P_VI_DEF,
2238 			    (char_u *)NULL, PV_NONE,
2239 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2240     {"redrawtime",  "rdt",  P_NUM|P_VI_DEF,
2241 #ifdef FEAT_RELTIME
2242 			    (char_u *)&p_rdt, PV_NONE,
2243 #else
2244 			    (char_u *)NULL, PV_NONE,
2245 #endif
2246 			    {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
2247     {"regexpengine", "re",  P_NUM|P_VI_DEF,
2248 			    (char_u *)&p_re, PV_NONE,
2249 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2250     {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2251 			    (char_u *)VAR_WIN, PV_RNU,
2252 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2253     {"remap",	    NULL,   P_BOOL|P_VI_DEF,
2254 			    (char_u *)&p_remap, PV_NONE,
2255 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2256     {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
2257 #ifdef FEAT_RENDER_OPTIONS
2258 			    (char_u *)&p_rop, PV_NONE,
2259 			    {(char_u *)"", (char_u *)0L}
2260 #else
2261 			    (char_u *)NULL, PV_NONE,
2262 			    {(char_u *)NULL, (char_u *)0L}
2263 #endif
2264 			    SCTX_INIT},
2265     {"report",	    NULL,   P_NUM|P_VI_DEF,
2266 			    (char_u *)&p_report, PV_NONE,
2267 			    {(char_u *)2L, (char_u *)0L} SCTX_INIT},
2268     {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2269 #ifdef MSWIN
2270 			    (char_u *)&p_rs, PV_NONE,
2271 #else
2272 			    (char_u *)NULL, PV_NONE,
2273 #endif
2274 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2275     {"revins",	    "ri",   P_BOOL|P_VI_DEF|P_VIM,
2276 #ifdef FEAT_RIGHTLEFT
2277 			    (char_u *)&p_ri, PV_NONE,
2278 #else
2279 			    (char_u *)NULL, PV_NONE,
2280 #endif
2281 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2282     {"rightleft",   "rl",   P_BOOL|P_VI_DEF|P_RWIN,
2283 #ifdef FEAT_RIGHTLEFT
2284 			    (char_u *)VAR_WIN, PV_RL,
2285 #else
2286 			    (char_u *)NULL, PV_NONE,
2287 #endif
2288 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2289     {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2290 #ifdef FEAT_RIGHTLEFT
2291 			    (char_u *)VAR_WIN, PV_RLC,
2292 			    {(char_u *)"search", (char_u *)NULL}
2293 #else
2294 			    (char_u *)NULL, PV_NONE,
2295 			    {(char_u *)NULL, (char_u *)0L}
2296 #endif
2297 			    SCTX_INIT},
2298     {"rubydll",     NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2299 #if defined(DYNAMIC_RUBY)
2300 			    (char_u *)&p_rubydll, PV_NONE,
2301 			    {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2302 #else
2303 			    (char_u *)NULL, PV_NONE,
2304 			    {(char_u *)NULL, (char_u *)0L}
2305 #endif
2306 			    SCTX_INIT},
2307     {"ruler",	    "ru",   P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2308 #ifdef FEAT_CMDL_INFO
2309 			    (char_u *)&p_ru, PV_NONE,
2310 #else
2311 			    (char_u *)NULL, PV_NONE,
2312 #endif
2313 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2314     {"rulerformat", "ruf",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2315 #ifdef FEAT_STL_OPT
2316 			    (char_u *)&p_ruf, PV_NONE,
2317 #else
2318 			    (char_u *)NULL, PV_NONE,
2319 #endif
2320 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2321     {"runtimepath", "rtp",  P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2322 								    |P_SECURE,
2323 			    (char_u *)&p_rtp, PV_NONE,
2324 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2325 			    SCTX_INIT},
2326     {"scroll",	    "scr",  P_NUM|P_NO_MKRC|P_VI_DEF,
2327 			    (char_u *)VAR_WIN, PV_SCROLL,
2328 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2329     {"scrollbind",  "scb",  P_BOOL|P_VI_DEF,
2330 			    (char_u *)VAR_WIN, PV_SCBIND,
2331 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2332     {"scrolljump",  "sj",   P_NUM|P_VI_DEF|P_VIM,
2333 			    (char_u *)&p_sj, PV_NONE,
2334 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
2335     {"scrolloff",   "so",   P_NUM|P_VI_DEF|P_VIM|P_RALL,
2336 			    (char_u *)&p_so, PV_SO,
2337 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2338     {"scrollopt",   "sbo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2339 			    (char_u *)&p_sbo, PV_NONE,
2340 			    {(char_u *)"ver,jump", (char_u *)0L}
2341 			    SCTX_INIT},
2342     {"sections",    "sect", P_STRING|P_VI_DEF,
2343 			    (char_u *)&p_sections, PV_NONE,
2344 			    {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2345 			    SCTX_INIT},
2346     {"secure",	    NULL,   P_BOOL|P_VI_DEF|P_SECURE,
2347 			    (char_u *)&p_secure, PV_NONE,
2348 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2349     {"selection",   "sel",  P_STRING|P_VI_DEF,
2350 			    (char_u *)&p_sel, PV_NONE,
2351 			    {(char_u *)"inclusive", (char_u *)0L}
2352 			    SCTX_INIT},
2353     {"selectmode",  "slm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2354 			    (char_u *)&p_slm, PV_NONE,
2355 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2356     {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2357 #ifdef FEAT_SESSION
2358 			    (char_u *)&p_ssop, PV_NONE,
2359 	 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
2360 							       (char_u *)0L}
2361 #else
2362 			    (char_u *)NULL, PV_NONE,
2363 			    {(char_u *)0L, (char_u *)0L}
2364 #endif
2365 			    SCTX_INIT},
2366     {"shell",	    "sh",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2367 			    (char_u *)&p_sh, PV_NONE,
2368 			    {
2369 #ifdef VMS
2370 			    (char_u *)"-",
2371 #else
2372 # if defined(MSWIN)
2373 			    (char_u *)"",	/* set in set_init_1() */
2374 # else
2375 			    (char_u *)"sh",
2376 # endif
2377 #endif /* VMS */
2378 				(char_u *)0L} SCTX_INIT},
2379     {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2380 			    (char_u *)&p_shcf, PV_NONE,
2381 			    {
2382 #if defined(MSWIN)
2383 			    (char_u *)"/c",
2384 #else
2385 			    (char_u *)"-c",
2386 #endif
2387 				(char_u *)0L} SCTX_INIT},
2388     {"shellpipe",   "sp",   P_STRING|P_VI_DEF|P_SECURE,
2389 #ifdef FEAT_QUICKFIX
2390 			    (char_u *)&p_sp, PV_NONE,
2391 			    {
2392 #if defined(UNIX)
2393 			    (char_u *)"| tee",
2394 #else
2395 			    (char_u *)">",
2396 #endif
2397 				(char_u *)0L}
2398 #else
2399 			    (char_u *)NULL, PV_NONE,
2400 			    {(char_u *)0L, (char_u *)0L}
2401 #endif
2402 			    SCTX_INIT},
2403     {"shellquote",  "shq",  P_STRING|P_VI_DEF|P_SECURE,
2404 			    (char_u *)&p_shq, PV_NONE,
2405 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2406     {"shellredir",  "srr",  P_STRING|P_VI_DEF|P_SECURE,
2407 			    (char_u *)&p_srr, PV_NONE,
2408 			    {(char_u *)">", (char_u *)0L} SCTX_INIT},
2409     {"shellslash",  "ssl",   P_BOOL|P_VI_DEF,
2410 #ifdef BACKSLASH_IN_FILENAME
2411 			    (char_u *)&p_ssl, PV_NONE,
2412 #else
2413 			    (char_u *)NULL, PV_NONE,
2414 #endif
2415 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2416     {"shelltemp",   "stmp", P_BOOL,
2417 			    (char_u *)&p_stmp, PV_NONE,
2418 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
2419     {"shelltype",   "st",   P_NUM|P_VI_DEF,
2420 #ifdef AMIGA
2421 			    (char_u *)&p_st, PV_NONE,
2422 #else
2423 			    (char_u *)NULL, PV_NONE,
2424 #endif
2425 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2426     {"shellxquote", "sxq",  P_STRING|P_VI_DEF|P_SECURE,
2427 			    (char_u *)&p_sxq, PV_NONE,
2428 			    {
2429 #if defined(UNIX) && defined(USE_SYSTEM)
2430 			    (char_u *)"\"",
2431 #else
2432 			    (char_u *)"",
2433 #endif
2434 				(char_u *)0L} SCTX_INIT},
2435     {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2436 			    (char_u *)&p_sxe, PV_NONE,
2437 			    {
2438 #if defined(MSWIN)
2439 			    (char_u *)"\"&|<>()@^",
2440 #else
2441 			    (char_u *)"",
2442 #endif
2443 				(char_u *)0L} SCTX_INIT},
2444     {"shiftround",  "sr",   P_BOOL|P_VI_DEF|P_VIM,
2445 			    (char_u *)&p_sr, PV_NONE,
2446 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2447     {"shiftwidth",  "sw",   P_NUM|P_VI_DEF,
2448 			    (char_u *)&p_sw, PV_SW,
2449 			    {(char_u *)8L, (char_u *)0L} SCTX_INIT},
2450     {"shortmess",   "shm",  P_STRING|P_VIM|P_FLAGLIST,
2451 			    (char_u *)&p_shm, PV_NONE,
2452 			    {(char_u *)"S", (char_u *)"filnxtToOS"}
2453 			    SCTX_INIT},
2454     {"shortname",   "sn",   P_BOOL|P_VI_DEF,
2455 			    (char_u *)&p_sn, PV_SN,
2456 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2457     {"showbreak",   "sbr",  P_STRING|P_VI_DEF|P_RALL,
2458 #ifdef FEAT_LINEBREAK
2459 			    (char_u *)&p_sbr, PV_NONE,
2460 #else
2461 			    (char_u *)NULL, PV_NONE,
2462 #endif
2463 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2464     {"showcmd",	    "sc",   P_BOOL|P_VIM,
2465 #ifdef FEAT_CMDL_INFO
2466 			    (char_u *)&p_sc, PV_NONE,
2467 #else
2468 			    (char_u *)NULL, PV_NONE,
2469 #endif
2470 			    {(char_u *)FALSE,
2471 #ifdef UNIX
2472 				(char_u *)FALSE
2473 #else
2474 				(char_u *)TRUE
2475 #endif
2476 				} SCTX_INIT},
2477     {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
2478 			    (char_u *)&p_sft, PV_NONE,
2479 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2480     {"showmatch",   "sm",   P_BOOL|P_VI_DEF,
2481 			    (char_u *)&p_sm, PV_NONE,
2482 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2483     {"showmode",    "smd",  P_BOOL|P_VIM,
2484 			    (char_u *)&p_smd, PV_NONE,
2485 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
2486     {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2487 			    (char_u *)&p_stal, PV_NONE,
2488 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
2489     {"sidescroll",  "ss",   P_NUM|P_VI_DEF,
2490 			    (char_u *)&p_ss, PV_NONE,
2491 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2492     {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2493 			    (char_u *)&p_siso, PV_SISO,
2494 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2495     {"signcolumn",   "scl",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2496 #ifdef FEAT_SIGNS
2497 			    (char_u *)VAR_WIN, PV_SCL,
2498 			    {(char_u *)"auto", (char_u *)0L}
2499 #else
2500 			    (char_u *)NULL, PV_NONE,
2501 			    {(char_u *)NULL, (char_u *)0L}
2502 #endif
2503 			    SCTX_INIT},
2504     {"slowopen",    "slow", P_BOOL|P_VI_DEF,
2505 			    (char_u *)NULL, PV_NONE,
2506 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2507     {"smartcase",   "scs",  P_BOOL|P_VI_DEF|P_VIM,
2508 			    (char_u *)&p_scs, PV_NONE,
2509 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2510     {"smartindent", "si",   P_BOOL|P_VI_DEF|P_VIM,
2511 #ifdef FEAT_SMARTINDENT
2512 			    (char_u *)&p_si, PV_SI,
2513 #else
2514 			    (char_u *)NULL, PV_NONE,
2515 #endif
2516 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2517     {"smarttab",    "sta",  P_BOOL|P_VI_DEF|P_VIM,
2518 			    (char_u *)&p_sta, PV_NONE,
2519 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2520     {"softtabstop", "sts",  P_NUM|P_VI_DEF|P_VIM,
2521 			    (char_u *)&p_sts, PV_STS,
2522 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2523     {"sourceany",   NULL,   P_BOOL|P_VI_DEF,
2524 			    (char_u *)NULL, PV_NONE,
2525 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2526     {"spell",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
2527 #ifdef FEAT_SPELL
2528 			    (char_u *)VAR_WIN, PV_SPELL,
2529 #else
2530 			    (char_u *)NULL, PV_NONE,
2531 #endif
2532 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2533     {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
2534 #ifdef FEAT_SPELL
2535 			    (char_u *)&p_spc, PV_SPC,
2536 			    {(char_u *)"[.?!]\\_[\\])'\"	 ]\\+", (char_u *)0L}
2537 #else
2538 			    (char_u *)NULL, PV_NONE,
2539 			    {(char_u *)0L, (char_u *)0L}
2540 #endif
2541 			    SCTX_INIT},
2542     {"spellfile",   "spf",  P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2543 								  |P_ONECOMMA,
2544 #ifdef FEAT_SPELL
2545 			    (char_u *)&p_spf, PV_SPF,
2546 			    {(char_u *)"", (char_u *)0L}
2547 #else
2548 			    (char_u *)NULL, PV_NONE,
2549 			    {(char_u *)0L, (char_u *)0L}
2550 #endif
2551 			    SCTX_INIT},
2552     {"spelllang",   "spl",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2553 							     |P_RBUF|P_EXPAND,
2554 #ifdef FEAT_SPELL
2555 			    (char_u *)&p_spl, PV_SPL,
2556 			    {(char_u *)"en", (char_u *)0L}
2557 #else
2558 			    (char_u *)NULL, PV_NONE,
2559 			    {(char_u *)0L, (char_u *)0L}
2560 #endif
2561 			    SCTX_INIT},
2562     {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
2563 #ifdef FEAT_SPELL
2564 			    (char_u *)&p_sps, PV_NONE,
2565 			    {(char_u *)"best", (char_u *)0L}
2566 #else
2567 			    (char_u *)NULL, PV_NONE,
2568 			    {(char_u *)0L, (char_u *)0L}
2569 #endif
2570 			    SCTX_INIT},
2571     {"splitbelow",  "sb",   P_BOOL|P_VI_DEF,
2572 			    (char_u *)&p_sb, PV_NONE,
2573 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2574     {"splitright",  "spr",  P_BOOL|P_VI_DEF,
2575 			    (char_u *)&p_spr, PV_NONE,
2576 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2577     {"startofline", "sol",  P_BOOL|P_VI_DEF|P_VIM,
2578 			    (char_u *)&p_sol, PV_NONE,
2579 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2580     {"statusline"  ,"stl",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2581 #ifdef FEAT_STL_OPT
2582 			    (char_u *)&p_stl, PV_STL,
2583 #else
2584 			    (char_u *)NULL, PV_NONE,
2585 #endif
2586 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2587     {"suffixes",    "su",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2588 			    (char_u *)&p_su, PV_NONE,
2589 			    {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2590 				(char_u *)0L} SCTX_INIT},
2591     {"suffixesadd", "sua",  P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
2592 #ifdef FEAT_SEARCHPATH
2593 			    (char_u *)&p_sua, PV_SUA,
2594 			    {(char_u *)"", (char_u *)0L}
2595 #else
2596 			    (char_u *)NULL, PV_NONE,
2597 			    {(char_u *)0L, (char_u *)0L}
2598 #endif
2599 			    SCTX_INIT},
2600     {"swapfile",    "swf",  P_BOOL|P_VI_DEF|P_RSTAT,
2601 			    (char_u *)&p_swf, PV_SWF,
2602 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2603     {"swapsync",    "sws",  P_STRING|P_VI_DEF,
2604 			    (char_u *)&p_sws, PV_NONE,
2605 			    {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
2606     {"switchbuf",   "swb",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2607 			    (char_u *)&p_swb, PV_NONE,
2608 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2609     {"synmaxcol",   "smc",  P_NUM|P_VI_DEF|P_RBUF,
2610 #ifdef FEAT_SYN_HL
2611 			    (char_u *)&p_smc, PV_SMC,
2612 			    {(char_u *)3000L, (char_u *)0L}
2613 #else
2614 			    (char_u *)NULL, PV_NONE,
2615 			    {(char_u *)0L, (char_u *)0L}
2616 #endif
2617 			    SCTX_INIT},
2618     {"syntax",	    "syn",  P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
2619 #ifdef FEAT_SYN_HL
2620 			    (char_u *)&p_syn, PV_SYN,
2621 			    {(char_u *)"", (char_u *)0L}
2622 #else
2623 			    (char_u *)NULL, PV_NONE,
2624 			    {(char_u *)0L, (char_u *)0L}
2625 #endif
2626 			    SCTX_INIT},
2627     {"tabline",	    "tal",  P_STRING|P_VI_DEF|P_RALL,
2628 #ifdef FEAT_STL_OPT
2629 			    (char_u *)&p_tal, PV_NONE,
2630 #else
2631 			    (char_u *)NULL, PV_NONE,
2632 #endif
2633 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2634     {"tabpagemax",  "tpm",  P_NUM|P_VI_DEF,
2635 			    (char_u *)&p_tpm, PV_NONE,
2636 			    {(char_u *)10L, (char_u *)0L} SCTX_INIT},
2637     {"tabstop",	    "ts",   P_NUM|P_VI_DEF|P_RBUF,
2638 			    (char_u *)&p_ts, PV_TS,
2639 			    {(char_u *)8L, (char_u *)0L} SCTX_INIT},
2640     {"tagbsearch",  "tbs",   P_BOOL|P_VI_DEF,
2641 			    (char_u *)&p_tbs, PV_NONE,
2642 #ifdef VMS	/* binary searching doesn't appear to work on VMS */
2643 			    {(char_u *)0L, (char_u *)0L}
2644 #else
2645 			    {(char_u *)TRUE, (char_u *)0L}
2646 #endif
2647 			    SCTX_INIT},
2648     {"tagcase",	    "tc",   P_STRING|P_VIM,
2649 			    (char_u *)&p_tc, PV_TC,
2650 			    {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
2651     {"tagfunc",    "tfu",   P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2652 #ifdef FEAT_EVAL
2653 			    (char_u *)&p_tfu, PV_TFU,
2654 			    {(char_u *)"", (char_u *)0L}
2655 #else
2656 			    (char_u *)NULL, PV_NONE,
2657 			    {(char_u *)0L, (char_u *)0L}
2658 #endif
2659 			    SCTX_INIT},
2660     {"taglength",   "tl",   P_NUM|P_VI_DEF,
2661 			    (char_u *)&p_tl, PV_NONE,
2662 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2663     {"tagrelative", "tr",   P_BOOL|P_VIM,
2664 			    (char_u *)&p_tr, PV_NONE,
2665 			    {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
2666     {"tags",	    "tag",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
2667 			    (char_u *)&p_tags, PV_TAGS,
2668 			    {
2669 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2670 			    (char_u *)"./tags,./TAGS,tags,TAGS",
2671 #else
2672 			    (char_u *)"./tags,tags",
2673 #endif
2674 				(char_u *)0L} SCTX_INIT},
2675     {"tagstack",    "tgst", P_BOOL|P_VI_DEF,
2676 			    (char_u *)&p_tgst, PV_NONE,
2677 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2678     {"tcldll",      NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2679 #if defined(DYNAMIC_TCL)
2680 			    (char_u *)&p_tcldll, PV_NONE,
2681 			    {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2682 #else
2683 			    (char_u *)NULL, PV_NONE,
2684 			    {(char_u *)0L, (char_u *)0L}
2685 #endif
2686 			    SCTX_INIT},
2687     {"term",	    NULL,   P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2688 			    (char_u *)&T_NAME, PV_NONE,
2689 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2690     {"termbidi", "tbidi",   P_BOOL|P_VI_DEF,
2691 #ifdef FEAT_ARABIC
2692 			    (char_u *)&p_tbidi, PV_NONE,
2693 #else
2694 			    (char_u *)NULL, PV_NONE,
2695 #endif
2696 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2697     {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2698 			    (char_u *)&p_tenc, PV_NONE,
2699 			    {(char_u *)"", (char_u *)0L}
2700 			    SCTX_INIT},
2701     {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2702 #ifdef FEAT_TERMGUICOLORS
2703 			    (char_u *)&p_tgc, PV_NONE,
2704 			    {(char_u *)FALSE, (char_u *)FALSE}
2705 #else
2706 			    (char_u*)NULL, PV_NONE,
2707 			    {(char_u *)FALSE, (char_u *)FALSE}
2708 #endif
2709 			    SCTX_INIT},
2710     {"termwinkey", "twk",   P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2711 #ifdef FEAT_TERMINAL
2712 			    (char_u *)VAR_WIN, PV_TWK,
2713 			    {(char_u *)"", (char_u *)NULL}
2714 #else
2715 			    (char_u *)NULL, PV_NONE,
2716 			    {(char_u *)NULL, (char_u *)0L}
2717 #endif
2718 			    SCTX_INIT},
2719     {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2720 #ifdef FEAT_TERMINAL
2721 			    (char_u *)&p_twsl, PV_TWSL,
2722 			    {(char_u *)10000L, (char_u *)10000L}
2723 #else
2724 			    (char_u *)NULL, PV_NONE,
2725 			    {(char_u *)NULL, (char_u *)0L}
2726 #endif
2727 			    SCTX_INIT},
2728     {"termwinsize", "tws",  P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2729 #ifdef FEAT_TERMINAL
2730 			    (char_u *)VAR_WIN, PV_TWS,
2731 			    {(char_u *)"", (char_u *)NULL}
2732 #else
2733 			    (char_u *)NULL, PV_NONE,
2734 			    {(char_u *)NULL, (char_u *)0L}
2735 #endif
2736 			    SCTX_INIT},
2737     {"termwintype", "twt",  P_STRING|P_ALLOCED|P_VI_DEF,
2738 #if defined(MSWIN) && defined(FEAT_TERMINAL)
2739 			    (char_u *)&p_twt, PV_NONE,
2740 			    {(char_u *)"", (char_u *)NULL}
2741 #else
2742 			    (char_u *)NULL, PV_NONE,
2743 			    {(char_u *)NULL, (char_u *)0L}
2744 #endif
2745 			    SCTX_INIT},
2746     {"terse",	    NULL,   P_BOOL|P_VI_DEF,
2747 			    (char_u *)&p_terse, PV_NONE,
2748 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2749     {"textauto",    "ta",   P_BOOL|P_VIM,
2750 			    (char_u *)&p_ta, PV_NONE,
2751 			    {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2752 			    SCTX_INIT},
2753     {"textmode",    "tx",   P_BOOL|P_VI_DEF|P_NO_MKRC,
2754 			    (char_u *)&p_tx, PV_TX,
2755 			    {
2756 #ifdef USE_CRNL
2757 			    (char_u *)TRUE,
2758 #else
2759 			    (char_u *)FALSE,
2760 #endif
2761 				(char_u *)0L} SCTX_INIT},
2762     {"textwidth",   "tw",   P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2763 			    (char_u *)&p_tw, PV_TW,
2764 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2765     {"thesaurus",   "tsr",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
2766 #ifdef FEAT_INS_EXPAND
2767 			    (char_u *)&p_tsr, PV_TSR,
2768 #else
2769 			    (char_u *)NULL, PV_NONE,
2770 #endif
2771 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2772     {"tildeop",	    "top",  P_BOOL|P_VI_DEF|P_VIM,
2773 			    (char_u *)&p_to, PV_NONE,
2774 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2775     {"timeout",	    "to",   P_BOOL|P_VI_DEF,
2776 			    (char_u *)&p_timeout, PV_NONE,
2777 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2778     {"timeoutlen",  "tm",   P_NUM|P_VI_DEF,
2779 			    (char_u *)&p_tm, PV_NONE,
2780 			    {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
2781     {"title",	    NULL,   P_BOOL|P_VI_DEF,
2782 #ifdef FEAT_TITLE
2783 			    (char_u *)&p_title, PV_NONE,
2784 #else
2785 			    (char_u *)NULL, PV_NONE,
2786 #endif
2787 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2788     {"titlelen",    NULL,   P_NUM|P_VI_DEF,
2789 #ifdef FEAT_TITLE
2790 			    (char_u *)&p_titlelen, PV_NONE,
2791 #else
2792 			    (char_u *)NULL, PV_NONE,
2793 #endif
2794 			    {(char_u *)85L, (char_u *)0L} SCTX_INIT},
2795     {"titleold",    NULL,   P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
2796 #ifdef FEAT_TITLE
2797 			    (char_u *)&p_titleold, PV_NONE,
2798 			    {(char_u *)N_("Thanks for flying Vim"),
2799 							       (char_u *)0L}
2800 #else
2801 			    (char_u *)NULL, PV_NONE,
2802 			    {(char_u *)0L, (char_u *)0L}
2803 #endif
2804 			    SCTX_INIT},
2805     {"titlestring", NULL,   P_STRING|P_VI_DEF,
2806 #ifdef FEAT_TITLE
2807 			    (char_u *)&p_titlestring, PV_NONE,
2808 #else
2809 			    (char_u *)NULL, PV_NONE,
2810 #endif
2811 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2812     {"toolbar",     "tb",   P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
2813 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
2814 			    (char_u *)&p_toolbar, PV_NONE,
2815 			    {(char_u *)"icons,tooltips", (char_u *)0L}
2816 #else
2817 			    (char_u *)NULL, PV_NONE,
2818 			    {(char_u *)0L, (char_u *)0L}
2819 #endif
2820 			    SCTX_INIT},
2821     {"toolbariconsize",	"tbis", P_STRING|P_VI_DEF,
2822 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
2823 			    (char_u *)&p_tbis, PV_NONE,
2824 			    {(char_u *)"small", (char_u *)0L}
2825 #else
2826 			    (char_u *)NULL, PV_NONE,
2827 			    {(char_u *)0L, (char_u *)0L}
2828 #endif
2829 			    SCTX_INIT},
2830     {"ttimeout",    NULL,   P_BOOL|P_VI_DEF|P_VIM,
2831 			    (char_u *)&p_ttimeout, PV_NONE,
2832 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2833     {"ttimeoutlen", "ttm",  P_NUM|P_VI_DEF,
2834 			    (char_u *)&p_ttm, PV_NONE,
2835 			    {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
2836     {"ttybuiltin",  "tbi",  P_BOOL|P_VI_DEF,
2837 			    (char_u *)&p_tbi, PV_NONE,
2838 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2839     {"ttyfast",	    "tf",   P_BOOL|P_NO_MKRC|P_VI_DEF,
2840 			    (char_u *)&p_tf, PV_NONE,
2841 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2842     {"ttymouse",    "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2843 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2844 			    (char_u *)&p_ttym, PV_NONE,
2845 #else
2846 			    (char_u *)NULL, PV_NONE,
2847 #endif
2848 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2849     {"ttyscroll",   "tsl",  P_NUM|P_VI_DEF,
2850 			    (char_u *)&p_ttyscroll, PV_NONE,
2851 			    {(char_u *)999L, (char_u *)0L} SCTX_INIT},
2852     {"ttytype",	    "tty",  P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2853 			    (char_u *)&T_NAME, PV_NONE,
2854 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2855     {"undodir",     "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2856 								    |P_VI_DEF,
2857 #ifdef FEAT_PERSISTENT_UNDO
2858 			    (char_u *)&p_udir, PV_NONE,
2859 			    {(char_u *)".", (char_u *)0L}
2860 #else
2861 			    (char_u *)NULL, PV_NONE,
2862 			    {(char_u *)0L, (char_u *)0L}
2863 #endif
2864 			    SCTX_INIT},
2865     {"undofile",    "udf",  P_BOOL|P_VI_DEF|P_VIM,
2866 #ifdef FEAT_PERSISTENT_UNDO
2867 			    (char_u *)&p_udf, PV_UDF,
2868 #else
2869 			    (char_u *)NULL, PV_NONE,
2870 #endif
2871 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2872     {"undolevels",  "ul",   P_NUM|P_VI_DEF,
2873 			    (char_u *)&p_ul, PV_UL,
2874 			    {
2875 #if defined(UNIX) || defined(MSWIN) || defined(VMS)
2876 			    (char_u *)1000L,
2877 #else
2878 			    (char_u *)100L,
2879 #endif
2880 				(char_u *)0L} SCTX_INIT},
2881     {"undoreload",  "ur",   P_NUM|P_VI_DEF,
2882 			    (char_u *)&p_ur, PV_NONE,
2883 			    { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
2884     {"updatecount", "uc",   P_NUM|P_VI_DEF,
2885 			    (char_u *)&p_uc, PV_NONE,
2886 			    {(char_u *)200L, (char_u *)0L} SCTX_INIT},
2887     {"updatetime",  "ut",   P_NUM|P_VI_DEF,
2888 			    (char_u *)&p_ut, PV_NONE,
2889 			    {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
2890     {"varsofttabstop", "vsts",  P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2891 #ifdef FEAT_VARTABS
2892 			    (char_u *)&p_vsts, PV_VSTS,
2893 			    {(char_u *)"", (char_u *)0L}
2894 #else
2895 			    (char_u *)NULL, PV_NONE,
2896 			    {(char_u *)"", (char_u *)NULL}
2897 #endif
2898 			    SCTX_INIT},
2899     {"vartabstop",  "vts",  P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2900 #ifdef FEAT_VARTABS
2901 			    (char_u *)&p_vts, PV_VTS,
2902 			    {(char_u *)"", (char_u *)0L}
2903 #else
2904 			    (char_u *)NULL, PV_NONE,
2905 			    {(char_u *)"", (char_u *)NULL}
2906 #endif
2907 			    SCTX_INIT},
2908     {"verbose",	    "vbs",  P_NUM|P_VI_DEF,
2909 			    (char_u *)&p_verbose, PV_NONE,
2910 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2911     {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2912 			    (char_u *)&p_vfile, PV_NONE,
2913 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
2914     {"viewdir",     "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2915 #ifdef FEAT_SESSION
2916 			    (char_u *)&p_vdir, PV_NONE,
2917 			    {(char_u *)DFLT_VDIR, (char_u *)0L}
2918 #else
2919 			    (char_u *)NULL, PV_NONE,
2920 			    {(char_u *)0L, (char_u *)0L}
2921 #endif
2922 			    SCTX_INIT},
2923     {"viewoptions", "vop",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2924 #ifdef FEAT_SESSION
2925 			    (char_u *)&p_vop, PV_NONE,
2926 			    {(char_u *)"folds,options,cursor,curdir",
2927 								  (char_u *)0L}
2928 #else
2929 			    (char_u *)NULL, PV_NONE,
2930 			    {(char_u *)0L, (char_u *)0L}
2931 #endif
2932 			    SCTX_INIT},
2933     {"viminfo",	    "vi",   P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
2934 #ifdef FEAT_VIMINFO
2935 			    (char_u *)&p_viminfo, PV_NONE,
2936 #if defined(MSWIN)
2937 			    {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
2938 #else
2939 # ifdef AMIGA
2940 			    {(char_u *)"",
2941 				 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2942 # else
2943 			    {(char_u *)"", (char_u *)"'100,<50,s10,h"}
2944 # endif
2945 #endif
2946 #else
2947 			    (char_u *)NULL, PV_NONE,
2948 			    {(char_u *)0L, (char_u *)0L}
2949 #endif
2950 			    SCTX_INIT},
2951     {"viminfofile", "vif",  P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2952 							    |P_SECURE|P_VI_DEF,
2953 #ifdef FEAT_VIMINFO
2954 			    (char_u *)&p_viminfofile, PV_NONE,
2955 			    {(char_u *)"", (char_u *)0L}
2956 #else
2957 			    (char_u *)NULL, PV_NONE,
2958 			    {(char_u *)0L, (char_u *)0L}
2959 #endif
2960 			    SCTX_INIT},
2961     {"virtualedit", "ve",   P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2962 							    |P_VIM|P_CURSWANT,
2963 			    (char_u *)&p_ve, PV_NONE,
2964 			    {(char_u *)"", (char_u *)""}
2965 			    SCTX_INIT},
2966     {"visualbell",  "vb",   P_BOOL|P_VI_DEF,
2967 			    (char_u *)&p_vb, PV_NONE,
2968 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2969     {"w300",	    NULL,   P_NUM|P_VI_DEF,
2970 			    (char_u *)NULL, PV_NONE,
2971 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2972     {"w1200",	    NULL,   P_NUM|P_VI_DEF,
2973 			    (char_u *)NULL, PV_NONE,
2974 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2975     {"w9600",	    NULL,   P_NUM|P_VI_DEF,
2976 			    (char_u *)NULL, PV_NONE,
2977 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2978     {"warn",	    NULL,   P_BOOL|P_VI_DEF,
2979 			    (char_u *)&p_warn, PV_NONE,
2980 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
2981     {"weirdinvert", "wiv",  P_BOOL|P_VI_DEF|P_RCLR,
2982 			    (char_u *)&p_wiv, PV_NONE,
2983 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
2984     {"whichwrap",   "ww",   P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
2985 			    (char_u *)&p_ww, PV_NONE,
2986 			    {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
2987     {"wildchar",    "wc",   P_NUM|P_VIM,
2988 			    (char_u *)&p_wc, PV_NONE,
2989 			    {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2990 			    SCTX_INIT},
2991     {"wildcharm",   "wcm",  P_NUM|P_VI_DEF,
2992 			    (char_u *)&p_wcm, PV_NONE,
2993 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
2994     {"wildignore",  "wig",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2995 #ifdef FEAT_WILDIGN
2996 			    (char_u *)&p_wig, PV_NONE,
2997 #else
2998 			    (char_u *)NULL, PV_NONE,
2999 #endif
3000 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
3001     {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3002 			    (char_u *)&p_wic, PV_NONE,
3003 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
3004     {"wildmenu",    "wmnu", P_BOOL|P_VI_DEF,
3005 #ifdef FEAT_WILDMENU
3006 			    (char_u *)&p_wmnu, PV_NONE,
3007 #else
3008 			    (char_u *)NULL, PV_NONE,
3009 #endif
3010 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
3011     {"wildmode",    "wim",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
3012 			    (char_u *)&p_wim, PV_NONE,
3013 			    {(char_u *)"full", (char_u *)0L} SCTX_INIT},
3014     {"wildoptions", "wop",  P_STRING|P_VI_DEF,
3015 #ifdef FEAT_CMDL_COMPL
3016 			    (char_u *)&p_wop, PV_NONE,
3017 			    {(char_u *)"", (char_u *)0L}
3018 #else
3019 			    (char_u *)NULL, PV_NONE,
3020 			    {(char_u *)NULL, (char_u *)0L}
3021 #endif
3022 			    SCTX_INIT},
3023     {"winaltkeys",  "wak",  P_STRING|P_VI_DEF,
3024 #ifdef FEAT_WAK
3025 			    (char_u *)&p_wak, PV_NONE,
3026 			    {(char_u *)"menu", (char_u *)0L}
3027 #else
3028 			    (char_u *)NULL, PV_NONE,
3029 			    {(char_u *)NULL, (char_u *)0L}
3030 #endif
3031 			    SCTX_INIT},
3032     {"window",	    "wi",   P_NUM|P_VI_DEF,
3033 			    (char_u *)&p_window, PV_NONE,
3034 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
3035     {"winheight",   "wh",   P_NUM|P_VI_DEF,
3036 			    (char_u *)&p_wh, PV_NONE,
3037 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
3038     {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
3039 			    (char_u *)VAR_WIN, PV_WFH,
3040 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
3041     {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
3042 			    (char_u *)VAR_WIN, PV_WFW,
3043 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
3044     {"winminheight", "wmh", P_NUM|P_VI_DEF,
3045 			    (char_u *)&p_wmh, PV_NONE,
3046 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
3047     {"winminwidth", "wmw", P_NUM|P_VI_DEF,
3048 			    (char_u *)&p_wmw, PV_NONE,
3049 			    {(char_u *)1L, (char_u *)0L} SCTX_INIT},
3050     {"winptydll", NULL,	    P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
3051 #if defined(MSWIN) && defined(FEAT_TERMINAL)
3052 			    (char_u *)&p_winptydll, PV_NONE, {
3053 # ifdef _WIN64
3054 			    (char_u *)"winpty64.dll",
3055 # else
3056 			    (char_u *)"winpty32.dll",
3057 # endif
3058 				(char_u *)0L}
3059 #else
3060 			    (char_u *)NULL, PV_NONE,
3061 			    {(char_u *)0L, (char_u *)0L}
3062 #endif
3063 			    SCTX_INIT},
3064     {"winwidth",   "wiw",   P_NUM|P_VI_DEF,
3065 			    (char_u *)&p_wiw, PV_NONE,
3066 			    {(char_u *)20L, (char_u *)0L} SCTX_INIT},
3067     {"wrap",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
3068 			    (char_u *)VAR_WIN, PV_WRAP,
3069 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
3070     {"wrapmargin",  "wm",   P_NUM|P_VI_DEF,
3071 			    (char_u *)&p_wm, PV_WM,
3072 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
3073     {"wrapscan",    "ws",   P_BOOL|P_VI_DEF,
3074 			    (char_u *)&p_ws, PV_NONE,
3075 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
3076     {"write",	    NULL,   P_BOOL|P_VI_DEF,
3077 			    (char_u *)&p_write, PV_NONE,
3078 			    {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
3079     {"writeany",    "wa",   P_BOOL|P_VI_DEF,
3080 			    (char_u *)&p_wa, PV_NONE,
3081 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
3082     {"writebackup", "wb",   P_BOOL|P_VI_DEF|P_VIM,
3083 			    (char_u *)&p_wb, PV_NONE,
3084 			    {
3085 #ifdef FEAT_WRITEBACKUP
3086 			    (char_u *)TRUE,
3087 #else
3088 			    (char_u *)FALSE,
3089 #endif
3090 				(char_u *)0L} SCTX_INIT},
3091     {"writedelay",  "wd",   P_NUM|P_VI_DEF,
3092 			    (char_u *)&p_wd, PV_NONE,
3093 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
3094 
3095 /* terminal output codes */
3096 #define p_term(sss, vvv)   {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
3097 			    (char_u *)&vvv, PV_NONE, \
3098 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
3099 
3100     p_term("t_AB", T_CAB)
3101     p_term("t_AF", T_CAF)
3102     p_term("t_AL", T_CAL)
3103     p_term("t_al", T_AL)
3104     p_term("t_bc", T_BC)
3105     p_term("t_BE", T_BE)
3106     p_term("t_BD", T_BD)
3107     p_term("t_cd", T_CD)
3108     p_term("t_ce", T_CE)
3109     p_term("t_cl", T_CL)
3110     p_term("t_cm", T_CM)
3111     p_term("t_Ce", T_UCE)
3112     p_term("t_Co", T_CCO)
3113     p_term("t_CS", T_CCS)
3114     p_term("t_Cs", T_UCS)
3115     p_term("t_cs", T_CS)
3116     p_term("t_CV", T_CSV)
3117     p_term("t_da", T_DA)
3118     p_term("t_db", T_DB)
3119     p_term("t_DL", T_CDL)
3120     p_term("t_dl", T_DL)
3121     p_term("t_EC", T_CEC)
3122     p_term("t_EI", T_CEI)
3123     p_term("t_fs", T_FS)
3124     p_term("t_GP", T_CGP)
3125     p_term("t_IE", T_CIE)
3126     p_term("t_IS", T_CIS)
3127     p_term("t_ke", T_KE)
3128     p_term("t_ks", T_KS)
3129     p_term("t_le", T_LE)
3130     p_term("t_mb", T_MB)
3131     p_term("t_md", T_MD)
3132     p_term("t_me", T_ME)
3133     p_term("t_mr", T_MR)
3134     p_term("t_ms", T_MS)
3135     p_term("t_nd", T_ND)
3136     p_term("t_op", T_OP)
3137     p_term("t_RF", T_RFG)
3138     p_term("t_RB", T_RBG)
3139     p_term("t_RC", T_CRC)
3140     p_term("t_RI", T_CRI)
3141     p_term("t_Ri", T_SRI)
3142     p_term("t_RS", T_CRS)
3143     p_term("t_RT", T_CRT)
3144     p_term("t_RV", T_CRV)
3145     p_term("t_Sb", T_CSB)
3146     p_term("t_SC", T_CSC)
3147     p_term("t_se", T_SE)
3148     p_term("t_Sf", T_CSF)
3149     p_term("t_SH", T_CSH)
3150     p_term("t_SI", T_CSI)
3151     p_term("t_Si", T_SSI)
3152     p_term("t_so", T_SO)
3153     p_term("t_SR", T_CSR)
3154     p_term("t_sr", T_SR)
3155     p_term("t_ST", T_CST)
3156     p_term("t_Te", T_STE)
3157     p_term("t_te", T_TE)
3158     p_term("t_ti", T_TI)
3159     p_term("t_Ts", T_STS)
3160     p_term("t_ts", T_TS)
3161     p_term("t_u7", T_U7)
3162     p_term("t_ue", T_UE)
3163     p_term("t_us", T_US)
3164     p_term("t_ut", T_UT)
3165     p_term("t_vb", T_VB)
3166     p_term("t_ve", T_VE)
3167     p_term("t_vi", T_VI)
3168     p_term("t_VS", T_CVS)
3169     p_term("t_vs", T_VS)
3170     p_term("t_WP", T_CWP)
3171     p_term("t_WS", T_CWS)
3172     p_term("t_xn", T_XN)
3173     p_term("t_xs", T_XS)
3174     p_term("t_ZH", T_CZH)
3175     p_term("t_ZR", T_CZR)
3176     p_term("t_8f", T_8F)
3177     p_term("t_8b", T_8B)
3178 
3179 /* terminal key codes are not in here */
3180 
3181     /* end marker */
3182     {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
3183 };
3184 
3185 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3186 
3187 static char *(p_ambw_values[]) = {"single", "double", NULL};
3188 static char *(p_bg_values[]) = {"light", "dark", NULL};
3189 static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
3190 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
3191 #ifdef FEAT_CRYPT
3192 static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
3193 #endif
3194 #ifdef FEAT_CMDL_COMPL
3195 static char *(p_wop_values[]) = {"tagfile", NULL};
3196 #endif
3197 #ifdef FEAT_WAK
3198 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3199 #endif
3200 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
3201 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3202 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
3203 static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
3204 #ifdef FEAT_BROWSE
3205 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3206 #endif
3207 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3208 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
3209 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3210 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
3211 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3212 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3213 #ifdef FEAT_FOLDING
3214 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
3215 # ifdef FEAT_DIFF
3216 				"diff",
3217 # endif
3218 				NULL};
3219 static char *(p_fcl_values[]) = {"all", NULL};
3220 #endif
3221 #ifdef FEAT_INS_EXPAND
3222 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
3223 #endif
3224 #ifdef FEAT_SIGNS
3225 static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3226 #endif
3227 #if defined(MSWIN) && defined(FEAT_TERMINAL)
3228 static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
3229 #endif
3230 
3231 static void set_options_default(int opt_flags);
3232 static void set_string_default_esc(char *name, char_u *val, int escape);
3233 static char_u *term_bg_default(void);
3234 static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
3235 static char_u *option_expand(int opt_idx, char_u *val);
3236 static void didset_options(void);
3237 static void didset_options2(void);
3238 static void check_string_option(char_u **pp);
3239 #if defined(FEAT_EVAL) || defined(PROTO)
3240 static long_u *insecure_flag(int opt_idx, int opt_flags);
3241 #else
3242 # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3243 #endif
3244 static void set_string_option_global(int opt_idx, char_u **varp);
3245 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);
3246 static char *set_chars_option(char_u **varp);
3247 #ifdef FEAT_CLIPBOARD
3248 static char *check_clipboard_option(void);
3249 #endif
3250 #ifdef FEAT_SPELL
3251 static char *did_set_spell_option(int is_spellfile);
3252 static char *compile_cap_prog(synblock_T *synblock);
3253 #endif
3254 #ifdef FEAT_EVAL
3255 static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
3256 #endif
3257 static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3258 static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags);
3259 static void check_redraw(long_u flags);
3260 static int findoption(char_u *);
3261 static int find_key_option(char_u *arg_arg, int has_lt);
3262 static void showoptions(int all, int opt_flags);
3263 static int optval_default(struct vimoption *, char_u *varp);
3264 static void showoneopt(struct vimoption *, int opt_flags);
3265 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
3266 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3267 static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3268 static int  istermoption(struct vimoption *);
3269 static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3270 static char_u *get_varp(struct vimoption *);
3271 static void option_value2string(struct vimoption *, int opt_flags);
3272 static void check_winopt(winopt_T *wop);
3273 static int wc_use_keyname(char_u *varp, long *wcp);
3274 #ifdef FEAT_LANGMAP
3275 static void langmap_init(void);
3276 static void langmap_set(void);
3277 #endif
3278 static void paste_option_changed(void);
3279 static void compatible_set(void);
3280 #ifdef FEAT_LINEBREAK
3281 static void fill_breakat_flags(void);
3282 #endif
3283 static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3284 static int check_opt_strings(char_u *val, char **values, int);
3285 static int check_opt_wim(void);
3286 #ifdef FEAT_LINEBREAK
3287 static int briopt_check(win_T *wp);
3288 #endif
3289 
3290 /*
3291  * Initialize the options, first part.
3292  *
3293  * Called only once from main(), just after creating the first buffer.
3294  * If "clean_arg" is TRUE Vim was started with --clean.
3295  */
3296     void
3297 set_init_1(int clean_arg)
3298 {
3299     char_u	*p;
3300     int		opt_idx;
3301     long_u	n;
3302 
3303 #ifdef FEAT_LANGMAP
3304     langmap_init();
3305 #endif
3306 
3307     /* Be Vi compatible by default */
3308     p_cp = TRUE;
3309 
3310     /* Use POSIX compatibility when $VIM_POSIX is set. */
3311     if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
3312     {
3313 	set_string_default("cpo", (char_u *)CPO_ALL);
3314 	set_string_default("shm", (char_u *)SHM_POSIX);
3315     }
3316 
3317     /*
3318      * Find default value for 'shell' option.
3319      * Don't use it if it is empty.
3320      */
3321     if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
3322 #if defined(MSWIN)
3323 	    || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
3324 	    || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
3325 #endif
3326 	    )
3327 	set_string_default_esc("sh", p, TRUE);
3328 
3329 #ifdef FEAT_WILDIGN
3330     /*
3331      * Set the default for 'backupskip' to include environment variables for
3332      * temp files.
3333      */
3334     {
3335 # ifdef UNIX
3336 	static char	*(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3337 # else
3338 	static char	*(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3339 # endif
3340 	int		len;
3341 	garray_T	ga;
3342 	int		mustfree;
3343 
3344 	ga_init2(&ga, 1, 100);
3345 	for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3346 	{
3347 	    mustfree = FALSE;
3348 # ifdef UNIX
3349 	    if (*names[n] == NUL)
3350 #  ifdef MACOS_X
3351 		p = (char_u *)"/private/tmp";
3352 #  else
3353 		p = (char_u *)"/tmp";
3354 #  endif
3355 	    else
3356 # endif
3357 		p = vim_getenv((char_u *)names[n], &mustfree);
3358 	    if (p != NULL && *p != NUL)
3359 	    {
3360 		/* First time count the NUL, otherwise count the ','. */
3361 		len = (int)STRLEN(p) + 3;
3362 		if (ga_grow(&ga, len) == OK)
3363 		{
3364 		    if (ga.ga_len > 0)
3365 			STRCAT(ga.ga_data, ",");
3366 		    STRCAT(ga.ga_data, p);
3367 		    add_pathsep(ga.ga_data);
3368 		    STRCAT(ga.ga_data, "*");
3369 		    ga.ga_len += len;
3370 		}
3371 	    }
3372 	    if (mustfree)
3373 		vim_free(p);
3374 	}
3375 	if (ga.ga_data != NULL)
3376 	{
3377 	    set_string_default("bsk", ga.ga_data);
3378 	    vim_free(ga.ga_data);
3379 	}
3380     }
3381 #endif
3382 
3383     /*
3384      * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3385      */
3386     opt_idx = findoption((char_u *)"maxmemtot");
3387     if (opt_idx >= 0)
3388     {
3389 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3390 	if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3391 #endif
3392 	{
3393 #ifdef HAVE_AVAIL_MEM
3394 	    /* Use amount of memory available at this moment. */
3395 	    n = (mch_avail_mem(FALSE) >> 1);
3396 #else
3397 # ifdef HAVE_TOTAL_MEM
3398 	    /* Use amount of memory available to Vim. */
3399 	    n = (mch_total_mem(FALSE) >> 1);
3400 # else
3401 	    n = (0x7fffffff >> 11);
3402 # endif
3403 #endif
3404 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3405 	    opt_idx = findoption((char_u *)"maxmem");
3406 	    if (opt_idx >= 0)
3407 	    {
3408 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3409 		if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3410 		  || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3411 #endif
3412 		    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3413 	    }
3414 	}
3415     }
3416 
3417 #ifdef FEAT_SEARCHPATH
3418     {
3419 	char_u	*cdpath;
3420 	char_u	*buf;
3421 	int	i;
3422 	int	j;
3423 	int	mustfree = FALSE;
3424 
3425 	/* Initialize the 'cdpath' option's default value. */
3426 	cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
3427 	if (cdpath != NULL)
3428 	{
3429 	    buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3430 	    if (buf != NULL)
3431 	    {
3432 		buf[0] = ',';	    /* start with ",", current dir first */
3433 		j = 1;
3434 		for (i = 0; cdpath[i] != NUL; ++i)
3435 		{
3436 		    if (vim_ispathlistsep(cdpath[i]))
3437 			buf[j++] = ',';
3438 		    else
3439 		    {
3440 			if (cdpath[i] == ' ' || cdpath[i] == ',')
3441 			    buf[j++] = '\\';
3442 			buf[j++] = cdpath[i];
3443 		    }
3444 		}
3445 		buf[j] = NUL;
3446 		opt_idx = findoption((char_u *)"cdpath");
3447 		if (opt_idx >= 0)
3448 		{
3449 		    options[opt_idx].def_val[VI_DEFAULT] = buf;
3450 		    options[opt_idx].flags |= P_DEF_ALLOCED;
3451 		}
3452 		else
3453 		    vim_free(buf); /* cannot happen */
3454 	    }
3455 	    if (mustfree)
3456 		vim_free(cdpath);
3457 	}
3458     }
3459 #endif
3460 
3461 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3462     /* Set print encoding on platforms that don't default to latin1 */
3463     set_string_default("penc",
3464 # if defined(MSWIN)
3465 		       (char_u *)"cp1252"
3466 # else
3467 #  ifdef VMS
3468 		       (char_u *)"dec-mcs"
3469 #  else
3470 #   ifdef EBCDIC
3471 		       (char_u *)"ebcdic-uk"
3472 #   else
3473 #    ifdef MAC
3474 		       (char_u *)"mac-roman"
3475 #    else /* HPUX */
3476 		       (char_u *)"hp-roman8"
3477 #    endif
3478 #   endif
3479 #  endif
3480 # endif
3481 		       );
3482 #endif
3483 
3484 #ifdef FEAT_POSTSCRIPT
3485     /* 'printexpr' must be allocated to be able to evaluate it. */
3486     set_string_default("pexpr",
3487 # if defined(MSWIN)
3488 	    (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
3489 # else
3490 #  ifdef VMS
3491 	    (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3492 
3493 #  else
3494 	    (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3495 #  endif
3496 # endif
3497 	    );
3498 #endif
3499 
3500     /*
3501      * Set all the options (except the terminal options) to their default
3502      * value.  Also set the global value for local options.
3503      */
3504     set_options_default(0);
3505 
3506 #ifdef CLEAN_RUNTIMEPATH
3507     if (clean_arg)
3508     {
3509 	opt_idx = findoption((char_u *)"runtimepath");
3510 	if (opt_idx >= 0)
3511 	{
3512 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3513 	    p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3514 	}
3515 	opt_idx = findoption((char_u *)"packpath");
3516 	if (opt_idx >= 0)
3517 	{
3518 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3519 	    p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3520 	}
3521     }
3522 #endif
3523 
3524 #ifdef FEAT_GUI
3525     if (found_reverse_arg)
3526 	set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3527 #endif
3528 
3529     curbuf->b_p_initialized = TRUE;
3530     curbuf->b_p_ar = -1;	/* no local 'autoread' value */
3531     curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
3532     check_buf_options(curbuf);
3533     check_win_options(curwin);
3534     check_options();
3535 
3536     /* Must be before option_expand(), because that one needs vim_isIDc() */
3537     didset_options();
3538 
3539 #ifdef FEAT_SPELL
3540     /* Use the current chartab for the generic chartab. This is not in
3541      * didset_options() because it only depends on 'encoding'. */
3542     init_spell_chartab();
3543 #endif
3544 
3545     /*
3546      * Expand environment variables and things like "~" for the defaults.
3547      * If option_expand() returns non-NULL the variable is expanded.  This can
3548      * only happen for non-indirect options.
3549      * Also set the default to the expanded value, so ":set" does not list
3550      * them.
3551      * Don't set the P_ALLOCED flag, because we don't want to free the
3552      * default.
3553      */
3554     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3555     {
3556 	if ((options[opt_idx].flags & P_GETTEXT)
3557 					      && options[opt_idx].var != NULL)
3558 	    p = (char_u *)_(*(char **)options[opt_idx].var);
3559 	else
3560 	    p = option_expand(opt_idx, NULL);
3561 	if (p != NULL && (p = vim_strsave(p)) != NULL)
3562 	{
3563 	    *(char_u **)options[opt_idx].var = p;
3564 	    /* VIMEXP
3565 	     * Defaults for all expanded options are currently the same for Vi
3566 	     * and Vim.  When this changes, add some code here!  Also need to
3567 	     * split P_DEF_ALLOCED in two.
3568 	     */
3569 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
3570 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3571 	    options[opt_idx].def_val[VI_DEFAULT] = p;
3572 	    options[opt_idx].flags |= P_DEF_ALLOCED;
3573 	}
3574     }
3575 
3576     save_file_ff(curbuf);	/* Buffer is unchanged */
3577 
3578 #if defined(FEAT_ARABIC)
3579     /* Detect use of mlterm.
3580      * Mlterm is a terminal emulator akin to xterm that has some special
3581      * abilities (bidi namely).
3582      * NOTE: mlterm's author is being asked to 'set' a variable
3583      *       instead of an environment variable due to inheritance.
3584      */
3585     if (mch_getenv((char_u *)"MLTERM") != NULL)
3586 	set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3587 #endif
3588 
3589     didset_options2();
3590 
3591 # if defined(MSWIN) && defined(FEAT_GETTEXT)
3592     /*
3593      * If $LANG isn't set, try to get a good value for it.  This makes the
3594      * right language be used automatically.  Don't do this for English.
3595      */
3596     if (mch_getenv((char_u *)"LANG") == NULL)
3597     {
3598 	char	buf[20];
3599 
3600 	/* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3601 	 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3602 	 * only the first two. */
3603 	n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3604 							     (LPTSTR)buf, 20);
3605 	if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3606 	{
3607 	    /* There are a few exceptions (probably more) */
3608 	    if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3609 		STRCPY(buf, "zh_TW");
3610 	    else if (STRNICMP(buf, "chs", 3) == 0
3611 					      || STRNICMP(buf, "zhc", 3) == 0)
3612 		STRCPY(buf, "zh_CN");
3613 	    else if (STRNICMP(buf, "jp", 2) == 0)
3614 		STRCPY(buf, "ja");
3615 	    else
3616 		buf[2] = NUL;		/* truncate to two-letter code */
3617 	    vim_setenv((char_u *)"LANG", (char_u *)buf);
3618 	}
3619     }
3620 # else
3621 #  ifdef MACOS_CONVERT
3622     /* Moved to os_mac_conv.c to avoid dependency problems. */
3623     mac_lang_init();
3624 #  endif
3625 # endif
3626 
3627     /* enc_locale() will try to find the encoding of the current locale. */
3628     p = enc_locale();
3629     if (p != NULL)
3630     {
3631 	char_u *save_enc;
3632 
3633 	/* Try setting 'encoding' and check if the value is valid.
3634 	 * If not, go back to the default "latin1". */
3635 	save_enc = p_enc;
3636 	p_enc = p;
3637 	if (STRCMP(p_enc, "gb18030") == 0)
3638 	{
3639 	    /* We don't support "gb18030", but "cp936" is a good substitute
3640 	     * for practical purposes, thus use that.  It's not an alias to
3641 	     * still support conversion between gb18030 and utf-8. */
3642 	    p_enc = vim_strsave((char_u *)"cp936");
3643 	    vim_free(p);
3644 	}
3645 	if (mb_init() == NULL)
3646 	{
3647 	    opt_idx = findoption((char_u *)"encoding");
3648 	    if (opt_idx >= 0)
3649 	    {
3650 		options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3651 		options[opt_idx].flags |= P_DEF_ALLOCED;
3652 	    }
3653 
3654 #if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
3655 	    if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
3656 	    {
3657 		/* Adjust the default for 'isprint' and 'iskeyword' to match
3658 		 * latin1.  Also set the defaults for when 'nocompatible' is
3659 		 * set. */
3660 		set_string_option_direct((char_u *)"isp", -1,
3661 					      ISP_LATIN1, OPT_FREE, SID_NONE);
3662 		set_string_option_direct((char_u *)"isk", -1,
3663 					      ISK_LATIN1, OPT_FREE, SID_NONE);
3664 		opt_idx = findoption((char_u *)"isp");
3665 		if (opt_idx >= 0)
3666 		    options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
3667 		opt_idx = findoption((char_u *)"isk");
3668 		if (opt_idx >= 0)
3669 		    options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
3670 		(void)init_chartab();
3671 	    }
3672 #endif
3673 
3674 #if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
3675 	    /* Win32 console: When GetACP() returns a different value from
3676 	     * GetConsoleCP() set 'termencoding'. */
3677 	    if (
3678 # ifdef VIMDLL
3679 	       (!gui.in_use && !gui.starting) &&
3680 # endif
3681 	        GetACP() != GetConsoleCP())
3682 	    {
3683 		char	buf[50];
3684 
3685 		/* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3686 		 * Use an alternative value. */
3687 		if (GetConsoleCP() == 0)
3688 		    sprintf(buf, "cp%ld", (long)GetACP());
3689 		else
3690 		    sprintf(buf, "cp%ld", (long)GetConsoleCP());
3691 		p_tenc = vim_strsave((char_u *)buf);
3692 		if (p_tenc != NULL)
3693 		{
3694 		    opt_idx = findoption((char_u *)"termencoding");
3695 		    if (opt_idx >= 0)
3696 		    {
3697 			options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3698 			options[opt_idx].flags |= P_DEF_ALLOCED;
3699 		    }
3700 		    convert_setup(&input_conv, p_tenc, p_enc);
3701 		    convert_setup(&output_conv, p_enc, p_tenc);
3702 		}
3703 		else
3704 		    p_tenc = empty_option;
3705 	    }
3706 #endif
3707 #if defined(MSWIN)
3708 	    /* $HOME may have characters in active code page. */
3709 	    init_homedir();
3710 #endif
3711 	}
3712 	else
3713 	{
3714 	    vim_free(p_enc);
3715 	    p_enc = save_enc;
3716 	}
3717     }
3718 
3719 #ifdef FEAT_MULTI_LANG
3720     /* Set the default for 'helplang'. */
3721     set_helplang_default(get_mess_lang());
3722 #endif
3723 }
3724 
3725 /*
3726  * Set an option to its default value.
3727  * This does not take care of side effects!
3728  */
3729     static void
3730 set_option_default(
3731     int		opt_idx,
3732     int		opt_flags,	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3733     int		compatible)	/* use Vi default value */
3734 {
3735     char_u	*varp;		/* pointer to variable for current option */
3736     int		dvi;		/* index in def_val[] */
3737     long_u	flags;
3738     long_u	*flagsp;
3739     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3740 
3741     varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3742     flags = options[opt_idx].flags;
3743     if (varp != NULL)	    /* skip hidden option, nothing to do for it */
3744     {
3745 	dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3746 	if (flags & P_STRING)
3747 	{
3748 	    /* Use set_string_option_direct() for local options to handle
3749 	     * freeing and allocating the value. */
3750 	    if (options[opt_idx].indir != PV_NONE)
3751 		set_string_option_direct(NULL, opt_idx,
3752 				 options[opt_idx].def_val[dvi], opt_flags, 0);
3753 	    else
3754 	    {
3755 		if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3756 		    free_string_option(*(char_u **)(varp));
3757 		*(char_u **)varp = options[opt_idx].def_val[dvi];
3758 		options[opt_idx].flags &= ~P_ALLOCED;
3759 	    }
3760 	}
3761 	else if (flags & P_NUM)
3762 	{
3763 	    if (options[opt_idx].indir == PV_SCROLL)
3764 		win_comp_scroll(curwin);
3765 	    else
3766 	    {
3767 		long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3768 
3769 		if ((long *)varp == &curwin->w_p_so
3770 			|| (long *)varp == &curwin->w_p_siso)
3771 		    // 'scrolloff' and 'sidescrolloff' local values have a
3772 		    // different default value than the global default.
3773 		    *(long *)varp = -1;
3774 		else
3775 		    *(long *)varp = def_val;
3776 		/* May also set global value for local option. */
3777 		if (both)
3778 		    *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3779 								def_val;
3780 	    }
3781 	}
3782 	else	/* P_BOOL */
3783 	{
3784 	    /* the cast to long is required for Manx C, long_i is needed for
3785 	     * MSVC */
3786 	    *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
3787 #ifdef UNIX
3788 	    /* 'modeline' defaults to off for root */
3789 	    if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3790 		*(int *)varp = FALSE;
3791 #endif
3792 	    /* May also set global value for local option. */
3793 	    if (both)
3794 		*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3795 								*(int *)varp;
3796 	}
3797 
3798 	/* The default value is not insecure. */
3799 	flagsp = insecure_flag(opt_idx, opt_flags);
3800 	*flagsp = *flagsp & ~P_INSECURE;
3801     }
3802 
3803 #ifdef FEAT_EVAL
3804     set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
3805 #endif
3806 }
3807 
3808 /*
3809  * Set all options (except terminal options) to their default value.
3810  * When "opt_flags" is non-zero skip 'encoding'.
3811  */
3812     static void
3813 set_options_default(
3814     int		opt_flags)	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3815 {
3816     int		i;
3817     win_T	*wp;
3818     tabpage_T	*tp;
3819 
3820     for (i = 0; !istermoption(&options[i]); i++)
3821 	if (!(options[i].flags & P_NODEFAULT)
3822 		&& (opt_flags == 0
3823 		    || (options[i].var != (char_u *)&p_enc
3824 # if defined(FEAT_CRYPT)
3825 			&& options[i].var != (char_u *)&p_cm
3826 			&& options[i].var != (char_u *)&p_key
3827 # endif
3828 			)))
3829 	    set_option_default(i, opt_flags, p_cp);
3830 
3831     /* The 'scroll' option must be computed for all windows. */
3832     FOR_ALL_TAB_WINDOWS(tp, wp)
3833 	win_comp_scroll(wp);
3834 #ifdef FEAT_CINDENT
3835     parse_cino(curbuf);
3836 #endif
3837 }
3838 
3839 /*
3840  * Set the Vi-default value of a string option.
3841  * Used for 'sh', 'backupskip' and 'term'.
3842  * When "escape" is TRUE escape spaces with a backslash.
3843  */
3844     static void
3845 set_string_default_esc(char *name, char_u *val, int escape)
3846 {
3847     char_u	*p;
3848     int		opt_idx;
3849 
3850     if (escape && vim_strchr(val, ' ') != NULL)
3851 	p = vim_strsave_escaped(val, (char_u *)" ");
3852     else
3853 	p = vim_strsave(val);
3854     if (p != NULL)		/* we don't want a NULL */
3855     {
3856 	opt_idx = findoption((char_u *)name);
3857 	if (opt_idx >= 0)
3858 	{
3859 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
3860 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3861 	    options[opt_idx].def_val[VI_DEFAULT] = p;
3862 	    options[opt_idx].flags |= P_DEF_ALLOCED;
3863 	}
3864     }
3865 }
3866 
3867     void
3868 set_string_default(char *name, char_u *val)
3869 {
3870     set_string_default_esc(name, val, FALSE);
3871 }
3872 
3873 /*
3874  * Set the Vi-default value of a number option.
3875  * Used for 'lines' and 'columns'.
3876  */
3877     void
3878 set_number_default(char *name, long val)
3879 {
3880     int		opt_idx;
3881 
3882     opt_idx = findoption((char_u *)name);
3883     if (opt_idx >= 0)
3884 	options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3885 }
3886 
3887 #if defined(EXITFREE) || defined(PROTO)
3888 /*
3889  * Free all options.
3890  */
3891     void
3892 free_all_options(void)
3893 {
3894     int		i;
3895 
3896     for (i = 0; !istermoption(&options[i]); i++)
3897     {
3898 	if (options[i].indir == PV_NONE)
3899 	{
3900 	    /* global option: free value and default value. */
3901 	    if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
3902 		free_string_option(*(char_u **)options[i].var);
3903 	    if (options[i].flags & P_DEF_ALLOCED)
3904 		free_string_option(options[i].def_val[VI_DEFAULT]);
3905 	}
3906 	else if (options[i].var != VAR_WIN
3907 		&& (options[i].flags & P_STRING))
3908 	    /* buffer-local option: free global value */
3909 	    free_string_option(*(char_u **)options[i].var);
3910     }
3911 }
3912 #endif
3913 
3914 
3915 /*
3916  * Initialize the options, part two: After getting Rows and Columns and
3917  * setting 'term'.
3918  */
3919     void
3920 set_init_2(void)
3921 {
3922     int		idx;
3923 
3924     /*
3925      * 'scroll' defaults to half the window height. The stored default is zero,
3926      * which results in the actual value computed from the window height.
3927      */
3928     idx = findoption((char_u *)"scroll");
3929     if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3930 	set_option_default(idx, OPT_LOCAL, p_cp);
3931     comp_col();
3932 
3933     /*
3934      * 'window' is only for backwards compatibility with Vi.
3935      * Default is Rows - 1.
3936      */
3937     if (!option_was_set((char_u *)"window"))
3938 	p_window = Rows - 1;
3939     set_number_default("window", Rows - 1);
3940 
3941     /* For DOS console the default is always black. */
3942 #if !((defined(MSWIN)) && !defined(FEAT_GUI))
3943     /*
3944      * If 'background' wasn't set by the user, try guessing the value,
3945      * depending on the terminal name.  Only need to check for terminals
3946      * with a dark background, that can handle color.
3947      */
3948     idx = findoption((char_u *)"bg");
3949     if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3950 						 && *term_bg_default() == 'd')
3951     {
3952 	set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
3953 	/* don't mark it as set, when starting the GUI it may be
3954 	 * changed again */
3955 	options[idx].flags &= ~P_WAS_SET;
3956     }
3957 #endif
3958 
3959 #ifdef CURSOR_SHAPE
3960     parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3961 #endif
3962 #ifdef FEAT_MOUSESHAPE
3963     parse_shape_opt(SHAPE_MOUSE);  /* set mouse shapes from 'mouseshape' */
3964 #endif
3965 #ifdef FEAT_PRINTER
3966     (void)parse_printoptions();	    /* parse 'printoptions' default value */
3967 #endif
3968 }
3969 
3970 /*
3971  * Return "dark" or "light" depending on the kind of terminal.
3972  * This is just guessing!  Recognized are:
3973  * "linux"	    Linux console
3974  * "screen.linux"   Linux console with screen
3975  * "cygwin.*"	    Cygwin shell
3976  * "putty.*"	    Putty program
3977  * We also check the COLORFGBG environment variable, which is set by
3978  * rxvt and derivatives. This variable contains either two or three
3979  * values separated by semicolons; we want the last value in either
3980  * case. If this value is 0-6 or 8, our background is dark.
3981  */
3982     static char_u *
3983 term_bg_default(void)
3984 {
3985 #if defined(MSWIN)
3986     /* DOS console is nearly always black */
3987     return (char_u *)"dark";
3988 #else
3989     char_u	*p;
3990 
3991     if (STRCMP(T_NAME, "linux") == 0
3992 	    || STRCMP(T_NAME, "screen.linux") == 0
3993 	    || STRNCMP(T_NAME, "cygwin", 6) == 0
3994 	    || STRNCMP(T_NAME, "putty", 5) == 0
3995 	    || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3996 		&& (p = vim_strrchr(p, ';')) != NULL
3997 		&& ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3998 		&& p[2] == NUL))
3999 	return (char_u *)"dark";
4000     return (char_u *)"light";
4001 #endif
4002 }
4003 
4004 /*
4005  * Initialize the options, part three: After reading the .vimrc
4006  */
4007     void
4008 set_init_3(void)
4009 {
4010 #if defined(UNIX) || defined(MSWIN)
4011 /*
4012  * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4013  * This is done after other initializations, where 'shell' might have been
4014  * set, but only if they have not been set before.
4015  */
4016     char_u  *p;
4017     int	    idx_srr;
4018     int	    do_srr;
4019 # ifdef FEAT_QUICKFIX
4020     int	    idx_sp;
4021     int	    do_sp;
4022 # endif
4023 
4024     idx_srr = findoption((char_u *)"srr");
4025     if (idx_srr < 0)
4026 	do_srr = FALSE;
4027     else
4028 	do_srr = !(options[idx_srr].flags & P_WAS_SET);
4029 # ifdef FEAT_QUICKFIX
4030     idx_sp = findoption((char_u *)"sp");
4031     if (idx_sp < 0)
4032 	do_sp = FALSE;
4033     else
4034 	do_sp = !(options[idx_sp].flags & P_WAS_SET);
4035 # endif
4036     p = get_isolated_shell_name();
4037     if (p != NULL)
4038     {
4039 	/*
4040 	 * Default for p_sp is "| tee", for p_srr is ">".
4041 	 * For known shells it is changed here to include stderr.
4042 	 */
4043 	if (	   fnamecmp(p, "csh") == 0
4044 		|| fnamecmp(p, "tcsh") == 0
4045 # if defined(MSWIN)	// also check with .exe extension
4046 		|| fnamecmp(p, "csh.exe") == 0
4047 		|| fnamecmp(p, "tcsh.exe") == 0
4048 # endif
4049 	   )
4050 	{
4051 # if defined(FEAT_QUICKFIX)
4052 	    if (do_sp)
4053 	    {
4054 #  ifdef MSWIN
4055 		p_sp = (char_u *)">&";
4056 #  else
4057 		p_sp = (char_u *)"|& tee";
4058 #  endif
4059 		options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4060 	    }
4061 # endif
4062 	    if (do_srr)
4063 	    {
4064 		p_srr = (char_u *)">&";
4065 		options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4066 	    }
4067 	}
4068 	else
4069 	    /* Always use bourne shell style redirection if we reach this */
4070 	    if (       fnamecmp(p, "sh") == 0
4071 		    || fnamecmp(p, "ksh") == 0
4072 		    || fnamecmp(p, "mksh") == 0
4073 		    || fnamecmp(p, "pdksh") == 0
4074 		    || fnamecmp(p, "zsh") == 0
4075 		    || fnamecmp(p, "zsh-beta") == 0
4076 		    || fnamecmp(p, "bash") == 0
4077 		    || fnamecmp(p, "fish") == 0
4078 # ifdef MSWIN
4079 		    || fnamecmp(p, "cmd") == 0
4080 		    || fnamecmp(p, "sh.exe") == 0
4081 		    || fnamecmp(p, "ksh.exe") == 0
4082 		    || fnamecmp(p, "mksh.exe") == 0
4083 		    || fnamecmp(p, "pdksh.exe") == 0
4084 		    || fnamecmp(p, "zsh.exe") == 0
4085 		    || fnamecmp(p, "zsh-beta.exe") == 0
4086 		    || fnamecmp(p, "bash.exe") == 0
4087 		    || fnamecmp(p, "cmd.exe") == 0
4088 # endif
4089 		    )
4090 	    {
4091 # if defined(FEAT_QUICKFIX)
4092 		if (do_sp)
4093 		{
4094 #  ifdef MSWIN
4095 		    p_sp = (char_u *)">%s 2>&1";
4096 #  else
4097 		    p_sp = (char_u *)"2>&1| tee";
4098 #  endif
4099 		    options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4100 		}
4101 # endif
4102 		if (do_srr)
4103 		{
4104 		    p_srr = (char_u *)">%s 2>&1";
4105 		    options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4106 		}
4107 	    }
4108 	vim_free(p);
4109     }
4110 #endif
4111 
4112 #if defined(MSWIN)
4113     /*
4114      * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4115      * 'shell' option.
4116      * This is done after other initializations, where 'shell' might have been
4117      * set, but only if they have not been set before.  Default for p_shcf is
4118      * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
4119      * "-c" and "\"".  And for Win32 we need to set p_sxq instead.
4120      */
4121     if (strstr((char *)gettail(p_sh), "sh") != NULL)
4122     {
4123 	int	idx3;
4124 
4125 	idx3 = findoption((char_u *)"shcf");
4126 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4127 	{
4128 	    p_shcf = (char_u *)"-c";
4129 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
4130 	}
4131 
4132 	/* Somehow Win32 requires the quotes around the redirection too */
4133 	idx3 = findoption((char_u *)"sxq");
4134 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4135 	{
4136 	    p_sxq = (char_u *)"\"";
4137 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
4138 	}
4139     }
4140     else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4141     {
4142 	int	idx3;
4143 
4144 	/*
4145 	 * cmd.exe on Windows will strip the first and last double quote given
4146 	 * on the command line, e.g. most of the time things like:
4147 	 *   cmd /c "my path/to/echo" "my args to echo"
4148 	 * become:
4149 	 *   my path/to/echo" "my args to echo
4150 	 * when executed.
4151 	 *
4152 	 * To avoid this, set shellxquote to surround the command in
4153 	 * parenthesis.  This appears to make most commands work, without
4154 	 * breaking commands that worked previously, such as
4155 	 * '"path with spaces/cmd" "a&b"'.
4156 	 */
4157 	idx3 = findoption((char_u *)"sxq");
4158 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4159 	{
4160 	    p_sxq = (char_u *)"(";
4161 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
4162 	}
4163 
4164 	idx3 = findoption((char_u *)"shcf");
4165 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4166 	{
4167 	    p_shcf = (char_u *)"/c";
4168 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
4169 	}
4170     }
4171 #endif
4172 
4173     if (BUFEMPTY())
4174     {
4175 	int idx_ffs = findoption((char_u *)"ffs");
4176 
4177 	/* Apply the first entry of 'fileformats' to the initial buffer. */
4178 	if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4179 	    set_fileformat(default_fileformat(), OPT_LOCAL);
4180     }
4181 
4182 #ifdef FEAT_TITLE
4183     set_title_defaults();
4184 #endif
4185 }
4186 
4187 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
4188 /*
4189  * When 'helplang' is still at its default value, set it to "lang".
4190  * Only the first two characters of "lang" are used.
4191  */
4192     void
4193 set_helplang_default(char_u *lang)
4194 {
4195     int		idx;
4196 
4197     if (lang == NULL || STRLEN(lang) < 2)	/* safety check */
4198 	return;
4199     idx = findoption((char_u *)"hlg");
4200     if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
4201     {
4202 	if (options[idx].flags & P_ALLOCED)
4203 	    free_string_option(p_hlg);
4204 	p_hlg = vim_strsave(lang);
4205 	if (p_hlg == NULL)
4206 	    p_hlg = empty_option;
4207 	else
4208 	{
4209 	    // zh_CN becomes "cn", zh_TW becomes "tw"
4210 	    if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4211 	    {
4212 		p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4213 		p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4214 	    }
4215 	    // any C like setting, such as C.UTF-8, becomes "en"
4216 	    else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4217 	    {
4218 		p_hlg[0] = 'e';
4219 		p_hlg[1] = 'n';
4220 	    }
4221 	    p_hlg[2] = NUL;
4222 	}
4223 	options[idx].flags |= P_ALLOCED;
4224     }
4225 }
4226 #endif
4227 
4228 #ifdef FEAT_GUI
4229     static char_u *
4230 gui_bg_default(void)
4231 {
4232     if (gui_get_lightness(gui.back_pixel) < 127)
4233 	return (char_u *)"dark";
4234     return (char_u *)"light";
4235 }
4236 
4237 /*
4238  * Option initializations that can only be done after opening the GUI window.
4239  */
4240     void
4241 init_gui_options(void)
4242 {
4243     /* Set the 'background' option according to the lightness of the
4244      * background color, unless the user has set it already. */
4245     if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4246     {
4247 	set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4248 	highlight_changed();
4249     }
4250 }
4251 #endif
4252 
4253 #ifdef FEAT_TITLE
4254 /*
4255  * 'title' and 'icon' only default to true if they have not been set or reset
4256  * in .vimrc and we can read the old value.
4257  * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4258  * they can be reset.  This reduces startup time when using X on a remote
4259  * machine.
4260  */
4261     void
4262 set_title_defaults(void)
4263 {
4264     int	    idx1;
4265     long    val;
4266 
4267     /*
4268      * If GUI is (going to be) used, we can always set the window title and
4269      * icon name.  Saves a bit of time, because the X11 display server does
4270      * not need to be contacted.
4271      */
4272     idx1 = findoption((char_u *)"title");
4273     if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4274     {
4275 #ifdef FEAT_GUI
4276 	if (gui.starting || gui.in_use)
4277 	    val = TRUE;
4278 	else
4279 #endif
4280 	    val = mch_can_restore_title();
4281 	options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4282 	p_title = val;
4283     }
4284     idx1 = findoption((char_u *)"icon");
4285     if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4286     {
4287 #ifdef FEAT_GUI
4288 	if (gui.starting || gui.in_use)
4289 	    val = TRUE;
4290 	else
4291 #endif
4292 	    val = mch_can_restore_icon();
4293 	options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4294 	p_icon = val;
4295     }
4296 }
4297 #endif
4298 
4299 #if defined(FEAT_EVAL)
4300     static void
4301 trigger_optionsset_string(
4302 	int	opt_idx,
4303 	int	opt_flags,
4304 	char_u *oldval,
4305 	char_u *newval)
4306 {
4307     // Don't do this recursively.
4308     if (oldval != NULL && newval != NULL
4309 				    && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
4310     {
4311 	char_u buf_type[7];
4312 
4313 	sprintf((char *)buf_type, "%s",
4314 	    (opt_flags & OPT_LOCAL) ? "local" : "global");
4315 	set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4316 	set_vim_var_string(VV_OPTION_NEW, newval, -1);
4317 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4318 	apply_autocmds(EVENT_OPTIONSET,
4319 		       (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4320 	reset_v_option_vars();
4321     }
4322 }
4323 #endif
4324 
4325 /*
4326  * Parse 'arg' for option settings.
4327  *
4328  * 'arg' may be IObuff, but only when no errors can be present and option
4329  * does not need to be expanded with option_expand().
4330  * "opt_flags":
4331  * 0 for ":set"
4332  * OPT_GLOBAL   for ":setglobal"
4333  * OPT_LOCAL    for ":setlocal" and a modeline
4334  * OPT_MODELINE for a modeline
4335  * OPT_WINONLY  to only set window-local options
4336  * OPT_NOWIN	to skip setting window-local options
4337  *
4338  * returns FAIL if an error is detected, OK otherwise
4339  */
4340     int
4341 do_set(
4342     char_u	*arg,		/* option string (may be written to!) */
4343     int		opt_flags)
4344 {
4345     int		opt_idx;
4346     char	*errmsg;
4347     char	errbuf[80];
4348     char_u	*startarg;
4349     int		prefix;	/* 1: nothing, 0: "no", 2: "inv" in front of name */
4350     int		nextchar;	    /* next non-white char after option name */
4351     int		afterchar;	    /* character just after option name */
4352     int		len;
4353     int		i;
4354     varnumber_T	value;
4355     int		key;
4356     long_u	flags;		    /* flags for current option */
4357     char_u	*varp = NULL;	    /* pointer to variable for current option */
4358     int		did_show = FALSE;   /* already showed one value */
4359     int		adding;		    /* "opt+=arg" */
4360     int		prepending;	    /* "opt^=arg" */
4361     int		removing;	    /* "opt-=arg" */
4362     int		cp_val = 0;
4363     char_u	key_name[2];
4364 
4365     if (*arg == NUL)
4366     {
4367 	showoptions(0, opt_flags);
4368 	did_show = TRUE;
4369 	goto theend;
4370     }
4371 
4372     while (*arg != NUL)		/* loop to process all options */
4373     {
4374 	errmsg = NULL;
4375 	startarg = arg;		/* remember for error message */
4376 
4377 	if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4378 						&& !(opt_flags & OPT_MODELINE))
4379 	{
4380 	    /*
4381 	     * ":set all"  show all options.
4382 	     * ":set all&" set all options to their default value.
4383 	     */
4384 	    arg += 3;
4385 	    if (*arg == '&')
4386 	    {
4387 		++arg;
4388 		/* Only for :set command set global value of local options. */
4389 		set_options_default(OPT_FREE | opt_flags);
4390 		didset_options();
4391 		didset_options2();
4392 		redraw_all_later(CLEAR);
4393 	    }
4394 	    else
4395 	    {
4396 		showoptions(1, opt_flags);
4397 		did_show = TRUE;
4398 	    }
4399 	}
4400 	else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
4401 	{
4402 	    showoptions(2, opt_flags);
4403 	    show_termcodes();
4404 	    did_show = TRUE;
4405 	    arg += 7;
4406 	}
4407 	else
4408 	{
4409 	    prefix = 1;
4410 	    if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
4411 	    {
4412 		prefix = 0;
4413 		arg += 2;
4414 	    }
4415 	    else if (STRNCMP(arg, "inv", 3) == 0)
4416 	    {
4417 		prefix = 2;
4418 		arg += 3;
4419 	    }
4420 
4421 	    /* find end of name */
4422 	    key = 0;
4423 	    if (*arg == '<')
4424 	    {
4425 		opt_idx = -1;
4426 		/* look out for <t_>;> */
4427 		if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4428 		    len = 5;
4429 		else
4430 		{
4431 		    len = 1;
4432 		    while (arg[len] != NUL && arg[len] != '>')
4433 			++len;
4434 		}
4435 		if (arg[len] != '>')
4436 		{
4437 		    errmsg = e_invarg;
4438 		    goto skip;
4439 		}
4440 		arg[len] = NUL;			    /* put NUL after name */
4441 		if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4442 		    opt_idx = findoption(arg + 1);
4443 		arg[len++] = '>';		    /* restore '>' */
4444 		if (opt_idx == -1)
4445 		    key = find_key_option(arg + 1, TRUE);
4446 	    }
4447 	    else
4448 	    {
4449 		len = 0;
4450 		/*
4451 		 * The two characters after "t_" may not be alphanumeric.
4452 		 */
4453 		if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4454 		    len = 4;
4455 		else
4456 		    while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4457 			++len;
4458 		nextchar = arg[len];
4459 		arg[len] = NUL;			    /* put NUL after name */
4460 		opt_idx = findoption(arg);
4461 		arg[len] = nextchar;		    /* restore nextchar */
4462 		if (opt_idx == -1)
4463 		    key = find_key_option(arg, FALSE);
4464 	    }
4465 
4466 	    /* remember character after option name */
4467 	    afterchar = arg[len];
4468 
4469 	    /* skip white space, allow ":set ai  ?" */
4470 	    while (VIM_ISWHITE(arg[len]))
4471 		++len;
4472 
4473 	    adding = FALSE;
4474 	    prepending = FALSE;
4475 	    removing = FALSE;
4476 	    if (arg[len] != NUL && arg[len + 1] == '=')
4477 	    {
4478 		if (arg[len] == '+')
4479 		{
4480 		    adding = TRUE;		/* "+=" */
4481 		    ++len;
4482 		}
4483 		else if (arg[len] == '^')
4484 		{
4485 		    prepending = TRUE;		/* "^=" */
4486 		    ++len;
4487 		}
4488 		else if (arg[len] == '-')
4489 		{
4490 		    removing = TRUE;		/* "-=" */
4491 		    ++len;
4492 		}
4493 	    }
4494 	    nextchar = arg[len];
4495 
4496 	    if (opt_idx == -1 && key == 0)	/* found a mismatch: skip */
4497 	    {
4498 		errmsg = N_("E518: Unknown option");
4499 		goto skip;
4500 	    }
4501 
4502 	    if (opt_idx >= 0)
4503 	    {
4504 		if (options[opt_idx].var == NULL)   /* hidden option: skip */
4505 		{
4506 		    /* Only give an error message when requesting the value of
4507 		     * a hidden option, ignore setting it. */
4508 		    if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4509 			    && (!(options[opt_idx].flags & P_BOOL)
4510 				|| nextchar == '?'))
4511 			errmsg = N_("E519: Option not supported");
4512 		    goto skip;
4513 		}
4514 
4515 		flags = options[opt_idx].flags;
4516 		varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4517 	    }
4518 	    else
4519 	    {
4520 		flags = P_STRING;
4521 		if (key < 0)
4522 		{
4523 		    key_name[0] = KEY2TERMCAP0(key);
4524 		    key_name[1] = KEY2TERMCAP1(key);
4525 		}
4526 		else
4527 		{
4528 		    key_name[0] = KS_KEY;
4529 		    key_name[1] = (key & 0xff);
4530 		}
4531 	    }
4532 
4533 	    /* Skip all options that are not window-local (used when showing
4534 	     * an already loaded buffer in a window). */
4535 	    if ((opt_flags & OPT_WINONLY)
4536 			  && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4537 		goto skip;
4538 
4539 	    /* Skip all options that are window-local (used for :vimgrep). */
4540 	    if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4541 					   && options[opt_idx].var == VAR_WIN)
4542 		goto skip;
4543 
4544 	    /* Disallow changing some options from modelines. */
4545 	    if (opt_flags & OPT_MODELINE)
4546 	    {
4547 		if (flags & (P_SECURE | P_NO_ML))
4548 		{
4549 		    errmsg = _("E520: Not allowed in a modeline");
4550 		    goto skip;
4551 		}
4552 #ifdef FEAT_DIFF
4553 		/* In diff mode some options are overruled.  This avoids that
4554 		 * 'foldmethod' becomes "marker" instead of "diff" and that
4555 		 * "wrap" gets set. */
4556 		if (curwin->w_p_diff
4557 			&& opt_idx >= 0  /* shut up coverity warning */
4558 			&& (
4559 #ifdef FEAT_FOLDING
4560 			    options[opt_idx].indir == PV_FDM ||
4561 #endif
4562 			    options[opt_idx].indir == PV_WRAP))
4563 		    goto skip;
4564 #endif
4565 	    }
4566 
4567 #ifdef HAVE_SANDBOX
4568 	    /* Disallow changing some options in the sandbox */
4569 	    if (sandbox != 0 && (flags & P_SECURE))
4570 	    {
4571 		errmsg = _(e_sandbox);
4572 		goto skip;
4573 	    }
4574 #endif
4575 
4576 	    if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4577 	    {
4578 		arg += len;
4579 		cp_val = p_cp;
4580 		if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4581 		{
4582 		    if (arg[3] == 'm')	/* "opt&vim": set to Vim default */
4583 		    {
4584 			cp_val = FALSE;
4585 			arg += 3;
4586 		    }
4587 		    else		/* "opt&vi": set to Vi default */
4588 		    {
4589 			cp_val = TRUE;
4590 			arg += 2;
4591 		    }
4592 		}
4593 		if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4594 			&& arg[1] != NUL && !VIM_ISWHITE(arg[1]))
4595 		{
4596 		    errmsg = e_trailing;
4597 		    goto skip;
4598 		}
4599 	    }
4600 
4601 	    /*
4602 	     * allow '=' and ':' for hystorical reasons (MSDOS command.com
4603 	     * allows only one '=' character per "set" command line. grrr. (jw)
4604 	     */
4605 	    if (nextchar == '?'
4606 		    || (prefix == 1
4607 			&& vim_strchr((char_u *)"=:&<", nextchar) == NULL
4608 			&& !(flags & P_BOOL)))
4609 	    {
4610 		/*
4611 		 * print value
4612 		 */
4613 		if (did_show)
4614 		    msg_putchar('\n');	    /* cursor below last one */
4615 		else
4616 		{
4617 		    gotocmdline(TRUE);	    /* cursor at status line */
4618 		    did_show = TRUE;	    /* remember that we did a line */
4619 		}
4620 		if (opt_idx >= 0)
4621 		{
4622 		    showoneopt(&options[opt_idx], opt_flags);
4623 #ifdef FEAT_EVAL
4624 		    if (p_verbose > 0)
4625 		    {
4626 			/* Mention where the option was last set. */
4627 			if (varp == options[opt_idx].var)
4628 			    last_set_msg(options[opt_idx].script_ctx);
4629 			else if ((int)options[opt_idx].indir & PV_WIN)
4630 			    last_set_msg(curwin->w_p_script_ctx[
4631 				      (int)options[opt_idx].indir & PV_MASK]);
4632 			else if ((int)options[opt_idx].indir & PV_BUF)
4633 			    last_set_msg(curbuf->b_p_script_ctx[
4634 				      (int)options[opt_idx].indir & PV_MASK]);
4635 		    }
4636 #endif
4637 		}
4638 		else
4639 		{
4640 		    char_u	    *p;
4641 
4642 		    p = find_termcode(key_name);
4643 		    if (p == NULL)
4644 		    {
4645 			errmsg = N_("E846: Key code not set");
4646 			goto skip;
4647 		    }
4648 		    else
4649 			(void)show_one_termcode(key_name, p, TRUE);
4650 		}
4651 		if (nextchar != '?'
4652 			&& nextchar != NUL && !VIM_ISWHITE(afterchar))
4653 		    errmsg = e_trailing;
4654 	    }
4655 	    else
4656 	    {
4657 		int value_is_replaced = !prepending && !adding && !removing;
4658 		int value_checked = FALSE;
4659 
4660 		if (flags & P_BOOL)		    /* boolean */
4661 		{
4662 		    if (nextchar == '=' || nextchar == ':')
4663 		    {
4664 			errmsg = e_invarg;
4665 			goto skip;
4666 		    }
4667 
4668 		    /*
4669 		     * ":set opt!": invert
4670 		     * ":set opt&": reset to default value
4671 		     * ":set opt<": reset to global value
4672 		     */
4673 		    if (nextchar == '!')
4674 			value = *(int *)(varp) ^ 1;
4675 		    else if (nextchar == '&')
4676 			value = (int)(long)(long_i)options[opt_idx].def_val[
4677 						((flags & P_VI_DEF) || cp_val)
4678 						 ?  VI_DEFAULT : VIM_DEFAULT];
4679 		    else if (nextchar == '<')
4680 		    {
4681 			/* For 'autoread' -1 means to use global value. */
4682 			if ((int *)varp == &curbuf->b_p_ar
4683 						    && opt_flags == OPT_LOCAL)
4684 			    value = -1;
4685 			else
4686 			    value = *(int *)get_varp_scope(&(options[opt_idx]),
4687 								  OPT_GLOBAL);
4688 		    }
4689 		    else
4690 		    {
4691 			/*
4692 			 * ":set invopt": invert
4693 			 * ":set opt" or ":set noopt": set or reset
4694 			 */
4695 			if (nextchar != NUL && !VIM_ISWHITE(afterchar))
4696 			{
4697 			    errmsg = e_trailing;
4698 			    goto skip;
4699 			}
4700 			if (prefix == 2)	/* inv */
4701 			    value = *(int *)(varp) ^ 1;
4702 			else
4703 			    value = prefix;
4704 		    }
4705 
4706 		    errmsg = set_bool_option(opt_idx, varp, (int)value,
4707 								   opt_flags);
4708 		}
4709 		else				    /* numeric or string */
4710 		{
4711 		    if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4712 							       || prefix != 1)
4713 		    {
4714 			errmsg = e_invarg;
4715 			goto skip;
4716 		    }
4717 
4718 		    if (flags & P_NUM)		    /* numeric */
4719 		    {
4720 			/*
4721 			 * Different ways to set a number option:
4722 			 * &	    set to default value
4723 			 * <	    set to global value
4724 			 * <xx>	    accept special key codes for 'wildchar'
4725 			 * c	    accept any non-digit for 'wildchar'
4726 			 * [-]0-9   set number
4727 			 * other    error
4728 			 */
4729 			++arg;
4730 			if (nextchar == '&')
4731 			    value = (long)(long_i)options[opt_idx].def_val[
4732 						((flags & P_VI_DEF) || cp_val)
4733 						 ?  VI_DEFAULT : VIM_DEFAULT];
4734 			else if (nextchar == '<')
4735 			{
4736 			    /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4737 			     * use the global value. */
4738 			    if ((long *)varp == &curbuf->b_p_ul
4739 						    && opt_flags == OPT_LOCAL)
4740 				value = NO_LOCAL_UNDOLEVEL;
4741 			    else
4742 				value = *(long *)get_varp_scope(
4743 					     &(options[opt_idx]), OPT_GLOBAL);
4744 			}
4745 			else if (((long *)varp == &p_wc
4746 				    || (long *)varp == &p_wcm)
4747 				&& (*arg == '<'
4748 				    || *arg == '^'
4749 				    || (*arg != NUL
4750 					&& (!arg[1] || VIM_ISWHITE(arg[1]))
4751 					&& !VIM_ISDIGIT(*arg))))
4752 			{
4753 			    value = string_to_key(arg, FALSE);
4754 			    if (value == 0 && (long *)varp != &p_wcm)
4755 			    {
4756 				errmsg = e_invarg;
4757 				goto skip;
4758 			    }
4759 			}
4760 			else if (*arg == '-' || VIM_ISDIGIT(*arg))
4761 			{
4762 			    /* Allow negative (for 'undolevels'), octal and
4763 			     * hex numbers. */
4764 			    vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4765 							     &value, NULL, 0);
4766 			    if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
4767 			    {
4768 				errmsg = e_invarg;
4769 				goto skip;
4770 			    }
4771 			}
4772 			else
4773 			{
4774 			    errmsg = N_("E521: Number required after =");
4775 			    goto skip;
4776 			}
4777 
4778 			if (adding)
4779 			    value = *(long *)varp + value;
4780 			if (prepending)
4781 			    value = *(long *)varp * value;
4782 			if (removing)
4783 			    value = *(long *)varp - value;
4784 			errmsg = set_num_option(opt_idx, varp, value,
4785 					   errbuf, sizeof(errbuf), opt_flags);
4786 		    }
4787 		    else if (opt_idx >= 0)		    /* string */
4788 		    {
4789 			char_u	  *save_arg = NULL;
4790 			char_u	  *s = NULL;
4791 			char_u	  *oldval = NULL; /* previous value if *varp */
4792 			char_u	  *newval;
4793 			char_u	  *origval = NULL;
4794 #if defined(FEAT_EVAL)
4795 			char_u	  *saved_origval = NULL;
4796 			char_u	  *saved_newval = NULL;
4797 #endif
4798 			unsigned  newlen;
4799 			int	  comma;
4800 			int	  bs;
4801 			int	  new_value_alloced;	/* new string option
4802 							   was allocated */
4803 
4804 			/* When using ":set opt=val" for a global option
4805 			 * with a local value the local value will be
4806 			 * reset, use the global value here. */
4807 			if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4808 				&& ((int)options[opt_idx].indir & PV_BOTH))
4809 			    varp = options[opt_idx].var;
4810 
4811 			/* The old value is kept until we are sure that the
4812 			 * new value is valid. */
4813 			oldval = *(char_u **)varp;
4814 
4815 			/* When setting the local value of a global
4816 			 * option, the old value may be the global value. */
4817 			if (((int)options[opt_idx].indir & PV_BOTH)
4818 					       && (opt_flags & OPT_LOCAL))
4819 			    origval = *(char_u **)get_varp(
4820 						       &options[opt_idx]);
4821 			else
4822 			    origval = oldval;
4823 
4824 			if (nextchar == '&')	/* set to default val */
4825 			{
4826 			    newval = options[opt_idx].def_val[
4827 						((flags & P_VI_DEF) || cp_val)
4828 						 ?  VI_DEFAULT : VIM_DEFAULT];
4829 			    if ((char_u **)varp == &p_bg)
4830 			    {
4831 				/* guess the value of 'background' */
4832 #ifdef FEAT_GUI
4833 				if (gui.in_use)
4834 				    newval = gui_bg_default();
4835 				else
4836 #endif
4837 				    newval = term_bg_default();
4838 			    }
4839 
4840 			    /* expand environment variables and ~ (since the
4841 			     * default value was already expanded, only
4842 			     * required when an environment variable was set
4843 			     * later */
4844 			    if (newval == NULL)
4845 				newval = empty_option;
4846 			    else
4847 			    {
4848 				s = option_expand(opt_idx, newval);
4849 				if (s == NULL)
4850 				    s = newval;
4851 				newval = vim_strsave(s);
4852 			    }
4853 			    new_value_alloced = TRUE;
4854 			}
4855 			else if (nextchar == '<')	/* set to global val */
4856 			{
4857 			    newval = vim_strsave(*(char_u **)get_varp_scope(
4858 					     &(options[opt_idx]), OPT_GLOBAL));
4859 			    new_value_alloced = TRUE;
4860 			}
4861 			else
4862 			{
4863 			    ++arg;	/* jump to after the '=' or ':' */
4864 
4865 			    /*
4866 			     * Set 'keywordprg' to ":help" if an empty
4867 			     * value was passed to :set by the user.
4868 			     * Misuse errbuf[] for the resulting string.
4869 			     */
4870 			    if (varp == (char_u *)&p_kp
4871 					      && (*arg == NUL || *arg == ' '))
4872 			    {
4873 				STRCPY(errbuf, ":help");
4874 				save_arg = arg;
4875 				arg = (char_u *)errbuf;
4876 			    }
4877 			    /*
4878 			     * Convert 'backspace' number to string, for
4879 			     * adding, prepending and removing string.
4880 			     */
4881 			    else if (varp == (char_u *)&p_bs
4882 					 && VIM_ISDIGIT(**(char_u **)varp))
4883 			    {
4884 				i = getdigits((char_u **)varp);
4885 				switch (i)
4886 				{
4887 				    case 0:
4888 					*(char_u **)varp = empty_option;
4889 					break;
4890 				    case 1:
4891 					*(char_u **)varp = vim_strsave(
4892 						      (char_u *)"indent,eol");
4893 					break;
4894 				    case 2:
4895 					*(char_u **)varp = vim_strsave(
4896 						(char_u *)"indent,eol,start");
4897 					break;
4898 				}
4899 				vim_free(oldval);
4900 				if (origval == oldval)
4901 				    origval = *(char_u **)varp;
4902 				oldval = *(char_u **)varp;
4903 			    }
4904 			    /*
4905 			     * Convert 'whichwrap' number to string, for
4906 			     * backwards compatibility with Vim 3.0.
4907 			     * Misuse errbuf[] for the resulting string.
4908 			     */
4909 			    else if (varp == (char_u *)&p_ww
4910 							 && VIM_ISDIGIT(*arg))
4911 			    {
4912 				*errbuf = NUL;
4913 				i = getdigits(&arg);
4914 				if (i & 1)
4915 				    STRCAT(errbuf, "b,");
4916 				if (i & 2)
4917 				    STRCAT(errbuf, "s,");
4918 				if (i & 4)
4919 				    STRCAT(errbuf, "h,l,");
4920 				if (i & 8)
4921 				    STRCAT(errbuf, "<,>,");
4922 				if (i & 16)
4923 				    STRCAT(errbuf, "[,],");
4924 				if (*errbuf != NUL)	/* remove trailing , */
4925 				    errbuf[STRLEN(errbuf) - 1] = NUL;
4926 				save_arg = arg;
4927 				arg = (char_u *)errbuf;
4928 			    }
4929 			    /*
4930 			     * Remove '>' before 'dir' and 'bdir', for
4931 			     * backwards compatibility with version 3.0
4932 			     */
4933 			    else if (  *arg == '>'
4934 				    && (varp == (char_u *)&p_dir
4935 					    || varp == (char_u *)&p_bdir))
4936 			    {
4937 				++arg;
4938 			    }
4939 
4940 			    /*
4941 			     * Copy the new string into allocated memory.
4942 			     * Can't use set_string_option_direct(), because
4943 			     * we need to remove the backslashes.
4944 			     */
4945 			    /* get a bit too much */
4946 			    newlen = (unsigned)STRLEN(arg) + 1;
4947 			    if (adding || prepending || removing)
4948 				newlen += (unsigned)STRLEN(origval) + 1;
4949 			    newval = alloc(newlen);
4950 			    if (newval == NULL)  /* out of mem, don't change */
4951 				break;
4952 			    s = newval;
4953 
4954 			    /*
4955 			     * Copy the string, skip over escaped chars.
4956 			     * For MS-DOS and WIN32 backslashes before normal
4957 			     * file name characters are not removed, and keep
4958 			     * backslash at start, for "\\machine\path", but
4959 			     * do remove it for "\\\\machine\\path".
4960 			     * The reverse is found in ExpandOldSetting().
4961 			     */
4962 			    while (*arg && !VIM_ISWHITE(*arg))
4963 			    {
4964 				if (*arg == '\\' && arg[1] != NUL
4965 #ifdef BACKSLASH_IN_FILENAME
4966 					&& !((flags & P_EXPAND)
4967 						&& vim_isfilec(arg[1])
4968 						&& (arg[1] != '\\'
4969 						    || (s == newval
4970 							&& arg[2] != '\\')))
4971 #endif
4972 								    )
4973 				    ++arg;	/* remove backslash */
4974 				if (has_mbyte
4975 					&& (i = (*mb_ptr2len)(arg)) > 1)
4976 				{
4977 				    /* copy multibyte char */
4978 				    mch_memmove(s, arg, (size_t)i);
4979 				    arg += i;
4980 				    s += i;
4981 				}
4982 				else
4983 				    *s++ = *arg++;
4984 			    }
4985 			    *s = NUL;
4986 
4987 			    /*
4988 			     * Expand environment variables and ~.
4989 			     * Don't do it when adding without inserting a
4990 			     * comma.
4991 			     */
4992 			    if (!(adding || prepending || removing)
4993 							 || (flags & P_COMMA))
4994 			    {
4995 				s = option_expand(opt_idx, newval);
4996 				if (s != NULL)
4997 				{
4998 				    vim_free(newval);
4999 				    newlen = (unsigned)STRLEN(s) + 1;
5000 				    if (adding || prepending || removing)
5001 					newlen += (unsigned)STRLEN(origval) + 1;
5002 				    newval = alloc(newlen);
5003 				    if (newval == NULL)
5004 					break;
5005 				    STRCPY(newval, s);
5006 				}
5007 			    }
5008 
5009 			    /* locate newval[] in origval[] when removing it
5010 			     * and when adding to avoid duplicates */
5011 			    i = 0;	/* init for GCC */
5012 			    if (removing || (flags & P_NODUP))
5013 			    {
5014 				i = (int)STRLEN(newval);
5015 				bs = 0;
5016 				for (s = origval; *s; ++s)
5017 				{
5018 				    if ((!(flags & P_COMMA)
5019 						|| s == origval
5020 						|| (s[-1] == ',' && !(bs & 1)))
5021 					    && STRNCMP(s, newval, i) == 0
5022 					    && (!(flags & P_COMMA)
5023 						|| s[i] == ','
5024 						|| s[i] == NUL))
5025 					break;
5026 				    /* Count backslashes.  Only a comma with an
5027 				     * even number of backslashes or a single
5028 				     * backslash preceded by a comma before it
5029 				     * is recognized as a separator */
5030 				    if ((s > origval + 1
5031 						&& s[-1] == '\\'
5032 						&& s[-2] != ',')
5033 					    || (s == origval + 1
5034 						&& s[-1] == '\\'))
5035 
5036 					++bs;
5037 				    else
5038 					bs = 0;
5039 				}
5040 
5041 				/* do not add if already there */
5042 				if ((adding || prepending) && *s)
5043 				{
5044 				    prepending = FALSE;
5045 				    adding = FALSE;
5046 				    STRCPY(newval, origval);
5047 				}
5048 			    }
5049 
5050 			    /* concatenate the two strings; add a ',' if
5051 			     * needed */
5052 			    if (adding || prepending)
5053 			    {
5054 				comma = ((flags & P_COMMA) && *origval != NUL
5055 							   && *newval != NUL);
5056 				if (adding)
5057 				{
5058 				    i = (int)STRLEN(origval);
5059 				    /* strip a trailing comma, would get 2 */
5060 				    if (comma && i > 1
5061 					  && (flags & P_ONECOMMA) == P_ONECOMMA
5062 					  && origval[i - 1] == ','
5063 					  && origval[i - 2] != '\\')
5064 					i--;
5065 				    mch_memmove(newval + i + comma, newval,
5066 							  STRLEN(newval) + 1);
5067 				    mch_memmove(newval, origval, (size_t)i);
5068 				}
5069 				else
5070 				{
5071 				    i = (int)STRLEN(newval);
5072 				    STRMOVE(newval + i + comma, origval);
5073 				}
5074 				if (comma)
5075 				    newval[i] = ',';
5076 			    }
5077 
5078 			    /* Remove newval[] from origval[]. (Note: "i" has
5079 			     * been set above and is used here). */
5080 			    if (removing)
5081 			    {
5082 				STRCPY(newval, origval);
5083 				if (*s)
5084 				{
5085 				    /* may need to remove a comma */
5086 				    if (flags & P_COMMA)
5087 				    {
5088 					if (s == origval)
5089 					{
5090 					    /* include comma after string */
5091 					    if (s[i] == ',')
5092 						++i;
5093 					}
5094 					else
5095 					{
5096 					    /* include comma before string */
5097 					    --s;
5098 					    ++i;
5099 					}
5100 				    }
5101 				    STRMOVE(newval + (s - origval), s + i);
5102 				}
5103 			    }
5104 
5105 			    if (flags & P_FLAGLIST)
5106 			    {
5107 				/* Remove flags that appear twice. */
5108 				for (s = newval; *s;)
5109 				{
5110 				    /* if options have P_FLAGLIST and
5111 				     * P_ONECOMMA such as 'whichwrap' */
5112 				    if (flags & P_ONECOMMA)
5113 				    {
5114 					if (*s != ',' && *(s + 1) == ','
5115 					      && vim_strchr(s + 2, *s) != NULL)
5116 					{
5117 					    /* Remove the duplicated value and
5118 					     * the next comma. */
5119 					    STRMOVE(s, s + 2);
5120 					    continue;
5121 					}
5122 				    }
5123 				    else
5124 				    {
5125 					if ((!(flags & P_COMMA) || *s != ',')
5126 					      && vim_strchr(s + 1, *s) != NULL)
5127 					{
5128 					    STRMOVE(s, s + 1);
5129 					    continue;
5130 					}
5131 				    }
5132 				    ++s;
5133 				}
5134 			    }
5135 
5136 			    if (save_arg != NULL)   /* number for 'whichwrap' */
5137 				arg = save_arg;
5138 			    new_value_alloced = TRUE;
5139 			}
5140 
5141 			/*
5142 			 * Set the new value.
5143 			 */
5144 			*(char_u **)(varp) = newval;
5145 
5146 #if defined(FEAT_EVAL)
5147 			if (!starting
5148 # ifdef FEAT_CRYPT
5149 				&& options[opt_idx].indir != PV_KEY
5150 # endif
5151 					  && origval != NULL && newval != NULL)
5152 			{
5153 			    /* origval may be freed by
5154 			     * did_set_string_option(), make a copy. */
5155 			    saved_origval = vim_strsave(origval);
5156 			    /* newval (and varp) may become invalid if the
5157 			     * buffer is closed by autocommands. */
5158 			    saved_newval = vim_strsave(newval);
5159 			}
5160 #endif
5161 
5162 			{
5163 			    long_u *p = insecure_flag(opt_idx, opt_flags);
5164 			    int	    secure_saved = secure;
5165 
5166 			    // When an option is set in the sandbox, from a
5167 			    // modeline or in secure mode, then deal with side
5168 			    // effects in secure mode.  Also when the value was
5169 			    // set with the P_INSECURE flag and is not
5170 			    // completely replaced.
5171 			    if ((opt_flags & OPT_MODELINE)
5172 #ifdef HAVE_SANDBOX
5173 				  || sandbox != 0
5174 #endif
5175 				  || (!value_is_replaced && (*p & P_INSECURE)))
5176 				secure = 1;
5177 
5178 			    // Handle side effects, and set the global value
5179 			    // for ":set" on local options. Note: when setting
5180 			    // 'syntax' or 'filetype' autocommands may be
5181 			    // triggered that can cause havoc.
5182 			    errmsg = did_set_string_option(
5183 				    opt_idx, (char_u **)varp,
5184 				    new_value_alloced, oldval, errbuf,
5185 				    opt_flags, &value_checked);
5186 
5187 			    secure = secure_saved;
5188 			}
5189 
5190 #if defined(FEAT_EVAL)
5191 			if (errmsg == NULL)
5192 			    trigger_optionsset_string(opt_idx, opt_flags,
5193 						  saved_origval, saved_newval);
5194 			vim_free(saved_origval);
5195 			vim_free(saved_newval);
5196 #endif
5197 			/* If error detected, print the error message. */
5198 			if (errmsg != NULL)
5199 			    goto skip;
5200 		    }
5201 		    else	    /* key code option */
5202 		    {
5203 			char_u	    *p;
5204 
5205 			if (nextchar == '&')
5206 			{
5207 			    if (add_termcap_entry(key_name, TRUE) == FAIL)
5208 				errmsg = N_("E522: Not found in termcap");
5209 			}
5210 			else
5211 			{
5212 			    ++arg; /* jump to after the '=' or ':' */
5213 			    for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
5214 				if (*p == '\\' && p[1] != NUL)
5215 				    ++p;
5216 			    nextchar = *p;
5217 			    *p = NUL;
5218 			    add_termcode(key_name, arg, FALSE);
5219 			    *p = nextchar;
5220 			}
5221 			if (full_screen)
5222 			    ttest(FALSE);
5223 			redraw_all_later(CLEAR);
5224 		    }
5225 		}
5226 
5227 		if (opt_idx >= 0)
5228 		    did_set_option(
5229 			 opt_idx, opt_flags, value_is_replaced, value_checked);
5230 	    }
5231 
5232 skip:
5233 	    /*
5234 	     * Advance to next argument.
5235 	     * - skip until a blank found, taking care of backslashes
5236 	     * - skip blanks
5237 	     * - skip one "=val" argument (for hidden options ":set gfn =xx")
5238 	     */
5239 	    for (i = 0; i < 2 ; ++i)
5240 	    {
5241 		while (*arg != NUL && !VIM_ISWHITE(*arg))
5242 		    if (*arg++ == '\\' && *arg != NUL)
5243 			++arg;
5244 		arg = skipwhite(arg);
5245 		if (*arg != '=')
5246 		    break;
5247 	    }
5248 	}
5249 
5250 	if (errmsg != NULL)
5251 	{
5252 	    vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
5253 	    i = (int)STRLEN(IObuff) + 2;
5254 	    if (i + (arg - startarg) < IOSIZE)
5255 	    {
5256 		/* append the argument with the error */
5257 		STRCAT(IObuff, ": ");
5258 		mch_memmove(IObuff + i, startarg, (arg - startarg));
5259 		IObuff[i + (arg - startarg)] = NUL;
5260 	    }
5261 	    /* make sure all characters are printable */
5262 	    trans_characters(IObuff, IOSIZE);
5263 
5264 	    ++no_wait_return;		// wait_return done later
5265 	    emsg((char *)IObuff);	// show error highlighted
5266 	    --no_wait_return;
5267 
5268 	    return FAIL;
5269 	}
5270 
5271 	arg = skipwhite(arg);
5272     }
5273 
5274 theend:
5275     if (silent_mode && did_show)
5276     {
5277 	/* After displaying option values in silent mode. */
5278 	silent_mode = FALSE;
5279 	info_message = TRUE;	/* use mch_msg(), not mch_errmsg() */
5280 	msg_putchar('\n');
5281 	cursor_on();		/* msg_start() switches it off */
5282 	out_flush();
5283 	silent_mode = TRUE;
5284 	info_message = FALSE;	/* use mch_msg(), not mch_errmsg() */
5285     }
5286 
5287     return OK;
5288 }
5289 
5290 /*
5291  * Call this when an option has been given a new value through a user command.
5292  * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5293  */
5294     static void
5295 did_set_option(
5296     int	    opt_idx,
5297     int	    opt_flags,	    // possibly with OPT_MODELINE
5298     int	    new_value,	    // value was replaced completely
5299     int	    value_checked)  // value was checked to be safe, no need to set the
5300 			    // P_INSECURE flag.
5301 {
5302     long_u	*p;
5303 
5304     options[opt_idx].flags |= P_WAS_SET;
5305 
5306     /* When an option is set in the sandbox, from a modeline or in secure mode
5307      * set the P_INSECURE flag.  Otherwise, if a new value is stored reset the
5308      * flag. */
5309     p = insecure_flag(opt_idx, opt_flags);
5310     if (!value_checked && (secure
5311 #ifdef HAVE_SANDBOX
5312 	    || sandbox != 0
5313 #endif
5314 	    || (opt_flags & OPT_MODELINE)))
5315 	*p = *p | P_INSECURE;
5316     else if (new_value)
5317 	*p = *p & ~P_INSECURE;
5318 }
5319 
5320     static char *
5321 illegal_char(char *errbuf, int c)
5322 {
5323     if (errbuf == NULL)
5324 	return "";
5325     sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
5326 							(char *)transchar(c));
5327     return errbuf;
5328 }
5329 
5330 /*
5331  * Convert a key name or string into a key value.
5332  * Used for 'wildchar' and 'cedit' options.
5333  * When "multi_byte" is TRUE allow for multi-byte characters.
5334  */
5335     int
5336 string_to_key(char_u *arg, int multi_byte)
5337 {
5338     if (*arg == '<')
5339 	return find_key_option(arg + 1, TRUE);
5340     if (*arg == '^')
5341 	return Ctrl_chr(arg[1]);
5342     if (multi_byte)
5343 	return PTR2CHAR(arg);
5344     return *arg;
5345 }
5346 
5347 #ifdef FEAT_CMDWIN
5348 /*
5349  * Check value of 'cedit' and set cedit_key.
5350  * Returns NULL if value is OK, error message otherwise.
5351  */
5352     static char *
5353 check_cedit(void)
5354 {
5355     int n;
5356 
5357     if (*p_cedit == NUL)
5358 	cedit_key = -1;
5359     else
5360     {
5361 	n = string_to_key(p_cedit, FALSE);
5362 	if (vim_isprintc(n))
5363 	    return e_invarg;
5364 	cedit_key = n;
5365     }
5366     return NULL;
5367 }
5368 #endif
5369 
5370 #ifdef FEAT_TITLE
5371 /*
5372  * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5373  * maketitle() to create and display it.
5374  * When switching the title or icon off, call mch_restore_title() to get
5375  * the old value back.
5376  */
5377     static void
5378 did_set_title(void)
5379 {
5380     if (starting != NO_SCREEN
5381 #ifdef FEAT_GUI
5382 	    && !gui.starting
5383 #endif
5384 				)
5385 	maketitle();
5386 }
5387 #endif
5388 
5389 /*
5390  * set_options_bin -  called when 'bin' changes value.
5391  */
5392     void
5393 set_options_bin(
5394     int		oldval,
5395     int		newval,
5396     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
5397 {
5398     /*
5399      * The option values that are changed when 'bin' changes are
5400      * copied when 'bin is set and restored when 'bin' is reset.
5401      */
5402     if (newval)
5403     {
5404 	if (!oldval)		/* switched on */
5405 	{
5406 	    if (!(opt_flags & OPT_GLOBAL))
5407 	    {
5408 		curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5409 		curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5410 		curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5411 		curbuf->b_p_et_nobin = curbuf->b_p_et;
5412 	    }
5413 	    if (!(opt_flags & OPT_LOCAL))
5414 	    {
5415 		p_tw_nobin = p_tw;
5416 		p_wm_nobin = p_wm;
5417 		p_ml_nobin = p_ml;
5418 		p_et_nobin = p_et;
5419 	    }
5420 	}
5421 
5422 	if (!(opt_flags & OPT_GLOBAL))
5423 	{
5424 	    curbuf->b_p_tw = 0;	/* no automatic line wrap */
5425 	    curbuf->b_p_wm = 0;	/* no automatic line wrap */
5426 	    curbuf->b_p_ml = 0;	/* no modelines */
5427 	    curbuf->b_p_et = 0;	/* no expandtab */
5428 	}
5429 	if (!(opt_flags & OPT_LOCAL))
5430 	{
5431 	    p_tw = 0;
5432 	    p_wm = 0;
5433 	    p_ml = FALSE;
5434 	    p_et = FALSE;
5435 	    p_bin = TRUE;	/* needed when called for the "-b" argument */
5436 	}
5437     }
5438     else if (oldval)		/* switched off */
5439     {
5440 	if (!(opt_flags & OPT_GLOBAL))
5441 	{
5442 	    curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5443 	    curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5444 	    curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5445 	    curbuf->b_p_et = curbuf->b_p_et_nobin;
5446 	}
5447 	if (!(opt_flags & OPT_LOCAL))
5448 	{
5449 	    p_tw = p_tw_nobin;
5450 	    p_wm = p_wm_nobin;
5451 	    p_ml = p_ml_nobin;
5452 	    p_et = p_et_nobin;
5453 	}
5454     }
5455 }
5456 
5457 #ifdef FEAT_VIMINFO
5458 /*
5459  * Find the parameter represented by the given character (eg ', :, ", or /),
5460  * and return its associated value in the 'viminfo' string.
5461  * Only works for number parameters, not for 'r' or 'n'.
5462  * If the parameter is not specified in the string or there is no following
5463  * number, return -1.
5464  */
5465     int
5466 get_viminfo_parameter(int type)
5467 {
5468     char_u  *p;
5469 
5470     p = find_viminfo_parameter(type);
5471     if (p != NULL && VIM_ISDIGIT(*p))
5472 	return atoi((char *)p);
5473     return -1;
5474 }
5475 
5476 /*
5477  * Find the parameter represented by the given character (eg ''', ':', '"', or
5478  * '/') in the 'viminfo' option and return a pointer to the string after it.
5479  * Return NULL if the parameter is not specified in the string.
5480  */
5481     char_u *
5482 find_viminfo_parameter(int type)
5483 {
5484     char_u  *p;
5485 
5486     for (p = p_viminfo; *p; ++p)
5487     {
5488 	if (*p == type)
5489 	    return p + 1;
5490 	if (*p == 'n')		    /* 'n' is always the last one */
5491 	    break;
5492 	p = vim_strchr(p, ',');	    /* skip until next ',' */
5493 	if (p == NULL)		    /* hit the end without finding parameter */
5494 	    break;
5495     }
5496     return NULL;
5497 }
5498 #endif
5499 
5500 /*
5501  * Expand environment variables for some string options.
5502  * These string options cannot be indirect!
5503  * If "val" is NULL expand the current value of the option.
5504  * Return pointer to NameBuff, or NULL when not expanded.
5505  */
5506     static char_u *
5507 option_expand(int opt_idx, char_u *val)
5508 {
5509     /* if option doesn't need expansion nothing to do */
5510     if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5511 	return NULL;
5512 
5513     /* If val is longer than MAXPATHL no meaningful expansion can be done,
5514      * expand_env() would truncate the string. */
5515     if (val != NULL && STRLEN(val) > MAXPATHL)
5516 	return NULL;
5517 
5518     if (val == NULL)
5519 	val = *(char_u **)options[opt_idx].var;
5520 
5521     /*
5522      * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5523      * Escape spaces when expanding 'tags', they are used to separate file
5524      * names.
5525      * For 'spellsuggest' expand after "file:".
5526      */
5527     expand_env_esc(val, NameBuff, MAXPATHL,
5528 	    (char_u **)options[opt_idx].var == &p_tags, FALSE,
5529 #ifdef FEAT_SPELL
5530 	    (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5531 #endif
5532 				  NULL);
5533     if (STRCMP(NameBuff, val) == 0)   /* they are the same */
5534 	return NULL;
5535 
5536     return NameBuff;
5537 }
5538 
5539 /*
5540  * After setting various option values: recompute variables that depend on
5541  * option values.
5542  */
5543     static void
5544 didset_options(void)
5545 {
5546     /* initialize the table for 'iskeyword' et.al. */
5547     (void)init_chartab();
5548 
5549     (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5550     (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5551     (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
5552 #ifdef FEAT_SESSION
5553     (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5554     (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5555 #endif
5556 #ifdef FEAT_FOLDING
5557     (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5558 #endif
5559     (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5560     (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
5561     (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5562 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5563     (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5564 #endif
5565 #ifdef FEAT_SPELL
5566     (void)spell_check_msm();
5567     (void)spell_check_sps();
5568     (void)compile_cap_prog(curwin->w_s);
5569     (void)did_set_spell_option(TRUE);
5570 #endif
5571 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
5572     (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5573 #endif
5574 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
5575     (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5576 #endif
5577 #ifdef FEAT_CMDWIN
5578     /* set cedit_key */
5579     (void)check_cedit();
5580 #endif
5581 #ifdef FEAT_LINEBREAK
5582     briopt_check(curwin);
5583 #endif
5584 #ifdef FEAT_LINEBREAK
5585     /* initialize the table for 'breakat'. */
5586     fill_breakat_flags();
5587 #endif
5588 
5589 }
5590 
5591 /*
5592  * More side effects of setting options.
5593  */
5594     static void
5595 didset_options2(void)
5596 {
5597     /* Initialize the highlight_attr[] table. */
5598     (void)highlight_changed();
5599 
5600     /* Parse default for 'wildmode'  */
5601     check_opt_wim();
5602 
5603     (void)set_chars_option(&p_lcs);
5604     /* Parse default for 'fillchars'. */
5605     (void)set_chars_option(&p_fcs);
5606 
5607 #ifdef FEAT_CLIPBOARD
5608     /* Parse default for 'clipboard' */
5609     (void)check_clipboard_option();
5610 #endif
5611 #ifdef FEAT_VARTABS
5612     vim_free(curbuf->b_p_vsts_array);
5613     tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5614     vim_free(curbuf->b_p_vts_array);
5615     tabstop_set(curbuf->b_p_vts,  &curbuf->b_p_vts_array);
5616 #endif
5617 }
5618 
5619 /*
5620  * Check for string options that are NULL (normally only termcap options).
5621  */
5622     void
5623 check_options(void)
5624 {
5625     int		opt_idx;
5626 
5627     for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5628 	if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5629 	    check_string_option((char_u **)get_varp(&(options[opt_idx])));
5630 }
5631 
5632 /*
5633  * Check string options in a buffer for NULL value.
5634  */
5635     void
5636 check_buf_options(buf_T *buf)
5637 {
5638     check_string_option(&buf->b_p_bh);
5639     check_string_option(&buf->b_p_bt);
5640     check_string_option(&buf->b_p_fenc);
5641     check_string_option(&buf->b_p_ff);
5642 #ifdef FEAT_FIND_ID
5643     check_string_option(&buf->b_p_def);
5644     check_string_option(&buf->b_p_inc);
5645 # ifdef FEAT_EVAL
5646     check_string_option(&buf->b_p_inex);
5647 # endif
5648 #endif
5649 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5650     check_string_option(&buf->b_p_inde);
5651     check_string_option(&buf->b_p_indk);
5652 #endif
5653 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5654     check_string_option(&buf->b_p_bexpr);
5655 #endif
5656 #if defined(FEAT_CRYPT)
5657     check_string_option(&buf->b_p_cm);
5658 #endif
5659     check_string_option(&buf->b_p_fp);
5660 #if defined(FEAT_EVAL)
5661     check_string_option(&buf->b_p_fex);
5662 #endif
5663 #ifdef FEAT_CRYPT
5664     check_string_option(&buf->b_p_key);
5665 #endif
5666     check_string_option(&buf->b_p_kp);
5667     check_string_option(&buf->b_p_mps);
5668     check_string_option(&buf->b_p_fo);
5669     check_string_option(&buf->b_p_flp);
5670     check_string_option(&buf->b_p_isk);
5671 #ifdef FEAT_COMMENTS
5672     check_string_option(&buf->b_p_com);
5673 #endif
5674 #ifdef FEAT_FOLDING
5675     check_string_option(&buf->b_p_cms);
5676 #endif
5677     check_string_option(&buf->b_p_nf);
5678 #ifdef FEAT_TEXTOBJ
5679     check_string_option(&buf->b_p_qe);
5680 #endif
5681 #ifdef FEAT_SYN_HL
5682     check_string_option(&buf->b_p_syn);
5683     check_string_option(&buf->b_s.b_syn_isk);
5684 #endif
5685 #ifdef FEAT_SPELL
5686     check_string_option(&buf->b_s.b_p_spc);
5687     check_string_option(&buf->b_s.b_p_spf);
5688     check_string_option(&buf->b_s.b_p_spl);
5689 #endif
5690 #ifdef FEAT_SEARCHPATH
5691     check_string_option(&buf->b_p_sua);
5692 #endif
5693 #ifdef FEAT_CINDENT
5694     check_string_option(&buf->b_p_cink);
5695     check_string_option(&buf->b_p_cino);
5696     parse_cino(buf);
5697 #endif
5698     check_string_option(&buf->b_p_ft);
5699 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5700     check_string_option(&buf->b_p_cinw);
5701 #endif
5702 #ifdef FEAT_INS_EXPAND
5703     check_string_option(&buf->b_p_cpt);
5704 #endif
5705 #ifdef FEAT_COMPL_FUNC
5706     check_string_option(&buf->b_p_cfu);
5707     check_string_option(&buf->b_p_ofu);
5708 #endif
5709 #ifdef FEAT_EVAL
5710     check_string_option(&buf->b_p_tfu);
5711 #endif
5712 #ifdef FEAT_KEYMAP
5713     check_string_option(&buf->b_p_keymap);
5714 #endif
5715 #ifdef FEAT_QUICKFIX
5716     check_string_option(&buf->b_p_gp);
5717     check_string_option(&buf->b_p_mp);
5718     check_string_option(&buf->b_p_efm);
5719 #endif
5720     check_string_option(&buf->b_p_ep);
5721     check_string_option(&buf->b_p_path);
5722     check_string_option(&buf->b_p_tags);
5723     check_string_option(&buf->b_p_tc);
5724 #ifdef FEAT_INS_EXPAND
5725     check_string_option(&buf->b_p_dict);
5726     check_string_option(&buf->b_p_tsr);
5727 #endif
5728 #ifdef FEAT_LISP
5729     check_string_option(&buf->b_p_lw);
5730 #endif
5731     check_string_option(&buf->b_p_bkc);
5732     check_string_option(&buf->b_p_menc);
5733 #ifdef FEAT_VARTABS
5734     check_string_option(&buf->b_p_vsts);
5735     check_string_option(&buf->b_p_vts);
5736 #endif
5737 }
5738 
5739 /*
5740  * Free the string allocated for an option.
5741  * Checks for the string being empty_option. This may happen if we're out of
5742  * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5743  * check_options().
5744  * Does NOT check for P_ALLOCED flag!
5745  */
5746     void
5747 free_string_option(char_u *p)
5748 {
5749     if (p != empty_option)
5750 	vim_free(p);
5751 }
5752 
5753     void
5754 clear_string_option(char_u **pp)
5755 {
5756     if (*pp != empty_option)
5757 	vim_free(*pp);
5758     *pp = empty_option;
5759 }
5760 
5761     static void
5762 check_string_option(char_u **pp)
5763 {
5764     if (*pp == NULL)
5765 	*pp = empty_option;
5766 }
5767 
5768 /*
5769  * Return the option index found by a pointer into term_strings[].
5770  * Return -1 if not found.
5771  */
5772     int
5773 get_term_opt_idx(char_u **p)
5774 {
5775     int opt_idx;
5776 
5777     for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5778 	if (options[opt_idx].var == (char_u *)p)
5779 	    return opt_idx;
5780     return -1; // cannot happen: didn't find it!
5781 }
5782 
5783 /*
5784  * Mark a terminal option as allocated, found by a pointer into term_strings[].
5785  * Return the option index or -1 if not found.
5786  */
5787     int
5788 set_term_option_alloced(char_u **p)
5789 {
5790     int		opt_idx = get_term_opt_idx(p);
5791 
5792     if (opt_idx >= 0)
5793 	options[opt_idx].flags |= P_ALLOCED;
5794     return opt_idx;
5795 }
5796 
5797 #if defined(FEAT_EVAL) || defined(PROTO)
5798 /*
5799  * Return TRUE when option "opt" was set from a modeline or in secure mode.
5800  * Return FALSE when it wasn't.
5801  * Return -1 for an unknown option.
5802  */
5803     int
5804 was_set_insecurely(char_u *opt, int opt_flags)
5805 {
5806     int	    idx = findoption(opt);
5807     long_u  *flagp;
5808 
5809     if (idx >= 0)
5810     {
5811 	flagp = insecure_flag(idx, opt_flags);
5812 	return (*flagp & P_INSECURE) != 0;
5813     }
5814     internal_error("was_set_insecurely()");
5815     return -1;
5816 }
5817 
5818 /*
5819  * Get a pointer to the flags used for the P_INSECURE flag of option
5820  * "opt_idx".  For some local options a local flags field is used.
5821  */
5822     static long_u *
5823 insecure_flag(int opt_idx, int opt_flags)
5824 {
5825     if (opt_flags & OPT_LOCAL)
5826 	switch ((int)options[opt_idx].indir)
5827 	{
5828 #ifdef FEAT_STL_OPT
5829 	    case PV_STL:	return &curwin->w_p_stl_flags;
5830 #endif
5831 #ifdef FEAT_EVAL
5832 # ifdef FEAT_FOLDING
5833 	    case PV_FDE:	return &curwin->w_p_fde_flags;
5834 	    case PV_FDT:	return &curwin->w_p_fdt_flags;
5835 # endif
5836 # ifdef FEAT_BEVAL
5837 	    case PV_BEXPR:	return &curbuf->b_p_bexpr_flags;
5838 # endif
5839 # if defined(FEAT_CINDENT)
5840 	    case PV_INDE:	return &curbuf->b_p_inde_flags;
5841 # endif
5842 	    case PV_FEX:	return &curbuf->b_p_fex_flags;
5843 # ifdef FEAT_FIND_ID
5844 	    case PV_INEX:	return &curbuf->b_p_inex_flags;
5845 # endif
5846 #endif
5847 	}
5848 
5849     /* Nothing special, return global flags field. */
5850     return &options[opt_idx].flags;
5851 }
5852 #endif
5853 
5854 #ifdef FEAT_TITLE
5855 /*
5856  * Redraw the window title and/or tab page text later.
5857  */
5858 static void redraw_titles(void)
5859 {
5860     need_maketitle = TRUE;
5861     redraw_tabline = TRUE;
5862 }
5863 #endif
5864 
5865 /*
5866  * Set a string option to a new value (without checking the effect).
5867  * The string is copied into allocated memory.
5868  * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
5869  * When "set_sid" is zero set the scriptID to current_sctx.sc_sid.  When
5870  * "set_sid" is SID_NONE don't set the scriptID.  Otherwise set the scriptID to
5871  * "set_sid".
5872  */
5873     void
5874 set_string_option_direct(
5875     char_u	*name,
5876     int		opt_idx,
5877     char_u	*val,
5878     int		opt_flags,	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5879     int		set_sid UNUSED)
5880 {
5881     char_u	*s;
5882     char_u	**varp;
5883     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5884     int		idx = opt_idx;
5885 
5886     if (idx == -1)		/* use name */
5887     {
5888 	idx = findoption(name);
5889 	if (idx < 0)	/* not found (should not happen) */
5890 	{
5891 	    semsg(_(e_intern2), "set_string_option_direct()");
5892 	    siemsg(_("For option %s"), name);
5893 	    return;
5894 	}
5895     }
5896 
5897     if (options[idx].var == NULL)	/* can't set hidden option */
5898 	return;
5899 
5900     s = vim_strsave(val);
5901     if (s != NULL)
5902     {
5903 	varp = (char_u **)get_varp_scope(&(options[idx]),
5904 					       both ? OPT_LOCAL : opt_flags);
5905 	if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
5906 	    free_string_option(*varp);
5907 	*varp = s;
5908 
5909 	/* For buffer/window local option may also set the global value. */
5910 	if (both)
5911 	    set_string_option_global(idx, varp);
5912 
5913 	options[idx].flags |= P_ALLOCED;
5914 
5915 	/* When setting both values of a global option with a local value,
5916 	 * make the local value empty, so that the global value is used. */
5917 	if (((int)options[idx].indir & PV_BOTH) && both)
5918 	{
5919 	    free_string_option(*varp);
5920 	    *varp = empty_option;
5921 	}
5922 # ifdef FEAT_EVAL
5923 	if (set_sid != SID_NONE)
5924 	{
5925 	    sctx_T script_ctx;
5926 
5927 	    if (set_sid == 0)
5928 		script_ctx = current_sctx;
5929 	    else
5930 	    {
5931 		script_ctx.sc_sid = set_sid;
5932 		script_ctx.sc_seq = 0;
5933 		script_ctx.sc_lnum = 0;
5934 		script_ctx.sc_version = 1;
5935 	    }
5936 	    set_option_sctx_idx(idx, opt_flags, script_ctx);
5937 	}
5938 # endif
5939     }
5940 }
5941 
5942 /*
5943  * Set global value for string option when it's a local option.
5944  */
5945     static void
5946 set_string_option_global(
5947     int		opt_idx,	/* option index */
5948     char_u	**varp)		/* pointer to option variable */
5949 {
5950     char_u	**p, *s;
5951 
5952     /* the global value is always allocated */
5953     if (options[opt_idx].var == VAR_WIN)
5954 	p = (char_u **)GLOBAL_WO(varp);
5955     else
5956 	p = (char_u **)options[opt_idx].var;
5957     if (options[opt_idx].indir != PV_NONE
5958 	    && p != varp
5959 	    && (s = vim_strsave(*varp)) != NULL)
5960     {
5961 	free_string_option(*p);
5962 	*p = s;
5963     }
5964 }
5965 
5966 /*
5967  * Set a string option to a new value, and handle the effects.
5968  *
5969  * Returns NULL on success or error message on error.
5970  */
5971     static char *
5972 set_string_option(
5973     int		opt_idx,
5974     char_u	*value,
5975     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
5976 {
5977     char_u	*s;
5978     char_u	**varp;
5979     char_u	*oldval;
5980 #if defined(FEAT_EVAL)
5981     char_u	*saved_oldval = NULL;
5982     char_u	*saved_newval = NULL;
5983 #endif
5984     char	*r = NULL;
5985     int		value_checked = FALSE;
5986 
5987     if (options[opt_idx].var == NULL)	/* don't set hidden option */
5988 	return NULL;
5989 
5990     s = vim_strsave(value);
5991     if (s != NULL)
5992     {
5993 	varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5994 		(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5995 		    ? (((int)options[opt_idx].indir & PV_BOTH)
5996 			? OPT_GLOBAL : OPT_LOCAL)
5997 		    : opt_flags);
5998 	oldval = *varp;
5999 	*varp = s;
6000 
6001 #if defined(FEAT_EVAL)
6002 	if (!starting
6003 # ifdef FEAT_CRYPT
6004 		&& options[opt_idx].indir != PV_KEY
6005 # endif
6006 		)
6007 	{
6008 	    saved_oldval = vim_strsave(oldval);
6009 	    saved_newval = vim_strsave(s);
6010 	}
6011 #endif
6012 	if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6013 					   opt_flags, &value_checked)) == NULL)
6014 	    did_set_option(opt_idx, opt_flags, TRUE, value_checked);
6015 
6016 #if defined(FEAT_EVAL)
6017 	/* call autocommand after handling side effects */
6018 	if (r == NULL)
6019 	    trigger_optionsset_string(opt_idx, opt_flags,
6020 						   saved_oldval, saved_newval);
6021 	vim_free(saved_oldval);
6022 	vim_free(saved_newval);
6023 #endif
6024     }
6025     return r;
6026 }
6027 
6028 /*
6029  * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6030  * characters or characters in "allowed".
6031  */
6032     static int
6033 valid_name(char_u *val, char *allowed)
6034 {
6035     char_u *s;
6036 
6037     for (s = val; *s != NUL; ++s)
6038 	if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6039 	    return FALSE;
6040     return TRUE;
6041 }
6042 
6043 /*
6044  * Return TRUE if "val" is a valid 'filetype' name.
6045  * Also used for 'syntax' and 'keymap'.
6046  */
6047     static int
6048 valid_filetype(char_u *val)
6049 {
6050     return valid_name(val, ".-_");
6051 }
6052 
6053 #if defined(FEAT_SPELL) || defined(PROTO)
6054 /*
6055  * Return TRUE if "val" is a valid 'spellang' value.
6056  */
6057     int
6058 valid_spellang(char_u *val)
6059 {
6060     return valid_name(val, ".-_,@");
6061 }
6062 
6063 /*
6064  * Return TRUE if "val" is a valid 'spellfile' value.
6065  */
6066     static int
6067 valid_spellfile(char_u *val)
6068 {
6069     char_u *s;
6070 
6071     for (s = val; *s != NUL; ++s)
6072 	if (!vim_isfilec(*s) && *s != ',')
6073 	    return FALSE;
6074     return TRUE;
6075 }
6076 #endif
6077 
6078 /*
6079  * Handle string options that need some action to perform when changed.
6080  * Returns NULL for success, or an error message for an error.
6081  */
6082     static char *
6083 did_set_string_option(
6084     int		opt_idx,		// index in options[] table
6085     char_u	**varp,			// pointer to the option variable
6086     int		new_value_alloced,	// new value was allocated
6087     char_u	*oldval,		// previous value of the option
6088     char	*errbuf,		// buffer for errors, or NULL
6089     int		opt_flags,		// OPT_LOCAL and/or OPT_GLOBAL
6090     int		*value_checked)		// value was checked to be save, no
6091 					// need to set P_INSECURE
6092 {
6093     char	*errmsg = NULL;
6094     char_u	*s, *p;
6095     int		did_chartab = FALSE;
6096     char_u	**gvarp;
6097     long_u	free_oldval = (options[opt_idx].flags & P_ALLOCED);
6098 #ifdef FEAT_GUI
6099     /* set when changing an option that only requires a redraw in the GUI */
6100     int		redraw_gui_only = FALSE;
6101 #endif
6102     int		value_changed = FALSE;
6103 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6104     int		did_swaptcap = FALSE;
6105 #endif
6106 
6107     /* Get the global option to compare with, otherwise we would have to check
6108      * two values for all local options. */
6109     gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6110 
6111     /* Disallow changing some options from secure mode */
6112     if ((secure
6113 #ifdef HAVE_SANDBOX
6114 		|| sandbox != 0
6115 #endif
6116 		) && (options[opt_idx].flags & P_SECURE))
6117 	errmsg = e_secure;
6118 
6119     // Check for a "normal" directory or file name in some options.  Disallow a
6120     // path separator (slash and/or backslash), wildcards and characters that
6121     // are often illegal in a file name. Be more permissive if "secure" is off.
6122     else if (((options[opt_idx].flags & P_NFNAME)
6123 		    && vim_strpbrk(*varp, (char_u *)(secure
6124 			    ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
6125 	  || ((options[opt_idx].flags & P_NDNAME)
6126 		    && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
6127 	errmsg = e_invarg;
6128 
6129     /* 'term' */
6130     else if (varp == &T_NAME)
6131     {
6132 	if (T_NAME[0] == NUL)
6133 	    errmsg = N_("E529: Cannot set 'term' to empty string");
6134 #ifdef FEAT_GUI
6135 	if (gui.in_use)
6136 	    errmsg = N_("E530: Cannot change term in GUI");
6137 	else if (term_is_gui(T_NAME))
6138 	    errmsg = N_("E531: Use \":gui\" to start the GUI");
6139 #endif
6140 	else if (set_termname(T_NAME) == FAIL)
6141 	    errmsg = N_("E522: Not found in termcap");
6142 	else
6143 	{
6144 	    /* Screen colors may have changed. */
6145 	    redraw_later_clear();
6146 
6147 	    /* Both 'term' and 'ttytype' point to T_NAME, only set the
6148 	     * P_ALLOCED flag on 'term'. */
6149 	    opt_idx = findoption((char_u *)"term");
6150 	    free_oldval = (options[opt_idx].flags & P_ALLOCED);
6151 	}
6152     }
6153 
6154     /* 'backupcopy' */
6155     else if (gvarp == &p_bkc)
6156     {
6157 	char_u		*bkc = p_bkc;
6158 	unsigned int	*flags = &bkc_flags;
6159 
6160 	if (opt_flags & OPT_LOCAL)
6161 	{
6162 	    bkc = curbuf->b_p_bkc;
6163 	    flags = &curbuf->b_bkc_flags;
6164 	}
6165 
6166 	if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6167 	    /* make the local value empty: use the global value */
6168 	    *flags = 0;
6169 	else
6170 	{
6171 	    if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6172 		errmsg = e_invarg;
6173 	    if ((((int)*flags & BKC_AUTO) != 0)
6174 		    + (((int)*flags & BKC_YES) != 0)
6175 		    + (((int)*flags & BKC_NO) != 0) != 1)
6176 	    {
6177 		/* Must have exactly one of "auto", "yes"  and "no". */
6178 		(void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6179 		errmsg = e_invarg;
6180 	    }
6181 	}
6182     }
6183 
6184     /* 'backupext' and 'patchmode' */
6185     else if (varp == &p_bex || varp == &p_pm)
6186     {
6187 	if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6188 		     *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6189 	    errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
6190     }
6191 #ifdef FEAT_LINEBREAK
6192     /* 'breakindentopt' */
6193     else if (varp == &curwin->w_p_briopt)
6194     {
6195 	if (briopt_check(curwin) == FAIL)
6196 	    errmsg = e_invarg;
6197     }
6198 #endif
6199 
6200     /*
6201      * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
6202      * If the new option is invalid, use old value.  'lisp' option: refill
6203      * g_chartab[] for '-' char
6204      */
6205     else if (  varp == &p_isi
6206 	    || varp == &(curbuf->b_p_isk)
6207 	    || varp == &p_isp
6208 	    || varp == &p_isf)
6209     {
6210 	if (init_chartab() == FAIL)
6211 	{
6212 	    did_chartab = TRUE;	    /* need to restore it below */
6213 	    errmsg = e_invarg;	    /* error in value */
6214 	}
6215     }
6216 
6217     /* 'helpfile' */
6218     else if (varp == &p_hf)
6219     {
6220 	/* May compute new values for $VIM and $VIMRUNTIME */
6221 	if (didset_vim)
6222 	{
6223 	    vim_setenv((char_u *)"VIM", (char_u *)"");
6224 	    didset_vim = FALSE;
6225 	}
6226 	if (didset_vimruntime)
6227 	{
6228 	    vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6229 	    didset_vimruntime = FALSE;
6230 	}
6231     }
6232 
6233 #ifdef FEAT_SYN_HL
6234     /* 'colorcolumn' */
6235     else if (varp == &curwin->w_p_cc)
6236 	errmsg = check_colorcolumn(curwin);
6237 #endif
6238 
6239 #ifdef FEAT_MULTI_LANG
6240     /* 'helplang' */
6241     else if (varp == &p_hlg)
6242     {
6243 	/* Check for "", "ab", "ab,cd", etc. */
6244 	for (s = p_hlg; *s != NUL; s += 3)
6245 	{
6246 	    if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6247 	    {
6248 		errmsg = e_invarg;
6249 		break;
6250 	    }
6251 	    if (s[2] == NUL)
6252 		break;
6253 	}
6254     }
6255 #endif
6256 
6257     /* 'highlight' */
6258     else if (varp == &p_hl)
6259     {
6260 	if (highlight_changed() == FAIL)
6261 	    errmsg = e_invarg;	/* invalid flags */
6262     }
6263 
6264     /* 'nrformats' */
6265     else if (gvarp == &p_nf)
6266     {
6267 	if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6268 	    errmsg = e_invarg;
6269     }
6270 
6271 #ifdef FEAT_SESSION
6272     /* 'sessionoptions' */
6273     else if (varp == &p_ssop)
6274     {
6275 	if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6276 	    errmsg = e_invarg;
6277 	if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6278 	{
6279 	    /* Don't allow both "sesdir" and "curdir". */
6280 	    (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6281 	    errmsg = e_invarg;
6282 	}
6283     }
6284     /* 'viewoptions' */
6285     else if (varp == &p_vop)
6286     {
6287 	if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6288 	    errmsg = e_invarg;
6289     }
6290 #endif
6291 
6292     /* 'scrollopt' */
6293     else if (varp == &p_sbo)
6294     {
6295 	if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6296 	    errmsg = e_invarg;
6297     }
6298 
6299     /* 'ambiwidth' */
6300     else if (varp == &p_ambw || varp == &p_emoji)
6301     {
6302 	if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6303 	    errmsg = e_invarg;
6304 	else if (set_chars_option(&p_lcs) != NULL)
6305 	    errmsg = _("E834: Conflicts with value of 'listchars'");
6306 	else if (set_chars_option(&p_fcs) != NULL)
6307 	    errmsg = _("E835: Conflicts with value of 'fillchars'");
6308     }
6309 
6310     /* 'background' */
6311     else if (varp == &p_bg)
6312     {
6313 	if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6314 	{
6315 #ifdef FEAT_EVAL
6316 	    int dark = (*p_bg == 'd');
6317 #endif
6318 
6319 	    init_highlight(FALSE, FALSE);
6320 
6321 #ifdef FEAT_EVAL
6322 	    if (dark != (*p_bg == 'd')
6323 			  && get_var_value((char_u *)"g:colors_name") != NULL)
6324 	    {
6325 		/* The color scheme must have set 'background' back to another
6326 		 * value, that's not what we want here.  Disable the color
6327 		 * scheme and set the colors again. */
6328 		do_unlet((char_u *)"g:colors_name", TRUE);
6329 		free_string_option(p_bg);
6330 		p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6331 		check_string_option(&p_bg);
6332 		init_highlight(FALSE, FALSE);
6333 	    }
6334 #endif
6335 	}
6336 	else
6337 	    errmsg = e_invarg;
6338     }
6339 
6340     /* 'wildmode' */
6341     else if (varp == &p_wim)
6342     {
6343 	if (check_opt_wim() == FAIL)
6344 	    errmsg = e_invarg;
6345     }
6346 
6347 #ifdef FEAT_CMDL_COMPL
6348     /* 'wildoptions' */
6349     else if (varp == &p_wop)
6350     {
6351 	if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6352 	    errmsg = e_invarg;
6353     }
6354 #endif
6355 
6356 #ifdef FEAT_WAK
6357     /* 'winaltkeys' */
6358     else if (varp == &p_wak)
6359     {
6360 	if (*p_wak == NUL
6361 		|| check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6362 	    errmsg = e_invarg;
6363 # ifdef FEAT_MENU
6364 #  ifdef FEAT_GUI_MOTIF
6365 	else if (gui.in_use)
6366 	    gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6367 #  else
6368 #   ifdef FEAT_GUI_GTK
6369 	else if (gui.in_use)
6370 	    gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6371 #   endif
6372 #  endif
6373 # endif
6374     }
6375 #endif
6376 
6377     /* 'eventignore' */
6378     else if (varp == &p_ei)
6379     {
6380 	if (check_ei() == FAIL)
6381 	    errmsg = e_invarg;
6382     }
6383 
6384     /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6385     else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6386 							   || gvarp == &p_menc)
6387     {
6388 	if (gvarp == &p_fenc)
6389 	{
6390 	    if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
6391 		errmsg = e_modifiable;
6392 	    else if (vim_strchr(*varp, ',') != NULL)
6393 		/* No comma allowed in 'fileencoding'; catches confusing it
6394 		 * with 'fileencodings'. */
6395 		errmsg = e_invarg;
6396 	    else
6397 	    {
6398 #ifdef FEAT_TITLE
6399 		/* May show a "+" in the title now. */
6400 		redraw_titles();
6401 #endif
6402 		/* Add 'fileencoding' to the swap file. */
6403 		ml_setflags(curbuf);
6404 	    }
6405 	}
6406 	if (errmsg == NULL)
6407 	{
6408 	    /* canonize the value, so that STRCMP() can be used on it */
6409 	    p = enc_canonize(*varp);
6410 	    if (p != NULL)
6411 	    {
6412 		vim_free(*varp);
6413 		*varp = p;
6414 	    }
6415 	    if (varp == &p_enc)
6416 	    {
6417 		errmsg = mb_init();
6418 #ifdef FEAT_TITLE
6419 		redraw_titles();
6420 #endif
6421 	    }
6422 	}
6423 
6424 #if defined(FEAT_GUI_GTK)
6425 	if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6426 	{
6427 	    /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6428 	    if (STRCMP(p_tenc, "utf-8") != 0)
6429 		errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
6430 	}
6431 #endif
6432 
6433 	if (errmsg == NULL)
6434 	{
6435 #ifdef FEAT_KEYMAP
6436 	    /* When 'keymap' is used and 'encoding' changes, reload the keymap
6437 	     * (with another encoding). */
6438 	    if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6439 		(void)keymap_init();
6440 #endif
6441 
6442 	    /* When 'termencoding' is not empty and 'encoding' changes or when
6443 	     * 'termencoding' changes, need to setup for keyboard input and
6444 	     * display output conversion. */
6445 	    if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6446 	    {
6447 		if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6448 			|| convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6449 		{
6450 		    semsg(_("E950: Cannot convert between %s and %s"),
6451 			    p_tenc, p_enc);
6452 		    errmsg = e_invarg;
6453 		}
6454 	    }
6455 
6456 #if defined(MSWIN)
6457 	    /* $HOME may have characters in active code page. */
6458 	    if (varp == &p_enc)
6459 		init_homedir();
6460 #endif
6461 	}
6462     }
6463 
6464 #if defined(FEAT_POSTSCRIPT)
6465     else if (varp == &p_penc)
6466     {
6467 	/* Canonize printencoding if VIM standard one */
6468 	p = enc_canonize(p_penc);
6469 	if (p != NULL)
6470 	{
6471 	    vim_free(p_penc);
6472 	    p_penc = p;
6473 	}
6474 	else
6475 	{
6476 	    /* Ensure lower case and '-' for '_' */
6477 	    for (s = p_penc; *s != NUL; s++)
6478 	    {
6479 		if (*s == '_')
6480 		    *s = '-';
6481 		else
6482 		    *s = TOLOWER_ASC(*s);
6483 	    }
6484 	}
6485     }
6486 #endif
6487 
6488 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
6489     else if (varp == &p_imak)
6490     {
6491 	if (!im_xim_isvalid_imactivate())
6492 	    errmsg = e_invarg;
6493     }
6494 #endif
6495 
6496 #ifdef FEAT_KEYMAP
6497     else if (varp == &curbuf->b_p_keymap)
6498     {
6499 	if (!valid_filetype(*varp))
6500 	    errmsg = e_invarg;
6501 	else
6502 	{
6503 	    int	    secure_save = secure;
6504 
6505 	    // Reset the secure flag, since the value of 'keymap' has
6506 	    // been checked to be safe.
6507 	    secure = 0;
6508 
6509 	    // load or unload key mapping tables
6510 	    errmsg = keymap_init();
6511 
6512 	    secure = secure_save;
6513 
6514 	    // Since we check the value, there is no need to set P_INSECURE,
6515 	    // even when the value comes from a modeline.
6516 	    *value_checked = TRUE;
6517 	}
6518 
6519 	if (errmsg == NULL)
6520 	{
6521 	    if (*curbuf->b_p_keymap != NUL)
6522 	    {
6523 		/* Installed a new keymap, switch on using it. */
6524 		curbuf->b_p_iminsert = B_IMODE_LMAP;
6525 		if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6526 		    curbuf->b_p_imsearch = B_IMODE_LMAP;
6527 	    }
6528 	    else
6529 	    {
6530 		/* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6531 		if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6532 		    curbuf->b_p_iminsert = B_IMODE_NONE;
6533 		if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6534 		    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6535 	    }
6536 	    if ((opt_flags & OPT_LOCAL) == 0)
6537 	    {
6538 		set_iminsert_global();
6539 		set_imsearch_global();
6540 	    }
6541 	    status_redraw_curbuf();
6542 	}
6543     }
6544 #endif
6545 
6546     /* 'fileformat' */
6547     else if (gvarp == &p_ff)
6548     {
6549 	if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6550 	    errmsg = e_modifiable;
6551 	else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6552 	    errmsg = e_invarg;
6553 	else
6554 	{
6555 	    /* may also change 'textmode' */
6556 	    if (get_fileformat(curbuf) == EOL_DOS)
6557 		curbuf->b_p_tx = TRUE;
6558 	    else
6559 		curbuf->b_p_tx = FALSE;
6560 #ifdef FEAT_TITLE
6561 	    redraw_titles();
6562 #endif
6563 	    /* update flag in swap file */
6564 	    ml_setflags(curbuf);
6565 	    /* Redraw needed when switching to/from "mac": a CR in the text
6566 	     * will be displayed differently. */
6567 	    if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6568 		redraw_curbuf_later(NOT_VALID);
6569 	}
6570     }
6571 
6572     /* 'fileformats' */
6573     else if (varp == &p_ffs)
6574     {
6575 	if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6576 	    errmsg = e_invarg;
6577 	else
6578 	{
6579 	    /* also change 'textauto' */
6580 	    if (*p_ffs == NUL)
6581 		p_ta = FALSE;
6582 	    else
6583 		p_ta = TRUE;
6584 	}
6585     }
6586 
6587 #if defined(FEAT_CRYPT)
6588     /* 'cryptkey' */
6589     else if (gvarp == &p_key)
6590     {
6591 # if defined(FEAT_CMDHIST)
6592 	/* Make sure the ":set" command doesn't show the new value in the
6593 	 * history. */
6594 	remove_key_from_history();
6595 # endif
6596 	if (STRCMP(curbuf->b_p_key, oldval) != 0)
6597 	    /* Need to update the swapfile. */
6598 	    ml_set_crypt_key(curbuf, oldval,
6599 			      *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
6600     }
6601 
6602     else if (gvarp == &p_cm)
6603     {
6604 	if (opt_flags & OPT_LOCAL)
6605 	    p = curbuf->b_p_cm;
6606 	else
6607 	    p = p_cm;
6608 	if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6609 	    errmsg = e_invarg;
6610 	else if (crypt_self_test() == FAIL)
6611 	    errmsg = e_invarg;
6612 	else
6613 	{
6614 	    /* When setting the global value to empty, make it "zip". */
6615 	    if (*p_cm == NUL)
6616 	    {
6617 		if (new_value_alloced)
6618 		    free_string_option(p_cm);
6619 		p_cm = vim_strsave((char_u *)"zip");
6620 		new_value_alloced = TRUE;
6621 	    }
6622 	    /* When using ":set cm=name" the local value is going to be empty.
6623 	     * Do that here, otherwise the crypt functions will still use the
6624 	     * local value. */
6625 	    if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6626 	    {
6627 		free_string_option(curbuf->b_p_cm);
6628 		curbuf->b_p_cm = empty_option;
6629 	    }
6630 
6631 	    /* Need to update the swapfile when the effective method changed.
6632 	     * Set "s" to the effective old value, "p" to the effective new
6633 	     * method and compare. */
6634 	    if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6635 		s = p_cm;  /* was previously using the global value */
6636 	    else
6637 		s = oldval;
6638 	    if (*curbuf->b_p_cm == NUL)
6639 		p = p_cm;  /* is now using the global value */
6640 	    else
6641 		p = curbuf->b_p_cm;
6642 	    if (STRCMP(s, p) != 0)
6643 		ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
6644 
6645 	    /* If the global value changes need to update the swapfile for all
6646 	     * buffers using that value. */
6647 	    if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6648 	    {
6649 		buf_T	*buf;
6650 
6651 		FOR_ALL_BUFFERS(buf)
6652 		    if (buf != curbuf && *buf->b_p_cm == NUL)
6653 			ml_set_crypt_key(buf, buf->b_p_key, oldval);
6654 	    }
6655 	}
6656     }
6657 #endif
6658 
6659     /* 'matchpairs' */
6660     else if (gvarp == &p_mps)
6661     {
6662 	if (has_mbyte)
6663 	{
6664 	    for (p = *varp; *p != NUL; ++p)
6665 	    {
6666 		int x2 = -1;
6667 		int x3 = -1;
6668 
6669 		if (*p != NUL)
6670 		    p += mb_ptr2len(p);
6671 		if (*p != NUL)
6672 		    x2 = *p++;
6673 		if (*p != NUL)
6674 		{
6675 		    x3 = mb_ptr2char(p);
6676 		    p += mb_ptr2len(p);
6677 		}
6678 		if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
6679 		{
6680 		    errmsg = e_invarg;
6681 		    break;
6682 		}
6683 		if (*p == NUL)
6684 		    break;
6685 	    }
6686 	}
6687 	else
6688 	{
6689 	    /* Check for "x:y,x:y" */
6690 	    for (p = *varp; *p != NUL; p += 4)
6691 	    {
6692 		if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6693 		{
6694 		    errmsg = e_invarg;
6695 		    break;
6696 		}
6697 		if (p[3] == NUL)
6698 		    break;
6699 	    }
6700 	}
6701     }
6702 
6703 #ifdef FEAT_COMMENTS
6704     /* 'comments' */
6705     else if (gvarp == &p_com)
6706     {
6707 	for (s = *varp; *s; )
6708 	{
6709 	    while (*s && *s != ':')
6710 	    {
6711 		if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6712 					     && !VIM_ISDIGIT(*s) && *s != '-')
6713 		{
6714 		    errmsg = illegal_char(errbuf, *s);
6715 		    break;
6716 		}
6717 		++s;
6718 	    }
6719 	    if (*s++ == NUL)
6720 		errmsg = N_("E524: Missing colon");
6721 	    else if (*s == ',' || *s == NUL)
6722 		errmsg = N_("E525: Zero length string");
6723 	    if (errmsg != NULL)
6724 		break;
6725 	    while (*s && *s != ',')
6726 	    {
6727 		if (*s == '\\' && s[1] != NUL)
6728 		    ++s;
6729 		++s;
6730 	    }
6731 	    s = skip_to_option_part(s);
6732 	}
6733     }
6734 #endif
6735 
6736     /* 'listchars' */
6737     else if (varp == &p_lcs)
6738     {
6739 	errmsg = set_chars_option(varp);
6740     }
6741 
6742     /* 'fillchars' */
6743     else if (varp == &p_fcs)
6744     {
6745 	errmsg = set_chars_option(varp);
6746     }
6747 
6748 #ifdef FEAT_CMDWIN
6749     /* 'cedit' */
6750     else if (varp == &p_cedit)
6751     {
6752 	errmsg = check_cedit();
6753     }
6754 #endif
6755 
6756     /* 'verbosefile' */
6757     else if (varp == &p_vfile)
6758     {
6759 	verbose_stop();
6760 	if (*p_vfile != NUL && verbose_open() == FAIL)
6761 	    errmsg = e_invarg;
6762     }
6763 
6764 #ifdef FEAT_VIMINFO
6765     /* 'viminfo' */
6766     else if (varp == &p_viminfo)
6767     {
6768 	for (s = p_viminfo; *s;)
6769 	{
6770 	    /* Check it's a valid character */
6771 	    if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6772 	    {
6773 		errmsg = illegal_char(errbuf, *s);
6774 		break;
6775 	    }
6776 	    if (*s == 'n')	/* name is always last one */
6777 		break;
6778 	    else if (*s == 'r') /* skip until next ',' */
6779 	    {
6780 		while (*++s && *s != ',')
6781 		    ;
6782 	    }
6783 	    else if (*s == '%')
6784 	    {
6785 		/* optional number */
6786 		while (vim_isdigit(*++s))
6787 		    ;
6788 	    }
6789 	    else if (*s == '!' || *s == 'h' || *s == 'c')
6790 		++s;		/* no extra chars */
6791 	    else		/* must have a number */
6792 	    {
6793 		while (vim_isdigit(*++s))
6794 		    ;
6795 
6796 		if (!VIM_ISDIGIT(*(s - 1)))
6797 		{
6798 		    if (errbuf != NULL)
6799 		    {
6800 			sprintf(errbuf, _("E526: Missing number after <%s>"),
6801 						    transchar_byte(*(s - 1)));
6802 			errmsg = errbuf;
6803 		    }
6804 		    else
6805 			errmsg = "";
6806 		    break;
6807 		}
6808 	    }
6809 	    if (*s == ',')
6810 		++s;
6811 	    else if (*s)
6812 	    {
6813 		if (errbuf != NULL)
6814 		    errmsg = N_("E527: Missing comma");
6815 		else
6816 		    errmsg = "";
6817 		break;
6818 	    }
6819 	}
6820 	if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6821 	    errmsg = N_("E528: Must specify a ' value");
6822     }
6823 #endif /* FEAT_VIMINFO */
6824 
6825     /* terminal options */
6826     else if (istermoption(&options[opt_idx]) && full_screen)
6827     {
6828 	/* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6829 	if (varp == &T_CCO)
6830 	{
6831 	    int colors = atoi((char *)T_CCO);
6832 
6833 	    /* Only reinitialize colors if t_Co value has really changed to
6834 	     * avoid expensive reload of colorscheme if t_Co is set to the
6835 	     * same value multiple times. */
6836 	    if (colors != t_colors)
6837 	    {
6838 		t_colors = colors;
6839 		if (t_colors <= 1)
6840 		{
6841 		    if (new_value_alloced)
6842 			vim_free(T_CCO);
6843 		    T_CCO = empty_option;
6844 		}
6845 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6846 		if (is_term_win32())
6847 		{
6848 		    swap_tcap();
6849 		    did_swaptcap = TRUE;
6850 		}
6851 #endif
6852 		/* We now have a different color setup, initialize it again. */
6853 		init_highlight(TRUE, FALSE);
6854 	    }
6855 	}
6856 	ttest(FALSE);
6857 	if (varp == &T_ME)
6858 	{
6859 	    out_str(T_ME);
6860 	    redraw_later(CLEAR);
6861 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
6862 	    /* Since t_me has been set, this probably means that the user
6863 	     * wants to use this as default colors.  Need to reset default
6864 	     * background/foreground colors. */
6865 # ifdef VIMDLL
6866 	    if (!gui.in_use && !gui.starting)
6867 # endif
6868 		mch_set_normal_colors();
6869 #endif
6870 	}
6871 	if (varp == &T_BE && termcap_active)
6872 	{
6873 	    if (*T_BE == NUL)
6874 		/* When clearing t_BE we assume the user no longer wants
6875 		 * bracketed paste, thus disable it by writing t_BD. */
6876 		out_str(T_BD);
6877 	    else
6878 		out_str(T_BE);
6879 	}
6880     }
6881 
6882 #ifdef FEAT_LINEBREAK
6883     /* 'showbreak' */
6884     else if (varp == &p_sbr)
6885     {
6886 	for (s = p_sbr; *s; )
6887 	{
6888 	    if (ptr2cells(s) != 1)
6889 		errmsg = N_("E595: contains unprintable or wide character");
6890 	    MB_PTR_ADV(s);
6891 	}
6892     }
6893 #endif
6894 
6895 #ifdef FEAT_GUI
6896     /* 'guifont' */
6897     else if (varp == &p_guifont)
6898     {
6899 	if (gui.in_use)
6900 	{
6901 	    p = p_guifont;
6902 # if defined(FEAT_GUI_GTK)
6903 	    /*
6904 	     * Put up a font dialog and let the user select a new value.
6905 	     * If this is cancelled go back to the old value but don't
6906 	     * give an error message.
6907 	     */
6908 	    if (STRCMP(p, "*") == 0)
6909 	    {
6910 		p = gui_mch_font_dialog(oldval);
6911 
6912 		if (new_value_alloced)
6913 		    free_string_option(p_guifont);
6914 
6915 		p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6916 		new_value_alloced = TRUE;
6917 	    }
6918 # endif
6919 	    if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6920 	    {
6921 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6922 		if (STRCMP(p_guifont, "*") == 0)
6923 		{
6924 		    /* Dialog was cancelled: Keep the old value without giving
6925 		     * an error message. */
6926 		    if (new_value_alloced)
6927 			free_string_option(p_guifont);
6928 		    p_guifont = vim_strsave(oldval);
6929 		    new_value_alloced = TRUE;
6930 		}
6931 		else
6932 # endif
6933 		    errmsg = N_("E596: Invalid font(s)");
6934 	    }
6935 	}
6936 	redraw_gui_only = TRUE;
6937     }
6938 # ifdef FEAT_XFONTSET
6939     else if (varp == &p_guifontset)
6940     {
6941 	if (STRCMP(p_guifontset, "*") == 0)
6942 	    errmsg = N_("E597: can't select fontset");
6943 	else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6944 	    errmsg = N_("E598: Invalid fontset");
6945 	redraw_gui_only = TRUE;
6946     }
6947 # endif
6948     else if (varp == &p_guifontwide)
6949     {
6950 	if (STRCMP(p_guifontwide, "*") == 0)
6951 	    errmsg = N_("E533: can't select wide font");
6952 	else if (gui_get_wide_font() == FAIL)
6953 	    errmsg = N_("E534: Invalid wide font");
6954 	redraw_gui_only = TRUE;
6955     }
6956 #endif
6957 
6958 #ifdef CURSOR_SHAPE
6959     /* 'guicursor' */
6960     else if (varp == &p_guicursor)
6961 	errmsg = parse_shape_opt(SHAPE_CURSOR);
6962 #endif
6963 
6964 #ifdef FEAT_MOUSESHAPE
6965     /* 'mouseshape' */
6966     else if (varp == &p_mouseshape)
6967     {
6968 	errmsg = parse_shape_opt(SHAPE_MOUSE);
6969 	update_mouseshape(-1);
6970     }
6971 #endif
6972 
6973 #ifdef FEAT_PRINTER
6974     else if (varp == &p_popt)
6975 	errmsg = parse_printoptions();
6976 # if defined(FEAT_POSTSCRIPT)
6977     else if (varp == &p_pmfn)
6978 	errmsg = parse_printmbfont();
6979 # endif
6980 #endif
6981 
6982 #ifdef FEAT_LANGMAP
6983     /* 'langmap' */
6984     else if (varp == &p_langmap)
6985 	langmap_set();
6986 #endif
6987 
6988 #ifdef FEAT_LINEBREAK
6989     /* 'breakat' */
6990     else if (varp == &p_breakat)
6991 	fill_breakat_flags();
6992 #endif
6993 
6994 #ifdef FEAT_TITLE
6995     /* 'titlestring' and 'iconstring' */
6996     else if (varp == &p_titlestring || varp == &p_iconstring)
6997     {
6998 # ifdef FEAT_STL_OPT
6999 	int	flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7000 
7001 	/* NULL => statusline syntax */
7002 	if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7003 	    stl_syntax |= flagval;
7004 	else
7005 	    stl_syntax &= ~flagval;
7006 # endif
7007 	did_set_title();
7008     }
7009 #endif
7010 
7011 #ifdef FEAT_GUI
7012     /* 'guioptions' */
7013     else if (varp == &p_go)
7014     {
7015 	gui_init_which_components(oldval);
7016 	redraw_gui_only = TRUE;
7017     }
7018 #endif
7019 
7020 #if defined(FEAT_GUI_TABLINE)
7021     /* 'guitablabel' */
7022     else if (varp == &p_gtl)
7023     {
7024 	redraw_tabline = TRUE;
7025 	redraw_gui_only = TRUE;
7026     }
7027     /* 'guitabtooltip' */
7028     else if (varp == &p_gtt)
7029     {
7030 	redraw_gui_only = TRUE;
7031     }
7032 #endif
7033 
7034 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7035     /* 'ttymouse' */
7036     else if (varp == &p_ttym)
7037     {
7038 	/* Switch the mouse off before changing the escape sequences used for
7039 	 * that. */
7040 	mch_setmouse(FALSE);
7041 	if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7042 	    errmsg = e_invarg;
7043 	else
7044 	    check_mouse_termcode();
7045 	if (termcap_active)
7046 	    setmouse();		/* may switch it on again */
7047     }
7048 #endif
7049 
7050     /* 'selection' */
7051     else if (varp == &p_sel)
7052     {
7053 	if (*p_sel == NUL
7054 		|| check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7055 	    errmsg = e_invarg;
7056     }
7057 
7058     /* 'selectmode' */
7059     else if (varp == &p_slm)
7060     {
7061 	if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7062 	    errmsg = e_invarg;
7063     }
7064 
7065 #ifdef FEAT_BROWSE
7066     /* 'browsedir' */
7067     else if (varp == &p_bsdir)
7068     {
7069 	if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7070 		&& !mch_isdir(p_bsdir))
7071 	    errmsg = e_invarg;
7072     }
7073 #endif
7074 
7075     /* 'keymodel' */
7076     else if (varp == &p_km)
7077     {
7078 	if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7079 	    errmsg = e_invarg;
7080 	else
7081 	{
7082 	    km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7083 	    km_startsel = (vim_strchr(p_km, 'a') != NULL);
7084 	}
7085     }
7086 
7087     /* 'mousemodel' */
7088     else if (varp == &p_mousem)
7089     {
7090 	if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7091 	    errmsg = e_invarg;
7092 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7093 	else if (*p_mousem != *oldval)
7094 	    /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7095 	     * to create or delete the popup menus. */
7096 	    gui_motif_update_mousemodel(root_menu);
7097 #endif
7098     }
7099 
7100     /* 'switchbuf' */
7101     else if (varp == &p_swb)
7102     {
7103 	if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
7104 	    errmsg = e_invarg;
7105     }
7106 
7107     /* 'debug' */
7108     else if (varp == &p_debug)
7109     {
7110 	if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
7111 	    errmsg = e_invarg;
7112     }
7113 
7114     /* 'display' */
7115     else if (varp == &p_dy)
7116     {
7117 	if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7118 	    errmsg = e_invarg;
7119 	else
7120 	    (void)init_chartab();
7121 
7122     }
7123 
7124     /* 'eadirection' */
7125     else if (varp == &p_ead)
7126     {
7127 	if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7128 	    errmsg = e_invarg;
7129     }
7130 
7131 #ifdef FEAT_CLIPBOARD
7132     /* 'clipboard' */
7133     else if (varp == &p_cb)
7134 	errmsg = check_clipboard_option();
7135 #endif
7136 
7137 #ifdef FEAT_SPELL
7138     /* When 'spelllang' or 'spellfile' is set and there is a window for this
7139      * buffer in which 'spell' is set load the wordlists. */
7140     else if (varp == &(curwin->w_s->b_p_spl)
7141 	    || varp == &(curwin->w_s->b_p_spf))
7142     {
7143 	int	is_spellfile = varp == &(curwin->w_s->b_p_spf);
7144 
7145 	if ((is_spellfile && !valid_spellfile(*varp))
7146 	    || (!is_spellfile && !valid_spellang(*varp)))
7147 	    errmsg = e_invarg;
7148 	else
7149 	    errmsg = did_set_spell_option(is_spellfile);
7150     }
7151     /* When 'spellcapcheck' is set compile the regexp program. */
7152     else if (varp == &(curwin->w_s->b_p_spc))
7153     {
7154 	errmsg = compile_cap_prog(curwin->w_s);
7155     }
7156     /* 'spellsuggest' */
7157     else if (varp == &p_sps)
7158     {
7159 	if (spell_check_sps() != OK)
7160 	    errmsg = e_invarg;
7161     }
7162     /* 'mkspellmem' */
7163     else if (varp == &p_msm)
7164     {
7165 	if (spell_check_msm() != OK)
7166 	    errmsg = e_invarg;
7167     }
7168 #endif
7169 
7170     /* When 'bufhidden' is set, check for valid value. */
7171     else if (gvarp == &p_bh)
7172     {
7173 	if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7174 	    errmsg = e_invarg;
7175     }
7176 
7177     /* When 'buftype' is set, check for valid value. */
7178     else if (gvarp == &p_bt)
7179     {
7180 	if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7181 	    errmsg = e_invarg;
7182 	else
7183 	{
7184 	    if (curwin->w_status_height)
7185 	    {
7186 		curwin->w_redr_status = TRUE;
7187 		redraw_later(VALID);
7188 	    }
7189 	    curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
7190 #ifdef FEAT_TITLE
7191 	    redraw_titles();
7192 #endif
7193 	}
7194     }
7195 
7196 #ifdef FEAT_STL_OPT
7197     /* 'statusline' or 'rulerformat' */
7198     else if (gvarp == &p_stl || varp == &p_ruf)
7199     {
7200 	int wid;
7201 
7202 	if (varp == &p_ruf)	/* reset ru_wid first */
7203 	    ru_wid = 0;
7204 	s = *varp;
7205 	if (varp == &p_ruf && *s == '%')
7206 	{
7207 	    /* set ru_wid if 'ruf' starts with "%99(" */
7208 	    if (*++s == '-')	/* ignore a '-' */
7209 		s++;
7210 	    wid = getdigits(&s);
7211 	    if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7212 		ru_wid = wid;
7213 	    else
7214 		errmsg = check_stl_option(p_ruf);
7215 	}
7216 	/* check 'statusline' only if it doesn't start with "%!" */
7217 	else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
7218 	    errmsg = check_stl_option(s);
7219 	if (varp == &p_ruf && errmsg == NULL)
7220 	    comp_col();
7221     }
7222 #endif
7223 
7224 #ifdef FEAT_INS_EXPAND
7225     /* check if it is a valid value for 'complete' -- Acevedo */
7226     else if (gvarp == &p_cpt)
7227     {
7228 	for (s = *varp; *s;)
7229 	{
7230 	    while (*s == ',' || *s == ' ')
7231 		s++;
7232 	    if (!*s)
7233 		break;
7234 	    if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7235 	    {
7236 		errmsg = illegal_char(errbuf, *s);
7237 		break;
7238 	    }
7239 	    if (*++s != NUL && *s != ',' && *s != ' ')
7240 	    {
7241 		if (s[-1] == 'k' || s[-1] == 's')
7242 		{
7243 		    /* skip optional filename after 'k' and 's' */
7244 		    while (*s && *s != ',' && *s != ' ')
7245 		    {
7246 			if (*s == '\\' && s[1] != NUL)
7247 			    ++s;
7248 			++s;
7249 		    }
7250 		}
7251 		else
7252 		{
7253 		    if (errbuf != NULL)
7254 		    {
7255 			sprintf((char *)errbuf,
7256 				     _("E535: Illegal character after <%c>"),
7257 				     *--s);
7258 			errmsg = errbuf;
7259 		    }
7260 		    else
7261 			errmsg = "";
7262 		    break;
7263 		}
7264 	    }
7265 	}
7266     }
7267 
7268     /* 'completeopt' */
7269     else if (varp == &p_cot)
7270     {
7271 	if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7272 	    errmsg = e_invarg;
7273 	else
7274 	    completeopt_was_set();
7275     }
7276 #endif /* FEAT_INS_EXPAND */
7277 
7278 #ifdef FEAT_SIGNS
7279     /* 'signcolumn' */
7280     else if (varp == &curwin->w_p_scl)
7281     {
7282 	if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7283 	    errmsg = e_invarg;
7284     }
7285 #endif
7286 
7287 
7288 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
7289     /* 'toolbar' */
7290     else if (varp == &p_toolbar)
7291     {
7292 	if (opt_strings_flags(p_toolbar, p_toolbar_values,
7293 			      &toolbar_flags, TRUE) != OK)
7294 	    errmsg = e_invarg;
7295 	else
7296 	{
7297 	    out_flush();
7298 	    gui_mch_show_toolbar((toolbar_flags &
7299 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7300 	}
7301     }
7302 #endif
7303 
7304 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
7305     /* 'toolbariconsize': GTK+ 2 only */
7306     else if (varp == &p_tbis)
7307     {
7308 	if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7309 	    errmsg = e_invarg;
7310 	else
7311 	{
7312 	    out_flush();
7313 	    gui_mch_show_toolbar((toolbar_flags &
7314 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7315 	}
7316     }
7317 #endif
7318 
7319     /* 'pastetoggle': translate key codes like in a mapping */
7320     else if (varp == &p_pt)
7321     {
7322 	if (*p_pt)
7323 	{
7324 	    (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
7325 	    if (p != NULL)
7326 	    {
7327 		if (new_value_alloced)
7328 		    free_string_option(p_pt);
7329 		p_pt = p;
7330 		new_value_alloced = TRUE;
7331 	    }
7332 	}
7333     }
7334 
7335     /* 'backspace' */
7336     else if (varp == &p_bs)
7337     {
7338 	if (VIM_ISDIGIT(*p_bs))
7339 	{
7340 	    if (*p_bs > '2' || p_bs[1] != NUL)
7341 		errmsg = e_invarg;
7342 	}
7343 	else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7344 	    errmsg = e_invarg;
7345     }
7346     else if (varp == &p_bo)
7347     {
7348 	if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7349 	    errmsg = e_invarg;
7350     }
7351 
7352     /* 'tagcase' */
7353     else if (gvarp == &p_tc)
7354     {
7355 	unsigned int	*flags;
7356 
7357 	if (opt_flags & OPT_LOCAL)
7358 	{
7359 	    p = curbuf->b_p_tc;
7360 	    flags = &curbuf->b_tc_flags;
7361 	}
7362 	else
7363 	{
7364 	    p = p_tc;
7365 	    flags = &tc_flags;
7366 	}
7367 
7368 	if ((opt_flags & OPT_LOCAL) && *p == NUL)
7369 	    /* make the local value empty: use the global value */
7370 	    *flags = 0;
7371 	else if (*p == NUL
7372 		|| opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7373 	    errmsg = e_invarg;
7374     }
7375 
7376     /* 'casemap' */
7377     else if (varp == &p_cmp)
7378     {
7379 	if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7380 	    errmsg = e_invarg;
7381     }
7382 
7383 #ifdef FEAT_DIFF
7384     /* 'diffopt' */
7385     else if (varp == &p_dip)
7386     {
7387 	if (diffopt_changed() == FAIL)
7388 	    errmsg = e_invarg;
7389     }
7390 #endif
7391 
7392 #ifdef FEAT_FOLDING
7393     /* 'foldmethod' */
7394     else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7395     {
7396 	if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7397 		|| *curwin->w_p_fdm == NUL)
7398 	    errmsg = e_invarg;
7399 	else
7400 	{
7401 	    foldUpdateAll(curwin);
7402 	    if (foldmethodIsDiff(curwin))
7403 		newFoldLevel();
7404 	}
7405     }
7406 # ifdef FEAT_EVAL
7407     /* 'foldexpr' */
7408     else if (varp == &curwin->w_p_fde)
7409     {
7410 	if (foldmethodIsExpr(curwin))
7411 	    foldUpdateAll(curwin);
7412     }
7413 # endif
7414     /* 'foldmarker' */
7415     else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7416     {
7417 	p = vim_strchr(*varp, ',');
7418 	if (p == NULL)
7419 	    errmsg = N_("E536: comma required");
7420 	else if (p == *varp || p[1] == NUL)
7421 	    errmsg = e_invarg;
7422 	else if (foldmethodIsMarker(curwin))
7423 	    foldUpdateAll(curwin);
7424     }
7425     /* 'commentstring' */
7426     else if (gvarp == &p_cms)
7427     {
7428 	if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7429 	    errmsg = N_("E537: 'commentstring' must be empty or contain %s");
7430     }
7431     /* 'foldopen' */
7432     else if (varp == &p_fdo)
7433     {
7434 	if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7435 	    errmsg = e_invarg;
7436     }
7437     /* 'foldclose' */
7438     else if (varp == &p_fcl)
7439     {
7440 	if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7441 	    errmsg = e_invarg;
7442     }
7443     /* 'foldignore' */
7444     else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7445     {
7446 	if (foldmethodIsIndent(curwin))
7447 	    foldUpdateAll(curwin);
7448     }
7449 #endif
7450 
7451     /* 'virtualedit' */
7452     else if (varp == &p_ve)
7453     {
7454 	if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7455 	    errmsg = e_invarg;
7456 	else if (STRCMP(p_ve, oldval) != 0)
7457 	{
7458 	    /* Recompute cursor position in case the new 've' setting
7459 	     * changes something. */
7460 	    validate_virtcol();
7461 	    coladvance(curwin->w_virtcol);
7462 	}
7463     }
7464 
7465 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7466     else if (varp == &p_csqf)
7467     {
7468 	if (p_csqf != NULL)
7469 	{
7470 	    p = p_csqf;
7471 	    while (*p != NUL)
7472 	    {
7473 		if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7474 			|| p[1] == NUL
7475 			|| vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7476 			|| (p[2] != NUL && p[2] != ','))
7477 		{
7478 		    errmsg = e_invarg;
7479 		    break;
7480 		}
7481 		else if (p[2] == NUL)
7482 		    break;
7483 		else
7484 		    p += 3;
7485 	    }
7486 	}
7487     }
7488 #endif
7489 
7490 #ifdef FEAT_CINDENT
7491     /* 'cinoptions' */
7492     else if (gvarp == &p_cino)
7493     {
7494 	/* TODO: recognize errors */
7495 	parse_cino(curbuf);
7496     }
7497 #endif
7498 
7499 #if defined(FEAT_RENDER_OPTIONS)
7500     /* 'renderoptions' */
7501     else if (varp == &p_rop)
7502     {
7503 	if (!gui_mch_set_rendering_options(p_rop))
7504 	    errmsg = e_invarg;
7505     }
7506 #endif
7507 
7508     else if (gvarp == &p_ft)
7509     {
7510 	if (!valid_filetype(*varp))
7511 	    errmsg = e_invarg;
7512 	else
7513 	{
7514 	    value_changed = STRCMP(oldval, *varp) != 0;
7515 
7516 	    // Since we check the value, there is no need to set P_INSECURE,
7517 	    // even when the value comes from a modeline.
7518 	    *value_checked = TRUE;
7519 	}
7520     }
7521 
7522 #ifdef FEAT_SYN_HL
7523     else if (gvarp == &p_syn)
7524     {
7525 	if (!valid_filetype(*varp))
7526 	    errmsg = e_invarg;
7527 	else
7528 	{
7529 	    value_changed = STRCMP(oldval, *varp) != 0;
7530 
7531 	    // Since we check the value, there is no need to set P_INSECURE,
7532 	    // even when the value comes from a modeline.
7533 	    *value_checked = TRUE;
7534 	}
7535     }
7536 #endif
7537 
7538 #ifdef FEAT_TERMINAL
7539     // 'termwinkey'
7540     else if (varp == &curwin->w_p_twk)
7541     {
7542 	if (*curwin->w_p_twk != NUL
7543 				  && string_to_key(curwin->w_p_twk, TRUE) == 0)
7544 	    errmsg = e_invarg;
7545     }
7546     // 'termwinsize'
7547     else if (varp == &curwin->w_p_tws)
7548     {
7549 	if (*curwin->w_p_tws != NUL)
7550 	{
7551 	    p = skipdigits(curwin->w_p_tws);
7552 	    if (p == curwin->w_p_tws
7553 		    || (*p != 'x' && *p != '*')
7554 		    || *skipdigits(p + 1) != NUL)
7555 		errmsg = e_invarg;
7556 	}
7557     }
7558 # if defined(MSWIN)
7559     // 'termwintype'
7560     else if (varp == &p_twt)
7561     {
7562 	if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
7563 	    errmsg = e_invarg;
7564     }
7565 # endif
7566 #endif
7567 
7568 #ifdef FEAT_VARTABS
7569     /* 'varsofttabstop' */
7570     else if (varp == &(curbuf->b_p_vsts))
7571     {
7572 	char_u *cp;
7573 
7574 	if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7575 	{
7576 	    if (curbuf->b_p_vsts_array)
7577 	    {
7578 		vim_free(curbuf->b_p_vsts_array);
7579 		curbuf->b_p_vsts_array = 0;
7580 	    }
7581 	}
7582 	else
7583 	{
7584 	    for (cp = *varp; *cp; ++cp)
7585 	    {
7586 		if (vim_isdigit(*cp))
7587 		    continue;
7588 		if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7589 		    continue;
7590 		errmsg = e_invarg;
7591 		break;
7592 	    }
7593 	    if (errmsg == NULL)
7594 	    {
7595 		int *oldarray = curbuf->b_p_vsts_array;
7596 		if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7597 		{
7598 		    if (oldarray)
7599 			vim_free(oldarray);
7600 		}
7601 		else
7602 		    errmsg = e_invarg;
7603 	    }
7604 	}
7605     }
7606 
7607     /* 'vartabstop' */
7608     else if (varp == &(curbuf->b_p_vts))
7609     {
7610 	char_u *cp;
7611 
7612 	if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7613 	{
7614 	    if (curbuf->b_p_vts_array)
7615 	    {
7616 		vim_free(curbuf->b_p_vts_array);
7617 		curbuf->b_p_vts_array = NULL;
7618 	    }
7619 	}
7620 	else
7621 	{
7622 	    for (cp = *varp; *cp; ++cp)
7623 	    {
7624 		if (vim_isdigit(*cp))
7625 		    continue;
7626 		if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7627 		    continue;
7628 		errmsg = e_invarg;
7629 		break;
7630 	    }
7631 	    if (errmsg == NULL)
7632 	    {
7633 		int *oldarray = curbuf->b_p_vts_array;
7634 
7635 		if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7636 		{
7637 		    vim_free(oldarray);
7638 #ifdef FEAT_FOLDING
7639 		    if (foldmethodIsIndent(curwin))
7640 			foldUpdateAll(curwin);
7641 #endif
7642 		}
7643 		else
7644 		    errmsg = e_invarg;
7645 	    }
7646 	}
7647     }
7648 #endif
7649 
7650     /* Options that are a list of flags. */
7651     else
7652     {
7653 	p = NULL;
7654 	if (varp == &p_ww) /* 'whichwrap' */
7655 	    p = (char_u *)WW_ALL;
7656 	if (varp == &p_shm) /* 'shortmess' */
7657 	    p = (char_u *)SHM_ALL;
7658 	else if (varp == &(p_cpo)) /* 'cpoptions' */
7659 	    p = (char_u *)CPO_ALL;
7660 	else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
7661 	    p = (char_u *)FO_ALL;
7662 #ifdef FEAT_CONCEAL
7663 	else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
7664 	    p = (char_u *)COCU_ALL;
7665 #endif
7666 	else if (varp == &p_mouse) /* 'mouse' */
7667 	{
7668 #ifdef FEAT_MOUSE
7669 	    p = (char_u *)MOUSE_ALL;
7670 #else
7671 	    if (*p_mouse != NUL)
7672 		errmsg = N_("E538: No mouse support");
7673 #endif
7674 	}
7675 #if defined(FEAT_GUI)
7676 	else if (varp == &p_go) /* 'guioptions' */
7677 	    p = (char_u *)GO_ALL;
7678 #endif
7679 	if (p != NULL)
7680 	{
7681 	    for (s = *varp; *s; ++s)
7682 		if (vim_strchr(p, *s) == NULL)
7683 		{
7684 		    errmsg = illegal_char(errbuf, *s);
7685 		    break;
7686 		}
7687 	}
7688     }
7689 
7690     /*
7691      * If error detected, restore the previous value.
7692      */
7693     if (errmsg != NULL)
7694     {
7695 	if (new_value_alloced)
7696 	    free_string_option(*varp);
7697 	*varp = oldval;
7698 	/*
7699 	 * When resetting some values, need to act on it.
7700 	 */
7701 	if (did_chartab)
7702 	    (void)init_chartab();
7703 	if (varp == &p_hl)
7704 	    (void)highlight_changed();
7705     }
7706     else
7707     {
7708 #ifdef FEAT_EVAL
7709 	/* Remember where the option was set. */
7710 	set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
7711 #endif
7712 	/*
7713 	 * Free string options that are in allocated memory.
7714 	 * Use "free_oldval", because recursiveness may change the flags under
7715 	 * our fingers (esp. init_highlight()).
7716 	 */
7717 	if (free_oldval)
7718 	    free_string_option(oldval);
7719 	if (new_value_alloced)
7720 	    options[opt_idx].flags |= P_ALLOCED;
7721 	else
7722 	    options[opt_idx].flags &= ~P_ALLOCED;
7723 
7724 	if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
7725 		&& ((int)options[opt_idx].indir & PV_BOTH))
7726 	{
7727 	    /* global option with local value set to use global value; free
7728 	     * the local value and make it empty */
7729 	    p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7730 	    free_string_option(*(char_u **)p);
7731 	    *(char_u **)p = empty_option;
7732 	}
7733 
7734 	/* May set global value for local option. */
7735 	else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7736 	    set_string_option_global(opt_idx, varp);
7737 
7738 	/*
7739 	 * Trigger the autocommand only after setting the flags.
7740 	 */
7741 #ifdef FEAT_SYN_HL
7742 	/* When 'syntax' is set, load the syntax of that name */
7743 	if (varp == &(curbuf->b_p_syn))
7744 	{
7745 	    static int syn_recursive = 0;
7746 
7747 	    ++syn_recursive;
7748 	    // Only pass TRUE for "force" when the value changed or not used
7749 	    // recursively, to avoid endless recurrence.
7750 	    apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7751 		    value_changed || syn_recursive == 1, curbuf);
7752 	    --syn_recursive;
7753 	}
7754 #endif
7755 	else if (varp == &(curbuf->b_p_ft))
7756 	{
7757 	    /* 'filetype' is set, trigger the FileType autocommand.
7758 	     * Skip this when called from a modeline and the filetype was
7759 	     * already set to this value. */
7760 	    if (!(opt_flags & OPT_MODELINE) || value_changed)
7761 	    {
7762 		static int  ft_recursive = 0;
7763 		int	    secure_save = secure;
7764 
7765 		// Reset the secure flag, since the value of 'filetype' has
7766 		// been checked to be safe.
7767 		secure = 0;
7768 
7769 		++ft_recursive;
7770 		did_filetype = TRUE;
7771 		// Only pass TRUE for "force" when the value changed or not
7772 		// used recursively, to avoid endless recurrence.
7773 		apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7774 				   value_changed || ft_recursive == 1, curbuf);
7775 		--ft_recursive;
7776 		/* Just in case the old "curbuf" is now invalid. */
7777 		if (varp != &(curbuf->b_p_ft))
7778 		    varp = NULL;
7779 
7780 		secure = secure_save;
7781 	    }
7782 	}
7783 #ifdef FEAT_SPELL
7784 	if (varp == &(curwin->w_s->b_p_spl))
7785 	{
7786 	    char_u	fname[200];
7787 	    char_u	*q = curwin->w_s->b_p_spl;
7788 
7789 	    /* Skip the first name if it is "cjk". */
7790 	    if (STRNCMP(q, "cjk,", 4) == 0)
7791 		q += 4;
7792 
7793 	    /*
7794 	     * Source the spell/LANG.vim in 'runtimepath'.
7795 	     * They could set 'spellcapcheck' depending on the language.
7796 	     * Use the first name in 'spelllang' up to '_region' or
7797 	     * '.encoding'.
7798 	     */
7799 	    for (p = q; *p != NUL; ++p)
7800 		if (!ASCII_ISALNUM(*p) && *p != '-')
7801 		    break;
7802 	    if (p > q)
7803 	    {
7804 		vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7805 							      (int)(p - q), q);
7806 		source_runtime(fname, DIP_ALL);
7807 	    }
7808 	}
7809 #endif
7810     }
7811 
7812 #ifdef FEAT_MOUSE
7813     if (varp == &p_mouse)
7814     {
7815 # ifdef FEAT_MOUSE_TTY
7816 	if (*p_mouse == NUL)
7817 	    mch_setmouse(FALSE);    /* switch mouse off */
7818 	else
7819 # endif
7820 	    setmouse();		    /* in case 'mouse' changed */
7821     }
7822 #endif
7823 
7824     if (curwin->w_curswant != MAXCOL
7825 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
7826 	curwin->w_set_curswant = TRUE;
7827 
7828 #ifdef FEAT_GUI
7829     /* check redraw when it's not a GUI option or the GUI is active. */
7830     if (!redraw_gui_only || gui.in_use)
7831 #endif
7832 	check_redraw(options[opt_idx].flags);
7833 
7834 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7835     if (did_swaptcap)
7836     {
7837 	set_termname((char_u *)"win32");
7838 	init_highlight(TRUE, FALSE);
7839     }
7840 #endif
7841 
7842     return errmsg;
7843 }
7844 
7845 #if defined(FEAT_SYN_HL) || defined(PROTO)
7846 /*
7847  * Simple int comparison function for use with qsort()
7848  */
7849     static int
7850 int_cmp(const void *a, const void *b)
7851 {
7852     return *(const int *)a - *(const int *)b;
7853 }
7854 
7855 /*
7856  * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7857  * Returns error message, NULL if it's OK.
7858  */
7859     char *
7860 check_colorcolumn(win_T *wp)
7861 {
7862     char_u	*s;
7863     int		col;
7864     int		count = 0;
7865     int		color_cols[256];
7866     int		i;
7867     int		j = 0;
7868 
7869     if (wp->w_buffer == NULL)
7870 	return NULL;  /* buffer was closed */
7871 
7872     for (s = wp->w_p_cc; *s != NUL && count < 255;)
7873     {
7874 	if (*s == '-' || *s == '+')
7875 	{
7876 	    /* -N and +N: add to 'textwidth' */
7877 	    col = (*s == '-') ? -1 : 1;
7878 	    ++s;
7879 	    if (!VIM_ISDIGIT(*s))
7880 		return e_invarg;
7881 	    col = col * getdigits(&s);
7882 	    if (wp->w_buffer->b_p_tw == 0)
7883 		goto skip;  /* 'textwidth' not set, skip this item */
7884 	    col += wp->w_buffer->b_p_tw;
7885 	    if (col < 0)
7886 		goto skip;
7887 	}
7888 	else if (VIM_ISDIGIT(*s))
7889 	    col = getdigits(&s);
7890 	else
7891 	    return e_invarg;
7892 	color_cols[count++] = col - 1;  /* 1-based to 0-based */
7893 skip:
7894 	if (*s == NUL)
7895 	    break;
7896 	if (*s != ',')
7897 	    return e_invarg;
7898 	if (*++s == NUL)
7899 	    return e_invarg;  /* illegal trailing comma as in "set cc=80," */
7900     }
7901 
7902     vim_free(wp->w_p_cc_cols);
7903     if (count == 0)
7904 	wp->w_p_cc_cols = NULL;
7905     else
7906     {
7907 	wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7908 	if (wp->w_p_cc_cols != NULL)
7909 	{
7910 	    /* sort the columns for faster usage on screen redraw inside
7911 	     * win_line() */
7912 	    qsort(color_cols, count, sizeof(int), int_cmp);
7913 
7914 	    for (i = 0; i < count; ++i)
7915 		/* skip duplicates */
7916 		if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7917 		    wp->w_p_cc_cols[j++] = color_cols[i];
7918 	    wp->w_p_cc_cols[j] = -1;  /* end marker */
7919 	}
7920     }
7921 
7922     return NULL;  /* no error */
7923 }
7924 #endif
7925 
7926 /*
7927  * Handle setting 'listchars' or 'fillchars'.
7928  * Returns error message, NULL if it's OK.
7929  */
7930     static char *
7931 set_chars_option(char_u **varp)
7932 {
7933     int		round, i, len, entries;
7934     char_u	*p, *s;
7935     int		c1 = 0, c2 = 0, c3 = 0;
7936     struct charstab
7937     {
7938 	int	*cp;
7939 	char	*name;
7940     };
7941     static struct charstab filltab[] =
7942     {
7943 	{&fill_stl,	"stl"},
7944 	{&fill_stlnc,	"stlnc"},
7945 	{&fill_vert,	"vert"},
7946 	{&fill_fold,	"fold"},
7947 	{&fill_diff,	"diff"},
7948     };
7949     static struct charstab lcstab[] =
7950     {
7951 	{&lcs_eol,	"eol"},
7952 	{&lcs_ext,	"extends"},
7953 	{&lcs_nbsp,	"nbsp"},
7954 	{&lcs_prec,	"precedes"},
7955 	{&lcs_space,	"space"},
7956 	{&lcs_tab2,	"tab"},
7957 	{&lcs_trail,	"trail"},
7958 #ifdef FEAT_CONCEAL
7959 	{&lcs_conceal,	"conceal"},
7960 #else
7961 	{NULL,		"conceal"},
7962 #endif
7963     };
7964     struct charstab *tab;
7965 
7966     if (varp == &p_lcs)
7967     {
7968 	tab = lcstab;
7969 	entries = sizeof(lcstab) / sizeof(struct charstab);
7970     }
7971     else
7972     {
7973 	tab = filltab;
7974 	entries = sizeof(filltab) / sizeof(struct charstab);
7975     }
7976 
7977     /* first round: check for valid value, second round: assign values */
7978     for (round = 0; round <= 1; ++round)
7979     {
7980 	if (round > 0)
7981 	{
7982 	    /* After checking that the value is valid: set defaults: space for
7983 	     * 'fillchars', NUL for 'listchars' */
7984 	    for (i = 0; i < entries; ++i)
7985 		if (tab[i].cp != NULL)
7986 		    *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
7987 
7988 	    if (varp == &p_lcs)
7989 	    {
7990 		lcs_tab1 = NUL;
7991 		lcs_tab3 = NUL;
7992 	    }
7993 	    else
7994 		fill_diff = '-';
7995 	}
7996 	p = *varp;
7997 	while (*p)
7998 	{
7999 	    for (i = 0; i < entries; ++i)
8000 	    {
8001 		len = (int)STRLEN(tab[i].name);
8002 		if (STRNCMP(p, tab[i].name, len) == 0
8003 			&& p[len] == ':'
8004 			&& p[len + 1] != NUL)
8005 		{
8006 		    c2 = c3 = 0;
8007 		    s = p + len + 1;
8008 		    c1 = mb_ptr2char_adv(&s);
8009 		    if (mb_char2cells(c1) > 1)
8010 			continue;
8011 		    if (tab[i].cp == &lcs_tab2)
8012 		    {
8013 			if (*s == NUL)
8014 			    continue;
8015 			c2 = mb_ptr2char_adv(&s);
8016 			if (mb_char2cells(c2) > 1)
8017 			    continue;
8018 			if (!(*s == ',' || *s == NUL))
8019 			{
8020 			    c3 = mb_ptr2char_adv(&s);
8021 			    if (mb_char2cells(c3) > 1)
8022 				continue;
8023 			}
8024 		    }
8025 
8026 		    if (*s == ',' || *s == NUL)
8027 		    {
8028 			if (round)
8029 			{
8030 			    if (tab[i].cp == &lcs_tab2)
8031 			    {
8032 				lcs_tab1 = c1;
8033 				lcs_tab2 = c2;
8034 				lcs_tab3 = c3;
8035 			    }
8036 			    else if (tab[i].cp != NULL)
8037 				*(tab[i].cp) = c1;
8038 
8039 			}
8040 			p = s;
8041 			break;
8042 		    }
8043 		}
8044 	    }
8045 
8046 	    if (i == entries)
8047 		return e_invarg;
8048 	    if (*p == ',')
8049 		++p;
8050 	}
8051     }
8052 
8053     return NULL;	/* no error */
8054 }
8055 
8056 #ifdef FEAT_STL_OPT
8057 /*
8058  * Check validity of options with the 'statusline' format.
8059  * Return error message or NULL.
8060  */
8061     char *
8062 check_stl_option(char_u *s)
8063 {
8064     int		itemcnt = 0;
8065     int		groupdepth = 0;
8066     static char errbuf[80];
8067 
8068     while (*s && itemcnt < STL_MAX_ITEM)
8069     {
8070 	/* Check for valid keys after % sequences */
8071 	while (*s && *s != '%')
8072 	    s++;
8073 	if (!*s)
8074 	    break;
8075 	s++;
8076 	if (*s != '%' && *s != ')')
8077 	    ++itemcnt;
8078 	if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8079 	{
8080 	    s++;
8081 	    continue;
8082 	}
8083 	if (*s == ')')
8084 	{
8085 	    s++;
8086 	    if (--groupdepth < 0)
8087 		break;
8088 	    continue;
8089 	}
8090 	if (*s == '-')
8091 	    s++;
8092 	while (VIM_ISDIGIT(*s))
8093 	    s++;
8094 	if (*s == STL_USER_HL)
8095 	    continue;
8096 	if (*s == '.')
8097 	{
8098 	    s++;
8099 	    while (*s && VIM_ISDIGIT(*s))
8100 		s++;
8101 	}
8102 	if (*s == '(')
8103 	{
8104 	    groupdepth++;
8105 	    continue;
8106 	}
8107 	if (vim_strchr(STL_ALL, *s) == NULL)
8108 	{
8109 	    return illegal_char(errbuf, *s);
8110 	}
8111 	if (*s == '{')
8112 	{
8113 	    s++;
8114 	    while (*s != '}' && *s)
8115 		s++;
8116 	    if (*s != '}')
8117 		return N_("E540: Unclosed expression sequence");
8118 	}
8119     }
8120     if (itemcnt >= STL_MAX_ITEM)
8121 	return N_("E541: too many items");
8122     if (groupdepth != 0)
8123 	return N_("E542: unbalanced groups");
8124     return NULL;
8125 }
8126 #endif
8127 
8128 #ifdef FEAT_CLIPBOARD
8129 /*
8130  * Extract the items in the 'clipboard' option and set global values.
8131  * Return an error message or NULL for success.
8132  */
8133     static char *
8134 check_clipboard_option(void)
8135 {
8136     int		new_unnamed = 0;
8137     int		new_autoselect_star = FALSE;
8138     int		new_autoselect_plus = FALSE;
8139     int		new_autoselectml = FALSE;
8140     int		new_html = FALSE;
8141     regprog_T	*new_exclude_prog = NULL;
8142     char	*errmsg = NULL;
8143     char_u	*p;
8144 
8145     for (p = p_cb; *p != NUL; )
8146     {
8147 	if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8148 	{
8149 	    new_unnamed |= CLIP_UNNAMED;
8150 	    p += 7;
8151 	}
8152 	else if (STRNCMP(p, "unnamedplus", 11) == 0
8153 					    && (p[11] == ',' || p[11] == NUL))
8154 	{
8155 	    new_unnamed |= CLIP_UNNAMED_PLUS;
8156 	    p += 11;
8157 	}
8158 	else if (STRNCMP(p, "autoselect", 10) == 0
8159 					    && (p[10] == ',' || p[10] == NUL))
8160 	{
8161 	    new_autoselect_star = TRUE;
8162 	    p += 10;
8163 	}
8164 	else if (STRNCMP(p, "autoselectplus", 14) == 0
8165 					    && (p[14] == ',' || p[14] == NUL))
8166 	{
8167 	    new_autoselect_plus = TRUE;
8168 	    p += 14;
8169 	}
8170 	else if (STRNCMP(p, "autoselectml", 12) == 0
8171 					    && (p[12] == ',' || p[12] == NUL))
8172 	{
8173 	    new_autoselectml = TRUE;
8174 	    p += 12;
8175 	}
8176 	else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8177 	{
8178 	    new_html = TRUE;
8179 	    p += 4;
8180 	}
8181 	else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8182 	{
8183 	    p += 8;
8184 	    new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8185 	    if (new_exclude_prog == NULL)
8186 		errmsg = e_invarg;
8187 	    break;
8188 	}
8189 	else
8190 	{
8191 	    errmsg = e_invarg;
8192 	    break;
8193 	}
8194 	if (*p == ',')
8195 	    ++p;
8196     }
8197     if (errmsg == NULL)
8198     {
8199 	clip_unnamed = new_unnamed;
8200 	clip_autoselect_star = new_autoselect_star;
8201 	clip_autoselect_plus = new_autoselect_plus;
8202 	clip_autoselectml = new_autoselectml;
8203 	clip_html = new_html;
8204 	vim_regfree(clip_exclude_prog);
8205 	clip_exclude_prog = new_exclude_prog;
8206 #ifdef FEAT_GUI_GTK
8207 	if (gui.in_use)
8208 	{
8209 	    gui_gtk_set_selection_targets();
8210 	    gui_gtk_set_dnd_targets();
8211 	}
8212 #endif
8213     }
8214     else
8215 	vim_regfree(new_exclude_prog);
8216 
8217     return errmsg;
8218 }
8219 #endif
8220 
8221 #ifdef FEAT_SPELL
8222 /*
8223  * Handle side effects of setting 'spell'.
8224  * Return an error message or NULL for success.
8225  */
8226     static char *
8227 did_set_spell_option(int is_spellfile)
8228 {
8229     char    *errmsg = NULL;
8230     win_T   *wp;
8231     int	    l;
8232 
8233     if (is_spellfile)
8234     {
8235 	l = (int)STRLEN(curwin->w_s->b_p_spf);
8236 	if (l > 0 && (l < 4
8237 			|| STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8238 	    errmsg = e_invarg;
8239     }
8240 
8241     if (errmsg == NULL)
8242     {
8243 	FOR_ALL_WINDOWS(wp)
8244 	    if (wp->w_buffer == curbuf && wp->w_p_spell)
8245 	    {
8246 		errmsg = did_set_spelllang(wp);
8247 		break;
8248 	    }
8249     }
8250     return errmsg;
8251 }
8252 
8253 /*
8254  * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8255  * Return error message when failed, NULL when OK.
8256  */
8257     static char *
8258 compile_cap_prog(synblock_T *synblock)
8259 {
8260     regprog_T   *rp = synblock->b_cap_prog;
8261     char_u	*re;
8262 
8263     if (*synblock->b_p_spc == NUL)
8264 	synblock->b_cap_prog = NULL;
8265     else
8266     {
8267 	/* Prepend a ^ so that we only match at one column */
8268 	re = concat_str((char_u *)"^", synblock->b_p_spc);
8269 	if (re != NULL)
8270 	{
8271 	    synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
8272 	    vim_free(re);
8273 	    if (synblock->b_cap_prog == NULL)
8274 	    {
8275 		synblock->b_cap_prog = rp; /* restore the previous program */
8276 		return e_invarg;
8277 	    }
8278 	}
8279     }
8280 
8281     vim_regfree(rp);
8282     return NULL;
8283 }
8284 #endif
8285 
8286 #if defined(FEAT_EVAL) || defined(PROTO)
8287 /*
8288  * Set the script_ctx for an option, taking care of setting the buffer- or
8289  * window-local value.
8290  */
8291     static void
8292 set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
8293 {
8294     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8295     int		indir = (int)options[opt_idx].indir;
8296     sctx_T	new_script_ctx = script_ctx;
8297 
8298     new_script_ctx.sc_lnum += sourcing_lnum;
8299 
8300     /* Remember where the option was set.  For local options need to do that
8301      * in the buffer or window structure. */
8302     if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
8303 	options[opt_idx].script_ctx = new_script_ctx;
8304     if (both || (opt_flags & OPT_LOCAL))
8305     {
8306 	if (indir & PV_BUF)
8307 	    curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
8308 	else if (indir & PV_WIN)
8309 	    curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
8310     }
8311 }
8312 
8313 /*
8314  * Set the script_ctx for a termcap option.
8315  * "name" must be the two character code, e.g. "RV".
8316  * When "name" is NULL use "opt_idx".
8317  */
8318     void
8319 set_term_option_sctx_idx(char *name, int opt_idx)
8320 {
8321     char_u  buf[5];
8322     int	    idx;
8323 
8324     if (name == NULL)
8325 	idx = opt_idx;
8326     else
8327     {
8328 	buf[0] = 't';
8329 	buf[1] = '_';
8330 	buf[2] = name[0];
8331 	buf[3] = name[1];
8332 	buf[4] = 0;
8333 	idx = findoption(buf);
8334     }
8335     if (idx >= 0)
8336 	set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8337 }
8338 #endif
8339 
8340 /*
8341  * Set the value of a boolean option, and take care of side effects.
8342  * Returns NULL for success, or an error message for an error.
8343  */
8344     static char *
8345 set_bool_option(
8346     int		opt_idx,		/* index in options[] table */
8347     char_u	*varp,			/* pointer to the option variable */
8348     int		value,			/* new value */
8349     int		opt_flags)		/* OPT_LOCAL and/or OPT_GLOBAL */
8350 {
8351     int		old_value = *(int *)varp;
8352 
8353     /* Disallow changing some options from secure mode */
8354     if ((secure
8355 #ifdef HAVE_SANDBOX
8356 		|| sandbox != 0
8357 #endif
8358 		) && (options[opt_idx].flags & P_SECURE))
8359 	return e_secure;
8360 
8361     *(int *)varp = value;	    /* set the new value */
8362 #ifdef FEAT_EVAL
8363     /* Remember where the option was set. */
8364     set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
8365 #endif
8366 
8367 #ifdef FEAT_GUI
8368     need_mouse_correct = TRUE;
8369 #endif
8370 
8371     /* May set global value for local option. */
8372     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8373 	*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8374 
8375     /*
8376      * Handle side effects of changing a bool option.
8377      */
8378 
8379     /* 'compatible' */
8380     if ((int *)varp == &p_cp)
8381 	compatible_set();
8382 
8383 #ifdef FEAT_LANGMAP
8384     if ((int *)varp == &p_lrm)
8385 	/* 'langremap' -> !'langnoremap' */
8386 	p_lnr = !p_lrm;
8387     else if ((int *)varp == &p_lnr)
8388 	/* 'langnoremap' -> !'langremap' */
8389 	p_lrm = !p_lnr;
8390 #endif
8391 
8392 #ifdef FEAT_SYN_HL
8393     else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8394 	reset_cursorline();
8395 #endif
8396 
8397 #ifdef FEAT_PERSISTENT_UNDO
8398     /* 'undofile' */
8399     else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8400     {
8401 	/* Only take action when the option was set. When reset we do not
8402 	 * delete the undo file, the option may be set again without making
8403 	 * any changes in between. */
8404 	if (curbuf->b_p_udf || p_udf)
8405 	{
8406 	    char_u	hash[UNDO_HASH_SIZE];
8407 	    buf_T	*save_curbuf = curbuf;
8408 
8409 	    FOR_ALL_BUFFERS(curbuf)
8410 	    {
8411 		/* When 'undofile' is set globally: for every buffer, otherwise
8412 		 * only for the current buffer: Try to read in the undofile,
8413 		 * if one exists, the buffer wasn't changed and the buffer was
8414 		 * loaded */
8415 		if ((curbuf == save_curbuf
8416 				|| (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8417 			&& !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8418 		{
8419 		    u_compute_hash(hash);
8420 		    u_read_undo(NULL, hash, curbuf->b_fname);
8421 		}
8422 	    }
8423 	    curbuf = save_curbuf;
8424 	}
8425     }
8426 #endif
8427 
8428     else if ((int *)varp == &curbuf->b_p_ro)
8429     {
8430 	/* when 'readonly' is reset globally, also reset readonlymode */
8431 	if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8432 	    readonlymode = FALSE;
8433 
8434 	/* when 'readonly' is set may give W10 again */
8435 	if (curbuf->b_p_ro)
8436 	    curbuf->b_did_warn = FALSE;
8437 
8438 #ifdef FEAT_TITLE
8439 	redraw_titles();
8440 #endif
8441     }
8442 
8443 #ifdef FEAT_GUI
8444     else if ((int *)varp == &p_mh)
8445     {
8446 	if (!p_mh)
8447 	    gui_mch_mousehide(FALSE);
8448     }
8449 #endif
8450 
8451     /* when 'modifiable' is changed, redraw the window title */
8452     else if ((int *)varp == &curbuf->b_p_ma)
8453     {
8454 # ifdef FEAT_TERMINAL
8455 	/* Cannot set 'modifiable' when in Terminal mode. */
8456 	if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8457 		      && curbuf->b_term != NULL && !term_is_finished(curbuf))))
8458 	{
8459 	    curbuf->b_p_ma = FALSE;
8460 	    return N_("E946: Cannot make a terminal with running job modifiable");
8461 	}
8462 # endif
8463 # ifdef FEAT_TITLE
8464 	redraw_titles();
8465 # endif
8466     }
8467 #ifdef FEAT_TITLE
8468     /* when 'endofline' is changed, redraw the window title */
8469     else if ((int *)varp == &curbuf->b_p_eol)
8470     {
8471 	redraw_titles();
8472     }
8473     /* when 'fixeol' is changed, redraw the window title */
8474     else if ((int *)varp == &curbuf->b_p_fixeol)
8475     {
8476 	redraw_titles();
8477     }
8478     /* when 'bomb' is changed, redraw the window title and tab page text */
8479     else if ((int *)varp == &curbuf->b_p_bomb)
8480     {
8481 	redraw_titles();
8482     }
8483 #endif
8484 
8485     /* when 'bin' is set also set some other options */
8486     else if ((int *)varp == &curbuf->b_p_bin)
8487     {
8488 	set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8489 #ifdef FEAT_TITLE
8490 	redraw_titles();
8491 #endif
8492     }
8493 
8494     /* when 'buflisted' changes, trigger autocommands */
8495     else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8496     {
8497 	apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8498 						    NULL, NULL, TRUE, curbuf);
8499     }
8500 
8501     /* when 'swf' is set, create swapfile, when reset remove swapfile */
8502     else if ((int *)varp == &curbuf->b_p_swf)
8503     {
8504 	if (curbuf->b_p_swf && p_uc)
8505 	    ml_open_file(curbuf);		/* create the swap file */
8506 	else
8507 	    /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8508 	     * buf->b_p_swf */
8509 	    mf_close_file(curbuf, TRUE);	/* remove the swap file */
8510     }
8511 
8512     /* when 'terse' is set change 'shortmess' */
8513     else if ((int *)varp == &p_terse)
8514     {
8515 	char_u	*p;
8516 
8517 	p = vim_strchr(p_shm, SHM_SEARCH);
8518 
8519 	/* insert 's' in p_shm */
8520 	if (p_terse && p == NULL)
8521 	{
8522 	    STRCPY(IObuff, p_shm);
8523 	    STRCAT(IObuff, "s");
8524 	    set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
8525 	}
8526 	/* remove 's' from p_shm */
8527 	else if (!p_terse && p != NULL)
8528 	    STRMOVE(p, p + 1);
8529     }
8530 
8531     /* when 'paste' is set or reset also change other options */
8532     else if ((int *)varp == &p_paste)
8533     {
8534 	paste_option_changed();
8535     }
8536 
8537     /* when 'insertmode' is set from an autocommand need to do work here */
8538     else if ((int *)varp == &p_im)
8539     {
8540 	if (p_im)
8541 	{
8542 	    if ((State & INSERT) == 0)
8543 		need_start_insertmode = TRUE;
8544 	    stop_insert_mode = FALSE;
8545 	}
8546 	/* only reset if it was set previously */
8547 	else if (old_value)
8548 	{
8549 	    need_start_insertmode = FALSE;
8550 	    stop_insert_mode = TRUE;
8551 	    if (restart_edit != 0 && mode_displayed)
8552 		clear_cmdline = TRUE;	/* remove "(insert)" */
8553 	    restart_edit = 0;
8554 	}
8555     }
8556 
8557     /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8558     else if ((int *)varp == &p_ic && p_hls)
8559     {
8560 	redraw_all_later(SOME_VALID);
8561     }
8562 
8563 #ifdef FEAT_SEARCH_EXTRA
8564     /* when 'hlsearch' is set or reset: reset no_hlsearch */
8565     else if ((int *)varp == &p_hls)
8566     {
8567 	set_no_hlsearch(FALSE);
8568     }
8569 #endif
8570 
8571     /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8572      * at the end of normal_cmd() */
8573     else if ((int *)varp == &curwin->w_p_scb)
8574     {
8575 	if (curwin->w_p_scb)
8576 	{
8577 	    do_check_scrollbind(FALSE);
8578 	    curwin->w_scbind_pos = curwin->w_topline;
8579 	}
8580     }
8581 
8582 #if defined(FEAT_QUICKFIX)
8583     /* There can be only one window with 'previewwindow' set. */
8584     else if ((int *)varp == &curwin->w_p_pvw)
8585     {
8586 	if (curwin->w_p_pvw)
8587 	{
8588 	    win_T	*win;
8589 
8590 	    FOR_ALL_WINDOWS(win)
8591 		if (win->w_p_pvw && win != curwin)
8592 		{
8593 		    curwin->w_p_pvw = FALSE;
8594 		    return N_("E590: A preview window already exists");
8595 		}
8596 	}
8597     }
8598 #endif
8599 
8600     /* when 'textmode' is set or reset also change 'fileformat' */
8601     else if ((int *)varp == &curbuf->b_p_tx)
8602     {
8603 	set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8604     }
8605 
8606     /* when 'textauto' is set or reset also change 'fileformats' */
8607     else if ((int *)varp == &p_ta)
8608     {
8609 	set_string_option_direct((char_u *)"ffs", -1,
8610 				 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
8611 						     OPT_FREE | opt_flags, 0);
8612     }
8613 
8614     /*
8615      * When 'lisp' option changes include/exclude '-' in
8616      * keyword characters.
8617      */
8618 #ifdef FEAT_LISP
8619     else if (varp == (char_u *)&(curbuf->b_p_lisp))
8620     {
8621 	(void)buf_init_chartab(curbuf, FALSE);	    /* ignore errors */
8622     }
8623 #endif
8624 
8625 #ifdef FEAT_TITLE
8626     /* when 'title' changed, may need to change the title; same for 'icon' */
8627     else if ((int *)varp == &p_title || (int *)varp == &p_icon)
8628     {
8629 	did_set_title();
8630     }
8631 #endif
8632 
8633     else if ((int *)varp == &curbuf->b_changed)
8634     {
8635 	if (!value)
8636 	    save_file_ff(curbuf);	/* Buffer is unchanged */
8637 #ifdef FEAT_TITLE
8638 	redraw_titles();
8639 #endif
8640 	modified_was_set = value;
8641     }
8642 
8643 #ifdef BACKSLASH_IN_FILENAME
8644     else if ((int *)varp == &p_ssl)
8645     {
8646 	if (p_ssl)
8647 	{
8648 	    psepc = '/';
8649 	    psepcN = '\\';
8650 	    pseps[0] = '/';
8651 	}
8652 	else
8653 	{
8654 	    psepc = '\\';
8655 	    psepcN = '/';
8656 	    pseps[0] = '\\';
8657 	}
8658 
8659 	/* need to adjust the file name arguments and buffer names. */
8660 	buflist_slash_adjust();
8661 	alist_slash_adjust();
8662 # ifdef FEAT_EVAL
8663 	scriptnames_slash_adjust();
8664 # endif
8665     }
8666 #endif
8667 
8668     /* If 'wrap' is set, set w_leftcol to zero. */
8669     else if ((int *)varp == &curwin->w_p_wrap)
8670     {
8671 	if (curwin->w_p_wrap)
8672 	    curwin->w_leftcol = 0;
8673     }
8674 
8675     else if ((int *)varp == &p_ea)
8676     {
8677 	if (p_ea && !old_value)
8678 	    win_equal(curwin, FALSE, 0);
8679     }
8680 
8681     else if ((int *)varp == &p_wiv)
8682     {
8683 	/*
8684 	 * When 'weirdinvert' changed, set/reset 't_xs'.
8685 	 * Then set 'weirdinvert' according to value of 't_xs'.
8686 	 */
8687 	if (p_wiv && !old_value)
8688 	    T_XS = (char_u *)"y";
8689 	else if (!p_wiv && old_value)
8690 	    T_XS = empty_option;
8691 	p_wiv = (*T_XS != NUL);
8692     }
8693 
8694 #ifdef FEAT_BEVAL_GUI
8695     else if ((int *)varp == &p_beval)
8696     {
8697 	if (!balloonEvalForTerm)
8698 	{
8699 	    if (p_beval && !old_value)
8700 		gui_mch_enable_beval_area(balloonEval);
8701 	    else if (!p_beval && old_value)
8702 		gui_mch_disable_beval_area(balloonEval);
8703 	}
8704     }
8705 #endif
8706 #ifdef FEAT_BEVAL_TERM
8707     else if ((int *)varp == &p_bevalterm)
8708     {
8709 	mch_bevalterm_changed();
8710     }
8711 #endif
8712 
8713 #ifdef FEAT_AUTOCHDIR
8714     else if ((int *)varp == &p_acd)
8715     {
8716 	/* Change directories when the 'acd' option is set now. */
8717 	DO_AUTOCHDIR;
8718     }
8719 #endif
8720 
8721 #ifdef FEAT_DIFF
8722     /* 'diff' */
8723     else if ((int *)varp == &curwin->w_p_diff)
8724     {
8725 	/* May add or remove the buffer from the list of diff buffers. */
8726 	diff_buf_adjust(curwin);
8727 # ifdef FEAT_FOLDING
8728 	if (foldmethodIsDiff(curwin))
8729 	    foldUpdateAll(curwin);
8730 # endif
8731     }
8732 #endif
8733 
8734 #ifdef HAVE_INPUT_METHOD
8735     /* 'imdisable' */
8736     else if ((int *)varp == &p_imdisable)
8737     {
8738 	/* Only de-activate it here, it will be enabled when changing mode. */
8739 	if (p_imdisable)
8740 	    im_set_active(FALSE);
8741 	else if (State & INSERT)
8742 	    /* When the option is set from an autocommand, it may need to take
8743 	     * effect right away. */
8744 	    im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
8745     }
8746 #endif
8747 
8748 #ifdef FEAT_SPELL
8749     /* 'spell' */
8750     else if ((int *)varp == &curwin->w_p_spell)
8751     {
8752 	if (curwin->w_p_spell)
8753 	{
8754 	    char	*errmsg = did_set_spelllang(curwin);
8755 
8756 	    if (errmsg != NULL)
8757 		emsg(_(errmsg));
8758 	}
8759     }
8760 #endif
8761 
8762 #ifdef FEAT_ARABIC
8763     if ((int *)varp == &curwin->w_p_arab)
8764     {
8765 	if (curwin->w_p_arab)
8766 	{
8767 	    /*
8768 	     * 'arabic' is set, handle various sub-settings.
8769 	     */
8770 	    if (!p_tbidi)
8771 	    {
8772 		/* set rightleft mode */
8773 		if (!curwin->w_p_rl)
8774 		{
8775 		    curwin->w_p_rl = TRUE;
8776 		    changed_window_setting();
8777 		}
8778 
8779 		/* Enable Arabic shaping (major part of what Arabic requires) */
8780 		if (!p_arshape)
8781 		{
8782 		    p_arshape = TRUE;
8783 		    redraw_later_clear();
8784 		}
8785 	    }
8786 
8787 	    /* Arabic requires a utf-8 encoding, inform the user if its not
8788 	     * set. */
8789 	    if (STRCMP(p_enc, "utf-8") != 0)
8790 	    {
8791 		static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8792 
8793 		msg_source(HL_ATTR(HLF_W));
8794 		msg_attr(_(w_arabic), HL_ATTR(HLF_W));
8795 #ifdef FEAT_EVAL
8796 		set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8797 #endif
8798 	    }
8799 
8800 	    /* set 'delcombine' */
8801 	    p_deco = TRUE;
8802 
8803 # ifdef FEAT_KEYMAP
8804 	    /* Force-set the necessary keymap for arabic */
8805 	    set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8806 								   OPT_LOCAL);
8807 # endif
8808 	}
8809 	else
8810 	{
8811 	    /*
8812 	     * 'arabic' is reset, handle various sub-settings.
8813 	     */
8814 	    if (!p_tbidi)
8815 	    {
8816 		/* reset rightleft mode */
8817 		if (curwin->w_p_rl)
8818 		{
8819 		    curwin->w_p_rl = FALSE;
8820 		    changed_window_setting();
8821 		}
8822 
8823 		/* 'arabicshape' isn't reset, it is a global option and
8824 		 * another window may still need it "on". */
8825 	    }
8826 
8827 	    /* 'delcombine' isn't reset, it is a global option and another
8828 	     * window may still want it "on". */
8829 
8830 # ifdef FEAT_KEYMAP
8831 	    /* Revert to the default keymap */
8832 	    curbuf->b_p_iminsert = B_IMODE_NONE;
8833 	    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8834 # endif
8835 	}
8836     }
8837 
8838 #endif
8839 
8840 #ifdef FEAT_TERMGUICOLORS
8841     /* 'termguicolors' */
8842     else if ((int *)varp == &p_tgc)
8843     {
8844 # ifdef FEAT_VTP
8845 	/* Do not turn on 'tgc' when 24-bit colors are not supported. */
8846 	if (
8847 #  ifdef VIMDLL
8848 	    !gui.in_use && !gui.starting &&
8849 #  endif
8850 	    !has_vtp_working())
8851 	{
8852 	    p_tgc = 0;
8853 	    return N_("E954: 24-bit colors are not supported on this environment");
8854 	}
8855 	if (is_term_win32())
8856 	    swap_tcap();
8857 # endif
8858 # ifdef FEAT_GUI
8859 	if (!gui.in_use && !gui.starting)
8860 # endif
8861 	    highlight_gui_started();
8862 # ifdef FEAT_VTP
8863 	/* reset t_Co */
8864 	if (is_term_win32())
8865 	{
8866 	    control_console_color_rgb();
8867 	    set_termname(T_NAME);
8868 	    init_highlight(TRUE, FALSE);
8869 	}
8870 # endif
8871     }
8872 #endif
8873 
8874     /*
8875      * End of handling side effects for bool options.
8876      */
8877 
8878     /* after handling side effects, call autocommand */
8879 
8880     options[opt_idx].flags |= P_WAS_SET;
8881 
8882 #if defined(FEAT_EVAL)
8883     // Don't do this while starting up or recursively.
8884     if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
8885     {
8886 	char_u buf_old[2], buf_new[2], buf_type[7];
8887 
8888 	vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8889 	vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8890 	vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
8891 	set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8892 	set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8893 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8894 	apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8895 	reset_v_option_vars();
8896     }
8897 #endif
8898 
8899     comp_col();			    /* in case 'ruler' or 'showcmd' changed */
8900     if (curwin->w_curswant != MAXCOL
8901 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
8902 	curwin->w_set_curswant = TRUE;
8903     check_redraw(options[opt_idx].flags);
8904 
8905     return NULL;
8906 }
8907 
8908 /*
8909  * Set the value of a number option, and take care of side effects.
8910  * Returns NULL for success, or an error message for an error.
8911  */
8912     static char *
8913 set_num_option(
8914     int		opt_idx,		/* index in options[] table */
8915     char_u	*varp,			/* pointer to the option variable */
8916     long	value,			/* new value */
8917     char	*errbuf,		/* buffer for error messages */
8918     size_t	errbuflen,		/* length of "errbuf" */
8919     int		opt_flags)		/* OPT_LOCAL, OPT_GLOBAL and
8920 					   OPT_MODELINE */
8921 {
8922     char	*errmsg = NULL;
8923     long	old_value = *(long *)varp;
8924     long	old_Rows = Rows;	/* remember old Rows */
8925     long	old_Columns = Columns;	/* remember old Columns */
8926     long	*pp = (long *)varp;
8927 
8928     /* Disallow changing some options from secure mode. */
8929     if ((secure
8930 #ifdef HAVE_SANDBOX
8931 		|| sandbox != 0
8932 #endif
8933 		) && (options[opt_idx].flags & P_SECURE))
8934 	return e_secure;
8935 
8936     *pp = value;
8937 #ifdef FEAT_EVAL
8938     /* Remember where the option was set. */
8939     set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
8940 #endif
8941 #ifdef FEAT_GUI
8942     need_mouse_correct = TRUE;
8943 #endif
8944 
8945     if (curbuf->b_p_sw < 0)
8946     {
8947 	errmsg = e_positive;
8948 #ifdef FEAT_VARTABS
8949 	// Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8950 	curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8951 	               ? tabstop_first(curbuf->b_p_vts_array)
8952 		       : curbuf->b_p_ts;
8953 #else
8954 	curbuf->b_p_sw = curbuf->b_p_ts;
8955 #endif
8956     }
8957 
8958     /*
8959      * Number options that need some action when changed
8960      */
8961     if (pp == &p_wh || pp == &p_hh)
8962     {
8963 	// 'winheight' and 'helpheight'
8964 	if (p_wh < 1)
8965 	{
8966 	    errmsg = e_positive;
8967 	    p_wh = 1;
8968 	}
8969 	if (p_wmh > p_wh)
8970 	{
8971 	    errmsg = e_winheight;
8972 	    p_wh = p_wmh;
8973 	}
8974 	if (p_hh < 0)
8975 	{
8976 	    errmsg = e_positive;
8977 	    p_hh = 0;
8978 	}
8979 
8980 	/* Change window height NOW */
8981 	if (!ONE_WINDOW)
8982 	{
8983 	    if (pp == &p_wh && curwin->w_height < p_wh)
8984 		win_setheight((int)p_wh);
8985 	    if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8986 		win_setheight((int)p_hh);
8987 	}
8988     }
8989     else if (pp == &p_wmh)
8990     {
8991 	// 'winminheight'
8992 	if (p_wmh < 0)
8993 	{
8994 	    errmsg = e_positive;
8995 	    p_wmh = 0;
8996 	}
8997 	if (p_wmh > p_wh)
8998 	{
8999 	    errmsg = e_winheight;
9000 	    p_wmh = p_wh;
9001 	}
9002 	win_setminheight();
9003     }
9004     else if (pp == &p_wiw)
9005     {
9006 	// 'winwidth'
9007 	if (p_wiw < 1)
9008 	{
9009 	    errmsg = e_positive;
9010 	    p_wiw = 1;
9011 	}
9012 	if (p_wmw > p_wiw)
9013 	{
9014 	    errmsg = e_winwidth;
9015 	    p_wiw = p_wmw;
9016 	}
9017 
9018 	/* Change window width NOW */
9019 	if (!ONE_WINDOW && curwin->w_width < p_wiw)
9020 	    win_setwidth((int)p_wiw);
9021     }
9022     else if (pp == &p_wmw)
9023     {
9024 	// 'winminwidth'
9025 	if (p_wmw < 0)
9026 	{
9027 	    errmsg = e_positive;
9028 	    p_wmw = 0;
9029 	}
9030 	if (p_wmw > p_wiw)
9031 	{
9032 	    errmsg = e_winwidth;
9033 	    p_wmw = p_wiw;
9034 	}
9035 	win_setminwidth();
9036     }
9037 
9038     /* (re)set last window status line */
9039     else if (pp == &p_ls)
9040     {
9041 	last_status(FALSE);
9042     }
9043 
9044     /* (re)set tab page line */
9045     else if (pp == &p_stal)
9046     {
9047 	shell_new_rows();	/* recompute window positions and heights */
9048     }
9049 
9050 #ifdef FEAT_GUI
9051     else if (pp == &p_linespace)
9052     {
9053 	/* Recompute gui.char_height and resize the Vim window to keep the
9054 	 * same number of lines. */
9055 	if (gui.in_use && gui_mch_adjust_charheight() == OK)
9056 	    gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
9057     }
9058 #endif
9059 
9060 #ifdef FEAT_FOLDING
9061     /* 'foldlevel' */
9062     else if (pp == &curwin->w_p_fdl)
9063     {
9064 	if (curwin->w_p_fdl < 0)
9065 	    curwin->w_p_fdl = 0;
9066 	newFoldLevel();
9067     }
9068 
9069     /* 'foldminlines' */
9070     else if (pp == &curwin->w_p_fml)
9071     {
9072 	foldUpdateAll(curwin);
9073     }
9074 
9075     /* 'foldnestmax' */
9076     else if (pp == &curwin->w_p_fdn)
9077     {
9078 	if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9079 	    foldUpdateAll(curwin);
9080     }
9081 
9082     /* 'foldcolumn' */
9083     else if (pp == &curwin->w_p_fdc)
9084     {
9085 	if (curwin->w_p_fdc < 0)
9086 	{
9087 	    errmsg = e_positive;
9088 	    curwin->w_p_fdc = 0;
9089 	}
9090 	else if (curwin->w_p_fdc > 12)
9091 	{
9092 	    errmsg = e_invarg;
9093 	    curwin->w_p_fdc = 12;
9094 	}
9095     }
9096 #endif /* FEAT_FOLDING */
9097 
9098 #if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
9099     /* 'shiftwidth' or 'tabstop' */
9100     else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9101     {
9102 # ifdef FEAT_FOLDING
9103 	if (foldmethodIsIndent(curwin))
9104 	    foldUpdateAll(curwin);
9105 # endif
9106 # ifdef FEAT_CINDENT
9107 	/* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9108 	 * parse 'cinoptions'. */
9109 	if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9110 	    parse_cino(curbuf);
9111 # endif
9112     }
9113 #endif
9114 
9115     /* 'maxcombine' */
9116     else if (pp == &p_mco)
9117     {
9118 	if (p_mco > MAX_MCO)
9119 	    p_mco = MAX_MCO;
9120 	else if (p_mco < 0)
9121 	    p_mco = 0;
9122 	screenclear();	    /* will re-allocate the screen */
9123     }
9124 
9125     else if (pp == &curbuf->b_p_iminsert)
9126     {
9127 	if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9128 	{
9129 	    errmsg = e_invarg;
9130 	    curbuf->b_p_iminsert = B_IMODE_NONE;
9131 	}
9132 	p_iminsert = curbuf->b_p_iminsert;
9133 	if (termcap_active)	/* don't do this in the alternate screen */
9134 	    showmode();
9135 #if defined(FEAT_KEYMAP)
9136 	/* Show/unshow value of 'keymap' in status lines. */
9137 	status_redraw_curbuf();
9138 #endif
9139     }
9140 
9141 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9142     /* 'imstyle' */
9143     else if (pp == &p_imst)
9144     {
9145 	if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9146 	    errmsg = e_invarg;
9147     }
9148 #endif
9149 
9150     else if (pp == &p_window)
9151     {
9152 	if (p_window < 1)
9153 	    p_window = 1;
9154 	else if (p_window >= Rows)
9155 	    p_window = Rows - 1;
9156     }
9157 
9158     else if (pp == &curbuf->b_p_imsearch)
9159     {
9160 	if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9161 	{
9162 	    errmsg = e_invarg;
9163 	    curbuf->b_p_imsearch = B_IMODE_NONE;
9164 	}
9165 	p_imsearch = curbuf->b_p_imsearch;
9166     }
9167 
9168 #ifdef FEAT_TITLE
9169     /* if 'titlelen' has changed, redraw the title */
9170     else if (pp == &p_titlelen)
9171     {
9172 	if (p_titlelen < 0)
9173 	{
9174 	    errmsg = e_positive;
9175 	    p_titlelen = 85;
9176 	}
9177 	if (starting != NO_SCREEN && old_value != p_titlelen)
9178 	    need_maketitle = TRUE;
9179     }
9180 #endif
9181 
9182     /* if p_ch changed value, change the command line height */
9183     else if (pp == &p_ch)
9184     {
9185 	if (p_ch < 1)
9186 	{
9187 	    errmsg = e_positive;
9188 	    p_ch = 1;
9189 	}
9190 	if (p_ch > Rows - min_rows() + 1)
9191 	    p_ch = Rows - min_rows() + 1;
9192 
9193 	/* Only compute the new window layout when startup has been
9194 	 * completed. Otherwise the frame sizes may be wrong. */
9195 	if (p_ch != old_value && full_screen
9196 #ifdef FEAT_GUI
9197 		&& !gui.starting
9198 #endif
9199 	   )
9200 	    command_height();
9201     }
9202 
9203     /* when 'updatecount' changes from zero to non-zero, open swap files */
9204     else if (pp == &p_uc)
9205     {
9206 	if (p_uc < 0)
9207 	{
9208 	    errmsg = e_positive;
9209 	    p_uc = 100;
9210 	}
9211 	if (p_uc && !old_value)
9212 	    ml_open_files();
9213     }
9214 #ifdef FEAT_CONCEAL
9215     else if (pp == &curwin->w_p_cole)
9216     {
9217 	if (curwin->w_p_cole < 0)
9218 	{
9219 	    errmsg = e_positive;
9220 	    curwin->w_p_cole = 0;
9221 	}
9222 	else if (curwin->w_p_cole > 3)
9223 	{
9224 	    errmsg = e_invarg;
9225 	    curwin->w_p_cole = 3;
9226 	}
9227     }
9228 #endif
9229 #ifdef MZSCHEME_GUI_THREADS
9230     else if (pp == &p_mzq)
9231 	mzvim_reset_timer();
9232 #endif
9233 
9234 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9235     /* 'pyxversion' */
9236     else if (pp == &p_pyx)
9237     {
9238 	if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9239 	    errmsg = e_invarg;
9240     }
9241 #endif
9242 
9243     /* sync undo before 'undolevels' changes */
9244     else if (pp == &p_ul)
9245     {
9246 	/* use the old value, otherwise u_sync() may not work properly */
9247 	p_ul = old_value;
9248 	u_sync(TRUE);
9249 	p_ul = value;
9250     }
9251     else if (pp == &curbuf->b_p_ul)
9252     {
9253 	/* use the old value, otherwise u_sync() may not work properly */
9254 	curbuf->b_p_ul = old_value;
9255 	u_sync(TRUE);
9256 	curbuf->b_p_ul = value;
9257     }
9258 
9259 #ifdef FEAT_LINEBREAK
9260     /* 'numberwidth' must be positive */
9261     else if (pp == &curwin->w_p_nuw)
9262     {
9263 	if (curwin->w_p_nuw < 1)
9264 	{
9265 	    errmsg = e_positive;
9266 	    curwin->w_p_nuw = 1;
9267 	}
9268 	if (curwin->w_p_nuw > 10)
9269 	{
9270 	    errmsg = e_invarg;
9271 	    curwin->w_p_nuw = 10;
9272 	}
9273 	curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
9274     }
9275 #endif
9276 
9277     else if (pp == &curbuf->b_p_tw)
9278     {
9279 	if (curbuf->b_p_tw < 0)
9280 	{
9281 	    errmsg = e_positive;
9282 	    curbuf->b_p_tw = 0;
9283 	}
9284 #ifdef FEAT_SYN_HL
9285 	{
9286 	    win_T	*wp;
9287 	    tabpage_T	*tp;
9288 
9289 	    FOR_ALL_TAB_WINDOWS(tp, wp)
9290 		check_colorcolumn(wp);
9291 	}
9292 #endif
9293     }
9294 
9295     /*
9296      * Check the bounds for numeric options here
9297      */
9298     if (Rows < min_rows() && full_screen)
9299     {
9300 	if (errbuf != NULL)
9301 	{
9302 	    vim_snprintf((char *)errbuf, errbuflen,
9303 			       _("E593: Need at least %d lines"), min_rows());
9304 	    errmsg = errbuf;
9305 	}
9306 	Rows = min_rows();
9307     }
9308     if (Columns < MIN_COLUMNS && full_screen)
9309     {
9310 	if (errbuf != NULL)
9311 	{
9312 	    vim_snprintf((char *)errbuf, errbuflen,
9313 			    _("E594: Need at least %d columns"), MIN_COLUMNS);
9314 	    errmsg = errbuf;
9315 	}
9316 	Columns = MIN_COLUMNS;
9317     }
9318     limit_screen_size();
9319 
9320     /*
9321      * If the screen (shell) height has been changed, assume it is the
9322      * physical screenheight.
9323      */
9324     if (old_Rows != Rows || old_Columns != Columns)
9325     {
9326 	/* Changing the screen size is not allowed while updating the screen. */
9327 	if (updating_screen)
9328 	    *pp = old_value;
9329 	else if (full_screen
9330 #ifdef FEAT_GUI
9331 		&& !gui.starting
9332 #endif
9333 	    )
9334 	    set_shellsize((int)Columns, (int)Rows, TRUE);
9335 	else
9336 	{
9337 	    /* Postpone the resizing; check the size and cmdline position for
9338 	     * messages. */
9339 	    check_shellsize();
9340 	    if (cmdline_row > Rows - p_ch && Rows > p_ch)
9341 		cmdline_row = Rows - p_ch;
9342 	}
9343 	if (p_window >= Rows || !option_was_set((char_u *)"window"))
9344 	    p_window = Rows - 1;
9345     }
9346 
9347     if (curbuf->b_p_ts <= 0)
9348     {
9349 	errmsg = e_positive;
9350 	curbuf->b_p_ts = 8;
9351     }
9352     if (p_tm < 0)
9353     {
9354 	errmsg = e_positive;
9355 	p_tm = 0;
9356     }
9357     if ((curwin->w_p_scr <= 0
9358 		|| (curwin->w_p_scr > curwin->w_height
9359 		    && curwin->w_height > 0))
9360 	    && full_screen)
9361     {
9362 	if (pp == &(curwin->w_p_scr))
9363 	{
9364 	    if (curwin->w_p_scr != 0)
9365 		errmsg = e_scroll;
9366 	    win_comp_scroll(curwin);
9367 	}
9368 	/* If 'scroll' became invalid because of a side effect silently adjust
9369 	 * it. */
9370 	else if (curwin->w_p_scr <= 0)
9371 	    curwin->w_p_scr = 1;
9372 	else /* curwin->w_p_scr > curwin->w_height */
9373 	    curwin->w_p_scr = curwin->w_height;
9374     }
9375     if (p_hi < 0)
9376     {
9377 	errmsg = e_positive;
9378 	p_hi = 0;
9379     }
9380     else if (p_hi > 10000)
9381     {
9382 	errmsg = e_invarg;
9383 	p_hi = 10000;
9384     }
9385     if (p_re < 0 || p_re > 2)
9386     {
9387 	errmsg = e_invarg;
9388 	p_re = 0;
9389     }
9390     if (p_report < 0)
9391     {
9392 	errmsg = e_positive;
9393 	p_report = 1;
9394     }
9395     if ((p_sj < -100 || p_sj >= Rows) && full_screen)
9396     {
9397 	if (Rows != old_Rows)	/* Rows changed, just adjust p_sj */
9398 	    p_sj = Rows / 2;
9399 	else
9400 	{
9401 	    errmsg = e_scroll;
9402 	    p_sj = 1;
9403 	}
9404     }
9405     if (p_so < 0 && full_screen)
9406     {
9407 	errmsg = e_positive;
9408 	p_so = 0;
9409     }
9410     if (p_siso < 0 && full_screen)
9411     {
9412 	errmsg = e_positive;
9413 	p_siso = 0;
9414     }
9415 #ifdef FEAT_CMDWIN
9416     if (p_cwh < 1)
9417     {
9418 	errmsg = e_positive;
9419 	p_cwh = 1;
9420     }
9421 #endif
9422     if (p_ut < 0)
9423     {
9424 	errmsg = e_positive;
9425 	p_ut = 2000;
9426     }
9427     if (p_ss < 0)
9428     {
9429 	errmsg = e_positive;
9430 	p_ss = 0;
9431     }
9432 
9433     /* May set global value for local option. */
9434     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9435 	*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9436 
9437     options[opt_idx].flags |= P_WAS_SET;
9438 
9439 #if defined(FEAT_EVAL)
9440     // Don't do this while starting up, failure or recursively.
9441     if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
9442     {
9443 	char_u buf_old[11], buf_new[11], buf_type[7];
9444 
9445 	vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9446 	vim_snprintf((char *)buf_new, 10, "%ld", value);
9447 	vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
9448 	set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9449 	set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9450 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9451 	apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9452 	reset_v_option_vars();
9453     }
9454 #endif
9455 
9456     comp_col();			    /* in case 'columns' or 'ls' changed */
9457     if (curwin->w_curswant != MAXCOL
9458 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
9459 	curwin->w_set_curswant = TRUE;
9460     check_redraw(options[opt_idx].flags);
9461 
9462     return errmsg;
9463 }
9464 
9465 /*
9466  * Called after an option changed: check if something needs to be redrawn.
9467  */
9468     static void
9469 check_redraw(long_u flags)
9470 {
9471     /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
9472     int		doclear = (flags & P_RCLR) == P_RCLR;
9473     int		all = ((flags & P_RALL) == P_RALL || doclear);
9474 
9475     if ((flags & P_RSTAT) || all)	/* mark all status lines dirty */
9476 	status_redraw_all();
9477 
9478     if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9479 	changed_window_setting();
9480     if (flags & P_RBUF)
9481 	redraw_curbuf_later(NOT_VALID);
9482     if (flags & P_RWINONLY)
9483 	redraw_later(NOT_VALID);
9484     if (doclear)
9485 	redraw_all_later(CLEAR);
9486     else if (all)
9487 	redraw_all_later(NOT_VALID);
9488 }
9489 
9490 /*
9491  * Find index for option 'arg'.
9492  * Return -1 if not found.
9493  */
9494     static int
9495 findoption(char_u *arg)
9496 {
9497     int		    opt_idx;
9498     char	    *s, *p;
9499     static short    quick_tab[27] = {0, 0};	/* quick access table */
9500     int		    is_term_opt;
9501 
9502     /*
9503      * For first call: Initialize the quick-access table.
9504      * It contains the index for the first option that starts with a certain
9505      * letter.  There are 26 letters, plus the first "t_" option.
9506      */
9507     if (quick_tab[1] == 0)
9508     {
9509 	p = options[0].fullname;
9510 	for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9511 	{
9512 	    if (s[0] != p[0])
9513 	    {
9514 		if (s[0] == 't' && s[1] == '_')
9515 		    quick_tab[26] = opt_idx;
9516 		else
9517 		    quick_tab[CharOrdLow(s[0])] = opt_idx;
9518 	    }
9519 	    p = s;
9520 	}
9521     }
9522 
9523     /*
9524      * Check for name starting with an illegal character.
9525      */
9526 #ifdef EBCDIC
9527     if (!islower(arg[0]))
9528 #else
9529     if (arg[0] < 'a' || arg[0] > 'z')
9530 #endif
9531 	return -1;
9532 
9533     is_term_opt = (arg[0] == 't' && arg[1] == '_');
9534     if (is_term_opt)
9535 	opt_idx = quick_tab[26];
9536     else
9537 	opt_idx = quick_tab[CharOrdLow(arg[0])];
9538     for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9539     {
9540 	if (STRCMP(arg, s) == 0)		    /* match full name */
9541 	    break;
9542     }
9543     if (s == NULL && !is_term_opt)
9544     {
9545 	opt_idx = quick_tab[CharOrdLow(arg[0])];
9546 	for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9547 	{
9548 	    s = options[opt_idx].shortname;
9549 	    if (s != NULL && STRCMP(arg, s) == 0)   /* match short name */
9550 		break;
9551 	    s = NULL;
9552 	}
9553     }
9554     if (s == NULL)
9555 	opt_idx = -1;
9556     return opt_idx;
9557 }
9558 
9559 #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
9560 /*
9561  * Get the value for an option.
9562  *
9563  * Returns:
9564  * Number or Toggle option: 1, *numval gets value.
9565  *	     String option: 0, *stringval gets allocated string.
9566  * Hidden Number or Toggle option: -1.
9567  *	     hidden String option: -2.
9568  *		   unknown option: -3.
9569  */
9570     int
9571 get_option_value(
9572     char_u	*name,
9573     long	*numval,
9574     char_u	**stringval,	    /* NULL when only checking existence */
9575     int		opt_flags)
9576 {
9577     int		opt_idx;
9578     char_u	*varp;
9579 
9580     opt_idx = findoption(name);
9581     if (opt_idx < 0)		    /* unknown option */
9582     {
9583 	int key;
9584 
9585 	if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9586 		&& (key = find_key_option(name, FALSE)) != 0)
9587 	{
9588 	    char_u key_name[2];
9589 	    char_u *p;
9590 
9591 	    if (key < 0)
9592 	    {
9593 		key_name[0] = KEY2TERMCAP0(key);
9594 		key_name[1] = KEY2TERMCAP1(key);
9595 	    }
9596 	    else
9597 	    {
9598 		key_name[0] = KS_KEY;
9599 		key_name[1] = (key & 0xff);
9600 	    }
9601 	    p = find_termcode(key_name);
9602 	    if (p != NULL)
9603 	    {
9604 		if (stringval != NULL)
9605 		    *stringval = vim_strsave(p);
9606 		return 0;
9607 	    }
9608 	}
9609 	return -3;
9610     }
9611 
9612     varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9613 
9614     if (options[opt_idx].flags & P_STRING)
9615     {
9616 	if (varp == NULL)		    /* hidden option */
9617 	    return -2;
9618 	if (stringval != NULL)
9619 	{
9620 #ifdef FEAT_CRYPT
9621 	    /* never return the value of the crypt key */
9622 	    if ((char_u **)varp == &curbuf->b_p_key
9623 						&& **(char_u **)(varp) != NUL)
9624 		*stringval = vim_strsave((char_u *)"*****");
9625 	    else
9626 #endif
9627 		*stringval = vim_strsave(*(char_u **)(varp));
9628 	}
9629 	return 0;
9630     }
9631 
9632     if (varp == NULL)		    /* hidden option */
9633 	return -1;
9634     if (options[opt_idx].flags & P_NUM)
9635 	*numval = *(long *)varp;
9636     else
9637     {
9638 	/* Special case: 'modified' is b_changed, but we also want to consider
9639 	 * it set when 'ff' or 'fenc' changed. */
9640 	if ((int *)varp == &curbuf->b_changed)
9641 	    *numval = curbufIsChanged();
9642 	else
9643 	    *numval = (long) *(int *)varp;
9644     }
9645     return 1;
9646 }
9647 #endif
9648 
9649 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
9650 /*
9651  * Returns the option attributes and its value. Unlike the above function it
9652  * will return either global value or local value of the option depending on
9653  * what was requested, but it will never return global value if it was
9654  * requested to return local one and vice versa. Neither it will return
9655  * buffer-local value if it was requested to return window-local one.
9656  *
9657  * Pretends that option is absent if it is not present in the requested scope
9658  * (i.e. has no global, window-local or buffer-local value depending on
9659  * opt_type). Uses
9660  *
9661  * Returned flags:
9662  *       0 hidden or unknown option, also option that does not have requested
9663  *	   type (see SREQ_* in vim.h)
9664  *  see SOPT_* in vim.h for other flags
9665  *
9666  * Possible opt_type values: see SREQ_* in vim.h
9667  */
9668     int
9669 get_option_value_strict(
9670     char_u	*name,
9671     long	*numval,
9672     char_u	**stringval,	    /* NULL when only obtaining attributes */
9673     int		opt_type,
9674     void	*from)
9675 {
9676     int		opt_idx;
9677     char_u	*varp = NULL;
9678     struct vimoption *p;
9679     int		r = 0;
9680 
9681     opt_idx = findoption(name);
9682     if (opt_idx < 0)
9683 	return 0;
9684 
9685     p = &(options[opt_idx]);
9686 
9687     /* Hidden option */
9688     if (p->var == NULL)
9689 	return 0;
9690 
9691     if (p->flags & P_BOOL)
9692 	r |= SOPT_BOOL;
9693     else if (p->flags & P_NUM)
9694 	r |= SOPT_NUM;
9695     else if (p->flags & P_STRING)
9696 	r |= SOPT_STRING;
9697 
9698     if (p->indir == PV_NONE)
9699     {
9700 	if (opt_type == SREQ_GLOBAL)
9701 	    r |= SOPT_GLOBAL;
9702 	else
9703 	    return 0; /* Did not request global-only option */
9704     }
9705     else
9706     {
9707 	if (p->indir & PV_BOTH)
9708 	    r |= SOPT_GLOBAL;
9709 	else if (opt_type == SREQ_GLOBAL)
9710 	    return 0; /* Requested global option */
9711 
9712 	if (p->indir & PV_WIN)
9713 	{
9714 	    if (opt_type == SREQ_BUF)
9715 		return 0; /* Did not request window-local option */
9716 	    else
9717 		r |= SOPT_WIN;
9718 	}
9719 	else if (p->indir & PV_BUF)
9720 	{
9721 	    if (opt_type == SREQ_WIN)
9722 		return 0; /* Did not request buffer-local option */
9723 	    else
9724 		r |= SOPT_BUF;
9725 	}
9726     }
9727 
9728     if (stringval == NULL)
9729 	return r;
9730 
9731     if (opt_type == SREQ_GLOBAL)
9732 	varp = p->var;
9733     else
9734     {
9735 	if (opt_type == SREQ_BUF)
9736 	{
9737 	    /* Special case: 'modified' is b_changed, but we also want to
9738 	     * consider it set when 'ff' or 'fenc' changed. */
9739 	    if (p->indir == PV_MOD)
9740 	    {
9741 		*numval = bufIsChanged((buf_T *)from);
9742 		varp = NULL;
9743 	    }
9744 #ifdef FEAT_CRYPT
9745 	    else if (p->indir == PV_KEY)
9746 	    {
9747 		/* never return the value of the crypt key */
9748 		*stringval = NULL;
9749 		varp = NULL;
9750 	    }
9751 #endif
9752 	    else
9753 	    {
9754 		buf_T *save_curbuf = curbuf;
9755 
9756 		// only getting a pointer, no need to use aucmd_prepbuf()
9757 		curbuf = (buf_T *)from;
9758 		curwin->w_buffer = curbuf;
9759 		varp = get_varp(p);
9760 		curbuf = save_curbuf;
9761 		curwin->w_buffer = curbuf;
9762 	    }
9763 	}
9764 	else if (opt_type == SREQ_WIN)
9765 	{
9766 	    win_T	*save_curwin = curwin;
9767 
9768 	    curwin = (win_T *)from;
9769 	    curbuf = curwin->w_buffer;
9770 	    varp = get_varp(p);
9771 	    curwin = save_curwin;
9772 	    curbuf = curwin->w_buffer;
9773 	}
9774 	if (varp == p->var)
9775 	    return (r | SOPT_UNSET);
9776     }
9777 
9778     if (varp != NULL)
9779     {
9780 	if (p->flags & P_STRING)
9781 	    *stringval = vim_strsave(*(char_u **)(varp));
9782 	else if (p->flags & P_NUM)
9783 	    *numval = *(long *) varp;
9784 	else
9785 	    *numval = *(int *)varp;
9786     }
9787 
9788     return r;
9789 }
9790 
9791 /*
9792  * Iterate over options. First argument is a pointer to a pointer to a
9793  * structure inside options[] array, second is option type like in the above
9794  * function.
9795  *
9796  * If first argument points to NULL it is assumed that iteration just started
9797  * and caller needs the very first value.
9798  * If first argument points to the end marker function returns NULL and sets
9799  * first argument to NULL.
9800  *
9801  * Returns full option name for current option on each call.
9802  */
9803     char_u *
9804 option_iter_next(void **option, int opt_type)
9805 {
9806     struct vimoption	*ret = NULL;
9807     do
9808     {
9809 	if (*option == NULL)
9810 	    *option = (void *) options;
9811 	else if (((struct vimoption *) (*option))->fullname == NULL)
9812 	{
9813 	    *option = NULL;
9814 	    return NULL;
9815 	}
9816 	else
9817 	    *option = (void *) (((struct vimoption *) (*option)) + 1);
9818 
9819 	ret = ((struct vimoption *) (*option));
9820 
9821 	/* Hidden option */
9822 	if (ret->var == NULL)
9823 	{
9824 	    ret = NULL;
9825 	    continue;
9826 	}
9827 
9828 	switch (opt_type)
9829 	{
9830 	    case SREQ_GLOBAL:
9831 		if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9832 		    ret = NULL;
9833 		break;
9834 	    case SREQ_BUF:
9835 		if (!(ret->indir & PV_BUF))
9836 		    ret = NULL;
9837 		break;
9838 	    case SREQ_WIN:
9839 		if (!(ret->indir & PV_WIN))
9840 		    ret = NULL;
9841 		break;
9842 	    default:
9843 		internal_error("option_iter_next()");
9844 		return NULL;
9845 	}
9846     }
9847     while (ret == NULL);
9848 
9849     return (char_u *)ret->fullname;
9850 }
9851 #endif
9852 
9853 /*
9854  * Set the value of option "name".
9855  * Use "string" for string options, use "number" for other options.
9856  *
9857  * Returns NULL on success or error message on error.
9858  */
9859     char *
9860 set_option_value(
9861     char_u	*name,
9862     long	number,
9863     char_u	*string,
9864     int		opt_flags)	/* OPT_LOCAL or 0 (both) */
9865 {
9866     int		opt_idx;
9867     char_u	*varp;
9868     long_u	flags;
9869 
9870     opt_idx = findoption(name);
9871     if (opt_idx < 0)
9872     {
9873 	int key;
9874 
9875 	if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9876 		&& (key = find_key_option(name, FALSE)) != 0)
9877 	{
9878 	    char_u key_name[2];
9879 
9880 	    if (key < 0)
9881 	    {
9882 		key_name[0] = KEY2TERMCAP0(key);
9883 		key_name[1] = KEY2TERMCAP1(key);
9884 	    }
9885 	    else
9886 	    {
9887 		key_name[0] = KS_KEY;
9888 		key_name[1] = (key & 0xff);
9889 	    }
9890 	    add_termcode(key_name, string, FALSE);
9891 	    if (full_screen)
9892 		ttest(FALSE);
9893 	    redraw_all_later(CLEAR);
9894 	    return NULL;
9895 	}
9896 
9897 	semsg(_("E355: Unknown option: %s"), name);
9898     }
9899     else
9900     {
9901 	flags = options[opt_idx].flags;
9902 #ifdef HAVE_SANDBOX
9903 	/* Disallow changing some options in the sandbox */
9904 	if (sandbox > 0 && (flags & P_SECURE))
9905 	{
9906 	    emsg(_(e_sandbox));
9907 	    return NULL;
9908 	}
9909 #endif
9910 	if (flags & P_STRING)
9911 	    return set_string_option(opt_idx, string, opt_flags);
9912 	else
9913 	{
9914 	    varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9915 	    if (varp != NULL)	/* hidden option is not changed */
9916 	    {
9917 		if (number == 0 && string != NULL)
9918 		{
9919 		    int idx;
9920 
9921 		    /* Either we are given a string or we are setting option
9922 		     * to zero. */
9923 		    for (idx = 0; string[idx] == '0'; ++idx)
9924 			;
9925 		    if (string[idx] != NUL || idx == 0)
9926 		    {
9927 			/* There's another character after zeros or the string
9928 			 * is empty.  In both cases, we are trying to set a
9929 			 * num option using a string. */
9930 			semsg(_("E521: Number required: &%s = '%s'"),
9931 								name, string);
9932 			return NULL;     /* do nothing as we hit an error */
9933 
9934 		    }
9935 		}
9936 		if (flags & P_NUM)
9937 		    return set_num_option(opt_idx, varp, number,
9938 							  NULL, 0, opt_flags);
9939 		else
9940 		    return set_bool_option(opt_idx, varp, (int)number,
9941 								   opt_flags);
9942 	    }
9943 	}
9944     }
9945     return NULL;
9946 }
9947 
9948 /*
9949  * Get the terminal code for a terminal option.
9950  * Returns NULL when not found.
9951  */
9952     char_u *
9953 get_term_code(char_u *tname)
9954 {
9955     int	    opt_idx;
9956     char_u  *varp;
9957 
9958     if (tname[0] != 't' || tname[1] != '_' ||
9959 	    tname[2] == NUL || tname[3] == NUL)
9960 	return NULL;
9961     if ((opt_idx = findoption(tname)) >= 0)
9962     {
9963 	varp = get_varp(&(options[opt_idx]));
9964 	if (varp != NULL)
9965 	    varp = *(char_u **)(varp);
9966 	return varp;
9967     }
9968     return find_termcode(tname + 2);
9969 }
9970 
9971     char_u *
9972 get_highlight_default(void)
9973 {
9974     int i;
9975 
9976     i = findoption((char_u *)"hl");
9977     if (i >= 0)
9978 	return options[i].def_val[VI_DEFAULT];
9979     return (char_u *)NULL;
9980 }
9981 
9982     char_u *
9983 get_encoding_default(void)
9984 {
9985     int i;
9986 
9987     i = findoption((char_u *)"enc");
9988     if (i >= 0)
9989 	return options[i].def_val[VI_DEFAULT];
9990     return (char_u *)NULL;
9991 }
9992 
9993 /*
9994  * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9995  * When "has_lt" is true there is a '<' before "*arg_arg".
9996  * Returns 0 when the key is not recognized.
9997  */
9998     static int
9999 find_key_option(char_u *arg_arg, int has_lt)
10000 {
10001     int		key = 0;
10002     int		modifiers;
10003     char_u	*arg = arg_arg;
10004 
10005     /*
10006      * Don't use get_special_key_code() for t_xx, we don't want it to call
10007      * add_termcap_entry().
10008      */
10009     if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10010 	key = TERMCAP2KEY(arg[2], arg[3]);
10011     else if (has_lt)
10012     {
10013 	--arg;			    /* put arg at the '<' */
10014 	modifiers = 0;
10015 	key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
10016 	if (modifiers)		    /* can't handle modifiers here */
10017 	    key = 0;
10018     }
10019     return key;
10020 }
10021 
10022 /*
10023  * if 'all' == 0: show changed options
10024  * if 'all' == 1: show all normal options
10025  * if 'all' == 2: show all terminal options
10026  */
10027     static void
10028 showoptions(
10029     int		all,
10030     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
10031 {
10032     struct vimoption	*p;
10033     int			col;
10034     int			isterm;
10035     char_u		*varp;
10036     struct vimoption	**items;
10037     int			item_count;
10038     int			run;
10039     int			row, rows;
10040     int			cols;
10041     int			i;
10042     int			len;
10043 
10044 #define INC 20
10045 #define GAP 3
10046 
10047     items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10048 								PARAM_COUNT));
10049     if (items == NULL)
10050 	return;
10051 
10052     /* Highlight title */
10053     if (all == 2)
10054 	msg_puts_title(_("\n--- Terminal codes ---"));
10055     else if (opt_flags & OPT_GLOBAL)
10056 	msg_puts_title(_("\n--- Global option values ---"));
10057     else if (opt_flags & OPT_LOCAL)
10058 	msg_puts_title(_("\n--- Local option values ---"));
10059     else
10060 	msg_puts_title(_("\n--- Options ---"));
10061 
10062     /*
10063      * do the loop two times:
10064      * 1. display the short items
10065      * 2. display the long items (only strings and numbers)
10066      */
10067     for (run = 1; run <= 2 && !got_int; ++run)
10068     {
10069 	/*
10070 	 * collect the items in items[]
10071 	 */
10072 	item_count = 0;
10073 	for (p = &options[0]; p->fullname != NULL; p++)
10074 	{
10075 	    // apply :filter /pat/
10076 	    if (message_filtered((char_u *) p->fullname))
10077 		continue;
10078 
10079 	    varp = NULL;
10080 	    isterm = istermoption(p);
10081 	    if (opt_flags != 0)
10082 	    {
10083 		if (p->indir != PV_NONE && !isterm)
10084 		    varp = get_varp_scope(p, opt_flags);
10085 	    }
10086 	    else
10087 		varp = get_varp(p);
10088 	    if (varp != NULL
10089 		    && ((all == 2 && isterm)
10090 			|| (all == 1 && !isterm)
10091 			|| (all == 0 && !optval_default(p, varp))))
10092 	    {
10093 		if (p->flags & P_BOOL)
10094 		    len = 1;		/* a toggle option fits always */
10095 		else
10096 		{
10097 		    option_value2string(p, opt_flags);
10098 		    len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10099 		}
10100 		if ((len <= INC - GAP && run == 1) ||
10101 						(len > INC - GAP && run == 2))
10102 		    items[item_count++] = p;
10103 	    }
10104 	}
10105 
10106 	/*
10107 	 * display the items
10108 	 */
10109 	if (run == 1)
10110 	{
10111 	    cols = (Columns + GAP - 3) / INC;
10112 	    if (cols == 0)
10113 		cols = 1;
10114 	    rows = (item_count + cols - 1) / cols;
10115 	}
10116 	else	/* run == 2 */
10117 	    rows = item_count;
10118 	for (row = 0; row < rows && !got_int; ++row)
10119 	{
10120 	    msg_putchar('\n');			/* go to next line */
10121 	    if (got_int)			/* 'q' typed in more */
10122 		break;
10123 	    col = 0;
10124 	    for (i = row; i < item_count; i += rows)
10125 	    {
10126 		msg_col = col;			/* make columns */
10127 		showoneopt(items[i], opt_flags);
10128 		col += INC;
10129 	    }
10130 	    out_flush();
10131 	    ui_breakcheck();
10132 	}
10133     }
10134     vim_free(items);
10135 }
10136 
10137 /*
10138  * Return TRUE if option "p" has its default value.
10139  */
10140     static int
10141 optval_default(struct vimoption *p, char_u *varp)
10142 {
10143     int		dvi;
10144 
10145     if (varp == NULL)
10146 	return TRUE;	    /* hidden option is always at default */
10147     dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10148     if (p->flags & P_NUM)
10149 	return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
10150     if (p->flags & P_BOOL)
10151 			/* the cast to long is required for Manx C, long_i is
10152 			 * needed for MSVC */
10153 	return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
10154     /* P_STRING */
10155     return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10156 }
10157 
10158 /*
10159  * showoneopt: show the value of one option
10160  * must not be called with a hidden option!
10161  */
10162     static void
10163 showoneopt(
10164     struct vimoption	*p,
10165     int			opt_flags)	/* OPT_LOCAL or OPT_GLOBAL */
10166 {
10167     char_u	*varp;
10168     int		save_silent = silent_mode;
10169 
10170     silent_mode = FALSE;
10171     info_message = TRUE;	/* use mch_msg(), not mch_errmsg() */
10172 
10173     varp = get_varp_scope(p, opt_flags);
10174 
10175     /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10176     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10177 					? !curbufIsChanged() : !*(int *)varp))
10178 	msg_puts("no");
10179     else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10180 	msg_puts("--");
10181     else
10182 	msg_puts("  ");
10183     msg_puts(p->fullname);
10184     if (!(p->flags & P_BOOL))
10185     {
10186 	msg_putchar('=');
10187 	/* put value string in NameBuff */
10188 	option_value2string(p, opt_flags);
10189 	msg_outtrans(NameBuff);
10190     }
10191 
10192     silent_mode = save_silent;
10193     info_message = FALSE;
10194 }
10195 
10196 /*
10197  * Write modified options as ":set" commands to a file.
10198  *
10199  * There are three values for "opt_flags":
10200  * OPT_GLOBAL:		   Write global option values and fresh values of
10201  *			   buffer-local options (used for start of a session
10202  *			   file).
10203  * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10204  *			   curwin (used for a vimrc file).
10205  * OPT_LOCAL:		   Write buffer-local option values for curbuf, fresh
10206  *			   and local values for window-local options of
10207  *			   curwin.  Local values are also written when at the
10208  *			   default value, because a modeline or autocommand
10209  *			   may have set them when doing ":edit file" and the
10210  *			   user has set them back at the default or fresh
10211  *			   value.
10212  *			   When "local_only" is TRUE, don't write fresh
10213  *			   values, only local values (for ":mkview").
10214  * (fresh value = value used for a new buffer or window for a local option).
10215  *
10216  * Return FAIL on error, OK otherwise.
10217  */
10218     int
10219 makeset(FILE *fd, int opt_flags, int local_only)
10220 {
10221     struct vimoption	*p;
10222     char_u		*varp;			/* currently used value */
10223     char_u		*varp_fresh;		/* local value */
10224     char_u		*varp_local = NULL;	/* fresh value */
10225     char		*cmd;
10226     int			round;
10227     int			pri;
10228 
10229     /*
10230      * The options that don't have a default (terminal name, columns, lines)
10231      * are never written.  Terminal options are also not written.
10232      * Do the loop over "options[]" twice: once for options with the
10233      * P_PRI_MKRC flag and once without.
10234      */
10235     for (pri = 1; pri >= 0; --pri)
10236     {
10237       for (p = &options[0]; !istermoption(p); p++)
10238 	if (!(p->flags & P_NO_MKRC)
10239 		&& !istermoption(p)
10240 		&& ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
10241 	{
10242 	    /* skip global option when only doing locals */
10243 	    if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10244 		continue;
10245 
10246 	    /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10247 	     * file, they are always buffer-specific. */
10248 	    if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10249 		continue;
10250 
10251 	    /* Global values are only written when not at the default value. */
10252 	    varp = get_varp_scope(p, opt_flags);
10253 	    if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10254 		continue;
10255 
10256 	    round = 2;
10257 	    if (p->indir != PV_NONE)
10258 	    {
10259 		if (p->var == VAR_WIN)
10260 		{
10261 		    /* skip window-local option when only doing globals */
10262 		    if (!(opt_flags & OPT_LOCAL))
10263 			continue;
10264 		    /* When fresh value of window-local option is not at the
10265 		     * default, need to write it too. */
10266 		    if (!(opt_flags & OPT_GLOBAL) && !local_only)
10267 		    {
10268 			varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10269 			if (!optval_default(p, varp_fresh))
10270 			{
10271 			    round = 1;
10272 			    varp_local = varp;
10273 			    varp = varp_fresh;
10274 			}
10275 		    }
10276 		}
10277 	    }
10278 
10279 	    /* Round 1: fresh value for window-local options.
10280 	     * Round 2: other values */
10281 	    for ( ; round <= 2; varp = varp_local, ++round)
10282 	    {
10283 		if (round == 1 || (opt_flags & OPT_GLOBAL))
10284 		    cmd = "set";
10285 		else
10286 		    cmd = "setlocal";
10287 
10288 		if (p->flags & P_BOOL)
10289 		{
10290 		    if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10291 			return FAIL;
10292 		}
10293 		else if (p->flags & P_NUM)
10294 		{
10295 		    if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10296 			return FAIL;
10297 		}
10298 		else    /* P_STRING */
10299 		{
10300 		    int		do_endif = FALSE;
10301 
10302 		    /* Don't set 'syntax' and 'filetype' again if the value is
10303 		     * already right, avoids reloading the syntax file. */
10304 		    if (
10305 #if defined(FEAT_SYN_HL)
10306 			    p->indir == PV_SYN ||
10307 #endif
10308 			    p->indir == PV_FT)
10309 		    {
10310 			if (fprintf(fd, "if &%s != '%s'", p->fullname,
10311 						       *(char_u **)(varp)) < 0
10312 				|| put_eol(fd) < 0)
10313 			    return FAIL;
10314 			do_endif = TRUE;
10315 		    }
10316 		    if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10317 							     p->flags) == FAIL)
10318 			return FAIL;
10319 		    if (do_endif)
10320 		    {
10321 			if (put_line(fd, "endif") == FAIL)
10322 			    return FAIL;
10323 		    }
10324 		}
10325 	    }
10326 	}
10327     }
10328     return OK;
10329 }
10330 
10331 #if defined(FEAT_FOLDING) || defined(PROTO)
10332 /*
10333  * Generate set commands for the local fold options only.  Used when
10334  * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10335  */
10336     int
10337 makefoldset(FILE *fd)
10338 {
10339     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
10340 # ifdef FEAT_EVAL
10341 	    || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
10342 								       == FAIL
10343 # endif
10344 	    || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
10345 								       == FAIL
10346 	    || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
10347 								       == FAIL
10348 	    || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10349 	    || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10350 	    || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10351 	    || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10352 	    )
10353 	return FAIL;
10354 
10355     return OK;
10356 }
10357 #endif
10358 
10359     static int
10360 put_setstring(
10361     FILE	*fd,
10362     char	*cmd,
10363     char	*name,
10364     char_u	**valuep,
10365     long_u	flags)
10366 {
10367     char_u	*s;
10368     char_u	*buf = NULL;
10369     char_u	*part = NULL;
10370     char_u	*p;
10371 
10372     if (fprintf(fd, "%s %s=", cmd, name) < 0)
10373 	return FAIL;
10374     if (*valuep != NULL)
10375     {
10376 	/* Output 'pastetoggle' as key names.  For other
10377 	 * options some characters have to be escaped with
10378 	 * CTRL-V or backslash */
10379 	if (valuep == &p_pt)
10380 	{
10381 	    s = *valuep;
10382 	    while (*s != NUL)
10383 		if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
10384 		    return FAIL;
10385 	}
10386 	// expand the option value, replace $HOME by ~
10387 	else if ((flags & P_EXPAND) != 0)
10388 	{
10389 	    int  size = (int)STRLEN(*valuep) + 1;
10390 
10391 	    // replace home directory in the whole option value into "buf"
10392 	    buf = alloc(size);
10393 	    if (buf == NULL)
10394 		goto fail;
10395 	    home_replace(NULL, *valuep, buf, size, FALSE);
10396 
10397 	    // If the option value is longer than MAXPATHL, we need to append
10398 	    // earch comma separated part of the option separately, so that it
10399 	    // can be expanded when read back.
10400 	    if (size >= MAXPATHL && (flags & P_COMMA) != 0
10401 					   && vim_strchr(*valuep, ',') != NULL)
10402 	    {
10403 		part = alloc(size);
10404 		if (part == NULL)
10405 		    goto fail;
10406 
10407 		// write line break to clear the option, e.g. ':set rtp='
10408 		if (put_eol(fd) == FAIL)
10409 		    goto fail;
10410 
10411 		p = buf;
10412 		while (*p != NUL)
10413 		{
10414 		    // for each comma separated option part, append value to
10415 		    // the option, :set rtp+=value
10416 		    if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10417 			goto fail;
10418 		    (void)copy_option_part(&p, part, size,  ",");
10419 		    if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10420 			goto fail;
10421 		}
10422 		vim_free(buf);
10423 		vim_free(part);
10424 		return OK;
10425 	    }
10426 	    if (put_escstr(fd, buf, 2) == FAIL)
10427 	    {
10428 		vim_free(buf);
10429 		return FAIL;
10430 	    }
10431 	    vim_free(buf);
10432 	}
10433 	else if (put_escstr(fd, *valuep, 2) == FAIL)
10434 	    return FAIL;
10435     }
10436     if (put_eol(fd) < 0)
10437 	return FAIL;
10438     return OK;
10439 fail:
10440     vim_free(buf);
10441     vim_free(part);
10442     return FAIL;
10443 }
10444 
10445     static int
10446 put_setnum(
10447     FILE	*fd,
10448     char	*cmd,
10449     char	*name,
10450     long	*valuep)
10451 {
10452     long	wc;
10453 
10454     if (fprintf(fd, "%s %s=", cmd, name) < 0)
10455 	return FAIL;
10456     if (wc_use_keyname((char_u *)valuep, &wc))
10457     {
10458 	/* print 'wildchar' and 'wildcharm' as a key name */
10459 	if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10460 	    return FAIL;
10461     }
10462     else if (fprintf(fd, "%ld", *valuep) < 0)
10463 	return FAIL;
10464     if (put_eol(fd) < 0)
10465 	return FAIL;
10466     return OK;
10467 }
10468 
10469     static int
10470 put_setbool(
10471     FILE	*fd,
10472     char	*cmd,
10473     char	*name,
10474     int		value)
10475 {
10476     if (value < 0)	/* global/local option using global value */
10477 	return OK;
10478     if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10479 	    || put_eol(fd) < 0)
10480 	return FAIL;
10481     return OK;
10482 }
10483 
10484 /*
10485  * Clear all the terminal options.
10486  * If the option has been allocated, free the memory.
10487  * Terminal options are never hidden or indirect.
10488  */
10489     void
10490 clear_termoptions(void)
10491 {
10492     /*
10493      * Reset a few things before clearing the old options. This may cause
10494      * outputting a few things that the terminal doesn't understand, but the
10495      * screen will be cleared later, so this is OK.
10496      */
10497 #ifdef FEAT_MOUSE_TTY
10498     mch_setmouse(FALSE);	    /* switch mouse off */
10499 #endif
10500 #ifdef FEAT_TITLE
10501     mch_restore_title(SAVE_RESTORE_BOTH);    /* restore window titles */
10502 #endif
10503 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10504     /* When starting the GUI close the display opened for the clipboard.
10505      * After restoring the title, because that will need the display. */
10506     if (gui.starting)
10507 	clear_xterm_clip();
10508 #endif
10509     stoptermcap();			/* stop termcap mode */
10510 
10511     free_termoptions();
10512 }
10513 
10514     void
10515 free_termoptions(void)
10516 {
10517     struct vimoption   *p;
10518 
10519     for (p = options; p->fullname != NULL; p++)
10520 	if (istermoption(p))
10521 	{
10522 	    if (p->flags & P_ALLOCED)
10523 		free_string_option(*(char_u **)(p->var));
10524 	    if (p->flags & P_DEF_ALLOCED)
10525 		free_string_option(p->def_val[VI_DEFAULT]);
10526 	    *(char_u **)(p->var) = empty_option;
10527 	    p->def_val[VI_DEFAULT] = empty_option;
10528 	    p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10529 #ifdef FEAT_EVAL
10530 	    // remember where the option was cleared
10531 	    set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10532 #endif
10533 	}
10534     clear_termcodes();
10535 }
10536 
10537 /*
10538  * Free the string for one term option, if it was allocated.
10539  * Set the string to empty_option and clear allocated flag.
10540  * "var" points to the option value.
10541  */
10542     void
10543 free_one_termoption(char_u *var)
10544 {
10545     struct vimoption   *p;
10546 
10547     for (p = &options[0]; p->fullname != NULL; p++)
10548 	if (p->var == var)
10549 	{
10550 	    if (p->flags & P_ALLOCED)
10551 		free_string_option(*(char_u **)(p->var));
10552 	    *(char_u **)(p->var) = empty_option;
10553 	    p->flags &= ~P_ALLOCED;
10554 	    break;
10555 	}
10556 }
10557 
10558 /*
10559  * Set the terminal option defaults to the current value.
10560  * Used after setting the terminal name.
10561  */
10562     void
10563 set_term_defaults(void)
10564 {
10565     struct vimoption   *p;
10566 
10567     for (p = &options[0]; p->fullname != NULL; p++)
10568     {
10569 	if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10570 	{
10571 	    if (p->flags & P_DEF_ALLOCED)
10572 	    {
10573 		free_string_option(p->def_val[VI_DEFAULT]);
10574 		p->flags &= ~P_DEF_ALLOCED;
10575 	    }
10576 	    p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10577 	    if (p->flags & P_ALLOCED)
10578 	    {
10579 		p->flags |= P_DEF_ALLOCED;
10580 		p->flags &= ~P_ALLOCED;	 /* don't free the value now */
10581 	    }
10582 	}
10583     }
10584 }
10585 
10586 /*
10587  * return TRUE if 'p' starts with 't_'
10588  */
10589     static int
10590 istermoption(struct vimoption *p)
10591 {
10592     return (p->fullname[0] == 't' && p->fullname[1] == '_');
10593 }
10594 
10595 /*
10596  * Compute columns for ruler and shown command. 'sc_col' is also used to
10597  * decide what the maximum length of a message on the status line can be.
10598  * If there is a status line for the last window, 'sc_col' is independent
10599  * of 'ru_col'.
10600  */
10601 
10602 #define COL_RULER 17	    /* columns needed by standard ruler */
10603 
10604     void
10605 comp_col(void)
10606 {
10607 #if defined(FEAT_CMDL_INFO)
10608     int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
10609 
10610     sc_col = 0;
10611     ru_col = 0;
10612     if (p_ru)
10613     {
10614 # ifdef FEAT_STL_OPT
10615 	ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10616 # else
10617 	ru_col = COL_RULER + 1;
10618 # endif
10619 	/* no last status line, adjust sc_col */
10620 	if (!last_has_status)
10621 	    sc_col = ru_col;
10622     }
10623     if (p_sc)
10624     {
10625 	sc_col += SHOWCMD_COLS;
10626 	if (!p_ru || last_has_status)	    /* no need for separating space */
10627 	    ++sc_col;
10628     }
10629     sc_col = Columns - sc_col;
10630     ru_col = Columns - ru_col;
10631     if (sc_col <= 0)		/* screen too narrow, will become a mess */
10632 	sc_col = 1;
10633     if (ru_col <= 0)
10634 	ru_col = 1;
10635 #else
10636     sc_col = Columns;
10637     ru_col = Columns;
10638 #endif
10639 }
10640 
10641 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
10642 /*
10643  * Unset local option value, similar to ":set opt<".
10644  */
10645     void
10646 unset_global_local_option(char_u *name, void *from)
10647 {
10648     struct vimoption *p;
10649     int		opt_idx;
10650     buf_T	*buf = (buf_T *)from;
10651 
10652     opt_idx = findoption(name);
10653     if (opt_idx < 0)
10654 	return;
10655     p = &(options[opt_idx]);
10656 
10657     switch ((int)p->indir)
10658     {
10659 	/* global option with local value: use local value if it's been set */
10660 	case PV_EP:
10661 	    clear_string_option(&buf->b_p_ep);
10662 	    break;
10663 	case PV_KP:
10664 	    clear_string_option(&buf->b_p_kp);
10665 	    break;
10666 	case PV_PATH:
10667 	    clear_string_option(&buf->b_p_path);
10668 	    break;
10669 	case PV_AR:
10670 	    buf->b_p_ar = -1;
10671 	    break;
10672 	case PV_BKC:
10673 	    clear_string_option(&buf->b_p_bkc);
10674 	    buf->b_bkc_flags = 0;
10675 	    break;
10676 	case PV_TAGS:
10677 	    clear_string_option(&buf->b_p_tags);
10678 	    break;
10679 	case PV_TC:
10680 	    clear_string_option(&buf->b_p_tc);
10681 	    buf->b_tc_flags = 0;
10682 	    break;
10683         case PV_SISO:
10684             curwin->w_p_siso = -1;
10685             break;
10686         case PV_SO:
10687             curwin->w_p_so = -1;
10688             break;
10689 #ifdef FEAT_FIND_ID
10690 	case PV_DEF:
10691 	    clear_string_option(&buf->b_p_def);
10692 	    break;
10693 	case PV_INC:
10694 	    clear_string_option(&buf->b_p_inc);
10695 	    break;
10696 #endif
10697 #ifdef FEAT_INS_EXPAND
10698 	case PV_DICT:
10699 	    clear_string_option(&buf->b_p_dict);
10700 	    break;
10701 	case PV_TSR:
10702 	    clear_string_option(&buf->b_p_tsr);
10703 	    break;
10704 #endif
10705 	case PV_FP:
10706 	    clear_string_option(&buf->b_p_fp);
10707 	    break;
10708 #ifdef FEAT_QUICKFIX
10709 	case PV_EFM:
10710 	    clear_string_option(&buf->b_p_efm);
10711 	    break;
10712 	case PV_GP:
10713 	    clear_string_option(&buf->b_p_gp);
10714 	    break;
10715 	case PV_MP:
10716 	    clear_string_option(&buf->b_p_mp);
10717 	    break;
10718 #endif
10719 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10720 	case PV_BEXPR:
10721 	    clear_string_option(&buf->b_p_bexpr);
10722 	    break;
10723 #endif
10724 #if defined(FEAT_CRYPT)
10725 	case PV_CM:
10726 	    clear_string_option(&buf->b_p_cm);
10727 	    break;
10728 #endif
10729 #ifdef FEAT_STL_OPT
10730 	case PV_STL:
10731 	    clear_string_option(&((win_T *)from)->w_p_stl);
10732 	    break;
10733 #endif
10734 	case PV_UL:
10735 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10736 	    break;
10737 #ifdef FEAT_LISP
10738 	case PV_LW:
10739 	    clear_string_option(&buf->b_p_lw);
10740 	    break;
10741 #endif
10742 	case PV_MENC:
10743 	    clear_string_option(&buf->b_p_menc);
10744 	    break;
10745     }
10746 }
10747 #endif
10748 
10749 /*
10750  * Get pointer to option variable, depending on local or global scope.
10751  */
10752     static char_u *
10753 get_varp_scope(struct vimoption *p, int opt_flags)
10754 {
10755     if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10756     {
10757 	if (p->var == VAR_WIN)
10758 	    return (char_u *)GLOBAL_WO(get_varp(p));
10759 	return p->var;
10760     }
10761     if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
10762     {
10763 	switch ((int)p->indir)
10764 	{
10765 	    case PV_FP:   return (char_u *)&(curbuf->b_p_fp);
10766 #ifdef FEAT_QUICKFIX
10767 	    case PV_EFM:  return (char_u *)&(curbuf->b_p_efm);
10768 	    case PV_GP:   return (char_u *)&(curbuf->b_p_gp);
10769 	    case PV_MP:   return (char_u *)&(curbuf->b_p_mp);
10770 #endif
10771 	    case PV_EP:   return (char_u *)&(curbuf->b_p_ep);
10772 	    case PV_KP:   return (char_u *)&(curbuf->b_p_kp);
10773 	    case PV_PATH: return (char_u *)&(curbuf->b_p_path);
10774 	    case PV_AR:   return (char_u *)&(curbuf->b_p_ar);
10775 	    case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
10776 	    case PV_TC:   return (char_u *)&(curbuf->b_p_tc);
10777             case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10778             case PV_SO:   return (char_u *)&(curwin->w_p_so);
10779 #ifdef FEAT_FIND_ID
10780 	    case PV_DEF:  return (char_u *)&(curbuf->b_p_def);
10781 	    case PV_INC:  return (char_u *)&(curbuf->b_p_inc);
10782 #endif
10783 #ifdef FEAT_INS_EXPAND
10784 	    case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10785 	    case PV_TSR:  return (char_u *)&(curbuf->b_p_tsr);
10786 #endif
10787 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10788 	    case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10789 #endif
10790 #if defined(FEAT_CRYPT)
10791 	    case PV_CM:	  return (char_u *)&(curbuf->b_p_cm);
10792 #endif
10793 #ifdef FEAT_STL_OPT
10794 	    case PV_STL:  return (char_u *)&(curwin->w_p_stl);
10795 #endif
10796 	    case PV_UL:   return (char_u *)&(curbuf->b_p_ul);
10797 #ifdef FEAT_LISP
10798 	    case PV_LW:   return (char_u *)&(curbuf->b_p_lw);
10799 #endif
10800 	    case PV_BKC:  return (char_u *)&(curbuf->b_p_bkc);
10801 	    case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10802 	}
10803 	return NULL; /* "cannot happen" */
10804     }
10805     return get_varp(p);
10806 }
10807 
10808 /*
10809  * Get pointer to option variable.
10810  */
10811     static char_u *
10812 get_varp(struct vimoption *p)
10813 {
10814     /* hidden option, always return NULL */
10815     if (p->var == NULL)
10816 	return NULL;
10817 
10818     switch ((int)p->indir)
10819     {
10820 	case PV_NONE:	return p->var;
10821 
10822 	/* global option with local value: use local value if it's been set */
10823 	case PV_EP:	return *curbuf->b_p_ep != NUL
10824 				    ? (char_u *)&curbuf->b_p_ep : p->var;
10825 	case PV_KP:	return *curbuf->b_p_kp != NUL
10826 				    ? (char_u *)&curbuf->b_p_kp : p->var;
10827 	case PV_PATH:	return *curbuf->b_p_path != NUL
10828 				    ? (char_u *)&(curbuf->b_p_path) : p->var;
10829 	case PV_AR:	return curbuf->b_p_ar >= 0
10830 				    ? (char_u *)&(curbuf->b_p_ar) : p->var;
10831 	case PV_TAGS:	return *curbuf->b_p_tags != NUL
10832 				    ? (char_u *)&(curbuf->b_p_tags) : p->var;
10833 	case PV_TC:	return *curbuf->b_p_tc != NUL
10834 				    ? (char_u *)&(curbuf->b_p_tc) : p->var;
10835 	case PV_BKC:	return *curbuf->b_p_bkc != NUL
10836 				    ? (char_u *)&(curbuf->b_p_bkc) : p->var;
10837 	case PV_SISO:	return curwin->w_p_siso >= 0
10838 				    ? (char_u *)&(curwin->w_p_siso) : p->var;
10839 	case PV_SO:	return curwin->w_p_so >= 0
10840 				    ? (char_u *)&(curwin->w_p_so) : p->var;
10841 #ifdef FEAT_FIND_ID
10842 	case PV_DEF:	return *curbuf->b_p_def != NUL
10843 				    ? (char_u *)&(curbuf->b_p_def) : p->var;
10844 	case PV_INC:	return *curbuf->b_p_inc != NUL
10845 				    ? (char_u *)&(curbuf->b_p_inc) : p->var;
10846 #endif
10847 #ifdef FEAT_INS_EXPAND
10848 	case PV_DICT:	return *curbuf->b_p_dict != NUL
10849 				    ? (char_u *)&(curbuf->b_p_dict) : p->var;
10850 	case PV_TSR:	return *curbuf->b_p_tsr != NUL
10851 				    ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10852 #endif
10853 	case PV_FP:	return *curbuf->b_p_fp != NUL
10854 				    ? (char_u *)&(curbuf->b_p_fp) : p->var;
10855 #ifdef FEAT_QUICKFIX
10856 	case PV_EFM:	return *curbuf->b_p_efm != NUL
10857 				    ? (char_u *)&(curbuf->b_p_efm) : p->var;
10858 	case PV_GP:	return *curbuf->b_p_gp != NUL
10859 				    ? (char_u *)&(curbuf->b_p_gp) : p->var;
10860 	case PV_MP:	return *curbuf->b_p_mp != NUL
10861 				    ? (char_u *)&(curbuf->b_p_mp) : p->var;
10862 #endif
10863 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10864 	case PV_BEXPR:	return *curbuf->b_p_bexpr != NUL
10865 				    ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10866 #endif
10867 #if defined(FEAT_CRYPT)
10868 	case PV_CM:	return *curbuf->b_p_cm != NUL
10869 				    ? (char_u *)&(curbuf->b_p_cm) : p->var;
10870 #endif
10871 #ifdef FEAT_STL_OPT
10872 	case PV_STL:	return *curwin->w_p_stl != NUL
10873 				    ? (char_u *)&(curwin->w_p_stl) : p->var;
10874 #endif
10875 	case PV_UL:	return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10876 				    ? (char_u *)&(curbuf->b_p_ul) : p->var;
10877 #ifdef FEAT_LISP
10878 	case PV_LW:	return *curbuf->b_p_lw != NUL
10879 				    ? (char_u *)&(curbuf->b_p_lw) : p->var;
10880 #endif
10881 	case PV_MENC:	return *curbuf->b_p_menc != NUL
10882 				    ? (char_u *)&(curbuf->b_p_menc) : p->var;
10883 
10884 #ifdef FEAT_ARABIC
10885 	case PV_ARAB:	return (char_u *)&(curwin->w_p_arab);
10886 #endif
10887 	case PV_LIST:	return (char_u *)&(curwin->w_p_list);
10888 #ifdef FEAT_SPELL
10889 	case PV_SPELL:	return (char_u *)&(curwin->w_p_spell);
10890 #endif
10891 #ifdef FEAT_SYN_HL
10892 	case PV_CUC:	return (char_u *)&(curwin->w_p_cuc);
10893 	case PV_CUL:	return (char_u *)&(curwin->w_p_cul);
10894 	case PV_CC:	return (char_u *)&(curwin->w_p_cc);
10895 #endif
10896 #ifdef FEAT_DIFF
10897 	case PV_DIFF:	return (char_u *)&(curwin->w_p_diff);
10898 #endif
10899 #ifdef FEAT_FOLDING
10900 	case PV_FDC:	return (char_u *)&(curwin->w_p_fdc);
10901 	case PV_FEN:	return (char_u *)&(curwin->w_p_fen);
10902 	case PV_FDI:	return (char_u *)&(curwin->w_p_fdi);
10903 	case PV_FDL:	return (char_u *)&(curwin->w_p_fdl);
10904 	case PV_FDM:	return (char_u *)&(curwin->w_p_fdm);
10905 	case PV_FML:	return (char_u *)&(curwin->w_p_fml);
10906 	case PV_FDN:	return (char_u *)&(curwin->w_p_fdn);
10907 # ifdef FEAT_EVAL
10908 	case PV_FDE:	return (char_u *)&(curwin->w_p_fde);
10909 	case PV_FDT:	return (char_u *)&(curwin->w_p_fdt);
10910 # endif
10911 	case PV_FMR:	return (char_u *)&(curwin->w_p_fmr);
10912 #endif
10913 	case PV_NU:	return (char_u *)&(curwin->w_p_nu);
10914 	case PV_RNU:	return (char_u *)&(curwin->w_p_rnu);
10915 #ifdef FEAT_LINEBREAK
10916 	case PV_NUW:	return (char_u *)&(curwin->w_p_nuw);
10917 #endif
10918 	case PV_WFH:	return (char_u *)&(curwin->w_p_wfh);
10919 	case PV_WFW:	return (char_u *)&(curwin->w_p_wfw);
10920 #if defined(FEAT_QUICKFIX)
10921 	case PV_PVW:	return (char_u *)&(curwin->w_p_pvw);
10922 #endif
10923 #ifdef FEAT_RIGHTLEFT
10924 	case PV_RL:	return (char_u *)&(curwin->w_p_rl);
10925 	case PV_RLC:	return (char_u *)&(curwin->w_p_rlc);
10926 #endif
10927 	case PV_SCROLL:	return (char_u *)&(curwin->w_p_scr);
10928 	case PV_WRAP:	return (char_u *)&(curwin->w_p_wrap);
10929 #ifdef FEAT_LINEBREAK
10930 	case PV_LBR:	return (char_u *)&(curwin->w_p_lbr);
10931 	case PV_BRI:	return (char_u *)&(curwin->w_p_bri);
10932 	case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
10933 #endif
10934 	case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10935 	case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10936 #ifdef FEAT_CONCEAL
10937 	case PV_COCU:   return (char_u *)&(curwin->w_p_cocu);
10938 	case PV_COLE:   return (char_u *)&(curwin->w_p_cole);
10939 #endif
10940 #ifdef FEAT_TERMINAL
10941 	case PV_TWK:    return (char_u *)&(curwin->w_p_twk);
10942 	case PV_TWS:    return (char_u *)&(curwin->w_p_tws);
10943 	case PV_TWSL:	return (char_u *)&(curbuf->b_p_twsl);
10944 #endif
10945 
10946 	case PV_AI:	return (char_u *)&(curbuf->b_p_ai);
10947 	case PV_BIN:	return (char_u *)&(curbuf->b_p_bin);
10948 	case PV_BOMB:	return (char_u *)&(curbuf->b_p_bomb);
10949 	case PV_BH:	return (char_u *)&(curbuf->b_p_bh);
10950 	case PV_BT:	return (char_u *)&(curbuf->b_p_bt);
10951 	case PV_BL:	return (char_u *)&(curbuf->b_p_bl);
10952 	case PV_CI:	return (char_u *)&(curbuf->b_p_ci);
10953 #ifdef FEAT_CINDENT
10954 	case PV_CIN:	return (char_u *)&(curbuf->b_p_cin);
10955 	case PV_CINK:	return (char_u *)&(curbuf->b_p_cink);
10956 	case PV_CINO:	return (char_u *)&(curbuf->b_p_cino);
10957 #endif
10958 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10959 	case PV_CINW:	return (char_u *)&(curbuf->b_p_cinw);
10960 #endif
10961 #ifdef FEAT_COMMENTS
10962 	case PV_COM:	return (char_u *)&(curbuf->b_p_com);
10963 #endif
10964 #ifdef FEAT_FOLDING
10965 	case PV_CMS:	return (char_u *)&(curbuf->b_p_cms);
10966 #endif
10967 #ifdef FEAT_INS_EXPAND
10968 	case PV_CPT:	return (char_u *)&(curbuf->b_p_cpt);
10969 #endif
10970 #ifdef FEAT_COMPL_FUNC
10971 	case PV_CFU:	return (char_u *)&(curbuf->b_p_cfu);
10972 	case PV_OFU:	return (char_u *)&(curbuf->b_p_ofu);
10973 #endif
10974 #ifdef FEAT_EVAL
10975 	case PV_TFU:	return (char_u *)&(curbuf->b_p_tfu);
10976 #endif
10977 	case PV_EOL:	return (char_u *)&(curbuf->b_p_eol);
10978 	case PV_FIXEOL:	return (char_u *)&(curbuf->b_p_fixeol);
10979 	case PV_ET:	return (char_u *)&(curbuf->b_p_et);
10980 	case PV_FENC:	return (char_u *)&(curbuf->b_p_fenc);
10981 	case PV_FF:	return (char_u *)&(curbuf->b_p_ff);
10982 	case PV_FT:	return (char_u *)&(curbuf->b_p_ft);
10983 	case PV_FO:	return (char_u *)&(curbuf->b_p_fo);
10984 	case PV_FLP:	return (char_u *)&(curbuf->b_p_flp);
10985 	case PV_IMI:	return (char_u *)&(curbuf->b_p_iminsert);
10986 	case PV_IMS:	return (char_u *)&(curbuf->b_p_imsearch);
10987 	case PV_INF:	return (char_u *)&(curbuf->b_p_inf);
10988 	case PV_ISK:	return (char_u *)&(curbuf->b_p_isk);
10989 #ifdef FEAT_FIND_ID
10990 # ifdef FEAT_EVAL
10991 	case PV_INEX:	return (char_u *)&(curbuf->b_p_inex);
10992 # endif
10993 #endif
10994 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10995 	case PV_INDE:	return (char_u *)&(curbuf->b_p_inde);
10996 	case PV_INDK:	return (char_u *)&(curbuf->b_p_indk);
10997 #endif
10998 #ifdef FEAT_EVAL
10999 	case PV_FEX:	return (char_u *)&(curbuf->b_p_fex);
11000 #endif
11001 #ifdef FEAT_CRYPT
11002 	case PV_KEY:	return (char_u *)&(curbuf->b_p_key);
11003 #endif
11004 #ifdef FEAT_LISP
11005 	case PV_LISP:	return (char_u *)&(curbuf->b_p_lisp);
11006 #endif
11007 	case PV_ML:	return (char_u *)&(curbuf->b_p_ml);
11008 	case PV_MPS:	return (char_u *)&(curbuf->b_p_mps);
11009 	case PV_MA:	return (char_u *)&(curbuf->b_p_ma);
11010 	case PV_MOD:	return (char_u *)&(curbuf->b_changed);
11011 	case PV_NF:	return (char_u *)&(curbuf->b_p_nf);
11012 	case PV_PI:	return (char_u *)&(curbuf->b_p_pi);
11013 #ifdef FEAT_TEXTOBJ
11014 	case PV_QE:	return (char_u *)&(curbuf->b_p_qe);
11015 #endif
11016 	case PV_RO:	return (char_u *)&(curbuf->b_p_ro);
11017 #ifdef FEAT_SMARTINDENT
11018 	case PV_SI:	return (char_u *)&(curbuf->b_p_si);
11019 #endif
11020 	case PV_SN:	return (char_u *)&(curbuf->b_p_sn);
11021 	case PV_STS:	return (char_u *)&(curbuf->b_p_sts);
11022 #ifdef FEAT_SEARCHPATH
11023 	case PV_SUA:	return (char_u *)&(curbuf->b_p_sua);
11024 #endif
11025 	case PV_SWF:	return (char_u *)&(curbuf->b_p_swf);
11026 #ifdef FEAT_SYN_HL
11027 	case PV_SMC:	return (char_u *)&(curbuf->b_p_smc);
11028 	case PV_SYN:	return (char_u *)&(curbuf->b_p_syn);
11029 #endif
11030 #ifdef FEAT_SPELL
11031 	case PV_SPC:	return (char_u *)&(curwin->w_s->b_p_spc);
11032 	case PV_SPF:	return (char_u *)&(curwin->w_s->b_p_spf);
11033 	case PV_SPL:	return (char_u *)&(curwin->w_s->b_p_spl);
11034 #endif
11035 	case PV_SW:	return (char_u *)&(curbuf->b_p_sw);
11036 	case PV_TS:	return (char_u *)&(curbuf->b_p_ts);
11037 	case PV_TW:	return (char_u *)&(curbuf->b_p_tw);
11038 	case PV_TX:	return (char_u *)&(curbuf->b_p_tx);
11039 #ifdef FEAT_PERSISTENT_UNDO
11040 	case PV_UDF:	return (char_u *)&(curbuf->b_p_udf);
11041 #endif
11042 	case PV_WM:	return (char_u *)&(curbuf->b_p_wm);
11043 #ifdef FEAT_KEYMAP
11044 	case PV_KMAP:	return (char_u *)&(curbuf->b_p_keymap);
11045 #endif
11046 #ifdef FEAT_SIGNS
11047 	case PV_SCL:	return (char_u *)&(curwin->w_p_scl);
11048 #endif
11049 #ifdef FEAT_VARTABS
11050 	case PV_VSTS:	return (char_u *)&(curbuf->b_p_vsts);
11051 	case PV_VTS:	return (char_u *)&(curbuf->b_p_vts);
11052 #endif
11053 	default:	iemsg(_("E356: get_varp ERROR"));
11054     }
11055     /* always return a valid pointer to avoid a crash! */
11056     return (char_u *)&(curbuf->b_p_wm);
11057 }
11058 
11059 /*
11060  * Get the value of 'equalprg', either the buffer-local one or the global one.
11061  */
11062     char_u *
11063 get_equalprg(void)
11064 {
11065     if (*curbuf->b_p_ep == NUL)
11066 	return p_ep;
11067     return curbuf->b_p_ep;
11068 }
11069 
11070 /*
11071  * Copy options from one window to another.
11072  * Used when splitting a window.
11073  */
11074     void
11075 win_copy_options(win_T *wp_from, win_T *wp_to)
11076 {
11077     copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11078     copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11079 #if defined(FEAT_LINEBREAK)
11080     briopt_check(wp_to);
11081 #endif
11082 }
11083 
11084 /*
11085  * Copy the options from one winopt_T to another.
11086  * Doesn't free the old option values in "to", use clear_winopt() for that.
11087  * The 'scroll' option is not copied, because it depends on the window height.
11088  * The 'previewwindow' option is reset, there can be only one preview window.
11089  */
11090     void
11091 copy_winopt(winopt_T *from, winopt_T *to)
11092 {
11093 #ifdef FEAT_ARABIC
11094     to->wo_arab = from->wo_arab;
11095 #endif
11096     to->wo_list = from->wo_list;
11097     to->wo_nu = from->wo_nu;
11098     to->wo_rnu = from->wo_rnu;
11099 #ifdef FEAT_LINEBREAK
11100     to->wo_nuw = from->wo_nuw;
11101 #endif
11102 #ifdef FEAT_RIGHTLEFT
11103     to->wo_rl  = from->wo_rl;
11104     to->wo_rlc = vim_strsave(from->wo_rlc);
11105 #endif
11106 #ifdef FEAT_STL_OPT
11107     to->wo_stl = vim_strsave(from->wo_stl);
11108 #endif
11109     to->wo_wrap = from->wo_wrap;
11110 #ifdef FEAT_DIFF
11111     to->wo_wrap_save = from->wo_wrap_save;
11112 #endif
11113 #ifdef FEAT_LINEBREAK
11114     to->wo_lbr = from->wo_lbr;
11115     to->wo_bri = from->wo_bri;
11116     to->wo_briopt = vim_strsave(from->wo_briopt);
11117 #endif
11118     to->wo_scb = from->wo_scb;
11119     to->wo_scb_save = from->wo_scb_save;
11120     to->wo_crb = from->wo_crb;
11121     to->wo_crb_save = from->wo_crb_save;
11122 #ifdef FEAT_SPELL
11123     to->wo_spell = from->wo_spell;
11124 #endif
11125 #ifdef FEAT_SYN_HL
11126     to->wo_cuc = from->wo_cuc;
11127     to->wo_cul = from->wo_cul;
11128     to->wo_cc = vim_strsave(from->wo_cc);
11129 #endif
11130 #ifdef FEAT_DIFF
11131     to->wo_diff = from->wo_diff;
11132     to->wo_diff_saved = from->wo_diff_saved;
11133 #endif
11134 #ifdef FEAT_CONCEAL
11135     to->wo_cocu = vim_strsave(from->wo_cocu);
11136     to->wo_cole = from->wo_cole;
11137 #endif
11138 #ifdef FEAT_TERMINAL
11139     to->wo_twk = vim_strsave(from->wo_twk);
11140     to->wo_tws = vim_strsave(from->wo_tws);
11141 #endif
11142 #ifdef FEAT_FOLDING
11143     to->wo_fdc = from->wo_fdc;
11144     to->wo_fdc_save = from->wo_fdc_save;
11145     to->wo_fen = from->wo_fen;
11146     to->wo_fen_save = from->wo_fen_save;
11147     to->wo_fdi = vim_strsave(from->wo_fdi);
11148     to->wo_fml = from->wo_fml;
11149     to->wo_fdl = from->wo_fdl;
11150     to->wo_fdl_save = from->wo_fdl_save;
11151     to->wo_fdm = vim_strsave(from->wo_fdm);
11152     to->wo_fdm_save = from->wo_diff_saved
11153 			      ? vim_strsave(from->wo_fdm_save) : empty_option;
11154     to->wo_fdn = from->wo_fdn;
11155 # ifdef FEAT_EVAL
11156     to->wo_fde = vim_strsave(from->wo_fde);
11157     to->wo_fdt = vim_strsave(from->wo_fdt);
11158 # endif
11159     to->wo_fmr = vim_strsave(from->wo_fmr);
11160 #endif
11161 #ifdef FEAT_SIGNS
11162     to->wo_scl = vim_strsave(from->wo_scl);
11163 #endif
11164     check_winopt(to);		/* don't want NULL pointers */
11165 }
11166 
11167 /*
11168  * Check string options in a window for a NULL value.
11169  */
11170     void
11171 check_win_options(win_T *win)
11172 {
11173     check_winopt(&win->w_onebuf_opt);
11174     check_winopt(&win->w_allbuf_opt);
11175 }
11176 
11177 /*
11178  * Check for NULL pointers in a winopt_T and replace them with empty_option.
11179  */
11180     static void
11181 check_winopt(winopt_T *wop UNUSED)
11182 {
11183 #ifdef FEAT_FOLDING
11184     check_string_option(&wop->wo_fdi);
11185     check_string_option(&wop->wo_fdm);
11186     check_string_option(&wop->wo_fdm_save);
11187 # ifdef FEAT_EVAL
11188     check_string_option(&wop->wo_fde);
11189     check_string_option(&wop->wo_fdt);
11190 # endif
11191     check_string_option(&wop->wo_fmr);
11192 #endif
11193 #ifdef FEAT_SIGNS
11194     check_string_option(&wop->wo_scl);
11195 #endif
11196 #ifdef FEAT_RIGHTLEFT
11197     check_string_option(&wop->wo_rlc);
11198 #endif
11199 #ifdef FEAT_STL_OPT
11200     check_string_option(&wop->wo_stl);
11201 #endif
11202 #ifdef FEAT_SYN_HL
11203     check_string_option(&wop->wo_cc);
11204 #endif
11205 #ifdef FEAT_CONCEAL
11206     check_string_option(&wop->wo_cocu);
11207 #endif
11208 #ifdef FEAT_TERMINAL
11209     check_string_option(&wop->wo_twk);
11210     check_string_option(&wop->wo_tws);
11211 #endif
11212 #ifdef FEAT_LINEBREAK
11213     check_string_option(&wop->wo_briopt);
11214 #endif
11215 }
11216 
11217 /*
11218  * Free the allocated memory inside a winopt_T.
11219  */
11220     void
11221 clear_winopt(winopt_T *wop UNUSED)
11222 {
11223 #ifdef FEAT_FOLDING
11224     clear_string_option(&wop->wo_fdi);
11225     clear_string_option(&wop->wo_fdm);
11226     clear_string_option(&wop->wo_fdm_save);
11227 # ifdef FEAT_EVAL
11228     clear_string_option(&wop->wo_fde);
11229     clear_string_option(&wop->wo_fdt);
11230 # endif
11231     clear_string_option(&wop->wo_fmr);
11232 #endif
11233 #ifdef FEAT_SIGNS
11234     clear_string_option(&wop->wo_scl);
11235 #endif
11236 #ifdef FEAT_LINEBREAK
11237     clear_string_option(&wop->wo_briopt);
11238 #endif
11239 #ifdef FEAT_RIGHTLEFT
11240     clear_string_option(&wop->wo_rlc);
11241 #endif
11242 #ifdef FEAT_STL_OPT
11243     clear_string_option(&wop->wo_stl);
11244 #endif
11245 #ifdef FEAT_SYN_HL
11246     clear_string_option(&wop->wo_cc);
11247 #endif
11248 #ifdef FEAT_CONCEAL
11249     clear_string_option(&wop->wo_cocu);
11250 #endif
11251 #ifdef FEAT_TERMINAL
11252     clear_string_option(&wop->wo_twk);
11253     clear_string_option(&wop->wo_tws);
11254 #endif
11255 }
11256 
11257 /*
11258  * Copy global option values to local options for one buffer.
11259  * Used when creating a new buffer and sometimes when entering a buffer.
11260  * flags:
11261  * BCO_ENTER	We will enter the buf buffer.
11262  * BCO_ALWAYS	Always copy the options, but only set b_p_initialized when
11263  *		appropriate.
11264  * BCO_NOHELP	Don't copy the values to a help buffer.
11265  */
11266     void
11267 buf_copy_options(buf_T *buf, int flags)
11268 {
11269     int		should_copy = TRUE;
11270     char_u	*save_p_isk = NULL;	    /* init for GCC */
11271     int		dont_do_help;
11272     int		did_isk = FALSE;
11273 
11274     /*
11275      * Skip this when the option defaults have not been set yet.  Happens when
11276      * main() allocates the first buffer.
11277      */
11278     if (p_cpo != NULL)
11279     {
11280 	/*
11281 	 * Always copy when entering and 'cpo' contains 'S'.
11282 	 * Don't copy when already initialized.
11283 	 * Don't copy when 'cpo' contains 's' and not entering.
11284 	 * 'S'	BCO_ENTER  initialized	's'  should_copy
11285 	 * yes	  yes	       X	 X	TRUE
11286 	 * yes	  no	      yes	 X	FALSE
11287 	 * no	   X	      yes	 X	FALSE
11288 	 *  X	  no	      no	yes	FALSE
11289 	 *  X	  no	      no	no	TRUE
11290 	 * no	  yes	      no	 X	TRUE
11291 	 */
11292 	if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11293 		&& (buf->b_p_initialized
11294 		    || (!(flags & BCO_ENTER)
11295 			&& vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11296 	    should_copy = FALSE;
11297 
11298 	if (should_copy || (flags & BCO_ALWAYS))
11299 	{
11300 	    /* Don't copy the options specific to a help buffer when
11301 	     * BCO_NOHELP is given or the options were initialized already
11302 	     * (jumping back to a help file with CTRL-T or CTRL-O) */
11303 	    dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11304 						       || buf->b_p_initialized;
11305 	    if (dont_do_help)		/* don't free b_p_isk */
11306 	    {
11307 		save_p_isk = buf->b_p_isk;
11308 		buf->b_p_isk = NULL;
11309 	    }
11310 	    /*
11311 	     * Always free the allocated strings.  If not already initialized,
11312 	     * reset 'readonly' and copy 'fileformat'.
11313 	     */
11314 	    if (!buf->b_p_initialized)
11315 	    {
11316 		free_buf_options(buf, TRUE);
11317 		buf->b_p_ro = FALSE;		/* don't copy readonly */
11318 		buf->b_p_tx = p_tx;
11319 		buf->b_p_fenc = vim_strsave(p_fenc);
11320 		switch (*p_ffs)
11321 		{
11322 		    case 'm':
11323 			buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11324 		    case 'd':
11325 			buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11326 		    case 'u':
11327 			buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11328 		    default:
11329 			buf->b_p_ff = vim_strsave(p_ff);
11330 		}
11331 		if (buf->b_p_ff != NULL)
11332 		    buf->b_start_ffc = *buf->b_p_ff;
11333 		buf->b_p_bh = empty_option;
11334 		buf->b_p_bt = empty_option;
11335 	    }
11336 	    else
11337 		free_buf_options(buf, FALSE);
11338 
11339 	    buf->b_p_ai = p_ai;
11340 	    buf->b_p_ai_nopaste = p_ai_nopaste;
11341 	    buf->b_p_sw = p_sw;
11342 	    buf->b_p_tw = p_tw;
11343 	    buf->b_p_tw_nopaste = p_tw_nopaste;
11344 	    buf->b_p_tw_nobin = p_tw_nobin;
11345 	    buf->b_p_wm = p_wm;
11346 	    buf->b_p_wm_nopaste = p_wm_nopaste;
11347 	    buf->b_p_wm_nobin = p_wm_nobin;
11348 	    buf->b_p_bin = p_bin;
11349 	    buf->b_p_bomb = p_bomb;
11350 	    buf->b_p_fixeol = p_fixeol;
11351 	    buf->b_p_et = p_et;
11352 	    buf->b_p_et_nobin = p_et_nobin;
11353 	    buf->b_p_et_nopaste = p_et_nopaste;
11354 	    buf->b_p_ml = p_ml;
11355 	    buf->b_p_ml_nobin = p_ml_nobin;
11356 	    buf->b_p_inf = p_inf;
11357 	    buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
11358 #ifdef FEAT_INS_EXPAND
11359 	    buf->b_p_cpt = vim_strsave(p_cpt);
11360 #endif
11361 #ifdef FEAT_COMPL_FUNC
11362 	    buf->b_p_cfu = vim_strsave(p_cfu);
11363 	    buf->b_p_ofu = vim_strsave(p_ofu);
11364 #endif
11365 #ifdef FEAT_EVAL
11366 	    buf->b_p_tfu = vim_strsave(p_tfu);
11367 #endif
11368 	    buf->b_p_sts = p_sts;
11369 	    buf->b_p_sts_nopaste = p_sts_nopaste;
11370 #ifdef FEAT_VARTABS
11371 	    buf->b_p_vsts = vim_strsave(p_vsts);
11372 	    if (p_vsts && p_vsts != empty_option)
11373 		tabstop_set(p_vsts, &buf->b_p_vsts_array);
11374 	    else
11375 		buf->b_p_vsts_array = 0;
11376 	    buf->b_p_vsts_nopaste = p_vsts_nopaste
11377 				 ? vim_strsave(p_vsts_nopaste) : NULL;
11378 #endif
11379 	    buf->b_p_sn = p_sn;
11380 #ifdef FEAT_COMMENTS
11381 	    buf->b_p_com = vim_strsave(p_com);
11382 #endif
11383 #ifdef FEAT_FOLDING
11384 	    buf->b_p_cms = vim_strsave(p_cms);
11385 #endif
11386 	    buf->b_p_fo = vim_strsave(p_fo);
11387 	    buf->b_p_flp = vim_strsave(p_flp);
11388 	    buf->b_p_nf = vim_strsave(p_nf);
11389 	    buf->b_p_mps = vim_strsave(p_mps);
11390 #ifdef FEAT_SMARTINDENT
11391 	    buf->b_p_si = p_si;
11392 #endif
11393 	    buf->b_p_ci = p_ci;
11394 #ifdef FEAT_CINDENT
11395 	    buf->b_p_cin = p_cin;
11396 	    buf->b_p_cink = vim_strsave(p_cink);
11397 	    buf->b_p_cino = vim_strsave(p_cino);
11398 #endif
11399 	    /* Don't copy 'filetype', it must be detected */
11400 	    buf->b_p_ft = empty_option;
11401 	    buf->b_p_pi = p_pi;
11402 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11403 	    buf->b_p_cinw = vim_strsave(p_cinw);
11404 #endif
11405 #ifdef FEAT_LISP
11406 	    buf->b_p_lisp = p_lisp;
11407 #endif
11408 #ifdef FEAT_SYN_HL
11409 	    /* Don't copy 'syntax', it must be set */
11410 	    buf->b_p_syn = empty_option;
11411 	    buf->b_p_smc = p_smc;
11412 	    buf->b_s.b_syn_isk = empty_option;
11413 #endif
11414 #ifdef FEAT_SPELL
11415 	    buf->b_s.b_p_spc = vim_strsave(p_spc);
11416 	    (void)compile_cap_prog(&buf->b_s);
11417 	    buf->b_s.b_p_spf = vim_strsave(p_spf);
11418 	    buf->b_s.b_p_spl = vim_strsave(p_spl);
11419 #endif
11420 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11421 	    buf->b_p_inde = vim_strsave(p_inde);
11422 	    buf->b_p_indk = vim_strsave(p_indk);
11423 #endif
11424 	    buf->b_p_fp = empty_option;
11425 #if defined(FEAT_EVAL)
11426 	    buf->b_p_fex = vim_strsave(p_fex);
11427 #endif
11428 #ifdef FEAT_CRYPT
11429 	    buf->b_p_key = vim_strsave(p_key);
11430 #endif
11431 #ifdef FEAT_SEARCHPATH
11432 	    buf->b_p_sua = vim_strsave(p_sua);
11433 #endif
11434 #ifdef FEAT_KEYMAP
11435 	    buf->b_p_keymap = vim_strsave(p_keymap);
11436 	    buf->b_kmap_state |= KEYMAP_INIT;
11437 #endif
11438 #ifdef FEAT_TERMINAL
11439 	    buf->b_p_twsl = p_twsl;
11440 #endif
11441 	    /* This isn't really an option, but copying the langmap and IME
11442 	     * state from the current buffer is better than resetting it. */
11443 	    buf->b_p_iminsert = p_iminsert;
11444 	    buf->b_p_imsearch = p_imsearch;
11445 
11446 	    /* options that are normally global but also have a local value
11447 	     * are not copied, start using the global value */
11448 	    buf->b_p_ar = -1;
11449 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
11450 	    buf->b_p_bkc = empty_option;
11451 	    buf->b_bkc_flags = 0;
11452 #ifdef FEAT_QUICKFIX
11453 	    buf->b_p_gp = empty_option;
11454 	    buf->b_p_mp = empty_option;
11455 	    buf->b_p_efm = empty_option;
11456 #endif
11457 	    buf->b_p_ep = empty_option;
11458 	    buf->b_p_kp = empty_option;
11459 	    buf->b_p_path = empty_option;
11460 	    buf->b_p_tags = empty_option;
11461 	    buf->b_p_tc = empty_option;
11462 	    buf->b_tc_flags = 0;
11463 #ifdef FEAT_FIND_ID
11464 	    buf->b_p_def = empty_option;
11465 	    buf->b_p_inc = empty_option;
11466 # ifdef FEAT_EVAL
11467 	    buf->b_p_inex = vim_strsave(p_inex);
11468 # endif
11469 #endif
11470 #ifdef FEAT_INS_EXPAND
11471 	    buf->b_p_dict = empty_option;
11472 	    buf->b_p_tsr = empty_option;
11473 #endif
11474 #ifdef FEAT_TEXTOBJ
11475 	    buf->b_p_qe = vim_strsave(p_qe);
11476 #endif
11477 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11478 	    buf->b_p_bexpr = empty_option;
11479 #endif
11480 #if defined(FEAT_CRYPT)
11481 	    buf->b_p_cm = empty_option;
11482 #endif
11483 #ifdef FEAT_PERSISTENT_UNDO
11484 	    buf->b_p_udf = p_udf;
11485 #endif
11486 #ifdef FEAT_LISP
11487 	    buf->b_p_lw = empty_option;
11488 #endif
11489 	    buf->b_p_menc = empty_option;
11490 
11491 	    /*
11492 	     * Don't copy the options set by ex_help(), use the saved values,
11493 	     * when going from a help buffer to a non-help buffer.
11494 	     * Don't touch these at all when BCO_NOHELP is used and going from
11495 	     * or to a help buffer.
11496 	     */
11497 	    if (dont_do_help)
11498 	    {
11499 		buf->b_p_isk = save_p_isk;
11500 #ifdef FEAT_VARTABS
11501 		if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11502 		    tabstop_set(p_vts, &buf->b_p_vts_array);
11503 		else
11504 		    buf->b_p_vts_array = NULL;
11505 #endif
11506 	    }
11507 	    else
11508 	    {
11509 		buf->b_p_isk = vim_strsave(p_isk);
11510 		did_isk = TRUE;
11511 		buf->b_p_ts = p_ts;
11512 #ifdef FEAT_VARTABS
11513 		buf->b_p_vts = vim_strsave(p_vts);
11514 		if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11515 		    tabstop_set(p_vts, &buf->b_p_vts_array);
11516 		else
11517 		    buf->b_p_vts_array = NULL;
11518 #endif
11519 		buf->b_help = FALSE;
11520 		if (buf->b_p_bt[0] == 'h')
11521 		    clear_string_option(&buf->b_p_bt);
11522 		buf->b_p_ma = p_ma;
11523 	    }
11524 	}
11525 
11526 	/*
11527 	 * When the options should be copied (ignoring BCO_ALWAYS), set the
11528 	 * flag that indicates that the options have been initialized.
11529 	 */
11530 	if (should_copy)
11531 	    buf->b_p_initialized = TRUE;
11532     }
11533 
11534     check_buf_options(buf);	    /* make sure we don't have NULLs */
11535     if (did_isk)
11536 	(void)buf_init_chartab(buf, FALSE);
11537 }
11538 
11539 /*
11540  * Reset the 'modifiable' option and its default value.
11541  */
11542     void
11543 reset_modifiable(void)
11544 {
11545     int		opt_idx;
11546 
11547     curbuf->b_p_ma = FALSE;
11548     p_ma = FALSE;
11549     opt_idx = findoption((char_u *)"ma");
11550     if (opt_idx >= 0)
11551 	options[opt_idx].def_val[VI_DEFAULT] = FALSE;
11552 }
11553 
11554 /*
11555  * Set the global value for 'iminsert' to the local value.
11556  */
11557     void
11558 set_iminsert_global(void)
11559 {
11560     p_iminsert = curbuf->b_p_iminsert;
11561 }
11562 
11563 /*
11564  * Set the global value for 'imsearch' to the local value.
11565  */
11566     void
11567 set_imsearch_global(void)
11568 {
11569     p_imsearch = curbuf->b_p_imsearch;
11570 }
11571 
11572 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11573 static int expand_option_idx = -1;
11574 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11575 static int expand_option_flags = 0;
11576 
11577     void
11578 set_context_in_set_cmd(
11579     expand_T	*xp,
11580     char_u	*arg,
11581     int		opt_flags)	/* OPT_GLOBAL and/or OPT_LOCAL */
11582 {
11583     int		nextchar;
11584     long_u	flags = 0;	/* init for GCC */
11585     int		opt_idx = 0;	/* init for GCC */
11586     char_u	*p;
11587     char_u	*s;
11588     int		is_term_option = FALSE;
11589     int		key;
11590 
11591     expand_option_flags = opt_flags;
11592 
11593     xp->xp_context = EXPAND_SETTINGS;
11594     if (*arg == NUL)
11595     {
11596 	xp->xp_pattern = arg;
11597 	return;
11598     }
11599     p = arg + STRLEN(arg) - 1;
11600     if (*p == ' ' && *(p - 1) != '\\')
11601     {
11602 	xp->xp_pattern = p + 1;
11603 	return;
11604     }
11605     while (p > arg)
11606     {
11607 	s = p;
11608 	/* count number of backslashes before ' ' or ',' */
11609 	if (*p == ' ' || *p == ',')
11610 	{
11611 	    while (s > arg && *(s - 1) == '\\')
11612 		--s;
11613 	}
11614 	/* break at a space with an even number of backslashes */
11615 	if (*p == ' ' && ((p - s) & 1) == 0)
11616 	{
11617 	    ++p;
11618 	    break;
11619 	}
11620 	--p;
11621     }
11622     if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
11623     {
11624 	xp->xp_context = EXPAND_BOOL_SETTINGS;
11625 	p += 2;
11626     }
11627     if (STRNCMP(p, "inv", 3) == 0)
11628     {
11629 	xp->xp_context = EXPAND_BOOL_SETTINGS;
11630 	p += 3;
11631     }
11632     xp->xp_pattern = arg = p;
11633     if (*arg == '<')
11634     {
11635 	while (*p != '>')
11636 	    if (*p++ == NUL)	    /* expand terminal option name */
11637 		return;
11638 	key = get_special_key_code(arg + 1);
11639 	if (key == 0)		    /* unknown name */
11640 	{
11641 	    xp->xp_context = EXPAND_NOTHING;
11642 	    return;
11643 	}
11644 	nextchar = *++p;
11645 	is_term_option = TRUE;
11646 	expand_option_name[2] = KEY2TERMCAP0(key);
11647 	expand_option_name[3] = KEY2TERMCAP1(key);
11648     }
11649     else
11650     {
11651 	if (p[0] == 't' && p[1] == '_')
11652 	{
11653 	    p += 2;
11654 	    if (*p != NUL)
11655 		++p;
11656 	    if (*p == NUL)
11657 		return;		/* expand option name */
11658 	    nextchar = *++p;
11659 	    is_term_option = TRUE;
11660 	    expand_option_name[2] = p[-2];
11661 	    expand_option_name[3] = p[-1];
11662 	}
11663 	else
11664 	{
11665 		/* Allow * wildcard */
11666 	    while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11667 		p++;
11668 	    if (*p == NUL)
11669 		return;
11670 	    nextchar = *p;
11671 	    *p = NUL;
11672 	    opt_idx = findoption(arg);
11673 	    *p = nextchar;
11674 	    if (opt_idx == -1 || options[opt_idx].var == NULL)
11675 	    {
11676 		xp->xp_context = EXPAND_NOTHING;
11677 		return;
11678 	    }
11679 	    flags = options[opt_idx].flags;
11680 	    if (flags & P_BOOL)
11681 	    {
11682 		xp->xp_context = EXPAND_NOTHING;
11683 		return;
11684 	    }
11685 	}
11686     }
11687     /* handle "-=" and "+=" */
11688     if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11689     {
11690 	++p;
11691 	nextchar = '=';
11692     }
11693     if ((nextchar != '=' && nextchar != ':')
11694 				    || xp->xp_context == EXPAND_BOOL_SETTINGS)
11695     {
11696 	xp->xp_context = EXPAND_UNSUCCESSFUL;
11697 	return;
11698     }
11699     if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11700     {
11701 	xp->xp_context = EXPAND_OLD_SETTING;
11702 	if (is_term_option)
11703 	    expand_option_idx = -1;
11704 	else
11705 	    expand_option_idx = opt_idx;
11706 	xp->xp_pattern = p + 1;
11707 	return;
11708     }
11709     xp->xp_context = EXPAND_NOTHING;
11710     if (is_term_option || (flags & P_NUM))
11711 	return;
11712 
11713     xp->xp_pattern = p + 1;
11714 
11715     if (flags & P_EXPAND)
11716     {
11717 	p = options[opt_idx].var;
11718 	if (p == (char_u *)&p_bdir
11719 		|| p == (char_u *)&p_dir
11720 		|| p == (char_u *)&p_path
11721 		|| p == (char_u *)&p_pp
11722 		|| p == (char_u *)&p_rtp
11723 #ifdef FEAT_SEARCHPATH
11724 		|| p == (char_u *)&p_cdpath
11725 #endif
11726 #ifdef FEAT_SESSION
11727 		|| p == (char_u *)&p_vdir
11728 #endif
11729 		)
11730 	{
11731 	    xp->xp_context = EXPAND_DIRECTORIES;
11732 	    if (p == (char_u *)&p_path
11733 #ifdef FEAT_SEARCHPATH
11734 		    || p == (char_u *)&p_cdpath
11735 #endif
11736 		   )
11737 		xp->xp_backslash = XP_BS_THREE;
11738 	    else
11739 		xp->xp_backslash = XP_BS_ONE;
11740 	}
11741 	else
11742 	{
11743 	    xp->xp_context = EXPAND_FILES;
11744 	    /* for 'tags' need three backslashes for a space */
11745 	    if (p == (char_u *)&p_tags)
11746 		xp->xp_backslash = XP_BS_THREE;
11747 	    else
11748 		xp->xp_backslash = XP_BS_ONE;
11749 	}
11750     }
11751 
11752     /* For an option that is a list of file names, find the start of the
11753      * last file name. */
11754     for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11755     {
11756 	/* count number of backslashes before ' ' or ',' */
11757 	if (*p == ' ' || *p == ',')
11758 	{
11759 	    s = p;
11760 	    while (s > xp->xp_pattern && *(s - 1) == '\\')
11761 		--s;
11762 	    if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11763 		    || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11764 	    {
11765 		xp->xp_pattern = p + 1;
11766 		break;
11767 	    }
11768 	}
11769 
11770 #ifdef FEAT_SPELL
11771 	/* for 'spellsuggest' start at "file:" */
11772 	if (options[opt_idx].var == (char_u *)&p_sps
11773 					       && STRNCMP(p, "file:", 5) == 0)
11774 	{
11775 	    xp->xp_pattern = p + 5;
11776 	    break;
11777 	}
11778 #endif
11779     }
11780 
11781     return;
11782 }
11783 
11784     int
11785 ExpandSettings(
11786     expand_T	*xp,
11787     regmatch_T	*regmatch,
11788     int		*num_file,
11789     char_u	***file)
11790 {
11791     int		num_normal = 0;	    /* Nr of matching non-term-code settings */
11792     int		num_term = 0;	    /* Nr of matching terminal code settings */
11793     int		opt_idx;
11794     int		match;
11795     int		count = 0;
11796     char_u	*str;
11797     int		loop;
11798     int		is_term_opt;
11799     char_u	name_buf[MAX_KEY_NAME_LEN];
11800     static char *(names[]) = {"all", "termcap"};
11801     int		ic = regmatch->rm_ic;	/* remember the ignore-case flag */
11802 
11803     /* do this loop twice:
11804      * loop == 0: count the number of matching options
11805      * loop == 1: copy the matching options into allocated memory
11806      */
11807     for (loop = 0; loop <= 1; ++loop)
11808     {
11809 	regmatch->rm_ic = ic;
11810 	if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11811 	{
11812 	    for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11813 								      ++match)
11814 		if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11815 		{
11816 		    if (loop == 0)
11817 			num_normal++;
11818 		    else
11819 			(*file)[count++] = vim_strsave((char_u *)names[match]);
11820 		}
11821 	}
11822 	for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11823 								    opt_idx++)
11824 	{
11825 	    if (options[opt_idx].var == NULL)
11826 		continue;
11827 	    if (xp->xp_context == EXPAND_BOOL_SETTINGS
11828 	      && !(options[opt_idx].flags & P_BOOL))
11829 		continue;
11830 	    is_term_opt = istermoption(&options[opt_idx]);
11831 	    if (is_term_opt && num_normal > 0)
11832 		continue;
11833 	    match = FALSE;
11834 	    if (vim_regexec(regmatch, str, (colnr_T)0)
11835 		    || (options[opt_idx].shortname != NULL
11836 			&& vim_regexec(regmatch,
11837 			   (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11838 		match = TRUE;
11839 	    else if (is_term_opt)
11840 	    {
11841 		name_buf[0] = '<';
11842 		name_buf[1] = 't';
11843 		name_buf[2] = '_';
11844 		name_buf[3] = str[2];
11845 		name_buf[4] = str[3];
11846 		name_buf[5] = '>';
11847 		name_buf[6] = NUL;
11848 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11849 		{
11850 		    match = TRUE;
11851 		    str = name_buf;
11852 		}
11853 	    }
11854 	    if (match)
11855 	    {
11856 		if (loop == 0)
11857 		{
11858 		    if (is_term_opt)
11859 			num_term++;
11860 		    else
11861 			num_normal++;
11862 		}
11863 		else
11864 		    (*file)[count++] = vim_strsave(str);
11865 	    }
11866 	}
11867 	/*
11868 	 * Check terminal key codes, these are not in the option table
11869 	 */
11870 	if (xp->xp_context != EXPAND_BOOL_SETTINGS  && num_normal == 0)
11871 	{
11872 	    for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11873 	    {
11874 		if (!isprint(str[0]) || !isprint(str[1]))
11875 		    continue;
11876 
11877 		name_buf[0] = 't';
11878 		name_buf[1] = '_';
11879 		name_buf[2] = str[0];
11880 		name_buf[3] = str[1];
11881 		name_buf[4] = NUL;
11882 
11883 		match = FALSE;
11884 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11885 		    match = TRUE;
11886 		else
11887 		{
11888 		    name_buf[0] = '<';
11889 		    name_buf[1] = 't';
11890 		    name_buf[2] = '_';
11891 		    name_buf[3] = str[0];
11892 		    name_buf[4] = str[1];
11893 		    name_buf[5] = '>';
11894 		    name_buf[6] = NUL;
11895 
11896 		    if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11897 			match = TRUE;
11898 		}
11899 		if (match)
11900 		{
11901 		    if (loop == 0)
11902 			num_term++;
11903 		    else
11904 			(*file)[count++] = vim_strsave(name_buf);
11905 		}
11906 	    }
11907 
11908 	    /*
11909 	     * Check special key names.
11910 	     */
11911 	    regmatch->rm_ic = TRUE;		/* ignore case here */
11912 	    for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11913 	    {
11914 		name_buf[0] = '<';
11915 		STRCPY(name_buf + 1, str);
11916 		STRCAT(name_buf, ">");
11917 
11918 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11919 		{
11920 		    if (loop == 0)
11921 			num_term++;
11922 		    else
11923 			(*file)[count++] = vim_strsave(name_buf);
11924 		}
11925 	    }
11926 	}
11927 	if (loop == 0)
11928 	{
11929 	    if (num_normal > 0)
11930 		*num_file = num_normal;
11931 	    else if (num_term > 0)
11932 		*num_file = num_term;
11933 	    else
11934 		return OK;
11935 	    *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11936 	    if (*file == NULL)
11937 	    {
11938 		*file = (char_u **)"";
11939 		return FAIL;
11940 	    }
11941 	}
11942     }
11943     return OK;
11944 }
11945 
11946     int
11947 ExpandOldSetting(int *num_file, char_u ***file)
11948 {
11949     char_u  *var = NULL;	/* init for GCC */
11950     char_u  *buf;
11951 
11952     *num_file = 0;
11953     *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11954     if (*file == NULL)
11955 	return FAIL;
11956 
11957     /*
11958      * For a terminal key code expand_option_idx is < 0.
11959      */
11960     if (expand_option_idx < 0)
11961     {
11962 	var = find_termcode(expand_option_name + 2);
11963 	if (var == NULL)
11964 	    expand_option_idx = findoption(expand_option_name);
11965     }
11966 
11967     if (expand_option_idx >= 0)
11968     {
11969 	/* put string of option value in NameBuff */
11970 	option_value2string(&options[expand_option_idx], expand_option_flags);
11971 	var = NameBuff;
11972     }
11973     else if (var == NULL)
11974 	var = (char_u *)"";
11975 
11976     /* A backslash is required before some characters.  This is the reverse of
11977      * what happens in do_set(). */
11978     buf = vim_strsave_escaped(var, escape_chars);
11979 
11980     if (buf == NULL)
11981     {
11982 	VIM_CLEAR(*file);
11983 	return FAIL;
11984     }
11985 
11986 #ifdef BACKSLASH_IN_FILENAME
11987     /* For MS-Windows et al. we don't double backslashes at the start and
11988      * before a file name character. */
11989     for (var = buf; *var != NUL; MB_PTR_ADV(var))
11990 	if (var[0] == '\\' && var[1] == '\\'
11991 		&& expand_option_idx >= 0
11992 		&& (options[expand_option_idx].flags & P_EXPAND)
11993 		&& vim_isfilec(var[2])
11994 		&& (var[2] != '\\' || (var == buf && var[4] != '\\')))
11995 	    STRMOVE(var, var + 1);
11996 #endif
11997 
11998     *file[0] = buf;
11999     *num_file = 1;
12000     return OK;
12001 }
12002 #endif
12003 
12004 /*
12005  * Get the value for the numeric or string option *opp in a nice format into
12006  * NameBuff[].  Must not be called with a hidden option!
12007  */
12008     static void
12009 option_value2string(
12010     struct vimoption	*opp,
12011     int			opt_flags)	/* OPT_GLOBAL and/or OPT_LOCAL */
12012 {
12013     char_u	*varp;
12014 
12015     varp = get_varp_scope(opp, opt_flags);
12016 
12017     if (opp->flags & P_NUM)
12018     {
12019 	long wc = 0;
12020 
12021 	if (wc_use_keyname(varp, &wc))
12022 	    STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12023 	else if (wc != 0)
12024 	    STRCPY(NameBuff, transchar((int)wc));
12025 	else
12026 	    sprintf((char *)NameBuff, "%ld", *(long *)varp);
12027     }
12028     else    /* P_STRING */
12029     {
12030 	varp = *(char_u **)(varp);
12031 	if (varp == NULL)		    /* just in case */
12032 	    NameBuff[0] = NUL;
12033 #ifdef FEAT_CRYPT
12034 	/* don't show the actual value of 'key', only that it's set */
12035 	else if (opp->var == (char_u *)&p_key && *varp)
12036 	    STRCPY(NameBuff, "*****");
12037 #endif
12038 	else if (opp->flags & P_EXPAND)
12039 	    home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12040 	/* Translate 'pastetoggle' into special key names */
12041 	else if ((char_u **)opp->var == &p_pt)
12042 	    str2specialbuf(p_pt, NameBuff, MAXPATHL);
12043 	else
12044 	    vim_strncpy(NameBuff, varp, MAXPATHL - 1);
12045     }
12046 }
12047 
12048 /*
12049  * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12050  * printed as a keyname.
12051  * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12052  */
12053     static int
12054 wc_use_keyname(char_u *varp, long *wcp)
12055 {
12056     if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12057     {
12058 	*wcp = *(long *)varp;
12059 	if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12060 	    return TRUE;
12061     }
12062     return FALSE;
12063 }
12064 
12065 #if defined(FEAT_LANGMAP) || defined(PROTO)
12066 /*
12067  * Any character has an equivalent 'langmap' character.  This is used for
12068  * keyboards that have a special language mode that sends characters above
12069  * 128 (although other characters can be translated too).  The "to" field is a
12070  * Vim command character.  This avoids having to switch the keyboard back to
12071  * ASCII mode when leaving Insert mode.
12072  *
12073  * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12074  * commands.
12075  * langmap_mapga.ga_data is a sorted table of langmap_entry_T.  This does the
12076  * same as langmap_mapchar[] for characters >= 256.
12077  *
12078  * Use growarray for 'langmap' chars >= 256
12079  */
12080 typedef struct
12081 {
12082     int	    from;
12083     int     to;
12084 } langmap_entry_T;
12085 
12086 static garray_T langmap_mapga;
12087 
12088 /*
12089  * Search for an entry in "langmap_mapga" for "from".  If found set the "to"
12090  * field.  If not found insert a new entry at the appropriate location.
12091  */
12092     static void
12093 langmap_set_entry(int from, int to)
12094 {
12095     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12096     int		    a = 0;
12097     int		    b = langmap_mapga.ga_len;
12098 
12099     /* Do a binary search for an existing entry. */
12100     while (a != b)
12101     {
12102 	int i = (a + b) / 2;
12103 	int d = entries[i].from - from;
12104 
12105 	if (d == 0)
12106 	{
12107 	    entries[i].to = to;
12108 	    return;
12109 	}
12110 	if (d < 0)
12111 	    a = i + 1;
12112 	else
12113 	    b = i;
12114     }
12115 
12116     if (ga_grow(&langmap_mapga, 1) != OK)
12117 	return;  /* out of memory */
12118 
12119     /* insert new entry at position "a" */
12120     entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12121     mch_memmove(entries + 1, entries,
12122 			(langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12123     ++langmap_mapga.ga_len;
12124     entries[0].from = from;
12125     entries[0].to = to;
12126 }
12127 
12128 /*
12129  * Apply 'langmap' to multi-byte character "c" and return the result.
12130  */
12131     int
12132 langmap_adjust_mb(int c)
12133 {
12134     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12135     int a = 0;
12136     int b = langmap_mapga.ga_len;
12137 
12138     while (a != b)
12139     {
12140 	int i = (a + b) / 2;
12141 	int d = entries[i].from - c;
12142 
12143 	if (d == 0)
12144 	    return entries[i].to;  /* found matching entry */
12145 	if (d < 0)
12146 	    a = i + 1;
12147 	else
12148 	    b = i;
12149     }
12150     return c;  /* no entry found, return "c" unmodified */
12151 }
12152 
12153     static void
12154 langmap_init(void)
12155 {
12156     int i;
12157 
12158     for (i = 0; i < 256; i++)
12159 	langmap_mapchar[i] = i;	 /* we init with a one-to-one map */
12160     ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
12161 }
12162 
12163 /*
12164  * Called when langmap option is set; the language map can be
12165  * changed at any time!
12166  */
12167     static void
12168 langmap_set(void)
12169 {
12170     char_u  *p;
12171     char_u  *p2;
12172     int	    from, to;
12173 
12174     ga_clear(&langmap_mapga);		    /* clear the previous map first */
12175     langmap_init();			    /* back to one-to-one map */
12176 
12177     for (p = p_langmap; p[0] != NUL; )
12178     {
12179 	for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
12180 							       MB_PTR_ADV(p2))
12181 	{
12182 	    if (p2[0] == '\\' && p2[1] != NUL)
12183 		++p2;
12184 	}
12185 	if (p2[0] == ';')
12186 	    ++p2;	    /* abcd;ABCD form, p2 points to A */
12187 	else
12188 	    p2 = NULL;	    /* aAbBcCdD form, p2 is NULL */
12189 	while (p[0])
12190 	{
12191 	    if (p[0] == ',')
12192 	    {
12193 		++p;
12194 		break;
12195 	    }
12196 	    if (p[0] == '\\' && p[1] != NUL)
12197 		++p;
12198 	    from = (*mb_ptr2char)(p);
12199 	    to = NUL;
12200 	    if (p2 == NULL)
12201 	    {
12202 		MB_PTR_ADV(p);
12203 		if (p[0] != ',')
12204 		{
12205 		    if (p[0] == '\\')
12206 			++p;
12207 		    to = (*mb_ptr2char)(p);
12208 		}
12209 	    }
12210 	    else
12211 	    {
12212 		if (p2[0] != ',')
12213 		{
12214 		    if (p2[0] == '\\')
12215 			++p2;
12216 		    to = (*mb_ptr2char)(p2);
12217 		}
12218 	    }
12219 	    if (to == NUL)
12220 	    {
12221 		semsg(_("E357: 'langmap': Matching character missing for %s"),
12222 							     transchar(from));
12223 		return;
12224 	    }
12225 
12226 	    if (from >= 256)
12227 		langmap_set_entry(from, to);
12228 	    else
12229 		langmap_mapchar[from & 255] = to;
12230 
12231 	    /* Advance to next pair */
12232 	    MB_PTR_ADV(p);
12233 	    if (p2 != NULL)
12234 	    {
12235 		MB_PTR_ADV(p2);
12236 		if (*p == ';')
12237 		{
12238 		    p = p2;
12239 		    if (p[0] != NUL)
12240 		    {
12241 			if (p[0] != ',')
12242 			{
12243 			    semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12244 			    return;
12245 			}
12246 			++p;
12247 		    }
12248 		    break;
12249 		}
12250 	    }
12251 	}
12252     }
12253 }
12254 #endif
12255 
12256 /*
12257  * Return TRUE if format option 'x' is in effect.
12258  * Take care of no formatting when 'paste' is set.
12259  */
12260     int
12261 has_format_option(int x)
12262 {
12263     if (p_paste)
12264 	return FALSE;
12265     return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12266 }
12267 
12268 /*
12269  * Return TRUE if "x" is present in 'shortmess' option, or
12270  * 'shortmess' contains 'a' and "x" is present in SHM_A.
12271  */
12272     int
12273 shortmess(int x)
12274 {
12275     return p_shm != NULL &&
12276 	    (   vim_strchr(p_shm, x) != NULL
12277 	    || (vim_strchr(p_shm, 'a') != NULL
12278 		&& vim_strchr((char_u *)SHM_A, x) != NULL));
12279 }
12280 
12281 /*
12282  * paste_option_changed() - Called after p_paste was set or reset.
12283  */
12284     static void
12285 paste_option_changed(void)
12286 {
12287     static int	old_p_paste = FALSE;
12288     static int	save_sm = 0;
12289     static int	save_sta = 0;
12290 #ifdef FEAT_CMDL_INFO
12291     static int	save_ru = 0;
12292 #endif
12293 #ifdef FEAT_RIGHTLEFT
12294     static int	save_ri = 0;
12295     static int	save_hkmap = 0;
12296 #endif
12297     buf_T	*buf;
12298 
12299     if (p_paste)
12300     {
12301 	/*
12302 	 * Paste switched from off to on.
12303 	 * Save the current values, so they can be restored later.
12304 	 */
12305 	if (!old_p_paste)
12306 	{
12307 	    /* save options for each buffer */
12308 	    FOR_ALL_BUFFERS(buf)
12309 	    {
12310 		buf->b_p_tw_nopaste = buf->b_p_tw;
12311 		buf->b_p_wm_nopaste = buf->b_p_wm;
12312 		buf->b_p_sts_nopaste = buf->b_p_sts;
12313 		buf->b_p_ai_nopaste = buf->b_p_ai;
12314 		buf->b_p_et_nopaste = buf->b_p_et;
12315 #ifdef FEAT_VARTABS
12316 		if (buf->b_p_vsts_nopaste)
12317 		    vim_free(buf->b_p_vsts_nopaste);
12318 		buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12319 				     ? vim_strsave(buf->b_p_vsts) : NULL;
12320 #endif
12321 	    }
12322 
12323 	    /* save global options */
12324 	    save_sm = p_sm;
12325 	    save_sta = p_sta;
12326 #ifdef FEAT_CMDL_INFO
12327 	    save_ru = p_ru;
12328 #endif
12329 #ifdef FEAT_RIGHTLEFT
12330 	    save_ri = p_ri;
12331 	    save_hkmap = p_hkmap;
12332 #endif
12333 	    /* save global values for local buffer options */
12334 	    p_ai_nopaste = p_ai;
12335 	    p_et_nopaste = p_et;
12336 	    p_sts_nopaste = p_sts;
12337 	    p_tw_nopaste = p_tw;
12338 	    p_wm_nopaste = p_wm;
12339 #ifdef FEAT_VARTABS
12340 	    if (p_vsts_nopaste)
12341 		vim_free(p_vsts_nopaste);
12342 	    p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12343 #endif
12344 	}
12345 
12346 	/*
12347 	 * Always set the option values, also when 'paste' is set when it is
12348 	 * already on.
12349 	 */
12350 	/* set options for each buffer */
12351 	FOR_ALL_BUFFERS(buf)
12352 	{
12353 	    buf->b_p_tw = 0;	    /* textwidth is 0 */
12354 	    buf->b_p_wm = 0;	    /* wrapmargin is 0 */
12355 	    buf->b_p_sts = 0;	    /* softtabstop is 0 */
12356 	    buf->b_p_ai = 0;	    /* no auto-indent */
12357 	    buf->b_p_et = 0;	    /* no expandtab */
12358 #ifdef FEAT_VARTABS
12359 	    if (buf->b_p_vsts)
12360 		free_string_option(buf->b_p_vsts);
12361 	    buf->b_p_vsts = empty_option;
12362 	    if (buf->b_p_vsts_array)
12363 		vim_free(buf->b_p_vsts_array);
12364 	    buf->b_p_vsts_array = 0;
12365 #endif
12366 	}
12367 
12368 	/* set global options */
12369 	p_sm = 0;		    /* no showmatch */
12370 	p_sta = 0;		    /* no smarttab */
12371 #ifdef FEAT_CMDL_INFO
12372 	if (p_ru)
12373 	    status_redraw_all();    /* redraw to remove the ruler */
12374 	p_ru = 0;		    /* no ruler */
12375 #endif
12376 #ifdef FEAT_RIGHTLEFT
12377 	p_ri = 0;		    /* no reverse insert */
12378 	p_hkmap = 0;		    /* no Hebrew keyboard */
12379 #endif
12380 	/* set global values for local buffer options */
12381 	p_tw = 0;
12382 	p_wm = 0;
12383 	p_sts = 0;
12384 	p_ai = 0;
12385 #ifdef FEAT_VARTABS
12386 	if (p_vsts)
12387 	    free_string_option(p_vsts);
12388 	p_vsts = empty_option;
12389 #endif
12390     }
12391 
12392     /*
12393      * Paste switched from on to off: Restore saved values.
12394      */
12395     else if (old_p_paste)
12396     {
12397 	/* restore options for each buffer */
12398 	FOR_ALL_BUFFERS(buf)
12399 	{
12400 	    buf->b_p_tw = buf->b_p_tw_nopaste;
12401 	    buf->b_p_wm = buf->b_p_wm_nopaste;
12402 	    buf->b_p_sts = buf->b_p_sts_nopaste;
12403 	    buf->b_p_ai = buf->b_p_ai_nopaste;
12404 	    buf->b_p_et = buf->b_p_et_nopaste;
12405 #ifdef FEAT_VARTABS
12406 	    if (buf->b_p_vsts)
12407 		free_string_option(buf->b_p_vsts);
12408 	    buf->b_p_vsts = buf->b_p_vsts_nopaste
12409 			 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12410 	    if (buf->b_p_vsts_array)
12411 		vim_free(buf->b_p_vsts_array);
12412 	    if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12413 		tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12414 	    else
12415 		buf->b_p_vsts_array = 0;
12416 #endif
12417 	}
12418 
12419 	/* restore global options */
12420 	p_sm = save_sm;
12421 	p_sta = save_sta;
12422 #ifdef FEAT_CMDL_INFO
12423 	if (p_ru != save_ru)
12424 	    status_redraw_all();    /* redraw to draw the ruler */
12425 	p_ru = save_ru;
12426 #endif
12427 #ifdef FEAT_RIGHTLEFT
12428 	p_ri = save_ri;
12429 	p_hkmap = save_hkmap;
12430 #endif
12431 	/* set global values for local buffer options */
12432 	p_ai = p_ai_nopaste;
12433 	p_et = p_et_nopaste;
12434 	p_sts = p_sts_nopaste;
12435 	p_tw = p_tw_nopaste;
12436 	p_wm = p_wm_nopaste;
12437 #ifdef FEAT_VARTABS
12438 	if (p_vsts)
12439 	    free_string_option(p_vsts);
12440 	p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12441 #endif
12442     }
12443 
12444     old_p_paste = p_paste;
12445 }
12446 
12447 /*
12448  * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12449  *
12450  * Reset 'compatible' and set the values for options that didn't get set yet
12451  * to the Vim defaults.
12452  * Don't do this if the 'compatible' option has been set or reset before.
12453  * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
12454  */
12455     void
12456 vimrc_found(char_u *fname, char_u *envname)
12457 {
12458     int		opt_idx;
12459     int		dofree = FALSE;
12460     char_u	*p;
12461 
12462     if (!option_was_set((char_u *)"cp"))
12463     {
12464 	p_cp = FALSE;
12465 	for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12466 	    if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12467 		set_option_default(opt_idx, OPT_FREE, FALSE);
12468 	didset_options();
12469 	didset_options2();
12470     }
12471 
12472     if (fname != NULL)
12473     {
12474 	p = vim_getenv(envname, &dofree);
12475 	if (p == NULL)
12476 	{
12477 	    /* Set $MYVIMRC to the first vimrc file found. */
12478 	    p = FullName_save(fname, FALSE);
12479 	    if (p != NULL)
12480 	    {
12481 		vim_setenv(envname, p);
12482 		vim_free(p);
12483 	    }
12484 	}
12485 	else if (dofree)
12486 	    vim_free(p);
12487     }
12488 }
12489 
12490 /*
12491  * Set 'compatible' on or off.  Called for "-C" and "-N" command line arg.
12492  */
12493     void
12494 change_compatible(int on)
12495 {
12496     int	    opt_idx;
12497 
12498     if (p_cp != on)
12499     {
12500 	p_cp = on;
12501 	compatible_set();
12502     }
12503     opt_idx = findoption((char_u *)"cp");
12504     if (opt_idx >= 0)
12505 	options[opt_idx].flags |= P_WAS_SET;
12506 }
12507 
12508 /*
12509  * Return TRUE when option "name" has been set.
12510  * Only works correctly for global options.
12511  */
12512     int
12513 option_was_set(char_u *name)
12514 {
12515     int idx;
12516 
12517     idx = findoption(name);
12518     if (idx < 0)	/* unknown option */
12519 	return FALSE;
12520     if (options[idx].flags & P_WAS_SET)
12521 	return TRUE;
12522     return FALSE;
12523 }
12524 
12525 /*
12526  * Reset the flag indicating option "name" was set.
12527  */
12528     int
12529 reset_option_was_set(char_u *name)
12530 {
12531     int idx = findoption(name);
12532 
12533     if (idx >= 0)
12534     {
12535 	options[idx].flags &= ~P_WAS_SET;
12536 	return OK;
12537     }
12538     return FAIL;
12539 }
12540 
12541 /*
12542  * compatible_set() - Called when 'compatible' has been set or unset.
12543  *
12544  * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12545  * flag) to a Vi compatible value.
12546  * When 'compatible' is unset: Set all options that have a different default
12547  * for Vim (without the P_VI_DEF flag) to that default.
12548  */
12549     static void
12550 compatible_set(void)
12551 {
12552     int	    opt_idx;
12553 
12554     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12555 	if (	   ((options[opt_idx].flags & P_VIM) && p_cp)
12556 		|| (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12557 	    set_option_default(opt_idx, OPT_FREE, p_cp);
12558     didset_options();
12559     didset_options2();
12560 }
12561 
12562 #ifdef FEAT_LINEBREAK
12563 
12564 /*
12565  * fill_breakat_flags() -- called when 'breakat' changes value.
12566  */
12567     static void
12568 fill_breakat_flags(void)
12569 {
12570     char_u	*p;
12571     int		i;
12572 
12573     for (i = 0; i < 256; i++)
12574 	breakat_flags[i] = FALSE;
12575 
12576     if (p_breakat != NULL)
12577 	for (p = p_breakat; *p; p++)
12578 	    breakat_flags[*p] = TRUE;
12579 }
12580 #endif
12581 
12582 /*
12583  * Check an option that can be a range of string values.
12584  *
12585  * Return OK for correct value, FAIL otherwise.
12586  * Empty is always OK.
12587  */
12588     static int
12589 check_opt_strings(
12590     char_u	*val,
12591     char	**values,
12592     int		list)	    /* when TRUE: accept a list of values */
12593 {
12594     return opt_strings_flags(val, values, NULL, list);
12595 }
12596 
12597 /*
12598  * Handle an option that can be a range of string values.
12599  * Set a flag in "*flagp" for each string present.
12600  *
12601  * Return OK for correct value, FAIL otherwise.
12602  * Empty is always OK.
12603  */
12604     static int
12605 opt_strings_flags(
12606     char_u	*val,		/* new value */
12607     char	**values,	/* array of valid string values */
12608     unsigned	*flagp,
12609     int		list)		/* when TRUE: accept a list of values */
12610 {
12611     int		i;
12612     int		len;
12613     unsigned	new_flags = 0;
12614 
12615     while (*val)
12616     {
12617 	for (i = 0; ; ++i)
12618 	{
12619 	    if (values[i] == NULL)	/* val not found in values[] */
12620 		return FAIL;
12621 
12622 	    len = (int)STRLEN(values[i]);
12623 	    if (STRNCMP(values[i], val, len) == 0
12624 		    && ((list && val[len] == ',') || val[len] == NUL))
12625 	    {
12626 		val += len + (val[len] == ',');
12627 		new_flags |= (1 << i);
12628 		break;		/* check next item in val list */
12629 	    }
12630 	}
12631     }
12632     if (flagp != NULL)
12633 	*flagp = new_flags;
12634 
12635     return OK;
12636 }
12637 
12638 /*
12639  * Read the 'wildmode' option, fill wim_flags[].
12640  */
12641     static int
12642 check_opt_wim(void)
12643 {
12644     char_u	new_wim_flags[4];
12645     char_u	*p;
12646     int		i;
12647     int		idx = 0;
12648 
12649     for (i = 0; i < 4; ++i)
12650 	new_wim_flags[i] = 0;
12651 
12652     for (p = p_wim; *p; ++p)
12653     {
12654 	for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12655 	    ;
12656 	if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12657 	    return FAIL;
12658 	if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12659 	    new_wim_flags[idx] |= WIM_LONGEST;
12660 	else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12661 	    new_wim_flags[idx] |= WIM_FULL;
12662 	else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12663 	    new_wim_flags[idx] |= WIM_LIST;
12664 	else
12665 	    return FAIL;
12666 	p += i;
12667 	if (*p == NUL)
12668 	    break;
12669 	if (*p == ',')
12670 	{
12671 	    if (idx == 3)
12672 		return FAIL;
12673 	    ++idx;
12674 	}
12675     }
12676 
12677     /* fill remaining entries with last flag */
12678     while (idx < 3)
12679     {
12680 	new_wim_flags[idx + 1] = new_wim_flags[idx];
12681 	++idx;
12682     }
12683 
12684     /* only when there are no errors, wim_flags[] is changed */
12685     for (i = 0; i < 4; ++i)
12686 	wim_flags[i] = new_wim_flags[i];
12687     return OK;
12688 }
12689 
12690 /*
12691  * Check if backspacing over something is allowed.
12692  */
12693     int
12694 can_bs(
12695     int		what)	    /* BS_INDENT, BS_EOL or BS_START */
12696 {
12697 #ifdef FEAT_JOB_CHANNEL
12698     if (what == BS_START && bt_prompt(curbuf))
12699 	return FALSE;
12700 #endif
12701     switch (*p_bs)
12702     {
12703 	case '2':	return TRUE;
12704 	case '1':	return (what != BS_START);
12705 	case '0':	return FALSE;
12706     }
12707     return vim_strchr(p_bs, what) != NULL;
12708 }
12709 
12710 /*
12711  * Save the current values of 'fileformat' and 'fileencoding', so that we know
12712  * the file must be considered changed when the value is different.
12713  */
12714     void
12715 save_file_ff(buf_T *buf)
12716 {
12717     buf->b_start_ffc = *buf->b_p_ff;
12718     buf->b_start_eol = buf->b_p_eol;
12719     buf->b_start_bomb = buf->b_p_bomb;
12720 
12721     /* Only use free/alloc when necessary, they take time. */
12722     if (buf->b_start_fenc == NULL
12723 			     || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12724     {
12725 	vim_free(buf->b_start_fenc);
12726 	buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12727     }
12728 }
12729 
12730 /*
12731  * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12732  * from when editing started (save_file_ff() called).
12733  * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12734  * changed and 'binary' is not set.
12735  * Also when 'endofline' was changed and 'fixeol' is not set.
12736  * When "ignore_empty" is true don't consider a new, empty buffer to be
12737  * changed.
12738  */
12739     int
12740 file_ff_differs(buf_T *buf, int ignore_empty)
12741 {
12742     /* In a buffer that was never loaded the options are not valid. */
12743     if (buf->b_flags & BF_NEVERLOADED)
12744 	return FALSE;
12745     if (ignore_empty
12746 	    && (buf->b_flags & BF_NEW)
12747 	    && buf->b_ml.ml_line_count == 1
12748 	    && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12749 	return FALSE;
12750     if (buf->b_start_ffc != *buf->b_p_ff)
12751 	return TRUE;
12752     if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
12753 	return TRUE;
12754     if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12755 	return TRUE;
12756     if (buf->b_start_fenc == NULL)
12757 	return (*buf->b_p_fenc != NUL);
12758     return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12759 }
12760 
12761 /*
12762  * return OK if "p" is a valid fileformat name, FAIL otherwise.
12763  */
12764     int
12765 check_ff_value(char_u *p)
12766 {
12767     return check_opt_strings(p, p_ff_values, FALSE);
12768 }
12769 
12770 #if defined(FEAT_VARTABS) || defined(PROTO)
12771 
12772 /*
12773  * Set the integer values corresponding to the string setting of 'vartabstop'.
12774  * "array" will be set, caller must free it if needed.
12775  */
12776     int
12777 tabstop_set(char_u *var, int **array)
12778 {
12779     int valcount = 1;
12780     int t;
12781     char_u *cp;
12782 
12783     if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
12784     {
12785 	*array = NULL;
12786 	return TRUE;
12787     }
12788 
12789     for (cp = var; *cp != NUL; ++cp)
12790     {
12791 	if (cp == var || cp[-1] == ',')
12792 	{
12793 	    char_u *end;
12794 
12795 	    if (strtol((char *)cp, (char **)&end, 10) <= 0)
12796 	    {
12797 		if (cp != end)
12798 		    emsg(_(e_positive));
12799 		else
12800 		    emsg(_(e_invarg));
12801 		return FALSE;
12802 	    }
12803 	}
12804 
12805 	if (VIM_ISDIGIT(*cp))
12806 	    continue;
12807 	if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
12808 	{
12809 	    ++valcount;
12810 	    continue;
12811 	}
12812 	emsg(_(e_invarg));
12813 	return FALSE;
12814     }
12815 
12816     *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
12817     if (*array == NULL)
12818 	return FALSE;
12819     (*array)[0] = valcount;
12820 
12821     t = 1;
12822     for (cp = var; *cp != NUL;)
12823     {
12824 	(*array)[t++] = atoi((char *)cp);
12825 	while (*cp  != NUL && *cp != ',')
12826 	    ++cp;
12827 	if (*cp != NUL)
12828 	    ++cp;
12829     }
12830 
12831     return TRUE;
12832 }
12833 
12834 /*
12835  * Calculate the number of screen spaces a tab will occupy.
12836  * If "vts" is set then the tab widths are taken from that array,
12837  * otherwise the value of ts is used.
12838  */
12839     int
12840 tabstop_padding(colnr_T col, int ts_arg, int *vts)
12841 {
12842     int		ts = ts_arg == 0 ? 8 : ts_arg;
12843     int		tabcount;
12844     colnr_T	tabcol = 0;
12845     int		t;
12846     int		padding = 0;
12847 
12848     if (vts == NULL || vts[0] == 0)
12849 	return ts - (col % ts);
12850 
12851     tabcount = vts[0];
12852 
12853     for (t = 1; t <= tabcount; ++t)
12854     {
12855 	tabcol += vts[t];
12856 	if (tabcol > col)
12857 	{
12858 	    padding = (int)(tabcol - col);
12859 	    break;
12860 	}
12861     }
12862     if (t > tabcount)
12863 	padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12864 
12865     return padding;
12866 }
12867 
12868 /*
12869  * Find the size of the tab that covers a particular column.
12870  */
12871     int
12872 tabstop_at(colnr_T col, int ts, int *vts)
12873 {
12874     int		tabcount;
12875     colnr_T	tabcol = 0;
12876     int		t;
12877     int		tab_size = 0;
12878 
12879     if (vts == 0 || vts[0] == 0)
12880 	return ts;
12881 
12882     tabcount = vts[0];
12883     for (t = 1; t <= tabcount; ++t)
12884     {
12885 	tabcol += vts[t];
12886 	if (tabcol > col)
12887 	{
12888 	    tab_size = vts[t];
12889 	    break;
12890 	}
12891     }
12892     if (t > tabcount)
12893 	tab_size = vts[tabcount];
12894 
12895     return tab_size;
12896 }
12897 
12898 /*
12899  * Find the column on which a tab starts.
12900  */
12901     colnr_T
12902 tabstop_start(colnr_T col, int ts, int *vts)
12903 {
12904     int		tabcount;
12905     colnr_T	tabcol = 0;
12906     int		t;
12907     int         excess;
12908 
12909     if (vts == NULL || vts[0] == 0)
12910 	return (col / ts) * ts;
12911 
12912     tabcount = vts[0];
12913     for (t = 1; t <= tabcount; ++t)
12914     {
12915 	tabcol += vts[t];
12916 	if (tabcol > col)
12917 	    return tabcol - vts[t];
12918     }
12919 
12920     excess = tabcol % vts[tabcount];
12921     return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12922 }
12923 
12924 /*
12925  * Find the number of tabs and spaces necessary to get from one column
12926  * to another.
12927  */
12928     void
12929 tabstop_fromto(
12930 	colnr_T start_col,
12931 	colnr_T end_col,
12932 	int	ts_arg,
12933 	int	*vts,
12934 	int	*ntabs,
12935 	int	*nspcs)
12936 {
12937     int		spaces = end_col - start_col;
12938     colnr_T	tabcol = 0;
12939     int		padding = 0;
12940     int		tabcount;
12941     int		t;
12942     int		ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
12943 
12944     if (vts == NULL || vts[0] == 0)
12945     {
12946 	int tabs = 0;
12947 	int initspc = 0;
12948 
12949 	initspc = ts - (start_col % ts);
12950 	if (spaces >= initspc)
12951 	{
12952 	    spaces -= initspc;
12953 	    tabs++;
12954 	}
12955 	tabs += spaces / ts;
12956 	spaces -= (spaces / ts) * ts;
12957 
12958 	*ntabs = tabs;
12959 	*nspcs = spaces;
12960 	return;
12961     }
12962 
12963     /* Find the padding needed to reach the next tabstop. */
12964     tabcount = vts[0];
12965     for (t = 1; t <= tabcount; ++t)
12966     {
12967 	tabcol += vts[t];
12968 	if (tabcol > start_col)
12969 	{
12970 	    padding = (int)(tabcol - start_col);
12971 	    break;
12972 	}
12973     }
12974     if (t > tabcount)
12975 	padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12976 
12977     /* If the space needed is less than the padding no tabs can be used. */
12978     if (spaces < padding)
12979     {
12980 	*ntabs = 0;
12981 	*nspcs = spaces;
12982 	return;
12983     }
12984 
12985     *ntabs = 1;
12986     spaces -= padding;
12987 
12988     /* At least one tab has been used. See if any more will fit. */
12989     while (spaces != 0 && ++t <= tabcount)
12990     {
12991 	padding = vts[t];
12992 	if (spaces < padding)
12993 	{
12994 	    *nspcs = spaces;
12995 	    return;
12996 	}
12997 	++*ntabs;
12998 	spaces -= padding;
12999     }
13000 
13001     *ntabs += spaces / vts[tabcount];
13002     *nspcs =  spaces % vts[tabcount];
13003 }
13004 
13005 /*
13006  * See if two tabstop arrays contain the same values.
13007  */
13008     int
13009 tabstop_eq(int *ts1, int *ts2)
13010 {
13011     int		t;
13012 
13013     if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13014 	return FALSE;
13015     if (ts1 == ts2)
13016 	return TRUE;
13017     if (ts1[0] != ts2[0])
13018 	return FALSE;
13019 
13020     for (t = 1; t <= ts1[0]; ++t)
13021 	if (ts1[t] != ts2[t])
13022 	    return FALSE;
13023 
13024     return TRUE;
13025 }
13026 
13027 #if defined(FEAT_BEVAL) || defined(PROTO)
13028 /*
13029  * Copy a tabstop array, allocating space for the new array.
13030  */
13031     int *
13032 tabstop_copy(int *oldts)
13033 {
13034     int		*newts;
13035     int		t;
13036 
13037     if (oldts == NULL)
13038 	return NULL;
13039     newts = (int *)alloc((unsigned)((oldts[0] + 1) * sizeof(int)));
13040     if (newts != NULL)
13041 	for (t = 0; t <= oldts[0]; ++t)
13042 	    newts[t] = oldts[t];
13043     return newts;
13044 }
13045 #endif
13046 
13047 /*
13048  * Return a count of the number of tabstops.
13049  */
13050     int
13051 tabstop_count(int *ts)
13052 {
13053     return ts != NULL ? ts[0] : 0;
13054 }
13055 
13056 /*
13057  * Return the first tabstop, or 8 if there are no tabstops defined.
13058  */
13059     int
13060 tabstop_first(int *ts)
13061 {
13062     return ts != NULL ? ts[1] : 8;
13063 }
13064 
13065 #endif
13066 
13067 /*
13068  * Return the effective shiftwidth value for current buffer, using the
13069  * 'tabstop' value when 'shiftwidth' is zero.
13070  */
13071     long
13072 get_sw_value(buf_T *buf)
13073 {
13074     return get_sw_value_col(buf, 0);
13075 }
13076 
13077 /*
13078  * Idem, using the first non-black in the current line.
13079  */
13080     long
13081 get_sw_value_indent(buf_T *buf)
13082 {
13083     pos_T pos = curwin->w_cursor;
13084 
13085     pos.col = getwhitecols_curline();
13086     return get_sw_value_pos(buf, &pos);
13087 }
13088 
13089 /*
13090  * Idem, using "pos".
13091  */
13092     long
13093 get_sw_value_pos(buf_T *buf, pos_T *pos)
13094 {
13095     pos_T save_cursor = curwin->w_cursor;
13096     long sw_value;
13097 
13098     curwin->w_cursor = *pos;
13099     sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13100     curwin->w_cursor = save_cursor;
13101     return sw_value;
13102 }
13103 
13104 /*
13105  * Idem, using virtual column "col".
13106  */
13107     long
13108 get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13109 {
13110     return buf->b_p_sw ? buf->b_p_sw :
13111  #ifdef FEAT_VARTABS
13112 	tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13113  #else
13114 	buf->b_p_ts;
13115  #endif
13116 }
13117 
13118 /*
13119  * Return the effective softtabstop value for the current buffer, using the
13120  * 'shiftwidth' value when 'softtabstop' is negative.
13121  */
13122     long
13123 get_sts_value(void)
13124 {
13125     return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
13126 }
13127 
13128 /*
13129  * Return the effective 'scrolloff' value for the current window, using the
13130  * global value when appropriate.
13131  */
13132     long
13133 get_scrolloff_value(void)
13134 {
13135     return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13136 }
13137 
13138 /*
13139  * Return the effective 'sidescrolloff' value for the current window, using the
13140  * global value when appropriate.
13141  */
13142     long
13143 get_sidescrolloff_value(void)
13144 {
13145     return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13146 }
13147 
13148 /*
13149  * Check matchpairs option for "*initc".
13150  * If there is a match set "*initc" to the matching character and "*findc" to
13151  * the opposite character.  Set "*backwards" to the direction.
13152  * When "switchit" is TRUE swap the direction.
13153  */
13154     void
13155 find_mps_values(
13156     int	    *initc,
13157     int	    *findc,
13158     int	    *backwards,
13159     int	    switchit)
13160 {
13161     char_u	*ptr;
13162 
13163     ptr = curbuf->b_p_mps;
13164     while (*ptr != NUL)
13165     {
13166 	if (has_mbyte)
13167 	{
13168 	    char_u *prev;
13169 
13170 	    if (mb_ptr2char(ptr) == *initc)
13171 	    {
13172 		if (switchit)
13173 		{
13174 		    *findc = *initc;
13175 		    *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13176 		    *backwards = TRUE;
13177 		}
13178 		else
13179 		{
13180 		    *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13181 		    *backwards = FALSE;
13182 		}
13183 		return;
13184 	    }
13185 	    prev = ptr;
13186 	    ptr += mb_ptr2len(ptr) + 1;
13187 	    if (mb_ptr2char(ptr) == *initc)
13188 	    {
13189 		if (switchit)
13190 		{
13191 		    *findc = *initc;
13192 		    *initc = mb_ptr2char(prev);
13193 		    *backwards = FALSE;
13194 		}
13195 		else
13196 		{
13197 		    *findc = mb_ptr2char(prev);
13198 		    *backwards = TRUE;
13199 		}
13200 		return;
13201 	    }
13202 	    ptr += mb_ptr2len(ptr);
13203 	}
13204 	else
13205 	{
13206 	    if (*ptr == *initc)
13207 	    {
13208 		if (switchit)
13209 		{
13210 		    *backwards = TRUE;
13211 		    *findc = *initc;
13212 		    *initc = ptr[2];
13213 		}
13214 		else
13215 		{
13216 		    *backwards = FALSE;
13217 		    *findc = ptr[2];
13218 		}
13219 		return;
13220 	    }
13221 	    ptr += 2;
13222 	    if (*ptr == *initc)
13223 	    {
13224 		if (switchit)
13225 		{
13226 		    *backwards = FALSE;
13227 		    *findc = *initc;
13228 		    *initc = ptr[-2];
13229 		}
13230 		else
13231 		{
13232 		    *backwards = TRUE;
13233 		    *findc =  ptr[-2];
13234 		}
13235 		return;
13236 	    }
13237 	    ++ptr;
13238 	}
13239 	if (*ptr == ',')
13240 	    ++ptr;
13241     }
13242 }
13243 
13244 #if defined(FEAT_LINEBREAK) || defined(PROTO)
13245 /*
13246  * This is called when 'breakindentopt' is changed and when a window is
13247  * initialized.
13248  */
13249     static int
13250 briopt_check(win_T *wp)
13251 {
13252     char_u	*p;
13253     int		bri_shift = 0;
13254     long	bri_min = 20;
13255     int		bri_sbr = FALSE;
13256 
13257     p = wp->w_p_briopt;
13258     while (*p != NUL)
13259     {
13260 	if (STRNCMP(p, "shift:", 6) == 0
13261 		 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13262 	{
13263 	    p += 6;
13264 	    bri_shift = getdigits(&p);
13265 	}
13266 	else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13267 	{
13268 	    p += 4;
13269 	    bri_min = getdigits(&p);
13270 	}
13271 	else if (STRNCMP(p, "sbr", 3) == 0)
13272 	{
13273 	    p += 3;
13274 	    bri_sbr = TRUE;
13275 	}
13276 	if (*p != ',' && *p != NUL)
13277 	    return FAIL;
13278 	if (*p == ',')
13279 	    ++p;
13280     }
13281 
13282     wp->w_p_brishift = bri_shift;
13283     wp->w_p_brimin   = bri_min;
13284     wp->w_p_brisbr   = bri_sbr;
13285 
13286     return OK;
13287 }
13288 #endif
13289 
13290 /*
13291  * Get the local or global value of 'backupcopy'.
13292  */
13293     unsigned int
13294 get_bkc_value(buf_T *buf)
13295 {
13296     return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13297 }
13298 
13299 #if defined(FEAT_SIGNS) || defined(PROTO)
13300 /*
13301  * Return TRUE when window "wp" has a column to draw signs in.
13302  */
13303      int
13304 signcolumn_on(win_T *wp)
13305 {
13306     if (*wp->w_p_scl == 'n')
13307 	return FALSE;
13308     if (*wp->w_p_scl == 'y')
13309 	return TRUE;
13310     return (wp->w_buffer->b_signlist != NULL
13311 # ifdef FEAT_NETBEANS_INTG
13312 			|| wp->w_buffer->b_has_sign_column
13313 # endif
13314 		    );
13315 }
13316 #endif
13317 
13318 #if defined(FEAT_EVAL) || defined(PROTO)
13319 /*
13320  * Get window or buffer local options.
13321  */
13322     dict_T *
13323 get_winbuf_options(int bufopt)
13324 {
13325     dict_T	*d;
13326     int		opt_idx;
13327 
13328     d = dict_alloc();
13329     if (d == NULL)
13330 	return NULL;
13331 
13332     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13333     {
13334 	struct vimoption *opt = &options[opt_idx];
13335 
13336 	if ((bufopt && (opt->indir & PV_BUF))
13337 					 || (!bufopt && (opt->indir & PV_WIN)))
13338 	{
13339 	    char_u *varp = get_varp(opt);
13340 
13341 	    if (varp != NULL)
13342 	    {
13343 		if (opt->flags & P_STRING)
13344 		    dict_add_string(d, opt->fullname, *(char_u **)varp);
13345 		else if (opt->flags & P_NUM)
13346 		    dict_add_number(d, opt->fullname, *(long *)varp);
13347 		else
13348 		    dict_add_number(d, opt->fullname, *(int *)varp);
13349 	    }
13350 	}
13351     }
13352 
13353     return d;
13354 }
13355 #endif
13356