blob: ffeaf8644f098ba5f6ba5e051c8283f0dfbf5c19 [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.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002596 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002598 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2600# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002601 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002603 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002605 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606# endif
2607#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002608 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609 set_string_default("sh", p);
2610
2611#ifdef FEAT_WILDIGN
2612 /*
2613 * Set the default for 'backupskip' to include environment variables for
2614 * temp files.
2615 */
2616 {
2617# ifdef UNIX
2618 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2619# else
2620 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2621# endif
2622 int len;
2623 garray_T ga;
2624
2625 ga_init2(&ga, 1, 100);
2626 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2627 {
2628# ifdef UNIX
2629 if (*names[n] == NUL)
2630 p = (char_u *)"/tmp";
2631 else
2632# endif
2633 p = mch_getenv((char_u *)names[n]);
2634 if (p != NULL && *p != NUL)
2635 {
2636 /* First time count the NUL, otherwise count the ','. */
2637 len = STRLEN(p) + 3;
2638 if (ga_grow(&ga, len) == OK)
2639 {
2640 if (ga.ga_len > 0)
2641 STRCAT(ga.ga_data, ",");
2642 STRCAT(ga.ga_data, p);
2643 add_pathsep(ga.ga_data);
2644 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 ga.ga_len += len;
2646 }
2647 }
2648 }
2649 if (ga.ga_data != NULL)
2650 {
2651 set_string_default("bsk", ga.ga_data);
2652 vim_free(ga.ga_data);
2653 }
2654 }
2655#endif
2656
2657 /*
2658 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2659 */
2660 opt_idx = findoption((char_u *)"maxmemtot");
2661#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2662 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2663#endif
2664 {
2665#ifdef HAVE_AVAIL_MEM
2666 /* Use amount of memory available at this moment. */
2667 n = (mch_avail_mem(FALSE) >> 11);
2668#else
2669# ifdef HAVE_TOTAL_MEM
2670 /* Use amount of memory available to Vim. */
2671 n = (mch_total_mem(FALSE) >> 11);
2672# else
2673 n = (0x7fffffff >> 11);
2674# endif
2675#endif
2676 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2677 opt_idx = findoption((char_u *)"maxmem");
2678#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2679 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2680 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2681#endif
2682 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2683 }
2684
2685#ifdef FEAT_GUI_W32
2686 /* force 'shortname' for Win32s */
2687 if (gui_is_win32s())
2688 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2689 (char_u *)TRUE;
2690#endif
2691
2692#ifdef FEAT_SEARCHPATH
2693 {
2694 char_u *cdpath;
2695 char_u *buf;
2696 int i;
2697 int j;
2698
2699 /* Initialize the 'cdpath' option's default value. */
2700 cdpath = mch_getenv((char_u *)"CDPATH");
2701 if (cdpath != NULL)
2702 {
2703 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2704 if (buf != NULL)
2705 {
2706 buf[0] = ','; /* start with ",", current dir first */
2707 j = 1;
2708 for (i = 0; cdpath[i] != NUL; ++i)
2709 {
2710 if (vim_ispathlistsep(cdpath[i]))
2711 buf[j++] = ',';
2712 else
2713 {
2714 if (cdpath[i] == ' ' || cdpath[i] == ',')
2715 buf[j++] = '\\';
2716 buf[j++] = cdpath[i];
2717 }
2718 }
2719 buf[j] = NUL;
2720 opt_idx = findoption((char_u *)"cdpath");
2721 options[opt_idx].def_val[VI_DEFAULT] = buf;
2722 options[opt_idx].flags |= P_DEF_ALLOCED;
2723 }
2724 }
2725 }
2726#endif
2727
2728#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2729 /* Set print encoding on platforms that don't default to latin1 */
2730 set_string_default("penc",
2731# if defined(MSWIN) || defined(OS2)
2732 (char_u *)"cp1252"
2733# else
2734# ifdef VMS
2735 (char_u *)"dec-mcs"
2736# else
2737# ifdef EBCDIC
2738 (char_u *)"ebcdic-uk"
2739# else
2740# ifdef MAC
2741 (char_u *)"mac-roman"
2742# else /* HPUX */
2743 (char_u *)"hp-roman8"
2744# endif
2745# endif
2746# endif
2747# endif
2748 );
2749#endif
2750
2751#ifdef FEAT_POSTSCRIPT
2752 /* 'printexpr' must be allocated to be able to evaluate it. */
2753 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00002754# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
2755 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756# else
2757# ifdef VMS
2758 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
2759
2760# else
2761 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
2762# endif
2763# endif
2764 );
2765#endif
2766
2767 /*
2768 * Set all the options (except the terminal options) to their default
2769 * value. Also set the global value for local options.
2770 */
2771 set_options_default(0);
2772
2773#ifdef FEAT_GUI
2774 if (found_reverse_arg)
2775 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
2776#endif
2777
2778 curbuf->b_p_initialized = TRUE;
2779 curbuf->b_p_ar = -1; /* no local 'autoread' value */
2780 check_buf_options(curbuf);
2781 check_win_options(curwin);
2782 check_options();
2783
2784 /* Must be before option_expand(), because that one needs vim_isIDc() */
2785 didset_options();
2786
2787#ifdef FEAT_LINEBREAK
2788 /*
2789 * initialize the table for 'breakat'.
2790 */
2791 fill_breakat_flags();
2792#endif
2793
2794 /*
2795 * Expand environment variables and things like "~" for the defaults.
2796 * If option_expand() returns non-NULL the variable is expanded. This can
2797 * only happen for non-indirect options.
2798 * Also set the default to the expanded value, so ":set" does not list
2799 * them.
2800 * Don't set the P_ALLOCED flag, because we don't want to free the
2801 * default.
2802 */
2803 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
2804 {
2805 if ((options[opt_idx].flags & P_GETTEXT)
2806 && options[opt_idx].var != NULL)
2807 p = (char_u *)_(*(char **)options[opt_idx].var);
2808 else
2809 p = option_expand(opt_idx, NULL);
2810 if (p != NULL && (p = vim_strsave(p)) != NULL)
2811 {
2812 *(char_u **)options[opt_idx].var = p;
2813 /* VIMEXP
2814 * Defaults for all expanded options are currently the same for Vi
2815 * and Vim. When this changes, add some code here! Also need to
2816 * split P_DEF_ALLOCED in two.
2817 */
2818 if (options[opt_idx].flags & P_DEF_ALLOCED)
2819 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2820 options[opt_idx].def_val[VI_DEFAULT] = p;
2821 options[opt_idx].flags |= P_DEF_ALLOCED;
2822 }
2823 }
2824
2825 /* Initialize the highlight_attr[] table. */
2826 highlight_changed();
2827
2828 save_file_ff(curbuf); /* Buffer is unchanged */
2829
2830 /* Parse default for 'wildmode' */
2831 check_opt_wim();
2832
2833#if defined(FEAT_ARABIC)
2834 /* Detect use of mlterm.
2835 * Mlterm is a terminal emulator akin to xterm that has some special
2836 * abilities (bidi namely).
2837 * NOTE: mlterm's author is being asked to 'set' a variable
2838 * instead of an environment variable due to inheritance.
2839 */
2840 if (mch_getenv((char_u *)"MLTERM") != NULL)
2841 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
2842#endif
2843
2844#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
2845 /* Parse default for 'fillchars'. */
2846 (void)set_chars_option(&p_fcs);
2847#endif
2848
2849#ifdef FEAT_CLIPBOARD
2850 /* Parse default for 'clipboard' */
2851 (void)check_clipboard_option();
2852#endif
2853
2854#ifdef FEAT_MBYTE
2855# if defined(WIN3264) && defined(FEAT_GETTEXT)
2856 /*
2857 * If $LANG isn't set, try to get a good value for it. This makes the
2858 * right language be used automatically. Don't do this for English.
2859 */
2860 if (mch_getenv((char_u *)"LANG") == NULL)
2861 {
2862 char buf[20];
2863
2864 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
2865 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
2866 * only the first two. */
2867 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
2868 (LPTSTR)buf, 20);
2869 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
2870 {
2871 /* There are a few exceptions (probably more) */
2872 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
2873 STRCPY(buf, "zh_TW");
2874 else if (STRNICMP(buf, "chs", 3) == 0
2875 || STRNICMP(buf, "zhc", 3) == 0)
2876 STRCPY(buf, "zh_CN");
2877 else if (STRNICMP(buf, "jp", 2) == 0)
2878 STRCPY(buf, "ja");
2879 else
2880 buf[2] = NUL; /* truncate to two-letter code */
2881 vim_setenv("LANG", buf);
2882 }
2883 }
2884# endif
2885
2886 /* enc_locale() will try to find the encoding of the current locale. */
2887 p = enc_locale();
2888 if (p != NULL)
2889 {
2890 char_u *save_enc;
2891
2892 /* Try setting 'encoding' and check if the value is valid.
2893 * If not, go back to the default "latin1". */
2894 save_enc = p_enc;
2895 p_enc = p;
2896 if (mb_init() == NULL)
2897 {
2898 opt_idx = findoption((char_u *)"encoding");
2899 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
2900 options[opt_idx].flags |= P_DEF_ALLOCED;
2901
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002902#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
2903 || defined(VMS)
2904 if (STRCMP(p_enc, "latin1") == 0
2905# ifdef FEAT_MBYTE
2906 || enc_utf8
2907# endif
2908 )
2909 {
2910 /* Adjust the default for 'isprint' to match latin1. */
2911 set_string_option_direct((char_u *)"isp", -1,
2912 (char_u *)"@,161-255", OPT_FREE);
2913 (void)init_chartab();
2914 }
2915#endif
2916
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917# if defined(WIN3264) && !defined(FEAT_GUI)
2918 /* Win32 console: When GetACP() returns a different value from
2919 * GetConsoleCP() set 'termencoding'. */
2920 if (GetACP() != GetConsoleCP())
2921 {
2922 char buf[50];
2923
2924 sprintf(buf, "cp%ld", (long)GetConsoleCP());
2925 p_tenc = vim_strsave((char_u *)buf);
2926 if (p_tenc != NULL)
2927 {
2928 opt_idx = findoption((char_u *)"termencoding");
2929 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
2930 options[opt_idx].flags |= P_DEF_ALLOCED;
2931 convert_setup(&input_conv, p_tenc, p_enc);
2932 convert_setup(&output_conv, p_enc, p_tenc);
2933 }
2934 else
2935 p_tenc = empty_option;
2936 }
2937# endif
2938 }
2939 else
2940 {
2941 vim_free(p_enc);
2942 p_enc = save_enc;
2943 }
2944 }
2945#endif
2946
2947#ifdef FEAT_MULTI_LANG
2948 /* Set the default for 'helplang'. */
2949 set_helplang_default(get_mess_lang());
2950#endif
2951}
2952
2953/*
2954 * Set an option to its default value.
2955 * This does not take care of side effects!
2956 */
2957 static void
2958set_option_default(opt_idx, opt_flags, compatible)
2959 int opt_idx;
2960 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
2961 int compatible; /* use Vi default value */
2962{
2963 char_u *varp; /* pointer to variable for current option */
2964 int dvi; /* index in def_val[] */
2965 long_u flags;
2966 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
2967
2968 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
2969 flags = options[opt_idx].flags;
2970 if (varp != NULL) /* nothing to do for hidden option */
2971 {
2972 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
2973 if (flags & P_STRING)
2974 {
2975 /* Use set_string_option_direct() for local options to handle
2976 * freeing and allocating the value. */
2977 if (options[opt_idx].indir != PV_NONE)
2978 set_string_option_direct(NULL, opt_idx,
2979 options[opt_idx].def_val[dvi], opt_flags);
2980 else
2981 {
2982 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
2983 free_string_option(*(char_u **)(varp));
2984 *(char_u **)varp = options[opt_idx].def_val[dvi];
2985 options[opt_idx].flags &= ~P_ALLOCED;
2986 }
2987 }
2988 else if (flags & P_NUM)
2989 {
2990 if (varp == (char_u *)PV_SCROLL)
2991 win_comp_scroll(curwin);
2992 else
2993 {
2994 *(long *)varp = (long)options[opt_idx].def_val[dvi];
2995 /* May also set global value for local option. */
2996 if (both)
2997 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
2998 *(long *)varp;
2999 }
3000 }
3001 else /* P_BOOL */
3002 {
3003 /* the cast to long is required for Manx C */
3004 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3005 /* May also set global value for local option. */
3006 if (both)
3007 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3008 *(int *)varp;
3009 }
3010 }
3011
3012#ifdef FEAT_EVAL
3013 /* Remember where the option was set. */
3014 options[opt_idx].scriptID = current_SID;
3015#endif
3016}
3017
3018/*
3019 * Set all options (except terminal options) to their default value.
3020 */
3021 static void
3022set_options_default(opt_flags)
3023 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3024{
3025 int i;
3026#ifdef FEAT_WINDOWS
3027 win_T *wp;
3028#endif
3029
3030 for (i = 0; !istermoption(&options[i]); i++)
3031 if (!(options[i].flags & P_NODEFAULT))
3032 set_option_default(i, opt_flags, p_cp);
3033
3034#ifdef FEAT_WINDOWS
3035 /* The 'scroll' option must be computed for all windows. */
3036 for (wp = firstwin; wp != NULL; wp = wp->w_next)
3037 win_comp_scroll(wp);
3038#else
3039 win_comp_scroll(curwin);
3040#endif
3041}
3042
3043/*
3044 * Set the Vi-default value of a string option.
3045 * Used for 'sh', 'backupskip' and 'term'.
3046 */
3047 void
3048set_string_default(name, val)
3049 char *name;
3050 char_u *val;
3051{
3052 char_u *p;
3053 int opt_idx;
3054
3055 p = vim_strsave(val);
3056 if (p != NULL) /* we don't want a NULL */
3057 {
3058 opt_idx = findoption((char_u *)name);
3059 if (options[opt_idx].flags & P_DEF_ALLOCED)
3060 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3061 options[opt_idx].def_val[VI_DEFAULT] = p;
3062 options[opt_idx].flags |= P_DEF_ALLOCED;
3063 }
3064}
3065
3066/*
3067 * Set the Vi-default value of a number option.
3068 * Used for 'lines' and 'columns'.
3069 */
3070 void
3071set_number_default(name, val)
3072 char *name;
3073 long val;
3074{
3075 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3076}
3077
3078/*
3079 * Initialize the options, part two: After getting Rows and Columns and
3080 * setting 'term'.
3081 */
3082 void
3083set_init_2()
3084{
3085 /*
3086 * 'scroll' defaults to half the window height. Note that this default is
3087 * wrong when the window height changes.
3088 */
3089 options[findoption((char_u *)"scroll")].def_val[VI_DEFAULT]
3090 = (char_u *)((long_u)Rows >> 1);
3091 comp_col();
3092
3093#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3094 {
3095 int idx4;
3096
3097 /*
3098 * If 'background' wasn't set by the user, try guessing the value,
3099 * depending on the terminal name. Only need to check for terminals
3100 * with a dark background, that can handle color. Only "linux"
3101 * console at the moment.
3102 */
3103 idx4 = findoption((char_u *)"bg");
3104 if (!(options[idx4].flags & P_WAS_SET) && STRCMP(T_NAME, "linux") == 0)
3105 {
3106 set_string_option_direct(NULL, idx4, (char_u *)"dark", OPT_FREE);
3107 /* don't mark it as set, when starting the GUI it may be changed
3108 * again */
3109 options[idx4].flags &= ~P_WAS_SET;
3110 }
3111 }
3112#endif
3113}
3114
3115/*
3116 * Initialize the options, part three: After reading the .vimrc
3117 */
3118 void
3119set_init_3()
3120{
3121#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3122/*
3123 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3124 * This is done after other initializations, where 'shell' might have been
3125 * set, but only if they have not been set before.
3126 */
3127 char_u *p;
3128 int idx_srr;
3129 int do_srr;
3130#ifdef FEAT_QUICKFIX
3131 int idx_sp;
3132 int do_sp;
3133#endif
3134
3135 idx_srr = findoption((char_u *)"srr");
3136 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3137#ifdef FEAT_QUICKFIX
3138 idx_sp = findoption((char_u *)"sp");
3139 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3140#endif
3141
3142 /*
3143 * Isolate the name of the shell:
3144 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3145 * - Remove any argument. E.g., "csh -f" -> "csh".
3146 */
3147 p = gettail(p_sh);
3148 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3149 if (p != NULL)
3150 {
3151 /*
3152 * Default for p_sp is "| tee", for p_srr is ">".
3153 * For known shells it is changed here to include stderr.
3154 */
3155 if ( fnamecmp(p, "csh") == 0
3156 || fnamecmp(p, "tcsh") == 0
3157# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3158 || fnamecmp(p, "csh.exe") == 0
3159 || fnamecmp(p, "tcsh.exe") == 0
3160# endif
3161 )
3162 {
3163#if defined(FEAT_QUICKFIX)
3164 if (do_sp)
3165 {
3166# ifdef WIN3264
3167 p_sp = (char_u *)">&";
3168# else
3169 p_sp = (char_u *)"|& tee";
3170# endif
3171 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3172 }
3173#endif
3174 if (do_srr)
3175 {
3176 p_srr = (char_u *)">&";
3177 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3178 }
3179 }
3180 else
3181# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3182 if ( fnamecmp(p, "sh") == 0
3183 || fnamecmp(p, "ksh") == 0
3184 || fnamecmp(p, "zsh") == 0
3185 || fnamecmp(p, "bash") == 0
3186# ifdef WIN3264
3187 || fnamecmp(p, "cmd") == 0
3188 || fnamecmp(p, "sh.exe") == 0
3189 || fnamecmp(p, "ksh.exe") == 0
3190 || fnamecmp(p, "zsh.exe") == 0
3191 || fnamecmp(p, "bash.exe") == 0
3192 || fnamecmp(p, "cmd.exe") == 0
3193# endif
3194 )
3195# endif
3196 {
3197#if defined(FEAT_QUICKFIX)
3198 if (do_sp)
3199 {
3200# ifdef WIN3264
3201 p_sp = (char_u *)">%s 2>&1";
3202# else
3203 p_sp = (char_u *)"2>&1| tee";
3204# endif
3205 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3206 }
3207#endif
3208 if (do_srr)
3209 {
3210 p_srr = (char_u *)">%s 2>&1";
3211 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3212 }
3213 }
3214 vim_free(p);
3215 }
3216#endif
3217
3218#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3219 /*
3220 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3221 * This is done after other initializations, where 'shell' might have been
3222 * set, but only if they have not been set before. Default for p_shcf is
3223 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3224 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3225 * command.com. And for Win32 we need to set p_sxq instead.
3226 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 {
3229 int idx3;
3230
3231 idx3 = findoption((char_u *)"shcf");
3232 if (!(options[idx3].flags & P_WAS_SET))
3233 {
3234 p_shcf = (char_u *)"-c";
3235 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3236 }
3237
3238# ifndef DJGPP
3239# ifdef WIN3264
3240 /* Somehow Win32 requires the quotes around the redirection too */
3241 idx3 = findoption((char_u *)"sxq");
3242 if (!(options[idx3].flags & P_WAS_SET))
3243 {
3244 p_sxq = (char_u *)"\"";
3245 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3246 }
3247# else
3248 idx3 = findoption((char_u *)"shq");
3249 if (!(options[idx3].flags & P_WAS_SET))
3250 {
3251 p_shq = (char_u *)"\"";
3252 options[idx3].def_val[VI_DEFAULT] = p_shq;
3253 }
3254# endif
3255# endif
3256 }
3257#endif
3258
3259#ifdef FEAT_TITLE
3260 set_title_defaults();
3261#endif
3262}
3263
3264#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3265/*
3266 * When 'helplang' is still at its default value, set it to "lang".
3267 * Only the first two characters of "lang" are used.
3268 */
3269 void
3270set_helplang_default(lang)
3271 char_u *lang;
3272{
3273 int idx;
3274
3275 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3276 return;
3277 idx = findoption((char_u *)"hlg");
3278 if (!(options[idx].flags & P_WAS_SET))
3279 {
3280 if (options[idx].flags & P_ALLOCED)
3281 free_string_option(p_hlg);
3282 p_hlg = vim_strsave(lang);
3283 if (p_hlg == NULL)
3284 p_hlg = empty_option;
3285 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003286 {
3287 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3288 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3289 {
3290 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3291 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3292 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003294 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295 options[idx].flags |= P_ALLOCED;
3296 }
3297}
3298#endif
3299
3300#ifdef FEAT_GUI
3301static char_u *gui_bg_default __ARGS((void));
3302
3303 static char_u *
3304gui_bg_default()
3305{
3306 if (gui_get_lightness(gui.back_pixel) < 127)
3307 return (char_u *)"dark";
3308 return (char_u *)"light";
3309}
3310
3311/*
3312 * Option initializations that can only be done after opening the GUI window.
3313 */
3314 void
3315init_gui_options()
3316{
3317 /* Set the 'background' option according to the lightness of the
3318 * background color, unless the user has set it already. */
3319 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3320 {
3321 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3322 highlight_changed();
3323 }
3324}
3325#endif
3326
3327#ifdef FEAT_TITLE
3328/*
3329 * 'title' and 'icon' only default to true if they have not been set or reset
3330 * in .vimrc and we can read the old value.
3331 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3332 * they can be reset. This reduces startup time when using X on a remote
3333 * machine.
3334 */
3335 void
3336set_title_defaults()
3337{
3338 int idx1;
3339 long val;
3340
3341 /*
3342 * If GUI is (going to be) used, we can always set the window title and
3343 * icon name. Saves a bit of time, because the X11 display server does
3344 * not need to be contacted.
3345 */
3346 idx1 = findoption((char_u *)"title");
3347 if (!(options[idx1].flags & P_WAS_SET))
3348 {
3349#ifdef FEAT_GUI
3350 if (gui.starting || gui.in_use)
3351 val = TRUE;
3352 else
3353#endif
3354 val = mch_can_restore_title();
3355 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3356 p_title = val;
3357 }
3358 idx1 = findoption((char_u *)"icon");
3359 if (!(options[idx1].flags & P_WAS_SET))
3360 {
3361#ifdef FEAT_GUI
3362 if (gui.starting || gui.in_use)
3363 val = TRUE;
3364 else
3365#endif
3366 val = mch_can_restore_icon();
3367 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3368 p_icon = val;
3369 }
3370}
3371#endif
3372
3373/*
3374 * Parse 'arg' for option settings.
3375 *
3376 * 'arg' may be IObuff, but only when no errors can be present and option
3377 * does not need to be expanded with option_expand().
3378 * "opt_flags":
3379 * 0 for ":set"
3380 * OPT_GLOBAL for ":setglobal"
3381 * OPT_LOCAL for ":setlocal" and a modeline
3382 * OPT_MODELINE for a modeline
3383 *
3384 * returns FAIL if an error is detected, OK otherwise
3385 */
3386 int
3387do_set(arg, opt_flags)
3388 char_u *arg; /* option string (may be written to!) */
3389 int opt_flags;
3390{
3391 int opt_idx;
3392 char_u *errmsg;
3393 char_u errbuf[80];
3394 char_u *startarg;
3395 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3396 int nextchar; /* next non-white char after option name */
3397 int afterchar; /* character just after option name */
3398 int len;
3399 int i;
3400 long value;
3401 int key;
3402 long_u flags; /* flags for current option */
3403 char_u *varp = NULL; /* pointer to variable for current option */
3404 int did_show = FALSE; /* already showed one value */
3405 int adding; /* "opt+=arg" */
3406 int prepending; /* "opt^=arg" */
3407 int removing; /* "opt-=arg" */
3408 int cp_val = 0;
3409 char_u key_name[2];
3410
3411 if (*arg == NUL)
3412 {
3413 showoptions(0, opt_flags);
3414 return OK;
3415 }
3416
3417 while (*arg != NUL) /* loop to process all options */
3418 {
3419 errmsg = NULL;
3420 startarg = arg; /* remember for error message */
3421
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003422 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3423 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424 {
3425 /*
3426 * ":set all" show all options.
3427 * ":set all&" set all options to their default value.
3428 */
3429 arg += 3;
3430 if (*arg == '&')
3431 {
3432 ++arg;
3433 /* Only for :set command set global value of local options. */
3434 set_options_default(OPT_FREE | opt_flags);
3435 }
3436 else
3437 showoptions(1, opt_flags);
3438 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003439 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 {
3441 showoptions(2, opt_flags);
3442 show_termcodes();
3443 arg += 7;
3444 }
3445 else
3446 {
3447 prefix = 1;
3448 if (STRNCMP(arg, "no", 2) == 0)
3449 {
3450 prefix = 0;
3451 arg += 2;
3452 }
3453 else if (STRNCMP(arg, "inv", 3) == 0)
3454 {
3455 prefix = 2;
3456 arg += 3;
3457 }
3458
3459 /* find end of name */
3460 key = 0;
3461 if (*arg == '<')
3462 {
3463 nextchar = 0;
3464 opt_idx = -1;
3465 /* look out for <t_>;> */
3466 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3467 len = 5;
3468 else
3469 {
3470 len = 1;
3471 while (arg[len] != NUL && arg[len] != '>')
3472 ++len;
3473 }
3474 if (arg[len] != '>')
3475 {
3476 errmsg = e_invarg;
3477 goto skip;
3478 }
3479 arg[len] = NUL; /* put NUL after name */
3480 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3481 opt_idx = findoption(arg + 1);
3482 arg[len++] = '>'; /* restore '>' */
3483 if (opt_idx == -1)
3484 key = find_key_option(arg + 1);
3485 }
3486 else
3487 {
3488 len = 0;
3489 /*
3490 * The two characters after "t_" may not be alphanumeric.
3491 */
3492 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3493 len = 4;
3494 else
3495 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3496 ++len;
3497 nextchar = arg[len];
3498 arg[len] = NUL; /* put NUL after name */
3499 opt_idx = findoption(arg);
3500 arg[len] = nextchar; /* restore nextchar */
3501 if (opt_idx == -1)
3502 key = find_key_option(arg);
3503 }
3504
3505 /* remember character after option name */
3506 afterchar = arg[len];
3507
3508 /* skip white space, allow ":set ai ?" */
3509 while (vim_iswhite(arg[len]))
3510 ++len;
3511
3512 adding = FALSE;
3513 prepending = FALSE;
3514 removing = FALSE;
3515 if (arg[len] != NUL && arg[len + 1] == '=')
3516 {
3517 if (arg[len] == '+')
3518 {
3519 adding = TRUE; /* "+=" */
3520 ++len;
3521 }
3522 else if (arg[len] == '^')
3523 {
3524 prepending = TRUE; /* "^=" */
3525 ++len;
3526 }
3527 else if (arg[len] == '-')
3528 {
3529 removing = TRUE; /* "-=" */
3530 ++len;
3531 }
3532 }
3533 nextchar = arg[len];
3534
3535 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3536 {
3537 errmsg = (char_u *)N_("E518: Unknown option");
3538 goto skip;
3539 }
3540
3541 if (opt_idx >= 0)
3542 {
3543 if (options[opt_idx].var == NULL) /* hidden option: skip */
3544 {
3545 /* Only give an error message when requesting the value of
3546 * a hidden option, ignore setting it. */
3547 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3548 && (!(options[opt_idx].flags & P_BOOL)
3549 || nextchar == '?'))
3550 errmsg = (char_u *)N_("E519: Option not supported");
3551 goto skip;
3552 }
3553
3554 flags = options[opt_idx].flags;
3555 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3556 }
3557 else
3558 {
3559 flags = P_STRING;
3560 if (key < 0)
3561 {
3562 key_name[0] = KEY2TERMCAP0(key);
3563 key_name[1] = KEY2TERMCAP1(key);
3564 }
3565 else
3566 {
3567 key_name[0] = KS_KEY;
3568 key_name[1] = (key & 0xff);
3569 }
3570 }
3571
3572 /* Disallow changing some options from modelines */
3573 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3574 {
3575 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3576 goto skip;
3577 }
3578
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00003579 /* Skip all options that are not window-local (used when showing
3580 * an already loaded buffer in a window). */
3581 if ((opt_flags & OPT_WINONLY)
3582 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
3583 goto skip;
3584
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585#ifdef HAVE_SANDBOX
3586 /* Disallow changing some options in the sandbox */
3587 if (sandbox > 0 && (flags & P_SECURE))
3588 {
3589 errmsg = (char_u *)_(e_sandbox);
3590 goto skip;
3591 }
3592#endif
3593
3594 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3595 {
3596 arg += len;
3597 cp_val = p_cp;
3598 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3599 {
3600 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3601 {
3602 cp_val = FALSE;
3603 arg += 3;
3604 }
3605 else /* "opt&vi": set to Vi default */
3606 {
3607 cp_val = TRUE;
3608 arg += 2;
3609 }
3610 }
3611 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3612 && arg[1] != NUL && !vim_iswhite(arg[1]))
3613 {
3614 errmsg = e_trailing;
3615 goto skip;
3616 }
3617 }
3618
3619 /*
3620 * allow '=' and ':' as MSDOS command.com allows only one
3621 * '=' character per "set" command line. grrr. (jw)
3622 */
3623 if (nextchar == '?'
3624 || (prefix == 1
3625 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
3626 && !(flags & P_BOOL)))
3627 {
3628 /*
3629 * print value
3630 */
3631 if (did_show)
3632 msg_putchar('\n'); /* cursor below last one */
3633 else
3634 {
3635 gotocmdline(TRUE); /* cursor at status line */
3636 did_show = TRUE; /* remember that we did a line */
3637 }
3638 if (opt_idx >= 0)
3639 {
3640 showoneopt(&options[opt_idx], opt_flags);
3641#ifdef FEAT_EVAL
3642 if (p_verbose > 0)
3643 {
3644 if (options[opt_idx].scriptID != 0)
3645 {
3646 MSG_PUTS(_("\n\tLast set from "));
3647 MSG_PUTS(get_scriptname(options[opt_idx].scriptID));
3648 }
3649 }
3650#endif
3651 }
3652 else
3653 {
3654 char_u *p;
3655
3656 p = find_termcode(key_name);
3657 if (p == NULL)
3658 {
3659 errmsg = (char_u *)N_("E518: Unknown option");
3660 goto skip;
3661 }
3662 else
3663 (void)show_one_termcode(key_name, p, TRUE);
3664 }
3665 if (nextchar != '?'
3666 && nextchar != NUL && !vim_iswhite(afterchar))
3667 errmsg = e_trailing;
3668 }
3669 else
3670 {
3671 if (flags & P_BOOL) /* boolean */
3672 {
3673 if (nextchar == '=' || nextchar == ':')
3674 {
3675 errmsg = e_invarg;
3676 goto skip;
3677 }
3678
3679 /*
3680 * ":set opt!": invert
3681 * ":set opt&": reset to default value
3682 * ":set opt<": reset to global value
3683 */
3684 if (nextchar == '!')
3685 value = *(int *)(varp) ^ 1;
3686 else if (nextchar == '&')
3687 value = (int)(long)options[opt_idx].def_val[
3688 ((flags & P_VI_DEF) || cp_val)
3689 ? VI_DEFAULT : VIM_DEFAULT];
3690 else if (nextchar == '<')
3691 {
3692 /* For 'autoread' -1 means to use global value. */
3693 if ((int *)varp == &curbuf->b_p_ar
3694 && opt_flags == OPT_LOCAL)
3695 value = -1;
3696 else
3697 value = *(int *)get_varp_scope(&(options[opt_idx]),
3698 OPT_GLOBAL);
3699 }
3700 else
3701 {
3702 /*
3703 * ":set invopt": invert
3704 * ":set opt" or ":set noopt": set or reset
3705 */
3706 if (nextchar != NUL && !vim_iswhite(afterchar))
3707 {
3708 errmsg = e_trailing;
3709 goto skip;
3710 }
3711 if (prefix == 2) /* inv */
3712 value = *(int *)(varp) ^ 1;
3713 else
3714 value = prefix;
3715 }
3716
3717 errmsg = set_bool_option(opt_idx, varp, (int)value,
3718 opt_flags);
3719 }
3720 else /* numeric or string */
3721 {
3722 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
3723 || prefix != 1)
3724 {
3725 errmsg = e_invarg;
3726 goto skip;
3727 }
3728
3729 if (flags & P_NUM) /* numeric */
3730 {
3731 /*
3732 * Different ways to set a number option:
3733 * & set to default value
3734 * < set to global value
3735 * <xx> accept special key codes for 'wildchar'
3736 * c accept any non-digit for 'wildchar'
3737 * [-]0-9 set number
3738 * other error
3739 */
3740 ++arg;
3741 if (nextchar == '&')
3742 value = (long)options[opt_idx].def_val[
3743 ((flags & P_VI_DEF) || cp_val)
3744 ? VI_DEFAULT : VIM_DEFAULT];
3745 else if (nextchar == '<')
3746 value = *(long *)get_varp_scope(&(options[opt_idx]),
3747 OPT_GLOBAL);
3748 else if (((long *)varp == &p_wc
3749 || (long *)varp == &p_wcm)
3750 && (*arg == '<'
3751 || *arg == '^'
3752 || ((!arg[1] || vim_iswhite(arg[1]))
3753 && !VIM_ISDIGIT(*arg))))
3754 {
3755 value = string_to_key(arg);
3756 if (value == 0 && (long *)varp != &p_wcm)
3757 {
3758 errmsg = e_invarg;
3759 goto skip;
3760 }
3761 }
3762 /* allow negative numbers (for 'undolevels') */
3763 else if (*arg == '-' || VIM_ISDIGIT(*arg))
3764 {
3765 i = 0;
3766 if (*arg == '-')
3767 i = 1;
3768#ifdef HAVE_STRTOL
3769 value = strtol((char *)arg, NULL, 0);
3770 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
3771 i += 2;
3772#else
3773 value = atol((char *)arg);
3774#endif
3775 while (VIM_ISDIGIT(arg[i]))
3776 ++i;
3777 if (arg[i] != NUL && !vim_iswhite(arg[i]))
3778 {
3779 errmsg = e_invarg;
3780 goto skip;
3781 }
3782 }
3783 else
3784 {
3785 errmsg = (char_u *)N_("E521: Number required after =");
3786 goto skip;
3787 }
3788
3789 if (adding)
3790 value = *(long *)varp + value;
3791 if (prepending)
3792 value = *(long *)varp * value;
3793 if (removing)
3794 value = *(long *)varp - value;
3795 errmsg = set_num_option(opt_idx, varp, value,
3796 errbuf, opt_flags);
3797 }
3798 else if (opt_idx >= 0) /* string */
3799 {
3800 char_u *save_arg = NULL;
3801 char_u *s = NULL;
3802 char_u *oldval; /* previous value if *varp */
3803 char_u *newval;
3804 char_u *origval;
3805 unsigned newlen;
3806 int comma;
3807 int bs;
3808 int new_value_alloced; /* new string option
3809 was allocated */
3810
3811 /* When using ":set opt=val" for a global option
3812 * with a local value the local value will be
3813 * reset, use the global value here. */
3814 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
3815 && (int)options[opt_idx].indir >= PV_BOTH)
3816 varp = options[opt_idx].var;
3817
3818 /* The old value is kept until we are sure that the
3819 * new value is valid. */
3820 oldval = *(char_u **)varp;
3821 if (nextchar == '&') /* set to default val */
3822 {
3823 newval = options[opt_idx].def_val[
3824 ((flags & P_VI_DEF) || cp_val)
3825 ? VI_DEFAULT : VIM_DEFAULT];
3826 if ((char_u **)varp == &p_bg)
3827 {
3828 /* guess the value of 'background' */
3829#ifdef FEAT_GUI
3830 if (gui.in_use)
3831 newval = gui_bg_default();
3832 else
3833#endif
3834 if (STRCMP(T_NAME, "linux") == 0)
3835 newval = (char_u *)"dark";
3836 }
3837
3838 /* expand environment variables and ~ (since the
3839 * default value was already expanded, only
3840 * required when an environment variable was set
3841 * later */
3842 if (newval == NULL)
3843 newval = empty_option;
3844 else
3845 {
3846 s = option_expand(opt_idx, newval);
3847 if (s == NULL)
3848 s = newval;
3849 newval = vim_strsave(s);
3850 }
3851 new_value_alloced = TRUE;
3852 }
3853 else if (nextchar == '<') /* set to global val */
3854 {
3855 newval = vim_strsave(*(char_u **)get_varp_scope(
3856 &(options[opt_idx]), OPT_GLOBAL));
3857 new_value_alloced = TRUE;
3858 }
3859 else
3860 {
3861 ++arg; /* jump to after the '=' or ':' */
3862
3863 /*
3864 * Set 'keywordprg' to ":help" if an empty
3865 * value was passed to :set by the user.
3866 * Misuse errbuf[] for the resulting string.
3867 */
3868 if (varp == (char_u *)&p_kp
3869 && (*arg == NUL || *arg == ' '))
3870 {
3871 STRCPY(errbuf, ":help");
3872 save_arg = arg;
3873 arg = errbuf;
3874 }
3875 /*
3876 * Convert 'whichwrap' number to string, for
3877 * backwards compatibility with Vim 3.0.
3878 * Misuse errbuf[] for the resulting string.
3879 */
3880 else if (varp == (char_u *)&p_ww
3881 && VIM_ISDIGIT(*arg))
3882 {
3883 *errbuf = NUL;
3884 i = getdigits(&arg);
3885 if (i & 1)
3886 STRCAT(errbuf, "b,");
3887 if (i & 2)
3888 STRCAT(errbuf, "s,");
3889 if (i & 4)
3890 STRCAT(errbuf, "h,l,");
3891 if (i & 8)
3892 STRCAT(errbuf, "<,>,");
3893 if (i & 16)
3894 STRCAT(errbuf, "[,],");
3895 if (*errbuf != NUL) /* remove trailing , */
3896 errbuf[STRLEN(errbuf) - 1] = NUL;
3897 save_arg = arg;
3898 arg = errbuf;
3899 }
3900 /*
3901 * Remove '>' before 'dir' and 'bdir', for
3902 * backwards compatibility with version 3.0
3903 */
3904 else if ( *arg == '>'
3905 && (varp == (char_u *)&p_dir
3906 || varp == (char_u *)&p_bdir))
3907 {
3908 ++arg;
3909 }
3910
3911 /* When setting the local value of a global
3912 * option, the old value may be the global value. */
3913 if ((int)options[opt_idx].indir >= PV_BOTH
3914 && (opt_flags & OPT_LOCAL))
3915 origval = *(char_u **)get_varp(
3916 &options[opt_idx]);
3917 else
3918 origval = oldval;
3919
3920 /*
3921 * Copy the new string into allocated memory.
3922 * Can't use set_string_option_direct(), because
3923 * we need to remove the backslashes.
3924 */
3925 /* get a bit too much */
3926 newlen = (unsigned)STRLEN(arg) + 1;
3927 if (adding || prepending || removing)
3928 newlen += (unsigned)STRLEN(origval) + 1;
3929 newval = alloc(newlen);
3930 if (newval == NULL) /* out of mem, don't change */
3931 break;
3932 s = newval;
3933
3934 /*
3935 * Copy the string, skip over escaped chars.
3936 * For MS-DOS and WIN32 backslashes before normal
3937 * file name characters are not removed, and keep
3938 * backslash at start, for "\\machine\path", but
3939 * do remove it for "\\\\machine\\path".
3940 * The reverse is found in ExpandOldSetting().
3941 */
3942 while (*arg && !vim_iswhite(*arg))
3943 {
3944 if (*arg == '\\' && arg[1] != NUL
3945#ifdef BACKSLASH_IN_FILENAME
3946 && !((flags & P_EXPAND)
3947 && vim_isfilec(arg[1])
3948 && (arg[1] != '\\'
3949 || (s == newval
3950 && arg[2] != '\\')))
3951#endif
3952 )
3953 ++arg; /* remove backslash */
3954#ifdef FEAT_MBYTE
3955 if (has_mbyte
3956 && (i = (*mb_ptr2len_check)(arg)) > 1)
3957 {
3958 /* copy multibyte char */
3959 mch_memmove(s, arg, (size_t)i);
3960 arg += i;
3961 s += i;
3962 }
3963 else
3964#endif
3965 *s++ = *arg++;
3966 }
3967 *s = NUL;
3968
3969 /*
3970 * Expand environment variables and ~.
3971 * Don't do it when adding without inserting a
3972 * comma.
3973 */
3974 if (!(adding || prepending || removing)
3975 || (flags & P_COMMA))
3976 {
3977 s = option_expand(opt_idx, newval);
3978 if (s != NULL)
3979 {
3980 vim_free(newval);
3981 newlen = (unsigned)STRLEN(s) + 1;
3982 if (adding || prepending || removing)
3983 newlen += (unsigned)STRLEN(origval) + 1;
3984 newval = alloc(newlen);
3985 if (newval == NULL)
3986 break;
3987 STRCPY(newval, s);
3988 }
3989 }
3990
3991 /* locate newval[] in origval[] when removing it
3992 * and when adding to avoid duplicates */
3993 i = 0; /* init for GCC */
3994 if (removing || (flags & P_NODUP))
3995 {
3996 i = (int)STRLEN(newval);
3997 bs = 0;
3998 for (s = origval; *s; ++s)
3999 {
4000 if ((!(flags & P_COMMA)
4001 || s == origval
4002 || (s[-1] == ',' && !(bs & 1)))
4003 && STRNCMP(s, newval, i) == 0
4004 && (!(flags & P_COMMA)
4005 || s[i] == ','
4006 || s[i] == NUL))
4007 break;
4008 /* Count backspaces. Only a comma with an
4009 * even number of backspaces before it is
4010 * recognized as a separator */
4011 if (s > origval && s[-1] == '\\')
4012 ++bs;
4013 else
4014 bs = 0;
4015 }
4016
4017 /* do not add if already there */
4018 if ((adding || prepending) && *s)
4019 {
4020 prepending = FALSE;
4021 adding = FALSE;
4022 STRCPY(newval, origval);
4023 }
4024 }
4025
4026 /* concatenate the two strings; add a ',' if
4027 * needed */
4028 if (adding || prepending)
4029 {
4030 comma = ((flags & P_COMMA) && *origval != NUL
4031 && *newval != NUL);
4032 if (adding)
4033 {
4034 i = (int)STRLEN(origval);
4035 mch_memmove(newval + i + comma, newval,
4036 STRLEN(newval) + 1);
4037 mch_memmove(newval, origval, (size_t)i);
4038 }
4039 else
4040 {
4041 i = (int)STRLEN(newval);
4042 mch_memmove(newval + i + comma, origval,
4043 STRLEN(origval) + 1);
4044 }
4045 if (comma)
4046 newval[i] = ',';
4047 }
4048
4049 /* Remove newval[] from origval[]. (Note: "i" has
4050 * been set above and is used here). */
4051 if (removing)
4052 {
4053 STRCPY(newval, origval);
4054 if (*s)
4055 {
4056 /* may need to remove a comma */
4057 if (flags & P_COMMA)
4058 {
4059 if (s == origval)
4060 {
4061 /* include comma after string */
4062 if (s[i] == ',')
4063 ++i;
4064 }
4065 else
4066 {
4067 /* include comma before string */
4068 --s;
4069 ++i;
4070 }
4071 }
4072 mch_memmove(newval + (s - origval), s + i,
4073 STRLEN(s + i) + 1);
4074 }
4075 }
4076
4077 if (flags & P_FLAGLIST)
4078 {
4079 /* Remove flags that appear twice. */
4080 for (s = newval; *s; ++s)
4081 if ((!(flags & P_COMMA) || *s != ',')
4082 && vim_strchr(s + 1, *s) != NULL)
4083 {
4084 STRCPY(s, s + 1);
4085 --s;
4086 }
4087 }
4088
4089 if (save_arg != NULL) /* number for 'whichwrap' */
4090 arg = save_arg;
4091 new_value_alloced = TRUE;
4092 }
4093
4094 /* Set the new value. */
4095 *(char_u **)(varp) = newval;
4096
4097 /* Handle side effects, and set the global value for
4098 * ":set" on local options. */
4099 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4100 new_value_alloced, oldval, errbuf, opt_flags);
4101
4102 /* If error detected, print the error message. */
4103 if (errmsg != NULL)
4104 goto skip;
4105 }
4106 else /* key code option */
4107 {
4108 char_u *p;
4109
4110 if (nextchar == '&')
4111 {
4112 if (add_termcap_entry(key_name, TRUE) == FAIL)
4113 errmsg = (char_u *)N_("E522: Not found in termcap");
4114 }
4115 else
4116 {
4117 ++arg; /* jump to after the '=' or ':' */
4118 for (p = arg; *p && !vim_iswhite(*p); ++p)
4119 if (*p == '\\' && p[1] != NUL)
4120 ++p;
4121 nextchar = *p;
4122 *p = NUL;
4123 add_termcode(key_name, arg, FALSE);
4124 *p = nextchar;
4125 }
4126 if (full_screen)
4127 ttest(FALSE);
4128 redraw_all_later(CLEAR);
4129 }
4130 }
4131 if (opt_idx >= 0)
4132 options[opt_idx].flags |= P_WAS_SET;
4133 }
4134
4135skip:
4136 /*
4137 * Advance to next argument.
4138 * - skip until a blank found, taking care of backslashes
4139 * - skip blanks
4140 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4141 */
4142 for (i = 0; i < 2 ; ++i)
4143 {
4144 while (*arg != NUL && !vim_iswhite(*arg))
4145 if (*arg++ == '\\' && *arg != NUL)
4146 ++arg;
4147 arg = skipwhite(arg);
4148 if (*arg != '=')
4149 break;
4150 }
4151 }
4152
4153 if (errmsg != NULL)
4154 {
4155 STRNCPY(IObuff, _(errmsg), IOSIZE - 1);
4156 IObuff[IOSIZE - 1] = NUL;
4157 i = STRLEN(IObuff) + 2;
4158 if (i + (arg - startarg) < IOSIZE)
4159 {
4160 /* append the argument with the error */
4161 STRCAT(IObuff, ": ");
4162 mch_memmove(IObuff + i, startarg, (arg - startarg));
4163 IObuff[i + (arg - startarg)] = NUL;
4164 }
4165 /* make sure all characters are printable */
4166 trans_characters(IObuff, IOSIZE);
4167
4168 ++no_wait_return; /* wait_return done later */
4169 emsg(IObuff); /* show error highlighted */
4170 --no_wait_return;
4171
4172 return FAIL;
4173 }
4174
4175 arg = skipwhite(arg);
4176 }
4177
4178 return OK;
4179}
4180
4181 static char_u *
4182illegal_char(errbuf, c)
4183 char_u *errbuf;
4184 int c;
4185{
4186 if (errbuf == NULL)
4187 return (char_u *)"";
4188 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
4189 (char *)transchar(c));
4190 return errbuf;
4191}
4192
4193/*
4194 * Convert a key name or string into a key value.
4195 * Used for 'wildchar' and 'cedit' options.
4196 */
4197 static int
4198string_to_key(arg)
4199 char_u *arg;
4200{
4201 if (*arg == '<')
4202 return find_key_option(arg + 1);
4203 if (*arg == '^')
4204 return Ctrl_chr(arg[1]);
4205 return *arg;
4206}
4207
4208#ifdef FEAT_CMDWIN
4209/*
4210 * Check value of 'cedit' and set cedit_key.
4211 * Returns NULL if value is OK, error message otherwise.
4212 */
4213 static char_u *
4214check_cedit()
4215{
4216 int n;
4217
4218 if (*p_cedit == NUL)
4219 cedit_key = -1;
4220 else
4221 {
4222 n = string_to_key(p_cedit);
4223 if (vim_isprintc(n))
4224 return e_invarg;
4225 cedit_key = n;
4226 }
4227 return NULL;
4228}
4229#endif
4230
4231#ifdef FEAT_TITLE
4232/*
4233 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4234 * maketitle() to create and display it.
4235 * When switching the title or icon off, call mch_restore_title() to get
4236 * the old value back.
4237 */
4238 static void
4239did_set_title(icon)
4240 int icon; /* Did set icon instead of title */
4241{
4242 if (starting != NO_SCREEN
4243#ifdef FEAT_GUI
4244 && !gui.starting
4245#endif
4246 )
4247 {
4248 maketitle();
4249 if (icon)
4250 {
4251 if (!p_icon)
4252 mch_restore_title(2);
4253 }
4254 else
4255 {
4256 if (!p_title)
4257 mch_restore_title(1);
4258 }
4259 }
4260}
4261#endif
4262
4263/*
4264 * set_options_bin - called when 'bin' changes value.
4265 */
4266 void
4267set_options_bin(oldval, newval, opt_flags)
4268 int oldval;
4269 int newval;
4270 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4271{
4272 /*
4273 * The option values that are changed when 'bin' changes are
4274 * copied when 'bin is set and restored when 'bin' is reset.
4275 */
4276 if (newval)
4277 {
4278 if (!oldval) /* switched on */
4279 {
4280 if (!(opt_flags & OPT_GLOBAL))
4281 {
4282 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4283 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4284 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4285 curbuf->b_p_et_nobin = curbuf->b_p_et;
4286 }
4287 if (!(opt_flags & OPT_LOCAL))
4288 {
4289 p_tw_nobin = p_tw;
4290 p_wm_nobin = p_wm;
4291 p_ml_nobin = p_ml;
4292 p_et_nobin = p_et;
4293 }
4294 }
4295
4296 if (!(opt_flags & OPT_GLOBAL))
4297 {
4298 curbuf->b_p_tw = 0; /* no automatic line wrap */
4299 curbuf->b_p_wm = 0; /* no automatic line wrap */
4300 curbuf->b_p_ml = 0; /* no modelines */
4301 curbuf->b_p_et = 0; /* no expandtab */
4302 }
4303 if (!(opt_flags & OPT_LOCAL))
4304 {
4305 p_tw = 0;
4306 p_wm = 0;
4307 p_ml = FALSE;
4308 p_et = FALSE;
4309 p_bin = TRUE; /* needed when called for the "-b" argument */
4310 }
4311 }
4312 else if (oldval) /* switched off */
4313 {
4314 if (!(opt_flags & OPT_GLOBAL))
4315 {
4316 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4317 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4318 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4319 curbuf->b_p_et = curbuf->b_p_et_nobin;
4320 }
4321 if (!(opt_flags & OPT_LOCAL))
4322 {
4323 p_tw = p_tw_nobin;
4324 p_wm = p_wm_nobin;
4325 p_ml = p_ml_nobin;
4326 p_et = p_et_nobin;
4327 }
4328 }
4329}
4330
4331#ifdef FEAT_VIMINFO
4332/*
4333 * Find the parameter represented by the given character (eg ', :, ", or /),
4334 * and return its associated value in the 'viminfo' string.
4335 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004336 * If the parameter is not specified in the string or there is no following
4337 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004338 */
4339 int
4340get_viminfo_parameter(type)
4341 int type;
4342{
4343 char_u *p;
4344
4345 p = find_viminfo_parameter(type);
4346 if (p != NULL && VIM_ISDIGIT(*p))
4347 return atoi((char *)p);
4348 return -1;
4349}
4350
4351/*
4352 * Find the parameter represented by the given character (eg ''', ':', '"', or
4353 * '/') in the 'viminfo' option and return a pointer to the string after it.
4354 * Return NULL if the parameter is not specified in the string.
4355 */
4356 char_u *
4357find_viminfo_parameter(type)
4358 int type;
4359{
4360 char_u *p;
4361
4362 for (p = p_viminfo; *p; ++p)
4363 {
4364 if (*p == type)
4365 return p + 1;
4366 if (*p == 'n') /* 'n' is always the last one */
4367 break;
4368 p = vim_strchr(p, ','); /* skip until next ',' */
4369 if (p == NULL) /* hit the end without finding parameter */
4370 break;
4371 }
4372 return NULL;
4373}
4374#endif
4375
4376/*
4377 * Expand environment variables for some string options.
4378 * These string options cannot be indirect!
4379 * If "val" is NULL expand the current value of the option.
4380 * Return pointer to NameBuff, or NULL when not expanded.
4381 */
4382 static char_u *
4383option_expand(opt_idx, val)
4384 int opt_idx;
4385 char_u *val;
4386{
4387 /* if option doesn't need expansion nothing to do */
4388 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4389 return NULL;
4390
4391 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4392 * expand_env() would truncate the string. */
4393 if (val != NULL && STRLEN(val) > MAXPATHL)
4394 return NULL;
4395
4396 if (val == NULL)
4397 val = *(char_u **)options[opt_idx].var;
4398
4399 /*
4400 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4401 * Escape spaces when expanding 'tags', they are used to separate file
4402 * names.
4403 */
4404 expand_env_esc(val, NameBuff, MAXPATHL,
4405 (char_u **)options[opt_idx].var == &p_tags);
4406 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4407 return NULL;
4408
4409 return NameBuff;
4410}
4411
4412/*
4413 * After setting various option values: recompute variables that depend on
4414 * option values.
4415 */
4416 static void
4417didset_options()
4418{
4419 /* initialize the table for 'iskeyword' et.al. */
4420 (void)init_chartab();
4421
4422 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4423 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4424#ifdef FEAT_SESSION
4425 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4426 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4427#endif
4428#ifdef FEAT_FOLDING
4429 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4430#endif
4431 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4432#ifdef FEAT_VIRTUALEDIT
4433 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4434#endif
4435#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4436 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4437#endif
4438#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4439 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4440#endif
4441#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4442 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4443#endif
4444#ifdef FEAT_CMDWIN
4445 /* set cedit_key */
4446 (void)check_cedit();
4447#endif
4448}
4449
4450/*
4451 * Check for string options that are NULL (normally only termcap options).
4452 */
4453 void
4454check_options()
4455{
4456 int opt_idx;
4457
4458 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4459 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4460 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4461}
4462
4463/*
4464 * Check string options in a buffer for NULL value.
4465 */
4466 void
4467check_buf_options(buf)
4468 buf_T *buf;
4469{
4470#if defined(FEAT_QUICKFIX)
4471 check_string_option(&buf->b_p_bh);
4472 check_string_option(&buf->b_p_bt);
4473#endif
4474#ifdef FEAT_MBYTE
4475 check_string_option(&buf->b_p_fenc);
4476#endif
4477 check_string_option(&buf->b_p_ff);
4478#ifdef FEAT_FIND_ID
4479 check_string_option(&buf->b_p_def);
4480 check_string_option(&buf->b_p_inc);
4481# ifdef FEAT_EVAL
4482 check_string_option(&buf->b_p_inex);
4483# endif
4484#endif
4485#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4486 check_string_option(&buf->b_p_inde);
4487 check_string_option(&buf->b_p_indk);
4488#endif
4489#ifdef FEAT_CRYPT
4490 check_string_option(&buf->b_p_key);
4491#endif
4492 check_string_option(&buf->b_p_kp);
4493 check_string_option(&buf->b_p_mps);
4494 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004495 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004496 check_string_option(&buf->b_p_isk);
4497#ifdef FEAT_COMMENTS
4498 check_string_option(&buf->b_p_com);
4499#endif
4500#ifdef FEAT_FOLDING
4501 check_string_option(&buf->b_p_cms);
4502#endif
4503 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004504#ifdef FEAT_TEXTOBJ
4505 check_string_option(&buf->b_p_qe);
4506#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004507#ifdef FEAT_SYN_HL
4508 check_string_option(&buf->b_p_syn);
4509#endif
4510#ifdef FEAT_SEARCHPATH
4511 check_string_option(&buf->b_p_sua);
4512#endif
4513#ifdef FEAT_CINDENT
4514 check_string_option(&buf->b_p_cink);
4515 check_string_option(&buf->b_p_cino);
4516#endif
4517#ifdef FEAT_AUTOCMD
4518 check_string_option(&buf->b_p_ft);
4519#endif
4520#ifdef FEAT_OSFILETYPE
4521 check_string_option(&buf->b_p_oft);
4522#endif
4523#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4524 check_string_option(&buf->b_p_cinw);
4525#endif
4526#ifdef FEAT_INS_EXPAND
4527 check_string_option(&buf->b_p_cpt);
4528#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004529#ifdef FEAT_COMPL_FUNC
4530 check_string_option(&buf->b_p_cfu);
4531#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004532#ifdef FEAT_KEYMAP
4533 check_string_option(&buf->b_p_keymap);
4534#endif
4535#ifdef FEAT_QUICKFIX
4536 check_string_option(&buf->b_p_gp);
4537 check_string_option(&buf->b_p_mp);
4538 check_string_option(&buf->b_p_efm);
4539#endif
4540 check_string_option(&buf->b_p_ep);
4541 check_string_option(&buf->b_p_path);
4542 check_string_option(&buf->b_p_tags);
4543#ifdef FEAT_INS_EXPAND
4544 check_string_option(&buf->b_p_dict);
4545 check_string_option(&buf->b_p_tsr);
4546#endif
4547}
4548
4549/*
4550 * Free the string allocated for an option.
4551 * Checks for the string being empty_option. This may happen if we're out of
4552 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4553 * check_options().
4554 * Does NOT check for P_ALLOCED flag!
4555 */
4556 void
4557free_string_option(p)
4558 char_u *p;
4559{
4560 if (p != empty_option)
4561 vim_free(p);
4562}
4563
4564 void
4565clear_string_option(pp)
4566 char_u **pp;
4567{
4568 if (*pp != empty_option)
4569 vim_free(*pp);
4570 *pp = empty_option;
4571}
4572
4573 static void
4574check_string_option(pp)
4575 char_u **pp;
4576{
4577 if (*pp == NULL)
4578 *pp = empty_option;
4579}
4580
4581/*
4582 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4583 */
4584 void
4585set_term_option_alloced(p)
4586 char_u **p;
4587{
4588 int opt_idx;
4589
4590 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4591 if (options[opt_idx].var == (char_u *)p)
4592 {
4593 options[opt_idx].flags |= P_ALLOCED;
4594 return;
4595 }
4596 return; /* cannot happen: didn't find it! */
4597}
4598
4599/*
4600 * Set a string option to a new value (without checking the effect).
4601 * The string is copied into allocated memory.
4602 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4603 */
4604 void
4605set_string_option_direct(name, opt_idx, val, opt_flags)
4606 char_u *name;
4607 int opt_idx;
4608 char_u *val;
4609 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4610{
4611 char_u *s;
4612 char_u **varp;
4613 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
4614
4615 if (opt_idx == -1) /* use name */
4616 {
4617 opt_idx = findoption(name);
4618 if (opt_idx == -1) /* not found (should not happen) */
4619 return;
4620 }
4621
4622 if (options[opt_idx].var == NULL) /* can't set hidden option */
4623 return;
4624
4625 s = vim_strsave(val);
4626 if (s != NULL)
4627 {
4628 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4629 both ? OPT_LOCAL : opt_flags);
4630 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
4631 free_string_option(*varp);
4632 *varp = s;
4633
4634 /* For buffer/window local option may also set the global value. */
4635 if (both)
4636 set_string_option_global(opt_idx, varp);
4637
4638 options[opt_idx].flags |= P_ALLOCED;
4639
4640 /* When setting both values of a global option with a local value,
4641 * make the local value empty, so that the global value is used. */
4642 if ((int)options[opt_idx].indir >= PV_BOTH && both)
4643 {
4644 free_string_option(*varp);
4645 *varp = empty_option;
4646 }
4647 }
4648}
4649
4650/*
4651 * Set global value for string option when it's a local option.
4652 */
4653 static void
4654set_string_option_global(opt_idx, varp)
4655 int opt_idx; /* option index */
4656 char_u **varp; /* pointer to option variable */
4657{
4658 char_u **p, *s;
4659
4660 /* the global value is always allocated */
4661 if (options[opt_idx].var == VAR_WIN)
4662 p = (char_u **)GLOBAL_WO(varp);
4663 else
4664 p = (char_u **)options[opt_idx].var;
4665 if (options[opt_idx].indir != PV_NONE
4666 && p != varp
4667 && (s = vim_strsave(*varp)) != NULL)
4668 {
4669 free_string_option(*p);
4670 *p = s;
4671 }
4672}
4673
4674/*
4675 * Set a string option to a new value, and handle the effects.
4676 */
4677 static void
4678set_string_option(opt_idx, value, opt_flags)
4679 int opt_idx;
4680 char_u *value;
4681 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4682{
4683 char_u *s;
4684 char_u **varp;
4685 char_u *oldval;
4686
4687 if (options[opt_idx].var == NULL) /* don't set hidden option */
4688 return;
4689
4690 s = vim_strsave(value);
4691 if (s != NULL)
4692 {
4693 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4694 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4695 ? ((int)options[opt_idx].indir >= PV_BOTH
4696 ? OPT_GLOBAL : OPT_LOCAL)
4697 : opt_flags);
4698 oldval = *varp;
4699 *varp = s;
4700 options[opt_idx].flags |= P_WAS_SET;
4701 (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
4702 opt_flags);
4703 }
4704}
4705
4706/*
4707 * Handle string options that need some action to perform when changed.
4708 * Returns NULL for success, or an error message for an error.
4709 */
4710 static char_u *
4711did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
4712 opt_flags)
4713 int opt_idx; /* index in options[] table */
4714 char_u **varp; /* pointer to the option variable */
4715 int new_value_alloced; /* new value was allocated */
4716 char_u *oldval; /* previous value of the option */
4717 char_u *errbuf; /* buffer for errors, or NULL */
4718 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4719{
4720 char_u *errmsg = NULL;
4721 char_u *s, *p;
4722 int did_chartab = FALSE;
4723 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00004724 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004725
4726 /* Get the global option to compare with, otherwise we would have to check
4727 * two values for all local options. */
4728 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
4729
4730 /* Disallow changing some options from secure mode */
4731 if ((secure
4732#ifdef HAVE_SANDBOX
4733 || sandbox != 0
4734#endif
4735 ) && (options[opt_idx].flags & P_SECURE))
4736 {
4737 errmsg = e_secure;
4738 }
4739
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004740 /* Check for a "normal" file name in some options. Disallow a path
4741 * separator (slash and/or backslash), wildcards and characters that are
4742 * often illegal in a file name. */
4743 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004744 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004745 {
4746 errmsg = e_invarg;
4747 }
4748
Bram Moolenaar071d4272004-06-13 20:20:40 +00004749 /* 'term' */
4750 else if (varp == &T_NAME)
4751 {
4752 if (T_NAME[0] == NUL)
4753 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
4754#ifdef FEAT_GUI
4755 if (gui.in_use)
4756 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
4757 else if (term_is_gui(T_NAME))
4758 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
4759#endif
4760 else if (set_termname(T_NAME) == FAIL)
4761 errmsg = (char_u *)N_("E522: Not found in termcap");
4762 else
4763 /* Screen colors may have changed. */
4764 redraw_later_clear();
4765 }
4766
4767 /* 'backupcopy' */
4768 else if (varp == &p_bkc)
4769 {
4770 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
4771 errmsg = e_invarg;
4772 if (((bkc_flags & BKC_AUTO) != 0)
4773 + ((bkc_flags & BKC_YES) != 0)
4774 + ((bkc_flags & BKC_NO) != 0) != 1)
4775 {
4776 /* Must have exactly one of "auto", "yes" and "no". */
4777 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
4778 errmsg = e_invarg;
4779 }
4780 }
4781
4782 /* 'backupext' and 'patchmode' */
4783 else if (varp == &p_bex || varp == &p_pm)
4784 {
4785 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
4786 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
4787 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
4788 }
4789
4790 /*
4791 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
4792 * If the new option is invalid, use old value. 'lisp' option: refill
4793 * chartab[] for '-' char
4794 */
4795 else if ( varp == &p_isi
4796 || varp == &(curbuf->b_p_isk)
4797 || varp == &p_isp
4798 || varp == &p_isf)
4799 {
4800 if (init_chartab() == FAIL)
4801 {
4802 did_chartab = TRUE; /* need to restore it below */
4803 errmsg = e_invarg; /* error in value */
4804 }
4805 }
4806
4807 /* 'helpfile' */
4808 else if (varp == &p_hf)
4809 {
4810 /* May compute new values for $VIM and $VIMRUNTIME */
4811 if (didset_vim)
4812 {
4813 vim_setenv((char_u *)"VIM", (char_u *)"");
4814 didset_vim = FALSE;
4815 }
4816 if (didset_vimruntime)
4817 {
4818 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
4819 didset_vimruntime = FALSE;
4820 }
4821 }
4822
4823#ifdef FEAT_MULTI_LANG
4824 /* 'helplang' */
4825 else if (varp == &p_hlg)
4826 {
4827 /* Check for "", "ab", "ab,cd", etc. */
4828 for (s = p_hlg; *s != NUL; s += 3)
4829 {
4830 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
4831 {
4832 errmsg = e_invarg;
4833 break;
4834 }
4835 if (s[2] == NUL)
4836 break;
4837 }
4838 }
4839#endif
4840
4841 /* 'highlight' */
4842 else if (varp == &p_hl)
4843 {
4844 if (highlight_changed() == FAIL)
4845 errmsg = e_invarg; /* invalid flags */
4846 }
4847
4848 /* 'nrformats' */
4849 else if (gvarp == &p_nf)
4850 {
4851 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
4852 errmsg = e_invarg;
4853 }
4854
4855#ifdef FEAT_SESSION
4856 /* 'sessionoptions' */
4857 else if (varp == &p_ssop)
4858 {
4859 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
4860 errmsg = e_invarg;
4861 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
4862 {
4863 /* Don't allow both "sesdir" and "curdir". */
4864 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
4865 errmsg = e_invarg;
4866 }
4867 }
4868 /* 'viewoptions' */
4869 else if (varp == &p_vop)
4870 {
4871 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
4872 errmsg = e_invarg;
4873 }
4874#endif
4875
4876 /* 'scrollopt' */
4877#ifdef FEAT_SCROLLBIND
4878 else if (varp == &p_sbo)
4879 {
4880 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
4881 errmsg = e_invarg;
4882 }
4883#endif
4884
4885 /* 'ambiwidth' */
4886#ifdef FEAT_MBYTE
4887 else if (varp == &p_ambw)
4888 {
4889 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
4890 errmsg = e_invarg;
4891 }
4892#endif
4893
4894 /* 'background' */
4895 else if (varp == &p_bg)
4896 {
4897 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
4898 {
4899#ifdef FEAT_EVAL
4900 int dark = (*p_bg == 'd');
4901#endif
4902
4903 init_highlight(FALSE, FALSE);
4904
4905#ifdef FEAT_EVAL
4906 if (dark != (*p_bg == 'd')
4907 && get_var_value((char_u *)"g:colors_name") != NULL)
4908 {
4909 /* The color scheme must have set 'background' back to another
4910 * value, that's not what we want here. Disable the color
4911 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00004912 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004913 free_string_option(p_bg);
4914 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
4915 check_string_option(&p_bg);
4916 init_highlight(FALSE, FALSE);
4917 }
4918#endif
4919 }
4920 else
4921 errmsg = e_invarg;
4922 }
4923
4924 /* 'wildmode' */
4925 else if (varp == &p_wim)
4926 {
4927 if (check_opt_wim() == FAIL)
4928 errmsg = e_invarg;
4929 }
4930
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00004931#ifdef FEAT_CMDL_COMPL
4932 /* 'wildoptions' */
4933 else if (varp == &p_wop)
4934 {
4935 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
4936 errmsg = e_invarg;
4937 }
4938#endif
4939
Bram Moolenaar071d4272004-06-13 20:20:40 +00004940#ifdef FEAT_WAK
4941 /* 'winaltkeys' */
4942 else if (varp == &p_wak)
4943 {
4944 if (*p_wak == NUL
4945 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
4946 errmsg = e_invarg;
4947# ifdef FEAT_MENU
4948# ifdef FEAT_GUI_MOTIF
4949 else if (gui.in_use)
4950 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
4951# else
4952# ifdef FEAT_GUI_GTK
4953 else if (gui.in_use)
4954 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
4955# endif
4956# endif
4957# endif
4958 }
4959#endif
4960
4961#ifdef FEAT_AUTOCMD
4962 /* 'eventignore' */
4963 else if (varp == &p_ei)
4964 {
4965 if (check_ei() == FAIL)
4966 errmsg = e_invarg;
4967 }
4968#endif
4969
4970#ifdef FEAT_MBYTE
4971 /* 'encoding' and 'fileencoding' */
4972 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
4973 {
4974 if (gvarp == &p_fenc)
4975 {
4976 if (!curbuf->b_p_ma)
4977 errmsg = e_modifiable;
4978 else if (vim_strchr(*varp, ',') != NULL)
4979 /* No comma allowed in 'fileencoding'; catches confusing it
4980 * with 'fileencodings'. */
4981 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004982 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004983 {
4984# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00004985 /* May show a "+" in the title now. */
4986 need_maketitle = TRUE;
4987# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004988 /* Add 'fileencoding' to the swap file. */
4989 ml_setflags(curbuf);
4990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004991 }
4992 if (errmsg == NULL)
4993 {
4994 /* canonize the value, so that STRCMP() can be used on it */
4995 p = enc_canonize(*varp);
4996 if (p != NULL)
4997 {
4998 vim_free(*varp);
4999 *varp = p;
5000 }
5001 if (varp == &p_enc)
5002 {
5003 errmsg = mb_init();
5004# ifdef FEAT_TITLE
5005 need_maketitle = TRUE;
5006# endif
5007 }
5008 }
5009
5010# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5011 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5012 {
5013 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5014 if (STRCMP(p_tenc, "utf-8") != 0)
5015 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5016 }
5017# endif
5018
5019 if (errmsg == NULL)
5020 {
5021# ifdef FEAT_KEYMAP
5022 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5023 * (with another encoding). */
5024 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5025 (void)keymap_init();
5026# endif
5027
5028 /* When 'termencoding' is not empty and 'encoding' changes or when
5029 * 'termencoding' changes, need to setup for keyboard input and
5030 * display output conversion. */
5031 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5032 {
5033 convert_setup(&input_conv, p_tenc, p_enc);
5034 convert_setup(&output_conv, p_enc, p_tenc);
5035 }
5036 }
5037 }
5038#endif
5039
5040#if defined(FEAT_POSTSCRIPT)
5041 else if (varp == &p_penc)
5042 {
5043 /* Canonize printencoding if VIM standard one */
5044 p = enc_canonize(p_penc);
5045 if (p != NULL)
5046 {
5047 vim_free(p_penc);
5048 p_penc = p;
5049 }
5050 else
5051 {
5052 /* Ensure lower case and '-' for '_' */
5053 for (s = p_penc; *s != NUL; s++)
5054 {
5055 if (*s == '_')
5056 *s = '-';
5057 else
5058 *s = TOLOWER_ASC(*s);
5059 }
5060 }
5061 }
5062#endif
5063
Bram Moolenaar843ee412004-06-30 16:16:41 +00005064#if defined(FEAT_XIM) && ( defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065 else if (varp == &p_imak)
5066 {
5067 if (gui.in_use && !im_xim_isvalid_imactivate())
5068 errmsg = e_invarg;
5069 }
5070#endif
5071
5072#ifdef FEAT_KEYMAP
5073 else if (varp == &curbuf->b_p_keymap)
5074 {
5075 /* load or unload key mapping tables */
5076 errmsg = keymap_init();
5077
5078 /* When successfully installed a new keymap switch on using it. */
5079 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5080 {
5081 curbuf->b_p_iminsert = B_IMODE_LMAP;
5082 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5083 curbuf->b_p_imsearch = B_IMODE_LMAP;
5084 set_iminsert_global();
5085 set_imsearch_global();
5086# ifdef FEAT_WINDOWS
5087 status_redraw_curbuf();
5088# endif
5089 }
5090 }
5091#endif
5092
5093 /* 'fileformat' */
5094 else if (gvarp == &p_ff)
5095 {
5096 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5097 errmsg = e_modifiable;
5098 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5099 errmsg = e_invarg;
5100 else
5101 {
5102 /* may also change 'textmode' */
5103 if (get_fileformat(curbuf) == EOL_DOS)
5104 curbuf->b_p_tx = TRUE;
5105 else
5106 curbuf->b_p_tx = FALSE;
5107#ifdef FEAT_TITLE
5108 need_maketitle = TRUE;
5109#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005110 /* update flag in swap file */
5111 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005112 }
5113 }
5114
5115 /* 'fileformats' */
5116 else if (varp == &p_ffs)
5117 {
5118 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5119 errmsg = e_invarg;
5120 else
5121 {
5122 /* also change 'textauto' */
5123 if (*p_ffs == NUL)
5124 p_ta = FALSE;
5125 else
5126 p_ta = TRUE;
5127 }
5128 }
5129
5130#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5131 /* 'cryptkey' */
5132 else if (gvarp == &p_key)
5133 {
5134 /* Make sure the ":set" command doesn't show the new value in the
5135 * history. */
5136 remove_key_from_history();
5137 }
5138#endif
5139
5140 /* 'matchpairs' */
5141 else if (gvarp == &p_mps)
5142 {
5143 /* Check for "x:y,x:y" */
5144 for (p = *varp; *p != NUL; p += 4)
5145 {
5146 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5147 {
5148 errmsg = e_invarg;
5149 break;
5150 }
5151 if (p[3] == NUL)
5152 break;
5153 }
5154 }
5155
5156#ifdef FEAT_COMMENTS
5157 /* 'comments' */
5158 else if (gvarp == &p_com)
5159 {
5160 for (s = *varp; *s; )
5161 {
5162 while (*s && *s != ':')
5163 {
5164 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5165 && !VIM_ISDIGIT(*s) && *s != '-')
5166 {
5167 errmsg = illegal_char(errbuf, *s);
5168 break;
5169 }
5170 ++s;
5171 }
5172 if (*s++ == NUL)
5173 errmsg = (char_u *)N_("E524: Missing colon");
5174 else if (*s == ',' || *s == NUL)
5175 errmsg = (char_u *)N_("E525: Zero length string");
5176 if (errmsg != NULL)
5177 break;
5178 while (*s && *s != ',')
5179 {
5180 if (*s == '\\' && s[1] != NUL)
5181 ++s;
5182 ++s;
5183 }
5184 s = skip_to_option_part(s);
5185 }
5186 }
5187#endif
5188
5189 /* 'listchars' */
5190 else if (varp == &p_lcs)
5191 {
5192 errmsg = set_chars_option(varp);
5193 }
5194
5195#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5196 /* 'fillchars' */
5197 else if (varp == &p_fcs)
5198 {
5199 errmsg = set_chars_option(varp);
5200 }
5201#endif
5202
5203#ifdef FEAT_CMDWIN
5204 /* 'cedit' */
5205 else if (varp == &p_cedit)
5206 {
5207 errmsg = check_cedit();
5208 }
5209#endif
5210
5211#ifdef FEAT_VIMINFO
5212 /* 'viminfo' */
5213 else if (varp == &p_viminfo)
5214 {
5215 for (s = p_viminfo; *s;)
5216 {
5217 /* Check it's a valid character */
5218 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5219 {
5220 errmsg = illegal_char(errbuf, *s);
5221 break;
5222 }
5223 if (*s == 'n') /* name is always last one */
5224 {
5225 break;
5226 }
5227 else if (*s == 'r') /* skip until next ',' */
5228 {
5229 while (*++s && *s != ',')
5230 ;
5231 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005232 else if (*s == '%')
5233 {
5234 /* optional number */
5235 while (vim_isdigit(*++s))
5236 ;
5237 }
5238 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005239 ++s; /* no extra chars */
5240 else /* must have a number */
5241 {
5242 while (vim_isdigit(*++s))
5243 ;
5244
5245 if (!VIM_ISDIGIT(*(s - 1)))
5246 {
5247 if (errbuf != NULL)
5248 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005249 sprintf((char *)errbuf,
5250 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005251 transchar_byte(*(s - 1)));
5252 errmsg = errbuf;
5253 }
5254 else
5255 errmsg = (char_u *)"";
5256 break;
5257 }
5258 }
5259 if (*s == ',')
5260 ++s;
5261 else if (*s)
5262 {
5263 if (errbuf != NULL)
5264 errmsg = (char_u *)N_("E527: Missing comma");
5265 else
5266 errmsg = (char_u *)"";
5267 break;
5268 }
5269 }
5270 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5271 errmsg = (char_u *)N_("E528: Must specify a ' value");
5272 }
5273#endif /* FEAT_VIMINFO */
5274
5275 /* terminal options */
5276 else if (istermoption(&options[opt_idx]) && full_screen)
5277 {
5278 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5279 if (varp == &T_CCO)
5280 {
5281 t_colors = atoi((char *)T_CCO);
5282 if (t_colors <= 1)
5283 {
5284 if (new_value_alloced)
5285 vim_free(T_CCO);
5286 T_CCO = empty_option;
5287 }
5288 /* We now have a different color setup, initialize it again. */
5289 init_highlight(TRUE, FALSE);
5290 }
5291 ttest(FALSE);
5292 if (varp == &T_ME)
5293 {
5294 out_str(T_ME);
5295 redraw_later(CLEAR);
5296#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5297 /* Since t_me has been set, this probably means that the user
5298 * wants to use this as default colors. Need to reset default
5299 * background/foreground colors. */
5300 mch_set_normal_colors();
5301#endif
5302 }
5303 }
5304
5305#ifdef FEAT_LINEBREAK
5306 /* 'showbreak' */
5307 else if (varp == &p_sbr)
5308 {
5309 for (s = p_sbr; *s; )
5310 {
5311 if (ptr2cells(s) != 1)
5312 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005313 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005314 }
5315 }
5316#endif
5317
5318#ifdef FEAT_GUI
5319 /* 'guifont' */
5320 else if (varp == &p_guifont)
5321 {
5322 if (gui.in_use)
5323 {
5324 p = p_guifont;
Bram Moolenaar843ee412004-06-30 16:16:41 +00005325# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 /*
5327 * Put up a font dialog and let the user select a new value.
5328 * If this is cancelled go back to the old value but don't
5329 * give an error message.
5330 */
5331 if (STRCMP(p, "*") == 0)
5332 {
5333 p = gui_mch_font_dialog(oldval);
5334
5335 if (new_value_alloced)
5336 free_string_option(p_guifont);
5337
5338 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5339 new_value_alloced = TRUE;
5340 }
5341# endif
5342 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5343 {
5344# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5345 if (STRCMP(p_guifont, "*") == 0)
5346 {
5347 /* Dialog was cancelled: Keep the old value without giving
5348 * an error message. */
5349 if (new_value_alloced)
5350 free_string_option(p_guifont);
5351 p_guifont = vim_strsave(oldval);
5352 new_value_alloced = TRUE;
5353 }
5354 else
5355# endif
5356 errmsg = (char_u *)N_("E596: Invalid font(s)");
5357 }
5358 }
5359 }
5360# ifdef FEAT_XFONTSET
5361 else if (varp == &p_guifontset)
5362 {
5363 if (STRCMP(p_guifontset, "*") == 0)
5364 errmsg = (char_u *)N_("E597: can't select fontset");
5365 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5366 errmsg = (char_u *)N_("E598: Invalid fontset");
5367 }
5368# endif
5369# ifdef FEAT_MBYTE
5370 else if (varp == &p_guifontwide)
5371 {
5372 if (STRCMP(p_guifontwide, "*") == 0)
5373 errmsg = (char_u *)N_("E533: can't select wide font");
5374 else if (gui_get_wide_font() == FAIL)
5375 errmsg = (char_u *)N_("E534: Invalid wide font");
5376 }
5377# endif
5378#endif
5379
5380#ifdef CURSOR_SHAPE
5381 /* 'guicursor' */
5382 else if (varp == &p_guicursor)
5383 errmsg = parse_shape_opt(SHAPE_CURSOR);
5384#endif
5385
5386#ifdef FEAT_MOUSESHAPE
5387 /* 'mouseshape' */
5388 else if (varp == &p_mouseshape)
5389 {
5390 errmsg = parse_shape_opt(SHAPE_MOUSE);
5391 update_mouseshape(-1);
5392 }
5393#endif
5394
5395#ifdef FEAT_PRINTER
5396 else if (varp == &p_popt)
Bram Moolenaar269ec652004-07-29 08:43:53 +00005397 errmsg = parse_list_options(p_popt, printer_opts,
5398 OPT_PRINT_NUM_OPTIONS);
Bram Moolenaar8299df92004-07-10 09:47:34 +00005399
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005400# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005401 else if (varp == &p_pmfn)
Bram Moolenaar269ec652004-07-29 08:43:53 +00005402 errmsg = parse_list_options(p_pmfn, mbfont_opts,
5403 OPT_MBFONT_NUM_OPTIONS);
Bram Moolenaar8299df92004-07-10 09:47:34 +00005404# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005405#endif
5406
5407#ifdef FEAT_LANGMAP
5408 /* 'langmap' */
5409 else if (varp == &p_langmap)
5410 langmap_set();
5411#endif
5412
5413#ifdef FEAT_LINEBREAK
5414 /* 'breakat' */
5415 else if (varp == &p_breakat)
5416 fill_breakat_flags();
5417#endif
5418
5419#ifdef FEAT_TITLE
5420 /* 'titlestring' and 'iconstring' */
5421 else if (varp == &p_titlestring || varp == &p_iconstring)
5422 {
5423# ifdef FEAT_STL_OPT
5424 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5425
5426 /* NULL => statusline syntax */
5427 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5428 stl_syntax |= flagval;
5429 else
5430 stl_syntax &= ~flagval;
5431# endif
5432 did_set_title(varp == &p_iconstring);
5433
5434 }
5435#endif
5436
5437#ifdef FEAT_GUI
5438 /* 'guioptions' */
5439 else if (varp == &p_go)
5440 gui_init_which_components(oldval);
5441#endif
5442
5443#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5444 /* 'ttymouse' */
5445 else if (varp == &p_ttym)
5446 {
5447 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5448 errmsg = e_invarg;
5449 else
5450 check_mouse_termcode();
5451 }
5452#endif
5453
5454#ifdef FEAT_VISUAL
5455 /* 'selection' */
5456 else if (varp == &p_sel)
5457 {
5458 if (*p_sel == NUL
5459 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5460 errmsg = e_invarg;
5461 }
5462
5463 /* 'selectmode' */
5464 else if (varp == &p_slm)
5465 {
5466 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5467 errmsg = e_invarg;
5468 }
5469#endif
5470
5471#ifdef FEAT_BROWSE
5472 /* 'browsedir' */
5473 else if (varp == &p_bsdir)
5474 {
5475 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5476 && !mch_isdir(p_bsdir))
5477 errmsg = e_invarg;
5478 }
5479#endif
5480
5481#ifdef FEAT_VISUAL
5482 /* 'keymodel' */
5483 else if (varp == &p_km)
5484 {
5485 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5486 errmsg = e_invarg;
5487 else
5488 {
5489 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5490 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5491 }
5492 }
5493#endif
5494
5495 /* 'mousemodel' */
5496 else if (varp == &p_mousem)
5497 {
5498 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5499 errmsg = e_invarg;
5500#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5501 else if (*p_mousem != *oldval)
5502 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5503 * to create or delete the popup menus. */
5504 gui_motif_update_mousemodel(root_menu);
5505#endif
5506 }
5507
5508 /* 'switchbuf' */
5509 else if (varp == &p_swb)
5510 {
5511 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5512 errmsg = e_invarg;
5513 }
5514
5515 /* 'debug' */
5516 else if (varp == &p_debug)
5517 {
5518 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5519 errmsg = e_invarg;
5520 }
5521
5522 /* 'display' */
5523 else if (varp == &p_dy)
5524 {
5525 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5526 errmsg = e_invarg;
5527 else
5528 (void)init_chartab();
5529
5530 }
5531
5532#ifdef FEAT_VERTSPLIT
5533 /* 'eadirection' */
5534 else if (varp == &p_ead)
5535 {
5536 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5537 errmsg = e_invarg;
5538 }
5539#endif
5540
5541#ifdef FEAT_CLIPBOARD
5542 /* 'clipboard' */
5543 else if (varp == &p_cb)
5544 errmsg = check_clipboard_option();
5545#endif
5546
5547#ifdef FEAT_AUTOCMD
5548# ifdef FEAT_SYN_HL
5549 /* When 'syntax' is set, load the syntax of that name */
5550 else if (varp == &(curbuf->b_p_syn))
5551 {
5552 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
5553 curbuf->b_fname, TRUE, curbuf);
5554 }
5555# endif
5556
5557 /* When 'filetype' is set, trigger the FileType autocommands of that name */
5558 else if (varp == &(curbuf->b_p_ft))
5559 {
5560 did_filetype = TRUE;
5561 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
5562 curbuf->b_fname, TRUE, curbuf);
5563 }
5564#endif
5565
5566#ifdef FEAT_QUICKFIX
5567 /* When 'bufhidden' is set, check for valid value. */
5568 else if (gvarp == &p_bh)
5569 {
5570 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5571 errmsg = e_invarg;
5572 }
5573
5574 /* When 'buftype' is set, check for valid value. */
5575 else if (gvarp == &p_bt)
5576 {
5577 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5578 errmsg = e_invarg;
5579 else
5580 {
5581# ifdef FEAT_WINDOWS
5582 if (curwin->w_status_height)
5583 {
5584 curwin->w_redr_status = TRUE;
5585 redraw_later(VALID);
5586 }
5587# endif
5588 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5589 }
5590 }
5591#endif
5592
5593#ifdef FEAT_STL_OPT
5594 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005595 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005596 {
5597 int wid;
5598
5599 if (varp == &p_ruf) /* reset ru_wid first */
5600 ru_wid = 0;
5601 s = *varp;
5602 if (varp == &p_ruf && *s == '%')
5603 {
5604 /* set ru_wid if 'ruf' starts with "%99(" */
5605 if (*++s == '-') /* ignore a '-' */
5606 s++;
5607 wid = getdigits(&s);
5608 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5609 ru_wid = wid;
5610 else
5611 errmsg = check_stl_option(p_ruf);
5612 }
5613 else
5614 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005615 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005616 comp_col();
5617 }
5618#endif
5619
5620#ifdef FEAT_INS_EXPAND
5621 /* check if it is a valid value for 'complete' -- Acevedo */
5622 else if (gvarp == &p_cpt)
5623 {
5624 for (s = *varp; *s;)
5625 {
5626 while(*s == ',' || *s == ' ')
5627 s++;
5628 if (!*s)
5629 break;
5630 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5631 {
5632 errmsg = illegal_char(errbuf, *s);
5633 break;
5634 }
5635 if (*++s != NUL && *s != ',' && *s != ' ')
5636 {
5637 if (s[-1] == 'k' || s[-1] == 's')
5638 {
5639 /* skip optional filename after 'k' and 's' */
5640 while (*s && *s != ',' && *s != ' ')
5641 {
5642 if (*s == '\\')
5643 ++s;
5644 ++s;
5645 }
5646 }
5647 else
5648 {
5649 if (errbuf != NULL)
5650 {
5651 sprintf((char *)errbuf,
5652 _("E535: Illegal character after <%c>"),
5653 *--s);
5654 errmsg = errbuf;
5655 }
5656 else
5657 errmsg = (char_u *)"";
5658 break;
5659 }
5660 }
5661 }
5662 }
5663#endif /* FEAT_INS_EXPAND */
5664
5665
5666#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5667 else if (varp == &p_toolbar)
5668 {
5669 if (opt_strings_flags(p_toolbar, p_toolbar_values,
5670 &toolbar_flags, TRUE) != OK)
5671 errmsg = e_invarg;
5672 else
5673 {
5674 out_flush();
5675 gui_mch_show_toolbar((toolbar_flags &
5676 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5677 }
5678 }
5679#endif
5680
5681#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5682 /* 'toolbariconsize': GTK+ 2 only */
5683 else if (varp == &p_tbis)
5684 {
5685 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
5686 errmsg = e_invarg;
5687 else
5688 {
5689 out_flush();
5690 gui_mch_show_toolbar((toolbar_flags &
5691 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5692 }
5693 }
5694#endif
5695
5696 /* 'pastetoggle': translate key codes like in a mapping */
5697 else if (varp == &p_pt)
5698 {
5699 if (*p_pt)
5700 {
5701 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
5702 if (p != NULL)
5703 {
5704 if (new_value_alloced)
5705 free_string_option(p_pt);
5706 p_pt = p;
5707 new_value_alloced = TRUE;
5708 }
5709 }
5710 }
5711
5712 /* 'backspace' */
5713 else if (varp == &p_bs)
5714 {
5715 if (VIM_ISDIGIT(*p_bs))
5716 {
5717 if (*p_bs >'2' || p_bs[1] != NUL)
5718 errmsg = e_invarg;
5719 }
5720 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
5721 errmsg = e_invarg;
5722 }
5723
5724 /* 'casemap' */
5725 else if (varp == &p_cmp)
5726 {
5727 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
5728 errmsg = e_invarg;
5729 }
5730
5731#ifdef FEAT_DIFF
5732 /* 'diffopt' */
5733 else if (varp == &p_dip)
5734 {
5735 if (diffopt_changed() == FAIL)
5736 errmsg = e_invarg;
5737 }
5738#endif
5739
5740#ifdef FEAT_FOLDING
5741 /* 'foldmethod' */
5742 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
5743 {
5744 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
5745 || *curwin->w_p_fdm == NUL)
5746 errmsg = e_invarg;
5747 else
5748 foldUpdateAll(curwin);
5749 }
5750# ifdef FEAT_EVAL
5751 /* 'foldexpr' */
5752 else if (varp == &curwin->w_p_fde)
5753 {
5754 if (foldmethodIsExpr(curwin))
5755 foldUpdateAll(curwin);
5756 }
5757# endif
5758 /* 'foldmarker' */
5759 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
5760 {
5761 p = vim_strchr(*varp, ',');
5762 if (p == NULL)
5763 errmsg = (char_u *)N_("E536: comma required");
5764 else if (p == *varp || p[1] == NUL)
5765 errmsg = e_invarg;
5766 else if (foldmethodIsMarker(curwin))
5767 foldUpdateAll(curwin);
5768 }
5769 /* 'commentstring' */
5770 else if (gvarp == &p_cms)
5771 {
5772 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
5773 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
5774 }
5775 /* 'foldopen' */
5776 else if (varp == &p_fdo)
5777 {
5778 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
5779 errmsg = e_invarg;
5780 }
5781 /* 'foldclose' */
5782 else if (varp == &p_fcl)
5783 {
5784 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
5785 errmsg = e_invarg;
5786 }
5787#endif
5788
5789#ifdef FEAT_VIRTUALEDIT
5790 /* 'virtualedit' */
5791 else if (varp == &p_ve)
5792 {
5793 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
5794 errmsg = e_invarg;
5795 else if (STRCMP(p_ve, oldval) != 0)
5796 {
5797 /* Recompute cursor position in case the new 've' setting
5798 * changes something. */
5799 validate_virtcol();
5800 coladvance(curwin->w_virtcol);
5801 }
5802 }
5803#endif
5804
5805#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
5806 else if (varp == &p_csqf)
5807 {
5808 if (p_csqf != NULL)
5809 {
5810 p = p_csqf;
5811 while (*p != NUL)
5812 {
5813 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
5814 || p[1] == NUL
5815 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
5816 || (p[2] != NUL && p[2] != ','))
5817 {
5818 errmsg = e_invarg;
5819 break;
5820 }
5821 else if (p[2] == NUL)
5822 break;
5823 else
5824 p += 3;
5825 }
5826 }
5827 }
5828#endif
5829
5830 /* Options that are a list of flags. */
5831 else
5832 {
5833 p = NULL;
5834 if (varp == &p_ww)
5835 p = (char_u *)WW_ALL;
5836 if (varp == &p_shm)
5837 p = (char_u *)SHM_ALL;
5838 else if (varp == &(p_cpo))
5839 p = (char_u *)CPO_ALL;
5840 else if (varp == &(curbuf->b_p_fo))
5841 p = (char_u *)FO_ALL;
5842 else if (varp == &p_mouse)
5843 {
5844#ifdef FEAT_MOUSE
5845 p = (char_u *)MOUSE_ALL;
5846#else
5847 if (*p_mouse != NUL)
5848 errmsg = (char_u *)N_("E538: No mouse support");
5849#endif
5850 }
5851#if defined(FEAT_GUI)
5852 else if (varp == &p_go)
5853 p = (char_u *)GO_ALL;
5854#endif
5855 if (p != NULL)
5856 {
5857 for (s = *varp; *s; ++s)
5858 if (vim_strchr(p, *s) == NULL)
5859 {
5860 errmsg = illegal_char(errbuf, *s);
5861 break;
5862 }
5863 }
5864 }
5865
5866 /*
5867 * If error detected, restore the previous value.
5868 */
5869 if (errmsg != NULL)
5870 {
5871 if (new_value_alloced)
5872 free_string_option(*varp);
5873 *varp = oldval;
5874 /*
5875 * When resetting some values, need to act on it.
5876 */
5877 if (did_chartab)
5878 (void)init_chartab();
5879 if (varp == &p_hl)
5880 (void)highlight_changed();
5881 }
5882 else
5883 {
5884#ifdef FEAT_EVAL
5885 /* Remember where the option was set. */
5886 options[opt_idx].scriptID = current_SID;
5887#endif
5888 /*
5889 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005890 * Use "free_oldval", because recursiveness may change the flags under
5891 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005893 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 free_string_option(oldval);
5895 if (new_value_alloced)
5896 options[opt_idx].flags |= P_ALLOCED;
5897 else
5898 options[opt_idx].flags &= ~P_ALLOCED;
5899
5900 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5901 && (int)options[opt_idx].indir >= PV_BOTH)
5902 {
5903 /* global option with local value set to use global value; free
5904 * the local value and make it empty */
5905 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
5906 free_string_option(*(char_u **)p);
5907 *(char_u **)p = empty_option;
5908 }
5909
5910 /* May set global value for local option. */
5911 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
5912 set_string_option_global(opt_idx, varp);
5913 }
5914
5915#ifdef FEAT_MOUSE
5916 if (varp == &p_mouse)
5917 {
5918# ifdef FEAT_MOUSE_TTY
5919 if (*p_mouse == NUL)
5920 mch_setmouse(FALSE); /* switch mouse off */
5921 else
5922# endif
5923 setmouse(); /* in case 'mouse' changed */
5924 }
5925#endif
5926
5927 if (curwin->w_curswant != MAXCOL)
5928 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
5929 check_redraw(options[opt_idx].flags);
5930
5931 return errmsg;
5932}
5933
5934/*
5935 * Handle setting 'listchars' or 'fillchars'.
5936 * Returns error message, NULL if it's OK.
5937 */
5938 static char_u *
5939set_chars_option(varp)
5940 char_u **varp;
5941{
5942 int round, i, len, entries;
5943 char_u *p, *s;
5944 int c1, c2 = 0;
5945 struct charstab
5946 {
5947 int *cp;
5948 char *name;
5949 };
5950#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5951 static struct charstab filltab[] =
5952 {
5953 {&fill_stl, "stl"},
5954 {&fill_stlnc, "stlnc"},
5955 {&fill_vert, "vert"},
5956 {&fill_fold, "fold"},
5957 {&fill_diff, "diff"},
5958 };
5959#endif
5960 static struct charstab lcstab[] =
5961 {
5962 {&lcs_eol, "eol"},
5963 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005964 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965 {&lcs_prec, "precedes"},
5966 {&lcs_tab2, "tab"},
5967 {&lcs_trail, "trail"},
5968 };
5969 struct charstab *tab;
5970
5971#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5972 if (varp == &p_lcs)
5973#endif
5974 {
5975 tab = lcstab;
5976 entries = sizeof(lcstab) / sizeof(struct charstab);
5977 }
5978#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5979 else
5980 {
5981 tab = filltab;
5982 entries = sizeof(filltab) / sizeof(struct charstab);
5983 }
5984#endif
5985
5986 /* first round: check for valid value, second round: assign values */
5987 for (round = 0; round <= 1; ++round)
5988 {
5989 if (round)
5990 {
5991 /* After checking that the value is valid: set defaults: space for
5992 * 'fillchars', NUL for 'listchars' */
5993 for (i = 0; i < entries; ++i)
5994 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
5995 if (varp == &p_lcs)
5996 lcs_tab1 = NUL;
5997#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5998 else
5999 fill_diff = '-';
6000#endif
6001 }
6002 p = *varp;
6003 while (*p)
6004 {
6005 for (i = 0; i < entries; ++i)
6006 {
6007 len = (int)STRLEN(tab[i].name);
6008 if (STRNCMP(p, tab[i].name, len) == 0
6009 && p[len] == ':'
6010 && p[len + 1] != NUL)
6011 {
6012 s = p + len + 1;
6013#ifdef FEAT_MBYTE
6014 c1 = mb_ptr2char_adv(&s);
6015#else
6016 c1 = *s++;
6017#endif
6018 if (tab[i].cp == &lcs_tab2)
6019 {
6020 if (*s == NUL)
6021 continue;
6022#ifdef FEAT_MBYTE
6023 c2 = mb_ptr2char_adv(&s);
6024#else
6025 c2 = *s++;
6026#endif
6027 }
6028 if (*s == ',' || *s == NUL)
6029 {
6030 if (round)
6031 {
6032 if (tab[i].cp == &lcs_tab2)
6033 {
6034 lcs_tab1 = c1;
6035 lcs_tab2 = c2;
6036 }
6037 else
6038 *(tab[i].cp) = c1;
6039
6040 }
6041 p = s;
6042 break;
6043 }
6044 }
6045 }
6046
6047 if (i == entries)
6048 return e_invarg;
6049 if (*p == ',')
6050 ++p;
6051 }
6052 }
6053
6054 return NULL; /* no error */
6055}
6056
6057#ifdef FEAT_STL_OPT
6058/*
6059 * Check validity of options with the 'statusline' format.
6060 * Return error message or NULL.
6061 */
6062 char_u *
6063check_stl_option(s)
6064 char_u *s;
6065{
6066 int itemcnt = 0;
6067 int groupdepth = 0;
6068 static char_u errbuf[80];
6069
6070 while (*s && itemcnt < STL_MAX_ITEM)
6071 {
6072 /* Check for valid keys after % sequences */
6073 while (*s && *s != '%')
6074 s++;
6075 if (!*s)
6076 break;
6077 s++;
6078 if (*s != '%' && *s != ')')
6079 ++itemcnt;
6080 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6081 {
6082 s++;
6083 continue;
6084 }
6085 if (*s == ')')
6086 {
6087 s++;
6088 if (--groupdepth < 0)
6089 break;
6090 continue;
6091 }
6092 if (*s == '-')
6093 s++;
6094 while (VIM_ISDIGIT(*s))
6095 s++;
6096 if (*s == STL_HIGHLIGHT)
6097 continue;
6098 if (*s == '.')
6099 {
6100 s++;
6101 while (*s && VIM_ISDIGIT(*s))
6102 s++;
6103 }
6104 if (*s == '(')
6105 {
6106 groupdepth++;
6107 continue;
6108 }
6109 if (vim_strchr(STL_ALL, *s) == NULL)
6110 {
6111 return illegal_char(errbuf, *s);
6112 }
6113 if (*s == '{')
6114 {
6115 s++;
6116 while (*s != '}' && *s)
6117 s++;
6118 if (*s != '}')
6119 return (char_u *)N_("E540: Unclosed expression sequence");
6120 }
6121 }
6122 if (itemcnt >= STL_MAX_ITEM)
6123 return (char_u *)N_("E541: too many items");
6124 if (groupdepth != 0)
6125 return (char_u *)N_("E542: unbalanced groups");
6126 return NULL;
6127}
6128#endif
6129
6130#ifdef FEAT_CLIPBOARD
6131/*
6132 * Extract the items in the 'clipboard' option and set global values.
6133 */
6134 static char_u *
6135check_clipboard_option()
6136{
6137 int new_unnamed = FALSE;
6138 int new_autoselect = FALSE;
6139 int new_autoselectml = FALSE;
6140 regprog_T *new_exclude_prog = NULL;
6141 char_u *errmsg = NULL;
6142 char_u *p;
6143
6144 for (p = p_cb; *p != NUL; )
6145 {
6146 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6147 {
6148 new_unnamed = TRUE;
6149 p += 7;
6150 }
6151 else if (STRNCMP(p, "autoselect", 10) == 0
6152 && (p[10] == ',' || p[10] == NUL))
6153 {
6154 new_autoselect = TRUE;
6155 p += 10;
6156 }
6157 else if (STRNCMP(p, "autoselectml", 12) == 0
6158 && (p[12] == ',' || p[12] == NUL))
6159 {
6160 new_autoselectml = TRUE;
6161 p += 12;
6162 }
6163 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6164 {
6165 p += 8;
6166 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6167 if (new_exclude_prog == NULL)
6168 errmsg = e_invarg;
6169 break;
6170 }
6171 else
6172 {
6173 errmsg = e_invarg;
6174 break;
6175 }
6176 if (*p == ',')
6177 ++p;
6178 }
6179 if (errmsg == NULL)
6180 {
6181 clip_unnamed = new_unnamed;
6182 clip_autoselect = new_autoselect;
6183 clip_autoselectml = new_autoselectml;
6184 vim_free(clip_exclude_prog);
6185 clip_exclude_prog = new_exclude_prog;
6186 }
6187 else
6188 vim_free(new_exclude_prog);
6189
6190 return errmsg;
6191}
6192#endif
6193
6194/*
6195 * Set the value of a boolean option, and take care of side effects.
6196 * Returns NULL for success, or an error message for an error.
6197 */
6198 static char_u *
6199set_bool_option(opt_idx, varp, value, opt_flags)
6200 int opt_idx; /* index in options[] table */
6201 char_u *varp; /* pointer to the option variable */
6202 int value; /* new value */
6203 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6204{
6205 int old_value = *(int *)varp;
6206
6207#ifdef FEAT_GUI
6208 need_mouse_correct = TRUE;
6209#endif
6210
6211 /* Disallow changing some options from secure mode */
6212 if ((secure
6213#ifdef HAVE_SANDBOX
6214 || sandbox != 0
6215#endif
6216 ) && (options[opt_idx].flags & P_SECURE))
6217 return e_secure;
6218
6219 *(int *)varp = value; /* set the new value */
6220#ifdef FEAT_EVAL
6221 /* Remember where the option was set. */
6222 options[opt_idx].scriptID = current_SID;
6223#endif
6224
6225 /* May set global value for local option. */
6226 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6227 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6228
6229 /*
6230 * Handle side effects of changing a bool option.
6231 */
6232
6233 /* 'compatible' */
6234 if ((int *)varp == &p_cp)
6235 {
6236 compatible_set();
6237 }
6238
6239 /* when 'readonly' is reset globally, also reset readonlymode */
6240 else if ((int *)varp == &curbuf->b_p_ro)
6241 {
6242 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6243 readonlymode = FALSE;
6244#ifdef FEAT_TITLE
6245 need_maketitle = TRUE;
6246#endif
6247 }
6248
6249#ifdef FEAT_TITLE
6250 /* when 'modifiable' is changed, redraw the window title */
6251 else if ((int *)varp == &curbuf->b_p_ma)
6252 need_maketitle = TRUE;
6253 /* when 'endofline' is changed, redraw the window title */
6254 else if ((int *)varp == &curbuf->b_p_eol)
6255 need_maketitle = TRUE;
6256#endif
6257
6258 /* when 'bin' is set also set some other options */
6259 else if ((int *)varp == &curbuf->b_p_bin)
6260 {
6261 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6262#ifdef FEAT_TITLE
6263 need_maketitle = TRUE;
6264#endif
6265 }
6266
6267#ifdef FEAT_AUTOCMD
6268 /* when 'buflisted' changes, trigger autocommands */
6269 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6270 {
6271 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6272 NULL, NULL, TRUE, curbuf);
6273 }
6274#endif
6275
6276 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6277 else if ((int *)varp == &curbuf->b_p_swf)
6278 {
6279 if (curbuf->b_p_swf && p_uc)
6280 ml_open_file(curbuf); /* create the swap file */
6281 else
6282 mf_close_file(curbuf, TRUE); /* remove the swap file */
6283 }
6284
6285 /* when 'terse' is set change 'shortmess' */
6286 else if ((int *)varp == &p_terse)
6287 {
6288 char_u *p;
6289
6290 p = vim_strchr(p_shm, SHM_SEARCH);
6291
6292 /* insert 's' in p_shm */
6293 if (p_terse && p == NULL)
6294 {
6295 STRCPY(IObuff, p_shm);
6296 STRCAT(IObuff, "s");
6297 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6298 }
6299 /* remove 's' from p_shm */
6300 else if (!p_terse && p != NULL)
6301 mch_memmove(p, p + 1, STRLEN(p));
6302 }
6303
6304 /* when 'paste' is set or reset also change other options */
6305 else if ((int *)varp == &p_paste)
6306 {
6307 paste_option_changed();
6308 }
6309
6310 /* when 'insertmode' is set from an autocommand need to do work here */
6311 else if ((int *)varp == &p_im)
6312 {
6313 if (p_im)
6314 {
6315 if ((State & INSERT) == 0)
6316 need_start_insertmode = TRUE;
6317 stop_insert_mode = FALSE;
6318 }
6319 else
6320 {
6321 need_start_insertmode = FALSE;
6322 stop_insert_mode = TRUE;
6323 if (p_smd && restart_edit != 0)
6324 clear_cmdline = TRUE; /* remove "(insert)" */
6325 restart_edit = 0;
6326 }
6327 }
6328
6329 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6330 else if ((int *)varp == &p_ic && p_hls)
6331 {
6332 redraw_all_later(NOT_VALID);
6333 }
6334
6335#ifdef FEAT_SEARCH_EXTRA
6336 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6337 else if ((int *)varp == &p_hls)
6338 {
6339 no_hlsearch = FALSE;
6340 }
6341#endif
6342
6343#ifdef FEAT_SCROLLBIND
6344 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6345 * at the end of normal_cmd() */
6346 else if ((int *)varp == &curwin->w_p_scb)
6347 {
6348 if (curwin->w_p_scb)
6349 do_check_scrollbind(FALSE);
6350 }
6351#endif
6352
6353#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6354 /* There can be only one window with 'previewwindow' set. */
6355 else if ((int *)varp == &curwin->w_p_pvw)
6356 {
6357 if (curwin->w_p_pvw)
6358 {
6359 win_T *win;
6360
6361 for (win = firstwin; win != NULL; win = win->w_next)
6362 if (win->w_p_pvw && win != curwin)
6363 {
6364 curwin->w_p_pvw = FALSE;
6365 return (char_u *)N_("E590: A preview window already exists");
6366 }
6367 }
6368 }
6369#endif
6370
6371 /* when 'textmode' is set or reset also change 'fileformat' */
6372 else if ((int *)varp == &curbuf->b_p_tx)
6373 {
6374 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6375 }
6376
6377 /* when 'textauto' is set or reset also change 'fileformats' */
6378 else if ((int *)varp == &p_ta)
6379 {
6380 set_string_option_direct((char_u *)"ffs", -1,
6381 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6382 OPT_FREE | opt_flags);
6383 }
6384
6385 /*
6386 * When 'lisp' option changes include/exclude '-' in
6387 * keyword characters.
6388 */
6389#ifdef FEAT_LISP
6390 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6391 {
6392 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6393 }
6394#endif
6395
6396#ifdef FEAT_TITLE
6397 /* when 'title' changed, may need to change the title; same for 'icon' */
6398 else if ((int *)varp == &p_title)
6399 {
6400 did_set_title(FALSE);
6401 }
6402
6403 else if ((int *)varp == &p_icon)
6404 {
6405 did_set_title(TRUE);
6406 }
6407#endif
6408
6409 else if ((int *)varp == &curbuf->b_changed)
6410 {
6411 if (!value)
6412 save_file_ff(curbuf); /* Buffer is unchanged */
6413#ifdef FEAT_TITLE
6414 need_maketitle = TRUE;
6415#endif
6416#ifdef FEAT_AUTOCMD
6417 modified_was_set = value;
6418#endif
6419 }
6420
6421#ifdef BACKSLASH_IN_FILENAME
6422 else if ((int *)varp == &p_ssl)
6423 {
6424 if (p_ssl)
6425 {
6426 psepc = '/';
6427 psepcN = '\\';
6428 pseps[0] = '/';
6429 psepsN[0] = '\\';
6430 }
6431 else
6432 {
6433 psepc = '\\';
6434 psepcN = '/';
6435 pseps[0] = '\\';
6436 psepsN[0] = '/';
6437 }
6438
6439 /* need to adjust the file name arguments and buffer names. */
6440 buflist_slash_adjust();
6441 alist_slash_adjust();
6442# ifdef FEAT_EVAL
6443 scriptnames_slash_adjust();
6444# endif
6445 }
6446#endif
6447
6448 /* If 'wrap' is set, set w_leftcol to zero. */
6449 else if ((int *)varp == &curwin->w_p_wrap)
6450 {
6451 if (curwin->w_p_wrap)
6452 curwin->w_leftcol = 0;
6453 }
6454
6455#ifdef FEAT_WINDOWS
6456 else if ((int *)varp == &p_ea)
6457 {
6458 if (p_ea && !old_value)
6459 win_equal(curwin, FALSE, 0);
6460 }
6461#endif
6462
6463 else if ((int *)varp == &p_wiv)
6464 {
6465 /*
6466 * When 'weirdinvert' changed, set/reset 't_xs'.
6467 * Then set 'weirdinvert' according to value of 't_xs'.
6468 */
6469 if (p_wiv && !old_value)
6470 T_XS = (char_u *)"y";
6471 else if (!p_wiv && old_value)
6472 T_XS = empty_option;
6473 p_wiv = (*T_XS != NUL);
6474 }
6475
6476#if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \
6477 || defined(FEAT_NETBEANS_INTG))
6478 else if ((int *)varp == &p_beval)
6479 {
6480 extern BalloonEval *balloonEval;
6481
6482 if (p_beval == TRUE)
6483 gui_mch_enable_beval_area(balloonEval);
6484 else
6485 gui_mch_disable_beval_area(balloonEval);
6486 }
6487
6488 else if ((int *)varp == &p_acd)
6489 {
6490 if (p_acd && curbuf->b_ffname != NULL
6491 && vim_chdirfile(curbuf->b_ffname) == OK)
6492 shorten_fnames(TRUE);
6493 }
6494#endif
6495
6496#ifdef FEAT_DIFF
6497 /* 'diff' */
6498 else if ((int *)varp == &curwin->w_p_diff)
6499 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006500 /* May add or remove the buffer from the list of diff buffers. */
6501 diff_buf_adjust(curwin);
6502# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006503 if (foldmethodIsDiff(curwin))
6504 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006505# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006506 }
6507#endif
6508
6509#ifdef USE_IM_CONTROL
6510 /* 'imdisable' */
6511 else if ((int *)varp == &p_imdisable)
6512 {
6513 /* Only de-activate it here, it will be enabled when changing mode. */
6514 if (p_imdisable)
6515 im_set_active(FALSE);
6516 }
6517#endif
6518
6519#ifdef FEAT_FKMAP
6520 else if ((int *)varp == &p_altkeymap)
6521 {
6522 if (old_value != p_altkeymap)
6523 {
6524 if (!p_altkeymap)
6525 {
6526 p_hkmap = p_fkmap;
6527 p_fkmap = 0;
6528 }
6529 else
6530 {
6531 p_fkmap = p_hkmap;
6532 p_hkmap = 0;
6533 }
6534 (void)init_chartab();
6535 }
6536 }
6537
6538 /*
6539 * In case some second language keymapping options have changed, check
6540 * and correct the setting in a consistent way.
6541 */
6542
6543 /*
6544 * If hkmap or fkmap are set, reset Arabic keymapping.
6545 */
6546 if ((p_hkmap || p_fkmap) && p_altkeymap)
6547 {
6548 p_altkeymap = p_fkmap;
6549# ifdef FEAT_ARABIC
6550 curwin->w_p_arab = FALSE;
6551# endif
6552 (void)init_chartab();
6553 }
6554
6555 /*
6556 * If hkmap set, reset Farsi keymapping.
6557 */
6558 if (p_hkmap && p_altkeymap)
6559 {
6560 p_altkeymap = 0;
6561 p_fkmap = 0;
6562# ifdef FEAT_ARABIC
6563 curwin->w_p_arab = FALSE;
6564# endif
6565 (void)init_chartab();
6566 }
6567
6568 /*
6569 * If fkmap set, reset Hebrew keymapping.
6570 */
6571 if (p_fkmap && !p_altkeymap)
6572 {
6573 p_altkeymap = 1;
6574 p_hkmap = 0;
6575# ifdef FEAT_ARABIC
6576 curwin->w_p_arab = FALSE;
6577# endif
6578 (void)init_chartab();
6579 }
6580#endif
6581
6582#ifdef FEAT_ARABIC
6583 if ((int *)varp == &curwin->w_p_arab)
6584 {
6585 if (curwin->w_p_arab)
6586 {
6587 /*
6588 * 'arabic' is set, handle various sub-settings.
6589 */
6590 if (!p_tbidi)
6591 {
6592 /* set rightleft mode */
6593 if (!curwin->w_p_rl)
6594 {
6595 curwin->w_p_rl = TRUE;
6596 changed_window_setting();
6597 }
6598
6599 /* Enable Arabic shaping (major part of what Arabic requires) */
6600 if (!p_arshape)
6601 {
6602 p_arshape = TRUE;
6603 redraw_later_clear();
6604 }
6605 }
6606
6607 /* Arabic requires a utf-8 encoding, inform the user if its not
6608 * set. */
6609 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006610 {
6611 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006612 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6613 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006614 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006615
6616# ifdef FEAT_MBYTE
6617 /* set 'delcombine' */
6618 p_deco = TRUE;
6619# endif
6620
6621# ifdef FEAT_KEYMAP
6622 /* Force-set the necessary keymap for arabic */
6623 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
6624 OPT_LOCAL);
6625# endif
6626# ifdef FEAT_FKMAP
6627 p_altkeymap = 0;
6628 p_hkmap = 0;
6629 p_fkmap = 0;
6630 (void)init_chartab();
6631# endif
6632 }
6633 else
6634 {
6635 /*
6636 * 'arabic' is reset, handle various sub-settings.
6637 */
6638 if (!p_tbidi)
6639 {
6640 /* reset rightleft mode */
6641 if (curwin->w_p_rl)
6642 {
6643 curwin->w_p_rl = FALSE;
6644 changed_window_setting();
6645 }
6646
6647 /* 'arabicshape' isn't reset, it is a global option and
6648 * another window may still need it "on". */
6649 }
6650
6651 /* 'delcombine' isn't reset, it is a global option and another
6652 * window may still want it "on". */
6653
6654# ifdef FEAT_KEYMAP
6655 /* Revert to the default keymap */
6656 curbuf->b_p_iminsert = B_IMODE_NONE;
6657 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6658# endif
6659 }
6660 }
6661#endif
6662
6663 /*
6664 * End of handling side effects for bool options.
6665 */
6666
6667 options[opt_idx].flags |= P_WAS_SET;
6668
6669 comp_col(); /* in case 'ruler' or 'showcmd' changed */
6670 if (curwin->w_curswant != MAXCOL)
6671 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
6672 check_redraw(options[opt_idx].flags);
6673
6674 return NULL;
6675}
6676
6677/*
6678 * Set the value of a number option, and take care of side effects.
6679 * Returns NULL for success, or an error message for an error.
6680 */
6681 static char_u *
6682set_num_option(opt_idx, varp, value, errbuf, opt_flags)
6683 int opt_idx; /* index in options[] table */
6684 char_u *varp; /* pointer to the option variable */
6685 long value; /* new value */
6686 char_u *errbuf; /* buffer for error messages */
6687 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
6688 OPT_MODELINE */
6689{
6690 char_u *errmsg = NULL;
6691 long old_value = *(long *)varp;
6692 long old_Rows = Rows; /* remember old Rows */
6693 long old_Columns = Columns; /* remember old Columns */
6694 long *pp = (long *)varp;
6695
6696#ifdef FEAT_GUI
6697 need_mouse_correct = TRUE;
6698#endif
6699
6700 *pp = value;
6701#ifdef FEAT_EVAL
6702 /* Remember where the option was set. */
6703 options[opt_idx].scriptID = current_SID;
6704#endif
6705
6706 if (curbuf->b_p_sw <= 0)
6707 {
6708 errmsg = e_positive;
6709 curbuf->b_p_sw = curbuf->b_p_ts;
6710 }
6711
6712 /*
6713 * Number options that need some action when changed
6714 */
6715#ifdef FEAT_WINDOWS
6716 if (pp == &p_wh || pp == &p_hh)
6717 {
6718 if (p_wh < 1)
6719 {
6720 errmsg = e_positive;
6721 p_wh = 1;
6722 }
6723 if (p_wmh > p_wh)
6724 {
6725 errmsg = e_winheight;
6726 p_wh = p_wmh;
6727 }
6728 if (p_hh < 0)
6729 {
6730 errmsg = e_positive;
6731 p_hh = 0;
6732 }
6733
6734 /* Change window height NOW */
6735 if (lastwin != firstwin)
6736 {
6737 if (pp == &p_wh && curwin->w_height < p_wh)
6738 win_setheight((int)p_wh);
6739 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
6740 win_setheight((int)p_hh);
6741 }
6742 }
6743
6744 /* 'winminheight' */
6745 else if (pp == &p_wmh)
6746 {
6747 if (p_wmh < 0)
6748 {
6749 errmsg = e_positive;
6750 p_wmh = 0;
6751 }
6752 if (p_wmh > p_wh)
6753 {
6754 errmsg = e_winheight;
6755 p_wmh = p_wh;
6756 }
6757 win_setminheight();
6758 }
6759
6760# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006761 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762 {
6763 if (p_wiw < 1)
6764 {
6765 errmsg = e_positive;
6766 p_wiw = 1;
6767 }
6768 if (p_wmw > p_wiw)
6769 {
6770 errmsg = e_winwidth;
6771 p_wiw = p_wmw;
6772 }
6773
6774 /* Change window width NOW */
6775 if (lastwin != firstwin && curwin->w_width < p_wiw)
6776 win_setwidth((int)p_wiw);
6777 }
6778
6779 /* 'winminwidth' */
6780 else if (pp == &p_wmw)
6781 {
6782 if (p_wmw < 0)
6783 {
6784 errmsg = e_positive;
6785 p_wmw = 0;
6786 }
6787 if (p_wmw > p_wiw)
6788 {
6789 errmsg = e_winwidth;
6790 p_wmw = p_wiw;
6791 }
6792 win_setminheight();
6793 }
6794# endif
6795
6796#endif
6797
6798#ifdef FEAT_WINDOWS
6799 /* (re)set last window status line */
6800 else if (pp == &p_ls)
6801 {
6802 last_status(FALSE);
6803 }
6804#endif
6805
6806#ifdef FEAT_GUI
6807 else if (pp == &p_linespace)
6808 {
6809 if (gui.in_use && gui_mch_adjust_charsize() == OK)
6810 gui_set_shellsize(FALSE, FALSE);
6811 }
6812#endif
6813
6814#ifdef FEAT_FOLDING
6815 /* 'foldlevel' */
6816 else if (pp == &curwin->w_p_fdl)
6817 {
6818 if (curwin->w_p_fdl < 0)
6819 curwin->w_p_fdl = 0;
6820 newFoldLevel();
6821 }
6822
6823 /* 'foldminlevel' */
6824 else if (pp == &curwin->w_p_fml)
6825 {
6826 foldUpdateAll(curwin);
6827 }
6828
6829 /* 'foldnestmax' */
6830 else if (pp == &curwin->w_p_fdn)
6831 {
6832 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
6833 foldUpdateAll(curwin);
6834 }
6835
6836 /* 'foldcolumn' */
6837 else if (pp == &curwin->w_p_fdc)
6838 {
6839 if (curwin->w_p_fdc < 0)
6840 {
6841 errmsg = e_positive;
6842 curwin->w_p_fdc = 0;
6843 }
6844 else if (curwin->w_p_fdc > 12)
6845 {
6846 errmsg = e_invarg;
6847 curwin->w_p_fdc = 12;
6848 }
6849 }
6850
6851 /* 'shiftwidth' or 'tabstop' */
6852 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
6853 {
6854 if (foldmethodIsIndent(curwin))
6855 foldUpdateAll(curwin);
6856 }
6857#endif /* FEAT_FOLDING */
6858
6859 else if (pp == &curbuf->b_p_iminsert)
6860 {
6861 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
6862 {
6863 errmsg = e_invarg;
6864 curbuf->b_p_iminsert = B_IMODE_NONE;
6865 }
6866 p_iminsert = curbuf->b_p_iminsert;
6867 if (termcap_active) /* don't do this in the alternate screen */
6868 showmode();
6869#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
6870 /* Show/unshow value of 'keymap' in status lines. */
6871 status_redraw_curbuf();
6872#endif
6873 }
6874
6875 else if (pp == &curbuf->b_p_imsearch)
6876 {
6877 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
6878 {
6879 errmsg = e_invarg;
6880 curbuf->b_p_imsearch = B_IMODE_NONE;
6881 }
6882 p_imsearch = curbuf->b_p_imsearch;
6883 }
6884
6885#ifdef FEAT_TITLE
6886 /* if 'titlelen' has changed, redraw the title */
6887 else if (pp == &p_titlelen)
6888 {
6889 if (p_titlelen < 0)
6890 {
6891 errmsg = e_positive;
6892 p_titlelen = 85;
6893 }
6894 if (starting != NO_SCREEN && old_value != p_titlelen)
6895 need_maketitle = TRUE;
6896 }
6897#endif
6898
6899 /* if p_ch changed value, change the command line height */
6900 else if (pp == &p_ch)
6901 {
6902 if (p_ch < 1)
6903 {
6904 errmsg = e_positive;
6905 p_ch = 1;
6906 }
6907
6908 /* Only compute the new window layout when startup has been
6909 * completed. Otherwise the frame sizes may be wrong. */
6910 if (p_ch != old_value && full_screen
6911#ifdef FEAT_GUI
6912 && !gui.starting
6913#endif
6914 )
6915 command_height(old_value);
6916 }
6917
6918 /* when 'updatecount' changes from zero to non-zero, open swap files */
6919 else if (pp == &p_uc)
6920 {
6921 if (p_uc < 0)
6922 {
6923 errmsg = e_positive;
6924 p_uc = 100;
6925 }
6926 if (p_uc && !old_value)
6927 ml_open_files();
6928 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006929#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00006930 else if (pp == &p_mzq)
6931 mzvim_reset_timer();
6932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006933
6934 /* sync undo before 'undolevels' changes */
6935 else if (pp == &p_ul)
6936 {
6937 /* use the old value, otherwise u_sync() may not work properly */
6938 p_ul = old_value;
6939 u_sync();
6940 p_ul = value;
6941 }
6942
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006943#ifdef FEAT_LINEBREAK
6944 /* 'numberwidth' must be positive */
6945 else if (pp == &curwin->w_p_nuw)
6946 {
6947 if (curwin->w_p_nuw < 1)
6948 {
6949 errmsg = e_positive;
6950 curwin->w_p_nuw = 1;
6951 }
6952 if (curwin->w_p_nuw > 10)
6953 {
6954 errmsg = e_invarg;
6955 curwin->w_p_nuw = 10;
6956 }
6957 curwin->w_nrwidth_line_count = 0;
6958 }
6959#endif
6960
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961 /*
6962 * Check the bounds for numeric options here
6963 */
6964 if (Rows < min_rows() && full_screen)
6965 {
6966 if (errbuf != NULL)
6967 {
6968 sprintf((char *)errbuf, _("E593: Need at least %d lines"),
6969 min_rows());
6970 errmsg = errbuf;
6971 }
6972 Rows = min_rows();
6973 }
6974 if (Columns < MIN_COLUMNS && full_screen)
6975 {
6976 if (errbuf != NULL)
6977 {
6978 sprintf((char *)errbuf, _("E594: Need at least %d columns"),
6979 MIN_COLUMNS);
6980 errmsg = errbuf;
6981 }
6982 Columns = MIN_COLUMNS;
6983 }
6984
6985#ifdef DJGPP
6986 /* avoid a crash by checking for a too large value of 'columns' */
6987 if (old_Columns != Columns && full_screen && term_console)
6988 mch_check_columns();
6989#endif
6990
6991 /*
6992 * If the screen (shell) height has been changed, assume it is the
6993 * physical screenheight.
6994 */
6995 if (old_Rows != Rows || old_Columns != Columns)
6996 {
6997 /* Changing the screen size is not allowed while updating the screen. */
6998 if (updating_screen)
6999 *pp = old_value;
7000 else if (full_screen
7001#ifdef FEAT_GUI
7002 && !gui.starting
7003#endif
7004 )
7005 set_shellsize((int)Columns, (int)Rows, TRUE);
7006 else
7007 {
7008 /* Postpone the resizing; check the size and cmdline position for
7009 * messages. */
7010 check_shellsize();
7011 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7012 cmdline_row = Rows - p_ch;
7013 }
7014 }
7015
7016 if (curbuf->b_p_sts < 0)
7017 {
7018 errmsg = e_positive;
7019 curbuf->b_p_sts = 0;
7020 }
7021 if (curbuf->b_p_ts <= 0)
7022 {
7023 errmsg = e_positive;
7024 curbuf->b_p_ts = 8;
7025 }
7026 if (curbuf->b_p_tw < 0)
7027 {
7028 errmsg = e_positive;
7029 curbuf->b_p_tw = 0;
7030 }
7031 if (p_tm < 0)
7032 {
7033 errmsg = e_positive;
7034 p_tm = 0;
7035 }
7036 if ((curwin->w_p_scr <= 0
7037 || (curwin->w_p_scr > curwin->w_height
7038 && curwin->w_height > 0))
7039 && full_screen)
7040 {
7041 if (pp == &(curwin->w_p_scr))
7042 {
7043 if (curwin->w_p_scr != 0)
7044 errmsg = e_scroll;
7045 win_comp_scroll(curwin);
7046 }
7047 /* If 'scroll' became invalid because of a side effect silently adjust
7048 * it. */
7049 else if (curwin->w_p_scr <= 0)
7050 curwin->w_p_scr = 1;
7051 else /* curwin->w_p_scr > curwin->w_height */
7052 curwin->w_p_scr = curwin->w_height;
7053 }
7054 if (p_report < 0)
7055 {
7056 errmsg = e_positive;
7057 p_report = 1;
7058 }
7059 if ((p_sj < 0 || p_sj >= Rows) && full_screen)
7060 {
7061 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7062 p_sj = Rows / 2;
7063 else
7064 {
7065 errmsg = e_scroll;
7066 p_sj = 1;
7067 }
7068 }
7069 if (p_so < 0 && full_screen)
7070 {
7071 errmsg = e_scroll;
7072 p_so = 0;
7073 }
7074 if (p_siso < 0 && full_screen)
7075 {
7076 errmsg = e_positive;
7077 p_siso = 0;
7078 }
7079#ifdef FEAT_CMDWIN
7080 if (p_cwh < 1)
7081 {
7082 errmsg = e_positive;
7083 p_cwh = 1;
7084 }
7085#endif
7086 if (p_ut < 0)
7087 {
7088 errmsg = e_positive;
7089 p_ut = 2000;
7090 }
7091 if (p_ss < 0)
7092 {
7093 errmsg = e_positive;
7094 p_ss = 0;
7095 }
7096
7097 /* May set global value for local option. */
7098 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7099 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7100
7101 options[opt_idx].flags |= P_WAS_SET;
7102
7103 comp_col(); /* in case 'columns' or 'ls' changed */
7104 if (curwin->w_curswant != MAXCOL)
7105 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7106 check_redraw(options[opt_idx].flags);
7107
7108 return errmsg;
7109}
7110
7111/*
7112 * Called after an option changed: check if something needs to be redrawn.
7113 */
7114 static void
7115check_redraw(flags)
7116 long_u flags;
7117{
7118 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7119 int clear = (flags & P_RCLR) == P_RCLR;
7120 int all = ((flags & P_RALL) == P_RALL || clear);
7121
7122#ifdef FEAT_WINDOWS
7123 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7124 status_redraw_all();
7125#endif
7126
7127 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7128 changed_window_setting();
7129 if (flags & P_RBUF)
7130 redraw_curbuf_later(NOT_VALID);
7131 if (clear)
7132 redraw_all_later(CLEAR);
7133 else if (all)
7134 redraw_all_later(NOT_VALID);
7135}
7136
7137/*
7138 * Find index for option 'arg'.
7139 * Return -1 if not found.
7140 */
7141 static int
7142findoption(arg)
7143 char_u *arg;
7144{
7145 int opt_idx;
7146 char *s, *p;
7147 static short quick_tab[27] = {0, 0}; /* quick access table */
7148 int is_term_opt;
7149
7150 /*
7151 * For first call: Initialize the quick-access table.
7152 * It contains the index for the first option that starts with a certain
7153 * letter. There are 26 letters, plus the first "t_" option.
7154 */
7155 if (quick_tab[1] == 0)
7156 {
7157 p = options[0].fullname;
7158 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7159 {
7160 if (s[0] != p[0])
7161 {
7162 if (s[0] == 't' && s[1] == '_')
7163 quick_tab[26] = opt_idx;
7164 else
7165 quick_tab[CharOrdLow(s[0])] = opt_idx;
7166 }
7167 p = s;
7168 }
7169 }
7170
7171 /*
7172 * Check for name starting with an illegal character.
7173 */
7174#ifdef EBCDIC
7175 if (!islower(arg[0]))
7176#else
7177 if (arg[0] < 'a' || arg[0] > 'z')
7178#endif
7179 return -1;
7180
7181 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7182 if (is_term_opt)
7183 opt_idx = quick_tab[26];
7184 else
7185 opt_idx = quick_tab[CharOrdLow(arg[0])];
7186 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7187 {
7188 if (STRCMP(arg, s) == 0) /* match full name */
7189 break;
7190 }
7191 if (s == NULL && !is_term_opt)
7192 {
7193 opt_idx = quick_tab[CharOrdLow(arg[0])];
7194 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7195 {
7196 s = options[opt_idx].shortname;
7197 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7198 break;
7199 s = NULL;
7200 }
7201 }
7202 if (s == NULL)
7203 opt_idx = -1;
7204 return opt_idx;
7205}
7206
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007207#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007208/*
7209 * Get the value for an option.
7210 *
7211 * Returns:
7212 * Number or Toggle option: 1, *numval gets value.
7213 * String option: 0, *stringval gets allocated string.
7214 * Hidden Number or Toggle option: -1.
7215 * hidden String option: -2.
7216 * unknown option: -3.
7217 */
7218 int
7219get_option_value(name, numval, stringval, opt_flags)
7220 char_u *name;
7221 long *numval;
7222 char_u **stringval; /* NULL when only checking existance */
7223 int opt_flags;
7224{
7225 int opt_idx;
7226 char_u *varp;
7227
7228 opt_idx = findoption(name);
7229 if (opt_idx < 0) /* unknown option */
7230 return -3;
7231
7232 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7233
7234 if (options[opt_idx].flags & P_STRING)
7235 {
7236 if (varp == NULL) /* hidden option */
7237 return -2;
7238 if (stringval != NULL)
7239 {
7240#ifdef FEAT_CRYPT
7241 /* never return the value of the crypt key */
7242 if ((char_u **)varp == &curbuf->b_p_key)
7243 *stringval = vim_strsave((char_u *)"*****");
7244 else
7245#endif
7246 *stringval = vim_strsave(*(char_u **)(varp));
7247 }
7248 return 0;
7249 }
7250
7251 if (varp == NULL) /* hidden option */
7252 return -1;
7253 if (options[opt_idx].flags & P_NUM)
7254 *numval = *(long *)varp;
7255 else
7256 {
7257 /* Special case: 'modified' is b_changed, but we also want to consider
7258 * it set when 'ff' or 'fenc' changed. */
7259 if ((int *)varp == &curbuf->b_changed)
7260 *numval = curbufIsChanged();
7261 else
7262 *numval = *(int *)varp;
7263 }
7264 return 1;
7265}
7266#endif
7267
7268/*
7269 * Set the value of option "name".
7270 * Use "string" for string options, use "number" for other options.
7271 */
7272 void
7273set_option_value(name, number, string, opt_flags)
7274 char_u *name;
7275 long number;
7276 char_u *string;
7277 int opt_flags; /* OPT_LOCAL or 0 (both) */
7278{
7279 int opt_idx;
7280 char_u *varp;
7281 int flags;
7282
7283 opt_idx = findoption(name);
7284 if (opt_idx == -1)
7285 EMSG2(_("E355: Unknown option: %s"), name);
7286 else
7287 {
7288 flags = options[opt_idx].flags;
7289#ifdef HAVE_SANDBOX
7290 /* Disallow changing some options in the sandbox */
7291 if (sandbox > 0 && (flags & P_SECURE))
7292 EMSG(_(e_sandbox));
7293 else
7294#endif
7295 if (flags & P_STRING)
7296 set_string_option(opt_idx, string, opt_flags);
7297 else
7298 {
7299 varp = get_varp(&options[opt_idx]);
7300 if (varp != NULL) /* hidden option is not changed */
7301 {
7302 if (flags & P_NUM)
7303 (void)set_num_option(opt_idx, varp, number, NULL, opt_flags);
7304 else
7305 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7306 }
7307 }
7308 }
7309}
7310
7311/*
7312 * Get the terminal code for a terminal option.
7313 * Returns NULL when not found.
7314 */
7315 char_u *
7316get_term_code(tname)
7317 char_u *tname;
7318{
7319 int opt_idx;
7320 char_u *varp;
7321
7322 if (tname[0] != 't' || tname[1] != '_' ||
7323 tname[2] == NUL || tname[3] == NUL)
7324 return NULL;
7325 if ((opt_idx = findoption(tname)) >= 0)
7326 {
7327 varp = get_varp(&(options[opt_idx]));
7328 if (varp != NULL)
7329 varp = *(char_u **)(varp);
7330 return varp;
7331 }
7332 return find_termcode(tname + 2);
7333}
7334
7335 char_u *
7336get_highlight_default()
7337{
7338 int i;
7339
7340 i = findoption((char_u *)"hl");
7341 if (i >= 0)
7342 return options[i].def_val[VI_DEFAULT];
7343 return (char_u *)NULL;
7344}
7345
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007346#if defined(FEAT_MBYTE) || defined(PROTO)
7347 char_u *
7348get_encoding_default()
7349{
7350 int i;
7351
7352 i = findoption((char_u *)"enc");
7353 if (i >= 0)
7354 return options[i].def_val[VI_DEFAULT];
7355 return (char_u *)NULL;
7356}
7357#endif
7358
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359/*
7360 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7361 */
7362 static int
7363find_key_option(arg)
7364 char_u *arg;
7365{
7366 int key;
7367 int modifiers;
7368
7369 /*
7370 * Don't use get_special_key_code() for t_xx, we don't want it to call
7371 * add_termcap_entry().
7372 */
7373 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7374 key = TERMCAP2KEY(arg[2], arg[3]);
7375 else
7376 {
7377 --arg; /* put arg at the '<' */
7378 modifiers = 0;
7379 key = find_special_key(&arg, &modifiers, TRUE);
7380 if (modifiers) /* can't handle modifiers here */
7381 key = 0;
7382 }
7383 return key;
7384}
7385
7386/*
7387 * if 'all' == 0: show changed options
7388 * if 'all' == 1: show all normal options
7389 * if 'all' == 2: show all terminal options
7390 */
7391 static void
7392showoptions(all, opt_flags)
7393 int all;
7394 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7395{
7396 struct vimoption *p;
7397 int col;
7398 int isterm;
7399 char_u *varp;
7400 struct vimoption **items;
7401 int item_count;
7402 int run;
7403 int row, rows;
7404 int cols;
7405 int i;
7406 int len;
7407
7408#define INC 20
7409#define GAP 3
7410
7411 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7412 PARAM_COUNT));
7413 if (items == NULL)
7414 return;
7415
7416 /* Highlight title */
7417 if (all == 2)
7418 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7419 else if (opt_flags & OPT_GLOBAL)
7420 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7421 else if (opt_flags & OPT_LOCAL)
7422 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7423 else
7424 MSG_PUTS_TITLE(_("\n--- Options ---"));
7425
7426 /*
7427 * do the loop two times:
7428 * 1. display the short items
7429 * 2. display the long items (only strings and numbers)
7430 */
7431 for (run = 1; run <= 2 && !got_int; ++run)
7432 {
7433 /*
7434 * collect the items in items[]
7435 */
7436 item_count = 0;
7437 for (p = &options[0]; p->fullname != NULL; p++)
7438 {
7439 varp = NULL;
7440 isterm = istermoption(p);
7441 if (opt_flags != 0)
7442 {
7443 if (p->indir != PV_NONE && !isterm)
7444 varp = get_varp_scope(p, opt_flags);
7445 }
7446 else
7447 varp = get_varp(p);
7448 if (varp != NULL
7449 && ((all == 2 && isterm)
7450 || (all == 1 && !isterm)
7451 || (all == 0 && !optval_default(p, varp))))
7452 {
7453 if (p->flags & P_BOOL)
7454 len = 1; /* a toggle option fits always */
7455 else
7456 {
7457 option_value2string(p, opt_flags);
7458 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7459 }
7460 if ((len <= INC - GAP && run == 1) ||
7461 (len > INC - GAP && run == 2))
7462 items[item_count++] = p;
7463 }
7464 }
7465
7466 /*
7467 * display the items
7468 */
7469 if (run == 1)
7470 {
7471 cols = (Columns + GAP - 3) / INC;
7472 if (cols == 0)
7473 cols = 1;
7474 rows = (item_count + cols - 1) / cols;
7475 }
7476 else /* run == 2 */
7477 rows = item_count;
7478 for (row = 0; row < rows && !got_int; ++row)
7479 {
7480 msg_putchar('\n'); /* go to next line */
7481 if (got_int) /* 'q' typed in more */
7482 break;
7483 col = 0;
7484 for (i = row; i < item_count; i += rows)
7485 {
7486 msg_col = col; /* make columns */
7487 showoneopt(items[i], opt_flags);
7488 col += INC;
7489 }
7490 out_flush();
7491 ui_breakcheck();
7492 }
7493 }
7494 vim_free(items);
7495}
7496
7497/*
7498 * Return TRUE if option "p" has its default value.
7499 */
7500 static int
7501optval_default(p, varp)
7502 struct vimoption *p;
7503 char_u *varp;
7504{
7505 int dvi;
7506
7507 if (varp == NULL)
7508 return TRUE; /* hidden option is always at default */
7509 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7510 if (p->flags & P_NUM)
7511 return (*(long *)varp == (long)p->def_val[dvi]);
7512 if (p->flags & P_BOOL)
7513 /* the cast to long is required for Manx C */
7514 return (*(int *)varp == (int)(long)p->def_val[dvi]);
7515 /* P_STRING */
7516 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7517}
7518
7519/*
7520 * showoneopt: show the value of one option
7521 * must not be called with a hidden option!
7522 */
7523 static void
7524showoneopt(p, opt_flags)
7525 struct vimoption *p;
7526 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
7527{
7528 char_u *varp;
7529
7530 varp = get_varp_scope(p, opt_flags);
7531
7532 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7533 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7534 ? !curbufIsChanged() : !*(int *)varp))
7535 MSG_PUTS("no");
7536 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7537 MSG_PUTS("--");
7538 else
7539 MSG_PUTS(" ");
7540 MSG_PUTS(p->fullname);
7541 if (!(p->flags & P_BOOL))
7542 {
7543 msg_putchar('=');
7544 /* put value string in NameBuff */
7545 option_value2string(p, opt_flags);
7546 msg_outtrans(NameBuff);
7547 }
7548}
7549
7550/*
7551 * Write modified options as ":set" commands to a file.
7552 *
7553 * There are three values for "opt_flags":
7554 * OPT_GLOBAL: Write global option values and fresh values of
7555 * buffer-local options (used for start of a session
7556 * file).
7557 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7558 * curwin (used for a vimrc file).
7559 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
7560 * and local values for window-local options of
7561 * curwin. Local values are also written when at the
7562 * default value, because a modeline or autocommand
7563 * may have set them when doing ":edit file" and the
7564 * user has set them back at the default or fresh
7565 * value.
7566 * When "local_only" is TRUE, don't write fresh
7567 * values, only local values (for ":mkview").
7568 * (fresh value = value used for a new buffer or window for a local option).
7569 *
7570 * Return FAIL on error, OK otherwise.
7571 */
7572 int
7573makeset(fd, opt_flags, local_only)
7574 FILE *fd;
7575 int opt_flags;
7576 int local_only;
7577{
7578 struct vimoption *p;
7579 char_u *varp; /* currently used value */
7580 char_u *varp_fresh; /* local value */
7581 char_u *varp_local = NULL; /* fresh value */
7582 char *cmd;
7583 int round;
7584
7585 /*
7586 * The options that don't have a default (terminal name, columns, lines)
7587 * are never written. Terminal options are also not written.
7588 */
7589 for (p = &options[0]; !istermoption(p); p++)
7590 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7591 {
7592 /* skip global option when only doing locals */
7593 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7594 continue;
7595
7596 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
7597 * file, they are always buffer-specific. */
7598 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
7599 continue;
7600
7601 /* Global values are only written when not at the default value. */
7602 varp = get_varp_scope(p, opt_flags);
7603 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
7604 continue;
7605
7606 round = 2;
7607 if (p->indir != PV_NONE)
7608 {
7609 if (p->var == VAR_WIN)
7610 {
7611 /* skip window-local option when only doing globals */
7612 if (!(opt_flags & OPT_LOCAL))
7613 continue;
7614 /* When fresh value of window-local option is not at the
7615 * default, need to write it too. */
7616 if (!(opt_flags & OPT_GLOBAL) && !local_only)
7617 {
7618 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
7619 if (!optval_default(p, varp_fresh))
7620 {
7621 round = 1;
7622 varp_local = varp;
7623 varp = varp_fresh;
7624 }
7625 }
7626 }
7627 }
7628
7629 /* Round 1: fresh value for window-local options.
7630 * Round 2: other values */
7631 for ( ; round <= 2; varp = varp_local, ++round)
7632 {
7633 if (round == 1 || (opt_flags & OPT_GLOBAL))
7634 cmd = "set";
7635 else
7636 cmd = "setlocal";
7637
7638 if (p->flags & P_BOOL)
7639 {
7640 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
7641 return FAIL;
7642 }
7643 else if (p->flags & P_NUM)
7644 {
7645 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
7646 return FAIL;
7647 }
7648 else /* P_STRING */
7649 {
7650 /* Don't set 'syntax' and 'filetype' again if the value is
7651 * already right, avoids reloading the syntax file. */
7652 if (p->indir == PV_SYN || p->indir == PV_FT)
7653 {
7654 if (fprintf(fd, "if &%s != '%s'", p->fullname,
7655 *(char_u **)(varp)) < 0
7656 || put_eol(fd) < 0)
7657 return FAIL;
7658 }
7659 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
7660 (p->flags & P_EXPAND) != 0) == FAIL)
7661 return FAIL;
7662 if (p->indir == PV_SYN || p->indir == PV_FT)
7663 {
7664 if (put_line(fd, "endif") == FAIL)
7665 return FAIL;
7666 }
7667 }
7668 }
7669 }
7670 return OK;
7671}
7672
7673#if defined(FEAT_FOLDING) || defined(PROTO)
7674/*
7675 * Generate set commands for the local fold options only. Used when
7676 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
7677 */
7678 int
7679makefoldset(fd)
7680 FILE *fd;
7681{
7682 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
7683# ifdef FEAT_EVAL
7684 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
7685 == FAIL
7686# endif
7687 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
7688 == FAIL
7689 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
7690 == FAIL
7691 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
7692 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
7693 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
7694 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
7695 )
7696 return FAIL;
7697
7698 return OK;
7699}
7700#endif
7701
7702 static int
7703put_setstring(fd, cmd, name, valuep, expand)
7704 FILE *fd;
7705 char *cmd;
7706 char *name;
7707 char_u **valuep;
7708 int expand;
7709{
7710 char_u *s;
7711 char_u buf[MAXPATHL];
7712
7713 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7714 return FAIL;
7715 if (*valuep != NULL)
7716 {
7717 /* Output 'pastetoggle' as key names. For other
7718 * options some characters have to be escaped with
7719 * CTRL-V or backslash */
7720 if (valuep == &p_pt)
7721 {
7722 s = *valuep;
7723 while (*s != NUL)
7724 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
7725 return FAIL;
7726 }
7727 else if (expand)
7728 {
7729 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
7730 if (put_escstr(fd, buf, 2) == FAIL)
7731 return FAIL;
7732 }
7733 else if (put_escstr(fd, *valuep, 2) == FAIL)
7734 return FAIL;
7735 }
7736 if (put_eol(fd) < 0)
7737 return FAIL;
7738 return OK;
7739}
7740
7741 static int
7742put_setnum(fd, cmd, name, valuep)
7743 FILE *fd;
7744 char *cmd;
7745 char *name;
7746 long *valuep;
7747{
7748 long wc;
7749
7750 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7751 return FAIL;
7752 if (wc_use_keyname((char_u *)valuep, &wc))
7753 {
7754 /* print 'wildchar' and 'wildcharm' as a key name */
7755 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
7756 return FAIL;
7757 }
7758 else if (fprintf(fd, "%ld", *valuep) < 0)
7759 return FAIL;
7760 if (put_eol(fd) < 0)
7761 return FAIL;
7762 return OK;
7763}
7764
7765 static int
7766put_setbool(fd, cmd, name, value)
7767 FILE *fd;
7768 char *cmd;
7769 char *name;
7770 int value;
7771{
7772 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
7773 || put_eol(fd) < 0)
7774 return FAIL;
7775 return OK;
7776}
7777
7778/*
7779 * Clear all the terminal options.
7780 * If the option has been allocated, free the memory.
7781 * Terminal options are never hidden or indirect.
7782 */
7783 void
7784clear_termoptions()
7785{
7786 struct vimoption *p;
7787
7788 /*
7789 * Reset a few things before clearing the old options. This may cause
7790 * outputting a few things that the terminal doesn't understand, but the
7791 * screen will be cleared later, so this is OK.
7792 */
7793#ifdef FEAT_MOUSE_TTY
7794 mch_setmouse(FALSE); /* switch mouse off */
7795#endif
7796#ifdef FEAT_TITLE
7797 mch_restore_title(3); /* restore window titles */
7798#endif
7799#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
7800 /* When starting the GUI close the display opened for the clipboard.
7801 * After restoring the title, because that will need the display. */
7802 if (gui.starting)
7803 clear_xterm_clip();
7804#endif
7805#ifdef WIN3264
7806 /*
7807 * Check if this is allowed now.
7808 */
7809 if (can_end_termcap_mode(FALSE) == TRUE)
7810#endif
7811 stoptermcap(); /* stop termcap mode */
7812
7813 for (p = &options[0]; p->fullname != NULL; p++)
7814 if (istermoption(p))
7815 {
7816 if (p->flags & P_ALLOCED)
7817 free_string_option(*(char_u **)(p->var));
7818 if (p->flags & P_DEF_ALLOCED)
7819 free_string_option(p->def_val[VI_DEFAULT]);
7820 *(char_u **)(p->var) = empty_option;
7821 p->def_val[VI_DEFAULT] = empty_option;
7822 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
7823 }
7824 clear_termcodes();
7825}
7826
7827/*
7828 * Set the terminal option defaults to the current value.
7829 * Used after setting the terminal name.
7830 */
7831 void
7832set_term_defaults()
7833{
7834 struct vimoption *p;
7835
7836 for (p = &options[0]; p->fullname != NULL; p++)
7837 {
7838 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
7839 {
7840 if (p->flags & P_DEF_ALLOCED)
7841 {
7842 free_string_option(p->def_val[VI_DEFAULT]);
7843 p->flags &= ~P_DEF_ALLOCED;
7844 }
7845 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
7846 if (p->flags & P_ALLOCED)
7847 {
7848 p->flags |= P_DEF_ALLOCED;
7849 p->flags &= ~P_ALLOCED; /* don't free the value now */
7850 }
7851 }
7852 }
7853}
7854
7855/*
7856 * return TRUE if 'p' starts with 't_'
7857 */
7858 static int
7859istermoption(p)
7860 struct vimoption *p;
7861{
7862 return (p->fullname[0] == 't' && p->fullname[1] == '_');
7863}
7864
7865/*
7866 * Compute columns for ruler and shown command. 'sc_col' is also used to
7867 * decide what the maximum length of a message on the status line can be.
7868 * If there is a status line for the last window, 'sc_col' is independent
7869 * of 'ru_col'.
7870 */
7871
7872#define COL_RULER 17 /* columns needed by standard ruler */
7873
7874 void
7875comp_col()
7876{
7877#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
7878 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
7879
7880 sc_col = 0;
7881 ru_col = 0;
7882 if (p_ru)
7883 {
7884#ifdef FEAT_STL_OPT
7885 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
7886#else
7887 ru_col = COL_RULER + 1;
7888#endif
7889 /* no last status line, adjust sc_col */
7890 if (!last_has_status)
7891 sc_col = ru_col;
7892 }
7893 if (p_sc)
7894 {
7895 sc_col += SHOWCMD_COLS;
7896 if (!p_ru || last_has_status) /* no need for separating space */
7897 ++sc_col;
7898 }
7899 sc_col = Columns - sc_col;
7900 ru_col = Columns - ru_col;
7901 if (sc_col <= 0) /* screen too narrow, will become a mess */
7902 sc_col = 1;
7903 if (ru_col <= 0)
7904 ru_col = 1;
7905#else
7906 sc_col = Columns;
7907 ru_col = Columns;
7908#endif
7909}
7910
7911/*
7912 * Get pointer to option variable, depending on local or global scope.
7913 */
7914 static char_u *
7915get_varp_scope(p, opt_flags)
7916 struct vimoption *p;
7917 int opt_flags;
7918{
7919 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
7920 {
7921 if (p->var == VAR_WIN)
7922 return (char_u *)GLOBAL_WO(get_varp(p));
7923 return p->var;
7924 }
7925 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
7926 {
7927 switch ((int)p->indir)
7928 {
7929#ifdef FEAT_QUICKFIX
7930 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
7931 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
7932 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
7933#endif
7934 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
7935 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
7936 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
7937 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
7938 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
7939#ifdef FEAT_FIND_ID
7940 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
7941 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
7942#endif
7943#ifdef FEAT_INS_EXPAND
7944 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
7945 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
7946#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007947#ifdef FEAT_STL_OPT
7948 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
7949#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950 }
7951 return NULL; /* "cannot happen" */
7952 }
7953 return get_varp(p);
7954}
7955
7956/*
7957 * Get pointer to option variable.
7958 */
7959 static char_u *
7960get_varp(p)
7961 struct vimoption *p;
7962{
7963 /* hidden option, always return NULL */
7964 if (p->var == NULL)
7965 return NULL;
7966
7967 switch ((int)p->indir)
7968 {
7969 case PV_NONE: return p->var;
7970
7971 /* global option with local value: use local value if it's been set */
7972 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
7973 ? (char_u *)&curbuf->b_p_ep : p->var;
7974 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
7975 ? (char_u *)&curbuf->b_p_kp : p->var;
7976 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
7977 ? (char_u *)&(curbuf->b_p_path) : p->var;
7978 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
7979 ? (char_u *)&(curbuf->b_p_ar) : p->var;
7980 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
7981 ? (char_u *)&(curbuf->b_p_tags) : p->var;
7982#ifdef FEAT_FIND_ID
7983 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
7984 ? (char_u *)&(curbuf->b_p_def) : p->var;
7985 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
7986 ? (char_u *)&(curbuf->b_p_inc) : p->var;
7987#endif
7988#ifdef FEAT_INS_EXPAND
7989 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
7990 ? (char_u *)&(curbuf->b_p_dict) : p->var;
7991 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
7992 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
7993#endif
7994#ifdef FEAT_QUICKFIX
7995 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
7996 ? (char_u *)&(curbuf->b_p_gp) : p->var;
7997 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
7998 ? (char_u *)&(curbuf->b_p_mp) : p->var;
7999 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8000 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8001#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008002#ifdef FEAT_STL_OPT
8003 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8004 ? (char_u *)&(curwin->w_p_stl) : p->var;
8005#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006
8007#ifdef FEAT_ARABIC
8008 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8009#endif
8010 case PV_LIST: return (char_u *)&(curwin->w_p_list);
8011#ifdef FEAT_DIFF
8012 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8013#endif
8014#ifdef FEAT_FOLDING
8015 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8016 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8017 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8018 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8019 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8020 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8021 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8022# ifdef FEAT_EVAL
8023 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8024 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8025# endif
8026 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8027#endif
8028 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008029#ifdef FEAT_LINEBREAK
8030 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8031#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032#if defined(FEAT_WINDOWS)
8033 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8034#endif
8035#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8036 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8037#endif
8038#ifdef FEAT_RIGHTLEFT
8039 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8040 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8041#endif
8042 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8043 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8044#ifdef FEAT_LINEBREAK
8045 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8046#endif
8047#ifdef FEAT_SCROLLBIND
8048 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8049#endif
8050
8051 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8052 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8053#ifdef FEAT_MBYTE
8054 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8055#endif
8056#if defined(FEAT_QUICKFIX)
8057 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8058 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8059#endif
8060 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8061 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8062#ifdef FEAT_CINDENT
8063 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8064 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8065 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8066#endif
8067#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8068 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8069#endif
8070#ifdef FEAT_COMMENTS
8071 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8072#endif
8073#ifdef FEAT_FOLDING
8074 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8075#endif
8076#ifdef FEAT_INS_EXPAND
8077 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8078#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008079#ifdef FEAT_COMPL_FUNC
8080 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
8081#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008082 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8083 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8084#ifdef FEAT_MBYTE
8085 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8086#endif
8087 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8088#ifdef FEAT_AUTOCMD
8089 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8090#endif
8091 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008092 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8094 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8095 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8096 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8097#ifdef FEAT_FIND_ID
8098# ifdef FEAT_EVAL
8099 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8100# endif
8101#endif
8102#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8103 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8104 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8105#endif
8106#ifdef FEAT_CRYPT
8107 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8108#endif
8109#ifdef FEAT_LISP
8110 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8111#endif
8112 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8113 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8114 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8115 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8116 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8117#ifdef FEAT_OSFILETYPE
8118 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8119#endif
8120 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008121#ifdef FEAT_TEXTOBJ
8122 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8123#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8125#ifdef FEAT_SMARTINDENT
8126 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8127#endif
8128#ifndef SHORT_FNAME
8129 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8130#endif
8131 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8132#ifdef FEAT_SEARCHPATH
8133 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8134#endif
8135 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8136#ifdef FEAT_SYN_HL
8137 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
8138#endif
8139 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8140 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8141 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8142 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8143 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8144#ifdef FEAT_KEYMAP
8145 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8146#endif
8147 default: EMSG(_("E356: get_varp ERROR"));
8148 }
8149 /* always return a valid pointer to avoid a crash! */
8150 return (char_u *)&(curbuf->b_p_wm);
8151}
8152
8153/*
8154 * Get the value of 'equalprg', either the buffer-local one or the global one.
8155 */
8156 char_u *
8157get_equalprg()
8158{
8159 if (*curbuf->b_p_ep == NUL)
8160 return p_ep;
8161 return curbuf->b_p_ep;
8162}
8163
8164#if defined(FEAT_WINDOWS) || defined(PROTO)
8165/*
8166 * Copy options from one window to another.
8167 * Used when splitting a window.
8168 */
8169 void
8170win_copy_options(wp_from, wp_to)
8171 win_T *wp_from;
8172 win_T *wp_to;
8173{
8174 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8175 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8176# ifdef FEAT_RIGHTLEFT
8177# ifdef FEAT_FKMAP
8178 /* Is this right? */
8179 wp_to->w_farsi = wp_from->w_farsi;
8180# endif
8181# endif
8182}
8183#endif
8184
8185/*
8186 * Copy the options from one winopt_T to another.
8187 * Doesn't free the old option values in "to", use clear_winopt() for that.
8188 * The 'scroll' option is not copied, because it depends on the window height.
8189 * The 'previewwindow' option is reset, there can be only one preview window.
8190 */
8191 void
8192copy_winopt(from, to)
8193 winopt_T *from;
8194 winopt_T *to;
8195{
8196#ifdef FEAT_ARABIC
8197 to->wo_arab = from->wo_arab;
8198#endif
8199 to->wo_list = from->wo_list;
8200 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008201#ifdef FEAT_LINEBREAK
8202 to->wo_nuw = from->wo_nuw;
8203#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204#ifdef FEAT_RIGHTLEFT
8205 to->wo_rl = from->wo_rl;
8206 to->wo_rlc = vim_strsave(from->wo_rlc);
8207#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008208#ifdef FEAT_STL_OPT
8209 to->wo_stl = vim_strsave(from->wo_stl);
8210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211 to->wo_wrap = from->wo_wrap;
8212#ifdef FEAT_LINEBREAK
8213 to->wo_lbr = from->wo_lbr;
8214#endif
8215#ifdef FEAT_SCROLLBIND
8216 to->wo_scb = from->wo_scb;
8217#endif
8218#ifdef FEAT_DIFF
8219 to->wo_diff = from->wo_diff;
8220#endif
8221#ifdef FEAT_FOLDING
8222 to->wo_fdc = from->wo_fdc;
8223 to->wo_fen = from->wo_fen;
8224 to->wo_fdi = vim_strsave(from->wo_fdi);
8225 to->wo_fml = from->wo_fml;
8226 to->wo_fdl = from->wo_fdl;
8227 to->wo_fdm = vim_strsave(from->wo_fdm);
8228 to->wo_fdn = from->wo_fdn;
8229# ifdef FEAT_EVAL
8230 to->wo_fde = vim_strsave(from->wo_fde);
8231 to->wo_fdt = vim_strsave(from->wo_fdt);
8232# endif
8233 to->wo_fmr = vim_strsave(from->wo_fmr);
8234#endif
8235 check_winopt(to); /* don't want NULL pointers */
8236}
8237
8238/*
8239 * Check string options in a window for a NULL value.
8240 */
8241 void
8242check_win_options(win)
8243 win_T *win;
8244{
8245 check_winopt(&win->w_onebuf_opt);
8246 check_winopt(&win->w_allbuf_opt);
8247}
8248
8249/*
8250 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8251 */
8252/*ARGSUSED*/
8253 void
8254check_winopt(wop)
8255 winopt_T *wop;
8256{
8257#ifdef FEAT_FOLDING
8258 check_string_option(&wop->wo_fdi);
8259 check_string_option(&wop->wo_fdm);
8260# ifdef FEAT_EVAL
8261 check_string_option(&wop->wo_fde);
8262 check_string_option(&wop->wo_fdt);
8263# endif
8264 check_string_option(&wop->wo_fmr);
8265#endif
8266#ifdef FEAT_RIGHTLEFT
8267 check_string_option(&wop->wo_rlc);
8268#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008269#ifdef FEAT_STL_OPT
8270 check_string_option(&wop->wo_stl);
8271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272}
8273
8274/*
8275 * Free the allocated memory inside a winopt_T.
8276 */
8277/*ARGSUSED*/
8278 void
8279clear_winopt(wop)
8280 winopt_T *wop;
8281{
8282#ifdef FEAT_FOLDING
8283 clear_string_option(&wop->wo_fdi);
8284 clear_string_option(&wop->wo_fdm);
8285# ifdef FEAT_EVAL
8286 clear_string_option(&wop->wo_fde);
8287 clear_string_option(&wop->wo_fdt);
8288# endif
8289 clear_string_option(&wop->wo_fmr);
8290#endif
8291#ifdef FEAT_RIGHTLEFT
8292 clear_string_option(&wop->wo_rlc);
8293#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008294#ifdef FEAT_STL_OPT
8295 clear_string_option(&wop->wo_stl);
8296#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297}
8298
8299/*
8300 * Copy global option values to local options for one buffer.
8301 * Used when creating a new buffer and sometimes when entering a buffer.
8302 * flags:
8303 * BCO_ENTER We will enter the buf buffer.
8304 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8305 * appropriate.
8306 * BCO_NOHELP Don't copy the values to a help buffer.
8307 */
8308 void
8309buf_copy_options(buf, flags)
8310 buf_T *buf;
8311 int flags;
8312{
8313 int should_copy = TRUE;
8314 char_u *save_p_isk = NULL; /* init for GCC */
8315 int dont_do_help;
8316 int did_isk = FALSE;
8317
8318 /*
8319 * Don't do anything of the buffer is invalid.
8320 */
8321 if (buf == NULL || !buf_valid(buf))
8322 return;
8323
8324 /*
8325 * Skip this when the option defaults have not been set yet. Happens when
8326 * main() allocates the first buffer.
8327 */
8328 if (p_cpo != NULL)
8329 {
8330 /*
8331 * Always copy when entering and 'cpo' contains 'S'.
8332 * Don't copy when already initialized.
8333 * Don't copy when 'cpo' contains 's' and not entering.
8334 * 'S' BCO_ENTER initialized 's' should_copy
8335 * yes yes X X TRUE
8336 * yes no yes X FALSE
8337 * no X yes X FALSE
8338 * X no no yes FALSE
8339 * X no no no TRUE
8340 * no yes no X TRUE
8341 */
8342 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8343 && (buf->b_p_initialized
8344 || (!(flags & BCO_ENTER)
8345 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8346 should_copy = FALSE;
8347
8348 if (should_copy || (flags & BCO_ALWAYS))
8349 {
8350 /* Don't copy the options specific to a help buffer when
8351 * BCO_NOHELP is given or the options were initialized already
8352 * (jumping back to a help file with CTRL-T or CTRL-O) */
8353 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8354 || buf->b_p_initialized;
8355 if (dont_do_help) /* don't free b_p_isk */
8356 {
8357 save_p_isk = buf->b_p_isk;
8358 buf->b_p_isk = NULL;
8359 }
8360 /*
8361 * Always free the allocated strings.
8362 * If not already initialized, set 'readonly' and copy 'fileformat'.
8363 */
8364 if (!buf->b_p_initialized)
8365 {
8366 free_buf_options(buf, TRUE);
8367 buf->b_p_ro = FALSE; /* don't copy readonly */
8368 buf->b_p_tx = p_tx;
8369#ifdef FEAT_MBYTE
8370 buf->b_p_fenc = vim_strsave(p_fenc);
8371#endif
8372 buf->b_p_ff = vim_strsave(p_ff);
8373#if defined(FEAT_QUICKFIX)
8374 buf->b_p_bh = empty_option;
8375 buf->b_p_bt = empty_option;
8376#endif
8377 }
8378 else
8379 free_buf_options(buf, FALSE);
8380
8381 buf->b_p_ai = p_ai;
8382 buf->b_p_ai_nopaste = p_ai_nopaste;
8383 buf->b_p_sw = p_sw;
8384 buf->b_p_tw = p_tw;
8385 buf->b_p_tw_nopaste = p_tw_nopaste;
8386 buf->b_p_tw_nobin = p_tw_nobin;
8387 buf->b_p_wm = p_wm;
8388 buf->b_p_wm_nopaste = p_wm_nopaste;
8389 buf->b_p_wm_nobin = p_wm_nobin;
8390 buf->b_p_bin = p_bin;
8391 buf->b_p_et = p_et;
8392 buf->b_p_et_nobin = p_et_nobin;
8393 buf->b_p_ml = p_ml;
8394 buf->b_p_ml_nobin = p_ml_nobin;
8395 buf->b_p_inf = p_inf;
8396 buf->b_p_swf = p_swf;
8397#ifdef FEAT_INS_EXPAND
8398 buf->b_p_cpt = vim_strsave(p_cpt);
8399#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008400#ifdef FEAT_COMPL_FUNC
8401 buf->b_p_cfu = vim_strsave(p_cfu);
8402#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 buf->b_p_sts = p_sts;
8404 buf->b_p_sts_nopaste = p_sts_nopaste;
8405#ifndef SHORT_FNAME
8406 buf->b_p_sn = p_sn;
8407#endif
8408#ifdef FEAT_COMMENTS
8409 buf->b_p_com = vim_strsave(p_com);
8410#endif
8411#ifdef FEAT_FOLDING
8412 buf->b_p_cms = vim_strsave(p_cms);
8413#endif
8414 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008415 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 buf->b_p_nf = vim_strsave(p_nf);
8417 buf->b_p_mps = vim_strsave(p_mps);
8418#ifdef FEAT_SMARTINDENT
8419 buf->b_p_si = p_si;
8420#endif
8421 buf->b_p_ci = p_ci;
8422#ifdef FEAT_CINDENT
8423 buf->b_p_cin = p_cin;
8424 buf->b_p_cink = vim_strsave(p_cink);
8425 buf->b_p_cino = vim_strsave(p_cino);
8426#endif
8427#ifdef FEAT_AUTOCMD
8428 /* Don't copy 'filetype', it must be detected */
8429 buf->b_p_ft = empty_option;
8430#endif
8431#ifdef FEAT_OSFILETYPE
8432 buf->b_p_oft = vim_strsave(p_oft);
8433#endif
8434 buf->b_p_pi = p_pi;
8435#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8436 buf->b_p_cinw = vim_strsave(p_cinw);
8437#endif
8438#ifdef FEAT_LISP
8439 buf->b_p_lisp = p_lisp;
8440#endif
8441#ifdef FEAT_SYN_HL
8442 /* Don't copy 'syntax', it must be set */
8443 buf->b_p_syn = empty_option;
8444#endif
8445#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8446 buf->b_p_inde = vim_strsave(p_inde);
8447 buf->b_p_indk = vim_strsave(p_indk);
8448#endif
8449#ifdef FEAT_CRYPT
8450 buf->b_p_key = vim_strsave(p_key);
8451#endif
8452#ifdef FEAT_SEARCHPATH
8453 buf->b_p_sua = vim_strsave(p_sua);
8454#endif
8455#ifdef FEAT_KEYMAP
8456 buf->b_p_keymap = vim_strsave(p_keymap);
8457 buf->b_kmap_state |= KEYMAP_INIT;
8458#endif
8459 /* This isn't really an option, but copying the langmap and IME
8460 * state from the current buffer is better than resetting it. */
8461 buf->b_p_iminsert = p_iminsert;
8462 buf->b_p_imsearch = p_imsearch;
8463
8464 /* options that are normally global but also have a local value
8465 * are not copied, start using the global value */
8466 buf->b_p_ar = -1;
8467#ifdef FEAT_QUICKFIX
8468 buf->b_p_gp = empty_option;
8469 buf->b_p_mp = empty_option;
8470 buf->b_p_efm = empty_option;
8471#endif
8472 buf->b_p_ep = empty_option;
8473 buf->b_p_kp = empty_option;
8474 buf->b_p_path = empty_option;
8475 buf->b_p_tags = empty_option;
8476#ifdef FEAT_FIND_ID
8477 buf->b_p_def = empty_option;
8478 buf->b_p_inc = empty_option;
8479# ifdef FEAT_EVAL
8480 buf->b_p_inex = vim_strsave(p_inex);
8481# endif
8482#endif
8483#ifdef FEAT_INS_EXPAND
8484 buf->b_p_dict = empty_option;
8485 buf->b_p_tsr = empty_option;
8486#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008487#ifdef FEAT_TEXTOBJ
8488 buf->b_p_qe = vim_strsave(p_qe);
8489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490
8491 /*
8492 * Don't copy the options set by ex_help(), use the saved values,
8493 * when going from a help buffer to a non-help buffer.
8494 * Don't touch these at all when BCO_NOHELP is used and going from
8495 * or to a help buffer.
8496 */
8497 if (dont_do_help)
8498 buf->b_p_isk = save_p_isk;
8499 else
8500 {
8501 buf->b_p_isk = vim_strsave(p_isk);
8502 did_isk = TRUE;
8503 buf->b_p_ts = p_ts;
8504 buf->b_help = FALSE;
8505#ifdef FEAT_QUICKFIX
8506 if (buf->b_p_bt[0] == 'h')
8507 clear_string_option(&buf->b_p_bt);
8508#endif
8509 buf->b_p_ma = p_ma;
8510 }
8511 }
8512
8513 /*
8514 * When the options should be copied (ignoring BCO_ALWAYS), set the
8515 * flag that indicates that the options have been initialized.
8516 */
8517 if (should_copy)
8518 buf->b_p_initialized = TRUE;
8519 }
8520
8521 check_buf_options(buf); /* make sure we don't have NULLs */
8522 if (did_isk)
8523 (void)buf_init_chartab(buf, FALSE);
8524}
8525
8526/*
8527 * Reset the 'modifiable' option and its default value.
8528 */
8529 void
8530reset_modifiable()
8531{
8532 int opt_idx;
8533
8534 curbuf->b_p_ma = FALSE;
8535 p_ma = FALSE;
8536 opt_idx = findoption((char_u *)"ma");
8537 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8538}
8539
8540/*
8541 * Set the global value for 'iminsert' to the local value.
8542 */
8543 void
8544set_iminsert_global()
8545{
8546 p_iminsert = curbuf->b_p_iminsert;
8547}
8548
8549/*
8550 * Set the global value for 'imsearch' to the local value.
8551 */
8552 void
8553set_imsearch_global()
8554{
8555 p_imsearch = curbuf->b_p_imsearch;
8556}
8557
8558#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8559static int expand_option_idx = -1;
8560static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8561static int expand_option_flags = 0;
8562
8563 void
8564set_context_in_set_cmd(xp, arg, opt_flags)
8565 expand_T *xp;
8566 char_u *arg;
8567 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8568{
8569 int nextchar;
8570 long_u flags = 0; /* init for GCC */
8571 int opt_idx = 0; /* init for GCC */
8572 char_u *p;
8573 char_u *s;
8574 int is_term_option = FALSE;
8575 int key;
8576
8577 expand_option_flags = opt_flags;
8578
8579 xp->xp_context = EXPAND_SETTINGS;
8580 if (*arg == NUL)
8581 {
8582 xp->xp_pattern = arg;
8583 return;
8584 }
8585 p = arg + STRLEN(arg) - 1;
8586 if (*p == ' ' && *(p - 1) != '\\')
8587 {
8588 xp->xp_pattern = p + 1;
8589 return;
8590 }
8591 while (p > arg)
8592 {
8593 s = p;
8594 /* count number of backslashes before ' ' or ',' */
8595 if (*p == ' ' || *p == ',')
8596 {
8597 while (s > arg && *(s - 1) == '\\')
8598 --s;
8599 }
8600 /* break at a space with an even number of backslashes */
8601 if (*p == ' ' && ((p - s) & 1) == 0)
8602 {
8603 ++p;
8604 break;
8605 }
8606 --p;
8607 }
8608 if (STRNCMP(p, "no", 2) == 0)
8609 {
8610 xp->xp_context = EXPAND_BOOL_SETTINGS;
8611 p += 2;
8612 }
8613 if (STRNCMP(p, "inv", 3) == 0)
8614 {
8615 xp->xp_context = EXPAND_BOOL_SETTINGS;
8616 p += 3;
8617 }
8618 xp->xp_pattern = arg = p;
8619 if (*arg == '<')
8620 {
8621 while (*p != '>')
8622 if (*p++ == NUL) /* expand terminal option name */
8623 return;
8624 key = get_special_key_code(arg + 1);
8625 if (key == 0) /* unknown name */
8626 {
8627 xp->xp_context = EXPAND_NOTHING;
8628 return;
8629 }
8630 nextchar = *++p;
8631 is_term_option = TRUE;
8632 expand_option_name[2] = KEY2TERMCAP0(key);
8633 expand_option_name[3] = KEY2TERMCAP1(key);
8634 }
8635 else
8636 {
8637 if (p[0] == 't' && p[1] == '_')
8638 {
8639 p += 2;
8640 if (*p != NUL)
8641 ++p;
8642 if (*p == NUL)
8643 return; /* expand option name */
8644 nextchar = *++p;
8645 is_term_option = TRUE;
8646 expand_option_name[2] = p[-2];
8647 expand_option_name[3] = p[-1];
8648 }
8649 else
8650 {
8651 /* Allow * wildcard */
8652 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
8653 p++;
8654 if (*p == NUL)
8655 return;
8656 nextchar = *p;
8657 *p = NUL;
8658 opt_idx = findoption(arg);
8659 *p = nextchar;
8660 if (opt_idx == -1 || options[opt_idx].var == NULL)
8661 {
8662 xp->xp_context = EXPAND_NOTHING;
8663 return;
8664 }
8665 flags = options[opt_idx].flags;
8666 if (flags & P_BOOL)
8667 {
8668 xp->xp_context = EXPAND_NOTHING;
8669 return;
8670 }
8671 }
8672 }
8673 /* handle "-=" and "+=" */
8674 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
8675 {
8676 ++p;
8677 nextchar = '=';
8678 }
8679 if ((nextchar != '=' && nextchar != ':')
8680 || xp->xp_context == EXPAND_BOOL_SETTINGS)
8681 {
8682 xp->xp_context = EXPAND_UNSUCCESSFUL;
8683 return;
8684 }
8685 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
8686 {
8687 xp->xp_context = EXPAND_OLD_SETTING;
8688 if (is_term_option)
8689 expand_option_idx = -1;
8690 else
8691 expand_option_idx = opt_idx;
8692 xp->xp_pattern = p + 1;
8693 return;
8694 }
8695 xp->xp_context = EXPAND_NOTHING;
8696 if (is_term_option || (flags & P_NUM))
8697 return;
8698
8699 xp->xp_pattern = p + 1;
8700
8701 if (flags & P_EXPAND)
8702 {
8703 p = options[opt_idx].var;
8704 if (p == (char_u *)&p_bdir
8705 || p == (char_u *)&p_dir
8706 || p == (char_u *)&p_path
8707 || p == (char_u *)&p_rtp
8708#ifdef FEAT_SEARCHPATH
8709 || p == (char_u *)&p_cdpath
8710#endif
8711#ifdef FEAT_SESSION
8712 || p == (char_u *)&p_vdir
8713#endif
8714 )
8715 {
8716 xp->xp_context = EXPAND_DIRECTORIES;
8717 if (p == (char_u *)&p_path
8718#ifdef FEAT_SEARCHPATH
8719 || p == (char_u *)&p_cdpath
8720#endif
8721 )
8722 xp->xp_backslash = XP_BS_THREE;
8723 else
8724 xp->xp_backslash = XP_BS_ONE;
8725 }
8726 else
8727 {
8728 xp->xp_context = EXPAND_FILES;
8729 /* for 'tags' need three backslashes for a space */
8730 if (p == (char_u *)&p_tags)
8731 xp->xp_backslash = XP_BS_THREE;
8732 else
8733 xp->xp_backslash = XP_BS_ONE;
8734 }
8735 }
8736
8737 /* For an option that is a list of file names, find the start of the
8738 * last file name. */
8739 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
8740 {
8741 /* count number of backslashes before ' ' or ',' */
8742 if (*p == ' ' || *p == ',')
8743 {
8744 s = p;
8745 while (s > xp->xp_pattern && *(s - 1) == '\\')
8746 --s;
8747 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
8748 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
8749 {
8750 xp->xp_pattern = p + 1;
8751 break;
8752 }
8753 }
8754 }
8755
8756 return;
8757}
8758
8759 int
8760ExpandSettings(xp, regmatch, num_file, file)
8761 expand_T *xp;
8762 regmatch_T *regmatch;
8763 int *num_file;
8764 char_u ***file;
8765{
8766 int num_normal = 0; /* Nr of matching non-term-code settings */
8767 int num_term = 0; /* Nr of matching terminal code settings */
8768 int opt_idx;
8769 int match;
8770 int count = 0;
8771 char_u *str;
8772 int loop;
8773 int is_term_opt;
8774 char_u name_buf[MAX_KEY_NAME_LEN];
8775 static char *(names[]) = {"all", "termcap"};
8776 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
8777
8778 /* do this loop twice:
8779 * loop == 0: count the number of matching options
8780 * loop == 1: copy the matching options into allocated memory
8781 */
8782 for (loop = 0; loop <= 1; ++loop)
8783 {
8784 regmatch->rm_ic = ic;
8785 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
8786 {
8787 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
8788 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
8789 {
8790 if (loop == 0)
8791 num_normal++;
8792 else
8793 (*file)[count++] = vim_strsave((char_u *)names[match]);
8794 }
8795 }
8796 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
8797 opt_idx++)
8798 {
8799 if (options[opt_idx].var == NULL)
8800 continue;
8801 if (xp->xp_context == EXPAND_BOOL_SETTINGS
8802 && !(options[opt_idx].flags & P_BOOL))
8803 continue;
8804 is_term_opt = istermoption(&options[opt_idx]);
8805 if (is_term_opt && num_normal > 0)
8806 continue;
8807 match = FALSE;
8808 if (vim_regexec(regmatch, str, (colnr_T)0)
8809 || (options[opt_idx].shortname != NULL
8810 && vim_regexec(regmatch,
8811 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
8812 match = TRUE;
8813 else if (is_term_opt)
8814 {
8815 name_buf[0] = '<';
8816 name_buf[1] = 't';
8817 name_buf[2] = '_';
8818 name_buf[3] = str[2];
8819 name_buf[4] = str[3];
8820 name_buf[5] = '>';
8821 name_buf[6] = NUL;
8822 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8823 {
8824 match = TRUE;
8825 str = name_buf;
8826 }
8827 }
8828 if (match)
8829 {
8830 if (loop == 0)
8831 {
8832 if (is_term_opt)
8833 num_term++;
8834 else
8835 num_normal++;
8836 }
8837 else
8838 (*file)[count++] = vim_strsave(str);
8839 }
8840 }
8841 /*
8842 * Check terminal key codes, these are not in the option table
8843 */
8844 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
8845 {
8846 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
8847 {
8848 if (!isprint(str[0]) || !isprint(str[1]))
8849 continue;
8850
8851 name_buf[0] = 't';
8852 name_buf[1] = '_';
8853 name_buf[2] = str[0];
8854 name_buf[3] = str[1];
8855 name_buf[4] = NUL;
8856
8857 match = FALSE;
8858 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8859 match = TRUE;
8860 else
8861 {
8862 name_buf[0] = '<';
8863 name_buf[1] = 't';
8864 name_buf[2] = '_';
8865 name_buf[3] = str[0];
8866 name_buf[4] = str[1];
8867 name_buf[5] = '>';
8868 name_buf[6] = NUL;
8869
8870 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8871 match = TRUE;
8872 }
8873 if (match)
8874 {
8875 if (loop == 0)
8876 num_term++;
8877 else
8878 (*file)[count++] = vim_strsave(name_buf);
8879 }
8880 }
8881
8882 /*
8883 * Check special key names.
8884 */
8885 regmatch->rm_ic = TRUE; /* ignore case here */
8886 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
8887 {
8888 name_buf[0] = '<';
8889 STRCPY(name_buf + 1, str);
8890 STRCAT(name_buf, ">");
8891
8892 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8893 {
8894 if (loop == 0)
8895 num_term++;
8896 else
8897 (*file)[count++] = vim_strsave(name_buf);
8898 }
8899 }
8900 }
8901 if (loop == 0)
8902 {
8903 if (num_normal > 0)
8904 *num_file = num_normal;
8905 else if (num_term > 0)
8906 *num_file = num_term;
8907 else
8908 return OK;
8909 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
8910 if (*file == NULL)
8911 {
8912 *file = (char_u **)"";
8913 return FAIL;
8914 }
8915 }
8916 }
8917 return OK;
8918}
8919
8920 int
8921ExpandOldSetting(num_file, file)
8922 int *num_file;
8923 char_u ***file;
8924{
8925 char_u *var = NULL; /* init for GCC */
8926 char_u *buf;
8927
8928 *num_file = 0;
8929 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
8930 if (*file == NULL)
8931 return FAIL;
8932
8933 /*
8934 * For a terminal key code expand_option_idx is < 0.
8935 */
8936 if (expand_option_idx < 0)
8937 {
8938 var = find_termcode(expand_option_name + 2);
8939 if (var == NULL)
8940 expand_option_idx = findoption(expand_option_name);
8941 }
8942
8943 if (expand_option_idx >= 0)
8944 {
8945 /* put string of option value in NameBuff */
8946 option_value2string(&options[expand_option_idx], expand_option_flags);
8947 var = NameBuff;
8948 }
8949 else if (var == NULL)
8950 var = (char_u *)"";
8951
8952 /* A backslash is required before some characters. This is the reverse of
8953 * what happens in do_set(). */
8954 buf = vim_strsave_escaped(var, escape_chars);
8955
8956 if (buf == NULL)
8957 {
8958 vim_free(*file);
8959 *file = NULL;
8960 return FAIL;
8961 }
8962
8963#ifdef BACKSLASH_IN_FILENAME
8964 /* For MS-Windows et al. we don't double backslashes at the start and
8965 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008966 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008967 if (var[0] == '\\' && var[1] == '\\'
8968 && expand_option_idx >= 0
8969 && (options[expand_option_idx].flags & P_EXPAND)
8970 && vim_isfilec(var[2])
8971 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
8972 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973#endif
8974
8975 *file[0] = buf;
8976 *num_file = 1;
8977 return OK;
8978}
8979#endif
8980
8981/*
8982 * Get the value for the numeric or string option *opp in a nice format into
8983 * NameBuff[]. Must not be called with a hidden option!
8984 */
8985 static void
8986option_value2string(opp, opt_flags)
8987 struct vimoption *opp;
8988 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8989{
8990 char_u *varp;
8991
8992 varp = get_varp_scope(opp, opt_flags);
8993
8994 if (opp->flags & P_NUM)
8995 {
8996 long wc = 0;
8997
8998 if (wc_use_keyname(varp, &wc))
8999 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9000 else if (wc != 0)
9001 STRCPY(NameBuff, transchar((int)wc));
9002 else
9003 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9004 }
9005 else /* P_STRING */
9006 {
9007 varp = *(char_u **)(varp);
9008 if (varp == NULL) /* just in case */
9009 NameBuff[0] = NUL;
9010#ifdef FEAT_CRYPT
9011 /* don't show the actual value of 'key', only that it's set */
9012 if (opp->var == (char_u *)&p_key && *varp)
9013 STRCPY(NameBuff, "*****");
9014#endif
9015 else if (opp->flags & P_EXPAND)
9016 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9017 /* Translate 'pastetoggle' into special key names */
9018 else if ((char_u **)opp->var == &p_pt)
9019 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9020 else
9021 STRNCPY(NameBuff, varp, MAXPATHL);
9022 }
9023}
9024
9025/*
9026 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9027 * printed as a keyname.
9028 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9029 */
9030 static int
9031wc_use_keyname(varp, wcp)
9032 char_u *varp;
9033 long *wcp;
9034{
9035 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9036 {
9037 *wcp = *(long *)varp;
9038 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9039 return TRUE;
9040 }
9041 return FALSE;
9042}
9043
9044#ifdef FEAT_LANGMAP
9045/*
9046 * Any character has an equivalent character. This is used for keyboards that
9047 * have a special language mode that sends characters above 128 (although
9048 * other characters can be translated too).
9049 */
9050
9051/*
9052 * char_u langmap_mapchar[256];
9053 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9054 * "translate" native lang chars in normal mode or some cases of
9055 * insert mode without having to tediously switch lang mode back&forth.
9056 */
9057
9058 static void
9059langmap_init()
9060{
9061 int i;
9062
9063 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9064 langmap_mapchar[i] = i;
9065}
9066
9067/*
9068 * Called when langmap option is set; the language map can be
9069 * changed at any time!
9070 */
9071 static void
9072langmap_set()
9073{
9074 char_u *p;
9075 char_u *p2;
9076 int from, to;
9077
9078 langmap_init(); /* back to one-to-one map first */
9079
9080 for (p = p_langmap; p[0] != NUL; )
9081 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009082 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9083 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009084 {
9085 if (p2[0] == '\\' && p2[1] != NUL)
9086 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 }
9088 if (p2[0] == ';')
9089 ++p2; /* abcd;ABCD form, p2 points to A */
9090 else
9091 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9092 while (p[0])
9093 {
9094 if (p[0] == '\\' && p[1] != NUL)
9095 ++p;
9096#ifdef FEAT_MBYTE
9097 from = (*mb_ptr2char)(p);
9098#else
9099 from = p[0];
9100#endif
9101 if (p2 == NULL)
9102 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009103 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009104 if (p[0] == '\\')
9105 ++p;
9106#ifdef FEAT_MBYTE
9107 to = (*mb_ptr2char)(p);
9108#else
9109 to = p[0];
9110#endif
9111 }
9112 else
9113 {
9114 if (p2[0] == '\\')
9115 ++p2;
9116#ifdef FEAT_MBYTE
9117 to = (*mb_ptr2char)(p2);
9118#else
9119 to = p2[0];
9120#endif
9121 }
9122 if (to == NUL)
9123 {
9124 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9125 transchar(from));
9126 return;
9127 }
9128 langmap_mapchar[from & 255] = to;
9129
9130 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009131 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132 if (p2 == NULL)
9133 {
9134 if (p[0] == ',')
9135 {
9136 ++p;
9137 break;
9138 }
9139 }
9140 else
9141 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009142 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009143 if (*p == ';')
9144 {
9145 p = p2;
9146 if (p[0] != NUL)
9147 {
9148 if (p[0] != ',')
9149 {
9150 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9151 return;
9152 }
9153 ++p;
9154 }
9155 break;
9156 }
9157 }
9158 }
9159 }
9160}
9161#endif
9162
9163/*
9164 * Return TRUE if format option 'x' is in effect.
9165 * Take care of no formatting when 'paste' is set.
9166 */
9167 int
9168has_format_option(x)
9169 int x;
9170{
9171 if (p_paste)
9172 return FALSE;
9173 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9174}
9175
9176/*
9177 * Return TRUE if "x" is present in 'shortmess' option, or
9178 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9179 */
9180 int
9181shortmess(x)
9182 int x;
9183{
9184 return ( vim_strchr(p_shm, x) != NULL
9185 || (vim_strchr(p_shm, 'a') != NULL
9186 && vim_strchr((char_u *)SHM_A, x) != NULL));
9187}
9188
9189/*
9190 * paste_option_changed() - Called after p_paste was set or reset.
9191 */
9192 static void
9193paste_option_changed()
9194{
9195 static int old_p_paste = FALSE;
9196 static int save_sm = 0;
9197#ifdef FEAT_CMDL_INFO
9198 static int save_ru = 0;
9199#endif
9200#ifdef FEAT_RIGHTLEFT
9201 static int save_ri = 0;
9202 static int save_hkmap = 0;
9203#endif
9204 buf_T *buf;
9205
9206 if (p_paste)
9207 {
9208 /*
9209 * Paste switched from off to on.
9210 * Save the current values, so they can be restored later.
9211 */
9212 if (!old_p_paste)
9213 {
9214 /* save options for each buffer */
9215 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9216 {
9217 buf->b_p_tw_nopaste = buf->b_p_tw;
9218 buf->b_p_wm_nopaste = buf->b_p_wm;
9219 buf->b_p_sts_nopaste = buf->b_p_sts;
9220 buf->b_p_ai_nopaste = buf->b_p_ai;
9221 }
9222
9223 /* save global options */
9224 save_sm = p_sm;
9225#ifdef FEAT_CMDL_INFO
9226 save_ru = p_ru;
9227#endif
9228#ifdef FEAT_RIGHTLEFT
9229 save_ri = p_ri;
9230 save_hkmap = p_hkmap;
9231#endif
9232 /* save global values for local buffer options */
9233 p_tw_nopaste = p_tw;
9234 p_wm_nopaste = p_wm;
9235 p_sts_nopaste = p_sts;
9236 p_ai_nopaste = p_ai;
9237 }
9238
9239 /*
9240 * Always set the option values, also when 'paste' is set when it is
9241 * already on.
9242 */
9243 /* set options for each buffer */
9244 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9245 {
9246 buf->b_p_tw = 0; /* textwidth is 0 */
9247 buf->b_p_wm = 0; /* wrapmargin is 0 */
9248 buf->b_p_sts = 0; /* softtabstop is 0 */
9249 buf->b_p_ai = 0; /* no auto-indent */
9250 }
9251
9252 /* set global options */
9253 p_sm = 0; /* no showmatch */
9254#ifdef FEAT_CMDL_INFO
9255# ifdef FEAT_WINDOWS
9256 if (p_ru)
9257 status_redraw_all(); /* redraw to remove the ruler */
9258# endif
9259 p_ru = 0; /* no ruler */
9260#endif
9261#ifdef FEAT_RIGHTLEFT
9262 p_ri = 0; /* no reverse insert */
9263 p_hkmap = 0; /* no Hebrew keyboard */
9264#endif
9265 /* set global values for local buffer options */
9266 p_tw = 0;
9267 p_wm = 0;
9268 p_sts = 0;
9269 p_ai = 0;
9270 }
9271
9272 /*
9273 * Paste switched from on to off: Restore saved values.
9274 */
9275 else if (old_p_paste)
9276 {
9277 /* restore options for each buffer */
9278 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9279 {
9280 buf->b_p_tw = buf->b_p_tw_nopaste;
9281 buf->b_p_wm = buf->b_p_wm_nopaste;
9282 buf->b_p_sts = buf->b_p_sts_nopaste;
9283 buf->b_p_ai = buf->b_p_ai_nopaste;
9284 }
9285
9286 /* restore global options */
9287 p_sm = save_sm;
9288#ifdef FEAT_CMDL_INFO
9289# ifdef FEAT_WINDOWS
9290 if (p_ru != save_ru)
9291 status_redraw_all(); /* redraw to draw the ruler */
9292# endif
9293 p_ru = save_ru;
9294#endif
9295#ifdef FEAT_RIGHTLEFT
9296 p_ri = save_ri;
9297 p_hkmap = save_hkmap;
9298#endif
9299 /* set global values for local buffer options */
9300 p_tw = p_tw_nopaste;
9301 p_wm = p_wm_nopaste;
9302 p_sts = p_sts_nopaste;
9303 p_ai = p_ai_nopaste;
9304 }
9305
9306 old_p_paste = p_paste;
9307}
9308
9309/*
9310 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9311 *
9312 * Reset 'compatible' and set the values for options that didn't get set yet
9313 * to the Vim defaults.
9314 * Don't do this if the 'compatible' option has been set or reset before.
9315 */
9316 void
9317vimrc_found()
9318{
9319 int opt_idx;
9320
9321 if (!option_was_set((char_u *)"cp"))
9322 {
9323 p_cp = FALSE;
9324 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9325 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9326 set_option_default(opt_idx, OPT_FREE, FALSE);
9327 didset_options();
9328 }
9329}
9330
9331/*
9332 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9333 */
9334 void
9335change_compatible(on)
9336 int on;
9337{
9338 if (p_cp != on)
9339 {
9340 p_cp = on;
9341 compatible_set();
9342 }
9343 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9344}
9345
9346/*
9347 * Return TRUE when option "name" has been set.
9348 */
9349 int
9350option_was_set(name)
9351 char_u *name;
9352{
9353 int idx;
9354
9355 idx = findoption(name);
9356 if (idx < 0) /* unknown option */
9357 return FALSE;
9358 if (options[idx].flags & P_WAS_SET)
9359 return TRUE;
9360 return FALSE;
9361}
9362
9363/*
9364 * compatible_set() - Called when 'compatible' has been set or unset.
9365 *
9366 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9367 * flag) to a Vi compatible value.
9368 * When 'compatible' is unset: Set all options that have a different default
9369 * for Vim (without the P_VI_DEF flag) to that default.
9370 */
9371 static void
9372compatible_set()
9373{
9374 int opt_idx;
9375
9376 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9377 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9378 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9379 set_option_default(opt_idx, OPT_FREE, p_cp);
9380 didset_options();
9381}
9382
9383#ifdef FEAT_LINEBREAK
9384
9385# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9386 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009387 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009388# endif
9389
9390/*
9391 * fill_breakat_flags() -- called when 'breakat' changes value.
9392 */
9393 static void
9394fill_breakat_flags()
9395{
9396 char_u *c;
9397 int i;
9398
9399 for (i = 0; i < 256; i++)
9400 breakat_flags[i] = FALSE;
9401
9402 if (p_breakat != NULL)
9403 for (c = p_breakat; *c; c++)
9404 breakat_flags[*c] = TRUE;
9405}
9406
9407# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009408 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409# endif
9410
9411#endif
9412
9413/*
9414 * Check an option that can be a range of string values.
9415 *
9416 * Return OK for correct value, FAIL otherwise.
9417 * Empty is always OK.
9418 */
9419 static int
9420check_opt_strings(val, values, list)
9421 char_u *val;
9422 char **values;
9423 int list; /* when TRUE: accept a list of values */
9424{
9425 return opt_strings_flags(val, values, NULL, list);
9426}
9427
9428/*
9429 * Handle an option that can be a range of string values.
9430 * Set a flag in "*flagp" for each string present.
9431 *
9432 * Return OK for correct value, FAIL otherwise.
9433 * Empty is always OK.
9434 */
9435 static int
9436opt_strings_flags(val, values, flagp, list)
9437 char_u *val; /* new value */
9438 char **values; /* array of valid string values */
9439 unsigned *flagp;
9440 int list; /* when TRUE: accept a list of values */
9441{
9442 int i;
9443 int len;
9444 unsigned new_flags = 0;
9445
9446 while (*val)
9447 {
9448 for (i = 0; ; ++i)
9449 {
9450 if (values[i] == NULL) /* val not found in values[] */
9451 return FAIL;
9452
9453 len = (int)STRLEN(values[i]);
9454 if (STRNCMP(values[i], val, len) == 0
9455 && ((list && val[len] == ',') || val[len] == NUL))
9456 {
9457 val += len + (val[len] == ',');
9458 new_flags |= (1 << i);
9459 break; /* check next item in val list */
9460 }
9461 }
9462 }
9463 if (flagp != NULL)
9464 *flagp = new_flags;
9465
9466 return OK;
9467}
9468
9469/*
9470 * Read the 'wildmode' option, fill wim_flags[].
9471 */
9472 static int
9473check_opt_wim()
9474{
9475 char_u new_wim_flags[4];
9476 char_u *p;
9477 int i;
9478 int idx = 0;
9479
9480 for (i = 0; i < 4; ++i)
9481 new_wim_flags[i] = 0;
9482
9483 for (p = p_wim; *p; ++p)
9484 {
9485 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9486 ;
9487 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9488 return FAIL;
9489 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9490 new_wim_flags[idx] |= WIM_LONGEST;
9491 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9492 new_wim_flags[idx] |= WIM_FULL;
9493 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9494 new_wim_flags[idx] |= WIM_LIST;
9495 else
9496 return FAIL;
9497 p += i;
9498 if (*p == NUL)
9499 break;
9500 if (*p == ',')
9501 {
9502 if (idx == 3)
9503 return FAIL;
9504 ++idx;
9505 }
9506 }
9507
9508 /* fill remaining entries with last flag */
9509 while (idx < 3)
9510 {
9511 new_wim_flags[idx + 1] = new_wim_flags[idx];
9512 ++idx;
9513 }
9514
9515 /* only when there are no errors, wim_flags[] is changed */
9516 for (i = 0; i < 4; ++i)
9517 wim_flags[i] = new_wim_flags[i];
9518 return OK;
9519}
9520
9521/*
9522 * Check if backspacing over something is allowed.
9523 */
9524 int
9525can_bs(what)
9526 int what; /* BS_INDENT, BS_EOL or BS_START */
9527{
9528 switch (*p_bs)
9529 {
9530 case '2': return TRUE;
9531 case '1': return (what != BS_START);
9532 case '0': return FALSE;
9533 }
9534 return vim_strchr(p_bs, what) != NULL;
9535}
9536
9537/*
9538 * Save the current values of 'fileformat' and 'fileencoding', so that we know
9539 * the file must be considered changed when the value is different.
9540 */
9541 void
9542save_file_ff(buf)
9543 buf_T *buf;
9544{
9545 buf->b_start_ffc = *buf->b_p_ff;
9546 buf->b_start_eol = buf->b_p_eol;
9547#ifdef FEAT_MBYTE
9548 /* Only use free/alloc when necessary, they take time. */
9549 if (buf->b_start_fenc == NULL
9550 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9551 {
9552 vim_free(buf->b_start_fenc);
9553 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9554 }
9555#endif
9556}
9557
9558/*
9559 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9560 * from when editing started (save_file_ff() called).
9561 * Also when 'endofline' was changed and 'binary' is set.
9562 * Don't consider a new, empty buffer to be changed.
9563 */
9564 int
9565file_ff_differs(buf)
9566 buf_T *buf;
9567{
9568 if ((buf->b_flags & BF_NEW)
9569 && buf->b_ml.ml_line_count == 1
9570 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
9571 return FALSE;
9572 if (buf->b_start_ffc != *buf->b_p_ff)
9573 return TRUE;
9574 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
9575 return TRUE;
9576#ifdef FEAT_MBYTE
9577 if (buf->b_start_fenc == NULL)
9578 return (*buf->b_p_fenc != NUL);
9579 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
9580#else
9581 return FALSE;
9582#endif
9583}
9584
9585/*
9586 * return OK if "p" is a valid fileformat name, FAIL otherwise.
9587 */
9588 int
9589check_ff_value(p)
9590 char_u *p;
9591{
9592 return check_opt_strings(p, p_ff_values, FALSE);
9593}