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