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