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