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