blob: 2bfeec3a200c3f033c34b39d400e729e77a57f62 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/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.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
41 * PV_BOTH is added: global option which also has a local value.
42 */
43#define PV_BOTH 0x1000
44#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
45
46typedef enum
47{
48 PV_NONE = 0
49 , PV_AI
50 , PV_AR
51 , PV_ARAB
52 , PV_BH
53 , PV_BIN
54 , PV_BL
55 , PV_BOMB
56 , PV_BT
57 , PV_CI
58 , PV_CIN
59 , PV_CINK
60 , PV_CINO
61 , PV_CINW
62 , PV_CMS
63 , PV_COM
64 , PV_CPT
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000065 , PV_CFU
Bram Moolenaar071d4272004-06-13 20:20:40 +000066 , PV_DEF
67 , PV_DICT
68 , PV_DIFF
69 , PV_EFM
70 , PV_EOL
71 , PV_EP
72 , PV_ET
73 , PV_FDC
74 , PV_FDE
75 , PV_FDI
76 , PV_FDL
77 , PV_FDM
78 , PV_FDN
79 , PV_FDT
80 , PV_FEN
81 , PV_FENC
82 , PV_FF
83 , PV_FML
84 , PV_FMR
Bram Moolenaar86b68352004-12-27 21:59:20 +000085 , PV_FLP
Bram Moolenaar071d4272004-06-13 20:20:40 +000086 , PV_FO
87 , PV_FT
88 , PV_GP
89 , PV_IMI
90 , PV_IMS
91 , PV_INC
92 , PV_INDE
93 , PV_INDK
94 , PV_INEX
95 , PV_INF
96 , PV_ISK
97 , PV_KEY
98 , PV_KMAP
99 , PV_KP
100 , PV_LBR
101 , PV_LISP
102 , PV_LIST
103 , PV_MA
104 , PV_ML
105 , PV_MOD
106 , PV_MP
107 , PV_MPS
108 , PV_NF
109 , PV_NU
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000110 , PV_NUW
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111 , PV_OFT
112 , PV_PATH
113 , PV_PI
114 , PV_PVW
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000115 , PV_QE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116 , PV_RL
117 , PV_RLC
118 , PV_RO
119 , PV_SCBIND
120 , PV_SCROLL
121 , PV_SI
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +0000122 , PV_STL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123 , PV_SN
124 , PV_STS
125 , PV_SUA
126 , PV_SW
127 , PV_SWF
128 , PV_SYN
129 , PV_TAGS
130 , PV_TS
131 , PV_TSR
132 , PV_TW
133 , PV_TX
134 , PV_WFH
135 , PV_WM
136 , PV_WRAP
137} idopt_T;
138
139/*
140 * Options local to a window have a value local to a buffer and global to all
141 * buffers. Indicate this by setting "var" to VAR_WIN.
142 */
143#define VAR_WIN ((char_u *)-1)
144
145/*
146 * These the global values for options which are also local to a buffer.
147 * Only to be used in option.c!
148 */
149static int p_ai;
150static int p_bin;
151#ifdef FEAT_MBYTE
152static int p_bomb;
153#endif
154#if defined(FEAT_QUICKFIX)
155static char_u *p_bh;
156static char_u *p_bt;
157#endif
158static int p_bl;
159static int p_ci;
160#ifdef FEAT_CINDENT
161static int p_cin;
162static char_u *p_cink;
163static char_u *p_cino;
164#endif
165#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
166static char_u *p_cinw;
167#endif
168#ifdef FEAT_COMMENTS
169static char_u *p_com;
170#endif
171#ifdef FEAT_FOLDING
172static char_u *p_cms;
173#endif
174#ifdef FEAT_INS_EXPAND
175static char_u *p_cpt;
176#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000177#ifdef FEAT_COMPL_FUNC
178static char_u *p_cfu;
179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180static int p_eol;
181static int p_et;
182#ifdef FEAT_MBYTE
183static char_u *p_fenc;
184#endif
185static char_u *p_ff;
186static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000187static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188#ifdef FEAT_AUTOCMD
189static char_u *p_ft;
190#endif
191static long p_iminsert;
192static long p_imsearch;
193#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
194static char_u *p_inex;
195#endif
196#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
197static char_u *p_inde;
198static char_u *p_indk;
199#endif
200static int p_inf;
201static char_u *p_isk;
202#ifdef FEAT_CRYPT
203static char_u *p_key;
204#endif
205#ifdef FEAT_LISP
206static int p_lisp;
207#endif
208static int p_ml;
209static int p_ma;
210static int p_mod;
211static char_u *p_mps;
212static char_u *p_nf;
213#ifdef FEAT_OSFILETYPE
214static char_u *p_oft;
215#endif
216static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000217#ifdef FEAT_TEXTOBJ
218static char_u *p_qe;
219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220static int p_ro;
221#ifdef FEAT_SMARTINDENT
222static int p_si;
223#endif
224#ifndef SHORT_FNAME
225static int p_sn;
226#endif
227static long p_sts;
228#if defined(FEAT_SEARCHPATH)
229static char_u *p_sua;
230#endif
231static long p_sw;
232static int p_swf;
233#ifdef FEAT_SYN_HL
234static char_u *p_syn;
235#endif
236static long p_ts;
237static long p_tw;
238static int p_tx;
239static long p_wm;
240#ifdef FEAT_KEYMAP
241static char_u *p_keymap;
242#endif
243
244/* Saved values for when 'bin' is set. */
245static int p_et_nobin;
246static int p_ml_nobin;
247static long p_tw_nobin;
248static long p_wm_nobin;
249
250/* Saved values for when 'paste' is set */
251static long p_tw_nopaste;
252static long p_wm_nopaste;
253static long p_sts_nopaste;
254static int p_ai_nopaste;
255
256struct vimoption
257{
258 char *fullname; /* full option name */
259 char *shortname; /* permissible abbreviation */
260 long_u flags; /* see below */
261 char_u *var; /* global option: pointer to variable;
262 * window-local option: VAR_WIN;
263 * buffer-local option: global value */
264 idopt_T indir; /* global option: PV_NONE;
265 * local option: indirect option index */
266 char_u *def_val[2]; /* default values for variable (vi and vim) */
267#ifdef FEAT_EVAL
268 scid_T scriptID; /* script in which the option was last set */
269#endif
270};
271
272#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
273#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
274
275/*
276 * Flags
277 */
278#define P_BOOL 0x01 /* the option is boolean */
279#define P_NUM 0x02 /* the option is numeric */
280#define P_STRING 0x04 /* the option is a string */
281#define P_ALLOCED 0x08 /* the string option is in allocated memory,
282 must use vim_free() when assigning new
283 value. Not set if default is the same. */
284#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
285 never be used for local or hidden options! */
286#define P_NODEFAULT 0x40 /* don't set to default value */
287#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
288 use vim_free() when assigning new value */
289#define P_WAS_SET 0x100 /* option has been set/reset */
290#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
291#define P_VI_DEF 0x400 /* Use Vi default for Vim */
292#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
293
294 /* when option changed, what to display: */
295#define P_RSTAT 0x1000 /* redraw status lines */
296#define P_RWIN 0x2000 /* redraw current window */
297#define P_RBUF 0x4000 /* redraw current buffer */
298#define P_RALL 0x6000 /* redraw all windows */
299#define P_RCLR 0x7000 /* clear and redraw all */
300
301#define P_COMMA 0x8000 /* comma separated list */
302#define P_NODUP 0x10000L/* don't allow duplicate strings */
303#define P_FLAGLIST 0x20000L/* list of single-char flags */
304
305#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
306#define P_GETTEXT 0x80000L/* expand default value with _() */
307#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000308#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309
310/*
311 * options[] is initialized here.
312 * The order of the options MUST be alphabetic for ":set all" and findoption().
313 * All option names MUST start with a lowercase letter (for findoption()).
314 * Exception: "t_" options are at the end.
315 * The options with a NULL variable are 'hidden': a set command for them is
316 * ignored and they are not printed.
317 */
318static struct vimoption
319#ifdef FEAT_GUI_W16
320 _far
321#endif
322 options[] =
323{
324 {"aleph", "al", P_NUM|P_VI_DEF,
325#ifdef FEAT_RIGHTLEFT
326 (char_u *)&p_aleph, PV_NONE,
327#else
328 (char_u *)NULL, PV_NONE,
329#endif
330 {
331#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
332 (char_u *)128L,
333#else
334 (char_u *)224L,
335#endif
336 (char_u *)0L}},
337 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
338#if defined(FEAT_GUI) && defined(MACOS_X)
339 (char_u *)&p_antialias, PV_NONE,
340 {(char_u *)FALSE, (char_u *)FALSE}
341#else
342 (char_u *)NULL, PV_NONE,
343 {(char_u *)FALSE, (char_u *)FALSE}
344#endif
345 },
346 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
347#ifdef FEAT_ARABIC
348 (char_u *)VAR_WIN, PV_ARAB,
349#else
350 (char_u *)NULL, PV_NONE,
351#endif
352 {(char_u *)FALSE, (char_u *)0L}},
353 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
354#ifdef FEAT_ARABIC
355 (char_u *)&p_arshape, PV_NONE,
356#else
357 (char_u *)NULL, PV_NONE,
358#endif
359 {(char_u *)TRUE, (char_u *)0L}},
360 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
361#ifdef FEAT_RIGHTLEFT
362 (char_u *)&p_ari, PV_NONE,
363#else
364 (char_u *)NULL, PV_NONE,
365#endif
366 {(char_u *)FALSE, (char_u *)0L}},
367 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
368#ifdef FEAT_FKMAP
369 (char_u *)&p_altkeymap, PV_NONE,
370#else
371 (char_u *)NULL, PV_NONE,
372#endif
373 {(char_u *)FALSE, (char_u *)0L}},
374 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
375#if defined(FEAT_MBYTE)
376 (char_u *)&p_ambw, PV_NONE,
377 {(char_u *)"single", (char_u *)0L}
378#else
379 (char_u *)NULL, PV_NONE,
380 {(char_u *)0L, (char_u *)0L}
381#endif
382 },
383#if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
384 {"autochdir", "acd", P_BOOL|P_VI_DEF,
385 (char_u *)&p_acd, PV_NONE,
386 {(char_u *)FALSE, (char_u *)0L}},
387#endif
388 {"autoindent", "ai", P_BOOL|P_VI_DEF,
389 (char_u *)&p_ai, PV_AI,
390 {(char_u *)FALSE, (char_u *)0L}},
391 {"autoprint", "ap", P_BOOL|P_VI_DEF,
392 (char_u *)NULL, PV_NONE,
393 {(char_u *)FALSE, (char_u *)0L}},
394 {"autoread", "ar", P_BOOL|P_VI_DEF,
395 (char_u *)&p_ar, OPT_BOTH(PV_AR),
396 {(char_u *)FALSE, (char_u *)0L}},
397 {"autowrite", "aw", P_BOOL|P_VI_DEF,
398 (char_u *)&p_aw, PV_NONE,
399 {(char_u *)FALSE, (char_u *)0L}},
400 {"autowriteall","awa", P_BOOL|P_VI_DEF,
401 (char_u *)&p_awa, PV_NONE,
402 {(char_u *)FALSE, (char_u *)0L}},
403 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
404 (char_u *)&p_bg, PV_NONE,
405 {
406#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
407 (char_u *)"dark",
408#else
409 (char_u *)"light",
410#endif
411 (char_u *)0L}},
412 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
413 (char_u *)&p_bs, PV_NONE,
414 {(char_u *)"", (char_u *)0L}},
415 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
416 (char_u *)&p_bk, PV_NONE,
417 {(char_u *)FALSE, (char_u *)0L}},
418 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
419 (char_u *)&p_bkc, PV_NONE,
420#ifdef UNIX
421 {(char_u *)"yes", (char_u *)"auto"}
422#else
423 {(char_u *)"auto", (char_u *)"auto"}
424#endif
425 },
426 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
427 (char_u *)&p_bdir, PV_NONE,
428 {(char_u *)DFLT_BDIR, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000429 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430 (char_u *)&p_bex, PV_NONE,
431 {
432#ifdef VMS
433 (char_u *)"_",
434#else
435 (char_u *)"~",
436#endif
437 (char_u *)0L}},
438 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
439#ifdef FEAT_WILDIGN
440 (char_u *)&p_bsk, PV_NONE,
441 {(char_u *)"", (char_u *)0L}
442#else
443 (char_u *)NULL, PV_NONE,
444 {(char_u *)0L, (char_u *)0L}
445#endif
446 },
447#ifdef FEAT_BEVAL
448 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
449 (char_u *)&p_bdlay, PV_NONE,
450 {(char_u *)600L, (char_u *)0L}},
451#endif
452#if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \
453 || defined(FEAT_NETBEANS_INTG))
454 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
455 (char_u *)&p_beval, PV_NONE,
456 {(char_u*)FALSE, (char_u *)0L}},
457#endif
458 {"beautify", "bf", P_BOOL|P_VI_DEF,
459 (char_u *)NULL, PV_NONE,
460 {(char_u *)FALSE, (char_u *)0L}},
461 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
462 (char_u *)&p_bin, PV_BIN,
463 {(char_u *)FALSE, (char_u *)0L}},
464 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
465#ifdef MSDOS
466 (char_u *)&p_biosk, PV_NONE,
467#else
468 (char_u *)NULL, PV_NONE,
469#endif
470 {(char_u *)TRUE, (char_u *)0L}},
471 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
472#ifdef FEAT_MBYTE
473 (char_u *)&p_bomb, PV_BOMB,
474#else
475 (char_u *)NULL, PV_NONE,
476#endif
477 {(char_u *)FALSE, (char_u *)0L}},
478 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
479#ifdef FEAT_LINEBREAK
480 (char_u *)&p_breakat, PV_NONE,
481 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
482#else
483 (char_u *)NULL, PV_NONE,
484 {(char_u *)0L, (char_u *)0L}
485#endif
486 },
487 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
488#ifdef FEAT_BROWSE
489 (char_u *)&p_bsdir, PV_NONE,
490 {(char_u *)"last", (char_u *)0L}
491#else
492 (char_u *)NULL, PV_NONE,
493 {(char_u *)0L, (char_u *)0L}
494#endif
495 },
496 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
497#if defined(FEAT_QUICKFIX)
498 (char_u *)&p_bh, PV_BH,
499 {(char_u *)"", (char_u *)0L}
500#else
501 (char_u *)NULL, PV_NONE,
502 {(char_u *)0L, (char_u *)0L}
503#endif
504 },
505 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
506 (char_u *)&p_bl, PV_BL,
507 {(char_u *)1L, (char_u *)0L}
508 },
509 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
510#if defined(FEAT_QUICKFIX)
511 (char_u *)&p_bt, PV_BT,
512 {(char_u *)"", (char_u *)0L}
513#else
514 (char_u *)NULL, PV_NONE,
515 {(char_u *)0L, (char_u *)0L}
516#endif
517 },
518 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
519 (char_u *)&p_cmp, PV_NONE,
520 {(char_u *)"internal,keepascii", (char_u *)0L}
521 },
522 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
523#ifdef FEAT_SEARCHPATH
524 (char_u *)&p_cdpath, PV_NONE,
525 {(char_u *)",,", (char_u *)0L}
526#else
527 (char_u *)NULL, PV_NONE,
528 {(char_u *)0L, (char_u *)0L}
529#endif
530 },
531 {"cedit", NULL, P_STRING,
532#ifdef FEAT_CMDWIN
533 (char_u *)&p_cedit, PV_NONE,
534 {(char_u *)"", (char_u *)CTRL_F_STR}
535#else
536 (char_u *)NULL, PV_NONE,
537 {(char_u *)0L, (char_u *)0L}
538#endif
539 },
540 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
541#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
542 (char_u *)&p_ccv, PV_NONE,
543 {(char_u *)"", (char_u *)0L}
544#else
545 (char_u *)NULL, PV_NONE,
546 {(char_u *)0L, (char_u *)0L}
547#endif
548 },
549 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
550#ifdef FEAT_CINDENT
551 (char_u *)&p_cin, PV_CIN,
552#else
553 (char_u *)NULL, PV_NONE,
554#endif
555 {(char_u *)FALSE, (char_u *)0L}},
556 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
557#ifdef FEAT_CINDENT
558 (char_u *)&p_cink, PV_CINK,
559 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
560#else
561 (char_u *)NULL, PV_NONE,
562 {(char_u *)0L, (char_u *)0L}
563#endif
564 },
565 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
566#ifdef FEAT_CINDENT
567 (char_u *)&p_cino, PV_CINO,
568#else
569 (char_u *)NULL, PV_NONE,
570#endif
571 {(char_u *)"", (char_u *)0L}},
572 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
573#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
574 (char_u *)&p_cinw, PV_CINW,
575 {(char_u *)"if,else,while,do,for,switch",
576 (char_u *)0L}
577#else
578 (char_u *)NULL, PV_NONE,
579 {(char_u *)0L, (char_u *)0L}
580#endif
581 },
582 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
583#ifdef FEAT_CLIPBOARD
584 (char_u *)&p_cb, PV_NONE,
585# ifdef FEAT_XCLIPBOARD
586 {(char_u *)"autoselect,exclude:cons\\|linux",
587 (char_u *)0L}
588# else
589 {(char_u *)"", (char_u *)0L}
590# endif
591#else
592 (char_u *)NULL, PV_NONE,
593 {(char_u *)"", (char_u *)0L}
594#endif
595 },
596 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
597 (char_u *)&p_ch, PV_NONE,
598 {(char_u *)1L, (char_u *)0L}},
599 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
600#ifdef FEAT_CMDWIN
601 (char_u *)&p_cwh, PV_NONE,
602#else
603 (char_u *)NULL, PV_NONE,
604#endif
605 {(char_u *)7L, (char_u *)0L}},
606 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
607 (char_u *)&Columns, PV_NONE,
608 {(char_u *)80L, (char_u *)0L}},
609 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
610#ifdef FEAT_COMMENTS
611 (char_u *)&p_com, PV_COM,
612 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
613 (char_u *)0L}
614#else
615 (char_u *)NULL, PV_NONE,
616 {(char_u *)0L, (char_u *)0L}
617#endif
618 },
619 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
620#ifdef FEAT_FOLDING
621 (char_u *)&p_cms, PV_CMS,
622 {(char_u *)"/*%s*/", (char_u *)0L}
623#else
624 (char_u *)NULL, PV_NONE,
625 {(char_u *)0L, (char_u *)0L}
626#endif
627 },
628 {"compatible", "cp", P_BOOL|P_RALL,
629 (char_u *)&p_cp, PV_NONE,
630 {(char_u *)TRUE, (char_u *)FALSE}},
631 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
632#ifdef FEAT_INS_EXPAND
633 (char_u *)&p_cpt, PV_CPT,
634 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
635#else
636 (char_u *)NULL, PV_NONE,
637 {(char_u *)0L, (char_u *)0L}
638#endif
639 },
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000640 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
641#ifdef FEAT_COMPL_FUNC
642 (char_u *)&p_cfu, PV_CFU,
643 {(char_u *)"", (char_u *)0L}
644#else
645 (char_u *)NULL, PV_NONE,
646 {(char_u *)0L, (char_u *)0L}
647#endif
648 },
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 {"confirm", "cf", P_BOOL|P_VI_DEF,
650#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
651 (char_u *)&p_confirm, PV_NONE,
652#else
653 (char_u *)NULL, PV_NONE,
654#endif
655 {(char_u *)FALSE, (char_u *)0L}},
656 {"conskey", "consk",P_BOOL|P_VI_DEF,
657#ifdef MSDOS
658 (char_u *)&p_consk, PV_NONE,
659#else
660 (char_u *)NULL, PV_NONE,
661#endif
662 {(char_u *)FALSE, (char_u *)0L}},
663 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
664 (char_u *)&p_ci, PV_CI,
665 {(char_u *)FALSE, (char_u *)0L}},
666 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
667 (char_u *)&p_cpo, PV_NONE,
668 {(char_u *)CPO_ALL, (char_u *)CPO_DEFAULT}},
669 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
670#ifdef FEAT_CSCOPE
671 (char_u *)&p_cspc, PV_NONE,
672#else
673 (char_u *)NULL, PV_NONE,
674#endif
675 {(char_u *)0L, (char_u *)0L}},
676 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
677#ifdef FEAT_CSCOPE
678 (char_u *)&p_csprg, PV_NONE,
679 {(char_u *)"cscope", (char_u *)0L}
680#else
681 (char_u *)NULL, PV_NONE,
682 {(char_u *)0L, (char_u *)0L}
683#endif
684 },
685 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
686#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
687 (char_u *)&p_csqf, PV_NONE,
688 {(char_u *)"", (char_u *)0L}
689#else
690 (char_u *)NULL, PV_NONE,
691 {(char_u *)0L, (char_u *)0L}
692#endif
693 },
694 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
695#ifdef FEAT_CSCOPE
696 (char_u *)&p_cst, PV_NONE,
697#else
698 (char_u *)NULL, PV_NONE,
699#endif
700 {(char_u *)0L, (char_u *)0L}},
701 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
702#ifdef FEAT_CSCOPE
703 (char_u *)&p_csto, PV_NONE,
704#else
705 (char_u *)NULL, PV_NONE,
706#endif
707 {(char_u *)0L, (char_u *)0L}},
708 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
709#ifdef FEAT_CSCOPE
710 (char_u *)&p_csverbose, PV_NONE,
711#else
712 (char_u *)NULL, PV_NONE,
713#endif
714 {(char_u *)0L, (char_u *)0L}},
715 {"debug", NULL, P_STRING|P_VI_DEF,
716 (char_u *)&p_debug, PV_NONE,
717 {(char_u *)"", (char_u *)0L}},
718 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
719#ifdef FEAT_FIND_ID
720 (char_u *)&p_def, OPT_BOTH(PV_DEF),
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000721 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722#else
723 (char_u *)NULL, PV_NONE,
724 {(char_u *)NULL, (char_u *)0L}
725#endif
726 },
727 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
728#ifdef FEAT_MBYTE
729 (char_u *)&p_deco, PV_NONE,
730#else
731 (char_u *)NULL, PV_NONE,
732#endif
733 {(char_u *)FALSE, (char_u *)0L}
734 },
735 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
736#ifdef FEAT_INS_EXPAND
737 (char_u *)&p_dict, OPT_BOTH(PV_DICT),
738#else
739 (char_u *)NULL, PV_NONE,
740#endif
741 {(char_u *)"", (char_u *)0L}},
742 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
743#ifdef FEAT_DIFF
744 (char_u *)VAR_WIN, PV_DIFF,
745#else
746 (char_u *)NULL, PV_NONE,
747#endif
748 {(char_u *)FALSE, (char_u *)0L}},
749 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
750#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
751 (char_u *)&p_dex, PV_NONE,
752 {(char_u *)"", (char_u *)0L}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
757 },
758 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
759#ifdef FEAT_DIFF
760 (char_u *)&p_dip, PV_NONE,
761 {(char_u *)"filler", (char_u *)NULL}
762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)"", (char_u *)NULL}
765#endif
766 },
767 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
768#ifdef FEAT_DIGRAPHS
769 (char_u *)&p_dg, PV_NONE,
770#else
771 (char_u *)NULL, PV_NONE,
772#endif
773 {(char_u *)FALSE, (char_u *)0L}},
774 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
775 (char_u *)&p_dir, PV_NONE,
776 {(char_u *)DFLT_DIR, (char_u *)0L}},
777 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
778 (char_u *)&p_dy, PV_NONE,
779 {(char_u *)"", (char_u *)0L}},
780 {"eadirection", "ead", P_STRING|P_VI_DEF,
781#ifdef FEAT_VERTSPLIT
782 (char_u *)&p_ead, PV_NONE,
783 {(char_u *)"both", (char_u *)0L}
784#else
785 (char_u *)NULL, PV_NONE,
786 {(char_u *)NULL, (char_u *)0L}
787#endif
788 },
789 {"edcompatible","ed", P_BOOL|P_VI_DEF,
790 (char_u *)&p_ed, PV_NONE,
791 {(char_u *)FALSE, (char_u *)0L}},
792 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
793#ifdef FEAT_MBYTE
794 (char_u *)&p_enc, PV_NONE,
795 {(char_u *)ENC_DFLT, (char_u *)0L}
796#else
797 (char_u *)NULL, PV_NONE,
798 {(char_u *)0L, (char_u *)0L}
799#endif
800 },
801 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
802 (char_u *)&p_eol, PV_EOL,
803 {(char_u *)TRUE, (char_u *)0L}},
804 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
805 (char_u *)&p_ea, PV_NONE,
806 {(char_u *)TRUE, (char_u *)0L}},
807 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
808 (char_u *)&p_ep, OPT_BOTH(PV_EP),
809 {(char_u *)"", (char_u *)0L}},
810 {"errorbells", "eb", P_BOOL|P_VI_DEF,
811 (char_u *)&p_eb, PV_NONE,
812 {(char_u *)FALSE, (char_u *)0L}},
813 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
814#ifdef FEAT_QUICKFIX
815 (char_u *)&p_ef, PV_NONE,
816 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
817#else
818 (char_u *)NULL, PV_NONE,
819 {(char_u *)NULL, (char_u *)0L}
820#endif
821 },
822 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
823#ifdef FEAT_QUICKFIX
824 (char_u *)&p_efm, OPT_BOTH(PV_EFM),
825 {(char_u *)DFLT_EFM, (char_u *)0L},
826#else
827 (char_u *)NULL, PV_NONE,
828 {(char_u *)NULL, (char_u *)0L}
829#endif
830 },
831 {"esckeys", "ek", P_BOOL|P_VIM,
832 (char_u *)&p_ek, PV_NONE,
833 {(char_u *)FALSE, (char_u *)TRUE}},
834 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
835#ifdef FEAT_AUTOCMD
836 (char_u *)&p_ei, PV_NONE,
837#else
838 (char_u *)NULL, PV_NONE,
839#endif
840 {(char_u *)"", (char_u *)0L}},
841 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
842 (char_u *)&p_et, PV_ET,
843 {(char_u *)FALSE, (char_u *)0L}},
844 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
845 (char_u *)&p_exrc, PV_NONE,
846 {(char_u *)FALSE, (char_u *)0L}},
847 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
848#ifdef FEAT_MBYTE
849 (char_u *)&p_fenc, PV_FENC,
850 {(char_u *)"", (char_u *)0L}
851#else
852 (char_u *)NULL, PV_NONE,
853 {(char_u *)0L, (char_u *)0L}
854#endif
855 },
856 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
857#ifdef FEAT_MBYTE
858 (char_u *)&p_fencs, PV_NONE,
859 {(char_u *)"ucs-bom", (char_u *)0L}
860#else
861 (char_u *)NULL, PV_NONE,
862 {(char_u *)0L, (char_u *)0L}
863#endif
864 },
865 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
866 (char_u *)&p_ff, PV_FF,
867 {(char_u *)DFLT_FF, (char_u *)0L}},
868 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
869 (char_u *)&p_ffs, PV_NONE,
870 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000871 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000872#ifdef FEAT_AUTOCMD
873 (char_u *)&p_ft, PV_FT,
874 {(char_u *)"", (char_u *)0L}
875#else
876 (char_u *)NULL, PV_NONE,
877 {(char_u *)0L, (char_u *)0L}
878#endif
879 },
880 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
881#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
882 (char_u *)&p_fcs, PV_NONE,
883 {(char_u *)"vert:|,fold:-", (char_u *)0L}
884#else
885 (char_u *)NULL, PV_NONE,
886 {(char_u *)"", (char_u *)0L}
887#endif
888 },
889 {"fkmap", "fk", P_BOOL|P_VI_DEF,
890#ifdef FEAT_FKMAP
891 (char_u *)&p_fkmap, PV_NONE,
892#else
893 (char_u *)NULL, PV_NONE,
894#endif
895 {(char_u *)FALSE, (char_u *)0L}},
896 {"flash", "fl", P_BOOL|P_VI_DEF,
897 (char_u *)NULL, PV_NONE,
898 {(char_u *)FALSE, (char_u *)0L}},
899#ifdef FEAT_FOLDING
900 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
901 (char_u *)&p_fcl, PV_NONE,
902 {(char_u *)"", (char_u *)0L}},
903 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
904 (char_u *)VAR_WIN, PV_FDC,
905 {(char_u *)FALSE, (char_u *)0L}},
906 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
907 (char_u *)VAR_WIN, PV_FEN,
908 {(char_u *)TRUE, (char_u *)0L}},
909 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
910# ifdef FEAT_EVAL
911 (char_u *)VAR_WIN, PV_FDE,
912 {(char_u *)"0", (char_u *)NULL}
913# else
914 (char_u *)NULL, PV_NONE,
915 {(char_u *)NULL, (char_u *)0L}
916# endif
917 },
918 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
919 (char_u *)VAR_WIN, PV_FDI,
920 {(char_u *)"#", (char_u *)NULL}},
921 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
922 (char_u *)VAR_WIN, PV_FDL,
923 {(char_u *)0L, (char_u *)0L}},
924 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
925 (char_u *)&p_fdls, PV_NONE,
926 {(char_u *)-1L, (char_u *)0L}},
927 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
928 P_RWIN|P_COMMA|P_NODUP,
929 (char_u *)VAR_WIN, PV_FMR,
930 {(char_u *)"{{{,}}}", (char_u *)NULL}},
931 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
932 (char_u *)VAR_WIN, PV_FDM,
933 {(char_u *)"manual", (char_u *)NULL}},
934 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
935 (char_u *)VAR_WIN, PV_FML,
936 {(char_u *)1L, (char_u *)0L}},
937 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
938 (char_u *)VAR_WIN, PV_FDN,
939 {(char_u *)20L, (char_u *)0L}},
940 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
941 (char_u *)&p_fdo, PV_NONE,
942 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
943 (char_u *)0L}},
944 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
945# ifdef FEAT_EVAL
946 (char_u *)VAR_WIN, PV_FDT,
947 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +0000948# else
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949 (char_u *)NULL, PV_NONE,
950 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +0000951# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 },
953#endif
954 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
955 (char_u *)&p_fo, PV_FO,
956 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
Bram Moolenaar86b68352004-12-27 21:59:20 +0000957 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
958 (char_u *)&p_flp, PV_FLP,
959 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
961 (char_u *)&p_fp, PV_NONE,
962 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000963 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
964#ifdef HAVE_FSYNC
965 (char_u *)&p_fs, PV_NONE,
966 {(char_u *)TRUE, (char_u *)0L}
967#else
968 (char_u *)NULL, PV_NONE,
969 {(char_u *)FALSE, (char_u *)0L}
970#endif
971 },
Bram Moolenaar071d4272004-06-13 20:20:40 +0000972 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
973 (char_u *)&p_gd, PV_NONE,
974 {(char_u *)FALSE, (char_u *)0L}},
975 {"graphic", "gr", P_BOOL|P_VI_DEF,
976 (char_u *)NULL, PV_NONE,
977 {(char_u *)FALSE, (char_u *)0L}},
978 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
979#ifdef FEAT_QUICKFIX
980 (char_u *)&p_gefm, PV_NONE,
981 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L},
982#else
983 (char_u *)NULL, PV_NONE,
984 {(char_u *)NULL, (char_u *)0L}
985#endif
986 },
987 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
988#ifdef FEAT_QUICKFIX
989 (char_u *)&p_gp, OPT_BOTH(PV_GP),
990 {
991# ifdef WIN3264
992 /* may be changed to "grep -n" in os_win32.c */
993 (char_u *)"findstr /n",
994# else
995# ifdef UNIX
996 /* Add an extra file name so that grep will always
997 * insert a file name in the match line. */
998 (char_u *)"grep -n $* /dev/null",
999# else
1000# ifdef VMS
1001 (char_u *)"SEARCH/NUMBERS ",
1002# else
1003 (char_u *)"grep -n ",
1004#endif
1005#endif
1006# endif
1007 (char_u *)0L},
1008#else
1009 (char_u *)NULL, PV_NONE,
1010 {(char_u *)NULL, (char_u *)0L}
1011#endif
1012 },
1013 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1014#ifdef CURSOR_SHAPE
1015 (char_u *)&p_guicursor, PV_NONE,
1016 {
1017# ifdef FEAT_GUI
1018 (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",
1019# else /* MSDOS or Win32 console */
1020 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1021# endif
1022 (char_u *)0L}
1023#else
1024 (char_u *)NULL, PV_NONE,
1025 {(char_u *)NULL, (char_u *)0L}
1026#endif
1027 },
1028 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1029#ifdef FEAT_GUI
1030 (char_u *)&p_guifont, PV_NONE,
1031 {(char_u *)"", (char_u *)0L}
1032#else
1033 (char_u *)NULL, PV_NONE,
1034 {(char_u *)NULL, (char_u *)0L}
1035#endif
1036 },
1037 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1038#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1039 (char_u *)&p_guifontset, PV_NONE,
1040 {(char_u *)"", (char_u *)0L}
1041#else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)NULL, (char_u *)0L}
1044#endif
1045 },
1046 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1047#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1048 (char_u *)&p_guifontwide, PV_NONE,
1049 {(char_u *)"", (char_u *)0L}
1050#else
1051 (char_u *)NULL, PV_NONE,
1052 {(char_u *)NULL, (char_u *)0L}
1053#endif
1054 },
1055 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar843ee412004-06-30 16:16:41 +00001056#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 (char_u *)&p_ghr, PV_NONE,
1058#else
1059 (char_u *)NULL, PV_NONE,
1060#endif
1061 {(char_u *)50L, (char_u *)0L}},
1062 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar843ee412004-06-30 16:16:41 +00001063#if defined(FEAT_GUI) || defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 (char_u *)&p_go, PV_NONE,
1065# if defined(UNIX) && !defined(MACOS)
1066 {(char_u *)"agimrLtT", (char_u *)0L}
1067# else
1068 {(char_u *)"gmrLtT", (char_u *)0L}
1069# endif
1070#else
1071 (char_u *)NULL, PV_NONE,
1072 {(char_u *)NULL, (char_u *)0L}
1073#endif
1074 },
1075 {"guipty", NULL, P_BOOL|P_VI_DEF,
1076#if defined(FEAT_GUI)
1077 (char_u *)&p_guipty, PV_NONE,
1078#else
1079 (char_u *)NULL, PV_NONE,
1080#endif
1081 {(char_u *)TRUE, (char_u *)0L}},
1082 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1083 (char_u *)NULL, PV_NONE,
1084 {(char_u *)0L, (char_u *)0L}},
1085 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1086 (char_u *)&p_hf, PV_NONE,
1087 {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
1088 {"helpheight", "hh", P_NUM|P_VI_DEF,
1089#ifdef FEAT_WINDOWS
1090 (char_u *)&p_hh, PV_NONE,
1091#else
1092 (char_u *)NULL, PV_NONE,
1093#endif
1094 {(char_u *)20L, (char_u *)0L}},
1095 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1096#ifdef FEAT_MULTI_LANG
1097 (char_u *)&p_hlg, PV_NONE,
1098 {(char_u *)"", (char_u *)0L}
1099#else
1100 (char_u *)NULL, PV_NONE,
1101 {(char_u *)0L, (char_u *)0L}
1102#endif
1103 },
1104 {"hidden", "hid", P_BOOL|P_VI_DEF,
1105 (char_u *)&p_hid, PV_NONE,
1106 {(char_u *)FALSE, (char_u *)0L}},
1107 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1108 (char_u *)&p_hl, PV_NONE,
1109 {(char_u *)"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",
1110 (char_u *)0L}},
1111 {"history", "hi", P_NUM|P_VIM,
1112 (char_u *)&p_hi, PV_NONE,
1113 {(char_u *)0L, (char_u *)20L}},
1114 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1115#ifdef FEAT_RIGHTLEFT
1116 (char_u *)&p_hkmap, PV_NONE,
1117#else
1118 (char_u *)NULL, PV_NONE,
1119#endif
1120 {(char_u *)FALSE, (char_u *)0L}},
1121 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1122#ifdef FEAT_RIGHTLEFT
1123 (char_u *)&p_hkmapp, PV_NONE,
1124#else
1125 (char_u *)NULL, PV_NONE,
1126#endif
1127 {(char_u *)FALSE, (char_u *)0L}},
1128 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1129 (char_u *)&p_hls, PV_NONE,
1130 {(char_u *)FALSE, (char_u *)0L}},
1131 {"icon", NULL, P_BOOL|P_VI_DEF,
1132#ifdef FEAT_TITLE
1133 (char_u *)&p_icon, PV_NONE,
1134#else
1135 (char_u *)NULL, PV_NONE,
1136#endif
1137 {(char_u *)FALSE, (char_u *)0L}},
1138 {"iconstring", NULL, P_STRING|P_VI_DEF,
1139#ifdef FEAT_TITLE
1140 (char_u *)&p_iconstring, PV_NONE,
1141#else
1142 (char_u *)NULL, PV_NONE,
1143#endif
1144 {(char_u *)"", (char_u *)0L}},
1145 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1146 (char_u *)&p_ic, PV_NONE,
1147 {(char_u *)FALSE, (char_u *)0L}},
1148 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar843ee412004-06-30 16:16:41 +00001149#if defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 (char_u *)&p_imak, PV_NONE,
1151#else
1152 (char_u *)NULL, PV_NONE,
1153#endif
1154 {(char_u *)"", (char_u *)0L}},
1155 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1156#ifdef USE_IM_CONTROL
1157 (char_u *)&p_imcmdline, PV_NONE,
1158#else
1159 (char_u *)NULL, PV_NONE,
1160#endif
1161 {(char_u *)FALSE, (char_u *)0L}},
1162 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1163#ifdef USE_IM_CONTROL
1164 (char_u *)&p_imdisable, PV_NONE,
1165#else
1166 (char_u *)NULL, PV_NONE,
1167#endif
1168#ifdef __sgi
1169 {(char_u *)TRUE, (char_u *)0L}
1170#else
1171 {(char_u *)FALSE, (char_u *)0L}
1172#endif
1173 },
1174 {"iminsert", "imi", P_NUM|P_VI_DEF,
1175 (char_u *)&p_iminsert, PV_IMI,
1176#ifdef B_IMODE_IM
1177 {(char_u *)B_IMODE_IM, (char_u *)0L}
1178#else
1179 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1180#endif
1181 },
1182 {"imsearch", "ims", P_NUM|P_VI_DEF,
1183 (char_u *)&p_imsearch, PV_IMS,
1184#ifdef B_IMODE_IM
1185 {(char_u *)B_IMODE_IM, (char_u *)0L}
1186#else
1187 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1188#endif
1189 },
1190 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1191#ifdef FEAT_FIND_ID
1192 (char_u *)&p_inc, OPT_BOTH(PV_INC),
1193 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)0L, (char_u *)0L}
1197#endif
1198 },
1199 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1200#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1201 (char_u *)&p_inex, PV_INEX,
1202 {(char_u *)"", (char_u *)0L}
1203#else
1204 (char_u *)NULL, PV_NONE,
1205 {(char_u *)0L, (char_u *)0L}
1206#endif
1207 },
1208 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1209 (char_u *)&p_is, PV_NONE,
1210 {(char_u *)FALSE, (char_u *)0L}},
1211 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1212#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1213 (char_u *)&p_inde, PV_INDE,
1214 {(char_u *)"", (char_u *)0L}
1215#else
1216 (char_u *)NULL, PV_NONE,
1217 {(char_u *)0L, (char_u *)0L}
1218#endif
1219 },
1220 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1221#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1222 (char_u *)&p_indk, PV_INDK,
1223 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1224#else
1225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)0L, (char_u *)0L}
1227#endif
1228 },
1229 {"infercase", "inf", P_BOOL|P_VI_DEF,
1230 (char_u *)&p_inf, PV_INF,
1231 {(char_u *)FALSE, (char_u *)0L}},
1232 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1233 (char_u *)&p_im, PV_NONE,
1234 {(char_u *)FALSE, (char_u *)0L}},
1235 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1236 (char_u *)&p_isf, PV_NONE,
1237 {
1238#ifdef BACKSLASH_IN_FILENAME
1239 /* Excluded are: & and ^ are special in cmd.exe
1240 * ( and ) are used in text separating fnames */
1241 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1242#else
1243# ifdef AMIGA
1244 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1245# else
1246# ifdef VMS
1247 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1248# else /* UNIX et al. */
1249# ifdef EBCDIC
1250 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1251# else
1252 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1253# endif
1254# endif
1255# endif
1256#endif
1257 (char_u *)0L}},
1258 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1259 (char_u *)&p_isi, PV_NONE,
1260 {
1261#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1262 (char_u *)"@,48-57,_,128-167,224-235",
1263#else
1264# ifdef EBCDIC
1265 /* TODO: EBCDIC Check this! @ == isalpha()*/
1266 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1267 "112-120,128,140-142,156,158,172,"
1268 "174,186,191,203-207,219-225,235-239,"
1269 "251-254",
1270# else
1271 (char_u *)"@,48-57,_,192-255",
1272# endif
1273#endif
1274 (char_u *)0L}},
1275 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1276 (char_u *)&p_isk, PV_ISK,
1277 {
1278#ifdef EBCDIC
1279 (char_u *)"@,240-249,_",
1280 /* TODO: EBCDIC Check this! @ == isalpha()*/
1281 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1282 "112-120,128,140-142,156,158,172,"
1283 "174,186,191,203-207,219-225,235-239,"
1284 "251-254",
1285#else
1286 (char_u *)"@,48-57,_",
1287# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1288 (char_u *)"@,48-57,_,128-167,224-235"
1289# else
1290 (char_u *)"@,48-57,_,192-255"
1291# endif
1292#endif
1293 }},
1294 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1295 (char_u *)&p_isp, PV_NONE,
1296 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001297#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1298 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 || defined(VMS)
1300 (char_u *)"@,~-255",
1301#else
1302# ifdef EBCDIC
1303 /* all chars above 63 are printable */
1304 (char_u *)"63-255",
1305# else
1306 (char_u *)"@,161-255",
1307# endif
1308#endif
1309 (char_u *)0L}},
1310 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1311 (char_u *)&p_js, PV_NONE,
1312 {(char_u *)TRUE, (char_u *)0L}},
1313 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1314#ifdef FEAT_CRYPT
1315 (char_u *)&p_key, PV_KEY,
1316 {(char_u *)"", (char_u *)0L}
1317#else
1318 (char_u *)NULL, PV_NONE,
1319 {(char_u *)0L, (char_u *)0L}
1320#endif
1321 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001322 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323#ifdef FEAT_KEYMAP
1324 (char_u *)&p_keymap, PV_KMAP,
1325 {(char_u *)"", (char_u *)0L}
1326#else
1327 (char_u *)NULL, PV_NONE,
1328 {(char_u *)"", (char_u *)0L}
1329#endif
1330 },
1331 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1332#ifdef FEAT_VISUAL
1333 (char_u *)&p_km, PV_NONE,
1334#else
1335 (char_u *)NULL, PV_NONE,
1336#endif
1337 {(char_u *)"", (char_u *)0L}},
1338 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1339 (char_u *)&p_kp, OPT_BOTH(PV_KP),
1340 {
1341#if defined(MSDOS) || defined(MSWIN)
1342 (char_u *)":help",
1343#else
1344#ifdef VMS
1345 (char_u *)"help",
1346#else
1347# if defined(OS2)
1348 (char_u *)"view /",
1349# else
1350# ifdef USEMAN_S
1351 (char_u *)"man -s",
1352# else
1353 (char_u *)"man",
1354# endif
1355# endif
1356#endif
1357#endif
1358 (char_u *)0L}},
1359 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1360#ifdef FEAT_LANGMAP
1361 (char_u *)&p_langmap, PV_NONE,
1362 {(char_u *)"", /* unmatched } */
1363#else
1364 (char_u *)NULL, PV_NONE,
1365 {(char_u *)NULL,
1366#endif
1367 (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001368 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1370 (char_u *)&p_lm, PV_NONE,
1371#else
1372 (char_u *)NULL, PV_NONE,
1373#endif
1374 {(char_u *)"", (char_u *)0L}},
1375 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1376#ifdef FEAT_WINDOWS
1377 (char_u *)&p_ls, PV_NONE,
1378#else
1379 (char_u *)NULL, PV_NONE,
1380#endif
1381 {(char_u *)1L, (char_u *)0L}},
1382 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1383 (char_u *)&p_lz, PV_NONE,
1384 {(char_u *)FALSE, (char_u *)0L}},
1385 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1386#ifdef FEAT_LINEBREAK
1387 (char_u *)VAR_WIN, PV_LBR,
1388#else
1389 (char_u *)NULL, PV_NONE,
1390#endif
1391 {(char_u *)FALSE, (char_u *)0L}},
1392 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1393 (char_u *)&Rows, PV_NONE,
1394 {
1395#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1396 (char_u *)25L,
1397#else
1398 (char_u *)24L,
1399#endif
1400 (char_u *)0L}},
1401 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1402#ifdef FEAT_GUI
1403 (char_u *)&p_linespace, PV_NONE,
1404#else
1405 (char_u *)NULL, PV_NONE,
1406#endif
1407#ifdef FEAT_GUI_W32
1408 {(char_u *)1L, (char_u *)0L}
1409#else
1410 {(char_u *)0L, (char_u *)0L}
1411#endif
1412 },
1413 {"lisp", NULL, P_BOOL|P_VI_DEF,
1414#ifdef FEAT_LISP
1415 (char_u *)&p_lisp, PV_LISP,
1416#else
1417 (char_u *)NULL, PV_NONE,
1418#endif
1419 {(char_u *)FALSE, (char_u *)0L}},
1420 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1421#ifdef FEAT_LISP
1422 (char_u *)&p_lispwords, PV_NONE,
1423 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1424#else
1425 (char_u *)NULL, PV_NONE,
1426 {(char_u *)"", (char_u *)0L}
1427#endif
1428 },
1429 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1430 (char_u *)VAR_WIN, PV_LIST,
1431 {(char_u *)FALSE, (char_u *)0L}},
1432 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1433 (char_u *)&p_lcs, PV_NONE,
1434 {(char_u *)"eol:$", (char_u *)0L}},
1435 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1436 (char_u *)&p_lpl, PV_NONE,
1437 {(char_u *)TRUE, (char_u *)0L}},
1438 {"magic", NULL, P_BOOL|P_VI_DEF,
1439 (char_u *)&p_magic, PV_NONE,
1440 {(char_u *)TRUE, (char_u *)0L}},
1441 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1442#ifdef FEAT_QUICKFIX
1443 (char_u *)&p_mef, PV_NONE,
1444 {(char_u *)"", (char_u *)0L}
1445#else
1446 (char_u *)NULL, PV_NONE,
1447 {(char_u *)NULL, (char_u *)0L}
1448#endif
1449 },
1450 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1451#ifdef FEAT_QUICKFIX
1452 (char_u *)&p_mp, OPT_BOTH(PV_MP),
1453# ifdef VMS
1454 {(char_u *)"MMS", (char_u *)0L}
1455# else
1456 {(char_u *)"make", (char_u *)0L}
1457# endif
1458#else
1459 (char_u *)NULL, PV_NONE,
1460 {(char_u *)NULL, (char_u *)0L}
1461#endif
1462 },
1463 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1464 (char_u *)&p_mps, PV_MPS,
1465 {(char_u *)"(:),{:},[:]", (char_u *)0L}},
1466 {"matchtime", "mat", P_NUM|P_VI_DEF,
1467 (char_u *)&p_mat, PV_NONE,
1468 {(char_u *)5L, (char_u *)0L}},
1469 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1470#ifdef FEAT_EVAL
1471 (char_u *)&p_mfd, PV_NONE,
1472#else
1473 (char_u *)NULL, PV_NONE,
1474#endif
1475 {(char_u *)100L, (char_u *)0L}},
1476 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1477 (char_u *)&p_mmd, PV_NONE,
1478 {(char_u *)1000L, (char_u *)0L}},
1479 {"maxmem", "mm", P_NUM|P_VI_DEF,
1480 (char_u *)&p_mm, PV_NONE,
1481 {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
1482 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1483 (char_u *)&p_mmt, PV_NONE,
1484 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
1485 {"menuitems", "mis", P_NUM|P_VI_DEF,
1486#ifdef FEAT_MENU
1487 (char_u *)&p_mis, PV_NONE,
1488#else
1489 (char_u *)NULL, PV_NONE,
1490#endif
1491 {(char_u *)25L, (char_u *)0L}},
1492 {"mesg", NULL, P_BOOL|P_VI_DEF,
1493 (char_u *)NULL, PV_NONE,
1494 {(char_u *)FALSE, (char_u *)0L}},
1495 {"modeline", "ml", P_BOOL|P_VIM,
1496 (char_u *)&p_ml, PV_ML,
1497 {(char_u *)FALSE, (char_u *)TRUE}},
1498 {"modelines", "mls", P_NUM|P_VI_DEF,
1499 (char_u *)&p_mls, PV_NONE,
1500 {(char_u *)5L, (char_u *)0L}},
1501 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1502 (char_u *)&p_ma, PV_MA,
1503 {(char_u *)TRUE, (char_u *)0L}},
1504 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1505 (char_u *)&p_mod, PV_MOD,
1506 {(char_u *)FALSE, (char_u *)0L}},
1507 {"more", NULL, P_BOOL|P_VIM,
1508 (char_u *)&p_more, PV_NONE,
1509 {(char_u *)FALSE, (char_u *)TRUE}},
1510 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1511 (char_u *)&p_mouse, PV_NONE,
1512 {
1513#if defined(MSDOS) || defined(WIN3264)
1514 (char_u *)"a",
1515#else
1516 (char_u *)"",
1517#endif
1518 (char_u *)0L}},
1519 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1520#ifdef FEAT_GUI
1521 (char_u *)&p_mousef, PV_NONE,
1522#else
1523 (char_u *)NULL, PV_NONE,
1524#endif
1525 {(char_u *)FALSE, (char_u *)0L}},
1526 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1527#ifdef FEAT_GUI
1528 (char_u *)&p_mh, PV_NONE,
1529#else
1530 (char_u *)NULL, PV_NONE,
1531#endif
1532 {(char_u *)TRUE, (char_u *)0L}},
1533 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1534 (char_u *)&p_mousem, PV_NONE,
1535 {
1536#if defined(MSDOS) || defined(MSWIN)
1537 (char_u *)"popup",
1538#else
1539# if defined(MACOS)
1540 (char_u *)"popup_setpos",
1541# else
1542 (char_u *)"extend",
1543# endif
1544#endif
1545 (char_u *)0L}},
1546 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1547#ifdef FEAT_MOUSESHAPE
1548 (char_u *)&p_mouseshape, PV_NONE,
1549 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1550#else
1551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)NULL, (char_u *)0L}
1553#endif
1554 },
1555 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1556 (char_u *)&p_mouset, PV_NONE,
1557 {(char_u *)500L, (char_u *)0L}},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001558 {"mzquantum", "mzq", P_NUM,
1559#ifdef FEAT_MZSCHEME
1560 (char_u *)&p_mzq, PV_NONE,
1561#else
1562 (char_u *)NULL, PV_NONE,
1563#endif
1564 {(char_u *)100L, (char_u *)100L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565 {"novice", NULL, P_BOOL|P_VI_DEF,
1566 (char_u *)NULL, PV_NONE,
1567 {(char_u *)FALSE, (char_u *)0L}},
1568 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1569 (char_u *)&p_nf, PV_NF,
1570 {(char_u *)"octal,hex", (char_u *)0L}},
1571 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1572 (char_u *)VAR_WIN, PV_NU,
1573 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001574 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1575#ifdef FEAT_LINEBREAK
1576 (char_u *)VAR_WIN, PV_NUW,
1577#else
1578 (char_u *)NULL, PV_NONE,
1579#endif
1580 {(char_u *)8L, (char_u *)4L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"open", NULL, P_BOOL|P_VI_DEF,
1582 (char_u *)NULL, PV_NONE,
1583 {(char_u *)FALSE, (char_u *)0L}},
1584 {"optimize", "opt", P_BOOL|P_VI_DEF,
1585 (char_u *)NULL, PV_NONE,
1586 {(char_u *)FALSE, (char_u *)0L}},
1587 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1588#ifdef FEAT_OSFILETYPE
1589 (char_u *)&p_oft, PV_OFT,
1590 {(char_u *)DFLT_OFT, (char_u *)0L}
1591#else
1592 (char_u *)NULL, PV_NONE,
1593 {(char_u *)0L, (char_u *)0L}
1594#endif
1595 },
1596 {"paragraphs", "para", P_STRING|P_VI_DEF,
1597 (char_u *)&p_para, PV_NONE,
1598 {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}},
1599 {"paste", NULL, P_BOOL|P_VI_DEF,
1600 (char_u *)&p_paste, PV_NONE,
1601 {(char_u *)FALSE, (char_u *)0L}},
1602 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1603 (char_u *)&p_pt, PV_NONE,
1604 {(char_u *)"", (char_u *)0L}},
1605 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1606#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1607 (char_u *)&p_pex, PV_NONE,
1608 {(char_u *)"", (char_u *)0L}
1609#else
1610 (char_u *)NULL, PV_NONE,
1611 {(char_u *)0L, (char_u *)0L}
1612#endif
1613 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001614 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615 (char_u *)&p_pm, PV_NONE,
1616 {(char_u *)"", (char_u *)0L}},
1617 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
1618 (char_u *)&p_path, OPT_BOTH(PV_PATH),
1619 {
1620#if defined AMIGA || defined MSDOS || defined MSWIN
1621 (char_u *)".,,",
1622#else
1623# if defined(__EMX__)
1624 (char_u *)".,/emx/include,,",
1625# else /* Unix, probably */
1626 (char_u *)".,/usr/include,,",
1627# endif
1628#endif
1629 (char_u *)0L}},
1630 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1631 (char_u *)&p_pi, PV_PI,
1632 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001633 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001634#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1635 (char_u *)&p_pvh, PV_NONE,
1636#else
1637 (char_u *)NULL, PV_NONE,
1638#endif
1639 {(char_u *)12L, (char_u *)0L}},
1640 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1641#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1642 (char_u *)VAR_WIN, PV_PVW,
1643#else
1644 (char_u *)NULL, PV_NONE,
1645#endif
1646 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001647 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648#ifdef FEAT_PRINTER
1649 (char_u *)&p_pdev, PV_NONE,
1650 {(char_u *)"", (char_u *)0L}
1651#else
1652 (char_u *)NULL, PV_NONE,
1653 {(char_u *)NULL, (char_u *)0L}
1654#endif
1655 },
1656 {"printencoding", "penc", P_STRING|P_VI_DEF,
1657#ifdef FEAT_POSTSCRIPT
1658 (char_u *)&p_penc, PV_NONE,
1659 {(char_u *)"", (char_u *)0L}
1660#else
1661 (char_u *)NULL, PV_NONE,
1662 {(char_u *)NULL, (char_u *)0L}
1663#endif
1664 },
1665 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1666#ifdef FEAT_POSTSCRIPT
1667 (char_u *)&p_pexpr, PV_NONE,
1668 {(char_u *)"", (char_u *)0L}
1669#else
1670 (char_u *)NULL, PV_NONE,
1671 {(char_u *)NULL, (char_u *)0L}
1672#endif
1673 },
1674 {"printfont", "pfn", P_STRING|P_VI_DEF,
1675#ifdef FEAT_PRINTER
1676 (char_u *)&p_pfn, PV_NONE,
1677 {
1678# ifdef MSWIN
1679 (char_u *)"Courier_New:h10",
1680# else
1681 (char_u *)"courier",
1682# endif
1683 (char_u *)0L}
1684#else
1685 (char_u *)NULL, PV_NONE,
1686 {(char_u *)NULL, (char_u *)0L}
1687#endif
1688 },
1689 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1690#ifdef FEAT_PRINTER
1691 (char_u *)&p_header, PV_NONE,
1692 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1693#else
1694 (char_u *)NULL, PV_NONE,
1695 {(char_u *)NULL, (char_u *)0L}
1696#endif
1697 },
Bram Moolenaar8299df92004-07-10 09:47:34 +00001698 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1699#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1700 (char_u *)&p_pmcs, PV_NONE,
1701 {(char_u *)"", (char_u *)0L}
1702#else
1703 (char_u *)NULL, PV_NONE,
1704 {(char_u *)NULL, (char_u *)0L}
1705#endif
1706 },
1707 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1708#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1709 (char_u *)&p_pmfn, PV_NONE,
1710 {(char_u *)"", (char_u *)0L}
1711#else
1712 (char_u *)NULL, PV_NONE,
1713 {(char_u *)NULL, (char_u *)0L}
1714#endif
1715 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1717#ifdef FEAT_PRINTER
1718 (char_u *)&p_popt, PV_NONE,
1719 {(char_u *)"", (char_u *)0L}
1720#else
1721 (char_u *)NULL, PV_NONE,
1722 {(char_u *)NULL, (char_u *)0L}
1723#endif
1724 },
1725 {"prompt", NULL, P_BOOL|P_VI_DEF,
1726 (char_u *)NULL, PV_NONE,
1727 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001728 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
1729#ifdef FEAT_TEXTOBJ
1730 (char_u *)&p_qe, PV_QE,
1731 {(char_u *)"\\", (char_u *)0L}
1732#else
1733 (char_u *)NULL, PV_NONE,
1734 {(char_u *)NULL, (char_u *)0L}
1735#endif
1736 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1738 (char_u *)&p_ro, PV_RO,
1739 {(char_u *)FALSE, (char_u *)0L}},
1740 {"redraw", NULL, P_BOOL|P_VI_DEF,
1741 (char_u *)NULL, PV_NONE,
1742 {(char_u *)FALSE, (char_u *)0L}},
1743 {"remap", NULL, P_BOOL|P_VI_DEF,
1744 (char_u *)&p_remap, PV_NONE,
1745 {(char_u *)TRUE, (char_u *)0L}},
1746 {"report", NULL, P_NUM|P_VI_DEF,
1747 (char_u *)&p_report, PV_NONE,
1748 {(char_u *)2L, (char_u *)0L}},
1749 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
1750#ifdef WIN3264
1751 (char_u *)&p_rs, PV_NONE,
1752#else
1753 (char_u *)NULL, PV_NONE,
1754#endif
1755 {(char_u *)TRUE, (char_u *)0L}},
1756 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
1757#ifdef FEAT_RIGHTLEFT
1758 (char_u *)&p_ri, PV_NONE,
1759#else
1760 (char_u *)NULL, PV_NONE,
1761#endif
1762 {(char_u *)FALSE, (char_u *)0L}},
1763 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
1764#ifdef FEAT_RIGHTLEFT
1765 (char_u *)VAR_WIN, PV_RL,
1766#else
1767 (char_u *)NULL, PV_NONE,
1768#endif
1769 {(char_u *)FALSE, (char_u *)0L}},
1770 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
1771#ifdef FEAT_RIGHTLEFT
1772 (char_u *)VAR_WIN, PV_RLC,
1773 {(char_u *)"search", (char_u *)NULL}
1774#else
1775 (char_u *)NULL, PV_NONE,
1776 {(char_u *)NULL, (char_u *)0L}
1777#endif
1778 },
1779 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
1780#ifdef FEAT_CMDL_INFO
1781 (char_u *)&p_ru, PV_NONE,
1782#else
1783 (char_u *)NULL, PV_NONE,
1784#endif
1785 {(char_u *)FALSE, (char_u *)0L}},
1786 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
1787#ifdef FEAT_STL_OPT
1788 (char_u *)&p_ruf, PV_NONE,
1789#else
1790 (char_u *)NULL, PV_NONE,
1791#endif
1792 {(char_u *)"", (char_u *)0L}},
1793 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
1794 (char_u *)&p_rtp, PV_NONE,
1795 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
1796 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
1797 (char_u *)VAR_WIN, PV_SCROLL,
1798 {(char_u *)12L, (char_u *)0L}},
1799 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
1800#ifdef FEAT_SCROLLBIND
1801 (char_u *)VAR_WIN, PV_SCBIND,
1802#else
1803 (char_u *)NULL, PV_NONE,
1804#endif
1805 {(char_u *)FALSE, (char_u *)0L}},
1806 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
1807 (char_u *)&p_sj, PV_NONE,
1808 {(char_u *)1L, (char_u *)0L}},
1809 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
1810 (char_u *)&p_so, PV_NONE,
1811 {(char_u *)0L, (char_u *)0L}},
1812 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1813#ifdef FEAT_SCROLLBIND
1814 (char_u *)&p_sbo, PV_NONE,
1815 {(char_u *)"ver,jump", (char_u *)0L}
1816#else
1817 (char_u *)NULL, PV_NONE,
1818 {(char_u *)0L, (char_u *)0L}
1819#endif
1820 },
1821 {"sections", "sect", P_STRING|P_VI_DEF,
1822 (char_u *)&p_sections, PV_NONE,
1823 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
1824 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
1825 (char_u *)&p_secure, PV_NONE,
1826 {(char_u *)FALSE, (char_u *)0L}},
1827 {"selection", "sel", P_STRING|P_VI_DEF,
1828#ifdef FEAT_VISUAL
1829 (char_u *)&p_sel, PV_NONE,
1830#else
1831 (char_u *)NULL, PV_NONE,
1832#endif
1833 {(char_u *)"inclusive", (char_u *)0L}},
1834 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1835#ifdef FEAT_VISUAL
1836 (char_u *)&p_slm, PV_NONE,
1837#else
1838 (char_u *)NULL, PV_NONE,
1839#endif
1840 {(char_u *)"", (char_u *)0L}},
1841 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1842#ifdef FEAT_SESSION
1843 (char_u *)&p_ssop, PV_NONE,
1844 {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
1845 (char_u *)0L}
1846#else
1847 (char_u *)NULL, PV_NONE,
1848 {(char_u *)0L, (char_u *)0L}
1849#endif
1850 },
1851 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1852 (char_u *)&p_sh, PV_NONE,
1853 {
1854#ifdef VMS
1855 (char_u *)"-",
1856#else
1857# if defined(MSDOS)
1858 (char_u *)"command",
1859# else
1860# if defined(WIN16)
1861 (char_u *)"command.com",
1862# else
1863# if defined(WIN3264)
1864 (char_u *)"", /* set in set_init_1() */
1865# else
1866# if defined(OS2)
1867 (char_u *)"cmd.exe",
1868# else
1869# if defined(ARCHIE)
1870 (char_u *)"gos",
1871# else
1872 (char_u *)"sh",
1873# endif
1874# endif
1875# endif
1876# endif
1877# endif
1878#endif /* VMS */
1879 (char_u *)0L}},
1880 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
1881 (char_u *)&p_shcf, PV_NONE,
1882 {
1883#if defined(MSDOS) || defined(MSWIN)
1884 (char_u *)"/c",
1885#else
1886# if defined(OS2)
1887 (char_u *)"/c",
1888# else
1889 (char_u *)"-c",
1890# endif
1891#endif
1892 (char_u *)0L}},
1893 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
1894#ifdef FEAT_QUICKFIX
1895 (char_u *)&p_sp, PV_NONE,
1896 {
1897#if defined(UNIX) || defined(OS2)
1898# ifdef ARCHIE
1899 (char_u *)"2>",
1900# else
1901 (char_u *)"| tee",
1902# endif
1903#else
1904 (char_u *)">",
1905#endif
1906 (char_u *)0L}
1907#else
1908 (char_u *)NULL, PV_NONE,
1909 {(char_u *)0L, (char_u *)0L}
1910#endif
1911 },
1912 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
1913 (char_u *)&p_shq, PV_NONE,
1914 {(char_u *)"", (char_u *)0L}},
1915 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
1916 (char_u *)&p_srr, PV_NONE,
1917 {(char_u *)">", (char_u *)0L}},
1918 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
1919#ifdef BACKSLASH_IN_FILENAME
1920 (char_u *)&p_ssl, PV_NONE,
1921#else
1922 (char_u *)NULL, PV_NONE,
1923#endif
1924 {(char_u *)FALSE, (char_u *)0L}},
1925 {"shelltype", "st", P_NUM|P_VI_DEF,
1926#ifdef AMIGA
1927 (char_u *)&p_st, PV_NONE,
1928#else
1929 (char_u *)NULL, PV_NONE,
1930#endif
1931 {(char_u *)0L, (char_u *)0L}},
1932 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
1933 (char_u *)&p_sxq, PV_NONE,
1934 {
1935#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
1936 (char_u *)"\"",
1937#else
1938 (char_u *)"",
1939#endif
1940 (char_u *)0L}},
1941 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
1942 (char_u *)&p_sr, PV_NONE,
1943 {(char_u *)FALSE, (char_u *)0L}},
1944 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
1945 (char_u *)&p_sw, PV_SW,
1946 {(char_u *)8L, (char_u *)0L}},
1947 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
1948 (char_u *)&p_shm, PV_NONE,
1949 {(char_u *)"", (char_u *)"filnxtToO"}},
1950 {"shortname", "sn", P_BOOL|P_VI_DEF,
1951#ifdef SHORT_FNAME
1952 (char_u *)NULL, PV_NONE,
1953#else
1954 (char_u *)&p_sn, PV_SN,
1955#endif
1956 {(char_u *)FALSE, (char_u *)0L}},
1957 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
1958#ifdef FEAT_LINEBREAK
1959 (char_u *)&p_sbr, PV_NONE,
1960#else
1961 (char_u *)NULL, PV_NONE,
1962#endif
1963 {(char_u *)"", (char_u *)0L}},
1964 {"showcmd", "sc", P_BOOL|P_VIM,
1965#ifdef FEAT_CMDL_INFO
1966 (char_u *)&p_sc, PV_NONE,
1967#else
1968 (char_u *)NULL, PV_NONE,
1969#endif
1970 {(char_u *)FALSE,
1971#ifdef UNIX
1972 (char_u *)FALSE
1973#else
1974 (char_u *)TRUE
1975#endif
1976 }},
1977 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
1978 (char_u *)&p_sft, PV_NONE,
1979 {(char_u *)FALSE, (char_u *)0L}},
1980 {"showmatch", "sm", P_BOOL|P_VI_DEF,
1981 (char_u *)&p_sm, PV_NONE,
1982 {(char_u *)FALSE, (char_u *)0L}},
1983 {"showmode", "smd", P_BOOL|P_VIM,
1984 (char_u *)&p_smd, PV_NONE,
1985 {(char_u *)FALSE, (char_u *)TRUE}},
1986 {"sidescroll", "ss", P_NUM|P_VI_DEF,
1987 (char_u *)&p_ss, PV_NONE,
1988 {(char_u *)0L, (char_u *)0L}},
1989 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
1990 (char_u *)&p_siso, PV_NONE,
1991 {(char_u *)0L, (char_u *)0L}},
1992 {"slowopen", "slow", P_BOOL|P_VI_DEF,
1993 (char_u *)NULL, PV_NONE,
1994 {(char_u *)FALSE, (char_u *)0L}},
1995 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
1996 (char_u *)&p_scs, PV_NONE,
1997 {(char_u *)FALSE, (char_u *)0L}},
1998 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
1999#ifdef FEAT_SMARTINDENT
2000 (char_u *)&p_si, PV_SI,
2001#else
2002 (char_u *)NULL, PV_NONE,
2003#endif
2004 {(char_u *)FALSE, (char_u *)0L}},
2005 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2006 (char_u *)&p_sta, PV_NONE,
2007 {(char_u *)FALSE, (char_u *)0L}},
2008 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2009 (char_u *)&p_sts, PV_STS,
2010 {(char_u *)0L, (char_u *)0L}},
2011 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2012 (char_u *)NULL, PV_NONE,
2013 {(char_u *)FALSE, (char_u *)0L}},
2014 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2015#ifdef FEAT_WINDOWS
2016 (char_u *)&p_sb, PV_NONE,
2017#else
2018 (char_u *)NULL, PV_NONE,
2019#endif
2020 {(char_u *)FALSE, (char_u *)0L}},
2021 {"splitright", "spr", P_BOOL|P_VI_DEF,
2022#ifdef FEAT_VERTSPLIT
2023 (char_u *)&p_spr, PV_NONE,
2024#else
2025 (char_u *)NULL, PV_NONE,
2026#endif
2027 {(char_u *)FALSE, (char_u *)0L}},
2028 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2029 (char_u *)&p_sol, PV_NONE,
2030 {(char_u *)TRUE, (char_u *)0L}},
2031 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2032#ifdef FEAT_STL_OPT
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002033 (char_u *)&p_stl, OPT_BOTH(PV_STL),
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034#else
2035 (char_u *)NULL, PV_NONE,
2036#endif
2037 {(char_u *)"", (char_u *)0L}},
2038 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2039 (char_u *)&p_su, PV_NONE,
2040 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2041 (char_u *)0L}},
2042 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
2043#if defined(FEAT_SEARCHPATH)
2044 (char_u *)&p_sua, PV_SUA,
2045 {(char_u *)"", (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)0L, (char_u *)0L}
2049#endif
2050 },
2051 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2052 (char_u *)&p_swf, PV_SWF,
2053 {(char_u *)TRUE, (char_u *)0L}},
2054 {"swapsync", "sws", P_STRING|P_VI_DEF,
2055 (char_u *)&p_sws, PV_NONE,
2056 {(char_u *)"fsync", (char_u *)0L}},
2057 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2058 (char_u *)&p_swb, PV_NONE,
2059 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002060 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061#ifdef FEAT_SYN_HL
2062 (char_u *)&p_syn, PV_SYN,
2063 {(char_u *)"", (char_u *)0L}
2064#else
2065 (char_u *)NULL, PV_NONE,
2066 {(char_u *)0L, (char_u *)0L}
2067#endif
2068 },
2069 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2070 (char_u *)&p_ts, PV_TS,
2071 {(char_u *)8L, (char_u *)0L}},
2072 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2073 (char_u *)&p_tbs, PV_NONE,
2074#ifdef VMS /* binary searching doesn't appear to work on VMS */
2075 {(char_u *)0L, (char_u *)0L}
2076#else
2077 {(char_u *)TRUE, (char_u *)0L}
2078#endif
2079 },
2080 {"taglength", "tl", P_NUM|P_VI_DEF,
2081 (char_u *)&p_tl, PV_NONE,
2082 {(char_u *)0L, (char_u *)0L}},
2083 {"tagrelative", "tr", P_BOOL|P_VIM,
2084 (char_u *)&p_tr, PV_NONE,
2085 {(char_u *)FALSE, (char_u *)TRUE}},
2086 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2087 (char_u *)&p_tags, OPT_BOTH(PV_TAGS),
2088 {
2089#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2090 (char_u *)"./tags,./TAGS,tags,TAGS",
2091#else
2092 (char_u *)"./tags,tags",
2093#endif
2094 (char_u *)0L}},
2095 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2096 (char_u *)&p_tgst, PV_NONE,
2097 {(char_u *)TRUE, (char_u *)0L}},
2098 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2099 (char_u *)&T_NAME, PV_NONE,
2100 {(char_u *)"", (char_u *)0L}},
2101 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2102#ifdef FEAT_ARABIC
2103 (char_u *)&p_tbidi, PV_NONE,
2104#else
2105 (char_u *)NULL, PV_NONE,
2106#endif
2107 {(char_u *)FALSE, (char_u *)0L}},
2108 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2109#ifdef FEAT_MBYTE
2110 (char_u *)&p_tenc, PV_NONE,
2111 {(char_u *)"", (char_u *)0L}
2112#else
2113 (char_u *)NULL, PV_NONE,
2114 {(char_u *)0L, (char_u *)0L}
2115#endif
2116 },
2117 {"terse", NULL, P_BOOL|P_VI_DEF,
2118 (char_u *)&p_terse, PV_NONE,
2119 {(char_u *)FALSE, (char_u *)0L}},
2120 {"textauto", "ta", P_BOOL|P_VIM,
2121 (char_u *)&p_ta, PV_NONE,
2122 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2123 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2124 (char_u *)&p_tx, PV_TX,
2125 {
2126#ifdef USE_CRNL
2127 (char_u *)TRUE,
2128#else
2129 (char_u *)FALSE,
2130#endif
2131 (char_u *)0L}},
2132 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2133 (char_u *)&p_tw, PV_TW,
2134 {(char_u *)0L, (char_u *)0L}},
2135 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2136#ifdef FEAT_INS_EXPAND
2137 (char_u *)&p_tsr, OPT_BOTH(PV_TSR),
2138#else
2139 (char_u *)NULL, PV_NONE,
2140#endif
2141 {(char_u *)"", (char_u *)0L}},
2142 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2143 (char_u *)&p_to, PV_NONE,
2144 {(char_u *)FALSE, (char_u *)0L}},
2145 {"timeout", "to", P_BOOL|P_VI_DEF,
2146 (char_u *)&p_timeout, PV_NONE,
2147 {(char_u *)TRUE, (char_u *)0L}},
2148 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2149 (char_u *)&p_tm, PV_NONE,
2150 {(char_u *)1000L, (char_u *)0L}},
2151 {"title", NULL, P_BOOL|P_VI_DEF,
2152#ifdef FEAT_TITLE
2153 (char_u *)&p_title, PV_NONE,
2154#else
2155 (char_u *)NULL, PV_NONE,
2156#endif
2157 {(char_u *)FALSE, (char_u *)0L}},
2158 {"titlelen", NULL, P_NUM|P_VI_DEF,
2159#ifdef FEAT_TITLE
2160 (char_u *)&p_titlelen, PV_NONE,
2161#else
2162 (char_u *)NULL, PV_NONE,
2163#endif
2164 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002165 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166#ifdef FEAT_TITLE
2167 (char_u *)&p_titleold, PV_NONE,
2168 {(char_u *)N_("Thanks for flying Vim"),
2169 (char_u *)0L}
2170#else
2171 (char_u *)NULL, PV_NONE,
2172 {(char_u *)0L, (char_u *)0L}
2173#endif
2174 },
2175 {"titlestring", NULL, P_STRING|P_VI_DEF,
2176#ifdef FEAT_TITLE
2177 (char_u *)&p_titlestring, PV_NONE,
2178#else
2179 (char_u *)NULL, PV_NONE,
2180#endif
2181 {(char_u *)"", (char_u *)0L}},
2182#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2183 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2184 (char_u *)&p_toolbar, PV_NONE,
2185 {(char_u *)"icons,tooltips", (char_u *)0L}},
2186#endif
2187#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2188 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2189 (char_u *)&p_tbis, PV_NONE,
2190 {(char_u *)"small", (char_u *)0L}},
2191#endif
2192 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2193 (char_u *)&p_ttimeout, PV_NONE,
2194 {(char_u *)FALSE, (char_u *)0L}},
2195 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2196 (char_u *)&p_ttm, PV_NONE,
2197 {(char_u *)-1L, (char_u *)0L}},
2198 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2199 (char_u *)&p_tbi, PV_NONE,
2200 {(char_u *)TRUE, (char_u *)0L}},
2201 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2202 (char_u *)&p_tf, PV_NONE,
2203 {(char_u *)FALSE, (char_u *)0L}},
2204 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2205#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2206 (char_u *)&p_ttym, PV_NONE,
2207#else
2208 (char_u *)NULL, PV_NONE,
2209#endif
2210 {(char_u *)"", (char_u *)0L}},
2211 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2212 (char_u *)&p_ttyscroll, PV_NONE,
2213 {(char_u *)999L, (char_u *)0L}},
2214 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2215 (char_u *)&T_NAME, PV_NONE,
2216 {(char_u *)"", (char_u *)0L}},
2217 {"undolevels", "ul", P_NUM|P_VI_DEF,
2218 (char_u *)&p_ul, PV_NONE,
2219 {
2220#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2221 (char_u *)1000L,
2222#else
2223 (char_u *)100L,
2224#endif
2225 (char_u *)0L}},
2226 {"updatecount", "uc", P_NUM|P_VI_DEF,
2227 (char_u *)&p_uc, PV_NONE,
2228 {(char_u *)200L, (char_u *)0L}},
2229 {"updatetime", "ut", P_NUM|P_VI_DEF,
2230 (char_u *)&p_ut, PV_NONE,
2231 {(char_u *)4000L, (char_u *)0L}},
2232 {"verbose", "vbs", P_NUM|P_VI_DEF,
2233 (char_u *)&p_verbose, PV_NONE,
2234 {(char_u *)0L, (char_u *)0L}},
2235 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2236#ifdef FEAT_SESSION
2237 (char_u *)&p_vdir, PV_NONE,
2238 {(char_u *)DFLT_VDIR, (char_u *)0L}
2239#else
2240 (char_u *)NULL, PV_NONE,
2241 {(char_u *)0L, (char_u *)0L}
2242#endif
2243 },
2244 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2245#ifdef FEAT_SESSION
2246 (char_u *)&p_vop, PV_NONE,
2247 {(char_u *)"folds,options,cursor", (char_u *)0L}
2248#else
2249 (char_u *)NULL, PV_NONE,
2250 {(char_u *)0L, (char_u *)0L}
2251#endif
2252 },
2253 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2254#ifdef FEAT_VIMINFO
2255 (char_u *)&p_viminfo, PV_NONE,
2256#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2257 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2258#else
2259# ifdef AMIGA
2260 {(char_u *)"",
2261 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2262# else
2263 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2264# endif
2265#endif
2266#else
2267 (char_u *)NULL, PV_NONE,
2268 {(char_u *)0L, (char_u *)0L}
2269#endif
2270 },
2271 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2272#ifdef FEAT_VIRTUALEDIT
2273 (char_u *)&p_ve, PV_NONE,
2274 {(char_u *)"", (char_u *)""}
2275#else
2276 (char_u *)NULL, PV_NONE,
2277 {(char_u *)0L, (char_u *)0L}
2278#endif
2279 },
2280 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2281 (char_u *)&p_vb, PV_NONE,
2282 {(char_u *)FALSE, (char_u *)0L}},
2283 {"w300", NULL, P_NUM|P_VI_DEF,
2284 (char_u *)NULL, PV_NONE,
2285 {(char_u *)0L, (char_u *)0L}},
2286 {"w1200", NULL, P_NUM|P_VI_DEF,
2287 (char_u *)NULL, PV_NONE,
2288 {(char_u *)0L, (char_u *)0L}},
2289 {"w9600", NULL, P_NUM|P_VI_DEF,
2290 (char_u *)NULL, PV_NONE,
2291 {(char_u *)0L, (char_u *)0L}},
2292 {"warn", NULL, P_BOOL|P_VI_DEF,
2293 (char_u *)&p_warn, PV_NONE,
2294 {(char_u *)TRUE, (char_u *)0L}},
2295 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2296 (char_u *)&p_wiv, PV_NONE,
2297 {(char_u *)FALSE, (char_u *)0L}},
2298 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2299 (char_u *)&p_ww, PV_NONE,
2300 {(char_u *)"", (char_u *)"b,s"}},
2301 {"wildchar", "wc", P_NUM|P_VIM,
2302 (char_u *)&p_wc, PV_NONE,
2303 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2304 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2305 (char_u *)&p_wcm, PV_NONE,
2306 {(char_u *)0L, (char_u *)0L}},
2307 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2308#ifdef FEAT_WILDIGN
2309 (char_u *)&p_wig, PV_NONE,
2310#else
2311 (char_u *)NULL, PV_NONE,
2312#endif
2313 {(char_u *)"", (char_u *)0L}},
2314 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2315#ifdef FEAT_WILDMENU
2316 (char_u *)&p_wmnu, PV_NONE,
2317#else
2318 (char_u *)NULL, PV_NONE,
2319#endif
2320 {(char_u *)FALSE, (char_u *)0L}},
2321 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2322 (char_u *)&p_wim, PV_NONE,
2323 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002324 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2325#ifdef FEAT_CMDL_COMPL
2326 (char_u *)&p_wop, PV_NONE,
2327 {(char_u *)"", (char_u *)0L}
2328#else
2329 (char_u *)NULL, PV_NONE,
2330 {(char_u *)NULL, (char_u *)0L}
2331#endif
2332 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2334#ifdef FEAT_WAK
2335 (char_u *)&p_wak, PV_NONE,
2336 {(char_u *)"menu", (char_u *)0L}
2337#else
2338 (char_u *)NULL, PV_NONE,
2339 {(char_u *)NULL, (char_u *)0L}
2340#endif
2341 },
2342 {"window", "wi", P_NUM|P_VI_DEF,
2343 (char_u *)NULL, PV_NONE,
2344 {(char_u *)0L, (char_u *)0L}},
2345 {"winheight", "wh", P_NUM|P_VI_DEF,
2346#ifdef FEAT_WINDOWS
2347 (char_u *)&p_wh, PV_NONE,
2348#else
2349 (char_u *)NULL, PV_NONE,
2350#endif
2351 {(char_u *)1L, (char_u *)0L}},
2352 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
2353#if defined(FEAT_WINDOWS)
2354 (char_u *)VAR_WIN, PV_WFH,
2355#else
2356 (char_u *)NULL, PV_NONE,
2357#endif
2358 {(char_u *)FALSE, (char_u *)0L}},
2359 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2360#ifdef FEAT_WINDOWS
2361 (char_u *)&p_wmh, PV_NONE,
2362#else
2363 (char_u *)NULL, PV_NONE,
2364#endif
2365 {(char_u *)1L, (char_u *)0L}},
2366 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2367#ifdef FEAT_VERTSPLIT
2368 (char_u *)&p_wmw, PV_NONE,
2369#else
2370 (char_u *)NULL, PV_NONE,
2371#endif
2372 {(char_u *)1L, (char_u *)0L}},
2373 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2374#ifdef FEAT_VERTSPLIT
2375 (char_u *)&p_wiw, PV_NONE,
2376#else
2377 (char_u *)NULL, PV_NONE,
2378#endif
2379 {(char_u *)20L, (char_u *)0L}},
2380 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2381 (char_u *)VAR_WIN, PV_WRAP,
2382 {(char_u *)TRUE, (char_u *)0L}},
2383 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2384 (char_u *)&p_wm, PV_WM,
2385 {(char_u *)0L, (char_u *)0L}},
2386 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2387 (char_u *)&p_ws, PV_NONE,
2388 {(char_u *)TRUE, (char_u *)0L}},
2389 {"write", NULL, P_BOOL|P_VI_DEF,
2390 (char_u *)&p_write, PV_NONE,
2391 {(char_u *)TRUE, (char_u *)0L}},
2392 {"writeany", "wa", P_BOOL|P_VI_DEF,
2393 (char_u *)&p_wa, PV_NONE,
2394 {(char_u *)FALSE, (char_u *)0L}},
2395 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2396 (char_u *)&p_wb, PV_NONE,
2397 {
2398#ifdef FEAT_WRITEBACKUP
2399 (char_u *)TRUE,
2400#else
2401 (char_u *)FALSE,
2402#endif
2403 (char_u *)0L}},
2404 {"writedelay", "wd", P_NUM|P_VI_DEF,
2405 (char_u *)&p_wd, PV_NONE,
2406 {(char_u *)0L, (char_u *)0L}},
2407
2408/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002409#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 (char_u *)&vvv, PV_NONE, \
2411 {(char_u *)"", (char_u *)0L}},
2412
2413 p_term("t_AB", T_CAB)
2414 p_term("t_AF", T_CAF)
2415 p_term("t_AL", T_CAL)
2416 p_term("t_al", T_AL)
2417 p_term("t_bc", T_BC)
2418 p_term("t_cd", T_CD)
2419 p_term("t_ce", T_CE)
2420 p_term("t_cl", T_CL)
2421 p_term("t_cm", T_CM)
2422 p_term("t_Co", T_CCO)
2423 p_term("t_CS", T_CCS)
2424 p_term("t_cs", T_CS)
2425#ifdef FEAT_VERTSPLIT
2426 p_term("t_CV", T_CSV)
2427#endif
2428 p_term("t_ut", T_UT)
2429 p_term("t_da", T_DA)
2430 p_term("t_db", T_DB)
2431 p_term("t_DL", T_CDL)
2432 p_term("t_dl", T_DL)
2433 p_term("t_fs", T_FS)
2434 p_term("t_IE", T_CIE)
2435 p_term("t_IS", T_CIS)
2436 p_term("t_ke", T_KE)
2437 p_term("t_ks", T_KS)
2438 p_term("t_le", T_LE)
2439 p_term("t_mb", T_MB)
2440 p_term("t_md", T_MD)
2441 p_term("t_me", T_ME)
2442 p_term("t_mr", T_MR)
2443 p_term("t_ms", T_MS)
2444 p_term("t_nd", T_ND)
2445 p_term("t_op", T_OP)
2446 p_term("t_RI", T_CRI)
2447 p_term("t_RV", T_CRV)
2448 p_term("t_Sb", T_CSB)
2449 p_term("t_Sf", T_CSF)
2450 p_term("t_se", T_SE)
2451 p_term("t_so", T_SO)
2452 p_term("t_sr", T_SR)
2453 p_term("t_ts", T_TS)
2454 p_term("t_te", T_TE)
2455 p_term("t_ti", T_TI)
2456 p_term("t_ue", T_UE)
2457 p_term("t_us", T_US)
2458 p_term("t_vb", T_VB)
2459 p_term("t_ve", T_VE)
2460 p_term("t_vi", T_VI)
2461 p_term("t_vs", T_VS)
2462 p_term("t_WP", T_CWP)
2463 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002464 p_term("t_SI", T_CSI)
2465 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 p_term("t_xs", T_XS)
2467 p_term("t_ZH", T_CZH)
2468 p_term("t_ZR", T_CZR)
2469
2470/* terminal key codes are not in here */
2471
2472 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2473};
2474
2475#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2476
2477#ifdef FEAT_MBYTE
2478static char *(p_ambw_values[]) = {"single", "double", NULL};
2479#endif
2480static char *(p_bg_values[]) = {"light", "dark", NULL};
2481static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2482static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002483#ifdef FEAT_CMDL_COMPL
2484static char *(p_wop_values[]) = {"tagfile", NULL};
2485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486#ifdef FEAT_WAK
2487static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2488#endif
2489static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2490#ifdef FEAT_VISUAL
2491static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2492static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2493#endif
2494#ifdef FEAT_VISUAL
2495static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2496#endif
2497#ifdef FEAT_BROWSE
2498static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2499#endif
2500#ifdef FEAT_SCROLLBIND
2501static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2502#endif
2503static char *(p_swb_values[]) = {"useopen", "split", NULL};
2504static char *(p_debug_values[]) = {"msg", NULL};
2505#ifdef FEAT_VERTSPLIT
2506static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2507#endif
2508#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002509# ifdef FEAT_AUTOCMD
2510static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2511# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002513# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2515#endif
2516static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2517#ifdef FEAT_FOLDING
2518static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
2519#ifdef FEAT_DIFF
2520 "diff",
2521#endif
2522 NULL};
2523static char *(p_fcl_values[]) = {"all", NULL};
2524#endif
2525
2526static void set_option_default __ARGS((int, int opt_flags, int compatible));
2527static void set_options_default __ARGS((int opt_flags));
2528static char_u *illegal_char __ARGS((char_u *, int));
2529static int string_to_key __ARGS((char_u *arg));
2530#ifdef FEAT_CMDWIN
2531static char_u *check_cedit __ARGS((void));
2532#endif
2533#ifdef FEAT_TITLE
2534static void did_set_title __ARGS((int icon));
2535#endif
2536static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2537static void didset_options __ARGS((void));
2538static void check_string_option __ARGS((char_u **pp));
2539static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2540static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2541static 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));
2542static char_u *set_chars_option __ARGS((char_u **varp));
2543#ifdef FEAT_CLIPBOARD
2544static char_u *check_clipboard_option __ARGS((void));
2545#endif
2546static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
2547static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, int opt_flags));
2548static void check_redraw __ARGS((long_u flags));
2549static int findoption __ARGS((char_u *));
2550static int find_key_option __ARGS((char_u *));
2551static void showoptions __ARGS((int all, int opt_flags));
2552static int optval_default __ARGS((struct vimoption *, char_u *varp));
2553static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2554static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2555static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2556static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2557static int istermoption __ARGS((struct vimoption *));
2558static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2559static char_u *get_varp __ARGS((struct vimoption *));
2560static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2561static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2562#ifdef FEAT_LANGMAP
2563static void langmap_init __ARGS((void));
2564static void langmap_set __ARGS((void));
2565#endif
2566static void paste_option_changed __ARGS((void));
2567static void compatible_set __ARGS((void));
2568#ifdef FEAT_LINEBREAK
2569static void fill_breakat_flags __ARGS((void));
2570#endif
2571static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2572static int check_opt_strings __ARGS((char_u *val, char **values, int));
2573static int check_opt_wim __ARGS((void));
2574
2575/*
2576 * Initialize the options, first part.
2577 *
2578 * Called only once from main(), just after creating the first buffer.
2579 */
2580 void
2581set_init_1()
2582{
2583 char_u *p;
2584 int opt_idx;
2585 long n;
2586
2587#ifdef FEAT_LANGMAP
2588 langmap_init();
2589#endif
2590
2591 /* Be Vi compatible by default */
2592 p_cp = TRUE;
2593
2594 /*
2595 * Find default value for 'shell' option.
2596 */
2597 if ((p = mch_getenv((char_u *)"SHELL")) != NULL
2598#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2599# ifdef __EMX__
2600 || (p = mch_getenv((char_u *)"EMXSHELL")) != NULL
2601# endif
2602 || (p = mch_getenv((char_u *)"COMSPEC")) != NULL
2603# ifdef WIN3264
2604 || (p = default_shell()) != NULL
2605# endif
2606#endif
2607 )
2608 set_string_default("sh", p);
2609
2610#ifdef FEAT_WILDIGN
2611 /*
2612 * Set the default for 'backupskip' to include environment variables for
2613 * temp files.
2614 */
2615 {
2616# ifdef UNIX
2617 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2618# else
2619 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2620# endif
2621 int len;
2622 garray_T ga;
2623
2624 ga_init2(&ga, 1, 100);
2625 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2626 {
2627# ifdef UNIX
2628 if (*names[n] == NUL)
2629 p = (char_u *)"/tmp";
2630 else
2631# endif
2632 p = mch_getenv((char_u *)names[n]);
2633 if (p != NULL && *p != NUL)
2634 {
2635 /* First time count the NUL, otherwise count the ','. */
2636 len = STRLEN(p) + 3;
2637 if (ga_grow(&ga, len) == OK)
2638 {
2639 if (ga.ga_len > 0)
2640 STRCAT(ga.ga_data, ",");
2641 STRCAT(ga.ga_data, p);
2642 add_pathsep(ga.ga_data);
2643 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 ga.ga_len += len;
2645 }
2646 }
2647 }
2648 if (ga.ga_data != NULL)
2649 {
2650 set_string_default("bsk", ga.ga_data);
2651 vim_free(ga.ga_data);
2652 }
2653 }
2654#endif
2655
2656 /*
2657 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2658 */
2659 opt_idx = findoption((char_u *)"maxmemtot");
2660#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2661 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2662#endif
2663 {
2664#ifdef HAVE_AVAIL_MEM
2665 /* Use amount of memory available at this moment. */
2666 n = (mch_avail_mem(FALSE) >> 11);
2667#else
2668# ifdef HAVE_TOTAL_MEM
2669 /* Use amount of memory available to Vim. */
2670 n = (mch_total_mem(FALSE) >> 11);
2671# else
2672 n = (0x7fffffff >> 11);
2673# endif
2674#endif
2675 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2676 opt_idx = findoption((char_u *)"maxmem");
2677#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2678 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2679 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2680#endif
2681 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2682 }
2683
2684#ifdef FEAT_GUI_W32
2685 /* force 'shortname' for Win32s */
2686 if (gui_is_win32s())
2687 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2688 (char_u *)TRUE;
2689#endif
2690
2691#ifdef FEAT_SEARCHPATH
2692 {
2693 char_u *cdpath;
2694 char_u *buf;
2695 int i;
2696 int j;
2697
2698 /* Initialize the 'cdpath' option's default value. */
2699 cdpath = mch_getenv((char_u *)"CDPATH");
2700 if (cdpath != NULL)
2701 {
2702 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2703 if (buf != NULL)
2704 {
2705 buf[0] = ','; /* start with ",", current dir first */
2706 j = 1;
2707 for (i = 0; cdpath[i] != NUL; ++i)
2708 {
2709 if (vim_ispathlistsep(cdpath[i]))
2710 buf[j++] = ',';
2711 else
2712 {
2713 if (cdpath[i] == ' ' || cdpath[i] == ',')
2714 buf[j++] = '\\';
2715 buf[j++] = cdpath[i];
2716 }
2717 }
2718 buf[j] = NUL;
2719 opt_idx = findoption((char_u *)"cdpath");
2720 options[opt_idx].def_val[VI_DEFAULT] = buf;
2721 options[opt_idx].flags |= P_DEF_ALLOCED;
2722 }
2723 }
2724 }
2725#endif
2726
2727#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2728 /* Set print encoding on platforms that don't default to latin1 */
2729 set_string_default("penc",
2730# if defined(MSWIN) || defined(OS2)
2731 (char_u *)"cp1252"
2732# else
2733# ifdef VMS
2734 (char_u *)"dec-mcs"
2735# else
2736# ifdef EBCDIC
2737 (char_u *)"ebcdic-uk"
2738# else
2739# ifdef MAC
2740 (char_u *)"mac-roman"
2741# else /* HPUX */
2742 (char_u *)"hp-roman8"
2743# endif
2744# endif
2745# endif
2746# endif
2747 );
2748#endif
2749
2750#ifdef FEAT_POSTSCRIPT
2751 /* 'printexpr' must be allocated to be able to evaluate it. */
2752 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00002753# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
2754 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755# else
2756# ifdef VMS
2757 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
2758
2759# else
2760 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
2761# endif
2762# endif
2763 );
2764#endif
2765
2766 /*
2767 * Set all the options (except the terminal options) to their default
2768 * value. Also set the global value for local options.
2769 */
2770 set_options_default(0);
2771
2772#ifdef FEAT_GUI
2773 if (found_reverse_arg)
2774 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
2775#endif
2776
2777 curbuf->b_p_initialized = TRUE;
2778 curbuf->b_p_ar = -1; /* no local 'autoread' value */
2779 check_buf_options(curbuf);
2780 check_win_options(curwin);
2781 check_options();
2782
2783 /* Must be before option_expand(), because that one needs vim_isIDc() */
2784 didset_options();
2785
2786#ifdef FEAT_LINEBREAK
2787 /*
2788 * initialize the table for 'breakat'.
2789 */
2790 fill_breakat_flags();
2791#endif
2792
2793 /*
2794 * Expand environment variables and things like "~" for the defaults.
2795 * If option_expand() returns non-NULL the variable is expanded. This can
2796 * only happen for non-indirect options.
2797 * Also set the default to the expanded value, so ":set" does not list
2798 * them.
2799 * Don't set the P_ALLOCED flag, because we don't want to free the
2800 * default.
2801 */
2802 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
2803 {
2804 if ((options[opt_idx].flags & P_GETTEXT)
2805 && options[opt_idx].var != NULL)
2806 p = (char_u *)_(*(char **)options[opt_idx].var);
2807 else
2808 p = option_expand(opt_idx, NULL);
2809 if (p != NULL && (p = vim_strsave(p)) != NULL)
2810 {
2811 *(char_u **)options[opt_idx].var = p;
2812 /* VIMEXP
2813 * Defaults for all expanded options are currently the same for Vi
2814 * and Vim. When this changes, add some code here! Also need to
2815 * split P_DEF_ALLOCED in two.
2816 */
2817 if (options[opt_idx].flags & P_DEF_ALLOCED)
2818 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2819 options[opt_idx].def_val[VI_DEFAULT] = p;
2820 options[opt_idx].flags |= P_DEF_ALLOCED;
2821 }
2822 }
2823
2824 /* Initialize the highlight_attr[] table. */
2825 highlight_changed();
2826
2827 save_file_ff(curbuf); /* Buffer is unchanged */
2828
2829 /* Parse default for 'wildmode' */
2830 check_opt_wim();
2831
2832#if defined(FEAT_ARABIC)
2833 /* Detect use of mlterm.
2834 * Mlterm is a terminal emulator akin to xterm that has some special
2835 * abilities (bidi namely).
2836 * NOTE: mlterm's author is being asked to 'set' a variable
2837 * instead of an environment variable due to inheritance.
2838 */
2839 if (mch_getenv((char_u *)"MLTERM") != NULL)
2840 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
2841#endif
2842
2843#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
2844 /* Parse default for 'fillchars'. */
2845 (void)set_chars_option(&p_fcs);
2846#endif
2847
2848#ifdef FEAT_CLIPBOARD
2849 /* Parse default for 'clipboard' */
2850 (void)check_clipboard_option();
2851#endif
2852
2853#ifdef FEAT_MBYTE
2854# if defined(WIN3264) && defined(FEAT_GETTEXT)
2855 /*
2856 * If $LANG isn't set, try to get a good value for it. This makes the
2857 * right language be used automatically. Don't do this for English.
2858 */
2859 if (mch_getenv((char_u *)"LANG") == NULL)
2860 {
2861 char buf[20];
2862
2863 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
2864 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
2865 * only the first two. */
2866 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
2867 (LPTSTR)buf, 20);
2868 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
2869 {
2870 /* There are a few exceptions (probably more) */
2871 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
2872 STRCPY(buf, "zh_TW");
2873 else if (STRNICMP(buf, "chs", 3) == 0
2874 || STRNICMP(buf, "zhc", 3) == 0)
2875 STRCPY(buf, "zh_CN");
2876 else if (STRNICMP(buf, "jp", 2) == 0)
2877 STRCPY(buf, "ja");
2878 else
2879 buf[2] = NUL; /* truncate to two-letter code */
2880 vim_setenv("LANG", buf);
2881 }
2882 }
2883# endif
2884
2885 /* enc_locale() will try to find the encoding of the current locale. */
2886 p = enc_locale();
2887 if (p != NULL)
2888 {
2889 char_u *save_enc;
2890
2891 /* Try setting 'encoding' and check if the value is valid.
2892 * If not, go back to the default "latin1". */
2893 save_enc = p_enc;
2894 p_enc = p;
2895 if (mb_init() == NULL)
2896 {
2897 opt_idx = findoption((char_u *)"encoding");
2898 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
2899 options[opt_idx].flags |= P_DEF_ALLOCED;
2900
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002901#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
2902 || defined(VMS)
2903 if (STRCMP(p_enc, "latin1") == 0
2904# ifdef FEAT_MBYTE
2905 || enc_utf8
2906# endif
2907 )
2908 {
2909 /* Adjust the default for 'isprint' to match latin1. */
2910 set_string_option_direct((char_u *)"isp", -1,
2911 (char_u *)"@,161-255", OPT_FREE);
2912 (void)init_chartab();
2913 }
2914#endif
2915
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916# if defined(WIN3264) && !defined(FEAT_GUI)
2917 /* Win32 console: When GetACP() returns a different value from
2918 * GetConsoleCP() set 'termencoding'. */
2919 if (GetACP() != GetConsoleCP())
2920 {
2921 char buf[50];
2922
2923 sprintf(buf, "cp%ld", (long)GetConsoleCP());
2924 p_tenc = vim_strsave((char_u *)buf);
2925 if (p_tenc != NULL)
2926 {
2927 opt_idx = findoption((char_u *)"termencoding");
2928 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
2929 options[opt_idx].flags |= P_DEF_ALLOCED;
2930 convert_setup(&input_conv, p_tenc, p_enc);
2931 convert_setup(&output_conv, p_enc, p_tenc);
2932 }
2933 else
2934 p_tenc = empty_option;
2935 }
2936# endif
2937 }
2938 else
2939 {
2940 vim_free(p_enc);
2941 p_enc = save_enc;
2942 }
2943 }
2944#endif
2945
2946#ifdef FEAT_MULTI_LANG
2947 /* Set the default for 'helplang'. */
2948 set_helplang_default(get_mess_lang());
2949#endif
2950}
2951
2952/*
2953 * Set an option to its default value.
2954 * This does not take care of side effects!
2955 */
2956 static void
2957set_option_default(opt_idx, opt_flags, compatible)
2958 int opt_idx;
2959 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
2960 int compatible; /* use Vi default value */
2961{
2962 char_u *varp; /* pointer to variable for current option */
2963 int dvi; /* index in def_val[] */
2964 long_u flags;
2965 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
2966
2967 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
2968 flags = options[opt_idx].flags;
2969 if (varp != NULL) /* nothing to do for hidden option */
2970 {
2971 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
2972 if (flags & P_STRING)
2973 {
2974 /* Use set_string_option_direct() for local options to handle
2975 * freeing and allocating the value. */
2976 if (options[opt_idx].indir != PV_NONE)
2977 set_string_option_direct(NULL, opt_idx,
2978 options[opt_idx].def_val[dvi], opt_flags);
2979 else
2980 {
2981 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
2982 free_string_option(*(char_u **)(varp));
2983 *(char_u **)varp = options[opt_idx].def_val[dvi];
2984 options[opt_idx].flags &= ~P_ALLOCED;
2985 }
2986 }
2987 else if (flags & P_NUM)
2988 {
2989 if (varp == (char_u *)PV_SCROLL)
2990 win_comp_scroll(curwin);
2991 else
2992 {
2993 *(long *)varp = (long)options[opt_idx].def_val[dvi];
2994 /* May also set global value for local option. */
2995 if (both)
2996 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
2997 *(long *)varp;
2998 }
2999 }
3000 else /* P_BOOL */
3001 {
3002 /* the cast to long is required for Manx C */
3003 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3004 /* May also set global value for local option. */
3005 if (both)
3006 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3007 *(int *)varp;
3008 }
3009 }
3010
3011#ifdef FEAT_EVAL
3012 /* Remember where the option was set. */
3013 options[opt_idx].scriptID = current_SID;
3014#endif
3015}
3016
3017/*
3018 * Set all options (except terminal options) to their default value.
3019 */
3020 static void
3021set_options_default(opt_flags)
3022 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3023{
3024 int i;
3025#ifdef FEAT_WINDOWS
3026 win_T *wp;
3027#endif
3028
3029 for (i = 0; !istermoption(&options[i]); i++)
3030 if (!(options[i].flags & P_NODEFAULT))
3031 set_option_default(i, opt_flags, p_cp);
3032
3033#ifdef FEAT_WINDOWS
3034 /* The 'scroll' option must be computed for all windows. */
3035 for (wp = firstwin; wp != NULL; wp = wp->w_next)
3036 win_comp_scroll(wp);
3037#else
3038 win_comp_scroll(curwin);
3039#endif
3040}
3041
3042/*
3043 * Set the Vi-default value of a string option.
3044 * Used for 'sh', 'backupskip' and 'term'.
3045 */
3046 void
3047set_string_default(name, val)
3048 char *name;
3049 char_u *val;
3050{
3051 char_u *p;
3052 int opt_idx;
3053
3054 p = vim_strsave(val);
3055 if (p != NULL) /* we don't want a NULL */
3056 {
3057 opt_idx = findoption((char_u *)name);
3058 if (options[opt_idx].flags & P_DEF_ALLOCED)
3059 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3060 options[opt_idx].def_val[VI_DEFAULT] = p;
3061 options[opt_idx].flags |= P_DEF_ALLOCED;
3062 }
3063}
3064
3065/*
3066 * Set the Vi-default value of a number option.
3067 * Used for 'lines' and 'columns'.
3068 */
3069 void
3070set_number_default(name, val)
3071 char *name;
3072 long val;
3073{
3074 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3075}
3076
3077/*
3078 * Initialize the options, part two: After getting Rows and Columns and
3079 * setting 'term'.
3080 */
3081 void
3082set_init_2()
3083{
3084 /*
3085 * 'scroll' defaults to half the window height. Note that this default is
3086 * wrong when the window height changes.
3087 */
3088 options[findoption((char_u *)"scroll")].def_val[VI_DEFAULT]
3089 = (char_u *)((long_u)Rows >> 1);
3090 comp_col();
3091
3092#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3093 {
3094 int idx4;
3095
3096 /*
3097 * If 'background' wasn't set by the user, try guessing the value,
3098 * depending on the terminal name. Only need to check for terminals
3099 * with a dark background, that can handle color. Only "linux"
3100 * console at the moment.
3101 */
3102 idx4 = findoption((char_u *)"bg");
3103 if (!(options[idx4].flags & P_WAS_SET) && STRCMP(T_NAME, "linux") == 0)
3104 {
3105 set_string_option_direct(NULL, idx4, (char_u *)"dark", OPT_FREE);
3106 /* don't mark it as set, when starting the GUI it may be changed
3107 * again */
3108 options[idx4].flags &= ~P_WAS_SET;
3109 }
3110 }
3111#endif
3112}
3113
3114/*
3115 * Initialize the options, part three: After reading the .vimrc
3116 */
3117 void
3118set_init_3()
3119{
3120#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3121/*
3122 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3123 * This is done after other initializations, where 'shell' might have been
3124 * set, but only if they have not been set before.
3125 */
3126 char_u *p;
3127 int idx_srr;
3128 int do_srr;
3129#ifdef FEAT_QUICKFIX
3130 int idx_sp;
3131 int do_sp;
3132#endif
3133
3134 idx_srr = findoption((char_u *)"srr");
3135 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3136#ifdef FEAT_QUICKFIX
3137 idx_sp = findoption((char_u *)"sp");
3138 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3139#endif
3140
3141 /*
3142 * Isolate the name of the shell:
3143 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3144 * - Remove any argument. E.g., "csh -f" -> "csh".
3145 */
3146 p = gettail(p_sh);
3147 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3148 if (p != NULL)
3149 {
3150 /*
3151 * Default for p_sp is "| tee", for p_srr is ">".
3152 * For known shells it is changed here to include stderr.
3153 */
3154 if ( fnamecmp(p, "csh") == 0
3155 || fnamecmp(p, "tcsh") == 0
3156# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3157 || fnamecmp(p, "csh.exe") == 0
3158 || fnamecmp(p, "tcsh.exe") == 0
3159# endif
3160 )
3161 {
3162#if defined(FEAT_QUICKFIX)
3163 if (do_sp)
3164 {
3165# ifdef WIN3264
3166 p_sp = (char_u *)">&";
3167# else
3168 p_sp = (char_u *)"|& tee";
3169# endif
3170 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3171 }
3172#endif
3173 if (do_srr)
3174 {
3175 p_srr = (char_u *)">&";
3176 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3177 }
3178 }
3179 else
3180# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3181 if ( fnamecmp(p, "sh") == 0
3182 || fnamecmp(p, "ksh") == 0
3183 || fnamecmp(p, "zsh") == 0
3184 || fnamecmp(p, "bash") == 0
3185# ifdef WIN3264
3186 || fnamecmp(p, "cmd") == 0
3187 || fnamecmp(p, "sh.exe") == 0
3188 || fnamecmp(p, "ksh.exe") == 0
3189 || fnamecmp(p, "zsh.exe") == 0
3190 || fnamecmp(p, "bash.exe") == 0
3191 || fnamecmp(p, "cmd.exe") == 0
3192# endif
3193 )
3194# endif
3195 {
3196#if defined(FEAT_QUICKFIX)
3197 if (do_sp)
3198 {
3199# ifdef WIN3264
3200 p_sp = (char_u *)">%s 2>&1";
3201# else
3202 p_sp = (char_u *)"2>&1| tee";
3203# endif
3204 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3205 }
3206#endif
3207 if (do_srr)
3208 {
3209 p_srr = (char_u *)">%s 2>&1";
3210 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3211 }
3212 }
3213 vim_free(p);
3214 }
3215#endif
3216
3217#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3218 /*
3219 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3220 * This is done after other initializations, where 'shell' might have been
3221 * set, but only if they have not been set before. Default for p_shcf is
3222 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3223 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3224 * command.com. And for Win32 we need to set p_sxq instead.
3225 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 {
3228 int idx3;
3229
3230 idx3 = findoption((char_u *)"shcf");
3231 if (!(options[idx3].flags & P_WAS_SET))
3232 {
3233 p_shcf = (char_u *)"-c";
3234 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3235 }
3236
3237# ifndef DJGPP
3238# ifdef WIN3264
3239 /* Somehow Win32 requires the quotes around the redirection too */
3240 idx3 = findoption((char_u *)"sxq");
3241 if (!(options[idx3].flags & P_WAS_SET))
3242 {
3243 p_sxq = (char_u *)"\"";
3244 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3245 }
3246# else
3247 idx3 = findoption((char_u *)"shq");
3248 if (!(options[idx3].flags & P_WAS_SET))
3249 {
3250 p_shq = (char_u *)"\"";
3251 options[idx3].def_val[VI_DEFAULT] = p_shq;
3252 }
3253# endif
3254# endif
3255 }
3256#endif
3257
3258#ifdef FEAT_TITLE
3259 set_title_defaults();
3260#endif
3261}
3262
3263#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3264/*
3265 * When 'helplang' is still at its default value, set it to "lang".
3266 * Only the first two characters of "lang" are used.
3267 */
3268 void
3269set_helplang_default(lang)
3270 char_u *lang;
3271{
3272 int idx;
3273
3274 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3275 return;
3276 idx = findoption((char_u *)"hlg");
3277 if (!(options[idx].flags & P_WAS_SET))
3278 {
3279 if (options[idx].flags & P_ALLOCED)
3280 free_string_option(p_hlg);
3281 p_hlg = vim_strsave(lang);
3282 if (p_hlg == NULL)
3283 p_hlg = empty_option;
3284 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003285 {
3286 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3287 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3288 {
3289 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3290 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3291 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003293 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294 options[idx].flags |= P_ALLOCED;
3295 }
3296}
3297#endif
3298
3299#ifdef FEAT_GUI
3300static char_u *gui_bg_default __ARGS((void));
3301
3302 static char_u *
3303gui_bg_default()
3304{
3305 if (gui_get_lightness(gui.back_pixel) < 127)
3306 return (char_u *)"dark";
3307 return (char_u *)"light";
3308}
3309
3310/*
3311 * Option initializations that can only be done after opening the GUI window.
3312 */
3313 void
3314init_gui_options()
3315{
3316 /* Set the 'background' option according to the lightness of the
3317 * background color, unless the user has set it already. */
3318 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3319 {
3320 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3321 highlight_changed();
3322 }
3323}
3324#endif
3325
3326#ifdef FEAT_TITLE
3327/*
3328 * 'title' and 'icon' only default to true if they have not been set or reset
3329 * in .vimrc and we can read the old value.
3330 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3331 * they can be reset. This reduces startup time when using X on a remote
3332 * machine.
3333 */
3334 void
3335set_title_defaults()
3336{
3337 int idx1;
3338 long val;
3339
3340 /*
3341 * If GUI is (going to be) used, we can always set the window title and
3342 * icon name. Saves a bit of time, because the X11 display server does
3343 * not need to be contacted.
3344 */
3345 idx1 = findoption((char_u *)"title");
3346 if (!(options[idx1].flags & P_WAS_SET))
3347 {
3348#ifdef FEAT_GUI
3349 if (gui.starting || gui.in_use)
3350 val = TRUE;
3351 else
3352#endif
3353 val = mch_can_restore_title();
3354 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3355 p_title = val;
3356 }
3357 idx1 = findoption((char_u *)"icon");
3358 if (!(options[idx1].flags & P_WAS_SET))
3359 {
3360#ifdef FEAT_GUI
3361 if (gui.starting || gui.in_use)
3362 val = TRUE;
3363 else
3364#endif
3365 val = mch_can_restore_icon();
3366 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3367 p_icon = val;
3368 }
3369}
3370#endif
3371
3372/*
3373 * Parse 'arg' for option settings.
3374 *
3375 * 'arg' may be IObuff, but only when no errors can be present and option
3376 * does not need to be expanded with option_expand().
3377 * "opt_flags":
3378 * 0 for ":set"
3379 * OPT_GLOBAL for ":setglobal"
3380 * OPT_LOCAL for ":setlocal" and a modeline
3381 * OPT_MODELINE for a modeline
3382 *
3383 * returns FAIL if an error is detected, OK otherwise
3384 */
3385 int
3386do_set(arg, opt_flags)
3387 char_u *arg; /* option string (may be written to!) */
3388 int opt_flags;
3389{
3390 int opt_idx;
3391 char_u *errmsg;
3392 char_u errbuf[80];
3393 char_u *startarg;
3394 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3395 int nextchar; /* next non-white char after option name */
3396 int afterchar; /* character just after option name */
3397 int len;
3398 int i;
3399 long value;
3400 int key;
3401 long_u flags; /* flags for current option */
3402 char_u *varp = NULL; /* pointer to variable for current option */
3403 int did_show = FALSE; /* already showed one value */
3404 int adding; /* "opt+=arg" */
3405 int prepending; /* "opt^=arg" */
3406 int removing; /* "opt-=arg" */
3407 int cp_val = 0;
3408 char_u key_name[2];
3409
3410 if (*arg == NUL)
3411 {
3412 showoptions(0, opt_flags);
3413 return OK;
3414 }
3415
3416 while (*arg != NUL) /* loop to process all options */
3417 {
3418 errmsg = NULL;
3419 startarg = arg; /* remember for error message */
3420
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003421 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3422 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423 {
3424 /*
3425 * ":set all" show all options.
3426 * ":set all&" set all options to their default value.
3427 */
3428 arg += 3;
3429 if (*arg == '&')
3430 {
3431 ++arg;
3432 /* Only for :set command set global value of local options. */
3433 set_options_default(OPT_FREE | opt_flags);
3434 }
3435 else
3436 showoptions(1, opt_flags);
3437 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003438 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439 {
3440 showoptions(2, opt_flags);
3441 show_termcodes();
3442 arg += 7;
3443 }
3444 else
3445 {
3446 prefix = 1;
3447 if (STRNCMP(arg, "no", 2) == 0)
3448 {
3449 prefix = 0;
3450 arg += 2;
3451 }
3452 else if (STRNCMP(arg, "inv", 3) == 0)
3453 {
3454 prefix = 2;
3455 arg += 3;
3456 }
3457
3458 /* find end of name */
3459 key = 0;
3460 if (*arg == '<')
3461 {
3462 nextchar = 0;
3463 opt_idx = -1;
3464 /* look out for <t_>;> */
3465 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3466 len = 5;
3467 else
3468 {
3469 len = 1;
3470 while (arg[len] != NUL && arg[len] != '>')
3471 ++len;
3472 }
3473 if (arg[len] != '>')
3474 {
3475 errmsg = e_invarg;
3476 goto skip;
3477 }
3478 arg[len] = NUL; /* put NUL after name */
3479 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3480 opt_idx = findoption(arg + 1);
3481 arg[len++] = '>'; /* restore '>' */
3482 if (opt_idx == -1)
3483 key = find_key_option(arg + 1);
3484 }
3485 else
3486 {
3487 len = 0;
3488 /*
3489 * The two characters after "t_" may not be alphanumeric.
3490 */
3491 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3492 len = 4;
3493 else
3494 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3495 ++len;
3496 nextchar = arg[len];
3497 arg[len] = NUL; /* put NUL after name */
3498 opt_idx = findoption(arg);
3499 arg[len] = nextchar; /* restore nextchar */
3500 if (opt_idx == -1)
3501 key = find_key_option(arg);
3502 }
3503
3504 /* remember character after option name */
3505 afterchar = arg[len];
3506
3507 /* skip white space, allow ":set ai ?" */
3508 while (vim_iswhite(arg[len]))
3509 ++len;
3510
3511 adding = FALSE;
3512 prepending = FALSE;
3513 removing = FALSE;
3514 if (arg[len] != NUL && arg[len + 1] == '=')
3515 {
3516 if (arg[len] == '+')
3517 {
3518 adding = TRUE; /* "+=" */
3519 ++len;
3520 }
3521 else if (arg[len] == '^')
3522 {
3523 prepending = TRUE; /* "^=" */
3524 ++len;
3525 }
3526 else if (arg[len] == '-')
3527 {
3528 removing = TRUE; /* "-=" */
3529 ++len;
3530 }
3531 }
3532 nextchar = arg[len];
3533
3534 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3535 {
3536 errmsg = (char_u *)N_("E518: Unknown option");
3537 goto skip;
3538 }
3539
3540 if (opt_idx >= 0)
3541 {
3542 if (options[opt_idx].var == NULL) /* hidden option: skip */
3543 {
3544 /* Only give an error message when requesting the value of
3545 * a hidden option, ignore setting it. */
3546 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3547 && (!(options[opt_idx].flags & P_BOOL)
3548 || nextchar == '?'))
3549 errmsg = (char_u *)N_("E519: Option not supported");
3550 goto skip;
3551 }
3552
3553 flags = options[opt_idx].flags;
3554 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3555 }
3556 else
3557 {
3558 flags = P_STRING;
3559 if (key < 0)
3560 {
3561 key_name[0] = KEY2TERMCAP0(key);
3562 key_name[1] = KEY2TERMCAP1(key);
3563 }
3564 else
3565 {
3566 key_name[0] = KS_KEY;
3567 key_name[1] = (key & 0xff);
3568 }
3569 }
3570
3571 /* Disallow changing some options from modelines */
3572 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3573 {
3574 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3575 goto skip;
3576 }
3577
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00003578 /* Skip all options that are not window-local (used when showing
3579 * an already loaded buffer in a window). */
3580 if ((opt_flags & OPT_WINONLY)
3581 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
3582 goto skip;
3583
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584#ifdef HAVE_SANDBOX
3585 /* Disallow changing some options in the sandbox */
3586 if (sandbox > 0 && (flags & P_SECURE))
3587 {
3588 errmsg = (char_u *)_(e_sandbox);
3589 goto skip;
3590 }
3591#endif
3592
3593 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3594 {
3595 arg += len;
3596 cp_val = p_cp;
3597 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3598 {
3599 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3600 {
3601 cp_val = FALSE;
3602 arg += 3;
3603 }
3604 else /* "opt&vi": set to Vi default */
3605 {
3606 cp_val = TRUE;
3607 arg += 2;
3608 }
3609 }
3610 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3611 && arg[1] != NUL && !vim_iswhite(arg[1]))
3612 {
3613 errmsg = e_trailing;
3614 goto skip;
3615 }
3616 }
3617
3618 /*
3619 * allow '=' and ':' as MSDOS command.com allows only one
3620 * '=' character per "set" command line. grrr. (jw)
3621 */
3622 if (nextchar == '?'
3623 || (prefix == 1
3624 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
3625 && !(flags & P_BOOL)))
3626 {
3627 /*
3628 * print value
3629 */
3630 if (did_show)
3631 msg_putchar('\n'); /* cursor below last one */
3632 else
3633 {
3634 gotocmdline(TRUE); /* cursor at status line */
3635 did_show = TRUE; /* remember that we did a line */
3636 }
3637 if (opt_idx >= 0)
3638 {
3639 showoneopt(&options[opt_idx], opt_flags);
3640#ifdef FEAT_EVAL
3641 if (p_verbose > 0)
3642 {
3643 if (options[opt_idx].scriptID != 0)
3644 {
3645 MSG_PUTS(_("\n\tLast set from "));
3646 MSG_PUTS(get_scriptname(options[opt_idx].scriptID));
3647 }
3648 }
3649#endif
3650 }
3651 else
3652 {
3653 char_u *p;
3654
3655 p = find_termcode(key_name);
3656 if (p == NULL)
3657 {
3658 errmsg = (char_u *)N_("E518: Unknown option");
3659 goto skip;
3660 }
3661 else
3662 (void)show_one_termcode(key_name, p, TRUE);
3663 }
3664 if (nextchar != '?'
3665 && nextchar != NUL && !vim_iswhite(afterchar))
3666 errmsg = e_trailing;
3667 }
3668 else
3669 {
3670 if (flags & P_BOOL) /* boolean */
3671 {
3672 if (nextchar == '=' || nextchar == ':')
3673 {
3674 errmsg = e_invarg;
3675 goto skip;
3676 }
3677
3678 /*
3679 * ":set opt!": invert
3680 * ":set opt&": reset to default value
3681 * ":set opt<": reset to global value
3682 */
3683 if (nextchar == '!')
3684 value = *(int *)(varp) ^ 1;
3685 else if (nextchar == '&')
3686 value = (int)(long)options[opt_idx].def_val[
3687 ((flags & P_VI_DEF) || cp_val)
3688 ? VI_DEFAULT : VIM_DEFAULT];
3689 else if (nextchar == '<')
3690 {
3691 /* For 'autoread' -1 means to use global value. */
3692 if ((int *)varp == &curbuf->b_p_ar
3693 && opt_flags == OPT_LOCAL)
3694 value = -1;
3695 else
3696 value = *(int *)get_varp_scope(&(options[opt_idx]),
3697 OPT_GLOBAL);
3698 }
3699 else
3700 {
3701 /*
3702 * ":set invopt": invert
3703 * ":set opt" or ":set noopt": set or reset
3704 */
3705 if (nextchar != NUL && !vim_iswhite(afterchar))
3706 {
3707 errmsg = e_trailing;
3708 goto skip;
3709 }
3710 if (prefix == 2) /* inv */
3711 value = *(int *)(varp) ^ 1;
3712 else
3713 value = prefix;
3714 }
3715
3716 errmsg = set_bool_option(opt_idx, varp, (int)value,
3717 opt_flags);
3718 }
3719 else /* numeric or string */
3720 {
3721 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
3722 || prefix != 1)
3723 {
3724 errmsg = e_invarg;
3725 goto skip;
3726 }
3727
3728 if (flags & P_NUM) /* numeric */
3729 {
3730 /*
3731 * Different ways to set a number option:
3732 * & set to default value
3733 * < set to global value
3734 * <xx> accept special key codes for 'wildchar'
3735 * c accept any non-digit for 'wildchar'
3736 * [-]0-9 set number
3737 * other error
3738 */
3739 ++arg;
3740 if (nextchar == '&')
3741 value = (long)options[opt_idx].def_val[
3742 ((flags & P_VI_DEF) || cp_val)
3743 ? VI_DEFAULT : VIM_DEFAULT];
3744 else if (nextchar == '<')
3745 value = *(long *)get_varp_scope(&(options[opt_idx]),
3746 OPT_GLOBAL);
3747 else if (((long *)varp == &p_wc
3748 || (long *)varp == &p_wcm)
3749 && (*arg == '<'
3750 || *arg == '^'
3751 || ((!arg[1] || vim_iswhite(arg[1]))
3752 && !VIM_ISDIGIT(*arg))))
3753 {
3754 value = string_to_key(arg);
3755 if (value == 0 && (long *)varp != &p_wcm)
3756 {
3757 errmsg = e_invarg;
3758 goto skip;
3759 }
3760 }
3761 /* allow negative numbers (for 'undolevels') */
3762 else if (*arg == '-' || VIM_ISDIGIT(*arg))
3763 {
3764 i = 0;
3765 if (*arg == '-')
3766 i = 1;
3767#ifdef HAVE_STRTOL
3768 value = strtol((char *)arg, NULL, 0);
3769 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
3770 i += 2;
3771#else
3772 value = atol((char *)arg);
3773#endif
3774 while (VIM_ISDIGIT(arg[i]))
3775 ++i;
3776 if (arg[i] != NUL && !vim_iswhite(arg[i]))
3777 {
3778 errmsg = e_invarg;
3779 goto skip;
3780 }
3781 }
3782 else
3783 {
3784 errmsg = (char_u *)N_("E521: Number required after =");
3785 goto skip;
3786 }
3787
3788 if (adding)
3789 value = *(long *)varp + value;
3790 if (prepending)
3791 value = *(long *)varp * value;
3792 if (removing)
3793 value = *(long *)varp - value;
3794 errmsg = set_num_option(opt_idx, varp, value,
3795 errbuf, opt_flags);
3796 }
3797 else if (opt_idx >= 0) /* string */
3798 {
3799 char_u *save_arg = NULL;
3800 char_u *s = NULL;
3801 char_u *oldval; /* previous value if *varp */
3802 char_u *newval;
3803 char_u *origval;
3804 unsigned newlen;
3805 int comma;
3806 int bs;
3807 int new_value_alloced; /* new string option
3808 was allocated */
3809
3810 /* When using ":set opt=val" for a global option
3811 * with a local value the local value will be
3812 * reset, use the global value here. */
3813 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
3814 && (int)options[opt_idx].indir >= PV_BOTH)
3815 varp = options[opt_idx].var;
3816
3817 /* The old value is kept until we are sure that the
3818 * new value is valid. */
3819 oldval = *(char_u **)varp;
3820 if (nextchar == '&') /* set to default val */
3821 {
3822 newval = options[opt_idx].def_val[
3823 ((flags & P_VI_DEF) || cp_val)
3824 ? VI_DEFAULT : VIM_DEFAULT];
3825 if ((char_u **)varp == &p_bg)
3826 {
3827 /* guess the value of 'background' */
3828#ifdef FEAT_GUI
3829 if (gui.in_use)
3830 newval = gui_bg_default();
3831 else
3832#endif
3833 if (STRCMP(T_NAME, "linux") == 0)
3834 newval = (char_u *)"dark";
3835 }
3836
3837 /* expand environment variables and ~ (since the
3838 * default value was already expanded, only
3839 * required when an environment variable was set
3840 * later */
3841 if (newval == NULL)
3842 newval = empty_option;
3843 else
3844 {
3845 s = option_expand(opt_idx, newval);
3846 if (s == NULL)
3847 s = newval;
3848 newval = vim_strsave(s);
3849 }
3850 new_value_alloced = TRUE;
3851 }
3852 else if (nextchar == '<') /* set to global val */
3853 {
3854 newval = vim_strsave(*(char_u **)get_varp_scope(
3855 &(options[opt_idx]), OPT_GLOBAL));
3856 new_value_alloced = TRUE;
3857 }
3858 else
3859 {
3860 ++arg; /* jump to after the '=' or ':' */
3861
3862 /*
3863 * Set 'keywordprg' to ":help" if an empty
3864 * value was passed to :set by the user.
3865 * Misuse errbuf[] for the resulting string.
3866 */
3867 if (varp == (char_u *)&p_kp
3868 && (*arg == NUL || *arg == ' '))
3869 {
3870 STRCPY(errbuf, ":help");
3871 save_arg = arg;
3872 arg = errbuf;
3873 }
3874 /*
3875 * Convert 'whichwrap' number to string, for
3876 * backwards compatibility with Vim 3.0.
3877 * Misuse errbuf[] for the resulting string.
3878 */
3879 else if (varp == (char_u *)&p_ww
3880 && VIM_ISDIGIT(*arg))
3881 {
3882 *errbuf = NUL;
3883 i = getdigits(&arg);
3884 if (i & 1)
3885 STRCAT(errbuf, "b,");
3886 if (i & 2)
3887 STRCAT(errbuf, "s,");
3888 if (i & 4)
3889 STRCAT(errbuf, "h,l,");
3890 if (i & 8)
3891 STRCAT(errbuf, "<,>,");
3892 if (i & 16)
3893 STRCAT(errbuf, "[,],");
3894 if (*errbuf != NUL) /* remove trailing , */
3895 errbuf[STRLEN(errbuf) - 1] = NUL;
3896 save_arg = arg;
3897 arg = errbuf;
3898 }
3899 /*
3900 * Remove '>' before 'dir' and 'bdir', for
3901 * backwards compatibility with version 3.0
3902 */
3903 else if ( *arg == '>'
3904 && (varp == (char_u *)&p_dir
3905 || varp == (char_u *)&p_bdir))
3906 {
3907 ++arg;
3908 }
3909
3910 /* When setting the local value of a global
3911 * option, the old value may be the global value. */
3912 if ((int)options[opt_idx].indir >= PV_BOTH
3913 && (opt_flags & OPT_LOCAL))
3914 origval = *(char_u **)get_varp(
3915 &options[opt_idx]);
3916 else
3917 origval = oldval;
3918
3919 /*
3920 * Copy the new string into allocated memory.
3921 * Can't use set_string_option_direct(), because
3922 * we need to remove the backslashes.
3923 */
3924 /* get a bit too much */
3925 newlen = (unsigned)STRLEN(arg) + 1;
3926 if (adding || prepending || removing)
3927 newlen += (unsigned)STRLEN(origval) + 1;
3928 newval = alloc(newlen);
3929 if (newval == NULL) /* out of mem, don't change */
3930 break;
3931 s = newval;
3932
3933 /*
3934 * Copy the string, skip over escaped chars.
3935 * For MS-DOS and WIN32 backslashes before normal
3936 * file name characters are not removed, and keep
3937 * backslash at start, for "\\machine\path", but
3938 * do remove it for "\\\\machine\\path".
3939 * The reverse is found in ExpandOldSetting().
3940 */
3941 while (*arg && !vim_iswhite(*arg))
3942 {
3943 if (*arg == '\\' && arg[1] != NUL
3944#ifdef BACKSLASH_IN_FILENAME
3945 && !((flags & P_EXPAND)
3946 && vim_isfilec(arg[1])
3947 && (arg[1] != '\\'
3948 || (s == newval
3949 && arg[2] != '\\')))
3950#endif
3951 )
3952 ++arg; /* remove backslash */
3953#ifdef FEAT_MBYTE
3954 if (has_mbyte
3955 && (i = (*mb_ptr2len_check)(arg)) > 1)
3956 {
3957 /* copy multibyte char */
3958 mch_memmove(s, arg, (size_t)i);
3959 arg += i;
3960 s += i;
3961 }
3962 else
3963#endif
3964 *s++ = *arg++;
3965 }
3966 *s = NUL;
3967
3968 /*
3969 * Expand environment variables and ~.
3970 * Don't do it when adding without inserting a
3971 * comma.
3972 */
3973 if (!(adding || prepending || removing)
3974 || (flags & P_COMMA))
3975 {
3976 s = option_expand(opt_idx, newval);
3977 if (s != NULL)
3978 {
3979 vim_free(newval);
3980 newlen = (unsigned)STRLEN(s) + 1;
3981 if (adding || prepending || removing)
3982 newlen += (unsigned)STRLEN(origval) + 1;
3983 newval = alloc(newlen);
3984 if (newval == NULL)
3985 break;
3986 STRCPY(newval, s);
3987 }
3988 }
3989
3990 /* locate newval[] in origval[] when removing it
3991 * and when adding to avoid duplicates */
3992 i = 0; /* init for GCC */
3993 if (removing || (flags & P_NODUP))
3994 {
3995 i = (int)STRLEN(newval);
3996 bs = 0;
3997 for (s = origval; *s; ++s)
3998 {
3999 if ((!(flags & P_COMMA)
4000 || s == origval
4001 || (s[-1] == ',' && !(bs & 1)))
4002 && STRNCMP(s, newval, i) == 0
4003 && (!(flags & P_COMMA)
4004 || s[i] == ','
4005 || s[i] == NUL))
4006 break;
4007 /* Count backspaces. Only a comma with an
4008 * even number of backspaces before it is
4009 * recognized as a separator */
4010 if (s > origval && s[-1] == '\\')
4011 ++bs;
4012 else
4013 bs = 0;
4014 }
4015
4016 /* do not add if already there */
4017 if ((adding || prepending) && *s)
4018 {
4019 prepending = FALSE;
4020 adding = FALSE;
4021 STRCPY(newval, origval);
4022 }
4023 }
4024
4025 /* concatenate the two strings; add a ',' if
4026 * needed */
4027 if (adding || prepending)
4028 {
4029 comma = ((flags & P_COMMA) && *origval != NUL
4030 && *newval != NUL);
4031 if (adding)
4032 {
4033 i = (int)STRLEN(origval);
4034 mch_memmove(newval + i + comma, newval,
4035 STRLEN(newval) + 1);
4036 mch_memmove(newval, origval, (size_t)i);
4037 }
4038 else
4039 {
4040 i = (int)STRLEN(newval);
4041 mch_memmove(newval + i + comma, origval,
4042 STRLEN(origval) + 1);
4043 }
4044 if (comma)
4045 newval[i] = ',';
4046 }
4047
4048 /* Remove newval[] from origval[]. (Note: "i" has
4049 * been set above and is used here). */
4050 if (removing)
4051 {
4052 STRCPY(newval, origval);
4053 if (*s)
4054 {
4055 /* may need to remove a comma */
4056 if (flags & P_COMMA)
4057 {
4058 if (s == origval)
4059 {
4060 /* include comma after string */
4061 if (s[i] == ',')
4062 ++i;
4063 }
4064 else
4065 {
4066 /* include comma before string */
4067 --s;
4068 ++i;
4069 }
4070 }
4071 mch_memmove(newval + (s - origval), s + i,
4072 STRLEN(s + i) + 1);
4073 }
4074 }
4075
4076 if (flags & P_FLAGLIST)
4077 {
4078 /* Remove flags that appear twice. */
4079 for (s = newval; *s; ++s)
4080 if ((!(flags & P_COMMA) || *s != ',')
4081 && vim_strchr(s + 1, *s) != NULL)
4082 {
4083 STRCPY(s, s + 1);
4084 --s;
4085 }
4086 }
4087
4088 if (save_arg != NULL) /* number for 'whichwrap' */
4089 arg = save_arg;
4090 new_value_alloced = TRUE;
4091 }
4092
4093 /* Set the new value. */
4094 *(char_u **)(varp) = newval;
4095
4096 /* Handle side effects, and set the global value for
4097 * ":set" on local options. */
4098 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4099 new_value_alloced, oldval, errbuf, opt_flags);
4100
4101 /* If error detected, print the error message. */
4102 if (errmsg != NULL)
4103 goto skip;
4104 }
4105 else /* key code option */
4106 {
4107 char_u *p;
4108
4109 if (nextchar == '&')
4110 {
4111 if (add_termcap_entry(key_name, TRUE) == FAIL)
4112 errmsg = (char_u *)N_("E522: Not found in termcap");
4113 }
4114 else
4115 {
4116 ++arg; /* jump to after the '=' or ':' */
4117 for (p = arg; *p && !vim_iswhite(*p); ++p)
4118 if (*p == '\\' && p[1] != NUL)
4119 ++p;
4120 nextchar = *p;
4121 *p = NUL;
4122 add_termcode(key_name, arg, FALSE);
4123 *p = nextchar;
4124 }
4125 if (full_screen)
4126 ttest(FALSE);
4127 redraw_all_later(CLEAR);
4128 }
4129 }
4130 if (opt_idx >= 0)
4131 options[opt_idx].flags |= P_WAS_SET;
4132 }
4133
4134skip:
4135 /*
4136 * Advance to next argument.
4137 * - skip until a blank found, taking care of backslashes
4138 * - skip blanks
4139 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4140 */
4141 for (i = 0; i < 2 ; ++i)
4142 {
4143 while (*arg != NUL && !vim_iswhite(*arg))
4144 if (*arg++ == '\\' && *arg != NUL)
4145 ++arg;
4146 arg = skipwhite(arg);
4147 if (*arg != '=')
4148 break;
4149 }
4150 }
4151
4152 if (errmsg != NULL)
4153 {
4154 STRNCPY(IObuff, _(errmsg), IOSIZE - 1);
4155 IObuff[IOSIZE - 1] = NUL;
4156 i = STRLEN(IObuff) + 2;
4157 if (i + (arg - startarg) < IOSIZE)
4158 {
4159 /* append the argument with the error */
4160 STRCAT(IObuff, ": ");
4161 mch_memmove(IObuff + i, startarg, (arg - startarg));
4162 IObuff[i + (arg - startarg)] = NUL;
4163 }
4164 /* make sure all characters are printable */
4165 trans_characters(IObuff, IOSIZE);
4166
4167 ++no_wait_return; /* wait_return done later */
4168 emsg(IObuff); /* show error highlighted */
4169 --no_wait_return;
4170
4171 return FAIL;
4172 }
4173
4174 arg = skipwhite(arg);
4175 }
4176
4177 return OK;
4178}
4179
4180 static char_u *
4181illegal_char(errbuf, c)
4182 char_u *errbuf;
4183 int c;
4184{
4185 if (errbuf == NULL)
4186 return (char_u *)"";
4187 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
4188 (char *)transchar(c));
4189 return errbuf;
4190}
4191
4192/*
4193 * Convert a key name or string into a key value.
4194 * Used for 'wildchar' and 'cedit' options.
4195 */
4196 static int
4197string_to_key(arg)
4198 char_u *arg;
4199{
4200 if (*arg == '<')
4201 return find_key_option(arg + 1);
4202 if (*arg == '^')
4203 return Ctrl_chr(arg[1]);
4204 return *arg;
4205}
4206
4207#ifdef FEAT_CMDWIN
4208/*
4209 * Check value of 'cedit' and set cedit_key.
4210 * Returns NULL if value is OK, error message otherwise.
4211 */
4212 static char_u *
4213check_cedit()
4214{
4215 int n;
4216
4217 if (*p_cedit == NUL)
4218 cedit_key = -1;
4219 else
4220 {
4221 n = string_to_key(p_cedit);
4222 if (vim_isprintc(n))
4223 return e_invarg;
4224 cedit_key = n;
4225 }
4226 return NULL;
4227}
4228#endif
4229
4230#ifdef FEAT_TITLE
4231/*
4232 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4233 * maketitle() to create and display it.
4234 * When switching the title or icon off, call mch_restore_title() to get
4235 * the old value back.
4236 */
4237 static void
4238did_set_title(icon)
4239 int icon; /* Did set icon instead of title */
4240{
4241 if (starting != NO_SCREEN
4242#ifdef FEAT_GUI
4243 && !gui.starting
4244#endif
4245 )
4246 {
4247 maketitle();
4248 if (icon)
4249 {
4250 if (!p_icon)
4251 mch_restore_title(2);
4252 }
4253 else
4254 {
4255 if (!p_title)
4256 mch_restore_title(1);
4257 }
4258 }
4259}
4260#endif
4261
4262/*
4263 * set_options_bin - called when 'bin' changes value.
4264 */
4265 void
4266set_options_bin(oldval, newval, opt_flags)
4267 int oldval;
4268 int newval;
4269 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4270{
4271 /*
4272 * The option values that are changed when 'bin' changes are
4273 * copied when 'bin is set and restored when 'bin' is reset.
4274 */
4275 if (newval)
4276 {
4277 if (!oldval) /* switched on */
4278 {
4279 if (!(opt_flags & OPT_GLOBAL))
4280 {
4281 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4282 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4283 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4284 curbuf->b_p_et_nobin = curbuf->b_p_et;
4285 }
4286 if (!(opt_flags & OPT_LOCAL))
4287 {
4288 p_tw_nobin = p_tw;
4289 p_wm_nobin = p_wm;
4290 p_ml_nobin = p_ml;
4291 p_et_nobin = p_et;
4292 }
4293 }
4294
4295 if (!(opt_flags & OPT_GLOBAL))
4296 {
4297 curbuf->b_p_tw = 0; /* no automatic line wrap */
4298 curbuf->b_p_wm = 0; /* no automatic line wrap */
4299 curbuf->b_p_ml = 0; /* no modelines */
4300 curbuf->b_p_et = 0; /* no expandtab */
4301 }
4302 if (!(opt_flags & OPT_LOCAL))
4303 {
4304 p_tw = 0;
4305 p_wm = 0;
4306 p_ml = FALSE;
4307 p_et = FALSE;
4308 p_bin = TRUE; /* needed when called for the "-b" argument */
4309 }
4310 }
4311 else if (oldval) /* switched off */
4312 {
4313 if (!(opt_flags & OPT_GLOBAL))
4314 {
4315 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4316 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4317 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4318 curbuf->b_p_et = curbuf->b_p_et_nobin;
4319 }
4320 if (!(opt_flags & OPT_LOCAL))
4321 {
4322 p_tw = p_tw_nobin;
4323 p_wm = p_wm_nobin;
4324 p_ml = p_ml_nobin;
4325 p_et = p_et_nobin;
4326 }
4327 }
4328}
4329
4330#ifdef FEAT_VIMINFO
4331/*
4332 * Find the parameter represented by the given character (eg ', :, ", or /),
4333 * and return its associated value in the 'viminfo' string.
4334 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004335 * If the parameter is not specified in the string or there is no following
4336 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004337 */
4338 int
4339get_viminfo_parameter(type)
4340 int type;
4341{
4342 char_u *p;
4343
4344 p = find_viminfo_parameter(type);
4345 if (p != NULL && VIM_ISDIGIT(*p))
4346 return atoi((char *)p);
4347 return -1;
4348}
4349
4350/*
4351 * Find the parameter represented by the given character (eg ''', ':', '"', or
4352 * '/') in the 'viminfo' option and return a pointer to the string after it.
4353 * Return NULL if the parameter is not specified in the string.
4354 */
4355 char_u *
4356find_viminfo_parameter(type)
4357 int type;
4358{
4359 char_u *p;
4360
4361 for (p = p_viminfo; *p; ++p)
4362 {
4363 if (*p == type)
4364 return p + 1;
4365 if (*p == 'n') /* 'n' is always the last one */
4366 break;
4367 p = vim_strchr(p, ','); /* skip until next ',' */
4368 if (p == NULL) /* hit the end without finding parameter */
4369 break;
4370 }
4371 return NULL;
4372}
4373#endif
4374
4375/*
4376 * Expand environment variables for some string options.
4377 * These string options cannot be indirect!
4378 * If "val" is NULL expand the current value of the option.
4379 * Return pointer to NameBuff, or NULL when not expanded.
4380 */
4381 static char_u *
4382option_expand(opt_idx, val)
4383 int opt_idx;
4384 char_u *val;
4385{
4386 /* if option doesn't need expansion nothing to do */
4387 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4388 return NULL;
4389
4390 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4391 * expand_env() would truncate the string. */
4392 if (val != NULL && STRLEN(val) > MAXPATHL)
4393 return NULL;
4394
4395 if (val == NULL)
4396 val = *(char_u **)options[opt_idx].var;
4397
4398 /*
4399 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4400 * Escape spaces when expanding 'tags', they are used to separate file
4401 * names.
4402 */
4403 expand_env_esc(val, NameBuff, MAXPATHL,
4404 (char_u **)options[opt_idx].var == &p_tags);
4405 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4406 return NULL;
4407
4408 return NameBuff;
4409}
4410
4411/*
4412 * After setting various option values: recompute variables that depend on
4413 * option values.
4414 */
4415 static void
4416didset_options()
4417{
4418 /* initialize the table for 'iskeyword' et.al. */
4419 (void)init_chartab();
4420
4421 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4422 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4423#ifdef FEAT_SESSION
4424 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4425 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4426#endif
4427#ifdef FEAT_FOLDING
4428 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4429#endif
4430 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4431#ifdef FEAT_VIRTUALEDIT
4432 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4433#endif
4434#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4435 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4436#endif
4437#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4438 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4439#endif
4440#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4441 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4442#endif
4443#ifdef FEAT_CMDWIN
4444 /* set cedit_key */
4445 (void)check_cedit();
4446#endif
4447}
4448
4449/*
4450 * Check for string options that are NULL (normally only termcap options).
4451 */
4452 void
4453check_options()
4454{
4455 int opt_idx;
4456
4457 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4458 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4459 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4460}
4461
4462/*
4463 * Check string options in a buffer for NULL value.
4464 */
4465 void
4466check_buf_options(buf)
4467 buf_T *buf;
4468{
4469#if defined(FEAT_QUICKFIX)
4470 check_string_option(&buf->b_p_bh);
4471 check_string_option(&buf->b_p_bt);
4472#endif
4473#ifdef FEAT_MBYTE
4474 check_string_option(&buf->b_p_fenc);
4475#endif
4476 check_string_option(&buf->b_p_ff);
4477#ifdef FEAT_FIND_ID
4478 check_string_option(&buf->b_p_def);
4479 check_string_option(&buf->b_p_inc);
4480# ifdef FEAT_EVAL
4481 check_string_option(&buf->b_p_inex);
4482# endif
4483#endif
4484#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4485 check_string_option(&buf->b_p_inde);
4486 check_string_option(&buf->b_p_indk);
4487#endif
4488#ifdef FEAT_CRYPT
4489 check_string_option(&buf->b_p_key);
4490#endif
4491 check_string_option(&buf->b_p_kp);
4492 check_string_option(&buf->b_p_mps);
4493 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004494 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004495 check_string_option(&buf->b_p_isk);
4496#ifdef FEAT_COMMENTS
4497 check_string_option(&buf->b_p_com);
4498#endif
4499#ifdef FEAT_FOLDING
4500 check_string_option(&buf->b_p_cms);
4501#endif
4502 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004503#ifdef FEAT_TEXTOBJ
4504 check_string_option(&buf->b_p_qe);
4505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004506#ifdef FEAT_SYN_HL
4507 check_string_option(&buf->b_p_syn);
4508#endif
4509#ifdef FEAT_SEARCHPATH
4510 check_string_option(&buf->b_p_sua);
4511#endif
4512#ifdef FEAT_CINDENT
4513 check_string_option(&buf->b_p_cink);
4514 check_string_option(&buf->b_p_cino);
4515#endif
4516#ifdef FEAT_AUTOCMD
4517 check_string_option(&buf->b_p_ft);
4518#endif
4519#ifdef FEAT_OSFILETYPE
4520 check_string_option(&buf->b_p_oft);
4521#endif
4522#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4523 check_string_option(&buf->b_p_cinw);
4524#endif
4525#ifdef FEAT_INS_EXPAND
4526 check_string_option(&buf->b_p_cpt);
4527#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004528#ifdef FEAT_COMPL_FUNC
4529 check_string_option(&buf->b_p_cfu);
4530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004531#ifdef FEAT_KEYMAP
4532 check_string_option(&buf->b_p_keymap);
4533#endif
4534#ifdef FEAT_QUICKFIX
4535 check_string_option(&buf->b_p_gp);
4536 check_string_option(&buf->b_p_mp);
4537 check_string_option(&buf->b_p_efm);
4538#endif
4539 check_string_option(&buf->b_p_ep);
4540 check_string_option(&buf->b_p_path);
4541 check_string_option(&buf->b_p_tags);
4542#ifdef FEAT_INS_EXPAND
4543 check_string_option(&buf->b_p_dict);
4544 check_string_option(&buf->b_p_tsr);
4545#endif
4546}
4547
4548/*
4549 * Free the string allocated for an option.
4550 * Checks for the string being empty_option. This may happen if we're out of
4551 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4552 * check_options().
4553 * Does NOT check for P_ALLOCED flag!
4554 */
4555 void
4556free_string_option(p)
4557 char_u *p;
4558{
4559 if (p != empty_option)
4560 vim_free(p);
4561}
4562
4563 void
4564clear_string_option(pp)
4565 char_u **pp;
4566{
4567 if (*pp != empty_option)
4568 vim_free(*pp);
4569 *pp = empty_option;
4570}
4571
4572 static void
4573check_string_option(pp)
4574 char_u **pp;
4575{
4576 if (*pp == NULL)
4577 *pp = empty_option;
4578}
4579
4580/*
4581 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4582 */
4583 void
4584set_term_option_alloced(p)
4585 char_u **p;
4586{
4587 int opt_idx;
4588
4589 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4590 if (options[opt_idx].var == (char_u *)p)
4591 {
4592 options[opt_idx].flags |= P_ALLOCED;
4593 return;
4594 }
4595 return; /* cannot happen: didn't find it! */
4596}
4597
4598/*
4599 * Set a string option to a new value (without checking the effect).
4600 * The string is copied into allocated memory.
4601 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4602 */
4603 void
4604set_string_option_direct(name, opt_idx, val, opt_flags)
4605 char_u *name;
4606 int opt_idx;
4607 char_u *val;
4608 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4609{
4610 char_u *s;
4611 char_u **varp;
4612 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
4613
4614 if (opt_idx == -1) /* use name */
4615 {
4616 opt_idx = findoption(name);
4617 if (opt_idx == -1) /* not found (should not happen) */
4618 return;
4619 }
4620
4621 if (options[opt_idx].var == NULL) /* can't set hidden option */
4622 return;
4623
4624 s = vim_strsave(val);
4625 if (s != NULL)
4626 {
4627 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4628 both ? OPT_LOCAL : opt_flags);
4629 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
4630 free_string_option(*varp);
4631 *varp = s;
4632
4633 /* For buffer/window local option may also set the global value. */
4634 if (both)
4635 set_string_option_global(opt_idx, varp);
4636
4637 options[opt_idx].flags |= P_ALLOCED;
4638
4639 /* When setting both values of a global option with a local value,
4640 * make the local value empty, so that the global value is used. */
4641 if ((int)options[opt_idx].indir >= PV_BOTH && both)
4642 {
4643 free_string_option(*varp);
4644 *varp = empty_option;
4645 }
4646 }
4647}
4648
4649/*
4650 * Set global value for string option when it's a local option.
4651 */
4652 static void
4653set_string_option_global(opt_idx, varp)
4654 int opt_idx; /* option index */
4655 char_u **varp; /* pointer to option variable */
4656{
4657 char_u **p, *s;
4658
4659 /* the global value is always allocated */
4660 if (options[opt_idx].var == VAR_WIN)
4661 p = (char_u **)GLOBAL_WO(varp);
4662 else
4663 p = (char_u **)options[opt_idx].var;
4664 if (options[opt_idx].indir != PV_NONE
4665 && p != varp
4666 && (s = vim_strsave(*varp)) != NULL)
4667 {
4668 free_string_option(*p);
4669 *p = s;
4670 }
4671}
4672
4673/*
4674 * Set a string option to a new value, and handle the effects.
4675 */
4676 static void
4677set_string_option(opt_idx, value, opt_flags)
4678 int opt_idx;
4679 char_u *value;
4680 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4681{
4682 char_u *s;
4683 char_u **varp;
4684 char_u *oldval;
4685
4686 if (options[opt_idx].var == NULL) /* don't set hidden option */
4687 return;
4688
4689 s = vim_strsave(value);
4690 if (s != NULL)
4691 {
4692 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4693 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4694 ? ((int)options[opt_idx].indir >= PV_BOTH
4695 ? OPT_GLOBAL : OPT_LOCAL)
4696 : opt_flags);
4697 oldval = *varp;
4698 *varp = s;
4699 options[opt_idx].flags |= P_WAS_SET;
4700 (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
4701 opt_flags);
4702 }
4703}
4704
4705/*
4706 * Handle string options that need some action to perform when changed.
4707 * Returns NULL for success, or an error message for an error.
4708 */
4709 static char_u *
4710did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
4711 opt_flags)
4712 int opt_idx; /* index in options[] table */
4713 char_u **varp; /* pointer to the option variable */
4714 int new_value_alloced; /* new value was allocated */
4715 char_u *oldval; /* previous value of the option */
4716 char_u *errbuf; /* buffer for errors, or NULL */
4717 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4718{
4719 char_u *errmsg = NULL;
4720 char_u *s, *p;
4721 int did_chartab = FALSE;
4722 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00004723 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724
4725 /* Get the global option to compare with, otherwise we would have to check
4726 * two values for all local options. */
4727 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
4728
4729 /* Disallow changing some options from secure mode */
4730 if ((secure
4731#ifdef HAVE_SANDBOX
4732 || sandbox != 0
4733#endif
4734 ) && (options[opt_idx].flags & P_SECURE))
4735 {
4736 errmsg = e_secure;
4737 }
4738
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004739 /* Check for a "normal" file name in some options. Disallow a path
4740 * separator (slash and/or backslash), wildcards and characters that are
4741 * often illegal in a file name. */
4742 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004743 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004744 {
4745 errmsg = e_invarg;
4746 }
4747
Bram Moolenaar071d4272004-06-13 20:20:40 +00004748 /* 'term' */
4749 else if (varp == &T_NAME)
4750 {
4751 if (T_NAME[0] == NUL)
4752 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
4753#ifdef FEAT_GUI
4754 if (gui.in_use)
4755 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
4756 else if (term_is_gui(T_NAME))
4757 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
4758#endif
4759 else if (set_termname(T_NAME) == FAIL)
4760 errmsg = (char_u *)N_("E522: Not found in termcap");
4761 else
4762 /* Screen colors may have changed. */
4763 redraw_later_clear();
4764 }
4765
4766 /* 'backupcopy' */
4767 else if (varp == &p_bkc)
4768 {
4769 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
4770 errmsg = e_invarg;
4771 if (((bkc_flags & BKC_AUTO) != 0)
4772 + ((bkc_flags & BKC_YES) != 0)
4773 + ((bkc_flags & BKC_NO) != 0) != 1)
4774 {
4775 /* Must have exactly one of "auto", "yes" and "no". */
4776 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
4777 errmsg = e_invarg;
4778 }
4779 }
4780
4781 /* 'backupext' and 'patchmode' */
4782 else if (varp == &p_bex || varp == &p_pm)
4783 {
4784 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
4785 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
4786 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
4787 }
4788
4789 /*
4790 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
4791 * If the new option is invalid, use old value. 'lisp' option: refill
4792 * chartab[] for '-' char
4793 */
4794 else if ( varp == &p_isi
4795 || varp == &(curbuf->b_p_isk)
4796 || varp == &p_isp
4797 || varp == &p_isf)
4798 {
4799 if (init_chartab() == FAIL)
4800 {
4801 did_chartab = TRUE; /* need to restore it below */
4802 errmsg = e_invarg; /* error in value */
4803 }
4804 }
4805
4806 /* 'helpfile' */
4807 else if (varp == &p_hf)
4808 {
4809 /* May compute new values for $VIM and $VIMRUNTIME */
4810 if (didset_vim)
4811 {
4812 vim_setenv((char_u *)"VIM", (char_u *)"");
4813 didset_vim = FALSE;
4814 }
4815 if (didset_vimruntime)
4816 {
4817 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
4818 didset_vimruntime = FALSE;
4819 }
4820 }
4821
4822#ifdef FEAT_MULTI_LANG
4823 /* 'helplang' */
4824 else if (varp == &p_hlg)
4825 {
4826 /* Check for "", "ab", "ab,cd", etc. */
4827 for (s = p_hlg; *s != NUL; s += 3)
4828 {
4829 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
4830 {
4831 errmsg = e_invarg;
4832 break;
4833 }
4834 if (s[2] == NUL)
4835 break;
4836 }
4837 }
4838#endif
4839
4840 /* 'highlight' */
4841 else if (varp == &p_hl)
4842 {
4843 if (highlight_changed() == FAIL)
4844 errmsg = e_invarg; /* invalid flags */
4845 }
4846
4847 /* 'nrformats' */
4848 else if (gvarp == &p_nf)
4849 {
4850 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
4851 errmsg = e_invarg;
4852 }
4853
4854#ifdef FEAT_SESSION
4855 /* 'sessionoptions' */
4856 else if (varp == &p_ssop)
4857 {
4858 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
4859 errmsg = e_invarg;
4860 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
4861 {
4862 /* Don't allow both "sesdir" and "curdir". */
4863 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
4864 errmsg = e_invarg;
4865 }
4866 }
4867 /* 'viewoptions' */
4868 else if (varp == &p_vop)
4869 {
4870 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
4871 errmsg = e_invarg;
4872 }
4873#endif
4874
4875 /* 'scrollopt' */
4876#ifdef FEAT_SCROLLBIND
4877 else if (varp == &p_sbo)
4878 {
4879 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
4880 errmsg = e_invarg;
4881 }
4882#endif
4883
4884 /* 'ambiwidth' */
4885#ifdef FEAT_MBYTE
4886 else if (varp == &p_ambw)
4887 {
4888 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
4889 errmsg = e_invarg;
4890 }
4891#endif
4892
4893 /* 'background' */
4894 else if (varp == &p_bg)
4895 {
4896 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
4897 {
4898#ifdef FEAT_EVAL
4899 int dark = (*p_bg == 'd');
4900#endif
4901
4902 init_highlight(FALSE, FALSE);
4903
4904#ifdef FEAT_EVAL
4905 if (dark != (*p_bg == 'd')
4906 && get_var_value((char_u *)"g:colors_name") != NULL)
4907 {
4908 /* The color scheme must have set 'background' back to another
4909 * value, that's not what we want here. Disable the color
4910 * scheme and set the colors again. */
4911 do_unlet((char_u *)"g:colors_name");
4912 free_string_option(p_bg);
4913 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
4914 check_string_option(&p_bg);
4915 init_highlight(FALSE, FALSE);
4916 }
4917#endif
4918 }
4919 else
4920 errmsg = e_invarg;
4921 }
4922
4923 /* 'wildmode' */
4924 else if (varp == &p_wim)
4925 {
4926 if (check_opt_wim() == FAIL)
4927 errmsg = e_invarg;
4928 }
4929
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00004930#ifdef FEAT_CMDL_COMPL
4931 /* 'wildoptions' */
4932 else if (varp == &p_wop)
4933 {
4934 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
4935 errmsg = e_invarg;
4936 }
4937#endif
4938
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939#ifdef FEAT_WAK
4940 /* 'winaltkeys' */
4941 else if (varp == &p_wak)
4942 {
4943 if (*p_wak == NUL
4944 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
4945 errmsg = e_invarg;
4946# ifdef FEAT_MENU
4947# ifdef FEAT_GUI_MOTIF
4948 else if (gui.in_use)
4949 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
4950# else
4951# ifdef FEAT_GUI_GTK
4952 else if (gui.in_use)
4953 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
4954# endif
4955# endif
4956# endif
4957 }
4958#endif
4959
4960#ifdef FEAT_AUTOCMD
4961 /* 'eventignore' */
4962 else if (varp == &p_ei)
4963 {
4964 if (check_ei() == FAIL)
4965 errmsg = e_invarg;
4966 }
4967#endif
4968
4969#ifdef FEAT_MBYTE
4970 /* 'encoding' and 'fileencoding' */
4971 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
4972 {
4973 if (gvarp == &p_fenc)
4974 {
4975 if (!curbuf->b_p_ma)
4976 errmsg = e_modifiable;
4977 else if (vim_strchr(*varp, ',') != NULL)
4978 /* No comma allowed in 'fileencoding'; catches confusing it
4979 * with 'fileencodings'. */
4980 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004981 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004982 {
4983# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00004984 /* May show a "+" in the title now. */
4985 need_maketitle = TRUE;
4986# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004987 /* Add 'fileencoding' to the swap file. */
4988 ml_setflags(curbuf);
4989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004990 }
4991 if (errmsg == NULL)
4992 {
4993 /* canonize the value, so that STRCMP() can be used on it */
4994 p = enc_canonize(*varp);
4995 if (p != NULL)
4996 {
4997 vim_free(*varp);
4998 *varp = p;
4999 }
5000 if (varp == &p_enc)
5001 {
5002 errmsg = mb_init();
5003# ifdef FEAT_TITLE
5004 need_maketitle = TRUE;
5005# endif
5006 }
5007 }
5008
5009# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5010 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5011 {
5012 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5013 if (STRCMP(p_tenc, "utf-8") != 0)
5014 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5015 }
5016# endif
5017
5018 if (errmsg == NULL)
5019 {
5020# ifdef FEAT_KEYMAP
5021 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5022 * (with another encoding). */
5023 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5024 (void)keymap_init();
5025# endif
5026
5027 /* When 'termencoding' is not empty and 'encoding' changes or when
5028 * 'termencoding' changes, need to setup for keyboard input and
5029 * display output conversion. */
5030 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5031 {
5032 convert_setup(&input_conv, p_tenc, p_enc);
5033 convert_setup(&output_conv, p_enc, p_tenc);
5034 }
5035 }
5036 }
5037#endif
5038
5039#if defined(FEAT_POSTSCRIPT)
5040 else if (varp == &p_penc)
5041 {
5042 /* Canonize printencoding if VIM standard one */
5043 p = enc_canonize(p_penc);
5044 if (p != NULL)
5045 {
5046 vim_free(p_penc);
5047 p_penc = p;
5048 }
5049 else
5050 {
5051 /* Ensure lower case and '-' for '_' */
5052 for (s = p_penc; *s != NUL; s++)
5053 {
5054 if (*s == '_')
5055 *s = '-';
5056 else
5057 *s = TOLOWER_ASC(*s);
5058 }
5059 }
5060 }
5061#endif
5062
Bram Moolenaar843ee412004-06-30 16:16:41 +00005063#if defined(FEAT_XIM) && ( defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005064 else if (varp == &p_imak)
5065 {
5066 if (gui.in_use && !im_xim_isvalid_imactivate())
5067 errmsg = e_invarg;
5068 }
5069#endif
5070
5071#ifdef FEAT_KEYMAP
5072 else if (varp == &curbuf->b_p_keymap)
5073 {
5074 /* load or unload key mapping tables */
5075 errmsg = keymap_init();
5076
5077 /* When successfully installed a new keymap switch on using it. */
5078 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5079 {
5080 curbuf->b_p_iminsert = B_IMODE_LMAP;
5081 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5082 curbuf->b_p_imsearch = B_IMODE_LMAP;
5083 set_iminsert_global();
5084 set_imsearch_global();
5085# ifdef FEAT_WINDOWS
5086 status_redraw_curbuf();
5087# endif
5088 }
5089 }
5090#endif
5091
5092 /* 'fileformat' */
5093 else if (gvarp == &p_ff)
5094 {
5095 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5096 errmsg = e_modifiable;
5097 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5098 errmsg = e_invarg;
5099 else
5100 {
5101 /* may also change 'textmode' */
5102 if (get_fileformat(curbuf) == EOL_DOS)
5103 curbuf->b_p_tx = TRUE;
5104 else
5105 curbuf->b_p_tx = FALSE;
5106#ifdef FEAT_TITLE
5107 need_maketitle = TRUE;
5108#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005109 /* update flag in swap file */
5110 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 }
5112 }
5113
5114 /* 'fileformats' */
5115 else if (varp == &p_ffs)
5116 {
5117 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5118 errmsg = e_invarg;
5119 else
5120 {
5121 /* also change 'textauto' */
5122 if (*p_ffs == NUL)
5123 p_ta = FALSE;
5124 else
5125 p_ta = TRUE;
5126 }
5127 }
5128
5129#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5130 /* 'cryptkey' */
5131 else if (gvarp == &p_key)
5132 {
5133 /* Make sure the ":set" command doesn't show the new value in the
5134 * history. */
5135 remove_key_from_history();
5136 }
5137#endif
5138
5139 /* 'matchpairs' */
5140 else if (gvarp == &p_mps)
5141 {
5142 /* Check for "x:y,x:y" */
5143 for (p = *varp; *p != NUL; p += 4)
5144 {
5145 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5146 {
5147 errmsg = e_invarg;
5148 break;
5149 }
5150 if (p[3] == NUL)
5151 break;
5152 }
5153 }
5154
5155#ifdef FEAT_COMMENTS
5156 /* 'comments' */
5157 else if (gvarp == &p_com)
5158 {
5159 for (s = *varp; *s; )
5160 {
5161 while (*s && *s != ':')
5162 {
5163 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5164 && !VIM_ISDIGIT(*s) && *s != '-')
5165 {
5166 errmsg = illegal_char(errbuf, *s);
5167 break;
5168 }
5169 ++s;
5170 }
5171 if (*s++ == NUL)
5172 errmsg = (char_u *)N_("E524: Missing colon");
5173 else if (*s == ',' || *s == NUL)
5174 errmsg = (char_u *)N_("E525: Zero length string");
5175 if (errmsg != NULL)
5176 break;
5177 while (*s && *s != ',')
5178 {
5179 if (*s == '\\' && s[1] != NUL)
5180 ++s;
5181 ++s;
5182 }
5183 s = skip_to_option_part(s);
5184 }
5185 }
5186#endif
5187
5188 /* 'listchars' */
5189 else if (varp == &p_lcs)
5190 {
5191 errmsg = set_chars_option(varp);
5192 }
5193
5194#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5195 /* 'fillchars' */
5196 else if (varp == &p_fcs)
5197 {
5198 errmsg = set_chars_option(varp);
5199 }
5200#endif
5201
5202#ifdef FEAT_CMDWIN
5203 /* 'cedit' */
5204 else if (varp == &p_cedit)
5205 {
5206 errmsg = check_cedit();
5207 }
5208#endif
5209
5210#ifdef FEAT_VIMINFO
5211 /* 'viminfo' */
5212 else if (varp == &p_viminfo)
5213 {
5214 for (s = p_viminfo; *s;)
5215 {
5216 /* Check it's a valid character */
5217 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5218 {
5219 errmsg = illegal_char(errbuf, *s);
5220 break;
5221 }
5222 if (*s == 'n') /* name is always last one */
5223 {
5224 break;
5225 }
5226 else if (*s == 'r') /* skip until next ',' */
5227 {
5228 while (*++s && *s != ',')
5229 ;
5230 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005231 else if (*s == '%')
5232 {
5233 /* optional number */
5234 while (vim_isdigit(*++s))
5235 ;
5236 }
5237 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005238 ++s; /* no extra chars */
5239 else /* must have a number */
5240 {
5241 while (vim_isdigit(*++s))
5242 ;
5243
5244 if (!VIM_ISDIGIT(*(s - 1)))
5245 {
5246 if (errbuf != NULL)
5247 {
5248 sprintf((char *)errbuf, _("E526: Missing number after <%s>"),
5249 transchar_byte(*(s - 1)));
5250 errmsg = errbuf;
5251 }
5252 else
5253 errmsg = (char_u *)"";
5254 break;
5255 }
5256 }
5257 if (*s == ',')
5258 ++s;
5259 else if (*s)
5260 {
5261 if (errbuf != NULL)
5262 errmsg = (char_u *)N_("E527: Missing comma");
5263 else
5264 errmsg = (char_u *)"";
5265 break;
5266 }
5267 }
5268 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5269 errmsg = (char_u *)N_("E528: Must specify a ' value");
5270 }
5271#endif /* FEAT_VIMINFO */
5272
5273 /* terminal options */
5274 else if (istermoption(&options[opt_idx]) && full_screen)
5275 {
5276 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5277 if (varp == &T_CCO)
5278 {
5279 t_colors = atoi((char *)T_CCO);
5280 if (t_colors <= 1)
5281 {
5282 if (new_value_alloced)
5283 vim_free(T_CCO);
5284 T_CCO = empty_option;
5285 }
5286 /* We now have a different color setup, initialize it again. */
5287 init_highlight(TRUE, FALSE);
5288 }
5289 ttest(FALSE);
5290 if (varp == &T_ME)
5291 {
5292 out_str(T_ME);
5293 redraw_later(CLEAR);
5294#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5295 /* Since t_me has been set, this probably means that the user
5296 * wants to use this as default colors. Need to reset default
5297 * background/foreground colors. */
5298 mch_set_normal_colors();
5299#endif
5300 }
5301 }
5302
5303#ifdef FEAT_LINEBREAK
5304 /* 'showbreak' */
5305 else if (varp == &p_sbr)
5306 {
5307 for (s = p_sbr; *s; )
5308 {
5309 if (ptr2cells(s) != 1)
5310 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005311 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312 }
5313 }
5314#endif
5315
5316#ifdef FEAT_GUI
5317 /* 'guifont' */
5318 else if (varp == &p_guifont)
5319 {
5320 if (gui.in_use)
5321 {
5322 p = p_guifont;
Bram Moolenaar843ee412004-06-30 16:16:41 +00005323# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005324 /*
5325 * Put up a font dialog and let the user select a new value.
5326 * If this is cancelled go back to the old value but don't
5327 * give an error message.
5328 */
5329 if (STRCMP(p, "*") == 0)
5330 {
5331 p = gui_mch_font_dialog(oldval);
5332
5333 if (new_value_alloced)
5334 free_string_option(p_guifont);
5335
5336 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5337 new_value_alloced = TRUE;
5338 }
5339# endif
5340 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5341 {
5342# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5343 if (STRCMP(p_guifont, "*") == 0)
5344 {
5345 /* Dialog was cancelled: Keep the old value without giving
5346 * an error message. */
5347 if (new_value_alloced)
5348 free_string_option(p_guifont);
5349 p_guifont = vim_strsave(oldval);
5350 new_value_alloced = TRUE;
5351 }
5352 else
5353# endif
5354 errmsg = (char_u *)N_("E596: Invalid font(s)");
5355 }
5356 }
5357 }
5358# ifdef FEAT_XFONTSET
5359 else if (varp == &p_guifontset)
5360 {
5361 if (STRCMP(p_guifontset, "*") == 0)
5362 errmsg = (char_u *)N_("E597: can't select fontset");
5363 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5364 errmsg = (char_u *)N_("E598: Invalid fontset");
5365 }
5366# endif
5367# ifdef FEAT_MBYTE
5368 else if (varp == &p_guifontwide)
5369 {
5370 if (STRCMP(p_guifontwide, "*") == 0)
5371 errmsg = (char_u *)N_("E533: can't select wide font");
5372 else if (gui_get_wide_font() == FAIL)
5373 errmsg = (char_u *)N_("E534: Invalid wide font");
5374 }
5375# endif
5376#endif
5377
5378#ifdef CURSOR_SHAPE
5379 /* 'guicursor' */
5380 else if (varp == &p_guicursor)
5381 errmsg = parse_shape_opt(SHAPE_CURSOR);
5382#endif
5383
5384#ifdef FEAT_MOUSESHAPE
5385 /* 'mouseshape' */
5386 else if (varp == &p_mouseshape)
5387 {
5388 errmsg = parse_shape_opt(SHAPE_MOUSE);
5389 update_mouseshape(-1);
5390 }
5391#endif
5392
5393#ifdef FEAT_PRINTER
5394 else if (varp == &p_popt)
Bram Moolenaar269ec652004-07-29 08:43:53 +00005395 errmsg = parse_list_options(p_popt, printer_opts,
5396 OPT_PRINT_NUM_OPTIONS);
Bram Moolenaar8299df92004-07-10 09:47:34 +00005397
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005398# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005399 else if (varp == &p_pmfn)
Bram Moolenaar269ec652004-07-29 08:43:53 +00005400 errmsg = parse_list_options(p_pmfn, mbfont_opts,
5401 OPT_MBFONT_NUM_OPTIONS);
Bram Moolenaar8299df92004-07-10 09:47:34 +00005402# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005403#endif
5404
5405#ifdef FEAT_LANGMAP
5406 /* 'langmap' */
5407 else if (varp == &p_langmap)
5408 langmap_set();
5409#endif
5410
5411#ifdef FEAT_LINEBREAK
5412 /* 'breakat' */
5413 else if (varp == &p_breakat)
5414 fill_breakat_flags();
5415#endif
5416
5417#ifdef FEAT_TITLE
5418 /* 'titlestring' and 'iconstring' */
5419 else if (varp == &p_titlestring || varp == &p_iconstring)
5420 {
5421# ifdef FEAT_STL_OPT
5422 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5423
5424 /* NULL => statusline syntax */
5425 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5426 stl_syntax |= flagval;
5427 else
5428 stl_syntax &= ~flagval;
5429# endif
5430 did_set_title(varp == &p_iconstring);
5431
5432 }
5433#endif
5434
5435#ifdef FEAT_GUI
5436 /* 'guioptions' */
5437 else if (varp == &p_go)
5438 gui_init_which_components(oldval);
5439#endif
5440
5441#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5442 /* 'ttymouse' */
5443 else if (varp == &p_ttym)
5444 {
5445 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5446 errmsg = e_invarg;
5447 else
5448 check_mouse_termcode();
5449 }
5450#endif
5451
5452#ifdef FEAT_VISUAL
5453 /* 'selection' */
5454 else if (varp == &p_sel)
5455 {
5456 if (*p_sel == NUL
5457 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5458 errmsg = e_invarg;
5459 }
5460
5461 /* 'selectmode' */
5462 else if (varp == &p_slm)
5463 {
5464 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5465 errmsg = e_invarg;
5466 }
5467#endif
5468
5469#ifdef FEAT_BROWSE
5470 /* 'browsedir' */
5471 else if (varp == &p_bsdir)
5472 {
5473 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5474 && !mch_isdir(p_bsdir))
5475 errmsg = e_invarg;
5476 }
5477#endif
5478
5479#ifdef FEAT_VISUAL
5480 /* 'keymodel' */
5481 else if (varp == &p_km)
5482 {
5483 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5484 errmsg = e_invarg;
5485 else
5486 {
5487 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5488 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5489 }
5490 }
5491#endif
5492
5493 /* 'mousemodel' */
5494 else if (varp == &p_mousem)
5495 {
5496 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5497 errmsg = e_invarg;
5498#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5499 else if (*p_mousem != *oldval)
5500 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5501 * to create or delete the popup menus. */
5502 gui_motif_update_mousemodel(root_menu);
5503#endif
5504 }
5505
5506 /* 'switchbuf' */
5507 else if (varp == &p_swb)
5508 {
5509 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5510 errmsg = e_invarg;
5511 }
5512
5513 /* 'debug' */
5514 else if (varp == &p_debug)
5515 {
5516 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5517 errmsg = e_invarg;
5518 }
5519
5520 /* 'display' */
5521 else if (varp == &p_dy)
5522 {
5523 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5524 errmsg = e_invarg;
5525 else
5526 (void)init_chartab();
5527
5528 }
5529
5530#ifdef FEAT_VERTSPLIT
5531 /* 'eadirection' */
5532 else if (varp == &p_ead)
5533 {
5534 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5535 errmsg = e_invarg;
5536 }
5537#endif
5538
5539#ifdef FEAT_CLIPBOARD
5540 /* 'clipboard' */
5541 else if (varp == &p_cb)
5542 errmsg = check_clipboard_option();
5543#endif
5544
5545#ifdef FEAT_AUTOCMD
5546# ifdef FEAT_SYN_HL
5547 /* When 'syntax' is set, load the syntax of that name */
5548 else if (varp == &(curbuf->b_p_syn))
5549 {
5550 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
5551 curbuf->b_fname, TRUE, curbuf);
5552 }
5553# endif
5554
5555 /* When 'filetype' is set, trigger the FileType autocommands of that name */
5556 else if (varp == &(curbuf->b_p_ft))
5557 {
5558 did_filetype = TRUE;
5559 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
5560 curbuf->b_fname, TRUE, curbuf);
5561 }
5562#endif
5563
5564#ifdef FEAT_QUICKFIX
5565 /* When 'bufhidden' is set, check for valid value. */
5566 else if (gvarp == &p_bh)
5567 {
5568 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5569 errmsg = e_invarg;
5570 }
5571
5572 /* When 'buftype' is set, check for valid value. */
5573 else if (gvarp == &p_bt)
5574 {
5575 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5576 errmsg = e_invarg;
5577 else
5578 {
5579# ifdef FEAT_WINDOWS
5580 if (curwin->w_status_height)
5581 {
5582 curwin->w_redr_status = TRUE;
5583 redraw_later(VALID);
5584 }
5585# endif
5586 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5587 }
5588 }
5589#endif
5590
5591#ifdef FEAT_STL_OPT
5592 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005593 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005594 {
5595 int wid;
5596
5597 if (varp == &p_ruf) /* reset ru_wid first */
5598 ru_wid = 0;
5599 s = *varp;
5600 if (varp == &p_ruf && *s == '%')
5601 {
5602 /* set ru_wid if 'ruf' starts with "%99(" */
5603 if (*++s == '-') /* ignore a '-' */
5604 s++;
5605 wid = getdigits(&s);
5606 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5607 ru_wid = wid;
5608 else
5609 errmsg = check_stl_option(p_ruf);
5610 }
5611 else
5612 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005613 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005614 comp_col();
5615 }
5616#endif
5617
5618#ifdef FEAT_INS_EXPAND
5619 /* check if it is a valid value for 'complete' -- Acevedo */
5620 else if (gvarp == &p_cpt)
5621 {
5622 for (s = *varp; *s;)
5623 {
5624 while(*s == ',' || *s == ' ')
5625 s++;
5626 if (!*s)
5627 break;
5628 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5629 {
5630 errmsg = illegal_char(errbuf, *s);
5631 break;
5632 }
5633 if (*++s != NUL && *s != ',' && *s != ' ')
5634 {
5635 if (s[-1] == 'k' || s[-1] == 's')
5636 {
5637 /* skip optional filename after 'k' and 's' */
5638 while (*s && *s != ',' && *s != ' ')
5639 {
5640 if (*s == '\\')
5641 ++s;
5642 ++s;
5643 }
5644 }
5645 else
5646 {
5647 if (errbuf != NULL)
5648 {
5649 sprintf((char *)errbuf,
5650 _("E535: Illegal character after <%c>"),
5651 *--s);
5652 errmsg = errbuf;
5653 }
5654 else
5655 errmsg = (char_u *)"";
5656 break;
5657 }
5658 }
5659 }
5660 }
5661#endif /* FEAT_INS_EXPAND */
5662
5663
5664#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5665 else if (varp == &p_toolbar)
5666 {
5667 if (opt_strings_flags(p_toolbar, p_toolbar_values,
5668 &toolbar_flags, TRUE) != OK)
5669 errmsg = e_invarg;
5670 else
5671 {
5672 out_flush();
5673 gui_mch_show_toolbar((toolbar_flags &
5674 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5675 }
5676 }
5677#endif
5678
5679#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5680 /* 'toolbariconsize': GTK+ 2 only */
5681 else if (varp == &p_tbis)
5682 {
5683 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
5684 errmsg = e_invarg;
5685 else
5686 {
5687 out_flush();
5688 gui_mch_show_toolbar((toolbar_flags &
5689 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5690 }
5691 }
5692#endif
5693
5694 /* 'pastetoggle': translate key codes like in a mapping */
5695 else if (varp == &p_pt)
5696 {
5697 if (*p_pt)
5698 {
5699 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
5700 if (p != NULL)
5701 {
5702 if (new_value_alloced)
5703 free_string_option(p_pt);
5704 p_pt = p;
5705 new_value_alloced = TRUE;
5706 }
5707 }
5708 }
5709
5710 /* 'backspace' */
5711 else if (varp == &p_bs)
5712 {
5713 if (VIM_ISDIGIT(*p_bs))
5714 {
5715 if (*p_bs >'2' || p_bs[1] != NUL)
5716 errmsg = e_invarg;
5717 }
5718 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
5719 errmsg = e_invarg;
5720 }
5721
5722 /* 'casemap' */
5723 else if (varp == &p_cmp)
5724 {
5725 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
5726 errmsg = e_invarg;
5727 }
5728
5729#ifdef FEAT_DIFF
5730 /* 'diffopt' */
5731 else if (varp == &p_dip)
5732 {
5733 if (diffopt_changed() == FAIL)
5734 errmsg = e_invarg;
5735 }
5736#endif
5737
5738#ifdef FEAT_FOLDING
5739 /* 'foldmethod' */
5740 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
5741 {
5742 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
5743 || *curwin->w_p_fdm == NUL)
5744 errmsg = e_invarg;
5745 else
5746 foldUpdateAll(curwin);
5747 }
5748# ifdef FEAT_EVAL
5749 /* 'foldexpr' */
5750 else if (varp == &curwin->w_p_fde)
5751 {
5752 if (foldmethodIsExpr(curwin))
5753 foldUpdateAll(curwin);
5754 }
5755# endif
5756 /* 'foldmarker' */
5757 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
5758 {
5759 p = vim_strchr(*varp, ',');
5760 if (p == NULL)
5761 errmsg = (char_u *)N_("E536: comma required");
5762 else if (p == *varp || p[1] == NUL)
5763 errmsg = e_invarg;
5764 else if (foldmethodIsMarker(curwin))
5765 foldUpdateAll(curwin);
5766 }
5767 /* 'commentstring' */
5768 else if (gvarp == &p_cms)
5769 {
5770 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
5771 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
5772 }
5773 /* 'foldopen' */
5774 else if (varp == &p_fdo)
5775 {
5776 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
5777 errmsg = e_invarg;
5778 }
5779 /* 'foldclose' */
5780 else if (varp == &p_fcl)
5781 {
5782 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
5783 errmsg = e_invarg;
5784 }
5785#endif
5786
5787#ifdef FEAT_VIRTUALEDIT
5788 /* 'virtualedit' */
5789 else if (varp == &p_ve)
5790 {
5791 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
5792 errmsg = e_invarg;
5793 else if (STRCMP(p_ve, oldval) != 0)
5794 {
5795 /* Recompute cursor position in case the new 've' setting
5796 * changes something. */
5797 validate_virtcol();
5798 coladvance(curwin->w_virtcol);
5799 }
5800 }
5801#endif
5802
5803#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
5804 else if (varp == &p_csqf)
5805 {
5806 if (p_csqf != NULL)
5807 {
5808 p = p_csqf;
5809 while (*p != NUL)
5810 {
5811 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
5812 || p[1] == NUL
5813 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
5814 || (p[2] != NUL && p[2] != ','))
5815 {
5816 errmsg = e_invarg;
5817 break;
5818 }
5819 else if (p[2] == NUL)
5820 break;
5821 else
5822 p += 3;
5823 }
5824 }
5825 }
5826#endif
5827
5828 /* Options that are a list of flags. */
5829 else
5830 {
5831 p = NULL;
5832 if (varp == &p_ww)
5833 p = (char_u *)WW_ALL;
5834 if (varp == &p_shm)
5835 p = (char_u *)SHM_ALL;
5836 else if (varp == &(p_cpo))
5837 p = (char_u *)CPO_ALL;
5838 else if (varp == &(curbuf->b_p_fo))
5839 p = (char_u *)FO_ALL;
5840 else if (varp == &p_mouse)
5841 {
5842#ifdef FEAT_MOUSE
5843 p = (char_u *)MOUSE_ALL;
5844#else
5845 if (*p_mouse != NUL)
5846 errmsg = (char_u *)N_("E538: No mouse support");
5847#endif
5848 }
5849#if defined(FEAT_GUI)
5850 else if (varp == &p_go)
5851 p = (char_u *)GO_ALL;
5852#endif
5853 if (p != NULL)
5854 {
5855 for (s = *varp; *s; ++s)
5856 if (vim_strchr(p, *s) == NULL)
5857 {
5858 errmsg = illegal_char(errbuf, *s);
5859 break;
5860 }
5861 }
5862 }
5863
5864 /*
5865 * If error detected, restore the previous value.
5866 */
5867 if (errmsg != NULL)
5868 {
5869 if (new_value_alloced)
5870 free_string_option(*varp);
5871 *varp = oldval;
5872 /*
5873 * When resetting some values, need to act on it.
5874 */
5875 if (did_chartab)
5876 (void)init_chartab();
5877 if (varp == &p_hl)
5878 (void)highlight_changed();
5879 }
5880 else
5881 {
5882#ifdef FEAT_EVAL
5883 /* Remember where the option was set. */
5884 options[opt_idx].scriptID = current_SID;
5885#endif
5886 /*
5887 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005888 * Use "free_oldval", because recursiveness may change the flags under
5889 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005891 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892 free_string_option(oldval);
5893 if (new_value_alloced)
5894 options[opt_idx].flags |= P_ALLOCED;
5895 else
5896 options[opt_idx].flags &= ~P_ALLOCED;
5897
5898 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5899 && (int)options[opt_idx].indir >= PV_BOTH)
5900 {
5901 /* global option with local value set to use global value; free
5902 * the local value and make it empty */
5903 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
5904 free_string_option(*(char_u **)p);
5905 *(char_u **)p = empty_option;
5906 }
5907
5908 /* May set global value for local option. */
5909 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
5910 set_string_option_global(opt_idx, varp);
5911 }
5912
5913#ifdef FEAT_MOUSE
5914 if (varp == &p_mouse)
5915 {
5916# ifdef FEAT_MOUSE_TTY
5917 if (*p_mouse == NUL)
5918 mch_setmouse(FALSE); /* switch mouse off */
5919 else
5920# endif
5921 setmouse(); /* in case 'mouse' changed */
5922 }
5923#endif
5924
5925 if (curwin->w_curswant != MAXCOL)
5926 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
5927 check_redraw(options[opt_idx].flags);
5928
5929 return errmsg;
5930}
5931
5932/*
5933 * Handle setting 'listchars' or 'fillchars'.
5934 * Returns error message, NULL if it's OK.
5935 */
5936 static char_u *
5937set_chars_option(varp)
5938 char_u **varp;
5939{
5940 int round, i, len, entries;
5941 char_u *p, *s;
5942 int c1, c2 = 0;
5943 struct charstab
5944 {
5945 int *cp;
5946 char *name;
5947 };
5948#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5949 static struct charstab filltab[] =
5950 {
5951 {&fill_stl, "stl"},
5952 {&fill_stlnc, "stlnc"},
5953 {&fill_vert, "vert"},
5954 {&fill_fold, "fold"},
5955 {&fill_diff, "diff"},
5956 };
5957#endif
5958 static struct charstab lcstab[] =
5959 {
5960 {&lcs_eol, "eol"},
5961 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005962 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 {&lcs_prec, "precedes"},
5964 {&lcs_tab2, "tab"},
5965 {&lcs_trail, "trail"},
5966 };
5967 struct charstab *tab;
5968
5969#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5970 if (varp == &p_lcs)
5971#endif
5972 {
5973 tab = lcstab;
5974 entries = sizeof(lcstab) / sizeof(struct charstab);
5975 }
5976#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5977 else
5978 {
5979 tab = filltab;
5980 entries = sizeof(filltab) / sizeof(struct charstab);
5981 }
5982#endif
5983
5984 /* first round: check for valid value, second round: assign values */
5985 for (round = 0; round <= 1; ++round)
5986 {
5987 if (round)
5988 {
5989 /* After checking that the value is valid: set defaults: space for
5990 * 'fillchars', NUL for 'listchars' */
5991 for (i = 0; i < entries; ++i)
5992 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
5993 if (varp == &p_lcs)
5994 lcs_tab1 = NUL;
5995#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5996 else
5997 fill_diff = '-';
5998#endif
5999 }
6000 p = *varp;
6001 while (*p)
6002 {
6003 for (i = 0; i < entries; ++i)
6004 {
6005 len = (int)STRLEN(tab[i].name);
6006 if (STRNCMP(p, tab[i].name, len) == 0
6007 && p[len] == ':'
6008 && p[len + 1] != NUL)
6009 {
6010 s = p + len + 1;
6011#ifdef FEAT_MBYTE
6012 c1 = mb_ptr2char_adv(&s);
6013#else
6014 c1 = *s++;
6015#endif
6016 if (tab[i].cp == &lcs_tab2)
6017 {
6018 if (*s == NUL)
6019 continue;
6020#ifdef FEAT_MBYTE
6021 c2 = mb_ptr2char_adv(&s);
6022#else
6023 c2 = *s++;
6024#endif
6025 }
6026 if (*s == ',' || *s == NUL)
6027 {
6028 if (round)
6029 {
6030 if (tab[i].cp == &lcs_tab2)
6031 {
6032 lcs_tab1 = c1;
6033 lcs_tab2 = c2;
6034 }
6035 else
6036 *(tab[i].cp) = c1;
6037
6038 }
6039 p = s;
6040 break;
6041 }
6042 }
6043 }
6044
6045 if (i == entries)
6046 return e_invarg;
6047 if (*p == ',')
6048 ++p;
6049 }
6050 }
6051
6052 return NULL; /* no error */
6053}
6054
6055#ifdef FEAT_STL_OPT
6056/*
6057 * Check validity of options with the 'statusline' format.
6058 * Return error message or NULL.
6059 */
6060 char_u *
6061check_stl_option(s)
6062 char_u *s;
6063{
6064 int itemcnt = 0;
6065 int groupdepth = 0;
6066 static char_u errbuf[80];
6067
6068 while (*s && itemcnt < STL_MAX_ITEM)
6069 {
6070 /* Check for valid keys after % sequences */
6071 while (*s && *s != '%')
6072 s++;
6073 if (!*s)
6074 break;
6075 s++;
6076 if (*s != '%' && *s != ')')
6077 ++itemcnt;
6078 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6079 {
6080 s++;
6081 continue;
6082 }
6083 if (*s == ')')
6084 {
6085 s++;
6086 if (--groupdepth < 0)
6087 break;
6088 continue;
6089 }
6090 if (*s == '-')
6091 s++;
6092 while (VIM_ISDIGIT(*s))
6093 s++;
6094 if (*s == STL_HIGHLIGHT)
6095 continue;
6096 if (*s == '.')
6097 {
6098 s++;
6099 while (*s && VIM_ISDIGIT(*s))
6100 s++;
6101 }
6102 if (*s == '(')
6103 {
6104 groupdepth++;
6105 continue;
6106 }
6107 if (vim_strchr(STL_ALL, *s) == NULL)
6108 {
6109 return illegal_char(errbuf, *s);
6110 }
6111 if (*s == '{')
6112 {
6113 s++;
6114 while (*s != '}' && *s)
6115 s++;
6116 if (*s != '}')
6117 return (char_u *)N_("E540: Unclosed expression sequence");
6118 }
6119 }
6120 if (itemcnt >= STL_MAX_ITEM)
6121 return (char_u *)N_("E541: too many items");
6122 if (groupdepth != 0)
6123 return (char_u *)N_("E542: unbalanced groups");
6124 return NULL;
6125}
6126#endif
6127
6128#ifdef FEAT_CLIPBOARD
6129/*
6130 * Extract the items in the 'clipboard' option and set global values.
6131 */
6132 static char_u *
6133check_clipboard_option()
6134{
6135 int new_unnamed = FALSE;
6136 int new_autoselect = FALSE;
6137 int new_autoselectml = FALSE;
6138 regprog_T *new_exclude_prog = NULL;
6139 char_u *errmsg = NULL;
6140 char_u *p;
6141
6142 for (p = p_cb; *p != NUL; )
6143 {
6144 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6145 {
6146 new_unnamed = TRUE;
6147 p += 7;
6148 }
6149 else if (STRNCMP(p, "autoselect", 10) == 0
6150 && (p[10] == ',' || p[10] == NUL))
6151 {
6152 new_autoselect = TRUE;
6153 p += 10;
6154 }
6155 else if (STRNCMP(p, "autoselectml", 12) == 0
6156 && (p[12] == ',' || p[12] == NUL))
6157 {
6158 new_autoselectml = TRUE;
6159 p += 12;
6160 }
6161 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6162 {
6163 p += 8;
6164 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6165 if (new_exclude_prog == NULL)
6166 errmsg = e_invarg;
6167 break;
6168 }
6169 else
6170 {
6171 errmsg = e_invarg;
6172 break;
6173 }
6174 if (*p == ',')
6175 ++p;
6176 }
6177 if (errmsg == NULL)
6178 {
6179 clip_unnamed = new_unnamed;
6180 clip_autoselect = new_autoselect;
6181 clip_autoselectml = new_autoselectml;
6182 vim_free(clip_exclude_prog);
6183 clip_exclude_prog = new_exclude_prog;
6184 }
6185 else
6186 vim_free(new_exclude_prog);
6187
6188 return errmsg;
6189}
6190#endif
6191
6192/*
6193 * Set the value of a boolean option, and take care of side effects.
6194 * Returns NULL for success, or an error message for an error.
6195 */
6196 static char_u *
6197set_bool_option(opt_idx, varp, value, opt_flags)
6198 int opt_idx; /* index in options[] table */
6199 char_u *varp; /* pointer to the option variable */
6200 int value; /* new value */
6201 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6202{
6203 int old_value = *(int *)varp;
6204
6205#ifdef FEAT_GUI
6206 need_mouse_correct = TRUE;
6207#endif
6208
6209 /* Disallow changing some options from secure mode */
6210 if ((secure
6211#ifdef HAVE_SANDBOX
6212 || sandbox != 0
6213#endif
6214 ) && (options[opt_idx].flags & P_SECURE))
6215 return e_secure;
6216
6217 *(int *)varp = value; /* set the new value */
6218#ifdef FEAT_EVAL
6219 /* Remember where the option was set. */
6220 options[opt_idx].scriptID = current_SID;
6221#endif
6222
6223 /* May set global value for local option. */
6224 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6225 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6226
6227 /*
6228 * Handle side effects of changing a bool option.
6229 */
6230
6231 /* 'compatible' */
6232 if ((int *)varp == &p_cp)
6233 {
6234 compatible_set();
6235 }
6236
6237 /* when 'readonly' is reset globally, also reset readonlymode */
6238 else if ((int *)varp == &curbuf->b_p_ro)
6239 {
6240 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6241 readonlymode = FALSE;
6242#ifdef FEAT_TITLE
6243 need_maketitle = TRUE;
6244#endif
6245 }
6246
6247#ifdef FEAT_TITLE
6248 /* when 'modifiable' is changed, redraw the window title */
6249 else if ((int *)varp == &curbuf->b_p_ma)
6250 need_maketitle = TRUE;
6251 /* when 'endofline' is changed, redraw the window title */
6252 else if ((int *)varp == &curbuf->b_p_eol)
6253 need_maketitle = TRUE;
6254#endif
6255
6256 /* when 'bin' is set also set some other options */
6257 else if ((int *)varp == &curbuf->b_p_bin)
6258 {
6259 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6260#ifdef FEAT_TITLE
6261 need_maketitle = TRUE;
6262#endif
6263 }
6264
6265#ifdef FEAT_AUTOCMD
6266 /* when 'buflisted' changes, trigger autocommands */
6267 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6268 {
6269 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6270 NULL, NULL, TRUE, curbuf);
6271 }
6272#endif
6273
6274 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6275 else if ((int *)varp == &curbuf->b_p_swf)
6276 {
6277 if (curbuf->b_p_swf && p_uc)
6278 ml_open_file(curbuf); /* create the swap file */
6279 else
6280 mf_close_file(curbuf, TRUE); /* remove the swap file */
6281 }
6282
6283 /* when 'terse' is set change 'shortmess' */
6284 else if ((int *)varp == &p_terse)
6285 {
6286 char_u *p;
6287
6288 p = vim_strchr(p_shm, SHM_SEARCH);
6289
6290 /* insert 's' in p_shm */
6291 if (p_terse && p == NULL)
6292 {
6293 STRCPY(IObuff, p_shm);
6294 STRCAT(IObuff, "s");
6295 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6296 }
6297 /* remove 's' from p_shm */
6298 else if (!p_terse && p != NULL)
6299 mch_memmove(p, p + 1, STRLEN(p));
6300 }
6301
6302 /* when 'paste' is set or reset also change other options */
6303 else if ((int *)varp == &p_paste)
6304 {
6305 paste_option_changed();
6306 }
6307
6308 /* when 'insertmode' is set from an autocommand need to do work here */
6309 else if ((int *)varp == &p_im)
6310 {
6311 if (p_im)
6312 {
6313 if ((State & INSERT) == 0)
6314 need_start_insertmode = TRUE;
6315 stop_insert_mode = FALSE;
6316 }
6317 else
6318 {
6319 need_start_insertmode = FALSE;
6320 stop_insert_mode = TRUE;
6321 if (p_smd && restart_edit != 0)
6322 clear_cmdline = TRUE; /* remove "(insert)" */
6323 restart_edit = 0;
6324 }
6325 }
6326
6327 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6328 else if ((int *)varp == &p_ic && p_hls)
6329 {
6330 redraw_all_later(NOT_VALID);
6331 }
6332
6333#ifdef FEAT_SEARCH_EXTRA
6334 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6335 else if ((int *)varp == &p_hls)
6336 {
6337 no_hlsearch = FALSE;
6338 }
6339#endif
6340
6341#ifdef FEAT_SCROLLBIND
6342 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6343 * at the end of normal_cmd() */
6344 else if ((int *)varp == &curwin->w_p_scb)
6345 {
6346 if (curwin->w_p_scb)
6347 do_check_scrollbind(FALSE);
6348 }
6349#endif
6350
6351#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6352 /* There can be only one window with 'previewwindow' set. */
6353 else if ((int *)varp == &curwin->w_p_pvw)
6354 {
6355 if (curwin->w_p_pvw)
6356 {
6357 win_T *win;
6358
6359 for (win = firstwin; win != NULL; win = win->w_next)
6360 if (win->w_p_pvw && win != curwin)
6361 {
6362 curwin->w_p_pvw = FALSE;
6363 return (char_u *)N_("E590: A preview window already exists");
6364 }
6365 }
6366 }
6367#endif
6368
6369 /* when 'textmode' is set or reset also change 'fileformat' */
6370 else if ((int *)varp == &curbuf->b_p_tx)
6371 {
6372 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6373 }
6374
6375 /* when 'textauto' is set or reset also change 'fileformats' */
6376 else if ((int *)varp == &p_ta)
6377 {
6378 set_string_option_direct((char_u *)"ffs", -1,
6379 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6380 OPT_FREE | opt_flags);
6381 }
6382
6383 /*
6384 * When 'lisp' option changes include/exclude '-' in
6385 * keyword characters.
6386 */
6387#ifdef FEAT_LISP
6388 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6389 {
6390 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6391 }
6392#endif
6393
6394#ifdef FEAT_TITLE
6395 /* when 'title' changed, may need to change the title; same for 'icon' */
6396 else if ((int *)varp == &p_title)
6397 {
6398 did_set_title(FALSE);
6399 }
6400
6401 else if ((int *)varp == &p_icon)
6402 {
6403 did_set_title(TRUE);
6404 }
6405#endif
6406
6407 else if ((int *)varp == &curbuf->b_changed)
6408 {
6409 if (!value)
6410 save_file_ff(curbuf); /* Buffer is unchanged */
6411#ifdef FEAT_TITLE
6412 need_maketitle = TRUE;
6413#endif
6414#ifdef FEAT_AUTOCMD
6415 modified_was_set = value;
6416#endif
6417 }
6418
6419#ifdef BACKSLASH_IN_FILENAME
6420 else if ((int *)varp == &p_ssl)
6421 {
6422 if (p_ssl)
6423 {
6424 psepc = '/';
6425 psepcN = '\\';
6426 pseps[0] = '/';
6427 psepsN[0] = '\\';
6428 }
6429 else
6430 {
6431 psepc = '\\';
6432 psepcN = '/';
6433 pseps[0] = '\\';
6434 psepsN[0] = '/';
6435 }
6436
6437 /* need to adjust the file name arguments and buffer names. */
6438 buflist_slash_adjust();
6439 alist_slash_adjust();
6440# ifdef FEAT_EVAL
6441 scriptnames_slash_adjust();
6442# endif
6443 }
6444#endif
6445
6446 /* If 'wrap' is set, set w_leftcol to zero. */
6447 else if ((int *)varp == &curwin->w_p_wrap)
6448 {
6449 if (curwin->w_p_wrap)
6450 curwin->w_leftcol = 0;
6451 }
6452
6453#ifdef FEAT_WINDOWS
6454 else if ((int *)varp == &p_ea)
6455 {
6456 if (p_ea && !old_value)
6457 win_equal(curwin, FALSE, 0);
6458 }
6459#endif
6460
6461 else if ((int *)varp == &p_wiv)
6462 {
6463 /*
6464 * When 'weirdinvert' changed, set/reset 't_xs'.
6465 * Then set 'weirdinvert' according to value of 't_xs'.
6466 */
6467 if (p_wiv && !old_value)
6468 T_XS = (char_u *)"y";
6469 else if (!p_wiv && old_value)
6470 T_XS = empty_option;
6471 p_wiv = (*T_XS != NUL);
6472 }
6473
6474#if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \
6475 || defined(FEAT_NETBEANS_INTG))
6476 else if ((int *)varp == &p_beval)
6477 {
6478 extern BalloonEval *balloonEval;
6479
6480 if (p_beval == TRUE)
6481 gui_mch_enable_beval_area(balloonEval);
6482 else
6483 gui_mch_disable_beval_area(balloonEval);
6484 }
6485
6486 else if ((int *)varp == &p_acd)
6487 {
6488 if (p_acd && curbuf->b_ffname != NULL
6489 && vim_chdirfile(curbuf->b_ffname) == OK)
6490 shorten_fnames(TRUE);
6491 }
6492#endif
6493
6494#ifdef FEAT_DIFF
6495 /* 'diff' */
6496 else if ((int *)varp == &curwin->w_p_diff)
6497 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006498 /* May add or remove the buffer from the list of diff buffers. */
6499 diff_buf_adjust(curwin);
6500# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006501 if (foldmethodIsDiff(curwin))
6502 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006503# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006504 }
6505#endif
6506
6507#ifdef USE_IM_CONTROL
6508 /* 'imdisable' */
6509 else if ((int *)varp == &p_imdisable)
6510 {
6511 /* Only de-activate it here, it will be enabled when changing mode. */
6512 if (p_imdisable)
6513 im_set_active(FALSE);
6514 }
6515#endif
6516
6517#ifdef FEAT_FKMAP
6518 else if ((int *)varp == &p_altkeymap)
6519 {
6520 if (old_value != p_altkeymap)
6521 {
6522 if (!p_altkeymap)
6523 {
6524 p_hkmap = p_fkmap;
6525 p_fkmap = 0;
6526 }
6527 else
6528 {
6529 p_fkmap = p_hkmap;
6530 p_hkmap = 0;
6531 }
6532 (void)init_chartab();
6533 }
6534 }
6535
6536 /*
6537 * In case some second language keymapping options have changed, check
6538 * and correct the setting in a consistent way.
6539 */
6540
6541 /*
6542 * If hkmap or fkmap are set, reset Arabic keymapping.
6543 */
6544 if ((p_hkmap || p_fkmap) && p_altkeymap)
6545 {
6546 p_altkeymap = p_fkmap;
6547# ifdef FEAT_ARABIC
6548 curwin->w_p_arab = FALSE;
6549# endif
6550 (void)init_chartab();
6551 }
6552
6553 /*
6554 * If hkmap set, reset Farsi keymapping.
6555 */
6556 if (p_hkmap && p_altkeymap)
6557 {
6558 p_altkeymap = 0;
6559 p_fkmap = 0;
6560# ifdef FEAT_ARABIC
6561 curwin->w_p_arab = FALSE;
6562# endif
6563 (void)init_chartab();
6564 }
6565
6566 /*
6567 * If fkmap set, reset Hebrew keymapping.
6568 */
6569 if (p_fkmap && !p_altkeymap)
6570 {
6571 p_altkeymap = 1;
6572 p_hkmap = 0;
6573# ifdef FEAT_ARABIC
6574 curwin->w_p_arab = FALSE;
6575# endif
6576 (void)init_chartab();
6577 }
6578#endif
6579
6580#ifdef FEAT_ARABIC
6581 if ((int *)varp == &curwin->w_p_arab)
6582 {
6583 if (curwin->w_p_arab)
6584 {
6585 /*
6586 * 'arabic' is set, handle various sub-settings.
6587 */
6588 if (!p_tbidi)
6589 {
6590 /* set rightleft mode */
6591 if (!curwin->w_p_rl)
6592 {
6593 curwin->w_p_rl = TRUE;
6594 changed_window_setting();
6595 }
6596
6597 /* Enable Arabic shaping (major part of what Arabic requires) */
6598 if (!p_arshape)
6599 {
6600 p_arshape = TRUE;
6601 redraw_later_clear();
6602 }
6603 }
6604
6605 /* Arabic requires a utf-8 encoding, inform the user if its not
6606 * set. */
6607 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006608 {
6609 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006610 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6611 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006612 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613
6614# ifdef FEAT_MBYTE
6615 /* set 'delcombine' */
6616 p_deco = TRUE;
6617# endif
6618
6619# ifdef FEAT_KEYMAP
6620 /* Force-set the necessary keymap for arabic */
6621 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
6622 OPT_LOCAL);
6623# endif
6624# ifdef FEAT_FKMAP
6625 p_altkeymap = 0;
6626 p_hkmap = 0;
6627 p_fkmap = 0;
6628 (void)init_chartab();
6629# endif
6630 }
6631 else
6632 {
6633 /*
6634 * 'arabic' is reset, handle various sub-settings.
6635 */
6636 if (!p_tbidi)
6637 {
6638 /* reset rightleft mode */
6639 if (curwin->w_p_rl)
6640 {
6641 curwin->w_p_rl = FALSE;
6642 changed_window_setting();
6643 }
6644
6645 /* 'arabicshape' isn't reset, it is a global option and
6646 * another window may still need it "on". */
6647 }
6648
6649 /* 'delcombine' isn't reset, it is a global option and another
6650 * window may still want it "on". */
6651
6652# ifdef FEAT_KEYMAP
6653 /* Revert to the default keymap */
6654 curbuf->b_p_iminsert = B_IMODE_NONE;
6655 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6656# endif
6657 }
6658 }
6659#endif
6660
6661 /*
6662 * End of handling side effects for bool options.
6663 */
6664
6665 options[opt_idx].flags |= P_WAS_SET;
6666
6667 comp_col(); /* in case 'ruler' or 'showcmd' changed */
6668 if (curwin->w_curswant != MAXCOL)
6669 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
6670 check_redraw(options[opt_idx].flags);
6671
6672 return NULL;
6673}
6674
6675/*
6676 * Set the value of a number option, and take care of side effects.
6677 * Returns NULL for success, or an error message for an error.
6678 */
6679 static char_u *
6680set_num_option(opt_idx, varp, value, errbuf, opt_flags)
6681 int opt_idx; /* index in options[] table */
6682 char_u *varp; /* pointer to the option variable */
6683 long value; /* new value */
6684 char_u *errbuf; /* buffer for error messages */
6685 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
6686 OPT_MODELINE */
6687{
6688 char_u *errmsg = NULL;
6689 long old_value = *(long *)varp;
6690 long old_Rows = Rows; /* remember old Rows */
6691 long old_Columns = Columns; /* remember old Columns */
6692 long *pp = (long *)varp;
6693
6694#ifdef FEAT_GUI
6695 need_mouse_correct = TRUE;
6696#endif
6697
6698 *pp = value;
6699#ifdef FEAT_EVAL
6700 /* Remember where the option was set. */
6701 options[opt_idx].scriptID = current_SID;
6702#endif
6703
6704 if (curbuf->b_p_sw <= 0)
6705 {
6706 errmsg = e_positive;
6707 curbuf->b_p_sw = curbuf->b_p_ts;
6708 }
6709
6710 /*
6711 * Number options that need some action when changed
6712 */
6713#ifdef FEAT_WINDOWS
6714 if (pp == &p_wh || pp == &p_hh)
6715 {
6716 if (p_wh < 1)
6717 {
6718 errmsg = e_positive;
6719 p_wh = 1;
6720 }
6721 if (p_wmh > p_wh)
6722 {
6723 errmsg = e_winheight;
6724 p_wh = p_wmh;
6725 }
6726 if (p_hh < 0)
6727 {
6728 errmsg = e_positive;
6729 p_hh = 0;
6730 }
6731
6732 /* Change window height NOW */
6733 if (lastwin != firstwin)
6734 {
6735 if (pp == &p_wh && curwin->w_height < p_wh)
6736 win_setheight((int)p_wh);
6737 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
6738 win_setheight((int)p_hh);
6739 }
6740 }
6741
6742 /* 'winminheight' */
6743 else if (pp == &p_wmh)
6744 {
6745 if (p_wmh < 0)
6746 {
6747 errmsg = e_positive;
6748 p_wmh = 0;
6749 }
6750 if (p_wmh > p_wh)
6751 {
6752 errmsg = e_winheight;
6753 p_wmh = p_wh;
6754 }
6755 win_setminheight();
6756 }
6757
6758# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006759 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760 {
6761 if (p_wiw < 1)
6762 {
6763 errmsg = e_positive;
6764 p_wiw = 1;
6765 }
6766 if (p_wmw > p_wiw)
6767 {
6768 errmsg = e_winwidth;
6769 p_wiw = p_wmw;
6770 }
6771
6772 /* Change window width NOW */
6773 if (lastwin != firstwin && curwin->w_width < p_wiw)
6774 win_setwidth((int)p_wiw);
6775 }
6776
6777 /* 'winminwidth' */
6778 else if (pp == &p_wmw)
6779 {
6780 if (p_wmw < 0)
6781 {
6782 errmsg = e_positive;
6783 p_wmw = 0;
6784 }
6785 if (p_wmw > p_wiw)
6786 {
6787 errmsg = e_winwidth;
6788 p_wmw = p_wiw;
6789 }
6790 win_setminheight();
6791 }
6792# endif
6793
6794#endif
6795
6796#ifdef FEAT_WINDOWS
6797 /* (re)set last window status line */
6798 else if (pp == &p_ls)
6799 {
6800 last_status(FALSE);
6801 }
6802#endif
6803
6804#ifdef FEAT_GUI
6805 else if (pp == &p_linespace)
6806 {
6807 if (gui.in_use && gui_mch_adjust_charsize() == OK)
6808 gui_set_shellsize(FALSE, FALSE);
6809 }
6810#endif
6811
6812#ifdef FEAT_FOLDING
6813 /* 'foldlevel' */
6814 else if (pp == &curwin->w_p_fdl)
6815 {
6816 if (curwin->w_p_fdl < 0)
6817 curwin->w_p_fdl = 0;
6818 newFoldLevel();
6819 }
6820
6821 /* 'foldminlevel' */
6822 else if (pp == &curwin->w_p_fml)
6823 {
6824 foldUpdateAll(curwin);
6825 }
6826
6827 /* 'foldnestmax' */
6828 else if (pp == &curwin->w_p_fdn)
6829 {
6830 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
6831 foldUpdateAll(curwin);
6832 }
6833
6834 /* 'foldcolumn' */
6835 else if (pp == &curwin->w_p_fdc)
6836 {
6837 if (curwin->w_p_fdc < 0)
6838 {
6839 errmsg = e_positive;
6840 curwin->w_p_fdc = 0;
6841 }
6842 else if (curwin->w_p_fdc > 12)
6843 {
6844 errmsg = e_invarg;
6845 curwin->w_p_fdc = 12;
6846 }
6847 }
6848
6849 /* 'shiftwidth' or 'tabstop' */
6850 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
6851 {
6852 if (foldmethodIsIndent(curwin))
6853 foldUpdateAll(curwin);
6854 }
6855#endif /* FEAT_FOLDING */
6856
6857 else if (pp == &curbuf->b_p_iminsert)
6858 {
6859 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
6860 {
6861 errmsg = e_invarg;
6862 curbuf->b_p_iminsert = B_IMODE_NONE;
6863 }
6864 p_iminsert = curbuf->b_p_iminsert;
6865 if (termcap_active) /* don't do this in the alternate screen */
6866 showmode();
6867#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
6868 /* Show/unshow value of 'keymap' in status lines. */
6869 status_redraw_curbuf();
6870#endif
6871 }
6872
6873 else if (pp == &curbuf->b_p_imsearch)
6874 {
6875 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
6876 {
6877 errmsg = e_invarg;
6878 curbuf->b_p_imsearch = B_IMODE_NONE;
6879 }
6880 p_imsearch = curbuf->b_p_imsearch;
6881 }
6882
6883#ifdef FEAT_TITLE
6884 /* if 'titlelen' has changed, redraw the title */
6885 else if (pp == &p_titlelen)
6886 {
6887 if (p_titlelen < 0)
6888 {
6889 errmsg = e_positive;
6890 p_titlelen = 85;
6891 }
6892 if (starting != NO_SCREEN && old_value != p_titlelen)
6893 need_maketitle = TRUE;
6894 }
6895#endif
6896
6897 /* if p_ch changed value, change the command line height */
6898 else if (pp == &p_ch)
6899 {
6900 if (p_ch < 1)
6901 {
6902 errmsg = e_positive;
6903 p_ch = 1;
6904 }
6905
6906 /* Only compute the new window layout when startup has been
6907 * completed. Otherwise the frame sizes may be wrong. */
6908 if (p_ch != old_value && full_screen
6909#ifdef FEAT_GUI
6910 && !gui.starting
6911#endif
6912 )
6913 command_height(old_value);
6914 }
6915
6916 /* when 'updatecount' changes from zero to non-zero, open swap files */
6917 else if (pp == &p_uc)
6918 {
6919 if (p_uc < 0)
6920 {
6921 errmsg = e_positive;
6922 p_uc = 100;
6923 }
6924 if (p_uc && !old_value)
6925 ml_open_files();
6926 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006927#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00006928 else if (pp == &p_mzq)
6929 mzvim_reset_timer();
6930#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006931
6932 /* sync undo before 'undolevels' changes */
6933 else if (pp == &p_ul)
6934 {
6935 /* use the old value, otherwise u_sync() may not work properly */
6936 p_ul = old_value;
6937 u_sync();
6938 p_ul = value;
6939 }
6940
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006941#ifdef FEAT_LINEBREAK
6942 /* 'numberwidth' must be positive */
6943 else if (pp == &curwin->w_p_nuw)
6944 {
6945 if (curwin->w_p_nuw < 1)
6946 {
6947 errmsg = e_positive;
6948 curwin->w_p_nuw = 1;
6949 }
6950 if (curwin->w_p_nuw > 10)
6951 {
6952 errmsg = e_invarg;
6953 curwin->w_p_nuw = 10;
6954 }
6955 curwin->w_nrwidth_line_count = 0;
6956 }
6957#endif
6958
Bram Moolenaar071d4272004-06-13 20:20:40 +00006959 /*
6960 * Check the bounds for numeric options here
6961 */
6962 if (Rows < min_rows() && full_screen)
6963 {
6964 if (errbuf != NULL)
6965 {
6966 sprintf((char *)errbuf, _("E593: Need at least %d lines"),
6967 min_rows());
6968 errmsg = errbuf;
6969 }
6970 Rows = min_rows();
6971 }
6972 if (Columns < MIN_COLUMNS && full_screen)
6973 {
6974 if (errbuf != NULL)
6975 {
6976 sprintf((char *)errbuf, _("E594: Need at least %d columns"),
6977 MIN_COLUMNS);
6978 errmsg = errbuf;
6979 }
6980 Columns = MIN_COLUMNS;
6981 }
6982
6983#ifdef DJGPP
6984 /* avoid a crash by checking for a too large value of 'columns' */
6985 if (old_Columns != Columns && full_screen && term_console)
6986 mch_check_columns();
6987#endif
6988
6989 /*
6990 * If the screen (shell) height has been changed, assume it is the
6991 * physical screenheight.
6992 */
6993 if (old_Rows != Rows || old_Columns != Columns)
6994 {
6995 /* Changing the screen size is not allowed while updating the screen. */
6996 if (updating_screen)
6997 *pp = old_value;
6998 else if (full_screen
6999#ifdef FEAT_GUI
7000 && !gui.starting
7001#endif
7002 )
7003 set_shellsize((int)Columns, (int)Rows, TRUE);
7004 else
7005 {
7006 /* Postpone the resizing; check the size and cmdline position for
7007 * messages. */
7008 check_shellsize();
7009 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7010 cmdline_row = Rows - p_ch;
7011 }
7012 }
7013
7014 if (curbuf->b_p_sts < 0)
7015 {
7016 errmsg = e_positive;
7017 curbuf->b_p_sts = 0;
7018 }
7019 if (curbuf->b_p_ts <= 0)
7020 {
7021 errmsg = e_positive;
7022 curbuf->b_p_ts = 8;
7023 }
7024 if (curbuf->b_p_tw < 0)
7025 {
7026 errmsg = e_positive;
7027 curbuf->b_p_tw = 0;
7028 }
7029 if (p_tm < 0)
7030 {
7031 errmsg = e_positive;
7032 p_tm = 0;
7033 }
7034 if ((curwin->w_p_scr <= 0
7035 || (curwin->w_p_scr > curwin->w_height
7036 && curwin->w_height > 0))
7037 && full_screen)
7038 {
7039 if (pp == &(curwin->w_p_scr))
7040 {
7041 if (curwin->w_p_scr != 0)
7042 errmsg = e_scroll;
7043 win_comp_scroll(curwin);
7044 }
7045 /* If 'scroll' became invalid because of a side effect silently adjust
7046 * it. */
7047 else if (curwin->w_p_scr <= 0)
7048 curwin->w_p_scr = 1;
7049 else /* curwin->w_p_scr > curwin->w_height */
7050 curwin->w_p_scr = curwin->w_height;
7051 }
7052 if (p_report < 0)
7053 {
7054 errmsg = e_positive;
7055 p_report = 1;
7056 }
7057 if ((p_sj < 0 || p_sj >= Rows) && full_screen)
7058 {
7059 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7060 p_sj = Rows / 2;
7061 else
7062 {
7063 errmsg = e_scroll;
7064 p_sj = 1;
7065 }
7066 }
7067 if (p_so < 0 && full_screen)
7068 {
7069 errmsg = e_scroll;
7070 p_so = 0;
7071 }
7072 if (p_siso < 0 && full_screen)
7073 {
7074 errmsg = e_positive;
7075 p_siso = 0;
7076 }
7077#ifdef FEAT_CMDWIN
7078 if (p_cwh < 1)
7079 {
7080 errmsg = e_positive;
7081 p_cwh = 1;
7082 }
7083#endif
7084 if (p_ut < 0)
7085 {
7086 errmsg = e_positive;
7087 p_ut = 2000;
7088 }
7089 if (p_ss < 0)
7090 {
7091 errmsg = e_positive;
7092 p_ss = 0;
7093 }
7094
7095 /* May set global value for local option. */
7096 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7097 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7098
7099 options[opt_idx].flags |= P_WAS_SET;
7100
7101 comp_col(); /* in case 'columns' or 'ls' changed */
7102 if (curwin->w_curswant != MAXCOL)
7103 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7104 check_redraw(options[opt_idx].flags);
7105
7106 return errmsg;
7107}
7108
7109/*
7110 * Called after an option changed: check if something needs to be redrawn.
7111 */
7112 static void
7113check_redraw(flags)
7114 long_u flags;
7115{
7116 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7117 int clear = (flags & P_RCLR) == P_RCLR;
7118 int all = ((flags & P_RALL) == P_RALL || clear);
7119
7120#ifdef FEAT_WINDOWS
7121 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7122 status_redraw_all();
7123#endif
7124
7125 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7126 changed_window_setting();
7127 if (flags & P_RBUF)
7128 redraw_curbuf_later(NOT_VALID);
7129 if (clear)
7130 redraw_all_later(CLEAR);
7131 else if (all)
7132 redraw_all_later(NOT_VALID);
7133}
7134
7135/*
7136 * Find index for option 'arg'.
7137 * Return -1 if not found.
7138 */
7139 static int
7140findoption(arg)
7141 char_u *arg;
7142{
7143 int opt_idx;
7144 char *s, *p;
7145 static short quick_tab[27] = {0, 0}; /* quick access table */
7146 int is_term_opt;
7147
7148 /*
7149 * For first call: Initialize the quick-access table.
7150 * It contains the index for the first option that starts with a certain
7151 * letter. There are 26 letters, plus the first "t_" option.
7152 */
7153 if (quick_tab[1] == 0)
7154 {
7155 p = options[0].fullname;
7156 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7157 {
7158 if (s[0] != p[0])
7159 {
7160 if (s[0] == 't' && s[1] == '_')
7161 quick_tab[26] = opt_idx;
7162 else
7163 quick_tab[CharOrdLow(s[0])] = opt_idx;
7164 }
7165 p = s;
7166 }
7167 }
7168
7169 /*
7170 * Check for name starting with an illegal character.
7171 */
7172#ifdef EBCDIC
7173 if (!islower(arg[0]))
7174#else
7175 if (arg[0] < 'a' || arg[0] > 'z')
7176#endif
7177 return -1;
7178
7179 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7180 if (is_term_opt)
7181 opt_idx = quick_tab[26];
7182 else
7183 opt_idx = quick_tab[CharOrdLow(arg[0])];
7184 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7185 {
7186 if (STRCMP(arg, s) == 0) /* match full name */
7187 break;
7188 }
7189 if (s == NULL && !is_term_opt)
7190 {
7191 opt_idx = quick_tab[CharOrdLow(arg[0])];
7192 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7193 {
7194 s = options[opt_idx].shortname;
7195 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7196 break;
7197 s = NULL;
7198 }
7199 }
7200 if (s == NULL)
7201 opt_idx = -1;
7202 return opt_idx;
7203}
7204
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007205#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206/*
7207 * Get the value for an option.
7208 *
7209 * Returns:
7210 * Number or Toggle option: 1, *numval gets value.
7211 * String option: 0, *stringval gets allocated string.
7212 * Hidden Number or Toggle option: -1.
7213 * hidden String option: -2.
7214 * unknown option: -3.
7215 */
7216 int
7217get_option_value(name, numval, stringval, opt_flags)
7218 char_u *name;
7219 long *numval;
7220 char_u **stringval; /* NULL when only checking existance */
7221 int opt_flags;
7222{
7223 int opt_idx;
7224 char_u *varp;
7225
7226 opt_idx = findoption(name);
7227 if (opt_idx < 0) /* unknown option */
7228 return -3;
7229
7230 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7231
7232 if (options[opt_idx].flags & P_STRING)
7233 {
7234 if (varp == NULL) /* hidden option */
7235 return -2;
7236 if (stringval != NULL)
7237 {
7238#ifdef FEAT_CRYPT
7239 /* never return the value of the crypt key */
7240 if ((char_u **)varp == &curbuf->b_p_key)
7241 *stringval = vim_strsave((char_u *)"*****");
7242 else
7243#endif
7244 *stringval = vim_strsave(*(char_u **)(varp));
7245 }
7246 return 0;
7247 }
7248
7249 if (varp == NULL) /* hidden option */
7250 return -1;
7251 if (options[opt_idx].flags & P_NUM)
7252 *numval = *(long *)varp;
7253 else
7254 {
7255 /* Special case: 'modified' is b_changed, but we also want to consider
7256 * it set when 'ff' or 'fenc' changed. */
7257 if ((int *)varp == &curbuf->b_changed)
7258 *numval = curbufIsChanged();
7259 else
7260 *numval = *(int *)varp;
7261 }
7262 return 1;
7263}
7264#endif
7265
7266/*
7267 * Set the value of option "name".
7268 * Use "string" for string options, use "number" for other options.
7269 */
7270 void
7271set_option_value(name, number, string, opt_flags)
7272 char_u *name;
7273 long number;
7274 char_u *string;
7275 int opt_flags; /* OPT_LOCAL or 0 (both) */
7276{
7277 int opt_idx;
7278 char_u *varp;
7279 int flags;
7280
7281 opt_idx = findoption(name);
7282 if (opt_idx == -1)
7283 EMSG2(_("E355: Unknown option: %s"), name);
7284 else
7285 {
7286 flags = options[opt_idx].flags;
7287#ifdef HAVE_SANDBOX
7288 /* Disallow changing some options in the sandbox */
7289 if (sandbox > 0 && (flags & P_SECURE))
7290 EMSG(_(e_sandbox));
7291 else
7292#endif
7293 if (flags & P_STRING)
7294 set_string_option(opt_idx, string, opt_flags);
7295 else
7296 {
7297 varp = get_varp(&options[opt_idx]);
7298 if (varp != NULL) /* hidden option is not changed */
7299 {
7300 if (flags & P_NUM)
7301 (void)set_num_option(opt_idx, varp, number, NULL, opt_flags);
7302 else
7303 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7304 }
7305 }
7306 }
7307}
7308
7309/*
7310 * Get the terminal code for a terminal option.
7311 * Returns NULL when not found.
7312 */
7313 char_u *
7314get_term_code(tname)
7315 char_u *tname;
7316{
7317 int opt_idx;
7318 char_u *varp;
7319
7320 if (tname[0] != 't' || tname[1] != '_' ||
7321 tname[2] == NUL || tname[3] == NUL)
7322 return NULL;
7323 if ((opt_idx = findoption(tname)) >= 0)
7324 {
7325 varp = get_varp(&(options[opt_idx]));
7326 if (varp != NULL)
7327 varp = *(char_u **)(varp);
7328 return varp;
7329 }
7330 return find_termcode(tname + 2);
7331}
7332
7333 char_u *
7334get_highlight_default()
7335{
7336 int i;
7337
7338 i = findoption((char_u *)"hl");
7339 if (i >= 0)
7340 return options[i].def_val[VI_DEFAULT];
7341 return (char_u *)NULL;
7342}
7343
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007344#if defined(FEAT_MBYTE) || defined(PROTO)
7345 char_u *
7346get_encoding_default()
7347{
7348 int i;
7349
7350 i = findoption((char_u *)"enc");
7351 if (i >= 0)
7352 return options[i].def_val[VI_DEFAULT];
7353 return (char_u *)NULL;
7354}
7355#endif
7356
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357/*
7358 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7359 */
7360 static int
7361find_key_option(arg)
7362 char_u *arg;
7363{
7364 int key;
7365 int modifiers;
7366
7367 /*
7368 * Don't use get_special_key_code() for t_xx, we don't want it to call
7369 * add_termcap_entry().
7370 */
7371 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7372 key = TERMCAP2KEY(arg[2], arg[3]);
7373 else
7374 {
7375 --arg; /* put arg at the '<' */
7376 modifiers = 0;
7377 key = find_special_key(&arg, &modifiers, TRUE);
7378 if (modifiers) /* can't handle modifiers here */
7379 key = 0;
7380 }
7381 return key;
7382}
7383
7384/*
7385 * if 'all' == 0: show changed options
7386 * if 'all' == 1: show all normal options
7387 * if 'all' == 2: show all terminal options
7388 */
7389 static void
7390showoptions(all, opt_flags)
7391 int all;
7392 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7393{
7394 struct vimoption *p;
7395 int col;
7396 int isterm;
7397 char_u *varp;
7398 struct vimoption **items;
7399 int item_count;
7400 int run;
7401 int row, rows;
7402 int cols;
7403 int i;
7404 int len;
7405
7406#define INC 20
7407#define GAP 3
7408
7409 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7410 PARAM_COUNT));
7411 if (items == NULL)
7412 return;
7413
7414 /* Highlight title */
7415 if (all == 2)
7416 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7417 else if (opt_flags & OPT_GLOBAL)
7418 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7419 else if (opt_flags & OPT_LOCAL)
7420 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7421 else
7422 MSG_PUTS_TITLE(_("\n--- Options ---"));
7423
7424 /*
7425 * do the loop two times:
7426 * 1. display the short items
7427 * 2. display the long items (only strings and numbers)
7428 */
7429 for (run = 1; run <= 2 && !got_int; ++run)
7430 {
7431 /*
7432 * collect the items in items[]
7433 */
7434 item_count = 0;
7435 for (p = &options[0]; p->fullname != NULL; p++)
7436 {
7437 varp = NULL;
7438 isterm = istermoption(p);
7439 if (opt_flags != 0)
7440 {
7441 if (p->indir != PV_NONE && !isterm)
7442 varp = get_varp_scope(p, opt_flags);
7443 }
7444 else
7445 varp = get_varp(p);
7446 if (varp != NULL
7447 && ((all == 2 && isterm)
7448 || (all == 1 && !isterm)
7449 || (all == 0 && !optval_default(p, varp))))
7450 {
7451 if (p->flags & P_BOOL)
7452 len = 1; /* a toggle option fits always */
7453 else
7454 {
7455 option_value2string(p, opt_flags);
7456 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7457 }
7458 if ((len <= INC - GAP && run == 1) ||
7459 (len > INC - GAP && run == 2))
7460 items[item_count++] = p;
7461 }
7462 }
7463
7464 /*
7465 * display the items
7466 */
7467 if (run == 1)
7468 {
7469 cols = (Columns + GAP - 3) / INC;
7470 if (cols == 0)
7471 cols = 1;
7472 rows = (item_count + cols - 1) / cols;
7473 }
7474 else /* run == 2 */
7475 rows = item_count;
7476 for (row = 0; row < rows && !got_int; ++row)
7477 {
7478 msg_putchar('\n'); /* go to next line */
7479 if (got_int) /* 'q' typed in more */
7480 break;
7481 col = 0;
7482 for (i = row; i < item_count; i += rows)
7483 {
7484 msg_col = col; /* make columns */
7485 showoneopt(items[i], opt_flags);
7486 col += INC;
7487 }
7488 out_flush();
7489 ui_breakcheck();
7490 }
7491 }
7492 vim_free(items);
7493}
7494
7495/*
7496 * Return TRUE if option "p" has its default value.
7497 */
7498 static int
7499optval_default(p, varp)
7500 struct vimoption *p;
7501 char_u *varp;
7502{
7503 int dvi;
7504
7505 if (varp == NULL)
7506 return TRUE; /* hidden option is always at default */
7507 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7508 if (p->flags & P_NUM)
7509 return (*(long *)varp == (long)p->def_val[dvi]);
7510 if (p->flags & P_BOOL)
7511 /* the cast to long is required for Manx C */
7512 return (*(int *)varp == (int)(long)p->def_val[dvi]);
7513 /* P_STRING */
7514 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7515}
7516
7517/*
7518 * showoneopt: show the value of one option
7519 * must not be called with a hidden option!
7520 */
7521 static void
7522showoneopt(p, opt_flags)
7523 struct vimoption *p;
7524 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
7525{
7526 char_u *varp;
7527
7528 varp = get_varp_scope(p, opt_flags);
7529
7530 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7531 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7532 ? !curbufIsChanged() : !*(int *)varp))
7533 MSG_PUTS("no");
7534 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7535 MSG_PUTS("--");
7536 else
7537 MSG_PUTS(" ");
7538 MSG_PUTS(p->fullname);
7539 if (!(p->flags & P_BOOL))
7540 {
7541 msg_putchar('=');
7542 /* put value string in NameBuff */
7543 option_value2string(p, opt_flags);
7544 msg_outtrans(NameBuff);
7545 }
7546}
7547
7548/*
7549 * Write modified options as ":set" commands to a file.
7550 *
7551 * There are three values for "opt_flags":
7552 * OPT_GLOBAL: Write global option values and fresh values of
7553 * buffer-local options (used for start of a session
7554 * file).
7555 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7556 * curwin (used for a vimrc file).
7557 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
7558 * and local values for window-local options of
7559 * curwin. Local values are also written when at the
7560 * default value, because a modeline or autocommand
7561 * may have set them when doing ":edit file" and the
7562 * user has set them back at the default or fresh
7563 * value.
7564 * When "local_only" is TRUE, don't write fresh
7565 * values, only local values (for ":mkview").
7566 * (fresh value = value used for a new buffer or window for a local option).
7567 *
7568 * Return FAIL on error, OK otherwise.
7569 */
7570 int
7571makeset(fd, opt_flags, local_only)
7572 FILE *fd;
7573 int opt_flags;
7574 int local_only;
7575{
7576 struct vimoption *p;
7577 char_u *varp; /* currently used value */
7578 char_u *varp_fresh; /* local value */
7579 char_u *varp_local = NULL; /* fresh value */
7580 char *cmd;
7581 int round;
7582
7583 /*
7584 * The options that don't have a default (terminal name, columns, lines)
7585 * are never written. Terminal options are also not written.
7586 */
7587 for (p = &options[0]; !istermoption(p); p++)
7588 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7589 {
7590 /* skip global option when only doing locals */
7591 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7592 continue;
7593
7594 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
7595 * file, they are always buffer-specific. */
7596 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
7597 continue;
7598
7599 /* Global values are only written when not at the default value. */
7600 varp = get_varp_scope(p, opt_flags);
7601 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
7602 continue;
7603
7604 round = 2;
7605 if (p->indir != PV_NONE)
7606 {
7607 if (p->var == VAR_WIN)
7608 {
7609 /* skip window-local option when only doing globals */
7610 if (!(opt_flags & OPT_LOCAL))
7611 continue;
7612 /* When fresh value of window-local option is not at the
7613 * default, need to write it too. */
7614 if (!(opt_flags & OPT_GLOBAL) && !local_only)
7615 {
7616 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
7617 if (!optval_default(p, varp_fresh))
7618 {
7619 round = 1;
7620 varp_local = varp;
7621 varp = varp_fresh;
7622 }
7623 }
7624 }
7625 }
7626
7627 /* Round 1: fresh value for window-local options.
7628 * Round 2: other values */
7629 for ( ; round <= 2; varp = varp_local, ++round)
7630 {
7631 if (round == 1 || (opt_flags & OPT_GLOBAL))
7632 cmd = "set";
7633 else
7634 cmd = "setlocal";
7635
7636 if (p->flags & P_BOOL)
7637 {
7638 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
7639 return FAIL;
7640 }
7641 else if (p->flags & P_NUM)
7642 {
7643 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
7644 return FAIL;
7645 }
7646 else /* P_STRING */
7647 {
7648 /* Don't set 'syntax' and 'filetype' again if the value is
7649 * already right, avoids reloading the syntax file. */
7650 if (p->indir == PV_SYN || p->indir == PV_FT)
7651 {
7652 if (fprintf(fd, "if &%s != '%s'", p->fullname,
7653 *(char_u **)(varp)) < 0
7654 || put_eol(fd) < 0)
7655 return FAIL;
7656 }
7657 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
7658 (p->flags & P_EXPAND) != 0) == FAIL)
7659 return FAIL;
7660 if (p->indir == PV_SYN || p->indir == PV_FT)
7661 {
7662 if (put_line(fd, "endif") == FAIL)
7663 return FAIL;
7664 }
7665 }
7666 }
7667 }
7668 return OK;
7669}
7670
7671#if defined(FEAT_FOLDING) || defined(PROTO)
7672/*
7673 * Generate set commands for the local fold options only. Used when
7674 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
7675 */
7676 int
7677makefoldset(fd)
7678 FILE *fd;
7679{
7680 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
7681# ifdef FEAT_EVAL
7682 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
7683 == FAIL
7684# endif
7685 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
7686 == FAIL
7687 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
7688 == FAIL
7689 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
7690 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
7691 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
7692 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
7693 )
7694 return FAIL;
7695
7696 return OK;
7697}
7698#endif
7699
7700 static int
7701put_setstring(fd, cmd, name, valuep, expand)
7702 FILE *fd;
7703 char *cmd;
7704 char *name;
7705 char_u **valuep;
7706 int expand;
7707{
7708 char_u *s;
7709 char_u buf[MAXPATHL];
7710
7711 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7712 return FAIL;
7713 if (*valuep != NULL)
7714 {
7715 /* Output 'pastetoggle' as key names. For other
7716 * options some characters have to be escaped with
7717 * CTRL-V or backslash */
7718 if (valuep == &p_pt)
7719 {
7720 s = *valuep;
7721 while (*s != NUL)
7722 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
7723 return FAIL;
7724 }
7725 else if (expand)
7726 {
7727 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
7728 if (put_escstr(fd, buf, 2) == FAIL)
7729 return FAIL;
7730 }
7731 else if (put_escstr(fd, *valuep, 2) == FAIL)
7732 return FAIL;
7733 }
7734 if (put_eol(fd) < 0)
7735 return FAIL;
7736 return OK;
7737}
7738
7739 static int
7740put_setnum(fd, cmd, name, valuep)
7741 FILE *fd;
7742 char *cmd;
7743 char *name;
7744 long *valuep;
7745{
7746 long wc;
7747
7748 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7749 return FAIL;
7750 if (wc_use_keyname((char_u *)valuep, &wc))
7751 {
7752 /* print 'wildchar' and 'wildcharm' as a key name */
7753 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
7754 return FAIL;
7755 }
7756 else if (fprintf(fd, "%ld", *valuep) < 0)
7757 return FAIL;
7758 if (put_eol(fd) < 0)
7759 return FAIL;
7760 return OK;
7761}
7762
7763 static int
7764put_setbool(fd, cmd, name, value)
7765 FILE *fd;
7766 char *cmd;
7767 char *name;
7768 int value;
7769{
7770 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
7771 || put_eol(fd) < 0)
7772 return FAIL;
7773 return OK;
7774}
7775
7776/*
7777 * Clear all the terminal options.
7778 * If the option has been allocated, free the memory.
7779 * Terminal options are never hidden or indirect.
7780 */
7781 void
7782clear_termoptions()
7783{
7784 struct vimoption *p;
7785
7786 /*
7787 * Reset a few things before clearing the old options. This may cause
7788 * outputting a few things that the terminal doesn't understand, but the
7789 * screen will be cleared later, so this is OK.
7790 */
7791#ifdef FEAT_MOUSE_TTY
7792 mch_setmouse(FALSE); /* switch mouse off */
7793#endif
7794#ifdef FEAT_TITLE
7795 mch_restore_title(3); /* restore window titles */
7796#endif
7797#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
7798 /* When starting the GUI close the display opened for the clipboard.
7799 * After restoring the title, because that will need the display. */
7800 if (gui.starting)
7801 clear_xterm_clip();
7802#endif
7803#ifdef WIN3264
7804 /*
7805 * Check if this is allowed now.
7806 */
7807 if (can_end_termcap_mode(FALSE) == TRUE)
7808#endif
7809 stoptermcap(); /* stop termcap mode */
7810
7811 for (p = &options[0]; p->fullname != NULL; p++)
7812 if (istermoption(p))
7813 {
7814 if (p->flags & P_ALLOCED)
7815 free_string_option(*(char_u **)(p->var));
7816 if (p->flags & P_DEF_ALLOCED)
7817 free_string_option(p->def_val[VI_DEFAULT]);
7818 *(char_u **)(p->var) = empty_option;
7819 p->def_val[VI_DEFAULT] = empty_option;
7820 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
7821 }
7822 clear_termcodes();
7823}
7824
7825/*
7826 * Set the terminal option defaults to the current value.
7827 * Used after setting the terminal name.
7828 */
7829 void
7830set_term_defaults()
7831{
7832 struct vimoption *p;
7833
7834 for (p = &options[0]; p->fullname != NULL; p++)
7835 {
7836 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
7837 {
7838 if (p->flags & P_DEF_ALLOCED)
7839 {
7840 free_string_option(p->def_val[VI_DEFAULT]);
7841 p->flags &= ~P_DEF_ALLOCED;
7842 }
7843 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
7844 if (p->flags & P_ALLOCED)
7845 {
7846 p->flags |= P_DEF_ALLOCED;
7847 p->flags &= ~P_ALLOCED; /* don't free the value now */
7848 }
7849 }
7850 }
7851}
7852
7853/*
7854 * return TRUE if 'p' starts with 't_'
7855 */
7856 static int
7857istermoption(p)
7858 struct vimoption *p;
7859{
7860 return (p->fullname[0] == 't' && p->fullname[1] == '_');
7861}
7862
7863/*
7864 * Compute columns for ruler and shown command. 'sc_col' is also used to
7865 * decide what the maximum length of a message on the status line can be.
7866 * If there is a status line for the last window, 'sc_col' is independent
7867 * of 'ru_col'.
7868 */
7869
7870#define COL_RULER 17 /* columns needed by standard ruler */
7871
7872 void
7873comp_col()
7874{
7875#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
7876 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
7877
7878 sc_col = 0;
7879 ru_col = 0;
7880 if (p_ru)
7881 {
7882#ifdef FEAT_STL_OPT
7883 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
7884#else
7885 ru_col = COL_RULER + 1;
7886#endif
7887 /* no last status line, adjust sc_col */
7888 if (!last_has_status)
7889 sc_col = ru_col;
7890 }
7891 if (p_sc)
7892 {
7893 sc_col += SHOWCMD_COLS;
7894 if (!p_ru || last_has_status) /* no need for separating space */
7895 ++sc_col;
7896 }
7897 sc_col = Columns - sc_col;
7898 ru_col = Columns - ru_col;
7899 if (sc_col <= 0) /* screen too narrow, will become a mess */
7900 sc_col = 1;
7901 if (ru_col <= 0)
7902 ru_col = 1;
7903#else
7904 sc_col = Columns;
7905 ru_col = Columns;
7906#endif
7907}
7908
7909/*
7910 * Get pointer to option variable, depending on local or global scope.
7911 */
7912 static char_u *
7913get_varp_scope(p, opt_flags)
7914 struct vimoption *p;
7915 int opt_flags;
7916{
7917 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
7918 {
7919 if (p->var == VAR_WIN)
7920 return (char_u *)GLOBAL_WO(get_varp(p));
7921 return p->var;
7922 }
7923 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
7924 {
7925 switch ((int)p->indir)
7926 {
7927#ifdef FEAT_QUICKFIX
7928 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
7929 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
7930 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
7931#endif
7932 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
7933 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
7934 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
7935 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
7936 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
7937#ifdef FEAT_FIND_ID
7938 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
7939 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
7940#endif
7941#ifdef FEAT_INS_EXPAND
7942 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
7943 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
7944#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007945#ifdef FEAT_STL_OPT
7946 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
7947#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007948 }
7949 return NULL; /* "cannot happen" */
7950 }
7951 return get_varp(p);
7952}
7953
7954/*
7955 * Get pointer to option variable.
7956 */
7957 static char_u *
7958get_varp(p)
7959 struct vimoption *p;
7960{
7961 /* hidden option, always return NULL */
7962 if (p->var == NULL)
7963 return NULL;
7964
7965 switch ((int)p->indir)
7966 {
7967 case PV_NONE: return p->var;
7968
7969 /* global option with local value: use local value if it's been set */
7970 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
7971 ? (char_u *)&curbuf->b_p_ep : p->var;
7972 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
7973 ? (char_u *)&curbuf->b_p_kp : p->var;
7974 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
7975 ? (char_u *)&(curbuf->b_p_path) : p->var;
7976 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
7977 ? (char_u *)&(curbuf->b_p_ar) : p->var;
7978 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
7979 ? (char_u *)&(curbuf->b_p_tags) : p->var;
7980#ifdef FEAT_FIND_ID
7981 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
7982 ? (char_u *)&(curbuf->b_p_def) : p->var;
7983 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
7984 ? (char_u *)&(curbuf->b_p_inc) : p->var;
7985#endif
7986#ifdef FEAT_INS_EXPAND
7987 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
7988 ? (char_u *)&(curbuf->b_p_dict) : p->var;
7989 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
7990 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
7991#endif
7992#ifdef FEAT_QUICKFIX
7993 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
7994 ? (char_u *)&(curbuf->b_p_gp) : p->var;
7995 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
7996 ? (char_u *)&(curbuf->b_p_mp) : p->var;
7997 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
7998 ? (char_u *)&(curbuf->b_p_efm) : p->var;
7999#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008000#ifdef FEAT_STL_OPT
8001 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8002 ? (char_u *)&(curwin->w_p_stl) : p->var;
8003#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004
8005#ifdef FEAT_ARABIC
8006 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8007#endif
8008 case PV_LIST: return (char_u *)&(curwin->w_p_list);
8009#ifdef FEAT_DIFF
8010 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8011#endif
8012#ifdef FEAT_FOLDING
8013 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8014 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8015 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8016 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8017 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8018 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8019 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8020# ifdef FEAT_EVAL
8021 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8022 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8023# endif
8024 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8025#endif
8026 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008027#ifdef FEAT_LINEBREAK
8028 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8029#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030#if defined(FEAT_WINDOWS)
8031 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8032#endif
8033#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8034 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8035#endif
8036#ifdef FEAT_RIGHTLEFT
8037 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8038 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8039#endif
8040 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8041 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8042#ifdef FEAT_LINEBREAK
8043 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8044#endif
8045#ifdef FEAT_SCROLLBIND
8046 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8047#endif
8048
8049 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8050 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8051#ifdef FEAT_MBYTE
8052 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8053#endif
8054#if defined(FEAT_QUICKFIX)
8055 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8056 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8057#endif
8058 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8059 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8060#ifdef FEAT_CINDENT
8061 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8062 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8063 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8064#endif
8065#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8066 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8067#endif
8068#ifdef FEAT_COMMENTS
8069 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8070#endif
8071#ifdef FEAT_FOLDING
8072 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8073#endif
8074#ifdef FEAT_INS_EXPAND
8075 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8076#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008077#ifdef FEAT_COMPL_FUNC
8078 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
8079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008080 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8081 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8082#ifdef FEAT_MBYTE
8083 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8084#endif
8085 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8086#ifdef FEAT_AUTOCMD
8087 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8088#endif
8089 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008090 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8092 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8093 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8094 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8095#ifdef FEAT_FIND_ID
8096# ifdef FEAT_EVAL
8097 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8098# endif
8099#endif
8100#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8101 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8102 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8103#endif
8104#ifdef FEAT_CRYPT
8105 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8106#endif
8107#ifdef FEAT_LISP
8108 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8109#endif
8110 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8111 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8112 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8113 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8114 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8115#ifdef FEAT_OSFILETYPE
8116 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8117#endif
8118 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008119#ifdef FEAT_TEXTOBJ
8120 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8121#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8123#ifdef FEAT_SMARTINDENT
8124 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8125#endif
8126#ifndef SHORT_FNAME
8127 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8128#endif
8129 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8130#ifdef FEAT_SEARCHPATH
8131 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8132#endif
8133 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8134#ifdef FEAT_SYN_HL
8135 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
8136#endif
8137 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8138 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8139 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8140 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8141 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8142#ifdef FEAT_KEYMAP
8143 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8144#endif
8145 default: EMSG(_("E356: get_varp ERROR"));
8146 }
8147 /* always return a valid pointer to avoid a crash! */
8148 return (char_u *)&(curbuf->b_p_wm);
8149}
8150
8151/*
8152 * Get the value of 'equalprg', either the buffer-local one or the global one.
8153 */
8154 char_u *
8155get_equalprg()
8156{
8157 if (*curbuf->b_p_ep == NUL)
8158 return p_ep;
8159 return curbuf->b_p_ep;
8160}
8161
8162#if defined(FEAT_WINDOWS) || defined(PROTO)
8163/*
8164 * Copy options from one window to another.
8165 * Used when splitting a window.
8166 */
8167 void
8168win_copy_options(wp_from, wp_to)
8169 win_T *wp_from;
8170 win_T *wp_to;
8171{
8172 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8173 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8174# ifdef FEAT_RIGHTLEFT
8175# ifdef FEAT_FKMAP
8176 /* Is this right? */
8177 wp_to->w_farsi = wp_from->w_farsi;
8178# endif
8179# endif
8180}
8181#endif
8182
8183/*
8184 * Copy the options from one winopt_T to another.
8185 * Doesn't free the old option values in "to", use clear_winopt() for that.
8186 * The 'scroll' option is not copied, because it depends on the window height.
8187 * The 'previewwindow' option is reset, there can be only one preview window.
8188 */
8189 void
8190copy_winopt(from, to)
8191 winopt_T *from;
8192 winopt_T *to;
8193{
8194#ifdef FEAT_ARABIC
8195 to->wo_arab = from->wo_arab;
8196#endif
8197 to->wo_list = from->wo_list;
8198 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008199#ifdef FEAT_LINEBREAK
8200 to->wo_nuw = from->wo_nuw;
8201#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202#ifdef FEAT_RIGHTLEFT
8203 to->wo_rl = from->wo_rl;
8204 to->wo_rlc = vim_strsave(from->wo_rlc);
8205#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008206#ifdef FEAT_STL_OPT
8207 to->wo_stl = vim_strsave(from->wo_stl);
8208#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 to->wo_wrap = from->wo_wrap;
8210#ifdef FEAT_LINEBREAK
8211 to->wo_lbr = from->wo_lbr;
8212#endif
8213#ifdef FEAT_SCROLLBIND
8214 to->wo_scb = from->wo_scb;
8215#endif
8216#ifdef FEAT_DIFF
8217 to->wo_diff = from->wo_diff;
8218#endif
8219#ifdef FEAT_FOLDING
8220 to->wo_fdc = from->wo_fdc;
8221 to->wo_fen = from->wo_fen;
8222 to->wo_fdi = vim_strsave(from->wo_fdi);
8223 to->wo_fml = from->wo_fml;
8224 to->wo_fdl = from->wo_fdl;
8225 to->wo_fdm = vim_strsave(from->wo_fdm);
8226 to->wo_fdn = from->wo_fdn;
8227# ifdef FEAT_EVAL
8228 to->wo_fde = vim_strsave(from->wo_fde);
8229 to->wo_fdt = vim_strsave(from->wo_fdt);
8230# endif
8231 to->wo_fmr = vim_strsave(from->wo_fmr);
8232#endif
8233 check_winopt(to); /* don't want NULL pointers */
8234}
8235
8236/*
8237 * Check string options in a window for a NULL value.
8238 */
8239 void
8240check_win_options(win)
8241 win_T *win;
8242{
8243 check_winopt(&win->w_onebuf_opt);
8244 check_winopt(&win->w_allbuf_opt);
8245}
8246
8247/*
8248 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8249 */
8250/*ARGSUSED*/
8251 void
8252check_winopt(wop)
8253 winopt_T *wop;
8254{
8255#ifdef FEAT_FOLDING
8256 check_string_option(&wop->wo_fdi);
8257 check_string_option(&wop->wo_fdm);
8258# ifdef FEAT_EVAL
8259 check_string_option(&wop->wo_fde);
8260 check_string_option(&wop->wo_fdt);
8261# endif
8262 check_string_option(&wop->wo_fmr);
8263#endif
8264#ifdef FEAT_RIGHTLEFT
8265 check_string_option(&wop->wo_rlc);
8266#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008267#ifdef FEAT_STL_OPT
8268 check_string_option(&wop->wo_stl);
8269#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008270}
8271
8272/*
8273 * Free the allocated memory inside a winopt_T.
8274 */
8275/*ARGSUSED*/
8276 void
8277clear_winopt(wop)
8278 winopt_T *wop;
8279{
8280#ifdef FEAT_FOLDING
8281 clear_string_option(&wop->wo_fdi);
8282 clear_string_option(&wop->wo_fdm);
8283# ifdef FEAT_EVAL
8284 clear_string_option(&wop->wo_fde);
8285 clear_string_option(&wop->wo_fdt);
8286# endif
8287 clear_string_option(&wop->wo_fmr);
8288#endif
8289#ifdef FEAT_RIGHTLEFT
8290 clear_string_option(&wop->wo_rlc);
8291#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008292#ifdef FEAT_STL_OPT
8293 clear_string_option(&wop->wo_stl);
8294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008295}
8296
8297/*
8298 * Copy global option values to local options for one buffer.
8299 * Used when creating a new buffer and sometimes when entering a buffer.
8300 * flags:
8301 * BCO_ENTER We will enter the buf buffer.
8302 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8303 * appropriate.
8304 * BCO_NOHELP Don't copy the values to a help buffer.
8305 */
8306 void
8307buf_copy_options(buf, flags)
8308 buf_T *buf;
8309 int flags;
8310{
8311 int should_copy = TRUE;
8312 char_u *save_p_isk = NULL; /* init for GCC */
8313 int dont_do_help;
8314 int did_isk = FALSE;
8315
8316 /*
8317 * Don't do anything of the buffer is invalid.
8318 */
8319 if (buf == NULL || !buf_valid(buf))
8320 return;
8321
8322 /*
8323 * Skip this when the option defaults have not been set yet. Happens when
8324 * main() allocates the first buffer.
8325 */
8326 if (p_cpo != NULL)
8327 {
8328 /*
8329 * Always copy when entering and 'cpo' contains 'S'.
8330 * Don't copy when already initialized.
8331 * Don't copy when 'cpo' contains 's' and not entering.
8332 * 'S' BCO_ENTER initialized 's' should_copy
8333 * yes yes X X TRUE
8334 * yes no yes X FALSE
8335 * no X yes X FALSE
8336 * X no no yes FALSE
8337 * X no no no TRUE
8338 * no yes no X TRUE
8339 */
8340 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8341 && (buf->b_p_initialized
8342 || (!(flags & BCO_ENTER)
8343 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8344 should_copy = FALSE;
8345
8346 if (should_copy || (flags & BCO_ALWAYS))
8347 {
8348 /* Don't copy the options specific to a help buffer when
8349 * BCO_NOHELP is given or the options were initialized already
8350 * (jumping back to a help file with CTRL-T or CTRL-O) */
8351 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8352 || buf->b_p_initialized;
8353 if (dont_do_help) /* don't free b_p_isk */
8354 {
8355 save_p_isk = buf->b_p_isk;
8356 buf->b_p_isk = NULL;
8357 }
8358 /*
8359 * Always free the allocated strings.
8360 * If not already initialized, set 'readonly' and copy 'fileformat'.
8361 */
8362 if (!buf->b_p_initialized)
8363 {
8364 free_buf_options(buf, TRUE);
8365 buf->b_p_ro = FALSE; /* don't copy readonly */
8366 buf->b_p_tx = p_tx;
8367#ifdef FEAT_MBYTE
8368 buf->b_p_fenc = vim_strsave(p_fenc);
8369#endif
8370 buf->b_p_ff = vim_strsave(p_ff);
8371#if defined(FEAT_QUICKFIX)
8372 buf->b_p_bh = empty_option;
8373 buf->b_p_bt = empty_option;
8374#endif
8375 }
8376 else
8377 free_buf_options(buf, FALSE);
8378
8379 buf->b_p_ai = p_ai;
8380 buf->b_p_ai_nopaste = p_ai_nopaste;
8381 buf->b_p_sw = p_sw;
8382 buf->b_p_tw = p_tw;
8383 buf->b_p_tw_nopaste = p_tw_nopaste;
8384 buf->b_p_tw_nobin = p_tw_nobin;
8385 buf->b_p_wm = p_wm;
8386 buf->b_p_wm_nopaste = p_wm_nopaste;
8387 buf->b_p_wm_nobin = p_wm_nobin;
8388 buf->b_p_bin = p_bin;
8389 buf->b_p_et = p_et;
8390 buf->b_p_et_nobin = p_et_nobin;
8391 buf->b_p_ml = p_ml;
8392 buf->b_p_ml_nobin = p_ml_nobin;
8393 buf->b_p_inf = p_inf;
8394 buf->b_p_swf = p_swf;
8395#ifdef FEAT_INS_EXPAND
8396 buf->b_p_cpt = vim_strsave(p_cpt);
8397#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008398#ifdef FEAT_COMPL_FUNC
8399 buf->b_p_cfu = vim_strsave(p_cfu);
8400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401 buf->b_p_sts = p_sts;
8402 buf->b_p_sts_nopaste = p_sts_nopaste;
8403#ifndef SHORT_FNAME
8404 buf->b_p_sn = p_sn;
8405#endif
8406#ifdef FEAT_COMMENTS
8407 buf->b_p_com = vim_strsave(p_com);
8408#endif
8409#ifdef FEAT_FOLDING
8410 buf->b_p_cms = vim_strsave(p_cms);
8411#endif
8412 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008413 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414 buf->b_p_nf = vim_strsave(p_nf);
8415 buf->b_p_mps = vim_strsave(p_mps);
8416#ifdef FEAT_SMARTINDENT
8417 buf->b_p_si = p_si;
8418#endif
8419 buf->b_p_ci = p_ci;
8420#ifdef FEAT_CINDENT
8421 buf->b_p_cin = p_cin;
8422 buf->b_p_cink = vim_strsave(p_cink);
8423 buf->b_p_cino = vim_strsave(p_cino);
8424#endif
8425#ifdef FEAT_AUTOCMD
8426 /* Don't copy 'filetype', it must be detected */
8427 buf->b_p_ft = empty_option;
8428#endif
8429#ifdef FEAT_OSFILETYPE
8430 buf->b_p_oft = vim_strsave(p_oft);
8431#endif
8432 buf->b_p_pi = p_pi;
8433#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8434 buf->b_p_cinw = vim_strsave(p_cinw);
8435#endif
8436#ifdef FEAT_LISP
8437 buf->b_p_lisp = p_lisp;
8438#endif
8439#ifdef FEAT_SYN_HL
8440 /* Don't copy 'syntax', it must be set */
8441 buf->b_p_syn = empty_option;
8442#endif
8443#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8444 buf->b_p_inde = vim_strsave(p_inde);
8445 buf->b_p_indk = vim_strsave(p_indk);
8446#endif
8447#ifdef FEAT_CRYPT
8448 buf->b_p_key = vim_strsave(p_key);
8449#endif
8450#ifdef FEAT_SEARCHPATH
8451 buf->b_p_sua = vim_strsave(p_sua);
8452#endif
8453#ifdef FEAT_KEYMAP
8454 buf->b_p_keymap = vim_strsave(p_keymap);
8455 buf->b_kmap_state |= KEYMAP_INIT;
8456#endif
8457 /* This isn't really an option, but copying the langmap and IME
8458 * state from the current buffer is better than resetting it. */
8459 buf->b_p_iminsert = p_iminsert;
8460 buf->b_p_imsearch = p_imsearch;
8461
8462 /* options that are normally global but also have a local value
8463 * are not copied, start using the global value */
8464 buf->b_p_ar = -1;
8465#ifdef FEAT_QUICKFIX
8466 buf->b_p_gp = empty_option;
8467 buf->b_p_mp = empty_option;
8468 buf->b_p_efm = empty_option;
8469#endif
8470 buf->b_p_ep = empty_option;
8471 buf->b_p_kp = empty_option;
8472 buf->b_p_path = empty_option;
8473 buf->b_p_tags = empty_option;
8474#ifdef FEAT_FIND_ID
8475 buf->b_p_def = empty_option;
8476 buf->b_p_inc = empty_option;
8477# ifdef FEAT_EVAL
8478 buf->b_p_inex = vim_strsave(p_inex);
8479# endif
8480#endif
8481#ifdef FEAT_INS_EXPAND
8482 buf->b_p_dict = empty_option;
8483 buf->b_p_tsr = empty_option;
8484#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008485#ifdef FEAT_TEXTOBJ
8486 buf->b_p_qe = vim_strsave(p_qe);
8487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008488
8489 /*
8490 * Don't copy the options set by ex_help(), use the saved values,
8491 * when going from a help buffer to a non-help buffer.
8492 * Don't touch these at all when BCO_NOHELP is used and going from
8493 * or to a help buffer.
8494 */
8495 if (dont_do_help)
8496 buf->b_p_isk = save_p_isk;
8497 else
8498 {
8499 buf->b_p_isk = vim_strsave(p_isk);
8500 did_isk = TRUE;
8501 buf->b_p_ts = p_ts;
8502 buf->b_help = FALSE;
8503#ifdef FEAT_QUICKFIX
8504 if (buf->b_p_bt[0] == 'h')
8505 clear_string_option(&buf->b_p_bt);
8506#endif
8507 buf->b_p_ma = p_ma;
8508 }
8509 }
8510
8511 /*
8512 * When the options should be copied (ignoring BCO_ALWAYS), set the
8513 * flag that indicates that the options have been initialized.
8514 */
8515 if (should_copy)
8516 buf->b_p_initialized = TRUE;
8517 }
8518
8519 check_buf_options(buf); /* make sure we don't have NULLs */
8520 if (did_isk)
8521 (void)buf_init_chartab(buf, FALSE);
8522}
8523
8524/*
8525 * Reset the 'modifiable' option and its default value.
8526 */
8527 void
8528reset_modifiable()
8529{
8530 int opt_idx;
8531
8532 curbuf->b_p_ma = FALSE;
8533 p_ma = FALSE;
8534 opt_idx = findoption((char_u *)"ma");
8535 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8536}
8537
8538/*
8539 * Set the global value for 'iminsert' to the local value.
8540 */
8541 void
8542set_iminsert_global()
8543{
8544 p_iminsert = curbuf->b_p_iminsert;
8545}
8546
8547/*
8548 * Set the global value for 'imsearch' to the local value.
8549 */
8550 void
8551set_imsearch_global()
8552{
8553 p_imsearch = curbuf->b_p_imsearch;
8554}
8555
8556#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8557static int expand_option_idx = -1;
8558static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8559static int expand_option_flags = 0;
8560
8561 void
8562set_context_in_set_cmd(xp, arg, opt_flags)
8563 expand_T *xp;
8564 char_u *arg;
8565 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8566{
8567 int nextchar;
8568 long_u flags = 0; /* init for GCC */
8569 int opt_idx = 0; /* init for GCC */
8570 char_u *p;
8571 char_u *s;
8572 int is_term_option = FALSE;
8573 int key;
8574
8575 expand_option_flags = opt_flags;
8576
8577 xp->xp_context = EXPAND_SETTINGS;
8578 if (*arg == NUL)
8579 {
8580 xp->xp_pattern = arg;
8581 return;
8582 }
8583 p = arg + STRLEN(arg) - 1;
8584 if (*p == ' ' && *(p - 1) != '\\')
8585 {
8586 xp->xp_pattern = p + 1;
8587 return;
8588 }
8589 while (p > arg)
8590 {
8591 s = p;
8592 /* count number of backslashes before ' ' or ',' */
8593 if (*p == ' ' || *p == ',')
8594 {
8595 while (s > arg && *(s - 1) == '\\')
8596 --s;
8597 }
8598 /* break at a space with an even number of backslashes */
8599 if (*p == ' ' && ((p - s) & 1) == 0)
8600 {
8601 ++p;
8602 break;
8603 }
8604 --p;
8605 }
8606 if (STRNCMP(p, "no", 2) == 0)
8607 {
8608 xp->xp_context = EXPAND_BOOL_SETTINGS;
8609 p += 2;
8610 }
8611 if (STRNCMP(p, "inv", 3) == 0)
8612 {
8613 xp->xp_context = EXPAND_BOOL_SETTINGS;
8614 p += 3;
8615 }
8616 xp->xp_pattern = arg = p;
8617 if (*arg == '<')
8618 {
8619 while (*p != '>')
8620 if (*p++ == NUL) /* expand terminal option name */
8621 return;
8622 key = get_special_key_code(arg + 1);
8623 if (key == 0) /* unknown name */
8624 {
8625 xp->xp_context = EXPAND_NOTHING;
8626 return;
8627 }
8628 nextchar = *++p;
8629 is_term_option = TRUE;
8630 expand_option_name[2] = KEY2TERMCAP0(key);
8631 expand_option_name[3] = KEY2TERMCAP1(key);
8632 }
8633 else
8634 {
8635 if (p[0] == 't' && p[1] == '_')
8636 {
8637 p += 2;
8638 if (*p != NUL)
8639 ++p;
8640 if (*p == NUL)
8641 return; /* expand option name */
8642 nextchar = *++p;
8643 is_term_option = TRUE;
8644 expand_option_name[2] = p[-2];
8645 expand_option_name[3] = p[-1];
8646 }
8647 else
8648 {
8649 /* Allow * wildcard */
8650 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
8651 p++;
8652 if (*p == NUL)
8653 return;
8654 nextchar = *p;
8655 *p = NUL;
8656 opt_idx = findoption(arg);
8657 *p = nextchar;
8658 if (opt_idx == -1 || options[opt_idx].var == NULL)
8659 {
8660 xp->xp_context = EXPAND_NOTHING;
8661 return;
8662 }
8663 flags = options[opt_idx].flags;
8664 if (flags & P_BOOL)
8665 {
8666 xp->xp_context = EXPAND_NOTHING;
8667 return;
8668 }
8669 }
8670 }
8671 /* handle "-=" and "+=" */
8672 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
8673 {
8674 ++p;
8675 nextchar = '=';
8676 }
8677 if ((nextchar != '=' && nextchar != ':')
8678 || xp->xp_context == EXPAND_BOOL_SETTINGS)
8679 {
8680 xp->xp_context = EXPAND_UNSUCCESSFUL;
8681 return;
8682 }
8683 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
8684 {
8685 xp->xp_context = EXPAND_OLD_SETTING;
8686 if (is_term_option)
8687 expand_option_idx = -1;
8688 else
8689 expand_option_idx = opt_idx;
8690 xp->xp_pattern = p + 1;
8691 return;
8692 }
8693 xp->xp_context = EXPAND_NOTHING;
8694 if (is_term_option || (flags & P_NUM))
8695 return;
8696
8697 xp->xp_pattern = p + 1;
8698
8699 if (flags & P_EXPAND)
8700 {
8701 p = options[opt_idx].var;
8702 if (p == (char_u *)&p_bdir
8703 || p == (char_u *)&p_dir
8704 || p == (char_u *)&p_path
8705 || p == (char_u *)&p_rtp
8706#ifdef FEAT_SEARCHPATH
8707 || p == (char_u *)&p_cdpath
8708#endif
8709#ifdef FEAT_SESSION
8710 || p == (char_u *)&p_vdir
8711#endif
8712 )
8713 {
8714 xp->xp_context = EXPAND_DIRECTORIES;
8715 if (p == (char_u *)&p_path
8716#ifdef FEAT_SEARCHPATH
8717 || p == (char_u *)&p_cdpath
8718#endif
8719 )
8720 xp->xp_backslash = XP_BS_THREE;
8721 else
8722 xp->xp_backslash = XP_BS_ONE;
8723 }
8724 else
8725 {
8726 xp->xp_context = EXPAND_FILES;
8727 /* for 'tags' need three backslashes for a space */
8728 if (p == (char_u *)&p_tags)
8729 xp->xp_backslash = XP_BS_THREE;
8730 else
8731 xp->xp_backslash = XP_BS_ONE;
8732 }
8733 }
8734
8735 /* For an option that is a list of file names, find the start of the
8736 * last file name. */
8737 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
8738 {
8739 /* count number of backslashes before ' ' or ',' */
8740 if (*p == ' ' || *p == ',')
8741 {
8742 s = p;
8743 while (s > xp->xp_pattern && *(s - 1) == '\\')
8744 --s;
8745 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
8746 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
8747 {
8748 xp->xp_pattern = p + 1;
8749 break;
8750 }
8751 }
8752 }
8753
8754 return;
8755}
8756
8757 int
8758ExpandSettings(xp, regmatch, num_file, file)
8759 expand_T *xp;
8760 regmatch_T *regmatch;
8761 int *num_file;
8762 char_u ***file;
8763{
8764 int num_normal = 0; /* Nr of matching non-term-code settings */
8765 int num_term = 0; /* Nr of matching terminal code settings */
8766 int opt_idx;
8767 int match;
8768 int count = 0;
8769 char_u *str;
8770 int loop;
8771 int is_term_opt;
8772 char_u name_buf[MAX_KEY_NAME_LEN];
8773 static char *(names[]) = {"all", "termcap"};
8774 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
8775
8776 /* do this loop twice:
8777 * loop == 0: count the number of matching options
8778 * loop == 1: copy the matching options into allocated memory
8779 */
8780 for (loop = 0; loop <= 1; ++loop)
8781 {
8782 regmatch->rm_ic = ic;
8783 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
8784 {
8785 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
8786 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
8787 {
8788 if (loop == 0)
8789 num_normal++;
8790 else
8791 (*file)[count++] = vim_strsave((char_u *)names[match]);
8792 }
8793 }
8794 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
8795 opt_idx++)
8796 {
8797 if (options[opt_idx].var == NULL)
8798 continue;
8799 if (xp->xp_context == EXPAND_BOOL_SETTINGS
8800 && !(options[opt_idx].flags & P_BOOL))
8801 continue;
8802 is_term_opt = istermoption(&options[opt_idx]);
8803 if (is_term_opt && num_normal > 0)
8804 continue;
8805 match = FALSE;
8806 if (vim_regexec(regmatch, str, (colnr_T)0)
8807 || (options[opt_idx].shortname != NULL
8808 && vim_regexec(regmatch,
8809 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
8810 match = TRUE;
8811 else if (is_term_opt)
8812 {
8813 name_buf[0] = '<';
8814 name_buf[1] = 't';
8815 name_buf[2] = '_';
8816 name_buf[3] = str[2];
8817 name_buf[4] = str[3];
8818 name_buf[5] = '>';
8819 name_buf[6] = NUL;
8820 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8821 {
8822 match = TRUE;
8823 str = name_buf;
8824 }
8825 }
8826 if (match)
8827 {
8828 if (loop == 0)
8829 {
8830 if (is_term_opt)
8831 num_term++;
8832 else
8833 num_normal++;
8834 }
8835 else
8836 (*file)[count++] = vim_strsave(str);
8837 }
8838 }
8839 /*
8840 * Check terminal key codes, these are not in the option table
8841 */
8842 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
8843 {
8844 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
8845 {
8846 if (!isprint(str[0]) || !isprint(str[1]))
8847 continue;
8848
8849 name_buf[0] = 't';
8850 name_buf[1] = '_';
8851 name_buf[2] = str[0];
8852 name_buf[3] = str[1];
8853 name_buf[4] = NUL;
8854
8855 match = FALSE;
8856 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8857 match = TRUE;
8858 else
8859 {
8860 name_buf[0] = '<';
8861 name_buf[1] = 't';
8862 name_buf[2] = '_';
8863 name_buf[3] = str[0];
8864 name_buf[4] = str[1];
8865 name_buf[5] = '>';
8866 name_buf[6] = NUL;
8867
8868 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8869 match = TRUE;
8870 }
8871 if (match)
8872 {
8873 if (loop == 0)
8874 num_term++;
8875 else
8876 (*file)[count++] = vim_strsave(name_buf);
8877 }
8878 }
8879
8880 /*
8881 * Check special key names.
8882 */
8883 regmatch->rm_ic = TRUE; /* ignore case here */
8884 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
8885 {
8886 name_buf[0] = '<';
8887 STRCPY(name_buf + 1, str);
8888 STRCAT(name_buf, ">");
8889
8890 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8891 {
8892 if (loop == 0)
8893 num_term++;
8894 else
8895 (*file)[count++] = vim_strsave(name_buf);
8896 }
8897 }
8898 }
8899 if (loop == 0)
8900 {
8901 if (num_normal > 0)
8902 *num_file = num_normal;
8903 else if (num_term > 0)
8904 *num_file = num_term;
8905 else
8906 return OK;
8907 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
8908 if (*file == NULL)
8909 {
8910 *file = (char_u **)"";
8911 return FAIL;
8912 }
8913 }
8914 }
8915 return OK;
8916}
8917
8918 int
8919ExpandOldSetting(num_file, file)
8920 int *num_file;
8921 char_u ***file;
8922{
8923 char_u *var = NULL; /* init for GCC */
8924 char_u *buf;
8925
8926 *num_file = 0;
8927 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
8928 if (*file == NULL)
8929 return FAIL;
8930
8931 /*
8932 * For a terminal key code expand_option_idx is < 0.
8933 */
8934 if (expand_option_idx < 0)
8935 {
8936 var = find_termcode(expand_option_name + 2);
8937 if (var == NULL)
8938 expand_option_idx = findoption(expand_option_name);
8939 }
8940
8941 if (expand_option_idx >= 0)
8942 {
8943 /* put string of option value in NameBuff */
8944 option_value2string(&options[expand_option_idx], expand_option_flags);
8945 var = NameBuff;
8946 }
8947 else if (var == NULL)
8948 var = (char_u *)"";
8949
8950 /* A backslash is required before some characters. This is the reverse of
8951 * what happens in do_set(). */
8952 buf = vim_strsave_escaped(var, escape_chars);
8953
8954 if (buf == NULL)
8955 {
8956 vim_free(*file);
8957 *file = NULL;
8958 return FAIL;
8959 }
8960
8961#ifdef BACKSLASH_IN_FILENAME
8962 /* For MS-Windows et al. we don't double backslashes at the start and
8963 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008964 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 if (var[0] == '\\' && var[1] == '\\'
8966 && expand_option_idx >= 0
8967 && (options[expand_option_idx].flags & P_EXPAND)
8968 && vim_isfilec(var[2])
8969 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
8970 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00008971#endif
8972
8973 *file[0] = buf;
8974 *num_file = 1;
8975 return OK;
8976}
8977#endif
8978
8979/*
8980 * Get the value for the numeric or string option *opp in a nice format into
8981 * NameBuff[]. Must not be called with a hidden option!
8982 */
8983 static void
8984option_value2string(opp, opt_flags)
8985 struct vimoption *opp;
8986 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8987{
8988 char_u *varp;
8989
8990 varp = get_varp_scope(opp, opt_flags);
8991
8992 if (opp->flags & P_NUM)
8993 {
8994 long wc = 0;
8995
8996 if (wc_use_keyname(varp, &wc))
8997 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
8998 else if (wc != 0)
8999 STRCPY(NameBuff, transchar((int)wc));
9000 else
9001 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9002 }
9003 else /* P_STRING */
9004 {
9005 varp = *(char_u **)(varp);
9006 if (varp == NULL) /* just in case */
9007 NameBuff[0] = NUL;
9008#ifdef FEAT_CRYPT
9009 /* don't show the actual value of 'key', only that it's set */
9010 if (opp->var == (char_u *)&p_key && *varp)
9011 STRCPY(NameBuff, "*****");
9012#endif
9013 else if (opp->flags & P_EXPAND)
9014 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9015 /* Translate 'pastetoggle' into special key names */
9016 else if ((char_u **)opp->var == &p_pt)
9017 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9018 else
9019 STRNCPY(NameBuff, varp, MAXPATHL);
9020 }
9021}
9022
9023/*
9024 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9025 * printed as a keyname.
9026 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9027 */
9028 static int
9029wc_use_keyname(varp, wcp)
9030 char_u *varp;
9031 long *wcp;
9032{
9033 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9034 {
9035 *wcp = *(long *)varp;
9036 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9037 return TRUE;
9038 }
9039 return FALSE;
9040}
9041
9042#ifdef FEAT_LANGMAP
9043/*
9044 * Any character has an equivalent character. This is used for keyboards that
9045 * have a special language mode that sends characters above 128 (although
9046 * other characters can be translated too).
9047 */
9048
9049/*
9050 * char_u langmap_mapchar[256];
9051 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9052 * "translate" native lang chars in normal mode or some cases of
9053 * insert mode without having to tediously switch lang mode back&forth.
9054 */
9055
9056 static void
9057langmap_init()
9058{
9059 int i;
9060
9061 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9062 langmap_mapchar[i] = i;
9063}
9064
9065/*
9066 * Called when langmap option is set; the language map can be
9067 * changed at any time!
9068 */
9069 static void
9070langmap_set()
9071{
9072 char_u *p;
9073 char_u *p2;
9074 int from, to;
9075
9076 langmap_init(); /* back to one-to-one map first */
9077
9078 for (p = p_langmap; p[0] != NUL; )
9079 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009080 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9081 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009082 {
9083 if (p2[0] == '\\' && p2[1] != NUL)
9084 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085 }
9086 if (p2[0] == ';')
9087 ++p2; /* abcd;ABCD form, p2 points to A */
9088 else
9089 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9090 while (p[0])
9091 {
9092 if (p[0] == '\\' && p[1] != NUL)
9093 ++p;
9094#ifdef FEAT_MBYTE
9095 from = (*mb_ptr2char)(p);
9096#else
9097 from = p[0];
9098#endif
9099 if (p2 == NULL)
9100 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009101 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102 if (p[0] == '\\')
9103 ++p;
9104#ifdef FEAT_MBYTE
9105 to = (*mb_ptr2char)(p);
9106#else
9107 to = p[0];
9108#endif
9109 }
9110 else
9111 {
9112 if (p2[0] == '\\')
9113 ++p2;
9114#ifdef FEAT_MBYTE
9115 to = (*mb_ptr2char)(p2);
9116#else
9117 to = p2[0];
9118#endif
9119 }
9120 if (to == NUL)
9121 {
9122 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9123 transchar(from));
9124 return;
9125 }
9126 langmap_mapchar[from & 255] = to;
9127
9128 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009129 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009130 if (p2 == NULL)
9131 {
9132 if (p[0] == ',')
9133 {
9134 ++p;
9135 break;
9136 }
9137 }
9138 else
9139 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009140 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141 if (*p == ';')
9142 {
9143 p = p2;
9144 if (p[0] != NUL)
9145 {
9146 if (p[0] != ',')
9147 {
9148 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9149 return;
9150 }
9151 ++p;
9152 }
9153 break;
9154 }
9155 }
9156 }
9157 }
9158}
9159#endif
9160
9161/*
9162 * Return TRUE if format option 'x' is in effect.
9163 * Take care of no formatting when 'paste' is set.
9164 */
9165 int
9166has_format_option(x)
9167 int x;
9168{
9169 if (p_paste)
9170 return FALSE;
9171 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9172}
9173
9174/*
9175 * Return TRUE if "x" is present in 'shortmess' option, or
9176 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9177 */
9178 int
9179shortmess(x)
9180 int x;
9181{
9182 return ( vim_strchr(p_shm, x) != NULL
9183 || (vim_strchr(p_shm, 'a') != NULL
9184 && vim_strchr((char_u *)SHM_A, x) != NULL));
9185}
9186
9187/*
9188 * paste_option_changed() - Called after p_paste was set or reset.
9189 */
9190 static void
9191paste_option_changed()
9192{
9193 static int old_p_paste = FALSE;
9194 static int save_sm = 0;
9195#ifdef FEAT_CMDL_INFO
9196 static int save_ru = 0;
9197#endif
9198#ifdef FEAT_RIGHTLEFT
9199 static int save_ri = 0;
9200 static int save_hkmap = 0;
9201#endif
9202 buf_T *buf;
9203
9204 if (p_paste)
9205 {
9206 /*
9207 * Paste switched from off to on.
9208 * Save the current values, so they can be restored later.
9209 */
9210 if (!old_p_paste)
9211 {
9212 /* save options for each buffer */
9213 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9214 {
9215 buf->b_p_tw_nopaste = buf->b_p_tw;
9216 buf->b_p_wm_nopaste = buf->b_p_wm;
9217 buf->b_p_sts_nopaste = buf->b_p_sts;
9218 buf->b_p_ai_nopaste = buf->b_p_ai;
9219 }
9220
9221 /* save global options */
9222 save_sm = p_sm;
9223#ifdef FEAT_CMDL_INFO
9224 save_ru = p_ru;
9225#endif
9226#ifdef FEAT_RIGHTLEFT
9227 save_ri = p_ri;
9228 save_hkmap = p_hkmap;
9229#endif
9230 /* save global values for local buffer options */
9231 p_tw_nopaste = p_tw;
9232 p_wm_nopaste = p_wm;
9233 p_sts_nopaste = p_sts;
9234 p_ai_nopaste = p_ai;
9235 }
9236
9237 /*
9238 * Always set the option values, also when 'paste' is set when it is
9239 * already on.
9240 */
9241 /* set options for each buffer */
9242 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9243 {
9244 buf->b_p_tw = 0; /* textwidth is 0 */
9245 buf->b_p_wm = 0; /* wrapmargin is 0 */
9246 buf->b_p_sts = 0; /* softtabstop is 0 */
9247 buf->b_p_ai = 0; /* no auto-indent */
9248 }
9249
9250 /* set global options */
9251 p_sm = 0; /* no showmatch */
9252#ifdef FEAT_CMDL_INFO
9253# ifdef FEAT_WINDOWS
9254 if (p_ru)
9255 status_redraw_all(); /* redraw to remove the ruler */
9256# endif
9257 p_ru = 0; /* no ruler */
9258#endif
9259#ifdef FEAT_RIGHTLEFT
9260 p_ri = 0; /* no reverse insert */
9261 p_hkmap = 0; /* no Hebrew keyboard */
9262#endif
9263 /* set global values for local buffer options */
9264 p_tw = 0;
9265 p_wm = 0;
9266 p_sts = 0;
9267 p_ai = 0;
9268 }
9269
9270 /*
9271 * Paste switched from on to off: Restore saved values.
9272 */
9273 else if (old_p_paste)
9274 {
9275 /* restore options for each buffer */
9276 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9277 {
9278 buf->b_p_tw = buf->b_p_tw_nopaste;
9279 buf->b_p_wm = buf->b_p_wm_nopaste;
9280 buf->b_p_sts = buf->b_p_sts_nopaste;
9281 buf->b_p_ai = buf->b_p_ai_nopaste;
9282 }
9283
9284 /* restore global options */
9285 p_sm = save_sm;
9286#ifdef FEAT_CMDL_INFO
9287# ifdef FEAT_WINDOWS
9288 if (p_ru != save_ru)
9289 status_redraw_all(); /* redraw to draw the ruler */
9290# endif
9291 p_ru = save_ru;
9292#endif
9293#ifdef FEAT_RIGHTLEFT
9294 p_ri = save_ri;
9295 p_hkmap = save_hkmap;
9296#endif
9297 /* set global values for local buffer options */
9298 p_tw = p_tw_nopaste;
9299 p_wm = p_wm_nopaste;
9300 p_sts = p_sts_nopaste;
9301 p_ai = p_ai_nopaste;
9302 }
9303
9304 old_p_paste = p_paste;
9305}
9306
9307/*
9308 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9309 *
9310 * Reset 'compatible' and set the values for options that didn't get set yet
9311 * to the Vim defaults.
9312 * Don't do this if the 'compatible' option has been set or reset before.
9313 */
9314 void
9315vimrc_found()
9316{
9317 int opt_idx;
9318
9319 if (!option_was_set((char_u *)"cp"))
9320 {
9321 p_cp = FALSE;
9322 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9323 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9324 set_option_default(opt_idx, OPT_FREE, FALSE);
9325 didset_options();
9326 }
9327}
9328
9329/*
9330 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9331 */
9332 void
9333change_compatible(on)
9334 int on;
9335{
9336 if (p_cp != on)
9337 {
9338 p_cp = on;
9339 compatible_set();
9340 }
9341 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9342}
9343
9344/*
9345 * Return TRUE when option "name" has been set.
9346 */
9347 int
9348option_was_set(name)
9349 char_u *name;
9350{
9351 int idx;
9352
9353 idx = findoption(name);
9354 if (idx < 0) /* unknown option */
9355 return FALSE;
9356 if (options[idx].flags & P_WAS_SET)
9357 return TRUE;
9358 return FALSE;
9359}
9360
9361/*
9362 * compatible_set() - Called when 'compatible' has been set or unset.
9363 *
9364 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9365 * flag) to a Vi compatible value.
9366 * When 'compatible' is unset: Set all options that have a different default
9367 * for Vim (without the P_VI_DEF flag) to that default.
9368 */
9369 static void
9370compatible_set()
9371{
9372 int opt_idx;
9373
9374 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9375 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9376 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9377 set_option_default(opt_idx, OPT_FREE, p_cp);
9378 didset_options();
9379}
9380
9381#ifdef FEAT_LINEBREAK
9382
9383# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9384 /* Borland C++ screws up loop optimisation here (negri) */
9385# pragma option -O-l
9386# endif
9387
9388/*
9389 * fill_breakat_flags() -- called when 'breakat' changes value.
9390 */
9391 static void
9392fill_breakat_flags()
9393{
9394 char_u *c;
9395 int i;
9396
9397 for (i = 0; i < 256; i++)
9398 breakat_flags[i] = FALSE;
9399
9400 if (p_breakat != NULL)
9401 for (c = p_breakat; *c; c++)
9402 breakat_flags[*c] = TRUE;
9403}
9404
9405# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9406# pragma option -O.l
9407# endif
9408
9409#endif
9410
9411/*
9412 * Check an option that can be a range of string values.
9413 *
9414 * Return OK for correct value, FAIL otherwise.
9415 * Empty is always OK.
9416 */
9417 static int
9418check_opt_strings(val, values, list)
9419 char_u *val;
9420 char **values;
9421 int list; /* when TRUE: accept a list of values */
9422{
9423 return opt_strings_flags(val, values, NULL, list);
9424}
9425
9426/*
9427 * Handle an option that can be a range of string values.
9428 * Set a flag in "*flagp" for each string present.
9429 *
9430 * Return OK for correct value, FAIL otherwise.
9431 * Empty is always OK.
9432 */
9433 static int
9434opt_strings_flags(val, values, flagp, list)
9435 char_u *val; /* new value */
9436 char **values; /* array of valid string values */
9437 unsigned *flagp;
9438 int list; /* when TRUE: accept a list of values */
9439{
9440 int i;
9441 int len;
9442 unsigned new_flags = 0;
9443
9444 while (*val)
9445 {
9446 for (i = 0; ; ++i)
9447 {
9448 if (values[i] == NULL) /* val not found in values[] */
9449 return FAIL;
9450
9451 len = (int)STRLEN(values[i]);
9452 if (STRNCMP(values[i], val, len) == 0
9453 && ((list && val[len] == ',') || val[len] == NUL))
9454 {
9455 val += len + (val[len] == ',');
9456 new_flags |= (1 << i);
9457 break; /* check next item in val list */
9458 }
9459 }
9460 }
9461 if (flagp != NULL)
9462 *flagp = new_flags;
9463
9464 return OK;
9465}
9466
9467/*
9468 * Read the 'wildmode' option, fill wim_flags[].
9469 */
9470 static int
9471check_opt_wim()
9472{
9473 char_u new_wim_flags[4];
9474 char_u *p;
9475 int i;
9476 int idx = 0;
9477
9478 for (i = 0; i < 4; ++i)
9479 new_wim_flags[i] = 0;
9480
9481 for (p = p_wim; *p; ++p)
9482 {
9483 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9484 ;
9485 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9486 return FAIL;
9487 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9488 new_wim_flags[idx] |= WIM_LONGEST;
9489 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9490 new_wim_flags[idx] |= WIM_FULL;
9491 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9492 new_wim_flags[idx] |= WIM_LIST;
9493 else
9494 return FAIL;
9495 p += i;
9496 if (*p == NUL)
9497 break;
9498 if (*p == ',')
9499 {
9500 if (idx == 3)
9501 return FAIL;
9502 ++idx;
9503 }
9504 }
9505
9506 /* fill remaining entries with last flag */
9507 while (idx < 3)
9508 {
9509 new_wim_flags[idx + 1] = new_wim_flags[idx];
9510 ++idx;
9511 }
9512
9513 /* only when there are no errors, wim_flags[] is changed */
9514 for (i = 0; i < 4; ++i)
9515 wim_flags[i] = new_wim_flags[i];
9516 return OK;
9517}
9518
9519/*
9520 * Check if backspacing over something is allowed.
9521 */
9522 int
9523can_bs(what)
9524 int what; /* BS_INDENT, BS_EOL or BS_START */
9525{
9526 switch (*p_bs)
9527 {
9528 case '2': return TRUE;
9529 case '1': return (what != BS_START);
9530 case '0': return FALSE;
9531 }
9532 return vim_strchr(p_bs, what) != NULL;
9533}
9534
9535/*
9536 * Save the current values of 'fileformat' and 'fileencoding', so that we know
9537 * the file must be considered changed when the value is different.
9538 */
9539 void
9540save_file_ff(buf)
9541 buf_T *buf;
9542{
9543 buf->b_start_ffc = *buf->b_p_ff;
9544 buf->b_start_eol = buf->b_p_eol;
9545#ifdef FEAT_MBYTE
9546 /* Only use free/alloc when necessary, they take time. */
9547 if (buf->b_start_fenc == NULL
9548 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9549 {
9550 vim_free(buf->b_start_fenc);
9551 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9552 }
9553#endif
9554}
9555
9556/*
9557 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9558 * from when editing started (save_file_ff() called).
9559 * Also when 'endofline' was changed and 'binary' is set.
9560 * Don't consider a new, empty buffer to be changed.
9561 */
9562 int
9563file_ff_differs(buf)
9564 buf_T *buf;
9565{
9566 if ((buf->b_flags & BF_NEW)
9567 && buf->b_ml.ml_line_count == 1
9568 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
9569 return FALSE;
9570 if (buf->b_start_ffc != *buf->b_p_ff)
9571 return TRUE;
9572 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
9573 return TRUE;
9574#ifdef FEAT_MBYTE
9575 if (buf->b_start_fenc == NULL)
9576 return (*buf->b_p_fenc != NUL);
9577 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
9578#else
9579 return FALSE;
9580#endif
9581}
9582
9583/*
9584 * return OK if "p" is a valid fileformat name, FAIL otherwise.
9585 */
9586 int
9587check_ff_value(p)
9588 char_u *p;
9589{
9590 return check_opt_strings(p, p_ff_values, FALSE);
9591}