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