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