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