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