blob: 3d9c77849d87718696c625fa4fb744abc4ffc691 [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)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001102 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001104 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105# 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}},
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001118 {"guitablabel", "gtl", P_STRING|P_VI_DEF,
1119#if defined(FEAT_GUI_TABLINE)
1120 (char_u *)&p_gtl, PV_NONE,
1121 {(char_u *)"", (char_u *)0L}
1122#else
1123 (char_u *)NULL, PV_NONE,
1124 {(char_u *)NULL, (char_u *)0L}
1125#endif
1126 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1128 (char_u *)NULL, PV_NONE,
1129 {(char_u *)0L, (char_u *)0L}},
1130 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1131 (char_u *)&p_hf, PV_NONE,
1132 {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
1133 {"helpheight", "hh", P_NUM|P_VI_DEF,
1134#ifdef FEAT_WINDOWS
1135 (char_u *)&p_hh, PV_NONE,
1136#else
1137 (char_u *)NULL, PV_NONE,
1138#endif
1139 {(char_u *)20L, (char_u *)0L}},
1140 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1141#ifdef FEAT_MULTI_LANG
1142 (char_u *)&p_hlg, PV_NONE,
1143 {(char_u *)"", (char_u *)0L}
1144#else
1145 (char_u *)NULL, PV_NONE,
1146 {(char_u *)0L, (char_u *)0L}
1147#endif
1148 },
1149 {"hidden", "hid", P_BOOL|P_VI_DEF,
1150 (char_u *)&p_hid, PV_NONE,
1151 {(char_u *)FALSE, (char_u *)0L}},
1152 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1153 (char_u *)&p_hl, PV_NONE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00001154 {(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 +00001155 (char_u *)0L}},
1156 {"history", "hi", P_NUM|P_VIM,
1157 (char_u *)&p_hi, PV_NONE,
1158 {(char_u *)0L, (char_u *)20L}},
1159 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1160#ifdef FEAT_RIGHTLEFT
1161 (char_u *)&p_hkmap, PV_NONE,
1162#else
1163 (char_u *)NULL, PV_NONE,
1164#endif
1165 {(char_u *)FALSE, (char_u *)0L}},
1166 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1167#ifdef FEAT_RIGHTLEFT
1168 (char_u *)&p_hkmapp, PV_NONE,
1169#else
1170 (char_u *)NULL, PV_NONE,
1171#endif
1172 {(char_u *)FALSE, (char_u *)0L}},
1173 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1174 (char_u *)&p_hls, PV_NONE,
1175 {(char_u *)FALSE, (char_u *)0L}},
1176 {"icon", NULL, P_BOOL|P_VI_DEF,
1177#ifdef FEAT_TITLE
1178 (char_u *)&p_icon, PV_NONE,
1179#else
1180 (char_u *)NULL, PV_NONE,
1181#endif
1182 {(char_u *)FALSE, (char_u *)0L}},
1183 {"iconstring", NULL, P_STRING|P_VI_DEF,
1184#ifdef FEAT_TITLE
1185 (char_u *)&p_iconstring, PV_NONE,
1186#else
1187 (char_u *)NULL, PV_NONE,
1188#endif
1189 {(char_u *)"", (char_u *)0L}},
1190 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1191 (char_u *)&p_ic, PV_NONE,
1192 {(char_u *)FALSE, (char_u *)0L}},
1193 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001194#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 (char_u *)&p_imak, PV_NONE,
1196#else
1197 (char_u *)NULL, PV_NONE,
1198#endif
1199 {(char_u *)"", (char_u *)0L}},
1200 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1201#ifdef USE_IM_CONTROL
1202 (char_u *)&p_imcmdline, PV_NONE,
1203#else
1204 (char_u *)NULL, PV_NONE,
1205#endif
1206 {(char_u *)FALSE, (char_u *)0L}},
1207 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1208#ifdef USE_IM_CONTROL
1209 (char_u *)&p_imdisable, PV_NONE,
1210#else
1211 (char_u *)NULL, PV_NONE,
1212#endif
1213#ifdef __sgi
1214 {(char_u *)TRUE, (char_u *)0L}
1215#else
1216 {(char_u *)FALSE, (char_u *)0L}
1217#endif
1218 },
1219 {"iminsert", "imi", P_NUM|P_VI_DEF,
1220 (char_u *)&p_iminsert, PV_IMI,
1221#ifdef B_IMODE_IM
1222 {(char_u *)B_IMODE_IM, (char_u *)0L}
1223#else
1224 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1225#endif
1226 },
1227 {"imsearch", "ims", P_NUM|P_VI_DEF,
1228 (char_u *)&p_imsearch, PV_IMS,
1229#ifdef B_IMODE_IM
1230 {(char_u *)B_IMODE_IM, (char_u *)0L}
1231#else
1232 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1233#endif
1234 },
1235 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1236#ifdef FEAT_FIND_ID
1237 (char_u *)&p_inc, OPT_BOTH(PV_INC),
1238 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)0L, (char_u *)0L}
1242#endif
1243 },
1244 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1245#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1246 (char_u *)&p_inex, PV_INEX,
1247 {(char_u *)"", (char_u *)0L}
1248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)0L, (char_u *)0L}
1251#endif
1252 },
1253 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1254 (char_u *)&p_is, PV_NONE,
1255 {(char_u *)FALSE, (char_u *)0L}},
1256 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1257#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1258 (char_u *)&p_inde, PV_INDE,
1259 {(char_u *)"", (char_u *)0L}
1260#else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)0L, (char_u *)0L}
1263#endif
1264 },
1265 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1266#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1267 (char_u *)&p_indk, PV_INDK,
1268 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1269#else
1270 (char_u *)NULL, PV_NONE,
1271 {(char_u *)0L, (char_u *)0L}
1272#endif
1273 },
1274 {"infercase", "inf", P_BOOL|P_VI_DEF,
1275 (char_u *)&p_inf, PV_INF,
1276 {(char_u *)FALSE, (char_u *)0L}},
1277 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1278 (char_u *)&p_im, PV_NONE,
1279 {(char_u *)FALSE, (char_u *)0L}},
1280 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1281 (char_u *)&p_isf, PV_NONE,
1282 {
1283#ifdef BACKSLASH_IN_FILENAME
1284 /* Excluded are: & and ^ are special in cmd.exe
1285 * ( and ) are used in text separating fnames */
1286 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1287#else
1288# ifdef AMIGA
1289 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1290# else
1291# ifdef VMS
1292 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1293# else /* UNIX et al. */
1294# ifdef EBCDIC
1295 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1296# else
1297 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1298# endif
1299# endif
1300# endif
1301#endif
1302 (char_u *)0L}},
1303 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1304 (char_u *)&p_isi, PV_NONE,
1305 {
1306#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1307 (char_u *)"@,48-57,_,128-167,224-235",
1308#else
1309# ifdef EBCDIC
1310 /* TODO: EBCDIC Check this! @ == isalpha()*/
1311 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1312 "112-120,128,140-142,156,158,172,"
1313 "174,186,191,203-207,219-225,235-239,"
1314 "251-254",
1315# else
1316 (char_u *)"@,48-57,_,192-255",
1317# endif
1318#endif
1319 (char_u *)0L}},
1320 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1321 (char_u *)&p_isk, PV_ISK,
1322 {
1323#ifdef EBCDIC
1324 (char_u *)"@,240-249,_",
1325 /* TODO: EBCDIC Check this! @ == isalpha()*/
1326 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1327 "112-120,128,140-142,156,158,172,"
1328 "174,186,191,203-207,219-225,235-239,"
1329 "251-254",
1330#else
1331 (char_u *)"@,48-57,_",
1332# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1333 (char_u *)"@,48-57,_,128-167,224-235"
1334# else
1335 (char_u *)"@,48-57,_,192-255"
1336# endif
1337#endif
1338 }},
1339 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1340 (char_u *)&p_isp, PV_NONE,
1341 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001342#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1343 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 || defined(VMS)
1345 (char_u *)"@,~-255",
1346#else
1347# ifdef EBCDIC
1348 /* all chars above 63 are printable */
1349 (char_u *)"63-255",
1350# else
1351 (char_u *)"@,161-255",
1352# endif
1353#endif
1354 (char_u *)0L}},
1355 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1356 (char_u *)&p_js, PV_NONE,
1357 {(char_u *)TRUE, (char_u *)0L}},
1358 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1359#ifdef FEAT_CRYPT
1360 (char_u *)&p_key, PV_KEY,
1361 {(char_u *)"", (char_u *)0L}
1362#else
1363 (char_u *)NULL, PV_NONE,
1364 {(char_u *)0L, (char_u *)0L}
1365#endif
1366 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001367 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368#ifdef FEAT_KEYMAP
1369 (char_u *)&p_keymap, PV_KMAP,
1370 {(char_u *)"", (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)"", (char_u *)0L}
1374#endif
1375 },
1376 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1377#ifdef FEAT_VISUAL
1378 (char_u *)&p_km, PV_NONE,
1379#else
1380 (char_u *)NULL, PV_NONE,
1381#endif
1382 {(char_u *)"", (char_u *)0L}},
1383 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1384 (char_u *)&p_kp, OPT_BOTH(PV_KP),
1385 {
1386#if defined(MSDOS) || defined(MSWIN)
1387 (char_u *)":help",
1388#else
1389#ifdef VMS
1390 (char_u *)"help",
1391#else
1392# if defined(OS2)
1393 (char_u *)"view /",
1394# else
1395# ifdef USEMAN_S
1396 (char_u *)"man -s",
1397# else
1398 (char_u *)"man",
1399# endif
1400# endif
1401#endif
1402#endif
1403 (char_u *)0L}},
1404 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1405#ifdef FEAT_LANGMAP
1406 (char_u *)&p_langmap, PV_NONE,
1407 {(char_u *)"", /* unmatched } */
1408#else
1409 (char_u *)NULL, PV_NONE,
1410 {(char_u *)NULL,
1411#endif
1412 (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001413 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001414#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1415 (char_u *)&p_lm, PV_NONE,
1416#else
1417 (char_u *)NULL, PV_NONE,
1418#endif
1419 {(char_u *)"", (char_u *)0L}},
1420 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1421#ifdef FEAT_WINDOWS
1422 (char_u *)&p_ls, PV_NONE,
1423#else
1424 (char_u *)NULL, PV_NONE,
1425#endif
1426 {(char_u *)1L, (char_u *)0L}},
1427 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1428 (char_u *)&p_lz, PV_NONE,
1429 {(char_u *)FALSE, (char_u *)0L}},
1430 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1431#ifdef FEAT_LINEBREAK
1432 (char_u *)VAR_WIN, PV_LBR,
1433#else
1434 (char_u *)NULL, PV_NONE,
1435#endif
1436 {(char_u *)FALSE, (char_u *)0L}},
1437 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1438 (char_u *)&Rows, PV_NONE,
1439 {
1440#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1441 (char_u *)25L,
1442#else
1443 (char_u *)24L,
1444#endif
1445 (char_u *)0L}},
1446 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1447#ifdef FEAT_GUI
1448 (char_u *)&p_linespace, PV_NONE,
1449#else
1450 (char_u *)NULL, PV_NONE,
1451#endif
1452#ifdef FEAT_GUI_W32
1453 {(char_u *)1L, (char_u *)0L}
1454#else
1455 {(char_u *)0L, (char_u *)0L}
1456#endif
1457 },
1458 {"lisp", NULL, P_BOOL|P_VI_DEF,
1459#ifdef FEAT_LISP
1460 (char_u *)&p_lisp, PV_LISP,
1461#else
1462 (char_u *)NULL, PV_NONE,
1463#endif
1464 {(char_u *)FALSE, (char_u *)0L}},
1465 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1466#ifdef FEAT_LISP
1467 (char_u *)&p_lispwords, PV_NONE,
1468 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1469#else
1470 (char_u *)NULL, PV_NONE,
1471 {(char_u *)"", (char_u *)0L}
1472#endif
1473 },
1474 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1475 (char_u *)VAR_WIN, PV_LIST,
1476 {(char_u *)FALSE, (char_u *)0L}},
1477 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1478 (char_u *)&p_lcs, PV_NONE,
1479 {(char_u *)"eol:$", (char_u *)0L}},
1480 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1481 (char_u *)&p_lpl, PV_NONE,
1482 {(char_u *)TRUE, (char_u *)0L}},
1483 {"magic", NULL, P_BOOL|P_VI_DEF,
1484 (char_u *)&p_magic, PV_NONE,
1485 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001486 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487#ifdef FEAT_QUICKFIX
1488 (char_u *)&p_mef, PV_NONE,
1489 {(char_u *)"", (char_u *)0L}
1490#else
1491 (char_u *)NULL, PV_NONE,
1492 {(char_u *)NULL, (char_u *)0L}
1493#endif
1494 },
1495 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1496#ifdef FEAT_QUICKFIX
1497 (char_u *)&p_mp, OPT_BOTH(PV_MP),
1498# ifdef VMS
1499 {(char_u *)"MMS", (char_u *)0L}
1500# else
1501 {(char_u *)"make", (char_u *)0L}
1502# endif
1503#else
1504 (char_u *)NULL, PV_NONE,
1505 {(char_u *)NULL, (char_u *)0L}
1506#endif
1507 },
1508 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1509 (char_u *)&p_mps, PV_MPS,
1510 {(char_u *)"(:),{:},[:]", (char_u *)0L}},
1511 {"matchtime", "mat", P_NUM|P_VI_DEF,
1512 (char_u *)&p_mat, PV_NONE,
1513 {(char_u *)5L, (char_u *)0L}},
1514 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1515#ifdef FEAT_EVAL
1516 (char_u *)&p_mfd, PV_NONE,
1517#else
1518 (char_u *)NULL, PV_NONE,
1519#endif
1520 {(char_u *)100L, (char_u *)0L}},
1521 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1522 (char_u *)&p_mmd, PV_NONE,
1523 {(char_u *)1000L, (char_u *)0L}},
1524 {"maxmem", "mm", P_NUM|P_VI_DEF,
1525 (char_u *)&p_mm, PV_NONE,
1526 {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001527 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1528 (char_u *)&p_mmp, PV_NONE,
1529 {(char_u *)1000L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1531 (char_u *)&p_mmt, PV_NONE,
1532 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
1533 {"menuitems", "mis", P_NUM|P_VI_DEF,
1534#ifdef FEAT_MENU
1535 (char_u *)&p_mis, PV_NONE,
1536#else
1537 (char_u *)NULL, PV_NONE,
1538#endif
1539 {(char_u *)25L, (char_u *)0L}},
1540 {"mesg", NULL, P_BOOL|P_VI_DEF,
1541 (char_u *)NULL, PV_NONE,
1542 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001543 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
1544#ifdef FEAT_SYN_HL
1545 (char_u *)&p_msm, PV_NONE,
1546 {(char_u *)"460000,2000,500", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
1551 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 {"modeline", "ml", P_BOOL|P_VIM,
1553 (char_u *)&p_ml, PV_ML,
1554 {(char_u *)FALSE, (char_u *)TRUE}},
1555 {"modelines", "mls", P_NUM|P_VI_DEF,
1556 (char_u *)&p_mls, PV_NONE,
1557 {(char_u *)5L, (char_u *)0L}},
1558 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1559 (char_u *)&p_ma, PV_MA,
1560 {(char_u *)TRUE, (char_u *)0L}},
1561 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1562 (char_u *)&p_mod, PV_MOD,
1563 {(char_u *)FALSE, (char_u *)0L}},
1564 {"more", NULL, P_BOOL|P_VIM,
1565 (char_u *)&p_more, PV_NONE,
1566 {(char_u *)FALSE, (char_u *)TRUE}},
1567 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1568 (char_u *)&p_mouse, PV_NONE,
1569 {
1570#if defined(MSDOS) || defined(WIN3264)
1571 (char_u *)"a",
1572#else
1573 (char_u *)"",
1574#endif
1575 (char_u *)0L}},
1576 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1577#ifdef FEAT_GUI
1578 (char_u *)&p_mousef, PV_NONE,
1579#else
1580 (char_u *)NULL, PV_NONE,
1581#endif
1582 {(char_u *)FALSE, (char_u *)0L}},
1583 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1584#ifdef FEAT_GUI
1585 (char_u *)&p_mh, PV_NONE,
1586#else
1587 (char_u *)NULL, PV_NONE,
1588#endif
1589 {(char_u *)TRUE, (char_u *)0L}},
1590 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1591 (char_u *)&p_mousem, PV_NONE,
1592 {
1593#if defined(MSDOS) || defined(MSWIN)
1594 (char_u *)"popup",
1595#else
1596# if defined(MACOS)
1597 (char_u *)"popup_setpos",
1598# else
1599 (char_u *)"extend",
1600# endif
1601#endif
1602 (char_u *)0L}},
1603 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1604#ifdef FEAT_MOUSESHAPE
1605 (char_u *)&p_mouseshape, PV_NONE,
1606 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1607#else
1608 (char_u *)NULL, PV_NONE,
1609 {(char_u *)NULL, (char_u *)0L}
1610#endif
1611 },
1612 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1613 (char_u *)&p_mouset, PV_NONE,
1614 {(char_u *)500L, (char_u *)0L}},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001615 {"mzquantum", "mzq", P_NUM,
1616#ifdef FEAT_MZSCHEME
1617 (char_u *)&p_mzq, PV_NONE,
1618#else
1619 (char_u *)NULL, PV_NONE,
1620#endif
1621 {(char_u *)100L, (char_u *)100L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622 {"novice", NULL, P_BOOL|P_VI_DEF,
1623 (char_u *)NULL, PV_NONE,
1624 {(char_u *)FALSE, (char_u *)0L}},
1625 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1626 (char_u *)&p_nf, PV_NF,
1627 {(char_u *)"octal,hex", (char_u *)0L}},
1628 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1629 (char_u *)VAR_WIN, PV_NU,
1630 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001631 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1632#ifdef FEAT_LINEBREAK
1633 (char_u *)VAR_WIN, PV_NUW,
1634#else
1635 (char_u *)NULL, PV_NONE,
1636#endif
1637 {(char_u *)8L, (char_u *)4L}},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001638 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001639#ifdef FEAT_COMPL_FUNC
1640 (char_u *)&p_ofu, PV_OFU,
1641 {(char_u *)"", (char_u *)0L}
1642#else
1643 (char_u *)NULL, PV_NONE,
1644 {(char_u *)0L, (char_u *)0L}
1645#endif
1646 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"open", NULL, P_BOOL|P_VI_DEF,
1648 (char_u *)NULL, PV_NONE,
1649 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001650 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1651 (char_u *)&p_opfunc, PV_NONE,
1652 {(char_u *)"", (char_u *)0L} },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"optimize", "opt", P_BOOL|P_VI_DEF,
1654 (char_u *)NULL, PV_NONE,
1655 {(char_u *)FALSE, (char_u *)0L}},
1656 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1657#ifdef FEAT_OSFILETYPE
1658 (char_u *)&p_oft, PV_OFT,
1659 {(char_u *)DFLT_OFT, (char_u *)0L}
1660#else
1661 (char_u *)NULL, PV_NONE,
1662 {(char_u *)0L, (char_u *)0L}
1663#endif
1664 },
1665 {"paragraphs", "para", P_STRING|P_VI_DEF,
1666 (char_u *)&p_para, PV_NONE,
1667 {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}},
1668 {"paste", NULL, P_BOOL|P_VI_DEF,
1669 (char_u *)&p_paste, PV_NONE,
1670 {(char_u *)FALSE, (char_u *)0L}},
1671 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1672 (char_u *)&p_pt, PV_NONE,
1673 {(char_u *)"", (char_u *)0L}},
1674 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1675#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1676 (char_u *)&p_pex, PV_NONE,
1677 {(char_u *)"", (char_u *)0L}
1678#else
1679 (char_u *)NULL, PV_NONE,
1680 {(char_u *)0L, (char_u *)0L}
1681#endif
1682 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001683 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 (char_u *)&p_pm, PV_NONE,
1685 {(char_u *)"", (char_u *)0L}},
1686 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
1687 (char_u *)&p_path, OPT_BOTH(PV_PATH),
1688 {
1689#if defined AMIGA || defined MSDOS || defined MSWIN
1690 (char_u *)".,,",
1691#else
1692# if defined(__EMX__)
1693 (char_u *)".,/emx/include,,",
1694# else /* Unix, probably */
1695 (char_u *)".,/usr/include,,",
1696# endif
1697#endif
1698 (char_u *)0L}},
1699 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1700 (char_u *)&p_pi, PV_PI,
1701 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001702 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1704 (char_u *)&p_pvh, PV_NONE,
1705#else
1706 (char_u *)NULL, PV_NONE,
1707#endif
1708 {(char_u *)12L, (char_u *)0L}},
1709 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1710#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1711 (char_u *)VAR_WIN, PV_PVW,
1712#else
1713 (char_u *)NULL, PV_NONE,
1714#endif
1715 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001716 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717#ifdef FEAT_PRINTER
1718 (char_u *)&p_pdev, 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 {"printencoding", "penc", P_STRING|P_VI_DEF,
1726#ifdef FEAT_POSTSCRIPT
1727 (char_u *)&p_penc, 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 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1735#ifdef FEAT_POSTSCRIPT
1736 (char_u *)&p_pexpr, PV_NONE,
1737 {(char_u *)"", (char_u *)0L}
1738#else
1739 (char_u *)NULL, PV_NONE,
1740 {(char_u *)NULL, (char_u *)0L}
1741#endif
1742 },
1743 {"printfont", "pfn", P_STRING|P_VI_DEF,
1744#ifdef FEAT_PRINTER
1745 (char_u *)&p_pfn, PV_NONE,
1746 {
1747# ifdef MSWIN
1748 (char_u *)"Courier_New:h10",
1749# else
1750 (char_u *)"courier",
1751# endif
1752 (char_u *)0L}
1753#else
1754 (char_u *)NULL, PV_NONE,
1755 {(char_u *)NULL, (char_u *)0L}
1756#endif
1757 },
1758 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1759#ifdef FEAT_PRINTER
1760 (char_u *)&p_header, PV_NONE,
1761 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1762#else
1763 (char_u *)NULL, PV_NONE,
1764 {(char_u *)NULL, (char_u *)0L}
1765#endif
1766 },
Bram Moolenaar8299df92004-07-10 09:47:34 +00001767 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1768#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1769 (char_u *)&p_pmcs, 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 },
1776 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1777#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1778 (char_u *)&p_pmfn, 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 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1786#ifdef FEAT_PRINTER
1787 (char_u *)&p_popt, PV_NONE,
1788 {(char_u *)"", (char_u *)0L}
1789#else
1790 (char_u *)NULL, PV_NONE,
1791 {(char_u *)NULL, (char_u *)0L}
1792#endif
1793 },
1794 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001795 (char_u *)&p_prompt, PV_NONE,
1796 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001797 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
1798#ifdef FEAT_TEXTOBJ
1799 (char_u *)&p_qe, PV_QE,
1800 {(char_u *)"\\", (char_u *)0L}
1801#else
1802 (char_u *)NULL, PV_NONE,
1803 {(char_u *)NULL, (char_u *)0L}
1804#endif
1805 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001806 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1807 (char_u *)&p_ro, PV_RO,
1808 {(char_u *)FALSE, (char_u *)0L}},
1809 {"redraw", NULL, P_BOOL|P_VI_DEF,
1810 (char_u *)NULL, PV_NONE,
1811 {(char_u *)FALSE, (char_u *)0L}},
1812 {"remap", NULL, P_BOOL|P_VI_DEF,
1813 (char_u *)&p_remap, PV_NONE,
1814 {(char_u *)TRUE, (char_u *)0L}},
1815 {"report", NULL, P_NUM|P_VI_DEF,
1816 (char_u *)&p_report, PV_NONE,
1817 {(char_u *)2L, (char_u *)0L}},
1818 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
1819#ifdef WIN3264
1820 (char_u *)&p_rs, PV_NONE,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
1824 {(char_u *)TRUE, (char_u *)0L}},
1825 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
1826#ifdef FEAT_RIGHTLEFT
1827 (char_u *)&p_ri, PV_NONE,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
1831 {(char_u *)FALSE, (char_u *)0L}},
1832 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
1833#ifdef FEAT_RIGHTLEFT
1834 (char_u *)VAR_WIN, PV_RL,
1835#else
1836 (char_u *)NULL, PV_NONE,
1837#endif
1838 {(char_u *)FALSE, (char_u *)0L}},
1839 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
1840#ifdef FEAT_RIGHTLEFT
1841 (char_u *)VAR_WIN, PV_RLC,
1842 {(char_u *)"search", (char_u *)NULL}
1843#else
1844 (char_u *)NULL, PV_NONE,
1845 {(char_u *)NULL, (char_u *)0L}
1846#endif
1847 },
1848 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
1849#ifdef FEAT_CMDL_INFO
1850 (char_u *)&p_ru, PV_NONE,
1851#else
1852 (char_u *)NULL, PV_NONE,
1853#endif
1854 {(char_u *)FALSE, (char_u *)0L}},
1855 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
1856#ifdef FEAT_STL_OPT
1857 (char_u *)&p_ruf, PV_NONE,
1858#else
1859 (char_u *)NULL, PV_NONE,
1860#endif
1861 {(char_u *)"", (char_u *)0L}},
1862 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
1863 (char_u *)&p_rtp, PV_NONE,
1864 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
1865 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
1866 (char_u *)VAR_WIN, PV_SCROLL,
1867 {(char_u *)12L, (char_u *)0L}},
1868 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
1869#ifdef FEAT_SCROLLBIND
1870 (char_u *)VAR_WIN, PV_SCBIND,
1871#else
1872 (char_u *)NULL, PV_NONE,
1873#endif
1874 {(char_u *)FALSE, (char_u *)0L}},
1875 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
1876 (char_u *)&p_sj, PV_NONE,
1877 {(char_u *)1L, (char_u *)0L}},
1878 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
1879 (char_u *)&p_so, PV_NONE,
1880 {(char_u *)0L, (char_u *)0L}},
1881 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1882#ifdef FEAT_SCROLLBIND
1883 (char_u *)&p_sbo, PV_NONE,
1884 {(char_u *)"ver,jump", (char_u *)0L}
1885#else
1886 (char_u *)NULL, PV_NONE,
1887 {(char_u *)0L, (char_u *)0L}
1888#endif
1889 },
1890 {"sections", "sect", P_STRING|P_VI_DEF,
1891 (char_u *)&p_sections, PV_NONE,
1892 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
1893 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
1894 (char_u *)&p_secure, PV_NONE,
1895 {(char_u *)FALSE, (char_u *)0L}},
1896 {"selection", "sel", P_STRING|P_VI_DEF,
1897#ifdef FEAT_VISUAL
1898 (char_u *)&p_sel, PV_NONE,
1899#else
1900 (char_u *)NULL, PV_NONE,
1901#endif
1902 {(char_u *)"inclusive", (char_u *)0L}},
1903 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1904#ifdef FEAT_VISUAL
1905 (char_u *)&p_slm, PV_NONE,
1906#else
1907 (char_u *)NULL, PV_NONE,
1908#endif
1909 {(char_u *)"", (char_u *)0L}},
1910 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1911#ifdef FEAT_SESSION
1912 (char_u *)&p_ssop, PV_NONE,
1913 {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
1914 (char_u *)0L}
1915#else
1916 (char_u *)NULL, PV_NONE,
1917 {(char_u *)0L, (char_u *)0L}
1918#endif
1919 },
1920 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1921 (char_u *)&p_sh, PV_NONE,
1922 {
1923#ifdef VMS
1924 (char_u *)"-",
1925#else
1926# if defined(MSDOS)
1927 (char_u *)"command",
1928# else
1929# if defined(WIN16)
1930 (char_u *)"command.com",
1931# else
1932# if defined(WIN3264)
1933 (char_u *)"", /* set in set_init_1() */
1934# else
1935# if defined(OS2)
1936 (char_u *)"cmd.exe",
1937# else
1938# if defined(ARCHIE)
1939 (char_u *)"gos",
1940# else
1941 (char_u *)"sh",
1942# endif
1943# endif
1944# endif
1945# endif
1946# endif
1947#endif /* VMS */
1948 (char_u *)0L}},
1949 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
1950 (char_u *)&p_shcf, PV_NONE,
1951 {
1952#if defined(MSDOS) || defined(MSWIN)
1953 (char_u *)"/c",
1954#else
1955# if defined(OS2)
1956 (char_u *)"/c",
1957# else
1958 (char_u *)"-c",
1959# endif
1960#endif
1961 (char_u *)0L}},
1962 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
1963#ifdef FEAT_QUICKFIX
1964 (char_u *)&p_sp, PV_NONE,
1965 {
1966#if defined(UNIX) || defined(OS2)
1967# ifdef ARCHIE
1968 (char_u *)"2>",
1969# else
1970 (char_u *)"| tee",
1971# endif
1972#else
1973 (char_u *)">",
1974#endif
1975 (char_u *)0L}
1976#else
1977 (char_u *)NULL, PV_NONE,
1978 {(char_u *)0L, (char_u *)0L}
1979#endif
1980 },
1981 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
1982 (char_u *)&p_shq, PV_NONE,
1983 {(char_u *)"", (char_u *)0L}},
1984 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
1985 (char_u *)&p_srr, PV_NONE,
1986 {(char_u *)">", (char_u *)0L}},
1987 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
1988#ifdef BACKSLASH_IN_FILENAME
1989 (char_u *)&p_ssl, PV_NONE,
1990#else
1991 (char_u *)NULL, PV_NONE,
1992#endif
1993 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001994 {"shelltemp", "stmp", P_BOOL,
1995 (char_u *)&p_stmp, PV_NONE,
1996 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"shelltype", "st", P_NUM|P_VI_DEF,
1998#ifdef AMIGA
1999 (char_u *)&p_st, PV_NONE,
2000#else
2001 (char_u *)NULL, PV_NONE,
2002#endif
2003 {(char_u *)0L, (char_u *)0L}},
2004 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2005 (char_u *)&p_sxq, PV_NONE,
2006 {
2007#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2008 (char_u *)"\"",
2009#else
2010 (char_u *)"",
2011#endif
2012 (char_u *)0L}},
2013 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2014 (char_u *)&p_sr, PV_NONE,
2015 {(char_u *)FALSE, (char_u *)0L}},
2016 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2017 (char_u *)&p_sw, PV_SW,
2018 {(char_u *)8L, (char_u *)0L}},
2019 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2020 (char_u *)&p_shm, PV_NONE,
2021 {(char_u *)"", (char_u *)"filnxtToO"}},
2022 {"shortname", "sn", P_BOOL|P_VI_DEF,
2023#ifdef SHORT_FNAME
2024 (char_u *)NULL, PV_NONE,
2025#else
2026 (char_u *)&p_sn, PV_SN,
2027#endif
2028 {(char_u *)FALSE, (char_u *)0L}},
2029 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2030#ifdef FEAT_LINEBREAK
2031 (char_u *)&p_sbr, PV_NONE,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
2035 {(char_u *)"", (char_u *)0L}},
2036 {"showcmd", "sc", P_BOOL|P_VIM,
2037#ifdef FEAT_CMDL_INFO
2038 (char_u *)&p_sc, PV_NONE,
2039#else
2040 (char_u *)NULL, PV_NONE,
2041#endif
2042 {(char_u *)FALSE,
2043#ifdef UNIX
2044 (char_u *)FALSE
2045#else
2046 (char_u *)TRUE
2047#endif
2048 }},
2049 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2050 (char_u *)&p_sft, PV_NONE,
2051 {(char_u *)FALSE, (char_u *)0L}},
2052 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2053 (char_u *)&p_sm, PV_NONE,
2054 {(char_u *)FALSE, (char_u *)0L}},
2055 {"showmode", "smd", P_BOOL|P_VIM,
2056 (char_u *)&p_smd, PV_NONE,
2057 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002058 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2059#ifdef FEAT_WINDOWS
2060 (char_u *)&p_stal, PV_NONE,
2061#else
2062 (char_u *)NULL, PV_NONE,
2063#endif
2064 {(char_u *)1L, (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2066 (char_u *)&p_ss, PV_NONE,
2067 {(char_u *)0L, (char_u *)0L}},
2068 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2069 (char_u *)&p_siso, PV_NONE,
2070 {(char_u *)0L, (char_u *)0L}},
2071 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2072 (char_u *)NULL, PV_NONE,
2073 {(char_u *)FALSE, (char_u *)0L}},
2074 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2075 (char_u *)&p_scs, PV_NONE,
2076 {(char_u *)FALSE, (char_u *)0L}},
2077 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2078#ifdef FEAT_SMARTINDENT
2079 (char_u *)&p_si, PV_SI,
2080#else
2081 (char_u *)NULL, PV_NONE,
2082#endif
2083 {(char_u *)FALSE, (char_u *)0L}},
2084 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2085 (char_u *)&p_sta, PV_NONE,
2086 {(char_u *)FALSE, (char_u *)0L}},
2087 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2088 (char_u *)&p_sts, PV_STS,
2089 {(char_u *)0L, (char_u *)0L}},
2090 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2091 (char_u *)NULL, PV_NONE,
2092 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002093 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2094#ifdef FEAT_SYN_HL
2095 (char_u *)VAR_WIN, PV_SPELL,
2096#else
2097 (char_u *)NULL, PV_NONE,
2098#endif
2099 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002100 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002101#ifdef FEAT_SYN_HL
2102 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002103 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002104#else
2105 (char_u *)NULL, PV_NONE,
2106 {(char_u *)0L, (char_u *)0L}
2107#endif
2108 },
2109 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002110#ifdef FEAT_SYN_HL
2111 (char_u *)&p_spf, PV_SPF,
2112 {(char_u *)"", (char_u *)0L}
2113#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 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaar217ad922005-03-20 22:37:15 +00002119#ifdef FEAT_SYN_HL
2120 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002121 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002122#else
2123 (char_u *)NULL, PV_NONE,
2124 {(char_u *)0L, (char_u *)0L}
2125#endif
2126 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002127 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002128#ifdef FEAT_SYN_HL
2129 (char_u *)&p_sps, PV_NONE,
2130 {(char_u *)"best", (char_u *)0L}
2131#else
2132 (char_u *)NULL, PV_NONE,
2133 {(char_u *)0L, (char_u *)0L}
2134#endif
2135 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2137#ifdef FEAT_WINDOWS
2138 (char_u *)&p_sb, PV_NONE,
2139#else
2140 (char_u *)NULL, PV_NONE,
2141#endif
2142 {(char_u *)FALSE, (char_u *)0L}},
2143 {"splitright", "spr", P_BOOL|P_VI_DEF,
2144#ifdef FEAT_VERTSPLIT
2145 (char_u *)&p_spr, PV_NONE,
2146#else
2147 (char_u *)NULL, PV_NONE,
2148#endif
2149 {(char_u *)FALSE, (char_u *)0L}},
2150 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2151 (char_u *)&p_sol, PV_NONE,
2152 {(char_u *)TRUE, (char_u *)0L}},
2153 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2154#ifdef FEAT_STL_OPT
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002155 (char_u *)&p_stl, OPT_BOTH(PV_STL),
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
2159 {(char_u *)"", (char_u *)0L}},
2160 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2161 (char_u *)&p_su, PV_NONE,
2162 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2163 (char_u *)0L}},
2164 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
2165#if defined(FEAT_SEARCHPATH)
2166 (char_u *)&p_sua, PV_SUA,
2167 {(char_u *)"", (char_u *)0L}
2168#else
2169 (char_u *)NULL, PV_NONE,
2170 {(char_u *)0L, (char_u *)0L}
2171#endif
2172 },
2173 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2174 (char_u *)&p_swf, PV_SWF,
2175 {(char_u *)TRUE, (char_u *)0L}},
2176 {"swapsync", "sws", P_STRING|P_VI_DEF,
2177 (char_u *)&p_sws, PV_NONE,
2178 {(char_u *)"fsync", (char_u *)0L}},
2179 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2180 (char_u *)&p_swb, PV_NONE,
2181 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002182 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2183#ifdef FEAT_SYN_HL
2184 (char_u *)&p_smc, PV_SMC,
2185 {(char_u *)3000L, (char_u *)0L}
2186#else
2187 (char_u *)NULL, PV_NONE,
2188 {(char_u *)0L, (char_u *)0L}
2189#endif
2190 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002191 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192#ifdef FEAT_SYN_HL
2193 (char_u *)&p_syn, PV_SYN,
2194 {(char_u *)"", (char_u *)0L}
2195#else
2196 (char_u *)NULL, PV_NONE,
2197 {(char_u *)0L, (char_u *)0L}
2198#endif
2199 },
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002200 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2201#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002202 (char_u *)&p_tal, PV_NONE,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002206 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2208 (char_u *)&p_ts, PV_TS,
2209 {(char_u *)8L, (char_u *)0L}},
2210 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2211 (char_u *)&p_tbs, PV_NONE,
2212#ifdef VMS /* binary searching doesn't appear to work on VMS */
2213 {(char_u *)0L, (char_u *)0L}
2214#else
2215 {(char_u *)TRUE, (char_u *)0L}
2216#endif
2217 },
2218 {"taglength", "tl", P_NUM|P_VI_DEF,
2219 (char_u *)&p_tl, PV_NONE,
2220 {(char_u *)0L, (char_u *)0L}},
2221 {"tagrelative", "tr", P_BOOL|P_VIM,
2222 (char_u *)&p_tr, PV_NONE,
2223 {(char_u *)FALSE, (char_u *)TRUE}},
2224 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2225 (char_u *)&p_tags, OPT_BOTH(PV_TAGS),
2226 {
2227#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2228 (char_u *)"./tags,./TAGS,tags,TAGS",
2229#else
2230 (char_u *)"./tags,tags",
2231#endif
2232 (char_u *)0L}},
2233 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2234 (char_u *)&p_tgst, PV_NONE,
2235 {(char_u *)TRUE, (char_u *)0L}},
2236 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2237 (char_u *)&T_NAME, PV_NONE,
2238 {(char_u *)"", (char_u *)0L}},
2239 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2240#ifdef FEAT_ARABIC
2241 (char_u *)&p_tbidi, PV_NONE,
2242#else
2243 (char_u *)NULL, PV_NONE,
2244#endif
2245 {(char_u *)FALSE, (char_u *)0L}},
2246 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2247#ifdef FEAT_MBYTE
2248 (char_u *)&p_tenc, PV_NONE,
2249 {(char_u *)"", (char_u *)0L}
2250#else
2251 (char_u *)NULL, PV_NONE,
2252 {(char_u *)0L, (char_u *)0L}
2253#endif
2254 },
2255 {"terse", NULL, P_BOOL|P_VI_DEF,
2256 (char_u *)&p_terse, PV_NONE,
2257 {(char_u *)FALSE, (char_u *)0L}},
2258 {"textauto", "ta", P_BOOL|P_VIM,
2259 (char_u *)&p_ta, PV_NONE,
2260 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2261 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2262 (char_u *)&p_tx, PV_TX,
2263 {
2264#ifdef USE_CRNL
2265 (char_u *)TRUE,
2266#else
2267 (char_u *)FALSE,
2268#endif
2269 (char_u *)0L}},
2270 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2271 (char_u *)&p_tw, PV_TW,
2272 {(char_u *)0L, (char_u *)0L}},
2273 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2274#ifdef FEAT_INS_EXPAND
2275 (char_u *)&p_tsr, OPT_BOTH(PV_TSR),
2276#else
2277 (char_u *)NULL, PV_NONE,
2278#endif
2279 {(char_u *)"", (char_u *)0L}},
2280 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2281 (char_u *)&p_to, PV_NONE,
2282 {(char_u *)FALSE, (char_u *)0L}},
2283 {"timeout", "to", P_BOOL|P_VI_DEF,
2284 (char_u *)&p_timeout, PV_NONE,
2285 {(char_u *)TRUE, (char_u *)0L}},
2286 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2287 (char_u *)&p_tm, PV_NONE,
2288 {(char_u *)1000L, (char_u *)0L}},
2289 {"title", NULL, P_BOOL|P_VI_DEF,
2290#ifdef FEAT_TITLE
2291 (char_u *)&p_title, PV_NONE,
2292#else
2293 (char_u *)NULL, PV_NONE,
2294#endif
2295 {(char_u *)FALSE, (char_u *)0L}},
2296 {"titlelen", NULL, P_NUM|P_VI_DEF,
2297#ifdef FEAT_TITLE
2298 (char_u *)&p_titlelen, PV_NONE,
2299#else
2300 (char_u *)NULL, PV_NONE,
2301#endif
2302 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002303 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304#ifdef FEAT_TITLE
2305 (char_u *)&p_titleold, PV_NONE,
2306 {(char_u *)N_("Thanks for flying Vim"),
2307 (char_u *)0L}
2308#else
2309 (char_u *)NULL, PV_NONE,
2310 {(char_u *)0L, (char_u *)0L}
2311#endif
2312 },
2313 {"titlestring", NULL, P_STRING|P_VI_DEF,
2314#ifdef FEAT_TITLE
2315 (char_u *)&p_titlestring, PV_NONE,
2316#else
2317 (char_u *)NULL, PV_NONE,
2318#endif
2319 {(char_u *)"", (char_u *)0L}},
2320#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2321 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2322 (char_u *)&p_toolbar, PV_NONE,
2323 {(char_u *)"icons,tooltips", (char_u *)0L}},
2324#endif
2325#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2326 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2327 (char_u *)&p_tbis, PV_NONE,
2328 {(char_u *)"small", (char_u *)0L}},
2329#endif
2330 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2331 (char_u *)&p_ttimeout, PV_NONE,
2332 {(char_u *)FALSE, (char_u *)0L}},
2333 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2334 (char_u *)&p_ttm, PV_NONE,
2335 {(char_u *)-1L, (char_u *)0L}},
2336 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2337 (char_u *)&p_tbi, PV_NONE,
2338 {(char_u *)TRUE, (char_u *)0L}},
2339 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2340 (char_u *)&p_tf, PV_NONE,
2341 {(char_u *)FALSE, (char_u *)0L}},
2342 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2343#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2344 (char_u *)&p_ttym, PV_NONE,
2345#else
2346 (char_u *)NULL, PV_NONE,
2347#endif
2348 {(char_u *)"", (char_u *)0L}},
2349 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2350 (char_u *)&p_ttyscroll, PV_NONE,
2351 {(char_u *)999L, (char_u *)0L}},
2352 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2353 (char_u *)&T_NAME, PV_NONE,
2354 {(char_u *)"", (char_u *)0L}},
2355 {"undolevels", "ul", P_NUM|P_VI_DEF,
2356 (char_u *)&p_ul, PV_NONE,
2357 {
2358#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2359 (char_u *)1000L,
2360#else
2361 (char_u *)100L,
2362#endif
2363 (char_u *)0L}},
2364 {"updatecount", "uc", P_NUM|P_VI_DEF,
2365 (char_u *)&p_uc, PV_NONE,
2366 {(char_u *)200L, (char_u *)0L}},
2367 {"updatetime", "ut", P_NUM|P_VI_DEF,
2368 (char_u *)&p_ut, PV_NONE,
2369 {(char_u *)4000L, (char_u *)0L}},
2370 {"verbose", "vbs", P_NUM|P_VI_DEF,
2371 (char_u *)&p_verbose, PV_NONE,
2372 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002373 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2374 (char_u *)&p_vfile, PV_NONE,
2375 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2377#ifdef FEAT_SESSION
2378 (char_u *)&p_vdir, PV_NONE,
2379 {(char_u *)DFLT_VDIR, (char_u *)0L}
2380#else
2381 (char_u *)NULL, PV_NONE,
2382 {(char_u *)0L, (char_u *)0L}
2383#endif
2384 },
2385 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2386#ifdef FEAT_SESSION
2387 (char_u *)&p_vop, PV_NONE,
2388 {(char_u *)"folds,options,cursor", (char_u *)0L}
2389#else
2390 (char_u *)NULL, PV_NONE,
2391 {(char_u *)0L, (char_u *)0L}
2392#endif
2393 },
2394 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2395#ifdef FEAT_VIMINFO
2396 (char_u *)&p_viminfo, PV_NONE,
2397#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2398 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2399#else
2400# ifdef AMIGA
2401 {(char_u *)"",
2402 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2403# else
2404 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2405# endif
2406#endif
2407#else
2408 (char_u *)NULL, PV_NONE,
2409 {(char_u *)0L, (char_u *)0L}
2410#endif
2411 },
2412 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2413#ifdef FEAT_VIRTUALEDIT
2414 (char_u *)&p_ve, PV_NONE,
2415 {(char_u *)"", (char_u *)""}
2416#else
2417 (char_u *)NULL, PV_NONE,
2418 {(char_u *)0L, (char_u *)0L}
2419#endif
2420 },
2421 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2422 (char_u *)&p_vb, PV_NONE,
2423 {(char_u *)FALSE, (char_u *)0L}},
2424 {"w300", NULL, P_NUM|P_VI_DEF,
2425 (char_u *)NULL, PV_NONE,
2426 {(char_u *)0L, (char_u *)0L}},
2427 {"w1200", NULL, P_NUM|P_VI_DEF,
2428 (char_u *)NULL, PV_NONE,
2429 {(char_u *)0L, (char_u *)0L}},
2430 {"w9600", NULL, P_NUM|P_VI_DEF,
2431 (char_u *)NULL, PV_NONE,
2432 {(char_u *)0L, (char_u *)0L}},
2433 {"warn", NULL, P_BOOL|P_VI_DEF,
2434 (char_u *)&p_warn, PV_NONE,
2435 {(char_u *)TRUE, (char_u *)0L}},
2436 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2437 (char_u *)&p_wiv, PV_NONE,
2438 {(char_u *)FALSE, (char_u *)0L}},
2439 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2440 (char_u *)&p_ww, PV_NONE,
2441 {(char_u *)"", (char_u *)"b,s"}},
2442 {"wildchar", "wc", P_NUM|P_VIM,
2443 (char_u *)&p_wc, PV_NONE,
2444 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2445 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2446 (char_u *)&p_wcm, PV_NONE,
2447 {(char_u *)0L, (char_u *)0L}},
2448 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2449#ifdef FEAT_WILDIGN
2450 (char_u *)&p_wig, PV_NONE,
2451#else
2452 (char_u *)NULL, PV_NONE,
2453#endif
2454 {(char_u *)"", (char_u *)0L}},
2455 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2456#ifdef FEAT_WILDMENU
2457 (char_u *)&p_wmnu, PV_NONE,
2458#else
2459 (char_u *)NULL, PV_NONE,
2460#endif
2461 {(char_u *)FALSE, (char_u *)0L}},
2462 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2463 (char_u *)&p_wim, PV_NONE,
2464 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002465 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2466#ifdef FEAT_CMDL_COMPL
2467 (char_u *)&p_wop, PV_NONE,
2468 {(char_u *)"", (char_u *)0L}
2469#else
2470 (char_u *)NULL, PV_NONE,
2471 {(char_u *)NULL, (char_u *)0L}
2472#endif
2473 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2475#ifdef FEAT_WAK
2476 (char_u *)&p_wak, PV_NONE,
2477 {(char_u *)"menu", (char_u *)0L}
2478#else
2479 (char_u *)NULL, PV_NONE,
2480 {(char_u *)NULL, (char_u *)0L}
2481#endif
2482 },
2483 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002484 (char_u *)&p_window, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 {(char_u *)0L, (char_u *)0L}},
2486 {"winheight", "wh", P_NUM|P_VI_DEF,
2487#ifdef FEAT_WINDOWS
2488 (char_u *)&p_wh, PV_NONE,
2489#else
2490 (char_u *)NULL, PV_NONE,
2491#endif
2492 {(char_u *)1L, (char_u *)0L}},
2493 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
2494#if defined(FEAT_WINDOWS)
2495 (char_u *)VAR_WIN, PV_WFH,
2496#else
2497 (char_u *)NULL, PV_NONE,
2498#endif
2499 {(char_u *)FALSE, (char_u *)0L}},
2500 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2501#ifdef FEAT_WINDOWS
2502 (char_u *)&p_wmh, PV_NONE,
2503#else
2504 (char_u *)NULL, PV_NONE,
2505#endif
2506 {(char_u *)1L, (char_u *)0L}},
2507 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2508#ifdef FEAT_VERTSPLIT
2509 (char_u *)&p_wmw, PV_NONE,
2510#else
2511 (char_u *)NULL, PV_NONE,
2512#endif
2513 {(char_u *)1L, (char_u *)0L}},
2514 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2515#ifdef FEAT_VERTSPLIT
2516 (char_u *)&p_wiw, PV_NONE,
2517#else
2518 (char_u *)NULL, PV_NONE,
2519#endif
2520 {(char_u *)20L, (char_u *)0L}},
2521 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2522 (char_u *)VAR_WIN, PV_WRAP,
2523 {(char_u *)TRUE, (char_u *)0L}},
2524 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2525 (char_u *)&p_wm, PV_WM,
2526 {(char_u *)0L, (char_u *)0L}},
2527 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2528 (char_u *)&p_ws, PV_NONE,
2529 {(char_u *)TRUE, (char_u *)0L}},
2530 {"write", NULL, P_BOOL|P_VI_DEF,
2531 (char_u *)&p_write, PV_NONE,
2532 {(char_u *)TRUE, (char_u *)0L}},
2533 {"writeany", "wa", P_BOOL|P_VI_DEF,
2534 (char_u *)&p_wa, PV_NONE,
2535 {(char_u *)FALSE, (char_u *)0L}},
2536 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2537 (char_u *)&p_wb, PV_NONE,
2538 {
2539#ifdef FEAT_WRITEBACKUP
2540 (char_u *)TRUE,
2541#else
2542 (char_u *)FALSE,
2543#endif
2544 (char_u *)0L}},
2545 {"writedelay", "wd", P_NUM|P_VI_DEF,
2546 (char_u *)&p_wd, PV_NONE,
2547 {(char_u *)0L, (char_u *)0L}},
2548
2549/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002550#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 (char_u *)&vvv, PV_NONE, \
2552 {(char_u *)"", (char_u *)0L}},
2553
2554 p_term("t_AB", T_CAB)
2555 p_term("t_AF", T_CAF)
2556 p_term("t_AL", T_CAL)
2557 p_term("t_al", T_AL)
2558 p_term("t_bc", T_BC)
2559 p_term("t_cd", T_CD)
2560 p_term("t_ce", T_CE)
2561 p_term("t_cl", T_CL)
2562 p_term("t_cm", T_CM)
2563 p_term("t_Co", T_CCO)
2564 p_term("t_CS", T_CCS)
2565 p_term("t_cs", T_CS)
2566#ifdef FEAT_VERTSPLIT
2567 p_term("t_CV", T_CSV)
2568#endif
2569 p_term("t_ut", T_UT)
2570 p_term("t_da", T_DA)
2571 p_term("t_db", T_DB)
2572 p_term("t_DL", T_CDL)
2573 p_term("t_dl", T_DL)
2574 p_term("t_fs", T_FS)
2575 p_term("t_IE", T_CIE)
2576 p_term("t_IS", T_CIS)
2577 p_term("t_ke", T_KE)
2578 p_term("t_ks", T_KS)
2579 p_term("t_le", T_LE)
2580 p_term("t_mb", T_MB)
2581 p_term("t_md", T_MD)
2582 p_term("t_me", T_ME)
2583 p_term("t_mr", T_MR)
2584 p_term("t_ms", T_MS)
2585 p_term("t_nd", T_ND)
2586 p_term("t_op", T_OP)
2587 p_term("t_RI", T_CRI)
2588 p_term("t_RV", T_CRV)
2589 p_term("t_Sb", T_CSB)
2590 p_term("t_Sf", T_CSF)
2591 p_term("t_se", T_SE)
2592 p_term("t_so", T_SO)
2593 p_term("t_sr", T_SR)
2594 p_term("t_ts", T_TS)
2595 p_term("t_te", T_TE)
2596 p_term("t_ti", T_TI)
2597 p_term("t_ue", T_UE)
2598 p_term("t_us", T_US)
2599 p_term("t_vb", T_VB)
2600 p_term("t_ve", T_VE)
2601 p_term("t_vi", T_VI)
2602 p_term("t_vs", T_VS)
2603 p_term("t_WP", T_CWP)
2604 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002605 p_term("t_SI", T_CSI)
2606 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 p_term("t_xs", T_XS)
2608 p_term("t_ZH", T_CZH)
2609 p_term("t_ZR", T_CZR)
2610
2611/* terminal key codes are not in here */
2612
2613 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2614};
2615
2616#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2617
2618#ifdef FEAT_MBYTE
2619static char *(p_ambw_values[]) = {"single", "double", NULL};
2620#endif
2621static char *(p_bg_values[]) = {"light", "dark", NULL};
2622static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2623static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002624#ifdef FEAT_CMDL_COMPL
2625static char *(p_wop_values[]) = {"tagfile", NULL};
2626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627#ifdef FEAT_WAK
2628static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2629#endif
2630static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2631#ifdef FEAT_VISUAL
2632static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2633static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2634#endif
2635#ifdef FEAT_VISUAL
2636static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2637#endif
2638#ifdef FEAT_BROWSE
2639static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2640#endif
2641#ifdef FEAT_SCROLLBIND
2642static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2643#endif
2644static char *(p_swb_values[]) = {"useopen", "split", NULL};
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002645static char *(p_debug_values[]) = {"msg", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646#ifdef FEAT_VERTSPLIT
2647static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2648#endif
2649#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002650# ifdef FEAT_AUTOCMD
2651static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2652# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002654# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2656#endif
2657static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2658#ifdef FEAT_FOLDING
2659static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002660# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002662# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 NULL};
2664static char *(p_fcl_values[]) = {"all", NULL};
2665#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002666#ifdef FEAT_INS_EXPAND
Bram Moolenaarc7453f52006-02-10 23:20:28 +00002667static char *(p_cot_values[]) = {"menu", "longest", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002668#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669
2670static void set_option_default __ARGS((int, int opt_flags, int compatible));
2671static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002672static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002673static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674static char_u *illegal_char __ARGS((char_u *, int));
2675static int string_to_key __ARGS((char_u *arg));
2676#ifdef FEAT_CMDWIN
2677static char_u *check_cedit __ARGS((void));
2678#endif
2679#ifdef FEAT_TITLE
2680static void did_set_title __ARGS((int icon));
2681#endif
2682static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2683static void didset_options __ARGS((void));
2684static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002685#if defined(FEAT_EVAL) || defined(PROTO)
2686static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2687#else
2688# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2691static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2692static 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));
2693static char_u *set_chars_option __ARGS((char_u **varp));
2694#ifdef FEAT_CLIPBOARD
2695static char_u *check_clipboard_option __ARGS((void));
2696#endif
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002697#ifdef FEAT_SYN_HL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002698static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002699#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002701static 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 +00002702static void check_redraw __ARGS((long_u flags));
2703static int findoption __ARGS((char_u *));
2704static int find_key_option __ARGS((char_u *));
2705static void showoptions __ARGS((int all, int opt_flags));
2706static int optval_default __ARGS((struct vimoption *, char_u *varp));
2707static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2708static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2709static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2710static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2711static int istermoption __ARGS((struct vimoption *));
2712static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2713static char_u *get_varp __ARGS((struct vimoption *));
2714static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2715static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2716#ifdef FEAT_LANGMAP
2717static void langmap_init __ARGS((void));
2718static void langmap_set __ARGS((void));
2719#endif
2720static void paste_option_changed __ARGS((void));
2721static void compatible_set __ARGS((void));
2722#ifdef FEAT_LINEBREAK
2723static void fill_breakat_flags __ARGS((void));
2724#endif
2725static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2726static int check_opt_strings __ARGS((char_u *val, char **values, int));
2727static int check_opt_wim __ARGS((void));
2728
2729/*
2730 * Initialize the options, first part.
2731 *
2732 * Called only once from main(), just after creating the first buffer.
2733 */
2734 void
2735set_init_1()
2736{
2737 char_u *p;
2738 int opt_idx;
2739 long n;
2740
2741#ifdef FEAT_LANGMAP
2742 langmap_init();
2743#endif
2744
2745 /* Be Vi compatible by default */
2746 p_cp = TRUE;
2747
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002748 /* Use POSIX compatibility when $VIM_POSIX is set. */
2749 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002750 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002751 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002752 set_string_default("shm", (char_u *)"A");
2753 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002754
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 /*
2756 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002757 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002759 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2761# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002762 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002764 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002766 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767# endif
2768#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002769 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 set_string_default("sh", p);
2771
2772#ifdef FEAT_WILDIGN
2773 /*
2774 * Set the default for 'backupskip' to include environment variables for
2775 * temp files.
2776 */
2777 {
2778# ifdef UNIX
2779 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2780# else
2781 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2782# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002783 int len;
2784 garray_T ga;
2785 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786
2787 ga_init2(&ga, 1, 100);
2788 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2789 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002790 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791# ifdef UNIX
2792 if (*names[n] == NUL)
2793 p = (char_u *)"/tmp";
2794 else
2795# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002796 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 if (p != NULL && *p != NUL)
2798 {
2799 /* First time count the NUL, otherwise count the ','. */
2800 len = STRLEN(p) + 3;
2801 if (ga_grow(&ga, len) == OK)
2802 {
2803 if (ga.ga_len > 0)
2804 STRCAT(ga.ga_data, ",");
2805 STRCAT(ga.ga_data, p);
2806 add_pathsep(ga.ga_data);
2807 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 ga.ga_len += len;
2809 }
2810 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002811 if (mustfree)
2812 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 }
2814 if (ga.ga_data != NULL)
2815 {
2816 set_string_default("bsk", ga.ga_data);
2817 vim_free(ga.ga_data);
2818 }
2819 }
2820#endif
2821
2822 /*
2823 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2824 */
2825 opt_idx = findoption((char_u *)"maxmemtot");
2826#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2827 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2828#endif
2829 {
2830#ifdef HAVE_AVAIL_MEM
2831 /* Use amount of memory available at this moment. */
2832 n = (mch_avail_mem(FALSE) >> 11);
2833#else
2834# ifdef HAVE_TOTAL_MEM
2835 /* Use amount of memory available to Vim. */
2836 n = (mch_total_mem(FALSE) >> 11);
2837# else
2838 n = (0x7fffffff >> 11);
2839# endif
2840#endif
2841 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2842 opt_idx = findoption((char_u *)"maxmem");
2843#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2844 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2845 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2846#endif
2847 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2848 }
2849
2850#ifdef FEAT_GUI_W32
2851 /* force 'shortname' for Win32s */
2852 if (gui_is_win32s())
2853 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2854 (char_u *)TRUE;
2855#endif
2856
2857#ifdef FEAT_SEARCHPATH
2858 {
2859 char_u *cdpath;
2860 char_u *buf;
2861 int i;
2862 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002863 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864
2865 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00002866 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 if (cdpath != NULL)
2868 {
2869 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2870 if (buf != NULL)
2871 {
2872 buf[0] = ','; /* start with ",", current dir first */
2873 j = 1;
2874 for (i = 0; cdpath[i] != NUL; ++i)
2875 {
2876 if (vim_ispathlistsep(cdpath[i]))
2877 buf[j++] = ',';
2878 else
2879 {
2880 if (cdpath[i] == ' ' || cdpath[i] == ',')
2881 buf[j++] = '\\';
2882 buf[j++] = cdpath[i];
2883 }
2884 }
2885 buf[j] = NUL;
2886 opt_idx = findoption((char_u *)"cdpath");
2887 options[opt_idx].def_val[VI_DEFAULT] = buf;
2888 options[opt_idx].flags |= P_DEF_ALLOCED;
2889 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002890 if (mustfree)
2891 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 }
2893 }
2894#endif
2895
2896#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2897 /* Set print encoding on platforms that don't default to latin1 */
2898 set_string_default("penc",
2899# if defined(MSWIN) || defined(OS2)
2900 (char_u *)"cp1252"
2901# else
2902# ifdef VMS
2903 (char_u *)"dec-mcs"
2904# else
2905# ifdef EBCDIC
2906 (char_u *)"ebcdic-uk"
2907# else
2908# ifdef MAC
2909 (char_u *)"mac-roman"
2910# else /* HPUX */
2911 (char_u *)"hp-roman8"
2912# endif
2913# endif
2914# endif
2915# endif
2916 );
2917#endif
2918
2919#ifdef FEAT_POSTSCRIPT
2920 /* 'printexpr' must be allocated to be able to evaluate it. */
2921 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00002922# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
2923 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924# else
2925# ifdef VMS
2926 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
2927
2928# else
2929 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
2930# endif
2931# endif
2932 );
2933#endif
2934
2935 /*
2936 * Set all the options (except the terminal options) to their default
2937 * value. Also set the global value for local options.
2938 */
2939 set_options_default(0);
2940
2941#ifdef FEAT_GUI
2942 if (found_reverse_arg)
2943 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
2944#endif
2945
2946 curbuf->b_p_initialized = TRUE;
2947 curbuf->b_p_ar = -1; /* no local 'autoread' value */
2948 check_buf_options(curbuf);
2949 check_win_options(curwin);
2950 check_options();
2951
2952 /* Must be before option_expand(), because that one needs vim_isIDc() */
2953 didset_options();
2954
Bram Moolenaar6bb68362005-03-22 23:03:44 +00002955#ifdef FEAT_SYN_HL
2956 /* Use the current chartab for the generic chartab. */
2957 init_spell_chartab();
2958#endif
2959
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960#ifdef FEAT_LINEBREAK
2961 /*
2962 * initialize the table for 'breakat'.
2963 */
2964 fill_breakat_flags();
2965#endif
2966
2967 /*
2968 * Expand environment variables and things like "~" for the defaults.
2969 * If option_expand() returns non-NULL the variable is expanded. This can
2970 * only happen for non-indirect options.
2971 * Also set the default to the expanded value, so ":set" does not list
2972 * them.
2973 * Don't set the P_ALLOCED flag, because we don't want to free the
2974 * default.
2975 */
2976 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
2977 {
2978 if ((options[opt_idx].flags & P_GETTEXT)
2979 && options[opt_idx].var != NULL)
2980 p = (char_u *)_(*(char **)options[opt_idx].var);
2981 else
2982 p = option_expand(opt_idx, NULL);
2983 if (p != NULL && (p = vim_strsave(p)) != NULL)
2984 {
2985 *(char_u **)options[opt_idx].var = p;
2986 /* VIMEXP
2987 * Defaults for all expanded options are currently the same for Vi
2988 * and Vim. When this changes, add some code here! Also need to
2989 * split P_DEF_ALLOCED in two.
2990 */
2991 if (options[opt_idx].flags & P_DEF_ALLOCED)
2992 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2993 options[opt_idx].def_val[VI_DEFAULT] = p;
2994 options[opt_idx].flags |= P_DEF_ALLOCED;
2995 }
2996 }
2997
2998 /* Initialize the highlight_attr[] table. */
2999 highlight_changed();
3000
3001 save_file_ff(curbuf); /* Buffer is unchanged */
3002
3003 /* Parse default for 'wildmode' */
3004 check_opt_wim();
3005
3006#if defined(FEAT_ARABIC)
3007 /* Detect use of mlterm.
3008 * Mlterm is a terminal emulator akin to xterm that has some special
3009 * abilities (bidi namely).
3010 * NOTE: mlterm's author is being asked to 'set' a variable
3011 * instead of an environment variable due to inheritance.
3012 */
3013 if (mch_getenv((char_u *)"MLTERM") != NULL)
3014 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3015#endif
3016
3017#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3018 /* Parse default for 'fillchars'. */
3019 (void)set_chars_option(&p_fcs);
3020#endif
3021
3022#ifdef FEAT_CLIPBOARD
3023 /* Parse default for 'clipboard' */
3024 (void)check_clipboard_option();
3025#endif
3026
3027#ifdef FEAT_MBYTE
3028# if defined(WIN3264) && defined(FEAT_GETTEXT)
3029 /*
3030 * If $LANG isn't set, try to get a good value for it. This makes the
3031 * right language be used automatically. Don't do this for English.
3032 */
3033 if (mch_getenv((char_u *)"LANG") == NULL)
3034 {
3035 char buf[20];
3036
3037 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3038 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3039 * only the first two. */
3040 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3041 (LPTSTR)buf, 20);
3042 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3043 {
3044 /* There are a few exceptions (probably more) */
3045 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3046 STRCPY(buf, "zh_TW");
3047 else if (STRNICMP(buf, "chs", 3) == 0
3048 || STRNICMP(buf, "zhc", 3) == 0)
3049 STRCPY(buf, "zh_CN");
3050 else if (STRNICMP(buf, "jp", 2) == 0)
3051 STRCPY(buf, "ja");
3052 else
3053 buf[2] = NUL; /* truncate to two-letter code */
3054 vim_setenv("LANG", buf);
3055 }
3056 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003057# else
3058# ifdef MACOS
3059 if (mch_getenv((char_u *)"LANG") == NULL)
3060 {
3061 char buf[20];
3062 if (LocaleRefGetPartString(NULL,
3063 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3064 kLocaleRegionMask | kLocaleRegionVariantMask,
3065 sizeof buf, buf) == noErr && *buf)
3066 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003067 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003068# ifdef HAVE_LOCALE_H
3069 setlocale(LC_ALL, "");
3070# endif
3071 }
3072 }
3073# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074# endif
3075
3076 /* enc_locale() will try to find the encoding of the current locale. */
3077 p = enc_locale();
3078 if (p != NULL)
3079 {
3080 char_u *save_enc;
3081
3082 /* Try setting 'encoding' and check if the value is valid.
3083 * If not, go back to the default "latin1". */
3084 save_enc = p_enc;
3085 p_enc = p;
3086 if (mb_init() == NULL)
3087 {
3088 opt_idx = findoption((char_u *)"encoding");
3089 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3090 options[opt_idx].flags |= P_DEF_ALLOCED;
3091
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003092#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3093 || defined(VMS)
3094 if (STRCMP(p_enc, "latin1") == 0
3095# ifdef FEAT_MBYTE
3096 || enc_utf8
3097# endif
3098 )
3099 {
3100 /* Adjust the default for 'isprint' to match latin1. */
3101 set_string_option_direct((char_u *)"isp", -1,
3102 (char_u *)"@,161-255", OPT_FREE);
3103 (void)init_chartab();
3104 }
3105#endif
3106
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107# if defined(WIN3264) && !defined(FEAT_GUI)
3108 /* Win32 console: When GetACP() returns a different value from
3109 * GetConsoleCP() set 'termencoding'. */
3110 if (GetACP() != GetConsoleCP())
3111 {
3112 char buf[50];
3113
3114 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3115 p_tenc = vim_strsave((char_u *)buf);
3116 if (p_tenc != NULL)
3117 {
3118 opt_idx = findoption((char_u *)"termencoding");
3119 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3120 options[opt_idx].flags |= P_DEF_ALLOCED;
3121 convert_setup(&input_conv, p_tenc, p_enc);
3122 convert_setup(&output_conv, p_enc, p_tenc);
3123 }
3124 else
3125 p_tenc = empty_option;
3126 }
3127# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003128# if defined(WIN3264) && defined(FEAT_MBYTE)
3129 /* $HOME may have characters in active code page. */
3130 init_homedir();
3131# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 }
3133 else
3134 {
3135 vim_free(p_enc);
3136 p_enc = save_enc;
3137 }
3138 }
3139#endif
3140
3141#ifdef FEAT_MULTI_LANG
3142 /* Set the default for 'helplang'. */
3143 set_helplang_default(get_mess_lang());
3144#endif
3145}
3146
3147/*
3148 * Set an option to its default value.
3149 * This does not take care of side effects!
3150 */
3151 static void
3152set_option_default(opt_idx, opt_flags, compatible)
3153 int opt_idx;
3154 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3155 int compatible; /* use Vi default value */
3156{
3157 char_u *varp; /* pointer to variable for current option */
3158 int dvi; /* index in def_val[] */
3159 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003160 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3162
3163 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3164 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003165 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 {
3167 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3168 if (flags & P_STRING)
3169 {
3170 /* Use set_string_option_direct() for local options to handle
3171 * freeing and allocating the value. */
3172 if (options[opt_idx].indir != PV_NONE)
3173 set_string_option_direct(NULL, opt_idx,
3174 options[opt_idx].def_val[dvi], opt_flags);
3175 else
3176 {
3177 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3178 free_string_option(*(char_u **)(varp));
3179 *(char_u **)varp = options[opt_idx].def_val[dvi];
3180 options[opt_idx].flags &= ~P_ALLOCED;
3181 }
3182 }
3183 else if (flags & P_NUM)
3184 {
3185 if (varp == (char_u *)PV_SCROLL)
3186 win_comp_scroll(curwin);
3187 else
3188 {
3189 *(long *)varp = (long)options[opt_idx].def_val[dvi];
3190 /* May also set global value for local option. */
3191 if (both)
3192 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3193 *(long *)varp;
3194 }
3195 }
3196 else /* P_BOOL */
3197 {
3198 /* the cast to long is required for Manx C */
3199 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3200 /* May also set global value for local option. */
3201 if (both)
3202 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3203 *(int *)varp;
3204 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003205
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003206 /* The default value is not insecure. */
3207 flagsp = insecure_flag(opt_idx, opt_flags);
3208 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209 }
3210
3211#ifdef FEAT_EVAL
3212 /* Remember where the option was set. */
3213 options[opt_idx].scriptID = current_SID;
3214#endif
3215}
3216
3217/*
3218 * Set all options (except terminal options) to their default value.
3219 */
3220 static void
3221set_options_default(opt_flags)
3222 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3223{
3224 int i;
3225#ifdef FEAT_WINDOWS
3226 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003227 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228#endif
3229
3230 for (i = 0; !istermoption(&options[i]); i++)
3231 if (!(options[i].flags & P_NODEFAULT))
3232 set_option_default(i, opt_flags, p_cp);
3233
3234#ifdef FEAT_WINDOWS
3235 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003236 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237 win_comp_scroll(wp);
3238#else
3239 win_comp_scroll(curwin);
3240#endif
3241}
3242
3243/*
3244 * Set the Vi-default value of a string option.
3245 * Used for 'sh', 'backupskip' and 'term'.
3246 */
3247 void
3248set_string_default(name, val)
3249 char *name;
3250 char_u *val;
3251{
3252 char_u *p;
3253 int opt_idx;
3254
3255 p = vim_strsave(val);
3256 if (p != NULL) /* we don't want a NULL */
3257 {
3258 opt_idx = findoption((char_u *)name);
3259 if (options[opt_idx].flags & P_DEF_ALLOCED)
3260 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3261 options[opt_idx].def_val[VI_DEFAULT] = p;
3262 options[opt_idx].flags |= P_DEF_ALLOCED;
3263 }
3264}
3265
3266/*
3267 * Set the Vi-default value of a number option.
3268 * Used for 'lines' and 'columns'.
3269 */
3270 void
3271set_number_default(name, val)
3272 char *name;
3273 long val;
3274{
3275 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3276}
3277
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003278#if defined(EXITFREE) || defined(PROTO)
3279/*
3280 * Free all options.
3281 */
3282 void
3283free_all_options()
3284{
3285 int i;
3286
3287 for (i = 0; !istermoption(&options[i]); i++)
3288 {
3289 if (options[i].indir == PV_NONE)
3290 {
3291 /* global option: free value and default value. */
3292 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3293 free_string_option(*(char_u **)options[i].var);
3294 if (options[i].flags & P_DEF_ALLOCED)
3295 free_string_option(options[i].def_val[VI_DEFAULT]);
3296 }
3297 else if (options[i].var != VAR_WIN
3298 && (options[i].flags & P_STRING))
3299 /* buffer-local option: free global value */
3300 free_string_option(*(char_u **)options[i].var);
3301 }
3302}
3303#endif
3304
3305
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306/*
3307 * Initialize the options, part two: After getting Rows and Columns and
3308 * setting 'term'.
3309 */
3310 void
3311set_init_2()
3312{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003313 int idx;
3314
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315 /*
3316 * 'scroll' defaults to half the window height. Note that this default is
3317 * wrong when the window height changes.
3318 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003319 set_number_default("scroll", (long_u)Rows >> 1);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003320 idx = findoption((char_u *)"scroll");
3321 if (!(options[idx].flags & P_WAS_SET))
3322 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323 comp_col();
3324
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003325 /*
3326 * 'window' is only for backwards compatibility with Vi.
3327 * Default is Rows - 1.
3328 */
3329 idx = findoption((char_u *)"wi");
3330 if (!(options[idx].flags & P_WAS_SET))
3331 p_window = Rows - 1;
3332 set_number_default("window", Rows - 1);
3333
Bram Moolenaarf740b292006-02-16 22:11:02 +00003334 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003336 /*
3337 * If 'background' wasn't set by the user, try guessing the value,
3338 * depending on the terminal name. Only need to check for terminals
3339 * with a dark background, that can handle color.
3340 */
3341 idx = findoption((char_u *)"bg");
3342 if (!(options[idx].flags & P_WAS_SET) && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343 {
Bram Moolenaarf740b292006-02-16 22:11:02 +00003344 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE);
3345 /* don't mark it as set, when starting the GUI it may be
3346 * changed again */
3347 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 }
3349#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003350
3351#ifdef CURSOR_SHAPE
3352 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3353#endif
3354#ifdef FEAT_MOUSESHAPE
3355 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3356#endif
3357#ifdef FEAT_PRINTER
3358 (void)parse_printoptions(); /* parse 'printoptions' default value */
3359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360}
3361
3362/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003363 * Return "dark" or "light" depending on the kind of terminal.
3364 * This is just guessing! Recognized are:
3365 * "linux" Linux console
3366 * "screen.linux" Linux console with screen
3367 * "cygwin" Cygwin shell
3368 * "putty" Putty program
3369 * We also check the COLORFGBG environment variable, which is set by
3370 * rxvt and derivatives. This variable contains either two or three
3371 * values separated by semicolons; we want the last value in either
3372 * case. If this value is 0-6 or 8, our background is dark.
3373 */
3374 static char_u *
3375term_bg_default()
3376{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003377#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3378 /* DOS console nearly always black */
3379 return (char_u *)"dark";
3380#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003381 char_u *p;
3382
Bram Moolenaarf740b292006-02-16 22:11:02 +00003383 if (STRCMP(T_NAME, "linux") == 0
3384 || STRCMP(T_NAME, "screen.linux") == 0
3385 || STRCMP(T_NAME, "cygwin") == 0
3386 || STRCMP(T_NAME, "putty") == 0
3387 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3388 && (p = vim_strrchr(p, ';')) != NULL
3389 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3390 && p[2] == NUL))
3391 return (char_u *)"dark";
3392 return (char_u *)"light";
3393#endif
3394}
3395
3396/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 * Initialize the options, part three: After reading the .vimrc
3398 */
3399 void
3400set_init_3()
3401{
3402#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3403/*
3404 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3405 * This is done after other initializations, where 'shell' might have been
3406 * set, but only if they have not been set before.
3407 */
3408 char_u *p;
3409 int idx_srr;
3410 int do_srr;
3411#ifdef FEAT_QUICKFIX
3412 int idx_sp;
3413 int do_sp;
3414#endif
3415
3416 idx_srr = findoption((char_u *)"srr");
3417 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3418#ifdef FEAT_QUICKFIX
3419 idx_sp = findoption((char_u *)"sp");
3420 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3421#endif
3422
3423 /*
3424 * Isolate the name of the shell:
3425 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3426 * - Remove any argument. E.g., "csh -f" -> "csh".
3427 */
3428 p = gettail(p_sh);
3429 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3430 if (p != NULL)
3431 {
3432 /*
3433 * Default for p_sp is "| tee", for p_srr is ">".
3434 * For known shells it is changed here to include stderr.
3435 */
3436 if ( fnamecmp(p, "csh") == 0
3437 || fnamecmp(p, "tcsh") == 0
3438# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3439 || fnamecmp(p, "csh.exe") == 0
3440 || fnamecmp(p, "tcsh.exe") == 0
3441# endif
3442 )
3443 {
3444#if defined(FEAT_QUICKFIX)
3445 if (do_sp)
3446 {
3447# ifdef WIN3264
3448 p_sp = (char_u *)">&";
3449# else
3450 p_sp = (char_u *)"|& tee";
3451# endif
3452 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3453 }
3454#endif
3455 if (do_srr)
3456 {
3457 p_srr = (char_u *)">&";
3458 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3459 }
3460 }
3461 else
3462# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3463 if ( fnamecmp(p, "sh") == 0
3464 || fnamecmp(p, "ksh") == 0
3465 || fnamecmp(p, "zsh") == 0
3466 || fnamecmp(p, "bash") == 0
3467# ifdef WIN3264
3468 || fnamecmp(p, "cmd") == 0
3469 || fnamecmp(p, "sh.exe") == 0
3470 || fnamecmp(p, "ksh.exe") == 0
3471 || fnamecmp(p, "zsh.exe") == 0
3472 || fnamecmp(p, "bash.exe") == 0
3473 || fnamecmp(p, "cmd.exe") == 0
3474# endif
3475 )
3476# endif
3477 {
3478#if defined(FEAT_QUICKFIX)
3479 if (do_sp)
3480 {
3481# ifdef WIN3264
3482 p_sp = (char_u *)">%s 2>&1";
3483# else
3484 p_sp = (char_u *)"2>&1| tee";
3485# endif
3486 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3487 }
3488#endif
3489 if (do_srr)
3490 {
3491 p_srr = (char_u *)">%s 2>&1";
3492 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3493 }
3494 }
3495 vim_free(p);
3496 }
3497#endif
3498
3499#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3500 /*
3501 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3502 * This is done after other initializations, where 'shell' might have been
3503 * set, but only if they have not been set before. Default for p_shcf is
3504 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3505 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3506 * command.com. And for Win32 we need to set p_sxq instead.
3507 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003508 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003509 {
3510 int idx3;
3511
3512 idx3 = findoption((char_u *)"shcf");
3513 if (!(options[idx3].flags & P_WAS_SET))
3514 {
3515 p_shcf = (char_u *)"-c";
3516 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3517 }
3518
3519# ifndef DJGPP
3520# ifdef WIN3264
3521 /* Somehow Win32 requires the quotes around the redirection too */
3522 idx3 = findoption((char_u *)"sxq");
3523 if (!(options[idx3].flags & P_WAS_SET))
3524 {
3525 p_sxq = (char_u *)"\"";
3526 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3527 }
3528# else
3529 idx3 = findoption((char_u *)"shq");
3530 if (!(options[idx3].flags & P_WAS_SET))
3531 {
3532 p_shq = (char_u *)"\"";
3533 options[idx3].def_val[VI_DEFAULT] = p_shq;
3534 }
3535# endif
3536# endif
3537 }
3538#endif
3539
3540#ifdef FEAT_TITLE
3541 set_title_defaults();
3542#endif
3543}
3544
3545#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3546/*
3547 * When 'helplang' is still at its default value, set it to "lang".
3548 * Only the first two characters of "lang" are used.
3549 */
3550 void
3551set_helplang_default(lang)
3552 char_u *lang;
3553{
3554 int idx;
3555
3556 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3557 return;
3558 idx = findoption((char_u *)"hlg");
3559 if (!(options[idx].flags & P_WAS_SET))
3560 {
3561 if (options[idx].flags & P_ALLOCED)
3562 free_string_option(p_hlg);
3563 p_hlg = vim_strsave(lang);
3564 if (p_hlg == NULL)
3565 p_hlg = empty_option;
3566 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003567 {
3568 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3569 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3570 {
3571 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3572 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3573 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576 options[idx].flags |= P_ALLOCED;
3577 }
3578}
3579#endif
3580
3581#ifdef FEAT_GUI
3582static char_u *gui_bg_default __ARGS((void));
3583
3584 static char_u *
3585gui_bg_default()
3586{
3587 if (gui_get_lightness(gui.back_pixel) < 127)
3588 return (char_u *)"dark";
3589 return (char_u *)"light";
3590}
3591
3592/*
3593 * Option initializations that can only be done after opening the GUI window.
3594 */
3595 void
3596init_gui_options()
3597{
3598 /* Set the 'background' option according to the lightness of the
3599 * background color, unless the user has set it already. */
3600 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3601 {
3602 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3603 highlight_changed();
3604 }
3605}
3606#endif
3607
3608#ifdef FEAT_TITLE
3609/*
3610 * 'title' and 'icon' only default to true if they have not been set or reset
3611 * in .vimrc and we can read the old value.
3612 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3613 * they can be reset. This reduces startup time when using X on a remote
3614 * machine.
3615 */
3616 void
3617set_title_defaults()
3618{
3619 int idx1;
3620 long val;
3621
3622 /*
3623 * If GUI is (going to be) used, we can always set the window title and
3624 * icon name. Saves a bit of time, because the X11 display server does
3625 * not need to be contacted.
3626 */
3627 idx1 = findoption((char_u *)"title");
3628 if (!(options[idx1].flags & P_WAS_SET))
3629 {
3630#ifdef FEAT_GUI
3631 if (gui.starting || gui.in_use)
3632 val = TRUE;
3633 else
3634#endif
3635 val = mch_can_restore_title();
3636 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3637 p_title = val;
3638 }
3639 idx1 = findoption((char_u *)"icon");
3640 if (!(options[idx1].flags & P_WAS_SET))
3641 {
3642#ifdef FEAT_GUI
3643 if (gui.starting || gui.in_use)
3644 val = TRUE;
3645 else
3646#endif
3647 val = mch_can_restore_icon();
3648 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3649 p_icon = val;
3650 }
3651}
3652#endif
3653
3654/*
3655 * Parse 'arg' for option settings.
3656 *
3657 * 'arg' may be IObuff, but only when no errors can be present and option
3658 * does not need to be expanded with option_expand().
3659 * "opt_flags":
3660 * 0 for ":set"
3661 * OPT_GLOBAL for ":setglobal"
3662 * OPT_LOCAL for ":setlocal" and a modeline
3663 * OPT_MODELINE for a modeline
3664 *
3665 * returns FAIL if an error is detected, OK otherwise
3666 */
3667 int
3668do_set(arg, opt_flags)
3669 char_u *arg; /* option string (may be written to!) */
3670 int opt_flags;
3671{
3672 int opt_idx;
3673 char_u *errmsg;
3674 char_u errbuf[80];
3675 char_u *startarg;
3676 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3677 int nextchar; /* next non-white char after option name */
3678 int afterchar; /* character just after option name */
3679 int len;
3680 int i;
3681 long value;
3682 int key;
3683 long_u flags; /* flags for current option */
3684 char_u *varp = NULL; /* pointer to variable for current option */
3685 int did_show = FALSE; /* already showed one value */
3686 int adding; /* "opt+=arg" */
3687 int prepending; /* "opt^=arg" */
3688 int removing; /* "opt-=arg" */
3689 int cp_val = 0;
3690 char_u key_name[2];
3691
3692 if (*arg == NUL)
3693 {
3694 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003695 did_show = TRUE;
3696 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003697 }
3698
3699 while (*arg != NUL) /* loop to process all options */
3700 {
3701 errmsg = NULL;
3702 startarg = arg; /* remember for error message */
3703
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003704 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3705 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 {
3707 /*
3708 * ":set all" show all options.
3709 * ":set all&" set all options to their default value.
3710 */
3711 arg += 3;
3712 if (*arg == '&')
3713 {
3714 ++arg;
3715 /* Only for :set command set global value of local options. */
3716 set_options_default(OPT_FREE | opt_flags);
3717 }
3718 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003719 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003721 did_show = TRUE;
3722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003724 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725 {
3726 showoptions(2, opt_flags);
3727 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003728 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729 arg += 7;
3730 }
3731 else
3732 {
3733 prefix = 1;
3734 if (STRNCMP(arg, "no", 2) == 0)
3735 {
3736 prefix = 0;
3737 arg += 2;
3738 }
3739 else if (STRNCMP(arg, "inv", 3) == 0)
3740 {
3741 prefix = 2;
3742 arg += 3;
3743 }
3744
3745 /* find end of name */
3746 key = 0;
3747 if (*arg == '<')
3748 {
3749 nextchar = 0;
3750 opt_idx = -1;
3751 /* look out for <t_>;> */
3752 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3753 len = 5;
3754 else
3755 {
3756 len = 1;
3757 while (arg[len] != NUL && arg[len] != '>')
3758 ++len;
3759 }
3760 if (arg[len] != '>')
3761 {
3762 errmsg = e_invarg;
3763 goto skip;
3764 }
3765 arg[len] = NUL; /* put NUL after name */
3766 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3767 opt_idx = findoption(arg + 1);
3768 arg[len++] = '>'; /* restore '>' */
3769 if (opt_idx == -1)
3770 key = find_key_option(arg + 1);
3771 }
3772 else
3773 {
3774 len = 0;
3775 /*
3776 * The two characters after "t_" may not be alphanumeric.
3777 */
3778 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3779 len = 4;
3780 else
3781 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3782 ++len;
3783 nextchar = arg[len];
3784 arg[len] = NUL; /* put NUL after name */
3785 opt_idx = findoption(arg);
3786 arg[len] = nextchar; /* restore nextchar */
3787 if (opt_idx == -1)
3788 key = find_key_option(arg);
3789 }
3790
3791 /* remember character after option name */
3792 afterchar = arg[len];
3793
3794 /* skip white space, allow ":set ai ?" */
3795 while (vim_iswhite(arg[len]))
3796 ++len;
3797
3798 adding = FALSE;
3799 prepending = FALSE;
3800 removing = FALSE;
3801 if (arg[len] != NUL && arg[len + 1] == '=')
3802 {
3803 if (arg[len] == '+')
3804 {
3805 adding = TRUE; /* "+=" */
3806 ++len;
3807 }
3808 else if (arg[len] == '^')
3809 {
3810 prepending = TRUE; /* "^=" */
3811 ++len;
3812 }
3813 else if (arg[len] == '-')
3814 {
3815 removing = TRUE; /* "-=" */
3816 ++len;
3817 }
3818 }
3819 nextchar = arg[len];
3820
3821 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3822 {
3823 errmsg = (char_u *)N_("E518: Unknown option");
3824 goto skip;
3825 }
3826
3827 if (opt_idx >= 0)
3828 {
3829 if (options[opt_idx].var == NULL) /* hidden option: skip */
3830 {
3831 /* Only give an error message when requesting the value of
3832 * a hidden option, ignore setting it. */
3833 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3834 && (!(options[opt_idx].flags & P_BOOL)
3835 || nextchar == '?'))
3836 errmsg = (char_u *)N_("E519: Option not supported");
3837 goto skip;
3838 }
3839
3840 flags = options[opt_idx].flags;
3841 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3842 }
3843 else
3844 {
3845 flags = P_STRING;
3846 if (key < 0)
3847 {
3848 key_name[0] = KEY2TERMCAP0(key);
3849 key_name[1] = KEY2TERMCAP1(key);
3850 }
3851 else
3852 {
3853 key_name[0] = KS_KEY;
3854 key_name[1] = (key & 0xff);
3855 }
3856 }
3857
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003858 /* Skip all options that are not window-local (used when showing
3859 * an already loaded buffer in a window). */
3860 if ((opt_flags & OPT_WINONLY)
3861 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
3862 goto skip;
3863
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 /* Disallow changing some options from modelines */
3865 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3866 {
3867 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3868 goto skip;
3869 }
3870
3871#ifdef HAVE_SANDBOX
3872 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003873 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874 {
3875 errmsg = (char_u *)_(e_sandbox);
3876 goto skip;
3877 }
3878#endif
3879
3880 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3881 {
3882 arg += len;
3883 cp_val = p_cp;
3884 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3885 {
3886 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3887 {
3888 cp_val = FALSE;
3889 arg += 3;
3890 }
3891 else /* "opt&vi": set to Vi default */
3892 {
3893 cp_val = TRUE;
3894 arg += 2;
3895 }
3896 }
3897 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3898 && arg[1] != NUL && !vim_iswhite(arg[1]))
3899 {
3900 errmsg = e_trailing;
3901 goto skip;
3902 }
3903 }
3904
3905 /*
3906 * allow '=' and ':' as MSDOS command.com allows only one
3907 * '=' character per "set" command line. grrr. (jw)
3908 */
3909 if (nextchar == '?'
3910 || (prefix == 1
3911 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
3912 && !(flags & P_BOOL)))
3913 {
3914 /*
3915 * print value
3916 */
3917 if (did_show)
3918 msg_putchar('\n'); /* cursor below last one */
3919 else
3920 {
3921 gotocmdline(TRUE); /* cursor at status line */
3922 did_show = TRUE; /* remember that we did a line */
3923 }
3924 if (opt_idx >= 0)
3925 {
3926 showoneopt(&options[opt_idx], opt_flags);
3927#ifdef FEAT_EVAL
3928 if (p_verbose > 0)
Bram Moolenaar661b1822005-07-28 22:36:45 +00003929 last_set_msg(options[opt_idx].scriptID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930#endif
3931 }
3932 else
3933 {
3934 char_u *p;
3935
3936 p = find_termcode(key_name);
3937 if (p == NULL)
3938 {
3939 errmsg = (char_u *)N_("E518: Unknown option");
3940 goto skip;
3941 }
3942 else
3943 (void)show_one_termcode(key_name, p, TRUE);
3944 }
3945 if (nextchar != '?'
3946 && nextchar != NUL && !vim_iswhite(afterchar))
3947 errmsg = e_trailing;
3948 }
3949 else
3950 {
3951 if (flags & P_BOOL) /* boolean */
3952 {
3953 if (nextchar == '=' || nextchar == ':')
3954 {
3955 errmsg = e_invarg;
3956 goto skip;
3957 }
3958
3959 /*
3960 * ":set opt!": invert
3961 * ":set opt&": reset to default value
3962 * ":set opt<": reset to global value
3963 */
3964 if (nextchar == '!')
3965 value = *(int *)(varp) ^ 1;
3966 else if (nextchar == '&')
3967 value = (int)(long)options[opt_idx].def_val[
3968 ((flags & P_VI_DEF) || cp_val)
3969 ? VI_DEFAULT : VIM_DEFAULT];
3970 else if (nextchar == '<')
3971 {
3972 /* For 'autoread' -1 means to use global value. */
3973 if ((int *)varp == &curbuf->b_p_ar
3974 && opt_flags == OPT_LOCAL)
3975 value = -1;
3976 else
3977 value = *(int *)get_varp_scope(&(options[opt_idx]),
3978 OPT_GLOBAL);
3979 }
3980 else
3981 {
3982 /*
3983 * ":set invopt": invert
3984 * ":set opt" or ":set noopt": set or reset
3985 */
3986 if (nextchar != NUL && !vim_iswhite(afterchar))
3987 {
3988 errmsg = e_trailing;
3989 goto skip;
3990 }
3991 if (prefix == 2) /* inv */
3992 value = *(int *)(varp) ^ 1;
3993 else
3994 value = prefix;
3995 }
3996
3997 errmsg = set_bool_option(opt_idx, varp, (int)value,
3998 opt_flags);
3999 }
4000 else /* numeric or string */
4001 {
4002 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4003 || prefix != 1)
4004 {
4005 errmsg = e_invarg;
4006 goto skip;
4007 }
4008
4009 if (flags & P_NUM) /* numeric */
4010 {
4011 /*
4012 * Different ways to set a number option:
4013 * & set to default value
4014 * < set to global value
4015 * <xx> accept special key codes for 'wildchar'
4016 * c accept any non-digit for 'wildchar'
4017 * [-]0-9 set number
4018 * other error
4019 */
4020 ++arg;
4021 if (nextchar == '&')
4022 value = (long)options[opt_idx].def_val[
4023 ((flags & P_VI_DEF) || cp_val)
4024 ? VI_DEFAULT : VIM_DEFAULT];
4025 else if (nextchar == '<')
4026 value = *(long *)get_varp_scope(&(options[opt_idx]),
4027 OPT_GLOBAL);
4028 else if (((long *)varp == &p_wc
4029 || (long *)varp == &p_wcm)
4030 && (*arg == '<'
4031 || *arg == '^'
4032 || ((!arg[1] || vim_iswhite(arg[1]))
4033 && !VIM_ISDIGIT(*arg))))
4034 {
4035 value = string_to_key(arg);
4036 if (value == 0 && (long *)varp != &p_wcm)
4037 {
4038 errmsg = e_invarg;
4039 goto skip;
4040 }
4041 }
4042 /* allow negative numbers (for 'undolevels') */
4043 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4044 {
4045 i = 0;
4046 if (*arg == '-')
4047 i = 1;
4048#ifdef HAVE_STRTOL
4049 value = strtol((char *)arg, NULL, 0);
4050 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4051 i += 2;
4052#else
4053 value = atol((char *)arg);
4054#endif
4055 while (VIM_ISDIGIT(arg[i]))
4056 ++i;
4057 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4058 {
4059 errmsg = e_invarg;
4060 goto skip;
4061 }
4062 }
4063 else
4064 {
4065 errmsg = (char_u *)N_("E521: Number required after =");
4066 goto skip;
4067 }
4068
4069 if (adding)
4070 value = *(long *)varp + value;
4071 if (prepending)
4072 value = *(long *)varp * value;
4073 if (removing)
4074 value = *(long *)varp - value;
4075 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004076 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 }
4078 else if (opt_idx >= 0) /* string */
4079 {
4080 char_u *save_arg = NULL;
4081 char_u *s = NULL;
4082 char_u *oldval; /* previous value if *varp */
4083 char_u *newval;
4084 char_u *origval;
4085 unsigned newlen;
4086 int comma;
4087 int bs;
4088 int new_value_alloced; /* new string option
4089 was allocated */
4090
4091 /* When using ":set opt=val" for a global option
4092 * with a local value the local value will be
4093 * reset, use the global value here. */
4094 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4095 && (int)options[opt_idx].indir >= PV_BOTH)
4096 varp = options[opt_idx].var;
4097
4098 /* The old value is kept until we are sure that the
4099 * new value is valid. */
4100 oldval = *(char_u **)varp;
4101 if (nextchar == '&') /* set to default val */
4102 {
4103 newval = options[opt_idx].def_val[
4104 ((flags & P_VI_DEF) || cp_val)
4105 ? VI_DEFAULT : VIM_DEFAULT];
4106 if ((char_u **)varp == &p_bg)
4107 {
4108 /* guess the value of 'background' */
4109#ifdef FEAT_GUI
4110 if (gui.in_use)
4111 newval = gui_bg_default();
4112 else
4113#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004114 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 }
4116
4117 /* expand environment variables and ~ (since the
4118 * default value was already expanded, only
4119 * required when an environment variable was set
4120 * later */
4121 if (newval == NULL)
4122 newval = empty_option;
4123 else
4124 {
4125 s = option_expand(opt_idx, newval);
4126 if (s == NULL)
4127 s = newval;
4128 newval = vim_strsave(s);
4129 }
4130 new_value_alloced = TRUE;
4131 }
4132 else if (nextchar == '<') /* set to global val */
4133 {
4134 newval = vim_strsave(*(char_u **)get_varp_scope(
4135 &(options[opt_idx]), OPT_GLOBAL));
4136 new_value_alloced = TRUE;
4137 }
4138 else
4139 {
4140 ++arg; /* jump to after the '=' or ':' */
4141
4142 /*
4143 * Set 'keywordprg' to ":help" if an empty
4144 * value was passed to :set by the user.
4145 * Misuse errbuf[] for the resulting string.
4146 */
4147 if (varp == (char_u *)&p_kp
4148 && (*arg == NUL || *arg == ' '))
4149 {
4150 STRCPY(errbuf, ":help");
4151 save_arg = arg;
4152 arg = errbuf;
4153 }
4154 /*
4155 * Convert 'whichwrap' number to string, for
4156 * backwards compatibility with Vim 3.0.
4157 * Misuse errbuf[] for the resulting string.
4158 */
4159 else if (varp == (char_u *)&p_ww
4160 && VIM_ISDIGIT(*arg))
4161 {
4162 *errbuf = NUL;
4163 i = getdigits(&arg);
4164 if (i & 1)
4165 STRCAT(errbuf, "b,");
4166 if (i & 2)
4167 STRCAT(errbuf, "s,");
4168 if (i & 4)
4169 STRCAT(errbuf, "h,l,");
4170 if (i & 8)
4171 STRCAT(errbuf, "<,>,");
4172 if (i & 16)
4173 STRCAT(errbuf, "[,],");
4174 if (*errbuf != NUL) /* remove trailing , */
4175 errbuf[STRLEN(errbuf) - 1] = NUL;
4176 save_arg = arg;
4177 arg = errbuf;
4178 }
4179 /*
4180 * Remove '>' before 'dir' and 'bdir', for
4181 * backwards compatibility with version 3.0
4182 */
4183 else if ( *arg == '>'
4184 && (varp == (char_u *)&p_dir
4185 || varp == (char_u *)&p_bdir))
4186 {
4187 ++arg;
4188 }
4189
4190 /* When setting the local value of a global
4191 * option, the old value may be the global value. */
4192 if ((int)options[opt_idx].indir >= PV_BOTH
4193 && (opt_flags & OPT_LOCAL))
4194 origval = *(char_u **)get_varp(
4195 &options[opt_idx]);
4196 else
4197 origval = oldval;
4198
4199 /*
4200 * Copy the new string into allocated memory.
4201 * Can't use set_string_option_direct(), because
4202 * we need to remove the backslashes.
4203 */
4204 /* get a bit too much */
4205 newlen = (unsigned)STRLEN(arg) + 1;
4206 if (adding || prepending || removing)
4207 newlen += (unsigned)STRLEN(origval) + 1;
4208 newval = alloc(newlen);
4209 if (newval == NULL) /* out of mem, don't change */
4210 break;
4211 s = newval;
4212
4213 /*
4214 * Copy the string, skip over escaped chars.
4215 * For MS-DOS and WIN32 backslashes before normal
4216 * file name characters are not removed, and keep
4217 * backslash at start, for "\\machine\path", but
4218 * do remove it for "\\\\machine\\path".
4219 * The reverse is found in ExpandOldSetting().
4220 */
4221 while (*arg && !vim_iswhite(*arg))
4222 {
4223 if (*arg == '\\' && arg[1] != NUL
4224#ifdef BACKSLASH_IN_FILENAME
4225 && !((flags & P_EXPAND)
4226 && vim_isfilec(arg[1])
4227 && (arg[1] != '\\'
4228 || (s == newval
4229 && arg[2] != '\\')))
4230#endif
4231 )
4232 ++arg; /* remove backslash */
4233#ifdef FEAT_MBYTE
4234 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004235 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 {
4237 /* copy multibyte char */
4238 mch_memmove(s, arg, (size_t)i);
4239 arg += i;
4240 s += i;
4241 }
4242 else
4243#endif
4244 *s++ = *arg++;
4245 }
4246 *s = NUL;
4247
4248 /*
4249 * Expand environment variables and ~.
4250 * Don't do it when adding without inserting a
4251 * comma.
4252 */
4253 if (!(adding || prepending || removing)
4254 || (flags & P_COMMA))
4255 {
4256 s = option_expand(opt_idx, newval);
4257 if (s != NULL)
4258 {
4259 vim_free(newval);
4260 newlen = (unsigned)STRLEN(s) + 1;
4261 if (adding || prepending || removing)
4262 newlen += (unsigned)STRLEN(origval) + 1;
4263 newval = alloc(newlen);
4264 if (newval == NULL)
4265 break;
4266 STRCPY(newval, s);
4267 }
4268 }
4269
4270 /* locate newval[] in origval[] when removing it
4271 * and when adding to avoid duplicates */
4272 i = 0; /* init for GCC */
4273 if (removing || (flags & P_NODUP))
4274 {
4275 i = (int)STRLEN(newval);
4276 bs = 0;
4277 for (s = origval; *s; ++s)
4278 {
4279 if ((!(flags & P_COMMA)
4280 || s == origval
4281 || (s[-1] == ',' && !(bs & 1)))
4282 && STRNCMP(s, newval, i) == 0
4283 && (!(flags & P_COMMA)
4284 || s[i] == ','
4285 || s[i] == NUL))
4286 break;
4287 /* Count backspaces. Only a comma with an
4288 * even number of backspaces before it is
4289 * recognized as a separator */
4290 if (s > origval && s[-1] == '\\')
4291 ++bs;
4292 else
4293 bs = 0;
4294 }
4295
4296 /* do not add if already there */
4297 if ((adding || prepending) && *s)
4298 {
4299 prepending = FALSE;
4300 adding = FALSE;
4301 STRCPY(newval, origval);
4302 }
4303 }
4304
4305 /* concatenate the two strings; add a ',' if
4306 * needed */
4307 if (adding || prepending)
4308 {
4309 comma = ((flags & P_COMMA) && *origval != NUL
4310 && *newval != NUL);
4311 if (adding)
4312 {
4313 i = (int)STRLEN(origval);
4314 mch_memmove(newval + i + comma, newval,
4315 STRLEN(newval) + 1);
4316 mch_memmove(newval, origval, (size_t)i);
4317 }
4318 else
4319 {
4320 i = (int)STRLEN(newval);
4321 mch_memmove(newval + i + comma, origval,
4322 STRLEN(origval) + 1);
4323 }
4324 if (comma)
4325 newval[i] = ',';
4326 }
4327
4328 /* Remove newval[] from origval[]. (Note: "i" has
4329 * been set above and is used here). */
4330 if (removing)
4331 {
4332 STRCPY(newval, origval);
4333 if (*s)
4334 {
4335 /* may need to remove a comma */
4336 if (flags & P_COMMA)
4337 {
4338 if (s == origval)
4339 {
4340 /* include comma after string */
4341 if (s[i] == ',')
4342 ++i;
4343 }
4344 else
4345 {
4346 /* include comma before string */
4347 --s;
4348 ++i;
4349 }
4350 }
4351 mch_memmove(newval + (s - origval), s + i,
4352 STRLEN(s + i) + 1);
4353 }
4354 }
4355
4356 if (flags & P_FLAGLIST)
4357 {
4358 /* Remove flags that appear twice. */
4359 for (s = newval; *s; ++s)
4360 if ((!(flags & P_COMMA) || *s != ',')
4361 && vim_strchr(s + 1, *s) != NULL)
4362 {
4363 STRCPY(s, s + 1);
4364 --s;
4365 }
4366 }
4367
4368 if (save_arg != NULL) /* number for 'whichwrap' */
4369 arg = save_arg;
4370 new_value_alloced = TRUE;
4371 }
4372
4373 /* Set the new value. */
4374 *(char_u **)(varp) = newval;
4375
4376 /* Handle side effects, and set the global value for
4377 * ":set" on local options. */
4378 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4379 new_value_alloced, oldval, errbuf, opt_flags);
4380
4381 /* If error detected, print the error message. */
4382 if (errmsg != NULL)
4383 goto skip;
4384 }
4385 else /* key code option */
4386 {
4387 char_u *p;
4388
4389 if (nextchar == '&')
4390 {
4391 if (add_termcap_entry(key_name, TRUE) == FAIL)
4392 errmsg = (char_u *)N_("E522: Not found in termcap");
4393 }
4394 else
4395 {
4396 ++arg; /* jump to after the '=' or ':' */
4397 for (p = arg; *p && !vim_iswhite(*p); ++p)
4398 if (*p == '\\' && p[1] != NUL)
4399 ++p;
4400 nextchar = *p;
4401 *p = NUL;
4402 add_termcode(key_name, arg, FALSE);
4403 *p = nextchar;
4404 }
4405 if (full_screen)
4406 ttest(FALSE);
4407 redraw_all_later(CLEAR);
4408 }
4409 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004410
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004412 did_set_option(opt_idx, opt_flags,
4413 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 }
4415
4416skip:
4417 /*
4418 * Advance to next argument.
4419 * - skip until a blank found, taking care of backslashes
4420 * - skip blanks
4421 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4422 */
4423 for (i = 0; i < 2 ; ++i)
4424 {
4425 while (*arg != NUL && !vim_iswhite(*arg))
4426 if (*arg++ == '\\' && *arg != NUL)
4427 ++arg;
4428 arg = skipwhite(arg);
4429 if (*arg != '=')
4430 break;
4431 }
4432 }
4433
4434 if (errmsg != NULL)
4435 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004436 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 i = STRLEN(IObuff) + 2;
4438 if (i + (arg - startarg) < IOSIZE)
4439 {
4440 /* append the argument with the error */
4441 STRCAT(IObuff, ": ");
4442 mch_memmove(IObuff + i, startarg, (arg - startarg));
4443 IObuff[i + (arg - startarg)] = NUL;
4444 }
4445 /* make sure all characters are printable */
4446 trans_characters(IObuff, IOSIZE);
4447
4448 ++no_wait_return; /* wait_return done later */
4449 emsg(IObuff); /* show error highlighted */
4450 --no_wait_return;
4451
4452 return FAIL;
4453 }
4454
4455 arg = skipwhite(arg);
4456 }
4457
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004458theend:
4459 if (silent_mode && did_show)
4460 {
4461 /* After displaying option values in silent mode. */
4462 silent_mode = FALSE;
4463 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4464 msg_putchar('\n');
4465 cursor_on(); /* msg_start() switches it off */
4466 out_flush();
4467 silent_mode = TRUE;
4468 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4469 }
4470
Bram Moolenaar071d4272004-06-13 20:20:40 +00004471 return OK;
4472}
4473
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004474/*
4475 * Call this when an option has been given a new value through a user command.
4476 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4477 */
4478 static void
4479did_set_option(opt_idx, opt_flags, new_value)
4480 int opt_idx;
4481 int opt_flags; /* possibly with OPT_MODELINE */
4482 int new_value; /* value was replaced completely */
4483{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004484 long_u *p;
4485
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004486 options[opt_idx].flags |= P_WAS_SET;
4487
4488 /* When an option is set in the sandbox, from a modeline or in secure mode
4489 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004490 * flag. */
4491 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004492 if (secure
4493#ifdef HAVE_SANDBOX
4494 || sandbox != 0
4495#endif
4496 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004497 *p = *p | P_INSECURE;
4498 else if (new_value)
4499 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004500}
4501
Bram Moolenaar071d4272004-06-13 20:20:40 +00004502 static char_u *
4503illegal_char(errbuf, c)
4504 char_u *errbuf;
4505 int c;
4506{
4507 if (errbuf == NULL)
4508 return (char_u *)"";
4509 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004510 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004511 return errbuf;
4512}
4513
4514/*
4515 * Convert a key name or string into a key value.
4516 * Used for 'wildchar' and 'cedit' options.
4517 */
4518 static int
4519string_to_key(arg)
4520 char_u *arg;
4521{
4522 if (*arg == '<')
4523 return find_key_option(arg + 1);
4524 if (*arg == '^')
4525 return Ctrl_chr(arg[1]);
4526 return *arg;
4527}
4528
4529#ifdef FEAT_CMDWIN
4530/*
4531 * Check value of 'cedit' and set cedit_key.
4532 * Returns NULL if value is OK, error message otherwise.
4533 */
4534 static char_u *
4535check_cedit()
4536{
4537 int n;
4538
4539 if (*p_cedit == NUL)
4540 cedit_key = -1;
4541 else
4542 {
4543 n = string_to_key(p_cedit);
4544 if (vim_isprintc(n))
4545 return e_invarg;
4546 cedit_key = n;
4547 }
4548 return NULL;
4549}
4550#endif
4551
4552#ifdef FEAT_TITLE
4553/*
4554 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4555 * maketitle() to create and display it.
4556 * When switching the title or icon off, call mch_restore_title() to get
4557 * the old value back.
4558 */
4559 static void
4560did_set_title(icon)
4561 int icon; /* Did set icon instead of title */
4562{
4563 if (starting != NO_SCREEN
4564#ifdef FEAT_GUI
4565 && !gui.starting
4566#endif
4567 )
4568 {
4569 maketitle();
4570 if (icon)
4571 {
4572 if (!p_icon)
4573 mch_restore_title(2);
4574 }
4575 else
4576 {
4577 if (!p_title)
4578 mch_restore_title(1);
4579 }
4580 }
4581}
4582#endif
4583
4584/*
4585 * set_options_bin - called when 'bin' changes value.
4586 */
4587 void
4588set_options_bin(oldval, newval, opt_flags)
4589 int oldval;
4590 int newval;
4591 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4592{
4593 /*
4594 * The option values that are changed when 'bin' changes are
4595 * copied when 'bin is set and restored when 'bin' is reset.
4596 */
4597 if (newval)
4598 {
4599 if (!oldval) /* switched on */
4600 {
4601 if (!(opt_flags & OPT_GLOBAL))
4602 {
4603 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4604 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4605 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4606 curbuf->b_p_et_nobin = curbuf->b_p_et;
4607 }
4608 if (!(opt_flags & OPT_LOCAL))
4609 {
4610 p_tw_nobin = p_tw;
4611 p_wm_nobin = p_wm;
4612 p_ml_nobin = p_ml;
4613 p_et_nobin = p_et;
4614 }
4615 }
4616
4617 if (!(opt_flags & OPT_GLOBAL))
4618 {
4619 curbuf->b_p_tw = 0; /* no automatic line wrap */
4620 curbuf->b_p_wm = 0; /* no automatic line wrap */
4621 curbuf->b_p_ml = 0; /* no modelines */
4622 curbuf->b_p_et = 0; /* no expandtab */
4623 }
4624 if (!(opt_flags & OPT_LOCAL))
4625 {
4626 p_tw = 0;
4627 p_wm = 0;
4628 p_ml = FALSE;
4629 p_et = FALSE;
4630 p_bin = TRUE; /* needed when called for the "-b" argument */
4631 }
4632 }
4633 else if (oldval) /* switched off */
4634 {
4635 if (!(opt_flags & OPT_GLOBAL))
4636 {
4637 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4638 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4639 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4640 curbuf->b_p_et = curbuf->b_p_et_nobin;
4641 }
4642 if (!(opt_flags & OPT_LOCAL))
4643 {
4644 p_tw = p_tw_nobin;
4645 p_wm = p_wm_nobin;
4646 p_ml = p_ml_nobin;
4647 p_et = p_et_nobin;
4648 }
4649 }
4650}
4651
4652#ifdef FEAT_VIMINFO
4653/*
4654 * Find the parameter represented by the given character (eg ', :, ", or /),
4655 * and return its associated value in the 'viminfo' string.
4656 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004657 * If the parameter is not specified in the string or there is no following
4658 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659 */
4660 int
4661get_viminfo_parameter(type)
4662 int type;
4663{
4664 char_u *p;
4665
4666 p = find_viminfo_parameter(type);
4667 if (p != NULL && VIM_ISDIGIT(*p))
4668 return atoi((char *)p);
4669 return -1;
4670}
4671
4672/*
4673 * Find the parameter represented by the given character (eg ''', ':', '"', or
4674 * '/') in the 'viminfo' option and return a pointer to the string after it.
4675 * Return NULL if the parameter is not specified in the string.
4676 */
4677 char_u *
4678find_viminfo_parameter(type)
4679 int type;
4680{
4681 char_u *p;
4682
4683 for (p = p_viminfo; *p; ++p)
4684 {
4685 if (*p == type)
4686 return p + 1;
4687 if (*p == 'n') /* 'n' is always the last one */
4688 break;
4689 p = vim_strchr(p, ','); /* skip until next ',' */
4690 if (p == NULL) /* hit the end without finding parameter */
4691 break;
4692 }
4693 return NULL;
4694}
4695#endif
4696
4697/*
4698 * Expand environment variables for some string options.
4699 * These string options cannot be indirect!
4700 * If "val" is NULL expand the current value of the option.
4701 * Return pointer to NameBuff, or NULL when not expanded.
4702 */
4703 static char_u *
4704option_expand(opt_idx, val)
4705 int opt_idx;
4706 char_u *val;
4707{
4708 /* if option doesn't need expansion nothing to do */
4709 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4710 return NULL;
4711
4712 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4713 * expand_env() would truncate the string. */
4714 if (val != NULL && STRLEN(val) > MAXPATHL)
4715 return NULL;
4716
4717 if (val == NULL)
4718 val = *(char_u **)options[opt_idx].var;
4719
4720 /*
4721 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4722 * Escape spaces when expanding 'tags', they are used to separate file
4723 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004724 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004725 */
4726 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004727 (char_u **)options[opt_idx].var == &p_tags,
4728#ifdef FEAT_SYN_HL
4729 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4730#endif
4731 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004732 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4733 return NULL;
4734
4735 return NameBuff;
4736}
4737
4738/*
4739 * After setting various option values: recompute variables that depend on
4740 * option values.
4741 */
4742 static void
4743didset_options()
4744{
4745 /* initialize the table for 'iskeyword' et.al. */
4746 (void)init_chartab();
4747
4748 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4749 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4750#ifdef FEAT_SESSION
4751 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4752 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4753#endif
4754#ifdef FEAT_FOLDING
4755 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4756#endif
4757 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4758#ifdef FEAT_VIRTUALEDIT
4759 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4760#endif
4761#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4762 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4763#endif
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004764#ifdef FEAT_SYN_HL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004765 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004766 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004767 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004768#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4770 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4771#endif
4772#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4773 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4774#endif
4775#ifdef FEAT_CMDWIN
4776 /* set cedit_key */
4777 (void)check_cedit();
4778#endif
4779}
4780
4781/*
4782 * Check for string options that are NULL (normally only termcap options).
4783 */
4784 void
4785check_options()
4786{
4787 int opt_idx;
4788
4789 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4790 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4791 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4792}
4793
4794/*
4795 * Check string options in a buffer for NULL value.
4796 */
4797 void
4798check_buf_options(buf)
4799 buf_T *buf;
4800{
4801#if defined(FEAT_QUICKFIX)
4802 check_string_option(&buf->b_p_bh);
4803 check_string_option(&buf->b_p_bt);
4804#endif
4805#ifdef FEAT_MBYTE
4806 check_string_option(&buf->b_p_fenc);
4807#endif
4808 check_string_option(&buf->b_p_ff);
4809#ifdef FEAT_FIND_ID
4810 check_string_option(&buf->b_p_def);
4811 check_string_option(&buf->b_p_inc);
4812# ifdef FEAT_EVAL
4813 check_string_option(&buf->b_p_inex);
4814# endif
4815#endif
4816#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4817 check_string_option(&buf->b_p_inde);
4818 check_string_option(&buf->b_p_indk);
4819#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00004820#if defined(FEAT_EVAL)
4821 check_string_option(&buf->b_p_fex);
4822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004823#ifdef FEAT_CRYPT
4824 check_string_option(&buf->b_p_key);
4825#endif
4826 check_string_option(&buf->b_p_kp);
4827 check_string_option(&buf->b_p_mps);
4828 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004829 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004830 check_string_option(&buf->b_p_isk);
4831#ifdef FEAT_COMMENTS
4832 check_string_option(&buf->b_p_com);
4833#endif
4834#ifdef FEAT_FOLDING
4835 check_string_option(&buf->b_p_cms);
4836#endif
4837 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004838#ifdef FEAT_TEXTOBJ
4839 check_string_option(&buf->b_p_qe);
4840#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841#ifdef FEAT_SYN_HL
4842 check_string_option(&buf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004843 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00004844 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00004845 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004846#endif
4847#ifdef FEAT_SEARCHPATH
4848 check_string_option(&buf->b_p_sua);
4849#endif
4850#ifdef FEAT_CINDENT
4851 check_string_option(&buf->b_p_cink);
4852 check_string_option(&buf->b_p_cino);
4853#endif
4854#ifdef FEAT_AUTOCMD
4855 check_string_option(&buf->b_p_ft);
4856#endif
4857#ifdef FEAT_OSFILETYPE
4858 check_string_option(&buf->b_p_oft);
4859#endif
4860#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4861 check_string_option(&buf->b_p_cinw);
4862#endif
4863#ifdef FEAT_INS_EXPAND
4864 check_string_option(&buf->b_p_cpt);
4865#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004866#ifdef FEAT_COMPL_FUNC
4867 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00004868 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004869#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004870#ifdef FEAT_KEYMAP
4871 check_string_option(&buf->b_p_keymap);
4872#endif
4873#ifdef FEAT_QUICKFIX
4874 check_string_option(&buf->b_p_gp);
4875 check_string_option(&buf->b_p_mp);
4876 check_string_option(&buf->b_p_efm);
4877#endif
4878 check_string_option(&buf->b_p_ep);
4879 check_string_option(&buf->b_p_path);
4880 check_string_option(&buf->b_p_tags);
4881#ifdef FEAT_INS_EXPAND
4882 check_string_option(&buf->b_p_dict);
4883 check_string_option(&buf->b_p_tsr);
4884#endif
4885}
4886
4887/*
4888 * Free the string allocated for an option.
4889 * Checks for the string being empty_option. This may happen if we're out of
4890 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4891 * check_options().
4892 * Does NOT check for P_ALLOCED flag!
4893 */
4894 void
4895free_string_option(p)
4896 char_u *p;
4897{
4898 if (p != empty_option)
4899 vim_free(p);
4900}
4901
4902 void
4903clear_string_option(pp)
4904 char_u **pp;
4905{
4906 if (*pp != empty_option)
4907 vim_free(*pp);
4908 *pp = empty_option;
4909}
4910
4911 static void
4912check_string_option(pp)
4913 char_u **pp;
4914{
4915 if (*pp == NULL)
4916 *pp = empty_option;
4917}
4918
4919/*
4920 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4921 */
4922 void
4923set_term_option_alloced(p)
4924 char_u **p;
4925{
4926 int opt_idx;
4927
4928 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4929 if (options[opt_idx].var == (char_u *)p)
4930 {
4931 options[opt_idx].flags |= P_ALLOCED;
4932 return;
4933 }
4934 return; /* cannot happen: didn't find it! */
4935}
4936
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004937#if defined(FEAT_EVAL) || defined(PROTO)
4938/*
4939 * Return TRUE when option "opt" was set from a modeline or in secure mode.
4940 * Return FALSE when it wasn't.
4941 * Return -1 for an unknown option.
4942 */
4943 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004944was_set_insecurely(opt, opt_flags)
4945 char_u *opt;
4946 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004947{
4948 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004949 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004950
4951 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004952 {
4953 flagp = insecure_flag(idx, opt_flags);
4954 return (*flagp & P_INSECURE) != 0;
4955 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004956 EMSG2(_(e_intern2), "was_set_insecurely()");
4957 return -1;
4958}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004959
4960/*
4961 * Get a pointer to the flags used for the P_INSECURE flag of option
4962 * "opt_idx". For some local options a local flags field is used.
4963 */
4964 static long_u *
4965insecure_flag(opt_idx, opt_flags)
4966 int opt_idx;
4967 int opt_flags;
4968{
4969 if (opt_flags & OPT_LOCAL)
4970 switch ((int)options[opt_idx].indir)
4971 {
4972#ifdef FEAT_STL_OPT
4973 case OPT_BOTH(PV_STL): return &curwin->w_p_stl_flags;
4974#endif
4975#ifdef FEAT_EVAL
4976 case PV_FDE: return &curwin->w_p_fde_flags;
4977 case PV_FDT: return &curwin->w_p_fdt_flags;
4978#endif
4979#if defined(FEAT_EVAL)
4980# if defined(FEAT_CINDENT)
4981 case PV_INDE: return &curbuf->b_p_inde_flags;
4982# endif
4983 case PV_FEX: return &curbuf->b_p_fex_flags;
4984# ifdef FEAT_FIND_ID
4985 case PV_INEX: return &curbuf->b_p_inex_flags;
4986# endif
4987#endif
4988 }
4989
4990 /* Nothing special, return global flags field. */
4991 return &options[opt_idx].flags;
4992}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004993#endif
4994
Bram Moolenaar071d4272004-06-13 20:20:40 +00004995/*
4996 * Set a string option to a new value (without checking the effect).
4997 * The string is copied into allocated memory.
4998 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4999 */
5000 void
5001set_string_option_direct(name, opt_idx, val, opt_flags)
5002 char_u *name;
5003 int opt_idx;
5004 char_u *val;
5005 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5006{
5007 char_u *s;
5008 char_u **varp;
5009 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5010
5011 if (opt_idx == -1) /* use name */
5012 {
5013 opt_idx = findoption(name);
5014 if (opt_idx == -1) /* not found (should not happen) */
5015 return;
5016 }
5017
5018 if (options[opt_idx].var == NULL) /* can't set hidden option */
5019 return;
5020
5021 s = vim_strsave(val);
5022 if (s != NULL)
5023 {
5024 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5025 both ? OPT_LOCAL : opt_flags);
5026 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
5027 free_string_option(*varp);
5028 *varp = s;
5029
5030 /* For buffer/window local option may also set the global value. */
5031 if (both)
5032 set_string_option_global(opt_idx, varp);
5033
5034 options[opt_idx].flags |= P_ALLOCED;
5035
5036 /* When setting both values of a global option with a local value,
5037 * make the local value empty, so that the global value is used. */
5038 if ((int)options[opt_idx].indir >= PV_BOTH && both)
5039 {
5040 free_string_option(*varp);
5041 *varp = empty_option;
5042 }
5043 }
5044}
5045
5046/*
5047 * Set global value for string option when it's a local option.
5048 */
5049 static void
5050set_string_option_global(opt_idx, varp)
5051 int opt_idx; /* option index */
5052 char_u **varp; /* pointer to option variable */
5053{
5054 char_u **p, *s;
5055
5056 /* the global value is always allocated */
5057 if (options[opt_idx].var == VAR_WIN)
5058 p = (char_u **)GLOBAL_WO(varp);
5059 else
5060 p = (char_u **)options[opt_idx].var;
5061 if (options[opt_idx].indir != PV_NONE
5062 && p != varp
5063 && (s = vim_strsave(*varp)) != NULL)
5064 {
5065 free_string_option(*p);
5066 *p = s;
5067 }
5068}
5069
5070/*
5071 * Set a string option to a new value, and handle the effects.
5072 */
5073 static void
5074set_string_option(opt_idx, value, opt_flags)
5075 int opt_idx;
5076 char_u *value;
5077 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5078{
5079 char_u *s;
5080 char_u **varp;
5081 char_u *oldval;
5082
5083 if (options[opt_idx].var == NULL) /* don't set hidden option */
5084 return;
5085
5086 s = vim_strsave(value);
5087 if (s != NULL)
5088 {
5089 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5090 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5091 ? ((int)options[opt_idx].indir >= PV_BOTH
5092 ? OPT_GLOBAL : OPT_LOCAL)
5093 : opt_flags);
5094 oldval = *varp;
5095 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005096 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5097 opt_flags) == NULL)
5098 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099 }
5100}
5101
5102/*
5103 * Handle string options that need some action to perform when changed.
5104 * Returns NULL for success, or an error message for an error.
5105 */
5106 static char_u *
5107did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5108 opt_flags)
5109 int opt_idx; /* index in options[] table */
5110 char_u **varp; /* pointer to the option variable */
5111 int new_value_alloced; /* new value was allocated */
5112 char_u *oldval; /* previous value of the option */
5113 char_u *errbuf; /* buffer for errors, or NULL */
5114 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5115{
5116 char_u *errmsg = NULL;
5117 char_u *s, *p;
5118 int did_chartab = FALSE;
5119 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00005120 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121
5122 /* Get the global option to compare with, otherwise we would have to check
5123 * two values for all local options. */
5124 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5125
5126 /* Disallow changing some options from secure mode */
5127 if ((secure
5128#ifdef HAVE_SANDBOX
5129 || sandbox != 0
5130#endif
5131 ) && (options[opt_idx].flags & P_SECURE))
5132 {
5133 errmsg = e_secure;
5134 }
5135
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005136 /* Check for a "normal" file name in some options. Disallow a path
5137 * separator (slash and/or backslash), wildcards and characters that are
5138 * often illegal in a file name. */
5139 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005140 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005141 {
5142 errmsg = e_invarg;
5143 }
5144
Bram Moolenaar071d4272004-06-13 20:20:40 +00005145 /* 'term' */
5146 else if (varp == &T_NAME)
5147 {
5148 if (T_NAME[0] == NUL)
5149 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5150#ifdef FEAT_GUI
5151 if (gui.in_use)
5152 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5153 else if (term_is_gui(T_NAME))
5154 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5155#endif
5156 else if (set_termname(T_NAME) == FAIL)
5157 errmsg = (char_u *)N_("E522: Not found in termcap");
5158 else
5159 /* Screen colors may have changed. */
5160 redraw_later_clear();
5161 }
5162
5163 /* 'backupcopy' */
5164 else if (varp == &p_bkc)
5165 {
5166 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5167 errmsg = e_invarg;
5168 if (((bkc_flags & BKC_AUTO) != 0)
5169 + ((bkc_flags & BKC_YES) != 0)
5170 + ((bkc_flags & BKC_NO) != 0) != 1)
5171 {
5172 /* Must have exactly one of "auto", "yes" and "no". */
5173 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5174 errmsg = e_invarg;
5175 }
5176 }
5177
5178 /* 'backupext' and 'patchmode' */
5179 else if (varp == &p_bex || varp == &p_pm)
5180 {
5181 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5182 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5183 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5184 }
5185
5186 /*
5187 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5188 * If the new option is invalid, use old value. 'lisp' option: refill
5189 * chartab[] for '-' char
5190 */
5191 else if ( varp == &p_isi
5192 || varp == &(curbuf->b_p_isk)
5193 || varp == &p_isp
5194 || varp == &p_isf)
5195 {
5196 if (init_chartab() == FAIL)
5197 {
5198 did_chartab = TRUE; /* need to restore it below */
5199 errmsg = e_invarg; /* error in value */
5200 }
5201 }
5202
5203 /* 'helpfile' */
5204 else if (varp == &p_hf)
5205 {
5206 /* May compute new values for $VIM and $VIMRUNTIME */
5207 if (didset_vim)
5208 {
5209 vim_setenv((char_u *)"VIM", (char_u *)"");
5210 didset_vim = FALSE;
5211 }
5212 if (didset_vimruntime)
5213 {
5214 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5215 didset_vimruntime = FALSE;
5216 }
5217 }
5218
5219#ifdef FEAT_MULTI_LANG
5220 /* 'helplang' */
5221 else if (varp == &p_hlg)
5222 {
5223 /* Check for "", "ab", "ab,cd", etc. */
5224 for (s = p_hlg; *s != NUL; s += 3)
5225 {
5226 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5227 {
5228 errmsg = e_invarg;
5229 break;
5230 }
5231 if (s[2] == NUL)
5232 break;
5233 }
5234 }
5235#endif
5236
5237 /* 'highlight' */
5238 else if (varp == &p_hl)
5239 {
5240 if (highlight_changed() == FAIL)
5241 errmsg = e_invarg; /* invalid flags */
5242 }
5243
5244 /* 'nrformats' */
5245 else if (gvarp == &p_nf)
5246 {
5247 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5248 errmsg = e_invarg;
5249 }
5250
5251#ifdef FEAT_SESSION
5252 /* 'sessionoptions' */
5253 else if (varp == &p_ssop)
5254 {
5255 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5256 errmsg = e_invarg;
5257 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5258 {
5259 /* Don't allow both "sesdir" and "curdir". */
5260 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5261 errmsg = e_invarg;
5262 }
5263 }
5264 /* 'viewoptions' */
5265 else if (varp == &p_vop)
5266 {
5267 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5268 errmsg = e_invarg;
5269 }
5270#endif
5271
5272 /* 'scrollopt' */
5273#ifdef FEAT_SCROLLBIND
5274 else if (varp == &p_sbo)
5275 {
5276 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5277 errmsg = e_invarg;
5278 }
5279#endif
5280
5281 /* 'ambiwidth' */
5282#ifdef FEAT_MBYTE
5283 else if (varp == &p_ambw)
5284 {
5285 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5286 errmsg = e_invarg;
5287 }
5288#endif
5289
5290 /* 'background' */
5291 else if (varp == &p_bg)
5292 {
5293 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5294 {
5295#ifdef FEAT_EVAL
5296 int dark = (*p_bg == 'd');
5297#endif
5298
5299 init_highlight(FALSE, FALSE);
5300
5301#ifdef FEAT_EVAL
5302 if (dark != (*p_bg == 'd')
5303 && get_var_value((char_u *)"g:colors_name") != NULL)
5304 {
5305 /* The color scheme must have set 'background' back to another
5306 * value, that's not what we want here. Disable the color
5307 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005308 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309 free_string_option(p_bg);
5310 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5311 check_string_option(&p_bg);
5312 init_highlight(FALSE, FALSE);
5313 }
5314#endif
5315 }
5316 else
5317 errmsg = e_invarg;
5318 }
5319
5320 /* 'wildmode' */
5321 else if (varp == &p_wim)
5322 {
5323 if (check_opt_wim() == FAIL)
5324 errmsg = e_invarg;
5325 }
5326
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005327#ifdef FEAT_CMDL_COMPL
5328 /* 'wildoptions' */
5329 else if (varp == &p_wop)
5330 {
5331 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5332 errmsg = e_invarg;
5333 }
5334#endif
5335
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336#ifdef FEAT_WAK
5337 /* 'winaltkeys' */
5338 else if (varp == &p_wak)
5339 {
5340 if (*p_wak == NUL
5341 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5342 errmsg = e_invarg;
5343# ifdef FEAT_MENU
5344# ifdef FEAT_GUI_MOTIF
5345 else if (gui.in_use)
5346 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5347# else
5348# ifdef FEAT_GUI_GTK
5349 else if (gui.in_use)
5350 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5351# endif
5352# endif
5353# endif
5354 }
5355#endif
5356
5357#ifdef FEAT_AUTOCMD
5358 /* 'eventignore' */
5359 else if (varp == &p_ei)
5360 {
5361 if (check_ei() == FAIL)
5362 errmsg = e_invarg;
5363 }
5364#endif
5365
5366#ifdef FEAT_MBYTE
5367 /* 'encoding' and 'fileencoding' */
5368 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5369 {
5370 if (gvarp == &p_fenc)
5371 {
5372 if (!curbuf->b_p_ma)
5373 errmsg = e_modifiable;
5374 else if (vim_strchr(*varp, ',') != NULL)
5375 /* No comma allowed in 'fileencoding'; catches confusing it
5376 * with 'fileencodings'. */
5377 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005378 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005379 {
5380# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381 /* May show a "+" in the title now. */
5382 need_maketitle = TRUE;
5383# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005384 /* Add 'fileencoding' to the swap file. */
5385 ml_setflags(curbuf);
5386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387 }
5388 if (errmsg == NULL)
5389 {
5390 /* canonize the value, so that STRCMP() can be used on it */
5391 p = enc_canonize(*varp);
5392 if (p != NULL)
5393 {
5394 vim_free(*varp);
5395 *varp = p;
5396 }
5397 if (varp == &p_enc)
5398 {
5399 errmsg = mb_init();
5400# ifdef FEAT_TITLE
5401 need_maketitle = TRUE;
5402# endif
5403 }
5404 }
5405
5406# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5407 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5408 {
5409 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5410 if (STRCMP(p_tenc, "utf-8") != 0)
5411 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5412 }
5413# endif
5414
5415 if (errmsg == NULL)
5416 {
5417# ifdef FEAT_KEYMAP
5418 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5419 * (with another encoding). */
5420 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5421 (void)keymap_init();
5422# endif
5423
5424 /* When 'termencoding' is not empty and 'encoding' changes or when
5425 * 'termencoding' changes, need to setup for keyboard input and
5426 * display output conversion. */
5427 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5428 {
5429 convert_setup(&input_conv, p_tenc, p_enc);
5430 convert_setup(&output_conv, p_enc, p_tenc);
5431 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005432
5433# if defined(WIN3264) && defined(FEAT_MBYTE)
5434 /* $HOME may have characters in active code page. */
5435 if (varp == &p_enc)
5436 init_homedir();
5437# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005438 }
5439 }
5440#endif
5441
5442#if defined(FEAT_POSTSCRIPT)
5443 else if (varp == &p_penc)
5444 {
5445 /* Canonize printencoding if VIM standard one */
5446 p = enc_canonize(p_penc);
5447 if (p != NULL)
5448 {
5449 vim_free(p_penc);
5450 p_penc = p;
5451 }
5452 else
5453 {
5454 /* Ensure lower case and '-' for '_' */
5455 for (s = p_penc; *s != NUL; s++)
5456 {
5457 if (*s == '_')
5458 *s = '-';
5459 else
5460 *s = TOLOWER_ASC(*s);
5461 }
5462 }
5463 }
5464#endif
5465
Bram Moolenaar9372a112005-12-06 19:59:18 +00005466#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467 else if (varp == &p_imak)
5468 {
5469 if (gui.in_use && !im_xim_isvalid_imactivate())
5470 errmsg = e_invarg;
5471 }
5472#endif
5473
5474#ifdef FEAT_KEYMAP
5475 else if (varp == &curbuf->b_p_keymap)
5476 {
5477 /* load or unload key mapping tables */
5478 errmsg = keymap_init();
5479
5480 /* When successfully installed a new keymap switch on using it. */
5481 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5482 {
5483 curbuf->b_p_iminsert = B_IMODE_LMAP;
5484 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5485 curbuf->b_p_imsearch = B_IMODE_LMAP;
5486 set_iminsert_global();
5487 set_imsearch_global();
5488# ifdef FEAT_WINDOWS
5489 status_redraw_curbuf();
5490# endif
5491 }
5492 }
5493#endif
5494
5495 /* 'fileformat' */
5496 else if (gvarp == &p_ff)
5497 {
5498 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5499 errmsg = e_modifiable;
5500 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5501 errmsg = e_invarg;
5502 else
5503 {
5504 /* may also change 'textmode' */
5505 if (get_fileformat(curbuf) == EOL_DOS)
5506 curbuf->b_p_tx = TRUE;
5507 else
5508 curbuf->b_p_tx = FALSE;
5509#ifdef FEAT_TITLE
5510 need_maketitle = TRUE;
5511#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005512 /* update flag in swap file */
5513 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514 }
5515 }
5516
5517 /* 'fileformats' */
5518 else if (varp == &p_ffs)
5519 {
5520 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5521 errmsg = e_invarg;
5522 else
5523 {
5524 /* also change 'textauto' */
5525 if (*p_ffs == NUL)
5526 p_ta = FALSE;
5527 else
5528 p_ta = TRUE;
5529 }
5530 }
5531
5532#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5533 /* 'cryptkey' */
5534 else if (gvarp == &p_key)
5535 {
5536 /* Make sure the ":set" command doesn't show the new value in the
5537 * history. */
5538 remove_key_from_history();
5539 }
5540#endif
5541
5542 /* 'matchpairs' */
5543 else if (gvarp == &p_mps)
5544 {
5545 /* Check for "x:y,x:y" */
5546 for (p = *varp; *p != NUL; p += 4)
5547 {
5548 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5549 {
5550 errmsg = e_invarg;
5551 break;
5552 }
5553 if (p[3] == NUL)
5554 break;
5555 }
5556 }
5557
5558#ifdef FEAT_COMMENTS
5559 /* 'comments' */
5560 else if (gvarp == &p_com)
5561 {
5562 for (s = *varp; *s; )
5563 {
5564 while (*s && *s != ':')
5565 {
5566 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5567 && !VIM_ISDIGIT(*s) && *s != '-')
5568 {
5569 errmsg = illegal_char(errbuf, *s);
5570 break;
5571 }
5572 ++s;
5573 }
5574 if (*s++ == NUL)
5575 errmsg = (char_u *)N_("E524: Missing colon");
5576 else if (*s == ',' || *s == NUL)
5577 errmsg = (char_u *)N_("E525: Zero length string");
5578 if (errmsg != NULL)
5579 break;
5580 while (*s && *s != ',')
5581 {
5582 if (*s == '\\' && s[1] != NUL)
5583 ++s;
5584 ++s;
5585 }
5586 s = skip_to_option_part(s);
5587 }
5588 }
5589#endif
5590
5591 /* 'listchars' */
5592 else if (varp == &p_lcs)
5593 {
5594 errmsg = set_chars_option(varp);
5595 }
5596
5597#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5598 /* 'fillchars' */
5599 else if (varp == &p_fcs)
5600 {
5601 errmsg = set_chars_option(varp);
5602 }
5603#endif
5604
5605#ifdef FEAT_CMDWIN
5606 /* 'cedit' */
5607 else if (varp == &p_cedit)
5608 {
5609 errmsg = check_cedit();
5610 }
5611#endif
5612
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005613 /* 'verbosefile' */
5614 else if (varp == &p_vfile)
5615 {
5616 verbose_stop();
5617 if (*p_vfile != NUL && verbose_open() == FAIL)
5618 errmsg = e_invarg;
5619 }
5620
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621#ifdef FEAT_VIMINFO
5622 /* 'viminfo' */
5623 else if (varp == &p_viminfo)
5624 {
5625 for (s = p_viminfo; *s;)
5626 {
5627 /* Check it's a valid character */
5628 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5629 {
5630 errmsg = illegal_char(errbuf, *s);
5631 break;
5632 }
5633 if (*s == 'n') /* name is always last one */
5634 {
5635 break;
5636 }
5637 else if (*s == 'r') /* skip until next ',' */
5638 {
5639 while (*++s && *s != ',')
5640 ;
5641 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005642 else if (*s == '%')
5643 {
5644 /* optional number */
5645 while (vim_isdigit(*++s))
5646 ;
5647 }
5648 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649 ++s; /* no extra chars */
5650 else /* must have a number */
5651 {
5652 while (vim_isdigit(*++s))
5653 ;
5654
5655 if (!VIM_ISDIGIT(*(s - 1)))
5656 {
5657 if (errbuf != NULL)
5658 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005659 sprintf((char *)errbuf,
5660 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661 transchar_byte(*(s - 1)));
5662 errmsg = errbuf;
5663 }
5664 else
5665 errmsg = (char_u *)"";
5666 break;
5667 }
5668 }
5669 if (*s == ',')
5670 ++s;
5671 else if (*s)
5672 {
5673 if (errbuf != NULL)
5674 errmsg = (char_u *)N_("E527: Missing comma");
5675 else
5676 errmsg = (char_u *)"";
5677 break;
5678 }
5679 }
5680 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5681 errmsg = (char_u *)N_("E528: Must specify a ' value");
5682 }
5683#endif /* FEAT_VIMINFO */
5684
5685 /* terminal options */
5686 else if (istermoption(&options[opt_idx]) && full_screen)
5687 {
5688 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5689 if (varp == &T_CCO)
5690 {
5691 t_colors = atoi((char *)T_CCO);
5692 if (t_colors <= 1)
5693 {
5694 if (new_value_alloced)
5695 vim_free(T_CCO);
5696 T_CCO = empty_option;
5697 }
5698 /* We now have a different color setup, initialize it again. */
5699 init_highlight(TRUE, FALSE);
5700 }
5701 ttest(FALSE);
5702 if (varp == &T_ME)
5703 {
5704 out_str(T_ME);
5705 redraw_later(CLEAR);
5706#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5707 /* Since t_me has been set, this probably means that the user
5708 * wants to use this as default colors. Need to reset default
5709 * background/foreground colors. */
5710 mch_set_normal_colors();
5711#endif
5712 }
5713 }
5714
5715#ifdef FEAT_LINEBREAK
5716 /* 'showbreak' */
5717 else if (varp == &p_sbr)
5718 {
5719 for (s = p_sbr; *s; )
5720 {
5721 if (ptr2cells(s) != 1)
5722 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005723 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005724 }
5725 }
5726#endif
5727
5728#ifdef FEAT_GUI
5729 /* 'guifont' */
5730 else if (varp == &p_guifont)
5731 {
5732 if (gui.in_use)
5733 {
5734 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00005735# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736 /*
5737 * Put up a font dialog and let the user select a new value.
5738 * If this is cancelled go back to the old value but don't
5739 * give an error message.
5740 */
5741 if (STRCMP(p, "*") == 0)
5742 {
5743 p = gui_mch_font_dialog(oldval);
5744
5745 if (new_value_alloced)
5746 free_string_option(p_guifont);
5747
5748 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5749 new_value_alloced = TRUE;
5750 }
5751# endif
5752 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5753 {
5754# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5755 if (STRCMP(p_guifont, "*") == 0)
5756 {
5757 /* Dialog was cancelled: Keep the old value without giving
5758 * an error message. */
5759 if (new_value_alloced)
5760 free_string_option(p_guifont);
5761 p_guifont = vim_strsave(oldval);
5762 new_value_alloced = TRUE;
5763 }
5764 else
5765# endif
5766 errmsg = (char_u *)N_("E596: Invalid font(s)");
5767 }
5768 }
5769 }
5770# ifdef FEAT_XFONTSET
5771 else if (varp == &p_guifontset)
5772 {
5773 if (STRCMP(p_guifontset, "*") == 0)
5774 errmsg = (char_u *)N_("E597: can't select fontset");
5775 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5776 errmsg = (char_u *)N_("E598: Invalid fontset");
5777 }
5778# endif
5779# ifdef FEAT_MBYTE
5780 else if (varp == &p_guifontwide)
5781 {
5782 if (STRCMP(p_guifontwide, "*") == 0)
5783 errmsg = (char_u *)N_("E533: can't select wide font");
5784 else if (gui_get_wide_font() == FAIL)
5785 errmsg = (char_u *)N_("E534: Invalid wide font");
5786 }
5787# endif
5788#endif
5789
5790#ifdef CURSOR_SHAPE
5791 /* 'guicursor' */
5792 else if (varp == &p_guicursor)
5793 errmsg = parse_shape_opt(SHAPE_CURSOR);
5794#endif
5795
5796#ifdef FEAT_MOUSESHAPE
5797 /* 'mouseshape' */
5798 else if (varp == &p_mouseshape)
5799 {
5800 errmsg = parse_shape_opt(SHAPE_MOUSE);
5801 update_mouseshape(-1);
5802 }
5803#endif
5804
5805#ifdef FEAT_PRINTER
5806 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005807 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005808# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005809 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005810 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00005811# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005812#endif
5813
5814#ifdef FEAT_LANGMAP
5815 /* 'langmap' */
5816 else if (varp == &p_langmap)
5817 langmap_set();
5818#endif
5819
5820#ifdef FEAT_LINEBREAK
5821 /* 'breakat' */
5822 else if (varp == &p_breakat)
5823 fill_breakat_flags();
5824#endif
5825
5826#ifdef FEAT_TITLE
5827 /* 'titlestring' and 'iconstring' */
5828 else if (varp == &p_titlestring || varp == &p_iconstring)
5829 {
5830# ifdef FEAT_STL_OPT
5831 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5832
5833 /* NULL => statusline syntax */
5834 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5835 stl_syntax |= flagval;
5836 else
5837 stl_syntax &= ~flagval;
5838# endif
5839 did_set_title(varp == &p_iconstring);
5840
5841 }
5842#endif
5843
5844#ifdef FEAT_GUI
5845 /* 'guioptions' */
5846 else if (varp == &p_go)
5847 gui_init_which_components(oldval);
5848#endif
5849
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00005850#if defined(FEAT_GUI_TABLINE)
5851 /* 'guitablabel' */
5852 else if (varp == &p_gtl)
5853 gui_update_tabline();
5854#endif
5855
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5857 /* 'ttymouse' */
5858 else if (varp == &p_ttym)
5859 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00005860 /* Switch the mouse off before changing the escape sequences used for
5861 * that. */
5862 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5864 errmsg = e_invarg;
5865 else
5866 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00005867 if (termcap_active)
5868 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 }
5870#endif
5871
5872#ifdef FEAT_VISUAL
5873 /* 'selection' */
5874 else if (varp == &p_sel)
5875 {
5876 if (*p_sel == NUL
5877 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5878 errmsg = e_invarg;
5879 }
5880
5881 /* 'selectmode' */
5882 else if (varp == &p_slm)
5883 {
5884 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5885 errmsg = e_invarg;
5886 }
5887#endif
5888
5889#ifdef FEAT_BROWSE
5890 /* 'browsedir' */
5891 else if (varp == &p_bsdir)
5892 {
5893 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5894 && !mch_isdir(p_bsdir))
5895 errmsg = e_invarg;
5896 }
5897#endif
5898
5899#ifdef FEAT_VISUAL
5900 /* 'keymodel' */
5901 else if (varp == &p_km)
5902 {
5903 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5904 errmsg = e_invarg;
5905 else
5906 {
5907 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5908 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5909 }
5910 }
5911#endif
5912
5913 /* 'mousemodel' */
5914 else if (varp == &p_mousem)
5915 {
5916 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5917 errmsg = e_invarg;
5918#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5919 else if (*p_mousem != *oldval)
5920 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5921 * to create or delete the popup menus. */
5922 gui_motif_update_mousemodel(root_menu);
5923#endif
5924 }
5925
5926 /* 'switchbuf' */
5927 else if (varp == &p_swb)
5928 {
5929 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5930 errmsg = e_invarg;
5931 }
5932
5933 /* 'debug' */
5934 else if (varp == &p_debug)
5935 {
5936 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5937 errmsg = e_invarg;
5938 }
5939
5940 /* 'display' */
5941 else if (varp == &p_dy)
5942 {
5943 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5944 errmsg = e_invarg;
5945 else
5946 (void)init_chartab();
5947
5948 }
5949
5950#ifdef FEAT_VERTSPLIT
5951 /* 'eadirection' */
5952 else if (varp == &p_ead)
5953 {
5954 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5955 errmsg = e_invarg;
5956 }
5957#endif
5958
5959#ifdef FEAT_CLIPBOARD
5960 /* 'clipboard' */
5961 else if (varp == &p_cb)
5962 errmsg = check_clipboard_option();
5963#endif
5964
Bram Moolenaar217ad922005-03-20 22:37:15 +00005965#ifdef FEAT_SYN_HL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005966 /* When 'spelllang' or 'spellfile' is set and there is a window for this
5967 * buffer in which 'spell' is set load the wordlists. */
5968 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00005969 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005970 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005971 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005972
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005973 if (varp == &(curbuf->b_p_spf))
5974 {
5975 l = STRLEN(curbuf->b_p_spf);
5976 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
5977 ".add") != 0))
5978 errmsg = e_invarg;
5979 }
5980
5981 if (errmsg == NULL)
5982 {
5983 FOR_ALL_WINDOWS(wp)
5984 if (wp->w_buffer == curbuf && wp->w_p_spell)
5985 {
5986 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005987# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005988 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005989# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005990 }
5991 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005992 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005993 /* When 'spellcapcheck' is set compile the regexp program. */
5994 else if (varp == &(curbuf->b_p_spc))
5995 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005996 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005997 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005998 /* 'spellsuggest' */
5999 else if (varp == &p_sps)
6000 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006001 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006002 errmsg = e_invarg;
6003 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006004 /* 'mkspellmem' */
6005 else if (varp == &p_msm)
6006 {
6007 if (spell_check_msm() != OK)
6008 errmsg = e_invarg;
6009 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006010#endif
6011
Bram Moolenaar071d4272004-06-13 20:20:40 +00006012#ifdef FEAT_QUICKFIX
6013 /* When 'bufhidden' is set, check for valid value. */
6014 else if (gvarp == &p_bh)
6015 {
6016 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6017 errmsg = e_invarg;
6018 }
6019
6020 /* When 'buftype' is set, check for valid value. */
6021 else if (gvarp == &p_bt)
6022 {
6023 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6024 errmsg = e_invarg;
6025 else
6026 {
6027# ifdef FEAT_WINDOWS
6028 if (curwin->w_status_height)
6029 {
6030 curwin->w_redr_status = TRUE;
6031 redraw_later(VALID);
6032 }
6033# endif
6034 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
6035 }
6036 }
6037#endif
6038
6039#ifdef FEAT_STL_OPT
6040 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006041 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006042 {
6043 int wid;
6044
6045 if (varp == &p_ruf) /* reset ru_wid first */
6046 ru_wid = 0;
6047 s = *varp;
6048 if (varp == &p_ruf && *s == '%')
6049 {
6050 /* set ru_wid if 'ruf' starts with "%99(" */
6051 if (*++s == '-') /* ignore a '-' */
6052 s++;
6053 wid = getdigits(&s);
6054 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6055 ru_wid = wid;
6056 else
6057 errmsg = check_stl_option(p_ruf);
6058 }
6059 else
6060 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006061 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006062 comp_col();
6063 }
6064#endif
6065
6066#ifdef FEAT_INS_EXPAND
6067 /* check if it is a valid value for 'complete' -- Acevedo */
6068 else if (gvarp == &p_cpt)
6069 {
6070 for (s = *varp; *s;)
6071 {
6072 while(*s == ',' || *s == ' ')
6073 s++;
6074 if (!*s)
6075 break;
6076 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6077 {
6078 errmsg = illegal_char(errbuf, *s);
6079 break;
6080 }
6081 if (*++s != NUL && *s != ',' && *s != ' ')
6082 {
6083 if (s[-1] == 'k' || s[-1] == 's')
6084 {
6085 /* skip optional filename after 'k' and 's' */
6086 while (*s && *s != ',' && *s != ' ')
6087 {
6088 if (*s == '\\')
6089 ++s;
6090 ++s;
6091 }
6092 }
6093 else
6094 {
6095 if (errbuf != NULL)
6096 {
6097 sprintf((char *)errbuf,
6098 _("E535: Illegal character after <%c>"),
6099 *--s);
6100 errmsg = errbuf;
6101 }
6102 else
6103 errmsg = (char_u *)"";
6104 break;
6105 }
6106 }
6107 }
6108 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006109
6110 /* 'completeopt' */
6111 else if (varp == &p_cot)
6112 {
6113 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6114 errmsg = e_invarg;
6115 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116#endif /* FEAT_INS_EXPAND */
6117
6118
6119#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6120 else if (varp == &p_toolbar)
6121 {
6122 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6123 &toolbar_flags, TRUE) != 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#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6135 /* 'toolbariconsize': GTK+ 2 only */
6136 else if (varp == &p_tbis)
6137 {
6138 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6139 errmsg = e_invarg;
6140 else
6141 {
6142 out_flush();
6143 gui_mch_show_toolbar((toolbar_flags &
6144 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6145 }
6146 }
6147#endif
6148
6149 /* 'pastetoggle': translate key codes like in a mapping */
6150 else if (varp == &p_pt)
6151 {
6152 if (*p_pt)
6153 {
6154 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
6155 if (p != NULL)
6156 {
6157 if (new_value_alloced)
6158 free_string_option(p_pt);
6159 p_pt = p;
6160 new_value_alloced = TRUE;
6161 }
6162 }
6163 }
6164
6165 /* 'backspace' */
6166 else if (varp == &p_bs)
6167 {
6168 if (VIM_ISDIGIT(*p_bs))
6169 {
6170 if (*p_bs >'2' || p_bs[1] != NUL)
6171 errmsg = e_invarg;
6172 }
6173 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6174 errmsg = e_invarg;
6175 }
6176
6177 /* 'casemap' */
6178 else if (varp == &p_cmp)
6179 {
6180 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6181 errmsg = e_invarg;
6182 }
6183
6184#ifdef FEAT_DIFF
6185 /* 'diffopt' */
6186 else if (varp == &p_dip)
6187 {
6188 if (diffopt_changed() == FAIL)
6189 errmsg = e_invarg;
6190 }
6191#endif
6192
6193#ifdef FEAT_FOLDING
6194 /* 'foldmethod' */
6195 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6196 {
6197 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6198 || *curwin->w_p_fdm == NUL)
6199 errmsg = e_invarg;
6200 else
6201 foldUpdateAll(curwin);
6202 }
6203# ifdef FEAT_EVAL
6204 /* 'foldexpr' */
6205 else if (varp == &curwin->w_p_fde)
6206 {
6207 if (foldmethodIsExpr(curwin))
6208 foldUpdateAll(curwin);
6209 }
6210# endif
6211 /* 'foldmarker' */
6212 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6213 {
6214 p = vim_strchr(*varp, ',');
6215 if (p == NULL)
6216 errmsg = (char_u *)N_("E536: comma required");
6217 else if (p == *varp || p[1] == NUL)
6218 errmsg = e_invarg;
6219 else if (foldmethodIsMarker(curwin))
6220 foldUpdateAll(curwin);
6221 }
6222 /* 'commentstring' */
6223 else if (gvarp == &p_cms)
6224 {
6225 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6226 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6227 }
6228 /* 'foldopen' */
6229 else if (varp == &p_fdo)
6230 {
6231 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6232 errmsg = e_invarg;
6233 }
6234 /* 'foldclose' */
6235 else if (varp == &p_fcl)
6236 {
6237 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6238 errmsg = e_invarg;
6239 }
6240#endif
6241
6242#ifdef FEAT_VIRTUALEDIT
6243 /* 'virtualedit' */
6244 else if (varp == &p_ve)
6245 {
6246 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6247 errmsg = e_invarg;
6248 else if (STRCMP(p_ve, oldval) != 0)
6249 {
6250 /* Recompute cursor position in case the new 've' setting
6251 * changes something. */
6252 validate_virtcol();
6253 coladvance(curwin->w_virtcol);
6254 }
6255 }
6256#endif
6257
6258#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6259 else if (varp == &p_csqf)
6260 {
6261 if (p_csqf != NULL)
6262 {
6263 p = p_csqf;
6264 while (*p != NUL)
6265 {
6266 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6267 || p[1] == NUL
6268 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6269 || (p[2] != NUL && p[2] != ','))
6270 {
6271 errmsg = e_invarg;
6272 break;
6273 }
6274 else if (p[2] == NUL)
6275 break;
6276 else
6277 p += 3;
6278 }
6279 }
6280 }
6281#endif
6282
6283 /* Options that are a list of flags. */
6284 else
6285 {
6286 p = NULL;
6287 if (varp == &p_ww)
6288 p = (char_u *)WW_ALL;
6289 if (varp == &p_shm)
6290 p = (char_u *)SHM_ALL;
6291 else if (varp == &(p_cpo))
6292 p = (char_u *)CPO_ALL;
6293 else if (varp == &(curbuf->b_p_fo))
6294 p = (char_u *)FO_ALL;
6295 else if (varp == &p_mouse)
6296 {
6297#ifdef FEAT_MOUSE
6298 p = (char_u *)MOUSE_ALL;
6299#else
6300 if (*p_mouse != NUL)
6301 errmsg = (char_u *)N_("E538: No mouse support");
6302#endif
6303 }
6304#if defined(FEAT_GUI)
6305 else if (varp == &p_go)
6306 p = (char_u *)GO_ALL;
6307#endif
6308 if (p != NULL)
6309 {
6310 for (s = *varp; *s; ++s)
6311 if (vim_strchr(p, *s) == NULL)
6312 {
6313 errmsg = illegal_char(errbuf, *s);
6314 break;
6315 }
6316 }
6317 }
6318
6319 /*
6320 * If error detected, restore the previous value.
6321 */
6322 if (errmsg != NULL)
6323 {
6324 if (new_value_alloced)
6325 free_string_option(*varp);
6326 *varp = oldval;
6327 /*
6328 * When resetting some values, need to act on it.
6329 */
6330 if (did_chartab)
6331 (void)init_chartab();
6332 if (varp == &p_hl)
6333 (void)highlight_changed();
6334 }
6335 else
6336 {
6337#ifdef FEAT_EVAL
6338 /* Remember where the option was set. */
6339 options[opt_idx].scriptID = current_SID;
6340#endif
6341 /*
6342 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006343 * Use "free_oldval", because recursiveness may change the flags under
6344 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006346 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006347 free_string_option(oldval);
6348 if (new_value_alloced)
6349 options[opt_idx].flags |= P_ALLOCED;
6350 else
6351 options[opt_idx].flags &= ~P_ALLOCED;
6352
6353 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6354 && (int)options[opt_idx].indir >= PV_BOTH)
6355 {
6356 /* global option with local value set to use global value; free
6357 * the local value and make it empty */
6358 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6359 free_string_option(*(char_u **)p);
6360 *(char_u **)p = empty_option;
6361 }
6362
6363 /* May set global value for local option. */
6364 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6365 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006366
6367#ifdef FEAT_AUTOCMD
6368 /*
6369 * Trigger the autocommand only after setting the flags.
6370 */
6371# ifdef FEAT_SYN_HL
6372 /* When 'syntax' is set, load the syntax of that name */
6373 if (varp == &(curbuf->b_p_syn))
6374 {
6375 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6376 curbuf->b_fname, TRUE, curbuf);
6377 }
6378# endif
6379 else if (varp == &(curbuf->b_p_ft))
6380 {
6381 /* 'filetype' is set, trigger the FileType autocommand */
6382 did_filetype = TRUE;
6383 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6384 curbuf->b_fname, TRUE, curbuf);
6385 }
6386#endif
6387#ifdef FEAT_SYN_HL
6388 if (varp == &(curbuf->b_p_spl))
6389 {
6390 char_u fname[200];
6391
6392 /*
6393 * Source the spell/LANG.vim in 'runtimepath'.
6394 * They could set 'spellcapcheck' depending on the language.
6395 * Use the first name in 'spelllang' up to '_region' or
6396 * '.encoding'.
6397 */
6398 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6399 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6400 break;
6401 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6402 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6403 source_runtime(fname, TRUE);
6404 }
6405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006406 }
6407
6408#ifdef FEAT_MOUSE
6409 if (varp == &p_mouse)
6410 {
6411# ifdef FEAT_MOUSE_TTY
6412 if (*p_mouse == NUL)
6413 mch_setmouse(FALSE); /* switch mouse off */
6414 else
6415# endif
6416 setmouse(); /* in case 'mouse' changed */
6417 }
6418#endif
6419
6420 if (curwin->w_curswant != MAXCOL)
6421 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6422 check_redraw(options[opt_idx].flags);
6423
6424 return errmsg;
6425}
6426
6427/*
6428 * Handle setting 'listchars' or 'fillchars'.
6429 * Returns error message, NULL if it's OK.
6430 */
6431 static char_u *
6432set_chars_option(varp)
6433 char_u **varp;
6434{
6435 int round, i, len, entries;
6436 char_u *p, *s;
6437 int c1, c2 = 0;
6438 struct charstab
6439 {
6440 int *cp;
6441 char *name;
6442 };
6443#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6444 static struct charstab filltab[] =
6445 {
6446 {&fill_stl, "stl"},
6447 {&fill_stlnc, "stlnc"},
6448 {&fill_vert, "vert"},
6449 {&fill_fold, "fold"},
6450 {&fill_diff, "diff"},
6451 };
6452#endif
6453 static struct charstab lcstab[] =
6454 {
6455 {&lcs_eol, "eol"},
6456 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006457 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458 {&lcs_prec, "precedes"},
6459 {&lcs_tab2, "tab"},
6460 {&lcs_trail, "trail"},
6461 };
6462 struct charstab *tab;
6463
6464#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6465 if (varp == &p_lcs)
6466#endif
6467 {
6468 tab = lcstab;
6469 entries = sizeof(lcstab) / sizeof(struct charstab);
6470 }
6471#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6472 else
6473 {
6474 tab = filltab;
6475 entries = sizeof(filltab) / sizeof(struct charstab);
6476 }
6477#endif
6478
6479 /* first round: check for valid value, second round: assign values */
6480 for (round = 0; round <= 1; ++round)
6481 {
6482 if (round)
6483 {
6484 /* After checking that the value is valid: set defaults: space for
6485 * 'fillchars', NUL for 'listchars' */
6486 for (i = 0; i < entries; ++i)
6487 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6488 if (varp == &p_lcs)
6489 lcs_tab1 = NUL;
6490#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6491 else
6492 fill_diff = '-';
6493#endif
6494 }
6495 p = *varp;
6496 while (*p)
6497 {
6498 for (i = 0; i < entries; ++i)
6499 {
6500 len = (int)STRLEN(tab[i].name);
6501 if (STRNCMP(p, tab[i].name, len) == 0
6502 && p[len] == ':'
6503 && p[len + 1] != NUL)
6504 {
6505 s = p + len + 1;
6506#ifdef FEAT_MBYTE
6507 c1 = mb_ptr2char_adv(&s);
6508#else
6509 c1 = *s++;
6510#endif
6511 if (tab[i].cp == &lcs_tab2)
6512 {
6513 if (*s == NUL)
6514 continue;
6515#ifdef FEAT_MBYTE
6516 c2 = mb_ptr2char_adv(&s);
6517#else
6518 c2 = *s++;
6519#endif
6520 }
6521 if (*s == ',' || *s == NUL)
6522 {
6523 if (round)
6524 {
6525 if (tab[i].cp == &lcs_tab2)
6526 {
6527 lcs_tab1 = c1;
6528 lcs_tab2 = c2;
6529 }
6530 else
6531 *(tab[i].cp) = c1;
6532
6533 }
6534 p = s;
6535 break;
6536 }
6537 }
6538 }
6539
6540 if (i == entries)
6541 return e_invarg;
6542 if (*p == ',')
6543 ++p;
6544 }
6545 }
6546
6547 return NULL; /* no error */
6548}
6549
6550#ifdef FEAT_STL_OPT
6551/*
6552 * Check validity of options with the 'statusline' format.
6553 * Return error message or NULL.
6554 */
6555 char_u *
6556check_stl_option(s)
6557 char_u *s;
6558{
6559 int itemcnt = 0;
6560 int groupdepth = 0;
6561 static char_u errbuf[80];
6562
6563 while (*s && itemcnt < STL_MAX_ITEM)
6564 {
6565 /* Check for valid keys after % sequences */
6566 while (*s && *s != '%')
6567 s++;
6568 if (!*s)
6569 break;
6570 s++;
6571 if (*s != '%' && *s != ')')
6572 ++itemcnt;
6573 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6574 {
6575 s++;
6576 continue;
6577 }
6578 if (*s == ')')
6579 {
6580 s++;
6581 if (--groupdepth < 0)
6582 break;
6583 continue;
6584 }
6585 if (*s == '-')
6586 s++;
6587 while (VIM_ISDIGIT(*s))
6588 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00006589 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 continue;
6591 if (*s == '.')
6592 {
6593 s++;
6594 while (*s && VIM_ISDIGIT(*s))
6595 s++;
6596 }
6597 if (*s == '(')
6598 {
6599 groupdepth++;
6600 continue;
6601 }
6602 if (vim_strchr(STL_ALL, *s) == NULL)
6603 {
6604 return illegal_char(errbuf, *s);
6605 }
6606 if (*s == '{')
6607 {
6608 s++;
6609 while (*s != '}' && *s)
6610 s++;
6611 if (*s != '}')
6612 return (char_u *)N_("E540: Unclosed expression sequence");
6613 }
6614 }
6615 if (itemcnt >= STL_MAX_ITEM)
6616 return (char_u *)N_("E541: too many items");
6617 if (groupdepth != 0)
6618 return (char_u *)N_("E542: unbalanced groups");
6619 return NULL;
6620}
6621#endif
6622
6623#ifdef FEAT_CLIPBOARD
6624/*
6625 * Extract the items in the 'clipboard' option and set global values.
6626 */
6627 static char_u *
6628check_clipboard_option()
6629{
6630 int new_unnamed = FALSE;
6631 int new_autoselect = FALSE;
6632 int new_autoselectml = FALSE;
6633 regprog_T *new_exclude_prog = NULL;
6634 char_u *errmsg = NULL;
6635 char_u *p;
6636
6637 for (p = p_cb; *p != NUL; )
6638 {
6639 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6640 {
6641 new_unnamed = TRUE;
6642 p += 7;
6643 }
6644 else if (STRNCMP(p, "autoselect", 10) == 0
6645 && (p[10] == ',' || p[10] == NUL))
6646 {
6647 new_autoselect = TRUE;
6648 p += 10;
6649 }
6650 else if (STRNCMP(p, "autoselectml", 12) == 0
6651 && (p[12] == ',' || p[12] == NUL))
6652 {
6653 new_autoselectml = TRUE;
6654 p += 12;
6655 }
6656 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6657 {
6658 p += 8;
6659 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6660 if (new_exclude_prog == NULL)
6661 errmsg = e_invarg;
6662 break;
6663 }
6664 else
6665 {
6666 errmsg = e_invarg;
6667 break;
6668 }
6669 if (*p == ',')
6670 ++p;
6671 }
6672 if (errmsg == NULL)
6673 {
6674 clip_unnamed = new_unnamed;
6675 clip_autoselect = new_autoselect;
6676 clip_autoselectml = new_autoselectml;
6677 vim_free(clip_exclude_prog);
6678 clip_exclude_prog = new_exclude_prog;
6679 }
6680 else
6681 vim_free(new_exclude_prog);
6682
6683 return errmsg;
6684}
6685#endif
6686
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006687#ifdef FEAT_SYN_HL
6688/*
6689 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6690 * Return error message when failed, NULL when OK.
6691 */
6692 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006693compile_cap_prog(buf)
6694 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006695{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006696 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006697 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006698
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006699 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006700 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006701 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006702 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00006703 /* Prepend a ^ so that we only match at one column */
6704 re = concat_str((char_u *)"^", buf->b_p_spc);
6705 if (re != NULL)
6706 {
6707 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
6708 if (buf->b_cap_prog == NULL)
6709 {
6710 buf->b_cap_prog = rp; /* restore the previous program */
6711 return e_invarg;
6712 }
6713 vim_free(re);
6714 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006715 }
6716
6717 vim_free(rp);
6718 return NULL;
6719}
6720#endif
6721
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006722#if defined(FEAT_EVAL) || defined(PROTO)
6723/*
6724 * Set the script ID of option "name" to "id".
6725 */
6726 void
6727set_option_scriptID(name, id)
6728 char_u *name;
6729 int id;
6730{
6731 int opt_idx = findoption(name);
6732
6733 if (opt_idx == -1) /* not found (should not happen) */
6734 EMSG2(_(e_intern2), "set_option_scriptID()");
6735 else
6736 options[opt_idx].scriptID = id;
6737}
6738#endif
6739
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740/*
6741 * Set the value of a boolean option, and take care of side effects.
6742 * Returns NULL for success, or an error message for an error.
6743 */
6744 static char_u *
6745set_bool_option(opt_idx, varp, value, opt_flags)
6746 int opt_idx; /* index in options[] table */
6747 char_u *varp; /* pointer to the option variable */
6748 int value; /* new value */
6749 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6750{
6751 int old_value = *(int *)varp;
6752
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753 /* Disallow changing some options from secure mode */
6754 if ((secure
6755#ifdef HAVE_SANDBOX
6756 || sandbox != 0
6757#endif
6758 ) && (options[opt_idx].flags & P_SECURE))
6759 return e_secure;
6760
6761 *(int *)varp = value; /* set the new value */
6762#ifdef FEAT_EVAL
6763 /* Remember where the option was set. */
6764 options[opt_idx].scriptID = current_SID;
6765#endif
6766
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006767#ifdef FEAT_GUI
6768 need_mouse_correct = TRUE;
6769#endif
6770
Bram Moolenaar071d4272004-06-13 20:20:40 +00006771 /* May set global value for local option. */
6772 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6773 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6774
6775 /*
6776 * Handle side effects of changing a bool option.
6777 */
6778
6779 /* 'compatible' */
6780 if ((int *)varp == &p_cp)
6781 {
6782 compatible_set();
6783 }
6784
Bram Moolenaar071d4272004-06-13 20:20:40 +00006785 else if ((int *)varp == &curbuf->b_p_ro)
6786 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006787 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006788 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6789 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006790
6791 /* when 'readonly' is set may give W10 again */
6792 if (curbuf->b_p_ro)
6793 curbuf->b_did_warn = FALSE;
6794
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795#ifdef FEAT_TITLE
6796 need_maketitle = TRUE;
6797#endif
6798 }
6799
6800#ifdef FEAT_TITLE
6801 /* when 'modifiable' is changed, redraw the window title */
6802 else if ((int *)varp == &curbuf->b_p_ma)
6803 need_maketitle = TRUE;
6804 /* when 'endofline' is changed, redraw the window title */
6805 else if ((int *)varp == &curbuf->b_p_eol)
6806 need_maketitle = TRUE;
6807#endif
6808
6809 /* when 'bin' is set also set some other options */
6810 else if ((int *)varp == &curbuf->b_p_bin)
6811 {
6812 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6813#ifdef FEAT_TITLE
6814 need_maketitle = TRUE;
6815#endif
6816 }
6817
6818#ifdef FEAT_AUTOCMD
6819 /* when 'buflisted' changes, trigger autocommands */
6820 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6821 {
6822 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6823 NULL, NULL, TRUE, curbuf);
6824 }
6825#endif
6826
6827 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6828 else if ((int *)varp == &curbuf->b_p_swf)
6829 {
6830 if (curbuf->b_p_swf && p_uc)
6831 ml_open_file(curbuf); /* create the swap file */
6832 else
6833 mf_close_file(curbuf, TRUE); /* remove the swap file */
6834 }
6835
6836 /* when 'terse' is set change 'shortmess' */
6837 else if ((int *)varp == &p_terse)
6838 {
6839 char_u *p;
6840
6841 p = vim_strchr(p_shm, SHM_SEARCH);
6842
6843 /* insert 's' in p_shm */
6844 if (p_terse && p == NULL)
6845 {
6846 STRCPY(IObuff, p_shm);
6847 STRCAT(IObuff, "s");
6848 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006849# ifdef FEAT_EVAL
6850 set_option_scriptID((char_u *)"shm", current_SID);
6851# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852 }
6853 /* remove 's' from p_shm */
6854 else if (!p_terse && p != NULL)
6855 mch_memmove(p, p + 1, STRLEN(p));
6856 }
6857
6858 /* when 'paste' is set or reset also change other options */
6859 else if ((int *)varp == &p_paste)
6860 {
6861 paste_option_changed();
6862 }
6863
6864 /* when 'insertmode' is set from an autocommand need to do work here */
6865 else if ((int *)varp == &p_im)
6866 {
6867 if (p_im)
6868 {
6869 if ((State & INSERT) == 0)
6870 need_start_insertmode = TRUE;
6871 stop_insert_mode = FALSE;
6872 }
6873 else
6874 {
6875 need_start_insertmode = FALSE;
6876 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00006877 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006878 clear_cmdline = TRUE; /* remove "(insert)" */
6879 restart_edit = 0;
6880 }
6881 }
6882
6883 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6884 else if ((int *)varp == &p_ic && p_hls)
6885 {
6886 redraw_all_later(NOT_VALID);
6887 }
6888
6889#ifdef FEAT_SEARCH_EXTRA
6890 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6891 else if ((int *)varp == &p_hls)
6892 {
6893 no_hlsearch = FALSE;
6894 }
6895#endif
6896
6897#ifdef FEAT_SCROLLBIND
6898 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6899 * at the end of normal_cmd() */
6900 else if ((int *)varp == &curwin->w_p_scb)
6901 {
6902 if (curwin->w_p_scb)
6903 do_check_scrollbind(FALSE);
6904 }
6905#endif
6906
6907#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6908 /* There can be only one window with 'previewwindow' set. */
6909 else if ((int *)varp == &curwin->w_p_pvw)
6910 {
6911 if (curwin->w_p_pvw)
6912 {
6913 win_T *win;
6914
6915 for (win = firstwin; win != NULL; win = win->w_next)
6916 if (win->w_p_pvw && win != curwin)
6917 {
6918 curwin->w_p_pvw = FALSE;
6919 return (char_u *)N_("E590: A preview window already exists");
6920 }
6921 }
6922 }
6923#endif
6924
6925 /* when 'textmode' is set or reset also change 'fileformat' */
6926 else if ((int *)varp == &curbuf->b_p_tx)
6927 {
6928 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6929 }
6930
6931 /* when 'textauto' is set or reset also change 'fileformats' */
6932 else if ((int *)varp == &p_ta)
6933 {
6934 set_string_option_direct((char_u *)"ffs", -1,
6935 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6936 OPT_FREE | opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00006937# ifdef FEAT_EVAL
6938 set_option_scriptID((char_u *)"ffs", current_SID);
6939# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006940 }
6941
6942 /*
6943 * When 'lisp' option changes include/exclude '-' in
6944 * keyword characters.
6945 */
6946#ifdef FEAT_LISP
6947 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6948 {
6949 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6950 }
6951#endif
6952
6953#ifdef FEAT_TITLE
6954 /* when 'title' changed, may need to change the title; same for 'icon' */
6955 else if ((int *)varp == &p_title)
6956 {
6957 did_set_title(FALSE);
6958 }
6959
6960 else if ((int *)varp == &p_icon)
6961 {
6962 did_set_title(TRUE);
6963 }
6964#endif
6965
6966 else if ((int *)varp == &curbuf->b_changed)
6967 {
6968 if (!value)
6969 save_file_ff(curbuf); /* Buffer is unchanged */
6970#ifdef FEAT_TITLE
6971 need_maketitle = TRUE;
6972#endif
6973#ifdef FEAT_AUTOCMD
6974 modified_was_set = value;
6975#endif
6976 }
6977
6978#ifdef BACKSLASH_IN_FILENAME
6979 else if ((int *)varp == &p_ssl)
6980 {
6981 if (p_ssl)
6982 {
6983 psepc = '/';
6984 psepcN = '\\';
6985 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006986 }
6987 else
6988 {
6989 psepc = '\\';
6990 psepcN = '/';
6991 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992 }
6993
6994 /* need to adjust the file name arguments and buffer names. */
6995 buflist_slash_adjust();
6996 alist_slash_adjust();
6997# ifdef FEAT_EVAL
6998 scriptnames_slash_adjust();
6999# endif
7000 }
7001#endif
7002
7003 /* If 'wrap' is set, set w_leftcol to zero. */
7004 else if ((int *)varp == &curwin->w_p_wrap)
7005 {
7006 if (curwin->w_p_wrap)
7007 curwin->w_leftcol = 0;
7008 }
7009
7010#ifdef FEAT_WINDOWS
7011 else if ((int *)varp == &p_ea)
7012 {
7013 if (p_ea && !old_value)
7014 win_equal(curwin, FALSE, 0);
7015 }
7016#endif
7017
7018 else if ((int *)varp == &p_wiv)
7019 {
7020 /*
7021 * When 'weirdinvert' changed, set/reset 't_xs'.
7022 * Then set 'weirdinvert' according to value of 't_xs'.
7023 */
7024 if (p_wiv && !old_value)
7025 T_XS = (char_u *)"y";
7026 else if (!p_wiv && old_value)
7027 T_XS = empty_option;
7028 p_wiv = (*T_XS != NUL);
7029 }
7030
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007031#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007032 else if ((int *)varp == &p_beval)
7033 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034 if (p_beval == TRUE)
7035 gui_mch_enable_beval_area(balloonEval);
7036 else
7037 gui_mch_disable_beval_area(balloonEval);
7038 }
7039
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007040# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 else if ((int *)varp == &p_acd)
7042 {
7043 if (p_acd && curbuf->b_ffname != NULL
7044 && vim_chdirfile(curbuf->b_ffname) == OK)
7045 shorten_fnames(TRUE);
7046 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007047# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048#endif
7049
7050#ifdef FEAT_DIFF
7051 /* 'diff' */
7052 else if ((int *)varp == &curwin->w_p_diff)
7053 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007054 /* May add or remove the buffer from the list of diff buffers. */
7055 diff_buf_adjust(curwin);
7056# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007057 if (foldmethodIsDiff(curwin))
7058 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007059# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060 }
7061#endif
7062
7063#ifdef USE_IM_CONTROL
7064 /* 'imdisable' */
7065 else if ((int *)varp == &p_imdisable)
7066 {
7067 /* Only de-activate it here, it will be enabled when changing mode. */
7068 if (p_imdisable)
7069 im_set_active(FALSE);
7070 }
7071#endif
7072
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007073#ifdef FEAT_SYN_HL
7074 /* 'spell' */
7075 else if ((int *)varp == &curwin->w_p_spell)
7076 {
7077 if (curwin->w_p_spell)
7078 {
7079 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007080
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007081 if (errmsg != NULL)
7082 EMSG(_(errmsg));
7083 }
7084 }
7085#endif
7086
Bram Moolenaar071d4272004-06-13 20:20:40 +00007087#ifdef FEAT_FKMAP
7088 else if ((int *)varp == &p_altkeymap)
7089 {
7090 if (old_value != p_altkeymap)
7091 {
7092 if (!p_altkeymap)
7093 {
7094 p_hkmap = p_fkmap;
7095 p_fkmap = 0;
7096 }
7097 else
7098 {
7099 p_fkmap = p_hkmap;
7100 p_hkmap = 0;
7101 }
7102 (void)init_chartab();
7103 }
7104 }
7105
7106 /*
7107 * In case some second language keymapping options have changed, check
7108 * and correct the setting in a consistent way.
7109 */
7110
7111 /*
7112 * If hkmap or fkmap are set, reset Arabic keymapping.
7113 */
7114 if ((p_hkmap || p_fkmap) && p_altkeymap)
7115 {
7116 p_altkeymap = p_fkmap;
7117# ifdef FEAT_ARABIC
7118 curwin->w_p_arab = FALSE;
7119# endif
7120 (void)init_chartab();
7121 }
7122
7123 /*
7124 * If hkmap set, reset Farsi keymapping.
7125 */
7126 if (p_hkmap && p_altkeymap)
7127 {
7128 p_altkeymap = 0;
7129 p_fkmap = 0;
7130# ifdef FEAT_ARABIC
7131 curwin->w_p_arab = FALSE;
7132# endif
7133 (void)init_chartab();
7134 }
7135
7136 /*
7137 * If fkmap set, reset Hebrew keymapping.
7138 */
7139 if (p_fkmap && !p_altkeymap)
7140 {
7141 p_altkeymap = 1;
7142 p_hkmap = 0;
7143# ifdef FEAT_ARABIC
7144 curwin->w_p_arab = FALSE;
7145# endif
7146 (void)init_chartab();
7147 }
7148#endif
7149
7150#ifdef FEAT_ARABIC
7151 if ((int *)varp == &curwin->w_p_arab)
7152 {
7153 if (curwin->w_p_arab)
7154 {
7155 /*
7156 * 'arabic' is set, handle various sub-settings.
7157 */
7158 if (!p_tbidi)
7159 {
7160 /* set rightleft mode */
7161 if (!curwin->w_p_rl)
7162 {
7163 curwin->w_p_rl = TRUE;
7164 changed_window_setting();
7165 }
7166
7167 /* Enable Arabic shaping (major part of what Arabic requires) */
7168 if (!p_arshape)
7169 {
7170 p_arshape = TRUE;
7171 redraw_later_clear();
7172 }
7173 }
7174
7175 /* Arabic requires a utf-8 encoding, inform the user if its not
7176 * set. */
7177 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007178 {
7179 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
7181 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007183
7184# ifdef FEAT_MBYTE
7185 /* set 'delcombine' */
7186 p_deco = TRUE;
7187# endif
7188
7189# ifdef FEAT_KEYMAP
7190 /* Force-set the necessary keymap for arabic */
7191 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7192 OPT_LOCAL);
7193# endif
7194# ifdef FEAT_FKMAP
7195 p_altkeymap = 0;
7196 p_hkmap = 0;
7197 p_fkmap = 0;
7198 (void)init_chartab();
7199# endif
7200 }
7201 else
7202 {
7203 /*
7204 * 'arabic' is reset, handle various sub-settings.
7205 */
7206 if (!p_tbidi)
7207 {
7208 /* reset rightleft mode */
7209 if (curwin->w_p_rl)
7210 {
7211 curwin->w_p_rl = FALSE;
7212 changed_window_setting();
7213 }
7214
7215 /* 'arabicshape' isn't reset, it is a global option and
7216 * another window may still need it "on". */
7217 }
7218
7219 /* 'delcombine' isn't reset, it is a global option and another
7220 * window may still want it "on". */
7221
7222# ifdef FEAT_KEYMAP
7223 /* Revert to the default keymap */
7224 curbuf->b_p_iminsert = B_IMODE_NONE;
7225 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7226# endif
7227 }
7228 }
7229#endif
7230
7231 /*
7232 * End of handling side effects for bool options.
7233 */
7234
7235 options[opt_idx].flags |= P_WAS_SET;
7236
7237 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7238 if (curwin->w_curswant != MAXCOL)
7239 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7240 check_redraw(options[opt_idx].flags);
7241
7242 return NULL;
7243}
7244
7245/*
7246 * Set the value of a number option, and take care of side effects.
7247 * Returns NULL for success, or an error message for an error.
7248 */
7249 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007250set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 int opt_idx; /* index in options[] table */
7252 char_u *varp; /* pointer to the option variable */
7253 long value; /* new value */
7254 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007255 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007256 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7257 OPT_MODELINE */
7258{
7259 char_u *errmsg = NULL;
7260 long old_value = *(long *)varp;
7261 long old_Rows = Rows; /* remember old Rows */
7262 long old_Columns = Columns; /* remember old Columns */
7263 long *pp = (long *)varp;
7264
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007265 /* Disallow changing some options from secure mode. */
7266 if ((secure
7267#ifdef HAVE_SANDBOX
7268 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007269#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007270 ) && (options[opt_idx].flags & P_SECURE))
7271 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007272
7273 *pp = value;
7274#ifdef FEAT_EVAL
7275 /* Remember where the option was set. */
7276 options[opt_idx].scriptID = current_SID;
7277#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007278#ifdef FEAT_GUI
7279 need_mouse_correct = TRUE;
7280#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007281
7282 if (curbuf->b_p_sw <= 0)
7283 {
7284 errmsg = e_positive;
7285 curbuf->b_p_sw = curbuf->b_p_ts;
7286 }
7287
7288 /*
7289 * Number options that need some action when changed
7290 */
7291#ifdef FEAT_WINDOWS
7292 if (pp == &p_wh || pp == &p_hh)
7293 {
7294 if (p_wh < 1)
7295 {
7296 errmsg = e_positive;
7297 p_wh = 1;
7298 }
7299 if (p_wmh > p_wh)
7300 {
7301 errmsg = e_winheight;
7302 p_wh = p_wmh;
7303 }
7304 if (p_hh < 0)
7305 {
7306 errmsg = e_positive;
7307 p_hh = 0;
7308 }
7309
7310 /* Change window height NOW */
7311 if (lastwin != firstwin)
7312 {
7313 if (pp == &p_wh && curwin->w_height < p_wh)
7314 win_setheight((int)p_wh);
7315 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7316 win_setheight((int)p_hh);
7317 }
7318 }
7319
7320 /* 'winminheight' */
7321 else if (pp == &p_wmh)
7322 {
7323 if (p_wmh < 0)
7324 {
7325 errmsg = e_positive;
7326 p_wmh = 0;
7327 }
7328 if (p_wmh > p_wh)
7329 {
7330 errmsg = e_winheight;
7331 p_wmh = p_wh;
7332 }
7333 win_setminheight();
7334 }
7335
7336# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007337 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007338 {
7339 if (p_wiw < 1)
7340 {
7341 errmsg = e_positive;
7342 p_wiw = 1;
7343 }
7344 if (p_wmw > p_wiw)
7345 {
7346 errmsg = e_winwidth;
7347 p_wiw = p_wmw;
7348 }
7349
7350 /* Change window width NOW */
7351 if (lastwin != firstwin && curwin->w_width < p_wiw)
7352 win_setwidth((int)p_wiw);
7353 }
7354
7355 /* 'winminwidth' */
7356 else if (pp == &p_wmw)
7357 {
7358 if (p_wmw < 0)
7359 {
7360 errmsg = e_positive;
7361 p_wmw = 0;
7362 }
7363 if (p_wmw > p_wiw)
7364 {
7365 errmsg = e_winwidth;
7366 p_wmw = p_wiw;
7367 }
7368 win_setminheight();
7369 }
7370# endif
7371
7372#endif
7373
7374#ifdef FEAT_WINDOWS
7375 /* (re)set last window status line */
7376 else if (pp == &p_ls)
7377 {
7378 last_status(FALSE);
7379 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007380
7381 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007382 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007383 {
7384 shell_new_rows(); /* recompute window positions and heights */
7385 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007386#endif
7387
7388#ifdef FEAT_GUI
7389 else if (pp == &p_linespace)
7390 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007391 /* Recompute gui.char_height and resize the Vim window to keep the
7392 * same number of lines. */
7393 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007394 gui_set_shellsize(FALSE, FALSE);
7395 }
7396#endif
7397
7398#ifdef FEAT_FOLDING
7399 /* 'foldlevel' */
7400 else if (pp == &curwin->w_p_fdl)
7401 {
7402 if (curwin->w_p_fdl < 0)
7403 curwin->w_p_fdl = 0;
7404 newFoldLevel();
7405 }
7406
7407 /* 'foldminlevel' */
7408 else if (pp == &curwin->w_p_fml)
7409 {
7410 foldUpdateAll(curwin);
7411 }
7412
7413 /* 'foldnestmax' */
7414 else if (pp == &curwin->w_p_fdn)
7415 {
7416 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7417 foldUpdateAll(curwin);
7418 }
7419
7420 /* 'foldcolumn' */
7421 else if (pp == &curwin->w_p_fdc)
7422 {
7423 if (curwin->w_p_fdc < 0)
7424 {
7425 errmsg = e_positive;
7426 curwin->w_p_fdc = 0;
7427 }
7428 else if (curwin->w_p_fdc > 12)
7429 {
7430 errmsg = e_invarg;
7431 curwin->w_p_fdc = 12;
7432 }
7433 }
7434
7435 /* 'shiftwidth' or 'tabstop' */
7436 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7437 {
7438 if (foldmethodIsIndent(curwin))
7439 foldUpdateAll(curwin);
7440 }
7441#endif /* FEAT_FOLDING */
7442
7443 else if (pp == &curbuf->b_p_iminsert)
7444 {
7445 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7446 {
7447 errmsg = e_invarg;
7448 curbuf->b_p_iminsert = B_IMODE_NONE;
7449 }
7450 p_iminsert = curbuf->b_p_iminsert;
7451 if (termcap_active) /* don't do this in the alternate screen */
7452 showmode();
7453#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7454 /* Show/unshow value of 'keymap' in status lines. */
7455 status_redraw_curbuf();
7456#endif
7457 }
7458
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007459 else if (pp == &p_window)
7460 {
7461 if (p_window < 1)
7462 p_window = 1;
7463 else if (p_window >= Rows)
7464 p_window = Rows - 1;
7465 }
7466
Bram Moolenaar071d4272004-06-13 20:20:40 +00007467 else if (pp == &curbuf->b_p_imsearch)
7468 {
7469 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7470 {
7471 errmsg = e_invarg;
7472 curbuf->b_p_imsearch = B_IMODE_NONE;
7473 }
7474 p_imsearch = curbuf->b_p_imsearch;
7475 }
7476
7477#ifdef FEAT_TITLE
7478 /* if 'titlelen' has changed, redraw the title */
7479 else if (pp == &p_titlelen)
7480 {
7481 if (p_titlelen < 0)
7482 {
7483 errmsg = e_positive;
7484 p_titlelen = 85;
7485 }
7486 if (starting != NO_SCREEN && old_value != p_titlelen)
7487 need_maketitle = TRUE;
7488 }
7489#endif
7490
7491 /* if p_ch changed value, change the command line height */
7492 else if (pp == &p_ch)
7493 {
7494 if (p_ch < 1)
7495 {
7496 errmsg = e_positive;
7497 p_ch = 1;
7498 }
7499
7500 /* Only compute the new window layout when startup has been
7501 * completed. Otherwise the frame sizes may be wrong. */
7502 if (p_ch != old_value && full_screen
7503#ifdef FEAT_GUI
7504 && !gui.starting
7505#endif
7506 )
7507 command_height(old_value);
7508 }
7509
7510 /* when 'updatecount' changes from zero to non-zero, open swap files */
7511 else if (pp == &p_uc)
7512 {
7513 if (p_uc < 0)
7514 {
7515 errmsg = e_positive;
7516 p_uc = 100;
7517 }
7518 if (p_uc && !old_value)
7519 ml_open_files();
7520 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007521#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007522 else if (pp == &p_mzq)
7523 mzvim_reset_timer();
7524#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525
7526 /* sync undo before 'undolevels' changes */
7527 else if (pp == &p_ul)
7528 {
7529 /* use the old value, otherwise u_sync() may not work properly */
7530 p_ul = old_value;
7531 u_sync();
7532 p_ul = value;
7533 }
7534
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007535#ifdef FEAT_LINEBREAK
7536 /* 'numberwidth' must be positive */
7537 else if (pp == &curwin->w_p_nuw)
7538 {
7539 if (curwin->w_p_nuw < 1)
7540 {
7541 errmsg = e_positive;
7542 curwin->w_p_nuw = 1;
7543 }
7544 if (curwin->w_p_nuw > 10)
7545 {
7546 errmsg = e_invarg;
7547 curwin->w_p_nuw = 10;
7548 }
7549 curwin->w_nrwidth_line_count = 0;
7550 }
7551#endif
7552
Bram Moolenaar071d4272004-06-13 20:20:40 +00007553 /*
7554 * Check the bounds for numeric options here
7555 */
7556 if (Rows < min_rows() && full_screen)
7557 {
7558 if (errbuf != NULL)
7559 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007560 vim_snprintf((char *)errbuf, errbuflen,
7561 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007562 errmsg = errbuf;
7563 }
7564 Rows = min_rows();
7565 }
7566 if (Columns < MIN_COLUMNS && full_screen)
7567 {
7568 if (errbuf != NULL)
7569 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007570 vim_snprintf((char *)errbuf, errbuflen,
7571 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007572 errmsg = errbuf;
7573 }
7574 Columns = MIN_COLUMNS;
7575 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007576 /* Limit the values to avoid an overflow in Rows * Columns. */
7577 if (Columns > 10000)
7578 Columns = 10000;
7579 if (Rows > 1000)
7580 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581
7582#ifdef DJGPP
7583 /* avoid a crash by checking for a too large value of 'columns' */
7584 if (old_Columns != Columns && full_screen && term_console)
7585 mch_check_columns();
7586#endif
7587
7588 /*
7589 * If the screen (shell) height has been changed, assume it is the
7590 * physical screenheight.
7591 */
7592 if (old_Rows != Rows || old_Columns != Columns)
7593 {
7594 /* Changing the screen size is not allowed while updating the screen. */
7595 if (updating_screen)
7596 *pp = old_value;
7597 else if (full_screen
7598#ifdef FEAT_GUI
7599 && !gui.starting
7600#endif
7601 )
7602 set_shellsize((int)Columns, (int)Rows, TRUE);
7603 else
7604 {
7605 /* Postpone the resizing; check the size and cmdline position for
7606 * messages. */
7607 check_shellsize();
7608 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7609 cmdline_row = Rows - p_ch;
7610 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007611 if (p_window >= Rows)
7612 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007613 }
7614
7615 if (curbuf->b_p_sts < 0)
7616 {
7617 errmsg = e_positive;
7618 curbuf->b_p_sts = 0;
7619 }
7620 if (curbuf->b_p_ts <= 0)
7621 {
7622 errmsg = e_positive;
7623 curbuf->b_p_ts = 8;
7624 }
7625 if (curbuf->b_p_tw < 0)
7626 {
7627 errmsg = e_positive;
7628 curbuf->b_p_tw = 0;
7629 }
7630 if (p_tm < 0)
7631 {
7632 errmsg = e_positive;
7633 p_tm = 0;
7634 }
7635 if ((curwin->w_p_scr <= 0
7636 || (curwin->w_p_scr > curwin->w_height
7637 && curwin->w_height > 0))
7638 && full_screen)
7639 {
7640 if (pp == &(curwin->w_p_scr))
7641 {
7642 if (curwin->w_p_scr != 0)
7643 errmsg = e_scroll;
7644 win_comp_scroll(curwin);
7645 }
7646 /* If 'scroll' became invalid because of a side effect silently adjust
7647 * it. */
7648 else if (curwin->w_p_scr <= 0)
7649 curwin->w_p_scr = 1;
7650 else /* curwin->w_p_scr > curwin->w_height */
7651 curwin->w_p_scr = curwin->w_height;
7652 }
7653 if (p_report < 0)
7654 {
7655 errmsg = e_positive;
7656 p_report = 1;
7657 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007658 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 {
7660 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7661 p_sj = Rows / 2;
7662 else
7663 {
7664 errmsg = e_scroll;
7665 p_sj = 1;
7666 }
7667 }
7668 if (p_so < 0 && full_screen)
7669 {
7670 errmsg = e_scroll;
7671 p_so = 0;
7672 }
7673 if (p_siso < 0 && full_screen)
7674 {
7675 errmsg = e_positive;
7676 p_siso = 0;
7677 }
7678#ifdef FEAT_CMDWIN
7679 if (p_cwh < 1)
7680 {
7681 errmsg = e_positive;
7682 p_cwh = 1;
7683 }
7684#endif
7685 if (p_ut < 0)
7686 {
7687 errmsg = e_positive;
7688 p_ut = 2000;
7689 }
7690 if (p_ss < 0)
7691 {
7692 errmsg = e_positive;
7693 p_ss = 0;
7694 }
7695
7696 /* May set global value for local option. */
7697 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7698 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7699
7700 options[opt_idx].flags |= P_WAS_SET;
7701
7702 comp_col(); /* in case 'columns' or 'ls' changed */
7703 if (curwin->w_curswant != MAXCOL)
7704 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7705 check_redraw(options[opt_idx].flags);
7706
7707 return errmsg;
7708}
7709
7710/*
7711 * Called after an option changed: check if something needs to be redrawn.
7712 */
7713 static void
7714check_redraw(flags)
7715 long_u flags;
7716{
7717 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7718 int clear = (flags & P_RCLR) == P_RCLR;
7719 int all = ((flags & P_RALL) == P_RALL || clear);
7720
7721#ifdef FEAT_WINDOWS
7722 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7723 status_redraw_all();
7724#endif
7725
7726 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7727 changed_window_setting();
7728 if (flags & P_RBUF)
7729 redraw_curbuf_later(NOT_VALID);
7730 if (clear)
7731 redraw_all_later(CLEAR);
7732 else if (all)
7733 redraw_all_later(NOT_VALID);
7734}
7735
7736/*
7737 * Find index for option 'arg'.
7738 * Return -1 if not found.
7739 */
7740 static int
7741findoption(arg)
7742 char_u *arg;
7743{
7744 int opt_idx;
7745 char *s, *p;
7746 static short quick_tab[27] = {0, 0}; /* quick access table */
7747 int is_term_opt;
7748
7749 /*
7750 * For first call: Initialize the quick-access table.
7751 * It contains the index for the first option that starts with a certain
7752 * letter. There are 26 letters, plus the first "t_" option.
7753 */
7754 if (quick_tab[1] == 0)
7755 {
7756 p = options[0].fullname;
7757 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7758 {
7759 if (s[0] != p[0])
7760 {
7761 if (s[0] == 't' && s[1] == '_')
7762 quick_tab[26] = opt_idx;
7763 else
7764 quick_tab[CharOrdLow(s[0])] = opt_idx;
7765 }
7766 p = s;
7767 }
7768 }
7769
7770 /*
7771 * Check for name starting with an illegal character.
7772 */
7773#ifdef EBCDIC
7774 if (!islower(arg[0]))
7775#else
7776 if (arg[0] < 'a' || arg[0] > 'z')
7777#endif
7778 return -1;
7779
7780 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7781 if (is_term_opt)
7782 opt_idx = quick_tab[26];
7783 else
7784 opt_idx = quick_tab[CharOrdLow(arg[0])];
7785 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7786 {
7787 if (STRCMP(arg, s) == 0) /* match full name */
7788 break;
7789 }
7790 if (s == NULL && !is_term_opt)
7791 {
7792 opt_idx = quick_tab[CharOrdLow(arg[0])];
7793 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7794 {
7795 s = options[opt_idx].shortname;
7796 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7797 break;
7798 s = NULL;
7799 }
7800 }
7801 if (s == NULL)
7802 opt_idx = -1;
7803 return opt_idx;
7804}
7805
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007806#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007807/*
7808 * Get the value for an option.
7809 *
7810 * Returns:
7811 * Number or Toggle option: 1, *numval gets value.
7812 * String option: 0, *stringval gets allocated string.
7813 * Hidden Number or Toggle option: -1.
7814 * hidden String option: -2.
7815 * unknown option: -3.
7816 */
7817 int
7818get_option_value(name, numval, stringval, opt_flags)
7819 char_u *name;
7820 long *numval;
7821 char_u **stringval; /* NULL when only checking existance */
7822 int opt_flags;
7823{
7824 int opt_idx;
7825 char_u *varp;
7826
7827 opt_idx = findoption(name);
7828 if (opt_idx < 0) /* unknown option */
7829 return -3;
7830
7831 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7832
7833 if (options[opt_idx].flags & P_STRING)
7834 {
7835 if (varp == NULL) /* hidden option */
7836 return -2;
7837 if (stringval != NULL)
7838 {
7839#ifdef FEAT_CRYPT
7840 /* never return the value of the crypt key */
7841 if ((char_u **)varp == &curbuf->b_p_key)
7842 *stringval = vim_strsave((char_u *)"*****");
7843 else
7844#endif
7845 *stringval = vim_strsave(*(char_u **)(varp));
7846 }
7847 return 0;
7848 }
7849
7850 if (varp == NULL) /* hidden option */
7851 return -1;
7852 if (options[opt_idx].flags & P_NUM)
7853 *numval = *(long *)varp;
7854 else
7855 {
7856 /* Special case: 'modified' is b_changed, but we also want to consider
7857 * it set when 'ff' or 'fenc' changed. */
7858 if ((int *)varp == &curbuf->b_changed)
7859 *numval = curbufIsChanged();
7860 else
7861 *numval = *(int *)varp;
7862 }
7863 return 1;
7864}
7865#endif
7866
7867/*
7868 * Set the value of option "name".
7869 * Use "string" for string options, use "number" for other options.
7870 */
7871 void
7872set_option_value(name, number, string, opt_flags)
7873 char_u *name;
7874 long number;
7875 char_u *string;
7876 int opt_flags; /* OPT_LOCAL or 0 (both) */
7877{
7878 int opt_idx;
7879 char_u *varp;
7880 int flags;
7881
7882 opt_idx = findoption(name);
7883 if (opt_idx == -1)
7884 EMSG2(_("E355: Unknown option: %s"), name);
7885 else
7886 {
7887 flags = options[opt_idx].flags;
7888#ifdef HAVE_SANDBOX
7889 /* Disallow changing some options in the sandbox */
7890 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007891 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007893 return;
7894 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007896 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007897 set_string_option(opt_idx, string, opt_flags);
7898 else
7899 {
7900 varp = get_varp(&options[opt_idx]);
7901 if (varp != NULL) /* hidden option is not changed */
7902 {
7903 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00007904 (void)set_num_option(opt_idx, varp, number,
7905 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007907 (void)set_bool_option(opt_idx, varp, (int)number,
7908 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909 }
7910 }
7911 }
7912}
7913
7914/*
7915 * Get the terminal code for a terminal option.
7916 * Returns NULL when not found.
7917 */
7918 char_u *
7919get_term_code(tname)
7920 char_u *tname;
7921{
7922 int opt_idx;
7923 char_u *varp;
7924
7925 if (tname[0] != 't' || tname[1] != '_' ||
7926 tname[2] == NUL || tname[3] == NUL)
7927 return NULL;
7928 if ((opt_idx = findoption(tname)) >= 0)
7929 {
7930 varp = get_varp(&(options[opt_idx]));
7931 if (varp != NULL)
7932 varp = *(char_u **)(varp);
7933 return varp;
7934 }
7935 return find_termcode(tname + 2);
7936}
7937
7938 char_u *
7939get_highlight_default()
7940{
7941 int i;
7942
7943 i = findoption((char_u *)"hl");
7944 if (i >= 0)
7945 return options[i].def_val[VI_DEFAULT];
7946 return (char_u *)NULL;
7947}
7948
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007949#if defined(FEAT_MBYTE) || defined(PROTO)
7950 char_u *
7951get_encoding_default()
7952{
7953 int i;
7954
7955 i = findoption((char_u *)"enc");
7956 if (i >= 0)
7957 return options[i].def_val[VI_DEFAULT];
7958 return (char_u *)NULL;
7959}
7960#endif
7961
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962/*
7963 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7964 */
7965 static int
7966find_key_option(arg)
7967 char_u *arg;
7968{
7969 int key;
7970 int modifiers;
7971
7972 /*
7973 * Don't use get_special_key_code() for t_xx, we don't want it to call
7974 * add_termcap_entry().
7975 */
7976 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7977 key = TERMCAP2KEY(arg[2], arg[3]);
7978 else
7979 {
7980 --arg; /* put arg at the '<' */
7981 modifiers = 0;
7982 key = find_special_key(&arg, &modifiers, TRUE);
7983 if (modifiers) /* can't handle modifiers here */
7984 key = 0;
7985 }
7986 return key;
7987}
7988
7989/*
7990 * if 'all' == 0: show changed options
7991 * if 'all' == 1: show all normal options
7992 * if 'all' == 2: show all terminal options
7993 */
7994 static void
7995showoptions(all, opt_flags)
7996 int all;
7997 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7998{
7999 struct vimoption *p;
8000 int col;
8001 int isterm;
8002 char_u *varp;
8003 struct vimoption **items;
8004 int item_count;
8005 int run;
8006 int row, rows;
8007 int cols;
8008 int i;
8009 int len;
8010
8011#define INC 20
8012#define GAP 3
8013
8014 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8015 PARAM_COUNT));
8016 if (items == NULL)
8017 return;
8018
8019 /* Highlight title */
8020 if (all == 2)
8021 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8022 else if (opt_flags & OPT_GLOBAL)
8023 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8024 else if (opt_flags & OPT_LOCAL)
8025 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8026 else
8027 MSG_PUTS_TITLE(_("\n--- Options ---"));
8028
8029 /*
8030 * do the loop two times:
8031 * 1. display the short items
8032 * 2. display the long items (only strings and numbers)
8033 */
8034 for (run = 1; run <= 2 && !got_int; ++run)
8035 {
8036 /*
8037 * collect the items in items[]
8038 */
8039 item_count = 0;
8040 for (p = &options[0]; p->fullname != NULL; p++)
8041 {
8042 varp = NULL;
8043 isterm = istermoption(p);
8044 if (opt_flags != 0)
8045 {
8046 if (p->indir != PV_NONE && !isterm)
8047 varp = get_varp_scope(p, opt_flags);
8048 }
8049 else
8050 varp = get_varp(p);
8051 if (varp != NULL
8052 && ((all == 2 && isterm)
8053 || (all == 1 && !isterm)
8054 || (all == 0 && !optval_default(p, varp))))
8055 {
8056 if (p->flags & P_BOOL)
8057 len = 1; /* a toggle option fits always */
8058 else
8059 {
8060 option_value2string(p, opt_flags);
8061 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8062 }
8063 if ((len <= INC - GAP && run == 1) ||
8064 (len > INC - GAP && run == 2))
8065 items[item_count++] = p;
8066 }
8067 }
8068
8069 /*
8070 * display the items
8071 */
8072 if (run == 1)
8073 {
8074 cols = (Columns + GAP - 3) / INC;
8075 if (cols == 0)
8076 cols = 1;
8077 rows = (item_count + cols - 1) / cols;
8078 }
8079 else /* run == 2 */
8080 rows = item_count;
8081 for (row = 0; row < rows && !got_int; ++row)
8082 {
8083 msg_putchar('\n'); /* go to next line */
8084 if (got_int) /* 'q' typed in more */
8085 break;
8086 col = 0;
8087 for (i = row; i < item_count; i += rows)
8088 {
8089 msg_col = col; /* make columns */
8090 showoneopt(items[i], opt_flags);
8091 col += INC;
8092 }
8093 out_flush();
8094 ui_breakcheck();
8095 }
8096 }
8097 vim_free(items);
8098}
8099
8100/*
8101 * Return TRUE if option "p" has its default value.
8102 */
8103 static int
8104optval_default(p, varp)
8105 struct vimoption *p;
8106 char_u *varp;
8107{
8108 int dvi;
8109
8110 if (varp == NULL)
8111 return TRUE; /* hidden option is always at default */
8112 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8113 if (p->flags & P_NUM)
8114 return (*(long *)varp == (long)p->def_val[dvi]);
8115 if (p->flags & P_BOOL)
8116 /* the cast to long is required for Manx C */
8117 return (*(int *)varp == (int)(long)p->def_val[dvi]);
8118 /* P_STRING */
8119 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8120}
8121
8122/*
8123 * showoneopt: show the value of one option
8124 * must not be called with a hidden option!
8125 */
8126 static void
8127showoneopt(p, opt_flags)
8128 struct vimoption *p;
8129 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8130{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008131 char_u *varp;
8132 int save_silent = silent_mode;
8133
8134 silent_mode = FALSE;
8135 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136
8137 varp = get_varp_scope(p, opt_flags);
8138
8139 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8140 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8141 ? !curbufIsChanged() : !*(int *)varp))
8142 MSG_PUTS("no");
8143 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8144 MSG_PUTS("--");
8145 else
8146 MSG_PUTS(" ");
8147 MSG_PUTS(p->fullname);
8148 if (!(p->flags & P_BOOL))
8149 {
8150 msg_putchar('=');
8151 /* put value string in NameBuff */
8152 option_value2string(p, opt_flags);
8153 msg_outtrans(NameBuff);
8154 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008155
8156 silent_mode = save_silent;
8157 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158}
8159
8160/*
8161 * Write modified options as ":set" commands to a file.
8162 *
8163 * There are three values for "opt_flags":
8164 * OPT_GLOBAL: Write global option values and fresh values of
8165 * buffer-local options (used for start of a session
8166 * file).
8167 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8168 * curwin (used for a vimrc file).
8169 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8170 * and local values for window-local options of
8171 * curwin. Local values are also written when at the
8172 * default value, because a modeline or autocommand
8173 * may have set them when doing ":edit file" and the
8174 * user has set them back at the default or fresh
8175 * value.
8176 * When "local_only" is TRUE, don't write fresh
8177 * values, only local values (for ":mkview").
8178 * (fresh value = value used for a new buffer or window for a local option).
8179 *
8180 * Return FAIL on error, OK otherwise.
8181 */
8182 int
8183makeset(fd, opt_flags, local_only)
8184 FILE *fd;
8185 int opt_flags;
8186 int local_only;
8187{
8188 struct vimoption *p;
8189 char_u *varp; /* currently used value */
8190 char_u *varp_fresh; /* local value */
8191 char_u *varp_local = NULL; /* fresh value */
8192 char *cmd;
8193 int round;
8194
8195 /*
8196 * The options that don't have a default (terminal name, columns, lines)
8197 * are never written. Terminal options are also not written.
8198 */
8199 for (p = &options[0]; !istermoption(p); p++)
8200 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
8201 {
8202 /* skip global option when only doing locals */
8203 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8204 continue;
8205
8206 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8207 * file, they are always buffer-specific. */
8208 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8209 continue;
8210
8211 /* Global values are only written when not at the default value. */
8212 varp = get_varp_scope(p, opt_flags);
8213 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8214 continue;
8215
8216 round = 2;
8217 if (p->indir != PV_NONE)
8218 {
8219 if (p->var == VAR_WIN)
8220 {
8221 /* skip window-local option when only doing globals */
8222 if (!(opt_flags & OPT_LOCAL))
8223 continue;
8224 /* When fresh value of window-local option is not at the
8225 * default, need to write it too. */
8226 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8227 {
8228 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8229 if (!optval_default(p, varp_fresh))
8230 {
8231 round = 1;
8232 varp_local = varp;
8233 varp = varp_fresh;
8234 }
8235 }
8236 }
8237 }
8238
8239 /* Round 1: fresh value for window-local options.
8240 * Round 2: other values */
8241 for ( ; round <= 2; varp = varp_local, ++round)
8242 {
8243 if (round == 1 || (opt_flags & OPT_GLOBAL))
8244 cmd = "set";
8245 else
8246 cmd = "setlocal";
8247
8248 if (p->flags & P_BOOL)
8249 {
8250 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8251 return FAIL;
8252 }
8253 else if (p->flags & P_NUM)
8254 {
8255 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8256 return FAIL;
8257 }
8258 else /* P_STRING */
8259 {
8260 /* Don't set 'syntax' and 'filetype' again if the value is
8261 * already right, avoids reloading the syntax file. */
8262 if (p->indir == PV_SYN || p->indir == PV_FT)
8263 {
8264 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8265 *(char_u **)(varp)) < 0
8266 || put_eol(fd) < 0)
8267 return FAIL;
8268 }
8269 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8270 (p->flags & P_EXPAND) != 0) == FAIL)
8271 return FAIL;
8272 if (p->indir == PV_SYN || p->indir == PV_FT)
8273 {
8274 if (put_line(fd, "endif") == FAIL)
8275 return FAIL;
8276 }
8277 }
8278 }
8279 }
8280 return OK;
8281}
8282
8283#if defined(FEAT_FOLDING) || defined(PROTO)
8284/*
8285 * Generate set commands for the local fold options only. Used when
8286 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8287 */
8288 int
8289makefoldset(fd)
8290 FILE *fd;
8291{
8292 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8293# ifdef FEAT_EVAL
8294 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8295 == FAIL
8296# endif
8297 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8298 == FAIL
8299 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8300 == FAIL
8301 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8302 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8303 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8304 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8305 )
8306 return FAIL;
8307
8308 return OK;
8309}
8310#endif
8311
8312 static int
8313put_setstring(fd, cmd, name, valuep, expand)
8314 FILE *fd;
8315 char *cmd;
8316 char *name;
8317 char_u **valuep;
8318 int expand;
8319{
8320 char_u *s;
8321 char_u buf[MAXPATHL];
8322
8323 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8324 return FAIL;
8325 if (*valuep != NULL)
8326 {
8327 /* Output 'pastetoggle' as key names. For other
8328 * options some characters have to be escaped with
8329 * CTRL-V or backslash */
8330 if (valuep == &p_pt)
8331 {
8332 s = *valuep;
8333 while (*s != NUL)
8334 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8335 return FAIL;
8336 }
8337 else if (expand)
8338 {
8339 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8340 if (put_escstr(fd, buf, 2) == FAIL)
8341 return FAIL;
8342 }
8343 else if (put_escstr(fd, *valuep, 2) == FAIL)
8344 return FAIL;
8345 }
8346 if (put_eol(fd) < 0)
8347 return FAIL;
8348 return OK;
8349}
8350
8351 static int
8352put_setnum(fd, cmd, name, valuep)
8353 FILE *fd;
8354 char *cmd;
8355 char *name;
8356 long *valuep;
8357{
8358 long wc;
8359
8360 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8361 return FAIL;
8362 if (wc_use_keyname((char_u *)valuep, &wc))
8363 {
8364 /* print 'wildchar' and 'wildcharm' as a key name */
8365 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8366 return FAIL;
8367 }
8368 else if (fprintf(fd, "%ld", *valuep) < 0)
8369 return FAIL;
8370 if (put_eol(fd) < 0)
8371 return FAIL;
8372 return OK;
8373}
8374
8375 static int
8376put_setbool(fd, cmd, name, value)
8377 FILE *fd;
8378 char *cmd;
8379 char *name;
8380 int value;
8381{
8382 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8383 || put_eol(fd) < 0)
8384 return FAIL;
8385 return OK;
8386}
8387
8388/*
8389 * Clear all the terminal options.
8390 * If the option has been allocated, free the memory.
8391 * Terminal options are never hidden or indirect.
8392 */
8393 void
8394clear_termoptions()
8395{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 /*
8397 * Reset a few things before clearing the old options. This may cause
8398 * outputting a few things that the terminal doesn't understand, but the
8399 * screen will be cleared later, so this is OK.
8400 */
8401#ifdef FEAT_MOUSE_TTY
8402 mch_setmouse(FALSE); /* switch mouse off */
8403#endif
8404#ifdef FEAT_TITLE
8405 mch_restore_title(3); /* restore window titles */
8406#endif
8407#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8408 /* When starting the GUI close the display opened for the clipboard.
8409 * After restoring the title, because that will need the display. */
8410 if (gui.starting)
8411 clear_xterm_clip();
8412#endif
8413#ifdef WIN3264
8414 /*
8415 * Check if this is allowed now.
8416 */
8417 if (can_end_termcap_mode(FALSE) == TRUE)
8418#endif
8419 stoptermcap(); /* stop termcap mode */
8420
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008421 free_termoptions();
8422}
8423
8424 void
8425free_termoptions()
8426{
8427 struct vimoption *p;
8428
Bram Moolenaar071d4272004-06-13 20:20:40 +00008429 for (p = &options[0]; p->fullname != NULL; p++)
8430 if (istermoption(p))
8431 {
8432 if (p->flags & P_ALLOCED)
8433 free_string_option(*(char_u **)(p->var));
8434 if (p->flags & P_DEF_ALLOCED)
8435 free_string_option(p->def_val[VI_DEFAULT]);
8436 *(char_u **)(p->var) = empty_option;
8437 p->def_val[VI_DEFAULT] = empty_option;
8438 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8439 }
8440 clear_termcodes();
8441}
8442
8443/*
8444 * Set the terminal option defaults to the current value.
8445 * Used after setting the terminal name.
8446 */
8447 void
8448set_term_defaults()
8449{
8450 struct vimoption *p;
8451
8452 for (p = &options[0]; p->fullname != NULL; p++)
8453 {
8454 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8455 {
8456 if (p->flags & P_DEF_ALLOCED)
8457 {
8458 free_string_option(p->def_val[VI_DEFAULT]);
8459 p->flags &= ~P_DEF_ALLOCED;
8460 }
8461 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8462 if (p->flags & P_ALLOCED)
8463 {
8464 p->flags |= P_DEF_ALLOCED;
8465 p->flags &= ~P_ALLOCED; /* don't free the value now */
8466 }
8467 }
8468 }
8469}
8470
8471/*
8472 * return TRUE if 'p' starts with 't_'
8473 */
8474 static int
8475istermoption(p)
8476 struct vimoption *p;
8477{
8478 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8479}
8480
8481/*
8482 * Compute columns for ruler and shown command. 'sc_col' is also used to
8483 * decide what the maximum length of a message on the status line can be.
8484 * If there is a status line for the last window, 'sc_col' is independent
8485 * of 'ru_col'.
8486 */
8487
8488#define COL_RULER 17 /* columns needed by standard ruler */
8489
8490 void
8491comp_col()
8492{
8493#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8494 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8495
8496 sc_col = 0;
8497 ru_col = 0;
8498 if (p_ru)
8499 {
8500#ifdef FEAT_STL_OPT
8501 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8502#else
8503 ru_col = COL_RULER + 1;
8504#endif
8505 /* no last status line, adjust sc_col */
8506 if (!last_has_status)
8507 sc_col = ru_col;
8508 }
8509 if (p_sc)
8510 {
8511 sc_col += SHOWCMD_COLS;
8512 if (!p_ru || last_has_status) /* no need for separating space */
8513 ++sc_col;
8514 }
8515 sc_col = Columns - sc_col;
8516 ru_col = Columns - ru_col;
8517 if (sc_col <= 0) /* screen too narrow, will become a mess */
8518 sc_col = 1;
8519 if (ru_col <= 0)
8520 ru_col = 1;
8521#else
8522 sc_col = Columns;
8523 ru_col = Columns;
8524#endif
8525}
8526
8527/*
8528 * Get pointer to option variable, depending on local or global scope.
8529 */
8530 static char_u *
8531get_varp_scope(p, opt_flags)
8532 struct vimoption *p;
8533 int opt_flags;
8534{
8535 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8536 {
8537 if (p->var == VAR_WIN)
8538 return (char_u *)GLOBAL_WO(get_varp(p));
8539 return p->var;
8540 }
8541 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
8542 {
8543 switch ((int)p->indir)
8544 {
8545#ifdef FEAT_QUICKFIX
8546 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
8547 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
8548 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
8549#endif
8550 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
8551 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
8552 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
8553 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
8554 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
8555#ifdef FEAT_FIND_ID
8556 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
8557 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
8558#endif
8559#ifdef FEAT_INS_EXPAND
8560 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
8561 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
8562#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008563#ifdef FEAT_STL_OPT
8564 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
8565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008566 }
8567 return NULL; /* "cannot happen" */
8568 }
8569 return get_varp(p);
8570}
8571
8572/*
8573 * Get pointer to option variable.
8574 */
8575 static char_u *
8576get_varp(p)
8577 struct vimoption *p;
8578{
8579 /* hidden option, always return NULL */
8580 if (p->var == NULL)
8581 return NULL;
8582
8583 switch ((int)p->indir)
8584 {
8585 case PV_NONE: return p->var;
8586
8587 /* global option with local value: use local value if it's been set */
8588 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
8589 ? (char_u *)&curbuf->b_p_ep : p->var;
8590 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
8591 ? (char_u *)&curbuf->b_p_kp : p->var;
8592 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
8593 ? (char_u *)&(curbuf->b_p_path) : p->var;
8594 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
8595 ? (char_u *)&(curbuf->b_p_ar) : p->var;
8596 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
8597 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8598#ifdef FEAT_FIND_ID
8599 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
8600 ? (char_u *)&(curbuf->b_p_def) : p->var;
8601 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
8602 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8603#endif
8604#ifdef FEAT_INS_EXPAND
8605 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
8606 ? (char_u *)&(curbuf->b_p_dict) : p->var;
8607 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
8608 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8609#endif
8610#ifdef FEAT_QUICKFIX
8611 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
8612 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8613 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
8614 ? (char_u *)&(curbuf->b_p_mp) : p->var;
8615 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8616 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8617#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008618#ifdef FEAT_STL_OPT
8619 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8620 ? (char_u *)&(curwin->w_p_stl) : p->var;
8621#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622
8623#ifdef FEAT_ARABIC
8624 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8625#endif
8626 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008627#ifdef FEAT_SYN_HL
8628 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008630#ifdef FEAT_DIFF
8631 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8632#endif
8633#ifdef FEAT_FOLDING
8634 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8635 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8636 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8637 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8638 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8639 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8640 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8641# ifdef FEAT_EVAL
8642 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8643 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8644# endif
8645 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8646#endif
8647 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008648#ifdef FEAT_LINEBREAK
8649 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008651#if defined(FEAT_WINDOWS)
8652 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8653#endif
8654#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8655 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8656#endif
8657#ifdef FEAT_RIGHTLEFT
8658 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8659 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8660#endif
8661 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8662 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8663#ifdef FEAT_LINEBREAK
8664 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8665#endif
8666#ifdef FEAT_SCROLLBIND
8667 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8668#endif
8669
8670 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8671 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8672#ifdef FEAT_MBYTE
8673 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8674#endif
8675#if defined(FEAT_QUICKFIX)
8676 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8677 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8678#endif
8679 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8680 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8681#ifdef FEAT_CINDENT
8682 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8683 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8684 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8685#endif
8686#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8687 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8688#endif
8689#ifdef FEAT_COMMENTS
8690 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8691#endif
8692#ifdef FEAT_FOLDING
8693 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8694#endif
8695#ifdef FEAT_INS_EXPAND
8696 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8697#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008698#ifdef FEAT_COMPL_FUNC
8699 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008700 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008702 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8703 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8704#ifdef FEAT_MBYTE
8705 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8706#endif
8707 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8708#ifdef FEAT_AUTOCMD
8709 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8710#endif
8711 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008712 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008713 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8714 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8715 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8716 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8717#ifdef FEAT_FIND_ID
8718# ifdef FEAT_EVAL
8719 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8720# endif
8721#endif
8722#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8723 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8724 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8725#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00008726#if defined(FEAT_EVAL)
8727 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
8728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729#ifdef FEAT_CRYPT
8730 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8731#endif
8732#ifdef FEAT_LISP
8733 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8734#endif
8735 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8736 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8737 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8738 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8739 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8740#ifdef FEAT_OSFILETYPE
8741 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8742#endif
8743 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008744#ifdef FEAT_TEXTOBJ
8745 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8748#ifdef FEAT_SMARTINDENT
8749 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8750#endif
8751#ifndef SHORT_FNAME
8752 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8753#endif
8754 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8755#ifdef FEAT_SEARCHPATH
8756 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8757#endif
8758 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8759#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008760 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008762 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008763 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008764 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765#endif
8766 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8767 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8768 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8769 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8770 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8771#ifdef FEAT_KEYMAP
8772 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8773#endif
8774 default: EMSG(_("E356: get_varp ERROR"));
8775 }
8776 /* always return a valid pointer to avoid a crash! */
8777 return (char_u *)&(curbuf->b_p_wm);
8778}
8779
8780/*
8781 * Get the value of 'equalprg', either the buffer-local one or the global one.
8782 */
8783 char_u *
8784get_equalprg()
8785{
8786 if (*curbuf->b_p_ep == NUL)
8787 return p_ep;
8788 return curbuf->b_p_ep;
8789}
8790
8791#if defined(FEAT_WINDOWS) || defined(PROTO)
8792/*
8793 * Copy options from one window to another.
8794 * Used when splitting a window.
8795 */
8796 void
8797win_copy_options(wp_from, wp_to)
8798 win_T *wp_from;
8799 win_T *wp_to;
8800{
8801 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8802 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8803# ifdef FEAT_RIGHTLEFT
8804# ifdef FEAT_FKMAP
8805 /* Is this right? */
8806 wp_to->w_farsi = wp_from->w_farsi;
8807# endif
8808# endif
8809}
8810#endif
8811
8812/*
8813 * Copy the options from one winopt_T to another.
8814 * Doesn't free the old option values in "to", use clear_winopt() for that.
8815 * The 'scroll' option is not copied, because it depends on the window height.
8816 * The 'previewwindow' option is reset, there can be only one preview window.
8817 */
8818 void
8819copy_winopt(from, to)
8820 winopt_T *from;
8821 winopt_T *to;
8822{
8823#ifdef FEAT_ARABIC
8824 to->wo_arab = from->wo_arab;
8825#endif
8826 to->wo_list = from->wo_list;
8827 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008828#ifdef FEAT_LINEBREAK
8829 to->wo_nuw = from->wo_nuw;
8830#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008831#ifdef FEAT_RIGHTLEFT
8832 to->wo_rl = from->wo_rl;
8833 to->wo_rlc = vim_strsave(from->wo_rlc);
8834#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008835#ifdef FEAT_STL_OPT
8836 to->wo_stl = vim_strsave(from->wo_stl);
8837#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 to->wo_wrap = from->wo_wrap;
8839#ifdef FEAT_LINEBREAK
8840 to->wo_lbr = from->wo_lbr;
8841#endif
8842#ifdef FEAT_SCROLLBIND
8843 to->wo_scb = from->wo_scb;
8844#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008845#ifdef FEAT_SYN_HL
8846 to->wo_spell = from->wo_spell;
8847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848#ifdef FEAT_DIFF
8849 to->wo_diff = from->wo_diff;
8850#endif
8851#ifdef FEAT_FOLDING
8852 to->wo_fdc = from->wo_fdc;
8853 to->wo_fen = from->wo_fen;
8854 to->wo_fdi = vim_strsave(from->wo_fdi);
8855 to->wo_fml = from->wo_fml;
8856 to->wo_fdl = from->wo_fdl;
8857 to->wo_fdm = vim_strsave(from->wo_fdm);
8858 to->wo_fdn = from->wo_fdn;
8859# ifdef FEAT_EVAL
8860 to->wo_fde = vim_strsave(from->wo_fde);
8861 to->wo_fdt = vim_strsave(from->wo_fdt);
8862# endif
8863 to->wo_fmr = vim_strsave(from->wo_fmr);
8864#endif
8865 check_winopt(to); /* don't want NULL pointers */
8866}
8867
8868/*
8869 * Check string options in a window for a NULL value.
8870 */
8871 void
8872check_win_options(win)
8873 win_T *win;
8874{
8875 check_winopt(&win->w_onebuf_opt);
8876 check_winopt(&win->w_allbuf_opt);
8877}
8878
8879/*
8880 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8881 */
8882/*ARGSUSED*/
8883 void
8884check_winopt(wop)
8885 winopt_T *wop;
8886{
8887#ifdef FEAT_FOLDING
8888 check_string_option(&wop->wo_fdi);
8889 check_string_option(&wop->wo_fdm);
8890# ifdef FEAT_EVAL
8891 check_string_option(&wop->wo_fde);
8892 check_string_option(&wop->wo_fdt);
8893# endif
8894 check_string_option(&wop->wo_fmr);
8895#endif
8896#ifdef FEAT_RIGHTLEFT
8897 check_string_option(&wop->wo_rlc);
8898#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008899#ifdef FEAT_STL_OPT
8900 check_string_option(&wop->wo_stl);
8901#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902}
8903
8904/*
8905 * Free the allocated memory inside a winopt_T.
8906 */
8907/*ARGSUSED*/
8908 void
8909clear_winopt(wop)
8910 winopt_T *wop;
8911{
8912#ifdef FEAT_FOLDING
8913 clear_string_option(&wop->wo_fdi);
8914 clear_string_option(&wop->wo_fdm);
8915# ifdef FEAT_EVAL
8916 clear_string_option(&wop->wo_fde);
8917 clear_string_option(&wop->wo_fdt);
8918# endif
8919 clear_string_option(&wop->wo_fmr);
8920#endif
8921#ifdef FEAT_RIGHTLEFT
8922 clear_string_option(&wop->wo_rlc);
8923#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008924#ifdef FEAT_STL_OPT
8925 clear_string_option(&wop->wo_stl);
8926#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008927}
8928
8929/*
8930 * Copy global option values to local options for one buffer.
8931 * Used when creating a new buffer and sometimes when entering a buffer.
8932 * flags:
8933 * BCO_ENTER We will enter the buf buffer.
8934 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8935 * appropriate.
8936 * BCO_NOHELP Don't copy the values to a help buffer.
8937 */
8938 void
8939buf_copy_options(buf, flags)
8940 buf_T *buf;
8941 int flags;
8942{
8943 int should_copy = TRUE;
8944 char_u *save_p_isk = NULL; /* init for GCC */
8945 int dont_do_help;
8946 int did_isk = FALSE;
8947
8948 /*
8949 * Don't do anything of the buffer is invalid.
8950 */
8951 if (buf == NULL || !buf_valid(buf))
8952 return;
8953
8954 /*
8955 * Skip this when the option defaults have not been set yet. Happens when
8956 * main() allocates the first buffer.
8957 */
8958 if (p_cpo != NULL)
8959 {
8960 /*
8961 * Always copy when entering and 'cpo' contains 'S'.
8962 * Don't copy when already initialized.
8963 * Don't copy when 'cpo' contains 's' and not entering.
8964 * 'S' BCO_ENTER initialized 's' should_copy
8965 * yes yes X X TRUE
8966 * yes no yes X FALSE
8967 * no X yes X FALSE
8968 * X no no yes FALSE
8969 * X no no no TRUE
8970 * no yes no X TRUE
8971 */
8972 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8973 && (buf->b_p_initialized
8974 || (!(flags & BCO_ENTER)
8975 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8976 should_copy = FALSE;
8977
8978 if (should_copy || (flags & BCO_ALWAYS))
8979 {
8980 /* Don't copy the options specific to a help buffer when
8981 * BCO_NOHELP is given or the options were initialized already
8982 * (jumping back to a help file with CTRL-T or CTRL-O) */
8983 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8984 || buf->b_p_initialized;
8985 if (dont_do_help) /* don't free b_p_isk */
8986 {
8987 save_p_isk = buf->b_p_isk;
8988 buf->b_p_isk = NULL;
8989 }
8990 /*
8991 * Always free the allocated strings.
8992 * If not already initialized, set 'readonly' and copy 'fileformat'.
8993 */
8994 if (!buf->b_p_initialized)
8995 {
8996 free_buf_options(buf, TRUE);
8997 buf->b_p_ro = FALSE; /* don't copy readonly */
8998 buf->b_p_tx = p_tx;
8999#ifdef FEAT_MBYTE
9000 buf->b_p_fenc = vim_strsave(p_fenc);
9001#endif
9002 buf->b_p_ff = vim_strsave(p_ff);
9003#if defined(FEAT_QUICKFIX)
9004 buf->b_p_bh = empty_option;
9005 buf->b_p_bt = empty_option;
9006#endif
9007 }
9008 else
9009 free_buf_options(buf, FALSE);
9010
9011 buf->b_p_ai = p_ai;
9012 buf->b_p_ai_nopaste = p_ai_nopaste;
9013 buf->b_p_sw = p_sw;
9014 buf->b_p_tw = p_tw;
9015 buf->b_p_tw_nopaste = p_tw_nopaste;
9016 buf->b_p_tw_nobin = p_tw_nobin;
9017 buf->b_p_wm = p_wm;
9018 buf->b_p_wm_nopaste = p_wm_nopaste;
9019 buf->b_p_wm_nobin = p_wm_nobin;
9020 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009021#ifdef FEAT_MBYTE
9022 buf->b_p_bomb = p_bomb;
9023#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009024 buf->b_p_et = p_et;
9025 buf->b_p_et_nobin = p_et_nobin;
9026 buf->b_p_ml = p_ml;
9027 buf->b_p_ml_nobin = p_ml_nobin;
9028 buf->b_p_inf = p_inf;
9029 buf->b_p_swf = p_swf;
9030#ifdef FEAT_INS_EXPAND
9031 buf->b_p_cpt = vim_strsave(p_cpt);
9032#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009033#ifdef FEAT_COMPL_FUNC
9034 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009035 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009036#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037 buf->b_p_sts = p_sts;
9038 buf->b_p_sts_nopaste = p_sts_nopaste;
9039#ifndef SHORT_FNAME
9040 buf->b_p_sn = p_sn;
9041#endif
9042#ifdef FEAT_COMMENTS
9043 buf->b_p_com = vim_strsave(p_com);
9044#endif
9045#ifdef FEAT_FOLDING
9046 buf->b_p_cms = vim_strsave(p_cms);
9047#endif
9048 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009049 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 buf->b_p_nf = vim_strsave(p_nf);
9051 buf->b_p_mps = vim_strsave(p_mps);
9052#ifdef FEAT_SMARTINDENT
9053 buf->b_p_si = p_si;
9054#endif
9055 buf->b_p_ci = p_ci;
9056#ifdef FEAT_CINDENT
9057 buf->b_p_cin = p_cin;
9058 buf->b_p_cink = vim_strsave(p_cink);
9059 buf->b_p_cino = vim_strsave(p_cino);
9060#endif
9061#ifdef FEAT_AUTOCMD
9062 /* Don't copy 'filetype', it must be detected */
9063 buf->b_p_ft = empty_option;
9064#endif
9065#ifdef FEAT_OSFILETYPE
9066 buf->b_p_oft = vim_strsave(p_oft);
9067#endif
9068 buf->b_p_pi = p_pi;
9069#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9070 buf->b_p_cinw = vim_strsave(p_cinw);
9071#endif
9072#ifdef FEAT_LISP
9073 buf->b_p_lisp = p_lisp;
9074#endif
9075#ifdef FEAT_SYN_HL
9076 /* Don't copy 'syntax', it must be set */
9077 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009078 buf->b_p_smc = p_smc;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009079 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009080 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009081 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009082 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083#endif
9084#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9085 buf->b_p_inde = vim_strsave(p_inde);
9086 buf->b_p_indk = vim_strsave(p_indk);
9087#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009088#if defined(FEAT_EVAL)
9089 buf->b_p_fex = vim_strsave(p_fex);
9090#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009091#ifdef FEAT_CRYPT
9092 buf->b_p_key = vim_strsave(p_key);
9093#endif
9094#ifdef FEAT_SEARCHPATH
9095 buf->b_p_sua = vim_strsave(p_sua);
9096#endif
9097#ifdef FEAT_KEYMAP
9098 buf->b_p_keymap = vim_strsave(p_keymap);
9099 buf->b_kmap_state |= KEYMAP_INIT;
9100#endif
9101 /* This isn't really an option, but copying the langmap and IME
9102 * state from the current buffer is better than resetting it. */
9103 buf->b_p_iminsert = p_iminsert;
9104 buf->b_p_imsearch = p_imsearch;
9105
9106 /* options that are normally global but also have a local value
9107 * are not copied, start using the global value */
9108 buf->b_p_ar = -1;
9109#ifdef FEAT_QUICKFIX
9110 buf->b_p_gp = empty_option;
9111 buf->b_p_mp = empty_option;
9112 buf->b_p_efm = empty_option;
9113#endif
9114 buf->b_p_ep = empty_option;
9115 buf->b_p_kp = empty_option;
9116 buf->b_p_path = empty_option;
9117 buf->b_p_tags = empty_option;
9118#ifdef FEAT_FIND_ID
9119 buf->b_p_def = empty_option;
9120 buf->b_p_inc = empty_option;
9121# ifdef FEAT_EVAL
9122 buf->b_p_inex = vim_strsave(p_inex);
9123# endif
9124#endif
9125#ifdef FEAT_INS_EXPAND
9126 buf->b_p_dict = empty_option;
9127 buf->b_p_tsr = empty_option;
9128#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009129#ifdef FEAT_TEXTOBJ
9130 buf->b_p_qe = vim_strsave(p_qe);
9131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132
9133 /*
9134 * Don't copy the options set by ex_help(), use the saved values,
9135 * when going from a help buffer to a non-help buffer.
9136 * Don't touch these at all when BCO_NOHELP is used and going from
9137 * or to a help buffer.
9138 */
9139 if (dont_do_help)
9140 buf->b_p_isk = save_p_isk;
9141 else
9142 {
9143 buf->b_p_isk = vim_strsave(p_isk);
9144 did_isk = TRUE;
9145 buf->b_p_ts = p_ts;
9146 buf->b_help = FALSE;
9147#ifdef FEAT_QUICKFIX
9148 if (buf->b_p_bt[0] == 'h')
9149 clear_string_option(&buf->b_p_bt);
9150#endif
9151 buf->b_p_ma = p_ma;
9152 }
9153 }
9154
9155 /*
9156 * When the options should be copied (ignoring BCO_ALWAYS), set the
9157 * flag that indicates that the options have been initialized.
9158 */
9159 if (should_copy)
9160 buf->b_p_initialized = TRUE;
9161 }
9162
9163 check_buf_options(buf); /* make sure we don't have NULLs */
9164 if (did_isk)
9165 (void)buf_init_chartab(buf, FALSE);
9166}
9167
9168/*
9169 * Reset the 'modifiable' option and its default value.
9170 */
9171 void
9172reset_modifiable()
9173{
9174 int opt_idx;
9175
9176 curbuf->b_p_ma = FALSE;
9177 p_ma = FALSE;
9178 opt_idx = findoption((char_u *)"ma");
9179 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
9180}
9181
9182/*
9183 * Set the global value for 'iminsert' to the local value.
9184 */
9185 void
9186set_iminsert_global()
9187{
9188 p_iminsert = curbuf->b_p_iminsert;
9189}
9190
9191/*
9192 * Set the global value for 'imsearch' to the local value.
9193 */
9194 void
9195set_imsearch_global()
9196{
9197 p_imsearch = curbuf->b_p_imsearch;
9198}
9199
9200#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9201static int expand_option_idx = -1;
9202static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9203static int expand_option_flags = 0;
9204
9205 void
9206set_context_in_set_cmd(xp, arg, opt_flags)
9207 expand_T *xp;
9208 char_u *arg;
9209 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9210{
9211 int nextchar;
9212 long_u flags = 0; /* init for GCC */
9213 int opt_idx = 0; /* init for GCC */
9214 char_u *p;
9215 char_u *s;
9216 int is_term_option = FALSE;
9217 int key;
9218
9219 expand_option_flags = opt_flags;
9220
9221 xp->xp_context = EXPAND_SETTINGS;
9222 if (*arg == NUL)
9223 {
9224 xp->xp_pattern = arg;
9225 return;
9226 }
9227 p = arg + STRLEN(arg) - 1;
9228 if (*p == ' ' && *(p - 1) != '\\')
9229 {
9230 xp->xp_pattern = p + 1;
9231 return;
9232 }
9233 while (p > arg)
9234 {
9235 s = p;
9236 /* count number of backslashes before ' ' or ',' */
9237 if (*p == ' ' || *p == ',')
9238 {
9239 while (s > arg && *(s - 1) == '\\')
9240 --s;
9241 }
9242 /* break at a space with an even number of backslashes */
9243 if (*p == ' ' && ((p - s) & 1) == 0)
9244 {
9245 ++p;
9246 break;
9247 }
9248 --p;
9249 }
9250 if (STRNCMP(p, "no", 2) == 0)
9251 {
9252 xp->xp_context = EXPAND_BOOL_SETTINGS;
9253 p += 2;
9254 }
9255 if (STRNCMP(p, "inv", 3) == 0)
9256 {
9257 xp->xp_context = EXPAND_BOOL_SETTINGS;
9258 p += 3;
9259 }
9260 xp->xp_pattern = arg = p;
9261 if (*arg == '<')
9262 {
9263 while (*p != '>')
9264 if (*p++ == NUL) /* expand terminal option name */
9265 return;
9266 key = get_special_key_code(arg + 1);
9267 if (key == 0) /* unknown name */
9268 {
9269 xp->xp_context = EXPAND_NOTHING;
9270 return;
9271 }
9272 nextchar = *++p;
9273 is_term_option = TRUE;
9274 expand_option_name[2] = KEY2TERMCAP0(key);
9275 expand_option_name[3] = KEY2TERMCAP1(key);
9276 }
9277 else
9278 {
9279 if (p[0] == 't' && p[1] == '_')
9280 {
9281 p += 2;
9282 if (*p != NUL)
9283 ++p;
9284 if (*p == NUL)
9285 return; /* expand option name */
9286 nextchar = *++p;
9287 is_term_option = TRUE;
9288 expand_option_name[2] = p[-2];
9289 expand_option_name[3] = p[-1];
9290 }
9291 else
9292 {
9293 /* Allow * wildcard */
9294 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9295 p++;
9296 if (*p == NUL)
9297 return;
9298 nextchar = *p;
9299 *p = NUL;
9300 opt_idx = findoption(arg);
9301 *p = nextchar;
9302 if (opt_idx == -1 || options[opt_idx].var == NULL)
9303 {
9304 xp->xp_context = EXPAND_NOTHING;
9305 return;
9306 }
9307 flags = options[opt_idx].flags;
9308 if (flags & P_BOOL)
9309 {
9310 xp->xp_context = EXPAND_NOTHING;
9311 return;
9312 }
9313 }
9314 }
9315 /* handle "-=" and "+=" */
9316 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9317 {
9318 ++p;
9319 nextchar = '=';
9320 }
9321 if ((nextchar != '=' && nextchar != ':')
9322 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9323 {
9324 xp->xp_context = EXPAND_UNSUCCESSFUL;
9325 return;
9326 }
9327 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9328 {
9329 xp->xp_context = EXPAND_OLD_SETTING;
9330 if (is_term_option)
9331 expand_option_idx = -1;
9332 else
9333 expand_option_idx = opt_idx;
9334 xp->xp_pattern = p + 1;
9335 return;
9336 }
9337 xp->xp_context = EXPAND_NOTHING;
9338 if (is_term_option || (flags & P_NUM))
9339 return;
9340
9341 xp->xp_pattern = p + 1;
9342
9343 if (flags & P_EXPAND)
9344 {
9345 p = options[opt_idx].var;
9346 if (p == (char_u *)&p_bdir
9347 || p == (char_u *)&p_dir
9348 || p == (char_u *)&p_path
9349 || p == (char_u *)&p_rtp
9350#ifdef FEAT_SEARCHPATH
9351 || p == (char_u *)&p_cdpath
9352#endif
9353#ifdef FEAT_SESSION
9354 || p == (char_u *)&p_vdir
9355#endif
9356 )
9357 {
9358 xp->xp_context = EXPAND_DIRECTORIES;
9359 if (p == (char_u *)&p_path
9360#ifdef FEAT_SEARCHPATH
9361 || p == (char_u *)&p_cdpath
9362#endif
9363 )
9364 xp->xp_backslash = XP_BS_THREE;
9365 else
9366 xp->xp_backslash = XP_BS_ONE;
9367 }
9368 else
9369 {
9370 xp->xp_context = EXPAND_FILES;
9371 /* for 'tags' need three backslashes for a space */
9372 if (p == (char_u *)&p_tags)
9373 xp->xp_backslash = XP_BS_THREE;
9374 else
9375 xp->xp_backslash = XP_BS_ONE;
9376 }
9377 }
9378
9379 /* For an option that is a list of file names, find the start of the
9380 * last file name. */
9381 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9382 {
9383 /* count number of backslashes before ' ' or ',' */
9384 if (*p == ' ' || *p == ',')
9385 {
9386 s = p;
9387 while (s > xp->xp_pattern && *(s - 1) == '\\')
9388 --s;
9389 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9390 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9391 {
9392 xp->xp_pattern = p + 1;
9393 break;
9394 }
9395 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009396
9397#ifdef FEAT_SYN_HL
9398 /* for 'spellsuggest' start at "file:" */
9399 if (options[opt_idx].var == (char_u *)&p_sps
9400 && STRNCMP(p, "file:", 5) == 0)
9401 {
9402 xp->xp_pattern = p + 5;
9403 break;
9404 }
9405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009406 }
9407
9408 return;
9409}
9410
9411 int
9412ExpandSettings(xp, regmatch, num_file, file)
9413 expand_T *xp;
9414 regmatch_T *regmatch;
9415 int *num_file;
9416 char_u ***file;
9417{
9418 int num_normal = 0; /* Nr of matching non-term-code settings */
9419 int num_term = 0; /* Nr of matching terminal code settings */
9420 int opt_idx;
9421 int match;
9422 int count = 0;
9423 char_u *str;
9424 int loop;
9425 int is_term_opt;
9426 char_u name_buf[MAX_KEY_NAME_LEN];
9427 static char *(names[]) = {"all", "termcap"};
9428 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9429
9430 /* do this loop twice:
9431 * loop == 0: count the number of matching options
9432 * loop == 1: copy the matching options into allocated memory
9433 */
9434 for (loop = 0; loop <= 1; ++loop)
9435 {
9436 regmatch->rm_ic = ic;
9437 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9438 {
9439 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9440 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9441 {
9442 if (loop == 0)
9443 num_normal++;
9444 else
9445 (*file)[count++] = vim_strsave((char_u *)names[match]);
9446 }
9447 }
9448 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9449 opt_idx++)
9450 {
9451 if (options[opt_idx].var == NULL)
9452 continue;
9453 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9454 && !(options[opt_idx].flags & P_BOOL))
9455 continue;
9456 is_term_opt = istermoption(&options[opt_idx]);
9457 if (is_term_opt && num_normal > 0)
9458 continue;
9459 match = FALSE;
9460 if (vim_regexec(regmatch, str, (colnr_T)0)
9461 || (options[opt_idx].shortname != NULL
9462 && vim_regexec(regmatch,
9463 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9464 match = TRUE;
9465 else if (is_term_opt)
9466 {
9467 name_buf[0] = '<';
9468 name_buf[1] = 't';
9469 name_buf[2] = '_';
9470 name_buf[3] = str[2];
9471 name_buf[4] = str[3];
9472 name_buf[5] = '>';
9473 name_buf[6] = NUL;
9474 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9475 {
9476 match = TRUE;
9477 str = name_buf;
9478 }
9479 }
9480 if (match)
9481 {
9482 if (loop == 0)
9483 {
9484 if (is_term_opt)
9485 num_term++;
9486 else
9487 num_normal++;
9488 }
9489 else
9490 (*file)[count++] = vim_strsave(str);
9491 }
9492 }
9493 /*
9494 * Check terminal key codes, these are not in the option table
9495 */
9496 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9497 {
9498 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9499 {
9500 if (!isprint(str[0]) || !isprint(str[1]))
9501 continue;
9502
9503 name_buf[0] = 't';
9504 name_buf[1] = '_';
9505 name_buf[2] = str[0];
9506 name_buf[3] = str[1];
9507 name_buf[4] = NUL;
9508
9509 match = FALSE;
9510 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9511 match = TRUE;
9512 else
9513 {
9514 name_buf[0] = '<';
9515 name_buf[1] = 't';
9516 name_buf[2] = '_';
9517 name_buf[3] = str[0];
9518 name_buf[4] = str[1];
9519 name_buf[5] = '>';
9520 name_buf[6] = NUL;
9521
9522 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9523 match = TRUE;
9524 }
9525 if (match)
9526 {
9527 if (loop == 0)
9528 num_term++;
9529 else
9530 (*file)[count++] = vim_strsave(name_buf);
9531 }
9532 }
9533
9534 /*
9535 * Check special key names.
9536 */
9537 regmatch->rm_ic = TRUE; /* ignore case here */
9538 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9539 {
9540 name_buf[0] = '<';
9541 STRCPY(name_buf + 1, str);
9542 STRCAT(name_buf, ">");
9543
9544 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9545 {
9546 if (loop == 0)
9547 num_term++;
9548 else
9549 (*file)[count++] = vim_strsave(name_buf);
9550 }
9551 }
9552 }
9553 if (loop == 0)
9554 {
9555 if (num_normal > 0)
9556 *num_file = num_normal;
9557 else if (num_term > 0)
9558 *num_file = num_term;
9559 else
9560 return OK;
9561 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9562 if (*file == NULL)
9563 {
9564 *file = (char_u **)"";
9565 return FAIL;
9566 }
9567 }
9568 }
9569 return OK;
9570}
9571
9572 int
9573ExpandOldSetting(num_file, file)
9574 int *num_file;
9575 char_u ***file;
9576{
9577 char_u *var = NULL; /* init for GCC */
9578 char_u *buf;
9579
9580 *num_file = 0;
9581 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9582 if (*file == NULL)
9583 return FAIL;
9584
9585 /*
9586 * For a terminal key code expand_option_idx is < 0.
9587 */
9588 if (expand_option_idx < 0)
9589 {
9590 var = find_termcode(expand_option_name + 2);
9591 if (var == NULL)
9592 expand_option_idx = findoption(expand_option_name);
9593 }
9594
9595 if (expand_option_idx >= 0)
9596 {
9597 /* put string of option value in NameBuff */
9598 option_value2string(&options[expand_option_idx], expand_option_flags);
9599 var = NameBuff;
9600 }
9601 else if (var == NULL)
9602 var = (char_u *)"";
9603
9604 /* A backslash is required before some characters. This is the reverse of
9605 * what happens in do_set(). */
9606 buf = vim_strsave_escaped(var, escape_chars);
9607
9608 if (buf == NULL)
9609 {
9610 vim_free(*file);
9611 *file = NULL;
9612 return FAIL;
9613 }
9614
9615#ifdef BACKSLASH_IN_FILENAME
9616 /* For MS-Windows et al. we don't double backslashes at the start and
9617 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009618 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009619 if (var[0] == '\\' && var[1] == '\\'
9620 && expand_option_idx >= 0
9621 && (options[expand_option_idx].flags & P_EXPAND)
9622 && vim_isfilec(var[2])
9623 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9624 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009625#endif
9626
9627 *file[0] = buf;
9628 *num_file = 1;
9629 return OK;
9630}
9631#endif
9632
9633/*
9634 * Get the value for the numeric or string option *opp in a nice format into
9635 * NameBuff[]. Must not be called with a hidden option!
9636 */
9637 static void
9638option_value2string(opp, opt_flags)
9639 struct vimoption *opp;
9640 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9641{
9642 char_u *varp;
9643
9644 varp = get_varp_scope(opp, opt_flags);
9645
9646 if (opp->flags & P_NUM)
9647 {
9648 long wc = 0;
9649
9650 if (wc_use_keyname(varp, &wc))
9651 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9652 else if (wc != 0)
9653 STRCPY(NameBuff, transchar((int)wc));
9654 else
9655 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9656 }
9657 else /* P_STRING */
9658 {
9659 varp = *(char_u **)(varp);
9660 if (varp == NULL) /* just in case */
9661 NameBuff[0] = NUL;
9662#ifdef FEAT_CRYPT
9663 /* don't show the actual value of 'key', only that it's set */
9664 if (opp->var == (char_u *)&p_key && *varp)
9665 STRCPY(NameBuff, "*****");
9666#endif
9667 else if (opp->flags & P_EXPAND)
9668 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9669 /* Translate 'pastetoggle' into special key names */
9670 else if ((char_u **)opp->var == &p_pt)
9671 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9672 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009673 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009674 }
9675}
9676
9677/*
9678 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9679 * printed as a keyname.
9680 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9681 */
9682 static int
9683wc_use_keyname(varp, wcp)
9684 char_u *varp;
9685 long *wcp;
9686{
9687 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9688 {
9689 *wcp = *(long *)varp;
9690 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9691 return TRUE;
9692 }
9693 return FALSE;
9694}
9695
9696#ifdef FEAT_LANGMAP
9697/*
9698 * Any character has an equivalent character. This is used for keyboards that
9699 * have a special language mode that sends characters above 128 (although
9700 * other characters can be translated too).
9701 */
9702
9703/*
9704 * char_u langmap_mapchar[256];
9705 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9706 * "translate" native lang chars in normal mode or some cases of
9707 * insert mode without having to tediously switch lang mode back&forth.
9708 */
9709
9710 static void
9711langmap_init()
9712{
9713 int i;
9714
9715 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9716 langmap_mapchar[i] = i;
9717}
9718
9719/*
9720 * Called when langmap option is set; the language map can be
9721 * changed at any time!
9722 */
9723 static void
9724langmap_set()
9725{
9726 char_u *p;
9727 char_u *p2;
9728 int from, to;
9729
9730 langmap_init(); /* back to one-to-one map first */
9731
9732 for (p = p_langmap; p[0] != NUL; )
9733 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009734 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9735 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009736 {
9737 if (p2[0] == '\\' && p2[1] != NUL)
9738 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009739 }
9740 if (p2[0] == ';')
9741 ++p2; /* abcd;ABCD form, p2 points to A */
9742 else
9743 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9744 while (p[0])
9745 {
9746 if (p[0] == '\\' && p[1] != NUL)
9747 ++p;
9748#ifdef FEAT_MBYTE
9749 from = (*mb_ptr2char)(p);
9750#else
9751 from = p[0];
9752#endif
9753 if (p2 == NULL)
9754 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009755 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756 if (p[0] == '\\')
9757 ++p;
9758#ifdef FEAT_MBYTE
9759 to = (*mb_ptr2char)(p);
9760#else
9761 to = p[0];
9762#endif
9763 }
9764 else
9765 {
9766 if (p2[0] == '\\')
9767 ++p2;
9768#ifdef FEAT_MBYTE
9769 to = (*mb_ptr2char)(p2);
9770#else
9771 to = p2[0];
9772#endif
9773 }
9774 if (to == NUL)
9775 {
9776 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9777 transchar(from));
9778 return;
9779 }
9780 langmap_mapchar[from & 255] = to;
9781
9782 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009783 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009784 if (p2 == NULL)
9785 {
9786 if (p[0] == ',')
9787 {
9788 ++p;
9789 break;
9790 }
9791 }
9792 else
9793 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009794 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795 if (*p == ';')
9796 {
9797 p = p2;
9798 if (p[0] != NUL)
9799 {
9800 if (p[0] != ',')
9801 {
9802 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9803 return;
9804 }
9805 ++p;
9806 }
9807 break;
9808 }
9809 }
9810 }
9811 }
9812}
9813#endif
9814
9815/*
9816 * Return TRUE if format option 'x' is in effect.
9817 * Take care of no formatting when 'paste' is set.
9818 */
9819 int
9820has_format_option(x)
9821 int x;
9822{
9823 if (p_paste)
9824 return FALSE;
9825 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9826}
9827
9828/*
9829 * Return TRUE if "x" is present in 'shortmess' option, or
9830 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9831 */
9832 int
9833shortmess(x)
9834 int x;
9835{
9836 return ( vim_strchr(p_shm, x) != NULL
9837 || (vim_strchr(p_shm, 'a') != NULL
9838 && vim_strchr((char_u *)SHM_A, x) != NULL));
9839}
9840
9841/*
9842 * paste_option_changed() - Called after p_paste was set or reset.
9843 */
9844 static void
9845paste_option_changed()
9846{
9847 static int old_p_paste = FALSE;
9848 static int save_sm = 0;
9849#ifdef FEAT_CMDL_INFO
9850 static int save_ru = 0;
9851#endif
9852#ifdef FEAT_RIGHTLEFT
9853 static int save_ri = 0;
9854 static int save_hkmap = 0;
9855#endif
9856 buf_T *buf;
9857
9858 if (p_paste)
9859 {
9860 /*
9861 * Paste switched from off to on.
9862 * Save the current values, so they can be restored later.
9863 */
9864 if (!old_p_paste)
9865 {
9866 /* save options for each buffer */
9867 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9868 {
9869 buf->b_p_tw_nopaste = buf->b_p_tw;
9870 buf->b_p_wm_nopaste = buf->b_p_wm;
9871 buf->b_p_sts_nopaste = buf->b_p_sts;
9872 buf->b_p_ai_nopaste = buf->b_p_ai;
9873 }
9874
9875 /* save global options */
9876 save_sm = p_sm;
9877#ifdef FEAT_CMDL_INFO
9878 save_ru = p_ru;
9879#endif
9880#ifdef FEAT_RIGHTLEFT
9881 save_ri = p_ri;
9882 save_hkmap = p_hkmap;
9883#endif
9884 /* save global values for local buffer options */
9885 p_tw_nopaste = p_tw;
9886 p_wm_nopaste = p_wm;
9887 p_sts_nopaste = p_sts;
9888 p_ai_nopaste = p_ai;
9889 }
9890
9891 /*
9892 * Always set the option values, also when 'paste' is set when it is
9893 * already on.
9894 */
9895 /* set options for each buffer */
9896 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9897 {
9898 buf->b_p_tw = 0; /* textwidth is 0 */
9899 buf->b_p_wm = 0; /* wrapmargin is 0 */
9900 buf->b_p_sts = 0; /* softtabstop is 0 */
9901 buf->b_p_ai = 0; /* no auto-indent */
9902 }
9903
9904 /* set global options */
9905 p_sm = 0; /* no showmatch */
9906#ifdef FEAT_CMDL_INFO
9907# ifdef FEAT_WINDOWS
9908 if (p_ru)
9909 status_redraw_all(); /* redraw to remove the ruler */
9910# endif
9911 p_ru = 0; /* no ruler */
9912#endif
9913#ifdef FEAT_RIGHTLEFT
9914 p_ri = 0; /* no reverse insert */
9915 p_hkmap = 0; /* no Hebrew keyboard */
9916#endif
9917 /* set global values for local buffer options */
9918 p_tw = 0;
9919 p_wm = 0;
9920 p_sts = 0;
9921 p_ai = 0;
9922 }
9923
9924 /*
9925 * Paste switched from on to off: Restore saved values.
9926 */
9927 else if (old_p_paste)
9928 {
9929 /* restore options for each buffer */
9930 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9931 {
9932 buf->b_p_tw = buf->b_p_tw_nopaste;
9933 buf->b_p_wm = buf->b_p_wm_nopaste;
9934 buf->b_p_sts = buf->b_p_sts_nopaste;
9935 buf->b_p_ai = buf->b_p_ai_nopaste;
9936 }
9937
9938 /* restore global options */
9939 p_sm = save_sm;
9940#ifdef FEAT_CMDL_INFO
9941# ifdef FEAT_WINDOWS
9942 if (p_ru != save_ru)
9943 status_redraw_all(); /* redraw to draw the ruler */
9944# endif
9945 p_ru = save_ru;
9946#endif
9947#ifdef FEAT_RIGHTLEFT
9948 p_ri = save_ri;
9949 p_hkmap = save_hkmap;
9950#endif
9951 /* set global values for local buffer options */
9952 p_tw = p_tw_nopaste;
9953 p_wm = p_wm_nopaste;
9954 p_sts = p_sts_nopaste;
9955 p_ai = p_ai_nopaste;
9956 }
9957
9958 old_p_paste = p_paste;
9959}
9960
9961/*
9962 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9963 *
9964 * Reset 'compatible' and set the values for options that didn't get set yet
9965 * to the Vim defaults.
9966 * Don't do this if the 'compatible' option has been set or reset before.
9967 */
9968 void
9969vimrc_found()
9970{
9971 int opt_idx;
9972
9973 if (!option_was_set((char_u *)"cp"))
9974 {
9975 p_cp = FALSE;
9976 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9977 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9978 set_option_default(opt_idx, OPT_FREE, FALSE);
9979 didset_options();
9980 }
9981}
9982
9983/*
9984 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9985 */
9986 void
9987change_compatible(on)
9988 int on;
9989{
9990 if (p_cp != on)
9991 {
9992 p_cp = on;
9993 compatible_set();
9994 }
9995 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9996}
9997
9998/*
9999 * Return TRUE when option "name" has been set.
10000 */
10001 int
10002option_was_set(name)
10003 char_u *name;
10004{
10005 int idx;
10006
10007 idx = findoption(name);
10008 if (idx < 0) /* unknown option */
10009 return FALSE;
10010 if (options[idx].flags & P_WAS_SET)
10011 return TRUE;
10012 return FALSE;
10013}
10014
10015/*
10016 * compatible_set() - Called when 'compatible' has been set or unset.
10017 *
10018 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10019 * flag) to a Vi compatible value.
10020 * When 'compatible' is unset: Set all options that have a different default
10021 * for Vim (without the P_VI_DEF flag) to that default.
10022 */
10023 static void
10024compatible_set()
10025{
10026 int opt_idx;
10027
10028 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10029 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10030 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10031 set_option_default(opt_idx, OPT_FREE, p_cp);
10032 didset_options();
10033}
10034
10035#ifdef FEAT_LINEBREAK
10036
10037# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10038 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010039 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040# endif
10041
10042/*
10043 * fill_breakat_flags() -- called when 'breakat' changes value.
10044 */
10045 static void
10046fill_breakat_flags()
10047{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010048 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049 int i;
10050
10051 for (i = 0; i < 256; i++)
10052 breakat_flags[i] = FALSE;
10053
10054 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010055 for (p = p_breakat; *p; p++)
10056 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010057}
10058
10059# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010060 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010061# endif
10062
10063#endif
10064
10065/*
10066 * Check an option that can be a range of string values.
10067 *
10068 * Return OK for correct value, FAIL otherwise.
10069 * Empty is always OK.
10070 */
10071 static int
10072check_opt_strings(val, values, list)
10073 char_u *val;
10074 char **values;
10075 int list; /* when TRUE: accept a list of values */
10076{
10077 return opt_strings_flags(val, values, NULL, list);
10078}
10079
10080/*
10081 * Handle an option that can be a range of string values.
10082 * Set a flag in "*flagp" for each string present.
10083 *
10084 * Return OK for correct value, FAIL otherwise.
10085 * Empty is always OK.
10086 */
10087 static int
10088opt_strings_flags(val, values, flagp, list)
10089 char_u *val; /* new value */
10090 char **values; /* array of valid string values */
10091 unsigned *flagp;
10092 int list; /* when TRUE: accept a list of values */
10093{
10094 int i;
10095 int len;
10096 unsigned new_flags = 0;
10097
10098 while (*val)
10099 {
10100 for (i = 0; ; ++i)
10101 {
10102 if (values[i] == NULL) /* val not found in values[] */
10103 return FAIL;
10104
10105 len = (int)STRLEN(values[i]);
10106 if (STRNCMP(values[i], val, len) == 0
10107 && ((list && val[len] == ',') || val[len] == NUL))
10108 {
10109 val += len + (val[len] == ',');
10110 new_flags |= (1 << i);
10111 break; /* check next item in val list */
10112 }
10113 }
10114 }
10115 if (flagp != NULL)
10116 *flagp = new_flags;
10117
10118 return OK;
10119}
10120
10121/*
10122 * Read the 'wildmode' option, fill wim_flags[].
10123 */
10124 static int
10125check_opt_wim()
10126{
10127 char_u new_wim_flags[4];
10128 char_u *p;
10129 int i;
10130 int idx = 0;
10131
10132 for (i = 0; i < 4; ++i)
10133 new_wim_flags[i] = 0;
10134
10135 for (p = p_wim; *p; ++p)
10136 {
10137 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10138 ;
10139 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10140 return FAIL;
10141 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10142 new_wim_flags[idx] |= WIM_LONGEST;
10143 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10144 new_wim_flags[idx] |= WIM_FULL;
10145 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10146 new_wim_flags[idx] |= WIM_LIST;
10147 else
10148 return FAIL;
10149 p += i;
10150 if (*p == NUL)
10151 break;
10152 if (*p == ',')
10153 {
10154 if (idx == 3)
10155 return FAIL;
10156 ++idx;
10157 }
10158 }
10159
10160 /* fill remaining entries with last flag */
10161 while (idx < 3)
10162 {
10163 new_wim_flags[idx + 1] = new_wim_flags[idx];
10164 ++idx;
10165 }
10166
10167 /* only when there are no errors, wim_flags[] is changed */
10168 for (i = 0; i < 4; ++i)
10169 wim_flags[i] = new_wim_flags[i];
10170 return OK;
10171}
10172
10173/*
10174 * Check if backspacing over something is allowed.
10175 */
10176 int
10177can_bs(what)
10178 int what; /* BS_INDENT, BS_EOL or BS_START */
10179{
10180 switch (*p_bs)
10181 {
10182 case '2': return TRUE;
10183 case '1': return (what != BS_START);
10184 case '0': return FALSE;
10185 }
10186 return vim_strchr(p_bs, what) != NULL;
10187}
10188
10189/*
10190 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10191 * the file must be considered changed when the value is different.
10192 */
10193 void
10194save_file_ff(buf)
10195 buf_T *buf;
10196{
10197 buf->b_start_ffc = *buf->b_p_ff;
10198 buf->b_start_eol = buf->b_p_eol;
10199#ifdef FEAT_MBYTE
10200 /* Only use free/alloc when necessary, they take time. */
10201 if (buf->b_start_fenc == NULL
10202 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
10203 {
10204 vim_free(buf->b_start_fenc);
10205 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
10206 }
10207#endif
10208}
10209
10210/*
10211 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
10212 * from when editing started (save_file_ff() called).
10213 * Also when 'endofline' was changed and 'binary' is set.
10214 * Don't consider a new, empty buffer to be changed.
10215 */
10216 int
10217file_ff_differs(buf)
10218 buf_T *buf;
10219{
10220 if ((buf->b_flags & BF_NEW)
10221 && buf->b_ml.ml_line_count == 1
10222 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10223 return FALSE;
10224 if (buf->b_start_ffc != *buf->b_p_ff)
10225 return TRUE;
10226 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10227 return TRUE;
10228#ifdef FEAT_MBYTE
10229 if (buf->b_start_fenc == NULL)
10230 return (*buf->b_p_fenc != NUL);
10231 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10232#else
10233 return FALSE;
10234#endif
10235}
10236
10237/*
10238 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10239 */
10240 int
10241check_ff_value(p)
10242 char_u *p;
10243{
10244 return check_opt_strings(p, p_ff_values, FALSE);
10245}