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