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