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