Merge branch 'vim-with-runtime'
[vim_extended.git] / src / option.c
blob0f997c59d2a69dd3a2b08e4a5bce90b6bc21d9c6
1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
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 */
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
34 #define IN_OPTION_C
35 #include "vim.h"
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.
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))
54 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
57 #define PV_AI OPT_BUF(BV_AI)
58 #define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
59 #ifdef FEAT_QUICKFIX
60 # define PV_BH OPT_BUF(BV_BH)
61 # define PV_BT OPT_BUF(BV_BT)
62 # define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63 # define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64 # define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
65 #endif
66 #define PV_BIN OPT_BUF(BV_BIN)
67 #define PV_BL OPT_BUF(BV_BL)
68 #ifdef FEAT_MBYTE
69 # define PV_BOMB OPT_BUF(BV_BOMB)
70 #endif
71 #define PV_CI OPT_BUF(BV_CI)
72 #ifdef FEAT_CINDENT
73 # define PV_CIN OPT_BUF(BV_CIN)
74 # define PV_CINK OPT_BUF(BV_CINK)
75 # define PV_CINO OPT_BUF(BV_CINO)
76 #endif
77 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78 # define PV_CINW OPT_BUF(BV_CINW)
79 #endif
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_EP OPT_BOTH(OPT_BUF(BV_EP))
100 #define PV_ET OPT_BUF(BV_ET)
101 #ifdef FEAT_MBYTE
102 # define PV_FENC OPT_BUF(BV_FENC)
103 #endif
104 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
105 # define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
106 #endif
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 #ifdef FEAT_AUTOCMD
114 # define PV_FT OPT_BUF(BV_FT)
115 #endif
116 #define PV_IMI OPT_BUF(BV_IMI)
117 #define PV_IMS OPT_BUF(BV_IMS)
118 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
119 # define PV_INDE OPT_BUF(BV_INDE)
120 # define PV_INDK OPT_BUF(BV_INDK)
121 #endif
122 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
123 # define PV_INEX OPT_BUF(BV_INEX)
124 #endif
125 #define PV_INF OPT_BUF(BV_INF)
126 #define PV_ISK OPT_BUF(BV_ISK)
127 #ifdef FEAT_CRYPT
128 # define PV_KEY OPT_BUF(BV_KEY)
129 #endif
130 #ifdef FEAT_KEYMAP
131 # define PV_KMAP OPT_BUF(BV_KMAP)
132 #endif
133 #define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
134 #ifdef FEAT_LISP
135 # define PV_LISP OPT_BUF(BV_LISP)
136 #endif
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_OSFILETYPE
143 # define PV_OFT OPT_BUF(BV_OFT)
144 #endif
145 #ifdef FEAT_COMPL_FUNC
146 # define PV_OFU OPT_BUF(BV_OFU)
147 #endif
148 #define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
149 #define PV_PI OPT_BUF(BV_PI)
150 #ifdef FEAT_TEXTOBJ
151 # define PV_QE OPT_BUF(BV_QE)
152 #endif
153 #define PV_RO OPT_BUF(BV_RO)
154 #ifdef FEAT_SMARTINDENT
155 # define PV_SI OPT_BUF(BV_SI)
156 #endif
157 #ifndef SHORT_FNAME
158 # define PV_SN OPT_BUF(BV_SN)
159 #endif
160 #ifdef FEAT_SYN_HL
161 # define PV_SMC OPT_BUF(BV_SMC)
162 # define PV_SYN OPT_BUF(BV_SYN)
163 #endif
164 #ifdef FEAT_SPELL
165 # define PV_SPC OPT_BUF(BV_SPC)
166 # define PV_SPF OPT_BUF(BV_SPF)
167 # define PV_SPL OPT_BUF(BV_SPL)
168 #endif
169 #define PV_STS OPT_BUF(BV_STS)
170 #ifdef FEAT_SEARCHPATH
171 # define PV_SUA OPT_BUF(BV_SUA)
172 #endif
173 #define PV_SW OPT_BUF(BV_SW)
174 #define PV_SWF OPT_BUF(BV_SWF)
175 #define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
176 #define PV_TS OPT_BUF(BV_TS)
177 #define PV_TW OPT_BUF(BV_TW)
178 #define PV_TX OPT_BUF(BV_TX)
179 #ifdef FEAT_PERSISTENT_UNDO
180 #define PV_UDF OPT_BUF(BV_UDF)
181 #endif
182 #define PV_WM OPT_BUF(BV_WM)
183 #ifdef FEAT_VARTABS
184 #define PV_VSTS OPT_BUF(BV_VSTS)
185 #define PV_VTS OPT_BUF(BV_VTS)
186 #endif
189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
192 #define PV_LIST OPT_WIN(WV_LIST)
193 #ifdef FEAT_ARABIC
194 # define PV_ARAB OPT_WIN(WV_ARAB)
195 #endif
196 #ifdef FEAT_LINEBREAK
197 # define PV_BRI OPT_WIN(WV_BRI)
198 # define PV_BRIMIN OPT_WIN(WV_BRIMIN)
199 # define PV_BRISHIFT OPT_WIN(WV_BRISHIFT)
200 #endif
201 #ifdef FEAT_DIFF
202 # define PV_DIFF OPT_WIN(WV_DIFF)
203 #endif
204 #ifdef FEAT_FOLDING
205 # define PV_FDC OPT_WIN(WV_FDC)
206 # define PV_FEN OPT_WIN(WV_FEN)
207 # define PV_FDI OPT_WIN(WV_FDI)
208 # define PV_FDL OPT_WIN(WV_FDL)
209 # define PV_FDM OPT_WIN(WV_FDM)
210 # define PV_FML OPT_WIN(WV_FML)
211 # define PV_FDN OPT_WIN(WV_FDN)
212 # ifdef FEAT_EVAL
213 # define PV_FDE OPT_WIN(WV_FDE)
214 # define PV_FDT OPT_WIN(WV_FDT)
215 # endif
216 # define PV_FMR OPT_WIN(WV_FMR)
217 #endif
218 #ifdef FEAT_LINEBREAK
219 # define PV_LBR OPT_WIN(WV_LBR)
220 #endif
221 #define PV_NU OPT_WIN(WV_NU)
222 #define PV_RNU OPT_WIN(WV_RNU)
223 #ifdef FEAT_LINEBREAK
224 # define PV_NUW OPT_WIN(WV_NUW)
225 #endif
226 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
227 # define PV_PVW OPT_WIN(WV_PVW)
228 #endif
229 #ifdef FEAT_RIGHTLEFT
230 # define PV_RL OPT_WIN(WV_RL)
231 # define PV_RLC OPT_WIN(WV_RLC)
232 #endif
233 #ifdef FEAT_SCROLLBIND
234 # define PV_SCBIND OPT_WIN(WV_SCBIND)
235 #endif
236 #define PV_SCROLL OPT_WIN(WV_SCROLL)
237 #ifdef FEAT_SPELL
238 # define PV_SPELL OPT_WIN(WV_SPELL)
239 #endif
240 #ifdef FEAT_SYN_HL
241 # define PV_CUC OPT_WIN(WV_CUC)
242 # define PV_CUL OPT_WIN(WV_CUL)
243 #endif
244 #ifdef FEAT_STL_OPT
245 # define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246 #endif
247 #ifdef FEAT_WINDOWS
248 # define PV_WFH OPT_WIN(WV_WFH)
249 #endif
250 #ifdef FEAT_VERTSPLIT
251 # define PV_WFW OPT_WIN(WV_WFW)
252 #endif
253 #define PV_WRAP OPT_WIN(WV_WRAP)
256 /* WV_ and BV_ values get typecasted to this for the "indir" field */
257 typedef enum
259 PV_NONE = 0,
260 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
261 } idopt_T;
264 * Options local to a window have a value local to a buffer and global to all
265 * buffers. Indicate this by setting "var" to VAR_WIN.
267 #define VAR_WIN ((char_u *)-1)
270 * These are the global values for options which are also local to a buffer.
271 * Only to be used in option.c!
273 static int p_ai;
274 static int p_bin;
275 #ifdef FEAT_MBYTE
276 static int p_bomb;
277 #endif
278 #if defined(FEAT_QUICKFIX)
279 static char_u *p_bh;
280 static char_u *p_bt;
281 #endif
282 static int p_bl;
283 static int p_ci;
284 #ifdef FEAT_CINDENT
285 static int p_cin;
286 static char_u *p_cink;
287 static char_u *p_cino;
288 #endif
289 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
290 static char_u *p_cinw;
291 #endif
292 #ifdef FEAT_COMMENTS
293 static char_u *p_com;
294 #endif
295 #ifdef FEAT_FOLDING
296 static char_u *p_cms;
297 #endif
298 #ifdef FEAT_INS_EXPAND
299 static char_u *p_cpt;
300 #endif
301 #ifdef FEAT_COMPL_FUNC
302 static char_u *p_cfu;
303 static char_u *p_ofu;
304 #endif
305 static int p_eol;
306 static int p_et;
307 #ifdef FEAT_MBYTE
308 static char_u *p_fenc;
309 #endif
310 static char_u *p_ff;
311 static char_u *p_fo;
312 static char_u *p_flp;
313 #ifdef FEAT_AUTOCMD
314 static char_u *p_ft;
315 #endif
316 static long p_iminsert;
317 static long p_imsearch;
318 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
319 static char_u *p_inex;
320 #endif
321 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
322 static char_u *p_inde;
323 static char_u *p_indk;
324 #endif
325 #if defined(FEAT_EVAL)
326 static char_u *p_fex;
327 #endif
328 static int p_inf;
329 static char_u *p_isk;
330 #ifdef FEAT_CRYPT
331 static char_u *p_key;
332 #endif
333 #ifdef FEAT_LISP
334 static int p_lisp;
335 #endif
336 static int p_ml;
337 static int p_ma;
338 static int p_mod;
339 static char_u *p_mps;
340 static char_u *p_nf;
341 #ifdef FEAT_OSFILETYPE
342 static char_u *p_oft;
343 #endif
344 static int p_pi;
345 #ifdef FEAT_TEXTOBJ
346 static char_u *p_qe;
347 #endif
348 static int p_ro;
349 #ifdef FEAT_SMARTINDENT
350 static int p_si;
351 #endif
352 #ifndef SHORT_FNAME
353 static int p_sn;
354 #endif
355 static long p_sts;
356 #if defined(FEAT_SEARCHPATH)
357 static char_u *p_sua;
358 #endif
359 static long p_sw;
360 static int p_swf;
361 #ifdef FEAT_SYN_HL
362 static long p_smc;
363 static char_u *p_syn;
364 #endif
365 #ifdef FEAT_SPELL
366 static char_u *p_spc;
367 static char_u *p_spf;
368 static char_u *p_spl;
369 #endif
370 static long p_ts;
371 static long p_tw;
372 static int p_tx;
373 #ifdef FEAT_PERSISTENT_UNDO
374 static int p_udf;
375 #endif
376 static long p_wm;
377 #ifdef FEAT_VARTABS
378 static char_u *p_vsts;
379 static char_u *p_vts;
380 #endif
381 #ifdef FEAT_KEYMAP
382 static char_u *p_keymap;
383 #endif
385 /* Saved values for when 'bin' is set. */
386 static int p_et_nobin;
387 static int p_ml_nobin;
388 static long p_tw_nobin;
389 static long p_wm_nobin;
391 /* Saved values for when 'paste' is set */
392 static long p_tw_nopaste;
393 static long p_wm_nopaste;
394 static long p_sts_nopaste;
395 static int p_ai_nopaste;
396 #ifdef FEAT_VARTABS
397 static char_u *p_vsts_nopaste;
398 #endif
400 struct vimoption
402 char *fullname; /* full option name */
403 char *shortname; /* permissible abbreviation */
404 long_u flags; /* see below */
405 char_u *var; /* global option: pointer to variable;
406 * window-local option: VAR_WIN;
407 * buffer-local option: global value */
408 idopt_T indir; /* global option: PV_NONE;
409 * local option: indirect option index */
410 char_u *def_val[2]; /* default values for variable (vi and vim) */
411 #ifdef FEAT_EVAL
412 scid_T scriptID; /* script in which the option was last set */
413 # define SCRIPTID_INIT , 0
414 #else
415 # define SCRIPTID_INIT
416 #endif
419 #define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
420 #define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
423 * Flags
425 #define P_BOOL 0x01 /* the option is boolean */
426 #define P_NUM 0x02 /* the option is numeric */
427 #define P_STRING 0x04 /* the option is a string */
428 #define P_ALLOCED 0x08 /* the string option is in allocated memory,
429 must use free_string_option() when
430 assigning new value. Not set if default is
431 the same. */
432 #define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
433 never be used for local or hidden options! */
434 #define P_NODEFAULT 0x40 /* don't set to default value */
435 #define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
436 use vim_free() when assigning new value */
437 #define P_WAS_SET 0x100 /* option has been set/reset */
438 #define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
439 #define P_VI_DEF 0x400 /* Use Vi default for Vim */
440 #define P_VIM 0x800 /* Vim option, reset when 'cp' set */
442 /* when option changed, what to display: */
443 #define P_RSTAT 0x1000 /* redraw status lines */
444 #define P_RWIN 0x2000 /* redraw current window */
445 #define P_RBUF 0x4000 /* redraw current buffer */
446 #define P_RALL 0x6000 /* redraw all windows */
447 #define P_RCLR 0x7000 /* clear and redraw all */
449 #define P_COMMA 0x8000 /* comma separated list */
450 #define P_NODUP 0x10000L/* don't allow duplicate strings */
451 #define P_FLAGLIST 0x20000L/* list of single-char flags */
453 #define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
454 #define P_GETTEXT 0x80000L/* expand default value with _() */
455 #define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
456 #define P_NFNAME 0x200000L/* only normal file name chars allowed */
457 #define P_INSECURE 0x400000L/* option was set from a modeline */
458 #define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
459 side effects) */
461 #define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
463 /* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
464 * for the currency sign. */
465 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
466 # define ISP_LATIN1 (char_u *)"@,~-255"
467 #else
468 # define ISP_LATIN1 (char_u *)"@,161-255"
469 #endif
471 /* The 16 bit MS-DOS version is low on space, make the string as short as
472 * possible when compiling with few features. */
473 #if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
474 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
475 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL)
476 # define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine"
477 #else
478 # define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
479 #endif
482 * options[] is initialized here.
483 * The order of the options MUST be alphabetic for ":set all" and findoption().
484 * All option names MUST start with a lowercase letter (for findoption()).
485 * Exception: "t_" options are at the end.
486 * The options with a NULL variable are 'hidden': a set command for them is
487 * ignored and they are not printed.
489 static struct vimoption
490 #ifdef FEAT_GUI_W16
491 _far
492 #endif
493 options[] =
495 {"aleph", "al", P_NUM|P_VI_DEF,
496 #ifdef FEAT_RIGHTLEFT
497 (char_u *)&p_aleph, PV_NONE,
498 #else
499 (char_u *)NULL, PV_NONE,
500 #endif
502 #if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
503 (char_u *)128L,
504 #else
505 (char_u *)224L,
506 #endif
507 (char_u *)0L} SCRIPTID_INIT},
508 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
509 #if defined(FEAT_GUI) && defined(MACOS_X)
510 (char_u *)&p_antialias, PV_NONE,
511 {(char_u *)FALSE, (char_u *)FALSE}
512 #else
513 (char_u *)NULL, PV_NONE,
514 {(char_u *)FALSE, (char_u *)FALSE}
515 #endif
516 SCRIPTID_INIT},
517 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
518 #ifdef FEAT_ARABIC
519 (char_u *)VAR_WIN, PV_ARAB,
520 #else
521 (char_u *)NULL, PV_NONE,
522 #endif
523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
524 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
525 #ifdef FEAT_ARABIC
526 (char_u *)&p_arshape, PV_NONE,
527 #else
528 (char_u *)NULL, PV_NONE,
529 #endif
530 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
531 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
532 #ifdef FEAT_RIGHTLEFT
533 (char_u *)&p_ari, PV_NONE,
534 #else
535 (char_u *)NULL, PV_NONE,
536 #endif
537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
538 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
539 #ifdef FEAT_FKMAP
540 (char_u *)&p_altkeymap, PV_NONE,
541 #else
542 (char_u *)NULL, PV_NONE,
543 #endif
544 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
545 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
546 #if defined(FEAT_MBYTE)
547 (char_u *)&p_ambw, PV_NONE,
548 {(char_u *)"single", (char_u *)0L}
549 #else
550 (char_u *)NULL, PV_NONE,
551 {(char_u *)0L, (char_u *)0L}
552 #endif
553 SCRIPTID_INIT},
554 #ifdef FEAT_AUTOCHDIR
555 {"autochdir", "acd", P_BOOL|P_VI_DEF,
556 (char_u *)&p_acd, PV_NONE,
557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
558 #endif
559 {"autoindent", "ai", P_BOOL|P_VI_DEF,
560 (char_u *)&p_ai, PV_AI,
561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
562 {"autoprint", "ap", P_BOOL|P_VI_DEF,
563 (char_u *)NULL, PV_NONE,
564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
565 {"autoread", "ar", P_BOOL|P_VI_DEF,
566 (char_u *)&p_ar, PV_AR,
567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
568 {"autowrite", "aw", P_BOOL|P_VI_DEF,
569 (char_u *)&p_aw, PV_NONE,
570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
571 {"autowriteall","awa", P_BOOL|P_VI_DEF,
572 (char_u *)&p_awa, PV_NONE,
573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
574 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
575 (char_u *)&p_bg, PV_NONE,
577 #if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
578 (char_u *)"dark",
579 #else
580 (char_u *)"light",
581 #endif
582 (char_u *)0L} SCRIPTID_INIT},
583 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
584 (char_u *)&p_bs, PV_NONE,
585 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
586 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
587 (char_u *)&p_bk, PV_NONE,
588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
589 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
590 (char_u *)&p_bkc, PV_NONE,
591 #ifdef UNIX
592 {(char_u *)"yes", (char_u *)"auto"}
593 #else
594 {(char_u *)"auto", (char_u *)"auto"}
595 #endif
596 SCRIPTID_INIT},
597 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
598 (char_u *)&p_bdir, PV_NONE,
599 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
600 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
601 (char_u *)&p_bex, PV_NONE,
603 #ifdef VMS
604 (char_u *)"_",
605 #else
606 (char_u *)"~",
607 #endif
608 (char_u *)0L} SCRIPTID_INIT},
609 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
610 #ifdef FEAT_WILDIGN
611 (char_u *)&p_bsk, PV_NONE,
612 {(char_u *)"", (char_u *)0L}
613 #else
614 (char_u *)NULL, PV_NONE,
615 {(char_u *)0L, (char_u *)0L}
616 #endif
617 SCRIPTID_INIT},
618 #ifdef FEAT_BEVAL
619 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
620 (char_u *)&p_bdlay, PV_NONE,
621 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
622 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
623 (char_u *)&p_beval, PV_NONE,
624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
625 # ifdef FEAT_EVAL
626 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
627 (char_u *)&p_bexpr, PV_BEXPR,
628 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
629 # endif
630 #endif
631 {"beautify", "bf", P_BOOL|P_VI_DEF,
632 (char_u *)NULL, PV_NONE,
633 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
634 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
635 (char_u *)&p_bin, PV_BIN,
636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
637 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
638 #ifdef MSDOS
639 (char_u *)&p_biosk, PV_NONE,
640 #else
641 (char_u *)NULL, PV_NONE,
642 #endif
643 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
644 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
645 #ifdef FEAT_MBYTE
646 (char_u *)&p_bomb, PV_BOMB,
647 #else
648 (char_u *)NULL, PV_NONE,
649 #endif
650 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
651 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
652 #ifdef FEAT_LINEBREAK
653 (char_u *)&p_breakat, PV_NONE,
654 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
655 #else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658 #endif
659 SCRIPTID_INIT},
660 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
661 #ifdef FEAT_LINEBREAK
662 (char_u *)VAR_WIN, PV_BRI,
663 #else
664 (char_u *)NULL, PV_NONE,
665 #endif
666 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
667 {"breakindentmin", "brimin", P_NUM|P_VI_DEF|P_VIM|P_RWIN,
668 #ifdef FEAT_LINEBREAK
669 (char_u *)VAR_WIN, PV_BRIMIN,
670 #else
671 (char_u *)NULL, PV_NONE,
672 #endif
673 {(char_u *)20L, (char_u *)20L} SCRIPTID_INIT},
674 {"breakindentshift", "brishift", P_NUM|P_VI_DEF|P_VIM|P_RWIN,
675 #ifdef FEAT_LINEBREAK
676 (char_u *)VAR_WIN, PV_BRISHIFT,
677 #else
678 (char_u *)NULL, PV_NONE,
679 #endif
680 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
681 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
682 #ifdef FEAT_BROWSE
683 (char_u *)&p_bsdir, PV_NONE,
684 {(char_u *)"last", (char_u *)0L}
685 #else
686 (char_u *)NULL, PV_NONE,
687 {(char_u *)0L, (char_u *)0L}
688 #endif
689 SCRIPTID_INIT},
690 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
691 #if defined(FEAT_QUICKFIX)
692 (char_u *)&p_bh, PV_BH,
693 {(char_u *)"", (char_u *)0L}
694 #else
695 (char_u *)NULL, PV_NONE,
696 {(char_u *)0L, (char_u *)0L}
697 #endif
698 SCRIPTID_INIT},
699 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
700 (char_u *)&p_bl, PV_BL,
701 {(char_u *)1L, (char_u *)0L}
702 SCRIPTID_INIT},
703 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
704 #if defined(FEAT_QUICKFIX)
705 (char_u *)&p_bt, PV_BT,
706 {(char_u *)"", (char_u *)0L}
707 #else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)0L, (char_u *)0L}
710 #endif
711 SCRIPTID_INIT},
712 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
713 #ifdef FEAT_MBYTE
714 (char_u *)&p_cmp, PV_NONE,
715 {(char_u *)"internal,keepascii", (char_u *)0L}
716 #else
717 (char_u *)NULL, PV_NONE,
718 {(char_u *)0L, (char_u *)0L}
719 #endif
720 SCRIPTID_INIT},
721 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
722 #ifdef FEAT_SEARCHPATH
723 (char_u *)&p_cdpath, PV_NONE,
724 {(char_u *)",,", (char_u *)0L}
725 #else
726 (char_u *)NULL, PV_NONE,
727 {(char_u *)0L, (char_u *)0L}
728 #endif
729 SCRIPTID_INIT},
730 {"cedit", NULL, P_STRING,
731 #ifdef FEAT_CMDWIN
732 (char_u *)&p_cedit, PV_NONE,
733 {(char_u *)"", (char_u *)CTRL_F_STR}
734 #else
735 (char_u *)NULL, PV_NONE,
736 {(char_u *)0L, (char_u *)0L}
737 #endif
738 SCRIPTID_INIT},
739 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
740 #if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
741 (char_u *)&p_ccv, PV_NONE,
742 {(char_u *)"", (char_u *)0L}
743 #else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746 #endif
747 SCRIPTID_INIT},
748 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
749 #ifdef FEAT_CINDENT
750 (char_u *)&p_cin, PV_CIN,
751 #else
752 (char_u *)NULL, PV_NONE,
753 #endif
754 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
755 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
756 #ifdef FEAT_CINDENT
757 (char_u *)&p_cink, PV_CINK,
758 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
759 #else
760 (char_u *)NULL, PV_NONE,
761 {(char_u *)0L, (char_u *)0L}
762 #endif
763 SCRIPTID_INIT},
764 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
765 #ifdef FEAT_CINDENT
766 (char_u *)&p_cino, PV_CINO,
767 #else
768 (char_u *)NULL, PV_NONE,
769 #endif
770 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
771 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
772 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
773 (char_u *)&p_cinw, PV_CINW,
774 {(char_u *)"if,else,while,do,for,switch",
775 (char_u *)0L}
776 #else
777 (char_u *)NULL, PV_NONE,
778 {(char_u *)0L, (char_u *)0L}
779 #endif
780 SCRIPTID_INIT},
781 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
782 #ifdef FEAT_CLIPBOARD
783 (char_u *)&p_cb, PV_NONE,
784 # ifdef FEAT_XCLIPBOARD
785 {(char_u *)"autoselect,exclude:cons\\|linux",
786 (char_u *)0L}
787 # else
788 {(char_u *)"", (char_u *)0L}
789 # endif
790 #else
791 (char_u *)NULL, PV_NONE,
792 {(char_u *)"", (char_u *)0L}
793 #endif
794 SCRIPTID_INIT},
795 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
796 (char_u *)&p_ch, PV_NONE,
797 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
798 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
799 #ifdef FEAT_CMDWIN
800 (char_u *)&p_cwh, PV_NONE,
801 #else
802 (char_u *)NULL, PV_NONE,
803 #endif
804 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
805 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
806 (char_u *)&Columns, PV_NONE,
807 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
808 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
809 #ifdef FEAT_COMMENTS
810 (char_u *)&p_com, PV_COM,
811 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
812 (char_u *)0L}
813 #else
814 (char_u *)NULL, PV_NONE,
815 {(char_u *)0L, (char_u *)0L}
816 #endif
817 SCRIPTID_INIT},
818 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
819 #ifdef FEAT_FOLDING
820 (char_u *)&p_cms, PV_CMS,
821 {(char_u *)"/*%s*/", (char_u *)0L}
822 #else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)0L, (char_u *)0L}
825 #endif
826 SCRIPTID_INIT},
827 /* P_PRI_MKRC isn't needed here, optval_default()
828 * always returns TRUE for 'compatible' */
829 {"compatible", "cp", P_BOOL|P_RALL,
830 (char_u *)&p_cp, PV_NONE,
831 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
832 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
833 #ifdef FEAT_INS_EXPAND
834 (char_u *)&p_cpt, PV_CPT,
835 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
836 #else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839 #endif
840 SCRIPTID_INIT},
841 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
842 #ifdef FEAT_COMPL_FUNC
843 (char_u *)&p_cfu, PV_CFU,
844 {(char_u *)"", (char_u *)0L}
845 #else
846 (char_u *)NULL, PV_NONE,
847 {(char_u *)0L, (char_u *)0L}
848 #endif
849 SCRIPTID_INIT},
850 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
851 #ifdef FEAT_INS_EXPAND
852 (char_u *)&p_cot, PV_NONE,
853 {(char_u *)"menu,preview", (char_u *)0L}
854 #else
855 (char_u *)NULL, PV_NONE,
856 {(char_u *)0L, (char_u *)0L}
857 #endif
858 SCRIPTID_INIT},
859 {"confirm", "cf", P_BOOL|P_VI_DEF,
860 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
861 (char_u *)&p_confirm, PV_NONE,
862 #else
863 (char_u *)NULL, PV_NONE,
864 #endif
865 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
866 {"conskey", "consk",P_BOOL|P_VI_DEF,
867 #ifdef MSDOS
868 (char_u *)&p_consk, PV_NONE,
869 #else
870 (char_u *)NULL, PV_NONE,
871 #endif
872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
873 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
874 (char_u *)&p_ci, PV_CI,
875 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
876 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
877 (char_u *)&p_cpo, PV_NONE,
878 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
879 SCRIPTID_INIT},
880 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
881 #ifdef FEAT_CSCOPE
882 (char_u *)&p_cspc, PV_NONE,
883 #else
884 (char_u *)NULL, PV_NONE,
885 #endif
886 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
887 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
888 #ifdef FEAT_CSCOPE
889 (char_u *)&p_csprg, PV_NONE,
890 {(char_u *)"cscope", (char_u *)0L}
891 #else
892 (char_u *)NULL, PV_NONE,
893 {(char_u *)0L, (char_u *)0L}
894 #endif
895 SCRIPTID_INIT},
896 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
897 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
898 (char_u *)&p_csqf, PV_NONE,
899 {(char_u *)"", (char_u *)0L}
900 #else
901 (char_u *)NULL, PV_NONE,
902 {(char_u *)0L, (char_u *)0L}
903 #endif
904 SCRIPTID_INIT},
905 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
906 #ifdef FEAT_CSCOPE
907 (char_u *)&p_cst, PV_NONE,
908 #else
909 (char_u *)NULL, PV_NONE,
910 #endif
911 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
912 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
913 #ifdef FEAT_CSCOPE
914 (char_u *)&p_csto, PV_NONE,
915 #else
916 (char_u *)NULL, PV_NONE,
917 #endif
918 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
919 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
920 #ifdef FEAT_CSCOPE
921 (char_u *)&p_csverbose, PV_NONE,
922 #else
923 (char_u *)NULL, PV_NONE,
924 #endif
925 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
926 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
927 #ifdef FEAT_SYN_HL
928 (char_u *)VAR_WIN, PV_CUC,
929 #else
930 (char_u *)NULL, PV_NONE,
931 #endif
932 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
933 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
934 #ifdef FEAT_SYN_HL
935 (char_u *)VAR_WIN, PV_CUL,
936 #else
937 (char_u *)NULL, PV_NONE,
938 #endif
939 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
940 {"debug", NULL, P_STRING|P_VI_DEF,
941 (char_u *)&p_debug, PV_NONE,
942 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
943 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
944 #ifdef FEAT_FIND_ID
945 (char_u *)&p_def, PV_DEF,
946 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
947 #else
948 (char_u *)NULL, PV_NONE,
949 {(char_u *)NULL, (char_u *)0L}
950 #endif
951 SCRIPTID_INIT},
952 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
953 #ifdef FEAT_MBYTE
954 (char_u *)&p_deco, PV_NONE,
955 #else
956 (char_u *)NULL, PV_NONE,
957 #endif
958 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
959 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
960 #ifdef FEAT_INS_EXPAND
961 (char_u *)&p_dict, PV_DICT,
962 #else
963 (char_u *)NULL, PV_NONE,
964 #endif
965 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
966 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
967 #ifdef FEAT_DIFF
968 (char_u *)VAR_WIN, PV_DIFF,
969 #else
970 (char_u *)NULL, PV_NONE,
971 #endif
972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
973 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
974 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
975 (char_u *)&p_dex, PV_NONE,
976 {(char_u *)"", (char_u *)0L}
977 #else
978 (char_u *)NULL, PV_NONE,
979 {(char_u *)0L, (char_u *)0L}
980 #endif
981 SCRIPTID_INIT},
982 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
983 #ifdef FEAT_DIFF
984 (char_u *)&p_dip, PV_NONE,
985 {(char_u *)"filler", (char_u *)NULL}
986 #else
987 (char_u *)NULL, PV_NONE,
988 {(char_u *)"", (char_u *)NULL}
989 #endif
990 SCRIPTID_INIT},
991 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
992 #ifdef FEAT_DIGRAPHS
993 (char_u *)&p_dg, PV_NONE,
994 #else
995 (char_u *)NULL, PV_NONE,
996 #endif
997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
998 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
999 (char_u *)&p_dir, PV_NONE,
1000 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
1001 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1002 (char_u *)&p_dy, PV_NONE,
1003 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1004 {"eadirection", "ead", P_STRING|P_VI_DEF,
1005 #ifdef FEAT_VERTSPLIT
1006 (char_u *)&p_ead, PV_NONE,
1007 {(char_u *)"both", (char_u *)0L}
1008 #else
1009 (char_u *)NULL, PV_NONE,
1010 {(char_u *)NULL, (char_u *)0L}
1011 #endif
1012 SCRIPTID_INIT},
1013 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1014 (char_u *)&p_ed, PV_NONE,
1015 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1016 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
1017 #ifdef FEAT_MBYTE
1018 (char_u *)&p_enc, PV_NONE,
1019 {(char_u *)ENC_DFLT, (char_u *)0L}
1020 #else
1021 (char_u *)NULL, PV_NONE,
1022 {(char_u *)0L, (char_u *)0L}
1023 #endif
1024 SCRIPTID_INIT},
1025 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1026 (char_u *)&p_eol, PV_EOL,
1027 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1028 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1029 (char_u *)&p_ea, PV_NONE,
1030 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1031 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1032 (char_u *)&p_ep, PV_EP,
1033 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1034 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1035 (char_u *)&p_eb, PV_NONE,
1036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1037 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1038 #ifdef FEAT_QUICKFIX
1039 (char_u *)&p_ef, PV_NONE,
1040 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1041 #else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)NULL, (char_u *)0L}
1044 #endif
1045 SCRIPTID_INIT},
1046 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1047 #ifdef FEAT_QUICKFIX
1048 (char_u *)&p_efm, PV_EFM,
1049 {(char_u *)DFLT_EFM, (char_u *)0L}
1050 #else
1051 (char_u *)NULL, PV_NONE,
1052 {(char_u *)NULL, (char_u *)0L}
1053 #endif
1054 SCRIPTID_INIT},
1055 {"esckeys", "ek", P_BOOL|P_VIM,
1056 (char_u *)&p_ek, PV_NONE,
1057 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1058 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1059 #ifdef FEAT_AUTOCMD
1060 (char_u *)&p_ei, PV_NONE,
1061 #else
1062 (char_u *)NULL, PV_NONE,
1063 #endif
1064 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1065 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1066 (char_u *)&p_et, PV_ET,
1067 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1068 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1069 (char_u *)&p_exrc, PV_NONE,
1070 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1071 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1072 #ifdef FEAT_MBYTE
1073 (char_u *)&p_fenc, PV_FENC,
1074 {(char_u *)"", (char_u *)0L}
1075 #else
1076 (char_u *)NULL, PV_NONE,
1077 {(char_u *)0L, (char_u *)0L}
1078 #endif
1079 SCRIPTID_INIT},
1080 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1081 #ifdef FEAT_MBYTE
1082 (char_u *)&p_fencs, PV_NONE,
1083 {(char_u *)"ucs-bom", (char_u *)0L}
1084 #else
1085 (char_u *)NULL, PV_NONE,
1086 {(char_u *)0L, (char_u *)0L}
1087 #endif
1088 SCRIPTID_INIT},
1089 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1090 (char_u *)&p_ff, PV_FF,
1091 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
1092 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1093 (char_u *)&p_ffs, PV_NONE,
1094 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1095 SCRIPTID_INIT},
1096 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
1097 #ifdef FEAT_AUTOCMD
1098 (char_u *)&p_ft, PV_FT,
1099 {(char_u *)"", (char_u *)0L}
1100 #else
1101 (char_u *)NULL, PV_NONE,
1102 {(char_u *)0L, (char_u *)0L}
1103 #endif
1104 SCRIPTID_INIT},
1105 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1106 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1107 (char_u *)&p_fcs, PV_NONE,
1108 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1109 #else
1110 (char_u *)NULL, PV_NONE,
1111 {(char_u *)"", (char_u *)0L}
1112 #endif
1113 SCRIPTID_INIT},
1114 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1115 #ifdef FEAT_FKMAP
1116 (char_u *)&p_fkmap, PV_NONE,
1117 #else
1118 (char_u *)NULL, PV_NONE,
1119 #endif
1120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1121 {"flash", "fl", P_BOOL|P_VI_DEF,
1122 (char_u *)NULL, PV_NONE,
1123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1124 #ifdef FEAT_FOLDING
1125 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1126 (char_u *)&p_fcl, PV_NONE,
1127 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1128 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1129 (char_u *)VAR_WIN, PV_FDC,
1130 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1131 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1132 (char_u *)VAR_WIN, PV_FEN,
1133 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1134 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1135 # ifdef FEAT_EVAL
1136 (char_u *)VAR_WIN, PV_FDE,
1137 {(char_u *)"0", (char_u *)NULL}
1138 # else
1139 (char_u *)NULL, PV_NONE,
1140 {(char_u *)NULL, (char_u *)0L}
1141 # endif
1142 SCRIPTID_INIT},
1143 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1144 (char_u *)VAR_WIN, PV_FDI,
1145 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
1146 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1147 (char_u *)VAR_WIN, PV_FDL,
1148 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
1149 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1150 (char_u *)&p_fdls, PV_NONE,
1151 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
1152 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1153 P_RWIN|P_COMMA|P_NODUP,
1154 (char_u *)VAR_WIN, PV_FMR,
1155 {(char_u *)"{{{,}}}", (char_u *)NULL}
1156 SCRIPTID_INIT},
1157 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1158 (char_u *)VAR_WIN, PV_FDM,
1159 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
1160 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1161 (char_u *)VAR_WIN, PV_FML,
1162 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
1163 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1164 (char_u *)VAR_WIN, PV_FDN,
1165 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
1166 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1167 (char_u *)&p_fdo, PV_NONE,
1168 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1169 (char_u *)0L} SCRIPTID_INIT},
1170 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1171 # ifdef FEAT_EVAL
1172 (char_u *)VAR_WIN, PV_FDT,
1173 {(char_u *)"foldtext()", (char_u *)NULL}
1174 # else
1175 (char_u *)NULL, PV_NONE,
1176 {(char_u *)NULL, (char_u *)0L}
1177 # endif
1178 SCRIPTID_INIT},
1179 #endif
1180 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1181 #ifdef FEAT_EVAL
1182 (char_u *)&p_fex, PV_FEX,
1183 {(char_u *)"", (char_u *)0L}
1184 #else
1185 (char_u *)NULL, PV_NONE,
1186 {(char_u *)0L, (char_u *)0L}
1187 #endif
1188 SCRIPTID_INIT},
1189 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1190 (char_u *)&p_fo, PV_FO,
1191 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1192 SCRIPTID_INIT},
1193 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1194 (char_u *)&p_flp, PV_FLP,
1195 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1196 (char_u *)0L} SCRIPTID_INIT},
1197 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1198 (char_u *)&p_fp, PV_NONE,
1199 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1200 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1201 #ifdef HAVE_FSYNC
1202 (char_u *)&p_fs, PV_NONE,
1203 {(char_u *)TRUE, (char_u *)0L}
1204 #else
1205 (char_u *)NULL, PV_NONE,
1206 {(char_u *)FALSE, (char_u *)0L}
1207 #endif
1208 SCRIPTID_INIT},
1209 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1210 (char_u *)&p_gd, PV_NONE,
1211 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1212 {"graphic", "gr", P_BOOL|P_VI_DEF,
1213 (char_u *)NULL, PV_NONE,
1214 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1215 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1216 #ifdef FEAT_QUICKFIX
1217 (char_u *)&p_gefm, PV_NONE,
1218 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
1219 #else
1220 (char_u *)NULL, PV_NONE,
1221 {(char_u *)NULL, (char_u *)0L}
1222 #endif
1223 SCRIPTID_INIT},
1224 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1225 #ifdef FEAT_QUICKFIX
1226 (char_u *)&p_gp, PV_GP,
1228 # ifdef WIN3264
1229 /* may be changed to "grep -n" in os_win32.c */
1230 (char_u *)"findstr /n",
1231 # else
1232 # ifdef UNIX
1233 /* Add an extra file name so that grep will always
1234 * insert a file name in the match line. */
1235 (char_u *)"grep -n $* /dev/null",
1236 # else
1237 # ifdef VMS
1238 (char_u *)"SEARCH/NUMBERS ",
1239 # else
1240 (char_u *)"grep -n ",
1241 # endif
1242 # endif
1243 # endif
1244 (char_u *)0L}
1245 #else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)NULL, (char_u *)0L}
1248 #endif
1249 SCRIPTID_INIT},
1250 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1251 #ifdef CURSOR_SHAPE
1252 (char_u *)&p_guicursor, PV_NONE,
1254 # ifdef FEAT_GUI
1255 (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",
1256 # else /* MSDOS or Win32 console */
1257 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1258 # endif
1259 (char_u *)0L}
1260 #else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)NULL, (char_u *)0L}
1263 #endif
1264 SCRIPTID_INIT},
1265 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1266 #ifdef FEAT_GUI
1267 (char_u *)&p_guifont, PV_NONE,
1268 {(char_u *)"", (char_u *)0L}
1269 #else
1270 (char_u *)NULL, PV_NONE,
1271 {(char_u *)NULL, (char_u *)0L}
1272 #endif
1273 SCRIPTID_INIT},
1274 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1275 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1276 (char_u *)&p_guifontset, PV_NONE,
1277 {(char_u *)"", (char_u *)0L}
1278 #else
1279 (char_u *)NULL, PV_NONE,
1280 {(char_u *)NULL, (char_u *)0L}
1281 #endif
1282 SCRIPTID_INIT},
1283 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1284 #if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1285 (char_u *)&p_guifontwide, PV_NONE,
1286 {(char_u *)"", (char_u *)0L}
1287 #else
1288 (char_u *)NULL, PV_NONE,
1289 {(char_u *)NULL, (char_u *)0L}
1290 #endif
1291 SCRIPTID_INIT},
1292 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
1293 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
1294 (char_u *)&p_ghr, PV_NONE,
1295 #else
1296 (char_u *)NULL, PV_NONE,
1297 #endif
1298 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
1299 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
1300 #if defined(FEAT_GUI)
1301 (char_u *)&p_go, PV_NONE,
1302 # if defined(UNIX) && !defined(MACOS)
1303 {(char_u *)"aegimrLtT", (char_u *)0L}
1304 # else
1305 {(char_u *)"egmrLtT", (char_u *)0L}
1306 # endif
1307 #else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310 #endif
1311 SCRIPTID_INIT},
1312 {"guipty", NULL, P_BOOL|P_VI_DEF,
1313 #if defined(FEAT_GUI)
1314 (char_u *)&p_guipty, PV_NONE,
1315 #else
1316 (char_u *)NULL, PV_NONE,
1317 #endif
1318 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1319 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
1320 #if defined(FEAT_GUI_TABLINE)
1321 (char_u *)&p_gtl, PV_NONE,
1322 {(char_u *)"", (char_u *)0L}
1323 #else
1324 (char_u *)NULL, PV_NONE,
1325 {(char_u *)NULL, (char_u *)0L}
1326 #endif
1327 SCRIPTID_INIT},
1328 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
1329 #if defined(FEAT_GUI_TABLINE)
1330 (char_u *)&p_gtt, PV_NONE,
1331 {(char_u *)"", (char_u *)0L}
1332 #else
1333 (char_u *)NULL, PV_NONE,
1334 {(char_u *)NULL, (char_u *)0L}
1335 #endif
1336 SCRIPTID_INIT},
1337 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
1340 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1341 (char_u *)&p_hf, PV_NONE,
1342 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1343 SCRIPTID_INIT},
1344 {"helpheight", "hh", P_NUM|P_VI_DEF,
1345 #ifdef FEAT_WINDOWS
1346 (char_u *)&p_hh, PV_NONE,
1347 #else
1348 (char_u *)NULL, PV_NONE,
1349 #endif
1350 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
1351 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1352 #ifdef FEAT_MULTI_LANG
1353 (char_u *)&p_hlg, PV_NONE,
1354 {(char_u *)"", (char_u *)0L}
1355 #else
1356 (char_u *)NULL, PV_NONE,
1357 {(char_u *)0L, (char_u *)0L}
1358 #endif
1359 SCRIPTID_INIT},
1360 {"hidden", "hid", P_BOOL|P_VI_DEF,
1361 (char_u *)&p_hid, PV_NONE,
1362 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1363 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1364 (char_u *)&p_hl, PV_NONE,
1365 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1366 SCRIPTID_INIT},
1367 {"history", "hi", P_NUM|P_VIM,
1368 (char_u *)&p_hi, PV_NONE,
1369 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
1370 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1371 #ifdef FEAT_RIGHTLEFT
1372 (char_u *)&p_hkmap, PV_NONE,
1373 #else
1374 (char_u *)NULL, PV_NONE,
1375 #endif
1376 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1377 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1378 #ifdef FEAT_RIGHTLEFT
1379 (char_u *)&p_hkmapp, PV_NONE,
1380 #else
1381 (char_u *)NULL, PV_NONE,
1382 #endif
1383 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1384 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1385 (char_u *)&p_hls, PV_NONE,
1386 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1387 {"icon", NULL, P_BOOL|P_VI_DEF,
1388 #ifdef FEAT_TITLE
1389 (char_u *)&p_icon, PV_NONE,
1390 #else
1391 (char_u *)NULL, PV_NONE,
1392 #endif
1393 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1394 {"iconstring", NULL, P_STRING|P_VI_DEF,
1395 #ifdef FEAT_TITLE
1396 (char_u *)&p_iconstring, PV_NONE,
1397 #else
1398 (char_u *)NULL, PV_NONE,
1399 #endif
1400 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1401 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1402 (char_u *)&p_ic, PV_NONE,
1403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1404 {"imactivatekey","imak",P_STRING|P_VI_DEF,
1405 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1406 (char_u *)&p_imak, PV_NONE,
1407 #else
1408 (char_u *)NULL, PV_NONE,
1409 #endif
1410 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1411 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1412 #ifdef USE_IM_CONTROL
1413 (char_u *)&p_imcmdline, PV_NONE,
1414 #else
1415 (char_u *)NULL, PV_NONE,
1416 #endif
1417 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1418 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1419 #ifdef USE_IM_CONTROL
1420 (char_u *)&p_imdisable, PV_NONE,
1421 #else
1422 (char_u *)NULL, PV_NONE,
1423 #endif
1424 #ifdef __sgi
1425 {(char_u *)TRUE, (char_u *)0L}
1426 #else
1427 {(char_u *)FALSE, (char_u *)0L}
1428 #endif
1429 SCRIPTID_INIT},
1430 {"iminsert", "imi", P_NUM|P_VI_DEF,
1431 (char_u *)&p_iminsert, PV_IMI,
1432 #ifdef B_IMODE_IM
1433 {(char_u *)B_IMODE_IM, (char_u *)0L}
1434 #else
1435 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1436 #endif
1437 SCRIPTID_INIT},
1438 {"imsearch", "ims", P_NUM|P_VI_DEF,
1439 (char_u *)&p_imsearch, PV_IMS,
1440 #ifdef B_IMODE_IM
1441 {(char_u *)B_IMODE_IM, (char_u *)0L}
1442 #else
1443 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1444 #endif
1445 SCRIPTID_INIT},
1446 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1447 #ifdef FEAT_FIND_ID
1448 (char_u *)&p_inc, PV_INC,
1449 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1450 #else
1451 (char_u *)NULL, PV_NONE,
1452 {(char_u *)0L, (char_u *)0L}
1453 #endif
1454 SCRIPTID_INIT},
1455 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1456 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1457 (char_u *)&p_inex, PV_INEX,
1458 {(char_u *)"", (char_u *)0L}
1459 #else
1460 (char_u *)NULL, PV_NONE,
1461 {(char_u *)0L, (char_u *)0L}
1462 #endif
1463 SCRIPTID_INIT},
1464 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1465 (char_u *)&p_is, PV_NONE,
1466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1467 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1468 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1469 (char_u *)&p_inde, PV_INDE,
1470 {(char_u *)"", (char_u *)0L}
1471 #else
1472 (char_u *)NULL, PV_NONE,
1473 {(char_u *)0L, (char_u *)0L}
1474 #endif
1475 SCRIPTID_INIT},
1476 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1477 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1478 (char_u *)&p_indk, PV_INDK,
1479 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1480 #else
1481 (char_u *)NULL, PV_NONE,
1482 {(char_u *)0L, (char_u *)0L}
1483 #endif
1484 SCRIPTID_INIT},
1485 {"infercase", "inf", P_BOOL|P_VI_DEF,
1486 (char_u *)&p_inf, PV_INF,
1487 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1488 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1489 (char_u *)&p_im, PV_NONE,
1490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1491 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1492 (char_u *)&p_isf, PV_NONE,
1494 #ifdef BACKSLASH_IN_FILENAME
1495 /* Excluded are: & and ^ are special in cmd.exe
1496 * ( and ) are used in text separating fnames */
1497 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1498 #else
1499 # ifdef AMIGA
1500 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1501 # else
1502 # ifdef VMS
1503 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1504 # else /* UNIX et al. */
1505 # ifdef EBCDIC
1506 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1507 # else
1508 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1509 # endif
1510 # endif
1511 # endif
1512 #endif
1513 (char_u *)0L} SCRIPTID_INIT},
1514 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1515 (char_u *)&p_isi, PV_NONE,
1517 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1518 (char_u *)"@,48-57,_,128-167,224-235",
1519 #else
1520 # ifdef EBCDIC
1521 /* TODO: EBCDIC Check this! @ == isalpha()*/
1522 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1523 "112-120,128,140-142,156,158,172,"
1524 "174,186,191,203-207,219-225,235-239,"
1525 "251-254",
1526 # else
1527 (char_u *)"@,48-57,_,192-255",
1528 # endif
1529 #endif
1530 (char_u *)0L} SCRIPTID_INIT},
1531 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1532 (char_u *)&p_isk, PV_ISK,
1534 #ifdef EBCDIC
1535 (char_u *)"@,240-249,_",
1536 /* TODO: EBCDIC Check this! @ == isalpha()*/
1537 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1538 "112-120,128,140-142,156,158,172,"
1539 "174,186,191,203-207,219-225,235-239,"
1540 "251-254",
1541 #else
1542 (char_u *)"@,48-57,_",
1543 # if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1544 (char_u *)"@,48-57,_,128-167,224-235"
1545 # else
1546 ISK_LATIN1
1547 # endif
1548 #endif
1549 } SCRIPTID_INIT},
1550 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1551 (char_u *)&p_isp, PV_NONE,
1553 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1554 || (defined(MACOS) && !defined(MACOS_X)) \
1555 || defined(VMS)
1556 (char_u *)"@,~-255",
1557 #else
1558 # ifdef EBCDIC
1559 /* all chars above 63 are printable */
1560 (char_u *)"63-255",
1561 # else
1562 ISP_LATIN1,
1563 # endif
1564 #endif
1565 (char_u *)0L} SCRIPTID_INIT},
1566 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1567 (char_u *)&p_js, PV_NONE,
1568 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1569 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1570 #ifdef FEAT_CRYPT
1571 (char_u *)&p_key, PV_KEY,
1572 {(char_u *)"", (char_u *)0L}
1573 #else
1574 (char_u *)NULL, PV_NONE,
1575 {(char_u *)0L, (char_u *)0L}
1576 #endif
1577 SCRIPTID_INIT},
1578 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
1579 #ifdef FEAT_KEYMAP
1580 (char_u *)&p_keymap, PV_KMAP,
1581 {(char_u *)"", (char_u *)0L}
1582 #else
1583 (char_u *)NULL, PV_NONE,
1584 {(char_u *)"", (char_u *)0L}
1585 #endif
1586 SCRIPTID_INIT},
1587 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1588 #ifdef FEAT_VISUAL
1589 (char_u *)&p_km, PV_NONE,
1590 #else
1591 (char_u *)NULL, PV_NONE,
1592 #endif
1593 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1594 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1595 (char_u *)&p_kp, PV_KP,
1597 #if defined(MSDOS) || defined(MSWIN)
1598 (char_u *)":help",
1599 #else
1600 #ifdef VMS
1601 (char_u *)"help",
1602 #else
1603 # if defined(OS2)
1604 (char_u *)"view /",
1605 # else
1606 # ifdef USEMAN_S
1607 (char_u *)"man -s",
1608 # else
1609 (char_u *)"man",
1610 # endif
1611 # endif
1612 #endif
1613 #endif
1614 (char_u *)0L} SCRIPTID_INIT},
1615 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1616 #ifdef FEAT_LANGMAP
1617 (char_u *)&p_langmap, PV_NONE,
1618 {(char_u *)"", /* unmatched } */
1619 #else
1620 (char_u *)NULL, PV_NONE,
1621 {(char_u *)NULL,
1622 #endif
1623 (char_u *)0L} SCRIPTID_INIT},
1624 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
1625 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1626 (char_u *)&p_lm, PV_NONE,
1627 #else
1628 (char_u *)NULL, PV_NONE,
1629 #endif
1630 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1631 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1632 #ifdef FEAT_WINDOWS
1633 (char_u *)&p_ls, PV_NONE,
1634 #else
1635 (char_u *)NULL, PV_NONE,
1636 #endif
1637 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
1638 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1639 (char_u *)&p_lz, PV_NONE,
1640 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1641 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1642 #ifdef FEAT_LINEBREAK
1643 (char_u *)VAR_WIN, PV_LBR,
1644 #else
1645 (char_u *)NULL, PV_NONE,
1646 #endif
1647 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1648 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1649 (char_u *)&Rows, PV_NONE,
1651 #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1652 (char_u *)25L,
1653 #else
1654 (char_u *)24L,
1655 #endif
1656 (char_u *)0L} SCRIPTID_INIT},
1657 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1658 #ifdef FEAT_GUI
1659 (char_u *)&p_linespace, PV_NONE,
1660 #else
1661 (char_u *)NULL, PV_NONE,
1662 #endif
1663 #ifdef FEAT_GUI_W32
1664 {(char_u *)1L, (char_u *)0L}
1665 #else
1666 {(char_u *)0L, (char_u *)0L}
1667 #endif
1668 SCRIPTID_INIT},
1669 {"lisp", NULL, P_BOOL|P_VI_DEF,
1670 #ifdef FEAT_LISP
1671 (char_u *)&p_lisp, PV_LISP,
1672 #else
1673 (char_u *)NULL, PV_NONE,
1674 #endif
1675 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1676 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1677 #ifdef FEAT_LISP
1678 (char_u *)&p_lispwords, PV_NONE,
1679 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1680 #else
1681 (char_u *)NULL, PV_NONE,
1682 {(char_u *)"", (char_u *)0L}
1683 #endif
1684 SCRIPTID_INIT},
1685 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1686 (char_u *)VAR_WIN, PV_LIST,
1687 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1688 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1689 (char_u *)&p_lcs, PV_NONE,
1690 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
1691 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1692 (char_u *)&p_lpl, PV_NONE,
1693 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1694 #ifdef FEAT_GUI_MAC
1695 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1696 (char_u *)&p_macatsui, PV_NONE,
1697 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1698 #endif
1699 {"magic", NULL, P_BOOL|P_VI_DEF,
1700 (char_u *)&p_magic, PV_NONE,
1701 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1702 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1703 #ifdef FEAT_QUICKFIX
1704 (char_u *)&p_mef, 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 SCRIPTID_INIT},
1711 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1712 #ifdef FEAT_QUICKFIX
1713 (char_u *)&p_mp, PV_MP,
1714 # ifdef VMS
1715 {(char_u *)"MMS", (char_u *)0L}
1716 # else
1717 {(char_u *)"make", (char_u *)0L}
1718 # endif
1719 #else
1720 (char_u *)NULL, PV_NONE,
1721 {(char_u *)NULL, (char_u *)0L}
1722 #endif
1723 SCRIPTID_INIT},
1724 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1725 (char_u *)&p_mps, PV_MPS,
1726 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1727 SCRIPTID_INIT},
1728 {"matchtime", "mat", P_NUM|P_VI_DEF,
1729 (char_u *)&p_mat, PV_NONE,
1730 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
1731 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1732 #ifdef FEAT_MBYTE
1733 (char_u *)&p_mco, PV_NONE,
1734 #else
1735 (char_u *)NULL, PV_NONE,
1736 #endif
1737 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
1738 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1739 #ifdef FEAT_EVAL
1740 (char_u *)&p_mfd, PV_NONE,
1741 #else
1742 (char_u *)NULL, PV_NONE,
1743 #endif
1744 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
1745 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1746 (char_u *)&p_mmd, PV_NONE,
1747 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
1748 {"maxmem", "mm", P_NUM|P_VI_DEF,
1749 (char_u *)&p_mm, PV_NONE,
1750 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1751 SCRIPTID_INIT},
1752 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1753 (char_u *)&p_mmp, PV_NONE,
1754 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
1755 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1756 (char_u *)&p_mmt, PV_NONE,
1757 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1758 SCRIPTID_INIT},
1759 {"menuitems", "mis", P_NUM|P_VI_DEF,
1760 #ifdef FEAT_MENU
1761 (char_u *)&p_mis, PV_NONE,
1762 #else
1763 (char_u *)NULL, PV_NONE,
1764 #endif
1765 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
1766 {"mesg", NULL, P_BOOL|P_VI_DEF,
1767 (char_u *)NULL, PV_NONE,
1768 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1769 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
1770 #ifdef FEAT_SPELL
1771 (char_u *)&p_msm, PV_NONE,
1772 {(char_u *)"460000,2000,500", (char_u *)0L}
1773 #else
1774 (char_u *)NULL, PV_NONE,
1775 {(char_u *)0L, (char_u *)0L}
1776 #endif
1777 SCRIPTID_INIT},
1778 {"modeline", "ml", P_BOOL|P_VIM,
1779 (char_u *)&p_ml, PV_ML,
1780 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1781 {"modelines", "mls", P_NUM|P_VI_DEF,
1782 (char_u *)&p_mls, PV_NONE,
1783 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
1784 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1785 (char_u *)&p_ma, PV_MA,
1786 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1787 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1788 (char_u *)&p_mod, PV_MOD,
1789 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1790 {"more", NULL, P_BOOL|P_VIM,
1791 (char_u *)&p_more, PV_NONE,
1792 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1793 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1794 (char_u *)&p_mouse, PV_NONE,
1796 #if defined(MSDOS) || defined(WIN3264)
1797 (char_u *)"a",
1798 #else
1799 (char_u *)"",
1800 #endif
1801 (char_u *)0L} SCRIPTID_INIT},
1802 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1803 #ifdef FEAT_GUI
1804 (char_u *)&p_mousef, PV_NONE,
1805 #else
1806 (char_u *)NULL, PV_NONE,
1807 #endif
1808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1809 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1810 #ifdef FEAT_GUI
1811 (char_u *)&p_mh, PV_NONE,
1812 #else
1813 (char_u *)NULL, PV_NONE,
1814 #endif
1815 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1816 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1817 (char_u *)&p_mousem, PV_NONE,
1819 #if defined(MSDOS) || defined(MSWIN)
1820 (char_u *)"popup",
1821 #else
1822 # if defined(MACOS)
1823 (char_u *)"popup_setpos",
1824 # else
1825 (char_u *)"extend",
1826 # endif
1827 #endif
1828 (char_u *)0L} SCRIPTID_INIT},
1829 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1830 #ifdef FEAT_MOUSESHAPE
1831 (char_u *)&p_mouseshape, PV_NONE,
1832 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1833 #else
1834 (char_u *)NULL, PV_NONE,
1835 {(char_u *)NULL, (char_u *)0L}
1836 #endif
1837 SCRIPTID_INIT},
1838 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1839 (char_u *)&p_mouset, PV_NONE,
1840 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
1841 {"mzquantum", "mzq", P_NUM,
1842 #ifdef FEAT_MZSCHEME
1843 (char_u *)&p_mzq, PV_NONE,
1844 #else
1845 (char_u *)NULL, PV_NONE,
1846 #endif
1847 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
1848 {"novice", NULL, P_BOOL|P_VI_DEF,
1849 (char_u *)NULL, PV_NONE,
1850 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1851 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1852 (char_u *)&p_nf, PV_NF,
1853 {(char_u *)"octal,hex", (char_u *)0L}
1854 SCRIPTID_INIT},
1855 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1856 (char_u *)VAR_WIN, PV_NU,
1857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1858 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1859 #ifdef FEAT_LINEBREAK
1860 (char_u *)VAR_WIN, PV_NUW,
1861 #else
1862 (char_u *)NULL, PV_NONE,
1863 #endif
1864 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
1865 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
1866 #ifdef FEAT_COMPL_FUNC
1867 (char_u *)&p_ofu, PV_OFU,
1868 {(char_u *)"", (char_u *)0L}
1869 #else
1870 (char_u *)NULL, PV_NONE,
1871 {(char_u *)0L, (char_u *)0L}
1872 #endif
1873 SCRIPTID_INIT},
1874 {"open", NULL, P_BOOL|P_VI_DEF,
1875 (char_u *)NULL, PV_NONE,
1876 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1877 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1878 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1879 (char_u *)&p_odev, PV_NONE,
1880 #else
1881 (char_u *)NULL, PV_NONE,
1882 #endif
1883 {(char_u *)FALSE, (char_u *)FALSE}
1884 SCRIPTID_INIT},
1885 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1886 (char_u *)&p_opfunc, PV_NONE,
1887 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1888 {"optimize", "opt", P_BOOL|P_VI_DEF,
1889 (char_u *)NULL, PV_NONE,
1890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1891 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1892 #ifdef FEAT_OSFILETYPE
1893 (char_u *)&p_oft, PV_OFT,
1894 {(char_u *)DFLT_OFT, (char_u *)0L}
1895 #else
1896 (char_u *)NULL, PV_NONE,
1897 {(char_u *)0L, (char_u *)0L}
1898 #endif
1899 SCRIPTID_INIT},
1900 {"paragraphs", "para", P_STRING|P_VI_DEF,
1901 (char_u *)&p_para, PV_NONE,
1902 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
1903 (char_u *)0L} SCRIPTID_INIT},
1904 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
1905 (char_u *)&p_paste, PV_NONE,
1906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1907 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1908 (char_u *)&p_pt, PV_NONE,
1909 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1910 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1911 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1912 (char_u *)&p_pex, PV_NONE,
1913 {(char_u *)"", (char_u *)0L}
1914 #else
1915 (char_u *)NULL, PV_NONE,
1916 {(char_u *)0L, (char_u *)0L}
1917 #endif
1918 SCRIPTID_INIT},
1919 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
1920 (char_u *)&p_pm, PV_NONE,
1921 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1922 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
1923 (char_u *)&p_path, PV_PATH,
1925 #if defined AMIGA || defined MSDOS || defined MSWIN
1926 (char_u *)".,,",
1927 #else
1928 # if defined(__EMX__)
1929 (char_u *)".,/emx/include,,",
1930 # else /* Unix, probably */
1931 (char_u *)".,/usr/include,,",
1932 # endif
1933 #endif
1934 (char_u *)0L} SCRIPTID_INIT},
1935 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1936 (char_u *)&p_pi, PV_PI,
1937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1938 {"previewheight", "pvh", P_NUM|P_VI_DEF,
1939 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1940 (char_u *)&p_pvh, PV_NONE,
1941 #else
1942 (char_u *)NULL, PV_NONE,
1943 #endif
1944 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
1945 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1946 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1947 (char_u *)VAR_WIN, PV_PVW,
1948 #else
1949 (char_u *)NULL, PV_NONE,
1950 #endif
1951 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1952 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
1953 #ifdef FEAT_PRINTER
1954 (char_u *)&p_pdev, PV_NONE,
1955 {(char_u *)"", (char_u *)0L}
1956 #else
1957 (char_u *)NULL, PV_NONE,
1958 {(char_u *)NULL, (char_u *)0L}
1959 #endif
1960 SCRIPTID_INIT},
1961 {"printencoding", "penc", P_STRING|P_VI_DEF,
1962 #ifdef FEAT_POSTSCRIPT
1963 (char_u *)&p_penc, PV_NONE,
1964 {(char_u *)"", (char_u *)0L}
1965 #else
1966 (char_u *)NULL, PV_NONE,
1967 {(char_u *)NULL, (char_u *)0L}
1968 #endif
1969 SCRIPTID_INIT},
1970 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1971 #ifdef FEAT_POSTSCRIPT
1972 (char_u *)&p_pexpr, PV_NONE,
1973 {(char_u *)"", (char_u *)0L}
1974 #else
1975 (char_u *)NULL, PV_NONE,
1976 {(char_u *)NULL, (char_u *)0L}
1977 #endif
1978 SCRIPTID_INIT},
1979 {"printfont", "pfn", P_STRING|P_VI_DEF,
1980 #ifdef FEAT_PRINTER
1981 (char_u *)&p_pfn, PV_NONE,
1983 # ifdef MSWIN
1984 (char_u *)"Courier_New:h10",
1985 # else
1986 (char_u *)"courier",
1987 # endif
1988 (char_u *)0L}
1989 #else
1990 (char_u *)NULL, PV_NONE,
1991 {(char_u *)NULL, (char_u *)0L}
1992 #endif
1993 SCRIPTID_INIT},
1994 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1995 #ifdef FEAT_PRINTER
1996 (char_u *)&p_header, PV_NONE,
1997 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1998 #else
1999 (char_u *)NULL, PV_NONE,
2000 {(char_u *)NULL, (char_u *)0L}
2001 #endif
2002 SCRIPTID_INIT},
2003 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2004 #if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2005 (char_u *)&p_pmcs, PV_NONE,
2006 {(char_u *)"", (char_u *)0L}
2007 #else
2008 (char_u *)NULL, PV_NONE,
2009 {(char_u *)NULL, (char_u *)0L}
2010 #endif
2011 SCRIPTID_INIT},
2012 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2013 #if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2014 (char_u *)&p_pmfn, PV_NONE,
2015 {(char_u *)"", (char_u *)0L}
2016 #else
2017 (char_u *)NULL, PV_NONE,
2018 {(char_u *)NULL, (char_u *)0L}
2019 #endif
2020 SCRIPTID_INIT},
2021 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2022 #ifdef FEAT_PRINTER
2023 (char_u *)&p_popt, PV_NONE,
2024 {(char_u *)"", (char_u *)0L}
2025 #else
2026 (char_u *)NULL, PV_NONE,
2027 {(char_u *)NULL, (char_u *)0L}
2028 #endif
2029 SCRIPTID_INIT},
2030 {"prompt", NULL, P_BOOL|P_VI_DEF,
2031 (char_u *)&p_prompt, PV_NONE,
2032 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2033 {"pumheight", "ph", P_NUM|P_VI_DEF,
2034 #ifdef FEAT_INS_EXPAND
2035 (char_u *)&p_ph, PV_NONE,
2036 #else
2037 (char_u *)NULL, PV_NONE,
2038 #endif
2039 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2040 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2041 #ifdef FEAT_TEXTOBJ
2042 (char_u *)&p_qe, PV_QE,
2043 {(char_u *)"\\", (char_u *)0L}
2044 #else
2045 (char_u *)NULL, PV_NONE,
2046 {(char_u *)NULL, (char_u *)0L}
2047 #endif
2048 SCRIPTID_INIT},
2049 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2050 (char_u *)&p_ro, PV_RO,
2051 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2052 {"redraw", NULL, P_BOOL|P_VI_DEF,
2053 (char_u *)NULL, PV_NONE,
2054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2055 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2056 #ifdef FEAT_RELTIME
2057 (char_u *)&p_rdt, PV_NONE,
2058 #else
2059 (char_u *)NULL, PV_NONE,
2060 #endif
2061 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
2062 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2063 (char_u *)VAR_WIN, PV_RNU,
2064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2065 {"remap", NULL, P_BOOL|P_VI_DEF,
2066 (char_u *)&p_remap, PV_NONE,
2067 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2068 {"report", NULL, P_NUM|P_VI_DEF,
2069 (char_u *)&p_report, PV_NONE,
2070 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
2071 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2072 #ifdef WIN3264
2073 (char_u *)&p_rs, PV_NONE,
2074 #else
2075 (char_u *)NULL, PV_NONE,
2076 #endif
2077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2078 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2079 #ifdef FEAT_RIGHTLEFT
2080 (char_u *)&p_ri, PV_NONE,
2081 #else
2082 (char_u *)NULL, PV_NONE,
2083 #endif
2084 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2085 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2086 #ifdef FEAT_RIGHTLEFT
2087 (char_u *)VAR_WIN, PV_RL,
2088 #else
2089 (char_u *)NULL, PV_NONE,
2090 #endif
2091 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2092 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2093 #ifdef FEAT_RIGHTLEFT
2094 (char_u *)VAR_WIN, PV_RLC,
2095 {(char_u *)"search", (char_u *)NULL}
2096 #else
2097 (char_u *)NULL, PV_NONE,
2098 {(char_u *)NULL, (char_u *)0L}
2099 #endif
2100 SCRIPTID_INIT},
2101 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2102 #ifdef FEAT_CMDL_INFO
2103 (char_u *)&p_ru, PV_NONE,
2104 #else
2105 (char_u *)NULL, PV_NONE,
2106 #endif
2107 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2108 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2109 #ifdef FEAT_STL_OPT
2110 (char_u *)&p_ruf, PV_NONE,
2111 #else
2112 (char_u *)NULL, PV_NONE,
2113 #endif
2114 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2115 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2116 (char_u *)&p_rtp, PV_NONE,
2117 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2118 SCRIPTID_INIT},
2119 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2120 (char_u *)VAR_WIN, PV_SCROLL,
2121 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
2122 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2123 #ifdef FEAT_SCROLLBIND
2124 (char_u *)VAR_WIN, PV_SCBIND,
2125 #else
2126 (char_u *)NULL, PV_NONE,
2127 #endif
2128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2129 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2130 (char_u *)&p_sj, PV_NONE,
2131 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2132 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2133 (char_u *)&p_so, PV_NONE,
2134 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2135 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2136 #ifdef FEAT_SCROLLBIND
2137 (char_u *)&p_sbo, PV_NONE,
2138 {(char_u *)"ver,jump", (char_u *)0L}
2139 #else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)0L, (char_u *)0L}
2142 #endif
2143 SCRIPTID_INIT},
2144 {"sections", "sect", P_STRING|P_VI_DEF,
2145 (char_u *)&p_sections, PV_NONE,
2146 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2147 SCRIPTID_INIT},
2148 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2149 (char_u *)&p_secure, PV_NONE,
2150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2151 {"selection", "sel", P_STRING|P_VI_DEF,
2152 #ifdef FEAT_VISUAL
2153 (char_u *)&p_sel, PV_NONE,
2154 #else
2155 (char_u *)NULL, PV_NONE,
2156 #endif
2157 {(char_u *)"inclusive", (char_u *)0L}
2158 SCRIPTID_INIT},
2159 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2160 #ifdef FEAT_VISUAL
2161 (char_u *)&p_slm, PV_NONE,
2162 #else
2163 (char_u *)NULL, PV_NONE,
2164 #endif
2165 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2166 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2167 #ifdef FEAT_SESSION
2168 (char_u *)&p_ssop, PV_NONE,
2169 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
2170 (char_u *)0L}
2171 #else
2172 (char_u *)NULL, PV_NONE,
2173 {(char_u *)0L, (char_u *)0L}
2174 #endif
2175 SCRIPTID_INIT},
2176 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2177 (char_u *)&p_sh, PV_NONE,
2179 #ifdef VMS
2180 (char_u *)"-",
2181 #else
2182 # if defined(MSDOS)
2183 (char_u *)"command",
2184 # else
2185 # if defined(WIN16)
2186 (char_u *)"command.com",
2187 # else
2188 # if defined(WIN3264)
2189 (char_u *)"", /* set in set_init_1() */
2190 # else
2191 # if defined(OS2)
2192 (char_u *)"cmd.exe",
2193 # else
2194 # if defined(ARCHIE)
2195 (char_u *)"gos",
2196 # else
2197 (char_u *)"sh",
2198 # endif
2199 # endif
2200 # endif
2201 # endif
2202 # endif
2203 #endif /* VMS */
2204 (char_u *)0L} SCRIPTID_INIT},
2205 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2206 (char_u *)&p_shcf, PV_NONE,
2208 #if defined(MSDOS) || defined(MSWIN)
2209 (char_u *)"/c",
2210 #else
2211 # if defined(OS2)
2212 (char_u *)"/c",
2213 # else
2214 (char_u *)"-c",
2215 # endif
2216 #endif
2217 (char_u *)0L} SCRIPTID_INIT},
2218 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2219 #ifdef FEAT_QUICKFIX
2220 (char_u *)&p_sp, PV_NONE,
2222 #if defined(UNIX) || defined(OS2)
2223 # ifdef ARCHIE
2224 (char_u *)"2>",
2225 # else
2226 (char_u *)"| tee",
2227 # endif
2228 #else
2229 (char_u *)">",
2230 #endif
2231 (char_u *)0L}
2232 #else
2233 (char_u *)NULL, PV_NONE,
2234 {(char_u *)0L, (char_u *)0L}
2235 #endif
2236 SCRIPTID_INIT},
2237 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2238 (char_u *)&p_shq, PV_NONE,
2239 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2240 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2241 (char_u *)&p_srr, PV_NONE,
2242 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
2243 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2244 #ifdef BACKSLASH_IN_FILENAME
2245 (char_u *)&p_ssl, PV_NONE,
2246 #else
2247 (char_u *)NULL, PV_NONE,
2248 #endif
2249 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2250 {"shelltemp", "stmp", P_BOOL,
2251 (char_u *)&p_stmp, PV_NONE,
2252 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2253 {"shelltype", "st", P_NUM|P_VI_DEF,
2254 #ifdef AMIGA
2255 (char_u *)&p_st, PV_NONE,
2256 #else
2257 (char_u *)NULL, PV_NONE,
2258 #endif
2259 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2260 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2261 (char_u *)&p_sxq, PV_NONE,
2263 #if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2264 (char_u *)"\"",
2265 #else
2266 (char_u *)"",
2267 #endif
2268 (char_u *)0L} SCRIPTID_INIT},
2269 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2270 (char_u *)&p_sr, PV_NONE,
2271 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2272 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2273 (char_u *)&p_sw, PV_SW,
2274 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
2275 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2276 (char_u *)&p_shm, PV_NONE,
2277 {(char_u *)"", (char_u *)"filnxtToO"}
2278 SCRIPTID_INIT},
2279 {"shortname", "sn", P_BOOL|P_VI_DEF,
2280 #ifdef SHORT_FNAME
2281 (char_u *)NULL, PV_NONE,
2282 #else
2283 (char_u *)&p_sn, PV_SN,
2284 #endif
2285 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2286 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2287 #ifdef FEAT_LINEBREAK
2288 (char_u *)&p_sbr, PV_NONE,
2289 #else
2290 (char_u *)NULL, PV_NONE,
2291 #endif
2292 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2293 {"showcmd", "sc", P_BOOL|P_VIM,
2294 #ifdef FEAT_CMDL_INFO
2295 (char_u *)&p_sc, PV_NONE,
2296 #else
2297 (char_u *)NULL, PV_NONE,
2298 #endif
2299 {(char_u *)FALSE,
2300 #ifdef UNIX
2301 (char_u *)FALSE
2302 #else
2303 (char_u *)TRUE
2304 #endif
2305 } SCRIPTID_INIT},
2306 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2307 (char_u *)&p_sft, PV_NONE,
2308 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2309 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2310 (char_u *)&p_sm, PV_NONE,
2311 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2312 {"showmode", "smd", P_BOOL|P_VIM,
2313 (char_u *)&p_smd, PV_NONE,
2314 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2315 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2316 #ifdef FEAT_WINDOWS
2317 (char_u *)&p_stal, PV_NONE,
2318 #else
2319 (char_u *)NULL, PV_NONE,
2320 #endif
2321 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2322 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2323 (char_u *)&p_ss, PV_NONE,
2324 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2325 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2326 (char_u *)&p_siso, PV_NONE,
2327 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2328 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2329 (char_u *)NULL, PV_NONE,
2330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2331 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2332 (char_u *)&p_scs, PV_NONE,
2333 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2334 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2335 #ifdef FEAT_SMARTINDENT
2336 (char_u *)&p_si, PV_SI,
2337 #else
2338 (char_u *)NULL, PV_NONE,
2339 #endif
2340 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2341 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2342 (char_u *)&p_sta, PV_NONE,
2343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2344 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2345 (char_u *)&p_sts, PV_STS,
2346 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2347 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2348 (char_u *)NULL, PV_NONE,
2349 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2350 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2351 #ifdef FEAT_SPELL
2352 (char_u *)VAR_WIN, PV_SPELL,
2353 #else
2354 (char_u *)NULL, PV_NONE,
2355 #endif
2356 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2357 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
2358 #ifdef FEAT_SPELL
2359 (char_u *)&p_spc, PV_SPC,
2360 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
2361 #else
2362 (char_u *)NULL, PV_NONE,
2363 {(char_u *)0L, (char_u *)0L}
2364 #endif
2365 SCRIPTID_INIT},
2366 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
2367 #ifdef FEAT_SPELL
2368 (char_u *)&p_spf, PV_SPF,
2369 {(char_u *)"", (char_u *)0L}
2370 #else
2371 (char_u *)NULL, PV_NONE,
2372 {(char_u *)0L, (char_u *)0L}
2373 #endif
2374 SCRIPTID_INIT},
2375 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
2376 #ifdef FEAT_SPELL
2377 (char_u *)&p_spl, PV_SPL,
2378 {(char_u *)"en", (char_u *)0L}
2379 #else
2380 (char_u *)NULL, PV_NONE,
2381 {(char_u *)0L, (char_u *)0L}
2382 #endif
2383 SCRIPTID_INIT},
2384 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
2385 #ifdef FEAT_SPELL
2386 (char_u *)&p_sps, PV_NONE,
2387 {(char_u *)"best", (char_u *)0L}
2388 #else
2389 (char_u *)NULL, PV_NONE,
2390 {(char_u *)0L, (char_u *)0L}
2391 #endif
2392 SCRIPTID_INIT},
2393 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2394 #ifdef FEAT_WINDOWS
2395 (char_u *)&p_sb, PV_NONE,
2396 #else
2397 (char_u *)NULL, PV_NONE,
2398 #endif
2399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2400 {"splitright", "spr", P_BOOL|P_VI_DEF,
2401 #ifdef FEAT_VERTSPLIT
2402 (char_u *)&p_spr, PV_NONE,
2403 #else
2404 (char_u *)NULL, PV_NONE,
2405 #endif
2406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2407 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2408 (char_u *)&p_sol, PV_NONE,
2409 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2410 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2411 #ifdef FEAT_STL_OPT
2412 (char_u *)&p_stl, PV_STL,
2413 #else
2414 (char_u *)NULL, PV_NONE,
2415 #endif
2416 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2417 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2418 (char_u *)&p_su, PV_NONE,
2419 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2420 (char_u *)0L} SCRIPTID_INIT},
2421 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
2422 #ifdef FEAT_SEARCHPATH
2423 (char_u *)&p_sua, PV_SUA,
2424 {(char_u *)"", (char_u *)0L}
2425 #else
2426 (char_u *)NULL, PV_NONE,
2427 {(char_u *)0L, (char_u *)0L}
2428 #endif
2429 SCRIPTID_INIT},
2430 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2431 (char_u *)&p_swf, PV_SWF,
2432 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2433 {"swapsync", "sws", P_STRING|P_VI_DEF,
2434 (char_u *)&p_sws, PV_NONE,
2435 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
2436 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2437 (char_u *)&p_swb, PV_NONE,
2438 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2439 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2440 #ifdef FEAT_SYN_HL
2441 (char_u *)&p_smc, PV_SMC,
2442 {(char_u *)3000L, (char_u *)0L}
2443 #else
2444 (char_u *)NULL, PV_NONE,
2445 {(char_u *)0L, (char_u *)0L}
2446 #endif
2447 SCRIPTID_INIT},
2448 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
2449 #ifdef FEAT_SYN_HL
2450 (char_u *)&p_syn, PV_SYN,
2451 {(char_u *)"", (char_u *)0L}
2452 #else
2453 (char_u *)NULL, PV_NONE,
2454 {(char_u *)0L, (char_u *)0L}
2455 #endif
2456 SCRIPTID_INIT},
2457 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2458 #ifdef FEAT_STL_OPT
2459 (char_u *)&p_tal, PV_NONE,
2460 #else
2461 (char_u *)NULL, PV_NONE,
2462 #endif
2463 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2464 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2465 #ifdef FEAT_WINDOWS
2466 (char_u *)&p_tpm, PV_NONE,
2467 #else
2468 (char_u *)NULL, PV_NONE,
2469 #endif
2470 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
2471 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2472 (char_u *)&p_ts, PV_TS,
2473 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
2474 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2475 (char_u *)&p_tbs, PV_NONE,
2476 #ifdef VMS /* binary searching doesn't appear to work on VMS */
2477 {(char_u *)0L, (char_u *)0L}
2478 #else
2479 {(char_u *)TRUE, (char_u *)0L}
2480 #endif
2481 SCRIPTID_INIT},
2482 {"taglength", "tl", P_NUM|P_VI_DEF,
2483 (char_u *)&p_tl, PV_NONE,
2484 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2485 {"tagrelative", "tr", P_BOOL|P_VIM,
2486 (char_u *)&p_tr, PV_NONE,
2487 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2488 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2489 (char_u *)&p_tags, PV_TAGS,
2491 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2492 (char_u *)"./tags,./TAGS,tags,TAGS",
2493 #else
2494 (char_u *)"./tags,tags",
2495 #endif
2496 (char_u *)0L} SCRIPTID_INIT},
2497 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2498 (char_u *)&p_tgst, PV_NONE,
2499 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2500 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2501 (char_u *)&T_NAME, PV_NONE,
2502 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2503 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2504 #ifdef FEAT_ARABIC
2505 (char_u *)&p_tbidi, PV_NONE,
2506 #else
2507 (char_u *)NULL, PV_NONE,
2508 #endif
2509 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2510 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2511 #ifdef FEAT_MBYTE
2512 (char_u *)&p_tenc, PV_NONE,
2513 {(char_u *)"", (char_u *)0L}
2514 #else
2515 (char_u *)NULL, PV_NONE,
2516 {(char_u *)0L, (char_u *)0L}
2517 #endif
2518 SCRIPTID_INIT},
2519 {"terse", NULL, P_BOOL|P_VI_DEF,
2520 (char_u *)&p_terse, PV_NONE,
2521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2522 {"textauto", "ta", P_BOOL|P_VIM,
2523 (char_u *)&p_ta, PV_NONE,
2524 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2525 SCRIPTID_INIT},
2526 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2527 (char_u *)&p_tx, PV_TX,
2529 #ifdef USE_CRNL
2530 (char_u *)TRUE,
2531 #else
2532 (char_u *)FALSE,
2533 #endif
2534 (char_u *)0L} SCRIPTID_INIT},
2535 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2536 (char_u *)&p_tw, PV_TW,
2537 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2538 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2539 #ifdef FEAT_INS_EXPAND
2540 (char_u *)&p_tsr, PV_TSR,
2541 #else
2542 (char_u *)NULL, PV_NONE,
2543 #endif
2544 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2545 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2546 (char_u *)&p_to, PV_NONE,
2547 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2548 {"timeout", "to", P_BOOL|P_VI_DEF,
2549 (char_u *)&p_timeout, PV_NONE,
2550 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2551 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2552 (char_u *)&p_tm, PV_NONE,
2553 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
2554 {"title", NULL, P_BOOL|P_VI_DEF,
2555 #ifdef FEAT_TITLE
2556 (char_u *)&p_title, PV_NONE,
2557 #else
2558 (char_u *)NULL, PV_NONE,
2559 #endif
2560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2561 {"titlelen", NULL, P_NUM|P_VI_DEF,
2562 #ifdef FEAT_TITLE
2563 (char_u *)&p_titlelen, PV_NONE,
2564 #else
2565 (char_u *)NULL, PV_NONE,
2566 #endif
2567 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
2568 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
2569 #ifdef FEAT_TITLE
2570 (char_u *)&p_titleold, PV_NONE,
2571 {(char_u *)N_("Thanks for flying Vim"),
2572 (char_u *)0L}
2573 #else
2574 (char_u *)NULL, PV_NONE,
2575 {(char_u *)0L, (char_u *)0L}
2576 #endif
2577 SCRIPTID_INIT},
2578 {"titlestring", NULL, P_STRING|P_VI_DEF,
2579 #ifdef FEAT_TITLE
2580 (char_u *)&p_titlestring, PV_NONE,
2581 #else
2582 (char_u *)NULL, PV_NONE,
2583 #endif
2584 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2585 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2586 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2587 (char_u *)&p_toolbar, PV_NONE,
2588 {(char_u *)"icons,tooltips", (char_u *)0L}
2589 SCRIPTID_INIT},
2590 #endif
2591 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2592 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2593 (char_u *)&p_tbis, PV_NONE,
2594 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
2595 #endif
2596 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2597 (char_u *)&p_ttimeout, PV_NONE,
2598 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2599 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2600 (char_u *)&p_ttm, PV_NONE,
2601 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
2602 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2603 (char_u *)&p_tbi, PV_NONE,
2604 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2605 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2606 (char_u *)&p_tf, PV_NONE,
2607 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2608 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2609 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2610 (char_u *)&p_ttym, PV_NONE,
2611 #else
2612 (char_u *)NULL, PV_NONE,
2613 #endif
2614 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2615 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2616 (char_u *)&p_ttyscroll, PV_NONE,
2617 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
2618 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2619 (char_u *)&T_NAME, PV_NONE,
2620 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2621 #ifdef FEAT_PERSISTENT_UNDO
2622 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2623 (char_u *)&p_udir, PV_NONE,
2624 {(char_u *)DFLT_UDIR, (char_u *)0L}},
2625 {"undofile", "udf", P_BOOL|P_VIM,
2626 (char_u *)&p_udf, PV_UDF,
2627 {(char_u *)TRUE, (char_u *)0L}},
2628 #endif
2629 {"undolevels", "ul", P_NUM|P_VI_DEF,
2630 (char_u *)&p_ul, PV_NONE,
2632 #if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2633 (char_u *)1000L,
2634 #else
2635 (char_u *)100L,
2636 #endif
2637 (char_u *)0L} SCRIPTID_INIT},
2638 {"updatecount", "uc", P_NUM|P_VI_DEF,
2639 (char_u *)&p_uc, PV_NONE,
2640 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
2641 {"updatetime", "ut", P_NUM|P_VI_DEF,
2642 (char_u *)&p_ut, PV_NONE,
2643 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
2644 #ifdef FEAT_VARTABS
2645 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2646 (char_u *)&p_vsts, PV_VSTS,
2647 {(char_u *)"", (char_u *)0L}},
2648 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2649 (char_u *)&p_vts, PV_VTS,
2650 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2651 #endif
2652 {"verbose", "vbs", P_NUM|P_VI_DEF,
2653 (char_u *)&p_verbose, PV_NONE,
2654 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2655 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2656 (char_u *)&p_vfile, PV_NONE,
2657 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2658 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2659 #ifdef FEAT_SESSION
2660 (char_u *)&p_vdir, PV_NONE,
2661 {(char_u *)DFLT_VDIR, (char_u *)0L}
2662 #else
2663 (char_u *)NULL, PV_NONE,
2664 {(char_u *)0L, (char_u *)0L}
2665 #endif
2666 SCRIPTID_INIT},
2667 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2668 #ifdef FEAT_SESSION
2669 (char_u *)&p_vop, PV_NONE,
2670 {(char_u *)"folds,options,cursor", (char_u *)0L}
2671 #else
2672 (char_u *)NULL, PV_NONE,
2673 {(char_u *)0L, (char_u *)0L}
2674 #endif
2675 SCRIPTID_INIT},
2676 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2677 #ifdef FEAT_VIMINFO
2678 (char_u *)&p_viminfo, PV_NONE,
2679 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2680 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
2681 #else
2682 # ifdef AMIGA
2683 {(char_u *)"",
2684 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2685 # else
2686 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
2687 # endif
2688 #endif
2689 #else
2690 (char_u *)NULL, PV_NONE,
2691 {(char_u *)0L, (char_u *)0L}
2692 #endif
2693 SCRIPTID_INIT},
2694 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2695 #ifdef FEAT_VIRTUALEDIT
2696 (char_u *)&p_ve, PV_NONE,
2697 {(char_u *)"", (char_u *)""}
2698 #else
2699 (char_u *)NULL, PV_NONE,
2700 {(char_u *)0L, (char_u *)0L}
2701 #endif
2702 SCRIPTID_INIT},
2703 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2704 (char_u *)&p_vb, PV_NONE,
2705 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2706 {"w300", NULL, P_NUM|P_VI_DEF,
2707 (char_u *)NULL, PV_NONE,
2708 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2709 {"w1200", NULL, P_NUM|P_VI_DEF,
2710 (char_u *)NULL, PV_NONE,
2711 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2712 {"w9600", NULL, P_NUM|P_VI_DEF,
2713 (char_u *)NULL, PV_NONE,
2714 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2715 {"warn", NULL, P_BOOL|P_VI_DEF,
2716 (char_u *)&p_warn, PV_NONE,
2717 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2718 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2719 (char_u *)&p_wiv, PV_NONE,
2720 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2721 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2722 (char_u *)&p_ww, PV_NONE,
2723 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
2724 {"wildchar", "wc", P_NUM|P_VIM,
2725 (char_u *)&p_wc, PV_NONE,
2726 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2727 SCRIPTID_INIT},
2728 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2729 (char_u *)&p_wcm, PV_NONE,
2730 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2731 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2732 #ifdef FEAT_WILDIGN
2733 (char_u *)&p_wig, PV_NONE,
2734 #else
2735 (char_u *)NULL, PV_NONE,
2736 #endif
2737 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2738 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2739 #ifdef FEAT_WILDMENU
2740 (char_u *)&p_wmnu, PV_NONE,
2741 #else
2742 (char_u *)NULL, PV_NONE,
2743 #endif
2744 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2745 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2746 (char_u *)&p_wim, PV_NONE,
2747 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
2748 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2749 #ifdef FEAT_CMDL_COMPL
2750 (char_u *)&p_wop, PV_NONE,
2751 {(char_u *)"", (char_u *)0L}
2752 #else
2753 (char_u *)NULL, PV_NONE,
2754 {(char_u *)NULL, (char_u *)0L}
2755 #endif
2756 SCRIPTID_INIT},
2757 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2758 #ifdef FEAT_WAK
2759 (char_u *)&p_wak, PV_NONE,
2760 {(char_u *)"menu", (char_u *)0L}
2761 #else
2762 (char_u *)NULL, PV_NONE,
2763 {(char_u *)NULL, (char_u *)0L}
2764 #endif
2765 SCRIPTID_INIT},
2766 {"window", "wi", P_NUM|P_VI_DEF,
2767 (char_u *)&p_window, PV_NONE,
2768 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2769 {"winheight", "wh", P_NUM|P_VI_DEF,
2770 #ifdef FEAT_WINDOWS
2771 (char_u *)&p_wh, PV_NONE,
2772 #else
2773 (char_u *)NULL, PV_NONE,
2774 #endif
2775 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2776 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
2777 #ifdef FEAT_WINDOWS
2778 (char_u *)VAR_WIN, PV_WFH,
2779 #else
2780 (char_u *)NULL, PV_NONE,
2781 #endif
2782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2783 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2784 #ifdef FEAT_VERTSPLIT
2785 (char_u *)VAR_WIN, PV_WFW,
2786 #else
2787 (char_u *)NULL, PV_NONE,
2788 #endif
2789 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2790 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2791 #ifdef FEAT_WINDOWS
2792 (char_u *)&p_wmh, PV_NONE,
2793 #else
2794 (char_u *)NULL, PV_NONE,
2795 #endif
2796 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2797 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2798 #ifdef FEAT_VERTSPLIT
2799 (char_u *)&p_wmw, PV_NONE,
2800 #else
2801 (char_u *)NULL, PV_NONE,
2802 #endif
2803 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2804 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2805 #ifdef FEAT_VERTSPLIT
2806 (char_u *)&p_wiw, PV_NONE,
2807 #else
2808 (char_u *)NULL, PV_NONE,
2809 #endif
2810 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
2811 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2812 (char_u *)VAR_WIN, PV_WRAP,
2813 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2814 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2815 (char_u *)&p_wm, PV_WM,
2816 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2817 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2818 (char_u *)&p_ws, PV_NONE,
2819 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2820 {"write", NULL, P_BOOL|P_VI_DEF,
2821 (char_u *)&p_write, PV_NONE,
2822 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2823 {"writeany", "wa", P_BOOL|P_VI_DEF,
2824 (char_u *)&p_wa, PV_NONE,
2825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2826 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2827 (char_u *)&p_wb, PV_NONE,
2829 #ifdef FEAT_WRITEBACKUP
2830 (char_u *)TRUE,
2831 #else
2832 (char_u *)FALSE,
2833 #endif
2834 (char_u *)0L} SCRIPTID_INIT},
2835 {"writedelay", "wd", P_NUM|P_VI_DEF,
2836 (char_u *)&p_wd, PV_NONE,
2837 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2839 /* terminal output codes */
2840 #define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
2841 (char_u *)&vvv, PV_NONE, \
2842 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2844 p_term("t_AB", T_CAB)
2845 p_term("t_AF", T_CAF)
2846 p_term("t_AL", T_CAL)
2847 p_term("t_al", T_AL)
2848 p_term("t_bc", T_BC)
2849 p_term("t_cd", T_CD)
2850 p_term("t_ce", T_CE)
2851 p_term("t_cl", T_CL)
2852 p_term("t_cm", T_CM)
2853 p_term("t_Co", T_CCO)
2854 p_term("t_CS", T_CCS)
2855 p_term("t_cs", T_CS)
2856 #ifdef FEAT_VERTSPLIT
2857 p_term("t_CV", T_CSV)
2858 #endif
2859 p_term("t_ut", T_UT)
2860 p_term("t_da", T_DA)
2861 p_term("t_db", T_DB)
2862 p_term("t_DL", T_CDL)
2863 p_term("t_dl", T_DL)
2864 p_term("t_fs", T_FS)
2865 p_term("t_IE", T_CIE)
2866 p_term("t_IS", T_CIS)
2867 p_term("t_ke", T_KE)
2868 p_term("t_ks", T_KS)
2869 p_term("t_le", T_LE)
2870 p_term("t_mb", T_MB)
2871 p_term("t_md", T_MD)
2872 p_term("t_me", T_ME)
2873 p_term("t_mr", T_MR)
2874 p_term("t_ms", T_MS)
2875 p_term("t_nd", T_ND)
2876 p_term("t_op", T_OP)
2877 p_term("t_RI", T_CRI)
2878 p_term("t_RV", T_CRV)
2879 p_term("t_Sb", T_CSB)
2880 p_term("t_Sf", T_CSF)
2881 p_term("t_se", T_SE)
2882 p_term("t_so", T_SO)
2883 p_term("t_sr", T_SR)
2884 p_term("t_ts", T_TS)
2885 p_term("t_te", T_TE)
2886 p_term("t_ti", T_TI)
2887 p_term("t_ue", T_UE)
2888 p_term("t_us", T_US)
2889 p_term("t_vb", T_VB)
2890 p_term("t_ve", T_VE)
2891 p_term("t_vi", T_VI)
2892 p_term("t_vs", T_VS)
2893 p_term("t_WP", T_CWP)
2894 p_term("t_WS", T_CWS)
2895 p_term("t_SI", T_CSI)
2896 p_term("t_EI", T_CEI)
2897 p_term("t_xs", T_XS)
2898 p_term("t_ZH", T_CZH)
2899 p_term("t_ZR", T_CZR)
2901 /* terminal key codes are not in here */
2903 /* end marker */
2904 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
2907 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2909 #ifdef FEAT_MBYTE
2910 static char *(p_ambw_values[]) = {"single", "double", NULL};
2911 #endif
2912 static char *(p_bg_values[]) = {"light", "dark", NULL};
2913 static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2914 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
2915 #ifdef FEAT_CMDL_COMPL
2916 static char *(p_wop_values[]) = {"tagfile", NULL};
2917 #endif
2918 #ifdef FEAT_WAK
2919 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2920 #endif
2921 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2922 #ifdef FEAT_VISUAL
2923 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2924 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2925 #endif
2926 #ifdef FEAT_VISUAL
2927 static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2928 #endif
2929 #ifdef FEAT_BROWSE
2930 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2931 #endif
2932 #ifdef FEAT_SCROLLBIND
2933 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2934 #endif
2935 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
2936 #ifdef FEAT_VERTSPLIT
2937 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2938 #endif
2939 #if defined(FEAT_QUICKFIX)
2940 # ifdef FEAT_AUTOCMD
2941 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2942 # else
2943 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
2944 # endif
2945 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2946 #endif
2947 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2948 #ifdef FEAT_FOLDING
2949 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
2950 # ifdef FEAT_DIFF
2951 "diff",
2952 # endif
2953 NULL};
2954 static char *(p_fcl_values[]) = {"all", NULL};
2955 #endif
2956 #ifdef FEAT_INS_EXPAND
2957 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
2958 #endif
2960 static void set_option_default __ARGS((int, int opt_flags, int compatible));
2961 static void set_options_default __ARGS((int opt_flags));
2962 static char_u *term_bg_default __ARGS((void));
2963 static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
2964 static char_u *illegal_char __ARGS((char_u *, int));
2965 static int string_to_key __ARGS((char_u *arg));
2966 #ifdef FEAT_CMDWIN
2967 static char_u *check_cedit __ARGS((void));
2968 #endif
2969 #ifdef FEAT_TITLE
2970 static void did_set_title __ARGS((int icon));
2971 #endif
2972 static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2973 static void didset_options __ARGS((void));
2974 static void check_string_option __ARGS((char_u **pp));
2975 #if defined(FEAT_EVAL) || defined(PROTO)
2976 static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2977 #else
2978 # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2979 #endif
2980 static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2981 static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2982 static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
2983 static char_u *set_chars_option __ARGS((char_u **varp));
2984 #ifdef FEAT_CLIPBOARD
2985 static char_u *check_clipboard_option __ARGS((void));
2986 #endif
2987 #ifdef FEAT_SPELL
2988 static char_u *compile_cap_prog __ARGS((buf_T *buf));
2989 #endif
2990 #ifdef FEAT_EVAL
2991 static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2992 #endif
2993 static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
2994 static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
2995 static void check_redraw __ARGS((long_u flags));
2996 static int findoption __ARGS((char_u *));
2997 static int find_key_option __ARGS((char_u *));
2998 static void showoptions __ARGS((int all, int opt_flags));
2999 static int optval_default __ARGS((struct vimoption *, char_u *varp));
3000 static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3001 static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3002 static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3003 static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3004 static int istermoption __ARGS((struct vimoption *));
3005 static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3006 static char_u *get_varp __ARGS((struct vimoption *));
3007 static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3008 static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3009 #ifdef FEAT_LANGMAP
3010 static void langmap_init __ARGS((void));
3011 static void langmap_set __ARGS((void));
3012 #endif
3013 static void paste_option_changed __ARGS((void));
3014 static void compatible_set __ARGS((void));
3015 #ifdef FEAT_LINEBREAK
3016 static void fill_breakat_flags __ARGS((void));
3017 #endif
3018 static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3019 static int check_opt_strings __ARGS((char_u *val, char **values, int));
3020 static int check_opt_wim __ARGS((void));
3023 * Initialize the options, first part.
3025 * Called only once from main(), just after creating the first buffer.
3027 void
3028 set_init_1()
3030 char_u *p;
3031 int opt_idx;
3032 long_u n;
3034 #ifdef FEAT_LANGMAP
3035 langmap_init();
3036 #endif
3038 /* Be Vi compatible by default */
3039 p_cp = TRUE;
3041 /* Use POSIX compatibility when $VIM_POSIX is set. */
3042 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
3044 set_string_default("cpo", (char_u *)CPO_ALL);
3045 set_string_default("shm", (char_u *)"A");
3049 * Find default value for 'shell' option.
3050 * Don't use it if it is empty.
3052 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
3053 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3054 # ifdef __EMX__
3055 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
3056 # endif
3057 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
3058 # ifdef WIN3264
3059 || ((p = default_shell()) != NULL && *p != NUL)
3060 # endif
3061 #endif
3063 set_string_default("sh", p);
3065 #ifdef FEAT_WILDIGN
3067 * Set the default for 'backupskip' to include environment variables for
3068 * temp files.
3071 # ifdef UNIX
3072 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3073 # else
3074 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3075 # endif
3076 int len;
3077 garray_T ga;
3078 int mustfree;
3080 ga_init2(&ga, 1, 100);
3081 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3083 mustfree = FALSE;
3084 # ifdef UNIX
3085 if (*names[n] == NUL)
3086 p = (char_u *)"/tmp";
3087 else
3088 # endif
3089 p = vim_getenv((char_u *)names[n], &mustfree);
3090 if (p != NULL && *p != NUL)
3092 /* First time count the NUL, otherwise count the ','. */
3093 len = (int)STRLEN(p) + 3;
3094 if (ga_grow(&ga, len) == OK)
3096 if (ga.ga_len > 0)
3097 STRCAT(ga.ga_data, ",");
3098 STRCAT(ga.ga_data, p);
3099 add_pathsep(ga.ga_data);
3100 STRCAT(ga.ga_data, "*");
3101 ga.ga_len += len;
3104 if (mustfree)
3105 vim_free(p);
3107 if (ga.ga_data != NULL)
3109 set_string_default("bsk", ga.ga_data);
3110 vim_free(ga.ga_data);
3113 #endif
3116 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3118 opt_idx = findoption((char_u *)"maxmemtot");
3119 if (opt_idx >= 0)
3121 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3122 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3123 #endif
3125 #ifdef HAVE_AVAIL_MEM
3126 /* Use amount of memory available at this moment. */
3127 n = (mch_avail_mem(FALSE) >> 11);
3128 #else
3129 # ifdef HAVE_TOTAL_MEM
3130 /* Use amount of memory available to Vim. */
3131 n = (mch_total_mem(FALSE) >> 1);
3132 # else
3133 n = (0x7fffffff >> 11);
3134 # endif
3135 #endif
3136 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3137 opt_idx = findoption((char_u *)"maxmem");
3138 if (opt_idx >= 0)
3140 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3141 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3142 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3143 #endif
3144 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3149 #ifdef FEAT_GUI_W32
3150 /* force 'shortname' for Win32s */
3151 if (gui_is_win32s())
3153 opt_idx = findoption((char_u *)"shortname");
3154 if (opt_idx >= 0)
3155 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3157 #endif
3159 #ifdef FEAT_SEARCHPATH
3161 char_u *cdpath;
3162 char_u *buf;
3163 int i;
3164 int j;
3165 int mustfree = FALSE;
3167 /* Initialize the 'cdpath' option's default value. */
3168 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
3169 if (cdpath != NULL)
3171 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3172 if (buf != NULL)
3174 buf[0] = ','; /* start with ",", current dir first */
3175 j = 1;
3176 for (i = 0; cdpath[i] != NUL; ++i)
3178 if (vim_ispathlistsep(cdpath[i]))
3179 buf[j++] = ',';
3180 else
3182 if (cdpath[i] == ' ' || cdpath[i] == ',')
3183 buf[j++] = '\\';
3184 buf[j++] = cdpath[i];
3187 buf[j] = NUL;
3188 opt_idx = findoption((char_u *)"cdpath");
3189 if (opt_idx >= 0)
3191 options[opt_idx].def_val[VI_DEFAULT] = buf;
3192 options[opt_idx].flags |= P_DEF_ALLOCED;
3195 if (mustfree)
3196 vim_free(cdpath);
3199 #endif
3201 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3202 /* Set print encoding on platforms that don't default to latin1 */
3203 set_string_default("penc",
3204 # if defined(MSWIN) || defined(OS2)
3205 (char_u *)"cp1252"
3206 # else
3207 # ifdef VMS
3208 (char_u *)"dec-mcs"
3209 # else
3210 # ifdef EBCDIC
3211 (char_u *)"ebcdic-uk"
3212 # else
3213 # ifdef MAC
3214 (char_u *)"mac-roman"
3215 # else /* HPUX */
3216 (char_u *)"hp-roman8"
3217 # endif
3218 # endif
3219 # endif
3220 # endif
3222 #endif
3224 #ifdef FEAT_POSTSCRIPT
3225 /* 'printexpr' must be allocated to be able to evaluate it. */
3226 set_string_default("pexpr",
3227 # if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3228 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
3229 # else
3230 # ifdef VMS
3231 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3233 # else
3234 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3235 # endif
3236 # endif
3238 #endif
3241 * Set all the options (except the terminal options) to their default
3242 * value. Also set the global value for local options.
3244 set_options_default(0);
3246 #ifdef FEAT_GUI
3247 if (found_reverse_arg)
3248 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3249 #endif
3251 curbuf->b_p_initialized = TRUE;
3252 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3253 check_buf_options(curbuf);
3254 check_win_options(curwin);
3255 check_options();
3257 /* Must be before option_expand(), because that one needs vim_isIDc() */
3258 didset_options();
3260 #ifdef FEAT_SPELL
3261 /* Use the current chartab for the generic chartab. */
3262 init_spell_chartab();
3263 #endif
3265 #ifdef FEAT_LINEBREAK
3267 * initialize the table for 'breakat'.
3269 fill_breakat_flags();
3270 #endif
3273 * Expand environment variables and things like "~" for the defaults.
3274 * If option_expand() returns non-NULL the variable is expanded. This can
3275 * only happen for non-indirect options.
3276 * Also set the default to the expanded value, so ":set" does not list
3277 * them.
3278 * Don't set the P_ALLOCED flag, because we don't want to free the
3279 * default.
3281 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3283 if ((options[opt_idx].flags & P_GETTEXT)
3284 && options[opt_idx].var != NULL)
3285 p = (char_u *)_(*(char **)options[opt_idx].var);
3286 else
3287 p = option_expand(opt_idx, NULL);
3288 if (p != NULL && (p = vim_strsave(p)) != NULL)
3290 *(char_u **)options[opt_idx].var = p;
3291 /* VIMEXP
3292 * Defaults for all expanded options are currently the same for Vi
3293 * and Vim. When this changes, add some code here! Also need to
3294 * split P_DEF_ALLOCED in two.
3296 if (options[opt_idx].flags & P_DEF_ALLOCED)
3297 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3298 options[opt_idx].def_val[VI_DEFAULT] = p;
3299 options[opt_idx].flags |= P_DEF_ALLOCED;
3303 /* Initialize the highlight_attr[] table. */
3304 highlight_changed();
3306 save_file_ff(curbuf); /* Buffer is unchanged */
3308 /* Parse default for 'wildmode' */
3309 check_opt_wim();
3311 #if defined(FEAT_ARABIC)
3312 /* Detect use of mlterm.
3313 * Mlterm is a terminal emulator akin to xterm that has some special
3314 * abilities (bidi namely).
3315 * NOTE: mlterm's author is being asked to 'set' a variable
3316 * instead of an environment variable due to inheritance.
3318 if (mch_getenv((char_u *)"MLTERM") != NULL)
3319 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3320 #endif
3322 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3323 /* Parse default for 'fillchars'. */
3324 (void)set_chars_option(&p_fcs);
3325 #endif
3327 #ifdef FEAT_CLIPBOARD
3328 /* Parse default for 'clipboard' */
3329 (void)check_clipboard_option();
3330 #endif
3332 #ifdef FEAT_MBYTE
3333 # if defined(WIN3264) && defined(FEAT_GETTEXT)
3335 * If $LANG isn't set, try to get a good value for it. This makes the
3336 * right language be used automatically. Don't do this for English.
3338 if (mch_getenv((char_u *)"LANG") == NULL)
3340 char buf[20];
3342 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3343 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3344 * only the first two. */
3345 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3346 (LPTSTR)buf, 20);
3347 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3349 /* There are a few exceptions (probably more) */
3350 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3351 STRCPY(buf, "zh_TW");
3352 else if (STRNICMP(buf, "chs", 3) == 0
3353 || STRNICMP(buf, "zhc", 3) == 0)
3354 STRCPY(buf, "zh_CN");
3355 else if (STRNICMP(buf, "jp", 2) == 0)
3356 STRCPY(buf, "ja");
3357 else
3358 buf[2] = NUL; /* truncate to two-letter code */
3359 vim_setenv("LANG", buf);
3362 # else
3363 # ifdef MACOS_CONVERT
3364 /* Moved to os_mac_conv.c to avoid dependency problems. */
3365 mac_lang_init();
3366 # endif
3367 # endif
3369 /* enc_locale() will try to find the encoding of the current locale. */
3370 p = enc_locale();
3371 if (p != NULL)
3373 char_u *save_enc;
3375 /* Try setting 'encoding' and check if the value is valid.
3376 * If not, go back to the default "latin1". */
3377 save_enc = p_enc;
3378 p_enc = p;
3379 if (STRCMP(p_enc, "gb18030") == 0)
3381 /* We don't support "gb18030", but "cp936" is a good substitute
3382 * for practical purposes, thus use that. It's not an alias to
3383 * still support conversion between gb18030 and utf-8. */
3384 p_enc = vim_strsave((char_u *)"cp936");
3385 vim_free(p);
3387 if (mb_init() == NULL)
3389 opt_idx = findoption((char_u *)"encoding");
3390 if (opt_idx >= 0)
3392 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3393 options[opt_idx].flags |= P_DEF_ALLOCED;
3396 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3397 || defined(VMS)
3398 if (STRCMP(p_enc, "latin1") == 0
3399 # ifdef FEAT_MBYTE
3400 || enc_utf8
3401 # endif
3404 /* Adjust the default for 'isprint' and 'iskeyword' to match
3405 * latin1. Also set the defaults for when 'nocompatible' is
3406 * set. */
3407 set_string_option_direct((char_u *)"isp", -1,
3408 ISP_LATIN1, OPT_FREE, SID_NONE);
3409 set_string_option_direct((char_u *)"isk", -1,
3410 ISK_LATIN1, OPT_FREE, SID_NONE);
3411 opt_idx = findoption((char_u *)"isp");
3412 if (opt_idx >= 0)
3413 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
3414 opt_idx = findoption((char_u *)"isk");
3415 if (opt_idx >= 0)
3416 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
3417 (void)init_chartab();
3419 #endif
3421 # if defined(WIN3264) && !defined(FEAT_GUI)
3422 /* Win32 console: When GetACP() returns a different value from
3423 * GetConsoleCP() set 'termencoding'. */
3424 if (GetACP() != GetConsoleCP())
3426 char buf[50];
3428 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3429 p_tenc = vim_strsave((char_u *)buf);
3430 if (p_tenc != NULL)
3432 opt_idx = findoption((char_u *)"termencoding");
3433 if (opt_idx >= 0)
3435 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3436 options[opt_idx].flags |= P_DEF_ALLOCED;
3438 convert_setup(&input_conv, p_tenc, p_enc);
3439 convert_setup(&output_conv, p_enc, p_tenc);
3441 else
3442 p_tenc = empty_option;
3444 # endif
3445 # if defined(WIN3264) && defined(FEAT_MBYTE)
3446 /* $HOME may have characters in active code page. */
3447 init_homedir();
3448 # endif
3450 else
3452 vim_free(p_enc);
3453 p_enc = save_enc;
3456 #endif
3458 #ifdef FEAT_MULTI_LANG
3459 /* Set the default for 'helplang'. */
3460 set_helplang_default(get_mess_lang());
3461 #endif
3465 * Set an option to its default value.
3466 * This does not take care of side effects!
3468 static void
3469 set_option_default(opt_idx, opt_flags, compatible)
3470 int opt_idx;
3471 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3472 int compatible; /* use Vi default value */
3474 char_u *varp; /* pointer to variable for current option */
3475 int dvi; /* index in def_val[] */
3476 long_u flags;
3477 long_u *flagsp;
3478 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3480 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3481 flags = options[opt_idx].flags;
3482 if (varp != NULL) /* skip hidden option, nothing to do for it */
3484 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3485 if (flags & P_STRING)
3487 /* Use set_string_option_direct() for local options to handle
3488 * freeing and allocating the value. */
3489 if (options[opt_idx].indir != PV_NONE)
3490 set_string_option_direct(NULL, opt_idx,
3491 options[opt_idx].def_val[dvi], opt_flags, 0);
3492 else
3494 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3495 free_string_option(*(char_u **)(varp));
3496 *(char_u **)varp = options[opt_idx].def_val[dvi];
3497 options[opt_idx].flags &= ~P_ALLOCED;
3500 else if (flags & P_NUM)
3502 if (options[opt_idx].indir == PV_SCROLL)
3503 win_comp_scroll(curwin);
3504 else
3506 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
3507 /* May also set global value for local option. */
3508 if (both)
3509 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3510 *(long *)varp;
3513 else /* P_BOOL */
3515 /* the cast to long is required for Manx C, long_i is needed for
3516 * MSVC */
3517 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
3518 #ifdef UNIX
3519 /* 'modeline' defaults to off for root */
3520 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3521 *(int *)varp = FALSE;
3522 #endif
3523 /* May also set global value for local option. */
3524 if (both)
3525 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3526 *(int *)varp;
3529 /* The default value is not insecure. */
3530 flagsp = insecure_flag(opt_idx, opt_flags);
3531 *flagsp = *flagsp & ~P_INSECURE;
3534 #ifdef FEAT_EVAL
3535 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
3536 #endif
3540 * Set all options (except terminal options) to their default value.
3542 static void
3543 set_options_default(opt_flags)
3544 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3546 int i;
3547 #ifdef FEAT_WINDOWS
3548 win_T *wp;
3549 tabpage_T *tp;
3550 #endif
3552 for (i = 0; !istermoption(&options[i]); i++)
3553 if (!(options[i].flags & P_NODEFAULT))
3554 set_option_default(i, opt_flags, p_cp);
3556 #ifdef FEAT_WINDOWS
3557 /* The 'scroll' option must be computed for all windows. */
3558 FOR_ALL_TAB_WINDOWS(tp, wp)
3559 win_comp_scroll(wp);
3560 #else
3561 win_comp_scroll(curwin);
3562 #endif
3566 * Set the Vi-default value of a string option.
3567 * Used for 'sh', 'backupskip' and 'term'.
3569 void
3570 set_string_default(name, val)
3571 char *name;
3572 char_u *val;
3574 char_u *p;
3575 int opt_idx;
3577 p = vim_strsave(val);
3578 if (p != NULL) /* we don't want a NULL */
3580 opt_idx = findoption((char_u *)name);
3581 if (opt_idx >= 0)
3583 if (options[opt_idx].flags & P_DEF_ALLOCED)
3584 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3585 options[opt_idx].def_val[VI_DEFAULT] = p;
3586 options[opt_idx].flags |= P_DEF_ALLOCED;
3592 * Set the Vi-default value of a number option.
3593 * Used for 'lines' and 'columns'.
3595 void
3596 set_number_default(name, val)
3597 char *name;
3598 long val;
3600 int opt_idx;
3602 opt_idx = findoption((char_u *)name);
3603 if (opt_idx >= 0)
3604 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3607 #if defined(EXITFREE) || defined(PROTO)
3609 * Free all options.
3611 void
3612 free_all_options()
3614 int i;
3616 for (i = 0; !istermoption(&options[i]); i++)
3618 if (options[i].indir == PV_NONE)
3620 /* global option: free value and default value. */
3621 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3622 free_string_option(*(char_u **)options[i].var);
3623 if (options[i].flags & P_DEF_ALLOCED)
3624 free_string_option(options[i].def_val[VI_DEFAULT]);
3626 else if (options[i].var != VAR_WIN
3627 && (options[i].flags & P_STRING))
3628 /* buffer-local option: free global value */
3629 free_string_option(*(char_u **)options[i].var);
3632 #endif
3636 * Initialize the options, part two: After getting Rows and Columns and
3637 * setting 'term'.
3639 void
3640 set_init_2()
3642 int idx;
3645 * 'scroll' defaults to half the window height. Note that this default is
3646 * wrong when the window height changes.
3648 set_number_default("scroll", (long)((long_u)Rows >> 1));
3649 idx = findoption((char_u *)"scroll");
3650 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3651 set_option_default(idx, OPT_LOCAL, p_cp);
3652 comp_col();
3655 * 'window' is only for backwards compatibility with Vi.
3656 * Default is Rows - 1.
3658 if (!option_was_set((char_u *)"window"))
3659 p_window = Rows - 1;
3660 set_number_default("window", Rows - 1);
3662 /* For DOS console the default is always black. */
3663 #if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3665 * If 'background' wasn't set by the user, try guessing the value,
3666 * depending on the terminal name. Only need to check for terminals
3667 * with a dark background, that can handle color.
3669 idx = findoption((char_u *)"bg");
3670 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3671 && *term_bg_default() == 'd')
3673 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
3674 /* don't mark it as set, when starting the GUI it may be
3675 * changed again */
3676 options[idx].flags &= ~P_WAS_SET;
3678 #endif
3680 #ifdef CURSOR_SHAPE
3681 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3682 #endif
3683 #ifdef FEAT_MOUSESHAPE
3684 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3685 #endif
3686 #ifdef FEAT_PRINTER
3687 (void)parse_printoptions(); /* parse 'printoptions' default value */
3688 #endif
3692 * Return "dark" or "light" depending on the kind of terminal.
3693 * This is just guessing! Recognized are:
3694 * "linux" Linux console
3695 * "screen.linux" Linux console with screen
3696 * "cygwin" Cygwin shell
3697 * "putty" Putty program
3698 * We also check the COLORFGBG environment variable, which is set by
3699 * rxvt and derivatives. This variable contains either two or three
3700 * values separated by semicolons; we want the last value in either
3701 * case. If this value is 0-6 or 8, our background is dark.
3703 static char_u *
3704 term_bg_default()
3706 #if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3707 /* DOS console nearly always black */
3708 return (char_u *)"dark";
3709 #else
3710 char_u *p;
3712 if (STRCMP(T_NAME, "linux") == 0
3713 || STRCMP(T_NAME, "screen.linux") == 0
3714 || STRCMP(T_NAME, "cygwin") == 0
3715 || STRCMP(T_NAME, "putty") == 0
3716 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3717 && (p = vim_strrchr(p, ';')) != NULL
3718 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3719 && p[2] == NUL))
3720 return (char_u *)"dark";
3721 return (char_u *)"light";
3722 #endif
3726 * Initialize the options, part three: After reading the .vimrc
3728 void
3729 set_init_3()
3731 #if defined(UNIX) || defined(OS2) || defined(WIN3264)
3733 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3734 * This is done after other initializations, where 'shell' might have been
3735 * set, but only if they have not been set before.
3737 char_u *p;
3738 int idx_srr;
3739 int do_srr;
3740 #ifdef FEAT_QUICKFIX
3741 int idx_sp;
3742 int do_sp;
3743 #endif
3745 idx_srr = findoption((char_u *)"srr");
3746 if (idx_srr < 0)
3747 do_srr = FALSE;
3748 else
3749 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3750 #ifdef FEAT_QUICKFIX
3751 idx_sp = findoption((char_u *)"sp");
3752 if (idx_sp < 0)
3753 do_sp = FALSE;
3754 else
3755 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3756 #endif
3759 * Isolate the name of the shell:
3760 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3761 * - Remove any argument. E.g., "csh -f" -> "csh".
3762 * But don't allow a space in the path, so that this works:
3763 * "/usr/bin/csh --rcfile ~/.cshrc"
3764 * But don't do that for Windows, it's common to have a space in the path.
3766 #ifdef WIN3264
3767 p = gettail(p_sh);
3768 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3769 #else
3770 p = skiptowhite(p_sh);
3771 if (*p == NUL)
3773 /* No white space, use the tail. */
3774 p = vim_strsave(gettail(p_sh));
3776 else
3778 char_u *p1, *p2;
3780 /* Find the last path separator before the space. */
3781 p1 = p_sh;
3782 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3783 if (vim_ispathsep(*p2))
3784 p1 = p2 + 1;
3785 p = vim_strnsave(p1, (int)(p - p1));
3787 #endif
3788 if (p != NULL)
3791 * Default for p_sp is "| tee", for p_srr is ">".
3792 * For known shells it is changed here to include stderr.
3794 if ( fnamecmp(p, "csh") == 0
3795 || fnamecmp(p, "tcsh") == 0
3796 # if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3797 || fnamecmp(p, "csh.exe") == 0
3798 || fnamecmp(p, "tcsh.exe") == 0
3799 # endif
3802 #if defined(FEAT_QUICKFIX)
3803 if (do_sp)
3805 # ifdef WIN3264
3806 p_sp = (char_u *)">&";
3807 # else
3808 p_sp = (char_u *)"|& tee";
3809 # endif
3810 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3812 #endif
3813 if (do_srr)
3815 p_srr = (char_u *)">&";
3816 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3819 else
3820 # ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3821 if ( fnamecmp(p, "sh") == 0
3822 || fnamecmp(p, "ksh") == 0
3823 || fnamecmp(p, "zsh") == 0
3824 || fnamecmp(p, "zsh-beta") == 0
3825 || fnamecmp(p, "bash") == 0
3826 # ifdef WIN3264
3827 || fnamecmp(p, "cmd") == 0
3828 || fnamecmp(p, "sh.exe") == 0
3829 || fnamecmp(p, "ksh.exe") == 0
3830 || fnamecmp(p, "zsh.exe") == 0
3831 || fnamecmp(p, "zsh-beta.exe") == 0
3832 || fnamecmp(p, "bash.exe") == 0
3833 || fnamecmp(p, "cmd.exe") == 0
3834 # endif
3836 # endif
3838 #if defined(FEAT_QUICKFIX)
3839 if (do_sp)
3841 # ifdef WIN3264
3842 p_sp = (char_u *)">%s 2>&1";
3843 # else
3844 p_sp = (char_u *)"2>&1| tee";
3845 # endif
3846 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3848 #endif
3849 if (do_srr)
3851 p_srr = (char_u *)">%s 2>&1";
3852 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3855 vim_free(p);
3857 #endif
3859 #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3861 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3862 * This is done after other initializations, where 'shell' might have been
3863 * set, but only if they have not been set before. Default for p_shcf is
3864 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3865 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3866 * command.com. And for Win32 we need to set p_sxq instead.
3868 if (strstr((char *)gettail(p_sh), "sh") != NULL)
3870 int idx3;
3872 idx3 = findoption((char_u *)"shcf");
3873 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3875 p_shcf = (char_u *)"-c";
3876 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3879 # ifndef DJGPP
3880 # ifdef WIN3264
3881 /* Somehow Win32 requires the quotes around the redirection too */
3882 idx3 = findoption((char_u *)"sxq");
3883 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3885 p_sxq = (char_u *)"\"";
3886 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3888 # else
3889 idx3 = findoption((char_u *)"shq");
3890 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3892 p_shq = (char_u *)"\"";
3893 options[idx3].def_val[VI_DEFAULT] = p_shq;
3895 # endif
3896 # endif
3898 #endif
3900 #ifdef FEAT_TITLE
3901 set_title_defaults();
3902 #endif
3905 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
3907 * When 'helplang' is still at its default value, set it to "lang".
3908 * Only the first two characters of "lang" are used.
3910 void
3911 set_helplang_default(lang)
3912 char_u *lang;
3914 int idx;
3916 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3917 return;
3918 idx = findoption((char_u *)"hlg");
3919 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3921 if (options[idx].flags & P_ALLOCED)
3922 free_string_option(p_hlg);
3923 p_hlg = vim_strsave(lang);
3924 if (p_hlg == NULL)
3925 p_hlg = empty_option;
3926 else
3928 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3929 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3931 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3932 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3934 p_hlg[2] = NUL;
3936 options[idx].flags |= P_ALLOCED;
3939 #endif
3941 #ifdef FEAT_GUI
3942 static char_u *gui_bg_default __ARGS((void));
3944 static char_u *
3945 gui_bg_default()
3947 if (gui_get_lightness(gui.back_pixel) < 127)
3948 return (char_u *)"dark";
3949 return (char_u *)"light";
3953 * Option initializations that can only be done after opening the GUI window.
3955 void
3956 init_gui_options()
3958 /* Set the 'background' option according to the lightness of the
3959 * background color, unless the user has set it already. */
3960 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3962 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3963 highlight_changed();
3966 #endif
3968 #ifdef FEAT_TITLE
3970 * 'title' and 'icon' only default to true if they have not been set or reset
3971 * in .vimrc and we can read the old value.
3972 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3973 * they can be reset. This reduces startup time when using X on a remote
3974 * machine.
3976 void
3977 set_title_defaults()
3979 int idx1;
3980 long val;
3983 * If GUI is (going to be) used, we can always set the window title and
3984 * icon name. Saves a bit of time, because the X11 display server does
3985 * not need to be contacted.
3987 idx1 = findoption((char_u *)"title");
3988 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
3990 #ifdef FEAT_GUI
3991 if (gui.starting || gui.in_use)
3992 val = TRUE;
3993 else
3994 #endif
3995 val = mch_can_restore_title();
3996 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3997 p_title = val;
3999 idx1 = findoption((char_u *)"icon");
4000 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4002 #ifdef FEAT_GUI
4003 if (gui.starting || gui.in_use)
4004 val = TRUE;
4005 else
4006 #endif
4007 val = mch_can_restore_icon();
4008 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4009 p_icon = val;
4012 #endif
4015 * Parse 'arg' for option settings.
4017 * 'arg' may be IObuff, but only when no errors can be present and option
4018 * does not need to be expanded with option_expand().
4019 * "opt_flags":
4020 * 0 for ":set"
4021 * OPT_GLOBAL for ":setglobal"
4022 * OPT_LOCAL for ":setlocal" and a modeline
4023 * OPT_MODELINE for a modeline
4024 * OPT_WINONLY to only set window-local options
4025 * OPT_NOWIN to skip setting window-local options
4027 * returns FAIL if an error is detected, OK otherwise
4030 do_set(arg, opt_flags)
4031 char_u *arg; /* option string (may be written to!) */
4032 int opt_flags;
4034 int opt_idx;
4035 char_u *errmsg;
4036 char_u errbuf[80];
4037 char_u *startarg;
4038 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4039 int nextchar; /* next non-white char after option name */
4040 int afterchar; /* character just after option name */
4041 int len;
4042 int i;
4043 long value;
4044 int key;
4045 long_u flags; /* flags for current option */
4046 char_u *varp = NULL; /* pointer to variable for current option */
4047 int did_show = FALSE; /* already showed one value */
4048 int adding; /* "opt+=arg" */
4049 int prepending; /* "opt^=arg" */
4050 int removing; /* "opt-=arg" */
4051 int cp_val = 0;
4052 char_u key_name[2];
4054 if (*arg == NUL)
4056 showoptions(0, opt_flags);
4057 did_show = TRUE;
4058 goto theend;
4061 while (*arg != NUL) /* loop to process all options */
4063 errmsg = NULL;
4064 startarg = arg; /* remember for error message */
4066 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4067 && !(opt_flags & OPT_MODELINE))
4070 * ":set all" show all options.
4071 * ":set all&" set all options to their default value.
4073 arg += 3;
4074 if (*arg == '&')
4076 ++arg;
4077 /* Only for :set command set global value of local options. */
4078 set_options_default(OPT_FREE | opt_flags);
4080 else
4082 showoptions(1, opt_flags);
4083 did_show = TRUE;
4086 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
4088 showoptions(2, opt_flags);
4089 show_termcodes();
4090 did_show = TRUE;
4091 arg += 7;
4093 else
4095 prefix = 1;
4096 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
4098 prefix = 0;
4099 arg += 2;
4101 else if (STRNCMP(arg, "inv", 3) == 0)
4103 prefix = 2;
4104 arg += 3;
4107 /* find end of name */
4108 key = 0;
4109 if (*arg == '<')
4111 nextchar = 0;
4112 opt_idx = -1;
4113 /* look out for <t_>;> */
4114 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4115 len = 5;
4116 else
4118 len = 1;
4119 while (arg[len] != NUL && arg[len] != '>')
4120 ++len;
4122 if (arg[len] != '>')
4124 errmsg = e_invarg;
4125 goto skip;
4127 arg[len] = NUL; /* put NUL after name */
4128 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4129 opt_idx = findoption(arg + 1);
4130 arg[len++] = '>'; /* restore '>' */
4131 if (opt_idx == -1)
4132 key = find_key_option(arg + 1);
4134 else
4136 len = 0;
4138 * The two characters after "t_" may not be alphanumeric.
4140 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4141 len = 4;
4142 else
4143 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4144 ++len;
4145 nextchar = arg[len];
4146 arg[len] = NUL; /* put NUL after name */
4147 opt_idx = findoption(arg);
4148 arg[len] = nextchar; /* restore nextchar */
4149 if (opt_idx == -1)
4150 key = find_key_option(arg);
4153 /* remember character after option name */
4154 afterchar = arg[len];
4156 /* skip white space, allow ":set ai ?" */
4157 while (vim_iswhite(arg[len]))
4158 ++len;
4160 adding = FALSE;
4161 prepending = FALSE;
4162 removing = FALSE;
4163 if (arg[len] != NUL && arg[len + 1] == '=')
4165 if (arg[len] == '+')
4167 adding = TRUE; /* "+=" */
4168 ++len;
4170 else if (arg[len] == '^')
4172 prepending = TRUE; /* "^=" */
4173 ++len;
4175 else if (arg[len] == '-')
4177 removing = TRUE; /* "-=" */
4178 ++len;
4181 nextchar = arg[len];
4183 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4185 errmsg = (char_u *)N_("E518: Unknown option");
4186 goto skip;
4189 if (opt_idx >= 0)
4191 if (options[opt_idx].var == NULL) /* hidden option: skip */
4193 /* Only give an error message when requesting the value of
4194 * a hidden option, ignore setting it. */
4195 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4196 && (!(options[opt_idx].flags & P_BOOL)
4197 || nextchar == '?'))
4198 errmsg = (char_u *)N_("E519: Option not supported");
4199 goto skip;
4202 flags = options[opt_idx].flags;
4203 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4205 else
4207 flags = P_STRING;
4208 if (key < 0)
4210 key_name[0] = KEY2TERMCAP0(key);
4211 key_name[1] = KEY2TERMCAP1(key);
4213 else
4215 key_name[0] = KS_KEY;
4216 key_name[1] = (key & 0xff);
4220 /* Skip all options that are not window-local (used when showing
4221 * an already loaded buffer in a window). */
4222 if ((opt_flags & OPT_WINONLY)
4223 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4224 goto skip;
4226 /* Skip all options that are window-local (used for :vimgrep). */
4227 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4228 && options[opt_idx].var == VAR_WIN)
4229 goto skip;
4231 /* Disallow changing some options from modelines. */
4232 if (opt_flags & OPT_MODELINE)
4234 if (flags & P_SECURE)
4236 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4237 goto skip;
4239 #ifdef FEAT_DIFF
4240 /* In diff mode some options are overruled. This avoids that
4241 * 'foldmethod' becomes "marker" instead of "diff" and that
4242 * "wrap" gets set. */
4243 if (curwin->w_p_diff
4244 && (options[opt_idx].indir == PV_FDM
4245 || options[opt_idx].indir == PV_WRAP))
4246 goto skip;
4247 #endif
4250 #ifdef HAVE_SANDBOX
4251 /* Disallow changing some options in the sandbox */
4252 if (sandbox != 0 && (flags & P_SECURE))
4254 errmsg = (char_u *)_(e_sandbox);
4255 goto skip;
4257 #endif
4259 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4261 arg += len;
4262 cp_val = p_cp;
4263 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4265 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4267 cp_val = FALSE;
4268 arg += 3;
4270 else /* "opt&vi": set to Vi default */
4272 cp_val = TRUE;
4273 arg += 2;
4276 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4277 && arg[1] != NUL && !vim_iswhite(arg[1]))
4279 errmsg = e_trailing;
4280 goto skip;
4285 * allow '=' and ':' as MSDOS command.com allows only one
4286 * '=' character per "set" command line. grrr. (jw)
4288 if (nextchar == '?'
4289 || (prefix == 1
4290 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4291 && !(flags & P_BOOL)))
4294 * print value
4296 if (did_show)
4297 msg_putchar('\n'); /* cursor below last one */
4298 else
4300 gotocmdline(TRUE); /* cursor at status line */
4301 did_show = TRUE; /* remember that we did a line */
4303 if (opt_idx >= 0)
4305 showoneopt(&options[opt_idx], opt_flags);
4306 #ifdef FEAT_EVAL
4307 if (p_verbose > 0)
4309 /* Mention where the option was last set. */
4310 if (varp == options[opt_idx].var)
4311 last_set_msg(options[opt_idx].scriptID);
4312 else if ((int)options[opt_idx].indir & PV_WIN)
4313 last_set_msg(curwin->w_p_scriptID[
4314 (int)options[opt_idx].indir & PV_MASK]);
4315 else if ((int)options[opt_idx].indir & PV_BUF)
4316 last_set_msg(curbuf->b_p_scriptID[
4317 (int)options[opt_idx].indir & PV_MASK]);
4319 #endif
4321 else
4323 char_u *p;
4325 p = find_termcode(key_name);
4326 if (p == NULL)
4328 errmsg = (char_u *)N_("E518: Unknown option");
4329 goto skip;
4331 else
4332 (void)show_one_termcode(key_name, p, TRUE);
4334 if (nextchar != '?'
4335 && nextchar != NUL && !vim_iswhite(afterchar))
4336 errmsg = e_trailing;
4338 else
4340 if (flags & P_BOOL) /* boolean */
4342 if (nextchar == '=' || nextchar == ':')
4344 errmsg = e_invarg;
4345 goto skip;
4349 * ":set opt!": invert
4350 * ":set opt&": reset to default value
4351 * ":set opt<": reset to global value
4353 if (nextchar == '!')
4354 value = *(int *)(varp) ^ 1;
4355 else if (nextchar == '&')
4356 value = (int)(long)(long_i)options[opt_idx].def_val[
4357 ((flags & P_VI_DEF) || cp_val)
4358 ? VI_DEFAULT : VIM_DEFAULT];
4359 else if (nextchar == '<')
4361 /* For 'autoread' -1 means to use global value. */
4362 if ((int *)varp == &curbuf->b_p_ar
4363 && opt_flags == OPT_LOCAL)
4364 value = -1;
4365 else
4366 value = *(int *)get_varp_scope(&(options[opt_idx]),
4367 OPT_GLOBAL);
4369 else
4372 * ":set invopt": invert
4373 * ":set opt" or ":set noopt": set or reset
4375 if (nextchar != NUL && !vim_iswhite(afterchar))
4377 errmsg = e_trailing;
4378 goto skip;
4380 if (prefix == 2) /* inv */
4381 value = *(int *)(varp) ^ 1;
4382 else
4383 value = prefix;
4386 errmsg = set_bool_option(opt_idx, varp, (int)value,
4387 opt_flags);
4389 else /* numeric or string */
4391 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4392 || prefix != 1)
4394 errmsg = e_invarg;
4395 goto skip;
4398 if (flags & P_NUM) /* numeric */
4401 * Different ways to set a number option:
4402 * & set to default value
4403 * < set to global value
4404 * <xx> accept special key codes for 'wildchar'
4405 * c accept any non-digit for 'wildchar'
4406 * [-]0-9 set number
4407 * other error
4409 ++arg;
4410 if (nextchar == '&')
4411 value = (long)(long_i)options[opt_idx].def_val[
4412 ((flags & P_VI_DEF) || cp_val)
4413 ? VI_DEFAULT : VIM_DEFAULT];
4414 else if (nextchar == '<')
4415 value = *(long *)get_varp_scope(&(options[opt_idx]),
4416 OPT_GLOBAL);
4417 else if (((long *)varp == &p_wc
4418 || (long *)varp == &p_wcm)
4419 && (*arg == '<'
4420 || *arg == '^'
4421 || ((!arg[1] || vim_iswhite(arg[1]))
4422 && !VIM_ISDIGIT(*arg))))
4424 value = string_to_key(arg);
4425 if (value == 0 && (long *)varp != &p_wcm)
4427 errmsg = e_invarg;
4428 goto skip;
4431 /* allow negative numbers (for 'undolevels') */
4432 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4434 i = 0;
4435 if (*arg == '-')
4436 i = 1;
4437 #ifdef HAVE_STRTOL
4438 value = strtol((char *)arg, NULL, 0);
4439 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4440 i += 2;
4441 #else
4442 value = atol((char *)arg);
4443 #endif
4444 while (VIM_ISDIGIT(arg[i]))
4445 ++i;
4446 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4448 errmsg = e_invarg;
4449 goto skip;
4452 else
4454 errmsg = (char_u *)N_("E521: Number required after =");
4455 goto skip;
4458 if (adding)
4459 value = *(long *)varp + value;
4460 if (prepending)
4461 value = *(long *)varp * value;
4462 if (removing)
4463 value = *(long *)varp - value;
4464 errmsg = set_num_option(opt_idx, varp, value,
4465 errbuf, sizeof(errbuf), opt_flags);
4467 else if (opt_idx >= 0) /* string */
4469 char_u *save_arg = NULL;
4470 char_u *s = NULL;
4471 char_u *oldval; /* previous value if *varp */
4472 char_u *newval;
4473 char_u *origval;
4474 unsigned newlen;
4475 int comma;
4476 int bs;
4477 int new_value_alloced; /* new string option
4478 was allocated */
4480 /* When using ":set opt=val" for a global option
4481 * with a local value the local value will be
4482 * reset, use the global value here. */
4483 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4484 && ((int)options[opt_idx].indir & PV_BOTH))
4485 varp = options[opt_idx].var;
4487 /* The old value is kept until we are sure that the
4488 * new value is valid. */
4489 oldval = *(char_u **)varp;
4490 if (nextchar == '&') /* set to default val */
4492 newval = options[opt_idx].def_val[
4493 ((flags & P_VI_DEF) || cp_val)
4494 ? VI_DEFAULT : VIM_DEFAULT];
4495 if ((char_u **)varp == &p_bg)
4497 /* guess the value of 'background' */
4498 #ifdef FEAT_GUI
4499 if (gui.in_use)
4500 newval = gui_bg_default();
4501 else
4502 #endif
4503 newval = term_bg_default();
4506 /* expand environment variables and ~ (since the
4507 * default value was already expanded, only
4508 * required when an environment variable was set
4509 * later */
4510 if (newval == NULL)
4511 newval = empty_option;
4512 else
4514 s = option_expand(opt_idx, newval);
4515 if (s == NULL)
4516 s = newval;
4517 newval = vim_strsave(s);
4519 new_value_alloced = TRUE;
4521 else if (nextchar == '<') /* set to global val */
4523 newval = vim_strsave(*(char_u **)get_varp_scope(
4524 &(options[opt_idx]), OPT_GLOBAL));
4525 new_value_alloced = TRUE;
4527 else
4529 ++arg; /* jump to after the '=' or ':' */
4532 * Set 'keywordprg' to ":help" if an empty
4533 * value was passed to :set by the user.
4534 * Misuse errbuf[] for the resulting string.
4536 if (varp == (char_u *)&p_kp
4537 && (*arg == NUL || *arg == ' '))
4539 STRCPY(errbuf, ":help");
4540 save_arg = arg;
4541 arg = errbuf;
4544 * Convert 'whichwrap' number to string, for
4545 * backwards compatibility with Vim 3.0.
4546 * Misuse errbuf[] for the resulting string.
4548 else if (varp == (char_u *)&p_ww
4549 && VIM_ISDIGIT(*arg))
4551 *errbuf = NUL;
4552 i = getdigits(&arg);
4553 if (i & 1)
4554 STRCAT(errbuf, "b,");
4555 if (i & 2)
4556 STRCAT(errbuf, "s,");
4557 if (i & 4)
4558 STRCAT(errbuf, "h,l,");
4559 if (i & 8)
4560 STRCAT(errbuf, "<,>,");
4561 if (i & 16)
4562 STRCAT(errbuf, "[,],");
4563 if (*errbuf != NUL) /* remove trailing , */
4564 errbuf[STRLEN(errbuf) - 1] = NUL;
4565 save_arg = arg;
4566 arg = errbuf;
4569 * Remove '>' before 'dir' and 'bdir', for
4570 * backwards compatibility with version 3.0
4572 else if ( *arg == '>'
4573 && (varp == (char_u *)&p_dir
4574 || varp == (char_u *)&p_bdir))
4576 ++arg;
4579 /* When setting the local value of a global
4580 * option, the old value may be the global value. */
4581 if (((int)options[opt_idx].indir & PV_BOTH)
4582 && (opt_flags & OPT_LOCAL))
4583 origval = *(char_u **)get_varp(
4584 &options[opt_idx]);
4585 else
4586 origval = oldval;
4589 * Copy the new string into allocated memory.
4590 * Can't use set_string_option_direct(), because
4591 * we need to remove the backslashes.
4593 /* get a bit too much */
4594 newlen = (unsigned)STRLEN(arg) + 1;
4595 if (adding || prepending || removing)
4596 newlen += (unsigned)STRLEN(origval) + 1;
4597 newval = alloc(newlen);
4598 if (newval == NULL) /* out of mem, don't change */
4599 break;
4600 s = newval;
4603 * Copy the string, skip over escaped chars.
4604 * For MS-DOS and WIN32 backslashes before normal
4605 * file name characters are not removed, and keep
4606 * backslash at start, for "\\machine\path", but
4607 * do remove it for "\\\\machine\\path".
4608 * The reverse is found in ExpandOldSetting().
4610 while (*arg && !vim_iswhite(*arg))
4612 if (*arg == '\\' && arg[1] != NUL
4613 #ifdef BACKSLASH_IN_FILENAME
4614 && !((flags & P_EXPAND)
4615 && vim_isfilec(arg[1])
4616 && (arg[1] != '\\'
4617 || (s == newval
4618 && arg[2] != '\\')))
4619 #endif
4621 ++arg; /* remove backslash */
4622 #ifdef FEAT_MBYTE
4623 if (has_mbyte
4624 && (i = (*mb_ptr2len)(arg)) > 1)
4626 /* copy multibyte char */
4627 mch_memmove(s, arg, (size_t)i);
4628 arg += i;
4629 s += i;
4631 else
4632 #endif
4633 *s++ = *arg++;
4635 *s = NUL;
4638 * Expand environment variables and ~.
4639 * Don't do it when adding without inserting a
4640 * comma.
4642 if (!(adding || prepending || removing)
4643 || (flags & P_COMMA))
4645 s = option_expand(opt_idx, newval);
4646 if (s != NULL)
4648 vim_free(newval);
4649 newlen = (unsigned)STRLEN(s) + 1;
4650 if (adding || prepending || removing)
4651 newlen += (unsigned)STRLEN(origval) + 1;
4652 newval = alloc(newlen);
4653 if (newval == NULL)
4654 break;
4655 STRCPY(newval, s);
4659 /* locate newval[] in origval[] when removing it
4660 * and when adding to avoid duplicates */
4661 i = 0; /* init for GCC */
4662 if (removing || (flags & P_NODUP))
4664 i = (int)STRLEN(newval);
4665 bs = 0;
4666 for (s = origval; *s; ++s)
4668 if ((!(flags & P_COMMA)
4669 || s == origval
4670 || (s[-1] == ',' && !(bs & 1)))
4671 && STRNCMP(s, newval, i) == 0
4672 && (!(flags & P_COMMA)
4673 || s[i] == ','
4674 || s[i] == NUL))
4675 break;
4676 /* Count backspaces. Only a comma with an
4677 * even number of backspaces before it is
4678 * recognized as a separator */
4679 if (s > origval && s[-1] == '\\')
4680 ++bs;
4681 else
4682 bs = 0;
4685 /* do not add if already there */
4686 if ((adding || prepending) && *s)
4688 prepending = FALSE;
4689 adding = FALSE;
4690 STRCPY(newval, origval);
4694 /* concatenate the two strings; add a ',' if
4695 * needed */
4696 if (adding || prepending)
4698 comma = ((flags & P_COMMA) && *origval != NUL
4699 && *newval != NUL);
4700 if (adding)
4702 i = (int)STRLEN(origval);
4703 mch_memmove(newval + i + comma, newval,
4704 STRLEN(newval) + 1);
4705 mch_memmove(newval, origval, (size_t)i);
4707 else
4709 i = (int)STRLEN(newval);
4710 STRMOVE(newval + i + comma, origval);
4712 if (comma)
4713 newval[i] = ',';
4716 /* Remove newval[] from origval[]. (Note: "i" has
4717 * been set above and is used here). */
4718 if (removing)
4720 STRCPY(newval, origval);
4721 if (*s)
4723 /* may need to remove a comma */
4724 if (flags & P_COMMA)
4726 if (s == origval)
4728 /* include comma after string */
4729 if (s[i] == ',')
4730 ++i;
4732 else
4734 /* include comma before string */
4735 --s;
4736 ++i;
4739 STRMOVE(newval + (s - origval), s + i);
4743 if (flags & P_FLAGLIST)
4745 /* Remove flags that appear twice. */
4746 for (s = newval; *s; ++s)
4747 if ((!(flags & P_COMMA) || *s != ',')
4748 && vim_strchr(s + 1, *s) != NULL)
4750 STRMOVE(s, s + 1);
4751 --s;
4755 if (save_arg != NULL) /* number for 'whichwrap' */
4756 arg = save_arg;
4757 new_value_alloced = TRUE;
4760 /* Set the new value. */
4761 *(char_u **)(varp) = newval;
4763 /* Handle side effects, and set the global value for
4764 * ":set" on local options. */
4765 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4766 new_value_alloced, oldval, errbuf, opt_flags);
4768 /* If error detected, print the error message. */
4769 if (errmsg != NULL)
4770 goto skip;
4772 else /* key code option */
4774 char_u *p;
4776 if (nextchar == '&')
4778 if (add_termcap_entry(key_name, TRUE) == FAIL)
4779 errmsg = (char_u *)N_("E522: Not found in termcap");
4781 else
4783 ++arg; /* jump to after the '=' or ':' */
4784 for (p = arg; *p && !vim_iswhite(*p); ++p)
4785 if (*p == '\\' && p[1] != NUL)
4786 ++p;
4787 nextchar = *p;
4788 *p = NUL;
4789 add_termcode(key_name, arg, FALSE);
4790 *p = nextchar;
4792 if (full_screen)
4793 ttest(FALSE);
4794 redraw_all_later(CLEAR);
4798 if (opt_idx >= 0)
4799 did_set_option(opt_idx, opt_flags,
4800 !prepending && !adding && !removing);
4803 skip:
4805 * Advance to next argument.
4806 * - skip until a blank found, taking care of backslashes
4807 * - skip blanks
4808 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4810 for (i = 0; i < 2 ; ++i)
4812 while (*arg != NUL && !vim_iswhite(*arg))
4813 if (*arg++ == '\\' && *arg != NUL)
4814 ++arg;
4815 arg = skipwhite(arg);
4816 if (*arg != '=')
4817 break;
4821 if (errmsg != NULL)
4823 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
4824 i = (int)STRLEN(IObuff) + 2;
4825 if (i + (arg - startarg) < IOSIZE)
4827 /* append the argument with the error */
4828 STRCAT(IObuff, ": ");
4829 mch_memmove(IObuff + i, startarg, (arg - startarg));
4830 IObuff[i + (arg - startarg)] = NUL;
4832 /* make sure all characters are printable */
4833 trans_characters(IObuff, IOSIZE);
4835 ++no_wait_return; /* wait_return done later */
4836 emsg(IObuff); /* show error highlighted */
4837 --no_wait_return;
4839 return FAIL;
4842 arg = skipwhite(arg);
4845 theend:
4846 if (silent_mode && did_show)
4848 /* After displaying option values in silent mode. */
4849 silent_mode = FALSE;
4850 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4851 msg_putchar('\n');
4852 cursor_on(); /* msg_start() switches it off */
4853 out_flush();
4854 silent_mode = TRUE;
4855 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4858 return OK;
4862 * Call this when an option has been given a new value through a user command.
4863 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4865 static void
4866 did_set_option(opt_idx, opt_flags, new_value)
4867 int opt_idx;
4868 int opt_flags; /* possibly with OPT_MODELINE */
4869 int new_value; /* value was replaced completely */
4871 long_u *p;
4873 options[opt_idx].flags |= P_WAS_SET;
4875 /* When an option is set in the sandbox, from a modeline or in secure mode
4876 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
4877 * flag. */
4878 p = insecure_flag(opt_idx, opt_flags);
4879 if (secure
4880 #ifdef HAVE_SANDBOX
4881 || sandbox != 0
4882 #endif
4883 || (opt_flags & OPT_MODELINE))
4884 *p = *p | P_INSECURE;
4885 else if (new_value)
4886 *p = *p & ~P_INSECURE;
4889 static char_u *
4890 illegal_char(errbuf, c)
4891 char_u *errbuf;
4892 int c;
4894 if (errbuf == NULL)
4895 return (char_u *)"";
4896 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
4897 (char *)transchar(c));
4898 return errbuf;
4902 * Convert a key name or string into a key value.
4903 * Used for 'wildchar' and 'cedit' options.
4905 static int
4906 string_to_key(arg)
4907 char_u *arg;
4909 if (*arg == '<')
4910 return find_key_option(arg + 1);
4911 if (*arg == '^')
4912 return Ctrl_chr(arg[1]);
4913 return *arg;
4916 #ifdef FEAT_CMDWIN
4918 * Check value of 'cedit' and set cedit_key.
4919 * Returns NULL if value is OK, error message otherwise.
4921 static char_u *
4922 check_cedit()
4924 int n;
4926 if (*p_cedit == NUL)
4927 cedit_key = -1;
4928 else
4930 n = string_to_key(p_cedit);
4931 if (vim_isprintc(n))
4932 return e_invarg;
4933 cedit_key = n;
4935 return NULL;
4937 #endif
4939 #ifdef FEAT_TITLE
4941 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4942 * maketitle() to create and display it.
4943 * When switching the title or icon off, call mch_restore_title() to get
4944 * the old value back.
4946 static void
4947 did_set_title(icon)
4948 int icon; /* Did set icon instead of title */
4950 if (starting != NO_SCREEN
4951 #ifdef FEAT_GUI
4952 && !gui.starting
4953 #endif
4956 maketitle();
4957 if (icon)
4959 if (!p_icon)
4960 mch_restore_title(2);
4962 else
4964 if (!p_title)
4965 mch_restore_title(1);
4969 #endif
4972 * set_options_bin - called when 'bin' changes value.
4974 void
4975 set_options_bin(oldval, newval, opt_flags)
4976 int oldval;
4977 int newval;
4978 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4981 * The option values that are changed when 'bin' changes are
4982 * copied when 'bin is set and restored when 'bin' is reset.
4984 if (newval)
4986 if (!oldval) /* switched on */
4988 if (!(opt_flags & OPT_GLOBAL))
4990 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4991 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4992 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4993 curbuf->b_p_et_nobin = curbuf->b_p_et;
4995 if (!(opt_flags & OPT_LOCAL))
4997 p_tw_nobin = p_tw;
4998 p_wm_nobin = p_wm;
4999 p_ml_nobin = p_ml;
5000 p_et_nobin = p_et;
5004 if (!(opt_flags & OPT_GLOBAL))
5006 curbuf->b_p_tw = 0; /* no automatic line wrap */
5007 curbuf->b_p_wm = 0; /* no automatic line wrap */
5008 curbuf->b_p_ml = 0; /* no modelines */
5009 curbuf->b_p_et = 0; /* no expandtab */
5011 if (!(opt_flags & OPT_LOCAL))
5013 p_tw = 0;
5014 p_wm = 0;
5015 p_ml = FALSE;
5016 p_et = FALSE;
5017 p_bin = TRUE; /* needed when called for the "-b" argument */
5020 else if (oldval) /* switched off */
5022 if (!(opt_flags & OPT_GLOBAL))
5024 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5025 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5026 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5027 curbuf->b_p_et = curbuf->b_p_et_nobin;
5029 if (!(opt_flags & OPT_LOCAL))
5031 p_tw = p_tw_nobin;
5032 p_wm = p_wm_nobin;
5033 p_ml = p_ml_nobin;
5034 p_et = p_et_nobin;
5039 #ifdef FEAT_VIMINFO
5041 * Find the parameter represented by the given character (eg ', :, ", or /),
5042 * and return its associated value in the 'viminfo' string.
5043 * Only works for number parameters, not for 'r' or 'n'.
5044 * If the parameter is not specified in the string or there is no following
5045 * number, return -1.
5048 get_viminfo_parameter(type)
5049 int type;
5051 char_u *p;
5053 p = find_viminfo_parameter(type);
5054 if (p != NULL && VIM_ISDIGIT(*p))
5055 return atoi((char *)p);
5056 return -1;
5060 * Find the parameter represented by the given character (eg ''', ':', '"', or
5061 * '/') in the 'viminfo' option and return a pointer to the string after it.
5062 * Return NULL if the parameter is not specified in the string.
5064 char_u *
5065 find_viminfo_parameter(type)
5066 int type;
5068 char_u *p;
5070 for (p = p_viminfo; *p; ++p)
5072 if (*p == type)
5073 return p + 1;
5074 if (*p == 'n') /* 'n' is always the last one */
5075 break;
5076 p = vim_strchr(p, ','); /* skip until next ',' */
5077 if (p == NULL) /* hit the end without finding parameter */
5078 break;
5080 return NULL;
5082 #endif
5085 * Expand environment variables for some string options.
5086 * These string options cannot be indirect!
5087 * If "val" is NULL expand the current value of the option.
5088 * Return pointer to NameBuff, or NULL when not expanded.
5090 static char_u *
5091 option_expand(opt_idx, val)
5092 int opt_idx;
5093 char_u *val;
5095 /* if option doesn't need expansion nothing to do */
5096 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5097 return NULL;
5099 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5100 * expand_env() would truncate the string. */
5101 if (val != NULL && STRLEN(val) > MAXPATHL)
5102 return NULL;
5104 if (val == NULL)
5105 val = *(char_u **)options[opt_idx].var;
5108 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5109 * Escape spaces when expanding 'tags', they are used to separate file
5110 * names.
5111 * For 'spellsuggest' expand after "file:".
5113 expand_env_esc(val, NameBuff, MAXPATHL,
5114 (char_u **)options[opt_idx].var == &p_tags, FALSE,
5115 #ifdef FEAT_SPELL
5116 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5117 #endif
5118 NULL);
5119 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5120 return NULL;
5122 return NameBuff;
5126 * After setting various option values: recompute variables that depend on
5127 * option values.
5129 static void
5130 didset_options()
5132 /* initialize the table for 'iskeyword' et.al. */
5133 (void)init_chartab();
5135 #ifdef FEAT_MBYTE
5136 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5137 #endif
5138 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5139 #ifdef FEAT_SESSION
5140 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5141 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5142 #endif
5143 #ifdef FEAT_FOLDING
5144 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5145 #endif
5146 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5147 #ifdef FEAT_VIRTUALEDIT
5148 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5149 #endif
5150 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5151 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5152 #endif
5153 #ifdef FEAT_SPELL
5154 (void)spell_check_msm();
5155 (void)spell_check_sps();
5156 (void)compile_cap_prog(curbuf);
5157 #endif
5158 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5159 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5160 #endif
5161 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5162 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5163 #endif
5164 #ifdef FEAT_CMDWIN
5165 /* set cedit_key */
5166 (void)check_cedit();
5167 #endif
5168 #ifdef FEAT_VARTABS
5169 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_ary);
5170 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_ary);
5171 #endif
5175 * Check for string options that are NULL (normally only termcap options).
5177 void
5178 check_options()
5180 int opt_idx;
5182 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5183 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5184 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5188 * Check string options in a buffer for NULL value.
5190 void
5191 check_buf_options(buf)
5192 buf_T *buf;
5194 #if defined(FEAT_QUICKFIX)
5195 check_string_option(&buf->b_p_bh);
5196 check_string_option(&buf->b_p_bt);
5197 #endif
5198 #ifdef FEAT_MBYTE
5199 check_string_option(&buf->b_p_fenc);
5200 #endif
5201 check_string_option(&buf->b_p_ff);
5202 #ifdef FEAT_FIND_ID
5203 check_string_option(&buf->b_p_def);
5204 check_string_option(&buf->b_p_inc);
5205 # ifdef FEAT_EVAL
5206 check_string_option(&buf->b_p_inex);
5207 # endif
5208 #endif
5209 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5210 check_string_option(&buf->b_p_inde);
5211 check_string_option(&buf->b_p_indk);
5212 #endif
5213 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5214 check_string_option(&buf->b_p_bexpr);
5215 #endif
5216 #if defined(FEAT_EVAL)
5217 check_string_option(&buf->b_p_fex);
5218 #endif
5219 #ifdef FEAT_CRYPT
5220 check_string_option(&buf->b_p_key);
5221 #endif
5222 check_string_option(&buf->b_p_kp);
5223 check_string_option(&buf->b_p_mps);
5224 check_string_option(&buf->b_p_fo);
5225 check_string_option(&buf->b_p_flp);
5226 check_string_option(&buf->b_p_isk);
5227 #ifdef FEAT_COMMENTS
5228 check_string_option(&buf->b_p_com);
5229 #endif
5230 #ifdef FEAT_FOLDING
5231 check_string_option(&buf->b_p_cms);
5232 #endif
5233 check_string_option(&buf->b_p_nf);
5234 #ifdef FEAT_TEXTOBJ
5235 check_string_option(&buf->b_p_qe);
5236 #endif
5237 #ifdef FEAT_SYN_HL
5238 check_string_option(&buf->b_p_syn);
5239 #endif
5240 #ifdef FEAT_SPELL
5241 check_string_option(&buf->b_p_spc);
5242 check_string_option(&buf->b_p_spf);
5243 check_string_option(&buf->b_p_spl);
5244 #endif
5245 #ifdef FEAT_SEARCHPATH
5246 check_string_option(&buf->b_p_sua);
5247 #endif
5248 #ifdef FEAT_CINDENT
5249 check_string_option(&buf->b_p_cink);
5250 check_string_option(&buf->b_p_cino);
5251 #endif
5252 #ifdef FEAT_AUTOCMD
5253 check_string_option(&buf->b_p_ft);
5254 #endif
5255 #ifdef FEAT_OSFILETYPE
5256 check_string_option(&buf->b_p_oft);
5257 #endif
5258 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5259 check_string_option(&buf->b_p_cinw);
5260 #endif
5261 #ifdef FEAT_INS_EXPAND
5262 check_string_option(&buf->b_p_cpt);
5263 #endif
5264 #ifdef FEAT_COMPL_FUNC
5265 check_string_option(&buf->b_p_cfu);
5266 check_string_option(&buf->b_p_ofu);
5267 #endif
5268 #ifdef FEAT_KEYMAP
5269 check_string_option(&buf->b_p_keymap);
5270 #endif
5271 #ifdef FEAT_QUICKFIX
5272 check_string_option(&buf->b_p_gp);
5273 check_string_option(&buf->b_p_mp);
5274 check_string_option(&buf->b_p_efm);
5275 #endif
5276 check_string_option(&buf->b_p_ep);
5277 check_string_option(&buf->b_p_path);
5278 check_string_option(&buf->b_p_tags);
5279 #ifdef FEAT_INS_EXPAND
5280 check_string_option(&buf->b_p_dict);
5281 check_string_option(&buf->b_p_tsr);
5282 #endif
5283 #ifdef FEAT_VARTABS
5284 check_string_option(&buf->b_p_vsts);
5285 check_string_option(&buf->b_p_vts);
5286 #endif
5290 * Free the string allocated for an option.
5291 * Checks for the string being empty_option. This may happen if we're out of
5292 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5293 * check_options().
5294 * Does NOT check for P_ALLOCED flag!
5296 void
5297 free_string_option(p)
5298 char_u *p;
5300 if (p != empty_option)
5301 vim_free(p);
5304 void
5305 clear_string_option(pp)
5306 char_u **pp;
5308 if (*pp != empty_option)
5309 vim_free(*pp);
5310 *pp = empty_option;
5313 static void
5314 check_string_option(pp)
5315 char_u **pp;
5317 if (*pp == NULL)
5318 *pp = empty_option;
5322 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5324 void
5325 set_term_option_alloced(p)
5326 char_u **p;
5328 int opt_idx;
5330 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5331 if (options[opt_idx].var == (char_u *)p)
5333 options[opt_idx].flags |= P_ALLOCED;
5334 return;
5336 return; /* cannot happen: didn't find it! */
5339 #if defined(FEAT_EVAL) || defined(PROTO)
5341 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5342 * Return FALSE when it wasn't.
5343 * Return -1 for an unknown option.
5346 was_set_insecurely(opt, opt_flags)
5347 char_u *opt;
5348 int opt_flags;
5350 int idx = findoption(opt);
5351 long_u *flagp;
5353 if (idx >= 0)
5355 flagp = insecure_flag(idx, opt_flags);
5356 return (*flagp & P_INSECURE) != 0;
5358 EMSG2(_(e_intern2), "was_set_insecurely()");
5359 return -1;
5363 * Get a pointer to the flags used for the P_INSECURE flag of option
5364 * "opt_idx". For some local options a local flags field is used.
5366 static long_u *
5367 insecure_flag(opt_idx, opt_flags)
5368 int opt_idx;
5369 int opt_flags;
5371 if (opt_flags & OPT_LOCAL)
5372 switch ((int)options[opt_idx].indir)
5374 #ifdef FEAT_STL_OPT
5375 case PV_STL: return &curwin->w_p_stl_flags;
5376 #endif
5377 #ifdef FEAT_EVAL
5378 # ifdef FEAT_FOLDING
5379 case PV_FDE: return &curwin->w_p_fde_flags;
5380 case PV_FDT: return &curwin->w_p_fdt_flags;
5381 # endif
5382 # ifdef FEAT_BEVAL
5383 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5384 # endif
5385 # if defined(FEAT_CINDENT)
5386 case PV_INDE: return &curbuf->b_p_inde_flags;
5387 # endif
5388 case PV_FEX: return &curbuf->b_p_fex_flags;
5389 # ifdef FEAT_FIND_ID
5390 case PV_INEX: return &curbuf->b_p_inex_flags;
5391 # endif
5392 #endif
5395 /* Nothing special, return global flags field. */
5396 return &options[opt_idx].flags;
5398 #endif
5400 #ifdef FEAT_TITLE
5401 static void redraw_titles __ARGS((void));
5404 * Redraw the window title and/or tab page text later.
5406 static void redraw_titles()
5408 need_maketitle = TRUE;
5409 # ifdef FEAT_WINDOWS
5410 redraw_tabline = TRUE;
5411 # endif
5413 #endif
5416 * Set a string option to a new value (without checking the effect).
5417 * The string is copied into allocated memory.
5418 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
5419 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
5420 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
5422 void
5423 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
5424 char_u *name;
5425 int opt_idx;
5426 char_u *val;
5427 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5428 int set_sid UNUSED;
5430 char_u *s;
5431 char_u **varp;
5432 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5433 int idx = opt_idx;
5435 if (idx == -1) /* use name */
5437 idx = findoption(name);
5438 if (idx < 0) /* not found (should not happen) */
5440 EMSG2(_(e_intern2), "set_string_option_direct()");
5441 return;
5445 if (options[idx].var == NULL) /* can't set hidden option */
5446 return;
5448 s = vim_strsave(val);
5449 if (s != NULL)
5451 varp = (char_u **)get_varp_scope(&(options[idx]),
5452 both ? OPT_LOCAL : opt_flags);
5453 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
5454 free_string_option(*varp);
5455 *varp = s;
5457 /* For buffer/window local option may also set the global value. */
5458 if (both)
5459 set_string_option_global(idx, varp);
5461 options[idx].flags |= P_ALLOCED;
5463 /* When setting both values of a global option with a local value,
5464 * make the local value empty, so that the global value is used. */
5465 if (((int)options[idx].indir & PV_BOTH) && both)
5467 free_string_option(*varp);
5468 *varp = empty_option;
5470 # ifdef FEAT_EVAL
5471 if (set_sid != SID_NONE)
5472 set_option_scriptID_idx(idx, opt_flags,
5473 set_sid == 0 ? current_SID : set_sid);
5474 # endif
5479 * Set global value for string option when it's a local option.
5481 static void
5482 set_string_option_global(opt_idx, varp)
5483 int opt_idx; /* option index */
5484 char_u **varp; /* pointer to option variable */
5486 char_u **p, *s;
5488 /* the global value is always allocated */
5489 if (options[opt_idx].var == VAR_WIN)
5490 p = (char_u **)GLOBAL_WO(varp);
5491 else
5492 p = (char_u **)options[opt_idx].var;
5493 if (options[opt_idx].indir != PV_NONE
5494 && p != varp
5495 && (s = vim_strsave(*varp)) != NULL)
5497 free_string_option(*p);
5498 *p = s;
5503 * Set a string option to a new value, and handle the effects.
5505 static void
5506 set_string_option(opt_idx, value, opt_flags)
5507 int opt_idx;
5508 char_u *value;
5509 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5511 char_u *s;
5512 char_u **varp;
5513 char_u *oldval;
5515 if (options[opt_idx].var == NULL) /* don't set hidden option */
5516 return;
5518 s = vim_strsave(value);
5519 if (s != NULL)
5521 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5522 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5523 ? (((int)options[opt_idx].indir & PV_BOTH)
5524 ? OPT_GLOBAL : OPT_LOCAL)
5525 : opt_flags);
5526 oldval = *varp;
5527 *varp = s;
5528 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5529 opt_flags) == NULL)
5530 did_set_option(opt_idx, opt_flags, TRUE);
5535 * Handle string options that need some action to perform when changed.
5536 * Returns NULL for success, or an error message for an error.
5538 static char_u *
5539 did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5540 opt_flags)
5541 int opt_idx; /* index in options[] table */
5542 char_u **varp; /* pointer to the option variable */
5543 int new_value_alloced; /* new value was allocated */
5544 char_u *oldval; /* previous value of the option */
5545 char_u *errbuf; /* buffer for errors, or NULL */
5546 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5548 char_u *errmsg = NULL;
5549 char_u *s, *p;
5550 int did_chartab = FALSE;
5551 char_u **gvarp;
5552 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
5553 #ifdef FEAT_GUI
5554 /* set when changing an option that only requires a redraw in the GUI */
5555 int redraw_gui_only = FALSE;
5556 #endif
5558 /* Get the global option to compare with, otherwise we would have to check
5559 * two values for all local options. */
5560 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5562 /* Disallow changing some options from secure mode */
5563 if ((secure
5564 #ifdef HAVE_SANDBOX
5565 || sandbox != 0
5566 #endif
5567 ) && (options[opt_idx].flags & P_SECURE))
5569 errmsg = e_secure;
5572 /* Check for a "normal" file name in some options. Disallow a path
5573 * separator (slash and/or backslash), wildcards and characters that are
5574 * often illegal in a file name. */
5575 else if ((options[opt_idx].flags & P_NFNAME)
5576 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
5578 errmsg = e_invarg;
5581 /* 'term' */
5582 else if (varp == &T_NAME)
5584 if (T_NAME[0] == NUL)
5585 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5586 #ifdef FEAT_GUI
5587 if (gui.in_use)
5588 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5589 else if (term_is_gui(T_NAME))
5590 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5591 #endif
5592 else if (set_termname(T_NAME) == FAIL)
5593 errmsg = (char_u *)N_("E522: Not found in termcap");
5594 else
5595 /* Screen colors may have changed. */
5596 redraw_later_clear();
5599 /* 'backupcopy' */
5600 else if (varp == &p_bkc)
5602 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5603 errmsg = e_invarg;
5604 if (((bkc_flags & BKC_AUTO) != 0)
5605 + ((bkc_flags & BKC_YES) != 0)
5606 + ((bkc_flags & BKC_NO) != 0) != 1)
5608 /* Must have exactly one of "auto", "yes" and "no". */
5609 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5610 errmsg = e_invarg;
5614 /* 'backupext' and 'patchmode' */
5615 else if (varp == &p_bex || varp == &p_pm)
5617 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5618 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5619 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5623 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5624 * If the new option is invalid, use old value. 'lisp' option: refill
5625 * chartab[] for '-' char
5627 else if ( varp == &p_isi
5628 || varp == &(curbuf->b_p_isk)
5629 || varp == &p_isp
5630 || varp == &p_isf)
5632 if (init_chartab() == FAIL)
5634 did_chartab = TRUE; /* need to restore it below */
5635 errmsg = e_invarg; /* error in value */
5639 /* 'helpfile' */
5640 else if (varp == &p_hf)
5642 /* May compute new values for $VIM and $VIMRUNTIME */
5643 if (didset_vim)
5645 vim_setenv((char_u *)"VIM", (char_u *)"");
5646 didset_vim = FALSE;
5648 if (didset_vimruntime)
5650 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5651 didset_vimruntime = FALSE;
5655 #ifdef FEAT_MULTI_LANG
5656 /* 'helplang' */
5657 else if (varp == &p_hlg)
5659 /* Check for "", "ab", "ab,cd", etc. */
5660 for (s = p_hlg; *s != NUL; s += 3)
5662 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5664 errmsg = e_invarg;
5665 break;
5667 if (s[2] == NUL)
5668 break;
5671 #endif
5673 /* 'highlight' */
5674 else if (varp == &p_hl)
5676 if (highlight_changed() == FAIL)
5677 errmsg = e_invarg; /* invalid flags */
5680 /* 'nrformats' */
5681 else if (gvarp == &p_nf)
5683 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5684 errmsg = e_invarg;
5687 #ifdef FEAT_SESSION
5688 /* 'sessionoptions' */
5689 else if (varp == &p_ssop)
5691 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5692 errmsg = e_invarg;
5693 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5695 /* Don't allow both "sesdir" and "curdir". */
5696 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5697 errmsg = e_invarg;
5700 /* 'viewoptions' */
5701 else if (varp == &p_vop)
5703 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5704 errmsg = e_invarg;
5706 #endif
5708 /* 'scrollopt' */
5709 #ifdef FEAT_SCROLLBIND
5710 else if (varp == &p_sbo)
5712 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5713 errmsg = e_invarg;
5715 #endif
5717 /* 'ambiwidth' */
5718 #ifdef FEAT_MBYTE
5719 else if (varp == &p_ambw)
5721 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5722 errmsg = e_invarg;
5724 #endif
5726 /* 'background' */
5727 else if (varp == &p_bg)
5729 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5731 #ifdef FEAT_EVAL
5732 int dark = (*p_bg == 'd');
5733 #endif
5735 init_highlight(FALSE, FALSE);
5737 #ifdef FEAT_EVAL
5738 if (dark != (*p_bg == 'd')
5739 && get_var_value((char_u *)"g:colors_name") != NULL)
5741 /* The color scheme must have set 'background' back to another
5742 * value, that's not what we want here. Disable the color
5743 * scheme and set the colors again. */
5744 do_unlet((char_u *)"g:colors_name", TRUE);
5745 free_string_option(p_bg);
5746 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5747 check_string_option(&p_bg);
5748 init_highlight(FALSE, FALSE);
5750 #endif
5752 else
5753 errmsg = e_invarg;
5756 /* 'wildmode' */
5757 else if (varp == &p_wim)
5759 if (check_opt_wim() == FAIL)
5760 errmsg = e_invarg;
5763 #ifdef FEAT_CMDL_COMPL
5764 /* 'wildoptions' */
5765 else if (varp == &p_wop)
5767 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5768 errmsg = e_invarg;
5770 #endif
5772 #ifdef FEAT_WAK
5773 /* 'winaltkeys' */
5774 else if (varp == &p_wak)
5776 if (*p_wak == NUL
5777 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5778 errmsg = e_invarg;
5779 # ifdef FEAT_MENU
5780 # ifdef FEAT_GUI_MOTIF
5781 else if (gui.in_use)
5782 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5783 # else
5784 # ifdef FEAT_GUI_GTK
5785 else if (gui.in_use)
5786 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5787 # endif
5788 # endif
5789 # endif
5791 #endif
5793 #ifdef FEAT_AUTOCMD
5794 /* 'eventignore' */
5795 else if (varp == &p_ei)
5797 if (check_ei() == FAIL)
5798 errmsg = e_invarg;
5800 #endif
5802 #ifdef FEAT_MBYTE
5803 /* 'encoding' and 'fileencoding' */
5804 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5806 if (gvarp == &p_fenc)
5808 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
5809 errmsg = e_modifiable;
5810 else if (vim_strchr(*varp, ',') != NULL)
5811 /* No comma allowed in 'fileencoding'; catches confusing it
5812 * with 'fileencodings'. */
5813 errmsg = e_invarg;
5814 else
5816 # ifdef FEAT_TITLE
5817 /* May show a "+" in the title now. */
5818 redraw_titles();
5819 # endif
5820 /* Add 'fileencoding' to the swap file. */
5821 ml_setflags(curbuf);
5824 if (errmsg == NULL)
5826 /* canonize the value, so that STRCMP() can be used on it */
5827 p = enc_canonize(*varp);
5828 if (p != NULL)
5830 vim_free(*varp);
5831 *varp = p;
5833 if (varp == &p_enc)
5835 errmsg = mb_init();
5836 # ifdef FEAT_TITLE
5837 redraw_titles();
5838 # endif
5842 # if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5843 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5845 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5846 if (STRCMP(p_tenc, "utf-8") != 0)
5847 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5849 # endif
5851 if (errmsg == NULL)
5853 # ifdef FEAT_KEYMAP
5854 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5855 * (with another encoding). */
5856 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5857 (void)keymap_init();
5858 # endif
5860 /* When 'termencoding' is not empty and 'encoding' changes or when
5861 * 'termencoding' changes, need to setup for keyboard input and
5862 * display output conversion. */
5863 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5865 convert_setup(&input_conv, p_tenc, p_enc);
5866 convert_setup(&output_conv, p_enc, p_tenc);
5869 # if defined(WIN3264) && defined(FEAT_MBYTE)
5870 /* $HOME may have characters in active code page. */
5871 if (varp == &p_enc)
5872 init_homedir();
5873 # endif
5876 #endif
5878 #if defined(FEAT_POSTSCRIPT)
5879 else if (varp == &p_penc)
5881 /* Canonize printencoding if VIM standard one */
5882 p = enc_canonize(p_penc);
5883 if (p != NULL)
5885 vim_free(p_penc);
5886 p_penc = p;
5888 else
5890 /* Ensure lower case and '-' for '_' */
5891 for (s = p_penc; *s != NUL; s++)
5893 if (*s == '_')
5894 *s = '-';
5895 else
5896 *s = TOLOWER_ASC(*s);
5900 #endif
5902 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
5903 else if (varp == &p_imak)
5905 if (gui.in_use && !im_xim_isvalid_imactivate())
5906 errmsg = e_invarg;
5908 #endif
5910 #ifdef FEAT_KEYMAP
5911 else if (varp == &curbuf->b_p_keymap)
5913 /* load or unload key mapping tables */
5914 errmsg = keymap_init();
5916 if (errmsg == NULL)
5918 if (*curbuf->b_p_keymap != NUL)
5920 /* Installed a new keymap, switch on using it. */
5921 curbuf->b_p_iminsert = B_IMODE_LMAP;
5922 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5923 curbuf->b_p_imsearch = B_IMODE_LMAP;
5925 else
5927 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5928 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5929 curbuf->b_p_iminsert = B_IMODE_NONE;
5930 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5931 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5933 if ((opt_flags & OPT_LOCAL) == 0)
5935 set_iminsert_global();
5936 set_imsearch_global();
5938 # ifdef FEAT_WINDOWS
5939 status_redraw_curbuf();
5940 # endif
5943 #endif
5945 /* 'fileformat' */
5946 else if (gvarp == &p_ff)
5948 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5949 errmsg = e_modifiable;
5950 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5951 errmsg = e_invarg;
5952 else
5954 /* may also change 'textmode' */
5955 if (get_fileformat(curbuf) == EOL_DOS)
5956 curbuf->b_p_tx = TRUE;
5957 else
5958 curbuf->b_p_tx = FALSE;
5959 #ifdef FEAT_TITLE
5960 redraw_titles();
5961 #endif
5962 /* update flag in swap file */
5963 ml_setflags(curbuf);
5964 /* Redraw needed when switching to/from "mac": a CR in the text
5965 * will be displayed differently. */
5966 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5967 redraw_curbuf_later(NOT_VALID);
5971 /* 'fileformats' */
5972 else if (varp == &p_ffs)
5974 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5975 errmsg = e_invarg;
5976 else
5978 /* also change 'textauto' */
5979 if (*p_ffs == NUL)
5980 p_ta = FALSE;
5981 else
5982 p_ta = TRUE;
5986 #if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5987 /* 'cryptkey' */
5988 else if (gvarp == &p_key)
5990 /* Make sure the ":set" command doesn't show the new value in the
5991 * history. */
5992 remove_key_from_history();
5994 #endif
5996 /* 'matchpairs' */
5997 else if (gvarp == &p_mps)
5999 /* Check for "x:y,x:y" */
6000 for (p = *varp; *p != NUL; p += 4)
6002 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6004 errmsg = e_invarg;
6005 break;
6007 if (p[3] == NUL)
6008 break;
6012 #ifdef FEAT_COMMENTS
6013 /* 'comments' */
6014 else if (gvarp == &p_com)
6016 for (s = *varp; *s; )
6018 while (*s && *s != ':')
6020 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6021 && !VIM_ISDIGIT(*s) && *s != '-')
6023 errmsg = illegal_char(errbuf, *s);
6024 break;
6026 ++s;
6028 if (*s++ == NUL)
6029 errmsg = (char_u *)N_("E524: Missing colon");
6030 else if (*s == ',' || *s == NUL)
6031 errmsg = (char_u *)N_("E525: Zero length string");
6032 if (errmsg != NULL)
6033 break;
6034 while (*s && *s != ',')
6036 if (*s == '\\' && s[1] != NUL)
6037 ++s;
6038 ++s;
6040 s = skip_to_option_part(s);
6043 #endif
6045 /* 'listchars' */
6046 else if (varp == &p_lcs)
6048 errmsg = set_chars_option(varp);
6051 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6052 /* 'fillchars' */
6053 else if (varp == &p_fcs)
6055 errmsg = set_chars_option(varp);
6057 #endif
6059 #ifdef FEAT_CMDWIN
6060 /* 'cedit' */
6061 else if (varp == &p_cedit)
6063 errmsg = check_cedit();
6065 #endif
6067 /* 'verbosefile' */
6068 else if (varp == &p_vfile)
6070 verbose_stop();
6071 if (*p_vfile != NUL && verbose_open() == FAIL)
6072 errmsg = e_invarg;
6075 #ifdef FEAT_VIMINFO
6076 /* 'viminfo' */
6077 else if (varp == &p_viminfo)
6079 for (s = p_viminfo; *s;)
6081 /* Check it's a valid character */
6082 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6084 errmsg = illegal_char(errbuf, *s);
6085 break;
6087 if (*s == 'n') /* name is always last one */
6089 break;
6091 else if (*s == 'r') /* skip until next ',' */
6093 while (*++s && *s != ',')
6096 else if (*s == '%')
6098 /* optional number */
6099 while (vim_isdigit(*++s))
6102 else if (*s == '!' || *s == 'h' || *s == 'c')
6103 ++s; /* no extra chars */
6104 else /* must have a number */
6106 while (vim_isdigit(*++s))
6109 if (!VIM_ISDIGIT(*(s - 1)))
6111 if (errbuf != NULL)
6113 sprintf((char *)errbuf,
6114 _("E526: Missing number after <%s>"),
6115 transchar_byte(*(s - 1)));
6116 errmsg = errbuf;
6118 else
6119 errmsg = (char_u *)"";
6120 break;
6123 if (*s == ',')
6124 ++s;
6125 else if (*s)
6127 if (errbuf != NULL)
6128 errmsg = (char_u *)N_("E527: Missing comma");
6129 else
6130 errmsg = (char_u *)"";
6131 break;
6134 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6135 errmsg = (char_u *)N_("E528: Must specify a ' value");
6137 #endif /* FEAT_VIMINFO */
6139 /* terminal options */
6140 else if (istermoption(&options[opt_idx]) && full_screen)
6142 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6143 if (varp == &T_CCO)
6145 int colors = atoi((char *)T_CCO);
6147 /* Only reinitialize colors if t_Co value has really changed to
6148 * avoid expensive reload of colorscheme if t_Co is set to the
6149 * same value multiple times. */
6150 if (colors != t_colors)
6152 t_colors = colors;
6153 if (t_colors <= 1)
6155 if (new_value_alloced)
6156 vim_free(T_CCO);
6157 T_CCO = empty_option;
6159 /* We now have a different color setup, initialize it again. */
6160 init_highlight(TRUE, FALSE);
6163 ttest(FALSE);
6164 if (varp == &T_ME)
6166 out_str(T_ME);
6167 redraw_later(CLEAR);
6168 #if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6169 /* Since t_me has been set, this probably means that the user
6170 * wants to use this as default colors. Need to reset default
6171 * background/foreground colors. */
6172 mch_set_normal_colors();
6173 #endif
6177 #ifdef FEAT_LINEBREAK
6178 /* 'showbreak' */
6179 else if (varp == &p_sbr)
6181 for (s = p_sbr; *s; )
6183 if (ptr2cells(s) != 1)
6184 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
6185 mb_ptr_adv(s);
6188 #endif
6190 #ifdef FEAT_GUI
6191 /* 'guifont' */
6192 else if (varp == &p_guifont)
6194 if (gui.in_use)
6196 p = p_guifont;
6197 # if defined(FEAT_GUI_GTK)
6199 * Put up a font dialog and let the user select a new value.
6200 * If this is cancelled go back to the old value but don't
6201 * give an error message.
6203 if (STRCMP(p, "*") == 0)
6205 p = gui_mch_font_dialog(oldval);
6207 if (new_value_alloced)
6208 free_string_option(p_guifont);
6210 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6211 new_value_alloced = TRUE;
6213 # endif
6214 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6216 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6217 if (STRCMP(p_guifont, "*") == 0)
6219 /* Dialog was cancelled: Keep the old value without giving
6220 * an error message. */
6221 if (new_value_alloced)
6222 free_string_option(p_guifont);
6223 p_guifont = vim_strsave(oldval);
6224 new_value_alloced = TRUE;
6226 else
6227 # endif
6228 errmsg = (char_u *)N_("E596: Invalid font(s)");
6231 redraw_gui_only = TRUE;
6233 # ifdef FEAT_XFONTSET
6234 else if (varp == &p_guifontset)
6236 if (STRCMP(p_guifontset, "*") == 0)
6237 errmsg = (char_u *)N_("E597: can't select fontset");
6238 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6239 errmsg = (char_u *)N_("E598: Invalid fontset");
6240 redraw_gui_only = TRUE;
6242 # endif
6243 # ifdef FEAT_MBYTE
6244 else if (varp == &p_guifontwide)
6246 if (STRCMP(p_guifontwide, "*") == 0)
6247 errmsg = (char_u *)N_("E533: can't select wide font");
6248 else if (gui_get_wide_font() == FAIL)
6249 errmsg = (char_u *)N_("E534: Invalid wide font");
6250 redraw_gui_only = TRUE;
6252 # endif
6253 #endif
6255 #ifdef CURSOR_SHAPE
6256 /* 'guicursor' */
6257 else if (varp == &p_guicursor)
6258 errmsg = parse_shape_opt(SHAPE_CURSOR);
6259 #endif
6261 #ifdef FEAT_MOUSESHAPE
6262 /* 'mouseshape' */
6263 else if (varp == &p_mouseshape)
6265 errmsg = parse_shape_opt(SHAPE_MOUSE);
6266 update_mouseshape(-1);
6268 #endif
6270 #ifdef FEAT_PRINTER
6271 else if (varp == &p_popt)
6272 errmsg = parse_printoptions();
6273 # if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
6274 else if (varp == &p_pmfn)
6275 errmsg = parse_printmbfont();
6276 # endif
6277 #endif
6279 #ifdef FEAT_LANGMAP
6280 /* 'langmap' */
6281 else if (varp == &p_langmap)
6282 langmap_set();
6283 #endif
6285 #ifdef FEAT_LINEBREAK
6286 /* 'breakat' */
6287 else if (varp == &p_breakat)
6288 fill_breakat_flags();
6289 #endif
6291 #ifdef FEAT_TITLE
6292 /* 'titlestring' and 'iconstring' */
6293 else if (varp == &p_titlestring || varp == &p_iconstring)
6295 # ifdef FEAT_STL_OPT
6296 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6298 /* NULL => statusline syntax */
6299 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6300 stl_syntax |= flagval;
6301 else
6302 stl_syntax &= ~flagval;
6303 # endif
6304 did_set_title(varp == &p_iconstring);
6307 #endif
6309 #ifdef FEAT_GUI
6310 /* 'guioptions' */
6311 else if (varp == &p_go)
6313 gui_init_which_components(oldval);
6314 redraw_gui_only = TRUE;
6316 #endif
6318 #if defined(FEAT_GUI_TABLINE)
6319 /* 'guitablabel' */
6320 else if (varp == &p_gtl)
6322 redraw_tabline = TRUE;
6323 redraw_gui_only = TRUE;
6325 /* 'guitabtooltip' */
6326 else if (varp == &p_gtt)
6328 redraw_gui_only = TRUE;
6330 #endif
6332 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6333 /* 'ttymouse' */
6334 else if (varp == &p_ttym)
6336 /* Switch the mouse off before changing the escape sequences used for
6337 * that. */
6338 mch_setmouse(FALSE);
6339 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6340 errmsg = e_invarg;
6341 else
6342 check_mouse_termcode();
6343 if (termcap_active)
6344 setmouse(); /* may switch it on again */
6346 #endif
6348 #ifdef FEAT_VISUAL
6349 /* 'selection' */
6350 else if (varp == &p_sel)
6352 if (*p_sel == NUL
6353 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6354 errmsg = e_invarg;
6357 /* 'selectmode' */
6358 else if (varp == &p_slm)
6360 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6361 errmsg = e_invarg;
6363 #endif
6365 #ifdef FEAT_BROWSE
6366 /* 'browsedir' */
6367 else if (varp == &p_bsdir)
6369 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6370 && !mch_isdir(p_bsdir))
6371 errmsg = e_invarg;
6373 #endif
6375 #ifdef FEAT_VISUAL
6376 /* 'keymodel' */
6377 else if (varp == &p_km)
6379 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6380 errmsg = e_invarg;
6381 else
6383 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6384 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6387 #endif
6389 /* 'mousemodel' */
6390 else if (varp == &p_mousem)
6392 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6393 errmsg = e_invarg;
6394 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6395 else if (*p_mousem != *oldval)
6396 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6397 * to create or delete the popup menus. */
6398 gui_motif_update_mousemodel(root_menu);
6399 #endif
6402 /* 'switchbuf' */
6403 else if (varp == &p_swb)
6405 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
6406 errmsg = e_invarg;
6409 /* 'debug' */
6410 else if (varp == &p_debug)
6412 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
6413 errmsg = e_invarg;
6416 /* 'display' */
6417 else if (varp == &p_dy)
6419 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6420 errmsg = e_invarg;
6421 else
6422 (void)init_chartab();
6426 #ifdef FEAT_VERTSPLIT
6427 /* 'eadirection' */
6428 else if (varp == &p_ead)
6430 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6431 errmsg = e_invarg;
6433 #endif
6435 #ifdef FEAT_CLIPBOARD
6436 /* 'clipboard' */
6437 else if (varp == &p_cb)
6438 errmsg = check_clipboard_option();
6439 #endif
6441 #ifdef FEAT_SPELL
6442 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6443 * buffer in which 'spell' is set load the wordlists. */
6444 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
6446 win_T *wp;
6447 int l;
6449 if (varp == &(curbuf->b_p_spf))
6451 l = (int)STRLEN(curbuf->b_p_spf);
6452 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6453 ".add") != 0))
6454 errmsg = e_invarg;
6457 if (errmsg == NULL)
6459 FOR_ALL_WINDOWS(wp)
6460 if (wp->w_buffer == curbuf && wp->w_p_spell)
6462 errmsg = did_set_spelllang(curbuf);
6463 # ifdef FEAT_WINDOWS
6464 break;
6465 # endif
6469 /* When 'spellcapcheck' is set compile the regexp program. */
6470 else if (varp == &(curbuf->b_p_spc))
6472 errmsg = compile_cap_prog(curbuf);
6474 /* 'spellsuggest' */
6475 else if (varp == &p_sps)
6477 if (spell_check_sps() != OK)
6478 errmsg = e_invarg;
6480 /* 'mkspellmem' */
6481 else if (varp == &p_msm)
6483 if (spell_check_msm() != OK)
6484 errmsg = e_invarg;
6486 #endif
6488 #ifdef FEAT_QUICKFIX
6489 /* When 'bufhidden' is set, check for valid value. */
6490 else if (gvarp == &p_bh)
6492 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6493 errmsg = e_invarg;
6496 /* When 'buftype' is set, check for valid value. */
6497 else if (gvarp == &p_bt)
6499 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6500 errmsg = e_invarg;
6501 else
6503 # ifdef FEAT_WINDOWS
6504 if (curwin->w_status_height)
6506 curwin->w_redr_status = TRUE;
6507 redraw_later(VALID);
6509 # endif
6510 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6511 # ifdef FEAT_TITLE
6512 redraw_titles();
6513 # endif
6516 #endif
6518 #ifdef FEAT_STL_OPT
6519 /* 'statusline' or 'rulerformat' */
6520 else if (gvarp == &p_stl || varp == &p_ruf)
6522 int wid;
6524 if (varp == &p_ruf) /* reset ru_wid first */
6525 ru_wid = 0;
6526 s = *varp;
6527 if (varp == &p_ruf && *s == '%')
6529 /* set ru_wid if 'ruf' starts with "%99(" */
6530 if (*++s == '-') /* ignore a '-' */
6531 s++;
6532 wid = getdigits(&s);
6533 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6534 ru_wid = wid;
6535 else
6536 errmsg = check_stl_option(p_ruf);
6538 /* check 'statusline' only if it doesn't start with "%!" */
6539 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
6540 errmsg = check_stl_option(s);
6541 if (varp == &p_ruf && errmsg == NULL)
6542 comp_col();
6544 #endif
6546 #ifdef FEAT_INS_EXPAND
6547 /* check if it is a valid value for 'complete' -- Acevedo */
6548 else if (gvarp == &p_cpt)
6550 for (s = *varp; *s;)
6552 while(*s == ',' || *s == ' ')
6553 s++;
6554 if (!*s)
6555 break;
6556 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6558 errmsg = illegal_char(errbuf, *s);
6559 break;
6561 if (*++s != NUL && *s != ',' && *s != ' ')
6563 if (s[-1] == 'k' || s[-1] == 's')
6565 /* skip optional filename after 'k' and 's' */
6566 while (*s && *s != ',' && *s != ' ')
6568 if (*s == '\\')
6569 ++s;
6570 ++s;
6573 else
6575 if (errbuf != NULL)
6577 sprintf((char *)errbuf,
6578 _("E535: Illegal character after <%c>"),
6579 *--s);
6580 errmsg = errbuf;
6582 else
6583 errmsg = (char_u *)"";
6584 break;
6590 /* 'completeopt' */
6591 else if (varp == &p_cot)
6593 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6594 errmsg = e_invarg;
6596 #endif /* FEAT_INS_EXPAND */
6599 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6600 else if (varp == &p_toolbar)
6602 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6603 &toolbar_flags, TRUE) != OK)
6604 errmsg = e_invarg;
6605 else
6607 out_flush();
6608 gui_mch_show_toolbar((toolbar_flags &
6609 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6612 #endif
6614 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6615 /* 'toolbariconsize': GTK+ 2 only */
6616 else if (varp == &p_tbis)
6618 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6619 errmsg = e_invarg;
6620 else
6622 out_flush();
6623 gui_mch_show_toolbar((toolbar_flags &
6624 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6627 #endif
6629 /* 'pastetoggle': translate key codes like in a mapping */
6630 else if (varp == &p_pt)
6632 if (*p_pt)
6634 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
6635 if (p != NULL)
6637 if (new_value_alloced)
6638 free_string_option(p_pt);
6639 p_pt = p;
6640 new_value_alloced = TRUE;
6645 /* 'backspace' */
6646 else if (varp == &p_bs)
6648 if (VIM_ISDIGIT(*p_bs))
6650 if (*p_bs >'2' || p_bs[1] != NUL)
6651 errmsg = e_invarg;
6653 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6654 errmsg = e_invarg;
6657 #ifdef FEAT_MBYTE
6658 /* 'casemap' */
6659 else if (varp == &p_cmp)
6661 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6662 errmsg = e_invarg;
6664 #endif
6666 #ifdef FEAT_DIFF
6667 /* 'diffopt' */
6668 else if (varp == &p_dip)
6670 if (diffopt_changed() == FAIL)
6671 errmsg = e_invarg;
6673 #endif
6675 #ifdef FEAT_FOLDING
6676 /* 'foldmethod' */
6677 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6679 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6680 || *curwin->w_p_fdm == NUL)
6681 errmsg = e_invarg;
6682 else
6684 foldUpdateAll(curwin);
6685 if (foldmethodIsDiff(curwin))
6686 newFoldLevel();
6689 # ifdef FEAT_EVAL
6690 /* 'foldexpr' */
6691 else if (varp == &curwin->w_p_fde)
6693 if (foldmethodIsExpr(curwin))
6694 foldUpdateAll(curwin);
6696 # endif
6697 /* 'foldmarker' */
6698 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6700 p = vim_strchr(*varp, ',');
6701 if (p == NULL)
6702 errmsg = (char_u *)N_("E536: comma required");
6703 else if (p == *varp || p[1] == NUL)
6704 errmsg = e_invarg;
6705 else if (foldmethodIsMarker(curwin))
6706 foldUpdateAll(curwin);
6708 /* 'commentstring' */
6709 else if (gvarp == &p_cms)
6711 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6712 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6714 /* 'foldopen' */
6715 else if (varp == &p_fdo)
6717 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6718 errmsg = e_invarg;
6720 /* 'foldclose' */
6721 else if (varp == &p_fcl)
6723 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6724 errmsg = e_invarg;
6726 /* 'foldignore' */
6727 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6729 if (foldmethodIsIndent(curwin))
6730 foldUpdateAll(curwin);
6732 #endif
6734 #ifdef FEAT_VIRTUALEDIT
6735 /* 'virtualedit' */
6736 else if (varp == &p_ve)
6738 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6739 errmsg = e_invarg;
6740 else if (STRCMP(p_ve, oldval) != 0)
6742 /* Recompute cursor position in case the new 've' setting
6743 * changes something. */
6744 validate_virtcol();
6745 coladvance(curwin->w_virtcol);
6748 #endif
6750 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6751 else if (varp == &p_csqf)
6753 if (p_csqf != NULL)
6755 p = p_csqf;
6756 while (*p != NUL)
6758 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6759 || p[1] == NUL
6760 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6761 || (p[2] != NUL && p[2] != ','))
6763 errmsg = e_invarg;
6764 break;
6766 else if (p[2] == NUL)
6767 break;
6768 else
6769 p += 3;
6773 #endif
6775 #ifdef FEAT_VARTABS
6776 /* 'varsofttabstop' */
6777 else if (varp == &(curbuf->b_p_vsts))
6779 char_u *cp;
6781 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
6783 if (curbuf->b_p_vsts_ary)
6785 vim_free(curbuf->b_p_vsts_ary);
6786 curbuf->b_p_vsts_ary = 0;
6789 else
6791 for (cp = *varp; *cp; ++cp)
6793 if (vim_isdigit(*cp))
6794 continue;
6795 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
6796 continue;
6797 errmsg = e_invarg;
6798 break;
6800 if (errmsg == NULL)
6802 int *oldarray = curbuf->b_p_vsts_ary;
6803 if (tabstop_set(*varp, &(curbuf->b_p_vsts_ary)))
6805 if (oldarray)
6806 vim_free(oldarray);
6808 else
6809 errmsg = e_invarg;
6814 /* 'vartabstop' */
6815 else if (varp == &(curbuf->b_p_vts))
6817 char_u *cp;
6819 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
6821 if (curbuf->b_p_vts_ary)
6823 vim_free(curbuf->b_p_vts_ary);
6824 curbuf->b_p_vts_ary = 0;
6827 else
6829 for (cp = *varp; *cp; ++cp)
6831 if (vim_isdigit(*cp))
6832 continue;
6833 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
6834 continue;
6835 errmsg = e_invarg;
6836 break;
6838 if (errmsg == NULL)
6840 int *oldarray = curbuf->b_p_vts_ary;
6841 if (tabstop_set(*varp, &(curbuf->b_p_vts_ary)))
6843 if (oldarray)
6844 vim_free(oldarray);
6845 #ifdef FEAT_FOLDING
6846 if (foldmethodIsIndent(curwin))
6847 foldUpdateAll(curwin);
6848 #endif /* FEAT_FOLDING */
6850 else
6851 errmsg = e_invarg;
6855 #endif
6857 /* Options that are a list of flags. */
6858 else
6860 p = NULL;
6861 if (varp == &p_ww)
6862 p = (char_u *)WW_ALL;
6863 if (varp == &p_shm)
6864 p = (char_u *)SHM_ALL;
6865 else if (varp == &(p_cpo))
6866 p = (char_u *)CPO_ALL;
6867 else if (varp == &(curbuf->b_p_fo))
6868 p = (char_u *)FO_ALL;
6869 else if (varp == &p_mouse)
6871 #ifdef FEAT_MOUSE
6872 p = (char_u *)MOUSE_ALL;
6873 #else
6874 if (*p_mouse != NUL)
6875 errmsg = (char_u *)N_("E538: No mouse support");
6876 #endif
6878 #if defined(FEAT_GUI)
6879 else if (varp == &p_go)
6880 p = (char_u *)GO_ALL;
6881 #endif
6882 if (p != NULL)
6884 for (s = *varp; *s; ++s)
6885 if (vim_strchr(p, *s) == NULL)
6887 errmsg = illegal_char(errbuf, *s);
6888 break;
6894 * If error detected, restore the previous value.
6896 if (errmsg != NULL)
6898 if (new_value_alloced)
6899 free_string_option(*varp);
6900 *varp = oldval;
6902 * When resetting some values, need to act on it.
6904 if (did_chartab)
6905 (void)init_chartab();
6906 if (varp == &p_hl)
6907 (void)highlight_changed();
6909 else
6911 #ifdef FEAT_EVAL
6912 /* Remember where the option was set. */
6913 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
6914 #endif
6916 * Free string options that are in allocated memory.
6917 * Use "free_oldval", because recursiveness may change the flags under
6918 * our fingers (esp. init_highlight()).
6920 if (free_oldval)
6921 free_string_option(oldval);
6922 if (new_value_alloced)
6923 options[opt_idx].flags |= P_ALLOCED;
6924 else
6925 options[opt_idx].flags &= ~P_ALLOCED;
6927 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6928 && ((int)options[opt_idx].indir & PV_BOTH))
6930 /* global option with local value set to use global value; free
6931 * the local value and make it empty */
6932 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6933 free_string_option(*(char_u **)p);
6934 *(char_u **)p = empty_option;
6937 /* May set global value for local option. */
6938 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6939 set_string_option_global(opt_idx, varp);
6941 #ifdef FEAT_AUTOCMD
6943 * Trigger the autocommand only after setting the flags.
6945 # ifdef FEAT_SYN_HL
6946 /* When 'syntax' is set, load the syntax of that name */
6947 if (varp == &(curbuf->b_p_syn))
6949 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6950 curbuf->b_fname, TRUE, curbuf);
6952 # endif
6953 else if (varp == &(curbuf->b_p_ft))
6955 /* 'filetype' is set, trigger the FileType autocommand */
6956 did_filetype = TRUE;
6957 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6958 curbuf->b_fname, TRUE, curbuf);
6960 #endif
6961 #ifdef FEAT_SPELL
6962 if (varp == &(curbuf->b_p_spl))
6964 char_u fname[200];
6967 * Source the spell/LANG.vim in 'runtimepath'.
6968 * They could set 'spellcapcheck' depending on the language.
6969 * Use the first name in 'spelllang' up to '_region' or
6970 * '.encoding'.
6972 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6973 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6974 break;
6975 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6976 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6977 source_runtime(fname, TRUE);
6979 #endif
6982 #ifdef FEAT_MOUSE
6983 if (varp == &p_mouse)
6985 # ifdef FEAT_MOUSE_TTY
6986 if (*p_mouse == NUL)
6987 mch_setmouse(FALSE); /* switch mouse off */
6988 else
6989 # endif
6990 setmouse(); /* in case 'mouse' changed */
6992 #endif
6994 if (curwin->w_curswant != MAXCOL)
6995 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6996 #ifdef FEAT_GUI
6997 /* check redraw when it's not a GUI option or the GUI is active. */
6998 if (!redraw_gui_only || gui.in_use)
6999 #endif
7000 check_redraw(options[opt_idx].flags);
7002 return errmsg;
7006 * Handle setting 'listchars' or 'fillchars'.
7007 * Returns error message, NULL if it's OK.
7009 static char_u *
7010 set_chars_option(varp)
7011 char_u **varp;
7013 int round, i, len, entries;
7014 char_u *p, *s;
7015 int c1, c2 = 0;
7016 struct charstab
7018 int *cp;
7019 char *name;
7021 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7022 static struct charstab filltab[] =
7024 {&fill_stl, "stl"},
7025 {&fill_stlnc, "stlnc"},
7026 {&fill_vert, "vert"},
7027 {&fill_fold, "fold"},
7028 {&fill_diff, "diff"},
7030 #endif
7031 static struct charstab lcstab[] =
7033 {&lcs_eol, "eol"},
7034 {&lcs_ext, "extends"},
7035 {&lcs_nbsp, "nbsp"},
7036 {&lcs_prec, "precedes"},
7037 {&lcs_tab2, "tab"},
7038 {&lcs_trail, "trail"},
7040 struct charstab *tab;
7042 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7043 if (varp == &p_lcs)
7044 #endif
7046 tab = lcstab;
7047 entries = sizeof(lcstab) / sizeof(struct charstab);
7049 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7050 else
7052 tab = filltab;
7053 entries = sizeof(filltab) / sizeof(struct charstab);
7055 #endif
7057 /* first round: check for valid value, second round: assign values */
7058 for (round = 0; round <= 1; ++round)
7060 if (round)
7062 /* After checking that the value is valid: set defaults: space for
7063 * 'fillchars', NUL for 'listchars' */
7064 for (i = 0; i < entries; ++i)
7065 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
7066 if (varp == &p_lcs)
7067 lcs_tab1 = NUL;
7068 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7069 else
7070 fill_diff = '-';
7071 #endif
7073 p = *varp;
7074 while (*p)
7076 for (i = 0; i < entries; ++i)
7078 len = (int)STRLEN(tab[i].name);
7079 if (STRNCMP(p, tab[i].name, len) == 0
7080 && p[len] == ':'
7081 && p[len + 1] != NUL)
7083 s = p + len + 1;
7084 #ifdef FEAT_MBYTE
7085 c1 = mb_ptr2char_adv(&s);
7086 if (mb_char2cells(c1) > 1)
7087 continue;
7088 #else
7089 c1 = *s++;
7090 #endif
7091 if (tab[i].cp == &lcs_tab2)
7093 if (*s == NUL)
7094 continue;
7095 #ifdef FEAT_MBYTE
7096 c2 = mb_ptr2char_adv(&s);
7097 if (mb_char2cells(c2) > 1)
7098 continue;
7099 #else
7100 c2 = *s++;
7101 #endif
7103 if (*s == ',' || *s == NUL)
7105 if (round)
7107 if (tab[i].cp == &lcs_tab2)
7109 lcs_tab1 = c1;
7110 lcs_tab2 = c2;
7112 else
7113 *(tab[i].cp) = c1;
7116 p = s;
7117 break;
7122 if (i == entries)
7123 return e_invarg;
7124 if (*p == ',')
7125 ++p;
7129 return NULL; /* no error */
7132 #ifdef FEAT_STL_OPT
7134 * Check validity of options with the 'statusline' format.
7135 * Return error message or NULL.
7137 char_u *
7138 check_stl_option(s)
7139 char_u *s;
7141 int itemcnt = 0;
7142 int groupdepth = 0;
7143 static char_u errbuf[80];
7145 while (*s && itemcnt < STL_MAX_ITEM)
7147 /* Check for valid keys after % sequences */
7148 while (*s && *s != '%')
7149 s++;
7150 if (!*s)
7151 break;
7152 s++;
7153 if (*s != '%' && *s != ')')
7154 ++itemcnt;
7155 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7157 s++;
7158 continue;
7160 if (*s == ')')
7162 s++;
7163 if (--groupdepth < 0)
7164 break;
7165 continue;
7167 if (*s == '-')
7168 s++;
7169 while (VIM_ISDIGIT(*s))
7170 s++;
7171 if (*s == STL_USER_HL)
7172 continue;
7173 if (*s == '.')
7175 s++;
7176 while (*s && VIM_ISDIGIT(*s))
7177 s++;
7179 if (*s == '(')
7181 groupdepth++;
7182 continue;
7184 if (vim_strchr(STL_ALL, *s) == NULL)
7186 return illegal_char(errbuf, *s);
7188 if (*s == '{')
7190 s++;
7191 while (*s != '}' && *s)
7192 s++;
7193 if (*s != '}')
7194 return (char_u *)N_("E540: Unclosed expression sequence");
7197 if (itemcnt >= STL_MAX_ITEM)
7198 return (char_u *)N_("E541: too many items");
7199 if (groupdepth != 0)
7200 return (char_u *)N_("E542: unbalanced groups");
7201 return NULL;
7203 #endif
7205 #ifdef FEAT_CLIPBOARD
7207 * Extract the items in the 'clipboard' option and set global values.
7209 static char_u *
7210 check_clipboard_option()
7212 int new_unnamed = FALSE;
7213 int new_autoselect = FALSE;
7214 int new_autoselectml = FALSE;
7215 int new_html = FALSE;
7216 regprog_T *new_exclude_prog = NULL;
7217 char_u *errmsg = NULL;
7218 char_u *p;
7220 for (p = p_cb; *p != NUL; )
7222 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7224 new_unnamed = TRUE;
7225 p += 7;
7227 else if (STRNCMP(p, "autoselect", 10) == 0
7228 && (p[10] == ',' || p[10] == NUL))
7230 new_autoselect = TRUE;
7231 p += 10;
7233 else if (STRNCMP(p, "autoselectml", 12) == 0
7234 && (p[12] == ',' || p[12] == NUL))
7236 new_autoselectml = TRUE;
7237 p += 12;
7239 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7241 new_html = TRUE;
7242 p += 4;
7244 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7246 p += 8;
7247 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7248 if (new_exclude_prog == NULL)
7249 errmsg = e_invarg;
7250 break;
7252 else
7254 errmsg = e_invarg;
7255 break;
7257 if (*p == ',')
7258 ++p;
7260 if (errmsg == NULL)
7262 clip_unnamed = new_unnamed;
7263 clip_autoselect = new_autoselect;
7264 clip_autoselectml = new_autoselectml;
7265 clip_html = new_html;
7266 vim_free(clip_exclude_prog);
7267 clip_exclude_prog = new_exclude_prog;
7268 #ifdef FEAT_GUI_GTK
7269 if (gui.in_use)
7271 gui_gtk_set_selection_targets();
7272 gui_gtk_set_dnd_targets();
7274 #endif
7276 else
7277 vim_free(new_exclude_prog);
7279 return errmsg;
7281 #endif
7283 #ifdef FEAT_SPELL
7285 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7286 * Return error message when failed, NULL when OK.
7288 static char_u *
7289 compile_cap_prog(buf)
7290 buf_T *buf;
7292 regprog_T *rp = buf->b_cap_prog;
7293 char_u *re;
7295 if (*buf->b_p_spc == NUL)
7296 buf->b_cap_prog = NULL;
7297 else
7299 /* Prepend a ^ so that we only match at one column */
7300 re = concat_str((char_u *)"^", buf->b_p_spc);
7301 if (re != NULL)
7303 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7304 if (buf->b_cap_prog == NULL)
7306 buf->b_cap_prog = rp; /* restore the previous program */
7307 return e_invarg;
7309 vim_free(re);
7313 vim_free(rp);
7314 return NULL;
7316 #endif
7318 #if defined(FEAT_EVAL) || defined(PROTO)
7320 * Set the scriptID for an option, taking care of setting the buffer- or
7321 * window-local value.
7323 static void
7324 set_option_scriptID_idx(opt_idx, opt_flags, id)
7325 int opt_idx;
7326 int opt_flags;
7327 int id;
7329 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7330 int indir = (int)options[opt_idx].indir;
7332 /* Remember where the option was set. For local options need to do that
7333 * in the buffer or window structure. */
7334 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
7335 options[opt_idx].scriptID = id;
7336 if (both || (opt_flags & OPT_LOCAL))
7338 if (indir & PV_BUF)
7339 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7340 else if (indir & PV_WIN)
7341 curwin->w_p_scriptID[indir & PV_MASK] = id;
7344 #endif
7347 * Set the value of a boolean option, and take care of side effects.
7348 * Returns NULL for success, or an error message for an error.
7350 static char_u *
7351 set_bool_option(opt_idx, varp, value, opt_flags)
7352 int opt_idx; /* index in options[] table */
7353 char_u *varp; /* pointer to the option variable */
7354 int value; /* new value */
7355 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7357 int old_value = *(int *)varp;
7359 /* Disallow changing some options from secure mode */
7360 if ((secure
7361 #ifdef HAVE_SANDBOX
7362 || sandbox != 0
7363 #endif
7364 ) && (options[opt_idx].flags & P_SECURE))
7365 return e_secure;
7367 *(int *)varp = value; /* set the new value */
7368 #ifdef FEAT_EVAL
7369 /* Remember where the option was set. */
7370 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
7371 #endif
7373 #ifdef FEAT_GUI
7374 need_mouse_correct = TRUE;
7375 #endif
7377 /* May set global value for local option. */
7378 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7379 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7382 * Handle side effects of changing a bool option.
7385 /* 'compatible' */
7386 if ((int *)varp == &p_cp)
7388 compatible_set();
7391 /* 'list', 'number' */
7392 else if ((int *)varp == &curwin->w_p_list
7393 || (int *)varp == &curwin->w_p_nu)
7395 if (curwin->w_curswant != MAXCOL)
7396 curwin->w_set_curswant = TRUE;
7399 else if ((int *)varp == &curbuf->b_p_ro)
7401 /* when 'readonly' is reset globally, also reset readonlymode */
7402 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7403 readonlymode = FALSE;
7405 /* when 'readonly' is set may give W10 again */
7406 if (curbuf->b_p_ro)
7407 curbuf->b_did_warn = FALSE;
7409 #ifdef FEAT_TITLE
7410 redraw_titles();
7411 #endif
7414 #ifdef FEAT_TITLE
7415 /* when 'modifiable' is changed, redraw the window title */
7416 else if ((int *)varp == &curbuf->b_p_ma)
7418 redraw_titles();
7420 /* when 'endofline' is changed, redraw the window title */
7421 else if ((int *)varp == &curbuf->b_p_eol)
7423 redraw_titles();
7425 # ifdef FEAT_MBYTE
7426 /* when 'bomb' is changed, redraw the window title and tab page text */
7427 else if ((int *)varp == &curbuf->b_p_bomb)
7429 redraw_titles();
7431 # endif
7432 #endif
7434 /* when 'bin' is set also set some other options */
7435 else if ((int *)varp == &curbuf->b_p_bin)
7437 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7438 #ifdef FEAT_TITLE
7439 redraw_titles();
7440 #endif
7443 #ifdef FEAT_AUTOCMD
7444 /* when 'buflisted' changes, trigger autocommands */
7445 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7447 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7448 NULL, NULL, TRUE, curbuf);
7450 #endif
7452 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7453 else if ((int *)varp == &curbuf->b_p_swf)
7455 if (curbuf->b_p_swf && p_uc)
7456 ml_open_file(curbuf); /* create the swap file */
7457 else
7458 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7459 * buf->b_p_swf */
7460 mf_close_file(curbuf, TRUE); /* remove the swap file */
7463 /* when 'terse' is set change 'shortmess' */
7464 else if ((int *)varp == &p_terse)
7466 char_u *p;
7468 p = vim_strchr(p_shm, SHM_SEARCH);
7470 /* insert 's' in p_shm */
7471 if (p_terse && p == NULL)
7473 STRCPY(IObuff, p_shm);
7474 STRCAT(IObuff, "s");
7475 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
7477 /* remove 's' from p_shm */
7478 else if (!p_terse && p != NULL)
7479 STRMOVE(p, p + 1);
7482 /* when 'paste' is set or reset also change other options */
7483 else if ((int *)varp == &p_paste)
7485 paste_option_changed();
7488 /* when 'insertmode' is set from an autocommand need to do work here */
7489 else if ((int *)varp == &p_im)
7491 if (p_im)
7493 if ((State & INSERT) == 0)
7494 need_start_insertmode = TRUE;
7495 stop_insert_mode = FALSE;
7497 else
7499 need_start_insertmode = FALSE;
7500 stop_insert_mode = TRUE;
7501 if (restart_edit != 0 && mode_displayed)
7502 clear_cmdline = TRUE; /* remove "(insert)" */
7503 restart_edit = 0;
7507 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7508 else if ((int *)varp == &p_ic && p_hls)
7510 redraw_all_later(SOME_VALID);
7513 #ifdef FEAT_SEARCH_EXTRA
7514 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7515 else if ((int *)varp == &p_hls)
7517 no_hlsearch = FALSE;
7519 #endif
7521 #ifdef FEAT_SCROLLBIND
7522 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7523 * at the end of normal_cmd() */
7524 else if ((int *)varp == &curwin->w_p_scb)
7526 if (curwin->w_p_scb)
7527 do_check_scrollbind(FALSE);
7529 #endif
7531 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7532 /* There can be only one window with 'previewwindow' set. */
7533 else if ((int *)varp == &curwin->w_p_pvw)
7535 if (curwin->w_p_pvw)
7537 win_T *win;
7539 for (win = firstwin; win != NULL; win = win->w_next)
7540 if (win->w_p_pvw && win != curwin)
7542 curwin->w_p_pvw = FALSE;
7543 return (char_u *)N_("E590: A preview window already exists");
7547 #endif
7549 /* when 'textmode' is set or reset also change 'fileformat' */
7550 else if ((int *)varp == &curbuf->b_p_tx)
7552 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7555 /* when 'textauto' is set or reset also change 'fileformats' */
7556 else if ((int *)varp == &p_ta)
7557 set_string_option_direct((char_u *)"ffs", -1,
7558 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
7559 OPT_FREE | opt_flags, 0);
7562 * When 'lisp' option changes include/exclude '-' in
7563 * keyword characters.
7565 #ifdef FEAT_LISP
7566 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7568 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7570 #endif
7572 #ifdef FEAT_TITLE
7573 /* when 'title' changed, may need to change the title; same for 'icon' */
7574 else if ((int *)varp == &p_title)
7576 did_set_title(FALSE);
7579 else if ((int *)varp == &p_icon)
7581 did_set_title(TRUE);
7583 #endif
7585 else if ((int *)varp == &curbuf->b_changed)
7587 if (!value)
7588 save_file_ff(curbuf); /* Buffer is unchanged */
7589 #ifdef FEAT_TITLE
7590 redraw_titles();
7591 #endif
7592 #ifdef FEAT_AUTOCMD
7593 modified_was_set = value;
7594 #endif
7597 #ifdef BACKSLASH_IN_FILENAME
7598 else if ((int *)varp == &p_ssl)
7600 if (p_ssl)
7602 psepc = '/';
7603 psepcN = '\\';
7604 pseps[0] = '/';
7606 else
7608 psepc = '\\';
7609 psepcN = '/';
7610 pseps[0] = '\\';
7613 /* need to adjust the file name arguments and buffer names. */
7614 buflist_slash_adjust();
7615 alist_slash_adjust();
7616 # ifdef FEAT_EVAL
7617 scriptnames_slash_adjust();
7618 # endif
7620 #endif
7622 /* If 'wrap' is set, set w_leftcol to zero. */
7623 else if ((int *)varp == &curwin->w_p_wrap)
7625 if (curwin->w_p_wrap)
7626 curwin->w_leftcol = 0;
7627 if (curwin->w_curswant != MAXCOL)
7628 curwin->w_set_curswant = TRUE;
7631 /* If 'number' is set, reset 'relativenumber'. */
7632 else if ((int *)varp == &curwin->w_p_nu)
7634 if (curwin->w_p_nu)
7635 curwin->w_p_rnu = FALSE;
7637 /* If 'relativenumber' is set, reset 'number'. */
7638 else if ((int *)varp == &curwin->w_p_rnu)
7640 if (curwin->w_p_rnu)
7641 curwin->w_p_nu = FALSE;
7644 #ifdef FEAT_WINDOWS
7645 else if ((int *)varp == &p_ea)
7647 if (p_ea && !old_value)
7648 win_equal(curwin, FALSE, 0);
7650 #endif
7652 else if ((int *)varp == &p_wiv)
7655 * When 'weirdinvert' changed, set/reset 't_xs'.
7656 * Then set 'weirdinvert' according to value of 't_xs'.
7658 if (p_wiv && !old_value)
7659 T_XS = (char_u *)"y";
7660 else if (!p_wiv && old_value)
7661 T_XS = empty_option;
7662 p_wiv = (*T_XS != NUL);
7665 #ifdef FEAT_BEVAL
7666 else if ((int *)varp == &p_beval)
7668 if (p_beval == TRUE)
7669 gui_mch_enable_beval_area(balloonEval);
7670 else
7671 gui_mch_disable_beval_area(balloonEval);
7673 #endif
7675 #ifdef FEAT_AUTOCHDIR
7676 else if ((int *)varp == &p_acd)
7678 /* Change directories when the 'acd' option is set now. */
7679 DO_AUTOCHDIR
7681 #endif
7683 #ifdef FEAT_DIFF
7684 /* 'diff' */
7685 else if ((int *)varp == &curwin->w_p_diff)
7687 /* May add or remove the buffer from the list of diff buffers. */
7688 diff_buf_adjust(curwin);
7689 # ifdef FEAT_FOLDING
7690 if (foldmethodIsDiff(curwin))
7691 foldUpdateAll(curwin);
7692 # endif
7694 #endif
7696 #ifdef USE_IM_CONTROL
7697 /* 'imdisable' */
7698 else if ((int *)varp == &p_imdisable)
7700 /* Only de-activate it here, it will be enabled when changing mode. */
7701 if (p_imdisable)
7702 im_set_active(FALSE);
7704 #endif
7706 #ifdef FEAT_SPELL
7707 /* 'spell' */
7708 else if ((int *)varp == &curwin->w_p_spell)
7710 if (curwin->w_p_spell)
7712 char_u *errmsg = did_set_spelllang(curbuf);
7714 if (errmsg != NULL)
7715 EMSG(_(errmsg));
7718 #endif
7720 #ifdef FEAT_FKMAP
7721 else if ((int *)varp == &p_altkeymap)
7723 if (old_value != p_altkeymap)
7725 if (!p_altkeymap)
7727 p_hkmap = p_fkmap;
7728 p_fkmap = 0;
7730 else
7732 p_fkmap = p_hkmap;
7733 p_hkmap = 0;
7735 (void)init_chartab();
7740 * In case some second language keymapping options have changed, check
7741 * and correct the setting in a consistent way.
7745 * If hkmap or fkmap are set, reset Arabic keymapping.
7747 if ((p_hkmap || p_fkmap) && p_altkeymap)
7749 p_altkeymap = p_fkmap;
7750 # ifdef FEAT_ARABIC
7751 curwin->w_p_arab = FALSE;
7752 # endif
7753 (void)init_chartab();
7757 * If hkmap set, reset Farsi keymapping.
7759 if (p_hkmap && p_altkeymap)
7761 p_altkeymap = 0;
7762 p_fkmap = 0;
7763 # ifdef FEAT_ARABIC
7764 curwin->w_p_arab = FALSE;
7765 # endif
7766 (void)init_chartab();
7770 * If fkmap set, reset Hebrew keymapping.
7772 if (p_fkmap && !p_altkeymap)
7774 p_altkeymap = 1;
7775 p_hkmap = 0;
7776 # ifdef FEAT_ARABIC
7777 curwin->w_p_arab = FALSE;
7778 # endif
7779 (void)init_chartab();
7781 #endif
7783 #ifdef FEAT_ARABIC
7784 if ((int *)varp == &curwin->w_p_arab)
7786 if (curwin->w_p_arab)
7789 * 'arabic' is set, handle various sub-settings.
7791 if (!p_tbidi)
7793 /* set rightleft mode */
7794 if (!curwin->w_p_rl)
7796 curwin->w_p_rl = TRUE;
7797 changed_window_setting();
7800 /* Enable Arabic shaping (major part of what Arabic requires) */
7801 if (!p_arshape)
7803 p_arshape = TRUE;
7804 redraw_later_clear();
7808 /* Arabic requires a utf-8 encoding, inform the user if its not
7809 * set. */
7810 if (STRCMP(p_enc, "utf-8") != 0)
7812 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7814 msg_source(hl_attr(HLF_W));
7815 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7816 #ifdef FEAT_EVAL
7817 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7818 #endif
7821 # ifdef FEAT_MBYTE
7822 /* set 'delcombine' */
7823 p_deco = TRUE;
7824 # endif
7826 # ifdef FEAT_KEYMAP
7827 /* Force-set the necessary keymap for arabic */
7828 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7829 OPT_LOCAL);
7830 # endif
7831 # ifdef FEAT_FKMAP
7832 p_altkeymap = 0;
7833 p_hkmap = 0;
7834 p_fkmap = 0;
7835 (void)init_chartab();
7836 # endif
7838 else
7841 * 'arabic' is reset, handle various sub-settings.
7843 if (!p_tbidi)
7845 /* reset rightleft mode */
7846 if (curwin->w_p_rl)
7848 curwin->w_p_rl = FALSE;
7849 changed_window_setting();
7852 /* 'arabicshape' isn't reset, it is a global option and
7853 * another window may still need it "on". */
7856 /* 'delcombine' isn't reset, it is a global option and another
7857 * window may still want it "on". */
7859 # ifdef FEAT_KEYMAP
7860 /* Revert to the default keymap */
7861 curbuf->b_p_iminsert = B_IMODE_NONE;
7862 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7863 # endif
7865 if (curwin->w_curswant != MAXCOL)
7866 curwin->w_set_curswant = TRUE;
7869 else if ((int *)varp == &p_arshape)
7871 if (curwin->w_curswant != MAXCOL)
7872 curwin->w_set_curswant = TRUE;
7874 #endif
7876 #ifdef FEAT_LINEBREAK
7877 if ((int *)varp == &curwin->w_p_lbr)
7879 if (curwin->w_curswant != MAXCOL)
7880 curwin->w_set_curswant = TRUE;
7882 #endif
7884 #ifdef FEAT_RIGHTLEFT
7885 if ((int *)varp == &curwin->w_p_rl)
7887 if (curwin->w_curswant != MAXCOL)
7888 curwin->w_set_curswant = TRUE;
7890 #endif
7893 * End of handling side effects for bool options.
7896 options[opt_idx].flags |= P_WAS_SET;
7898 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7900 check_redraw(options[opt_idx].flags);
7902 return NULL;
7906 * Set the value of a number option, and take care of side effects.
7907 * Returns NULL for success, or an error message for an error.
7909 static char_u *
7910 set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
7911 int opt_idx; /* index in options[] table */
7912 char_u *varp; /* pointer to the option variable */
7913 long value; /* new value */
7914 char_u *errbuf; /* buffer for error messages */
7915 size_t errbuflen; /* length of "errbuf" */
7916 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7917 OPT_MODELINE */
7919 char_u *errmsg = NULL;
7920 long old_value = *(long *)varp;
7921 long old_Rows = Rows; /* remember old Rows */
7922 long old_Columns = Columns; /* remember old Columns */
7923 long *pp = (long *)varp;
7925 /* Disallow changing some options from secure mode. */
7926 if ((secure
7927 #ifdef HAVE_SANDBOX
7928 || sandbox != 0
7929 #endif
7930 ) && (options[opt_idx].flags & P_SECURE))
7931 return e_secure;
7933 *pp = value;
7934 #ifdef FEAT_EVAL
7935 /* Remember where the option was set. */
7936 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
7937 #endif
7938 #ifdef FEAT_GUI
7939 need_mouse_correct = TRUE;
7940 #endif
7942 if (curbuf->b_p_sw <= 0)
7944 errmsg = e_positive;
7945 #ifdef FEAT_VARTABS
7946 /* Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use. */
7947 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_ary) > 0
7948 ? tabstop_first(curbuf->b_p_vts_ary)
7949 : curbuf->b_p_ts;
7950 #else
7951 curbuf->b_p_sw = curbuf->b_p_ts;
7952 #endif
7956 * Number options that need some action when changed
7958 #ifdef FEAT_WINDOWS
7959 if (pp == &p_wh || pp == &p_hh)
7961 if (p_wh < 1)
7963 errmsg = e_positive;
7964 p_wh = 1;
7966 if (p_wmh > p_wh)
7968 errmsg = e_winheight;
7969 p_wh = p_wmh;
7971 if (p_hh < 0)
7973 errmsg = e_positive;
7974 p_hh = 0;
7977 /* Change window height NOW */
7978 if (lastwin != firstwin)
7980 if (pp == &p_wh && curwin->w_height < p_wh)
7981 win_setheight((int)p_wh);
7982 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7983 win_setheight((int)p_hh);
7987 /* 'winminheight' */
7988 else if (pp == &p_wmh)
7990 if (p_wmh < 0)
7992 errmsg = e_positive;
7993 p_wmh = 0;
7995 if (p_wmh > p_wh)
7997 errmsg = e_winheight;
7998 p_wmh = p_wh;
8000 win_setminheight();
8003 # ifdef FEAT_VERTSPLIT
8004 else if (pp == &p_wiw)
8006 if (p_wiw < 1)
8008 errmsg = e_positive;
8009 p_wiw = 1;
8011 if (p_wmw > p_wiw)
8013 errmsg = e_winwidth;
8014 p_wiw = p_wmw;
8017 /* Change window width NOW */
8018 if (lastwin != firstwin && curwin->w_width < p_wiw)
8019 win_setwidth((int)p_wiw);
8022 /* 'winminwidth' */
8023 else if (pp == &p_wmw)
8025 if (p_wmw < 0)
8027 errmsg = e_positive;
8028 p_wmw = 0;
8030 if (p_wmw > p_wiw)
8032 errmsg = e_winwidth;
8033 p_wmw = p_wiw;
8035 win_setminheight();
8037 # endif
8039 #endif
8041 #ifdef FEAT_WINDOWS
8042 /* (re)set last window status line */
8043 else if (pp == &p_ls)
8045 last_status(FALSE);
8048 /* (re)set tab page line */
8049 else if (pp == &p_stal)
8051 shell_new_rows(); /* recompute window positions and heights */
8053 #endif
8055 #ifdef FEAT_GUI
8056 else if (pp == &p_linespace)
8058 /* Recompute gui.char_height and resize the Vim window to keep the
8059 * same number of lines. */
8060 if (gui.in_use && gui_mch_adjust_charheight() == OK)
8061 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
8063 #endif
8065 #ifdef FEAT_FOLDING
8066 /* 'foldlevel' */
8067 else if (pp == &curwin->w_p_fdl)
8069 if (curwin->w_p_fdl < 0)
8070 curwin->w_p_fdl = 0;
8071 newFoldLevel();
8074 /* 'foldminlines' */
8075 else if (pp == &curwin->w_p_fml)
8077 foldUpdateAll(curwin);
8080 /* 'foldnestmax' */
8081 else if (pp == &curwin->w_p_fdn)
8083 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8084 foldUpdateAll(curwin);
8087 /* 'foldcolumn' */
8088 else if (pp == &curwin->w_p_fdc)
8090 if (curwin->w_p_fdc < 0)
8092 errmsg = e_positive;
8093 curwin->w_p_fdc = 0;
8095 else if (curwin->w_p_fdc > 12)
8097 errmsg = e_invarg;
8098 curwin->w_p_fdc = 12;
8102 /* 'shiftwidth' or 'tabstop' */
8103 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8105 if (foldmethodIsIndent(curwin))
8106 foldUpdateAll(curwin);
8108 #endif /* FEAT_FOLDING */
8110 #ifdef FEAT_MBYTE
8111 /* 'maxcombine' */
8112 else if (pp == &p_mco)
8114 if (p_mco > MAX_MCO)
8115 p_mco = MAX_MCO;
8116 else if (p_mco < 0)
8117 p_mco = 0;
8118 screenclear(); /* will re-allocate the screen */
8120 #endif
8122 else if (pp == &curbuf->b_p_iminsert)
8124 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8126 errmsg = e_invarg;
8127 curbuf->b_p_iminsert = B_IMODE_NONE;
8129 p_iminsert = curbuf->b_p_iminsert;
8130 if (termcap_active) /* don't do this in the alternate screen */
8131 showmode();
8132 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8133 /* Show/unshow value of 'keymap' in status lines. */
8134 status_redraw_curbuf();
8135 #endif
8138 else if (pp == &p_window)
8140 if (p_window < 1)
8141 p_window = 1;
8142 else if (p_window >= Rows)
8143 p_window = Rows - 1;
8146 else if (pp == &curbuf->b_p_imsearch)
8148 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8150 errmsg = e_invarg;
8151 curbuf->b_p_imsearch = B_IMODE_NONE;
8153 p_imsearch = curbuf->b_p_imsearch;
8156 #ifdef FEAT_TITLE
8157 /* if 'titlelen' has changed, redraw the title */
8158 else if (pp == &p_titlelen)
8160 if (p_titlelen < 0)
8162 errmsg = e_positive;
8163 p_titlelen = 85;
8165 if (starting != NO_SCREEN && old_value != p_titlelen)
8166 need_maketitle = TRUE;
8168 #endif
8170 /* if p_ch changed value, change the command line height */
8171 else if (pp == &p_ch)
8173 if (p_ch < 1)
8175 errmsg = e_positive;
8176 p_ch = 1;
8178 if (p_ch > Rows - min_rows() + 1)
8179 p_ch = Rows - min_rows() + 1;
8181 /* Only compute the new window layout when startup has been
8182 * completed. Otherwise the frame sizes may be wrong. */
8183 if (p_ch != old_value && full_screen
8184 #ifdef FEAT_GUI
8185 && !gui.starting
8186 #endif
8188 command_height();
8191 /* when 'updatecount' changes from zero to non-zero, open swap files */
8192 else if (pp == &p_uc)
8194 if (p_uc < 0)
8196 errmsg = e_positive;
8197 p_uc = 100;
8199 if (p_uc && !old_value)
8200 ml_open_files();
8202 #ifdef MZSCHEME_GUI_THREADS
8203 else if (pp == &p_mzq)
8204 mzvim_reset_timer();
8205 #endif
8207 /* sync undo before 'undolevels' changes */
8208 else if (pp == &p_ul)
8210 /* use the old value, otherwise u_sync() may not work properly */
8211 p_ul = old_value;
8212 u_sync(TRUE);
8213 p_ul = value;
8216 #ifdef FEAT_LINEBREAK
8217 /* 'numberwidth' must be positive */
8218 else if (pp == &curwin->w_p_nuw)
8220 if (curwin->w_p_nuw < 1)
8222 errmsg = e_positive;
8223 curwin->w_p_nuw = 1;
8225 if (curwin->w_p_nuw > 10)
8227 errmsg = e_invarg;
8228 curwin->w_p_nuw = 10;
8230 curwin->w_nrwidth_line_count = 0;
8233 /* 'breakindentmin' must be positive */
8234 else if (pp == &curwin->w_p_brimin)
8236 if (curwin->w_p_brimin < 1)
8238 errmsg = e_positive;
8239 curwin->w_p_brimin = 1;
8242 #endif
8245 * Check the bounds for numeric options here
8247 if (Rows < min_rows() && full_screen)
8249 if (errbuf != NULL)
8251 vim_snprintf((char *)errbuf, errbuflen,
8252 _("E593: Need at least %d lines"), min_rows());
8253 errmsg = errbuf;
8255 Rows = min_rows();
8257 if (Columns < MIN_COLUMNS && full_screen)
8259 if (errbuf != NULL)
8261 vim_snprintf((char *)errbuf, errbuflen,
8262 _("E594: Need at least %d columns"), MIN_COLUMNS);
8263 errmsg = errbuf;
8265 Columns = MIN_COLUMNS;
8267 /* Limit the values to avoid an overflow in Rows * Columns. */
8268 if (Columns > 10000)
8269 Columns = 10000;
8270 if (Rows > 1000)
8271 Rows = 1000;
8273 #ifdef DJGPP
8274 /* avoid a crash by checking for a too large value of 'columns' */
8275 if (old_Columns != Columns && full_screen && term_console)
8276 mch_check_columns();
8277 #endif
8280 * If the screen (shell) height has been changed, assume it is the
8281 * physical screenheight.
8283 if (old_Rows != Rows || old_Columns != Columns)
8285 /* Changing the screen size is not allowed while updating the screen. */
8286 if (updating_screen)
8287 *pp = old_value;
8288 else if (full_screen
8289 #ifdef FEAT_GUI
8290 && !gui.starting
8291 #endif
8293 set_shellsize((int)Columns, (int)Rows, TRUE);
8294 else
8296 /* Postpone the resizing; check the size and cmdline position for
8297 * messages. */
8298 check_shellsize();
8299 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8300 cmdline_row = Rows - p_ch;
8302 if (p_window >= Rows || !option_was_set((char_u *)"window"))
8303 p_window = Rows - 1;
8306 if (curbuf->b_p_sts < 0)
8308 errmsg = e_positive;
8309 curbuf->b_p_sts = 0;
8311 if (curbuf->b_p_ts <= 0)
8313 errmsg = e_positive;
8314 curbuf->b_p_ts = 8;
8316 if (curbuf->b_p_tw < 0)
8318 errmsg = e_positive;
8319 curbuf->b_p_tw = 0;
8321 if (p_tm < 0)
8323 errmsg = e_positive;
8324 p_tm = 0;
8326 if ((curwin->w_p_scr <= 0
8327 || (curwin->w_p_scr > curwin->w_height
8328 && curwin->w_height > 0))
8329 && full_screen)
8331 if (pp == &(curwin->w_p_scr))
8333 if (curwin->w_p_scr != 0)
8334 errmsg = e_scroll;
8335 win_comp_scroll(curwin);
8337 /* If 'scroll' became invalid because of a side effect silently adjust
8338 * it. */
8339 else if (curwin->w_p_scr <= 0)
8340 curwin->w_p_scr = 1;
8341 else /* curwin->w_p_scr > curwin->w_height */
8342 curwin->w_p_scr = curwin->w_height;
8344 if (p_hi < 0)
8346 errmsg = e_positive;
8347 p_hi = 0;
8349 if (p_report < 0)
8351 errmsg = e_positive;
8352 p_report = 1;
8354 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
8356 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8357 p_sj = Rows / 2;
8358 else
8360 errmsg = e_scroll;
8361 p_sj = 1;
8364 if (p_so < 0 && full_screen)
8366 errmsg = e_scroll;
8367 p_so = 0;
8369 if (p_siso < 0 && full_screen)
8371 errmsg = e_positive;
8372 p_siso = 0;
8374 #ifdef FEAT_CMDWIN
8375 if (p_cwh < 1)
8377 errmsg = e_positive;
8378 p_cwh = 1;
8380 #endif
8381 if (p_ut < 0)
8383 errmsg = e_positive;
8384 p_ut = 2000;
8386 if (p_ss < 0)
8388 errmsg = e_positive;
8389 p_ss = 0;
8392 /* May set global value for local option. */
8393 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8394 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8396 options[opt_idx].flags |= P_WAS_SET;
8398 comp_col(); /* in case 'columns' or 'ls' changed */
8399 if (curwin->w_curswant != MAXCOL)
8400 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8401 check_redraw(options[opt_idx].flags);
8403 return errmsg;
8407 * Called after an option changed: check if something needs to be redrawn.
8409 static void
8410 check_redraw(flags)
8411 long_u flags;
8413 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8414 int clear = (flags & P_RCLR) == P_RCLR;
8415 int all = ((flags & P_RALL) == P_RALL || clear);
8417 #ifdef FEAT_WINDOWS
8418 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8419 status_redraw_all();
8420 #endif
8422 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8423 changed_window_setting();
8424 if (flags & P_RBUF)
8425 redraw_curbuf_later(NOT_VALID);
8426 if (clear)
8427 redraw_all_later(CLEAR);
8428 else if (all)
8429 redraw_all_later(NOT_VALID);
8433 * Find index for option 'arg'.
8434 * Return -1 if not found.
8436 static int
8437 findoption(arg)
8438 char_u *arg;
8440 int opt_idx;
8441 char *s, *p;
8442 static short quick_tab[27] = {0, 0}; /* quick access table */
8443 int is_term_opt;
8446 * For first call: Initialize the quick-access table.
8447 * It contains the index for the first option that starts with a certain
8448 * letter. There are 26 letters, plus the first "t_" option.
8450 if (quick_tab[1] == 0)
8452 p = options[0].fullname;
8453 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8455 if (s[0] != p[0])
8457 if (s[0] == 't' && s[1] == '_')
8458 quick_tab[26] = opt_idx;
8459 else
8460 quick_tab[CharOrdLow(s[0])] = opt_idx;
8462 p = s;
8467 * Check for name starting with an illegal character.
8469 #ifdef EBCDIC
8470 if (!islower(arg[0]))
8471 #else
8472 if (arg[0] < 'a' || arg[0] > 'z')
8473 #endif
8474 return -1;
8476 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8477 if (is_term_opt)
8478 opt_idx = quick_tab[26];
8479 else
8480 opt_idx = quick_tab[CharOrdLow(arg[0])];
8481 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8483 if (STRCMP(arg, s) == 0) /* match full name */
8484 break;
8486 if (s == NULL && !is_term_opt)
8488 opt_idx = quick_tab[CharOrdLow(arg[0])];
8489 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8491 s = options[opt_idx].shortname;
8492 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8493 break;
8494 s = NULL;
8497 if (s == NULL)
8498 opt_idx = -1;
8499 return opt_idx;
8502 #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
8504 * Get the value for an option.
8506 * Returns:
8507 * Number or Toggle option: 1, *numval gets value.
8508 * String option: 0, *stringval gets allocated string.
8509 * Hidden Number or Toggle option: -1.
8510 * hidden String option: -2.
8511 * unknown option: -3.
8514 get_option_value(name, numval, stringval, opt_flags)
8515 char_u *name;
8516 long *numval;
8517 char_u **stringval; /* NULL when only checking existance */
8518 int opt_flags;
8520 int opt_idx;
8521 char_u *varp;
8523 opt_idx = findoption(name);
8524 if (opt_idx < 0) /* unknown option */
8525 return -3;
8527 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8529 if (options[opt_idx].flags & P_STRING)
8531 if (varp == NULL) /* hidden option */
8532 return -2;
8533 if (stringval != NULL)
8535 #ifdef FEAT_CRYPT
8536 /* never return the value of the crypt key */
8537 if ((char_u **)varp == &curbuf->b_p_key
8538 && **(char_u **)(varp) != NUL)
8539 *stringval = vim_strsave((char_u *)"*****");
8540 else
8541 #endif
8542 *stringval = vim_strsave(*(char_u **)(varp));
8544 return 0;
8547 if (varp == NULL) /* hidden option */
8548 return -1;
8549 if (options[opt_idx].flags & P_NUM)
8550 *numval = *(long *)varp;
8551 else
8553 /* Special case: 'modified' is b_changed, but we also want to consider
8554 * it set when 'ff' or 'fenc' changed. */
8555 if ((int *)varp == &curbuf->b_changed)
8556 *numval = curbufIsChanged();
8557 else
8558 *numval = *(int *)varp;
8560 return 1;
8562 #endif
8565 * Set the value of option "name".
8566 * Use "string" for string options, use "number" for other options.
8568 void
8569 set_option_value(name, number, string, opt_flags)
8570 char_u *name;
8571 long number;
8572 char_u *string;
8573 int opt_flags; /* OPT_LOCAL or 0 (both) */
8575 int opt_idx;
8576 char_u *varp;
8577 long_u flags;
8579 opt_idx = findoption(name);
8580 if (opt_idx < 0)
8581 EMSG2(_("E355: Unknown option: %s"), name);
8582 else
8584 flags = options[opt_idx].flags;
8585 #ifdef HAVE_SANDBOX
8586 /* Disallow changing some options in the sandbox */
8587 if (sandbox > 0 && (flags & P_SECURE))
8589 EMSG(_(e_sandbox));
8590 return;
8592 #endif
8593 if (flags & P_STRING)
8594 set_string_option(opt_idx, string, opt_flags);
8595 else
8597 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8598 if (varp != NULL) /* hidden option is not changed */
8600 if (number == 0 && string != NULL)
8602 int idx;
8604 /* Either we are given a string or we are setting option
8605 * to zero. */
8606 for (idx = 0; string[idx] == '0'; ++idx)
8608 if (string[idx] != NUL || idx == 0)
8610 /* There's another character after zeros or the string
8611 * is empty. In both cases, we are trying to set a
8612 * num option using a string. */
8613 EMSG3(_("E521: Number required: &%s = '%s'"),
8614 name, string);
8615 return; /* do nothing as we hit an error */
8619 if (flags & P_NUM)
8620 (void)set_num_option(opt_idx, varp, number,
8621 NULL, 0, opt_flags);
8622 else
8623 (void)set_bool_option(opt_idx, varp, (int)number,
8624 opt_flags);
8631 * Get the terminal code for a terminal option.
8632 * Returns NULL when not found.
8634 char_u *
8635 get_term_code(tname)
8636 char_u *tname;
8638 int opt_idx;
8639 char_u *varp;
8641 if (tname[0] != 't' || tname[1] != '_' ||
8642 tname[2] == NUL || tname[3] == NUL)
8643 return NULL;
8644 if ((opt_idx = findoption(tname)) >= 0)
8646 varp = get_varp(&(options[opt_idx]));
8647 if (varp != NULL)
8648 varp = *(char_u **)(varp);
8649 return varp;
8651 return find_termcode(tname + 2);
8654 char_u *
8655 get_highlight_default()
8657 int i;
8659 i = findoption((char_u *)"hl");
8660 if (i >= 0)
8661 return options[i].def_val[VI_DEFAULT];
8662 return (char_u *)NULL;
8665 #if defined(FEAT_MBYTE) || defined(PROTO)
8666 char_u *
8667 get_encoding_default()
8669 int i;
8671 i = findoption((char_u *)"enc");
8672 if (i >= 0)
8673 return options[i].def_val[VI_DEFAULT];
8674 return (char_u *)NULL;
8676 #endif
8679 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8681 static int
8682 find_key_option(arg)
8683 char_u *arg;
8685 int key;
8686 int modifiers;
8689 * Don't use get_special_key_code() for t_xx, we don't want it to call
8690 * add_termcap_entry().
8692 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8693 key = TERMCAP2KEY(arg[2], arg[3]);
8694 else
8696 --arg; /* put arg at the '<' */
8697 modifiers = 0;
8698 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
8699 if (modifiers) /* can't handle modifiers here */
8700 key = 0;
8702 return key;
8706 * if 'all' == 0: show changed options
8707 * if 'all' == 1: show all normal options
8708 * if 'all' == 2: show all terminal options
8710 static void
8711 showoptions(all, opt_flags)
8712 int all;
8713 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8715 struct vimoption *p;
8716 int col;
8717 int isterm;
8718 char_u *varp;
8719 struct vimoption **items;
8720 int item_count;
8721 int run;
8722 int row, rows;
8723 int cols;
8724 int i;
8725 int len;
8727 #define INC 20
8728 #define GAP 3
8730 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8731 PARAM_COUNT));
8732 if (items == NULL)
8733 return;
8735 /* Highlight title */
8736 if (all == 2)
8737 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8738 else if (opt_flags & OPT_GLOBAL)
8739 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8740 else if (opt_flags & OPT_LOCAL)
8741 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8742 else
8743 MSG_PUTS_TITLE(_("\n--- Options ---"));
8746 * do the loop two times:
8747 * 1. display the short items
8748 * 2. display the long items (only strings and numbers)
8750 for (run = 1; run <= 2 && !got_int; ++run)
8753 * collect the items in items[]
8755 item_count = 0;
8756 for (p = &options[0]; p->fullname != NULL; p++)
8758 varp = NULL;
8759 isterm = istermoption(p);
8760 if (opt_flags != 0)
8762 if (p->indir != PV_NONE && !isterm)
8763 varp = get_varp_scope(p, opt_flags);
8765 else
8766 varp = get_varp(p);
8767 if (varp != NULL
8768 && ((all == 2 && isterm)
8769 || (all == 1 && !isterm)
8770 || (all == 0 && !optval_default(p, varp))))
8772 if (p->flags & P_BOOL)
8773 len = 1; /* a toggle option fits always */
8774 else
8776 option_value2string(p, opt_flags);
8777 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8779 if ((len <= INC - GAP && run == 1) ||
8780 (len > INC - GAP && run == 2))
8781 items[item_count++] = p;
8786 * display the items
8788 if (run == 1)
8790 cols = (Columns + GAP - 3) / INC;
8791 if (cols == 0)
8792 cols = 1;
8793 rows = (item_count + cols - 1) / cols;
8795 else /* run == 2 */
8796 rows = item_count;
8797 for (row = 0; row < rows && !got_int; ++row)
8799 msg_putchar('\n'); /* go to next line */
8800 if (got_int) /* 'q' typed in more */
8801 break;
8802 col = 0;
8803 for (i = row; i < item_count; i += rows)
8805 msg_col = col; /* make columns */
8806 showoneopt(items[i], opt_flags);
8807 col += INC;
8809 out_flush();
8810 ui_breakcheck();
8813 vim_free(items);
8817 * Return TRUE if option "p" has its default value.
8819 static int
8820 optval_default(p, varp)
8821 struct vimoption *p;
8822 char_u *varp;
8824 int dvi;
8826 if (varp == NULL)
8827 return TRUE; /* hidden option is always at default */
8828 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8829 if (p->flags & P_NUM)
8830 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
8831 if (p->flags & P_BOOL)
8832 /* the cast to long is required for Manx C, long_i is
8833 * needed for MSVC */
8834 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
8835 /* P_STRING */
8836 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8840 * showoneopt: show the value of one option
8841 * must not be called with a hidden option!
8843 static void
8844 showoneopt(p, opt_flags)
8845 struct vimoption *p;
8846 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8848 char_u *varp;
8849 int save_silent = silent_mode;
8851 silent_mode = FALSE;
8852 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
8854 varp = get_varp_scope(p, opt_flags);
8856 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8857 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8858 ? !curbufIsChanged() : !*(int *)varp))
8859 MSG_PUTS("no");
8860 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8861 MSG_PUTS("--");
8862 else
8863 MSG_PUTS(" ");
8864 MSG_PUTS(p->fullname);
8865 if (!(p->flags & P_BOOL))
8867 msg_putchar('=');
8868 /* put value string in NameBuff */
8869 option_value2string(p, opt_flags);
8870 msg_outtrans(NameBuff);
8873 silent_mode = save_silent;
8874 info_message = FALSE;
8878 * Write modified options as ":set" commands to a file.
8880 * There are three values for "opt_flags":
8881 * OPT_GLOBAL: Write global option values and fresh values of
8882 * buffer-local options (used for start of a session
8883 * file).
8884 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8885 * curwin (used for a vimrc file).
8886 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8887 * and local values for window-local options of
8888 * curwin. Local values are also written when at the
8889 * default value, because a modeline or autocommand
8890 * may have set them when doing ":edit file" and the
8891 * user has set them back at the default or fresh
8892 * value.
8893 * When "local_only" is TRUE, don't write fresh
8894 * values, only local values (for ":mkview").
8895 * (fresh value = value used for a new buffer or window for a local option).
8897 * Return FAIL on error, OK otherwise.
8900 makeset(fd, opt_flags, local_only)
8901 FILE *fd;
8902 int opt_flags;
8903 int local_only;
8905 struct vimoption *p;
8906 char_u *varp; /* currently used value */
8907 char_u *varp_fresh; /* local value */
8908 char_u *varp_local = NULL; /* fresh value */
8909 char *cmd;
8910 int round;
8911 int pri;
8914 * The options that don't have a default (terminal name, columns, lines)
8915 * are never written. Terminal options are also not written.
8916 * Do the loop over "options[]" twice: once for options with the
8917 * P_PRI_MKRC flag and once without.
8919 for (pri = 1; pri >= 0; --pri)
8921 for (p = &options[0]; !istermoption(p); p++)
8922 if (!(p->flags & P_NO_MKRC)
8923 && !istermoption(p)
8924 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
8926 /* skip global option when only doing locals */
8927 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8928 continue;
8930 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8931 * file, they are always buffer-specific. */
8932 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8933 continue;
8935 /* Global values are only written when not at the default value. */
8936 varp = get_varp_scope(p, opt_flags);
8937 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8938 continue;
8940 round = 2;
8941 if (p->indir != PV_NONE)
8943 if (p->var == VAR_WIN)
8945 /* skip window-local option when only doing globals */
8946 if (!(opt_flags & OPT_LOCAL))
8947 continue;
8948 /* When fresh value of window-local option is not at the
8949 * default, need to write it too. */
8950 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8952 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8953 if (!optval_default(p, varp_fresh))
8955 round = 1;
8956 varp_local = varp;
8957 varp = varp_fresh;
8963 /* Round 1: fresh value for window-local options.
8964 * Round 2: other values */
8965 for ( ; round <= 2; varp = varp_local, ++round)
8967 if (round == 1 || (opt_flags & OPT_GLOBAL))
8968 cmd = "set";
8969 else
8970 cmd = "setlocal";
8972 if (p->flags & P_BOOL)
8974 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8975 return FAIL;
8977 else if (p->flags & P_NUM)
8979 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8980 return FAIL;
8982 else /* P_STRING */
8984 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8985 int do_endif = FALSE;
8987 /* Don't set 'syntax' and 'filetype' again if the value is
8988 * already right, avoids reloading the syntax file. */
8989 if (
8990 # if defined(FEAT_SYN_HL)
8991 p->indir == PV_SYN
8992 # if defined(FEAT_AUTOCMD)
8994 # endif
8995 # endif
8996 # if defined(FEAT_AUTOCMD)
8997 p->indir == PV_FT
8998 # endif
9001 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9002 *(char_u **)(varp)) < 0
9003 || put_eol(fd) < 0)
9004 return FAIL;
9005 do_endif = TRUE;
9007 #endif
9008 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9009 (p->flags & P_EXPAND) != 0) == FAIL)
9010 return FAIL;
9011 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9012 if (do_endif)
9014 if (put_line(fd, "endif") == FAIL)
9015 return FAIL;
9017 #endif
9022 return OK;
9025 #if defined(FEAT_FOLDING) || defined(PROTO)
9027 * Generate set commands for the local fold options only. Used when
9028 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9031 makefoldset(fd)
9032 FILE *fd;
9034 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9035 # ifdef FEAT_EVAL
9036 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9037 == FAIL
9038 # endif
9039 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9040 == FAIL
9041 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9042 == FAIL
9043 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9044 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9045 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9046 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9048 return FAIL;
9050 return OK;
9052 #endif
9054 static int
9055 put_setstring(fd, cmd, name, valuep, expand)
9056 FILE *fd;
9057 char *cmd;
9058 char *name;
9059 char_u **valuep;
9060 int expand;
9062 char_u *s;
9063 char_u buf[MAXPATHL];
9065 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9066 return FAIL;
9067 if (*valuep != NULL)
9069 /* Output 'pastetoggle' as key names. For other
9070 * options some characters have to be escaped with
9071 * CTRL-V or backslash */
9072 if (valuep == &p_pt)
9074 s = *valuep;
9075 while (*s != NUL)
9076 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
9077 return FAIL;
9079 else if (expand)
9081 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9082 if (put_escstr(fd, buf, 2) == FAIL)
9083 return FAIL;
9085 else if (put_escstr(fd, *valuep, 2) == FAIL)
9086 return FAIL;
9088 if (put_eol(fd) < 0)
9089 return FAIL;
9090 return OK;
9093 static int
9094 put_setnum(fd, cmd, name, valuep)
9095 FILE *fd;
9096 char *cmd;
9097 char *name;
9098 long *valuep;
9100 long wc;
9102 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9103 return FAIL;
9104 if (wc_use_keyname((char_u *)valuep, &wc))
9106 /* print 'wildchar' and 'wildcharm' as a key name */
9107 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9108 return FAIL;
9110 else if (fprintf(fd, "%ld", *valuep) < 0)
9111 return FAIL;
9112 if (put_eol(fd) < 0)
9113 return FAIL;
9114 return OK;
9117 static int
9118 put_setbool(fd, cmd, name, value)
9119 FILE *fd;
9120 char *cmd;
9121 char *name;
9122 int value;
9124 if (value < 0) /* global/local option using global value */
9125 return OK;
9126 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9127 || put_eol(fd) < 0)
9128 return FAIL;
9129 return OK;
9133 * Clear all the terminal options.
9134 * If the option has been allocated, free the memory.
9135 * Terminal options are never hidden or indirect.
9137 void
9138 clear_termoptions()
9141 * Reset a few things before clearing the old options. This may cause
9142 * outputting a few things that the terminal doesn't understand, but the
9143 * screen will be cleared later, so this is OK.
9145 #ifdef FEAT_MOUSE_TTY
9146 mch_setmouse(FALSE); /* switch mouse off */
9147 #endif
9148 #ifdef FEAT_TITLE
9149 mch_restore_title(3); /* restore window titles */
9150 #endif
9151 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9152 /* When starting the GUI close the display opened for the clipboard.
9153 * After restoring the title, because that will need the display. */
9154 if (gui.starting)
9155 clear_xterm_clip();
9156 #endif
9157 #ifdef WIN3264
9159 * Check if this is allowed now.
9161 if (can_end_termcap_mode(FALSE) == TRUE)
9162 #endif
9163 stoptermcap(); /* stop termcap mode */
9165 free_termoptions();
9168 void
9169 free_termoptions()
9171 struct vimoption *p;
9173 for (p = &options[0]; p->fullname != NULL; p++)
9174 if (istermoption(p))
9176 if (p->flags & P_ALLOCED)
9177 free_string_option(*(char_u **)(p->var));
9178 if (p->flags & P_DEF_ALLOCED)
9179 free_string_option(p->def_val[VI_DEFAULT]);
9180 *(char_u **)(p->var) = empty_option;
9181 p->def_val[VI_DEFAULT] = empty_option;
9182 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9184 clear_termcodes();
9188 * Free the string for one term option, if it was allocated.
9189 * Set the string to empty_option and clear allocated flag.
9190 * "var" points to the option value.
9192 void
9193 free_one_termoption(var)
9194 char_u *var;
9196 struct vimoption *p;
9198 for (p = &options[0]; p->fullname != NULL; p++)
9199 if (p->var == var)
9201 if (p->flags & P_ALLOCED)
9202 free_string_option(*(char_u **)(p->var));
9203 *(char_u **)(p->var) = empty_option;
9204 p->flags &= ~P_ALLOCED;
9205 break;
9210 * Set the terminal option defaults to the current value.
9211 * Used after setting the terminal name.
9213 void
9214 set_term_defaults()
9216 struct vimoption *p;
9218 for (p = &options[0]; p->fullname != NULL; p++)
9220 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9222 if (p->flags & P_DEF_ALLOCED)
9224 free_string_option(p->def_val[VI_DEFAULT]);
9225 p->flags &= ~P_DEF_ALLOCED;
9227 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9228 if (p->flags & P_ALLOCED)
9230 p->flags |= P_DEF_ALLOCED;
9231 p->flags &= ~P_ALLOCED; /* don't free the value now */
9238 * return TRUE if 'p' starts with 't_'
9240 static int
9241 istermoption(p)
9242 struct vimoption *p;
9244 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9248 * Compute columns for ruler and shown command. 'sc_col' is also used to
9249 * decide what the maximum length of a message on the status line can be.
9250 * If there is a status line for the last window, 'sc_col' is independent
9251 * of 'ru_col'.
9254 #define COL_RULER 17 /* columns needed by standard ruler */
9256 void
9257 comp_col()
9259 #if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9260 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9262 sc_col = 0;
9263 ru_col = 0;
9264 if (p_ru)
9266 #ifdef FEAT_STL_OPT
9267 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9268 #else
9269 ru_col = COL_RULER + 1;
9270 #endif
9271 /* no last status line, adjust sc_col */
9272 if (!last_has_status)
9273 sc_col = ru_col;
9275 if (p_sc)
9277 sc_col += SHOWCMD_COLS;
9278 if (!p_ru || last_has_status) /* no need for separating space */
9279 ++sc_col;
9281 sc_col = Columns - sc_col;
9282 ru_col = Columns - ru_col;
9283 if (sc_col <= 0) /* screen too narrow, will become a mess */
9284 sc_col = 1;
9285 if (ru_col <= 0)
9286 ru_col = 1;
9287 #else
9288 sc_col = Columns;
9289 ru_col = Columns;
9290 #endif
9294 * Get pointer to option variable, depending on local or global scope.
9296 static char_u *
9297 get_varp_scope(p, opt_flags)
9298 struct vimoption *p;
9299 int opt_flags;
9301 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9303 if (p->var == VAR_WIN)
9304 return (char_u *)GLOBAL_WO(get_varp(p));
9305 return p->var;
9307 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
9309 switch ((int)p->indir)
9311 #ifdef FEAT_QUICKFIX
9312 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9313 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9314 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
9315 #endif
9316 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9317 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9318 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
9319 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
9320 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
9321 #ifdef FEAT_FIND_ID
9322 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9323 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
9324 #endif
9325 #ifdef FEAT_INS_EXPAND
9326 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9327 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
9328 #endif
9329 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9330 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9331 #endif
9332 #ifdef FEAT_STL_OPT
9333 case PV_STL: return (char_u *)&(curwin->w_p_stl);
9334 #endif
9336 return NULL; /* "cannot happen" */
9338 return get_varp(p);
9342 * Get pointer to option variable.
9344 static char_u *
9345 get_varp(p)
9346 struct vimoption *p;
9348 /* hidden option, always return NULL */
9349 if (p->var == NULL)
9350 return NULL;
9352 switch ((int)p->indir)
9354 case PV_NONE: return p->var;
9356 /* global option with local value: use local value if it's been set */
9357 case PV_EP: return *curbuf->b_p_ep != NUL
9358 ? (char_u *)&curbuf->b_p_ep : p->var;
9359 case PV_KP: return *curbuf->b_p_kp != NUL
9360 ? (char_u *)&curbuf->b_p_kp : p->var;
9361 case PV_PATH: return *curbuf->b_p_path != NUL
9362 ? (char_u *)&(curbuf->b_p_path) : p->var;
9363 case PV_AR: return curbuf->b_p_ar >= 0
9364 ? (char_u *)&(curbuf->b_p_ar) : p->var;
9365 case PV_TAGS: return *curbuf->b_p_tags != NUL
9366 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9367 #ifdef FEAT_FIND_ID
9368 case PV_DEF: return *curbuf->b_p_def != NUL
9369 ? (char_u *)&(curbuf->b_p_def) : p->var;
9370 case PV_INC: return *curbuf->b_p_inc != NUL
9371 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9372 #endif
9373 #ifdef FEAT_INS_EXPAND
9374 case PV_DICT: return *curbuf->b_p_dict != NUL
9375 ? (char_u *)&(curbuf->b_p_dict) : p->var;
9376 case PV_TSR: return *curbuf->b_p_tsr != NUL
9377 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9378 #endif
9379 #ifdef FEAT_QUICKFIX
9380 case PV_EFM: return *curbuf->b_p_efm != NUL
9381 ? (char_u *)&(curbuf->b_p_efm) : p->var;
9382 case PV_GP: return *curbuf->b_p_gp != NUL
9383 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9384 case PV_MP: return *curbuf->b_p_mp != NUL
9385 ? (char_u *)&(curbuf->b_p_mp) : p->var;
9386 #endif
9387 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9388 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9389 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9390 #endif
9391 #ifdef FEAT_STL_OPT
9392 case PV_STL: return *curwin->w_p_stl != NUL
9393 ? (char_u *)&(curwin->w_p_stl) : p->var;
9394 #endif
9396 #ifdef FEAT_ARABIC
9397 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9398 #endif
9399 case PV_LIST: return (char_u *)&(curwin->w_p_list);
9400 #ifdef FEAT_SPELL
9401 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9402 #endif
9403 #ifdef FEAT_SYN_HL
9404 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9405 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9406 #endif
9407 #ifdef FEAT_DIFF
9408 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9409 #endif
9410 #ifdef FEAT_FOLDING
9411 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9412 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9413 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9414 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9415 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9416 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9417 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9418 # ifdef FEAT_EVAL
9419 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9420 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9421 # endif
9422 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9423 #endif
9424 case PV_NU: return (char_u *)&(curwin->w_p_nu);
9425 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
9426 #ifdef FEAT_LINEBREAK
9427 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9428 #endif
9429 #ifdef FEAT_WINDOWS
9430 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9431 #endif
9432 #ifdef FEAT_VERTSPLIT
9433 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9434 #endif
9435 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9436 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9437 #endif
9438 #ifdef FEAT_RIGHTLEFT
9439 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9440 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9441 #endif
9442 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9443 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9444 #ifdef FEAT_LINEBREAK
9445 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9446 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
9447 case PV_BRIMIN: return (char_u *)&(curwin->w_p_brimin);
9448 case PV_BRISHIFT: return (char_u *)&(curwin->w_p_brishift);
9449 #endif
9450 #ifdef FEAT_SCROLLBIND
9451 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9452 #endif
9454 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9455 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9456 #ifdef FEAT_MBYTE
9457 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9458 #endif
9459 #if defined(FEAT_QUICKFIX)
9460 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9461 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9462 #endif
9463 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9464 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9465 #ifdef FEAT_CINDENT
9466 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9467 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9468 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9469 #endif
9470 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9471 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9472 #endif
9473 #ifdef FEAT_COMMENTS
9474 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9475 #endif
9476 #ifdef FEAT_FOLDING
9477 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9478 #endif
9479 #ifdef FEAT_INS_EXPAND
9480 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9481 #endif
9482 #ifdef FEAT_COMPL_FUNC
9483 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
9484 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
9485 #endif
9486 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9487 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9488 #ifdef FEAT_MBYTE
9489 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9490 #endif
9491 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9492 #ifdef FEAT_AUTOCMD
9493 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9494 #endif
9495 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
9496 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
9497 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9498 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9499 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9500 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9501 #ifdef FEAT_FIND_ID
9502 # ifdef FEAT_EVAL
9503 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9504 # endif
9505 #endif
9506 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9507 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9508 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9509 #endif
9510 #ifdef FEAT_EVAL
9511 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9512 #endif
9513 #ifdef FEAT_CRYPT
9514 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9515 #endif
9516 #ifdef FEAT_LISP
9517 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9518 #endif
9519 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9520 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9521 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9522 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9523 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9524 #ifdef FEAT_OSFILETYPE
9525 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9526 #endif
9527 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
9528 #ifdef FEAT_TEXTOBJ
9529 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9530 #endif
9531 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9532 #ifdef FEAT_SMARTINDENT
9533 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9534 #endif
9535 #ifndef SHORT_FNAME
9536 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9537 #endif
9538 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9539 #ifdef FEAT_SEARCHPATH
9540 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9541 #endif
9542 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9543 #ifdef FEAT_SYN_HL
9544 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
9545 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9546 #endif
9547 #ifdef FEAT_SPELL
9548 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
9549 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
9550 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
9551 #endif
9552 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9553 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9554 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9555 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9556 #ifdef FEAT_PERSISTENT_UNDO
9557 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9558 #endif
9559 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9560 #ifdef FEAT_KEYMAP
9561 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9562 #endif
9563 #ifdef FEAT_VARTABS
9564 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
9565 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
9566 #endif
9567 default: EMSG(_("E356: get_varp ERROR"));
9569 /* always return a valid pointer to avoid a crash! */
9570 return (char_u *)&(curbuf->b_p_wm);
9574 * Get the value of 'equalprg', either the buffer-local one or the global one.
9576 char_u *
9577 get_equalprg()
9579 if (*curbuf->b_p_ep == NUL)
9580 return p_ep;
9581 return curbuf->b_p_ep;
9584 #if defined(FEAT_WINDOWS) || defined(PROTO)
9586 * Copy options from one window to another.
9587 * Used when splitting a window.
9589 void
9590 win_copy_options(wp_from, wp_to)
9591 win_T *wp_from;
9592 win_T *wp_to;
9594 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9595 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9596 # ifdef FEAT_RIGHTLEFT
9597 # ifdef FEAT_FKMAP
9598 /* Is this right? */
9599 wp_to->w_farsi = wp_from->w_farsi;
9600 # endif
9601 # endif
9603 #endif
9606 * Copy the options from one winopt_T to another.
9607 * Doesn't free the old option values in "to", use clear_winopt() for that.
9608 * The 'scroll' option is not copied, because it depends on the window height.
9609 * The 'previewwindow' option is reset, there can be only one preview window.
9611 void
9612 copy_winopt(from, to)
9613 winopt_T *from;
9614 winopt_T *to;
9616 #ifdef FEAT_ARABIC
9617 to->wo_arab = from->wo_arab;
9618 #endif
9619 to->wo_list = from->wo_list;
9620 to->wo_nu = from->wo_nu;
9621 to->wo_rnu = from->wo_rnu;
9622 #ifdef FEAT_LINEBREAK
9623 to->wo_nuw = from->wo_nuw;
9624 #endif
9625 #ifdef FEAT_RIGHTLEFT
9626 to->wo_rl = from->wo_rl;
9627 to->wo_rlc = vim_strsave(from->wo_rlc);
9628 #endif
9629 #ifdef FEAT_STL_OPT
9630 to->wo_stl = vim_strsave(from->wo_stl);
9631 #endif
9632 to->wo_wrap = from->wo_wrap;
9633 #ifdef FEAT_LINEBREAK
9634 to->wo_lbr = from->wo_lbr;
9635 to->wo_bri = from->wo_bri;
9636 to->wo_brimin = from->wo_brimin;
9637 #endif
9638 #ifdef FEAT_SCROLLBIND
9639 to->wo_scb = from->wo_scb;
9640 #endif
9641 #ifdef FEAT_SPELL
9642 to->wo_spell = from->wo_spell;
9643 #endif
9644 #ifdef FEAT_SYN_HL
9645 to->wo_cuc = from->wo_cuc;
9646 to->wo_cul = from->wo_cul;
9647 #endif
9648 #ifdef FEAT_DIFF
9649 to->wo_diff = from->wo_diff;
9650 #endif
9651 #ifdef FEAT_FOLDING
9652 to->wo_fdc = from->wo_fdc;
9653 to->wo_fen = from->wo_fen;
9654 to->wo_fdi = vim_strsave(from->wo_fdi);
9655 to->wo_fml = from->wo_fml;
9656 to->wo_fdl = from->wo_fdl;
9657 to->wo_fdm = vim_strsave(from->wo_fdm);
9658 to->wo_fdn = from->wo_fdn;
9659 # ifdef FEAT_EVAL
9660 to->wo_fde = vim_strsave(from->wo_fde);
9661 to->wo_fdt = vim_strsave(from->wo_fdt);
9662 # endif
9663 to->wo_fmr = vim_strsave(from->wo_fmr);
9664 #endif
9665 check_winopt(to); /* don't want NULL pointers */
9669 * Check string options in a window for a NULL value.
9671 void
9672 check_win_options(win)
9673 win_T *win;
9675 check_winopt(&win->w_onebuf_opt);
9676 check_winopt(&win->w_allbuf_opt);
9680 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9682 void
9683 check_winopt(wop)
9684 winopt_T *wop UNUSED;
9686 #ifdef FEAT_FOLDING
9687 check_string_option(&wop->wo_fdi);
9688 check_string_option(&wop->wo_fdm);
9689 # ifdef FEAT_EVAL
9690 check_string_option(&wop->wo_fde);
9691 check_string_option(&wop->wo_fdt);
9692 # endif
9693 check_string_option(&wop->wo_fmr);
9694 #endif
9695 #ifdef FEAT_RIGHTLEFT
9696 check_string_option(&wop->wo_rlc);
9697 #endif
9698 #ifdef FEAT_STL_OPT
9699 check_string_option(&wop->wo_stl);
9700 #endif
9704 * Free the allocated memory inside a winopt_T.
9706 void
9707 clear_winopt(wop)
9708 winopt_T *wop UNUSED;
9710 #ifdef FEAT_FOLDING
9711 clear_string_option(&wop->wo_fdi);
9712 clear_string_option(&wop->wo_fdm);
9713 # ifdef FEAT_EVAL
9714 clear_string_option(&wop->wo_fde);
9715 clear_string_option(&wop->wo_fdt);
9716 # endif
9717 clear_string_option(&wop->wo_fmr);
9718 #endif
9719 #ifdef FEAT_RIGHTLEFT
9720 clear_string_option(&wop->wo_rlc);
9721 #endif
9722 #ifdef FEAT_STL_OPT
9723 clear_string_option(&wop->wo_stl);
9724 #endif
9728 * Copy global option values to local options for one buffer.
9729 * Used when creating a new buffer and sometimes when entering a buffer.
9730 * flags:
9731 * BCO_ENTER We will enter the buf buffer.
9732 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9733 * appropriate.
9734 * BCO_NOHELP Don't copy the values to a help buffer.
9736 void
9737 buf_copy_options(buf, flags)
9738 buf_T *buf;
9739 int flags;
9741 int should_copy = TRUE;
9742 char_u *save_p_isk = NULL; /* init for GCC */
9743 int dont_do_help;
9744 int did_isk = FALSE;
9747 * Don't do anything of the buffer is invalid.
9749 if (buf == NULL || !buf_valid(buf))
9750 return;
9753 * Skip this when the option defaults have not been set yet. Happens when
9754 * main() allocates the first buffer.
9756 if (p_cpo != NULL)
9759 * Always copy when entering and 'cpo' contains 'S'.
9760 * Don't copy when already initialized.
9761 * Don't copy when 'cpo' contains 's' and not entering.
9762 * 'S' BCO_ENTER initialized 's' should_copy
9763 * yes yes X X TRUE
9764 * yes no yes X FALSE
9765 * no X yes X FALSE
9766 * X no no yes FALSE
9767 * X no no no TRUE
9768 * no yes no X TRUE
9770 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9771 && (buf->b_p_initialized
9772 || (!(flags & BCO_ENTER)
9773 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9774 should_copy = FALSE;
9776 if (should_copy || (flags & BCO_ALWAYS))
9778 /* Don't copy the options specific to a help buffer when
9779 * BCO_NOHELP is given or the options were initialized already
9780 * (jumping back to a help file with CTRL-T or CTRL-O) */
9781 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9782 || buf->b_p_initialized;
9783 if (dont_do_help) /* don't free b_p_isk */
9785 save_p_isk = buf->b_p_isk;
9786 buf->b_p_isk = NULL;
9789 * Always free the allocated strings.
9790 * If not already initialized, set 'readonly' and copy 'fileformat'.
9792 if (!buf->b_p_initialized)
9794 free_buf_options(buf, TRUE);
9795 buf->b_p_ro = FALSE; /* don't copy readonly */
9796 buf->b_p_tx = p_tx;
9797 #ifdef FEAT_MBYTE
9798 buf->b_p_fenc = vim_strsave(p_fenc);
9799 #endif
9800 buf->b_p_ff = vim_strsave(p_ff);
9801 #if defined(FEAT_QUICKFIX)
9802 buf->b_p_bh = empty_option;
9803 buf->b_p_bt = empty_option;
9804 #endif
9806 else
9807 free_buf_options(buf, FALSE);
9809 buf->b_p_ai = p_ai;
9810 buf->b_p_ai_nopaste = p_ai_nopaste;
9811 buf->b_p_sw = p_sw;
9812 buf->b_p_tw = p_tw;
9813 buf->b_p_tw_nopaste = p_tw_nopaste;
9814 buf->b_p_tw_nobin = p_tw_nobin;
9815 buf->b_p_wm = p_wm;
9816 buf->b_p_wm_nopaste = p_wm_nopaste;
9817 buf->b_p_wm_nobin = p_wm_nobin;
9818 buf->b_p_bin = p_bin;
9819 #ifdef FEAT_MBYTE
9820 buf->b_p_bomb = p_bomb;
9821 #endif
9822 buf->b_p_et = p_et;
9823 buf->b_p_et_nobin = p_et_nobin;
9824 buf->b_p_ml = p_ml;
9825 buf->b_p_ml_nobin = p_ml_nobin;
9826 buf->b_p_inf = p_inf;
9827 buf->b_p_swf = p_swf;
9828 #ifdef FEAT_INS_EXPAND
9829 buf->b_p_cpt = vim_strsave(p_cpt);
9830 #endif
9831 #ifdef FEAT_COMPL_FUNC
9832 buf->b_p_cfu = vim_strsave(p_cfu);
9833 buf->b_p_ofu = vim_strsave(p_ofu);
9834 #endif
9835 buf->b_p_sts = p_sts;
9836 buf->b_p_sts_nopaste = p_sts_nopaste;
9837 #ifdef FEAT_VARTABS
9838 buf->b_p_vsts = vim_strsave(p_vsts);
9839 if (p_vsts && p_vsts != empty_option)
9840 tabstop_set(p_vsts, &buf->b_p_vsts_ary);
9841 else
9842 buf->b_p_vsts_ary = 0;
9843 buf->b_p_vsts_nopaste = p_vsts_nopaste
9844 ? vim_strsave(p_vsts_nopaste) : NULL;
9845 #endif
9846 #ifndef SHORT_FNAME
9847 buf->b_p_sn = p_sn;
9848 #endif
9849 #ifdef FEAT_COMMENTS
9850 buf->b_p_com = vim_strsave(p_com);
9851 #endif
9852 #ifdef FEAT_FOLDING
9853 buf->b_p_cms = vim_strsave(p_cms);
9854 #endif
9855 buf->b_p_fo = vim_strsave(p_fo);
9856 buf->b_p_flp = vim_strsave(p_flp);
9857 buf->b_p_nf = vim_strsave(p_nf);
9858 buf->b_p_mps = vim_strsave(p_mps);
9859 #ifdef FEAT_SMARTINDENT
9860 buf->b_p_si = p_si;
9861 #endif
9862 buf->b_p_ci = p_ci;
9863 #ifdef FEAT_CINDENT
9864 buf->b_p_cin = p_cin;
9865 buf->b_p_cink = vim_strsave(p_cink);
9866 buf->b_p_cino = vim_strsave(p_cino);
9867 #endif
9868 #ifdef FEAT_AUTOCMD
9869 /* Don't copy 'filetype', it must be detected */
9870 buf->b_p_ft = empty_option;
9871 #endif
9872 #ifdef FEAT_OSFILETYPE
9873 buf->b_p_oft = vim_strsave(p_oft);
9874 #endif
9875 buf->b_p_pi = p_pi;
9876 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9877 buf->b_p_cinw = vim_strsave(p_cinw);
9878 #endif
9879 #ifdef FEAT_LISP
9880 buf->b_p_lisp = p_lisp;
9881 #endif
9882 #ifdef FEAT_SYN_HL
9883 /* Don't copy 'syntax', it must be set */
9884 buf->b_p_syn = empty_option;
9885 buf->b_p_smc = p_smc;
9886 #endif
9887 #ifdef FEAT_SPELL
9888 buf->b_p_spc = vim_strsave(p_spc);
9889 (void)compile_cap_prog(buf);
9890 buf->b_p_spf = vim_strsave(p_spf);
9891 buf->b_p_spl = vim_strsave(p_spl);
9892 #endif
9893 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9894 buf->b_p_inde = vim_strsave(p_inde);
9895 buf->b_p_indk = vim_strsave(p_indk);
9896 #endif
9897 #if defined(FEAT_EVAL)
9898 buf->b_p_fex = vim_strsave(p_fex);
9899 #endif
9900 #ifdef FEAT_CRYPT
9901 buf->b_p_key = vim_strsave(p_key);
9902 #endif
9903 #ifdef FEAT_SEARCHPATH
9904 buf->b_p_sua = vim_strsave(p_sua);
9905 #endif
9906 #ifdef FEAT_KEYMAP
9907 buf->b_p_keymap = vim_strsave(p_keymap);
9908 buf->b_kmap_state |= KEYMAP_INIT;
9909 #endif
9910 /* This isn't really an option, but copying the langmap and IME
9911 * state from the current buffer is better than resetting it. */
9912 buf->b_p_iminsert = p_iminsert;
9913 buf->b_p_imsearch = p_imsearch;
9915 /* options that are normally global but also have a local value
9916 * are not copied, start using the global value */
9917 buf->b_p_ar = -1;
9918 #ifdef FEAT_QUICKFIX
9919 buf->b_p_gp = empty_option;
9920 buf->b_p_mp = empty_option;
9921 buf->b_p_efm = empty_option;
9922 #endif
9923 buf->b_p_ep = empty_option;
9924 buf->b_p_kp = empty_option;
9925 buf->b_p_path = empty_option;
9926 buf->b_p_tags = empty_option;
9927 #ifdef FEAT_FIND_ID
9928 buf->b_p_def = empty_option;
9929 buf->b_p_inc = empty_option;
9930 # ifdef FEAT_EVAL
9931 buf->b_p_inex = vim_strsave(p_inex);
9932 # endif
9933 #endif
9934 #ifdef FEAT_INS_EXPAND
9935 buf->b_p_dict = empty_option;
9936 buf->b_p_tsr = empty_option;
9937 #endif
9938 #ifdef FEAT_TEXTOBJ
9939 buf->b_p_qe = vim_strsave(p_qe);
9940 #endif
9941 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9942 buf->b_p_bexpr = empty_option;
9943 #endif
9944 #ifdef FEAT_PERSISTENT_UNDO
9945 buf->b_p_udf = p_udf;
9946 #endif
9949 * Don't copy the options set by ex_help(), use the saved values,
9950 * when going from a help buffer to a non-help buffer.
9951 * Don't touch these at all when BCO_NOHELP is used and going from
9952 * or to a help buffer.
9954 if (dont_do_help)
9956 buf->b_p_isk = save_p_isk;
9957 #ifdef FEAT_VARTABS
9958 if (p_vts && p_vts != empty_option && !buf->b_p_vts_ary)
9959 tabstop_set(p_vts, &buf->b_p_vts_ary);
9960 else
9961 buf->b_p_vts_ary = 0;
9962 #endif
9964 else
9966 buf->b_p_isk = vim_strsave(p_isk);
9967 did_isk = TRUE;
9968 buf->b_p_ts = p_ts;
9969 #ifdef FEAT_VARTABS
9970 buf->b_p_vts = vim_strsave(p_vts);
9971 if (p_vts && p_vts != empty_option && !buf->b_p_vts_ary)
9972 tabstop_set(p_vts, &buf->b_p_vts_ary);
9973 else
9974 buf->b_p_vts_ary = 0;
9975 #endif
9976 buf->b_help = FALSE;
9977 #ifdef FEAT_QUICKFIX
9978 if (buf->b_p_bt[0] == 'h')
9979 clear_string_option(&buf->b_p_bt);
9980 #endif
9981 buf->b_p_ma = p_ma;
9986 * When the options should be copied (ignoring BCO_ALWAYS), set the
9987 * flag that indicates that the options have been initialized.
9989 if (should_copy)
9990 buf->b_p_initialized = TRUE;
9993 check_buf_options(buf); /* make sure we don't have NULLs */
9994 if (did_isk)
9995 (void)buf_init_chartab(buf, FALSE);
9999 * Reset the 'modifiable' option and its default value.
10001 void
10002 reset_modifiable()
10004 int opt_idx;
10006 curbuf->b_p_ma = FALSE;
10007 p_ma = FALSE;
10008 opt_idx = findoption((char_u *)"ma");
10009 if (opt_idx >= 0)
10010 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
10014 * Set the global value for 'iminsert' to the local value.
10016 void
10017 set_iminsert_global()
10019 p_iminsert = curbuf->b_p_iminsert;
10023 * Set the global value for 'imsearch' to the local value.
10025 void
10026 set_imsearch_global()
10028 p_imsearch = curbuf->b_p_imsearch;
10031 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10032 static int expand_option_idx = -1;
10033 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10034 static int expand_option_flags = 0;
10036 void
10037 set_context_in_set_cmd(xp, arg, opt_flags)
10038 expand_T *xp;
10039 char_u *arg;
10040 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10042 int nextchar;
10043 long_u flags = 0; /* init for GCC */
10044 int opt_idx = 0; /* init for GCC */
10045 char_u *p;
10046 char_u *s;
10047 int is_term_option = FALSE;
10048 int key;
10050 expand_option_flags = opt_flags;
10052 xp->xp_context = EXPAND_SETTINGS;
10053 if (*arg == NUL)
10055 xp->xp_pattern = arg;
10056 return;
10058 p = arg + STRLEN(arg) - 1;
10059 if (*p == ' ' && *(p - 1) != '\\')
10061 xp->xp_pattern = p + 1;
10062 return;
10064 while (p > arg)
10066 s = p;
10067 /* count number of backslashes before ' ' or ',' */
10068 if (*p == ' ' || *p == ',')
10070 while (s > arg && *(s - 1) == '\\')
10071 --s;
10073 /* break at a space with an even number of backslashes */
10074 if (*p == ' ' && ((p - s) & 1) == 0)
10076 ++p;
10077 break;
10079 --p;
10081 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
10083 xp->xp_context = EXPAND_BOOL_SETTINGS;
10084 p += 2;
10086 if (STRNCMP(p, "inv", 3) == 0)
10088 xp->xp_context = EXPAND_BOOL_SETTINGS;
10089 p += 3;
10091 xp->xp_pattern = arg = p;
10092 if (*arg == '<')
10094 while (*p != '>')
10095 if (*p++ == NUL) /* expand terminal option name */
10096 return;
10097 key = get_special_key_code(arg + 1);
10098 if (key == 0) /* unknown name */
10100 xp->xp_context = EXPAND_NOTHING;
10101 return;
10103 nextchar = *++p;
10104 is_term_option = TRUE;
10105 expand_option_name[2] = KEY2TERMCAP0(key);
10106 expand_option_name[3] = KEY2TERMCAP1(key);
10108 else
10110 if (p[0] == 't' && p[1] == '_')
10112 p += 2;
10113 if (*p != NUL)
10114 ++p;
10115 if (*p == NUL)
10116 return; /* expand option name */
10117 nextchar = *++p;
10118 is_term_option = TRUE;
10119 expand_option_name[2] = p[-2];
10120 expand_option_name[3] = p[-1];
10122 else
10124 /* Allow * wildcard */
10125 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10126 p++;
10127 if (*p == NUL)
10128 return;
10129 nextchar = *p;
10130 *p = NUL;
10131 opt_idx = findoption(arg);
10132 *p = nextchar;
10133 if (opt_idx == -1 || options[opt_idx].var == NULL)
10135 xp->xp_context = EXPAND_NOTHING;
10136 return;
10138 flags = options[opt_idx].flags;
10139 if (flags & P_BOOL)
10141 xp->xp_context = EXPAND_NOTHING;
10142 return;
10146 /* handle "-=" and "+=" */
10147 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10149 ++p;
10150 nextchar = '=';
10152 if ((nextchar != '=' && nextchar != ':')
10153 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10155 xp->xp_context = EXPAND_UNSUCCESSFUL;
10156 return;
10158 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10160 xp->xp_context = EXPAND_OLD_SETTING;
10161 if (is_term_option)
10162 expand_option_idx = -1;
10163 else
10164 expand_option_idx = opt_idx;
10165 xp->xp_pattern = p + 1;
10166 return;
10168 xp->xp_context = EXPAND_NOTHING;
10169 if (is_term_option || (flags & P_NUM))
10170 return;
10172 xp->xp_pattern = p + 1;
10174 if (flags & P_EXPAND)
10176 p = options[opt_idx].var;
10177 if (p == (char_u *)&p_bdir
10178 || p == (char_u *)&p_dir
10179 || p == (char_u *)&p_path
10180 || p == (char_u *)&p_rtp
10181 #ifdef FEAT_SEARCHPATH
10182 || p == (char_u *)&p_cdpath
10183 #endif
10184 #ifdef FEAT_SESSION
10185 || p == (char_u *)&p_vdir
10186 #endif
10189 xp->xp_context = EXPAND_DIRECTORIES;
10190 if (p == (char_u *)&p_path
10191 #ifdef FEAT_SEARCHPATH
10192 || p == (char_u *)&p_cdpath
10193 #endif
10195 xp->xp_backslash = XP_BS_THREE;
10196 else
10197 xp->xp_backslash = XP_BS_ONE;
10199 else
10201 xp->xp_context = EXPAND_FILES;
10202 /* for 'tags' need three backslashes for a space */
10203 if (p == (char_u *)&p_tags)
10204 xp->xp_backslash = XP_BS_THREE;
10205 else
10206 xp->xp_backslash = XP_BS_ONE;
10210 /* For an option that is a list of file names, find the start of the
10211 * last file name. */
10212 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10214 /* count number of backslashes before ' ' or ',' */
10215 if (*p == ' ' || *p == ',')
10217 s = p;
10218 while (s > xp->xp_pattern && *(s - 1) == '\\')
10219 --s;
10220 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10221 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10223 xp->xp_pattern = p + 1;
10224 break;
10228 #ifdef FEAT_SPELL
10229 /* for 'spellsuggest' start at "file:" */
10230 if (options[opt_idx].var == (char_u *)&p_sps
10231 && STRNCMP(p, "file:", 5) == 0)
10233 xp->xp_pattern = p + 5;
10234 break;
10236 #endif
10239 return;
10243 ExpandSettings(xp, regmatch, num_file, file)
10244 expand_T *xp;
10245 regmatch_T *regmatch;
10246 int *num_file;
10247 char_u ***file;
10249 int num_normal = 0; /* Nr of matching non-term-code settings */
10250 int num_term = 0; /* Nr of matching terminal code settings */
10251 int opt_idx;
10252 int match;
10253 int count = 0;
10254 char_u *str;
10255 int loop;
10256 int is_term_opt;
10257 char_u name_buf[MAX_KEY_NAME_LEN];
10258 static char *(names[]) = {"all", "termcap"};
10259 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10261 /* do this loop twice:
10262 * loop == 0: count the number of matching options
10263 * loop == 1: copy the matching options into allocated memory
10265 for (loop = 0; loop <= 1; ++loop)
10267 regmatch->rm_ic = ic;
10268 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10270 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10271 ++match)
10272 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10274 if (loop == 0)
10275 num_normal++;
10276 else
10277 (*file)[count++] = vim_strsave((char_u *)names[match]);
10280 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10281 opt_idx++)
10283 if (options[opt_idx].var == NULL)
10284 continue;
10285 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10286 && !(options[opt_idx].flags & P_BOOL))
10287 continue;
10288 is_term_opt = istermoption(&options[opt_idx]);
10289 if (is_term_opt && num_normal > 0)
10290 continue;
10291 match = FALSE;
10292 if (vim_regexec(regmatch, str, (colnr_T)0)
10293 || (options[opt_idx].shortname != NULL
10294 && vim_regexec(regmatch,
10295 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10296 match = TRUE;
10297 else if (is_term_opt)
10299 name_buf[0] = '<';
10300 name_buf[1] = 't';
10301 name_buf[2] = '_';
10302 name_buf[3] = str[2];
10303 name_buf[4] = str[3];
10304 name_buf[5] = '>';
10305 name_buf[6] = NUL;
10306 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10308 match = TRUE;
10309 str = name_buf;
10312 if (match)
10314 if (loop == 0)
10316 if (is_term_opt)
10317 num_term++;
10318 else
10319 num_normal++;
10321 else
10322 (*file)[count++] = vim_strsave(str);
10326 * Check terminal key codes, these are not in the option table
10328 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10330 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10332 if (!isprint(str[0]) || !isprint(str[1]))
10333 continue;
10335 name_buf[0] = 't';
10336 name_buf[1] = '_';
10337 name_buf[2] = str[0];
10338 name_buf[3] = str[1];
10339 name_buf[4] = NUL;
10341 match = FALSE;
10342 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10343 match = TRUE;
10344 else
10346 name_buf[0] = '<';
10347 name_buf[1] = 't';
10348 name_buf[2] = '_';
10349 name_buf[3] = str[0];
10350 name_buf[4] = str[1];
10351 name_buf[5] = '>';
10352 name_buf[6] = NUL;
10354 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10355 match = TRUE;
10357 if (match)
10359 if (loop == 0)
10360 num_term++;
10361 else
10362 (*file)[count++] = vim_strsave(name_buf);
10367 * Check special key names.
10369 regmatch->rm_ic = TRUE; /* ignore case here */
10370 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10372 name_buf[0] = '<';
10373 STRCPY(name_buf + 1, str);
10374 STRCAT(name_buf, ">");
10376 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10378 if (loop == 0)
10379 num_term++;
10380 else
10381 (*file)[count++] = vim_strsave(name_buf);
10385 if (loop == 0)
10387 if (num_normal > 0)
10388 *num_file = num_normal;
10389 else if (num_term > 0)
10390 *num_file = num_term;
10391 else
10392 return OK;
10393 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10394 if (*file == NULL)
10396 *file = (char_u **)"";
10397 return FAIL;
10401 return OK;
10405 ExpandOldSetting(num_file, file)
10406 int *num_file;
10407 char_u ***file;
10409 char_u *var = NULL; /* init for GCC */
10410 char_u *buf;
10412 *num_file = 0;
10413 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10414 if (*file == NULL)
10415 return FAIL;
10418 * For a terminal key code expand_option_idx is < 0.
10420 if (expand_option_idx < 0)
10422 var = find_termcode(expand_option_name + 2);
10423 if (var == NULL)
10424 expand_option_idx = findoption(expand_option_name);
10427 if (expand_option_idx >= 0)
10429 /* put string of option value in NameBuff */
10430 option_value2string(&options[expand_option_idx], expand_option_flags);
10431 var = NameBuff;
10433 else if (var == NULL)
10434 var = (char_u *)"";
10436 /* A backslash is required before some characters. This is the reverse of
10437 * what happens in do_set(). */
10438 buf = vim_strsave_escaped(var, escape_chars);
10440 if (buf == NULL)
10442 vim_free(*file);
10443 *file = NULL;
10444 return FAIL;
10447 #ifdef BACKSLASH_IN_FILENAME
10448 /* For MS-Windows et al. we don't double backslashes at the start and
10449 * before a file name character. */
10450 for (var = buf; *var != NUL; mb_ptr_adv(var))
10451 if (var[0] == '\\' && var[1] == '\\'
10452 && expand_option_idx >= 0
10453 && (options[expand_option_idx].flags & P_EXPAND)
10454 && vim_isfilec(var[2])
10455 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
10456 STRMOVE(var, var + 1);
10457 #endif
10459 *file[0] = buf;
10460 *num_file = 1;
10461 return OK;
10463 #endif
10466 * Get the value for the numeric or string option *opp in a nice format into
10467 * NameBuff[]. Must not be called with a hidden option!
10469 static void
10470 option_value2string(opp, opt_flags)
10471 struct vimoption *opp;
10472 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10474 char_u *varp;
10476 varp = get_varp_scope(opp, opt_flags);
10478 if (opp->flags & P_NUM)
10480 long wc = 0;
10482 if (wc_use_keyname(varp, &wc))
10483 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10484 else if (wc != 0)
10485 STRCPY(NameBuff, transchar((int)wc));
10486 else
10487 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10489 else /* P_STRING */
10491 varp = *(char_u **)(varp);
10492 if (varp == NULL) /* just in case */
10493 NameBuff[0] = NUL;
10494 #ifdef FEAT_CRYPT
10495 /* don't show the actual value of 'key', only that it's set */
10496 else if (opp->var == (char_u *)&p_key && *varp)
10497 STRCPY(NameBuff, "*****");
10498 #endif
10499 else if (opp->flags & P_EXPAND)
10500 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10501 /* Translate 'pastetoggle' into special key names */
10502 else if ((char_u **)opp->var == &p_pt)
10503 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10504 else
10505 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
10510 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10511 * printed as a keyname.
10512 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10514 static int
10515 wc_use_keyname(varp, wcp)
10516 char_u *varp;
10517 long *wcp;
10519 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10521 *wcp = *(long *)varp;
10522 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10523 return TRUE;
10525 return FALSE;
10528 #ifdef FEAT_LANGMAP
10530 * Any character has an equivalent 'langmap' character. This is used for
10531 * keyboards that have a special language mode that sends characters above
10532 * 128 (although other characters can be translated too). The "to" field is a
10533 * Vim command character. This avoids having to switch the keyboard back to
10534 * ASCII mode when leaving Insert mode.
10536 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10537 * commands.
10538 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10539 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10540 * 256.
10542 # ifdef FEAT_MBYTE
10544 * With multi-byte support use growarray for 'langmap' chars >= 256
10546 typedef struct
10548 int from;
10549 int to;
10550 } langmap_entry_T;
10552 static garray_T langmap_mapga;
10553 static void langmap_set_entry __ARGS((int from, int to));
10556 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10557 * field. If not found insert a new entry at the appropriate location.
10559 static void
10560 langmap_set_entry(from, to)
10561 int from;
10562 int to;
10564 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10565 int a = 0;
10566 int b = langmap_mapga.ga_len;
10568 /* Do a binary search for an existing entry. */
10569 while (a != b)
10571 int i = (a + b) / 2;
10572 int d = entries[i].from - from;
10574 if (d == 0)
10576 entries[i].to = to;
10577 return;
10579 if (d < 0)
10580 a = i + 1;
10581 else
10582 b = i;
10585 if (ga_grow(&langmap_mapga, 1) != OK)
10586 return; /* out of memory */
10588 /* insert new entry at position "a" */
10589 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10590 mch_memmove(entries + 1, entries,
10591 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10592 ++langmap_mapga.ga_len;
10593 entries[0].from = from;
10594 entries[0].to = to;
10598 * Apply 'langmap' to multi-byte character "c" and return the result.
10601 langmap_adjust_mb(c)
10602 int c;
10604 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10605 int a = 0;
10606 int b = langmap_mapga.ga_len;
10608 while (a != b)
10610 int i = (a + b) / 2;
10611 int d = entries[i].from - c;
10613 if (d == 0)
10614 return entries[i].to; /* found matching entry */
10615 if (d < 0)
10616 a = i + 1;
10617 else
10618 b = i;
10620 return c; /* no entry found, return "c" unmodified */
10622 # endif
10624 static void
10625 langmap_init()
10627 int i;
10629 for (i = 0; i < 256; i++)
10630 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10631 # ifdef FEAT_MBYTE
10632 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10633 # endif
10637 * Called when langmap option is set; the language map can be
10638 * changed at any time!
10640 static void
10641 langmap_set()
10643 char_u *p;
10644 char_u *p2;
10645 int from, to;
10647 #ifdef FEAT_MBYTE
10648 ga_clear(&langmap_mapga); /* clear the previous map first */
10649 #endif
10650 langmap_init(); /* back to one-to-one map */
10652 for (p = p_langmap; p[0] != NUL; )
10654 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10655 mb_ptr_adv(p2))
10657 if (p2[0] == '\\' && p2[1] != NUL)
10658 ++p2;
10660 if (p2[0] == ';')
10661 ++p2; /* abcd;ABCD form, p2 points to A */
10662 else
10663 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10664 while (p[0])
10666 if (p[0] == ',')
10668 ++p;
10669 break;
10671 if (p[0] == '\\' && p[1] != NUL)
10672 ++p;
10673 #ifdef FEAT_MBYTE
10674 from = (*mb_ptr2char)(p);
10675 #else
10676 from = p[0];
10677 #endif
10678 to = NUL;
10679 if (p2 == NULL)
10681 mb_ptr_adv(p);
10682 if (p[0] != ',')
10684 if (p[0] == '\\')
10685 ++p;
10686 #ifdef FEAT_MBYTE
10687 to = (*mb_ptr2char)(p);
10688 #else
10689 to = p[0];
10690 #endif
10693 else
10695 if (p2[0] != ',')
10697 if (p2[0] == '\\')
10698 ++p2;
10699 #ifdef FEAT_MBYTE
10700 to = (*mb_ptr2char)(p2);
10701 #else
10702 to = p2[0];
10703 #endif
10706 if (to == NUL)
10708 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10709 transchar(from));
10710 return;
10713 #ifdef FEAT_MBYTE
10714 if (from >= 256)
10715 langmap_set_entry(from, to);
10716 else
10717 #endif
10718 langmap_mapchar[from & 255] = to;
10720 /* Advance to next pair */
10721 mb_ptr_adv(p);
10722 if (p2 != NULL)
10724 mb_ptr_adv(p2);
10725 if (*p == ';')
10727 p = p2;
10728 if (p[0] != NUL)
10730 if (p[0] != ',')
10732 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10733 return;
10735 ++p;
10737 break;
10743 #endif
10746 * Return TRUE if format option 'x' is in effect.
10747 * Take care of no formatting when 'paste' is set.
10750 has_format_option(x)
10751 int x;
10753 if (p_paste)
10754 return FALSE;
10755 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10759 * Return TRUE if "x" is present in 'shortmess' option, or
10760 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10763 shortmess(x)
10764 int x;
10766 return ( vim_strchr(p_shm, x) != NULL
10767 || (vim_strchr(p_shm, 'a') != NULL
10768 && vim_strchr((char_u *)SHM_A, x) != NULL));
10772 * paste_option_changed() - Called after p_paste was set or reset.
10774 static void
10775 paste_option_changed()
10777 static int old_p_paste = FALSE;
10778 static int save_sm = 0;
10779 #ifdef FEAT_CMDL_INFO
10780 static int save_ru = 0;
10781 #endif
10782 #ifdef FEAT_RIGHTLEFT
10783 static int save_ri = 0;
10784 static int save_hkmap = 0;
10785 #endif
10786 buf_T *buf;
10788 if (p_paste)
10791 * Paste switched from off to on.
10792 * Save the current values, so they can be restored later.
10794 if (!old_p_paste)
10796 /* save options for each buffer */
10797 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10799 buf->b_p_tw_nopaste = buf->b_p_tw;
10800 buf->b_p_wm_nopaste = buf->b_p_wm;
10801 buf->b_p_sts_nopaste = buf->b_p_sts;
10802 buf->b_p_ai_nopaste = buf->b_p_ai;
10803 #ifdef FEAT_VARTABS
10804 if (buf->b_p_vsts_nopaste)
10805 vim_free(buf->b_p_vsts_nopaste);
10806 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
10807 ? vim_strsave(buf->b_p_vsts) : NULL;
10808 #endif
10811 /* save global options */
10812 save_sm = p_sm;
10813 #ifdef FEAT_CMDL_INFO
10814 save_ru = p_ru;
10815 #endif
10816 #ifdef FEAT_RIGHTLEFT
10817 save_ri = p_ri;
10818 save_hkmap = p_hkmap;
10819 #endif
10820 /* save global values for local buffer options */
10821 p_tw_nopaste = p_tw;
10822 p_wm_nopaste = p_wm;
10823 p_sts_nopaste = p_sts;
10824 p_ai_nopaste = p_ai;
10825 #ifdef FEAT_VARTABS
10826 if (p_vsts_nopaste)
10827 vim_free(p_vsts_nopaste);
10828 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
10829 #endif
10833 * Always set the option values, also when 'paste' is set when it is
10834 * already on.
10836 /* set options for each buffer */
10837 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10839 buf->b_p_tw = 0; /* textwidth is 0 */
10840 buf->b_p_wm = 0; /* wrapmargin is 0 */
10841 buf->b_p_sts = 0; /* softtabstop is 0 */
10842 buf->b_p_ai = 0; /* no auto-indent */
10843 #ifdef FEAT_VARTABS
10844 if (buf->b_p_vsts)
10845 free_string_option(buf->b_p_vsts);
10846 buf->b_p_vsts = empty_option;
10847 if (buf->b_p_vsts_ary)
10848 vim_free(buf->b_p_vsts_ary);
10849 buf->b_p_vsts_ary = 0;
10850 #endif
10853 /* set global options */
10854 p_sm = 0; /* no showmatch */
10855 #ifdef FEAT_CMDL_INFO
10856 # ifdef FEAT_WINDOWS
10857 if (p_ru)
10858 status_redraw_all(); /* redraw to remove the ruler */
10859 # endif
10860 p_ru = 0; /* no ruler */
10861 #endif
10862 #ifdef FEAT_RIGHTLEFT
10863 p_ri = 0; /* no reverse insert */
10864 p_hkmap = 0; /* no Hebrew keyboard */
10865 #endif
10866 /* set global values for local buffer options */
10867 p_tw = 0;
10868 p_wm = 0;
10869 p_sts = 0;
10870 p_ai = 0;
10871 #ifdef FEAT_VARTABS
10872 if (p_vsts)
10873 free_string_option(p_vsts);
10874 p_vsts = empty_option;
10875 #endif
10879 * Paste switched from on to off: Restore saved values.
10881 else if (old_p_paste)
10883 /* restore options for each buffer */
10884 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10886 buf->b_p_tw = buf->b_p_tw_nopaste;
10887 buf->b_p_wm = buf->b_p_wm_nopaste;
10888 buf->b_p_sts = buf->b_p_sts_nopaste;
10889 buf->b_p_ai = buf->b_p_ai_nopaste;
10890 #ifdef FEAT_VARTABS
10891 if (buf->b_p_vsts)
10892 free_string_option(buf->b_p_vsts);
10893 buf->b_p_vsts = buf->b_p_vsts_nopaste
10894 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
10895 if (buf->b_p_vsts_ary)
10896 vim_free(buf->b_p_vsts_ary);
10897 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
10898 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_ary);
10899 else
10900 buf->b_p_vsts_ary = 0;
10901 #endif
10904 /* restore global options */
10905 p_sm = save_sm;
10906 #ifdef FEAT_CMDL_INFO
10907 # ifdef FEAT_WINDOWS
10908 if (p_ru != save_ru)
10909 status_redraw_all(); /* redraw to draw the ruler */
10910 # endif
10911 p_ru = save_ru;
10912 #endif
10913 #ifdef FEAT_RIGHTLEFT
10914 p_ri = save_ri;
10915 p_hkmap = save_hkmap;
10916 #endif
10917 /* set global values for local buffer options */
10918 p_tw = p_tw_nopaste;
10919 p_wm = p_wm_nopaste;
10920 p_sts = p_sts_nopaste;
10921 p_ai = p_ai_nopaste;
10922 #ifdef FEAT_VARTABS
10923 if (p_vsts)
10924 free_string_option(p_vsts);
10925 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
10926 #endif
10929 old_p_paste = p_paste;
10933 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10935 * Reset 'compatible' and set the values for options that didn't get set yet
10936 * to the Vim defaults.
10937 * Don't do this if the 'compatible' option has been set or reset before.
10938 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
10940 void
10941 vimrc_found(fname, envname)
10942 char_u *fname;
10943 char_u *envname;
10945 int opt_idx;
10946 int dofree = FALSE;
10947 char_u *p;
10949 if (!option_was_set((char_u *)"cp"))
10951 p_cp = FALSE;
10952 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10953 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10954 set_option_default(opt_idx, OPT_FREE, FALSE);
10955 didset_options();
10958 if (fname != NULL)
10960 p = vim_getenv(envname, &dofree);
10961 if (p == NULL)
10963 /* Set $MYVIMRC to the first vimrc file found. */
10964 p = FullName_save(fname, FALSE);
10965 if (p != NULL)
10967 vim_setenv(envname, p);
10968 vim_free(p);
10971 else if (dofree)
10972 vim_free(p);
10977 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10979 void
10980 change_compatible(on)
10981 int on;
10983 int opt_idx;
10985 if (p_cp != on)
10987 p_cp = on;
10988 compatible_set();
10990 opt_idx = findoption((char_u *)"cp");
10991 if (opt_idx >= 0)
10992 options[opt_idx].flags |= P_WAS_SET;
10996 * Return TRUE when option "name" has been set.
10999 option_was_set(name)
11000 char_u *name;
11002 int idx;
11004 idx = findoption(name);
11005 if (idx < 0) /* unknown option */
11006 return FALSE;
11007 if (options[idx].flags & P_WAS_SET)
11008 return TRUE;
11009 return FALSE;
11013 * compatible_set() - Called when 'compatible' has been set or unset.
11015 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11016 * flag) to a Vi compatible value.
11017 * When 'compatible' is unset: Set all options that have a different default
11018 * for Vim (without the P_VI_DEF flag) to that default.
11020 static void
11021 compatible_set()
11023 int opt_idx;
11025 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11026 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11027 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11028 set_option_default(opt_idx, OPT_FREE, p_cp);
11029 didset_options();
11032 #ifdef FEAT_LINEBREAK
11034 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11035 /* Borland C++ screws up loop optimisation here (negri) */
11036 #pragma option -O-l
11037 # endif
11040 * fill_breakat_flags() -- called when 'breakat' changes value.
11042 static void
11043 fill_breakat_flags()
11045 char_u *p;
11046 int i;
11048 for (i = 0; i < 256; i++)
11049 breakat_flags[i] = FALSE;
11051 if (p_breakat != NULL)
11052 for (p = p_breakat; *p; p++)
11053 breakat_flags[*p] = TRUE;
11056 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11057 #pragma option -O.l
11058 # endif
11060 #endif
11063 * Check an option that can be a range of string values.
11065 * Return OK for correct value, FAIL otherwise.
11066 * Empty is always OK.
11068 static int
11069 check_opt_strings(val, values, list)
11070 char_u *val;
11071 char **values;
11072 int list; /* when TRUE: accept a list of values */
11074 return opt_strings_flags(val, values, NULL, list);
11078 * Handle an option that can be a range of string values.
11079 * Set a flag in "*flagp" for each string present.
11081 * Return OK for correct value, FAIL otherwise.
11082 * Empty is always OK.
11084 static int
11085 opt_strings_flags(val, values, flagp, list)
11086 char_u *val; /* new value */
11087 char **values; /* array of valid string values */
11088 unsigned *flagp;
11089 int list; /* when TRUE: accept a list of values */
11091 int i;
11092 int len;
11093 unsigned new_flags = 0;
11095 while (*val)
11097 for (i = 0; ; ++i)
11099 if (values[i] == NULL) /* val not found in values[] */
11100 return FAIL;
11102 len = (int)STRLEN(values[i]);
11103 if (STRNCMP(values[i], val, len) == 0
11104 && ((list && val[len] == ',') || val[len] == NUL))
11106 val += len + (val[len] == ',');
11107 new_flags |= (1 << i);
11108 break; /* check next item in val list */
11112 if (flagp != NULL)
11113 *flagp = new_flags;
11115 return OK;
11119 * Read the 'wildmode' option, fill wim_flags[].
11121 static int
11122 check_opt_wim()
11124 char_u new_wim_flags[4];
11125 char_u *p;
11126 int i;
11127 int idx = 0;
11129 for (i = 0; i < 4; ++i)
11130 new_wim_flags[i] = 0;
11132 for (p = p_wim; *p; ++p)
11134 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11136 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11137 return FAIL;
11138 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11139 new_wim_flags[idx] |= WIM_LONGEST;
11140 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11141 new_wim_flags[idx] |= WIM_FULL;
11142 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11143 new_wim_flags[idx] |= WIM_LIST;
11144 else
11145 return FAIL;
11146 p += i;
11147 if (*p == NUL)
11148 break;
11149 if (*p == ',')
11151 if (idx == 3)
11152 return FAIL;
11153 ++idx;
11157 /* fill remaining entries with last flag */
11158 while (idx < 3)
11160 new_wim_flags[idx + 1] = new_wim_flags[idx];
11161 ++idx;
11164 /* only when there are no errors, wim_flags[] is changed */
11165 for (i = 0; i < 4; ++i)
11166 wim_flags[i] = new_wim_flags[i];
11167 return OK;
11171 * Check if backspacing over something is allowed.
11174 can_bs(what)
11175 int what; /* BS_INDENT, BS_EOL or BS_START */
11177 switch (*p_bs)
11179 case '2': return TRUE;
11180 case '1': return (what != BS_START);
11181 case '0': return FALSE;
11183 return vim_strchr(p_bs, what) != NULL;
11187 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11188 * the file must be considered changed when the value is different.
11190 void
11191 save_file_ff(buf)
11192 buf_T *buf;
11194 buf->b_start_ffc = *buf->b_p_ff;
11195 buf->b_start_eol = buf->b_p_eol;
11196 #ifdef FEAT_MBYTE
11197 buf->b_start_bomb = buf->b_p_bomb;
11199 /* Only use free/alloc when necessary, they take time. */
11200 if (buf->b_start_fenc == NULL
11201 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11203 vim_free(buf->b_start_fenc);
11204 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11206 #endif
11210 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11211 * from when editing started (save_file_ff() called).
11212 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11213 * changed and 'binary' is not set.
11214 * Don't consider a new, empty buffer to be changed.
11217 file_ff_differs(buf)
11218 buf_T *buf;
11220 /* In a buffer that was never loaded the options are not valid. */
11221 if (buf->b_flags & BF_NEVERLOADED)
11222 return FALSE;
11223 if ((buf->b_flags & BF_NEW)
11224 && buf->b_ml.ml_line_count == 1
11225 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11226 return FALSE;
11227 if (buf->b_start_ffc != *buf->b_p_ff)
11228 return TRUE;
11229 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11230 return TRUE;
11231 #ifdef FEAT_MBYTE
11232 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11233 return TRUE;
11234 if (buf->b_start_fenc == NULL)
11235 return (*buf->b_p_fenc != NUL);
11236 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11237 #else
11238 return FALSE;
11239 #endif
11243 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11246 check_ff_value(p)
11247 char_u *p;
11249 return check_opt_strings(p, p_ff_values, FALSE);
11252 #ifdef FEAT_VARTABS
11255 * Set the integer values corresponding to the string setting of 'vartabstop'.
11258 tabstop_set(var, array)
11259 char_u *var;
11260 int **array;
11262 int valcount = 1;
11263 int t;
11264 char_u *cp;
11266 if ((!var[0] || (var[0] == '0' && !var[1])))
11268 *array = (int *)0;
11269 return TRUE;
11272 for (cp = var; *cp; ++cp)
11274 if (cp == var || *(cp - 1) == ',')
11275 if (atoi((char *)cp) <= 0)
11276 return FALSE;
11278 if (VIM_ISDIGIT(*cp))
11279 continue;
11280 if (*cp == ',' && cp > var && *(cp - 1) != ',')
11282 ++valcount;
11283 continue;
11285 return FALSE;
11288 *array = (int *) alloc((unsigned) ((valcount + 1) * sizeof(int)));
11289 (*array)[0] = valcount;
11291 t = 1;
11292 for (cp = var; *cp;)
11294 (*array)[t++] = atoi((char *)cp);
11295 while (*cp && *cp != ',')
11296 ++cp;
11297 if (*cp)
11298 ++cp;
11301 return TRUE;
11305 * Calculate the number of screen spaces a tab will occupy.
11306 * If vts is set then the tab widths are taken from that array,
11307 * otherwise the value of ts is used.
11310 tabstop_padding(col, ts, vts)
11311 colnr_T col;
11312 int ts;
11313 int *vts;
11315 int tabcount;
11316 colnr_T tabcol = 0;
11317 int t;
11318 int padding = 0;
11320 if (ts == 0)
11321 ts = 8;
11322 if (vts == 0 || vts[0] == 0)
11323 return ts - (col % ts);
11325 tabcount = vts[0];
11327 for (t = 1; t <= tabcount; ++t)
11329 tabcol += vts[t];
11330 if (tabcol > col)
11332 padding = (int)(tabcol - col);
11333 break;
11336 if (t > tabcount)
11337 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
11339 return padding;
11343 * Find the size of the tab that covers a particular column.
11346 tabstop_at(col, ts, vts)
11347 colnr_T col;
11348 int ts;
11349 int *vts;
11351 int tabcount;
11352 colnr_T tabcol = 0;
11353 int t;
11354 int tab_size = 0;
11356 if (vts == 0 || vts[0] == 0)
11357 return ts;
11359 tabcount = vts[0];
11360 for (t = 1; t <= tabcount; ++t)
11362 tabcol += vts[t];
11363 if (tabcol > col)
11365 tab_size = vts[t];
11366 break;
11369 if (t > tabcount)
11370 tab_size = vts[tabcount];
11372 return tab_size;
11376 * Find the column on which a tab starts.
11378 colnr_T
11379 tabstop_start(col, ts, vts)
11380 colnr_T col;
11381 int ts;
11382 int *vts;
11384 int tabcount;
11385 colnr_T tabcol = 0;
11386 int t;
11388 if (vts == 0 || vts[0] == 0)
11389 return (col / ts) * ts;
11391 tabcount = vts[0];
11392 for (t = 1; t <= tabcount; ++t)
11394 tabcol += vts[t];
11395 if (tabcol > col)
11396 return tabcol - vts[t];
11399 int excess = tabcol % vts[tabcount];
11400 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
11404 * Find the number of tabs and spaces necessary to get from one column
11405 * to another.
11407 void
11408 tabstop_fromto(start_col, end_col, ts, vts, ntabs, nspcs)
11409 colnr_T start_col;
11410 colnr_T end_col;
11411 int ts;
11412 int *vts;
11413 int *ntabs;
11414 int *nspcs;
11416 int spaces = end_col - start_col;
11417 colnr_T tabcol = 0;
11418 int padding = 0;
11419 int tabcount;
11420 int t;
11422 if (vts == 0 || vts[0] == 0)
11424 int tabs = 0;
11425 int initspc = ts - (start_col % ts);
11426 if (spaces >= initspc)
11428 spaces -= initspc;
11429 tabs++;
11431 tabs += spaces / ts;
11432 spaces -= (spaces / ts) * ts;
11434 *ntabs = tabs;
11435 *nspcs = spaces;
11436 return;
11439 /* Find the padding needed to reach the next tabstop. */
11440 tabcount = vts[0];
11441 for (t = 1; t <= tabcount; ++t)
11443 tabcol += vts[t];
11444 if (tabcol > start_col)
11446 padding = (int)(tabcol - start_col);
11447 break;
11450 if (t > tabcount)
11451 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
11453 /* If the space needed is less than the padding no tabs can be used. */
11454 if (spaces < padding)
11456 *ntabs = 0;
11457 *nspcs = spaces;
11458 return;
11461 *ntabs = 1;
11462 spaces -= padding;
11464 /* At least one tab has been used. See if any more will fit. */
11465 while (spaces != 0 && ++t <= tabcount)
11467 padding = vts[t];
11468 if (spaces < padding)
11470 *nspcs = spaces;
11471 return;
11473 ++*ntabs;
11474 spaces -= padding;
11477 *ntabs += spaces / vts[tabcount];
11478 *nspcs = spaces % vts[tabcount];
11482 * See if two tabstop arrays contain the same values.
11485 tabstop_eq(ts1, ts2)
11486 int *ts1;
11487 int *ts2;
11489 int t;
11491 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
11492 return FALSE;
11493 if (ts1 == ts2)
11494 return TRUE;
11495 if (ts1[0] != ts2[0])
11496 return FALSE;
11498 for (t = 1; t <= ts1[0]; ++t)
11499 if (ts1[t] != ts2[t])
11500 return FALSE;
11502 return TRUE;
11506 * Copy a tabstop array, allocating space for the new array.
11508 int *
11509 tabstop_copy(oldts)
11510 int *oldts;
11512 int *newts;
11513 int t;
11515 if (oldts == 0)
11516 return 0;
11518 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
11519 for (t = 0; t <= oldts[0]; ++t)
11520 newts[t] = oldts[t];
11522 return newts;
11526 * Return a count of the number of tabstops.
11529 tabstop_count(ts)
11530 int *ts;
11532 return ts ? ts[0] : 0;
11536 * Return the first tabstop, or 8 if there are no tabstops defined.
11539 tabstop_first(ts)
11540 int *ts;
11542 return ts ? ts[1] : 8;
11545 #endif