Merge branch 'vim-with-runtime'
[vim_extended.git] / src / option.c
blob987de785ffcfd0620796cdea6b86714243a9b21b
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".
3763 p = gettail(p_sh);
3764 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3765 if (p != NULL)
3768 * Default for p_sp is "| tee", for p_srr is ">".
3769 * For known shells it is changed here to include stderr.
3771 if ( fnamecmp(p, "csh") == 0
3772 || fnamecmp(p, "tcsh") == 0
3773 # if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3774 || fnamecmp(p, "csh.exe") == 0
3775 || fnamecmp(p, "tcsh.exe") == 0
3776 # endif
3779 #if defined(FEAT_QUICKFIX)
3780 if (do_sp)
3782 # ifdef WIN3264
3783 p_sp = (char_u *)">&";
3784 # else
3785 p_sp = (char_u *)"|& tee";
3786 # endif
3787 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3789 #endif
3790 if (do_srr)
3792 p_srr = (char_u *)">&";
3793 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3796 else
3797 # ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3798 if ( fnamecmp(p, "sh") == 0
3799 || fnamecmp(p, "ksh") == 0
3800 || fnamecmp(p, "zsh") == 0
3801 || fnamecmp(p, "zsh-beta") == 0
3802 || fnamecmp(p, "bash") == 0
3803 # ifdef WIN3264
3804 || fnamecmp(p, "cmd") == 0
3805 || fnamecmp(p, "sh.exe") == 0
3806 || fnamecmp(p, "ksh.exe") == 0
3807 || fnamecmp(p, "zsh.exe") == 0
3808 || fnamecmp(p, "zsh-beta.exe") == 0
3809 || fnamecmp(p, "bash.exe") == 0
3810 || fnamecmp(p, "cmd.exe") == 0
3811 # endif
3813 # endif
3815 #if defined(FEAT_QUICKFIX)
3816 if (do_sp)
3818 # ifdef WIN3264
3819 p_sp = (char_u *)">%s 2>&1";
3820 # else
3821 p_sp = (char_u *)"2>&1| tee";
3822 # endif
3823 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3825 #endif
3826 if (do_srr)
3828 p_srr = (char_u *)">%s 2>&1";
3829 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3832 vim_free(p);
3834 #endif
3836 #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3838 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3839 * This is done after other initializations, where 'shell' might have been
3840 * set, but only if they have not been set before. Default for p_shcf is
3841 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3842 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3843 * command.com. And for Win32 we need to set p_sxq instead.
3845 if (strstr((char *)gettail(p_sh), "sh") != NULL)
3847 int idx3;
3849 idx3 = findoption((char_u *)"shcf");
3850 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3852 p_shcf = (char_u *)"-c";
3853 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3856 # ifndef DJGPP
3857 # ifdef WIN3264
3858 /* Somehow Win32 requires the quotes around the redirection too */
3859 idx3 = findoption((char_u *)"sxq");
3860 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3862 p_sxq = (char_u *)"\"";
3863 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3865 # else
3866 idx3 = findoption((char_u *)"shq");
3867 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3869 p_shq = (char_u *)"\"";
3870 options[idx3].def_val[VI_DEFAULT] = p_shq;
3872 # endif
3873 # endif
3875 #endif
3877 #ifdef FEAT_TITLE
3878 set_title_defaults();
3879 #endif
3882 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
3884 * When 'helplang' is still at its default value, set it to "lang".
3885 * Only the first two characters of "lang" are used.
3887 void
3888 set_helplang_default(lang)
3889 char_u *lang;
3891 int idx;
3893 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3894 return;
3895 idx = findoption((char_u *)"hlg");
3896 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3898 if (options[idx].flags & P_ALLOCED)
3899 free_string_option(p_hlg);
3900 p_hlg = vim_strsave(lang);
3901 if (p_hlg == NULL)
3902 p_hlg = empty_option;
3903 else
3905 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3906 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3908 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3909 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3911 p_hlg[2] = NUL;
3913 options[idx].flags |= P_ALLOCED;
3916 #endif
3918 #ifdef FEAT_GUI
3919 static char_u *gui_bg_default __ARGS((void));
3921 static char_u *
3922 gui_bg_default()
3924 if (gui_get_lightness(gui.back_pixel) < 127)
3925 return (char_u *)"dark";
3926 return (char_u *)"light";
3930 * Option initializations that can only be done after opening the GUI window.
3932 void
3933 init_gui_options()
3935 /* Set the 'background' option according to the lightness of the
3936 * background color, unless the user has set it already. */
3937 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3939 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3940 highlight_changed();
3943 #endif
3945 #ifdef FEAT_TITLE
3947 * 'title' and 'icon' only default to true if they have not been set or reset
3948 * in .vimrc and we can read the old value.
3949 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3950 * they can be reset. This reduces startup time when using X on a remote
3951 * machine.
3953 void
3954 set_title_defaults()
3956 int idx1;
3957 long val;
3960 * If GUI is (going to be) used, we can always set the window title and
3961 * icon name. Saves a bit of time, because the X11 display server does
3962 * not need to be contacted.
3964 idx1 = findoption((char_u *)"title");
3965 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
3967 #ifdef FEAT_GUI
3968 if (gui.starting || gui.in_use)
3969 val = TRUE;
3970 else
3971 #endif
3972 val = mch_can_restore_title();
3973 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3974 p_title = val;
3976 idx1 = findoption((char_u *)"icon");
3977 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
3979 #ifdef FEAT_GUI
3980 if (gui.starting || gui.in_use)
3981 val = TRUE;
3982 else
3983 #endif
3984 val = mch_can_restore_icon();
3985 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3986 p_icon = val;
3989 #endif
3992 * Parse 'arg' for option settings.
3994 * 'arg' may be IObuff, but only when no errors can be present and option
3995 * does not need to be expanded with option_expand().
3996 * "opt_flags":
3997 * 0 for ":set"
3998 * OPT_GLOBAL for ":setglobal"
3999 * OPT_LOCAL for ":setlocal" and a modeline
4000 * OPT_MODELINE for a modeline
4001 * OPT_WINONLY to only set window-local options
4002 * OPT_NOWIN to skip setting window-local options
4004 * returns FAIL if an error is detected, OK otherwise
4007 do_set(arg, opt_flags)
4008 char_u *arg; /* option string (may be written to!) */
4009 int opt_flags;
4011 int opt_idx;
4012 char_u *errmsg;
4013 char_u errbuf[80];
4014 char_u *startarg;
4015 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4016 int nextchar; /* next non-white char after option name */
4017 int afterchar; /* character just after option name */
4018 int len;
4019 int i;
4020 long value;
4021 int key;
4022 long_u flags; /* flags for current option */
4023 char_u *varp = NULL; /* pointer to variable for current option */
4024 int did_show = FALSE; /* already showed one value */
4025 int adding; /* "opt+=arg" */
4026 int prepending; /* "opt^=arg" */
4027 int removing; /* "opt-=arg" */
4028 int cp_val = 0;
4029 char_u key_name[2];
4031 if (*arg == NUL)
4033 showoptions(0, opt_flags);
4034 did_show = TRUE;
4035 goto theend;
4038 while (*arg != NUL) /* loop to process all options */
4040 errmsg = NULL;
4041 startarg = arg; /* remember for error message */
4043 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4044 && !(opt_flags & OPT_MODELINE))
4047 * ":set all" show all options.
4048 * ":set all&" set all options to their default value.
4050 arg += 3;
4051 if (*arg == '&')
4053 ++arg;
4054 /* Only for :set command set global value of local options. */
4055 set_options_default(OPT_FREE | opt_flags);
4057 else
4059 showoptions(1, opt_flags);
4060 did_show = TRUE;
4063 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
4065 showoptions(2, opt_flags);
4066 show_termcodes();
4067 did_show = TRUE;
4068 arg += 7;
4070 else
4072 prefix = 1;
4073 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
4075 prefix = 0;
4076 arg += 2;
4078 else if (STRNCMP(arg, "inv", 3) == 0)
4080 prefix = 2;
4081 arg += 3;
4084 /* find end of name */
4085 key = 0;
4086 if (*arg == '<')
4088 nextchar = 0;
4089 opt_idx = -1;
4090 /* look out for <t_>;> */
4091 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4092 len = 5;
4093 else
4095 len = 1;
4096 while (arg[len] != NUL && arg[len] != '>')
4097 ++len;
4099 if (arg[len] != '>')
4101 errmsg = e_invarg;
4102 goto skip;
4104 arg[len] = NUL; /* put NUL after name */
4105 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4106 opt_idx = findoption(arg + 1);
4107 arg[len++] = '>'; /* restore '>' */
4108 if (opt_idx == -1)
4109 key = find_key_option(arg + 1);
4111 else
4113 len = 0;
4115 * The two characters after "t_" may not be alphanumeric.
4117 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4118 len = 4;
4119 else
4120 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4121 ++len;
4122 nextchar = arg[len];
4123 arg[len] = NUL; /* put NUL after name */
4124 opt_idx = findoption(arg);
4125 arg[len] = nextchar; /* restore nextchar */
4126 if (opt_idx == -1)
4127 key = find_key_option(arg);
4130 /* remember character after option name */
4131 afterchar = arg[len];
4133 /* skip white space, allow ":set ai ?" */
4134 while (vim_iswhite(arg[len]))
4135 ++len;
4137 adding = FALSE;
4138 prepending = FALSE;
4139 removing = FALSE;
4140 if (arg[len] != NUL && arg[len + 1] == '=')
4142 if (arg[len] == '+')
4144 adding = TRUE; /* "+=" */
4145 ++len;
4147 else if (arg[len] == '^')
4149 prepending = TRUE; /* "^=" */
4150 ++len;
4152 else if (arg[len] == '-')
4154 removing = TRUE; /* "-=" */
4155 ++len;
4158 nextchar = arg[len];
4160 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4162 errmsg = (char_u *)N_("E518: Unknown option");
4163 goto skip;
4166 if (opt_idx >= 0)
4168 if (options[opt_idx].var == NULL) /* hidden option: skip */
4170 /* Only give an error message when requesting the value of
4171 * a hidden option, ignore setting it. */
4172 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4173 && (!(options[opt_idx].flags & P_BOOL)
4174 || nextchar == '?'))
4175 errmsg = (char_u *)N_("E519: Option not supported");
4176 goto skip;
4179 flags = options[opt_idx].flags;
4180 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4182 else
4184 flags = P_STRING;
4185 if (key < 0)
4187 key_name[0] = KEY2TERMCAP0(key);
4188 key_name[1] = KEY2TERMCAP1(key);
4190 else
4192 key_name[0] = KS_KEY;
4193 key_name[1] = (key & 0xff);
4197 /* Skip all options that are not window-local (used when showing
4198 * an already loaded buffer in a window). */
4199 if ((opt_flags & OPT_WINONLY)
4200 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4201 goto skip;
4203 /* Skip all options that are window-local (used for :vimgrep). */
4204 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4205 && options[opt_idx].var == VAR_WIN)
4206 goto skip;
4208 /* Disallow changing some options from modelines. */
4209 if (opt_flags & OPT_MODELINE)
4211 if (flags & P_SECURE)
4213 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4214 goto skip;
4216 #ifdef FEAT_DIFF
4217 /* In diff mode some options are overruled. This avoids that
4218 * 'foldmethod' becomes "marker" instead of "diff" and that
4219 * "wrap" gets set. */
4220 if (curwin->w_p_diff
4221 && (options[opt_idx].indir == PV_FDM
4222 || options[opt_idx].indir == PV_WRAP))
4223 goto skip;
4224 #endif
4227 #ifdef HAVE_SANDBOX
4228 /* Disallow changing some options in the sandbox */
4229 if (sandbox != 0 && (flags & P_SECURE))
4231 errmsg = (char_u *)_(e_sandbox);
4232 goto skip;
4234 #endif
4236 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4238 arg += len;
4239 cp_val = p_cp;
4240 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4242 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4244 cp_val = FALSE;
4245 arg += 3;
4247 else /* "opt&vi": set to Vi default */
4249 cp_val = TRUE;
4250 arg += 2;
4253 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4254 && arg[1] != NUL && !vim_iswhite(arg[1]))
4256 errmsg = e_trailing;
4257 goto skip;
4262 * allow '=' and ':' as MSDOS command.com allows only one
4263 * '=' character per "set" command line. grrr. (jw)
4265 if (nextchar == '?'
4266 || (prefix == 1
4267 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4268 && !(flags & P_BOOL)))
4271 * print value
4273 if (did_show)
4274 msg_putchar('\n'); /* cursor below last one */
4275 else
4277 gotocmdline(TRUE); /* cursor at status line */
4278 did_show = TRUE; /* remember that we did a line */
4280 if (opt_idx >= 0)
4282 showoneopt(&options[opt_idx], opt_flags);
4283 #ifdef FEAT_EVAL
4284 if (p_verbose > 0)
4286 /* Mention where the option was last set. */
4287 if (varp == options[opt_idx].var)
4288 last_set_msg(options[opt_idx].scriptID);
4289 else if ((int)options[opt_idx].indir & PV_WIN)
4290 last_set_msg(curwin->w_p_scriptID[
4291 (int)options[opt_idx].indir & PV_MASK]);
4292 else if ((int)options[opt_idx].indir & PV_BUF)
4293 last_set_msg(curbuf->b_p_scriptID[
4294 (int)options[opt_idx].indir & PV_MASK]);
4296 #endif
4298 else
4300 char_u *p;
4302 p = find_termcode(key_name);
4303 if (p == NULL)
4305 errmsg = (char_u *)N_("E518: Unknown option");
4306 goto skip;
4308 else
4309 (void)show_one_termcode(key_name, p, TRUE);
4311 if (nextchar != '?'
4312 && nextchar != NUL && !vim_iswhite(afterchar))
4313 errmsg = e_trailing;
4315 else
4317 if (flags & P_BOOL) /* boolean */
4319 if (nextchar == '=' || nextchar == ':')
4321 errmsg = e_invarg;
4322 goto skip;
4326 * ":set opt!": invert
4327 * ":set opt&": reset to default value
4328 * ":set opt<": reset to global value
4330 if (nextchar == '!')
4331 value = *(int *)(varp) ^ 1;
4332 else if (nextchar == '&')
4333 value = (int)(long)(long_i)options[opt_idx].def_val[
4334 ((flags & P_VI_DEF) || cp_val)
4335 ? VI_DEFAULT : VIM_DEFAULT];
4336 else if (nextchar == '<')
4338 /* For 'autoread' -1 means to use global value. */
4339 if ((int *)varp == &curbuf->b_p_ar
4340 && opt_flags == OPT_LOCAL)
4341 value = -1;
4342 else
4343 value = *(int *)get_varp_scope(&(options[opt_idx]),
4344 OPT_GLOBAL);
4346 else
4349 * ":set invopt": invert
4350 * ":set opt" or ":set noopt": set or reset
4352 if (nextchar != NUL && !vim_iswhite(afterchar))
4354 errmsg = e_trailing;
4355 goto skip;
4357 if (prefix == 2) /* inv */
4358 value = *(int *)(varp) ^ 1;
4359 else
4360 value = prefix;
4363 errmsg = set_bool_option(opt_idx, varp, (int)value,
4364 opt_flags);
4366 else /* numeric or string */
4368 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4369 || prefix != 1)
4371 errmsg = e_invarg;
4372 goto skip;
4375 if (flags & P_NUM) /* numeric */
4378 * Different ways to set a number option:
4379 * & set to default value
4380 * < set to global value
4381 * <xx> accept special key codes for 'wildchar'
4382 * c accept any non-digit for 'wildchar'
4383 * [-]0-9 set number
4384 * other error
4386 ++arg;
4387 if (nextchar == '&')
4388 value = (long)(long_i)options[opt_idx].def_val[
4389 ((flags & P_VI_DEF) || cp_val)
4390 ? VI_DEFAULT : VIM_DEFAULT];
4391 else if (nextchar == '<')
4392 value = *(long *)get_varp_scope(&(options[opt_idx]),
4393 OPT_GLOBAL);
4394 else if (((long *)varp == &p_wc
4395 || (long *)varp == &p_wcm)
4396 && (*arg == '<'
4397 || *arg == '^'
4398 || ((!arg[1] || vim_iswhite(arg[1]))
4399 && !VIM_ISDIGIT(*arg))))
4401 value = string_to_key(arg);
4402 if (value == 0 && (long *)varp != &p_wcm)
4404 errmsg = e_invarg;
4405 goto skip;
4408 /* allow negative numbers (for 'undolevels') */
4409 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4411 i = 0;
4412 if (*arg == '-')
4413 i = 1;
4414 #ifdef HAVE_STRTOL
4415 value = strtol((char *)arg, NULL, 0);
4416 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4417 i += 2;
4418 #else
4419 value = atol((char *)arg);
4420 #endif
4421 while (VIM_ISDIGIT(arg[i]))
4422 ++i;
4423 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4425 errmsg = e_invarg;
4426 goto skip;
4429 else
4431 errmsg = (char_u *)N_("E521: Number required after =");
4432 goto skip;
4435 if (adding)
4436 value = *(long *)varp + value;
4437 if (prepending)
4438 value = *(long *)varp * value;
4439 if (removing)
4440 value = *(long *)varp - value;
4441 errmsg = set_num_option(opt_idx, varp, value,
4442 errbuf, sizeof(errbuf), opt_flags);
4444 else if (opt_idx >= 0) /* string */
4446 char_u *save_arg = NULL;
4447 char_u *s = NULL;
4448 char_u *oldval; /* previous value if *varp */
4449 char_u *newval;
4450 char_u *origval;
4451 unsigned newlen;
4452 int comma;
4453 int bs;
4454 int new_value_alloced; /* new string option
4455 was allocated */
4457 /* When using ":set opt=val" for a global option
4458 * with a local value the local value will be
4459 * reset, use the global value here. */
4460 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4461 && ((int)options[opt_idx].indir & PV_BOTH))
4462 varp = options[opt_idx].var;
4464 /* The old value is kept until we are sure that the
4465 * new value is valid. */
4466 oldval = *(char_u **)varp;
4467 if (nextchar == '&') /* set to default val */
4469 newval = options[opt_idx].def_val[
4470 ((flags & P_VI_DEF) || cp_val)
4471 ? VI_DEFAULT : VIM_DEFAULT];
4472 if ((char_u **)varp == &p_bg)
4474 /* guess the value of 'background' */
4475 #ifdef FEAT_GUI
4476 if (gui.in_use)
4477 newval = gui_bg_default();
4478 else
4479 #endif
4480 newval = term_bg_default();
4483 /* expand environment variables and ~ (since the
4484 * default value was already expanded, only
4485 * required when an environment variable was set
4486 * later */
4487 if (newval == NULL)
4488 newval = empty_option;
4489 else
4491 s = option_expand(opt_idx, newval);
4492 if (s == NULL)
4493 s = newval;
4494 newval = vim_strsave(s);
4496 new_value_alloced = TRUE;
4498 else if (nextchar == '<') /* set to global val */
4500 newval = vim_strsave(*(char_u **)get_varp_scope(
4501 &(options[opt_idx]), OPT_GLOBAL));
4502 new_value_alloced = TRUE;
4504 else
4506 ++arg; /* jump to after the '=' or ':' */
4509 * Set 'keywordprg' to ":help" if an empty
4510 * value was passed to :set by the user.
4511 * Misuse errbuf[] for the resulting string.
4513 if (varp == (char_u *)&p_kp
4514 && (*arg == NUL || *arg == ' '))
4516 STRCPY(errbuf, ":help");
4517 save_arg = arg;
4518 arg = errbuf;
4521 * Convert 'whichwrap' number to string, for
4522 * backwards compatibility with Vim 3.0.
4523 * Misuse errbuf[] for the resulting string.
4525 else if (varp == (char_u *)&p_ww
4526 && VIM_ISDIGIT(*arg))
4528 *errbuf = NUL;
4529 i = getdigits(&arg);
4530 if (i & 1)
4531 STRCAT(errbuf, "b,");
4532 if (i & 2)
4533 STRCAT(errbuf, "s,");
4534 if (i & 4)
4535 STRCAT(errbuf, "h,l,");
4536 if (i & 8)
4537 STRCAT(errbuf, "<,>,");
4538 if (i & 16)
4539 STRCAT(errbuf, "[,],");
4540 if (*errbuf != NUL) /* remove trailing , */
4541 errbuf[STRLEN(errbuf) - 1] = NUL;
4542 save_arg = arg;
4543 arg = errbuf;
4546 * Remove '>' before 'dir' and 'bdir', for
4547 * backwards compatibility with version 3.0
4549 else if ( *arg == '>'
4550 && (varp == (char_u *)&p_dir
4551 || varp == (char_u *)&p_bdir))
4553 ++arg;
4556 /* When setting the local value of a global
4557 * option, the old value may be the global value. */
4558 if (((int)options[opt_idx].indir & PV_BOTH)
4559 && (opt_flags & OPT_LOCAL))
4560 origval = *(char_u **)get_varp(
4561 &options[opt_idx]);
4562 else
4563 origval = oldval;
4566 * Copy the new string into allocated memory.
4567 * Can't use set_string_option_direct(), because
4568 * we need to remove the backslashes.
4570 /* get a bit too much */
4571 newlen = (unsigned)STRLEN(arg) + 1;
4572 if (adding || prepending || removing)
4573 newlen += (unsigned)STRLEN(origval) + 1;
4574 newval = alloc(newlen);
4575 if (newval == NULL) /* out of mem, don't change */
4576 break;
4577 s = newval;
4580 * Copy the string, skip over escaped chars.
4581 * For MS-DOS and WIN32 backslashes before normal
4582 * file name characters are not removed, and keep
4583 * backslash at start, for "\\machine\path", but
4584 * do remove it for "\\\\machine\\path".
4585 * The reverse is found in ExpandOldSetting().
4587 while (*arg && !vim_iswhite(*arg))
4589 if (*arg == '\\' && arg[1] != NUL
4590 #ifdef BACKSLASH_IN_FILENAME
4591 && !((flags & P_EXPAND)
4592 && vim_isfilec(arg[1])
4593 && (arg[1] != '\\'
4594 || (s == newval
4595 && arg[2] != '\\')))
4596 #endif
4598 ++arg; /* remove backslash */
4599 #ifdef FEAT_MBYTE
4600 if (has_mbyte
4601 && (i = (*mb_ptr2len)(arg)) > 1)
4603 /* copy multibyte char */
4604 mch_memmove(s, arg, (size_t)i);
4605 arg += i;
4606 s += i;
4608 else
4609 #endif
4610 *s++ = *arg++;
4612 *s = NUL;
4615 * Expand environment variables and ~.
4616 * Don't do it when adding without inserting a
4617 * comma.
4619 if (!(adding || prepending || removing)
4620 || (flags & P_COMMA))
4622 s = option_expand(opt_idx, newval);
4623 if (s != NULL)
4625 vim_free(newval);
4626 newlen = (unsigned)STRLEN(s) + 1;
4627 if (adding || prepending || removing)
4628 newlen += (unsigned)STRLEN(origval) + 1;
4629 newval = alloc(newlen);
4630 if (newval == NULL)
4631 break;
4632 STRCPY(newval, s);
4636 /* locate newval[] in origval[] when removing it
4637 * and when adding to avoid duplicates */
4638 i = 0; /* init for GCC */
4639 if (removing || (flags & P_NODUP))
4641 i = (int)STRLEN(newval);
4642 bs = 0;
4643 for (s = origval; *s; ++s)
4645 if ((!(flags & P_COMMA)
4646 || s == origval
4647 || (s[-1] == ',' && !(bs & 1)))
4648 && STRNCMP(s, newval, i) == 0
4649 && (!(flags & P_COMMA)
4650 || s[i] == ','
4651 || s[i] == NUL))
4652 break;
4653 /* Count backspaces. Only a comma with an
4654 * even number of backspaces before it is
4655 * recognized as a separator */
4656 if (s > origval && s[-1] == '\\')
4657 ++bs;
4658 else
4659 bs = 0;
4662 /* do not add if already there */
4663 if ((adding || prepending) && *s)
4665 prepending = FALSE;
4666 adding = FALSE;
4667 STRCPY(newval, origval);
4671 /* concatenate the two strings; add a ',' if
4672 * needed */
4673 if (adding || prepending)
4675 comma = ((flags & P_COMMA) && *origval != NUL
4676 && *newval != NUL);
4677 if (adding)
4679 i = (int)STRLEN(origval);
4680 mch_memmove(newval + i + comma, newval,
4681 STRLEN(newval) + 1);
4682 mch_memmove(newval, origval, (size_t)i);
4684 else
4686 i = (int)STRLEN(newval);
4687 STRMOVE(newval + i + comma, origval);
4689 if (comma)
4690 newval[i] = ',';
4693 /* Remove newval[] from origval[]. (Note: "i" has
4694 * been set above and is used here). */
4695 if (removing)
4697 STRCPY(newval, origval);
4698 if (*s)
4700 /* may need to remove a comma */
4701 if (flags & P_COMMA)
4703 if (s == origval)
4705 /* include comma after string */
4706 if (s[i] == ',')
4707 ++i;
4709 else
4711 /* include comma before string */
4712 --s;
4713 ++i;
4716 STRMOVE(newval + (s - origval), s + i);
4720 if (flags & P_FLAGLIST)
4722 /* Remove flags that appear twice. */
4723 for (s = newval; *s; ++s)
4724 if ((!(flags & P_COMMA) || *s != ',')
4725 && vim_strchr(s + 1, *s) != NULL)
4727 STRMOVE(s, s + 1);
4728 --s;
4732 if (save_arg != NULL) /* number for 'whichwrap' */
4733 arg = save_arg;
4734 new_value_alloced = TRUE;
4737 /* Set the new value. */
4738 *(char_u **)(varp) = newval;
4740 /* Handle side effects, and set the global value for
4741 * ":set" on local options. */
4742 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4743 new_value_alloced, oldval, errbuf, opt_flags);
4745 /* If error detected, print the error message. */
4746 if (errmsg != NULL)
4747 goto skip;
4749 else /* key code option */
4751 char_u *p;
4753 if (nextchar == '&')
4755 if (add_termcap_entry(key_name, TRUE) == FAIL)
4756 errmsg = (char_u *)N_("E522: Not found in termcap");
4758 else
4760 ++arg; /* jump to after the '=' or ':' */
4761 for (p = arg; *p && !vim_iswhite(*p); ++p)
4762 if (*p == '\\' && p[1] != NUL)
4763 ++p;
4764 nextchar = *p;
4765 *p = NUL;
4766 add_termcode(key_name, arg, FALSE);
4767 *p = nextchar;
4769 if (full_screen)
4770 ttest(FALSE);
4771 redraw_all_later(CLEAR);
4775 if (opt_idx >= 0)
4776 did_set_option(opt_idx, opt_flags,
4777 !prepending && !adding && !removing);
4780 skip:
4782 * Advance to next argument.
4783 * - skip until a blank found, taking care of backslashes
4784 * - skip blanks
4785 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4787 for (i = 0; i < 2 ; ++i)
4789 while (*arg != NUL && !vim_iswhite(*arg))
4790 if (*arg++ == '\\' && *arg != NUL)
4791 ++arg;
4792 arg = skipwhite(arg);
4793 if (*arg != '=')
4794 break;
4798 if (errmsg != NULL)
4800 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
4801 i = (int)STRLEN(IObuff) + 2;
4802 if (i + (arg - startarg) < IOSIZE)
4804 /* append the argument with the error */
4805 STRCAT(IObuff, ": ");
4806 mch_memmove(IObuff + i, startarg, (arg - startarg));
4807 IObuff[i + (arg - startarg)] = NUL;
4809 /* make sure all characters are printable */
4810 trans_characters(IObuff, IOSIZE);
4812 ++no_wait_return; /* wait_return done later */
4813 emsg(IObuff); /* show error highlighted */
4814 --no_wait_return;
4816 return FAIL;
4819 arg = skipwhite(arg);
4822 theend:
4823 if (silent_mode && did_show)
4825 /* After displaying option values in silent mode. */
4826 silent_mode = FALSE;
4827 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4828 msg_putchar('\n');
4829 cursor_on(); /* msg_start() switches it off */
4830 out_flush();
4831 silent_mode = TRUE;
4832 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4835 return OK;
4839 * Call this when an option has been given a new value through a user command.
4840 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4842 static void
4843 did_set_option(opt_idx, opt_flags, new_value)
4844 int opt_idx;
4845 int opt_flags; /* possibly with OPT_MODELINE */
4846 int new_value; /* value was replaced completely */
4848 long_u *p;
4850 options[opt_idx].flags |= P_WAS_SET;
4852 /* When an option is set in the sandbox, from a modeline or in secure mode
4853 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
4854 * flag. */
4855 p = insecure_flag(opt_idx, opt_flags);
4856 if (secure
4857 #ifdef HAVE_SANDBOX
4858 || sandbox != 0
4859 #endif
4860 || (opt_flags & OPT_MODELINE))
4861 *p = *p | P_INSECURE;
4862 else if (new_value)
4863 *p = *p & ~P_INSECURE;
4866 static char_u *
4867 illegal_char(errbuf, c)
4868 char_u *errbuf;
4869 int c;
4871 if (errbuf == NULL)
4872 return (char_u *)"";
4873 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
4874 (char *)transchar(c));
4875 return errbuf;
4879 * Convert a key name or string into a key value.
4880 * Used for 'wildchar' and 'cedit' options.
4882 static int
4883 string_to_key(arg)
4884 char_u *arg;
4886 if (*arg == '<')
4887 return find_key_option(arg + 1);
4888 if (*arg == '^')
4889 return Ctrl_chr(arg[1]);
4890 return *arg;
4893 #ifdef FEAT_CMDWIN
4895 * Check value of 'cedit' and set cedit_key.
4896 * Returns NULL if value is OK, error message otherwise.
4898 static char_u *
4899 check_cedit()
4901 int n;
4903 if (*p_cedit == NUL)
4904 cedit_key = -1;
4905 else
4907 n = string_to_key(p_cedit);
4908 if (vim_isprintc(n))
4909 return e_invarg;
4910 cedit_key = n;
4912 return NULL;
4914 #endif
4916 #ifdef FEAT_TITLE
4918 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4919 * maketitle() to create and display it.
4920 * When switching the title or icon off, call mch_restore_title() to get
4921 * the old value back.
4923 static void
4924 did_set_title(icon)
4925 int icon; /* Did set icon instead of title */
4927 if (starting != NO_SCREEN
4928 #ifdef FEAT_GUI
4929 && !gui.starting
4930 #endif
4933 maketitle();
4934 if (icon)
4936 if (!p_icon)
4937 mch_restore_title(2);
4939 else
4941 if (!p_title)
4942 mch_restore_title(1);
4946 #endif
4949 * set_options_bin - called when 'bin' changes value.
4951 void
4952 set_options_bin(oldval, newval, opt_flags)
4953 int oldval;
4954 int newval;
4955 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4958 * The option values that are changed when 'bin' changes are
4959 * copied when 'bin is set and restored when 'bin' is reset.
4961 if (newval)
4963 if (!oldval) /* switched on */
4965 if (!(opt_flags & OPT_GLOBAL))
4967 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4968 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4969 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4970 curbuf->b_p_et_nobin = curbuf->b_p_et;
4972 if (!(opt_flags & OPT_LOCAL))
4974 p_tw_nobin = p_tw;
4975 p_wm_nobin = p_wm;
4976 p_ml_nobin = p_ml;
4977 p_et_nobin = p_et;
4981 if (!(opt_flags & OPT_GLOBAL))
4983 curbuf->b_p_tw = 0; /* no automatic line wrap */
4984 curbuf->b_p_wm = 0; /* no automatic line wrap */
4985 curbuf->b_p_ml = 0; /* no modelines */
4986 curbuf->b_p_et = 0; /* no expandtab */
4988 if (!(opt_flags & OPT_LOCAL))
4990 p_tw = 0;
4991 p_wm = 0;
4992 p_ml = FALSE;
4993 p_et = FALSE;
4994 p_bin = TRUE; /* needed when called for the "-b" argument */
4997 else if (oldval) /* switched off */
4999 if (!(opt_flags & OPT_GLOBAL))
5001 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5002 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5003 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5004 curbuf->b_p_et = curbuf->b_p_et_nobin;
5006 if (!(opt_flags & OPT_LOCAL))
5008 p_tw = p_tw_nobin;
5009 p_wm = p_wm_nobin;
5010 p_ml = p_ml_nobin;
5011 p_et = p_et_nobin;
5016 #ifdef FEAT_VIMINFO
5018 * Find the parameter represented by the given character (eg ', :, ", or /),
5019 * and return its associated value in the 'viminfo' string.
5020 * Only works for number parameters, not for 'r' or 'n'.
5021 * If the parameter is not specified in the string or there is no following
5022 * number, return -1.
5025 get_viminfo_parameter(type)
5026 int type;
5028 char_u *p;
5030 p = find_viminfo_parameter(type);
5031 if (p != NULL && VIM_ISDIGIT(*p))
5032 return atoi((char *)p);
5033 return -1;
5037 * Find the parameter represented by the given character (eg ''', ':', '"', or
5038 * '/') in the 'viminfo' option and return a pointer to the string after it.
5039 * Return NULL if the parameter is not specified in the string.
5041 char_u *
5042 find_viminfo_parameter(type)
5043 int type;
5045 char_u *p;
5047 for (p = p_viminfo; *p; ++p)
5049 if (*p == type)
5050 return p + 1;
5051 if (*p == 'n') /* 'n' is always the last one */
5052 break;
5053 p = vim_strchr(p, ','); /* skip until next ',' */
5054 if (p == NULL) /* hit the end without finding parameter */
5055 break;
5057 return NULL;
5059 #endif
5062 * Expand environment variables for some string options.
5063 * These string options cannot be indirect!
5064 * If "val" is NULL expand the current value of the option.
5065 * Return pointer to NameBuff, or NULL when not expanded.
5067 static char_u *
5068 option_expand(opt_idx, val)
5069 int opt_idx;
5070 char_u *val;
5072 /* if option doesn't need expansion nothing to do */
5073 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5074 return NULL;
5076 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5077 * expand_env() would truncate the string. */
5078 if (val != NULL && STRLEN(val) > MAXPATHL)
5079 return NULL;
5081 if (val == NULL)
5082 val = *(char_u **)options[opt_idx].var;
5085 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5086 * Escape spaces when expanding 'tags', they are used to separate file
5087 * names.
5088 * For 'spellsuggest' expand after "file:".
5090 expand_env_esc(val, NameBuff, MAXPATHL,
5091 (char_u **)options[opt_idx].var == &p_tags, FALSE,
5092 #ifdef FEAT_SPELL
5093 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5094 #endif
5095 NULL);
5096 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5097 return NULL;
5099 return NameBuff;
5103 * After setting various option values: recompute variables that depend on
5104 * option values.
5106 static void
5107 didset_options()
5109 /* initialize the table for 'iskeyword' et.al. */
5110 (void)init_chartab();
5112 #ifdef FEAT_MBYTE
5113 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5114 #endif
5115 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5116 #ifdef FEAT_SESSION
5117 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5118 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5119 #endif
5120 #ifdef FEAT_FOLDING
5121 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5122 #endif
5123 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5124 #ifdef FEAT_VIRTUALEDIT
5125 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5126 #endif
5127 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5128 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5129 #endif
5130 #ifdef FEAT_SPELL
5131 (void)spell_check_msm();
5132 (void)spell_check_sps();
5133 (void)compile_cap_prog(curbuf);
5134 #endif
5135 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5136 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5137 #endif
5138 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5139 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5140 #endif
5141 #ifdef FEAT_CMDWIN
5142 /* set cedit_key */
5143 (void)check_cedit();
5144 #endif
5145 #ifdef FEAT_VARTABS
5146 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_ary);
5147 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_ary);
5148 #endif
5152 * Check for string options that are NULL (normally only termcap options).
5154 void
5155 check_options()
5157 int opt_idx;
5159 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5160 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5161 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5165 * Check string options in a buffer for NULL value.
5167 void
5168 check_buf_options(buf)
5169 buf_T *buf;
5171 #if defined(FEAT_QUICKFIX)
5172 check_string_option(&buf->b_p_bh);
5173 check_string_option(&buf->b_p_bt);
5174 #endif
5175 #ifdef FEAT_MBYTE
5176 check_string_option(&buf->b_p_fenc);
5177 #endif
5178 check_string_option(&buf->b_p_ff);
5179 #ifdef FEAT_FIND_ID
5180 check_string_option(&buf->b_p_def);
5181 check_string_option(&buf->b_p_inc);
5182 # ifdef FEAT_EVAL
5183 check_string_option(&buf->b_p_inex);
5184 # endif
5185 #endif
5186 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5187 check_string_option(&buf->b_p_inde);
5188 check_string_option(&buf->b_p_indk);
5189 #endif
5190 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5191 check_string_option(&buf->b_p_bexpr);
5192 #endif
5193 #if defined(FEAT_EVAL)
5194 check_string_option(&buf->b_p_fex);
5195 #endif
5196 #ifdef FEAT_CRYPT
5197 check_string_option(&buf->b_p_key);
5198 #endif
5199 check_string_option(&buf->b_p_kp);
5200 check_string_option(&buf->b_p_mps);
5201 check_string_option(&buf->b_p_fo);
5202 check_string_option(&buf->b_p_flp);
5203 check_string_option(&buf->b_p_isk);
5204 #ifdef FEAT_COMMENTS
5205 check_string_option(&buf->b_p_com);
5206 #endif
5207 #ifdef FEAT_FOLDING
5208 check_string_option(&buf->b_p_cms);
5209 #endif
5210 check_string_option(&buf->b_p_nf);
5211 #ifdef FEAT_TEXTOBJ
5212 check_string_option(&buf->b_p_qe);
5213 #endif
5214 #ifdef FEAT_SYN_HL
5215 check_string_option(&buf->b_p_syn);
5216 #endif
5217 #ifdef FEAT_SPELL
5218 check_string_option(&buf->b_p_spc);
5219 check_string_option(&buf->b_p_spf);
5220 check_string_option(&buf->b_p_spl);
5221 #endif
5222 #ifdef FEAT_SEARCHPATH
5223 check_string_option(&buf->b_p_sua);
5224 #endif
5225 #ifdef FEAT_CINDENT
5226 check_string_option(&buf->b_p_cink);
5227 check_string_option(&buf->b_p_cino);
5228 #endif
5229 #ifdef FEAT_AUTOCMD
5230 check_string_option(&buf->b_p_ft);
5231 #endif
5232 #ifdef FEAT_OSFILETYPE
5233 check_string_option(&buf->b_p_oft);
5234 #endif
5235 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5236 check_string_option(&buf->b_p_cinw);
5237 #endif
5238 #ifdef FEAT_INS_EXPAND
5239 check_string_option(&buf->b_p_cpt);
5240 #endif
5241 #ifdef FEAT_COMPL_FUNC
5242 check_string_option(&buf->b_p_cfu);
5243 check_string_option(&buf->b_p_ofu);
5244 #endif
5245 #ifdef FEAT_KEYMAP
5246 check_string_option(&buf->b_p_keymap);
5247 #endif
5248 #ifdef FEAT_QUICKFIX
5249 check_string_option(&buf->b_p_gp);
5250 check_string_option(&buf->b_p_mp);
5251 check_string_option(&buf->b_p_efm);
5252 #endif
5253 check_string_option(&buf->b_p_ep);
5254 check_string_option(&buf->b_p_path);
5255 check_string_option(&buf->b_p_tags);
5256 #ifdef FEAT_INS_EXPAND
5257 check_string_option(&buf->b_p_dict);
5258 check_string_option(&buf->b_p_tsr);
5259 #endif
5260 #ifdef FEAT_VARTABS
5261 check_string_option(&buf->b_p_vsts);
5262 check_string_option(&buf->b_p_vts);
5263 #endif
5267 * Free the string allocated for an option.
5268 * Checks for the string being empty_option. This may happen if we're out of
5269 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5270 * check_options().
5271 * Does NOT check for P_ALLOCED flag!
5273 void
5274 free_string_option(p)
5275 char_u *p;
5277 if (p != empty_option)
5278 vim_free(p);
5281 void
5282 clear_string_option(pp)
5283 char_u **pp;
5285 if (*pp != empty_option)
5286 vim_free(*pp);
5287 *pp = empty_option;
5290 static void
5291 check_string_option(pp)
5292 char_u **pp;
5294 if (*pp == NULL)
5295 *pp = empty_option;
5299 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5301 void
5302 set_term_option_alloced(p)
5303 char_u **p;
5305 int opt_idx;
5307 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5308 if (options[opt_idx].var == (char_u *)p)
5310 options[opt_idx].flags |= P_ALLOCED;
5311 return;
5313 return; /* cannot happen: didn't find it! */
5316 #if defined(FEAT_EVAL) || defined(PROTO)
5318 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5319 * Return FALSE when it wasn't.
5320 * Return -1 for an unknown option.
5323 was_set_insecurely(opt, opt_flags)
5324 char_u *opt;
5325 int opt_flags;
5327 int idx = findoption(opt);
5328 long_u *flagp;
5330 if (idx >= 0)
5332 flagp = insecure_flag(idx, opt_flags);
5333 return (*flagp & P_INSECURE) != 0;
5335 EMSG2(_(e_intern2), "was_set_insecurely()");
5336 return -1;
5340 * Get a pointer to the flags used for the P_INSECURE flag of option
5341 * "opt_idx". For some local options a local flags field is used.
5343 static long_u *
5344 insecure_flag(opt_idx, opt_flags)
5345 int opt_idx;
5346 int opt_flags;
5348 if (opt_flags & OPT_LOCAL)
5349 switch ((int)options[opt_idx].indir)
5351 #ifdef FEAT_STL_OPT
5352 case PV_STL: return &curwin->w_p_stl_flags;
5353 #endif
5354 #ifdef FEAT_EVAL
5355 # ifdef FEAT_FOLDING
5356 case PV_FDE: return &curwin->w_p_fde_flags;
5357 case PV_FDT: return &curwin->w_p_fdt_flags;
5358 # endif
5359 # ifdef FEAT_BEVAL
5360 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5361 # endif
5362 # if defined(FEAT_CINDENT)
5363 case PV_INDE: return &curbuf->b_p_inde_flags;
5364 # endif
5365 case PV_FEX: return &curbuf->b_p_fex_flags;
5366 # ifdef FEAT_FIND_ID
5367 case PV_INEX: return &curbuf->b_p_inex_flags;
5368 # endif
5369 #endif
5372 /* Nothing special, return global flags field. */
5373 return &options[opt_idx].flags;
5375 #endif
5377 #ifdef FEAT_TITLE
5378 static void redraw_titles __ARGS((void));
5381 * Redraw the window title and/or tab page text later.
5383 static void redraw_titles()
5385 need_maketitle = TRUE;
5386 # ifdef FEAT_WINDOWS
5387 redraw_tabline = TRUE;
5388 # endif
5390 #endif
5393 * Set a string option to a new value (without checking the effect).
5394 * The string is copied into allocated memory.
5395 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
5396 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
5397 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
5399 void
5400 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
5401 char_u *name;
5402 int opt_idx;
5403 char_u *val;
5404 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5405 int set_sid UNUSED;
5407 char_u *s;
5408 char_u **varp;
5409 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5410 int idx = opt_idx;
5412 if (idx == -1) /* use name */
5414 idx = findoption(name);
5415 if (idx < 0) /* not found (should not happen) */
5417 EMSG2(_(e_intern2), "set_string_option_direct()");
5418 return;
5422 if (options[idx].var == NULL) /* can't set hidden option */
5423 return;
5425 s = vim_strsave(val);
5426 if (s != NULL)
5428 varp = (char_u **)get_varp_scope(&(options[idx]),
5429 both ? OPT_LOCAL : opt_flags);
5430 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
5431 free_string_option(*varp);
5432 *varp = s;
5434 /* For buffer/window local option may also set the global value. */
5435 if (both)
5436 set_string_option_global(idx, varp);
5438 options[idx].flags |= P_ALLOCED;
5440 /* When setting both values of a global option with a local value,
5441 * make the local value empty, so that the global value is used. */
5442 if (((int)options[idx].indir & PV_BOTH) && both)
5444 free_string_option(*varp);
5445 *varp = empty_option;
5447 # ifdef FEAT_EVAL
5448 if (set_sid != SID_NONE)
5449 set_option_scriptID_idx(idx, opt_flags,
5450 set_sid == 0 ? current_SID : set_sid);
5451 # endif
5456 * Set global value for string option when it's a local option.
5458 static void
5459 set_string_option_global(opt_idx, varp)
5460 int opt_idx; /* option index */
5461 char_u **varp; /* pointer to option variable */
5463 char_u **p, *s;
5465 /* the global value is always allocated */
5466 if (options[opt_idx].var == VAR_WIN)
5467 p = (char_u **)GLOBAL_WO(varp);
5468 else
5469 p = (char_u **)options[opt_idx].var;
5470 if (options[opt_idx].indir != PV_NONE
5471 && p != varp
5472 && (s = vim_strsave(*varp)) != NULL)
5474 free_string_option(*p);
5475 *p = s;
5480 * Set a string option to a new value, and handle the effects.
5482 static void
5483 set_string_option(opt_idx, value, opt_flags)
5484 int opt_idx;
5485 char_u *value;
5486 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5488 char_u *s;
5489 char_u **varp;
5490 char_u *oldval;
5492 if (options[opt_idx].var == NULL) /* don't set hidden option */
5493 return;
5495 s = vim_strsave(value);
5496 if (s != NULL)
5498 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5499 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5500 ? (((int)options[opt_idx].indir & PV_BOTH)
5501 ? OPT_GLOBAL : OPT_LOCAL)
5502 : opt_flags);
5503 oldval = *varp;
5504 *varp = s;
5505 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5506 opt_flags) == NULL)
5507 did_set_option(opt_idx, opt_flags, TRUE);
5512 * Handle string options that need some action to perform when changed.
5513 * Returns NULL for success, or an error message for an error.
5515 static char_u *
5516 did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5517 opt_flags)
5518 int opt_idx; /* index in options[] table */
5519 char_u **varp; /* pointer to the option variable */
5520 int new_value_alloced; /* new value was allocated */
5521 char_u *oldval; /* previous value of the option */
5522 char_u *errbuf; /* buffer for errors, or NULL */
5523 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5525 char_u *errmsg = NULL;
5526 char_u *s, *p;
5527 int did_chartab = FALSE;
5528 char_u **gvarp;
5529 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
5530 #ifdef FEAT_GUI
5531 /* set when changing an option that only requires a redraw in the GUI */
5532 int redraw_gui_only = FALSE;
5533 #endif
5535 /* Get the global option to compare with, otherwise we would have to check
5536 * two values for all local options. */
5537 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5539 /* Disallow changing some options from secure mode */
5540 if ((secure
5541 #ifdef HAVE_SANDBOX
5542 || sandbox != 0
5543 #endif
5544 ) && (options[opt_idx].flags & P_SECURE))
5546 errmsg = e_secure;
5549 /* Check for a "normal" file name in some options. Disallow a path
5550 * separator (slash and/or backslash), wildcards and characters that are
5551 * often illegal in a file name. */
5552 else if ((options[opt_idx].flags & P_NFNAME)
5553 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
5555 errmsg = e_invarg;
5558 /* 'term' */
5559 else if (varp == &T_NAME)
5561 if (T_NAME[0] == NUL)
5562 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5563 #ifdef FEAT_GUI
5564 if (gui.in_use)
5565 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5566 else if (term_is_gui(T_NAME))
5567 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5568 #endif
5569 else if (set_termname(T_NAME) == FAIL)
5570 errmsg = (char_u *)N_("E522: Not found in termcap");
5571 else
5572 /* Screen colors may have changed. */
5573 redraw_later_clear();
5576 /* 'backupcopy' */
5577 else if (varp == &p_bkc)
5579 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5580 errmsg = e_invarg;
5581 if (((bkc_flags & BKC_AUTO) != 0)
5582 + ((bkc_flags & BKC_YES) != 0)
5583 + ((bkc_flags & BKC_NO) != 0) != 1)
5585 /* Must have exactly one of "auto", "yes" and "no". */
5586 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5587 errmsg = e_invarg;
5591 /* 'backupext' and 'patchmode' */
5592 else if (varp == &p_bex || varp == &p_pm)
5594 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5595 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5596 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5600 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5601 * If the new option is invalid, use old value. 'lisp' option: refill
5602 * chartab[] for '-' char
5604 else if ( varp == &p_isi
5605 || varp == &(curbuf->b_p_isk)
5606 || varp == &p_isp
5607 || varp == &p_isf)
5609 if (init_chartab() == FAIL)
5611 did_chartab = TRUE; /* need to restore it below */
5612 errmsg = e_invarg; /* error in value */
5616 /* 'helpfile' */
5617 else if (varp == &p_hf)
5619 /* May compute new values for $VIM and $VIMRUNTIME */
5620 if (didset_vim)
5622 vim_setenv((char_u *)"VIM", (char_u *)"");
5623 didset_vim = FALSE;
5625 if (didset_vimruntime)
5627 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5628 didset_vimruntime = FALSE;
5632 #ifdef FEAT_MULTI_LANG
5633 /* 'helplang' */
5634 else if (varp == &p_hlg)
5636 /* Check for "", "ab", "ab,cd", etc. */
5637 for (s = p_hlg; *s != NUL; s += 3)
5639 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5641 errmsg = e_invarg;
5642 break;
5644 if (s[2] == NUL)
5645 break;
5648 #endif
5650 /* 'highlight' */
5651 else if (varp == &p_hl)
5653 if (highlight_changed() == FAIL)
5654 errmsg = e_invarg; /* invalid flags */
5657 /* 'nrformats' */
5658 else if (gvarp == &p_nf)
5660 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5661 errmsg = e_invarg;
5664 #ifdef FEAT_SESSION
5665 /* 'sessionoptions' */
5666 else if (varp == &p_ssop)
5668 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5669 errmsg = e_invarg;
5670 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5672 /* Don't allow both "sesdir" and "curdir". */
5673 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5674 errmsg = e_invarg;
5677 /* 'viewoptions' */
5678 else if (varp == &p_vop)
5680 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5681 errmsg = e_invarg;
5683 #endif
5685 /* 'scrollopt' */
5686 #ifdef FEAT_SCROLLBIND
5687 else if (varp == &p_sbo)
5689 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5690 errmsg = e_invarg;
5692 #endif
5694 /* 'ambiwidth' */
5695 #ifdef FEAT_MBYTE
5696 else if (varp == &p_ambw)
5698 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5699 errmsg = e_invarg;
5701 #endif
5703 /* 'background' */
5704 else if (varp == &p_bg)
5706 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5708 #ifdef FEAT_EVAL
5709 int dark = (*p_bg == 'd');
5710 #endif
5712 init_highlight(FALSE, FALSE);
5714 #ifdef FEAT_EVAL
5715 if (dark != (*p_bg == 'd')
5716 && get_var_value((char_u *)"g:colors_name") != NULL)
5718 /* The color scheme must have set 'background' back to another
5719 * value, that's not what we want here. Disable the color
5720 * scheme and set the colors again. */
5721 do_unlet((char_u *)"g:colors_name", TRUE);
5722 free_string_option(p_bg);
5723 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5724 check_string_option(&p_bg);
5725 init_highlight(FALSE, FALSE);
5727 #endif
5729 else
5730 errmsg = e_invarg;
5733 /* 'wildmode' */
5734 else if (varp == &p_wim)
5736 if (check_opt_wim() == FAIL)
5737 errmsg = e_invarg;
5740 #ifdef FEAT_CMDL_COMPL
5741 /* 'wildoptions' */
5742 else if (varp == &p_wop)
5744 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5745 errmsg = e_invarg;
5747 #endif
5749 #ifdef FEAT_WAK
5750 /* 'winaltkeys' */
5751 else if (varp == &p_wak)
5753 if (*p_wak == NUL
5754 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5755 errmsg = e_invarg;
5756 # ifdef FEAT_MENU
5757 # ifdef FEAT_GUI_MOTIF
5758 else if (gui.in_use)
5759 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5760 # else
5761 # ifdef FEAT_GUI_GTK
5762 else if (gui.in_use)
5763 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5764 # endif
5765 # endif
5766 # endif
5768 #endif
5770 #ifdef FEAT_AUTOCMD
5771 /* 'eventignore' */
5772 else if (varp == &p_ei)
5774 if (check_ei() == FAIL)
5775 errmsg = e_invarg;
5777 #endif
5779 #ifdef FEAT_MBYTE
5780 /* 'encoding' and 'fileencoding' */
5781 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5783 if (gvarp == &p_fenc)
5785 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
5786 errmsg = e_modifiable;
5787 else if (vim_strchr(*varp, ',') != NULL)
5788 /* No comma allowed in 'fileencoding'; catches confusing it
5789 * with 'fileencodings'. */
5790 errmsg = e_invarg;
5791 else
5793 # ifdef FEAT_TITLE
5794 /* May show a "+" in the title now. */
5795 redraw_titles();
5796 # endif
5797 /* Add 'fileencoding' to the swap file. */
5798 ml_setflags(curbuf);
5801 if (errmsg == NULL)
5803 /* canonize the value, so that STRCMP() can be used on it */
5804 p = enc_canonize(*varp);
5805 if (p != NULL)
5807 vim_free(*varp);
5808 *varp = p;
5810 if (varp == &p_enc)
5812 errmsg = mb_init();
5813 # ifdef FEAT_TITLE
5814 redraw_titles();
5815 # endif
5819 # if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5820 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5822 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5823 if (STRCMP(p_tenc, "utf-8") != 0)
5824 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5826 # endif
5828 if (errmsg == NULL)
5830 # ifdef FEAT_KEYMAP
5831 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5832 * (with another encoding). */
5833 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5834 (void)keymap_init();
5835 # endif
5837 /* When 'termencoding' is not empty and 'encoding' changes or when
5838 * 'termencoding' changes, need to setup for keyboard input and
5839 * display output conversion. */
5840 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5842 convert_setup(&input_conv, p_tenc, p_enc);
5843 convert_setup(&output_conv, p_enc, p_tenc);
5846 # if defined(WIN3264) && defined(FEAT_MBYTE)
5847 /* $HOME may have characters in active code page. */
5848 if (varp == &p_enc)
5849 init_homedir();
5850 # endif
5853 #endif
5855 #if defined(FEAT_POSTSCRIPT)
5856 else if (varp == &p_penc)
5858 /* Canonize printencoding if VIM standard one */
5859 p = enc_canonize(p_penc);
5860 if (p != NULL)
5862 vim_free(p_penc);
5863 p_penc = p;
5865 else
5867 /* Ensure lower case and '-' for '_' */
5868 for (s = p_penc; *s != NUL; s++)
5870 if (*s == '_')
5871 *s = '-';
5872 else
5873 *s = TOLOWER_ASC(*s);
5877 #endif
5879 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
5880 else if (varp == &p_imak)
5882 if (gui.in_use && !im_xim_isvalid_imactivate())
5883 errmsg = e_invarg;
5885 #endif
5887 #ifdef FEAT_KEYMAP
5888 else if (varp == &curbuf->b_p_keymap)
5890 /* load or unload key mapping tables */
5891 errmsg = keymap_init();
5893 if (errmsg == NULL)
5895 if (*curbuf->b_p_keymap != NUL)
5897 /* Installed a new keymap, switch on using it. */
5898 curbuf->b_p_iminsert = B_IMODE_LMAP;
5899 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5900 curbuf->b_p_imsearch = B_IMODE_LMAP;
5902 else
5904 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5905 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5906 curbuf->b_p_iminsert = B_IMODE_NONE;
5907 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5908 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5910 if ((opt_flags & OPT_LOCAL) == 0)
5912 set_iminsert_global();
5913 set_imsearch_global();
5915 # ifdef FEAT_WINDOWS
5916 status_redraw_curbuf();
5917 # endif
5920 #endif
5922 /* 'fileformat' */
5923 else if (gvarp == &p_ff)
5925 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5926 errmsg = e_modifiable;
5927 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5928 errmsg = e_invarg;
5929 else
5931 /* may also change 'textmode' */
5932 if (get_fileformat(curbuf) == EOL_DOS)
5933 curbuf->b_p_tx = TRUE;
5934 else
5935 curbuf->b_p_tx = FALSE;
5936 #ifdef FEAT_TITLE
5937 redraw_titles();
5938 #endif
5939 /* update flag in swap file */
5940 ml_setflags(curbuf);
5941 /* Redraw needed when switching to/from "mac": a CR in the text
5942 * will be displayed differently. */
5943 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5944 redraw_curbuf_later(NOT_VALID);
5948 /* 'fileformats' */
5949 else if (varp == &p_ffs)
5951 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5952 errmsg = e_invarg;
5953 else
5955 /* also change 'textauto' */
5956 if (*p_ffs == NUL)
5957 p_ta = FALSE;
5958 else
5959 p_ta = TRUE;
5963 #if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5964 /* 'cryptkey' */
5965 else if (gvarp == &p_key)
5967 /* Make sure the ":set" command doesn't show the new value in the
5968 * history. */
5969 remove_key_from_history();
5971 #endif
5973 /* 'matchpairs' */
5974 else if (gvarp == &p_mps)
5976 /* Check for "x:y,x:y" */
5977 for (p = *varp; *p != NUL; p += 4)
5979 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5981 errmsg = e_invarg;
5982 break;
5984 if (p[3] == NUL)
5985 break;
5989 #ifdef FEAT_COMMENTS
5990 /* 'comments' */
5991 else if (gvarp == &p_com)
5993 for (s = *varp; *s; )
5995 while (*s && *s != ':')
5997 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5998 && !VIM_ISDIGIT(*s) && *s != '-')
6000 errmsg = illegal_char(errbuf, *s);
6001 break;
6003 ++s;
6005 if (*s++ == NUL)
6006 errmsg = (char_u *)N_("E524: Missing colon");
6007 else if (*s == ',' || *s == NUL)
6008 errmsg = (char_u *)N_("E525: Zero length string");
6009 if (errmsg != NULL)
6010 break;
6011 while (*s && *s != ',')
6013 if (*s == '\\' && s[1] != NUL)
6014 ++s;
6015 ++s;
6017 s = skip_to_option_part(s);
6020 #endif
6022 /* 'listchars' */
6023 else if (varp == &p_lcs)
6025 errmsg = set_chars_option(varp);
6028 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6029 /* 'fillchars' */
6030 else if (varp == &p_fcs)
6032 errmsg = set_chars_option(varp);
6034 #endif
6036 #ifdef FEAT_CMDWIN
6037 /* 'cedit' */
6038 else if (varp == &p_cedit)
6040 errmsg = check_cedit();
6042 #endif
6044 /* 'verbosefile' */
6045 else if (varp == &p_vfile)
6047 verbose_stop();
6048 if (*p_vfile != NUL && verbose_open() == FAIL)
6049 errmsg = e_invarg;
6052 #ifdef FEAT_VIMINFO
6053 /* 'viminfo' */
6054 else if (varp == &p_viminfo)
6056 for (s = p_viminfo; *s;)
6058 /* Check it's a valid character */
6059 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6061 errmsg = illegal_char(errbuf, *s);
6062 break;
6064 if (*s == 'n') /* name is always last one */
6066 break;
6068 else if (*s == 'r') /* skip until next ',' */
6070 while (*++s && *s != ',')
6073 else if (*s == '%')
6075 /* optional number */
6076 while (vim_isdigit(*++s))
6079 else if (*s == '!' || *s == 'h' || *s == 'c')
6080 ++s; /* no extra chars */
6081 else /* must have a number */
6083 while (vim_isdigit(*++s))
6086 if (!VIM_ISDIGIT(*(s - 1)))
6088 if (errbuf != NULL)
6090 sprintf((char *)errbuf,
6091 _("E526: Missing number after <%s>"),
6092 transchar_byte(*(s - 1)));
6093 errmsg = errbuf;
6095 else
6096 errmsg = (char_u *)"";
6097 break;
6100 if (*s == ',')
6101 ++s;
6102 else if (*s)
6104 if (errbuf != NULL)
6105 errmsg = (char_u *)N_("E527: Missing comma");
6106 else
6107 errmsg = (char_u *)"";
6108 break;
6111 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6112 errmsg = (char_u *)N_("E528: Must specify a ' value");
6114 #endif /* FEAT_VIMINFO */
6116 /* terminal options */
6117 else if (istermoption(&options[opt_idx]) && full_screen)
6119 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6120 if (varp == &T_CCO)
6122 int colors = atoi((char *)T_CCO);
6124 /* Only reinitialize colors if t_Co value has really changed to
6125 * avoid expensive reload of colorscheme if t_Co is set to the
6126 * same value multiple times. */
6127 if (colors != t_colors)
6129 t_colors = colors;
6130 if (t_colors <= 1)
6132 if (new_value_alloced)
6133 vim_free(T_CCO);
6134 T_CCO = empty_option;
6136 /* We now have a different color setup, initialize it again. */
6137 init_highlight(TRUE, FALSE);
6140 ttest(FALSE);
6141 if (varp == &T_ME)
6143 out_str(T_ME);
6144 redraw_later(CLEAR);
6145 #if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6146 /* Since t_me has been set, this probably means that the user
6147 * wants to use this as default colors. Need to reset default
6148 * background/foreground colors. */
6149 mch_set_normal_colors();
6150 #endif
6154 #ifdef FEAT_LINEBREAK
6155 /* 'showbreak' */
6156 else if (varp == &p_sbr)
6158 for (s = p_sbr; *s; )
6160 if (ptr2cells(s) != 1)
6161 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
6162 mb_ptr_adv(s);
6165 #endif
6167 #ifdef FEAT_GUI
6168 /* 'guifont' */
6169 else if (varp == &p_guifont)
6171 if (gui.in_use)
6173 p = p_guifont;
6174 # if defined(FEAT_GUI_GTK)
6176 * Put up a font dialog and let the user select a new value.
6177 * If this is cancelled go back to the old value but don't
6178 * give an error message.
6180 if (STRCMP(p, "*") == 0)
6182 p = gui_mch_font_dialog(oldval);
6184 if (new_value_alloced)
6185 free_string_option(p_guifont);
6187 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6188 new_value_alloced = TRUE;
6190 # endif
6191 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6193 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6194 if (STRCMP(p_guifont, "*") == 0)
6196 /* Dialog was cancelled: Keep the old value without giving
6197 * an error message. */
6198 if (new_value_alloced)
6199 free_string_option(p_guifont);
6200 p_guifont = vim_strsave(oldval);
6201 new_value_alloced = TRUE;
6203 else
6204 # endif
6205 errmsg = (char_u *)N_("E596: Invalid font(s)");
6208 redraw_gui_only = TRUE;
6210 # ifdef FEAT_XFONTSET
6211 else if (varp == &p_guifontset)
6213 if (STRCMP(p_guifontset, "*") == 0)
6214 errmsg = (char_u *)N_("E597: can't select fontset");
6215 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6216 errmsg = (char_u *)N_("E598: Invalid fontset");
6217 redraw_gui_only = TRUE;
6219 # endif
6220 # ifdef FEAT_MBYTE
6221 else if (varp == &p_guifontwide)
6223 if (STRCMP(p_guifontwide, "*") == 0)
6224 errmsg = (char_u *)N_("E533: can't select wide font");
6225 else if (gui_get_wide_font() == FAIL)
6226 errmsg = (char_u *)N_("E534: Invalid wide font");
6227 redraw_gui_only = TRUE;
6229 # endif
6230 #endif
6232 #ifdef CURSOR_SHAPE
6233 /* 'guicursor' */
6234 else if (varp == &p_guicursor)
6235 errmsg = parse_shape_opt(SHAPE_CURSOR);
6236 #endif
6238 #ifdef FEAT_MOUSESHAPE
6239 /* 'mouseshape' */
6240 else if (varp == &p_mouseshape)
6242 errmsg = parse_shape_opt(SHAPE_MOUSE);
6243 update_mouseshape(-1);
6245 #endif
6247 #ifdef FEAT_PRINTER
6248 else if (varp == &p_popt)
6249 errmsg = parse_printoptions();
6250 # if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
6251 else if (varp == &p_pmfn)
6252 errmsg = parse_printmbfont();
6253 # endif
6254 #endif
6256 #ifdef FEAT_LANGMAP
6257 /* 'langmap' */
6258 else if (varp == &p_langmap)
6259 langmap_set();
6260 #endif
6262 #ifdef FEAT_LINEBREAK
6263 /* 'breakat' */
6264 else if (varp == &p_breakat)
6265 fill_breakat_flags();
6266 #endif
6268 #ifdef FEAT_TITLE
6269 /* 'titlestring' and 'iconstring' */
6270 else if (varp == &p_titlestring || varp == &p_iconstring)
6272 # ifdef FEAT_STL_OPT
6273 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6275 /* NULL => statusline syntax */
6276 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6277 stl_syntax |= flagval;
6278 else
6279 stl_syntax &= ~flagval;
6280 # endif
6281 did_set_title(varp == &p_iconstring);
6284 #endif
6286 #ifdef FEAT_GUI
6287 /* 'guioptions' */
6288 else if (varp == &p_go)
6290 gui_init_which_components(oldval);
6291 redraw_gui_only = TRUE;
6293 #endif
6295 #if defined(FEAT_GUI_TABLINE)
6296 /* 'guitablabel' */
6297 else if (varp == &p_gtl)
6299 redraw_tabline = TRUE;
6300 redraw_gui_only = TRUE;
6302 /* 'guitabtooltip' */
6303 else if (varp == &p_gtt)
6305 redraw_gui_only = TRUE;
6307 #endif
6309 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6310 /* 'ttymouse' */
6311 else if (varp == &p_ttym)
6313 /* Switch the mouse off before changing the escape sequences used for
6314 * that. */
6315 mch_setmouse(FALSE);
6316 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6317 errmsg = e_invarg;
6318 else
6319 check_mouse_termcode();
6320 if (termcap_active)
6321 setmouse(); /* may switch it on again */
6323 #endif
6325 #ifdef FEAT_VISUAL
6326 /* 'selection' */
6327 else if (varp == &p_sel)
6329 if (*p_sel == NUL
6330 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6331 errmsg = e_invarg;
6334 /* 'selectmode' */
6335 else if (varp == &p_slm)
6337 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6338 errmsg = e_invarg;
6340 #endif
6342 #ifdef FEAT_BROWSE
6343 /* 'browsedir' */
6344 else if (varp == &p_bsdir)
6346 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6347 && !mch_isdir(p_bsdir))
6348 errmsg = e_invarg;
6350 #endif
6352 #ifdef FEAT_VISUAL
6353 /* 'keymodel' */
6354 else if (varp == &p_km)
6356 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6357 errmsg = e_invarg;
6358 else
6360 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6361 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6364 #endif
6366 /* 'mousemodel' */
6367 else if (varp == &p_mousem)
6369 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6370 errmsg = e_invarg;
6371 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6372 else if (*p_mousem != *oldval)
6373 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6374 * to create or delete the popup menus. */
6375 gui_motif_update_mousemodel(root_menu);
6376 #endif
6379 /* 'switchbuf' */
6380 else if (varp == &p_swb)
6382 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
6383 errmsg = e_invarg;
6386 /* 'debug' */
6387 else if (varp == &p_debug)
6389 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
6390 errmsg = e_invarg;
6393 /* 'display' */
6394 else if (varp == &p_dy)
6396 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6397 errmsg = e_invarg;
6398 else
6399 (void)init_chartab();
6403 #ifdef FEAT_VERTSPLIT
6404 /* 'eadirection' */
6405 else if (varp == &p_ead)
6407 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6408 errmsg = e_invarg;
6410 #endif
6412 #ifdef FEAT_CLIPBOARD
6413 /* 'clipboard' */
6414 else if (varp == &p_cb)
6415 errmsg = check_clipboard_option();
6416 #endif
6418 #ifdef FEAT_SPELL
6419 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6420 * buffer in which 'spell' is set load the wordlists. */
6421 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
6423 win_T *wp;
6424 int l;
6426 if (varp == &(curbuf->b_p_spf))
6428 l = (int)STRLEN(curbuf->b_p_spf);
6429 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6430 ".add") != 0))
6431 errmsg = e_invarg;
6434 if (errmsg == NULL)
6436 FOR_ALL_WINDOWS(wp)
6437 if (wp->w_buffer == curbuf && wp->w_p_spell)
6439 errmsg = did_set_spelllang(curbuf);
6440 # ifdef FEAT_WINDOWS
6441 break;
6442 # endif
6446 /* When 'spellcapcheck' is set compile the regexp program. */
6447 else if (varp == &(curbuf->b_p_spc))
6449 errmsg = compile_cap_prog(curbuf);
6451 /* 'spellsuggest' */
6452 else if (varp == &p_sps)
6454 if (spell_check_sps() != OK)
6455 errmsg = e_invarg;
6457 /* 'mkspellmem' */
6458 else if (varp == &p_msm)
6460 if (spell_check_msm() != OK)
6461 errmsg = e_invarg;
6463 #endif
6465 #ifdef FEAT_QUICKFIX
6466 /* When 'bufhidden' is set, check for valid value. */
6467 else if (gvarp == &p_bh)
6469 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6470 errmsg = e_invarg;
6473 /* When 'buftype' is set, check for valid value. */
6474 else if (gvarp == &p_bt)
6476 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6477 errmsg = e_invarg;
6478 else
6480 # ifdef FEAT_WINDOWS
6481 if (curwin->w_status_height)
6483 curwin->w_redr_status = TRUE;
6484 redraw_later(VALID);
6486 # endif
6487 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6488 # ifdef FEAT_TITLE
6489 redraw_titles();
6490 # endif
6493 #endif
6495 #ifdef FEAT_STL_OPT
6496 /* 'statusline' or 'rulerformat' */
6497 else if (gvarp == &p_stl || varp == &p_ruf)
6499 int wid;
6501 if (varp == &p_ruf) /* reset ru_wid first */
6502 ru_wid = 0;
6503 s = *varp;
6504 if (varp == &p_ruf && *s == '%')
6506 /* set ru_wid if 'ruf' starts with "%99(" */
6507 if (*++s == '-') /* ignore a '-' */
6508 s++;
6509 wid = getdigits(&s);
6510 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6511 ru_wid = wid;
6512 else
6513 errmsg = check_stl_option(p_ruf);
6515 /* check 'statusline' only if it doesn't start with "%!" */
6516 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
6517 errmsg = check_stl_option(s);
6518 if (varp == &p_ruf && errmsg == NULL)
6519 comp_col();
6521 #endif
6523 #ifdef FEAT_INS_EXPAND
6524 /* check if it is a valid value for 'complete' -- Acevedo */
6525 else if (gvarp == &p_cpt)
6527 for (s = *varp; *s;)
6529 while(*s == ',' || *s == ' ')
6530 s++;
6531 if (!*s)
6532 break;
6533 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6535 errmsg = illegal_char(errbuf, *s);
6536 break;
6538 if (*++s != NUL && *s != ',' && *s != ' ')
6540 if (s[-1] == 'k' || s[-1] == 's')
6542 /* skip optional filename after 'k' and 's' */
6543 while (*s && *s != ',' && *s != ' ')
6545 if (*s == '\\')
6546 ++s;
6547 ++s;
6550 else
6552 if (errbuf != NULL)
6554 sprintf((char *)errbuf,
6555 _("E535: Illegal character after <%c>"),
6556 *--s);
6557 errmsg = errbuf;
6559 else
6560 errmsg = (char_u *)"";
6561 break;
6567 /* 'completeopt' */
6568 else if (varp == &p_cot)
6570 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6571 errmsg = e_invarg;
6573 #endif /* FEAT_INS_EXPAND */
6576 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6577 else if (varp == &p_toolbar)
6579 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6580 &toolbar_flags, TRUE) != OK)
6581 errmsg = e_invarg;
6582 else
6584 out_flush();
6585 gui_mch_show_toolbar((toolbar_flags &
6586 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6589 #endif
6591 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6592 /* 'toolbariconsize': GTK+ 2 only */
6593 else if (varp == &p_tbis)
6595 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6596 errmsg = e_invarg;
6597 else
6599 out_flush();
6600 gui_mch_show_toolbar((toolbar_flags &
6601 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6604 #endif
6606 /* 'pastetoggle': translate key codes like in a mapping */
6607 else if (varp == &p_pt)
6609 if (*p_pt)
6611 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
6612 if (p != NULL)
6614 if (new_value_alloced)
6615 free_string_option(p_pt);
6616 p_pt = p;
6617 new_value_alloced = TRUE;
6622 /* 'backspace' */
6623 else if (varp == &p_bs)
6625 if (VIM_ISDIGIT(*p_bs))
6627 if (*p_bs >'2' || p_bs[1] != NUL)
6628 errmsg = e_invarg;
6630 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6631 errmsg = e_invarg;
6634 #ifdef FEAT_MBYTE
6635 /* 'casemap' */
6636 else if (varp == &p_cmp)
6638 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6639 errmsg = e_invarg;
6641 #endif
6643 #ifdef FEAT_DIFF
6644 /* 'diffopt' */
6645 else if (varp == &p_dip)
6647 if (diffopt_changed() == FAIL)
6648 errmsg = e_invarg;
6650 #endif
6652 #ifdef FEAT_FOLDING
6653 /* 'foldmethod' */
6654 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6656 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6657 || *curwin->w_p_fdm == NUL)
6658 errmsg = e_invarg;
6659 else
6660 foldUpdateAll(curwin);
6662 # ifdef FEAT_EVAL
6663 /* 'foldexpr' */
6664 else if (varp == &curwin->w_p_fde)
6666 if (foldmethodIsExpr(curwin))
6667 foldUpdateAll(curwin);
6669 # endif
6670 /* 'foldmarker' */
6671 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6673 p = vim_strchr(*varp, ',');
6674 if (p == NULL)
6675 errmsg = (char_u *)N_("E536: comma required");
6676 else if (p == *varp || p[1] == NUL)
6677 errmsg = e_invarg;
6678 else if (foldmethodIsMarker(curwin))
6679 foldUpdateAll(curwin);
6681 /* 'commentstring' */
6682 else if (gvarp == &p_cms)
6684 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6685 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6687 /* 'foldopen' */
6688 else if (varp == &p_fdo)
6690 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6691 errmsg = e_invarg;
6693 /* 'foldclose' */
6694 else if (varp == &p_fcl)
6696 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6697 errmsg = e_invarg;
6699 /* 'foldignore' */
6700 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6702 if (foldmethodIsIndent(curwin))
6703 foldUpdateAll(curwin);
6705 #endif
6707 #ifdef FEAT_VIRTUALEDIT
6708 /* 'virtualedit' */
6709 else if (varp == &p_ve)
6711 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6712 errmsg = e_invarg;
6713 else if (STRCMP(p_ve, oldval) != 0)
6715 /* Recompute cursor position in case the new 've' setting
6716 * changes something. */
6717 validate_virtcol();
6718 coladvance(curwin->w_virtcol);
6721 #endif
6723 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6724 else if (varp == &p_csqf)
6726 if (p_csqf != NULL)
6728 p = p_csqf;
6729 while (*p != NUL)
6731 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6732 || p[1] == NUL
6733 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6734 || (p[2] != NUL && p[2] != ','))
6736 errmsg = e_invarg;
6737 break;
6739 else if (p[2] == NUL)
6740 break;
6741 else
6742 p += 3;
6746 #endif
6748 #ifdef FEAT_VARTABS
6749 /* 'varsofttabstop' */
6750 else if (varp == &(curbuf->b_p_vsts))
6752 char_u *cp;
6754 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
6756 if (curbuf->b_p_vsts_ary)
6758 vim_free(curbuf->b_p_vsts_ary);
6759 curbuf->b_p_vsts_ary = 0;
6762 else
6764 for (cp = *varp; *cp; ++cp)
6766 if (vim_isdigit(*cp))
6767 continue;
6768 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
6769 continue;
6770 errmsg = e_invarg;
6771 break;
6773 if (errmsg == NULL)
6775 int *oldarray = curbuf->b_p_vsts_ary;
6776 if (tabstop_set(*varp, &(curbuf->b_p_vsts_ary)))
6778 if (oldarray)
6779 vim_free(oldarray);
6781 else
6782 errmsg = e_invarg;
6787 /* 'vartabstop' */
6788 else if (varp == &(curbuf->b_p_vts))
6790 char_u *cp;
6792 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
6794 if (curbuf->b_p_vts_ary)
6796 vim_free(curbuf->b_p_vts_ary);
6797 curbuf->b_p_vts_ary = 0;
6800 else
6802 for (cp = *varp; *cp; ++cp)
6804 if (vim_isdigit(*cp))
6805 continue;
6806 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
6807 continue;
6808 errmsg = e_invarg;
6809 break;
6811 if (errmsg == NULL)
6813 int *oldarray = curbuf->b_p_vts_ary;
6814 if (tabstop_set(*varp, &(curbuf->b_p_vts_ary)))
6816 if (oldarray)
6817 vim_free(oldarray);
6818 #ifdef FEAT_FOLDING
6819 if (foldmethodIsIndent(curwin))
6820 foldUpdateAll(curwin);
6821 #endif /* FEAT_FOLDING */
6823 else
6824 errmsg = e_invarg;
6828 #endif
6830 /* Options that are a list of flags. */
6831 else
6833 p = NULL;
6834 if (varp == &p_ww)
6835 p = (char_u *)WW_ALL;
6836 if (varp == &p_shm)
6837 p = (char_u *)SHM_ALL;
6838 else if (varp == &(p_cpo))
6839 p = (char_u *)CPO_ALL;
6840 else if (varp == &(curbuf->b_p_fo))
6841 p = (char_u *)FO_ALL;
6842 else if (varp == &p_mouse)
6844 #ifdef FEAT_MOUSE
6845 p = (char_u *)MOUSE_ALL;
6846 #else
6847 if (*p_mouse != NUL)
6848 errmsg = (char_u *)N_("E538: No mouse support");
6849 #endif
6851 #if defined(FEAT_GUI)
6852 else if (varp == &p_go)
6853 p = (char_u *)GO_ALL;
6854 #endif
6855 if (p != NULL)
6857 for (s = *varp; *s; ++s)
6858 if (vim_strchr(p, *s) == NULL)
6860 errmsg = illegal_char(errbuf, *s);
6861 break;
6867 * If error detected, restore the previous value.
6869 if (errmsg != NULL)
6871 if (new_value_alloced)
6872 free_string_option(*varp);
6873 *varp = oldval;
6875 * When resetting some values, need to act on it.
6877 if (did_chartab)
6878 (void)init_chartab();
6879 if (varp == &p_hl)
6880 (void)highlight_changed();
6882 else
6884 #ifdef FEAT_EVAL
6885 /* Remember where the option was set. */
6886 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
6887 #endif
6889 * Free string options that are in allocated memory.
6890 * Use "free_oldval", because recursiveness may change the flags under
6891 * our fingers (esp. init_highlight()).
6893 if (free_oldval)
6894 free_string_option(oldval);
6895 if (new_value_alloced)
6896 options[opt_idx].flags |= P_ALLOCED;
6897 else
6898 options[opt_idx].flags &= ~P_ALLOCED;
6900 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6901 && ((int)options[opt_idx].indir & PV_BOTH))
6903 /* global option with local value set to use global value; free
6904 * the local value and make it empty */
6905 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6906 free_string_option(*(char_u **)p);
6907 *(char_u **)p = empty_option;
6910 /* May set global value for local option. */
6911 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6912 set_string_option_global(opt_idx, varp);
6914 #ifdef FEAT_AUTOCMD
6916 * Trigger the autocommand only after setting the flags.
6918 # ifdef FEAT_SYN_HL
6919 /* When 'syntax' is set, load the syntax of that name */
6920 if (varp == &(curbuf->b_p_syn))
6922 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6923 curbuf->b_fname, TRUE, curbuf);
6925 # endif
6926 else if (varp == &(curbuf->b_p_ft))
6928 /* 'filetype' is set, trigger the FileType autocommand */
6929 did_filetype = TRUE;
6930 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6931 curbuf->b_fname, TRUE, curbuf);
6933 #endif
6934 #ifdef FEAT_SPELL
6935 if (varp == &(curbuf->b_p_spl))
6937 char_u fname[200];
6940 * Source the spell/LANG.vim in 'runtimepath'.
6941 * They could set 'spellcapcheck' depending on the language.
6942 * Use the first name in 'spelllang' up to '_region' or
6943 * '.encoding'.
6945 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6946 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6947 break;
6948 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6949 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6950 source_runtime(fname, TRUE);
6952 #endif
6955 #ifdef FEAT_MOUSE
6956 if (varp == &p_mouse)
6958 # ifdef FEAT_MOUSE_TTY
6959 if (*p_mouse == NUL)
6960 mch_setmouse(FALSE); /* switch mouse off */
6961 else
6962 # endif
6963 setmouse(); /* in case 'mouse' changed */
6965 #endif
6967 if (curwin->w_curswant != MAXCOL)
6968 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6969 #ifdef FEAT_GUI
6970 /* check redraw when it's not a GUI option or the GUI is active. */
6971 if (!redraw_gui_only || gui.in_use)
6972 #endif
6973 check_redraw(options[opt_idx].flags);
6975 return errmsg;
6979 * Handle setting 'listchars' or 'fillchars'.
6980 * Returns error message, NULL if it's OK.
6982 static char_u *
6983 set_chars_option(varp)
6984 char_u **varp;
6986 int round, i, len, entries;
6987 char_u *p, *s;
6988 int c1, c2 = 0;
6989 struct charstab
6991 int *cp;
6992 char *name;
6994 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6995 static struct charstab filltab[] =
6997 {&fill_stl, "stl"},
6998 {&fill_stlnc, "stlnc"},
6999 {&fill_vert, "vert"},
7000 {&fill_fold, "fold"},
7001 {&fill_diff, "diff"},
7003 #endif
7004 static struct charstab lcstab[] =
7006 {&lcs_eol, "eol"},
7007 {&lcs_ext, "extends"},
7008 {&lcs_nbsp, "nbsp"},
7009 {&lcs_prec, "precedes"},
7010 {&lcs_tab2, "tab"},
7011 {&lcs_trail, "trail"},
7013 struct charstab *tab;
7015 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7016 if (varp == &p_lcs)
7017 #endif
7019 tab = lcstab;
7020 entries = sizeof(lcstab) / sizeof(struct charstab);
7022 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7023 else
7025 tab = filltab;
7026 entries = sizeof(filltab) / sizeof(struct charstab);
7028 #endif
7030 /* first round: check for valid value, second round: assign values */
7031 for (round = 0; round <= 1; ++round)
7033 if (round)
7035 /* After checking that the value is valid: set defaults: space for
7036 * 'fillchars', NUL for 'listchars' */
7037 for (i = 0; i < entries; ++i)
7038 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
7039 if (varp == &p_lcs)
7040 lcs_tab1 = NUL;
7041 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7042 else
7043 fill_diff = '-';
7044 #endif
7046 p = *varp;
7047 while (*p)
7049 for (i = 0; i < entries; ++i)
7051 len = (int)STRLEN(tab[i].name);
7052 if (STRNCMP(p, tab[i].name, len) == 0
7053 && p[len] == ':'
7054 && p[len + 1] != NUL)
7056 s = p + len + 1;
7057 #ifdef FEAT_MBYTE
7058 c1 = mb_ptr2char_adv(&s);
7059 if (mb_char2cells(c1) > 1)
7060 continue;
7061 #else
7062 c1 = *s++;
7063 #endif
7064 if (tab[i].cp == &lcs_tab2)
7066 if (*s == NUL)
7067 continue;
7068 #ifdef FEAT_MBYTE
7069 c2 = mb_ptr2char_adv(&s);
7070 if (mb_char2cells(c2) > 1)
7071 continue;
7072 #else
7073 c2 = *s++;
7074 #endif
7076 if (*s == ',' || *s == NUL)
7078 if (round)
7080 if (tab[i].cp == &lcs_tab2)
7082 lcs_tab1 = c1;
7083 lcs_tab2 = c2;
7085 else
7086 *(tab[i].cp) = c1;
7089 p = s;
7090 break;
7095 if (i == entries)
7096 return e_invarg;
7097 if (*p == ',')
7098 ++p;
7102 return NULL; /* no error */
7105 #ifdef FEAT_STL_OPT
7107 * Check validity of options with the 'statusline' format.
7108 * Return error message or NULL.
7110 char_u *
7111 check_stl_option(s)
7112 char_u *s;
7114 int itemcnt = 0;
7115 int groupdepth = 0;
7116 static char_u errbuf[80];
7118 while (*s && itemcnt < STL_MAX_ITEM)
7120 /* Check for valid keys after % sequences */
7121 while (*s && *s != '%')
7122 s++;
7123 if (!*s)
7124 break;
7125 s++;
7126 if (*s != '%' && *s != ')')
7127 ++itemcnt;
7128 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7130 s++;
7131 continue;
7133 if (*s == ')')
7135 s++;
7136 if (--groupdepth < 0)
7137 break;
7138 continue;
7140 if (*s == '-')
7141 s++;
7142 while (VIM_ISDIGIT(*s))
7143 s++;
7144 if (*s == STL_USER_HL)
7145 continue;
7146 if (*s == '.')
7148 s++;
7149 while (*s && VIM_ISDIGIT(*s))
7150 s++;
7152 if (*s == '(')
7154 groupdepth++;
7155 continue;
7157 if (vim_strchr(STL_ALL, *s) == NULL)
7159 return illegal_char(errbuf, *s);
7161 if (*s == '{')
7163 s++;
7164 while (*s != '}' && *s)
7165 s++;
7166 if (*s != '}')
7167 return (char_u *)N_("E540: Unclosed expression sequence");
7170 if (itemcnt >= STL_MAX_ITEM)
7171 return (char_u *)N_("E541: too many items");
7172 if (groupdepth != 0)
7173 return (char_u *)N_("E542: unbalanced groups");
7174 return NULL;
7176 #endif
7178 #ifdef FEAT_CLIPBOARD
7180 * Extract the items in the 'clipboard' option and set global values.
7182 static char_u *
7183 check_clipboard_option()
7185 int new_unnamed = FALSE;
7186 int new_autoselect = FALSE;
7187 int new_autoselectml = FALSE;
7188 int new_html = FALSE;
7189 regprog_T *new_exclude_prog = NULL;
7190 char_u *errmsg = NULL;
7191 char_u *p;
7193 for (p = p_cb; *p != NUL; )
7195 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7197 new_unnamed = TRUE;
7198 p += 7;
7200 else if (STRNCMP(p, "autoselect", 10) == 0
7201 && (p[10] == ',' || p[10] == NUL))
7203 new_autoselect = TRUE;
7204 p += 10;
7206 else if (STRNCMP(p, "autoselectml", 12) == 0
7207 && (p[12] == ',' || p[12] == NUL))
7209 new_autoselectml = TRUE;
7210 p += 12;
7212 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7214 new_html = TRUE;
7215 p += 4;
7217 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7219 p += 8;
7220 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7221 if (new_exclude_prog == NULL)
7222 errmsg = e_invarg;
7223 break;
7225 else
7227 errmsg = e_invarg;
7228 break;
7230 if (*p == ',')
7231 ++p;
7233 if (errmsg == NULL)
7235 clip_unnamed = new_unnamed;
7236 clip_autoselect = new_autoselect;
7237 clip_autoselectml = new_autoselectml;
7238 clip_html = new_html;
7239 vim_free(clip_exclude_prog);
7240 clip_exclude_prog = new_exclude_prog;
7242 else
7243 vim_free(new_exclude_prog);
7245 return errmsg;
7247 #endif
7249 #ifdef FEAT_SPELL
7251 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7252 * Return error message when failed, NULL when OK.
7254 static char_u *
7255 compile_cap_prog(buf)
7256 buf_T *buf;
7258 regprog_T *rp = buf->b_cap_prog;
7259 char_u *re;
7261 if (*buf->b_p_spc == NUL)
7262 buf->b_cap_prog = NULL;
7263 else
7265 /* Prepend a ^ so that we only match at one column */
7266 re = concat_str((char_u *)"^", buf->b_p_spc);
7267 if (re != NULL)
7269 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7270 if (buf->b_cap_prog == NULL)
7272 buf->b_cap_prog = rp; /* restore the previous program */
7273 return e_invarg;
7275 vim_free(re);
7279 vim_free(rp);
7280 return NULL;
7282 #endif
7284 #if defined(FEAT_EVAL) || defined(PROTO)
7286 * Set the scriptID for an option, taking care of setting the buffer- or
7287 * window-local value.
7289 static void
7290 set_option_scriptID_idx(opt_idx, opt_flags, id)
7291 int opt_idx;
7292 int opt_flags;
7293 int id;
7295 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7296 int indir = (int)options[opt_idx].indir;
7298 /* Remember where the option was set. For local options need to do that
7299 * in the buffer or window structure. */
7300 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
7301 options[opt_idx].scriptID = id;
7302 if (both || (opt_flags & OPT_LOCAL))
7304 if (indir & PV_BUF)
7305 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7306 else if (indir & PV_WIN)
7307 curwin->w_p_scriptID[indir & PV_MASK] = id;
7310 #endif
7313 * Set the value of a boolean option, and take care of side effects.
7314 * Returns NULL for success, or an error message for an error.
7316 static char_u *
7317 set_bool_option(opt_idx, varp, value, opt_flags)
7318 int opt_idx; /* index in options[] table */
7319 char_u *varp; /* pointer to the option variable */
7320 int value; /* new value */
7321 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7323 int old_value = *(int *)varp;
7325 /* Disallow changing some options from secure mode */
7326 if ((secure
7327 #ifdef HAVE_SANDBOX
7328 || sandbox != 0
7329 #endif
7330 ) && (options[opt_idx].flags & P_SECURE))
7331 return e_secure;
7333 *(int *)varp = value; /* set the new value */
7334 #ifdef FEAT_EVAL
7335 /* Remember where the option was set. */
7336 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
7337 #endif
7339 #ifdef FEAT_GUI
7340 need_mouse_correct = TRUE;
7341 #endif
7343 /* May set global value for local option. */
7344 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7345 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7348 * Handle side effects of changing a bool option.
7351 /* 'compatible' */
7352 if ((int *)varp == &p_cp)
7354 compatible_set();
7357 /* 'list', 'number' */
7358 else if ((int *)varp == &curwin->w_p_list
7359 || (int *)varp == &curwin->w_p_nu)
7361 if (curwin->w_curswant != MAXCOL)
7362 curwin->w_set_curswant = TRUE;
7365 else if ((int *)varp == &curbuf->b_p_ro)
7367 /* when 'readonly' is reset globally, also reset readonlymode */
7368 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7369 readonlymode = FALSE;
7371 /* when 'readonly' is set may give W10 again */
7372 if (curbuf->b_p_ro)
7373 curbuf->b_did_warn = FALSE;
7375 #ifdef FEAT_TITLE
7376 redraw_titles();
7377 #endif
7380 #ifdef FEAT_TITLE
7381 /* when 'modifiable' is changed, redraw the window title */
7382 else if ((int *)varp == &curbuf->b_p_ma)
7384 redraw_titles();
7386 /* when 'endofline' is changed, redraw the window title */
7387 else if ((int *)varp == &curbuf->b_p_eol)
7389 redraw_titles();
7391 # ifdef FEAT_MBYTE
7392 /* when 'bomb' is changed, redraw the window title and tab page text */
7393 else if ((int *)varp == &curbuf->b_p_bomb)
7395 redraw_titles();
7397 # endif
7398 #endif
7400 /* when 'bin' is set also set some other options */
7401 else if ((int *)varp == &curbuf->b_p_bin)
7403 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7404 #ifdef FEAT_TITLE
7405 redraw_titles();
7406 #endif
7409 #ifdef FEAT_AUTOCMD
7410 /* when 'buflisted' changes, trigger autocommands */
7411 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7413 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7414 NULL, NULL, TRUE, curbuf);
7416 #endif
7418 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7419 else if ((int *)varp == &curbuf->b_p_swf)
7421 if (curbuf->b_p_swf && p_uc)
7422 ml_open_file(curbuf); /* create the swap file */
7423 else
7424 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7425 * buf->b_p_swf */
7426 mf_close_file(curbuf, TRUE); /* remove the swap file */
7429 /* when 'terse' is set change 'shortmess' */
7430 else if ((int *)varp == &p_terse)
7432 char_u *p;
7434 p = vim_strchr(p_shm, SHM_SEARCH);
7436 /* insert 's' in p_shm */
7437 if (p_terse && p == NULL)
7439 STRCPY(IObuff, p_shm);
7440 STRCAT(IObuff, "s");
7441 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
7443 /* remove 's' from p_shm */
7444 else if (!p_terse && p != NULL)
7445 STRMOVE(p, p + 1);
7448 /* when 'paste' is set or reset also change other options */
7449 else if ((int *)varp == &p_paste)
7451 paste_option_changed();
7454 /* when 'insertmode' is set from an autocommand need to do work here */
7455 else if ((int *)varp == &p_im)
7457 if (p_im)
7459 if ((State & INSERT) == 0)
7460 need_start_insertmode = TRUE;
7461 stop_insert_mode = FALSE;
7463 else
7465 need_start_insertmode = FALSE;
7466 stop_insert_mode = TRUE;
7467 if (restart_edit != 0 && mode_displayed)
7468 clear_cmdline = TRUE; /* remove "(insert)" */
7469 restart_edit = 0;
7473 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7474 else if ((int *)varp == &p_ic && p_hls)
7476 redraw_all_later(SOME_VALID);
7479 #ifdef FEAT_SEARCH_EXTRA
7480 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7481 else if ((int *)varp == &p_hls)
7483 no_hlsearch = FALSE;
7485 #endif
7487 #ifdef FEAT_SCROLLBIND
7488 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7489 * at the end of normal_cmd() */
7490 else if ((int *)varp == &curwin->w_p_scb)
7492 if (curwin->w_p_scb)
7493 do_check_scrollbind(FALSE);
7495 #endif
7497 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7498 /* There can be only one window with 'previewwindow' set. */
7499 else if ((int *)varp == &curwin->w_p_pvw)
7501 if (curwin->w_p_pvw)
7503 win_T *win;
7505 for (win = firstwin; win != NULL; win = win->w_next)
7506 if (win->w_p_pvw && win != curwin)
7508 curwin->w_p_pvw = FALSE;
7509 return (char_u *)N_("E590: A preview window already exists");
7513 #endif
7515 /* when 'textmode' is set or reset also change 'fileformat' */
7516 else if ((int *)varp == &curbuf->b_p_tx)
7518 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7521 /* when 'textauto' is set or reset also change 'fileformats' */
7522 else if ((int *)varp == &p_ta)
7523 set_string_option_direct((char_u *)"ffs", -1,
7524 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
7525 OPT_FREE | opt_flags, 0);
7528 * When 'lisp' option changes include/exclude '-' in
7529 * keyword characters.
7531 #ifdef FEAT_LISP
7532 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7534 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7536 #endif
7538 #ifdef FEAT_TITLE
7539 /* when 'title' changed, may need to change the title; same for 'icon' */
7540 else if ((int *)varp == &p_title)
7542 did_set_title(FALSE);
7545 else if ((int *)varp == &p_icon)
7547 did_set_title(TRUE);
7549 #endif
7551 else if ((int *)varp == &curbuf->b_changed)
7553 if (!value)
7554 save_file_ff(curbuf); /* Buffer is unchanged */
7555 #ifdef FEAT_TITLE
7556 redraw_titles();
7557 #endif
7558 #ifdef FEAT_AUTOCMD
7559 modified_was_set = value;
7560 #endif
7563 #ifdef BACKSLASH_IN_FILENAME
7564 else if ((int *)varp == &p_ssl)
7566 if (p_ssl)
7568 psepc = '/';
7569 psepcN = '\\';
7570 pseps[0] = '/';
7572 else
7574 psepc = '\\';
7575 psepcN = '/';
7576 pseps[0] = '\\';
7579 /* need to adjust the file name arguments and buffer names. */
7580 buflist_slash_adjust();
7581 alist_slash_adjust();
7582 # ifdef FEAT_EVAL
7583 scriptnames_slash_adjust();
7584 # endif
7586 #endif
7588 /* If 'wrap' is set, set w_leftcol to zero. */
7589 else if ((int *)varp == &curwin->w_p_wrap)
7591 if (curwin->w_p_wrap)
7592 curwin->w_leftcol = 0;
7593 if (curwin->w_curswant != MAXCOL)
7594 curwin->w_set_curswant = TRUE;
7597 /* If 'number' is set, reset 'relativenumber'. */
7598 else if ((int *)varp == &curwin->w_p_nu)
7600 if (curwin->w_p_nu)
7601 curwin->w_p_rnu = FALSE;
7603 /* If 'relativenumber' is set, reset 'number'. */
7604 else if ((int *)varp == &curwin->w_p_rnu)
7606 if (curwin->w_p_rnu)
7607 curwin->w_p_nu = FALSE;
7610 #ifdef FEAT_WINDOWS
7611 else if ((int *)varp == &p_ea)
7613 if (p_ea && !old_value)
7614 win_equal(curwin, FALSE, 0);
7616 #endif
7618 else if ((int *)varp == &p_wiv)
7621 * When 'weirdinvert' changed, set/reset 't_xs'.
7622 * Then set 'weirdinvert' according to value of 't_xs'.
7624 if (p_wiv && !old_value)
7625 T_XS = (char_u *)"y";
7626 else if (!p_wiv && old_value)
7627 T_XS = empty_option;
7628 p_wiv = (*T_XS != NUL);
7631 #ifdef FEAT_BEVAL
7632 else if ((int *)varp == &p_beval)
7634 if (p_beval == TRUE)
7635 gui_mch_enable_beval_area(balloonEval);
7636 else
7637 gui_mch_disable_beval_area(balloonEval);
7639 #endif
7641 #ifdef FEAT_AUTOCHDIR
7642 else if ((int *)varp == &p_acd)
7644 /* Change directories when the 'acd' option is set now. */
7645 DO_AUTOCHDIR
7647 #endif
7649 #ifdef FEAT_DIFF
7650 /* 'diff' */
7651 else if ((int *)varp == &curwin->w_p_diff)
7653 /* May add or remove the buffer from the list of diff buffers. */
7654 diff_buf_adjust(curwin);
7655 # ifdef FEAT_FOLDING
7656 if (foldmethodIsDiff(curwin))
7657 foldUpdateAll(curwin);
7658 # endif
7660 #endif
7662 #ifdef USE_IM_CONTROL
7663 /* 'imdisable' */
7664 else if ((int *)varp == &p_imdisable)
7666 /* Only de-activate it here, it will be enabled when changing mode. */
7667 if (p_imdisable)
7668 im_set_active(FALSE);
7670 #endif
7672 #ifdef FEAT_SPELL
7673 /* 'spell' */
7674 else if ((int *)varp == &curwin->w_p_spell)
7676 if (curwin->w_p_spell)
7678 char_u *errmsg = did_set_spelllang(curbuf);
7680 if (errmsg != NULL)
7681 EMSG(_(errmsg));
7684 #endif
7686 #ifdef FEAT_FKMAP
7687 else if ((int *)varp == &p_altkeymap)
7689 if (old_value != p_altkeymap)
7691 if (!p_altkeymap)
7693 p_hkmap = p_fkmap;
7694 p_fkmap = 0;
7696 else
7698 p_fkmap = p_hkmap;
7699 p_hkmap = 0;
7701 (void)init_chartab();
7706 * In case some second language keymapping options have changed, check
7707 * and correct the setting in a consistent way.
7711 * If hkmap or fkmap are set, reset Arabic keymapping.
7713 if ((p_hkmap || p_fkmap) && p_altkeymap)
7715 p_altkeymap = p_fkmap;
7716 # ifdef FEAT_ARABIC
7717 curwin->w_p_arab = FALSE;
7718 # endif
7719 (void)init_chartab();
7723 * If hkmap set, reset Farsi keymapping.
7725 if (p_hkmap && p_altkeymap)
7727 p_altkeymap = 0;
7728 p_fkmap = 0;
7729 # ifdef FEAT_ARABIC
7730 curwin->w_p_arab = FALSE;
7731 # endif
7732 (void)init_chartab();
7736 * If fkmap set, reset Hebrew keymapping.
7738 if (p_fkmap && !p_altkeymap)
7740 p_altkeymap = 1;
7741 p_hkmap = 0;
7742 # ifdef FEAT_ARABIC
7743 curwin->w_p_arab = FALSE;
7744 # endif
7745 (void)init_chartab();
7747 #endif
7749 #ifdef FEAT_ARABIC
7750 if ((int *)varp == &curwin->w_p_arab)
7752 if (curwin->w_p_arab)
7755 * 'arabic' is set, handle various sub-settings.
7757 if (!p_tbidi)
7759 /* set rightleft mode */
7760 if (!curwin->w_p_rl)
7762 curwin->w_p_rl = TRUE;
7763 changed_window_setting();
7766 /* Enable Arabic shaping (major part of what Arabic requires) */
7767 if (!p_arshape)
7769 p_arshape = TRUE;
7770 redraw_later_clear();
7774 /* Arabic requires a utf-8 encoding, inform the user if its not
7775 * set. */
7776 if (STRCMP(p_enc, "utf-8") != 0)
7778 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7780 msg_source(hl_attr(HLF_W));
7781 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7782 #ifdef FEAT_EVAL
7783 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7784 #endif
7787 # ifdef FEAT_MBYTE
7788 /* set 'delcombine' */
7789 p_deco = TRUE;
7790 # endif
7792 # ifdef FEAT_KEYMAP
7793 /* Force-set the necessary keymap for arabic */
7794 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7795 OPT_LOCAL);
7796 # endif
7797 # ifdef FEAT_FKMAP
7798 p_altkeymap = 0;
7799 p_hkmap = 0;
7800 p_fkmap = 0;
7801 (void)init_chartab();
7802 # endif
7804 else
7807 * 'arabic' is reset, handle various sub-settings.
7809 if (!p_tbidi)
7811 /* reset rightleft mode */
7812 if (curwin->w_p_rl)
7814 curwin->w_p_rl = FALSE;
7815 changed_window_setting();
7818 /* 'arabicshape' isn't reset, it is a global option and
7819 * another window may still need it "on". */
7822 /* 'delcombine' isn't reset, it is a global option and another
7823 * window may still want it "on". */
7825 # ifdef FEAT_KEYMAP
7826 /* Revert to the default keymap */
7827 curbuf->b_p_iminsert = B_IMODE_NONE;
7828 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7829 # endif
7831 if (curwin->w_curswant != MAXCOL)
7832 curwin->w_set_curswant = TRUE;
7835 else if ((int *)varp == &p_arshape)
7837 if (curwin->w_curswant != MAXCOL)
7838 curwin->w_set_curswant = TRUE;
7840 #endif
7842 #ifdef FEAT_LINEBREAK
7843 if ((int *)varp == &curwin->w_p_lbr)
7845 if (curwin->w_curswant != MAXCOL)
7846 curwin->w_set_curswant = TRUE;
7848 #endif
7850 #ifdef FEAT_RIGHTLEFT
7851 if ((int *)varp == &curwin->w_p_rl)
7853 if (curwin->w_curswant != MAXCOL)
7854 curwin->w_set_curswant = TRUE;
7856 #endif
7859 * End of handling side effects for bool options.
7862 options[opt_idx].flags |= P_WAS_SET;
7864 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7866 check_redraw(options[opt_idx].flags);
7868 return NULL;
7872 * Set the value of a number option, and take care of side effects.
7873 * Returns NULL for success, or an error message for an error.
7875 static char_u *
7876 set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
7877 int opt_idx; /* index in options[] table */
7878 char_u *varp; /* pointer to the option variable */
7879 long value; /* new value */
7880 char_u *errbuf; /* buffer for error messages */
7881 size_t errbuflen; /* length of "errbuf" */
7882 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7883 OPT_MODELINE */
7885 char_u *errmsg = NULL;
7886 long old_value = *(long *)varp;
7887 long old_Rows = Rows; /* remember old Rows */
7888 long old_Columns = Columns; /* remember old Columns */
7889 long *pp = (long *)varp;
7891 /* Disallow changing some options from secure mode. */
7892 if ((secure
7893 #ifdef HAVE_SANDBOX
7894 || sandbox != 0
7895 #endif
7896 ) && (options[opt_idx].flags & P_SECURE))
7897 return e_secure;
7899 *pp = value;
7900 #ifdef FEAT_EVAL
7901 /* Remember where the option was set. */
7902 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
7903 #endif
7904 #ifdef FEAT_GUI
7905 need_mouse_correct = TRUE;
7906 #endif
7908 if (curbuf->b_p_sw <= 0)
7910 errmsg = e_positive;
7911 #ifdef FEAT_VARTABS
7912 /* Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use. */
7913 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_ary) > 0
7914 ? tabstop_first(curbuf->b_p_vts_ary)
7915 : curbuf->b_p_ts;
7916 #else
7917 curbuf->b_p_sw = curbuf->b_p_ts;
7918 #endif
7922 * Number options that need some action when changed
7924 #ifdef FEAT_WINDOWS
7925 if (pp == &p_wh || pp == &p_hh)
7927 if (p_wh < 1)
7929 errmsg = e_positive;
7930 p_wh = 1;
7932 if (p_wmh > p_wh)
7934 errmsg = e_winheight;
7935 p_wh = p_wmh;
7937 if (p_hh < 0)
7939 errmsg = e_positive;
7940 p_hh = 0;
7943 /* Change window height NOW */
7944 if (lastwin != firstwin)
7946 if (pp == &p_wh && curwin->w_height < p_wh)
7947 win_setheight((int)p_wh);
7948 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7949 win_setheight((int)p_hh);
7953 /* 'winminheight' */
7954 else if (pp == &p_wmh)
7956 if (p_wmh < 0)
7958 errmsg = e_positive;
7959 p_wmh = 0;
7961 if (p_wmh > p_wh)
7963 errmsg = e_winheight;
7964 p_wmh = p_wh;
7966 win_setminheight();
7969 # ifdef FEAT_VERTSPLIT
7970 else if (pp == &p_wiw)
7972 if (p_wiw < 1)
7974 errmsg = e_positive;
7975 p_wiw = 1;
7977 if (p_wmw > p_wiw)
7979 errmsg = e_winwidth;
7980 p_wiw = p_wmw;
7983 /* Change window width NOW */
7984 if (lastwin != firstwin && curwin->w_width < p_wiw)
7985 win_setwidth((int)p_wiw);
7988 /* 'winminwidth' */
7989 else if (pp == &p_wmw)
7991 if (p_wmw < 0)
7993 errmsg = e_positive;
7994 p_wmw = 0;
7996 if (p_wmw > p_wiw)
7998 errmsg = e_winwidth;
7999 p_wmw = p_wiw;
8001 win_setminheight();
8003 # endif
8005 #endif
8007 #ifdef FEAT_WINDOWS
8008 /* (re)set last window status line */
8009 else if (pp == &p_ls)
8011 last_status(FALSE);
8014 /* (re)set tab page line */
8015 else if (pp == &p_stal)
8017 shell_new_rows(); /* recompute window positions and heights */
8019 #endif
8021 #ifdef FEAT_GUI
8022 else if (pp == &p_linespace)
8024 /* Recompute gui.char_height and resize the Vim window to keep the
8025 * same number of lines. */
8026 if (gui.in_use && gui_mch_adjust_charheight() == OK)
8027 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
8029 #endif
8031 #ifdef FEAT_FOLDING
8032 /* 'foldlevel' */
8033 else if (pp == &curwin->w_p_fdl)
8035 if (curwin->w_p_fdl < 0)
8036 curwin->w_p_fdl = 0;
8037 newFoldLevel();
8040 /* 'foldminlines' */
8041 else if (pp == &curwin->w_p_fml)
8043 foldUpdateAll(curwin);
8046 /* 'foldnestmax' */
8047 else if (pp == &curwin->w_p_fdn)
8049 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8050 foldUpdateAll(curwin);
8053 /* 'foldcolumn' */
8054 else if (pp == &curwin->w_p_fdc)
8056 if (curwin->w_p_fdc < 0)
8058 errmsg = e_positive;
8059 curwin->w_p_fdc = 0;
8061 else if (curwin->w_p_fdc > 12)
8063 errmsg = e_invarg;
8064 curwin->w_p_fdc = 12;
8068 /* 'shiftwidth' or 'tabstop' */
8069 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8071 if (foldmethodIsIndent(curwin))
8072 foldUpdateAll(curwin);
8074 #endif /* FEAT_FOLDING */
8076 #ifdef FEAT_MBYTE
8077 /* 'maxcombine' */
8078 else if (pp == &p_mco)
8080 if (p_mco > MAX_MCO)
8081 p_mco = MAX_MCO;
8082 else if (p_mco < 0)
8083 p_mco = 0;
8084 screenclear(); /* will re-allocate the screen */
8086 #endif
8088 else if (pp == &curbuf->b_p_iminsert)
8090 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8092 errmsg = e_invarg;
8093 curbuf->b_p_iminsert = B_IMODE_NONE;
8095 p_iminsert = curbuf->b_p_iminsert;
8096 if (termcap_active) /* don't do this in the alternate screen */
8097 showmode();
8098 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8099 /* Show/unshow value of 'keymap' in status lines. */
8100 status_redraw_curbuf();
8101 #endif
8104 else if (pp == &p_window)
8106 if (p_window < 1)
8107 p_window = 1;
8108 else if (p_window >= Rows)
8109 p_window = Rows - 1;
8112 else if (pp == &curbuf->b_p_imsearch)
8114 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8116 errmsg = e_invarg;
8117 curbuf->b_p_imsearch = B_IMODE_NONE;
8119 p_imsearch = curbuf->b_p_imsearch;
8122 #ifdef FEAT_TITLE
8123 /* if 'titlelen' has changed, redraw the title */
8124 else if (pp == &p_titlelen)
8126 if (p_titlelen < 0)
8128 errmsg = e_positive;
8129 p_titlelen = 85;
8131 if (starting != NO_SCREEN && old_value != p_titlelen)
8132 need_maketitle = TRUE;
8134 #endif
8136 /* if p_ch changed value, change the command line height */
8137 else if (pp == &p_ch)
8139 if (p_ch < 1)
8141 errmsg = e_positive;
8142 p_ch = 1;
8144 if (p_ch > Rows - min_rows() + 1)
8145 p_ch = Rows - min_rows() + 1;
8147 /* Only compute the new window layout when startup has been
8148 * completed. Otherwise the frame sizes may be wrong. */
8149 if (p_ch != old_value && full_screen
8150 #ifdef FEAT_GUI
8151 && !gui.starting
8152 #endif
8154 command_height();
8157 /* when 'updatecount' changes from zero to non-zero, open swap files */
8158 else if (pp == &p_uc)
8160 if (p_uc < 0)
8162 errmsg = e_positive;
8163 p_uc = 100;
8165 if (p_uc && !old_value)
8166 ml_open_files();
8168 #ifdef MZSCHEME_GUI_THREADS
8169 else if (pp == &p_mzq)
8170 mzvim_reset_timer();
8171 #endif
8173 /* sync undo before 'undolevels' changes */
8174 else if (pp == &p_ul)
8176 /* use the old value, otherwise u_sync() may not work properly */
8177 p_ul = old_value;
8178 u_sync(TRUE);
8179 p_ul = value;
8182 #ifdef FEAT_LINEBREAK
8183 /* 'numberwidth' must be positive */
8184 else if (pp == &curwin->w_p_nuw)
8186 if (curwin->w_p_nuw < 1)
8188 errmsg = e_positive;
8189 curwin->w_p_nuw = 1;
8191 if (curwin->w_p_nuw > 10)
8193 errmsg = e_invarg;
8194 curwin->w_p_nuw = 10;
8196 curwin->w_nrwidth_line_count = 0;
8199 /* 'breakindentmin' must be positive */
8200 else if (pp == &curwin->w_p_brimin)
8202 if (curwin->w_p_brimin < 1)
8204 errmsg = e_positive;
8205 curwin->w_p_brimin = 1;
8208 #endif
8211 * Check the bounds for numeric options here
8213 if (Rows < min_rows() && full_screen)
8215 if (errbuf != NULL)
8217 vim_snprintf((char *)errbuf, errbuflen,
8218 _("E593: Need at least %d lines"), min_rows());
8219 errmsg = errbuf;
8221 Rows = min_rows();
8223 if (Columns < MIN_COLUMNS && full_screen)
8225 if (errbuf != NULL)
8227 vim_snprintf((char *)errbuf, errbuflen,
8228 _("E594: Need at least %d columns"), MIN_COLUMNS);
8229 errmsg = errbuf;
8231 Columns = MIN_COLUMNS;
8233 /* Limit the values to avoid an overflow in Rows * Columns. */
8234 if (Columns > 10000)
8235 Columns = 10000;
8236 if (Rows > 1000)
8237 Rows = 1000;
8239 #ifdef DJGPP
8240 /* avoid a crash by checking for a too large value of 'columns' */
8241 if (old_Columns != Columns && full_screen && term_console)
8242 mch_check_columns();
8243 #endif
8246 * If the screen (shell) height has been changed, assume it is the
8247 * physical screenheight.
8249 if (old_Rows != Rows || old_Columns != Columns)
8251 /* Changing the screen size is not allowed while updating the screen. */
8252 if (updating_screen)
8253 *pp = old_value;
8254 else if (full_screen
8255 #ifdef FEAT_GUI
8256 && !gui.starting
8257 #endif
8259 set_shellsize((int)Columns, (int)Rows, TRUE);
8260 else
8262 /* Postpone the resizing; check the size and cmdline position for
8263 * messages. */
8264 check_shellsize();
8265 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8266 cmdline_row = Rows - p_ch;
8268 if (p_window >= Rows || !option_was_set((char_u *)"window"))
8269 p_window = Rows - 1;
8272 if (curbuf->b_p_sts < 0)
8274 errmsg = e_positive;
8275 curbuf->b_p_sts = 0;
8277 if (curbuf->b_p_ts <= 0)
8279 errmsg = e_positive;
8280 curbuf->b_p_ts = 8;
8282 if (curbuf->b_p_tw < 0)
8284 errmsg = e_positive;
8285 curbuf->b_p_tw = 0;
8287 if (p_tm < 0)
8289 errmsg = e_positive;
8290 p_tm = 0;
8292 if ((curwin->w_p_scr <= 0
8293 || (curwin->w_p_scr > curwin->w_height
8294 && curwin->w_height > 0))
8295 && full_screen)
8297 if (pp == &(curwin->w_p_scr))
8299 if (curwin->w_p_scr != 0)
8300 errmsg = e_scroll;
8301 win_comp_scroll(curwin);
8303 /* If 'scroll' became invalid because of a side effect silently adjust
8304 * it. */
8305 else if (curwin->w_p_scr <= 0)
8306 curwin->w_p_scr = 1;
8307 else /* curwin->w_p_scr > curwin->w_height */
8308 curwin->w_p_scr = curwin->w_height;
8310 if (p_hi < 0)
8312 errmsg = e_positive;
8313 p_hi = 0;
8315 if (p_report < 0)
8317 errmsg = e_positive;
8318 p_report = 1;
8320 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
8322 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8323 p_sj = Rows / 2;
8324 else
8326 errmsg = e_scroll;
8327 p_sj = 1;
8330 if (p_so < 0 && full_screen)
8332 errmsg = e_scroll;
8333 p_so = 0;
8335 if (p_siso < 0 && full_screen)
8337 errmsg = e_positive;
8338 p_siso = 0;
8340 #ifdef FEAT_CMDWIN
8341 if (p_cwh < 1)
8343 errmsg = e_positive;
8344 p_cwh = 1;
8346 #endif
8347 if (p_ut < 0)
8349 errmsg = e_positive;
8350 p_ut = 2000;
8352 if (p_ss < 0)
8354 errmsg = e_positive;
8355 p_ss = 0;
8358 /* May set global value for local option. */
8359 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8360 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8362 options[opt_idx].flags |= P_WAS_SET;
8364 comp_col(); /* in case 'columns' or 'ls' changed */
8365 if (curwin->w_curswant != MAXCOL)
8366 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8367 check_redraw(options[opt_idx].flags);
8369 return errmsg;
8373 * Called after an option changed: check if something needs to be redrawn.
8375 static void
8376 check_redraw(flags)
8377 long_u flags;
8379 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8380 int clear = (flags & P_RCLR) == P_RCLR;
8381 int all = ((flags & P_RALL) == P_RALL || clear);
8383 #ifdef FEAT_WINDOWS
8384 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8385 status_redraw_all();
8386 #endif
8388 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8389 changed_window_setting();
8390 if (flags & P_RBUF)
8391 redraw_curbuf_later(NOT_VALID);
8392 if (clear)
8393 redraw_all_later(CLEAR);
8394 else if (all)
8395 redraw_all_later(NOT_VALID);
8399 * Find index for option 'arg'.
8400 * Return -1 if not found.
8402 static int
8403 findoption(arg)
8404 char_u *arg;
8406 int opt_idx;
8407 char *s, *p;
8408 static short quick_tab[27] = {0, 0}; /* quick access table */
8409 int is_term_opt;
8412 * For first call: Initialize the quick-access table.
8413 * It contains the index for the first option that starts with a certain
8414 * letter. There are 26 letters, plus the first "t_" option.
8416 if (quick_tab[1] == 0)
8418 p = options[0].fullname;
8419 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8421 if (s[0] != p[0])
8423 if (s[0] == 't' && s[1] == '_')
8424 quick_tab[26] = opt_idx;
8425 else
8426 quick_tab[CharOrdLow(s[0])] = opt_idx;
8428 p = s;
8433 * Check for name starting with an illegal character.
8435 #ifdef EBCDIC
8436 if (!islower(arg[0]))
8437 #else
8438 if (arg[0] < 'a' || arg[0] > 'z')
8439 #endif
8440 return -1;
8442 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8443 if (is_term_opt)
8444 opt_idx = quick_tab[26];
8445 else
8446 opt_idx = quick_tab[CharOrdLow(arg[0])];
8447 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8449 if (STRCMP(arg, s) == 0) /* match full name */
8450 break;
8452 if (s == NULL && !is_term_opt)
8454 opt_idx = quick_tab[CharOrdLow(arg[0])];
8455 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8457 s = options[opt_idx].shortname;
8458 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8459 break;
8460 s = NULL;
8463 if (s == NULL)
8464 opt_idx = -1;
8465 return opt_idx;
8468 #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
8470 * Get the value for an option.
8472 * Returns:
8473 * Number or Toggle option: 1, *numval gets value.
8474 * String option: 0, *stringval gets allocated string.
8475 * Hidden Number or Toggle option: -1.
8476 * hidden String option: -2.
8477 * unknown option: -3.
8480 get_option_value(name, numval, stringval, opt_flags)
8481 char_u *name;
8482 long *numval;
8483 char_u **stringval; /* NULL when only checking existance */
8484 int opt_flags;
8486 int opt_idx;
8487 char_u *varp;
8489 opt_idx = findoption(name);
8490 if (opt_idx < 0) /* unknown option */
8491 return -3;
8493 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8495 if (options[opt_idx].flags & P_STRING)
8497 if (varp == NULL) /* hidden option */
8498 return -2;
8499 if (stringval != NULL)
8501 #ifdef FEAT_CRYPT
8502 /* never return the value of the crypt key */
8503 if ((char_u **)varp == &curbuf->b_p_key
8504 && **(char_u **)(varp) != NUL)
8505 *stringval = vim_strsave((char_u *)"*****");
8506 else
8507 #endif
8508 *stringval = vim_strsave(*(char_u **)(varp));
8510 return 0;
8513 if (varp == NULL) /* hidden option */
8514 return -1;
8515 if (options[opt_idx].flags & P_NUM)
8516 *numval = *(long *)varp;
8517 else
8519 /* Special case: 'modified' is b_changed, but we also want to consider
8520 * it set when 'ff' or 'fenc' changed. */
8521 if ((int *)varp == &curbuf->b_changed)
8522 *numval = curbufIsChanged();
8523 else
8524 *numval = *(int *)varp;
8526 return 1;
8528 #endif
8531 * Set the value of option "name".
8532 * Use "string" for string options, use "number" for other options.
8534 void
8535 set_option_value(name, number, string, opt_flags)
8536 char_u *name;
8537 long number;
8538 char_u *string;
8539 int opt_flags; /* OPT_LOCAL or 0 (both) */
8541 int opt_idx;
8542 char_u *varp;
8543 long_u flags;
8545 opt_idx = findoption(name);
8546 if (opt_idx < 0)
8547 EMSG2(_("E355: Unknown option: %s"), name);
8548 else
8550 flags = options[opt_idx].flags;
8551 #ifdef HAVE_SANDBOX
8552 /* Disallow changing some options in the sandbox */
8553 if (sandbox > 0 && (flags & P_SECURE))
8555 EMSG(_(e_sandbox));
8556 return;
8558 #endif
8559 if (flags & P_STRING)
8560 set_string_option(opt_idx, string, opt_flags);
8561 else
8563 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8564 if (varp != NULL) /* hidden option is not changed */
8566 if (number == 0 && string != NULL)
8568 int idx;
8570 /* Either we are given a string or we are setting option
8571 * to zero. */
8572 for (idx = 0; string[idx] == '0'; ++idx)
8574 if (string[idx] != NUL || idx == 0)
8576 /* There's another character after zeros or the string
8577 * is empty. In both cases, we are trying to set a
8578 * num option using a string. */
8579 EMSG3(_("E521: Number required: &%s = '%s'"),
8580 name, string);
8581 return; /* do nothing as we hit an error */
8585 if (flags & P_NUM)
8586 (void)set_num_option(opt_idx, varp, number,
8587 NULL, 0, opt_flags);
8588 else
8589 (void)set_bool_option(opt_idx, varp, (int)number,
8590 opt_flags);
8597 * Get the terminal code for a terminal option.
8598 * Returns NULL when not found.
8600 char_u *
8601 get_term_code(tname)
8602 char_u *tname;
8604 int opt_idx;
8605 char_u *varp;
8607 if (tname[0] != 't' || tname[1] != '_' ||
8608 tname[2] == NUL || tname[3] == NUL)
8609 return NULL;
8610 if ((opt_idx = findoption(tname)) >= 0)
8612 varp = get_varp(&(options[opt_idx]));
8613 if (varp != NULL)
8614 varp = *(char_u **)(varp);
8615 return varp;
8617 return find_termcode(tname + 2);
8620 char_u *
8621 get_highlight_default()
8623 int i;
8625 i = findoption((char_u *)"hl");
8626 if (i >= 0)
8627 return options[i].def_val[VI_DEFAULT];
8628 return (char_u *)NULL;
8631 #if defined(FEAT_MBYTE) || defined(PROTO)
8632 char_u *
8633 get_encoding_default()
8635 int i;
8637 i = findoption((char_u *)"enc");
8638 if (i >= 0)
8639 return options[i].def_val[VI_DEFAULT];
8640 return (char_u *)NULL;
8642 #endif
8645 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8647 static int
8648 find_key_option(arg)
8649 char_u *arg;
8651 int key;
8652 int modifiers;
8655 * Don't use get_special_key_code() for t_xx, we don't want it to call
8656 * add_termcap_entry().
8658 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8659 key = TERMCAP2KEY(arg[2], arg[3]);
8660 else
8662 --arg; /* put arg at the '<' */
8663 modifiers = 0;
8664 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
8665 if (modifiers) /* can't handle modifiers here */
8666 key = 0;
8668 return key;
8672 * if 'all' == 0: show changed options
8673 * if 'all' == 1: show all normal options
8674 * if 'all' == 2: show all terminal options
8676 static void
8677 showoptions(all, opt_flags)
8678 int all;
8679 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8681 struct vimoption *p;
8682 int col;
8683 int isterm;
8684 char_u *varp;
8685 struct vimoption **items;
8686 int item_count;
8687 int run;
8688 int row, rows;
8689 int cols;
8690 int i;
8691 int len;
8693 #define INC 20
8694 #define GAP 3
8696 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8697 PARAM_COUNT));
8698 if (items == NULL)
8699 return;
8701 /* Highlight title */
8702 if (all == 2)
8703 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8704 else if (opt_flags & OPT_GLOBAL)
8705 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8706 else if (opt_flags & OPT_LOCAL)
8707 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8708 else
8709 MSG_PUTS_TITLE(_("\n--- Options ---"));
8712 * do the loop two times:
8713 * 1. display the short items
8714 * 2. display the long items (only strings and numbers)
8716 for (run = 1; run <= 2 && !got_int; ++run)
8719 * collect the items in items[]
8721 item_count = 0;
8722 for (p = &options[0]; p->fullname != NULL; p++)
8724 varp = NULL;
8725 isterm = istermoption(p);
8726 if (opt_flags != 0)
8728 if (p->indir != PV_NONE && !isterm)
8729 varp = get_varp_scope(p, opt_flags);
8731 else
8732 varp = get_varp(p);
8733 if (varp != NULL
8734 && ((all == 2 && isterm)
8735 || (all == 1 && !isterm)
8736 || (all == 0 && !optval_default(p, varp))))
8738 if (p->flags & P_BOOL)
8739 len = 1; /* a toggle option fits always */
8740 else
8742 option_value2string(p, opt_flags);
8743 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8745 if ((len <= INC - GAP && run == 1) ||
8746 (len > INC - GAP && run == 2))
8747 items[item_count++] = p;
8752 * display the items
8754 if (run == 1)
8756 cols = (Columns + GAP - 3) / INC;
8757 if (cols == 0)
8758 cols = 1;
8759 rows = (item_count + cols - 1) / cols;
8761 else /* run == 2 */
8762 rows = item_count;
8763 for (row = 0; row < rows && !got_int; ++row)
8765 msg_putchar('\n'); /* go to next line */
8766 if (got_int) /* 'q' typed in more */
8767 break;
8768 col = 0;
8769 for (i = row; i < item_count; i += rows)
8771 msg_col = col; /* make columns */
8772 showoneopt(items[i], opt_flags);
8773 col += INC;
8775 out_flush();
8776 ui_breakcheck();
8779 vim_free(items);
8783 * Return TRUE if option "p" has its default value.
8785 static int
8786 optval_default(p, varp)
8787 struct vimoption *p;
8788 char_u *varp;
8790 int dvi;
8792 if (varp == NULL)
8793 return TRUE; /* hidden option is always at default */
8794 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8795 if (p->flags & P_NUM)
8796 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
8797 if (p->flags & P_BOOL)
8798 /* the cast to long is required for Manx C, long_i is
8799 * needed for MSVC */
8800 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
8801 /* P_STRING */
8802 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8806 * showoneopt: show the value of one option
8807 * must not be called with a hidden option!
8809 static void
8810 showoneopt(p, opt_flags)
8811 struct vimoption *p;
8812 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8814 char_u *varp;
8815 int save_silent = silent_mode;
8817 silent_mode = FALSE;
8818 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
8820 varp = get_varp_scope(p, opt_flags);
8822 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8823 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8824 ? !curbufIsChanged() : !*(int *)varp))
8825 MSG_PUTS("no");
8826 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8827 MSG_PUTS("--");
8828 else
8829 MSG_PUTS(" ");
8830 MSG_PUTS(p->fullname);
8831 if (!(p->flags & P_BOOL))
8833 msg_putchar('=');
8834 /* put value string in NameBuff */
8835 option_value2string(p, opt_flags);
8836 msg_outtrans(NameBuff);
8839 silent_mode = save_silent;
8840 info_message = FALSE;
8844 * Write modified options as ":set" commands to a file.
8846 * There are three values for "opt_flags":
8847 * OPT_GLOBAL: Write global option values and fresh values of
8848 * buffer-local options (used for start of a session
8849 * file).
8850 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8851 * curwin (used for a vimrc file).
8852 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8853 * and local values for window-local options of
8854 * curwin. Local values are also written when at the
8855 * default value, because a modeline or autocommand
8856 * may have set them when doing ":edit file" and the
8857 * user has set them back at the default or fresh
8858 * value.
8859 * When "local_only" is TRUE, don't write fresh
8860 * values, only local values (for ":mkview").
8861 * (fresh value = value used for a new buffer or window for a local option).
8863 * Return FAIL on error, OK otherwise.
8866 makeset(fd, opt_flags, local_only)
8867 FILE *fd;
8868 int opt_flags;
8869 int local_only;
8871 struct vimoption *p;
8872 char_u *varp; /* currently used value */
8873 char_u *varp_fresh; /* local value */
8874 char_u *varp_local = NULL; /* fresh value */
8875 char *cmd;
8876 int round;
8877 int pri;
8880 * The options that don't have a default (terminal name, columns, lines)
8881 * are never written. Terminal options are also not written.
8882 * Do the loop over "options[]" twice: once for options with the
8883 * P_PRI_MKRC flag and once without.
8885 for (pri = 1; pri >= 0; --pri)
8887 for (p = &options[0]; !istermoption(p); p++)
8888 if (!(p->flags & P_NO_MKRC)
8889 && !istermoption(p)
8890 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
8892 /* skip global option when only doing locals */
8893 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8894 continue;
8896 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8897 * file, they are always buffer-specific. */
8898 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8899 continue;
8901 /* Global values are only written when not at the default value. */
8902 varp = get_varp_scope(p, opt_flags);
8903 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8904 continue;
8906 round = 2;
8907 if (p->indir != PV_NONE)
8909 if (p->var == VAR_WIN)
8911 /* skip window-local option when only doing globals */
8912 if (!(opt_flags & OPT_LOCAL))
8913 continue;
8914 /* When fresh value of window-local option is not at the
8915 * default, need to write it too. */
8916 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8918 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8919 if (!optval_default(p, varp_fresh))
8921 round = 1;
8922 varp_local = varp;
8923 varp = varp_fresh;
8929 /* Round 1: fresh value for window-local options.
8930 * Round 2: other values */
8931 for ( ; round <= 2; varp = varp_local, ++round)
8933 if (round == 1 || (opt_flags & OPT_GLOBAL))
8934 cmd = "set";
8935 else
8936 cmd = "setlocal";
8938 if (p->flags & P_BOOL)
8940 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8941 return FAIL;
8943 else if (p->flags & P_NUM)
8945 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8946 return FAIL;
8948 else /* P_STRING */
8950 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8951 int do_endif = FALSE;
8953 /* Don't set 'syntax' and 'filetype' again if the value is
8954 * already right, avoids reloading the syntax file. */
8955 if (
8956 # if defined(FEAT_SYN_HL)
8957 p->indir == PV_SYN
8958 # if defined(FEAT_AUTOCMD)
8960 # endif
8961 # endif
8962 # if defined(FEAT_AUTOCMD)
8963 p->indir == PV_FT
8964 # endif
8967 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8968 *(char_u **)(varp)) < 0
8969 || put_eol(fd) < 0)
8970 return FAIL;
8971 do_endif = TRUE;
8973 #endif
8974 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8975 (p->flags & P_EXPAND) != 0) == FAIL)
8976 return FAIL;
8977 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8978 if (do_endif)
8980 if (put_line(fd, "endif") == FAIL)
8981 return FAIL;
8983 #endif
8988 return OK;
8991 #if defined(FEAT_FOLDING) || defined(PROTO)
8993 * Generate set commands for the local fold options only. Used when
8994 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8997 makefoldset(fd)
8998 FILE *fd;
9000 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9001 # ifdef FEAT_EVAL
9002 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9003 == FAIL
9004 # endif
9005 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9006 == FAIL
9007 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9008 == FAIL
9009 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9010 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9011 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9012 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9014 return FAIL;
9016 return OK;
9018 #endif
9020 static int
9021 put_setstring(fd, cmd, name, valuep, expand)
9022 FILE *fd;
9023 char *cmd;
9024 char *name;
9025 char_u **valuep;
9026 int expand;
9028 char_u *s;
9029 char_u buf[MAXPATHL];
9031 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9032 return FAIL;
9033 if (*valuep != NULL)
9035 /* Output 'pastetoggle' as key names. For other
9036 * options some characters have to be escaped with
9037 * CTRL-V or backslash */
9038 if (valuep == &p_pt)
9040 s = *valuep;
9041 while (*s != NUL)
9042 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
9043 return FAIL;
9045 else if (expand)
9047 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9048 if (put_escstr(fd, buf, 2) == FAIL)
9049 return FAIL;
9051 else if (put_escstr(fd, *valuep, 2) == FAIL)
9052 return FAIL;
9054 if (put_eol(fd) < 0)
9055 return FAIL;
9056 return OK;
9059 static int
9060 put_setnum(fd, cmd, name, valuep)
9061 FILE *fd;
9062 char *cmd;
9063 char *name;
9064 long *valuep;
9066 long wc;
9068 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9069 return FAIL;
9070 if (wc_use_keyname((char_u *)valuep, &wc))
9072 /* print 'wildchar' and 'wildcharm' as a key name */
9073 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9074 return FAIL;
9076 else if (fprintf(fd, "%ld", *valuep) < 0)
9077 return FAIL;
9078 if (put_eol(fd) < 0)
9079 return FAIL;
9080 return OK;
9083 static int
9084 put_setbool(fd, cmd, name, value)
9085 FILE *fd;
9086 char *cmd;
9087 char *name;
9088 int value;
9090 if (value < 0) /* global/local option using global value */
9091 return OK;
9092 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9093 || put_eol(fd) < 0)
9094 return FAIL;
9095 return OK;
9099 * Clear all the terminal options.
9100 * If the option has been allocated, free the memory.
9101 * Terminal options are never hidden or indirect.
9103 void
9104 clear_termoptions()
9107 * Reset a few things before clearing the old options. This may cause
9108 * outputting a few things that the terminal doesn't understand, but the
9109 * screen will be cleared later, so this is OK.
9111 #ifdef FEAT_MOUSE_TTY
9112 mch_setmouse(FALSE); /* switch mouse off */
9113 #endif
9114 #ifdef FEAT_TITLE
9115 mch_restore_title(3); /* restore window titles */
9116 #endif
9117 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9118 /* When starting the GUI close the display opened for the clipboard.
9119 * After restoring the title, because that will need the display. */
9120 if (gui.starting)
9121 clear_xterm_clip();
9122 #endif
9123 #ifdef WIN3264
9125 * Check if this is allowed now.
9127 if (can_end_termcap_mode(FALSE) == TRUE)
9128 #endif
9129 stoptermcap(); /* stop termcap mode */
9131 free_termoptions();
9134 void
9135 free_termoptions()
9137 struct vimoption *p;
9139 for (p = &options[0]; p->fullname != NULL; p++)
9140 if (istermoption(p))
9142 if (p->flags & P_ALLOCED)
9143 free_string_option(*(char_u **)(p->var));
9144 if (p->flags & P_DEF_ALLOCED)
9145 free_string_option(p->def_val[VI_DEFAULT]);
9146 *(char_u **)(p->var) = empty_option;
9147 p->def_val[VI_DEFAULT] = empty_option;
9148 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9150 clear_termcodes();
9154 * Free the string for one term option, if it was allocated.
9155 * Set the string to empty_option and clear allocated flag.
9156 * "var" points to the option value.
9158 void
9159 free_one_termoption(var)
9160 char_u *var;
9162 struct vimoption *p;
9164 for (p = &options[0]; p->fullname != NULL; p++)
9165 if (p->var == var)
9167 if (p->flags & P_ALLOCED)
9168 free_string_option(*(char_u **)(p->var));
9169 *(char_u **)(p->var) = empty_option;
9170 p->flags &= ~P_ALLOCED;
9171 break;
9176 * Set the terminal option defaults to the current value.
9177 * Used after setting the terminal name.
9179 void
9180 set_term_defaults()
9182 struct vimoption *p;
9184 for (p = &options[0]; p->fullname != NULL; p++)
9186 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9188 if (p->flags & P_DEF_ALLOCED)
9190 free_string_option(p->def_val[VI_DEFAULT]);
9191 p->flags &= ~P_DEF_ALLOCED;
9193 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9194 if (p->flags & P_ALLOCED)
9196 p->flags |= P_DEF_ALLOCED;
9197 p->flags &= ~P_ALLOCED; /* don't free the value now */
9204 * return TRUE if 'p' starts with 't_'
9206 static int
9207 istermoption(p)
9208 struct vimoption *p;
9210 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9214 * Compute columns for ruler and shown command. 'sc_col' is also used to
9215 * decide what the maximum length of a message on the status line can be.
9216 * If there is a status line for the last window, 'sc_col' is independent
9217 * of 'ru_col'.
9220 #define COL_RULER 17 /* columns needed by standard ruler */
9222 void
9223 comp_col()
9225 #if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9226 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9228 sc_col = 0;
9229 ru_col = 0;
9230 if (p_ru)
9232 #ifdef FEAT_STL_OPT
9233 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9234 #else
9235 ru_col = COL_RULER + 1;
9236 #endif
9237 /* no last status line, adjust sc_col */
9238 if (!last_has_status)
9239 sc_col = ru_col;
9241 if (p_sc)
9243 sc_col += SHOWCMD_COLS;
9244 if (!p_ru || last_has_status) /* no need for separating space */
9245 ++sc_col;
9247 sc_col = Columns - sc_col;
9248 ru_col = Columns - ru_col;
9249 if (sc_col <= 0) /* screen too narrow, will become a mess */
9250 sc_col = 1;
9251 if (ru_col <= 0)
9252 ru_col = 1;
9253 #else
9254 sc_col = Columns;
9255 ru_col = Columns;
9256 #endif
9260 * Get pointer to option variable, depending on local or global scope.
9262 static char_u *
9263 get_varp_scope(p, opt_flags)
9264 struct vimoption *p;
9265 int opt_flags;
9267 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9269 if (p->var == VAR_WIN)
9270 return (char_u *)GLOBAL_WO(get_varp(p));
9271 return p->var;
9273 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
9275 switch ((int)p->indir)
9277 #ifdef FEAT_QUICKFIX
9278 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9279 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9280 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
9281 #endif
9282 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9283 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9284 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
9285 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
9286 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
9287 #ifdef FEAT_FIND_ID
9288 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9289 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
9290 #endif
9291 #ifdef FEAT_INS_EXPAND
9292 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9293 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
9294 #endif
9295 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9296 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9297 #endif
9298 #ifdef FEAT_STL_OPT
9299 case PV_STL: return (char_u *)&(curwin->w_p_stl);
9300 #endif
9302 return NULL; /* "cannot happen" */
9304 return get_varp(p);
9308 * Get pointer to option variable.
9310 static char_u *
9311 get_varp(p)
9312 struct vimoption *p;
9314 /* hidden option, always return NULL */
9315 if (p->var == NULL)
9316 return NULL;
9318 switch ((int)p->indir)
9320 case PV_NONE: return p->var;
9322 /* global option with local value: use local value if it's been set */
9323 case PV_EP: return *curbuf->b_p_ep != NUL
9324 ? (char_u *)&curbuf->b_p_ep : p->var;
9325 case PV_KP: return *curbuf->b_p_kp != NUL
9326 ? (char_u *)&curbuf->b_p_kp : p->var;
9327 case PV_PATH: return *curbuf->b_p_path != NUL
9328 ? (char_u *)&(curbuf->b_p_path) : p->var;
9329 case PV_AR: return curbuf->b_p_ar >= 0
9330 ? (char_u *)&(curbuf->b_p_ar) : p->var;
9331 case PV_TAGS: return *curbuf->b_p_tags != NUL
9332 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9333 #ifdef FEAT_FIND_ID
9334 case PV_DEF: return *curbuf->b_p_def != NUL
9335 ? (char_u *)&(curbuf->b_p_def) : p->var;
9336 case PV_INC: return *curbuf->b_p_inc != NUL
9337 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9338 #endif
9339 #ifdef FEAT_INS_EXPAND
9340 case PV_DICT: return *curbuf->b_p_dict != NUL
9341 ? (char_u *)&(curbuf->b_p_dict) : p->var;
9342 case PV_TSR: return *curbuf->b_p_tsr != NUL
9343 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9344 #endif
9345 #ifdef FEAT_QUICKFIX
9346 case PV_EFM: return *curbuf->b_p_efm != NUL
9347 ? (char_u *)&(curbuf->b_p_efm) : p->var;
9348 case PV_GP: return *curbuf->b_p_gp != NUL
9349 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9350 case PV_MP: return *curbuf->b_p_mp != NUL
9351 ? (char_u *)&(curbuf->b_p_mp) : p->var;
9352 #endif
9353 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9354 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9355 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9356 #endif
9357 #ifdef FEAT_STL_OPT
9358 case PV_STL: return *curwin->w_p_stl != NUL
9359 ? (char_u *)&(curwin->w_p_stl) : p->var;
9360 #endif
9362 #ifdef FEAT_ARABIC
9363 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9364 #endif
9365 case PV_LIST: return (char_u *)&(curwin->w_p_list);
9366 #ifdef FEAT_SPELL
9367 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9368 #endif
9369 #ifdef FEAT_SYN_HL
9370 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9371 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9372 #endif
9373 #ifdef FEAT_DIFF
9374 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9375 #endif
9376 #ifdef FEAT_FOLDING
9377 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9378 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9379 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9380 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9381 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9382 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9383 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9384 # ifdef FEAT_EVAL
9385 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9386 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9387 # endif
9388 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9389 #endif
9390 case PV_NU: return (char_u *)&(curwin->w_p_nu);
9391 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
9392 #ifdef FEAT_LINEBREAK
9393 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9394 #endif
9395 #ifdef FEAT_WINDOWS
9396 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9397 #endif
9398 #ifdef FEAT_VERTSPLIT
9399 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9400 #endif
9401 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9402 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9403 #endif
9404 #ifdef FEAT_RIGHTLEFT
9405 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9406 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9407 #endif
9408 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9409 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9410 #ifdef FEAT_LINEBREAK
9411 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9412 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
9413 case PV_BRIMIN: return (char_u *)&(curwin->w_p_brimin);
9414 case PV_BRISHIFT: return (char_u *)&(curwin->w_p_brishift);
9415 #endif
9416 #ifdef FEAT_SCROLLBIND
9417 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9418 #endif
9420 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9421 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9422 #ifdef FEAT_MBYTE
9423 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9424 #endif
9425 #if defined(FEAT_QUICKFIX)
9426 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9427 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9428 #endif
9429 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9430 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9431 #ifdef FEAT_CINDENT
9432 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9433 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9434 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9435 #endif
9436 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9437 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9438 #endif
9439 #ifdef FEAT_COMMENTS
9440 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9441 #endif
9442 #ifdef FEAT_FOLDING
9443 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9444 #endif
9445 #ifdef FEAT_INS_EXPAND
9446 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9447 #endif
9448 #ifdef FEAT_COMPL_FUNC
9449 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
9450 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
9451 #endif
9452 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9453 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9454 #ifdef FEAT_MBYTE
9455 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9456 #endif
9457 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9458 #ifdef FEAT_AUTOCMD
9459 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9460 #endif
9461 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
9462 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
9463 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9464 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9465 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9466 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9467 #ifdef FEAT_FIND_ID
9468 # ifdef FEAT_EVAL
9469 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9470 # endif
9471 #endif
9472 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9473 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9474 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9475 #endif
9476 #ifdef FEAT_EVAL
9477 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9478 #endif
9479 #ifdef FEAT_CRYPT
9480 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9481 #endif
9482 #ifdef FEAT_LISP
9483 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9484 #endif
9485 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9486 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9487 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9488 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9489 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9490 #ifdef FEAT_OSFILETYPE
9491 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9492 #endif
9493 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
9494 #ifdef FEAT_TEXTOBJ
9495 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9496 #endif
9497 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9498 #ifdef FEAT_SMARTINDENT
9499 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9500 #endif
9501 #ifndef SHORT_FNAME
9502 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9503 #endif
9504 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9505 #ifdef FEAT_SEARCHPATH
9506 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9507 #endif
9508 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9509 #ifdef FEAT_SYN_HL
9510 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
9511 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9512 #endif
9513 #ifdef FEAT_SPELL
9514 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
9515 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
9516 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
9517 #endif
9518 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9519 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9520 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9521 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9522 #ifdef FEAT_PERSISTENT_UNDO
9523 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9524 #endif
9525 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9526 #ifdef FEAT_KEYMAP
9527 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9528 #endif
9529 #ifdef FEAT_VARTABS
9530 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
9531 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
9532 #endif
9533 default: EMSG(_("E356: get_varp ERROR"));
9535 /* always return a valid pointer to avoid a crash! */
9536 return (char_u *)&(curbuf->b_p_wm);
9540 * Get the value of 'equalprg', either the buffer-local one or the global one.
9542 char_u *
9543 get_equalprg()
9545 if (*curbuf->b_p_ep == NUL)
9546 return p_ep;
9547 return curbuf->b_p_ep;
9550 #if defined(FEAT_WINDOWS) || defined(PROTO)
9552 * Copy options from one window to another.
9553 * Used when splitting a window.
9555 void
9556 win_copy_options(wp_from, wp_to)
9557 win_T *wp_from;
9558 win_T *wp_to;
9560 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9561 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9562 # ifdef FEAT_RIGHTLEFT
9563 # ifdef FEAT_FKMAP
9564 /* Is this right? */
9565 wp_to->w_farsi = wp_from->w_farsi;
9566 # endif
9567 # endif
9569 #endif
9572 * Copy the options from one winopt_T to another.
9573 * Doesn't free the old option values in "to", use clear_winopt() for that.
9574 * The 'scroll' option is not copied, because it depends on the window height.
9575 * The 'previewwindow' option is reset, there can be only one preview window.
9577 void
9578 copy_winopt(from, to)
9579 winopt_T *from;
9580 winopt_T *to;
9582 #ifdef FEAT_ARABIC
9583 to->wo_arab = from->wo_arab;
9584 #endif
9585 to->wo_list = from->wo_list;
9586 to->wo_nu = from->wo_nu;
9587 to->wo_rnu = from->wo_rnu;
9588 #ifdef FEAT_LINEBREAK
9589 to->wo_nuw = from->wo_nuw;
9590 #endif
9591 #ifdef FEAT_RIGHTLEFT
9592 to->wo_rl = from->wo_rl;
9593 to->wo_rlc = vim_strsave(from->wo_rlc);
9594 #endif
9595 #ifdef FEAT_STL_OPT
9596 to->wo_stl = vim_strsave(from->wo_stl);
9597 #endif
9598 to->wo_wrap = from->wo_wrap;
9599 #ifdef FEAT_LINEBREAK
9600 to->wo_lbr = from->wo_lbr;
9601 to->wo_bri = from->wo_bri;
9602 to->wo_brimin = from->wo_brimin;
9603 #endif
9604 #ifdef FEAT_SCROLLBIND
9605 to->wo_scb = from->wo_scb;
9606 #endif
9607 #ifdef FEAT_SPELL
9608 to->wo_spell = from->wo_spell;
9609 #endif
9610 #ifdef FEAT_SYN_HL
9611 to->wo_cuc = from->wo_cuc;
9612 to->wo_cul = from->wo_cul;
9613 #endif
9614 #ifdef FEAT_DIFF
9615 to->wo_diff = from->wo_diff;
9616 #endif
9617 #ifdef FEAT_FOLDING
9618 to->wo_fdc = from->wo_fdc;
9619 to->wo_fen = from->wo_fen;
9620 to->wo_fdi = vim_strsave(from->wo_fdi);
9621 to->wo_fml = from->wo_fml;
9622 to->wo_fdl = from->wo_fdl;
9623 to->wo_fdm = vim_strsave(from->wo_fdm);
9624 to->wo_fdn = from->wo_fdn;
9625 # ifdef FEAT_EVAL
9626 to->wo_fde = vim_strsave(from->wo_fde);
9627 to->wo_fdt = vim_strsave(from->wo_fdt);
9628 # endif
9629 to->wo_fmr = vim_strsave(from->wo_fmr);
9630 #endif
9631 check_winopt(to); /* don't want NULL pointers */
9635 * Check string options in a window for a NULL value.
9637 void
9638 check_win_options(win)
9639 win_T *win;
9641 check_winopt(&win->w_onebuf_opt);
9642 check_winopt(&win->w_allbuf_opt);
9646 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9648 void
9649 check_winopt(wop)
9650 winopt_T *wop UNUSED;
9652 #ifdef FEAT_FOLDING
9653 check_string_option(&wop->wo_fdi);
9654 check_string_option(&wop->wo_fdm);
9655 # ifdef FEAT_EVAL
9656 check_string_option(&wop->wo_fde);
9657 check_string_option(&wop->wo_fdt);
9658 # endif
9659 check_string_option(&wop->wo_fmr);
9660 #endif
9661 #ifdef FEAT_RIGHTLEFT
9662 check_string_option(&wop->wo_rlc);
9663 #endif
9664 #ifdef FEAT_STL_OPT
9665 check_string_option(&wop->wo_stl);
9666 #endif
9670 * Free the allocated memory inside a winopt_T.
9672 void
9673 clear_winopt(wop)
9674 winopt_T *wop UNUSED;
9676 #ifdef FEAT_FOLDING
9677 clear_string_option(&wop->wo_fdi);
9678 clear_string_option(&wop->wo_fdm);
9679 # ifdef FEAT_EVAL
9680 clear_string_option(&wop->wo_fde);
9681 clear_string_option(&wop->wo_fdt);
9682 # endif
9683 clear_string_option(&wop->wo_fmr);
9684 #endif
9685 #ifdef FEAT_RIGHTLEFT
9686 clear_string_option(&wop->wo_rlc);
9687 #endif
9688 #ifdef FEAT_STL_OPT
9689 clear_string_option(&wop->wo_stl);
9690 #endif
9694 * Copy global option values to local options for one buffer.
9695 * Used when creating a new buffer and sometimes when entering a buffer.
9696 * flags:
9697 * BCO_ENTER We will enter the buf buffer.
9698 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9699 * appropriate.
9700 * BCO_NOHELP Don't copy the values to a help buffer.
9702 void
9703 buf_copy_options(buf, flags)
9704 buf_T *buf;
9705 int flags;
9707 int should_copy = TRUE;
9708 char_u *save_p_isk = NULL; /* init for GCC */
9709 int dont_do_help;
9710 int did_isk = FALSE;
9713 * Don't do anything of the buffer is invalid.
9715 if (buf == NULL || !buf_valid(buf))
9716 return;
9719 * Skip this when the option defaults have not been set yet. Happens when
9720 * main() allocates the first buffer.
9722 if (p_cpo != NULL)
9725 * Always copy when entering and 'cpo' contains 'S'.
9726 * Don't copy when already initialized.
9727 * Don't copy when 'cpo' contains 's' and not entering.
9728 * 'S' BCO_ENTER initialized 's' should_copy
9729 * yes yes X X TRUE
9730 * yes no yes X FALSE
9731 * no X yes X FALSE
9732 * X no no yes FALSE
9733 * X no no no TRUE
9734 * no yes no X TRUE
9736 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9737 && (buf->b_p_initialized
9738 || (!(flags & BCO_ENTER)
9739 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9740 should_copy = FALSE;
9742 if (should_copy || (flags & BCO_ALWAYS))
9744 /* Don't copy the options specific to a help buffer when
9745 * BCO_NOHELP is given or the options were initialized already
9746 * (jumping back to a help file with CTRL-T or CTRL-O) */
9747 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9748 || buf->b_p_initialized;
9749 if (dont_do_help) /* don't free b_p_isk */
9751 save_p_isk = buf->b_p_isk;
9752 buf->b_p_isk = NULL;
9755 * Always free the allocated strings.
9756 * If not already initialized, set 'readonly' and copy 'fileformat'.
9758 if (!buf->b_p_initialized)
9760 free_buf_options(buf, TRUE);
9761 buf->b_p_ro = FALSE; /* don't copy readonly */
9762 buf->b_p_tx = p_tx;
9763 #ifdef FEAT_MBYTE
9764 buf->b_p_fenc = vim_strsave(p_fenc);
9765 #endif
9766 buf->b_p_ff = vim_strsave(p_ff);
9767 #if defined(FEAT_QUICKFIX)
9768 buf->b_p_bh = empty_option;
9769 buf->b_p_bt = empty_option;
9770 #endif
9772 else
9773 free_buf_options(buf, FALSE);
9775 buf->b_p_ai = p_ai;
9776 buf->b_p_ai_nopaste = p_ai_nopaste;
9777 buf->b_p_sw = p_sw;
9778 buf->b_p_tw = p_tw;
9779 buf->b_p_tw_nopaste = p_tw_nopaste;
9780 buf->b_p_tw_nobin = p_tw_nobin;
9781 buf->b_p_wm = p_wm;
9782 buf->b_p_wm_nopaste = p_wm_nopaste;
9783 buf->b_p_wm_nobin = p_wm_nobin;
9784 buf->b_p_bin = p_bin;
9785 #ifdef FEAT_MBYTE
9786 buf->b_p_bomb = p_bomb;
9787 #endif
9788 buf->b_p_et = p_et;
9789 buf->b_p_et_nobin = p_et_nobin;
9790 buf->b_p_ml = p_ml;
9791 buf->b_p_ml_nobin = p_ml_nobin;
9792 buf->b_p_inf = p_inf;
9793 buf->b_p_swf = p_swf;
9794 #ifdef FEAT_INS_EXPAND
9795 buf->b_p_cpt = vim_strsave(p_cpt);
9796 #endif
9797 #ifdef FEAT_COMPL_FUNC
9798 buf->b_p_cfu = vim_strsave(p_cfu);
9799 buf->b_p_ofu = vim_strsave(p_ofu);
9800 #endif
9801 buf->b_p_sts = p_sts;
9802 buf->b_p_sts_nopaste = p_sts_nopaste;
9803 #ifdef FEAT_VARTABS
9804 buf->b_p_vsts = vim_strsave(p_vsts);
9805 if (p_vsts && p_vsts != empty_option)
9806 tabstop_set(p_vsts, &buf->b_p_vsts_ary);
9807 else
9808 buf->b_p_vsts_ary = 0;
9809 buf->b_p_vsts_nopaste = p_vsts_nopaste
9810 ? vim_strsave(p_vsts_nopaste) : NULL;
9811 #endif
9812 #ifndef SHORT_FNAME
9813 buf->b_p_sn = p_sn;
9814 #endif
9815 #ifdef FEAT_COMMENTS
9816 buf->b_p_com = vim_strsave(p_com);
9817 #endif
9818 #ifdef FEAT_FOLDING
9819 buf->b_p_cms = vim_strsave(p_cms);
9820 #endif
9821 buf->b_p_fo = vim_strsave(p_fo);
9822 buf->b_p_flp = vim_strsave(p_flp);
9823 buf->b_p_nf = vim_strsave(p_nf);
9824 buf->b_p_mps = vim_strsave(p_mps);
9825 #ifdef FEAT_SMARTINDENT
9826 buf->b_p_si = p_si;
9827 #endif
9828 buf->b_p_ci = p_ci;
9829 #ifdef FEAT_CINDENT
9830 buf->b_p_cin = p_cin;
9831 buf->b_p_cink = vim_strsave(p_cink);
9832 buf->b_p_cino = vim_strsave(p_cino);
9833 #endif
9834 #ifdef FEAT_AUTOCMD
9835 /* Don't copy 'filetype', it must be detected */
9836 buf->b_p_ft = empty_option;
9837 #endif
9838 #ifdef FEAT_OSFILETYPE
9839 buf->b_p_oft = vim_strsave(p_oft);
9840 #endif
9841 buf->b_p_pi = p_pi;
9842 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9843 buf->b_p_cinw = vim_strsave(p_cinw);
9844 #endif
9845 #ifdef FEAT_LISP
9846 buf->b_p_lisp = p_lisp;
9847 #endif
9848 #ifdef FEAT_SYN_HL
9849 /* Don't copy 'syntax', it must be set */
9850 buf->b_p_syn = empty_option;
9851 buf->b_p_smc = p_smc;
9852 #endif
9853 #ifdef FEAT_SPELL
9854 buf->b_p_spc = vim_strsave(p_spc);
9855 (void)compile_cap_prog(buf);
9856 buf->b_p_spf = vim_strsave(p_spf);
9857 buf->b_p_spl = vim_strsave(p_spl);
9858 #endif
9859 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9860 buf->b_p_inde = vim_strsave(p_inde);
9861 buf->b_p_indk = vim_strsave(p_indk);
9862 #endif
9863 #if defined(FEAT_EVAL)
9864 buf->b_p_fex = vim_strsave(p_fex);
9865 #endif
9866 #ifdef FEAT_CRYPT
9867 buf->b_p_key = vim_strsave(p_key);
9868 #endif
9869 #ifdef FEAT_SEARCHPATH
9870 buf->b_p_sua = vim_strsave(p_sua);
9871 #endif
9872 #ifdef FEAT_KEYMAP
9873 buf->b_p_keymap = vim_strsave(p_keymap);
9874 buf->b_kmap_state |= KEYMAP_INIT;
9875 #endif
9876 /* This isn't really an option, but copying the langmap and IME
9877 * state from the current buffer is better than resetting it. */
9878 buf->b_p_iminsert = p_iminsert;
9879 buf->b_p_imsearch = p_imsearch;
9881 /* options that are normally global but also have a local value
9882 * are not copied, start using the global value */
9883 buf->b_p_ar = -1;
9884 #ifdef FEAT_QUICKFIX
9885 buf->b_p_gp = empty_option;
9886 buf->b_p_mp = empty_option;
9887 buf->b_p_efm = empty_option;
9888 #endif
9889 buf->b_p_ep = empty_option;
9890 buf->b_p_kp = empty_option;
9891 buf->b_p_path = empty_option;
9892 buf->b_p_tags = empty_option;
9893 #ifdef FEAT_FIND_ID
9894 buf->b_p_def = empty_option;
9895 buf->b_p_inc = empty_option;
9896 # ifdef FEAT_EVAL
9897 buf->b_p_inex = vim_strsave(p_inex);
9898 # endif
9899 #endif
9900 #ifdef FEAT_INS_EXPAND
9901 buf->b_p_dict = empty_option;
9902 buf->b_p_tsr = empty_option;
9903 #endif
9904 #ifdef FEAT_TEXTOBJ
9905 buf->b_p_qe = vim_strsave(p_qe);
9906 #endif
9907 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9908 buf->b_p_bexpr = empty_option;
9909 #endif
9910 #ifdef FEAT_PERSISTENT_UNDO
9911 buf->b_p_udf = p_udf;
9912 #endif
9915 * Don't copy the options set by ex_help(), use the saved values,
9916 * when going from a help buffer to a non-help buffer.
9917 * Don't touch these at all when BCO_NOHELP is used and going from
9918 * or to a help buffer.
9920 if (dont_do_help)
9922 buf->b_p_isk = save_p_isk;
9923 #ifdef FEAT_VARTABS
9924 if (p_vts && p_vts != empty_option && !buf->b_p_vts_ary)
9925 tabstop_set(p_vts, &buf->b_p_vts_ary);
9926 else
9927 buf->b_p_vts_ary = 0;
9928 #endif
9930 else
9932 buf->b_p_isk = vim_strsave(p_isk);
9933 did_isk = TRUE;
9934 buf->b_p_ts = p_ts;
9935 #ifdef FEAT_VARTABS
9936 buf->b_p_vts = vim_strsave(p_vts);
9937 if (p_vts && p_vts != empty_option && !buf->b_p_vts_ary)
9938 tabstop_set(p_vts, &buf->b_p_vts_ary);
9939 else
9940 buf->b_p_vts_ary = 0;
9941 #endif
9942 buf->b_help = FALSE;
9943 #ifdef FEAT_QUICKFIX
9944 if (buf->b_p_bt[0] == 'h')
9945 clear_string_option(&buf->b_p_bt);
9946 #endif
9947 buf->b_p_ma = p_ma;
9952 * When the options should be copied (ignoring BCO_ALWAYS), set the
9953 * flag that indicates that the options have been initialized.
9955 if (should_copy)
9956 buf->b_p_initialized = TRUE;
9959 check_buf_options(buf); /* make sure we don't have NULLs */
9960 if (did_isk)
9961 (void)buf_init_chartab(buf, FALSE);
9965 * Reset the 'modifiable' option and its default value.
9967 void
9968 reset_modifiable()
9970 int opt_idx;
9972 curbuf->b_p_ma = FALSE;
9973 p_ma = FALSE;
9974 opt_idx = findoption((char_u *)"ma");
9975 if (opt_idx >= 0)
9976 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9980 * Set the global value for 'iminsert' to the local value.
9982 void
9983 set_iminsert_global()
9985 p_iminsert = curbuf->b_p_iminsert;
9989 * Set the global value for 'imsearch' to the local value.
9991 void
9992 set_imsearch_global()
9994 p_imsearch = curbuf->b_p_imsearch;
9997 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9998 static int expand_option_idx = -1;
9999 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10000 static int expand_option_flags = 0;
10002 void
10003 set_context_in_set_cmd(xp, arg, opt_flags)
10004 expand_T *xp;
10005 char_u *arg;
10006 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10008 int nextchar;
10009 long_u flags = 0; /* init for GCC */
10010 int opt_idx = 0; /* init for GCC */
10011 char_u *p;
10012 char_u *s;
10013 int is_term_option = FALSE;
10014 int key;
10016 expand_option_flags = opt_flags;
10018 xp->xp_context = EXPAND_SETTINGS;
10019 if (*arg == NUL)
10021 xp->xp_pattern = arg;
10022 return;
10024 p = arg + STRLEN(arg) - 1;
10025 if (*p == ' ' && *(p - 1) != '\\')
10027 xp->xp_pattern = p + 1;
10028 return;
10030 while (p > arg)
10032 s = p;
10033 /* count number of backslashes before ' ' or ',' */
10034 if (*p == ' ' || *p == ',')
10036 while (s > arg && *(s - 1) == '\\')
10037 --s;
10039 /* break at a space with an even number of backslashes */
10040 if (*p == ' ' && ((p - s) & 1) == 0)
10042 ++p;
10043 break;
10045 --p;
10047 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
10049 xp->xp_context = EXPAND_BOOL_SETTINGS;
10050 p += 2;
10052 if (STRNCMP(p, "inv", 3) == 0)
10054 xp->xp_context = EXPAND_BOOL_SETTINGS;
10055 p += 3;
10057 xp->xp_pattern = arg = p;
10058 if (*arg == '<')
10060 while (*p != '>')
10061 if (*p++ == NUL) /* expand terminal option name */
10062 return;
10063 key = get_special_key_code(arg + 1);
10064 if (key == 0) /* unknown name */
10066 xp->xp_context = EXPAND_NOTHING;
10067 return;
10069 nextchar = *++p;
10070 is_term_option = TRUE;
10071 expand_option_name[2] = KEY2TERMCAP0(key);
10072 expand_option_name[3] = KEY2TERMCAP1(key);
10074 else
10076 if (p[0] == 't' && p[1] == '_')
10078 p += 2;
10079 if (*p != NUL)
10080 ++p;
10081 if (*p == NUL)
10082 return; /* expand option name */
10083 nextchar = *++p;
10084 is_term_option = TRUE;
10085 expand_option_name[2] = p[-2];
10086 expand_option_name[3] = p[-1];
10088 else
10090 /* Allow * wildcard */
10091 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10092 p++;
10093 if (*p == NUL)
10094 return;
10095 nextchar = *p;
10096 *p = NUL;
10097 opt_idx = findoption(arg);
10098 *p = nextchar;
10099 if (opt_idx == -1 || options[opt_idx].var == NULL)
10101 xp->xp_context = EXPAND_NOTHING;
10102 return;
10104 flags = options[opt_idx].flags;
10105 if (flags & P_BOOL)
10107 xp->xp_context = EXPAND_NOTHING;
10108 return;
10112 /* handle "-=" and "+=" */
10113 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10115 ++p;
10116 nextchar = '=';
10118 if ((nextchar != '=' && nextchar != ':')
10119 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10121 xp->xp_context = EXPAND_UNSUCCESSFUL;
10122 return;
10124 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10126 xp->xp_context = EXPAND_OLD_SETTING;
10127 if (is_term_option)
10128 expand_option_idx = -1;
10129 else
10130 expand_option_idx = opt_idx;
10131 xp->xp_pattern = p + 1;
10132 return;
10134 xp->xp_context = EXPAND_NOTHING;
10135 if (is_term_option || (flags & P_NUM))
10136 return;
10138 xp->xp_pattern = p + 1;
10140 if (flags & P_EXPAND)
10142 p = options[opt_idx].var;
10143 if (p == (char_u *)&p_bdir
10144 || p == (char_u *)&p_dir
10145 || p == (char_u *)&p_path
10146 || p == (char_u *)&p_rtp
10147 #ifdef FEAT_SEARCHPATH
10148 || p == (char_u *)&p_cdpath
10149 #endif
10150 #ifdef FEAT_SESSION
10151 || p == (char_u *)&p_vdir
10152 #endif
10155 xp->xp_context = EXPAND_DIRECTORIES;
10156 if (p == (char_u *)&p_path
10157 #ifdef FEAT_SEARCHPATH
10158 || p == (char_u *)&p_cdpath
10159 #endif
10161 xp->xp_backslash = XP_BS_THREE;
10162 else
10163 xp->xp_backslash = XP_BS_ONE;
10165 else
10167 xp->xp_context = EXPAND_FILES;
10168 /* for 'tags' need three backslashes for a space */
10169 if (p == (char_u *)&p_tags)
10170 xp->xp_backslash = XP_BS_THREE;
10171 else
10172 xp->xp_backslash = XP_BS_ONE;
10176 /* For an option that is a list of file names, find the start of the
10177 * last file name. */
10178 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10180 /* count number of backslashes before ' ' or ',' */
10181 if (*p == ' ' || *p == ',')
10183 s = p;
10184 while (s > xp->xp_pattern && *(s - 1) == '\\')
10185 --s;
10186 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10187 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10189 xp->xp_pattern = p + 1;
10190 break;
10194 #ifdef FEAT_SPELL
10195 /* for 'spellsuggest' start at "file:" */
10196 if (options[opt_idx].var == (char_u *)&p_sps
10197 && STRNCMP(p, "file:", 5) == 0)
10199 xp->xp_pattern = p + 5;
10200 break;
10202 #endif
10205 return;
10209 ExpandSettings(xp, regmatch, num_file, file)
10210 expand_T *xp;
10211 regmatch_T *regmatch;
10212 int *num_file;
10213 char_u ***file;
10215 int num_normal = 0; /* Nr of matching non-term-code settings */
10216 int num_term = 0; /* Nr of matching terminal code settings */
10217 int opt_idx;
10218 int match;
10219 int count = 0;
10220 char_u *str;
10221 int loop;
10222 int is_term_opt;
10223 char_u name_buf[MAX_KEY_NAME_LEN];
10224 static char *(names[]) = {"all", "termcap"};
10225 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10227 /* do this loop twice:
10228 * loop == 0: count the number of matching options
10229 * loop == 1: copy the matching options into allocated memory
10231 for (loop = 0; loop <= 1; ++loop)
10233 regmatch->rm_ic = ic;
10234 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10236 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10237 ++match)
10238 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10240 if (loop == 0)
10241 num_normal++;
10242 else
10243 (*file)[count++] = vim_strsave((char_u *)names[match]);
10246 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10247 opt_idx++)
10249 if (options[opt_idx].var == NULL)
10250 continue;
10251 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10252 && !(options[opt_idx].flags & P_BOOL))
10253 continue;
10254 is_term_opt = istermoption(&options[opt_idx]);
10255 if (is_term_opt && num_normal > 0)
10256 continue;
10257 match = FALSE;
10258 if (vim_regexec(regmatch, str, (colnr_T)0)
10259 || (options[opt_idx].shortname != NULL
10260 && vim_regexec(regmatch,
10261 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10262 match = TRUE;
10263 else if (is_term_opt)
10265 name_buf[0] = '<';
10266 name_buf[1] = 't';
10267 name_buf[2] = '_';
10268 name_buf[3] = str[2];
10269 name_buf[4] = str[3];
10270 name_buf[5] = '>';
10271 name_buf[6] = NUL;
10272 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10274 match = TRUE;
10275 str = name_buf;
10278 if (match)
10280 if (loop == 0)
10282 if (is_term_opt)
10283 num_term++;
10284 else
10285 num_normal++;
10287 else
10288 (*file)[count++] = vim_strsave(str);
10292 * Check terminal key codes, these are not in the option table
10294 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10296 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10298 if (!isprint(str[0]) || !isprint(str[1]))
10299 continue;
10301 name_buf[0] = 't';
10302 name_buf[1] = '_';
10303 name_buf[2] = str[0];
10304 name_buf[3] = str[1];
10305 name_buf[4] = NUL;
10307 match = FALSE;
10308 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10309 match = TRUE;
10310 else
10312 name_buf[0] = '<';
10313 name_buf[1] = 't';
10314 name_buf[2] = '_';
10315 name_buf[3] = str[0];
10316 name_buf[4] = str[1];
10317 name_buf[5] = '>';
10318 name_buf[6] = NUL;
10320 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10321 match = TRUE;
10323 if (match)
10325 if (loop == 0)
10326 num_term++;
10327 else
10328 (*file)[count++] = vim_strsave(name_buf);
10333 * Check special key names.
10335 regmatch->rm_ic = TRUE; /* ignore case here */
10336 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10338 name_buf[0] = '<';
10339 STRCPY(name_buf + 1, str);
10340 STRCAT(name_buf, ">");
10342 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10344 if (loop == 0)
10345 num_term++;
10346 else
10347 (*file)[count++] = vim_strsave(name_buf);
10351 if (loop == 0)
10353 if (num_normal > 0)
10354 *num_file = num_normal;
10355 else if (num_term > 0)
10356 *num_file = num_term;
10357 else
10358 return OK;
10359 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10360 if (*file == NULL)
10362 *file = (char_u **)"";
10363 return FAIL;
10367 return OK;
10371 ExpandOldSetting(num_file, file)
10372 int *num_file;
10373 char_u ***file;
10375 char_u *var = NULL; /* init for GCC */
10376 char_u *buf;
10378 *num_file = 0;
10379 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10380 if (*file == NULL)
10381 return FAIL;
10384 * For a terminal key code expand_option_idx is < 0.
10386 if (expand_option_idx < 0)
10388 var = find_termcode(expand_option_name + 2);
10389 if (var == NULL)
10390 expand_option_idx = findoption(expand_option_name);
10393 if (expand_option_idx >= 0)
10395 /* put string of option value in NameBuff */
10396 option_value2string(&options[expand_option_idx], expand_option_flags);
10397 var = NameBuff;
10399 else if (var == NULL)
10400 var = (char_u *)"";
10402 /* A backslash is required before some characters. This is the reverse of
10403 * what happens in do_set(). */
10404 buf = vim_strsave_escaped(var, escape_chars);
10406 if (buf == NULL)
10408 vim_free(*file);
10409 *file = NULL;
10410 return FAIL;
10413 #ifdef BACKSLASH_IN_FILENAME
10414 /* For MS-Windows et al. we don't double backslashes at the start and
10415 * before a file name character. */
10416 for (var = buf; *var != NUL; mb_ptr_adv(var))
10417 if (var[0] == '\\' && var[1] == '\\'
10418 && expand_option_idx >= 0
10419 && (options[expand_option_idx].flags & P_EXPAND)
10420 && vim_isfilec(var[2])
10421 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
10422 STRMOVE(var, var + 1);
10423 #endif
10425 *file[0] = buf;
10426 *num_file = 1;
10427 return OK;
10429 #endif
10432 * Get the value for the numeric or string option *opp in a nice format into
10433 * NameBuff[]. Must not be called with a hidden option!
10435 static void
10436 option_value2string(opp, opt_flags)
10437 struct vimoption *opp;
10438 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10440 char_u *varp;
10442 varp = get_varp_scope(opp, opt_flags);
10444 if (opp->flags & P_NUM)
10446 long wc = 0;
10448 if (wc_use_keyname(varp, &wc))
10449 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10450 else if (wc != 0)
10451 STRCPY(NameBuff, transchar((int)wc));
10452 else
10453 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10455 else /* P_STRING */
10457 varp = *(char_u **)(varp);
10458 if (varp == NULL) /* just in case */
10459 NameBuff[0] = NUL;
10460 #ifdef FEAT_CRYPT
10461 /* don't show the actual value of 'key', only that it's set */
10462 else if (opp->var == (char_u *)&p_key && *varp)
10463 STRCPY(NameBuff, "*****");
10464 #endif
10465 else if (opp->flags & P_EXPAND)
10466 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10467 /* Translate 'pastetoggle' into special key names */
10468 else if ((char_u **)opp->var == &p_pt)
10469 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10470 else
10471 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
10476 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10477 * printed as a keyname.
10478 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10480 static int
10481 wc_use_keyname(varp, wcp)
10482 char_u *varp;
10483 long *wcp;
10485 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10487 *wcp = *(long *)varp;
10488 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10489 return TRUE;
10491 return FALSE;
10494 #ifdef FEAT_LANGMAP
10496 * Any character has an equivalent 'langmap' character. This is used for
10497 * keyboards that have a special language mode that sends characters above
10498 * 128 (although other characters can be translated too). The "to" field is a
10499 * Vim command character. This avoids having to switch the keyboard back to
10500 * ASCII mode when leaving Insert mode.
10502 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10503 * commands.
10504 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10505 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10506 * 256.
10508 # ifdef FEAT_MBYTE
10510 * With multi-byte support use growarray for 'langmap' chars >= 256
10512 typedef struct
10514 int from;
10515 int to;
10516 } langmap_entry_T;
10518 static garray_T langmap_mapga;
10519 static void langmap_set_entry __ARGS((int from, int to));
10522 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10523 * field. If not found insert a new entry at the appropriate location.
10525 static void
10526 langmap_set_entry(from, to)
10527 int from;
10528 int to;
10530 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10531 int a = 0;
10532 int b = langmap_mapga.ga_len;
10534 /* Do a binary search for an existing entry. */
10535 while (a != b)
10537 int i = (a + b) / 2;
10538 int d = entries[i].from - from;
10540 if (d == 0)
10542 entries[i].to = to;
10543 return;
10545 if (d < 0)
10546 a = i + 1;
10547 else
10548 b = i;
10551 if (ga_grow(&langmap_mapga, 1) != OK)
10552 return; /* out of memory */
10554 /* insert new entry at position "a" */
10555 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10556 mch_memmove(entries + 1, entries,
10557 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10558 ++langmap_mapga.ga_len;
10559 entries[0].from = from;
10560 entries[0].to = to;
10564 * Apply 'langmap' to multi-byte character "c" and return the result.
10567 langmap_adjust_mb(c)
10568 int c;
10570 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10571 int a = 0;
10572 int b = langmap_mapga.ga_len;
10574 while (a != b)
10576 int i = (a + b) / 2;
10577 int d = entries[i].from - c;
10579 if (d == 0)
10580 return entries[i].to; /* found matching entry */
10581 if (d < 0)
10582 a = i + 1;
10583 else
10584 b = i;
10586 return c; /* no entry found, return "c" unmodified */
10588 # endif
10590 static void
10591 langmap_init()
10593 int i;
10595 for (i = 0; i < 256; i++)
10596 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10597 # ifdef FEAT_MBYTE
10598 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10599 # endif
10603 * Called when langmap option is set; the language map can be
10604 * changed at any time!
10606 static void
10607 langmap_set()
10609 char_u *p;
10610 char_u *p2;
10611 int from, to;
10613 #ifdef FEAT_MBYTE
10614 ga_clear(&langmap_mapga); /* clear the previous map first */
10615 #endif
10616 langmap_init(); /* back to one-to-one map */
10618 for (p = p_langmap; p[0] != NUL; )
10620 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10621 mb_ptr_adv(p2))
10623 if (p2[0] == '\\' && p2[1] != NUL)
10624 ++p2;
10626 if (p2[0] == ';')
10627 ++p2; /* abcd;ABCD form, p2 points to A */
10628 else
10629 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10630 while (p[0])
10632 if (p[0] == '\\' && p[1] != NUL)
10633 ++p;
10634 #ifdef FEAT_MBYTE
10635 from = (*mb_ptr2char)(p);
10636 #else
10637 from = p[0];
10638 #endif
10639 if (p2 == NULL)
10641 mb_ptr_adv(p);
10642 if (p[0] == '\\')
10643 ++p;
10644 #ifdef FEAT_MBYTE
10645 to = (*mb_ptr2char)(p);
10646 #else
10647 to = p[0];
10648 #endif
10650 else
10652 if (p2[0] == '\\')
10653 ++p2;
10654 #ifdef FEAT_MBYTE
10655 to = (*mb_ptr2char)(p2);
10656 #else
10657 to = p2[0];
10658 #endif
10660 if (to == NUL)
10662 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10663 transchar(from));
10664 return;
10667 #ifdef FEAT_MBYTE
10668 if (from >= 256)
10669 langmap_set_entry(from, to);
10670 else
10671 #endif
10672 langmap_mapchar[from & 255] = to;
10674 /* Advance to next pair */
10675 mb_ptr_adv(p);
10676 if (p2 == NULL)
10678 if (p[0] == ',')
10680 ++p;
10681 break;
10684 else
10686 mb_ptr_adv(p2);
10687 if (*p == ';')
10689 p = p2;
10690 if (p[0] != NUL)
10692 if (p[0] != ',')
10694 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10695 return;
10697 ++p;
10699 break;
10705 #endif
10708 * Return TRUE if format option 'x' is in effect.
10709 * Take care of no formatting when 'paste' is set.
10712 has_format_option(x)
10713 int x;
10715 if (p_paste)
10716 return FALSE;
10717 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10721 * Return TRUE if "x" is present in 'shortmess' option, or
10722 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10725 shortmess(x)
10726 int x;
10728 return ( vim_strchr(p_shm, x) != NULL
10729 || (vim_strchr(p_shm, 'a') != NULL
10730 && vim_strchr((char_u *)SHM_A, x) != NULL));
10734 * paste_option_changed() - Called after p_paste was set or reset.
10736 static void
10737 paste_option_changed()
10739 static int old_p_paste = FALSE;
10740 static int save_sm = 0;
10741 #ifdef FEAT_CMDL_INFO
10742 static int save_ru = 0;
10743 #endif
10744 #ifdef FEAT_RIGHTLEFT
10745 static int save_ri = 0;
10746 static int save_hkmap = 0;
10747 #endif
10748 buf_T *buf;
10750 if (p_paste)
10753 * Paste switched from off to on.
10754 * Save the current values, so they can be restored later.
10756 if (!old_p_paste)
10758 /* save options for each buffer */
10759 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10761 buf->b_p_tw_nopaste = buf->b_p_tw;
10762 buf->b_p_wm_nopaste = buf->b_p_wm;
10763 buf->b_p_sts_nopaste = buf->b_p_sts;
10764 buf->b_p_ai_nopaste = buf->b_p_ai;
10765 #ifdef FEAT_VARTABS
10766 if (buf->b_p_vsts_nopaste)
10767 vim_free(buf->b_p_vsts_nopaste);
10768 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
10769 ? vim_strsave(buf->b_p_vsts) : NULL;
10770 #endif
10773 /* save global options */
10774 save_sm = p_sm;
10775 #ifdef FEAT_CMDL_INFO
10776 save_ru = p_ru;
10777 #endif
10778 #ifdef FEAT_RIGHTLEFT
10779 save_ri = p_ri;
10780 save_hkmap = p_hkmap;
10781 #endif
10782 /* save global values for local buffer options */
10783 p_tw_nopaste = p_tw;
10784 p_wm_nopaste = p_wm;
10785 p_sts_nopaste = p_sts;
10786 p_ai_nopaste = p_ai;
10787 #ifdef FEAT_VARTABS
10788 if (p_vsts_nopaste)
10789 vim_free(p_vsts_nopaste);
10790 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
10791 #endif
10795 * Always set the option values, also when 'paste' is set when it is
10796 * already on.
10798 /* set options for each buffer */
10799 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10801 buf->b_p_tw = 0; /* textwidth is 0 */
10802 buf->b_p_wm = 0; /* wrapmargin is 0 */
10803 buf->b_p_sts = 0; /* softtabstop is 0 */
10804 buf->b_p_ai = 0; /* no auto-indent */
10805 #ifdef FEAT_VARTABS
10806 if (buf->b_p_vsts)
10807 free_string_option(buf->b_p_vsts);
10808 buf->b_p_vsts = empty_option;
10809 if (buf->b_p_vsts_ary)
10810 vim_free(buf->b_p_vsts_ary);
10811 buf->b_p_vsts_ary = 0;
10812 #endif
10815 /* set global options */
10816 p_sm = 0; /* no showmatch */
10817 #ifdef FEAT_CMDL_INFO
10818 # ifdef FEAT_WINDOWS
10819 if (p_ru)
10820 status_redraw_all(); /* redraw to remove the ruler */
10821 # endif
10822 p_ru = 0; /* no ruler */
10823 #endif
10824 #ifdef FEAT_RIGHTLEFT
10825 p_ri = 0; /* no reverse insert */
10826 p_hkmap = 0; /* no Hebrew keyboard */
10827 #endif
10828 /* set global values for local buffer options */
10829 p_tw = 0;
10830 p_wm = 0;
10831 p_sts = 0;
10832 p_ai = 0;
10833 #ifdef FEAT_VARTABS
10834 if (p_vsts)
10835 free_string_option(p_vsts);
10836 p_vsts = empty_option;
10837 #endif
10841 * Paste switched from on to off: Restore saved values.
10843 else if (old_p_paste)
10845 /* restore options for each buffer */
10846 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10848 buf->b_p_tw = buf->b_p_tw_nopaste;
10849 buf->b_p_wm = buf->b_p_wm_nopaste;
10850 buf->b_p_sts = buf->b_p_sts_nopaste;
10851 buf->b_p_ai = buf->b_p_ai_nopaste;
10852 #ifdef FEAT_VARTABS
10853 if (buf->b_p_vsts)
10854 free_string_option(buf->b_p_vsts);
10855 buf->b_p_vsts = buf->b_p_vsts_nopaste
10856 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
10857 if (buf->b_p_vsts_ary)
10858 vim_free(buf->b_p_vsts_ary);
10859 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
10860 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_ary);
10861 else
10862 buf->b_p_vsts_ary = 0;
10863 #endif
10866 /* restore global options */
10867 p_sm = save_sm;
10868 #ifdef FEAT_CMDL_INFO
10869 # ifdef FEAT_WINDOWS
10870 if (p_ru != save_ru)
10871 status_redraw_all(); /* redraw to draw the ruler */
10872 # endif
10873 p_ru = save_ru;
10874 #endif
10875 #ifdef FEAT_RIGHTLEFT
10876 p_ri = save_ri;
10877 p_hkmap = save_hkmap;
10878 #endif
10879 /* set global values for local buffer options */
10880 p_tw = p_tw_nopaste;
10881 p_wm = p_wm_nopaste;
10882 p_sts = p_sts_nopaste;
10883 p_ai = p_ai_nopaste;
10884 #ifdef FEAT_VARTABS
10885 if (p_vsts)
10886 free_string_option(p_vsts);
10887 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
10888 #endif
10891 old_p_paste = p_paste;
10895 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10897 * Reset 'compatible' and set the values for options that didn't get set yet
10898 * to the Vim defaults.
10899 * Don't do this if the 'compatible' option has been set or reset before.
10900 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
10902 void
10903 vimrc_found(fname, envname)
10904 char_u *fname;
10905 char_u *envname;
10907 int opt_idx;
10908 int dofree = FALSE;
10909 char_u *p;
10911 if (!option_was_set((char_u *)"cp"))
10913 p_cp = FALSE;
10914 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10915 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10916 set_option_default(opt_idx, OPT_FREE, FALSE);
10917 didset_options();
10920 if (fname != NULL)
10922 p = vim_getenv(envname, &dofree);
10923 if (p == NULL)
10925 /* Set $MYVIMRC to the first vimrc file found. */
10926 p = FullName_save(fname, FALSE);
10927 if (p != NULL)
10929 vim_setenv(envname, p);
10930 vim_free(p);
10933 else if (dofree)
10934 vim_free(p);
10939 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10941 void
10942 change_compatible(on)
10943 int on;
10945 int opt_idx;
10947 if (p_cp != on)
10949 p_cp = on;
10950 compatible_set();
10952 opt_idx = findoption((char_u *)"cp");
10953 if (opt_idx >= 0)
10954 options[opt_idx].flags |= P_WAS_SET;
10958 * Return TRUE when option "name" has been set.
10961 option_was_set(name)
10962 char_u *name;
10964 int idx;
10966 idx = findoption(name);
10967 if (idx < 0) /* unknown option */
10968 return FALSE;
10969 if (options[idx].flags & P_WAS_SET)
10970 return TRUE;
10971 return FALSE;
10975 * compatible_set() - Called when 'compatible' has been set or unset.
10977 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10978 * flag) to a Vi compatible value.
10979 * When 'compatible' is unset: Set all options that have a different default
10980 * for Vim (without the P_VI_DEF flag) to that default.
10982 static void
10983 compatible_set()
10985 int opt_idx;
10987 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10988 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10989 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10990 set_option_default(opt_idx, OPT_FREE, p_cp);
10991 didset_options();
10994 #ifdef FEAT_LINEBREAK
10996 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10997 /* Borland C++ screws up loop optimisation here (negri) */
10998 #pragma option -O-l
10999 # endif
11002 * fill_breakat_flags() -- called when 'breakat' changes value.
11004 static void
11005 fill_breakat_flags()
11007 char_u *p;
11008 int i;
11010 for (i = 0; i < 256; i++)
11011 breakat_flags[i] = FALSE;
11013 if (p_breakat != NULL)
11014 for (p = p_breakat; *p; p++)
11015 breakat_flags[*p] = TRUE;
11018 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11019 #pragma option -O.l
11020 # endif
11022 #endif
11025 * Check an option that can be a range of string values.
11027 * Return OK for correct value, FAIL otherwise.
11028 * Empty is always OK.
11030 static int
11031 check_opt_strings(val, values, list)
11032 char_u *val;
11033 char **values;
11034 int list; /* when TRUE: accept a list of values */
11036 return opt_strings_flags(val, values, NULL, list);
11040 * Handle an option that can be a range of string values.
11041 * Set a flag in "*flagp" for each string present.
11043 * Return OK for correct value, FAIL otherwise.
11044 * Empty is always OK.
11046 static int
11047 opt_strings_flags(val, values, flagp, list)
11048 char_u *val; /* new value */
11049 char **values; /* array of valid string values */
11050 unsigned *flagp;
11051 int list; /* when TRUE: accept a list of values */
11053 int i;
11054 int len;
11055 unsigned new_flags = 0;
11057 while (*val)
11059 for (i = 0; ; ++i)
11061 if (values[i] == NULL) /* val not found in values[] */
11062 return FAIL;
11064 len = (int)STRLEN(values[i]);
11065 if (STRNCMP(values[i], val, len) == 0
11066 && ((list && val[len] == ',') || val[len] == NUL))
11068 val += len + (val[len] == ',');
11069 new_flags |= (1 << i);
11070 break; /* check next item in val list */
11074 if (flagp != NULL)
11075 *flagp = new_flags;
11077 return OK;
11081 * Read the 'wildmode' option, fill wim_flags[].
11083 static int
11084 check_opt_wim()
11086 char_u new_wim_flags[4];
11087 char_u *p;
11088 int i;
11089 int idx = 0;
11091 for (i = 0; i < 4; ++i)
11092 new_wim_flags[i] = 0;
11094 for (p = p_wim; *p; ++p)
11096 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11098 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11099 return FAIL;
11100 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11101 new_wim_flags[idx] |= WIM_LONGEST;
11102 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11103 new_wim_flags[idx] |= WIM_FULL;
11104 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11105 new_wim_flags[idx] |= WIM_LIST;
11106 else
11107 return FAIL;
11108 p += i;
11109 if (*p == NUL)
11110 break;
11111 if (*p == ',')
11113 if (idx == 3)
11114 return FAIL;
11115 ++idx;
11119 /* fill remaining entries with last flag */
11120 while (idx < 3)
11122 new_wim_flags[idx + 1] = new_wim_flags[idx];
11123 ++idx;
11126 /* only when there are no errors, wim_flags[] is changed */
11127 for (i = 0; i < 4; ++i)
11128 wim_flags[i] = new_wim_flags[i];
11129 return OK;
11133 * Check if backspacing over something is allowed.
11136 can_bs(what)
11137 int what; /* BS_INDENT, BS_EOL or BS_START */
11139 switch (*p_bs)
11141 case '2': return TRUE;
11142 case '1': return (what != BS_START);
11143 case '0': return FALSE;
11145 return vim_strchr(p_bs, what) != NULL;
11149 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11150 * the file must be considered changed when the value is different.
11152 void
11153 save_file_ff(buf)
11154 buf_T *buf;
11156 buf->b_start_ffc = *buf->b_p_ff;
11157 buf->b_start_eol = buf->b_p_eol;
11158 #ifdef FEAT_MBYTE
11159 buf->b_start_bomb = buf->b_p_bomb;
11161 /* Only use free/alloc when necessary, they take time. */
11162 if (buf->b_start_fenc == NULL
11163 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11165 vim_free(buf->b_start_fenc);
11166 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11168 #endif
11172 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11173 * from when editing started (save_file_ff() called).
11174 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11175 * changed and 'binary' is not set.
11176 * Don't consider a new, empty buffer to be changed.
11179 file_ff_differs(buf)
11180 buf_T *buf;
11182 /* In a buffer that was never loaded the options are not valid. */
11183 if (buf->b_flags & BF_NEVERLOADED)
11184 return FALSE;
11185 if ((buf->b_flags & BF_NEW)
11186 && buf->b_ml.ml_line_count == 1
11187 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11188 return FALSE;
11189 if (buf->b_start_ffc != *buf->b_p_ff)
11190 return TRUE;
11191 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11192 return TRUE;
11193 #ifdef FEAT_MBYTE
11194 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11195 return TRUE;
11196 if (buf->b_start_fenc == NULL)
11197 return (*buf->b_p_fenc != NUL);
11198 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11199 #else
11200 return FALSE;
11201 #endif
11205 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11208 check_ff_value(p)
11209 char_u *p;
11211 return check_opt_strings(p, p_ff_values, FALSE);
11214 #ifdef FEAT_VARTABS
11217 * Set the integer values corresponding to the string setting of 'vartabstop'.
11220 tabstop_set(var, array)
11221 char_u *var;
11222 int **array;
11224 int valcount = 1;
11225 int t;
11226 char_u *cp;
11228 if ((!var[0] || (var[0] == '0' && !var[1])))
11230 *array = (int *)0;
11231 return TRUE;
11234 for (cp = var; *cp; ++cp)
11236 if (cp == var || *(cp - 1) == ',')
11237 if (atoi((char *)cp) <= 0)
11238 return FALSE;
11240 if (VIM_ISDIGIT(*cp))
11241 continue;
11242 if (*cp == ',' && cp > var && *(cp - 1) != ',')
11244 ++valcount;
11245 continue;
11247 return FALSE;
11250 *array = (int *) alloc((unsigned) ((valcount + 1) * sizeof(int)));
11251 (*array)[0] = valcount;
11253 t = 1;
11254 for (cp = var; *cp;)
11256 (*array)[t++] = atoi((char *)cp);
11257 while (*cp && *cp != ',')
11258 ++cp;
11259 if (*cp)
11260 ++cp;
11263 return TRUE;
11267 * Calculate the number of screen spaces a tab will occupy.
11268 * If vts is set then the tab widths are taken from that array,
11269 * otherwise the value of ts is used.
11272 tabstop_padding(col, ts, vts)
11273 colnr_T col;
11274 int ts;
11275 int *vts;
11277 int tabcount;
11278 colnr_T tabcol = 0;
11279 int t;
11280 int padding = 0;
11282 if (ts == 0)
11283 ts = 8;
11284 if (vts == 0 || vts[0] == 0)
11285 return ts - (col % ts);
11287 tabcount = vts[0];
11289 for (t = 1; t <= tabcount; ++t)
11291 tabcol += vts[t];
11292 if (tabcol > col)
11294 padding = (int)(tabcol - col);
11295 break;
11298 if (t > tabcount)
11299 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
11301 return padding;
11305 * Find the size of the tab that covers a particular column.
11308 tabstop_at(col, ts, vts)
11309 colnr_T col;
11310 int ts;
11311 int *vts;
11313 int tabcount;
11314 colnr_T tabcol = 0;
11315 int t;
11316 int tab_size = 0;
11318 if (vts == 0 || vts[0] == 0)
11319 return ts;
11321 tabcount = vts[0];
11322 for (t = 1; t <= tabcount; ++t)
11324 tabcol += vts[t];
11325 if (tabcol > col)
11327 tab_size = vts[t];
11328 break;
11331 if (t > tabcount)
11332 tab_size = vts[tabcount];
11334 return tab_size;
11338 * Find the column on which a tab starts.
11340 colnr_T
11341 tabstop_start(col, ts, vts)
11342 colnr_T col;
11343 int ts;
11344 int *vts;
11346 int tabcount;
11347 colnr_T tabcol = 0;
11348 int t;
11350 if (vts == 0 || vts[0] == 0)
11351 return (col / ts) * ts;
11353 tabcount = vts[0];
11354 for (t = 1; t <= tabcount; ++t)
11356 tabcol += vts[t];
11357 if (tabcol > col)
11358 return tabcol - vts[t];
11361 int excess = tabcol % vts[tabcount];
11362 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
11366 * Find the number of tabs and spaces necessary to get from one column
11367 * to another.
11369 void
11370 tabstop_fromto(start_col, end_col, ts, vts, ntabs, nspcs)
11371 colnr_T start_col;
11372 colnr_T end_col;
11373 int ts;
11374 int *vts;
11375 int *ntabs;
11376 int *nspcs;
11378 int spaces = end_col - start_col;
11379 colnr_T tabcol = 0;
11380 int padding = 0;
11381 int tabcount;
11382 int t;
11384 if (vts == 0 || vts[0] == 0)
11386 int tabs = 0;
11387 int initspc = ts - (start_col % ts);
11388 if (spaces >= initspc)
11390 spaces -= initspc;
11391 tabs++;
11393 tabs += spaces / ts;
11394 spaces -= (spaces / ts) * ts;
11396 *ntabs = tabs;
11397 *nspcs = spaces;
11398 return;
11401 /* Find the padding needed to reach the next tabstop. */
11402 tabcount = vts[0];
11403 for (t = 1; t <= tabcount; ++t)
11405 tabcol += vts[t];
11406 if (tabcol > start_col)
11408 padding = (int)(tabcol - start_col);
11409 break;
11412 if (t > tabcount)
11413 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
11415 /* If the space needed is less than the padding no tabs can be used. */
11416 if (spaces < padding)
11418 *ntabs = 0;
11419 *nspcs = spaces;
11420 return;
11423 *ntabs = 1;
11424 spaces -= padding;
11426 /* At least one tab has been used. See if any more will fit. */
11427 while (spaces != 0 && ++t <= tabcount)
11429 padding = vts[t];
11430 if (spaces < padding)
11432 *nspcs = spaces;
11433 return;
11435 ++*ntabs;
11436 spaces -= padding;
11439 *ntabs += spaces / vts[tabcount];
11440 *nspcs = spaces % vts[tabcount];
11444 * See if two tabstop arrays contain the same values.
11447 tabstop_eq(ts1, ts2)
11448 int *ts1;
11449 int *ts2;
11451 int t;
11453 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
11454 return FALSE;
11455 if (ts1 == ts2)
11456 return TRUE;
11457 if (ts1[0] != ts2[0])
11458 return FALSE;
11460 for (t = 1; t <= ts1[0]; ++t)
11461 if (ts1[t] != ts2[t])
11462 return FALSE;
11464 return TRUE;
11468 * Copy a tabstop array, allocating space for the new array.
11470 int *
11471 tabstop_copy(oldts)
11472 int *oldts;
11474 int *newts;
11475 int t;
11477 if (oldts == 0)
11478 return 0;
11480 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
11481 for (t = 0; t <= oldts[0]; ++t)
11482 newts[t] = oldts[t];
11484 return newts;
11488 * Return a count of the number of tabstops.
11491 tabstop_count(ts)
11492 int *ts;
11494 return ts ? ts[0] : 0;
11498 * Return the first tabstop, or 8 if there are no tabstops defined.
11501 tabstop_first(ts)
11502 int *ts;
11504 return ts ? ts[1] : 8;
11507 #endif