blob: 192500010fdb0c91a4e128b546bcc6d95d9edeb4 [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 Moolenaarfaa959a2006-02-20 21:37:40 +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,*:TabLine,#:TabLineSel,_:TabLineFill",
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}},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002049 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2050#ifdef FEAT_WINDOWS
2051 (char_u *)&p_stal, PV_NONE,
2052#else
2053 (char_u *)NULL, PV_NONE,
2054#endif
2055 {(char_u *)1L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2057 (char_u *)&p_ss, PV_NONE,
2058 {(char_u *)0L, (char_u *)0L}},
2059 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2060 (char_u *)&p_siso, PV_NONE,
2061 {(char_u *)0L, (char_u *)0L}},
2062 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2063 (char_u *)NULL, PV_NONE,
2064 {(char_u *)FALSE, (char_u *)0L}},
2065 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2066 (char_u *)&p_scs, PV_NONE,
2067 {(char_u *)FALSE, (char_u *)0L}},
2068 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2069#ifdef FEAT_SMARTINDENT
2070 (char_u *)&p_si, PV_SI,
2071#else
2072 (char_u *)NULL, PV_NONE,
2073#endif
2074 {(char_u *)FALSE, (char_u *)0L}},
2075 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2076 (char_u *)&p_sta, PV_NONE,
2077 {(char_u *)FALSE, (char_u *)0L}},
2078 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2079 (char_u *)&p_sts, PV_STS,
2080 {(char_u *)0L, (char_u *)0L}},
2081 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2082 (char_u *)NULL, PV_NONE,
2083 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002084 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2085#ifdef FEAT_SYN_HL
2086 (char_u *)VAR_WIN, PV_SPELL,
2087#else
2088 (char_u *)NULL, PV_NONE,
2089#endif
2090 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002091 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002092#ifdef FEAT_SYN_HL
2093 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002094 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002095#else
2096 (char_u *)NULL, PV_NONE,
2097 {(char_u *)0L, (char_u *)0L}
2098#endif
2099 },
2100 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002101#ifdef FEAT_SYN_HL
2102 (char_u *)&p_spf, PV_SPF,
2103 {(char_u *)"", (char_u *)0L}
2104#else
2105 (char_u *)NULL, PV_NONE,
2106 {(char_u *)0L, (char_u *)0L}
2107#endif
2108 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002109 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaar217ad922005-03-20 22:37:15 +00002110#ifdef FEAT_SYN_HL
2111 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002112 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002113#else
2114 (char_u *)NULL, PV_NONE,
2115 {(char_u *)0L, (char_u *)0L}
2116#endif
2117 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002118 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002119#ifdef FEAT_SYN_HL
2120 (char_u *)&p_sps, PV_NONE,
2121 {(char_u *)"best", (char_u *)0L}
2122#else
2123 (char_u *)NULL, PV_NONE,
2124 {(char_u *)0L, (char_u *)0L}
2125#endif
2126 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2128#ifdef FEAT_WINDOWS
2129 (char_u *)&p_sb, PV_NONE,
2130#else
2131 (char_u *)NULL, PV_NONE,
2132#endif
2133 {(char_u *)FALSE, (char_u *)0L}},
2134 {"splitright", "spr", P_BOOL|P_VI_DEF,
2135#ifdef FEAT_VERTSPLIT
2136 (char_u *)&p_spr, PV_NONE,
2137#else
2138 (char_u *)NULL, PV_NONE,
2139#endif
2140 {(char_u *)FALSE, (char_u *)0L}},
2141 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2142 (char_u *)&p_sol, PV_NONE,
2143 {(char_u *)TRUE, (char_u *)0L}},
2144 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2145#ifdef FEAT_STL_OPT
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002146 (char_u *)&p_stl, OPT_BOTH(PV_STL),
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147#else
2148 (char_u *)NULL, PV_NONE,
2149#endif
2150 {(char_u *)"", (char_u *)0L}},
2151 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2152 (char_u *)&p_su, PV_NONE,
2153 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2154 (char_u *)0L}},
2155 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
2156#if defined(FEAT_SEARCHPATH)
2157 (char_u *)&p_sua, PV_SUA,
2158 {(char_u *)"", (char_u *)0L}
2159#else
2160 (char_u *)NULL, PV_NONE,
2161 {(char_u *)0L, (char_u *)0L}
2162#endif
2163 },
2164 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2165 (char_u *)&p_swf, PV_SWF,
2166 {(char_u *)TRUE, (char_u *)0L}},
2167 {"swapsync", "sws", P_STRING|P_VI_DEF,
2168 (char_u *)&p_sws, PV_NONE,
2169 {(char_u *)"fsync", (char_u *)0L}},
2170 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2171 (char_u *)&p_swb, PV_NONE,
2172 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002173 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2174#ifdef FEAT_SYN_HL
2175 (char_u *)&p_smc, PV_SMC,
2176 {(char_u *)3000L, (char_u *)0L}
2177#else
2178 (char_u *)NULL, PV_NONE,
2179 {(char_u *)0L, (char_u *)0L}
2180#endif
2181 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002182 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183#ifdef FEAT_SYN_HL
2184 (char_u *)&p_syn, PV_SYN,
2185 {(char_u *)"", (char_u *)0L}
2186#else
2187 (char_u *)NULL, PV_NONE,
2188 {(char_u *)0L, (char_u *)0L}
2189#endif
2190 },
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002191 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2192#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002193 (char_u *)&p_tal, PV_NONE,
2194#else
2195 (char_u *)NULL, PV_NONE,
2196#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002197 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002198 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2199 (char_u *)&p_ts, PV_TS,
2200 {(char_u *)8L, (char_u *)0L}},
2201 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2202 (char_u *)&p_tbs, PV_NONE,
2203#ifdef VMS /* binary searching doesn't appear to work on VMS */
2204 {(char_u *)0L, (char_u *)0L}
2205#else
2206 {(char_u *)TRUE, (char_u *)0L}
2207#endif
2208 },
2209 {"taglength", "tl", P_NUM|P_VI_DEF,
2210 (char_u *)&p_tl, PV_NONE,
2211 {(char_u *)0L, (char_u *)0L}},
2212 {"tagrelative", "tr", P_BOOL|P_VIM,
2213 (char_u *)&p_tr, PV_NONE,
2214 {(char_u *)FALSE, (char_u *)TRUE}},
2215 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2216 (char_u *)&p_tags, OPT_BOTH(PV_TAGS),
2217 {
2218#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2219 (char_u *)"./tags,./TAGS,tags,TAGS",
2220#else
2221 (char_u *)"./tags,tags",
2222#endif
2223 (char_u *)0L}},
2224 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2225 (char_u *)&p_tgst, PV_NONE,
2226 {(char_u *)TRUE, (char_u *)0L}},
2227 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2228 (char_u *)&T_NAME, PV_NONE,
2229 {(char_u *)"", (char_u *)0L}},
2230 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2231#ifdef FEAT_ARABIC
2232 (char_u *)&p_tbidi, PV_NONE,
2233#else
2234 (char_u *)NULL, PV_NONE,
2235#endif
2236 {(char_u *)FALSE, (char_u *)0L}},
2237 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2238#ifdef FEAT_MBYTE
2239 (char_u *)&p_tenc, PV_NONE,
2240 {(char_u *)"", (char_u *)0L}
2241#else
2242 (char_u *)NULL, PV_NONE,
2243 {(char_u *)0L, (char_u *)0L}
2244#endif
2245 },
2246 {"terse", NULL, P_BOOL|P_VI_DEF,
2247 (char_u *)&p_terse, PV_NONE,
2248 {(char_u *)FALSE, (char_u *)0L}},
2249 {"textauto", "ta", P_BOOL|P_VIM,
2250 (char_u *)&p_ta, PV_NONE,
2251 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2252 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2253 (char_u *)&p_tx, PV_TX,
2254 {
2255#ifdef USE_CRNL
2256 (char_u *)TRUE,
2257#else
2258 (char_u *)FALSE,
2259#endif
2260 (char_u *)0L}},
2261 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2262 (char_u *)&p_tw, PV_TW,
2263 {(char_u *)0L, (char_u *)0L}},
2264 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2265#ifdef FEAT_INS_EXPAND
2266 (char_u *)&p_tsr, OPT_BOTH(PV_TSR),
2267#else
2268 (char_u *)NULL, PV_NONE,
2269#endif
2270 {(char_u *)"", (char_u *)0L}},
2271 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2272 (char_u *)&p_to, PV_NONE,
2273 {(char_u *)FALSE, (char_u *)0L}},
2274 {"timeout", "to", P_BOOL|P_VI_DEF,
2275 (char_u *)&p_timeout, PV_NONE,
2276 {(char_u *)TRUE, (char_u *)0L}},
2277 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2278 (char_u *)&p_tm, PV_NONE,
2279 {(char_u *)1000L, (char_u *)0L}},
2280 {"title", NULL, P_BOOL|P_VI_DEF,
2281#ifdef FEAT_TITLE
2282 (char_u *)&p_title, PV_NONE,
2283#else
2284 (char_u *)NULL, PV_NONE,
2285#endif
2286 {(char_u *)FALSE, (char_u *)0L}},
2287 {"titlelen", NULL, P_NUM|P_VI_DEF,
2288#ifdef FEAT_TITLE
2289 (char_u *)&p_titlelen, PV_NONE,
2290#else
2291 (char_u *)NULL, PV_NONE,
2292#endif
2293 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002294 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295#ifdef FEAT_TITLE
2296 (char_u *)&p_titleold, PV_NONE,
2297 {(char_u *)N_("Thanks for flying Vim"),
2298 (char_u *)0L}
2299#else
2300 (char_u *)NULL, PV_NONE,
2301 {(char_u *)0L, (char_u *)0L}
2302#endif
2303 },
2304 {"titlestring", NULL, P_STRING|P_VI_DEF,
2305#ifdef FEAT_TITLE
2306 (char_u *)&p_titlestring, PV_NONE,
2307#else
2308 (char_u *)NULL, PV_NONE,
2309#endif
2310 {(char_u *)"", (char_u *)0L}},
2311#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2312 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2313 (char_u *)&p_toolbar, PV_NONE,
2314 {(char_u *)"icons,tooltips", (char_u *)0L}},
2315#endif
2316#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2317 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2318 (char_u *)&p_tbis, PV_NONE,
2319 {(char_u *)"small", (char_u *)0L}},
2320#endif
2321 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2322 (char_u *)&p_ttimeout, PV_NONE,
2323 {(char_u *)FALSE, (char_u *)0L}},
2324 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2325 (char_u *)&p_ttm, PV_NONE,
2326 {(char_u *)-1L, (char_u *)0L}},
2327 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2328 (char_u *)&p_tbi, PV_NONE,
2329 {(char_u *)TRUE, (char_u *)0L}},
2330 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2331 (char_u *)&p_tf, PV_NONE,
2332 {(char_u *)FALSE, (char_u *)0L}},
2333 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2334#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2335 (char_u *)&p_ttym, PV_NONE,
2336#else
2337 (char_u *)NULL, PV_NONE,
2338#endif
2339 {(char_u *)"", (char_u *)0L}},
2340 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2341 (char_u *)&p_ttyscroll, PV_NONE,
2342 {(char_u *)999L, (char_u *)0L}},
2343 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2344 (char_u *)&T_NAME, PV_NONE,
2345 {(char_u *)"", (char_u *)0L}},
2346 {"undolevels", "ul", P_NUM|P_VI_DEF,
2347 (char_u *)&p_ul, PV_NONE,
2348 {
2349#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2350 (char_u *)1000L,
2351#else
2352 (char_u *)100L,
2353#endif
2354 (char_u *)0L}},
2355 {"updatecount", "uc", P_NUM|P_VI_DEF,
2356 (char_u *)&p_uc, PV_NONE,
2357 {(char_u *)200L, (char_u *)0L}},
2358 {"updatetime", "ut", P_NUM|P_VI_DEF,
2359 (char_u *)&p_ut, PV_NONE,
2360 {(char_u *)4000L, (char_u *)0L}},
2361 {"verbose", "vbs", P_NUM|P_VI_DEF,
2362 (char_u *)&p_verbose, PV_NONE,
2363 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002364 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2365 (char_u *)&p_vfile, PV_NONE,
2366 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2368#ifdef FEAT_SESSION
2369 (char_u *)&p_vdir, PV_NONE,
2370 {(char_u *)DFLT_VDIR, (char_u *)0L}
2371#else
2372 (char_u *)NULL, PV_NONE,
2373 {(char_u *)0L, (char_u *)0L}
2374#endif
2375 },
2376 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2377#ifdef FEAT_SESSION
2378 (char_u *)&p_vop, PV_NONE,
2379 {(char_u *)"folds,options,cursor", (char_u *)0L}
2380#else
2381 (char_u *)NULL, PV_NONE,
2382 {(char_u *)0L, (char_u *)0L}
2383#endif
2384 },
2385 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2386#ifdef FEAT_VIMINFO
2387 (char_u *)&p_viminfo, PV_NONE,
2388#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2389 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2390#else
2391# ifdef AMIGA
2392 {(char_u *)"",
2393 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2394# else
2395 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2396# endif
2397#endif
2398#else
2399 (char_u *)NULL, PV_NONE,
2400 {(char_u *)0L, (char_u *)0L}
2401#endif
2402 },
2403 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2404#ifdef FEAT_VIRTUALEDIT
2405 (char_u *)&p_ve, PV_NONE,
2406 {(char_u *)"", (char_u *)""}
2407#else
2408 (char_u *)NULL, PV_NONE,
2409 {(char_u *)0L, (char_u *)0L}
2410#endif
2411 },
2412 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2413 (char_u *)&p_vb, PV_NONE,
2414 {(char_u *)FALSE, (char_u *)0L}},
2415 {"w300", NULL, P_NUM|P_VI_DEF,
2416 (char_u *)NULL, PV_NONE,
2417 {(char_u *)0L, (char_u *)0L}},
2418 {"w1200", NULL, P_NUM|P_VI_DEF,
2419 (char_u *)NULL, PV_NONE,
2420 {(char_u *)0L, (char_u *)0L}},
2421 {"w9600", NULL, P_NUM|P_VI_DEF,
2422 (char_u *)NULL, PV_NONE,
2423 {(char_u *)0L, (char_u *)0L}},
2424 {"warn", NULL, P_BOOL|P_VI_DEF,
2425 (char_u *)&p_warn, PV_NONE,
2426 {(char_u *)TRUE, (char_u *)0L}},
2427 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2428 (char_u *)&p_wiv, PV_NONE,
2429 {(char_u *)FALSE, (char_u *)0L}},
2430 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2431 (char_u *)&p_ww, PV_NONE,
2432 {(char_u *)"", (char_u *)"b,s"}},
2433 {"wildchar", "wc", P_NUM|P_VIM,
2434 (char_u *)&p_wc, PV_NONE,
2435 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2436 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2437 (char_u *)&p_wcm, PV_NONE,
2438 {(char_u *)0L, (char_u *)0L}},
2439 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2440#ifdef FEAT_WILDIGN
2441 (char_u *)&p_wig, PV_NONE,
2442#else
2443 (char_u *)NULL, PV_NONE,
2444#endif
2445 {(char_u *)"", (char_u *)0L}},
2446 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2447#ifdef FEAT_WILDMENU
2448 (char_u *)&p_wmnu, PV_NONE,
2449#else
2450 (char_u *)NULL, PV_NONE,
2451#endif
2452 {(char_u *)FALSE, (char_u *)0L}},
2453 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2454 (char_u *)&p_wim, PV_NONE,
2455 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002456 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2457#ifdef FEAT_CMDL_COMPL
2458 (char_u *)&p_wop, PV_NONE,
2459 {(char_u *)"", (char_u *)0L}
2460#else
2461 (char_u *)NULL, PV_NONE,
2462 {(char_u *)NULL, (char_u *)0L}
2463#endif
2464 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2466#ifdef FEAT_WAK
2467 (char_u *)&p_wak, PV_NONE,
2468 {(char_u *)"menu", (char_u *)0L}
2469#else
2470 (char_u *)NULL, PV_NONE,
2471 {(char_u *)NULL, (char_u *)0L}
2472#endif
2473 },
2474 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002475 (char_u *)&p_window, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {(char_u *)0L, (char_u *)0L}},
2477 {"winheight", "wh", P_NUM|P_VI_DEF,
2478#ifdef FEAT_WINDOWS
2479 (char_u *)&p_wh, PV_NONE,
2480#else
2481 (char_u *)NULL, PV_NONE,
2482#endif
2483 {(char_u *)1L, (char_u *)0L}},
2484 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
2485#if defined(FEAT_WINDOWS)
2486 (char_u *)VAR_WIN, PV_WFH,
2487#else
2488 (char_u *)NULL, PV_NONE,
2489#endif
2490 {(char_u *)FALSE, (char_u *)0L}},
2491 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2492#ifdef FEAT_WINDOWS
2493 (char_u *)&p_wmh, PV_NONE,
2494#else
2495 (char_u *)NULL, PV_NONE,
2496#endif
2497 {(char_u *)1L, (char_u *)0L}},
2498 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2499#ifdef FEAT_VERTSPLIT
2500 (char_u *)&p_wmw, PV_NONE,
2501#else
2502 (char_u *)NULL, PV_NONE,
2503#endif
2504 {(char_u *)1L, (char_u *)0L}},
2505 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2506#ifdef FEAT_VERTSPLIT
2507 (char_u *)&p_wiw, PV_NONE,
2508#else
2509 (char_u *)NULL, PV_NONE,
2510#endif
2511 {(char_u *)20L, (char_u *)0L}},
2512 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2513 (char_u *)VAR_WIN, PV_WRAP,
2514 {(char_u *)TRUE, (char_u *)0L}},
2515 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2516 (char_u *)&p_wm, PV_WM,
2517 {(char_u *)0L, (char_u *)0L}},
2518 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2519 (char_u *)&p_ws, PV_NONE,
2520 {(char_u *)TRUE, (char_u *)0L}},
2521 {"write", NULL, P_BOOL|P_VI_DEF,
2522 (char_u *)&p_write, PV_NONE,
2523 {(char_u *)TRUE, (char_u *)0L}},
2524 {"writeany", "wa", P_BOOL|P_VI_DEF,
2525 (char_u *)&p_wa, PV_NONE,
2526 {(char_u *)FALSE, (char_u *)0L}},
2527 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2528 (char_u *)&p_wb, PV_NONE,
2529 {
2530#ifdef FEAT_WRITEBACKUP
2531 (char_u *)TRUE,
2532#else
2533 (char_u *)FALSE,
2534#endif
2535 (char_u *)0L}},
2536 {"writedelay", "wd", P_NUM|P_VI_DEF,
2537 (char_u *)&p_wd, PV_NONE,
2538 {(char_u *)0L, (char_u *)0L}},
2539
2540/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002541#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 (char_u *)&vvv, PV_NONE, \
2543 {(char_u *)"", (char_u *)0L}},
2544
2545 p_term("t_AB", T_CAB)
2546 p_term("t_AF", T_CAF)
2547 p_term("t_AL", T_CAL)
2548 p_term("t_al", T_AL)
2549 p_term("t_bc", T_BC)
2550 p_term("t_cd", T_CD)
2551 p_term("t_ce", T_CE)
2552 p_term("t_cl", T_CL)
2553 p_term("t_cm", T_CM)
2554 p_term("t_Co", T_CCO)
2555 p_term("t_CS", T_CCS)
2556 p_term("t_cs", T_CS)
2557#ifdef FEAT_VERTSPLIT
2558 p_term("t_CV", T_CSV)
2559#endif
2560 p_term("t_ut", T_UT)
2561 p_term("t_da", T_DA)
2562 p_term("t_db", T_DB)
2563 p_term("t_DL", T_CDL)
2564 p_term("t_dl", T_DL)
2565 p_term("t_fs", T_FS)
2566 p_term("t_IE", T_CIE)
2567 p_term("t_IS", T_CIS)
2568 p_term("t_ke", T_KE)
2569 p_term("t_ks", T_KS)
2570 p_term("t_le", T_LE)
2571 p_term("t_mb", T_MB)
2572 p_term("t_md", T_MD)
2573 p_term("t_me", T_ME)
2574 p_term("t_mr", T_MR)
2575 p_term("t_ms", T_MS)
2576 p_term("t_nd", T_ND)
2577 p_term("t_op", T_OP)
2578 p_term("t_RI", T_CRI)
2579 p_term("t_RV", T_CRV)
2580 p_term("t_Sb", T_CSB)
2581 p_term("t_Sf", T_CSF)
2582 p_term("t_se", T_SE)
2583 p_term("t_so", T_SO)
2584 p_term("t_sr", T_SR)
2585 p_term("t_ts", T_TS)
2586 p_term("t_te", T_TE)
2587 p_term("t_ti", T_TI)
2588 p_term("t_ue", T_UE)
2589 p_term("t_us", T_US)
2590 p_term("t_vb", T_VB)
2591 p_term("t_ve", T_VE)
2592 p_term("t_vi", T_VI)
2593 p_term("t_vs", T_VS)
2594 p_term("t_WP", T_CWP)
2595 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002596 p_term("t_SI", T_CSI)
2597 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 p_term("t_xs", T_XS)
2599 p_term("t_ZH", T_CZH)
2600 p_term("t_ZR", T_CZR)
2601
2602/* terminal key codes are not in here */
2603
2604 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2605};
2606
2607#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2608
2609#ifdef FEAT_MBYTE
2610static char *(p_ambw_values[]) = {"single", "double", NULL};
2611#endif
2612static char *(p_bg_values[]) = {"light", "dark", NULL};
2613static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2614static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002615#ifdef FEAT_CMDL_COMPL
2616static char *(p_wop_values[]) = {"tagfile", NULL};
2617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618#ifdef FEAT_WAK
2619static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2620#endif
2621static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2622#ifdef FEAT_VISUAL
2623static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2624static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2625#endif
2626#ifdef FEAT_VISUAL
2627static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2628#endif
2629#ifdef FEAT_BROWSE
2630static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2631#endif
2632#ifdef FEAT_SCROLLBIND
2633static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2634#endif
2635static char *(p_swb_values[]) = {"useopen", "split", NULL};
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002636static char *(p_debug_values[]) = {"msg", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637#ifdef FEAT_VERTSPLIT
2638static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2639#endif
2640#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002641# ifdef FEAT_AUTOCMD
2642static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2643# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002645# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2647#endif
2648static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2649#ifdef FEAT_FOLDING
2650static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002651# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002653# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 NULL};
2655static char *(p_fcl_values[]) = {"all", NULL};
2656#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002657#ifdef FEAT_INS_EXPAND
Bram Moolenaarc7453f52006-02-10 23:20:28 +00002658static char *(p_cot_values[]) = {"menu", "longest", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002659#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660
2661static void set_option_default __ARGS((int, int opt_flags, int compatible));
2662static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002663static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002664static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665static char_u *illegal_char __ARGS((char_u *, int));
2666static int string_to_key __ARGS((char_u *arg));
2667#ifdef FEAT_CMDWIN
2668static char_u *check_cedit __ARGS((void));
2669#endif
2670#ifdef FEAT_TITLE
2671static void did_set_title __ARGS((int icon));
2672#endif
2673static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2674static void didset_options __ARGS((void));
2675static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002676#if defined(FEAT_EVAL) || defined(PROTO)
2677static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2678#else
2679# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2682static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2683static 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));
2684static char_u *set_chars_option __ARGS((char_u **varp));
2685#ifdef FEAT_CLIPBOARD
2686static char_u *check_clipboard_option __ARGS((void));
2687#endif
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002688#ifdef FEAT_SYN_HL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002689static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002690#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002692static 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 +00002693static void check_redraw __ARGS((long_u flags));
2694static int findoption __ARGS((char_u *));
2695static int find_key_option __ARGS((char_u *));
2696static void showoptions __ARGS((int all, int opt_flags));
2697static int optval_default __ARGS((struct vimoption *, char_u *varp));
2698static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2699static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2700static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2701static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2702static int istermoption __ARGS((struct vimoption *));
2703static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2704static char_u *get_varp __ARGS((struct vimoption *));
2705static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2706static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2707#ifdef FEAT_LANGMAP
2708static void langmap_init __ARGS((void));
2709static void langmap_set __ARGS((void));
2710#endif
2711static void paste_option_changed __ARGS((void));
2712static void compatible_set __ARGS((void));
2713#ifdef FEAT_LINEBREAK
2714static void fill_breakat_flags __ARGS((void));
2715#endif
2716static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2717static int check_opt_strings __ARGS((char_u *val, char **values, int));
2718static int check_opt_wim __ARGS((void));
2719
2720/*
2721 * Initialize the options, first part.
2722 *
2723 * Called only once from main(), just after creating the first buffer.
2724 */
2725 void
2726set_init_1()
2727{
2728 char_u *p;
2729 int opt_idx;
2730 long n;
2731
2732#ifdef FEAT_LANGMAP
2733 langmap_init();
2734#endif
2735
2736 /* Be Vi compatible by default */
2737 p_cp = TRUE;
2738
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002739 /* Use POSIX compatibility when $VIM_POSIX is set. */
2740 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002741 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002742 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002743 set_string_default("shm", (char_u *)"A");
2744 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002745
Bram Moolenaar071d4272004-06-13 20:20:40 +00002746 /*
2747 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002748 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002749 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002750 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2752# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002753 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002755 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002757 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758# endif
2759#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002760 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 set_string_default("sh", p);
2762
2763#ifdef FEAT_WILDIGN
2764 /*
2765 * Set the default for 'backupskip' to include environment variables for
2766 * temp files.
2767 */
2768 {
2769# ifdef UNIX
2770 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2771# else
2772 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2773# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002774 int len;
2775 garray_T ga;
2776 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777
2778 ga_init2(&ga, 1, 100);
2779 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2780 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002781 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782# ifdef UNIX
2783 if (*names[n] == NUL)
2784 p = (char_u *)"/tmp";
2785 else
2786# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002787 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 if (p != NULL && *p != NUL)
2789 {
2790 /* First time count the NUL, otherwise count the ','. */
2791 len = STRLEN(p) + 3;
2792 if (ga_grow(&ga, len) == OK)
2793 {
2794 if (ga.ga_len > 0)
2795 STRCAT(ga.ga_data, ",");
2796 STRCAT(ga.ga_data, p);
2797 add_pathsep(ga.ga_data);
2798 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 ga.ga_len += len;
2800 }
2801 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002802 if (mustfree)
2803 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 }
2805 if (ga.ga_data != NULL)
2806 {
2807 set_string_default("bsk", ga.ga_data);
2808 vim_free(ga.ga_data);
2809 }
2810 }
2811#endif
2812
2813 /*
2814 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2815 */
2816 opt_idx = findoption((char_u *)"maxmemtot");
2817#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2818 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2819#endif
2820 {
2821#ifdef HAVE_AVAIL_MEM
2822 /* Use amount of memory available at this moment. */
2823 n = (mch_avail_mem(FALSE) >> 11);
2824#else
2825# ifdef HAVE_TOTAL_MEM
2826 /* Use amount of memory available to Vim. */
2827 n = (mch_total_mem(FALSE) >> 11);
2828# else
2829 n = (0x7fffffff >> 11);
2830# endif
2831#endif
2832 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2833 opt_idx = findoption((char_u *)"maxmem");
2834#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2835 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2836 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2837#endif
2838 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2839 }
2840
2841#ifdef FEAT_GUI_W32
2842 /* force 'shortname' for Win32s */
2843 if (gui_is_win32s())
2844 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2845 (char_u *)TRUE;
2846#endif
2847
2848#ifdef FEAT_SEARCHPATH
2849 {
2850 char_u *cdpath;
2851 char_u *buf;
2852 int i;
2853 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002854 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855
2856 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00002857 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 if (cdpath != NULL)
2859 {
2860 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2861 if (buf != NULL)
2862 {
2863 buf[0] = ','; /* start with ",", current dir first */
2864 j = 1;
2865 for (i = 0; cdpath[i] != NUL; ++i)
2866 {
2867 if (vim_ispathlistsep(cdpath[i]))
2868 buf[j++] = ',';
2869 else
2870 {
2871 if (cdpath[i] == ' ' || cdpath[i] == ',')
2872 buf[j++] = '\\';
2873 buf[j++] = cdpath[i];
2874 }
2875 }
2876 buf[j] = NUL;
2877 opt_idx = findoption((char_u *)"cdpath");
2878 options[opt_idx].def_val[VI_DEFAULT] = buf;
2879 options[opt_idx].flags |= P_DEF_ALLOCED;
2880 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002881 if (mustfree)
2882 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 }
2884 }
2885#endif
2886
2887#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2888 /* Set print encoding on platforms that don't default to latin1 */
2889 set_string_default("penc",
2890# if defined(MSWIN) || defined(OS2)
2891 (char_u *)"cp1252"
2892# else
2893# ifdef VMS
2894 (char_u *)"dec-mcs"
2895# else
2896# ifdef EBCDIC
2897 (char_u *)"ebcdic-uk"
2898# else
2899# ifdef MAC
2900 (char_u *)"mac-roman"
2901# else /* HPUX */
2902 (char_u *)"hp-roman8"
2903# endif
2904# endif
2905# endif
2906# endif
2907 );
2908#endif
2909
2910#ifdef FEAT_POSTSCRIPT
2911 /* 'printexpr' must be allocated to be able to evaluate it. */
2912 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00002913# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
2914 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915# else
2916# ifdef VMS
2917 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
2918
2919# else
2920 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
2921# endif
2922# endif
2923 );
2924#endif
2925
2926 /*
2927 * Set all the options (except the terminal options) to their default
2928 * value. Also set the global value for local options.
2929 */
2930 set_options_default(0);
2931
2932#ifdef FEAT_GUI
2933 if (found_reverse_arg)
2934 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
2935#endif
2936
2937 curbuf->b_p_initialized = TRUE;
2938 curbuf->b_p_ar = -1; /* no local 'autoread' value */
2939 check_buf_options(curbuf);
2940 check_win_options(curwin);
2941 check_options();
2942
2943 /* Must be before option_expand(), because that one needs vim_isIDc() */
2944 didset_options();
2945
Bram Moolenaar6bb68362005-03-22 23:03:44 +00002946#ifdef FEAT_SYN_HL
2947 /* Use the current chartab for the generic chartab. */
2948 init_spell_chartab();
2949#endif
2950
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951#ifdef FEAT_LINEBREAK
2952 /*
2953 * initialize the table for 'breakat'.
2954 */
2955 fill_breakat_flags();
2956#endif
2957
2958 /*
2959 * Expand environment variables and things like "~" for the defaults.
2960 * If option_expand() returns non-NULL the variable is expanded. This can
2961 * only happen for non-indirect options.
2962 * Also set the default to the expanded value, so ":set" does not list
2963 * them.
2964 * Don't set the P_ALLOCED flag, because we don't want to free the
2965 * default.
2966 */
2967 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
2968 {
2969 if ((options[opt_idx].flags & P_GETTEXT)
2970 && options[opt_idx].var != NULL)
2971 p = (char_u *)_(*(char **)options[opt_idx].var);
2972 else
2973 p = option_expand(opt_idx, NULL);
2974 if (p != NULL && (p = vim_strsave(p)) != NULL)
2975 {
2976 *(char_u **)options[opt_idx].var = p;
2977 /* VIMEXP
2978 * Defaults for all expanded options are currently the same for Vi
2979 * and Vim. When this changes, add some code here! Also need to
2980 * split P_DEF_ALLOCED in two.
2981 */
2982 if (options[opt_idx].flags & P_DEF_ALLOCED)
2983 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2984 options[opt_idx].def_val[VI_DEFAULT] = p;
2985 options[opt_idx].flags |= P_DEF_ALLOCED;
2986 }
2987 }
2988
2989 /* Initialize the highlight_attr[] table. */
2990 highlight_changed();
2991
2992 save_file_ff(curbuf); /* Buffer is unchanged */
2993
2994 /* Parse default for 'wildmode' */
2995 check_opt_wim();
2996
2997#if defined(FEAT_ARABIC)
2998 /* Detect use of mlterm.
2999 * Mlterm is a terminal emulator akin to xterm that has some special
3000 * abilities (bidi namely).
3001 * NOTE: mlterm's author is being asked to 'set' a variable
3002 * instead of an environment variable due to inheritance.
3003 */
3004 if (mch_getenv((char_u *)"MLTERM") != NULL)
3005 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3006#endif
3007
3008#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3009 /* Parse default for 'fillchars'. */
3010 (void)set_chars_option(&p_fcs);
3011#endif
3012
3013#ifdef FEAT_CLIPBOARD
3014 /* Parse default for 'clipboard' */
3015 (void)check_clipboard_option();
3016#endif
3017
3018#ifdef FEAT_MBYTE
3019# if defined(WIN3264) && defined(FEAT_GETTEXT)
3020 /*
3021 * If $LANG isn't set, try to get a good value for it. This makes the
3022 * right language be used automatically. Don't do this for English.
3023 */
3024 if (mch_getenv((char_u *)"LANG") == NULL)
3025 {
3026 char buf[20];
3027
3028 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3029 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3030 * only the first two. */
3031 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3032 (LPTSTR)buf, 20);
3033 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3034 {
3035 /* There are a few exceptions (probably more) */
3036 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3037 STRCPY(buf, "zh_TW");
3038 else if (STRNICMP(buf, "chs", 3) == 0
3039 || STRNICMP(buf, "zhc", 3) == 0)
3040 STRCPY(buf, "zh_CN");
3041 else if (STRNICMP(buf, "jp", 2) == 0)
3042 STRCPY(buf, "ja");
3043 else
3044 buf[2] = NUL; /* truncate to two-letter code */
3045 vim_setenv("LANG", buf);
3046 }
3047 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003048# else
3049# ifdef MACOS
3050 if (mch_getenv((char_u *)"LANG") == NULL)
3051 {
3052 char buf[20];
3053 if (LocaleRefGetPartString(NULL,
3054 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3055 kLocaleRegionMask | kLocaleRegionVariantMask,
3056 sizeof buf, buf) == noErr && *buf)
3057 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003058 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003059# ifdef HAVE_LOCALE_H
3060 setlocale(LC_ALL, "");
3061# endif
3062 }
3063 }
3064# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065# endif
3066
3067 /* enc_locale() will try to find the encoding of the current locale. */
3068 p = enc_locale();
3069 if (p != NULL)
3070 {
3071 char_u *save_enc;
3072
3073 /* Try setting 'encoding' and check if the value is valid.
3074 * If not, go back to the default "latin1". */
3075 save_enc = p_enc;
3076 p_enc = p;
3077 if (mb_init() == NULL)
3078 {
3079 opt_idx = findoption((char_u *)"encoding");
3080 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3081 options[opt_idx].flags |= P_DEF_ALLOCED;
3082
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003083#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3084 || defined(VMS)
3085 if (STRCMP(p_enc, "latin1") == 0
3086# ifdef FEAT_MBYTE
3087 || enc_utf8
3088# endif
3089 )
3090 {
3091 /* Adjust the default for 'isprint' to match latin1. */
3092 set_string_option_direct((char_u *)"isp", -1,
3093 (char_u *)"@,161-255", OPT_FREE);
3094 (void)init_chartab();
3095 }
3096#endif
3097
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098# if defined(WIN3264) && !defined(FEAT_GUI)
3099 /* Win32 console: When GetACP() returns a different value from
3100 * GetConsoleCP() set 'termencoding'. */
3101 if (GetACP() != GetConsoleCP())
3102 {
3103 char buf[50];
3104
3105 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3106 p_tenc = vim_strsave((char_u *)buf);
3107 if (p_tenc != NULL)
3108 {
3109 opt_idx = findoption((char_u *)"termencoding");
3110 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3111 options[opt_idx].flags |= P_DEF_ALLOCED;
3112 convert_setup(&input_conv, p_tenc, p_enc);
3113 convert_setup(&output_conv, p_enc, p_tenc);
3114 }
3115 else
3116 p_tenc = empty_option;
3117 }
3118# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003119# if defined(WIN3264) && defined(FEAT_MBYTE)
3120 /* $HOME may have characters in active code page. */
3121 init_homedir();
3122# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 }
3124 else
3125 {
3126 vim_free(p_enc);
3127 p_enc = save_enc;
3128 }
3129 }
3130#endif
3131
3132#ifdef FEAT_MULTI_LANG
3133 /* Set the default for 'helplang'. */
3134 set_helplang_default(get_mess_lang());
3135#endif
3136}
3137
3138/*
3139 * Set an option to its default value.
3140 * This does not take care of side effects!
3141 */
3142 static void
3143set_option_default(opt_idx, opt_flags, compatible)
3144 int opt_idx;
3145 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3146 int compatible; /* use Vi default value */
3147{
3148 char_u *varp; /* pointer to variable for current option */
3149 int dvi; /* index in def_val[] */
3150 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003151 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3153
3154 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3155 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003156 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 {
3158 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3159 if (flags & P_STRING)
3160 {
3161 /* Use set_string_option_direct() for local options to handle
3162 * freeing and allocating the value. */
3163 if (options[opt_idx].indir != PV_NONE)
3164 set_string_option_direct(NULL, opt_idx,
3165 options[opt_idx].def_val[dvi], opt_flags);
3166 else
3167 {
3168 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3169 free_string_option(*(char_u **)(varp));
3170 *(char_u **)varp = options[opt_idx].def_val[dvi];
3171 options[opt_idx].flags &= ~P_ALLOCED;
3172 }
3173 }
3174 else if (flags & P_NUM)
3175 {
3176 if (varp == (char_u *)PV_SCROLL)
3177 win_comp_scroll(curwin);
3178 else
3179 {
3180 *(long *)varp = (long)options[opt_idx].def_val[dvi];
3181 /* May also set global value for local option. */
3182 if (both)
3183 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3184 *(long *)varp;
3185 }
3186 }
3187 else /* P_BOOL */
3188 {
3189 /* the cast to long is required for Manx C */
3190 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3191 /* May also set global value for local option. */
3192 if (both)
3193 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3194 *(int *)varp;
3195 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003196
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003197 /* The default value is not insecure. */
3198 flagsp = insecure_flag(opt_idx, opt_flags);
3199 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 }
3201
3202#ifdef FEAT_EVAL
3203 /* Remember where the option was set. */
3204 options[opt_idx].scriptID = current_SID;
3205#endif
3206}
3207
3208/*
3209 * Set all options (except terminal options) to their default value.
3210 */
3211 static void
3212set_options_default(opt_flags)
3213 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3214{
3215 int i;
3216#ifdef FEAT_WINDOWS
3217 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003218 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219#endif
3220
3221 for (i = 0; !istermoption(&options[i]); i++)
3222 if (!(options[i].flags & P_NODEFAULT))
3223 set_option_default(i, opt_flags, p_cp);
3224
3225#ifdef FEAT_WINDOWS
3226 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003227 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 win_comp_scroll(wp);
3229#else
3230 win_comp_scroll(curwin);
3231#endif
3232}
3233
3234/*
3235 * Set the Vi-default value of a string option.
3236 * Used for 'sh', 'backupskip' and 'term'.
3237 */
3238 void
3239set_string_default(name, val)
3240 char *name;
3241 char_u *val;
3242{
3243 char_u *p;
3244 int opt_idx;
3245
3246 p = vim_strsave(val);
3247 if (p != NULL) /* we don't want a NULL */
3248 {
3249 opt_idx = findoption((char_u *)name);
3250 if (options[opt_idx].flags & P_DEF_ALLOCED)
3251 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3252 options[opt_idx].def_val[VI_DEFAULT] = p;
3253 options[opt_idx].flags |= P_DEF_ALLOCED;
3254 }
3255}
3256
3257/*
3258 * Set the Vi-default value of a number option.
3259 * Used for 'lines' and 'columns'.
3260 */
3261 void
3262set_number_default(name, val)
3263 char *name;
3264 long val;
3265{
3266 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3267}
3268
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003269#if defined(EXITFREE) || defined(PROTO)
3270/*
3271 * Free all options.
3272 */
3273 void
3274free_all_options()
3275{
3276 int i;
3277
3278 for (i = 0; !istermoption(&options[i]); i++)
3279 {
3280 if (options[i].indir == PV_NONE)
3281 {
3282 /* global option: free value and default value. */
3283 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3284 free_string_option(*(char_u **)options[i].var);
3285 if (options[i].flags & P_DEF_ALLOCED)
3286 free_string_option(options[i].def_val[VI_DEFAULT]);
3287 }
3288 else if (options[i].var != VAR_WIN
3289 && (options[i].flags & P_STRING))
3290 /* buffer-local option: free global value */
3291 free_string_option(*(char_u **)options[i].var);
3292 }
3293}
3294#endif
3295
3296
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297/*
3298 * Initialize the options, part two: After getting Rows and Columns and
3299 * setting 'term'.
3300 */
3301 void
3302set_init_2()
3303{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003304 int idx;
3305
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306 /*
3307 * 'scroll' defaults to half the window height. Note that this default is
3308 * wrong when the window height changes.
3309 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003310 set_number_default("scroll", (long_u)Rows >> 1);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003311 idx = findoption((char_u *)"scroll");
3312 if (!(options[idx].flags & P_WAS_SET))
3313 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314 comp_col();
3315
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003316 /*
3317 * 'window' is only for backwards compatibility with Vi.
3318 * Default is Rows - 1.
3319 */
3320 idx = findoption((char_u *)"wi");
3321 if (!(options[idx].flags & P_WAS_SET))
3322 p_window = Rows - 1;
3323 set_number_default("window", Rows - 1);
3324
Bram Moolenaarf740b292006-02-16 22:11:02 +00003325 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003327 /*
3328 * If 'background' wasn't set by the user, try guessing the value,
3329 * depending on the terminal name. Only need to check for terminals
3330 * with a dark background, that can handle color.
3331 */
3332 idx = findoption((char_u *)"bg");
3333 if (!(options[idx].flags & P_WAS_SET) && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334 {
Bram Moolenaarf740b292006-02-16 22:11:02 +00003335 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE);
3336 /* don't mark it as set, when starting the GUI it may be
3337 * changed again */
3338 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 }
3340#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003341
3342#ifdef CURSOR_SHAPE
3343 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3344#endif
3345#ifdef FEAT_MOUSESHAPE
3346 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3347#endif
3348#ifdef FEAT_PRINTER
3349 (void)parse_printoptions(); /* parse 'printoptions' default value */
3350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351}
3352
3353/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003354 * Return "dark" or "light" depending on the kind of terminal.
3355 * This is just guessing! Recognized are:
3356 * "linux" Linux console
3357 * "screen.linux" Linux console with screen
3358 * "cygwin" Cygwin shell
3359 * "putty" Putty program
3360 * We also check the COLORFGBG environment variable, which is set by
3361 * rxvt and derivatives. This variable contains either two or three
3362 * values separated by semicolons; we want the last value in either
3363 * case. If this value is 0-6 or 8, our background is dark.
3364 */
3365 static char_u *
3366term_bg_default()
3367{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003368#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3369 /* DOS console nearly always black */
3370 return (char_u *)"dark";
3371#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003372 char_u *p;
3373
Bram Moolenaarf740b292006-02-16 22:11:02 +00003374 if (STRCMP(T_NAME, "linux") == 0
3375 || STRCMP(T_NAME, "screen.linux") == 0
3376 || STRCMP(T_NAME, "cygwin") == 0
3377 || STRCMP(T_NAME, "putty") == 0
3378 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3379 && (p = vim_strrchr(p, ';')) != NULL
3380 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3381 && p[2] == NUL))
3382 return (char_u *)"dark";
3383 return (char_u *)"light";
3384#endif
3385}
3386
3387/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 * Initialize the options, part three: After reading the .vimrc
3389 */
3390 void
3391set_init_3()
3392{
3393#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3394/*
3395 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3396 * This is done after other initializations, where 'shell' might have been
3397 * set, but only if they have not been set before.
3398 */
3399 char_u *p;
3400 int idx_srr;
3401 int do_srr;
3402#ifdef FEAT_QUICKFIX
3403 int idx_sp;
3404 int do_sp;
3405#endif
3406
3407 idx_srr = findoption((char_u *)"srr");
3408 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3409#ifdef FEAT_QUICKFIX
3410 idx_sp = findoption((char_u *)"sp");
3411 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3412#endif
3413
3414 /*
3415 * Isolate the name of the shell:
3416 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3417 * - Remove any argument. E.g., "csh -f" -> "csh".
3418 */
3419 p = gettail(p_sh);
3420 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3421 if (p != NULL)
3422 {
3423 /*
3424 * Default for p_sp is "| tee", for p_srr is ">".
3425 * For known shells it is changed here to include stderr.
3426 */
3427 if ( fnamecmp(p, "csh") == 0
3428 || fnamecmp(p, "tcsh") == 0
3429# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3430 || fnamecmp(p, "csh.exe") == 0
3431 || fnamecmp(p, "tcsh.exe") == 0
3432# endif
3433 )
3434 {
3435#if defined(FEAT_QUICKFIX)
3436 if (do_sp)
3437 {
3438# ifdef WIN3264
3439 p_sp = (char_u *)">&";
3440# else
3441 p_sp = (char_u *)"|& tee";
3442# endif
3443 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3444 }
3445#endif
3446 if (do_srr)
3447 {
3448 p_srr = (char_u *)">&";
3449 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3450 }
3451 }
3452 else
3453# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3454 if ( fnamecmp(p, "sh") == 0
3455 || fnamecmp(p, "ksh") == 0
3456 || fnamecmp(p, "zsh") == 0
3457 || fnamecmp(p, "bash") == 0
3458# ifdef WIN3264
3459 || fnamecmp(p, "cmd") == 0
3460 || fnamecmp(p, "sh.exe") == 0
3461 || fnamecmp(p, "ksh.exe") == 0
3462 || fnamecmp(p, "zsh.exe") == 0
3463 || fnamecmp(p, "bash.exe") == 0
3464 || fnamecmp(p, "cmd.exe") == 0
3465# endif
3466 )
3467# endif
3468 {
3469#if defined(FEAT_QUICKFIX)
3470 if (do_sp)
3471 {
3472# ifdef WIN3264
3473 p_sp = (char_u *)">%s 2>&1";
3474# else
3475 p_sp = (char_u *)"2>&1| tee";
3476# endif
3477 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3478 }
3479#endif
3480 if (do_srr)
3481 {
3482 p_srr = (char_u *)">%s 2>&1";
3483 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3484 }
3485 }
3486 vim_free(p);
3487 }
3488#endif
3489
3490#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3491 /*
3492 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3493 * This is done after other initializations, where 'shell' might have been
3494 * set, but only if they have not been set before. Default for p_shcf is
3495 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3496 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3497 * command.com. And for Win32 we need to set p_sxq instead.
3498 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003499 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500 {
3501 int idx3;
3502
3503 idx3 = findoption((char_u *)"shcf");
3504 if (!(options[idx3].flags & P_WAS_SET))
3505 {
3506 p_shcf = (char_u *)"-c";
3507 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3508 }
3509
3510# ifndef DJGPP
3511# ifdef WIN3264
3512 /* Somehow Win32 requires the quotes around the redirection too */
3513 idx3 = findoption((char_u *)"sxq");
3514 if (!(options[idx3].flags & P_WAS_SET))
3515 {
3516 p_sxq = (char_u *)"\"";
3517 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3518 }
3519# else
3520 idx3 = findoption((char_u *)"shq");
3521 if (!(options[idx3].flags & P_WAS_SET))
3522 {
3523 p_shq = (char_u *)"\"";
3524 options[idx3].def_val[VI_DEFAULT] = p_shq;
3525 }
3526# endif
3527# endif
3528 }
3529#endif
3530
3531#ifdef FEAT_TITLE
3532 set_title_defaults();
3533#endif
3534}
3535
3536#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3537/*
3538 * When 'helplang' is still at its default value, set it to "lang".
3539 * Only the first two characters of "lang" are used.
3540 */
3541 void
3542set_helplang_default(lang)
3543 char_u *lang;
3544{
3545 int idx;
3546
3547 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3548 return;
3549 idx = findoption((char_u *)"hlg");
3550 if (!(options[idx].flags & P_WAS_SET))
3551 {
3552 if (options[idx].flags & P_ALLOCED)
3553 free_string_option(p_hlg);
3554 p_hlg = vim_strsave(lang);
3555 if (p_hlg == NULL)
3556 p_hlg = empty_option;
3557 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003558 {
3559 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3560 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3561 {
3562 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3563 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3564 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003567 options[idx].flags |= P_ALLOCED;
3568 }
3569}
3570#endif
3571
3572#ifdef FEAT_GUI
3573static char_u *gui_bg_default __ARGS((void));
3574
3575 static char_u *
3576gui_bg_default()
3577{
3578 if (gui_get_lightness(gui.back_pixel) < 127)
3579 return (char_u *)"dark";
3580 return (char_u *)"light";
3581}
3582
3583/*
3584 * Option initializations that can only be done after opening the GUI window.
3585 */
3586 void
3587init_gui_options()
3588{
3589 /* Set the 'background' option according to the lightness of the
3590 * background color, unless the user has set it already. */
3591 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3592 {
3593 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3594 highlight_changed();
3595 }
3596}
3597#endif
3598
3599#ifdef FEAT_TITLE
3600/*
3601 * 'title' and 'icon' only default to true if they have not been set or reset
3602 * in .vimrc and we can read the old value.
3603 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3604 * they can be reset. This reduces startup time when using X on a remote
3605 * machine.
3606 */
3607 void
3608set_title_defaults()
3609{
3610 int idx1;
3611 long val;
3612
3613 /*
3614 * If GUI is (going to be) used, we can always set the window title and
3615 * icon name. Saves a bit of time, because the X11 display server does
3616 * not need to be contacted.
3617 */
3618 idx1 = findoption((char_u *)"title");
3619 if (!(options[idx1].flags & P_WAS_SET))
3620 {
3621#ifdef FEAT_GUI
3622 if (gui.starting || gui.in_use)
3623 val = TRUE;
3624 else
3625#endif
3626 val = mch_can_restore_title();
3627 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3628 p_title = val;
3629 }
3630 idx1 = findoption((char_u *)"icon");
3631 if (!(options[idx1].flags & P_WAS_SET))
3632 {
3633#ifdef FEAT_GUI
3634 if (gui.starting || gui.in_use)
3635 val = TRUE;
3636 else
3637#endif
3638 val = mch_can_restore_icon();
3639 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3640 p_icon = val;
3641 }
3642}
3643#endif
3644
3645/*
3646 * Parse 'arg' for option settings.
3647 *
3648 * 'arg' may be IObuff, but only when no errors can be present and option
3649 * does not need to be expanded with option_expand().
3650 * "opt_flags":
3651 * 0 for ":set"
3652 * OPT_GLOBAL for ":setglobal"
3653 * OPT_LOCAL for ":setlocal" and a modeline
3654 * OPT_MODELINE for a modeline
3655 *
3656 * returns FAIL if an error is detected, OK otherwise
3657 */
3658 int
3659do_set(arg, opt_flags)
3660 char_u *arg; /* option string (may be written to!) */
3661 int opt_flags;
3662{
3663 int opt_idx;
3664 char_u *errmsg;
3665 char_u errbuf[80];
3666 char_u *startarg;
3667 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3668 int nextchar; /* next non-white char after option name */
3669 int afterchar; /* character just after option name */
3670 int len;
3671 int i;
3672 long value;
3673 int key;
3674 long_u flags; /* flags for current option */
3675 char_u *varp = NULL; /* pointer to variable for current option */
3676 int did_show = FALSE; /* already showed one value */
3677 int adding; /* "opt+=arg" */
3678 int prepending; /* "opt^=arg" */
3679 int removing; /* "opt-=arg" */
3680 int cp_val = 0;
3681 char_u key_name[2];
3682
3683 if (*arg == NUL)
3684 {
3685 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003686 did_show = TRUE;
3687 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688 }
3689
3690 while (*arg != NUL) /* loop to process all options */
3691 {
3692 errmsg = NULL;
3693 startarg = arg; /* remember for error message */
3694
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003695 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3696 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003697 {
3698 /*
3699 * ":set all" show all options.
3700 * ":set all&" set all options to their default value.
3701 */
3702 arg += 3;
3703 if (*arg == '&')
3704 {
3705 ++arg;
3706 /* Only for :set command set global value of local options. */
3707 set_options_default(OPT_FREE | opt_flags);
3708 }
3709 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003710 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003712 did_show = TRUE;
3713 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003714 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003715 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 {
3717 showoptions(2, opt_flags);
3718 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003719 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 arg += 7;
3721 }
3722 else
3723 {
3724 prefix = 1;
3725 if (STRNCMP(arg, "no", 2) == 0)
3726 {
3727 prefix = 0;
3728 arg += 2;
3729 }
3730 else if (STRNCMP(arg, "inv", 3) == 0)
3731 {
3732 prefix = 2;
3733 arg += 3;
3734 }
3735
3736 /* find end of name */
3737 key = 0;
3738 if (*arg == '<')
3739 {
3740 nextchar = 0;
3741 opt_idx = -1;
3742 /* look out for <t_>;> */
3743 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3744 len = 5;
3745 else
3746 {
3747 len = 1;
3748 while (arg[len] != NUL && arg[len] != '>')
3749 ++len;
3750 }
3751 if (arg[len] != '>')
3752 {
3753 errmsg = e_invarg;
3754 goto skip;
3755 }
3756 arg[len] = NUL; /* put NUL after name */
3757 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3758 opt_idx = findoption(arg + 1);
3759 arg[len++] = '>'; /* restore '>' */
3760 if (opt_idx == -1)
3761 key = find_key_option(arg + 1);
3762 }
3763 else
3764 {
3765 len = 0;
3766 /*
3767 * The two characters after "t_" may not be alphanumeric.
3768 */
3769 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3770 len = 4;
3771 else
3772 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3773 ++len;
3774 nextchar = arg[len];
3775 arg[len] = NUL; /* put NUL after name */
3776 opt_idx = findoption(arg);
3777 arg[len] = nextchar; /* restore nextchar */
3778 if (opt_idx == -1)
3779 key = find_key_option(arg);
3780 }
3781
3782 /* remember character after option name */
3783 afterchar = arg[len];
3784
3785 /* skip white space, allow ":set ai ?" */
3786 while (vim_iswhite(arg[len]))
3787 ++len;
3788
3789 adding = FALSE;
3790 prepending = FALSE;
3791 removing = FALSE;
3792 if (arg[len] != NUL && arg[len + 1] == '=')
3793 {
3794 if (arg[len] == '+')
3795 {
3796 adding = TRUE; /* "+=" */
3797 ++len;
3798 }
3799 else if (arg[len] == '^')
3800 {
3801 prepending = TRUE; /* "^=" */
3802 ++len;
3803 }
3804 else if (arg[len] == '-')
3805 {
3806 removing = TRUE; /* "-=" */
3807 ++len;
3808 }
3809 }
3810 nextchar = arg[len];
3811
3812 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3813 {
3814 errmsg = (char_u *)N_("E518: Unknown option");
3815 goto skip;
3816 }
3817
3818 if (opt_idx >= 0)
3819 {
3820 if (options[opt_idx].var == NULL) /* hidden option: skip */
3821 {
3822 /* Only give an error message when requesting the value of
3823 * a hidden option, ignore setting it. */
3824 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3825 && (!(options[opt_idx].flags & P_BOOL)
3826 || nextchar == '?'))
3827 errmsg = (char_u *)N_("E519: Option not supported");
3828 goto skip;
3829 }
3830
3831 flags = options[opt_idx].flags;
3832 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3833 }
3834 else
3835 {
3836 flags = P_STRING;
3837 if (key < 0)
3838 {
3839 key_name[0] = KEY2TERMCAP0(key);
3840 key_name[1] = KEY2TERMCAP1(key);
3841 }
3842 else
3843 {
3844 key_name[0] = KS_KEY;
3845 key_name[1] = (key & 0xff);
3846 }
3847 }
3848
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003849 /* Skip all options that are not window-local (used when showing
3850 * an already loaded buffer in a window). */
3851 if ((opt_flags & OPT_WINONLY)
3852 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
3853 goto skip;
3854
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855 /* Disallow changing some options from modelines */
3856 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3857 {
3858 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3859 goto skip;
3860 }
3861
3862#ifdef HAVE_SANDBOX
3863 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003864 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865 {
3866 errmsg = (char_u *)_(e_sandbox);
3867 goto skip;
3868 }
3869#endif
3870
3871 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3872 {
3873 arg += len;
3874 cp_val = p_cp;
3875 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3876 {
3877 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3878 {
3879 cp_val = FALSE;
3880 arg += 3;
3881 }
3882 else /* "opt&vi": set to Vi default */
3883 {
3884 cp_val = TRUE;
3885 arg += 2;
3886 }
3887 }
3888 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3889 && arg[1] != NUL && !vim_iswhite(arg[1]))
3890 {
3891 errmsg = e_trailing;
3892 goto skip;
3893 }
3894 }
3895
3896 /*
3897 * allow '=' and ':' as MSDOS command.com allows only one
3898 * '=' character per "set" command line. grrr. (jw)
3899 */
3900 if (nextchar == '?'
3901 || (prefix == 1
3902 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
3903 && !(flags & P_BOOL)))
3904 {
3905 /*
3906 * print value
3907 */
3908 if (did_show)
3909 msg_putchar('\n'); /* cursor below last one */
3910 else
3911 {
3912 gotocmdline(TRUE); /* cursor at status line */
3913 did_show = TRUE; /* remember that we did a line */
3914 }
3915 if (opt_idx >= 0)
3916 {
3917 showoneopt(&options[opt_idx], opt_flags);
3918#ifdef FEAT_EVAL
3919 if (p_verbose > 0)
Bram Moolenaar661b1822005-07-28 22:36:45 +00003920 last_set_msg(options[opt_idx].scriptID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921#endif
3922 }
3923 else
3924 {
3925 char_u *p;
3926
3927 p = find_termcode(key_name);
3928 if (p == NULL)
3929 {
3930 errmsg = (char_u *)N_("E518: Unknown option");
3931 goto skip;
3932 }
3933 else
3934 (void)show_one_termcode(key_name, p, TRUE);
3935 }
3936 if (nextchar != '?'
3937 && nextchar != NUL && !vim_iswhite(afterchar))
3938 errmsg = e_trailing;
3939 }
3940 else
3941 {
3942 if (flags & P_BOOL) /* boolean */
3943 {
3944 if (nextchar == '=' || nextchar == ':')
3945 {
3946 errmsg = e_invarg;
3947 goto skip;
3948 }
3949
3950 /*
3951 * ":set opt!": invert
3952 * ":set opt&": reset to default value
3953 * ":set opt<": reset to global value
3954 */
3955 if (nextchar == '!')
3956 value = *(int *)(varp) ^ 1;
3957 else if (nextchar == '&')
3958 value = (int)(long)options[opt_idx].def_val[
3959 ((flags & P_VI_DEF) || cp_val)
3960 ? VI_DEFAULT : VIM_DEFAULT];
3961 else if (nextchar == '<')
3962 {
3963 /* For 'autoread' -1 means to use global value. */
3964 if ((int *)varp == &curbuf->b_p_ar
3965 && opt_flags == OPT_LOCAL)
3966 value = -1;
3967 else
3968 value = *(int *)get_varp_scope(&(options[opt_idx]),
3969 OPT_GLOBAL);
3970 }
3971 else
3972 {
3973 /*
3974 * ":set invopt": invert
3975 * ":set opt" or ":set noopt": set or reset
3976 */
3977 if (nextchar != NUL && !vim_iswhite(afterchar))
3978 {
3979 errmsg = e_trailing;
3980 goto skip;
3981 }
3982 if (prefix == 2) /* inv */
3983 value = *(int *)(varp) ^ 1;
3984 else
3985 value = prefix;
3986 }
3987
3988 errmsg = set_bool_option(opt_idx, varp, (int)value,
3989 opt_flags);
3990 }
3991 else /* numeric or string */
3992 {
3993 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
3994 || prefix != 1)
3995 {
3996 errmsg = e_invarg;
3997 goto skip;
3998 }
3999
4000 if (flags & P_NUM) /* numeric */
4001 {
4002 /*
4003 * Different ways to set a number option:
4004 * & set to default value
4005 * < set to global value
4006 * <xx> accept special key codes for 'wildchar'
4007 * c accept any non-digit for 'wildchar'
4008 * [-]0-9 set number
4009 * other error
4010 */
4011 ++arg;
4012 if (nextchar == '&')
4013 value = (long)options[opt_idx].def_val[
4014 ((flags & P_VI_DEF) || cp_val)
4015 ? VI_DEFAULT : VIM_DEFAULT];
4016 else if (nextchar == '<')
4017 value = *(long *)get_varp_scope(&(options[opt_idx]),
4018 OPT_GLOBAL);
4019 else if (((long *)varp == &p_wc
4020 || (long *)varp == &p_wcm)
4021 && (*arg == '<'
4022 || *arg == '^'
4023 || ((!arg[1] || vim_iswhite(arg[1]))
4024 && !VIM_ISDIGIT(*arg))))
4025 {
4026 value = string_to_key(arg);
4027 if (value == 0 && (long *)varp != &p_wcm)
4028 {
4029 errmsg = e_invarg;
4030 goto skip;
4031 }
4032 }
4033 /* allow negative numbers (for 'undolevels') */
4034 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4035 {
4036 i = 0;
4037 if (*arg == '-')
4038 i = 1;
4039#ifdef HAVE_STRTOL
4040 value = strtol((char *)arg, NULL, 0);
4041 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4042 i += 2;
4043#else
4044 value = atol((char *)arg);
4045#endif
4046 while (VIM_ISDIGIT(arg[i]))
4047 ++i;
4048 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4049 {
4050 errmsg = e_invarg;
4051 goto skip;
4052 }
4053 }
4054 else
4055 {
4056 errmsg = (char_u *)N_("E521: Number required after =");
4057 goto skip;
4058 }
4059
4060 if (adding)
4061 value = *(long *)varp + value;
4062 if (prepending)
4063 value = *(long *)varp * value;
4064 if (removing)
4065 value = *(long *)varp - value;
4066 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004067 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 }
4069 else if (opt_idx >= 0) /* string */
4070 {
4071 char_u *save_arg = NULL;
4072 char_u *s = NULL;
4073 char_u *oldval; /* previous value if *varp */
4074 char_u *newval;
4075 char_u *origval;
4076 unsigned newlen;
4077 int comma;
4078 int bs;
4079 int new_value_alloced; /* new string option
4080 was allocated */
4081
4082 /* When using ":set opt=val" for a global option
4083 * with a local value the local value will be
4084 * reset, use the global value here. */
4085 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4086 && (int)options[opt_idx].indir >= PV_BOTH)
4087 varp = options[opt_idx].var;
4088
4089 /* The old value is kept until we are sure that the
4090 * new value is valid. */
4091 oldval = *(char_u **)varp;
4092 if (nextchar == '&') /* set to default val */
4093 {
4094 newval = options[opt_idx].def_val[
4095 ((flags & P_VI_DEF) || cp_val)
4096 ? VI_DEFAULT : VIM_DEFAULT];
4097 if ((char_u **)varp == &p_bg)
4098 {
4099 /* guess the value of 'background' */
4100#ifdef FEAT_GUI
4101 if (gui.in_use)
4102 newval = gui_bg_default();
4103 else
4104#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004105 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 }
4107
4108 /* expand environment variables and ~ (since the
4109 * default value was already expanded, only
4110 * required when an environment variable was set
4111 * later */
4112 if (newval == NULL)
4113 newval = empty_option;
4114 else
4115 {
4116 s = option_expand(opt_idx, newval);
4117 if (s == NULL)
4118 s = newval;
4119 newval = vim_strsave(s);
4120 }
4121 new_value_alloced = TRUE;
4122 }
4123 else if (nextchar == '<') /* set to global val */
4124 {
4125 newval = vim_strsave(*(char_u **)get_varp_scope(
4126 &(options[opt_idx]), OPT_GLOBAL));
4127 new_value_alloced = TRUE;
4128 }
4129 else
4130 {
4131 ++arg; /* jump to after the '=' or ':' */
4132
4133 /*
4134 * Set 'keywordprg' to ":help" if an empty
4135 * value was passed to :set by the user.
4136 * Misuse errbuf[] for the resulting string.
4137 */
4138 if (varp == (char_u *)&p_kp
4139 && (*arg == NUL || *arg == ' '))
4140 {
4141 STRCPY(errbuf, ":help");
4142 save_arg = arg;
4143 arg = errbuf;
4144 }
4145 /*
4146 * Convert 'whichwrap' number to string, for
4147 * backwards compatibility with Vim 3.0.
4148 * Misuse errbuf[] for the resulting string.
4149 */
4150 else if (varp == (char_u *)&p_ww
4151 && VIM_ISDIGIT(*arg))
4152 {
4153 *errbuf = NUL;
4154 i = getdigits(&arg);
4155 if (i & 1)
4156 STRCAT(errbuf, "b,");
4157 if (i & 2)
4158 STRCAT(errbuf, "s,");
4159 if (i & 4)
4160 STRCAT(errbuf, "h,l,");
4161 if (i & 8)
4162 STRCAT(errbuf, "<,>,");
4163 if (i & 16)
4164 STRCAT(errbuf, "[,],");
4165 if (*errbuf != NUL) /* remove trailing , */
4166 errbuf[STRLEN(errbuf) - 1] = NUL;
4167 save_arg = arg;
4168 arg = errbuf;
4169 }
4170 /*
4171 * Remove '>' before 'dir' and 'bdir', for
4172 * backwards compatibility with version 3.0
4173 */
4174 else if ( *arg == '>'
4175 && (varp == (char_u *)&p_dir
4176 || varp == (char_u *)&p_bdir))
4177 {
4178 ++arg;
4179 }
4180
4181 /* When setting the local value of a global
4182 * option, the old value may be the global value. */
4183 if ((int)options[opt_idx].indir >= PV_BOTH
4184 && (opt_flags & OPT_LOCAL))
4185 origval = *(char_u **)get_varp(
4186 &options[opt_idx]);
4187 else
4188 origval = oldval;
4189
4190 /*
4191 * Copy the new string into allocated memory.
4192 * Can't use set_string_option_direct(), because
4193 * we need to remove the backslashes.
4194 */
4195 /* get a bit too much */
4196 newlen = (unsigned)STRLEN(arg) + 1;
4197 if (adding || prepending || removing)
4198 newlen += (unsigned)STRLEN(origval) + 1;
4199 newval = alloc(newlen);
4200 if (newval == NULL) /* out of mem, don't change */
4201 break;
4202 s = newval;
4203
4204 /*
4205 * Copy the string, skip over escaped chars.
4206 * For MS-DOS and WIN32 backslashes before normal
4207 * file name characters are not removed, and keep
4208 * backslash at start, for "\\machine\path", but
4209 * do remove it for "\\\\machine\\path".
4210 * The reverse is found in ExpandOldSetting().
4211 */
4212 while (*arg && !vim_iswhite(*arg))
4213 {
4214 if (*arg == '\\' && arg[1] != NUL
4215#ifdef BACKSLASH_IN_FILENAME
4216 && !((flags & P_EXPAND)
4217 && vim_isfilec(arg[1])
4218 && (arg[1] != '\\'
4219 || (s == newval
4220 && arg[2] != '\\')))
4221#endif
4222 )
4223 ++arg; /* remove backslash */
4224#ifdef FEAT_MBYTE
4225 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004226 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 {
4228 /* copy multibyte char */
4229 mch_memmove(s, arg, (size_t)i);
4230 arg += i;
4231 s += i;
4232 }
4233 else
4234#endif
4235 *s++ = *arg++;
4236 }
4237 *s = NUL;
4238
4239 /*
4240 * Expand environment variables and ~.
4241 * Don't do it when adding without inserting a
4242 * comma.
4243 */
4244 if (!(adding || prepending || removing)
4245 || (flags & P_COMMA))
4246 {
4247 s = option_expand(opt_idx, newval);
4248 if (s != NULL)
4249 {
4250 vim_free(newval);
4251 newlen = (unsigned)STRLEN(s) + 1;
4252 if (adding || prepending || removing)
4253 newlen += (unsigned)STRLEN(origval) + 1;
4254 newval = alloc(newlen);
4255 if (newval == NULL)
4256 break;
4257 STRCPY(newval, s);
4258 }
4259 }
4260
4261 /* locate newval[] in origval[] when removing it
4262 * and when adding to avoid duplicates */
4263 i = 0; /* init for GCC */
4264 if (removing || (flags & P_NODUP))
4265 {
4266 i = (int)STRLEN(newval);
4267 bs = 0;
4268 for (s = origval; *s; ++s)
4269 {
4270 if ((!(flags & P_COMMA)
4271 || s == origval
4272 || (s[-1] == ',' && !(bs & 1)))
4273 && STRNCMP(s, newval, i) == 0
4274 && (!(flags & P_COMMA)
4275 || s[i] == ','
4276 || s[i] == NUL))
4277 break;
4278 /* Count backspaces. Only a comma with an
4279 * even number of backspaces before it is
4280 * recognized as a separator */
4281 if (s > origval && s[-1] == '\\')
4282 ++bs;
4283 else
4284 bs = 0;
4285 }
4286
4287 /* do not add if already there */
4288 if ((adding || prepending) && *s)
4289 {
4290 prepending = FALSE;
4291 adding = FALSE;
4292 STRCPY(newval, origval);
4293 }
4294 }
4295
4296 /* concatenate the two strings; add a ',' if
4297 * needed */
4298 if (adding || prepending)
4299 {
4300 comma = ((flags & P_COMMA) && *origval != NUL
4301 && *newval != NUL);
4302 if (adding)
4303 {
4304 i = (int)STRLEN(origval);
4305 mch_memmove(newval + i + comma, newval,
4306 STRLEN(newval) + 1);
4307 mch_memmove(newval, origval, (size_t)i);
4308 }
4309 else
4310 {
4311 i = (int)STRLEN(newval);
4312 mch_memmove(newval + i + comma, origval,
4313 STRLEN(origval) + 1);
4314 }
4315 if (comma)
4316 newval[i] = ',';
4317 }
4318
4319 /* Remove newval[] from origval[]. (Note: "i" has
4320 * been set above and is used here). */
4321 if (removing)
4322 {
4323 STRCPY(newval, origval);
4324 if (*s)
4325 {
4326 /* may need to remove a comma */
4327 if (flags & P_COMMA)
4328 {
4329 if (s == origval)
4330 {
4331 /* include comma after string */
4332 if (s[i] == ',')
4333 ++i;
4334 }
4335 else
4336 {
4337 /* include comma before string */
4338 --s;
4339 ++i;
4340 }
4341 }
4342 mch_memmove(newval + (s - origval), s + i,
4343 STRLEN(s + i) + 1);
4344 }
4345 }
4346
4347 if (flags & P_FLAGLIST)
4348 {
4349 /* Remove flags that appear twice. */
4350 for (s = newval; *s; ++s)
4351 if ((!(flags & P_COMMA) || *s != ',')
4352 && vim_strchr(s + 1, *s) != NULL)
4353 {
4354 STRCPY(s, s + 1);
4355 --s;
4356 }
4357 }
4358
4359 if (save_arg != NULL) /* number for 'whichwrap' */
4360 arg = save_arg;
4361 new_value_alloced = TRUE;
4362 }
4363
4364 /* Set the new value. */
4365 *(char_u **)(varp) = newval;
4366
4367 /* Handle side effects, and set the global value for
4368 * ":set" on local options. */
4369 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4370 new_value_alloced, oldval, errbuf, opt_flags);
4371
4372 /* If error detected, print the error message. */
4373 if (errmsg != NULL)
4374 goto skip;
4375 }
4376 else /* key code option */
4377 {
4378 char_u *p;
4379
4380 if (nextchar == '&')
4381 {
4382 if (add_termcap_entry(key_name, TRUE) == FAIL)
4383 errmsg = (char_u *)N_("E522: Not found in termcap");
4384 }
4385 else
4386 {
4387 ++arg; /* jump to after the '=' or ':' */
4388 for (p = arg; *p && !vim_iswhite(*p); ++p)
4389 if (*p == '\\' && p[1] != NUL)
4390 ++p;
4391 nextchar = *p;
4392 *p = NUL;
4393 add_termcode(key_name, arg, FALSE);
4394 *p = nextchar;
4395 }
4396 if (full_screen)
4397 ttest(FALSE);
4398 redraw_all_later(CLEAR);
4399 }
4400 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004401
Bram Moolenaar071d4272004-06-13 20:20:40 +00004402 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004403 did_set_option(opt_idx, opt_flags,
4404 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004405 }
4406
4407skip:
4408 /*
4409 * Advance to next argument.
4410 * - skip until a blank found, taking care of backslashes
4411 * - skip blanks
4412 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4413 */
4414 for (i = 0; i < 2 ; ++i)
4415 {
4416 while (*arg != NUL && !vim_iswhite(*arg))
4417 if (*arg++ == '\\' && *arg != NUL)
4418 ++arg;
4419 arg = skipwhite(arg);
4420 if (*arg != '=')
4421 break;
4422 }
4423 }
4424
4425 if (errmsg != NULL)
4426 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004427 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004428 i = STRLEN(IObuff) + 2;
4429 if (i + (arg - startarg) < IOSIZE)
4430 {
4431 /* append the argument with the error */
4432 STRCAT(IObuff, ": ");
4433 mch_memmove(IObuff + i, startarg, (arg - startarg));
4434 IObuff[i + (arg - startarg)] = NUL;
4435 }
4436 /* make sure all characters are printable */
4437 trans_characters(IObuff, IOSIZE);
4438
4439 ++no_wait_return; /* wait_return done later */
4440 emsg(IObuff); /* show error highlighted */
4441 --no_wait_return;
4442
4443 return FAIL;
4444 }
4445
4446 arg = skipwhite(arg);
4447 }
4448
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004449theend:
4450 if (silent_mode && did_show)
4451 {
4452 /* After displaying option values in silent mode. */
4453 silent_mode = FALSE;
4454 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4455 msg_putchar('\n');
4456 cursor_on(); /* msg_start() switches it off */
4457 out_flush();
4458 silent_mode = TRUE;
4459 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4460 }
4461
Bram Moolenaar071d4272004-06-13 20:20:40 +00004462 return OK;
4463}
4464
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004465/*
4466 * Call this when an option has been given a new value through a user command.
4467 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4468 */
4469 static void
4470did_set_option(opt_idx, opt_flags, new_value)
4471 int opt_idx;
4472 int opt_flags; /* possibly with OPT_MODELINE */
4473 int new_value; /* value was replaced completely */
4474{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004475 long_u *p;
4476
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004477 options[opt_idx].flags |= P_WAS_SET;
4478
4479 /* When an option is set in the sandbox, from a modeline or in secure mode
4480 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004481 * flag. */
4482 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004483 if (secure
4484#ifdef HAVE_SANDBOX
4485 || sandbox != 0
4486#endif
4487 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004488 *p = *p | P_INSECURE;
4489 else if (new_value)
4490 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004491}
4492
Bram Moolenaar071d4272004-06-13 20:20:40 +00004493 static char_u *
4494illegal_char(errbuf, c)
4495 char_u *errbuf;
4496 int c;
4497{
4498 if (errbuf == NULL)
4499 return (char_u *)"";
4500 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004501 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004502 return errbuf;
4503}
4504
4505/*
4506 * Convert a key name or string into a key value.
4507 * Used for 'wildchar' and 'cedit' options.
4508 */
4509 static int
4510string_to_key(arg)
4511 char_u *arg;
4512{
4513 if (*arg == '<')
4514 return find_key_option(arg + 1);
4515 if (*arg == '^')
4516 return Ctrl_chr(arg[1]);
4517 return *arg;
4518}
4519
4520#ifdef FEAT_CMDWIN
4521/*
4522 * Check value of 'cedit' and set cedit_key.
4523 * Returns NULL if value is OK, error message otherwise.
4524 */
4525 static char_u *
4526check_cedit()
4527{
4528 int n;
4529
4530 if (*p_cedit == NUL)
4531 cedit_key = -1;
4532 else
4533 {
4534 n = string_to_key(p_cedit);
4535 if (vim_isprintc(n))
4536 return e_invarg;
4537 cedit_key = n;
4538 }
4539 return NULL;
4540}
4541#endif
4542
4543#ifdef FEAT_TITLE
4544/*
4545 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4546 * maketitle() to create and display it.
4547 * When switching the title or icon off, call mch_restore_title() to get
4548 * the old value back.
4549 */
4550 static void
4551did_set_title(icon)
4552 int icon; /* Did set icon instead of title */
4553{
4554 if (starting != NO_SCREEN
4555#ifdef FEAT_GUI
4556 && !gui.starting
4557#endif
4558 )
4559 {
4560 maketitle();
4561 if (icon)
4562 {
4563 if (!p_icon)
4564 mch_restore_title(2);
4565 }
4566 else
4567 {
4568 if (!p_title)
4569 mch_restore_title(1);
4570 }
4571 }
4572}
4573#endif
4574
4575/*
4576 * set_options_bin - called when 'bin' changes value.
4577 */
4578 void
4579set_options_bin(oldval, newval, opt_flags)
4580 int oldval;
4581 int newval;
4582 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4583{
4584 /*
4585 * The option values that are changed when 'bin' changes are
4586 * copied when 'bin is set and restored when 'bin' is reset.
4587 */
4588 if (newval)
4589 {
4590 if (!oldval) /* switched on */
4591 {
4592 if (!(opt_flags & OPT_GLOBAL))
4593 {
4594 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4595 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4596 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4597 curbuf->b_p_et_nobin = curbuf->b_p_et;
4598 }
4599 if (!(opt_flags & OPT_LOCAL))
4600 {
4601 p_tw_nobin = p_tw;
4602 p_wm_nobin = p_wm;
4603 p_ml_nobin = p_ml;
4604 p_et_nobin = p_et;
4605 }
4606 }
4607
4608 if (!(opt_flags & OPT_GLOBAL))
4609 {
4610 curbuf->b_p_tw = 0; /* no automatic line wrap */
4611 curbuf->b_p_wm = 0; /* no automatic line wrap */
4612 curbuf->b_p_ml = 0; /* no modelines */
4613 curbuf->b_p_et = 0; /* no expandtab */
4614 }
4615 if (!(opt_flags & OPT_LOCAL))
4616 {
4617 p_tw = 0;
4618 p_wm = 0;
4619 p_ml = FALSE;
4620 p_et = FALSE;
4621 p_bin = TRUE; /* needed when called for the "-b" argument */
4622 }
4623 }
4624 else if (oldval) /* switched off */
4625 {
4626 if (!(opt_flags & OPT_GLOBAL))
4627 {
4628 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4629 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4630 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4631 curbuf->b_p_et = curbuf->b_p_et_nobin;
4632 }
4633 if (!(opt_flags & OPT_LOCAL))
4634 {
4635 p_tw = p_tw_nobin;
4636 p_wm = p_wm_nobin;
4637 p_ml = p_ml_nobin;
4638 p_et = p_et_nobin;
4639 }
4640 }
4641}
4642
4643#ifdef FEAT_VIMINFO
4644/*
4645 * Find the parameter represented by the given character (eg ', :, ", or /),
4646 * and return its associated value in the 'viminfo' string.
4647 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004648 * If the parameter is not specified in the string or there is no following
4649 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004650 */
4651 int
4652get_viminfo_parameter(type)
4653 int type;
4654{
4655 char_u *p;
4656
4657 p = find_viminfo_parameter(type);
4658 if (p != NULL && VIM_ISDIGIT(*p))
4659 return atoi((char *)p);
4660 return -1;
4661}
4662
4663/*
4664 * Find the parameter represented by the given character (eg ''', ':', '"', or
4665 * '/') in the 'viminfo' option and return a pointer to the string after it.
4666 * Return NULL if the parameter is not specified in the string.
4667 */
4668 char_u *
4669find_viminfo_parameter(type)
4670 int type;
4671{
4672 char_u *p;
4673
4674 for (p = p_viminfo; *p; ++p)
4675 {
4676 if (*p == type)
4677 return p + 1;
4678 if (*p == 'n') /* 'n' is always the last one */
4679 break;
4680 p = vim_strchr(p, ','); /* skip until next ',' */
4681 if (p == NULL) /* hit the end without finding parameter */
4682 break;
4683 }
4684 return NULL;
4685}
4686#endif
4687
4688/*
4689 * Expand environment variables for some string options.
4690 * These string options cannot be indirect!
4691 * If "val" is NULL expand the current value of the option.
4692 * Return pointer to NameBuff, or NULL when not expanded.
4693 */
4694 static char_u *
4695option_expand(opt_idx, val)
4696 int opt_idx;
4697 char_u *val;
4698{
4699 /* if option doesn't need expansion nothing to do */
4700 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4701 return NULL;
4702
4703 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4704 * expand_env() would truncate the string. */
4705 if (val != NULL && STRLEN(val) > MAXPATHL)
4706 return NULL;
4707
4708 if (val == NULL)
4709 val = *(char_u **)options[opt_idx].var;
4710
4711 /*
4712 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4713 * Escape spaces when expanding 'tags', they are used to separate file
4714 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004715 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 */
4717 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004718 (char_u **)options[opt_idx].var == &p_tags,
4719#ifdef FEAT_SYN_HL
4720 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4721#endif
4722 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004723 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4724 return NULL;
4725
4726 return NameBuff;
4727}
4728
4729/*
4730 * After setting various option values: recompute variables that depend on
4731 * option values.
4732 */
4733 static void
4734didset_options()
4735{
4736 /* initialize the table for 'iskeyword' et.al. */
4737 (void)init_chartab();
4738
4739 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4740 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4741#ifdef FEAT_SESSION
4742 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4743 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4744#endif
4745#ifdef FEAT_FOLDING
4746 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4747#endif
4748 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4749#ifdef FEAT_VIRTUALEDIT
4750 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4751#endif
4752#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4753 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4754#endif
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004755#ifdef FEAT_SYN_HL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004756 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004757 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004758 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004759#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4761 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4762#endif
4763#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4764 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4765#endif
4766#ifdef FEAT_CMDWIN
4767 /* set cedit_key */
4768 (void)check_cedit();
4769#endif
4770}
4771
4772/*
4773 * Check for string options that are NULL (normally only termcap options).
4774 */
4775 void
4776check_options()
4777{
4778 int opt_idx;
4779
4780 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4781 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4782 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4783}
4784
4785/*
4786 * Check string options in a buffer for NULL value.
4787 */
4788 void
4789check_buf_options(buf)
4790 buf_T *buf;
4791{
4792#if defined(FEAT_QUICKFIX)
4793 check_string_option(&buf->b_p_bh);
4794 check_string_option(&buf->b_p_bt);
4795#endif
4796#ifdef FEAT_MBYTE
4797 check_string_option(&buf->b_p_fenc);
4798#endif
4799 check_string_option(&buf->b_p_ff);
4800#ifdef FEAT_FIND_ID
4801 check_string_option(&buf->b_p_def);
4802 check_string_option(&buf->b_p_inc);
4803# ifdef FEAT_EVAL
4804 check_string_option(&buf->b_p_inex);
4805# endif
4806#endif
4807#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4808 check_string_option(&buf->b_p_inde);
4809 check_string_option(&buf->b_p_indk);
4810#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00004811#if defined(FEAT_EVAL)
4812 check_string_option(&buf->b_p_fex);
4813#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004814#ifdef FEAT_CRYPT
4815 check_string_option(&buf->b_p_key);
4816#endif
4817 check_string_option(&buf->b_p_kp);
4818 check_string_option(&buf->b_p_mps);
4819 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004820 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004821 check_string_option(&buf->b_p_isk);
4822#ifdef FEAT_COMMENTS
4823 check_string_option(&buf->b_p_com);
4824#endif
4825#ifdef FEAT_FOLDING
4826 check_string_option(&buf->b_p_cms);
4827#endif
4828 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004829#ifdef FEAT_TEXTOBJ
4830 check_string_option(&buf->b_p_qe);
4831#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832#ifdef FEAT_SYN_HL
4833 check_string_option(&buf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004834 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00004835 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00004836 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004837#endif
4838#ifdef FEAT_SEARCHPATH
4839 check_string_option(&buf->b_p_sua);
4840#endif
4841#ifdef FEAT_CINDENT
4842 check_string_option(&buf->b_p_cink);
4843 check_string_option(&buf->b_p_cino);
4844#endif
4845#ifdef FEAT_AUTOCMD
4846 check_string_option(&buf->b_p_ft);
4847#endif
4848#ifdef FEAT_OSFILETYPE
4849 check_string_option(&buf->b_p_oft);
4850#endif
4851#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4852 check_string_option(&buf->b_p_cinw);
4853#endif
4854#ifdef FEAT_INS_EXPAND
4855 check_string_option(&buf->b_p_cpt);
4856#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004857#ifdef FEAT_COMPL_FUNC
4858 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00004859 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004860#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004861#ifdef FEAT_KEYMAP
4862 check_string_option(&buf->b_p_keymap);
4863#endif
4864#ifdef FEAT_QUICKFIX
4865 check_string_option(&buf->b_p_gp);
4866 check_string_option(&buf->b_p_mp);
4867 check_string_option(&buf->b_p_efm);
4868#endif
4869 check_string_option(&buf->b_p_ep);
4870 check_string_option(&buf->b_p_path);
4871 check_string_option(&buf->b_p_tags);
4872#ifdef FEAT_INS_EXPAND
4873 check_string_option(&buf->b_p_dict);
4874 check_string_option(&buf->b_p_tsr);
4875#endif
4876}
4877
4878/*
4879 * Free the string allocated for an option.
4880 * Checks for the string being empty_option. This may happen if we're out of
4881 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4882 * check_options().
4883 * Does NOT check for P_ALLOCED flag!
4884 */
4885 void
4886free_string_option(p)
4887 char_u *p;
4888{
4889 if (p != empty_option)
4890 vim_free(p);
4891}
4892
4893 void
4894clear_string_option(pp)
4895 char_u **pp;
4896{
4897 if (*pp != empty_option)
4898 vim_free(*pp);
4899 *pp = empty_option;
4900}
4901
4902 static void
4903check_string_option(pp)
4904 char_u **pp;
4905{
4906 if (*pp == NULL)
4907 *pp = empty_option;
4908}
4909
4910/*
4911 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4912 */
4913 void
4914set_term_option_alloced(p)
4915 char_u **p;
4916{
4917 int opt_idx;
4918
4919 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4920 if (options[opt_idx].var == (char_u *)p)
4921 {
4922 options[opt_idx].flags |= P_ALLOCED;
4923 return;
4924 }
4925 return; /* cannot happen: didn't find it! */
4926}
4927
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004928#if defined(FEAT_EVAL) || defined(PROTO)
4929/*
4930 * Return TRUE when option "opt" was set from a modeline or in secure mode.
4931 * Return FALSE when it wasn't.
4932 * Return -1 for an unknown option.
4933 */
4934 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004935was_set_insecurely(opt, opt_flags)
4936 char_u *opt;
4937 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004938{
4939 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004940 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004941
4942 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004943 {
4944 flagp = insecure_flag(idx, opt_flags);
4945 return (*flagp & P_INSECURE) != 0;
4946 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004947 EMSG2(_(e_intern2), "was_set_insecurely()");
4948 return -1;
4949}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004950
4951/*
4952 * Get a pointer to the flags used for the P_INSECURE flag of option
4953 * "opt_idx". For some local options a local flags field is used.
4954 */
4955 static long_u *
4956insecure_flag(opt_idx, opt_flags)
4957 int opt_idx;
4958 int opt_flags;
4959{
4960 if (opt_flags & OPT_LOCAL)
4961 switch ((int)options[opt_idx].indir)
4962 {
4963#ifdef FEAT_STL_OPT
4964 case OPT_BOTH(PV_STL): return &curwin->w_p_stl_flags;
4965#endif
4966#ifdef FEAT_EVAL
4967 case PV_FDE: return &curwin->w_p_fde_flags;
4968 case PV_FDT: return &curwin->w_p_fdt_flags;
4969#endif
4970#if defined(FEAT_EVAL)
4971# if defined(FEAT_CINDENT)
4972 case PV_INDE: return &curbuf->b_p_inde_flags;
4973# endif
4974 case PV_FEX: return &curbuf->b_p_fex_flags;
4975# ifdef FEAT_FIND_ID
4976 case PV_INEX: return &curbuf->b_p_inex_flags;
4977# endif
4978#endif
4979 }
4980
4981 /* Nothing special, return global flags field. */
4982 return &options[opt_idx].flags;
4983}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004984#endif
4985
Bram Moolenaar071d4272004-06-13 20:20:40 +00004986/*
4987 * Set a string option to a new value (without checking the effect).
4988 * The string is copied into allocated memory.
4989 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4990 */
4991 void
4992set_string_option_direct(name, opt_idx, val, opt_flags)
4993 char_u *name;
4994 int opt_idx;
4995 char_u *val;
4996 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4997{
4998 char_u *s;
4999 char_u **varp;
5000 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5001
5002 if (opt_idx == -1) /* use name */
5003 {
5004 opt_idx = findoption(name);
5005 if (opt_idx == -1) /* not found (should not happen) */
5006 return;
5007 }
5008
5009 if (options[opt_idx].var == NULL) /* can't set hidden option */
5010 return;
5011
5012 s = vim_strsave(val);
5013 if (s != NULL)
5014 {
5015 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5016 both ? OPT_LOCAL : opt_flags);
5017 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
5018 free_string_option(*varp);
5019 *varp = s;
5020
5021 /* For buffer/window local option may also set the global value. */
5022 if (both)
5023 set_string_option_global(opt_idx, varp);
5024
5025 options[opt_idx].flags |= P_ALLOCED;
5026
5027 /* When setting both values of a global option with a local value,
5028 * make the local value empty, so that the global value is used. */
5029 if ((int)options[opt_idx].indir >= PV_BOTH && both)
5030 {
5031 free_string_option(*varp);
5032 *varp = empty_option;
5033 }
5034 }
5035}
5036
5037/*
5038 * Set global value for string option when it's a local option.
5039 */
5040 static void
5041set_string_option_global(opt_idx, varp)
5042 int opt_idx; /* option index */
5043 char_u **varp; /* pointer to option variable */
5044{
5045 char_u **p, *s;
5046
5047 /* the global value is always allocated */
5048 if (options[opt_idx].var == VAR_WIN)
5049 p = (char_u **)GLOBAL_WO(varp);
5050 else
5051 p = (char_u **)options[opt_idx].var;
5052 if (options[opt_idx].indir != PV_NONE
5053 && p != varp
5054 && (s = vim_strsave(*varp)) != NULL)
5055 {
5056 free_string_option(*p);
5057 *p = s;
5058 }
5059}
5060
5061/*
5062 * Set a string option to a new value, and handle the effects.
5063 */
5064 static void
5065set_string_option(opt_idx, value, opt_flags)
5066 int opt_idx;
5067 char_u *value;
5068 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5069{
5070 char_u *s;
5071 char_u **varp;
5072 char_u *oldval;
5073
5074 if (options[opt_idx].var == NULL) /* don't set hidden option */
5075 return;
5076
5077 s = vim_strsave(value);
5078 if (s != NULL)
5079 {
5080 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5081 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5082 ? ((int)options[opt_idx].indir >= PV_BOTH
5083 ? OPT_GLOBAL : OPT_LOCAL)
5084 : opt_flags);
5085 oldval = *varp;
5086 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005087 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5088 opt_flags) == NULL)
5089 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005090 }
5091}
5092
5093/*
5094 * Handle string options that need some action to perform when changed.
5095 * Returns NULL for success, or an error message for an error.
5096 */
5097 static char_u *
5098did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5099 opt_flags)
5100 int opt_idx; /* index in options[] table */
5101 char_u **varp; /* pointer to the option variable */
5102 int new_value_alloced; /* new value was allocated */
5103 char_u *oldval; /* previous value of the option */
5104 char_u *errbuf; /* buffer for errors, or NULL */
5105 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5106{
5107 char_u *errmsg = NULL;
5108 char_u *s, *p;
5109 int did_chartab = FALSE;
5110 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005111 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005112
5113 /* Get the global option to compare with, otherwise we would have to check
5114 * two values for all local options. */
5115 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5116
5117 /* Disallow changing some options from secure mode */
5118 if ((secure
5119#ifdef HAVE_SANDBOX
5120 || sandbox != 0
5121#endif
5122 ) && (options[opt_idx].flags & P_SECURE))
5123 {
5124 errmsg = e_secure;
5125 }
5126
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005127 /* Check for a "normal" file name in some options. Disallow a path
5128 * separator (slash and/or backslash), wildcards and characters that are
5129 * often illegal in a file name. */
5130 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005131 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005132 {
5133 errmsg = e_invarg;
5134 }
5135
Bram Moolenaar071d4272004-06-13 20:20:40 +00005136 /* 'term' */
5137 else if (varp == &T_NAME)
5138 {
5139 if (T_NAME[0] == NUL)
5140 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5141#ifdef FEAT_GUI
5142 if (gui.in_use)
5143 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5144 else if (term_is_gui(T_NAME))
5145 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5146#endif
5147 else if (set_termname(T_NAME) == FAIL)
5148 errmsg = (char_u *)N_("E522: Not found in termcap");
5149 else
5150 /* Screen colors may have changed. */
5151 redraw_later_clear();
5152 }
5153
5154 /* 'backupcopy' */
5155 else if (varp == &p_bkc)
5156 {
5157 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5158 errmsg = e_invarg;
5159 if (((bkc_flags & BKC_AUTO) != 0)
5160 + ((bkc_flags & BKC_YES) != 0)
5161 + ((bkc_flags & BKC_NO) != 0) != 1)
5162 {
5163 /* Must have exactly one of "auto", "yes" and "no". */
5164 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5165 errmsg = e_invarg;
5166 }
5167 }
5168
5169 /* 'backupext' and 'patchmode' */
5170 else if (varp == &p_bex || varp == &p_pm)
5171 {
5172 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5173 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5174 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5175 }
5176
5177 /*
5178 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5179 * If the new option is invalid, use old value. 'lisp' option: refill
5180 * chartab[] for '-' char
5181 */
5182 else if ( varp == &p_isi
5183 || varp == &(curbuf->b_p_isk)
5184 || varp == &p_isp
5185 || varp == &p_isf)
5186 {
5187 if (init_chartab() == FAIL)
5188 {
5189 did_chartab = TRUE; /* need to restore it below */
5190 errmsg = e_invarg; /* error in value */
5191 }
5192 }
5193
5194 /* 'helpfile' */
5195 else if (varp == &p_hf)
5196 {
5197 /* May compute new values for $VIM and $VIMRUNTIME */
5198 if (didset_vim)
5199 {
5200 vim_setenv((char_u *)"VIM", (char_u *)"");
5201 didset_vim = FALSE;
5202 }
5203 if (didset_vimruntime)
5204 {
5205 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5206 didset_vimruntime = FALSE;
5207 }
5208 }
5209
5210#ifdef FEAT_MULTI_LANG
5211 /* 'helplang' */
5212 else if (varp == &p_hlg)
5213 {
5214 /* Check for "", "ab", "ab,cd", etc. */
5215 for (s = p_hlg; *s != NUL; s += 3)
5216 {
5217 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5218 {
5219 errmsg = e_invarg;
5220 break;
5221 }
5222 if (s[2] == NUL)
5223 break;
5224 }
5225 }
5226#endif
5227
5228 /* 'highlight' */
5229 else if (varp == &p_hl)
5230 {
5231 if (highlight_changed() == FAIL)
5232 errmsg = e_invarg; /* invalid flags */
5233 }
5234
5235 /* 'nrformats' */
5236 else if (gvarp == &p_nf)
5237 {
5238 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5239 errmsg = e_invarg;
5240 }
5241
5242#ifdef FEAT_SESSION
5243 /* 'sessionoptions' */
5244 else if (varp == &p_ssop)
5245 {
5246 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5247 errmsg = e_invarg;
5248 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5249 {
5250 /* Don't allow both "sesdir" and "curdir". */
5251 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5252 errmsg = e_invarg;
5253 }
5254 }
5255 /* 'viewoptions' */
5256 else if (varp == &p_vop)
5257 {
5258 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5259 errmsg = e_invarg;
5260 }
5261#endif
5262
5263 /* 'scrollopt' */
5264#ifdef FEAT_SCROLLBIND
5265 else if (varp == &p_sbo)
5266 {
5267 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5268 errmsg = e_invarg;
5269 }
5270#endif
5271
5272 /* 'ambiwidth' */
5273#ifdef FEAT_MBYTE
5274 else if (varp == &p_ambw)
5275 {
5276 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5277 errmsg = e_invarg;
5278 }
5279#endif
5280
5281 /* 'background' */
5282 else if (varp == &p_bg)
5283 {
5284 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5285 {
5286#ifdef FEAT_EVAL
5287 int dark = (*p_bg == 'd');
5288#endif
5289
5290 init_highlight(FALSE, FALSE);
5291
5292#ifdef FEAT_EVAL
5293 if (dark != (*p_bg == 'd')
5294 && get_var_value((char_u *)"g:colors_name") != NULL)
5295 {
5296 /* The color scheme must have set 'background' back to another
5297 * value, that's not what we want here. Disable the color
5298 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005299 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300 free_string_option(p_bg);
5301 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5302 check_string_option(&p_bg);
5303 init_highlight(FALSE, FALSE);
5304 }
5305#endif
5306 }
5307 else
5308 errmsg = e_invarg;
5309 }
5310
5311 /* 'wildmode' */
5312 else if (varp == &p_wim)
5313 {
5314 if (check_opt_wim() == FAIL)
5315 errmsg = e_invarg;
5316 }
5317
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005318#ifdef FEAT_CMDL_COMPL
5319 /* 'wildoptions' */
5320 else if (varp == &p_wop)
5321 {
5322 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5323 errmsg = e_invarg;
5324 }
5325#endif
5326
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327#ifdef FEAT_WAK
5328 /* 'winaltkeys' */
5329 else if (varp == &p_wak)
5330 {
5331 if (*p_wak == NUL
5332 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5333 errmsg = e_invarg;
5334# ifdef FEAT_MENU
5335# ifdef FEAT_GUI_MOTIF
5336 else if (gui.in_use)
5337 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5338# else
5339# ifdef FEAT_GUI_GTK
5340 else if (gui.in_use)
5341 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5342# endif
5343# endif
5344# endif
5345 }
5346#endif
5347
5348#ifdef FEAT_AUTOCMD
5349 /* 'eventignore' */
5350 else if (varp == &p_ei)
5351 {
5352 if (check_ei() == FAIL)
5353 errmsg = e_invarg;
5354 }
5355#endif
5356
5357#ifdef FEAT_MBYTE
5358 /* 'encoding' and 'fileencoding' */
5359 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5360 {
5361 if (gvarp == &p_fenc)
5362 {
5363 if (!curbuf->b_p_ma)
5364 errmsg = e_modifiable;
5365 else if (vim_strchr(*varp, ',') != NULL)
5366 /* No comma allowed in 'fileencoding'; catches confusing it
5367 * with 'fileencodings'. */
5368 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005370 {
5371# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372 /* May show a "+" in the title now. */
5373 need_maketitle = TRUE;
5374# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005375 /* Add 'fileencoding' to the swap file. */
5376 ml_setflags(curbuf);
5377 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005378 }
5379 if (errmsg == NULL)
5380 {
5381 /* canonize the value, so that STRCMP() can be used on it */
5382 p = enc_canonize(*varp);
5383 if (p != NULL)
5384 {
5385 vim_free(*varp);
5386 *varp = p;
5387 }
5388 if (varp == &p_enc)
5389 {
5390 errmsg = mb_init();
5391# ifdef FEAT_TITLE
5392 need_maketitle = TRUE;
5393# endif
5394 }
5395 }
5396
5397# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5398 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5399 {
5400 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5401 if (STRCMP(p_tenc, "utf-8") != 0)
5402 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5403 }
5404# endif
5405
5406 if (errmsg == NULL)
5407 {
5408# ifdef FEAT_KEYMAP
5409 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5410 * (with another encoding). */
5411 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5412 (void)keymap_init();
5413# endif
5414
5415 /* When 'termencoding' is not empty and 'encoding' changes or when
5416 * 'termencoding' changes, need to setup for keyboard input and
5417 * display output conversion. */
5418 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5419 {
5420 convert_setup(&input_conv, p_tenc, p_enc);
5421 convert_setup(&output_conv, p_enc, p_tenc);
5422 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005423
5424# if defined(WIN3264) && defined(FEAT_MBYTE)
5425 /* $HOME may have characters in active code page. */
5426 if (varp == &p_enc)
5427 init_homedir();
5428# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005429 }
5430 }
5431#endif
5432
5433#if defined(FEAT_POSTSCRIPT)
5434 else if (varp == &p_penc)
5435 {
5436 /* Canonize printencoding if VIM standard one */
5437 p = enc_canonize(p_penc);
5438 if (p != NULL)
5439 {
5440 vim_free(p_penc);
5441 p_penc = p;
5442 }
5443 else
5444 {
5445 /* Ensure lower case and '-' for '_' */
5446 for (s = p_penc; *s != NUL; s++)
5447 {
5448 if (*s == '_')
5449 *s = '-';
5450 else
5451 *s = TOLOWER_ASC(*s);
5452 }
5453 }
5454 }
5455#endif
5456
Bram Moolenaar9372a112005-12-06 19:59:18 +00005457#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005458 else if (varp == &p_imak)
5459 {
5460 if (gui.in_use && !im_xim_isvalid_imactivate())
5461 errmsg = e_invarg;
5462 }
5463#endif
5464
5465#ifdef FEAT_KEYMAP
5466 else if (varp == &curbuf->b_p_keymap)
5467 {
5468 /* load or unload key mapping tables */
5469 errmsg = keymap_init();
5470
5471 /* When successfully installed a new keymap switch on using it. */
5472 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5473 {
5474 curbuf->b_p_iminsert = B_IMODE_LMAP;
5475 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5476 curbuf->b_p_imsearch = B_IMODE_LMAP;
5477 set_iminsert_global();
5478 set_imsearch_global();
5479# ifdef FEAT_WINDOWS
5480 status_redraw_curbuf();
5481# endif
5482 }
5483 }
5484#endif
5485
5486 /* 'fileformat' */
5487 else if (gvarp == &p_ff)
5488 {
5489 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5490 errmsg = e_modifiable;
5491 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5492 errmsg = e_invarg;
5493 else
5494 {
5495 /* may also change 'textmode' */
5496 if (get_fileformat(curbuf) == EOL_DOS)
5497 curbuf->b_p_tx = TRUE;
5498 else
5499 curbuf->b_p_tx = FALSE;
5500#ifdef FEAT_TITLE
5501 need_maketitle = TRUE;
5502#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005503 /* update flag in swap file */
5504 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005505 }
5506 }
5507
5508 /* 'fileformats' */
5509 else if (varp == &p_ffs)
5510 {
5511 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5512 errmsg = e_invarg;
5513 else
5514 {
5515 /* also change 'textauto' */
5516 if (*p_ffs == NUL)
5517 p_ta = FALSE;
5518 else
5519 p_ta = TRUE;
5520 }
5521 }
5522
5523#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5524 /* 'cryptkey' */
5525 else if (gvarp == &p_key)
5526 {
5527 /* Make sure the ":set" command doesn't show the new value in the
5528 * history. */
5529 remove_key_from_history();
5530 }
5531#endif
5532
5533 /* 'matchpairs' */
5534 else if (gvarp == &p_mps)
5535 {
5536 /* Check for "x:y,x:y" */
5537 for (p = *varp; *p != NUL; p += 4)
5538 {
5539 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5540 {
5541 errmsg = e_invarg;
5542 break;
5543 }
5544 if (p[3] == NUL)
5545 break;
5546 }
5547 }
5548
5549#ifdef FEAT_COMMENTS
5550 /* 'comments' */
5551 else if (gvarp == &p_com)
5552 {
5553 for (s = *varp; *s; )
5554 {
5555 while (*s && *s != ':')
5556 {
5557 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5558 && !VIM_ISDIGIT(*s) && *s != '-')
5559 {
5560 errmsg = illegal_char(errbuf, *s);
5561 break;
5562 }
5563 ++s;
5564 }
5565 if (*s++ == NUL)
5566 errmsg = (char_u *)N_("E524: Missing colon");
5567 else if (*s == ',' || *s == NUL)
5568 errmsg = (char_u *)N_("E525: Zero length string");
5569 if (errmsg != NULL)
5570 break;
5571 while (*s && *s != ',')
5572 {
5573 if (*s == '\\' && s[1] != NUL)
5574 ++s;
5575 ++s;
5576 }
5577 s = skip_to_option_part(s);
5578 }
5579 }
5580#endif
5581
5582 /* 'listchars' */
5583 else if (varp == &p_lcs)
5584 {
5585 errmsg = set_chars_option(varp);
5586 }
5587
5588#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5589 /* 'fillchars' */
5590 else if (varp == &p_fcs)
5591 {
5592 errmsg = set_chars_option(varp);
5593 }
5594#endif
5595
5596#ifdef FEAT_CMDWIN
5597 /* 'cedit' */
5598 else if (varp == &p_cedit)
5599 {
5600 errmsg = check_cedit();
5601 }
5602#endif
5603
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005604 /* 'verbosefile' */
5605 else if (varp == &p_vfile)
5606 {
5607 verbose_stop();
5608 if (*p_vfile != NUL && verbose_open() == FAIL)
5609 errmsg = e_invarg;
5610 }
5611
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612#ifdef FEAT_VIMINFO
5613 /* 'viminfo' */
5614 else if (varp == &p_viminfo)
5615 {
5616 for (s = p_viminfo; *s;)
5617 {
5618 /* Check it's a valid character */
5619 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5620 {
5621 errmsg = illegal_char(errbuf, *s);
5622 break;
5623 }
5624 if (*s == 'n') /* name is always last one */
5625 {
5626 break;
5627 }
5628 else if (*s == 'r') /* skip until next ',' */
5629 {
5630 while (*++s && *s != ',')
5631 ;
5632 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005633 else if (*s == '%')
5634 {
5635 /* optional number */
5636 while (vim_isdigit(*++s))
5637 ;
5638 }
5639 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640 ++s; /* no extra chars */
5641 else /* must have a number */
5642 {
5643 while (vim_isdigit(*++s))
5644 ;
5645
5646 if (!VIM_ISDIGIT(*(s - 1)))
5647 {
5648 if (errbuf != NULL)
5649 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005650 sprintf((char *)errbuf,
5651 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652 transchar_byte(*(s - 1)));
5653 errmsg = errbuf;
5654 }
5655 else
5656 errmsg = (char_u *)"";
5657 break;
5658 }
5659 }
5660 if (*s == ',')
5661 ++s;
5662 else if (*s)
5663 {
5664 if (errbuf != NULL)
5665 errmsg = (char_u *)N_("E527: Missing comma");
5666 else
5667 errmsg = (char_u *)"";
5668 break;
5669 }
5670 }
5671 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5672 errmsg = (char_u *)N_("E528: Must specify a ' value");
5673 }
5674#endif /* FEAT_VIMINFO */
5675
5676 /* terminal options */
5677 else if (istermoption(&options[opt_idx]) && full_screen)
5678 {
5679 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5680 if (varp == &T_CCO)
5681 {
5682 t_colors = atoi((char *)T_CCO);
5683 if (t_colors <= 1)
5684 {
5685 if (new_value_alloced)
5686 vim_free(T_CCO);
5687 T_CCO = empty_option;
5688 }
5689 /* We now have a different color setup, initialize it again. */
5690 init_highlight(TRUE, FALSE);
5691 }
5692 ttest(FALSE);
5693 if (varp == &T_ME)
5694 {
5695 out_str(T_ME);
5696 redraw_later(CLEAR);
5697#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5698 /* Since t_me has been set, this probably means that the user
5699 * wants to use this as default colors. Need to reset default
5700 * background/foreground colors. */
5701 mch_set_normal_colors();
5702#endif
5703 }
5704 }
5705
5706#ifdef FEAT_LINEBREAK
5707 /* 'showbreak' */
5708 else if (varp == &p_sbr)
5709 {
5710 for (s = p_sbr; *s; )
5711 {
5712 if (ptr2cells(s) != 1)
5713 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005714 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715 }
5716 }
5717#endif
5718
5719#ifdef FEAT_GUI
5720 /* 'guifont' */
5721 else if (varp == &p_guifont)
5722 {
5723 if (gui.in_use)
5724 {
5725 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00005726# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727 /*
5728 * Put up a font dialog and let the user select a new value.
5729 * If this is cancelled go back to the old value but don't
5730 * give an error message.
5731 */
5732 if (STRCMP(p, "*") == 0)
5733 {
5734 p = gui_mch_font_dialog(oldval);
5735
5736 if (new_value_alloced)
5737 free_string_option(p_guifont);
5738
5739 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5740 new_value_alloced = TRUE;
5741 }
5742# endif
5743 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5744 {
5745# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5746 if (STRCMP(p_guifont, "*") == 0)
5747 {
5748 /* Dialog was cancelled: Keep the old value without giving
5749 * an error message. */
5750 if (new_value_alloced)
5751 free_string_option(p_guifont);
5752 p_guifont = vim_strsave(oldval);
5753 new_value_alloced = TRUE;
5754 }
5755 else
5756# endif
5757 errmsg = (char_u *)N_("E596: Invalid font(s)");
5758 }
5759 }
5760 }
5761# ifdef FEAT_XFONTSET
5762 else if (varp == &p_guifontset)
5763 {
5764 if (STRCMP(p_guifontset, "*") == 0)
5765 errmsg = (char_u *)N_("E597: can't select fontset");
5766 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5767 errmsg = (char_u *)N_("E598: Invalid fontset");
5768 }
5769# endif
5770# ifdef FEAT_MBYTE
5771 else if (varp == &p_guifontwide)
5772 {
5773 if (STRCMP(p_guifontwide, "*") == 0)
5774 errmsg = (char_u *)N_("E533: can't select wide font");
5775 else if (gui_get_wide_font() == FAIL)
5776 errmsg = (char_u *)N_("E534: Invalid wide font");
5777 }
5778# endif
5779#endif
5780
5781#ifdef CURSOR_SHAPE
5782 /* 'guicursor' */
5783 else if (varp == &p_guicursor)
5784 errmsg = parse_shape_opt(SHAPE_CURSOR);
5785#endif
5786
5787#ifdef FEAT_MOUSESHAPE
5788 /* 'mouseshape' */
5789 else if (varp == &p_mouseshape)
5790 {
5791 errmsg = parse_shape_opt(SHAPE_MOUSE);
5792 update_mouseshape(-1);
5793 }
5794#endif
5795
5796#ifdef FEAT_PRINTER
5797 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005798 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005799# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005800 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005801 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00005802# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005803#endif
5804
5805#ifdef FEAT_LANGMAP
5806 /* 'langmap' */
5807 else if (varp == &p_langmap)
5808 langmap_set();
5809#endif
5810
5811#ifdef FEAT_LINEBREAK
5812 /* 'breakat' */
5813 else if (varp == &p_breakat)
5814 fill_breakat_flags();
5815#endif
5816
5817#ifdef FEAT_TITLE
5818 /* 'titlestring' and 'iconstring' */
5819 else if (varp == &p_titlestring || varp == &p_iconstring)
5820 {
5821# ifdef FEAT_STL_OPT
5822 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5823
5824 /* NULL => statusline syntax */
5825 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5826 stl_syntax |= flagval;
5827 else
5828 stl_syntax &= ~flagval;
5829# endif
5830 did_set_title(varp == &p_iconstring);
5831
5832 }
5833#endif
5834
5835#ifdef FEAT_GUI
5836 /* 'guioptions' */
5837 else if (varp == &p_go)
5838 gui_init_which_components(oldval);
5839#endif
5840
5841#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5842 /* 'ttymouse' */
5843 else if (varp == &p_ttym)
5844 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00005845 /* Switch the mouse off before changing the escape sequences used for
5846 * that. */
5847 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5849 errmsg = e_invarg;
5850 else
5851 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00005852 if (termcap_active)
5853 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005854 }
5855#endif
5856
5857#ifdef FEAT_VISUAL
5858 /* 'selection' */
5859 else if (varp == &p_sel)
5860 {
5861 if (*p_sel == NUL
5862 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5863 errmsg = e_invarg;
5864 }
5865
5866 /* 'selectmode' */
5867 else if (varp == &p_slm)
5868 {
5869 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5870 errmsg = e_invarg;
5871 }
5872#endif
5873
5874#ifdef FEAT_BROWSE
5875 /* 'browsedir' */
5876 else if (varp == &p_bsdir)
5877 {
5878 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5879 && !mch_isdir(p_bsdir))
5880 errmsg = e_invarg;
5881 }
5882#endif
5883
5884#ifdef FEAT_VISUAL
5885 /* 'keymodel' */
5886 else if (varp == &p_km)
5887 {
5888 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5889 errmsg = e_invarg;
5890 else
5891 {
5892 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5893 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5894 }
5895 }
5896#endif
5897
5898 /* 'mousemodel' */
5899 else if (varp == &p_mousem)
5900 {
5901 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5902 errmsg = e_invarg;
5903#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5904 else if (*p_mousem != *oldval)
5905 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5906 * to create or delete the popup menus. */
5907 gui_motif_update_mousemodel(root_menu);
5908#endif
5909 }
5910
5911 /* 'switchbuf' */
5912 else if (varp == &p_swb)
5913 {
5914 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5915 errmsg = e_invarg;
5916 }
5917
5918 /* 'debug' */
5919 else if (varp == &p_debug)
5920 {
5921 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5922 errmsg = e_invarg;
5923 }
5924
5925 /* 'display' */
5926 else if (varp == &p_dy)
5927 {
5928 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5929 errmsg = e_invarg;
5930 else
5931 (void)init_chartab();
5932
5933 }
5934
5935#ifdef FEAT_VERTSPLIT
5936 /* 'eadirection' */
5937 else if (varp == &p_ead)
5938 {
5939 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5940 errmsg = e_invarg;
5941 }
5942#endif
5943
5944#ifdef FEAT_CLIPBOARD
5945 /* 'clipboard' */
5946 else if (varp == &p_cb)
5947 errmsg = check_clipboard_option();
5948#endif
5949
Bram Moolenaar217ad922005-03-20 22:37:15 +00005950#ifdef FEAT_SYN_HL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005951 /* When 'spelllang' or 'spellfile' is set and there is a window for this
5952 * buffer in which 'spell' is set load the wordlists. */
5953 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00005954 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005955 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005956 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005957
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005958 if (varp == &(curbuf->b_p_spf))
5959 {
5960 l = STRLEN(curbuf->b_p_spf);
5961 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
5962 ".add") != 0))
5963 errmsg = e_invarg;
5964 }
5965
5966 if (errmsg == NULL)
5967 {
5968 FOR_ALL_WINDOWS(wp)
5969 if (wp->w_buffer == curbuf && wp->w_p_spell)
5970 {
5971 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005972# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005973 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005974# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005975 }
5976 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005977 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005978 /* When 'spellcapcheck' is set compile the regexp program. */
5979 else if (varp == &(curbuf->b_p_spc))
5980 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005981 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005982 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005983 /* 'spellsuggest' */
5984 else if (varp == &p_sps)
5985 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005986 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005987 errmsg = e_invarg;
5988 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005989 /* 'mkspellmem' */
5990 else if (varp == &p_msm)
5991 {
5992 if (spell_check_msm() != OK)
5993 errmsg = e_invarg;
5994 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005995#endif
5996
Bram Moolenaar071d4272004-06-13 20:20:40 +00005997#ifdef FEAT_QUICKFIX
5998 /* When 'bufhidden' is set, check for valid value. */
5999 else if (gvarp == &p_bh)
6000 {
6001 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6002 errmsg = e_invarg;
6003 }
6004
6005 /* When 'buftype' is set, check for valid value. */
6006 else if (gvarp == &p_bt)
6007 {
6008 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6009 errmsg = e_invarg;
6010 else
6011 {
6012# ifdef FEAT_WINDOWS
6013 if (curwin->w_status_height)
6014 {
6015 curwin->w_redr_status = TRUE;
6016 redraw_later(VALID);
6017 }
6018# endif
6019 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6020 }
6021 }
6022#endif
6023
6024#ifdef FEAT_STL_OPT
6025 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006026 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006027 {
6028 int wid;
6029
6030 if (varp == &p_ruf) /* reset ru_wid first */
6031 ru_wid = 0;
6032 s = *varp;
6033 if (varp == &p_ruf && *s == '%')
6034 {
6035 /* set ru_wid if 'ruf' starts with "%99(" */
6036 if (*++s == '-') /* ignore a '-' */
6037 s++;
6038 wid = getdigits(&s);
6039 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6040 ru_wid = wid;
6041 else
6042 errmsg = check_stl_option(p_ruf);
6043 }
6044 else
6045 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006046 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047 comp_col();
6048 }
6049#endif
6050
6051#ifdef FEAT_INS_EXPAND
6052 /* check if it is a valid value for 'complete' -- Acevedo */
6053 else if (gvarp == &p_cpt)
6054 {
6055 for (s = *varp; *s;)
6056 {
6057 while(*s == ',' || *s == ' ')
6058 s++;
6059 if (!*s)
6060 break;
6061 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6062 {
6063 errmsg = illegal_char(errbuf, *s);
6064 break;
6065 }
6066 if (*++s != NUL && *s != ',' && *s != ' ')
6067 {
6068 if (s[-1] == 'k' || s[-1] == 's')
6069 {
6070 /* skip optional filename after 'k' and 's' */
6071 while (*s && *s != ',' && *s != ' ')
6072 {
6073 if (*s == '\\')
6074 ++s;
6075 ++s;
6076 }
6077 }
6078 else
6079 {
6080 if (errbuf != NULL)
6081 {
6082 sprintf((char *)errbuf,
6083 _("E535: Illegal character after <%c>"),
6084 *--s);
6085 errmsg = errbuf;
6086 }
6087 else
6088 errmsg = (char_u *)"";
6089 break;
6090 }
6091 }
6092 }
6093 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006094
6095 /* 'completeopt' */
6096 else if (varp == &p_cot)
6097 {
6098 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6099 errmsg = e_invarg;
6100 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101#endif /* FEAT_INS_EXPAND */
6102
6103
6104#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6105 else if (varp == &p_toolbar)
6106 {
6107 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6108 &toolbar_flags, TRUE) != OK)
6109 errmsg = e_invarg;
6110 else
6111 {
6112 out_flush();
6113 gui_mch_show_toolbar((toolbar_flags &
6114 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6115 }
6116 }
6117#endif
6118
6119#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6120 /* 'toolbariconsize': GTK+ 2 only */
6121 else if (varp == &p_tbis)
6122 {
6123 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6124 errmsg = e_invarg;
6125 else
6126 {
6127 out_flush();
6128 gui_mch_show_toolbar((toolbar_flags &
6129 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6130 }
6131 }
6132#endif
6133
6134 /* 'pastetoggle': translate key codes like in a mapping */
6135 else if (varp == &p_pt)
6136 {
6137 if (*p_pt)
6138 {
6139 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
6140 if (p != NULL)
6141 {
6142 if (new_value_alloced)
6143 free_string_option(p_pt);
6144 p_pt = p;
6145 new_value_alloced = TRUE;
6146 }
6147 }
6148 }
6149
6150 /* 'backspace' */
6151 else if (varp == &p_bs)
6152 {
6153 if (VIM_ISDIGIT(*p_bs))
6154 {
6155 if (*p_bs >'2' || p_bs[1] != NUL)
6156 errmsg = e_invarg;
6157 }
6158 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6159 errmsg = e_invarg;
6160 }
6161
6162 /* 'casemap' */
6163 else if (varp == &p_cmp)
6164 {
6165 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6166 errmsg = e_invarg;
6167 }
6168
6169#ifdef FEAT_DIFF
6170 /* 'diffopt' */
6171 else if (varp == &p_dip)
6172 {
6173 if (diffopt_changed() == FAIL)
6174 errmsg = e_invarg;
6175 }
6176#endif
6177
6178#ifdef FEAT_FOLDING
6179 /* 'foldmethod' */
6180 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6181 {
6182 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6183 || *curwin->w_p_fdm == NUL)
6184 errmsg = e_invarg;
6185 else
6186 foldUpdateAll(curwin);
6187 }
6188# ifdef FEAT_EVAL
6189 /* 'foldexpr' */
6190 else if (varp == &curwin->w_p_fde)
6191 {
6192 if (foldmethodIsExpr(curwin))
6193 foldUpdateAll(curwin);
6194 }
6195# endif
6196 /* 'foldmarker' */
6197 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6198 {
6199 p = vim_strchr(*varp, ',');
6200 if (p == NULL)
6201 errmsg = (char_u *)N_("E536: comma required");
6202 else if (p == *varp || p[1] == NUL)
6203 errmsg = e_invarg;
6204 else if (foldmethodIsMarker(curwin))
6205 foldUpdateAll(curwin);
6206 }
6207 /* 'commentstring' */
6208 else if (gvarp == &p_cms)
6209 {
6210 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6211 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6212 }
6213 /* 'foldopen' */
6214 else if (varp == &p_fdo)
6215 {
6216 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6217 errmsg = e_invarg;
6218 }
6219 /* 'foldclose' */
6220 else if (varp == &p_fcl)
6221 {
6222 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6223 errmsg = e_invarg;
6224 }
6225#endif
6226
6227#ifdef FEAT_VIRTUALEDIT
6228 /* 'virtualedit' */
6229 else if (varp == &p_ve)
6230 {
6231 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6232 errmsg = e_invarg;
6233 else if (STRCMP(p_ve, oldval) != 0)
6234 {
6235 /* Recompute cursor position in case the new 've' setting
6236 * changes something. */
6237 validate_virtcol();
6238 coladvance(curwin->w_virtcol);
6239 }
6240 }
6241#endif
6242
6243#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6244 else if (varp == &p_csqf)
6245 {
6246 if (p_csqf != NULL)
6247 {
6248 p = p_csqf;
6249 while (*p != NUL)
6250 {
6251 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6252 || p[1] == NUL
6253 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6254 || (p[2] != NUL && p[2] != ','))
6255 {
6256 errmsg = e_invarg;
6257 break;
6258 }
6259 else if (p[2] == NUL)
6260 break;
6261 else
6262 p += 3;
6263 }
6264 }
6265 }
6266#endif
6267
6268 /* Options that are a list of flags. */
6269 else
6270 {
6271 p = NULL;
6272 if (varp == &p_ww)
6273 p = (char_u *)WW_ALL;
6274 if (varp == &p_shm)
6275 p = (char_u *)SHM_ALL;
6276 else if (varp == &(p_cpo))
6277 p = (char_u *)CPO_ALL;
6278 else if (varp == &(curbuf->b_p_fo))
6279 p = (char_u *)FO_ALL;
6280 else if (varp == &p_mouse)
6281 {
6282#ifdef FEAT_MOUSE
6283 p = (char_u *)MOUSE_ALL;
6284#else
6285 if (*p_mouse != NUL)
6286 errmsg = (char_u *)N_("E538: No mouse support");
6287#endif
6288 }
6289#if defined(FEAT_GUI)
6290 else if (varp == &p_go)
6291 p = (char_u *)GO_ALL;
6292#endif
6293 if (p != NULL)
6294 {
6295 for (s = *varp; *s; ++s)
6296 if (vim_strchr(p, *s) == NULL)
6297 {
6298 errmsg = illegal_char(errbuf, *s);
6299 break;
6300 }
6301 }
6302 }
6303
6304 /*
6305 * If error detected, restore the previous value.
6306 */
6307 if (errmsg != NULL)
6308 {
6309 if (new_value_alloced)
6310 free_string_option(*varp);
6311 *varp = oldval;
6312 /*
6313 * When resetting some values, need to act on it.
6314 */
6315 if (did_chartab)
6316 (void)init_chartab();
6317 if (varp == &p_hl)
6318 (void)highlight_changed();
6319 }
6320 else
6321 {
6322#ifdef FEAT_EVAL
6323 /* Remember where the option was set. */
6324 options[opt_idx].scriptID = current_SID;
6325#endif
6326 /*
6327 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006328 * Use "free_oldval", because recursiveness may change the flags under
6329 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006330 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006331 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006332 free_string_option(oldval);
6333 if (new_value_alloced)
6334 options[opt_idx].flags |= P_ALLOCED;
6335 else
6336 options[opt_idx].flags &= ~P_ALLOCED;
6337
6338 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6339 && (int)options[opt_idx].indir >= PV_BOTH)
6340 {
6341 /* global option with local value set to use global value; free
6342 * the local value and make it empty */
6343 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6344 free_string_option(*(char_u **)p);
6345 *(char_u **)p = empty_option;
6346 }
6347
6348 /* May set global value for local option. */
6349 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6350 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006351
6352#ifdef FEAT_AUTOCMD
6353 /*
6354 * Trigger the autocommand only after setting the flags.
6355 */
6356# ifdef FEAT_SYN_HL
6357 /* When 'syntax' is set, load the syntax of that name */
6358 if (varp == &(curbuf->b_p_syn))
6359 {
6360 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6361 curbuf->b_fname, TRUE, curbuf);
6362 }
6363# endif
6364 else if (varp == &(curbuf->b_p_ft))
6365 {
6366 /* 'filetype' is set, trigger the FileType autocommand */
6367 did_filetype = TRUE;
6368 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6369 curbuf->b_fname, TRUE, curbuf);
6370 }
6371#endif
6372#ifdef FEAT_SYN_HL
6373 if (varp == &(curbuf->b_p_spl))
6374 {
6375 char_u fname[200];
6376
6377 /*
6378 * Source the spell/LANG.vim in 'runtimepath'.
6379 * They could set 'spellcapcheck' depending on the language.
6380 * Use the first name in 'spelllang' up to '_region' or
6381 * '.encoding'.
6382 */
6383 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6384 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6385 break;
6386 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6387 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6388 source_runtime(fname, TRUE);
6389 }
6390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391 }
6392
6393#ifdef FEAT_MOUSE
6394 if (varp == &p_mouse)
6395 {
6396# ifdef FEAT_MOUSE_TTY
6397 if (*p_mouse == NUL)
6398 mch_setmouse(FALSE); /* switch mouse off */
6399 else
6400# endif
6401 setmouse(); /* in case 'mouse' changed */
6402 }
6403#endif
6404
6405 if (curwin->w_curswant != MAXCOL)
6406 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6407 check_redraw(options[opt_idx].flags);
6408
6409 return errmsg;
6410}
6411
6412/*
6413 * Handle setting 'listchars' or 'fillchars'.
6414 * Returns error message, NULL if it's OK.
6415 */
6416 static char_u *
6417set_chars_option(varp)
6418 char_u **varp;
6419{
6420 int round, i, len, entries;
6421 char_u *p, *s;
6422 int c1, c2 = 0;
6423 struct charstab
6424 {
6425 int *cp;
6426 char *name;
6427 };
6428#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6429 static struct charstab filltab[] =
6430 {
6431 {&fill_stl, "stl"},
6432 {&fill_stlnc, "stlnc"},
6433 {&fill_vert, "vert"},
6434 {&fill_fold, "fold"},
6435 {&fill_diff, "diff"},
6436 };
6437#endif
6438 static struct charstab lcstab[] =
6439 {
6440 {&lcs_eol, "eol"},
6441 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006442 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443 {&lcs_prec, "precedes"},
6444 {&lcs_tab2, "tab"},
6445 {&lcs_trail, "trail"},
6446 };
6447 struct charstab *tab;
6448
6449#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6450 if (varp == &p_lcs)
6451#endif
6452 {
6453 tab = lcstab;
6454 entries = sizeof(lcstab) / sizeof(struct charstab);
6455 }
6456#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6457 else
6458 {
6459 tab = filltab;
6460 entries = sizeof(filltab) / sizeof(struct charstab);
6461 }
6462#endif
6463
6464 /* first round: check for valid value, second round: assign values */
6465 for (round = 0; round <= 1; ++round)
6466 {
6467 if (round)
6468 {
6469 /* After checking that the value is valid: set defaults: space for
6470 * 'fillchars', NUL for 'listchars' */
6471 for (i = 0; i < entries; ++i)
6472 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6473 if (varp == &p_lcs)
6474 lcs_tab1 = NUL;
6475#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6476 else
6477 fill_diff = '-';
6478#endif
6479 }
6480 p = *varp;
6481 while (*p)
6482 {
6483 for (i = 0; i < entries; ++i)
6484 {
6485 len = (int)STRLEN(tab[i].name);
6486 if (STRNCMP(p, tab[i].name, len) == 0
6487 && p[len] == ':'
6488 && p[len + 1] != NUL)
6489 {
6490 s = p + len + 1;
6491#ifdef FEAT_MBYTE
6492 c1 = mb_ptr2char_adv(&s);
6493#else
6494 c1 = *s++;
6495#endif
6496 if (tab[i].cp == &lcs_tab2)
6497 {
6498 if (*s == NUL)
6499 continue;
6500#ifdef FEAT_MBYTE
6501 c2 = mb_ptr2char_adv(&s);
6502#else
6503 c2 = *s++;
6504#endif
6505 }
6506 if (*s == ',' || *s == NUL)
6507 {
6508 if (round)
6509 {
6510 if (tab[i].cp == &lcs_tab2)
6511 {
6512 lcs_tab1 = c1;
6513 lcs_tab2 = c2;
6514 }
6515 else
6516 *(tab[i].cp) = c1;
6517
6518 }
6519 p = s;
6520 break;
6521 }
6522 }
6523 }
6524
6525 if (i == entries)
6526 return e_invarg;
6527 if (*p == ',')
6528 ++p;
6529 }
6530 }
6531
6532 return NULL; /* no error */
6533}
6534
6535#ifdef FEAT_STL_OPT
6536/*
6537 * Check validity of options with the 'statusline' format.
6538 * Return error message or NULL.
6539 */
6540 char_u *
6541check_stl_option(s)
6542 char_u *s;
6543{
6544 int itemcnt = 0;
6545 int groupdepth = 0;
6546 static char_u errbuf[80];
6547
6548 while (*s && itemcnt < STL_MAX_ITEM)
6549 {
6550 /* Check for valid keys after % sequences */
6551 while (*s && *s != '%')
6552 s++;
6553 if (!*s)
6554 break;
6555 s++;
6556 if (*s != '%' && *s != ')')
6557 ++itemcnt;
6558 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6559 {
6560 s++;
6561 continue;
6562 }
6563 if (*s == ')')
6564 {
6565 s++;
6566 if (--groupdepth < 0)
6567 break;
6568 continue;
6569 }
6570 if (*s == '-')
6571 s++;
6572 while (VIM_ISDIGIT(*s))
6573 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006574 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006575 continue;
6576 if (*s == '.')
6577 {
6578 s++;
6579 while (*s && VIM_ISDIGIT(*s))
6580 s++;
6581 }
6582 if (*s == '(')
6583 {
6584 groupdepth++;
6585 continue;
6586 }
6587 if (vim_strchr(STL_ALL, *s) == NULL)
6588 {
6589 return illegal_char(errbuf, *s);
6590 }
6591 if (*s == '{')
6592 {
6593 s++;
6594 while (*s != '}' && *s)
6595 s++;
6596 if (*s != '}')
6597 return (char_u *)N_("E540: Unclosed expression sequence");
6598 }
6599 }
6600 if (itemcnt >= STL_MAX_ITEM)
6601 return (char_u *)N_("E541: too many items");
6602 if (groupdepth != 0)
6603 return (char_u *)N_("E542: unbalanced groups");
6604 return NULL;
6605}
6606#endif
6607
6608#ifdef FEAT_CLIPBOARD
6609/*
6610 * Extract the items in the 'clipboard' option and set global values.
6611 */
6612 static char_u *
6613check_clipboard_option()
6614{
6615 int new_unnamed = FALSE;
6616 int new_autoselect = FALSE;
6617 int new_autoselectml = FALSE;
6618 regprog_T *new_exclude_prog = NULL;
6619 char_u *errmsg = NULL;
6620 char_u *p;
6621
6622 for (p = p_cb; *p != NUL; )
6623 {
6624 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6625 {
6626 new_unnamed = TRUE;
6627 p += 7;
6628 }
6629 else if (STRNCMP(p, "autoselect", 10) == 0
6630 && (p[10] == ',' || p[10] == NUL))
6631 {
6632 new_autoselect = TRUE;
6633 p += 10;
6634 }
6635 else if (STRNCMP(p, "autoselectml", 12) == 0
6636 && (p[12] == ',' || p[12] == NUL))
6637 {
6638 new_autoselectml = TRUE;
6639 p += 12;
6640 }
6641 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6642 {
6643 p += 8;
6644 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6645 if (new_exclude_prog == NULL)
6646 errmsg = e_invarg;
6647 break;
6648 }
6649 else
6650 {
6651 errmsg = e_invarg;
6652 break;
6653 }
6654 if (*p == ',')
6655 ++p;
6656 }
6657 if (errmsg == NULL)
6658 {
6659 clip_unnamed = new_unnamed;
6660 clip_autoselect = new_autoselect;
6661 clip_autoselectml = new_autoselectml;
6662 vim_free(clip_exclude_prog);
6663 clip_exclude_prog = new_exclude_prog;
6664 }
6665 else
6666 vim_free(new_exclude_prog);
6667
6668 return errmsg;
6669}
6670#endif
6671
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006672#ifdef FEAT_SYN_HL
6673/*
6674 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6675 * Return error message when failed, NULL when OK.
6676 */
6677 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006678compile_cap_prog(buf)
6679 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006680{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006681 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006682 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006683
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006684 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006685 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006686 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006687 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006688 /* Prepend a ^ so that we only match at one column */
6689 re = concat_str((char_u *)"^", buf->b_p_spc);
6690 if (re != NULL)
6691 {
6692 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
6693 if (buf->b_cap_prog == NULL)
6694 {
6695 buf->b_cap_prog = rp; /* restore the previous program */
6696 return e_invarg;
6697 }
6698 vim_free(re);
6699 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006700 }
6701
6702 vim_free(rp);
6703 return NULL;
6704}
6705#endif
6706
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006707#if defined(FEAT_EVAL) || defined(PROTO)
6708/*
6709 * Set the script ID of option "name" to "id".
6710 */
6711 void
6712set_option_scriptID(name, id)
6713 char_u *name;
6714 int id;
6715{
6716 int opt_idx = findoption(name);
6717
6718 if (opt_idx == -1) /* not found (should not happen) */
6719 EMSG2(_(e_intern2), "set_option_scriptID()");
6720 else
6721 options[opt_idx].scriptID = id;
6722}
6723#endif
6724
Bram Moolenaar071d4272004-06-13 20:20:40 +00006725/*
6726 * Set the value of a boolean option, and take care of side effects.
6727 * Returns NULL for success, or an error message for an error.
6728 */
6729 static char_u *
6730set_bool_option(opt_idx, varp, value, opt_flags)
6731 int opt_idx; /* index in options[] table */
6732 char_u *varp; /* pointer to the option variable */
6733 int value; /* new value */
6734 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6735{
6736 int old_value = *(int *)varp;
6737
Bram Moolenaar071d4272004-06-13 20:20:40 +00006738 /* Disallow changing some options from secure mode */
6739 if ((secure
6740#ifdef HAVE_SANDBOX
6741 || sandbox != 0
6742#endif
6743 ) && (options[opt_idx].flags & P_SECURE))
6744 return e_secure;
6745
6746 *(int *)varp = value; /* set the new value */
6747#ifdef FEAT_EVAL
6748 /* Remember where the option was set. */
6749 options[opt_idx].scriptID = current_SID;
6750#endif
6751
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006752#ifdef FEAT_GUI
6753 need_mouse_correct = TRUE;
6754#endif
6755
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 /* May set global value for local option. */
6757 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6758 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6759
6760 /*
6761 * Handle side effects of changing a bool option.
6762 */
6763
6764 /* 'compatible' */
6765 if ((int *)varp == &p_cp)
6766 {
6767 compatible_set();
6768 }
6769
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770 else if ((int *)varp == &curbuf->b_p_ro)
6771 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006772 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6774 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006775
6776 /* when 'readonly' is set may give W10 again */
6777 if (curbuf->b_p_ro)
6778 curbuf->b_did_warn = FALSE;
6779
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780#ifdef FEAT_TITLE
6781 need_maketitle = TRUE;
6782#endif
6783 }
6784
6785#ifdef FEAT_TITLE
6786 /* when 'modifiable' is changed, redraw the window title */
6787 else if ((int *)varp == &curbuf->b_p_ma)
6788 need_maketitle = TRUE;
6789 /* when 'endofline' is changed, redraw the window title */
6790 else if ((int *)varp == &curbuf->b_p_eol)
6791 need_maketitle = TRUE;
6792#endif
6793
6794 /* when 'bin' is set also set some other options */
6795 else if ((int *)varp == &curbuf->b_p_bin)
6796 {
6797 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6798#ifdef FEAT_TITLE
6799 need_maketitle = TRUE;
6800#endif
6801 }
6802
6803#ifdef FEAT_AUTOCMD
6804 /* when 'buflisted' changes, trigger autocommands */
6805 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6806 {
6807 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6808 NULL, NULL, TRUE, curbuf);
6809 }
6810#endif
6811
6812 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6813 else if ((int *)varp == &curbuf->b_p_swf)
6814 {
6815 if (curbuf->b_p_swf && p_uc)
6816 ml_open_file(curbuf); /* create the swap file */
6817 else
6818 mf_close_file(curbuf, TRUE); /* remove the swap file */
6819 }
6820
6821 /* when 'terse' is set change 'shortmess' */
6822 else if ((int *)varp == &p_terse)
6823 {
6824 char_u *p;
6825
6826 p = vim_strchr(p_shm, SHM_SEARCH);
6827
6828 /* insert 's' in p_shm */
6829 if (p_terse && p == NULL)
6830 {
6831 STRCPY(IObuff, p_shm);
6832 STRCAT(IObuff, "s");
6833 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006834# ifdef FEAT_EVAL
6835 set_option_scriptID((char_u *)"shm", current_SID);
6836# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006837 }
6838 /* remove 's' from p_shm */
6839 else if (!p_terse && p != NULL)
6840 mch_memmove(p, p + 1, STRLEN(p));
6841 }
6842
6843 /* when 'paste' is set or reset also change other options */
6844 else if ((int *)varp == &p_paste)
6845 {
6846 paste_option_changed();
6847 }
6848
6849 /* when 'insertmode' is set from an autocommand need to do work here */
6850 else if ((int *)varp == &p_im)
6851 {
6852 if (p_im)
6853 {
6854 if ((State & INSERT) == 0)
6855 need_start_insertmode = TRUE;
6856 stop_insert_mode = FALSE;
6857 }
6858 else
6859 {
6860 need_start_insertmode = FALSE;
6861 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00006862 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006863 clear_cmdline = TRUE; /* remove "(insert)" */
6864 restart_edit = 0;
6865 }
6866 }
6867
6868 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6869 else if ((int *)varp == &p_ic && p_hls)
6870 {
6871 redraw_all_later(NOT_VALID);
6872 }
6873
6874#ifdef FEAT_SEARCH_EXTRA
6875 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6876 else if ((int *)varp == &p_hls)
6877 {
6878 no_hlsearch = FALSE;
6879 }
6880#endif
6881
6882#ifdef FEAT_SCROLLBIND
6883 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6884 * at the end of normal_cmd() */
6885 else if ((int *)varp == &curwin->w_p_scb)
6886 {
6887 if (curwin->w_p_scb)
6888 do_check_scrollbind(FALSE);
6889 }
6890#endif
6891
6892#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6893 /* There can be only one window with 'previewwindow' set. */
6894 else if ((int *)varp == &curwin->w_p_pvw)
6895 {
6896 if (curwin->w_p_pvw)
6897 {
6898 win_T *win;
6899
6900 for (win = firstwin; win != NULL; win = win->w_next)
6901 if (win->w_p_pvw && win != curwin)
6902 {
6903 curwin->w_p_pvw = FALSE;
6904 return (char_u *)N_("E590: A preview window already exists");
6905 }
6906 }
6907 }
6908#endif
6909
6910 /* when 'textmode' is set or reset also change 'fileformat' */
6911 else if ((int *)varp == &curbuf->b_p_tx)
6912 {
6913 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6914 }
6915
6916 /* when 'textauto' is set or reset also change 'fileformats' */
6917 else if ((int *)varp == &p_ta)
6918 {
6919 set_string_option_direct((char_u *)"ffs", -1,
6920 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6921 OPT_FREE | opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006922# ifdef FEAT_EVAL
6923 set_option_scriptID((char_u *)"ffs", current_SID);
6924# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 }
6926
6927 /*
6928 * When 'lisp' option changes include/exclude '-' in
6929 * keyword characters.
6930 */
6931#ifdef FEAT_LISP
6932 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6933 {
6934 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6935 }
6936#endif
6937
6938#ifdef FEAT_TITLE
6939 /* when 'title' changed, may need to change the title; same for 'icon' */
6940 else if ((int *)varp == &p_title)
6941 {
6942 did_set_title(FALSE);
6943 }
6944
6945 else if ((int *)varp == &p_icon)
6946 {
6947 did_set_title(TRUE);
6948 }
6949#endif
6950
6951 else if ((int *)varp == &curbuf->b_changed)
6952 {
6953 if (!value)
6954 save_file_ff(curbuf); /* Buffer is unchanged */
6955#ifdef FEAT_TITLE
6956 need_maketitle = TRUE;
6957#endif
6958#ifdef FEAT_AUTOCMD
6959 modified_was_set = value;
6960#endif
6961 }
6962
6963#ifdef BACKSLASH_IN_FILENAME
6964 else if ((int *)varp == &p_ssl)
6965 {
6966 if (p_ssl)
6967 {
6968 psepc = '/';
6969 psepcN = '\\';
6970 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006971 }
6972 else
6973 {
6974 psepc = '\\';
6975 psepcN = '/';
6976 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006977 }
6978
6979 /* need to adjust the file name arguments and buffer names. */
6980 buflist_slash_adjust();
6981 alist_slash_adjust();
6982# ifdef FEAT_EVAL
6983 scriptnames_slash_adjust();
6984# endif
6985 }
6986#endif
6987
6988 /* If 'wrap' is set, set w_leftcol to zero. */
6989 else if ((int *)varp == &curwin->w_p_wrap)
6990 {
6991 if (curwin->w_p_wrap)
6992 curwin->w_leftcol = 0;
6993 }
6994
6995#ifdef FEAT_WINDOWS
6996 else if ((int *)varp == &p_ea)
6997 {
6998 if (p_ea && !old_value)
6999 win_equal(curwin, FALSE, 0);
7000 }
7001#endif
7002
7003 else if ((int *)varp == &p_wiv)
7004 {
7005 /*
7006 * When 'weirdinvert' changed, set/reset 't_xs'.
7007 * Then set 'weirdinvert' according to value of 't_xs'.
7008 */
7009 if (p_wiv && !old_value)
7010 T_XS = (char_u *)"y";
7011 else if (!p_wiv && old_value)
7012 T_XS = empty_option;
7013 p_wiv = (*T_XS != NUL);
7014 }
7015
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007016#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 else if ((int *)varp == &p_beval)
7018 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019 if (p_beval == TRUE)
7020 gui_mch_enable_beval_area(balloonEval);
7021 else
7022 gui_mch_disable_beval_area(balloonEval);
7023 }
7024
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007025# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026 else if ((int *)varp == &p_acd)
7027 {
7028 if (p_acd && curbuf->b_ffname != NULL
7029 && vim_chdirfile(curbuf->b_ffname) == OK)
7030 shorten_fnames(TRUE);
7031 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007032# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007033#endif
7034
7035#ifdef FEAT_DIFF
7036 /* 'diff' */
7037 else if ((int *)varp == &curwin->w_p_diff)
7038 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007039 /* May add or remove the buffer from the list of diff buffers. */
7040 diff_buf_adjust(curwin);
7041# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 if (foldmethodIsDiff(curwin))
7043 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007044# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007045 }
7046#endif
7047
7048#ifdef USE_IM_CONTROL
7049 /* 'imdisable' */
7050 else if ((int *)varp == &p_imdisable)
7051 {
7052 /* Only de-activate it here, it will be enabled when changing mode. */
7053 if (p_imdisable)
7054 im_set_active(FALSE);
7055 }
7056#endif
7057
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007058#ifdef FEAT_SYN_HL
7059 /* 'spell' */
7060 else if ((int *)varp == &curwin->w_p_spell)
7061 {
7062 if (curwin->w_p_spell)
7063 {
7064 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007065
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007066 if (errmsg != NULL)
7067 EMSG(_(errmsg));
7068 }
7069 }
7070#endif
7071
Bram Moolenaar071d4272004-06-13 20:20:40 +00007072#ifdef FEAT_FKMAP
7073 else if ((int *)varp == &p_altkeymap)
7074 {
7075 if (old_value != p_altkeymap)
7076 {
7077 if (!p_altkeymap)
7078 {
7079 p_hkmap = p_fkmap;
7080 p_fkmap = 0;
7081 }
7082 else
7083 {
7084 p_fkmap = p_hkmap;
7085 p_hkmap = 0;
7086 }
7087 (void)init_chartab();
7088 }
7089 }
7090
7091 /*
7092 * In case some second language keymapping options have changed, check
7093 * and correct the setting in a consistent way.
7094 */
7095
7096 /*
7097 * If hkmap or fkmap are set, reset Arabic keymapping.
7098 */
7099 if ((p_hkmap || p_fkmap) && p_altkeymap)
7100 {
7101 p_altkeymap = p_fkmap;
7102# ifdef FEAT_ARABIC
7103 curwin->w_p_arab = FALSE;
7104# endif
7105 (void)init_chartab();
7106 }
7107
7108 /*
7109 * If hkmap set, reset Farsi keymapping.
7110 */
7111 if (p_hkmap && p_altkeymap)
7112 {
7113 p_altkeymap = 0;
7114 p_fkmap = 0;
7115# ifdef FEAT_ARABIC
7116 curwin->w_p_arab = FALSE;
7117# endif
7118 (void)init_chartab();
7119 }
7120
7121 /*
7122 * If fkmap set, reset Hebrew keymapping.
7123 */
7124 if (p_fkmap && !p_altkeymap)
7125 {
7126 p_altkeymap = 1;
7127 p_hkmap = 0;
7128# ifdef FEAT_ARABIC
7129 curwin->w_p_arab = FALSE;
7130# endif
7131 (void)init_chartab();
7132 }
7133#endif
7134
7135#ifdef FEAT_ARABIC
7136 if ((int *)varp == &curwin->w_p_arab)
7137 {
7138 if (curwin->w_p_arab)
7139 {
7140 /*
7141 * 'arabic' is set, handle various sub-settings.
7142 */
7143 if (!p_tbidi)
7144 {
7145 /* set rightleft mode */
7146 if (!curwin->w_p_rl)
7147 {
7148 curwin->w_p_rl = TRUE;
7149 changed_window_setting();
7150 }
7151
7152 /* Enable Arabic shaping (major part of what Arabic requires) */
7153 if (!p_arshape)
7154 {
7155 p_arshape = TRUE;
7156 redraw_later_clear();
7157 }
7158 }
7159
7160 /* Arabic requires a utf-8 encoding, inform the user if its not
7161 * set. */
7162 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007163 {
7164 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
7166 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168
7169# ifdef FEAT_MBYTE
7170 /* set 'delcombine' */
7171 p_deco = TRUE;
7172# endif
7173
7174# ifdef FEAT_KEYMAP
7175 /* Force-set the necessary keymap for arabic */
7176 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7177 OPT_LOCAL);
7178# endif
7179# ifdef FEAT_FKMAP
7180 p_altkeymap = 0;
7181 p_hkmap = 0;
7182 p_fkmap = 0;
7183 (void)init_chartab();
7184# endif
7185 }
7186 else
7187 {
7188 /*
7189 * 'arabic' is reset, handle various sub-settings.
7190 */
7191 if (!p_tbidi)
7192 {
7193 /* reset rightleft mode */
7194 if (curwin->w_p_rl)
7195 {
7196 curwin->w_p_rl = FALSE;
7197 changed_window_setting();
7198 }
7199
7200 /* 'arabicshape' isn't reset, it is a global option and
7201 * another window may still need it "on". */
7202 }
7203
7204 /* 'delcombine' isn't reset, it is a global option and another
7205 * window may still want it "on". */
7206
7207# ifdef FEAT_KEYMAP
7208 /* Revert to the default keymap */
7209 curbuf->b_p_iminsert = B_IMODE_NONE;
7210 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7211# endif
7212 }
7213 }
7214#endif
7215
7216 /*
7217 * End of handling side effects for bool options.
7218 */
7219
7220 options[opt_idx].flags |= P_WAS_SET;
7221
7222 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7223 if (curwin->w_curswant != MAXCOL)
7224 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7225 check_redraw(options[opt_idx].flags);
7226
7227 return NULL;
7228}
7229
7230/*
7231 * Set the value of a number option, and take care of side effects.
7232 * Returns NULL for success, or an error message for an error.
7233 */
7234 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007235set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007236 int opt_idx; /* index in options[] table */
7237 char_u *varp; /* pointer to the option variable */
7238 long value; /* new value */
7239 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007240 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007241 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7242 OPT_MODELINE */
7243{
7244 char_u *errmsg = NULL;
7245 long old_value = *(long *)varp;
7246 long old_Rows = Rows; /* remember old Rows */
7247 long old_Columns = Columns; /* remember old Columns */
7248 long *pp = (long *)varp;
7249
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007250 /* Disallow changing some options from secure mode. */
7251 if ((secure
7252#ifdef HAVE_SANDBOX
7253 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007255 ) && (options[opt_idx].flags & P_SECURE))
7256 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007257
7258 *pp = value;
7259#ifdef FEAT_EVAL
7260 /* Remember where the option was set. */
7261 options[opt_idx].scriptID = current_SID;
7262#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007263#ifdef FEAT_GUI
7264 need_mouse_correct = TRUE;
7265#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007266
7267 if (curbuf->b_p_sw <= 0)
7268 {
7269 errmsg = e_positive;
7270 curbuf->b_p_sw = curbuf->b_p_ts;
7271 }
7272
7273 /*
7274 * Number options that need some action when changed
7275 */
7276#ifdef FEAT_WINDOWS
7277 if (pp == &p_wh || pp == &p_hh)
7278 {
7279 if (p_wh < 1)
7280 {
7281 errmsg = e_positive;
7282 p_wh = 1;
7283 }
7284 if (p_wmh > p_wh)
7285 {
7286 errmsg = e_winheight;
7287 p_wh = p_wmh;
7288 }
7289 if (p_hh < 0)
7290 {
7291 errmsg = e_positive;
7292 p_hh = 0;
7293 }
7294
7295 /* Change window height NOW */
7296 if (lastwin != firstwin)
7297 {
7298 if (pp == &p_wh && curwin->w_height < p_wh)
7299 win_setheight((int)p_wh);
7300 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7301 win_setheight((int)p_hh);
7302 }
7303 }
7304
7305 /* 'winminheight' */
7306 else if (pp == &p_wmh)
7307 {
7308 if (p_wmh < 0)
7309 {
7310 errmsg = e_positive;
7311 p_wmh = 0;
7312 }
7313 if (p_wmh > p_wh)
7314 {
7315 errmsg = e_winheight;
7316 p_wmh = p_wh;
7317 }
7318 win_setminheight();
7319 }
7320
7321# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007322 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007323 {
7324 if (p_wiw < 1)
7325 {
7326 errmsg = e_positive;
7327 p_wiw = 1;
7328 }
7329 if (p_wmw > p_wiw)
7330 {
7331 errmsg = e_winwidth;
7332 p_wiw = p_wmw;
7333 }
7334
7335 /* Change window width NOW */
7336 if (lastwin != firstwin && curwin->w_width < p_wiw)
7337 win_setwidth((int)p_wiw);
7338 }
7339
7340 /* 'winminwidth' */
7341 else if (pp == &p_wmw)
7342 {
7343 if (p_wmw < 0)
7344 {
7345 errmsg = e_positive;
7346 p_wmw = 0;
7347 }
7348 if (p_wmw > p_wiw)
7349 {
7350 errmsg = e_winwidth;
7351 p_wmw = p_wiw;
7352 }
7353 win_setminheight();
7354 }
7355# endif
7356
7357#endif
7358
7359#ifdef FEAT_WINDOWS
7360 /* (re)set last window status line */
7361 else if (pp == &p_ls)
7362 {
7363 last_status(FALSE);
7364 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007365
7366 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007367 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007368 {
7369 shell_new_rows(); /* recompute window positions and heights */
7370 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007371#endif
7372
7373#ifdef FEAT_GUI
7374 else if (pp == &p_linespace)
7375 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007376 /* Recompute gui.char_height and resize the Vim window to keep the
7377 * same number of lines. */
7378 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007379 gui_set_shellsize(FALSE, FALSE);
7380 }
7381#endif
7382
7383#ifdef FEAT_FOLDING
7384 /* 'foldlevel' */
7385 else if (pp == &curwin->w_p_fdl)
7386 {
7387 if (curwin->w_p_fdl < 0)
7388 curwin->w_p_fdl = 0;
7389 newFoldLevel();
7390 }
7391
7392 /* 'foldminlevel' */
7393 else if (pp == &curwin->w_p_fml)
7394 {
7395 foldUpdateAll(curwin);
7396 }
7397
7398 /* 'foldnestmax' */
7399 else if (pp == &curwin->w_p_fdn)
7400 {
7401 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7402 foldUpdateAll(curwin);
7403 }
7404
7405 /* 'foldcolumn' */
7406 else if (pp == &curwin->w_p_fdc)
7407 {
7408 if (curwin->w_p_fdc < 0)
7409 {
7410 errmsg = e_positive;
7411 curwin->w_p_fdc = 0;
7412 }
7413 else if (curwin->w_p_fdc > 12)
7414 {
7415 errmsg = e_invarg;
7416 curwin->w_p_fdc = 12;
7417 }
7418 }
7419
7420 /* 'shiftwidth' or 'tabstop' */
7421 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7422 {
7423 if (foldmethodIsIndent(curwin))
7424 foldUpdateAll(curwin);
7425 }
7426#endif /* FEAT_FOLDING */
7427
7428 else if (pp == &curbuf->b_p_iminsert)
7429 {
7430 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7431 {
7432 errmsg = e_invarg;
7433 curbuf->b_p_iminsert = B_IMODE_NONE;
7434 }
7435 p_iminsert = curbuf->b_p_iminsert;
7436 if (termcap_active) /* don't do this in the alternate screen */
7437 showmode();
7438#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7439 /* Show/unshow value of 'keymap' in status lines. */
7440 status_redraw_curbuf();
7441#endif
7442 }
7443
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007444 else if (pp == &p_window)
7445 {
7446 if (p_window < 1)
7447 p_window = 1;
7448 else if (p_window >= Rows)
7449 p_window = Rows - 1;
7450 }
7451
Bram Moolenaar071d4272004-06-13 20:20:40 +00007452 else if (pp == &curbuf->b_p_imsearch)
7453 {
7454 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7455 {
7456 errmsg = e_invarg;
7457 curbuf->b_p_imsearch = B_IMODE_NONE;
7458 }
7459 p_imsearch = curbuf->b_p_imsearch;
7460 }
7461
7462#ifdef FEAT_TITLE
7463 /* if 'titlelen' has changed, redraw the title */
7464 else if (pp == &p_titlelen)
7465 {
7466 if (p_titlelen < 0)
7467 {
7468 errmsg = e_positive;
7469 p_titlelen = 85;
7470 }
7471 if (starting != NO_SCREEN && old_value != p_titlelen)
7472 need_maketitle = TRUE;
7473 }
7474#endif
7475
7476 /* if p_ch changed value, change the command line height */
7477 else if (pp == &p_ch)
7478 {
7479 if (p_ch < 1)
7480 {
7481 errmsg = e_positive;
7482 p_ch = 1;
7483 }
7484
7485 /* Only compute the new window layout when startup has been
7486 * completed. Otherwise the frame sizes may be wrong. */
7487 if (p_ch != old_value && full_screen
7488#ifdef FEAT_GUI
7489 && !gui.starting
7490#endif
7491 )
7492 command_height(old_value);
7493 }
7494
7495 /* when 'updatecount' changes from zero to non-zero, open swap files */
7496 else if (pp == &p_uc)
7497 {
7498 if (p_uc < 0)
7499 {
7500 errmsg = e_positive;
7501 p_uc = 100;
7502 }
7503 if (p_uc && !old_value)
7504 ml_open_files();
7505 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007506#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007507 else if (pp == &p_mzq)
7508 mzvim_reset_timer();
7509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510
7511 /* sync undo before 'undolevels' changes */
7512 else if (pp == &p_ul)
7513 {
7514 /* use the old value, otherwise u_sync() may not work properly */
7515 p_ul = old_value;
7516 u_sync();
7517 p_ul = value;
7518 }
7519
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007520#ifdef FEAT_LINEBREAK
7521 /* 'numberwidth' must be positive */
7522 else if (pp == &curwin->w_p_nuw)
7523 {
7524 if (curwin->w_p_nuw < 1)
7525 {
7526 errmsg = e_positive;
7527 curwin->w_p_nuw = 1;
7528 }
7529 if (curwin->w_p_nuw > 10)
7530 {
7531 errmsg = e_invarg;
7532 curwin->w_p_nuw = 10;
7533 }
7534 curwin->w_nrwidth_line_count = 0;
7535 }
7536#endif
7537
Bram Moolenaar071d4272004-06-13 20:20:40 +00007538 /*
7539 * Check the bounds for numeric options here
7540 */
7541 if (Rows < min_rows() && full_screen)
7542 {
7543 if (errbuf != NULL)
7544 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007545 vim_snprintf((char *)errbuf, errbuflen,
7546 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547 errmsg = errbuf;
7548 }
7549 Rows = min_rows();
7550 }
7551 if (Columns < MIN_COLUMNS && full_screen)
7552 {
7553 if (errbuf != NULL)
7554 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007555 vim_snprintf((char *)errbuf, errbuflen,
7556 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557 errmsg = errbuf;
7558 }
7559 Columns = MIN_COLUMNS;
7560 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007561 /* Limit the values to avoid an overflow in Rows * Columns. */
7562 if (Columns > 10000)
7563 Columns = 10000;
7564 if (Rows > 1000)
7565 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007566
7567#ifdef DJGPP
7568 /* avoid a crash by checking for a too large value of 'columns' */
7569 if (old_Columns != Columns && full_screen && term_console)
7570 mch_check_columns();
7571#endif
7572
7573 /*
7574 * If the screen (shell) height has been changed, assume it is the
7575 * physical screenheight.
7576 */
7577 if (old_Rows != Rows || old_Columns != Columns)
7578 {
7579 /* Changing the screen size is not allowed while updating the screen. */
7580 if (updating_screen)
7581 *pp = old_value;
7582 else if (full_screen
7583#ifdef FEAT_GUI
7584 && !gui.starting
7585#endif
7586 )
7587 set_shellsize((int)Columns, (int)Rows, TRUE);
7588 else
7589 {
7590 /* Postpone the resizing; check the size and cmdline position for
7591 * messages. */
7592 check_shellsize();
7593 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7594 cmdline_row = Rows - p_ch;
7595 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007596 if (p_window >= Rows)
7597 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007598 }
7599
7600 if (curbuf->b_p_sts < 0)
7601 {
7602 errmsg = e_positive;
7603 curbuf->b_p_sts = 0;
7604 }
7605 if (curbuf->b_p_ts <= 0)
7606 {
7607 errmsg = e_positive;
7608 curbuf->b_p_ts = 8;
7609 }
7610 if (curbuf->b_p_tw < 0)
7611 {
7612 errmsg = e_positive;
7613 curbuf->b_p_tw = 0;
7614 }
7615 if (p_tm < 0)
7616 {
7617 errmsg = e_positive;
7618 p_tm = 0;
7619 }
7620 if ((curwin->w_p_scr <= 0
7621 || (curwin->w_p_scr > curwin->w_height
7622 && curwin->w_height > 0))
7623 && full_screen)
7624 {
7625 if (pp == &(curwin->w_p_scr))
7626 {
7627 if (curwin->w_p_scr != 0)
7628 errmsg = e_scroll;
7629 win_comp_scroll(curwin);
7630 }
7631 /* If 'scroll' became invalid because of a side effect silently adjust
7632 * it. */
7633 else if (curwin->w_p_scr <= 0)
7634 curwin->w_p_scr = 1;
7635 else /* curwin->w_p_scr > curwin->w_height */
7636 curwin->w_p_scr = curwin->w_height;
7637 }
7638 if (p_report < 0)
7639 {
7640 errmsg = e_positive;
7641 p_report = 1;
7642 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007643 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007644 {
7645 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7646 p_sj = Rows / 2;
7647 else
7648 {
7649 errmsg = e_scroll;
7650 p_sj = 1;
7651 }
7652 }
7653 if (p_so < 0 && full_screen)
7654 {
7655 errmsg = e_scroll;
7656 p_so = 0;
7657 }
7658 if (p_siso < 0 && full_screen)
7659 {
7660 errmsg = e_positive;
7661 p_siso = 0;
7662 }
7663#ifdef FEAT_CMDWIN
7664 if (p_cwh < 1)
7665 {
7666 errmsg = e_positive;
7667 p_cwh = 1;
7668 }
7669#endif
7670 if (p_ut < 0)
7671 {
7672 errmsg = e_positive;
7673 p_ut = 2000;
7674 }
7675 if (p_ss < 0)
7676 {
7677 errmsg = e_positive;
7678 p_ss = 0;
7679 }
7680
7681 /* May set global value for local option. */
7682 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7683 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7684
7685 options[opt_idx].flags |= P_WAS_SET;
7686
7687 comp_col(); /* in case 'columns' or 'ls' changed */
7688 if (curwin->w_curswant != MAXCOL)
7689 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7690 check_redraw(options[opt_idx].flags);
7691
7692 return errmsg;
7693}
7694
7695/*
7696 * Called after an option changed: check if something needs to be redrawn.
7697 */
7698 static void
7699check_redraw(flags)
7700 long_u flags;
7701{
7702 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7703 int clear = (flags & P_RCLR) == P_RCLR;
7704 int all = ((flags & P_RALL) == P_RALL || clear);
7705
7706#ifdef FEAT_WINDOWS
7707 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7708 status_redraw_all();
7709#endif
7710
7711 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7712 changed_window_setting();
7713 if (flags & P_RBUF)
7714 redraw_curbuf_later(NOT_VALID);
7715 if (clear)
7716 redraw_all_later(CLEAR);
7717 else if (all)
7718 redraw_all_later(NOT_VALID);
7719}
7720
7721/*
7722 * Find index for option 'arg'.
7723 * Return -1 if not found.
7724 */
7725 static int
7726findoption(arg)
7727 char_u *arg;
7728{
7729 int opt_idx;
7730 char *s, *p;
7731 static short quick_tab[27] = {0, 0}; /* quick access table */
7732 int is_term_opt;
7733
7734 /*
7735 * For first call: Initialize the quick-access table.
7736 * It contains the index for the first option that starts with a certain
7737 * letter. There are 26 letters, plus the first "t_" option.
7738 */
7739 if (quick_tab[1] == 0)
7740 {
7741 p = options[0].fullname;
7742 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7743 {
7744 if (s[0] != p[0])
7745 {
7746 if (s[0] == 't' && s[1] == '_')
7747 quick_tab[26] = opt_idx;
7748 else
7749 quick_tab[CharOrdLow(s[0])] = opt_idx;
7750 }
7751 p = s;
7752 }
7753 }
7754
7755 /*
7756 * Check for name starting with an illegal character.
7757 */
7758#ifdef EBCDIC
7759 if (!islower(arg[0]))
7760#else
7761 if (arg[0] < 'a' || arg[0] > 'z')
7762#endif
7763 return -1;
7764
7765 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7766 if (is_term_opt)
7767 opt_idx = quick_tab[26];
7768 else
7769 opt_idx = quick_tab[CharOrdLow(arg[0])];
7770 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7771 {
7772 if (STRCMP(arg, s) == 0) /* match full name */
7773 break;
7774 }
7775 if (s == NULL && !is_term_opt)
7776 {
7777 opt_idx = quick_tab[CharOrdLow(arg[0])];
7778 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7779 {
7780 s = options[opt_idx].shortname;
7781 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7782 break;
7783 s = NULL;
7784 }
7785 }
7786 if (s == NULL)
7787 opt_idx = -1;
7788 return opt_idx;
7789}
7790
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007791#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792/*
7793 * Get the value for an option.
7794 *
7795 * Returns:
7796 * Number or Toggle option: 1, *numval gets value.
7797 * String option: 0, *stringval gets allocated string.
7798 * Hidden Number or Toggle option: -1.
7799 * hidden String option: -2.
7800 * unknown option: -3.
7801 */
7802 int
7803get_option_value(name, numval, stringval, opt_flags)
7804 char_u *name;
7805 long *numval;
7806 char_u **stringval; /* NULL when only checking existance */
7807 int opt_flags;
7808{
7809 int opt_idx;
7810 char_u *varp;
7811
7812 opt_idx = findoption(name);
7813 if (opt_idx < 0) /* unknown option */
7814 return -3;
7815
7816 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7817
7818 if (options[opt_idx].flags & P_STRING)
7819 {
7820 if (varp == NULL) /* hidden option */
7821 return -2;
7822 if (stringval != NULL)
7823 {
7824#ifdef FEAT_CRYPT
7825 /* never return the value of the crypt key */
7826 if ((char_u **)varp == &curbuf->b_p_key)
7827 *stringval = vim_strsave((char_u *)"*****");
7828 else
7829#endif
7830 *stringval = vim_strsave(*(char_u **)(varp));
7831 }
7832 return 0;
7833 }
7834
7835 if (varp == NULL) /* hidden option */
7836 return -1;
7837 if (options[opt_idx].flags & P_NUM)
7838 *numval = *(long *)varp;
7839 else
7840 {
7841 /* Special case: 'modified' is b_changed, but we also want to consider
7842 * it set when 'ff' or 'fenc' changed. */
7843 if ((int *)varp == &curbuf->b_changed)
7844 *numval = curbufIsChanged();
7845 else
7846 *numval = *(int *)varp;
7847 }
7848 return 1;
7849}
7850#endif
7851
7852/*
7853 * Set the value of option "name".
7854 * Use "string" for string options, use "number" for other options.
7855 */
7856 void
7857set_option_value(name, number, string, opt_flags)
7858 char_u *name;
7859 long number;
7860 char_u *string;
7861 int opt_flags; /* OPT_LOCAL or 0 (both) */
7862{
7863 int opt_idx;
7864 char_u *varp;
7865 int flags;
7866
7867 opt_idx = findoption(name);
7868 if (opt_idx == -1)
7869 EMSG2(_("E355: Unknown option: %s"), name);
7870 else
7871 {
7872 flags = options[opt_idx].flags;
7873#ifdef HAVE_SANDBOX
7874 /* Disallow changing some options in the sandbox */
7875 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007876 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007878 return;
7879 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007880#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007881 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007882 set_string_option(opt_idx, string, opt_flags);
7883 else
7884 {
7885 varp = get_varp(&options[opt_idx]);
7886 if (varp != NULL) /* hidden option is not changed */
7887 {
7888 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00007889 (void)set_num_option(opt_idx, varp, number,
7890 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007891 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007892 (void)set_bool_option(opt_idx, varp, (int)number,
7893 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 }
7895 }
7896 }
7897}
7898
7899/*
7900 * Get the terminal code for a terminal option.
7901 * Returns NULL when not found.
7902 */
7903 char_u *
7904get_term_code(tname)
7905 char_u *tname;
7906{
7907 int opt_idx;
7908 char_u *varp;
7909
7910 if (tname[0] != 't' || tname[1] != '_' ||
7911 tname[2] == NUL || tname[3] == NUL)
7912 return NULL;
7913 if ((opt_idx = findoption(tname)) >= 0)
7914 {
7915 varp = get_varp(&(options[opt_idx]));
7916 if (varp != NULL)
7917 varp = *(char_u **)(varp);
7918 return varp;
7919 }
7920 return find_termcode(tname + 2);
7921}
7922
7923 char_u *
7924get_highlight_default()
7925{
7926 int i;
7927
7928 i = findoption((char_u *)"hl");
7929 if (i >= 0)
7930 return options[i].def_val[VI_DEFAULT];
7931 return (char_u *)NULL;
7932}
7933
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007934#if defined(FEAT_MBYTE) || defined(PROTO)
7935 char_u *
7936get_encoding_default()
7937{
7938 int i;
7939
7940 i = findoption((char_u *)"enc");
7941 if (i >= 0)
7942 return options[i].def_val[VI_DEFAULT];
7943 return (char_u *)NULL;
7944}
7945#endif
7946
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947/*
7948 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7949 */
7950 static int
7951find_key_option(arg)
7952 char_u *arg;
7953{
7954 int key;
7955 int modifiers;
7956
7957 /*
7958 * Don't use get_special_key_code() for t_xx, we don't want it to call
7959 * add_termcap_entry().
7960 */
7961 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7962 key = TERMCAP2KEY(arg[2], arg[3]);
7963 else
7964 {
7965 --arg; /* put arg at the '<' */
7966 modifiers = 0;
7967 key = find_special_key(&arg, &modifiers, TRUE);
7968 if (modifiers) /* can't handle modifiers here */
7969 key = 0;
7970 }
7971 return key;
7972}
7973
7974/*
7975 * if 'all' == 0: show changed options
7976 * if 'all' == 1: show all normal options
7977 * if 'all' == 2: show all terminal options
7978 */
7979 static void
7980showoptions(all, opt_flags)
7981 int all;
7982 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7983{
7984 struct vimoption *p;
7985 int col;
7986 int isterm;
7987 char_u *varp;
7988 struct vimoption **items;
7989 int item_count;
7990 int run;
7991 int row, rows;
7992 int cols;
7993 int i;
7994 int len;
7995
7996#define INC 20
7997#define GAP 3
7998
7999 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8000 PARAM_COUNT));
8001 if (items == NULL)
8002 return;
8003
8004 /* Highlight title */
8005 if (all == 2)
8006 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8007 else if (opt_flags & OPT_GLOBAL)
8008 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8009 else if (opt_flags & OPT_LOCAL)
8010 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8011 else
8012 MSG_PUTS_TITLE(_("\n--- Options ---"));
8013
8014 /*
8015 * do the loop two times:
8016 * 1. display the short items
8017 * 2. display the long items (only strings and numbers)
8018 */
8019 for (run = 1; run <= 2 && !got_int; ++run)
8020 {
8021 /*
8022 * collect the items in items[]
8023 */
8024 item_count = 0;
8025 for (p = &options[0]; p->fullname != NULL; p++)
8026 {
8027 varp = NULL;
8028 isterm = istermoption(p);
8029 if (opt_flags != 0)
8030 {
8031 if (p->indir != PV_NONE && !isterm)
8032 varp = get_varp_scope(p, opt_flags);
8033 }
8034 else
8035 varp = get_varp(p);
8036 if (varp != NULL
8037 && ((all == 2 && isterm)
8038 || (all == 1 && !isterm)
8039 || (all == 0 && !optval_default(p, varp))))
8040 {
8041 if (p->flags & P_BOOL)
8042 len = 1; /* a toggle option fits always */
8043 else
8044 {
8045 option_value2string(p, opt_flags);
8046 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8047 }
8048 if ((len <= INC - GAP && run == 1) ||
8049 (len > INC - GAP && run == 2))
8050 items[item_count++] = p;
8051 }
8052 }
8053
8054 /*
8055 * display the items
8056 */
8057 if (run == 1)
8058 {
8059 cols = (Columns + GAP - 3) / INC;
8060 if (cols == 0)
8061 cols = 1;
8062 rows = (item_count + cols - 1) / cols;
8063 }
8064 else /* run == 2 */
8065 rows = item_count;
8066 for (row = 0; row < rows && !got_int; ++row)
8067 {
8068 msg_putchar('\n'); /* go to next line */
8069 if (got_int) /* 'q' typed in more */
8070 break;
8071 col = 0;
8072 for (i = row; i < item_count; i += rows)
8073 {
8074 msg_col = col; /* make columns */
8075 showoneopt(items[i], opt_flags);
8076 col += INC;
8077 }
8078 out_flush();
8079 ui_breakcheck();
8080 }
8081 }
8082 vim_free(items);
8083}
8084
8085/*
8086 * Return TRUE if option "p" has its default value.
8087 */
8088 static int
8089optval_default(p, varp)
8090 struct vimoption *p;
8091 char_u *varp;
8092{
8093 int dvi;
8094
8095 if (varp == NULL)
8096 return TRUE; /* hidden option is always at default */
8097 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8098 if (p->flags & P_NUM)
8099 return (*(long *)varp == (long)p->def_val[dvi]);
8100 if (p->flags & P_BOOL)
8101 /* the cast to long is required for Manx C */
8102 return (*(int *)varp == (int)(long)p->def_val[dvi]);
8103 /* P_STRING */
8104 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8105}
8106
8107/*
8108 * showoneopt: show the value of one option
8109 * must not be called with a hidden option!
8110 */
8111 static void
8112showoneopt(p, opt_flags)
8113 struct vimoption *p;
8114 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8115{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008116 char_u *varp;
8117 int save_silent = silent_mode;
8118
8119 silent_mode = FALSE;
8120 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008121
8122 varp = get_varp_scope(p, opt_flags);
8123
8124 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8125 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8126 ? !curbufIsChanged() : !*(int *)varp))
8127 MSG_PUTS("no");
8128 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8129 MSG_PUTS("--");
8130 else
8131 MSG_PUTS(" ");
8132 MSG_PUTS(p->fullname);
8133 if (!(p->flags & P_BOOL))
8134 {
8135 msg_putchar('=');
8136 /* put value string in NameBuff */
8137 option_value2string(p, opt_flags);
8138 msg_outtrans(NameBuff);
8139 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008140
8141 silent_mode = save_silent;
8142 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143}
8144
8145/*
8146 * Write modified options as ":set" commands to a file.
8147 *
8148 * There are three values for "opt_flags":
8149 * OPT_GLOBAL: Write global option values and fresh values of
8150 * buffer-local options (used for start of a session
8151 * file).
8152 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8153 * curwin (used for a vimrc file).
8154 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8155 * and local values for window-local options of
8156 * curwin. Local values are also written when at the
8157 * default value, because a modeline or autocommand
8158 * may have set them when doing ":edit file" and the
8159 * user has set them back at the default or fresh
8160 * value.
8161 * When "local_only" is TRUE, don't write fresh
8162 * values, only local values (for ":mkview").
8163 * (fresh value = value used for a new buffer or window for a local option).
8164 *
8165 * Return FAIL on error, OK otherwise.
8166 */
8167 int
8168makeset(fd, opt_flags, local_only)
8169 FILE *fd;
8170 int opt_flags;
8171 int local_only;
8172{
8173 struct vimoption *p;
8174 char_u *varp; /* currently used value */
8175 char_u *varp_fresh; /* local value */
8176 char_u *varp_local = NULL; /* fresh value */
8177 char *cmd;
8178 int round;
8179
8180 /*
8181 * The options that don't have a default (terminal name, columns, lines)
8182 * are never written. Terminal options are also not written.
8183 */
8184 for (p = &options[0]; !istermoption(p); p++)
8185 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
8186 {
8187 /* skip global option when only doing locals */
8188 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8189 continue;
8190
8191 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8192 * file, they are always buffer-specific. */
8193 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8194 continue;
8195
8196 /* Global values are only written when not at the default value. */
8197 varp = get_varp_scope(p, opt_flags);
8198 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8199 continue;
8200
8201 round = 2;
8202 if (p->indir != PV_NONE)
8203 {
8204 if (p->var == VAR_WIN)
8205 {
8206 /* skip window-local option when only doing globals */
8207 if (!(opt_flags & OPT_LOCAL))
8208 continue;
8209 /* When fresh value of window-local option is not at the
8210 * default, need to write it too. */
8211 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8212 {
8213 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8214 if (!optval_default(p, varp_fresh))
8215 {
8216 round = 1;
8217 varp_local = varp;
8218 varp = varp_fresh;
8219 }
8220 }
8221 }
8222 }
8223
8224 /* Round 1: fresh value for window-local options.
8225 * Round 2: other values */
8226 for ( ; round <= 2; varp = varp_local, ++round)
8227 {
8228 if (round == 1 || (opt_flags & OPT_GLOBAL))
8229 cmd = "set";
8230 else
8231 cmd = "setlocal";
8232
8233 if (p->flags & P_BOOL)
8234 {
8235 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8236 return FAIL;
8237 }
8238 else if (p->flags & P_NUM)
8239 {
8240 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8241 return FAIL;
8242 }
8243 else /* P_STRING */
8244 {
8245 /* Don't set 'syntax' and 'filetype' again if the value is
8246 * already right, avoids reloading the syntax file. */
8247 if (p->indir == PV_SYN || p->indir == PV_FT)
8248 {
8249 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8250 *(char_u **)(varp)) < 0
8251 || put_eol(fd) < 0)
8252 return FAIL;
8253 }
8254 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8255 (p->flags & P_EXPAND) != 0) == FAIL)
8256 return FAIL;
8257 if (p->indir == PV_SYN || p->indir == PV_FT)
8258 {
8259 if (put_line(fd, "endif") == FAIL)
8260 return FAIL;
8261 }
8262 }
8263 }
8264 }
8265 return OK;
8266}
8267
8268#if defined(FEAT_FOLDING) || defined(PROTO)
8269/*
8270 * Generate set commands for the local fold options only. Used when
8271 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8272 */
8273 int
8274makefoldset(fd)
8275 FILE *fd;
8276{
8277 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8278# ifdef FEAT_EVAL
8279 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8280 == FAIL
8281# endif
8282 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8283 == FAIL
8284 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8285 == FAIL
8286 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8287 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8288 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8289 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8290 )
8291 return FAIL;
8292
8293 return OK;
8294}
8295#endif
8296
8297 static int
8298put_setstring(fd, cmd, name, valuep, expand)
8299 FILE *fd;
8300 char *cmd;
8301 char *name;
8302 char_u **valuep;
8303 int expand;
8304{
8305 char_u *s;
8306 char_u buf[MAXPATHL];
8307
8308 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8309 return FAIL;
8310 if (*valuep != NULL)
8311 {
8312 /* Output 'pastetoggle' as key names. For other
8313 * options some characters have to be escaped with
8314 * CTRL-V or backslash */
8315 if (valuep == &p_pt)
8316 {
8317 s = *valuep;
8318 while (*s != NUL)
8319 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8320 return FAIL;
8321 }
8322 else if (expand)
8323 {
8324 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8325 if (put_escstr(fd, buf, 2) == FAIL)
8326 return FAIL;
8327 }
8328 else if (put_escstr(fd, *valuep, 2) == FAIL)
8329 return FAIL;
8330 }
8331 if (put_eol(fd) < 0)
8332 return FAIL;
8333 return OK;
8334}
8335
8336 static int
8337put_setnum(fd, cmd, name, valuep)
8338 FILE *fd;
8339 char *cmd;
8340 char *name;
8341 long *valuep;
8342{
8343 long wc;
8344
8345 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8346 return FAIL;
8347 if (wc_use_keyname((char_u *)valuep, &wc))
8348 {
8349 /* print 'wildchar' and 'wildcharm' as a key name */
8350 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8351 return FAIL;
8352 }
8353 else if (fprintf(fd, "%ld", *valuep) < 0)
8354 return FAIL;
8355 if (put_eol(fd) < 0)
8356 return FAIL;
8357 return OK;
8358}
8359
8360 static int
8361put_setbool(fd, cmd, name, value)
8362 FILE *fd;
8363 char *cmd;
8364 char *name;
8365 int value;
8366{
8367 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8368 || put_eol(fd) < 0)
8369 return FAIL;
8370 return OK;
8371}
8372
8373/*
8374 * Clear all the terminal options.
8375 * If the option has been allocated, free the memory.
8376 * Terminal options are never hidden or indirect.
8377 */
8378 void
8379clear_termoptions()
8380{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008381 /*
8382 * Reset a few things before clearing the old options. This may cause
8383 * outputting a few things that the terminal doesn't understand, but the
8384 * screen will be cleared later, so this is OK.
8385 */
8386#ifdef FEAT_MOUSE_TTY
8387 mch_setmouse(FALSE); /* switch mouse off */
8388#endif
8389#ifdef FEAT_TITLE
8390 mch_restore_title(3); /* restore window titles */
8391#endif
8392#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8393 /* When starting the GUI close the display opened for the clipboard.
8394 * After restoring the title, because that will need the display. */
8395 if (gui.starting)
8396 clear_xterm_clip();
8397#endif
8398#ifdef WIN3264
8399 /*
8400 * Check if this is allowed now.
8401 */
8402 if (can_end_termcap_mode(FALSE) == TRUE)
8403#endif
8404 stoptermcap(); /* stop termcap mode */
8405
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008406 free_termoptions();
8407}
8408
8409 void
8410free_termoptions()
8411{
8412 struct vimoption *p;
8413
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414 for (p = &options[0]; p->fullname != NULL; p++)
8415 if (istermoption(p))
8416 {
8417 if (p->flags & P_ALLOCED)
8418 free_string_option(*(char_u **)(p->var));
8419 if (p->flags & P_DEF_ALLOCED)
8420 free_string_option(p->def_val[VI_DEFAULT]);
8421 *(char_u **)(p->var) = empty_option;
8422 p->def_val[VI_DEFAULT] = empty_option;
8423 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8424 }
8425 clear_termcodes();
8426}
8427
8428/*
8429 * Set the terminal option defaults to the current value.
8430 * Used after setting the terminal name.
8431 */
8432 void
8433set_term_defaults()
8434{
8435 struct vimoption *p;
8436
8437 for (p = &options[0]; p->fullname != NULL; p++)
8438 {
8439 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8440 {
8441 if (p->flags & P_DEF_ALLOCED)
8442 {
8443 free_string_option(p->def_val[VI_DEFAULT]);
8444 p->flags &= ~P_DEF_ALLOCED;
8445 }
8446 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8447 if (p->flags & P_ALLOCED)
8448 {
8449 p->flags |= P_DEF_ALLOCED;
8450 p->flags &= ~P_ALLOCED; /* don't free the value now */
8451 }
8452 }
8453 }
8454}
8455
8456/*
8457 * return TRUE if 'p' starts with 't_'
8458 */
8459 static int
8460istermoption(p)
8461 struct vimoption *p;
8462{
8463 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8464}
8465
8466/*
8467 * Compute columns for ruler and shown command. 'sc_col' is also used to
8468 * decide what the maximum length of a message on the status line can be.
8469 * If there is a status line for the last window, 'sc_col' is independent
8470 * of 'ru_col'.
8471 */
8472
8473#define COL_RULER 17 /* columns needed by standard ruler */
8474
8475 void
8476comp_col()
8477{
8478#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8479 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8480
8481 sc_col = 0;
8482 ru_col = 0;
8483 if (p_ru)
8484 {
8485#ifdef FEAT_STL_OPT
8486 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8487#else
8488 ru_col = COL_RULER + 1;
8489#endif
8490 /* no last status line, adjust sc_col */
8491 if (!last_has_status)
8492 sc_col = ru_col;
8493 }
8494 if (p_sc)
8495 {
8496 sc_col += SHOWCMD_COLS;
8497 if (!p_ru || last_has_status) /* no need for separating space */
8498 ++sc_col;
8499 }
8500 sc_col = Columns - sc_col;
8501 ru_col = Columns - ru_col;
8502 if (sc_col <= 0) /* screen too narrow, will become a mess */
8503 sc_col = 1;
8504 if (ru_col <= 0)
8505 ru_col = 1;
8506#else
8507 sc_col = Columns;
8508 ru_col = Columns;
8509#endif
8510}
8511
8512/*
8513 * Get pointer to option variable, depending on local or global scope.
8514 */
8515 static char_u *
8516get_varp_scope(p, opt_flags)
8517 struct vimoption *p;
8518 int opt_flags;
8519{
8520 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8521 {
8522 if (p->var == VAR_WIN)
8523 return (char_u *)GLOBAL_WO(get_varp(p));
8524 return p->var;
8525 }
8526 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
8527 {
8528 switch ((int)p->indir)
8529 {
8530#ifdef FEAT_QUICKFIX
8531 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
8532 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
8533 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
8534#endif
8535 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
8536 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
8537 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
8538 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
8539 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
8540#ifdef FEAT_FIND_ID
8541 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
8542 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
8543#endif
8544#ifdef FEAT_INS_EXPAND
8545 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
8546 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
8547#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008548#ifdef FEAT_STL_OPT
8549 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
8550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551 }
8552 return NULL; /* "cannot happen" */
8553 }
8554 return get_varp(p);
8555}
8556
8557/*
8558 * Get pointer to option variable.
8559 */
8560 static char_u *
8561get_varp(p)
8562 struct vimoption *p;
8563{
8564 /* hidden option, always return NULL */
8565 if (p->var == NULL)
8566 return NULL;
8567
8568 switch ((int)p->indir)
8569 {
8570 case PV_NONE: return p->var;
8571
8572 /* global option with local value: use local value if it's been set */
8573 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
8574 ? (char_u *)&curbuf->b_p_ep : p->var;
8575 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
8576 ? (char_u *)&curbuf->b_p_kp : p->var;
8577 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
8578 ? (char_u *)&(curbuf->b_p_path) : p->var;
8579 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
8580 ? (char_u *)&(curbuf->b_p_ar) : p->var;
8581 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
8582 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8583#ifdef FEAT_FIND_ID
8584 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
8585 ? (char_u *)&(curbuf->b_p_def) : p->var;
8586 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
8587 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8588#endif
8589#ifdef FEAT_INS_EXPAND
8590 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
8591 ? (char_u *)&(curbuf->b_p_dict) : p->var;
8592 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
8593 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8594#endif
8595#ifdef FEAT_QUICKFIX
8596 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
8597 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8598 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
8599 ? (char_u *)&(curbuf->b_p_mp) : p->var;
8600 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8601 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8602#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008603#ifdef FEAT_STL_OPT
8604 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8605 ? (char_u *)&(curwin->w_p_stl) : p->var;
8606#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008607
8608#ifdef FEAT_ARABIC
8609 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8610#endif
8611 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008612#ifdef FEAT_SYN_HL
8613 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615#ifdef FEAT_DIFF
8616 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8617#endif
8618#ifdef FEAT_FOLDING
8619 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8620 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8621 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8622 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8623 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8624 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8625 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8626# ifdef FEAT_EVAL
8627 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8628 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8629# endif
8630 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8631#endif
8632 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008633#ifdef FEAT_LINEBREAK
8634 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8635#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636#if defined(FEAT_WINDOWS)
8637 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8638#endif
8639#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8640 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8641#endif
8642#ifdef FEAT_RIGHTLEFT
8643 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8644 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8645#endif
8646 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8647 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8648#ifdef FEAT_LINEBREAK
8649 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8650#endif
8651#ifdef FEAT_SCROLLBIND
8652 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8653#endif
8654
8655 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8656 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8657#ifdef FEAT_MBYTE
8658 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8659#endif
8660#if defined(FEAT_QUICKFIX)
8661 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8662 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8663#endif
8664 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8665 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8666#ifdef FEAT_CINDENT
8667 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8668 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8669 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8670#endif
8671#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8672 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8673#endif
8674#ifdef FEAT_COMMENTS
8675 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8676#endif
8677#ifdef FEAT_FOLDING
8678 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8679#endif
8680#ifdef FEAT_INS_EXPAND
8681 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8682#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008683#ifdef FEAT_COMPL_FUNC
8684 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008685 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008687 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8688 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8689#ifdef FEAT_MBYTE
8690 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8691#endif
8692 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8693#ifdef FEAT_AUTOCMD
8694 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8695#endif
8696 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008697 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8699 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8700 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8701 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8702#ifdef FEAT_FIND_ID
8703# ifdef FEAT_EVAL
8704 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8705# endif
8706#endif
8707#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8708 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8709 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8710#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008711#if defined(FEAT_EVAL)
8712 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
8713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714#ifdef FEAT_CRYPT
8715 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8716#endif
8717#ifdef FEAT_LISP
8718 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8719#endif
8720 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8721 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8722 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8723 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8724 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8725#ifdef FEAT_OSFILETYPE
8726 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8727#endif
8728 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008729#ifdef FEAT_TEXTOBJ
8730 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8731#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8733#ifdef FEAT_SMARTINDENT
8734 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8735#endif
8736#ifndef SHORT_FNAME
8737 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8738#endif
8739 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8740#ifdef FEAT_SEARCHPATH
8741 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8742#endif
8743 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8744#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008745 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008747 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008748 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008749 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750#endif
8751 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8752 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8753 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8754 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8755 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8756#ifdef FEAT_KEYMAP
8757 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8758#endif
8759 default: EMSG(_("E356: get_varp ERROR"));
8760 }
8761 /* always return a valid pointer to avoid a crash! */
8762 return (char_u *)&(curbuf->b_p_wm);
8763}
8764
8765/*
8766 * Get the value of 'equalprg', either the buffer-local one or the global one.
8767 */
8768 char_u *
8769get_equalprg()
8770{
8771 if (*curbuf->b_p_ep == NUL)
8772 return p_ep;
8773 return curbuf->b_p_ep;
8774}
8775
8776#if defined(FEAT_WINDOWS) || defined(PROTO)
8777/*
8778 * Copy options from one window to another.
8779 * Used when splitting a window.
8780 */
8781 void
8782win_copy_options(wp_from, wp_to)
8783 win_T *wp_from;
8784 win_T *wp_to;
8785{
8786 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8787 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8788# ifdef FEAT_RIGHTLEFT
8789# ifdef FEAT_FKMAP
8790 /* Is this right? */
8791 wp_to->w_farsi = wp_from->w_farsi;
8792# endif
8793# endif
8794}
8795#endif
8796
8797/*
8798 * Copy the options from one winopt_T to another.
8799 * Doesn't free the old option values in "to", use clear_winopt() for that.
8800 * The 'scroll' option is not copied, because it depends on the window height.
8801 * The 'previewwindow' option is reset, there can be only one preview window.
8802 */
8803 void
8804copy_winopt(from, to)
8805 winopt_T *from;
8806 winopt_T *to;
8807{
8808#ifdef FEAT_ARABIC
8809 to->wo_arab = from->wo_arab;
8810#endif
8811 to->wo_list = from->wo_list;
8812 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008813#ifdef FEAT_LINEBREAK
8814 to->wo_nuw = from->wo_nuw;
8815#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008816#ifdef FEAT_RIGHTLEFT
8817 to->wo_rl = from->wo_rl;
8818 to->wo_rlc = vim_strsave(from->wo_rlc);
8819#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008820#ifdef FEAT_STL_OPT
8821 to->wo_stl = vim_strsave(from->wo_stl);
8822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 to->wo_wrap = from->wo_wrap;
8824#ifdef FEAT_LINEBREAK
8825 to->wo_lbr = from->wo_lbr;
8826#endif
8827#ifdef FEAT_SCROLLBIND
8828 to->wo_scb = from->wo_scb;
8829#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008830#ifdef FEAT_SYN_HL
8831 to->wo_spell = from->wo_spell;
8832#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833#ifdef FEAT_DIFF
8834 to->wo_diff = from->wo_diff;
8835#endif
8836#ifdef FEAT_FOLDING
8837 to->wo_fdc = from->wo_fdc;
8838 to->wo_fen = from->wo_fen;
8839 to->wo_fdi = vim_strsave(from->wo_fdi);
8840 to->wo_fml = from->wo_fml;
8841 to->wo_fdl = from->wo_fdl;
8842 to->wo_fdm = vim_strsave(from->wo_fdm);
8843 to->wo_fdn = from->wo_fdn;
8844# ifdef FEAT_EVAL
8845 to->wo_fde = vim_strsave(from->wo_fde);
8846 to->wo_fdt = vim_strsave(from->wo_fdt);
8847# endif
8848 to->wo_fmr = vim_strsave(from->wo_fmr);
8849#endif
8850 check_winopt(to); /* don't want NULL pointers */
8851}
8852
8853/*
8854 * Check string options in a window for a NULL value.
8855 */
8856 void
8857check_win_options(win)
8858 win_T *win;
8859{
8860 check_winopt(&win->w_onebuf_opt);
8861 check_winopt(&win->w_allbuf_opt);
8862}
8863
8864/*
8865 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8866 */
8867/*ARGSUSED*/
8868 void
8869check_winopt(wop)
8870 winopt_T *wop;
8871{
8872#ifdef FEAT_FOLDING
8873 check_string_option(&wop->wo_fdi);
8874 check_string_option(&wop->wo_fdm);
8875# ifdef FEAT_EVAL
8876 check_string_option(&wop->wo_fde);
8877 check_string_option(&wop->wo_fdt);
8878# endif
8879 check_string_option(&wop->wo_fmr);
8880#endif
8881#ifdef FEAT_RIGHTLEFT
8882 check_string_option(&wop->wo_rlc);
8883#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008884#ifdef FEAT_STL_OPT
8885 check_string_option(&wop->wo_stl);
8886#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008887}
8888
8889/*
8890 * Free the allocated memory inside a winopt_T.
8891 */
8892/*ARGSUSED*/
8893 void
8894clear_winopt(wop)
8895 winopt_T *wop;
8896{
8897#ifdef FEAT_FOLDING
8898 clear_string_option(&wop->wo_fdi);
8899 clear_string_option(&wop->wo_fdm);
8900# ifdef FEAT_EVAL
8901 clear_string_option(&wop->wo_fde);
8902 clear_string_option(&wop->wo_fdt);
8903# endif
8904 clear_string_option(&wop->wo_fmr);
8905#endif
8906#ifdef FEAT_RIGHTLEFT
8907 clear_string_option(&wop->wo_rlc);
8908#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008909#ifdef FEAT_STL_OPT
8910 clear_string_option(&wop->wo_stl);
8911#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008912}
8913
8914/*
8915 * Copy global option values to local options for one buffer.
8916 * Used when creating a new buffer and sometimes when entering a buffer.
8917 * flags:
8918 * BCO_ENTER We will enter the buf buffer.
8919 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8920 * appropriate.
8921 * BCO_NOHELP Don't copy the values to a help buffer.
8922 */
8923 void
8924buf_copy_options(buf, flags)
8925 buf_T *buf;
8926 int flags;
8927{
8928 int should_copy = TRUE;
8929 char_u *save_p_isk = NULL; /* init for GCC */
8930 int dont_do_help;
8931 int did_isk = FALSE;
8932
8933 /*
8934 * Don't do anything of the buffer is invalid.
8935 */
8936 if (buf == NULL || !buf_valid(buf))
8937 return;
8938
8939 /*
8940 * Skip this when the option defaults have not been set yet. Happens when
8941 * main() allocates the first buffer.
8942 */
8943 if (p_cpo != NULL)
8944 {
8945 /*
8946 * Always copy when entering and 'cpo' contains 'S'.
8947 * Don't copy when already initialized.
8948 * Don't copy when 'cpo' contains 's' and not entering.
8949 * 'S' BCO_ENTER initialized 's' should_copy
8950 * yes yes X X TRUE
8951 * yes no yes X FALSE
8952 * no X yes X FALSE
8953 * X no no yes FALSE
8954 * X no no no TRUE
8955 * no yes no X TRUE
8956 */
8957 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8958 && (buf->b_p_initialized
8959 || (!(flags & BCO_ENTER)
8960 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8961 should_copy = FALSE;
8962
8963 if (should_copy || (flags & BCO_ALWAYS))
8964 {
8965 /* Don't copy the options specific to a help buffer when
8966 * BCO_NOHELP is given or the options were initialized already
8967 * (jumping back to a help file with CTRL-T or CTRL-O) */
8968 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8969 || buf->b_p_initialized;
8970 if (dont_do_help) /* don't free b_p_isk */
8971 {
8972 save_p_isk = buf->b_p_isk;
8973 buf->b_p_isk = NULL;
8974 }
8975 /*
8976 * Always free the allocated strings.
8977 * If not already initialized, set 'readonly' and copy 'fileformat'.
8978 */
8979 if (!buf->b_p_initialized)
8980 {
8981 free_buf_options(buf, TRUE);
8982 buf->b_p_ro = FALSE; /* don't copy readonly */
8983 buf->b_p_tx = p_tx;
8984#ifdef FEAT_MBYTE
8985 buf->b_p_fenc = vim_strsave(p_fenc);
8986#endif
8987 buf->b_p_ff = vim_strsave(p_ff);
8988#if defined(FEAT_QUICKFIX)
8989 buf->b_p_bh = empty_option;
8990 buf->b_p_bt = empty_option;
8991#endif
8992 }
8993 else
8994 free_buf_options(buf, FALSE);
8995
8996 buf->b_p_ai = p_ai;
8997 buf->b_p_ai_nopaste = p_ai_nopaste;
8998 buf->b_p_sw = p_sw;
8999 buf->b_p_tw = p_tw;
9000 buf->b_p_tw_nopaste = p_tw_nopaste;
9001 buf->b_p_tw_nobin = p_tw_nobin;
9002 buf->b_p_wm = p_wm;
9003 buf->b_p_wm_nopaste = p_wm_nopaste;
9004 buf->b_p_wm_nobin = p_wm_nobin;
9005 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009006#ifdef FEAT_MBYTE
9007 buf->b_p_bomb = p_bomb;
9008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009 buf->b_p_et = p_et;
9010 buf->b_p_et_nobin = p_et_nobin;
9011 buf->b_p_ml = p_ml;
9012 buf->b_p_ml_nobin = p_ml_nobin;
9013 buf->b_p_inf = p_inf;
9014 buf->b_p_swf = p_swf;
9015#ifdef FEAT_INS_EXPAND
9016 buf->b_p_cpt = vim_strsave(p_cpt);
9017#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009018#ifdef FEAT_COMPL_FUNC
9019 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009020 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009021#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009022 buf->b_p_sts = p_sts;
9023 buf->b_p_sts_nopaste = p_sts_nopaste;
9024#ifndef SHORT_FNAME
9025 buf->b_p_sn = p_sn;
9026#endif
9027#ifdef FEAT_COMMENTS
9028 buf->b_p_com = vim_strsave(p_com);
9029#endif
9030#ifdef FEAT_FOLDING
9031 buf->b_p_cms = vim_strsave(p_cms);
9032#endif
9033 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009034 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035 buf->b_p_nf = vim_strsave(p_nf);
9036 buf->b_p_mps = vim_strsave(p_mps);
9037#ifdef FEAT_SMARTINDENT
9038 buf->b_p_si = p_si;
9039#endif
9040 buf->b_p_ci = p_ci;
9041#ifdef FEAT_CINDENT
9042 buf->b_p_cin = p_cin;
9043 buf->b_p_cink = vim_strsave(p_cink);
9044 buf->b_p_cino = vim_strsave(p_cino);
9045#endif
9046#ifdef FEAT_AUTOCMD
9047 /* Don't copy 'filetype', it must be detected */
9048 buf->b_p_ft = empty_option;
9049#endif
9050#ifdef FEAT_OSFILETYPE
9051 buf->b_p_oft = vim_strsave(p_oft);
9052#endif
9053 buf->b_p_pi = p_pi;
9054#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9055 buf->b_p_cinw = vim_strsave(p_cinw);
9056#endif
9057#ifdef FEAT_LISP
9058 buf->b_p_lisp = p_lisp;
9059#endif
9060#ifdef FEAT_SYN_HL
9061 /* Don't copy 'syntax', it must be set */
9062 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009063 buf->b_p_smc = p_smc;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009064 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009065 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009066 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009067 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009068#endif
9069#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9070 buf->b_p_inde = vim_strsave(p_inde);
9071 buf->b_p_indk = vim_strsave(p_indk);
9072#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009073#if defined(FEAT_EVAL)
9074 buf->b_p_fex = vim_strsave(p_fex);
9075#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076#ifdef FEAT_CRYPT
9077 buf->b_p_key = vim_strsave(p_key);
9078#endif
9079#ifdef FEAT_SEARCHPATH
9080 buf->b_p_sua = vim_strsave(p_sua);
9081#endif
9082#ifdef FEAT_KEYMAP
9083 buf->b_p_keymap = vim_strsave(p_keymap);
9084 buf->b_kmap_state |= KEYMAP_INIT;
9085#endif
9086 /* This isn't really an option, but copying the langmap and IME
9087 * state from the current buffer is better than resetting it. */
9088 buf->b_p_iminsert = p_iminsert;
9089 buf->b_p_imsearch = p_imsearch;
9090
9091 /* options that are normally global but also have a local value
9092 * are not copied, start using the global value */
9093 buf->b_p_ar = -1;
9094#ifdef FEAT_QUICKFIX
9095 buf->b_p_gp = empty_option;
9096 buf->b_p_mp = empty_option;
9097 buf->b_p_efm = empty_option;
9098#endif
9099 buf->b_p_ep = empty_option;
9100 buf->b_p_kp = empty_option;
9101 buf->b_p_path = empty_option;
9102 buf->b_p_tags = empty_option;
9103#ifdef FEAT_FIND_ID
9104 buf->b_p_def = empty_option;
9105 buf->b_p_inc = empty_option;
9106# ifdef FEAT_EVAL
9107 buf->b_p_inex = vim_strsave(p_inex);
9108# endif
9109#endif
9110#ifdef FEAT_INS_EXPAND
9111 buf->b_p_dict = empty_option;
9112 buf->b_p_tsr = empty_option;
9113#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009114#ifdef FEAT_TEXTOBJ
9115 buf->b_p_qe = vim_strsave(p_qe);
9116#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117
9118 /*
9119 * Don't copy the options set by ex_help(), use the saved values,
9120 * when going from a help buffer to a non-help buffer.
9121 * Don't touch these at all when BCO_NOHELP is used and going from
9122 * or to a help buffer.
9123 */
9124 if (dont_do_help)
9125 buf->b_p_isk = save_p_isk;
9126 else
9127 {
9128 buf->b_p_isk = vim_strsave(p_isk);
9129 did_isk = TRUE;
9130 buf->b_p_ts = p_ts;
9131 buf->b_help = FALSE;
9132#ifdef FEAT_QUICKFIX
9133 if (buf->b_p_bt[0] == 'h')
9134 clear_string_option(&buf->b_p_bt);
9135#endif
9136 buf->b_p_ma = p_ma;
9137 }
9138 }
9139
9140 /*
9141 * When the options should be copied (ignoring BCO_ALWAYS), set the
9142 * flag that indicates that the options have been initialized.
9143 */
9144 if (should_copy)
9145 buf->b_p_initialized = TRUE;
9146 }
9147
9148 check_buf_options(buf); /* make sure we don't have NULLs */
9149 if (did_isk)
9150 (void)buf_init_chartab(buf, FALSE);
9151}
9152
9153/*
9154 * Reset the 'modifiable' option and its default value.
9155 */
9156 void
9157reset_modifiable()
9158{
9159 int opt_idx;
9160
9161 curbuf->b_p_ma = FALSE;
9162 p_ma = FALSE;
9163 opt_idx = findoption((char_u *)"ma");
9164 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9165}
9166
9167/*
9168 * Set the global value for 'iminsert' to the local value.
9169 */
9170 void
9171set_iminsert_global()
9172{
9173 p_iminsert = curbuf->b_p_iminsert;
9174}
9175
9176/*
9177 * Set the global value for 'imsearch' to the local value.
9178 */
9179 void
9180set_imsearch_global()
9181{
9182 p_imsearch = curbuf->b_p_imsearch;
9183}
9184
9185#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9186static int expand_option_idx = -1;
9187static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9188static int expand_option_flags = 0;
9189
9190 void
9191set_context_in_set_cmd(xp, arg, opt_flags)
9192 expand_T *xp;
9193 char_u *arg;
9194 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9195{
9196 int nextchar;
9197 long_u flags = 0; /* init for GCC */
9198 int opt_idx = 0; /* init for GCC */
9199 char_u *p;
9200 char_u *s;
9201 int is_term_option = FALSE;
9202 int key;
9203
9204 expand_option_flags = opt_flags;
9205
9206 xp->xp_context = EXPAND_SETTINGS;
9207 if (*arg == NUL)
9208 {
9209 xp->xp_pattern = arg;
9210 return;
9211 }
9212 p = arg + STRLEN(arg) - 1;
9213 if (*p == ' ' && *(p - 1) != '\\')
9214 {
9215 xp->xp_pattern = p + 1;
9216 return;
9217 }
9218 while (p > arg)
9219 {
9220 s = p;
9221 /* count number of backslashes before ' ' or ',' */
9222 if (*p == ' ' || *p == ',')
9223 {
9224 while (s > arg && *(s - 1) == '\\')
9225 --s;
9226 }
9227 /* break at a space with an even number of backslashes */
9228 if (*p == ' ' && ((p - s) & 1) == 0)
9229 {
9230 ++p;
9231 break;
9232 }
9233 --p;
9234 }
9235 if (STRNCMP(p, "no", 2) == 0)
9236 {
9237 xp->xp_context = EXPAND_BOOL_SETTINGS;
9238 p += 2;
9239 }
9240 if (STRNCMP(p, "inv", 3) == 0)
9241 {
9242 xp->xp_context = EXPAND_BOOL_SETTINGS;
9243 p += 3;
9244 }
9245 xp->xp_pattern = arg = p;
9246 if (*arg == '<')
9247 {
9248 while (*p != '>')
9249 if (*p++ == NUL) /* expand terminal option name */
9250 return;
9251 key = get_special_key_code(arg + 1);
9252 if (key == 0) /* unknown name */
9253 {
9254 xp->xp_context = EXPAND_NOTHING;
9255 return;
9256 }
9257 nextchar = *++p;
9258 is_term_option = TRUE;
9259 expand_option_name[2] = KEY2TERMCAP0(key);
9260 expand_option_name[3] = KEY2TERMCAP1(key);
9261 }
9262 else
9263 {
9264 if (p[0] == 't' && p[1] == '_')
9265 {
9266 p += 2;
9267 if (*p != NUL)
9268 ++p;
9269 if (*p == NUL)
9270 return; /* expand option name */
9271 nextchar = *++p;
9272 is_term_option = TRUE;
9273 expand_option_name[2] = p[-2];
9274 expand_option_name[3] = p[-1];
9275 }
9276 else
9277 {
9278 /* Allow * wildcard */
9279 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9280 p++;
9281 if (*p == NUL)
9282 return;
9283 nextchar = *p;
9284 *p = NUL;
9285 opt_idx = findoption(arg);
9286 *p = nextchar;
9287 if (opt_idx == -1 || options[opt_idx].var == NULL)
9288 {
9289 xp->xp_context = EXPAND_NOTHING;
9290 return;
9291 }
9292 flags = options[opt_idx].flags;
9293 if (flags & P_BOOL)
9294 {
9295 xp->xp_context = EXPAND_NOTHING;
9296 return;
9297 }
9298 }
9299 }
9300 /* handle "-=" and "+=" */
9301 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9302 {
9303 ++p;
9304 nextchar = '=';
9305 }
9306 if ((nextchar != '=' && nextchar != ':')
9307 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9308 {
9309 xp->xp_context = EXPAND_UNSUCCESSFUL;
9310 return;
9311 }
9312 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9313 {
9314 xp->xp_context = EXPAND_OLD_SETTING;
9315 if (is_term_option)
9316 expand_option_idx = -1;
9317 else
9318 expand_option_idx = opt_idx;
9319 xp->xp_pattern = p + 1;
9320 return;
9321 }
9322 xp->xp_context = EXPAND_NOTHING;
9323 if (is_term_option || (flags & P_NUM))
9324 return;
9325
9326 xp->xp_pattern = p + 1;
9327
9328 if (flags & P_EXPAND)
9329 {
9330 p = options[opt_idx].var;
9331 if (p == (char_u *)&p_bdir
9332 || p == (char_u *)&p_dir
9333 || p == (char_u *)&p_path
9334 || p == (char_u *)&p_rtp
9335#ifdef FEAT_SEARCHPATH
9336 || p == (char_u *)&p_cdpath
9337#endif
9338#ifdef FEAT_SESSION
9339 || p == (char_u *)&p_vdir
9340#endif
9341 )
9342 {
9343 xp->xp_context = EXPAND_DIRECTORIES;
9344 if (p == (char_u *)&p_path
9345#ifdef FEAT_SEARCHPATH
9346 || p == (char_u *)&p_cdpath
9347#endif
9348 )
9349 xp->xp_backslash = XP_BS_THREE;
9350 else
9351 xp->xp_backslash = XP_BS_ONE;
9352 }
9353 else
9354 {
9355 xp->xp_context = EXPAND_FILES;
9356 /* for 'tags' need three backslashes for a space */
9357 if (p == (char_u *)&p_tags)
9358 xp->xp_backslash = XP_BS_THREE;
9359 else
9360 xp->xp_backslash = XP_BS_ONE;
9361 }
9362 }
9363
9364 /* For an option that is a list of file names, find the start of the
9365 * last file name. */
9366 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9367 {
9368 /* count number of backslashes before ' ' or ',' */
9369 if (*p == ' ' || *p == ',')
9370 {
9371 s = p;
9372 while (s > xp->xp_pattern && *(s - 1) == '\\')
9373 --s;
9374 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9375 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9376 {
9377 xp->xp_pattern = p + 1;
9378 break;
9379 }
9380 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009381
9382#ifdef FEAT_SYN_HL
9383 /* for 'spellsuggest' start at "file:" */
9384 if (options[opt_idx].var == (char_u *)&p_sps
9385 && STRNCMP(p, "file:", 5) == 0)
9386 {
9387 xp->xp_pattern = p + 5;
9388 break;
9389 }
9390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009391 }
9392
9393 return;
9394}
9395
9396 int
9397ExpandSettings(xp, regmatch, num_file, file)
9398 expand_T *xp;
9399 regmatch_T *regmatch;
9400 int *num_file;
9401 char_u ***file;
9402{
9403 int num_normal = 0; /* Nr of matching non-term-code settings */
9404 int num_term = 0; /* Nr of matching terminal code settings */
9405 int opt_idx;
9406 int match;
9407 int count = 0;
9408 char_u *str;
9409 int loop;
9410 int is_term_opt;
9411 char_u name_buf[MAX_KEY_NAME_LEN];
9412 static char *(names[]) = {"all", "termcap"};
9413 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9414
9415 /* do this loop twice:
9416 * loop == 0: count the number of matching options
9417 * loop == 1: copy the matching options into allocated memory
9418 */
9419 for (loop = 0; loop <= 1; ++loop)
9420 {
9421 regmatch->rm_ic = ic;
9422 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9423 {
9424 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9425 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9426 {
9427 if (loop == 0)
9428 num_normal++;
9429 else
9430 (*file)[count++] = vim_strsave((char_u *)names[match]);
9431 }
9432 }
9433 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9434 opt_idx++)
9435 {
9436 if (options[opt_idx].var == NULL)
9437 continue;
9438 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9439 && !(options[opt_idx].flags & P_BOOL))
9440 continue;
9441 is_term_opt = istermoption(&options[opt_idx]);
9442 if (is_term_opt && num_normal > 0)
9443 continue;
9444 match = FALSE;
9445 if (vim_regexec(regmatch, str, (colnr_T)0)
9446 || (options[opt_idx].shortname != NULL
9447 && vim_regexec(regmatch,
9448 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9449 match = TRUE;
9450 else if (is_term_opt)
9451 {
9452 name_buf[0] = '<';
9453 name_buf[1] = 't';
9454 name_buf[2] = '_';
9455 name_buf[3] = str[2];
9456 name_buf[4] = str[3];
9457 name_buf[5] = '>';
9458 name_buf[6] = NUL;
9459 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9460 {
9461 match = TRUE;
9462 str = name_buf;
9463 }
9464 }
9465 if (match)
9466 {
9467 if (loop == 0)
9468 {
9469 if (is_term_opt)
9470 num_term++;
9471 else
9472 num_normal++;
9473 }
9474 else
9475 (*file)[count++] = vim_strsave(str);
9476 }
9477 }
9478 /*
9479 * Check terminal key codes, these are not in the option table
9480 */
9481 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9482 {
9483 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9484 {
9485 if (!isprint(str[0]) || !isprint(str[1]))
9486 continue;
9487
9488 name_buf[0] = 't';
9489 name_buf[1] = '_';
9490 name_buf[2] = str[0];
9491 name_buf[3] = str[1];
9492 name_buf[4] = NUL;
9493
9494 match = FALSE;
9495 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9496 match = TRUE;
9497 else
9498 {
9499 name_buf[0] = '<';
9500 name_buf[1] = 't';
9501 name_buf[2] = '_';
9502 name_buf[3] = str[0];
9503 name_buf[4] = str[1];
9504 name_buf[5] = '>';
9505 name_buf[6] = NUL;
9506
9507 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9508 match = TRUE;
9509 }
9510 if (match)
9511 {
9512 if (loop == 0)
9513 num_term++;
9514 else
9515 (*file)[count++] = vim_strsave(name_buf);
9516 }
9517 }
9518
9519 /*
9520 * Check special key names.
9521 */
9522 regmatch->rm_ic = TRUE; /* ignore case here */
9523 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9524 {
9525 name_buf[0] = '<';
9526 STRCPY(name_buf + 1, str);
9527 STRCAT(name_buf, ">");
9528
9529 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9530 {
9531 if (loop == 0)
9532 num_term++;
9533 else
9534 (*file)[count++] = vim_strsave(name_buf);
9535 }
9536 }
9537 }
9538 if (loop == 0)
9539 {
9540 if (num_normal > 0)
9541 *num_file = num_normal;
9542 else if (num_term > 0)
9543 *num_file = num_term;
9544 else
9545 return OK;
9546 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9547 if (*file == NULL)
9548 {
9549 *file = (char_u **)"";
9550 return FAIL;
9551 }
9552 }
9553 }
9554 return OK;
9555}
9556
9557 int
9558ExpandOldSetting(num_file, file)
9559 int *num_file;
9560 char_u ***file;
9561{
9562 char_u *var = NULL; /* init for GCC */
9563 char_u *buf;
9564
9565 *num_file = 0;
9566 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9567 if (*file == NULL)
9568 return FAIL;
9569
9570 /*
9571 * For a terminal key code expand_option_idx is < 0.
9572 */
9573 if (expand_option_idx < 0)
9574 {
9575 var = find_termcode(expand_option_name + 2);
9576 if (var == NULL)
9577 expand_option_idx = findoption(expand_option_name);
9578 }
9579
9580 if (expand_option_idx >= 0)
9581 {
9582 /* put string of option value in NameBuff */
9583 option_value2string(&options[expand_option_idx], expand_option_flags);
9584 var = NameBuff;
9585 }
9586 else if (var == NULL)
9587 var = (char_u *)"";
9588
9589 /* A backslash is required before some characters. This is the reverse of
9590 * what happens in do_set(). */
9591 buf = vim_strsave_escaped(var, escape_chars);
9592
9593 if (buf == NULL)
9594 {
9595 vim_free(*file);
9596 *file = NULL;
9597 return FAIL;
9598 }
9599
9600#ifdef BACKSLASH_IN_FILENAME
9601 /* For MS-Windows et al. we don't double backslashes at the start and
9602 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009603 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009604 if (var[0] == '\\' && var[1] == '\\'
9605 && expand_option_idx >= 0
9606 && (options[expand_option_idx].flags & P_EXPAND)
9607 && vim_isfilec(var[2])
9608 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9609 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009610#endif
9611
9612 *file[0] = buf;
9613 *num_file = 1;
9614 return OK;
9615}
9616#endif
9617
9618/*
9619 * Get the value for the numeric or string option *opp in a nice format into
9620 * NameBuff[]. Must not be called with a hidden option!
9621 */
9622 static void
9623option_value2string(opp, opt_flags)
9624 struct vimoption *opp;
9625 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9626{
9627 char_u *varp;
9628
9629 varp = get_varp_scope(opp, opt_flags);
9630
9631 if (opp->flags & P_NUM)
9632 {
9633 long wc = 0;
9634
9635 if (wc_use_keyname(varp, &wc))
9636 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9637 else if (wc != 0)
9638 STRCPY(NameBuff, transchar((int)wc));
9639 else
9640 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9641 }
9642 else /* P_STRING */
9643 {
9644 varp = *(char_u **)(varp);
9645 if (varp == NULL) /* just in case */
9646 NameBuff[0] = NUL;
9647#ifdef FEAT_CRYPT
9648 /* don't show the actual value of 'key', only that it's set */
9649 if (opp->var == (char_u *)&p_key && *varp)
9650 STRCPY(NameBuff, "*****");
9651#endif
9652 else if (opp->flags & P_EXPAND)
9653 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9654 /* Translate 'pastetoggle' into special key names */
9655 else if ((char_u **)opp->var == &p_pt)
9656 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9657 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009658 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009659 }
9660}
9661
9662/*
9663 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9664 * printed as a keyname.
9665 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9666 */
9667 static int
9668wc_use_keyname(varp, wcp)
9669 char_u *varp;
9670 long *wcp;
9671{
9672 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9673 {
9674 *wcp = *(long *)varp;
9675 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9676 return TRUE;
9677 }
9678 return FALSE;
9679}
9680
9681#ifdef FEAT_LANGMAP
9682/*
9683 * Any character has an equivalent character. This is used for keyboards that
9684 * have a special language mode that sends characters above 128 (although
9685 * other characters can be translated too).
9686 */
9687
9688/*
9689 * char_u langmap_mapchar[256];
9690 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9691 * "translate" native lang chars in normal mode or some cases of
9692 * insert mode without having to tediously switch lang mode back&forth.
9693 */
9694
9695 static void
9696langmap_init()
9697{
9698 int i;
9699
9700 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9701 langmap_mapchar[i] = i;
9702}
9703
9704/*
9705 * Called when langmap option is set; the language map can be
9706 * changed at any time!
9707 */
9708 static void
9709langmap_set()
9710{
9711 char_u *p;
9712 char_u *p2;
9713 int from, to;
9714
9715 langmap_init(); /* back to one-to-one map first */
9716
9717 for (p = p_langmap; p[0] != NUL; )
9718 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009719 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9720 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721 {
9722 if (p2[0] == '\\' && p2[1] != NUL)
9723 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009724 }
9725 if (p2[0] == ';')
9726 ++p2; /* abcd;ABCD form, p2 points to A */
9727 else
9728 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9729 while (p[0])
9730 {
9731 if (p[0] == '\\' && p[1] != NUL)
9732 ++p;
9733#ifdef FEAT_MBYTE
9734 from = (*mb_ptr2char)(p);
9735#else
9736 from = p[0];
9737#endif
9738 if (p2 == NULL)
9739 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009740 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741 if (p[0] == '\\')
9742 ++p;
9743#ifdef FEAT_MBYTE
9744 to = (*mb_ptr2char)(p);
9745#else
9746 to = p[0];
9747#endif
9748 }
9749 else
9750 {
9751 if (p2[0] == '\\')
9752 ++p2;
9753#ifdef FEAT_MBYTE
9754 to = (*mb_ptr2char)(p2);
9755#else
9756 to = p2[0];
9757#endif
9758 }
9759 if (to == NUL)
9760 {
9761 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9762 transchar(from));
9763 return;
9764 }
9765 langmap_mapchar[from & 255] = to;
9766
9767 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009768 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009769 if (p2 == NULL)
9770 {
9771 if (p[0] == ',')
9772 {
9773 ++p;
9774 break;
9775 }
9776 }
9777 else
9778 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009779 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009780 if (*p == ';')
9781 {
9782 p = p2;
9783 if (p[0] != NUL)
9784 {
9785 if (p[0] != ',')
9786 {
9787 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9788 return;
9789 }
9790 ++p;
9791 }
9792 break;
9793 }
9794 }
9795 }
9796 }
9797}
9798#endif
9799
9800/*
9801 * Return TRUE if format option 'x' is in effect.
9802 * Take care of no formatting when 'paste' is set.
9803 */
9804 int
9805has_format_option(x)
9806 int x;
9807{
9808 if (p_paste)
9809 return FALSE;
9810 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9811}
9812
9813/*
9814 * Return TRUE if "x" is present in 'shortmess' option, or
9815 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9816 */
9817 int
9818shortmess(x)
9819 int x;
9820{
9821 return ( vim_strchr(p_shm, x) != NULL
9822 || (vim_strchr(p_shm, 'a') != NULL
9823 && vim_strchr((char_u *)SHM_A, x) != NULL));
9824}
9825
9826/*
9827 * paste_option_changed() - Called after p_paste was set or reset.
9828 */
9829 static void
9830paste_option_changed()
9831{
9832 static int old_p_paste = FALSE;
9833 static int save_sm = 0;
9834#ifdef FEAT_CMDL_INFO
9835 static int save_ru = 0;
9836#endif
9837#ifdef FEAT_RIGHTLEFT
9838 static int save_ri = 0;
9839 static int save_hkmap = 0;
9840#endif
9841 buf_T *buf;
9842
9843 if (p_paste)
9844 {
9845 /*
9846 * Paste switched from off to on.
9847 * Save the current values, so they can be restored later.
9848 */
9849 if (!old_p_paste)
9850 {
9851 /* save options for each buffer */
9852 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9853 {
9854 buf->b_p_tw_nopaste = buf->b_p_tw;
9855 buf->b_p_wm_nopaste = buf->b_p_wm;
9856 buf->b_p_sts_nopaste = buf->b_p_sts;
9857 buf->b_p_ai_nopaste = buf->b_p_ai;
9858 }
9859
9860 /* save global options */
9861 save_sm = p_sm;
9862#ifdef FEAT_CMDL_INFO
9863 save_ru = p_ru;
9864#endif
9865#ifdef FEAT_RIGHTLEFT
9866 save_ri = p_ri;
9867 save_hkmap = p_hkmap;
9868#endif
9869 /* save global values for local buffer options */
9870 p_tw_nopaste = p_tw;
9871 p_wm_nopaste = p_wm;
9872 p_sts_nopaste = p_sts;
9873 p_ai_nopaste = p_ai;
9874 }
9875
9876 /*
9877 * Always set the option values, also when 'paste' is set when it is
9878 * already on.
9879 */
9880 /* set options for each buffer */
9881 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9882 {
9883 buf->b_p_tw = 0; /* textwidth is 0 */
9884 buf->b_p_wm = 0; /* wrapmargin is 0 */
9885 buf->b_p_sts = 0; /* softtabstop is 0 */
9886 buf->b_p_ai = 0; /* no auto-indent */
9887 }
9888
9889 /* set global options */
9890 p_sm = 0; /* no showmatch */
9891#ifdef FEAT_CMDL_INFO
9892# ifdef FEAT_WINDOWS
9893 if (p_ru)
9894 status_redraw_all(); /* redraw to remove the ruler */
9895# endif
9896 p_ru = 0; /* no ruler */
9897#endif
9898#ifdef FEAT_RIGHTLEFT
9899 p_ri = 0; /* no reverse insert */
9900 p_hkmap = 0; /* no Hebrew keyboard */
9901#endif
9902 /* set global values for local buffer options */
9903 p_tw = 0;
9904 p_wm = 0;
9905 p_sts = 0;
9906 p_ai = 0;
9907 }
9908
9909 /*
9910 * Paste switched from on to off: Restore saved values.
9911 */
9912 else if (old_p_paste)
9913 {
9914 /* restore options for each buffer */
9915 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9916 {
9917 buf->b_p_tw = buf->b_p_tw_nopaste;
9918 buf->b_p_wm = buf->b_p_wm_nopaste;
9919 buf->b_p_sts = buf->b_p_sts_nopaste;
9920 buf->b_p_ai = buf->b_p_ai_nopaste;
9921 }
9922
9923 /* restore global options */
9924 p_sm = save_sm;
9925#ifdef FEAT_CMDL_INFO
9926# ifdef FEAT_WINDOWS
9927 if (p_ru != save_ru)
9928 status_redraw_all(); /* redraw to draw the ruler */
9929# endif
9930 p_ru = save_ru;
9931#endif
9932#ifdef FEAT_RIGHTLEFT
9933 p_ri = save_ri;
9934 p_hkmap = save_hkmap;
9935#endif
9936 /* set global values for local buffer options */
9937 p_tw = p_tw_nopaste;
9938 p_wm = p_wm_nopaste;
9939 p_sts = p_sts_nopaste;
9940 p_ai = p_ai_nopaste;
9941 }
9942
9943 old_p_paste = p_paste;
9944}
9945
9946/*
9947 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9948 *
9949 * Reset 'compatible' and set the values for options that didn't get set yet
9950 * to the Vim defaults.
9951 * Don't do this if the 'compatible' option has been set or reset before.
9952 */
9953 void
9954vimrc_found()
9955{
9956 int opt_idx;
9957
9958 if (!option_was_set((char_u *)"cp"))
9959 {
9960 p_cp = FALSE;
9961 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9962 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9963 set_option_default(opt_idx, OPT_FREE, FALSE);
9964 didset_options();
9965 }
9966}
9967
9968/*
9969 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9970 */
9971 void
9972change_compatible(on)
9973 int on;
9974{
9975 if (p_cp != on)
9976 {
9977 p_cp = on;
9978 compatible_set();
9979 }
9980 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9981}
9982
9983/*
9984 * Return TRUE when option "name" has been set.
9985 */
9986 int
9987option_was_set(name)
9988 char_u *name;
9989{
9990 int idx;
9991
9992 idx = findoption(name);
9993 if (idx < 0) /* unknown option */
9994 return FALSE;
9995 if (options[idx].flags & P_WAS_SET)
9996 return TRUE;
9997 return FALSE;
9998}
9999
10000/*
10001 * compatible_set() - Called when 'compatible' has been set or unset.
10002 *
10003 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10004 * flag) to a Vi compatible value.
10005 * When 'compatible' is unset: Set all options that have a different default
10006 * for Vim (without the P_VI_DEF flag) to that default.
10007 */
10008 static void
10009compatible_set()
10010{
10011 int opt_idx;
10012
10013 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10014 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10015 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10016 set_option_default(opt_idx, OPT_FREE, p_cp);
10017 didset_options();
10018}
10019
10020#ifdef FEAT_LINEBREAK
10021
10022# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10023 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010024 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010025# endif
10026
10027/*
10028 * fill_breakat_flags() -- called when 'breakat' changes value.
10029 */
10030 static void
10031fill_breakat_flags()
10032{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010033 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034 int i;
10035
10036 for (i = 0; i < 256; i++)
10037 breakat_flags[i] = FALSE;
10038
10039 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010040 for (p = p_breakat; *p; p++)
10041 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042}
10043
10044# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010045 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046# endif
10047
10048#endif
10049
10050/*
10051 * Check an option that can be a range of string values.
10052 *
10053 * Return OK for correct value, FAIL otherwise.
10054 * Empty is always OK.
10055 */
10056 static int
10057check_opt_strings(val, values, list)
10058 char_u *val;
10059 char **values;
10060 int list; /* when TRUE: accept a list of values */
10061{
10062 return opt_strings_flags(val, values, NULL, list);
10063}
10064
10065/*
10066 * Handle an option that can be a range of string values.
10067 * Set a flag in "*flagp" for each string present.
10068 *
10069 * Return OK for correct value, FAIL otherwise.
10070 * Empty is always OK.
10071 */
10072 static int
10073opt_strings_flags(val, values, flagp, list)
10074 char_u *val; /* new value */
10075 char **values; /* array of valid string values */
10076 unsigned *flagp;
10077 int list; /* when TRUE: accept a list of values */
10078{
10079 int i;
10080 int len;
10081 unsigned new_flags = 0;
10082
10083 while (*val)
10084 {
10085 for (i = 0; ; ++i)
10086 {
10087 if (values[i] == NULL) /* val not found in values[] */
10088 return FAIL;
10089
10090 len = (int)STRLEN(values[i]);
10091 if (STRNCMP(values[i], val, len) == 0
10092 && ((list && val[len] == ',') || val[len] == NUL))
10093 {
10094 val += len + (val[len] == ',');
10095 new_flags |= (1 << i);
10096 break; /* check next item in val list */
10097 }
10098 }
10099 }
10100 if (flagp != NULL)
10101 *flagp = new_flags;
10102
10103 return OK;
10104}
10105
10106/*
10107 * Read the 'wildmode' option, fill wim_flags[].
10108 */
10109 static int
10110check_opt_wim()
10111{
10112 char_u new_wim_flags[4];
10113 char_u *p;
10114 int i;
10115 int idx = 0;
10116
10117 for (i = 0; i < 4; ++i)
10118 new_wim_flags[i] = 0;
10119
10120 for (p = p_wim; *p; ++p)
10121 {
10122 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10123 ;
10124 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10125 return FAIL;
10126 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10127 new_wim_flags[idx] |= WIM_LONGEST;
10128 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10129 new_wim_flags[idx] |= WIM_FULL;
10130 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10131 new_wim_flags[idx] |= WIM_LIST;
10132 else
10133 return FAIL;
10134 p += i;
10135 if (*p == NUL)
10136 break;
10137 if (*p == ',')
10138 {
10139 if (idx == 3)
10140 return FAIL;
10141 ++idx;
10142 }
10143 }
10144
10145 /* fill remaining entries with last flag */
10146 while (idx < 3)
10147 {
10148 new_wim_flags[idx + 1] = new_wim_flags[idx];
10149 ++idx;
10150 }
10151
10152 /* only when there are no errors, wim_flags[] is changed */
10153 for (i = 0; i < 4; ++i)
10154 wim_flags[i] = new_wim_flags[i];
10155 return OK;
10156}
10157
10158/*
10159 * Check if backspacing over something is allowed.
10160 */
10161 int
10162can_bs(what)
10163 int what; /* BS_INDENT, BS_EOL or BS_START */
10164{
10165 switch (*p_bs)
10166 {
10167 case '2': return TRUE;
10168 case '1': return (what != BS_START);
10169 case '0': return FALSE;
10170 }
10171 return vim_strchr(p_bs, what) != NULL;
10172}
10173
10174/*
10175 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10176 * the file must be considered changed when the value is different.
10177 */
10178 void
10179save_file_ff(buf)
10180 buf_T *buf;
10181{
10182 buf->b_start_ffc = *buf->b_p_ff;
10183 buf->b_start_eol = buf->b_p_eol;
10184#ifdef FEAT_MBYTE
10185 /* Only use free/alloc when necessary, they take time. */
10186 if (buf->b_start_fenc == NULL
10187 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10188 {
10189 vim_free(buf->b_start_fenc);
10190 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10191 }
10192#endif
10193}
10194
10195/*
10196 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10197 * from when editing started (save_file_ff() called).
10198 * Also when 'endofline' was changed and 'binary' is set.
10199 * Don't consider a new, empty buffer to be changed.
10200 */
10201 int
10202file_ff_differs(buf)
10203 buf_T *buf;
10204{
10205 if ((buf->b_flags & BF_NEW)
10206 && buf->b_ml.ml_line_count == 1
10207 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10208 return FALSE;
10209 if (buf->b_start_ffc != *buf->b_p_ff)
10210 return TRUE;
10211 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10212 return TRUE;
10213#ifdef FEAT_MBYTE
10214 if (buf->b_start_fenc == NULL)
10215 return (*buf->b_p_fenc != NUL);
10216 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10217#else
10218 return FALSE;
10219#endif
10220}
10221
10222/*
10223 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10224 */
10225 int
10226check_ff_value(p)
10227 char_u *p;
10228{
10229 return check_opt_strings(p, p_ff_values, FALSE);
10230}