blob: 1b724dca4698b504b106c5816c5f5f23b39792ae [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 Moolenaar843ee412004-06-30 16:16:41 +00001078#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_KDE)
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 Moolenaar843ee412004-06-30 16:16:41 +00001085#if defined(FEAT_GUI) || defined(FEAT_GUI_KDE)
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 Moolenaar843ee412004-06-30 16:16:41 +00001171#if defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE))
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}},
1627 {"optimize", "opt", P_BOOL|P_VI_DEF,
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)FALSE, (char_u *)0L}},
1630 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1631#ifdef FEAT_OSFILETYPE
1632 (char_u *)&p_oft, PV_OFT,
1633 {(char_u *)DFLT_OFT, (char_u *)0L}
1634#else
1635 (char_u *)NULL, PV_NONE,
1636 {(char_u *)0L, (char_u *)0L}
1637#endif
1638 },
1639 {"paragraphs", "para", P_STRING|P_VI_DEF,
1640 (char_u *)&p_para, PV_NONE,
1641 {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}},
1642 {"paste", NULL, P_BOOL|P_VI_DEF,
1643 (char_u *)&p_paste, PV_NONE,
1644 {(char_u *)FALSE, (char_u *)0L}},
1645 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1646 (char_u *)&p_pt, PV_NONE,
1647 {(char_u *)"", (char_u *)0L}},
1648 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1649#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1650 (char_u *)&p_pex, PV_NONE,
1651 {(char_u *)"", (char_u *)0L}
1652#else
1653 (char_u *)NULL, PV_NONE,
1654 {(char_u *)0L, (char_u *)0L}
1655#endif
1656 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001657 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 (char_u *)&p_pm, PV_NONE,
1659 {(char_u *)"", (char_u *)0L}},
1660 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
1661 (char_u *)&p_path, OPT_BOTH(PV_PATH),
1662 {
1663#if defined AMIGA || defined MSDOS || defined MSWIN
1664 (char_u *)".,,",
1665#else
1666# if defined(__EMX__)
1667 (char_u *)".,/emx/include,,",
1668# else /* Unix, probably */
1669 (char_u *)".,/usr/include,,",
1670# endif
1671#endif
1672 (char_u *)0L}},
1673 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1674 (char_u *)&p_pi, PV_PI,
1675 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001676 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1678 (char_u *)&p_pvh, PV_NONE,
1679#else
1680 (char_u *)NULL, PV_NONE,
1681#endif
1682 {(char_u *)12L, (char_u *)0L}},
1683 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1684#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1685 (char_u *)VAR_WIN, PV_PVW,
1686#else
1687 (char_u *)NULL, PV_NONE,
1688#endif
1689 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001690 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691#ifdef FEAT_PRINTER
1692 (char_u *)&p_pdev, PV_NONE,
1693 {(char_u *)"", (char_u *)0L}
1694#else
1695 (char_u *)NULL, PV_NONE,
1696 {(char_u *)NULL, (char_u *)0L}
1697#endif
1698 },
1699 {"printencoding", "penc", P_STRING|P_VI_DEF,
1700#ifdef FEAT_POSTSCRIPT
1701 (char_u *)&p_penc, PV_NONE,
1702 {(char_u *)"", (char_u *)0L}
1703#else
1704 (char_u *)NULL, PV_NONE,
1705 {(char_u *)NULL, (char_u *)0L}
1706#endif
1707 },
1708 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1709#ifdef FEAT_POSTSCRIPT
1710 (char_u *)&p_pexpr, PV_NONE,
1711 {(char_u *)"", (char_u *)0L}
1712#else
1713 (char_u *)NULL, PV_NONE,
1714 {(char_u *)NULL, (char_u *)0L}
1715#endif
1716 },
1717 {"printfont", "pfn", P_STRING|P_VI_DEF,
1718#ifdef FEAT_PRINTER
1719 (char_u *)&p_pfn, PV_NONE,
1720 {
1721# ifdef MSWIN
1722 (char_u *)"Courier_New:h10",
1723# else
1724 (char_u *)"courier",
1725# endif
1726 (char_u *)0L}
1727#else
1728 (char_u *)NULL, PV_NONE,
1729 {(char_u *)NULL, (char_u *)0L}
1730#endif
1731 },
1732 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1733#ifdef FEAT_PRINTER
1734 (char_u *)&p_header, PV_NONE,
1735 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1736#else
1737 (char_u *)NULL, PV_NONE,
1738 {(char_u *)NULL, (char_u *)0L}
1739#endif
1740 },
Bram Moolenaar8299df92004-07-10 09:47:34 +00001741 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1742#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1743 (char_u *)&p_pmcs, PV_NONE,
1744 {(char_u *)"", (char_u *)0L}
1745#else
1746 (char_u *)NULL, PV_NONE,
1747 {(char_u *)NULL, (char_u *)0L}
1748#endif
1749 },
1750 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1751#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1752 (char_u *)&p_pmfn, PV_NONE,
1753 {(char_u *)"", (char_u *)0L}
1754#else
1755 (char_u *)NULL, PV_NONE,
1756 {(char_u *)NULL, (char_u *)0L}
1757#endif
1758 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1760#ifdef FEAT_PRINTER
1761 (char_u *)&p_popt, PV_NONE,
1762 {(char_u *)"", (char_u *)0L}
1763#else
1764 (char_u *)NULL, PV_NONE,
1765 {(char_u *)NULL, (char_u *)0L}
1766#endif
1767 },
1768 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001769 (char_u *)&p_prompt, PV_NONE,
1770 {(char_u *)TRUE, (char_u *)0L}},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001771 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
1772#ifdef FEAT_TEXTOBJ
1773 (char_u *)&p_qe, PV_QE,
1774 {(char_u *)"\\", (char_u *)0L}
1775#else
1776 (char_u *)NULL, PV_NONE,
1777 {(char_u *)NULL, (char_u *)0L}
1778#endif
1779 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1781 (char_u *)&p_ro, PV_RO,
1782 {(char_u *)FALSE, (char_u *)0L}},
1783 {"redraw", NULL, P_BOOL|P_VI_DEF,
1784 (char_u *)NULL, PV_NONE,
1785 {(char_u *)FALSE, (char_u *)0L}},
1786 {"remap", NULL, P_BOOL|P_VI_DEF,
1787 (char_u *)&p_remap, PV_NONE,
1788 {(char_u *)TRUE, (char_u *)0L}},
1789 {"report", NULL, P_NUM|P_VI_DEF,
1790 (char_u *)&p_report, PV_NONE,
1791 {(char_u *)2L, (char_u *)0L}},
1792 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
1793#ifdef WIN3264
1794 (char_u *)&p_rs, PV_NONE,
1795#else
1796 (char_u *)NULL, PV_NONE,
1797#endif
1798 {(char_u *)TRUE, (char_u *)0L}},
1799 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
1800#ifdef FEAT_RIGHTLEFT
1801 (char_u *)&p_ri, PV_NONE,
1802#else
1803 (char_u *)NULL, PV_NONE,
1804#endif
1805 {(char_u *)FALSE, (char_u *)0L}},
1806 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
1807#ifdef FEAT_RIGHTLEFT
1808 (char_u *)VAR_WIN, PV_RL,
1809#else
1810 (char_u *)NULL, PV_NONE,
1811#endif
1812 {(char_u *)FALSE, (char_u *)0L}},
1813 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
1814#ifdef FEAT_RIGHTLEFT
1815 (char_u *)VAR_WIN, PV_RLC,
1816 {(char_u *)"search", (char_u *)NULL}
1817#else
1818 (char_u *)NULL, PV_NONE,
1819 {(char_u *)NULL, (char_u *)0L}
1820#endif
1821 },
1822 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
1823#ifdef FEAT_CMDL_INFO
1824 (char_u *)&p_ru, PV_NONE,
1825#else
1826 (char_u *)NULL, PV_NONE,
1827#endif
1828 {(char_u *)FALSE, (char_u *)0L}},
1829 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
1830#ifdef FEAT_STL_OPT
1831 (char_u *)&p_ruf, PV_NONE,
1832#else
1833 (char_u *)NULL, PV_NONE,
1834#endif
1835 {(char_u *)"", (char_u *)0L}},
1836 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
1837 (char_u *)&p_rtp, PV_NONE,
1838 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
1839 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
1840 (char_u *)VAR_WIN, PV_SCROLL,
1841 {(char_u *)12L, (char_u *)0L}},
1842 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
1843#ifdef FEAT_SCROLLBIND
1844 (char_u *)VAR_WIN, PV_SCBIND,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
1848 {(char_u *)FALSE, (char_u *)0L}},
1849 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
1850 (char_u *)&p_sj, PV_NONE,
1851 {(char_u *)1L, (char_u *)0L}},
1852 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
1853 (char_u *)&p_so, PV_NONE,
1854 {(char_u *)0L, (char_u *)0L}},
1855 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1856#ifdef FEAT_SCROLLBIND
1857 (char_u *)&p_sbo, PV_NONE,
1858 {(char_u *)"ver,jump", (char_u *)0L}
1859#else
1860 (char_u *)NULL, PV_NONE,
1861 {(char_u *)0L, (char_u *)0L}
1862#endif
1863 },
1864 {"sections", "sect", P_STRING|P_VI_DEF,
1865 (char_u *)&p_sections, PV_NONE,
1866 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
1867 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
1868 (char_u *)&p_secure, PV_NONE,
1869 {(char_u *)FALSE, (char_u *)0L}},
1870 {"selection", "sel", P_STRING|P_VI_DEF,
1871#ifdef FEAT_VISUAL
1872 (char_u *)&p_sel, PV_NONE,
1873#else
1874 (char_u *)NULL, PV_NONE,
1875#endif
1876 {(char_u *)"inclusive", (char_u *)0L}},
1877 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1878#ifdef FEAT_VISUAL
1879 (char_u *)&p_slm, PV_NONE,
1880#else
1881 (char_u *)NULL, PV_NONE,
1882#endif
1883 {(char_u *)"", (char_u *)0L}},
1884 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1885#ifdef FEAT_SESSION
1886 (char_u *)&p_ssop, PV_NONE,
1887 {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
1888 (char_u *)0L}
1889#else
1890 (char_u *)NULL, PV_NONE,
1891 {(char_u *)0L, (char_u *)0L}
1892#endif
1893 },
1894 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1895 (char_u *)&p_sh, PV_NONE,
1896 {
1897#ifdef VMS
1898 (char_u *)"-",
1899#else
1900# if defined(MSDOS)
1901 (char_u *)"command",
1902# else
1903# if defined(WIN16)
1904 (char_u *)"command.com",
1905# else
1906# if defined(WIN3264)
1907 (char_u *)"", /* set in set_init_1() */
1908# else
1909# if defined(OS2)
1910 (char_u *)"cmd.exe",
1911# else
1912# if defined(ARCHIE)
1913 (char_u *)"gos",
1914# else
1915 (char_u *)"sh",
1916# endif
1917# endif
1918# endif
1919# endif
1920# endif
1921#endif /* VMS */
1922 (char_u *)0L}},
1923 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
1924 (char_u *)&p_shcf, PV_NONE,
1925 {
1926#if defined(MSDOS) || defined(MSWIN)
1927 (char_u *)"/c",
1928#else
1929# if defined(OS2)
1930 (char_u *)"/c",
1931# else
1932 (char_u *)"-c",
1933# endif
1934#endif
1935 (char_u *)0L}},
1936 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
1937#ifdef FEAT_QUICKFIX
1938 (char_u *)&p_sp, PV_NONE,
1939 {
1940#if defined(UNIX) || defined(OS2)
1941# ifdef ARCHIE
1942 (char_u *)"2>",
1943# else
1944 (char_u *)"| tee",
1945# endif
1946#else
1947 (char_u *)">",
1948#endif
1949 (char_u *)0L}
1950#else
1951 (char_u *)NULL, PV_NONE,
1952 {(char_u *)0L, (char_u *)0L}
1953#endif
1954 },
1955 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
1956 (char_u *)&p_shq, PV_NONE,
1957 {(char_u *)"", (char_u *)0L}},
1958 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
1959 (char_u *)&p_srr, PV_NONE,
1960 {(char_u *)">", (char_u *)0L}},
1961 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
1962#ifdef BACKSLASH_IN_FILENAME
1963 (char_u *)&p_ssl, PV_NONE,
1964#else
1965 (char_u *)NULL, PV_NONE,
1966#endif
1967 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00001968 {"shelltemp", "stmp", P_BOOL,
1969 (char_u *)&p_stmp, PV_NONE,
1970 {(char_u *)FALSE, (char_u *)TRUE}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"shelltype", "st", P_NUM|P_VI_DEF,
1972#ifdef AMIGA
1973 (char_u *)&p_st, PV_NONE,
1974#else
1975 (char_u *)NULL, PV_NONE,
1976#endif
1977 {(char_u *)0L, (char_u *)0L}},
1978 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
1979 (char_u *)&p_sxq, PV_NONE,
1980 {
1981#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
1982 (char_u *)"\"",
1983#else
1984 (char_u *)"",
1985#endif
1986 (char_u *)0L}},
1987 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
1988 (char_u *)&p_sr, PV_NONE,
1989 {(char_u *)FALSE, (char_u *)0L}},
1990 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
1991 (char_u *)&p_sw, PV_SW,
1992 {(char_u *)8L, (char_u *)0L}},
1993 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
1994 (char_u *)&p_shm, PV_NONE,
1995 {(char_u *)"", (char_u *)"filnxtToO"}},
1996 {"shortname", "sn", P_BOOL|P_VI_DEF,
1997#ifdef SHORT_FNAME
1998 (char_u *)NULL, PV_NONE,
1999#else
2000 (char_u *)&p_sn, PV_SN,
2001#endif
2002 {(char_u *)FALSE, (char_u *)0L}},
2003 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2004#ifdef FEAT_LINEBREAK
2005 (char_u *)&p_sbr, PV_NONE,
2006#else
2007 (char_u *)NULL, PV_NONE,
2008#endif
2009 {(char_u *)"", (char_u *)0L}},
2010 {"showcmd", "sc", P_BOOL|P_VIM,
2011#ifdef FEAT_CMDL_INFO
2012 (char_u *)&p_sc, PV_NONE,
2013#else
2014 (char_u *)NULL, PV_NONE,
2015#endif
2016 {(char_u *)FALSE,
2017#ifdef UNIX
2018 (char_u *)FALSE
2019#else
2020 (char_u *)TRUE
2021#endif
2022 }},
2023 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2024 (char_u *)&p_sft, PV_NONE,
2025 {(char_u *)FALSE, (char_u *)0L}},
2026 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2027 (char_u *)&p_sm, PV_NONE,
2028 {(char_u *)FALSE, (char_u *)0L}},
2029 {"showmode", "smd", P_BOOL|P_VIM,
2030 (char_u *)&p_smd, PV_NONE,
2031 {(char_u *)FALSE, (char_u *)TRUE}},
2032 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2033 (char_u *)&p_ss, PV_NONE,
2034 {(char_u *)0L, (char_u *)0L}},
2035 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2036 (char_u *)&p_siso, PV_NONE,
2037 {(char_u *)0L, (char_u *)0L}},
2038 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2039 (char_u *)NULL, PV_NONE,
2040 {(char_u *)FALSE, (char_u *)0L}},
2041 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2042 (char_u *)&p_scs, PV_NONE,
2043 {(char_u *)FALSE, (char_u *)0L}},
2044 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2045#ifdef FEAT_SMARTINDENT
2046 (char_u *)&p_si, PV_SI,
2047#else
2048 (char_u *)NULL, PV_NONE,
2049#endif
2050 {(char_u *)FALSE, (char_u *)0L}},
2051 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2052 (char_u *)&p_sta, PV_NONE,
2053 {(char_u *)FALSE, (char_u *)0L}},
2054 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2055 (char_u *)&p_sts, PV_STS,
2056 {(char_u *)0L, (char_u *)0L}},
2057 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2058 (char_u *)NULL, PV_NONE,
2059 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002060 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2061#ifdef FEAT_SYN_HL
2062 (char_u *)VAR_WIN, PV_SPELL,
2063#else
2064 (char_u *)NULL, PV_NONE,
2065#endif
2066 {(char_u *)FALSE, (char_u *)0L}},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002067 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002068#ifdef FEAT_SYN_HL
2069 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002070 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002071#else
2072 (char_u *)NULL, PV_NONE,
2073 {(char_u *)0L, (char_u *)0L}
2074#endif
2075 },
2076 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002077#ifdef FEAT_SYN_HL
2078 (char_u *)&p_spf, PV_SPF,
2079 {(char_u *)"", (char_u *)0L}
2080#else
2081 (char_u *)NULL, PV_NONE,
2082 {(char_u *)0L, (char_u *)0L}
2083#endif
2084 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002085 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaar217ad922005-03-20 22:37:15 +00002086#ifdef FEAT_SYN_HL
2087 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002088 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002089#else
2090 (char_u *)NULL, PV_NONE,
2091 {(char_u *)0L, (char_u *)0L}
2092#endif
2093 },
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002094 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002095#ifdef FEAT_SYN_HL
2096 (char_u *)&p_sps, PV_NONE,
2097 {(char_u *)"best", (char_u *)0L}
2098#else
2099 (char_u *)NULL, PV_NONE,
2100 {(char_u *)0L, (char_u *)0L}
2101#endif
2102 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2104#ifdef FEAT_WINDOWS
2105 (char_u *)&p_sb, PV_NONE,
2106#else
2107 (char_u *)NULL, PV_NONE,
2108#endif
2109 {(char_u *)FALSE, (char_u *)0L}},
2110 {"splitright", "spr", P_BOOL|P_VI_DEF,
2111#ifdef FEAT_VERTSPLIT
2112 (char_u *)&p_spr, PV_NONE,
2113#else
2114 (char_u *)NULL, PV_NONE,
2115#endif
2116 {(char_u *)FALSE, (char_u *)0L}},
2117 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2118 (char_u *)&p_sol, PV_NONE,
2119 {(char_u *)TRUE, (char_u *)0L}},
2120 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2121#ifdef FEAT_STL_OPT
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002122 (char_u *)&p_stl, OPT_BOTH(PV_STL),
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123#else
2124 (char_u *)NULL, PV_NONE,
2125#endif
2126 {(char_u *)"", (char_u *)0L}},
2127 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2128 (char_u *)&p_su, PV_NONE,
2129 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2130 (char_u *)0L}},
2131 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
2132#if defined(FEAT_SEARCHPATH)
2133 (char_u *)&p_sua, PV_SUA,
2134 {(char_u *)"", (char_u *)0L}
2135#else
2136 (char_u *)NULL, PV_NONE,
2137 {(char_u *)0L, (char_u *)0L}
2138#endif
2139 },
2140 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2141 (char_u *)&p_swf, PV_SWF,
2142 {(char_u *)TRUE, (char_u *)0L}},
2143 {"swapsync", "sws", P_STRING|P_VI_DEF,
2144 (char_u *)&p_sws, PV_NONE,
2145 {(char_u *)"fsync", (char_u *)0L}},
2146 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2147 (char_u *)&p_swb, PV_NONE,
2148 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002149 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2150#ifdef FEAT_SYN_HL
2151 (char_u *)&p_smc, PV_SMC,
2152 {(char_u *)3000L, (char_u *)0L}
2153#else
2154 (char_u *)NULL, PV_NONE,
2155 {(char_u *)0L, (char_u *)0L}
2156#endif
2157 },
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002158 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159#ifdef FEAT_SYN_HL
2160 (char_u *)&p_syn, PV_SYN,
2161 {(char_u *)"", (char_u *)0L}
2162#else
2163 (char_u *)NULL, PV_NONE,
2164 {(char_u *)0L, (char_u *)0L}
2165#endif
2166 },
2167 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2168 (char_u *)&p_ts, PV_TS,
2169 {(char_u *)8L, (char_u *)0L}},
2170 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2171 (char_u *)&p_tbs, PV_NONE,
2172#ifdef VMS /* binary searching doesn't appear to work on VMS */
2173 {(char_u *)0L, (char_u *)0L}
2174#else
2175 {(char_u *)TRUE, (char_u *)0L}
2176#endif
2177 },
2178 {"taglength", "tl", P_NUM|P_VI_DEF,
2179 (char_u *)&p_tl, PV_NONE,
2180 {(char_u *)0L, (char_u *)0L}},
2181 {"tagrelative", "tr", P_BOOL|P_VIM,
2182 (char_u *)&p_tr, PV_NONE,
2183 {(char_u *)FALSE, (char_u *)TRUE}},
2184 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2185 (char_u *)&p_tags, OPT_BOTH(PV_TAGS),
2186 {
2187#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2188 (char_u *)"./tags,./TAGS,tags,TAGS",
2189#else
2190 (char_u *)"./tags,tags",
2191#endif
2192 (char_u *)0L}},
2193 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2194 (char_u *)&p_tgst, PV_NONE,
2195 {(char_u *)TRUE, (char_u *)0L}},
2196 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2197 (char_u *)&T_NAME, PV_NONE,
2198 {(char_u *)"", (char_u *)0L}},
2199 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2200#ifdef FEAT_ARABIC
2201 (char_u *)&p_tbidi, PV_NONE,
2202#else
2203 (char_u *)NULL, PV_NONE,
2204#endif
2205 {(char_u *)FALSE, (char_u *)0L}},
2206 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2207#ifdef FEAT_MBYTE
2208 (char_u *)&p_tenc, PV_NONE,
2209 {(char_u *)"", (char_u *)0L}
2210#else
2211 (char_u *)NULL, PV_NONE,
2212 {(char_u *)0L, (char_u *)0L}
2213#endif
2214 },
2215 {"terse", NULL, P_BOOL|P_VI_DEF,
2216 (char_u *)&p_terse, PV_NONE,
2217 {(char_u *)FALSE, (char_u *)0L}},
2218 {"textauto", "ta", P_BOOL|P_VIM,
2219 (char_u *)&p_ta, PV_NONE,
2220 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2221 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2222 (char_u *)&p_tx, PV_TX,
2223 {
2224#ifdef USE_CRNL
2225 (char_u *)TRUE,
2226#else
2227 (char_u *)FALSE,
2228#endif
2229 (char_u *)0L}},
2230 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2231 (char_u *)&p_tw, PV_TW,
2232 {(char_u *)0L, (char_u *)0L}},
2233 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2234#ifdef FEAT_INS_EXPAND
2235 (char_u *)&p_tsr, OPT_BOTH(PV_TSR),
2236#else
2237 (char_u *)NULL, PV_NONE,
2238#endif
2239 {(char_u *)"", (char_u *)0L}},
2240 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2241 (char_u *)&p_to, PV_NONE,
2242 {(char_u *)FALSE, (char_u *)0L}},
2243 {"timeout", "to", P_BOOL|P_VI_DEF,
2244 (char_u *)&p_timeout, PV_NONE,
2245 {(char_u *)TRUE, (char_u *)0L}},
2246 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2247 (char_u *)&p_tm, PV_NONE,
2248 {(char_u *)1000L, (char_u *)0L}},
2249 {"title", NULL, P_BOOL|P_VI_DEF,
2250#ifdef FEAT_TITLE
2251 (char_u *)&p_title, PV_NONE,
2252#else
2253 (char_u *)NULL, PV_NONE,
2254#endif
2255 {(char_u *)FALSE, (char_u *)0L}},
2256 {"titlelen", NULL, P_NUM|P_VI_DEF,
2257#ifdef FEAT_TITLE
2258 (char_u *)&p_titlelen, PV_NONE,
2259#else
2260 (char_u *)NULL, PV_NONE,
2261#endif
2262 {(char_u *)85L, (char_u *)0L}},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002263 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002264#ifdef FEAT_TITLE
2265 (char_u *)&p_titleold, PV_NONE,
2266 {(char_u *)N_("Thanks for flying Vim"),
2267 (char_u *)0L}
2268#else
2269 (char_u *)NULL, PV_NONE,
2270 {(char_u *)0L, (char_u *)0L}
2271#endif
2272 },
2273 {"titlestring", NULL, P_STRING|P_VI_DEF,
2274#ifdef FEAT_TITLE
2275 (char_u *)&p_titlestring, PV_NONE,
2276#else
2277 (char_u *)NULL, PV_NONE,
2278#endif
2279 {(char_u *)"", (char_u *)0L}},
2280#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2281 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2282 (char_u *)&p_toolbar, PV_NONE,
2283 {(char_u *)"icons,tooltips", (char_u *)0L}},
2284#endif
2285#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2286 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2287 (char_u *)&p_tbis, PV_NONE,
2288 {(char_u *)"small", (char_u *)0L}},
2289#endif
2290 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2291 (char_u *)&p_ttimeout, PV_NONE,
2292 {(char_u *)FALSE, (char_u *)0L}},
2293 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2294 (char_u *)&p_ttm, PV_NONE,
2295 {(char_u *)-1L, (char_u *)0L}},
2296 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2297 (char_u *)&p_tbi, PV_NONE,
2298 {(char_u *)TRUE, (char_u *)0L}},
2299 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2300 (char_u *)&p_tf, PV_NONE,
2301 {(char_u *)FALSE, (char_u *)0L}},
2302 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2303#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2304 (char_u *)&p_ttym, PV_NONE,
2305#else
2306 (char_u *)NULL, PV_NONE,
2307#endif
2308 {(char_u *)"", (char_u *)0L}},
2309 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2310 (char_u *)&p_ttyscroll, PV_NONE,
2311 {(char_u *)999L, (char_u *)0L}},
2312 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2313 (char_u *)&T_NAME, PV_NONE,
2314 {(char_u *)"", (char_u *)0L}},
2315 {"undolevels", "ul", P_NUM|P_VI_DEF,
2316 (char_u *)&p_ul, PV_NONE,
2317 {
2318#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2319 (char_u *)1000L,
2320#else
2321 (char_u *)100L,
2322#endif
2323 (char_u *)0L}},
2324 {"updatecount", "uc", P_NUM|P_VI_DEF,
2325 (char_u *)&p_uc, PV_NONE,
2326 {(char_u *)200L, (char_u *)0L}},
2327 {"updatetime", "ut", P_NUM|P_VI_DEF,
2328 (char_u *)&p_ut, PV_NONE,
2329 {(char_u *)4000L, (char_u *)0L}},
2330 {"verbose", "vbs", P_NUM|P_VI_DEF,
2331 (char_u *)&p_verbose, PV_NONE,
2332 {(char_u *)0L, (char_u *)0L}},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002333 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2334 (char_u *)&p_vfile, PV_NONE,
2335 {(char_u *)"", (char_u *)0L}},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2337#ifdef FEAT_SESSION
2338 (char_u *)&p_vdir, PV_NONE,
2339 {(char_u *)DFLT_VDIR, (char_u *)0L}
2340#else
2341 (char_u *)NULL, PV_NONE,
2342 {(char_u *)0L, (char_u *)0L}
2343#endif
2344 },
2345 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2346#ifdef FEAT_SESSION
2347 (char_u *)&p_vop, PV_NONE,
2348 {(char_u *)"folds,options,cursor", (char_u *)0L}
2349#else
2350 (char_u *)NULL, PV_NONE,
2351 {(char_u *)0L, (char_u *)0L}
2352#endif
2353 },
2354 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2355#ifdef FEAT_VIMINFO
2356 (char_u *)&p_viminfo, PV_NONE,
2357#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2358 {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2359#else
2360# ifdef AMIGA
2361 {(char_u *)"",
2362 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2363# else
2364 {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2365# endif
2366#endif
2367#else
2368 (char_u *)NULL, PV_NONE,
2369 {(char_u *)0L, (char_u *)0L}
2370#endif
2371 },
2372 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2373#ifdef FEAT_VIRTUALEDIT
2374 (char_u *)&p_ve, PV_NONE,
2375 {(char_u *)"", (char_u *)""}
2376#else
2377 (char_u *)NULL, PV_NONE,
2378 {(char_u *)0L, (char_u *)0L}
2379#endif
2380 },
2381 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2382 (char_u *)&p_vb, PV_NONE,
2383 {(char_u *)FALSE, (char_u *)0L}},
2384 {"w300", NULL, P_NUM|P_VI_DEF,
2385 (char_u *)NULL, PV_NONE,
2386 {(char_u *)0L, (char_u *)0L}},
2387 {"w1200", NULL, P_NUM|P_VI_DEF,
2388 (char_u *)NULL, PV_NONE,
2389 {(char_u *)0L, (char_u *)0L}},
2390 {"w9600", NULL, P_NUM|P_VI_DEF,
2391 (char_u *)NULL, PV_NONE,
2392 {(char_u *)0L, (char_u *)0L}},
2393 {"warn", NULL, P_BOOL|P_VI_DEF,
2394 (char_u *)&p_warn, PV_NONE,
2395 {(char_u *)TRUE, (char_u *)0L}},
2396 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2397 (char_u *)&p_wiv, PV_NONE,
2398 {(char_u *)FALSE, (char_u *)0L}},
2399 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2400 (char_u *)&p_ww, PV_NONE,
2401 {(char_u *)"", (char_u *)"b,s"}},
2402 {"wildchar", "wc", P_NUM|P_VIM,
2403 (char_u *)&p_wc, PV_NONE,
2404 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2405 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2406 (char_u *)&p_wcm, PV_NONE,
2407 {(char_u *)0L, (char_u *)0L}},
2408 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2409#ifdef FEAT_WILDIGN
2410 (char_u *)&p_wig, PV_NONE,
2411#else
2412 (char_u *)NULL, PV_NONE,
2413#endif
2414 {(char_u *)"", (char_u *)0L}},
2415 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2416#ifdef FEAT_WILDMENU
2417 (char_u *)&p_wmnu, PV_NONE,
2418#else
2419 (char_u *)NULL, PV_NONE,
2420#endif
2421 {(char_u *)FALSE, (char_u *)0L}},
2422 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2423 (char_u *)&p_wim, PV_NONE,
2424 {(char_u *)"full", (char_u *)0L}},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002425 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2426#ifdef FEAT_CMDL_COMPL
2427 (char_u *)&p_wop, PV_NONE,
2428 {(char_u *)"", (char_u *)0L}
2429#else
2430 (char_u *)NULL, PV_NONE,
2431 {(char_u *)NULL, (char_u *)0L}
2432#endif
2433 },
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2435#ifdef FEAT_WAK
2436 (char_u *)&p_wak, PV_NONE,
2437 {(char_u *)"menu", (char_u *)0L}
2438#else
2439 (char_u *)NULL, PV_NONE,
2440 {(char_u *)NULL, (char_u *)0L}
2441#endif
2442 },
2443 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002444 (char_u *)&p_window, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {(char_u *)0L, (char_u *)0L}},
2446 {"winheight", "wh", P_NUM|P_VI_DEF,
2447#ifdef FEAT_WINDOWS
2448 (char_u *)&p_wh, PV_NONE,
2449#else
2450 (char_u *)NULL, PV_NONE,
2451#endif
2452 {(char_u *)1L, (char_u *)0L}},
2453 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
2454#if defined(FEAT_WINDOWS)
2455 (char_u *)VAR_WIN, PV_WFH,
2456#else
2457 (char_u *)NULL, PV_NONE,
2458#endif
2459 {(char_u *)FALSE, (char_u *)0L}},
2460 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2461#ifdef FEAT_WINDOWS
2462 (char_u *)&p_wmh, PV_NONE,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
2466 {(char_u *)1L, (char_u *)0L}},
2467 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2468#ifdef FEAT_VERTSPLIT
2469 (char_u *)&p_wmw, PV_NONE,
2470#else
2471 (char_u *)NULL, PV_NONE,
2472#endif
2473 {(char_u *)1L, (char_u *)0L}},
2474 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2475#ifdef FEAT_VERTSPLIT
2476 (char_u *)&p_wiw, PV_NONE,
2477#else
2478 (char_u *)NULL, PV_NONE,
2479#endif
2480 {(char_u *)20L, (char_u *)0L}},
2481 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2482 (char_u *)VAR_WIN, PV_WRAP,
2483 {(char_u *)TRUE, (char_u *)0L}},
2484 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2485 (char_u *)&p_wm, PV_WM,
2486 {(char_u *)0L, (char_u *)0L}},
2487 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2488 (char_u *)&p_ws, PV_NONE,
2489 {(char_u *)TRUE, (char_u *)0L}},
2490 {"write", NULL, P_BOOL|P_VI_DEF,
2491 (char_u *)&p_write, PV_NONE,
2492 {(char_u *)TRUE, (char_u *)0L}},
2493 {"writeany", "wa", P_BOOL|P_VI_DEF,
2494 (char_u *)&p_wa, PV_NONE,
2495 {(char_u *)FALSE, (char_u *)0L}},
2496 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2497 (char_u *)&p_wb, PV_NONE,
2498 {
2499#ifdef FEAT_WRITEBACKUP
2500 (char_u *)TRUE,
2501#else
2502 (char_u *)FALSE,
2503#endif
2504 (char_u *)0L}},
2505 {"writedelay", "wd", P_NUM|P_VI_DEF,
2506 (char_u *)&p_wd, PV_NONE,
2507 {(char_u *)0L, (char_u *)0L}},
2508
2509/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002510#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 (char_u *)&vvv, PV_NONE, \
2512 {(char_u *)"", (char_u *)0L}},
2513
2514 p_term("t_AB", T_CAB)
2515 p_term("t_AF", T_CAF)
2516 p_term("t_AL", T_CAL)
2517 p_term("t_al", T_AL)
2518 p_term("t_bc", T_BC)
2519 p_term("t_cd", T_CD)
2520 p_term("t_ce", T_CE)
2521 p_term("t_cl", T_CL)
2522 p_term("t_cm", T_CM)
2523 p_term("t_Co", T_CCO)
2524 p_term("t_CS", T_CCS)
2525 p_term("t_cs", T_CS)
2526#ifdef FEAT_VERTSPLIT
2527 p_term("t_CV", T_CSV)
2528#endif
2529 p_term("t_ut", T_UT)
2530 p_term("t_da", T_DA)
2531 p_term("t_db", T_DB)
2532 p_term("t_DL", T_CDL)
2533 p_term("t_dl", T_DL)
2534 p_term("t_fs", T_FS)
2535 p_term("t_IE", T_CIE)
2536 p_term("t_IS", T_CIS)
2537 p_term("t_ke", T_KE)
2538 p_term("t_ks", T_KS)
2539 p_term("t_le", T_LE)
2540 p_term("t_mb", T_MB)
2541 p_term("t_md", T_MD)
2542 p_term("t_me", T_ME)
2543 p_term("t_mr", T_MR)
2544 p_term("t_ms", T_MS)
2545 p_term("t_nd", T_ND)
2546 p_term("t_op", T_OP)
2547 p_term("t_RI", T_CRI)
2548 p_term("t_RV", T_CRV)
2549 p_term("t_Sb", T_CSB)
2550 p_term("t_Sf", T_CSF)
2551 p_term("t_se", T_SE)
2552 p_term("t_so", T_SO)
2553 p_term("t_sr", T_SR)
2554 p_term("t_ts", T_TS)
2555 p_term("t_te", T_TE)
2556 p_term("t_ti", T_TI)
2557 p_term("t_ue", T_UE)
2558 p_term("t_us", T_US)
2559 p_term("t_vb", T_VB)
2560 p_term("t_ve", T_VE)
2561 p_term("t_vi", T_VI)
2562 p_term("t_vs", T_VS)
2563 p_term("t_WP", T_CWP)
2564 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002565 p_term("t_SI", T_CSI)
2566 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 p_term("t_xs", T_XS)
2568 p_term("t_ZH", T_CZH)
2569 p_term("t_ZR", T_CZR)
2570
2571/* terminal key codes are not in here */
2572
2573 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}} /* end marker */
2574};
2575
2576#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2577
2578#ifdef FEAT_MBYTE
2579static char *(p_ambw_values[]) = {"single", "double", NULL};
2580#endif
2581static char *(p_bg_values[]) = {"light", "dark", NULL};
2582static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2583static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002584#ifdef FEAT_CMDL_COMPL
2585static char *(p_wop_values[]) = {"tagfile", NULL};
2586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587#ifdef FEAT_WAK
2588static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2589#endif
2590static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2591#ifdef FEAT_VISUAL
2592static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2593static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2594#endif
2595#ifdef FEAT_VISUAL
2596static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2597#endif
2598#ifdef FEAT_BROWSE
2599static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2600#endif
2601#ifdef FEAT_SCROLLBIND
2602static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2603#endif
2604static char *(p_swb_values[]) = {"useopen", "split", NULL};
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002605static char *(p_debug_values[]) = {"msg", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606#ifdef FEAT_VERTSPLIT
2607static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2608#endif
2609#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002610# ifdef FEAT_AUTOCMD
2611static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2612# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002614# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2616#endif
2617static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2618#ifdef FEAT_FOLDING
2619static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002620# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002622# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 NULL};
2624static char *(p_fcl_values[]) = {"all", NULL};
2625#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002626#ifdef FEAT_INS_EXPAND
2627static char *(p_cot_values[]) = {"menu", NULL};
2628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629
2630static void set_option_default __ARGS((int, int opt_flags, int compatible));
2631static void set_options_default __ARGS((int opt_flags));
2632static char_u *illegal_char __ARGS((char_u *, int));
2633static int string_to_key __ARGS((char_u *arg));
2634#ifdef FEAT_CMDWIN
2635static char_u *check_cedit __ARGS((void));
2636#endif
2637#ifdef FEAT_TITLE
2638static void did_set_title __ARGS((int icon));
2639#endif
2640static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2641static void didset_options __ARGS((void));
2642static void check_string_option __ARGS((char_u **pp));
2643static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2644static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2645static 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));
2646static char_u *set_chars_option __ARGS((char_u **varp));
2647#ifdef FEAT_CLIPBOARD
2648static char_u *check_clipboard_option __ARGS((void));
2649#endif
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002650#ifdef FEAT_SYN_HL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002651static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002654static 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 +00002655static void check_redraw __ARGS((long_u flags));
2656static int findoption __ARGS((char_u *));
2657static int find_key_option __ARGS((char_u *));
2658static void showoptions __ARGS((int all, int opt_flags));
2659static int optval_default __ARGS((struct vimoption *, char_u *varp));
2660static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2661static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2662static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2663static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2664static int istermoption __ARGS((struct vimoption *));
2665static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2666static char_u *get_varp __ARGS((struct vimoption *));
2667static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2668static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2669#ifdef FEAT_LANGMAP
2670static void langmap_init __ARGS((void));
2671static void langmap_set __ARGS((void));
2672#endif
2673static void paste_option_changed __ARGS((void));
2674static void compatible_set __ARGS((void));
2675#ifdef FEAT_LINEBREAK
2676static void fill_breakat_flags __ARGS((void));
2677#endif
2678static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2679static int check_opt_strings __ARGS((char_u *val, char **values, int));
2680static int check_opt_wim __ARGS((void));
2681
2682/*
2683 * Initialize the options, first part.
2684 *
2685 * Called only once from main(), just after creating the first buffer.
2686 */
2687 void
2688set_init_1()
2689{
2690 char_u *p;
2691 int opt_idx;
2692 long n;
2693
2694#ifdef FEAT_LANGMAP
2695 langmap_init();
2696#endif
2697
2698 /* Be Vi compatible by default */
2699 p_cp = TRUE;
2700
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002701 /* Use POSIX compatibility when $VIM_POSIX is set. */
2702 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002703 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002704 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002705 set_string_default("shm", (char_u *)"A");
2706 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002707
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 /*
2709 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00002710 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00002712 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2714# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00002715 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002717 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00002719 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720# endif
2721#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00002722 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 set_string_default("sh", p);
2724
2725#ifdef FEAT_WILDIGN
2726 /*
2727 * Set the default for 'backupskip' to include environment variables for
2728 * temp files.
2729 */
2730 {
2731# ifdef UNIX
2732 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2733# else
2734 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2735# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002736 int len;
2737 garray_T ga;
2738 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739
2740 ga_init2(&ga, 1, 100);
2741 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2742 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00002743 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744# ifdef UNIX
2745 if (*names[n] == NUL)
2746 p = (char_u *)"/tmp";
2747 else
2748# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00002749 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 if (p != NULL && *p != NUL)
2751 {
2752 /* First time count the NUL, otherwise count the ','. */
2753 len = STRLEN(p) + 3;
2754 if (ga_grow(&ga, len) == OK)
2755 {
2756 if (ga.ga_len > 0)
2757 STRCAT(ga.ga_data, ",");
2758 STRCAT(ga.ga_data, p);
2759 add_pathsep(ga.ga_data);
2760 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 ga.ga_len += len;
2762 }
2763 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002764 if (mustfree)
2765 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 }
2767 if (ga.ga_data != NULL)
2768 {
2769 set_string_default("bsk", ga.ga_data);
2770 vim_free(ga.ga_data);
2771 }
2772 }
2773#endif
2774
2775 /*
2776 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2777 */
2778 opt_idx = findoption((char_u *)"maxmemtot");
2779#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2780 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2781#endif
2782 {
2783#ifdef HAVE_AVAIL_MEM
2784 /* Use amount of memory available at this moment. */
2785 n = (mch_avail_mem(FALSE) >> 11);
2786#else
2787# ifdef HAVE_TOTAL_MEM
2788 /* Use amount of memory available to Vim. */
2789 n = (mch_total_mem(FALSE) >> 11);
2790# else
2791 n = (0x7fffffff >> 11);
2792# endif
2793#endif
2794 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2795 opt_idx = findoption((char_u *)"maxmem");
2796#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2797 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2798 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2799#endif
2800 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2801 }
2802
2803#ifdef FEAT_GUI_W32
2804 /* force 'shortname' for Win32s */
2805 if (gui_is_win32s())
2806 options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2807 (char_u *)TRUE;
2808#endif
2809
2810#ifdef FEAT_SEARCHPATH
2811 {
2812 char_u *cdpath;
2813 char_u *buf;
2814 int i;
2815 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00002816 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817
2818 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00002819 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 if (cdpath != NULL)
2821 {
2822 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2823 if (buf != NULL)
2824 {
2825 buf[0] = ','; /* start with ",", current dir first */
2826 j = 1;
2827 for (i = 0; cdpath[i] != NUL; ++i)
2828 {
2829 if (vim_ispathlistsep(cdpath[i]))
2830 buf[j++] = ',';
2831 else
2832 {
2833 if (cdpath[i] == ' ' || cdpath[i] == ',')
2834 buf[j++] = '\\';
2835 buf[j++] = cdpath[i];
2836 }
2837 }
2838 buf[j] = NUL;
2839 opt_idx = findoption((char_u *)"cdpath");
2840 options[opt_idx].def_val[VI_DEFAULT] = buf;
2841 options[opt_idx].flags |= P_DEF_ALLOCED;
2842 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00002843 if (mustfree)
2844 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 }
2846 }
2847#endif
2848
2849#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2850 /* Set print encoding on platforms that don't default to latin1 */
2851 set_string_default("penc",
2852# if defined(MSWIN) || defined(OS2)
2853 (char_u *)"cp1252"
2854# else
2855# ifdef VMS
2856 (char_u *)"dec-mcs"
2857# else
2858# ifdef EBCDIC
2859 (char_u *)"ebcdic-uk"
2860# else
2861# ifdef MAC
2862 (char_u *)"mac-roman"
2863# else /* HPUX */
2864 (char_u *)"hp-roman8"
2865# endif
2866# endif
2867# endif
2868# endif
2869 );
2870#endif
2871
2872#ifdef FEAT_POSTSCRIPT
2873 /* 'printexpr' must be allocated to be able to evaluate it. */
2874 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00002875# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
2876 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877# else
2878# ifdef VMS
2879 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
2880
2881# else
2882 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
2883# endif
2884# endif
2885 );
2886#endif
2887
2888 /*
2889 * Set all the options (except the terminal options) to their default
2890 * value. Also set the global value for local options.
2891 */
2892 set_options_default(0);
2893
2894#ifdef FEAT_GUI
2895 if (found_reverse_arg)
2896 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
2897#endif
2898
2899 curbuf->b_p_initialized = TRUE;
2900 curbuf->b_p_ar = -1; /* no local 'autoread' value */
2901 check_buf_options(curbuf);
2902 check_win_options(curwin);
2903 check_options();
2904
2905 /* Must be before option_expand(), because that one needs vim_isIDc() */
2906 didset_options();
2907
Bram Moolenaar6bb68362005-03-22 23:03:44 +00002908#ifdef FEAT_SYN_HL
2909 /* Use the current chartab for the generic chartab. */
2910 init_spell_chartab();
2911#endif
2912
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913#ifdef FEAT_LINEBREAK
2914 /*
2915 * initialize the table for 'breakat'.
2916 */
2917 fill_breakat_flags();
2918#endif
2919
2920 /*
2921 * Expand environment variables and things like "~" for the defaults.
2922 * If option_expand() returns non-NULL the variable is expanded. This can
2923 * only happen for non-indirect options.
2924 * Also set the default to the expanded value, so ":set" does not list
2925 * them.
2926 * Don't set the P_ALLOCED flag, because we don't want to free the
2927 * default.
2928 */
2929 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
2930 {
2931 if ((options[opt_idx].flags & P_GETTEXT)
2932 && options[opt_idx].var != NULL)
2933 p = (char_u *)_(*(char **)options[opt_idx].var);
2934 else
2935 p = option_expand(opt_idx, NULL);
2936 if (p != NULL && (p = vim_strsave(p)) != NULL)
2937 {
2938 *(char_u **)options[opt_idx].var = p;
2939 /* VIMEXP
2940 * Defaults for all expanded options are currently the same for Vi
2941 * and Vim. When this changes, add some code here! Also need to
2942 * split P_DEF_ALLOCED in two.
2943 */
2944 if (options[opt_idx].flags & P_DEF_ALLOCED)
2945 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2946 options[opt_idx].def_val[VI_DEFAULT] = p;
2947 options[opt_idx].flags |= P_DEF_ALLOCED;
2948 }
2949 }
2950
2951 /* Initialize the highlight_attr[] table. */
2952 highlight_changed();
2953
2954 save_file_ff(curbuf); /* Buffer is unchanged */
2955
2956 /* Parse default for 'wildmode' */
2957 check_opt_wim();
2958
2959#if defined(FEAT_ARABIC)
2960 /* Detect use of mlterm.
2961 * Mlterm is a terminal emulator akin to xterm that has some special
2962 * abilities (bidi namely).
2963 * NOTE: mlterm's author is being asked to 'set' a variable
2964 * instead of an environment variable due to inheritance.
2965 */
2966 if (mch_getenv((char_u *)"MLTERM") != NULL)
2967 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
2968#endif
2969
2970#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
2971 /* Parse default for 'fillchars'. */
2972 (void)set_chars_option(&p_fcs);
2973#endif
2974
2975#ifdef FEAT_CLIPBOARD
2976 /* Parse default for 'clipboard' */
2977 (void)check_clipboard_option();
2978#endif
2979
2980#ifdef FEAT_MBYTE
2981# if defined(WIN3264) && defined(FEAT_GETTEXT)
2982 /*
2983 * If $LANG isn't set, try to get a good value for it. This makes the
2984 * right language be used automatically. Don't do this for English.
2985 */
2986 if (mch_getenv((char_u *)"LANG") == NULL)
2987 {
2988 char buf[20];
2989
2990 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
2991 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
2992 * only the first two. */
2993 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
2994 (LPTSTR)buf, 20);
2995 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
2996 {
2997 /* There are a few exceptions (probably more) */
2998 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
2999 STRCPY(buf, "zh_TW");
3000 else if (STRNICMP(buf, "chs", 3) == 0
3001 || STRNICMP(buf, "zhc", 3) == 0)
3002 STRCPY(buf, "zh_CN");
3003 else if (STRNICMP(buf, "jp", 2) == 0)
3004 STRCPY(buf, "ja");
3005 else
3006 buf[2] = NUL; /* truncate to two-letter code */
3007 vim_setenv("LANG", buf);
3008 }
3009 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003010# else
3011# ifdef MACOS
3012 if (mch_getenv((char_u *)"LANG") == NULL)
3013 {
3014 char buf[20];
3015 if (LocaleRefGetPartString(NULL,
3016 kLocaleLanguageMask | kLocaleLanguageVariantMask |
3017 kLocaleRegionMask | kLocaleRegionVariantMask,
3018 sizeof buf, buf) == noErr && *buf)
3019 {
Bram Moolenaarda2303d2005-08-30 21:55:26 +00003020 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003021# ifdef HAVE_LOCALE_H
3022 setlocale(LC_ALL, "");
3023# endif
3024 }
3025 }
3026# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027# endif
3028
3029 /* enc_locale() will try to find the encoding of the current locale. */
3030 p = enc_locale();
3031 if (p != NULL)
3032 {
3033 char_u *save_enc;
3034
3035 /* Try setting 'encoding' and check if the value is valid.
3036 * If not, go back to the default "latin1". */
3037 save_enc = p_enc;
3038 p_enc = p;
3039 if (mb_init() == NULL)
3040 {
3041 opt_idx = findoption((char_u *)"encoding");
3042 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3043 options[opt_idx].flags |= P_DEF_ALLOCED;
3044
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003045#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3046 || defined(VMS)
3047 if (STRCMP(p_enc, "latin1") == 0
3048# ifdef FEAT_MBYTE
3049 || enc_utf8
3050# endif
3051 )
3052 {
3053 /* Adjust the default for 'isprint' to match latin1. */
3054 set_string_option_direct((char_u *)"isp", -1,
3055 (char_u *)"@,161-255", OPT_FREE);
3056 (void)init_chartab();
3057 }
3058#endif
3059
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060# if defined(WIN3264) && !defined(FEAT_GUI)
3061 /* Win32 console: When GetACP() returns a different value from
3062 * GetConsoleCP() set 'termencoding'. */
3063 if (GetACP() != GetConsoleCP())
3064 {
3065 char buf[50];
3066
3067 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3068 p_tenc = vim_strsave((char_u *)buf);
3069 if (p_tenc != NULL)
3070 {
3071 opt_idx = findoption((char_u *)"termencoding");
3072 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3073 options[opt_idx].flags |= P_DEF_ALLOCED;
3074 convert_setup(&input_conv, p_tenc, p_enc);
3075 convert_setup(&output_conv, p_enc, p_tenc);
3076 }
3077 else
3078 p_tenc = empty_option;
3079 }
3080# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003081# if defined(WIN3264) && defined(FEAT_MBYTE)
3082 /* $HOME may have characters in active code page. */
3083 init_homedir();
3084# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 }
3086 else
3087 {
3088 vim_free(p_enc);
3089 p_enc = save_enc;
3090 }
3091 }
3092#endif
3093
3094#ifdef FEAT_MULTI_LANG
3095 /* Set the default for 'helplang'. */
3096 set_helplang_default(get_mess_lang());
3097#endif
3098}
3099
3100/*
3101 * Set an option to its default value.
3102 * This does not take care of side effects!
3103 */
3104 static void
3105set_option_default(opt_idx, opt_flags, compatible)
3106 int opt_idx;
3107 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3108 int compatible; /* use Vi default value */
3109{
3110 char_u *varp; /* pointer to variable for current option */
3111 int dvi; /* index in def_val[] */
3112 long_u flags;
3113 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3114
3115 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3116 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003117 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 {
3119 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3120 if (flags & P_STRING)
3121 {
3122 /* Use set_string_option_direct() for local options to handle
3123 * freeing and allocating the value. */
3124 if (options[opt_idx].indir != PV_NONE)
3125 set_string_option_direct(NULL, opt_idx,
3126 options[opt_idx].def_val[dvi], opt_flags);
3127 else
3128 {
3129 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3130 free_string_option(*(char_u **)(varp));
3131 *(char_u **)varp = options[opt_idx].def_val[dvi];
3132 options[opt_idx].flags &= ~P_ALLOCED;
3133 }
3134 }
3135 else if (flags & P_NUM)
3136 {
3137 if (varp == (char_u *)PV_SCROLL)
3138 win_comp_scroll(curwin);
3139 else
3140 {
3141 *(long *)varp = (long)options[opt_idx].def_val[dvi];
3142 /* May also set global value for local option. */
3143 if (both)
3144 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3145 *(long *)varp;
3146 }
3147 }
3148 else /* P_BOOL */
3149 {
3150 /* the cast to long is required for Manx C */
3151 *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
3152 /* May also set global value for local option. */
3153 if (both)
3154 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3155 *(int *)varp;
3156 }
3157 }
3158
3159#ifdef FEAT_EVAL
3160 /* Remember where the option was set. */
3161 options[opt_idx].scriptID = current_SID;
3162#endif
3163}
3164
3165/*
3166 * Set all options (except terminal options) to their default value.
3167 */
3168 static void
3169set_options_default(opt_flags)
3170 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3171{
3172 int i;
3173#ifdef FEAT_WINDOWS
3174 win_T *wp;
3175#endif
3176
3177 for (i = 0; !istermoption(&options[i]); i++)
3178 if (!(options[i].flags & P_NODEFAULT))
3179 set_option_default(i, opt_flags, p_cp);
3180
3181#ifdef FEAT_WINDOWS
3182 /* The 'scroll' option must be computed for all windows. */
3183 for (wp = firstwin; wp != NULL; wp = wp->w_next)
3184 win_comp_scroll(wp);
3185#else
3186 win_comp_scroll(curwin);
3187#endif
3188}
3189
3190/*
3191 * Set the Vi-default value of a string option.
3192 * Used for 'sh', 'backupskip' and 'term'.
3193 */
3194 void
3195set_string_default(name, val)
3196 char *name;
3197 char_u *val;
3198{
3199 char_u *p;
3200 int opt_idx;
3201
3202 p = vim_strsave(val);
3203 if (p != NULL) /* we don't want a NULL */
3204 {
3205 opt_idx = findoption((char_u *)name);
3206 if (options[opt_idx].flags & P_DEF_ALLOCED)
3207 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3208 options[opt_idx].def_val[VI_DEFAULT] = p;
3209 options[opt_idx].flags |= P_DEF_ALLOCED;
3210 }
3211}
3212
3213/*
3214 * Set the Vi-default value of a number option.
3215 * Used for 'lines' and 'columns'.
3216 */
3217 void
3218set_number_default(name, val)
3219 char *name;
3220 long val;
3221{
3222 options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3223}
3224
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003225#if defined(EXITFREE) || defined(PROTO)
3226/*
3227 * Free all options.
3228 */
3229 void
3230free_all_options()
3231{
3232 int i;
3233
3234 for (i = 0; !istermoption(&options[i]); i++)
3235 {
3236 if (options[i].indir == PV_NONE)
3237 {
3238 /* global option: free value and default value. */
3239 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3240 free_string_option(*(char_u **)options[i].var);
3241 if (options[i].flags & P_DEF_ALLOCED)
3242 free_string_option(options[i].def_val[VI_DEFAULT]);
3243 }
3244 else if (options[i].var != VAR_WIN
3245 && (options[i].flags & P_STRING))
3246 /* buffer-local option: free global value */
3247 free_string_option(*(char_u **)options[i].var);
3248 }
3249}
3250#endif
3251
3252
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253/*
3254 * Initialize the options, part two: After getting Rows and Columns and
3255 * setting 'term'.
3256 */
3257 void
3258set_init_2()
3259{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003260 int idx;
3261
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262 /*
3263 * 'scroll' defaults to half the window height. Note that this default is
3264 * wrong when the window height changes.
3265 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003266 set_number_default("scroll", (long_u)Rows >> 1);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003267 idx = findoption((char_u *)"scroll");
3268 if (!(options[idx].flags & P_WAS_SET))
3269 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270 comp_col();
3271
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003272 /*
3273 * 'window' is only for backwards compatibility with Vi.
3274 * Default is Rows - 1.
3275 */
3276 idx = findoption((char_u *)"wi");
3277 if (!(options[idx].flags & P_WAS_SET))
3278 p_window = Rows - 1;
3279 set_number_default("window", Rows - 1);
3280
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3282 {
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003283 char_u *p;
3284
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285 /*
3286 * If 'background' wasn't set by the user, try guessing the value,
3287 * depending on the terminal name. Only need to check for terminals
Bram Moolenaara21b29a2005-02-27 22:40:05 +00003288 * with a dark background, that can handle color. Recognized are:
3289 * "linux" Linux console
3290 * "screen.linux" Linux console with screen
Bram Moolenaar19a09a12005-03-04 23:39:37 +00003291 * "cygwin" Cygwin shell
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003292 * "putty" Putty program
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003293 * We also check the COLORFGBG environment variable, which is set by
3294 * rxvt and derivatives. This variable contains either two or three
3295 * values separated by semicolons; we want the last value in either
3296 * case. If this value is 0-6 or 8, our background is dark.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003298 idx = findoption((char_u *)"bg");
Bram Moolenaara21b29a2005-02-27 22:40:05 +00003299 if (!(options[idx].flags & P_WAS_SET)
3300 && (STRCMP(T_NAME, "linux") == 0
Bram Moolenaar19a09a12005-03-04 23:39:37 +00003301 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003302 || STRCMP(T_NAME, "cygwin") == 0
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00003303 || STRCMP(T_NAME, "putty") == 0
Bram Moolenaar46152342005-09-07 21:18:43 +00003304 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003305 && (p = vim_strrchr(p, ';')) != NULL
3306 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3307 && p[2] == NUL)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003309 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE);
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003310 /* don't mark it as set, when starting the GUI it may be
3311 * changed again */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003312 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 }
3314 }
3315#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003316
3317#ifdef CURSOR_SHAPE
3318 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3319#endif
3320#ifdef FEAT_MOUSESHAPE
3321 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3322#endif
3323#ifdef FEAT_PRINTER
3324 (void)parse_printoptions(); /* parse 'printoptions' default value */
3325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326}
3327
3328/*
3329 * Initialize the options, part three: After reading the .vimrc
3330 */
3331 void
3332set_init_3()
3333{
3334#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3335/*
3336 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3337 * This is done after other initializations, where 'shell' might have been
3338 * set, but only if they have not been set before.
3339 */
3340 char_u *p;
3341 int idx_srr;
3342 int do_srr;
3343#ifdef FEAT_QUICKFIX
3344 int idx_sp;
3345 int do_sp;
3346#endif
3347
3348 idx_srr = findoption((char_u *)"srr");
3349 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3350#ifdef FEAT_QUICKFIX
3351 idx_sp = findoption((char_u *)"sp");
3352 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3353#endif
3354
3355 /*
3356 * Isolate the name of the shell:
3357 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3358 * - Remove any argument. E.g., "csh -f" -> "csh".
3359 */
3360 p = gettail(p_sh);
3361 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3362 if (p != NULL)
3363 {
3364 /*
3365 * Default for p_sp is "| tee", for p_srr is ">".
3366 * For known shells it is changed here to include stderr.
3367 */
3368 if ( fnamecmp(p, "csh") == 0
3369 || fnamecmp(p, "tcsh") == 0
3370# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3371 || fnamecmp(p, "csh.exe") == 0
3372 || fnamecmp(p, "tcsh.exe") == 0
3373# endif
3374 )
3375 {
3376#if defined(FEAT_QUICKFIX)
3377 if (do_sp)
3378 {
3379# ifdef WIN3264
3380 p_sp = (char_u *)">&";
3381# else
3382 p_sp = (char_u *)"|& tee";
3383# endif
3384 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3385 }
3386#endif
3387 if (do_srr)
3388 {
3389 p_srr = (char_u *)">&";
3390 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3391 }
3392 }
3393 else
3394# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3395 if ( fnamecmp(p, "sh") == 0
3396 || fnamecmp(p, "ksh") == 0
3397 || fnamecmp(p, "zsh") == 0
3398 || fnamecmp(p, "bash") == 0
3399# ifdef WIN3264
3400 || fnamecmp(p, "cmd") == 0
3401 || fnamecmp(p, "sh.exe") == 0
3402 || fnamecmp(p, "ksh.exe") == 0
3403 || fnamecmp(p, "zsh.exe") == 0
3404 || fnamecmp(p, "bash.exe") == 0
3405 || fnamecmp(p, "cmd.exe") == 0
3406# endif
3407 )
3408# endif
3409 {
3410#if defined(FEAT_QUICKFIX)
3411 if (do_sp)
3412 {
3413# ifdef WIN3264
3414 p_sp = (char_u *)">%s 2>&1";
3415# else
3416 p_sp = (char_u *)"2>&1| tee";
3417# endif
3418 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3419 }
3420#endif
3421 if (do_srr)
3422 {
3423 p_srr = (char_u *)">%s 2>&1";
3424 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3425 }
3426 }
3427 vim_free(p);
3428 }
3429#endif
3430
3431#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3432 /*
3433 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3434 * This is done after other initializations, where 'shell' might have been
3435 * set, but only if they have not been set before. Default for p_shcf is
3436 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3437 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3438 * command.com. And for Win32 we need to set p_sxq instead.
3439 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003440 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 {
3442 int idx3;
3443
3444 idx3 = findoption((char_u *)"shcf");
3445 if (!(options[idx3].flags & P_WAS_SET))
3446 {
3447 p_shcf = (char_u *)"-c";
3448 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3449 }
3450
3451# ifndef DJGPP
3452# ifdef WIN3264
3453 /* Somehow Win32 requires the quotes around the redirection too */
3454 idx3 = findoption((char_u *)"sxq");
3455 if (!(options[idx3].flags & P_WAS_SET))
3456 {
3457 p_sxq = (char_u *)"\"";
3458 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3459 }
3460# else
3461 idx3 = findoption((char_u *)"shq");
3462 if (!(options[idx3].flags & P_WAS_SET))
3463 {
3464 p_shq = (char_u *)"\"";
3465 options[idx3].def_val[VI_DEFAULT] = p_shq;
3466 }
3467# endif
3468# endif
3469 }
3470#endif
3471
3472#ifdef FEAT_TITLE
3473 set_title_defaults();
3474#endif
3475}
3476
3477#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3478/*
3479 * When 'helplang' is still at its default value, set it to "lang".
3480 * Only the first two characters of "lang" are used.
3481 */
3482 void
3483set_helplang_default(lang)
3484 char_u *lang;
3485{
3486 int idx;
3487
3488 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3489 return;
3490 idx = findoption((char_u *)"hlg");
3491 if (!(options[idx].flags & P_WAS_SET))
3492 {
3493 if (options[idx].flags & P_ALLOCED)
3494 free_string_option(p_hlg);
3495 p_hlg = vim_strsave(lang);
3496 if (p_hlg == NULL)
3497 p_hlg = empty_option;
3498 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003499 {
3500 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3501 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3502 {
3503 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3504 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3505 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003507 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003508 options[idx].flags |= P_ALLOCED;
3509 }
3510}
3511#endif
3512
3513#ifdef FEAT_GUI
3514static char_u *gui_bg_default __ARGS((void));
3515
3516 static char_u *
3517gui_bg_default()
3518{
3519 if (gui_get_lightness(gui.back_pixel) < 127)
3520 return (char_u *)"dark";
3521 return (char_u *)"light";
3522}
3523
3524/*
3525 * Option initializations that can only be done after opening the GUI window.
3526 */
3527 void
3528init_gui_options()
3529{
3530 /* Set the 'background' option according to the lightness of the
3531 * background color, unless the user has set it already. */
3532 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3533 {
3534 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3535 highlight_changed();
3536 }
3537}
3538#endif
3539
3540#ifdef FEAT_TITLE
3541/*
3542 * 'title' and 'icon' only default to true if they have not been set or reset
3543 * in .vimrc and we can read the old value.
3544 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3545 * they can be reset. This reduces startup time when using X on a remote
3546 * machine.
3547 */
3548 void
3549set_title_defaults()
3550{
3551 int idx1;
3552 long val;
3553
3554 /*
3555 * If GUI is (going to be) used, we can always set the window title and
3556 * icon name. Saves a bit of time, because the X11 display server does
3557 * not need to be contacted.
3558 */
3559 idx1 = findoption((char_u *)"title");
3560 if (!(options[idx1].flags & P_WAS_SET))
3561 {
3562#ifdef FEAT_GUI
3563 if (gui.starting || gui.in_use)
3564 val = TRUE;
3565 else
3566#endif
3567 val = mch_can_restore_title();
3568 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3569 p_title = val;
3570 }
3571 idx1 = findoption((char_u *)"icon");
3572 if (!(options[idx1].flags & P_WAS_SET))
3573 {
3574#ifdef FEAT_GUI
3575 if (gui.starting || gui.in_use)
3576 val = TRUE;
3577 else
3578#endif
3579 val = mch_can_restore_icon();
3580 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3581 p_icon = val;
3582 }
3583}
3584#endif
3585
3586/*
3587 * Parse 'arg' for option settings.
3588 *
3589 * 'arg' may be IObuff, but only when no errors can be present and option
3590 * does not need to be expanded with option_expand().
3591 * "opt_flags":
3592 * 0 for ":set"
3593 * OPT_GLOBAL for ":setglobal"
3594 * OPT_LOCAL for ":setlocal" and a modeline
3595 * OPT_MODELINE for a modeline
3596 *
3597 * returns FAIL if an error is detected, OK otherwise
3598 */
3599 int
3600do_set(arg, opt_flags)
3601 char_u *arg; /* option string (may be written to!) */
3602 int opt_flags;
3603{
3604 int opt_idx;
3605 char_u *errmsg;
3606 char_u errbuf[80];
3607 char_u *startarg;
3608 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3609 int nextchar; /* next non-white char after option name */
3610 int afterchar; /* character just after option name */
3611 int len;
3612 int i;
3613 long value;
3614 int key;
3615 long_u flags; /* flags for current option */
3616 char_u *varp = NULL; /* pointer to variable for current option */
3617 int did_show = FALSE; /* already showed one value */
3618 int adding; /* "opt+=arg" */
3619 int prepending; /* "opt^=arg" */
3620 int removing; /* "opt-=arg" */
3621 int cp_val = 0;
3622 char_u key_name[2];
3623
3624 if (*arg == NUL)
3625 {
3626 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003627 did_show = TRUE;
3628 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629 }
3630
3631 while (*arg != NUL) /* loop to process all options */
3632 {
3633 errmsg = NULL;
3634 startarg = arg; /* remember for error message */
3635
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003636 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3637 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 {
3639 /*
3640 * ":set all" show all options.
3641 * ":set all&" set all options to their default value.
3642 */
3643 arg += 3;
3644 if (*arg == '&')
3645 {
3646 ++arg;
3647 /* Only for :set command set global value of local options. */
3648 set_options_default(OPT_FREE | opt_flags);
3649 }
3650 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003651 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003653 did_show = TRUE;
3654 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003656 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657 {
3658 showoptions(2, opt_flags);
3659 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003660 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661 arg += 7;
3662 }
3663 else
3664 {
3665 prefix = 1;
3666 if (STRNCMP(arg, "no", 2) == 0)
3667 {
3668 prefix = 0;
3669 arg += 2;
3670 }
3671 else if (STRNCMP(arg, "inv", 3) == 0)
3672 {
3673 prefix = 2;
3674 arg += 3;
3675 }
3676
3677 /* find end of name */
3678 key = 0;
3679 if (*arg == '<')
3680 {
3681 nextchar = 0;
3682 opt_idx = -1;
3683 /* look out for <t_>;> */
3684 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3685 len = 5;
3686 else
3687 {
3688 len = 1;
3689 while (arg[len] != NUL && arg[len] != '>')
3690 ++len;
3691 }
3692 if (arg[len] != '>')
3693 {
3694 errmsg = e_invarg;
3695 goto skip;
3696 }
3697 arg[len] = NUL; /* put NUL after name */
3698 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3699 opt_idx = findoption(arg + 1);
3700 arg[len++] = '>'; /* restore '>' */
3701 if (opt_idx == -1)
3702 key = find_key_option(arg + 1);
3703 }
3704 else
3705 {
3706 len = 0;
3707 /*
3708 * The two characters after "t_" may not be alphanumeric.
3709 */
3710 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3711 len = 4;
3712 else
3713 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3714 ++len;
3715 nextchar = arg[len];
3716 arg[len] = NUL; /* put NUL after name */
3717 opt_idx = findoption(arg);
3718 arg[len] = nextchar; /* restore nextchar */
3719 if (opt_idx == -1)
3720 key = find_key_option(arg);
3721 }
3722
3723 /* remember character after option name */
3724 afterchar = arg[len];
3725
3726 /* skip white space, allow ":set ai ?" */
3727 while (vim_iswhite(arg[len]))
3728 ++len;
3729
3730 adding = FALSE;
3731 prepending = FALSE;
3732 removing = FALSE;
3733 if (arg[len] != NUL && arg[len + 1] == '=')
3734 {
3735 if (arg[len] == '+')
3736 {
3737 adding = TRUE; /* "+=" */
3738 ++len;
3739 }
3740 else if (arg[len] == '^')
3741 {
3742 prepending = TRUE; /* "^=" */
3743 ++len;
3744 }
3745 else if (arg[len] == '-')
3746 {
3747 removing = TRUE; /* "-=" */
3748 ++len;
3749 }
3750 }
3751 nextchar = arg[len];
3752
3753 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3754 {
3755 errmsg = (char_u *)N_("E518: Unknown option");
3756 goto skip;
3757 }
3758
3759 if (opt_idx >= 0)
3760 {
3761 if (options[opt_idx].var == NULL) /* hidden option: skip */
3762 {
3763 /* Only give an error message when requesting the value of
3764 * a hidden option, ignore setting it. */
3765 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3766 && (!(options[opt_idx].flags & P_BOOL)
3767 || nextchar == '?'))
3768 errmsg = (char_u *)N_("E519: Option not supported");
3769 goto skip;
3770 }
3771
3772 flags = options[opt_idx].flags;
3773 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3774 }
3775 else
3776 {
3777 flags = P_STRING;
3778 if (key < 0)
3779 {
3780 key_name[0] = KEY2TERMCAP0(key);
3781 key_name[1] = KEY2TERMCAP1(key);
3782 }
3783 else
3784 {
3785 key_name[0] = KS_KEY;
3786 key_name[1] = (key & 0xff);
3787 }
3788 }
3789
3790 /* Disallow changing some options from modelines */
3791 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3792 {
3793 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3794 goto skip;
3795 }
3796
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00003797 /* Skip all options that are not window-local (used when showing
3798 * an already loaded buffer in a window). */
3799 if ((opt_flags & OPT_WINONLY)
3800 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
3801 goto skip;
3802
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803#ifdef HAVE_SANDBOX
3804 /* Disallow changing some options in the sandbox */
3805 if (sandbox > 0 && (flags & P_SECURE))
3806 {
3807 errmsg = (char_u *)_(e_sandbox);
3808 goto skip;
3809 }
3810#endif
3811
3812 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3813 {
3814 arg += len;
3815 cp_val = p_cp;
3816 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3817 {
3818 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3819 {
3820 cp_val = FALSE;
3821 arg += 3;
3822 }
3823 else /* "opt&vi": set to Vi default */
3824 {
3825 cp_val = TRUE;
3826 arg += 2;
3827 }
3828 }
3829 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3830 && arg[1] != NUL && !vim_iswhite(arg[1]))
3831 {
3832 errmsg = e_trailing;
3833 goto skip;
3834 }
3835 }
3836
3837 /*
3838 * allow '=' and ':' as MSDOS command.com allows only one
3839 * '=' character per "set" command line. grrr. (jw)
3840 */
3841 if (nextchar == '?'
3842 || (prefix == 1
3843 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
3844 && !(flags & P_BOOL)))
3845 {
3846 /*
3847 * print value
3848 */
3849 if (did_show)
3850 msg_putchar('\n'); /* cursor below last one */
3851 else
3852 {
3853 gotocmdline(TRUE); /* cursor at status line */
3854 did_show = TRUE; /* remember that we did a line */
3855 }
3856 if (opt_idx >= 0)
3857 {
3858 showoneopt(&options[opt_idx], opt_flags);
3859#ifdef FEAT_EVAL
3860 if (p_verbose > 0)
Bram Moolenaar661b1822005-07-28 22:36:45 +00003861 last_set_msg(options[opt_idx].scriptID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862#endif
3863 }
3864 else
3865 {
3866 char_u *p;
3867
3868 p = find_termcode(key_name);
3869 if (p == NULL)
3870 {
3871 errmsg = (char_u *)N_("E518: Unknown option");
3872 goto skip;
3873 }
3874 else
3875 (void)show_one_termcode(key_name, p, TRUE);
3876 }
3877 if (nextchar != '?'
3878 && nextchar != NUL && !vim_iswhite(afterchar))
3879 errmsg = e_trailing;
3880 }
3881 else
3882 {
3883 if (flags & P_BOOL) /* boolean */
3884 {
3885 if (nextchar == '=' || nextchar == ':')
3886 {
3887 errmsg = e_invarg;
3888 goto skip;
3889 }
3890
3891 /*
3892 * ":set opt!": invert
3893 * ":set opt&": reset to default value
3894 * ":set opt<": reset to global value
3895 */
3896 if (nextchar == '!')
3897 value = *(int *)(varp) ^ 1;
3898 else if (nextchar == '&')
3899 value = (int)(long)options[opt_idx].def_val[
3900 ((flags & P_VI_DEF) || cp_val)
3901 ? VI_DEFAULT : VIM_DEFAULT];
3902 else if (nextchar == '<')
3903 {
3904 /* For 'autoread' -1 means to use global value. */
3905 if ((int *)varp == &curbuf->b_p_ar
3906 && opt_flags == OPT_LOCAL)
3907 value = -1;
3908 else
3909 value = *(int *)get_varp_scope(&(options[opt_idx]),
3910 OPT_GLOBAL);
3911 }
3912 else
3913 {
3914 /*
3915 * ":set invopt": invert
3916 * ":set opt" or ":set noopt": set or reset
3917 */
3918 if (nextchar != NUL && !vim_iswhite(afterchar))
3919 {
3920 errmsg = e_trailing;
3921 goto skip;
3922 }
3923 if (prefix == 2) /* inv */
3924 value = *(int *)(varp) ^ 1;
3925 else
3926 value = prefix;
3927 }
3928
3929 errmsg = set_bool_option(opt_idx, varp, (int)value,
3930 opt_flags);
3931 }
3932 else /* numeric or string */
3933 {
3934 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
3935 || prefix != 1)
3936 {
3937 errmsg = e_invarg;
3938 goto skip;
3939 }
3940
3941 if (flags & P_NUM) /* numeric */
3942 {
3943 /*
3944 * Different ways to set a number option:
3945 * & set to default value
3946 * < set to global value
3947 * <xx> accept special key codes for 'wildchar'
3948 * c accept any non-digit for 'wildchar'
3949 * [-]0-9 set number
3950 * other error
3951 */
3952 ++arg;
3953 if (nextchar == '&')
3954 value = (long)options[opt_idx].def_val[
3955 ((flags & P_VI_DEF) || cp_val)
3956 ? VI_DEFAULT : VIM_DEFAULT];
3957 else if (nextchar == '<')
3958 value = *(long *)get_varp_scope(&(options[opt_idx]),
3959 OPT_GLOBAL);
3960 else if (((long *)varp == &p_wc
3961 || (long *)varp == &p_wcm)
3962 && (*arg == '<'
3963 || *arg == '^'
3964 || ((!arg[1] || vim_iswhite(arg[1]))
3965 && !VIM_ISDIGIT(*arg))))
3966 {
3967 value = string_to_key(arg);
3968 if (value == 0 && (long *)varp != &p_wcm)
3969 {
3970 errmsg = e_invarg;
3971 goto skip;
3972 }
3973 }
3974 /* allow negative numbers (for 'undolevels') */
3975 else if (*arg == '-' || VIM_ISDIGIT(*arg))
3976 {
3977 i = 0;
3978 if (*arg == '-')
3979 i = 1;
3980#ifdef HAVE_STRTOL
3981 value = strtol((char *)arg, NULL, 0);
3982 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
3983 i += 2;
3984#else
3985 value = atol((char *)arg);
3986#endif
3987 while (VIM_ISDIGIT(arg[i]))
3988 ++i;
3989 if (arg[i] != NUL && !vim_iswhite(arg[i]))
3990 {
3991 errmsg = e_invarg;
3992 goto skip;
3993 }
3994 }
3995 else
3996 {
3997 errmsg = (char_u *)N_("E521: Number required after =");
3998 goto skip;
3999 }
4000
4001 if (adding)
4002 value = *(long *)varp + value;
4003 if (prepending)
4004 value = *(long *)varp * value;
4005 if (removing)
4006 value = *(long *)varp - value;
4007 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004008 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009 }
4010 else if (opt_idx >= 0) /* string */
4011 {
4012 char_u *save_arg = NULL;
4013 char_u *s = NULL;
4014 char_u *oldval; /* previous value if *varp */
4015 char_u *newval;
4016 char_u *origval;
4017 unsigned newlen;
4018 int comma;
4019 int bs;
4020 int new_value_alloced; /* new string option
4021 was allocated */
4022
4023 /* When using ":set opt=val" for a global option
4024 * with a local value the local value will be
4025 * reset, use the global value here. */
4026 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4027 && (int)options[opt_idx].indir >= PV_BOTH)
4028 varp = options[opt_idx].var;
4029
4030 /* The old value is kept until we are sure that the
4031 * new value is valid. */
4032 oldval = *(char_u **)varp;
4033 if (nextchar == '&') /* set to default val */
4034 {
4035 newval = options[opt_idx].def_val[
4036 ((flags & P_VI_DEF) || cp_val)
4037 ? VI_DEFAULT : VIM_DEFAULT];
4038 if ((char_u **)varp == &p_bg)
4039 {
4040 /* guess the value of 'background' */
4041#ifdef FEAT_GUI
4042 if (gui.in_use)
4043 newval = gui_bg_default();
4044 else
4045#endif
4046 if (STRCMP(T_NAME, "linux") == 0)
4047 newval = (char_u *)"dark";
4048 }
4049
4050 /* expand environment variables and ~ (since the
4051 * default value was already expanded, only
4052 * required when an environment variable was set
4053 * later */
4054 if (newval == NULL)
4055 newval = empty_option;
4056 else
4057 {
4058 s = option_expand(opt_idx, newval);
4059 if (s == NULL)
4060 s = newval;
4061 newval = vim_strsave(s);
4062 }
4063 new_value_alloced = TRUE;
4064 }
4065 else if (nextchar == '<') /* set to global val */
4066 {
4067 newval = vim_strsave(*(char_u **)get_varp_scope(
4068 &(options[opt_idx]), OPT_GLOBAL));
4069 new_value_alloced = TRUE;
4070 }
4071 else
4072 {
4073 ++arg; /* jump to after the '=' or ':' */
4074
4075 /*
4076 * Set 'keywordprg' to ":help" if an empty
4077 * value was passed to :set by the user.
4078 * Misuse errbuf[] for the resulting string.
4079 */
4080 if (varp == (char_u *)&p_kp
4081 && (*arg == NUL || *arg == ' '))
4082 {
4083 STRCPY(errbuf, ":help");
4084 save_arg = arg;
4085 arg = errbuf;
4086 }
4087 /*
4088 * Convert 'whichwrap' number to string, for
4089 * backwards compatibility with Vim 3.0.
4090 * Misuse errbuf[] for the resulting string.
4091 */
4092 else if (varp == (char_u *)&p_ww
4093 && VIM_ISDIGIT(*arg))
4094 {
4095 *errbuf = NUL;
4096 i = getdigits(&arg);
4097 if (i & 1)
4098 STRCAT(errbuf, "b,");
4099 if (i & 2)
4100 STRCAT(errbuf, "s,");
4101 if (i & 4)
4102 STRCAT(errbuf, "h,l,");
4103 if (i & 8)
4104 STRCAT(errbuf, "<,>,");
4105 if (i & 16)
4106 STRCAT(errbuf, "[,],");
4107 if (*errbuf != NUL) /* remove trailing , */
4108 errbuf[STRLEN(errbuf) - 1] = NUL;
4109 save_arg = arg;
4110 arg = errbuf;
4111 }
4112 /*
4113 * Remove '>' before 'dir' and 'bdir', for
4114 * backwards compatibility with version 3.0
4115 */
4116 else if ( *arg == '>'
4117 && (varp == (char_u *)&p_dir
4118 || varp == (char_u *)&p_bdir))
4119 {
4120 ++arg;
4121 }
4122
4123 /* When setting the local value of a global
4124 * option, the old value may be the global value. */
4125 if ((int)options[opt_idx].indir >= PV_BOTH
4126 && (opt_flags & OPT_LOCAL))
4127 origval = *(char_u **)get_varp(
4128 &options[opt_idx]);
4129 else
4130 origval = oldval;
4131
4132 /*
4133 * Copy the new string into allocated memory.
4134 * Can't use set_string_option_direct(), because
4135 * we need to remove the backslashes.
4136 */
4137 /* get a bit too much */
4138 newlen = (unsigned)STRLEN(arg) + 1;
4139 if (adding || prepending || removing)
4140 newlen += (unsigned)STRLEN(origval) + 1;
4141 newval = alloc(newlen);
4142 if (newval == NULL) /* out of mem, don't change */
4143 break;
4144 s = newval;
4145
4146 /*
4147 * Copy the string, skip over escaped chars.
4148 * For MS-DOS and WIN32 backslashes before normal
4149 * file name characters are not removed, and keep
4150 * backslash at start, for "\\machine\path", but
4151 * do remove it for "\\\\machine\\path".
4152 * The reverse is found in ExpandOldSetting().
4153 */
4154 while (*arg && !vim_iswhite(*arg))
4155 {
4156 if (*arg == '\\' && arg[1] != NUL
4157#ifdef BACKSLASH_IN_FILENAME
4158 && !((flags & P_EXPAND)
4159 && vim_isfilec(arg[1])
4160 && (arg[1] != '\\'
4161 || (s == newval
4162 && arg[2] != '\\')))
4163#endif
4164 )
4165 ++arg; /* remove backslash */
4166#ifdef FEAT_MBYTE
4167 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004168 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 {
4170 /* copy multibyte char */
4171 mch_memmove(s, arg, (size_t)i);
4172 arg += i;
4173 s += i;
4174 }
4175 else
4176#endif
4177 *s++ = *arg++;
4178 }
4179 *s = NUL;
4180
4181 /*
4182 * Expand environment variables and ~.
4183 * Don't do it when adding without inserting a
4184 * comma.
4185 */
4186 if (!(adding || prepending || removing)
4187 || (flags & P_COMMA))
4188 {
4189 s = option_expand(opt_idx, newval);
4190 if (s != NULL)
4191 {
4192 vim_free(newval);
4193 newlen = (unsigned)STRLEN(s) + 1;
4194 if (adding || prepending || removing)
4195 newlen += (unsigned)STRLEN(origval) + 1;
4196 newval = alloc(newlen);
4197 if (newval == NULL)
4198 break;
4199 STRCPY(newval, s);
4200 }
4201 }
4202
4203 /* locate newval[] in origval[] when removing it
4204 * and when adding to avoid duplicates */
4205 i = 0; /* init for GCC */
4206 if (removing || (flags & P_NODUP))
4207 {
4208 i = (int)STRLEN(newval);
4209 bs = 0;
4210 for (s = origval; *s; ++s)
4211 {
4212 if ((!(flags & P_COMMA)
4213 || s == origval
4214 || (s[-1] == ',' && !(bs & 1)))
4215 && STRNCMP(s, newval, i) == 0
4216 && (!(flags & P_COMMA)
4217 || s[i] == ','
4218 || s[i] == NUL))
4219 break;
4220 /* Count backspaces. Only a comma with an
4221 * even number of backspaces before it is
4222 * recognized as a separator */
4223 if (s > origval && s[-1] == '\\')
4224 ++bs;
4225 else
4226 bs = 0;
4227 }
4228
4229 /* do not add if already there */
4230 if ((adding || prepending) && *s)
4231 {
4232 prepending = FALSE;
4233 adding = FALSE;
4234 STRCPY(newval, origval);
4235 }
4236 }
4237
4238 /* concatenate the two strings; add a ',' if
4239 * needed */
4240 if (adding || prepending)
4241 {
4242 comma = ((flags & P_COMMA) && *origval != NUL
4243 && *newval != NUL);
4244 if (adding)
4245 {
4246 i = (int)STRLEN(origval);
4247 mch_memmove(newval + i + comma, newval,
4248 STRLEN(newval) + 1);
4249 mch_memmove(newval, origval, (size_t)i);
4250 }
4251 else
4252 {
4253 i = (int)STRLEN(newval);
4254 mch_memmove(newval + i + comma, origval,
4255 STRLEN(origval) + 1);
4256 }
4257 if (comma)
4258 newval[i] = ',';
4259 }
4260
4261 /* Remove newval[] from origval[]. (Note: "i" has
4262 * been set above and is used here). */
4263 if (removing)
4264 {
4265 STRCPY(newval, origval);
4266 if (*s)
4267 {
4268 /* may need to remove a comma */
4269 if (flags & P_COMMA)
4270 {
4271 if (s == origval)
4272 {
4273 /* include comma after string */
4274 if (s[i] == ',')
4275 ++i;
4276 }
4277 else
4278 {
4279 /* include comma before string */
4280 --s;
4281 ++i;
4282 }
4283 }
4284 mch_memmove(newval + (s - origval), s + i,
4285 STRLEN(s + i) + 1);
4286 }
4287 }
4288
4289 if (flags & P_FLAGLIST)
4290 {
4291 /* Remove flags that appear twice. */
4292 for (s = newval; *s; ++s)
4293 if ((!(flags & P_COMMA) || *s != ',')
4294 && vim_strchr(s + 1, *s) != NULL)
4295 {
4296 STRCPY(s, s + 1);
4297 --s;
4298 }
4299 }
4300
4301 if (save_arg != NULL) /* number for 'whichwrap' */
4302 arg = save_arg;
4303 new_value_alloced = TRUE;
4304 }
4305
4306 /* Set the new value. */
4307 *(char_u **)(varp) = newval;
4308
4309 /* Handle side effects, and set the global value for
4310 * ":set" on local options. */
4311 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4312 new_value_alloced, oldval, errbuf, opt_flags);
4313
4314 /* If error detected, print the error message. */
4315 if (errmsg != NULL)
4316 goto skip;
4317 }
4318 else /* key code option */
4319 {
4320 char_u *p;
4321
4322 if (nextchar == '&')
4323 {
4324 if (add_termcap_entry(key_name, TRUE) == FAIL)
4325 errmsg = (char_u *)N_("E522: Not found in termcap");
4326 }
4327 else
4328 {
4329 ++arg; /* jump to after the '=' or ':' */
4330 for (p = arg; *p && !vim_iswhite(*p); ++p)
4331 if (*p == '\\' && p[1] != NUL)
4332 ++p;
4333 nextchar = *p;
4334 *p = NUL;
4335 add_termcode(key_name, arg, FALSE);
4336 *p = nextchar;
4337 }
4338 if (full_screen)
4339 ttest(FALSE);
4340 redraw_all_later(CLEAR);
4341 }
4342 }
4343 if (opt_idx >= 0)
4344 options[opt_idx].flags |= P_WAS_SET;
4345 }
4346
4347skip:
4348 /*
4349 * Advance to next argument.
4350 * - skip until a blank found, taking care of backslashes
4351 * - skip blanks
4352 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4353 */
4354 for (i = 0; i < 2 ; ++i)
4355 {
4356 while (*arg != NUL && !vim_iswhite(*arg))
4357 if (*arg++ == '\\' && *arg != NUL)
4358 ++arg;
4359 arg = skipwhite(arg);
4360 if (*arg != '=')
4361 break;
4362 }
4363 }
4364
4365 if (errmsg != NULL)
4366 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004367 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368 i = STRLEN(IObuff) + 2;
4369 if (i + (arg - startarg) < IOSIZE)
4370 {
4371 /* append the argument with the error */
4372 STRCAT(IObuff, ": ");
4373 mch_memmove(IObuff + i, startarg, (arg - startarg));
4374 IObuff[i + (arg - startarg)] = NUL;
4375 }
4376 /* make sure all characters are printable */
4377 trans_characters(IObuff, IOSIZE);
4378
4379 ++no_wait_return; /* wait_return done later */
4380 emsg(IObuff); /* show error highlighted */
4381 --no_wait_return;
4382
4383 return FAIL;
4384 }
4385
4386 arg = skipwhite(arg);
4387 }
4388
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004389theend:
4390 if (silent_mode && did_show)
4391 {
4392 /* After displaying option values in silent mode. */
4393 silent_mode = FALSE;
4394 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4395 msg_putchar('\n');
4396 cursor_on(); /* msg_start() switches it off */
4397 out_flush();
4398 silent_mode = TRUE;
4399 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4400 }
4401
Bram Moolenaar071d4272004-06-13 20:20:40 +00004402 return OK;
4403}
4404
4405 static char_u *
4406illegal_char(errbuf, c)
4407 char_u *errbuf;
4408 int c;
4409{
4410 if (errbuf == NULL)
4411 return (char_u *)"";
4412 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004413 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 return errbuf;
4415}
4416
4417/*
4418 * Convert a key name or string into a key value.
4419 * Used for 'wildchar' and 'cedit' options.
4420 */
4421 static int
4422string_to_key(arg)
4423 char_u *arg;
4424{
4425 if (*arg == '<')
4426 return find_key_option(arg + 1);
4427 if (*arg == '^')
4428 return Ctrl_chr(arg[1]);
4429 return *arg;
4430}
4431
4432#ifdef FEAT_CMDWIN
4433/*
4434 * Check value of 'cedit' and set cedit_key.
4435 * Returns NULL if value is OK, error message otherwise.
4436 */
4437 static char_u *
4438check_cedit()
4439{
4440 int n;
4441
4442 if (*p_cedit == NUL)
4443 cedit_key = -1;
4444 else
4445 {
4446 n = string_to_key(p_cedit);
4447 if (vim_isprintc(n))
4448 return e_invarg;
4449 cedit_key = n;
4450 }
4451 return NULL;
4452}
4453#endif
4454
4455#ifdef FEAT_TITLE
4456/*
4457 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4458 * maketitle() to create and display it.
4459 * When switching the title or icon off, call mch_restore_title() to get
4460 * the old value back.
4461 */
4462 static void
4463did_set_title(icon)
4464 int icon; /* Did set icon instead of title */
4465{
4466 if (starting != NO_SCREEN
4467#ifdef FEAT_GUI
4468 && !gui.starting
4469#endif
4470 )
4471 {
4472 maketitle();
4473 if (icon)
4474 {
4475 if (!p_icon)
4476 mch_restore_title(2);
4477 }
4478 else
4479 {
4480 if (!p_title)
4481 mch_restore_title(1);
4482 }
4483 }
4484}
4485#endif
4486
4487/*
4488 * set_options_bin - called when 'bin' changes value.
4489 */
4490 void
4491set_options_bin(oldval, newval, opt_flags)
4492 int oldval;
4493 int newval;
4494 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4495{
4496 /*
4497 * The option values that are changed when 'bin' changes are
4498 * copied when 'bin is set and restored when 'bin' is reset.
4499 */
4500 if (newval)
4501 {
4502 if (!oldval) /* switched on */
4503 {
4504 if (!(opt_flags & OPT_GLOBAL))
4505 {
4506 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4507 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4508 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4509 curbuf->b_p_et_nobin = curbuf->b_p_et;
4510 }
4511 if (!(opt_flags & OPT_LOCAL))
4512 {
4513 p_tw_nobin = p_tw;
4514 p_wm_nobin = p_wm;
4515 p_ml_nobin = p_ml;
4516 p_et_nobin = p_et;
4517 }
4518 }
4519
4520 if (!(opt_flags & OPT_GLOBAL))
4521 {
4522 curbuf->b_p_tw = 0; /* no automatic line wrap */
4523 curbuf->b_p_wm = 0; /* no automatic line wrap */
4524 curbuf->b_p_ml = 0; /* no modelines */
4525 curbuf->b_p_et = 0; /* no expandtab */
4526 }
4527 if (!(opt_flags & OPT_LOCAL))
4528 {
4529 p_tw = 0;
4530 p_wm = 0;
4531 p_ml = FALSE;
4532 p_et = FALSE;
4533 p_bin = TRUE; /* needed when called for the "-b" argument */
4534 }
4535 }
4536 else if (oldval) /* switched off */
4537 {
4538 if (!(opt_flags & OPT_GLOBAL))
4539 {
4540 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4541 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4542 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4543 curbuf->b_p_et = curbuf->b_p_et_nobin;
4544 }
4545 if (!(opt_flags & OPT_LOCAL))
4546 {
4547 p_tw = p_tw_nobin;
4548 p_wm = p_wm_nobin;
4549 p_ml = p_ml_nobin;
4550 p_et = p_et_nobin;
4551 }
4552 }
4553}
4554
4555#ifdef FEAT_VIMINFO
4556/*
4557 * Find the parameter represented by the given character (eg ', :, ", or /),
4558 * and return its associated value in the 'viminfo' string.
4559 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004560 * If the parameter is not specified in the string or there is no following
4561 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 */
4563 int
4564get_viminfo_parameter(type)
4565 int type;
4566{
4567 char_u *p;
4568
4569 p = find_viminfo_parameter(type);
4570 if (p != NULL && VIM_ISDIGIT(*p))
4571 return atoi((char *)p);
4572 return -1;
4573}
4574
4575/*
4576 * Find the parameter represented by the given character (eg ''', ':', '"', or
4577 * '/') in the 'viminfo' option and return a pointer to the string after it.
4578 * Return NULL if the parameter is not specified in the string.
4579 */
4580 char_u *
4581find_viminfo_parameter(type)
4582 int type;
4583{
4584 char_u *p;
4585
4586 for (p = p_viminfo; *p; ++p)
4587 {
4588 if (*p == type)
4589 return p + 1;
4590 if (*p == 'n') /* 'n' is always the last one */
4591 break;
4592 p = vim_strchr(p, ','); /* skip until next ',' */
4593 if (p == NULL) /* hit the end without finding parameter */
4594 break;
4595 }
4596 return NULL;
4597}
4598#endif
4599
4600/*
4601 * Expand environment variables for some string options.
4602 * These string options cannot be indirect!
4603 * If "val" is NULL expand the current value of the option.
4604 * Return pointer to NameBuff, or NULL when not expanded.
4605 */
4606 static char_u *
4607option_expand(opt_idx, val)
4608 int opt_idx;
4609 char_u *val;
4610{
4611 /* if option doesn't need expansion nothing to do */
4612 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4613 return NULL;
4614
4615 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4616 * expand_env() would truncate the string. */
4617 if (val != NULL && STRLEN(val) > MAXPATHL)
4618 return NULL;
4619
4620 if (val == NULL)
4621 val = *(char_u **)options[opt_idx].var;
4622
4623 /*
4624 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4625 * Escape spaces when expanding 'tags', they are used to separate file
4626 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004627 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004628 */
4629 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004630 (char_u **)options[opt_idx].var == &p_tags,
4631#ifdef FEAT_SYN_HL
4632 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4633#endif
4634 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004635 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4636 return NULL;
4637
4638 return NameBuff;
4639}
4640
4641/*
4642 * After setting various option values: recompute variables that depend on
4643 * option values.
4644 */
4645 static void
4646didset_options()
4647{
4648 /* initialize the table for 'iskeyword' et.al. */
4649 (void)init_chartab();
4650
4651 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4652 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4653#ifdef FEAT_SESSION
4654 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4655 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4656#endif
4657#ifdef FEAT_FOLDING
4658 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4659#endif
4660 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4661#ifdef FEAT_VIRTUALEDIT
4662 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4663#endif
4664#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4665 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4666#endif
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004667#ifdef FEAT_SYN_HL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004668 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004669 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004670 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004671#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004672#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4673 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4674#endif
4675#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4676 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4677#endif
4678#ifdef FEAT_CMDWIN
4679 /* set cedit_key */
4680 (void)check_cedit();
4681#endif
4682}
4683
4684/*
4685 * Check for string options that are NULL (normally only termcap options).
4686 */
4687 void
4688check_options()
4689{
4690 int opt_idx;
4691
4692 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4693 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4694 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4695}
4696
4697/*
4698 * Check string options in a buffer for NULL value.
4699 */
4700 void
4701check_buf_options(buf)
4702 buf_T *buf;
4703{
4704#if defined(FEAT_QUICKFIX)
4705 check_string_option(&buf->b_p_bh);
4706 check_string_option(&buf->b_p_bt);
4707#endif
4708#ifdef FEAT_MBYTE
4709 check_string_option(&buf->b_p_fenc);
4710#endif
4711 check_string_option(&buf->b_p_ff);
4712#ifdef FEAT_FIND_ID
4713 check_string_option(&buf->b_p_def);
4714 check_string_option(&buf->b_p_inc);
4715# ifdef FEAT_EVAL
4716 check_string_option(&buf->b_p_inex);
4717# endif
4718#endif
4719#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4720 check_string_option(&buf->b_p_inde);
4721 check_string_option(&buf->b_p_indk);
4722#endif
4723#ifdef FEAT_CRYPT
4724 check_string_option(&buf->b_p_key);
4725#endif
4726 check_string_option(&buf->b_p_kp);
4727 check_string_option(&buf->b_p_mps);
4728 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004729 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004730 check_string_option(&buf->b_p_isk);
4731#ifdef FEAT_COMMENTS
4732 check_string_option(&buf->b_p_com);
4733#endif
4734#ifdef FEAT_FOLDING
4735 check_string_option(&buf->b_p_cms);
4736#endif
4737 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004738#ifdef FEAT_TEXTOBJ
4739 check_string_option(&buf->b_p_qe);
4740#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004741#ifdef FEAT_SYN_HL
4742 check_string_option(&buf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004743 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00004744 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00004745 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004746#endif
4747#ifdef FEAT_SEARCHPATH
4748 check_string_option(&buf->b_p_sua);
4749#endif
4750#ifdef FEAT_CINDENT
4751 check_string_option(&buf->b_p_cink);
4752 check_string_option(&buf->b_p_cino);
4753#endif
4754#ifdef FEAT_AUTOCMD
4755 check_string_option(&buf->b_p_ft);
4756#endif
4757#ifdef FEAT_OSFILETYPE
4758 check_string_option(&buf->b_p_oft);
4759#endif
4760#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4761 check_string_option(&buf->b_p_cinw);
4762#endif
4763#ifdef FEAT_INS_EXPAND
4764 check_string_option(&buf->b_p_cpt);
4765#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004766#ifdef FEAT_COMPL_FUNC
4767 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00004768 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770#ifdef FEAT_KEYMAP
4771 check_string_option(&buf->b_p_keymap);
4772#endif
4773#ifdef FEAT_QUICKFIX
4774 check_string_option(&buf->b_p_gp);
4775 check_string_option(&buf->b_p_mp);
4776 check_string_option(&buf->b_p_efm);
4777#endif
4778 check_string_option(&buf->b_p_ep);
4779 check_string_option(&buf->b_p_path);
4780 check_string_option(&buf->b_p_tags);
4781#ifdef FEAT_INS_EXPAND
4782 check_string_option(&buf->b_p_dict);
4783 check_string_option(&buf->b_p_tsr);
4784#endif
4785}
4786
4787/*
4788 * Free the string allocated for an option.
4789 * Checks for the string being empty_option. This may happen if we're out of
4790 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4791 * check_options().
4792 * Does NOT check for P_ALLOCED flag!
4793 */
4794 void
4795free_string_option(p)
4796 char_u *p;
4797{
4798 if (p != empty_option)
4799 vim_free(p);
4800}
4801
4802 void
4803clear_string_option(pp)
4804 char_u **pp;
4805{
4806 if (*pp != empty_option)
4807 vim_free(*pp);
4808 *pp = empty_option;
4809}
4810
4811 static void
4812check_string_option(pp)
4813 char_u **pp;
4814{
4815 if (*pp == NULL)
4816 *pp = empty_option;
4817}
4818
4819/*
4820 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4821 */
4822 void
4823set_term_option_alloced(p)
4824 char_u **p;
4825{
4826 int opt_idx;
4827
4828 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4829 if (options[opt_idx].var == (char_u *)p)
4830 {
4831 options[opt_idx].flags |= P_ALLOCED;
4832 return;
4833 }
4834 return; /* cannot happen: didn't find it! */
4835}
4836
4837/*
4838 * Set a string option to a new value (without checking the effect).
4839 * The string is copied into allocated memory.
4840 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4841 */
4842 void
4843set_string_option_direct(name, opt_idx, val, opt_flags)
4844 char_u *name;
4845 int opt_idx;
4846 char_u *val;
4847 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4848{
4849 char_u *s;
4850 char_u **varp;
4851 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
4852
4853 if (opt_idx == -1) /* use name */
4854 {
4855 opt_idx = findoption(name);
4856 if (opt_idx == -1) /* not found (should not happen) */
4857 return;
4858 }
4859
4860 if (options[opt_idx].var == NULL) /* can't set hidden option */
4861 return;
4862
4863 s = vim_strsave(val);
4864 if (s != NULL)
4865 {
4866 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4867 both ? OPT_LOCAL : opt_flags);
4868 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
4869 free_string_option(*varp);
4870 *varp = s;
4871
4872 /* For buffer/window local option may also set the global value. */
4873 if (both)
4874 set_string_option_global(opt_idx, varp);
4875
4876 options[opt_idx].flags |= P_ALLOCED;
4877
4878 /* When setting both values of a global option with a local value,
4879 * make the local value empty, so that the global value is used. */
4880 if ((int)options[opt_idx].indir >= PV_BOTH && both)
4881 {
4882 free_string_option(*varp);
4883 *varp = empty_option;
4884 }
4885 }
4886}
4887
4888/*
4889 * Set global value for string option when it's a local option.
4890 */
4891 static void
4892set_string_option_global(opt_idx, varp)
4893 int opt_idx; /* option index */
4894 char_u **varp; /* pointer to option variable */
4895{
4896 char_u **p, *s;
4897
4898 /* the global value is always allocated */
4899 if (options[opt_idx].var == VAR_WIN)
4900 p = (char_u **)GLOBAL_WO(varp);
4901 else
4902 p = (char_u **)options[opt_idx].var;
4903 if (options[opt_idx].indir != PV_NONE
4904 && p != varp
4905 && (s = vim_strsave(*varp)) != NULL)
4906 {
4907 free_string_option(*p);
4908 *p = s;
4909 }
4910}
4911
4912/*
4913 * Set a string option to a new value, and handle the effects.
4914 */
4915 static void
4916set_string_option(opt_idx, value, opt_flags)
4917 int opt_idx;
4918 char_u *value;
4919 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4920{
4921 char_u *s;
4922 char_u **varp;
4923 char_u *oldval;
4924
4925 if (options[opt_idx].var == NULL) /* don't set hidden option */
4926 return;
4927
4928 s = vim_strsave(value);
4929 if (s != NULL)
4930 {
4931 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4932 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4933 ? ((int)options[opt_idx].indir >= PV_BOTH
4934 ? OPT_GLOBAL : OPT_LOCAL)
4935 : opt_flags);
4936 oldval = *varp;
4937 *varp = s;
4938 options[opt_idx].flags |= P_WAS_SET;
4939 (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
4940 opt_flags);
4941 }
4942}
4943
4944/*
4945 * Handle string options that need some action to perform when changed.
4946 * Returns NULL for success, or an error message for an error.
4947 */
4948 static char_u *
4949did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
4950 opt_flags)
4951 int opt_idx; /* index in options[] table */
4952 char_u **varp; /* pointer to the option variable */
4953 int new_value_alloced; /* new value was allocated */
4954 char_u *oldval; /* previous value of the option */
4955 char_u *errbuf; /* buffer for errors, or NULL */
4956 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4957{
4958 char_u *errmsg = NULL;
4959 char_u *s, *p;
4960 int did_chartab = FALSE;
4961 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00004962 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004963
4964 /* Get the global option to compare with, otherwise we would have to check
4965 * two values for all local options. */
4966 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
4967
4968 /* Disallow changing some options from secure mode */
4969 if ((secure
4970#ifdef HAVE_SANDBOX
4971 || sandbox != 0
4972#endif
4973 ) && (options[opt_idx].flags & P_SECURE))
4974 {
4975 errmsg = e_secure;
4976 }
4977
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004978 /* Check for a "normal" file name in some options. Disallow a path
4979 * separator (slash and/or backslash), wildcards and characters that are
4980 * often illegal in a file name. */
4981 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004982 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004983 {
4984 errmsg = e_invarg;
4985 }
4986
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 /* 'term' */
4988 else if (varp == &T_NAME)
4989 {
4990 if (T_NAME[0] == NUL)
4991 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
4992#ifdef FEAT_GUI
4993 if (gui.in_use)
4994 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
4995 else if (term_is_gui(T_NAME))
4996 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
4997#endif
4998 else if (set_termname(T_NAME) == FAIL)
4999 errmsg = (char_u *)N_("E522: Not found in termcap");
5000 else
5001 /* Screen colors may have changed. */
5002 redraw_later_clear();
5003 }
5004
5005 /* 'backupcopy' */
5006 else if (varp == &p_bkc)
5007 {
5008 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5009 errmsg = e_invarg;
5010 if (((bkc_flags & BKC_AUTO) != 0)
5011 + ((bkc_flags & BKC_YES) != 0)
5012 + ((bkc_flags & BKC_NO) != 0) != 1)
5013 {
5014 /* Must have exactly one of "auto", "yes" and "no". */
5015 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5016 errmsg = e_invarg;
5017 }
5018 }
5019
5020 /* 'backupext' and 'patchmode' */
5021 else if (varp == &p_bex || varp == &p_pm)
5022 {
5023 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5024 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5025 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5026 }
5027
5028 /*
5029 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5030 * If the new option is invalid, use old value. 'lisp' option: refill
5031 * chartab[] for '-' char
5032 */
5033 else if ( varp == &p_isi
5034 || varp == &(curbuf->b_p_isk)
5035 || varp == &p_isp
5036 || varp == &p_isf)
5037 {
5038 if (init_chartab() == FAIL)
5039 {
5040 did_chartab = TRUE; /* need to restore it below */
5041 errmsg = e_invarg; /* error in value */
5042 }
5043 }
5044
5045 /* 'helpfile' */
5046 else if (varp == &p_hf)
5047 {
5048 /* May compute new values for $VIM and $VIMRUNTIME */
5049 if (didset_vim)
5050 {
5051 vim_setenv((char_u *)"VIM", (char_u *)"");
5052 didset_vim = FALSE;
5053 }
5054 if (didset_vimruntime)
5055 {
5056 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5057 didset_vimruntime = FALSE;
5058 }
5059 }
5060
5061#ifdef FEAT_MULTI_LANG
5062 /* 'helplang' */
5063 else if (varp == &p_hlg)
5064 {
5065 /* Check for "", "ab", "ab,cd", etc. */
5066 for (s = p_hlg; *s != NUL; s += 3)
5067 {
5068 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5069 {
5070 errmsg = e_invarg;
5071 break;
5072 }
5073 if (s[2] == NUL)
5074 break;
5075 }
5076 }
5077#endif
5078
5079 /* 'highlight' */
5080 else if (varp == &p_hl)
5081 {
5082 if (highlight_changed() == FAIL)
5083 errmsg = e_invarg; /* invalid flags */
5084 }
5085
5086 /* 'nrformats' */
5087 else if (gvarp == &p_nf)
5088 {
5089 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5090 errmsg = e_invarg;
5091 }
5092
5093#ifdef FEAT_SESSION
5094 /* 'sessionoptions' */
5095 else if (varp == &p_ssop)
5096 {
5097 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5098 errmsg = e_invarg;
5099 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5100 {
5101 /* Don't allow both "sesdir" and "curdir". */
5102 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5103 errmsg = e_invarg;
5104 }
5105 }
5106 /* 'viewoptions' */
5107 else if (varp == &p_vop)
5108 {
5109 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5110 errmsg = e_invarg;
5111 }
5112#endif
5113
5114 /* 'scrollopt' */
5115#ifdef FEAT_SCROLLBIND
5116 else if (varp == &p_sbo)
5117 {
5118 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5119 errmsg = e_invarg;
5120 }
5121#endif
5122
5123 /* 'ambiwidth' */
5124#ifdef FEAT_MBYTE
5125 else if (varp == &p_ambw)
5126 {
5127 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5128 errmsg = e_invarg;
5129 }
5130#endif
5131
5132 /* 'background' */
5133 else if (varp == &p_bg)
5134 {
5135 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5136 {
5137#ifdef FEAT_EVAL
5138 int dark = (*p_bg == 'd');
5139#endif
5140
5141 init_highlight(FALSE, FALSE);
5142
5143#ifdef FEAT_EVAL
5144 if (dark != (*p_bg == 'd')
5145 && get_var_value((char_u *)"g:colors_name") != NULL)
5146 {
5147 /* The color scheme must have set 'background' back to another
5148 * value, that's not what we want here. Disable the color
5149 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005150 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005151 free_string_option(p_bg);
5152 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5153 check_string_option(&p_bg);
5154 init_highlight(FALSE, FALSE);
5155 }
5156#endif
5157 }
5158 else
5159 errmsg = e_invarg;
5160 }
5161
5162 /* 'wildmode' */
5163 else if (varp == &p_wim)
5164 {
5165 if (check_opt_wim() == FAIL)
5166 errmsg = e_invarg;
5167 }
5168
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005169#ifdef FEAT_CMDL_COMPL
5170 /* 'wildoptions' */
5171 else if (varp == &p_wop)
5172 {
5173 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5174 errmsg = e_invarg;
5175 }
5176#endif
5177
Bram Moolenaar071d4272004-06-13 20:20:40 +00005178#ifdef FEAT_WAK
5179 /* 'winaltkeys' */
5180 else if (varp == &p_wak)
5181 {
5182 if (*p_wak == NUL
5183 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5184 errmsg = e_invarg;
5185# ifdef FEAT_MENU
5186# ifdef FEAT_GUI_MOTIF
5187 else if (gui.in_use)
5188 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5189# else
5190# ifdef FEAT_GUI_GTK
5191 else if (gui.in_use)
5192 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5193# endif
5194# endif
5195# endif
5196 }
5197#endif
5198
5199#ifdef FEAT_AUTOCMD
5200 /* 'eventignore' */
5201 else if (varp == &p_ei)
5202 {
5203 if (check_ei() == FAIL)
5204 errmsg = e_invarg;
5205 }
5206#endif
5207
5208#ifdef FEAT_MBYTE
5209 /* 'encoding' and 'fileencoding' */
5210 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5211 {
5212 if (gvarp == &p_fenc)
5213 {
5214 if (!curbuf->b_p_ma)
5215 errmsg = e_modifiable;
5216 else if (vim_strchr(*varp, ',') != NULL)
5217 /* No comma allowed in 'fileencoding'; catches confusing it
5218 * with 'fileencodings'. */
5219 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005221 {
5222# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005223 /* May show a "+" in the title now. */
5224 need_maketitle = TRUE;
5225# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005226 /* Add 'fileencoding' to the swap file. */
5227 ml_setflags(curbuf);
5228 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005229 }
5230 if (errmsg == NULL)
5231 {
5232 /* canonize the value, so that STRCMP() can be used on it */
5233 p = enc_canonize(*varp);
5234 if (p != NULL)
5235 {
5236 vim_free(*varp);
5237 *varp = p;
5238 }
5239 if (varp == &p_enc)
5240 {
5241 errmsg = mb_init();
5242# ifdef FEAT_TITLE
5243 need_maketitle = TRUE;
5244# endif
5245 }
5246 }
5247
5248# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5249 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5250 {
5251 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5252 if (STRCMP(p_tenc, "utf-8") != 0)
5253 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5254 }
5255# endif
5256
5257 if (errmsg == NULL)
5258 {
5259# ifdef FEAT_KEYMAP
5260 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5261 * (with another encoding). */
5262 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5263 (void)keymap_init();
5264# endif
5265
5266 /* When 'termencoding' is not empty and 'encoding' changes or when
5267 * 'termencoding' changes, need to setup for keyboard input and
5268 * display output conversion. */
5269 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5270 {
5271 convert_setup(&input_conv, p_tenc, p_enc);
5272 convert_setup(&output_conv, p_enc, p_tenc);
5273 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005274
5275# if defined(WIN3264) && defined(FEAT_MBYTE)
5276 /* $HOME may have characters in active code page. */
5277 if (varp == &p_enc)
5278 init_homedir();
5279# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005280 }
5281 }
5282#endif
5283
5284#if defined(FEAT_POSTSCRIPT)
5285 else if (varp == &p_penc)
5286 {
5287 /* Canonize printencoding if VIM standard one */
5288 p = enc_canonize(p_penc);
5289 if (p != NULL)
5290 {
5291 vim_free(p_penc);
5292 p_penc = p;
5293 }
5294 else
5295 {
5296 /* Ensure lower case and '-' for '_' */
5297 for (s = p_penc; *s != NUL; s++)
5298 {
5299 if (*s == '_')
5300 *s = '-';
5301 else
5302 *s = TOLOWER_ASC(*s);
5303 }
5304 }
5305 }
5306#endif
5307
Bram Moolenaar843ee412004-06-30 16:16:41 +00005308#if defined(FEAT_XIM) && ( defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309 else if (varp == &p_imak)
5310 {
5311 if (gui.in_use && !im_xim_isvalid_imactivate())
5312 errmsg = e_invarg;
5313 }
5314#endif
5315
5316#ifdef FEAT_KEYMAP
5317 else if (varp == &curbuf->b_p_keymap)
5318 {
5319 /* load or unload key mapping tables */
5320 errmsg = keymap_init();
5321
5322 /* When successfully installed a new keymap switch on using it. */
5323 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5324 {
5325 curbuf->b_p_iminsert = B_IMODE_LMAP;
5326 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5327 curbuf->b_p_imsearch = B_IMODE_LMAP;
5328 set_iminsert_global();
5329 set_imsearch_global();
5330# ifdef FEAT_WINDOWS
5331 status_redraw_curbuf();
5332# endif
5333 }
5334 }
5335#endif
5336
5337 /* 'fileformat' */
5338 else if (gvarp == &p_ff)
5339 {
5340 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5341 errmsg = e_modifiable;
5342 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5343 errmsg = e_invarg;
5344 else
5345 {
5346 /* may also change 'textmode' */
5347 if (get_fileformat(curbuf) == EOL_DOS)
5348 curbuf->b_p_tx = TRUE;
5349 else
5350 curbuf->b_p_tx = FALSE;
5351#ifdef FEAT_TITLE
5352 need_maketitle = TRUE;
5353#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005354 /* update flag in swap file */
5355 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356 }
5357 }
5358
5359 /* 'fileformats' */
5360 else if (varp == &p_ffs)
5361 {
5362 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5363 errmsg = e_invarg;
5364 else
5365 {
5366 /* also change 'textauto' */
5367 if (*p_ffs == NUL)
5368 p_ta = FALSE;
5369 else
5370 p_ta = TRUE;
5371 }
5372 }
5373
5374#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5375 /* 'cryptkey' */
5376 else if (gvarp == &p_key)
5377 {
5378 /* Make sure the ":set" command doesn't show the new value in the
5379 * history. */
5380 remove_key_from_history();
5381 }
5382#endif
5383
5384 /* 'matchpairs' */
5385 else if (gvarp == &p_mps)
5386 {
5387 /* Check for "x:y,x:y" */
5388 for (p = *varp; *p != NUL; p += 4)
5389 {
5390 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5391 {
5392 errmsg = e_invarg;
5393 break;
5394 }
5395 if (p[3] == NUL)
5396 break;
5397 }
5398 }
5399
5400#ifdef FEAT_COMMENTS
5401 /* 'comments' */
5402 else if (gvarp == &p_com)
5403 {
5404 for (s = *varp; *s; )
5405 {
5406 while (*s && *s != ':')
5407 {
5408 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5409 && !VIM_ISDIGIT(*s) && *s != '-')
5410 {
5411 errmsg = illegal_char(errbuf, *s);
5412 break;
5413 }
5414 ++s;
5415 }
5416 if (*s++ == NUL)
5417 errmsg = (char_u *)N_("E524: Missing colon");
5418 else if (*s == ',' || *s == NUL)
5419 errmsg = (char_u *)N_("E525: Zero length string");
5420 if (errmsg != NULL)
5421 break;
5422 while (*s && *s != ',')
5423 {
5424 if (*s == '\\' && s[1] != NUL)
5425 ++s;
5426 ++s;
5427 }
5428 s = skip_to_option_part(s);
5429 }
5430 }
5431#endif
5432
5433 /* 'listchars' */
5434 else if (varp == &p_lcs)
5435 {
5436 errmsg = set_chars_option(varp);
5437 }
5438
5439#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5440 /* 'fillchars' */
5441 else if (varp == &p_fcs)
5442 {
5443 errmsg = set_chars_option(varp);
5444 }
5445#endif
5446
5447#ifdef FEAT_CMDWIN
5448 /* 'cedit' */
5449 else if (varp == &p_cedit)
5450 {
5451 errmsg = check_cedit();
5452 }
5453#endif
5454
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005455 /* 'verbosefile' */
5456 else if (varp == &p_vfile)
5457 {
5458 verbose_stop();
5459 if (*p_vfile != NUL && verbose_open() == FAIL)
5460 errmsg = e_invarg;
5461 }
5462
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463#ifdef FEAT_VIMINFO
5464 /* 'viminfo' */
5465 else if (varp == &p_viminfo)
5466 {
5467 for (s = p_viminfo; *s;)
5468 {
5469 /* Check it's a valid character */
5470 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5471 {
5472 errmsg = illegal_char(errbuf, *s);
5473 break;
5474 }
5475 if (*s == 'n') /* name is always last one */
5476 {
5477 break;
5478 }
5479 else if (*s == 'r') /* skip until next ',' */
5480 {
5481 while (*++s && *s != ',')
5482 ;
5483 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005484 else if (*s == '%')
5485 {
5486 /* optional number */
5487 while (vim_isdigit(*++s))
5488 ;
5489 }
5490 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005491 ++s; /* no extra chars */
5492 else /* must have a number */
5493 {
5494 while (vim_isdigit(*++s))
5495 ;
5496
5497 if (!VIM_ISDIGIT(*(s - 1)))
5498 {
5499 if (errbuf != NULL)
5500 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005501 sprintf((char *)errbuf,
5502 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503 transchar_byte(*(s - 1)));
5504 errmsg = errbuf;
5505 }
5506 else
5507 errmsg = (char_u *)"";
5508 break;
5509 }
5510 }
5511 if (*s == ',')
5512 ++s;
5513 else if (*s)
5514 {
5515 if (errbuf != NULL)
5516 errmsg = (char_u *)N_("E527: Missing comma");
5517 else
5518 errmsg = (char_u *)"";
5519 break;
5520 }
5521 }
5522 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5523 errmsg = (char_u *)N_("E528: Must specify a ' value");
5524 }
5525#endif /* FEAT_VIMINFO */
5526
5527 /* terminal options */
5528 else if (istermoption(&options[opt_idx]) && full_screen)
5529 {
5530 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5531 if (varp == &T_CCO)
5532 {
5533 t_colors = atoi((char *)T_CCO);
5534 if (t_colors <= 1)
5535 {
5536 if (new_value_alloced)
5537 vim_free(T_CCO);
5538 T_CCO = empty_option;
5539 }
5540 /* We now have a different color setup, initialize it again. */
5541 init_highlight(TRUE, FALSE);
5542 }
5543 ttest(FALSE);
5544 if (varp == &T_ME)
5545 {
5546 out_str(T_ME);
5547 redraw_later(CLEAR);
5548#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5549 /* Since t_me has been set, this probably means that the user
5550 * wants to use this as default colors. Need to reset default
5551 * background/foreground colors. */
5552 mch_set_normal_colors();
5553#endif
5554 }
5555 }
5556
5557#ifdef FEAT_LINEBREAK
5558 /* 'showbreak' */
5559 else if (varp == &p_sbr)
5560 {
5561 for (s = p_sbr; *s; )
5562 {
5563 if (ptr2cells(s) != 1)
5564 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005565 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566 }
5567 }
5568#endif
5569
5570#ifdef FEAT_GUI
5571 /* 'guifont' */
5572 else if (varp == &p_guifont)
5573 {
5574 if (gui.in_use)
5575 {
5576 p = p_guifont;
Bram Moolenaar843ee412004-06-30 16:16:41 +00005577# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 /*
5579 * Put up a font dialog and let the user select a new value.
5580 * If this is cancelled go back to the old value but don't
5581 * give an error message.
5582 */
5583 if (STRCMP(p, "*") == 0)
5584 {
5585 p = gui_mch_font_dialog(oldval);
5586
5587 if (new_value_alloced)
5588 free_string_option(p_guifont);
5589
5590 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5591 new_value_alloced = TRUE;
5592 }
5593# endif
5594 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5595 {
5596# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5597 if (STRCMP(p_guifont, "*") == 0)
5598 {
5599 /* Dialog was cancelled: Keep the old value without giving
5600 * an error message. */
5601 if (new_value_alloced)
5602 free_string_option(p_guifont);
5603 p_guifont = vim_strsave(oldval);
5604 new_value_alloced = TRUE;
5605 }
5606 else
5607# endif
5608 errmsg = (char_u *)N_("E596: Invalid font(s)");
5609 }
5610 }
5611 }
5612# ifdef FEAT_XFONTSET
5613 else if (varp == &p_guifontset)
5614 {
5615 if (STRCMP(p_guifontset, "*") == 0)
5616 errmsg = (char_u *)N_("E597: can't select fontset");
5617 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5618 errmsg = (char_u *)N_("E598: Invalid fontset");
5619 }
5620# endif
5621# ifdef FEAT_MBYTE
5622 else if (varp == &p_guifontwide)
5623 {
5624 if (STRCMP(p_guifontwide, "*") == 0)
5625 errmsg = (char_u *)N_("E533: can't select wide font");
5626 else if (gui_get_wide_font() == FAIL)
5627 errmsg = (char_u *)N_("E534: Invalid wide font");
5628 }
5629# endif
5630#endif
5631
5632#ifdef CURSOR_SHAPE
5633 /* 'guicursor' */
5634 else if (varp == &p_guicursor)
5635 errmsg = parse_shape_opt(SHAPE_CURSOR);
5636#endif
5637
5638#ifdef FEAT_MOUSESHAPE
5639 /* 'mouseshape' */
5640 else if (varp == &p_mouseshape)
5641 {
5642 errmsg = parse_shape_opt(SHAPE_MOUSE);
5643 update_mouseshape(-1);
5644 }
5645#endif
5646
5647#ifdef FEAT_PRINTER
5648 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005649 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005650# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005651 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005652 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00005653# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654#endif
5655
5656#ifdef FEAT_LANGMAP
5657 /* 'langmap' */
5658 else if (varp == &p_langmap)
5659 langmap_set();
5660#endif
5661
5662#ifdef FEAT_LINEBREAK
5663 /* 'breakat' */
5664 else if (varp == &p_breakat)
5665 fill_breakat_flags();
5666#endif
5667
5668#ifdef FEAT_TITLE
5669 /* 'titlestring' and 'iconstring' */
5670 else if (varp == &p_titlestring || varp == &p_iconstring)
5671 {
5672# ifdef FEAT_STL_OPT
5673 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5674
5675 /* NULL => statusline syntax */
5676 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5677 stl_syntax |= flagval;
5678 else
5679 stl_syntax &= ~flagval;
5680# endif
5681 did_set_title(varp == &p_iconstring);
5682
5683 }
5684#endif
5685
5686#ifdef FEAT_GUI
5687 /* 'guioptions' */
5688 else if (varp == &p_go)
5689 gui_init_which_components(oldval);
5690#endif
5691
5692#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5693 /* 'ttymouse' */
5694 else if (varp == &p_ttym)
5695 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00005696 /* Switch the mouse off before changing the escape sequences used for
5697 * that. */
5698 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5700 errmsg = e_invarg;
5701 else
5702 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00005703 if (termcap_active)
5704 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705 }
5706#endif
5707
5708#ifdef FEAT_VISUAL
5709 /* 'selection' */
5710 else if (varp == &p_sel)
5711 {
5712 if (*p_sel == NUL
5713 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5714 errmsg = e_invarg;
5715 }
5716
5717 /* 'selectmode' */
5718 else if (varp == &p_slm)
5719 {
5720 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5721 errmsg = e_invarg;
5722 }
5723#endif
5724
5725#ifdef FEAT_BROWSE
5726 /* 'browsedir' */
5727 else if (varp == &p_bsdir)
5728 {
5729 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5730 && !mch_isdir(p_bsdir))
5731 errmsg = e_invarg;
5732 }
5733#endif
5734
5735#ifdef FEAT_VISUAL
5736 /* 'keymodel' */
5737 else if (varp == &p_km)
5738 {
5739 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5740 errmsg = e_invarg;
5741 else
5742 {
5743 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5744 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5745 }
5746 }
5747#endif
5748
5749 /* 'mousemodel' */
5750 else if (varp == &p_mousem)
5751 {
5752 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5753 errmsg = e_invarg;
5754#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5755 else if (*p_mousem != *oldval)
5756 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5757 * to create or delete the popup menus. */
5758 gui_motif_update_mousemodel(root_menu);
5759#endif
5760 }
5761
5762 /* 'switchbuf' */
5763 else if (varp == &p_swb)
5764 {
5765 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5766 errmsg = e_invarg;
5767 }
5768
5769 /* 'debug' */
5770 else if (varp == &p_debug)
5771 {
5772 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5773 errmsg = e_invarg;
5774 }
5775
5776 /* 'display' */
5777 else if (varp == &p_dy)
5778 {
5779 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5780 errmsg = e_invarg;
5781 else
5782 (void)init_chartab();
5783
5784 }
5785
5786#ifdef FEAT_VERTSPLIT
5787 /* 'eadirection' */
5788 else if (varp == &p_ead)
5789 {
5790 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5791 errmsg = e_invarg;
5792 }
5793#endif
5794
5795#ifdef FEAT_CLIPBOARD
5796 /* 'clipboard' */
5797 else if (varp == &p_cb)
5798 errmsg = check_clipboard_option();
5799#endif
5800
Bram Moolenaar217ad922005-03-20 22:37:15 +00005801#ifdef FEAT_SYN_HL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005802 /* When 'spelllang' or 'spellfile' is set and there is a window for this
5803 * buffer in which 'spell' is set load the wordlists. */
5804 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00005805 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005806 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005807 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005808
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005809 if (varp == &(curbuf->b_p_spf))
5810 {
5811 l = STRLEN(curbuf->b_p_spf);
5812 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
5813 ".add") != 0))
5814 errmsg = e_invarg;
5815 }
5816
5817 if (errmsg == NULL)
5818 {
5819 FOR_ALL_WINDOWS(wp)
5820 if (wp->w_buffer == curbuf && wp->w_p_spell)
5821 {
5822 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005823# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005824 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005825# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005826 }
5827 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005828 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005829 /* When 'spellcapcheck' is set compile the regexp program. */
5830 else if (varp == &(curbuf->b_p_spc))
5831 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005832 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005833 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005834 /* 'spellsuggest' */
5835 else if (varp == &p_sps)
5836 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005837 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005838 errmsg = e_invarg;
5839 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005840 /* 'mkspellmem' */
5841 else if (varp == &p_msm)
5842 {
5843 if (spell_check_msm() != OK)
5844 errmsg = e_invarg;
5845 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005846#endif
5847
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848#ifdef FEAT_QUICKFIX
5849 /* When 'bufhidden' is set, check for valid value. */
5850 else if (gvarp == &p_bh)
5851 {
5852 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5853 errmsg = e_invarg;
5854 }
5855
5856 /* When 'buftype' is set, check for valid value. */
5857 else if (gvarp == &p_bt)
5858 {
5859 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5860 errmsg = e_invarg;
5861 else
5862 {
5863# ifdef FEAT_WINDOWS
5864 if (curwin->w_status_height)
5865 {
5866 curwin->w_redr_status = TRUE;
5867 redraw_later(VALID);
5868 }
5869# endif
5870 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5871 }
5872 }
5873#endif
5874
5875#ifdef FEAT_STL_OPT
5876 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005877 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878 {
5879 int wid;
5880
5881 if (varp == &p_ruf) /* reset ru_wid first */
5882 ru_wid = 0;
5883 s = *varp;
5884 if (varp == &p_ruf && *s == '%')
5885 {
5886 /* set ru_wid if 'ruf' starts with "%99(" */
5887 if (*++s == '-') /* ignore a '-' */
5888 s++;
5889 wid = getdigits(&s);
5890 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5891 ru_wid = wid;
5892 else
5893 errmsg = check_stl_option(p_ruf);
5894 }
5895 else
5896 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005897 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 comp_col();
5899 }
5900#endif
5901
5902#ifdef FEAT_INS_EXPAND
5903 /* check if it is a valid value for 'complete' -- Acevedo */
5904 else if (gvarp == &p_cpt)
5905 {
5906 for (s = *varp; *s;)
5907 {
5908 while(*s == ',' || *s == ' ')
5909 s++;
5910 if (!*s)
5911 break;
5912 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5913 {
5914 errmsg = illegal_char(errbuf, *s);
5915 break;
5916 }
5917 if (*++s != NUL && *s != ',' && *s != ' ')
5918 {
5919 if (s[-1] == 'k' || s[-1] == 's')
5920 {
5921 /* skip optional filename after 'k' and 's' */
5922 while (*s && *s != ',' && *s != ' ')
5923 {
5924 if (*s == '\\')
5925 ++s;
5926 ++s;
5927 }
5928 }
5929 else
5930 {
5931 if (errbuf != NULL)
5932 {
5933 sprintf((char *)errbuf,
5934 _("E535: Illegal character after <%c>"),
5935 *--s);
5936 errmsg = errbuf;
5937 }
5938 else
5939 errmsg = (char_u *)"";
5940 break;
5941 }
5942 }
5943 }
5944 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00005945
5946 /* 'completeopt' */
5947 else if (varp == &p_cot)
5948 {
5949 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
5950 errmsg = e_invarg;
5951 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005952#endif /* FEAT_INS_EXPAND */
5953
5954
5955#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5956 else if (varp == &p_toolbar)
5957 {
5958 if (opt_strings_flags(p_toolbar, p_toolbar_values,
5959 &toolbar_flags, TRUE) != OK)
5960 errmsg = e_invarg;
5961 else
5962 {
5963 out_flush();
5964 gui_mch_show_toolbar((toolbar_flags &
5965 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5966 }
5967 }
5968#endif
5969
5970#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5971 /* 'toolbariconsize': GTK+ 2 only */
5972 else if (varp == &p_tbis)
5973 {
5974 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
5975 errmsg = e_invarg;
5976 else
5977 {
5978 out_flush();
5979 gui_mch_show_toolbar((toolbar_flags &
5980 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5981 }
5982 }
5983#endif
5984
5985 /* 'pastetoggle': translate key codes like in a mapping */
5986 else if (varp == &p_pt)
5987 {
5988 if (*p_pt)
5989 {
5990 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
5991 if (p != NULL)
5992 {
5993 if (new_value_alloced)
5994 free_string_option(p_pt);
5995 p_pt = p;
5996 new_value_alloced = TRUE;
5997 }
5998 }
5999 }
6000
6001 /* 'backspace' */
6002 else if (varp == &p_bs)
6003 {
6004 if (VIM_ISDIGIT(*p_bs))
6005 {
6006 if (*p_bs >'2' || p_bs[1] != NUL)
6007 errmsg = e_invarg;
6008 }
6009 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6010 errmsg = e_invarg;
6011 }
6012
6013 /* 'casemap' */
6014 else if (varp == &p_cmp)
6015 {
6016 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6017 errmsg = e_invarg;
6018 }
6019
6020#ifdef FEAT_DIFF
6021 /* 'diffopt' */
6022 else if (varp == &p_dip)
6023 {
6024 if (diffopt_changed() == FAIL)
6025 errmsg = e_invarg;
6026 }
6027#endif
6028
6029#ifdef FEAT_FOLDING
6030 /* 'foldmethod' */
6031 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6032 {
6033 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6034 || *curwin->w_p_fdm == NUL)
6035 errmsg = e_invarg;
6036 else
6037 foldUpdateAll(curwin);
6038 }
6039# ifdef FEAT_EVAL
6040 /* 'foldexpr' */
6041 else if (varp == &curwin->w_p_fde)
6042 {
6043 if (foldmethodIsExpr(curwin))
6044 foldUpdateAll(curwin);
6045 }
6046# endif
6047 /* 'foldmarker' */
6048 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6049 {
6050 p = vim_strchr(*varp, ',');
6051 if (p == NULL)
6052 errmsg = (char_u *)N_("E536: comma required");
6053 else if (p == *varp || p[1] == NUL)
6054 errmsg = e_invarg;
6055 else if (foldmethodIsMarker(curwin))
6056 foldUpdateAll(curwin);
6057 }
6058 /* 'commentstring' */
6059 else if (gvarp == &p_cms)
6060 {
6061 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6062 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6063 }
6064 /* 'foldopen' */
6065 else if (varp == &p_fdo)
6066 {
6067 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6068 errmsg = e_invarg;
6069 }
6070 /* 'foldclose' */
6071 else if (varp == &p_fcl)
6072 {
6073 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6074 errmsg = e_invarg;
6075 }
6076#endif
6077
6078#ifdef FEAT_VIRTUALEDIT
6079 /* 'virtualedit' */
6080 else if (varp == &p_ve)
6081 {
6082 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6083 errmsg = e_invarg;
6084 else if (STRCMP(p_ve, oldval) != 0)
6085 {
6086 /* Recompute cursor position in case the new 've' setting
6087 * changes something. */
6088 validate_virtcol();
6089 coladvance(curwin->w_virtcol);
6090 }
6091 }
6092#endif
6093
6094#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6095 else if (varp == &p_csqf)
6096 {
6097 if (p_csqf != NULL)
6098 {
6099 p = p_csqf;
6100 while (*p != NUL)
6101 {
6102 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6103 || p[1] == NUL
6104 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6105 || (p[2] != NUL && p[2] != ','))
6106 {
6107 errmsg = e_invarg;
6108 break;
6109 }
6110 else if (p[2] == NUL)
6111 break;
6112 else
6113 p += 3;
6114 }
6115 }
6116 }
6117#endif
6118
6119 /* Options that are a list of flags. */
6120 else
6121 {
6122 p = NULL;
6123 if (varp == &p_ww)
6124 p = (char_u *)WW_ALL;
6125 if (varp == &p_shm)
6126 p = (char_u *)SHM_ALL;
6127 else if (varp == &(p_cpo))
6128 p = (char_u *)CPO_ALL;
6129 else if (varp == &(curbuf->b_p_fo))
6130 p = (char_u *)FO_ALL;
6131 else if (varp == &p_mouse)
6132 {
6133#ifdef FEAT_MOUSE
6134 p = (char_u *)MOUSE_ALL;
6135#else
6136 if (*p_mouse != NUL)
6137 errmsg = (char_u *)N_("E538: No mouse support");
6138#endif
6139 }
6140#if defined(FEAT_GUI)
6141 else if (varp == &p_go)
6142 p = (char_u *)GO_ALL;
6143#endif
6144 if (p != NULL)
6145 {
6146 for (s = *varp; *s; ++s)
6147 if (vim_strchr(p, *s) == NULL)
6148 {
6149 errmsg = illegal_char(errbuf, *s);
6150 break;
6151 }
6152 }
6153 }
6154
6155 /*
6156 * If error detected, restore the previous value.
6157 */
6158 if (errmsg != NULL)
6159 {
6160 if (new_value_alloced)
6161 free_string_option(*varp);
6162 *varp = oldval;
6163 /*
6164 * When resetting some values, need to act on it.
6165 */
6166 if (did_chartab)
6167 (void)init_chartab();
6168 if (varp == &p_hl)
6169 (void)highlight_changed();
6170 }
6171 else
6172 {
6173#ifdef FEAT_EVAL
6174 /* Remember where the option was set. */
6175 options[opt_idx].scriptID = current_SID;
6176#endif
6177 /*
6178 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006179 * Use "free_oldval", because recursiveness may change the flags under
6180 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006181 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006182 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006183 free_string_option(oldval);
6184 if (new_value_alloced)
6185 options[opt_idx].flags |= P_ALLOCED;
6186 else
6187 options[opt_idx].flags &= ~P_ALLOCED;
6188
6189 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6190 && (int)options[opt_idx].indir >= PV_BOTH)
6191 {
6192 /* global option with local value set to use global value; free
6193 * the local value and make it empty */
6194 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6195 free_string_option(*(char_u **)p);
6196 *(char_u **)p = empty_option;
6197 }
6198
6199 /* May set global value for local option. */
6200 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6201 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006202
6203#ifdef FEAT_AUTOCMD
6204 /*
6205 * Trigger the autocommand only after setting the flags.
6206 */
6207# ifdef FEAT_SYN_HL
6208 /* When 'syntax' is set, load the syntax of that name */
6209 if (varp == &(curbuf->b_p_syn))
6210 {
6211 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6212 curbuf->b_fname, TRUE, curbuf);
6213 }
6214# endif
6215 else if (varp == &(curbuf->b_p_ft))
6216 {
6217 /* 'filetype' is set, trigger the FileType autocommand */
6218 did_filetype = TRUE;
6219 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6220 curbuf->b_fname, TRUE, curbuf);
6221 }
6222#endif
6223#ifdef FEAT_SYN_HL
6224 if (varp == &(curbuf->b_p_spl))
6225 {
6226 char_u fname[200];
6227
6228 /*
6229 * Source the spell/LANG.vim in 'runtimepath'.
6230 * They could set 'spellcapcheck' depending on the language.
6231 * Use the first name in 'spelllang' up to '_region' or
6232 * '.encoding'.
6233 */
6234 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6235 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6236 break;
6237 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6238 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6239 source_runtime(fname, TRUE);
6240 }
6241#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006242 }
6243
6244#ifdef FEAT_MOUSE
6245 if (varp == &p_mouse)
6246 {
6247# ifdef FEAT_MOUSE_TTY
6248 if (*p_mouse == NUL)
6249 mch_setmouse(FALSE); /* switch mouse off */
6250 else
6251# endif
6252 setmouse(); /* in case 'mouse' changed */
6253 }
6254#endif
6255
6256 if (curwin->w_curswant != MAXCOL)
6257 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6258 check_redraw(options[opt_idx].flags);
6259
6260 return errmsg;
6261}
6262
6263/*
6264 * Handle setting 'listchars' or 'fillchars'.
6265 * Returns error message, NULL if it's OK.
6266 */
6267 static char_u *
6268set_chars_option(varp)
6269 char_u **varp;
6270{
6271 int round, i, len, entries;
6272 char_u *p, *s;
6273 int c1, c2 = 0;
6274 struct charstab
6275 {
6276 int *cp;
6277 char *name;
6278 };
6279#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6280 static struct charstab filltab[] =
6281 {
6282 {&fill_stl, "stl"},
6283 {&fill_stlnc, "stlnc"},
6284 {&fill_vert, "vert"},
6285 {&fill_fold, "fold"},
6286 {&fill_diff, "diff"},
6287 };
6288#endif
6289 static struct charstab lcstab[] =
6290 {
6291 {&lcs_eol, "eol"},
6292 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006293 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006294 {&lcs_prec, "precedes"},
6295 {&lcs_tab2, "tab"},
6296 {&lcs_trail, "trail"},
6297 };
6298 struct charstab *tab;
6299
6300#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6301 if (varp == &p_lcs)
6302#endif
6303 {
6304 tab = lcstab;
6305 entries = sizeof(lcstab) / sizeof(struct charstab);
6306 }
6307#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6308 else
6309 {
6310 tab = filltab;
6311 entries = sizeof(filltab) / sizeof(struct charstab);
6312 }
6313#endif
6314
6315 /* first round: check for valid value, second round: assign values */
6316 for (round = 0; round <= 1; ++round)
6317 {
6318 if (round)
6319 {
6320 /* After checking that the value is valid: set defaults: space for
6321 * 'fillchars', NUL for 'listchars' */
6322 for (i = 0; i < entries; ++i)
6323 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6324 if (varp == &p_lcs)
6325 lcs_tab1 = NUL;
6326#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6327 else
6328 fill_diff = '-';
6329#endif
6330 }
6331 p = *varp;
6332 while (*p)
6333 {
6334 for (i = 0; i < entries; ++i)
6335 {
6336 len = (int)STRLEN(tab[i].name);
6337 if (STRNCMP(p, tab[i].name, len) == 0
6338 && p[len] == ':'
6339 && p[len + 1] != NUL)
6340 {
6341 s = p + len + 1;
6342#ifdef FEAT_MBYTE
6343 c1 = mb_ptr2char_adv(&s);
6344#else
6345 c1 = *s++;
6346#endif
6347 if (tab[i].cp == &lcs_tab2)
6348 {
6349 if (*s == NUL)
6350 continue;
6351#ifdef FEAT_MBYTE
6352 c2 = mb_ptr2char_adv(&s);
6353#else
6354 c2 = *s++;
6355#endif
6356 }
6357 if (*s == ',' || *s == NUL)
6358 {
6359 if (round)
6360 {
6361 if (tab[i].cp == &lcs_tab2)
6362 {
6363 lcs_tab1 = c1;
6364 lcs_tab2 = c2;
6365 }
6366 else
6367 *(tab[i].cp) = c1;
6368
6369 }
6370 p = s;
6371 break;
6372 }
6373 }
6374 }
6375
6376 if (i == entries)
6377 return e_invarg;
6378 if (*p == ',')
6379 ++p;
6380 }
6381 }
6382
6383 return NULL; /* no error */
6384}
6385
6386#ifdef FEAT_STL_OPT
6387/*
6388 * Check validity of options with the 'statusline' format.
6389 * Return error message or NULL.
6390 */
6391 char_u *
6392check_stl_option(s)
6393 char_u *s;
6394{
6395 int itemcnt = 0;
6396 int groupdepth = 0;
6397 static char_u errbuf[80];
6398
6399 while (*s && itemcnt < STL_MAX_ITEM)
6400 {
6401 /* Check for valid keys after % sequences */
6402 while (*s && *s != '%')
6403 s++;
6404 if (!*s)
6405 break;
6406 s++;
6407 if (*s != '%' && *s != ')')
6408 ++itemcnt;
6409 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6410 {
6411 s++;
6412 continue;
6413 }
6414 if (*s == ')')
6415 {
6416 s++;
6417 if (--groupdepth < 0)
6418 break;
6419 continue;
6420 }
6421 if (*s == '-')
6422 s++;
6423 while (VIM_ISDIGIT(*s))
6424 s++;
6425 if (*s == STL_HIGHLIGHT)
6426 continue;
6427 if (*s == '.')
6428 {
6429 s++;
6430 while (*s && VIM_ISDIGIT(*s))
6431 s++;
6432 }
6433 if (*s == '(')
6434 {
6435 groupdepth++;
6436 continue;
6437 }
6438 if (vim_strchr(STL_ALL, *s) == NULL)
6439 {
6440 return illegal_char(errbuf, *s);
6441 }
6442 if (*s == '{')
6443 {
6444 s++;
6445 while (*s != '}' && *s)
6446 s++;
6447 if (*s != '}')
6448 return (char_u *)N_("E540: Unclosed expression sequence");
6449 }
6450 }
6451 if (itemcnt >= STL_MAX_ITEM)
6452 return (char_u *)N_("E541: too many items");
6453 if (groupdepth != 0)
6454 return (char_u *)N_("E542: unbalanced groups");
6455 return NULL;
6456}
6457#endif
6458
6459#ifdef FEAT_CLIPBOARD
6460/*
6461 * Extract the items in the 'clipboard' option and set global values.
6462 */
6463 static char_u *
6464check_clipboard_option()
6465{
6466 int new_unnamed = FALSE;
6467 int new_autoselect = FALSE;
6468 int new_autoselectml = FALSE;
6469 regprog_T *new_exclude_prog = NULL;
6470 char_u *errmsg = NULL;
6471 char_u *p;
6472
6473 for (p = p_cb; *p != NUL; )
6474 {
6475 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6476 {
6477 new_unnamed = TRUE;
6478 p += 7;
6479 }
6480 else if (STRNCMP(p, "autoselect", 10) == 0
6481 && (p[10] == ',' || p[10] == NUL))
6482 {
6483 new_autoselect = TRUE;
6484 p += 10;
6485 }
6486 else if (STRNCMP(p, "autoselectml", 12) == 0
6487 && (p[12] == ',' || p[12] == NUL))
6488 {
6489 new_autoselectml = TRUE;
6490 p += 12;
6491 }
6492 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6493 {
6494 p += 8;
6495 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6496 if (new_exclude_prog == NULL)
6497 errmsg = e_invarg;
6498 break;
6499 }
6500 else
6501 {
6502 errmsg = e_invarg;
6503 break;
6504 }
6505 if (*p == ',')
6506 ++p;
6507 }
6508 if (errmsg == NULL)
6509 {
6510 clip_unnamed = new_unnamed;
6511 clip_autoselect = new_autoselect;
6512 clip_autoselectml = new_autoselectml;
6513 vim_free(clip_exclude_prog);
6514 clip_exclude_prog = new_exclude_prog;
6515 }
6516 else
6517 vim_free(new_exclude_prog);
6518
6519 return errmsg;
6520}
6521#endif
6522
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006523#ifdef FEAT_SYN_HL
6524/*
6525 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6526 * Return error message when failed, NULL when OK.
6527 */
6528 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006529compile_cap_prog(buf)
6530 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006531{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006532 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006533
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006534 if (*buf->b_p_spc == NUL)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006535 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006536 buf->b_cap_prog = NULL;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006537 vim_free(rp);
6538 return NULL;
6539 }
6540
6541 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006542 vim_snprintf((char *)IObuff, IOSIZE, "^%s", buf->b_p_spc);
6543 buf->b_cap_prog = vim_regcomp(IObuff, RE_MAGIC);
6544 if (buf->b_cap_prog == NULL)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006545 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006546 buf->b_cap_prog = rp;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006547 return e_invarg;
6548 }
6549
6550 vim_free(rp);
6551 return NULL;
6552}
6553#endif
6554
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555/*
6556 * Set the value of a boolean option, and take care of side effects.
6557 * Returns NULL for success, or an error message for an error.
6558 */
6559 static char_u *
6560set_bool_option(opt_idx, varp, value, opt_flags)
6561 int opt_idx; /* index in options[] table */
6562 char_u *varp; /* pointer to the option variable */
6563 int value; /* new value */
6564 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6565{
6566 int old_value = *(int *)varp;
6567
6568#ifdef FEAT_GUI
6569 need_mouse_correct = TRUE;
6570#endif
6571
6572 /* Disallow changing some options from secure mode */
6573 if ((secure
6574#ifdef HAVE_SANDBOX
6575 || sandbox != 0
6576#endif
6577 ) && (options[opt_idx].flags & P_SECURE))
6578 return e_secure;
6579
6580 *(int *)varp = value; /* set the new value */
6581#ifdef FEAT_EVAL
6582 /* Remember where the option was set. */
6583 options[opt_idx].scriptID = current_SID;
6584#endif
6585
6586 /* May set global value for local option. */
6587 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6588 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6589
6590 /*
6591 * Handle side effects of changing a bool option.
6592 */
6593
6594 /* 'compatible' */
6595 if ((int *)varp == &p_cp)
6596 {
6597 compatible_set();
6598 }
6599
Bram Moolenaar071d4272004-06-13 20:20:40 +00006600 else if ((int *)varp == &curbuf->b_p_ro)
6601 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006602 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006603 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6604 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006605
6606 /* when 'readonly' is set may give W10 again */
6607 if (curbuf->b_p_ro)
6608 curbuf->b_did_warn = FALSE;
6609
Bram Moolenaar071d4272004-06-13 20:20:40 +00006610#ifdef FEAT_TITLE
6611 need_maketitle = TRUE;
6612#endif
6613 }
6614
6615#ifdef FEAT_TITLE
6616 /* when 'modifiable' is changed, redraw the window title */
6617 else if ((int *)varp == &curbuf->b_p_ma)
6618 need_maketitle = TRUE;
6619 /* when 'endofline' is changed, redraw the window title */
6620 else if ((int *)varp == &curbuf->b_p_eol)
6621 need_maketitle = TRUE;
6622#endif
6623
6624 /* when 'bin' is set also set some other options */
6625 else if ((int *)varp == &curbuf->b_p_bin)
6626 {
6627 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6628#ifdef FEAT_TITLE
6629 need_maketitle = TRUE;
6630#endif
6631 }
6632
6633#ifdef FEAT_AUTOCMD
6634 /* when 'buflisted' changes, trigger autocommands */
6635 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6636 {
6637 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6638 NULL, NULL, TRUE, curbuf);
6639 }
6640#endif
6641
6642 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6643 else if ((int *)varp == &curbuf->b_p_swf)
6644 {
6645 if (curbuf->b_p_swf && p_uc)
6646 ml_open_file(curbuf); /* create the swap file */
6647 else
6648 mf_close_file(curbuf, TRUE); /* remove the swap file */
6649 }
6650
6651 /* when 'terse' is set change 'shortmess' */
6652 else if ((int *)varp == &p_terse)
6653 {
6654 char_u *p;
6655
6656 p = vim_strchr(p_shm, SHM_SEARCH);
6657
6658 /* insert 's' in p_shm */
6659 if (p_terse && p == NULL)
6660 {
6661 STRCPY(IObuff, p_shm);
6662 STRCAT(IObuff, "s");
6663 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6664 }
6665 /* remove 's' from p_shm */
6666 else if (!p_terse && p != NULL)
6667 mch_memmove(p, p + 1, STRLEN(p));
6668 }
6669
6670 /* when 'paste' is set or reset also change other options */
6671 else if ((int *)varp == &p_paste)
6672 {
6673 paste_option_changed();
6674 }
6675
6676 /* when 'insertmode' is set from an autocommand need to do work here */
6677 else if ((int *)varp == &p_im)
6678 {
6679 if (p_im)
6680 {
6681 if ((State & INSERT) == 0)
6682 need_start_insertmode = TRUE;
6683 stop_insert_mode = FALSE;
6684 }
6685 else
6686 {
6687 need_start_insertmode = FALSE;
6688 stop_insert_mode = TRUE;
6689 if (p_smd && restart_edit != 0)
6690 clear_cmdline = TRUE; /* remove "(insert)" */
6691 restart_edit = 0;
6692 }
6693 }
6694
6695 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6696 else if ((int *)varp == &p_ic && p_hls)
6697 {
6698 redraw_all_later(NOT_VALID);
6699 }
6700
6701#ifdef FEAT_SEARCH_EXTRA
6702 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6703 else if ((int *)varp == &p_hls)
6704 {
6705 no_hlsearch = FALSE;
6706 }
6707#endif
6708
6709#ifdef FEAT_SCROLLBIND
6710 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6711 * at the end of normal_cmd() */
6712 else if ((int *)varp == &curwin->w_p_scb)
6713 {
6714 if (curwin->w_p_scb)
6715 do_check_scrollbind(FALSE);
6716 }
6717#endif
6718
6719#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6720 /* There can be only one window with 'previewwindow' set. */
6721 else if ((int *)varp == &curwin->w_p_pvw)
6722 {
6723 if (curwin->w_p_pvw)
6724 {
6725 win_T *win;
6726
6727 for (win = firstwin; win != NULL; win = win->w_next)
6728 if (win->w_p_pvw && win != curwin)
6729 {
6730 curwin->w_p_pvw = FALSE;
6731 return (char_u *)N_("E590: A preview window already exists");
6732 }
6733 }
6734 }
6735#endif
6736
6737 /* when 'textmode' is set or reset also change 'fileformat' */
6738 else if ((int *)varp == &curbuf->b_p_tx)
6739 {
6740 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6741 }
6742
6743 /* when 'textauto' is set or reset also change 'fileformats' */
6744 else if ((int *)varp == &p_ta)
6745 {
6746 set_string_option_direct((char_u *)"ffs", -1,
6747 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6748 OPT_FREE | opt_flags);
6749 }
6750
6751 /*
6752 * When 'lisp' option changes include/exclude '-' in
6753 * keyword characters.
6754 */
6755#ifdef FEAT_LISP
6756 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6757 {
6758 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6759 }
6760#endif
6761
6762#ifdef FEAT_TITLE
6763 /* when 'title' changed, may need to change the title; same for 'icon' */
6764 else if ((int *)varp == &p_title)
6765 {
6766 did_set_title(FALSE);
6767 }
6768
6769 else if ((int *)varp == &p_icon)
6770 {
6771 did_set_title(TRUE);
6772 }
6773#endif
6774
6775 else if ((int *)varp == &curbuf->b_changed)
6776 {
6777 if (!value)
6778 save_file_ff(curbuf); /* Buffer is unchanged */
6779#ifdef FEAT_TITLE
6780 need_maketitle = TRUE;
6781#endif
6782#ifdef FEAT_AUTOCMD
6783 modified_was_set = value;
6784#endif
6785 }
6786
6787#ifdef BACKSLASH_IN_FILENAME
6788 else if ((int *)varp == &p_ssl)
6789 {
6790 if (p_ssl)
6791 {
6792 psepc = '/';
6793 psepcN = '\\';
6794 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 }
6796 else
6797 {
6798 psepc = '\\';
6799 psepcN = '/';
6800 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 }
6802
6803 /* need to adjust the file name arguments and buffer names. */
6804 buflist_slash_adjust();
6805 alist_slash_adjust();
6806# ifdef FEAT_EVAL
6807 scriptnames_slash_adjust();
6808# endif
6809 }
6810#endif
6811
6812 /* If 'wrap' is set, set w_leftcol to zero. */
6813 else if ((int *)varp == &curwin->w_p_wrap)
6814 {
6815 if (curwin->w_p_wrap)
6816 curwin->w_leftcol = 0;
6817 }
6818
6819#ifdef FEAT_WINDOWS
6820 else if ((int *)varp == &p_ea)
6821 {
6822 if (p_ea && !old_value)
6823 win_equal(curwin, FALSE, 0);
6824 }
6825#endif
6826
6827 else if ((int *)varp == &p_wiv)
6828 {
6829 /*
6830 * When 'weirdinvert' changed, set/reset 't_xs'.
6831 * Then set 'weirdinvert' according to value of 't_xs'.
6832 */
6833 if (p_wiv && !old_value)
6834 T_XS = (char_u *)"y";
6835 else if (!p_wiv && old_value)
6836 T_XS = empty_option;
6837 p_wiv = (*T_XS != NUL);
6838 }
6839
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006840#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00006841 else if ((int *)varp == &p_beval)
6842 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006843 if (p_beval == TRUE)
6844 gui_mch_enable_beval_area(balloonEval);
6845 else
6846 gui_mch_disable_beval_area(balloonEval);
6847 }
6848
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006849# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006850 else if ((int *)varp == &p_acd)
6851 {
6852 if (p_acd && curbuf->b_ffname != NULL
6853 && vim_chdirfile(curbuf->b_ffname) == OK)
6854 shorten_fnames(TRUE);
6855 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006856# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857#endif
6858
6859#ifdef FEAT_DIFF
6860 /* 'diff' */
6861 else if ((int *)varp == &curwin->w_p_diff)
6862 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006863 /* May add or remove the buffer from the list of diff buffers. */
6864 diff_buf_adjust(curwin);
6865# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006866 if (foldmethodIsDiff(curwin))
6867 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006868# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006869 }
6870#endif
6871
6872#ifdef USE_IM_CONTROL
6873 /* 'imdisable' */
6874 else if ((int *)varp == &p_imdisable)
6875 {
6876 /* Only de-activate it here, it will be enabled when changing mode. */
6877 if (p_imdisable)
6878 im_set_active(FALSE);
6879 }
6880#endif
6881
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006882#ifdef FEAT_SYN_HL
6883 /* 'spell' */
6884 else if ((int *)varp == &curwin->w_p_spell)
6885 {
6886 if (curwin->w_p_spell)
6887 {
6888 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00006889
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006890 if (errmsg != NULL)
6891 EMSG(_(errmsg));
6892 }
6893 }
6894#endif
6895
Bram Moolenaar071d4272004-06-13 20:20:40 +00006896#ifdef FEAT_FKMAP
6897 else if ((int *)varp == &p_altkeymap)
6898 {
6899 if (old_value != p_altkeymap)
6900 {
6901 if (!p_altkeymap)
6902 {
6903 p_hkmap = p_fkmap;
6904 p_fkmap = 0;
6905 }
6906 else
6907 {
6908 p_fkmap = p_hkmap;
6909 p_hkmap = 0;
6910 }
6911 (void)init_chartab();
6912 }
6913 }
6914
6915 /*
6916 * In case some second language keymapping options have changed, check
6917 * and correct the setting in a consistent way.
6918 */
6919
6920 /*
6921 * If hkmap or fkmap are set, reset Arabic keymapping.
6922 */
6923 if ((p_hkmap || p_fkmap) && p_altkeymap)
6924 {
6925 p_altkeymap = p_fkmap;
6926# ifdef FEAT_ARABIC
6927 curwin->w_p_arab = FALSE;
6928# endif
6929 (void)init_chartab();
6930 }
6931
6932 /*
6933 * If hkmap set, reset Farsi keymapping.
6934 */
6935 if (p_hkmap && p_altkeymap)
6936 {
6937 p_altkeymap = 0;
6938 p_fkmap = 0;
6939# ifdef FEAT_ARABIC
6940 curwin->w_p_arab = FALSE;
6941# endif
6942 (void)init_chartab();
6943 }
6944
6945 /*
6946 * If fkmap set, reset Hebrew keymapping.
6947 */
6948 if (p_fkmap && !p_altkeymap)
6949 {
6950 p_altkeymap = 1;
6951 p_hkmap = 0;
6952# ifdef FEAT_ARABIC
6953 curwin->w_p_arab = FALSE;
6954# endif
6955 (void)init_chartab();
6956 }
6957#endif
6958
6959#ifdef FEAT_ARABIC
6960 if ((int *)varp == &curwin->w_p_arab)
6961 {
6962 if (curwin->w_p_arab)
6963 {
6964 /*
6965 * 'arabic' is set, handle various sub-settings.
6966 */
6967 if (!p_tbidi)
6968 {
6969 /* set rightleft mode */
6970 if (!curwin->w_p_rl)
6971 {
6972 curwin->w_p_rl = TRUE;
6973 changed_window_setting();
6974 }
6975
6976 /* Enable Arabic shaping (major part of what Arabic requires) */
6977 if (!p_arshape)
6978 {
6979 p_arshape = TRUE;
6980 redraw_later_clear();
6981 }
6982 }
6983
6984 /* Arabic requires a utf-8 encoding, inform the user if its not
6985 * set. */
6986 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006987 {
6988 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006989 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6990 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992
6993# ifdef FEAT_MBYTE
6994 /* set 'delcombine' */
6995 p_deco = TRUE;
6996# endif
6997
6998# ifdef FEAT_KEYMAP
6999 /* Force-set the necessary keymap for arabic */
7000 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7001 OPT_LOCAL);
7002# endif
7003# ifdef FEAT_FKMAP
7004 p_altkeymap = 0;
7005 p_hkmap = 0;
7006 p_fkmap = 0;
7007 (void)init_chartab();
7008# endif
7009 }
7010 else
7011 {
7012 /*
7013 * 'arabic' is reset, handle various sub-settings.
7014 */
7015 if (!p_tbidi)
7016 {
7017 /* reset rightleft mode */
7018 if (curwin->w_p_rl)
7019 {
7020 curwin->w_p_rl = FALSE;
7021 changed_window_setting();
7022 }
7023
7024 /* 'arabicshape' isn't reset, it is a global option and
7025 * another window may still need it "on". */
7026 }
7027
7028 /* 'delcombine' isn't reset, it is a global option and another
7029 * window may still want it "on". */
7030
7031# ifdef FEAT_KEYMAP
7032 /* Revert to the default keymap */
7033 curbuf->b_p_iminsert = B_IMODE_NONE;
7034 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7035# endif
7036 }
7037 }
7038#endif
7039
7040 /*
7041 * End of handling side effects for bool options.
7042 */
7043
7044 options[opt_idx].flags |= P_WAS_SET;
7045
7046 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7047 if (curwin->w_curswant != MAXCOL)
7048 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7049 check_redraw(options[opt_idx].flags);
7050
7051 return NULL;
7052}
7053
7054/*
7055 * Set the value of a number option, and take care of side effects.
7056 * Returns NULL for success, or an error message for an error.
7057 */
7058 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007059set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060 int opt_idx; /* index in options[] table */
7061 char_u *varp; /* pointer to the option variable */
7062 long value; /* new value */
7063 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007064 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007065 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7066 OPT_MODELINE */
7067{
7068 char_u *errmsg = NULL;
7069 long old_value = *(long *)varp;
7070 long old_Rows = Rows; /* remember old Rows */
7071 long old_Columns = Columns; /* remember old Columns */
7072 long *pp = (long *)varp;
7073
7074#ifdef FEAT_GUI
7075 need_mouse_correct = TRUE;
7076#endif
7077
7078 *pp = value;
7079#ifdef FEAT_EVAL
7080 /* Remember where the option was set. */
7081 options[opt_idx].scriptID = current_SID;
7082#endif
7083
7084 if (curbuf->b_p_sw <= 0)
7085 {
7086 errmsg = e_positive;
7087 curbuf->b_p_sw = curbuf->b_p_ts;
7088 }
7089
7090 /*
7091 * Number options that need some action when changed
7092 */
7093#ifdef FEAT_WINDOWS
7094 if (pp == &p_wh || pp == &p_hh)
7095 {
7096 if (p_wh < 1)
7097 {
7098 errmsg = e_positive;
7099 p_wh = 1;
7100 }
7101 if (p_wmh > p_wh)
7102 {
7103 errmsg = e_winheight;
7104 p_wh = p_wmh;
7105 }
7106 if (p_hh < 0)
7107 {
7108 errmsg = e_positive;
7109 p_hh = 0;
7110 }
7111
7112 /* Change window height NOW */
7113 if (lastwin != firstwin)
7114 {
7115 if (pp == &p_wh && curwin->w_height < p_wh)
7116 win_setheight((int)p_wh);
7117 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7118 win_setheight((int)p_hh);
7119 }
7120 }
7121
7122 /* 'winminheight' */
7123 else if (pp == &p_wmh)
7124 {
7125 if (p_wmh < 0)
7126 {
7127 errmsg = e_positive;
7128 p_wmh = 0;
7129 }
7130 if (p_wmh > p_wh)
7131 {
7132 errmsg = e_winheight;
7133 p_wmh = p_wh;
7134 }
7135 win_setminheight();
7136 }
7137
7138# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007139 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007140 {
7141 if (p_wiw < 1)
7142 {
7143 errmsg = e_positive;
7144 p_wiw = 1;
7145 }
7146 if (p_wmw > p_wiw)
7147 {
7148 errmsg = e_winwidth;
7149 p_wiw = p_wmw;
7150 }
7151
7152 /* Change window width NOW */
7153 if (lastwin != firstwin && curwin->w_width < p_wiw)
7154 win_setwidth((int)p_wiw);
7155 }
7156
7157 /* 'winminwidth' */
7158 else if (pp == &p_wmw)
7159 {
7160 if (p_wmw < 0)
7161 {
7162 errmsg = e_positive;
7163 p_wmw = 0;
7164 }
7165 if (p_wmw > p_wiw)
7166 {
7167 errmsg = e_winwidth;
7168 p_wmw = p_wiw;
7169 }
7170 win_setminheight();
7171 }
7172# endif
7173
7174#endif
7175
7176#ifdef FEAT_WINDOWS
7177 /* (re)set last window status line */
7178 else if (pp == &p_ls)
7179 {
7180 last_status(FALSE);
7181 }
7182#endif
7183
7184#ifdef FEAT_GUI
7185 else if (pp == &p_linespace)
7186 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007187 /* Recompute gui.char_height and resize the Vim window to keep the
7188 * same number of lines. */
7189 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190 gui_set_shellsize(FALSE, FALSE);
7191 }
7192#endif
7193
7194#ifdef FEAT_FOLDING
7195 /* 'foldlevel' */
7196 else if (pp == &curwin->w_p_fdl)
7197 {
7198 if (curwin->w_p_fdl < 0)
7199 curwin->w_p_fdl = 0;
7200 newFoldLevel();
7201 }
7202
7203 /* 'foldminlevel' */
7204 else if (pp == &curwin->w_p_fml)
7205 {
7206 foldUpdateAll(curwin);
7207 }
7208
7209 /* 'foldnestmax' */
7210 else if (pp == &curwin->w_p_fdn)
7211 {
7212 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7213 foldUpdateAll(curwin);
7214 }
7215
7216 /* 'foldcolumn' */
7217 else if (pp == &curwin->w_p_fdc)
7218 {
7219 if (curwin->w_p_fdc < 0)
7220 {
7221 errmsg = e_positive;
7222 curwin->w_p_fdc = 0;
7223 }
7224 else if (curwin->w_p_fdc > 12)
7225 {
7226 errmsg = e_invarg;
7227 curwin->w_p_fdc = 12;
7228 }
7229 }
7230
7231 /* 'shiftwidth' or 'tabstop' */
7232 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7233 {
7234 if (foldmethodIsIndent(curwin))
7235 foldUpdateAll(curwin);
7236 }
7237#endif /* FEAT_FOLDING */
7238
7239 else if (pp == &curbuf->b_p_iminsert)
7240 {
7241 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7242 {
7243 errmsg = e_invarg;
7244 curbuf->b_p_iminsert = B_IMODE_NONE;
7245 }
7246 p_iminsert = curbuf->b_p_iminsert;
7247 if (termcap_active) /* don't do this in the alternate screen */
7248 showmode();
7249#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7250 /* Show/unshow value of 'keymap' in status lines. */
7251 status_redraw_curbuf();
7252#endif
7253 }
7254
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007255 else if (pp == &p_window)
7256 {
7257 if (p_window < 1)
7258 p_window = 1;
7259 else if (p_window >= Rows)
7260 p_window = Rows - 1;
7261 }
7262
Bram Moolenaar071d4272004-06-13 20:20:40 +00007263 else if (pp == &curbuf->b_p_imsearch)
7264 {
7265 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7266 {
7267 errmsg = e_invarg;
7268 curbuf->b_p_imsearch = B_IMODE_NONE;
7269 }
7270 p_imsearch = curbuf->b_p_imsearch;
7271 }
7272
7273#ifdef FEAT_TITLE
7274 /* if 'titlelen' has changed, redraw the title */
7275 else if (pp == &p_titlelen)
7276 {
7277 if (p_titlelen < 0)
7278 {
7279 errmsg = e_positive;
7280 p_titlelen = 85;
7281 }
7282 if (starting != NO_SCREEN && old_value != p_titlelen)
7283 need_maketitle = TRUE;
7284 }
7285#endif
7286
7287 /* if p_ch changed value, change the command line height */
7288 else if (pp == &p_ch)
7289 {
7290 if (p_ch < 1)
7291 {
7292 errmsg = e_positive;
7293 p_ch = 1;
7294 }
7295
7296 /* Only compute the new window layout when startup has been
7297 * completed. Otherwise the frame sizes may be wrong. */
7298 if (p_ch != old_value && full_screen
7299#ifdef FEAT_GUI
7300 && !gui.starting
7301#endif
7302 )
7303 command_height(old_value);
7304 }
7305
7306 /* when 'updatecount' changes from zero to non-zero, open swap files */
7307 else if (pp == &p_uc)
7308 {
7309 if (p_uc < 0)
7310 {
7311 errmsg = e_positive;
7312 p_uc = 100;
7313 }
7314 if (p_uc && !old_value)
7315 ml_open_files();
7316 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007317#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007318 else if (pp == &p_mzq)
7319 mzvim_reset_timer();
7320#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007321
7322 /* sync undo before 'undolevels' changes */
7323 else if (pp == &p_ul)
7324 {
7325 /* use the old value, otherwise u_sync() may not work properly */
7326 p_ul = old_value;
7327 u_sync();
7328 p_ul = value;
7329 }
7330
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007331#ifdef FEAT_LINEBREAK
7332 /* 'numberwidth' must be positive */
7333 else if (pp == &curwin->w_p_nuw)
7334 {
7335 if (curwin->w_p_nuw < 1)
7336 {
7337 errmsg = e_positive;
7338 curwin->w_p_nuw = 1;
7339 }
7340 if (curwin->w_p_nuw > 10)
7341 {
7342 errmsg = e_invarg;
7343 curwin->w_p_nuw = 10;
7344 }
7345 curwin->w_nrwidth_line_count = 0;
7346 }
7347#endif
7348
Bram Moolenaar071d4272004-06-13 20:20:40 +00007349 /*
7350 * Check the bounds for numeric options here
7351 */
7352 if (Rows < min_rows() && full_screen)
7353 {
7354 if (errbuf != NULL)
7355 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007356 vim_snprintf((char *)errbuf, errbuflen,
7357 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358 errmsg = errbuf;
7359 }
7360 Rows = min_rows();
7361 }
7362 if (Columns < MIN_COLUMNS && full_screen)
7363 {
7364 if (errbuf != NULL)
7365 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007366 vim_snprintf((char *)errbuf, errbuflen,
7367 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368 errmsg = errbuf;
7369 }
7370 Columns = MIN_COLUMNS;
7371 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007372 /* Limit the values to avoid an overflow in Rows * Columns. */
7373 if (Columns > 10000)
7374 Columns = 10000;
7375 if (Rows > 1000)
7376 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007377
7378#ifdef DJGPP
7379 /* avoid a crash by checking for a too large value of 'columns' */
7380 if (old_Columns != Columns && full_screen && term_console)
7381 mch_check_columns();
7382#endif
7383
7384 /*
7385 * If the screen (shell) height has been changed, assume it is the
7386 * physical screenheight.
7387 */
7388 if (old_Rows != Rows || old_Columns != Columns)
7389 {
7390 /* Changing the screen size is not allowed while updating the screen. */
7391 if (updating_screen)
7392 *pp = old_value;
7393 else if (full_screen
7394#ifdef FEAT_GUI
7395 && !gui.starting
7396#endif
7397 )
7398 set_shellsize((int)Columns, (int)Rows, TRUE);
7399 else
7400 {
7401 /* Postpone the resizing; check the size and cmdline position for
7402 * messages. */
7403 check_shellsize();
7404 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7405 cmdline_row = Rows - p_ch;
7406 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007407 if (p_window >= Rows)
7408 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007409 }
7410
7411 if (curbuf->b_p_sts < 0)
7412 {
7413 errmsg = e_positive;
7414 curbuf->b_p_sts = 0;
7415 }
7416 if (curbuf->b_p_ts <= 0)
7417 {
7418 errmsg = e_positive;
7419 curbuf->b_p_ts = 8;
7420 }
7421 if (curbuf->b_p_tw < 0)
7422 {
7423 errmsg = e_positive;
7424 curbuf->b_p_tw = 0;
7425 }
7426 if (p_tm < 0)
7427 {
7428 errmsg = e_positive;
7429 p_tm = 0;
7430 }
7431 if ((curwin->w_p_scr <= 0
7432 || (curwin->w_p_scr > curwin->w_height
7433 && curwin->w_height > 0))
7434 && full_screen)
7435 {
7436 if (pp == &(curwin->w_p_scr))
7437 {
7438 if (curwin->w_p_scr != 0)
7439 errmsg = e_scroll;
7440 win_comp_scroll(curwin);
7441 }
7442 /* If 'scroll' became invalid because of a side effect silently adjust
7443 * it. */
7444 else if (curwin->w_p_scr <= 0)
7445 curwin->w_p_scr = 1;
7446 else /* curwin->w_p_scr > curwin->w_height */
7447 curwin->w_p_scr = curwin->w_height;
7448 }
7449 if (p_report < 0)
7450 {
7451 errmsg = e_positive;
7452 p_report = 1;
7453 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00007454 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007455 {
7456 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7457 p_sj = Rows / 2;
7458 else
7459 {
7460 errmsg = e_scroll;
7461 p_sj = 1;
7462 }
7463 }
7464 if (p_so < 0 && full_screen)
7465 {
7466 errmsg = e_scroll;
7467 p_so = 0;
7468 }
7469 if (p_siso < 0 && full_screen)
7470 {
7471 errmsg = e_positive;
7472 p_siso = 0;
7473 }
7474#ifdef FEAT_CMDWIN
7475 if (p_cwh < 1)
7476 {
7477 errmsg = e_positive;
7478 p_cwh = 1;
7479 }
7480#endif
7481 if (p_ut < 0)
7482 {
7483 errmsg = e_positive;
7484 p_ut = 2000;
7485 }
7486 if (p_ss < 0)
7487 {
7488 errmsg = e_positive;
7489 p_ss = 0;
7490 }
7491
7492 /* May set global value for local option. */
7493 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7494 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7495
7496 options[opt_idx].flags |= P_WAS_SET;
7497
7498 comp_col(); /* in case 'columns' or 'ls' changed */
7499 if (curwin->w_curswant != MAXCOL)
7500 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7501 check_redraw(options[opt_idx].flags);
7502
7503 return errmsg;
7504}
7505
7506/*
7507 * Called after an option changed: check if something needs to be redrawn.
7508 */
7509 static void
7510check_redraw(flags)
7511 long_u flags;
7512{
7513 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7514 int clear = (flags & P_RCLR) == P_RCLR;
7515 int all = ((flags & P_RALL) == P_RALL || clear);
7516
7517#ifdef FEAT_WINDOWS
7518 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7519 status_redraw_all();
7520#endif
7521
7522 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7523 changed_window_setting();
7524 if (flags & P_RBUF)
7525 redraw_curbuf_later(NOT_VALID);
7526 if (clear)
7527 redraw_all_later(CLEAR);
7528 else if (all)
7529 redraw_all_later(NOT_VALID);
7530}
7531
7532/*
7533 * Find index for option 'arg'.
7534 * Return -1 if not found.
7535 */
7536 static int
7537findoption(arg)
7538 char_u *arg;
7539{
7540 int opt_idx;
7541 char *s, *p;
7542 static short quick_tab[27] = {0, 0}; /* quick access table */
7543 int is_term_opt;
7544
7545 /*
7546 * For first call: Initialize the quick-access table.
7547 * It contains the index for the first option that starts with a certain
7548 * letter. There are 26 letters, plus the first "t_" option.
7549 */
7550 if (quick_tab[1] == 0)
7551 {
7552 p = options[0].fullname;
7553 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7554 {
7555 if (s[0] != p[0])
7556 {
7557 if (s[0] == 't' && s[1] == '_')
7558 quick_tab[26] = opt_idx;
7559 else
7560 quick_tab[CharOrdLow(s[0])] = opt_idx;
7561 }
7562 p = s;
7563 }
7564 }
7565
7566 /*
7567 * Check for name starting with an illegal character.
7568 */
7569#ifdef EBCDIC
7570 if (!islower(arg[0]))
7571#else
7572 if (arg[0] < 'a' || arg[0] > 'z')
7573#endif
7574 return -1;
7575
7576 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7577 if (is_term_opt)
7578 opt_idx = quick_tab[26];
7579 else
7580 opt_idx = quick_tab[CharOrdLow(arg[0])];
7581 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7582 {
7583 if (STRCMP(arg, s) == 0) /* match full name */
7584 break;
7585 }
7586 if (s == NULL && !is_term_opt)
7587 {
7588 opt_idx = quick_tab[CharOrdLow(arg[0])];
7589 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7590 {
7591 s = options[opt_idx].shortname;
7592 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7593 break;
7594 s = NULL;
7595 }
7596 }
7597 if (s == NULL)
7598 opt_idx = -1;
7599 return opt_idx;
7600}
7601
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007602#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007603/*
7604 * Get the value for an option.
7605 *
7606 * Returns:
7607 * Number or Toggle option: 1, *numval gets value.
7608 * String option: 0, *stringval gets allocated string.
7609 * Hidden Number or Toggle option: -1.
7610 * hidden String option: -2.
7611 * unknown option: -3.
7612 */
7613 int
7614get_option_value(name, numval, stringval, opt_flags)
7615 char_u *name;
7616 long *numval;
7617 char_u **stringval; /* NULL when only checking existance */
7618 int opt_flags;
7619{
7620 int opt_idx;
7621 char_u *varp;
7622
7623 opt_idx = findoption(name);
7624 if (opt_idx < 0) /* unknown option */
7625 return -3;
7626
7627 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7628
7629 if (options[opt_idx].flags & P_STRING)
7630 {
7631 if (varp == NULL) /* hidden option */
7632 return -2;
7633 if (stringval != NULL)
7634 {
7635#ifdef FEAT_CRYPT
7636 /* never return the value of the crypt key */
7637 if ((char_u **)varp == &curbuf->b_p_key)
7638 *stringval = vim_strsave((char_u *)"*****");
7639 else
7640#endif
7641 *stringval = vim_strsave(*(char_u **)(varp));
7642 }
7643 return 0;
7644 }
7645
7646 if (varp == NULL) /* hidden option */
7647 return -1;
7648 if (options[opt_idx].flags & P_NUM)
7649 *numval = *(long *)varp;
7650 else
7651 {
7652 /* Special case: 'modified' is b_changed, but we also want to consider
7653 * it set when 'ff' or 'fenc' changed. */
7654 if ((int *)varp == &curbuf->b_changed)
7655 *numval = curbufIsChanged();
7656 else
7657 *numval = *(int *)varp;
7658 }
7659 return 1;
7660}
7661#endif
7662
7663/*
7664 * Set the value of option "name".
7665 * Use "string" for string options, use "number" for other options.
7666 */
7667 void
7668set_option_value(name, number, string, opt_flags)
7669 char_u *name;
7670 long number;
7671 char_u *string;
7672 int opt_flags; /* OPT_LOCAL or 0 (both) */
7673{
7674 int opt_idx;
7675 char_u *varp;
7676 int flags;
7677
7678 opt_idx = findoption(name);
7679 if (opt_idx == -1)
7680 EMSG2(_("E355: Unknown option: %s"), name);
7681 else
7682 {
7683 flags = options[opt_idx].flags;
7684#ifdef HAVE_SANDBOX
7685 /* Disallow changing some options in the sandbox */
7686 if (sandbox > 0 && (flags & P_SECURE))
7687 EMSG(_(e_sandbox));
7688 else
7689#endif
7690 if (flags & P_STRING)
7691 set_string_option(opt_idx, string, opt_flags);
7692 else
7693 {
7694 varp = get_varp(&options[opt_idx]);
7695 if (varp != NULL) /* hidden option is not changed */
7696 {
7697 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00007698 (void)set_num_option(opt_idx, varp, number,
7699 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007700 else
7701 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7702 }
7703 }
7704 }
7705}
7706
7707/*
7708 * Get the terminal code for a terminal option.
7709 * Returns NULL when not found.
7710 */
7711 char_u *
7712get_term_code(tname)
7713 char_u *tname;
7714{
7715 int opt_idx;
7716 char_u *varp;
7717
7718 if (tname[0] != 't' || tname[1] != '_' ||
7719 tname[2] == NUL || tname[3] == NUL)
7720 return NULL;
7721 if ((opt_idx = findoption(tname)) >= 0)
7722 {
7723 varp = get_varp(&(options[opt_idx]));
7724 if (varp != NULL)
7725 varp = *(char_u **)(varp);
7726 return varp;
7727 }
7728 return find_termcode(tname + 2);
7729}
7730
7731 char_u *
7732get_highlight_default()
7733{
7734 int i;
7735
7736 i = findoption((char_u *)"hl");
7737 if (i >= 0)
7738 return options[i].def_val[VI_DEFAULT];
7739 return (char_u *)NULL;
7740}
7741
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007742#if defined(FEAT_MBYTE) || defined(PROTO)
7743 char_u *
7744get_encoding_default()
7745{
7746 int i;
7747
7748 i = findoption((char_u *)"enc");
7749 if (i >= 0)
7750 return options[i].def_val[VI_DEFAULT];
7751 return (char_u *)NULL;
7752}
7753#endif
7754
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755/*
7756 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7757 */
7758 static int
7759find_key_option(arg)
7760 char_u *arg;
7761{
7762 int key;
7763 int modifiers;
7764
7765 /*
7766 * Don't use get_special_key_code() for t_xx, we don't want it to call
7767 * add_termcap_entry().
7768 */
7769 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7770 key = TERMCAP2KEY(arg[2], arg[3]);
7771 else
7772 {
7773 --arg; /* put arg at the '<' */
7774 modifiers = 0;
7775 key = find_special_key(&arg, &modifiers, TRUE);
7776 if (modifiers) /* can't handle modifiers here */
7777 key = 0;
7778 }
7779 return key;
7780}
7781
7782/*
7783 * if 'all' == 0: show changed options
7784 * if 'all' == 1: show all normal options
7785 * if 'all' == 2: show all terminal options
7786 */
7787 static void
7788showoptions(all, opt_flags)
7789 int all;
7790 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7791{
7792 struct vimoption *p;
7793 int col;
7794 int isterm;
7795 char_u *varp;
7796 struct vimoption **items;
7797 int item_count;
7798 int run;
7799 int row, rows;
7800 int cols;
7801 int i;
7802 int len;
7803
7804#define INC 20
7805#define GAP 3
7806
7807 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7808 PARAM_COUNT));
7809 if (items == NULL)
7810 return;
7811
7812 /* Highlight title */
7813 if (all == 2)
7814 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7815 else if (opt_flags & OPT_GLOBAL)
7816 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7817 else if (opt_flags & OPT_LOCAL)
7818 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7819 else
7820 MSG_PUTS_TITLE(_("\n--- Options ---"));
7821
7822 /*
7823 * do the loop two times:
7824 * 1. display the short items
7825 * 2. display the long items (only strings and numbers)
7826 */
7827 for (run = 1; run <= 2 && !got_int; ++run)
7828 {
7829 /*
7830 * collect the items in items[]
7831 */
7832 item_count = 0;
7833 for (p = &options[0]; p->fullname != NULL; p++)
7834 {
7835 varp = NULL;
7836 isterm = istermoption(p);
7837 if (opt_flags != 0)
7838 {
7839 if (p->indir != PV_NONE && !isterm)
7840 varp = get_varp_scope(p, opt_flags);
7841 }
7842 else
7843 varp = get_varp(p);
7844 if (varp != NULL
7845 && ((all == 2 && isterm)
7846 || (all == 1 && !isterm)
7847 || (all == 0 && !optval_default(p, varp))))
7848 {
7849 if (p->flags & P_BOOL)
7850 len = 1; /* a toggle option fits always */
7851 else
7852 {
7853 option_value2string(p, opt_flags);
7854 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7855 }
7856 if ((len <= INC - GAP && run == 1) ||
7857 (len > INC - GAP && run == 2))
7858 items[item_count++] = p;
7859 }
7860 }
7861
7862 /*
7863 * display the items
7864 */
7865 if (run == 1)
7866 {
7867 cols = (Columns + GAP - 3) / INC;
7868 if (cols == 0)
7869 cols = 1;
7870 rows = (item_count + cols - 1) / cols;
7871 }
7872 else /* run == 2 */
7873 rows = item_count;
7874 for (row = 0; row < rows && !got_int; ++row)
7875 {
7876 msg_putchar('\n'); /* go to next line */
7877 if (got_int) /* 'q' typed in more */
7878 break;
7879 col = 0;
7880 for (i = row; i < item_count; i += rows)
7881 {
7882 msg_col = col; /* make columns */
7883 showoneopt(items[i], opt_flags);
7884 col += INC;
7885 }
7886 out_flush();
7887 ui_breakcheck();
7888 }
7889 }
7890 vim_free(items);
7891}
7892
7893/*
7894 * Return TRUE if option "p" has its default value.
7895 */
7896 static int
7897optval_default(p, varp)
7898 struct vimoption *p;
7899 char_u *varp;
7900{
7901 int dvi;
7902
7903 if (varp == NULL)
7904 return TRUE; /* hidden option is always at default */
7905 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7906 if (p->flags & P_NUM)
7907 return (*(long *)varp == (long)p->def_val[dvi]);
7908 if (p->flags & P_BOOL)
7909 /* the cast to long is required for Manx C */
7910 return (*(int *)varp == (int)(long)p->def_val[dvi]);
7911 /* P_STRING */
7912 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7913}
7914
7915/*
7916 * showoneopt: show the value of one option
7917 * must not be called with a hidden option!
7918 */
7919 static void
7920showoneopt(p, opt_flags)
7921 struct vimoption *p;
7922 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
7923{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007924 char_u *varp;
7925 int save_silent = silent_mode;
7926
7927 silent_mode = FALSE;
7928 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007929
7930 varp = get_varp_scope(p, opt_flags);
7931
7932 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7933 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7934 ? !curbufIsChanged() : !*(int *)varp))
7935 MSG_PUTS("no");
7936 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7937 MSG_PUTS("--");
7938 else
7939 MSG_PUTS(" ");
7940 MSG_PUTS(p->fullname);
7941 if (!(p->flags & P_BOOL))
7942 {
7943 msg_putchar('=');
7944 /* put value string in NameBuff */
7945 option_value2string(p, opt_flags);
7946 msg_outtrans(NameBuff);
7947 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007948
7949 silent_mode = save_silent;
7950 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951}
7952
7953/*
7954 * Write modified options as ":set" commands to a file.
7955 *
7956 * There are three values for "opt_flags":
7957 * OPT_GLOBAL: Write global option values and fresh values of
7958 * buffer-local options (used for start of a session
7959 * file).
7960 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7961 * curwin (used for a vimrc file).
7962 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
7963 * and local values for window-local options of
7964 * curwin. Local values are also written when at the
7965 * default value, because a modeline or autocommand
7966 * may have set them when doing ":edit file" and the
7967 * user has set them back at the default or fresh
7968 * value.
7969 * When "local_only" is TRUE, don't write fresh
7970 * values, only local values (for ":mkview").
7971 * (fresh value = value used for a new buffer or window for a local option).
7972 *
7973 * Return FAIL on error, OK otherwise.
7974 */
7975 int
7976makeset(fd, opt_flags, local_only)
7977 FILE *fd;
7978 int opt_flags;
7979 int local_only;
7980{
7981 struct vimoption *p;
7982 char_u *varp; /* currently used value */
7983 char_u *varp_fresh; /* local value */
7984 char_u *varp_local = NULL; /* fresh value */
7985 char *cmd;
7986 int round;
7987
7988 /*
7989 * The options that don't have a default (terminal name, columns, lines)
7990 * are never written. Terminal options are also not written.
7991 */
7992 for (p = &options[0]; !istermoption(p); p++)
7993 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7994 {
7995 /* skip global option when only doing locals */
7996 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7997 continue;
7998
7999 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8000 * file, they are always buffer-specific. */
8001 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8002 continue;
8003
8004 /* Global values are only written when not at the default value. */
8005 varp = get_varp_scope(p, opt_flags);
8006 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8007 continue;
8008
8009 round = 2;
8010 if (p->indir != PV_NONE)
8011 {
8012 if (p->var == VAR_WIN)
8013 {
8014 /* skip window-local option when only doing globals */
8015 if (!(opt_flags & OPT_LOCAL))
8016 continue;
8017 /* When fresh value of window-local option is not at the
8018 * default, need to write it too. */
8019 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8020 {
8021 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8022 if (!optval_default(p, varp_fresh))
8023 {
8024 round = 1;
8025 varp_local = varp;
8026 varp = varp_fresh;
8027 }
8028 }
8029 }
8030 }
8031
8032 /* Round 1: fresh value for window-local options.
8033 * Round 2: other values */
8034 for ( ; round <= 2; varp = varp_local, ++round)
8035 {
8036 if (round == 1 || (opt_flags & OPT_GLOBAL))
8037 cmd = "set";
8038 else
8039 cmd = "setlocal";
8040
8041 if (p->flags & P_BOOL)
8042 {
8043 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8044 return FAIL;
8045 }
8046 else if (p->flags & P_NUM)
8047 {
8048 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8049 return FAIL;
8050 }
8051 else /* P_STRING */
8052 {
8053 /* Don't set 'syntax' and 'filetype' again if the value is
8054 * already right, avoids reloading the syntax file. */
8055 if (p->indir == PV_SYN || p->indir == PV_FT)
8056 {
8057 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8058 *(char_u **)(varp)) < 0
8059 || put_eol(fd) < 0)
8060 return FAIL;
8061 }
8062 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8063 (p->flags & P_EXPAND) != 0) == FAIL)
8064 return FAIL;
8065 if (p->indir == PV_SYN || p->indir == PV_FT)
8066 {
8067 if (put_line(fd, "endif") == FAIL)
8068 return FAIL;
8069 }
8070 }
8071 }
8072 }
8073 return OK;
8074}
8075
8076#if defined(FEAT_FOLDING) || defined(PROTO)
8077/*
8078 * Generate set commands for the local fold options only. Used when
8079 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8080 */
8081 int
8082makefoldset(fd)
8083 FILE *fd;
8084{
8085 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8086# ifdef FEAT_EVAL
8087 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8088 == FAIL
8089# endif
8090 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8091 == FAIL
8092 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8093 == FAIL
8094 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8095 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8096 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8097 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8098 )
8099 return FAIL;
8100
8101 return OK;
8102}
8103#endif
8104
8105 static int
8106put_setstring(fd, cmd, name, valuep, expand)
8107 FILE *fd;
8108 char *cmd;
8109 char *name;
8110 char_u **valuep;
8111 int expand;
8112{
8113 char_u *s;
8114 char_u buf[MAXPATHL];
8115
8116 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8117 return FAIL;
8118 if (*valuep != NULL)
8119 {
8120 /* Output 'pastetoggle' as key names. For other
8121 * options some characters have to be escaped with
8122 * CTRL-V or backslash */
8123 if (valuep == &p_pt)
8124 {
8125 s = *valuep;
8126 while (*s != NUL)
8127 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8128 return FAIL;
8129 }
8130 else if (expand)
8131 {
8132 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8133 if (put_escstr(fd, buf, 2) == FAIL)
8134 return FAIL;
8135 }
8136 else if (put_escstr(fd, *valuep, 2) == FAIL)
8137 return FAIL;
8138 }
8139 if (put_eol(fd) < 0)
8140 return FAIL;
8141 return OK;
8142}
8143
8144 static int
8145put_setnum(fd, cmd, name, valuep)
8146 FILE *fd;
8147 char *cmd;
8148 char *name;
8149 long *valuep;
8150{
8151 long wc;
8152
8153 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8154 return FAIL;
8155 if (wc_use_keyname((char_u *)valuep, &wc))
8156 {
8157 /* print 'wildchar' and 'wildcharm' as a key name */
8158 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8159 return FAIL;
8160 }
8161 else if (fprintf(fd, "%ld", *valuep) < 0)
8162 return FAIL;
8163 if (put_eol(fd) < 0)
8164 return FAIL;
8165 return OK;
8166}
8167
8168 static int
8169put_setbool(fd, cmd, name, value)
8170 FILE *fd;
8171 char *cmd;
8172 char *name;
8173 int value;
8174{
8175 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8176 || put_eol(fd) < 0)
8177 return FAIL;
8178 return OK;
8179}
8180
8181/*
8182 * Clear all the terminal options.
8183 * If the option has been allocated, free the memory.
8184 * Terminal options are never hidden or indirect.
8185 */
8186 void
8187clear_termoptions()
8188{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189 /*
8190 * Reset a few things before clearing the old options. This may cause
8191 * outputting a few things that the terminal doesn't understand, but the
8192 * screen will be cleared later, so this is OK.
8193 */
8194#ifdef FEAT_MOUSE_TTY
8195 mch_setmouse(FALSE); /* switch mouse off */
8196#endif
8197#ifdef FEAT_TITLE
8198 mch_restore_title(3); /* restore window titles */
8199#endif
8200#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8201 /* When starting the GUI close the display opened for the clipboard.
8202 * After restoring the title, because that will need the display. */
8203 if (gui.starting)
8204 clear_xterm_clip();
8205#endif
8206#ifdef WIN3264
8207 /*
8208 * Check if this is allowed now.
8209 */
8210 if (can_end_termcap_mode(FALSE) == TRUE)
8211#endif
8212 stoptermcap(); /* stop termcap mode */
8213
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008214 free_termoptions();
8215}
8216
8217 void
8218free_termoptions()
8219{
8220 struct vimoption *p;
8221
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 for (p = &options[0]; p->fullname != NULL; p++)
8223 if (istermoption(p))
8224 {
8225 if (p->flags & P_ALLOCED)
8226 free_string_option(*(char_u **)(p->var));
8227 if (p->flags & P_DEF_ALLOCED)
8228 free_string_option(p->def_val[VI_DEFAULT]);
8229 *(char_u **)(p->var) = empty_option;
8230 p->def_val[VI_DEFAULT] = empty_option;
8231 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8232 }
8233 clear_termcodes();
8234}
8235
8236/*
8237 * Set the terminal option defaults to the current value.
8238 * Used after setting the terminal name.
8239 */
8240 void
8241set_term_defaults()
8242{
8243 struct vimoption *p;
8244
8245 for (p = &options[0]; p->fullname != NULL; p++)
8246 {
8247 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8248 {
8249 if (p->flags & P_DEF_ALLOCED)
8250 {
8251 free_string_option(p->def_val[VI_DEFAULT]);
8252 p->flags &= ~P_DEF_ALLOCED;
8253 }
8254 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8255 if (p->flags & P_ALLOCED)
8256 {
8257 p->flags |= P_DEF_ALLOCED;
8258 p->flags &= ~P_ALLOCED; /* don't free the value now */
8259 }
8260 }
8261 }
8262}
8263
8264/*
8265 * return TRUE if 'p' starts with 't_'
8266 */
8267 static int
8268istermoption(p)
8269 struct vimoption *p;
8270{
8271 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8272}
8273
8274/*
8275 * Compute columns for ruler and shown command. 'sc_col' is also used to
8276 * decide what the maximum length of a message on the status line can be.
8277 * If there is a status line for the last window, 'sc_col' is independent
8278 * of 'ru_col'.
8279 */
8280
8281#define COL_RULER 17 /* columns needed by standard ruler */
8282
8283 void
8284comp_col()
8285{
8286#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8287 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8288
8289 sc_col = 0;
8290 ru_col = 0;
8291 if (p_ru)
8292 {
8293#ifdef FEAT_STL_OPT
8294 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8295#else
8296 ru_col = COL_RULER + 1;
8297#endif
8298 /* no last status line, adjust sc_col */
8299 if (!last_has_status)
8300 sc_col = ru_col;
8301 }
8302 if (p_sc)
8303 {
8304 sc_col += SHOWCMD_COLS;
8305 if (!p_ru || last_has_status) /* no need for separating space */
8306 ++sc_col;
8307 }
8308 sc_col = Columns - sc_col;
8309 ru_col = Columns - ru_col;
8310 if (sc_col <= 0) /* screen too narrow, will become a mess */
8311 sc_col = 1;
8312 if (ru_col <= 0)
8313 ru_col = 1;
8314#else
8315 sc_col = Columns;
8316 ru_col = Columns;
8317#endif
8318}
8319
8320/*
8321 * Get pointer to option variable, depending on local or global scope.
8322 */
8323 static char_u *
8324get_varp_scope(p, opt_flags)
8325 struct vimoption *p;
8326 int opt_flags;
8327{
8328 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8329 {
8330 if (p->var == VAR_WIN)
8331 return (char_u *)GLOBAL_WO(get_varp(p));
8332 return p->var;
8333 }
8334 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
8335 {
8336 switch ((int)p->indir)
8337 {
8338#ifdef FEAT_QUICKFIX
8339 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
8340 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
8341 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
8342#endif
8343 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
8344 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
8345 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
8346 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
8347 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
8348#ifdef FEAT_FIND_ID
8349 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
8350 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
8351#endif
8352#ifdef FEAT_INS_EXPAND
8353 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
8354 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
8355#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008356#ifdef FEAT_STL_OPT
8357 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
8358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359 }
8360 return NULL; /* "cannot happen" */
8361 }
8362 return get_varp(p);
8363}
8364
8365/*
8366 * Get pointer to option variable.
8367 */
8368 static char_u *
8369get_varp(p)
8370 struct vimoption *p;
8371{
8372 /* hidden option, always return NULL */
8373 if (p->var == NULL)
8374 return NULL;
8375
8376 switch ((int)p->indir)
8377 {
8378 case PV_NONE: return p->var;
8379
8380 /* global option with local value: use local value if it's been set */
8381 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
8382 ? (char_u *)&curbuf->b_p_ep : p->var;
8383 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
8384 ? (char_u *)&curbuf->b_p_kp : p->var;
8385 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
8386 ? (char_u *)&(curbuf->b_p_path) : p->var;
8387 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
8388 ? (char_u *)&(curbuf->b_p_ar) : p->var;
8389 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
8390 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8391#ifdef FEAT_FIND_ID
8392 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
8393 ? (char_u *)&(curbuf->b_p_def) : p->var;
8394 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
8395 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8396#endif
8397#ifdef FEAT_INS_EXPAND
8398 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
8399 ? (char_u *)&(curbuf->b_p_dict) : p->var;
8400 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
8401 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8402#endif
8403#ifdef FEAT_QUICKFIX
8404 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
8405 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8406 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
8407 ? (char_u *)&(curbuf->b_p_mp) : p->var;
8408 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8409 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8410#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008411#ifdef FEAT_STL_OPT
8412 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8413 ? (char_u *)&(curwin->w_p_stl) : p->var;
8414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415
8416#ifdef FEAT_ARABIC
8417 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8418#endif
8419 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008420#ifdef FEAT_SYN_HL
8421 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8422#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423#ifdef FEAT_DIFF
8424 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8425#endif
8426#ifdef FEAT_FOLDING
8427 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8428 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8429 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8430 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8431 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8432 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8433 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8434# ifdef FEAT_EVAL
8435 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8436 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8437# endif
8438 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8439#endif
8440 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008441#ifdef FEAT_LINEBREAK
8442 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8443#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444#if defined(FEAT_WINDOWS)
8445 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8446#endif
8447#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8448 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8449#endif
8450#ifdef FEAT_RIGHTLEFT
8451 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8452 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8453#endif
8454 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8455 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8456#ifdef FEAT_LINEBREAK
8457 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8458#endif
8459#ifdef FEAT_SCROLLBIND
8460 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8461#endif
8462
8463 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8464 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8465#ifdef FEAT_MBYTE
8466 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8467#endif
8468#if defined(FEAT_QUICKFIX)
8469 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8470 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8471#endif
8472 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8473 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8474#ifdef FEAT_CINDENT
8475 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8476 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8477 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8478#endif
8479#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8480 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8481#endif
8482#ifdef FEAT_COMMENTS
8483 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8484#endif
8485#ifdef FEAT_FOLDING
8486 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8487#endif
8488#ifdef FEAT_INS_EXPAND
8489 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8490#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008491#ifdef FEAT_COMPL_FUNC
8492 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008493 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8496 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8497#ifdef FEAT_MBYTE
8498 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8499#endif
8500 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8501#ifdef FEAT_AUTOCMD
8502 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8503#endif
8504 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008505 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8507 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8508 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8509 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8510#ifdef FEAT_FIND_ID
8511# ifdef FEAT_EVAL
8512 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8513# endif
8514#endif
8515#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8516 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8517 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8518#endif
8519#ifdef FEAT_CRYPT
8520 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8521#endif
8522#ifdef FEAT_LISP
8523 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8524#endif
8525 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8526 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8527 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8528 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8529 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8530#ifdef FEAT_OSFILETYPE
8531 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8532#endif
8533 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008534#ifdef FEAT_TEXTOBJ
8535 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008537 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8538#ifdef FEAT_SMARTINDENT
8539 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8540#endif
8541#ifndef SHORT_FNAME
8542 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8543#endif
8544 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8545#ifdef FEAT_SEARCHPATH
8546 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8547#endif
8548 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8549#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008550 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008552 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008553 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008554 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555#endif
8556 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8557 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8558 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8559 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8560 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8561#ifdef FEAT_KEYMAP
8562 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8563#endif
8564 default: EMSG(_("E356: get_varp ERROR"));
8565 }
8566 /* always return a valid pointer to avoid a crash! */
8567 return (char_u *)&(curbuf->b_p_wm);
8568}
8569
8570/*
8571 * Get the value of 'equalprg', either the buffer-local one or the global one.
8572 */
8573 char_u *
8574get_equalprg()
8575{
8576 if (*curbuf->b_p_ep == NUL)
8577 return p_ep;
8578 return curbuf->b_p_ep;
8579}
8580
8581#if defined(FEAT_WINDOWS) || defined(PROTO)
8582/*
8583 * Copy options from one window to another.
8584 * Used when splitting a window.
8585 */
8586 void
8587win_copy_options(wp_from, wp_to)
8588 win_T *wp_from;
8589 win_T *wp_to;
8590{
8591 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8592 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8593# ifdef FEAT_RIGHTLEFT
8594# ifdef FEAT_FKMAP
8595 /* Is this right? */
8596 wp_to->w_farsi = wp_from->w_farsi;
8597# endif
8598# endif
8599}
8600#endif
8601
8602/*
8603 * Copy the options from one winopt_T to another.
8604 * Doesn't free the old option values in "to", use clear_winopt() for that.
8605 * The 'scroll' option is not copied, because it depends on the window height.
8606 * The 'previewwindow' option is reset, there can be only one preview window.
8607 */
8608 void
8609copy_winopt(from, to)
8610 winopt_T *from;
8611 winopt_T *to;
8612{
8613#ifdef FEAT_ARABIC
8614 to->wo_arab = from->wo_arab;
8615#endif
8616 to->wo_list = from->wo_list;
8617 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008618#ifdef FEAT_LINEBREAK
8619 to->wo_nuw = from->wo_nuw;
8620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008621#ifdef FEAT_RIGHTLEFT
8622 to->wo_rl = from->wo_rl;
8623 to->wo_rlc = vim_strsave(from->wo_rlc);
8624#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008625#ifdef FEAT_STL_OPT
8626 to->wo_stl = vim_strsave(from->wo_stl);
8627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 to->wo_wrap = from->wo_wrap;
8629#ifdef FEAT_LINEBREAK
8630 to->wo_lbr = from->wo_lbr;
8631#endif
8632#ifdef FEAT_SCROLLBIND
8633 to->wo_scb = from->wo_scb;
8634#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008635#ifdef FEAT_SYN_HL
8636 to->wo_spell = from->wo_spell;
8637#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638#ifdef FEAT_DIFF
8639 to->wo_diff = from->wo_diff;
8640#endif
8641#ifdef FEAT_FOLDING
8642 to->wo_fdc = from->wo_fdc;
8643 to->wo_fen = from->wo_fen;
8644 to->wo_fdi = vim_strsave(from->wo_fdi);
8645 to->wo_fml = from->wo_fml;
8646 to->wo_fdl = from->wo_fdl;
8647 to->wo_fdm = vim_strsave(from->wo_fdm);
8648 to->wo_fdn = from->wo_fdn;
8649# ifdef FEAT_EVAL
8650 to->wo_fde = vim_strsave(from->wo_fde);
8651 to->wo_fdt = vim_strsave(from->wo_fdt);
8652# endif
8653 to->wo_fmr = vim_strsave(from->wo_fmr);
8654#endif
8655 check_winopt(to); /* don't want NULL pointers */
8656}
8657
8658/*
8659 * Check string options in a window for a NULL value.
8660 */
8661 void
8662check_win_options(win)
8663 win_T *win;
8664{
8665 check_winopt(&win->w_onebuf_opt);
8666 check_winopt(&win->w_allbuf_opt);
8667}
8668
8669/*
8670 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8671 */
8672/*ARGSUSED*/
8673 void
8674check_winopt(wop)
8675 winopt_T *wop;
8676{
8677#ifdef FEAT_FOLDING
8678 check_string_option(&wop->wo_fdi);
8679 check_string_option(&wop->wo_fdm);
8680# ifdef FEAT_EVAL
8681 check_string_option(&wop->wo_fde);
8682 check_string_option(&wop->wo_fdt);
8683# endif
8684 check_string_option(&wop->wo_fmr);
8685#endif
8686#ifdef FEAT_RIGHTLEFT
8687 check_string_option(&wop->wo_rlc);
8688#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008689#ifdef FEAT_STL_OPT
8690 check_string_option(&wop->wo_stl);
8691#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008692}
8693
8694/*
8695 * Free the allocated memory inside a winopt_T.
8696 */
8697/*ARGSUSED*/
8698 void
8699clear_winopt(wop)
8700 winopt_T *wop;
8701{
8702#ifdef FEAT_FOLDING
8703 clear_string_option(&wop->wo_fdi);
8704 clear_string_option(&wop->wo_fdm);
8705# ifdef FEAT_EVAL
8706 clear_string_option(&wop->wo_fde);
8707 clear_string_option(&wop->wo_fdt);
8708# endif
8709 clear_string_option(&wop->wo_fmr);
8710#endif
8711#ifdef FEAT_RIGHTLEFT
8712 clear_string_option(&wop->wo_rlc);
8713#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008714#ifdef FEAT_STL_OPT
8715 clear_string_option(&wop->wo_stl);
8716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008717}
8718
8719/*
8720 * Copy global option values to local options for one buffer.
8721 * Used when creating a new buffer and sometimes when entering a buffer.
8722 * flags:
8723 * BCO_ENTER We will enter the buf buffer.
8724 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8725 * appropriate.
8726 * BCO_NOHELP Don't copy the values to a help buffer.
8727 */
8728 void
8729buf_copy_options(buf, flags)
8730 buf_T *buf;
8731 int flags;
8732{
8733 int should_copy = TRUE;
8734 char_u *save_p_isk = NULL; /* init for GCC */
8735 int dont_do_help;
8736 int did_isk = FALSE;
8737
8738 /*
8739 * Don't do anything of the buffer is invalid.
8740 */
8741 if (buf == NULL || !buf_valid(buf))
8742 return;
8743
8744 /*
8745 * Skip this when the option defaults have not been set yet. Happens when
8746 * main() allocates the first buffer.
8747 */
8748 if (p_cpo != NULL)
8749 {
8750 /*
8751 * Always copy when entering and 'cpo' contains 'S'.
8752 * Don't copy when already initialized.
8753 * Don't copy when 'cpo' contains 's' and not entering.
8754 * 'S' BCO_ENTER initialized 's' should_copy
8755 * yes yes X X TRUE
8756 * yes no yes X FALSE
8757 * no X yes X FALSE
8758 * X no no yes FALSE
8759 * X no no no TRUE
8760 * no yes no X TRUE
8761 */
8762 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8763 && (buf->b_p_initialized
8764 || (!(flags & BCO_ENTER)
8765 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8766 should_copy = FALSE;
8767
8768 if (should_copy || (flags & BCO_ALWAYS))
8769 {
8770 /* Don't copy the options specific to a help buffer when
8771 * BCO_NOHELP is given or the options were initialized already
8772 * (jumping back to a help file with CTRL-T or CTRL-O) */
8773 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8774 || buf->b_p_initialized;
8775 if (dont_do_help) /* don't free b_p_isk */
8776 {
8777 save_p_isk = buf->b_p_isk;
8778 buf->b_p_isk = NULL;
8779 }
8780 /*
8781 * Always free the allocated strings.
8782 * If not already initialized, set 'readonly' and copy 'fileformat'.
8783 */
8784 if (!buf->b_p_initialized)
8785 {
8786 free_buf_options(buf, TRUE);
8787 buf->b_p_ro = FALSE; /* don't copy readonly */
8788 buf->b_p_tx = p_tx;
8789#ifdef FEAT_MBYTE
8790 buf->b_p_fenc = vim_strsave(p_fenc);
8791#endif
8792 buf->b_p_ff = vim_strsave(p_ff);
8793#if defined(FEAT_QUICKFIX)
8794 buf->b_p_bh = empty_option;
8795 buf->b_p_bt = empty_option;
8796#endif
8797 }
8798 else
8799 free_buf_options(buf, FALSE);
8800
8801 buf->b_p_ai = p_ai;
8802 buf->b_p_ai_nopaste = p_ai_nopaste;
8803 buf->b_p_sw = p_sw;
8804 buf->b_p_tw = p_tw;
8805 buf->b_p_tw_nopaste = p_tw_nopaste;
8806 buf->b_p_tw_nobin = p_tw_nobin;
8807 buf->b_p_wm = p_wm;
8808 buf->b_p_wm_nopaste = p_wm_nopaste;
8809 buf->b_p_wm_nobin = p_wm_nobin;
8810 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00008811#ifdef FEAT_MBYTE
8812 buf->b_p_bomb = p_bomb;
8813#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814 buf->b_p_et = p_et;
8815 buf->b_p_et_nobin = p_et_nobin;
8816 buf->b_p_ml = p_ml;
8817 buf->b_p_ml_nobin = p_ml_nobin;
8818 buf->b_p_inf = p_inf;
8819 buf->b_p_swf = p_swf;
8820#ifdef FEAT_INS_EXPAND
8821 buf->b_p_cpt = vim_strsave(p_cpt);
8822#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008823#ifdef FEAT_COMPL_FUNC
8824 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00008825 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 buf->b_p_sts = p_sts;
8828 buf->b_p_sts_nopaste = p_sts_nopaste;
8829#ifndef SHORT_FNAME
8830 buf->b_p_sn = p_sn;
8831#endif
8832#ifdef FEAT_COMMENTS
8833 buf->b_p_com = vim_strsave(p_com);
8834#endif
8835#ifdef FEAT_FOLDING
8836 buf->b_p_cms = vim_strsave(p_cms);
8837#endif
8838 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008839 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 buf->b_p_nf = vim_strsave(p_nf);
8841 buf->b_p_mps = vim_strsave(p_mps);
8842#ifdef FEAT_SMARTINDENT
8843 buf->b_p_si = p_si;
8844#endif
8845 buf->b_p_ci = p_ci;
8846#ifdef FEAT_CINDENT
8847 buf->b_p_cin = p_cin;
8848 buf->b_p_cink = vim_strsave(p_cink);
8849 buf->b_p_cino = vim_strsave(p_cino);
8850#endif
8851#ifdef FEAT_AUTOCMD
8852 /* Don't copy 'filetype', it must be detected */
8853 buf->b_p_ft = empty_option;
8854#endif
8855#ifdef FEAT_OSFILETYPE
8856 buf->b_p_oft = vim_strsave(p_oft);
8857#endif
8858 buf->b_p_pi = p_pi;
8859#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8860 buf->b_p_cinw = vim_strsave(p_cinw);
8861#endif
8862#ifdef FEAT_LISP
8863 buf->b_p_lisp = p_lisp;
8864#endif
8865#ifdef FEAT_SYN_HL
8866 /* Don't copy 'syntax', it must be set */
8867 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008868 buf->b_p_smc = p_smc;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008869 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00008870 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008871 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008872 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873#endif
8874#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8875 buf->b_p_inde = vim_strsave(p_inde);
8876 buf->b_p_indk = vim_strsave(p_indk);
8877#endif
8878#ifdef FEAT_CRYPT
8879 buf->b_p_key = vim_strsave(p_key);
8880#endif
8881#ifdef FEAT_SEARCHPATH
8882 buf->b_p_sua = vim_strsave(p_sua);
8883#endif
8884#ifdef FEAT_KEYMAP
8885 buf->b_p_keymap = vim_strsave(p_keymap);
8886 buf->b_kmap_state |= KEYMAP_INIT;
8887#endif
8888 /* This isn't really an option, but copying the langmap and IME
8889 * state from the current buffer is better than resetting it. */
8890 buf->b_p_iminsert = p_iminsert;
8891 buf->b_p_imsearch = p_imsearch;
8892
8893 /* options that are normally global but also have a local value
8894 * are not copied, start using the global value */
8895 buf->b_p_ar = -1;
8896#ifdef FEAT_QUICKFIX
8897 buf->b_p_gp = empty_option;
8898 buf->b_p_mp = empty_option;
8899 buf->b_p_efm = empty_option;
8900#endif
8901 buf->b_p_ep = empty_option;
8902 buf->b_p_kp = empty_option;
8903 buf->b_p_path = empty_option;
8904 buf->b_p_tags = empty_option;
8905#ifdef FEAT_FIND_ID
8906 buf->b_p_def = empty_option;
8907 buf->b_p_inc = empty_option;
8908# ifdef FEAT_EVAL
8909 buf->b_p_inex = vim_strsave(p_inex);
8910# endif
8911#endif
8912#ifdef FEAT_INS_EXPAND
8913 buf->b_p_dict = empty_option;
8914 buf->b_p_tsr = empty_option;
8915#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008916#ifdef FEAT_TEXTOBJ
8917 buf->b_p_qe = vim_strsave(p_qe);
8918#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919
8920 /*
8921 * Don't copy the options set by ex_help(), use the saved values,
8922 * when going from a help buffer to a non-help buffer.
8923 * Don't touch these at all when BCO_NOHELP is used and going from
8924 * or to a help buffer.
8925 */
8926 if (dont_do_help)
8927 buf->b_p_isk = save_p_isk;
8928 else
8929 {
8930 buf->b_p_isk = vim_strsave(p_isk);
8931 did_isk = TRUE;
8932 buf->b_p_ts = p_ts;
8933 buf->b_help = FALSE;
8934#ifdef FEAT_QUICKFIX
8935 if (buf->b_p_bt[0] == 'h')
8936 clear_string_option(&buf->b_p_bt);
8937#endif
8938 buf->b_p_ma = p_ma;
8939 }
8940 }
8941
8942 /*
8943 * When the options should be copied (ignoring BCO_ALWAYS), set the
8944 * flag that indicates that the options have been initialized.
8945 */
8946 if (should_copy)
8947 buf->b_p_initialized = TRUE;
8948 }
8949
8950 check_buf_options(buf); /* make sure we don't have NULLs */
8951 if (did_isk)
8952 (void)buf_init_chartab(buf, FALSE);
8953}
8954
8955/*
8956 * Reset the 'modifiable' option and its default value.
8957 */
8958 void
8959reset_modifiable()
8960{
8961 int opt_idx;
8962
8963 curbuf->b_p_ma = FALSE;
8964 p_ma = FALSE;
8965 opt_idx = findoption((char_u *)"ma");
8966 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8967}
8968
8969/*
8970 * Set the global value for 'iminsert' to the local value.
8971 */
8972 void
8973set_iminsert_global()
8974{
8975 p_iminsert = curbuf->b_p_iminsert;
8976}
8977
8978/*
8979 * Set the global value for 'imsearch' to the local value.
8980 */
8981 void
8982set_imsearch_global()
8983{
8984 p_imsearch = curbuf->b_p_imsearch;
8985}
8986
8987#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8988static int expand_option_idx = -1;
8989static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8990static int expand_option_flags = 0;
8991
8992 void
8993set_context_in_set_cmd(xp, arg, opt_flags)
8994 expand_T *xp;
8995 char_u *arg;
8996 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8997{
8998 int nextchar;
8999 long_u flags = 0; /* init for GCC */
9000 int opt_idx = 0; /* init for GCC */
9001 char_u *p;
9002 char_u *s;
9003 int is_term_option = FALSE;
9004 int key;
9005
9006 expand_option_flags = opt_flags;
9007
9008 xp->xp_context = EXPAND_SETTINGS;
9009 if (*arg == NUL)
9010 {
9011 xp->xp_pattern = arg;
9012 return;
9013 }
9014 p = arg + STRLEN(arg) - 1;
9015 if (*p == ' ' && *(p - 1) != '\\')
9016 {
9017 xp->xp_pattern = p + 1;
9018 return;
9019 }
9020 while (p > arg)
9021 {
9022 s = p;
9023 /* count number of backslashes before ' ' or ',' */
9024 if (*p == ' ' || *p == ',')
9025 {
9026 while (s > arg && *(s - 1) == '\\')
9027 --s;
9028 }
9029 /* break at a space with an even number of backslashes */
9030 if (*p == ' ' && ((p - s) & 1) == 0)
9031 {
9032 ++p;
9033 break;
9034 }
9035 --p;
9036 }
9037 if (STRNCMP(p, "no", 2) == 0)
9038 {
9039 xp->xp_context = EXPAND_BOOL_SETTINGS;
9040 p += 2;
9041 }
9042 if (STRNCMP(p, "inv", 3) == 0)
9043 {
9044 xp->xp_context = EXPAND_BOOL_SETTINGS;
9045 p += 3;
9046 }
9047 xp->xp_pattern = arg = p;
9048 if (*arg == '<')
9049 {
9050 while (*p != '>')
9051 if (*p++ == NUL) /* expand terminal option name */
9052 return;
9053 key = get_special_key_code(arg + 1);
9054 if (key == 0) /* unknown name */
9055 {
9056 xp->xp_context = EXPAND_NOTHING;
9057 return;
9058 }
9059 nextchar = *++p;
9060 is_term_option = TRUE;
9061 expand_option_name[2] = KEY2TERMCAP0(key);
9062 expand_option_name[3] = KEY2TERMCAP1(key);
9063 }
9064 else
9065 {
9066 if (p[0] == 't' && p[1] == '_')
9067 {
9068 p += 2;
9069 if (*p != NUL)
9070 ++p;
9071 if (*p == NUL)
9072 return; /* expand option name */
9073 nextchar = *++p;
9074 is_term_option = TRUE;
9075 expand_option_name[2] = p[-2];
9076 expand_option_name[3] = p[-1];
9077 }
9078 else
9079 {
9080 /* Allow * wildcard */
9081 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9082 p++;
9083 if (*p == NUL)
9084 return;
9085 nextchar = *p;
9086 *p = NUL;
9087 opt_idx = findoption(arg);
9088 *p = nextchar;
9089 if (opt_idx == -1 || options[opt_idx].var == NULL)
9090 {
9091 xp->xp_context = EXPAND_NOTHING;
9092 return;
9093 }
9094 flags = options[opt_idx].flags;
9095 if (flags & P_BOOL)
9096 {
9097 xp->xp_context = EXPAND_NOTHING;
9098 return;
9099 }
9100 }
9101 }
9102 /* handle "-=" and "+=" */
9103 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9104 {
9105 ++p;
9106 nextchar = '=';
9107 }
9108 if ((nextchar != '=' && nextchar != ':')
9109 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9110 {
9111 xp->xp_context = EXPAND_UNSUCCESSFUL;
9112 return;
9113 }
9114 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9115 {
9116 xp->xp_context = EXPAND_OLD_SETTING;
9117 if (is_term_option)
9118 expand_option_idx = -1;
9119 else
9120 expand_option_idx = opt_idx;
9121 xp->xp_pattern = p + 1;
9122 return;
9123 }
9124 xp->xp_context = EXPAND_NOTHING;
9125 if (is_term_option || (flags & P_NUM))
9126 return;
9127
9128 xp->xp_pattern = p + 1;
9129
9130 if (flags & P_EXPAND)
9131 {
9132 p = options[opt_idx].var;
9133 if (p == (char_u *)&p_bdir
9134 || p == (char_u *)&p_dir
9135 || p == (char_u *)&p_path
9136 || p == (char_u *)&p_rtp
9137#ifdef FEAT_SEARCHPATH
9138 || p == (char_u *)&p_cdpath
9139#endif
9140#ifdef FEAT_SESSION
9141 || p == (char_u *)&p_vdir
9142#endif
9143 )
9144 {
9145 xp->xp_context = EXPAND_DIRECTORIES;
9146 if (p == (char_u *)&p_path
9147#ifdef FEAT_SEARCHPATH
9148 || p == (char_u *)&p_cdpath
9149#endif
9150 )
9151 xp->xp_backslash = XP_BS_THREE;
9152 else
9153 xp->xp_backslash = XP_BS_ONE;
9154 }
9155 else
9156 {
9157 xp->xp_context = EXPAND_FILES;
9158 /* for 'tags' need three backslashes for a space */
9159 if (p == (char_u *)&p_tags)
9160 xp->xp_backslash = XP_BS_THREE;
9161 else
9162 xp->xp_backslash = XP_BS_ONE;
9163 }
9164 }
9165
9166 /* For an option that is a list of file names, find the start of the
9167 * last file name. */
9168 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9169 {
9170 /* count number of backslashes before ' ' or ',' */
9171 if (*p == ' ' || *p == ',')
9172 {
9173 s = p;
9174 while (s > xp->xp_pattern && *(s - 1) == '\\')
9175 --s;
9176 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9177 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9178 {
9179 xp->xp_pattern = p + 1;
9180 break;
9181 }
9182 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009183
9184#ifdef FEAT_SYN_HL
9185 /* for 'spellsuggest' start at "file:" */
9186 if (options[opt_idx].var == (char_u *)&p_sps
9187 && STRNCMP(p, "file:", 5) == 0)
9188 {
9189 xp->xp_pattern = p + 5;
9190 break;
9191 }
9192#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009193 }
9194
9195 return;
9196}
9197
9198 int
9199ExpandSettings(xp, regmatch, num_file, file)
9200 expand_T *xp;
9201 regmatch_T *regmatch;
9202 int *num_file;
9203 char_u ***file;
9204{
9205 int num_normal = 0; /* Nr of matching non-term-code settings */
9206 int num_term = 0; /* Nr of matching terminal code settings */
9207 int opt_idx;
9208 int match;
9209 int count = 0;
9210 char_u *str;
9211 int loop;
9212 int is_term_opt;
9213 char_u name_buf[MAX_KEY_NAME_LEN];
9214 static char *(names[]) = {"all", "termcap"};
9215 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9216
9217 /* do this loop twice:
9218 * loop == 0: count the number of matching options
9219 * loop == 1: copy the matching options into allocated memory
9220 */
9221 for (loop = 0; loop <= 1; ++loop)
9222 {
9223 regmatch->rm_ic = ic;
9224 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9225 {
9226 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9227 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9228 {
9229 if (loop == 0)
9230 num_normal++;
9231 else
9232 (*file)[count++] = vim_strsave((char_u *)names[match]);
9233 }
9234 }
9235 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9236 opt_idx++)
9237 {
9238 if (options[opt_idx].var == NULL)
9239 continue;
9240 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9241 && !(options[opt_idx].flags & P_BOOL))
9242 continue;
9243 is_term_opt = istermoption(&options[opt_idx]);
9244 if (is_term_opt && num_normal > 0)
9245 continue;
9246 match = FALSE;
9247 if (vim_regexec(regmatch, str, (colnr_T)0)
9248 || (options[opt_idx].shortname != NULL
9249 && vim_regexec(regmatch,
9250 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9251 match = TRUE;
9252 else if (is_term_opt)
9253 {
9254 name_buf[0] = '<';
9255 name_buf[1] = 't';
9256 name_buf[2] = '_';
9257 name_buf[3] = str[2];
9258 name_buf[4] = str[3];
9259 name_buf[5] = '>';
9260 name_buf[6] = NUL;
9261 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9262 {
9263 match = TRUE;
9264 str = name_buf;
9265 }
9266 }
9267 if (match)
9268 {
9269 if (loop == 0)
9270 {
9271 if (is_term_opt)
9272 num_term++;
9273 else
9274 num_normal++;
9275 }
9276 else
9277 (*file)[count++] = vim_strsave(str);
9278 }
9279 }
9280 /*
9281 * Check terminal key codes, these are not in the option table
9282 */
9283 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9284 {
9285 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9286 {
9287 if (!isprint(str[0]) || !isprint(str[1]))
9288 continue;
9289
9290 name_buf[0] = 't';
9291 name_buf[1] = '_';
9292 name_buf[2] = str[0];
9293 name_buf[3] = str[1];
9294 name_buf[4] = NUL;
9295
9296 match = FALSE;
9297 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9298 match = TRUE;
9299 else
9300 {
9301 name_buf[0] = '<';
9302 name_buf[1] = 't';
9303 name_buf[2] = '_';
9304 name_buf[3] = str[0];
9305 name_buf[4] = str[1];
9306 name_buf[5] = '>';
9307 name_buf[6] = NUL;
9308
9309 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9310 match = TRUE;
9311 }
9312 if (match)
9313 {
9314 if (loop == 0)
9315 num_term++;
9316 else
9317 (*file)[count++] = vim_strsave(name_buf);
9318 }
9319 }
9320
9321 /*
9322 * Check special key names.
9323 */
9324 regmatch->rm_ic = TRUE; /* ignore case here */
9325 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9326 {
9327 name_buf[0] = '<';
9328 STRCPY(name_buf + 1, str);
9329 STRCAT(name_buf, ">");
9330
9331 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9332 {
9333 if (loop == 0)
9334 num_term++;
9335 else
9336 (*file)[count++] = vim_strsave(name_buf);
9337 }
9338 }
9339 }
9340 if (loop == 0)
9341 {
9342 if (num_normal > 0)
9343 *num_file = num_normal;
9344 else if (num_term > 0)
9345 *num_file = num_term;
9346 else
9347 return OK;
9348 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9349 if (*file == NULL)
9350 {
9351 *file = (char_u **)"";
9352 return FAIL;
9353 }
9354 }
9355 }
9356 return OK;
9357}
9358
9359 int
9360ExpandOldSetting(num_file, file)
9361 int *num_file;
9362 char_u ***file;
9363{
9364 char_u *var = NULL; /* init for GCC */
9365 char_u *buf;
9366
9367 *num_file = 0;
9368 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9369 if (*file == NULL)
9370 return FAIL;
9371
9372 /*
9373 * For a terminal key code expand_option_idx is < 0.
9374 */
9375 if (expand_option_idx < 0)
9376 {
9377 var = find_termcode(expand_option_name + 2);
9378 if (var == NULL)
9379 expand_option_idx = findoption(expand_option_name);
9380 }
9381
9382 if (expand_option_idx >= 0)
9383 {
9384 /* put string of option value in NameBuff */
9385 option_value2string(&options[expand_option_idx], expand_option_flags);
9386 var = NameBuff;
9387 }
9388 else if (var == NULL)
9389 var = (char_u *)"";
9390
9391 /* A backslash is required before some characters. This is the reverse of
9392 * what happens in do_set(). */
9393 buf = vim_strsave_escaped(var, escape_chars);
9394
9395 if (buf == NULL)
9396 {
9397 vim_free(*file);
9398 *file = NULL;
9399 return FAIL;
9400 }
9401
9402#ifdef BACKSLASH_IN_FILENAME
9403 /* For MS-Windows et al. we don't double backslashes at the start and
9404 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009405 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009406 if (var[0] == '\\' && var[1] == '\\'
9407 && expand_option_idx >= 0
9408 && (options[expand_option_idx].flags & P_EXPAND)
9409 && vim_isfilec(var[2])
9410 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9411 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009412#endif
9413
9414 *file[0] = buf;
9415 *num_file = 1;
9416 return OK;
9417}
9418#endif
9419
9420/*
9421 * Get the value for the numeric or string option *opp in a nice format into
9422 * NameBuff[]. Must not be called with a hidden option!
9423 */
9424 static void
9425option_value2string(opp, opt_flags)
9426 struct vimoption *opp;
9427 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9428{
9429 char_u *varp;
9430
9431 varp = get_varp_scope(opp, opt_flags);
9432
9433 if (opp->flags & P_NUM)
9434 {
9435 long wc = 0;
9436
9437 if (wc_use_keyname(varp, &wc))
9438 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9439 else if (wc != 0)
9440 STRCPY(NameBuff, transchar((int)wc));
9441 else
9442 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9443 }
9444 else /* P_STRING */
9445 {
9446 varp = *(char_u **)(varp);
9447 if (varp == NULL) /* just in case */
9448 NameBuff[0] = NUL;
9449#ifdef FEAT_CRYPT
9450 /* don't show the actual value of 'key', only that it's set */
9451 if (opp->var == (char_u *)&p_key && *varp)
9452 STRCPY(NameBuff, "*****");
9453#endif
9454 else if (opp->flags & P_EXPAND)
9455 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9456 /* Translate 'pastetoggle' into special key names */
9457 else if ((char_u **)opp->var == &p_pt)
9458 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9459 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009460 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009461 }
9462}
9463
9464/*
9465 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9466 * printed as a keyname.
9467 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9468 */
9469 static int
9470wc_use_keyname(varp, wcp)
9471 char_u *varp;
9472 long *wcp;
9473{
9474 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9475 {
9476 *wcp = *(long *)varp;
9477 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9478 return TRUE;
9479 }
9480 return FALSE;
9481}
9482
9483#ifdef FEAT_LANGMAP
9484/*
9485 * Any character has an equivalent character. This is used for keyboards that
9486 * have a special language mode that sends characters above 128 (although
9487 * other characters can be translated too).
9488 */
9489
9490/*
9491 * char_u langmap_mapchar[256];
9492 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9493 * "translate" native lang chars in normal mode or some cases of
9494 * insert mode without having to tediously switch lang mode back&forth.
9495 */
9496
9497 static void
9498langmap_init()
9499{
9500 int i;
9501
9502 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9503 langmap_mapchar[i] = i;
9504}
9505
9506/*
9507 * Called when langmap option is set; the language map can be
9508 * changed at any time!
9509 */
9510 static void
9511langmap_set()
9512{
9513 char_u *p;
9514 char_u *p2;
9515 int from, to;
9516
9517 langmap_init(); /* back to one-to-one map first */
9518
9519 for (p = p_langmap; p[0] != NUL; )
9520 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009521 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9522 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009523 {
9524 if (p2[0] == '\\' && p2[1] != NUL)
9525 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009526 }
9527 if (p2[0] == ';')
9528 ++p2; /* abcd;ABCD form, p2 points to A */
9529 else
9530 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9531 while (p[0])
9532 {
9533 if (p[0] == '\\' && p[1] != NUL)
9534 ++p;
9535#ifdef FEAT_MBYTE
9536 from = (*mb_ptr2char)(p);
9537#else
9538 from = p[0];
9539#endif
9540 if (p2 == NULL)
9541 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009542 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009543 if (p[0] == '\\')
9544 ++p;
9545#ifdef FEAT_MBYTE
9546 to = (*mb_ptr2char)(p);
9547#else
9548 to = p[0];
9549#endif
9550 }
9551 else
9552 {
9553 if (p2[0] == '\\')
9554 ++p2;
9555#ifdef FEAT_MBYTE
9556 to = (*mb_ptr2char)(p2);
9557#else
9558 to = p2[0];
9559#endif
9560 }
9561 if (to == NUL)
9562 {
9563 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9564 transchar(from));
9565 return;
9566 }
9567 langmap_mapchar[from & 255] = to;
9568
9569 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009570 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009571 if (p2 == NULL)
9572 {
9573 if (p[0] == ',')
9574 {
9575 ++p;
9576 break;
9577 }
9578 }
9579 else
9580 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009581 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582 if (*p == ';')
9583 {
9584 p = p2;
9585 if (p[0] != NUL)
9586 {
9587 if (p[0] != ',')
9588 {
9589 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9590 return;
9591 }
9592 ++p;
9593 }
9594 break;
9595 }
9596 }
9597 }
9598 }
9599}
9600#endif
9601
9602/*
9603 * Return TRUE if format option 'x' is in effect.
9604 * Take care of no formatting when 'paste' is set.
9605 */
9606 int
9607has_format_option(x)
9608 int x;
9609{
9610 if (p_paste)
9611 return FALSE;
9612 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9613}
9614
9615/*
9616 * Return TRUE if "x" is present in 'shortmess' option, or
9617 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9618 */
9619 int
9620shortmess(x)
9621 int x;
9622{
9623 return ( vim_strchr(p_shm, x) != NULL
9624 || (vim_strchr(p_shm, 'a') != NULL
9625 && vim_strchr((char_u *)SHM_A, x) != NULL));
9626}
9627
9628/*
9629 * paste_option_changed() - Called after p_paste was set or reset.
9630 */
9631 static void
9632paste_option_changed()
9633{
9634 static int old_p_paste = FALSE;
9635 static int save_sm = 0;
9636#ifdef FEAT_CMDL_INFO
9637 static int save_ru = 0;
9638#endif
9639#ifdef FEAT_RIGHTLEFT
9640 static int save_ri = 0;
9641 static int save_hkmap = 0;
9642#endif
9643 buf_T *buf;
9644
9645 if (p_paste)
9646 {
9647 /*
9648 * Paste switched from off to on.
9649 * Save the current values, so they can be restored later.
9650 */
9651 if (!old_p_paste)
9652 {
9653 /* save options for each buffer */
9654 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9655 {
9656 buf->b_p_tw_nopaste = buf->b_p_tw;
9657 buf->b_p_wm_nopaste = buf->b_p_wm;
9658 buf->b_p_sts_nopaste = buf->b_p_sts;
9659 buf->b_p_ai_nopaste = buf->b_p_ai;
9660 }
9661
9662 /* save global options */
9663 save_sm = p_sm;
9664#ifdef FEAT_CMDL_INFO
9665 save_ru = p_ru;
9666#endif
9667#ifdef FEAT_RIGHTLEFT
9668 save_ri = p_ri;
9669 save_hkmap = p_hkmap;
9670#endif
9671 /* save global values for local buffer options */
9672 p_tw_nopaste = p_tw;
9673 p_wm_nopaste = p_wm;
9674 p_sts_nopaste = p_sts;
9675 p_ai_nopaste = p_ai;
9676 }
9677
9678 /*
9679 * Always set the option values, also when 'paste' is set when it is
9680 * already on.
9681 */
9682 /* set options for each buffer */
9683 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9684 {
9685 buf->b_p_tw = 0; /* textwidth is 0 */
9686 buf->b_p_wm = 0; /* wrapmargin is 0 */
9687 buf->b_p_sts = 0; /* softtabstop is 0 */
9688 buf->b_p_ai = 0; /* no auto-indent */
9689 }
9690
9691 /* set global options */
9692 p_sm = 0; /* no showmatch */
9693#ifdef FEAT_CMDL_INFO
9694# ifdef FEAT_WINDOWS
9695 if (p_ru)
9696 status_redraw_all(); /* redraw to remove the ruler */
9697# endif
9698 p_ru = 0; /* no ruler */
9699#endif
9700#ifdef FEAT_RIGHTLEFT
9701 p_ri = 0; /* no reverse insert */
9702 p_hkmap = 0; /* no Hebrew keyboard */
9703#endif
9704 /* set global values for local buffer options */
9705 p_tw = 0;
9706 p_wm = 0;
9707 p_sts = 0;
9708 p_ai = 0;
9709 }
9710
9711 /*
9712 * Paste switched from on to off: Restore saved values.
9713 */
9714 else if (old_p_paste)
9715 {
9716 /* restore options for each buffer */
9717 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9718 {
9719 buf->b_p_tw = buf->b_p_tw_nopaste;
9720 buf->b_p_wm = buf->b_p_wm_nopaste;
9721 buf->b_p_sts = buf->b_p_sts_nopaste;
9722 buf->b_p_ai = buf->b_p_ai_nopaste;
9723 }
9724
9725 /* restore global options */
9726 p_sm = save_sm;
9727#ifdef FEAT_CMDL_INFO
9728# ifdef FEAT_WINDOWS
9729 if (p_ru != save_ru)
9730 status_redraw_all(); /* redraw to draw the ruler */
9731# endif
9732 p_ru = save_ru;
9733#endif
9734#ifdef FEAT_RIGHTLEFT
9735 p_ri = save_ri;
9736 p_hkmap = save_hkmap;
9737#endif
9738 /* set global values for local buffer options */
9739 p_tw = p_tw_nopaste;
9740 p_wm = p_wm_nopaste;
9741 p_sts = p_sts_nopaste;
9742 p_ai = p_ai_nopaste;
9743 }
9744
9745 old_p_paste = p_paste;
9746}
9747
9748/*
9749 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9750 *
9751 * Reset 'compatible' and set the values for options that didn't get set yet
9752 * to the Vim defaults.
9753 * Don't do this if the 'compatible' option has been set or reset before.
9754 */
9755 void
9756vimrc_found()
9757{
9758 int opt_idx;
9759
9760 if (!option_was_set((char_u *)"cp"))
9761 {
9762 p_cp = FALSE;
9763 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9764 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9765 set_option_default(opt_idx, OPT_FREE, FALSE);
9766 didset_options();
9767 }
9768}
9769
9770/*
9771 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9772 */
9773 void
9774change_compatible(on)
9775 int on;
9776{
9777 if (p_cp != on)
9778 {
9779 p_cp = on;
9780 compatible_set();
9781 }
9782 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9783}
9784
9785/*
9786 * Return TRUE when option "name" has been set.
9787 */
9788 int
9789option_was_set(name)
9790 char_u *name;
9791{
9792 int idx;
9793
9794 idx = findoption(name);
9795 if (idx < 0) /* unknown option */
9796 return FALSE;
9797 if (options[idx].flags & P_WAS_SET)
9798 return TRUE;
9799 return FALSE;
9800}
9801
9802/*
9803 * compatible_set() - Called when 'compatible' has been set or unset.
9804 *
9805 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9806 * flag) to a Vi compatible value.
9807 * When 'compatible' is unset: Set all options that have a different default
9808 * for Vim (without the P_VI_DEF flag) to that default.
9809 */
9810 static void
9811compatible_set()
9812{
9813 int opt_idx;
9814
9815 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9816 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9817 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9818 set_option_default(opt_idx, OPT_FREE, p_cp);
9819 didset_options();
9820}
9821
9822#ifdef FEAT_LINEBREAK
9823
9824# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9825 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009826 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009827# endif
9828
9829/*
9830 * fill_breakat_flags() -- called when 'breakat' changes value.
9831 */
9832 static void
9833fill_breakat_flags()
9834{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00009835 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009836 int i;
9837
9838 for (i = 0; i < 256; i++)
9839 breakat_flags[i] = FALSE;
9840
9841 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00009842 for (p = p_breakat; *p; p++)
9843 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844}
9845
9846# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009847 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009848# endif
9849
9850#endif
9851
9852/*
9853 * Check an option that can be a range of string values.
9854 *
9855 * Return OK for correct value, FAIL otherwise.
9856 * Empty is always OK.
9857 */
9858 static int
9859check_opt_strings(val, values, list)
9860 char_u *val;
9861 char **values;
9862 int list; /* when TRUE: accept a list of values */
9863{
9864 return opt_strings_flags(val, values, NULL, list);
9865}
9866
9867/*
9868 * Handle an option that can be a range of string values.
9869 * Set a flag in "*flagp" for each string present.
9870 *
9871 * Return OK for correct value, FAIL otherwise.
9872 * Empty is always OK.
9873 */
9874 static int
9875opt_strings_flags(val, values, flagp, list)
9876 char_u *val; /* new value */
9877 char **values; /* array of valid string values */
9878 unsigned *flagp;
9879 int list; /* when TRUE: accept a list of values */
9880{
9881 int i;
9882 int len;
9883 unsigned new_flags = 0;
9884
9885 while (*val)
9886 {
9887 for (i = 0; ; ++i)
9888 {
9889 if (values[i] == NULL) /* val not found in values[] */
9890 return FAIL;
9891
9892 len = (int)STRLEN(values[i]);
9893 if (STRNCMP(values[i], val, len) == 0
9894 && ((list && val[len] == ',') || val[len] == NUL))
9895 {
9896 val += len + (val[len] == ',');
9897 new_flags |= (1 << i);
9898 break; /* check next item in val list */
9899 }
9900 }
9901 }
9902 if (flagp != NULL)
9903 *flagp = new_flags;
9904
9905 return OK;
9906}
9907
9908/*
9909 * Read the 'wildmode' option, fill wim_flags[].
9910 */
9911 static int
9912check_opt_wim()
9913{
9914 char_u new_wim_flags[4];
9915 char_u *p;
9916 int i;
9917 int idx = 0;
9918
9919 for (i = 0; i < 4; ++i)
9920 new_wim_flags[i] = 0;
9921
9922 for (p = p_wim; *p; ++p)
9923 {
9924 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9925 ;
9926 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9927 return FAIL;
9928 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9929 new_wim_flags[idx] |= WIM_LONGEST;
9930 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9931 new_wim_flags[idx] |= WIM_FULL;
9932 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9933 new_wim_flags[idx] |= WIM_LIST;
9934 else
9935 return FAIL;
9936 p += i;
9937 if (*p == NUL)
9938 break;
9939 if (*p == ',')
9940 {
9941 if (idx == 3)
9942 return FAIL;
9943 ++idx;
9944 }
9945 }
9946
9947 /* fill remaining entries with last flag */
9948 while (idx < 3)
9949 {
9950 new_wim_flags[idx + 1] = new_wim_flags[idx];
9951 ++idx;
9952 }
9953
9954 /* only when there are no errors, wim_flags[] is changed */
9955 for (i = 0; i < 4; ++i)
9956 wim_flags[i] = new_wim_flags[i];
9957 return OK;
9958}
9959
9960/*
9961 * Check if backspacing over something is allowed.
9962 */
9963 int
9964can_bs(what)
9965 int what; /* BS_INDENT, BS_EOL or BS_START */
9966{
9967 switch (*p_bs)
9968 {
9969 case '2': return TRUE;
9970 case '1': return (what != BS_START);
9971 case '0': return FALSE;
9972 }
9973 return vim_strchr(p_bs, what) != NULL;
9974}
9975
9976/*
9977 * Save the current values of 'fileformat' and 'fileencoding', so that we know
9978 * the file must be considered changed when the value is different.
9979 */
9980 void
9981save_file_ff(buf)
9982 buf_T *buf;
9983{
9984 buf->b_start_ffc = *buf->b_p_ff;
9985 buf->b_start_eol = buf->b_p_eol;
9986#ifdef FEAT_MBYTE
9987 /* Only use free/alloc when necessary, they take time. */
9988 if (buf->b_start_fenc == NULL
9989 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9990 {
9991 vim_free(buf->b_start_fenc);
9992 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9993 }
9994#endif
9995}
9996
9997/*
9998 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9999 * from when editing started (save_file_ff() called).
10000 * Also when 'endofline' was changed and 'binary' is set.
10001 * Don't consider a new, empty buffer to be changed.
10002 */
10003 int
10004file_ff_differs(buf)
10005 buf_T *buf;
10006{
10007 if ((buf->b_flags & BF_NEW)
10008 && buf->b_ml.ml_line_count == 1
10009 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
10010 return FALSE;
10011 if (buf->b_start_ffc != *buf->b_p_ff)
10012 return TRUE;
10013 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
10014 return TRUE;
10015#ifdef FEAT_MBYTE
10016 if (buf->b_start_fenc == NULL)
10017 return (*buf->b_p_fenc != NUL);
10018 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
10019#else
10020 return FALSE;
10021#endif
10022}
10023
10024/*
10025 * return OK if "p" is a valid fileformat name, FAIL otherwise.
10026 */
10027 int
10028check_ff_value(p)
10029 char_u *p;
10030{
10031 return check_opt_strings(p, p_ff_values, FALSE);
10032}