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