blob: 8553771ae6ac7fc38bf6cfe99f2bb90c9ed15841 [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] = '/';
6648 psepsN[0] = '\\';
6649 }
6650 else
6651 {
6652 psepc = '\\';
6653 psepcN = '/';
6654 pseps[0] = '\\';
6655 psepsN[0] = '/';
6656 }
6657
6658 /* need to adjust the file name arguments and buffer names. */
6659 buflist_slash_adjust();
6660 alist_slash_adjust();
6661# ifdef FEAT_EVAL
6662 scriptnames_slash_adjust();
6663# endif
6664 }
6665#endif
6666
6667 /* If 'wrap' is set, set w_leftcol to zero. */
6668 else if ((int *)varp == &curwin->w_p_wrap)
6669 {
6670 if (curwin->w_p_wrap)
6671 curwin->w_leftcol = 0;
6672 }
6673
6674#ifdef FEAT_WINDOWS
6675 else if ((int *)varp == &p_ea)
6676 {
6677 if (p_ea && !old_value)
6678 win_equal(curwin, FALSE, 0);
6679 }
6680#endif
6681
6682 else if ((int *)varp == &p_wiv)
6683 {
6684 /*
6685 * When 'weirdinvert' changed, set/reset 't_xs'.
6686 * Then set 'weirdinvert' according to value of 't_xs'.
6687 */
6688 if (p_wiv && !old_value)
6689 T_XS = (char_u *)"y";
6690 else if (!p_wiv && old_value)
6691 T_XS = empty_option;
6692 p_wiv = (*T_XS != NUL);
6693 }
6694
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006695#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696 else if ((int *)varp == &p_beval)
6697 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698 if (p_beval == TRUE)
6699 gui_mch_enable_beval_area(balloonEval);
6700 else
6701 gui_mch_disable_beval_area(balloonEval);
6702 }
6703
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006704# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006705 else if ((int *)varp == &p_acd)
6706 {
6707 if (p_acd && curbuf->b_ffname != NULL
6708 && vim_chdirfile(curbuf->b_ffname) == OK)
6709 shorten_fnames(TRUE);
6710 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006711# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006712#endif
6713
6714#ifdef FEAT_DIFF
6715 /* 'diff' */
6716 else if ((int *)varp == &curwin->w_p_diff)
6717 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006718 /* May add or remove the buffer from the list of diff buffers. */
6719 diff_buf_adjust(curwin);
6720# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721 if (foldmethodIsDiff(curwin))
6722 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006723# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006724 }
6725#endif
6726
6727#ifdef USE_IM_CONTROL
6728 /* 'imdisable' */
6729 else if ((int *)varp == &p_imdisable)
6730 {
6731 /* Only de-activate it here, it will be enabled when changing mode. */
6732 if (p_imdisable)
6733 im_set_active(FALSE);
6734 }
6735#endif
6736
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006737#ifdef FEAT_SYN_HL
6738 /* 'spell' */
6739 else if ((int *)varp == &curwin->w_p_spell)
6740 {
6741 if (curwin->w_p_spell)
6742 {
6743 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00006744
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006745 if (errmsg != NULL)
6746 EMSG(_(errmsg));
6747 }
6748 }
6749#endif
6750
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751#ifdef FEAT_FKMAP
6752 else if ((int *)varp == &p_altkeymap)
6753 {
6754 if (old_value != p_altkeymap)
6755 {
6756 if (!p_altkeymap)
6757 {
6758 p_hkmap = p_fkmap;
6759 p_fkmap = 0;
6760 }
6761 else
6762 {
6763 p_fkmap = p_hkmap;
6764 p_hkmap = 0;
6765 }
6766 (void)init_chartab();
6767 }
6768 }
6769
6770 /*
6771 * In case some second language keymapping options have changed, check
6772 * and correct the setting in a consistent way.
6773 */
6774
6775 /*
6776 * If hkmap or fkmap are set, reset Arabic keymapping.
6777 */
6778 if ((p_hkmap || p_fkmap) && p_altkeymap)
6779 {
6780 p_altkeymap = p_fkmap;
6781# ifdef FEAT_ARABIC
6782 curwin->w_p_arab = FALSE;
6783# endif
6784 (void)init_chartab();
6785 }
6786
6787 /*
6788 * If hkmap set, reset Farsi keymapping.
6789 */
6790 if (p_hkmap && p_altkeymap)
6791 {
6792 p_altkeymap = 0;
6793 p_fkmap = 0;
6794# ifdef FEAT_ARABIC
6795 curwin->w_p_arab = FALSE;
6796# endif
6797 (void)init_chartab();
6798 }
6799
6800 /*
6801 * If fkmap set, reset Hebrew keymapping.
6802 */
6803 if (p_fkmap && !p_altkeymap)
6804 {
6805 p_altkeymap = 1;
6806 p_hkmap = 0;
6807# ifdef FEAT_ARABIC
6808 curwin->w_p_arab = FALSE;
6809# endif
6810 (void)init_chartab();
6811 }
6812#endif
6813
6814#ifdef FEAT_ARABIC
6815 if ((int *)varp == &curwin->w_p_arab)
6816 {
6817 if (curwin->w_p_arab)
6818 {
6819 /*
6820 * 'arabic' is set, handle various sub-settings.
6821 */
6822 if (!p_tbidi)
6823 {
6824 /* set rightleft mode */
6825 if (!curwin->w_p_rl)
6826 {
6827 curwin->w_p_rl = TRUE;
6828 changed_window_setting();
6829 }
6830
6831 /* Enable Arabic shaping (major part of what Arabic requires) */
6832 if (!p_arshape)
6833 {
6834 p_arshape = TRUE;
6835 redraw_later_clear();
6836 }
6837 }
6838
6839 /* Arabic requires a utf-8 encoding, inform the user if its not
6840 * set. */
6841 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006842 {
6843 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6845 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847
6848# ifdef FEAT_MBYTE
6849 /* set 'delcombine' */
6850 p_deco = TRUE;
6851# endif
6852
6853# ifdef FEAT_KEYMAP
6854 /* Force-set the necessary keymap for arabic */
6855 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
6856 OPT_LOCAL);
6857# endif
6858# ifdef FEAT_FKMAP
6859 p_altkeymap = 0;
6860 p_hkmap = 0;
6861 p_fkmap = 0;
6862 (void)init_chartab();
6863# endif
6864 }
6865 else
6866 {
6867 /*
6868 * 'arabic' is reset, handle various sub-settings.
6869 */
6870 if (!p_tbidi)
6871 {
6872 /* reset rightleft mode */
6873 if (curwin->w_p_rl)
6874 {
6875 curwin->w_p_rl = FALSE;
6876 changed_window_setting();
6877 }
6878
6879 /* 'arabicshape' isn't reset, it is a global option and
6880 * another window may still need it "on". */
6881 }
6882
6883 /* 'delcombine' isn't reset, it is a global option and another
6884 * window may still want it "on". */
6885
6886# ifdef FEAT_KEYMAP
6887 /* Revert to the default keymap */
6888 curbuf->b_p_iminsert = B_IMODE_NONE;
6889 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6890# endif
6891 }
6892 }
6893#endif
6894
6895 /*
6896 * End of handling side effects for bool options.
6897 */
6898
6899 options[opt_idx].flags |= P_WAS_SET;
6900
6901 comp_col(); /* in case 'ruler' or 'showcmd' changed */
6902 if (curwin->w_curswant != MAXCOL)
6903 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
6904 check_redraw(options[opt_idx].flags);
6905
6906 return NULL;
6907}
6908
6909/*
6910 * Set the value of a number option, and take care of side effects.
6911 * Returns NULL for success, or an error message for an error.
6912 */
6913 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00006914set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006915 int opt_idx; /* index in options[] table */
6916 char_u *varp; /* pointer to the option variable */
6917 long value; /* new value */
6918 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00006919 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
6921 OPT_MODELINE */
6922{
6923 char_u *errmsg = NULL;
6924 long old_value = *(long *)varp;
6925 long old_Rows = Rows; /* remember old Rows */
6926 long old_Columns = Columns; /* remember old Columns */
6927 long *pp = (long *)varp;
6928
6929#ifdef FEAT_GUI
6930 need_mouse_correct = TRUE;
6931#endif
6932
6933 *pp = value;
6934#ifdef FEAT_EVAL
6935 /* Remember where the option was set. */
6936 options[opt_idx].scriptID = current_SID;
6937#endif
6938
6939 if (curbuf->b_p_sw <= 0)
6940 {
6941 errmsg = e_positive;
6942 curbuf->b_p_sw = curbuf->b_p_ts;
6943 }
6944
6945 /*
6946 * Number options that need some action when changed
6947 */
6948#ifdef FEAT_WINDOWS
6949 if (pp == &p_wh || pp == &p_hh)
6950 {
6951 if (p_wh < 1)
6952 {
6953 errmsg = e_positive;
6954 p_wh = 1;
6955 }
6956 if (p_wmh > p_wh)
6957 {
6958 errmsg = e_winheight;
6959 p_wh = p_wmh;
6960 }
6961 if (p_hh < 0)
6962 {
6963 errmsg = e_positive;
6964 p_hh = 0;
6965 }
6966
6967 /* Change window height NOW */
6968 if (lastwin != firstwin)
6969 {
6970 if (pp == &p_wh && curwin->w_height < p_wh)
6971 win_setheight((int)p_wh);
6972 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
6973 win_setheight((int)p_hh);
6974 }
6975 }
6976
6977 /* 'winminheight' */
6978 else if (pp == &p_wmh)
6979 {
6980 if (p_wmh < 0)
6981 {
6982 errmsg = e_positive;
6983 p_wmh = 0;
6984 }
6985 if (p_wmh > p_wh)
6986 {
6987 errmsg = e_winheight;
6988 p_wmh = p_wh;
6989 }
6990 win_setminheight();
6991 }
6992
6993# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006994 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006995 {
6996 if (p_wiw < 1)
6997 {
6998 errmsg = e_positive;
6999 p_wiw = 1;
7000 }
7001 if (p_wmw > p_wiw)
7002 {
7003 errmsg = e_winwidth;
7004 p_wiw = p_wmw;
7005 }
7006
7007 /* Change window width NOW */
7008 if (lastwin != firstwin && curwin->w_width < p_wiw)
7009 win_setwidth((int)p_wiw);
7010 }
7011
7012 /* 'winminwidth' */
7013 else if (pp == &p_wmw)
7014 {
7015 if (p_wmw < 0)
7016 {
7017 errmsg = e_positive;
7018 p_wmw = 0;
7019 }
7020 if (p_wmw > p_wiw)
7021 {
7022 errmsg = e_winwidth;
7023 p_wmw = p_wiw;
7024 }
7025 win_setminheight();
7026 }
7027# endif
7028
7029#endif
7030
7031#ifdef FEAT_WINDOWS
7032 /* (re)set last window status line */
7033 else if (pp == &p_ls)
7034 {
7035 last_status(FALSE);
7036 }
7037#endif
7038
7039#ifdef FEAT_GUI
7040 else if (pp == &p_linespace)
7041 {
7042 if (gui.in_use && gui_mch_adjust_charsize() == OK)
7043 gui_set_shellsize(FALSE, FALSE);
7044 }
7045#endif
7046
7047#ifdef FEAT_FOLDING
7048 /* 'foldlevel' */
7049 else if (pp == &curwin->w_p_fdl)
7050 {
7051 if (curwin->w_p_fdl < 0)
7052 curwin->w_p_fdl = 0;
7053 newFoldLevel();
7054 }
7055
7056 /* 'foldminlevel' */
7057 else if (pp == &curwin->w_p_fml)
7058 {
7059 foldUpdateAll(curwin);
7060 }
7061
7062 /* 'foldnestmax' */
7063 else if (pp == &curwin->w_p_fdn)
7064 {
7065 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7066 foldUpdateAll(curwin);
7067 }
7068
7069 /* 'foldcolumn' */
7070 else if (pp == &curwin->w_p_fdc)
7071 {
7072 if (curwin->w_p_fdc < 0)
7073 {
7074 errmsg = e_positive;
7075 curwin->w_p_fdc = 0;
7076 }
7077 else if (curwin->w_p_fdc > 12)
7078 {
7079 errmsg = e_invarg;
7080 curwin->w_p_fdc = 12;
7081 }
7082 }
7083
7084 /* 'shiftwidth' or 'tabstop' */
7085 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7086 {
7087 if (foldmethodIsIndent(curwin))
7088 foldUpdateAll(curwin);
7089 }
7090#endif /* FEAT_FOLDING */
7091
7092 else if (pp == &curbuf->b_p_iminsert)
7093 {
7094 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7095 {
7096 errmsg = e_invarg;
7097 curbuf->b_p_iminsert = B_IMODE_NONE;
7098 }
7099 p_iminsert = curbuf->b_p_iminsert;
7100 if (termcap_active) /* don't do this in the alternate screen */
7101 showmode();
7102#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7103 /* Show/unshow value of 'keymap' in status lines. */
7104 status_redraw_curbuf();
7105#endif
7106 }
7107
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007108 else if (pp == &p_window)
7109 {
7110 if (p_window < 1)
7111 p_window = 1;
7112 else if (p_window >= Rows)
7113 p_window = Rows - 1;
7114 }
7115
Bram Moolenaar071d4272004-06-13 20:20:40 +00007116 else if (pp == &curbuf->b_p_imsearch)
7117 {
7118 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7119 {
7120 errmsg = e_invarg;
7121 curbuf->b_p_imsearch = B_IMODE_NONE;
7122 }
7123 p_imsearch = curbuf->b_p_imsearch;
7124 }
7125
7126#ifdef FEAT_TITLE
7127 /* if 'titlelen' has changed, redraw the title */
7128 else if (pp == &p_titlelen)
7129 {
7130 if (p_titlelen < 0)
7131 {
7132 errmsg = e_positive;
7133 p_titlelen = 85;
7134 }
7135 if (starting != NO_SCREEN && old_value != p_titlelen)
7136 need_maketitle = TRUE;
7137 }
7138#endif
7139
7140 /* if p_ch changed value, change the command line height */
7141 else if (pp == &p_ch)
7142 {
7143 if (p_ch < 1)
7144 {
7145 errmsg = e_positive;
7146 p_ch = 1;
7147 }
7148
7149 /* Only compute the new window layout when startup has been
7150 * completed. Otherwise the frame sizes may be wrong. */
7151 if (p_ch != old_value && full_screen
7152#ifdef FEAT_GUI
7153 && !gui.starting
7154#endif
7155 )
7156 command_height(old_value);
7157 }
7158
7159 /* when 'updatecount' changes from zero to non-zero, open swap files */
7160 else if (pp == &p_uc)
7161 {
7162 if (p_uc < 0)
7163 {
7164 errmsg = e_positive;
7165 p_uc = 100;
7166 }
7167 if (p_uc && !old_value)
7168 ml_open_files();
7169 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007170#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007171 else if (pp == &p_mzq)
7172 mzvim_reset_timer();
7173#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007174
7175 /* sync undo before 'undolevels' changes */
7176 else if (pp == &p_ul)
7177 {
7178 /* use the old value, otherwise u_sync() may not work properly */
7179 p_ul = old_value;
7180 u_sync();
7181 p_ul = value;
7182 }
7183
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007184#ifdef FEAT_LINEBREAK
7185 /* 'numberwidth' must be positive */
7186 else if (pp == &curwin->w_p_nuw)
7187 {
7188 if (curwin->w_p_nuw < 1)
7189 {
7190 errmsg = e_positive;
7191 curwin->w_p_nuw = 1;
7192 }
7193 if (curwin->w_p_nuw > 10)
7194 {
7195 errmsg = e_invarg;
7196 curwin->w_p_nuw = 10;
7197 }
7198 curwin->w_nrwidth_line_count = 0;
7199 }
7200#endif
7201
Bram Moolenaar071d4272004-06-13 20:20:40 +00007202 /*
7203 * Check the bounds for numeric options here
7204 */
7205 if (Rows < min_rows() && full_screen)
7206 {
7207 if (errbuf != NULL)
7208 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007209 vim_snprintf((char *)errbuf, errbuflen,
7210 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007211 errmsg = errbuf;
7212 }
7213 Rows = min_rows();
7214 }
7215 if (Columns < MIN_COLUMNS && full_screen)
7216 {
7217 if (errbuf != NULL)
7218 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007219 vim_snprintf((char *)errbuf, errbuflen,
7220 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007221 errmsg = errbuf;
7222 }
7223 Columns = MIN_COLUMNS;
7224 }
7225
7226#ifdef DJGPP
7227 /* avoid a crash by checking for a too large value of 'columns' */
7228 if (old_Columns != Columns && full_screen && term_console)
7229 mch_check_columns();
7230#endif
7231
7232 /*
7233 * If the screen (shell) height has been changed, assume it is the
7234 * physical screenheight.
7235 */
7236 if (old_Rows != Rows || old_Columns != Columns)
7237 {
7238 /* Changing the screen size is not allowed while updating the screen. */
7239 if (updating_screen)
7240 *pp = old_value;
7241 else if (full_screen
7242#ifdef FEAT_GUI
7243 && !gui.starting
7244#endif
7245 )
7246 set_shellsize((int)Columns, (int)Rows, TRUE);
7247 else
7248 {
7249 /* Postpone the resizing; check the size and cmdline position for
7250 * messages. */
7251 check_shellsize();
7252 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7253 cmdline_row = Rows - p_ch;
7254 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007255 if (p_window >= Rows)
7256 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007257 }
7258
7259 if (curbuf->b_p_sts < 0)
7260 {
7261 errmsg = e_positive;
7262 curbuf->b_p_sts = 0;
7263 }
7264 if (curbuf->b_p_ts <= 0)
7265 {
7266 errmsg = e_positive;
7267 curbuf->b_p_ts = 8;
7268 }
7269 if (curbuf->b_p_tw < 0)
7270 {
7271 errmsg = e_positive;
7272 curbuf->b_p_tw = 0;
7273 }
7274 if (p_tm < 0)
7275 {
7276 errmsg = e_positive;
7277 p_tm = 0;
7278 }
7279 if ((curwin->w_p_scr <= 0
7280 || (curwin->w_p_scr > curwin->w_height
7281 && curwin->w_height > 0))
7282 && full_screen)
7283 {
7284 if (pp == &(curwin->w_p_scr))
7285 {
7286 if (curwin->w_p_scr != 0)
7287 errmsg = e_scroll;
7288 win_comp_scroll(curwin);
7289 }
7290 /* If 'scroll' became invalid because of a side effect silently adjust
7291 * it. */
7292 else if (curwin->w_p_scr <= 0)
7293 curwin->w_p_scr = 1;
7294 else /* curwin->w_p_scr > curwin->w_height */
7295 curwin->w_p_scr = curwin->w_height;
7296 }
7297 if (p_report < 0)
7298 {
7299 errmsg = e_positive;
7300 p_report = 1;
7301 }
7302 if ((p_sj < 0 || p_sj >= Rows) && full_screen)
7303 {
7304 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7305 p_sj = Rows / 2;
7306 else
7307 {
7308 errmsg = e_scroll;
7309 p_sj = 1;
7310 }
7311 }
7312 if (p_so < 0 && full_screen)
7313 {
7314 errmsg = e_scroll;
7315 p_so = 0;
7316 }
7317 if (p_siso < 0 && full_screen)
7318 {
7319 errmsg = e_positive;
7320 p_siso = 0;
7321 }
7322#ifdef FEAT_CMDWIN
7323 if (p_cwh < 1)
7324 {
7325 errmsg = e_positive;
7326 p_cwh = 1;
7327 }
7328#endif
7329 if (p_ut < 0)
7330 {
7331 errmsg = e_positive;
7332 p_ut = 2000;
7333 }
7334 if (p_ss < 0)
7335 {
7336 errmsg = e_positive;
7337 p_ss = 0;
7338 }
7339
7340 /* May set global value for local option. */
7341 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7342 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7343
7344 options[opt_idx].flags |= P_WAS_SET;
7345
7346 comp_col(); /* in case 'columns' or 'ls' changed */
7347 if (curwin->w_curswant != MAXCOL)
7348 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7349 check_redraw(options[opt_idx].flags);
7350
7351 return errmsg;
7352}
7353
7354/*
7355 * Called after an option changed: check if something needs to be redrawn.
7356 */
7357 static void
7358check_redraw(flags)
7359 long_u flags;
7360{
7361 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7362 int clear = (flags & P_RCLR) == P_RCLR;
7363 int all = ((flags & P_RALL) == P_RALL || clear);
7364
7365#ifdef FEAT_WINDOWS
7366 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7367 status_redraw_all();
7368#endif
7369
7370 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7371 changed_window_setting();
7372 if (flags & P_RBUF)
7373 redraw_curbuf_later(NOT_VALID);
7374 if (clear)
7375 redraw_all_later(CLEAR);
7376 else if (all)
7377 redraw_all_later(NOT_VALID);
7378}
7379
7380/*
7381 * Find index for option 'arg'.
7382 * Return -1 if not found.
7383 */
7384 static int
7385findoption(arg)
7386 char_u *arg;
7387{
7388 int opt_idx;
7389 char *s, *p;
7390 static short quick_tab[27] = {0, 0}; /* quick access table */
7391 int is_term_opt;
7392
7393 /*
7394 * For first call: Initialize the quick-access table.
7395 * It contains the index for the first option that starts with a certain
7396 * letter. There are 26 letters, plus the first "t_" option.
7397 */
7398 if (quick_tab[1] == 0)
7399 {
7400 p = options[0].fullname;
7401 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7402 {
7403 if (s[0] != p[0])
7404 {
7405 if (s[0] == 't' && s[1] == '_')
7406 quick_tab[26] = opt_idx;
7407 else
7408 quick_tab[CharOrdLow(s[0])] = opt_idx;
7409 }
7410 p = s;
7411 }
7412 }
7413
7414 /*
7415 * Check for name starting with an illegal character.
7416 */
7417#ifdef EBCDIC
7418 if (!islower(arg[0]))
7419#else
7420 if (arg[0] < 'a' || arg[0] > 'z')
7421#endif
7422 return -1;
7423
7424 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7425 if (is_term_opt)
7426 opt_idx = quick_tab[26];
7427 else
7428 opt_idx = quick_tab[CharOrdLow(arg[0])];
7429 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7430 {
7431 if (STRCMP(arg, s) == 0) /* match full name */
7432 break;
7433 }
7434 if (s == NULL && !is_term_opt)
7435 {
7436 opt_idx = quick_tab[CharOrdLow(arg[0])];
7437 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7438 {
7439 s = options[opt_idx].shortname;
7440 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7441 break;
7442 s = NULL;
7443 }
7444 }
7445 if (s == NULL)
7446 opt_idx = -1;
7447 return opt_idx;
7448}
7449
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007450#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007451/*
7452 * Get the value for an option.
7453 *
7454 * Returns:
7455 * Number or Toggle option: 1, *numval gets value.
7456 * String option: 0, *stringval gets allocated string.
7457 * Hidden Number or Toggle option: -1.
7458 * hidden String option: -2.
7459 * unknown option: -3.
7460 */
7461 int
7462get_option_value(name, numval, stringval, opt_flags)
7463 char_u *name;
7464 long *numval;
7465 char_u **stringval; /* NULL when only checking existance */
7466 int opt_flags;
7467{
7468 int opt_idx;
7469 char_u *varp;
7470
7471 opt_idx = findoption(name);
7472 if (opt_idx < 0) /* unknown option */
7473 return -3;
7474
7475 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7476
7477 if (options[opt_idx].flags & P_STRING)
7478 {
7479 if (varp == NULL) /* hidden option */
7480 return -2;
7481 if (stringval != NULL)
7482 {
7483#ifdef FEAT_CRYPT
7484 /* never return the value of the crypt key */
7485 if ((char_u **)varp == &curbuf->b_p_key)
7486 *stringval = vim_strsave((char_u *)"*****");
7487 else
7488#endif
7489 *stringval = vim_strsave(*(char_u **)(varp));
7490 }
7491 return 0;
7492 }
7493
7494 if (varp == NULL) /* hidden option */
7495 return -1;
7496 if (options[opt_idx].flags & P_NUM)
7497 *numval = *(long *)varp;
7498 else
7499 {
7500 /* Special case: 'modified' is b_changed, but we also want to consider
7501 * it set when 'ff' or 'fenc' changed. */
7502 if ((int *)varp == &curbuf->b_changed)
7503 *numval = curbufIsChanged();
7504 else
7505 *numval = *(int *)varp;
7506 }
7507 return 1;
7508}
7509#endif
7510
7511/*
7512 * Set the value of option "name".
7513 * Use "string" for string options, use "number" for other options.
7514 */
7515 void
7516set_option_value(name, number, string, opt_flags)
7517 char_u *name;
7518 long number;
7519 char_u *string;
7520 int opt_flags; /* OPT_LOCAL or 0 (both) */
7521{
7522 int opt_idx;
7523 char_u *varp;
7524 int flags;
7525
7526 opt_idx = findoption(name);
7527 if (opt_idx == -1)
7528 EMSG2(_("E355: Unknown option: %s"), name);
7529 else
7530 {
7531 flags = options[opt_idx].flags;
7532#ifdef HAVE_SANDBOX
7533 /* Disallow changing some options in the sandbox */
7534 if (sandbox > 0 && (flags & P_SECURE))
7535 EMSG(_(e_sandbox));
7536 else
7537#endif
7538 if (flags & P_STRING)
7539 set_string_option(opt_idx, string, opt_flags);
7540 else
7541 {
7542 varp = get_varp(&options[opt_idx]);
7543 if (varp != NULL) /* hidden option is not changed */
7544 {
7545 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00007546 (void)set_num_option(opt_idx, varp, number,
7547 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 else
7549 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7550 }
7551 }
7552 }
7553}
7554
7555/*
7556 * Get the terminal code for a terminal option.
7557 * Returns NULL when not found.
7558 */
7559 char_u *
7560get_term_code(tname)
7561 char_u *tname;
7562{
7563 int opt_idx;
7564 char_u *varp;
7565
7566 if (tname[0] != 't' || tname[1] != '_' ||
7567 tname[2] == NUL || tname[3] == NUL)
7568 return NULL;
7569 if ((opt_idx = findoption(tname)) >= 0)
7570 {
7571 varp = get_varp(&(options[opt_idx]));
7572 if (varp != NULL)
7573 varp = *(char_u **)(varp);
7574 return varp;
7575 }
7576 return find_termcode(tname + 2);
7577}
7578
7579 char_u *
7580get_highlight_default()
7581{
7582 int i;
7583
7584 i = findoption((char_u *)"hl");
7585 if (i >= 0)
7586 return options[i].def_val[VI_DEFAULT];
7587 return (char_u *)NULL;
7588}
7589
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007590#if defined(FEAT_MBYTE) || defined(PROTO)
7591 char_u *
7592get_encoding_default()
7593{
7594 int i;
7595
7596 i = findoption((char_u *)"enc");
7597 if (i >= 0)
7598 return options[i].def_val[VI_DEFAULT];
7599 return (char_u *)NULL;
7600}
7601#endif
7602
Bram Moolenaar071d4272004-06-13 20:20:40 +00007603/*
7604 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7605 */
7606 static int
7607find_key_option(arg)
7608 char_u *arg;
7609{
7610 int key;
7611 int modifiers;
7612
7613 /*
7614 * Don't use get_special_key_code() for t_xx, we don't want it to call
7615 * add_termcap_entry().
7616 */
7617 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7618 key = TERMCAP2KEY(arg[2], arg[3]);
7619 else
7620 {
7621 --arg; /* put arg at the '<' */
7622 modifiers = 0;
7623 key = find_special_key(&arg, &modifiers, TRUE);
7624 if (modifiers) /* can't handle modifiers here */
7625 key = 0;
7626 }
7627 return key;
7628}
7629
7630/*
7631 * if 'all' == 0: show changed options
7632 * if 'all' == 1: show all normal options
7633 * if 'all' == 2: show all terminal options
7634 */
7635 static void
7636showoptions(all, opt_flags)
7637 int all;
7638 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7639{
7640 struct vimoption *p;
7641 int col;
7642 int isterm;
7643 char_u *varp;
7644 struct vimoption **items;
7645 int item_count;
7646 int run;
7647 int row, rows;
7648 int cols;
7649 int i;
7650 int len;
7651
7652#define INC 20
7653#define GAP 3
7654
7655 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7656 PARAM_COUNT));
7657 if (items == NULL)
7658 return;
7659
7660 /* Highlight title */
7661 if (all == 2)
7662 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7663 else if (opt_flags & OPT_GLOBAL)
7664 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7665 else if (opt_flags & OPT_LOCAL)
7666 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7667 else
7668 MSG_PUTS_TITLE(_("\n--- Options ---"));
7669
7670 /*
7671 * do the loop two times:
7672 * 1. display the short items
7673 * 2. display the long items (only strings and numbers)
7674 */
7675 for (run = 1; run <= 2 && !got_int; ++run)
7676 {
7677 /*
7678 * collect the items in items[]
7679 */
7680 item_count = 0;
7681 for (p = &options[0]; p->fullname != NULL; p++)
7682 {
7683 varp = NULL;
7684 isterm = istermoption(p);
7685 if (opt_flags != 0)
7686 {
7687 if (p->indir != PV_NONE && !isterm)
7688 varp = get_varp_scope(p, opt_flags);
7689 }
7690 else
7691 varp = get_varp(p);
7692 if (varp != NULL
7693 && ((all == 2 && isterm)
7694 || (all == 1 && !isterm)
7695 || (all == 0 && !optval_default(p, varp))))
7696 {
7697 if (p->flags & P_BOOL)
7698 len = 1; /* a toggle option fits always */
7699 else
7700 {
7701 option_value2string(p, opt_flags);
7702 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7703 }
7704 if ((len <= INC - GAP && run == 1) ||
7705 (len > INC - GAP && run == 2))
7706 items[item_count++] = p;
7707 }
7708 }
7709
7710 /*
7711 * display the items
7712 */
7713 if (run == 1)
7714 {
7715 cols = (Columns + GAP - 3) / INC;
7716 if (cols == 0)
7717 cols = 1;
7718 rows = (item_count + cols - 1) / cols;
7719 }
7720 else /* run == 2 */
7721 rows = item_count;
7722 for (row = 0; row < rows && !got_int; ++row)
7723 {
7724 msg_putchar('\n'); /* go to next line */
7725 if (got_int) /* 'q' typed in more */
7726 break;
7727 col = 0;
7728 for (i = row; i < item_count; i += rows)
7729 {
7730 msg_col = col; /* make columns */
7731 showoneopt(items[i], opt_flags);
7732 col += INC;
7733 }
7734 out_flush();
7735 ui_breakcheck();
7736 }
7737 }
7738 vim_free(items);
7739}
7740
7741/*
7742 * Return TRUE if option "p" has its default value.
7743 */
7744 static int
7745optval_default(p, varp)
7746 struct vimoption *p;
7747 char_u *varp;
7748{
7749 int dvi;
7750
7751 if (varp == NULL)
7752 return TRUE; /* hidden option is always at default */
7753 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7754 if (p->flags & P_NUM)
7755 return (*(long *)varp == (long)p->def_val[dvi]);
7756 if (p->flags & P_BOOL)
7757 /* the cast to long is required for Manx C */
7758 return (*(int *)varp == (int)(long)p->def_val[dvi]);
7759 /* P_STRING */
7760 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7761}
7762
7763/*
7764 * showoneopt: show the value of one option
7765 * must not be called with a hidden option!
7766 */
7767 static void
7768showoneopt(p, opt_flags)
7769 struct vimoption *p;
7770 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
7771{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007772 char_u *varp;
7773 int save_silent = silent_mode;
7774
7775 silent_mode = FALSE;
7776 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777
7778 varp = get_varp_scope(p, opt_flags);
7779
7780 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7781 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7782 ? !curbufIsChanged() : !*(int *)varp))
7783 MSG_PUTS("no");
7784 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7785 MSG_PUTS("--");
7786 else
7787 MSG_PUTS(" ");
7788 MSG_PUTS(p->fullname);
7789 if (!(p->flags & P_BOOL))
7790 {
7791 msg_putchar('=');
7792 /* put value string in NameBuff */
7793 option_value2string(p, opt_flags);
7794 msg_outtrans(NameBuff);
7795 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007796
7797 silent_mode = save_silent;
7798 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799}
7800
7801/*
7802 * Write modified options as ":set" commands to a file.
7803 *
7804 * There are three values for "opt_flags":
7805 * OPT_GLOBAL: Write global option values and fresh values of
7806 * buffer-local options (used for start of a session
7807 * file).
7808 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7809 * curwin (used for a vimrc file).
7810 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
7811 * and local values for window-local options of
7812 * curwin. Local values are also written when at the
7813 * default value, because a modeline or autocommand
7814 * may have set them when doing ":edit file" and the
7815 * user has set them back at the default or fresh
7816 * value.
7817 * When "local_only" is TRUE, don't write fresh
7818 * values, only local values (for ":mkview").
7819 * (fresh value = value used for a new buffer or window for a local option).
7820 *
7821 * Return FAIL on error, OK otherwise.
7822 */
7823 int
7824makeset(fd, opt_flags, local_only)
7825 FILE *fd;
7826 int opt_flags;
7827 int local_only;
7828{
7829 struct vimoption *p;
7830 char_u *varp; /* currently used value */
7831 char_u *varp_fresh; /* local value */
7832 char_u *varp_local = NULL; /* fresh value */
7833 char *cmd;
7834 int round;
7835
7836 /*
7837 * The options that don't have a default (terminal name, columns, lines)
7838 * are never written. Terminal options are also not written.
7839 */
7840 for (p = &options[0]; !istermoption(p); p++)
7841 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7842 {
7843 /* skip global option when only doing locals */
7844 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7845 continue;
7846
7847 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
7848 * file, they are always buffer-specific. */
7849 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
7850 continue;
7851
7852 /* Global values are only written when not at the default value. */
7853 varp = get_varp_scope(p, opt_flags);
7854 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
7855 continue;
7856
7857 round = 2;
7858 if (p->indir != PV_NONE)
7859 {
7860 if (p->var == VAR_WIN)
7861 {
7862 /* skip window-local option when only doing globals */
7863 if (!(opt_flags & OPT_LOCAL))
7864 continue;
7865 /* When fresh value of window-local option is not at the
7866 * default, need to write it too. */
7867 if (!(opt_flags & OPT_GLOBAL) && !local_only)
7868 {
7869 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
7870 if (!optval_default(p, varp_fresh))
7871 {
7872 round = 1;
7873 varp_local = varp;
7874 varp = varp_fresh;
7875 }
7876 }
7877 }
7878 }
7879
7880 /* Round 1: fresh value for window-local options.
7881 * Round 2: other values */
7882 for ( ; round <= 2; varp = varp_local, ++round)
7883 {
7884 if (round == 1 || (opt_flags & OPT_GLOBAL))
7885 cmd = "set";
7886 else
7887 cmd = "setlocal";
7888
7889 if (p->flags & P_BOOL)
7890 {
7891 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
7892 return FAIL;
7893 }
7894 else if (p->flags & P_NUM)
7895 {
7896 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
7897 return FAIL;
7898 }
7899 else /* P_STRING */
7900 {
7901 /* Don't set 'syntax' and 'filetype' again if the value is
7902 * already right, avoids reloading the syntax file. */
7903 if (p->indir == PV_SYN || p->indir == PV_FT)
7904 {
7905 if (fprintf(fd, "if &%s != '%s'", p->fullname,
7906 *(char_u **)(varp)) < 0
7907 || put_eol(fd) < 0)
7908 return FAIL;
7909 }
7910 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
7911 (p->flags & P_EXPAND) != 0) == FAIL)
7912 return FAIL;
7913 if (p->indir == PV_SYN || p->indir == PV_FT)
7914 {
7915 if (put_line(fd, "endif") == FAIL)
7916 return FAIL;
7917 }
7918 }
7919 }
7920 }
7921 return OK;
7922}
7923
7924#if defined(FEAT_FOLDING) || defined(PROTO)
7925/*
7926 * Generate set commands for the local fold options only. Used when
7927 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
7928 */
7929 int
7930makefoldset(fd)
7931 FILE *fd;
7932{
7933 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
7934# ifdef FEAT_EVAL
7935 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
7936 == FAIL
7937# endif
7938 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
7939 == FAIL
7940 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
7941 == FAIL
7942 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
7943 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
7944 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
7945 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
7946 )
7947 return FAIL;
7948
7949 return OK;
7950}
7951#endif
7952
7953 static int
7954put_setstring(fd, cmd, name, valuep, expand)
7955 FILE *fd;
7956 char *cmd;
7957 char *name;
7958 char_u **valuep;
7959 int expand;
7960{
7961 char_u *s;
7962 char_u buf[MAXPATHL];
7963
7964 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7965 return FAIL;
7966 if (*valuep != NULL)
7967 {
7968 /* Output 'pastetoggle' as key names. For other
7969 * options some characters have to be escaped with
7970 * CTRL-V or backslash */
7971 if (valuep == &p_pt)
7972 {
7973 s = *valuep;
7974 while (*s != NUL)
7975 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
7976 return FAIL;
7977 }
7978 else if (expand)
7979 {
7980 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
7981 if (put_escstr(fd, buf, 2) == FAIL)
7982 return FAIL;
7983 }
7984 else if (put_escstr(fd, *valuep, 2) == FAIL)
7985 return FAIL;
7986 }
7987 if (put_eol(fd) < 0)
7988 return FAIL;
7989 return OK;
7990}
7991
7992 static int
7993put_setnum(fd, cmd, name, valuep)
7994 FILE *fd;
7995 char *cmd;
7996 char *name;
7997 long *valuep;
7998{
7999 long wc;
8000
8001 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8002 return FAIL;
8003 if (wc_use_keyname((char_u *)valuep, &wc))
8004 {
8005 /* print 'wildchar' and 'wildcharm' as a key name */
8006 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8007 return FAIL;
8008 }
8009 else if (fprintf(fd, "%ld", *valuep) < 0)
8010 return FAIL;
8011 if (put_eol(fd) < 0)
8012 return FAIL;
8013 return OK;
8014}
8015
8016 static int
8017put_setbool(fd, cmd, name, value)
8018 FILE *fd;
8019 char *cmd;
8020 char *name;
8021 int value;
8022{
8023 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8024 || put_eol(fd) < 0)
8025 return FAIL;
8026 return OK;
8027}
8028
8029/*
8030 * Clear all the terminal options.
8031 * If the option has been allocated, free the memory.
8032 * Terminal options are never hidden or indirect.
8033 */
8034 void
8035clear_termoptions()
8036{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 /*
8038 * Reset a few things before clearing the old options. This may cause
8039 * outputting a few things that the terminal doesn't understand, but the
8040 * screen will be cleared later, so this is OK.
8041 */
8042#ifdef FEAT_MOUSE_TTY
8043 mch_setmouse(FALSE); /* switch mouse off */
8044#endif
8045#ifdef FEAT_TITLE
8046 mch_restore_title(3); /* restore window titles */
8047#endif
8048#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8049 /* When starting the GUI close the display opened for the clipboard.
8050 * After restoring the title, because that will need the display. */
8051 if (gui.starting)
8052 clear_xterm_clip();
8053#endif
8054#ifdef WIN3264
8055 /*
8056 * Check if this is allowed now.
8057 */
8058 if (can_end_termcap_mode(FALSE) == TRUE)
8059#endif
8060 stoptermcap(); /* stop termcap mode */
8061
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008062 free_termoptions();
8063}
8064
8065 void
8066free_termoptions()
8067{
8068 struct vimoption *p;
8069
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 for (p = &options[0]; p->fullname != NULL; p++)
8071 if (istermoption(p))
8072 {
8073 if (p->flags & P_ALLOCED)
8074 free_string_option(*(char_u **)(p->var));
8075 if (p->flags & P_DEF_ALLOCED)
8076 free_string_option(p->def_val[VI_DEFAULT]);
8077 *(char_u **)(p->var) = empty_option;
8078 p->def_val[VI_DEFAULT] = empty_option;
8079 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8080 }
8081 clear_termcodes();
8082}
8083
8084/*
8085 * Set the terminal option defaults to the current value.
8086 * Used after setting the terminal name.
8087 */
8088 void
8089set_term_defaults()
8090{
8091 struct vimoption *p;
8092
8093 for (p = &options[0]; p->fullname != NULL; p++)
8094 {
8095 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8096 {
8097 if (p->flags & P_DEF_ALLOCED)
8098 {
8099 free_string_option(p->def_val[VI_DEFAULT]);
8100 p->flags &= ~P_DEF_ALLOCED;
8101 }
8102 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8103 if (p->flags & P_ALLOCED)
8104 {
8105 p->flags |= P_DEF_ALLOCED;
8106 p->flags &= ~P_ALLOCED; /* don't free the value now */
8107 }
8108 }
8109 }
8110}
8111
8112/*
8113 * return TRUE if 'p' starts with 't_'
8114 */
8115 static int
8116istermoption(p)
8117 struct vimoption *p;
8118{
8119 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8120}
8121
8122/*
8123 * Compute columns for ruler and shown command. 'sc_col' is also used to
8124 * decide what the maximum length of a message on the status line can be.
8125 * If there is a status line for the last window, 'sc_col' is independent
8126 * of 'ru_col'.
8127 */
8128
8129#define COL_RULER 17 /* columns needed by standard ruler */
8130
8131 void
8132comp_col()
8133{
8134#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8135 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8136
8137 sc_col = 0;
8138 ru_col = 0;
8139 if (p_ru)
8140 {
8141#ifdef FEAT_STL_OPT
8142 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8143#else
8144 ru_col = COL_RULER + 1;
8145#endif
8146 /* no last status line, adjust sc_col */
8147 if (!last_has_status)
8148 sc_col = ru_col;
8149 }
8150 if (p_sc)
8151 {
8152 sc_col += SHOWCMD_COLS;
8153 if (!p_ru || last_has_status) /* no need for separating space */
8154 ++sc_col;
8155 }
8156 sc_col = Columns - sc_col;
8157 ru_col = Columns - ru_col;
8158 if (sc_col <= 0) /* screen too narrow, will become a mess */
8159 sc_col = 1;
8160 if (ru_col <= 0)
8161 ru_col = 1;
8162#else
8163 sc_col = Columns;
8164 ru_col = Columns;
8165#endif
8166}
8167
8168/*
8169 * Get pointer to option variable, depending on local or global scope.
8170 */
8171 static char_u *
8172get_varp_scope(p, opt_flags)
8173 struct vimoption *p;
8174 int opt_flags;
8175{
8176 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8177 {
8178 if (p->var == VAR_WIN)
8179 return (char_u *)GLOBAL_WO(get_varp(p));
8180 return p->var;
8181 }
8182 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
8183 {
8184 switch ((int)p->indir)
8185 {
8186#ifdef FEAT_QUICKFIX
8187 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
8188 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
8189 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
8190#endif
8191 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
8192 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
8193 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
8194 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
8195 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
8196#ifdef FEAT_FIND_ID
8197 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
8198 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
8199#endif
8200#ifdef FEAT_INS_EXPAND
8201 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
8202 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
8203#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008204#ifdef FEAT_STL_OPT
8205 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
8206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207 }
8208 return NULL; /* "cannot happen" */
8209 }
8210 return get_varp(p);
8211}
8212
8213/*
8214 * Get pointer to option variable.
8215 */
8216 static char_u *
8217get_varp(p)
8218 struct vimoption *p;
8219{
8220 /* hidden option, always return NULL */
8221 if (p->var == NULL)
8222 return NULL;
8223
8224 switch ((int)p->indir)
8225 {
8226 case PV_NONE: return p->var;
8227
8228 /* global option with local value: use local value if it's been set */
8229 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
8230 ? (char_u *)&curbuf->b_p_ep : p->var;
8231 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
8232 ? (char_u *)&curbuf->b_p_kp : p->var;
8233 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
8234 ? (char_u *)&(curbuf->b_p_path) : p->var;
8235 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
8236 ? (char_u *)&(curbuf->b_p_ar) : p->var;
8237 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
8238 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8239#ifdef FEAT_FIND_ID
8240 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
8241 ? (char_u *)&(curbuf->b_p_def) : p->var;
8242 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
8243 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8244#endif
8245#ifdef FEAT_INS_EXPAND
8246 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
8247 ? (char_u *)&(curbuf->b_p_dict) : p->var;
8248 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
8249 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8250#endif
8251#ifdef FEAT_QUICKFIX
8252 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
8253 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8254 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
8255 ? (char_u *)&(curbuf->b_p_mp) : p->var;
8256 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8257 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8258#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008259#ifdef FEAT_STL_OPT
8260 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8261 ? (char_u *)&(curwin->w_p_stl) : p->var;
8262#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263
8264#ifdef FEAT_ARABIC
8265 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8266#endif
8267 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008268#ifdef FEAT_SYN_HL
8269 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8270#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008271#ifdef FEAT_DIFF
8272 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8273#endif
8274#ifdef FEAT_FOLDING
8275 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8276 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8277 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8278 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8279 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8280 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8281 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8282# ifdef FEAT_EVAL
8283 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8284 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8285# endif
8286 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8287#endif
8288 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008289#ifdef FEAT_LINEBREAK
8290 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8291#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008292#if defined(FEAT_WINDOWS)
8293 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8294#endif
8295#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8296 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8297#endif
8298#ifdef FEAT_RIGHTLEFT
8299 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8300 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8301#endif
8302 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8303 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8304#ifdef FEAT_LINEBREAK
8305 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8306#endif
8307#ifdef FEAT_SCROLLBIND
8308 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8309#endif
8310
8311 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8312 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8313#ifdef FEAT_MBYTE
8314 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8315#endif
8316#if defined(FEAT_QUICKFIX)
8317 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8318 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8319#endif
8320 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8321 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8322#ifdef FEAT_CINDENT
8323 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8324 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8325 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8326#endif
8327#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8328 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8329#endif
8330#ifdef FEAT_COMMENTS
8331 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8332#endif
8333#ifdef FEAT_FOLDING
8334 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8335#endif
8336#ifdef FEAT_INS_EXPAND
8337 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8338#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008339#ifdef FEAT_COMPL_FUNC
8340 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
8341#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008342 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8343 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8344#ifdef FEAT_MBYTE
8345 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8346#endif
8347 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8348#ifdef FEAT_AUTOCMD
8349 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8350#endif
8351 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008352 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8354 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8355 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8356 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8357#ifdef FEAT_FIND_ID
8358# ifdef FEAT_EVAL
8359 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8360# endif
8361#endif
8362#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8363 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8364 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8365#endif
8366#ifdef FEAT_CRYPT
8367 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8368#endif
8369#ifdef FEAT_LISP
8370 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8371#endif
8372 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8373 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8374 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8375 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8376 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8377#ifdef FEAT_OSFILETYPE
8378 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8379#endif
8380 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008381#ifdef FEAT_TEXTOBJ
8382 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008384 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8385#ifdef FEAT_SMARTINDENT
8386 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8387#endif
8388#ifndef SHORT_FNAME
8389 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8390#endif
8391 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8392#ifdef FEAT_SEARCHPATH
8393 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8394#endif
8395 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8396#ifdef FEAT_SYN_HL
8397 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008398 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008399 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400#endif
8401 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8402 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8403 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8404 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8405 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8406#ifdef FEAT_KEYMAP
8407 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8408#endif
8409 default: EMSG(_("E356: get_varp ERROR"));
8410 }
8411 /* always return a valid pointer to avoid a crash! */
8412 return (char_u *)&(curbuf->b_p_wm);
8413}
8414
8415/*
8416 * Get the value of 'equalprg', either the buffer-local one or the global one.
8417 */
8418 char_u *
8419get_equalprg()
8420{
8421 if (*curbuf->b_p_ep == NUL)
8422 return p_ep;
8423 return curbuf->b_p_ep;
8424}
8425
8426#if defined(FEAT_WINDOWS) || defined(PROTO)
8427/*
8428 * Copy options from one window to another.
8429 * Used when splitting a window.
8430 */
8431 void
8432win_copy_options(wp_from, wp_to)
8433 win_T *wp_from;
8434 win_T *wp_to;
8435{
8436 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8437 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8438# ifdef FEAT_RIGHTLEFT
8439# ifdef FEAT_FKMAP
8440 /* Is this right? */
8441 wp_to->w_farsi = wp_from->w_farsi;
8442# endif
8443# endif
8444}
8445#endif
8446
8447/*
8448 * Copy the options from one winopt_T to another.
8449 * Doesn't free the old option values in "to", use clear_winopt() for that.
8450 * The 'scroll' option is not copied, because it depends on the window height.
8451 * The 'previewwindow' option is reset, there can be only one preview window.
8452 */
8453 void
8454copy_winopt(from, to)
8455 winopt_T *from;
8456 winopt_T *to;
8457{
8458#ifdef FEAT_ARABIC
8459 to->wo_arab = from->wo_arab;
8460#endif
8461 to->wo_list = from->wo_list;
8462 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008463#ifdef FEAT_LINEBREAK
8464 to->wo_nuw = from->wo_nuw;
8465#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466#ifdef FEAT_RIGHTLEFT
8467 to->wo_rl = from->wo_rl;
8468 to->wo_rlc = vim_strsave(from->wo_rlc);
8469#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008470#ifdef FEAT_STL_OPT
8471 to->wo_stl = vim_strsave(from->wo_stl);
8472#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 to->wo_wrap = from->wo_wrap;
8474#ifdef FEAT_LINEBREAK
8475 to->wo_lbr = from->wo_lbr;
8476#endif
8477#ifdef FEAT_SCROLLBIND
8478 to->wo_scb = from->wo_scb;
8479#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008480#ifdef FEAT_SYN_HL
8481 to->wo_spell = from->wo_spell;
8482#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483#ifdef FEAT_DIFF
8484 to->wo_diff = from->wo_diff;
8485#endif
8486#ifdef FEAT_FOLDING
8487 to->wo_fdc = from->wo_fdc;
8488 to->wo_fen = from->wo_fen;
8489 to->wo_fdi = vim_strsave(from->wo_fdi);
8490 to->wo_fml = from->wo_fml;
8491 to->wo_fdl = from->wo_fdl;
8492 to->wo_fdm = vim_strsave(from->wo_fdm);
8493 to->wo_fdn = from->wo_fdn;
8494# ifdef FEAT_EVAL
8495 to->wo_fde = vim_strsave(from->wo_fde);
8496 to->wo_fdt = vim_strsave(from->wo_fdt);
8497# endif
8498 to->wo_fmr = vim_strsave(from->wo_fmr);
8499#endif
8500 check_winopt(to); /* don't want NULL pointers */
8501}
8502
8503/*
8504 * Check string options in a window for a NULL value.
8505 */
8506 void
8507check_win_options(win)
8508 win_T *win;
8509{
8510 check_winopt(&win->w_onebuf_opt);
8511 check_winopt(&win->w_allbuf_opt);
8512}
8513
8514/*
8515 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8516 */
8517/*ARGSUSED*/
8518 void
8519check_winopt(wop)
8520 winopt_T *wop;
8521{
8522#ifdef FEAT_FOLDING
8523 check_string_option(&wop->wo_fdi);
8524 check_string_option(&wop->wo_fdm);
8525# ifdef FEAT_EVAL
8526 check_string_option(&wop->wo_fde);
8527 check_string_option(&wop->wo_fdt);
8528# endif
8529 check_string_option(&wop->wo_fmr);
8530#endif
8531#ifdef FEAT_RIGHTLEFT
8532 check_string_option(&wop->wo_rlc);
8533#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008534#ifdef FEAT_STL_OPT
8535 check_string_option(&wop->wo_stl);
8536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008537}
8538
8539/*
8540 * Free the allocated memory inside a winopt_T.
8541 */
8542/*ARGSUSED*/
8543 void
8544clear_winopt(wop)
8545 winopt_T *wop;
8546{
8547#ifdef FEAT_FOLDING
8548 clear_string_option(&wop->wo_fdi);
8549 clear_string_option(&wop->wo_fdm);
8550# ifdef FEAT_EVAL
8551 clear_string_option(&wop->wo_fde);
8552 clear_string_option(&wop->wo_fdt);
8553# endif
8554 clear_string_option(&wop->wo_fmr);
8555#endif
8556#ifdef FEAT_RIGHTLEFT
8557 clear_string_option(&wop->wo_rlc);
8558#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008559#ifdef FEAT_STL_OPT
8560 clear_string_option(&wop->wo_stl);
8561#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008562}
8563
8564/*
8565 * Copy global option values to local options for one buffer.
8566 * Used when creating a new buffer and sometimes when entering a buffer.
8567 * flags:
8568 * BCO_ENTER We will enter the buf buffer.
8569 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8570 * appropriate.
8571 * BCO_NOHELP Don't copy the values to a help buffer.
8572 */
8573 void
8574buf_copy_options(buf, flags)
8575 buf_T *buf;
8576 int flags;
8577{
8578 int should_copy = TRUE;
8579 char_u *save_p_isk = NULL; /* init for GCC */
8580 int dont_do_help;
8581 int did_isk = FALSE;
8582
8583 /*
8584 * Don't do anything of the buffer is invalid.
8585 */
8586 if (buf == NULL || !buf_valid(buf))
8587 return;
8588
8589 /*
8590 * Skip this when the option defaults have not been set yet. Happens when
8591 * main() allocates the first buffer.
8592 */
8593 if (p_cpo != NULL)
8594 {
8595 /*
8596 * Always copy when entering and 'cpo' contains 'S'.
8597 * Don't copy when already initialized.
8598 * Don't copy when 'cpo' contains 's' and not entering.
8599 * 'S' BCO_ENTER initialized 's' should_copy
8600 * yes yes X X TRUE
8601 * yes no yes X FALSE
8602 * no X yes X FALSE
8603 * X no no yes FALSE
8604 * X no no no TRUE
8605 * no yes no X TRUE
8606 */
8607 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8608 && (buf->b_p_initialized
8609 || (!(flags & BCO_ENTER)
8610 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8611 should_copy = FALSE;
8612
8613 if (should_copy || (flags & BCO_ALWAYS))
8614 {
8615 /* Don't copy the options specific to a help buffer when
8616 * BCO_NOHELP is given or the options were initialized already
8617 * (jumping back to a help file with CTRL-T or CTRL-O) */
8618 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8619 || buf->b_p_initialized;
8620 if (dont_do_help) /* don't free b_p_isk */
8621 {
8622 save_p_isk = buf->b_p_isk;
8623 buf->b_p_isk = NULL;
8624 }
8625 /*
8626 * Always free the allocated strings.
8627 * If not already initialized, set 'readonly' and copy 'fileformat'.
8628 */
8629 if (!buf->b_p_initialized)
8630 {
8631 free_buf_options(buf, TRUE);
8632 buf->b_p_ro = FALSE; /* don't copy readonly */
8633 buf->b_p_tx = p_tx;
8634#ifdef FEAT_MBYTE
8635 buf->b_p_fenc = vim_strsave(p_fenc);
8636#endif
8637 buf->b_p_ff = vim_strsave(p_ff);
8638#if defined(FEAT_QUICKFIX)
8639 buf->b_p_bh = empty_option;
8640 buf->b_p_bt = empty_option;
8641#endif
8642 }
8643 else
8644 free_buf_options(buf, FALSE);
8645
8646 buf->b_p_ai = p_ai;
8647 buf->b_p_ai_nopaste = p_ai_nopaste;
8648 buf->b_p_sw = p_sw;
8649 buf->b_p_tw = p_tw;
8650 buf->b_p_tw_nopaste = p_tw_nopaste;
8651 buf->b_p_tw_nobin = p_tw_nobin;
8652 buf->b_p_wm = p_wm;
8653 buf->b_p_wm_nopaste = p_wm_nopaste;
8654 buf->b_p_wm_nobin = p_wm_nobin;
8655 buf->b_p_bin = p_bin;
8656 buf->b_p_et = p_et;
8657 buf->b_p_et_nobin = p_et_nobin;
8658 buf->b_p_ml = p_ml;
8659 buf->b_p_ml_nobin = p_ml_nobin;
8660 buf->b_p_inf = p_inf;
8661 buf->b_p_swf = p_swf;
8662#ifdef FEAT_INS_EXPAND
8663 buf->b_p_cpt = vim_strsave(p_cpt);
8664#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008665#ifdef FEAT_COMPL_FUNC
8666 buf->b_p_cfu = vim_strsave(p_cfu);
8667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668 buf->b_p_sts = p_sts;
8669 buf->b_p_sts_nopaste = p_sts_nopaste;
8670#ifndef SHORT_FNAME
8671 buf->b_p_sn = p_sn;
8672#endif
8673#ifdef FEAT_COMMENTS
8674 buf->b_p_com = vim_strsave(p_com);
8675#endif
8676#ifdef FEAT_FOLDING
8677 buf->b_p_cms = vim_strsave(p_cms);
8678#endif
8679 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008680 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008681 buf->b_p_nf = vim_strsave(p_nf);
8682 buf->b_p_mps = vim_strsave(p_mps);
8683#ifdef FEAT_SMARTINDENT
8684 buf->b_p_si = p_si;
8685#endif
8686 buf->b_p_ci = p_ci;
8687#ifdef FEAT_CINDENT
8688 buf->b_p_cin = p_cin;
8689 buf->b_p_cink = vim_strsave(p_cink);
8690 buf->b_p_cino = vim_strsave(p_cino);
8691#endif
8692#ifdef FEAT_AUTOCMD
8693 /* Don't copy 'filetype', it must be detected */
8694 buf->b_p_ft = empty_option;
8695#endif
8696#ifdef FEAT_OSFILETYPE
8697 buf->b_p_oft = vim_strsave(p_oft);
8698#endif
8699 buf->b_p_pi = p_pi;
8700#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8701 buf->b_p_cinw = vim_strsave(p_cinw);
8702#endif
8703#ifdef FEAT_LISP
8704 buf->b_p_lisp = p_lisp;
8705#endif
8706#ifdef FEAT_SYN_HL
8707 /* Don't copy 'syntax', it must be set */
8708 buf->b_p_syn = empty_option;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008709 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008710 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008711#endif
8712#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8713 buf->b_p_inde = vim_strsave(p_inde);
8714 buf->b_p_indk = vim_strsave(p_indk);
8715#endif
8716#ifdef FEAT_CRYPT
8717 buf->b_p_key = vim_strsave(p_key);
8718#endif
8719#ifdef FEAT_SEARCHPATH
8720 buf->b_p_sua = vim_strsave(p_sua);
8721#endif
8722#ifdef FEAT_KEYMAP
8723 buf->b_p_keymap = vim_strsave(p_keymap);
8724 buf->b_kmap_state |= KEYMAP_INIT;
8725#endif
8726 /* This isn't really an option, but copying the langmap and IME
8727 * state from the current buffer is better than resetting it. */
8728 buf->b_p_iminsert = p_iminsert;
8729 buf->b_p_imsearch = p_imsearch;
8730
8731 /* options that are normally global but also have a local value
8732 * are not copied, start using the global value */
8733 buf->b_p_ar = -1;
8734#ifdef FEAT_QUICKFIX
8735 buf->b_p_gp = empty_option;
8736 buf->b_p_mp = empty_option;
8737 buf->b_p_efm = empty_option;
8738#endif
8739 buf->b_p_ep = empty_option;
8740 buf->b_p_kp = empty_option;
8741 buf->b_p_path = empty_option;
8742 buf->b_p_tags = empty_option;
8743#ifdef FEAT_FIND_ID
8744 buf->b_p_def = empty_option;
8745 buf->b_p_inc = empty_option;
8746# ifdef FEAT_EVAL
8747 buf->b_p_inex = vim_strsave(p_inex);
8748# endif
8749#endif
8750#ifdef FEAT_INS_EXPAND
8751 buf->b_p_dict = empty_option;
8752 buf->b_p_tsr = empty_option;
8753#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008754#ifdef FEAT_TEXTOBJ
8755 buf->b_p_qe = vim_strsave(p_qe);
8756#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757
8758 /*
8759 * Don't copy the options set by ex_help(), use the saved values,
8760 * when going from a help buffer to a non-help buffer.
8761 * Don't touch these at all when BCO_NOHELP is used and going from
8762 * or to a help buffer.
8763 */
8764 if (dont_do_help)
8765 buf->b_p_isk = save_p_isk;
8766 else
8767 {
8768 buf->b_p_isk = vim_strsave(p_isk);
8769 did_isk = TRUE;
8770 buf->b_p_ts = p_ts;
8771 buf->b_help = FALSE;
8772#ifdef FEAT_QUICKFIX
8773 if (buf->b_p_bt[0] == 'h')
8774 clear_string_option(&buf->b_p_bt);
8775#endif
8776 buf->b_p_ma = p_ma;
8777 }
8778 }
8779
8780 /*
8781 * When the options should be copied (ignoring BCO_ALWAYS), set the
8782 * flag that indicates that the options have been initialized.
8783 */
8784 if (should_copy)
8785 buf->b_p_initialized = TRUE;
8786 }
8787
8788 check_buf_options(buf); /* make sure we don't have NULLs */
8789 if (did_isk)
8790 (void)buf_init_chartab(buf, FALSE);
8791}
8792
8793/*
8794 * Reset the 'modifiable' option and its default value.
8795 */
8796 void
8797reset_modifiable()
8798{
8799 int opt_idx;
8800
8801 curbuf->b_p_ma = FALSE;
8802 p_ma = FALSE;
8803 opt_idx = findoption((char_u *)"ma");
8804 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8805}
8806
8807/*
8808 * Set the global value for 'iminsert' to the local value.
8809 */
8810 void
8811set_iminsert_global()
8812{
8813 p_iminsert = curbuf->b_p_iminsert;
8814}
8815
8816/*
8817 * Set the global value for 'imsearch' to the local value.
8818 */
8819 void
8820set_imsearch_global()
8821{
8822 p_imsearch = curbuf->b_p_imsearch;
8823}
8824
8825#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8826static int expand_option_idx = -1;
8827static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8828static int expand_option_flags = 0;
8829
8830 void
8831set_context_in_set_cmd(xp, arg, opt_flags)
8832 expand_T *xp;
8833 char_u *arg;
8834 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8835{
8836 int nextchar;
8837 long_u flags = 0; /* init for GCC */
8838 int opt_idx = 0; /* init for GCC */
8839 char_u *p;
8840 char_u *s;
8841 int is_term_option = FALSE;
8842 int key;
8843
8844 expand_option_flags = opt_flags;
8845
8846 xp->xp_context = EXPAND_SETTINGS;
8847 if (*arg == NUL)
8848 {
8849 xp->xp_pattern = arg;
8850 return;
8851 }
8852 p = arg + STRLEN(arg) - 1;
8853 if (*p == ' ' && *(p - 1) != '\\')
8854 {
8855 xp->xp_pattern = p + 1;
8856 return;
8857 }
8858 while (p > arg)
8859 {
8860 s = p;
8861 /* count number of backslashes before ' ' or ',' */
8862 if (*p == ' ' || *p == ',')
8863 {
8864 while (s > arg && *(s - 1) == '\\')
8865 --s;
8866 }
8867 /* break at a space with an even number of backslashes */
8868 if (*p == ' ' && ((p - s) & 1) == 0)
8869 {
8870 ++p;
8871 break;
8872 }
8873 --p;
8874 }
8875 if (STRNCMP(p, "no", 2) == 0)
8876 {
8877 xp->xp_context = EXPAND_BOOL_SETTINGS;
8878 p += 2;
8879 }
8880 if (STRNCMP(p, "inv", 3) == 0)
8881 {
8882 xp->xp_context = EXPAND_BOOL_SETTINGS;
8883 p += 3;
8884 }
8885 xp->xp_pattern = arg = p;
8886 if (*arg == '<')
8887 {
8888 while (*p != '>')
8889 if (*p++ == NUL) /* expand terminal option name */
8890 return;
8891 key = get_special_key_code(arg + 1);
8892 if (key == 0) /* unknown name */
8893 {
8894 xp->xp_context = EXPAND_NOTHING;
8895 return;
8896 }
8897 nextchar = *++p;
8898 is_term_option = TRUE;
8899 expand_option_name[2] = KEY2TERMCAP0(key);
8900 expand_option_name[3] = KEY2TERMCAP1(key);
8901 }
8902 else
8903 {
8904 if (p[0] == 't' && p[1] == '_')
8905 {
8906 p += 2;
8907 if (*p != NUL)
8908 ++p;
8909 if (*p == NUL)
8910 return; /* expand option name */
8911 nextchar = *++p;
8912 is_term_option = TRUE;
8913 expand_option_name[2] = p[-2];
8914 expand_option_name[3] = p[-1];
8915 }
8916 else
8917 {
8918 /* Allow * wildcard */
8919 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
8920 p++;
8921 if (*p == NUL)
8922 return;
8923 nextchar = *p;
8924 *p = NUL;
8925 opt_idx = findoption(arg);
8926 *p = nextchar;
8927 if (opt_idx == -1 || options[opt_idx].var == NULL)
8928 {
8929 xp->xp_context = EXPAND_NOTHING;
8930 return;
8931 }
8932 flags = options[opt_idx].flags;
8933 if (flags & P_BOOL)
8934 {
8935 xp->xp_context = EXPAND_NOTHING;
8936 return;
8937 }
8938 }
8939 }
8940 /* handle "-=" and "+=" */
8941 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
8942 {
8943 ++p;
8944 nextchar = '=';
8945 }
8946 if ((nextchar != '=' && nextchar != ':')
8947 || xp->xp_context == EXPAND_BOOL_SETTINGS)
8948 {
8949 xp->xp_context = EXPAND_UNSUCCESSFUL;
8950 return;
8951 }
8952 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
8953 {
8954 xp->xp_context = EXPAND_OLD_SETTING;
8955 if (is_term_option)
8956 expand_option_idx = -1;
8957 else
8958 expand_option_idx = opt_idx;
8959 xp->xp_pattern = p + 1;
8960 return;
8961 }
8962 xp->xp_context = EXPAND_NOTHING;
8963 if (is_term_option || (flags & P_NUM))
8964 return;
8965
8966 xp->xp_pattern = p + 1;
8967
8968 if (flags & P_EXPAND)
8969 {
8970 p = options[opt_idx].var;
8971 if (p == (char_u *)&p_bdir
8972 || p == (char_u *)&p_dir
8973 || p == (char_u *)&p_path
8974 || p == (char_u *)&p_rtp
8975#ifdef FEAT_SEARCHPATH
8976 || p == (char_u *)&p_cdpath
8977#endif
8978#ifdef FEAT_SESSION
8979 || p == (char_u *)&p_vdir
8980#endif
8981 )
8982 {
8983 xp->xp_context = EXPAND_DIRECTORIES;
8984 if (p == (char_u *)&p_path
8985#ifdef FEAT_SEARCHPATH
8986 || p == (char_u *)&p_cdpath
8987#endif
8988 )
8989 xp->xp_backslash = XP_BS_THREE;
8990 else
8991 xp->xp_backslash = XP_BS_ONE;
8992 }
8993 else
8994 {
8995 xp->xp_context = EXPAND_FILES;
8996 /* for 'tags' need three backslashes for a space */
8997 if (p == (char_u *)&p_tags)
8998 xp->xp_backslash = XP_BS_THREE;
8999 else
9000 xp->xp_backslash = XP_BS_ONE;
9001 }
9002 }
9003
9004 /* For an option that is a list of file names, find the start of the
9005 * last file name. */
9006 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9007 {
9008 /* count number of backslashes before ' ' or ',' */
9009 if (*p == ' ' || *p == ',')
9010 {
9011 s = p;
9012 while (s > xp->xp_pattern && *(s - 1) == '\\')
9013 --s;
9014 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9015 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9016 {
9017 xp->xp_pattern = p + 1;
9018 break;
9019 }
9020 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009021
9022#ifdef FEAT_SYN_HL
9023 /* for 'spellsuggest' start at "file:" */
9024 if (options[opt_idx].var == (char_u *)&p_sps
9025 && STRNCMP(p, "file:", 5) == 0)
9026 {
9027 xp->xp_pattern = p + 5;
9028 break;
9029 }
9030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009031 }
9032
9033 return;
9034}
9035
9036 int
9037ExpandSettings(xp, regmatch, num_file, file)
9038 expand_T *xp;
9039 regmatch_T *regmatch;
9040 int *num_file;
9041 char_u ***file;
9042{
9043 int num_normal = 0; /* Nr of matching non-term-code settings */
9044 int num_term = 0; /* Nr of matching terminal code settings */
9045 int opt_idx;
9046 int match;
9047 int count = 0;
9048 char_u *str;
9049 int loop;
9050 int is_term_opt;
9051 char_u name_buf[MAX_KEY_NAME_LEN];
9052 static char *(names[]) = {"all", "termcap"};
9053 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9054
9055 /* do this loop twice:
9056 * loop == 0: count the number of matching options
9057 * loop == 1: copy the matching options into allocated memory
9058 */
9059 for (loop = 0; loop <= 1; ++loop)
9060 {
9061 regmatch->rm_ic = ic;
9062 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9063 {
9064 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9065 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9066 {
9067 if (loop == 0)
9068 num_normal++;
9069 else
9070 (*file)[count++] = vim_strsave((char_u *)names[match]);
9071 }
9072 }
9073 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9074 opt_idx++)
9075 {
9076 if (options[opt_idx].var == NULL)
9077 continue;
9078 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9079 && !(options[opt_idx].flags & P_BOOL))
9080 continue;
9081 is_term_opt = istermoption(&options[opt_idx]);
9082 if (is_term_opt && num_normal > 0)
9083 continue;
9084 match = FALSE;
9085 if (vim_regexec(regmatch, str, (colnr_T)0)
9086 || (options[opt_idx].shortname != NULL
9087 && vim_regexec(regmatch,
9088 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9089 match = TRUE;
9090 else if (is_term_opt)
9091 {
9092 name_buf[0] = '<';
9093 name_buf[1] = 't';
9094 name_buf[2] = '_';
9095 name_buf[3] = str[2];
9096 name_buf[4] = str[3];
9097 name_buf[5] = '>';
9098 name_buf[6] = NUL;
9099 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9100 {
9101 match = TRUE;
9102 str = name_buf;
9103 }
9104 }
9105 if (match)
9106 {
9107 if (loop == 0)
9108 {
9109 if (is_term_opt)
9110 num_term++;
9111 else
9112 num_normal++;
9113 }
9114 else
9115 (*file)[count++] = vim_strsave(str);
9116 }
9117 }
9118 /*
9119 * Check terminal key codes, these are not in the option table
9120 */
9121 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9122 {
9123 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9124 {
9125 if (!isprint(str[0]) || !isprint(str[1]))
9126 continue;
9127
9128 name_buf[0] = 't';
9129 name_buf[1] = '_';
9130 name_buf[2] = str[0];
9131 name_buf[3] = str[1];
9132 name_buf[4] = NUL;
9133
9134 match = FALSE;
9135 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9136 match = TRUE;
9137 else
9138 {
9139 name_buf[0] = '<';
9140 name_buf[1] = 't';
9141 name_buf[2] = '_';
9142 name_buf[3] = str[0];
9143 name_buf[4] = str[1];
9144 name_buf[5] = '>';
9145 name_buf[6] = NUL;
9146
9147 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9148 match = TRUE;
9149 }
9150 if (match)
9151 {
9152 if (loop == 0)
9153 num_term++;
9154 else
9155 (*file)[count++] = vim_strsave(name_buf);
9156 }
9157 }
9158
9159 /*
9160 * Check special key names.
9161 */
9162 regmatch->rm_ic = TRUE; /* ignore case here */
9163 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9164 {
9165 name_buf[0] = '<';
9166 STRCPY(name_buf + 1, str);
9167 STRCAT(name_buf, ">");
9168
9169 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9170 {
9171 if (loop == 0)
9172 num_term++;
9173 else
9174 (*file)[count++] = vim_strsave(name_buf);
9175 }
9176 }
9177 }
9178 if (loop == 0)
9179 {
9180 if (num_normal > 0)
9181 *num_file = num_normal;
9182 else if (num_term > 0)
9183 *num_file = num_term;
9184 else
9185 return OK;
9186 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9187 if (*file == NULL)
9188 {
9189 *file = (char_u **)"";
9190 return FAIL;
9191 }
9192 }
9193 }
9194 return OK;
9195}
9196
9197 int
9198ExpandOldSetting(num_file, file)
9199 int *num_file;
9200 char_u ***file;
9201{
9202 char_u *var = NULL; /* init for GCC */
9203 char_u *buf;
9204
9205 *num_file = 0;
9206 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9207 if (*file == NULL)
9208 return FAIL;
9209
9210 /*
9211 * For a terminal key code expand_option_idx is < 0.
9212 */
9213 if (expand_option_idx < 0)
9214 {
9215 var = find_termcode(expand_option_name + 2);
9216 if (var == NULL)
9217 expand_option_idx = findoption(expand_option_name);
9218 }
9219
9220 if (expand_option_idx >= 0)
9221 {
9222 /* put string of option value in NameBuff */
9223 option_value2string(&options[expand_option_idx], expand_option_flags);
9224 var = NameBuff;
9225 }
9226 else if (var == NULL)
9227 var = (char_u *)"";
9228
9229 /* A backslash is required before some characters. This is the reverse of
9230 * what happens in do_set(). */
9231 buf = vim_strsave_escaped(var, escape_chars);
9232
9233 if (buf == NULL)
9234 {
9235 vim_free(*file);
9236 *file = NULL;
9237 return FAIL;
9238 }
9239
9240#ifdef BACKSLASH_IN_FILENAME
9241 /* For MS-Windows et al. we don't double backslashes at the start and
9242 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009243 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009244 if (var[0] == '\\' && var[1] == '\\'
9245 && expand_option_idx >= 0
9246 && (options[expand_option_idx].flags & P_EXPAND)
9247 && vim_isfilec(var[2])
9248 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9249 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009250#endif
9251
9252 *file[0] = buf;
9253 *num_file = 1;
9254 return OK;
9255}
9256#endif
9257
9258/*
9259 * Get the value for the numeric or string option *opp in a nice format into
9260 * NameBuff[]. Must not be called with a hidden option!
9261 */
9262 static void
9263option_value2string(opp, opt_flags)
9264 struct vimoption *opp;
9265 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9266{
9267 char_u *varp;
9268
9269 varp = get_varp_scope(opp, opt_flags);
9270
9271 if (opp->flags & P_NUM)
9272 {
9273 long wc = 0;
9274
9275 if (wc_use_keyname(varp, &wc))
9276 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9277 else if (wc != 0)
9278 STRCPY(NameBuff, transchar((int)wc));
9279 else
9280 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9281 }
9282 else /* P_STRING */
9283 {
9284 varp = *(char_u **)(varp);
9285 if (varp == NULL) /* just in case */
9286 NameBuff[0] = NUL;
9287#ifdef FEAT_CRYPT
9288 /* don't show the actual value of 'key', only that it's set */
9289 if (opp->var == (char_u *)&p_key && *varp)
9290 STRCPY(NameBuff, "*****");
9291#endif
9292 else if (opp->flags & P_EXPAND)
9293 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9294 /* Translate 'pastetoggle' into special key names */
9295 else if ((char_u **)opp->var == &p_pt)
9296 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9297 else
9298 STRNCPY(NameBuff, varp, MAXPATHL);
9299 }
9300}
9301
9302/*
9303 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9304 * printed as a keyname.
9305 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9306 */
9307 static int
9308wc_use_keyname(varp, wcp)
9309 char_u *varp;
9310 long *wcp;
9311{
9312 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9313 {
9314 *wcp = *(long *)varp;
9315 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9316 return TRUE;
9317 }
9318 return FALSE;
9319}
9320
9321#ifdef FEAT_LANGMAP
9322/*
9323 * Any character has an equivalent character. This is used for keyboards that
9324 * have a special language mode that sends characters above 128 (although
9325 * other characters can be translated too).
9326 */
9327
9328/*
9329 * char_u langmap_mapchar[256];
9330 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9331 * "translate" native lang chars in normal mode or some cases of
9332 * insert mode without having to tediously switch lang mode back&forth.
9333 */
9334
9335 static void
9336langmap_init()
9337{
9338 int i;
9339
9340 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9341 langmap_mapchar[i] = i;
9342}
9343
9344/*
9345 * Called when langmap option is set; the language map can be
9346 * changed at any time!
9347 */
9348 static void
9349langmap_set()
9350{
9351 char_u *p;
9352 char_u *p2;
9353 int from, to;
9354
9355 langmap_init(); /* back to one-to-one map first */
9356
9357 for (p = p_langmap; p[0] != NUL; )
9358 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009359 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9360 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361 {
9362 if (p2[0] == '\\' && p2[1] != NUL)
9363 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 }
9365 if (p2[0] == ';')
9366 ++p2; /* abcd;ABCD form, p2 points to A */
9367 else
9368 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9369 while (p[0])
9370 {
9371 if (p[0] == '\\' && p[1] != NUL)
9372 ++p;
9373#ifdef FEAT_MBYTE
9374 from = (*mb_ptr2char)(p);
9375#else
9376 from = p[0];
9377#endif
9378 if (p2 == NULL)
9379 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009380 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009381 if (p[0] == '\\')
9382 ++p;
9383#ifdef FEAT_MBYTE
9384 to = (*mb_ptr2char)(p);
9385#else
9386 to = p[0];
9387#endif
9388 }
9389 else
9390 {
9391 if (p2[0] == '\\')
9392 ++p2;
9393#ifdef FEAT_MBYTE
9394 to = (*mb_ptr2char)(p2);
9395#else
9396 to = p2[0];
9397#endif
9398 }
9399 if (to == NUL)
9400 {
9401 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9402 transchar(from));
9403 return;
9404 }
9405 langmap_mapchar[from & 255] = to;
9406
9407 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009408 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409 if (p2 == NULL)
9410 {
9411 if (p[0] == ',')
9412 {
9413 ++p;
9414 break;
9415 }
9416 }
9417 else
9418 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009419 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420 if (*p == ';')
9421 {
9422 p = p2;
9423 if (p[0] != NUL)
9424 {
9425 if (p[0] != ',')
9426 {
9427 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9428 return;
9429 }
9430 ++p;
9431 }
9432 break;
9433 }
9434 }
9435 }
9436 }
9437}
9438#endif
9439
9440/*
9441 * Return TRUE if format option 'x' is in effect.
9442 * Take care of no formatting when 'paste' is set.
9443 */
9444 int
9445has_format_option(x)
9446 int x;
9447{
9448 if (p_paste)
9449 return FALSE;
9450 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9451}
9452
9453/*
9454 * Return TRUE if "x" is present in 'shortmess' option, or
9455 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9456 */
9457 int
9458shortmess(x)
9459 int x;
9460{
9461 return ( vim_strchr(p_shm, x) != NULL
9462 || (vim_strchr(p_shm, 'a') != NULL
9463 && vim_strchr((char_u *)SHM_A, x) != NULL));
9464}
9465
9466/*
9467 * paste_option_changed() - Called after p_paste was set or reset.
9468 */
9469 static void
9470paste_option_changed()
9471{
9472 static int old_p_paste = FALSE;
9473 static int save_sm = 0;
9474#ifdef FEAT_CMDL_INFO
9475 static int save_ru = 0;
9476#endif
9477#ifdef FEAT_RIGHTLEFT
9478 static int save_ri = 0;
9479 static int save_hkmap = 0;
9480#endif
9481 buf_T *buf;
9482
9483 if (p_paste)
9484 {
9485 /*
9486 * Paste switched from off to on.
9487 * Save the current values, so they can be restored later.
9488 */
9489 if (!old_p_paste)
9490 {
9491 /* save options for each buffer */
9492 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9493 {
9494 buf->b_p_tw_nopaste = buf->b_p_tw;
9495 buf->b_p_wm_nopaste = buf->b_p_wm;
9496 buf->b_p_sts_nopaste = buf->b_p_sts;
9497 buf->b_p_ai_nopaste = buf->b_p_ai;
9498 }
9499
9500 /* save global options */
9501 save_sm = p_sm;
9502#ifdef FEAT_CMDL_INFO
9503 save_ru = p_ru;
9504#endif
9505#ifdef FEAT_RIGHTLEFT
9506 save_ri = p_ri;
9507 save_hkmap = p_hkmap;
9508#endif
9509 /* save global values for local buffer options */
9510 p_tw_nopaste = p_tw;
9511 p_wm_nopaste = p_wm;
9512 p_sts_nopaste = p_sts;
9513 p_ai_nopaste = p_ai;
9514 }
9515
9516 /*
9517 * Always set the option values, also when 'paste' is set when it is
9518 * already on.
9519 */
9520 /* set options for each buffer */
9521 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9522 {
9523 buf->b_p_tw = 0; /* textwidth is 0 */
9524 buf->b_p_wm = 0; /* wrapmargin is 0 */
9525 buf->b_p_sts = 0; /* softtabstop is 0 */
9526 buf->b_p_ai = 0; /* no auto-indent */
9527 }
9528
9529 /* set global options */
9530 p_sm = 0; /* no showmatch */
9531#ifdef FEAT_CMDL_INFO
9532# ifdef FEAT_WINDOWS
9533 if (p_ru)
9534 status_redraw_all(); /* redraw to remove the ruler */
9535# endif
9536 p_ru = 0; /* no ruler */
9537#endif
9538#ifdef FEAT_RIGHTLEFT
9539 p_ri = 0; /* no reverse insert */
9540 p_hkmap = 0; /* no Hebrew keyboard */
9541#endif
9542 /* set global values for local buffer options */
9543 p_tw = 0;
9544 p_wm = 0;
9545 p_sts = 0;
9546 p_ai = 0;
9547 }
9548
9549 /*
9550 * Paste switched from on to off: Restore saved values.
9551 */
9552 else if (old_p_paste)
9553 {
9554 /* restore options for each buffer */
9555 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9556 {
9557 buf->b_p_tw = buf->b_p_tw_nopaste;
9558 buf->b_p_wm = buf->b_p_wm_nopaste;
9559 buf->b_p_sts = buf->b_p_sts_nopaste;
9560 buf->b_p_ai = buf->b_p_ai_nopaste;
9561 }
9562
9563 /* restore global options */
9564 p_sm = save_sm;
9565#ifdef FEAT_CMDL_INFO
9566# ifdef FEAT_WINDOWS
9567 if (p_ru != save_ru)
9568 status_redraw_all(); /* redraw to draw the ruler */
9569# endif
9570 p_ru = save_ru;
9571#endif
9572#ifdef FEAT_RIGHTLEFT
9573 p_ri = save_ri;
9574 p_hkmap = save_hkmap;
9575#endif
9576 /* set global values for local buffer options */
9577 p_tw = p_tw_nopaste;
9578 p_wm = p_wm_nopaste;
9579 p_sts = p_sts_nopaste;
9580 p_ai = p_ai_nopaste;
9581 }
9582
9583 old_p_paste = p_paste;
9584}
9585
9586/*
9587 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9588 *
9589 * Reset 'compatible' and set the values for options that didn't get set yet
9590 * to the Vim defaults.
9591 * Don't do this if the 'compatible' option has been set or reset before.
9592 */
9593 void
9594vimrc_found()
9595{
9596 int opt_idx;
9597
9598 if (!option_was_set((char_u *)"cp"))
9599 {
9600 p_cp = FALSE;
9601 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9602 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9603 set_option_default(opt_idx, OPT_FREE, FALSE);
9604 didset_options();
9605 }
9606}
9607
9608/*
9609 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9610 */
9611 void
9612change_compatible(on)
9613 int on;
9614{
9615 if (p_cp != on)
9616 {
9617 p_cp = on;
9618 compatible_set();
9619 }
9620 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9621}
9622
9623/*
9624 * Return TRUE when option "name" has been set.
9625 */
9626 int
9627option_was_set(name)
9628 char_u *name;
9629{
9630 int idx;
9631
9632 idx = findoption(name);
9633 if (idx < 0) /* unknown option */
9634 return FALSE;
9635 if (options[idx].flags & P_WAS_SET)
9636 return TRUE;
9637 return FALSE;
9638}
9639
9640/*
9641 * compatible_set() - Called when 'compatible' has been set or unset.
9642 *
9643 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9644 * flag) to a Vi compatible value.
9645 * When 'compatible' is unset: Set all options that have a different default
9646 * for Vim (without the P_VI_DEF flag) to that default.
9647 */
9648 static void
9649compatible_set()
9650{
9651 int opt_idx;
9652
9653 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9654 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9655 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9656 set_option_default(opt_idx, OPT_FREE, p_cp);
9657 didset_options();
9658}
9659
9660#ifdef FEAT_LINEBREAK
9661
9662# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9663 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009664 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009665# endif
9666
9667/*
9668 * fill_breakat_flags() -- called when 'breakat' changes value.
9669 */
9670 static void
9671fill_breakat_flags()
9672{
9673 char_u *c;
9674 int i;
9675
9676 for (i = 0; i < 256; i++)
9677 breakat_flags[i] = FALSE;
9678
9679 if (p_breakat != NULL)
9680 for (c = p_breakat; *c; c++)
9681 breakat_flags[*c] = TRUE;
9682}
9683
9684# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009685 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009686# endif
9687
9688#endif
9689
9690/*
9691 * Check an option that can be a range of string values.
9692 *
9693 * Return OK for correct value, FAIL otherwise.
9694 * Empty is always OK.
9695 */
9696 static int
9697check_opt_strings(val, values, list)
9698 char_u *val;
9699 char **values;
9700 int list; /* when TRUE: accept a list of values */
9701{
9702 return opt_strings_flags(val, values, NULL, list);
9703}
9704
9705/*
9706 * Handle an option that can be a range of string values.
9707 * Set a flag in "*flagp" for each string present.
9708 *
9709 * Return OK for correct value, FAIL otherwise.
9710 * Empty is always OK.
9711 */
9712 static int
9713opt_strings_flags(val, values, flagp, list)
9714 char_u *val; /* new value */
9715 char **values; /* array of valid string values */
9716 unsigned *flagp;
9717 int list; /* when TRUE: accept a list of values */
9718{
9719 int i;
9720 int len;
9721 unsigned new_flags = 0;
9722
9723 while (*val)
9724 {
9725 for (i = 0; ; ++i)
9726 {
9727 if (values[i] == NULL) /* val not found in values[] */
9728 return FAIL;
9729
9730 len = (int)STRLEN(values[i]);
9731 if (STRNCMP(values[i], val, len) == 0
9732 && ((list && val[len] == ',') || val[len] == NUL))
9733 {
9734 val += len + (val[len] == ',');
9735 new_flags |= (1 << i);
9736 break; /* check next item in val list */
9737 }
9738 }
9739 }
9740 if (flagp != NULL)
9741 *flagp = new_flags;
9742
9743 return OK;
9744}
9745
9746/*
9747 * Read the 'wildmode' option, fill wim_flags[].
9748 */
9749 static int
9750check_opt_wim()
9751{
9752 char_u new_wim_flags[4];
9753 char_u *p;
9754 int i;
9755 int idx = 0;
9756
9757 for (i = 0; i < 4; ++i)
9758 new_wim_flags[i] = 0;
9759
9760 for (p = p_wim; *p; ++p)
9761 {
9762 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9763 ;
9764 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9765 return FAIL;
9766 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9767 new_wim_flags[idx] |= WIM_LONGEST;
9768 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9769 new_wim_flags[idx] |= WIM_FULL;
9770 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9771 new_wim_flags[idx] |= WIM_LIST;
9772 else
9773 return FAIL;
9774 p += i;
9775 if (*p == NUL)
9776 break;
9777 if (*p == ',')
9778 {
9779 if (idx == 3)
9780 return FAIL;
9781 ++idx;
9782 }
9783 }
9784
9785 /* fill remaining entries with last flag */
9786 while (idx < 3)
9787 {
9788 new_wim_flags[idx + 1] = new_wim_flags[idx];
9789 ++idx;
9790 }
9791
9792 /* only when there are no errors, wim_flags[] is changed */
9793 for (i = 0; i < 4; ++i)
9794 wim_flags[i] = new_wim_flags[i];
9795 return OK;
9796}
9797
9798/*
9799 * Check if backspacing over something is allowed.
9800 */
9801 int
9802can_bs(what)
9803 int what; /* BS_INDENT, BS_EOL or BS_START */
9804{
9805 switch (*p_bs)
9806 {
9807 case '2': return TRUE;
9808 case '1': return (what != BS_START);
9809 case '0': return FALSE;
9810 }
9811 return vim_strchr(p_bs, what) != NULL;
9812}
9813
9814/*
9815 * Save the current values of 'fileformat' and 'fileencoding', so that we know
9816 * the file must be considered changed when the value is different.
9817 */
9818 void
9819save_file_ff(buf)
9820 buf_T *buf;
9821{
9822 buf->b_start_ffc = *buf->b_p_ff;
9823 buf->b_start_eol = buf->b_p_eol;
9824#ifdef FEAT_MBYTE
9825 /* Only use free/alloc when necessary, they take time. */
9826 if (buf->b_start_fenc == NULL
9827 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9828 {
9829 vim_free(buf->b_start_fenc);
9830 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9831 }
9832#endif
9833}
9834
9835/*
9836 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9837 * from when editing started (save_file_ff() called).
9838 * Also when 'endofline' was changed and 'binary' is set.
9839 * Don't consider a new, empty buffer to be changed.
9840 */
9841 int
9842file_ff_differs(buf)
9843 buf_T *buf;
9844{
9845 if ((buf->b_flags & BF_NEW)
9846 && buf->b_ml.ml_line_count == 1
9847 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
9848 return FALSE;
9849 if (buf->b_start_ffc != *buf->b_p_ff)
9850 return TRUE;
9851 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
9852 return TRUE;
9853#ifdef FEAT_MBYTE
9854 if (buf->b_start_fenc == NULL)
9855 return (*buf->b_p_fenc != NUL);
9856 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
9857#else
9858 return FALSE;
9859#endif
9860}
9861
9862/*
9863 * return OK if "p" is a valid fileformat name, FAIL otherwise.
9864 */
9865 int
9866check_ff_value(p)
9867 char_u *p;
9868{
9869 return check_opt_strings(p, p_ff_values, FALSE);
9870}