blob: eef61292b65dbe1a514817ae2fe99102d9a41cb1 [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 Moolenaar24bbcfe2005-06-28 23:32:02 +00002043 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
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 Moolenaar24bbcfe2005-06-28 23:32:02 +00002052 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002053#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.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004557 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004558 */
4559 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004560 (char_u **)options[opt_idx].var == &p_tags,
4561#ifdef FEAT_SYN_HL
4562 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4563#endif
4564 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4566 return NULL;
4567
4568 return NameBuff;
4569}
4570
4571/*
4572 * After setting various option values: recompute variables that depend on
4573 * option values.
4574 */
4575 static void
4576didset_options()
4577{
4578 /* initialize the table for 'iskeyword' et.al. */
4579 (void)init_chartab();
4580
4581 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4582 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4583#ifdef FEAT_SESSION
4584 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4585 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4586#endif
4587#ifdef FEAT_FOLDING
4588 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4589#endif
4590 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4591#ifdef FEAT_VIRTUALEDIT
4592 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4593#endif
4594#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4595 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4596#endif
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004597#ifdef FEAT_SYN_HL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004598 (void)spell_check_sps();
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004600#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4601 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4602#endif
4603#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4604 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4605#endif
4606#ifdef FEAT_CMDWIN
4607 /* set cedit_key */
4608 (void)check_cedit();
4609#endif
4610}
4611
4612/*
4613 * Check for string options that are NULL (normally only termcap options).
4614 */
4615 void
4616check_options()
4617{
4618 int opt_idx;
4619
4620 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4621 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4622 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4623}
4624
4625/*
4626 * Check string options in a buffer for NULL value.
4627 */
4628 void
4629check_buf_options(buf)
4630 buf_T *buf;
4631{
4632#if defined(FEAT_QUICKFIX)
4633 check_string_option(&buf->b_p_bh);
4634 check_string_option(&buf->b_p_bt);
4635#endif
4636#ifdef FEAT_MBYTE
4637 check_string_option(&buf->b_p_fenc);
4638#endif
4639 check_string_option(&buf->b_p_ff);
4640#ifdef FEAT_FIND_ID
4641 check_string_option(&buf->b_p_def);
4642 check_string_option(&buf->b_p_inc);
4643# ifdef FEAT_EVAL
4644 check_string_option(&buf->b_p_inex);
4645# endif
4646#endif
4647#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4648 check_string_option(&buf->b_p_inde);
4649 check_string_option(&buf->b_p_indk);
4650#endif
4651#ifdef FEAT_CRYPT
4652 check_string_option(&buf->b_p_key);
4653#endif
4654 check_string_option(&buf->b_p_kp);
4655 check_string_option(&buf->b_p_mps);
4656 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004657 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004658 check_string_option(&buf->b_p_isk);
4659#ifdef FEAT_COMMENTS
4660 check_string_option(&buf->b_p_com);
4661#endif
4662#ifdef FEAT_FOLDING
4663 check_string_option(&buf->b_p_cms);
4664#endif
4665 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004666#ifdef FEAT_TEXTOBJ
4667 check_string_option(&buf->b_p_qe);
4668#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004669#ifdef FEAT_SYN_HL
4670 check_string_option(&buf->b_p_syn);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00004671 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00004672 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004673#endif
4674#ifdef FEAT_SEARCHPATH
4675 check_string_option(&buf->b_p_sua);
4676#endif
4677#ifdef FEAT_CINDENT
4678 check_string_option(&buf->b_p_cink);
4679 check_string_option(&buf->b_p_cino);
4680#endif
4681#ifdef FEAT_AUTOCMD
4682 check_string_option(&buf->b_p_ft);
4683#endif
4684#ifdef FEAT_OSFILETYPE
4685 check_string_option(&buf->b_p_oft);
4686#endif
4687#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4688 check_string_option(&buf->b_p_cinw);
4689#endif
4690#ifdef FEAT_INS_EXPAND
4691 check_string_option(&buf->b_p_cpt);
4692#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004693#ifdef FEAT_COMPL_FUNC
4694 check_string_option(&buf->b_p_cfu);
4695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004696#ifdef FEAT_KEYMAP
4697 check_string_option(&buf->b_p_keymap);
4698#endif
4699#ifdef FEAT_QUICKFIX
4700 check_string_option(&buf->b_p_gp);
4701 check_string_option(&buf->b_p_mp);
4702 check_string_option(&buf->b_p_efm);
4703#endif
4704 check_string_option(&buf->b_p_ep);
4705 check_string_option(&buf->b_p_path);
4706 check_string_option(&buf->b_p_tags);
4707#ifdef FEAT_INS_EXPAND
4708 check_string_option(&buf->b_p_dict);
4709 check_string_option(&buf->b_p_tsr);
4710#endif
4711}
4712
4713/*
4714 * Free the string allocated for an option.
4715 * Checks for the string being empty_option. This may happen if we're out of
4716 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4717 * check_options().
4718 * Does NOT check for P_ALLOCED flag!
4719 */
4720 void
4721free_string_option(p)
4722 char_u *p;
4723{
4724 if (p != empty_option)
4725 vim_free(p);
4726}
4727
4728 void
4729clear_string_option(pp)
4730 char_u **pp;
4731{
4732 if (*pp != empty_option)
4733 vim_free(*pp);
4734 *pp = empty_option;
4735}
4736
4737 static void
4738check_string_option(pp)
4739 char_u **pp;
4740{
4741 if (*pp == NULL)
4742 *pp = empty_option;
4743}
4744
4745/*
4746 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4747 */
4748 void
4749set_term_option_alloced(p)
4750 char_u **p;
4751{
4752 int opt_idx;
4753
4754 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4755 if (options[opt_idx].var == (char_u *)p)
4756 {
4757 options[opt_idx].flags |= P_ALLOCED;
4758 return;
4759 }
4760 return; /* cannot happen: didn't find it! */
4761}
4762
4763/*
4764 * Set a string option to a new value (without checking the effect).
4765 * The string is copied into allocated memory.
4766 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4767 */
4768 void
4769set_string_option_direct(name, opt_idx, val, opt_flags)
4770 char_u *name;
4771 int opt_idx;
4772 char_u *val;
4773 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4774{
4775 char_u *s;
4776 char_u **varp;
4777 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
4778
4779 if (opt_idx == -1) /* use name */
4780 {
4781 opt_idx = findoption(name);
4782 if (opt_idx == -1) /* not found (should not happen) */
4783 return;
4784 }
4785
4786 if (options[opt_idx].var == NULL) /* can't set hidden option */
4787 return;
4788
4789 s = vim_strsave(val);
4790 if (s != NULL)
4791 {
4792 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4793 both ? OPT_LOCAL : opt_flags);
4794 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
4795 free_string_option(*varp);
4796 *varp = s;
4797
4798 /* For buffer/window local option may also set the global value. */
4799 if (both)
4800 set_string_option_global(opt_idx, varp);
4801
4802 options[opt_idx].flags |= P_ALLOCED;
4803
4804 /* When setting both values of a global option with a local value,
4805 * make the local value empty, so that the global value is used. */
4806 if ((int)options[opt_idx].indir >= PV_BOTH && both)
4807 {
4808 free_string_option(*varp);
4809 *varp = empty_option;
4810 }
4811 }
4812}
4813
4814/*
4815 * Set global value for string option when it's a local option.
4816 */
4817 static void
4818set_string_option_global(opt_idx, varp)
4819 int opt_idx; /* option index */
4820 char_u **varp; /* pointer to option variable */
4821{
4822 char_u **p, *s;
4823
4824 /* the global value is always allocated */
4825 if (options[opt_idx].var == VAR_WIN)
4826 p = (char_u **)GLOBAL_WO(varp);
4827 else
4828 p = (char_u **)options[opt_idx].var;
4829 if (options[opt_idx].indir != PV_NONE
4830 && p != varp
4831 && (s = vim_strsave(*varp)) != NULL)
4832 {
4833 free_string_option(*p);
4834 *p = s;
4835 }
4836}
4837
4838/*
4839 * Set a string option to a new value, and handle the effects.
4840 */
4841 static void
4842set_string_option(opt_idx, value, opt_flags)
4843 int opt_idx;
4844 char_u *value;
4845 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4846{
4847 char_u *s;
4848 char_u **varp;
4849 char_u *oldval;
4850
4851 if (options[opt_idx].var == NULL) /* don't set hidden option */
4852 return;
4853
4854 s = vim_strsave(value);
4855 if (s != NULL)
4856 {
4857 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4858 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4859 ? ((int)options[opt_idx].indir >= PV_BOTH
4860 ? OPT_GLOBAL : OPT_LOCAL)
4861 : opt_flags);
4862 oldval = *varp;
4863 *varp = s;
4864 options[opt_idx].flags |= P_WAS_SET;
4865 (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
4866 opt_flags);
4867 }
4868}
4869
4870/*
4871 * Handle string options that need some action to perform when changed.
4872 * Returns NULL for success, or an error message for an error.
4873 */
4874 static char_u *
4875did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
4876 opt_flags)
4877 int opt_idx; /* index in options[] table */
4878 char_u **varp; /* pointer to the option variable */
4879 int new_value_alloced; /* new value was allocated */
4880 char_u *oldval; /* previous value of the option */
4881 char_u *errbuf; /* buffer for errors, or NULL */
4882 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4883{
4884 char_u *errmsg = NULL;
4885 char_u *s, *p;
4886 int did_chartab = FALSE;
4887 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00004888 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004889
4890 /* Get the global option to compare with, otherwise we would have to check
4891 * two values for all local options. */
4892 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
4893
4894 /* Disallow changing some options from secure mode */
4895 if ((secure
4896#ifdef HAVE_SANDBOX
4897 || sandbox != 0
4898#endif
4899 ) && (options[opt_idx].flags & P_SECURE))
4900 {
4901 errmsg = e_secure;
4902 }
4903
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004904 /* Check for a "normal" file name in some options. Disallow a path
4905 * separator (slash and/or backslash), wildcards and characters that are
4906 * often illegal in a file name. */
4907 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004908 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004909 {
4910 errmsg = e_invarg;
4911 }
4912
Bram Moolenaar071d4272004-06-13 20:20:40 +00004913 /* 'term' */
4914 else if (varp == &T_NAME)
4915 {
4916 if (T_NAME[0] == NUL)
4917 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
4918#ifdef FEAT_GUI
4919 if (gui.in_use)
4920 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
4921 else if (term_is_gui(T_NAME))
4922 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
4923#endif
4924 else if (set_termname(T_NAME) == FAIL)
4925 errmsg = (char_u *)N_("E522: Not found in termcap");
4926 else
4927 /* Screen colors may have changed. */
4928 redraw_later_clear();
4929 }
4930
4931 /* 'backupcopy' */
4932 else if (varp == &p_bkc)
4933 {
4934 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
4935 errmsg = e_invarg;
4936 if (((bkc_flags & BKC_AUTO) != 0)
4937 + ((bkc_flags & BKC_YES) != 0)
4938 + ((bkc_flags & BKC_NO) != 0) != 1)
4939 {
4940 /* Must have exactly one of "auto", "yes" and "no". */
4941 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
4942 errmsg = e_invarg;
4943 }
4944 }
4945
4946 /* 'backupext' and 'patchmode' */
4947 else if (varp == &p_bex || varp == &p_pm)
4948 {
4949 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
4950 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
4951 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
4952 }
4953
4954 /*
4955 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
4956 * If the new option is invalid, use old value. 'lisp' option: refill
4957 * chartab[] for '-' char
4958 */
4959 else if ( varp == &p_isi
4960 || varp == &(curbuf->b_p_isk)
4961 || varp == &p_isp
4962 || varp == &p_isf)
4963 {
4964 if (init_chartab() == FAIL)
4965 {
4966 did_chartab = TRUE; /* need to restore it below */
4967 errmsg = e_invarg; /* error in value */
4968 }
4969 }
4970
4971 /* 'helpfile' */
4972 else if (varp == &p_hf)
4973 {
4974 /* May compute new values for $VIM and $VIMRUNTIME */
4975 if (didset_vim)
4976 {
4977 vim_setenv((char_u *)"VIM", (char_u *)"");
4978 didset_vim = FALSE;
4979 }
4980 if (didset_vimruntime)
4981 {
4982 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
4983 didset_vimruntime = FALSE;
4984 }
4985 }
4986
4987#ifdef FEAT_MULTI_LANG
4988 /* 'helplang' */
4989 else if (varp == &p_hlg)
4990 {
4991 /* Check for "", "ab", "ab,cd", etc. */
4992 for (s = p_hlg; *s != NUL; s += 3)
4993 {
4994 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
4995 {
4996 errmsg = e_invarg;
4997 break;
4998 }
4999 if (s[2] == NUL)
5000 break;
5001 }
5002 }
5003#endif
5004
5005 /* 'highlight' */
5006 else if (varp == &p_hl)
5007 {
5008 if (highlight_changed() == FAIL)
5009 errmsg = e_invarg; /* invalid flags */
5010 }
5011
5012 /* 'nrformats' */
5013 else if (gvarp == &p_nf)
5014 {
5015 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5016 errmsg = e_invarg;
5017 }
5018
5019#ifdef FEAT_SESSION
5020 /* 'sessionoptions' */
5021 else if (varp == &p_ssop)
5022 {
5023 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5024 errmsg = e_invarg;
5025 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5026 {
5027 /* Don't allow both "sesdir" and "curdir". */
5028 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5029 errmsg = e_invarg;
5030 }
5031 }
5032 /* 'viewoptions' */
5033 else if (varp == &p_vop)
5034 {
5035 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5036 errmsg = e_invarg;
5037 }
5038#endif
5039
5040 /* 'scrollopt' */
5041#ifdef FEAT_SCROLLBIND
5042 else if (varp == &p_sbo)
5043 {
5044 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5045 errmsg = e_invarg;
5046 }
5047#endif
5048
5049 /* 'ambiwidth' */
5050#ifdef FEAT_MBYTE
5051 else if (varp == &p_ambw)
5052 {
5053 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5054 errmsg = e_invarg;
5055 }
5056#endif
5057
5058 /* 'background' */
5059 else if (varp == &p_bg)
5060 {
5061 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5062 {
5063#ifdef FEAT_EVAL
5064 int dark = (*p_bg == 'd');
5065#endif
5066
5067 init_highlight(FALSE, FALSE);
5068
5069#ifdef FEAT_EVAL
5070 if (dark != (*p_bg == 'd')
5071 && get_var_value((char_u *)"g:colors_name") != NULL)
5072 {
5073 /* The color scheme must have set 'background' back to another
5074 * value, that's not what we want here. Disable the color
5075 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005076 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 free_string_option(p_bg);
5078 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5079 check_string_option(&p_bg);
5080 init_highlight(FALSE, FALSE);
5081 }
5082#endif
5083 }
5084 else
5085 errmsg = e_invarg;
5086 }
5087
5088 /* 'wildmode' */
5089 else if (varp == &p_wim)
5090 {
5091 if (check_opt_wim() == FAIL)
5092 errmsg = e_invarg;
5093 }
5094
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005095#ifdef FEAT_CMDL_COMPL
5096 /* 'wildoptions' */
5097 else if (varp == &p_wop)
5098 {
5099 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5100 errmsg = e_invarg;
5101 }
5102#endif
5103
Bram Moolenaar071d4272004-06-13 20:20:40 +00005104#ifdef FEAT_WAK
5105 /* 'winaltkeys' */
5106 else if (varp == &p_wak)
5107 {
5108 if (*p_wak == NUL
5109 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5110 errmsg = e_invarg;
5111# ifdef FEAT_MENU
5112# ifdef FEAT_GUI_MOTIF
5113 else if (gui.in_use)
5114 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5115# else
5116# ifdef FEAT_GUI_GTK
5117 else if (gui.in_use)
5118 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5119# endif
5120# endif
5121# endif
5122 }
5123#endif
5124
5125#ifdef FEAT_AUTOCMD
5126 /* 'eventignore' */
5127 else if (varp == &p_ei)
5128 {
5129 if (check_ei() == FAIL)
5130 errmsg = e_invarg;
5131 }
5132#endif
5133
5134#ifdef FEAT_MBYTE
5135 /* 'encoding' and 'fileencoding' */
5136 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5137 {
5138 if (gvarp == &p_fenc)
5139 {
5140 if (!curbuf->b_p_ma)
5141 errmsg = e_modifiable;
5142 else if (vim_strchr(*varp, ',') != NULL)
5143 /* No comma allowed in 'fileencoding'; catches confusing it
5144 * with 'fileencodings'. */
5145 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005147 {
5148# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005149 /* May show a "+" in the title now. */
5150 need_maketitle = TRUE;
5151# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005152 /* Add 'fileencoding' to the swap file. */
5153 ml_setflags(curbuf);
5154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005155 }
5156 if (errmsg == NULL)
5157 {
5158 /* canonize the value, so that STRCMP() can be used on it */
5159 p = enc_canonize(*varp);
5160 if (p != NULL)
5161 {
5162 vim_free(*varp);
5163 *varp = p;
5164 }
5165 if (varp == &p_enc)
5166 {
5167 errmsg = mb_init();
5168# ifdef FEAT_TITLE
5169 need_maketitle = TRUE;
5170# endif
5171 }
5172 }
5173
5174# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5175 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5176 {
5177 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5178 if (STRCMP(p_tenc, "utf-8") != 0)
5179 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5180 }
5181# endif
5182
5183 if (errmsg == NULL)
5184 {
5185# ifdef FEAT_KEYMAP
5186 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5187 * (with another encoding). */
5188 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5189 (void)keymap_init();
5190# endif
5191
5192 /* When 'termencoding' is not empty and 'encoding' changes or when
5193 * 'termencoding' changes, need to setup for keyboard input and
5194 * display output conversion. */
5195 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5196 {
5197 convert_setup(&input_conv, p_tenc, p_enc);
5198 convert_setup(&output_conv, p_enc, p_tenc);
5199 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005200
5201# if defined(WIN3264) && defined(FEAT_MBYTE)
5202 /* $HOME may have characters in active code page. */
5203 if (varp == &p_enc)
5204 init_homedir();
5205# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 }
5207 }
5208#endif
5209
5210#if defined(FEAT_POSTSCRIPT)
5211 else if (varp == &p_penc)
5212 {
5213 /* Canonize printencoding if VIM standard one */
5214 p = enc_canonize(p_penc);
5215 if (p != NULL)
5216 {
5217 vim_free(p_penc);
5218 p_penc = p;
5219 }
5220 else
5221 {
5222 /* Ensure lower case and '-' for '_' */
5223 for (s = p_penc; *s != NUL; s++)
5224 {
5225 if (*s == '_')
5226 *s = '-';
5227 else
5228 *s = TOLOWER_ASC(*s);
5229 }
5230 }
5231 }
5232#endif
5233
Bram Moolenaar843ee412004-06-30 16:16:41 +00005234#if defined(FEAT_XIM) && ( defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005235 else if (varp == &p_imak)
5236 {
5237 if (gui.in_use && !im_xim_isvalid_imactivate())
5238 errmsg = e_invarg;
5239 }
5240#endif
5241
5242#ifdef FEAT_KEYMAP
5243 else if (varp == &curbuf->b_p_keymap)
5244 {
5245 /* load or unload key mapping tables */
5246 errmsg = keymap_init();
5247
5248 /* When successfully installed a new keymap switch on using it. */
5249 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5250 {
5251 curbuf->b_p_iminsert = B_IMODE_LMAP;
5252 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5253 curbuf->b_p_imsearch = B_IMODE_LMAP;
5254 set_iminsert_global();
5255 set_imsearch_global();
5256# ifdef FEAT_WINDOWS
5257 status_redraw_curbuf();
5258# endif
5259 }
5260 }
5261#endif
5262
5263 /* 'fileformat' */
5264 else if (gvarp == &p_ff)
5265 {
5266 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5267 errmsg = e_modifiable;
5268 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5269 errmsg = e_invarg;
5270 else
5271 {
5272 /* may also change 'textmode' */
5273 if (get_fileformat(curbuf) == EOL_DOS)
5274 curbuf->b_p_tx = TRUE;
5275 else
5276 curbuf->b_p_tx = FALSE;
5277#ifdef FEAT_TITLE
5278 need_maketitle = TRUE;
5279#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005280 /* update flag in swap file */
5281 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005282 }
5283 }
5284
5285 /* 'fileformats' */
5286 else if (varp == &p_ffs)
5287 {
5288 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5289 errmsg = e_invarg;
5290 else
5291 {
5292 /* also change 'textauto' */
5293 if (*p_ffs == NUL)
5294 p_ta = FALSE;
5295 else
5296 p_ta = TRUE;
5297 }
5298 }
5299
5300#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5301 /* 'cryptkey' */
5302 else if (gvarp == &p_key)
5303 {
5304 /* Make sure the ":set" command doesn't show the new value in the
5305 * history. */
5306 remove_key_from_history();
5307 }
5308#endif
5309
5310 /* 'matchpairs' */
5311 else if (gvarp == &p_mps)
5312 {
5313 /* Check for "x:y,x:y" */
5314 for (p = *varp; *p != NUL; p += 4)
5315 {
5316 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5317 {
5318 errmsg = e_invarg;
5319 break;
5320 }
5321 if (p[3] == NUL)
5322 break;
5323 }
5324 }
5325
5326#ifdef FEAT_COMMENTS
5327 /* 'comments' */
5328 else if (gvarp == &p_com)
5329 {
5330 for (s = *varp; *s; )
5331 {
5332 while (*s && *s != ':')
5333 {
5334 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5335 && !VIM_ISDIGIT(*s) && *s != '-')
5336 {
5337 errmsg = illegal_char(errbuf, *s);
5338 break;
5339 }
5340 ++s;
5341 }
5342 if (*s++ == NUL)
5343 errmsg = (char_u *)N_("E524: Missing colon");
5344 else if (*s == ',' || *s == NUL)
5345 errmsg = (char_u *)N_("E525: Zero length string");
5346 if (errmsg != NULL)
5347 break;
5348 while (*s && *s != ',')
5349 {
5350 if (*s == '\\' && s[1] != NUL)
5351 ++s;
5352 ++s;
5353 }
5354 s = skip_to_option_part(s);
5355 }
5356 }
5357#endif
5358
5359 /* 'listchars' */
5360 else if (varp == &p_lcs)
5361 {
5362 errmsg = set_chars_option(varp);
5363 }
5364
5365#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5366 /* 'fillchars' */
5367 else if (varp == &p_fcs)
5368 {
5369 errmsg = set_chars_option(varp);
5370 }
5371#endif
5372
5373#ifdef FEAT_CMDWIN
5374 /* 'cedit' */
5375 else if (varp == &p_cedit)
5376 {
5377 errmsg = check_cedit();
5378 }
5379#endif
5380
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005381 /* 'verbosefile' */
5382 else if (varp == &p_vfile)
5383 {
5384 verbose_stop();
5385 if (*p_vfile != NUL && verbose_open() == FAIL)
5386 errmsg = e_invarg;
5387 }
5388
Bram Moolenaar071d4272004-06-13 20:20:40 +00005389#ifdef FEAT_VIMINFO
5390 /* 'viminfo' */
5391 else if (varp == &p_viminfo)
5392 {
5393 for (s = p_viminfo; *s;)
5394 {
5395 /* Check it's a valid character */
5396 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5397 {
5398 errmsg = illegal_char(errbuf, *s);
5399 break;
5400 }
5401 if (*s == 'n') /* name is always last one */
5402 {
5403 break;
5404 }
5405 else if (*s == 'r') /* skip until next ',' */
5406 {
5407 while (*++s && *s != ',')
5408 ;
5409 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005410 else if (*s == '%')
5411 {
5412 /* optional number */
5413 while (vim_isdigit(*++s))
5414 ;
5415 }
5416 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005417 ++s; /* no extra chars */
5418 else /* must have a number */
5419 {
5420 while (vim_isdigit(*++s))
5421 ;
5422
5423 if (!VIM_ISDIGIT(*(s - 1)))
5424 {
5425 if (errbuf != NULL)
5426 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005427 sprintf((char *)errbuf,
5428 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005429 transchar_byte(*(s - 1)));
5430 errmsg = errbuf;
5431 }
5432 else
5433 errmsg = (char_u *)"";
5434 break;
5435 }
5436 }
5437 if (*s == ',')
5438 ++s;
5439 else if (*s)
5440 {
5441 if (errbuf != NULL)
5442 errmsg = (char_u *)N_("E527: Missing comma");
5443 else
5444 errmsg = (char_u *)"";
5445 break;
5446 }
5447 }
5448 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5449 errmsg = (char_u *)N_("E528: Must specify a ' value");
5450 }
5451#endif /* FEAT_VIMINFO */
5452
5453 /* terminal options */
5454 else if (istermoption(&options[opt_idx]) && full_screen)
5455 {
5456 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5457 if (varp == &T_CCO)
5458 {
5459 t_colors = atoi((char *)T_CCO);
5460 if (t_colors <= 1)
5461 {
5462 if (new_value_alloced)
5463 vim_free(T_CCO);
5464 T_CCO = empty_option;
5465 }
5466 /* We now have a different color setup, initialize it again. */
5467 init_highlight(TRUE, FALSE);
5468 }
5469 ttest(FALSE);
5470 if (varp == &T_ME)
5471 {
5472 out_str(T_ME);
5473 redraw_later(CLEAR);
5474#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5475 /* Since t_me has been set, this probably means that the user
5476 * wants to use this as default colors. Need to reset default
5477 * background/foreground colors. */
5478 mch_set_normal_colors();
5479#endif
5480 }
5481 }
5482
5483#ifdef FEAT_LINEBREAK
5484 /* 'showbreak' */
5485 else if (varp == &p_sbr)
5486 {
5487 for (s = p_sbr; *s; )
5488 {
5489 if (ptr2cells(s) != 1)
5490 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005491 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492 }
5493 }
5494#endif
5495
5496#ifdef FEAT_GUI
5497 /* 'guifont' */
5498 else if (varp == &p_guifont)
5499 {
5500 if (gui.in_use)
5501 {
5502 p = p_guifont;
Bram Moolenaar843ee412004-06-30 16:16:41 +00005503# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504 /*
5505 * Put up a font dialog and let the user select a new value.
5506 * If this is cancelled go back to the old value but don't
5507 * give an error message.
5508 */
5509 if (STRCMP(p, "*") == 0)
5510 {
5511 p = gui_mch_font_dialog(oldval);
5512
5513 if (new_value_alloced)
5514 free_string_option(p_guifont);
5515
5516 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5517 new_value_alloced = TRUE;
5518 }
5519# endif
5520 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5521 {
5522# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5523 if (STRCMP(p_guifont, "*") == 0)
5524 {
5525 /* Dialog was cancelled: Keep the old value without giving
5526 * an error message. */
5527 if (new_value_alloced)
5528 free_string_option(p_guifont);
5529 p_guifont = vim_strsave(oldval);
5530 new_value_alloced = TRUE;
5531 }
5532 else
5533# endif
5534 errmsg = (char_u *)N_("E596: Invalid font(s)");
5535 }
5536 }
5537 }
5538# ifdef FEAT_XFONTSET
5539 else if (varp == &p_guifontset)
5540 {
5541 if (STRCMP(p_guifontset, "*") == 0)
5542 errmsg = (char_u *)N_("E597: can't select fontset");
5543 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5544 errmsg = (char_u *)N_("E598: Invalid fontset");
5545 }
5546# endif
5547# ifdef FEAT_MBYTE
5548 else if (varp == &p_guifontwide)
5549 {
5550 if (STRCMP(p_guifontwide, "*") == 0)
5551 errmsg = (char_u *)N_("E533: can't select wide font");
5552 else if (gui_get_wide_font() == FAIL)
5553 errmsg = (char_u *)N_("E534: Invalid wide font");
5554 }
5555# endif
5556#endif
5557
5558#ifdef CURSOR_SHAPE
5559 /* 'guicursor' */
5560 else if (varp == &p_guicursor)
5561 errmsg = parse_shape_opt(SHAPE_CURSOR);
5562#endif
5563
5564#ifdef FEAT_MOUSESHAPE
5565 /* 'mouseshape' */
5566 else if (varp == &p_mouseshape)
5567 {
5568 errmsg = parse_shape_opt(SHAPE_MOUSE);
5569 update_mouseshape(-1);
5570 }
5571#endif
5572
5573#ifdef FEAT_PRINTER
5574 else if (varp == &p_popt)
Bram Moolenaar269ec652004-07-29 08:43:53 +00005575 errmsg = parse_list_options(p_popt, printer_opts,
5576 OPT_PRINT_NUM_OPTIONS);
Bram Moolenaar8299df92004-07-10 09:47:34 +00005577
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005578# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005579 else if (varp == &p_pmfn)
Bram Moolenaar269ec652004-07-29 08:43:53 +00005580 errmsg = parse_list_options(p_pmfn, mbfont_opts,
5581 OPT_MBFONT_NUM_OPTIONS);
Bram Moolenaar8299df92004-07-10 09:47:34 +00005582# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583#endif
5584
5585#ifdef FEAT_LANGMAP
5586 /* 'langmap' */
5587 else if (varp == &p_langmap)
5588 langmap_set();
5589#endif
5590
5591#ifdef FEAT_LINEBREAK
5592 /* 'breakat' */
5593 else if (varp == &p_breakat)
5594 fill_breakat_flags();
5595#endif
5596
5597#ifdef FEAT_TITLE
5598 /* 'titlestring' and 'iconstring' */
5599 else if (varp == &p_titlestring || varp == &p_iconstring)
5600 {
5601# ifdef FEAT_STL_OPT
5602 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5603
5604 /* NULL => statusline syntax */
5605 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5606 stl_syntax |= flagval;
5607 else
5608 stl_syntax &= ~flagval;
5609# endif
5610 did_set_title(varp == &p_iconstring);
5611
5612 }
5613#endif
5614
5615#ifdef FEAT_GUI
5616 /* 'guioptions' */
5617 else if (varp == &p_go)
5618 gui_init_which_components(oldval);
5619#endif
5620
5621#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5622 /* 'ttymouse' */
5623 else if (varp == &p_ttym)
5624 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00005625 /* Switch the mouse off before changing the escape sequences used for
5626 * that. */
5627 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5629 errmsg = e_invarg;
5630 else
5631 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00005632 if (termcap_active)
5633 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005634 }
5635#endif
5636
5637#ifdef FEAT_VISUAL
5638 /* 'selection' */
5639 else if (varp == &p_sel)
5640 {
5641 if (*p_sel == NUL
5642 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5643 errmsg = e_invarg;
5644 }
5645
5646 /* 'selectmode' */
5647 else if (varp == &p_slm)
5648 {
5649 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5650 errmsg = e_invarg;
5651 }
5652#endif
5653
5654#ifdef FEAT_BROWSE
5655 /* 'browsedir' */
5656 else if (varp == &p_bsdir)
5657 {
5658 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5659 && !mch_isdir(p_bsdir))
5660 errmsg = e_invarg;
5661 }
5662#endif
5663
5664#ifdef FEAT_VISUAL
5665 /* 'keymodel' */
5666 else if (varp == &p_km)
5667 {
5668 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5669 errmsg = e_invarg;
5670 else
5671 {
5672 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5673 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5674 }
5675 }
5676#endif
5677
5678 /* 'mousemodel' */
5679 else if (varp == &p_mousem)
5680 {
5681 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5682 errmsg = e_invarg;
5683#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5684 else if (*p_mousem != *oldval)
5685 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5686 * to create or delete the popup menus. */
5687 gui_motif_update_mousemodel(root_menu);
5688#endif
5689 }
5690
5691 /* 'switchbuf' */
5692 else if (varp == &p_swb)
5693 {
5694 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5695 errmsg = e_invarg;
5696 }
5697
5698 /* 'debug' */
5699 else if (varp == &p_debug)
5700 {
5701 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5702 errmsg = e_invarg;
5703 }
5704
5705 /* 'display' */
5706 else if (varp == &p_dy)
5707 {
5708 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5709 errmsg = e_invarg;
5710 else
5711 (void)init_chartab();
5712
5713 }
5714
5715#ifdef FEAT_VERTSPLIT
5716 /* 'eadirection' */
5717 else if (varp == &p_ead)
5718 {
5719 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5720 errmsg = e_invarg;
5721 }
5722#endif
5723
5724#ifdef FEAT_CLIPBOARD
5725 /* 'clipboard' */
5726 else if (varp == &p_cb)
5727 errmsg = check_clipboard_option();
5728#endif
5729
Bram Moolenaar217ad922005-03-20 22:37:15 +00005730#ifdef FEAT_SYN_HL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005731 /* When 'spelllang' or 'spellfile' is set and there is a window for this
5732 * buffer in which 'spell' is set load the wordlists. */
5733 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00005734 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005735 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005736 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005737
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005738 if (varp == &(curbuf->b_p_spf))
5739 {
5740 l = STRLEN(curbuf->b_p_spf);
5741 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
5742 ".add") != 0))
5743 errmsg = e_invarg;
5744 }
5745
5746 if (errmsg == NULL)
5747 {
5748 FOR_ALL_WINDOWS(wp)
5749 if (wp->w_buffer == curbuf && wp->w_p_spell)
5750 {
5751 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005752# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005753 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005754# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005755 }
5756 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005757 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005758 /* 'spellsuggest' */
5759 else if (varp == &p_sps)
5760 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005761 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005762 errmsg = e_invarg;
5763 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005764#endif
5765
Bram Moolenaar071d4272004-06-13 20:20:40 +00005766#ifdef FEAT_AUTOCMD
5767# ifdef FEAT_SYN_HL
5768 /* When 'syntax' is set, load the syntax of that name */
5769 else if (varp == &(curbuf->b_p_syn))
5770 {
5771 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
5772 curbuf->b_fname, TRUE, curbuf);
5773 }
5774# endif
5775
5776 /* When 'filetype' is set, trigger the FileType autocommands of that name */
5777 else if (varp == &(curbuf->b_p_ft))
5778 {
5779 did_filetype = TRUE;
5780 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
5781 curbuf->b_fname, TRUE, curbuf);
5782 }
5783#endif
5784
5785#ifdef FEAT_QUICKFIX
5786 /* When 'bufhidden' is set, check for valid value. */
5787 else if (gvarp == &p_bh)
5788 {
5789 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5790 errmsg = e_invarg;
5791 }
5792
5793 /* When 'buftype' is set, check for valid value. */
5794 else if (gvarp == &p_bt)
5795 {
5796 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5797 errmsg = e_invarg;
5798 else
5799 {
5800# ifdef FEAT_WINDOWS
5801 if (curwin->w_status_height)
5802 {
5803 curwin->w_redr_status = TRUE;
5804 redraw_later(VALID);
5805 }
5806# endif
5807 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5808 }
5809 }
5810#endif
5811
5812#ifdef FEAT_STL_OPT
5813 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005814 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005815 {
5816 int wid;
5817
5818 if (varp == &p_ruf) /* reset ru_wid first */
5819 ru_wid = 0;
5820 s = *varp;
5821 if (varp == &p_ruf && *s == '%')
5822 {
5823 /* set ru_wid if 'ruf' starts with "%99(" */
5824 if (*++s == '-') /* ignore a '-' */
5825 s++;
5826 wid = getdigits(&s);
5827 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5828 ru_wid = wid;
5829 else
5830 errmsg = check_stl_option(p_ruf);
5831 }
5832 else
5833 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005834 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005835 comp_col();
5836 }
5837#endif
5838
5839#ifdef FEAT_INS_EXPAND
5840 /* check if it is a valid value for 'complete' -- Acevedo */
5841 else if (gvarp == &p_cpt)
5842 {
5843 for (s = *varp; *s;)
5844 {
5845 while(*s == ',' || *s == ' ')
5846 s++;
5847 if (!*s)
5848 break;
5849 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5850 {
5851 errmsg = illegal_char(errbuf, *s);
5852 break;
5853 }
5854 if (*++s != NUL && *s != ',' && *s != ' ')
5855 {
5856 if (s[-1] == 'k' || s[-1] == 's')
5857 {
5858 /* skip optional filename after 'k' and 's' */
5859 while (*s && *s != ',' && *s != ' ')
5860 {
5861 if (*s == '\\')
5862 ++s;
5863 ++s;
5864 }
5865 }
5866 else
5867 {
5868 if (errbuf != NULL)
5869 {
5870 sprintf((char *)errbuf,
5871 _("E535: Illegal character after <%c>"),
5872 *--s);
5873 errmsg = errbuf;
5874 }
5875 else
5876 errmsg = (char_u *)"";
5877 break;
5878 }
5879 }
5880 }
5881 }
5882#endif /* FEAT_INS_EXPAND */
5883
5884
5885#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5886 else if (varp == &p_toolbar)
5887 {
5888 if (opt_strings_flags(p_toolbar, p_toolbar_values,
5889 &toolbar_flags, TRUE) != OK)
5890 errmsg = e_invarg;
5891 else
5892 {
5893 out_flush();
5894 gui_mch_show_toolbar((toolbar_flags &
5895 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5896 }
5897 }
5898#endif
5899
5900#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5901 /* 'toolbariconsize': GTK+ 2 only */
5902 else if (varp == &p_tbis)
5903 {
5904 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
5905 errmsg = e_invarg;
5906 else
5907 {
5908 out_flush();
5909 gui_mch_show_toolbar((toolbar_flags &
5910 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5911 }
5912 }
5913#endif
5914
5915 /* 'pastetoggle': translate key codes like in a mapping */
5916 else if (varp == &p_pt)
5917 {
5918 if (*p_pt)
5919 {
5920 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
5921 if (p != NULL)
5922 {
5923 if (new_value_alloced)
5924 free_string_option(p_pt);
5925 p_pt = p;
5926 new_value_alloced = TRUE;
5927 }
5928 }
5929 }
5930
5931 /* 'backspace' */
5932 else if (varp == &p_bs)
5933 {
5934 if (VIM_ISDIGIT(*p_bs))
5935 {
5936 if (*p_bs >'2' || p_bs[1] != NUL)
5937 errmsg = e_invarg;
5938 }
5939 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
5940 errmsg = e_invarg;
5941 }
5942
5943 /* 'casemap' */
5944 else if (varp == &p_cmp)
5945 {
5946 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
5947 errmsg = e_invarg;
5948 }
5949
5950#ifdef FEAT_DIFF
5951 /* 'diffopt' */
5952 else if (varp == &p_dip)
5953 {
5954 if (diffopt_changed() == FAIL)
5955 errmsg = e_invarg;
5956 }
5957#endif
5958
5959#ifdef FEAT_FOLDING
5960 /* 'foldmethod' */
5961 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
5962 {
5963 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
5964 || *curwin->w_p_fdm == NUL)
5965 errmsg = e_invarg;
5966 else
5967 foldUpdateAll(curwin);
5968 }
5969# ifdef FEAT_EVAL
5970 /* 'foldexpr' */
5971 else if (varp == &curwin->w_p_fde)
5972 {
5973 if (foldmethodIsExpr(curwin))
5974 foldUpdateAll(curwin);
5975 }
5976# endif
5977 /* 'foldmarker' */
5978 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
5979 {
5980 p = vim_strchr(*varp, ',');
5981 if (p == NULL)
5982 errmsg = (char_u *)N_("E536: comma required");
5983 else if (p == *varp || p[1] == NUL)
5984 errmsg = e_invarg;
5985 else if (foldmethodIsMarker(curwin))
5986 foldUpdateAll(curwin);
5987 }
5988 /* 'commentstring' */
5989 else if (gvarp == &p_cms)
5990 {
5991 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
5992 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
5993 }
5994 /* 'foldopen' */
5995 else if (varp == &p_fdo)
5996 {
5997 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
5998 errmsg = e_invarg;
5999 }
6000 /* 'foldclose' */
6001 else if (varp == &p_fcl)
6002 {
6003 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6004 errmsg = e_invarg;
6005 }
6006#endif
6007
6008#ifdef FEAT_VIRTUALEDIT
6009 /* 'virtualedit' */
6010 else if (varp == &p_ve)
6011 {
6012 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6013 errmsg = e_invarg;
6014 else if (STRCMP(p_ve, oldval) != 0)
6015 {
6016 /* Recompute cursor position in case the new 've' setting
6017 * changes something. */
6018 validate_virtcol();
6019 coladvance(curwin->w_virtcol);
6020 }
6021 }
6022#endif
6023
6024#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6025 else if (varp == &p_csqf)
6026 {
6027 if (p_csqf != NULL)
6028 {
6029 p = p_csqf;
6030 while (*p != NUL)
6031 {
6032 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6033 || p[1] == NUL
6034 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6035 || (p[2] != NUL && p[2] != ','))
6036 {
6037 errmsg = e_invarg;
6038 break;
6039 }
6040 else if (p[2] == NUL)
6041 break;
6042 else
6043 p += 3;
6044 }
6045 }
6046 }
6047#endif
6048
6049 /* Options that are a list of flags. */
6050 else
6051 {
6052 p = NULL;
6053 if (varp == &p_ww)
6054 p = (char_u *)WW_ALL;
6055 if (varp == &p_shm)
6056 p = (char_u *)SHM_ALL;
6057 else if (varp == &(p_cpo))
6058 p = (char_u *)CPO_ALL;
6059 else if (varp == &(curbuf->b_p_fo))
6060 p = (char_u *)FO_ALL;
6061 else if (varp == &p_mouse)
6062 {
6063#ifdef FEAT_MOUSE
6064 p = (char_u *)MOUSE_ALL;
6065#else
6066 if (*p_mouse != NUL)
6067 errmsg = (char_u *)N_("E538: No mouse support");
6068#endif
6069 }
6070#if defined(FEAT_GUI)
6071 else if (varp == &p_go)
6072 p = (char_u *)GO_ALL;
6073#endif
6074 if (p != NULL)
6075 {
6076 for (s = *varp; *s; ++s)
6077 if (vim_strchr(p, *s) == NULL)
6078 {
6079 errmsg = illegal_char(errbuf, *s);
6080 break;
6081 }
6082 }
6083 }
6084
6085 /*
6086 * If error detected, restore the previous value.
6087 */
6088 if (errmsg != NULL)
6089 {
6090 if (new_value_alloced)
6091 free_string_option(*varp);
6092 *varp = oldval;
6093 /*
6094 * When resetting some values, need to act on it.
6095 */
6096 if (did_chartab)
6097 (void)init_chartab();
6098 if (varp == &p_hl)
6099 (void)highlight_changed();
6100 }
6101 else
6102 {
6103#ifdef FEAT_EVAL
6104 /* Remember where the option was set. */
6105 options[opt_idx].scriptID = current_SID;
6106#endif
6107 /*
6108 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006109 * Use "free_oldval", because recursiveness may change the flags under
6110 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006112 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 free_string_option(oldval);
6114 if (new_value_alloced)
6115 options[opt_idx].flags |= P_ALLOCED;
6116 else
6117 options[opt_idx].flags &= ~P_ALLOCED;
6118
6119 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6120 && (int)options[opt_idx].indir >= PV_BOTH)
6121 {
6122 /* global option with local value set to use global value; free
6123 * the local value and make it empty */
6124 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6125 free_string_option(*(char_u **)p);
6126 *(char_u **)p = empty_option;
6127 }
6128
6129 /* May set global value for local option. */
6130 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6131 set_string_option_global(opt_idx, varp);
6132 }
6133
6134#ifdef FEAT_MOUSE
6135 if (varp == &p_mouse)
6136 {
6137# ifdef FEAT_MOUSE_TTY
6138 if (*p_mouse == NUL)
6139 mch_setmouse(FALSE); /* switch mouse off */
6140 else
6141# endif
6142 setmouse(); /* in case 'mouse' changed */
6143 }
6144#endif
6145
6146 if (curwin->w_curswant != MAXCOL)
6147 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6148 check_redraw(options[opt_idx].flags);
6149
6150 return errmsg;
6151}
6152
6153/*
6154 * Handle setting 'listchars' or 'fillchars'.
6155 * Returns error message, NULL if it's OK.
6156 */
6157 static char_u *
6158set_chars_option(varp)
6159 char_u **varp;
6160{
6161 int round, i, len, entries;
6162 char_u *p, *s;
6163 int c1, c2 = 0;
6164 struct charstab
6165 {
6166 int *cp;
6167 char *name;
6168 };
6169#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6170 static struct charstab filltab[] =
6171 {
6172 {&fill_stl, "stl"},
6173 {&fill_stlnc, "stlnc"},
6174 {&fill_vert, "vert"},
6175 {&fill_fold, "fold"},
6176 {&fill_diff, "diff"},
6177 };
6178#endif
6179 static struct charstab lcstab[] =
6180 {
6181 {&lcs_eol, "eol"},
6182 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006183 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184 {&lcs_prec, "precedes"},
6185 {&lcs_tab2, "tab"},
6186 {&lcs_trail, "trail"},
6187 };
6188 struct charstab *tab;
6189
6190#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6191 if (varp == &p_lcs)
6192#endif
6193 {
6194 tab = lcstab;
6195 entries = sizeof(lcstab) / sizeof(struct charstab);
6196 }
6197#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6198 else
6199 {
6200 tab = filltab;
6201 entries = sizeof(filltab) / sizeof(struct charstab);
6202 }
6203#endif
6204
6205 /* first round: check for valid value, second round: assign values */
6206 for (round = 0; round <= 1; ++round)
6207 {
6208 if (round)
6209 {
6210 /* After checking that the value is valid: set defaults: space for
6211 * 'fillchars', NUL for 'listchars' */
6212 for (i = 0; i < entries; ++i)
6213 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6214 if (varp == &p_lcs)
6215 lcs_tab1 = NUL;
6216#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6217 else
6218 fill_diff = '-';
6219#endif
6220 }
6221 p = *varp;
6222 while (*p)
6223 {
6224 for (i = 0; i < entries; ++i)
6225 {
6226 len = (int)STRLEN(tab[i].name);
6227 if (STRNCMP(p, tab[i].name, len) == 0
6228 && p[len] == ':'
6229 && p[len + 1] != NUL)
6230 {
6231 s = p + len + 1;
6232#ifdef FEAT_MBYTE
6233 c1 = mb_ptr2char_adv(&s);
6234#else
6235 c1 = *s++;
6236#endif
6237 if (tab[i].cp == &lcs_tab2)
6238 {
6239 if (*s == NUL)
6240 continue;
6241#ifdef FEAT_MBYTE
6242 c2 = mb_ptr2char_adv(&s);
6243#else
6244 c2 = *s++;
6245#endif
6246 }
6247 if (*s == ',' || *s == NUL)
6248 {
6249 if (round)
6250 {
6251 if (tab[i].cp == &lcs_tab2)
6252 {
6253 lcs_tab1 = c1;
6254 lcs_tab2 = c2;
6255 }
6256 else
6257 *(tab[i].cp) = c1;
6258
6259 }
6260 p = s;
6261 break;
6262 }
6263 }
6264 }
6265
6266 if (i == entries)
6267 return e_invarg;
6268 if (*p == ',')
6269 ++p;
6270 }
6271 }
6272
6273 return NULL; /* no error */
6274}
6275
6276#ifdef FEAT_STL_OPT
6277/*
6278 * Check validity of options with the 'statusline' format.
6279 * Return error message or NULL.
6280 */
6281 char_u *
6282check_stl_option(s)
6283 char_u *s;
6284{
6285 int itemcnt = 0;
6286 int groupdepth = 0;
6287 static char_u errbuf[80];
6288
6289 while (*s && itemcnt < STL_MAX_ITEM)
6290 {
6291 /* Check for valid keys after % sequences */
6292 while (*s && *s != '%')
6293 s++;
6294 if (!*s)
6295 break;
6296 s++;
6297 if (*s != '%' && *s != ')')
6298 ++itemcnt;
6299 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6300 {
6301 s++;
6302 continue;
6303 }
6304 if (*s == ')')
6305 {
6306 s++;
6307 if (--groupdepth < 0)
6308 break;
6309 continue;
6310 }
6311 if (*s == '-')
6312 s++;
6313 while (VIM_ISDIGIT(*s))
6314 s++;
6315 if (*s == STL_HIGHLIGHT)
6316 continue;
6317 if (*s == '.')
6318 {
6319 s++;
6320 while (*s && VIM_ISDIGIT(*s))
6321 s++;
6322 }
6323 if (*s == '(')
6324 {
6325 groupdepth++;
6326 continue;
6327 }
6328 if (vim_strchr(STL_ALL, *s) == NULL)
6329 {
6330 return illegal_char(errbuf, *s);
6331 }
6332 if (*s == '{')
6333 {
6334 s++;
6335 while (*s != '}' && *s)
6336 s++;
6337 if (*s != '}')
6338 return (char_u *)N_("E540: Unclosed expression sequence");
6339 }
6340 }
6341 if (itemcnt >= STL_MAX_ITEM)
6342 return (char_u *)N_("E541: too many items");
6343 if (groupdepth != 0)
6344 return (char_u *)N_("E542: unbalanced groups");
6345 return NULL;
6346}
6347#endif
6348
6349#ifdef FEAT_CLIPBOARD
6350/*
6351 * Extract the items in the 'clipboard' option and set global values.
6352 */
6353 static char_u *
6354check_clipboard_option()
6355{
6356 int new_unnamed = FALSE;
6357 int new_autoselect = FALSE;
6358 int new_autoselectml = FALSE;
6359 regprog_T *new_exclude_prog = NULL;
6360 char_u *errmsg = NULL;
6361 char_u *p;
6362
6363 for (p = p_cb; *p != NUL; )
6364 {
6365 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6366 {
6367 new_unnamed = TRUE;
6368 p += 7;
6369 }
6370 else if (STRNCMP(p, "autoselect", 10) == 0
6371 && (p[10] == ',' || p[10] == NUL))
6372 {
6373 new_autoselect = TRUE;
6374 p += 10;
6375 }
6376 else if (STRNCMP(p, "autoselectml", 12) == 0
6377 && (p[12] == ',' || p[12] == NUL))
6378 {
6379 new_autoselectml = TRUE;
6380 p += 12;
6381 }
6382 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6383 {
6384 p += 8;
6385 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6386 if (new_exclude_prog == NULL)
6387 errmsg = e_invarg;
6388 break;
6389 }
6390 else
6391 {
6392 errmsg = e_invarg;
6393 break;
6394 }
6395 if (*p == ',')
6396 ++p;
6397 }
6398 if (errmsg == NULL)
6399 {
6400 clip_unnamed = new_unnamed;
6401 clip_autoselect = new_autoselect;
6402 clip_autoselectml = new_autoselectml;
6403 vim_free(clip_exclude_prog);
6404 clip_exclude_prog = new_exclude_prog;
6405 }
6406 else
6407 vim_free(new_exclude_prog);
6408
6409 return errmsg;
6410}
6411#endif
6412
6413/*
6414 * Set the value of a boolean option, and take care of side effects.
6415 * Returns NULL for success, or an error message for an error.
6416 */
6417 static char_u *
6418set_bool_option(opt_idx, varp, value, opt_flags)
6419 int opt_idx; /* index in options[] table */
6420 char_u *varp; /* pointer to the option variable */
6421 int value; /* new value */
6422 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6423{
6424 int old_value = *(int *)varp;
6425
6426#ifdef FEAT_GUI
6427 need_mouse_correct = TRUE;
6428#endif
6429
6430 /* Disallow changing some options from secure mode */
6431 if ((secure
6432#ifdef HAVE_SANDBOX
6433 || sandbox != 0
6434#endif
6435 ) && (options[opt_idx].flags & P_SECURE))
6436 return e_secure;
6437
6438 *(int *)varp = value; /* set the new value */
6439#ifdef FEAT_EVAL
6440 /* Remember where the option was set. */
6441 options[opt_idx].scriptID = current_SID;
6442#endif
6443
6444 /* May set global value for local option. */
6445 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6446 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6447
6448 /*
6449 * Handle side effects of changing a bool option.
6450 */
6451
6452 /* 'compatible' */
6453 if ((int *)varp == &p_cp)
6454 {
6455 compatible_set();
6456 }
6457
6458 /* when 'readonly' is reset globally, also reset readonlymode */
6459 else if ((int *)varp == &curbuf->b_p_ro)
6460 {
6461 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6462 readonlymode = FALSE;
6463#ifdef FEAT_TITLE
6464 need_maketitle = TRUE;
6465#endif
6466 }
6467
6468#ifdef FEAT_TITLE
6469 /* when 'modifiable' is changed, redraw the window title */
6470 else if ((int *)varp == &curbuf->b_p_ma)
6471 need_maketitle = TRUE;
6472 /* when 'endofline' is changed, redraw the window title */
6473 else if ((int *)varp == &curbuf->b_p_eol)
6474 need_maketitle = TRUE;
6475#endif
6476
6477 /* when 'bin' is set also set some other options */
6478 else if ((int *)varp == &curbuf->b_p_bin)
6479 {
6480 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6481#ifdef FEAT_TITLE
6482 need_maketitle = TRUE;
6483#endif
6484 }
6485
6486#ifdef FEAT_AUTOCMD
6487 /* when 'buflisted' changes, trigger autocommands */
6488 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6489 {
6490 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6491 NULL, NULL, TRUE, curbuf);
6492 }
6493#endif
6494
6495 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6496 else if ((int *)varp == &curbuf->b_p_swf)
6497 {
6498 if (curbuf->b_p_swf && p_uc)
6499 ml_open_file(curbuf); /* create the swap file */
6500 else
6501 mf_close_file(curbuf, TRUE); /* remove the swap file */
6502 }
6503
6504 /* when 'terse' is set change 'shortmess' */
6505 else if ((int *)varp == &p_terse)
6506 {
6507 char_u *p;
6508
6509 p = vim_strchr(p_shm, SHM_SEARCH);
6510
6511 /* insert 's' in p_shm */
6512 if (p_terse && p == NULL)
6513 {
6514 STRCPY(IObuff, p_shm);
6515 STRCAT(IObuff, "s");
6516 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6517 }
6518 /* remove 's' from p_shm */
6519 else if (!p_terse && p != NULL)
6520 mch_memmove(p, p + 1, STRLEN(p));
6521 }
6522
6523 /* when 'paste' is set or reset also change other options */
6524 else if ((int *)varp == &p_paste)
6525 {
6526 paste_option_changed();
6527 }
6528
6529 /* when 'insertmode' is set from an autocommand need to do work here */
6530 else if ((int *)varp == &p_im)
6531 {
6532 if (p_im)
6533 {
6534 if ((State & INSERT) == 0)
6535 need_start_insertmode = TRUE;
6536 stop_insert_mode = FALSE;
6537 }
6538 else
6539 {
6540 need_start_insertmode = FALSE;
6541 stop_insert_mode = TRUE;
6542 if (p_smd && restart_edit != 0)
6543 clear_cmdline = TRUE; /* remove "(insert)" */
6544 restart_edit = 0;
6545 }
6546 }
6547
6548 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6549 else if ((int *)varp == &p_ic && p_hls)
6550 {
6551 redraw_all_later(NOT_VALID);
6552 }
6553
6554#ifdef FEAT_SEARCH_EXTRA
6555 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6556 else if ((int *)varp == &p_hls)
6557 {
6558 no_hlsearch = FALSE;
6559 }
6560#endif
6561
6562#ifdef FEAT_SCROLLBIND
6563 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6564 * at the end of normal_cmd() */
6565 else if ((int *)varp == &curwin->w_p_scb)
6566 {
6567 if (curwin->w_p_scb)
6568 do_check_scrollbind(FALSE);
6569 }
6570#endif
6571
6572#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6573 /* There can be only one window with 'previewwindow' set. */
6574 else if ((int *)varp == &curwin->w_p_pvw)
6575 {
6576 if (curwin->w_p_pvw)
6577 {
6578 win_T *win;
6579
6580 for (win = firstwin; win != NULL; win = win->w_next)
6581 if (win->w_p_pvw && win != curwin)
6582 {
6583 curwin->w_p_pvw = FALSE;
6584 return (char_u *)N_("E590: A preview window already exists");
6585 }
6586 }
6587 }
6588#endif
6589
6590 /* when 'textmode' is set or reset also change 'fileformat' */
6591 else if ((int *)varp == &curbuf->b_p_tx)
6592 {
6593 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6594 }
6595
6596 /* when 'textauto' is set or reset also change 'fileformats' */
6597 else if ((int *)varp == &p_ta)
6598 {
6599 set_string_option_direct((char_u *)"ffs", -1,
6600 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6601 OPT_FREE | opt_flags);
6602 }
6603
6604 /*
6605 * When 'lisp' option changes include/exclude '-' in
6606 * keyword characters.
6607 */
6608#ifdef FEAT_LISP
6609 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6610 {
6611 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6612 }
6613#endif
6614
6615#ifdef FEAT_TITLE
6616 /* when 'title' changed, may need to change the title; same for 'icon' */
6617 else if ((int *)varp == &p_title)
6618 {
6619 did_set_title(FALSE);
6620 }
6621
6622 else if ((int *)varp == &p_icon)
6623 {
6624 did_set_title(TRUE);
6625 }
6626#endif
6627
6628 else if ((int *)varp == &curbuf->b_changed)
6629 {
6630 if (!value)
6631 save_file_ff(curbuf); /* Buffer is unchanged */
6632#ifdef FEAT_TITLE
6633 need_maketitle = TRUE;
6634#endif
6635#ifdef FEAT_AUTOCMD
6636 modified_was_set = value;
6637#endif
6638 }
6639
6640#ifdef BACKSLASH_IN_FILENAME
6641 else if ((int *)varp == &p_ssl)
6642 {
6643 if (p_ssl)
6644 {
6645 psepc = '/';
6646 psepcN = '\\';
6647 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006648 }
6649 else
6650 {
6651 psepc = '\\';
6652 psepcN = '/';
6653 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 }
6655
6656 /* need to adjust the file name arguments and buffer names. */
6657 buflist_slash_adjust();
6658 alist_slash_adjust();
6659# ifdef FEAT_EVAL
6660 scriptnames_slash_adjust();
6661# endif
6662 }
6663#endif
6664
6665 /* If 'wrap' is set, set w_leftcol to zero. */
6666 else if ((int *)varp == &curwin->w_p_wrap)
6667 {
6668 if (curwin->w_p_wrap)
6669 curwin->w_leftcol = 0;
6670 }
6671
6672#ifdef FEAT_WINDOWS
6673 else if ((int *)varp == &p_ea)
6674 {
6675 if (p_ea && !old_value)
6676 win_equal(curwin, FALSE, 0);
6677 }
6678#endif
6679
6680 else if ((int *)varp == &p_wiv)
6681 {
6682 /*
6683 * When 'weirdinvert' changed, set/reset 't_xs'.
6684 * Then set 'weirdinvert' according to value of 't_xs'.
6685 */
6686 if (p_wiv && !old_value)
6687 T_XS = (char_u *)"y";
6688 else if (!p_wiv && old_value)
6689 T_XS = empty_option;
6690 p_wiv = (*T_XS != NUL);
6691 }
6692
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006693#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00006694 else if ((int *)varp == &p_beval)
6695 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696 if (p_beval == TRUE)
6697 gui_mch_enable_beval_area(balloonEval);
6698 else
6699 gui_mch_disable_beval_area(balloonEval);
6700 }
6701
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006702# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006703 else if ((int *)varp == &p_acd)
6704 {
6705 if (p_acd && curbuf->b_ffname != NULL
6706 && vim_chdirfile(curbuf->b_ffname) == OK)
6707 shorten_fnames(TRUE);
6708 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006709# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006710#endif
6711
6712#ifdef FEAT_DIFF
6713 /* 'diff' */
6714 else if ((int *)varp == &curwin->w_p_diff)
6715 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006716 /* May add or remove the buffer from the list of diff buffers. */
6717 diff_buf_adjust(curwin);
6718# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719 if (foldmethodIsDiff(curwin))
6720 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006721# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722 }
6723#endif
6724
6725#ifdef USE_IM_CONTROL
6726 /* 'imdisable' */
6727 else if ((int *)varp == &p_imdisable)
6728 {
6729 /* Only de-activate it here, it will be enabled when changing mode. */
6730 if (p_imdisable)
6731 im_set_active(FALSE);
6732 }
6733#endif
6734
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006735#ifdef FEAT_SYN_HL
6736 /* 'spell' */
6737 else if ((int *)varp == &curwin->w_p_spell)
6738 {
6739 if (curwin->w_p_spell)
6740 {
6741 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00006742
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006743 if (errmsg != NULL)
6744 EMSG(_(errmsg));
6745 }
6746 }
6747#endif
6748
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749#ifdef FEAT_FKMAP
6750 else if ((int *)varp == &p_altkeymap)
6751 {
6752 if (old_value != p_altkeymap)
6753 {
6754 if (!p_altkeymap)
6755 {
6756 p_hkmap = p_fkmap;
6757 p_fkmap = 0;
6758 }
6759 else
6760 {
6761 p_fkmap = p_hkmap;
6762 p_hkmap = 0;
6763 }
6764 (void)init_chartab();
6765 }
6766 }
6767
6768 /*
6769 * In case some second language keymapping options have changed, check
6770 * and correct the setting in a consistent way.
6771 */
6772
6773 /*
6774 * If hkmap or fkmap are set, reset Arabic keymapping.
6775 */
6776 if ((p_hkmap || p_fkmap) && p_altkeymap)
6777 {
6778 p_altkeymap = p_fkmap;
6779# ifdef FEAT_ARABIC
6780 curwin->w_p_arab = FALSE;
6781# endif
6782 (void)init_chartab();
6783 }
6784
6785 /*
6786 * If hkmap set, reset Farsi keymapping.
6787 */
6788 if (p_hkmap && p_altkeymap)
6789 {
6790 p_altkeymap = 0;
6791 p_fkmap = 0;
6792# ifdef FEAT_ARABIC
6793 curwin->w_p_arab = FALSE;
6794# endif
6795 (void)init_chartab();
6796 }
6797
6798 /*
6799 * If fkmap set, reset Hebrew keymapping.
6800 */
6801 if (p_fkmap && !p_altkeymap)
6802 {
6803 p_altkeymap = 1;
6804 p_hkmap = 0;
6805# ifdef FEAT_ARABIC
6806 curwin->w_p_arab = FALSE;
6807# endif
6808 (void)init_chartab();
6809 }
6810#endif
6811
6812#ifdef FEAT_ARABIC
6813 if ((int *)varp == &curwin->w_p_arab)
6814 {
6815 if (curwin->w_p_arab)
6816 {
6817 /*
6818 * 'arabic' is set, handle various sub-settings.
6819 */
6820 if (!p_tbidi)
6821 {
6822 /* set rightleft mode */
6823 if (!curwin->w_p_rl)
6824 {
6825 curwin->w_p_rl = TRUE;
6826 changed_window_setting();
6827 }
6828
6829 /* Enable Arabic shaping (major part of what Arabic requires) */
6830 if (!p_arshape)
6831 {
6832 p_arshape = TRUE;
6833 redraw_later_clear();
6834 }
6835 }
6836
6837 /* Arabic requires a utf-8 encoding, inform the user if its not
6838 * set. */
6839 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006840 {
6841 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6843 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006844 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845
6846# ifdef FEAT_MBYTE
6847 /* set 'delcombine' */
6848 p_deco = TRUE;
6849# endif
6850
6851# ifdef FEAT_KEYMAP
6852 /* Force-set the necessary keymap for arabic */
6853 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
6854 OPT_LOCAL);
6855# endif
6856# ifdef FEAT_FKMAP
6857 p_altkeymap = 0;
6858 p_hkmap = 0;
6859 p_fkmap = 0;
6860 (void)init_chartab();
6861# endif
6862 }
6863 else
6864 {
6865 /*
6866 * 'arabic' is reset, handle various sub-settings.
6867 */
6868 if (!p_tbidi)
6869 {
6870 /* reset rightleft mode */
6871 if (curwin->w_p_rl)
6872 {
6873 curwin->w_p_rl = FALSE;
6874 changed_window_setting();
6875 }
6876
6877 /* 'arabicshape' isn't reset, it is a global option and
6878 * another window may still need it "on". */
6879 }
6880
6881 /* 'delcombine' isn't reset, it is a global option and another
6882 * window may still want it "on". */
6883
6884# ifdef FEAT_KEYMAP
6885 /* Revert to the default keymap */
6886 curbuf->b_p_iminsert = B_IMODE_NONE;
6887 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6888# endif
6889 }
6890 }
6891#endif
6892
6893 /*
6894 * End of handling side effects for bool options.
6895 */
6896
6897 options[opt_idx].flags |= P_WAS_SET;
6898
6899 comp_col(); /* in case 'ruler' or 'showcmd' changed */
6900 if (curwin->w_curswant != MAXCOL)
6901 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
6902 check_redraw(options[opt_idx].flags);
6903
6904 return NULL;
6905}
6906
6907/*
6908 * Set the value of a number option, and take care of side effects.
6909 * Returns NULL for success, or an error message for an error.
6910 */
6911 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00006912set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006913 int opt_idx; /* index in options[] table */
6914 char_u *varp; /* pointer to the option variable */
6915 long value; /* new value */
6916 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00006917 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
6919 OPT_MODELINE */
6920{
6921 char_u *errmsg = NULL;
6922 long old_value = *(long *)varp;
6923 long old_Rows = Rows; /* remember old Rows */
6924 long old_Columns = Columns; /* remember old Columns */
6925 long *pp = (long *)varp;
6926
6927#ifdef FEAT_GUI
6928 need_mouse_correct = TRUE;
6929#endif
6930
6931 *pp = value;
6932#ifdef FEAT_EVAL
6933 /* Remember where the option was set. */
6934 options[opt_idx].scriptID = current_SID;
6935#endif
6936
6937 if (curbuf->b_p_sw <= 0)
6938 {
6939 errmsg = e_positive;
6940 curbuf->b_p_sw = curbuf->b_p_ts;
6941 }
6942
6943 /*
6944 * Number options that need some action when changed
6945 */
6946#ifdef FEAT_WINDOWS
6947 if (pp == &p_wh || pp == &p_hh)
6948 {
6949 if (p_wh < 1)
6950 {
6951 errmsg = e_positive;
6952 p_wh = 1;
6953 }
6954 if (p_wmh > p_wh)
6955 {
6956 errmsg = e_winheight;
6957 p_wh = p_wmh;
6958 }
6959 if (p_hh < 0)
6960 {
6961 errmsg = e_positive;
6962 p_hh = 0;
6963 }
6964
6965 /* Change window height NOW */
6966 if (lastwin != firstwin)
6967 {
6968 if (pp == &p_wh && curwin->w_height < p_wh)
6969 win_setheight((int)p_wh);
6970 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
6971 win_setheight((int)p_hh);
6972 }
6973 }
6974
6975 /* 'winminheight' */
6976 else if (pp == &p_wmh)
6977 {
6978 if (p_wmh < 0)
6979 {
6980 errmsg = e_positive;
6981 p_wmh = 0;
6982 }
6983 if (p_wmh > p_wh)
6984 {
6985 errmsg = e_winheight;
6986 p_wmh = p_wh;
6987 }
6988 win_setminheight();
6989 }
6990
6991# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006992 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 {
6994 if (p_wiw < 1)
6995 {
6996 errmsg = e_positive;
6997 p_wiw = 1;
6998 }
6999 if (p_wmw > p_wiw)
7000 {
7001 errmsg = e_winwidth;
7002 p_wiw = p_wmw;
7003 }
7004
7005 /* Change window width NOW */
7006 if (lastwin != firstwin && curwin->w_width < p_wiw)
7007 win_setwidth((int)p_wiw);
7008 }
7009
7010 /* 'winminwidth' */
7011 else if (pp == &p_wmw)
7012 {
7013 if (p_wmw < 0)
7014 {
7015 errmsg = e_positive;
7016 p_wmw = 0;
7017 }
7018 if (p_wmw > p_wiw)
7019 {
7020 errmsg = e_winwidth;
7021 p_wmw = p_wiw;
7022 }
7023 win_setminheight();
7024 }
7025# endif
7026
7027#endif
7028
7029#ifdef FEAT_WINDOWS
7030 /* (re)set last window status line */
7031 else if (pp == &p_ls)
7032 {
7033 last_status(FALSE);
7034 }
7035#endif
7036
7037#ifdef FEAT_GUI
7038 else if (pp == &p_linespace)
7039 {
7040 if (gui.in_use && gui_mch_adjust_charsize() == OK)
7041 gui_set_shellsize(FALSE, FALSE);
7042 }
7043#endif
7044
7045#ifdef FEAT_FOLDING
7046 /* 'foldlevel' */
7047 else if (pp == &curwin->w_p_fdl)
7048 {
7049 if (curwin->w_p_fdl < 0)
7050 curwin->w_p_fdl = 0;
7051 newFoldLevel();
7052 }
7053
7054 /* 'foldminlevel' */
7055 else if (pp == &curwin->w_p_fml)
7056 {
7057 foldUpdateAll(curwin);
7058 }
7059
7060 /* 'foldnestmax' */
7061 else if (pp == &curwin->w_p_fdn)
7062 {
7063 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7064 foldUpdateAll(curwin);
7065 }
7066
7067 /* 'foldcolumn' */
7068 else if (pp == &curwin->w_p_fdc)
7069 {
7070 if (curwin->w_p_fdc < 0)
7071 {
7072 errmsg = e_positive;
7073 curwin->w_p_fdc = 0;
7074 }
7075 else if (curwin->w_p_fdc > 12)
7076 {
7077 errmsg = e_invarg;
7078 curwin->w_p_fdc = 12;
7079 }
7080 }
7081
7082 /* 'shiftwidth' or 'tabstop' */
7083 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7084 {
7085 if (foldmethodIsIndent(curwin))
7086 foldUpdateAll(curwin);
7087 }
7088#endif /* FEAT_FOLDING */
7089
7090 else if (pp == &curbuf->b_p_iminsert)
7091 {
7092 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7093 {
7094 errmsg = e_invarg;
7095 curbuf->b_p_iminsert = B_IMODE_NONE;
7096 }
7097 p_iminsert = curbuf->b_p_iminsert;
7098 if (termcap_active) /* don't do this in the alternate screen */
7099 showmode();
7100#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7101 /* Show/unshow value of 'keymap' in status lines. */
7102 status_redraw_curbuf();
7103#endif
7104 }
7105
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007106 else if (pp == &p_window)
7107 {
7108 if (p_window < 1)
7109 p_window = 1;
7110 else if (p_window >= Rows)
7111 p_window = Rows - 1;
7112 }
7113
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114 else if (pp == &curbuf->b_p_imsearch)
7115 {
7116 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7117 {
7118 errmsg = e_invarg;
7119 curbuf->b_p_imsearch = B_IMODE_NONE;
7120 }
7121 p_imsearch = curbuf->b_p_imsearch;
7122 }
7123
7124#ifdef FEAT_TITLE
7125 /* if 'titlelen' has changed, redraw the title */
7126 else if (pp == &p_titlelen)
7127 {
7128 if (p_titlelen < 0)
7129 {
7130 errmsg = e_positive;
7131 p_titlelen = 85;
7132 }
7133 if (starting != NO_SCREEN && old_value != p_titlelen)
7134 need_maketitle = TRUE;
7135 }
7136#endif
7137
7138 /* if p_ch changed value, change the command line height */
7139 else if (pp == &p_ch)
7140 {
7141 if (p_ch < 1)
7142 {
7143 errmsg = e_positive;
7144 p_ch = 1;
7145 }
7146
7147 /* Only compute the new window layout when startup has been
7148 * completed. Otherwise the frame sizes may be wrong. */
7149 if (p_ch != old_value && full_screen
7150#ifdef FEAT_GUI
7151 && !gui.starting
7152#endif
7153 )
7154 command_height(old_value);
7155 }
7156
7157 /* when 'updatecount' changes from zero to non-zero, open swap files */
7158 else if (pp == &p_uc)
7159 {
7160 if (p_uc < 0)
7161 {
7162 errmsg = e_positive;
7163 p_uc = 100;
7164 }
7165 if (p_uc && !old_value)
7166 ml_open_files();
7167 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007168#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007169 else if (pp == &p_mzq)
7170 mzvim_reset_timer();
7171#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007172
7173 /* sync undo before 'undolevels' changes */
7174 else if (pp == &p_ul)
7175 {
7176 /* use the old value, otherwise u_sync() may not work properly */
7177 p_ul = old_value;
7178 u_sync();
7179 p_ul = value;
7180 }
7181
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007182#ifdef FEAT_LINEBREAK
7183 /* 'numberwidth' must be positive */
7184 else if (pp == &curwin->w_p_nuw)
7185 {
7186 if (curwin->w_p_nuw < 1)
7187 {
7188 errmsg = e_positive;
7189 curwin->w_p_nuw = 1;
7190 }
7191 if (curwin->w_p_nuw > 10)
7192 {
7193 errmsg = e_invarg;
7194 curwin->w_p_nuw = 10;
7195 }
7196 curwin->w_nrwidth_line_count = 0;
7197 }
7198#endif
7199
Bram Moolenaar071d4272004-06-13 20:20:40 +00007200 /*
7201 * Check the bounds for numeric options here
7202 */
7203 if (Rows < min_rows() && full_screen)
7204 {
7205 if (errbuf != NULL)
7206 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007207 vim_snprintf((char *)errbuf, errbuflen,
7208 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209 errmsg = errbuf;
7210 }
7211 Rows = min_rows();
7212 }
7213 if (Columns < MIN_COLUMNS && full_screen)
7214 {
7215 if (errbuf != NULL)
7216 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007217 vim_snprintf((char *)errbuf, errbuflen,
7218 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007219 errmsg = errbuf;
7220 }
7221 Columns = MIN_COLUMNS;
7222 }
7223
7224#ifdef DJGPP
7225 /* avoid a crash by checking for a too large value of 'columns' */
7226 if (old_Columns != Columns && full_screen && term_console)
7227 mch_check_columns();
7228#endif
7229
7230 /*
7231 * If the screen (shell) height has been changed, assume it is the
7232 * physical screenheight.
7233 */
7234 if (old_Rows != Rows || old_Columns != Columns)
7235 {
7236 /* Changing the screen size is not allowed while updating the screen. */
7237 if (updating_screen)
7238 *pp = old_value;
7239 else if (full_screen
7240#ifdef FEAT_GUI
7241 && !gui.starting
7242#endif
7243 )
7244 set_shellsize((int)Columns, (int)Rows, TRUE);
7245 else
7246 {
7247 /* Postpone the resizing; check the size and cmdline position for
7248 * messages. */
7249 check_shellsize();
7250 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7251 cmdline_row = Rows - p_ch;
7252 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007253 if (p_window >= Rows)
7254 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255 }
7256
7257 if (curbuf->b_p_sts < 0)
7258 {
7259 errmsg = e_positive;
7260 curbuf->b_p_sts = 0;
7261 }
7262 if (curbuf->b_p_ts <= 0)
7263 {
7264 errmsg = e_positive;
7265 curbuf->b_p_ts = 8;
7266 }
7267 if (curbuf->b_p_tw < 0)
7268 {
7269 errmsg = e_positive;
7270 curbuf->b_p_tw = 0;
7271 }
7272 if (p_tm < 0)
7273 {
7274 errmsg = e_positive;
7275 p_tm = 0;
7276 }
7277 if ((curwin->w_p_scr <= 0
7278 || (curwin->w_p_scr > curwin->w_height
7279 && curwin->w_height > 0))
7280 && full_screen)
7281 {
7282 if (pp == &(curwin->w_p_scr))
7283 {
7284 if (curwin->w_p_scr != 0)
7285 errmsg = e_scroll;
7286 win_comp_scroll(curwin);
7287 }
7288 /* If 'scroll' became invalid because of a side effect silently adjust
7289 * it. */
7290 else if (curwin->w_p_scr <= 0)
7291 curwin->w_p_scr = 1;
7292 else /* curwin->w_p_scr > curwin->w_height */
7293 curwin->w_p_scr = curwin->w_height;
7294 }
7295 if (p_report < 0)
7296 {
7297 errmsg = e_positive;
7298 p_report = 1;
7299 }
7300 if ((p_sj < 0 || p_sj >= Rows) && full_screen)
7301 {
7302 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7303 p_sj = Rows / 2;
7304 else
7305 {
7306 errmsg = e_scroll;
7307 p_sj = 1;
7308 }
7309 }
7310 if (p_so < 0 && full_screen)
7311 {
7312 errmsg = e_scroll;
7313 p_so = 0;
7314 }
7315 if (p_siso < 0 && full_screen)
7316 {
7317 errmsg = e_positive;
7318 p_siso = 0;
7319 }
7320#ifdef FEAT_CMDWIN
7321 if (p_cwh < 1)
7322 {
7323 errmsg = e_positive;
7324 p_cwh = 1;
7325 }
7326#endif
7327 if (p_ut < 0)
7328 {
7329 errmsg = e_positive;
7330 p_ut = 2000;
7331 }
7332 if (p_ss < 0)
7333 {
7334 errmsg = e_positive;
7335 p_ss = 0;
7336 }
7337
7338 /* May set global value for local option. */
7339 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7340 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7341
7342 options[opt_idx].flags |= P_WAS_SET;
7343
7344 comp_col(); /* in case 'columns' or 'ls' changed */
7345 if (curwin->w_curswant != MAXCOL)
7346 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7347 check_redraw(options[opt_idx].flags);
7348
7349 return errmsg;
7350}
7351
7352/*
7353 * Called after an option changed: check if something needs to be redrawn.
7354 */
7355 static void
7356check_redraw(flags)
7357 long_u flags;
7358{
7359 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7360 int clear = (flags & P_RCLR) == P_RCLR;
7361 int all = ((flags & P_RALL) == P_RALL || clear);
7362
7363#ifdef FEAT_WINDOWS
7364 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7365 status_redraw_all();
7366#endif
7367
7368 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7369 changed_window_setting();
7370 if (flags & P_RBUF)
7371 redraw_curbuf_later(NOT_VALID);
7372 if (clear)
7373 redraw_all_later(CLEAR);
7374 else if (all)
7375 redraw_all_later(NOT_VALID);
7376}
7377
7378/*
7379 * Find index for option 'arg'.
7380 * Return -1 if not found.
7381 */
7382 static int
7383findoption(arg)
7384 char_u *arg;
7385{
7386 int opt_idx;
7387 char *s, *p;
7388 static short quick_tab[27] = {0, 0}; /* quick access table */
7389 int is_term_opt;
7390
7391 /*
7392 * For first call: Initialize the quick-access table.
7393 * It contains the index for the first option that starts with a certain
7394 * letter. There are 26 letters, plus the first "t_" option.
7395 */
7396 if (quick_tab[1] == 0)
7397 {
7398 p = options[0].fullname;
7399 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7400 {
7401 if (s[0] != p[0])
7402 {
7403 if (s[0] == 't' && s[1] == '_')
7404 quick_tab[26] = opt_idx;
7405 else
7406 quick_tab[CharOrdLow(s[0])] = opt_idx;
7407 }
7408 p = s;
7409 }
7410 }
7411
7412 /*
7413 * Check for name starting with an illegal character.
7414 */
7415#ifdef EBCDIC
7416 if (!islower(arg[0]))
7417#else
7418 if (arg[0] < 'a' || arg[0] > 'z')
7419#endif
7420 return -1;
7421
7422 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7423 if (is_term_opt)
7424 opt_idx = quick_tab[26];
7425 else
7426 opt_idx = quick_tab[CharOrdLow(arg[0])];
7427 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7428 {
7429 if (STRCMP(arg, s) == 0) /* match full name */
7430 break;
7431 }
7432 if (s == NULL && !is_term_opt)
7433 {
7434 opt_idx = quick_tab[CharOrdLow(arg[0])];
7435 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7436 {
7437 s = options[opt_idx].shortname;
7438 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7439 break;
7440 s = NULL;
7441 }
7442 }
7443 if (s == NULL)
7444 opt_idx = -1;
7445 return opt_idx;
7446}
7447
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007448#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449/*
7450 * Get the value for an option.
7451 *
7452 * Returns:
7453 * Number or Toggle option: 1, *numval gets value.
7454 * String option: 0, *stringval gets allocated string.
7455 * Hidden Number or Toggle option: -1.
7456 * hidden String option: -2.
7457 * unknown option: -3.
7458 */
7459 int
7460get_option_value(name, numval, stringval, opt_flags)
7461 char_u *name;
7462 long *numval;
7463 char_u **stringval; /* NULL when only checking existance */
7464 int opt_flags;
7465{
7466 int opt_idx;
7467 char_u *varp;
7468
7469 opt_idx = findoption(name);
7470 if (opt_idx < 0) /* unknown option */
7471 return -3;
7472
7473 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7474
7475 if (options[opt_idx].flags & P_STRING)
7476 {
7477 if (varp == NULL) /* hidden option */
7478 return -2;
7479 if (stringval != NULL)
7480 {
7481#ifdef FEAT_CRYPT
7482 /* never return the value of the crypt key */
7483 if ((char_u **)varp == &curbuf->b_p_key)
7484 *stringval = vim_strsave((char_u *)"*****");
7485 else
7486#endif
7487 *stringval = vim_strsave(*(char_u **)(varp));
7488 }
7489 return 0;
7490 }
7491
7492 if (varp == NULL) /* hidden option */
7493 return -1;
7494 if (options[opt_idx].flags & P_NUM)
7495 *numval = *(long *)varp;
7496 else
7497 {
7498 /* Special case: 'modified' is b_changed, but we also want to consider
7499 * it set when 'ff' or 'fenc' changed. */
7500 if ((int *)varp == &curbuf->b_changed)
7501 *numval = curbufIsChanged();
7502 else
7503 *numval = *(int *)varp;
7504 }
7505 return 1;
7506}
7507#endif
7508
7509/*
7510 * Set the value of option "name".
7511 * Use "string" for string options, use "number" for other options.
7512 */
7513 void
7514set_option_value(name, number, string, opt_flags)
7515 char_u *name;
7516 long number;
7517 char_u *string;
7518 int opt_flags; /* OPT_LOCAL or 0 (both) */
7519{
7520 int opt_idx;
7521 char_u *varp;
7522 int flags;
7523
7524 opt_idx = findoption(name);
7525 if (opt_idx == -1)
7526 EMSG2(_("E355: Unknown option: %s"), name);
7527 else
7528 {
7529 flags = options[opt_idx].flags;
7530#ifdef HAVE_SANDBOX
7531 /* Disallow changing some options in the sandbox */
7532 if (sandbox > 0 && (flags & P_SECURE))
7533 EMSG(_(e_sandbox));
7534 else
7535#endif
7536 if (flags & P_STRING)
7537 set_string_option(opt_idx, string, opt_flags);
7538 else
7539 {
7540 varp = get_varp(&options[opt_idx]);
7541 if (varp != NULL) /* hidden option is not changed */
7542 {
7543 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00007544 (void)set_num_option(opt_idx, varp, number,
7545 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546 else
7547 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7548 }
7549 }
7550 }
7551}
7552
7553/*
7554 * Get the terminal code for a terminal option.
7555 * Returns NULL when not found.
7556 */
7557 char_u *
7558get_term_code(tname)
7559 char_u *tname;
7560{
7561 int opt_idx;
7562 char_u *varp;
7563
7564 if (tname[0] != 't' || tname[1] != '_' ||
7565 tname[2] == NUL || tname[3] == NUL)
7566 return NULL;
7567 if ((opt_idx = findoption(tname)) >= 0)
7568 {
7569 varp = get_varp(&(options[opt_idx]));
7570 if (varp != NULL)
7571 varp = *(char_u **)(varp);
7572 return varp;
7573 }
7574 return find_termcode(tname + 2);
7575}
7576
7577 char_u *
7578get_highlight_default()
7579{
7580 int i;
7581
7582 i = findoption((char_u *)"hl");
7583 if (i >= 0)
7584 return options[i].def_val[VI_DEFAULT];
7585 return (char_u *)NULL;
7586}
7587
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007588#if defined(FEAT_MBYTE) || defined(PROTO)
7589 char_u *
7590get_encoding_default()
7591{
7592 int i;
7593
7594 i = findoption((char_u *)"enc");
7595 if (i >= 0)
7596 return options[i].def_val[VI_DEFAULT];
7597 return (char_u *)NULL;
7598}
7599#endif
7600
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601/*
7602 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7603 */
7604 static int
7605find_key_option(arg)
7606 char_u *arg;
7607{
7608 int key;
7609 int modifiers;
7610
7611 /*
7612 * Don't use get_special_key_code() for t_xx, we don't want it to call
7613 * add_termcap_entry().
7614 */
7615 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7616 key = TERMCAP2KEY(arg[2], arg[3]);
7617 else
7618 {
7619 --arg; /* put arg at the '<' */
7620 modifiers = 0;
7621 key = find_special_key(&arg, &modifiers, TRUE);
7622 if (modifiers) /* can't handle modifiers here */
7623 key = 0;
7624 }
7625 return key;
7626}
7627
7628/*
7629 * if 'all' == 0: show changed options
7630 * if 'all' == 1: show all normal options
7631 * if 'all' == 2: show all terminal options
7632 */
7633 static void
7634showoptions(all, opt_flags)
7635 int all;
7636 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7637{
7638 struct vimoption *p;
7639 int col;
7640 int isterm;
7641 char_u *varp;
7642 struct vimoption **items;
7643 int item_count;
7644 int run;
7645 int row, rows;
7646 int cols;
7647 int i;
7648 int len;
7649
7650#define INC 20
7651#define GAP 3
7652
7653 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7654 PARAM_COUNT));
7655 if (items == NULL)
7656 return;
7657
7658 /* Highlight title */
7659 if (all == 2)
7660 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7661 else if (opt_flags & OPT_GLOBAL)
7662 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7663 else if (opt_flags & OPT_LOCAL)
7664 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7665 else
7666 MSG_PUTS_TITLE(_("\n--- Options ---"));
7667
7668 /*
7669 * do the loop two times:
7670 * 1. display the short items
7671 * 2. display the long items (only strings and numbers)
7672 */
7673 for (run = 1; run <= 2 && !got_int; ++run)
7674 {
7675 /*
7676 * collect the items in items[]
7677 */
7678 item_count = 0;
7679 for (p = &options[0]; p->fullname != NULL; p++)
7680 {
7681 varp = NULL;
7682 isterm = istermoption(p);
7683 if (opt_flags != 0)
7684 {
7685 if (p->indir != PV_NONE && !isterm)
7686 varp = get_varp_scope(p, opt_flags);
7687 }
7688 else
7689 varp = get_varp(p);
7690 if (varp != NULL
7691 && ((all == 2 && isterm)
7692 || (all == 1 && !isterm)
7693 || (all == 0 && !optval_default(p, varp))))
7694 {
7695 if (p->flags & P_BOOL)
7696 len = 1; /* a toggle option fits always */
7697 else
7698 {
7699 option_value2string(p, opt_flags);
7700 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7701 }
7702 if ((len <= INC - GAP && run == 1) ||
7703 (len > INC - GAP && run == 2))
7704 items[item_count++] = p;
7705 }
7706 }
7707
7708 /*
7709 * display the items
7710 */
7711 if (run == 1)
7712 {
7713 cols = (Columns + GAP - 3) / INC;
7714 if (cols == 0)
7715 cols = 1;
7716 rows = (item_count + cols - 1) / cols;
7717 }
7718 else /* run == 2 */
7719 rows = item_count;
7720 for (row = 0; row < rows && !got_int; ++row)
7721 {
7722 msg_putchar('\n'); /* go to next line */
7723 if (got_int) /* 'q' typed in more */
7724 break;
7725 col = 0;
7726 for (i = row; i < item_count; i += rows)
7727 {
7728 msg_col = col; /* make columns */
7729 showoneopt(items[i], opt_flags);
7730 col += INC;
7731 }
7732 out_flush();
7733 ui_breakcheck();
7734 }
7735 }
7736 vim_free(items);
7737}
7738
7739/*
7740 * Return TRUE if option "p" has its default value.
7741 */
7742 static int
7743optval_default(p, varp)
7744 struct vimoption *p;
7745 char_u *varp;
7746{
7747 int dvi;
7748
7749 if (varp == NULL)
7750 return TRUE; /* hidden option is always at default */
7751 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7752 if (p->flags & P_NUM)
7753 return (*(long *)varp == (long)p->def_val[dvi]);
7754 if (p->flags & P_BOOL)
7755 /* the cast to long is required for Manx C */
7756 return (*(int *)varp == (int)(long)p->def_val[dvi]);
7757 /* P_STRING */
7758 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7759}
7760
7761/*
7762 * showoneopt: show the value of one option
7763 * must not be called with a hidden option!
7764 */
7765 static void
7766showoneopt(p, opt_flags)
7767 struct vimoption *p;
7768 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
7769{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007770 char_u *varp;
7771 int save_silent = silent_mode;
7772
7773 silent_mode = FALSE;
7774 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007775
7776 varp = get_varp_scope(p, opt_flags);
7777
7778 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7779 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7780 ? !curbufIsChanged() : !*(int *)varp))
7781 MSG_PUTS("no");
7782 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7783 MSG_PUTS("--");
7784 else
7785 MSG_PUTS(" ");
7786 MSG_PUTS(p->fullname);
7787 if (!(p->flags & P_BOOL))
7788 {
7789 msg_putchar('=');
7790 /* put value string in NameBuff */
7791 option_value2string(p, opt_flags);
7792 msg_outtrans(NameBuff);
7793 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007794
7795 silent_mode = save_silent;
7796 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007797}
7798
7799/*
7800 * Write modified options as ":set" commands to a file.
7801 *
7802 * There are three values for "opt_flags":
7803 * OPT_GLOBAL: Write global option values and fresh values of
7804 * buffer-local options (used for start of a session
7805 * file).
7806 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7807 * curwin (used for a vimrc file).
7808 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
7809 * and local values for window-local options of
7810 * curwin. Local values are also written when at the
7811 * default value, because a modeline or autocommand
7812 * may have set them when doing ":edit file" and the
7813 * user has set them back at the default or fresh
7814 * value.
7815 * When "local_only" is TRUE, don't write fresh
7816 * values, only local values (for ":mkview").
7817 * (fresh value = value used for a new buffer or window for a local option).
7818 *
7819 * Return FAIL on error, OK otherwise.
7820 */
7821 int
7822makeset(fd, opt_flags, local_only)
7823 FILE *fd;
7824 int opt_flags;
7825 int local_only;
7826{
7827 struct vimoption *p;
7828 char_u *varp; /* currently used value */
7829 char_u *varp_fresh; /* local value */
7830 char_u *varp_local = NULL; /* fresh value */
7831 char *cmd;
7832 int round;
7833
7834 /*
7835 * The options that don't have a default (terminal name, columns, lines)
7836 * are never written. Terminal options are also not written.
7837 */
7838 for (p = &options[0]; !istermoption(p); p++)
7839 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7840 {
7841 /* skip global option when only doing locals */
7842 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7843 continue;
7844
7845 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
7846 * file, they are always buffer-specific. */
7847 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
7848 continue;
7849
7850 /* Global values are only written when not at the default value. */
7851 varp = get_varp_scope(p, opt_flags);
7852 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
7853 continue;
7854
7855 round = 2;
7856 if (p->indir != PV_NONE)
7857 {
7858 if (p->var == VAR_WIN)
7859 {
7860 /* skip window-local option when only doing globals */
7861 if (!(opt_flags & OPT_LOCAL))
7862 continue;
7863 /* When fresh value of window-local option is not at the
7864 * default, need to write it too. */
7865 if (!(opt_flags & OPT_GLOBAL) && !local_only)
7866 {
7867 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
7868 if (!optval_default(p, varp_fresh))
7869 {
7870 round = 1;
7871 varp_local = varp;
7872 varp = varp_fresh;
7873 }
7874 }
7875 }
7876 }
7877
7878 /* Round 1: fresh value for window-local options.
7879 * Round 2: other values */
7880 for ( ; round <= 2; varp = varp_local, ++round)
7881 {
7882 if (round == 1 || (opt_flags & OPT_GLOBAL))
7883 cmd = "set";
7884 else
7885 cmd = "setlocal";
7886
7887 if (p->flags & P_BOOL)
7888 {
7889 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
7890 return FAIL;
7891 }
7892 else if (p->flags & P_NUM)
7893 {
7894 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
7895 return FAIL;
7896 }
7897 else /* P_STRING */
7898 {
7899 /* Don't set 'syntax' and 'filetype' again if the value is
7900 * already right, avoids reloading the syntax file. */
7901 if (p->indir == PV_SYN || p->indir == PV_FT)
7902 {
7903 if (fprintf(fd, "if &%s != '%s'", p->fullname,
7904 *(char_u **)(varp)) < 0
7905 || put_eol(fd) < 0)
7906 return FAIL;
7907 }
7908 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
7909 (p->flags & P_EXPAND) != 0) == FAIL)
7910 return FAIL;
7911 if (p->indir == PV_SYN || p->indir == PV_FT)
7912 {
7913 if (put_line(fd, "endif") == FAIL)
7914 return FAIL;
7915 }
7916 }
7917 }
7918 }
7919 return OK;
7920}
7921
7922#if defined(FEAT_FOLDING) || defined(PROTO)
7923/*
7924 * Generate set commands for the local fold options only. Used when
7925 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
7926 */
7927 int
7928makefoldset(fd)
7929 FILE *fd;
7930{
7931 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
7932# ifdef FEAT_EVAL
7933 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
7934 == FAIL
7935# endif
7936 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
7937 == FAIL
7938 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
7939 == FAIL
7940 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
7941 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
7942 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
7943 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
7944 )
7945 return FAIL;
7946
7947 return OK;
7948}
7949#endif
7950
7951 static int
7952put_setstring(fd, cmd, name, valuep, expand)
7953 FILE *fd;
7954 char *cmd;
7955 char *name;
7956 char_u **valuep;
7957 int expand;
7958{
7959 char_u *s;
7960 char_u buf[MAXPATHL];
7961
7962 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7963 return FAIL;
7964 if (*valuep != NULL)
7965 {
7966 /* Output 'pastetoggle' as key names. For other
7967 * options some characters have to be escaped with
7968 * CTRL-V or backslash */
7969 if (valuep == &p_pt)
7970 {
7971 s = *valuep;
7972 while (*s != NUL)
7973 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
7974 return FAIL;
7975 }
7976 else if (expand)
7977 {
7978 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
7979 if (put_escstr(fd, buf, 2) == FAIL)
7980 return FAIL;
7981 }
7982 else if (put_escstr(fd, *valuep, 2) == FAIL)
7983 return FAIL;
7984 }
7985 if (put_eol(fd) < 0)
7986 return FAIL;
7987 return OK;
7988}
7989
7990 static int
7991put_setnum(fd, cmd, name, valuep)
7992 FILE *fd;
7993 char *cmd;
7994 char *name;
7995 long *valuep;
7996{
7997 long wc;
7998
7999 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8000 return FAIL;
8001 if (wc_use_keyname((char_u *)valuep, &wc))
8002 {
8003 /* print 'wildchar' and 'wildcharm' as a key name */
8004 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8005 return FAIL;
8006 }
8007 else if (fprintf(fd, "%ld", *valuep) < 0)
8008 return FAIL;
8009 if (put_eol(fd) < 0)
8010 return FAIL;
8011 return OK;
8012}
8013
8014 static int
8015put_setbool(fd, cmd, name, value)
8016 FILE *fd;
8017 char *cmd;
8018 char *name;
8019 int value;
8020{
8021 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8022 || put_eol(fd) < 0)
8023 return FAIL;
8024 return OK;
8025}
8026
8027/*
8028 * Clear all the terminal options.
8029 * If the option has been allocated, free the memory.
8030 * Terminal options are never hidden or indirect.
8031 */
8032 void
8033clear_termoptions()
8034{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 /*
8036 * Reset a few things before clearing the old options. This may cause
8037 * outputting a few things that the terminal doesn't understand, but the
8038 * screen will be cleared later, so this is OK.
8039 */
8040#ifdef FEAT_MOUSE_TTY
8041 mch_setmouse(FALSE); /* switch mouse off */
8042#endif
8043#ifdef FEAT_TITLE
8044 mch_restore_title(3); /* restore window titles */
8045#endif
8046#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8047 /* When starting the GUI close the display opened for the clipboard.
8048 * After restoring the title, because that will need the display. */
8049 if (gui.starting)
8050 clear_xterm_clip();
8051#endif
8052#ifdef WIN3264
8053 /*
8054 * Check if this is allowed now.
8055 */
8056 if (can_end_termcap_mode(FALSE) == TRUE)
8057#endif
8058 stoptermcap(); /* stop termcap mode */
8059
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008060 free_termoptions();
8061}
8062
8063 void
8064free_termoptions()
8065{
8066 struct vimoption *p;
8067
Bram Moolenaar071d4272004-06-13 20:20:40 +00008068 for (p = &options[0]; p->fullname != NULL; p++)
8069 if (istermoption(p))
8070 {
8071 if (p->flags & P_ALLOCED)
8072 free_string_option(*(char_u **)(p->var));
8073 if (p->flags & P_DEF_ALLOCED)
8074 free_string_option(p->def_val[VI_DEFAULT]);
8075 *(char_u **)(p->var) = empty_option;
8076 p->def_val[VI_DEFAULT] = empty_option;
8077 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8078 }
8079 clear_termcodes();
8080}
8081
8082/*
8083 * Set the terminal option defaults to the current value.
8084 * Used after setting the terminal name.
8085 */
8086 void
8087set_term_defaults()
8088{
8089 struct vimoption *p;
8090
8091 for (p = &options[0]; p->fullname != NULL; p++)
8092 {
8093 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8094 {
8095 if (p->flags & P_DEF_ALLOCED)
8096 {
8097 free_string_option(p->def_val[VI_DEFAULT]);
8098 p->flags &= ~P_DEF_ALLOCED;
8099 }
8100 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8101 if (p->flags & P_ALLOCED)
8102 {
8103 p->flags |= P_DEF_ALLOCED;
8104 p->flags &= ~P_ALLOCED; /* don't free the value now */
8105 }
8106 }
8107 }
8108}
8109
8110/*
8111 * return TRUE if 'p' starts with 't_'
8112 */
8113 static int
8114istermoption(p)
8115 struct vimoption *p;
8116{
8117 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8118}
8119
8120/*
8121 * Compute columns for ruler and shown command. 'sc_col' is also used to
8122 * decide what the maximum length of a message on the status line can be.
8123 * If there is a status line for the last window, 'sc_col' is independent
8124 * of 'ru_col'.
8125 */
8126
8127#define COL_RULER 17 /* columns needed by standard ruler */
8128
8129 void
8130comp_col()
8131{
8132#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8133 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8134
8135 sc_col = 0;
8136 ru_col = 0;
8137 if (p_ru)
8138 {
8139#ifdef FEAT_STL_OPT
8140 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8141#else
8142 ru_col = COL_RULER + 1;
8143#endif
8144 /* no last status line, adjust sc_col */
8145 if (!last_has_status)
8146 sc_col = ru_col;
8147 }
8148 if (p_sc)
8149 {
8150 sc_col += SHOWCMD_COLS;
8151 if (!p_ru || last_has_status) /* no need for separating space */
8152 ++sc_col;
8153 }
8154 sc_col = Columns - sc_col;
8155 ru_col = Columns - ru_col;
8156 if (sc_col <= 0) /* screen too narrow, will become a mess */
8157 sc_col = 1;
8158 if (ru_col <= 0)
8159 ru_col = 1;
8160#else
8161 sc_col = Columns;
8162 ru_col = Columns;
8163#endif
8164}
8165
8166/*
8167 * Get pointer to option variable, depending on local or global scope.
8168 */
8169 static char_u *
8170get_varp_scope(p, opt_flags)
8171 struct vimoption *p;
8172 int opt_flags;
8173{
8174 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8175 {
8176 if (p->var == VAR_WIN)
8177 return (char_u *)GLOBAL_WO(get_varp(p));
8178 return p->var;
8179 }
8180 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
8181 {
8182 switch ((int)p->indir)
8183 {
8184#ifdef FEAT_QUICKFIX
8185 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
8186 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
8187 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
8188#endif
8189 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
8190 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
8191 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
8192 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
8193 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
8194#ifdef FEAT_FIND_ID
8195 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
8196 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
8197#endif
8198#ifdef FEAT_INS_EXPAND
8199 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
8200 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
8201#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008202#ifdef FEAT_STL_OPT
8203 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
8204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 }
8206 return NULL; /* "cannot happen" */
8207 }
8208 return get_varp(p);
8209}
8210
8211/*
8212 * Get pointer to option variable.
8213 */
8214 static char_u *
8215get_varp(p)
8216 struct vimoption *p;
8217{
8218 /* hidden option, always return NULL */
8219 if (p->var == NULL)
8220 return NULL;
8221
8222 switch ((int)p->indir)
8223 {
8224 case PV_NONE: return p->var;
8225
8226 /* global option with local value: use local value if it's been set */
8227 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
8228 ? (char_u *)&curbuf->b_p_ep : p->var;
8229 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
8230 ? (char_u *)&curbuf->b_p_kp : p->var;
8231 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
8232 ? (char_u *)&(curbuf->b_p_path) : p->var;
8233 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
8234 ? (char_u *)&(curbuf->b_p_ar) : p->var;
8235 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
8236 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8237#ifdef FEAT_FIND_ID
8238 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
8239 ? (char_u *)&(curbuf->b_p_def) : p->var;
8240 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
8241 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8242#endif
8243#ifdef FEAT_INS_EXPAND
8244 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
8245 ? (char_u *)&(curbuf->b_p_dict) : p->var;
8246 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
8247 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8248#endif
8249#ifdef FEAT_QUICKFIX
8250 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
8251 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8252 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
8253 ? (char_u *)&(curbuf->b_p_mp) : p->var;
8254 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8255 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8256#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008257#ifdef FEAT_STL_OPT
8258 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8259 ? (char_u *)&(curwin->w_p_stl) : p->var;
8260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261
8262#ifdef FEAT_ARABIC
8263 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8264#endif
8265 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008266#ifdef FEAT_SYN_HL
8267 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008269#ifdef FEAT_DIFF
8270 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8271#endif
8272#ifdef FEAT_FOLDING
8273 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8274 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8275 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8276 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8277 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8278 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8279 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8280# ifdef FEAT_EVAL
8281 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8282 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8283# endif
8284 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8285#endif
8286 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008287#ifdef FEAT_LINEBREAK
8288 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290#if defined(FEAT_WINDOWS)
8291 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8292#endif
8293#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8294 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8295#endif
8296#ifdef FEAT_RIGHTLEFT
8297 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8298 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8299#endif
8300 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8301 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8302#ifdef FEAT_LINEBREAK
8303 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8304#endif
8305#ifdef FEAT_SCROLLBIND
8306 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8307#endif
8308
8309 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8310 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8311#ifdef FEAT_MBYTE
8312 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8313#endif
8314#if defined(FEAT_QUICKFIX)
8315 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8316 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8317#endif
8318 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8319 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8320#ifdef FEAT_CINDENT
8321 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8322 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8323 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8324#endif
8325#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8326 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8327#endif
8328#ifdef FEAT_COMMENTS
8329 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8330#endif
8331#ifdef FEAT_FOLDING
8332 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8333#endif
8334#ifdef FEAT_INS_EXPAND
8335 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8336#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008337#ifdef FEAT_COMPL_FUNC
8338 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
8339#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8341 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8342#ifdef FEAT_MBYTE
8343 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8344#endif
8345 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8346#ifdef FEAT_AUTOCMD
8347 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8348#endif
8349 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008350 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8352 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8353 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8354 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8355#ifdef FEAT_FIND_ID
8356# ifdef FEAT_EVAL
8357 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8358# endif
8359#endif
8360#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8361 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8362 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8363#endif
8364#ifdef FEAT_CRYPT
8365 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8366#endif
8367#ifdef FEAT_LISP
8368 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8369#endif
8370 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8371 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8372 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8373 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8374 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8375#ifdef FEAT_OSFILETYPE
8376 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8377#endif
8378 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008379#ifdef FEAT_TEXTOBJ
8380 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008382 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8383#ifdef FEAT_SMARTINDENT
8384 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8385#endif
8386#ifndef SHORT_FNAME
8387 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8388#endif
8389 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8390#ifdef FEAT_SEARCHPATH
8391 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8392#endif
8393 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8394#ifdef FEAT_SYN_HL
8395 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008396 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008397 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008398#endif
8399 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8400 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8401 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8402 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8403 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8404#ifdef FEAT_KEYMAP
8405 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8406#endif
8407 default: EMSG(_("E356: get_varp ERROR"));
8408 }
8409 /* always return a valid pointer to avoid a crash! */
8410 return (char_u *)&(curbuf->b_p_wm);
8411}
8412
8413/*
8414 * Get the value of 'equalprg', either the buffer-local one or the global one.
8415 */
8416 char_u *
8417get_equalprg()
8418{
8419 if (*curbuf->b_p_ep == NUL)
8420 return p_ep;
8421 return curbuf->b_p_ep;
8422}
8423
8424#if defined(FEAT_WINDOWS) || defined(PROTO)
8425/*
8426 * Copy options from one window to another.
8427 * Used when splitting a window.
8428 */
8429 void
8430win_copy_options(wp_from, wp_to)
8431 win_T *wp_from;
8432 win_T *wp_to;
8433{
8434 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8435 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8436# ifdef FEAT_RIGHTLEFT
8437# ifdef FEAT_FKMAP
8438 /* Is this right? */
8439 wp_to->w_farsi = wp_from->w_farsi;
8440# endif
8441# endif
8442}
8443#endif
8444
8445/*
8446 * Copy the options from one winopt_T to another.
8447 * Doesn't free the old option values in "to", use clear_winopt() for that.
8448 * The 'scroll' option is not copied, because it depends on the window height.
8449 * The 'previewwindow' option is reset, there can be only one preview window.
8450 */
8451 void
8452copy_winopt(from, to)
8453 winopt_T *from;
8454 winopt_T *to;
8455{
8456#ifdef FEAT_ARABIC
8457 to->wo_arab = from->wo_arab;
8458#endif
8459 to->wo_list = from->wo_list;
8460 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008461#ifdef FEAT_LINEBREAK
8462 to->wo_nuw = from->wo_nuw;
8463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464#ifdef FEAT_RIGHTLEFT
8465 to->wo_rl = from->wo_rl;
8466 to->wo_rlc = vim_strsave(from->wo_rlc);
8467#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008468#ifdef FEAT_STL_OPT
8469 to->wo_stl = vim_strsave(from->wo_stl);
8470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 to->wo_wrap = from->wo_wrap;
8472#ifdef FEAT_LINEBREAK
8473 to->wo_lbr = from->wo_lbr;
8474#endif
8475#ifdef FEAT_SCROLLBIND
8476 to->wo_scb = from->wo_scb;
8477#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008478#ifdef FEAT_SYN_HL
8479 to->wo_spell = from->wo_spell;
8480#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008481#ifdef FEAT_DIFF
8482 to->wo_diff = from->wo_diff;
8483#endif
8484#ifdef FEAT_FOLDING
8485 to->wo_fdc = from->wo_fdc;
8486 to->wo_fen = from->wo_fen;
8487 to->wo_fdi = vim_strsave(from->wo_fdi);
8488 to->wo_fml = from->wo_fml;
8489 to->wo_fdl = from->wo_fdl;
8490 to->wo_fdm = vim_strsave(from->wo_fdm);
8491 to->wo_fdn = from->wo_fdn;
8492# ifdef FEAT_EVAL
8493 to->wo_fde = vim_strsave(from->wo_fde);
8494 to->wo_fdt = vim_strsave(from->wo_fdt);
8495# endif
8496 to->wo_fmr = vim_strsave(from->wo_fmr);
8497#endif
8498 check_winopt(to); /* don't want NULL pointers */
8499}
8500
8501/*
8502 * Check string options in a window for a NULL value.
8503 */
8504 void
8505check_win_options(win)
8506 win_T *win;
8507{
8508 check_winopt(&win->w_onebuf_opt);
8509 check_winopt(&win->w_allbuf_opt);
8510}
8511
8512/*
8513 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8514 */
8515/*ARGSUSED*/
8516 void
8517check_winopt(wop)
8518 winopt_T *wop;
8519{
8520#ifdef FEAT_FOLDING
8521 check_string_option(&wop->wo_fdi);
8522 check_string_option(&wop->wo_fdm);
8523# ifdef FEAT_EVAL
8524 check_string_option(&wop->wo_fde);
8525 check_string_option(&wop->wo_fdt);
8526# endif
8527 check_string_option(&wop->wo_fmr);
8528#endif
8529#ifdef FEAT_RIGHTLEFT
8530 check_string_option(&wop->wo_rlc);
8531#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008532#ifdef FEAT_STL_OPT
8533 check_string_option(&wop->wo_stl);
8534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008535}
8536
8537/*
8538 * Free the allocated memory inside a winopt_T.
8539 */
8540/*ARGSUSED*/
8541 void
8542clear_winopt(wop)
8543 winopt_T *wop;
8544{
8545#ifdef FEAT_FOLDING
8546 clear_string_option(&wop->wo_fdi);
8547 clear_string_option(&wop->wo_fdm);
8548# ifdef FEAT_EVAL
8549 clear_string_option(&wop->wo_fde);
8550 clear_string_option(&wop->wo_fdt);
8551# endif
8552 clear_string_option(&wop->wo_fmr);
8553#endif
8554#ifdef FEAT_RIGHTLEFT
8555 clear_string_option(&wop->wo_rlc);
8556#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008557#ifdef FEAT_STL_OPT
8558 clear_string_option(&wop->wo_stl);
8559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560}
8561
8562/*
8563 * Copy global option values to local options for one buffer.
8564 * Used when creating a new buffer and sometimes when entering a buffer.
8565 * flags:
8566 * BCO_ENTER We will enter the buf buffer.
8567 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8568 * appropriate.
8569 * BCO_NOHELP Don't copy the values to a help buffer.
8570 */
8571 void
8572buf_copy_options(buf, flags)
8573 buf_T *buf;
8574 int flags;
8575{
8576 int should_copy = TRUE;
8577 char_u *save_p_isk = NULL; /* init for GCC */
8578 int dont_do_help;
8579 int did_isk = FALSE;
8580
8581 /*
8582 * Don't do anything of the buffer is invalid.
8583 */
8584 if (buf == NULL || !buf_valid(buf))
8585 return;
8586
8587 /*
8588 * Skip this when the option defaults have not been set yet. Happens when
8589 * main() allocates the first buffer.
8590 */
8591 if (p_cpo != NULL)
8592 {
8593 /*
8594 * Always copy when entering and 'cpo' contains 'S'.
8595 * Don't copy when already initialized.
8596 * Don't copy when 'cpo' contains 's' and not entering.
8597 * 'S' BCO_ENTER initialized 's' should_copy
8598 * yes yes X X TRUE
8599 * yes no yes X FALSE
8600 * no X yes X FALSE
8601 * X no no yes FALSE
8602 * X no no no TRUE
8603 * no yes no X TRUE
8604 */
8605 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8606 && (buf->b_p_initialized
8607 || (!(flags & BCO_ENTER)
8608 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8609 should_copy = FALSE;
8610
8611 if (should_copy || (flags & BCO_ALWAYS))
8612 {
8613 /* Don't copy the options specific to a help buffer when
8614 * BCO_NOHELP is given or the options were initialized already
8615 * (jumping back to a help file with CTRL-T or CTRL-O) */
8616 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8617 || buf->b_p_initialized;
8618 if (dont_do_help) /* don't free b_p_isk */
8619 {
8620 save_p_isk = buf->b_p_isk;
8621 buf->b_p_isk = NULL;
8622 }
8623 /*
8624 * Always free the allocated strings.
8625 * If not already initialized, set 'readonly' and copy 'fileformat'.
8626 */
8627 if (!buf->b_p_initialized)
8628 {
8629 free_buf_options(buf, TRUE);
8630 buf->b_p_ro = FALSE; /* don't copy readonly */
8631 buf->b_p_tx = p_tx;
8632#ifdef FEAT_MBYTE
8633 buf->b_p_fenc = vim_strsave(p_fenc);
8634#endif
8635 buf->b_p_ff = vim_strsave(p_ff);
8636#if defined(FEAT_QUICKFIX)
8637 buf->b_p_bh = empty_option;
8638 buf->b_p_bt = empty_option;
8639#endif
8640 }
8641 else
8642 free_buf_options(buf, FALSE);
8643
8644 buf->b_p_ai = p_ai;
8645 buf->b_p_ai_nopaste = p_ai_nopaste;
8646 buf->b_p_sw = p_sw;
8647 buf->b_p_tw = p_tw;
8648 buf->b_p_tw_nopaste = p_tw_nopaste;
8649 buf->b_p_tw_nobin = p_tw_nobin;
8650 buf->b_p_wm = p_wm;
8651 buf->b_p_wm_nopaste = p_wm_nopaste;
8652 buf->b_p_wm_nobin = p_wm_nobin;
8653 buf->b_p_bin = p_bin;
8654 buf->b_p_et = p_et;
8655 buf->b_p_et_nobin = p_et_nobin;
8656 buf->b_p_ml = p_ml;
8657 buf->b_p_ml_nobin = p_ml_nobin;
8658 buf->b_p_inf = p_inf;
8659 buf->b_p_swf = p_swf;
8660#ifdef FEAT_INS_EXPAND
8661 buf->b_p_cpt = vim_strsave(p_cpt);
8662#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008663#ifdef FEAT_COMPL_FUNC
8664 buf->b_p_cfu = vim_strsave(p_cfu);
8665#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666 buf->b_p_sts = p_sts;
8667 buf->b_p_sts_nopaste = p_sts_nopaste;
8668#ifndef SHORT_FNAME
8669 buf->b_p_sn = p_sn;
8670#endif
8671#ifdef FEAT_COMMENTS
8672 buf->b_p_com = vim_strsave(p_com);
8673#endif
8674#ifdef FEAT_FOLDING
8675 buf->b_p_cms = vim_strsave(p_cms);
8676#endif
8677 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008678 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679 buf->b_p_nf = vim_strsave(p_nf);
8680 buf->b_p_mps = vim_strsave(p_mps);
8681#ifdef FEAT_SMARTINDENT
8682 buf->b_p_si = p_si;
8683#endif
8684 buf->b_p_ci = p_ci;
8685#ifdef FEAT_CINDENT
8686 buf->b_p_cin = p_cin;
8687 buf->b_p_cink = vim_strsave(p_cink);
8688 buf->b_p_cino = vim_strsave(p_cino);
8689#endif
8690#ifdef FEAT_AUTOCMD
8691 /* Don't copy 'filetype', it must be detected */
8692 buf->b_p_ft = empty_option;
8693#endif
8694#ifdef FEAT_OSFILETYPE
8695 buf->b_p_oft = vim_strsave(p_oft);
8696#endif
8697 buf->b_p_pi = p_pi;
8698#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8699 buf->b_p_cinw = vim_strsave(p_cinw);
8700#endif
8701#ifdef FEAT_LISP
8702 buf->b_p_lisp = p_lisp;
8703#endif
8704#ifdef FEAT_SYN_HL
8705 /* Don't copy 'syntax', it must be set */
8706 buf->b_p_syn = empty_option;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008707 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008708 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709#endif
8710#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8711 buf->b_p_inde = vim_strsave(p_inde);
8712 buf->b_p_indk = vim_strsave(p_indk);
8713#endif
8714#ifdef FEAT_CRYPT
8715 buf->b_p_key = vim_strsave(p_key);
8716#endif
8717#ifdef FEAT_SEARCHPATH
8718 buf->b_p_sua = vim_strsave(p_sua);
8719#endif
8720#ifdef FEAT_KEYMAP
8721 buf->b_p_keymap = vim_strsave(p_keymap);
8722 buf->b_kmap_state |= KEYMAP_INIT;
8723#endif
8724 /* This isn't really an option, but copying the langmap and IME
8725 * state from the current buffer is better than resetting it. */
8726 buf->b_p_iminsert = p_iminsert;
8727 buf->b_p_imsearch = p_imsearch;
8728
8729 /* options that are normally global but also have a local value
8730 * are not copied, start using the global value */
8731 buf->b_p_ar = -1;
8732#ifdef FEAT_QUICKFIX
8733 buf->b_p_gp = empty_option;
8734 buf->b_p_mp = empty_option;
8735 buf->b_p_efm = empty_option;
8736#endif
8737 buf->b_p_ep = empty_option;
8738 buf->b_p_kp = empty_option;
8739 buf->b_p_path = empty_option;
8740 buf->b_p_tags = empty_option;
8741#ifdef FEAT_FIND_ID
8742 buf->b_p_def = empty_option;
8743 buf->b_p_inc = empty_option;
8744# ifdef FEAT_EVAL
8745 buf->b_p_inex = vim_strsave(p_inex);
8746# endif
8747#endif
8748#ifdef FEAT_INS_EXPAND
8749 buf->b_p_dict = empty_option;
8750 buf->b_p_tsr = empty_option;
8751#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008752#ifdef FEAT_TEXTOBJ
8753 buf->b_p_qe = vim_strsave(p_qe);
8754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755
8756 /*
8757 * Don't copy the options set by ex_help(), use the saved values,
8758 * when going from a help buffer to a non-help buffer.
8759 * Don't touch these at all when BCO_NOHELP is used and going from
8760 * or to a help buffer.
8761 */
8762 if (dont_do_help)
8763 buf->b_p_isk = save_p_isk;
8764 else
8765 {
8766 buf->b_p_isk = vim_strsave(p_isk);
8767 did_isk = TRUE;
8768 buf->b_p_ts = p_ts;
8769 buf->b_help = FALSE;
8770#ifdef FEAT_QUICKFIX
8771 if (buf->b_p_bt[0] == 'h')
8772 clear_string_option(&buf->b_p_bt);
8773#endif
8774 buf->b_p_ma = p_ma;
8775 }
8776 }
8777
8778 /*
8779 * When the options should be copied (ignoring BCO_ALWAYS), set the
8780 * flag that indicates that the options have been initialized.
8781 */
8782 if (should_copy)
8783 buf->b_p_initialized = TRUE;
8784 }
8785
8786 check_buf_options(buf); /* make sure we don't have NULLs */
8787 if (did_isk)
8788 (void)buf_init_chartab(buf, FALSE);
8789}
8790
8791/*
8792 * Reset the 'modifiable' option and its default value.
8793 */
8794 void
8795reset_modifiable()
8796{
8797 int opt_idx;
8798
8799 curbuf->b_p_ma = FALSE;
8800 p_ma = FALSE;
8801 opt_idx = findoption((char_u *)"ma");
8802 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8803}
8804
8805/*
8806 * Set the global value for 'iminsert' to the local value.
8807 */
8808 void
8809set_iminsert_global()
8810{
8811 p_iminsert = curbuf->b_p_iminsert;
8812}
8813
8814/*
8815 * Set the global value for 'imsearch' to the local value.
8816 */
8817 void
8818set_imsearch_global()
8819{
8820 p_imsearch = curbuf->b_p_imsearch;
8821}
8822
8823#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8824static int expand_option_idx = -1;
8825static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8826static int expand_option_flags = 0;
8827
8828 void
8829set_context_in_set_cmd(xp, arg, opt_flags)
8830 expand_T *xp;
8831 char_u *arg;
8832 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8833{
8834 int nextchar;
8835 long_u flags = 0; /* init for GCC */
8836 int opt_idx = 0; /* init for GCC */
8837 char_u *p;
8838 char_u *s;
8839 int is_term_option = FALSE;
8840 int key;
8841
8842 expand_option_flags = opt_flags;
8843
8844 xp->xp_context = EXPAND_SETTINGS;
8845 if (*arg == NUL)
8846 {
8847 xp->xp_pattern = arg;
8848 return;
8849 }
8850 p = arg + STRLEN(arg) - 1;
8851 if (*p == ' ' && *(p - 1) != '\\')
8852 {
8853 xp->xp_pattern = p + 1;
8854 return;
8855 }
8856 while (p > arg)
8857 {
8858 s = p;
8859 /* count number of backslashes before ' ' or ',' */
8860 if (*p == ' ' || *p == ',')
8861 {
8862 while (s > arg && *(s - 1) == '\\')
8863 --s;
8864 }
8865 /* break at a space with an even number of backslashes */
8866 if (*p == ' ' && ((p - s) & 1) == 0)
8867 {
8868 ++p;
8869 break;
8870 }
8871 --p;
8872 }
8873 if (STRNCMP(p, "no", 2) == 0)
8874 {
8875 xp->xp_context = EXPAND_BOOL_SETTINGS;
8876 p += 2;
8877 }
8878 if (STRNCMP(p, "inv", 3) == 0)
8879 {
8880 xp->xp_context = EXPAND_BOOL_SETTINGS;
8881 p += 3;
8882 }
8883 xp->xp_pattern = arg = p;
8884 if (*arg == '<')
8885 {
8886 while (*p != '>')
8887 if (*p++ == NUL) /* expand terminal option name */
8888 return;
8889 key = get_special_key_code(arg + 1);
8890 if (key == 0) /* unknown name */
8891 {
8892 xp->xp_context = EXPAND_NOTHING;
8893 return;
8894 }
8895 nextchar = *++p;
8896 is_term_option = TRUE;
8897 expand_option_name[2] = KEY2TERMCAP0(key);
8898 expand_option_name[3] = KEY2TERMCAP1(key);
8899 }
8900 else
8901 {
8902 if (p[0] == 't' && p[1] == '_')
8903 {
8904 p += 2;
8905 if (*p != NUL)
8906 ++p;
8907 if (*p == NUL)
8908 return; /* expand option name */
8909 nextchar = *++p;
8910 is_term_option = TRUE;
8911 expand_option_name[2] = p[-2];
8912 expand_option_name[3] = p[-1];
8913 }
8914 else
8915 {
8916 /* Allow * wildcard */
8917 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
8918 p++;
8919 if (*p == NUL)
8920 return;
8921 nextchar = *p;
8922 *p = NUL;
8923 opt_idx = findoption(arg);
8924 *p = nextchar;
8925 if (opt_idx == -1 || options[opt_idx].var == NULL)
8926 {
8927 xp->xp_context = EXPAND_NOTHING;
8928 return;
8929 }
8930 flags = options[opt_idx].flags;
8931 if (flags & P_BOOL)
8932 {
8933 xp->xp_context = EXPAND_NOTHING;
8934 return;
8935 }
8936 }
8937 }
8938 /* handle "-=" and "+=" */
8939 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
8940 {
8941 ++p;
8942 nextchar = '=';
8943 }
8944 if ((nextchar != '=' && nextchar != ':')
8945 || xp->xp_context == EXPAND_BOOL_SETTINGS)
8946 {
8947 xp->xp_context = EXPAND_UNSUCCESSFUL;
8948 return;
8949 }
8950 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
8951 {
8952 xp->xp_context = EXPAND_OLD_SETTING;
8953 if (is_term_option)
8954 expand_option_idx = -1;
8955 else
8956 expand_option_idx = opt_idx;
8957 xp->xp_pattern = p + 1;
8958 return;
8959 }
8960 xp->xp_context = EXPAND_NOTHING;
8961 if (is_term_option || (flags & P_NUM))
8962 return;
8963
8964 xp->xp_pattern = p + 1;
8965
8966 if (flags & P_EXPAND)
8967 {
8968 p = options[opt_idx].var;
8969 if (p == (char_u *)&p_bdir
8970 || p == (char_u *)&p_dir
8971 || p == (char_u *)&p_path
8972 || p == (char_u *)&p_rtp
8973#ifdef FEAT_SEARCHPATH
8974 || p == (char_u *)&p_cdpath
8975#endif
8976#ifdef FEAT_SESSION
8977 || p == (char_u *)&p_vdir
8978#endif
8979 )
8980 {
8981 xp->xp_context = EXPAND_DIRECTORIES;
8982 if (p == (char_u *)&p_path
8983#ifdef FEAT_SEARCHPATH
8984 || p == (char_u *)&p_cdpath
8985#endif
8986 )
8987 xp->xp_backslash = XP_BS_THREE;
8988 else
8989 xp->xp_backslash = XP_BS_ONE;
8990 }
8991 else
8992 {
8993 xp->xp_context = EXPAND_FILES;
8994 /* for 'tags' need three backslashes for a space */
8995 if (p == (char_u *)&p_tags)
8996 xp->xp_backslash = XP_BS_THREE;
8997 else
8998 xp->xp_backslash = XP_BS_ONE;
8999 }
9000 }
9001
9002 /* For an option that is a list of file names, find the start of the
9003 * last file name. */
9004 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9005 {
9006 /* count number of backslashes before ' ' or ',' */
9007 if (*p == ' ' || *p == ',')
9008 {
9009 s = p;
9010 while (s > xp->xp_pattern && *(s - 1) == '\\')
9011 --s;
9012 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9013 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9014 {
9015 xp->xp_pattern = p + 1;
9016 break;
9017 }
9018 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009019
9020#ifdef FEAT_SYN_HL
9021 /* for 'spellsuggest' start at "file:" */
9022 if (options[opt_idx].var == (char_u *)&p_sps
9023 && STRNCMP(p, "file:", 5) == 0)
9024 {
9025 xp->xp_pattern = p + 5;
9026 break;
9027 }
9028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009029 }
9030
9031 return;
9032}
9033
9034 int
9035ExpandSettings(xp, regmatch, num_file, file)
9036 expand_T *xp;
9037 regmatch_T *regmatch;
9038 int *num_file;
9039 char_u ***file;
9040{
9041 int num_normal = 0; /* Nr of matching non-term-code settings */
9042 int num_term = 0; /* Nr of matching terminal code settings */
9043 int opt_idx;
9044 int match;
9045 int count = 0;
9046 char_u *str;
9047 int loop;
9048 int is_term_opt;
9049 char_u name_buf[MAX_KEY_NAME_LEN];
9050 static char *(names[]) = {"all", "termcap"};
9051 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9052
9053 /* do this loop twice:
9054 * loop == 0: count the number of matching options
9055 * loop == 1: copy the matching options into allocated memory
9056 */
9057 for (loop = 0; loop <= 1; ++loop)
9058 {
9059 regmatch->rm_ic = ic;
9060 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9061 {
9062 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9063 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9064 {
9065 if (loop == 0)
9066 num_normal++;
9067 else
9068 (*file)[count++] = vim_strsave((char_u *)names[match]);
9069 }
9070 }
9071 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9072 opt_idx++)
9073 {
9074 if (options[opt_idx].var == NULL)
9075 continue;
9076 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9077 && !(options[opt_idx].flags & P_BOOL))
9078 continue;
9079 is_term_opt = istermoption(&options[opt_idx]);
9080 if (is_term_opt && num_normal > 0)
9081 continue;
9082 match = FALSE;
9083 if (vim_regexec(regmatch, str, (colnr_T)0)
9084 || (options[opt_idx].shortname != NULL
9085 && vim_regexec(regmatch,
9086 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9087 match = TRUE;
9088 else if (is_term_opt)
9089 {
9090 name_buf[0] = '<';
9091 name_buf[1] = 't';
9092 name_buf[2] = '_';
9093 name_buf[3] = str[2];
9094 name_buf[4] = str[3];
9095 name_buf[5] = '>';
9096 name_buf[6] = NUL;
9097 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9098 {
9099 match = TRUE;
9100 str = name_buf;
9101 }
9102 }
9103 if (match)
9104 {
9105 if (loop == 0)
9106 {
9107 if (is_term_opt)
9108 num_term++;
9109 else
9110 num_normal++;
9111 }
9112 else
9113 (*file)[count++] = vim_strsave(str);
9114 }
9115 }
9116 /*
9117 * Check terminal key codes, these are not in the option table
9118 */
9119 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9120 {
9121 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9122 {
9123 if (!isprint(str[0]) || !isprint(str[1]))
9124 continue;
9125
9126 name_buf[0] = 't';
9127 name_buf[1] = '_';
9128 name_buf[2] = str[0];
9129 name_buf[3] = str[1];
9130 name_buf[4] = NUL;
9131
9132 match = FALSE;
9133 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9134 match = TRUE;
9135 else
9136 {
9137 name_buf[0] = '<';
9138 name_buf[1] = 't';
9139 name_buf[2] = '_';
9140 name_buf[3] = str[0];
9141 name_buf[4] = str[1];
9142 name_buf[5] = '>';
9143 name_buf[6] = NUL;
9144
9145 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9146 match = TRUE;
9147 }
9148 if (match)
9149 {
9150 if (loop == 0)
9151 num_term++;
9152 else
9153 (*file)[count++] = vim_strsave(name_buf);
9154 }
9155 }
9156
9157 /*
9158 * Check special key names.
9159 */
9160 regmatch->rm_ic = TRUE; /* ignore case here */
9161 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9162 {
9163 name_buf[0] = '<';
9164 STRCPY(name_buf + 1, str);
9165 STRCAT(name_buf, ">");
9166
9167 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9168 {
9169 if (loop == 0)
9170 num_term++;
9171 else
9172 (*file)[count++] = vim_strsave(name_buf);
9173 }
9174 }
9175 }
9176 if (loop == 0)
9177 {
9178 if (num_normal > 0)
9179 *num_file = num_normal;
9180 else if (num_term > 0)
9181 *num_file = num_term;
9182 else
9183 return OK;
9184 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9185 if (*file == NULL)
9186 {
9187 *file = (char_u **)"";
9188 return FAIL;
9189 }
9190 }
9191 }
9192 return OK;
9193}
9194
9195 int
9196ExpandOldSetting(num_file, file)
9197 int *num_file;
9198 char_u ***file;
9199{
9200 char_u *var = NULL; /* init for GCC */
9201 char_u *buf;
9202
9203 *num_file = 0;
9204 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9205 if (*file == NULL)
9206 return FAIL;
9207
9208 /*
9209 * For a terminal key code expand_option_idx is < 0.
9210 */
9211 if (expand_option_idx < 0)
9212 {
9213 var = find_termcode(expand_option_name + 2);
9214 if (var == NULL)
9215 expand_option_idx = findoption(expand_option_name);
9216 }
9217
9218 if (expand_option_idx >= 0)
9219 {
9220 /* put string of option value in NameBuff */
9221 option_value2string(&options[expand_option_idx], expand_option_flags);
9222 var = NameBuff;
9223 }
9224 else if (var == NULL)
9225 var = (char_u *)"";
9226
9227 /* A backslash is required before some characters. This is the reverse of
9228 * what happens in do_set(). */
9229 buf = vim_strsave_escaped(var, escape_chars);
9230
9231 if (buf == NULL)
9232 {
9233 vim_free(*file);
9234 *file = NULL;
9235 return FAIL;
9236 }
9237
9238#ifdef BACKSLASH_IN_FILENAME
9239 /* For MS-Windows et al. we don't double backslashes at the start and
9240 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009241 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009242 if (var[0] == '\\' && var[1] == '\\'
9243 && expand_option_idx >= 0
9244 && (options[expand_option_idx].flags & P_EXPAND)
9245 && vim_isfilec(var[2])
9246 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9247 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009248#endif
9249
9250 *file[0] = buf;
9251 *num_file = 1;
9252 return OK;
9253}
9254#endif
9255
9256/*
9257 * Get the value for the numeric or string option *opp in a nice format into
9258 * NameBuff[]. Must not be called with a hidden option!
9259 */
9260 static void
9261option_value2string(opp, opt_flags)
9262 struct vimoption *opp;
9263 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9264{
9265 char_u *varp;
9266
9267 varp = get_varp_scope(opp, opt_flags);
9268
9269 if (opp->flags & P_NUM)
9270 {
9271 long wc = 0;
9272
9273 if (wc_use_keyname(varp, &wc))
9274 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9275 else if (wc != 0)
9276 STRCPY(NameBuff, transchar((int)wc));
9277 else
9278 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9279 }
9280 else /* P_STRING */
9281 {
9282 varp = *(char_u **)(varp);
9283 if (varp == NULL) /* just in case */
9284 NameBuff[0] = NUL;
9285#ifdef FEAT_CRYPT
9286 /* don't show the actual value of 'key', only that it's set */
9287 if (opp->var == (char_u *)&p_key && *varp)
9288 STRCPY(NameBuff, "*****");
9289#endif
9290 else if (opp->flags & P_EXPAND)
9291 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9292 /* Translate 'pastetoggle' into special key names */
9293 else if ((char_u **)opp->var == &p_pt)
9294 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9295 else
9296 STRNCPY(NameBuff, varp, MAXPATHL);
9297 }
9298}
9299
9300/*
9301 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9302 * printed as a keyname.
9303 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9304 */
9305 static int
9306wc_use_keyname(varp, wcp)
9307 char_u *varp;
9308 long *wcp;
9309{
9310 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9311 {
9312 *wcp = *(long *)varp;
9313 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9314 return TRUE;
9315 }
9316 return FALSE;
9317}
9318
9319#ifdef FEAT_LANGMAP
9320/*
9321 * Any character has an equivalent character. This is used for keyboards that
9322 * have a special language mode that sends characters above 128 (although
9323 * other characters can be translated too).
9324 */
9325
9326/*
9327 * char_u langmap_mapchar[256];
9328 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9329 * "translate" native lang chars in normal mode or some cases of
9330 * insert mode without having to tediously switch lang mode back&forth.
9331 */
9332
9333 static void
9334langmap_init()
9335{
9336 int i;
9337
9338 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9339 langmap_mapchar[i] = i;
9340}
9341
9342/*
9343 * Called when langmap option is set; the language map can be
9344 * changed at any time!
9345 */
9346 static void
9347langmap_set()
9348{
9349 char_u *p;
9350 char_u *p2;
9351 int from, to;
9352
9353 langmap_init(); /* back to one-to-one map first */
9354
9355 for (p = p_langmap; p[0] != NUL; )
9356 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009357 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9358 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359 {
9360 if (p2[0] == '\\' && p2[1] != NUL)
9361 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362 }
9363 if (p2[0] == ';')
9364 ++p2; /* abcd;ABCD form, p2 points to A */
9365 else
9366 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9367 while (p[0])
9368 {
9369 if (p[0] == '\\' && p[1] != NUL)
9370 ++p;
9371#ifdef FEAT_MBYTE
9372 from = (*mb_ptr2char)(p);
9373#else
9374 from = p[0];
9375#endif
9376 if (p2 == NULL)
9377 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009378 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379 if (p[0] == '\\')
9380 ++p;
9381#ifdef FEAT_MBYTE
9382 to = (*mb_ptr2char)(p);
9383#else
9384 to = p[0];
9385#endif
9386 }
9387 else
9388 {
9389 if (p2[0] == '\\')
9390 ++p2;
9391#ifdef FEAT_MBYTE
9392 to = (*mb_ptr2char)(p2);
9393#else
9394 to = p2[0];
9395#endif
9396 }
9397 if (to == NUL)
9398 {
9399 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9400 transchar(from));
9401 return;
9402 }
9403 langmap_mapchar[from & 255] = to;
9404
9405 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009406 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009407 if (p2 == NULL)
9408 {
9409 if (p[0] == ',')
9410 {
9411 ++p;
9412 break;
9413 }
9414 }
9415 else
9416 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009417 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418 if (*p == ';')
9419 {
9420 p = p2;
9421 if (p[0] != NUL)
9422 {
9423 if (p[0] != ',')
9424 {
9425 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9426 return;
9427 }
9428 ++p;
9429 }
9430 break;
9431 }
9432 }
9433 }
9434 }
9435}
9436#endif
9437
9438/*
9439 * Return TRUE if format option 'x' is in effect.
9440 * Take care of no formatting when 'paste' is set.
9441 */
9442 int
9443has_format_option(x)
9444 int x;
9445{
9446 if (p_paste)
9447 return FALSE;
9448 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9449}
9450
9451/*
9452 * Return TRUE if "x" is present in 'shortmess' option, or
9453 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9454 */
9455 int
9456shortmess(x)
9457 int x;
9458{
9459 return ( vim_strchr(p_shm, x) != NULL
9460 || (vim_strchr(p_shm, 'a') != NULL
9461 && vim_strchr((char_u *)SHM_A, x) != NULL));
9462}
9463
9464/*
9465 * paste_option_changed() - Called after p_paste was set or reset.
9466 */
9467 static void
9468paste_option_changed()
9469{
9470 static int old_p_paste = FALSE;
9471 static int save_sm = 0;
9472#ifdef FEAT_CMDL_INFO
9473 static int save_ru = 0;
9474#endif
9475#ifdef FEAT_RIGHTLEFT
9476 static int save_ri = 0;
9477 static int save_hkmap = 0;
9478#endif
9479 buf_T *buf;
9480
9481 if (p_paste)
9482 {
9483 /*
9484 * Paste switched from off to on.
9485 * Save the current values, so they can be restored later.
9486 */
9487 if (!old_p_paste)
9488 {
9489 /* save options for each buffer */
9490 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9491 {
9492 buf->b_p_tw_nopaste = buf->b_p_tw;
9493 buf->b_p_wm_nopaste = buf->b_p_wm;
9494 buf->b_p_sts_nopaste = buf->b_p_sts;
9495 buf->b_p_ai_nopaste = buf->b_p_ai;
9496 }
9497
9498 /* save global options */
9499 save_sm = p_sm;
9500#ifdef FEAT_CMDL_INFO
9501 save_ru = p_ru;
9502#endif
9503#ifdef FEAT_RIGHTLEFT
9504 save_ri = p_ri;
9505 save_hkmap = p_hkmap;
9506#endif
9507 /* save global values for local buffer options */
9508 p_tw_nopaste = p_tw;
9509 p_wm_nopaste = p_wm;
9510 p_sts_nopaste = p_sts;
9511 p_ai_nopaste = p_ai;
9512 }
9513
9514 /*
9515 * Always set the option values, also when 'paste' is set when it is
9516 * already on.
9517 */
9518 /* set options for each buffer */
9519 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9520 {
9521 buf->b_p_tw = 0; /* textwidth is 0 */
9522 buf->b_p_wm = 0; /* wrapmargin is 0 */
9523 buf->b_p_sts = 0; /* softtabstop is 0 */
9524 buf->b_p_ai = 0; /* no auto-indent */
9525 }
9526
9527 /* set global options */
9528 p_sm = 0; /* no showmatch */
9529#ifdef FEAT_CMDL_INFO
9530# ifdef FEAT_WINDOWS
9531 if (p_ru)
9532 status_redraw_all(); /* redraw to remove the ruler */
9533# endif
9534 p_ru = 0; /* no ruler */
9535#endif
9536#ifdef FEAT_RIGHTLEFT
9537 p_ri = 0; /* no reverse insert */
9538 p_hkmap = 0; /* no Hebrew keyboard */
9539#endif
9540 /* set global values for local buffer options */
9541 p_tw = 0;
9542 p_wm = 0;
9543 p_sts = 0;
9544 p_ai = 0;
9545 }
9546
9547 /*
9548 * Paste switched from on to off: Restore saved values.
9549 */
9550 else if (old_p_paste)
9551 {
9552 /* restore options for each buffer */
9553 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9554 {
9555 buf->b_p_tw = buf->b_p_tw_nopaste;
9556 buf->b_p_wm = buf->b_p_wm_nopaste;
9557 buf->b_p_sts = buf->b_p_sts_nopaste;
9558 buf->b_p_ai = buf->b_p_ai_nopaste;
9559 }
9560
9561 /* restore global options */
9562 p_sm = save_sm;
9563#ifdef FEAT_CMDL_INFO
9564# ifdef FEAT_WINDOWS
9565 if (p_ru != save_ru)
9566 status_redraw_all(); /* redraw to draw the ruler */
9567# endif
9568 p_ru = save_ru;
9569#endif
9570#ifdef FEAT_RIGHTLEFT
9571 p_ri = save_ri;
9572 p_hkmap = save_hkmap;
9573#endif
9574 /* set global values for local buffer options */
9575 p_tw = p_tw_nopaste;
9576 p_wm = p_wm_nopaste;
9577 p_sts = p_sts_nopaste;
9578 p_ai = p_ai_nopaste;
9579 }
9580
9581 old_p_paste = p_paste;
9582}
9583
9584/*
9585 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9586 *
9587 * Reset 'compatible' and set the values for options that didn't get set yet
9588 * to the Vim defaults.
9589 * Don't do this if the 'compatible' option has been set or reset before.
9590 */
9591 void
9592vimrc_found()
9593{
9594 int opt_idx;
9595
9596 if (!option_was_set((char_u *)"cp"))
9597 {
9598 p_cp = FALSE;
9599 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9600 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9601 set_option_default(opt_idx, OPT_FREE, FALSE);
9602 didset_options();
9603 }
9604}
9605
9606/*
9607 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9608 */
9609 void
9610change_compatible(on)
9611 int on;
9612{
9613 if (p_cp != on)
9614 {
9615 p_cp = on;
9616 compatible_set();
9617 }
9618 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9619}
9620
9621/*
9622 * Return TRUE when option "name" has been set.
9623 */
9624 int
9625option_was_set(name)
9626 char_u *name;
9627{
9628 int idx;
9629
9630 idx = findoption(name);
9631 if (idx < 0) /* unknown option */
9632 return FALSE;
9633 if (options[idx].flags & P_WAS_SET)
9634 return TRUE;
9635 return FALSE;
9636}
9637
9638/*
9639 * compatible_set() - Called when 'compatible' has been set or unset.
9640 *
9641 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9642 * flag) to a Vi compatible value.
9643 * When 'compatible' is unset: Set all options that have a different default
9644 * for Vim (without the P_VI_DEF flag) to that default.
9645 */
9646 static void
9647compatible_set()
9648{
9649 int opt_idx;
9650
9651 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9652 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9653 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9654 set_option_default(opt_idx, OPT_FREE, p_cp);
9655 didset_options();
9656}
9657
9658#ifdef FEAT_LINEBREAK
9659
9660# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9661 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009662 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009663# endif
9664
9665/*
9666 * fill_breakat_flags() -- called when 'breakat' changes value.
9667 */
9668 static void
9669fill_breakat_flags()
9670{
9671 char_u *c;
9672 int i;
9673
9674 for (i = 0; i < 256; i++)
9675 breakat_flags[i] = FALSE;
9676
9677 if (p_breakat != NULL)
9678 for (c = p_breakat; *c; c++)
9679 breakat_flags[*c] = TRUE;
9680}
9681
9682# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009683 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009684# endif
9685
9686#endif
9687
9688/*
9689 * Check an option that can be a range of string values.
9690 *
9691 * Return OK for correct value, FAIL otherwise.
9692 * Empty is always OK.
9693 */
9694 static int
9695check_opt_strings(val, values, list)
9696 char_u *val;
9697 char **values;
9698 int list; /* when TRUE: accept a list of values */
9699{
9700 return opt_strings_flags(val, values, NULL, list);
9701}
9702
9703/*
9704 * Handle an option that can be a range of string values.
9705 * Set a flag in "*flagp" for each string present.
9706 *
9707 * Return OK for correct value, FAIL otherwise.
9708 * Empty is always OK.
9709 */
9710 static int
9711opt_strings_flags(val, values, flagp, list)
9712 char_u *val; /* new value */
9713 char **values; /* array of valid string values */
9714 unsigned *flagp;
9715 int list; /* when TRUE: accept a list of values */
9716{
9717 int i;
9718 int len;
9719 unsigned new_flags = 0;
9720
9721 while (*val)
9722 {
9723 for (i = 0; ; ++i)
9724 {
9725 if (values[i] == NULL) /* val not found in values[] */
9726 return FAIL;
9727
9728 len = (int)STRLEN(values[i]);
9729 if (STRNCMP(values[i], val, len) == 0
9730 && ((list && val[len] == ',') || val[len] == NUL))
9731 {
9732 val += len + (val[len] == ',');
9733 new_flags |= (1 << i);
9734 break; /* check next item in val list */
9735 }
9736 }
9737 }
9738 if (flagp != NULL)
9739 *flagp = new_flags;
9740
9741 return OK;
9742}
9743
9744/*
9745 * Read the 'wildmode' option, fill wim_flags[].
9746 */
9747 static int
9748check_opt_wim()
9749{
9750 char_u new_wim_flags[4];
9751 char_u *p;
9752 int i;
9753 int idx = 0;
9754
9755 for (i = 0; i < 4; ++i)
9756 new_wim_flags[i] = 0;
9757
9758 for (p = p_wim; *p; ++p)
9759 {
9760 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9761 ;
9762 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9763 return FAIL;
9764 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9765 new_wim_flags[idx] |= WIM_LONGEST;
9766 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9767 new_wim_flags[idx] |= WIM_FULL;
9768 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9769 new_wim_flags[idx] |= WIM_LIST;
9770 else
9771 return FAIL;
9772 p += i;
9773 if (*p == NUL)
9774 break;
9775 if (*p == ',')
9776 {
9777 if (idx == 3)
9778 return FAIL;
9779 ++idx;
9780 }
9781 }
9782
9783 /* fill remaining entries with last flag */
9784 while (idx < 3)
9785 {
9786 new_wim_flags[idx + 1] = new_wim_flags[idx];
9787 ++idx;
9788 }
9789
9790 /* only when there are no errors, wim_flags[] is changed */
9791 for (i = 0; i < 4; ++i)
9792 wim_flags[i] = new_wim_flags[i];
9793 return OK;
9794}
9795
9796/*
9797 * Check if backspacing over something is allowed.
9798 */
9799 int
9800can_bs(what)
9801 int what; /* BS_INDENT, BS_EOL or BS_START */
9802{
9803 switch (*p_bs)
9804 {
9805 case '2': return TRUE;
9806 case '1': return (what != BS_START);
9807 case '0': return FALSE;
9808 }
9809 return vim_strchr(p_bs, what) != NULL;
9810}
9811
9812/*
9813 * Save the current values of 'fileformat' and 'fileencoding', so that we know
9814 * the file must be considered changed when the value is different.
9815 */
9816 void
9817save_file_ff(buf)
9818 buf_T *buf;
9819{
9820 buf->b_start_ffc = *buf->b_p_ff;
9821 buf->b_start_eol = buf->b_p_eol;
9822#ifdef FEAT_MBYTE
9823 /* Only use free/alloc when necessary, they take time. */
9824 if (buf->b_start_fenc == NULL
9825 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9826 {
9827 vim_free(buf->b_start_fenc);
9828 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9829 }
9830#endif
9831}
9832
9833/*
9834 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9835 * from when editing started (save_file_ff() called).
9836 * Also when 'endofline' was changed and 'binary' is set.
9837 * Don't consider a new, empty buffer to be changed.
9838 */
9839 int
9840file_ff_differs(buf)
9841 buf_T *buf;
9842{
9843 if ((buf->b_flags & BF_NEW)
9844 && buf->b_ml.ml_line_count == 1
9845 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
9846 return FALSE;
9847 if (buf->b_start_ffc != *buf->b_p_ff)
9848 return TRUE;
9849 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
9850 return TRUE;
9851#ifdef FEAT_MBYTE
9852 if (buf->b_start_fenc == NULL)
9853 return (*buf->b_p_fenc != NUL);
9854 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
9855#else
9856 return FALSE;
9857#endif
9858}
9859
9860/*
9861 * return OK if "p" is a valid fileformat name, FAIL otherwise.
9862 */
9863 int
9864check_ff_value(p)
9865 char_u *p;
9866{
9867 return check_opt_strings(p, p_ff_values, FALSE);
9868}