Add handling IM state
[MacVim/KaoriYa.git] / src / option.c
blob75ea1628c80379629c169083490c6dadc12b942e
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 #ifdef USE_MIGEMO
139 # define PV_MIG OPT_BUF(BV_MIG)
140 #endif
141 #define PV_ML OPT_BUF(BV_ML)
142 #define PV_MOD OPT_BUF(BV_MOD)
143 #define PV_MPS OPT_BUF(BV_MPS)
144 #ifdef FEAT_GUI_MACVIM
145 #define PV_MMTA OPT_BUF(BV_MMTA)
146 #endif
147 #define PV_NF OPT_BUF(BV_NF)
148 #ifdef FEAT_OSFILETYPE
149 # define PV_OFT OPT_BUF(BV_OFT)
150 #endif
151 #ifdef FEAT_COMPL_FUNC
152 # define PV_OFU OPT_BUF(BV_OFU)
153 #endif
154 #define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
155 #define PV_PI OPT_BUF(BV_PI)
156 #ifdef FEAT_TEXTOBJ
157 # define PV_QE OPT_BUF(BV_QE)
158 #endif
159 #define PV_RO OPT_BUF(BV_RO)
160 #ifdef FEAT_SMARTINDENT
161 # define PV_SI OPT_BUF(BV_SI)
162 #endif
163 #ifndef SHORT_FNAME
164 # define PV_SN OPT_BUF(BV_SN)
165 #endif
166 #ifdef FEAT_SYN_HL
167 # define PV_SMC OPT_BUF(BV_SMC)
168 # define PV_SYN OPT_BUF(BV_SYN)
169 #endif
170 #ifdef FEAT_SPELL
171 # define PV_SPC OPT_BUF(BV_SPC)
172 # define PV_SPF OPT_BUF(BV_SPF)
173 # define PV_SPL OPT_BUF(BV_SPL)
174 #endif
175 #define PV_STS OPT_BUF(BV_STS)
176 #ifdef FEAT_SEARCHPATH
177 # define PV_SUA OPT_BUF(BV_SUA)
178 #endif
179 #define PV_SW OPT_BUF(BV_SW)
180 #define PV_SWF OPT_BUF(BV_SWF)
181 #define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
182 #define PV_TS OPT_BUF(BV_TS)
183 #define PV_TW OPT_BUF(BV_TW)
184 #define PV_TX OPT_BUF(BV_TX)
185 #define PV_WM OPT_BUF(BV_WM)
188 * Definition of the PV_ values for window-local options.
189 * The WV_ values are defined in option.h.
191 #define PV_LIST OPT_WIN(WV_LIST)
192 #ifdef FEAT_ARABIC
193 # define PV_ARAB OPT_WIN(WV_ARAB)
194 #endif
195 #ifdef FEAT_DIFF
196 # define PV_DIFF OPT_WIN(WV_DIFF)
197 #endif
198 #ifdef FEAT_FOLDING
199 # define PV_FDC OPT_WIN(WV_FDC)
200 # define PV_FEN OPT_WIN(WV_FEN)
201 # define PV_FDI OPT_WIN(WV_FDI)
202 # define PV_FDL OPT_WIN(WV_FDL)
203 # define PV_FDM OPT_WIN(WV_FDM)
204 # define PV_FML OPT_WIN(WV_FML)
205 # define PV_FDN OPT_WIN(WV_FDN)
206 # ifdef FEAT_EVAL
207 # define PV_FDE OPT_WIN(WV_FDE)
208 # define PV_FDT OPT_WIN(WV_FDT)
209 # endif
210 # define PV_FMR OPT_WIN(WV_FMR)
211 #endif
212 #ifdef FEAT_LINEBREAK
213 # define PV_LBR OPT_WIN(WV_LBR)
214 #endif
215 #define PV_NU OPT_WIN(WV_NU)
216 #ifdef FEAT_LINEBREAK
217 # define PV_NUW OPT_WIN(WV_NUW)
218 #endif
219 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
220 # define PV_PVW OPT_WIN(WV_PVW)
221 #endif
222 #ifdef FEAT_RIGHTLEFT
223 # define PV_RL OPT_WIN(WV_RL)
224 # define PV_RLC OPT_WIN(WV_RLC)
225 #endif
226 #ifdef FEAT_SCROLLBIND
227 # define PV_SCBIND OPT_WIN(WV_SCBIND)
228 #endif
229 #define PV_SCROLL OPT_WIN(WV_SCROLL)
230 #ifdef FEAT_SPELL
231 # define PV_SPELL OPT_WIN(WV_SPELL)
232 #endif
233 #ifdef FEAT_SYN_HL
234 # define PV_CUC OPT_WIN(WV_CUC)
235 # define PV_CUL OPT_WIN(WV_CUL)
236 #endif
237 #ifdef FEAT_STL_OPT
238 # define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
239 #endif
240 #ifdef FEAT_WINDOWS
241 # define PV_WFH OPT_WIN(WV_WFH)
242 #endif
243 #ifdef FEAT_VERTSPLIT
244 # define PV_WFW OPT_WIN(WV_WFW)
245 #endif
246 #define PV_WRAP OPT_WIN(WV_WRAP)
249 /* WV_ and BV_ values get typecasted to this for the "indir" field */
250 typedef enum
252 PV_NONE = 0,
253 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
254 } idopt_T;
257 * Options local to a window have a value local to a buffer and global to all
258 * buffers. Indicate this by setting "var" to VAR_WIN.
260 #define VAR_WIN ((char_u *)-1)
263 * These are the global values for options which are also local to a buffer.
264 * Only to be used in option.c!
266 static int p_ai;
267 static int p_bin;
268 #ifdef FEAT_MBYTE
269 static int p_bomb;
270 #endif
271 #if defined(FEAT_QUICKFIX)
272 static char_u *p_bh;
273 static char_u *p_bt;
274 #endif
275 static int p_bl;
276 static int p_ci;
277 #ifdef FEAT_CINDENT
278 static int p_cin;
279 static char_u *p_cink;
280 static char_u *p_cino;
281 #endif
282 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
283 static char_u *p_cinw;
284 #endif
285 #ifdef FEAT_COMMENTS
286 static char_u *p_com;
287 #endif
288 #ifdef FEAT_FOLDING
289 static char_u *p_cms;
290 #endif
291 #ifdef FEAT_INS_EXPAND
292 static char_u *p_cpt;
293 #endif
294 #ifdef FEAT_COMPL_FUNC
295 static char_u *p_cfu;
296 static char_u *p_ofu;
297 #endif
298 static int p_eol;
299 static int p_et;
300 #ifdef FEAT_MBYTE
301 static char_u *p_fenc;
302 #endif
303 static char_u *p_ff;
304 static char_u *p_fo;
305 static char_u *p_flp;
306 #ifdef FEAT_AUTOCMD
307 static char_u *p_ft;
308 #endif
309 static long p_iminsert;
310 static long p_imsearch;
311 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
312 static char_u *p_inex;
313 #endif
314 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
315 static char_u *p_inde;
316 static char_u *p_indk;
317 #endif
318 #if defined(FEAT_EVAL)
319 static char_u *p_fex;
320 #endif
321 static int p_inf;
322 static char_u *p_isk;
323 #ifdef FEAT_CRYPT
324 static char_u *p_key;
325 #endif
326 #ifdef FEAT_LISP
327 static int p_lisp;
328 #endif
329 static int p_ml;
330 static int p_ma;
331 #ifdef FEAT_GUI_MACVIM
332 static int p_mmta;
333 #endif
334 static int p_mod;
335 static char_u *p_mps;
336 static char_u *p_nf;
337 #ifdef FEAT_OSFILETYPE
338 static char_u *p_oft;
339 #endif
340 static int p_pi;
341 #ifdef FEAT_TEXTOBJ
342 static char_u *p_qe;
343 #endif
344 static int p_ro;
345 #ifdef FEAT_SMARTINDENT
346 static int p_si;
347 #endif
348 #ifndef SHORT_FNAME
349 static int p_sn;
350 #endif
351 static long p_sts;
352 #if defined(FEAT_SEARCHPATH)
353 static char_u *p_sua;
354 #endif
355 static long p_sw;
356 static int p_swf;
357 #ifdef FEAT_SYN_HL
358 static long p_smc;
359 static char_u *p_syn;
360 #endif
361 #ifdef FEAT_SPELL
362 static char_u *p_spc;
363 static char_u *p_spf;
364 static char_u *p_spl;
365 #endif
366 static long p_ts;
367 static long p_tw;
368 static int p_tx;
369 static long p_wm;
370 #ifdef FEAT_KEYMAP
371 static char_u *p_keymap;
372 #endif
374 /* Saved values for when 'bin' is set. */
375 static int p_et_nobin;
376 static int p_ml_nobin;
377 static long p_tw_nobin;
378 static long p_wm_nobin;
380 /* Saved values for when 'paste' is set */
381 static long p_tw_nopaste;
382 static long p_wm_nopaste;
383 static long p_sts_nopaste;
384 static int p_ai_nopaste;
386 struct vimoption
388 char *fullname; /* full option name */
389 char *shortname; /* permissible abbreviation */
390 long_u flags; /* see below */
391 char_u *var; /* global option: pointer to variable;
392 * window-local option: VAR_WIN;
393 * buffer-local option: global value */
394 idopt_T indir; /* global option: PV_NONE;
395 * local option: indirect option index */
396 char_u *def_val[2]; /* default values for variable (vi and vim) */
397 #ifdef FEAT_EVAL
398 scid_T scriptID; /* script in which the option was last set */
399 #endif
402 #define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
403 #define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
406 * Flags
408 #define P_BOOL 0x01 /* the option is boolean */
409 #define P_NUM 0x02 /* the option is numeric */
410 #define P_STRING 0x04 /* the option is a string */
411 #define P_ALLOCED 0x08 /* the string option is in allocated memory,
412 must use vim_free() when assigning new
413 value. Not set if default is the same. */
414 #define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
415 never be used for local or hidden options! */
416 #define P_NODEFAULT 0x40 /* don't set to default value */
417 #define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
418 use vim_free() when assigning new value */
419 #define P_WAS_SET 0x100 /* option has been set/reset */
420 #define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
421 #define P_VI_DEF 0x400 /* Use Vi default for Vim */
422 #define P_VIM 0x800 /* Vim option, reset when 'cp' set */
424 /* when option changed, what to display: */
425 #define P_RSTAT 0x1000 /* redraw status lines */
426 #define P_RWIN 0x2000 /* redraw current window */
427 #define P_RBUF 0x4000 /* redraw current buffer */
428 #define P_RALL 0x6000 /* redraw all windows */
429 #define P_RCLR 0x7000 /* clear and redraw all */
431 #define P_COMMA 0x8000 /* comma separated list */
432 #define P_NODUP 0x10000L/* don't allow duplicate strings */
433 #define P_FLAGLIST 0x20000L/* list of single-char flags */
435 #define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
436 #define P_GETTEXT 0x80000L/* expand default value with _() */
437 #define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
438 #define P_NFNAME 0x200000L/* only normal file name chars allowed */
439 #define P_INSECURE 0x400000L/* option was set from a modeline */
440 #define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
441 side effects) */
443 #define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
445 /* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
446 * for the currency sign. */
447 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
448 # define ISP_LATIN1 (char_u *)"@,~-255"
449 #else
450 # define ISP_LATIN1 (char_u *)"@,161-255"
451 #endif
453 /* The 16 bit MS-DOS version is low on space, make the string as short as
454 * possible when compiling with few features. */
455 #if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
456 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
457 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL)
458 # 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"
459 #else
460 # 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"
461 #endif
464 * options[] is initialized here.
465 * The order of the options MUST be alphabetic for ":set all" and findoption().
466 * All option names MUST start with a lowercase letter (for findoption()).
467 * Exception: "t_" options are at the end.
468 * The options with a NULL variable are 'hidden': a set command for them is
469 * ignored and they are not printed.
471 static struct vimoption
472 #ifdef FEAT_GUI_W16
473 _far
474 #endif
475 options[] =
477 {"aleph", "al", P_NUM|P_VI_DEF,
478 #ifdef FEAT_RIGHTLEFT
479 (char_u *)&p_aleph, PV_NONE,
480 #else
481 (char_u *)NULL, PV_NONE,
482 #endif
484 #if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
485 (char_u *)128L,
486 #else
487 (char_u *)224L,
488 #endif
489 (char_u *)0L}},
490 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
491 #ifdef FEAT_ANTIALIAS
492 (char_u *)&p_antialias, PV_NONE,
493 #else
494 (char_u *)NULL, PV_NONE,
495 #endif
496 #if FEAT_GUI_MACVIM
497 {(char_u *)TRUE, (char_u *)0L}},
498 #else
499 {(char_u *)FALSE, (char_u *)0L}},
500 #endif
501 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
502 #ifdef FEAT_ARABIC
503 (char_u *)VAR_WIN, PV_ARAB,
504 #else
505 (char_u *)NULL, PV_NONE,
506 #endif
507 {(char_u *)FALSE, (char_u *)0L}},
508 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
509 #ifdef FEAT_ARABIC
510 (char_u *)&p_arshape, PV_NONE,
511 #else
512 (char_u *)NULL, PV_NONE,
513 #endif
514 {(char_u *)TRUE, (char_u *)0L}},
515 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
516 #ifdef FEAT_RIGHTLEFT
517 (char_u *)&p_ari, PV_NONE,
518 #else
519 (char_u *)NULL, PV_NONE,
520 #endif
521 {(char_u *)FALSE, (char_u *)0L}},
522 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
523 #ifdef FEAT_FKMAP
524 (char_u *)&p_altkeymap, PV_NONE,
525 #else
526 (char_u *)NULL, PV_NONE,
527 #endif
528 {(char_u *)FALSE, (char_u *)0L}},
529 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
530 #if defined(FEAT_MBYTE)
531 (char_u *)&p_ambw, PV_NONE,
532 {(char_u *)"single", (char_u *)0L}
533 #else
534 (char_u *)NULL, PV_NONE,
535 {(char_u *)0L, (char_u *)0L}
536 #endif
538 #ifdef FEAT_AUTOCHDIR
539 {"autochdir", "acd", P_BOOL|P_VI_DEF,
540 (char_u *)&p_acd, PV_NONE,
541 {(char_u *)FALSE, (char_u *)0L}},
542 #endif
543 {"autoindent", "ai", P_BOOL|P_VI_DEF,
544 (char_u *)&p_ai, PV_AI,
545 {(char_u *)FALSE, (char_u *)0L}},
546 {"autoprint", "ap", P_BOOL|P_VI_DEF,
547 (char_u *)NULL, PV_NONE,
548 {(char_u *)FALSE, (char_u *)0L}},
549 {"autoread", "ar", P_BOOL|P_VI_DEF,
550 (char_u *)&p_ar, PV_AR,
551 {(char_u *)FALSE, (char_u *)0L}},
552 {"autowrite", "aw", P_BOOL|P_VI_DEF,
553 (char_u *)&p_aw, PV_NONE,
554 {(char_u *)FALSE, (char_u *)0L}},
555 {"autowriteall","awa", P_BOOL|P_VI_DEF,
556 (char_u *)&p_awa, PV_NONE,
557 {(char_u *)FALSE, (char_u *)0L}},
558 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
559 (char_u *)&p_bg, PV_NONE,
561 #if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
562 (char_u *)"dark",
563 #else
564 (char_u *)"light",
565 #endif
566 (char_u *)0L}},
567 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
568 (char_u *)&p_bs, PV_NONE,
569 {(char_u *)"", (char_u *)0L}},
570 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
571 (char_u *)&p_bk, PV_NONE,
572 {(char_u *)FALSE, (char_u *)0L}},
573 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
574 (char_u *)&p_bkc, PV_NONE,
575 #ifdef UNIX
576 {(char_u *)"yes", (char_u *)"auto"}
577 #else
578 {(char_u *)"auto", (char_u *)"auto"}
579 #endif
581 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
582 (char_u *)&p_bdir, PV_NONE,
583 {(char_u *)DFLT_BDIR, (char_u *)0L}},
584 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
585 (char_u *)&p_bex, PV_NONE,
587 #ifdef VMS
588 (char_u *)"_",
589 #else
590 (char_u *)"~",
591 #endif
592 (char_u *)0L}},
593 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
594 #ifdef FEAT_WILDIGN
595 (char_u *)&p_bsk, PV_NONE,
596 {(char_u *)"", (char_u *)0L}
597 #else
598 (char_u *)NULL, PV_NONE,
599 {(char_u *)0L, (char_u *)0L}
600 #endif
602 #ifdef FEAT_BEVAL
603 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
604 (char_u *)&p_bdlay, PV_NONE,
605 {(char_u *)600L, (char_u *)0L}},
606 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
607 (char_u *)&p_beval, PV_NONE,
608 {(char_u *)FALSE, (char_u *)0L}},
609 # ifdef FEAT_EVAL
610 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
611 (char_u *)&p_bexpr, PV_BEXPR,
612 {(char_u *)"", (char_u *)0L}},
613 # endif
614 #endif
615 {"beautify", "bf", P_BOOL|P_VI_DEF,
616 (char_u *)NULL, PV_NONE,
617 {(char_u *)FALSE, (char_u *)0L}},
618 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
619 (char_u *)&p_bin, PV_BIN,
620 {(char_u *)FALSE, (char_u *)0L}},
621 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
622 #ifdef MSDOS
623 (char_u *)&p_biosk, PV_NONE,
624 #else
625 (char_u *)NULL, PV_NONE,
626 #endif
627 {(char_u *)TRUE, (char_u *)0L}},
628 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
629 #ifdef FEAT_MBYTE
630 (char_u *)&p_bomb, PV_BOMB,
631 #else
632 (char_u *)NULL, PV_NONE,
633 #endif
634 {(char_u *)FALSE, (char_u *)0L}},
635 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
636 #ifdef FEAT_LINEBREAK
637 (char_u *)&p_breakat, PV_NONE,
638 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
639 #else
640 (char_u *)NULL, PV_NONE,
641 {(char_u *)0L, (char_u *)0L}
642 #endif
644 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
645 #ifdef FEAT_BROWSE
646 (char_u *)&p_bsdir, PV_NONE,
647 {(char_u *)"last", (char_u *)0L}
648 #else
649 (char_u *)NULL, PV_NONE,
650 {(char_u *)0L, (char_u *)0L}
651 #endif
653 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
654 #if defined(FEAT_QUICKFIX)
655 (char_u *)&p_bh, PV_BH,
656 {(char_u *)"", (char_u *)0L}
657 #else
658 (char_u *)NULL, PV_NONE,
659 {(char_u *)0L, (char_u *)0L}
660 #endif
662 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
663 (char_u *)&p_bl, PV_BL,
664 {(char_u *)1L, (char_u *)0L}
666 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
667 #if defined(FEAT_QUICKFIX)
668 (char_u *)&p_bt, PV_BT,
669 {(char_u *)"", (char_u *)0L}
670 #else
671 (char_u *)NULL, PV_NONE,
672 {(char_u *)0L, (char_u *)0L}
673 #endif
675 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
676 #ifdef FEAT_MBYTE
677 (char_u *)&p_cmp, PV_NONE,
678 {(char_u *)"internal,keepascii", (char_u *)0L}
679 #else
680 (char_u *)NULL, PV_NONE,
681 {(char_u *)0L, (char_u *)0L}
682 #endif
684 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
685 #ifdef FEAT_SEARCHPATH
686 (char_u *)&p_cdpath, PV_NONE,
687 {(char_u *)",,", (char_u *)0L}
688 #else
689 (char_u *)NULL, PV_NONE,
690 {(char_u *)0L, (char_u *)0L}
691 #endif
693 {"cedit", NULL, P_STRING,
694 #ifdef FEAT_CMDWIN
695 (char_u *)&p_cedit, PV_NONE,
696 {(char_u *)"", (char_u *)CTRL_F_STR}
697 #else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)0L, (char_u *)0L}
700 #endif
702 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
703 #if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
704 (char_u *)&p_ccv, PV_NONE,
705 {(char_u *)"", (char_u *)0L}
706 #else
707 (char_u *)NULL, PV_NONE,
708 {(char_u *)0L, (char_u *)0L}
709 #endif
711 {"charspace", "csp", P_NUM|P_NODEFAULT|P_VIM|P_RCLR,
712 #ifdef FEAT_GUI
713 (char_u *)&p_charspace, PV_NONE,
714 #else
715 (char_u *)NULL, PV_NONE,
716 #endif
717 {(char_u *)0L, (char_u *)0L}
719 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
720 #ifdef FEAT_CINDENT
721 (char_u *)&p_cin, PV_CIN,
722 #else
723 (char_u *)NULL, PV_NONE,
724 #endif
725 {(char_u *)FALSE, (char_u *)0L}},
726 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
727 #ifdef FEAT_CINDENT
728 (char_u *)&p_cink, PV_CINK,
729 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
730 #else
731 (char_u *)NULL, PV_NONE,
732 {(char_u *)0L, (char_u *)0L}
733 #endif
735 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
736 #ifdef FEAT_CINDENT
737 (char_u *)&p_cino, PV_CINO,
738 #else
739 (char_u *)NULL, PV_NONE,
740 #endif
741 {(char_u *)"", (char_u *)0L}},
742 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
743 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
744 (char_u *)&p_cinw, PV_CINW,
745 {(char_u *)"if,else,while,do,for,switch",
746 (char_u *)0L}
747 #else
748 (char_u *)NULL, PV_NONE,
749 {(char_u *)0L, (char_u *)0L}
750 #endif
752 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
753 #ifdef FEAT_CLIPBOARD
754 (char_u *)&p_cb, PV_NONE,
755 # ifdef FEAT_XCLIPBOARD
756 {(char_u *)"autoselect,exclude:cons\\|linux",
757 (char_u *)0L}
758 # else
759 {(char_u *)"", (char_u *)0L}
760 # endif
761 #else
762 (char_u *)NULL, PV_NONE,
763 {(char_u *)"", (char_u *)0L}
764 #endif
766 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
767 (char_u *)&p_ch, PV_NONE,
768 {(char_u *)1L, (char_u *)0L}},
769 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
770 #ifdef FEAT_CMDWIN
771 (char_u *)&p_cwh, PV_NONE,
772 #else
773 (char_u *)NULL, PV_NONE,
774 #endif
775 {(char_u *)7L, (char_u *)0L}},
776 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
777 (char_u *)&Columns, PV_NONE,
778 {(char_u *)80L, (char_u *)0L}},
779 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
780 #ifdef FEAT_COMMENTS
781 (char_u *)&p_com, PV_COM,
782 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
783 (char_u *)0L}
784 #else
785 (char_u *)NULL, PV_NONE,
786 {(char_u *)0L, (char_u *)0L}
787 #endif
789 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
790 #ifdef FEAT_FOLDING
791 (char_u *)&p_cms, PV_CMS,
792 {(char_u *)"/*%s*/", (char_u *)0L}
793 #else
794 (char_u *)NULL, PV_NONE,
795 {(char_u *)0L, (char_u *)0L}
796 #endif
798 /* P_PRI_MKRC isn't needed here, optval_default()
799 * always returns TRUE for 'compatible' */
800 {"compatible", "cp", P_BOOL|P_RALL,
801 (char_u *)&p_cp, PV_NONE,
802 {(char_u *)TRUE, (char_u *)FALSE}},
803 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
804 #ifdef FEAT_INS_EXPAND
805 (char_u *)&p_cpt, PV_CPT,
806 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
807 #else
808 (char_u *)NULL, PV_NONE,
809 {(char_u *)0L, (char_u *)0L}
810 #endif
812 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
813 #ifdef FEAT_COMPL_FUNC
814 (char_u *)&p_cfu, PV_CFU,
815 {(char_u *)"", (char_u *)0L}
816 #else
817 (char_u *)NULL, PV_NONE,
818 {(char_u *)0L, (char_u *)0L}
819 #endif
821 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
822 #ifdef FEAT_INS_EXPAND
823 (char_u *)&p_cot, PV_NONE,
824 {(char_u *)"menu,preview", (char_u *)0L}
825 #else
826 (char_u *)NULL, PV_NONE,
827 {(char_u *)0L, (char_u *)0L}
828 #endif
830 {"confirm", "cf", P_BOOL|P_VI_DEF,
831 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
832 (char_u *)&p_confirm, PV_NONE,
833 #else
834 (char_u *)NULL, PV_NONE,
835 #endif
836 {(char_u *)FALSE, (char_u *)0L}},
837 {"conskey", "consk",P_BOOL|P_VI_DEF,
838 #ifdef MSDOS
839 (char_u *)&p_consk, PV_NONE,
840 #else
841 (char_u *)NULL, PV_NONE,
842 #endif
843 {(char_u *)FALSE, (char_u *)0L}},
844 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
845 (char_u *)&p_ci, PV_CI,
846 {(char_u *)FALSE, (char_u *)0L}},
847 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
848 (char_u *)&p_cpo, PV_NONE,
849 {(char_u *)CPO_VI, (char_u *)CPO_VIM}},
850 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
851 #ifdef FEAT_CSCOPE
852 (char_u *)&p_cspc, PV_NONE,
853 #else
854 (char_u *)NULL, PV_NONE,
855 #endif
856 {(char_u *)0L, (char_u *)0L}},
857 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
858 #ifdef FEAT_CSCOPE
859 (char_u *)&p_csprg, PV_NONE,
860 {(char_u *)"cscope", (char_u *)0L}
861 #else
862 (char_u *)NULL, PV_NONE,
863 {(char_u *)0L, (char_u *)0L}
864 #endif
866 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
867 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
868 (char_u *)&p_csqf, PV_NONE,
869 {(char_u *)"", (char_u *)0L}
870 #else
871 (char_u *)NULL, PV_NONE,
872 {(char_u *)0L, (char_u *)0L}
873 #endif
875 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
876 #ifdef FEAT_CSCOPE
877 (char_u *)&p_cst, PV_NONE,
878 #else
879 (char_u *)NULL, PV_NONE,
880 #endif
881 {(char_u *)0L, (char_u *)0L}},
882 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
883 #ifdef FEAT_CSCOPE
884 (char_u *)&p_csto, PV_NONE,
885 #else
886 (char_u *)NULL, PV_NONE,
887 #endif
888 {(char_u *)0L, (char_u *)0L}},
889 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
890 #ifdef FEAT_CSCOPE
891 (char_u *)&p_csverbose, PV_NONE,
892 #else
893 (char_u *)NULL, PV_NONE,
894 #endif
895 {(char_u *)0L, (char_u *)0L}},
896 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
897 #ifdef FEAT_SYN_HL
898 (char_u *)VAR_WIN, PV_CUC,
899 #else
900 (char_u *)NULL, PV_NONE,
901 #endif
902 {(char_u *)FALSE, (char_u *)0L}},
903 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
904 #ifdef FEAT_SYN_HL
905 (char_u *)VAR_WIN, PV_CUL,
906 #else
907 (char_u *)NULL, PV_NONE,
908 #endif
909 {(char_u *)FALSE, (char_u *)0L}},
910 {"debug", NULL, P_STRING|P_VI_DEF,
911 (char_u *)&p_debug, PV_NONE,
912 {(char_u *)"", (char_u *)0L}},
913 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
914 #ifdef FEAT_FIND_ID
915 (char_u *)&p_def, PV_DEF,
916 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
917 #else
918 (char_u *)NULL, PV_NONE,
919 {(char_u *)NULL, (char_u *)0L}
920 #endif
922 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
923 #ifdef FEAT_MBYTE
924 (char_u *)&p_deco, PV_NONE,
925 #else
926 (char_u *)NULL, PV_NONE,
927 #endif
928 {(char_u *)FALSE, (char_u *)0L}},
929 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
930 #ifdef FEAT_INS_EXPAND
931 (char_u *)&p_dict, PV_DICT,
932 #else
933 (char_u *)NULL, PV_NONE,
934 #endif
935 {(char_u *)"", (char_u *)0L}},
936 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
937 #ifdef FEAT_DIFF
938 (char_u *)VAR_WIN, PV_DIFF,
939 #else
940 (char_u *)NULL, PV_NONE,
941 #endif
942 {(char_u *)FALSE, (char_u *)0L}},
943 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
944 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
945 (char_u *)&p_dex, PV_NONE,
946 {(char_u *)"", (char_u *)0L}
947 #else
948 (char_u *)NULL, PV_NONE,
949 {(char_u *)0L, (char_u *)0L}
950 #endif
952 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
953 #ifdef FEAT_DIFF
954 (char_u *)&p_dip, PV_NONE,
955 {(char_u *)"filler", (char_u *)NULL}
956 #else
957 (char_u *)NULL, PV_NONE,
958 {(char_u *)"", (char_u *)NULL}
959 #endif
961 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
962 #ifdef FEAT_DIGRAPHS
963 (char_u *)&p_dg, PV_NONE,
964 #else
965 (char_u *)NULL, PV_NONE,
966 #endif
967 {(char_u *)FALSE, (char_u *)0L}},
968 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
969 (char_u *)&p_dir, PV_NONE,
970 {(char_u *)DFLT_DIR, (char_u *)0L}},
971 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
972 (char_u *)&p_dy, PV_NONE,
973 {(char_u *)"", (char_u *)0L}},
974 {"eadirection", "ead", P_STRING|P_VI_DEF,
975 #ifdef FEAT_VERTSPLIT
976 (char_u *)&p_ead, PV_NONE,
977 {(char_u *)"both", (char_u *)0L}
978 #else
979 (char_u *)NULL, PV_NONE,
980 {(char_u *)NULL, (char_u *)0L}
981 #endif
983 {"edcompatible","ed", P_BOOL|P_VI_DEF,
984 (char_u *)&p_ed, PV_NONE,
985 {(char_u *)FALSE, (char_u *)0L}},
986 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
987 #ifdef FEAT_MBYTE
988 (char_u *)&p_enc, PV_NONE,
989 {(char_u *)ENC_DFLT, (char_u *)0L}
990 #else
991 (char_u *)NULL, PV_NONE,
992 {(char_u *)0L, (char_u *)0L}
993 #endif
995 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
996 (char_u *)&p_eol, PV_EOL,
997 {(char_u *)TRUE, (char_u *)0L}},
998 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
999 (char_u *)&p_ea, PV_NONE,
1000 {(char_u *)TRUE, (char_u *)0L}},
1001 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1002 (char_u *)&p_ep, PV_EP,
1003 {(char_u *)"", (char_u *)0L}},
1004 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1005 (char_u *)&p_eb, PV_NONE,
1006 {(char_u *)FALSE, (char_u *)0L}},
1007 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1008 #ifdef FEAT_QUICKFIX
1009 (char_u *)&p_ef, PV_NONE,
1010 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1011 #else
1012 (char_u *)NULL, PV_NONE,
1013 {(char_u *)NULL, (char_u *)0L}
1014 #endif
1016 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1017 #ifdef FEAT_QUICKFIX
1018 (char_u *)&p_efm, PV_EFM,
1019 {(char_u *)DFLT_EFM, (char_u *)0L},
1020 #else
1021 (char_u *)NULL, PV_NONE,
1022 {(char_u *)NULL, (char_u *)0L}
1023 #endif
1025 {"esckeys", "ek", P_BOOL|P_VIM,
1026 (char_u *)&p_ek, PV_NONE,
1027 {(char_u *)FALSE, (char_u *)TRUE}},
1028 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1029 #ifdef FEAT_AUTOCMD
1030 (char_u *)&p_ei, PV_NONE,
1031 #else
1032 (char_u *)NULL, PV_NONE,
1033 #endif
1034 {(char_u *)"", (char_u *)0L}},
1035 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1036 (char_u *)&p_et, PV_ET,
1037 {(char_u *)FALSE, (char_u *)0L}},
1038 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1039 (char_u *)&p_exrc, PV_NONE,
1040 {(char_u *)FALSE, (char_u *)0L}},
1041 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1042 #ifdef FEAT_MBYTE
1043 (char_u *)&p_fenc, PV_FENC,
1044 {(char_u *)"", (char_u *)0L}
1045 #else
1046 (char_u *)NULL, PV_NONE,
1047 {(char_u *)0L, (char_u *)0L}
1048 #endif
1050 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1051 #ifdef FEAT_MBYTE
1052 (char_u *)&p_fencs, PV_NONE,
1053 {(char_u *)"ucs-bom", (char_u *)0L}
1054 #else
1055 (char_u *)NULL, PV_NONE,
1056 {(char_u *)0L, (char_u *)0L}
1057 #endif
1059 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1060 (char_u *)&p_ff, PV_FF,
1061 {(char_u *)DFLT_FF, (char_u *)0L}},
1062 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1063 (char_u *)&p_ffs, PV_NONE,
1064 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}},
1065 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
1066 #ifdef FEAT_AUTOCMD
1067 (char_u *)&p_ft, PV_FT,
1068 {(char_u *)"", (char_u *)0L}
1069 #else
1070 (char_u *)NULL, PV_NONE,
1071 {(char_u *)0L, (char_u *)0L}
1072 #endif
1074 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1075 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1076 (char_u *)&p_fcs, PV_NONE,
1077 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1078 #else
1079 (char_u *)NULL, PV_NONE,
1080 {(char_u *)"", (char_u *)0L}
1081 #endif
1083 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1084 #ifdef FEAT_FKMAP
1085 (char_u *)&p_fkmap, PV_NONE,
1086 #else
1087 (char_u *)NULL, PV_NONE,
1088 #endif
1089 {(char_u *)FALSE, (char_u *)0L}},
1090 {"flash", "fl", P_BOOL|P_VI_DEF,
1091 (char_u *)NULL, PV_NONE,
1092 {(char_u *)FALSE, (char_u *)0L}},
1093 #ifdef FEAT_FOLDING
1094 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1095 (char_u *)&p_fcl, PV_NONE,
1096 {(char_u *)"", (char_u *)0L}},
1097 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1098 (char_u *)VAR_WIN, PV_FDC,
1099 {(char_u *)FALSE, (char_u *)0L}},
1100 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1101 (char_u *)VAR_WIN, PV_FEN,
1102 {(char_u *)TRUE, (char_u *)0L}},
1103 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1104 # ifdef FEAT_EVAL
1105 (char_u *)VAR_WIN, PV_FDE,
1106 {(char_u *)"0", (char_u *)NULL}
1107 # else
1108 (char_u *)NULL, PV_NONE,
1109 {(char_u *)NULL, (char_u *)0L}
1110 # endif
1112 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1113 (char_u *)VAR_WIN, PV_FDI,
1114 {(char_u *)"#", (char_u *)NULL}},
1115 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1116 (char_u *)VAR_WIN, PV_FDL,
1117 {(char_u *)0L, (char_u *)0L}},
1118 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1119 (char_u *)&p_fdls, PV_NONE,
1120 {(char_u *)-1L, (char_u *)0L}},
1121 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1122 P_RWIN|P_COMMA|P_NODUP,
1123 (char_u *)VAR_WIN, PV_FMR,
1124 {(char_u *)"{{{,}}}", (char_u *)NULL}},
1125 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1126 (char_u *)VAR_WIN, PV_FDM,
1127 {(char_u *)"manual", (char_u *)NULL}},
1128 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1129 (char_u *)VAR_WIN, PV_FML,
1130 {(char_u *)1L, (char_u *)0L}},
1131 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1132 (char_u *)VAR_WIN, PV_FDN,
1133 {(char_u *)20L, (char_u *)0L}},
1134 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1135 (char_u *)&p_fdo, PV_NONE,
1136 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1137 (char_u *)0L}},
1138 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1139 # ifdef FEAT_EVAL
1140 (char_u *)VAR_WIN, PV_FDT,
1141 {(char_u *)"foldtext()", (char_u *)NULL}
1142 # else
1143 (char_u *)NULL, PV_NONE,
1144 {(char_u *)NULL, (char_u *)0L}
1145 # endif
1147 #endif
1148 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1149 #ifdef FEAT_EVAL
1150 (char_u *)&p_fex, PV_FEX,
1151 {(char_u *)"", (char_u *)0L}
1152 #else
1153 (char_u *)NULL, PV_NONE,
1154 {(char_u *)0L, (char_u *)0L}
1155 #endif
1157 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1158 (char_u *)&p_fo, PV_FO,
1159 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
1160 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1161 (char_u *)&p_flp, PV_FLP,
1162 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*", (char_u *)0L}},
1163 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1164 (char_u *)&p_fp, PV_NONE,
1165 {(char_u *)"", (char_u *)0L}},
1166 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1167 #ifdef HAVE_FSYNC
1168 (char_u *)&p_fs, PV_NONE,
1169 {(char_u *)TRUE, (char_u *)0L}
1170 #else
1171 (char_u *)NULL, PV_NONE,
1172 {(char_u *)FALSE, (char_u *)0L}
1173 #endif
1175 {"fullscreen", "fu", P_BOOL|P_NO_MKRC,
1176 #ifdef FEAT_FULLSCREEN
1177 (char_u *)&p_fullscreen, PV_NONE,
1178 #else
1179 (char_u *)NULL, PV_NONE,
1180 #endif
1181 {(char_u *)FALSE, (char_u *)0L}},
1182 {"fuoptions", "fuopt", P_STRING|P_COMMA|P_NODUP|P_VI_DEF,
1183 #ifdef FEAT_FULLSCREEN
1184 (char_u *)&p_fuoptions, PV_NONE,
1185 {(char_u *)"maxvert", (char_u *)0L}},
1186 #else
1187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)NULL, (char_u *)0L}},
1189 #endif
1190 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1191 (char_u *)&p_gd, PV_NONE,
1192 {(char_u *)FALSE, (char_u *)0L}},
1193 {"graphic", "gr", P_BOOL|P_VI_DEF,
1194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)FALSE, (char_u *)0L}},
1196 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1197 #ifdef FEAT_QUICKFIX
1198 (char_u *)&p_gefm, PV_NONE,
1199 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L},
1200 #else
1201 (char_u *)NULL, PV_NONE,
1202 {(char_u *)NULL, (char_u *)0L}
1203 #endif
1205 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1206 #ifdef FEAT_QUICKFIX
1207 (char_u *)&p_gp, PV_GP,
1209 # ifdef WIN3264
1210 /* may be changed to "grep -n" in os_win32.c */
1211 (char_u *)"findstr /n",
1212 # else
1213 # ifdef UNIX
1214 /* Add an extra file name so that grep will always
1215 * insert a file name in the match line. */
1216 (char_u *)"grep -n $* /dev/null",
1217 # else
1218 # ifdef VMS
1219 (char_u *)"SEARCH/NUMBERS ",
1220 # else
1221 (char_u *)"grep -n ",
1222 #endif
1223 #endif
1224 # endif
1225 (char_u *)0L},
1226 #else
1227 (char_u *)NULL, PV_NONE,
1228 {(char_u *)NULL, (char_u *)0L}
1229 #endif
1231 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1232 #ifdef CURSOR_SHAPE
1233 (char_u *)&p_guicursor, PV_NONE,
1235 # ifdef FEAT_GUI
1236 (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",
1237 # else /* MSDOS or Win32 console */
1238 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1239 # endif
1240 (char_u *)0L}
1241 #else
1242 (char_u *)NULL, PV_NONE,
1243 {(char_u *)NULL, (char_u *)0L}
1244 #endif
1246 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1247 #ifdef FEAT_GUI
1248 (char_u *)&p_guifont, PV_NONE,
1249 {(char_u *)"", (char_u *)0L}
1250 #else
1251 (char_u *)NULL, PV_NONE,
1252 {(char_u *)NULL, (char_u *)0L}
1253 #endif
1255 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1256 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1257 (char_u *)&p_guifontset, PV_NONE,
1258 {(char_u *)"", (char_u *)0L}
1259 #else
1260 (char_u *)NULL, PV_NONE,
1261 {(char_u *)NULL, (char_u *)0L}
1262 #endif
1264 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1265 #if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1266 (char_u *)&p_guifontwide, PV_NONE,
1267 {(char_u *)"", (char_u *)0L}
1268 #else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)NULL, (char_u *)0L}
1271 #endif
1273 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
1274 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
1275 (char_u *)&p_ghr, PV_NONE,
1276 #else
1277 (char_u *)NULL, PV_NONE,
1278 #endif
1279 {(char_u *)50L, (char_u *)0L}},
1280 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
1281 #if defined(FEAT_GUI)
1282 (char_u *)&p_go, PV_NONE,
1283 # if defined(UNIX) && !defined(MACOS)
1284 {(char_u *)"aegimrLtT", (char_u *)0L}
1285 # else
1286 {(char_u *)"egmrLtT", (char_u *)0L}
1287 # endif
1288 #else
1289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
1291 #endif
1293 {"guipty", NULL, P_BOOL|P_VI_DEF,
1294 #if defined(FEAT_GUI)
1295 (char_u *)&p_guipty, PV_NONE,
1296 #else
1297 (char_u *)NULL, PV_NONE,
1298 #endif
1299 {(char_u *)TRUE, (char_u *)0L}},
1300 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
1301 #if defined(FEAT_GUI_TABLINE)
1302 (char_u *)&p_gtl, PV_NONE,
1303 {(char_u *)"", (char_u *)0L}
1304 #else
1305 (char_u *)NULL, PV_NONE,
1306 {(char_u *)NULL, (char_u *)0L}
1307 #endif
1309 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
1310 #if defined(FEAT_GUI_TABLINE)
1311 (char_u *)&p_gtt, PV_NONE,
1312 {(char_u *)"", (char_u *)0L}
1313 #else
1314 (char_u *)NULL, PV_NONE,
1315 {(char_u *)NULL, (char_u *)0L}
1316 #endif
1318 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1319 (char_u *)NULL, PV_NONE,
1320 {(char_u *)0L, (char_u *)0L}},
1321 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1322 (char_u *)&p_hf, PV_NONE,
1323 {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
1324 {"helpheight", "hh", P_NUM|P_VI_DEF,
1325 #ifdef FEAT_WINDOWS
1326 (char_u *)&p_hh, PV_NONE,
1327 #else
1328 (char_u *)NULL, PV_NONE,
1329 #endif
1330 {(char_u *)20L, (char_u *)0L}},
1331 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1332 #ifdef FEAT_MULTI_LANG
1333 (char_u *)&p_hlg, PV_NONE,
1334 {(char_u *)"", (char_u *)0L}
1335 #else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)0L, (char_u *)0L}
1338 #endif
1340 {"hidden", "hid", P_BOOL|P_VI_DEF,
1341 (char_u *)&p_hid, PV_NONE,
1342 {(char_u *)FALSE, (char_u *)0L}},
1343 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1344 (char_u *)&p_hl, PV_NONE,
1345 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}},
1346 {"history", "hi", P_NUM|P_VIM,
1347 (char_u *)&p_hi, PV_NONE,
1348 {(char_u *)0L, (char_u *)20L}},
1349 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1350 #ifdef FEAT_RIGHTLEFT
1351 (char_u *)&p_hkmap, PV_NONE,
1352 #else
1353 (char_u *)NULL, PV_NONE,
1354 #endif
1355 {(char_u *)FALSE, (char_u *)0L}},
1356 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1357 #ifdef FEAT_RIGHTLEFT
1358 (char_u *)&p_hkmapp, PV_NONE,
1359 #else
1360 (char_u *)NULL, PV_NONE,
1361 #endif
1362 {(char_u *)FALSE, (char_u *)0L}},
1363 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1364 (char_u *)&p_hls, PV_NONE,
1365 {(char_u *)FALSE, (char_u *)0L}},
1366 {"icon", NULL, P_BOOL|P_VI_DEF,
1367 #ifdef FEAT_TITLE
1368 (char_u *)&p_icon, PV_NONE,
1369 #else
1370 (char_u *)NULL, PV_NONE,
1371 #endif
1372 {(char_u *)FALSE, (char_u *)0L}},
1373 {"iconstring", NULL, P_STRING|P_VI_DEF,
1374 #ifdef FEAT_TITLE
1375 (char_u *)&p_iconstring, PV_NONE,
1376 #else
1377 (char_u *)NULL, PV_NONE,
1378 #endif
1379 {(char_u *)"", (char_u *)0L}},
1380 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1381 (char_u *)&p_ic, PV_NONE,
1382 {(char_u *)FALSE, (char_u *)0L}},
1383 {"imactivatekey","imak",P_STRING|P_VI_DEF,
1384 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1385 (char_u *)&p_imak, PV_NONE,
1386 #else
1387 (char_u *)NULL, PV_NONE,
1388 #endif
1389 {(char_u *)"", (char_u *)0L}},
1390 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1391 #ifdef USE_IM_CONTROL
1392 (char_u *)&p_imcmdline, PV_NONE,
1393 #else
1394 (char_u *)NULL, PV_NONE,
1395 #endif
1396 {(char_u *)FALSE, (char_u *)0L}},
1397 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1398 #ifdef USE_IM_CONTROL
1399 (char_u *)&p_imdisable, PV_NONE,
1400 #else
1401 (char_u *)NULL, PV_NONE,
1402 #endif
1403 #if defined(__sgi) || defined(FEAT_GUI_MACVIM)
1404 {(char_u *)TRUE, (char_u *)0L}
1405 #else
1406 {(char_u *)FALSE, (char_u *)0L}
1407 #endif
1409 {"iminsert", "imi", P_NUM|P_VI_DEF,
1410 (char_u *)&p_iminsert, PV_IMI,
1411 #ifdef B_IMODE_IM
1412 {(char_u *)B_IMODE_IM, (char_u *)0L}
1413 #else
1414 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1415 #endif
1417 {"imsearch", "ims", P_NUM|P_VI_DEF,
1418 (char_u *)&p_imsearch, PV_IMS,
1419 #ifdef B_IMODE_IM
1420 {(char_u *)B_IMODE_IM, (char_u *)0L}
1421 #else
1422 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1423 #endif
1425 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1426 #ifdef FEAT_FIND_ID
1427 (char_u *)&p_inc, PV_INC,
1428 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1429 #else
1430 (char_u *)NULL, PV_NONE,
1431 {(char_u *)0L, (char_u *)0L}
1432 #endif
1434 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1435 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1436 (char_u *)&p_inex, PV_INEX,
1437 {(char_u *)"", (char_u *)0L}
1438 #else
1439 (char_u *)NULL, PV_NONE,
1440 {(char_u *)0L, (char_u *)0L}
1441 #endif
1443 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1444 (char_u *)&p_is, PV_NONE,
1445 {(char_u *)FALSE, (char_u *)0L}},
1446 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1447 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1448 (char_u *)&p_inde, PV_INDE,
1449 {(char_u *)"", (char_u *)0L}
1450 #else
1451 (char_u *)NULL, PV_NONE,
1452 {(char_u *)0L, (char_u *)0L}
1453 #endif
1455 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1456 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1457 (char_u *)&p_indk, PV_INDK,
1458 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1459 #else
1460 (char_u *)NULL, PV_NONE,
1461 {(char_u *)0L, (char_u *)0L}
1462 #endif
1464 {"infercase", "inf", P_BOOL|P_VI_DEF,
1465 (char_u *)&p_inf, PV_INF,
1466 {(char_u *)FALSE, (char_u *)0L}},
1467 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1468 (char_u *)&p_im, PV_NONE,
1469 {(char_u *)FALSE, (char_u *)0L}},
1470 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1471 (char_u *)&p_isf, PV_NONE,
1473 #ifdef BACKSLASH_IN_FILENAME
1474 /* Excluded are: & and ^ are special in cmd.exe
1475 * ( and ) are used in text separating fnames */
1476 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1477 #else
1478 # ifdef AMIGA
1479 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1480 # else
1481 # ifdef VMS
1482 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1483 # else /* UNIX et al. */
1484 # ifdef EBCDIC
1485 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1486 # else
1487 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1488 # endif
1489 # endif
1490 # endif
1491 #endif
1492 (char_u *)0L}},
1493 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1494 (char_u *)&p_isi, PV_NONE,
1496 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1497 (char_u *)"@,48-57,_,128-167,224-235",
1498 #else
1499 # ifdef EBCDIC
1500 /* TODO: EBCDIC Check this! @ == isalpha()*/
1501 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1502 "112-120,128,140-142,156,158,172,"
1503 "174,186,191,203-207,219-225,235-239,"
1504 "251-254",
1505 # else
1506 (char_u *)"@,48-57,_,192-255",
1507 # endif
1508 #endif
1509 (char_u *)0L}},
1510 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1511 (char_u *)&p_isk, PV_ISK,
1513 #ifdef EBCDIC
1514 (char_u *)"@,240-249,_",
1515 /* TODO: EBCDIC Check this! @ == isalpha()*/
1516 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1517 "112-120,128,140-142,156,158,172,"
1518 "174,186,191,203-207,219-225,235-239,"
1519 "251-254",
1520 #else
1521 (char_u *)"@,48-57,_",
1522 # if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1523 (char_u *)"@,48-57,_,128-167,224-235"
1524 # else
1525 ISK_LATIN1
1526 # endif
1527 #endif
1529 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1530 (char_u *)&p_isp, PV_NONE,
1532 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1533 || (defined(MACOS) && !defined(MACOS_X)) \
1534 || defined(VMS)
1535 (char_u *)"@,~-255",
1536 #else
1537 # ifdef EBCDIC
1538 /* all chars above 63 are printable */
1539 (char_u *)"63-255",
1540 # else
1541 ISP_LATIN1,
1542 # endif
1543 #endif
1544 (char_u *)0L}},
1545 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1546 (char_u *)&p_js, PV_NONE,
1547 {(char_u *)TRUE, (char_u *)0L}},
1548 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1549 #ifdef FEAT_CRYPT
1550 (char_u *)&p_key, PV_KEY,
1551 {(char_u *)"", (char_u *)0L}
1552 #else
1553 (char_u *)NULL, PV_NONE,
1554 {(char_u *)0L, (char_u *)0L}
1555 #endif
1557 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
1558 #ifdef FEAT_KEYMAP
1559 (char_u *)&p_keymap, PV_KMAP,
1560 {(char_u *)"", (char_u *)0L}
1561 #else
1562 (char_u *)NULL, PV_NONE,
1563 {(char_u *)"", (char_u *)0L}
1564 #endif
1566 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1567 #ifdef FEAT_VISUAL
1568 (char_u *)&p_km, PV_NONE,
1569 #else
1570 (char_u *)NULL, PV_NONE,
1571 #endif
1572 {(char_u *)"", (char_u *)0L}},
1573 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1574 (char_u *)&p_kp, PV_KP,
1576 #if defined(MSDOS) || defined(MSWIN)
1577 (char_u *)":help",
1578 #else
1579 #ifdef VMS
1580 (char_u *)"help",
1581 #else
1582 # if defined(OS2)
1583 (char_u *)"view /",
1584 # else
1585 # ifdef USEMAN_S
1586 (char_u *)"man -s",
1587 # else
1588 (char_u *)"man",
1589 # endif
1590 # endif
1591 #endif
1592 #endif
1593 (char_u *)0L}},
1594 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1595 #ifdef FEAT_LANGMAP
1596 (char_u *)&p_langmap, PV_NONE,
1597 {(char_u *)"", /* unmatched } */
1598 #else
1599 (char_u *)NULL, PV_NONE,
1600 {(char_u *)NULL,
1601 #endif
1602 (char_u *)0L}},
1603 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
1604 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1605 (char_u *)&p_lm, PV_NONE,
1606 #else
1607 (char_u *)NULL, PV_NONE,
1608 #endif
1609 {(char_u *)"", (char_u *)0L}},
1610 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1611 #ifdef FEAT_WINDOWS
1612 (char_u *)&p_ls, PV_NONE,
1613 #else
1614 (char_u *)NULL, PV_NONE,
1615 #endif
1616 {(char_u *)1L, (char_u *)0L}},
1617 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1618 (char_u *)&p_lz, PV_NONE,
1619 {(char_u *)FALSE, (char_u *)0L}},
1620 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1621 #ifdef FEAT_LINEBREAK
1622 (char_u *)VAR_WIN, PV_LBR,
1623 #else
1624 (char_u *)NULL, PV_NONE,
1625 #endif
1626 {(char_u *)FALSE, (char_u *)0L}},
1627 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1628 (char_u *)&Rows, PV_NONE,
1630 #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1631 (char_u *)25L,
1632 #else
1633 (char_u *)24L,
1634 #endif
1635 (char_u *)0L}},
1636 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1637 #ifdef FEAT_GUI
1638 (char_u *)&p_linespace, PV_NONE,
1639 #else
1640 (char_u *)NULL, PV_NONE,
1641 #endif
1642 #ifdef FEAT_GUI_W32
1643 {(char_u *)1L, (char_u *)0L}
1644 #else
1645 {(char_u *)0L, (char_u *)0L}
1646 #endif
1648 {"lisp", NULL, P_BOOL|P_VI_DEF,
1649 #ifdef FEAT_LISP
1650 (char_u *)&p_lisp, PV_LISP,
1651 #else
1652 (char_u *)NULL, PV_NONE,
1653 #endif
1654 {(char_u *)FALSE, (char_u *)0L}},
1655 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1656 #ifdef FEAT_LISP
1657 (char_u *)&p_lispwords, PV_NONE,
1658 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1659 #else
1660 (char_u *)NULL, PV_NONE,
1661 {(char_u *)"", (char_u *)0L}
1662 #endif
1664 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1665 (char_u *)VAR_WIN, PV_LIST,
1666 {(char_u *)FALSE, (char_u *)0L}},
1667 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1668 (char_u *)&p_lcs, PV_NONE,
1669 {(char_u *)"eol:$", (char_u *)0L}},
1670 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1671 (char_u *)&p_lpl, PV_NONE,
1672 {(char_u *)TRUE, (char_u *)0L}},
1673 #ifdef FEAT_GUI_MAC
1674 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1675 (char_u *)&p_macatsui, PV_NONE,
1676 {(char_u *)TRUE, (char_u *)0L}},
1677 #endif
1678 {"macmeta", "mmta", P_BOOL|P_VI_DEF,
1679 #ifdef FEAT_GUI_MACVIM
1680 (char_u *)&p_mmta, PV_MMTA,
1681 #else
1682 (char_u *)NULL, PV_NONE,
1683 #endif
1684 {(char_u *)FALSE, (char_u *)0L}},
1685 {"magic", NULL, P_BOOL|P_VI_DEF,
1686 (char_u *)&p_magic, PV_NONE,
1687 {(char_u *)TRUE, (char_u *)0L}},
1688 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1689 #ifdef FEAT_QUICKFIX
1690 (char_u *)&p_mef, PV_NONE,
1691 {(char_u *)"", (char_u *)0L}
1692 #else
1693 (char_u *)NULL, PV_NONE,
1694 {(char_u *)NULL, (char_u *)0L}
1695 #endif
1697 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1698 #ifdef FEAT_QUICKFIX
1699 (char_u *)&p_mp, PV_MP,
1700 # ifdef VMS
1701 {(char_u *)"MMS", (char_u *)0L}
1702 # else
1703 {(char_u *)"make", (char_u *)0L}
1704 # endif
1705 #else
1706 (char_u *)NULL, PV_NONE,
1707 {(char_u *)NULL, (char_u *)0L}
1708 #endif
1710 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1711 (char_u *)&p_mps, PV_MPS,
1712 {(char_u *)"(:),{:},[:]", (char_u *)0L}},
1713 {"matchtime", "mat", P_NUM|P_VI_DEF,
1714 (char_u *)&p_mat, PV_NONE,
1715 {(char_u *)5L, (char_u *)0L}},
1716 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1717 #ifdef FEAT_MBYTE
1718 (char_u *)&p_mco, PV_NONE,
1719 #else
1720 (char_u *)NULL, PV_NONE,
1721 #endif
1722 {(char_u *)2, (char_u *)0L}},
1723 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1724 #ifdef FEAT_EVAL
1725 (char_u *)&p_mfd, PV_NONE,
1726 #else
1727 (char_u *)NULL, PV_NONE,
1728 #endif
1729 {(char_u *)100L, (char_u *)0L}},
1730 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1731 (char_u *)&p_mmd, PV_NONE,
1732 {(char_u *)1000L, (char_u *)0L}},
1733 {"maxmem", "mm", P_NUM|P_VI_DEF,
1734 (char_u *)&p_mm, PV_NONE,
1735 {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
1736 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1737 (char_u *)&p_mmp, PV_NONE,
1738 {(char_u *)1000L, (char_u *)0L}},
1739 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1740 (char_u *)&p_mmt, PV_NONE,
1741 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
1742 {"menuitems", "mis", P_NUM|P_VI_DEF,
1743 #ifdef FEAT_MENU
1744 (char_u *)&p_mis, PV_NONE,
1745 #else
1746 (char_u *)NULL, PV_NONE,
1747 #endif
1748 {(char_u *)25L, (char_u *)0L}},
1749 {"mesg", NULL, P_BOOL|P_VI_DEF,
1750 (char_u *)NULL, PV_NONE,
1751 {(char_u *)FALSE, (char_u *)0L}},
1752 #ifdef USE_MIGEMO
1753 {"migemo", "mgm", P_BOOL|P_VI_DEF|P_VIM,
1754 (char_u *)&p_migemo, PV_MIG,
1755 {(char_u *)FALSE, (char_u *)0L}},
1756 {"migemodict", "mgd", P_STRING|P_EXPAND|P_VI_DEF|P_VIM,
1757 (char_u *)&p_migdict, PV_NONE,
1758 {(char_u *)"", (char_u *)0L}},
1759 #endif /* USE_MIGEMO */
1760 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
1761 #ifdef FEAT_SPELL
1762 (char_u *)&p_msm, PV_NONE,
1763 {(char_u *)"460000,2000,500", (char_u *)0L}
1764 #else
1765 (char_u *)NULL, PV_NONE,
1766 {(char_u *)0L, (char_u *)0L}
1767 #endif
1769 {"modeline", "ml", P_BOOL|P_VIM,
1770 (char_u *)&p_ml, PV_ML,
1771 {(char_u *)FALSE, (char_u *)TRUE}},
1772 {"modelines", "mls", P_NUM|P_VI_DEF,
1773 (char_u *)&p_mls, PV_NONE,
1774 {(char_u *)5L, (char_u *)0L}},
1775 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1776 (char_u *)&p_ma, PV_MA,
1777 {(char_u *)TRUE, (char_u *)0L}},
1778 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1779 (char_u *)&p_mod, PV_MOD,
1780 {(char_u *)FALSE, (char_u *)0L}},
1781 {"more", NULL, P_BOOL|P_VIM,
1782 (char_u *)&p_more, PV_NONE,
1783 {(char_u *)FALSE, (char_u *)TRUE}},
1784 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1785 (char_u *)&p_mouse, PV_NONE,
1787 #if defined(MSDOS) || defined(WIN3264)
1788 (char_u *)"a",
1789 #else
1790 (char_u *)"",
1791 #endif
1792 (char_u *)0L}},
1793 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1794 #ifdef FEAT_GUI
1795 (char_u *)&p_mousef, PV_NONE,
1796 #else
1797 (char_u *)NULL, PV_NONE,
1798 #endif
1799 {(char_u *)FALSE, (char_u *)0L}},
1800 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1801 #ifdef FEAT_GUI
1802 (char_u *)&p_mh, PV_NONE,
1803 #else
1804 (char_u *)NULL, PV_NONE,
1805 #endif
1806 {(char_u *)TRUE, (char_u *)0L}},
1807 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1808 (char_u *)&p_mousem, PV_NONE,
1810 #if defined(MSDOS) || defined(MSWIN)
1811 (char_u *)"popup",
1812 #else
1813 # if defined(MACOS)
1814 (char_u *)"popup_setpos",
1815 # else
1816 (char_u *)"extend",
1817 # endif
1818 #endif
1819 (char_u *)0L}},
1820 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1821 #ifdef FEAT_MOUSESHAPE
1822 (char_u *)&p_mouseshape, PV_NONE,
1823 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1824 #else
1825 (char_u *)NULL, PV_NONE,
1826 {(char_u *)NULL, (char_u *)0L}
1827 #endif
1829 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1830 (char_u *)&p_mouset, PV_NONE,
1831 {(char_u *)500L, (char_u *)0L}},
1832 {"mzquantum", "mzq", P_NUM,
1833 #ifdef FEAT_MZSCHEME
1834 (char_u *)&p_mzq, PV_NONE,
1835 #else
1836 (char_u *)NULL, PV_NONE,
1837 #endif
1838 {(char_u *)100L, (char_u *)100L}},
1839 {"novice", NULL, P_BOOL|P_VI_DEF,
1840 (char_u *)NULL, PV_NONE,
1841 {(char_u *)FALSE, (char_u *)0L}},
1842 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1843 (char_u *)&p_nf, PV_NF,
1844 {(char_u *)"octal,hex", (char_u *)0L}},
1845 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1846 (char_u *)VAR_WIN, PV_NU,
1847 {(char_u *)FALSE, (char_u *)0L}},
1848 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1849 #ifdef FEAT_LINEBREAK
1850 (char_u *)VAR_WIN, PV_NUW,
1851 #else
1852 (char_u *)NULL, PV_NONE,
1853 #endif
1854 {(char_u *)8L, (char_u *)4L}},
1855 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
1856 #ifdef FEAT_COMPL_FUNC
1857 (char_u *)&p_ofu, PV_OFU,
1858 {(char_u *)"", (char_u *)0L}
1859 #else
1860 (char_u *)NULL, PV_NONE,
1861 {(char_u *)0L, (char_u *)0L}
1862 #endif
1864 {"open", NULL, P_BOOL|P_VI_DEF,
1865 (char_u *)NULL, PV_NONE,
1866 {(char_u *)FALSE, (char_u *)0L}},
1867 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1868 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1869 (char_u *)&p_odev, PV_NONE,
1870 #else
1871 (char_u *)NULL, PV_NONE,
1872 #endif
1873 {(char_u *)FALSE, (char_u *)FALSE}
1875 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1876 (char_u *)&p_opfunc, PV_NONE,
1877 {(char_u *)"", (char_u *)0L} },
1878 {"optimize", "opt", P_BOOL|P_VI_DEF,
1879 (char_u *)NULL, PV_NONE,
1880 {(char_u *)FALSE, (char_u *)0L}},
1881 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1882 #ifdef FEAT_OSFILETYPE
1883 (char_u *)&p_oft, PV_OFT,
1884 {(char_u *)DFLT_OFT, (char_u *)0L}
1885 #else
1886 (char_u *)NULL, PV_NONE,
1887 {(char_u *)0L, (char_u *)0L}
1888 #endif
1890 {"paragraphs", "para", P_STRING|P_VI_DEF,
1891 (char_u *)&p_para, PV_NONE,
1892 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
1893 (char_u *)0L}},
1894 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
1895 (char_u *)&p_paste, PV_NONE,
1896 {(char_u *)FALSE, (char_u *)0L}},
1897 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1898 (char_u *)&p_pt, PV_NONE,
1899 {(char_u *)"", (char_u *)0L}},
1900 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1901 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1902 (char_u *)&p_pex, PV_NONE,
1903 {(char_u *)"", (char_u *)0L}
1904 #else
1905 (char_u *)NULL, PV_NONE,
1906 {(char_u *)0L, (char_u *)0L}
1907 #endif
1909 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
1910 (char_u *)&p_pm, PV_NONE,
1911 {(char_u *)"", (char_u *)0L}},
1912 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
1913 (char_u *)&p_path, PV_PATH,
1915 #if defined AMIGA || defined MSDOS || defined MSWIN
1916 (char_u *)".,,",
1917 #else
1918 # if defined(__EMX__)
1919 (char_u *)".,/emx/include,,",
1920 # else /* Unix, probably */
1921 (char_u *)".,/usr/include,,",
1922 # endif
1923 #endif
1924 (char_u *)0L}},
1925 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1926 (char_u *)&p_pi, PV_PI,
1927 {(char_u *)FALSE, (char_u *)0L}},
1928 {"previewheight", "pvh", P_NUM|P_VI_DEF,
1929 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1930 (char_u *)&p_pvh, PV_NONE,
1931 #else
1932 (char_u *)NULL, PV_NONE,
1933 #endif
1934 {(char_u *)12L, (char_u *)0L}},
1935 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1936 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1937 (char_u *)VAR_WIN, PV_PVW,
1938 #else
1939 (char_u *)NULL, PV_NONE,
1940 #endif
1941 {(char_u *)FALSE, (char_u *)0L}},
1942 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
1943 #ifdef FEAT_PRINTER
1944 (char_u *)&p_pdev, PV_NONE,
1945 {(char_u *)"", (char_u *)0L}
1946 #else
1947 (char_u *)NULL, PV_NONE,
1948 {(char_u *)NULL, (char_u *)0L}
1949 #endif
1951 {"printencoding", "penc", P_STRING|P_VI_DEF,
1952 #ifdef FEAT_POSTSCRIPT
1953 (char_u *)&p_penc, PV_NONE,
1954 {(char_u *)"", (char_u *)0L}
1955 #else
1956 (char_u *)NULL, PV_NONE,
1957 {(char_u *)NULL, (char_u *)0L}
1958 #endif
1960 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1961 #ifdef FEAT_POSTSCRIPT
1962 (char_u *)&p_pexpr, PV_NONE,
1963 {(char_u *)"", (char_u *)0L}
1964 #else
1965 (char_u *)NULL, PV_NONE,
1966 {(char_u *)NULL, (char_u *)0L}
1967 #endif
1969 {"printfont", "pfn", P_STRING|P_VI_DEF,
1970 #ifdef FEAT_PRINTER
1971 (char_u *)&p_pfn, PV_NONE,
1973 # ifdef MSWIN
1974 (char_u *)"Courier_New:h10",
1975 # else
1976 (char_u *)"courier",
1977 # endif
1978 (char_u *)0L}
1979 #else
1980 (char_u *)NULL, PV_NONE,
1981 {(char_u *)NULL, (char_u *)0L}
1982 #endif
1984 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1985 #ifdef FEAT_PRINTER
1986 (char_u *)&p_header, PV_NONE,
1987 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1988 #else
1989 (char_u *)NULL, PV_NONE,
1990 {(char_u *)NULL, (char_u *)0L}
1991 #endif
1993 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1994 #if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1995 (char_u *)&p_pmcs, PV_NONE,
1996 {(char_u *)"", (char_u *)0L}
1997 #else
1998 (char_u *)NULL, PV_NONE,
1999 {(char_u *)NULL, (char_u *)0L}
2000 #endif
2002 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2003 #if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2004 (char_u *)&p_pmfn, PV_NONE,
2005 {(char_u *)"", (char_u *)0L}
2006 #else
2007 (char_u *)NULL, PV_NONE,
2008 {(char_u *)NULL, (char_u *)0L}
2009 #endif
2011 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2012 #ifdef FEAT_PRINTER
2013 (char_u *)&p_popt, PV_NONE,
2014 {(char_u *)"", (char_u *)0L}
2015 #else
2016 (char_u *)NULL, PV_NONE,
2017 {(char_u *)NULL, (char_u *)0L}
2018 #endif
2020 {"prompt", NULL, P_BOOL|P_VI_DEF,
2021 (char_u *)&p_prompt, PV_NONE,
2022 {(char_u *)TRUE, (char_u *)0L}},
2023 {"pumheight", "ph", P_NUM|P_VI_DEF,
2024 #ifdef FEAT_INS_EXPAND
2025 (char_u *)&p_ph, PV_NONE,
2026 #else
2027 (char_u *)NULL, PV_NONE,
2028 #endif
2029 {(char_u *)0L, (char_u *)0L}},
2030 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2031 #ifdef FEAT_TEXTOBJ
2032 (char_u *)&p_qe, PV_QE,
2033 {(char_u *)"\\", (char_u *)0L}
2034 #else
2035 (char_u *)NULL, PV_NONE,
2036 {(char_u *)NULL, (char_u *)0L}
2037 #endif
2039 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2040 (char_u *)&p_ro, PV_RO,
2041 {(char_u *)FALSE, (char_u *)0L}},
2042 {"redraw", NULL, P_BOOL|P_VI_DEF,
2043 (char_u *)NULL, PV_NONE,
2044 {(char_u *)FALSE, (char_u *)0L}},
2045 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2046 #ifdef FEAT_RELTIME
2047 (char_u *)&p_rdt, PV_NONE,
2048 #else
2049 (char_u *)NULL, PV_NONE,
2050 #endif
2051 {(char_u *)2000L, (char_u *)0L}},
2052 {"remap", NULL, P_BOOL|P_VI_DEF,
2053 (char_u *)&p_remap, PV_NONE,
2054 {(char_u *)TRUE, (char_u *)0L}},
2055 {"report", NULL, P_NUM|P_VI_DEF,
2056 (char_u *)&p_report, PV_NONE,
2057 {(char_u *)2L, (char_u *)0L}},
2058 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2059 #ifdef WIN3264
2060 (char_u *)&p_rs, PV_NONE,
2061 #else
2062 (char_u *)NULL, PV_NONE,
2063 #endif
2064 {(char_u *)TRUE, (char_u *)0L}},
2065 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2066 #ifdef FEAT_RIGHTLEFT
2067 (char_u *)&p_ri, PV_NONE,
2068 #else
2069 (char_u *)NULL, PV_NONE,
2070 #endif
2071 {(char_u *)FALSE, (char_u *)0L}},
2072 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2073 #ifdef FEAT_RIGHTLEFT
2074 (char_u *)VAR_WIN, PV_RL,
2075 #else
2076 (char_u *)NULL, PV_NONE,
2077 #endif
2078 {(char_u *)FALSE, (char_u *)0L}},
2079 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2080 #ifdef FEAT_RIGHTLEFT
2081 (char_u *)VAR_WIN, PV_RLC,
2082 {(char_u *)"search", (char_u *)NULL}
2083 #else
2084 (char_u *)NULL, PV_NONE,
2085 {(char_u *)NULL, (char_u *)0L}
2086 #endif
2088 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2089 #ifdef FEAT_CMDL_INFO
2090 (char_u *)&p_ru, PV_NONE,
2091 #else
2092 (char_u *)NULL, PV_NONE,
2093 #endif
2094 {(char_u *)FALSE, (char_u *)0L}},
2095 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2096 #ifdef FEAT_STL_OPT
2097 (char_u *)&p_ruf, PV_NONE,
2098 #else
2099 (char_u *)NULL, PV_NONE,
2100 #endif
2101 {(char_u *)"", (char_u *)0L}},
2102 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2103 (char_u *)&p_rtp, PV_NONE,
2104 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
2105 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2106 (char_u *)VAR_WIN, PV_SCROLL,
2107 {(char_u *)12L, (char_u *)0L}},
2108 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2109 #ifdef FEAT_SCROLLBIND
2110 (char_u *)VAR_WIN, PV_SCBIND,
2111 #else
2112 (char_u *)NULL, PV_NONE,
2113 #endif
2114 {(char_u *)FALSE, (char_u *)0L}},
2115 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2116 (char_u *)&p_sj, PV_NONE,
2117 {(char_u *)1L, (char_u *)0L}},
2118 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2119 (char_u *)&p_so, PV_NONE,
2120 {(char_u *)0L, (char_u *)0L}},
2121 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2122 #ifdef FEAT_SCROLLBIND
2123 (char_u *)&p_sbo, PV_NONE,
2124 {(char_u *)"ver,jump", (char_u *)0L}
2125 #else
2126 (char_u *)NULL, PV_NONE,
2127 {(char_u *)0L, (char_u *)0L}
2128 #endif
2130 {"sections", "sect", P_STRING|P_VI_DEF,
2131 (char_u *)&p_sections, PV_NONE,
2132 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
2133 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2134 (char_u *)&p_secure, PV_NONE,
2135 {(char_u *)FALSE, (char_u *)0L}},
2136 {"selection", "sel", P_STRING|P_VI_DEF,
2137 #ifdef FEAT_VISUAL
2138 (char_u *)&p_sel, PV_NONE,
2139 #else
2140 (char_u *)NULL, PV_NONE,
2141 #endif
2142 {(char_u *)"inclusive", (char_u *)0L}},
2143 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2144 #ifdef FEAT_VISUAL
2145 (char_u *)&p_slm, PV_NONE,
2146 #else
2147 (char_u *)NULL, PV_NONE,
2148 #endif
2149 {(char_u *)"", (char_u *)0L}},
2150 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2151 #ifdef FEAT_SESSION
2152 (char_u *)&p_ssop, PV_NONE,
2153 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
2154 (char_u *)0L}
2155 #else
2156 (char_u *)NULL, PV_NONE,
2157 {(char_u *)0L, (char_u *)0L}
2158 #endif
2160 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2161 (char_u *)&p_sh, PV_NONE,
2163 #ifdef VMS
2164 (char_u *)"-",
2165 #else
2166 # if defined(MSDOS)
2167 (char_u *)"command",
2168 # else
2169 # if defined(WIN16)
2170 (char_u *)"command.com",
2171 # else
2172 # if defined(WIN3264)
2173 (char_u *)"", /* set in set_init_1() */
2174 # else
2175 # if defined(OS2)
2176 (char_u *)"cmd.exe",
2177 # else
2178 # if defined(ARCHIE)
2179 (char_u *)"gos",
2180 # else
2181 (char_u *)"sh",
2182 # endif
2183 # endif
2184 # endif
2185 # endif
2186 # endif
2187 #endif /* VMS */
2188 (char_u *)0L}},
2189 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2190 (char_u *)&p_shcf, PV_NONE,
2192 #if defined(MSDOS) || defined(MSWIN)
2193 (char_u *)"/c",
2194 #else
2195 # if defined(OS2)
2196 (char_u *)"/c",
2197 # else
2198 (char_u *)"-c",
2199 # endif
2200 #endif
2201 (char_u *)0L}},
2202 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2203 #ifdef FEAT_QUICKFIX
2204 (char_u *)&p_sp, PV_NONE,
2206 #if defined(UNIX) || defined(OS2)
2207 # ifdef ARCHIE
2208 (char_u *)"2>",
2209 # else
2210 (char_u *)"| tee",
2211 # endif
2212 #else
2213 (char_u *)">",
2214 #endif
2215 (char_u *)0L}
2216 #else
2217 (char_u *)NULL, PV_NONE,
2218 {(char_u *)0L, (char_u *)0L}
2219 #endif
2221 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2222 (char_u *)&p_shq, PV_NONE,
2223 {(char_u *)"", (char_u *)0L}},
2224 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2225 (char_u *)&p_srr, PV_NONE,
2226 {(char_u *)">", (char_u *)0L}},
2227 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2228 #ifdef BACKSLASH_IN_FILENAME
2229 (char_u *)&p_ssl, PV_NONE,
2230 #else
2231 (char_u *)NULL, PV_NONE,
2232 #endif
2233 {(char_u *)FALSE, (char_u *)0L}},
2234 {"shelltemp", "stmp", P_BOOL,
2235 (char_u *)&p_stmp, PV_NONE,
2236 {(char_u *)FALSE, (char_u *)TRUE}},
2237 {"shelltype", "st", P_NUM|P_VI_DEF,
2238 #ifdef AMIGA
2239 (char_u *)&p_st, PV_NONE,
2240 #else
2241 (char_u *)NULL, PV_NONE,
2242 #endif
2243 {(char_u *)0L, (char_u *)0L}},
2244 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2245 (char_u *)&p_sxq, PV_NONE,
2247 #if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2248 (char_u *)"\"",
2249 #else
2250 (char_u *)"",
2251 #endif
2252 (char_u *)0L}},
2253 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2254 (char_u *)&p_sr, PV_NONE,
2255 {(char_u *)FALSE, (char_u *)0L}},
2256 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2257 (char_u *)&p_sw, PV_SW,
2258 {(char_u *)8L, (char_u *)0L}},
2259 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2260 (char_u *)&p_shm, PV_NONE,
2261 {(char_u *)"", (char_u *)"filnxtToO"}},
2262 {"shortname", "sn", P_BOOL|P_VI_DEF,
2263 #ifdef SHORT_FNAME
2264 (char_u *)NULL, PV_NONE,
2265 #else
2266 (char_u *)&p_sn, PV_SN,
2267 #endif
2268 {(char_u *)FALSE, (char_u *)0L}},
2269 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2270 #ifdef FEAT_LINEBREAK
2271 (char_u *)&p_sbr, PV_NONE,
2272 #else
2273 (char_u *)NULL, PV_NONE,
2274 #endif
2275 {(char_u *)"", (char_u *)0L}},
2276 {"showcmd", "sc", P_BOOL|P_VIM,
2277 #ifdef FEAT_CMDL_INFO
2278 (char_u *)&p_sc, PV_NONE,
2279 #else
2280 (char_u *)NULL, PV_NONE,
2281 #endif
2282 {(char_u *)FALSE,
2283 #ifdef UNIX
2284 (char_u *)FALSE
2285 #else
2286 (char_u *)TRUE
2287 #endif
2289 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2290 (char_u *)&p_sft, PV_NONE,
2291 {(char_u *)FALSE, (char_u *)0L}},
2292 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2293 (char_u *)&p_sm, PV_NONE,
2294 {(char_u *)FALSE, (char_u *)0L}},
2295 {"showmode", "smd", P_BOOL|P_VIM,
2296 (char_u *)&p_smd, PV_NONE,
2297 {(char_u *)FALSE, (char_u *)TRUE}},
2298 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2299 #ifdef FEAT_WINDOWS
2300 (char_u *)&p_stal, PV_NONE,
2301 #else
2302 (char_u *)NULL, PV_NONE,
2303 #endif
2304 {(char_u *)1L, (char_u *)0L}},
2305 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2306 (char_u *)&p_ss, PV_NONE,
2307 {(char_u *)0L, (char_u *)0L}},
2308 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2309 (char_u *)&p_siso, PV_NONE,
2310 {(char_u *)0L, (char_u *)0L}},
2311 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2312 (char_u *)NULL, PV_NONE,
2313 {(char_u *)FALSE, (char_u *)0L}},
2314 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2315 (char_u *)&p_scs, PV_NONE,
2316 {(char_u *)FALSE, (char_u *)0L}},
2317 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2318 #ifdef FEAT_SMARTINDENT
2319 (char_u *)&p_si, PV_SI,
2320 #else
2321 (char_u *)NULL, PV_NONE,
2322 #endif
2323 {(char_u *)FALSE, (char_u *)0L}},
2324 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2325 (char_u *)&p_sta, PV_NONE,
2326 {(char_u *)FALSE, (char_u *)0L}},
2327 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2328 (char_u *)&p_sts, PV_STS,
2329 {(char_u *)0L, (char_u *)0L}},
2330 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2331 (char_u *)NULL, PV_NONE,
2332 {(char_u *)FALSE, (char_u *)0L}},
2333 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2334 #ifdef FEAT_SPELL
2335 (char_u *)VAR_WIN, PV_SPELL,
2336 #else
2337 (char_u *)NULL, PV_NONE,
2338 #endif
2339 {(char_u *)FALSE, (char_u *)0L}},
2340 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
2341 #ifdef FEAT_SPELL
2342 (char_u *)&p_spc, PV_SPC,
2343 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
2344 #else
2345 (char_u *)NULL, PV_NONE,
2346 {(char_u *)0L, (char_u *)0L}
2347 #endif
2349 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
2350 #ifdef FEAT_SPELL
2351 (char_u *)&p_spf, PV_SPF,
2352 {(char_u *)"", (char_u *)0L}
2353 #else
2354 (char_u *)NULL, PV_NONE,
2355 {(char_u *)0L, (char_u *)0L}
2356 #endif
2358 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
2359 #ifdef FEAT_SPELL
2360 (char_u *)&p_spl, PV_SPL,
2361 {(char_u *)"en", (char_u *)0L}
2362 #else
2363 (char_u *)NULL, PV_NONE,
2364 {(char_u *)0L, (char_u *)0L}
2365 #endif
2367 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
2368 #ifdef FEAT_SPELL
2369 (char_u *)&p_sps, PV_NONE,
2370 {(char_u *)"best", (char_u *)0L}
2371 #else
2372 (char_u *)NULL, PV_NONE,
2373 {(char_u *)0L, (char_u *)0L}
2374 #endif
2376 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2377 #ifdef FEAT_WINDOWS
2378 (char_u *)&p_sb, PV_NONE,
2379 #else
2380 (char_u *)NULL, PV_NONE,
2381 #endif
2382 {(char_u *)FALSE, (char_u *)0L}},
2383 {"splitright", "spr", P_BOOL|P_VI_DEF,
2384 #ifdef FEAT_VERTSPLIT
2385 (char_u *)&p_spr, PV_NONE,
2386 #else
2387 (char_u *)NULL, PV_NONE,
2388 #endif
2389 {(char_u *)FALSE, (char_u *)0L}},
2390 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2391 (char_u *)&p_sol, PV_NONE,
2392 {(char_u *)TRUE, (char_u *)0L}},
2393 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2394 #ifdef FEAT_STL_OPT
2395 (char_u *)&p_stl, PV_STL,
2396 #else
2397 (char_u *)NULL, PV_NONE,
2398 #endif
2399 {(char_u *)"", (char_u *)0L}},
2400 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2401 (char_u *)&p_su, PV_NONE,
2402 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2403 (char_u *)0L}},
2404 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
2405 #ifdef FEAT_SEARCHPATH
2406 (char_u *)&p_sua, PV_SUA,
2407 {(char_u *)"", (char_u *)0L}
2408 #else
2409 (char_u *)NULL, PV_NONE,
2410 {(char_u *)0L, (char_u *)0L}
2411 #endif
2413 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2414 (char_u *)&p_swf, PV_SWF,
2415 {(char_u *)TRUE, (char_u *)0L}},
2416 {"swapsync", "sws", P_STRING|P_VI_DEF,
2417 (char_u *)&p_sws, PV_NONE,
2418 {(char_u *)"fsync", (char_u *)0L}},
2419 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2420 (char_u *)&p_swb, PV_NONE,
2421 {(char_u *)"", (char_u *)0L}},
2422 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2423 #ifdef FEAT_SYN_HL
2424 (char_u *)&p_smc, PV_SMC,
2425 {(char_u *)3000L, (char_u *)0L}
2426 #else
2427 (char_u *)NULL, PV_NONE,
2428 {(char_u *)0L, (char_u *)0L}
2429 #endif
2431 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
2432 #ifdef FEAT_SYN_HL
2433 (char_u *)&p_syn, PV_SYN,
2434 {(char_u *)"", (char_u *)0L}
2435 #else
2436 (char_u *)NULL, PV_NONE,
2437 {(char_u *)0L, (char_u *)0L}
2438 #endif
2440 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2441 #ifdef FEAT_STL_OPT
2442 (char_u *)&p_tal, PV_NONE,
2443 #else
2444 (char_u *)NULL, PV_NONE,
2445 #endif
2446 {(char_u *)"", (char_u *)0L}},
2447 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2448 #ifdef FEAT_WINDOWS
2449 (char_u *)&p_tpm, PV_NONE,
2450 #else
2451 (char_u *)NULL, PV_NONE,
2452 #endif
2453 {(char_u *)10L, (char_u *)0L}},
2454 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2455 (char_u *)&p_ts, PV_TS,
2456 {(char_u *)8L, (char_u *)0L}},
2457 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2458 (char_u *)&p_tbs, PV_NONE,
2459 #ifdef VMS /* binary searching doesn't appear to work on VMS */
2460 {(char_u *)0L, (char_u *)0L}
2461 #else
2462 {(char_u *)TRUE, (char_u *)0L}
2463 #endif
2465 {"taglength", "tl", P_NUM|P_VI_DEF,
2466 (char_u *)&p_tl, PV_NONE,
2467 {(char_u *)0L, (char_u *)0L}},
2468 {"tagrelative", "tr", P_BOOL|P_VIM,
2469 (char_u *)&p_tr, PV_NONE,
2470 {(char_u *)FALSE, (char_u *)TRUE}},
2471 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2472 (char_u *)&p_tags, PV_TAGS,
2474 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2475 (char_u *)"./tags,./TAGS,tags,TAGS",
2476 #else
2477 (char_u *)"./tags,tags",
2478 #endif
2479 (char_u *)0L}},
2480 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2481 (char_u *)&p_tgst, PV_NONE,
2482 {(char_u *)TRUE, (char_u *)0L}},
2483 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2484 (char_u *)&T_NAME, PV_NONE,
2485 {(char_u *)"", (char_u *)0L}},
2486 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2487 #ifdef FEAT_ARABIC
2488 (char_u *)&p_tbidi, PV_NONE,
2489 #else
2490 (char_u *)NULL, PV_NONE,
2491 #endif
2492 {(char_u *)FALSE, (char_u *)0L}},
2493 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2494 #ifdef FEAT_MBYTE
2495 (char_u *)&p_tenc, PV_NONE,
2496 {(char_u *)"", (char_u *)0L}
2497 #else
2498 (char_u *)NULL, PV_NONE,
2499 {(char_u *)0L, (char_u *)0L}
2500 #endif
2502 {"terse", NULL, P_BOOL|P_VI_DEF,
2503 (char_u *)&p_terse, PV_NONE,
2504 {(char_u *)FALSE, (char_u *)0L}},
2505 {"textauto", "ta", P_BOOL|P_VIM,
2506 (char_u *)&p_ta, PV_NONE,
2507 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2508 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2509 (char_u *)&p_tx, PV_TX,
2511 #ifdef USE_CRNL
2512 (char_u *)TRUE,
2513 #else
2514 (char_u *)FALSE,
2515 #endif
2516 (char_u *)0L}},
2517 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2518 (char_u *)&p_tw, PV_TW,
2519 {(char_u *)0L, (char_u *)0L}},
2520 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2521 #ifdef FEAT_INS_EXPAND
2522 (char_u *)&p_tsr, PV_TSR,
2523 #else
2524 (char_u *)NULL, PV_NONE,
2525 #endif
2526 {(char_u *)"", (char_u *)0L}},
2527 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2528 (char_u *)&p_to, PV_NONE,
2529 {(char_u *)FALSE, (char_u *)0L}},
2530 {"timeout", "to", P_BOOL|P_VI_DEF,
2531 (char_u *)&p_timeout, PV_NONE,
2532 {(char_u *)TRUE, (char_u *)0L}},
2533 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2534 (char_u *)&p_tm, PV_NONE,
2535 {(char_u *)1000L, (char_u *)0L}},
2536 {"title", NULL, P_BOOL|P_VI_DEF,
2537 #ifdef FEAT_TITLE
2538 (char_u *)&p_title, PV_NONE,
2539 #else
2540 (char_u *)NULL, PV_NONE,
2541 #endif
2542 {(char_u *)FALSE, (char_u *)0L}},
2543 {"titlelen", NULL, P_NUM|P_VI_DEF,
2544 #ifdef FEAT_TITLE
2545 (char_u *)&p_titlelen, PV_NONE,
2546 #else
2547 (char_u *)NULL, PV_NONE,
2548 #endif
2549 {(char_u *)85L, (char_u *)0L}},
2550 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
2551 #ifdef FEAT_TITLE
2552 (char_u *)&p_titleold, PV_NONE,
2553 {(char_u *)N_("Thanks for flying Vim"),
2554 (char_u *)0L}
2555 #else
2556 (char_u *)NULL, PV_NONE,
2557 {(char_u *)0L, (char_u *)0L}
2558 #endif
2560 {"titlestring", NULL, P_STRING|P_VI_DEF,
2561 #ifdef FEAT_TITLE
2562 (char_u *)&p_titlestring, PV_NONE,
2563 #else
2564 (char_u *)NULL, PV_NONE,
2565 #endif
2566 {(char_u *)"", (char_u *)0L}},
2567 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2568 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2569 (char_u *)&p_toolbar, PV_NONE,
2570 {(char_u *)"icons,tooltips", (char_u *)0L}},
2571 #endif
2572 #if defined(FEAT_TOOLBAR) && ((defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)) \
2573 || defined(FEAT_GUI_MACVIM))
2574 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2575 (char_u *)&p_tbis, PV_NONE,
2576 {(char_u *)"small", (char_u *)0L}},
2577 #endif
2578 {"transparency", "transp", P_NUM|P_VIM|P_RCLR,
2579 #ifdef FEAT_TRANSPARENCY
2580 (char_u *)&p_transp, PV_NONE,
2581 #else
2582 (char_u *)NULL, PV_NONE,
2583 #endif
2584 {(char_u *)0L, (char_u *)0L} },
2585 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2586 (char_u *)&p_ttimeout, PV_NONE,
2587 {(char_u *)FALSE, (char_u *)0L}},
2588 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2589 (char_u *)&p_ttm, PV_NONE,
2590 {(char_u *)-1L, (char_u *)0L}},
2591 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2592 (char_u *)&p_tbi, PV_NONE,
2593 {(char_u *)TRUE, (char_u *)0L}},
2594 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2595 (char_u *)&p_tf, PV_NONE,
2596 {(char_u *)FALSE, (char_u *)0L}},
2597 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2598 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2599 (char_u *)&p_ttym, PV_NONE,
2600 #else
2601 (char_u *)NULL, PV_NONE,
2602 #endif
2603 {(char_u *)"", (char_u *)0L}},
2604 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2605 (char_u *)&p_ttyscroll, PV_NONE,
2606 {(char_u *)999L, (char_u *)0L}},
2607 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2608 (char_u *)&T_NAME, PV_NONE,
2609 {(char_u *)"", (char_u *)0L}},
2610 {"undolevels", "ul", P_NUM|P_VI_DEF,
2611 (char_u *)&p_ul, PV_NONE,
2613 #if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2614 (char_u *)1000L,
2615 #else
2616 (char_u *)100L,
2617 #endif
2618 (char_u *)0L}},
2619 {"updatecount", "uc", P_NUM|P_VI_DEF,
2620 (char_u *)&p_uc, PV_NONE,
2621 {(char_u *)200L, (char_u *)0L}},
2622 {"updatetime", "ut", P_NUM|P_VI_DEF,
2623 (char_u *)&p_ut, PV_NONE,
2624 {(char_u *)4000L, (char_u *)0L}},
2625 {"verbose", "vbs", P_NUM|P_VI_DEF,
2626 (char_u *)&p_verbose, PV_NONE,
2627 {(char_u *)0L, (char_u *)0L}},
2628 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2629 (char_u *)&p_vfile, PV_NONE,
2630 {(char_u *)"", (char_u *)0L}},
2631 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2632 #ifdef FEAT_SESSION
2633 (char_u *)&p_vdir, PV_NONE,
2634 {(char_u *)DFLT_VDIR, (char_u *)0L}
2635 #else
2636 (char_u *)NULL, PV_NONE,
2637 {(char_u *)0L, (char_u *)0L}
2638 #endif
2640 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2641 #ifdef FEAT_SESSION
2642 (char_u *)&p_vop, PV_NONE,
2643 {(char_u *)"folds,options,cursor", (char_u *)0L}
2644 #else
2645 (char_u *)NULL, PV_NONE,
2646 {(char_u *)0L, (char_u *)0L}
2647 #endif
2649 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2650 #ifdef FEAT_VIMINFO
2651 (char_u *)&p_viminfo, PV_NONE,
2652 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2653 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
2654 #else
2655 # ifdef AMIGA
2656 {(char_u *)"",
2657 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2658 # else
2659 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
2660 # endif
2661 #endif
2662 #else
2663 (char_u *)NULL, PV_NONE,
2664 {(char_u *)0L, (char_u *)0L}
2665 #endif
2667 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2668 #ifdef FEAT_VIRTUALEDIT
2669 (char_u *)&p_ve, PV_NONE,
2670 {(char_u *)"", (char_u *)""}
2671 #else
2672 (char_u *)NULL, PV_NONE,
2673 {(char_u *)0L, (char_u *)0L}
2674 #endif
2676 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2677 (char_u *)&p_vb, PV_NONE,
2678 {(char_u *)FALSE, (char_u *)0L}},
2679 {"w300", NULL, P_NUM|P_VI_DEF,
2680 (char_u *)NULL, PV_NONE,
2681 {(char_u *)0L, (char_u *)0L}},
2682 {"w1200", NULL, P_NUM|P_VI_DEF,
2683 (char_u *)NULL, PV_NONE,
2684 {(char_u *)0L, (char_u *)0L}},
2685 {"w9600", NULL, P_NUM|P_VI_DEF,
2686 (char_u *)NULL, PV_NONE,
2687 {(char_u *)0L, (char_u *)0L}},
2688 {"warn", NULL, P_BOOL|P_VI_DEF,
2689 (char_u *)&p_warn, PV_NONE,
2690 {(char_u *)TRUE, (char_u *)0L}},
2691 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2692 (char_u *)&p_wiv, PV_NONE,
2693 {(char_u *)FALSE, (char_u *)0L}},
2694 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2695 (char_u *)&p_ww, PV_NONE,
2696 {(char_u *)"", (char_u *)"b,s"}},
2697 {"wildchar", "wc", P_NUM|P_VIM,
2698 (char_u *)&p_wc, PV_NONE,
2699 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2700 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2701 (char_u *)&p_wcm, PV_NONE,
2702 {(char_u *)0L, (char_u *)0L}},
2703 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2704 #ifdef FEAT_WILDIGN
2705 (char_u *)&p_wig, PV_NONE,
2706 #else
2707 (char_u *)NULL, PV_NONE,
2708 #endif
2709 {(char_u *)"", (char_u *)0L}},
2710 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2711 #ifdef FEAT_WILDMENU
2712 (char_u *)&p_wmnu, PV_NONE,
2713 #else
2714 (char_u *)NULL, PV_NONE,
2715 #endif
2716 {(char_u *)FALSE, (char_u *)0L}},
2717 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2718 (char_u *)&p_wim, PV_NONE,
2719 {(char_u *)"full", (char_u *)0L}},
2720 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2721 #ifdef FEAT_CMDL_COMPL
2722 (char_u *)&p_wop, PV_NONE,
2723 {(char_u *)"", (char_u *)0L}
2724 #else
2725 (char_u *)NULL, PV_NONE,
2726 {(char_u *)NULL, (char_u *)0L}
2727 #endif
2729 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2730 #ifdef FEAT_WAK
2731 (char_u *)&p_wak, PV_NONE,
2732 {(char_u *)"menu", (char_u *)0L}
2733 #else
2734 (char_u *)NULL, PV_NONE,
2735 {(char_u *)NULL, (char_u *)0L}
2736 #endif
2738 {"window", "wi", P_NUM|P_VI_DEF,
2739 (char_u *)&p_window, PV_NONE,
2740 {(char_u *)0L, (char_u *)0L}},
2741 {"winheight", "wh", P_NUM|P_VI_DEF,
2742 #ifdef FEAT_WINDOWS
2743 (char_u *)&p_wh, PV_NONE,
2744 #else
2745 (char_u *)NULL, PV_NONE,
2746 #endif
2747 {(char_u *)1L, (char_u *)0L}},
2748 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
2749 #ifdef FEAT_WINDOWS
2750 (char_u *)VAR_WIN, PV_WFH,
2751 #else
2752 (char_u *)NULL, PV_NONE,
2753 #endif
2754 {(char_u *)FALSE, (char_u *)0L}},
2755 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2756 #ifdef FEAT_VERTSPLIT
2757 (char_u *)VAR_WIN, PV_WFW,
2758 #else
2759 (char_u *)NULL, PV_NONE,
2760 #endif
2761 {(char_u *)FALSE, (char_u *)0L}},
2762 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2763 #ifdef FEAT_WINDOWS
2764 (char_u *)&p_wmh, PV_NONE,
2765 #else
2766 (char_u *)NULL, PV_NONE,
2767 #endif
2768 {(char_u *)1L, (char_u *)0L}},
2769 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2770 #ifdef FEAT_VERTSPLIT
2771 (char_u *)&p_wmw, PV_NONE,
2772 #else
2773 (char_u *)NULL, PV_NONE,
2774 #endif
2775 {(char_u *)1L, (char_u *)0L}},
2776 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2777 #ifdef FEAT_VERTSPLIT
2778 (char_u *)&p_wiw, PV_NONE,
2779 #else
2780 (char_u *)NULL, PV_NONE,
2781 #endif
2782 {(char_u *)20L, (char_u *)0L}},
2783 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2784 (char_u *)VAR_WIN, PV_WRAP,
2785 {(char_u *)TRUE, (char_u *)0L}},
2786 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2787 (char_u *)&p_wm, PV_WM,
2788 {(char_u *)0L, (char_u *)0L}},
2789 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2790 (char_u *)&p_ws, PV_NONE,
2791 {(char_u *)TRUE, (char_u *)0L}},
2792 {"write", NULL, P_BOOL|P_VI_DEF,
2793 (char_u *)&p_write, PV_NONE,
2794 {(char_u *)TRUE, (char_u *)0L}},
2795 {"writeany", "wa", P_BOOL|P_VI_DEF,
2796 (char_u *)&p_wa, PV_NONE,
2797 {(char_u *)FALSE, (char_u *)0L}},
2798 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2799 (char_u *)&p_wb, PV_NONE,
2801 #ifdef FEAT_WRITEBACKUP
2802 (char_u *)TRUE,
2803 #else
2804 (char_u *)FALSE,
2805 #endif
2806 (char_u *)0L}},
2807 {"writedelay", "wd", P_NUM|P_VI_DEF,
2808 (char_u *)&p_wd, PV_NONE,
2809 {(char_u *)0L, (char_u *)0L}},
2811 /* terminal output codes */
2812 #define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
2813 (char_u *)&vvv, PV_NONE, \
2814 {(char_u *)"", (char_u *)0L}},
2816 p_term("t_AB", T_CAB)
2817 p_term("t_AF", T_CAF)
2818 p_term("t_AL", T_CAL)
2819 p_term("t_al", T_AL)
2820 p_term("t_bc", T_BC)
2821 p_term("t_cd", T_CD)
2822 p_term("t_ce", T_CE)
2823 p_term("t_cl", T_CL)
2824 p_term("t_cm", T_CM)
2825 p_term("t_Co", T_CCO)
2826 p_term("t_CS", T_CCS)
2827 p_term("t_cs", T_CS)
2828 #ifdef FEAT_VERTSPLIT
2829 p_term("t_CV", T_CSV)
2830 #endif
2831 p_term("t_ut", T_UT)
2832 p_term("t_da", T_DA)
2833 p_term("t_db", T_DB)
2834 p_term("t_DL", T_CDL)
2835 p_term("t_dl", T_DL)
2836 p_term("t_fs", T_FS)
2837 p_term("t_IE", T_CIE)
2838 p_term("t_IS", T_CIS)
2839 p_term("t_ke", T_KE)
2840 p_term("t_ks", T_KS)
2841 p_term("t_le", T_LE)
2842 p_term("t_mb", T_MB)
2843 p_term("t_md", T_MD)
2844 p_term("t_me", T_ME)
2845 p_term("t_mr", T_MR)
2846 p_term("t_ms", T_MS)
2847 p_term("t_nd", T_ND)
2848 p_term("t_op", T_OP)
2849 p_term("t_RI", T_CRI)
2850 p_term("t_RV", T_CRV)
2851 p_term("t_Sb", T_CSB)
2852 p_term("t_Sf", T_CSF)
2853 p_term("t_se", T_SE)
2854 p_term("t_so", T_SO)
2855 p_term("t_sr", T_SR)
2856 p_term("t_ts", T_TS)
2857 p_term("t_te", T_TE)
2858 p_term("t_ti", T_TI)
2859 p_term("t_ue", T_UE)
2860 p_term("t_us", T_US)
2861 p_term("t_vb", T_VB)
2862 p_term("t_ve", T_VE)
2863 p_term("t_vi", T_VI)
2864 p_term("t_vs", T_VS)
2865 p_term("t_WP", T_CWP)
2866 p_term("t_WS", T_CWS)
2867 p_term("t_SI", T_CSI)
2868 p_term("t_EI", T_CEI)
2869 p_term("t_xs", T_XS)
2870 p_term("t_ZH", T_CZH)
2871 p_term("t_ZR", T_CZR)
2873 /* terminal key codes are not in here */
2875 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2878 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2880 #ifdef FEAT_MBYTE
2881 static char *(p_ambw_values[]) = {"single", "double",
2882 # ifdef USE_AMBIWIDTH_AUTO
2883 "auto",
2884 # endif
2885 NULL};
2886 #endif
2887 static char *(p_bg_values[]) = {"light", "dark", NULL};
2888 static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2889 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
2890 #ifdef FEAT_CMDL_COMPL
2891 static char *(p_wop_values[]) = {"tagfile", NULL};
2892 #endif
2893 #ifdef FEAT_WAK
2894 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2895 #endif
2896 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2897 #ifdef FEAT_VISUAL
2898 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2899 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2900 #endif
2901 #ifdef FEAT_VISUAL
2902 static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2903 #endif
2904 #ifdef FEAT_BROWSE
2905 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2906 #endif
2907 #ifdef FEAT_SCROLLBIND
2908 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2909 #endif
2910 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
2911 #ifdef FEAT_VERTSPLIT
2912 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2913 #endif
2914 #if defined(FEAT_QUICKFIX)
2915 # ifdef FEAT_AUTOCMD
2916 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2917 # else
2918 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
2919 # endif
2920 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2921 #endif
2922 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2923 #ifdef FEAT_FOLDING
2924 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
2925 # ifdef FEAT_DIFF
2926 "diff",
2927 # endif
2928 NULL};
2929 static char *(p_fcl_values[]) = {"all", NULL};
2930 #endif
2931 #ifdef FEAT_INS_EXPAND
2932 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
2933 #endif
2935 static void set_option_default __ARGS((int, int opt_flags, int compatible));
2936 static void set_options_default __ARGS((int opt_flags));
2937 static char_u *term_bg_default __ARGS((void));
2938 static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
2939 static char_u *illegal_char __ARGS((char_u *, int));
2940 static int string_to_key __ARGS((char_u *arg));
2941 #ifdef FEAT_CMDWIN
2942 static char_u *check_cedit __ARGS((void));
2943 #endif
2944 #ifdef FEAT_TITLE
2945 static void did_set_title __ARGS((int icon));
2946 #endif
2947 static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2948 static void didset_options __ARGS((void));
2949 static void check_string_option __ARGS((char_u **pp));
2950 #if defined(FEAT_EVAL) || defined(PROTO)
2951 static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2952 #else
2953 # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2954 #endif
2955 static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2956 static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2957 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));
2958 static char_u *set_chars_option __ARGS((char_u **varp));
2959 #ifdef FEAT_CLIPBOARD
2960 static char_u *check_clipboard_option __ARGS((void));
2961 #endif
2962 #ifdef FEAT_SPELL
2963 static char_u *compile_cap_prog __ARGS((buf_T *buf));
2964 #endif
2965 #ifdef FEAT_EVAL
2966 static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2967 #endif
2968 static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
2969 static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
2970 static void check_redraw __ARGS((long_u flags));
2971 static int findoption __ARGS((char_u *));
2972 static int find_key_option __ARGS((char_u *));
2973 static void showoptions __ARGS((int all, int opt_flags));
2974 static int optval_default __ARGS((struct vimoption *, char_u *varp));
2975 static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2976 static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2977 static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2978 static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2979 static int istermoption __ARGS((struct vimoption *));
2980 static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2981 static char_u *get_varp __ARGS((struct vimoption *));
2982 static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2983 static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2984 #ifdef FEAT_LANGMAP
2985 static void langmap_init __ARGS((void));
2986 static void langmap_set __ARGS((void));
2987 #endif
2988 static void paste_option_changed __ARGS((void));
2989 static void compatible_set __ARGS((void));
2990 #ifdef FEAT_LINEBREAK
2991 static void fill_breakat_flags __ARGS((void));
2992 #endif
2993 static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2994 static int check_opt_strings __ARGS((char_u *val, char **values, int));
2995 static int check_opt_wim __ARGS((void));
2996 #ifdef FEAT_FULLSCREEN
2997 static int check_fuoptions __ARGS((char_u *, unsigned *, int *));
2998 #endif
3001 * Initialize the options, first part.
3003 * Called only once from main(), just after creating the first buffer.
3005 void
3006 set_init_1()
3008 char_u *p;
3009 int opt_idx;
3010 long_u n;
3011 #if defined(FEAT_GUI_MACVIM) && defined(FEAT_MBYTE)
3012 int did_mb_init;
3013 #endif
3015 #ifdef FEAT_LANGMAP
3016 langmap_init();
3017 #endif
3019 /* Be Vi compatible by default */
3020 p_cp = TRUE;
3022 /* Use POSIX compatibility when $VIM_POSIX is set. */
3023 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
3025 set_string_default("cpo", (char_u *)CPO_ALL);
3026 set_string_default("shm", (char_u *)"A");
3030 * Find default value for 'shell' option.
3031 * Don't use it if it is empty.
3033 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
3034 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3035 # ifdef __EMX__
3036 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
3037 # endif
3038 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
3039 # ifdef WIN3264
3040 || ((p = default_shell()) != NULL && *p != NUL)
3041 # endif
3042 #endif
3044 set_string_default("sh", p);
3046 #ifdef FEAT_WILDIGN
3048 * Set the default for 'backupskip' to include environment variables for
3049 * temp files.
3052 # ifdef UNIX
3053 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3054 # else
3055 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3056 # endif
3057 int len;
3058 garray_T ga;
3059 int mustfree;
3061 ga_init2(&ga, 1, 100);
3062 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3064 mustfree = FALSE;
3065 # ifdef UNIX
3066 if (*names[n] == NUL)
3067 p = (char_u *)"/tmp";
3068 else
3069 # endif
3070 p = vim_getenv((char_u *)names[n], &mustfree);
3071 if (p != NULL && *p != NUL)
3073 /* First time count the NUL, otherwise count the ','. */
3074 len = (int)STRLEN(p) + 3;
3075 if (ga_grow(&ga, len) == OK)
3077 if (ga.ga_len > 0)
3078 STRCAT(ga.ga_data, ",");
3079 STRCAT(ga.ga_data, p);
3080 add_pathsep(ga.ga_data);
3081 STRCAT(ga.ga_data, "*");
3082 ga.ga_len += len;
3085 if (mustfree)
3086 vim_free(p);
3088 if (ga.ga_data != NULL)
3090 set_string_default("bsk", ga.ga_data);
3091 vim_free(ga.ga_data);
3094 #endif
3097 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3099 opt_idx = findoption((char_u *)"maxmemtot");
3100 if (opt_idx >= 0)
3102 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3103 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3104 #endif
3106 #ifdef HAVE_AVAIL_MEM
3107 /* Use amount of memory available at this moment. */
3108 n = (mch_avail_mem(FALSE) >> 11);
3109 #else
3110 # ifdef HAVE_TOTAL_MEM
3111 /* Use amount of memory available to Vim. */
3112 n = (mch_total_mem(FALSE) >> 1);
3113 # else
3114 n = (0x7fffffff >> 11);
3115 # endif
3116 #endif
3117 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3118 opt_idx = findoption((char_u *)"maxmem");
3119 if (opt_idx >= 0)
3121 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3122 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3123 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3124 #endif
3125 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3130 #ifdef FEAT_GUI_W32
3131 /* force 'shortname' for Win32s */
3132 if (gui_is_win32s())
3134 opt_idx = findoption((char_u *)"shortname");
3135 if (opt_idx >= 0)
3136 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3138 #endif
3140 #ifdef FEAT_SEARCHPATH
3142 char_u *cdpath;
3143 char_u *buf;
3144 int i;
3145 int j;
3146 int mustfree = FALSE;
3148 /* Initialize the 'cdpath' option's default value. */
3149 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
3150 if (cdpath != NULL)
3152 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3153 if (buf != NULL)
3155 buf[0] = ','; /* start with ",", current dir first */
3156 j = 1;
3157 for (i = 0; cdpath[i] != NUL; ++i)
3159 if (vim_ispathlistsep(cdpath[i]))
3160 buf[j++] = ',';
3161 else
3163 if (cdpath[i] == ' ' || cdpath[i] == ',')
3164 buf[j++] = '\\';
3165 buf[j++] = cdpath[i];
3168 buf[j] = NUL;
3169 opt_idx = findoption((char_u *)"cdpath");
3170 if (opt_idx >= 0)
3172 options[opt_idx].def_val[VI_DEFAULT] = buf;
3173 options[opt_idx].flags |= P_DEF_ALLOCED;
3176 if (mustfree)
3177 vim_free(cdpath);
3180 #endif
3182 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3183 /* Set print encoding on platforms that don't default to latin1 */
3184 set_string_default("penc",
3185 # if defined(MSWIN) || defined(OS2)
3186 (char_u *)"cp1252"
3187 # else
3188 # ifdef VMS
3189 (char_u *)"dec-mcs"
3190 # else
3191 # ifdef EBCDIC
3192 (char_u *)"ebcdic-uk"
3193 # else
3194 # ifdef MAC
3195 (char_u *)"mac-roman"
3196 # else /* HPUX */
3197 (char_u *)"hp-roman8"
3198 # endif
3199 # endif
3200 # endif
3201 # endif
3203 #endif
3205 #ifdef FEAT_POSTSCRIPT
3206 /* 'printexpr' must be allocated to be able to evaluate it. */
3207 set_string_default("pexpr",
3208 # if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3209 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
3210 # else
3211 # ifdef VMS
3212 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3214 # else
3215 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3216 # endif
3217 # endif
3219 #endif
3222 * Set all the options (except the terminal options) to their default
3223 * value. Also set the global value for local options.
3225 set_options_default(0);
3227 #ifdef FEAT_GUI
3228 if (found_reverse_arg)
3229 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3230 #endif
3232 curbuf->b_p_initialized = TRUE;
3233 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3234 check_buf_options(curbuf);
3235 check_win_options(curwin);
3236 check_options();
3238 /* Must be before option_expand(), because that one needs vim_isIDc() */
3239 didset_options();
3241 #ifdef FEAT_SPELL
3242 /* Use the current chartab for the generic chartab. */
3243 init_spell_chartab();
3244 #endif
3246 #ifdef FEAT_LINEBREAK
3248 * initialize the table for 'breakat'.
3250 fill_breakat_flags();
3251 #endif
3254 * Expand environment variables and things like "~" for the defaults.
3255 * If option_expand() returns non-NULL the variable is expanded. This can
3256 * only happen for non-indirect options.
3257 * Also set the default to the expanded value, so ":set" does not list
3258 * them.
3259 * Don't set the P_ALLOCED flag, because we don't want to free the
3260 * default.
3262 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3264 if ((options[opt_idx].flags & P_GETTEXT)
3265 && options[opt_idx].var != NULL)
3266 p = (char_u *)_(*(char **)options[opt_idx].var);
3267 else
3268 p = option_expand(opt_idx, NULL);
3269 if (p != NULL && (p = vim_strsave(p)) != NULL)
3271 *(char_u **)options[opt_idx].var = p;
3272 /* VIMEXP
3273 * Defaults for all expanded options are currently the same for Vi
3274 * and Vim. When this changes, add some code here! Also need to
3275 * split P_DEF_ALLOCED in two.
3277 if (options[opt_idx].flags & P_DEF_ALLOCED)
3278 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3279 options[opt_idx].def_val[VI_DEFAULT] = p;
3280 options[opt_idx].flags |= P_DEF_ALLOCED;
3284 /* Initialize the highlight_attr[] table. */
3285 highlight_changed();
3287 save_file_ff(curbuf); /* Buffer is unchanged */
3289 /* Parse default for 'wildmode' */
3290 check_opt_wim();
3292 #if defined(FEAT_ARABIC)
3293 /* Detect use of mlterm.
3294 * Mlterm is a terminal emulator akin to xterm that has some special
3295 * abilities (bidi namely).
3296 * NOTE: mlterm's author is being asked to 'set' a variable
3297 * instead of an environment variable due to inheritance.
3299 if (mch_getenv((char_u *)"MLTERM") != NULL)
3300 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3301 #endif
3303 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3304 /* Parse default for 'fillchars'. */
3305 (void)set_chars_option(&p_fcs);
3306 #endif
3308 #ifdef FEAT_CLIPBOARD
3309 /* Parse default for 'clipboard' */
3310 (void)check_clipboard_option();
3311 #endif
3313 #ifdef FEAT_MBYTE
3314 # if defined(WIN3264) && defined(FEAT_GETTEXT)
3316 * If $LANG isn't set, try to get a good value for it. This makes the
3317 * right language be used automatically. Don't do this for English.
3319 if (mch_getenv((char_u *)"LANG") == NULL)
3321 char buf[20];
3323 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3324 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3325 * only the first two. */
3326 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3327 (LPTSTR)buf, 20);
3328 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3330 /* There are a few exceptions (probably more) */
3331 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3332 STRCPY(buf, "zh_TW");
3333 else if (STRNICMP(buf, "chs", 3) == 0
3334 || STRNICMP(buf, "zhc", 3) == 0)
3335 STRCPY(buf, "zh_CN");
3336 else if (STRNICMP(buf, "jp", 2) == 0)
3337 STRCPY(buf, "ja");
3338 else
3339 buf[2] = NUL; /* truncate to two-letter code */
3340 vim_setenv("LANG", buf);
3343 # else
3344 # ifdef MACOS_CONVERT
3345 /* Moved to os_mac_conv.c to avoid dependency problems. */
3346 mac_lang_init();
3347 # endif
3348 # endif
3350 /* enc_locale() will try to find the encoding of the current locale. */
3351 p = enc_locale();
3352 if (p != NULL)
3354 char_u *save_enc;
3356 /* Try setting 'encoding' and check if the value is valid.
3357 * If not, go back to the default "latin1". */
3358 save_enc = p_enc;
3359 p_enc = p;
3360 if (STRCMP(p_enc, "gb18030") == 0)
3362 /* We don't support "gb18030", but "cp936" is a good substitute
3363 * for practical purposes, thus use that. It's not an alias to
3364 * still support conversion between gb18030 and utf-8. */
3365 p_enc = vim_strsave((char_u *)"cp936");
3366 vim_free(p);
3368 #if defined(FEAT_GUI_MACVIM)
3369 did_mb_init = (mb_init() == NULL);
3370 if (!did_mb_init)
3372 /* The encoding returned by enc_locale() was invalid, so fall back
3373 * on using utf-8 as the default encoding in MacVim. */
3374 vim_free(p_enc);
3375 p_enc = vim_strsave((char_u *)"utf-8");
3376 did_mb_init = (mb_init() == NULL);
3379 /* did_mb_init should always be TRUE, but check just in case. */
3380 if (did_mb_init)
3381 #else
3382 if (mb_init() == NULL)
3383 #endif
3385 opt_idx = findoption((char_u *)"encoding");
3386 if (opt_idx >= 0)
3388 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3389 options[opt_idx].flags |= P_DEF_ALLOCED;
3392 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3393 || defined(VMS)
3394 if (STRCMP(p_enc, "latin1") == 0
3395 # ifdef FEAT_MBYTE
3396 || enc_utf8
3397 # endif
3400 /* Adjust the default for 'isprint' and 'iskeyword' to match
3401 * latin1. Also set the defaults for when 'nocompatible' is
3402 * set. */
3403 set_string_option_direct((char_u *)"isp", -1,
3404 ISP_LATIN1, OPT_FREE, SID_NONE);
3405 set_string_option_direct((char_u *)"isk", -1,
3406 ISK_LATIN1, OPT_FREE, SID_NONE);
3407 opt_idx = findoption((char_u *)"isp");
3408 if (opt_idx >= 0)
3409 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
3410 opt_idx = findoption((char_u *)"isk");
3411 if (opt_idx >= 0)
3412 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
3413 (void)init_chartab();
3415 #endif
3417 # if defined(WIN3264) && !defined(FEAT_GUI)
3418 /* Win32 console: When GetACP() returns a different value from
3419 * GetConsoleCP() set 'termencoding'. */
3420 if (GetACP() != GetConsoleCP())
3422 char buf[50];
3424 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3425 p_tenc = vim_strsave((char_u *)buf);
3426 if (p_tenc != NULL)
3428 opt_idx = findoption((char_u *)"termencoding");
3429 if (opt_idx >= 0)
3431 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3432 options[opt_idx].flags |= P_DEF_ALLOCED;
3434 convert_setup(&input_conv, p_tenc, p_enc);
3435 convert_setup(&output_conv, p_enc, p_tenc);
3437 else
3438 p_tenc = empty_option;
3440 # endif
3441 # if defined(WIN3264) && defined(FEAT_MBYTE)
3442 /* $HOME may have characters in active code page. */
3443 init_homedir();
3444 # endif
3446 else
3448 vim_free(p_enc);
3449 p_enc = save_enc;
3452 #endif
3454 #ifdef FEAT_MULTI_LANG
3455 /* Set the default for 'helplang'. */
3456 set_helplang_default(get_mess_lang());
3457 #endif
3461 * Set an option to its default value.
3462 * This does not take care of side effects!
3464 static void
3465 set_option_default(opt_idx, opt_flags, compatible)
3466 int opt_idx;
3467 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3468 int compatible; /* use Vi default value */
3470 char_u *varp; /* pointer to variable for current option */
3471 int dvi; /* index in def_val[] */
3472 long_u flags;
3473 long_u *flagsp;
3474 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3476 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3477 flags = options[opt_idx].flags;
3478 if (varp != NULL) /* skip hidden option, nothing to do for it */
3480 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3481 if (flags & P_STRING)
3483 /* Use set_string_option_direct() for local options to handle
3484 * freeing and allocating the value. */
3485 if (options[opt_idx].indir != PV_NONE)
3486 set_string_option_direct(NULL, opt_idx,
3487 options[opt_idx].def_val[dvi], opt_flags, 0);
3488 else
3490 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3491 free_string_option(*(char_u **)(varp));
3492 *(char_u **)varp = options[opt_idx].def_val[dvi];
3493 options[opt_idx].flags &= ~P_ALLOCED;
3496 else if (flags & P_NUM)
3498 if (options[opt_idx].indir == PV_SCROLL)
3499 win_comp_scroll(curwin);
3500 else
3502 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
3503 /* May also set global value for local option. */
3504 if (both)
3505 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3506 *(long *)varp;
3509 else /* P_BOOL */
3511 /* the cast to long is required for Manx C, long_i is needed for
3512 * MSVC */
3513 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
3514 #ifdef UNIX
3515 /* 'modeline' defaults to off for root */
3516 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3517 *(int *)varp = FALSE;
3518 #endif
3519 /* May also set global value for local option. */
3520 if (both)
3521 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3522 *(int *)varp;
3525 /* The default value is not insecure. */
3526 flagsp = insecure_flag(opt_idx, opt_flags);
3527 *flagsp = *flagsp & ~P_INSECURE;
3530 #ifdef FEAT_EVAL
3531 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
3532 #endif
3536 * Set all options (except terminal options) to their default value.
3538 static void
3539 set_options_default(opt_flags)
3540 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3542 int i;
3543 #ifdef FEAT_WINDOWS
3544 win_T *wp;
3545 tabpage_T *tp;
3546 #endif
3548 for (i = 0; !istermoption(&options[i]); i++)
3549 if (!(options[i].flags & P_NODEFAULT))
3550 set_option_default(i, opt_flags, p_cp);
3552 #ifdef FEAT_WINDOWS
3553 /* The 'scroll' option must be computed for all windows. */
3554 FOR_ALL_TAB_WINDOWS(tp, wp)
3555 win_comp_scroll(wp);
3556 #else
3557 win_comp_scroll(curwin);
3558 #endif
3562 * Set the Vi-default value of a string option.
3563 * Used for 'sh', 'backupskip' and 'term'.
3565 void
3566 set_string_default(name, val)
3567 char *name;
3568 char_u *val;
3570 char_u *p;
3571 int opt_idx;
3573 p = vim_strsave(val);
3574 if (p != NULL) /* we don't want a NULL */
3576 opt_idx = findoption((char_u *)name);
3577 if (opt_idx >= 0)
3579 if (options[opt_idx].flags & P_DEF_ALLOCED)
3580 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3581 options[opt_idx].def_val[VI_DEFAULT] = p;
3582 options[opt_idx].flags |= P_DEF_ALLOCED;
3588 * Set the Vi-default value of a number option.
3589 * Used for 'lines' and 'columns'.
3591 void
3592 set_number_default(name, val)
3593 char *name;
3594 long val;
3596 int opt_idx;
3598 opt_idx = findoption((char_u *)name);
3599 if (opt_idx >= 0)
3600 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3603 #if defined(EXITFREE) || defined(PROTO)
3605 * Free all options.
3607 void
3608 free_all_options()
3610 int i;
3612 for (i = 0; !istermoption(&options[i]); i++)
3614 if (options[i].indir == PV_NONE)
3616 /* global option: free value and default value. */
3617 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3618 free_string_option(*(char_u **)options[i].var);
3619 if (options[i].flags & P_DEF_ALLOCED)
3620 free_string_option(options[i].def_val[VI_DEFAULT]);
3622 else if (options[i].var != VAR_WIN
3623 && (options[i].flags & P_STRING))
3624 /* buffer-local option: free global value */
3625 free_string_option(*(char_u **)options[i].var);
3628 #endif
3632 * Initialize the options, part two: After getting Rows and Columns and
3633 * setting 'term'.
3635 void
3636 set_init_2()
3638 int idx;
3641 * 'scroll' defaults to half the window height. Note that this default is
3642 * wrong when the window height changes.
3644 set_number_default("scroll", (long)((long_u)Rows >> 1));
3645 idx = findoption((char_u *)"scroll");
3646 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3647 set_option_default(idx, OPT_LOCAL, p_cp);
3648 comp_col();
3651 * 'window' is only for backwards compatibility with Vi.
3652 * Default is Rows - 1.
3654 if (!option_was_set((char_u *)"window"))
3655 p_window = Rows - 1;
3656 set_number_default("window", Rows - 1);
3658 /* For DOS console the default is always black. */
3659 #if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3661 * If 'background' wasn't set by the user, try guessing the value,
3662 * depending on the terminal name. Only need to check for terminals
3663 * with a dark background, that can handle color.
3665 idx = findoption((char_u *)"bg");
3666 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3667 && *term_bg_default() == 'd')
3669 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
3670 /* don't mark it as set, when starting the GUI it may be
3671 * changed again */
3672 options[idx].flags &= ~P_WAS_SET;
3674 #endif
3676 #ifdef CURSOR_SHAPE
3677 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3678 #endif
3679 #ifdef FEAT_MOUSESHAPE
3680 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3681 #endif
3682 #ifdef FEAT_PRINTER
3683 (void)parse_printoptions(); /* parse 'printoptions' default value */
3684 #endif
3688 * Return "dark" or "light" depending on the kind of terminal.
3689 * This is just guessing! Recognized are:
3690 * "linux" Linux console
3691 * "screen.linux" Linux console with screen
3692 * "cygwin" Cygwin shell
3693 * "putty" Putty program
3694 * We also check the COLORFGBG environment variable, which is set by
3695 * rxvt and derivatives. This variable contains either two or three
3696 * values separated by semicolons; we want the last value in either
3697 * case. If this value is 0-6 or 8, our background is dark.
3699 static char_u *
3700 term_bg_default()
3702 #if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3703 /* DOS console nearly always black */
3704 return (char_u *)"dark";
3705 #else
3706 char_u *p;
3708 if (STRCMP(T_NAME, "linux") == 0
3709 || STRCMP(T_NAME, "screen.linux") == 0
3710 || STRCMP(T_NAME, "cygwin") == 0
3711 || STRCMP(T_NAME, "putty") == 0
3712 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3713 && (p = vim_strrchr(p, ';')) != NULL
3714 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3715 && p[2] == NUL))
3716 return (char_u *)"dark";
3717 return (char_u *)"light";
3718 #endif
3722 * Initialize the options, part three: After reading the .vimrc
3724 void
3725 set_init_3()
3727 #if defined(UNIX) || defined(OS2) || defined(WIN3264)
3729 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3730 * This is done after other initializations, where 'shell' might have been
3731 * set, but only if they have not been set before.
3733 char_u *p;
3734 int idx_srr;
3735 int do_srr;
3736 #ifdef FEAT_QUICKFIX
3737 int idx_sp;
3738 int do_sp;
3739 #endif
3741 idx_srr = findoption((char_u *)"srr");
3742 if (idx_srr < 0)
3743 do_srr = FALSE;
3744 else
3745 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3746 #ifdef FEAT_QUICKFIX
3747 idx_sp = findoption((char_u *)"sp");
3748 if (idx_sp < 0)
3749 do_sp = FALSE;
3750 else
3751 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3752 #endif
3755 * Isolate the name of the shell:
3756 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3757 * - Remove any argument. E.g., "csh -f" -> "csh".
3759 p = gettail(p_sh);
3760 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3761 if (p != NULL)
3764 * Default for p_sp is "| tee", for p_srr is ">".
3765 * For known shells it is changed here to include stderr.
3767 if ( fnamecmp(p, "csh") == 0
3768 || fnamecmp(p, "tcsh") == 0
3769 # if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3770 || fnamecmp(p, "csh.exe") == 0
3771 || fnamecmp(p, "tcsh.exe") == 0
3772 # endif
3775 #if defined(FEAT_QUICKFIX)
3776 if (do_sp)
3778 # ifdef WIN3264
3779 p_sp = (char_u *)">&";
3780 # else
3781 p_sp = (char_u *)"|& tee";
3782 # endif
3783 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3785 #endif
3786 if (do_srr)
3788 p_srr = (char_u *)">&";
3789 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3792 else
3793 # ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3794 if ( fnamecmp(p, "sh") == 0
3795 || fnamecmp(p, "ksh") == 0
3796 || fnamecmp(p, "zsh") == 0
3797 || fnamecmp(p, "zsh-beta") == 0
3798 || fnamecmp(p, "bash") == 0
3799 # ifdef WIN3264
3800 || fnamecmp(p, "cmd") == 0
3801 || fnamecmp(p, "sh.exe") == 0
3802 || fnamecmp(p, "ksh.exe") == 0
3803 || fnamecmp(p, "zsh.exe") == 0
3804 || fnamecmp(p, "zsh-beta.exe") == 0
3805 || fnamecmp(p, "bash.exe") == 0
3806 || fnamecmp(p, "cmd.exe") == 0
3807 # endif
3809 # endif
3811 #if defined(FEAT_QUICKFIX)
3812 if (do_sp)
3814 # ifdef WIN3264
3815 p_sp = (char_u *)">%s 2>&1";
3816 # else
3817 p_sp = (char_u *)"2>&1| tee";
3818 # endif
3819 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3821 #endif
3822 if (do_srr)
3824 p_srr = (char_u *)">%s 2>&1";
3825 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3828 vim_free(p);
3830 #endif
3832 #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3834 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3835 * This is done after other initializations, where 'shell' might have been
3836 * set, but only if they have not been set before. Default for p_shcf is
3837 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3838 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3839 * command.com. And for Win32 we need to set p_sxq instead.
3841 if (strstr((char *)gettail(p_sh), "sh") != NULL)
3843 int idx3;
3845 idx3 = findoption((char_u *)"shcf");
3846 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3848 p_shcf = (char_u *)"-c";
3849 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3852 # ifndef DJGPP
3853 # ifdef WIN3264
3854 /* Somehow Win32 requires the quotes around the redirection too */
3855 idx3 = findoption((char_u *)"sxq");
3856 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3858 p_sxq = (char_u *)"\"";
3859 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3861 # else
3862 idx3 = findoption((char_u *)"shq");
3863 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3865 p_shq = (char_u *)"\"";
3866 options[idx3].def_val[VI_DEFAULT] = p_shq;
3868 # endif
3869 # endif
3871 #endif
3873 #ifdef FEAT_TITLE
3874 set_title_defaults();
3875 #endif
3878 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
3880 * When 'helplang' is still at its default value, set it to "lang".
3881 * Only the first two characters of "lang" are used.
3883 void
3884 set_helplang_default(lang)
3885 char_u *lang;
3887 int idx;
3889 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3890 return;
3891 idx = findoption((char_u *)"hlg");
3892 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3894 if (options[idx].flags & P_ALLOCED)
3895 free_string_option(p_hlg);
3896 p_hlg = vim_strsave(lang);
3897 if (p_hlg == NULL)
3898 p_hlg = empty_option;
3899 else
3901 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3902 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3904 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3905 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3907 p_hlg[2] = NUL;
3909 options[idx].flags |= P_ALLOCED;
3912 #endif
3914 #ifdef FEAT_GUI
3915 static char_u *gui_bg_default __ARGS((void));
3917 static char_u *
3918 gui_bg_default()
3920 if (gui_get_lightness(gui.back_pixel) < 127)
3921 return (char_u *)"dark";
3922 return (char_u *)"light";
3926 * Option initializations that can only be done after opening the GUI window.
3928 void
3929 init_gui_options()
3931 /* Set the 'background' option according to the lightness of the
3932 * background color, unless the user has set it already. */
3933 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3935 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3936 highlight_changed();
3939 #endif
3941 #ifdef FEAT_TITLE
3943 * 'title' and 'icon' only default to true if they have not been set or reset
3944 * in .vimrc and we can read the old value.
3945 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3946 * they can be reset. This reduces startup time when using X on a remote
3947 * machine.
3949 void
3950 set_title_defaults()
3952 int idx1;
3953 long val;
3956 * If GUI is (going to be) used, we can always set the window title and
3957 * icon name. Saves a bit of time, because the X11 display server does
3958 * not need to be contacted.
3960 idx1 = findoption((char_u *)"title");
3961 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
3963 #ifdef FEAT_GUI
3964 if (gui.starting || gui.in_use)
3965 val = TRUE;
3966 else
3967 #endif
3968 val = mch_can_restore_title();
3969 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3970 p_title = val;
3972 idx1 = findoption((char_u *)"icon");
3973 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
3975 #ifdef FEAT_GUI
3976 if (gui.starting || gui.in_use)
3977 val = TRUE;
3978 else
3979 #endif
3980 val = mch_can_restore_icon();
3981 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3982 p_icon = val;
3985 #endif
3988 * Parse 'arg' for option settings.
3990 * 'arg' may be IObuff, but only when no errors can be present and option
3991 * does not need to be expanded with option_expand().
3992 * "opt_flags":
3993 * 0 for ":set"
3994 * OPT_GLOBAL for ":setglobal"
3995 * OPT_LOCAL for ":setlocal" and a modeline
3996 * OPT_MODELINE for a modeline
3997 * OPT_WINONLY to only set window-local options
3998 * OPT_NOWIN to skip setting window-local options
4000 * returns FAIL if an error is detected, OK otherwise
4003 do_set(arg, opt_flags)
4004 char_u *arg; /* option string (may be written to!) */
4005 int opt_flags;
4007 int opt_idx;
4008 char_u *errmsg;
4009 char_u errbuf[80];
4010 char_u *startarg;
4011 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4012 int nextchar; /* next non-white char after option name */
4013 int afterchar; /* character just after option name */
4014 int len;
4015 int i;
4016 long value;
4017 int key;
4018 long_u flags; /* flags for current option */
4019 char_u *varp = NULL; /* pointer to variable for current option */
4020 int did_show = FALSE; /* already showed one value */
4021 int adding; /* "opt+=arg" */
4022 int prepending; /* "opt^=arg" */
4023 int removing; /* "opt-=arg" */
4024 int cp_val = 0;
4025 char_u key_name[2];
4027 if (*arg == NUL)
4029 showoptions(0, opt_flags);
4030 did_show = TRUE;
4031 goto theend;
4034 while (*arg != NUL) /* loop to process all options */
4036 errmsg = NULL;
4037 startarg = arg; /* remember for error message */
4039 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4040 && !(opt_flags & OPT_MODELINE))
4043 * ":set all" show all options.
4044 * ":set all&" set all options to their default value.
4046 arg += 3;
4047 if (*arg == '&')
4049 ++arg;
4050 /* Only for :set command set global value of local options. */
4051 set_options_default(OPT_FREE | opt_flags);
4053 else
4055 showoptions(1, opt_flags);
4056 did_show = TRUE;
4059 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
4061 showoptions(2, opt_flags);
4062 show_termcodes();
4063 did_show = TRUE;
4064 arg += 7;
4066 else
4068 prefix = 1;
4069 if (STRNCMP(arg, "no", 2) == 0)
4071 prefix = 0;
4072 arg += 2;
4074 else if (STRNCMP(arg, "inv", 3) == 0)
4076 prefix = 2;
4077 arg += 3;
4080 /* find end of name */
4081 key = 0;
4082 if (*arg == '<')
4084 nextchar = 0;
4085 opt_idx = -1;
4086 /* look out for <t_>;> */
4087 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4088 len = 5;
4089 else
4091 len = 1;
4092 while (arg[len] != NUL && arg[len] != '>')
4093 ++len;
4095 if (arg[len] != '>')
4097 errmsg = e_invarg;
4098 goto skip;
4100 arg[len] = NUL; /* put NUL after name */
4101 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4102 opt_idx = findoption(arg + 1);
4103 arg[len++] = '>'; /* restore '>' */
4104 if (opt_idx == -1)
4105 key = find_key_option(arg + 1);
4107 else
4109 len = 0;
4111 * The two characters after "t_" may not be alphanumeric.
4113 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4114 len = 4;
4115 else
4116 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4117 ++len;
4118 nextchar = arg[len];
4119 arg[len] = NUL; /* put NUL after name */
4120 opt_idx = findoption(arg);
4121 arg[len] = nextchar; /* restore nextchar */
4122 if (opt_idx == -1)
4123 key = find_key_option(arg);
4126 /* remember character after option name */
4127 afterchar = arg[len];
4129 /* skip white space, allow ":set ai ?" */
4130 while (vim_iswhite(arg[len]))
4131 ++len;
4133 adding = FALSE;
4134 prepending = FALSE;
4135 removing = FALSE;
4136 if (arg[len] != NUL && arg[len + 1] == '=')
4138 if (arg[len] == '+')
4140 adding = TRUE; /* "+=" */
4141 ++len;
4143 else if (arg[len] == '^')
4145 prepending = TRUE; /* "^=" */
4146 ++len;
4148 else if (arg[len] == '-')
4150 removing = TRUE; /* "-=" */
4151 ++len;
4154 nextchar = arg[len];
4156 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4158 errmsg = (char_u *)N_("E518: Unknown option");
4159 goto skip;
4162 if (opt_idx >= 0)
4164 if (options[opt_idx].var == NULL) /* hidden option: skip */
4166 /* Only give an error message when requesting the value of
4167 * a hidden option, ignore setting it. */
4168 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4169 && (!(options[opt_idx].flags & P_BOOL)
4170 || nextchar == '?'))
4171 errmsg = (char_u *)N_("E519: Option not supported");
4172 goto skip;
4175 flags = options[opt_idx].flags;
4176 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4178 else
4180 flags = P_STRING;
4181 if (key < 0)
4183 key_name[0] = KEY2TERMCAP0(key);
4184 key_name[1] = KEY2TERMCAP1(key);
4186 else
4188 key_name[0] = KS_KEY;
4189 key_name[1] = (key & 0xff);
4193 /* Skip all options that are not window-local (used when showing
4194 * an already loaded buffer in a window). */
4195 if ((opt_flags & OPT_WINONLY)
4196 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4197 goto skip;
4199 /* Skip all options that are window-local (used for :vimgrep). */
4200 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4201 && options[opt_idx].var == VAR_WIN)
4202 goto skip;
4204 /* Disallow changing some options from modelines. */
4205 if (opt_flags & OPT_MODELINE)
4207 if (flags & P_SECURE)
4209 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4210 goto skip;
4212 #ifdef FEAT_DIFF
4213 /* In diff mode some options are overruled. This avoids that
4214 * 'foldmethod' becomes "marker" instead of "diff" and that
4215 * "wrap" gets set. */
4216 if (curwin->w_p_diff
4217 && (options[opt_idx].indir == PV_FDM
4218 || options[opt_idx].indir == PV_WRAP))
4219 goto skip;
4220 #endif
4223 #ifdef HAVE_SANDBOX
4224 /* Disallow changing some options in the sandbox */
4225 if (sandbox != 0 && (flags & P_SECURE))
4227 errmsg = (char_u *)_(e_sandbox);
4228 goto skip;
4230 #endif
4232 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4234 arg += len;
4235 cp_val = p_cp;
4236 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4238 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4240 cp_val = FALSE;
4241 arg += 3;
4243 else /* "opt&vi": set to Vi default */
4245 cp_val = TRUE;
4246 arg += 2;
4249 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4250 && arg[1] != NUL && !vim_iswhite(arg[1]))
4252 errmsg = e_trailing;
4253 goto skip;
4258 * allow '=' and ':' as MSDOS command.com allows only one
4259 * '=' character per "set" command line. grrr. (jw)
4261 if (nextchar == '?'
4262 || (prefix == 1
4263 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4264 && !(flags & P_BOOL)))
4267 * print value
4269 if (did_show)
4270 msg_putchar('\n'); /* cursor below last one */
4271 else
4273 gotocmdline(TRUE); /* cursor at status line */
4274 did_show = TRUE; /* remember that we did a line */
4276 if (opt_idx >= 0)
4278 showoneopt(&options[opt_idx], opt_flags);
4279 #ifdef FEAT_EVAL
4280 if (p_verbose > 0)
4282 /* Mention where the option was last set. */
4283 if (varp == options[opt_idx].var)
4284 last_set_msg(options[opt_idx].scriptID);
4285 else if ((int)options[opt_idx].indir & PV_WIN)
4286 last_set_msg(curwin->w_p_scriptID[
4287 (int)options[opt_idx].indir & PV_MASK]);
4288 else if ((int)options[opt_idx].indir & PV_BUF)
4289 last_set_msg(curbuf->b_p_scriptID[
4290 (int)options[opt_idx].indir & PV_MASK]);
4292 #endif
4294 else
4296 char_u *p;
4298 p = find_termcode(key_name);
4299 if (p == NULL)
4301 errmsg = (char_u *)N_("E518: Unknown option");
4302 goto skip;
4304 else
4305 (void)show_one_termcode(key_name, p, TRUE);
4307 if (nextchar != '?'
4308 && nextchar != NUL && !vim_iswhite(afterchar))
4309 errmsg = e_trailing;
4311 else
4313 if (flags & P_BOOL) /* boolean */
4315 if (nextchar == '=' || nextchar == ':')
4317 errmsg = e_invarg;
4318 goto skip;
4322 * ":set opt!": invert
4323 * ":set opt&": reset to default value
4324 * ":set opt<": reset to global value
4326 if (nextchar == '!')
4327 value = *(int *)(varp) ^ 1;
4328 else if (nextchar == '&')
4329 value = (int)(long)(long_i)options[opt_idx].def_val[
4330 ((flags & P_VI_DEF) || cp_val)
4331 ? VI_DEFAULT : VIM_DEFAULT];
4332 else if (nextchar == '<')
4334 /* For 'autoread' -1 means to use global value. */
4335 if ((int *)varp == &curbuf->b_p_ar
4336 && opt_flags == OPT_LOCAL)
4337 value = -1;
4338 else
4339 value = *(int *)get_varp_scope(&(options[opt_idx]),
4340 OPT_GLOBAL);
4342 else
4345 * ":set invopt": invert
4346 * ":set opt" or ":set noopt": set or reset
4348 if (nextchar != NUL && !vim_iswhite(afterchar))
4350 errmsg = e_trailing;
4351 goto skip;
4353 if (prefix == 2) /* inv */
4354 value = *(int *)(varp) ^ 1;
4355 else
4356 value = prefix;
4359 errmsg = set_bool_option(opt_idx, varp, (int)value,
4360 opt_flags);
4362 else /* numeric or string */
4364 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4365 || prefix != 1)
4367 errmsg = e_invarg;
4368 goto skip;
4371 if (flags & P_NUM) /* numeric */
4374 * Different ways to set a number option:
4375 * & set to default value
4376 * < set to global value
4377 * <xx> accept special key codes for 'wildchar'
4378 * c accept any non-digit for 'wildchar'
4379 * [-]0-9 set number
4380 * other error
4382 ++arg;
4383 if (nextchar == '&')
4384 value = (long)(long_i)options[opt_idx].def_val[
4385 ((flags & P_VI_DEF) || cp_val)
4386 ? VI_DEFAULT : VIM_DEFAULT];
4387 else if (nextchar == '<')
4388 value = *(long *)get_varp_scope(&(options[opt_idx]),
4389 OPT_GLOBAL);
4390 else if (((long *)varp == &p_wc
4391 || (long *)varp == &p_wcm)
4392 && (*arg == '<'
4393 || *arg == '^'
4394 || ((!arg[1] || vim_iswhite(arg[1]))
4395 && !VIM_ISDIGIT(*arg))))
4397 value = string_to_key(arg);
4398 if (value == 0 && (long *)varp != &p_wcm)
4400 errmsg = e_invarg;
4401 goto skip;
4404 /* allow negative numbers (for 'undolevels') */
4405 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4407 i = 0;
4408 if (*arg == '-')
4409 i = 1;
4410 #ifdef HAVE_STRTOL
4411 value = strtol((char *)arg, NULL, 0);
4412 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4413 i += 2;
4414 #else
4415 value = atol((char *)arg);
4416 #endif
4417 while (VIM_ISDIGIT(arg[i]))
4418 ++i;
4419 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4421 errmsg = e_invarg;
4422 goto skip;
4425 else
4427 errmsg = (char_u *)N_("E521: Number required after =");
4428 goto skip;
4431 if (adding)
4432 value = *(long *)varp + value;
4433 if (prepending)
4434 value = *(long *)varp * value;
4435 if (removing)
4436 value = *(long *)varp - value;
4437 errmsg = set_num_option(opt_idx, varp, value,
4438 errbuf, sizeof(errbuf), opt_flags);
4440 else if (opt_idx >= 0) /* string */
4442 char_u *save_arg = NULL;
4443 char_u *s = NULL;
4444 char_u *oldval; /* previous value if *varp */
4445 char_u *newval;
4446 char_u *origval;
4447 unsigned newlen;
4448 int comma;
4449 int bs;
4450 int new_value_alloced; /* new string option
4451 was allocated */
4453 /* When using ":set opt=val" for a global option
4454 * with a local value the local value will be
4455 * reset, use the global value here. */
4456 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4457 && ((int)options[opt_idx].indir & PV_BOTH))
4458 varp = options[opt_idx].var;
4460 /* The old value is kept until we are sure that the
4461 * new value is valid. */
4462 oldval = *(char_u **)varp;
4463 if (nextchar == '&') /* set to default val */
4465 newval = options[opt_idx].def_val[
4466 ((flags & P_VI_DEF) || cp_val)
4467 ? VI_DEFAULT : VIM_DEFAULT];
4468 if ((char_u **)varp == &p_bg)
4470 /* guess the value of 'background' */
4471 #ifdef FEAT_GUI
4472 if (gui.in_use)
4473 newval = gui_bg_default();
4474 else
4475 #endif
4476 newval = term_bg_default();
4479 /* expand environment variables and ~ (since the
4480 * default value was already expanded, only
4481 * required when an environment variable was set
4482 * later */
4483 if (newval == NULL)
4484 newval = empty_option;
4485 else
4487 s = option_expand(opt_idx, newval);
4488 if (s == NULL)
4489 s = newval;
4490 newval = vim_strsave(s);
4492 new_value_alloced = TRUE;
4494 else if (nextchar == '<') /* set to global val */
4496 newval = vim_strsave(*(char_u **)get_varp_scope(
4497 &(options[opt_idx]), OPT_GLOBAL));
4498 new_value_alloced = TRUE;
4500 else
4502 ++arg; /* jump to after the '=' or ':' */
4505 * Set 'keywordprg' to ":help" if an empty
4506 * value was passed to :set by the user.
4507 * Misuse errbuf[] for the resulting string.
4509 if (varp == (char_u *)&p_kp
4510 && (*arg == NUL || *arg == ' '))
4512 STRCPY(errbuf, ":help");
4513 save_arg = arg;
4514 arg = errbuf;
4517 * Convert 'whichwrap' number to string, for
4518 * backwards compatibility with Vim 3.0.
4519 * Misuse errbuf[] for the resulting string.
4521 else if (varp == (char_u *)&p_ww
4522 && VIM_ISDIGIT(*arg))
4524 *errbuf = NUL;
4525 i = getdigits(&arg);
4526 if (i & 1)
4527 STRCAT(errbuf, "b,");
4528 if (i & 2)
4529 STRCAT(errbuf, "s,");
4530 if (i & 4)
4531 STRCAT(errbuf, "h,l,");
4532 if (i & 8)
4533 STRCAT(errbuf, "<,>,");
4534 if (i & 16)
4535 STRCAT(errbuf, "[,],");
4536 if (*errbuf != NUL) /* remove trailing , */
4537 errbuf[STRLEN(errbuf) - 1] = NUL;
4538 save_arg = arg;
4539 arg = errbuf;
4542 * Remove '>' before 'dir' and 'bdir', for
4543 * backwards compatibility with version 3.0
4545 else if ( *arg == '>'
4546 && (varp == (char_u *)&p_dir
4547 || varp == (char_u *)&p_bdir))
4549 ++arg;
4552 /* When setting the local value of a global
4553 * option, the old value may be the global value. */
4554 if (((int)options[opt_idx].indir & PV_BOTH)
4555 && (opt_flags & OPT_LOCAL))
4556 origval = *(char_u **)get_varp(
4557 &options[opt_idx]);
4558 else
4559 origval = oldval;
4562 * Copy the new string into allocated memory.
4563 * Can't use set_string_option_direct(), because
4564 * we need to remove the backslashes.
4566 /* get a bit too much */
4567 newlen = (unsigned)STRLEN(arg) + 1;
4568 if (adding || prepending || removing)
4569 newlen += (unsigned)STRLEN(origval) + 1;
4570 newval = alloc(newlen);
4571 if (newval == NULL) /* out of mem, don't change */
4572 break;
4573 s = newval;
4576 * Copy the string, skip over escaped chars.
4577 * For MS-DOS and WIN32 backslashes before normal
4578 * file name characters are not removed, and keep
4579 * backslash at start, for "\\machine\path", but
4580 * do remove it for "\\\\machine\\path".
4581 * The reverse is found in ExpandOldSetting().
4583 while (*arg && !vim_iswhite(*arg))
4585 if (*arg == '\\' && arg[1] != NUL
4586 #ifdef BACKSLASH_IN_FILENAME
4587 && !((flags & P_EXPAND)
4588 && vim_isfilec(arg[1])
4589 && (arg[1] != '\\'
4590 || (s == newval
4591 && arg[2] != '\\')))
4592 #endif
4594 ++arg; /* remove backslash */
4595 #ifdef FEAT_MBYTE
4596 if (has_mbyte
4597 && (i = (*mb_ptr2len)(arg)) > 1)
4599 /* copy multibyte char */
4600 mch_memmove(s, arg, (size_t)i);
4601 arg += i;
4602 s += i;
4604 else
4605 #endif
4606 *s++ = *arg++;
4608 *s = NUL;
4611 * Expand environment variables and ~.
4612 * Don't do it when adding without inserting a
4613 * comma.
4615 if (!(adding || prepending || removing)
4616 || (flags & P_COMMA))
4618 s = option_expand(opt_idx, newval);
4619 if (s != NULL)
4621 vim_free(newval);
4622 newlen = (unsigned)STRLEN(s) + 1;
4623 if (adding || prepending || removing)
4624 newlen += (unsigned)STRLEN(origval) + 1;
4625 newval = alloc(newlen);
4626 if (newval == NULL)
4627 break;
4628 STRCPY(newval, s);
4632 /* locate newval[] in origval[] when removing it
4633 * and when adding to avoid duplicates */
4634 i = 0; /* init for GCC */
4635 if (removing || (flags & P_NODUP))
4637 i = (int)STRLEN(newval);
4638 bs = 0;
4639 for (s = origval; *s; ++s)
4641 if ((!(flags & P_COMMA)
4642 || s == origval
4643 || (s[-1] == ',' && !(bs & 1)))
4644 && STRNCMP(s, newval, i) == 0
4645 && (!(flags & P_COMMA)
4646 || s[i] == ','
4647 || s[i] == NUL))
4648 break;
4649 /* Count backspaces. Only a comma with an
4650 * even number of backspaces before it is
4651 * recognized as a separator */
4652 if (s > origval && s[-1] == '\\')
4653 ++bs;
4654 else
4655 bs = 0;
4658 /* do not add if already there */
4659 if ((adding || prepending) && *s)
4661 prepending = FALSE;
4662 adding = FALSE;
4663 STRCPY(newval, origval);
4667 /* concatenate the two strings; add a ',' if
4668 * needed */
4669 if (adding || prepending)
4671 comma = ((flags & P_COMMA) && *origval != NUL
4672 && *newval != NUL);
4673 if (adding)
4675 i = (int)STRLEN(origval);
4676 mch_memmove(newval + i + comma, newval,
4677 STRLEN(newval) + 1);
4678 mch_memmove(newval, origval, (size_t)i);
4680 else
4682 i = (int)STRLEN(newval);
4683 STRMOVE(newval + i + comma, origval);
4685 if (comma)
4686 newval[i] = ',';
4689 /* Remove newval[] from origval[]. (Note: "i" has
4690 * been set above and is used here). */
4691 if (removing)
4693 STRCPY(newval, origval);
4694 if (*s)
4696 /* may need to remove a comma */
4697 if (flags & P_COMMA)
4699 if (s == origval)
4701 /* include comma after string */
4702 if (s[i] == ',')
4703 ++i;
4705 else
4707 /* include comma before string */
4708 --s;
4709 ++i;
4712 STRMOVE(newval + (s - origval), s + i);
4716 if (flags & P_FLAGLIST)
4718 /* Remove flags that appear twice. */
4719 for (s = newval; *s; ++s)
4720 if ((!(flags & P_COMMA) || *s != ',')
4721 && vim_strchr(s + 1, *s) != NULL)
4723 STRMOVE(s, s + 1);
4724 --s;
4728 if (save_arg != NULL) /* number for 'whichwrap' */
4729 arg = save_arg;
4730 new_value_alloced = TRUE;
4733 /* Set the new value. */
4734 *(char_u **)(varp) = newval;
4736 /* Handle side effects, and set the global value for
4737 * ":set" on local options. */
4738 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4739 new_value_alloced, oldval, errbuf, opt_flags);
4741 /* If error detected, print the error message. */
4742 if (errmsg != NULL)
4743 goto skip;
4745 else /* key code option */
4747 char_u *p;
4749 if (nextchar == '&')
4751 if (add_termcap_entry(key_name, TRUE) == FAIL)
4752 errmsg = (char_u *)N_("E522: Not found in termcap");
4754 else
4756 ++arg; /* jump to after the '=' or ':' */
4757 for (p = arg; *p && !vim_iswhite(*p); ++p)
4758 if (*p == '\\' && p[1] != NUL)
4759 ++p;
4760 nextchar = *p;
4761 *p = NUL;
4762 add_termcode(key_name, arg, FALSE);
4763 *p = nextchar;
4765 if (full_screen)
4766 ttest(FALSE);
4767 redraw_all_later(CLEAR);
4771 if (opt_idx >= 0)
4772 did_set_option(opt_idx, opt_flags,
4773 !prepending && !adding && !removing);
4776 skip:
4778 * Advance to next argument.
4779 * - skip until a blank found, taking care of backslashes
4780 * - skip blanks
4781 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4783 for (i = 0; i < 2 ; ++i)
4785 while (*arg != NUL && !vim_iswhite(*arg))
4786 if (*arg++ == '\\' && *arg != NUL)
4787 ++arg;
4788 arg = skipwhite(arg);
4789 if (*arg != '=')
4790 break;
4794 if (errmsg != NULL)
4796 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
4797 i = (int)STRLEN(IObuff) + 2;
4798 if (i + (arg - startarg) < IOSIZE)
4800 /* append the argument with the error */
4801 STRCAT(IObuff, ": ");
4802 mch_memmove(IObuff + i, startarg, (arg - startarg));
4803 IObuff[i + (arg - startarg)] = NUL;
4805 /* make sure all characters are printable */
4806 trans_characters(IObuff, IOSIZE);
4808 ++no_wait_return; /* wait_return done later */
4809 emsg(IObuff); /* show error highlighted */
4810 --no_wait_return;
4812 return FAIL;
4815 arg = skipwhite(arg);
4818 theend:
4819 if (silent_mode && did_show)
4821 /* After displaying option values in silent mode. */
4822 silent_mode = FALSE;
4823 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4824 msg_putchar('\n');
4825 cursor_on(); /* msg_start() switches it off */
4826 out_flush();
4827 silent_mode = TRUE;
4828 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4831 return OK;
4835 * Call this when an option has been given a new value through a user command.
4836 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4838 static void
4839 did_set_option(opt_idx, opt_flags, new_value)
4840 int opt_idx;
4841 int opt_flags; /* possibly with OPT_MODELINE */
4842 int new_value; /* value was replaced completely */
4844 long_u *p;
4846 options[opt_idx].flags |= P_WAS_SET;
4848 /* When an option is set in the sandbox, from a modeline or in secure mode
4849 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
4850 * flag. */
4851 p = insecure_flag(opt_idx, opt_flags);
4852 if (secure
4853 #ifdef HAVE_SANDBOX
4854 || sandbox != 0
4855 #endif
4856 || (opt_flags & OPT_MODELINE))
4857 *p = *p | P_INSECURE;
4858 else if (new_value)
4859 *p = *p & ~P_INSECURE;
4862 static char_u *
4863 illegal_char(errbuf, c)
4864 char_u *errbuf;
4865 int c;
4867 if (errbuf == NULL)
4868 return (char_u *)"";
4869 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
4870 (char *)transchar(c));
4871 return errbuf;
4875 * Convert a key name or string into a key value.
4876 * Used for 'wildchar' and 'cedit' options.
4878 static int
4879 string_to_key(arg)
4880 char_u *arg;
4882 if (*arg == '<')
4883 return find_key_option(arg + 1);
4884 if (*arg == '^')
4885 return Ctrl_chr(arg[1]);
4886 return *arg;
4889 #ifdef FEAT_CMDWIN
4891 * Check value of 'cedit' and set cedit_key.
4892 * Returns NULL if value is OK, error message otherwise.
4894 static char_u *
4895 check_cedit()
4897 int n;
4899 if (*p_cedit == NUL)
4900 cedit_key = -1;
4901 else
4903 n = string_to_key(p_cedit);
4904 if (vim_isprintc(n))
4905 return e_invarg;
4906 cedit_key = n;
4908 return NULL;
4910 #endif
4912 #ifdef FEAT_TITLE
4914 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4915 * maketitle() to create and display it.
4916 * When switching the title or icon off, call mch_restore_title() to get
4917 * the old value back.
4919 static void
4920 did_set_title(icon)
4921 int icon; /* Did set icon instead of title */
4923 if (starting != NO_SCREEN
4924 #ifdef FEAT_GUI
4925 && !gui.starting
4926 #endif
4929 maketitle();
4930 if (icon)
4932 if (!p_icon)
4933 mch_restore_title(2);
4935 else
4937 if (!p_title)
4938 mch_restore_title(1);
4942 #endif
4945 * set_options_bin - called when 'bin' changes value.
4947 void
4948 set_options_bin(oldval, newval, opt_flags)
4949 int oldval;
4950 int newval;
4951 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4954 * The option values that are changed when 'bin' changes are
4955 * copied when 'bin is set and restored when 'bin' is reset.
4957 if (newval)
4959 if (!oldval) /* switched on */
4961 if (!(opt_flags & OPT_GLOBAL))
4963 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4964 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4965 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4966 curbuf->b_p_et_nobin = curbuf->b_p_et;
4968 if (!(opt_flags & OPT_LOCAL))
4970 p_tw_nobin = p_tw;
4971 p_wm_nobin = p_wm;
4972 p_ml_nobin = p_ml;
4973 p_et_nobin = p_et;
4977 if (!(opt_flags & OPT_GLOBAL))
4979 curbuf->b_p_tw = 0; /* no automatic line wrap */
4980 curbuf->b_p_wm = 0; /* no automatic line wrap */
4981 curbuf->b_p_ml = 0; /* no modelines */
4982 curbuf->b_p_et = 0; /* no expandtab */
4984 if (!(opt_flags & OPT_LOCAL))
4986 p_tw = 0;
4987 p_wm = 0;
4988 p_ml = FALSE;
4989 p_et = FALSE;
4990 p_bin = TRUE; /* needed when called for the "-b" argument */
4993 else if (oldval) /* switched off */
4995 if (!(opt_flags & OPT_GLOBAL))
4997 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4998 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4999 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5000 curbuf->b_p_et = curbuf->b_p_et_nobin;
5002 if (!(opt_flags & OPT_LOCAL))
5004 p_tw = p_tw_nobin;
5005 p_wm = p_wm_nobin;
5006 p_ml = p_ml_nobin;
5007 p_et = p_et_nobin;
5012 #ifdef FEAT_VIMINFO
5014 * Find the parameter represented by the given character (eg ', :, ", or /),
5015 * and return its associated value in the 'viminfo' string.
5016 * Only works for number parameters, not for 'r' or 'n'.
5017 * If the parameter is not specified in the string or there is no following
5018 * number, return -1.
5021 get_viminfo_parameter(type)
5022 int type;
5024 char_u *p;
5026 p = find_viminfo_parameter(type);
5027 if (p != NULL && VIM_ISDIGIT(*p))
5028 return atoi((char *)p);
5029 return -1;
5033 * Find the parameter represented by the given character (eg ''', ':', '"', or
5034 * '/') in the 'viminfo' option and return a pointer to the string after it.
5035 * Return NULL if the parameter is not specified in the string.
5037 char_u *
5038 find_viminfo_parameter(type)
5039 int type;
5041 char_u *p;
5043 for (p = p_viminfo; *p; ++p)
5045 if (*p == type)
5046 return p + 1;
5047 if (*p == 'n') /* 'n' is always the last one */
5048 break;
5049 p = vim_strchr(p, ','); /* skip until next ',' */
5050 if (p == NULL) /* hit the end without finding parameter */
5051 break;
5053 return NULL;
5055 #endif
5058 * Expand environment variables for some string options.
5059 * These string options cannot be indirect!
5060 * If "val" is NULL expand the current value of the option.
5061 * Return pointer to NameBuff, or NULL when not expanded.
5063 static char_u *
5064 option_expand(opt_idx, val)
5065 int opt_idx;
5066 char_u *val;
5068 /* if option doesn't need expansion nothing to do */
5069 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5070 return NULL;
5072 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5073 * expand_env() would truncate the string. */
5074 if (val != NULL && STRLEN(val) > MAXPATHL)
5075 return NULL;
5077 if (val == NULL)
5078 val = *(char_u **)options[opt_idx].var;
5081 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5082 * Escape spaces when expanding 'tags', they are used to separate file
5083 * names.
5084 * For 'spellsuggest' expand after "file:".
5086 expand_env_esc(val, NameBuff, MAXPATHL,
5087 (char_u **)options[opt_idx].var == &p_tags, FALSE,
5088 #ifdef FEAT_SPELL
5089 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5090 #endif
5091 NULL);
5092 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5093 return NULL;
5095 return NameBuff;
5099 * After setting various option values: recompute variables that depend on
5100 * option values.
5102 static void
5103 didset_options()
5105 /* initialize the table for 'iskeyword' et.al. */
5106 (void)init_chartab();
5108 #ifdef FEAT_MBYTE
5109 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5110 #endif
5111 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5112 #ifdef FEAT_SESSION
5113 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5114 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5115 #endif
5116 #ifdef FEAT_FOLDING
5117 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5118 #endif
5119 #ifdef FEAT_FULLSCREEN
5120 (void)check_fuoptions(p_fuoptions, &fuoptions_flags,
5121 &fuoptions_bgcolor);
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 || defined(FEAT_GUI_MACVIM))
5140 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5141 #endif
5142 #ifdef FEAT_CMDWIN
5143 /* set cedit_key */
5144 (void)check_cedit();
5145 #endif
5149 * Check for string options that are NULL (normally only termcap options).
5151 void
5152 check_options()
5154 int opt_idx;
5156 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5157 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5158 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5162 * Check string options in a buffer for NULL value.
5164 void
5165 check_buf_options(buf)
5166 buf_T *buf;
5168 #if defined(FEAT_QUICKFIX)
5169 check_string_option(&buf->b_p_bh);
5170 check_string_option(&buf->b_p_bt);
5171 #endif
5172 #ifdef FEAT_MBYTE
5173 check_string_option(&buf->b_p_fenc);
5174 #endif
5175 check_string_option(&buf->b_p_ff);
5176 #ifdef FEAT_FIND_ID
5177 check_string_option(&buf->b_p_def);
5178 check_string_option(&buf->b_p_inc);
5179 # ifdef FEAT_EVAL
5180 check_string_option(&buf->b_p_inex);
5181 # endif
5182 #endif
5183 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5184 check_string_option(&buf->b_p_inde);
5185 check_string_option(&buf->b_p_indk);
5186 #endif
5187 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5188 check_string_option(&buf->b_p_bexpr);
5189 #endif
5190 #if defined(FEAT_EVAL)
5191 check_string_option(&buf->b_p_fex);
5192 #endif
5193 #ifdef FEAT_CRYPT
5194 check_string_option(&buf->b_p_key);
5195 #endif
5196 check_string_option(&buf->b_p_kp);
5197 check_string_option(&buf->b_p_mps);
5198 check_string_option(&buf->b_p_fo);
5199 check_string_option(&buf->b_p_flp);
5200 check_string_option(&buf->b_p_isk);
5201 #ifdef FEAT_COMMENTS
5202 check_string_option(&buf->b_p_com);
5203 #endif
5204 #ifdef FEAT_FOLDING
5205 check_string_option(&buf->b_p_cms);
5206 #endif
5207 check_string_option(&buf->b_p_nf);
5208 #ifdef FEAT_TEXTOBJ
5209 check_string_option(&buf->b_p_qe);
5210 #endif
5211 #ifdef FEAT_SYN_HL
5212 check_string_option(&buf->b_p_syn);
5213 #endif
5214 #ifdef FEAT_SPELL
5215 check_string_option(&buf->b_p_spc);
5216 check_string_option(&buf->b_p_spf);
5217 check_string_option(&buf->b_p_spl);
5218 #endif
5219 #ifdef FEAT_SEARCHPATH
5220 check_string_option(&buf->b_p_sua);
5221 #endif
5222 #ifdef FEAT_CINDENT
5223 check_string_option(&buf->b_p_cink);
5224 check_string_option(&buf->b_p_cino);
5225 #endif
5226 #ifdef FEAT_AUTOCMD
5227 check_string_option(&buf->b_p_ft);
5228 #endif
5229 #ifdef FEAT_OSFILETYPE
5230 check_string_option(&buf->b_p_oft);
5231 #endif
5232 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5233 check_string_option(&buf->b_p_cinw);
5234 #endif
5235 #ifdef FEAT_INS_EXPAND
5236 check_string_option(&buf->b_p_cpt);
5237 #endif
5238 #ifdef FEAT_COMPL_FUNC
5239 check_string_option(&buf->b_p_cfu);
5240 check_string_option(&buf->b_p_ofu);
5241 #endif
5242 #ifdef FEAT_KEYMAP
5243 check_string_option(&buf->b_p_keymap);
5244 #endif
5245 #ifdef FEAT_QUICKFIX
5246 check_string_option(&buf->b_p_gp);
5247 check_string_option(&buf->b_p_mp);
5248 check_string_option(&buf->b_p_efm);
5249 #endif
5250 check_string_option(&buf->b_p_ep);
5251 check_string_option(&buf->b_p_path);
5252 check_string_option(&buf->b_p_tags);
5253 #ifdef FEAT_INS_EXPAND
5254 check_string_option(&buf->b_p_dict);
5255 check_string_option(&buf->b_p_tsr);
5256 #endif
5260 * Free the string allocated for an option.
5261 * Checks for the string being empty_option. This may happen if we're out of
5262 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5263 * check_options().
5264 * Does NOT check for P_ALLOCED flag!
5266 void
5267 free_string_option(p)
5268 char_u *p;
5270 if (p != empty_option)
5271 vim_free(p);
5274 void
5275 clear_string_option(pp)
5276 char_u **pp;
5278 if (*pp != empty_option)
5279 vim_free(*pp);
5280 *pp = empty_option;
5283 static void
5284 check_string_option(pp)
5285 char_u **pp;
5287 if (*pp == NULL)
5288 *pp = empty_option;
5292 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5294 void
5295 set_term_option_alloced(p)
5296 char_u **p;
5298 int opt_idx;
5300 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5301 if (options[opt_idx].var == (char_u *)p)
5303 options[opt_idx].flags |= P_ALLOCED;
5304 return;
5306 return; /* cannot happen: didn't find it! */
5309 #if defined(FEAT_EVAL) || defined(PROTO)
5311 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5312 * Return FALSE when it wasn't.
5313 * Return -1 for an unknown option.
5316 was_set_insecurely(opt, opt_flags)
5317 char_u *opt;
5318 int opt_flags;
5320 int idx = findoption(opt);
5321 long_u *flagp;
5323 if (idx >= 0)
5325 flagp = insecure_flag(idx, opt_flags);
5326 return (*flagp & P_INSECURE) != 0;
5328 EMSG2(_(e_intern2), "was_set_insecurely()");
5329 return -1;
5333 * Get a pointer to the flags used for the P_INSECURE flag of option
5334 * "opt_idx". For some local options a local flags field is used.
5336 static long_u *
5337 insecure_flag(opt_idx, opt_flags)
5338 int opt_idx;
5339 int opt_flags;
5341 if (opt_flags & OPT_LOCAL)
5342 switch ((int)options[opt_idx].indir)
5344 #ifdef FEAT_STL_OPT
5345 case PV_STL: return &curwin->w_p_stl_flags;
5346 #endif
5347 #ifdef FEAT_EVAL
5348 # ifdef FEAT_FOLDING
5349 case PV_FDE: return &curwin->w_p_fde_flags;
5350 case PV_FDT: return &curwin->w_p_fdt_flags;
5351 # endif
5352 # ifdef FEAT_BEVAL
5353 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5354 # endif
5355 # if defined(FEAT_CINDENT)
5356 case PV_INDE: return &curbuf->b_p_inde_flags;
5357 # endif
5358 case PV_FEX: return &curbuf->b_p_fex_flags;
5359 # ifdef FEAT_FIND_ID
5360 case PV_INEX: return &curbuf->b_p_inex_flags;
5361 # endif
5362 #endif
5365 /* Nothing special, return global flags field. */
5366 return &options[opt_idx].flags;
5368 #endif
5370 #ifdef FEAT_TITLE
5371 static void redraw_titles __ARGS((void));
5374 * Redraw the window title and/or tab page text later.
5376 static void redraw_titles()
5378 need_maketitle = TRUE;
5379 # ifdef FEAT_WINDOWS
5380 redraw_tabline = TRUE;
5381 # endif
5383 #endif
5386 * Set a string option to a new value (without checking the effect).
5387 * The string is copied into allocated memory.
5388 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
5389 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
5390 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
5392 /*ARGSUSED*/
5393 void
5394 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
5395 char_u *name;
5396 int opt_idx;
5397 char_u *val;
5398 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5399 int set_sid;
5401 char_u *s;
5402 char_u **varp;
5403 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5404 int idx = opt_idx;
5406 if (idx == -1) /* use name */
5408 idx = findoption(name);
5409 if (idx < 0) /* not found (should not happen) */
5411 EMSG2(_(e_intern2), "set_string_option_direct()");
5412 return;
5416 if (options[idx].var == NULL) /* can't set hidden option */
5417 return;
5419 s = vim_strsave(val);
5420 if (s != NULL)
5422 varp = (char_u **)get_varp_scope(&(options[idx]),
5423 both ? OPT_LOCAL : opt_flags);
5424 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
5425 free_string_option(*varp);
5426 *varp = s;
5428 /* For buffer/window local option may also set the global value. */
5429 if (both)
5430 set_string_option_global(idx, varp);
5432 options[idx].flags |= P_ALLOCED;
5434 /* When setting both values of a global option with a local value,
5435 * make the local value empty, so that the global value is used. */
5436 if (((int)options[idx].indir & PV_BOTH) && both)
5438 free_string_option(*varp);
5439 *varp = empty_option;
5441 # ifdef FEAT_EVAL
5442 if (set_sid != SID_NONE)
5443 set_option_scriptID_idx(idx, opt_flags,
5444 set_sid == 0 ? current_SID : set_sid);
5445 # endif
5450 * Set global value for string option when it's a local option.
5452 static void
5453 set_string_option_global(opt_idx, varp)
5454 int opt_idx; /* option index */
5455 char_u **varp; /* pointer to option variable */
5457 char_u **p, *s;
5459 /* the global value is always allocated */
5460 if (options[opt_idx].var == VAR_WIN)
5461 p = (char_u **)GLOBAL_WO(varp);
5462 else
5463 p = (char_u **)options[opt_idx].var;
5464 if (options[opt_idx].indir != PV_NONE
5465 && p != varp
5466 && (s = vim_strsave(*varp)) != NULL)
5468 free_string_option(*p);
5469 *p = s;
5472 #ifdef USE_MIGEMO
5473 if (varp == &p_migdict)
5474 reset_migemo(FALSE);
5475 #endif
5479 * Set a string option to a new value, and handle the effects.
5481 static void
5482 set_string_option(opt_idx, value, opt_flags)
5483 int opt_idx;
5484 char_u *value;
5485 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5487 char_u *s;
5488 char_u **varp;
5489 char_u *oldval;
5491 if (options[opt_idx].var == NULL) /* don't set hidden option */
5492 return;
5494 s = vim_strsave(value);
5495 if (s != NULL)
5497 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5498 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5499 ? (((int)options[opt_idx].indir & PV_BOTH)
5500 ? OPT_GLOBAL : OPT_LOCAL)
5501 : opt_flags);
5502 oldval = *varp;
5503 *varp = s;
5504 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5505 opt_flags) == NULL)
5506 did_set_option(opt_idx, opt_flags, TRUE);
5511 * Handle string options that need some action to perform when changed.
5512 * Returns NULL for success, or an error message for an error.
5514 static char_u *
5515 did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5516 opt_flags)
5517 int opt_idx; /* index in options[] table */
5518 char_u **varp; /* pointer to the option variable */
5519 int new_value_alloced; /* new value was allocated */
5520 char_u *oldval; /* previous value of the option */
5521 char_u *errbuf; /* buffer for errors, or NULL */
5522 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5524 char_u *errmsg = NULL;
5525 char_u *s, *p;
5526 int did_chartab = FALSE;
5527 char_u **gvarp;
5528 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
5529 #ifdef FEAT_GUI
5530 /* set when changing an option that only requires a redraw in the GUI */
5531 int redraw_gui_only = FALSE;
5532 #endif
5534 /* Get the global option to compare with, otherwise we would have to check
5535 * two values for all local options. */
5536 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5538 /* Disallow changing some options from secure mode */
5539 if ((secure
5540 #ifdef HAVE_SANDBOX
5541 || sandbox != 0
5542 #endif
5543 ) && (options[opt_idx].flags & P_SECURE))
5545 errmsg = e_secure;
5548 /* Check for a "normal" file name in some options. Disallow a path
5549 * separator (slash and/or backslash), wildcards and characters that are
5550 * often illegal in a file name. */
5551 else if ((options[opt_idx].flags & P_NFNAME)
5552 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
5554 errmsg = e_invarg;
5557 /* 'term' */
5558 else if (varp == &T_NAME)
5560 if (T_NAME[0] == NUL)
5561 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5562 #ifdef FEAT_GUI
5563 if (gui.in_use)
5564 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5565 else if (term_is_gui(T_NAME))
5566 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5567 #endif
5568 else if (set_termname(T_NAME) == FAIL)
5569 errmsg = (char_u *)N_("E522: Not found in termcap");
5570 else
5571 /* Screen colors may have changed. */
5572 redraw_later_clear();
5575 /* 'backupcopy' */
5576 else if (varp == &p_bkc)
5578 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5579 errmsg = e_invarg;
5580 if (((bkc_flags & BKC_AUTO) != 0)
5581 + ((bkc_flags & BKC_YES) != 0)
5582 + ((bkc_flags & BKC_NO) != 0) != 1)
5584 /* Must have exactly one of "auto", "yes" and "no". */
5585 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5586 errmsg = e_invarg;
5590 /* 'backupext' and 'patchmode' */
5591 else if (varp == &p_bex || varp == &p_pm)
5593 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5594 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5595 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5599 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5600 * If the new option is invalid, use old value. 'lisp' option: refill
5601 * chartab[] for '-' char
5603 else if ( varp == &p_isi
5604 || varp == &(curbuf->b_p_isk)
5605 || varp == &p_isp
5606 || varp == &p_isf)
5608 if (init_chartab() == FAIL)
5610 did_chartab = TRUE; /* need to restore it below */
5611 errmsg = e_invarg; /* error in value */
5615 /* 'helpfile' */
5616 else if (varp == &p_hf)
5618 /* May compute new values for $VIM and $VIMRUNTIME */
5619 if (didset_vim)
5621 vim_setenv((char_u *)"VIM", (char_u *)"");
5622 didset_vim = FALSE;
5624 if (didset_vimruntime)
5626 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5627 didset_vimruntime = FALSE;
5631 #ifdef FEAT_MULTI_LANG
5632 /* 'helplang' */
5633 else if (varp == &p_hlg)
5635 /* Check for "", "ab", "ab,cd", etc. */
5636 for (s = p_hlg; *s != NUL; s += 3)
5638 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5640 errmsg = e_invarg;
5641 break;
5643 if (s[2] == NUL)
5644 break;
5647 #endif
5649 /* 'highlight' */
5650 else if (varp == &p_hl)
5652 if (highlight_changed() == FAIL)
5653 errmsg = e_invarg; /* invalid flags */
5656 /* 'nrformats' */
5657 else if (gvarp == &p_nf)
5659 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5660 errmsg = e_invarg;
5663 #ifdef FEAT_SESSION
5664 /* 'sessionoptions' */
5665 else if (varp == &p_ssop)
5667 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5668 errmsg = e_invarg;
5669 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5671 /* Don't allow both "sesdir" and "curdir". */
5672 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5673 errmsg = e_invarg;
5676 /* 'viewoptions' */
5677 else if (varp == &p_vop)
5679 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5680 errmsg = e_invarg;
5682 #endif
5684 /* 'scrollopt' */
5685 #ifdef FEAT_SCROLLBIND
5686 else if (varp == &p_sbo)
5688 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5689 errmsg = e_invarg;
5691 #endif
5693 /* 'ambiwidth' */
5694 #ifdef FEAT_MBYTE
5695 else if (varp == &p_ambw)
5697 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5698 errmsg = e_invarg;
5700 #endif
5702 /* 'background' */
5703 else if (varp == &p_bg)
5705 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5707 #ifdef FEAT_EVAL
5708 int dark = (*p_bg == 'd');
5709 #endif
5711 init_highlight(FALSE, FALSE);
5713 #ifdef FEAT_EVAL
5714 if (dark != (*p_bg == 'd')
5715 && get_var_value((char_u *)"g:colors_name") != NULL)
5717 /* The color scheme must have set 'background' back to another
5718 * value, that's not what we want here. Disable the color
5719 * scheme and set the colors again. */
5720 do_unlet((char_u *)"g:colors_name", TRUE);
5721 free_string_option(p_bg);
5722 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5723 check_string_option(&p_bg);
5724 init_highlight(FALSE, FALSE);
5726 #endif
5728 else
5729 errmsg = e_invarg;
5732 /* 'wildmode' */
5733 else if (varp == &p_wim)
5735 if (check_opt_wim() == FAIL)
5736 errmsg = e_invarg;
5739 #ifdef FEAT_CMDL_COMPL
5740 /* 'wildoptions' */
5741 else if (varp == &p_wop)
5743 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5744 errmsg = e_invarg;
5746 #endif
5748 #ifdef FEAT_WAK
5749 /* 'winaltkeys' */
5750 else if (varp == &p_wak)
5752 if (*p_wak == NUL
5753 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5754 errmsg = e_invarg;
5755 # ifdef FEAT_MENU
5756 # ifdef FEAT_GUI_MOTIF
5757 else if (gui.in_use)
5758 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5759 # else
5760 # ifdef FEAT_GUI_GTK
5761 else if (gui.in_use)
5762 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5763 # endif
5764 # endif
5765 # endif
5767 #endif
5769 #ifdef FEAT_AUTOCMD
5770 /* 'eventignore' */
5771 else if (varp == &p_ei)
5773 if (check_ei() == FAIL)
5774 errmsg = e_invarg;
5776 #endif
5778 #ifdef FEAT_MBYTE
5779 /* 'encoding' and 'fileencoding' */
5780 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5782 if (gvarp == &p_fenc)
5784 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
5785 errmsg = e_modifiable;
5786 else if (vim_strchr(*varp, ',') != NULL)
5787 /* No comma allowed in 'fileencoding'; catches confusing it
5788 * with 'fileencodings'. */
5789 errmsg = e_invarg;
5790 else
5792 # ifdef FEAT_TITLE
5793 /* May show a "+" in the title now. */
5794 redraw_titles();
5795 # endif
5796 /* Add 'fileencoding' to the swap file. */
5797 ml_setflags(curbuf);
5800 if (errmsg == NULL)
5802 /* canonize the value, so that STRCMP() can be used on it */
5803 p = enc_canonize(*varp);
5804 if (p != NULL)
5806 vim_free(*varp);
5807 *varp = p;
5809 if (varp == &p_enc)
5811 errmsg = mb_init();
5812 # ifdef FEAT_TITLE
5813 redraw_titles();
5814 # endif
5818 # if (defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)) || defined(FEAT_GUI_MACVIM)
5819 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5821 /* MacVim and GTK+ 2 GUIs force 'tenc' to UTF-8. */
5822 if (STRCMP(p_tenc, "utf-8") != 0)
5823 # if defined(FEAT_GUI_MACVIM)
5824 errmsg = (char_u *)N_("E617: Cannot be changed in MacVim");
5825 # else
5826 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5827 # endif
5829 # endif
5831 if (errmsg == NULL)
5833 # ifdef FEAT_KEYMAP
5834 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5835 * (with another encoding). */
5836 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5837 (void)keymap_init();
5838 # endif
5840 /* When 'termencoding' is not empty and 'encoding' changes or when
5841 * 'termencoding' changes, need to setup for keyboard input and
5842 * display output conversion. */
5843 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5845 convert_setup(&input_conv, p_tenc, p_enc);
5846 convert_setup(&output_conv, p_enc, p_tenc);
5849 # if defined(WIN3264) && defined(FEAT_MBYTE)
5850 /* $HOME may have characters in active code page. */
5851 if (varp == &p_enc)
5852 init_homedir();
5853 # endif
5856 #endif
5858 #if defined(FEAT_POSTSCRIPT)
5859 else if (varp == &p_penc)
5861 /* Canonize printencoding if VIM standard one */
5862 p = enc_canonize(p_penc);
5863 if (p != NULL)
5865 vim_free(p_penc);
5866 p_penc = p;
5868 else
5870 /* Ensure lower case and '-' for '_' */
5871 for (s = p_penc; *s != NUL; s++)
5873 if (*s == '_')
5874 *s = '-';
5875 else
5876 *s = TOLOWER_ASC(*s);
5880 #endif
5882 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
5883 else if (varp == &p_imak)
5885 if (gui.in_use && !im_xim_isvalid_imactivate())
5886 errmsg = e_invarg;
5888 #endif
5890 #ifdef FEAT_KEYMAP
5891 else if (varp == &curbuf->b_p_keymap)
5893 /* load or unload key mapping tables */
5894 errmsg = keymap_init();
5896 if (errmsg == NULL)
5898 if (*curbuf->b_p_keymap != NUL)
5900 /* Installed a new keymap, switch on using it. */
5901 curbuf->b_p_iminsert = B_IMODE_LMAP;
5902 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5903 curbuf->b_p_imsearch = B_IMODE_LMAP;
5905 else
5907 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5908 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5909 curbuf->b_p_iminsert = B_IMODE_NONE;
5910 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5911 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5913 if ((opt_flags & OPT_LOCAL) == 0)
5915 set_iminsert_global();
5916 set_imsearch_global();
5918 # ifdef FEAT_WINDOWS
5919 status_redraw_curbuf();
5920 # endif
5923 #endif
5925 /* 'fileformat' */
5926 else if (gvarp == &p_ff)
5928 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5929 errmsg = e_modifiable;
5930 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5931 errmsg = e_invarg;
5932 else
5934 /* may also change 'textmode' */
5935 if (get_fileformat(curbuf) == EOL_DOS)
5936 curbuf->b_p_tx = TRUE;
5937 else
5938 curbuf->b_p_tx = FALSE;
5939 #ifdef FEAT_TITLE
5940 redraw_titles();
5941 #endif
5942 /* update flag in swap file */
5943 ml_setflags(curbuf);
5947 /* 'fileformats' */
5948 else if (varp == &p_ffs)
5950 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5951 errmsg = e_invarg;
5952 else
5954 /* also change 'textauto' */
5955 if (*p_ffs == NUL)
5956 p_ta = FALSE;
5957 else
5958 p_ta = TRUE;
5962 #if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5963 /* 'cryptkey' */
5964 else if (gvarp == &p_key)
5966 /* Make sure the ":set" command doesn't show the new value in the
5967 * history. */
5968 remove_key_from_history();
5970 #endif
5972 /* 'matchpairs' */
5973 else if (gvarp == &p_mps)
5975 /* Check for "x:y,x:y" */
5976 for (p = *varp; *p != NUL; p += 4)
5978 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5980 errmsg = e_invarg;
5981 break;
5983 if (p[3] == NUL)
5984 break;
5988 #ifdef FEAT_COMMENTS
5989 /* 'comments' */
5990 else if (gvarp == &p_com)
5992 for (s = *varp; *s; )
5994 while (*s && *s != ':')
5996 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5997 && !VIM_ISDIGIT(*s) && *s != '-')
5999 errmsg = illegal_char(errbuf, *s);
6000 break;
6002 ++s;
6004 if (*s++ == NUL)
6005 errmsg = (char_u *)N_("E524: Missing colon");
6006 else if (*s == ',' || *s == NUL)
6007 errmsg = (char_u *)N_("E525: Zero length string");
6008 if (errmsg != NULL)
6009 break;
6010 while (*s && *s != ',')
6012 if (*s == '\\' && s[1] != NUL)
6013 ++s;
6014 ++s;
6016 s = skip_to_option_part(s);
6019 #endif
6021 /* 'listchars' */
6022 else if (varp == &p_lcs)
6024 errmsg = set_chars_option(varp);
6027 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6028 /* 'fillchars' */
6029 else if (varp == &p_fcs)
6031 errmsg = set_chars_option(varp);
6033 #endif
6035 #ifdef FEAT_CMDWIN
6036 /* 'cedit' */
6037 else if (varp == &p_cedit)
6039 errmsg = check_cedit();
6041 #endif
6043 /* 'verbosefile' */
6044 else if (varp == &p_vfile)
6046 verbose_stop();
6047 if (*p_vfile != NUL && verbose_open() == FAIL)
6048 errmsg = e_invarg;
6051 #ifdef FEAT_VIMINFO
6052 /* 'viminfo' */
6053 else if (varp == &p_viminfo)
6055 for (s = p_viminfo; *s;)
6057 /* Check it's a valid character */
6058 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6060 errmsg = illegal_char(errbuf, *s);
6061 break;
6063 if (*s == 'n') /* name is always last one */
6065 break;
6067 else if (*s == 'r') /* skip until next ',' */
6069 while (*++s && *s != ',')
6072 else if (*s == '%')
6074 /* optional number */
6075 while (vim_isdigit(*++s))
6078 else if (*s == '!' || *s == 'h' || *s == 'c')
6079 ++s; /* no extra chars */
6080 else /* must have a number */
6082 while (vim_isdigit(*++s))
6085 if (!VIM_ISDIGIT(*(s - 1)))
6087 if (errbuf != NULL)
6089 sprintf((char *)errbuf,
6090 _("E526: Missing number after <%s>"),
6091 transchar_byte(*(s - 1)));
6092 errmsg = errbuf;
6094 else
6095 errmsg = (char_u *)"";
6096 break;
6099 if (*s == ',')
6100 ++s;
6101 else if (*s)
6103 if (errbuf != NULL)
6104 errmsg = (char_u *)N_("E527: Missing comma");
6105 else
6106 errmsg = (char_u *)"";
6107 break;
6110 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6111 errmsg = (char_u *)N_("E528: Must specify a ' value");
6113 #endif /* FEAT_VIMINFO */
6115 /* terminal options */
6116 else if (istermoption(&options[opt_idx]) && full_screen)
6118 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6119 if (varp == &T_CCO)
6121 int colors = atoi((char *)T_CCO);
6123 /* Only reinitialize colors if t_Co value has really changed to
6124 * avoid expensive reload of colorscheme if t_Co is set to the
6125 * same value multiple times. */
6126 if (colors != t_colors)
6128 t_colors = colors;
6129 if (t_colors <= 1)
6131 if (new_value_alloced)
6132 vim_free(T_CCO);
6133 T_CCO = empty_option;
6135 /* We now have a different color setup, initialize it again. */
6136 init_highlight(TRUE, FALSE);
6139 ttest(FALSE);
6140 if (varp == &T_ME)
6142 out_str(T_ME);
6143 redraw_later(CLEAR);
6144 #if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6145 /* Since t_me has been set, this probably means that the user
6146 * wants to use this as default colors. Need to reset default
6147 * background/foreground colors. */
6148 mch_set_normal_colors();
6149 #endif
6153 #ifdef FEAT_LINEBREAK
6154 /* 'showbreak' */
6155 else if (varp == &p_sbr)
6157 for (s = p_sbr; *s; )
6159 if (ptr2cells(s) != 1)
6160 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
6161 mb_ptr_adv(s);
6164 #endif
6166 #ifdef FEAT_GUI
6167 /* 'guifont' */
6168 else if (varp == &p_guifont)
6170 if (gui.in_use)
6172 p = p_guifont;
6173 # if defined(FEAT_GUI_GTK)
6175 * Put up a font dialog and let the user select a new value.
6176 * If this is cancelled go back to the old value but don't
6177 * give an error message.
6179 if (STRCMP(p, "*") == 0)
6181 p = gui_mch_font_dialog(oldval);
6183 if (new_value_alloced)
6184 free_string_option(p_guifont);
6186 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6187 new_value_alloced = TRUE;
6189 # endif
6190 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6192 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON) \
6193 || defined(FEAT_GUI_MACVIM)
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');
6490 #endif
6492 #ifdef FEAT_STL_OPT
6493 /* 'statusline' or 'rulerformat' */
6494 else if (gvarp == &p_stl || varp == &p_ruf)
6496 int wid;
6498 if (varp == &p_ruf) /* reset ru_wid first */
6499 ru_wid = 0;
6500 s = *varp;
6501 if (varp == &p_ruf && *s == '%')
6503 /* set ru_wid if 'ruf' starts with "%99(" */
6504 if (*++s == '-') /* ignore a '-' */
6505 s++;
6506 wid = getdigits(&s);
6507 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6508 ru_wid = wid;
6509 else
6510 errmsg = check_stl_option(p_ruf);
6512 /* check 'statusline' only if it doesn't start with "%!" */
6513 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
6514 errmsg = check_stl_option(s);
6515 if (varp == &p_ruf && errmsg == NULL)
6516 comp_col();
6518 #endif
6520 #ifdef FEAT_INS_EXPAND
6521 /* check if it is a valid value for 'complete' -- Acevedo */
6522 else if (gvarp == &p_cpt)
6524 for (s = *varp; *s;)
6526 while(*s == ',' || *s == ' ')
6527 s++;
6528 if (!*s)
6529 break;
6530 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6532 errmsg = illegal_char(errbuf, *s);
6533 break;
6535 if (*++s != NUL && *s != ',' && *s != ' ')
6537 if (s[-1] == 'k' || s[-1] == 's')
6539 /* skip optional filename after 'k' and 's' */
6540 while (*s && *s != ',' && *s != ' ')
6542 if (*s == '\\')
6543 ++s;
6544 ++s;
6547 else
6549 if (errbuf != NULL)
6551 sprintf((char *)errbuf,
6552 _("E535: Illegal character after <%c>"),
6553 *--s);
6554 errmsg = errbuf;
6556 else
6557 errmsg = (char_u *)"";
6558 break;
6564 /* 'completeopt' */
6565 else if (varp == &p_cot)
6567 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6568 errmsg = e_invarg;
6570 #endif /* FEAT_INS_EXPAND */
6573 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6574 else if (varp == &p_toolbar)
6576 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6577 &toolbar_flags, TRUE) != OK)
6578 errmsg = e_invarg;
6579 else
6581 out_flush();
6582 gui_mch_show_toolbar((toolbar_flags &
6583 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6586 #endif
6588 #if defined(FEAT_TOOLBAR) && ((defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)) \
6589 || defined(FEAT_GUI_MACVIM))
6590 /* 'toolbariconsize': GTK+ 2 and MacVim only */
6591 else if (varp == &p_tbis)
6593 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6594 errmsg = e_invarg;
6595 else
6597 out_flush();
6598 gui_mch_show_toolbar((toolbar_flags &
6599 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6602 #endif
6604 /* 'pastetoggle': translate key codes like in a mapping */
6605 else if (varp == &p_pt)
6607 if (*p_pt)
6609 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
6610 if (p != NULL)
6612 if (new_value_alloced)
6613 free_string_option(p_pt);
6614 p_pt = p;
6615 new_value_alloced = TRUE;
6620 /* 'backspace' */
6621 else if (varp == &p_bs)
6623 if (VIM_ISDIGIT(*p_bs))
6625 if (*p_bs >'2' || p_bs[1] != NUL)
6626 errmsg = e_invarg;
6628 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6629 errmsg = e_invarg;
6632 #ifdef FEAT_MBYTE
6633 /* 'casemap' */
6634 else if (varp == &p_cmp)
6636 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6637 errmsg = e_invarg;
6639 #endif
6641 #ifdef FEAT_DIFF
6642 /* 'diffopt' */
6643 else if (varp == &p_dip)
6645 if (diffopt_changed() == FAIL)
6646 errmsg = e_invarg;
6648 #endif
6650 #ifdef FEAT_FOLDING
6651 /* 'foldmethod' */
6652 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6654 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6655 || *curwin->w_p_fdm == NUL)
6656 errmsg = e_invarg;
6657 else
6658 foldUpdateAll(curwin);
6660 # ifdef FEAT_EVAL
6661 /* 'foldexpr' */
6662 else if (varp == &curwin->w_p_fde)
6664 if (foldmethodIsExpr(curwin))
6665 foldUpdateAll(curwin);
6667 # endif
6668 /* 'foldmarker' */
6669 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6671 p = vim_strchr(*varp, ',');
6672 if (p == NULL)
6673 errmsg = (char_u *)N_("E536: comma required");
6674 else if (p == *varp || p[1] == NUL)
6675 errmsg = e_invarg;
6676 else if (foldmethodIsMarker(curwin))
6677 foldUpdateAll(curwin);
6679 /* 'commentstring' */
6680 else if (gvarp == &p_cms)
6682 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6683 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6685 /* 'foldopen' */
6686 else if (varp == &p_fdo)
6688 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6689 errmsg = e_invarg;
6691 /* 'foldclose' */
6692 else if (varp == &p_fcl)
6694 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6695 errmsg = e_invarg;
6697 /* 'foldignore' */
6698 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6700 if (foldmethodIsIndent(curwin))
6701 foldUpdateAll(curwin);
6703 #endif
6705 #ifdef FEAT_FULLSCREEN
6706 /* 'fuoptions' */
6707 else if (varp == &p_fuoptions)
6709 if (check_fuoptions(p_fuoptions, &fuoptions_flags,
6710 &fuoptions_bgcolor) != OK)
6711 errmsg = e_invarg;
6713 #endif
6715 #ifdef FEAT_VIRTUALEDIT
6716 /* 'virtualedit' */
6717 else if (varp == &p_ve)
6719 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6720 errmsg = e_invarg;
6721 else if (STRCMP(p_ve, oldval) != 0)
6723 /* Recompute cursor position in case the new 've' setting
6724 * changes something. */
6725 validate_virtcol();
6726 coladvance(curwin->w_virtcol);
6729 #endif
6731 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6732 else if (varp == &p_csqf)
6734 if (p_csqf != NULL)
6736 p = p_csqf;
6737 while (*p != NUL)
6739 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6740 || p[1] == NUL
6741 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6742 || (p[2] != NUL && p[2] != ','))
6744 errmsg = e_invarg;
6745 break;
6747 else if (p[2] == NUL)
6748 break;
6749 else
6750 p += 3;
6754 #endif
6756 /* Options that are a list of flags. */
6757 else
6759 p = NULL;
6760 if (varp == &p_ww)
6761 p = (char_u *)WW_ALL;
6762 if (varp == &p_shm)
6763 p = (char_u *)SHM_ALL;
6764 else if (varp == &(p_cpo))
6765 p = (char_u *)CPO_ALL;
6766 else if (varp == &(curbuf->b_p_fo))
6767 p = (char_u *)FO_ALL;
6768 else if (varp == &p_mouse)
6770 #ifdef FEAT_MOUSE
6771 p = (char_u *)MOUSE_ALL;
6772 #else
6773 if (*p_mouse != NUL)
6774 errmsg = (char_u *)N_("E538: No mouse support");
6775 #endif
6777 #if defined(FEAT_GUI)
6778 else if (varp == &p_go)
6779 p = (char_u *)GO_ALL;
6780 #endif
6781 if (p != NULL)
6783 for (s = *varp; *s; ++s)
6784 if (vim_strchr(p, *s) == NULL)
6786 errmsg = illegal_char(errbuf, *s);
6787 break;
6793 * If error detected, restore the previous value.
6795 if (errmsg != NULL)
6797 if (new_value_alloced)
6798 free_string_option(*varp);
6799 *varp = oldval;
6801 * When resetting some values, need to act on it.
6803 if (did_chartab)
6804 (void)init_chartab();
6805 if (varp == &p_hl)
6806 (void)highlight_changed();
6808 else
6810 #ifdef FEAT_EVAL
6811 /* Remember where the option was set. */
6812 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
6813 #endif
6815 * Free string options that are in allocated memory.
6816 * Use "free_oldval", because recursiveness may change the flags under
6817 * our fingers (esp. init_highlight()).
6819 if (free_oldval)
6820 free_string_option(oldval);
6821 if (new_value_alloced)
6822 options[opt_idx].flags |= P_ALLOCED;
6823 else
6824 options[opt_idx].flags &= ~P_ALLOCED;
6826 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6827 && ((int)options[opt_idx].indir & PV_BOTH))
6829 /* global option with local value set to use global value; free
6830 * the local value and make it empty */
6831 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6832 free_string_option(*(char_u **)p);
6833 *(char_u **)p = empty_option;
6836 /* May set global value for local option. */
6837 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6838 set_string_option_global(opt_idx, varp);
6840 #ifdef FEAT_AUTOCMD
6842 * Trigger the autocommand only after setting the flags.
6844 # ifdef FEAT_SYN_HL
6845 /* When 'syntax' is set, load the syntax of that name */
6846 if (varp == &(curbuf->b_p_syn))
6848 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6849 curbuf->b_fname, TRUE, curbuf);
6851 # endif
6852 else if (varp == &(curbuf->b_p_ft))
6854 /* 'filetype' is set, trigger the FileType autocommand */
6855 did_filetype = TRUE;
6856 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6857 curbuf->b_fname, TRUE, curbuf);
6859 #endif
6860 #ifdef FEAT_SPELL
6861 if (varp == &(curbuf->b_p_spl))
6863 char_u fname[200];
6866 * Source the spell/LANG.vim in 'runtimepath'.
6867 * They could set 'spellcapcheck' depending on the language.
6868 * Use the first name in 'spelllang' up to '_region' or
6869 * '.encoding'.
6871 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6872 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6873 break;
6874 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6875 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6876 source_runtime(fname, TRUE);
6878 #endif
6881 #ifdef FEAT_MOUSE
6882 if (varp == &p_mouse)
6884 # ifdef FEAT_MOUSE_TTY
6885 if (*p_mouse == NUL)
6886 mch_setmouse(FALSE); /* switch mouse off */
6887 else
6888 # endif
6889 setmouse(); /* in case 'mouse' changed */
6891 #endif
6893 if (curwin->w_curswant != MAXCOL)
6894 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6895 #ifdef FEAT_GUI
6896 /* check redraw when it's not a GUI option or the GUI is active. */
6897 if (!redraw_gui_only || gui.in_use)
6898 #endif
6899 check_redraw(options[opt_idx].flags);
6901 return errmsg;
6905 * Handle setting 'listchars' or 'fillchars'.
6906 * Returns error message, NULL if it's OK.
6908 static char_u *
6909 set_chars_option(varp)
6910 char_u **varp;
6912 int round, i, len, entries;
6913 char_u *p, *s;
6914 int c1, c2 = 0;
6915 struct charstab
6917 int *cp;
6918 char *name;
6920 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6921 static struct charstab filltab[] =
6923 {&fill_stl, "stl"},
6924 {&fill_stlnc, "stlnc"},
6925 {&fill_vert, "vert"},
6926 {&fill_fold, "fold"},
6927 {&fill_diff, "diff"},
6929 #endif
6930 static struct charstab lcstab[] =
6932 {&lcs_eol, "eol"},
6933 {&lcs_ext, "extends"},
6934 {&lcs_nbsp, "nbsp"},
6935 {&lcs_prec, "precedes"},
6936 {&lcs_tab2, "tab"},
6937 {&lcs_trail, "trail"},
6939 struct charstab *tab;
6941 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6942 if (varp == &p_lcs)
6943 #endif
6945 tab = lcstab;
6946 entries = sizeof(lcstab) / sizeof(struct charstab);
6948 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6949 else
6951 tab = filltab;
6952 entries = sizeof(filltab) / sizeof(struct charstab);
6954 #endif
6956 /* first round: check for valid value, second round: assign values */
6957 for (round = 0; round <= 1; ++round)
6959 if (round)
6961 /* After checking that the value is valid: set defaults: space for
6962 * 'fillchars', NUL for 'listchars' */
6963 for (i = 0; i < entries; ++i)
6964 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6965 if (varp == &p_lcs)
6966 lcs_tab1 = NUL;
6967 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6968 else
6969 fill_diff = '-';
6970 #endif
6972 p = *varp;
6973 while (*p)
6975 for (i = 0; i < entries; ++i)
6977 len = (int)STRLEN(tab[i].name);
6978 if (STRNCMP(p, tab[i].name, len) == 0
6979 && p[len] == ':'
6980 && p[len + 1] != NUL)
6982 s = p + len + 1;
6983 #ifdef FEAT_MBYTE
6984 c1 = mb_ptr2char_adv(&s);
6985 if (mb_char2cells(c1) > 1)
6986 continue;
6987 #else
6988 c1 = *s++;
6989 #endif
6990 if (tab[i].cp == &lcs_tab2)
6992 if (*s == NUL)
6993 continue;
6994 #ifdef FEAT_MBYTE
6995 c2 = mb_ptr2char_adv(&s);
6996 if (mb_char2cells(c2) > 1)
6997 continue;
6998 #else
6999 c2 = *s++;
7000 #endif
7002 if (*s == ',' || *s == NUL)
7004 if (round)
7006 if (tab[i].cp == &lcs_tab2)
7008 lcs_tab1 = c1;
7009 lcs_tab2 = c2;
7011 else
7012 *(tab[i].cp) = c1;
7015 p = s;
7016 break;
7021 if (i == entries)
7022 return e_invarg;
7023 if (*p == ',')
7024 ++p;
7028 return NULL; /* no error */
7031 #ifdef FEAT_STL_OPT
7033 * Check validity of options with the 'statusline' format.
7034 * Return error message or NULL.
7036 char_u *
7037 check_stl_option(s)
7038 char_u *s;
7040 int itemcnt = 0;
7041 int groupdepth = 0;
7042 static char_u errbuf[80];
7044 while (*s && itemcnt < STL_MAX_ITEM)
7046 /* Check for valid keys after % sequences */
7047 while (*s && *s != '%')
7048 s++;
7049 if (!*s)
7050 break;
7051 s++;
7052 if (*s != '%' && *s != ')')
7053 ++itemcnt;
7054 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7056 s++;
7057 continue;
7059 if (*s == ')')
7061 s++;
7062 if (--groupdepth < 0)
7063 break;
7064 continue;
7066 if (*s == '-')
7067 s++;
7068 while (VIM_ISDIGIT(*s))
7069 s++;
7070 if (*s == STL_USER_HL)
7071 continue;
7072 if (*s == '.')
7074 s++;
7075 while (*s && VIM_ISDIGIT(*s))
7076 s++;
7078 if (*s == '(')
7080 groupdepth++;
7081 continue;
7083 if (vim_strchr(STL_ALL, *s) == NULL)
7085 return illegal_char(errbuf, *s);
7087 if (*s == '{')
7089 s++;
7090 while (*s != '}' && *s)
7091 s++;
7092 if (*s != '}')
7093 return (char_u *)N_("E540: Unclosed expression sequence");
7096 if (itemcnt >= STL_MAX_ITEM)
7097 return (char_u *)N_("E541: too many items");
7098 if (groupdepth != 0)
7099 return (char_u *)N_("E542: unbalanced groups");
7100 return NULL;
7102 #endif
7104 #ifdef FEAT_CLIPBOARD
7106 * Extract the items in the 'clipboard' option and set global values.
7108 static char_u *
7109 check_clipboard_option()
7111 int new_unnamed = FALSE;
7112 int new_autoselect = FALSE;
7113 int new_autoselectml = FALSE;
7114 regprog_T *new_exclude_prog = NULL;
7115 char_u *errmsg = NULL;
7116 char_u *p;
7118 for (p = p_cb; *p != NUL; )
7120 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7122 new_unnamed = TRUE;
7123 p += 7;
7125 else if (STRNCMP(p, "autoselect", 10) == 0
7126 && (p[10] == ',' || p[10] == NUL))
7128 new_autoselect = TRUE;
7129 p += 10;
7131 else if (STRNCMP(p, "autoselectml", 12) == 0
7132 && (p[12] == ',' || p[12] == NUL))
7134 new_autoselectml = TRUE;
7135 p += 12;
7137 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7139 p += 8;
7140 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7141 if (new_exclude_prog == NULL)
7142 errmsg = e_invarg;
7143 break;
7145 else
7147 errmsg = e_invarg;
7148 break;
7150 if (*p == ',')
7151 ++p;
7153 if (errmsg == NULL)
7155 clip_unnamed = new_unnamed;
7156 clip_autoselect = new_autoselect;
7157 clip_autoselectml = new_autoselectml;
7158 vim_free(clip_exclude_prog);
7159 clip_exclude_prog = new_exclude_prog;
7161 else
7162 vim_free(new_exclude_prog);
7164 return errmsg;
7166 #endif
7168 #ifdef FEAT_SPELL
7170 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7171 * Return error message when failed, NULL when OK.
7173 static char_u *
7174 compile_cap_prog(buf)
7175 buf_T *buf;
7177 regprog_T *rp = buf->b_cap_prog;
7178 char_u *re;
7180 if (*buf->b_p_spc == NUL)
7181 buf->b_cap_prog = NULL;
7182 else
7184 /* Prepend a ^ so that we only match at one column */
7185 re = concat_str((char_u *)"^", buf->b_p_spc);
7186 if (re != NULL)
7188 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7189 if (buf->b_cap_prog == NULL)
7191 buf->b_cap_prog = rp; /* restore the previous program */
7192 return e_invarg;
7194 vim_free(re);
7198 vim_free(rp);
7199 return NULL;
7201 #endif
7203 #if defined(FEAT_EVAL) || defined(PROTO)
7205 * Set the scriptID for an option, taking care of setting the buffer- or
7206 * window-local value.
7208 static void
7209 set_option_scriptID_idx(opt_idx, opt_flags, id)
7210 int opt_idx;
7211 int opt_flags;
7212 int id;
7214 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7215 int indir = (int)options[opt_idx].indir;
7217 /* Remember where the option was set. For local options need to do that
7218 * in the buffer or window structure. */
7219 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
7220 options[opt_idx].scriptID = id;
7221 if (both || (opt_flags & OPT_LOCAL))
7223 if (indir & PV_BUF)
7224 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7225 else if (indir & PV_WIN)
7226 curwin->w_p_scriptID[indir & PV_MASK] = id;
7229 #endif
7232 * Set the value of a boolean option, and take care of side effects.
7233 * Returns NULL for success, or an error message for an error.
7235 static char_u *
7236 set_bool_option(opt_idx, varp, value, opt_flags)
7237 int opt_idx; /* index in options[] table */
7238 char_u *varp; /* pointer to the option variable */
7239 int value; /* new value */
7240 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7242 int old_value = *(int *)varp;
7244 /* Disallow changing some options from secure mode */
7245 if ((secure
7246 #ifdef HAVE_SANDBOX
7247 || sandbox != 0
7248 #endif
7249 ) && (options[opt_idx].flags & P_SECURE))
7250 return e_secure;
7252 *(int *)varp = value; /* set the new value */
7253 #ifdef FEAT_EVAL
7254 /* Remember where the option was set. */
7255 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
7256 #endif
7258 #ifdef FEAT_GUI
7259 need_mouse_correct = TRUE;
7260 #endif
7262 /* May set global value for local option. */
7263 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7264 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7267 * Handle side effects of changing a bool option.
7270 /* 'compatible' */
7271 if ((int *)varp == &p_cp)
7273 compatible_set();
7276 else if ((int *)varp == &curbuf->b_p_ro)
7278 /* when 'readonly' is reset globally, also reset readonlymode */
7279 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7280 readonlymode = FALSE;
7282 /* when 'readonly' is set may give W10 again */
7283 if (curbuf->b_p_ro)
7284 curbuf->b_did_warn = FALSE;
7286 #ifdef FEAT_TITLE
7287 redraw_titles();
7288 #endif
7291 #ifdef FEAT_TITLE
7292 /* when 'modifiable' is changed, redraw the window title */
7293 else if ((int *)varp == &curbuf->b_p_ma)
7295 redraw_titles();
7297 /* when 'endofline' is changed, redraw the window title */
7298 else if ((int *)varp == &curbuf->b_p_eol)
7300 redraw_titles();
7302 # ifdef FEAT_MBYTE
7303 /* when 'bomb' is changed, redraw the window title and tab page text */
7304 else if ((int *)varp == &curbuf->b_p_bomb)
7306 redraw_titles();
7308 # endif
7309 #endif
7311 /* when 'bin' is set also set some other options */
7312 else if ((int *)varp == &curbuf->b_p_bin)
7314 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7315 #ifdef FEAT_TITLE
7316 redraw_titles();
7317 #endif
7320 #ifdef FEAT_AUTOCMD
7321 /* when 'buflisted' changes, trigger autocommands */
7322 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7324 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7325 NULL, NULL, TRUE, curbuf);
7327 #endif
7329 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7330 else if ((int *)varp == &curbuf->b_p_swf)
7332 if (curbuf->b_p_swf && p_uc)
7333 ml_open_file(curbuf); /* create the swap file */
7334 else
7335 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7336 * buf->b_p_swf */
7337 mf_close_file(curbuf, TRUE); /* remove the swap file */
7340 /* when 'terse' is set change 'shortmess' */
7341 else if ((int *)varp == &p_terse)
7343 char_u *p;
7345 p = vim_strchr(p_shm, SHM_SEARCH);
7347 /* insert 's' in p_shm */
7348 if (p_terse && p == NULL)
7350 STRCPY(IObuff, p_shm);
7351 STRCAT(IObuff, "s");
7352 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
7354 /* remove 's' from p_shm */
7355 else if (!p_terse && p != NULL)
7356 STRMOVE(p, p + 1);
7359 /* when 'paste' is set or reset also change other options */
7360 else if ((int *)varp == &p_paste)
7362 paste_option_changed();
7365 /* when 'insertmode' is set from an autocommand need to do work here */
7366 else if ((int *)varp == &p_im)
7368 if (p_im)
7370 if ((State & INSERT) == 0)
7371 need_start_insertmode = TRUE;
7372 stop_insert_mode = FALSE;
7374 else
7376 need_start_insertmode = FALSE;
7377 stop_insert_mode = TRUE;
7378 if (restart_edit != 0 && mode_displayed)
7379 clear_cmdline = TRUE; /* remove "(insert)" */
7380 restart_edit = 0;
7384 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7385 else if ((int *)varp == &p_ic && p_hls)
7387 redraw_all_later(SOME_VALID);
7390 #ifdef FEAT_SEARCH_EXTRA
7391 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7392 else if ((int *)varp == &p_hls)
7394 no_hlsearch = FALSE;
7396 #endif
7398 #ifdef FEAT_SCROLLBIND
7399 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7400 * at the end of normal_cmd() */
7401 else if ((int *)varp == &curwin->w_p_scb)
7403 if (curwin->w_p_scb)
7404 do_check_scrollbind(FALSE);
7406 #endif
7408 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7409 /* There can be only one window with 'previewwindow' set. */
7410 else if ((int *)varp == &curwin->w_p_pvw)
7412 if (curwin->w_p_pvw)
7414 win_T *win;
7416 for (win = firstwin; win != NULL; win = win->w_next)
7417 if (win->w_p_pvw && win != curwin)
7419 curwin->w_p_pvw = FALSE;
7420 return (char_u *)N_("E590: A preview window already exists");
7424 #endif
7426 /* when 'textmode' is set or reset also change 'fileformat' */
7427 else if ((int *)varp == &curbuf->b_p_tx)
7429 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7432 #ifdef FEAT_FULLSCREEN
7433 /* when 'fullscreen' changes, forward it to the gui */
7434 else if ((int *)varp == &p_fullscreen && gui.in_use)
7436 if (p_fullscreen && !old_value)
7438 guicolor_T fg, bg;
7439 if (fuoptions_flags & FUOPT_BGCOLOR_HLGROUP)
7441 /* Find out background color from colorscheme
7442 * via highlight group id */
7443 syn_id2colors(fuoptions_bgcolor, &fg, &bg);
7445 else
7447 /* set explicit background color */
7448 bg = fuoptions_bgcolor;
7450 gui_mch_enter_fullscreen(fuoptions_flags, bg);
7452 else if (!p_fullscreen && old_value)
7454 gui_mch_leave_fullscreen();
7457 #endif
7459 #if defined(FEAT_ANTIALIAS) && defined(FEAT_GUI_MACVIM)
7460 else if ((int *)varp == &p_antialias)
7462 gui_macvim_set_antialias(p_antialias);
7464 #endif
7466 /* when 'textauto' is set or reset also change 'fileformats' */
7467 else if ((int *)varp == &p_ta)
7468 set_string_option_direct((char_u *)"ffs", -1,
7469 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
7470 OPT_FREE | opt_flags, 0);
7473 * When 'lisp' option changes include/exclude '-' in
7474 * keyword characters.
7476 #ifdef FEAT_LISP
7477 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7479 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7481 #endif
7483 #ifdef FEAT_TITLE
7484 /* when 'title' changed, may need to change the title; same for 'icon' */
7485 else if ((int *)varp == &p_title)
7487 did_set_title(FALSE);
7490 else if ((int *)varp == &p_icon)
7492 did_set_title(TRUE);
7494 #endif
7496 else if ((int *)varp == &curbuf->b_changed)
7498 if (!value)
7499 save_file_ff(curbuf); /* Buffer is unchanged */
7500 #ifdef FEAT_TITLE
7501 redraw_titles();
7502 #endif
7503 #ifdef FEAT_AUTOCMD
7504 modified_was_set = value;
7505 #endif
7508 #ifdef BACKSLASH_IN_FILENAME
7509 else if ((int *)varp == &p_ssl)
7511 if (p_ssl)
7513 psepc = '/';
7514 psepcN = '\\';
7515 pseps[0] = '/';
7517 else
7519 psepc = '\\';
7520 psepcN = '/';
7521 pseps[0] = '\\';
7524 /* need to adjust the file name arguments and buffer names. */
7525 buflist_slash_adjust();
7526 alist_slash_adjust();
7527 # ifdef FEAT_EVAL
7528 scriptnames_slash_adjust();
7529 # endif
7531 #endif
7533 /* If 'wrap' is set, set w_leftcol to zero. */
7534 else if ((int *)varp == &curwin->w_p_wrap)
7536 if (curwin->w_p_wrap)
7537 curwin->w_leftcol = 0;
7540 #ifdef FEAT_WINDOWS
7541 else if ((int *)varp == &p_ea)
7543 if (p_ea && !old_value)
7544 win_equal(curwin, FALSE, 0);
7546 #endif
7548 else if ((int *)varp == &p_wiv)
7551 * When 'weirdinvert' changed, set/reset 't_xs'.
7552 * Then set 'weirdinvert' according to value of 't_xs'.
7554 if (p_wiv && !old_value)
7555 T_XS = (char_u *)"y";
7556 else if (!p_wiv && old_value)
7557 T_XS = empty_option;
7558 p_wiv = (*T_XS != NUL);
7561 #ifdef FEAT_BEVAL
7562 else if ((int *)varp == &p_beval)
7564 if (p_beval == TRUE)
7565 gui_mch_enable_beval_area(balloonEval);
7566 else
7567 gui_mch_disable_beval_area(balloonEval);
7569 #endif
7571 #ifdef FEAT_AUTOCHDIR
7572 else if ((int *)varp == &p_acd)
7574 /* Change directories when the 'acd' option is set now. */
7575 DO_AUTOCHDIR
7577 #endif
7579 #ifdef FEAT_DIFF
7580 /* 'diff' */
7581 else if ((int *)varp == &curwin->w_p_diff)
7583 /* May add or remove the buffer from the list of diff buffers. */
7584 diff_buf_adjust(curwin);
7585 # ifdef FEAT_FOLDING
7586 if (foldmethodIsDiff(curwin))
7587 foldUpdateAll(curwin);
7588 # endif
7590 #endif
7592 #ifdef USE_IM_CONTROL
7593 /* 'imdisable' */
7594 else if ((int *)varp == &p_imdisable)
7596 /* Only de-activate it here, it will be enabled when changing mode. */
7597 if (p_imdisable)
7599 im_set_active(FALSE);
7601 #ifdef FEAT_GUI_MACVIM
7602 im_set_control(!p_imdisable);
7603 #endif
7605 #endif
7607 #ifdef FEAT_SPELL
7608 /* 'spell' */
7609 else if ((int *)varp == &curwin->w_p_spell)
7611 if (curwin->w_p_spell)
7613 char_u *errmsg = did_set_spelllang(curbuf);
7615 if (errmsg != NULL)
7616 EMSG(_(errmsg));
7619 #endif
7621 #ifdef FEAT_FKMAP
7622 else if ((int *)varp == &p_altkeymap)
7624 if (old_value != p_altkeymap)
7626 if (!p_altkeymap)
7628 p_hkmap = p_fkmap;
7629 p_fkmap = 0;
7631 else
7633 p_fkmap = p_hkmap;
7634 p_hkmap = 0;
7636 (void)init_chartab();
7641 * In case some second language keymapping options have changed, check
7642 * and correct the setting in a consistent way.
7646 * If hkmap or fkmap are set, reset Arabic keymapping.
7648 if ((p_hkmap || p_fkmap) && p_altkeymap)
7650 p_altkeymap = p_fkmap;
7651 # ifdef FEAT_ARABIC
7652 curwin->w_p_arab = FALSE;
7653 # endif
7654 (void)init_chartab();
7658 * If hkmap set, reset Farsi keymapping.
7660 if (p_hkmap && p_altkeymap)
7662 p_altkeymap = 0;
7663 p_fkmap = 0;
7664 # ifdef FEAT_ARABIC
7665 curwin->w_p_arab = FALSE;
7666 # endif
7667 (void)init_chartab();
7671 * If fkmap set, reset Hebrew keymapping.
7673 if (p_fkmap && !p_altkeymap)
7675 p_altkeymap = 1;
7676 p_hkmap = 0;
7677 # ifdef FEAT_ARABIC
7678 curwin->w_p_arab = FALSE;
7679 # endif
7680 (void)init_chartab();
7682 #endif
7684 #ifdef FEAT_ARABIC
7685 if ((int *)varp == &curwin->w_p_arab)
7687 if (curwin->w_p_arab)
7690 * 'arabic' is set, handle various sub-settings.
7692 if (!p_tbidi)
7694 /* set rightleft mode */
7695 if (!curwin->w_p_rl)
7697 curwin->w_p_rl = TRUE;
7698 changed_window_setting();
7701 /* Enable Arabic shaping (major part of what Arabic requires) */
7702 if (!p_arshape)
7704 p_arshape = TRUE;
7705 redraw_later_clear();
7709 /* Arabic requires a utf-8 encoding, inform the user if its not
7710 * set. */
7711 if (STRCMP(p_enc, "utf-8") != 0)
7713 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7715 msg_source(hl_attr(HLF_W));
7716 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7717 #ifdef FEAT_EVAL
7718 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7719 #endif
7722 # ifdef FEAT_MBYTE
7723 /* set 'delcombine' */
7724 p_deco = TRUE;
7725 # endif
7727 # ifdef FEAT_KEYMAP
7728 /* Force-set the necessary keymap for arabic */
7729 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7730 OPT_LOCAL);
7731 # endif
7732 # ifdef FEAT_FKMAP
7733 p_altkeymap = 0;
7734 p_hkmap = 0;
7735 p_fkmap = 0;
7736 (void)init_chartab();
7737 # endif
7739 else
7742 * 'arabic' is reset, handle various sub-settings.
7744 if (!p_tbidi)
7746 /* reset rightleft mode */
7747 if (curwin->w_p_rl)
7749 curwin->w_p_rl = FALSE;
7750 changed_window_setting();
7753 /* 'arabicshape' isn't reset, it is a global option and
7754 * another window may still need it "on". */
7757 /* 'delcombine' isn't reset, it is a global option and another
7758 * window may still want it "on". */
7760 # ifdef FEAT_KEYMAP
7761 /* Revert to the default keymap */
7762 curbuf->b_p_iminsert = B_IMODE_NONE;
7763 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7764 # endif
7767 #endif
7770 * End of handling side effects for bool options.
7773 options[opt_idx].flags |= P_WAS_SET;
7775 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7776 if (curwin->w_curswant != MAXCOL)
7777 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7778 check_redraw(options[opt_idx].flags);
7780 return NULL;
7784 * Set the value of a number option, and take care of side effects.
7785 * Returns NULL for success, or an error message for an error.
7787 static char_u *
7788 set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
7789 int opt_idx; /* index in options[] table */
7790 char_u *varp; /* pointer to the option variable */
7791 long value; /* new value */
7792 char_u *errbuf; /* buffer for error messages */
7793 size_t errbuflen; /* length of "errbuf" */
7794 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7795 OPT_MODELINE */
7797 char_u *errmsg = NULL;
7798 long old_value = *(long *)varp;
7799 long old_Rows = Rows; /* remember old Rows */
7800 long old_Columns = Columns; /* remember old Columns */
7801 long *pp = (long *)varp;
7803 /* Disallow changing some options from secure mode. */
7804 if ((secure
7805 #ifdef HAVE_SANDBOX
7806 || sandbox != 0
7807 #endif
7808 ) && (options[opt_idx].flags & P_SECURE))
7809 return e_secure;
7811 *pp = value;
7812 #ifdef FEAT_EVAL
7813 /* Remember where the option was set. */
7814 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
7815 #endif
7816 #ifdef FEAT_GUI
7817 need_mouse_correct = TRUE;
7818 #endif
7820 if (curbuf->b_p_sw <= 0)
7822 errmsg = e_positive;
7823 curbuf->b_p_sw = curbuf->b_p_ts;
7827 * Number options that need some action when changed
7829 #ifdef FEAT_WINDOWS
7830 if (pp == &p_wh || pp == &p_hh)
7832 if (p_wh < 1)
7834 errmsg = e_positive;
7835 p_wh = 1;
7837 if (p_wmh > p_wh)
7839 errmsg = e_winheight;
7840 p_wh = p_wmh;
7842 if (p_hh < 0)
7844 errmsg = e_positive;
7845 p_hh = 0;
7848 /* Change window height NOW */
7849 if (lastwin != firstwin)
7851 if (pp == &p_wh && curwin->w_height < p_wh)
7852 win_setheight((int)p_wh);
7853 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7854 win_setheight((int)p_hh);
7858 /* 'winminheight' */
7859 else if (pp == &p_wmh)
7861 if (p_wmh < 0)
7863 errmsg = e_positive;
7864 p_wmh = 0;
7866 if (p_wmh > p_wh)
7868 errmsg = e_winheight;
7869 p_wmh = p_wh;
7871 win_setminheight();
7874 # ifdef FEAT_VERTSPLIT
7875 else if (pp == &p_wiw)
7877 if (p_wiw < 1)
7879 errmsg = e_positive;
7880 p_wiw = 1;
7882 if (p_wmw > p_wiw)
7884 errmsg = e_winwidth;
7885 p_wiw = p_wmw;
7888 /* Change window width NOW */
7889 if (lastwin != firstwin && curwin->w_width < p_wiw)
7890 win_setwidth((int)p_wiw);
7893 /* 'winminwidth' */
7894 else if (pp == &p_wmw)
7896 if (p_wmw < 0)
7898 errmsg = e_positive;
7899 p_wmw = 0;
7901 if (p_wmw > p_wiw)
7903 errmsg = e_winwidth;
7904 p_wmw = p_wiw;
7906 win_setminheight();
7908 # endif
7910 #endif
7912 #ifdef FEAT_WINDOWS
7913 /* (re)set last window status line */
7914 else if (pp == &p_ls)
7916 last_status(FALSE);
7919 /* (re)set tab page line */
7920 else if (pp == &p_stal)
7922 shell_new_rows(); /* recompute window positions and heights */
7924 #endif
7926 #ifdef FEAT_GUI
7927 else if (pp == &p_linespace || pp == &p_charspace)
7929 /* Recompute gui.char_height and resize the Vim window to keep the
7930 * same number of lines. */
7931 if (gui.in_use && gui_mch_adjust_charheight() == OK)
7932 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
7934 #endif
7936 #ifdef FEAT_FOLDING
7937 /* 'foldlevel' */
7938 else if (pp == &curwin->w_p_fdl)
7940 if (curwin->w_p_fdl < 0)
7941 curwin->w_p_fdl = 0;
7942 newFoldLevel();
7945 /* 'foldminlines' */
7946 else if (pp == &curwin->w_p_fml)
7948 foldUpdateAll(curwin);
7951 /* 'foldnestmax' */
7952 else if (pp == &curwin->w_p_fdn)
7954 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7955 foldUpdateAll(curwin);
7958 /* 'foldcolumn' */
7959 else if (pp == &curwin->w_p_fdc)
7961 if (curwin->w_p_fdc < 0)
7963 errmsg = e_positive;
7964 curwin->w_p_fdc = 0;
7966 else if (curwin->w_p_fdc > 12)
7968 errmsg = e_invarg;
7969 curwin->w_p_fdc = 12;
7973 /* 'shiftwidth' or 'tabstop' */
7974 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7976 if (foldmethodIsIndent(curwin))
7977 foldUpdateAll(curwin);
7979 #endif /* FEAT_FOLDING */
7981 #ifdef FEAT_MBYTE
7982 /* 'maxcombine' */
7983 else if (pp == &p_mco)
7985 if (p_mco > MAX_MCO)
7986 p_mco = MAX_MCO;
7987 else if (p_mco < 0)
7988 p_mco = 0;
7989 screenclear(); /* will re-allocate the screen */
7991 #endif
7993 else if (pp == &curbuf->b_p_iminsert)
7995 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7997 errmsg = e_invarg;
7998 curbuf->b_p_iminsert = B_IMODE_NONE;
8000 p_iminsert = curbuf->b_p_iminsert;
8001 if (termcap_active) /* don't do this in the alternate screen */
8002 showmode();
8003 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8004 /* Show/unshow value of 'keymap' in status lines. */
8005 status_redraw_curbuf();
8006 #endif
8009 else if (pp == &p_window)
8011 if (p_window < 1)
8012 p_window = 1;
8013 else if (p_window >= Rows)
8014 p_window = Rows - 1;
8017 else if (pp == &curbuf->b_p_imsearch)
8019 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8021 errmsg = e_invarg;
8022 curbuf->b_p_imsearch = B_IMODE_NONE;
8024 p_imsearch = curbuf->b_p_imsearch;
8027 #ifdef FEAT_TITLE
8028 /* if 'titlelen' has changed, redraw the title */
8029 else if (pp == &p_titlelen)
8031 if (p_titlelen < 0)
8033 errmsg = e_positive;
8034 p_titlelen = 85;
8036 if (starting != NO_SCREEN && old_value != p_titlelen)
8037 need_maketitle = TRUE;
8039 #endif
8041 /* if p_ch changed value, change the command line height */
8042 else if (pp == &p_ch)
8044 if (p_ch < 1)
8046 errmsg = e_positive;
8047 p_ch = 1;
8049 if (p_ch > Rows - min_rows() + 1)
8050 p_ch = Rows - min_rows() + 1;
8052 /* Only compute the new window layout when startup has been
8053 * completed. Otherwise the frame sizes may be wrong. */
8054 if (p_ch != old_value && full_screen
8055 #ifdef FEAT_GUI
8056 && !gui.starting
8057 #endif
8059 command_height();
8062 /* when 'updatecount' changes from zero to non-zero, open swap files */
8063 else if (pp == &p_uc)
8065 if (p_uc < 0)
8067 errmsg = e_positive;
8068 p_uc = 100;
8070 if (p_uc && !old_value)
8071 ml_open_files();
8073 #ifdef MZSCHEME_GUI_THREADS
8074 else if (pp == &p_mzq)
8075 mzvim_reset_timer();
8076 #endif
8078 /* sync undo before 'undolevels' changes */
8079 else if (pp == &p_ul)
8081 /* use the old value, otherwise u_sync() may not work properly */
8082 p_ul = old_value;
8083 u_sync(TRUE);
8084 p_ul = value;
8087 #ifdef FEAT_LINEBREAK
8088 /* 'numberwidth' must be positive */
8089 else if (pp == &curwin->w_p_nuw)
8091 if (curwin->w_p_nuw < 1)
8093 errmsg = e_positive;
8094 curwin->w_p_nuw = 1;
8096 if (curwin->w_p_nuw > 10)
8098 errmsg = e_invarg;
8099 curwin->w_p_nuw = 10;
8101 curwin->w_nrwidth_line_count = 0;
8103 #endif
8105 #if defined(FEAT_TRANSPARENCY)
8106 /* 'transparency' is a number between 0 and 100 */
8107 else if (pp == &p_transp)
8109 if (p_transp < 0 || p_transp > 100)
8111 errmsg = e_invarg;
8112 p_transp = old_value;
8114 else if (gui.in_use)
8115 gui_mch_new_colors();
8117 #endif
8120 * Check the bounds for numeric options here
8122 if (Rows < min_rows() && full_screen)
8124 if (errbuf != NULL)
8126 vim_snprintf((char *)errbuf, errbuflen,
8127 _("E593: Need at least %d lines"), min_rows());
8128 errmsg = errbuf;
8130 Rows = min_rows();
8132 if (Columns < MIN_COLUMNS && full_screen)
8134 if (errbuf != NULL)
8136 vim_snprintf((char *)errbuf, errbuflen,
8137 _("E594: Need at least %d columns"), MIN_COLUMNS);
8138 errmsg = errbuf;
8140 Columns = MIN_COLUMNS;
8142 /* Limit the values to avoid an overflow in Rows * Columns. */
8143 if (Columns > 10000)
8144 Columns = 10000;
8145 if (Rows > 1000)
8146 Rows = 1000;
8148 #ifdef DJGPP
8149 /* avoid a crash by checking for a too large value of 'columns' */
8150 if (old_Columns != Columns && full_screen && term_console)
8151 mch_check_columns();
8152 #endif
8155 * If the screen (shell) height has been changed, assume it is the
8156 * physical screenheight.
8158 if (old_Rows != Rows || old_Columns != Columns)
8160 /* Changing the screen size is not allowed while updating the screen. */
8161 if (updating_screen)
8162 *pp = old_value;
8163 else if (full_screen
8164 #ifdef FEAT_GUI
8165 && !gui.starting
8166 #endif
8168 set_shellsize((int)Columns, (int)Rows, TRUE);
8169 else
8171 /* Postpone the resizing; check the size and cmdline position for
8172 * messages. */
8173 check_shellsize();
8174 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8175 cmdline_row = Rows - p_ch;
8177 if (p_window >= Rows || !option_was_set((char_u *)"window"))
8178 p_window = Rows - 1;
8181 if (curbuf->b_p_sts < 0)
8183 errmsg = e_positive;
8184 curbuf->b_p_sts = 0;
8186 if (curbuf->b_p_ts <= 0)
8188 errmsg = e_positive;
8189 curbuf->b_p_ts = 8;
8191 if (curbuf->b_p_tw < 0)
8193 errmsg = e_positive;
8194 curbuf->b_p_tw = 0;
8196 if (p_tm < 0)
8198 errmsg = e_positive;
8199 p_tm = 0;
8201 if ((curwin->w_p_scr <= 0
8202 || (curwin->w_p_scr > curwin->w_height
8203 && curwin->w_height > 0))
8204 && full_screen)
8206 if (pp == &(curwin->w_p_scr))
8208 if (curwin->w_p_scr != 0)
8209 errmsg = e_scroll;
8210 win_comp_scroll(curwin);
8212 /* If 'scroll' became invalid because of a side effect silently adjust
8213 * it. */
8214 else if (curwin->w_p_scr <= 0)
8215 curwin->w_p_scr = 1;
8216 else /* curwin->w_p_scr > curwin->w_height */
8217 curwin->w_p_scr = curwin->w_height;
8219 if (p_hi < 0)
8221 errmsg = e_positive;
8222 p_hi = 0;
8224 if (p_report < 0)
8226 errmsg = e_positive;
8227 p_report = 1;
8229 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
8231 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8232 p_sj = Rows / 2;
8233 else
8235 errmsg = e_scroll;
8236 p_sj = 1;
8239 if (p_so < 0 && full_screen)
8241 errmsg = e_scroll;
8242 p_so = 0;
8244 if (p_siso < 0 && full_screen)
8246 errmsg = e_positive;
8247 p_siso = 0;
8249 #ifdef FEAT_CMDWIN
8250 if (p_cwh < 1)
8252 errmsg = e_positive;
8253 p_cwh = 1;
8255 #endif
8256 if (p_ut < 0)
8258 errmsg = e_positive;
8259 p_ut = 2000;
8261 if (p_ss < 0)
8263 errmsg = e_positive;
8264 p_ss = 0;
8267 /* May set global value for local option. */
8268 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8269 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8271 options[opt_idx].flags |= P_WAS_SET;
8273 comp_col(); /* in case 'columns' or 'ls' changed */
8274 if (curwin->w_curswant != MAXCOL)
8275 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8276 check_redraw(options[opt_idx].flags);
8278 return errmsg;
8282 * Called after an option changed: check if something needs to be redrawn.
8284 static void
8285 check_redraw(flags)
8286 long_u flags;
8288 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8289 int clear = (flags & P_RCLR) == P_RCLR;
8290 int all = ((flags & P_RALL) == P_RALL || clear);
8292 #ifdef FEAT_WINDOWS
8293 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8294 status_redraw_all();
8295 #endif
8297 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8298 changed_window_setting();
8299 if (flags & P_RBUF)
8300 redraw_curbuf_later(NOT_VALID);
8301 if (clear)
8302 redraw_all_later(CLEAR);
8303 else if (all)
8304 redraw_all_later(NOT_VALID);
8308 * Find index for option 'arg'.
8309 * Return -1 if not found.
8311 static int
8312 findoption(arg)
8313 char_u *arg;
8315 int opt_idx;
8316 char *s, *p;
8317 static short quick_tab[27] = {0, 0}; /* quick access table */
8318 int is_term_opt;
8321 * For first call: Initialize the quick-access table.
8322 * It contains the index for the first option that starts with a certain
8323 * letter. There are 26 letters, plus the first "t_" option.
8325 if (quick_tab[1] == 0)
8327 p = options[0].fullname;
8328 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8330 if (s[0] != p[0])
8332 if (s[0] == 't' && s[1] == '_')
8333 quick_tab[26] = opt_idx;
8334 else
8335 quick_tab[CharOrdLow(s[0])] = opt_idx;
8337 p = s;
8342 * Check for name starting with an illegal character.
8344 #ifdef EBCDIC
8345 if (!islower(arg[0]))
8346 #else
8347 if (arg[0] < 'a' || arg[0] > 'z')
8348 #endif
8349 return -1;
8351 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8352 if (is_term_opt)
8353 opt_idx = quick_tab[26];
8354 else
8355 opt_idx = quick_tab[CharOrdLow(arg[0])];
8356 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8358 if (STRCMP(arg, s) == 0) /* match full name */
8359 break;
8361 if (s == NULL && !is_term_opt)
8363 opt_idx = quick_tab[CharOrdLow(arg[0])];
8364 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8366 s = options[opt_idx].shortname;
8367 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8368 break;
8369 s = NULL;
8372 if (s == NULL)
8373 opt_idx = -1;
8374 return opt_idx;
8377 #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
8379 * Get the value for an option.
8381 * Returns:
8382 * Number or Toggle option: 1, *numval gets value.
8383 * String option: 0, *stringval gets allocated string.
8384 * Hidden Number or Toggle option: -1.
8385 * hidden String option: -2.
8386 * unknown option: -3.
8389 get_option_value(name, numval, stringval, opt_flags)
8390 char_u *name;
8391 long *numval;
8392 char_u **stringval; /* NULL when only checking existance */
8393 int opt_flags;
8395 int opt_idx;
8396 char_u *varp;
8398 opt_idx = findoption(name);
8399 if (opt_idx < 0) /* unknown option */
8400 return -3;
8402 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8404 if (options[opt_idx].flags & P_STRING)
8406 if (varp == NULL) /* hidden option */
8407 return -2;
8408 if (stringval != NULL)
8410 #ifdef FEAT_CRYPT
8411 /* never return the value of the crypt key */
8412 if ((char_u **)varp == &curbuf->b_p_key
8413 && **(char_u **)(varp) != NUL)
8414 *stringval = vim_strsave((char_u *)"*****");
8415 else
8416 #endif
8417 *stringval = vim_strsave(*(char_u **)(varp));
8419 return 0;
8422 if (varp == NULL) /* hidden option */
8423 return -1;
8424 if (options[opt_idx].flags & P_NUM)
8425 *numval = *(long *)varp;
8426 else
8428 /* Special case: 'modified' is b_changed, but we also want to consider
8429 * it set when 'ff' or 'fenc' changed. */
8430 if ((int *)varp == &curbuf->b_changed)
8431 *numval = curbufIsChanged();
8432 else
8433 *numval = *(int *)varp;
8435 return 1;
8437 #endif
8440 * Set the value of option "name".
8441 * Use "string" for string options, use "number" for other options.
8443 void
8444 set_option_value(name, number, string, opt_flags)
8445 char_u *name;
8446 long number;
8447 char_u *string;
8448 int opt_flags; /* OPT_LOCAL or 0 (both) */
8450 int opt_idx;
8451 char_u *varp;
8452 long_u flags;
8454 opt_idx = findoption(name);
8455 if (opt_idx < 0)
8456 EMSG2(_("E355: Unknown option: %s"), name);
8457 else
8459 flags = options[opt_idx].flags;
8460 #ifdef HAVE_SANDBOX
8461 /* Disallow changing some options in the sandbox */
8462 if (sandbox > 0 && (flags & P_SECURE))
8464 EMSG(_(e_sandbox));
8465 return;
8467 #endif
8468 if (flags & P_STRING)
8469 set_string_option(opt_idx, string, opt_flags);
8470 else
8472 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8473 if (varp != NULL) /* hidden option is not changed */
8475 if (number == 0 && string != NULL)
8477 int idx;
8479 /* Either we are given a string or we are setting option
8480 * to zero. */
8481 for (idx = 0; string[idx] == '0'; ++idx)
8483 if (string[idx] != NUL || idx == 0)
8485 /* There's another character after zeros or the string
8486 * is empty. In both cases, we are trying to set a
8487 * num option using a string. */
8488 EMSG3(_("E521: Number required: &%s = '%s'"),
8489 name, string);
8490 return; /* do nothing as we hit an error */
8494 if (flags & P_NUM)
8495 (void)set_num_option(opt_idx, varp, number,
8496 NULL, 0, opt_flags);
8497 else
8498 (void)set_bool_option(opt_idx, varp, (int)number,
8499 opt_flags);
8506 * Get the terminal code for a terminal option.
8507 * Returns NULL when not found.
8509 char_u *
8510 get_term_code(tname)
8511 char_u *tname;
8513 int opt_idx;
8514 char_u *varp;
8516 if (tname[0] != 't' || tname[1] != '_' ||
8517 tname[2] == NUL || tname[3] == NUL)
8518 return NULL;
8519 if ((opt_idx = findoption(tname)) >= 0)
8521 varp = get_varp(&(options[opt_idx]));
8522 if (varp != NULL)
8523 varp = *(char_u **)(varp);
8524 return varp;
8526 return find_termcode(tname + 2);
8529 char_u *
8530 get_highlight_default()
8532 int i;
8534 i = findoption((char_u *)"hl");
8535 if (i >= 0)
8536 return options[i].def_val[VI_DEFAULT];
8537 return (char_u *)NULL;
8540 #if defined(FEAT_MBYTE) || defined(PROTO)
8541 char_u *
8542 get_encoding_default()
8544 int i;
8546 i = findoption((char_u *)"enc");
8547 if (i >= 0)
8548 return options[i].def_val[VI_DEFAULT];
8549 return (char_u *)NULL;
8551 #endif
8554 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8556 static int
8557 find_key_option(arg)
8558 char_u *arg;
8560 int key;
8561 int modifiers;
8564 * Don't use get_special_key_code() for t_xx, we don't want it to call
8565 * add_termcap_entry().
8567 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8568 key = TERMCAP2KEY(arg[2], arg[3]);
8569 else
8571 --arg; /* put arg at the '<' */
8572 modifiers = 0;
8573 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
8574 if (modifiers) /* can't handle modifiers here */
8575 key = 0;
8577 return key;
8581 * if 'all' == 0: show changed options
8582 * if 'all' == 1: show all normal options
8583 * if 'all' == 2: show all terminal options
8585 static void
8586 showoptions(all, opt_flags)
8587 int all;
8588 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8590 struct vimoption *p;
8591 int col;
8592 int isterm;
8593 char_u *varp;
8594 struct vimoption **items;
8595 int item_count;
8596 int run;
8597 int row, rows;
8598 int cols;
8599 int i;
8600 int len;
8602 #define INC 20
8603 #define GAP 3
8605 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8606 PARAM_COUNT));
8607 if (items == NULL)
8608 return;
8610 /* Highlight title */
8611 if (all == 2)
8612 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8613 else if (opt_flags & OPT_GLOBAL)
8614 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8615 else if (opt_flags & OPT_LOCAL)
8616 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8617 else
8618 MSG_PUTS_TITLE(_("\n--- Options ---"));
8621 * do the loop two times:
8622 * 1. display the short items
8623 * 2. display the long items (only strings and numbers)
8625 for (run = 1; run <= 2 && !got_int; ++run)
8628 * collect the items in items[]
8630 item_count = 0;
8631 for (p = &options[0]; p->fullname != NULL; p++)
8633 varp = NULL;
8634 isterm = istermoption(p);
8635 if (opt_flags != 0)
8637 if (p->indir != PV_NONE && !isterm)
8638 varp = get_varp_scope(p, opt_flags);
8640 else
8641 varp = get_varp(p);
8642 if (varp != NULL
8643 && ((all == 2 && isterm)
8644 || (all == 1 && !isterm)
8645 || (all == 0 && !optval_default(p, varp))))
8647 if (p->flags & P_BOOL)
8648 len = 1; /* a toggle option fits always */
8649 else
8651 option_value2string(p, opt_flags);
8652 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8654 if ((len <= INC - GAP && run == 1) ||
8655 (len > INC - GAP && run == 2))
8656 items[item_count++] = p;
8661 * display the items
8663 if (run == 1)
8665 cols = (Columns + GAP - 3) / INC;
8666 if (cols == 0)
8667 cols = 1;
8668 rows = (item_count + cols - 1) / cols;
8670 else /* run == 2 */
8671 rows = item_count;
8672 for (row = 0; row < rows && !got_int; ++row)
8674 msg_putchar('\n'); /* go to next line */
8675 if (got_int) /* 'q' typed in more */
8676 break;
8677 col = 0;
8678 for (i = row; i < item_count; i += rows)
8680 msg_col = col; /* make columns */
8681 showoneopt(items[i], opt_flags);
8682 col += INC;
8684 out_flush();
8685 ui_breakcheck();
8688 vim_free(items);
8692 * Return TRUE if option "p" has its default value.
8694 static int
8695 optval_default(p, varp)
8696 struct vimoption *p;
8697 char_u *varp;
8699 int dvi;
8701 if (varp == NULL)
8702 return TRUE; /* hidden option is always at default */
8703 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8704 if (p->flags & P_NUM)
8705 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
8706 if (p->flags & P_BOOL)
8707 /* the cast to long is required for Manx C, long_i is
8708 * needed for MSVC */
8709 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
8710 /* P_STRING */
8711 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8715 * showoneopt: show the value of one option
8716 * must not be called with a hidden option!
8718 static void
8719 showoneopt(p, opt_flags)
8720 struct vimoption *p;
8721 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8723 char_u *varp;
8724 int save_silent = silent_mode;
8726 silent_mode = FALSE;
8727 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
8729 varp = get_varp_scope(p, opt_flags);
8731 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8732 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8733 ? !curbufIsChanged() : !*(int *)varp))
8734 MSG_PUTS("no");
8735 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8736 MSG_PUTS("--");
8737 else
8738 MSG_PUTS(" ");
8739 MSG_PUTS(p->fullname);
8740 if (!(p->flags & P_BOOL))
8742 msg_putchar('=');
8743 /* put value string in NameBuff */
8744 option_value2string(p, opt_flags);
8745 msg_outtrans(NameBuff);
8748 silent_mode = save_silent;
8749 info_message = FALSE;
8753 * Write modified options as ":set" commands to a file.
8755 * There are three values for "opt_flags":
8756 * OPT_GLOBAL: Write global option values and fresh values of
8757 * buffer-local options (used for start of a session
8758 * file).
8759 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8760 * curwin (used for a vimrc file).
8761 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8762 * and local values for window-local options of
8763 * curwin. Local values are also written when at the
8764 * default value, because a modeline or autocommand
8765 * may have set them when doing ":edit file" and the
8766 * user has set them back at the default or fresh
8767 * value.
8768 * When "local_only" is TRUE, don't write fresh
8769 * values, only local values (for ":mkview").
8770 * (fresh value = value used for a new buffer or window for a local option).
8772 * Return FAIL on error, OK otherwise.
8775 makeset(fd, opt_flags, local_only)
8776 FILE *fd;
8777 int opt_flags;
8778 int local_only;
8780 struct vimoption *p;
8781 char_u *varp; /* currently used value */
8782 char_u *varp_fresh; /* local value */
8783 char_u *varp_local = NULL; /* fresh value */
8784 char *cmd;
8785 int round;
8786 int pri;
8789 * The options that don't have a default (terminal name, columns, lines)
8790 * are never written. Terminal options are also not written.
8791 * Do the loop over "options[]" twice: once for options with the
8792 * P_PRI_MKRC flag and once without.
8794 for (pri = 1; pri >= 0; --pri)
8796 for (p = &options[0]; !istermoption(p); p++)
8797 if (!(p->flags & P_NO_MKRC)
8798 && !istermoption(p)
8799 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
8801 /* skip global option when only doing locals */
8802 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8803 continue;
8805 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8806 * file, they are always buffer-specific. */
8807 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8808 continue;
8810 /* Global values are only written when not at the default value. */
8811 varp = get_varp_scope(p, opt_flags);
8812 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8813 continue;
8815 round = 2;
8816 if (p->indir != PV_NONE)
8818 if (p->var == VAR_WIN)
8820 /* skip window-local option when only doing globals */
8821 if (!(opt_flags & OPT_LOCAL))
8822 continue;
8823 /* When fresh value of window-local option is not at the
8824 * default, need to write it too. */
8825 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8827 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8828 if (!optval_default(p, varp_fresh))
8830 round = 1;
8831 varp_local = varp;
8832 varp = varp_fresh;
8838 /* Round 1: fresh value for window-local options.
8839 * Round 2: other values */
8840 for ( ; round <= 2; varp = varp_local, ++round)
8842 if (round == 1 || (opt_flags & OPT_GLOBAL))
8843 cmd = "set";
8844 else
8845 cmd = "setlocal";
8847 if (p->flags & P_BOOL)
8849 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8850 return FAIL;
8852 else if (p->flags & P_NUM)
8854 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8855 return FAIL;
8857 else /* P_STRING */
8859 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8860 int do_endif = FALSE;
8862 /* Don't set 'syntax' and 'filetype' again if the value is
8863 * already right, avoids reloading the syntax file. */
8864 if (
8865 # if defined(FEAT_SYN_HL)
8866 p->indir == PV_SYN
8867 # if defined(FEAT_AUTOCMD)
8869 # endif
8870 # endif
8871 # if defined(FEAT_AUTOCMD)
8872 p->indir == PV_FT
8873 # endif
8876 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8877 *(char_u **)(varp)) < 0
8878 || put_eol(fd) < 0)
8879 return FAIL;
8880 do_endif = TRUE;
8882 #endif
8883 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8884 (p->flags & P_EXPAND) != 0) == FAIL)
8885 return FAIL;
8886 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8887 if (do_endif)
8889 if (put_line(fd, "endif") == FAIL)
8890 return FAIL;
8892 #endif
8897 return OK;
8900 #if defined(FEAT_FOLDING) || defined(PROTO)
8902 * Generate set commands for the local fold options only. Used when
8903 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8906 makefoldset(fd)
8907 FILE *fd;
8909 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8910 # ifdef FEAT_EVAL
8911 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8912 == FAIL
8913 # endif
8914 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8915 == FAIL
8916 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8917 == FAIL
8918 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8919 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8920 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8921 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8923 return FAIL;
8925 return OK;
8927 #endif
8929 static int
8930 put_setstring(fd, cmd, name, valuep, expand)
8931 FILE *fd;
8932 char *cmd;
8933 char *name;
8934 char_u **valuep;
8935 int expand;
8937 char_u *s;
8938 char_u buf[MAXPATHL];
8940 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8941 return FAIL;
8942 if (*valuep != NULL)
8944 /* Output 'pastetoggle' as key names. For other
8945 * options some characters have to be escaped with
8946 * CTRL-V or backslash */
8947 if (valuep == &p_pt)
8949 s = *valuep;
8950 while (*s != NUL)
8951 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
8952 return FAIL;
8954 else if (expand)
8956 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8957 if (put_escstr(fd, buf, 2) == FAIL)
8958 return FAIL;
8960 else if (put_escstr(fd, *valuep, 2) == FAIL)
8961 return FAIL;
8963 if (put_eol(fd) < 0)
8964 return FAIL;
8965 return OK;
8968 static int
8969 put_setnum(fd, cmd, name, valuep)
8970 FILE *fd;
8971 char *cmd;
8972 char *name;
8973 long *valuep;
8975 long wc;
8977 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8978 return FAIL;
8979 if (wc_use_keyname((char_u *)valuep, &wc))
8981 /* print 'wildchar' and 'wildcharm' as a key name */
8982 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8983 return FAIL;
8985 else if (fprintf(fd, "%ld", *valuep) < 0)
8986 return FAIL;
8987 if (put_eol(fd) < 0)
8988 return FAIL;
8989 return OK;
8992 static int
8993 put_setbool(fd, cmd, name, value)
8994 FILE *fd;
8995 char *cmd;
8996 char *name;
8997 int value;
8999 if (value < 0) /* global/local option using global value */
9000 return OK;
9001 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9002 || put_eol(fd) < 0)
9003 return FAIL;
9004 return OK;
9008 * Clear all the terminal options.
9009 * If the option has been allocated, free the memory.
9010 * Terminal options are never hidden or indirect.
9012 void
9013 clear_termoptions()
9016 * Reset a few things before clearing the old options. This may cause
9017 * outputting a few things that the terminal doesn't understand, but the
9018 * screen will be cleared later, so this is OK.
9020 #ifdef FEAT_MOUSE_TTY
9021 mch_setmouse(FALSE); /* switch mouse off */
9022 #endif
9023 #ifdef FEAT_TITLE
9024 mch_restore_title(3); /* restore window titles */
9025 #endif
9026 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9027 /* When starting the GUI close the display opened for the clipboard.
9028 * After restoring the title, because that will need the display. */
9029 if (gui.starting)
9030 clear_xterm_clip();
9031 #endif
9032 #ifdef WIN3264
9034 * Check if this is allowed now.
9036 if (can_end_termcap_mode(FALSE) == TRUE)
9037 #endif
9038 stoptermcap(); /* stop termcap mode */
9040 free_termoptions();
9043 void
9044 free_termoptions()
9046 struct vimoption *p;
9048 for (p = &options[0]; p->fullname != NULL; p++)
9049 if (istermoption(p))
9051 if (p->flags & P_ALLOCED)
9052 free_string_option(*(char_u **)(p->var));
9053 if (p->flags & P_DEF_ALLOCED)
9054 free_string_option(p->def_val[VI_DEFAULT]);
9055 *(char_u **)(p->var) = empty_option;
9056 p->def_val[VI_DEFAULT] = empty_option;
9057 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9059 clear_termcodes();
9063 * Set the terminal option defaults to the current value.
9064 * Used after setting the terminal name.
9066 void
9067 set_term_defaults()
9069 struct vimoption *p;
9071 for (p = &options[0]; p->fullname != NULL; p++)
9073 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9075 if (p->flags & P_DEF_ALLOCED)
9077 free_string_option(p->def_val[VI_DEFAULT]);
9078 p->flags &= ~P_DEF_ALLOCED;
9080 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9081 if (p->flags & P_ALLOCED)
9083 p->flags |= P_DEF_ALLOCED;
9084 p->flags &= ~P_ALLOCED; /* don't free the value now */
9091 * return TRUE if 'p' starts with 't_'
9093 static int
9094 istermoption(p)
9095 struct vimoption *p;
9097 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9101 * Compute columns for ruler and shown command. 'sc_col' is also used to
9102 * decide what the maximum length of a message on the status line can be.
9103 * If there is a status line for the last window, 'sc_col' is independent
9104 * of 'ru_col'.
9107 #define COL_RULER 17 /* columns needed by standard ruler */
9109 void
9110 comp_col()
9112 #if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9113 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9115 sc_col = 0;
9116 ru_col = 0;
9117 if (p_ru)
9119 #ifdef FEAT_STL_OPT
9120 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9121 #else
9122 ru_col = COL_RULER + 1;
9123 #endif
9124 /* no last status line, adjust sc_col */
9125 if (!last_has_status)
9126 sc_col = ru_col;
9128 if (p_sc)
9130 sc_col += SHOWCMD_COLS;
9131 if (!p_ru || last_has_status) /* no need for separating space */
9132 ++sc_col;
9134 sc_col = Columns - sc_col;
9135 ru_col = Columns - ru_col;
9136 if (sc_col <= 0) /* screen too narrow, will become a mess */
9137 sc_col = 1;
9138 if (ru_col <= 0)
9139 ru_col = 1;
9140 #else
9141 sc_col = Columns;
9142 ru_col = Columns;
9143 #endif
9147 * Get pointer to option variable, depending on local or global scope.
9149 static char_u *
9150 get_varp_scope(p, opt_flags)
9151 struct vimoption *p;
9152 int opt_flags;
9154 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9156 if (p->var == VAR_WIN)
9157 return (char_u *)GLOBAL_WO(get_varp(p));
9158 return p->var;
9160 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
9162 switch ((int)p->indir)
9164 #ifdef FEAT_QUICKFIX
9165 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9166 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9167 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
9168 #endif
9169 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9170 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9171 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
9172 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
9173 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
9174 #ifdef FEAT_FIND_ID
9175 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9176 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
9177 #endif
9178 #ifdef FEAT_INS_EXPAND
9179 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9180 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
9181 #endif
9182 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9183 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9184 #endif
9185 #ifdef FEAT_STL_OPT
9186 case PV_STL: return (char_u *)&(curwin->w_p_stl);
9187 #endif
9189 return NULL; /* "cannot happen" */
9191 return get_varp(p);
9195 * Get pointer to option variable.
9197 static char_u *
9198 get_varp(p)
9199 struct vimoption *p;
9201 /* hidden option, always return NULL */
9202 if (p->var == NULL)
9203 return NULL;
9205 switch ((int)p->indir)
9207 case PV_NONE: return p->var;
9209 /* global option with local value: use local value if it's been set */
9210 case PV_EP: return *curbuf->b_p_ep != NUL
9211 ? (char_u *)&curbuf->b_p_ep : p->var;
9212 case PV_KP: return *curbuf->b_p_kp != NUL
9213 ? (char_u *)&curbuf->b_p_kp : p->var;
9214 case PV_PATH: return *curbuf->b_p_path != NUL
9215 ? (char_u *)&(curbuf->b_p_path) : p->var;
9216 case PV_AR: return curbuf->b_p_ar >= 0
9217 ? (char_u *)&(curbuf->b_p_ar) : p->var;
9218 case PV_TAGS: return *curbuf->b_p_tags != NUL
9219 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9220 #ifdef FEAT_FIND_ID
9221 case PV_DEF: return *curbuf->b_p_def != NUL
9222 ? (char_u *)&(curbuf->b_p_def) : p->var;
9223 case PV_INC: return *curbuf->b_p_inc != NUL
9224 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9225 #endif
9226 #ifdef FEAT_INS_EXPAND
9227 case PV_DICT: return *curbuf->b_p_dict != NUL
9228 ? (char_u *)&(curbuf->b_p_dict) : p->var;
9229 case PV_TSR: return *curbuf->b_p_tsr != NUL
9230 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9231 #endif
9232 #ifdef FEAT_QUICKFIX
9233 case PV_EFM: return *curbuf->b_p_efm != NUL
9234 ? (char_u *)&(curbuf->b_p_efm) : p->var;
9235 case PV_GP: return *curbuf->b_p_gp != NUL
9236 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9237 case PV_MP: return *curbuf->b_p_mp != NUL
9238 ? (char_u *)&(curbuf->b_p_mp) : p->var;
9239 #endif
9240 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9241 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9242 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9243 #endif
9244 #ifdef FEAT_STL_OPT
9245 case PV_STL: return *curwin->w_p_stl != NUL
9246 ? (char_u *)&(curwin->w_p_stl) : p->var;
9247 #endif
9249 #ifdef FEAT_ARABIC
9250 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9251 #endif
9252 case PV_LIST: return (char_u *)&(curwin->w_p_list);
9253 #ifdef FEAT_SPELL
9254 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9255 #endif
9256 #ifdef FEAT_SYN_HL
9257 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9258 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9259 #endif
9260 #ifdef FEAT_DIFF
9261 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9262 #endif
9263 #ifdef FEAT_FOLDING
9264 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9265 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9266 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9267 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9268 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9269 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9270 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9271 # ifdef FEAT_EVAL
9272 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9273 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9274 # endif
9275 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9276 #endif
9277 case PV_NU: return (char_u *)&(curwin->w_p_nu);
9278 #ifdef FEAT_LINEBREAK
9279 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9280 #endif
9281 #ifdef FEAT_WINDOWS
9282 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9283 #endif
9284 #ifdef FEAT_VERTSPLIT
9285 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9286 #endif
9287 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9288 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9289 #endif
9290 #ifdef FEAT_RIGHTLEFT
9291 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9292 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9293 #endif
9294 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9295 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9296 #ifdef FEAT_LINEBREAK
9297 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9298 #endif
9299 #ifdef FEAT_SCROLLBIND
9300 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9301 #endif
9303 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9304 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9305 #ifdef FEAT_MBYTE
9306 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9307 #endif
9308 #if defined(FEAT_QUICKFIX)
9309 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9310 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9311 #endif
9312 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9313 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9314 #ifdef FEAT_CINDENT
9315 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9316 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9317 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9318 #endif
9319 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9320 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9321 #endif
9322 #ifdef FEAT_COMMENTS
9323 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9324 #endif
9325 #ifdef FEAT_FOLDING
9326 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9327 #endif
9328 #ifdef FEAT_INS_EXPAND
9329 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9330 #endif
9331 #ifdef FEAT_COMPL_FUNC
9332 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
9333 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
9334 #endif
9335 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9336 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9337 #ifdef FEAT_MBYTE
9338 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9339 #endif
9340 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9341 #ifdef FEAT_AUTOCMD
9342 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9343 #endif
9344 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
9345 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
9346 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9347 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9348 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9349 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9350 #ifdef FEAT_FIND_ID
9351 # ifdef FEAT_EVAL
9352 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9353 # endif
9354 #endif
9355 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9356 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9357 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9358 #endif
9359 #ifdef FEAT_EVAL
9360 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9361 #endif
9362 #ifdef FEAT_CRYPT
9363 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9364 #endif
9365 #ifdef FEAT_LISP
9366 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9367 #endif
9368 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9369 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9370 #ifdef FEAT_GUI_MACVIM
9371 case PV_MMTA: return (char_u *)&(curbuf->b_p_mmta);
9372 #endif
9373 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9374 #ifdef USE_MIGEMO
9375 case PV_MIG: return (char_u *)&(curbuf->b_p_migemo);
9376 #endif
9377 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9378 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9379 #ifdef FEAT_OSFILETYPE
9380 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9381 #endif
9382 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
9383 #ifdef FEAT_TEXTOBJ
9384 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9385 #endif
9386 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9387 #ifdef FEAT_SMARTINDENT
9388 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9389 #endif
9390 #ifndef SHORT_FNAME
9391 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9392 #endif
9393 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9394 #ifdef FEAT_SEARCHPATH
9395 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9396 #endif
9397 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9398 #ifdef FEAT_SYN_HL
9399 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
9400 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9401 #endif
9402 #ifdef FEAT_SPELL
9403 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
9404 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
9405 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
9406 #endif
9407 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9408 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9409 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9410 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
9411 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9412 #ifdef FEAT_KEYMAP
9413 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9414 #endif
9415 default: EMSG(_("E356: get_varp ERROR"));
9417 /* always return a valid pointer to avoid a crash! */
9418 return (char_u *)&(curbuf->b_p_wm);
9422 * Get the value of 'equalprg', either the buffer-local one or the global one.
9424 char_u *
9425 get_equalprg()
9427 if (*curbuf->b_p_ep == NUL)
9428 return p_ep;
9429 return curbuf->b_p_ep;
9432 #if defined(FEAT_WINDOWS) || defined(PROTO)
9434 * Copy options from one window to another.
9435 * Used when splitting a window.
9437 void
9438 win_copy_options(wp_from, wp_to)
9439 win_T *wp_from;
9440 win_T *wp_to;
9442 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9443 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9444 # ifdef FEAT_RIGHTLEFT
9445 # ifdef FEAT_FKMAP
9446 /* Is this right? */
9447 wp_to->w_farsi = wp_from->w_farsi;
9448 # endif
9449 # endif
9451 #endif
9454 * Copy the options from one winopt_T to another.
9455 * Doesn't free the old option values in "to", use clear_winopt() for that.
9456 * The 'scroll' option is not copied, because it depends on the window height.
9457 * The 'previewwindow' option is reset, there can be only one preview window.
9459 void
9460 copy_winopt(from, to)
9461 winopt_T *from;
9462 winopt_T *to;
9464 #ifdef FEAT_ARABIC
9465 to->wo_arab = from->wo_arab;
9466 #endif
9467 to->wo_list = from->wo_list;
9468 to->wo_nu = from->wo_nu;
9469 #ifdef FEAT_LINEBREAK
9470 to->wo_nuw = from->wo_nuw;
9471 #endif
9472 #ifdef FEAT_RIGHTLEFT
9473 to->wo_rl = from->wo_rl;
9474 to->wo_rlc = vim_strsave(from->wo_rlc);
9475 #endif
9476 #ifdef FEAT_STL_OPT
9477 to->wo_stl = vim_strsave(from->wo_stl);
9478 #endif
9479 to->wo_wrap = from->wo_wrap;
9480 #ifdef FEAT_LINEBREAK
9481 to->wo_lbr = from->wo_lbr;
9482 #endif
9483 #ifdef FEAT_SCROLLBIND
9484 to->wo_scb = from->wo_scb;
9485 #endif
9486 #ifdef FEAT_SPELL
9487 to->wo_spell = from->wo_spell;
9488 #endif
9489 #ifdef FEAT_SYN_HL
9490 to->wo_cuc = from->wo_cuc;
9491 to->wo_cul = from->wo_cul;
9492 #endif
9493 #ifdef FEAT_DIFF
9494 to->wo_diff = from->wo_diff;
9495 #endif
9496 #ifdef FEAT_FOLDING
9497 to->wo_fdc = from->wo_fdc;
9498 to->wo_fen = from->wo_fen;
9499 to->wo_fdi = vim_strsave(from->wo_fdi);
9500 to->wo_fml = from->wo_fml;
9501 to->wo_fdl = from->wo_fdl;
9502 to->wo_fdm = vim_strsave(from->wo_fdm);
9503 to->wo_fdn = from->wo_fdn;
9504 # ifdef FEAT_EVAL
9505 to->wo_fde = vim_strsave(from->wo_fde);
9506 to->wo_fdt = vim_strsave(from->wo_fdt);
9507 # endif
9508 to->wo_fmr = vim_strsave(from->wo_fmr);
9509 #endif
9510 check_winopt(to); /* don't want NULL pointers */
9514 * Check string options in a window for a NULL value.
9516 void
9517 check_win_options(win)
9518 win_T *win;
9520 check_winopt(&win->w_onebuf_opt);
9521 check_winopt(&win->w_allbuf_opt);
9525 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9527 /*ARGSUSED*/
9528 void
9529 check_winopt(wop)
9530 winopt_T *wop;
9532 #ifdef FEAT_FOLDING
9533 check_string_option(&wop->wo_fdi);
9534 check_string_option(&wop->wo_fdm);
9535 # ifdef FEAT_EVAL
9536 check_string_option(&wop->wo_fde);
9537 check_string_option(&wop->wo_fdt);
9538 # endif
9539 check_string_option(&wop->wo_fmr);
9540 #endif
9541 #ifdef FEAT_RIGHTLEFT
9542 check_string_option(&wop->wo_rlc);
9543 #endif
9544 #ifdef FEAT_STL_OPT
9545 check_string_option(&wop->wo_stl);
9546 #endif
9550 * Free the allocated memory inside a winopt_T.
9552 /*ARGSUSED*/
9553 void
9554 clear_winopt(wop)
9555 winopt_T *wop;
9557 #ifdef FEAT_FOLDING
9558 clear_string_option(&wop->wo_fdi);
9559 clear_string_option(&wop->wo_fdm);
9560 # ifdef FEAT_EVAL
9561 clear_string_option(&wop->wo_fde);
9562 clear_string_option(&wop->wo_fdt);
9563 # endif
9564 clear_string_option(&wop->wo_fmr);
9565 #endif
9566 #ifdef FEAT_RIGHTLEFT
9567 clear_string_option(&wop->wo_rlc);
9568 #endif
9569 #ifdef FEAT_STL_OPT
9570 clear_string_option(&wop->wo_stl);
9571 #endif
9575 * Copy global option values to local options for one buffer.
9576 * Used when creating a new buffer and sometimes when entering a buffer.
9577 * flags:
9578 * BCO_ENTER We will enter the buf buffer.
9579 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9580 * appropriate.
9581 * BCO_NOHELP Don't copy the values to a help buffer.
9583 void
9584 buf_copy_options(buf, flags)
9585 buf_T *buf;
9586 int flags;
9588 int should_copy = TRUE;
9589 char_u *save_p_isk = NULL; /* init for GCC */
9590 int dont_do_help;
9591 int did_isk = FALSE;
9594 * Don't do anything of the buffer is invalid.
9596 if (buf == NULL || !buf_valid(buf))
9597 return;
9600 * Skip this when the option defaults have not been set yet. Happens when
9601 * main() allocates the first buffer.
9603 if (p_cpo != NULL)
9606 * Always copy when entering and 'cpo' contains 'S'.
9607 * Don't copy when already initialized.
9608 * Don't copy when 'cpo' contains 's' and not entering.
9609 * 'S' BCO_ENTER initialized 's' should_copy
9610 * yes yes X X TRUE
9611 * yes no yes X FALSE
9612 * no X yes X FALSE
9613 * X no no yes FALSE
9614 * X no no no TRUE
9615 * no yes no X TRUE
9617 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9618 && (buf->b_p_initialized
9619 || (!(flags & BCO_ENTER)
9620 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9621 should_copy = FALSE;
9623 if (should_copy || (flags & BCO_ALWAYS))
9625 /* Don't copy the options specific to a help buffer when
9626 * BCO_NOHELP is given or the options were initialized already
9627 * (jumping back to a help file with CTRL-T or CTRL-O) */
9628 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9629 || buf->b_p_initialized;
9630 if (dont_do_help) /* don't free b_p_isk */
9632 save_p_isk = buf->b_p_isk;
9633 buf->b_p_isk = NULL;
9636 * Always free the allocated strings.
9637 * If not already initialized, set 'readonly' and copy 'fileformat'.
9639 if (!buf->b_p_initialized)
9641 free_buf_options(buf, TRUE);
9642 buf->b_p_ro = FALSE; /* don't copy readonly */
9643 buf->b_p_tx = p_tx;
9644 #ifdef FEAT_MBYTE
9645 buf->b_p_fenc = vim_strsave(p_fenc);
9646 #endif
9647 buf->b_p_ff = vim_strsave(p_ff);
9648 #if defined(FEAT_QUICKFIX)
9649 buf->b_p_bh = empty_option;
9650 buf->b_p_bt = empty_option;
9651 #endif
9653 else
9654 free_buf_options(buf, FALSE);
9656 buf->b_p_ai = p_ai;
9657 buf->b_p_ai_nopaste = p_ai_nopaste;
9658 buf->b_p_sw = p_sw;
9659 buf->b_p_tw = p_tw;
9660 buf->b_p_tw_nopaste = p_tw_nopaste;
9661 buf->b_p_tw_nobin = p_tw_nobin;
9662 buf->b_p_wm = p_wm;
9663 buf->b_p_wm_nopaste = p_wm_nopaste;
9664 buf->b_p_wm_nobin = p_wm_nobin;
9665 buf->b_p_bin = p_bin;
9666 #ifdef FEAT_MBYTE
9667 buf->b_p_bomb = p_bomb;
9668 #endif
9669 buf->b_p_et = p_et;
9670 buf->b_p_et_nobin = p_et_nobin;
9671 buf->b_p_ml = p_ml;
9672 buf->b_p_ml_nobin = p_ml_nobin;
9673 buf->b_p_inf = p_inf;
9674 buf->b_p_swf = p_swf;
9675 #ifdef FEAT_INS_EXPAND
9676 buf->b_p_cpt = vim_strsave(p_cpt);
9677 #endif
9678 #ifdef FEAT_COMPL_FUNC
9679 buf->b_p_cfu = vim_strsave(p_cfu);
9680 buf->b_p_ofu = vim_strsave(p_ofu);
9681 #endif
9682 buf->b_p_sts = p_sts;
9683 buf->b_p_sts_nopaste = p_sts_nopaste;
9684 #ifndef SHORT_FNAME
9685 buf->b_p_sn = p_sn;
9686 #endif
9687 #ifdef FEAT_COMMENTS
9688 buf->b_p_com = vim_strsave(p_com);
9689 #endif
9690 #ifdef FEAT_FOLDING
9691 buf->b_p_cms = vim_strsave(p_cms);
9692 #endif
9693 buf->b_p_fo = vim_strsave(p_fo);
9694 buf->b_p_flp = vim_strsave(p_flp);
9695 buf->b_p_nf = vim_strsave(p_nf);
9696 buf->b_p_mps = vim_strsave(p_mps);
9697 #ifdef FEAT_SMARTINDENT
9698 buf->b_p_si = p_si;
9699 #endif
9700 buf->b_p_ci = p_ci;
9701 #ifdef FEAT_CINDENT
9702 buf->b_p_cin = p_cin;
9703 buf->b_p_cink = vim_strsave(p_cink);
9704 buf->b_p_cino = vim_strsave(p_cino);
9705 #endif
9706 #ifdef FEAT_AUTOCMD
9707 /* Don't copy 'filetype', it must be detected */
9708 buf->b_p_ft = empty_option;
9709 #endif
9710 #ifdef FEAT_OSFILETYPE
9711 buf->b_p_oft = vim_strsave(p_oft);
9712 #endif
9713 buf->b_p_pi = p_pi;
9714 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9715 buf->b_p_cinw = vim_strsave(p_cinw);
9716 #endif
9717 #ifdef FEAT_LISP
9718 buf->b_p_lisp = p_lisp;
9719 #endif
9720 #ifdef FEAT_SYN_HL
9721 /* Don't copy 'syntax', it must be set */
9722 buf->b_p_syn = empty_option;
9723 buf->b_p_smc = p_smc;
9724 #endif
9725 #ifdef FEAT_SPELL
9726 buf->b_p_spc = vim_strsave(p_spc);
9727 (void)compile_cap_prog(buf);
9728 buf->b_p_spf = vim_strsave(p_spf);
9729 buf->b_p_spl = vim_strsave(p_spl);
9730 #endif
9731 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9732 buf->b_p_inde = vim_strsave(p_inde);
9733 buf->b_p_indk = vim_strsave(p_indk);
9734 #endif
9735 #if defined(FEAT_EVAL)
9736 buf->b_p_fex = vim_strsave(p_fex);
9737 #endif
9738 #ifdef FEAT_CRYPT
9739 buf->b_p_key = vim_strsave(p_key);
9740 #endif
9741 #ifdef FEAT_SEARCHPATH
9742 buf->b_p_sua = vim_strsave(p_sua);
9743 #endif
9744 #ifdef FEAT_KEYMAP
9745 buf->b_p_keymap = vim_strsave(p_keymap);
9746 buf->b_kmap_state |= KEYMAP_INIT;
9747 #endif
9748 #ifdef FEAT_GUI_MACVIM
9749 buf->b_p_mmta = p_mmta;
9750 #endif
9751 /* This isn't really an option, but copying the langmap and IME
9752 * state from the current buffer is better than resetting it. */
9753 buf->b_p_iminsert = p_iminsert;
9754 buf->b_p_imsearch = p_imsearch;
9756 #ifdef USE_MIGEMO
9757 /* This is migemo extension */
9758 buf->b_p_migemo = p_migemo;
9759 #endif
9761 /* options that are normally global but also have a local value
9762 * are not copied, start using the global value */
9763 buf->b_p_ar = -1;
9764 #ifdef FEAT_QUICKFIX
9765 buf->b_p_gp = empty_option;
9766 buf->b_p_mp = empty_option;
9767 buf->b_p_efm = empty_option;
9768 #endif
9769 buf->b_p_ep = empty_option;
9770 buf->b_p_kp = empty_option;
9771 buf->b_p_path = empty_option;
9772 buf->b_p_tags = empty_option;
9773 #ifdef FEAT_FIND_ID
9774 buf->b_p_def = empty_option;
9775 buf->b_p_inc = empty_option;
9776 # ifdef FEAT_EVAL
9777 buf->b_p_inex = vim_strsave(p_inex);
9778 # endif
9779 #endif
9780 #ifdef FEAT_INS_EXPAND
9781 buf->b_p_dict = empty_option;
9782 buf->b_p_tsr = empty_option;
9783 #endif
9784 #ifdef FEAT_TEXTOBJ
9785 buf->b_p_qe = vim_strsave(p_qe);
9786 #endif
9787 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9788 buf->b_p_bexpr = empty_option;
9789 #endif
9792 * Don't copy the options set by ex_help(), use the saved values,
9793 * when going from a help buffer to a non-help buffer.
9794 * Don't touch these at all when BCO_NOHELP is used and going from
9795 * or to a help buffer.
9797 if (dont_do_help)
9798 buf->b_p_isk = save_p_isk;
9799 else
9801 buf->b_p_isk = vim_strsave(p_isk);
9802 did_isk = TRUE;
9803 buf->b_p_ts = p_ts;
9804 buf->b_help = FALSE;
9805 #ifdef FEAT_QUICKFIX
9806 if (buf->b_p_bt[0] == 'h')
9807 clear_string_option(&buf->b_p_bt);
9808 #endif
9809 buf->b_p_ma = p_ma;
9814 * When the options should be copied (ignoring BCO_ALWAYS), set the
9815 * flag that indicates that the options have been initialized.
9817 if (should_copy)
9818 buf->b_p_initialized = TRUE;
9821 check_buf_options(buf); /* make sure we don't have NULLs */
9822 if (did_isk)
9823 (void)buf_init_chartab(buf, FALSE);
9827 * Reset the 'modifiable' option and its default value.
9829 void
9830 reset_modifiable()
9832 int opt_idx;
9834 curbuf->b_p_ma = FALSE;
9835 p_ma = FALSE;
9836 opt_idx = findoption((char_u *)"ma");
9837 if (opt_idx >= 0)
9838 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9842 * Set the global value for 'iminsert' to the local value.
9844 void
9845 set_iminsert_global()
9847 p_iminsert = curbuf->b_p_iminsert;
9851 * Set the global value for 'imsearch' to the local value.
9853 void
9854 set_imsearch_global()
9856 p_imsearch = curbuf->b_p_imsearch;
9859 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9860 static int expand_option_idx = -1;
9861 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9862 static int expand_option_flags = 0;
9864 void
9865 set_context_in_set_cmd(xp, arg, opt_flags)
9866 expand_T *xp;
9867 char_u *arg;
9868 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9870 int nextchar;
9871 long_u flags = 0; /* init for GCC */
9872 int opt_idx = 0; /* init for GCC */
9873 char_u *p;
9874 char_u *s;
9875 int is_term_option = FALSE;
9876 int key;
9878 expand_option_flags = opt_flags;
9880 xp->xp_context = EXPAND_SETTINGS;
9881 if (*arg == NUL)
9883 xp->xp_pattern = arg;
9884 return;
9886 p = arg + STRLEN(arg) - 1;
9887 if (*p == ' ' && *(p - 1) != '\\')
9889 xp->xp_pattern = p + 1;
9890 return;
9892 while (p > arg)
9894 s = p;
9895 /* count number of backslashes before ' ' or ',' */
9896 if (*p == ' ' || *p == ',')
9898 while (s > arg && *(s - 1) == '\\')
9899 --s;
9901 /* break at a space with an even number of backslashes */
9902 if (*p == ' ' && ((p - s) & 1) == 0)
9904 ++p;
9905 break;
9907 --p;
9909 if (STRNCMP(p, "no", 2) == 0)
9911 xp->xp_context = EXPAND_BOOL_SETTINGS;
9912 p += 2;
9914 if (STRNCMP(p, "inv", 3) == 0)
9916 xp->xp_context = EXPAND_BOOL_SETTINGS;
9917 p += 3;
9919 xp->xp_pattern = arg = p;
9920 if (*arg == '<')
9922 while (*p != '>')
9923 if (*p++ == NUL) /* expand terminal option name */
9924 return;
9925 key = get_special_key_code(arg + 1);
9926 if (key == 0) /* unknown name */
9928 xp->xp_context = EXPAND_NOTHING;
9929 return;
9931 nextchar = *++p;
9932 is_term_option = TRUE;
9933 expand_option_name[2] = KEY2TERMCAP0(key);
9934 expand_option_name[3] = KEY2TERMCAP1(key);
9936 else
9938 if (p[0] == 't' && p[1] == '_')
9940 p += 2;
9941 if (*p != NUL)
9942 ++p;
9943 if (*p == NUL)
9944 return; /* expand option name */
9945 nextchar = *++p;
9946 is_term_option = TRUE;
9947 expand_option_name[2] = p[-2];
9948 expand_option_name[3] = p[-1];
9950 else
9952 /* Allow * wildcard */
9953 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9954 p++;
9955 if (*p == NUL)
9956 return;
9957 nextchar = *p;
9958 *p = NUL;
9959 opt_idx = findoption(arg);
9960 *p = nextchar;
9961 if (opt_idx == -1 || options[opt_idx].var == NULL)
9963 xp->xp_context = EXPAND_NOTHING;
9964 return;
9966 flags = options[opt_idx].flags;
9967 if (flags & P_BOOL)
9969 xp->xp_context = EXPAND_NOTHING;
9970 return;
9974 /* handle "-=" and "+=" */
9975 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9977 ++p;
9978 nextchar = '=';
9980 if ((nextchar != '=' && nextchar != ':')
9981 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9983 xp->xp_context = EXPAND_UNSUCCESSFUL;
9984 return;
9986 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9988 xp->xp_context = EXPAND_OLD_SETTING;
9989 if (is_term_option)
9990 expand_option_idx = -1;
9991 else
9992 expand_option_idx = opt_idx;
9993 xp->xp_pattern = p + 1;
9994 return;
9996 xp->xp_context = EXPAND_NOTHING;
9997 if (is_term_option || (flags & P_NUM))
9998 return;
10000 xp->xp_pattern = p + 1;
10002 if (flags & P_EXPAND)
10004 p = options[opt_idx].var;
10005 if (p == (char_u *)&p_bdir
10006 || p == (char_u *)&p_dir
10007 || p == (char_u *)&p_path
10008 || p == (char_u *)&p_rtp
10009 #ifdef FEAT_SEARCHPATH
10010 || p == (char_u *)&p_cdpath
10011 #endif
10012 #ifdef FEAT_SESSION
10013 || p == (char_u *)&p_vdir
10014 #endif
10017 xp->xp_context = EXPAND_DIRECTORIES;
10018 if (p == (char_u *)&p_path
10019 #ifdef FEAT_SEARCHPATH
10020 || p == (char_u *)&p_cdpath
10021 #endif
10023 xp->xp_backslash = XP_BS_THREE;
10024 else
10025 xp->xp_backslash = XP_BS_ONE;
10027 else
10029 xp->xp_context = EXPAND_FILES;
10030 /* for 'tags' need three backslashes for a space */
10031 if (p == (char_u *)&p_tags)
10032 xp->xp_backslash = XP_BS_THREE;
10033 else
10034 xp->xp_backslash = XP_BS_ONE;
10038 /* For an option that is a list of file names, find the start of the
10039 * last file name. */
10040 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10042 /* count number of backslashes before ' ' or ',' */
10043 if (*p == ' ' || *p == ',')
10045 s = p;
10046 while (s > xp->xp_pattern && *(s - 1) == '\\')
10047 --s;
10048 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10049 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10051 xp->xp_pattern = p + 1;
10052 break;
10056 #ifdef FEAT_SPELL
10057 /* for 'spellsuggest' start at "file:" */
10058 if (options[opt_idx].var == (char_u *)&p_sps
10059 && STRNCMP(p, "file:", 5) == 0)
10061 xp->xp_pattern = p + 5;
10062 break;
10064 #endif
10067 return;
10071 ExpandSettings(xp, regmatch, num_file, file)
10072 expand_T *xp;
10073 regmatch_T *regmatch;
10074 int *num_file;
10075 char_u ***file;
10077 int num_normal = 0; /* Nr of matching non-term-code settings */
10078 int num_term = 0; /* Nr of matching terminal code settings */
10079 int opt_idx;
10080 int match;
10081 int count = 0;
10082 char_u *str;
10083 int loop;
10084 int is_term_opt;
10085 char_u name_buf[MAX_KEY_NAME_LEN];
10086 static char *(names[]) = {"all", "termcap"};
10087 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10089 /* do this loop twice:
10090 * loop == 0: count the number of matching options
10091 * loop == 1: copy the matching options into allocated memory
10093 for (loop = 0; loop <= 1; ++loop)
10095 regmatch->rm_ic = ic;
10096 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10098 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
10099 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10101 if (loop == 0)
10102 num_normal++;
10103 else
10104 (*file)[count++] = vim_strsave((char_u *)names[match]);
10107 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10108 opt_idx++)
10110 if (options[opt_idx].var == NULL)
10111 continue;
10112 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10113 && !(options[opt_idx].flags & P_BOOL))
10114 continue;
10115 is_term_opt = istermoption(&options[opt_idx]);
10116 if (is_term_opt && num_normal > 0)
10117 continue;
10118 match = FALSE;
10119 if (vim_regexec(regmatch, str, (colnr_T)0)
10120 || (options[opt_idx].shortname != NULL
10121 && vim_regexec(regmatch,
10122 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10123 match = TRUE;
10124 else if (is_term_opt)
10126 name_buf[0] = '<';
10127 name_buf[1] = 't';
10128 name_buf[2] = '_';
10129 name_buf[3] = str[2];
10130 name_buf[4] = str[3];
10131 name_buf[5] = '>';
10132 name_buf[6] = NUL;
10133 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10135 match = TRUE;
10136 str = name_buf;
10139 if (match)
10141 if (loop == 0)
10143 if (is_term_opt)
10144 num_term++;
10145 else
10146 num_normal++;
10148 else
10149 (*file)[count++] = vim_strsave(str);
10153 * Check terminal key codes, these are not in the option table
10155 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10157 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10159 if (!isprint(str[0]) || !isprint(str[1]))
10160 continue;
10162 name_buf[0] = 't';
10163 name_buf[1] = '_';
10164 name_buf[2] = str[0];
10165 name_buf[3] = str[1];
10166 name_buf[4] = NUL;
10168 match = FALSE;
10169 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10170 match = TRUE;
10171 else
10173 name_buf[0] = '<';
10174 name_buf[1] = 't';
10175 name_buf[2] = '_';
10176 name_buf[3] = str[0];
10177 name_buf[4] = str[1];
10178 name_buf[5] = '>';
10179 name_buf[6] = NUL;
10181 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10182 match = TRUE;
10184 if (match)
10186 if (loop == 0)
10187 num_term++;
10188 else
10189 (*file)[count++] = vim_strsave(name_buf);
10194 * Check special key names.
10196 regmatch->rm_ic = TRUE; /* ignore case here */
10197 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10199 name_buf[0] = '<';
10200 STRCPY(name_buf + 1, str);
10201 STRCAT(name_buf, ">");
10203 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10205 if (loop == 0)
10206 num_term++;
10207 else
10208 (*file)[count++] = vim_strsave(name_buf);
10212 if (loop == 0)
10214 if (num_normal > 0)
10215 *num_file = num_normal;
10216 else if (num_term > 0)
10217 *num_file = num_term;
10218 else
10219 return OK;
10220 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10221 if (*file == NULL)
10223 *file = (char_u **)"";
10224 return FAIL;
10228 return OK;
10232 ExpandOldSetting(num_file, file)
10233 int *num_file;
10234 char_u ***file;
10236 char_u *var = NULL; /* init for GCC */
10237 char_u *buf;
10239 *num_file = 0;
10240 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10241 if (*file == NULL)
10242 return FAIL;
10245 * For a terminal key code expand_option_idx is < 0.
10247 if (expand_option_idx < 0)
10249 var = find_termcode(expand_option_name + 2);
10250 if (var == NULL)
10251 expand_option_idx = findoption(expand_option_name);
10254 if (expand_option_idx >= 0)
10256 /* put string of option value in NameBuff */
10257 option_value2string(&options[expand_option_idx], expand_option_flags);
10258 var = NameBuff;
10260 else if (var == NULL)
10261 var = (char_u *)"";
10263 /* A backslash is required before some characters. This is the reverse of
10264 * what happens in do_set(). */
10265 buf = vim_strsave_escaped(var, escape_chars);
10267 if (buf == NULL)
10269 vim_free(*file);
10270 *file = NULL;
10271 return FAIL;
10274 #ifdef BACKSLASH_IN_FILENAME
10275 /* For MS-Windows et al. we don't double backslashes at the start and
10276 * before a file name character. */
10277 for (var = buf; *var != NUL; mb_ptr_adv(var))
10278 if (var[0] == '\\' && var[1] == '\\'
10279 && expand_option_idx >= 0
10280 && (options[expand_option_idx].flags & P_EXPAND)
10281 && vim_isfilec(var[2])
10282 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
10283 STRMOVE(var, var + 1);
10284 #endif
10286 *file[0] = buf;
10287 *num_file = 1;
10288 return OK;
10290 #endif
10293 * Get the value for the numeric or string option *opp in a nice format into
10294 * NameBuff[]. Must not be called with a hidden option!
10296 static void
10297 option_value2string(opp, opt_flags)
10298 struct vimoption *opp;
10299 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10301 char_u *varp;
10303 varp = get_varp_scope(opp, opt_flags);
10305 if (opp->flags & P_NUM)
10307 long wc = 0;
10309 if (wc_use_keyname(varp, &wc))
10310 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10311 else if (wc != 0)
10312 STRCPY(NameBuff, transchar((int)wc));
10313 else
10314 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10316 else /* P_STRING */
10318 varp = *(char_u **)(varp);
10319 if (varp == NULL) /* just in case */
10320 NameBuff[0] = NUL;
10321 #ifdef FEAT_CRYPT
10322 /* don't show the actual value of 'key', only that it's set */
10323 else if (opp->var == (char_u *)&p_key && *varp)
10324 STRCPY(NameBuff, "*****");
10325 #endif
10326 else if (opp->flags & P_EXPAND)
10327 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10328 /* Translate 'pastetoggle' into special key names */
10329 else if ((char_u **)opp->var == &p_pt)
10330 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10331 else
10332 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
10337 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10338 * printed as a keyname.
10339 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10341 static int
10342 wc_use_keyname(varp, wcp)
10343 char_u *varp;
10344 long *wcp;
10346 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10348 *wcp = *(long *)varp;
10349 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10350 return TRUE;
10352 return FALSE;
10355 #ifdef FEAT_LANGMAP
10357 * Any character has an equivalent 'langmap' character. This is used for
10358 * keyboards that have a special language mode that sends characters above
10359 * 128 (although other characters can be translated too). The "to" field is a
10360 * Vim command character. This avoids having to switch the keyboard back to
10361 * ASCII mode when leaving Insert mode.
10363 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10364 * commands.
10365 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10366 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10367 * 256.
10369 # ifdef FEAT_MBYTE
10371 * With multi-byte support use growarray for 'langmap' chars >= 256
10373 typedef struct
10375 int from;
10376 int to;
10377 } langmap_entry_T;
10379 static garray_T langmap_mapga;
10380 static void langmap_set_entry __ARGS((int from, int to));
10383 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10384 * field. If not found insert a new entry at the appropriate location.
10386 static void
10387 langmap_set_entry(from, to)
10388 int from;
10389 int to;
10391 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10392 int a = 0;
10393 int b = langmap_mapga.ga_len;
10395 /* Do a binary search for an existing entry. */
10396 while (a != b)
10398 int i = (a + b) / 2;
10399 int d = entries[i].from - from;
10401 if (d == 0)
10403 entries[i].to = to;
10404 return;
10406 if (d < 0)
10407 a = i + 1;
10408 else
10409 b = i;
10412 if (ga_grow(&langmap_mapga, 1) != OK)
10413 return; /* out of memory */
10415 /* insert new entry at position "a" */
10416 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10417 mch_memmove(entries + 1, entries,
10418 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10419 ++langmap_mapga.ga_len;
10420 entries[0].from = from;
10421 entries[0].to = to;
10425 * Apply 'langmap' to multi-byte character "c" and return the result.
10428 langmap_adjust_mb(c)
10429 int c;
10431 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10432 int a = 0;
10433 int b = langmap_mapga.ga_len;
10435 while (a != b)
10437 int i = (a + b) / 2;
10438 int d = entries[i].from - c;
10440 if (d == 0)
10441 return entries[i].to; /* found matching entry */
10442 if (d < 0)
10443 a = i + 1;
10444 else
10445 b = i;
10447 return c; /* no entry found, return "c" unmodified */
10449 # endif
10451 static void
10452 langmap_init()
10454 int i;
10456 for (i = 0; i < 256; i++)
10457 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10458 # ifdef FEAT_MBYTE
10459 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10460 # endif
10464 * Called when langmap option is set; the language map can be
10465 * changed at any time!
10467 static void
10468 langmap_set()
10470 char_u *p;
10471 char_u *p2;
10472 int from, to;
10474 #ifdef FEAT_MBYTE
10475 ga_clear(&langmap_mapga); /* clear the previous map first */
10476 #endif
10477 langmap_init(); /* back to one-to-one map */
10479 for (p = p_langmap; p[0] != NUL; )
10481 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10482 mb_ptr_adv(p2))
10484 if (p2[0] == '\\' && p2[1] != NUL)
10485 ++p2;
10487 if (p2[0] == ';')
10488 ++p2; /* abcd;ABCD form, p2 points to A */
10489 else
10490 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10491 while (p[0])
10493 if (p[0] == '\\' && p[1] != NUL)
10494 ++p;
10495 #ifdef FEAT_MBYTE
10496 from = (*mb_ptr2char)(p);
10497 #else
10498 from = p[0];
10499 #endif
10500 if (p2 == NULL)
10502 mb_ptr_adv(p);
10503 if (p[0] == '\\')
10504 ++p;
10505 #ifdef FEAT_MBYTE
10506 to = (*mb_ptr2char)(p);
10507 #else
10508 to = p[0];
10509 #endif
10511 else
10513 if (p2[0] == '\\')
10514 ++p2;
10515 #ifdef FEAT_MBYTE
10516 to = (*mb_ptr2char)(p2);
10517 #else
10518 to = p2[0];
10519 #endif
10521 if (to == NUL)
10523 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10524 transchar(from));
10525 return;
10528 #ifdef FEAT_MBYTE
10529 if (from >= 256)
10530 langmap_set_entry(from, to);
10531 else
10532 #endif
10533 langmap_mapchar[from & 255] = to;
10535 /* Advance to next pair */
10536 mb_ptr_adv(p);
10537 if (p2 == NULL)
10539 if (p[0] == ',')
10541 ++p;
10542 break;
10545 else
10547 mb_ptr_adv(p2);
10548 if (*p == ';')
10550 p = p2;
10551 if (p[0] != NUL)
10553 if (p[0] != ',')
10555 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10556 return;
10558 ++p;
10560 break;
10566 #endif
10569 * Return TRUE if format option 'x' is in effect.
10570 * Take care of no formatting when 'paste' is set.
10573 has_format_option(x)
10574 int x;
10576 if (p_paste)
10577 return FALSE;
10578 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10582 * Return TRUE if "x" is present in 'shortmess' option, or
10583 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10586 shortmess(x)
10587 int x;
10589 return ( vim_strchr(p_shm, x) != NULL
10590 || (vim_strchr(p_shm, 'a') != NULL
10591 && vim_strchr((char_u *)SHM_A, x) != NULL));
10595 * paste_option_changed() - Called after p_paste was set or reset.
10597 static void
10598 paste_option_changed()
10600 static int old_p_paste = FALSE;
10601 static int save_sm = 0;
10602 #ifdef FEAT_CMDL_INFO
10603 static int save_ru = 0;
10604 #endif
10605 #ifdef FEAT_RIGHTLEFT
10606 static int save_ri = 0;
10607 static int save_hkmap = 0;
10608 #endif
10609 buf_T *buf;
10611 if (p_paste)
10614 * Paste switched from off to on.
10615 * Save the current values, so they can be restored later.
10617 if (!old_p_paste)
10619 /* save options for each buffer */
10620 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10622 buf->b_p_tw_nopaste = buf->b_p_tw;
10623 buf->b_p_wm_nopaste = buf->b_p_wm;
10624 buf->b_p_sts_nopaste = buf->b_p_sts;
10625 buf->b_p_ai_nopaste = buf->b_p_ai;
10628 /* save global options */
10629 save_sm = p_sm;
10630 #ifdef FEAT_CMDL_INFO
10631 save_ru = p_ru;
10632 #endif
10633 #ifdef FEAT_RIGHTLEFT
10634 save_ri = p_ri;
10635 save_hkmap = p_hkmap;
10636 #endif
10637 /* save global values for local buffer options */
10638 p_tw_nopaste = p_tw;
10639 p_wm_nopaste = p_wm;
10640 p_sts_nopaste = p_sts;
10641 p_ai_nopaste = p_ai;
10645 * Always set the option values, also when 'paste' is set when it is
10646 * already on.
10648 /* set options for each buffer */
10649 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10651 buf->b_p_tw = 0; /* textwidth is 0 */
10652 buf->b_p_wm = 0; /* wrapmargin is 0 */
10653 buf->b_p_sts = 0; /* softtabstop is 0 */
10654 buf->b_p_ai = 0; /* no auto-indent */
10657 /* set global options */
10658 p_sm = 0; /* no showmatch */
10659 #ifdef FEAT_CMDL_INFO
10660 # ifdef FEAT_WINDOWS
10661 if (p_ru)
10662 status_redraw_all(); /* redraw to remove the ruler */
10663 # endif
10664 p_ru = 0; /* no ruler */
10665 #endif
10666 #ifdef FEAT_RIGHTLEFT
10667 p_ri = 0; /* no reverse insert */
10668 p_hkmap = 0; /* no Hebrew keyboard */
10669 #endif
10670 /* set global values for local buffer options */
10671 p_tw = 0;
10672 p_wm = 0;
10673 p_sts = 0;
10674 p_ai = 0;
10678 * Paste switched from on to off: Restore saved values.
10680 else if (old_p_paste)
10682 /* restore options for each buffer */
10683 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10685 buf->b_p_tw = buf->b_p_tw_nopaste;
10686 buf->b_p_wm = buf->b_p_wm_nopaste;
10687 buf->b_p_sts = buf->b_p_sts_nopaste;
10688 buf->b_p_ai = buf->b_p_ai_nopaste;
10691 /* restore global options */
10692 p_sm = save_sm;
10693 #ifdef FEAT_CMDL_INFO
10694 # ifdef FEAT_WINDOWS
10695 if (p_ru != save_ru)
10696 status_redraw_all(); /* redraw to draw the ruler */
10697 # endif
10698 p_ru = save_ru;
10699 #endif
10700 #ifdef FEAT_RIGHTLEFT
10701 p_ri = save_ri;
10702 p_hkmap = save_hkmap;
10703 #endif
10704 /* set global values for local buffer options */
10705 p_tw = p_tw_nopaste;
10706 p_wm = p_wm_nopaste;
10707 p_sts = p_sts_nopaste;
10708 p_ai = p_ai_nopaste;
10711 old_p_paste = p_paste;
10715 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10717 * Reset 'compatible' and set the values for options that didn't get set yet
10718 * to the Vim defaults.
10719 * Don't do this if the 'compatible' option has been set or reset before.
10720 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
10722 void
10723 vimrc_found(fname, envname)
10724 char_u *fname;
10725 char_u *envname;
10727 int opt_idx;
10728 int dofree = FALSE;
10729 char_u *p;
10731 if (!option_was_set((char_u *)"cp"))
10733 p_cp = FALSE;
10734 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10735 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10736 set_option_default(opt_idx, OPT_FREE, FALSE);
10737 didset_options();
10740 if (fname != NULL)
10742 p = vim_getenv(envname, &dofree);
10743 if (p == NULL)
10745 /* Set $MYVIMRC to the first vimrc file found. */
10746 p = FullName_save(fname, FALSE);
10747 if (p != NULL)
10749 vim_setenv(envname, p);
10750 vim_free(p);
10753 else if (dofree)
10754 vim_free(p);
10759 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10761 void
10762 change_compatible(on)
10763 int on;
10765 int opt_idx;
10767 if (p_cp != on)
10769 p_cp = on;
10770 compatible_set();
10772 opt_idx = findoption((char_u *)"cp");
10773 if (opt_idx >= 0)
10774 options[opt_idx].flags |= P_WAS_SET;
10778 * Return TRUE when option "name" has been set.
10781 option_was_set(name)
10782 char_u *name;
10784 int idx;
10786 idx = findoption(name);
10787 if (idx < 0) /* unknown option */
10788 return FALSE;
10789 if (options[idx].flags & P_WAS_SET)
10790 return TRUE;
10791 return FALSE;
10795 * compatible_set() - Called when 'compatible' has been set or unset.
10797 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10798 * flag) to a Vi compatible value.
10799 * When 'compatible' is unset: Set all options that have a different default
10800 * for Vim (without the P_VI_DEF flag) to that default.
10802 static void
10803 compatible_set()
10805 int opt_idx;
10807 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10808 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10809 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10810 set_option_default(opt_idx, OPT_FREE, p_cp);
10811 didset_options();
10814 #ifdef FEAT_LINEBREAK
10816 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10817 /* Borland C++ screws up loop optimisation here (negri) */
10818 #pragma option -O-l
10819 # endif
10822 * fill_breakat_flags() -- called when 'breakat' changes value.
10824 static void
10825 fill_breakat_flags()
10827 char_u *p;
10828 int i;
10830 for (i = 0; i < 256; i++)
10831 breakat_flags[i] = FALSE;
10833 if (p_breakat != NULL)
10834 for (p = p_breakat; *p; p++)
10835 breakat_flags[*p] = TRUE;
10838 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10839 #pragma option -O.l
10840 # endif
10842 #endif
10845 * Check an option that can be a range of string values.
10847 * Return OK for correct value, FAIL otherwise.
10848 * Empty is always OK.
10850 static int
10851 check_opt_strings(val, values, list)
10852 char_u *val;
10853 char **values;
10854 int list; /* when TRUE: accept a list of values */
10856 return opt_strings_flags(val, values, NULL, list);
10860 * Handle an option that can be a range of string values.
10861 * Set a flag in "*flagp" for each string present.
10863 * Return OK for correct value, FAIL otherwise.
10864 * Empty is always OK.
10866 static int
10867 opt_strings_flags(val, values, flagp, list)
10868 char_u *val; /* new value */
10869 char **values; /* array of valid string values */
10870 unsigned *flagp;
10871 int list; /* when TRUE: accept a list of values */
10873 int i;
10874 int len;
10875 unsigned new_flags = 0;
10877 while (*val)
10879 for (i = 0; ; ++i)
10881 if (values[i] == NULL) /* val not found in values[] */
10882 return FAIL;
10884 len = (int)STRLEN(values[i]);
10885 if (STRNCMP(values[i], val, len) == 0
10886 && ((list && val[len] == ',') || val[len] == NUL))
10888 val += len + (val[len] == ',');
10889 new_flags |= (1 << i);
10890 break; /* check next item in val list */
10894 if (flagp != NULL)
10895 *flagp = new_flags;
10897 return OK;
10901 * Read the 'wildmode' option, fill wim_flags[].
10903 static int
10904 check_opt_wim()
10906 char_u new_wim_flags[4];
10907 char_u *p;
10908 int i;
10909 int idx = 0;
10911 for (i = 0; i < 4; ++i)
10912 new_wim_flags[i] = 0;
10914 for (p = p_wim; *p; ++p)
10916 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10918 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10919 return FAIL;
10920 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10921 new_wim_flags[idx] |= WIM_LONGEST;
10922 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10923 new_wim_flags[idx] |= WIM_FULL;
10924 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10925 new_wim_flags[idx] |= WIM_LIST;
10926 else
10927 return FAIL;
10928 p += i;
10929 if (*p == NUL)
10930 break;
10931 if (*p == ',')
10933 if (idx == 3)
10934 return FAIL;
10935 ++idx;
10939 /* fill remaining entries with last flag */
10940 while (idx < 3)
10942 new_wim_flags[idx + 1] = new_wim_flags[idx];
10943 ++idx;
10946 /* only when there are no errors, wim_flags[] is changed */
10947 for (i = 0; i < 4; ++i)
10948 wim_flags[i] = new_wim_flags[i];
10949 return OK;
10953 * Check if backspacing over something is allowed.
10956 can_bs(what)
10957 int what; /* BS_INDENT, BS_EOL or BS_START */
10959 switch (*p_bs)
10961 case '2': return TRUE;
10962 case '1': return (what != BS_START);
10963 case '0': return FALSE;
10965 return vim_strchr(p_bs, what) != NULL;
10969 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10970 * the file must be considered changed when the value is different.
10972 void
10973 save_file_ff(buf)
10974 buf_T *buf;
10976 buf->b_start_ffc = *buf->b_p_ff;
10977 buf->b_start_eol = buf->b_p_eol;
10978 #ifdef FEAT_MBYTE
10979 buf->b_start_bomb = buf->b_p_bomb;
10981 /* Only use free/alloc when necessary, they take time. */
10982 if (buf->b_start_fenc == NULL
10983 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10985 vim_free(buf->b_start_fenc);
10986 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10988 #endif
10992 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10993 * from when editing started (save_file_ff() called).
10994 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
10995 * changed and 'binary' is not set.
10996 * Don't consider a new, empty buffer to be changed.
10999 file_ff_differs(buf)
11000 buf_T *buf;
11002 /* In a buffer that was never loaded the options are not valid. */
11003 if (buf->b_flags & BF_NEVERLOADED)
11004 return FALSE;
11005 if ((buf->b_flags & BF_NEW)
11006 && buf->b_ml.ml_line_count == 1
11007 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11008 return FALSE;
11009 if (buf->b_start_ffc != *buf->b_p_ff)
11010 return TRUE;
11011 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11012 return TRUE;
11013 #ifdef FEAT_MBYTE
11014 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11015 return TRUE;
11016 if (buf->b_start_fenc == NULL)
11017 return (*buf->b_p_fenc != NUL);
11018 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11019 #else
11020 return FALSE;
11021 #endif
11025 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11028 check_ff_value(p)
11029 char_u *p;
11031 return check_opt_strings(p, p_ff_values, FALSE);
11034 #ifdef FEAT_FULLSCREEN
11036 * Read the 'fuoptions' option, set fuoptions_flags and
11037 * fuoptions_bgcolor.
11039 static int
11040 check_fuoptions(p_fuoptions, flags, bgcolor)
11041 char_u *p_fuoptions; /* fuoptions string */
11042 unsigned *flags; /* fuoptions flags */
11043 int *bgcolor; /* background highlight group id */
11045 unsigned new_fuoptions_flags;
11046 int new_fuoptions_bgcolor;
11047 char_u *p;
11048 char_u hg_term; /* character terminating
11049 highlight group string in
11050 'background' option' */
11051 int i,j,k;
11053 new_fuoptions_flags = 0;
11054 new_fuoptions_bgcolor = 0xFF000000;
11056 for (p = p_fuoptions; *p; ++p)
11058 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11060 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11061 return FAIL;
11062 if (i == 10 && STRNCMP(p, "background", 10) == 0)
11064 if (p[i] != ':') return FAIL;
11065 i++;
11066 if (p[i] == NUL) return FAIL;
11067 if (p[i] == '#')
11069 /* explicit color (#aarrggbb) */
11070 i++;
11071 for (j = i; j < i+8 && vim_isxdigit(p[j]); ++j)
11073 if (j < i+8)
11074 return FAIL; /* less than 8 digits */
11075 if (p[j] != NUL && p[j] != ',')
11076 return FAIL;
11077 new_fuoptions_bgcolor = 0;
11078 for (k = 0; k < 8; k++)
11079 new_fuoptions_bgcolor = new_fuoptions_bgcolor * 16 +
11080 hex2nr(p[i+k]);
11081 i = j;
11082 /* mark bgcolor as an explicit argb color */
11083 new_fuoptions_flags &= ~FUOPT_BGCOLOR_HLGROUP;
11085 else
11087 /* highlight group name */
11088 for (j = i; ASCII_ISALPHA(p[j]); ++j)
11090 if (p[j] != NUL && p[j] != ',')
11091 return FAIL;
11092 hg_term = p[j];
11093 p[j] = NUL; /* temporarily terminate string */
11094 new_fuoptions_bgcolor = syn_name2id((char_u*)(p+i));
11095 p[j] = hg_term; /* restore string */
11096 if (! new_fuoptions_bgcolor)
11097 return FAIL;
11098 i = j;
11099 /* mark bgcolor as highlight group id */
11100 new_fuoptions_flags |= FUOPT_BGCOLOR_HLGROUP;
11103 else if (i == 7 && STRNCMP(p, "maxhorz", 7) == 0)
11104 new_fuoptions_flags |= FUOPT_MAXHORZ;
11105 else if (i == 7 && STRNCMP(p, "maxvert", 7) == 0)
11106 new_fuoptions_flags |= FUOPT_MAXVERT;
11107 else
11108 return FAIL;
11109 p += i;
11110 if (*p == NUL)
11111 break;
11112 if (*p == ':')
11113 return FAIL;
11116 *flags = new_fuoptions_flags;
11117 *bgcolor = new_fuoptions_bgcolor;
11119 /* Let the GUI know, in case the background color has changed. */
11120 gui_mch_fuopt_update();
11122 return OK;
11124 #endif