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