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