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