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