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