blob: cf5e9b407a73148408c7348aecd519d478c89c1f [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 Moolenaar6bb68362005-03-22 23:03:44 +00005661 /* When 'spelllang' is set, load the wordlists. */
Bram Moolenaar217ad922005-03-20 22:37:15 +00005662 else if (varp == &(curbuf->b_p_spl))
5663 {
5664 errmsg = did_set_spelllang(curbuf);
5665 }
5666#endif
5667
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668#ifdef FEAT_AUTOCMD
5669# ifdef FEAT_SYN_HL
5670 /* When 'syntax' is set, load the syntax of that name */
5671 else if (varp == &(curbuf->b_p_syn))
5672 {
5673 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
5674 curbuf->b_fname, TRUE, curbuf);
5675 }
5676# endif
5677
5678 /* When 'filetype' is set, trigger the FileType autocommands of that name */
5679 else if (varp == &(curbuf->b_p_ft))
5680 {
5681 did_filetype = TRUE;
5682 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
5683 curbuf->b_fname, TRUE, curbuf);
5684 }
5685#endif
5686
5687#ifdef FEAT_QUICKFIX
5688 /* When 'bufhidden' is set, check for valid value. */
5689 else if (gvarp == &p_bh)
5690 {
5691 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5692 errmsg = e_invarg;
5693 }
5694
5695 /* When 'buftype' is set, check for valid value. */
5696 else if (gvarp == &p_bt)
5697 {
5698 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5699 errmsg = e_invarg;
5700 else
5701 {
5702# ifdef FEAT_WINDOWS
5703 if (curwin->w_status_height)
5704 {
5705 curwin->w_redr_status = TRUE;
5706 redraw_later(VALID);
5707 }
5708# endif
5709 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5710 }
5711 }
5712#endif
5713
5714#ifdef FEAT_STL_OPT
5715 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005716 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717 {
5718 int wid;
5719
5720 if (varp == &p_ruf) /* reset ru_wid first */
5721 ru_wid = 0;
5722 s = *varp;
5723 if (varp == &p_ruf && *s == '%')
5724 {
5725 /* set ru_wid if 'ruf' starts with "%99(" */
5726 if (*++s == '-') /* ignore a '-' */
5727 s++;
5728 wid = getdigits(&s);
5729 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5730 ru_wid = wid;
5731 else
5732 errmsg = check_stl_option(p_ruf);
5733 }
5734 else
5735 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005736 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737 comp_col();
5738 }
5739#endif
5740
5741#ifdef FEAT_INS_EXPAND
5742 /* check if it is a valid value for 'complete' -- Acevedo */
5743 else if (gvarp == &p_cpt)
5744 {
5745 for (s = *varp; *s;)
5746 {
5747 while(*s == ',' || *s == ' ')
5748 s++;
5749 if (!*s)
5750 break;
5751 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5752 {
5753 errmsg = illegal_char(errbuf, *s);
5754 break;
5755 }
5756 if (*++s != NUL && *s != ',' && *s != ' ')
5757 {
5758 if (s[-1] == 'k' || s[-1] == 's')
5759 {
5760 /* skip optional filename after 'k' and 's' */
5761 while (*s && *s != ',' && *s != ' ')
5762 {
5763 if (*s == '\\')
5764 ++s;
5765 ++s;
5766 }
5767 }
5768 else
5769 {
5770 if (errbuf != NULL)
5771 {
5772 sprintf((char *)errbuf,
5773 _("E535: Illegal character after <%c>"),
5774 *--s);
5775 errmsg = errbuf;
5776 }
5777 else
5778 errmsg = (char_u *)"";
5779 break;
5780 }
5781 }
5782 }
5783 }
5784#endif /* FEAT_INS_EXPAND */
5785
5786
5787#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5788 else if (varp == &p_toolbar)
5789 {
5790 if (opt_strings_flags(p_toolbar, p_toolbar_values,
5791 &toolbar_flags, TRUE) != OK)
5792 errmsg = e_invarg;
5793 else
5794 {
5795 out_flush();
5796 gui_mch_show_toolbar((toolbar_flags &
5797 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5798 }
5799 }
5800#endif
5801
5802#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5803 /* 'toolbariconsize': GTK+ 2 only */
5804 else if (varp == &p_tbis)
5805 {
5806 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
5807 errmsg = e_invarg;
5808 else
5809 {
5810 out_flush();
5811 gui_mch_show_toolbar((toolbar_flags &
5812 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5813 }
5814 }
5815#endif
5816
5817 /* 'pastetoggle': translate key codes like in a mapping */
5818 else if (varp == &p_pt)
5819 {
5820 if (*p_pt)
5821 {
5822 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
5823 if (p != NULL)
5824 {
5825 if (new_value_alloced)
5826 free_string_option(p_pt);
5827 p_pt = p;
5828 new_value_alloced = TRUE;
5829 }
5830 }
5831 }
5832
5833 /* 'backspace' */
5834 else if (varp == &p_bs)
5835 {
5836 if (VIM_ISDIGIT(*p_bs))
5837 {
5838 if (*p_bs >'2' || p_bs[1] != NUL)
5839 errmsg = e_invarg;
5840 }
5841 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
5842 errmsg = e_invarg;
5843 }
5844
5845 /* 'casemap' */
5846 else if (varp == &p_cmp)
5847 {
5848 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
5849 errmsg = e_invarg;
5850 }
5851
5852#ifdef FEAT_DIFF
5853 /* 'diffopt' */
5854 else if (varp == &p_dip)
5855 {
5856 if (diffopt_changed() == FAIL)
5857 errmsg = e_invarg;
5858 }
5859#endif
5860
5861#ifdef FEAT_FOLDING
5862 /* 'foldmethod' */
5863 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
5864 {
5865 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
5866 || *curwin->w_p_fdm == NUL)
5867 errmsg = e_invarg;
5868 else
5869 foldUpdateAll(curwin);
5870 }
5871# ifdef FEAT_EVAL
5872 /* 'foldexpr' */
5873 else if (varp == &curwin->w_p_fde)
5874 {
5875 if (foldmethodIsExpr(curwin))
5876 foldUpdateAll(curwin);
5877 }
5878# endif
5879 /* 'foldmarker' */
5880 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
5881 {
5882 p = vim_strchr(*varp, ',');
5883 if (p == NULL)
5884 errmsg = (char_u *)N_("E536: comma required");
5885 else if (p == *varp || p[1] == NUL)
5886 errmsg = e_invarg;
5887 else if (foldmethodIsMarker(curwin))
5888 foldUpdateAll(curwin);
5889 }
5890 /* 'commentstring' */
5891 else if (gvarp == &p_cms)
5892 {
5893 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
5894 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
5895 }
5896 /* 'foldopen' */
5897 else if (varp == &p_fdo)
5898 {
5899 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
5900 errmsg = e_invarg;
5901 }
5902 /* 'foldclose' */
5903 else if (varp == &p_fcl)
5904 {
5905 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
5906 errmsg = e_invarg;
5907 }
5908#endif
5909
5910#ifdef FEAT_VIRTUALEDIT
5911 /* 'virtualedit' */
5912 else if (varp == &p_ve)
5913 {
5914 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
5915 errmsg = e_invarg;
5916 else if (STRCMP(p_ve, oldval) != 0)
5917 {
5918 /* Recompute cursor position in case the new 've' setting
5919 * changes something. */
5920 validate_virtcol();
5921 coladvance(curwin->w_virtcol);
5922 }
5923 }
5924#endif
5925
5926#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
5927 else if (varp == &p_csqf)
5928 {
5929 if (p_csqf != NULL)
5930 {
5931 p = p_csqf;
5932 while (*p != NUL)
5933 {
5934 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
5935 || p[1] == NUL
5936 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
5937 || (p[2] != NUL && p[2] != ','))
5938 {
5939 errmsg = e_invarg;
5940 break;
5941 }
5942 else if (p[2] == NUL)
5943 break;
5944 else
5945 p += 3;
5946 }
5947 }
5948 }
5949#endif
5950
5951 /* Options that are a list of flags. */
5952 else
5953 {
5954 p = NULL;
5955 if (varp == &p_ww)
5956 p = (char_u *)WW_ALL;
5957 if (varp == &p_shm)
5958 p = (char_u *)SHM_ALL;
5959 else if (varp == &(p_cpo))
5960 p = (char_u *)CPO_ALL;
5961 else if (varp == &(curbuf->b_p_fo))
5962 p = (char_u *)FO_ALL;
5963 else if (varp == &p_mouse)
5964 {
5965#ifdef FEAT_MOUSE
5966 p = (char_u *)MOUSE_ALL;
5967#else
5968 if (*p_mouse != NUL)
5969 errmsg = (char_u *)N_("E538: No mouse support");
5970#endif
5971 }
5972#if defined(FEAT_GUI)
5973 else if (varp == &p_go)
5974 p = (char_u *)GO_ALL;
5975#endif
5976 if (p != NULL)
5977 {
5978 for (s = *varp; *s; ++s)
5979 if (vim_strchr(p, *s) == NULL)
5980 {
5981 errmsg = illegal_char(errbuf, *s);
5982 break;
5983 }
5984 }
5985 }
5986
5987 /*
5988 * If error detected, restore the previous value.
5989 */
5990 if (errmsg != NULL)
5991 {
5992 if (new_value_alloced)
5993 free_string_option(*varp);
5994 *varp = oldval;
5995 /*
5996 * When resetting some values, need to act on it.
5997 */
5998 if (did_chartab)
5999 (void)init_chartab();
6000 if (varp == &p_hl)
6001 (void)highlight_changed();
6002 }
6003 else
6004 {
6005#ifdef FEAT_EVAL
6006 /* Remember where the option was set. */
6007 options[opt_idx].scriptID = current_SID;
6008#endif
6009 /*
6010 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006011 * Use "free_oldval", because recursiveness may change the flags under
6012 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006013 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006014 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006015 free_string_option(oldval);
6016 if (new_value_alloced)
6017 options[opt_idx].flags |= P_ALLOCED;
6018 else
6019 options[opt_idx].flags &= ~P_ALLOCED;
6020
6021 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6022 && (int)options[opt_idx].indir >= PV_BOTH)
6023 {
6024 /* global option with local value set to use global value; free
6025 * the local value and make it empty */
6026 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6027 free_string_option(*(char_u **)p);
6028 *(char_u **)p = empty_option;
6029 }
6030
6031 /* May set global value for local option. */
6032 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6033 set_string_option_global(opt_idx, varp);
6034 }
6035
6036#ifdef FEAT_MOUSE
6037 if (varp == &p_mouse)
6038 {
6039# ifdef FEAT_MOUSE_TTY
6040 if (*p_mouse == NUL)
6041 mch_setmouse(FALSE); /* switch mouse off */
6042 else
6043# endif
6044 setmouse(); /* in case 'mouse' changed */
6045 }
6046#endif
6047
6048 if (curwin->w_curswant != MAXCOL)
6049 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6050 check_redraw(options[opt_idx].flags);
6051
6052 return errmsg;
6053}
6054
6055/*
6056 * Handle setting 'listchars' or 'fillchars'.
6057 * Returns error message, NULL if it's OK.
6058 */
6059 static char_u *
6060set_chars_option(varp)
6061 char_u **varp;
6062{
6063 int round, i, len, entries;
6064 char_u *p, *s;
6065 int c1, c2 = 0;
6066 struct charstab
6067 {
6068 int *cp;
6069 char *name;
6070 };
6071#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6072 static struct charstab filltab[] =
6073 {
6074 {&fill_stl, "stl"},
6075 {&fill_stlnc, "stlnc"},
6076 {&fill_vert, "vert"},
6077 {&fill_fold, "fold"},
6078 {&fill_diff, "diff"},
6079 };
6080#endif
6081 static struct charstab lcstab[] =
6082 {
6083 {&lcs_eol, "eol"},
6084 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006085 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086 {&lcs_prec, "precedes"},
6087 {&lcs_tab2, "tab"},
6088 {&lcs_trail, "trail"},
6089 };
6090 struct charstab *tab;
6091
6092#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6093 if (varp == &p_lcs)
6094#endif
6095 {
6096 tab = lcstab;
6097 entries = sizeof(lcstab) / sizeof(struct charstab);
6098 }
6099#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6100 else
6101 {
6102 tab = filltab;
6103 entries = sizeof(filltab) / sizeof(struct charstab);
6104 }
6105#endif
6106
6107 /* first round: check for valid value, second round: assign values */
6108 for (round = 0; round <= 1; ++round)
6109 {
6110 if (round)
6111 {
6112 /* After checking that the value is valid: set defaults: space for
6113 * 'fillchars', NUL for 'listchars' */
6114 for (i = 0; i < entries; ++i)
6115 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6116 if (varp == &p_lcs)
6117 lcs_tab1 = NUL;
6118#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6119 else
6120 fill_diff = '-';
6121#endif
6122 }
6123 p = *varp;
6124 while (*p)
6125 {
6126 for (i = 0; i < entries; ++i)
6127 {
6128 len = (int)STRLEN(tab[i].name);
6129 if (STRNCMP(p, tab[i].name, len) == 0
6130 && p[len] == ':'
6131 && p[len + 1] != NUL)
6132 {
6133 s = p + len + 1;
6134#ifdef FEAT_MBYTE
6135 c1 = mb_ptr2char_adv(&s);
6136#else
6137 c1 = *s++;
6138#endif
6139 if (tab[i].cp == &lcs_tab2)
6140 {
6141 if (*s == NUL)
6142 continue;
6143#ifdef FEAT_MBYTE
6144 c2 = mb_ptr2char_adv(&s);
6145#else
6146 c2 = *s++;
6147#endif
6148 }
6149 if (*s == ',' || *s == NUL)
6150 {
6151 if (round)
6152 {
6153 if (tab[i].cp == &lcs_tab2)
6154 {
6155 lcs_tab1 = c1;
6156 lcs_tab2 = c2;
6157 }
6158 else
6159 *(tab[i].cp) = c1;
6160
6161 }
6162 p = s;
6163 break;
6164 }
6165 }
6166 }
6167
6168 if (i == entries)
6169 return e_invarg;
6170 if (*p == ',')
6171 ++p;
6172 }
6173 }
6174
6175 return NULL; /* no error */
6176}
6177
6178#ifdef FEAT_STL_OPT
6179/*
6180 * Check validity of options with the 'statusline' format.
6181 * Return error message or NULL.
6182 */
6183 char_u *
6184check_stl_option(s)
6185 char_u *s;
6186{
6187 int itemcnt = 0;
6188 int groupdepth = 0;
6189 static char_u errbuf[80];
6190
6191 while (*s && itemcnt < STL_MAX_ITEM)
6192 {
6193 /* Check for valid keys after % sequences */
6194 while (*s && *s != '%')
6195 s++;
6196 if (!*s)
6197 break;
6198 s++;
6199 if (*s != '%' && *s != ')')
6200 ++itemcnt;
6201 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6202 {
6203 s++;
6204 continue;
6205 }
6206 if (*s == ')')
6207 {
6208 s++;
6209 if (--groupdepth < 0)
6210 break;
6211 continue;
6212 }
6213 if (*s == '-')
6214 s++;
6215 while (VIM_ISDIGIT(*s))
6216 s++;
6217 if (*s == STL_HIGHLIGHT)
6218 continue;
6219 if (*s == '.')
6220 {
6221 s++;
6222 while (*s && VIM_ISDIGIT(*s))
6223 s++;
6224 }
6225 if (*s == '(')
6226 {
6227 groupdepth++;
6228 continue;
6229 }
6230 if (vim_strchr(STL_ALL, *s) == NULL)
6231 {
6232 return illegal_char(errbuf, *s);
6233 }
6234 if (*s == '{')
6235 {
6236 s++;
6237 while (*s != '}' && *s)
6238 s++;
6239 if (*s != '}')
6240 return (char_u *)N_("E540: Unclosed expression sequence");
6241 }
6242 }
6243 if (itemcnt >= STL_MAX_ITEM)
6244 return (char_u *)N_("E541: too many items");
6245 if (groupdepth != 0)
6246 return (char_u *)N_("E542: unbalanced groups");
6247 return NULL;
6248}
6249#endif
6250
6251#ifdef FEAT_CLIPBOARD
6252/*
6253 * Extract the items in the 'clipboard' option and set global values.
6254 */
6255 static char_u *
6256check_clipboard_option()
6257{
6258 int new_unnamed = FALSE;
6259 int new_autoselect = FALSE;
6260 int new_autoselectml = FALSE;
6261 regprog_T *new_exclude_prog = NULL;
6262 char_u *errmsg = NULL;
6263 char_u *p;
6264
6265 for (p = p_cb; *p != NUL; )
6266 {
6267 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6268 {
6269 new_unnamed = TRUE;
6270 p += 7;
6271 }
6272 else if (STRNCMP(p, "autoselect", 10) == 0
6273 && (p[10] == ',' || p[10] == NUL))
6274 {
6275 new_autoselect = TRUE;
6276 p += 10;
6277 }
6278 else if (STRNCMP(p, "autoselectml", 12) == 0
6279 && (p[12] == ',' || p[12] == NUL))
6280 {
6281 new_autoselectml = TRUE;
6282 p += 12;
6283 }
6284 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6285 {
6286 p += 8;
6287 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6288 if (new_exclude_prog == NULL)
6289 errmsg = e_invarg;
6290 break;
6291 }
6292 else
6293 {
6294 errmsg = e_invarg;
6295 break;
6296 }
6297 if (*p == ',')
6298 ++p;
6299 }
6300 if (errmsg == NULL)
6301 {
6302 clip_unnamed = new_unnamed;
6303 clip_autoselect = new_autoselect;
6304 clip_autoselectml = new_autoselectml;
6305 vim_free(clip_exclude_prog);
6306 clip_exclude_prog = new_exclude_prog;
6307 }
6308 else
6309 vim_free(new_exclude_prog);
6310
6311 return errmsg;
6312}
6313#endif
6314
6315/*
6316 * Set the value of a boolean option, and take care of side effects.
6317 * Returns NULL for success, or an error message for an error.
6318 */
6319 static char_u *
6320set_bool_option(opt_idx, varp, value, opt_flags)
6321 int opt_idx; /* index in options[] table */
6322 char_u *varp; /* pointer to the option variable */
6323 int value; /* new value */
6324 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6325{
6326 int old_value = *(int *)varp;
6327
6328#ifdef FEAT_GUI
6329 need_mouse_correct = TRUE;
6330#endif
6331
6332 /* Disallow changing some options from secure mode */
6333 if ((secure
6334#ifdef HAVE_SANDBOX
6335 || sandbox != 0
6336#endif
6337 ) && (options[opt_idx].flags & P_SECURE))
6338 return e_secure;
6339
6340 *(int *)varp = value; /* set the new value */
6341#ifdef FEAT_EVAL
6342 /* Remember where the option was set. */
6343 options[opt_idx].scriptID = current_SID;
6344#endif
6345
6346 /* May set global value for local option. */
6347 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6348 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6349
6350 /*
6351 * Handle side effects of changing a bool option.
6352 */
6353
6354 /* 'compatible' */
6355 if ((int *)varp == &p_cp)
6356 {
6357 compatible_set();
6358 }
6359
6360 /* when 'readonly' is reset globally, also reset readonlymode */
6361 else if ((int *)varp == &curbuf->b_p_ro)
6362 {
6363 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6364 readonlymode = FALSE;
6365#ifdef FEAT_TITLE
6366 need_maketitle = TRUE;
6367#endif
6368 }
6369
6370#ifdef FEAT_TITLE
6371 /* when 'modifiable' is changed, redraw the window title */
6372 else if ((int *)varp == &curbuf->b_p_ma)
6373 need_maketitle = TRUE;
6374 /* when 'endofline' is changed, redraw the window title */
6375 else if ((int *)varp == &curbuf->b_p_eol)
6376 need_maketitle = TRUE;
6377#endif
6378
6379 /* when 'bin' is set also set some other options */
6380 else if ((int *)varp == &curbuf->b_p_bin)
6381 {
6382 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6383#ifdef FEAT_TITLE
6384 need_maketitle = TRUE;
6385#endif
6386 }
6387
6388#ifdef FEAT_AUTOCMD
6389 /* when 'buflisted' changes, trigger autocommands */
6390 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6391 {
6392 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6393 NULL, NULL, TRUE, curbuf);
6394 }
6395#endif
6396
6397 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6398 else if ((int *)varp == &curbuf->b_p_swf)
6399 {
6400 if (curbuf->b_p_swf && p_uc)
6401 ml_open_file(curbuf); /* create the swap file */
6402 else
6403 mf_close_file(curbuf, TRUE); /* remove the swap file */
6404 }
6405
6406 /* when 'terse' is set change 'shortmess' */
6407 else if ((int *)varp == &p_terse)
6408 {
6409 char_u *p;
6410
6411 p = vim_strchr(p_shm, SHM_SEARCH);
6412
6413 /* insert 's' in p_shm */
6414 if (p_terse && p == NULL)
6415 {
6416 STRCPY(IObuff, p_shm);
6417 STRCAT(IObuff, "s");
6418 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6419 }
6420 /* remove 's' from p_shm */
6421 else if (!p_terse && p != NULL)
6422 mch_memmove(p, p + 1, STRLEN(p));
6423 }
6424
6425 /* when 'paste' is set or reset also change other options */
6426 else if ((int *)varp == &p_paste)
6427 {
6428 paste_option_changed();
6429 }
6430
6431 /* when 'insertmode' is set from an autocommand need to do work here */
6432 else if ((int *)varp == &p_im)
6433 {
6434 if (p_im)
6435 {
6436 if ((State & INSERT) == 0)
6437 need_start_insertmode = TRUE;
6438 stop_insert_mode = FALSE;
6439 }
6440 else
6441 {
6442 need_start_insertmode = FALSE;
6443 stop_insert_mode = TRUE;
6444 if (p_smd && restart_edit != 0)
6445 clear_cmdline = TRUE; /* remove "(insert)" */
6446 restart_edit = 0;
6447 }
6448 }
6449
6450 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6451 else if ((int *)varp == &p_ic && p_hls)
6452 {
6453 redraw_all_later(NOT_VALID);
6454 }
6455
6456#ifdef FEAT_SEARCH_EXTRA
6457 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6458 else if ((int *)varp == &p_hls)
6459 {
6460 no_hlsearch = FALSE;
6461 }
6462#endif
6463
6464#ifdef FEAT_SCROLLBIND
6465 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6466 * at the end of normal_cmd() */
6467 else if ((int *)varp == &curwin->w_p_scb)
6468 {
6469 if (curwin->w_p_scb)
6470 do_check_scrollbind(FALSE);
6471 }
6472#endif
6473
6474#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6475 /* There can be only one window with 'previewwindow' set. */
6476 else if ((int *)varp == &curwin->w_p_pvw)
6477 {
6478 if (curwin->w_p_pvw)
6479 {
6480 win_T *win;
6481
6482 for (win = firstwin; win != NULL; win = win->w_next)
6483 if (win->w_p_pvw && win != curwin)
6484 {
6485 curwin->w_p_pvw = FALSE;
6486 return (char_u *)N_("E590: A preview window already exists");
6487 }
6488 }
6489 }
6490#endif
6491
6492 /* when 'textmode' is set or reset also change 'fileformat' */
6493 else if ((int *)varp == &curbuf->b_p_tx)
6494 {
6495 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6496 }
6497
6498 /* when 'textauto' is set or reset also change 'fileformats' */
6499 else if ((int *)varp == &p_ta)
6500 {
6501 set_string_option_direct((char_u *)"ffs", -1,
6502 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6503 OPT_FREE | opt_flags);
6504 }
6505
6506 /*
6507 * When 'lisp' option changes include/exclude '-' in
6508 * keyword characters.
6509 */
6510#ifdef FEAT_LISP
6511 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6512 {
6513 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6514 }
6515#endif
6516
6517#ifdef FEAT_TITLE
6518 /* when 'title' changed, may need to change the title; same for 'icon' */
6519 else if ((int *)varp == &p_title)
6520 {
6521 did_set_title(FALSE);
6522 }
6523
6524 else if ((int *)varp == &p_icon)
6525 {
6526 did_set_title(TRUE);
6527 }
6528#endif
6529
6530 else if ((int *)varp == &curbuf->b_changed)
6531 {
6532 if (!value)
6533 save_file_ff(curbuf); /* Buffer is unchanged */
6534#ifdef FEAT_TITLE
6535 need_maketitle = TRUE;
6536#endif
6537#ifdef FEAT_AUTOCMD
6538 modified_was_set = value;
6539#endif
6540 }
6541
6542#ifdef BACKSLASH_IN_FILENAME
6543 else if ((int *)varp == &p_ssl)
6544 {
6545 if (p_ssl)
6546 {
6547 psepc = '/';
6548 psepcN = '\\';
6549 pseps[0] = '/';
6550 psepsN[0] = '\\';
6551 }
6552 else
6553 {
6554 psepc = '\\';
6555 psepcN = '/';
6556 pseps[0] = '\\';
6557 psepsN[0] = '/';
6558 }
6559
6560 /* need to adjust the file name arguments and buffer names. */
6561 buflist_slash_adjust();
6562 alist_slash_adjust();
6563# ifdef FEAT_EVAL
6564 scriptnames_slash_adjust();
6565# endif
6566 }
6567#endif
6568
6569 /* If 'wrap' is set, set w_leftcol to zero. */
6570 else if ((int *)varp == &curwin->w_p_wrap)
6571 {
6572 if (curwin->w_p_wrap)
6573 curwin->w_leftcol = 0;
6574 }
6575
6576#ifdef FEAT_WINDOWS
6577 else if ((int *)varp == &p_ea)
6578 {
6579 if (p_ea && !old_value)
6580 win_equal(curwin, FALSE, 0);
6581 }
6582#endif
6583
6584 else if ((int *)varp == &p_wiv)
6585 {
6586 /*
6587 * When 'weirdinvert' changed, set/reset 't_xs'.
6588 * Then set 'weirdinvert' according to value of 't_xs'.
6589 */
6590 if (p_wiv && !old_value)
6591 T_XS = (char_u *)"y";
6592 else if (!p_wiv && old_value)
6593 T_XS = empty_option;
6594 p_wiv = (*T_XS != NUL);
6595 }
6596
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006597#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598 else if ((int *)varp == &p_beval)
6599 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006600 if (p_beval == TRUE)
6601 gui_mch_enable_beval_area(balloonEval);
6602 else
6603 gui_mch_disable_beval_area(balloonEval);
6604 }
6605
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006606# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006607 else if ((int *)varp == &p_acd)
6608 {
6609 if (p_acd && curbuf->b_ffname != NULL
6610 && vim_chdirfile(curbuf->b_ffname) == OK)
6611 shorten_fnames(TRUE);
6612 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006613# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006614#endif
6615
6616#ifdef FEAT_DIFF
6617 /* 'diff' */
6618 else if ((int *)varp == &curwin->w_p_diff)
6619 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006620 /* May add or remove the buffer from the list of diff buffers. */
6621 diff_buf_adjust(curwin);
6622# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623 if (foldmethodIsDiff(curwin))
6624 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006625# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006626 }
6627#endif
6628
6629#ifdef USE_IM_CONTROL
6630 /* 'imdisable' */
6631 else if ((int *)varp == &p_imdisable)
6632 {
6633 /* Only de-activate it here, it will be enabled when changing mode. */
6634 if (p_imdisable)
6635 im_set_active(FALSE);
6636 }
6637#endif
6638
6639#ifdef FEAT_FKMAP
6640 else if ((int *)varp == &p_altkeymap)
6641 {
6642 if (old_value != p_altkeymap)
6643 {
6644 if (!p_altkeymap)
6645 {
6646 p_hkmap = p_fkmap;
6647 p_fkmap = 0;
6648 }
6649 else
6650 {
6651 p_fkmap = p_hkmap;
6652 p_hkmap = 0;
6653 }
6654 (void)init_chartab();
6655 }
6656 }
6657
6658 /*
6659 * In case some second language keymapping options have changed, check
6660 * and correct the setting in a consistent way.
6661 */
6662
6663 /*
6664 * If hkmap or fkmap are set, reset Arabic keymapping.
6665 */
6666 if ((p_hkmap || p_fkmap) && p_altkeymap)
6667 {
6668 p_altkeymap = p_fkmap;
6669# ifdef FEAT_ARABIC
6670 curwin->w_p_arab = FALSE;
6671# endif
6672 (void)init_chartab();
6673 }
6674
6675 /*
6676 * If hkmap set, reset Farsi keymapping.
6677 */
6678 if (p_hkmap && p_altkeymap)
6679 {
6680 p_altkeymap = 0;
6681 p_fkmap = 0;
6682# ifdef FEAT_ARABIC
6683 curwin->w_p_arab = FALSE;
6684# endif
6685 (void)init_chartab();
6686 }
6687
6688 /*
6689 * If fkmap set, reset Hebrew keymapping.
6690 */
6691 if (p_fkmap && !p_altkeymap)
6692 {
6693 p_altkeymap = 1;
6694 p_hkmap = 0;
6695# ifdef FEAT_ARABIC
6696 curwin->w_p_arab = FALSE;
6697# endif
6698 (void)init_chartab();
6699 }
6700#endif
6701
6702#ifdef FEAT_ARABIC
6703 if ((int *)varp == &curwin->w_p_arab)
6704 {
6705 if (curwin->w_p_arab)
6706 {
6707 /*
6708 * 'arabic' is set, handle various sub-settings.
6709 */
6710 if (!p_tbidi)
6711 {
6712 /* set rightleft mode */
6713 if (!curwin->w_p_rl)
6714 {
6715 curwin->w_p_rl = TRUE;
6716 changed_window_setting();
6717 }
6718
6719 /* Enable Arabic shaping (major part of what Arabic requires) */
6720 if (!p_arshape)
6721 {
6722 p_arshape = TRUE;
6723 redraw_later_clear();
6724 }
6725 }
6726
6727 /* Arabic requires a utf-8 encoding, inform the user if its not
6728 * set. */
6729 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006730 {
6731 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6733 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006734 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006735
6736# ifdef FEAT_MBYTE
6737 /* set 'delcombine' */
6738 p_deco = TRUE;
6739# endif
6740
6741# ifdef FEAT_KEYMAP
6742 /* Force-set the necessary keymap for arabic */
6743 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
6744 OPT_LOCAL);
6745# endif
6746# ifdef FEAT_FKMAP
6747 p_altkeymap = 0;
6748 p_hkmap = 0;
6749 p_fkmap = 0;
6750 (void)init_chartab();
6751# endif
6752 }
6753 else
6754 {
6755 /*
6756 * 'arabic' is reset, handle various sub-settings.
6757 */
6758 if (!p_tbidi)
6759 {
6760 /* reset rightleft mode */
6761 if (curwin->w_p_rl)
6762 {
6763 curwin->w_p_rl = FALSE;
6764 changed_window_setting();
6765 }
6766
6767 /* 'arabicshape' isn't reset, it is a global option and
6768 * another window may still need it "on". */
6769 }
6770
6771 /* 'delcombine' isn't reset, it is a global option and another
6772 * window may still want it "on". */
6773
6774# ifdef FEAT_KEYMAP
6775 /* Revert to the default keymap */
6776 curbuf->b_p_iminsert = B_IMODE_NONE;
6777 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6778# endif
6779 }
6780 }
6781#endif
6782
6783 /*
6784 * End of handling side effects for bool options.
6785 */
6786
6787 options[opt_idx].flags |= P_WAS_SET;
6788
6789 comp_col(); /* in case 'ruler' or 'showcmd' changed */
6790 if (curwin->w_curswant != MAXCOL)
6791 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
6792 check_redraw(options[opt_idx].flags);
6793
6794 return NULL;
6795}
6796
6797/*
6798 * Set the value of a number option, and take care of side effects.
6799 * Returns NULL for success, or an error message for an error.
6800 */
6801 static char_u *
6802set_num_option(opt_idx, varp, value, errbuf, opt_flags)
6803 int opt_idx; /* index in options[] table */
6804 char_u *varp; /* pointer to the option variable */
6805 long value; /* new value */
6806 char_u *errbuf; /* buffer for error messages */
6807 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
6808 OPT_MODELINE */
6809{
6810 char_u *errmsg = NULL;
6811 long old_value = *(long *)varp;
6812 long old_Rows = Rows; /* remember old Rows */
6813 long old_Columns = Columns; /* remember old Columns */
6814 long *pp = (long *)varp;
6815
6816#ifdef FEAT_GUI
6817 need_mouse_correct = TRUE;
6818#endif
6819
6820 *pp = value;
6821#ifdef FEAT_EVAL
6822 /* Remember where the option was set. */
6823 options[opt_idx].scriptID = current_SID;
6824#endif
6825
6826 if (curbuf->b_p_sw <= 0)
6827 {
6828 errmsg = e_positive;
6829 curbuf->b_p_sw = curbuf->b_p_ts;
6830 }
6831
6832 /*
6833 * Number options that need some action when changed
6834 */
6835#ifdef FEAT_WINDOWS
6836 if (pp == &p_wh || pp == &p_hh)
6837 {
6838 if (p_wh < 1)
6839 {
6840 errmsg = e_positive;
6841 p_wh = 1;
6842 }
6843 if (p_wmh > p_wh)
6844 {
6845 errmsg = e_winheight;
6846 p_wh = p_wmh;
6847 }
6848 if (p_hh < 0)
6849 {
6850 errmsg = e_positive;
6851 p_hh = 0;
6852 }
6853
6854 /* Change window height NOW */
6855 if (lastwin != firstwin)
6856 {
6857 if (pp == &p_wh && curwin->w_height < p_wh)
6858 win_setheight((int)p_wh);
6859 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
6860 win_setheight((int)p_hh);
6861 }
6862 }
6863
6864 /* 'winminheight' */
6865 else if (pp == &p_wmh)
6866 {
6867 if (p_wmh < 0)
6868 {
6869 errmsg = e_positive;
6870 p_wmh = 0;
6871 }
6872 if (p_wmh > p_wh)
6873 {
6874 errmsg = e_winheight;
6875 p_wmh = p_wh;
6876 }
6877 win_setminheight();
6878 }
6879
6880# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006881 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006882 {
6883 if (p_wiw < 1)
6884 {
6885 errmsg = e_positive;
6886 p_wiw = 1;
6887 }
6888 if (p_wmw > p_wiw)
6889 {
6890 errmsg = e_winwidth;
6891 p_wiw = p_wmw;
6892 }
6893
6894 /* Change window width NOW */
6895 if (lastwin != firstwin && curwin->w_width < p_wiw)
6896 win_setwidth((int)p_wiw);
6897 }
6898
6899 /* 'winminwidth' */
6900 else if (pp == &p_wmw)
6901 {
6902 if (p_wmw < 0)
6903 {
6904 errmsg = e_positive;
6905 p_wmw = 0;
6906 }
6907 if (p_wmw > p_wiw)
6908 {
6909 errmsg = e_winwidth;
6910 p_wmw = p_wiw;
6911 }
6912 win_setminheight();
6913 }
6914# endif
6915
6916#endif
6917
6918#ifdef FEAT_WINDOWS
6919 /* (re)set last window status line */
6920 else if (pp == &p_ls)
6921 {
6922 last_status(FALSE);
6923 }
6924#endif
6925
6926#ifdef FEAT_GUI
6927 else if (pp == &p_linespace)
6928 {
6929 if (gui.in_use && gui_mch_adjust_charsize() == OK)
6930 gui_set_shellsize(FALSE, FALSE);
6931 }
6932#endif
6933
6934#ifdef FEAT_FOLDING
6935 /* 'foldlevel' */
6936 else if (pp == &curwin->w_p_fdl)
6937 {
6938 if (curwin->w_p_fdl < 0)
6939 curwin->w_p_fdl = 0;
6940 newFoldLevel();
6941 }
6942
6943 /* 'foldminlevel' */
6944 else if (pp == &curwin->w_p_fml)
6945 {
6946 foldUpdateAll(curwin);
6947 }
6948
6949 /* 'foldnestmax' */
6950 else if (pp == &curwin->w_p_fdn)
6951 {
6952 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
6953 foldUpdateAll(curwin);
6954 }
6955
6956 /* 'foldcolumn' */
6957 else if (pp == &curwin->w_p_fdc)
6958 {
6959 if (curwin->w_p_fdc < 0)
6960 {
6961 errmsg = e_positive;
6962 curwin->w_p_fdc = 0;
6963 }
6964 else if (curwin->w_p_fdc > 12)
6965 {
6966 errmsg = e_invarg;
6967 curwin->w_p_fdc = 12;
6968 }
6969 }
6970
6971 /* 'shiftwidth' or 'tabstop' */
6972 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
6973 {
6974 if (foldmethodIsIndent(curwin))
6975 foldUpdateAll(curwin);
6976 }
6977#endif /* FEAT_FOLDING */
6978
6979 else if (pp == &curbuf->b_p_iminsert)
6980 {
6981 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
6982 {
6983 errmsg = e_invarg;
6984 curbuf->b_p_iminsert = B_IMODE_NONE;
6985 }
6986 p_iminsert = curbuf->b_p_iminsert;
6987 if (termcap_active) /* don't do this in the alternate screen */
6988 showmode();
6989#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
6990 /* Show/unshow value of 'keymap' in status lines. */
6991 status_redraw_curbuf();
6992#endif
6993 }
6994
Bram Moolenaar4399ef42005-02-12 14:29:27 +00006995 else if (pp == &p_window)
6996 {
6997 if (p_window < 1)
6998 p_window = 1;
6999 else if (p_window >= Rows)
7000 p_window = Rows - 1;
7001 }
7002
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003 else if (pp == &curbuf->b_p_imsearch)
7004 {
7005 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7006 {
7007 errmsg = e_invarg;
7008 curbuf->b_p_imsearch = B_IMODE_NONE;
7009 }
7010 p_imsearch = curbuf->b_p_imsearch;
7011 }
7012
7013#ifdef FEAT_TITLE
7014 /* if 'titlelen' has changed, redraw the title */
7015 else if (pp == &p_titlelen)
7016 {
7017 if (p_titlelen < 0)
7018 {
7019 errmsg = e_positive;
7020 p_titlelen = 85;
7021 }
7022 if (starting != NO_SCREEN && old_value != p_titlelen)
7023 need_maketitle = TRUE;
7024 }
7025#endif
7026
7027 /* if p_ch changed value, change the command line height */
7028 else if (pp == &p_ch)
7029 {
7030 if (p_ch < 1)
7031 {
7032 errmsg = e_positive;
7033 p_ch = 1;
7034 }
7035
7036 /* Only compute the new window layout when startup has been
7037 * completed. Otherwise the frame sizes may be wrong. */
7038 if (p_ch != old_value && full_screen
7039#ifdef FEAT_GUI
7040 && !gui.starting
7041#endif
7042 )
7043 command_height(old_value);
7044 }
7045
7046 /* when 'updatecount' changes from zero to non-zero, open swap files */
7047 else if (pp == &p_uc)
7048 {
7049 if (p_uc < 0)
7050 {
7051 errmsg = e_positive;
7052 p_uc = 100;
7053 }
7054 if (p_uc && !old_value)
7055 ml_open_files();
7056 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007057#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007058 else if (pp == &p_mzq)
7059 mzvim_reset_timer();
7060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007061
7062 /* sync undo before 'undolevels' changes */
7063 else if (pp == &p_ul)
7064 {
7065 /* use the old value, otherwise u_sync() may not work properly */
7066 p_ul = old_value;
7067 u_sync();
7068 p_ul = value;
7069 }
7070
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007071#ifdef FEAT_LINEBREAK
7072 /* 'numberwidth' must be positive */
7073 else if (pp == &curwin->w_p_nuw)
7074 {
7075 if (curwin->w_p_nuw < 1)
7076 {
7077 errmsg = e_positive;
7078 curwin->w_p_nuw = 1;
7079 }
7080 if (curwin->w_p_nuw > 10)
7081 {
7082 errmsg = e_invarg;
7083 curwin->w_p_nuw = 10;
7084 }
7085 curwin->w_nrwidth_line_count = 0;
7086 }
7087#endif
7088
Bram Moolenaar071d4272004-06-13 20:20:40 +00007089 /*
7090 * Check the bounds for numeric options here
7091 */
7092 if (Rows < min_rows() && full_screen)
7093 {
7094 if (errbuf != NULL)
7095 {
7096 sprintf((char *)errbuf, _("E593: Need at least %d lines"),
7097 min_rows());
7098 errmsg = errbuf;
7099 }
7100 Rows = min_rows();
7101 }
7102 if (Columns < MIN_COLUMNS && full_screen)
7103 {
7104 if (errbuf != NULL)
7105 {
7106 sprintf((char *)errbuf, _("E594: Need at least %d columns"),
7107 MIN_COLUMNS);
7108 errmsg = errbuf;
7109 }
7110 Columns = MIN_COLUMNS;
7111 }
7112
7113#ifdef DJGPP
7114 /* avoid a crash by checking for a too large value of 'columns' */
7115 if (old_Columns != Columns && full_screen && term_console)
7116 mch_check_columns();
7117#endif
7118
7119 /*
7120 * If the screen (shell) height has been changed, assume it is the
7121 * physical screenheight.
7122 */
7123 if (old_Rows != Rows || old_Columns != Columns)
7124 {
7125 /* Changing the screen size is not allowed while updating the screen. */
7126 if (updating_screen)
7127 *pp = old_value;
7128 else if (full_screen
7129#ifdef FEAT_GUI
7130 && !gui.starting
7131#endif
7132 )
7133 set_shellsize((int)Columns, (int)Rows, TRUE);
7134 else
7135 {
7136 /* Postpone the resizing; check the size and cmdline position for
7137 * messages. */
7138 check_shellsize();
7139 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7140 cmdline_row = Rows - p_ch;
7141 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007142 if (p_window >= Rows)
7143 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144 }
7145
7146 if (curbuf->b_p_sts < 0)
7147 {
7148 errmsg = e_positive;
7149 curbuf->b_p_sts = 0;
7150 }
7151 if (curbuf->b_p_ts <= 0)
7152 {
7153 errmsg = e_positive;
7154 curbuf->b_p_ts = 8;
7155 }
7156 if (curbuf->b_p_tw < 0)
7157 {
7158 errmsg = e_positive;
7159 curbuf->b_p_tw = 0;
7160 }
7161 if (p_tm < 0)
7162 {
7163 errmsg = e_positive;
7164 p_tm = 0;
7165 }
7166 if ((curwin->w_p_scr <= 0
7167 || (curwin->w_p_scr > curwin->w_height
7168 && curwin->w_height > 0))
7169 && full_screen)
7170 {
7171 if (pp == &(curwin->w_p_scr))
7172 {
7173 if (curwin->w_p_scr != 0)
7174 errmsg = e_scroll;
7175 win_comp_scroll(curwin);
7176 }
7177 /* If 'scroll' became invalid because of a side effect silently adjust
7178 * it. */
7179 else if (curwin->w_p_scr <= 0)
7180 curwin->w_p_scr = 1;
7181 else /* curwin->w_p_scr > curwin->w_height */
7182 curwin->w_p_scr = curwin->w_height;
7183 }
7184 if (p_report < 0)
7185 {
7186 errmsg = e_positive;
7187 p_report = 1;
7188 }
7189 if ((p_sj < 0 || p_sj >= Rows) && full_screen)
7190 {
7191 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7192 p_sj = Rows / 2;
7193 else
7194 {
7195 errmsg = e_scroll;
7196 p_sj = 1;
7197 }
7198 }
7199 if (p_so < 0 && full_screen)
7200 {
7201 errmsg = e_scroll;
7202 p_so = 0;
7203 }
7204 if (p_siso < 0 && full_screen)
7205 {
7206 errmsg = e_positive;
7207 p_siso = 0;
7208 }
7209#ifdef FEAT_CMDWIN
7210 if (p_cwh < 1)
7211 {
7212 errmsg = e_positive;
7213 p_cwh = 1;
7214 }
7215#endif
7216 if (p_ut < 0)
7217 {
7218 errmsg = e_positive;
7219 p_ut = 2000;
7220 }
7221 if (p_ss < 0)
7222 {
7223 errmsg = e_positive;
7224 p_ss = 0;
7225 }
7226
7227 /* May set global value for local option. */
7228 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7229 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7230
7231 options[opt_idx].flags |= P_WAS_SET;
7232
7233 comp_col(); /* in case 'columns' or 'ls' changed */
7234 if (curwin->w_curswant != MAXCOL)
7235 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7236 check_redraw(options[opt_idx].flags);
7237
7238 return errmsg;
7239}
7240
7241/*
7242 * Called after an option changed: check if something needs to be redrawn.
7243 */
7244 static void
7245check_redraw(flags)
7246 long_u flags;
7247{
7248 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7249 int clear = (flags & P_RCLR) == P_RCLR;
7250 int all = ((flags & P_RALL) == P_RALL || clear);
7251
7252#ifdef FEAT_WINDOWS
7253 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7254 status_redraw_all();
7255#endif
7256
7257 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7258 changed_window_setting();
7259 if (flags & P_RBUF)
7260 redraw_curbuf_later(NOT_VALID);
7261 if (clear)
7262 redraw_all_later(CLEAR);
7263 else if (all)
7264 redraw_all_later(NOT_VALID);
7265}
7266
7267/*
7268 * Find index for option 'arg'.
7269 * Return -1 if not found.
7270 */
7271 static int
7272findoption(arg)
7273 char_u *arg;
7274{
7275 int opt_idx;
7276 char *s, *p;
7277 static short quick_tab[27] = {0, 0}; /* quick access table */
7278 int is_term_opt;
7279
7280 /*
7281 * For first call: Initialize the quick-access table.
7282 * It contains the index for the first option that starts with a certain
7283 * letter. There are 26 letters, plus the first "t_" option.
7284 */
7285 if (quick_tab[1] == 0)
7286 {
7287 p = options[0].fullname;
7288 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7289 {
7290 if (s[0] != p[0])
7291 {
7292 if (s[0] == 't' && s[1] == '_')
7293 quick_tab[26] = opt_idx;
7294 else
7295 quick_tab[CharOrdLow(s[0])] = opt_idx;
7296 }
7297 p = s;
7298 }
7299 }
7300
7301 /*
7302 * Check for name starting with an illegal character.
7303 */
7304#ifdef EBCDIC
7305 if (!islower(arg[0]))
7306#else
7307 if (arg[0] < 'a' || arg[0] > 'z')
7308#endif
7309 return -1;
7310
7311 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7312 if (is_term_opt)
7313 opt_idx = quick_tab[26];
7314 else
7315 opt_idx = quick_tab[CharOrdLow(arg[0])];
7316 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7317 {
7318 if (STRCMP(arg, s) == 0) /* match full name */
7319 break;
7320 }
7321 if (s == NULL && !is_term_opt)
7322 {
7323 opt_idx = quick_tab[CharOrdLow(arg[0])];
7324 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7325 {
7326 s = options[opt_idx].shortname;
7327 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7328 break;
7329 s = NULL;
7330 }
7331 }
7332 if (s == NULL)
7333 opt_idx = -1;
7334 return opt_idx;
7335}
7336
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007337#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007338/*
7339 * Get the value for an option.
7340 *
7341 * Returns:
7342 * Number or Toggle option: 1, *numval gets value.
7343 * String option: 0, *stringval gets allocated string.
7344 * Hidden Number or Toggle option: -1.
7345 * hidden String option: -2.
7346 * unknown option: -3.
7347 */
7348 int
7349get_option_value(name, numval, stringval, opt_flags)
7350 char_u *name;
7351 long *numval;
7352 char_u **stringval; /* NULL when only checking existance */
7353 int opt_flags;
7354{
7355 int opt_idx;
7356 char_u *varp;
7357
7358 opt_idx = findoption(name);
7359 if (opt_idx < 0) /* unknown option */
7360 return -3;
7361
7362 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7363
7364 if (options[opt_idx].flags & P_STRING)
7365 {
7366 if (varp == NULL) /* hidden option */
7367 return -2;
7368 if (stringval != NULL)
7369 {
7370#ifdef FEAT_CRYPT
7371 /* never return the value of the crypt key */
7372 if ((char_u **)varp == &curbuf->b_p_key)
7373 *stringval = vim_strsave((char_u *)"*****");
7374 else
7375#endif
7376 *stringval = vim_strsave(*(char_u **)(varp));
7377 }
7378 return 0;
7379 }
7380
7381 if (varp == NULL) /* hidden option */
7382 return -1;
7383 if (options[opt_idx].flags & P_NUM)
7384 *numval = *(long *)varp;
7385 else
7386 {
7387 /* Special case: 'modified' is b_changed, but we also want to consider
7388 * it set when 'ff' or 'fenc' changed. */
7389 if ((int *)varp == &curbuf->b_changed)
7390 *numval = curbufIsChanged();
7391 else
7392 *numval = *(int *)varp;
7393 }
7394 return 1;
7395}
7396#endif
7397
7398/*
7399 * Set the value of option "name".
7400 * Use "string" for string options, use "number" for other options.
7401 */
7402 void
7403set_option_value(name, number, string, opt_flags)
7404 char_u *name;
7405 long number;
7406 char_u *string;
7407 int opt_flags; /* OPT_LOCAL or 0 (both) */
7408{
7409 int opt_idx;
7410 char_u *varp;
7411 int flags;
7412
7413 opt_idx = findoption(name);
7414 if (opt_idx == -1)
7415 EMSG2(_("E355: Unknown option: %s"), name);
7416 else
7417 {
7418 flags = options[opt_idx].flags;
7419#ifdef HAVE_SANDBOX
7420 /* Disallow changing some options in the sandbox */
7421 if (sandbox > 0 && (flags & P_SECURE))
7422 EMSG(_(e_sandbox));
7423 else
7424#endif
7425 if (flags & P_STRING)
7426 set_string_option(opt_idx, string, opt_flags);
7427 else
7428 {
7429 varp = get_varp(&options[opt_idx]);
7430 if (varp != NULL) /* hidden option is not changed */
7431 {
7432 if (flags & P_NUM)
7433 (void)set_num_option(opt_idx, varp, number, NULL, opt_flags);
7434 else
7435 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7436 }
7437 }
7438 }
7439}
7440
7441/*
7442 * Get the terminal code for a terminal option.
7443 * Returns NULL when not found.
7444 */
7445 char_u *
7446get_term_code(tname)
7447 char_u *tname;
7448{
7449 int opt_idx;
7450 char_u *varp;
7451
7452 if (tname[0] != 't' || tname[1] != '_' ||
7453 tname[2] == NUL || tname[3] == NUL)
7454 return NULL;
7455 if ((opt_idx = findoption(tname)) >= 0)
7456 {
7457 varp = get_varp(&(options[opt_idx]));
7458 if (varp != NULL)
7459 varp = *(char_u **)(varp);
7460 return varp;
7461 }
7462 return find_termcode(tname + 2);
7463}
7464
7465 char_u *
7466get_highlight_default()
7467{
7468 int i;
7469
7470 i = findoption((char_u *)"hl");
7471 if (i >= 0)
7472 return options[i].def_val[VI_DEFAULT];
7473 return (char_u *)NULL;
7474}
7475
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007476#if defined(FEAT_MBYTE) || defined(PROTO)
7477 char_u *
7478get_encoding_default()
7479{
7480 int i;
7481
7482 i = findoption((char_u *)"enc");
7483 if (i >= 0)
7484 return options[i].def_val[VI_DEFAULT];
7485 return (char_u *)NULL;
7486}
7487#endif
7488
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489/*
7490 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7491 */
7492 static int
7493find_key_option(arg)
7494 char_u *arg;
7495{
7496 int key;
7497 int modifiers;
7498
7499 /*
7500 * Don't use get_special_key_code() for t_xx, we don't want it to call
7501 * add_termcap_entry().
7502 */
7503 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7504 key = TERMCAP2KEY(arg[2], arg[3]);
7505 else
7506 {
7507 --arg; /* put arg at the '<' */
7508 modifiers = 0;
7509 key = find_special_key(&arg, &modifiers, TRUE);
7510 if (modifiers) /* can't handle modifiers here */
7511 key = 0;
7512 }
7513 return key;
7514}
7515
7516/*
7517 * if 'all' == 0: show changed options
7518 * if 'all' == 1: show all normal options
7519 * if 'all' == 2: show all terminal options
7520 */
7521 static void
7522showoptions(all, opt_flags)
7523 int all;
7524 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7525{
7526 struct vimoption *p;
7527 int col;
7528 int isterm;
7529 char_u *varp;
7530 struct vimoption **items;
7531 int item_count;
7532 int run;
7533 int row, rows;
7534 int cols;
7535 int i;
7536 int len;
7537
7538#define INC 20
7539#define GAP 3
7540
7541 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7542 PARAM_COUNT));
7543 if (items == NULL)
7544 return;
7545
7546 /* Highlight title */
7547 if (all == 2)
7548 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7549 else if (opt_flags & OPT_GLOBAL)
7550 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7551 else if (opt_flags & OPT_LOCAL)
7552 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7553 else
7554 MSG_PUTS_TITLE(_("\n--- Options ---"));
7555
7556 /*
7557 * do the loop two times:
7558 * 1. display the short items
7559 * 2. display the long items (only strings and numbers)
7560 */
7561 for (run = 1; run <= 2 && !got_int; ++run)
7562 {
7563 /*
7564 * collect the items in items[]
7565 */
7566 item_count = 0;
7567 for (p = &options[0]; p->fullname != NULL; p++)
7568 {
7569 varp = NULL;
7570 isterm = istermoption(p);
7571 if (opt_flags != 0)
7572 {
7573 if (p->indir != PV_NONE && !isterm)
7574 varp = get_varp_scope(p, opt_flags);
7575 }
7576 else
7577 varp = get_varp(p);
7578 if (varp != NULL
7579 && ((all == 2 && isterm)
7580 || (all == 1 && !isterm)
7581 || (all == 0 && !optval_default(p, varp))))
7582 {
7583 if (p->flags & P_BOOL)
7584 len = 1; /* a toggle option fits always */
7585 else
7586 {
7587 option_value2string(p, opt_flags);
7588 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7589 }
7590 if ((len <= INC - GAP && run == 1) ||
7591 (len > INC - GAP && run == 2))
7592 items[item_count++] = p;
7593 }
7594 }
7595
7596 /*
7597 * display the items
7598 */
7599 if (run == 1)
7600 {
7601 cols = (Columns + GAP - 3) / INC;
7602 if (cols == 0)
7603 cols = 1;
7604 rows = (item_count + cols - 1) / cols;
7605 }
7606 else /* run == 2 */
7607 rows = item_count;
7608 for (row = 0; row < rows && !got_int; ++row)
7609 {
7610 msg_putchar('\n'); /* go to next line */
7611 if (got_int) /* 'q' typed in more */
7612 break;
7613 col = 0;
7614 for (i = row; i < item_count; i += rows)
7615 {
7616 msg_col = col; /* make columns */
7617 showoneopt(items[i], opt_flags);
7618 col += INC;
7619 }
7620 out_flush();
7621 ui_breakcheck();
7622 }
7623 }
7624 vim_free(items);
7625}
7626
7627/*
7628 * Return TRUE if option "p" has its default value.
7629 */
7630 static int
7631optval_default(p, varp)
7632 struct vimoption *p;
7633 char_u *varp;
7634{
7635 int dvi;
7636
7637 if (varp == NULL)
7638 return TRUE; /* hidden option is always at default */
7639 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7640 if (p->flags & P_NUM)
7641 return (*(long *)varp == (long)p->def_val[dvi]);
7642 if (p->flags & P_BOOL)
7643 /* the cast to long is required for Manx C */
7644 return (*(int *)varp == (int)(long)p->def_val[dvi]);
7645 /* P_STRING */
7646 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7647}
7648
7649/*
7650 * showoneopt: show the value of one option
7651 * must not be called with a hidden option!
7652 */
7653 static void
7654showoneopt(p, opt_flags)
7655 struct vimoption *p;
7656 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
7657{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007658 char_u *varp;
7659 int save_silent = silent_mode;
7660
7661 silent_mode = FALSE;
7662 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007663
7664 varp = get_varp_scope(p, opt_flags);
7665
7666 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7667 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7668 ? !curbufIsChanged() : !*(int *)varp))
7669 MSG_PUTS("no");
7670 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7671 MSG_PUTS("--");
7672 else
7673 MSG_PUTS(" ");
7674 MSG_PUTS(p->fullname);
7675 if (!(p->flags & P_BOOL))
7676 {
7677 msg_putchar('=');
7678 /* put value string in NameBuff */
7679 option_value2string(p, opt_flags);
7680 msg_outtrans(NameBuff);
7681 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007682
7683 silent_mode = save_silent;
7684 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685}
7686
7687/*
7688 * Write modified options as ":set" commands to a file.
7689 *
7690 * There are three values for "opt_flags":
7691 * OPT_GLOBAL: Write global option values and fresh values of
7692 * buffer-local options (used for start of a session
7693 * file).
7694 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7695 * curwin (used for a vimrc file).
7696 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
7697 * and local values for window-local options of
7698 * curwin. Local values are also written when at the
7699 * default value, because a modeline or autocommand
7700 * may have set them when doing ":edit file" and the
7701 * user has set them back at the default or fresh
7702 * value.
7703 * When "local_only" is TRUE, don't write fresh
7704 * values, only local values (for ":mkview").
7705 * (fresh value = value used for a new buffer or window for a local option).
7706 *
7707 * Return FAIL on error, OK otherwise.
7708 */
7709 int
7710makeset(fd, opt_flags, local_only)
7711 FILE *fd;
7712 int opt_flags;
7713 int local_only;
7714{
7715 struct vimoption *p;
7716 char_u *varp; /* currently used value */
7717 char_u *varp_fresh; /* local value */
7718 char_u *varp_local = NULL; /* fresh value */
7719 char *cmd;
7720 int round;
7721
7722 /*
7723 * The options that don't have a default (terminal name, columns, lines)
7724 * are never written. Terminal options are also not written.
7725 */
7726 for (p = &options[0]; !istermoption(p); p++)
7727 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7728 {
7729 /* skip global option when only doing locals */
7730 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7731 continue;
7732
7733 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
7734 * file, they are always buffer-specific. */
7735 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
7736 continue;
7737
7738 /* Global values are only written when not at the default value. */
7739 varp = get_varp_scope(p, opt_flags);
7740 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
7741 continue;
7742
7743 round = 2;
7744 if (p->indir != PV_NONE)
7745 {
7746 if (p->var == VAR_WIN)
7747 {
7748 /* skip window-local option when only doing globals */
7749 if (!(opt_flags & OPT_LOCAL))
7750 continue;
7751 /* When fresh value of window-local option is not at the
7752 * default, need to write it too. */
7753 if (!(opt_flags & OPT_GLOBAL) && !local_only)
7754 {
7755 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
7756 if (!optval_default(p, varp_fresh))
7757 {
7758 round = 1;
7759 varp_local = varp;
7760 varp = varp_fresh;
7761 }
7762 }
7763 }
7764 }
7765
7766 /* Round 1: fresh value for window-local options.
7767 * Round 2: other values */
7768 for ( ; round <= 2; varp = varp_local, ++round)
7769 {
7770 if (round == 1 || (opt_flags & OPT_GLOBAL))
7771 cmd = "set";
7772 else
7773 cmd = "setlocal";
7774
7775 if (p->flags & P_BOOL)
7776 {
7777 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
7778 return FAIL;
7779 }
7780 else if (p->flags & P_NUM)
7781 {
7782 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
7783 return FAIL;
7784 }
7785 else /* P_STRING */
7786 {
7787 /* Don't set 'syntax' and 'filetype' again if the value is
7788 * already right, avoids reloading the syntax file. */
7789 if (p->indir == PV_SYN || p->indir == PV_FT)
7790 {
7791 if (fprintf(fd, "if &%s != '%s'", p->fullname,
7792 *(char_u **)(varp)) < 0
7793 || put_eol(fd) < 0)
7794 return FAIL;
7795 }
7796 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
7797 (p->flags & P_EXPAND) != 0) == FAIL)
7798 return FAIL;
7799 if (p->indir == PV_SYN || p->indir == PV_FT)
7800 {
7801 if (put_line(fd, "endif") == FAIL)
7802 return FAIL;
7803 }
7804 }
7805 }
7806 }
7807 return OK;
7808}
7809
7810#if defined(FEAT_FOLDING) || defined(PROTO)
7811/*
7812 * Generate set commands for the local fold options only. Used when
7813 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
7814 */
7815 int
7816makefoldset(fd)
7817 FILE *fd;
7818{
7819 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
7820# ifdef FEAT_EVAL
7821 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
7822 == FAIL
7823# endif
7824 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
7825 == FAIL
7826 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
7827 == FAIL
7828 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
7829 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
7830 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
7831 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
7832 )
7833 return FAIL;
7834
7835 return OK;
7836}
7837#endif
7838
7839 static int
7840put_setstring(fd, cmd, name, valuep, expand)
7841 FILE *fd;
7842 char *cmd;
7843 char *name;
7844 char_u **valuep;
7845 int expand;
7846{
7847 char_u *s;
7848 char_u buf[MAXPATHL];
7849
7850 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7851 return FAIL;
7852 if (*valuep != NULL)
7853 {
7854 /* Output 'pastetoggle' as key names. For other
7855 * options some characters have to be escaped with
7856 * CTRL-V or backslash */
7857 if (valuep == &p_pt)
7858 {
7859 s = *valuep;
7860 while (*s != NUL)
7861 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
7862 return FAIL;
7863 }
7864 else if (expand)
7865 {
7866 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
7867 if (put_escstr(fd, buf, 2) == FAIL)
7868 return FAIL;
7869 }
7870 else if (put_escstr(fd, *valuep, 2) == FAIL)
7871 return FAIL;
7872 }
7873 if (put_eol(fd) < 0)
7874 return FAIL;
7875 return OK;
7876}
7877
7878 static int
7879put_setnum(fd, cmd, name, valuep)
7880 FILE *fd;
7881 char *cmd;
7882 char *name;
7883 long *valuep;
7884{
7885 long wc;
7886
7887 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7888 return FAIL;
7889 if (wc_use_keyname((char_u *)valuep, &wc))
7890 {
7891 /* print 'wildchar' and 'wildcharm' as a key name */
7892 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
7893 return FAIL;
7894 }
7895 else if (fprintf(fd, "%ld", *valuep) < 0)
7896 return FAIL;
7897 if (put_eol(fd) < 0)
7898 return FAIL;
7899 return OK;
7900}
7901
7902 static int
7903put_setbool(fd, cmd, name, value)
7904 FILE *fd;
7905 char *cmd;
7906 char *name;
7907 int value;
7908{
7909 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
7910 || put_eol(fd) < 0)
7911 return FAIL;
7912 return OK;
7913}
7914
7915/*
7916 * Clear all the terminal options.
7917 * If the option has been allocated, free the memory.
7918 * Terminal options are never hidden or indirect.
7919 */
7920 void
7921clear_termoptions()
7922{
7923 struct vimoption *p;
7924
7925 /*
7926 * Reset a few things before clearing the old options. This may cause
7927 * outputting a few things that the terminal doesn't understand, but the
7928 * screen will be cleared later, so this is OK.
7929 */
7930#ifdef FEAT_MOUSE_TTY
7931 mch_setmouse(FALSE); /* switch mouse off */
7932#endif
7933#ifdef FEAT_TITLE
7934 mch_restore_title(3); /* restore window titles */
7935#endif
7936#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
7937 /* When starting the GUI close the display opened for the clipboard.
7938 * After restoring the title, because that will need the display. */
7939 if (gui.starting)
7940 clear_xterm_clip();
7941#endif
7942#ifdef WIN3264
7943 /*
7944 * Check if this is allowed now.
7945 */
7946 if (can_end_termcap_mode(FALSE) == TRUE)
7947#endif
7948 stoptermcap(); /* stop termcap mode */
7949
7950 for (p = &options[0]; p->fullname != NULL; p++)
7951 if (istermoption(p))
7952 {
7953 if (p->flags & P_ALLOCED)
7954 free_string_option(*(char_u **)(p->var));
7955 if (p->flags & P_DEF_ALLOCED)
7956 free_string_option(p->def_val[VI_DEFAULT]);
7957 *(char_u **)(p->var) = empty_option;
7958 p->def_val[VI_DEFAULT] = empty_option;
7959 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
7960 }
7961 clear_termcodes();
7962}
7963
7964/*
7965 * Set the terminal option defaults to the current value.
7966 * Used after setting the terminal name.
7967 */
7968 void
7969set_term_defaults()
7970{
7971 struct vimoption *p;
7972
7973 for (p = &options[0]; p->fullname != NULL; p++)
7974 {
7975 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
7976 {
7977 if (p->flags & P_DEF_ALLOCED)
7978 {
7979 free_string_option(p->def_val[VI_DEFAULT]);
7980 p->flags &= ~P_DEF_ALLOCED;
7981 }
7982 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
7983 if (p->flags & P_ALLOCED)
7984 {
7985 p->flags |= P_DEF_ALLOCED;
7986 p->flags &= ~P_ALLOCED; /* don't free the value now */
7987 }
7988 }
7989 }
7990}
7991
7992/*
7993 * return TRUE if 'p' starts with 't_'
7994 */
7995 static int
7996istermoption(p)
7997 struct vimoption *p;
7998{
7999 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8000}
8001
8002/*
8003 * Compute columns for ruler and shown command. 'sc_col' is also used to
8004 * decide what the maximum length of a message on the status line can be.
8005 * If there is a status line for the last window, 'sc_col' is independent
8006 * of 'ru_col'.
8007 */
8008
8009#define COL_RULER 17 /* columns needed by standard ruler */
8010
8011 void
8012comp_col()
8013{
8014#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8015 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8016
8017 sc_col = 0;
8018 ru_col = 0;
8019 if (p_ru)
8020 {
8021#ifdef FEAT_STL_OPT
8022 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8023#else
8024 ru_col = COL_RULER + 1;
8025#endif
8026 /* no last status line, adjust sc_col */
8027 if (!last_has_status)
8028 sc_col = ru_col;
8029 }
8030 if (p_sc)
8031 {
8032 sc_col += SHOWCMD_COLS;
8033 if (!p_ru || last_has_status) /* no need for separating space */
8034 ++sc_col;
8035 }
8036 sc_col = Columns - sc_col;
8037 ru_col = Columns - ru_col;
8038 if (sc_col <= 0) /* screen too narrow, will become a mess */
8039 sc_col = 1;
8040 if (ru_col <= 0)
8041 ru_col = 1;
8042#else
8043 sc_col = Columns;
8044 ru_col = Columns;
8045#endif
8046}
8047
8048/*
8049 * Get pointer to option variable, depending on local or global scope.
8050 */
8051 static char_u *
8052get_varp_scope(p, opt_flags)
8053 struct vimoption *p;
8054 int opt_flags;
8055{
8056 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8057 {
8058 if (p->var == VAR_WIN)
8059 return (char_u *)GLOBAL_WO(get_varp(p));
8060 return p->var;
8061 }
8062 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
8063 {
8064 switch ((int)p->indir)
8065 {
8066#ifdef FEAT_QUICKFIX
8067 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
8068 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
8069 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
8070#endif
8071 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
8072 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
8073 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
8074 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
8075 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
8076#ifdef FEAT_FIND_ID
8077 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
8078 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
8079#endif
8080#ifdef FEAT_INS_EXPAND
8081 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
8082 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
8083#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008084#ifdef FEAT_STL_OPT
8085 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
8086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087 }
8088 return NULL; /* "cannot happen" */
8089 }
8090 return get_varp(p);
8091}
8092
8093/*
8094 * Get pointer to option variable.
8095 */
8096 static char_u *
8097get_varp(p)
8098 struct vimoption *p;
8099{
8100 /* hidden option, always return NULL */
8101 if (p->var == NULL)
8102 return NULL;
8103
8104 switch ((int)p->indir)
8105 {
8106 case PV_NONE: return p->var;
8107
8108 /* global option with local value: use local value if it's been set */
8109 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
8110 ? (char_u *)&curbuf->b_p_ep : p->var;
8111 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
8112 ? (char_u *)&curbuf->b_p_kp : p->var;
8113 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
8114 ? (char_u *)&(curbuf->b_p_path) : p->var;
8115 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
8116 ? (char_u *)&(curbuf->b_p_ar) : p->var;
8117 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
8118 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8119#ifdef FEAT_FIND_ID
8120 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
8121 ? (char_u *)&(curbuf->b_p_def) : p->var;
8122 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
8123 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8124#endif
8125#ifdef FEAT_INS_EXPAND
8126 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
8127 ? (char_u *)&(curbuf->b_p_dict) : p->var;
8128 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
8129 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8130#endif
8131#ifdef FEAT_QUICKFIX
8132 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
8133 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8134 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
8135 ? (char_u *)&(curbuf->b_p_mp) : p->var;
8136 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8137 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8138#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008139#ifdef FEAT_STL_OPT
8140 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8141 ? (char_u *)&(curwin->w_p_stl) : p->var;
8142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143
8144#ifdef FEAT_ARABIC
8145 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8146#endif
8147 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008148#ifdef FEAT_SYN_HL
8149 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8150#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151#ifdef FEAT_DIFF
8152 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8153#endif
8154#ifdef FEAT_FOLDING
8155 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8156 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8157 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8158 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8159 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8160 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8161 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8162# ifdef FEAT_EVAL
8163 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8164 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8165# endif
8166 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8167#endif
8168 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008169#ifdef FEAT_LINEBREAK
8170 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8171#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172#if defined(FEAT_WINDOWS)
8173 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8174#endif
8175#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8176 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8177#endif
8178#ifdef FEAT_RIGHTLEFT
8179 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8180 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8181#endif
8182 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8183 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8184#ifdef FEAT_LINEBREAK
8185 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8186#endif
8187#ifdef FEAT_SCROLLBIND
8188 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8189#endif
8190
8191 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8192 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8193#ifdef FEAT_MBYTE
8194 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8195#endif
8196#if defined(FEAT_QUICKFIX)
8197 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8198 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8199#endif
8200 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8201 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8202#ifdef FEAT_CINDENT
8203 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8204 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8205 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8206#endif
8207#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8208 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8209#endif
8210#ifdef FEAT_COMMENTS
8211 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8212#endif
8213#ifdef FEAT_FOLDING
8214 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8215#endif
8216#ifdef FEAT_INS_EXPAND
8217 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8218#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008219#ifdef FEAT_COMPL_FUNC
8220 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
8221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8223 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8224#ifdef FEAT_MBYTE
8225 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8226#endif
8227 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8228#ifdef FEAT_AUTOCMD
8229 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8230#endif
8231 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008232 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8234 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8235 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8236 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8237#ifdef FEAT_FIND_ID
8238# ifdef FEAT_EVAL
8239 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8240# endif
8241#endif
8242#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8243 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8244 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8245#endif
8246#ifdef FEAT_CRYPT
8247 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8248#endif
8249#ifdef FEAT_LISP
8250 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8251#endif
8252 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8253 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8254 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8255 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8256 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8257#ifdef FEAT_OSFILETYPE
8258 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8259#endif
8260 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008261#ifdef FEAT_TEXTOBJ
8262 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8263#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008264 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8265#ifdef FEAT_SMARTINDENT
8266 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8267#endif
8268#ifndef SHORT_FNAME
8269 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8270#endif
8271 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8272#ifdef FEAT_SEARCHPATH
8273 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8274#endif
8275 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8276#ifdef FEAT_SYN_HL
8277 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008278 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008279#endif
8280 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8281 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8282 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8283 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8284 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8285#ifdef FEAT_KEYMAP
8286 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8287#endif
8288 default: EMSG(_("E356: get_varp ERROR"));
8289 }
8290 /* always return a valid pointer to avoid a crash! */
8291 return (char_u *)&(curbuf->b_p_wm);
8292}
8293
8294/*
8295 * Get the value of 'equalprg', either the buffer-local one or the global one.
8296 */
8297 char_u *
8298get_equalprg()
8299{
8300 if (*curbuf->b_p_ep == NUL)
8301 return p_ep;
8302 return curbuf->b_p_ep;
8303}
8304
8305#if defined(FEAT_WINDOWS) || defined(PROTO)
8306/*
8307 * Copy options from one window to another.
8308 * Used when splitting a window.
8309 */
8310 void
8311win_copy_options(wp_from, wp_to)
8312 win_T *wp_from;
8313 win_T *wp_to;
8314{
8315 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8316 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8317# ifdef FEAT_RIGHTLEFT
8318# ifdef FEAT_FKMAP
8319 /* Is this right? */
8320 wp_to->w_farsi = wp_from->w_farsi;
8321# endif
8322# endif
8323}
8324#endif
8325
8326/*
8327 * Copy the options from one winopt_T to another.
8328 * Doesn't free the old option values in "to", use clear_winopt() for that.
8329 * The 'scroll' option is not copied, because it depends on the window height.
8330 * The 'previewwindow' option is reset, there can be only one preview window.
8331 */
8332 void
8333copy_winopt(from, to)
8334 winopt_T *from;
8335 winopt_T *to;
8336{
8337#ifdef FEAT_ARABIC
8338 to->wo_arab = from->wo_arab;
8339#endif
8340 to->wo_list = from->wo_list;
8341 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008342#ifdef FEAT_LINEBREAK
8343 to->wo_nuw = from->wo_nuw;
8344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345#ifdef FEAT_RIGHTLEFT
8346 to->wo_rl = from->wo_rl;
8347 to->wo_rlc = vim_strsave(from->wo_rlc);
8348#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008349#ifdef FEAT_STL_OPT
8350 to->wo_stl = vim_strsave(from->wo_stl);
8351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 to->wo_wrap = from->wo_wrap;
8353#ifdef FEAT_LINEBREAK
8354 to->wo_lbr = from->wo_lbr;
8355#endif
8356#ifdef FEAT_SCROLLBIND
8357 to->wo_scb = from->wo_scb;
8358#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008359#ifdef FEAT_SYN_HL
8360 to->wo_spell = from->wo_spell;
8361#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362#ifdef FEAT_DIFF
8363 to->wo_diff = from->wo_diff;
8364#endif
8365#ifdef FEAT_FOLDING
8366 to->wo_fdc = from->wo_fdc;
8367 to->wo_fen = from->wo_fen;
8368 to->wo_fdi = vim_strsave(from->wo_fdi);
8369 to->wo_fml = from->wo_fml;
8370 to->wo_fdl = from->wo_fdl;
8371 to->wo_fdm = vim_strsave(from->wo_fdm);
8372 to->wo_fdn = from->wo_fdn;
8373# ifdef FEAT_EVAL
8374 to->wo_fde = vim_strsave(from->wo_fde);
8375 to->wo_fdt = vim_strsave(from->wo_fdt);
8376# endif
8377 to->wo_fmr = vim_strsave(from->wo_fmr);
8378#endif
8379 check_winopt(to); /* don't want NULL pointers */
8380}
8381
8382/*
8383 * Check string options in a window for a NULL value.
8384 */
8385 void
8386check_win_options(win)
8387 win_T *win;
8388{
8389 check_winopt(&win->w_onebuf_opt);
8390 check_winopt(&win->w_allbuf_opt);
8391}
8392
8393/*
8394 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8395 */
8396/*ARGSUSED*/
8397 void
8398check_winopt(wop)
8399 winopt_T *wop;
8400{
8401#ifdef FEAT_FOLDING
8402 check_string_option(&wop->wo_fdi);
8403 check_string_option(&wop->wo_fdm);
8404# ifdef FEAT_EVAL
8405 check_string_option(&wop->wo_fde);
8406 check_string_option(&wop->wo_fdt);
8407# endif
8408 check_string_option(&wop->wo_fmr);
8409#endif
8410#ifdef FEAT_RIGHTLEFT
8411 check_string_option(&wop->wo_rlc);
8412#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008413#ifdef FEAT_STL_OPT
8414 check_string_option(&wop->wo_stl);
8415#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416}
8417
8418/*
8419 * Free the allocated memory inside a winopt_T.
8420 */
8421/*ARGSUSED*/
8422 void
8423clear_winopt(wop)
8424 winopt_T *wop;
8425{
8426#ifdef FEAT_FOLDING
8427 clear_string_option(&wop->wo_fdi);
8428 clear_string_option(&wop->wo_fdm);
8429# ifdef FEAT_EVAL
8430 clear_string_option(&wop->wo_fde);
8431 clear_string_option(&wop->wo_fdt);
8432# endif
8433 clear_string_option(&wop->wo_fmr);
8434#endif
8435#ifdef FEAT_RIGHTLEFT
8436 clear_string_option(&wop->wo_rlc);
8437#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008438#ifdef FEAT_STL_OPT
8439 clear_string_option(&wop->wo_stl);
8440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441}
8442
8443/*
8444 * Copy global option values to local options for one buffer.
8445 * Used when creating a new buffer and sometimes when entering a buffer.
8446 * flags:
8447 * BCO_ENTER We will enter the buf buffer.
8448 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8449 * appropriate.
8450 * BCO_NOHELP Don't copy the values to a help buffer.
8451 */
8452 void
8453buf_copy_options(buf, flags)
8454 buf_T *buf;
8455 int flags;
8456{
8457 int should_copy = TRUE;
8458 char_u *save_p_isk = NULL; /* init for GCC */
8459 int dont_do_help;
8460 int did_isk = FALSE;
8461
8462 /*
8463 * Don't do anything of the buffer is invalid.
8464 */
8465 if (buf == NULL || !buf_valid(buf))
8466 return;
8467
8468 /*
8469 * Skip this when the option defaults have not been set yet. Happens when
8470 * main() allocates the first buffer.
8471 */
8472 if (p_cpo != NULL)
8473 {
8474 /*
8475 * Always copy when entering and 'cpo' contains 'S'.
8476 * Don't copy when already initialized.
8477 * Don't copy when 'cpo' contains 's' and not entering.
8478 * 'S' BCO_ENTER initialized 's' should_copy
8479 * yes yes X X TRUE
8480 * yes no yes X FALSE
8481 * no X yes X FALSE
8482 * X no no yes FALSE
8483 * X no no no TRUE
8484 * no yes no X TRUE
8485 */
8486 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8487 && (buf->b_p_initialized
8488 || (!(flags & BCO_ENTER)
8489 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8490 should_copy = FALSE;
8491
8492 if (should_copy || (flags & BCO_ALWAYS))
8493 {
8494 /* Don't copy the options specific to a help buffer when
8495 * BCO_NOHELP is given or the options were initialized already
8496 * (jumping back to a help file with CTRL-T or CTRL-O) */
8497 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8498 || buf->b_p_initialized;
8499 if (dont_do_help) /* don't free b_p_isk */
8500 {
8501 save_p_isk = buf->b_p_isk;
8502 buf->b_p_isk = NULL;
8503 }
8504 /*
8505 * Always free the allocated strings.
8506 * If not already initialized, set 'readonly' and copy 'fileformat'.
8507 */
8508 if (!buf->b_p_initialized)
8509 {
8510 free_buf_options(buf, TRUE);
8511 buf->b_p_ro = FALSE; /* don't copy readonly */
8512 buf->b_p_tx = p_tx;
8513#ifdef FEAT_MBYTE
8514 buf->b_p_fenc = vim_strsave(p_fenc);
8515#endif
8516 buf->b_p_ff = vim_strsave(p_ff);
8517#if defined(FEAT_QUICKFIX)
8518 buf->b_p_bh = empty_option;
8519 buf->b_p_bt = empty_option;
8520#endif
8521 }
8522 else
8523 free_buf_options(buf, FALSE);
8524
8525 buf->b_p_ai = p_ai;
8526 buf->b_p_ai_nopaste = p_ai_nopaste;
8527 buf->b_p_sw = p_sw;
8528 buf->b_p_tw = p_tw;
8529 buf->b_p_tw_nopaste = p_tw_nopaste;
8530 buf->b_p_tw_nobin = p_tw_nobin;
8531 buf->b_p_wm = p_wm;
8532 buf->b_p_wm_nopaste = p_wm_nopaste;
8533 buf->b_p_wm_nobin = p_wm_nobin;
8534 buf->b_p_bin = p_bin;
8535 buf->b_p_et = p_et;
8536 buf->b_p_et_nobin = p_et_nobin;
8537 buf->b_p_ml = p_ml;
8538 buf->b_p_ml_nobin = p_ml_nobin;
8539 buf->b_p_inf = p_inf;
8540 buf->b_p_swf = p_swf;
8541#ifdef FEAT_INS_EXPAND
8542 buf->b_p_cpt = vim_strsave(p_cpt);
8543#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008544#ifdef FEAT_COMPL_FUNC
8545 buf->b_p_cfu = vim_strsave(p_cfu);
8546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008547 buf->b_p_sts = p_sts;
8548 buf->b_p_sts_nopaste = p_sts_nopaste;
8549#ifndef SHORT_FNAME
8550 buf->b_p_sn = p_sn;
8551#endif
8552#ifdef FEAT_COMMENTS
8553 buf->b_p_com = vim_strsave(p_com);
8554#endif
8555#ifdef FEAT_FOLDING
8556 buf->b_p_cms = vim_strsave(p_cms);
8557#endif
8558 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008559 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560 buf->b_p_nf = vim_strsave(p_nf);
8561 buf->b_p_mps = vim_strsave(p_mps);
8562#ifdef FEAT_SMARTINDENT
8563 buf->b_p_si = p_si;
8564#endif
8565 buf->b_p_ci = p_ci;
8566#ifdef FEAT_CINDENT
8567 buf->b_p_cin = p_cin;
8568 buf->b_p_cink = vim_strsave(p_cink);
8569 buf->b_p_cino = vim_strsave(p_cino);
8570#endif
8571#ifdef FEAT_AUTOCMD
8572 /* Don't copy 'filetype', it must be detected */
8573 buf->b_p_ft = empty_option;
8574#endif
8575#ifdef FEAT_OSFILETYPE
8576 buf->b_p_oft = vim_strsave(p_oft);
8577#endif
8578 buf->b_p_pi = p_pi;
8579#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8580 buf->b_p_cinw = vim_strsave(p_cinw);
8581#endif
8582#ifdef FEAT_LISP
8583 buf->b_p_lisp = p_lisp;
8584#endif
8585#ifdef FEAT_SYN_HL
8586 /* Don't copy 'syntax', it must be set */
8587 buf->b_p_syn = empty_option;
Bram Moolenaar217ad922005-03-20 22:37:15 +00008588 buf->b_p_spl = vim_strsave(p_spl);
8589 did_set_spelllang(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590#endif
8591#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8592 buf->b_p_inde = vim_strsave(p_inde);
8593 buf->b_p_indk = vim_strsave(p_indk);
8594#endif
8595#ifdef FEAT_CRYPT
8596 buf->b_p_key = vim_strsave(p_key);
8597#endif
8598#ifdef FEAT_SEARCHPATH
8599 buf->b_p_sua = vim_strsave(p_sua);
8600#endif
8601#ifdef FEAT_KEYMAP
8602 buf->b_p_keymap = vim_strsave(p_keymap);
8603 buf->b_kmap_state |= KEYMAP_INIT;
8604#endif
8605 /* This isn't really an option, but copying the langmap and IME
8606 * state from the current buffer is better than resetting it. */
8607 buf->b_p_iminsert = p_iminsert;
8608 buf->b_p_imsearch = p_imsearch;
8609
8610 /* options that are normally global but also have a local value
8611 * are not copied, start using the global value */
8612 buf->b_p_ar = -1;
8613#ifdef FEAT_QUICKFIX
8614 buf->b_p_gp = empty_option;
8615 buf->b_p_mp = empty_option;
8616 buf->b_p_efm = empty_option;
8617#endif
8618 buf->b_p_ep = empty_option;
8619 buf->b_p_kp = empty_option;
8620 buf->b_p_path = empty_option;
8621 buf->b_p_tags = empty_option;
8622#ifdef FEAT_FIND_ID
8623 buf->b_p_def = empty_option;
8624 buf->b_p_inc = empty_option;
8625# ifdef FEAT_EVAL
8626 buf->b_p_inex = vim_strsave(p_inex);
8627# endif
8628#endif
8629#ifdef FEAT_INS_EXPAND
8630 buf->b_p_dict = empty_option;
8631 buf->b_p_tsr = empty_option;
8632#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008633#ifdef FEAT_TEXTOBJ
8634 buf->b_p_qe = vim_strsave(p_qe);
8635#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636
8637 /*
8638 * Don't copy the options set by ex_help(), use the saved values,
8639 * when going from a help buffer to a non-help buffer.
8640 * Don't touch these at all when BCO_NOHELP is used and going from
8641 * or to a help buffer.
8642 */
8643 if (dont_do_help)
8644 buf->b_p_isk = save_p_isk;
8645 else
8646 {
8647 buf->b_p_isk = vim_strsave(p_isk);
8648 did_isk = TRUE;
8649 buf->b_p_ts = p_ts;
8650 buf->b_help = FALSE;
8651#ifdef FEAT_QUICKFIX
8652 if (buf->b_p_bt[0] == 'h')
8653 clear_string_option(&buf->b_p_bt);
8654#endif
8655 buf->b_p_ma = p_ma;
8656 }
8657 }
8658
8659 /*
8660 * When the options should be copied (ignoring BCO_ALWAYS), set the
8661 * flag that indicates that the options have been initialized.
8662 */
8663 if (should_copy)
8664 buf->b_p_initialized = TRUE;
8665 }
8666
8667 check_buf_options(buf); /* make sure we don't have NULLs */
8668 if (did_isk)
8669 (void)buf_init_chartab(buf, FALSE);
8670}
8671
8672/*
8673 * Reset the 'modifiable' option and its default value.
8674 */
8675 void
8676reset_modifiable()
8677{
8678 int opt_idx;
8679
8680 curbuf->b_p_ma = FALSE;
8681 p_ma = FALSE;
8682 opt_idx = findoption((char_u *)"ma");
8683 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8684}
8685
8686/*
8687 * Set the global value for 'iminsert' to the local value.
8688 */
8689 void
8690set_iminsert_global()
8691{
8692 p_iminsert = curbuf->b_p_iminsert;
8693}
8694
8695/*
8696 * Set the global value for 'imsearch' to the local value.
8697 */
8698 void
8699set_imsearch_global()
8700{
8701 p_imsearch = curbuf->b_p_imsearch;
8702}
8703
8704#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8705static int expand_option_idx = -1;
8706static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8707static int expand_option_flags = 0;
8708
8709 void
8710set_context_in_set_cmd(xp, arg, opt_flags)
8711 expand_T *xp;
8712 char_u *arg;
8713 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8714{
8715 int nextchar;
8716 long_u flags = 0; /* init for GCC */
8717 int opt_idx = 0; /* init for GCC */
8718 char_u *p;
8719 char_u *s;
8720 int is_term_option = FALSE;
8721 int key;
8722
8723 expand_option_flags = opt_flags;
8724
8725 xp->xp_context = EXPAND_SETTINGS;
8726 if (*arg == NUL)
8727 {
8728 xp->xp_pattern = arg;
8729 return;
8730 }
8731 p = arg + STRLEN(arg) - 1;
8732 if (*p == ' ' && *(p - 1) != '\\')
8733 {
8734 xp->xp_pattern = p + 1;
8735 return;
8736 }
8737 while (p > arg)
8738 {
8739 s = p;
8740 /* count number of backslashes before ' ' or ',' */
8741 if (*p == ' ' || *p == ',')
8742 {
8743 while (s > arg && *(s - 1) == '\\')
8744 --s;
8745 }
8746 /* break at a space with an even number of backslashes */
8747 if (*p == ' ' && ((p - s) & 1) == 0)
8748 {
8749 ++p;
8750 break;
8751 }
8752 --p;
8753 }
8754 if (STRNCMP(p, "no", 2) == 0)
8755 {
8756 xp->xp_context = EXPAND_BOOL_SETTINGS;
8757 p += 2;
8758 }
8759 if (STRNCMP(p, "inv", 3) == 0)
8760 {
8761 xp->xp_context = EXPAND_BOOL_SETTINGS;
8762 p += 3;
8763 }
8764 xp->xp_pattern = arg = p;
8765 if (*arg == '<')
8766 {
8767 while (*p != '>')
8768 if (*p++ == NUL) /* expand terminal option name */
8769 return;
8770 key = get_special_key_code(arg + 1);
8771 if (key == 0) /* unknown name */
8772 {
8773 xp->xp_context = EXPAND_NOTHING;
8774 return;
8775 }
8776 nextchar = *++p;
8777 is_term_option = TRUE;
8778 expand_option_name[2] = KEY2TERMCAP0(key);
8779 expand_option_name[3] = KEY2TERMCAP1(key);
8780 }
8781 else
8782 {
8783 if (p[0] == 't' && p[1] == '_')
8784 {
8785 p += 2;
8786 if (*p != NUL)
8787 ++p;
8788 if (*p == NUL)
8789 return; /* expand option name */
8790 nextchar = *++p;
8791 is_term_option = TRUE;
8792 expand_option_name[2] = p[-2];
8793 expand_option_name[3] = p[-1];
8794 }
8795 else
8796 {
8797 /* Allow * wildcard */
8798 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
8799 p++;
8800 if (*p == NUL)
8801 return;
8802 nextchar = *p;
8803 *p = NUL;
8804 opt_idx = findoption(arg);
8805 *p = nextchar;
8806 if (opt_idx == -1 || options[opt_idx].var == NULL)
8807 {
8808 xp->xp_context = EXPAND_NOTHING;
8809 return;
8810 }
8811 flags = options[opt_idx].flags;
8812 if (flags & P_BOOL)
8813 {
8814 xp->xp_context = EXPAND_NOTHING;
8815 return;
8816 }
8817 }
8818 }
8819 /* handle "-=" and "+=" */
8820 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
8821 {
8822 ++p;
8823 nextchar = '=';
8824 }
8825 if ((nextchar != '=' && nextchar != ':')
8826 || xp->xp_context == EXPAND_BOOL_SETTINGS)
8827 {
8828 xp->xp_context = EXPAND_UNSUCCESSFUL;
8829 return;
8830 }
8831 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
8832 {
8833 xp->xp_context = EXPAND_OLD_SETTING;
8834 if (is_term_option)
8835 expand_option_idx = -1;
8836 else
8837 expand_option_idx = opt_idx;
8838 xp->xp_pattern = p + 1;
8839 return;
8840 }
8841 xp->xp_context = EXPAND_NOTHING;
8842 if (is_term_option || (flags & P_NUM))
8843 return;
8844
8845 xp->xp_pattern = p + 1;
8846
8847 if (flags & P_EXPAND)
8848 {
8849 p = options[opt_idx].var;
8850 if (p == (char_u *)&p_bdir
8851 || p == (char_u *)&p_dir
8852 || p == (char_u *)&p_path
8853 || p == (char_u *)&p_rtp
8854#ifdef FEAT_SEARCHPATH
8855 || p == (char_u *)&p_cdpath
8856#endif
8857#ifdef FEAT_SESSION
8858 || p == (char_u *)&p_vdir
8859#endif
8860 )
8861 {
8862 xp->xp_context = EXPAND_DIRECTORIES;
8863 if (p == (char_u *)&p_path
8864#ifdef FEAT_SEARCHPATH
8865 || p == (char_u *)&p_cdpath
8866#endif
8867 )
8868 xp->xp_backslash = XP_BS_THREE;
8869 else
8870 xp->xp_backslash = XP_BS_ONE;
8871 }
8872 else
8873 {
8874 xp->xp_context = EXPAND_FILES;
8875 /* for 'tags' need three backslashes for a space */
8876 if (p == (char_u *)&p_tags)
8877 xp->xp_backslash = XP_BS_THREE;
8878 else
8879 xp->xp_backslash = XP_BS_ONE;
8880 }
8881 }
8882
8883 /* For an option that is a list of file names, find the start of the
8884 * last file name. */
8885 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
8886 {
8887 /* count number of backslashes before ' ' or ',' */
8888 if (*p == ' ' || *p == ',')
8889 {
8890 s = p;
8891 while (s > xp->xp_pattern && *(s - 1) == '\\')
8892 --s;
8893 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
8894 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
8895 {
8896 xp->xp_pattern = p + 1;
8897 break;
8898 }
8899 }
8900 }
8901
8902 return;
8903}
8904
8905 int
8906ExpandSettings(xp, regmatch, num_file, file)
8907 expand_T *xp;
8908 regmatch_T *regmatch;
8909 int *num_file;
8910 char_u ***file;
8911{
8912 int num_normal = 0; /* Nr of matching non-term-code settings */
8913 int num_term = 0; /* Nr of matching terminal code settings */
8914 int opt_idx;
8915 int match;
8916 int count = 0;
8917 char_u *str;
8918 int loop;
8919 int is_term_opt;
8920 char_u name_buf[MAX_KEY_NAME_LEN];
8921 static char *(names[]) = {"all", "termcap"};
8922 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
8923
8924 /* do this loop twice:
8925 * loop == 0: count the number of matching options
8926 * loop == 1: copy the matching options into allocated memory
8927 */
8928 for (loop = 0; loop <= 1; ++loop)
8929 {
8930 regmatch->rm_ic = ic;
8931 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
8932 {
8933 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
8934 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
8935 {
8936 if (loop == 0)
8937 num_normal++;
8938 else
8939 (*file)[count++] = vim_strsave((char_u *)names[match]);
8940 }
8941 }
8942 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
8943 opt_idx++)
8944 {
8945 if (options[opt_idx].var == NULL)
8946 continue;
8947 if (xp->xp_context == EXPAND_BOOL_SETTINGS
8948 && !(options[opt_idx].flags & P_BOOL))
8949 continue;
8950 is_term_opt = istermoption(&options[opt_idx]);
8951 if (is_term_opt && num_normal > 0)
8952 continue;
8953 match = FALSE;
8954 if (vim_regexec(regmatch, str, (colnr_T)0)
8955 || (options[opt_idx].shortname != NULL
8956 && vim_regexec(regmatch,
8957 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
8958 match = TRUE;
8959 else if (is_term_opt)
8960 {
8961 name_buf[0] = '<';
8962 name_buf[1] = 't';
8963 name_buf[2] = '_';
8964 name_buf[3] = str[2];
8965 name_buf[4] = str[3];
8966 name_buf[5] = '>';
8967 name_buf[6] = NUL;
8968 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8969 {
8970 match = TRUE;
8971 str = name_buf;
8972 }
8973 }
8974 if (match)
8975 {
8976 if (loop == 0)
8977 {
8978 if (is_term_opt)
8979 num_term++;
8980 else
8981 num_normal++;
8982 }
8983 else
8984 (*file)[count++] = vim_strsave(str);
8985 }
8986 }
8987 /*
8988 * Check terminal key codes, these are not in the option table
8989 */
8990 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
8991 {
8992 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
8993 {
8994 if (!isprint(str[0]) || !isprint(str[1]))
8995 continue;
8996
8997 name_buf[0] = 't';
8998 name_buf[1] = '_';
8999 name_buf[2] = str[0];
9000 name_buf[3] = str[1];
9001 name_buf[4] = NUL;
9002
9003 match = FALSE;
9004 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9005 match = TRUE;
9006 else
9007 {
9008 name_buf[0] = '<';
9009 name_buf[1] = 't';
9010 name_buf[2] = '_';
9011 name_buf[3] = str[0];
9012 name_buf[4] = str[1];
9013 name_buf[5] = '>';
9014 name_buf[6] = NUL;
9015
9016 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9017 match = TRUE;
9018 }
9019 if (match)
9020 {
9021 if (loop == 0)
9022 num_term++;
9023 else
9024 (*file)[count++] = vim_strsave(name_buf);
9025 }
9026 }
9027
9028 /*
9029 * Check special key names.
9030 */
9031 regmatch->rm_ic = TRUE; /* ignore case here */
9032 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9033 {
9034 name_buf[0] = '<';
9035 STRCPY(name_buf + 1, str);
9036 STRCAT(name_buf, ">");
9037
9038 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9039 {
9040 if (loop == 0)
9041 num_term++;
9042 else
9043 (*file)[count++] = vim_strsave(name_buf);
9044 }
9045 }
9046 }
9047 if (loop == 0)
9048 {
9049 if (num_normal > 0)
9050 *num_file = num_normal;
9051 else if (num_term > 0)
9052 *num_file = num_term;
9053 else
9054 return OK;
9055 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9056 if (*file == NULL)
9057 {
9058 *file = (char_u **)"";
9059 return FAIL;
9060 }
9061 }
9062 }
9063 return OK;
9064}
9065
9066 int
9067ExpandOldSetting(num_file, file)
9068 int *num_file;
9069 char_u ***file;
9070{
9071 char_u *var = NULL; /* init for GCC */
9072 char_u *buf;
9073
9074 *num_file = 0;
9075 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9076 if (*file == NULL)
9077 return FAIL;
9078
9079 /*
9080 * For a terminal key code expand_option_idx is < 0.
9081 */
9082 if (expand_option_idx < 0)
9083 {
9084 var = find_termcode(expand_option_name + 2);
9085 if (var == NULL)
9086 expand_option_idx = findoption(expand_option_name);
9087 }
9088
9089 if (expand_option_idx >= 0)
9090 {
9091 /* put string of option value in NameBuff */
9092 option_value2string(&options[expand_option_idx], expand_option_flags);
9093 var = NameBuff;
9094 }
9095 else if (var == NULL)
9096 var = (char_u *)"";
9097
9098 /* A backslash is required before some characters. This is the reverse of
9099 * what happens in do_set(). */
9100 buf = vim_strsave_escaped(var, escape_chars);
9101
9102 if (buf == NULL)
9103 {
9104 vim_free(*file);
9105 *file = NULL;
9106 return FAIL;
9107 }
9108
9109#ifdef BACKSLASH_IN_FILENAME
9110 /* For MS-Windows et al. we don't double backslashes at the start and
9111 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009112 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009113 if (var[0] == '\\' && var[1] == '\\'
9114 && expand_option_idx >= 0
9115 && (options[expand_option_idx].flags & P_EXPAND)
9116 && vim_isfilec(var[2])
9117 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9118 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009119#endif
9120
9121 *file[0] = buf;
9122 *num_file = 1;
9123 return OK;
9124}
9125#endif
9126
9127/*
9128 * Get the value for the numeric or string option *opp in a nice format into
9129 * NameBuff[]. Must not be called with a hidden option!
9130 */
9131 static void
9132option_value2string(opp, opt_flags)
9133 struct vimoption *opp;
9134 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9135{
9136 char_u *varp;
9137
9138 varp = get_varp_scope(opp, opt_flags);
9139
9140 if (opp->flags & P_NUM)
9141 {
9142 long wc = 0;
9143
9144 if (wc_use_keyname(varp, &wc))
9145 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9146 else if (wc != 0)
9147 STRCPY(NameBuff, transchar((int)wc));
9148 else
9149 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9150 }
9151 else /* P_STRING */
9152 {
9153 varp = *(char_u **)(varp);
9154 if (varp == NULL) /* just in case */
9155 NameBuff[0] = NUL;
9156#ifdef FEAT_CRYPT
9157 /* don't show the actual value of 'key', only that it's set */
9158 if (opp->var == (char_u *)&p_key && *varp)
9159 STRCPY(NameBuff, "*****");
9160#endif
9161 else if (opp->flags & P_EXPAND)
9162 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9163 /* Translate 'pastetoggle' into special key names */
9164 else if ((char_u **)opp->var == &p_pt)
9165 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9166 else
9167 STRNCPY(NameBuff, varp, MAXPATHL);
9168 }
9169}
9170
9171/*
9172 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9173 * printed as a keyname.
9174 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9175 */
9176 static int
9177wc_use_keyname(varp, wcp)
9178 char_u *varp;
9179 long *wcp;
9180{
9181 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9182 {
9183 *wcp = *(long *)varp;
9184 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9185 return TRUE;
9186 }
9187 return FALSE;
9188}
9189
9190#ifdef FEAT_LANGMAP
9191/*
9192 * Any character has an equivalent character. This is used for keyboards that
9193 * have a special language mode that sends characters above 128 (although
9194 * other characters can be translated too).
9195 */
9196
9197/*
9198 * char_u langmap_mapchar[256];
9199 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9200 * "translate" native lang chars in normal mode or some cases of
9201 * insert mode without having to tediously switch lang mode back&forth.
9202 */
9203
9204 static void
9205langmap_init()
9206{
9207 int i;
9208
9209 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9210 langmap_mapchar[i] = i;
9211}
9212
9213/*
9214 * Called when langmap option is set; the language map can be
9215 * changed at any time!
9216 */
9217 static void
9218langmap_set()
9219{
9220 char_u *p;
9221 char_u *p2;
9222 int from, to;
9223
9224 langmap_init(); /* back to one-to-one map first */
9225
9226 for (p = p_langmap; p[0] != NUL; )
9227 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009228 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9229 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009230 {
9231 if (p2[0] == '\\' && p2[1] != NUL)
9232 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233 }
9234 if (p2[0] == ';')
9235 ++p2; /* abcd;ABCD form, p2 points to A */
9236 else
9237 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9238 while (p[0])
9239 {
9240 if (p[0] == '\\' && p[1] != NUL)
9241 ++p;
9242#ifdef FEAT_MBYTE
9243 from = (*mb_ptr2char)(p);
9244#else
9245 from = p[0];
9246#endif
9247 if (p2 == NULL)
9248 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009249 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009250 if (p[0] == '\\')
9251 ++p;
9252#ifdef FEAT_MBYTE
9253 to = (*mb_ptr2char)(p);
9254#else
9255 to = p[0];
9256#endif
9257 }
9258 else
9259 {
9260 if (p2[0] == '\\')
9261 ++p2;
9262#ifdef FEAT_MBYTE
9263 to = (*mb_ptr2char)(p2);
9264#else
9265 to = p2[0];
9266#endif
9267 }
9268 if (to == NUL)
9269 {
9270 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9271 transchar(from));
9272 return;
9273 }
9274 langmap_mapchar[from & 255] = to;
9275
9276 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009277 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009278 if (p2 == NULL)
9279 {
9280 if (p[0] == ',')
9281 {
9282 ++p;
9283 break;
9284 }
9285 }
9286 else
9287 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009288 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009289 if (*p == ';')
9290 {
9291 p = p2;
9292 if (p[0] != NUL)
9293 {
9294 if (p[0] != ',')
9295 {
9296 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9297 return;
9298 }
9299 ++p;
9300 }
9301 break;
9302 }
9303 }
9304 }
9305 }
9306}
9307#endif
9308
9309/*
9310 * Return TRUE if format option 'x' is in effect.
9311 * Take care of no formatting when 'paste' is set.
9312 */
9313 int
9314has_format_option(x)
9315 int x;
9316{
9317 if (p_paste)
9318 return FALSE;
9319 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9320}
9321
9322/*
9323 * Return TRUE if "x" is present in 'shortmess' option, or
9324 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9325 */
9326 int
9327shortmess(x)
9328 int x;
9329{
9330 return ( vim_strchr(p_shm, x) != NULL
9331 || (vim_strchr(p_shm, 'a') != NULL
9332 && vim_strchr((char_u *)SHM_A, x) != NULL));
9333}
9334
9335/*
9336 * paste_option_changed() - Called after p_paste was set or reset.
9337 */
9338 static void
9339paste_option_changed()
9340{
9341 static int old_p_paste = FALSE;
9342 static int save_sm = 0;
9343#ifdef FEAT_CMDL_INFO
9344 static int save_ru = 0;
9345#endif
9346#ifdef FEAT_RIGHTLEFT
9347 static int save_ri = 0;
9348 static int save_hkmap = 0;
9349#endif
9350 buf_T *buf;
9351
9352 if (p_paste)
9353 {
9354 /*
9355 * Paste switched from off to on.
9356 * Save the current values, so they can be restored later.
9357 */
9358 if (!old_p_paste)
9359 {
9360 /* save options for each buffer */
9361 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9362 {
9363 buf->b_p_tw_nopaste = buf->b_p_tw;
9364 buf->b_p_wm_nopaste = buf->b_p_wm;
9365 buf->b_p_sts_nopaste = buf->b_p_sts;
9366 buf->b_p_ai_nopaste = buf->b_p_ai;
9367 }
9368
9369 /* save global options */
9370 save_sm = p_sm;
9371#ifdef FEAT_CMDL_INFO
9372 save_ru = p_ru;
9373#endif
9374#ifdef FEAT_RIGHTLEFT
9375 save_ri = p_ri;
9376 save_hkmap = p_hkmap;
9377#endif
9378 /* save global values for local buffer options */
9379 p_tw_nopaste = p_tw;
9380 p_wm_nopaste = p_wm;
9381 p_sts_nopaste = p_sts;
9382 p_ai_nopaste = p_ai;
9383 }
9384
9385 /*
9386 * Always set the option values, also when 'paste' is set when it is
9387 * already on.
9388 */
9389 /* set options for each buffer */
9390 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9391 {
9392 buf->b_p_tw = 0; /* textwidth is 0 */
9393 buf->b_p_wm = 0; /* wrapmargin is 0 */
9394 buf->b_p_sts = 0; /* softtabstop is 0 */
9395 buf->b_p_ai = 0; /* no auto-indent */
9396 }
9397
9398 /* set global options */
9399 p_sm = 0; /* no showmatch */
9400#ifdef FEAT_CMDL_INFO
9401# ifdef FEAT_WINDOWS
9402 if (p_ru)
9403 status_redraw_all(); /* redraw to remove the ruler */
9404# endif
9405 p_ru = 0; /* no ruler */
9406#endif
9407#ifdef FEAT_RIGHTLEFT
9408 p_ri = 0; /* no reverse insert */
9409 p_hkmap = 0; /* no Hebrew keyboard */
9410#endif
9411 /* set global values for local buffer options */
9412 p_tw = 0;
9413 p_wm = 0;
9414 p_sts = 0;
9415 p_ai = 0;
9416 }
9417
9418 /*
9419 * Paste switched from on to off: Restore saved values.
9420 */
9421 else if (old_p_paste)
9422 {
9423 /* restore options for each buffer */
9424 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9425 {
9426 buf->b_p_tw = buf->b_p_tw_nopaste;
9427 buf->b_p_wm = buf->b_p_wm_nopaste;
9428 buf->b_p_sts = buf->b_p_sts_nopaste;
9429 buf->b_p_ai = buf->b_p_ai_nopaste;
9430 }
9431
9432 /* restore global options */
9433 p_sm = save_sm;
9434#ifdef FEAT_CMDL_INFO
9435# ifdef FEAT_WINDOWS
9436 if (p_ru != save_ru)
9437 status_redraw_all(); /* redraw to draw the ruler */
9438# endif
9439 p_ru = save_ru;
9440#endif
9441#ifdef FEAT_RIGHTLEFT
9442 p_ri = save_ri;
9443 p_hkmap = save_hkmap;
9444#endif
9445 /* set global values for local buffer options */
9446 p_tw = p_tw_nopaste;
9447 p_wm = p_wm_nopaste;
9448 p_sts = p_sts_nopaste;
9449 p_ai = p_ai_nopaste;
9450 }
9451
9452 old_p_paste = p_paste;
9453}
9454
9455/*
9456 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9457 *
9458 * Reset 'compatible' and set the values for options that didn't get set yet
9459 * to the Vim defaults.
9460 * Don't do this if the 'compatible' option has been set or reset before.
9461 */
9462 void
9463vimrc_found()
9464{
9465 int opt_idx;
9466
9467 if (!option_was_set((char_u *)"cp"))
9468 {
9469 p_cp = FALSE;
9470 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9471 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9472 set_option_default(opt_idx, OPT_FREE, FALSE);
9473 didset_options();
9474 }
9475}
9476
9477/*
9478 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9479 */
9480 void
9481change_compatible(on)
9482 int on;
9483{
9484 if (p_cp != on)
9485 {
9486 p_cp = on;
9487 compatible_set();
9488 }
9489 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9490}
9491
9492/*
9493 * Return TRUE when option "name" has been set.
9494 */
9495 int
9496option_was_set(name)
9497 char_u *name;
9498{
9499 int idx;
9500
9501 idx = findoption(name);
9502 if (idx < 0) /* unknown option */
9503 return FALSE;
9504 if (options[idx].flags & P_WAS_SET)
9505 return TRUE;
9506 return FALSE;
9507}
9508
9509/*
9510 * compatible_set() - Called when 'compatible' has been set or unset.
9511 *
9512 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9513 * flag) to a Vi compatible value.
9514 * When 'compatible' is unset: Set all options that have a different default
9515 * for Vim (without the P_VI_DEF flag) to that default.
9516 */
9517 static void
9518compatible_set()
9519{
9520 int opt_idx;
9521
9522 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9523 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9524 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9525 set_option_default(opt_idx, OPT_FREE, p_cp);
9526 didset_options();
9527}
9528
9529#ifdef FEAT_LINEBREAK
9530
9531# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9532 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009533 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009534# endif
9535
9536/*
9537 * fill_breakat_flags() -- called when 'breakat' changes value.
9538 */
9539 static void
9540fill_breakat_flags()
9541{
9542 char_u *c;
9543 int i;
9544
9545 for (i = 0; i < 256; i++)
9546 breakat_flags[i] = FALSE;
9547
9548 if (p_breakat != NULL)
9549 for (c = p_breakat; *c; c++)
9550 breakat_flags[*c] = TRUE;
9551}
9552
9553# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009554 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009555# endif
9556
9557#endif
9558
9559/*
9560 * Check an option that can be a range of string values.
9561 *
9562 * Return OK for correct value, FAIL otherwise.
9563 * Empty is always OK.
9564 */
9565 static int
9566check_opt_strings(val, values, list)
9567 char_u *val;
9568 char **values;
9569 int list; /* when TRUE: accept a list of values */
9570{
9571 return opt_strings_flags(val, values, NULL, list);
9572}
9573
9574/*
9575 * Handle an option that can be a range of string values.
9576 * Set a flag in "*flagp" for each string present.
9577 *
9578 * Return OK for correct value, FAIL otherwise.
9579 * Empty is always OK.
9580 */
9581 static int
9582opt_strings_flags(val, values, flagp, list)
9583 char_u *val; /* new value */
9584 char **values; /* array of valid string values */
9585 unsigned *flagp;
9586 int list; /* when TRUE: accept a list of values */
9587{
9588 int i;
9589 int len;
9590 unsigned new_flags = 0;
9591
9592 while (*val)
9593 {
9594 for (i = 0; ; ++i)
9595 {
9596 if (values[i] == NULL) /* val not found in values[] */
9597 return FAIL;
9598
9599 len = (int)STRLEN(values[i]);
9600 if (STRNCMP(values[i], val, len) == 0
9601 && ((list && val[len] == ',') || val[len] == NUL))
9602 {
9603 val += len + (val[len] == ',');
9604 new_flags |= (1 << i);
9605 break; /* check next item in val list */
9606 }
9607 }
9608 }
9609 if (flagp != NULL)
9610 *flagp = new_flags;
9611
9612 return OK;
9613}
9614
9615/*
9616 * Read the 'wildmode' option, fill wim_flags[].
9617 */
9618 static int
9619check_opt_wim()
9620{
9621 char_u new_wim_flags[4];
9622 char_u *p;
9623 int i;
9624 int idx = 0;
9625
9626 for (i = 0; i < 4; ++i)
9627 new_wim_flags[i] = 0;
9628
9629 for (p = p_wim; *p; ++p)
9630 {
9631 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9632 ;
9633 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9634 return FAIL;
9635 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9636 new_wim_flags[idx] |= WIM_LONGEST;
9637 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9638 new_wim_flags[idx] |= WIM_FULL;
9639 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9640 new_wim_flags[idx] |= WIM_LIST;
9641 else
9642 return FAIL;
9643 p += i;
9644 if (*p == NUL)
9645 break;
9646 if (*p == ',')
9647 {
9648 if (idx == 3)
9649 return FAIL;
9650 ++idx;
9651 }
9652 }
9653
9654 /* fill remaining entries with last flag */
9655 while (idx < 3)
9656 {
9657 new_wim_flags[idx + 1] = new_wim_flags[idx];
9658 ++idx;
9659 }
9660
9661 /* only when there are no errors, wim_flags[] is changed */
9662 for (i = 0; i < 4; ++i)
9663 wim_flags[i] = new_wim_flags[i];
9664 return OK;
9665}
9666
9667/*
9668 * Check if backspacing over something is allowed.
9669 */
9670 int
9671can_bs(what)
9672 int what; /* BS_INDENT, BS_EOL or BS_START */
9673{
9674 switch (*p_bs)
9675 {
9676 case '2': return TRUE;
9677 case '1': return (what != BS_START);
9678 case '0': return FALSE;
9679 }
9680 return vim_strchr(p_bs, what) != NULL;
9681}
9682
9683/*
9684 * Save the current values of 'fileformat' and 'fileencoding', so that we know
9685 * the file must be considered changed when the value is different.
9686 */
9687 void
9688save_file_ff(buf)
9689 buf_T *buf;
9690{
9691 buf->b_start_ffc = *buf->b_p_ff;
9692 buf->b_start_eol = buf->b_p_eol;
9693#ifdef FEAT_MBYTE
9694 /* Only use free/alloc when necessary, they take time. */
9695 if (buf->b_start_fenc == NULL
9696 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9697 {
9698 vim_free(buf->b_start_fenc);
9699 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9700 }
9701#endif
9702}
9703
9704/*
9705 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9706 * from when editing started (save_file_ff() called).
9707 * Also when 'endofline' was changed and 'binary' is set.
9708 * Don't consider a new, empty buffer to be changed.
9709 */
9710 int
9711file_ff_differs(buf)
9712 buf_T *buf;
9713{
9714 if ((buf->b_flags & BF_NEW)
9715 && buf->b_ml.ml_line_count == 1
9716 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
9717 return FALSE;
9718 if (buf->b_start_ffc != *buf->b_p_ff)
9719 return TRUE;
9720 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
9721 return TRUE;
9722#ifdef FEAT_MBYTE
9723 if (buf->b_start_fenc == NULL)
9724 return (*buf->b_p_fenc != NUL);
9725 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
9726#else
9727 return FALSE;
9728#endif
9729}
9730
9731/*
9732 * return OK if "p" is a valid fileformat name, FAIL otherwise.
9733 */
9734 int
9735check_ff_value(p)
9736 char_u *p;
9737{
9738 return check_opt_strings(p, p_ff_values, FALSE);
9739}