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