blob: 0dee50b976856ccaaf6f29476b1fba7a0853dee0 [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)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002478# ifdef FEAT_AUTOCMD
2479static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2480# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002482# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2484#endif
2485static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2486#ifdef FEAT_FOLDING
2487static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
2488#ifdef FEAT_DIFF
2489 "diff",
2490#endif
2491 NULL};
2492static char *(p_fcl_values[]) = {"all", NULL};
2493#endif
2494
2495static void set_option_default __ARGS((int, int opt_flags, int compatible));
2496static void set_options_default __ARGS((int opt_flags));
2497static char_u *illegal_char __ARGS((char_u *, int));
2498static int string_to_key __ARGS((char_u *arg));
2499#ifdef FEAT_CMDWIN
2500static char_u *check_cedit __ARGS((void));
2501#endif
2502#ifdef FEAT_TITLE
2503static void did_set_title __ARGS((int icon));
2504#endif
2505static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2506static void didset_options __ARGS((void));
2507static void check_string_option __ARGS((char_u **pp));
2508static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2509static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2510static 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));
2511static char_u *set_chars_option __ARGS((char_u **varp));
2512#ifdef FEAT_CLIPBOARD
2513static char_u *check_clipboard_option __ARGS((void));
2514#endif
2515static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
2516static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, int opt_flags));
2517static void check_redraw __ARGS((long_u flags));
2518static int findoption __ARGS((char_u *));
2519static int find_key_option __ARGS((char_u *));
2520static void showoptions __ARGS((int all, int opt_flags));
2521static int optval_default __ARGS((struct vimoption *, char_u *varp));
2522static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2523static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2524static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2525static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2526static int istermoption __ARGS((struct vimoption *));
2527static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2528static char_u *get_varp __ARGS((struct vimoption *));
2529static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2530static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2531#ifdef FEAT_LANGMAP
2532static void langmap_init __ARGS((void));
2533static void langmap_set __ARGS((void));
2534#endif
2535static void paste_option_changed __ARGS((void));
2536static void compatible_set __ARGS((void));
2537#ifdef FEAT_LINEBREAK
2538static void fill_breakat_flags __ARGS((void));
2539#endif
2540static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2541static int check_opt_strings __ARGS((char_u *val, char **values, int));
2542static int check_opt_wim __ARGS((void));
2543
2544/*
2545 * Initialize the options, first part.
2546 *
2547 * Called only once from main(), just after creating the first buffer.
2548 */
2549 void
2550set_init_1()
2551{
2552 char_u *p;
2553 int opt_idx;
2554 long n;
2555
2556#ifdef FEAT_LANGMAP
2557 langmap_init();
2558#endif
2559
2560 /* Be Vi compatible by default */
2561 p_cp = TRUE;
2562
2563 /*
2564 * Find default value for 'shell' option.
2565 */
2566 if ((p = mch_getenv((char_u *)"SHELL")) != NULL
2567#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2568# ifdef __EMX__
2569 || (p = mch_getenv((char_u *)"EMXSHELL")) != NULL
2570# endif
2571 || (p = mch_getenv((char_u *)"COMSPEC")) != NULL
2572# ifdef WIN3264
2573 || (p = default_shell()) != NULL
2574# endif
2575#endif
2576 )
2577 set_string_default("sh", p);
2578
2579#ifdef FEAT_WILDIGN
2580 /*
2581 * Set the default for 'backupskip' to include environment variables for
2582 * temp files.
2583 */
2584 {
2585# ifdef UNIX
2586 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2587# else
2588 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2589# endif
2590 int len;
2591 garray_T ga;
2592
2593 ga_init2(&ga, 1, 100);
2594 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2595 {
2596# ifdef UNIX
2597 if (*names[n] == NUL)
2598 p = (char_u *)"/tmp";
2599 else
2600# endif
2601 p = mch_getenv((char_u *)names[n]);
2602 if (p != NULL && *p != NUL)
2603 {
2604 /* First time count the NUL, otherwise count the ','. */
2605 len = STRLEN(p) + 3;
2606 if (ga_grow(&ga, len) == OK)
2607 {
2608 if (ga.ga_len > 0)
2609 STRCAT(ga.ga_data, ",");
2610 STRCAT(ga.ga_data, p);
2611 add_pathsep(ga.ga_data);
2612 STRCAT(ga.ga_data, "*");
2613 ga.ga_room -= len;
2614 ga.ga_len += len;
2615 }
2616 }
2617 }
2618 if (ga.ga_data != NULL)
2619 {
2620 set_string_default("bsk", ga.ga_data);
2621 vim_free(ga.ga_data);
2622 }
2623 }
2624#endif
2625
2626 /*
2627 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2628 */
2629 opt_idx = findoption((char_u *)"maxmemtot");
2630#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2631 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2632#endif
2633 {
2634#ifdef HAVE_AVAIL_MEM
2635 /* Use amount of memory available at this moment. */
2636 n = (mch_avail_mem(FALSE) >> 11);
2637#else
2638# ifdef HAVE_TOTAL_MEM
2639 /* Use amount of memory available to Vim. */
2640 n = (mch_total_mem(FALSE) >> 11);
2641# else
2642 n = (0x7fffffff >> 11);
2643# endif
2644#endif
2645 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2646 opt_idx = findoption((char_u *)"maxmem");
2647#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2648 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2649 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2650#endif
2651 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2652 }
2653
2654#ifdef FEAT_GUI_W32
2655 /* force 'shortname' for Win32s */
2656 if (gui_is_win32s())
2657 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2658 (char_u *)TRUE;
2659#endif
2660
2661#ifdef FEAT_SEARCHPATH
2662 {
2663 char_u *cdpath;
2664 char_u *buf;
2665 int i;
2666 int j;
2667
2668 /* Initialize the 'cdpath' option's default value. */
2669 cdpath = mch_getenv((char_u *)"CDPATH");
2670 if (cdpath != NULL)
2671 {
2672 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2673 if (buf != NULL)
2674 {
2675 buf[0] = ','; /* start with ",", current dir first */
2676 j = 1;
2677 for (i = 0; cdpath[i] != NUL; ++i)
2678 {
2679 if (vim_ispathlistsep(cdpath[i]))
2680 buf[j++] = ',';
2681 else
2682 {
2683 if (cdpath[i] == ' ' || cdpath[i] == ',')
2684 buf[j++] = '\\';
2685 buf[j++] = cdpath[i];
2686 }
2687 }
2688 buf[j] = NUL;
2689 opt_idx = findoption((char_u *)"cdpath");
2690 options[opt_idx].def_val[VI_DEFAULT] = buf;
2691 options[opt_idx].flags |= P_DEF_ALLOCED;
2692 }
2693 }
2694 }
2695#endif
2696
2697#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2698 /* Set print encoding on platforms that don't default to latin1 */
2699 set_string_default("penc",
2700# if defined(MSWIN) || defined(OS2)
2701 (char_u *)"cp1252"
2702# else
2703# ifdef VMS
2704 (char_u *)"dec-mcs"
2705# else
2706# ifdef EBCDIC
2707 (char_u *)"ebcdic-uk"
2708# else
2709# ifdef MAC
2710 (char_u *)"mac-roman"
2711# else /* HPUX */
2712 (char_u *)"hp-roman8"
2713# endif
2714# endif
2715# endif
2716# endif
2717 );
2718#endif
2719
2720#ifdef FEAT_POSTSCRIPT
2721 /* 'printexpr' must be allocated to be able to evaluate it. */
2722 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00002723# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
2724 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725# else
2726# ifdef VMS
2727 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
2728
2729# else
2730 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
2731# endif
2732# endif
2733 );
2734#endif
2735
2736 /*
2737 * Set all the options (except the terminal options) to their default
2738 * value. Also set the global value for local options.
2739 */
2740 set_options_default(0);
2741
2742#ifdef FEAT_GUI
2743 if (found_reverse_arg)
2744 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
2745#endif
2746
2747 curbuf->b_p_initialized = TRUE;
2748 curbuf->b_p_ar = -1; /* no local 'autoread' value */
2749 check_buf_options(curbuf);
2750 check_win_options(curwin);
2751 check_options();
2752
2753 /* Must be before option_expand(), because that one needs vim_isIDc() */
2754 didset_options();
2755
2756#ifdef FEAT_LINEBREAK
2757 /*
2758 * initialize the table for 'breakat'.
2759 */
2760 fill_breakat_flags();
2761#endif
2762
2763 /*
2764 * Expand environment variables and things like "~" for the defaults.
2765 * If option_expand() returns non-NULL the variable is expanded. This can
2766 * only happen for non-indirect options.
2767 * Also set the default to the expanded value, so ":set" does not list
2768 * them.
2769 * Don't set the P_ALLOCED flag, because we don't want to free the
2770 * default.
2771 */
2772 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
2773 {
2774 if ((options[opt_idx].flags & P_GETTEXT)
2775 && options[opt_idx].var != NULL)
2776 p = (char_u *)_(*(char **)options[opt_idx].var);
2777 else
2778 p = option_expand(opt_idx, NULL);
2779 if (p != NULL && (p = vim_strsave(p)) != NULL)
2780 {
2781 *(char_u **)options[opt_idx].var = p;
2782 /* VIMEXP
2783 * Defaults for all expanded options are currently the same for Vi
2784 * and Vim. When this changes, add some code here! Also need to
2785 * split P_DEF_ALLOCED in two.
2786 */
2787 if (options[opt_idx].flags & P_DEF_ALLOCED)
2788 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2789 options[opt_idx].def_val[VI_DEFAULT] = p;
2790 options[opt_idx].flags |= P_DEF_ALLOCED;
2791 }
2792 }
2793
2794 /* Initialize the highlight_attr[] table. */
2795 highlight_changed();
2796
2797 save_file_ff(curbuf); /* Buffer is unchanged */
2798
2799 /* Parse default for 'wildmode' */
2800 check_opt_wim();
2801
2802#if defined(FEAT_ARABIC)
2803 /* Detect use of mlterm.
2804 * Mlterm is a terminal emulator akin to xterm that has some special
2805 * abilities (bidi namely).
2806 * NOTE: mlterm's author is being asked to 'set' a variable
2807 * instead of an environment variable due to inheritance.
2808 */
2809 if (mch_getenv((char_u *)"MLTERM") != NULL)
2810 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
2811#endif
2812
2813#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
2814 /* Parse default for 'fillchars'. */
2815 (void)set_chars_option(&p_fcs);
2816#endif
2817
2818#ifdef FEAT_CLIPBOARD
2819 /* Parse default for 'clipboard' */
2820 (void)check_clipboard_option();
2821#endif
2822
2823#ifdef FEAT_MBYTE
2824# if defined(WIN3264) && defined(FEAT_GETTEXT)
2825 /*
2826 * If $LANG isn't set, try to get a good value for it. This makes the
2827 * right language be used automatically. Don't do this for English.
2828 */
2829 if (mch_getenv((char_u *)"LANG") == NULL)
2830 {
2831 char buf[20];
2832
2833 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
2834 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
2835 * only the first two. */
2836 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
2837 (LPTSTR)buf, 20);
2838 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
2839 {
2840 /* There are a few exceptions (probably more) */
2841 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
2842 STRCPY(buf, "zh_TW");
2843 else if (STRNICMP(buf, "chs", 3) == 0
2844 || STRNICMP(buf, "zhc", 3) == 0)
2845 STRCPY(buf, "zh_CN");
2846 else if (STRNICMP(buf, "jp", 2) == 0)
2847 STRCPY(buf, "ja");
2848 else
2849 buf[2] = NUL; /* truncate to two-letter code */
2850 vim_setenv("LANG", buf);
2851 }
2852 }
2853# endif
2854
2855 /* enc_locale() will try to find the encoding of the current locale. */
2856 p = enc_locale();
2857 if (p != NULL)
2858 {
2859 char_u *save_enc;
2860
2861 /* Try setting 'encoding' and check if the value is valid.
2862 * If not, go back to the default "latin1". */
2863 save_enc = p_enc;
2864 p_enc = p;
2865 if (mb_init() == NULL)
2866 {
2867 opt_idx = findoption((char_u *)"encoding");
2868 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
2869 options[opt_idx].flags |= P_DEF_ALLOCED;
2870
2871# if defined(WIN3264) && !defined(FEAT_GUI)
2872 /* Win32 console: When GetACP() returns a different value from
2873 * GetConsoleCP() set 'termencoding'. */
2874 if (GetACP() != GetConsoleCP())
2875 {
2876 char buf[50];
2877
2878 sprintf(buf, "cp%ld", (long)GetConsoleCP());
2879 p_tenc = vim_strsave((char_u *)buf);
2880 if (p_tenc != NULL)
2881 {
2882 opt_idx = findoption((char_u *)"termencoding");
2883 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
2884 options[opt_idx].flags |= P_DEF_ALLOCED;
2885 convert_setup(&input_conv, p_tenc, p_enc);
2886 convert_setup(&output_conv, p_enc, p_tenc);
2887 }
2888 else
2889 p_tenc = empty_option;
2890 }
2891# endif
2892 }
2893 else
2894 {
2895 vim_free(p_enc);
2896 p_enc = save_enc;
2897 }
2898 }
2899#endif
2900
2901#ifdef FEAT_MULTI_LANG
2902 /* Set the default for 'helplang'. */
2903 set_helplang_default(get_mess_lang());
2904#endif
2905}
2906
2907/*
2908 * Set an option to its default value.
2909 * This does not take care of side effects!
2910 */
2911 static void
2912set_option_default(opt_idx, opt_flags, compatible)
2913 int opt_idx;
2914 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
2915 int compatible; /* use Vi default value */
2916{
2917 char_u *varp; /* pointer to variable for current option */
2918 int dvi; /* index in def_val[] */
2919 long_u flags;
2920 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
2921
2922 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
2923 flags = options[opt_idx].flags;
2924 if (varp != NULL) /* nothing to do for hidden option */
2925 {
2926 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
2927 if (flags & P_STRING)
2928 {
2929 /* Use set_string_option_direct() for local options to handle
2930 * freeing and allocating the value. */
2931 if (options[opt_idx].indir != PV_NONE)
2932 set_string_option_direct(NULL, opt_idx,
2933 options[opt_idx].def_val[dvi], opt_flags);
2934 else
2935 {
2936 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
2937 free_string_option(*(char_u **)(varp));
2938 *(char_u **)varp = options[opt_idx].def_val[dvi];
2939 options[opt_idx].flags &= ~P_ALLOCED;
2940 }
2941 }
2942 else if (flags & P_NUM)
2943 {
2944 if (varp == (char_u *)PV_SCROLL)
2945 win_comp_scroll(curwin);
2946 else
2947 {
2948 *(long *)varp = (long)options[opt_idx].def_val[dvi];
2949 /* May also set global value for local option. */
2950 if (both)
2951 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
2952 *(long *)varp;
2953 }
2954 }
2955 else /* P_BOOL */
2956 {
2957 /* the cast to long is required for Manx C */
2958 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
2959 /* May also set global value for local option. */
2960 if (both)
2961 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
2962 *(int *)varp;
2963 }
2964 }
2965
2966#ifdef FEAT_EVAL
2967 /* Remember where the option was set. */
2968 options[opt_idx].scriptID = current_SID;
2969#endif
2970}
2971
2972/*
2973 * Set all options (except terminal options) to their default value.
2974 */
2975 static void
2976set_options_default(opt_flags)
2977 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
2978{
2979 int i;
2980#ifdef FEAT_WINDOWS
2981 win_T *wp;
2982#endif
2983
2984 for (i = 0; !istermoption(&options[i]); i++)
2985 if (!(options[i].flags & P_NODEFAULT))
2986 set_option_default(i, opt_flags, p_cp);
2987
2988#ifdef FEAT_WINDOWS
2989 /* The 'scroll' option must be computed for all windows. */
2990 for (wp = firstwin; wp != NULL; wp = wp->w_next)
2991 win_comp_scroll(wp);
2992#else
2993 win_comp_scroll(curwin);
2994#endif
2995}
2996
2997/*
2998 * Set the Vi-default value of a string option.
2999 * Used for 'sh', 'backupskip' and 'term'.
3000 */
3001 void
3002set_string_default(name, val)
3003 char *name;
3004 char_u *val;
3005{
3006 char_u *p;
3007 int opt_idx;
3008
3009 p = vim_strsave(val);
3010 if (p != NULL) /* we don't want a NULL */
3011 {
3012 opt_idx = findoption((char_u *)name);
3013 if (options[opt_idx].flags & P_DEF_ALLOCED)
3014 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3015 options[opt_idx].def_val[VI_DEFAULT] = p;
3016 options[opt_idx].flags |= P_DEF_ALLOCED;
3017 }
3018}
3019
3020/*
3021 * Set the Vi-default value of a number option.
3022 * Used for 'lines' and 'columns'.
3023 */
3024 void
3025set_number_default(name, val)
3026 char *name;
3027 long val;
3028{
3029 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3030}
3031
3032/*
3033 * Initialize the options, part two: After getting Rows and Columns and
3034 * setting 'term'.
3035 */
3036 void
3037set_init_2()
3038{
3039 /*
3040 * 'scroll' defaults to half the window height. Note that this default is
3041 * wrong when the window height changes.
3042 */
3043 options[findoption((char_u *)"scroll")].def_val[VI_DEFAULT]
3044 = (char_u *)((long_u)Rows >> 1);
3045 comp_col();
3046
3047#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3048 {
3049 int idx4;
3050
3051 /*
3052 * If 'background' wasn't set by the user, try guessing the value,
3053 * depending on the terminal name. Only need to check for terminals
3054 * with a dark background, that can handle color. Only "linux"
3055 * console at the moment.
3056 */
3057 idx4 = findoption((char_u *)"bg");
3058 if (!(options[idx4].flags & P_WAS_SET) && STRCMP(T_NAME, "linux") == 0)
3059 {
3060 set_string_option_direct(NULL, idx4, (char_u *)"dark", OPT_FREE);
3061 /* don't mark it as set, when starting the GUI it may be changed
3062 * again */
3063 options[idx4].flags &= ~P_WAS_SET;
3064 }
3065 }
3066#endif
3067}
3068
3069/*
3070 * Initialize the options, part three: After reading the .vimrc
3071 */
3072 void
3073set_init_3()
3074{
3075#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3076/*
3077 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3078 * This is done after other initializations, where 'shell' might have been
3079 * set, but only if they have not been set before.
3080 */
3081 char_u *p;
3082 int idx_srr;
3083 int do_srr;
3084#ifdef FEAT_QUICKFIX
3085 int idx_sp;
3086 int do_sp;
3087#endif
3088
3089 idx_srr = findoption((char_u *)"srr");
3090 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3091#ifdef FEAT_QUICKFIX
3092 idx_sp = findoption((char_u *)"sp");
3093 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3094#endif
3095
3096 /*
3097 * Isolate the name of the shell:
3098 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3099 * - Remove any argument. E.g., "csh -f" -> "csh".
3100 */
3101 p = gettail(p_sh);
3102 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3103 if (p != NULL)
3104 {
3105 /*
3106 * Default for p_sp is "| tee", for p_srr is ">".
3107 * For known shells it is changed here to include stderr.
3108 */
3109 if ( fnamecmp(p, "csh") == 0
3110 || fnamecmp(p, "tcsh") == 0
3111# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3112 || fnamecmp(p, "csh.exe") == 0
3113 || fnamecmp(p, "tcsh.exe") == 0
3114# endif
3115 )
3116 {
3117#if defined(FEAT_QUICKFIX)
3118 if (do_sp)
3119 {
3120# ifdef WIN3264
3121 p_sp = (char_u *)">&";
3122# else
3123 p_sp = (char_u *)"|& tee";
3124# endif
3125 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3126 }
3127#endif
3128 if (do_srr)
3129 {
3130 p_srr = (char_u *)">&";
3131 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3132 }
3133 }
3134 else
3135# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3136 if ( fnamecmp(p, "sh") == 0
3137 || fnamecmp(p, "ksh") == 0
3138 || fnamecmp(p, "zsh") == 0
3139 || fnamecmp(p, "bash") == 0
3140# ifdef WIN3264
3141 || fnamecmp(p, "cmd") == 0
3142 || fnamecmp(p, "sh.exe") == 0
3143 || fnamecmp(p, "ksh.exe") == 0
3144 || fnamecmp(p, "zsh.exe") == 0
3145 || fnamecmp(p, "bash.exe") == 0
3146 || fnamecmp(p, "cmd.exe") == 0
3147# endif
3148 )
3149# endif
3150 {
3151#if defined(FEAT_QUICKFIX)
3152 if (do_sp)
3153 {
3154# ifdef WIN3264
3155 p_sp = (char_u *)">%s 2>&1";
3156# else
3157 p_sp = (char_u *)"2>&1| tee";
3158# endif
3159 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3160 }
3161#endif
3162 if (do_srr)
3163 {
3164 p_srr = (char_u *)">%s 2>&1";
3165 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3166 }
3167 }
3168 vim_free(p);
3169 }
3170#endif
3171
3172#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3173 /*
3174 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3175 * This is done after other initializations, where 'shell' might have been
3176 * set, but only if they have not been set before. Default for p_shcf is
3177 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3178 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3179 * command.com. And for Win32 we need to set p_sxq instead.
3180 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 {
3183 int idx3;
3184
3185 idx3 = findoption((char_u *)"shcf");
3186 if (!(options[idx3].flags & P_WAS_SET))
3187 {
3188 p_shcf = (char_u *)"-c";
3189 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3190 }
3191
3192# ifndef DJGPP
3193# ifdef WIN3264
3194 /* Somehow Win32 requires the quotes around the redirection too */
3195 idx3 = findoption((char_u *)"sxq");
3196 if (!(options[idx3].flags & P_WAS_SET))
3197 {
3198 p_sxq = (char_u *)"\"";
3199 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3200 }
3201# else
3202 idx3 = findoption((char_u *)"shq");
3203 if (!(options[idx3].flags & P_WAS_SET))
3204 {
3205 p_shq = (char_u *)"\"";
3206 options[idx3].def_val[VI_DEFAULT] = p_shq;
3207 }
3208# endif
3209# endif
3210 }
3211#endif
3212
3213#ifdef FEAT_TITLE
3214 set_title_defaults();
3215#endif
3216}
3217
3218#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3219/*
3220 * When 'helplang' is still at its default value, set it to "lang".
3221 * Only the first two characters of "lang" are used.
3222 */
3223 void
3224set_helplang_default(lang)
3225 char_u *lang;
3226{
3227 int idx;
3228
3229 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3230 return;
3231 idx = findoption((char_u *)"hlg");
3232 if (!(options[idx].flags & P_WAS_SET))
3233 {
3234 if (options[idx].flags & P_ALLOCED)
3235 free_string_option(p_hlg);
3236 p_hlg = vim_strsave(lang);
3237 if (p_hlg == NULL)
3238 p_hlg = empty_option;
3239 else
3240 p_hlg[2] = NUL;
3241 options[idx].flags |= P_ALLOCED;
3242 }
3243}
3244#endif
3245
3246#ifdef FEAT_GUI
3247static char_u *gui_bg_default __ARGS((void));
3248
3249 static char_u *
3250gui_bg_default()
3251{
3252 if (gui_get_lightness(gui.back_pixel) < 127)
3253 return (char_u *)"dark";
3254 return (char_u *)"light";
3255}
3256
3257/*
3258 * Option initializations that can only be done after opening the GUI window.
3259 */
3260 void
3261init_gui_options()
3262{
3263 /* Set the 'background' option according to the lightness of the
3264 * background color, unless the user has set it already. */
3265 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3266 {
3267 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3268 highlight_changed();
3269 }
3270}
3271#endif
3272
3273#ifdef FEAT_TITLE
3274/*
3275 * 'title' and 'icon' only default to true if they have not been set or reset
3276 * in .vimrc and we can read the old value.
3277 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3278 * they can be reset. This reduces startup time when using X on a remote
3279 * machine.
3280 */
3281 void
3282set_title_defaults()
3283{
3284 int idx1;
3285 long val;
3286
3287 /*
3288 * If GUI is (going to be) used, we can always set the window title and
3289 * icon name. Saves a bit of time, because the X11 display server does
3290 * not need to be contacted.
3291 */
3292 idx1 = findoption((char_u *)"title");
3293 if (!(options[idx1].flags & P_WAS_SET))
3294 {
3295#ifdef FEAT_GUI
3296 if (gui.starting || gui.in_use)
3297 val = TRUE;
3298 else
3299#endif
3300 val = mch_can_restore_title();
3301 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3302 p_title = val;
3303 }
3304 idx1 = findoption((char_u *)"icon");
3305 if (!(options[idx1].flags & P_WAS_SET))
3306 {
3307#ifdef FEAT_GUI
3308 if (gui.starting || gui.in_use)
3309 val = TRUE;
3310 else
3311#endif
3312 val = mch_can_restore_icon();
3313 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3314 p_icon = val;
3315 }
3316}
3317#endif
3318
3319/*
3320 * Parse 'arg' for option settings.
3321 *
3322 * 'arg' may be IObuff, but only when no errors can be present and option
3323 * does not need to be expanded with option_expand().
3324 * "opt_flags":
3325 * 0 for ":set"
3326 * OPT_GLOBAL for ":setglobal"
3327 * OPT_LOCAL for ":setlocal" and a modeline
3328 * OPT_MODELINE for a modeline
3329 *
3330 * returns FAIL if an error is detected, OK otherwise
3331 */
3332 int
3333do_set(arg, opt_flags)
3334 char_u *arg; /* option string (may be written to!) */
3335 int opt_flags;
3336{
3337 int opt_idx;
3338 char_u *errmsg;
3339 char_u errbuf[80];
3340 char_u *startarg;
3341 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3342 int nextchar; /* next non-white char after option name */
3343 int afterchar; /* character just after option name */
3344 int len;
3345 int i;
3346 long value;
3347 int key;
3348 long_u flags; /* flags for current option */
3349 char_u *varp = NULL; /* pointer to variable for current option */
3350 int did_show = FALSE; /* already showed one value */
3351 int adding; /* "opt+=arg" */
3352 int prepending; /* "opt^=arg" */
3353 int removing; /* "opt-=arg" */
3354 int cp_val = 0;
3355 char_u key_name[2];
3356
3357 if (*arg == NUL)
3358 {
3359 showoptions(0, opt_flags);
3360 return OK;
3361 }
3362
3363 while (*arg != NUL) /* loop to process all options */
3364 {
3365 errmsg = NULL;
3366 startarg = arg; /* remember for error message */
3367
3368 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]))
3369 {
3370 /*
3371 * ":set all" show all options.
3372 * ":set all&" set all options to their default value.
3373 */
3374 arg += 3;
3375 if (*arg == '&')
3376 {
3377 ++arg;
3378 /* Only for :set command set global value of local options. */
3379 set_options_default(OPT_FREE | opt_flags);
3380 }
3381 else
3382 showoptions(1, opt_flags);
3383 }
3384 else if (STRNCMP(arg, "termcap", 7) == 0)
3385 {
3386 showoptions(2, opt_flags);
3387 show_termcodes();
3388 arg += 7;
3389 }
3390 else
3391 {
3392 prefix = 1;
3393 if (STRNCMP(arg, "no", 2) == 0)
3394 {
3395 prefix = 0;
3396 arg += 2;
3397 }
3398 else if (STRNCMP(arg, "inv", 3) == 0)
3399 {
3400 prefix = 2;
3401 arg += 3;
3402 }
3403
3404 /* find end of name */
3405 key = 0;
3406 if (*arg == '<')
3407 {
3408 nextchar = 0;
3409 opt_idx = -1;
3410 /* look out for <t_>;> */
3411 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3412 len = 5;
3413 else
3414 {
3415 len = 1;
3416 while (arg[len] != NUL && arg[len] != '>')
3417 ++len;
3418 }
3419 if (arg[len] != '>')
3420 {
3421 errmsg = e_invarg;
3422 goto skip;
3423 }
3424 arg[len] = NUL; /* put NUL after name */
3425 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3426 opt_idx = findoption(arg + 1);
3427 arg[len++] = '>'; /* restore '>' */
3428 if (opt_idx == -1)
3429 key = find_key_option(arg + 1);
3430 }
3431 else
3432 {
3433 len = 0;
3434 /*
3435 * The two characters after "t_" may not be alphanumeric.
3436 */
3437 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3438 len = 4;
3439 else
3440 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3441 ++len;
3442 nextchar = arg[len];
3443 arg[len] = NUL; /* put NUL after name */
3444 opt_idx = findoption(arg);
3445 arg[len] = nextchar; /* restore nextchar */
3446 if (opt_idx == -1)
3447 key = find_key_option(arg);
3448 }
3449
3450 /* remember character after option name */
3451 afterchar = arg[len];
3452
3453 /* skip white space, allow ":set ai ?" */
3454 while (vim_iswhite(arg[len]))
3455 ++len;
3456
3457 adding = FALSE;
3458 prepending = FALSE;
3459 removing = FALSE;
3460 if (arg[len] != NUL && arg[len + 1] == '=')
3461 {
3462 if (arg[len] == '+')
3463 {
3464 adding = TRUE; /* "+=" */
3465 ++len;
3466 }
3467 else if (arg[len] == '^')
3468 {
3469 prepending = TRUE; /* "^=" */
3470 ++len;
3471 }
3472 else if (arg[len] == '-')
3473 {
3474 removing = TRUE; /* "-=" */
3475 ++len;
3476 }
3477 }
3478 nextchar = arg[len];
3479
3480 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3481 {
3482 errmsg = (char_u *)N_("E518: Unknown option");
3483 goto skip;
3484 }
3485
3486 if (opt_idx >= 0)
3487 {
3488 if (options[opt_idx].var == NULL) /* hidden option: skip */
3489 {
3490 /* Only give an error message when requesting the value of
3491 * a hidden option, ignore setting it. */
3492 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3493 && (!(options[opt_idx].flags & P_BOOL)
3494 || nextchar == '?'))
3495 errmsg = (char_u *)N_("E519: Option not supported");
3496 goto skip;
3497 }
3498
3499 flags = options[opt_idx].flags;
3500 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3501 }
3502 else
3503 {
3504 flags = P_STRING;
3505 if (key < 0)
3506 {
3507 key_name[0] = KEY2TERMCAP0(key);
3508 key_name[1] = KEY2TERMCAP1(key);
3509 }
3510 else
3511 {
3512 key_name[0] = KS_KEY;
3513 key_name[1] = (key & 0xff);
3514 }
3515 }
3516
3517 /* Disallow changing some options from modelines */
3518 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3519 {
3520 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3521 goto skip;
3522 }
3523
3524#ifdef HAVE_SANDBOX
3525 /* Disallow changing some options in the sandbox */
3526 if (sandbox > 0 && (flags & P_SECURE))
3527 {
3528 errmsg = (char_u *)_(e_sandbox);
3529 goto skip;
3530 }
3531#endif
3532
3533 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3534 {
3535 arg += len;
3536 cp_val = p_cp;
3537 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3538 {
3539 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3540 {
3541 cp_val = FALSE;
3542 arg += 3;
3543 }
3544 else /* "opt&vi": set to Vi default */
3545 {
3546 cp_val = TRUE;
3547 arg += 2;
3548 }
3549 }
3550 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3551 && arg[1] != NUL && !vim_iswhite(arg[1]))
3552 {
3553 errmsg = e_trailing;
3554 goto skip;
3555 }
3556 }
3557
3558 /*
3559 * allow '=' and ':' as MSDOS command.com allows only one
3560 * '=' character per "set" command line. grrr. (jw)
3561 */
3562 if (nextchar == '?'
3563 || (prefix == 1
3564 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
3565 && !(flags & P_BOOL)))
3566 {
3567 /*
3568 * print value
3569 */
3570 if (did_show)
3571 msg_putchar('\n'); /* cursor below last one */
3572 else
3573 {
3574 gotocmdline(TRUE); /* cursor at status line */
3575 did_show = TRUE; /* remember that we did a line */
3576 }
3577 if (opt_idx >= 0)
3578 {
3579 showoneopt(&options[opt_idx], opt_flags);
3580#ifdef FEAT_EVAL
3581 if (p_verbose > 0)
3582 {
3583 if (options[opt_idx].scriptID != 0)
3584 {
3585 MSG_PUTS(_("\n\tLast set from "));
3586 MSG_PUTS(get_scriptname(options[opt_idx].scriptID));
3587 }
3588 }
3589#endif
3590 }
3591 else
3592 {
3593 char_u *p;
3594
3595 p = find_termcode(key_name);
3596 if (p == NULL)
3597 {
3598 errmsg = (char_u *)N_("E518: Unknown option");
3599 goto skip;
3600 }
3601 else
3602 (void)show_one_termcode(key_name, p, TRUE);
3603 }
3604 if (nextchar != '?'
3605 && nextchar != NUL && !vim_iswhite(afterchar))
3606 errmsg = e_trailing;
3607 }
3608 else
3609 {
3610 if (flags & P_BOOL) /* boolean */
3611 {
3612 if (nextchar == '=' || nextchar == ':')
3613 {
3614 errmsg = e_invarg;
3615 goto skip;
3616 }
3617
3618 /*
3619 * ":set opt!": invert
3620 * ":set opt&": reset to default value
3621 * ":set opt<": reset to global value
3622 */
3623 if (nextchar == '!')
3624 value = *(int *)(varp) ^ 1;
3625 else if (nextchar == '&')
3626 value = (int)(long)options[opt_idx].def_val[
3627 ((flags & P_VI_DEF) || cp_val)
3628 ? VI_DEFAULT : VIM_DEFAULT];
3629 else if (nextchar == '<')
3630 {
3631 /* For 'autoread' -1 means to use global value. */
3632 if ((int *)varp == &curbuf->b_p_ar
3633 && opt_flags == OPT_LOCAL)
3634 value = -1;
3635 else
3636 value = *(int *)get_varp_scope(&(options[opt_idx]),
3637 OPT_GLOBAL);
3638 }
3639 else
3640 {
3641 /*
3642 * ":set invopt": invert
3643 * ":set opt" or ":set noopt": set or reset
3644 */
3645 if (nextchar != NUL && !vim_iswhite(afterchar))
3646 {
3647 errmsg = e_trailing;
3648 goto skip;
3649 }
3650 if (prefix == 2) /* inv */
3651 value = *(int *)(varp) ^ 1;
3652 else
3653 value = prefix;
3654 }
3655
3656 errmsg = set_bool_option(opt_idx, varp, (int)value,
3657 opt_flags);
3658 }
3659 else /* numeric or string */
3660 {
3661 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
3662 || prefix != 1)
3663 {
3664 errmsg = e_invarg;
3665 goto skip;
3666 }
3667
3668 if (flags & P_NUM) /* numeric */
3669 {
3670 /*
3671 * Different ways to set a number option:
3672 * & set to default value
3673 * < set to global value
3674 * <xx> accept special key codes for 'wildchar'
3675 * c accept any non-digit for 'wildchar'
3676 * [-]0-9 set number
3677 * other error
3678 */
3679 ++arg;
3680 if (nextchar == '&')
3681 value = (long)options[opt_idx].def_val[
3682 ((flags & P_VI_DEF) || cp_val)
3683 ? VI_DEFAULT : VIM_DEFAULT];
3684 else if (nextchar == '<')
3685 value = *(long *)get_varp_scope(&(options[opt_idx]),
3686 OPT_GLOBAL);
3687 else if (((long *)varp == &p_wc
3688 || (long *)varp == &p_wcm)
3689 && (*arg == '<'
3690 || *arg == '^'
3691 || ((!arg[1] || vim_iswhite(arg[1]))
3692 && !VIM_ISDIGIT(*arg))))
3693 {
3694 value = string_to_key(arg);
3695 if (value == 0 && (long *)varp != &p_wcm)
3696 {
3697 errmsg = e_invarg;
3698 goto skip;
3699 }
3700 }
3701 /* allow negative numbers (for 'undolevels') */
3702 else if (*arg == '-' || VIM_ISDIGIT(*arg))
3703 {
3704 i = 0;
3705 if (*arg == '-')
3706 i = 1;
3707#ifdef HAVE_STRTOL
3708 value = strtol((char *)arg, NULL, 0);
3709 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
3710 i += 2;
3711#else
3712 value = atol((char *)arg);
3713#endif
3714 while (VIM_ISDIGIT(arg[i]))
3715 ++i;
3716 if (arg[i] != NUL && !vim_iswhite(arg[i]))
3717 {
3718 errmsg = e_invarg;
3719 goto skip;
3720 }
3721 }
3722 else
3723 {
3724 errmsg = (char_u *)N_("E521: Number required after =");
3725 goto skip;
3726 }
3727
3728 if (adding)
3729 value = *(long *)varp + value;
3730 if (prepending)
3731 value = *(long *)varp * value;
3732 if (removing)
3733 value = *(long *)varp - value;
3734 errmsg = set_num_option(opt_idx, varp, value,
3735 errbuf, opt_flags);
3736 }
3737 else if (opt_idx >= 0) /* string */
3738 {
3739 char_u *save_arg = NULL;
3740 char_u *s = NULL;
3741 char_u *oldval; /* previous value if *varp */
3742 char_u *newval;
3743 char_u *origval;
3744 unsigned newlen;
3745 int comma;
3746 int bs;
3747 int new_value_alloced; /* new string option
3748 was allocated */
3749
3750 /* When using ":set opt=val" for a global option
3751 * with a local value the local value will be
3752 * reset, use the global value here. */
3753 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
3754 && (int)options[opt_idx].indir >= PV_BOTH)
3755 varp = options[opt_idx].var;
3756
3757 /* The old value is kept until we are sure that the
3758 * new value is valid. */
3759 oldval = *(char_u **)varp;
3760 if (nextchar == '&') /* set to default val */
3761 {
3762 newval = options[opt_idx].def_val[
3763 ((flags & P_VI_DEF) || cp_val)
3764 ? VI_DEFAULT : VIM_DEFAULT];
3765 if ((char_u **)varp == &p_bg)
3766 {
3767 /* guess the value of 'background' */
3768#ifdef FEAT_GUI
3769 if (gui.in_use)
3770 newval = gui_bg_default();
3771 else
3772#endif
3773 if (STRCMP(T_NAME, "linux") == 0)
3774 newval = (char_u *)"dark";
3775 }
3776
3777 /* expand environment variables and ~ (since the
3778 * default value was already expanded, only
3779 * required when an environment variable was set
3780 * later */
3781 if (newval == NULL)
3782 newval = empty_option;
3783 else
3784 {
3785 s = option_expand(opt_idx, newval);
3786 if (s == NULL)
3787 s = newval;
3788 newval = vim_strsave(s);
3789 }
3790 new_value_alloced = TRUE;
3791 }
3792 else if (nextchar == '<') /* set to global val */
3793 {
3794 newval = vim_strsave(*(char_u **)get_varp_scope(
3795 &(options[opt_idx]), OPT_GLOBAL));
3796 new_value_alloced = TRUE;
3797 }
3798 else
3799 {
3800 ++arg; /* jump to after the '=' or ':' */
3801
3802 /*
3803 * Set 'keywordprg' to ":help" if an empty
3804 * value was passed to :set by the user.
3805 * Misuse errbuf[] for the resulting string.
3806 */
3807 if (varp == (char_u *)&p_kp
3808 && (*arg == NUL || *arg == ' '))
3809 {
3810 STRCPY(errbuf, ":help");
3811 save_arg = arg;
3812 arg = errbuf;
3813 }
3814 /*
3815 * Convert 'whichwrap' number to string, for
3816 * backwards compatibility with Vim 3.0.
3817 * Misuse errbuf[] for the resulting string.
3818 */
3819 else if (varp == (char_u *)&p_ww
3820 && VIM_ISDIGIT(*arg))
3821 {
3822 *errbuf = NUL;
3823 i = getdigits(&arg);
3824 if (i & 1)
3825 STRCAT(errbuf, "b,");
3826 if (i & 2)
3827 STRCAT(errbuf, "s,");
3828 if (i & 4)
3829 STRCAT(errbuf, "h,l,");
3830 if (i & 8)
3831 STRCAT(errbuf, "<,>,");
3832 if (i & 16)
3833 STRCAT(errbuf, "[,],");
3834 if (*errbuf != NUL) /* remove trailing , */
3835 errbuf[STRLEN(errbuf) - 1] = NUL;
3836 save_arg = arg;
3837 arg = errbuf;
3838 }
3839 /*
3840 * Remove '>' before 'dir' and 'bdir', for
3841 * backwards compatibility with version 3.0
3842 */
3843 else if ( *arg == '>'
3844 && (varp == (char_u *)&p_dir
3845 || varp == (char_u *)&p_bdir))
3846 {
3847 ++arg;
3848 }
3849
3850 /* When setting the local value of a global
3851 * option, the old value may be the global value. */
3852 if ((int)options[opt_idx].indir >= PV_BOTH
3853 && (opt_flags & OPT_LOCAL))
3854 origval = *(char_u **)get_varp(
3855 &options[opt_idx]);
3856 else
3857 origval = oldval;
3858
3859 /*
3860 * Copy the new string into allocated memory.
3861 * Can't use set_string_option_direct(), because
3862 * we need to remove the backslashes.
3863 */
3864 /* get a bit too much */
3865 newlen = (unsigned)STRLEN(arg) + 1;
3866 if (adding || prepending || removing)
3867 newlen += (unsigned)STRLEN(origval) + 1;
3868 newval = alloc(newlen);
3869 if (newval == NULL) /* out of mem, don't change */
3870 break;
3871 s = newval;
3872
3873 /*
3874 * Copy the string, skip over escaped chars.
3875 * For MS-DOS and WIN32 backslashes before normal
3876 * file name characters are not removed, and keep
3877 * backslash at start, for "\\machine\path", but
3878 * do remove it for "\\\\machine\\path".
3879 * The reverse is found in ExpandOldSetting().
3880 */
3881 while (*arg && !vim_iswhite(*arg))
3882 {
3883 if (*arg == '\\' && arg[1] != NUL
3884#ifdef BACKSLASH_IN_FILENAME
3885 && !((flags & P_EXPAND)
3886 && vim_isfilec(arg[1])
3887 && (arg[1] != '\\'
3888 || (s == newval
3889 && arg[2] != '\\')))
3890#endif
3891 )
3892 ++arg; /* remove backslash */
3893#ifdef FEAT_MBYTE
3894 if (has_mbyte
3895 && (i = (*mb_ptr2len_check)(arg)) > 1)
3896 {
3897 /* copy multibyte char */
3898 mch_memmove(s, arg, (size_t)i);
3899 arg += i;
3900 s += i;
3901 }
3902 else
3903#endif
3904 *s++ = *arg++;
3905 }
3906 *s = NUL;
3907
3908 /*
3909 * Expand environment variables and ~.
3910 * Don't do it when adding without inserting a
3911 * comma.
3912 */
3913 if (!(adding || prepending || removing)
3914 || (flags & P_COMMA))
3915 {
3916 s = option_expand(opt_idx, newval);
3917 if (s != NULL)
3918 {
3919 vim_free(newval);
3920 newlen = (unsigned)STRLEN(s) + 1;
3921 if (adding || prepending || removing)
3922 newlen += (unsigned)STRLEN(origval) + 1;
3923 newval = alloc(newlen);
3924 if (newval == NULL)
3925 break;
3926 STRCPY(newval, s);
3927 }
3928 }
3929
3930 /* locate newval[] in origval[] when removing it
3931 * and when adding to avoid duplicates */
3932 i = 0; /* init for GCC */
3933 if (removing || (flags & P_NODUP))
3934 {
3935 i = (int)STRLEN(newval);
3936 bs = 0;
3937 for (s = origval; *s; ++s)
3938 {
3939 if ((!(flags & P_COMMA)
3940 || s == origval
3941 || (s[-1] == ',' && !(bs & 1)))
3942 && STRNCMP(s, newval, i) == 0
3943 && (!(flags & P_COMMA)
3944 || s[i] == ','
3945 || s[i] == NUL))
3946 break;
3947 /* Count backspaces. Only a comma with an
3948 * even number of backspaces before it is
3949 * recognized as a separator */
3950 if (s > origval && s[-1] == '\\')
3951 ++bs;
3952 else
3953 bs = 0;
3954 }
3955
3956 /* do not add if already there */
3957 if ((adding || prepending) && *s)
3958 {
3959 prepending = FALSE;
3960 adding = FALSE;
3961 STRCPY(newval, origval);
3962 }
3963 }
3964
3965 /* concatenate the two strings; add a ',' if
3966 * needed */
3967 if (adding || prepending)
3968 {
3969 comma = ((flags & P_COMMA) && *origval != NUL
3970 && *newval != NUL);
3971 if (adding)
3972 {
3973 i = (int)STRLEN(origval);
3974 mch_memmove(newval + i + comma, newval,
3975 STRLEN(newval) + 1);
3976 mch_memmove(newval, origval, (size_t)i);
3977 }
3978 else
3979 {
3980 i = (int)STRLEN(newval);
3981 mch_memmove(newval + i + comma, origval,
3982 STRLEN(origval) + 1);
3983 }
3984 if (comma)
3985 newval[i] = ',';
3986 }
3987
3988 /* Remove newval[] from origval[]. (Note: "i" has
3989 * been set above and is used here). */
3990 if (removing)
3991 {
3992 STRCPY(newval, origval);
3993 if (*s)
3994 {
3995 /* may need to remove a comma */
3996 if (flags & P_COMMA)
3997 {
3998 if (s == origval)
3999 {
4000 /* include comma after string */
4001 if (s[i] == ',')
4002 ++i;
4003 }
4004 else
4005 {
4006 /* include comma before string */
4007 --s;
4008 ++i;
4009 }
4010 }
4011 mch_memmove(newval + (s - origval), s + i,
4012 STRLEN(s + i) + 1);
4013 }
4014 }
4015
4016 if (flags & P_FLAGLIST)
4017 {
4018 /* Remove flags that appear twice. */
4019 for (s = newval; *s; ++s)
4020 if ((!(flags & P_COMMA) || *s != ',')
4021 && vim_strchr(s + 1, *s) != NULL)
4022 {
4023 STRCPY(s, s + 1);
4024 --s;
4025 }
4026 }
4027
4028 if (save_arg != NULL) /* number for 'whichwrap' */
4029 arg = save_arg;
4030 new_value_alloced = TRUE;
4031 }
4032
4033 /* Set the new value. */
4034 *(char_u **)(varp) = newval;
4035
4036 /* Handle side effects, and set the global value for
4037 * ":set" on local options. */
4038 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4039 new_value_alloced, oldval, errbuf, opt_flags);
4040
4041 /* If error detected, print the error message. */
4042 if (errmsg != NULL)
4043 goto skip;
4044 }
4045 else /* key code option */
4046 {
4047 char_u *p;
4048
4049 if (nextchar == '&')
4050 {
4051 if (add_termcap_entry(key_name, TRUE) == FAIL)
4052 errmsg = (char_u *)N_("E522: Not found in termcap");
4053 }
4054 else
4055 {
4056 ++arg; /* jump to after the '=' or ':' */
4057 for (p = arg; *p && !vim_iswhite(*p); ++p)
4058 if (*p == '\\' && p[1] != NUL)
4059 ++p;
4060 nextchar = *p;
4061 *p = NUL;
4062 add_termcode(key_name, arg, FALSE);
4063 *p = nextchar;
4064 }
4065 if (full_screen)
4066 ttest(FALSE);
4067 redraw_all_later(CLEAR);
4068 }
4069 }
4070 if (opt_idx >= 0)
4071 options[opt_idx].flags |= P_WAS_SET;
4072 }
4073
4074skip:
4075 /*
4076 * Advance to next argument.
4077 * - skip until a blank found, taking care of backslashes
4078 * - skip blanks
4079 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4080 */
4081 for (i = 0; i < 2 ; ++i)
4082 {
4083 while (*arg != NUL && !vim_iswhite(*arg))
4084 if (*arg++ == '\\' && *arg != NUL)
4085 ++arg;
4086 arg = skipwhite(arg);
4087 if (*arg != '=')
4088 break;
4089 }
4090 }
4091
4092 if (errmsg != NULL)
4093 {
4094 STRNCPY(IObuff, _(errmsg), IOSIZE - 1);
4095 IObuff[IOSIZE - 1] = NUL;
4096 i = STRLEN(IObuff) + 2;
4097 if (i + (arg - startarg) < IOSIZE)
4098 {
4099 /* append the argument with the error */
4100 STRCAT(IObuff, ": ");
4101 mch_memmove(IObuff + i, startarg, (arg - startarg));
4102 IObuff[i + (arg - startarg)] = NUL;
4103 }
4104 /* make sure all characters are printable */
4105 trans_characters(IObuff, IOSIZE);
4106
4107 ++no_wait_return; /* wait_return done later */
4108 emsg(IObuff); /* show error highlighted */
4109 --no_wait_return;
4110
4111 return FAIL;
4112 }
4113
4114 arg = skipwhite(arg);
4115 }
4116
4117 return OK;
4118}
4119
4120 static char_u *
4121illegal_char(errbuf, c)
4122 char_u *errbuf;
4123 int c;
4124{
4125 if (errbuf == NULL)
4126 return (char_u *)"";
4127 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
4128 (char *)transchar(c));
4129 return errbuf;
4130}
4131
4132/*
4133 * Convert a key name or string into a key value.
4134 * Used for 'wildchar' and 'cedit' options.
4135 */
4136 static int
4137string_to_key(arg)
4138 char_u *arg;
4139{
4140 if (*arg == '<')
4141 return find_key_option(arg + 1);
4142 if (*arg == '^')
4143 return Ctrl_chr(arg[1]);
4144 return *arg;
4145}
4146
4147#ifdef FEAT_CMDWIN
4148/*
4149 * Check value of 'cedit' and set cedit_key.
4150 * Returns NULL if value is OK, error message otherwise.
4151 */
4152 static char_u *
4153check_cedit()
4154{
4155 int n;
4156
4157 if (*p_cedit == NUL)
4158 cedit_key = -1;
4159 else
4160 {
4161 n = string_to_key(p_cedit);
4162 if (vim_isprintc(n))
4163 return e_invarg;
4164 cedit_key = n;
4165 }
4166 return NULL;
4167}
4168#endif
4169
4170#ifdef FEAT_TITLE
4171/*
4172 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4173 * maketitle() to create and display it.
4174 * When switching the title or icon off, call mch_restore_title() to get
4175 * the old value back.
4176 */
4177 static void
4178did_set_title(icon)
4179 int icon; /* Did set icon instead of title */
4180{
4181 if (starting != NO_SCREEN
4182#ifdef FEAT_GUI
4183 && !gui.starting
4184#endif
4185 )
4186 {
4187 maketitle();
4188 if (icon)
4189 {
4190 if (!p_icon)
4191 mch_restore_title(2);
4192 }
4193 else
4194 {
4195 if (!p_title)
4196 mch_restore_title(1);
4197 }
4198 }
4199}
4200#endif
4201
4202/*
4203 * set_options_bin - called when 'bin' changes value.
4204 */
4205 void
4206set_options_bin(oldval, newval, opt_flags)
4207 int oldval;
4208 int newval;
4209 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4210{
4211 /*
4212 * The option values that are changed when 'bin' changes are
4213 * copied when 'bin is set and restored when 'bin' is reset.
4214 */
4215 if (newval)
4216 {
4217 if (!oldval) /* switched on */
4218 {
4219 if (!(opt_flags & OPT_GLOBAL))
4220 {
4221 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4222 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4223 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4224 curbuf->b_p_et_nobin = curbuf->b_p_et;
4225 }
4226 if (!(opt_flags & OPT_LOCAL))
4227 {
4228 p_tw_nobin = p_tw;
4229 p_wm_nobin = p_wm;
4230 p_ml_nobin = p_ml;
4231 p_et_nobin = p_et;
4232 }
4233 }
4234
4235 if (!(opt_flags & OPT_GLOBAL))
4236 {
4237 curbuf->b_p_tw = 0; /* no automatic line wrap */
4238 curbuf->b_p_wm = 0; /* no automatic line wrap */
4239 curbuf->b_p_ml = 0; /* no modelines */
4240 curbuf->b_p_et = 0; /* no expandtab */
4241 }
4242 if (!(opt_flags & OPT_LOCAL))
4243 {
4244 p_tw = 0;
4245 p_wm = 0;
4246 p_ml = FALSE;
4247 p_et = FALSE;
4248 p_bin = TRUE; /* needed when called for the "-b" argument */
4249 }
4250 }
4251 else if (oldval) /* switched off */
4252 {
4253 if (!(opt_flags & OPT_GLOBAL))
4254 {
4255 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4256 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4257 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4258 curbuf->b_p_et = curbuf->b_p_et_nobin;
4259 }
4260 if (!(opt_flags & OPT_LOCAL))
4261 {
4262 p_tw = p_tw_nobin;
4263 p_wm = p_wm_nobin;
4264 p_ml = p_ml_nobin;
4265 p_et = p_et_nobin;
4266 }
4267 }
4268}
4269
4270#ifdef FEAT_VIMINFO
4271/*
4272 * Find the parameter represented by the given character (eg ', :, ", or /),
4273 * and return its associated value in the 'viminfo' string.
4274 * Only works for number parameters, not for 'r' or 'n'.
4275 * If the parameter is not specified in the string, return -1.
4276 */
4277 int
4278get_viminfo_parameter(type)
4279 int type;
4280{
4281 char_u *p;
4282
4283 p = find_viminfo_parameter(type);
4284 if (p != NULL && VIM_ISDIGIT(*p))
4285 return atoi((char *)p);
4286 return -1;
4287}
4288
4289/*
4290 * Find the parameter represented by the given character (eg ''', ':', '"', or
4291 * '/') in the 'viminfo' option and return a pointer to the string after it.
4292 * Return NULL if the parameter is not specified in the string.
4293 */
4294 char_u *
4295find_viminfo_parameter(type)
4296 int type;
4297{
4298 char_u *p;
4299
4300 for (p = p_viminfo; *p; ++p)
4301 {
4302 if (*p == type)
4303 return p + 1;
4304 if (*p == 'n') /* 'n' is always the last one */
4305 break;
4306 p = vim_strchr(p, ','); /* skip until next ',' */
4307 if (p == NULL) /* hit the end without finding parameter */
4308 break;
4309 }
4310 return NULL;
4311}
4312#endif
4313
4314/*
4315 * Expand environment variables for some string options.
4316 * These string options cannot be indirect!
4317 * If "val" is NULL expand the current value of the option.
4318 * Return pointer to NameBuff, or NULL when not expanded.
4319 */
4320 static char_u *
4321option_expand(opt_idx, val)
4322 int opt_idx;
4323 char_u *val;
4324{
4325 /* if option doesn't need expansion nothing to do */
4326 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4327 return NULL;
4328
4329 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4330 * expand_env() would truncate the string. */
4331 if (val != NULL && STRLEN(val) > MAXPATHL)
4332 return NULL;
4333
4334 if (val == NULL)
4335 val = *(char_u **)options[opt_idx].var;
4336
4337 /*
4338 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4339 * Escape spaces when expanding 'tags', they are used to separate file
4340 * names.
4341 */
4342 expand_env_esc(val, NameBuff, MAXPATHL,
4343 (char_u **)options[opt_idx].var == &p_tags);
4344 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4345 return NULL;
4346
4347 return NameBuff;
4348}
4349
4350/*
4351 * After setting various option values: recompute variables that depend on
4352 * option values.
4353 */
4354 static void
4355didset_options()
4356{
4357 /* initialize the table for 'iskeyword' et.al. */
4358 (void)init_chartab();
4359
4360 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4361 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4362#ifdef FEAT_SESSION
4363 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4364 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4365#endif
4366#ifdef FEAT_FOLDING
4367 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4368#endif
4369 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4370#ifdef FEAT_VIRTUALEDIT
4371 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4372#endif
4373#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4374 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4375#endif
4376#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4377 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4378#endif
4379#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4380 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4381#endif
4382#ifdef FEAT_CMDWIN
4383 /* set cedit_key */
4384 (void)check_cedit();
4385#endif
4386}
4387
4388/*
4389 * Check for string options that are NULL (normally only termcap options).
4390 */
4391 void
4392check_options()
4393{
4394 int opt_idx;
4395
4396 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4397 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4398 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4399}
4400
4401/*
4402 * Check string options in a buffer for NULL value.
4403 */
4404 void
4405check_buf_options(buf)
4406 buf_T *buf;
4407{
4408#if defined(FEAT_QUICKFIX)
4409 check_string_option(&buf->b_p_bh);
4410 check_string_option(&buf->b_p_bt);
4411#endif
4412#ifdef FEAT_MBYTE
4413 check_string_option(&buf->b_p_fenc);
4414#endif
4415 check_string_option(&buf->b_p_ff);
4416#ifdef FEAT_FIND_ID
4417 check_string_option(&buf->b_p_def);
4418 check_string_option(&buf->b_p_inc);
4419# ifdef FEAT_EVAL
4420 check_string_option(&buf->b_p_inex);
4421# endif
4422#endif
4423#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4424 check_string_option(&buf->b_p_inde);
4425 check_string_option(&buf->b_p_indk);
4426#endif
4427#ifdef FEAT_CRYPT
4428 check_string_option(&buf->b_p_key);
4429#endif
4430 check_string_option(&buf->b_p_kp);
4431 check_string_option(&buf->b_p_mps);
4432 check_string_option(&buf->b_p_fo);
4433 check_string_option(&buf->b_p_isk);
4434#ifdef FEAT_COMMENTS
4435 check_string_option(&buf->b_p_com);
4436#endif
4437#ifdef FEAT_FOLDING
4438 check_string_option(&buf->b_p_cms);
4439#endif
4440 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004441#ifdef FEAT_TEXTOBJ
4442 check_string_option(&buf->b_p_qe);
4443#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004444#ifdef FEAT_SYN_HL
4445 check_string_option(&buf->b_p_syn);
4446#endif
4447#ifdef FEAT_SEARCHPATH
4448 check_string_option(&buf->b_p_sua);
4449#endif
4450#ifdef FEAT_CINDENT
4451 check_string_option(&buf->b_p_cink);
4452 check_string_option(&buf->b_p_cino);
4453#endif
4454#ifdef FEAT_AUTOCMD
4455 check_string_option(&buf->b_p_ft);
4456#endif
4457#ifdef FEAT_OSFILETYPE
4458 check_string_option(&buf->b_p_oft);
4459#endif
4460#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4461 check_string_option(&buf->b_p_cinw);
4462#endif
4463#ifdef FEAT_INS_EXPAND
4464 check_string_option(&buf->b_p_cpt);
4465#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004466#ifdef FEAT_COMPL_FUNC
4467 check_string_option(&buf->b_p_cfu);
4468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004469#ifdef FEAT_KEYMAP
4470 check_string_option(&buf->b_p_keymap);
4471#endif
4472#ifdef FEAT_QUICKFIX
4473 check_string_option(&buf->b_p_gp);
4474 check_string_option(&buf->b_p_mp);
4475 check_string_option(&buf->b_p_efm);
4476#endif
4477 check_string_option(&buf->b_p_ep);
4478 check_string_option(&buf->b_p_path);
4479 check_string_option(&buf->b_p_tags);
4480#ifdef FEAT_INS_EXPAND
4481 check_string_option(&buf->b_p_dict);
4482 check_string_option(&buf->b_p_tsr);
4483#endif
4484}
4485
4486/*
4487 * Free the string allocated for an option.
4488 * Checks for the string being empty_option. This may happen if we're out of
4489 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4490 * check_options().
4491 * Does NOT check for P_ALLOCED flag!
4492 */
4493 void
4494free_string_option(p)
4495 char_u *p;
4496{
4497 if (p != empty_option)
4498 vim_free(p);
4499}
4500
4501 void
4502clear_string_option(pp)
4503 char_u **pp;
4504{
4505 if (*pp != empty_option)
4506 vim_free(*pp);
4507 *pp = empty_option;
4508}
4509
4510 static void
4511check_string_option(pp)
4512 char_u **pp;
4513{
4514 if (*pp == NULL)
4515 *pp = empty_option;
4516}
4517
4518/*
4519 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4520 */
4521 void
4522set_term_option_alloced(p)
4523 char_u **p;
4524{
4525 int opt_idx;
4526
4527 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4528 if (options[opt_idx].var == (char_u *)p)
4529 {
4530 options[opt_idx].flags |= P_ALLOCED;
4531 return;
4532 }
4533 return; /* cannot happen: didn't find it! */
4534}
4535
4536/*
4537 * Set a string option to a new value (without checking the effect).
4538 * The string is copied into allocated memory.
4539 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4540 */
4541 void
4542set_string_option_direct(name, opt_idx, val, opt_flags)
4543 char_u *name;
4544 int opt_idx;
4545 char_u *val;
4546 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4547{
4548 char_u *s;
4549 char_u **varp;
4550 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
4551
4552 if (opt_idx == -1) /* use name */
4553 {
4554 opt_idx = findoption(name);
4555 if (opt_idx == -1) /* not found (should not happen) */
4556 return;
4557 }
4558
4559 if (options[opt_idx].var == NULL) /* can't set hidden option */
4560 return;
4561
4562 s = vim_strsave(val);
4563 if (s != NULL)
4564 {
4565 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4566 both ? OPT_LOCAL : opt_flags);
4567 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
4568 free_string_option(*varp);
4569 *varp = s;
4570
4571 /* For buffer/window local option may also set the global value. */
4572 if (both)
4573 set_string_option_global(opt_idx, varp);
4574
4575 options[opt_idx].flags |= P_ALLOCED;
4576
4577 /* When setting both values of a global option with a local value,
4578 * make the local value empty, so that the global value is used. */
4579 if ((int)options[opt_idx].indir >= PV_BOTH && both)
4580 {
4581 free_string_option(*varp);
4582 *varp = empty_option;
4583 }
4584 }
4585}
4586
4587/*
4588 * Set global value for string option when it's a local option.
4589 */
4590 static void
4591set_string_option_global(opt_idx, varp)
4592 int opt_idx; /* option index */
4593 char_u **varp; /* pointer to option variable */
4594{
4595 char_u **p, *s;
4596
4597 /* the global value is always allocated */
4598 if (options[opt_idx].var == VAR_WIN)
4599 p = (char_u **)GLOBAL_WO(varp);
4600 else
4601 p = (char_u **)options[opt_idx].var;
4602 if (options[opt_idx].indir != PV_NONE
4603 && p != varp
4604 && (s = vim_strsave(*varp)) != NULL)
4605 {
4606 free_string_option(*p);
4607 *p = s;
4608 }
4609}
4610
4611/*
4612 * Set a string option to a new value, and handle the effects.
4613 */
4614 static void
4615set_string_option(opt_idx, value, opt_flags)
4616 int opt_idx;
4617 char_u *value;
4618 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4619{
4620 char_u *s;
4621 char_u **varp;
4622 char_u *oldval;
4623
4624 if (options[opt_idx].var == NULL) /* don't set hidden option */
4625 return;
4626
4627 s = vim_strsave(value);
4628 if (s != NULL)
4629 {
4630 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4631 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4632 ? ((int)options[opt_idx].indir >= PV_BOTH
4633 ? OPT_GLOBAL : OPT_LOCAL)
4634 : opt_flags);
4635 oldval = *varp;
4636 *varp = s;
4637 options[opt_idx].flags |= P_WAS_SET;
4638 (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
4639 opt_flags);
4640 }
4641}
4642
4643/*
4644 * Handle string options that need some action to perform when changed.
4645 * Returns NULL for success, or an error message for an error.
4646 */
4647 static char_u *
4648did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
4649 opt_flags)
4650 int opt_idx; /* index in options[] table */
4651 char_u **varp; /* pointer to the option variable */
4652 int new_value_alloced; /* new value was allocated */
4653 char_u *oldval; /* previous value of the option */
4654 char_u *errbuf; /* buffer for errors, or NULL */
4655 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4656{
4657 char_u *errmsg = NULL;
4658 char_u *s, *p;
4659 int did_chartab = FALSE;
4660 char_u **gvarp;
4661
4662 /* Get the global option to compare with, otherwise we would have to check
4663 * two values for all local options. */
4664 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
4665
4666 /* Disallow changing some options from secure mode */
4667 if ((secure
4668#ifdef HAVE_SANDBOX
4669 || sandbox != 0
4670#endif
4671 ) && (options[opt_idx].flags & P_SECURE))
4672 {
4673 errmsg = e_secure;
4674 }
4675
4676 /* 'term' */
4677 else if (varp == &T_NAME)
4678 {
4679 if (T_NAME[0] == NUL)
4680 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
4681#ifdef FEAT_GUI
4682 if (gui.in_use)
4683 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
4684 else if (term_is_gui(T_NAME))
4685 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
4686#endif
4687 else if (set_termname(T_NAME) == FAIL)
4688 errmsg = (char_u *)N_("E522: Not found in termcap");
4689 else
4690 /* Screen colors may have changed. */
4691 redraw_later_clear();
4692 }
4693
4694 /* 'backupcopy' */
4695 else if (varp == &p_bkc)
4696 {
4697 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
4698 errmsg = e_invarg;
4699 if (((bkc_flags & BKC_AUTO) != 0)
4700 + ((bkc_flags & BKC_YES) != 0)
4701 + ((bkc_flags & BKC_NO) != 0) != 1)
4702 {
4703 /* Must have exactly one of "auto", "yes" and "no". */
4704 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
4705 errmsg = e_invarg;
4706 }
4707 }
4708
4709 /* 'backupext' and 'patchmode' */
4710 else if (varp == &p_bex || varp == &p_pm)
4711 {
4712 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
4713 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
4714 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
4715 }
4716
4717 /*
4718 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
4719 * If the new option is invalid, use old value. 'lisp' option: refill
4720 * chartab[] for '-' char
4721 */
4722 else if ( varp == &p_isi
4723 || varp == &(curbuf->b_p_isk)
4724 || varp == &p_isp
4725 || varp == &p_isf)
4726 {
4727 if (init_chartab() == FAIL)
4728 {
4729 did_chartab = TRUE; /* need to restore it below */
4730 errmsg = e_invarg; /* error in value */
4731 }
4732 }
4733
4734 /* 'helpfile' */
4735 else if (varp == &p_hf)
4736 {
4737 /* May compute new values for $VIM and $VIMRUNTIME */
4738 if (didset_vim)
4739 {
4740 vim_setenv((char_u *)"VIM", (char_u *)"");
4741 didset_vim = FALSE;
4742 }
4743 if (didset_vimruntime)
4744 {
4745 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
4746 didset_vimruntime = FALSE;
4747 }
4748 }
4749
4750#ifdef FEAT_MULTI_LANG
4751 /* 'helplang' */
4752 else if (varp == &p_hlg)
4753 {
4754 /* Check for "", "ab", "ab,cd", etc. */
4755 for (s = p_hlg; *s != NUL; s += 3)
4756 {
4757 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
4758 {
4759 errmsg = e_invarg;
4760 break;
4761 }
4762 if (s[2] == NUL)
4763 break;
4764 }
4765 }
4766#endif
4767
4768 /* 'highlight' */
4769 else if (varp == &p_hl)
4770 {
4771 if (highlight_changed() == FAIL)
4772 errmsg = e_invarg; /* invalid flags */
4773 }
4774
4775 /* 'nrformats' */
4776 else if (gvarp == &p_nf)
4777 {
4778 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
4779 errmsg = e_invarg;
4780 }
4781
4782#ifdef FEAT_SESSION
4783 /* 'sessionoptions' */
4784 else if (varp == &p_ssop)
4785 {
4786 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
4787 errmsg = e_invarg;
4788 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
4789 {
4790 /* Don't allow both "sesdir" and "curdir". */
4791 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
4792 errmsg = e_invarg;
4793 }
4794 }
4795 /* 'viewoptions' */
4796 else if (varp == &p_vop)
4797 {
4798 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
4799 errmsg = e_invarg;
4800 }
4801#endif
4802
4803 /* 'scrollopt' */
4804#ifdef FEAT_SCROLLBIND
4805 else if (varp == &p_sbo)
4806 {
4807 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
4808 errmsg = e_invarg;
4809 }
4810#endif
4811
4812 /* 'ambiwidth' */
4813#ifdef FEAT_MBYTE
4814 else if (varp == &p_ambw)
4815 {
4816 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
4817 errmsg = e_invarg;
4818 }
4819#endif
4820
4821 /* 'background' */
4822 else if (varp == &p_bg)
4823 {
4824 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
4825 {
4826#ifdef FEAT_EVAL
4827 int dark = (*p_bg == 'd');
4828#endif
4829
4830 init_highlight(FALSE, FALSE);
4831
4832#ifdef FEAT_EVAL
4833 if (dark != (*p_bg == 'd')
4834 && get_var_value((char_u *)"g:colors_name") != NULL)
4835 {
4836 /* The color scheme must have set 'background' back to another
4837 * value, that's not what we want here. Disable the color
4838 * scheme and set the colors again. */
4839 do_unlet((char_u *)"g:colors_name");
4840 free_string_option(p_bg);
4841 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
4842 check_string_option(&p_bg);
4843 init_highlight(FALSE, FALSE);
4844 }
4845#endif
4846 }
4847 else
4848 errmsg = e_invarg;
4849 }
4850
4851 /* 'wildmode' */
4852 else if (varp == &p_wim)
4853 {
4854 if (check_opt_wim() == FAIL)
4855 errmsg = e_invarg;
4856 }
4857
4858#ifdef FEAT_WAK
4859 /* 'winaltkeys' */
4860 else if (varp == &p_wak)
4861 {
4862 if (*p_wak == NUL
4863 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
4864 errmsg = e_invarg;
4865# ifdef FEAT_MENU
4866# ifdef FEAT_GUI_MOTIF
4867 else if (gui.in_use)
4868 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
4869# else
4870# ifdef FEAT_GUI_GTK
4871 else if (gui.in_use)
4872 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
4873# endif
4874# endif
4875# endif
4876 }
4877#endif
4878
4879#ifdef FEAT_AUTOCMD
4880 /* 'eventignore' */
4881 else if (varp == &p_ei)
4882 {
4883 if (check_ei() == FAIL)
4884 errmsg = e_invarg;
4885 }
4886#endif
4887
4888#ifdef FEAT_MBYTE
4889 /* 'encoding' and 'fileencoding' */
4890 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
4891 {
4892 if (gvarp == &p_fenc)
4893 {
4894 if (!curbuf->b_p_ma)
4895 errmsg = e_modifiable;
4896 else if (vim_strchr(*varp, ',') != NULL)
4897 /* No comma allowed in 'fileencoding'; catches confusing it
4898 * with 'fileencodings'. */
4899 errmsg = e_invarg;
4900# ifdef FEAT_TITLE
4901 else
4902 /* May show a "+" in the title now. */
4903 need_maketitle = TRUE;
4904# endif
4905 }
4906 if (errmsg == NULL)
4907 {
4908 /* canonize the value, so that STRCMP() can be used on it */
4909 p = enc_canonize(*varp);
4910 if (p != NULL)
4911 {
4912 vim_free(*varp);
4913 *varp = p;
4914 }
4915 if (varp == &p_enc)
4916 {
4917 errmsg = mb_init();
4918# ifdef FEAT_TITLE
4919 need_maketitle = TRUE;
4920# endif
4921 }
4922 }
4923
4924# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4925 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
4926 {
4927 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
4928 if (STRCMP(p_tenc, "utf-8") != 0)
4929 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
4930 }
4931# endif
4932
4933 if (errmsg == NULL)
4934 {
4935# ifdef FEAT_KEYMAP
4936 /* When 'keymap' is used and 'encoding' changes, reload the keymap
4937 * (with another encoding). */
4938 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
4939 (void)keymap_init();
4940# endif
4941
4942 /* When 'termencoding' is not empty and 'encoding' changes or when
4943 * 'termencoding' changes, need to setup for keyboard input and
4944 * display output conversion. */
4945 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
4946 {
4947 convert_setup(&input_conv, p_tenc, p_enc);
4948 convert_setup(&output_conv, p_enc, p_tenc);
4949 }
4950 }
4951 }
4952#endif
4953
4954#if defined(FEAT_POSTSCRIPT)
4955 else if (varp == &p_penc)
4956 {
4957 /* Canonize printencoding if VIM standard one */
4958 p = enc_canonize(p_penc);
4959 if (p != NULL)
4960 {
4961 vim_free(p_penc);
4962 p_penc = p;
4963 }
4964 else
4965 {
4966 /* Ensure lower case and '-' for '_' */
4967 for (s = p_penc; *s != NUL; s++)
4968 {
4969 if (*s == '_')
4970 *s = '-';
4971 else
4972 *s = TOLOWER_ASC(*s);
4973 }
4974 }
4975 }
4976#endif
4977
Bram Moolenaar843ee412004-06-30 16:16:41 +00004978#if defined(FEAT_XIM) && ( defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004979 else if (varp == &p_imak)
4980 {
4981 if (gui.in_use && !im_xim_isvalid_imactivate())
4982 errmsg = e_invarg;
4983 }
4984#endif
4985
4986#ifdef FEAT_KEYMAP
4987 else if (varp == &curbuf->b_p_keymap)
4988 {
4989 /* load or unload key mapping tables */
4990 errmsg = keymap_init();
4991
4992 /* When successfully installed a new keymap switch on using it. */
4993 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
4994 {
4995 curbuf->b_p_iminsert = B_IMODE_LMAP;
4996 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
4997 curbuf->b_p_imsearch = B_IMODE_LMAP;
4998 set_iminsert_global();
4999 set_imsearch_global();
5000# ifdef FEAT_WINDOWS
5001 status_redraw_curbuf();
5002# endif
5003 }
5004 }
5005#endif
5006
5007 /* 'fileformat' */
5008 else if (gvarp == &p_ff)
5009 {
5010 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5011 errmsg = e_modifiable;
5012 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5013 errmsg = e_invarg;
5014 else
5015 {
5016 /* may also change 'textmode' */
5017 if (get_fileformat(curbuf) == EOL_DOS)
5018 curbuf->b_p_tx = TRUE;
5019 else
5020 curbuf->b_p_tx = FALSE;
5021#ifdef FEAT_TITLE
5022 need_maketitle = TRUE;
5023#endif
5024 }
5025 }
5026
5027 /* 'fileformats' */
5028 else if (varp == &p_ffs)
5029 {
5030 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5031 errmsg = e_invarg;
5032 else
5033 {
5034 /* also change 'textauto' */
5035 if (*p_ffs == NUL)
5036 p_ta = FALSE;
5037 else
5038 p_ta = TRUE;
5039 }
5040 }
5041
5042#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5043 /* 'cryptkey' */
5044 else if (gvarp == &p_key)
5045 {
5046 /* Make sure the ":set" command doesn't show the new value in the
5047 * history. */
5048 remove_key_from_history();
5049 }
5050#endif
5051
5052 /* 'matchpairs' */
5053 else if (gvarp == &p_mps)
5054 {
5055 /* Check for "x:y,x:y" */
5056 for (p = *varp; *p != NUL; p += 4)
5057 {
5058 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5059 {
5060 errmsg = e_invarg;
5061 break;
5062 }
5063 if (p[3] == NUL)
5064 break;
5065 }
5066 }
5067
5068#ifdef FEAT_COMMENTS
5069 /* 'comments' */
5070 else if (gvarp == &p_com)
5071 {
5072 for (s = *varp; *s; )
5073 {
5074 while (*s && *s != ':')
5075 {
5076 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5077 && !VIM_ISDIGIT(*s) && *s != '-')
5078 {
5079 errmsg = illegal_char(errbuf, *s);
5080 break;
5081 }
5082 ++s;
5083 }
5084 if (*s++ == NUL)
5085 errmsg = (char_u *)N_("E524: Missing colon");
5086 else if (*s == ',' || *s == NUL)
5087 errmsg = (char_u *)N_("E525: Zero length string");
5088 if (errmsg != NULL)
5089 break;
5090 while (*s && *s != ',')
5091 {
5092 if (*s == '\\' && s[1] != NUL)
5093 ++s;
5094 ++s;
5095 }
5096 s = skip_to_option_part(s);
5097 }
5098 }
5099#endif
5100
5101 /* 'listchars' */
5102 else if (varp == &p_lcs)
5103 {
5104 errmsg = set_chars_option(varp);
5105 }
5106
5107#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5108 /* 'fillchars' */
5109 else if (varp == &p_fcs)
5110 {
5111 errmsg = set_chars_option(varp);
5112 }
5113#endif
5114
5115#ifdef FEAT_CMDWIN
5116 /* 'cedit' */
5117 else if (varp == &p_cedit)
5118 {
5119 errmsg = check_cedit();
5120 }
5121#endif
5122
5123#ifdef FEAT_VIMINFO
5124 /* 'viminfo' */
5125 else if (varp == &p_viminfo)
5126 {
5127 for (s = p_viminfo; *s;)
5128 {
5129 /* Check it's a valid character */
5130 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5131 {
5132 errmsg = illegal_char(errbuf, *s);
5133 break;
5134 }
5135 if (*s == 'n') /* name is always last one */
5136 {
5137 break;
5138 }
5139 else if (*s == 'r') /* skip until next ',' */
5140 {
5141 while (*++s && *s != ',')
5142 ;
5143 }
5144 else if (*s == '%' || *s == '!' || *s == 'h' || *s == 'c')
5145 ++s; /* no extra chars */
5146 else /* must have a number */
5147 {
5148 while (vim_isdigit(*++s))
5149 ;
5150
5151 if (!VIM_ISDIGIT(*(s - 1)))
5152 {
5153 if (errbuf != NULL)
5154 {
5155 sprintf((char *)errbuf, _("E526: Missing number after <%s>"),
5156 transchar_byte(*(s - 1)));
5157 errmsg = errbuf;
5158 }
5159 else
5160 errmsg = (char_u *)"";
5161 break;
5162 }
5163 }
5164 if (*s == ',')
5165 ++s;
5166 else if (*s)
5167 {
5168 if (errbuf != NULL)
5169 errmsg = (char_u *)N_("E527: Missing comma");
5170 else
5171 errmsg = (char_u *)"";
5172 break;
5173 }
5174 }
5175 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5176 errmsg = (char_u *)N_("E528: Must specify a ' value");
5177 }
5178#endif /* FEAT_VIMINFO */
5179
5180 /* terminal options */
5181 else if (istermoption(&options[opt_idx]) && full_screen)
5182 {
5183 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5184 if (varp == &T_CCO)
5185 {
5186 t_colors = atoi((char *)T_CCO);
5187 if (t_colors <= 1)
5188 {
5189 if (new_value_alloced)
5190 vim_free(T_CCO);
5191 T_CCO = empty_option;
5192 }
5193 /* We now have a different color setup, initialize it again. */
5194 init_highlight(TRUE, FALSE);
5195 }
5196 ttest(FALSE);
5197 if (varp == &T_ME)
5198 {
5199 out_str(T_ME);
5200 redraw_later(CLEAR);
5201#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5202 /* Since t_me has been set, this probably means that the user
5203 * wants to use this as default colors. Need to reset default
5204 * background/foreground colors. */
5205 mch_set_normal_colors();
5206#endif
5207 }
5208 }
5209
5210#ifdef FEAT_LINEBREAK
5211 /* 'showbreak' */
5212 else if (varp == &p_sbr)
5213 {
5214 for (s = p_sbr; *s; )
5215 {
5216 if (ptr2cells(s) != 1)
5217 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
5218# ifdef FEAT_MBYTE
5219 if (has_mbyte)
5220 s += (*mb_ptr2len_check)(s);
5221 else
5222# endif
5223 ++s;
5224 }
5225 }
5226#endif
5227
5228#ifdef FEAT_GUI
5229 /* 'guifont' */
5230 else if (varp == &p_guifont)
5231 {
5232 if (gui.in_use)
5233 {
5234 p = p_guifont;
Bram Moolenaar843ee412004-06-30 16:16:41 +00005235# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005236 /*
5237 * Put up a font dialog and let the user select a new value.
5238 * If this is cancelled go back to the old value but don't
5239 * give an error message.
5240 */
5241 if (STRCMP(p, "*") == 0)
5242 {
5243 p = gui_mch_font_dialog(oldval);
5244
5245 if (new_value_alloced)
5246 free_string_option(p_guifont);
5247
5248 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5249 new_value_alloced = TRUE;
5250 }
5251# endif
5252 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5253 {
5254# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5255 if (STRCMP(p_guifont, "*") == 0)
5256 {
5257 /* Dialog was cancelled: Keep the old value without giving
5258 * an error message. */
5259 if (new_value_alloced)
5260 free_string_option(p_guifont);
5261 p_guifont = vim_strsave(oldval);
5262 new_value_alloced = TRUE;
5263 }
5264 else
5265# endif
5266 errmsg = (char_u *)N_("E596: Invalid font(s)");
5267 }
5268 }
5269 }
5270# ifdef FEAT_XFONTSET
5271 else if (varp == &p_guifontset)
5272 {
5273 if (STRCMP(p_guifontset, "*") == 0)
5274 errmsg = (char_u *)N_("E597: can't select fontset");
5275 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5276 errmsg = (char_u *)N_("E598: Invalid fontset");
5277 }
5278# endif
5279# ifdef FEAT_MBYTE
5280 else if (varp == &p_guifontwide)
5281 {
5282 if (STRCMP(p_guifontwide, "*") == 0)
5283 errmsg = (char_u *)N_("E533: can't select wide font");
5284 else if (gui_get_wide_font() == FAIL)
5285 errmsg = (char_u *)N_("E534: Invalid wide font");
5286 }
5287# endif
5288#endif
5289
5290#ifdef CURSOR_SHAPE
5291 /* 'guicursor' */
5292 else if (varp == &p_guicursor)
5293 errmsg = parse_shape_opt(SHAPE_CURSOR);
5294#endif
5295
5296#ifdef FEAT_MOUSESHAPE
5297 /* 'mouseshape' */
5298 else if (varp == &p_mouseshape)
5299 {
5300 errmsg = parse_shape_opt(SHAPE_MOUSE);
5301 update_mouseshape(-1);
5302 }
5303#endif
5304
5305#ifdef FEAT_PRINTER
5306 else if (varp == &p_popt)
5307 errmsg = parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS);
Bram Moolenaar8299df92004-07-10 09:47:34 +00005308
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005309# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005310 else if (varp == &p_pmfn)
5311 errmsg = parse_list_options(p_pmfn, mbfont_opts, OPT_MBFONT_NUM_OPTIONS);
5312# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005313#endif
5314
5315#ifdef FEAT_LANGMAP
5316 /* 'langmap' */
5317 else if (varp == &p_langmap)
5318 langmap_set();
5319#endif
5320
5321#ifdef FEAT_LINEBREAK
5322 /* 'breakat' */
5323 else if (varp == &p_breakat)
5324 fill_breakat_flags();
5325#endif
5326
5327#ifdef FEAT_TITLE
5328 /* 'titlestring' and 'iconstring' */
5329 else if (varp == &p_titlestring || varp == &p_iconstring)
5330 {
5331# ifdef FEAT_STL_OPT
5332 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5333
5334 /* NULL => statusline syntax */
5335 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5336 stl_syntax |= flagval;
5337 else
5338 stl_syntax &= ~flagval;
5339# endif
5340 did_set_title(varp == &p_iconstring);
5341
5342 }
5343#endif
5344
5345#ifdef FEAT_GUI
5346 /* 'guioptions' */
5347 else if (varp == &p_go)
5348 gui_init_which_components(oldval);
5349#endif
5350
5351#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5352 /* 'ttymouse' */
5353 else if (varp == &p_ttym)
5354 {
5355 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5356 errmsg = e_invarg;
5357 else
5358 check_mouse_termcode();
5359 }
5360#endif
5361
5362#ifdef FEAT_VISUAL
5363 /* 'selection' */
5364 else if (varp == &p_sel)
5365 {
5366 if (*p_sel == NUL
5367 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5368 errmsg = e_invarg;
5369 }
5370
5371 /* 'selectmode' */
5372 else if (varp == &p_slm)
5373 {
5374 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5375 errmsg = e_invarg;
5376 }
5377#endif
5378
5379#ifdef FEAT_BROWSE
5380 /* 'browsedir' */
5381 else if (varp == &p_bsdir)
5382 {
5383 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5384 && !mch_isdir(p_bsdir))
5385 errmsg = e_invarg;
5386 }
5387#endif
5388
5389#ifdef FEAT_VISUAL
5390 /* 'keymodel' */
5391 else if (varp == &p_km)
5392 {
5393 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5394 errmsg = e_invarg;
5395 else
5396 {
5397 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5398 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5399 }
5400 }
5401#endif
5402
5403 /* 'mousemodel' */
5404 else if (varp == &p_mousem)
5405 {
5406 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5407 errmsg = e_invarg;
5408#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5409 else if (*p_mousem != *oldval)
5410 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5411 * to create or delete the popup menus. */
5412 gui_motif_update_mousemodel(root_menu);
5413#endif
5414 }
5415
5416 /* 'switchbuf' */
5417 else if (varp == &p_swb)
5418 {
5419 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5420 errmsg = e_invarg;
5421 }
5422
5423 /* 'debug' */
5424 else if (varp == &p_debug)
5425 {
5426 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5427 errmsg = e_invarg;
5428 }
5429
5430 /* 'display' */
5431 else if (varp == &p_dy)
5432 {
5433 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5434 errmsg = e_invarg;
5435 else
5436 (void)init_chartab();
5437
5438 }
5439
5440#ifdef FEAT_VERTSPLIT
5441 /* 'eadirection' */
5442 else if (varp == &p_ead)
5443 {
5444 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5445 errmsg = e_invarg;
5446 }
5447#endif
5448
5449#ifdef FEAT_CLIPBOARD
5450 /* 'clipboard' */
5451 else if (varp == &p_cb)
5452 errmsg = check_clipboard_option();
5453#endif
5454
5455#ifdef FEAT_AUTOCMD
5456# ifdef FEAT_SYN_HL
5457 /* When 'syntax' is set, load the syntax of that name */
5458 else if (varp == &(curbuf->b_p_syn))
5459 {
5460 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
5461 curbuf->b_fname, TRUE, curbuf);
5462 }
5463# endif
5464
5465 /* When 'filetype' is set, trigger the FileType autocommands of that name */
5466 else if (varp == &(curbuf->b_p_ft))
5467 {
5468 did_filetype = TRUE;
5469 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
5470 curbuf->b_fname, TRUE, curbuf);
5471 }
5472#endif
5473
5474#ifdef FEAT_QUICKFIX
5475 /* When 'bufhidden' is set, check for valid value. */
5476 else if (gvarp == &p_bh)
5477 {
5478 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5479 errmsg = e_invarg;
5480 }
5481
5482 /* When 'buftype' is set, check for valid value. */
5483 else if (gvarp == &p_bt)
5484 {
5485 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5486 errmsg = e_invarg;
5487 else
5488 {
5489# ifdef FEAT_WINDOWS
5490 if (curwin->w_status_height)
5491 {
5492 curwin->w_redr_status = TRUE;
5493 redraw_later(VALID);
5494 }
5495# endif
5496 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5497 }
5498 }
5499#endif
5500
5501#ifdef FEAT_STL_OPT
5502 /* 'statusline' or 'rulerformat' */
5503 else if (varp == &p_stl || varp == &p_ruf)
5504 {
5505 int wid;
5506
5507 if (varp == &p_ruf) /* reset ru_wid first */
5508 ru_wid = 0;
5509 s = *varp;
5510 if (varp == &p_ruf && *s == '%')
5511 {
5512 /* set ru_wid if 'ruf' starts with "%99(" */
5513 if (*++s == '-') /* ignore a '-' */
5514 s++;
5515 wid = getdigits(&s);
5516 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5517 ru_wid = wid;
5518 else
5519 errmsg = check_stl_option(p_ruf);
5520 }
5521 else
5522 errmsg = check_stl_option(s);
5523 if (varp == &(p_ruf) && errmsg == NULL)
5524 comp_col();
5525 }
5526#endif
5527
5528#ifdef FEAT_INS_EXPAND
5529 /* check if it is a valid value for 'complete' -- Acevedo */
5530 else if (gvarp == &p_cpt)
5531 {
5532 for (s = *varp; *s;)
5533 {
5534 while(*s == ',' || *s == ' ')
5535 s++;
5536 if (!*s)
5537 break;
5538 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5539 {
5540 errmsg = illegal_char(errbuf, *s);
5541 break;
5542 }
5543 if (*++s != NUL && *s != ',' && *s != ' ')
5544 {
5545 if (s[-1] == 'k' || s[-1] == 's')
5546 {
5547 /* skip optional filename after 'k' and 's' */
5548 while (*s && *s != ',' && *s != ' ')
5549 {
5550 if (*s == '\\')
5551 ++s;
5552 ++s;
5553 }
5554 }
5555 else
5556 {
5557 if (errbuf != NULL)
5558 {
5559 sprintf((char *)errbuf,
5560 _("E535: Illegal character after <%c>"),
5561 *--s);
5562 errmsg = errbuf;
5563 }
5564 else
5565 errmsg = (char_u *)"";
5566 break;
5567 }
5568 }
5569 }
5570 }
5571#endif /* FEAT_INS_EXPAND */
5572
5573
5574#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5575 else if (varp == &p_toolbar)
5576 {
5577 if (opt_strings_flags(p_toolbar, p_toolbar_values,
5578 &toolbar_flags, TRUE) != OK)
5579 errmsg = e_invarg;
5580 else
5581 {
5582 out_flush();
5583 gui_mch_show_toolbar((toolbar_flags &
5584 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5585 }
5586 }
5587#endif
5588
5589#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5590 /* 'toolbariconsize': GTK+ 2 only */
5591 else if (varp == &p_tbis)
5592 {
5593 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
5594 errmsg = e_invarg;
5595 else
5596 {
5597 out_flush();
5598 gui_mch_show_toolbar((toolbar_flags &
5599 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5600 }
5601 }
5602#endif
5603
5604 /* 'pastetoggle': translate key codes like in a mapping */
5605 else if (varp == &p_pt)
5606 {
5607 if (*p_pt)
5608 {
5609 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
5610 if (p != NULL)
5611 {
5612 if (new_value_alloced)
5613 free_string_option(p_pt);
5614 p_pt = p;
5615 new_value_alloced = TRUE;
5616 }
5617 }
5618 }
5619
5620 /* 'backspace' */
5621 else if (varp == &p_bs)
5622 {
5623 if (VIM_ISDIGIT(*p_bs))
5624 {
5625 if (*p_bs >'2' || p_bs[1] != NUL)
5626 errmsg = e_invarg;
5627 }
5628 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
5629 errmsg = e_invarg;
5630 }
5631
5632 /* 'casemap' */
5633 else if (varp == &p_cmp)
5634 {
5635 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
5636 errmsg = e_invarg;
5637 }
5638
5639#ifdef FEAT_DIFF
5640 /* 'diffopt' */
5641 else if (varp == &p_dip)
5642 {
5643 if (diffopt_changed() == FAIL)
5644 errmsg = e_invarg;
5645 }
5646#endif
5647
5648#ifdef FEAT_FOLDING
5649 /* 'foldmethod' */
5650 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
5651 {
5652 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
5653 || *curwin->w_p_fdm == NUL)
5654 errmsg = e_invarg;
5655 else
5656 foldUpdateAll(curwin);
5657 }
5658# ifdef FEAT_EVAL
5659 /* 'foldexpr' */
5660 else if (varp == &curwin->w_p_fde)
5661 {
5662 if (foldmethodIsExpr(curwin))
5663 foldUpdateAll(curwin);
5664 }
5665# endif
5666 /* 'foldmarker' */
5667 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
5668 {
5669 p = vim_strchr(*varp, ',');
5670 if (p == NULL)
5671 errmsg = (char_u *)N_("E536: comma required");
5672 else if (p == *varp || p[1] == NUL)
5673 errmsg = e_invarg;
5674 else if (foldmethodIsMarker(curwin))
5675 foldUpdateAll(curwin);
5676 }
5677 /* 'commentstring' */
5678 else if (gvarp == &p_cms)
5679 {
5680 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
5681 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
5682 }
5683 /* 'foldopen' */
5684 else if (varp == &p_fdo)
5685 {
5686 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
5687 errmsg = e_invarg;
5688 }
5689 /* 'foldclose' */
5690 else if (varp == &p_fcl)
5691 {
5692 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
5693 errmsg = e_invarg;
5694 }
5695#endif
5696
5697#ifdef FEAT_VIRTUALEDIT
5698 /* 'virtualedit' */
5699 else if (varp == &p_ve)
5700 {
5701 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
5702 errmsg = e_invarg;
5703 else if (STRCMP(p_ve, oldval) != 0)
5704 {
5705 /* Recompute cursor position in case the new 've' setting
5706 * changes something. */
5707 validate_virtcol();
5708 coladvance(curwin->w_virtcol);
5709 }
5710 }
5711#endif
5712
5713#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
5714 else if (varp == &p_csqf)
5715 {
5716 if (p_csqf != NULL)
5717 {
5718 p = p_csqf;
5719 while (*p != NUL)
5720 {
5721 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
5722 || p[1] == NUL
5723 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
5724 || (p[2] != NUL && p[2] != ','))
5725 {
5726 errmsg = e_invarg;
5727 break;
5728 }
5729 else if (p[2] == NUL)
5730 break;
5731 else
5732 p += 3;
5733 }
5734 }
5735 }
5736#endif
5737
5738 /* Options that are a list of flags. */
5739 else
5740 {
5741 p = NULL;
5742 if (varp == &p_ww)
5743 p = (char_u *)WW_ALL;
5744 if (varp == &p_shm)
5745 p = (char_u *)SHM_ALL;
5746 else if (varp == &(p_cpo))
5747 p = (char_u *)CPO_ALL;
5748 else if (varp == &(curbuf->b_p_fo))
5749 p = (char_u *)FO_ALL;
5750 else if (varp == &p_mouse)
5751 {
5752#ifdef FEAT_MOUSE
5753 p = (char_u *)MOUSE_ALL;
5754#else
5755 if (*p_mouse != NUL)
5756 errmsg = (char_u *)N_("E538: No mouse support");
5757#endif
5758 }
5759#if defined(FEAT_GUI)
5760 else if (varp == &p_go)
5761 p = (char_u *)GO_ALL;
5762#endif
5763 if (p != NULL)
5764 {
5765 for (s = *varp; *s; ++s)
5766 if (vim_strchr(p, *s) == NULL)
5767 {
5768 errmsg = illegal_char(errbuf, *s);
5769 break;
5770 }
5771 }
5772 }
5773
5774 /*
5775 * If error detected, restore the previous value.
5776 */
5777 if (errmsg != NULL)
5778 {
5779 if (new_value_alloced)
5780 free_string_option(*varp);
5781 *varp = oldval;
5782 /*
5783 * When resetting some values, need to act on it.
5784 */
5785 if (did_chartab)
5786 (void)init_chartab();
5787 if (varp == &p_hl)
5788 (void)highlight_changed();
5789 }
5790 else
5791 {
5792#ifdef FEAT_EVAL
5793 /* Remember where the option was set. */
5794 options[opt_idx].scriptID = current_SID;
5795#endif
5796 /*
5797 * Free string options that are in allocated memory.
5798 */
5799 if (options[opt_idx].flags & P_ALLOCED)
5800 free_string_option(oldval);
5801 if (new_value_alloced)
5802 options[opt_idx].flags |= P_ALLOCED;
5803 else
5804 options[opt_idx].flags &= ~P_ALLOCED;
5805
5806 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5807 && (int)options[opt_idx].indir >= PV_BOTH)
5808 {
5809 /* global option with local value set to use global value; free
5810 * the local value and make it empty */
5811 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
5812 free_string_option(*(char_u **)p);
5813 *(char_u **)p = empty_option;
5814 }
5815
5816 /* May set global value for local option. */
5817 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
5818 set_string_option_global(opt_idx, varp);
5819 }
5820
5821#ifdef FEAT_MOUSE
5822 if (varp == &p_mouse)
5823 {
5824# ifdef FEAT_MOUSE_TTY
5825 if (*p_mouse == NUL)
5826 mch_setmouse(FALSE); /* switch mouse off */
5827 else
5828# endif
5829 setmouse(); /* in case 'mouse' changed */
5830 }
5831#endif
5832
5833 if (curwin->w_curswant != MAXCOL)
5834 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
5835 check_redraw(options[opt_idx].flags);
5836
5837 return errmsg;
5838}
5839
5840/*
5841 * Handle setting 'listchars' or 'fillchars'.
5842 * Returns error message, NULL if it's OK.
5843 */
5844 static char_u *
5845set_chars_option(varp)
5846 char_u **varp;
5847{
5848 int round, i, len, entries;
5849 char_u *p, *s;
5850 int c1, c2 = 0;
5851 struct charstab
5852 {
5853 int *cp;
5854 char *name;
5855 };
5856#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5857 static struct charstab filltab[] =
5858 {
5859 {&fill_stl, "stl"},
5860 {&fill_stlnc, "stlnc"},
5861 {&fill_vert, "vert"},
5862 {&fill_fold, "fold"},
5863 {&fill_diff, "diff"},
5864 };
5865#endif
5866 static struct charstab lcstab[] =
5867 {
5868 {&lcs_eol, "eol"},
5869 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005870 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871 {&lcs_prec, "precedes"},
5872 {&lcs_tab2, "tab"},
5873 {&lcs_trail, "trail"},
5874 };
5875 struct charstab *tab;
5876
5877#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5878 if (varp == &p_lcs)
5879#endif
5880 {
5881 tab = lcstab;
5882 entries = sizeof(lcstab) / sizeof(struct charstab);
5883 }
5884#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5885 else
5886 {
5887 tab = filltab;
5888 entries = sizeof(filltab) / sizeof(struct charstab);
5889 }
5890#endif
5891
5892 /* first round: check for valid value, second round: assign values */
5893 for (round = 0; round <= 1; ++round)
5894 {
5895 if (round)
5896 {
5897 /* After checking that the value is valid: set defaults: space for
5898 * 'fillchars', NUL for 'listchars' */
5899 for (i = 0; i < entries; ++i)
5900 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
5901 if (varp == &p_lcs)
5902 lcs_tab1 = NUL;
5903#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5904 else
5905 fill_diff = '-';
5906#endif
5907 }
5908 p = *varp;
5909 while (*p)
5910 {
5911 for (i = 0; i < entries; ++i)
5912 {
5913 len = (int)STRLEN(tab[i].name);
5914 if (STRNCMP(p, tab[i].name, len) == 0
5915 && p[len] == ':'
5916 && p[len + 1] != NUL)
5917 {
5918 s = p + len + 1;
5919#ifdef FEAT_MBYTE
5920 c1 = mb_ptr2char_adv(&s);
5921#else
5922 c1 = *s++;
5923#endif
5924 if (tab[i].cp == &lcs_tab2)
5925 {
5926 if (*s == NUL)
5927 continue;
5928#ifdef FEAT_MBYTE
5929 c2 = mb_ptr2char_adv(&s);
5930#else
5931 c2 = *s++;
5932#endif
5933 }
5934 if (*s == ',' || *s == NUL)
5935 {
5936 if (round)
5937 {
5938 if (tab[i].cp == &lcs_tab2)
5939 {
5940 lcs_tab1 = c1;
5941 lcs_tab2 = c2;
5942 }
5943 else
5944 *(tab[i].cp) = c1;
5945
5946 }
5947 p = s;
5948 break;
5949 }
5950 }
5951 }
5952
5953 if (i == entries)
5954 return e_invarg;
5955 if (*p == ',')
5956 ++p;
5957 }
5958 }
5959
5960 return NULL; /* no error */
5961}
5962
5963#ifdef FEAT_STL_OPT
5964/*
5965 * Check validity of options with the 'statusline' format.
5966 * Return error message or NULL.
5967 */
5968 char_u *
5969check_stl_option(s)
5970 char_u *s;
5971{
5972 int itemcnt = 0;
5973 int groupdepth = 0;
5974 static char_u errbuf[80];
5975
5976 while (*s && itemcnt < STL_MAX_ITEM)
5977 {
5978 /* Check for valid keys after % sequences */
5979 while (*s && *s != '%')
5980 s++;
5981 if (!*s)
5982 break;
5983 s++;
5984 if (*s != '%' && *s != ')')
5985 ++itemcnt;
5986 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
5987 {
5988 s++;
5989 continue;
5990 }
5991 if (*s == ')')
5992 {
5993 s++;
5994 if (--groupdepth < 0)
5995 break;
5996 continue;
5997 }
5998 if (*s == '-')
5999 s++;
6000 while (VIM_ISDIGIT(*s))
6001 s++;
6002 if (*s == STL_HIGHLIGHT)
6003 continue;
6004 if (*s == '.')
6005 {
6006 s++;
6007 while (*s && VIM_ISDIGIT(*s))
6008 s++;
6009 }
6010 if (*s == '(')
6011 {
6012 groupdepth++;
6013 continue;
6014 }
6015 if (vim_strchr(STL_ALL, *s) == NULL)
6016 {
6017 return illegal_char(errbuf, *s);
6018 }
6019 if (*s == '{')
6020 {
6021 s++;
6022 while (*s != '}' && *s)
6023 s++;
6024 if (*s != '}')
6025 return (char_u *)N_("E540: Unclosed expression sequence");
6026 }
6027 }
6028 if (itemcnt >= STL_MAX_ITEM)
6029 return (char_u *)N_("E541: too many items");
6030 if (groupdepth != 0)
6031 return (char_u *)N_("E542: unbalanced groups");
6032 return NULL;
6033}
6034#endif
6035
6036#ifdef FEAT_CLIPBOARD
6037/*
6038 * Extract the items in the 'clipboard' option and set global values.
6039 */
6040 static char_u *
6041check_clipboard_option()
6042{
6043 int new_unnamed = FALSE;
6044 int new_autoselect = FALSE;
6045 int new_autoselectml = FALSE;
6046 regprog_T *new_exclude_prog = NULL;
6047 char_u *errmsg = NULL;
6048 char_u *p;
6049
6050 for (p = p_cb; *p != NUL; )
6051 {
6052 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6053 {
6054 new_unnamed = TRUE;
6055 p += 7;
6056 }
6057 else if (STRNCMP(p, "autoselect", 10) == 0
6058 && (p[10] == ',' || p[10] == NUL))
6059 {
6060 new_autoselect = TRUE;
6061 p += 10;
6062 }
6063 else if (STRNCMP(p, "autoselectml", 12) == 0
6064 && (p[12] == ',' || p[12] == NUL))
6065 {
6066 new_autoselectml = TRUE;
6067 p += 12;
6068 }
6069 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6070 {
6071 p += 8;
6072 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6073 if (new_exclude_prog == NULL)
6074 errmsg = e_invarg;
6075 break;
6076 }
6077 else
6078 {
6079 errmsg = e_invarg;
6080 break;
6081 }
6082 if (*p == ',')
6083 ++p;
6084 }
6085 if (errmsg == NULL)
6086 {
6087 clip_unnamed = new_unnamed;
6088 clip_autoselect = new_autoselect;
6089 clip_autoselectml = new_autoselectml;
6090 vim_free(clip_exclude_prog);
6091 clip_exclude_prog = new_exclude_prog;
6092 }
6093 else
6094 vim_free(new_exclude_prog);
6095
6096 return errmsg;
6097}
6098#endif
6099
6100/*
6101 * Set the value of a boolean option, and take care of side effects.
6102 * Returns NULL for success, or an error message for an error.
6103 */
6104 static char_u *
6105set_bool_option(opt_idx, varp, value, opt_flags)
6106 int opt_idx; /* index in options[] table */
6107 char_u *varp; /* pointer to the option variable */
6108 int value; /* new value */
6109 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6110{
6111 int old_value = *(int *)varp;
6112
6113#ifdef FEAT_GUI
6114 need_mouse_correct = TRUE;
6115#endif
6116
6117 /* Disallow changing some options from secure mode */
6118 if ((secure
6119#ifdef HAVE_SANDBOX
6120 || sandbox != 0
6121#endif
6122 ) && (options[opt_idx].flags & P_SECURE))
6123 return e_secure;
6124
6125 *(int *)varp = value; /* set the new value */
6126#ifdef FEAT_EVAL
6127 /* Remember where the option was set. */
6128 options[opt_idx].scriptID = current_SID;
6129#endif
6130
6131 /* May set global value for local option. */
6132 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6133 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6134
6135 /*
6136 * Handle side effects of changing a bool option.
6137 */
6138
6139 /* 'compatible' */
6140 if ((int *)varp == &p_cp)
6141 {
6142 compatible_set();
6143 }
6144
6145 /* when 'readonly' is reset globally, also reset readonlymode */
6146 else if ((int *)varp == &curbuf->b_p_ro)
6147 {
6148 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6149 readonlymode = FALSE;
6150#ifdef FEAT_TITLE
6151 need_maketitle = TRUE;
6152#endif
6153 }
6154
6155#ifdef FEAT_TITLE
6156 /* when 'modifiable' is changed, redraw the window title */
6157 else if ((int *)varp == &curbuf->b_p_ma)
6158 need_maketitle = TRUE;
6159 /* when 'endofline' is changed, redraw the window title */
6160 else if ((int *)varp == &curbuf->b_p_eol)
6161 need_maketitle = TRUE;
6162#endif
6163
6164 /* when 'bin' is set also set some other options */
6165 else if ((int *)varp == &curbuf->b_p_bin)
6166 {
6167 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6168#ifdef FEAT_TITLE
6169 need_maketitle = TRUE;
6170#endif
6171 }
6172
6173#ifdef FEAT_AUTOCMD
6174 /* when 'buflisted' changes, trigger autocommands */
6175 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6176 {
6177 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6178 NULL, NULL, TRUE, curbuf);
6179 }
6180#endif
6181
6182 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6183 else if ((int *)varp == &curbuf->b_p_swf)
6184 {
6185 if (curbuf->b_p_swf && p_uc)
6186 ml_open_file(curbuf); /* create the swap file */
6187 else
6188 mf_close_file(curbuf, TRUE); /* remove the swap file */
6189 }
6190
6191 /* when 'terse' is set change 'shortmess' */
6192 else if ((int *)varp == &p_terse)
6193 {
6194 char_u *p;
6195
6196 p = vim_strchr(p_shm, SHM_SEARCH);
6197
6198 /* insert 's' in p_shm */
6199 if (p_terse && p == NULL)
6200 {
6201 STRCPY(IObuff, p_shm);
6202 STRCAT(IObuff, "s");
6203 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6204 }
6205 /* remove 's' from p_shm */
6206 else if (!p_terse && p != NULL)
6207 mch_memmove(p, p + 1, STRLEN(p));
6208 }
6209
6210 /* when 'paste' is set or reset also change other options */
6211 else if ((int *)varp == &p_paste)
6212 {
6213 paste_option_changed();
6214 }
6215
6216 /* when 'insertmode' is set from an autocommand need to do work here */
6217 else if ((int *)varp == &p_im)
6218 {
6219 if (p_im)
6220 {
6221 if ((State & INSERT) == 0)
6222 need_start_insertmode = TRUE;
6223 stop_insert_mode = FALSE;
6224 }
6225 else
6226 {
6227 need_start_insertmode = FALSE;
6228 stop_insert_mode = TRUE;
6229 if (p_smd && restart_edit != 0)
6230 clear_cmdline = TRUE; /* remove "(insert)" */
6231 restart_edit = 0;
6232 }
6233 }
6234
6235 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6236 else if ((int *)varp == &p_ic && p_hls)
6237 {
6238 redraw_all_later(NOT_VALID);
6239 }
6240
6241#ifdef FEAT_SEARCH_EXTRA
6242 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6243 else if ((int *)varp == &p_hls)
6244 {
6245 no_hlsearch = FALSE;
6246 }
6247#endif
6248
6249#ifdef FEAT_SCROLLBIND
6250 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6251 * at the end of normal_cmd() */
6252 else if ((int *)varp == &curwin->w_p_scb)
6253 {
6254 if (curwin->w_p_scb)
6255 do_check_scrollbind(FALSE);
6256 }
6257#endif
6258
6259#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6260 /* There can be only one window with 'previewwindow' set. */
6261 else if ((int *)varp == &curwin->w_p_pvw)
6262 {
6263 if (curwin->w_p_pvw)
6264 {
6265 win_T *win;
6266
6267 for (win = firstwin; win != NULL; win = win->w_next)
6268 if (win->w_p_pvw && win != curwin)
6269 {
6270 curwin->w_p_pvw = FALSE;
6271 return (char_u *)N_("E590: A preview window already exists");
6272 }
6273 }
6274 }
6275#endif
6276
6277 /* when 'textmode' is set or reset also change 'fileformat' */
6278 else if ((int *)varp == &curbuf->b_p_tx)
6279 {
6280 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6281 }
6282
6283 /* when 'textauto' is set or reset also change 'fileformats' */
6284 else if ((int *)varp == &p_ta)
6285 {
6286 set_string_option_direct((char_u *)"ffs", -1,
6287 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6288 OPT_FREE | opt_flags);
6289 }
6290
6291 /*
6292 * When 'lisp' option changes include/exclude '-' in
6293 * keyword characters.
6294 */
6295#ifdef FEAT_LISP
6296 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6297 {
6298 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6299 }
6300#endif
6301
6302#ifdef FEAT_TITLE
6303 /* when 'title' changed, may need to change the title; same for 'icon' */
6304 else if ((int *)varp == &p_title)
6305 {
6306 did_set_title(FALSE);
6307 }
6308
6309 else if ((int *)varp == &p_icon)
6310 {
6311 did_set_title(TRUE);
6312 }
6313#endif
6314
6315 else if ((int *)varp == &curbuf->b_changed)
6316 {
6317 if (!value)
6318 save_file_ff(curbuf); /* Buffer is unchanged */
6319#ifdef FEAT_TITLE
6320 need_maketitle = TRUE;
6321#endif
6322#ifdef FEAT_AUTOCMD
6323 modified_was_set = value;
6324#endif
6325 }
6326
6327#ifdef BACKSLASH_IN_FILENAME
6328 else if ((int *)varp == &p_ssl)
6329 {
6330 if (p_ssl)
6331 {
6332 psepc = '/';
6333 psepcN = '\\';
6334 pseps[0] = '/';
6335 psepsN[0] = '\\';
6336 }
6337 else
6338 {
6339 psepc = '\\';
6340 psepcN = '/';
6341 pseps[0] = '\\';
6342 psepsN[0] = '/';
6343 }
6344
6345 /* need to adjust the file name arguments and buffer names. */
6346 buflist_slash_adjust();
6347 alist_slash_adjust();
6348# ifdef FEAT_EVAL
6349 scriptnames_slash_adjust();
6350# endif
6351 }
6352#endif
6353
6354 /* If 'wrap' is set, set w_leftcol to zero. */
6355 else if ((int *)varp == &curwin->w_p_wrap)
6356 {
6357 if (curwin->w_p_wrap)
6358 curwin->w_leftcol = 0;
6359 }
6360
6361#ifdef FEAT_WINDOWS
6362 else if ((int *)varp == &p_ea)
6363 {
6364 if (p_ea && !old_value)
6365 win_equal(curwin, FALSE, 0);
6366 }
6367#endif
6368
6369 else if ((int *)varp == &p_wiv)
6370 {
6371 /*
6372 * When 'weirdinvert' changed, set/reset 't_xs'.
6373 * Then set 'weirdinvert' according to value of 't_xs'.
6374 */
6375 if (p_wiv && !old_value)
6376 T_XS = (char_u *)"y";
6377 else if (!p_wiv && old_value)
6378 T_XS = empty_option;
6379 p_wiv = (*T_XS != NUL);
6380 }
6381
6382#if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \
6383 || defined(FEAT_NETBEANS_INTG))
6384 else if ((int *)varp == &p_beval)
6385 {
6386 extern BalloonEval *balloonEval;
6387
6388 if (p_beval == TRUE)
6389 gui_mch_enable_beval_area(balloonEval);
6390 else
6391 gui_mch_disable_beval_area(balloonEval);
6392 }
6393
6394 else if ((int *)varp == &p_acd)
6395 {
6396 if (p_acd && curbuf->b_ffname != NULL
6397 && vim_chdirfile(curbuf->b_ffname) == OK)
6398 shorten_fnames(TRUE);
6399 }
6400#endif
6401
6402#ifdef FEAT_DIFF
6403 /* 'diff' */
6404 else if ((int *)varp == &curwin->w_p_diff)
6405 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006406 /* May add or remove the buffer from the list of diff buffers. */
6407 diff_buf_adjust(curwin);
6408# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006409 if (foldmethodIsDiff(curwin))
6410 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006411# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006412 }
6413#endif
6414
6415#ifdef USE_IM_CONTROL
6416 /* 'imdisable' */
6417 else if ((int *)varp == &p_imdisable)
6418 {
6419 /* Only de-activate it here, it will be enabled when changing mode. */
6420 if (p_imdisable)
6421 im_set_active(FALSE);
6422 }
6423#endif
6424
6425#ifdef FEAT_FKMAP
6426 else if ((int *)varp == &p_altkeymap)
6427 {
6428 if (old_value != p_altkeymap)
6429 {
6430 if (!p_altkeymap)
6431 {
6432 p_hkmap = p_fkmap;
6433 p_fkmap = 0;
6434 }
6435 else
6436 {
6437 p_fkmap = p_hkmap;
6438 p_hkmap = 0;
6439 }
6440 (void)init_chartab();
6441 }
6442 }
6443
6444 /*
6445 * In case some second language keymapping options have changed, check
6446 * and correct the setting in a consistent way.
6447 */
6448
6449 /*
6450 * If hkmap or fkmap are set, reset Arabic keymapping.
6451 */
6452 if ((p_hkmap || p_fkmap) && p_altkeymap)
6453 {
6454 p_altkeymap = p_fkmap;
6455# ifdef FEAT_ARABIC
6456 curwin->w_p_arab = FALSE;
6457# endif
6458 (void)init_chartab();
6459 }
6460
6461 /*
6462 * If hkmap set, reset Farsi keymapping.
6463 */
6464 if (p_hkmap && p_altkeymap)
6465 {
6466 p_altkeymap = 0;
6467 p_fkmap = 0;
6468# ifdef FEAT_ARABIC
6469 curwin->w_p_arab = FALSE;
6470# endif
6471 (void)init_chartab();
6472 }
6473
6474 /*
6475 * If fkmap set, reset Hebrew keymapping.
6476 */
6477 if (p_fkmap && !p_altkeymap)
6478 {
6479 p_altkeymap = 1;
6480 p_hkmap = 0;
6481# ifdef FEAT_ARABIC
6482 curwin->w_p_arab = FALSE;
6483# endif
6484 (void)init_chartab();
6485 }
6486#endif
6487
6488#ifdef FEAT_ARABIC
6489 if ((int *)varp == &curwin->w_p_arab)
6490 {
6491 if (curwin->w_p_arab)
6492 {
6493 /*
6494 * 'arabic' is set, handle various sub-settings.
6495 */
6496 if (!p_tbidi)
6497 {
6498 /* set rightleft mode */
6499 if (!curwin->w_p_rl)
6500 {
6501 curwin->w_p_rl = TRUE;
6502 changed_window_setting();
6503 }
6504
6505 /* Enable Arabic shaping (major part of what Arabic requires) */
6506 if (!p_arshape)
6507 {
6508 p_arshape = TRUE;
6509 redraw_later_clear();
6510 }
6511 }
6512
6513 /* Arabic requires a utf-8 encoding, inform the user if its not
6514 * set. */
6515 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006516 {
6517 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6519 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521
6522# ifdef FEAT_MBYTE
6523 /* set 'delcombine' */
6524 p_deco = TRUE;
6525# endif
6526
6527# ifdef FEAT_KEYMAP
6528 /* Force-set the necessary keymap for arabic */
6529 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
6530 OPT_LOCAL);
6531# endif
6532# ifdef FEAT_FKMAP
6533 p_altkeymap = 0;
6534 p_hkmap = 0;
6535 p_fkmap = 0;
6536 (void)init_chartab();
6537# endif
6538 }
6539 else
6540 {
6541 /*
6542 * 'arabic' is reset, handle various sub-settings.
6543 */
6544 if (!p_tbidi)
6545 {
6546 /* reset rightleft mode */
6547 if (curwin->w_p_rl)
6548 {
6549 curwin->w_p_rl = FALSE;
6550 changed_window_setting();
6551 }
6552
6553 /* 'arabicshape' isn't reset, it is a global option and
6554 * another window may still need it "on". */
6555 }
6556
6557 /* 'delcombine' isn't reset, it is a global option and another
6558 * window may still want it "on". */
6559
6560# ifdef FEAT_KEYMAP
6561 /* Revert to the default keymap */
6562 curbuf->b_p_iminsert = B_IMODE_NONE;
6563 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6564# endif
6565 }
6566 }
6567#endif
6568
6569 /*
6570 * End of handling side effects for bool options.
6571 */
6572
6573 options[opt_idx].flags |= P_WAS_SET;
6574
6575 comp_col(); /* in case 'ruler' or 'showcmd' changed */
6576 if (curwin->w_curswant != MAXCOL)
6577 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
6578 check_redraw(options[opt_idx].flags);
6579
6580 return NULL;
6581}
6582
6583/*
6584 * Set the value of a number option, and take care of side effects.
6585 * Returns NULL for success, or an error message for an error.
6586 */
6587 static char_u *
6588set_num_option(opt_idx, varp, value, errbuf, opt_flags)
6589 int opt_idx; /* index in options[] table */
6590 char_u *varp; /* pointer to the option variable */
6591 long value; /* new value */
6592 char_u *errbuf; /* buffer for error messages */
6593 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
6594 OPT_MODELINE */
6595{
6596 char_u *errmsg = NULL;
6597 long old_value = *(long *)varp;
6598 long old_Rows = Rows; /* remember old Rows */
6599 long old_Columns = Columns; /* remember old Columns */
6600 long *pp = (long *)varp;
6601
6602#ifdef FEAT_GUI
6603 need_mouse_correct = TRUE;
6604#endif
6605
6606 *pp = value;
6607#ifdef FEAT_EVAL
6608 /* Remember where the option was set. */
6609 options[opt_idx].scriptID = current_SID;
6610#endif
6611
6612 if (curbuf->b_p_sw <= 0)
6613 {
6614 errmsg = e_positive;
6615 curbuf->b_p_sw = curbuf->b_p_ts;
6616 }
6617
6618 /*
6619 * Number options that need some action when changed
6620 */
6621#ifdef FEAT_WINDOWS
6622 if (pp == &p_wh || pp == &p_hh)
6623 {
6624 if (p_wh < 1)
6625 {
6626 errmsg = e_positive;
6627 p_wh = 1;
6628 }
6629 if (p_wmh > p_wh)
6630 {
6631 errmsg = e_winheight;
6632 p_wh = p_wmh;
6633 }
6634 if (p_hh < 0)
6635 {
6636 errmsg = e_positive;
6637 p_hh = 0;
6638 }
6639
6640 /* Change window height NOW */
6641 if (lastwin != firstwin)
6642 {
6643 if (pp == &p_wh && curwin->w_height < p_wh)
6644 win_setheight((int)p_wh);
6645 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
6646 win_setheight((int)p_hh);
6647 }
6648 }
6649
6650 /* 'winminheight' */
6651 else if (pp == &p_wmh)
6652 {
6653 if (p_wmh < 0)
6654 {
6655 errmsg = e_positive;
6656 p_wmh = 0;
6657 }
6658 if (p_wmh > p_wh)
6659 {
6660 errmsg = e_winheight;
6661 p_wmh = p_wh;
6662 }
6663 win_setminheight();
6664 }
6665
6666# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006667 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006668 {
6669 if (p_wiw < 1)
6670 {
6671 errmsg = e_positive;
6672 p_wiw = 1;
6673 }
6674 if (p_wmw > p_wiw)
6675 {
6676 errmsg = e_winwidth;
6677 p_wiw = p_wmw;
6678 }
6679
6680 /* Change window width NOW */
6681 if (lastwin != firstwin && curwin->w_width < p_wiw)
6682 win_setwidth((int)p_wiw);
6683 }
6684
6685 /* 'winminwidth' */
6686 else if (pp == &p_wmw)
6687 {
6688 if (p_wmw < 0)
6689 {
6690 errmsg = e_positive;
6691 p_wmw = 0;
6692 }
6693 if (p_wmw > p_wiw)
6694 {
6695 errmsg = e_winwidth;
6696 p_wmw = p_wiw;
6697 }
6698 win_setminheight();
6699 }
6700# endif
6701
6702#endif
6703
6704#ifdef FEAT_WINDOWS
6705 /* (re)set last window status line */
6706 else if (pp == &p_ls)
6707 {
6708 last_status(FALSE);
6709 }
6710#endif
6711
6712#ifdef FEAT_GUI
6713 else if (pp == &p_linespace)
6714 {
6715 if (gui.in_use && gui_mch_adjust_charsize() == OK)
6716 gui_set_shellsize(FALSE, FALSE);
6717 }
6718#endif
6719
6720#ifdef FEAT_FOLDING
6721 /* 'foldlevel' */
6722 else if (pp == &curwin->w_p_fdl)
6723 {
6724 if (curwin->w_p_fdl < 0)
6725 curwin->w_p_fdl = 0;
6726 newFoldLevel();
6727 }
6728
6729 /* 'foldminlevel' */
6730 else if (pp == &curwin->w_p_fml)
6731 {
6732 foldUpdateAll(curwin);
6733 }
6734
6735 /* 'foldnestmax' */
6736 else if (pp == &curwin->w_p_fdn)
6737 {
6738 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
6739 foldUpdateAll(curwin);
6740 }
6741
6742 /* 'foldcolumn' */
6743 else if (pp == &curwin->w_p_fdc)
6744 {
6745 if (curwin->w_p_fdc < 0)
6746 {
6747 errmsg = e_positive;
6748 curwin->w_p_fdc = 0;
6749 }
6750 else if (curwin->w_p_fdc > 12)
6751 {
6752 errmsg = e_invarg;
6753 curwin->w_p_fdc = 12;
6754 }
6755 }
6756
6757 /* 'shiftwidth' or 'tabstop' */
6758 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
6759 {
6760 if (foldmethodIsIndent(curwin))
6761 foldUpdateAll(curwin);
6762 }
6763#endif /* FEAT_FOLDING */
6764
6765 else if (pp == &curbuf->b_p_iminsert)
6766 {
6767 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
6768 {
6769 errmsg = e_invarg;
6770 curbuf->b_p_iminsert = B_IMODE_NONE;
6771 }
6772 p_iminsert = curbuf->b_p_iminsert;
6773 if (termcap_active) /* don't do this in the alternate screen */
6774 showmode();
6775#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
6776 /* Show/unshow value of 'keymap' in status lines. */
6777 status_redraw_curbuf();
6778#endif
6779 }
6780
6781 else if (pp == &curbuf->b_p_imsearch)
6782 {
6783 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
6784 {
6785 errmsg = e_invarg;
6786 curbuf->b_p_imsearch = B_IMODE_NONE;
6787 }
6788 p_imsearch = curbuf->b_p_imsearch;
6789 }
6790
6791#ifdef FEAT_TITLE
6792 /* if 'titlelen' has changed, redraw the title */
6793 else if (pp == &p_titlelen)
6794 {
6795 if (p_titlelen < 0)
6796 {
6797 errmsg = e_positive;
6798 p_titlelen = 85;
6799 }
6800 if (starting != NO_SCREEN && old_value != p_titlelen)
6801 need_maketitle = TRUE;
6802 }
6803#endif
6804
6805 /* if p_ch changed value, change the command line height */
6806 else if (pp == &p_ch)
6807 {
6808 if (p_ch < 1)
6809 {
6810 errmsg = e_positive;
6811 p_ch = 1;
6812 }
6813
6814 /* Only compute the new window layout when startup has been
6815 * completed. Otherwise the frame sizes may be wrong. */
6816 if (p_ch != old_value && full_screen
6817#ifdef FEAT_GUI
6818 && !gui.starting
6819#endif
6820 )
6821 command_height(old_value);
6822 }
6823
6824 /* when 'updatecount' changes from zero to non-zero, open swap files */
6825 else if (pp == &p_uc)
6826 {
6827 if (p_uc < 0)
6828 {
6829 errmsg = e_positive;
6830 p_uc = 100;
6831 }
6832 if (p_uc && !old_value)
6833 ml_open_files();
6834 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006835#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00006836 else if (pp == &p_mzq)
6837 mzvim_reset_timer();
6838#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839
6840 /* sync undo before 'undolevels' changes */
6841 else if (pp == &p_ul)
6842 {
6843 /* use the old value, otherwise u_sync() may not work properly */
6844 p_ul = old_value;
6845 u_sync();
6846 p_ul = value;
6847 }
6848
Bram Moolenaar592e0a22004-07-03 16:05:59 +00006849#ifdef FEAT_LINEBREAK
6850 /* 'numberwidth' must be positive */
6851 else if (pp == &curwin->w_p_nuw)
6852 {
6853 if (curwin->w_p_nuw < 1)
6854 {
6855 errmsg = e_positive;
6856 curwin->w_p_nuw = 1;
6857 }
6858 if (curwin->w_p_nuw > 10)
6859 {
6860 errmsg = e_invarg;
6861 curwin->w_p_nuw = 10;
6862 }
6863 curwin->w_nrwidth_line_count = 0;
6864 }
6865#endif
6866
Bram Moolenaar071d4272004-06-13 20:20:40 +00006867 /*
6868 * Check the bounds for numeric options here
6869 */
6870 if (Rows < min_rows() && full_screen)
6871 {
6872 if (errbuf != NULL)
6873 {
6874 sprintf((char *)errbuf, _("E593: Need at least %d lines"),
6875 min_rows());
6876 errmsg = errbuf;
6877 }
6878 Rows = min_rows();
6879 }
6880 if (Columns < MIN_COLUMNS && full_screen)
6881 {
6882 if (errbuf != NULL)
6883 {
6884 sprintf((char *)errbuf, _("E594: Need at least %d columns"),
6885 MIN_COLUMNS);
6886 errmsg = errbuf;
6887 }
6888 Columns = MIN_COLUMNS;
6889 }
6890
6891#ifdef DJGPP
6892 /* avoid a crash by checking for a too large value of 'columns' */
6893 if (old_Columns != Columns && full_screen && term_console)
6894 mch_check_columns();
6895#endif
6896
6897 /*
6898 * If the screen (shell) height has been changed, assume it is the
6899 * physical screenheight.
6900 */
6901 if (old_Rows != Rows || old_Columns != Columns)
6902 {
6903 /* Changing the screen size is not allowed while updating the screen. */
6904 if (updating_screen)
6905 *pp = old_value;
6906 else if (full_screen
6907#ifdef FEAT_GUI
6908 && !gui.starting
6909#endif
6910 )
6911 set_shellsize((int)Columns, (int)Rows, TRUE);
6912 else
6913 {
6914 /* Postpone the resizing; check the size and cmdline position for
6915 * messages. */
6916 check_shellsize();
6917 if (cmdline_row > Rows - p_ch && Rows > p_ch)
6918 cmdline_row = Rows - p_ch;
6919 }
6920 }
6921
6922 if (curbuf->b_p_sts < 0)
6923 {
6924 errmsg = e_positive;
6925 curbuf->b_p_sts = 0;
6926 }
6927 if (curbuf->b_p_ts <= 0)
6928 {
6929 errmsg = e_positive;
6930 curbuf->b_p_ts = 8;
6931 }
6932 if (curbuf->b_p_tw < 0)
6933 {
6934 errmsg = e_positive;
6935 curbuf->b_p_tw = 0;
6936 }
6937 if (p_tm < 0)
6938 {
6939 errmsg = e_positive;
6940 p_tm = 0;
6941 }
6942 if ((curwin->w_p_scr <= 0
6943 || (curwin->w_p_scr > curwin->w_height
6944 && curwin->w_height > 0))
6945 && full_screen)
6946 {
6947 if (pp == &(curwin->w_p_scr))
6948 {
6949 if (curwin->w_p_scr != 0)
6950 errmsg = e_scroll;
6951 win_comp_scroll(curwin);
6952 }
6953 /* If 'scroll' became invalid because of a side effect silently adjust
6954 * it. */
6955 else if (curwin->w_p_scr <= 0)
6956 curwin->w_p_scr = 1;
6957 else /* curwin->w_p_scr > curwin->w_height */
6958 curwin->w_p_scr = curwin->w_height;
6959 }
6960 if (p_report < 0)
6961 {
6962 errmsg = e_positive;
6963 p_report = 1;
6964 }
6965 if ((p_sj < 0 || p_sj >= Rows) && full_screen)
6966 {
6967 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
6968 p_sj = Rows / 2;
6969 else
6970 {
6971 errmsg = e_scroll;
6972 p_sj = 1;
6973 }
6974 }
6975 if (p_so < 0 && full_screen)
6976 {
6977 errmsg = e_scroll;
6978 p_so = 0;
6979 }
6980 if (p_siso < 0 && full_screen)
6981 {
6982 errmsg = e_positive;
6983 p_siso = 0;
6984 }
6985#ifdef FEAT_CMDWIN
6986 if (p_cwh < 1)
6987 {
6988 errmsg = e_positive;
6989 p_cwh = 1;
6990 }
6991#endif
6992 if (p_ut < 0)
6993 {
6994 errmsg = e_positive;
6995 p_ut = 2000;
6996 }
6997 if (p_ss < 0)
6998 {
6999 errmsg = e_positive;
7000 p_ss = 0;
7001 }
7002
7003 /* May set global value for local option. */
7004 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7005 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7006
7007 options[opt_idx].flags |= P_WAS_SET;
7008
7009 comp_col(); /* in case 'columns' or 'ls' changed */
7010 if (curwin->w_curswant != MAXCOL)
7011 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7012 check_redraw(options[opt_idx].flags);
7013
7014 return errmsg;
7015}
7016
7017/*
7018 * Called after an option changed: check if something needs to be redrawn.
7019 */
7020 static void
7021check_redraw(flags)
7022 long_u flags;
7023{
7024 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7025 int clear = (flags & P_RCLR) == P_RCLR;
7026 int all = ((flags & P_RALL) == P_RALL || clear);
7027
7028#ifdef FEAT_WINDOWS
7029 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7030 status_redraw_all();
7031#endif
7032
7033 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7034 changed_window_setting();
7035 if (flags & P_RBUF)
7036 redraw_curbuf_later(NOT_VALID);
7037 if (clear)
7038 redraw_all_later(CLEAR);
7039 else if (all)
7040 redraw_all_later(NOT_VALID);
7041}
7042
7043/*
7044 * Find index for option 'arg'.
7045 * Return -1 if not found.
7046 */
7047 static int
7048findoption(arg)
7049 char_u *arg;
7050{
7051 int opt_idx;
7052 char *s, *p;
7053 static short quick_tab[27] = {0, 0}; /* quick access table */
7054 int is_term_opt;
7055
7056 /*
7057 * For first call: Initialize the quick-access table.
7058 * It contains the index for the first option that starts with a certain
7059 * letter. There are 26 letters, plus the first "t_" option.
7060 */
7061 if (quick_tab[1] == 0)
7062 {
7063 p = options[0].fullname;
7064 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7065 {
7066 if (s[0] != p[0])
7067 {
7068 if (s[0] == 't' && s[1] == '_')
7069 quick_tab[26] = opt_idx;
7070 else
7071 quick_tab[CharOrdLow(s[0])] = opt_idx;
7072 }
7073 p = s;
7074 }
7075 }
7076
7077 /*
7078 * Check for name starting with an illegal character.
7079 */
7080#ifdef EBCDIC
7081 if (!islower(arg[0]))
7082#else
7083 if (arg[0] < 'a' || arg[0] > 'z')
7084#endif
7085 return -1;
7086
7087 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7088 if (is_term_opt)
7089 opt_idx = quick_tab[26];
7090 else
7091 opt_idx = quick_tab[CharOrdLow(arg[0])];
7092 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7093 {
7094 if (STRCMP(arg, s) == 0) /* match full name */
7095 break;
7096 }
7097 if (s == NULL && !is_term_opt)
7098 {
7099 opt_idx = quick_tab[CharOrdLow(arg[0])];
7100 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7101 {
7102 s = options[opt_idx].shortname;
7103 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7104 break;
7105 s = NULL;
7106 }
7107 }
7108 if (s == NULL)
7109 opt_idx = -1;
7110 return opt_idx;
7111}
7112
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007113#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114/*
7115 * Get the value for an option.
7116 *
7117 * Returns:
7118 * Number or Toggle option: 1, *numval gets value.
7119 * String option: 0, *stringval gets allocated string.
7120 * Hidden Number or Toggle option: -1.
7121 * hidden String option: -2.
7122 * unknown option: -3.
7123 */
7124 int
7125get_option_value(name, numval, stringval, opt_flags)
7126 char_u *name;
7127 long *numval;
7128 char_u **stringval; /* NULL when only checking existance */
7129 int opt_flags;
7130{
7131 int opt_idx;
7132 char_u *varp;
7133
7134 opt_idx = findoption(name);
7135 if (opt_idx < 0) /* unknown option */
7136 return -3;
7137
7138 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7139
7140 if (options[opt_idx].flags & P_STRING)
7141 {
7142 if (varp == NULL) /* hidden option */
7143 return -2;
7144 if (stringval != NULL)
7145 {
7146#ifdef FEAT_CRYPT
7147 /* never return the value of the crypt key */
7148 if ((char_u **)varp == &curbuf->b_p_key)
7149 *stringval = vim_strsave((char_u *)"*****");
7150 else
7151#endif
7152 *stringval = vim_strsave(*(char_u **)(varp));
7153 }
7154 return 0;
7155 }
7156
7157 if (varp == NULL) /* hidden option */
7158 return -1;
7159 if (options[opt_idx].flags & P_NUM)
7160 *numval = *(long *)varp;
7161 else
7162 {
7163 /* Special case: 'modified' is b_changed, but we also want to consider
7164 * it set when 'ff' or 'fenc' changed. */
7165 if ((int *)varp == &curbuf->b_changed)
7166 *numval = curbufIsChanged();
7167 else
7168 *numval = *(int *)varp;
7169 }
7170 return 1;
7171}
7172#endif
7173
7174/*
7175 * Set the value of option "name".
7176 * Use "string" for string options, use "number" for other options.
7177 */
7178 void
7179set_option_value(name, number, string, opt_flags)
7180 char_u *name;
7181 long number;
7182 char_u *string;
7183 int opt_flags; /* OPT_LOCAL or 0 (both) */
7184{
7185 int opt_idx;
7186 char_u *varp;
7187 int flags;
7188
7189 opt_idx = findoption(name);
7190 if (opt_idx == -1)
7191 EMSG2(_("E355: Unknown option: %s"), name);
7192 else
7193 {
7194 flags = options[opt_idx].flags;
7195#ifdef HAVE_SANDBOX
7196 /* Disallow changing some options in the sandbox */
7197 if (sandbox > 0 && (flags & P_SECURE))
7198 EMSG(_(e_sandbox));
7199 else
7200#endif
7201 if (flags & P_STRING)
7202 set_string_option(opt_idx, string, opt_flags);
7203 else
7204 {
7205 varp = get_varp(&options[opt_idx]);
7206 if (varp != NULL) /* hidden option is not changed */
7207 {
7208 if (flags & P_NUM)
7209 (void)set_num_option(opt_idx, varp, number, NULL, opt_flags);
7210 else
7211 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7212 }
7213 }
7214 }
7215}
7216
7217/*
7218 * Get the terminal code for a terminal option.
7219 * Returns NULL when not found.
7220 */
7221 char_u *
7222get_term_code(tname)
7223 char_u *tname;
7224{
7225 int opt_idx;
7226 char_u *varp;
7227
7228 if (tname[0] != 't' || tname[1] != '_' ||
7229 tname[2] == NUL || tname[3] == NUL)
7230 return NULL;
7231 if ((opt_idx = findoption(tname)) >= 0)
7232 {
7233 varp = get_varp(&(options[opt_idx]));
7234 if (varp != NULL)
7235 varp = *(char_u **)(varp);
7236 return varp;
7237 }
7238 return find_termcode(tname + 2);
7239}
7240
7241 char_u *
7242get_highlight_default()
7243{
7244 int i;
7245
7246 i = findoption((char_u *)"hl");
7247 if (i >= 0)
7248 return options[i].def_val[VI_DEFAULT];
7249 return (char_u *)NULL;
7250}
7251
7252/*
7253 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7254 */
7255 static int
7256find_key_option(arg)
7257 char_u *arg;
7258{
7259 int key;
7260 int modifiers;
7261
7262 /*
7263 * Don't use get_special_key_code() for t_xx, we don't want it to call
7264 * add_termcap_entry().
7265 */
7266 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7267 key = TERMCAP2KEY(arg[2], arg[3]);
7268 else
7269 {
7270 --arg; /* put arg at the '<' */
7271 modifiers = 0;
7272 key = find_special_key(&arg, &modifiers, TRUE);
7273 if (modifiers) /* can't handle modifiers here */
7274 key = 0;
7275 }
7276 return key;
7277}
7278
7279/*
7280 * if 'all' == 0: show changed options
7281 * if 'all' == 1: show all normal options
7282 * if 'all' == 2: show all terminal options
7283 */
7284 static void
7285showoptions(all, opt_flags)
7286 int all;
7287 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7288{
7289 struct vimoption *p;
7290 int col;
7291 int isterm;
7292 char_u *varp;
7293 struct vimoption **items;
7294 int item_count;
7295 int run;
7296 int row, rows;
7297 int cols;
7298 int i;
7299 int len;
7300
7301#define INC 20
7302#define GAP 3
7303
7304 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7305 PARAM_COUNT));
7306 if (items == NULL)
7307 return;
7308
7309 /* Highlight title */
7310 if (all == 2)
7311 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7312 else if (opt_flags & OPT_GLOBAL)
7313 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7314 else if (opt_flags & OPT_LOCAL)
7315 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7316 else
7317 MSG_PUTS_TITLE(_("\n--- Options ---"));
7318
7319 /*
7320 * do the loop two times:
7321 * 1. display the short items
7322 * 2. display the long items (only strings and numbers)
7323 */
7324 for (run = 1; run <= 2 && !got_int; ++run)
7325 {
7326 /*
7327 * collect the items in items[]
7328 */
7329 item_count = 0;
7330 for (p = &options[0]; p->fullname != NULL; p++)
7331 {
7332 varp = NULL;
7333 isterm = istermoption(p);
7334 if (opt_flags != 0)
7335 {
7336 if (p->indir != PV_NONE && !isterm)
7337 varp = get_varp_scope(p, opt_flags);
7338 }
7339 else
7340 varp = get_varp(p);
7341 if (varp != NULL
7342 && ((all == 2 && isterm)
7343 || (all == 1 && !isterm)
7344 || (all == 0 && !optval_default(p, varp))))
7345 {
7346 if (p->flags & P_BOOL)
7347 len = 1; /* a toggle option fits always */
7348 else
7349 {
7350 option_value2string(p, opt_flags);
7351 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7352 }
7353 if ((len <= INC - GAP && run == 1) ||
7354 (len > INC - GAP && run == 2))
7355 items[item_count++] = p;
7356 }
7357 }
7358
7359 /*
7360 * display the items
7361 */
7362 if (run == 1)
7363 {
7364 cols = (Columns + GAP - 3) / INC;
7365 if (cols == 0)
7366 cols = 1;
7367 rows = (item_count + cols - 1) / cols;
7368 }
7369 else /* run == 2 */
7370 rows = item_count;
7371 for (row = 0; row < rows && !got_int; ++row)
7372 {
7373 msg_putchar('\n'); /* go to next line */
7374 if (got_int) /* 'q' typed in more */
7375 break;
7376 col = 0;
7377 for (i = row; i < item_count; i += rows)
7378 {
7379 msg_col = col; /* make columns */
7380 showoneopt(items[i], opt_flags);
7381 col += INC;
7382 }
7383 out_flush();
7384 ui_breakcheck();
7385 }
7386 }
7387 vim_free(items);
7388}
7389
7390/*
7391 * Return TRUE if option "p" has its default value.
7392 */
7393 static int
7394optval_default(p, varp)
7395 struct vimoption *p;
7396 char_u *varp;
7397{
7398 int dvi;
7399
7400 if (varp == NULL)
7401 return TRUE; /* hidden option is always at default */
7402 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7403 if (p->flags & P_NUM)
7404 return (*(long *)varp == (long)p->def_val[dvi]);
7405 if (p->flags & P_BOOL)
7406 /* the cast to long is required for Manx C */
7407 return (*(int *)varp == (int)(long)p->def_val[dvi]);
7408 /* P_STRING */
7409 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7410}
7411
7412/*
7413 * showoneopt: show the value of one option
7414 * must not be called with a hidden option!
7415 */
7416 static void
7417showoneopt(p, opt_flags)
7418 struct vimoption *p;
7419 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
7420{
7421 char_u *varp;
7422
7423 varp = get_varp_scope(p, opt_flags);
7424
7425 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7426 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7427 ? !curbufIsChanged() : !*(int *)varp))
7428 MSG_PUTS("no");
7429 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7430 MSG_PUTS("--");
7431 else
7432 MSG_PUTS(" ");
7433 MSG_PUTS(p->fullname);
7434 if (!(p->flags & P_BOOL))
7435 {
7436 msg_putchar('=');
7437 /* put value string in NameBuff */
7438 option_value2string(p, opt_flags);
7439 msg_outtrans(NameBuff);
7440 }
7441}
7442
7443/*
7444 * Write modified options as ":set" commands to a file.
7445 *
7446 * There are three values for "opt_flags":
7447 * OPT_GLOBAL: Write global option values and fresh values of
7448 * buffer-local options (used for start of a session
7449 * file).
7450 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7451 * curwin (used for a vimrc file).
7452 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
7453 * and local values for window-local options of
7454 * curwin. Local values are also written when at the
7455 * default value, because a modeline or autocommand
7456 * may have set them when doing ":edit file" and the
7457 * user has set them back at the default or fresh
7458 * value.
7459 * When "local_only" is TRUE, don't write fresh
7460 * values, only local values (for ":mkview").
7461 * (fresh value = value used for a new buffer or window for a local option).
7462 *
7463 * Return FAIL on error, OK otherwise.
7464 */
7465 int
7466makeset(fd, opt_flags, local_only)
7467 FILE *fd;
7468 int opt_flags;
7469 int local_only;
7470{
7471 struct vimoption *p;
7472 char_u *varp; /* currently used value */
7473 char_u *varp_fresh; /* local value */
7474 char_u *varp_local = NULL; /* fresh value */
7475 char *cmd;
7476 int round;
7477
7478 /*
7479 * The options that don't have a default (terminal name, columns, lines)
7480 * are never written. Terminal options are also not written.
7481 */
7482 for (p = &options[0]; !istermoption(p); p++)
7483 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7484 {
7485 /* skip global option when only doing locals */
7486 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7487 continue;
7488
7489 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
7490 * file, they are always buffer-specific. */
7491 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
7492 continue;
7493
7494 /* Global values are only written when not at the default value. */
7495 varp = get_varp_scope(p, opt_flags);
7496 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
7497 continue;
7498
7499 round = 2;
7500 if (p->indir != PV_NONE)
7501 {
7502 if (p->var == VAR_WIN)
7503 {
7504 /* skip window-local option when only doing globals */
7505 if (!(opt_flags & OPT_LOCAL))
7506 continue;
7507 /* When fresh value of window-local option is not at the
7508 * default, need to write it too. */
7509 if (!(opt_flags & OPT_GLOBAL) && !local_only)
7510 {
7511 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
7512 if (!optval_default(p, varp_fresh))
7513 {
7514 round = 1;
7515 varp_local = varp;
7516 varp = varp_fresh;
7517 }
7518 }
7519 }
7520 }
7521
7522 /* Round 1: fresh value for window-local options.
7523 * Round 2: other values */
7524 for ( ; round <= 2; varp = varp_local, ++round)
7525 {
7526 if (round == 1 || (opt_flags & OPT_GLOBAL))
7527 cmd = "set";
7528 else
7529 cmd = "setlocal";
7530
7531 if (p->flags & P_BOOL)
7532 {
7533 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
7534 return FAIL;
7535 }
7536 else if (p->flags & P_NUM)
7537 {
7538 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
7539 return FAIL;
7540 }
7541 else /* P_STRING */
7542 {
7543 /* Don't set 'syntax' and 'filetype' again if the value is
7544 * already right, avoids reloading the syntax file. */
7545 if (p->indir == PV_SYN || p->indir == PV_FT)
7546 {
7547 if (fprintf(fd, "if &%s != '%s'", p->fullname,
7548 *(char_u **)(varp)) < 0
7549 || put_eol(fd) < 0)
7550 return FAIL;
7551 }
7552 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
7553 (p->flags & P_EXPAND) != 0) == FAIL)
7554 return FAIL;
7555 if (p->indir == PV_SYN || p->indir == PV_FT)
7556 {
7557 if (put_line(fd, "endif") == FAIL)
7558 return FAIL;
7559 }
7560 }
7561 }
7562 }
7563 return OK;
7564}
7565
7566#if defined(FEAT_FOLDING) || defined(PROTO)
7567/*
7568 * Generate set commands for the local fold options only. Used when
7569 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
7570 */
7571 int
7572makefoldset(fd)
7573 FILE *fd;
7574{
7575 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
7576# ifdef FEAT_EVAL
7577 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
7578 == FAIL
7579# endif
7580 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
7581 == FAIL
7582 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
7583 == FAIL
7584 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
7585 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
7586 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
7587 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
7588 )
7589 return FAIL;
7590
7591 return OK;
7592}
7593#endif
7594
7595 static int
7596put_setstring(fd, cmd, name, valuep, expand)
7597 FILE *fd;
7598 char *cmd;
7599 char *name;
7600 char_u **valuep;
7601 int expand;
7602{
7603 char_u *s;
7604 char_u buf[MAXPATHL];
7605
7606 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7607 return FAIL;
7608 if (*valuep != NULL)
7609 {
7610 /* Output 'pastetoggle' as key names. For other
7611 * options some characters have to be escaped with
7612 * CTRL-V or backslash */
7613 if (valuep == &p_pt)
7614 {
7615 s = *valuep;
7616 while (*s != NUL)
7617 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
7618 return FAIL;
7619 }
7620 else if (expand)
7621 {
7622 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
7623 if (put_escstr(fd, buf, 2) == FAIL)
7624 return FAIL;
7625 }
7626 else if (put_escstr(fd, *valuep, 2) == FAIL)
7627 return FAIL;
7628 }
7629 if (put_eol(fd) < 0)
7630 return FAIL;
7631 return OK;
7632}
7633
7634 static int
7635put_setnum(fd, cmd, name, valuep)
7636 FILE *fd;
7637 char *cmd;
7638 char *name;
7639 long *valuep;
7640{
7641 long wc;
7642
7643 if (fprintf(fd, "%s %s=", cmd, name) < 0)
7644 return FAIL;
7645 if (wc_use_keyname((char_u *)valuep, &wc))
7646 {
7647 /* print 'wildchar' and 'wildcharm' as a key name */
7648 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
7649 return FAIL;
7650 }
7651 else if (fprintf(fd, "%ld", *valuep) < 0)
7652 return FAIL;
7653 if (put_eol(fd) < 0)
7654 return FAIL;
7655 return OK;
7656}
7657
7658 static int
7659put_setbool(fd, cmd, name, value)
7660 FILE *fd;
7661 char *cmd;
7662 char *name;
7663 int value;
7664{
7665 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
7666 || put_eol(fd) < 0)
7667 return FAIL;
7668 return OK;
7669}
7670
7671/*
7672 * Clear all the terminal options.
7673 * If the option has been allocated, free the memory.
7674 * Terminal options are never hidden or indirect.
7675 */
7676 void
7677clear_termoptions()
7678{
7679 struct vimoption *p;
7680
7681 /*
7682 * Reset a few things before clearing the old options. This may cause
7683 * outputting a few things that the terminal doesn't understand, but the
7684 * screen will be cleared later, so this is OK.
7685 */
7686#ifdef FEAT_MOUSE_TTY
7687 mch_setmouse(FALSE); /* switch mouse off */
7688#endif
7689#ifdef FEAT_TITLE
7690 mch_restore_title(3); /* restore window titles */
7691#endif
7692#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
7693 /* When starting the GUI close the display opened for the clipboard.
7694 * After restoring the title, because that will need the display. */
7695 if (gui.starting)
7696 clear_xterm_clip();
7697#endif
7698#ifdef WIN3264
7699 /*
7700 * Check if this is allowed now.
7701 */
7702 if (can_end_termcap_mode(FALSE) == TRUE)
7703#endif
7704 stoptermcap(); /* stop termcap mode */
7705
7706 for (p = &options[0]; p->fullname != NULL; p++)
7707 if (istermoption(p))
7708 {
7709 if (p->flags & P_ALLOCED)
7710 free_string_option(*(char_u **)(p->var));
7711 if (p->flags & P_DEF_ALLOCED)
7712 free_string_option(p->def_val[VI_DEFAULT]);
7713 *(char_u **)(p->var) = empty_option;
7714 p->def_val[VI_DEFAULT] = empty_option;
7715 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
7716 }
7717 clear_termcodes();
7718}
7719
7720/*
7721 * Set the terminal option defaults to the current value.
7722 * Used after setting the terminal name.
7723 */
7724 void
7725set_term_defaults()
7726{
7727 struct vimoption *p;
7728
7729 for (p = &options[0]; p->fullname != NULL; p++)
7730 {
7731 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
7732 {
7733 if (p->flags & P_DEF_ALLOCED)
7734 {
7735 free_string_option(p->def_val[VI_DEFAULT]);
7736 p->flags &= ~P_DEF_ALLOCED;
7737 }
7738 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
7739 if (p->flags & P_ALLOCED)
7740 {
7741 p->flags |= P_DEF_ALLOCED;
7742 p->flags &= ~P_ALLOCED; /* don't free the value now */
7743 }
7744 }
7745 }
7746}
7747
7748/*
7749 * return TRUE if 'p' starts with 't_'
7750 */
7751 static int
7752istermoption(p)
7753 struct vimoption *p;
7754{
7755 return (p->fullname[0] == 't' && p->fullname[1] == '_');
7756}
7757
7758/*
7759 * Compute columns for ruler and shown command. 'sc_col' is also used to
7760 * decide what the maximum length of a message on the status line can be.
7761 * If there is a status line for the last window, 'sc_col' is independent
7762 * of 'ru_col'.
7763 */
7764
7765#define COL_RULER 17 /* columns needed by standard ruler */
7766
7767 void
7768comp_col()
7769{
7770#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
7771 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
7772
7773 sc_col = 0;
7774 ru_col = 0;
7775 if (p_ru)
7776 {
7777#ifdef FEAT_STL_OPT
7778 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
7779#else
7780 ru_col = COL_RULER + 1;
7781#endif
7782 /* no last status line, adjust sc_col */
7783 if (!last_has_status)
7784 sc_col = ru_col;
7785 }
7786 if (p_sc)
7787 {
7788 sc_col += SHOWCMD_COLS;
7789 if (!p_ru || last_has_status) /* no need for separating space */
7790 ++sc_col;
7791 }
7792 sc_col = Columns - sc_col;
7793 ru_col = Columns - ru_col;
7794 if (sc_col <= 0) /* screen too narrow, will become a mess */
7795 sc_col = 1;
7796 if (ru_col <= 0)
7797 ru_col = 1;
7798#else
7799 sc_col = Columns;
7800 ru_col = Columns;
7801#endif
7802}
7803
7804/*
7805 * Get pointer to option variable, depending on local or global scope.
7806 */
7807 static char_u *
7808get_varp_scope(p, opt_flags)
7809 struct vimoption *p;
7810 int opt_flags;
7811{
7812 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
7813 {
7814 if (p->var == VAR_WIN)
7815 return (char_u *)GLOBAL_WO(get_varp(p));
7816 return p->var;
7817 }
7818 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
7819 {
7820 switch ((int)p->indir)
7821 {
7822#ifdef FEAT_QUICKFIX
7823 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
7824 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
7825 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
7826#endif
7827 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
7828 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
7829 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
7830 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
7831 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
7832#ifdef FEAT_FIND_ID
7833 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
7834 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
7835#endif
7836#ifdef FEAT_INS_EXPAND
7837 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
7838 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
7839#endif
7840 }
7841 return NULL; /* "cannot happen" */
7842 }
7843 return get_varp(p);
7844}
7845
7846/*
7847 * Get pointer to option variable.
7848 */
7849 static char_u *
7850get_varp(p)
7851 struct vimoption *p;
7852{
7853 /* hidden option, always return NULL */
7854 if (p->var == NULL)
7855 return NULL;
7856
7857 switch ((int)p->indir)
7858 {
7859 case PV_NONE: return p->var;
7860
7861 /* global option with local value: use local value if it's been set */
7862 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
7863 ? (char_u *)&curbuf->b_p_ep : p->var;
7864 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
7865 ? (char_u *)&curbuf->b_p_kp : p->var;
7866 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
7867 ? (char_u *)&(curbuf->b_p_path) : p->var;
7868 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
7869 ? (char_u *)&(curbuf->b_p_ar) : p->var;
7870 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
7871 ? (char_u *)&(curbuf->b_p_tags) : p->var;
7872#ifdef FEAT_FIND_ID
7873 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
7874 ? (char_u *)&(curbuf->b_p_def) : p->var;
7875 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
7876 ? (char_u *)&(curbuf->b_p_inc) : p->var;
7877#endif
7878#ifdef FEAT_INS_EXPAND
7879 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
7880 ? (char_u *)&(curbuf->b_p_dict) : p->var;
7881 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
7882 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
7883#endif
7884#ifdef FEAT_QUICKFIX
7885 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
7886 ? (char_u *)&(curbuf->b_p_gp) : p->var;
7887 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
7888 ? (char_u *)&(curbuf->b_p_mp) : p->var;
7889 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
7890 ? (char_u *)&(curbuf->b_p_efm) : p->var;
7891#endif
7892
7893#ifdef FEAT_ARABIC
7894 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
7895#endif
7896 case PV_LIST: return (char_u *)&(curwin->w_p_list);
7897#ifdef FEAT_DIFF
7898 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
7899#endif
7900#ifdef FEAT_FOLDING
7901 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
7902 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
7903 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
7904 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
7905 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
7906 case PV_FML: return (char_u *)&(curwin->w_p_fml);
7907 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
7908# ifdef FEAT_EVAL
7909 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
7910 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
7911# endif
7912 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
7913#endif
7914 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007915#ifdef FEAT_LINEBREAK
7916 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
7917#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918#if defined(FEAT_WINDOWS)
7919 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
7920#endif
7921#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7922 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
7923#endif
7924#ifdef FEAT_RIGHTLEFT
7925 case PV_RL: return (char_u *)&(curwin->w_p_rl);
7926 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
7927#endif
7928 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
7929 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
7930#ifdef FEAT_LINEBREAK
7931 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
7932#endif
7933#ifdef FEAT_SCROLLBIND
7934 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
7935#endif
7936
7937 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
7938 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
7939#ifdef FEAT_MBYTE
7940 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
7941#endif
7942#if defined(FEAT_QUICKFIX)
7943 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
7944 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
7945#endif
7946 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
7947 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
7948#ifdef FEAT_CINDENT
7949 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
7950 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
7951 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
7952#endif
7953#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
7954 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
7955#endif
7956#ifdef FEAT_COMMENTS
7957 case PV_COM: return (char_u *)&(curbuf->b_p_com);
7958#endif
7959#ifdef FEAT_FOLDING
7960 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
7961#endif
7962#ifdef FEAT_INS_EXPAND
7963 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
7964#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007965#ifdef FEAT_COMPL_FUNC
7966 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
7967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
7969 case PV_ET: return (char_u *)&(curbuf->b_p_et);
7970#ifdef FEAT_MBYTE
7971 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
7972#endif
7973 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
7974#ifdef FEAT_AUTOCMD
7975 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
7976#endif
7977 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
7978 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
7979 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
7980 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
7981 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
7982#ifdef FEAT_FIND_ID
7983# ifdef FEAT_EVAL
7984 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
7985# endif
7986#endif
7987#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
7988 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
7989 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
7990#endif
7991#ifdef FEAT_CRYPT
7992 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
7993#endif
7994#ifdef FEAT_LISP
7995 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
7996#endif
7997 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
7998 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
7999 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8000 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8001 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8002#ifdef FEAT_OSFILETYPE
8003 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8004#endif
8005 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008006#ifdef FEAT_TEXTOBJ
8007 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8010#ifdef FEAT_SMARTINDENT
8011 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8012#endif
8013#ifndef SHORT_FNAME
8014 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8015#endif
8016 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8017#ifdef FEAT_SEARCHPATH
8018 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8019#endif
8020 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8021#ifdef FEAT_SYN_HL
8022 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
8023#endif
8024 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8025 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8026 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8027 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8028 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8029#ifdef FEAT_KEYMAP
8030 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8031#endif
8032 default: EMSG(_("E356: get_varp ERROR"));
8033 }
8034 /* always return a valid pointer to avoid a crash! */
8035 return (char_u *)&(curbuf->b_p_wm);
8036}
8037
8038/*
8039 * Get the value of 'equalprg', either the buffer-local one or the global one.
8040 */
8041 char_u *
8042get_equalprg()
8043{
8044 if (*curbuf->b_p_ep == NUL)
8045 return p_ep;
8046 return curbuf->b_p_ep;
8047}
8048
8049#if defined(FEAT_WINDOWS) || defined(PROTO)
8050/*
8051 * Copy options from one window to another.
8052 * Used when splitting a window.
8053 */
8054 void
8055win_copy_options(wp_from, wp_to)
8056 win_T *wp_from;
8057 win_T *wp_to;
8058{
8059 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8060 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8061# ifdef FEAT_RIGHTLEFT
8062# ifdef FEAT_FKMAP
8063 /* Is this right? */
8064 wp_to->w_farsi = wp_from->w_farsi;
8065# endif
8066# endif
8067}
8068#endif
8069
8070/*
8071 * Copy the options from one winopt_T to another.
8072 * Doesn't free the old option values in "to", use clear_winopt() for that.
8073 * The 'scroll' option is not copied, because it depends on the window height.
8074 * The 'previewwindow' option is reset, there can be only one preview window.
8075 */
8076 void
8077copy_winopt(from, to)
8078 winopt_T *from;
8079 winopt_T *to;
8080{
8081#ifdef FEAT_ARABIC
8082 to->wo_arab = from->wo_arab;
8083#endif
8084 to->wo_list = from->wo_list;
8085 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008086#ifdef FEAT_LINEBREAK
8087 to->wo_nuw = from->wo_nuw;
8088#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008089#ifdef FEAT_RIGHTLEFT
8090 to->wo_rl = from->wo_rl;
8091 to->wo_rlc = vim_strsave(from->wo_rlc);
8092#endif
8093 to->wo_wrap = from->wo_wrap;
8094#ifdef FEAT_LINEBREAK
8095 to->wo_lbr = from->wo_lbr;
8096#endif
8097#ifdef FEAT_SCROLLBIND
8098 to->wo_scb = from->wo_scb;
8099#endif
8100#ifdef FEAT_DIFF
8101 to->wo_diff = from->wo_diff;
8102#endif
8103#ifdef FEAT_FOLDING
8104 to->wo_fdc = from->wo_fdc;
8105 to->wo_fen = from->wo_fen;
8106 to->wo_fdi = vim_strsave(from->wo_fdi);
8107 to->wo_fml = from->wo_fml;
8108 to->wo_fdl = from->wo_fdl;
8109 to->wo_fdm = vim_strsave(from->wo_fdm);
8110 to->wo_fdn = from->wo_fdn;
8111# ifdef FEAT_EVAL
8112 to->wo_fde = vim_strsave(from->wo_fde);
8113 to->wo_fdt = vim_strsave(from->wo_fdt);
8114# endif
8115 to->wo_fmr = vim_strsave(from->wo_fmr);
8116#endif
8117 check_winopt(to); /* don't want NULL pointers */
8118}
8119
8120/*
8121 * Check string options in a window for a NULL value.
8122 */
8123 void
8124check_win_options(win)
8125 win_T *win;
8126{
8127 check_winopt(&win->w_onebuf_opt);
8128 check_winopt(&win->w_allbuf_opt);
8129}
8130
8131/*
8132 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8133 */
8134/*ARGSUSED*/
8135 void
8136check_winopt(wop)
8137 winopt_T *wop;
8138{
8139#ifdef FEAT_FOLDING
8140 check_string_option(&wop->wo_fdi);
8141 check_string_option(&wop->wo_fdm);
8142# ifdef FEAT_EVAL
8143 check_string_option(&wop->wo_fde);
8144 check_string_option(&wop->wo_fdt);
8145# endif
8146 check_string_option(&wop->wo_fmr);
8147#endif
8148#ifdef FEAT_RIGHTLEFT
8149 check_string_option(&wop->wo_rlc);
8150#endif
8151}
8152
8153/*
8154 * Free the allocated memory inside a winopt_T.
8155 */
8156/*ARGSUSED*/
8157 void
8158clear_winopt(wop)
8159 winopt_T *wop;
8160{
8161#ifdef FEAT_FOLDING
8162 clear_string_option(&wop->wo_fdi);
8163 clear_string_option(&wop->wo_fdm);
8164# ifdef FEAT_EVAL
8165 clear_string_option(&wop->wo_fde);
8166 clear_string_option(&wop->wo_fdt);
8167# endif
8168 clear_string_option(&wop->wo_fmr);
8169#endif
8170#ifdef FEAT_RIGHTLEFT
8171 clear_string_option(&wop->wo_rlc);
8172#endif
8173}
8174
8175/*
8176 * Copy global option values to local options for one buffer.
8177 * Used when creating a new buffer and sometimes when entering a buffer.
8178 * flags:
8179 * BCO_ENTER We will enter the buf buffer.
8180 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8181 * appropriate.
8182 * BCO_NOHELP Don't copy the values to a help buffer.
8183 */
8184 void
8185buf_copy_options(buf, flags)
8186 buf_T *buf;
8187 int flags;
8188{
8189 int should_copy = TRUE;
8190 char_u *save_p_isk = NULL; /* init for GCC */
8191 int dont_do_help;
8192 int did_isk = FALSE;
8193
8194 /*
8195 * Don't do anything of the buffer is invalid.
8196 */
8197 if (buf == NULL || !buf_valid(buf))
8198 return;
8199
8200 /*
8201 * Skip this when the option defaults have not been set yet. Happens when
8202 * main() allocates the first buffer.
8203 */
8204 if (p_cpo != NULL)
8205 {
8206 /*
8207 * Always copy when entering and 'cpo' contains 'S'.
8208 * Don't copy when already initialized.
8209 * Don't copy when 'cpo' contains 's' and not entering.
8210 * 'S' BCO_ENTER initialized 's' should_copy
8211 * yes yes X X TRUE
8212 * yes no yes X FALSE
8213 * no X yes X FALSE
8214 * X no no yes FALSE
8215 * X no no no TRUE
8216 * no yes no X TRUE
8217 */
8218 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8219 && (buf->b_p_initialized
8220 || (!(flags & BCO_ENTER)
8221 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8222 should_copy = FALSE;
8223
8224 if (should_copy || (flags & BCO_ALWAYS))
8225 {
8226 /* Don't copy the options specific to a help buffer when
8227 * BCO_NOHELP is given or the options were initialized already
8228 * (jumping back to a help file with CTRL-T or CTRL-O) */
8229 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8230 || buf->b_p_initialized;
8231 if (dont_do_help) /* don't free b_p_isk */
8232 {
8233 save_p_isk = buf->b_p_isk;
8234 buf->b_p_isk = NULL;
8235 }
8236 /*
8237 * Always free the allocated strings.
8238 * If not already initialized, set 'readonly' and copy 'fileformat'.
8239 */
8240 if (!buf->b_p_initialized)
8241 {
8242 free_buf_options(buf, TRUE);
8243 buf->b_p_ro = FALSE; /* don't copy readonly */
8244 buf->b_p_tx = p_tx;
8245#ifdef FEAT_MBYTE
8246 buf->b_p_fenc = vim_strsave(p_fenc);
8247#endif
8248 buf->b_p_ff = vim_strsave(p_ff);
8249#if defined(FEAT_QUICKFIX)
8250 buf->b_p_bh = empty_option;
8251 buf->b_p_bt = empty_option;
8252#endif
8253 }
8254 else
8255 free_buf_options(buf, FALSE);
8256
8257 buf->b_p_ai = p_ai;
8258 buf->b_p_ai_nopaste = p_ai_nopaste;
8259 buf->b_p_sw = p_sw;
8260 buf->b_p_tw = p_tw;
8261 buf->b_p_tw_nopaste = p_tw_nopaste;
8262 buf->b_p_tw_nobin = p_tw_nobin;
8263 buf->b_p_wm = p_wm;
8264 buf->b_p_wm_nopaste = p_wm_nopaste;
8265 buf->b_p_wm_nobin = p_wm_nobin;
8266 buf->b_p_bin = p_bin;
8267 buf->b_p_et = p_et;
8268 buf->b_p_et_nobin = p_et_nobin;
8269 buf->b_p_ml = p_ml;
8270 buf->b_p_ml_nobin = p_ml_nobin;
8271 buf->b_p_inf = p_inf;
8272 buf->b_p_swf = p_swf;
8273#ifdef FEAT_INS_EXPAND
8274 buf->b_p_cpt = vim_strsave(p_cpt);
8275#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008276#ifdef FEAT_COMPL_FUNC
8277 buf->b_p_cfu = vim_strsave(p_cfu);
8278#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008279 buf->b_p_sts = p_sts;
8280 buf->b_p_sts_nopaste = p_sts_nopaste;
8281#ifndef SHORT_FNAME
8282 buf->b_p_sn = p_sn;
8283#endif
8284#ifdef FEAT_COMMENTS
8285 buf->b_p_com = vim_strsave(p_com);
8286#endif
8287#ifdef FEAT_FOLDING
8288 buf->b_p_cms = vim_strsave(p_cms);
8289#endif
8290 buf->b_p_fo = vim_strsave(p_fo);
8291 buf->b_p_nf = vim_strsave(p_nf);
8292 buf->b_p_mps = vim_strsave(p_mps);
8293#ifdef FEAT_SMARTINDENT
8294 buf->b_p_si = p_si;
8295#endif
8296 buf->b_p_ci = p_ci;
8297#ifdef FEAT_CINDENT
8298 buf->b_p_cin = p_cin;
8299 buf->b_p_cink = vim_strsave(p_cink);
8300 buf->b_p_cino = vim_strsave(p_cino);
8301#endif
8302#ifdef FEAT_AUTOCMD
8303 /* Don't copy 'filetype', it must be detected */
8304 buf->b_p_ft = empty_option;
8305#endif
8306#ifdef FEAT_OSFILETYPE
8307 buf->b_p_oft = vim_strsave(p_oft);
8308#endif
8309 buf->b_p_pi = p_pi;
8310#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8311 buf->b_p_cinw = vim_strsave(p_cinw);
8312#endif
8313#ifdef FEAT_LISP
8314 buf->b_p_lisp = p_lisp;
8315#endif
8316#ifdef FEAT_SYN_HL
8317 /* Don't copy 'syntax', it must be set */
8318 buf->b_p_syn = empty_option;
8319#endif
8320#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8321 buf->b_p_inde = vim_strsave(p_inde);
8322 buf->b_p_indk = vim_strsave(p_indk);
8323#endif
8324#ifdef FEAT_CRYPT
8325 buf->b_p_key = vim_strsave(p_key);
8326#endif
8327#ifdef FEAT_SEARCHPATH
8328 buf->b_p_sua = vim_strsave(p_sua);
8329#endif
8330#ifdef FEAT_KEYMAP
8331 buf->b_p_keymap = vim_strsave(p_keymap);
8332 buf->b_kmap_state |= KEYMAP_INIT;
8333#endif
8334 /* This isn't really an option, but copying the langmap and IME
8335 * state from the current buffer is better than resetting it. */
8336 buf->b_p_iminsert = p_iminsert;
8337 buf->b_p_imsearch = p_imsearch;
8338
8339 /* options that are normally global but also have a local value
8340 * are not copied, start using the global value */
8341 buf->b_p_ar = -1;
8342#ifdef FEAT_QUICKFIX
8343 buf->b_p_gp = empty_option;
8344 buf->b_p_mp = empty_option;
8345 buf->b_p_efm = empty_option;
8346#endif
8347 buf->b_p_ep = empty_option;
8348 buf->b_p_kp = empty_option;
8349 buf->b_p_path = empty_option;
8350 buf->b_p_tags = empty_option;
8351#ifdef FEAT_FIND_ID
8352 buf->b_p_def = empty_option;
8353 buf->b_p_inc = empty_option;
8354# ifdef FEAT_EVAL
8355 buf->b_p_inex = vim_strsave(p_inex);
8356# endif
8357#endif
8358#ifdef FEAT_INS_EXPAND
8359 buf->b_p_dict = empty_option;
8360 buf->b_p_tsr = empty_option;
8361#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008362#ifdef FEAT_TEXTOBJ
8363 buf->b_p_qe = vim_strsave(p_qe);
8364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365
8366 /*
8367 * Don't copy the options set by ex_help(), use the saved values,
8368 * when going from a help buffer to a non-help buffer.
8369 * Don't touch these at all when BCO_NOHELP is used and going from
8370 * or to a help buffer.
8371 */
8372 if (dont_do_help)
8373 buf->b_p_isk = save_p_isk;
8374 else
8375 {
8376 buf->b_p_isk = vim_strsave(p_isk);
8377 did_isk = TRUE;
8378 buf->b_p_ts = p_ts;
8379 buf->b_help = FALSE;
8380#ifdef FEAT_QUICKFIX
8381 if (buf->b_p_bt[0] == 'h')
8382 clear_string_option(&buf->b_p_bt);
8383#endif
8384 buf->b_p_ma = p_ma;
8385 }
8386 }
8387
8388 /*
8389 * When the options should be copied (ignoring BCO_ALWAYS), set the
8390 * flag that indicates that the options have been initialized.
8391 */
8392 if (should_copy)
8393 buf->b_p_initialized = TRUE;
8394 }
8395
8396 check_buf_options(buf); /* make sure we don't have NULLs */
8397 if (did_isk)
8398 (void)buf_init_chartab(buf, FALSE);
8399}
8400
8401/*
8402 * Reset the 'modifiable' option and its default value.
8403 */
8404 void
8405reset_modifiable()
8406{
8407 int opt_idx;
8408
8409 curbuf->b_p_ma = FALSE;
8410 p_ma = FALSE;
8411 opt_idx = findoption((char_u *)"ma");
8412 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8413}
8414
8415/*
8416 * Set the global value for 'iminsert' to the local value.
8417 */
8418 void
8419set_iminsert_global()
8420{
8421 p_iminsert = curbuf->b_p_iminsert;
8422}
8423
8424/*
8425 * Set the global value for 'imsearch' to the local value.
8426 */
8427 void
8428set_imsearch_global()
8429{
8430 p_imsearch = curbuf->b_p_imsearch;
8431}
8432
8433#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8434static int expand_option_idx = -1;
8435static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8436static int expand_option_flags = 0;
8437
8438 void
8439set_context_in_set_cmd(xp, arg, opt_flags)
8440 expand_T *xp;
8441 char_u *arg;
8442 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8443{
8444 int nextchar;
8445 long_u flags = 0; /* init for GCC */
8446 int opt_idx = 0; /* init for GCC */
8447 char_u *p;
8448 char_u *s;
8449 int is_term_option = FALSE;
8450 int key;
8451
8452 expand_option_flags = opt_flags;
8453
8454 xp->xp_context = EXPAND_SETTINGS;
8455 if (*arg == NUL)
8456 {
8457 xp->xp_pattern = arg;
8458 return;
8459 }
8460 p = arg + STRLEN(arg) - 1;
8461 if (*p == ' ' && *(p - 1) != '\\')
8462 {
8463 xp->xp_pattern = p + 1;
8464 return;
8465 }
8466 while (p > arg)
8467 {
8468 s = p;
8469 /* count number of backslashes before ' ' or ',' */
8470 if (*p == ' ' || *p == ',')
8471 {
8472 while (s > arg && *(s - 1) == '\\')
8473 --s;
8474 }
8475 /* break at a space with an even number of backslashes */
8476 if (*p == ' ' && ((p - s) & 1) == 0)
8477 {
8478 ++p;
8479 break;
8480 }
8481 --p;
8482 }
8483 if (STRNCMP(p, "no", 2) == 0)
8484 {
8485 xp->xp_context = EXPAND_BOOL_SETTINGS;
8486 p += 2;
8487 }
8488 if (STRNCMP(p, "inv", 3) == 0)
8489 {
8490 xp->xp_context = EXPAND_BOOL_SETTINGS;
8491 p += 3;
8492 }
8493 xp->xp_pattern = arg = p;
8494 if (*arg == '<')
8495 {
8496 while (*p != '>')
8497 if (*p++ == NUL) /* expand terminal option name */
8498 return;
8499 key = get_special_key_code(arg + 1);
8500 if (key == 0) /* unknown name */
8501 {
8502 xp->xp_context = EXPAND_NOTHING;
8503 return;
8504 }
8505 nextchar = *++p;
8506 is_term_option = TRUE;
8507 expand_option_name[2] = KEY2TERMCAP0(key);
8508 expand_option_name[3] = KEY2TERMCAP1(key);
8509 }
8510 else
8511 {
8512 if (p[0] == 't' && p[1] == '_')
8513 {
8514 p += 2;
8515 if (*p != NUL)
8516 ++p;
8517 if (*p == NUL)
8518 return; /* expand option name */
8519 nextchar = *++p;
8520 is_term_option = TRUE;
8521 expand_option_name[2] = p[-2];
8522 expand_option_name[3] = p[-1];
8523 }
8524 else
8525 {
8526 /* Allow * wildcard */
8527 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
8528 p++;
8529 if (*p == NUL)
8530 return;
8531 nextchar = *p;
8532 *p = NUL;
8533 opt_idx = findoption(arg);
8534 *p = nextchar;
8535 if (opt_idx == -1 || options[opt_idx].var == NULL)
8536 {
8537 xp->xp_context = EXPAND_NOTHING;
8538 return;
8539 }
8540 flags = options[opt_idx].flags;
8541 if (flags & P_BOOL)
8542 {
8543 xp->xp_context = EXPAND_NOTHING;
8544 return;
8545 }
8546 }
8547 }
8548 /* handle "-=" and "+=" */
8549 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
8550 {
8551 ++p;
8552 nextchar = '=';
8553 }
8554 if ((nextchar != '=' && nextchar != ':')
8555 || xp->xp_context == EXPAND_BOOL_SETTINGS)
8556 {
8557 xp->xp_context = EXPAND_UNSUCCESSFUL;
8558 return;
8559 }
8560 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
8561 {
8562 xp->xp_context = EXPAND_OLD_SETTING;
8563 if (is_term_option)
8564 expand_option_idx = -1;
8565 else
8566 expand_option_idx = opt_idx;
8567 xp->xp_pattern = p + 1;
8568 return;
8569 }
8570 xp->xp_context = EXPAND_NOTHING;
8571 if (is_term_option || (flags & P_NUM))
8572 return;
8573
8574 xp->xp_pattern = p + 1;
8575
8576 if (flags & P_EXPAND)
8577 {
8578 p = options[opt_idx].var;
8579 if (p == (char_u *)&p_bdir
8580 || p == (char_u *)&p_dir
8581 || p == (char_u *)&p_path
8582 || p == (char_u *)&p_rtp
8583#ifdef FEAT_SEARCHPATH
8584 || p == (char_u *)&p_cdpath
8585#endif
8586#ifdef FEAT_SESSION
8587 || p == (char_u *)&p_vdir
8588#endif
8589 )
8590 {
8591 xp->xp_context = EXPAND_DIRECTORIES;
8592 if (p == (char_u *)&p_path
8593#ifdef FEAT_SEARCHPATH
8594 || p == (char_u *)&p_cdpath
8595#endif
8596 )
8597 xp->xp_backslash = XP_BS_THREE;
8598 else
8599 xp->xp_backslash = XP_BS_ONE;
8600 }
8601 else
8602 {
8603 xp->xp_context = EXPAND_FILES;
8604 /* for 'tags' need three backslashes for a space */
8605 if (p == (char_u *)&p_tags)
8606 xp->xp_backslash = XP_BS_THREE;
8607 else
8608 xp->xp_backslash = XP_BS_ONE;
8609 }
8610 }
8611
8612 /* For an option that is a list of file names, find the start of the
8613 * last file name. */
8614 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
8615 {
8616 /* count number of backslashes before ' ' or ',' */
8617 if (*p == ' ' || *p == ',')
8618 {
8619 s = p;
8620 while (s > xp->xp_pattern && *(s - 1) == '\\')
8621 --s;
8622 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
8623 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
8624 {
8625 xp->xp_pattern = p + 1;
8626 break;
8627 }
8628 }
8629 }
8630
8631 return;
8632}
8633
8634 int
8635ExpandSettings(xp, regmatch, num_file, file)
8636 expand_T *xp;
8637 regmatch_T *regmatch;
8638 int *num_file;
8639 char_u ***file;
8640{
8641 int num_normal = 0; /* Nr of matching non-term-code settings */
8642 int num_term = 0; /* Nr of matching terminal code settings */
8643 int opt_idx;
8644 int match;
8645 int count = 0;
8646 char_u *str;
8647 int loop;
8648 int is_term_opt;
8649 char_u name_buf[MAX_KEY_NAME_LEN];
8650 static char *(names[]) = {"all", "termcap"};
8651 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
8652
8653 /* do this loop twice:
8654 * loop == 0: count the number of matching options
8655 * loop == 1: copy the matching options into allocated memory
8656 */
8657 for (loop = 0; loop <= 1; ++loop)
8658 {
8659 regmatch->rm_ic = ic;
8660 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
8661 {
8662 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
8663 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
8664 {
8665 if (loop == 0)
8666 num_normal++;
8667 else
8668 (*file)[count++] = vim_strsave((char_u *)names[match]);
8669 }
8670 }
8671 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
8672 opt_idx++)
8673 {
8674 if (options[opt_idx].var == NULL)
8675 continue;
8676 if (xp->xp_context == EXPAND_BOOL_SETTINGS
8677 && !(options[opt_idx].flags & P_BOOL))
8678 continue;
8679 is_term_opt = istermoption(&options[opt_idx]);
8680 if (is_term_opt && num_normal > 0)
8681 continue;
8682 match = FALSE;
8683 if (vim_regexec(regmatch, str, (colnr_T)0)
8684 || (options[opt_idx].shortname != NULL
8685 && vim_regexec(regmatch,
8686 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
8687 match = TRUE;
8688 else if (is_term_opt)
8689 {
8690 name_buf[0] = '<';
8691 name_buf[1] = 't';
8692 name_buf[2] = '_';
8693 name_buf[3] = str[2];
8694 name_buf[4] = str[3];
8695 name_buf[5] = '>';
8696 name_buf[6] = NUL;
8697 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8698 {
8699 match = TRUE;
8700 str = name_buf;
8701 }
8702 }
8703 if (match)
8704 {
8705 if (loop == 0)
8706 {
8707 if (is_term_opt)
8708 num_term++;
8709 else
8710 num_normal++;
8711 }
8712 else
8713 (*file)[count++] = vim_strsave(str);
8714 }
8715 }
8716 /*
8717 * Check terminal key codes, these are not in the option table
8718 */
8719 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
8720 {
8721 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
8722 {
8723 if (!isprint(str[0]) || !isprint(str[1]))
8724 continue;
8725
8726 name_buf[0] = 't';
8727 name_buf[1] = '_';
8728 name_buf[2] = str[0];
8729 name_buf[3] = str[1];
8730 name_buf[4] = NUL;
8731
8732 match = FALSE;
8733 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8734 match = TRUE;
8735 else
8736 {
8737 name_buf[0] = '<';
8738 name_buf[1] = 't';
8739 name_buf[2] = '_';
8740 name_buf[3] = str[0];
8741 name_buf[4] = str[1];
8742 name_buf[5] = '>';
8743 name_buf[6] = NUL;
8744
8745 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8746 match = TRUE;
8747 }
8748 if (match)
8749 {
8750 if (loop == 0)
8751 num_term++;
8752 else
8753 (*file)[count++] = vim_strsave(name_buf);
8754 }
8755 }
8756
8757 /*
8758 * Check special key names.
8759 */
8760 regmatch->rm_ic = TRUE; /* ignore case here */
8761 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
8762 {
8763 name_buf[0] = '<';
8764 STRCPY(name_buf + 1, str);
8765 STRCAT(name_buf, ">");
8766
8767 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8768 {
8769 if (loop == 0)
8770 num_term++;
8771 else
8772 (*file)[count++] = vim_strsave(name_buf);
8773 }
8774 }
8775 }
8776 if (loop == 0)
8777 {
8778 if (num_normal > 0)
8779 *num_file = num_normal;
8780 else if (num_term > 0)
8781 *num_file = num_term;
8782 else
8783 return OK;
8784 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
8785 if (*file == NULL)
8786 {
8787 *file = (char_u **)"";
8788 return FAIL;
8789 }
8790 }
8791 }
8792 return OK;
8793}
8794
8795 int
8796ExpandOldSetting(num_file, file)
8797 int *num_file;
8798 char_u ***file;
8799{
8800 char_u *var = NULL; /* init for GCC */
8801 char_u *buf;
8802
8803 *num_file = 0;
8804 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
8805 if (*file == NULL)
8806 return FAIL;
8807
8808 /*
8809 * For a terminal key code expand_option_idx is < 0.
8810 */
8811 if (expand_option_idx < 0)
8812 {
8813 var = find_termcode(expand_option_name + 2);
8814 if (var == NULL)
8815 expand_option_idx = findoption(expand_option_name);
8816 }
8817
8818 if (expand_option_idx >= 0)
8819 {
8820 /* put string of option value in NameBuff */
8821 option_value2string(&options[expand_option_idx], expand_option_flags);
8822 var = NameBuff;
8823 }
8824 else if (var == NULL)
8825 var = (char_u *)"";
8826
8827 /* A backslash is required before some characters. This is the reverse of
8828 * what happens in do_set(). */
8829 buf = vim_strsave_escaped(var, escape_chars);
8830
8831 if (buf == NULL)
8832 {
8833 vim_free(*file);
8834 *file = NULL;
8835 return FAIL;
8836 }
8837
8838#ifdef BACKSLASH_IN_FILENAME
8839 /* For MS-Windows et al. we don't double backslashes at the start and
8840 * before a file name character. */
8841 for (var = buf; *var != NUL; )
8842 {
8843 if (var[0] == '\\' && var[1] == '\\'
8844 && expand_option_idx >= 0
8845 && (options[expand_option_idx].flags & P_EXPAND)
8846 && vim_isfilec(var[2])
8847 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
8848 mch_memmove(var, var + 1, STRLEN(var));
8849#ifdef FEAT_MBYTE
8850 else if (has_mbyte)
8851 var += (*mb_ptr2len_check)(var) - 1;
8852#endif
8853 ++var;
8854 }
8855#endif
8856
8857 *file[0] = buf;
8858 *num_file = 1;
8859 return OK;
8860}
8861#endif
8862
8863/*
8864 * Get the value for the numeric or string option *opp in a nice format into
8865 * NameBuff[]. Must not be called with a hidden option!
8866 */
8867 static void
8868option_value2string(opp, opt_flags)
8869 struct vimoption *opp;
8870 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8871{
8872 char_u *varp;
8873
8874 varp = get_varp_scope(opp, opt_flags);
8875
8876 if (opp->flags & P_NUM)
8877 {
8878 long wc = 0;
8879
8880 if (wc_use_keyname(varp, &wc))
8881 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
8882 else if (wc != 0)
8883 STRCPY(NameBuff, transchar((int)wc));
8884 else
8885 sprintf((char *)NameBuff, "%ld", *(long *)varp);
8886 }
8887 else /* P_STRING */
8888 {
8889 varp = *(char_u **)(varp);
8890 if (varp == NULL) /* just in case */
8891 NameBuff[0] = NUL;
8892#ifdef FEAT_CRYPT
8893 /* don't show the actual value of 'key', only that it's set */
8894 if (opp->var == (char_u *)&p_key && *varp)
8895 STRCPY(NameBuff, "*****");
8896#endif
8897 else if (opp->flags & P_EXPAND)
8898 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
8899 /* Translate 'pastetoggle' into special key names */
8900 else if ((char_u **)opp->var == &p_pt)
8901 str2specialbuf(p_pt, NameBuff, MAXPATHL);
8902 else
8903 STRNCPY(NameBuff, varp, MAXPATHL);
8904 }
8905}
8906
8907/*
8908 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
8909 * printed as a keyname.
8910 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
8911 */
8912 static int
8913wc_use_keyname(varp, wcp)
8914 char_u *varp;
8915 long *wcp;
8916{
8917 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
8918 {
8919 *wcp = *(long *)varp;
8920 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
8921 return TRUE;
8922 }
8923 return FALSE;
8924}
8925
8926#ifdef FEAT_LANGMAP
8927/*
8928 * Any character has an equivalent character. This is used for keyboards that
8929 * have a special language mode that sends characters above 128 (although
8930 * other characters can be translated too).
8931 */
8932
8933/*
8934 * char_u langmap_mapchar[256];
8935 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
8936 * "translate" native lang chars in normal mode or some cases of
8937 * insert mode without having to tediously switch lang mode back&forth.
8938 */
8939
8940 static void
8941langmap_init()
8942{
8943 int i;
8944
8945 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
8946 langmap_mapchar[i] = i;
8947}
8948
8949/*
8950 * Called when langmap option is set; the language map can be
8951 * changed at any time!
8952 */
8953 static void
8954langmap_set()
8955{
8956 char_u *p;
8957 char_u *p2;
8958 int from, to;
8959
8960 langmap_init(); /* back to one-to-one map first */
8961
8962 for (p = p_langmap; p[0] != NUL; )
8963 {
8964 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; ++p2)
8965 {
8966 if (p2[0] == '\\' && p2[1] != NUL)
8967 ++p2;
8968#ifdef FEAT_MBYTE
8969 p2 += (*mb_ptr2len_check)(p2) - 1;
8970#endif
8971 }
8972 if (p2[0] == ';')
8973 ++p2; /* abcd;ABCD form, p2 points to A */
8974 else
8975 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
8976 while (p[0])
8977 {
8978 if (p[0] == '\\' && p[1] != NUL)
8979 ++p;
8980#ifdef FEAT_MBYTE
8981 from = (*mb_ptr2char)(p);
8982#else
8983 from = p[0];
8984#endif
8985 if (p2 == NULL)
8986 {
8987#ifdef FEAT_MBYTE
8988 p += (*mb_ptr2len_check)(p);
8989#else
8990 ++p;
8991#endif
8992 if (p[0] == '\\')
8993 ++p;
8994#ifdef FEAT_MBYTE
8995 to = (*mb_ptr2char)(p);
8996#else
8997 to = p[0];
8998#endif
8999 }
9000 else
9001 {
9002 if (p2[0] == '\\')
9003 ++p2;
9004#ifdef FEAT_MBYTE
9005 to = (*mb_ptr2char)(p2);
9006#else
9007 to = p2[0];
9008#endif
9009 }
9010 if (to == NUL)
9011 {
9012 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9013 transchar(from));
9014 return;
9015 }
9016 langmap_mapchar[from & 255] = to;
9017
9018 /* Advance to next pair */
9019#ifdef FEAT_MBYTE
9020 p += (*mb_ptr2len_check)(p);
9021#else
9022 ++p;
9023#endif
9024 if (p2 == NULL)
9025 {
9026 if (p[0] == ',')
9027 {
9028 ++p;
9029 break;
9030 }
9031 }
9032 else
9033 {
9034#ifdef FEAT_MBYTE
9035 p2 += (*mb_ptr2len_check)(p2);
9036#else
9037 ++p2;
9038#endif
9039 if (*p == ';')
9040 {
9041 p = p2;
9042 if (p[0] != NUL)
9043 {
9044 if (p[0] != ',')
9045 {
9046 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9047 return;
9048 }
9049 ++p;
9050 }
9051 break;
9052 }
9053 }
9054 }
9055 }
9056}
9057#endif
9058
9059/*
9060 * Return TRUE if format option 'x' is in effect.
9061 * Take care of no formatting when 'paste' is set.
9062 */
9063 int
9064has_format_option(x)
9065 int x;
9066{
9067 if (p_paste)
9068 return FALSE;
9069 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9070}
9071
9072/*
9073 * Return TRUE if "x" is present in 'shortmess' option, or
9074 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9075 */
9076 int
9077shortmess(x)
9078 int x;
9079{
9080 return ( vim_strchr(p_shm, x) != NULL
9081 || (vim_strchr(p_shm, 'a') != NULL
9082 && vim_strchr((char_u *)SHM_A, x) != NULL));
9083}
9084
9085/*
9086 * paste_option_changed() - Called after p_paste was set or reset.
9087 */
9088 static void
9089paste_option_changed()
9090{
9091 static int old_p_paste = FALSE;
9092 static int save_sm = 0;
9093#ifdef FEAT_CMDL_INFO
9094 static int save_ru = 0;
9095#endif
9096#ifdef FEAT_RIGHTLEFT
9097 static int save_ri = 0;
9098 static int save_hkmap = 0;
9099#endif
9100 buf_T *buf;
9101
9102 if (p_paste)
9103 {
9104 /*
9105 * Paste switched from off to on.
9106 * Save the current values, so they can be restored later.
9107 */
9108 if (!old_p_paste)
9109 {
9110 /* save options for each buffer */
9111 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9112 {
9113 buf->b_p_tw_nopaste = buf->b_p_tw;
9114 buf->b_p_wm_nopaste = buf->b_p_wm;
9115 buf->b_p_sts_nopaste = buf->b_p_sts;
9116 buf->b_p_ai_nopaste = buf->b_p_ai;
9117 }
9118
9119 /* save global options */
9120 save_sm = p_sm;
9121#ifdef FEAT_CMDL_INFO
9122 save_ru = p_ru;
9123#endif
9124#ifdef FEAT_RIGHTLEFT
9125 save_ri = p_ri;
9126 save_hkmap = p_hkmap;
9127#endif
9128 /* save global values for local buffer options */
9129 p_tw_nopaste = p_tw;
9130 p_wm_nopaste = p_wm;
9131 p_sts_nopaste = p_sts;
9132 p_ai_nopaste = p_ai;
9133 }
9134
9135 /*
9136 * Always set the option values, also when 'paste' is set when it is
9137 * already on.
9138 */
9139 /* set options for each buffer */
9140 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9141 {
9142 buf->b_p_tw = 0; /* textwidth is 0 */
9143 buf->b_p_wm = 0; /* wrapmargin is 0 */
9144 buf->b_p_sts = 0; /* softtabstop is 0 */
9145 buf->b_p_ai = 0; /* no auto-indent */
9146 }
9147
9148 /* set global options */
9149 p_sm = 0; /* no showmatch */
9150#ifdef FEAT_CMDL_INFO
9151# ifdef FEAT_WINDOWS
9152 if (p_ru)
9153 status_redraw_all(); /* redraw to remove the ruler */
9154# endif
9155 p_ru = 0; /* no ruler */
9156#endif
9157#ifdef FEAT_RIGHTLEFT
9158 p_ri = 0; /* no reverse insert */
9159 p_hkmap = 0; /* no Hebrew keyboard */
9160#endif
9161 /* set global values for local buffer options */
9162 p_tw = 0;
9163 p_wm = 0;
9164 p_sts = 0;
9165 p_ai = 0;
9166 }
9167
9168 /*
9169 * Paste switched from on to off: Restore saved values.
9170 */
9171 else if (old_p_paste)
9172 {
9173 /* restore options for each buffer */
9174 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9175 {
9176 buf->b_p_tw = buf->b_p_tw_nopaste;
9177 buf->b_p_wm = buf->b_p_wm_nopaste;
9178 buf->b_p_sts = buf->b_p_sts_nopaste;
9179 buf->b_p_ai = buf->b_p_ai_nopaste;
9180 }
9181
9182 /* restore global options */
9183 p_sm = save_sm;
9184#ifdef FEAT_CMDL_INFO
9185# ifdef FEAT_WINDOWS
9186 if (p_ru != save_ru)
9187 status_redraw_all(); /* redraw to draw the ruler */
9188# endif
9189 p_ru = save_ru;
9190#endif
9191#ifdef FEAT_RIGHTLEFT
9192 p_ri = save_ri;
9193 p_hkmap = save_hkmap;
9194#endif
9195 /* set global values for local buffer options */
9196 p_tw = p_tw_nopaste;
9197 p_wm = p_wm_nopaste;
9198 p_sts = p_sts_nopaste;
9199 p_ai = p_ai_nopaste;
9200 }
9201
9202 old_p_paste = p_paste;
9203}
9204
9205/*
9206 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9207 *
9208 * Reset 'compatible' and set the values for options that didn't get set yet
9209 * to the Vim defaults.
9210 * Don't do this if the 'compatible' option has been set or reset before.
9211 */
9212 void
9213vimrc_found()
9214{
9215 int opt_idx;
9216
9217 if (!option_was_set((char_u *)"cp"))
9218 {
9219 p_cp = FALSE;
9220 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9221 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9222 set_option_default(opt_idx, OPT_FREE, FALSE);
9223 didset_options();
9224 }
9225}
9226
9227/*
9228 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9229 */
9230 void
9231change_compatible(on)
9232 int on;
9233{
9234 if (p_cp != on)
9235 {
9236 p_cp = on;
9237 compatible_set();
9238 }
9239 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9240}
9241
9242/*
9243 * Return TRUE when option "name" has been set.
9244 */
9245 int
9246option_was_set(name)
9247 char_u *name;
9248{
9249 int idx;
9250
9251 idx = findoption(name);
9252 if (idx < 0) /* unknown option */
9253 return FALSE;
9254 if (options[idx].flags & P_WAS_SET)
9255 return TRUE;
9256 return FALSE;
9257}
9258
9259/*
9260 * compatible_set() - Called when 'compatible' has been set or unset.
9261 *
9262 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9263 * flag) to a Vi compatible value.
9264 * When 'compatible' is unset: Set all options that have a different default
9265 * for Vim (without the P_VI_DEF flag) to that default.
9266 */
9267 static void
9268compatible_set()
9269{
9270 int opt_idx;
9271
9272 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9273 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9274 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9275 set_option_default(opt_idx, OPT_FREE, p_cp);
9276 didset_options();
9277}
9278
9279#ifdef FEAT_LINEBREAK
9280
9281# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9282 /* Borland C++ screws up loop optimisation here (negri) */
9283# pragma option -O-l
9284# endif
9285
9286/*
9287 * fill_breakat_flags() -- called when 'breakat' changes value.
9288 */
9289 static void
9290fill_breakat_flags()
9291{
9292 char_u *c;
9293 int i;
9294
9295 for (i = 0; i < 256; i++)
9296 breakat_flags[i] = FALSE;
9297
9298 if (p_breakat != NULL)
9299 for (c = p_breakat; *c; c++)
9300 breakat_flags[*c] = TRUE;
9301}
9302
9303# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9304# pragma option -O.l
9305# endif
9306
9307#endif
9308
9309/*
9310 * Check an option that can be a range of string values.
9311 *
9312 * Return OK for correct value, FAIL otherwise.
9313 * Empty is always OK.
9314 */
9315 static int
9316check_opt_strings(val, values, list)
9317 char_u *val;
9318 char **values;
9319 int list; /* when TRUE: accept a list of values */
9320{
9321 return opt_strings_flags(val, values, NULL, list);
9322}
9323
9324/*
9325 * Handle an option that can be a range of string values.
9326 * Set a flag in "*flagp" for each string present.
9327 *
9328 * Return OK for correct value, FAIL otherwise.
9329 * Empty is always OK.
9330 */
9331 static int
9332opt_strings_flags(val, values, flagp, list)
9333 char_u *val; /* new value */
9334 char **values; /* array of valid string values */
9335 unsigned *flagp;
9336 int list; /* when TRUE: accept a list of values */
9337{
9338 int i;
9339 int len;
9340 unsigned new_flags = 0;
9341
9342 while (*val)
9343 {
9344 for (i = 0; ; ++i)
9345 {
9346 if (values[i] == NULL) /* val not found in values[] */
9347 return FAIL;
9348
9349 len = (int)STRLEN(values[i]);
9350 if (STRNCMP(values[i], val, len) == 0
9351 && ((list && val[len] == ',') || val[len] == NUL))
9352 {
9353 val += len + (val[len] == ',');
9354 new_flags |= (1 << i);
9355 break; /* check next item in val list */
9356 }
9357 }
9358 }
9359 if (flagp != NULL)
9360 *flagp = new_flags;
9361
9362 return OK;
9363}
9364
9365/*
9366 * Read the 'wildmode' option, fill wim_flags[].
9367 */
9368 static int
9369check_opt_wim()
9370{
9371 char_u new_wim_flags[4];
9372 char_u *p;
9373 int i;
9374 int idx = 0;
9375
9376 for (i = 0; i < 4; ++i)
9377 new_wim_flags[i] = 0;
9378
9379 for (p = p_wim; *p; ++p)
9380 {
9381 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9382 ;
9383 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9384 return FAIL;
9385 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9386 new_wim_flags[idx] |= WIM_LONGEST;
9387 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9388 new_wim_flags[idx] |= WIM_FULL;
9389 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9390 new_wim_flags[idx] |= WIM_LIST;
9391 else
9392 return FAIL;
9393 p += i;
9394 if (*p == NUL)
9395 break;
9396 if (*p == ',')
9397 {
9398 if (idx == 3)
9399 return FAIL;
9400 ++idx;
9401 }
9402 }
9403
9404 /* fill remaining entries with last flag */
9405 while (idx < 3)
9406 {
9407 new_wim_flags[idx + 1] = new_wim_flags[idx];
9408 ++idx;
9409 }
9410
9411 /* only when there are no errors, wim_flags[] is changed */
9412 for (i = 0; i < 4; ++i)
9413 wim_flags[i] = new_wim_flags[i];
9414 return OK;
9415}
9416
9417/*
9418 * Check if backspacing over something is allowed.
9419 */
9420 int
9421can_bs(what)
9422 int what; /* BS_INDENT, BS_EOL or BS_START */
9423{
9424 switch (*p_bs)
9425 {
9426 case '2': return TRUE;
9427 case '1': return (what != BS_START);
9428 case '0': return FALSE;
9429 }
9430 return vim_strchr(p_bs, what) != NULL;
9431}
9432
9433/*
9434 * Save the current values of 'fileformat' and 'fileencoding', so that we know
9435 * the file must be considered changed when the value is different.
9436 */
9437 void
9438save_file_ff(buf)
9439 buf_T *buf;
9440{
9441 buf->b_start_ffc = *buf->b_p_ff;
9442 buf->b_start_eol = buf->b_p_eol;
9443#ifdef FEAT_MBYTE
9444 /* Only use free/alloc when necessary, they take time. */
9445 if (buf->b_start_fenc == NULL
9446 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9447 {
9448 vim_free(buf->b_start_fenc);
9449 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9450 }
9451#endif
9452}
9453
9454/*
9455 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9456 * from when editing started (save_file_ff() called).
9457 * Also when 'endofline' was changed and 'binary' is set.
9458 * Don't consider a new, empty buffer to be changed.
9459 */
9460 int
9461file_ff_differs(buf)
9462 buf_T *buf;
9463{
9464 if ((buf->b_flags & BF_NEW)
9465 && buf->b_ml.ml_line_count == 1
9466 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
9467 return FALSE;
9468 if (buf->b_start_ffc != *buf->b_p_ff)
9469 return TRUE;
9470 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
9471 return TRUE;
9472#ifdef FEAT_MBYTE
9473 if (buf->b_start_fenc == NULL)
9474 return (*buf->b_p_fenc != NUL);
9475 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
9476#else
9477 return FALSE;
9478#endif
9479}
9480
9481/*
9482 * return OK if "p" is a valid fileformat name, FAIL otherwise.
9483 */
9484 int
9485check_ff_value(p)
9486 char_u *p;
9487{
9488 return check_opt_strings(p, p_ff_values, FALSE);
9489}