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