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