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