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