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