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