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