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