blob: 25ddafbd2ad0654ff8db54ee0b8d62d3b2b5bca2 [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 Moolenaarb71eaae2006-01-20 23:10:18 +00002656static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657static char_u *illegal_char __ARGS((char_u *, int));
2658static int string_to_key __ARGS((char_u *arg));
2659#ifdef FEAT_CMDWIN
2660static char_u *check_cedit __ARGS((void));
2661#endif
2662#ifdef FEAT_TITLE
2663static void did_set_title __ARGS((int icon));
2664#endif
2665static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2666static void didset_options __ARGS((void));
2667static void check_string_option __ARGS((char_u **pp));
2668static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2669static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2670static 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));
2671static char_u *set_chars_option __ARGS((char_u **varp));
2672#ifdef FEAT_CLIPBOARD
2673static char_u *check_clipboard_option __ARGS((void));
2674#endif
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002675#ifdef FEAT_SYN_HL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002676static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002679static 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 +00002680static void check_redraw __ARGS((long_u flags));
2681static int findoption __ARGS((char_u *));
2682static int find_key_option __ARGS((char_u *));
2683static void showoptions __ARGS((int all, int opt_flags));
2684static int optval_default __ARGS((struct vimoption *, char_u *varp));
2685static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2686static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2687static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2688static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2689static int istermoption __ARGS((struct vimoption *));
2690static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2691static char_u *get_varp __ARGS((struct vimoption *));
2692static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2693static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2694#ifdef FEAT_LANGMAP
2695static void langmap_init __ARGS((void));
2696static void langmap_set __ARGS((void));
2697#endif
2698static void paste_option_changed __ARGS((void));
2699static void compatible_set __ARGS((void));
2700#ifdef FEAT_LINEBREAK
2701static void fill_breakat_flags __ARGS((void));
2702#endif
2703static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2704static int check_opt_strings __ARGS((char_u *val, char **values, int));
2705static int check_opt_wim __ARGS((void));
2706
2707/*
2708 * Initialize the options, first part.
2709 *
2710 * Called only once from main(), just after creating the first buffer.
2711 */
2712 void
2713set_init_1()
2714{
2715 char_u *p;
2716 int opt_idx;
2717 long n;
2718
2719#ifdef FEAT_LANGMAP
2720 langmap_init();
2721#endif
2722
2723 /* Be Vi compatible by default */
2724 p_cp = TRUE;
2725
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002726 /* Use POSIX compatibility when $VIM_POSIX is set. */
2727 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002728 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002729 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002730 set_string_default("shm", (char_u *)"A");
2731 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002732
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 /*
2734 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002735 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002737 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2739# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002740 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002741# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002742 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002744 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745# endif
2746#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002747 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 set_string_default("sh", p);
2749
2750#ifdef FEAT_WILDIGN
2751 /*
2752 * Set the default for 'backupskip' to include environment variables for
2753 * temp files.
2754 */
2755 {
2756# ifdef UNIX
2757 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2758# else
2759 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2760# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002761 int len;
2762 garray_T ga;
2763 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764
2765 ga_init2(&ga, 1, 100);
2766 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2767 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002768 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769# ifdef UNIX
2770 if (*names[n] == NUL)
2771 p = (char_u *)"/tmp";
2772 else
2773# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002774 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 if (p != NULL && *p != NUL)
2776 {
2777 /* First time count the NUL, otherwise count the ','. */
2778 len = STRLEN(p) + 3;
2779 if (ga_grow(&ga, len) == OK)
2780 {
2781 if (ga.ga_len > 0)
2782 STRCAT(ga.ga_data, ",");
2783 STRCAT(ga.ga_data, p);
2784 add_pathsep(ga.ga_data);
2785 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 ga.ga_len += len;
2787 }
2788 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002789 if (mustfree)
2790 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 }
2792 if (ga.ga_data != NULL)
2793 {
2794 set_string_default("bsk", ga.ga_data);
2795 vim_free(ga.ga_data);
2796 }
2797 }
2798#endif
2799
2800 /*
2801 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2802 */
2803 opt_idx = findoption((char_u *)"maxmemtot");
2804#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2805 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2806#endif
2807 {
2808#ifdef HAVE_AVAIL_MEM
2809 /* Use amount of memory available at this moment. */
2810 n = (mch_avail_mem(FALSE) >> 11);
2811#else
2812# ifdef HAVE_TOTAL_MEM
2813 /* Use amount of memory available to Vim. */
2814 n = (mch_total_mem(FALSE) >> 11);
2815# else
2816 n = (0x7fffffff >> 11);
2817# endif
2818#endif
2819 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2820 opt_idx = findoption((char_u *)"maxmem");
2821#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2822 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2823 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2824#endif
2825 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2826 }
2827
2828#ifdef FEAT_GUI_W32
2829 /* force 'shortname' for Win32s */
2830 if (gui_is_win32s())
2831 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2832 (char_u *)TRUE;
2833#endif
2834
2835#ifdef FEAT_SEARCHPATH
2836 {
2837 char_u *cdpath;
2838 char_u *buf;
2839 int i;
2840 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002841 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842
2843 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00002844 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 if (cdpath != NULL)
2846 {
2847 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2848 if (buf != NULL)
2849 {
2850 buf[0] = ','; /* start with ",", current dir first */
2851 j = 1;
2852 for (i = 0; cdpath[i] != NUL; ++i)
2853 {
2854 if (vim_ispathlistsep(cdpath[i]))
2855 buf[j++] = ',';
2856 else
2857 {
2858 if (cdpath[i] == ' ' || cdpath[i] == ',')
2859 buf[j++] = '\\';
2860 buf[j++] = cdpath[i];
2861 }
2862 }
2863 buf[j] = NUL;
2864 opt_idx = findoption((char_u *)"cdpath");
2865 options[opt_idx].def_val[VI_DEFAULT] = buf;
2866 options[opt_idx].flags |= P_DEF_ALLOCED;
2867 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002868 if (mustfree)
2869 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 }
2871 }
2872#endif
2873
2874#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2875 /* Set print encoding on platforms that don't default to latin1 */
2876 set_string_default("penc",
2877# if defined(MSWIN) || defined(OS2)
2878 (char_u *)"cp1252"
2879# else
2880# ifdef VMS
2881 (char_u *)"dec-mcs"
2882# else
2883# ifdef EBCDIC
2884 (char_u *)"ebcdic-uk"
2885# else
2886# ifdef MAC
2887 (char_u *)"mac-roman"
2888# else /* HPUX */
2889 (char_u *)"hp-roman8"
2890# endif
2891# endif
2892# endif
2893# endif
2894 );
2895#endif
2896
2897#ifdef FEAT_POSTSCRIPT
2898 /* 'printexpr' must be allocated to be able to evaluate it. */
2899 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00002900# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
2901 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902# else
2903# ifdef VMS
2904 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
2905
2906# else
2907 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
2908# endif
2909# endif
2910 );
2911#endif
2912
2913 /*
2914 * Set all the options (except the terminal options) to their default
2915 * value. Also set the global value for local options.
2916 */
2917 set_options_default(0);
2918
2919#ifdef FEAT_GUI
2920 if (found_reverse_arg)
2921 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
2922#endif
2923
2924 curbuf->b_p_initialized = TRUE;
2925 curbuf->b_p_ar = -1; /* no local 'autoread' value */
2926 check_buf_options(curbuf);
2927 check_win_options(curwin);
2928 check_options();
2929
2930 /* Must be before option_expand(), because that one needs vim_isIDc() */
2931 didset_options();
2932
Bram Moolenaar6bb68362005-03-22 23:03:44 +00002933#ifdef FEAT_SYN_HL
2934 /* Use the current chartab for the generic chartab. */
2935 init_spell_chartab();
2936#endif
2937
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938#ifdef FEAT_LINEBREAK
2939 /*
2940 * initialize the table for 'breakat'.
2941 */
2942 fill_breakat_flags();
2943#endif
2944
2945 /*
2946 * Expand environment variables and things like "~" for the defaults.
2947 * If option_expand() returns non-NULL the variable is expanded. This can
2948 * only happen for non-indirect options.
2949 * Also set the default to the expanded value, so ":set" does not list
2950 * them.
2951 * Don't set the P_ALLOCED flag, because we don't want to free the
2952 * default.
2953 */
2954 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
2955 {
2956 if ((options[opt_idx].flags & P_GETTEXT)
2957 && options[opt_idx].var != NULL)
2958 p = (char_u *)_(*(char **)options[opt_idx].var);
2959 else
2960 p = option_expand(opt_idx, NULL);
2961 if (p != NULL && (p = vim_strsave(p)) != NULL)
2962 {
2963 *(char_u **)options[opt_idx].var = p;
2964 /* VIMEXP
2965 * Defaults for all expanded options are currently the same for Vi
2966 * and Vim. When this changes, add some code here! Also need to
2967 * split P_DEF_ALLOCED in two.
2968 */
2969 if (options[opt_idx].flags & P_DEF_ALLOCED)
2970 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2971 options[opt_idx].def_val[VI_DEFAULT] = p;
2972 options[opt_idx].flags |= P_DEF_ALLOCED;
2973 }
2974 }
2975
2976 /* Initialize the highlight_attr[] table. */
2977 highlight_changed();
2978
2979 save_file_ff(curbuf); /* Buffer is unchanged */
2980
2981 /* Parse default for 'wildmode' */
2982 check_opt_wim();
2983
2984#if defined(FEAT_ARABIC)
2985 /* Detect use of mlterm.
2986 * Mlterm is a terminal emulator akin to xterm that has some special
2987 * abilities (bidi namely).
2988 * NOTE: mlterm's author is being asked to 'set' a variable
2989 * instead of an environment variable due to inheritance.
2990 */
2991 if (mch_getenv((char_u *)"MLTERM") != NULL)
2992 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
2993#endif
2994
2995#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
2996 /* Parse default for 'fillchars'. */
2997 (void)set_chars_option(&p_fcs);
2998#endif
2999
3000#ifdef FEAT_CLIPBOARD
3001 /* Parse default for 'clipboard' */
3002 (void)check_clipboard_option();
3003#endif
3004
3005#ifdef FEAT_MBYTE
3006# if defined(WIN3264) && defined(FEAT_GETTEXT)
3007 /*
3008 * If $LANG isn't set, try to get a good value for it. This makes the
3009 * right language be used automatically. Don't do this for English.
3010 */
3011 if (mch_getenv((char_u *)"LANG") == NULL)
3012 {
3013 char buf[20];
3014
3015 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3016 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3017 * only the first two. */
3018 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3019 (LPTSTR)buf, 20);
3020 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3021 {
3022 /* There are a few exceptions (probably more) */
3023 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3024 STRCPY(buf, "zh_TW");
3025 else if (STRNICMP(buf, "chs", 3) == 0
3026 || STRNICMP(buf, "zhc", 3) == 0)
3027 STRCPY(buf, "zh_CN");
3028 else if (STRNICMP(buf, "jp", 2) == 0)
3029 STRCPY(buf, "ja");
3030 else
3031 buf[2] = NUL; /* truncate to two-letter code */
3032 vim_setenv("LANG", buf);
3033 }
3034 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003035# else
3036# ifdef MACOS
3037 if (mch_getenv((char_u *)"LANG") == NULL)
3038 {
3039 char buf[20];
3040 if (LocaleRefGetPartString(NULL,
3041 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3042 kLocaleRegionMask | kLocaleRegionVariantMask,
3043 sizeof buf, buf) == noErr && *buf)
3044 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003045 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003046# ifdef HAVE_LOCALE_H
3047 setlocale(LC_ALL, "");
3048# endif
3049 }
3050 }
3051# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052# endif
3053
3054 /* enc_locale() will try to find the encoding of the current locale. */
3055 p = enc_locale();
3056 if (p != NULL)
3057 {
3058 char_u *save_enc;
3059
3060 /* Try setting 'encoding' and check if the value is valid.
3061 * If not, go back to the default "latin1". */
3062 save_enc = p_enc;
3063 p_enc = p;
3064 if (mb_init() == NULL)
3065 {
3066 opt_idx = findoption((char_u *)"encoding");
3067 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3068 options[opt_idx].flags |= P_DEF_ALLOCED;
3069
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003070#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3071 || defined(VMS)
3072 if (STRCMP(p_enc, "latin1") == 0
3073# ifdef FEAT_MBYTE
3074 || enc_utf8
3075# endif
3076 )
3077 {
3078 /* Adjust the default for 'isprint' to match latin1. */
3079 set_string_option_direct((char_u *)"isp", -1,
3080 (char_u *)"@,161-255", OPT_FREE);
3081 (void)init_chartab();
3082 }
3083#endif
3084
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085# if defined(WIN3264) && !defined(FEAT_GUI)
3086 /* Win32 console: When GetACP() returns a different value from
3087 * GetConsoleCP() set 'termencoding'. */
3088 if (GetACP() != GetConsoleCP())
3089 {
3090 char buf[50];
3091
3092 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3093 p_tenc = vim_strsave((char_u *)buf);
3094 if (p_tenc != NULL)
3095 {
3096 opt_idx = findoption((char_u *)"termencoding");
3097 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3098 options[opt_idx].flags |= P_DEF_ALLOCED;
3099 convert_setup(&input_conv, p_tenc, p_enc);
3100 convert_setup(&output_conv, p_enc, p_tenc);
3101 }
3102 else
3103 p_tenc = empty_option;
3104 }
3105# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003106# if defined(WIN3264) && defined(FEAT_MBYTE)
3107 /* $HOME may have characters in active code page. */
3108 init_homedir();
3109# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 }
3111 else
3112 {
3113 vim_free(p_enc);
3114 p_enc = save_enc;
3115 }
3116 }
3117#endif
3118
3119#ifdef FEAT_MULTI_LANG
3120 /* Set the default for 'helplang'. */
3121 set_helplang_default(get_mess_lang());
3122#endif
3123}
3124
3125/*
3126 * Set an option to its default value.
3127 * This does not take care of side effects!
3128 */
3129 static void
3130set_option_default(opt_idx, opt_flags, compatible)
3131 int opt_idx;
3132 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3133 int compatible; /* use Vi default value */
3134{
3135 char_u *varp; /* pointer to variable for current option */
3136 int dvi; /* index in def_val[] */
3137 long_u flags;
3138 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3139
3140 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3141 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003142 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 {
3144 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3145 if (flags & P_STRING)
3146 {
3147 /* Use set_string_option_direct() for local options to handle
3148 * freeing and allocating the value. */
3149 if (options[opt_idx].indir != PV_NONE)
3150 set_string_option_direct(NULL, opt_idx,
3151 options[opt_idx].def_val[dvi], opt_flags);
3152 else
3153 {
3154 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3155 free_string_option(*(char_u **)(varp));
3156 *(char_u **)varp = options[opt_idx].def_val[dvi];
3157 options[opt_idx].flags &= ~P_ALLOCED;
3158 }
3159 }
3160 else if (flags & P_NUM)
3161 {
3162 if (varp == (char_u *)PV_SCROLL)
3163 win_comp_scroll(curwin);
3164 else
3165 {
3166 *(long *)varp = (long)options[opt_idx].def_val[dvi];
3167 /* May also set global value for local option. */
3168 if (both)
3169 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3170 *(long *)varp;
3171 }
3172 }
3173 else /* P_BOOL */
3174 {
3175 /* the cast to long is required for Manx C */
3176 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3177 /* May also set global value for local option. */
3178 if (both)
3179 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3180 *(int *)varp;
3181 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003182
3183 /* the default value is not insecure */
3184 options[opt_idx].flags &= ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 }
3186
3187#ifdef FEAT_EVAL
3188 /* Remember where the option was set. */
3189 options[opt_idx].scriptID = current_SID;
3190#endif
3191}
3192
3193/*
3194 * Set all options (except terminal options) to their default value.
3195 */
3196 static void
3197set_options_default(opt_flags)
3198 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3199{
3200 int i;
3201#ifdef FEAT_WINDOWS
3202 win_T *wp;
3203#endif
3204
3205 for (i = 0; !istermoption(&options[i]); i++)
3206 if (!(options[i].flags & P_NODEFAULT))
3207 set_option_default(i, opt_flags, p_cp);
3208
3209#ifdef FEAT_WINDOWS
3210 /* The 'scroll' option must be computed for all windows. */
3211 for (wp = firstwin; wp != NULL; wp = wp->w_next)
3212 win_comp_scroll(wp);
3213#else
3214 win_comp_scroll(curwin);
3215#endif
3216}
3217
3218/*
3219 * Set the Vi-default value of a string option.
3220 * Used for 'sh', 'backupskip' and 'term'.
3221 */
3222 void
3223set_string_default(name, val)
3224 char *name;
3225 char_u *val;
3226{
3227 char_u *p;
3228 int opt_idx;
3229
3230 p = vim_strsave(val);
3231 if (p != NULL) /* we don't want a NULL */
3232 {
3233 opt_idx = findoption((char_u *)name);
3234 if (options[opt_idx].flags & P_DEF_ALLOCED)
3235 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3236 options[opt_idx].def_val[VI_DEFAULT] = p;
3237 options[opt_idx].flags |= P_DEF_ALLOCED;
3238 }
3239}
3240
3241/*
3242 * Set the Vi-default value of a number option.
3243 * Used for 'lines' and 'columns'.
3244 */
3245 void
3246set_number_default(name, val)
3247 char *name;
3248 long val;
3249{
3250 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3251}
3252
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003253#if defined(EXITFREE) || defined(PROTO)
3254/*
3255 * Free all options.
3256 */
3257 void
3258free_all_options()
3259{
3260 int i;
3261
3262 for (i = 0; !istermoption(&options[i]); i++)
3263 {
3264 if (options[i].indir == PV_NONE)
3265 {
3266 /* global option: free value and default value. */
3267 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3268 free_string_option(*(char_u **)options[i].var);
3269 if (options[i].flags & P_DEF_ALLOCED)
3270 free_string_option(options[i].def_val[VI_DEFAULT]);
3271 }
3272 else if (options[i].var != VAR_WIN
3273 && (options[i].flags & P_STRING))
3274 /* buffer-local option: free global value */
3275 free_string_option(*(char_u **)options[i].var);
3276 }
3277}
3278#endif
3279
3280
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281/*
3282 * Initialize the options, part two: After getting Rows and Columns and
3283 * setting 'term'.
3284 */
3285 void
3286set_init_2()
3287{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003288 int idx;
3289
Bram Moolenaar071d4272004-06-13 20:20:40 +00003290 /*
3291 * 'scroll' defaults to half the window height. Note that this default is
3292 * wrong when the window height changes.
3293 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003294 set_number_default("scroll", (long_u)Rows >> 1);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003295 idx = findoption((char_u *)"scroll");
3296 if (!(options[idx].flags & P_WAS_SET))
3297 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298 comp_col();
3299
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003300 /*
3301 * 'window' is only for backwards compatibility with Vi.
3302 * Default is Rows - 1.
3303 */
3304 idx = findoption((char_u *)"wi");
3305 if (!(options[idx].flags & P_WAS_SET))
3306 p_window = Rows - 1;
3307 set_number_default("window", Rows - 1);
3308
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3310 {
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003311 char_u *p;
3312
Bram Moolenaar071d4272004-06-13 20:20:40 +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
Bram Moolenaara21b29a2005-02-27 22:40:05 +00003316 * with a dark background, that can handle color. Recognized are:
3317 * "linux" Linux console
3318 * "screen.linux" Linux console with screen
Bram Moolenaar19a09a12005-03-04 23:39:37 +00003319 * "cygwin" Cygwin shell
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003320 * "putty" Putty program
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003321 * We also check the COLORFGBG environment variable, which is set by
3322 * rxvt and derivatives. This variable contains either two or three
3323 * values separated by semicolons; we want the last value in either
3324 * case. If this value is 0-6 or 8, our background is dark.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003326 idx = findoption((char_u *)"bg");
Bram Moolenaara21b29a2005-02-27 22:40:05 +00003327 if (!(options[idx].flags & P_WAS_SET)
3328 && (STRCMP(T_NAME, "linux") == 0
Bram Moolenaar19a09a12005-03-04 23:39:37 +00003329 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003330 || STRCMP(T_NAME, "cygwin") == 0
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003331 || STRCMP(T_NAME, "putty") == 0
Bram Moolenaar46152342005-09-07 21:18:43 +00003332 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003333 && (p = vim_strrchr(p, ';')) != NULL
3334 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3335 && p[2] == NUL)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003337 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE);
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003338 /* don't mark it as set, when starting the GUI it may be
3339 * changed again */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003340 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 }
3342 }
3343#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003344
3345#ifdef CURSOR_SHAPE
3346 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3347#endif
3348#ifdef FEAT_MOUSESHAPE
3349 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3350#endif
3351#ifdef FEAT_PRINTER
3352 (void)parse_printoptions(); /* parse 'printoptions' default value */
3353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354}
3355
3356/*
3357 * Initialize the options, part three: After reading the .vimrc
3358 */
3359 void
3360set_init_3()
3361{
3362#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3363/*
3364 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3365 * This is done after other initializations, where 'shell' might have been
3366 * set, but only if they have not been set before.
3367 */
3368 char_u *p;
3369 int idx_srr;
3370 int do_srr;
3371#ifdef FEAT_QUICKFIX
3372 int idx_sp;
3373 int do_sp;
3374#endif
3375
3376 idx_srr = findoption((char_u *)"srr");
3377 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3378#ifdef FEAT_QUICKFIX
3379 idx_sp = findoption((char_u *)"sp");
3380 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3381#endif
3382
3383 /*
3384 * Isolate the name of the shell:
3385 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3386 * - Remove any argument. E.g., "csh -f" -> "csh".
3387 */
3388 p = gettail(p_sh);
3389 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3390 if (p != NULL)
3391 {
3392 /*
3393 * Default for p_sp is "| tee", for p_srr is ">".
3394 * For known shells it is changed here to include stderr.
3395 */
3396 if ( fnamecmp(p, "csh") == 0
3397 || fnamecmp(p, "tcsh") == 0
3398# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3399 || fnamecmp(p, "csh.exe") == 0
3400 || fnamecmp(p, "tcsh.exe") == 0
3401# endif
3402 )
3403 {
3404#if defined(FEAT_QUICKFIX)
3405 if (do_sp)
3406 {
3407# ifdef WIN3264
3408 p_sp = (char_u *)">&";
3409# else
3410 p_sp = (char_u *)"|& tee";
3411# endif
3412 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3413 }
3414#endif
3415 if (do_srr)
3416 {
3417 p_srr = (char_u *)">&";
3418 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3419 }
3420 }
3421 else
3422# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3423 if ( fnamecmp(p, "sh") == 0
3424 || fnamecmp(p, "ksh") == 0
3425 || fnamecmp(p, "zsh") == 0
3426 || fnamecmp(p, "bash") == 0
3427# ifdef WIN3264
3428 || fnamecmp(p, "cmd") == 0
3429 || fnamecmp(p, "sh.exe") == 0
3430 || fnamecmp(p, "ksh.exe") == 0
3431 || fnamecmp(p, "zsh.exe") == 0
3432 || fnamecmp(p, "bash.exe") == 0
3433 || fnamecmp(p, "cmd.exe") == 0
3434# endif
3435 )
3436# endif
3437 {
3438#if defined(FEAT_QUICKFIX)
3439 if (do_sp)
3440 {
3441# ifdef WIN3264
3442 p_sp = (char_u *)">%s 2>&1";
3443# else
3444 p_sp = (char_u *)"2>&1| tee";
3445# endif
3446 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3447 }
3448#endif
3449 if (do_srr)
3450 {
3451 p_srr = (char_u *)">%s 2>&1";
3452 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3453 }
3454 }
3455 vim_free(p);
3456 }
3457#endif
3458
3459#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3460 /*
3461 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3462 * This is done after other initializations, where 'shell' might have been
3463 * set, but only if they have not been set before. Default for p_shcf is
3464 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3465 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3466 * command.com. And for Win32 we need to set p_sxq instead.
3467 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003468 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 {
3470 int idx3;
3471
3472 idx3 = findoption((char_u *)"shcf");
3473 if (!(options[idx3].flags & P_WAS_SET))
3474 {
3475 p_shcf = (char_u *)"-c";
3476 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3477 }
3478
3479# ifndef DJGPP
3480# ifdef WIN3264
3481 /* Somehow Win32 requires the quotes around the redirection too */
3482 idx3 = findoption((char_u *)"sxq");
3483 if (!(options[idx3].flags & P_WAS_SET))
3484 {
3485 p_sxq = (char_u *)"\"";
3486 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3487 }
3488# else
3489 idx3 = findoption((char_u *)"shq");
3490 if (!(options[idx3].flags & P_WAS_SET))
3491 {
3492 p_shq = (char_u *)"\"";
3493 options[idx3].def_val[VI_DEFAULT] = p_shq;
3494 }
3495# endif
3496# endif
3497 }
3498#endif
3499
3500#ifdef FEAT_TITLE
3501 set_title_defaults();
3502#endif
3503}
3504
3505#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3506/*
3507 * When 'helplang' is still at its default value, set it to "lang".
3508 * Only the first two characters of "lang" are used.
3509 */
3510 void
3511set_helplang_default(lang)
3512 char_u *lang;
3513{
3514 int idx;
3515
3516 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3517 return;
3518 idx = findoption((char_u *)"hlg");
3519 if (!(options[idx].flags & P_WAS_SET))
3520 {
3521 if (options[idx].flags & P_ALLOCED)
3522 free_string_option(p_hlg);
3523 p_hlg = vim_strsave(lang);
3524 if (p_hlg == NULL)
3525 p_hlg = empty_option;
3526 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003527 {
3528 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3529 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3530 {
3531 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3532 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3533 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003534 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003536 options[idx].flags |= P_ALLOCED;
3537 }
3538}
3539#endif
3540
3541#ifdef FEAT_GUI
3542static char_u *gui_bg_default __ARGS((void));
3543
3544 static char_u *
3545gui_bg_default()
3546{
3547 if (gui_get_lightness(gui.back_pixel) < 127)
3548 return (char_u *)"dark";
3549 return (char_u *)"light";
3550}
3551
3552/*
3553 * Option initializations that can only be done after opening the GUI window.
3554 */
3555 void
3556init_gui_options()
3557{
3558 /* Set the 'background' option according to the lightness of the
3559 * background color, unless the user has set it already. */
3560 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3561 {
3562 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3563 highlight_changed();
3564 }
3565}
3566#endif
3567
3568#ifdef FEAT_TITLE
3569/*
3570 * 'title' and 'icon' only default to true if they have not been set or reset
3571 * in .vimrc and we can read the old value.
3572 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3573 * they can be reset. This reduces startup time when using X on a remote
3574 * machine.
3575 */
3576 void
3577set_title_defaults()
3578{
3579 int idx1;
3580 long val;
3581
3582 /*
3583 * If GUI is (going to be) used, we can always set the window title and
3584 * icon name. Saves a bit of time, because the X11 display server does
3585 * not need to be contacted.
3586 */
3587 idx1 = findoption((char_u *)"title");
3588 if (!(options[idx1].flags & P_WAS_SET))
3589 {
3590#ifdef FEAT_GUI
3591 if (gui.starting || gui.in_use)
3592 val = TRUE;
3593 else
3594#endif
3595 val = mch_can_restore_title();
3596 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3597 p_title = val;
3598 }
3599 idx1 = findoption((char_u *)"icon");
3600 if (!(options[idx1].flags & P_WAS_SET))
3601 {
3602#ifdef FEAT_GUI
3603 if (gui.starting || gui.in_use)
3604 val = TRUE;
3605 else
3606#endif
3607 val = mch_can_restore_icon();
3608 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3609 p_icon = val;
3610 }
3611}
3612#endif
3613
3614/*
3615 * Parse 'arg' for option settings.
3616 *
3617 * 'arg' may be IObuff, but only when no errors can be present and option
3618 * does not need to be expanded with option_expand().
3619 * "opt_flags":
3620 * 0 for ":set"
3621 * OPT_GLOBAL for ":setglobal"
3622 * OPT_LOCAL for ":setlocal" and a modeline
3623 * OPT_MODELINE for a modeline
3624 *
3625 * returns FAIL if an error is detected, OK otherwise
3626 */
3627 int
3628do_set(arg, opt_flags)
3629 char_u *arg; /* option string (may be written to!) */
3630 int opt_flags;
3631{
3632 int opt_idx;
3633 char_u *errmsg;
3634 char_u errbuf[80];
3635 char_u *startarg;
3636 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3637 int nextchar; /* next non-white char after option name */
3638 int afterchar; /* character just after option name */
3639 int len;
3640 int i;
3641 long value;
3642 int key;
3643 long_u flags; /* flags for current option */
3644 char_u *varp = NULL; /* pointer to variable for current option */
3645 int did_show = FALSE; /* already showed one value */
3646 int adding; /* "opt+=arg" */
3647 int prepending; /* "opt^=arg" */
3648 int removing; /* "opt-=arg" */
3649 int cp_val = 0;
3650 char_u key_name[2];
3651
3652 if (*arg == NUL)
3653 {
3654 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003655 did_show = TRUE;
3656 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657 }
3658
3659 while (*arg != NUL) /* loop to process all options */
3660 {
3661 errmsg = NULL;
3662 startarg = arg; /* remember for error message */
3663
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003664 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3665 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666 {
3667 /*
3668 * ":set all" show all options.
3669 * ":set all&" set all options to their default value.
3670 */
3671 arg += 3;
3672 if (*arg == '&')
3673 {
3674 ++arg;
3675 /* Only for :set command set global value of local options. */
3676 set_options_default(OPT_FREE | opt_flags);
3677 }
3678 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003679 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003681 did_show = TRUE;
3682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003684 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685 {
3686 showoptions(2, opt_flags);
3687 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003688 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689 arg += 7;
3690 }
3691 else
3692 {
3693 prefix = 1;
3694 if (STRNCMP(arg, "no", 2) == 0)
3695 {
3696 prefix = 0;
3697 arg += 2;
3698 }
3699 else if (STRNCMP(arg, "inv", 3) == 0)
3700 {
3701 prefix = 2;
3702 arg += 3;
3703 }
3704
3705 /* find end of name */
3706 key = 0;
3707 if (*arg == '<')
3708 {
3709 nextchar = 0;
3710 opt_idx = -1;
3711 /* look out for <t_>;> */
3712 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3713 len = 5;
3714 else
3715 {
3716 len = 1;
3717 while (arg[len] != NUL && arg[len] != '>')
3718 ++len;
3719 }
3720 if (arg[len] != '>')
3721 {
3722 errmsg = e_invarg;
3723 goto skip;
3724 }
3725 arg[len] = NUL; /* put NUL after name */
3726 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3727 opt_idx = findoption(arg + 1);
3728 arg[len++] = '>'; /* restore '>' */
3729 if (opt_idx == -1)
3730 key = find_key_option(arg + 1);
3731 }
3732 else
3733 {
3734 len = 0;
3735 /*
3736 * The two characters after "t_" may not be alphanumeric.
3737 */
3738 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3739 len = 4;
3740 else
3741 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3742 ++len;
3743 nextchar = arg[len];
3744 arg[len] = NUL; /* put NUL after name */
3745 opt_idx = findoption(arg);
3746 arg[len] = nextchar; /* restore nextchar */
3747 if (opt_idx == -1)
3748 key = find_key_option(arg);
3749 }
3750
3751 /* remember character after option name */
3752 afterchar = arg[len];
3753
3754 /* skip white space, allow ":set ai ?" */
3755 while (vim_iswhite(arg[len]))
3756 ++len;
3757
3758 adding = FALSE;
3759 prepending = FALSE;
3760 removing = FALSE;
3761 if (arg[len] != NUL && arg[len + 1] == '=')
3762 {
3763 if (arg[len] == '+')
3764 {
3765 adding = TRUE; /* "+=" */
3766 ++len;
3767 }
3768 else if (arg[len] == '^')
3769 {
3770 prepending = TRUE; /* "^=" */
3771 ++len;
3772 }
3773 else if (arg[len] == '-')
3774 {
3775 removing = TRUE; /* "-=" */
3776 ++len;
3777 }
3778 }
3779 nextchar = arg[len];
3780
3781 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3782 {
3783 errmsg = (char_u *)N_("E518: Unknown option");
3784 goto skip;
3785 }
3786
3787 if (opt_idx >= 0)
3788 {
3789 if (options[opt_idx].var == NULL) /* hidden option: skip */
3790 {
3791 /* Only give an error message when requesting the value of
3792 * a hidden option, ignore setting it. */
3793 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3794 && (!(options[opt_idx].flags & P_BOOL)
3795 || nextchar == '?'))
3796 errmsg = (char_u *)N_("E519: Option not supported");
3797 goto skip;
3798 }
3799
3800 flags = options[opt_idx].flags;
3801 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3802 }
3803 else
3804 {
3805 flags = P_STRING;
3806 if (key < 0)
3807 {
3808 key_name[0] = KEY2TERMCAP0(key);
3809 key_name[1] = KEY2TERMCAP1(key);
3810 }
3811 else
3812 {
3813 key_name[0] = KS_KEY;
3814 key_name[1] = (key & 0xff);
3815 }
3816 }
3817
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003818 /* Skip all options that are not window-local (used when showing
3819 * an already loaded buffer in a window). */
3820 if ((opt_flags & OPT_WINONLY)
3821 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
3822 goto skip;
3823
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824 /* Disallow changing some options from modelines */
3825 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3826 {
3827 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3828 goto skip;
3829 }
3830
3831#ifdef HAVE_SANDBOX
3832 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003833 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 {
3835 errmsg = (char_u *)_(e_sandbox);
3836 goto skip;
3837 }
3838#endif
3839
3840 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3841 {
3842 arg += len;
3843 cp_val = p_cp;
3844 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3845 {
3846 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3847 {
3848 cp_val = FALSE;
3849 arg += 3;
3850 }
3851 else /* "opt&vi": set to Vi default */
3852 {
3853 cp_val = TRUE;
3854 arg += 2;
3855 }
3856 }
3857 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3858 && arg[1] != NUL && !vim_iswhite(arg[1]))
3859 {
3860 errmsg = e_trailing;
3861 goto skip;
3862 }
3863 }
3864
3865 /*
3866 * allow '=' and ':' as MSDOS command.com allows only one
3867 * '=' character per "set" command line. grrr. (jw)
3868 */
3869 if (nextchar == '?'
3870 || (prefix == 1
3871 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
3872 && !(flags & P_BOOL)))
3873 {
3874 /*
3875 * print value
3876 */
3877 if (did_show)
3878 msg_putchar('\n'); /* cursor below last one */
3879 else
3880 {
3881 gotocmdline(TRUE); /* cursor at status line */
3882 did_show = TRUE; /* remember that we did a line */
3883 }
3884 if (opt_idx >= 0)
3885 {
3886 showoneopt(&options[opt_idx], opt_flags);
3887#ifdef FEAT_EVAL
3888 if (p_verbose > 0)
Bram Moolenaar661b1822005-07-28 22:36:45 +00003889 last_set_msg(options[opt_idx].scriptID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890#endif
3891 }
3892 else
3893 {
3894 char_u *p;
3895
3896 p = find_termcode(key_name);
3897 if (p == NULL)
3898 {
3899 errmsg = (char_u *)N_("E518: Unknown option");
3900 goto skip;
3901 }
3902 else
3903 (void)show_one_termcode(key_name, p, TRUE);
3904 }
3905 if (nextchar != '?'
3906 && nextchar != NUL && !vim_iswhite(afterchar))
3907 errmsg = e_trailing;
3908 }
3909 else
3910 {
3911 if (flags & P_BOOL) /* boolean */
3912 {
3913 if (nextchar == '=' || nextchar == ':')
3914 {
3915 errmsg = e_invarg;
3916 goto skip;
3917 }
3918
3919 /*
3920 * ":set opt!": invert
3921 * ":set opt&": reset to default value
3922 * ":set opt<": reset to global value
3923 */
3924 if (nextchar == '!')
3925 value = *(int *)(varp) ^ 1;
3926 else if (nextchar == '&')
3927 value = (int)(long)options[opt_idx].def_val[
3928 ((flags & P_VI_DEF) || cp_val)
3929 ? VI_DEFAULT : VIM_DEFAULT];
3930 else if (nextchar == '<')
3931 {
3932 /* For 'autoread' -1 means to use global value. */
3933 if ((int *)varp == &curbuf->b_p_ar
3934 && opt_flags == OPT_LOCAL)
3935 value = -1;
3936 else
3937 value = *(int *)get_varp_scope(&(options[opt_idx]),
3938 OPT_GLOBAL);
3939 }
3940 else
3941 {
3942 /*
3943 * ":set invopt": invert
3944 * ":set opt" or ":set noopt": set or reset
3945 */
3946 if (nextchar != NUL && !vim_iswhite(afterchar))
3947 {
3948 errmsg = e_trailing;
3949 goto skip;
3950 }
3951 if (prefix == 2) /* inv */
3952 value = *(int *)(varp) ^ 1;
3953 else
3954 value = prefix;
3955 }
3956
3957 errmsg = set_bool_option(opt_idx, varp, (int)value,
3958 opt_flags);
3959 }
3960 else /* numeric or string */
3961 {
3962 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
3963 || prefix != 1)
3964 {
3965 errmsg = e_invarg;
3966 goto skip;
3967 }
3968
3969 if (flags & P_NUM) /* numeric */
3970 {
3971 /*
3972 * Different ways to set a number option:
3973 * & set to default value
3974 * < set to global value
3975 * <xx> accept special key codes for 'wildchar'
3976 * c accept any non-digit for 'wildchar'
3977 * [-]0-9 set number
3978 * other error
3979 */
3980 ++arg;
3981 if (nextchar == '&')
3982 value = (long)options[opt_idx].def_val[
3983 ((flags & P_VI_DEF) || cp_val)
3984 ? VI_DEFAULT : VIM_DEFAULT];
3985 else if (nextchar == '<')
3986 value = *(long *)get_varp_scope(&(options[opt_idx]),
3987 OPT_GLOBAL);
3988 else if (((long *)varp == &p_wc
3989 || (long *)varp == &p_wcm)
3990 && (*arg == '<'
3991 || *arg == '^'
3992 || ((!arg[1] || vim_iswhite(arg[1]))
3993 && !VIM_ISDIGIT(*arg))))
3994 {
3995 value = string_to_key(arg);
3996 if (value == 0 && (long *)varp != &p_wcm)
3997 {
3998 errmsg = e_invarg;
3999 goto skip;
4000 }
4001 }
4002 /* allow negative numbers (for 'undolevels') */
4003 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4004 {
4005 i = 0;
4006 if (*arg == '-')
4007 i = 1;
4008#ifdef HAVE_STRTOL
4009 value = strtol((char *)arg, NULL, 0);
4010 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4011 i += 2;
4012#else
4013 value = atol((char *)arg);
4014#endif
4015 while (VIM_ISDIGIT(arg[i]))
4016 ++i;
4017 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4018 {
4019 errmsg = e_invarg;
4020 goto skip;
4021 }
4022 }
4023 else
4024 {
4025 errmsg = (char_u *)N_("E521: Number required after =");
4026 goto skip;
4027 }
4028
4029 if (adding)
4030 value = *(long *)varp + value;
4031 if (prepending)
4032 value = *(long *)varp * value;
4033 if (removing)
4034 value = *(long *)varp - value;
4035 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004036 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 }
4038 else if (opt_idx >= 0) /* string */
4039 {
4040 char_u *save_arg = NULL;
4041 char_u *s = NULL;
4042 char_u *oldval; /* previous value if *varp */
4043 char_u *newval;
4044 char_u *origval;
4045 unsigned newlen;
4046 int comma;
4047 int bs;
4048 int new_value_alloced; /* new string option
4049 was allocated */
4050
4051 /* When using ":set opt=val" for a global option
4052 * with a local value the local value will be
4053 * reset, use the global value here. */
4054 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4055 && (int)options[opt_idx].indir >= PV_BOTH)
4056 varp = options[opt_idx].var;
4057
4058 /* The old value is kept until we are sure that the
4059 * new value is valid. */
4060 oldval = *(char_u **)varp;
4061 if (nextchar == '&') /* set to default val */
4062 {
4063 newval = options[opt_idx].def_val[
4064 ((flags & P_VI_DEF) || cp_val)
4065 ? VI_DEFAULT : VIM_DEFAULT];
4066 if ((char_u **)varp == &p_bg)
4067 {
4068 /* guess the value of 'background' */
4069#ifdef FEAT_GUI
4070 if (gui.in_use)
4071 newval = gui_bg_default();
4072 else
4073#endif
4074 if (STRCMP(T_NAME, "linux") == 0)
4075 newval = (char_u *)"dark";
4076 }
4077
4078 /* expand environment variables and ~ (since the
4079 * default value was already expanded, only
4080 * required when an environment variable was set
4081 * later */
4082 if (newval == NULL)
4083 newval = empty_option;
4084 else
4085 {
4086 s = option_expand(opt_idx, newval);
4087 if (s == NULL)
4088 s = newval;
4089 newval = vim_strsave(s);
4090 }
4091 new_value_alloced = TRUE;
4092 }
4093 else if (nextchar == '<') /* set to global val */
4094 {
4095 newval = vim_strsave(*(char_u **)get_varp_scope(
4096 &(options[opt_idx]), OPT_GLOBAL));
4097 new_value_alloced = TRUE;
4098 }
4099 else
4100 {
4101 ++arg; /* jump to after the '=' or ':' */
4102
4103 /*
4104 * Set 'keywordprg' to ":help" if an empty
4105 * value was passed to :set by the user.
4106 * Misuse errbuf[] for the resulting string.
4107 */
4108 if (varp == (char_u *)&p_kp
4109 && (*arg == NUL || *arg == ' '))
4110 {
4111 STRCPY(errbuf, ":help");
4112 save_arg = arg;
4113 arg = errbuf;
4114 }
4115 /*
4116 * Convert 'whichwrap' number to string, for
4117 * backwards compatibility with Vim 3.0.
4118 * Misuse errbuf[] for the resulting string.
4119 */
4120 else if (varp == (char_u *)&p_ww
4121 && VIM_ISDIGIT(*arg))
4122 {
4123 *errbuf = NUL;
4124 i = getdigits(&arg);
4125 if (i & 1)
4126 STRCAT(errbuf, "b,");
4127 if (i & 2)
4128 STRCAT(errbuf, "s,");
4129 if (i & 4)
4130 STRCAT(errbuf, "h,l,");
4131 if (i & 8)
4132 STRCAT(errbuf, "<,>,");
4133 if (i & 16)
4134 STRCAT(errbuf, "[,],");
4135 if (*errbuf != NUL) /* remove trailing , */
4136 errbuf[STRLEN(errbuf) - 1] = NUL;
4137 save_arg = arg;
4138 arg = errbuf;
4139 }
4140 /*
4141 * Remove '>' before 'dir' and 'bdir', for
4142 * backwards compatibility with version 3.0
4143 */
4144 else if ( *arg == '>'
4145 && (varp == (char_u *)&p_dir
4146 || varp == (char_u *)&p_bdir))
4147 {
4148 ++arg;
4149 }
4150
4151 /* When setting the local value of a global
4152 * option, the old value may be the global value. */
4153 if ((int)options[opt_idx].indir >= PV_BOTH
4154 && (opt_flags & OPT_LOCAL))
4155 origval = *(char_u **)get_varp(
4156 &options[opt_idx]);
4157 else
4158 origval = oldval;
4159
4160 /*
4161 * Copy the new string into allocated memory.
4162 * Can't use set_string_option_direct(), because
4163 * we need to remove the backslashes.
4164 */
4165 /* get a bit too much */
4166 newlen = (unsigned)STRLEN(arg) + 1;
4167 if (adding || prepending || removing)
4168 newlen += (unsigned)STRLEN(origval) + 1;
4169 newval = alloc(newlen);
4170 if (newval == NULL) /* out of mem, don't change */
4171 break;
4172 s = newval;
4173
4174 /*
4175 * Copy the string, skip over escaped chars.
4176 * For MS-DOS and WIN32 backslashes before normal
4177 * file name characters are not removed, and keep
4178 * backslash at start, for "\\machine\path", but
4179 * do remove it for "\\\\machine\\path".
4180 * The reverse is found in ExpandOldSetting().
4181 */
4182 while (*arg && !vim_iswhite(*arg))
4183 {
4184 if (*arg == '\\' && arg[1] != NUL
4185#ifdef BACKSLASH_IN_FILENAME
4186 && !((flags & P_EXPAND)
4187 && vim_isfilec(arg[1])
4188 && (arg[1] != '\\'
4189 || (s == newval
4190 && arg[2] != '\\')))
4191#endif
4192 )
4193 ++arg; /* remove backslash */
4194#ifdef FEAT_MBYTE
4195 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004196 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197 {
4198 /* copy multibyte char */
4199 mch_memmove(s, arg, (size_t)i);
4200 arg += i;
4201 s += i;
4202 }
4203 else
4204#endif
4205 *s++ = *arg++;
4206 }
4207 *s = NUL;
4208
4209 /*
4210 * Expand environment variables and ~.
4211 * Don't do it when adding without inserting a
4212 * comma.
4213 */
4214 if (!(adding || prepending || removing)
4215 || (flags & P_COMMA))
4216 {
4217 s = option_expand(opt_idx, newval);
4218 if (s != NULL)
4219 {
4220 vim_free(newval);
4221 newlen = (unsigned)STRLEN(s) + 1;
4222 if (adding || prepending || removing)
4223 newlen += (unsigned)STRLEN(origval) + 1;
4224 newval = alloc(newlen);
4225 if (newval == NULL)
4226 break;
4227 STRCPY(newval, s);
4228 }
4229 }
4230
4231 /* locate newval[] in origval[] when removing it
4232 * and when adding to avoid duplicates */
4233 i = 0; /* init for GCC */
4234 if (removing || (flags & P_NODUP))
4235 {
4236 i = (int)STRLEN(newval);
4237 bs = 0;
4238 for (s = origval; *s; ++s)
4239 {
4240 if ((!(flags & P_COMMA)
4241 || s == origval
4242 || (s[-1] == ',' && !(bs & 1)))
4243 && STRNCMP(s, newval, i) == 0
4244 && (!(flags & P_COMMA)
4245 || s[i] == ','
4246 || s[i] == NUL))
4247 break;
4248 /* Count backspaces. Only a comma with an
4249 * even number of backspaces before it is
4250 * recognized as a separator */
4251 if (s > origval && s[-1] == '\\')
4252 ++bs;
4253 else
4254 bs = 0;
4255 }
4256
4257 /* do not add if already there */
4258 if ((adding || prepending) && *s)
4259 {
4260 prepending = FALSE;
4261 adding = FALSE;
4262 STRCPY(newval, origval);
4263 }
4264 }
4265
4266 /* concatenate the two strings; add a ',' if
4267 * needed */
4268 if (adding || prepending)
4269 {
4270 comma = ((flags & P_COMMA) && *origval != NUL
4271 && *newval != NUL);
4272 if (adding)
4273 {
4274 i = (int)STRLEN(origval);
4275 mch_memmove(newval + i + comma, newval,
4276 STRLEN(newval) + 1);
4277 mch_memmove(newval, origval, (size_t)i);
4278 }
4279 else
4280 {
4281 i = (int)STRLEN(newval);
4282 mch_memmove(newval + i + comma, origval,
4283 STRLEN(origval) + 1);
4284 }
4285 if (comma)
4286 newval[i] = ',';
4287 }
4288
4289 /* Remove newval[] from origval[]. (Note: "i" has
4290 * been set above and is used here). */
4291 if (removing)
4292 {
4293 STRCPY(newval, origval);
4294 if (*s)
4295 {
4296 /* may need to remove a comma */
4297 if (flags & P_COMMA)
4298 {
4299 if (s == origval)
4300 {
4301 /* include comma after string */
4302 if (s[i] == ',')
4303 ++i;
4304 }
4305 else
4306 {
4307 /* include comma before string */
4308 --s;
4309 ++i;
4310 }
4311 }
4312 mch_memmove(newval + (s - origval), s + i,
4313 STRLEN(s + i) + 1);
4314 }
4315 }
4316
4317 if (flags & P_FLAGLIST)
4318 {
4319 /* Remove flags that appear twice. */
4320 for (s = newval; *s; ++s)
4321 if ((!(flags & P_COMMA) || *s != ',')
4322 && vim_strchr(s + 1, *s) != NULL)
4323 {
4324 STRCPY(s, s + 1);
4325 --s;
4326 }
4327 }
4328
4329 if (save_arg != NULL) /* number for 'whichwrap' */
4330 arg = save_arg;
4331 new_value_alloced = TRUE;
4332 }
4333
4334 /* Set the new value. */
4335 *(char_u **)(varp) = newval;
4336
4337 /* Handle side effects, and set the global value for
4338 * ":set" on local options. */
4339 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4340 new_value_alloced, oldval, errbuf, opt_flags);
4341
4342 /* If error detected, print the error message. */
4343 if (errmsg != NULL)
4344 goto skip;
4345 }
4346 else /* key code option */
4347 {
4348 char_u *p;
4349
4350 if (nextchar == '&')
4351 {
4352 if (add_termcap_entry(key_name, TRUE) == FAIL)
4353 errmsg = (char_u *)N_("E522: Not found in termcap");
4354 }
4355 else
4356 {
4357 ++arg; /* jump to after the '=' or ':' */
4358 for (p = arg; *p && !vim_iswhite(*p); ++p)
4359 if (*p == '\\' && p[1] != NUL)
4360 ++p;
4361 nextchar = *p;
4362 *p = NUL;
4363 add_termcode(key_name, arg, FALSE);
4364 *p = nextchar;
4365 }
4366 if (full_screen)
4367 ttest(FALSE);
4368 redraw_all_later(CLEAR);
4369 }
4370 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004371
Bram Moolenaar071d4272004-06-13 20:20:40 +00004372 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004373 did_set_option(opt_idx, opt_flags,
4374 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 }
4376
4377skip:
4378 /*
4379 * Advance to next argument.
4380 * - skip until a blank found, taking care of backslashes
4381 * - skip blanks
4382 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4383 */
4384 for (i = 0; i < 2 ; ++i)
4385 {
4386 while (*arg != NUL && !vim_iswhite(*arg))
4387 if (*arg++ == '\\' && *arg != NUL)
4388 ++arg;
4389 arg = skipwhite(arg);
4390 if (*arg != '=')
4391 break;
4392 }
4393 }
4394
4395 if (errmsg != NULL)
4396 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004397 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004398 i = STRLEN(IObuff) + 2;
4399 if (i + (arg - startarg) < IOSIZE)
4400 {
4401 /* append the argument with the error */
4402 STRCAT(IObuff, ": ");
4403 mch_memmove(IObuff + i, startarg, (arg - startarg));
4404 IObuff[i + (arg - startarg)] = NUL;
4405 }
4406 /* make sure all characters are printable */
4407 trans_characters(IObuff, IOSIZE);
4408
4409 ++no_wait_return; /* wait_return done later */
4410 emsg(IObuff); /* show error highlighted */
4411 --no_wait_return;
4412
4413 return FAIL;
4414 }
4415
4416 arg = skipwhite(arg);
4417 }
4418
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004419theend:
4420 if (silent_mode && did_show)
4421 {
4422 /* After displaying option values in silent mode. */
4423 silent_mode = FALSE;
4424 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4425 msg_putchar('\n');
4426 cursor_on(); /* msg_start() switches it off */
4427 out_flush();
4428 silent_mode = TRUE;
4429 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4430 }
4431
Bram Moolenaar071d4272004-06-13 20:20:40 +00004432 return OK;
4433}
4434
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004435/*
4436 * Call this when an option has been given a new value through a user command.
4437 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4438 */
4439 static void
4440did_set_option(opt_idx, opt_flags, new_value)
4441 int opt_idx;
4442 int opt_flags; /* possibly with OPT_MODELINE */
4443 int new_value; /* value was replaced completely */
4444{
4445 options[opt_idx].flags |= P_WAS_SET;
4446
4447 /* When an option is set in the sandbox, from a modeline or in secure mode
4448 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
4449 * flag. */
4450 if (secure
4451#ifdef HAVE_SANDBOX
4452 || sandbox != 0
4453#endif
4454 || (opt_flags & OPT_MODELINE))
4455 options[opt_idx].flags |= P_INSECURE;
4456 else if (new_value)
4457 options[opt_idx].flags &= ~P_INSECURE;
4458}
4459
Bram Moolenaar071d4272004-06-13 20:20:40 +00004460 static char_u *
4461illegal_char(errbuf, c)
4462 char_u *errbuf;
4463 int c;
4464{
4465 if (errbuf == NULL)
4466 return (char_u *)"";
4467 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004468 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004469 return errbuf;
4470}
4471
4472/*
4473 * Convert a key name or string into a key value.
4474 * Used for 'wildchar' and 'cedit' options.
4475 */
4476 static int
4477string_to_key(arg)
4478 char_u *arg;
4479{
4480 if (*arg == '<')
4481 return find_key_option(arg + 1);
4482 if (*arg == '^')
4483 return Ctrl_chr(arg[1]);
4484 return *arg;
4485}
4486
4487#ifdef FEAT_CMDWIN
4488/*
4489 * Check value of 'cedit' and set cedit_key.
4490 * Returns NULL if value is OK, error message otherwise.
4491 */
4492 static char_u *
4493check_cedit()
4494{
4495 int n;
4496
4497 if (*p_cedit == NUL)
4498 cedit_key = -1;
4499 else
4500 {
4501 n = string_to_key(p_cedit);
4502 if (vim_isprintc(n))
4503 return e_invarg;
4504 cedit_key = n;
4505 }
4506 return NULL;
4507}
4508#endif
4509
4510#ifdef FEAT_TITLE
4511/*
4512 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4513 * maketitle() to create and display it.
4514 * When switching the title or icon off, call mch_restore_title() to get
4515 * the old value back.
4516 */
4517 static void
4518did_set_title(icon)
4519 int icon; /* Did set icon instead of title */
4520{
4521 if (starting != NO_SCREEN
4522#ifdef FEAT_GUI
4523 && !gui.starting
4524#endif
4525 )
4526 {
4527 maketitle();
4528 if (icon)
4529 {
4530 if (!p_icon)
4531 mch_restore_title(2);
4532 }
4533 else
4534 {
4535 if (!p_title)
4536 mch_restore_title(1);
4537 }
4538 }
4539}
4540#endif
4541
4542/*
4543 * set_options_bin - called when 'bin' changes value.
4544 */
4545 void
4546set_options_bin(oldval, newval, opt_flags)
4547 int oldval;
4548 int newval;
4549 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4550{
4551 /*
4552 * The option values that are changed when 'bin' changes are
4553 * copied when 'bin is set and restored when 'bin' is reset.
4554 */
4555 if (newval)
4556 {
4557 if (!oldval) /* switched on */
4558 {
4559 if (!(opt_flags & OPT_GLOBAL))
4560 {
4561 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4562 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4563 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4564 curbuf->b_p_et_nobin = curbuf->b_p_et;
4565 }
4566 if (!(opt_flags & OPT_LOCAL))
4567 {
4568 p_tw_nobin = p_tw;
4569 p_wm_nobin = p_wm;
4570 p_ml_nobin = p_ml;
4571 p_et_nobin = p_et;
4572 }
4573 }
4574
4575 if (!(opt_flags & OPT_GLOBAL))
4576 {
4577 curbuf->b_p_tw = 0; /* no automatic line wrap */
4578 curbuf->b_p_wm = 0; /* no automatic line wrap */
4579 curbuf->b_p_ml = 0; /* no modelines */
4580 curbuf->b_p_et = 0; /* no expandtab */
4581 }
4582 if (!(opt_flags & OPT_LOCAL))
4583 {
4584 p_tw = 0;
4585 p_wm = 0;
4586 p_ml = FALSE;
4587 p_et = FALSE;
4588 p_bin = TRUE; /* needed when called for the "-b" argument */
4589 }
4590 }
4591 else if (oldval) /* switched off */
4592 {
4593 if (!(opt_flags & OPT_GLOBAL))
4594 {
4595 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4596 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4597 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4598 curbuf->b_p_et = curbuf->b_p_et_nobin;
4599 }
4600 if (!(opt_flags & OPT_LOCAL))
4601 {
4602 p_tw = p_tw_nobin;
4603 p_wm = p_wm_nobin;
4604 p_ml = p_ml_nobin;
4605 p_et = p_et_nobin;
4606 }
4607 }
4608}
4609
4610#ifdef FEAT_VIMINFO
4611/*
4612 * Find the parameter represented by the given character (eg ', :, ", or /),
4613 * and return its associated value in the 'viminfo' string.
4614 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004615 * If the parameter is not specified in the string or there is no following
4616 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 */
4618 int
4619get_viminfo_parameter(type)
4620 int type;
4621{
4622 char_u *p;
4623
4624 p = find_viminfo_parameter(type);
4625 if (p != NULL && VIM_ISDIGIT(*p))
4626 return atoi((char *)p);
4627 return -1;
4628}
4629
4630/*
4631 * Find the parameter represented by the given character (eg ''', ':', '"', or
4632 * '/') in the 'viminfo' option and return a pointer to the string after it.
4633 * Return NULL if the parameter is not specified in the string.
4634 */
4635 char_u *
4636find_viminfo_parameter(type)
4637 int type;
4638{
4639 char_u *p;
4640
4641 for (p = p_viminfo; *p; ++p)
4642 {
4643 if (*p == type)
4644 return p + 1;
4645 if (*p == 'n') /* 'n' is always the last one */
4646 break;
4647 p = vim_strchr(p, ','); /* skip until next ',' */
4648 if (p == NULL) /* hit the end without finding parameter */
4649 break;
4650 }
4651 return NULL;
4652}
4653#endif
4654
4655/*
4656 * Expand environment variables for some string options.
4657 * These string options cannot be indirect!
4658 * If "val" is NULL expand the current value of the option.
4659 * Return pointer to NameBuff, or NULL when not expanded.
4660 */
4661 static char_u *
4662option_expand(opt_idx, val)
4663 int opt_idx;
4664 char_u *val;
4665{
4666 /* if option doesn't need expansion nothing to do */
4667 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4668 return NULL;
4669
4670 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4671 * expand_env() would truncate the string. */
4672 if (val != NULL && STRLEN(val) > MAXPATHL)
4673 return NULL;
4674
4675 if (val == NULL)
4676 val = *(char_u **)options[opt_idx].var;
4677
4678 /*
4679 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4680 * Escape spaces when expanding 'tags', they are used to separate file
4681 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004682 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004683 */
4684 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004685 (char_u **)options[opt_idx].var == &p_tags,
4686#ifdef FEAT_SYN_HL
4687 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4688#endif
4689 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004690 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4691 return NULL;
4692
4693 return NameBuff;
4694}
4695
4696/*
4697 * After setting various option values: recompute variables that depend on
4698 * option values.
4699 */
4700 static void
4701didset_options()
4702{
4703 /* initialize the table for 'iskeyword' et.al. */
4704 (void)init_chartab();
4705
4706 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4707 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4708#ifdef FEAT_SESSION
4709 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4710 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4711#endif
4712#ifdef FEAT_FOLDING
4713 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4714#endif
4715 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4716#ifdef FEAT_VIRTUALEDIT
4717 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4718#endif
4719#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4720 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4721#endif
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004722#ifdef FEAT_SYN_HL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004723 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004724 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004725 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4728 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4729#endif
4730#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4731 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4732#endif
4733#ifdef FEAT_CMDWIN
4734 /* set cedit_key */
4735 (void)check_cedit();
4736#endif
4737}
4738
4739/*
4740 * Check for string options that are NULL (normally only termcap options).
4741 */
4742 void
4743check_options()
4744{
4745 int opt_idx;
4746
4747 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4748 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4749 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4750}
4751
4752/*
4753 * Check string options in a buffer for NULL value.
4754 */
4755 void
4756check_buf_options(buf)
4757 buf_T *buf;
4758{
4759#if defined(FEAT_QUICKFIX)
4760 check_string_option(&buf->b_p_bh);
4761 check_string_option(&buf->b_p_bt);
4762#endif
4763#ifdef FEAT_MBYTE
4764 check_string_option(&buf->b_p_fenc);
4765#endif
4766 check_string_option(&buf->b_p_ff);
4767#ifdef FEAT_FIND_ID
4768 check_string_option(&buf->b_p_def);
4769 check_string_option(&buf->b_p_inc);
4770# ifdef FEAT_EVAL
4771 check_string_option(&buf->b_p_inex);
4772# endif
4773#endif
4774#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4775 check_string_option(&buf->b_p_inde);
4776 check_string_option(&buf->b_p_indk);
4777#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00004778#if defined(FEAT_EVAL)
4779 check_string_option(&buf->b_p_fex);
4780#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004781#ifdef FEAT_CRYPT
4782 check_string_option(&buf->b_p_key);
4783#endif
4784 check_string_option(&buf->b_p_kp);
4785 check_string_option(&buf->b_p_mps);
4786 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004787 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004788 check_string_option(&buf->b_p_isk);
4789#ifdef FEAT_COMMENTS
4790 check_string_option(&buf->b_p_com);
4791#endif
4792#ifdef FEAT_FOLDING
4793 check_string_option(&buf->b_p_cms);
4794#endif
4795 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004796#ifdef FEAT_TEXTOBJ
4797 check_string_option(&buf->b_p_qe);
4798#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799#ifdef FEAT_SYN_HL
4800 check_string_option(&buf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004801 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00004802 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00004803 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804#endif
4805#ifdef FEAT_SEARCHPATH
4806 check_string_option(&buf->b_p_sua);
4807#endif
4808#ifdef FEAT_CINDENT
4809 check_string_option(&buf->b_p_cink);
4810 check_string_option(&buf->b_p_cino);
4811#endif
4812#ifdef FEAT_AUTOCMD
4813 check_string_option(&buf->b_p_ft);
4814#endif
4815#ifdef FEAT_OSFILETYPE
4816 check_string_option(&buf->b_p_oft);
4817#endif
4818#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4819 check_string_option(&buf->b_p_cinw);
4820#endif
4821#ifdef FEAT_INS_EXPAND
4822 check_string_option(&buf->b_p_cpt);
4823#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004824#ifdef FEAT_COMPL_FUNC
4825 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00004826 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004827#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004828#ifdef FEAT_KEYMAP
4829 check_string_option(&buf->b_p_keymap);
4830#endif
4831#ifdef FEAT_QUICKFIX
4832 check_string_option(&buf->b_p_gp);
4833 check_string_option(&buf->b_p_mp);
4834 check_string_option(&buf->b_p_efm);
4835#endif
4836 check_string_option(&buf->b_p_ep);
4837 check_string_option(&buf->b_p_path);
4838 check_string_option(&buf->b_p_tags);
4839#ifdef FEAT_INS_EXPAND
4840 check_string_option(&buf->b_p_dict);
4841 check_string_option(&buf->b_p_tsr);
4842#endif
4843}
4844
4845/*
4846 * Free the string allocated for an option.
4847 * Checks for the string being empty_option. This may happen if we're out of
4848 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4849 * check_options().
4850 * Does NOT check for P_ALLOCED flag!
4851 */
4852 void
4853free_string_option(p)
4854 char_u *p;
4855{
4856 if (p != empty_option)
4857 vim_free(p);
4858}
4859
4860 void
4861clear_string_option(pp)
4862 char_u **pp;
4863{
4864 if (*pp != empty_option)
4865 vim_free(*pp);
4866 *pp = empty_option;
4867}
4868
4869 static void
4870check_string_option(pp)
4871 char_u **pp;
4872{
4873 if (*pp == NULL)
4874 *pp = empty_option;
4875}
4876
4877/*
4878 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4879 */
4880 void
4881set_term_option_alloced(p)
4882 char_u **p;
4883{
4884 int opt_idx;
4885
4886 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4887 if (options[opt_idx].var == (char_u *)p)
4888 {
4889 options[opt_idx].flags |= P_ALLOCED;
4890 return;
4891 }
4892 return; /* cannot happen: didn't find it! */
4893}
4894
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004895#if defined(FEAT_EVAL) || defined(PROTO)
4896/*
4897 * Return TRUE when option "opt" was set from a modeline or in secure mode.
4898 * Return FALSE when it wasn't.
4899 * Return -1 for an unknown option.
4900 */
4901 int
4902was_set_insecurely(opt)
4903 char_u *opt;
4904{
4905 int idx = findoption(opt);
4906
4907 if (idx >= 0)
4908 return (options[idx].flags & P_INSECURE) != 0;
4909 EMSG2(_(e_intern2), "was_set_insecurely()");
4910 return -1;
4911}
4912#endif
4913
Bram Moolenaar071d4272004-06-13 20:20:40 +00004914/*
4915 * Set a string option to a new value (without checking the effect).
4916 * The string is copied into allocated memory.
4917 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4918 */
4919 void
4920set_string_option_direct(name, opt_idx, val, opt_flags)
4921 char_u *name;
4922 int opt_idx;
4923 char_u *val;
4924 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4925{
4926 char_u *s;
4927 char_u **varp;
4928 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
4929
4930 if (opt_idx == -1) /* use name */
4931 {
4932 opt_idx = findoption(name);
4933 if (opt_idx == -1) /* not found (should not happen) */
4934 return;
4935 }
4936
4937 if (options[opt_idx].var == NULL) /* can't set hidden option */
4938 return;
4939
4940 s = vim_strsave(val);
4941 if (s != NULL)
4942 {
4943 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4944 both ? OPT_LOCAL : opt_flags);
4945 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
4946 free_string_option(*varp);
4947 *varp = s;
4948
4949 /* For buffer/window local option may also set the global value. */
4950 if (both)
4951 set_string_option_global(opt_idx, varp);
4952
4953 options[opt_idx].flags |= P_ALLOCED;
4954
4955 /* When setting both values of a global option with a local value,
4956 * make the local value empty, so that the global value is used. */
4957 if ((int)options[opt_idx].indir >= PV_BOTH && both)
4958 {
4959 free_string_option(*varp);
4960 *varp = empty_option;
4961 }
4962 }
4963}
4964
4965/*
4966 * Set global value for string option when it's a local option.
4967 */
4968 static void
4969set_string_option_global(opt_idx, varp)
4970 int opt_idx; /* option index */
4971 char_u **varp; /* pointer to option variable */
4972{
4973 char_u **p, *s;
4974
4975 /* the global value is always allocated */
4976 if (options[opt_idx].var == VAR_WIN)
4977 p = (char_u **)GLOBAL_WO(varp);
4978 else
4979 p = (char_u **)options[opt_idx].var;
4980 if (options[opt_idx].indir != PV_NONE
4981 && p != varp
4982 && (s = vim_strsave(*varp)) != NULL)
4983 {
4984 free_string_option(*p);
4985 *p = s;
4986 }
4987}
4988
4989/*
4990 * Set a string option to a new value, and handle the effects.
4991 */
4992 static void
4993set_string_option(opt_idx, value, opt_flags)
4994 int opt_idx;
4995 char_u *value;
4996 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4997{
4998 char_u *s;
4999 char_u **varp;
5000 char_u *oldval;
5001
5002 if (options[opt_idx].var == NULL) /* don't set hidden option */
5003 return;
5004
5005 s = vim_strsave(value);
5006 if (s != NULL)
5007 {
5008 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5009 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5010 ? ((int)options[opt_idx].indir >= PV_BOTH
5011 ? OPT_GLOBAL : OPT_LOCAL)
5012 : opt_flags);
5013 oldval = *varp;
5014 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005015 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5016 opt_flags) == NULL)
5017 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005018 }
5019}
5020
5021/*
5022 * Handle string options that need some action to perform when changed.
5023 * Returns NULL for success, or an error message for an error.
5024 */
5025 static char_u *
5026did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5027 opt_flags)
5028 int opt_idx; /* index in options[] table */
5029 char_u **varp; /* pointer to the option variable */
5030 int new_value_alloced; /* new value was allocated */
5031 char_u *oldval; /* previous value of the option */
5032 char_u *errbuf; /* buffer for errors, or NULL */
5033 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5034{
5035 char_u *errmsg = NULL;
5036 char_u *s, *p;
5037 int did_chartab = FALSE;
5038 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005039 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040
5041 /* Get the global option to compare with, otherwise we would have to check
5042 * two values for all local options. */
5043 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5044
5045 /* Disallow changing some options from secure mode */
5046 if ((secure
5047#ifdef HAVE_SANDBOX
5048 || sandbox != 0
5049#endif
5050 ) && (options[opt_idx].flags & P_SECURE))
5051 {
5052 errmsg = e_secure;
5053 }
5054
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005055 /* Check for a "normal" file name in some options. Disallow a path
5056 * separator (slash and/or backslash), wildcards and characters that are
5057 * often illegal in a file name. */
5058 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005059 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005060 {
5061 errmsg = e_invarg;
5062 }
5063
Bram Moolenaar071d4272004-06-13 20:20:40 +00005064 /* 'term' */
5065 else if (varp == &T_NAME)
5066 {
5067 if (T_NAME[0] == NUL)
5068 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5069#ifdef FEAT_GUI
5070 if (gui.in_use)
5071 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5072 else if (term_is_gui(T_NAME))
5073 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5074#endif
5075 else if (set_termname(T_NAME) == FAIL)
5076 errmsg = (char_u *)N_("E522: Not found in termcap");
5077 else
5078 /* Screen colors may have changed. */
5079 redraw_later_clear();
5080 }
5081
5082 /* 'backupcopy' */
5083 else if (varp == &p_bkc)
5084 {
5085 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5086 errmsg = e_invarg;
5087 if (((bkc_flags & BKC_AUTO) != 0)
5088 + ((bkc_flags & BKC_YES) != 0)
5089 + ((bkc_flags & BKC_NO) != 0) != 1)
5090 {
5091 /* Must have exactly one of "auto", "yes" and "no". */
5092 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5093 errmsg = e_invarg;
5094 }
5095 }
5096
5097 /* 'backupext' and 'patchmode' */
5098 else if (varp == &p_bex || varp == &p_pm)
5099 {
5100 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5101 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5102 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5103 }
5104
5105 /*
5106 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5107 * If the new option is invalid, use old value. 'lisp' option: refill
5108 * chartab[] for '-' char
5109 */
5110 else if ( varp == &p_isi
5111 || varp == &(curbuf->b_p_isk)
5112 || varp == &p_isp
5113 || varp == &p_isf)
5114 {
5115 if (init_chartab() == FAIL)
5116 {
5117 did_chartab = TRUE; /* need to restore it below */
5118 errmsg = e_invarg; /* error in value */
5119 }
5120 }
5121
5122 /* 'helpfile' */
5123 else if (varp == &p_hf)
5124 {
5125 /* May compute new values for $VIM and $VIMRUNTIME */
5126 if (didset_vim)
5127 {
5128 vim_setenv((char_u *)"VIM", (char_u *)"");
5129 didset_vim = FALSE;
5130 }
5131 if (didset_vimruntime)
5132 {
5133 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5134 didset_vimruntime = FALSE;
5135 }
5136 }
5137
5138#ifdef FEAT_MULTI_LANG
5139 /* 'helplang' */
5140 else if (varp == &p_hlg)
5141 {
5142 /* Check for "", "ab", "ab,cd", etc. */
5143 for (s = p_hlg; *s != NUL; s += 3)
5144 {
5145 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5146 {
5147 errmsg = e_invarg;
5148 break;
5149 }
5150 if (s[2] == NUL)
5151 break;
5152 }
5153 }
5154#endif
5155
5156 /* 'highlight' */
5157 else if (varp == &p_hl)
5158 {
5159 if (highlight_changed() == FAIL)
5160 errmsg = e_invarg; /* invalid flags */
5161 }
5162
5163 /* 'nrformats' */
5164 else if (gvarp == &p_nf)
5165 {
5166 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5167 errmsg = e_invarg;
5168 }
5169
5170#ifdef FEAT_SESSION
5171 /* 'sessionoptions' */
5172 else if (varp == &p_ssop)
5173 {
5174 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5175 errmsg = e_invarg;
5176 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5177 {
5178 /* Don't allow both "sesdir" and "curdir". */
5179 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5180 errmsg = e_invarg;
5181 }
5182 }
5183 /* 'viewoptions' */
5184 else if (varp == &p_vop)
5185 {
5186 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5187 errmsg = e_invarg;
5188 }
5189#endif
5190
5191 /* 'scrollopt' */
5192#ifdef FEAT_SCROLLBIND
5193 else if (varp == &p_sbo)
5194 {
5195 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5196 errmsg = e_invarg;
5197 }
5198#endif
5199
5200 /* 'ambiwidth' */
5201#ifdef FEAT_MBYTE
5202 else if (varp == &p_ambw)
5203 {
5204 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5205 errmsg = e_invarg;
5206 }
5207#endif
5208
5209 /* 'background' */
5210 else if (varp == &p_bg)
5211 {
5212 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5213 {
5214#ifdef FEAT_EVAL
5215 int dark = (*p_bg == 'd');
5216#endif
5217
5218 init_highlight(FALSE, FALSE);
5219
5220#ifdef FEAT_EVAL
5221 if (dark != (*p_bg == 'd')
5222 && get_var_value((char_u *)"g:colors_name") != NULL)
5223 {
5224 /* The color scheme must have set 'background' back to another
5225 * value, that's not what we want here. Disable the color
5226 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005227 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 free_string_option(p_bg);
5229 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5230 check_string_option(&p_bg);
5231 init_highlight(FALSE, FALSE);
5232 }
5233#endif
5234 }
5235 else
5236 errmsg = e_invarg;
5237 }
5238
5239 /* 'wildmode' */
5240 else if (varp == &p_wim)
5241 {
5242 if (check_opt_wim() == FAIL)
5243 errmsg = e_invarg;
5244 }
5245
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005246#ifdef FEAT_CMDL_COMPL
5247 /* 'wildoptions' */
5248 else if (varp == &p_wop)
5249 {
5250 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5251 errmsg = e_invarg;
5252 }
5253#endif
5254
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255#ifdef FEAT_WAK
5256 /* 'winaltkeys' */
5257 else if (varp == &p_wak)
5258 {
5259 if (*p_wak == NUL
5260 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5261 errmsg = e_invarg;
5262# ifdef FEAT_MENU
5263# ifdef FEAT_GUI_MOTIF
5264 else if (gui.in_use)
5265 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5266# else
5267# ifdef FEAT_GUI_GTK
5268 else if (gui.in_use)
5269 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5270# endif
5271# endif
5272# endif
5273 }
5274#endif
5275
5276#ifdef FEAT_AUTOCMD
5277 /* 'eventignore' */
5278 else if (varp == &p_ei)
5279 {
5280 if (check_ei() == FAIL)
5281 errmsg = e_invarg;
5282 }
5283#endif
5284
5285#ifdef FEAT_MBYTE
5286 /* 'encoding' and 'fileencoding' */
5287 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5288 {
5289 if (gvarp == &p_fenc)
5290 {
5291 if (!curbuf->b_p_ma)
5292 errmsg = e_modifiable;
5293 else if (vim_strchr(*varp, ',') != NULL)
5294 /* No comma allowed in 'fileencoding'; catches confusing it
5295 * with 'fileencodings'. */
5296 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005297 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005298 {
5299# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300 /* May show a "+" in the title now. */
5301 need_maketitle = TRUE;
5302# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005303 /* Add 'fileencoding' to the swap file. */
5304 ml_setflags(curbuf);
5305 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005306 }
5307 if (errmsg == NULL)
5308 {
5309 /* canonize the value, so that STRCMP() can be used on it */
5310 p = enc_canonize(*varp);
5311 if (p != NULL)
5312 {
5313 vim_free(*varp);
5314 *varp = p;
5315 }
5316 if (varp == &p_enc)
5317 {
5318 errmsg = mb_init();
5319# ifdef FEAT_TITLE
5320 need_maketitle = TRUE;
5321# endif
5322 }
5323 }
5324
5325# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5326 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5327 {
5328 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5329 if (STRCMP(p_tenc, "utf-8") != 0)
5330 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5331 }
5332# endif
5333
5334 if (errmsg == NULL)
5335 {
5336# ifdef FEAT_KEYMAP
5337 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5338 * (with another encoding). */
5339 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5340 (void)keymap_init();
5341# endif
5342
5343 /* When 'termencoding' is not empty and 'encoding' changes or when
5344 * 'termencoding' changes, need to setup for keyboard input and
5345 * display output conversion. */
5346 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5347 {
5348 convert_setup(&input_conv, p_tenc, p_enc);
5349 convert_setup(&output_conv, p_enc, p_tenc);
5350 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005351
5352# if defined(WIN3264) && defined(FEAT_MBYTE)
5353 /* $HOME may have characters in active code page. */
5354 if (varp == &p_enc)
5355 init_homedir();
5356# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357 }
5358 }
5359#endif
5360
5361#if defined(FEAT_POSTSCRIPT)
5362 else if (varp == &p_penc)
5363 {
5364 /* Canonize printencoding if VIM standard one */
5365 p = enc_canonize(p_penc);
5366 if (p != NULL)
5367 {
5368 vim_free(p_penc);
5369 p_penc = p;
5370 }
5371 else
5372 {
5373 /* Ensure lower case and '-' for '_' */
5374 for (s = p_penc; *s != NUL; s++)
5375 {
5376 if (*s == '_')
5377 *s = '-';
5378 else
5379 *s = TOLOWER_ASC(*s);
5380 }
5381 }
5382 }
5383#endif
5384
Bram Moolenaar9372a112005-12-06 19:59:18 +00005385#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005386 else if (varp == &p_imak)
5387 {
5388 if (gui.in_use && !im_xim_isvalid_imactivate())
5389 errmsg = e_invarg;
5390 }
5391#endif
5392
5393#ifdef FEAT_KEYMAP
5394 else if (varp == &curbuf->b_p_keymap)
5395 {
5396 /* load or unload key mapping tables */
5397 errmsg = keymap_init();
5398
5399 /* When successfully installed a new keymap switch on using it. */
5400 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5401 {
5402 curbuf->b_p_iminsert = B_IMODE_LMAP;
5403 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5404 curbuf->b_p_imsearch = B_IMODE_LMAP;
5405 set_iminsert_global();
5406 set_imsearch_global();
5407# ifdef FEAT_WINDOWS
5408 status_redraw_curbuf();
5409# endif
5410 }
5411 }
5412#endif
5413
5414 /* 'fileformat' */
5415 else if (gvarp == &p_ff)
5416 {
5417 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5418 errmsg = e_modifiable;
5419 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5420 errmsg = e_invarg;
5421 else
5422 {
5423 /* may also change 'textmode' */
5424 if (get_fileformat(curbuf) == EOL_DOS)
5425 curbuf->b_p_tx = TRUE;
5426 else
5427 curbuf->b_p_tx = FALSE;
5428#ifdef FEAT_TITLE
5429 need_maketitle = TRUE;
5430#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005431 /* update flag in swap file */
5432 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433 }
5434 }
5435
5436 /* 'fileformats' */
5437 else if (varp == &p_ffs)
5438 {
5439 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5440 errmsg = e_invarg;
5441 else
5442 {
5443 /* also change 'textauto' */
5444 if (*p_ffs == NUL)
5445 p_ta = FALSE;
5446 else
5447 p_ta = TRUE;
5448 }
5449 }
5450
5451#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5452 /* 'cryptkey' */
5453 else if (gvarp == &p_key)
5454 {
5455 /* Make sure the ":set" command doesn't show the new value in the
5456 * history. */
5457 remove_key_from_history();
5458 }
5459#endif
5460
5461 /* 'matchpairs' */
5462 else if (gvarp == &p_mps)
5463 {
5464 /* Check for "x:y,x:y" */
5465 for (p = *varp; *p != NUL; p += 4)
5466 {
5467 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5468 {
5469 errmsg = e_invarg;
5470 break;
5471 }
5472 if (p[3] == NUL)
5473 break;
5474 }
5475 }
5476
5477#ifdef FEAT_COMMENTS
5478 /* 'comments' */
5479 else if (gvarp == &p_com)
5480 {
5481 for (s = *varp; *s; )
5482 {
5483 while (*s && *s != ':')
5484 {
5485 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5486 && !VIM_ISDIGIT(*s) && *s != '-')
5487 {
5488 errmsg = illegal_char(errbuf, *s);
5489 break;
5490 }
5491 ++s;
5492 }
5493 if (*s++ == NUL)
5494 errmsg = (char_u *)N_("E524: Missing colon");
5495 else if (*s == ',' || *s == NUL)
5496 errmsg = (char_u *)N_("E525: Zero length string");
5497 if (errmsg != NULL)
5498 break;
5499 while (*s && *s != ',')
5500 {
5501 if (*s == '\\' && s[1] != NUL)
5502 ++s;
5503 ++s;
5504 }
5505 s = skip_to_option_part(s);
5506 }
5507 }
5508#endif
5509
5510 /* 'listchars' */
5511 else if (varp == &p_lcs)
5512 {
5513 errmsg = set_chars_option(varp);
5514 }
5515
5516#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5517 /* 'fillchars' */
5518 else if (varp == &p_fcs)
5519 {
5520 errmsg = set_chars_option(varp);
5521 }
5522#endif
5523
5524#ifdef FEAT_CMDWIN
5525 /* 'cedit' */
5526 else if (varp == &p_cedit)
5527 {
5528 errmsg = check_cedit();
5529 }
5530#endif
5531
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005532 /* 'verbosefile' */
5533 else if (varp == &p_vfile)
5534 {
5535 verbose_stop();
5536 if (*p_vfile != NUL && verbose_open() == FAIL)
5537 errmsg = e_invarg;
5538 }
5539
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540#ifdef FEAT_VIMINFO
5541 /* 'viminfo' */
5542 else if (varp == &p_viminfo)
5543 {
5544 for (s = p_viminfo; *s;)
5545 {
5546 /* Check it's a valid character */
5547 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5548 {
5549 errmsg = illegal_char(errbuf, *s);
5550 break;
5551 }
5552 if (*s == 'n') /* name is always last one */
5553 {
5554 break;
5555 }
5556 else if (*s == 'r') /* skip until next ',' */
5557 {
5558 while (*++s && *s != ',')
5559 ;
5560 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005561 else if (*s == '%')
5562 {
5563 /* optional number */
5564 while (vim_isdigit(*++s))
5565 ;
5566 }
5567 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568 ++s; /* no extra chars */
5569 else /* must have a number */
5570 {
5571 while (vim_isdigit(*++s))
5572 ;
5573
5574 if (!VIM_ISDIGIT(*(s - 1)))
5575 {
5576 if (errbuf != NULL)
5577 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005578 sprintf((char *)errbuf,
5579 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005580 transchar_byte(*(s - 1)));
5581 errmsg = errbuf;
5582 }
5583 else
5584 errmsg = (char_u *)"";
5585 break;
5586 }
5587 }
5588 if (*s == ',')
5589 ++s;
5590 else if (*s)
5591 {
5592 if (errbuf != NULL)
5593 errmsg = (char_u *)N_("E527: Missing comma");
5594 else
5595 errmsg = (char_u *)"";
5596 break;
5597 }
5598 }
5599 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5600 errmsg = (char_u *)N_("E528: Must specify a ' value");
5601 }
5602#endif /* FEAT_VIMINFO */
5603
5604 /* terminal options */
5605 else if (istermoption(&options[opt_idx]) && full_screen)
5606 {
5607 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5608 if (varp == &T_CCO)
5609 {
5610 t_colors = atoi((char *)T_CCO);
5611 if (t_colors <= 1)
5612 {
5613 if (new_value_alloced)
5614 vim_free(T_CCO);
5615 T_CCO = empty_option;
5616 }
5617 /* We now have a different color setup, initialize it again. */
5618 init_highlight(TRUE, FALSE);
5619 }
5620 ttest(FALSE);
5621 if (varp == &T_ME)
5622 {
5623 out_str(T_ME);
5624 redraw_later(CLEAR);
5625#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5626 /* Since t_me has been set, this probably means that the user
5627 * wants to use this as default colors. Need to reset default
5628 * background/foreground colors. */
5629 mch_set_normal_colors();
5630#endif
5631 }
5632 }
5633
5634#ifdef FEAT_LINEBREAK
5635 /* 'showbreak' */
5636 else if (varp == &p_sbr)
5637 {
5638 for (s = p_sbr; *s; )
5639 {
5640 if (ptr2cells(s) != 1)
5641 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005642 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643 }
5644 }
5645#endif
5646
5647#ifdef FEAT_GUI
5648 /* 'guifont' */
5649 else if (varp == &p_guifont)
5650 {
5651 if (gui.in_use)
5652 {
5653 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00005654# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655 /*
5656 * Put up a font dialog and let the user select a new value.
5657 * If this is cancelled go back to the old value but don't
5658 * give an error message.
5659 */
5660 if (STRCMP(p, "*") == 0)
5661 {
5662 p = gui_mch_font_dialog(oldval);
5663
5664 if (new_value_alloced)
5665 free_string_option(p_guifont);
5666
5667 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5668 new_value_alloced = TRUE;
5669 }
5670# endif
5671 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5672 {
5673# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5674 if (STRCMP(p_guifont, "*") == 0)
5675 {
5676 /* Dialog was cancelled: Keep the old value without giving
5677 * an error message. */
5678 if (new_value_alloced)
5679 free_string_option(p_guifont);
5680 p_guifont = vim_strsave(oldval);
5681 new_value_alloced = TRUE;
5682 }
5683 else
5684# endif
5685 errmsg = (char_u *)N_("E596: Invalid font(s)");
5686 }
5687 }
5688 }
5689# ifdef FEAT_XFONTSET
5690 else if (varp == &p_guifontset)
5691 {
5692 if (STRCMP(p_guifontset, "*") == 0)
5693 errmsg = (char_u *)N_("E597: can't select fontset");
5694 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5695 errmsg = (char_u *)N_("E598: Invalid fontset");
5696 }
5697# endif
5698# ifdef FEAT_MBYTE
5699 else if (varp == &p_guifontwide)
5700 {
5701 if (STRCMP(p_guifontwide, "*") == 0)
5702 errmsg = (char_u *)N_("E533: can't select wide font");
5703 else if (gui_get_wide_font() == FAIL)
5704 errmsg = (char_u *)N_("E534: Invalid wide font");
5705 }
5706# endif
5707#endif
5708
5709#ifdef CURSOR_SHAPE
5710 /* 'guicursor' */
5711 else if (varp == &p_guicursor)
5712 errmsg = parse_shape_opt(SHAPE_CURSOR);
5713#endif
5714
5715#ifdef FEAT_MOUSESHAPE
5716 /* 'mouseshape' */
5717 else if (varp == &p_mouseshape)
5718 {
5719 errmsg = parse_shape_opt(SHAPE_MOUSE);
5720 update_mouseshape(-1);
5721 }
5722#endif
5723
5724#ifdef FEAT_PRINTER
5725 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005726 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005727# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005728 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005729 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00005730# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731#endif
5732
5733#ifdef FEAT_LANGMAP
5734 /* 'langmap' */
5735 else if (varp == &p_langmap)
5736 langmap_set();
5737#endif
5738
5739#ifdef FEAT_LINEBREAK
5740 /* 'breakat' */
5741 else if (varp == &p_breakat)
5742 fill_breakat_flags();
5743#endif
5744
5745#ifdef FEAT_TITLE
5746 /* 'titlestring' and 'iconstring' */
5747 else if (varp == &p_titlestring || varp == &p_iconstring)
5748 {
5749# ifdef FEAT_STL_OPT
5750 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5751
5752 /* NULL => statusline syntax */
5753 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5754 stl_syntax |= flagval;
5755 else
5756 stl_syntax &= ~flagval;
5757# endif
5758 did_set_title(varp == &p_iconstring);
5759
5760 }
5761#endif
5762
5763#ifdef FEAT_GUI
5764 /* 'guioptions' */
5765 else if (varp == &p_go)
5766 gui_init_which_components(oldval);
5767#endif
5768
5769#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5770 /* 'ttymouse' */
5771 else if (varp == &p_ttym)
5772 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00005773 /* Switch the mouse off before changing the escape sequences used for
5774 * that. */
5775 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5777 errmsg = e_invarg;
5778 else
5779 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00005780 if (termcap_active)
5781 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005782 }
5783#endif
5784
5785#ifdef FEAT_VISUAL
5786 /* 'selection' */
5787 else if (varp == &p_sel)
5788 {
5789 if (*p_sel == NUL
5790 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5791 errmsg = e_invarg;
5792 }
5793
5794 /* 'selectmode' */
5795 else if (varp == &p_slm)
5796 {
5797 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5798 errmsg = e_invarg;
5799 }
5800#endif
5801
5802#ifdef FEAT_BROWSE
5803 /* 'browsedir' */
5804 else if (varp == &p_bsdir)
5805 {
5806 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5807 && !mch_isdir(p_bsdir))
5808 errmsg = e_invarg;
5809 }
5810#endif
5811
5812#ifdef FEAT_VISUAL
5813 /* 'keymodel' */
5814 else if (varp == &p_km)
5815 {
5816 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5817 errmsg = e_invarg;
5818 else
5819 {
5820 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5821 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5822 }
5823 }
5824#endif
5825
5826 /* 'mousemodel' */
5827 else if (varp == &p_mousem)
5828 {
5829 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5830 errmsg = e_invarg;
5831#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5832 else if (*p_mousem != *oldval)
5833 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5834 * to create or delete the popup menus. */
5835 gui_motif_update_mousemodel(root_menu);
5836#endif
5837 }
5838
5839 /* 'switchbuf' */
5840 else if (varp == &p_swb)
5841 {
5842 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5843 errmsg = e_invarg;
5844 }
5845
5846 /* 'debug' */
5847 else if (varp == &p_debug)
5848 {
5849 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5850 errmsg = e_invarg;
5851 }
5852
5853 /* 'display' */
5854 else if (varp == &p_dy)
5855 {
5856 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5857 errmsg = e_invarg;
5858 else
5859 (void)init_chartab();
5860
5861 }
5862
5863#ifdef FEAT_VERTSPLIT
5864 /* 'eadirection' */
5865 else if (varp == &p_ead)
5866 {
5867 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5868 errmsg = e_invarg;
5869 }
5870#endif
5871
5872#ifdef FEAT_CLIPBOARD
5873 /* 'clipboard' */
5874 else if (varp == &p_cb)
5875 errmsg = check_clipboard_option();
5876#endif
5877
Bram Moolenaar217ad922005-03-20 22:37:15 +00005878#ifdef FEAT_SYN_HL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005879 /* When 'spelllang' or 'spellfile' is set and there is a window for this
5880 * buffer in which 'spell' is set load the wordlists. */
5881 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00005882 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005883 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005884 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005885
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005886 if (varp == &(curbuf->b_p_spf))
5887 {
5888 l = STRLEN(curbuf->b_p_spf);
5889 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
5890 ".add") != 0))
5891 errmsg = e_invarg;
5892 }
5893
5894 if (errmsg == NULL)
5895 {
5896 FOR_ALL_WINDOWS(wp)
5897 if (wp->w_buffer == curbuf && wp->w_p_spell)
5898 {
5899 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005900# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005901 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005902# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005903 }
5904 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005905 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005906 /* When 'spellcapcheck' is set compile the regexp program. */
5907 else if (varp == &(curbuf->b_p_spc))
5908 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005909 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005910 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005911 /* 'spellsuggest' */
5912 else if (varp == &p_sps)
5913 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005914 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005915 errmsg = e_invarg;
5916 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005917 /* 'mkspellmem' */
5918 else if (varp == &p_msm)
5919 {
5920 if (spell_check_msm() != OK)
5921 errmsg = e_invarg;
5922 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005923#endif
5924
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925#ifdef FEAT_QUICKFIX
5926 /* When 'bufhidden' is set, check for valid value. */
5927 else if (gvarp == &p_bh)
5928 {
5929 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5930 errmsg = e_invarg;
5931 }
5932
5933 /* When 'buftype' is set, check for valid value. */
5934 else if (gvarp == &p_bt)
5935 {
5936 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5937 errmsg = e_invarg;
5938 else
5939 {
5940# ifdef FEAT_WINDOWS
5941 if (curwin->w_status_height)
5942 {
5943 curwin->w_redr_status = TRUE;
5944 redraw_later(VALID);
5945 }
5946# endif
5947 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5948 }
5949 }
5950#endif
5951
5952#ifdef FEAT_STL_OPT
5953 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005954 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955 {
5956 int wid;
5957
5958 if (varp == &p_ruf) /* reset ru_wid first */
5959 ru_wid = 0;
5960 s = *varp;
5961 if (varp == &p_ruf && *s == '%')
5962 {
5963 /* set ru_wid if 'ruf' starts with "%99(" */
5964 if (*++s == '-') /* ignore a '-' */
5965 s++;
5966 wid = getdigits(&s);
5967 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5968 ru_wid = wid;
5969 else
5970 errmsg = check_stl_option(p_ruf);
5971 }
5972 else
5973 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005974 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975 comp_col();
5976 }
5977#endif
5978
5979#ifdef FEAT_INS_EXPAND
5980 /* check if it is a valid value for 'complete' -- Acevedo */
5981 else if (gvarp == &p_cpt)
5982 {
5983 for (s = *varp; *s;)
5984 {
5985 while(*s == ',' || *s == ' ')
5986 s++;
5987 if (!*s)
5988 break;
5989 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5990 {
5991 errmsg = illegal_char(errbuf, *s);
5992 break;
5993 }
5994 if (*++s != NUL && *s != ',' && *s != ' ')
5995 {
5996 if (s[-1] == 'k' || s[-1] == 's')
5997 {
5998 /* skip optional filename after 'k' and 's' */
5999 while (*s && *s != ',' && *s != ' ')
6000 {
6001 if (*s == '\\')
6002 ++s;
6003 ++s;
6004 }
6005 }
6006 else
6007 {
6008 if (errbuf != NULL)
6009 {
6010 sprintf((char *)errbuf,
6011 _("E535: Illegal character after <%c>"),
6012 *--s);
6013 errmsg = errbuf;
6014 }
6015 else
6016 errmsg = (char_u *)"";
6017 break;
6018 }
6019 }
6020 }
6021 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006022
6023 /* 'completeopt' */
6024 else if (varp == &p_cot)
6025 {
6026 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6027 errmsg = e_invarg;
6028 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006029#endif /* FEAT_INS_EXPAND */
6030
6031
6032#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6033 else if (varp == &p_toolbar)
6034 {
6035 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6036 &toolbar_flags, TRUE) != OK)
6037 errmsg = e_invarg;
6038 else
6039 {
6040 out_flush();
6041 gui_mch_show_toolbar((toolbar_flags &
6042 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6043 }
6044 }
6045#endif
6046
6047#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6048 /* 'toolbariconsize': GTK+ 2 only */
6049 else if (varp == &p_tbis)
6050 {
6051 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6052 errmsg = e_invarg;
6053 else
6054 {
6055 out_flush();
6056 gui_mch_show_toolbar((toolbar_flags &
6057 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6058 }
6059 }
6060#endif
6061
6062 /* 'pastetoggle': translate key codes like in a mapping */
6063 else if (varp == &p_pt)
6064 {
6065 if (*p_pt)
6066 {
6067 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
6068 if (p != NULL)
6069 {
6070 if (new_value_alloced)
6071 free_string_option(p_pt);
6072 p_pt = p;
6073 new_value_alloced = TRUE;
6074 }
6075 }
6076 }
6077
6078 /* 'backspace' */
6079 else if (varp == &p_bs)
6080 {
6081 if (VIM_ISDIGIT(*p_bs))
6082 {
6083 if (*p_bs >'2' || p_bs[1] != NUL)
6084 errmsg = e_invarg;
6085 }
6086 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6087 errmsg = e_invarg;
6088 }
6089
6090 /* 'casemap' */
6091 else if (varp == &p_cmp)
6092 {
6093 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6094 errmsg = e_invarg;
6095 }
6096
6097#ifdef FEAT_DIFF
6098 /* 'diffopt' */
6099 else if (varp == &p_dip)
6100 {
6101 if (diffopt_changed() == FAIL)
6102 errmsg = e_invarg;
6103 }
6104#endif
6105
6106#ifdef FEAT_FOLDING
6107 /* 'foldmethod' */
6108 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6109 {
6110 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6111 || *curwin->w_p_fdm == NUL)
6112 errmsg = e_invarg;
6113 else
6114 foldUpdateAll(curwin);
6115 }
6116# ifdef FEAT_EVAL
6117 /* 'foldexpr' */
6118 else if (varp == &curwin->w_p_fde)
6119 {
6120 if (foldmethodIsExpr(curwin))
6121 foldUpdateAll(curwin);
6122 }
6123# endif
6124 /* 'foldmarker' */
6125 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6126 {
6127 p = vim_strchr(*varp, ',');
6128 if (p == NULL)
6129 errmsg = (char_u *)N_("E536: comma required");
6130 else if (p == *varp || p[1] == NUL)
6131 errmsg = e_invarg;
6132 else if (foldmethodIsMarker(curwin))
6133 foldUpdateAll(curwin);
6134 }
6135 /* 'commentstring' */
6136 else if (gvarp == &p_cms)
6137 {
6138 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6139 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6140 }
6141 /* 'foldopen' */
6142 else if (varp == &p_fdo)
6143 {
6144 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6145 errmsg = e_invarg;
6146 }
6147 /* 'foldclose' */
6148 else if (varp == &p_fcl)
6149 {
6150 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6151 errmsg = e_invarg;
6152 }
6153#endif
6154
6155#ifdef FEAT_VIRTUALEDIT
6156 /* 'virtualedit' */
6157 else if (varp == &p_ve)
6158 {
6159 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6160 errmsg = e_invarg;
6161 else if (STRCMP(p_ve, oldval) != 0)
6162 {
6163 /* Recompute cursor position in case the new 've' setting
6164 * changes something. */
6165 validate_virtcol();
6166 coladvance(curwin->w_virtcol);
6167 }
6168 }
6169#endif
6170
6171#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6172 else if (varp == &p_csqf)
6173 {
6174 if (p_csqf != NULL)
6175 {
6176 p = p_csqf;
6177 while (*p != NUL)
6178 {
6179 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6180 || p[1] == NUL
6181 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6182 || (p[2] != NUL && p[2] != ','))
6183 {
6184 errmsg = e_invarg;
6185 break;
6186 }
6187 else if (p[2] == NUL)
6188 break;
6189 else
6190 p += 3;
6191 }
6192 }
6193 }
6194#endif
6195
6196 /* Options that are a list of flags. */
6197 else
6198 {
6199 p = NULL;
6200 if (varp == &p_ww)
6201 p = (char_u *)WW_ALL;
6202 if (varp == &p_shm)
6203 p = (char_u *)SHM_ALL;
6204 else if (varp == &(p_cpo))
6205 p = (char_u *)CPO_ALL;
6206 else if (varp == &(curbuf->b_p_fo))
6207 p = (char_u *)FO_ALL;
6208 else if (varp == &p_mouse)
6209 {
6210#ifdef FEAT_MOUSE
6211 p = (char_u *)MOUSE_ALL;
6212#else
6213 if (*p_mouse != NUL)
6214 errmsg = (char_u *)N_("E538: No mouse support");
6215#endif
6216 }
6217#if defined(FEAT_GUI)
6218 else if (varp == &p_go)
6219 p = (char_u *)GO_ALL;
6220#endif
6221 if (p != NULL)
6222 {
6223 for (s = *varp; *s; ++s)
6224 if (vim_strchr(p, *s) == NULL)
6225 {
6226 errmsg = illegal_char(errbuf, *s);
6227 break;
6228 }
6229 }
6230 }
6231
6232 /*
6233 * If error detected, restore the previous value.
6234 */
6235 if (errmsg != NULL)
6236 {
6237 if (new_value_alloced)
6238 free_string_option(*varp);
6239 *varp = oldval;
6240 /*
6241 * When resetting some values, need to act on it.
6242 */
6243 if (did_chartab)
6244 (void)init_chartab();
6245 if (varp == &p_hl)
6246 (void)highlight_changed();
6247 }
6248 else
6249 {
6250#ifdef FEAT_EVAL
6251 /* Remember where the option was set. */
6252 options[opt_idx].scriptID = current_SID;
6253#endif
6254 /*
6255 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006256 * Use "free_oldval", because recursiveness may change the flags under
6257 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006259 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006260 free_string_option(oldval);
6261 if (new_value_alloced)
6262 options[opt_idx].flags |= P_ALLOCED;
6263 else
6264 options[opt_idx].flags &= ~P_ALLOCED;
6265
6266 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6267 && (int)options[opt_idx].indir >= PV_BOTH)
6268 {
6269 /* global option with local value set to use global value; free
6270 * the local value and make it empty */
6271 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6272 free_string_option(*(char_u **)p);
6273 *(char_u **)p = empty_option;
6274 }
6275
6276 /* May set global value for local option. */
6277 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6278 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006279
6280#ifdef FEAT_AUTOCMD
6281 /*
6282 * Trigger the autocommand only after setting the flags.
6283 */
6284# ifdef FEAT_SYN_HL
6285 /* When 'syntax' is set, load the syntax of that name */
6286 if (varp == &(curbuf->b_p_syn))
6287 {
6288 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6289 curbuf->b_fname, TRUE, curbuf);
6290 }
6291# endif
6292 else if (varp == &(curbuf->b_p_ft))
6293 {
6294 /* 'filetype' is set, trigger the FileType autocommand */
6295 did_filetype = TRUE;
6296 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6297 curbuf->b_fname, TRUE, curbuf);
6298 }
6299#endif
6300#ifdef FEAT_SYN_HL
6301 if (varp == &(curbuf->b_p_spl))
6302 {
6303 char_u fname[200];
6304
6305 /*
6306 * Source the spell/LANG.vim in 'runtimepath'.
6307 * They could set 'spellcapcheck' depending on the language.
6308 * Use the first name in 'spelllang' up to '_region' or
6309 * '.encoding'.
6310 */
6311 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6312 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6313 break;
6314 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6315 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6316 source_runtime(fname, TRUE);
6317 }
6318#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319 }
6320
6321#ifdef FEAT_MOUSE
6322 if (varp == &p_mouse)
6323 {
6324# ifdef FEAT_MOUSE_TTY
6325 if (*p_mouse == NUL)
6326 mch_setmouse(FALSE); /* switch mouse off */
6327 else
6328# endif
6329 setmouse(); /* in case 'mouse' changed */
6330 }
6331#endif
6332
6333 if (curwin->w_curswant != MAXCOL)
6334 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6335 check_redraw(options[opt_idx].flags);
6336
6337 return errmsg;
6338}
6339
6340/*
6341 * Handle setting 'listchars' or 'fillchars'.
6342 * Returns error message, NULL if it's OK.
6343 */
6344 static char_u *
6345set_chars_option(varp)
6346 char_u **varp;
6347{
6348 int round, i, len, entries;
6349 char_u *p, *s;
6350 int c1, c2 = 0;
6351 struct charstab
6352 {
6353 int *cp;
6354 char *name;
6355 };
6356#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6357 static struct charstab filltab[] =
6358 {
6359 {&fill_stl, "stl"},
6360 {&fill_stlnc, "stlnc"},
6361 {&fill_vert, "vert"},
6362 {&fill_fold, "fold"},
6363 {&fill_diff, "diff"},
6364 };
6365#endif
6366 static struct charstab lcstab[] =
6367 {
6368 {&lcs_eol, "eol"},
6369 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006370 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371 {&lcs_prec, "precedes"},
6372 {&lcs_tab2, "tab"},
6373 {&lcs_trail, "trail"},
6374 };
6375 struct charstab *tab;
6376
6377#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6378 if (varp == &p_lcs)
6379#endif
6380 {
6381 tab = lcstab;
6382 entries = sizeof(lcstab) / sizeof(struct charstab);
6383 }
6384#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6385 else
6386 {
6387 tab = filltab;
6388 entries = sizeof(filltab) / sizeof(struct charstab);
6389 }
6390#endif
6391
6392 /* first round: check for valid value, second round: assign values */
6393 for (round = 0; round <= 1; ++round)
6394 {
6395 if (round)
6396 {
6397 /* After checking that the value is valid: set defaults: space for
6398 * 'fillchars', NUL for 'listchars' */
6399 for (i = 0; i < entries; ++i)
6400 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6401 if (varp == &p_lcs)
6402 lcs_tab1 = NUL;
6403#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6404 else
6405 fill_diff = '-';
6406#endif
6407 }
6408 p = *varp;
6409 while (*p)
6410 {
6411 for (i = 0; i < entries; ++i)
6412 {
6413 len = (int)STRLEN(tab[i].name);
6414 if (STRNCMP(p, tab[i].name, len) == 0
6415 && p[len] == ':'
6416 && p[len + 1] != NUL)
6417 {
6418 s = p + len + 1;
6419#ifdef FEAT_MBYTE
6420 c1 = mb_ptr2char_adv(&s);
6421#else
6422 c1 = *s++;
6423#endif
6424 if (tab[i].cp == &lcs_tab2)
6425 {
6426 if (*s == NUL)
6427 continue;
6428#ifdef FEAT_MBYTE
6429 c2 = mb_ptr2char_adv(&s);
6430#else
6431 c2 = *s++;
6432#endif
6433 }
6434 if (*s == ',' || *s == NUL)
6435 {
6436 if (round)
6437 {
6438 if (tab[i].cp == &lcs_tab2)
6439 {
6440 lcs_tab1 = c1;
6441 lcs_tab2 = c2;
6442 }
6443 else
6444 *(tab[i].cp) = c1;
6445
6446 }
6447 p = s;
6448 break;
6449 }
6450 }
6451 }
6452
6453 if (i == entries)
6454 return e_invarg;
6455 if (*p == ',')
6456 ++p;
6457 }
6458 }
6459
6460 return NULL; /* no error */
6461}
6462
6463#ifdef FEAT_STL_OPT
6464/*
6465 * Check validity of options with the 'statusline' format.
6466 * Return error message or NULL.
6467 */
6468 char_u *
6469check_stl_option(s)
6470 char_u *s;
6471{
6472 int itemcnt = 0;
6473 int groupdepth = 0;
6474 static char_u errbuf[80];
6475
6476 while (*s && itemcnt < STL_MAX_ITEM)
6477 {
6478 /* Check for valid keys after % sequences */
6479 while (*s && *s != '%')
6480 s++;
6481 if (!*s)
6482 break;
6483 s++;
6484 if (*s != '%' && *s != ')')
6485 ++itemcnt;
6486 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6487 {
6488 s++;
6489 continue;
6490 }
6491 if (*s == ')')
6492 {
6493 s++;
6494 if (--groupdepth < 0)
6495 break;
6496 continue;
6497 }
6498 if (*s == '-')
6499 s++;
6500 while (VIM_ISDIGIT(*s))
6501 s++;
6502 if (*s == STL_HIGHLIGHT)
6503 continue;
6504 if (*s == '.')
6505 {
6506 s++;
6507 while (*s && VIM_ISDIGIT(*s))
6508 s++;
6509 }
6510 if (*s == '(')
6511 {
6512 groupdepth++;
6513 continue;
6514 }
6515 if (vim_strchr(STL_ALL, *s) == NULL)
6516 {
6517 return illegal_char(errbuf, *s);
6518 }
6519 if (*s == '{')
6520 {
6521 s++;
6522 while (*s != '}' && *s)
6523 s++;
6524 if (*s != '}')
6525 return (char_u *)N_("E540: Unclosed expression sequence");
6526 }
6527 }
6528 if (itemcnt >= STL_MAX_ITEM)
6529 return (char_u *)N_("E541: too many items");
6530 if (groupdepth != 0)
6531 return (char_u *)N_("E542: unbalanced groups");
6532 return NULL;
6533}
6534#endif
6535
6536#ifdef FEAT_CLIPBOARD
6537/*
6538 * Extract the items in the 'clipboard' option and set global values.
6539 */
6540 static char_u *
6541check_clipboard_option()
6542{
6543 int new_unnamed = FALSE;
6544 int new_autoselect = FALSE;
6545 int new_autoselectml = FALSE;
6546 regprog_T *new_exclude_prog = NULL;
6547 char_u *errmsg = NULL;
6548 char_u *p;
6549
6550 for (p = p_cb; *p != NUL; )
6551 {
6552 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6553 {
6554 new_unnamed = TRUE;
6555 p += 7;
6556 }
6557 else if (STRNCMP(p, "autoselect", 10) == 0
6558 && (p[10] == ',' || p[10] == NUL))
6559 {
6560 new_autoselect = TRUE;
6561 p += 10;
6562 }
6563 else if (STRNCMP(p, "autoselectml", 12) == 0
6564 && (p[12] == ',' || p[12] == NUL))
6565 {
6566 new_autoselectml = TRUE;
6567 p += 12;
6568 }
6569 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6570 {
6571 p += 8;
6572 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6573 if (new_exclude_prog == NULL)
6574 errmsg = e_invarg;
6575 break;
6576 }
6577 else
6578 {
6579 errmsg = e_invarg;
6580 break;
6581 }
6582 if (*p == ',')
6583 ++p;
6584 }
6585 if (errmsg == NULL)
6586 {
6587 clip_unnamed = new_unnamed;
6588 clip_autoselect = new_autoselect;
6589 clip_autoselectml = new_autoselectml;
6590 vim_free(clip_exclude_prog);
6591 clip_exclude_prog = new_exclude_prog;
6592 }
6593 else
6594 vim_free(new_exclude_prog);
6595
6596 return errmsg;
6597}
6598#endif
6599
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006600#ifdef FEAT_SYN_HL
6601/*
6602 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6603 * Return error message when failed, NULL when OK.
6604 */
6605 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006606compile_cap_prog(buf)
6607 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006608{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006609 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006610 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006611
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006612 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006613 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006614 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006615 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006616 /* Prepend a ^ so that we only match at one column */
6617 re = concat_str((char_u *)"^", buf->b_p_spc);
6618 if (re != NULL)
6619 {
6620 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
6621 if (buf->b_cap_prog == NULL)
6622 {
6623 buf->b_cap_prog = rp; /* restore the previous program */
6624 return e_invarg;
6625 }
6626 vim_free(re);
6627 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006628 }
6629
6630 vim_free(rp);
6631 return NULL;
6632}
6633#endif
6634
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635/*
6636 * Set the value of a boolean option, and take care of side effects.
6637 * Returns NULL for success, or an error message for an error.
6638 */
6639 static char_u *
6640set_bool_option(opt_idx, varp, value, opt_flags)
6641 int opt_idx; /* index in options[] table */
6642 char_u *varp; /* pointer to the option variable */
6643 int value; /* new value */
6644 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6645{
6646 int old_value = *(int *)varp;
6647
Bram Moolenaar071d4272004-06-13 20:20:40 +00006648 /* Disallow changing some options from secure mode */
6649 if ((secure
6650#ifdef HAVE_SANDBOX
6651 || sandbox != 0
6652#endif
6653 ) && (options[opt_idx].flags & P_SECURE))
6654 return e_secure;
6655
6656 *(int *)varp = value; /* set the new value */
6657#ifdef FEAT_EVAL
6658 /* Remember where the option was set. */
6659 options[opt_idx].scriptID = current_SID;
6660#endif
6661
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006662#ifdef FEAT_GUI
6663 need_mouse_correct = TRUE;
6664#endif
6665
Bram Moolenaar071d4272004-06-13 20:20:40 +00006666 /* May set global value for local option. */
6667 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6668 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6669
6670 /*
6671 * Handle side effects of changing a bool option.
6672 */
6673
6674 /* 'compatible' */
6675 if ((int *)varp == &p_cp)
6676 {
6677 compatible_set();
6678 }
6679
Bram Moolenaar071d4272004-06-13 20:20:40 +00006680 else if ((int *)varp == &curbuf->b_p_ro)
6681 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006682 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006683 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6684 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006685
6686 /* when 'readonly' is set may give W10 again */
6687 if (curbuf->b_p_ro)
6688 curbuf->b_did_warn = FALSE;
6689
Bram Moolenaar071d4272004-06-13 20:20:40 +00006690#ifdef FEAT_TITLE
6691 need_maketitle = TRUE;
6692#endif
6693 }
6694
6695#ifdef FEAT_TITLE
6696 /* when 'modifiable' is changed, redraw the window title */
6697 else if ((int *)varp == &curbuf->b_p_ma)
6698 need_maketitle = TRUE;
6699 /* when 'endofline' is changed, redraw the window title */
6700 else if ((int *)varp == &curbuf->b_p_eol)
6701 need_maketitle = TRUE;
6702#endif
6703
6704 /* when 'bin' is set also set some other options */
6705 else if ((int *)varp == &curbuf->b_p_bin)
6706 {
6707 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6708#ifdef FEAT_TITLE
6709 need_maketitle = TRUE;
6710#endif
6711 }
6712
6713#ifdef FEAT_AUTOCMD
6714 /* when 'buflisted' changes, trigger autocommands */
6715 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6716 {
6717 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6718 NULL, NULL, TRUE, curbuf);
6719 }
6720#endif
6721
6722 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6723 else if ((int *)varp == &curbuf->b_p_swf)
6724 {
6725 if (curbuf->b_p_swf && p_uc)
6726 ml_open_file(curbuf); /* create the swap file */
6727 else
6728 mf_close_file(curbuf, TRUE); /* remove the swap file */
6729 }
6730
6731 /* when 'terse' is set change 'shortmess' */
6732 else if ((int *)varp == &p_terse)
6733 {
6734 char_u *p;
6735
6736 p = vim_strchr(p_shm, SHM_SEARCH);
6737
6738 /* insert 's' in p_shm */
6739 if (p_terse && p == NULL)
6740 {
6741 STRCPY(IObuff, p_shm);
6742 STRCAT(IObuff, "s");
6743 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6744 }
6745 /* remove 's' from p_shm */
6746 else if (!p_terse && p != NULL)
6747 mch_memmove(p, p + 1, STRLEN(p));
6748 }
6749
6750 /* when 'paste' is set or reset also change other options */
6751 else if ((int *)varp == &p_paste)
6752 {
6753 paste_option_changed();
6754 }
6755
6756 /* when 'insertmode' is set from an autocommand need to do work here */
6757 else if ((int *)varp == &p_im)
6758 {
6759 if (p_im)
6760 {
6761 if ((State & INSERT) == 0)
6762 need_start_insertmode = TRUE;
6763 stop_insert_mode = FALSE;
6764 }
6765 else
6766 {
6767 need_start_insertmode = FALSE;
6768 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00006769 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770 clear_cmdline = TRUE; /* remove "(insert)" */
6771 restart_edit = 0;
6772 }
6773 }
6774
6775 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6776 else if ((int *)varp == &p_ic && p_hls)
6777 {
6778 redraw_all_later(NOT_VALID);
6779 }
6780
6781#ifdef FEAT_SEARCH_EXTRA
6782 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6783 else if ((int *)varp == &p_hls)
6784 {
6785 no_hlsearch = FALSE;
6786 }
6787#endif
6788
6789#ifdef FEAT_SCROLLBIND
6790 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6791 * at the end of normal_cmd() */
6792 else if ((int *)varp == &curwin->w_p_scb)
6793 {
6794 if (curwin->w_p_scb)
6795 do_check_scrollbind(FALSE);
6796 }
6797#endif
6798
6799#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6800 /* There can be only one window with 'previewwindow' set. */
6801 else if ((int *)varp == &curwin->w_p_pvw)
6802 {
6803 if (curwin->w_p_pvw)
6804 {
6805 win_T *win;
6806
6807 for (win = firstwin; win != NULL; win = win->w_next)
6808 if (win->w_p_pvw && win != curwin)
6809 {
6810 curwin->w_p_pvw = FALSE;
6811 return (char_u *)N_("E590: A preview window already exists");
6812 }
6813 }
6814 }
6815#endif
6816
6817 /* when 'textmode' is set or reset also change 'fileformat' */
6818 else if ((int *)varp == &curbuf->b_p_tx)
6819 {
6820 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6821 }
6822
6823 /* when 'textauto' is set or reset also change 'fileformats' */
6824 else if ((int *)varp == &p_ta)
6825 {
6826 set_string_option_direct((char_u *)"ffs", -1,
6827 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6828 OPT_FREE | opt_flags);
6829 }
6830
6831 /*
6832 * When 'lisp' option changes include/exclude '-' in
6833 * keyword characters.
6834 */
6835#ifdef FEAT_LISP
6836 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6837 {
6838 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6839 }
6840#endif
6841
6842#ifdef FEAT_TITLE
6843 /* when 'title' changed, may need to change the title; same for 'icon' */
6844 else if ((int *)varp == &p_title)
6845 {
6846 did_set_title(FALSE);
6847 }
6848
6849 else if ((int *)varp == &p_icon)
6850 {
6851 did_set_title(TRUE);
6852 }
6853#endif
6854
6855 else if ((int *)varp == &curbuf->b_changed)
6856 {
6857 if (!value)
6858 save_file_ff(curbuf); /* Buffer is unchanged */
6859#ifdef FEAT_TITLE
6860 need_maketitle = TRUE;
6861#endif
6862#ifdef FEAT_AUTOCMD
6863 modified_was_set = value;
6864#endif
6865 }
6866
6867#ifdef BACKSLASH_IN_FILENAME
6868 else if ((int *)varp == &p_ssl)
6869 {
6870 if (p_ssl)
6871 {
6872 psepc = '/';
6873 psepcN = '\\';
6874 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875 }
6876 else
6877 {
6878 psepc = '\\';
6879 psepcN = '/';
6880 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881 }
6882
6883 /* need to adjust the file name arguments and buffer names. */
6884 buflist_slash_adjust();
6885 alist_slash_adjust();
6886# ifdef FEAT_EVAL
6887 scriptnames_slash_adjust();
6888# endif
6889 }
6890#endif
6891
6892 /* If 'wrap' is set, set w_leftcol to zero. */
6893 else if ((int *)varp == &curwin->w_p_wrap)
6894 {
6895 if (curwin->w_p_wrap)
6896 curwin->w_leftcol = 0;
6897 }
6898
6899#ifdef FEAT_WINDOWS
6900 else if ((int *)varp == &p_ea)
6901 {
6902 if (p_ea && !old_value)
6903 win_equal(curwin, FALSE, 0);
6904 }
6905#endif
6906
6907 else if ((int *)varp == &p_wiv)
6908 {
6909 /*
6910 * When 'weirdinvert' changed, set/reset 't_xs'.
6911 * Then set 'weirdinvert' according to value of 't_xs'.
6912 */
6913 if (p_wiv && !old_value)
6914 T_XS = (char_u *)"y";
6915 else if (!p_wiv && old_value)
6916 T_XS = empty_option;
6917 p_wiv = (*T_XS != NUL);
6918 }
6919
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006920#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00006921 else if ((int *)varp == &p_beval)
6922 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923 if (p_beval == TRUE)
6924 gui_mch_enable_beval_area(balloonEval);
6925 else
6926 gui_mch_disable_beval_area(balloonEval);
6927 }
6928
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006929# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006930 else if ((int *)varp == &p_acd)
6931 {
6932 if (p_acd && curbuf->b_ffname != NULL
6933 && vim_chdirfile(curbuf->b_ffname) == OK)
6934 shorten_fnames(TRUE);
6935 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937#endif
6938
6939#ifdef FEAT_DIFF
6940 /* 'diff' */
6941 else if ((int *)varp == &curwin->w_p_diff)
6942 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006943 /* May add or remove the buffer from the list of diff buffers. */
6944 diff_buf_adjust(curwin);
6945# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 if (foldmethodIsDiff(curwin))
6947 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006948# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006949 }
6950#endif
6951
6952#ifdef USE_IM_CONTROL
6953 /* 'imdisable' */
6954 else if ((int *)varp == &p_imdisable)
6955 {
6956 /* Only de-activate it here, it will be enabled when changing mode. */
6957 if (p_imdisable)
6958 im_set_active(FALSE);
6959 }
6960#endif
6961
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006962#ifdef FEAT_SYN_HL
6963 /* 'spell' */
6964 else if ((int *)varp == &curwin->w_p_spell)
6965 {
6966 if (curwin->w_p_spell)
6967 {
6968 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00006969
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006970 if (errmsg != NULL)
6971 EMSG(_(errmsg));
6972 }
6973 }
6974#endif
6975
Bram Moolenaar071d4272004-06-13 20:20:40 +00006976#ifdef FEAT_FKMAP
6977 else if ((int *)varp == &p_altkeymap)
6978 {
6979 if (old_value != p_altkeymap)
6980 {
6981 if (!p_altkeymap)
6982 {
6983 p_hkmap = p_fkmap;
6984 p_fkmap = 0;
6985 }
6986 else
6987 {
6988 p_fkmap = p_hkmap;
6989 p_hkmap = 0;
6990 }
6991 (void)init_chartab();
6992 }
6993 }
6994
6995 /*
6996 * In case some second language keymapping options have changed, check
6997 * and correct the setting in a consistent way.
6998 */
6999
7000 /*
7001 * If hkmap or fkmap are set, reset Arabic keymapping.
7002 */
7003 if ((p_hkmap || p_fkmap) && p_altkeymap)
7004 {
7005 p_altkeymap = p_fkmap;
7006# ifdef FEAT_ARABIC
7007 curwin->w_p_arab = FALSE;
7008# endif
7009 (void)init_chartab();
7010 }
7011
7012 /*
7013 * If hkmap set, reset Farsi keymapping.
7014 */
7015 if (p_hkmap && p_altkeymap)
7016 {
7017 p_altkeymap = 0;
7018 p_fkmap = 0;
7019# ifdef FEAT_ARABIC
7020 curwin->w_p_arab = FALSE;
7021# endif
7022 (void)init_chartab();
7023 }
7024
7025 /*
7026 * If fkmap set, reset Hebrew keymapping.
7027 */
7028 if (p_fkmap && !p_altkeymap)
7029 {
7030 p_altkeymap = 1;
7031 p_hkmap = 0;
7032# ifdef FEAT_ARABIC
7033 curwin->w_p_arab = FALSE;
7034# endif
7035 (void)init_chartab();
7036 }
7037#endif
7038
7039#ifdef FEAT_ARABIC
7040 if ((int *)varp == &curwin->w_p_arab)
7041 {
7042 if (curwin->w_p_arab)
7043 {
7044 /*
7045 * 'arabic' is set, handle various sub-settings.
7046 */
7047 if (!p_tbidi)
7048 {
7049 /* set rightleft mode */
7050 if (!curwin->w_p_rl)
7051 {
7052 curwin->w_p_rl = TRUE;
7053 changed_window_setting();
7054 }
7055
7056 /* Enable Arabic shaping (major part of what Arabic requires) */
7057 if (!p_arshape)
7058 {
7059 p_arshape = TRUE;
7060 redraw_later_clear();
7061 }
7062 }
7063
7064 /* Arabic requires a utf-8 encoding, inform the user if its not
7065 * set. */
7066 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007067 {
7068 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
7070 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007071 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007072
7073# ifdef FEAT_MBYTE
7074 /* set 'delcombine' */
7075 p_deco = TRUE;
7076# endif
7077
7078# ifdef FEAT_KEYMAP
7079 /* Force-set the necessary keymap for arabic */
7080 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7081 OPT_LOCAL);
7082# endif
7083# ifdef FEAT_FKMAP
7084 p_altkeymap = 0;
7085 p_hkmap = 0;
7086 p_fkmap = 0;
7087 (void)init_chartab();
7088# endif
7089 }
7090 else
7091 {
7092 /*
7093 * 'arabic' is reset, handle various sub-settings.
7094 */
7095 if (!p_tbidi)
7096 {
7097 /* reset rightleft mode */
7098 if (curwin->w_p_rl)
7099 {
7100 curwin->w_p_rl = FALSE;
7101 changed_window_setting();
7102 }
7103
7104 /* 'arabicshape' isn't reset, it is a global option and
7105 * another window may still need it "on". */
7106 }
7107
7108 /* 'delcombine' isn't reset, it is a global option and another
7109 * window may still want it "on". */
7110
7111# ifdef FEAT_KEYMAP
7112 /* Revert to the default keymap */
7113 curbuf->b_p_iminsert = B_IMODE_NONE;
7114 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7115# endif
7116 }
7117 }
7118#endif
7119
7120 /*
7121 * End of handling side effects for bool options.
7122 */
7123
7124 options[opt_idx].flags |= P_WAS_SET;
7125
7126 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7127 if (curwin->w_curswant != MAXCOL)
7128 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7129 check_redraw(options[opt_idx].flags);
7130
7131 return NULL;
7132}
7133
7134/*
7135 * Set the value of a number option, and take care of side effects.
7136 * Returns NULL for success, or an error message for an error.
7137 */
7138 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007139set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007140 int opt_idx; /* index in options[] table */
7141 char_u *varp; /* pointer to the option variable */
7142 long value; /* new value */
7143 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007144 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007145 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7146 OPT_MODELINE */
7147{
7148 char_u *errmsg = NULL;
7149 long old_value = *(long *)varp;
7150 long old_Rows = Rows; /* remember old Rows */
7151 long old_Columns = Columns; /* remember old Columns */
7152 long *pp = (long *)varp;
7153
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007154 /* Disallow changing some options from secure mode. */
7155 if ((secure
7156#ifdef HAVE_SANDBOX
7157 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007159 ) && (options[opt_idx].flags & P_SECURE))
7160 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007161
7162 *pp = value;
7163#ifdef FEAT_EVAL
7164 /* Remember where the option was set. */
7165 options[opt_idx].scriptID = current_SID;
7166#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007167#ifdef FEAT_GUI
7168 need_mouse_correct = TRUE;
7169#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007170
7171 if (curbuf->b_p_sw <= 0)
7172 {
7173 errmsg = e_positive;
7174 curbuf->b_p_sw = curbuf->b_p_ts;
7175 }
7176
7177 /*
7178 * Number options that need some action when changed
7179 */
7180#ifdef FEAT_WINDOWS
7181 if (pp == &p_wh || pp == &p_hh)
7182 {
7183 if (p_wh < 1)
7184 {
7185 errmsg = e_positive;
7186 p_wh = 1;
7187 }
7188 if (p_wmh > p_wh)
7189 {
7190 errmsg = e_winheight;
7191 p_wh = p_wmh;
7192 }
7193 if (p_hh < 0)
7194 {
7195 errmsg = e_positive;
7196 p_hh = 0;
7197 }
7198
7199 /* Change window height NOW */
7200 if (lastwin != firstwin)
7201 {
7202 if (pp == &p_wh && curwin->w_height < p_wh)
7203 win_setheight((int)p_wh);
7204 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7205 win_setheight((int)p_hh);
7206 }
7207 }
7208
7209 /* 'winminheight' */
7210 else if (pp == &p_wmh)
7211 {
7212 if (p_wmh < 0)
7213 {
7214 errmsg = e_positive;
7215 p_wmh = 0;
7216 }
7217 if (p_wmh > p_wh)
7218 {
7219 errmsg = e_winheight;
7220 p_wmh = p_wh;
7221 }
7222 win_setminheight();
7223 }
7224
7225# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007226 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227 {
7228 if (p_wiw < 1)
7229 {
7230 errmsg = e_positive;
7231 p_wiw = 1;
7232 }
7233 if (p_wmw > p_wiw)
7234 {
7235 errmsg = e_winwidth;
7236 p_wiw = p_wmw;
7237 }
7238
7239 /* Change window width NOW */
7240 if (lastwin != firstwin && curwin->w_width < p_wiw)
7241 win_setwidth((int)p_wiw);
7242 }
7243
7244 /* 'winminwidth' */
7245 else if (pp == &p_wmw)
7246 {
7247 if (p_wmw < 0)
7248 {
7249 errmsg = e_positive;
7250 p_wmw = 0;
7251 }
7252 if (p_wmw > p_wiw)
7253 {
7254 errmsg = e_winwidth;
7255 p_wmw = p_wiw;
7256 }
7257 win_setminheight();
7258 }
7259# endif
7260
7261#endif
7262
7263#ifdef FEAT_WINDOWS
7264 /* (re)set last window status line */
7265 else if (pp == &p_ls)
7266 {
7267 last_status(FALSE);
7268 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007269
7270 /* (re)set tab page line */
7271 else if (pp == &p_tal)
7272 {
7273 shell_new_rows(); /* recompute window positions and heights */
7274 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275#endif
7276
7277#ifdef FEAT_GUI
7278 else if (pp == &p_linespace)
7279 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007280 /* Recompute gui.char_height and resize the Vim window to keep the
7281 * same number of lines. */
7282 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007283 gui_set_shellsize(FALSE, FALSE);
7284 }
7285#endif
7286
7287#ifdef FEAT_FOLDING
7288 /* 'foldlevel' */
7289 else if (pp == &curwin->w_p_fdl)
7290 {
7291 if (curwin->w_p_fdl < 0)
7292 curwin->w_p_fdl = 0;
7293 newFoldLevel();
7294 }
7295
7296 /* 'foldminlevel' */
7297 else if (pp == &curwin->w_p_fml)
7298 {
7299 foldUpdateAll(curwin);
7300 }
7301
7302 /* 'foldnestmax' */
7303 else if (pp == &curwin->w_p_fdn)
7304 {
7305 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7306 foldUpdateAll(curwin);
7307 }
7308
7309 /* 'foldcolumn' */
7310 else if (pp == &curwin->w_p_fdc)
7311 {
7312 if (curwin->w_p_fdc < 0)
7313 {
7314 errmsg = e_positive;
7315 curwin->w_p_fdc = 0;
7316 }
7317 else if (curwin->w_p_fdc > 12)
7318 {
7319 errmsg = e_invarg;
7320 curwin->w_p_fdc = 12;
7321 }
7322 }
7323
7324 /* 'shiftwidth' or 'tabstop' */
7325 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7326 {
7327 if (foldmethodIsIndent(curwin))
7328 foldUpdateAll(curwin);
7329 }
7330#endif /* FEAT_FOLDING */
7331
7332 else if (pp == &curbuf->b_p_iminsert)
7333 {
7334 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7335 {
7336 errmsg = e_invarg;
7337 curbuf->b_p_iminsert = B_IMODE_NONE;
7338 }
7339 p_iminsert = curbuf->b_p_iminsert;
7340 if (termcap_active) /* don't do this in the alternate screen */
7341 showmode();
7342#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7343 /* Show/unshow value of 'keymap' in status lines. */
7344 status_redraw_curbuf();
7345#endif
7346 }
7347
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007348 else if (pp == &p_window)
7349 {
7350 if (p_window < 1)
7351 p_window = 1;
7352 else if (p_window >= Rows)
7353 p_window = Rows - 1;
7354 }
7355
Bram Moolenaar071d4272004-06-13 20:20:40 +00007356 else if (pp == &curbuf->b_p_imsearch)
7357 {
7358 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7359 {
7360 errmsg = e_invarg;
7361 curbuf->b_p_imsearch = B_IMODE_NONE;
7362 }
7363 p_imsearch = curbuf->b_p_imsearch;
7364 }
7365
7366#ifdef FEAT_TITLE
7367 /* if 'titlelen' has changed, redraw the title */
7368 else if (pp == &p_titlelen)
7369 {
7370 if (p_titlelen < 0)
7371 {
7372 errmsg = e_positive;
7373 p_titlelen = 85;
7374 }
7375 if (starting != NO_SCREEN && old_value != p_titlelen)
7376 need_maketitle = TRUE;
7377 }
7378#endif
7379
7380 /* if p_ch changed value, change the command line height */
7381 else if (pp == &p_ch)
7382 {
7383 if (p_ch < 1)
7384 {
7385 errmsg = e_positive;
7386 p_ch = 1;
7387 }
7388
7389 /* Only compute the new window layout when startup has been
7390 * completed. Otherwise the frame sizes may be wrong. */
7391 if (p_ch != old_value && full_screen
7392#ifdef FEAT_GUI
7393 && !gui.starting
7394#endif
7395 )
7396 command_height(old_value);
7397 }
7398
7399 /* when 'updatecount' changes from zero to non-zero, open swap files */
7400 else if (pp == &p_uc)
7401 {
7402 if (p_uc < 0)
7403 {
7404 errmsg = e_positive;
7405 p_uc = 100;
7406 }
7407 if (p_uc && !old_value)
7408 ml_open_files();
7409 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007410#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007411 else if (pp == &p_mzq)
7412 mzvim_reset_timer();
7413#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007414
7415 /* sync undo before 'undolevels' changes */
7416 else if (pp == &p_ul)
7417 {
7418 /* use the old value, otherwise u_sync() may not work properly */
7419 p_ul = old_value;
7420 u_sync();
7421 p_ul = value;
7422 }
7423
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007424#ifdef FEAT_LINEBREAK
7425 /* 'numberwidth' must be positive */
7426 else if (pp == &curwin->w_p_nuw)
7427 {
7428 if (curwin->w_p_nuw < 1)
7429 {
7430 errmsg = e_positive;
7431 curwin->w_p_nuw = 1;
7432 }
7433 if (curwin->w_p_nuw > 10)
7434 {
7435 errmsg = e_invarg;
7436 curwin->w_p_nuw = 10;
7437 }
7438 curwin->w_nrwidth_line_count = 0;
7439 }
7440#endif
7441
Bram Moolenaar071d4272004-06-13 20:20:40 +00007442 /*
7443 * Check the bounds for numeric options here
7444 */
7445 if (Rows < min_rows() && full_screen)
7446 {
7447 if (errbuf != NULL)
7448 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007449 vim_snprintf((char *)errbuf, errbuflen,
7450 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007451 errmsg = errbuf;
7452 }
7453 Rows = min_rows();
7454 }
7455 if (Columns < MIN_COLUMNS && full_screen)
7456 {
7457 if (errbuf != NULL)
7458 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007459 vim_snprintf((char *)errbuf, errbuflen,
7460 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007461 errmsg = errbuf;
7462 }
7463 Columns = MIN_COLUMNS;
7464 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007465 /* Limit the values to avoid an overflow in Rows * Columns. */
7466 if (Columns > 10000)
7467 Columns = 10000;
7468 if (Rows > 1000)
7469 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007470
7471#ifdef DJGPP
7472 /* avoid a crash by checking for a too large value of 'columns' */
7473 if (old_Columns != Columns && full_screen && term_console)
7474 mch_check_columns();
7475#endif
7476
7477 /*
7478 * If the screen (shell) height has been changed, assume it is the
7479 * physical screenheight.
7480 */
7481 if (old_Rows != Rows || old_Columns != Columns)
7482 {
7483 /* Changing the screen size is not allowed while updating the screen. */
7484 if (updating_screen)
7485 *pp = old_value;
7486 else if (full_screen
7487#ifdef FEAT_GUI
7488 && !gui.starting
7489#endif
7490 )
7491 set_shellsize((int)Columns, (int)Rows, TRUE);
7492 else
7493 {
7494 /* Postpone the resizing; check the size and cmdline position for
7495 * messages. */
7496 check_shellsize();
7497 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7498 cmdline_row = Rows - p_ch;
7499 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007500 if (p_window >= Rows)
7501 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502 }
7503
7504 if (curbuf->b_p_sts < 0)
7505 {
7506 errmsg = e_positive;
7507 curbuf->b_p_sts = 0;
7508 }
7509 if (curbuf->b_p_ts <= 0)
7510 {
7511 errmsg = e_positive;
7512 curbuf->b_p_ts = 8;
7513 }
7514 if (curbuf->b_p_tw < 0)
7515 {
7516 errmsg = e_positive;
7517 curbuf->b_p_tw = 0;
7518 }
7519 if (p_tm < 0)
7520 {
7521 errmsg = e_positive;
7522 p_tm = 0;
7523 }
7524 if ((curwin->w_p_scr <= 0
7525 || (curwin->w_p_scr > curwin->w_height
7526 && curwin->w_height > 0))
7527 && full_screen)
7528 {
7529 if (pp == &(curwin->w_p_scr))
7530 {
7531 if (curwin->w_p_scr != 0)
7532 errmsg = e_scroll;
7533 win_comp_scroll(curwin);
7534 }
7535 /* If 'scroll' became invalid because of a side effect silently adjust
7536 * it. */
7537 else if (curwin->w_p_scr <= 0)
7538 curwin->w_p_scr = 1;
7539 else /* curwin->w_p_scr > curwin->w_height */
7540 curwin->w_p_scr = curwin->w_height;
7541 }
7542 if (p_report < 0)
7543 {
7544 errmsg = e_positive;
7545 p_report = 1;
7546 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007547 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 {
7549 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7550 p_sj = Rows / 2;
7551 else
7552 {
7553 errmsg = e_scroll;
7554 p_sj = 1;
7555 }
7556 }
7557 if (p_so < 0 && full_screen)
7558 {
7559 errmsg = e_scroll;
7560 p_so = 0;
7561 }
7562 if (p_siso < 0 && full_screen)
7563 {
7564 errmsg = e_positive;
7565 p_siso = 0;
7566 }
7567#ifdef FEAT_CMDWIN
7568 if (p_cwh < 1)
7569 {
7570 errmsg = e_positive;
7571 p_cwh = 1;
7572 }
7573#endif
7574 if (p_ut < 0)
7575 {
7576 errmsg = e_positive;
7577 p_ut = 2000;
7578 }
7579 if (p_ss < 0)
7580 {
7581 errmsg = e_positive;
7582 p_ss = 0;
7583 }
7584
7585 /* May set global value for local option. */
7586 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7587 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7588
7589 options[opt_idx].flags |= P_WAS_SET;
7590
7591 comp_col(); /* in case 'columns' or 'ls' changed */
7592 if (curwin->w_curswant != MAXCOL)
7593 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7594 check_redraw(options[opt_idx].flags);
7595
7596 return errmsg;
7597}
7598
7599/*
7600 * Called after an option changed: check if something needs to be redrawn.
7601 */
7602 static void
7603check_redraw(flags)
7604 long_u flags;
7605{
7606 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7607 int clear = (flags & P_RCLR) == P_RCLR;
7608 int all = ((flags & P_RALL) == P_RALL || clear);
7609
7610#ifdef FEAT_WINDOWS
7611 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7612 status_redraw_all();
7613#endif
7614
7615 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7616 changed_window_setting();
7617 if (flags & P_RBUF)
7618 redraw_curbuf_later(NOT_VALID);
7619 if (clear)
7620 redraw_all_later(CLEAR);
7621 else if (all)
7622 redraw_all_later(NOT_VALID);
7623}
7624
7625/*
7626 * Find index for option 'arg'.
7627 * Return -1 if not found.
7628 */
7629 static int
7630findoption(arg)
7631 char_u *arg;
7632{
7633 int opt_idx;
7634 char *s, *p;
7635 static short quick_tab[27] = {0, 0}; /* quick access table */
7636 int is_term_opt;
7637
7638 /*
7639 * For first call: Initialize the quick-access table.
7640 * It contains the index for the first option that starts with a certain
7641 * letter. There are 26 letters, plus the first "t_" option.
7642 */
7643 if (quick_tab[1] == 0)
7644 {
7645 p = options[0].fullname;
7646 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7647 {
7648 if (s[0] != p[0])
7649 {
7650 if (s[0] == 't' && s[1] == '_')
7651 quick_tab[26] = opt_idx;
7652 else
7653 quick_tab[CharOrdLow(s[0])] = opt_idx;
7654 }
7655 p = s;
7656 }
7657 }
7658
7659 /*
7660 * Check for name starting with an illegal character.
7661 */
7662#ifdef EBCDIC
7663 if (!islower(arg[0]))
7664#else
7665 if (arg[0] < 'a' || arg[0] > 'z')
7666#endif
7667 return -1;
7668
7669 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7670 if (is_term_opt)
7671 opt_idx = quick_tab[26];
7672 else
7673 opt_idx = quick_tab[CharOrdLow(arg[0])];
7674 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7675 {
7676 if (STRCMP(arg, s) == 0) /* match full name */
7677 break;
7678 }
7679 if (s == NULL && !is_term_opt)
7680 {
7681 opt_idx = quick_tab[CharOrdLow(arg[0])];
7682 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7683 {
7684 s = options[opt_idx].shortname;
7685 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7686 break;
7687 s = NULL;
7688 }
7689 }
7690 if (s == NULL)
7691 opt_idx = -1;
7692 return opt_idx;
7693}
7694
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007695#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696/*
7697 * Get the value for an option.
7698 *
7699 * Returns:
7700 * Number or Toggle option: 1, *numval gets value.
7701 * String option: 0, *stringval gets allocated string.
7702 * Hidden Number or Toggle option: -1.
7703 * hidden String option: -2.
7704 * unknown option: -3.
7705 */
7706 int
7707get_option_value(name, numval, stringval, opt_flags)
7708 char_u *name;
7709 long *numval;
7710 char_u **stringval; /* NULL when only checking existance */
7711 int opt_flags;
7712{
7713 int opt_idx;
7714 char_u *varp;
7715
7716 opt_idx = findoption(name);
7717 if (opt_idx < 0) /* unknown option */
7718 return -3;
7719
7720 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7721
7722 if (options[opt_idx].flags & P_STRING)
7723 {
7724 if (varp == NULL) /* hidden option */
7725 return -2;
7726 if (stringval != NULL)
7727 {
7728#ifdef FEAT_CRYPT
7729 /* never return the value of the crypt key */
7730 if ((char_u **)varp == &curbuf->b_p_key)
7731 *stringval = vim_strsave((char_u *)"*****");
7732 else
7733#endif
7734 *stringval = vim_strsave(*(char_u **)(varp));
7735 }
7736 return 0;
7737 }
7738
7739 if (varp == NULL) /* hidden option */
7740 return -1;
7741 if (options[opt_idx].flags & P_NUM)
7742 *numval = *(long *)varp;
7743 else
7744 {
7745 /* Special case: 'modified' is b_changed, but we also want to consider
7746 * it set when 'ff' or 'fenc' changed. */
7747 if ((int *)varp == &curbuf->b_changed)
7748 *numval = curbufIsChanged();
7749 else
7750 *numval = *(int *)varp;
7751 }
7752 return 1;
7753}
7754#endif
7755
7756/*
7757 * Set the value of option "name".
7758 * Use "string" for string options, use "number" for other options.
7759 */
7760 void
7761set_option_value(name, number, string, opt_flags)
7762 char_u *name;
7763 long number;
7764 char_u *string;
7765 int opt_flags; /* OPT_LOCAL or 0 (both) */
7766{
7767 int opt_idx;
7768 char_u *varp;
7769 int flags;
7770
7771 opt_idx = findoption(name);
7772 if (opt_idx == -1)
7773 EMSG2(_("E355: Unknown option: %s"), name);
7774 else
7775 {
7776 flags = options[opt_idx].flags;
7777#ifdef HAVE_SANDBOX
7778 /* Disallow changing some options in the sandbox */
7779 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007780 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007782 return;
7783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007785 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007786 set_string_option(opt_idx, string, opt_flags);
7787 else
7788 {
7789 varp = get_varp(&options[opt_idx]);
7790 if (varp != NULL) /* hidden option is not changed */
7791 {
7792 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00007793 (void)set_num_option(opt_idx, varp, number,
7794 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007796 (void)set_bool_option(opt_idx, varp, (int)number,
7797 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798 }
7799 }
7800 }
7801}
7802
7803/*
7804 * Get the terminal code for a terminal option.
7805 * Returns NULL when not found.
7806 */
7807 char_u *
7808get_term_code(tname)
7809 char_u *tname;
7810{
7811 int opt_idx;
7812 char_u *varp;
7813
7814 if (tname[0] != 't' || tname[1] != '_' ||
7815 tname[2] == NUL || tname[3] == NUL)
7816 return NULL;
7817 if ((opt_idx = findoption(tname)) >= 0)
7818 {
7819 varp = get_varp(&(options[opt_idx]));
7820 if (varp != NULL)
7821 varp = *(char_u **)(varp);
7822 return varp;
7823 }
7824 return find_termcode(tname + 2);
7825}
7826
7827 char_u *
7828get_highlight_default()
7829{
7830 int i;
7831
7832 i = findoption((char_u *)"hl");
7833 if (i >= 0)
7834 return options[i].def_val[VI_DEFAULT];
7835 return (char_u *)NULL;
7836}
7837
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007838#if defined(FEAT_MBYTE) || defined(PROTO)
7839 char_u *
7840get_encoding_default()
7841{
7842 int i;
7843
7844 i = findoption((char_u *)"enc");
7845 if (i >= 0)
7846 return options[i].def_val[VI_DEFAULT];
7847 return (char_u *)NULL;
7848}
7849#endif
7850
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851/*
7852 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7853 */
7854 static int
7855find_key_option(arg)
7856 char_u *arg;
7857{
7858 int key;
7859 int modifiers;
7860
7861 /*
7862 * Don't use get_special_key_code() for t_xx, we don't want it to call
7863 * add_termcap_entry().
7864 */
7865 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7866 key = TERMCAP2KEY(arg[2], arg[3]);
7867 else
7868 {
7869 --arg; /* put arg at the '<' */
7870 modifiers = 0;
7871 key = find_special_key(&arg, &modifiers, TRUE);
7872 if (modifiers) /* can't handle modifiers here */
7873 key = 0;
7874 }
7875 return key;
7876}
7877
7878/*
7879 * if 'all' == 0: show changed options
7880 * if 'all' == 1: show all normal options
7881 * if 'all' == 2: show all terminal options
7882 */
7883 static void
7884showoptions(all, opt_flags)
7885 int all;
7886 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7887{
7888 struct vimoption *p;
7889 int col;
7890 int isterm;
7891 char_u *varp;
7892 struct vimoption **items;
7893 int item_count;
7894 int run;
7895 int row, rows;
7896 int cols;
7897 int i;
7898 int len;
7899
7900#define INC 20
7901#define GAP 3
7902
7903 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7904 PARAM_COUNT));
7905 if (items == NULL)
7906 return;
7907
7908 /* Highlight title */
7909 if (all == 2)
7910 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7911 else if (opt_flags & OPT_GLOBAL)
7912 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7913 else if (opt_flags & OPT_LOCAL)
7914 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7915 else
7916 MSG_PUTS_TITLE(_("\n--- Options ---"));
7917
7918 /*
7919 * do the loop two times:
7920 * 1. display the short items
7921 * 2. display the long items (only strings and numbers)
7922 */
7923 for (run = 1; run <= 2 && !got_int; ++run)
7924 {
7925 /*
7926 * collect the items in items[]
7927 */
7928 item_count = 0;
7929 for (p = &options[0]; p->fullname != NULL; p++)
7930 {
7931 varp = NULL;
7932 isterm = istermoption(p);
7933 if (opt_flags != 0)
7934 {
7935 if (p->indir != PV_NONE && !isterm)
7936 varp = get_varp_scope(p, opt_flags);
7937 }
7938 else
7939 varp = get_varp(p);
7940 if (varp != NULL
7941 && ((all == 2 && isterm)
7942 || (all == 1 && !isterm)
7943 || (all == 0 && !optval_default(p, varp))))
7944 {
7945 if (p->flags & P_BOOL)
7946 len = 1; /* a toggle option fits always */
7947 else
7948 {
7949 option_value2string(p, opt_flags);
7950 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7951 }
7952 if ((len <= INC - GAP && run == 1) ||
7953 (len > INC - GAP && run == 2))
7954 items[item_count++] = p;
7955 }
7956 }
7957
7958 /*
7959 * display the items
7960 */
7961 if (run == 1)
7962 {
7963 cols = (Columns + GAP - 3) / INC;
7964 if (cols == 0)
7965 cols = 1;
7966 rows = (item_count + cols - 1) / cols;
7967 }
7968 else /* run == 2 */
7969 rows = item_count;
7970 for (row = 0; row < rows && !got_int; ++row)
7971 {
7972 msg_putchar('\n'); /* go to next line */
7973 if (got_int) /* 'q' typed in more */
7974 break;
7975 col = 0;
7976 for (i = row; i < item_count; i += rows)
7977 {
7978 msg_col = col; /* make columns */
7979 showoneopt(items[i], opt_flags);
7980 col += INC;
7981 }
7982 out_flush();
7983 ui_breakcheck();
7984 }
7985 }
7986 vim_free(items);
7987}
7988
7989/*
7990 * Return TRUE if option "p" has its default value.
7991 */
7992 static int
7993optval_default(p, varp)
7994 struct vimoption *p;
7995 char_u *varp;
7996{
7997 int dvi;
7998
7999 if (varp == NULL)
8000 return TRUE; /* hidden option is always at default */
8001 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8002 if (p->flags & P_NUM)
8003 return (*(long *)varp == (long)p->def_val[dvi]);
8004 if (p->flags & P_BOOL)
8005 /* the cast to long is required for Manx C */
8006 return (*(int *)varp == (int)(long)p->def_val[dvi]);
8007 /* P_STRING */
8008 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8009}
8010
8011/*
8012 * showoneopt: show the value of one option
8013 * must not be called with a hidden option!
8014 */
8015 static void
8016showoneopt(p, opt_flags)
8017 struct vimoption *p;
8018 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8019{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008020 char_u *varp;
8021 int save_silent = silent_mode;
8022
8023 silent_mode = FALSE;
8024 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008025
8026 varp = get_varp_scope(p, opt_flags);
8027
8028 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8029 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8030 ? !curbufIsChanged() : !*(int *)varp))
8031 MSG_PUTS("no");
8032 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8033 MSG_PUTS("--");
8034 else
8035 MSG_PUTS(" ");
8036 MSG_PUTS(p->fullname);
8037 if (!(p->flags & P_BOOL))
8038 {
8039 msg_putchar('=');
8040 /* put value string in NameBuff */
8041 option_value2string(p, opt_flags);
8042 msg_outtrans(NameBuff);
8043 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008044
8045 silent_mode = save_silent;
8046 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047}
8048
8049/*
8050 * Write modified options as ":set" commands to a file.
8051 *
8052 * There are three values for "opt_flags":
8053 * OPT_GLOBAL: Write global option values and fresh values of
8054 * buffer-local options (used for start of a session
8055 * file).
8056 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8057 * curwin (used for a vimrc file).
8058 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8059 * and local values for window-local options of
8060 * curwin. Local values are also written when at the
8061 * default value, because a modeline or autocommand
8062 * may have set them when doing ":edit file" and the
8063 * user has set them back at the default or fresh
8064 * value.
8065 * When "local_only" is TRUE, don't write fresh
8066 * values, only local values (for ":mkview").
8067 * (fresh value = value used for a new buffer or window for a local option).
8068 *
8069 * Return FAIL on error, OK otherwise.
8070 */
8071 int
8072makeset(fd, opt_flags, local_only)
8073 FILE *fd;
8074 int opt_flags;
8075 int local_only;
8076{
8077 struct vimoption *p;
8078 char_u *varp; /* currently used value */
8079 char_u *varp_fresh; /* local value */
8080 char_u *varp_local = NULL; /* fresh value */
8081 char *cmd;
8082 int round;
8083
8084 /*
8085 * The options that don't have a default (terminal name, columns, lines)
8086 * are never written. Terminal options are also not written.
8087 */
8088 for (p = &options[0]; !istermoption(p); p++)
8089 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
8090 {
8091 /* skip global option when only doing locals */
8092 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8093 continue;
8094
8095 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8096 * file, they are always buffer-specific. */
8097 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8098 continue;
8099
8100 /* Global values are only written when not at the default value. */
8101 varp = get_varp_scope(p, opt_flags);
8102 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8103 continue;
8104
8105 round = 2;
8106 if (p->indir != PV_NONE)
8107 {
8108 if (p->var == VAR_WIN)
8109 {
8110 /* skip window-local option when only doing globals */
8111 if (!(opt_flags & OPT_LOCAL))
8112 continue;
8113 /* When fresh value of window-local option is not at the
8114 * default, need to write it too. */
8115 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8116 {
8117 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8118 if (!optval_default(p, varp_fresh))
8119 {
8120 round = 1;
8121 varp_local = varp;
8122 varp = varp_fresh;
8123 }
8124 }
8125 }
8126 }
8127
8128 /* Round 1: fresh value for window-local options.
8129 * Round 2: other values */
8130 for ( ; round <= 2; varp = varp_local, ++round)
8131 {
8132 if (round == 1 || (opt_flags & OPT_GLOBAL))
8133 cmd = "set";
8134 else
8135 cmd = "setlocal";
8136
8137 if (p->flags & P_BOOL)
8138 {
8139 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8140 return FAIL;
8141 }
8142 else if (p->flags & P_NUM)
8143 {
8144 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8145 return FAIL;
8146 }
8147 else /* P_STRING */
8148 {
8149 /* Don't set 'syntax' and 'filetype' again if the value is
8150 * already right, avoids reloading the syntax file. */
8151 if (p->indir == PV_SYN || p->indir == PV_FT)
8152 {
8153 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8154 *(char_u **)(varp)) < 0
8155 || put_eol(fd) < 0)
8156 return FAIL;
8157 }
8158 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8159 (p->flags & P_EXPAND) != 0) == FAIL)
8160 return FAIL;
8161 if (p->indir == PV_SYN || p->indir == PV_FT)
8162 {
8163 if (put_line(fd, "endif") == FAIL)
8164 return FAIL;
8165 }
8166 }
8167 }
8168 }
8169 return OK;
8170}
8171
8172#if defined(FEAT_FOLDING) || defined(PROTO)
8173/*
8174 * Generate set commands for the local fold options only. Used when
8175 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8176 */
8177 int
8178makefoldset(fd)
8179 FILE *fd;
8180{
8181 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8182# ifdef FEAT_EVAL
8183 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8184 == FAIL
8185# endif
8186 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8187 == FAIL
8188 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8189 == FAIL
8190 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8191 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8192 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8193 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8194 )
8195 return FAIL;
8196
8197 return OK;
8198}
8199#endif
8200
8201 static int
8202put_setstring(fd, cmd, name, valuep, expand)
8203 FILE *fd;
8204 char *cmd;
8205 char *name;
8206 char_u **valuep;
8207 int expand;
8208{
8209 char_u *s;
8210 char_u buf[MAXPATHL];
8211
8212 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8213 return FAIL;
8214 if (*valuep != NULL)
8215 {
8216 /* Output 'pastetoggle' as key names. For other
8217 * options some characters have to be escaped with
8218 * CTRL-V or backslash */
8219 if (valuep == &p_pt)
8220 {
8221 s = *valuep;
8222 while (*s != NUL)
8223 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8224 return FAIL;
8225 }
8226 else if (expand)
8227 {
8228 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8229 if (put_escstr(fd, buf, 2) == FAIL)
8230 return FAIL;
8231 }
8232 else if (put_escstr(fd, *valuep, 2) == FAIL)
8233 return FAIL;
8234 }
8235 if (put_eol(fd) < 0)
8236 return FAIL;
8237 return OK;
8238}
8239
8240 static int
8241put_setnum(fd, cmd, name, valuep)
8242 FILE *fd;
8243 char *cmd;
8244 char *name;
8245 long *valuep;
8246{
8247 long wc;
8248
8249 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8250 return FAIL;
8251 if (wc_use_keyname((char_u *)valuep, &wc))
8252 {
8253 /* print 'wildchar' and 'wildcharm' as a key name */
8254 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8255 return FAIL;
8256 }
8257 else if (fprintf(fd, "%ld", *valuep) < 0)
8258 return FAIL;
8259 if (put_eol(fd) < 0)
8260 return FAIL;
8261 return OK;
8262}
8263
8264 static int
8265put_setbool(fd, cmd, name, value)
8266 FILE *fd;
8267 char *cmd;
8268 char *name;
8269 int value;
8270{
8271 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8272 || put_eol(fd) < 0)
8273 return FAIL;
8274 return OK;
8275}
8276
8277/*
8278 * Clear all the terminal options.
8279 * If the option has been allocated, free the memory.
8280 * Terminal options are never hidden or indirect.
8281 */
8282 void
8283clear_termoptions()
8284{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008285 /*
8286 * Reset a few things before clearing the old options. This may cause
8287 * outputting a few things that the terminal doesn't understand, but the
8288 * screen will be cleared later, so this is OK.
8289 */
8290#ifdef FEAT_MOUSE_TTY
8291 mch_setmouse(FALSE); /* switch mouse off */
8292#endif
8293#ifdef FEAT_TITLE
8294 mch_restore_title(3); /* restore window titles */
8295#endif
8296#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8297 /* When starting the GUI close the display opened for the clipboard.
8298 * After restoring the title, because that will need the display. */
8299 if (gui.starting)
8300 clear_xterm_clip();
8301#endif
8302#ifdef WIN3264
8303 /*
8304 * Check if this is allowed now.
8305 */
8306 if (can_end_termcap_mode(FALSE) == TRUE)
8307#endif
8308 stoptermcap(); /* stop termcap mode */
8309
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008310 free_termoptions();
8311}
8312
8313 void
8314free_termoptions()
8315{
8316 struct vimoption *p;
8317
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318 for (p = &options[0]; p->fullname != NULL; p++)
8319 if (istermoption(p))
8320 {
8321 if (p->flags & P_ALLOCED)
8322 free_string_option(*(char_u **)(p->var));
8323 if (p->flags & P_DEF_ALLOCED)
8324 free_string_option(p->def_val[VI_DEFAULT]);
8325 *(char_u **)(p->var) = empty_option;
8326 p->def_val[VI_DEFAULT] = empty_option;
8327 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8328 }
8329 clear_termcodes();
8330}
8331
8332/*
8333 * Set the terminal option defaults to the current value.
8334 * Used after setting the terminal name.
8335 */
8336 void
8337set_term_defaults()
8338{
8339 struct vimoption *p;
8340
8341 for (p = &options[0]; p->fullname != NULL; p++)
8342 {
8343 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8344 {
8345 if (p->flags & P_DEF_ALLOCED)
8346 {
8347 free_string_option(p->def_val[VI_DEFAULT]);
8348 p->flags &= ~P_DEF_ALLOCED;
8349 }
8350 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8351 if (p->flags & P_ALLOCED)
8352 {
8353 p->flags |= P_DEF_ALLOCED;
8354 p->flags &= ~P_ALLOCED; /* don't free the value now */
8355 }
8356 }
8357 }
8358}
8359
8360/*
8361 * return TRUE if 'p' starts with 't_'
8362 */
8363 static int
8364istermoption(p)
8365 struct vimoption *p;
8366{
8367 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8368}
8369
8370/*
8371 * Compute columns for ruler and shown command. 'sc_col' is also used to
8372 * decide what the maximum length of a message on the status line can be.
8373 * If there is a status line for the last window, 'sc_col' is independent
8374 * of 'ru_col'.
8375 */
8376
8377#define COL_RULER 17 /* columns needed by standard ruler */
8378
8379 void
8380comp_col()
8381{
8382#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8383 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8384
8385 sc_col = 0;
8386 ru_col = 0;
8387 if (p_ru)
8388 {
8389#ifdef FEAT_STL_OPT
8390 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8391#else
8392 ru_col = COL_RULER + 1;
8393#endif
8394 /* no last status line, adjust sc_col */
8395 if (!last_has_status)
8396 sc_col = ru_col;
8397 }
8398 if (p_sc)
8399 {
8400 sc_col += SHOWCMD_COLS;
8401 if (!p_ru || last_has_status) /* no need for separating space */
8402 ++sc_col;
8403 }
8404 sc_col = Columns - sc_col;
8405 ru_col = Columns - ru_col;
8406 if (sc_col <= 0) /* screen too narrow, will become a mess */
8407 sc_col = 1;
8408 if (ru_col <= 0)
8409 ru_col = 1;
8410#else
8411 sc_col = Columns;
8412 ru_col = Columns;
8413#endif
8414}
8415
8416/*
8417 * Get pointer to option variable, depending on local or global scope.
8418 */
8419 static char_u *
8420get_varp_scope(p, opt_flags)
8421 struct vimoption *p;
8422 int opt_flags;
8423{
8424 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8425 {
8426 if (p->var == VAR_WIN)
8427 return (char_u *)GLOBAL_WO(get_varp(p));
8428 return p->var;
8429 }
8430 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
8431 {
8432 switch ((int)p->indir)
8433 {
8434#ifdef FEAT_QUICKFIX
8435 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
8436 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
8437 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
8438#endif
8439 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
8440 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
8441 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
8442 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
8443 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
8444#ifdef FEAT_FIND_ID
8445 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
8446 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
8447#endif
8448#ifdef FEAT_INS_EXPAND
8449 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
8450 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
8451#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008452#ifdef FEAT_STL_OPT
8453 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
8454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455 }
8456 return NULL; /* "cannot happen" */
8457 }
8458 return get_varp(p);
8459}
8460
8461/*
8462 * Get pointer to option variable.
8463 */
8464 static char_u *
8465get_varp(p)
8466 struct vimoption *p;
8467{
8468 /* hidden option, always return NULL */
8469 if (p->var == NULL)
8470 return NULL;
8471
8472 switch ((int)p->indir)
8473 {
8474 case PV_NONE: return p->var;
8475
8476 /* global option with local value: use local value if it's been set */
8477 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
8478 ? (char_u *)&curbuf->b_p_ep : p->var;
8479 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
8480 ? (char_u *)&curbuf->b_p_kp : p->var;
8481 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
8482 ? (char_u *)&(curbuf->b_p_path) : p->var;
8483 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
8484 ? (char_u *)&(curbuf->b_p_ar) : p->var;
8485 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
8486 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8487#ifdef FEAT_FIND_ID
8488 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
8489 ? (char_u *)&(curbuf->b_p_def) : p->var;
8490 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
8491 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8492#endif
8493#ifdef FEAT_INS_EXPAND
8494 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
8495 ? (char_u *)&(curbuf->b_p_dict) : p->var;
8496 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
8497 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8498#endif
8499#ifdef FEAT_QUICKFIX
8500 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
8501 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8502 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
8503 ? (char_u *)&(curbuf->b_p_mp) : p->var;
8504 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8505 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8506#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008507#ifdef FEAT_STL_OPT
8508 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8509 ? (char_u *)&(curwin->w_p_stl) : p->var;
8510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511
8512#ifdef FEAT_ARABIC
8513 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8514#endif
8515 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008516#ifdef FEAT_SYN_HL
8517 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8518#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519#ifdef FEAT_DIFF
8520 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8521#endif
8522#ifdef FEAT_FOLDING
8523 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8524 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8525 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8526 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8527 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8528 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8529 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8530# ifdef FEAT_EVAL
8531 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8532 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8533# endif
8534 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8535#endif
8536 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008537#ifdef FEAT_LINEBREAK
8538 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8539#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540#if defined(FEAT_WINDOWS)
8541 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8542#endif
8543#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8544 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8545#endif
8546#ifdef FEAT_RIGHTLEFT
8547 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8548 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8549#endif
8550 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8551 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8552#ifdef FEAT_LINEBREAK
8553 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8554#endif
8555#ifdef FEAT_SCROLLBIND
8556 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8557#endif
8558
8559 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8560 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8561#ifdef FEAT_MBYTE
8562 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8563#endif
8564#if defined(FEAT_QUICKFIX)
8565 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8566 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8567#endif
8568 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8569 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8570#ifdef FEAT_CINDENT
8571 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8572 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8573 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8574#endif
8575#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8576 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8577#endif
8578#ifdef FEAT_COMMENTS
8579 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8580#endif
8581#ifdef FEAT_FOLDING
8582 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8583#endif
8584#ifdef FEAT_INS_EXPAND
8585 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8586#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008587#ifdef FEAT_COMPL_FUNC
8588 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008589 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008590#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8592 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8593#ifdef FEAT_MBYTE
8594 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8595#endif
8596 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8597#ifdef FEAT_AUTOCMD
8598 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8599#endif
8600 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008601 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8603 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8604 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8605 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8606#ifdef FEAT_FIND_ID
8607# ifdef FEAT_EVAL
8608 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8609# endif
8610#endif
8611#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8612 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8613 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8614#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008615#if defined(FEAT_EVAL)
8616 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
8617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618#ifdef FEAT_CRYPT
8619 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8620#endif
8621#ifdef FEAT_LISP
8622 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8623#endif
8624 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8625 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8626 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8627 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8628 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8629#ifdef FEAT_OSFILETYPE
8630 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8631#endif
8632 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008633#ifdef FEAT_TEXTOBJ
8634 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8635#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8637#ifdef FEAT_SMARTINDENT
8638 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8639#endif
8640#ifndef SHORT_FNAME
8641 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8642#endif
8643 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8644#ifdef FEAT_SEARCHPATH
8645 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8646#endif
8647 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8648#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008649 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008651 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008652 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008653 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654#endif
8655 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8656 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8657 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8658 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8659 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8660#ifdef FEAT_KEYMAP
8661 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8662#endif
8663 default: EMSG(_("E356: get_varp ERROR"));
8664 }
8665 /* always return a valid pointer to avoid a crash! */
8666 return (char_u *)&(curbuf->b_p_wm);
8667}
8668
8669/*
8670 * Get the value of 'equalprg', either the buffer-local one or the global one.
8671 */
8672 char_u *
8673get_equalprg()
8674{
8675 if (*curbuf->b_p_ep == NUL)
8676 return p_ep;
8677 return curbuf->b_p_ep;
8678}
8679
8680#if defined(FEAT_WINDOWS) || defined(PROTO)
8681/*
8682 * Copy options from one window to another.
8683 * Used when splitting a window.
8684 */
8685 void
8686win_copy_options(wp_from, wp_to)
8687 win_T *wp_from;
8688 win_T *wp_to;
8689{
8690 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8691 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8692# ifdef FEAT_RIGHTLEFT
8693# ifdef FEAT_FKMAP
8694 /* Is this right? */
8695 wp_to->w_farsi = wp_from->w_farsi;
8696# endif
8697# endif
8698}
8699#endif
8700
8701/*
8702 * Copy the options from one winopt_T to another.
8703 * Doesn't free the old option values in "to", use clear_winopt() for that.
8704 * The 'scroll' option is not copied, because it depends on the window height.
8705 * The 'previewwindow' option is reset, there can be only one preview window.
8706 */
8707 void
8708copy_winopt(from, to)
8709 winopt_T *from;
8710 winopt_T *to;
8711{
8712#ifdef FEAT_ARABIC
8713 to->wo_arab = from->wo_arab;
8714#endif
8715 to->wo_list = from->wo_list;
8716 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008717#ifdef FEAT_LINEBREAK
8718 to->wo_nuw = from->wo_nuw;
8719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720#ifdef FEAT_RIGHTLEFT
8721 to->wo_rl = from->wo_rl;
8722 to->wo_rlc = vim_strsave(from->wo_rlc);
8723#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008724#ifdef FEAT_STL_OPT
8725 to->wo_stl = vim_strsave(from->wo_stl);
8726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008727 to->wo_wrap = from->wo_wrap;
8728#ifdef FEAT_LINEBREAK
8729 to->wo_lbr = from->wo_lbr;
8730#endif
8731#ifdef FEAT_SCROLLBIND
8732 to->wo_scb = from->wo_scb;
8733#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008734#ifdef FEAT_SYN_HL
8735 to->wo_spell = from->wo_spell;
8736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008737#ifdef FEAT_DIFF
8738 to->wo_diff = from->wo_diff;
8739#endif
8740#ifdef FEAT_FOLDING
8741 to->wo_fdc = from->wo_fdc;
8742 to->wo_fen = from->wo_fen;
8743 to->wo_fdi = vim_strsave(from->wo_fdi);
8744 to->wo_fml = from->wo_fml;
8745 to->wo_fdl = from->wo_fdl;
8746 to->wo_fdm = vim_strsave(from->wo_fdm);
8747 to->wo_fdn = from->wo_fdn;
8748# ifdef FEAT_EVAL
8749 to->wo_fde = vim_strsave(from->wo_fde);
8750 to->wo_fdt = vim_strsave(from->wo_fdt);
8751# endif
8752 to->wo_fmr = vim_strsave(from->wo_fmr);
8753#endif
8754 check_winopt(to); /* don't want NULL pointers */
8755}
8756
8757/*
8758 * Check string options in a window for a NULL value.
8759 */
8760 void
8761check_win_options(win)
8762 win_T *win;
8763{
8764 check_winopt(&win->w_onebuf_opt);
8765 check_winopt(&win->w_allbuf_opt);
8766}
8767
8768/*
8769 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8770 */
8771/*ARGSUSED*/
8772 void
8773check_winopt(wop)
8774 winopt_T *wop;
8775{
8776#ifdef FEAT_FOLDING
8777 check_string_option(&wop->wo_fdi);
8778 check_string_option(&wop->wo_fdm);
8779# ifdef FEAT_EVAL
8780 check_string_option(&wop->wo_fde);
8781 check_string_option(&wop->wo_fdt);
8782# endif
8783 check_string_option(&wop->wo_fmr);
8784#endif
8785#ifdef FEAT_RIGHTLEFT
8786 check_string_option(&wop->wo_rlc);
8787#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008788#ifdef FEAT_STL_OPT
8789 check_string_option(&wop->wo_stl);
8790#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791}
8792
8793/*
8794 * Free the allocated memory inside a winopt_T.
8795 */
8796/*ARGSUSED*/
8797 void
8798clear_winopt(wop)
8799 winopt_T *wop;
8800{
8801#ifdef FEAT_FOLDING
8802 clear_string_option(&wop->wo_fdi);
8803 clear_string_option(&wop->wo_fdm);
8804# ifdef FEAT_EVAL
8805 clear_string_option(&wop->wo_fde);
8806 clear_string_option(&wop->wo_fdt);
8807# endif
8808 clear_string_option(&wop->wo_fmr);
8809#endif
8810#ifdef FEAT_RIGHTLEFT
8811 clear_string_option(&wop->wo_rlc);
8812#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008813#ifdef FEAT_STL_OPT
8814 clear_string_option(&wop->wo_stl);
8815#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008816}
8817
8818/*
8819 * Copy global option values to local options for one buffer.
8820 * Used when creating a new buffer and sometimes when entering a buffer.
8821 * flags:
8822 * BCO_ENTER We will enter the buf buffer.
8823 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8824 * appropriate.
8825 * BCO_NOHELP Don't copy the values to a help buffer.
8826 */
8827 void
8828buf_copy_options(buf, flags)
8829 buf_T *buf;
8830 int flags;
8831{
8832 int should_copy = TRUE;
8833 char_u *save_p_isk = NULL; /* init for GCC */
8834 int dont_do_help;
8835 int did_isk = FALSE;
8836
8837 /*
8838 * Don't do anything of the buffer is invalid.
8839 */
8840 if (buf == NULL || !buf_valid(buf))
8841 return;
8842
8843 /*
8844 * Skip this when the option defaults have not been set yet. Happens when
8845 * main() allocates the first buffer.
8846 */
8847 if (p_cpo != NULL)
8848 {
8849 /*
8850 * Always copy when entering and 'cpo' contains 'S'.
8851 * Don't copy when already initialized.
8852 * Don't copy when 'cpo' contains 's' and not entering.
8853 * 'S' BCO_ENTER initialized 's' should_copy
8854 * yes yes X X TRUE
8855 * yes no yes X FALSE
8856 * no X yes X FALSE
8857 * X no no yes FALSE
8858 * X no no no TRUE
8859 * no yes no X TRUE
8860 */
8861 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8862 && (buf->b_p_initialized
8863 || (!(flags & BCO_ENTER)
8864 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8865 should_copy = FALSE;
8866
8867 if (should_copy || (flags & BCO_ALWAYS))
8868 {
8869 /* Don't copy the options specific to a help buffer when
8870 * BCO_NOHELP is given or the options were initialized already
8871 * (jumping back to a help file with CTRL-T or CTRL-O) */
8872 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8873 || buf->b_p_initialized;
8874 if (dont_do_help) /* don't free b_p_isk */
8875 {
8876 save_p_isk = buf->b_p_isk;
8877 buf->b_p_isk = NULL;
8878 }
8879 /*
8880 * Always free the allocated strings.
8881 * If not already initialized, set 'readonly' and copy 'fileformat'.
8882 */
8883 if (!buf->b_p_initialized)
8884 {
8885 free_buf_options(buf, TRUE);
8886 buf->b_p_ro = FALSE; /* don't copy readonly */
8887 buf->b_p_tx = p_tx;
8888#ifdef FEAT_MBYTE
8889 buf->b_p_fenc = vim_strsave(p_fenc);
8890#endif
8891 buf->b_p_ff = vim_strsave(p_ff);
8892#if defined(FEAT_QUICKFIX)
8893 buf->b_p_bh = empty_option;
8894 buf->b_p_bt = empty_option;
8895#endif
8896 }
8897 else
8898 free_buf_options(buf, FALSE);
8899
8900 buf->b_p_ai = p_ai;
8901 buf->b_p_ai_nopaste = p_ai_nopaste;
8902 buf->b_p_sw = p_sw;
8903 buf->b_p_tw = p_tw;
8904 buf->b_p_tw_nopaste = p_tw_nopaste;
8905 buf->b_p_tw_nobin = p_tw_nobin;
8906 buf->b_p_wm = p_wm;
8907 buf->b_p_wm_nopaste = p_wm_nopaste;
8908 buf->b_p_wm_nobin = p_wm_nobin;
8909 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00008910#ifdef FEAT_MBYTE
8911 buf->b_p_bomb = p_bomb;
8912#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 buf->b_p_et = p_et;
8914 buf->b_p_et_nobin = p_et_nobin;
8915 buf->b_p_ml = p_ml;
8916 buf->b_p_ml_nobin = p_ml_nobin;
8917 buf->b_p_inf = p_inf;
8918 buf->b_p_swf = p_swf;
8919#ifdef FEAT_INS_EXPAND
8920 buf->b_p_cpt = vim_strsave(p_cpt);
8921#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008922#ifdef FEAT_COMPL_FUNC
8923 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008924 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008925#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 buf->b_p_sts = p_sts;
8927 buf->b_p_sts_nopaste = p_sts_nopaste;
8928#ifndef SHORT_FNAME
8929 buf->b_p_sn = p_sn;
8930#endif
8931#ifdef FEAT_COMMENTS
8932 buf->b_p_com = vim_strsave(p_com);
8933#endif
8934#ifdef FEAT_FOLDING
8935 buf->b_p_cms = vim_strsave(p_cms);
8936#endif
8937 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008938 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 buf->b_p_nf = vim_strsave(p_nf);
8940 buf->b_p_mps = vim_strsave(p_mps);
8941#ifdef FEAT_SMARTINDENT
8942 buf->b_p_si = p_si;
8943#endif
8944 buf->b_p_ci = p_ci;
8945#ifdef FEAT_CINDENT
8946 buf->b_p_cin = p_cin;
8947 buf->b_p_cink = vim_strsave(p_cink);
8948 buf->b_p_cino = vim_strsave(p_cino);
8949#endif
8950#ifdef FEAT_AUTOCMD
8951 /* Don't copy 'filetype', it must be detected */
8952 buf->b_p_ft = empty_option;
8953#endif
8954#ifdef FEAT_OSFILETYPE
8955 buf->b_p_oft = vim_strsave(p_oft);
8956#endif
8957 buf->b_p_pi = p_pi;
8958#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8959 buf->b_p_cinw = vim_strsave(p_cinw);
8960#endif
8961#ifdef FEAT_LISP
8962 buf->b_p_lisp = p_lisp;
8963#endif
8964#ifdef FEAT_SYN_HL
8965 /* Don't copy 'syntax', it must be set */
8966 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008967 buf->b_p_smc = p_smc;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008968 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00008969 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008970 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008971 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008972#endif
8973#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8974 buf->b_p_inde = vim_strsave(p_inde);
8975 buf->b_p_indk = vim_strsave(p_indk);
8976#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008977#if defined(FEAT_EVAL)
8978 buf->b_p_fex = vim_strsave(p_fex);
8979#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980#ifdef FEAT_CRYPT
8981 buf->b_p_key = vim_strsave(p_key);
8982#endif
8983#ifdef FEAT_SEARCHPATH
8984 buf->b_p_sua = vim_strsave(p_sua);
8985#endif
8986#ifdef FEAT_KEYMAP
8987 buf->b_p_keymap = vim_strsave(p_keymap);
8988 buf->b_kmap_state |= KEYMAP_INIT;
8989#endif
8990 /* This isn't really an option, but copying the langmap and IME
8991 * state from the current buffer is better than resetting it. */
8992 buf->b_p_iminsert = p_iminsert;
8993 buf->b_p_imsearch = p_imsearch;
8994
8995 /* options that are normally global but also have a local value
8996 * are not copied, start using the global value */
8997 buf->b_p_ar = -1;
8998#ifdef FEAT_QUICKFIX
8999 buf->b_p_gp = empty_option;
9000 buf->b_p_mp = empty_option;
9001 buf->b_p_efm = empty_option;
9002#endif
9003 buf->b_p_ep = empty_option;
9004 buf->b_p_kp = empty_option;
9005 buf->b_p_path = empty_option;
9006 buf->b_p_tags = empty_option;
9007#ifdef FEAT_FIND_ID
9008 buf->b_p_def = empty_option;
9009 buf->b_p_inc = empty_option;
9010# ifdef FEAT_EVAL
9011 buf->b_p_inex = vim_strsave(p_inex);
9012# endif
9013#endif
9014#ifdef FEAT_INS_EXPAND
9015 buf->b_p_dict = empty_option;
9016 buf->b_p_tsr = empty_option;
9017#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009018#ifdef FEAT_TEXTOBJ
9019 buf->b_p_qe = vim_strsave(p_qe);
9020#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009021
9022 /*
9023 * Don't copy the options set by ex_help(), use the saved values,
9024 * when going from a help buffer to a non-help buffer.
9025 * Don't touch these at all when BCO_NOHELP is used and going from
9026 * or to a help buffer.
9027 */
9028 if (dont_do_help)
9029 buf->b_p_isk = save_p_isk;
9030 else
9031 {
9032 buf->b_p_isk = vim_strsave(p_isk);
9033 did_isk = TRUE;
9034 buf->b_p_ts = p_ts;
9035 buf->b_help = FALSE;
9036#ifdef FEAT_QUICKFIX
9037 if (buf->b_p_bt[0] == 'h')
9038 clear_string_option(&buf->b_p_bt);
9039#endif
9040 buf->b_p_ma = p_ma;
9041 }
9042 }
9043
9044 /*
9045 * When the options should be copied (ignoring BCO_ALWAYS), set the
9046 * flag that indicates that the options have been initialized.
9047 */
9048 if (should_copy)
9049 buf->b_p_initialized = TRUE;
9050 }
9051
9052 check_buf_options(buf); /* make sure we don't have NULLs */
9053 if (did_isk)
9054 (void)buf_init_chartab(buf, FALSE);
9055}
9056
9057/*
9058 * Reset the 'modifiable' option and its default value.
9059 */
9060 void
9061reset_modifiable()
9062{
9063 int opt_idx;
9064
9065 curbuf->b_p_ma = FALSE;
9066 p_ma = FALSE;
9067 opt_idx = findoption((char_u *)"ma");
9068 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9069}
9070
9071/*
9072 * Set the global value for 'iminsert' to the local value.
9073 */
9074 void
9075set_iminsert_global()
9076{
9077 p_iminsert = curbuf->b_p_iminsert;
9078}
9079
9080/*
9081 * Set the global value for 'imsearch' to the local value.
9082 */
9083 void
9084set_imsearch_global()
9085{
9086 p_imsearch = curbuf->b_p_imsearch;
9087}
9088
9089#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9090static int expand_option_idx = -1;
9091static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9092static int expand_option_flags = 0;
9093
9094 void
9095set_context_in_set_cmd(xp, arg, opt_flags)
9096 expand_T *xp;
9097 char_u *arg;
9098 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9099{
9100 int nextchar;
9101 long_u flags = 0; /* init for GCC */
9102 int opt_idx = 0; /* init for GCC */
9103 char_u *p;
9104 char_u *s;
9105 int is_term_option = FALSE;
9106 int key;
9107
9108 expand_option_flags = opt_flags;
9109
9110 xp->xp_context = EXPAND_SETTINGS;
9111 if (*arg == NUL)
9112 {
9113 xp->xp_pattern = arg;
9114 return;
9115 }
9116 p = arg + STRLEN(arg) - 1;
9117 if (*p == ' ' && *(p - 1) != '\\')
9118 {
9119 xp->xp_pattern = p + 1;
9120 return;
9121 }
9122 while (p > arg)
9123 {
9124 s = p;
9125 /* count number of backslashes before ' ' or ',' */
9126 if (*p == ' ' || *p == ',')
9127 {
9128 while (s > arg && *(s - 1) == '\\')
9129 --s;
9130 }
9131 /* break at a space with an even number of backslashes */
9132 if (*p == ' ' && ((p - s) & 1) == 0)
9133 {
9134 ++p;
9135 break;
9136 }
9137 --p;
9138 }
9139 if (STRNCMP(p, "no", 2) == 0)
9140 {
9141 xp->xp_context = EXPAND_BOOL_SETTINGS;
9142 p += 2;
9143 }
9144 if (STRNCMP(p, "inv", 3) == 0)
9145 {
9146 xp->xp_context = EXPAND_BOOL_SETTINGS;
9147 p += 3;
9148 }
9149 xp->xp_pattern = arg = p;
9150 if (*arg == '<')
9151 {
9152 while (*p != '>')
9153 if (*p++ == NUL) /* expand terminal option name */
9154 return;
9155 key = get_special_key_code(arg + 1);
9156 if (key == 0) /* unknown name */
9157 {
9158 xp->xp_context = EXPAND_NOTHING;
9159 return;
9160 }
9161 nextchar = *++p;
9162 is_term_option = TRUE;
9163 expand_option_name[2] = KEY2TERMCAP0(key);
9164 expand_option_name[3] = KEY2TERMCAP1(key);
9165 }
9166 else
9167 {
9168 if (p[0] == 't' && p[1] == '_')
9169 {
9170 p += 2;
9171 if (*p != NUL)
9172 ++p;
9173 if (*p == NUL)
9174 return; /* expand option name */
9175 nextchar = *++p;
9176 is_term_option = TRUE;
9177 expand_option_name[2] = p[-2];
9178 expand_option_name[3] = p[-1];
9179 }
9180 else
9181 {
9182 /* Allow * wildcard */
9183 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9184 p++;
9185 if (*p == NUL)
9186 return;
9187 nextchar = *p;
9188 *p = NUL;
9189 opt_idx = findoption(arg);
9190 *p = nextchar;
9191 if (opt_idx == -1 || options[opt_idx].var == NULL)
9192 {
9193 xp->xp_context = EXPAND_NOTHING;
9194 return;
9195 }
9196 flags = options[opt_idx].flags;
9197 if (flags & P_BOOL)
9198 {
9199 xp->xp_context = EXPAND_NOTHING;
9200 return;
9201 }
9202 }
9203 }
9204 /* handle "-=" and "+=" */
9205 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9206 {
9207 ++p;
9208 nextchar = '=';
9209 }
9210 if ((nextchar != '=' && nextchar != ':')
9211 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9212 {
9213 xp->xp_context = EXPAND_UNSUCCESSFUL;
9214 return;
9215 }
9216 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9217 {
9218 xp->xp_context = EXPAND_OLD_SETTING;
9219 if (is_term_option)
9220 expand_option_idx = -1;
9221 else
9222 expand_option_idx = opt_idx;
9223 xp->xp_pattern = p + 1;
9224 return;
9225 }
9226 xp->xp_context = EXPAND_NOTHING;
9227 if (is_term_option || (flags & P_NUM))
9228 return;
9229
9230 xp->xp_pattern = p + 1;
9231
9232 if (flags & P_EXPAND)
9233 {
9234 p = options[opt_idx].var;
9235 if (p == (char_u *)&p_bdir
9236 || p == (char_u *)&p_dir
9237 || p == (char_u *)&p_path
9238 || p == (char_u *)&p_rtp
9239#ifdef FEAT_SEARCHPATH
9240 || p == (char_u *)&p_cdpath
9241#endif
9242#ifdef FEAT_SESSION
9243 || p == (char_u *)&p_vdir
9244#endif
9245 )
9246 {
9247 xp->xp_context = EXPAND_DIRECTORIES;
9248 if (p == (char_u *)&p_path
9249#ifdef FEAT_SEARCHPATH
9250 || p == (char_u *)&p_cdpath
9251#endif
9252 )
9253 xp->xp_backslash = XP_BS_THREE;
9254 else
9255 xp->xp_backslash = XP_BS_ONE;
9256 }
9257 else
9258 {
9259 xp->xp_context = EXPAND_FILES;
9260 /* for 'tags' need three backslashes for a space */
9261 if (p == (char_u *)&p_tags)
9262 xp->xp_backslash = XP_BS_THREE;
9263 else
9264 xp->xp_backslash = XP_BS_ONE;
9265 }
9266 }
9267
9268 /* For an option that is a list of file names, find the start of the
9269 * last file name. */
9270 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9271 {
9272 /* count number of backslashes before ' ' or ',' */
9273 if (*p == ' ' || *p == ',')
9274 {
9275 s = p;
9276 while (s > xp->xp_pattern && *(s - 1) == '\\')
9277 --s;
9278 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9279 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9280 {
9281 xp->xp_pattern = p + 1;
9282 break;
9283 }
9284 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009285
9286#ifdef FEAT_SYN_HL
9287 /* for 'spellsuggest' start at "file:" */
9288 if (options[opt_idx].var == (char_u *)&p_sps
9289 && STRNCMP(p, "file:", 5) == 0)
9290 {
9291 xp->xp_pattern = p + 5;
9292 break;
9293 }
9294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295 }
9296
9297 return;
9298}
9299
9300 int
9301ExpandSettings(xp, regmatch, num_file, file)
9302 expand_T *xp;
9303 regmatch_T *regmatch;
9304 int *num_file;
9305 char_u ***file;
9306{
9307 int num_normal = 0; /* Nr of matching non-term-code settings */
9308 int num_term = 0; /* Nr of matching terminal code settings */
9309 int opt_idx;
9310 int match;
9311 int count = 0;
9312 char_u *str;
9313 int loop;
9314 int is_term_opt;
9315 char_u name_buf[MAX_KEY_NAME_LEN];
9316 static char *(names[]) = {"all", "termcap"};
9317 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9318
9319 /* do this loop twice:
9320 * loop == 0: count the number of matching options
9321 * loop == 1: copy the matching options into allocated memory
9322 */
9323 for (loop = 0; loop <= 1; ++loop)
9324 {
9325 regmatch->rm_ic = ic;
9326 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9327 {
9328 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9329 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9330 {
9331 if (loop == 0)
9332 num_normal++;
9333 else
9334 (*file)[count++] = vim_strsave((char_u *)names[match]);
9335 }
9336 }
9337 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9338 opt_idx++)
9339 {
9340 if (options[opt_idx].var == NULL)
9341 continue;
9342 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9343 && !(options[opt_idx].flags & P_BOOL))
9344 continue;
9345 is_term_opt = istermoption(&options[opt_idx]);
9346 if (is_term_opt && num_normal > 0)
9347 continue;
9348 match = FALSE;
9349 if (vim_regexec(regmatch, str, (colnr_T)0)
9350 || (options[opt_idx].shortname != NULL
9351 && vim_regexec(regmatch,
9352 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9353 match = TRUE;
9354 else if (is_term_opt)
9355 {
9356 name_buf[0] = '<';
9357 name_buf[1] = 't';
9358 name_buf[2] = '_';
9359 name_buf[3] = str[2];
9360 name_buf[4] = str[3];
9361 name_buf[5] = '>';
9362 name_buf[6] = NUL;
9363 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9364 {
9365 match = TRUE;
9366 str = name_buf;
9367 }
9368 }
9369 if (match)
9370 {
9371 if (loop == 0)
9372 {
9373 if (is_term_opt)
9374 num_term++;
9375 else
9376 num_normal++;
9377 }
9378 else
9379 (*file)[count++] = vim_strsave(str);
9380 }
9381 }
9382 /*
9383 * Check terminal key codes, these are not in the option table
9384 */
9385 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9386 {
9387 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9388 {
9389 if (!isprint(str[0]) || !isprint(str[1]))
9390 continue;
9391
9392 name_buf[0] = 't';
9393 name_buf[1] = '_';
9394 name_buf[2] = str[0];
9395 name_buf[3] = str[1];
9396 name_buf[4] = NUL;
9397
9398 match = FALSE;
9399 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9400 match = TRUE;
9401 else
9402 {
9403 name_buf[0] = '<';
9404 name_buf[1] = 't';
9405 name_buf[2] = '_';
9406 name_buf[3] = str[0];
9407 name_buf[4] = str[1];
9408 name_buf[5] = '>';
9409 name_buf[6] = NUL;
9410
9411 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9412 match = TRUE;
9413 }
9414 if (match)
9415 {
9416 if (loop == 0)
9417 num_term++;
9418 else
9419 (*file)[count++] = vim_strsave(name_buf);
9420 }
9421 }
9422
9423 /*
9424 * Check special key names.
9425 */
9426 regmatch->rm_ic = TRUE; /* ignore case here */
9427 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9428 {
9429 name_buf[0] = '<';
9430 STRCPY(name_buf + 1, str);
9431 STRCAT(name_buf, ">");
9432
9433 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9434 {
9435 if (loop == 0)
9436 num_term++;
9437 else
9438 (*file)[count++] = vim_strsave(name_buf);
9439 }
9440 }
9441 }
9442 if (loop == 0)
9443 {
9444 if (num_normal > 0)
9445 *num_file = num_normal;
9446 else if (num_term > 0)
9447 *num_file = num_term;
9448 else
9449 return OK;
9450 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9451 if (*file == NULL)
9452 {
9453 *file = (char_u **)"";
9454 return FAIL;
9455 }
9456 }
9457 }
9458 return OK;
9459}
9460
9461 int
9462ExpandOldSetting(num_file, file)
9463 int *num_file;
9464 char_u ***file;
9465{
9466 char_u *var = NULL; /* init for GCC */
9467 char_u *buf;
9468
9469 *num_file = 0;
9470 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9471 if (*file == NULL)
9472 return FAIL;
9473
9474 /*
9475 * For a terminal key code expand_option_idx is < 0.
9476 */
9477 if (expand_option_idx < 0)
9478 {
9479 var = find_termcode(expand_option_name + 2);
9480 if (var == NULL)
9481 expand_option_idx = findoption(expand_option_name);
9482 }
9483
9484 if (expand_option_idx >= 0)
9485 {
9486 /* put string of option value in NameBuff */
9487 option_value2string(&options[expand_option_idx], expand_option_flags);
9488 var = NameBuff;
9489 }
9490 else if (var == NULL)
9491 var = (char_u *)"";
9492
9493 /* A backslash is required before some characters. This is the reverse of
9494 * what happens in do_set(). */
9495 buf = vim_strsave_escaped(var, escape_chars);
9496
9497 if (buf == NULL)
9498 {
9499 vim_free(*file);
9500 *file = NULL;
9501 return FAIL;
9502 }
9503
9504#ifdef BACKSLASH_IN_FILENAME
9505 /* For MS-Windows et al. we don't double backslashes at the start and
9506 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009507 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009508 if (var[0] == '\\' && var[1] == '\\'
9509 && expand_option_idx >= 0
9510 && (options[expand_option_idx].flags & P_EXPAND)
9511 && vim_isfilec(var[2])
9512 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9513 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009514#endif
9515
9516 *file[0] = buf;
9517 *num_file = 1;
9518 return OK;
9519}
9520#endif
9521
9522/*
9523 * Get the value for the numeric or string option *opp in a nice format into
9524 * NameBuff[]. Must not be called with a hidden option!
9525 */
9526 static void
9527option_value2string(opp, opt_flags)
9528 struct vimoption *opp;
9529 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9530{
9531 char_u *varp;
9532
9533 varp = get_varp_scope(opp, opt_flags);
9534
9535 if (opp->flags & P_NUM)
9536 {
9537 long wc = 0;
9538
9539 if (wc_use_keyname(varp, &wc))
9540 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9541 else if (wc != 0)
9542 STRCPY(NameBuff, transchar((int)wc));
9543 else
9544 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9545 }
9546 else /* P_STRING */
9547 {
9548 varp = *(char_u **)(varp);
9549 if (varp == NULL) /* just in case */
9550 NameBuff[0] = NUL;
9551#ifdef FEAT_CRYPT
9552 /* don't show the actual value of 'key', only that it's set */
9553 if (opp->var == (char_u *)&p_key && *varp)
9554 STRCPY(NameBuff, "*****");
9555#endif
9556 else if (opp->flags & P_EXPAND)
9557 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9558 /* Translate 'pastetoggle' into special key names */
9559 else if ((char_u **)opp->var == &p_pt)
9560 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9561 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009562 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009563 }
9564}
9565
9566/*
9567 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9568 * printed as a keyname.
9569 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9570 */
9571 static int
9572wc_use_keyname(varp, wcp)
9573 char_u *varp;
9574 long *wcp;
9575{
9576 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9577 {
9578 *wcp = *(long *)varp;
9579 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9580 return TRUE;
9581 }
9582 return FALSE;
9583}
9584
9585#ifdef FEAT_LANGMAP
9586/*
9587 * Any character has an equivalent character. This is used for keyboards that
9588 * have a special language mode that sends characters above 128 (although
9589 * other characters can be translated too).
9590 */
9591
9592/*
9593 * char_u langmap_mapchar[256];
9594 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9595 * "translate" native lang chars in normal mode or some cases of
9596 * insert mode without having to tediously switch lang mode back&forth.
9597 */
9598
9599 static void
9600langmap_init()
9601{
9602 int i;
9603
9604 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9605 langmap_mapchar[i] = i;
9606}
9607
9608/*
9609 * Called when langmap option is set; the language map can be
9610 * changed at any time!
9611 */
9612 static void
9613langmap_set()
9614{
9615 char_u *p;
9616 char_u *p2;
9617 int from, to;
9618
9619 langmap_init(); /* back to one-to-one map first */
9620
9621 for (p = p_langmap; p[0] != NUL; )
9622 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009623 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9624 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009625 {
9626 if (p2[0] == '\\' && p2[1] != NUL)
9627 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009628 }
9629 if (p2[0] == ';')
9630 ++p2; /* abcd;ABCD form, p2 points to A */
9631 else
9632 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9633 while (p[0])
9634 {
9635 if (p[0] == '\\' && p[1] != NUL)
9636 ++p;
9637#ifdef FEAT_MBYTE
9638 from = (*mb_ptr2char)(p);
9639#else
9640 from = p[0];
9641#endif
9642 if (p2 == NULL)
9643 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009644 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645 if (p[0] == '\\')
9646 ++p;
9647#ifdef FEAT_MBYTE
9648 to = (*mb_ptr2char)(p);
9649#else
9650 to = p[0];
9651#endif
9652 }
9653 else
9654 {
9655 if (p2[0] == '\\')
9656 ++p2;
9657#ifdef FEAT_MBYTE
9658 to = (*mb_ptr2char)(p2);
9659#else
9660 to = p2[0];
9661#endif
9662 }
9663 if (to == NUL)
9664 {
9665 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9666 transchar(from));
9667 return;
9668 }
9669 langmap_mapchar[from & 255] = to;
9670
9671 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009672 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009673 if (p2 == NULL)
9674 {
9675 if (p[0] == ',')
9676 {
9677 ++p;
9678 break;
9679 }
9680 }
9681 else
9682 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009683 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009684 if (*p == ';')
9685 {
9686 p = p2;
9687 if (p[0] != NUL)
9688 {
9689 if (p[0] != ',')
9690 {
9691 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9692 return;
9693 }
9694 ++p;
9695 }
9696 break;
9697 }
9698 }
9699 }
9700 }
9701}
9702#endif
9703
9704/*
9705 * Return TRUE if format option 'x' is in effect.
9706 * Take care of no formatting when 'paste' is set.
9707 */
9708 int
9709has_format_option(x)
9710 int x;
9711{
9712 if (p_paste)
9713 return FALSE;
9714 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9715}
9716
9717/*
9718 * Return TRUE if "x" is present in 'shortmess' option, or
9719 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9720 */
9721 int
9722shortmess(x)
9723 int x;
9724{
9725 return ( vim_strchr(p_shm, x) != NULL
9726 || (vim_strchr(p_shm, 'a') != NULL
9727 && vim_strchr((char_u *)SHM_A, x) != NULL));
9728}
9729
9730/*
9731 * paste_option_changed() - Called after p_paste was set or reset.
9732 */
9733 static void
9734paste_option_changed()
9735{
9736 static int old_p_paste = FALSE;
9737 static int save_sm = 0;
9738#ifdef FEAT_CMDL_INFO
9739 static int save_ru = 0;
9740#endif
9741#ifdef FEAT_RIGHTLEFT
9742 static int save_ri = 0;
9743 static int save_hkmap = 0;
9744#endif
9745 buf_T *buf;
9746
9747 if (p_paste)
9748 {
9749 /*
9750 * Paste switched from off to on.
9751 * Save the current values, so they can be restored later.
9752 */
9753 if (!old_p_paste)
9754 {
9755 /* save options for each buffer */
9756 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9757 {
9758 buf->b_p_tw_nopaste = buf->b_p_tw;
9759 buf->b_p_wm_nopaste = buf->b_p_wm;
9760 buf->b_p_sts_nopaste = buf->b_p_sts;
9761 buf->b_p_ai_nopaste = buf->b_p_ai;
9762 }
9763
9764 /* save global options */
9765 save_sm = p_sm;
9766#ifdef FEAT_CMDL_INFO
9767 save_ru = p_ru;
9768#endif
9769#ifdef FEAT_RIGHTLEFT
9770 save_ri = p_ri;
9771 save_hkmap = p_hkmap;
9772#endif
9773 /* save global values for local buffer options */
9774 p_tw_nopaste = p_tw;
9775 p_wm_nopaste = p_wm;
9776 p_sts_nopaste = p_sts;
9777 p_ai_nopaste = p_ai;
9778 }
9779
9780 /*
9781 * Always set the option values, also when 'paste' is set when it is
9782 * already on.
9783 */
9784 /* set options for each buffer */
9785 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9786 {
9787 buf->b_p_tw = 0; /* textwidth is 0 */
9788 buf->b_p_wm = 0; /* wrapmargin is 0 */
9789 buf->b_p_sts = 0; /* softtabstop is 0 */
9790 buf->b_p_ai = 0; /* no auto-indent */
9791 }
9792
9793 /* set global options */
9794 p_sm = 0; /* no showmatch */
9795#ifdef FEAT_CMDL_INFO
9796# ifdef FEAT_WINDOWS
9797 if (p_ru)
9798 status_redraw_all(); /* redraw to remove the ruler */
9799# endif
9800 p_ru = 0; /* no ruler */
9801#endif
9802#ifdef FEAT_RIGHTLEFT
9803 p_ri = 0; /* no reverse insert */
9804 p_hkmap = 0; /* no Hebrew keyboard */
9805#endif
9806 /* set global values for local buffer options */
9807 p_tw = 0;
9808 p_wm = 0;
9809 p_sts = 0;
9810 p_ai = 0;
9811 }
9812
9813 /*
9814 * Paste switched from on to off: Restore saved values.
9815 */
9816 else if (old_p_paste)
9817 {
9818 /* restore options for each buffer */
9819 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9820 {
9821 buf->b_p_tw = buf->b_p_tw_nopaste;
9822 buf->b_p_wm = buf->b_p_wm_nopaste;
9823 buf->b_p_sts = buf->b_p_sts_nopaste;
9824 buf->b_p_ai = buf->b_p_ai_nopaste;
9825 }
9826
9827 /* restore global options */
9828 p_sm = save_sm;
9829#ifdef FEAT_CMDL_INFO
9830# ifdef FEAT_WINDOWS
9831 if (p_ru != save_ru)
9832 status_redraw_all(); /* redraw to draw the ruler */
9833# endif
9834 p_ru = save_ru;
9835#endif
9836#ifdef FEAT_RIGHTLEFT
9837 p_ri = save_ri;
9838 p_hkmap = save_hkmap;
9839#endif
9840 /* set global values for local buffer options */
9841 p_tw = p_tw_nopaste;
9842 p_wm = p_wm_nopaste;
9843 p_sts = p_sts_nopaste;
9844 p_ai = p_ai_nopaste;
9845 }
9846
9847 old_p_paste = p_paste;
9848}
9849
9850/*
9851 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9852 *
9853 * Reset 'compatible' and set the values for options that didn't get set yet
9854 * to the Vim defaults.
9855 * Don't do this if the 'compatible' option has been set or reset before.
9856 */
9857 void
9858vimrc_found()
9859{
9860 int opt_idx;
9861
9862 if (!option_was_set((char_u *)"cp"))
9863 {
9864 p_cp = FALSE;
9865 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9866 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9867 set_option_default(opt_idx, OPT_FREE, FALSE);
9868 didset_options();
9869 }
9870}
9871
9872/*
9873 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9874 */
9875 void
9876change_compatible(on)
9877 int on;
9878{
9879 if (p_cp != on)
9880 {
9881 p_cp = on;
9882 compatible_set();
9883 }
9884 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9885}
9886
9887/*
9888 * Return TRUE when option "name" has been set.
9889 */
9890 int
9891option_was_set(name)
9892 char_u *name;
9893{
9894 int idx;
9895
9896 idx = findoption(name);
9897 if (idx < 0) /* unknown option */
9898 return FALSE;
9899 if (options[idx].flags & P_WAS_SET)
9900 return TRUE;
9901 return FALSE;
9902}
9903
9904/*
9905 * compatible_set() - Called when 'compatible' has been set or unset.
9906 *
9907 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9908 * flag) to a Vi compatible value.
9909 * When 'compatible' is unset: Set all options that have a different default
9910 * for Vim (without the P_VI_DEF flag) to that default.
9911 */
9912 static void
9913compatible_set()
9914{
9915 int opt_idx;
9916
9917 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9918 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9919 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9920 set_option_default(opt_idx, OPT_FREE, p_cp);
9921 didset_options();
9922}
9923
9924#ifdef FEAT_LINEBREAK
9925
9926# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9927 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009928 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009929# endif
9930
9931/*
9932 * fill_breakat_flags() -- called when 'breakat' changes value.
9933 */
9934 static void
9935fill_breakat_flags()
9936{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00009937 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009938 int i;
9939
9940 for (i = 0; i < 256; i++)
9941 breakat_flags[i] = FALSE;
9942
9943 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00009944 for (p = p_breakat; *p; p++)
9945 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009946}
9947
9948# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009949 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950# endif
9951
9952#endif
9953
9954/*
9955 * Check an option that can be a range of string values.
9956 *
9957 * Return OK for correct value, FAIL otherwise.
9958 * Empty is always OK.
9959 */
9960 static int
9961check_opt_strings(val, values, list)
9962 char_u *val;
9963 char **values;
9964 int list; /* when TRUE: accept a list of values */
9965{
9966 return opt_strings_flags(val, values, NULL, list);
9967}
9968
9969/*
9970 * Handle an option that can be a range of string values.
9971 * Set a flag in "*flagp" for each string present.
9972 *
9973 * Return OK for correct value, FAIL otherwise.
9974 * Empty is always OK.
9975 */
9976 static int
9977opt_strings_flags(val, values, flagp, list)
9978 char_u *val; /* new value */
9979 char **values; /* array of valid string values */
9980 unsigned *flagp;
9981 int list; /* when TRUE: accept a list of values */
9982{
9983 int i;
9984 int len;
9985 unsigned new_flags = 0;
9986
9987 while (*val)
9988 {
9989 for (i = 0; ; ++i)
9990 {
9991 if (values[i] == NULL) /* val not found in values[] */
9992 return FAIL;
9993
9994 len = (int)STRLEN(values[i]);
9995 if (STRNCMP(values[i], val, len) == 0
9996 && ((list && val[len] == ',') || val[len] == NUL))
9997 {
9998 val += len + (val[len] == ',');
9999 new_flags |= (1 << i);
10000 break; /* check next item in val list */
10001 }
10002 }
10003 }
10004 if (flagp != NULL)
10005 *flagp = new_flags;
10006
10007 return OK;
10008}
10009
10010/*
10011 * Read the 'wildmode' option, fill wim_flags[].
10012 */
10013 static int
10014check_opt_wim()
10015{
10016 char_u new_wim_flags[4];
10017 char_u *p;
10018 int i;
10019 int idx = 0;
10020
10021 for (i = 0; i < 4; ++i)
10022 new_wim_flags[i] = 0;
10023
10024 for (p = p_wim; *p; ++p)
10025 {
10026 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10027 ;
10028 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10029 return FAIL;
10030 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10031 new_wim_flags[idx] |= WIM_LONGEST;
10032 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10033 new_wim_flags[idx] |= WIM_FULL;
10034 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10035 new_wim_flags[idx] |= WIM_LIST;
10036 else
10037 return FAIL;
10038 p += i;
10039 if (*p == NUL)
10040 break;
10041 if (*p == ',')
10042 {
10043 if (idx == 3)
10044 return FAIL;
10045 ++idx;
10046 }
10047 }
10048
10049 /* fill remaining entries with last flag */
10050 while (idx < 3)
10051 {
10052 new_wim_flags[idx + 1] = new_wim_flags[idx];
10053 ++idx;
10054 }
10055
10056 /* only when there are no errors, wim_flags[] is changed */
10057 for (i = 0; i < 4; ++i)
10058 wim_flags[i] = new_wim_flags[i];
10059 return OK;
10060}
10061
10062/*
10063 * Check if backspacing over something is allowed.
10064 */
10065 int
10066can_bs(what)
10067 int what; /* BS_INDENT, BS_EOL or BS_START */
10068{
10069 switch (*p_bs)
10070 {
10071 case '2': return TRUE;
10072 case '1': return (what != BS_START);
10073 case '0': return FALSE;
10074 }
10075 return vim_strchr(p_bs, what) != NULL;
10076}
10077
10078/*
10079 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10080 * the file must be considered changed when the value is different.
10081 */
10082 void
10083save_file_ff(buf)
10084 buf_T *buf;
10085{
10086 buf->b_start_ffc = *buf->b_p_ff;
10087 buf->b_start_eol = buf->b_p_eol;
10088#ifdef FEAT_MBYTE
10089 /* Only use free/alloc when necessary, they take time. */
10090 if (buf->b_start_fenc == NULL
10091 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10092 {
10093 vim_free(buf->b_start_fenc);
10094 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10095 }
10096#endif
10097}
10098
10099/*
10100 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10101 * from when editing started (save_file_ff() called).
10102 * Also when 'endofline' was changed and 'binary' is set.
10103 * Don't consider a new, empty buffer to be changed.
10104 */
10105 int
10106file_ff_differs(buf)
10107 buf_T *buf;
10108{
10109 if ((buf->b_flags & BF_NEW)
10110 && buf->b_ml.ml_line_count == 1
10111 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10112 return FALSE;
10113 if (buf->b_start_ffc != *buf->b_p_ff)
10114 return TRUE;
10115 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10116 return TRUE;
10117#ifdef FEAT_MBYTE
10118 if (buf->b_start_fenc == NULL)
10119 return (*buf->b_p_fenc != NUL);
10120 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10121#else
10122 return FALSE;
10123#endif
10124}
10125
10126/*
10127 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10128 */
10129 int
10130check_ff_value(p)
10131 char_u *p;
10132{
10133 return check_opt_strings(p, p_ff_values, FALSE);
10134}