blob: 98c0ad89adcc1818f96e9b4ca16696981b29264b [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 Moolenaarac6e65f2005-08-29 22:25:38 +00003260 char_u *p;
3261
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262 /*
3263 * If 'background' wasn't set by the user, try guessing the value,
3264 * depending on the terminal name. Only need to check for terminals
Bram Moolenaara21b29a2005-02-27 22:40:05 +00003265 * with a dark background, that can handle color. Recognized are:
3266 * "linux" Linux console
3267 * "screen.linux" Linux console with screen
Bram Moolenaar19a09a12005-03-04 23:39:37 +00003268 * "cygwin" Cygwin shell
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003269 * We also check the COLORFGBG environment variable, which is set by
3270 * rxvt and derivatives. This variable contains either two or three
3271 * values separated by semicolons; we want the last value in either
3272 * case. If this value is 0-6 or 8, our background is dark.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003274 idx = findoption((char_u *)"bg");
Bram Moolenaara21b29a2005-02-27 22:40:05 +00003275 if (!(options[idx].flags & P_WAS_SET)
3276 && (STRCMP(T_NAME, "linux") == 0
Bram Moolenaar19a09a12005-03-04 23:39:37 +00003277 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003278 || STRCMP(T_NAME, "cygwin") == 0
3279 || ((p = mch_getenv("COLORFGBG")) != NULL
3280 && (p = vim_strrchr(p, ';')) != NULL
3281 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3282 && p[2] == NUL)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003284 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE);
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00003285 /* don't mark it as set, when starting the GUI it may be
3286 * changed again */
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003287 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288 }
3289 }
3290#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003291
3292#ifdef CURSOR_SHAPE
3293 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3294#endif
3295#ifdef FEAT_MOUSESHAPE
3296 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3297#endif
3298#ifdef FEAT_PRINTER
3299 (void)parse_printoptions(); /* parse 'printoptions' default value */
3300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301}
3302
3303/*
3304 * Initialize the options, part three: After reading the .vimrc
3305 */
3306 void
3307set_init_3()
3308{
3309#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3310/*
3311 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3312 * This is done after other initializations, where 'shell' might have been
3313 * set, but only if they have not been set before.
3314 */
3315 char_u *p;
3316 int idx_srr;
3317 int do_srr;
3318#ifdef FEAT_QUICKFIX
3319 int idx_sp;
3320 int do_sp;
3321#endif
3322
3323 idx_srr = findoption((char_u *)"srr");
3324 do_srr = !(options[idx_srr].flags & P_WAS_SET);
3325#ifdef FEAT_QUICKFIX
3326 idx_sp = findoption((char_u *)"sp");
3327 do_sp = !(options[idx_sp].flags & P_WAS_SET);
3328#endif
3329
3330 /*
3331 * Isolate the name of the shell:
3332 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3333 * - Remove any argument. E.g., "csh -f" -> "csh".
3334 */
3335 p = gettail(p_sh);
3336 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3337 if (p != NULL)
3338 {
3339 /*
3340 * Default for p_sp is "| tee", for p_srr is ">".
3341 * For known shells it is changed here to include stderr.
3342 */
3343 if ( fnamecmp(p, "csh") == 0
3344 || fnamecmp(p, "tcsh") == 0
3345# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3346 || fnamecmp(p, "csh.exe") == 0
3347 || fnamecmp(p, "tcsh.exe") == 0
3348# endif
3349 )
3350 {
3351#if defined(FEAT_QUICKFIX)
3352 if (do_sp)
3353 {
3354# ifdef WIN3264
3355 p_sp = (char_u *)">&";
3356# else
3357 p_sp = (char_u *)"|& tee";
3358# endif
3359 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3360 }
3361#endif
3362 if (do_srr)
3363 {
3364 p_srr = (char_u *)">&";
3365 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3366 }
3367 }
3368 else
3369# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3370 if ( fnamecmp(p, "sh") == 0
3371 || fnamecmp(p, "ksh") == 0
3372 || fnamecmp(p, "zsh") == 0
3373 || fnamecmp(p, "bash") == 0
3374# ifdef WIN3264
3375 || fnamecmp(p, "cmd") == 0
3376 || fnamecmp(p, "sh.exe") == 0
3377 || fnamecmp(p, "ksh.exe") == 0
3378 || fnamecmp(p, "zsh.exe") == 0
3379 || fnamecmp(p, "bash.exe") == 0
3380 || fnamecmp(p, "cmd.exe") == 0
3381# endif
3382 )
3383# endif
3384 {
3385#if defined(FEAT_QUICKFIX)
3386 if (do_sp)
3387 {
3388# ifdef WIN3264
3389 p_sp = (char_u *)">%s 2>&1";
3390# else
3391 p_sp = (char_u *)"2>&1| tee";
3392# endif
3393 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3394 }
3395#endif
3396 if (do_srr)
3397 {
3398 p_srr = (char_u *)">%s 2>&1";
3399 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3400 }
3401 }
3402 vim_free(p);
3403 }
3404#endif
3405
3406#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3407 /*
3408 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3409 * This is done after other initializations, where 'shell' might have been
3410 * set, but only if they have not been set before. Default for p_shcf is
3411 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3412 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3413 * command.com. And for Win32 we need to set p_sxq instead.
3414 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003415 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416 {
3417 int idx3;
3418
3419 idx3 = findoption((char_u *)"shcf");
3420 if (!(options[idx3].flags & P_WAS_SET))
3421 {
3422 p_shcf = (char_u *)"-c";
3423 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3424 }
3425
3426# ifndef DJGPP
3427# ifdef WIN3264
3428 /* Somehow Win32 requires the quotes around the redirection too */
3429 idx3 = findoption((char_u *)"sxq");
3430 if (!(options[idx3].flags & P_WAS_SET))
3431 {
3432 p_sxq = (char_u *)"\"";
3433 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3434 }
3435# else
3436 idx3 = findoption((char_u *)"shq");
3437 if (!(options[idx3].flags & P_WAS_SET))
3438 {
3439 p_shq = (char_u *)"\"";
3440 options[idx3].def_val[VI_DEFAULT] = p_shq;
3441 }
3442# endif
3443# endif
3444 }
3445#endif
3446
3447#ifdef FEAT_TITLE
3448 set_title_defaults();
3449#endif
3450}
3451
3452#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3453/*
3454 * When 'helplang' is still at its default value, set it to "lang".
3455 * Only the first two characters of "lang" are used.
3456 */
3457 void
3458set_helplang_default(lang)
3459 char_u *lang;
3460{
3461 int idx;
3462
3463 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3464 return;
3465 idx = findoption((char_u *)"hlg");
3466 if (!(options[idx].flags & P_WAS_SET))
3467 {
3468 if (options[idx].flags & P_ALLOCED)
3469 free_string_option(p_hlg);
3470 p_hlg = vim_strsave(lang);
3471 if (p_hlg == NULL)
3472 p_hlg = empty_option;
3473 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003474 {
3475 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3476 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3477 {
3478 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3479 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3480 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003482 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 options[idx].flags |= P_ALLOCED;
3484 }
3485}
3486#endif
3487
3488#ifdef FEAT_GUI
3489static char_u *gui_bg_default __ARGS((void));
3490
3491 static char_u *
3492gui_bg_default()
3493{
3494 if (gui_get_lightness(gui.back_pixel) < 127)
3495 return (char_u *)"dark";
3496 return (char_u *)"light";
3497}
3498
3499/*
3500 * Option initializations that can only be done after opening the GUI window.
3501 */
3502 void
3503init_gui_options()
3504{
3505 /* Set the 'background' option according to the lightness of the
3506 * background color, unless the user has set it already. */
3507 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3508 {
3509 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3510 highlight_changed();
3511 }
3512}
3513#endif
3514
3515#ifdef FEAT_TITLE
3516/*
3517 * 'title' and 'icon' only default to true if they have not been set or reset
3518 * in .vimrc and we can read the old value.
3519 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3520 * they can be reset. This reduces startup time when using X on a remote
3521 * machine.
3522 */
3523 void
3524set_title_defaults()
3525{
3526 int idx1;
3527 long val;
3528
3529 /*
3530 * If GUI is (going to be) used, we can always set the window title and
3531 * icon name. Saves a bit of time, because the X11 display server does
3532 * not need to be contacted.
3533 */
3534 idx1 = findoption((char_u *)"title");
3535 if (!(options[idx1].flags & P_WAS_SET))
3536 {
3537#ifdef FEAT_GUI
3538 if (gui.starting || gui.in_use)
3539 val = TRUE;
3540 else
3541#endif
3542 val = mch_can_restore_title();
3543 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3544 p_title = val;
3545 }
3546 idx1 = findoption((char_u *)"icon");
3547 if (!(options[idx1].flags & P_WAS_SET))
3548 {
3549#ifdef FEAT_GUI
3550 if (gui.starting || gui.in_use)
3551 val = TRUE;
3552 else
3553#endif
3554 val = mch_can_restore_icon();
3555 options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3556 p_icon = val;
3557 }
3558}
3559#endif
3560
3561/*
3562 * Parse 'arg' for option settings.
3563 *
3564 * 'arg' may be IObuff, but only when no errors can be present and option
3565 * does not need to be expanded with option_expand().
3566 * "opt_flags":
3567 * 0 for ":set"
3568 * OPT_GLOBAL for ":setglobal"
3569 * OPT_LOCAL for ":setlocal" and a modeline
3570 * OPT_MODELINE for a modeline
3571 *
3572 * returns FAIL if an error is detected, OK otherwise
3573 */
3574 int
3575do_set(arg, opt_flags)
3576 char_u *arg; /* option string (may be written to!) */
3577 int opt_flags;
3578{
3579 int opt_idx;
3580 char_u *errmsg;
3581 char_u errbuf[80];
3582 char_u *startarg;
3583 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
3584 int nextchar; /* next non-white char after option name */
3585 int afterchar; /* character just after option name */
3586 int len;
3587 int i;
3588 long value;
3589 int key;
3590 long_u flags; /* flags for current option */
3591 char_u *varp = NULL; /* pointer to variable for current option */
3592 int did_show = FALSE; /* already showed one value */
3593 int adding; /* "opt+=arg" */
3594 int prepending; /* "opt^=arg" */
3595 int removing; /* "opt-=arg" */
3596 int cp_val = 0;
3597 char_u key_name[2];
3598
3599 if (*arg == NUL)
3600 {
3601 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003602 did_show = TRUE;
3603 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 }
3605
3606 while (*arg != NUL) /* loop to process all options */
3607 {
3608 errmsg = NULL;
3609 startarg = arg; /* remember for error message */
3610
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003611 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
3612 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613 {
3614 /*
3615 * ":set all" show all options.
3616 * ":set all&" set all options to their default value.
3617 */
3618 arg += 3;
3619 if (*arg == '&')
3620 {
3621 ++arg;
3622 /* Only for :set command set global value of local options. */
3623 set_options_default(OPT_FREE | opt_flags);
3624 }
3625 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003626 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003628 did_show = TRUE;
3629 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003631 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632 {
3633 showoptions(2, opt_flags);
3634 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003635 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 arg += 7;
3637 }
3638 else
3639 {
3640 prefix = 1;
3641 if (STRNCMP(arg, "no", 2) == 0)
3642 {
3643 prefix = 0;
3644 arg += 2;
3645 }
3646 else if (STRNCMP(arg, "inv", 3) == 0)
3647 {
3648 prefix = 2;
3649 arg += 3;
3650 }
3651
3652 /* find end of name */
3653 key = 0;
3654 if (*arg == '<')
3655 {
3656 nextchar = 0;
3657 opt_idx = -1;
3658 /* look out for <t_>;> */
3659 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3660 len = 5;
3661 else
3662 {
3663 len = 1;
3664 while (arg[len] != NUL && arg[len] != '>')
3665 ++len;
3666 }
3667 if (arg[len] != '>')
3668 {
3669 errmsg = e_invarg;
3670 goto skip;
3671 }
3672 arg[len] = NUL; /* put NUL after name */
3673 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3674 opt_idx = findoption(arg + 1);
3675 arg[len++] = '>'; /* restore '>' */
3676 if (opt_idx == -1)
3677 key = find_key_option(arg + 1);
3678 }
3679 else
3680 {
3681 len = 0;
3682 /*
3683 * The two characters after "t_" may not be alphanumeric.
3684 */
3685 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3686 len = 4;
3687 else
3688 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3689 ++len;
3690 nextchar = arg[len];
3691 arg[len] = NUL; /* put NUL after name */
3692 opt_idx = findoption(arg);
3693 arg[len] = nextchar; /* restore nextchar */
3694 if (opt_idx == -1)
3695 key = find_key_option(arg);
3696 }
3697
3698 /* remember character after option name */
3699 afterchar = arg[len];
3700
3701 /* skip white space, allow ":set ai ?" */
3702 while (vim_iswhite(arg[len]))
3703 ++len;
3704
3705 adding = FALSE;
3706 prepending = FALSE;
3707 removing = FALSE;
3708 if (arg[len] != NUL && arg[len + 1] == '=')
3709 {
3710 if (arg[len] == '+')
3711 {
3712 adding = TRUE; /* "+=" */
3713 ++len;
3714 }
3715 else if (arg[len] == '^')
3716 {
3717 prepending = TRUE; /* "^=" */
3718 ++len;
3719 }
3720 else if (arg[len] == '-')
3721 {
3722 removing = TRUE; /* "-=" */
3723 ++len;
3724 }
3725 }
3726 nextchar = arg[len];
3727
3728 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
3729 {
3730 errmsg = (char_u *)N_("E518: Unknown option");
3731 goto skip;
3732 }
3733
3734 if (opt_idx >= 0)
3735 {
3736 if (options[opt_idx].var == NULL) /* hidden option: skip */
3737 {
3738 /* Only give an error message when requesting the value of
3739 * a hidden option, ignore setting it. */
3740 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3741 && (!(options[opt_idx].flags & P_BOOL)
3742 || nextchar == '?'))
3743 errmsg = (char_u *)N_("E519: Option not supported");
3744 goto skip;
3745 }
3746
3747 flags = options[opt_idx].flags;
3748 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3749 }
3750 else
3751 {
3752 flags = P_STRING;
3753 if (key < 0)
3754 {
3755 key_name[0] = KEY2TERMCAP0(key);
3756 key_name[1] = KEY2TERMCAP1(key);
3757 }
3758 else
3759 {
3760 key_name[0] = KS_KEY;
3761 key_name[1] = (key & 0xff);
3762 }
3763 }
3764
3765 /* Disallow changing some options from modelines */
3766 if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3767 {
3768 errmsg = (char_u *)_("E520: Not allowed in a modeline");
3769 goto skip;
3770 }
3771
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00003772 /* Skip all options that are not window-local (used when showing
3773 * an already loaded buffer in a window). */
3774 if ((opt_flags & OPT_WINONLY)
3775 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
3776 goto skip;
3777
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778#ifdef HAVE_SANDBOX
3779 /* Disallow changing some options in the sandbox */
3780 if (sandbox > 0 && (flags & P_SECURE))
3781 {
3782 errmsg = (char_u *)_(e_sandbox);
3783 goto skip;
3784 }
3785#endif
3786
3787 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3788 {
3789 arg += len;
3790 cp_val = p_cp;
3791 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3792 {
3793 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
3794 {
3795 cp_val = FALSE;
3796 arg += 3;
3797 }
3798 else /* "opt&vi": set to Vi default */
3799 {
3800 cp_val = TRUE;
3801 arg += 2;
3802 }
3803 }
3804 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3805 && arg[1] != NUL && !vim_iswhite(arg[1]))
3806 {
3807 errmsg = e_trailing;
3808 goto skip;
3809 }
3810 }
3811
3812 /*
3813 * allow '=' and ':' as MSDOS command.com allows only one
3814 * '=' character per "set" command line. grrr. (jw)
3815 */
3816 if (nextchar == '?'
3817 || (prefix == 1
3818 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
3819 && !(flags & P_BOOL)))
3820 {
3821 /*
3822 * print value
3823 */
3824 if (did_show)
3825 msg_putchar('\n'); /* cursor below last one */
3826 else
3827 {
3828 gotocmdline(TRUE); /* cursor at status line */
3829 did_show = TRUE; /* remember that we did a line */
3830 }
3831 if (opt_idx >= 0)
3832 {
3833 showoneopt(&options[opt_idx], opt_flags);
3834#ifdef FEAT_EVAL
3835 if (p_verbose > 0)
Bram Moolenaar661b1822005-07-28 22:36:45 +00003836 last_set_msg(options[opt_idx].scriptID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837#endif
3838 }
3839 else
3840 {
3841 char_u *p;
3842
3843 p = find_termcode(key_name);
3844 if (p == NULL)
3845 {
3846 errmsg = (char_u *)N_("E518: Unknown option");
3847 goto skip;
3848 }
3849 else
3850 (void)show_one_termcode(key_name, p, TRUE);
3851 }
3852 if (nextchar != '?'
3853 && nextchar != NUL && !vim_iswhite(afterchar))
3854 errmsg = e_trailing;
3855 }
3856 else
3857 {
3858 if (flags & P_BOOL) /* boolean */
3859 {
3860 if (nextchar == '=' || nextchar == ':')
3861 {
3862 errmsg = e_invarg;
3863 goto skip;
3864 }
3865
3866 /*
3867 * ":set opt!": invert
3868 * ":set opt&": reset to default value
3869 * ":set opt<": reset to global value
3870 */
3871 if (nextchar == '!')
3872 value = *(int *)(varp) ^ 1;
3873 else if (nextchar == '&')
3874 value = (int)(long)options[opt_idx].def_val[
3875 ((flags & P_VI_DEF) || cp_val)
3876 ? VI_DEFAULT : VIM_DEFAULT];
3877 else if (nextchar == '<')
3878 {
3879 /* For 'autoread' -1 means to use global value. */
3880 if ((int *)varp == &curbuf->b_p_ar
3881 && opt_flags == OPT_LOCAL)
3882 value = -1;
3883 else
3884 value = *(int *)get_varp_scope(&(options[opt_idx]),
3885 OPT_GLOBAL);
3886 }
3887 else
3888 {
3889 /*
3890 * ":set invopt": invert
3891 * ":set opt" or ":set noopt": set or reset
3892 */
3893 if (nextchar != NUL && !vim_iswhite(afterchar))
3894 {
3895 errmsg = e_trailing;
3896 goto skip;
3897 }
3898 if (prefix == 2) /* inv */
3899 value = *(int *)(varp) ^ 1;
3900 else
3901 value = prefix;
3902 }
3903
3904 errmsg = set_bool_option(opt_idx, varp, (int)value,
3905 opt_flags);
3906 }
3907 else /* numeric or string */
3908 {
3909 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
3910 || prefix != 1)
3911 {
3912 errmsg = e_invarg;
3913 goto skip;
3914 }
3915
3916 if (flags & P_NUM) /* numeric */
3917 {
3918 /*
3919 * Different ways to set a number option:
3920 * & set to default value
3921 * < set to global value
3922 * <xx> accept special key codes for 'wildchar'
3923 * c accept any non-digit for 'wildchar'
3924 * [-]0-9 set number
3925 * other error
3926 */
3927 ++arg;
3928 if (nextchar == '&')
3929 value = (long)options[opt_idx].def_val[
3930 ((flags & P_VI_DEF) || cp_val)
3931 ? VI_DEFAULT : VIM_DEFAULT];
3932 else if (nextchar == '<')
3933 value = *(long *)get_varp_scope(&(options[opt_idx]),
3934 OPT_GLOBAL);
3935 else if (((long *)varp == &p_wc
3936 || (long *)varp == &p_wcm)
3937 && (*arg == '<'
3938 || *arg == '^'
3939 || ((!arg[1] || vim_iswhite(arg[1]))
3940 && !VIM_ISDIGIT(*arg))))
3941 {
3942 value = string_to_key(arg);
3943 if (value == 0 && (long *)varp != &p_wcm)
3944 {
3945 errmsg = e_invarg;
3946 goto skip;
3947 }
3948 }
3949 /* allow negative numbers (for 'undolevels') */
3950 else if (*arg == '-' || VIM_ISDIGIT(*arg))
3951 {
3952 i = 0;
3953 if (*arg == '-')
3954 i = 1;
3955#ifdef HAVE_STRTOL
3956 value = strtol((char *)arg, NULL, 0);
3957 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
3958 i += 2;
3959#else
3960 value = atol((char *)arg);
3961#endif
3962 while (VIM_ISDIGIT(arg[i]))
3963 ++i;
3964 if (arg[i] != NUL && !vim_iswhite(arg[i]))
3965 {
3966 errmsg = e_invarg;
3967 goto skip;
3968 }
3969 }
3970 else
3971 {
3972 errmsg = (char_u *)N_("E521: Number required after =");
3973 goto skip;
3974 }
3975
3976 if (adding)
3977 value = *(long *)varp + value;
3978 if (prepending)
3979 value = *(long *)varp * value;
3980 if (removing)
3981 value = *(long *)varp - value;
3982 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00003983 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 }
3985 else if (opt_idx >= 0) /* string */
3986 {
3987 char_u *save_arg = NULL;
3988 char_u *s = NULL;
3989 char_u *oldval; /* previous value if *varp */
3990 char_u *newval;
3991 char_u *origval;
3992 unsigned newlen;
3993 int comma;
3994 int bs;
3995 int new_value_alloced; /* new string option
3996 was allocated */
3997
3998 /* When using ":set opt=val" for a global option
3999 * with a local value the local value will be
4000 * reset, use the global value here. */
4001 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4002 && (int)options[opt_idx].indir >= PV_BOTH)
4003 varp = options[opt_idx].var;
4004
4005 /* The old value is kept until we are sure that the
4006 * new value is valid. */
4007 oldval = *(char_u **)varp;
4008 if (nextchar == '&') /* set to default val */
4009 {
4010 newval = options[opt_idx].def_val[
4011 ((flags & P_VI_DEF) || cp_val)
4012 ? VI_DEFAULT : VIM_DEFAULT];
4013 if ((char_u **)varp == &p_bg)
4014 {
4015 /* guess the value of 'background' */
4016#ifdef FEAT_GUI
4017 if (gui.in_use)
4018 newval = gui_bg_default();
4019 else
4020#endif
4021 if (STRCMP(T_NAME, "linux") == 0)
4022 newval = (char_u *)"dark";
4023 }
4024
4025 /* expand environment variables and ~ (since the
4026 * default value was already expanded, only
4027 * required when an environment variable was set
4028 * later */
4029 if (newval == NULL)
4030 newval = empty_option;
4031 else
4032 {
4033 s = option_expand(opt_idx, newval);
4034 if (s == NULL)
4035 s = newval;
4036 newval = vim_strsave(s);
4037 }
4038 new_value_alloced = TRUE;
4039 }
4040 else if (nextchar == '<') /* set to global val */
4041 {
4042 newval = vim_strsave(*(char_u **)get_varp_scope(
4043 &(options[opt_idx]), OPT_GLOBAL));
4044 new_value_alloced = TRUE;
4045 }
4046 else
4047 {
4048 ++arg; /* jump to after the '=' or ':' */
4049
4050 /*
4051 * Set 'keywordprg' to ":help" if an empty
4052 * value was passed to :set by the user.
4053 * Misuse errbuf[] for the resulting string.
4054 */
4055 if (varp == (char_u *)&p_kp
4056 && (*arg == NUL || *arg == ' '))
4057 {
4058 STRCPY(errbuf, ":help");
4059 save_arg = arg;
4060 arg = errbuf;
4061 }
4062 /*
4063 * Convert 'whichwrap' number to string, for
4064 * backwards compatibility with Vim 3.0.
4065 * Misuse errbuf[] for the resulting string.
4066 */
4067 else if (varp == (char_u *)&p_ww
4068 && VIM_ISDIGIT(*arg))
4069 {
4070 *errbuf = NUL;
4071 i = getdigits(&arg);
4072 if (i & 1)
4073 STRCAT(errbuf, "b,");
4074 if (i & 2)
4075 STRCAT(errbuf, "s,");
4076 if (i & 4)
4077 STRCAT(errbuf, "h,l,");
4078 if (i & 8)
4079 STRCAT(errbuf, "<,>,");
4080 if (i & 16)
4081 STRCAT(errbuf, "[,],");
4082 if (*errbuf != NUL) /* remove trailing , */
4083 errbuf[STRLEN(errbuf) - 1] = NUL;
4084 save_arg = arg;
4085 arg = errbuf;
4086 }
4087 /*
4088 * Remove '>' before 'dir' and 'bdir', for
4089 * backwards compatibility with version 3.0
4090 */
4091 else if ( *arg == '>'
4092 && (varp == (char_u *)&p_dir
4093 || varp == (char_u *)&p_bdir))
4094 {
4095 ++arg;
4096 }
4097
4098 /* When setting the local value of a global
4099 * option, the old value may be the global value. */
4100 if ((int)options[opt_idx].indir >= PV_BOTH
4101 && (opt_flags & OPT_LOCAL))
4102 origval = *(char_u **)get_varp(
4103 &options[opt_idx]);
4104 else
4105 origval = oldval;
4106
4107 /*
4108 * Copy the new string into allocated memory.
4109 * Can't use set_string_option_direct(), because
4110 * we need to remove the backslashes.
4111 */
4112 /* get a bit too much */
4113 newlen = (unsigned)STRLEN(arg) + 1;
4114 if (adding || prepending || removing)
4115 newlen += (unsigned)STRLEN(origval) + 1;
4116 newval = alloc(newlen);
4117 if (newval == NULL) /* out of mem, don't change */
4118 break;
4119 s = newval;
4120
4121 /*
4122 * Copy the string, skip over escaped chars.
4123 * For MS-DOS and WIN32 backslashes before normal
4124 * file name characters are not removed, and keep
4125 * backslash at start, for "\\machine\path", but
4126 * do remove it for "\\\\machine\\path".
4127 * The reverse is found in ExpandOldSetting().
4128 */
4129 while (*arg && !vim_iswhite(*arg))
4130 {
4131 if (*arg == '\\' && arg[1] != NUL
4132#ifdef BACKSLASH_IN_FILENAME
4133 && !((flags & P_EXPAND)
4134 && vim_isfilec(arg[1])
4135 && (arg[1] != '\\'
4136 || (s == newval
4137 && arg[2] != '\\')))
4138#endif
4139 )
4140 ++arg; /* remove backslash */
4141#ifdef FEAT_MBYTE
4142 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004143 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 {
4145 /* copy multibyte char */
4146 mch_memmove(s, arg, (size_t)i);
4147 arg += i;
4148 s += i;
4149 }
4150 else
4151#endif
4152 *s++ = *arg++;
4153 }
4154 *s = NUL;
4155
4156 /*
4157 * Expand environment variables and ~.
4158 * Don't do it when adding without inserting a
4159 * comma.
4160 */
4161 if (!(adding || prepending || removing)
4162 || (flags & P_COMMA))
4163 {
4164 s = option_expand(opt_idx, newval);
4165 if (s != NULL)
4166 {
4167 vim_free(newval);
4168 newlen = (unsigned)STRLEN(s) + 1;
4169 if (adding || prepending || removing)
4170 newlen += (unsigned)STRLEN(origval) + 1;
4171 newval = alloc(newlen);
4172 if (newval == NULL)
4173 break;
4174 STRCPY(newval, s);
4175 }
4176 }
4177
4178 /* locate newval[] in origval[] when removing it
4179 * and when adding to avoid duplicates */
4180 i = 0; /* init for GCC */
4181 if (removing || (flags & P_NODUP))
4182 {
4183 i = (int)STRLEN(newval);
4184 bs = 0;
4185 for (s = origval; *s; ++s)
4186 {
4187 if ((!(flags & P_COMMA)
4188 || s == origval
4189 || (s[-1] == ',' && !(bs & 1)))
4190 && STRNCMP(s, newval, i) == 0
4191 && (!(flags & P_COMMA)
4192 || s[i] == ','
4193 || s[i] == NUL))
4194 break;
4195 /* Count backspaces. Only a comma with an
4196 * even number of backspaces before it is
4197 * recognized as a separator */
4198 if (s > origval && s[-1] == '\\')
4199 ++bs;
4200 else
4201 bs = 0;
4202 }
4203
4204 /* do not add if already there */
4205 if ((adding || prepending) && *s)
4206 {
4207 prepending = FALSE;
4208 adding = FALSE;
4209 STRCPY(newval, origval);
4210 }
4211 }
4212
4213 /* concatenate the two strings; add a ',' if
4214 * needed */
4215 if (adding || prepending)
4216 {
4217 comma = ((flags & P_COMMA) && *origval != NUL
4218 && *newval != NUL);
4219 if (adding)
4220 {
4221 i = (int)STRLEN(origval);
4222 mch_memmove(newval + i + comma, newval,
4223 STRLEN(newval) + 1);
4224 mch_memmove(newval, origval, (size_t)i);
4225 }
4226 else
4227 {
4228 i = (int)STRLEN(newval);
4229 mch_memmove(newval + i + comma, origval,
4230 STRLEN(origval) + 1);
4231 }
4232 if (comma)
4233 newval[i] = ',';
4234 }
4235
4236 /* Remove newval[] from origval[]. (Note: "i" has
4237 * been set above and is used here). */
4238 if (removing)
4239 {
4240 STRCPY(newval, origval);
4241 if (*s)
4242 {
4243 /* may need to remove a comma */
4244 if (flags & P_COMMA)
4245 {
4246 if (s == origval)
4247 {
4248 /* include comma after string */
4249 if (s[i] == ',')
4250 ++i;
4251 }
4252 else
4253 {
4254 /* include comma before string */
4255 --s;
4256 ++i;
4257 }
4258 }
4259 mch_memmove(newval + (s - origval), s + i,
4260 STRLEN(s + i) + 1);
4261 }
4262 }
4263
4264 if (flags & P_FLAGLIST)
4265 {
4266 /* Remove flags that appear twice. */
4267 for (s = newval; *s; ++s)
4268 if ((!(flags & P_COMMA) || *s != ',')
4269 && vim_strchr(s + 1, *s) != NULL)
4270 {
4271 STRCPY(s, s + 1);
4272 --s;
4273 }
4274 }
4275
4276 if (save_arg != NULL) /* number for 'whichwrap' */
4277 arg = save_arg;
4278 new_value_alloced = TRUE;
4279 }
4280
4281 /* Set the new value. */
4282 *(char_u **)(varp) = newval;
4283
4284 /* Handle side effects, and set the global value for
4285 * ":set" on local options. */
4286 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4287 new_value_alloced, oldval, errbuf, opt_flags);
4288
4289 /* If error detected, print the error message. */
4290 if (errmsg != NULL)
4291 goto skip;
4292 }
4293 else /* key code option */
4294 {
4295 char_u *p;
4296
4297 if (nextchar == '&')
4298 {
4299 if (add_termcap_entry(key_name, TRUE) == FAIL)
4300 errmsg = (char_u *)N_("E522: Not found in termcap");
4301 }
4302 else
4303 {
4304 ++arg; /* jump to after the '=' or ':' */
4305 for (p = arg; *p && !vim_iswhite(*p); ++p)
4306 if (*p == '\\' && p[1] != NUL)
4307 ++p;
4308 nextchar = *p;
4309 *p = NUL;
4310 add_termcode(key_name, arg, FALSE);
4311 *p = nextchar;
4312 }
4313 if (full_screen)
4314 ttest(FALSE);
4315 redraw_all_later(CLEAR);
4316 }
4317 }
4318 if (opt_idx >= 0)
4319 options[opt_idx].flags |= P_WAS_SET;
4320 }
4321
4322skip:
4323 /*
4324 * Advance to next argument.
4325 * - skip until a blank found, taking care of backslashes
4326 * - skip blanks
4327 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4328 */
4329 for (i = 0; i < 2 ; ++i)
4330 {
4331 while (*arg != NUL && !vim_iswhite(*arg))
4332 if (*arg++ == '\\' && *arg != NUL)
4333 ++arg;
4334 arg = skipwhite(arg);
4335 if (*arg != '=')
4336 break;
4337 }
4338 }
4339
4340 if (errmsg != NULL)
4341 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004342 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004343 i = STRLEN(IObuff) + 2;
4344 if (i + (arg - startarg) < IOSIZE)
4345 {
4346 /* append the argument with the error */
4347 STRCAT(IObuff, ": ");
4348 mch_memmove(IObuff + i, startarg, (arg - startarg));
4349 IObuff[i + (arg - startarg)] = NUL;
4350 }
4351 /* make sure all characters are printable */
4352 trans_characters(IObuff, IOSIZE);
4353
4354 ++no_wait_return; /* wait_return done later */
4355 emsg(IObuff); /* show error highlighted */
4356 --no_wait_return;
4357
4358 return FAIL;
4359 }
4360
4361 arg = skipwhite(arg);
4362 }
4363
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004364theend:
4365 if (silent_mode && did_show)
4366 {
4367 /* After displaying option values in silent mode. */
4368 silent_mode = FALSE;
4369 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4370 msg_putchar('\n');
4371 cursor_on(); /* msg_start() switches it off */
4372 out_flush();
4373 silent_mode = TRUE;
4374 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4375 }
4376
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377 return OK;
4378}
4379
4380 static char_u *
4381illegal_char(errbuf, c)
4382 char_u *errbuf;
4383 int c;
4384{
4385 if (errbuf == NULL)
4386 return (char_u *)"";
4387 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004388 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 return errbuf;
4390}
4391
4392/*
4393 * Convert a key name or string into a key value.
4394 * Used for 'wildchar' and 'cedit' options.
4395 */
4396 static int
4397string_to_key(arg)
4398 char_u *arg;
4399{
4400 if (*arg == '<')
4401 return find_key_option(arg + 1);
4402 if (*arg == '^')
4403 return Ctrl_chr(arg[1]);
4404 return *arg;
4405}
4406
4407#ifdef FEAT_CMDWIN
4408/*
4409 * Check value of 'cedit' and set cedit_key.
4410 * Returns NULL if value is OK, error message otherwise.
4411 */
4412 static char_u *
4413check_cedit()
4414{
4415 int n;
4416
4417 if (*p_cedit == NUL)
4418 cedit_key = -1;
4419 else
4420 {
4421 n = string_to_key(p_cedit);
4422 if (vim_isprintc(n))
4423 return e_invarg;
4424 cedit_key = n;
4425 }
4426 return NULL;
4427}
4428#endif
4429
4430#ifdef FEAT_TITLE
4431/*
4432 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4433 * maketitle() to create and display it.
4434 * When switching the title or icon off, call mch_restore_title() to get
4435 * the old value back.
4436 */
4437 static void
4438did_set_title(icon)
4439 int icon; /* Did set icon instead of title */
4440{
4441 if (starting != NO_SCREEN
4442#ifdef FEAT_GUI
4443 && !gui.starting
4444#endif
4445 )
4446 {
4447 maketitle();
4448 if (icon)
4449 {
4450 if (!p_icon)
4451 mch_restore_title(2);
4452 }
4453 else
4454 {
4455 if (!p_title)
4456 mch_restore_title(1);
4457 }
4458 }
4459}
4460#endif
4461
4462/*
4463 * set_options_bin - called when 'bin' changes value.
4464 */
4465 void
4466set_options_bin(oldval, newval, opt_flags)
4467 int oldval;
4468 int newval;
4469 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4470{
4471 /*
4472 * The option values that are changed when 'bin' changes are
4473 * copied when 'bin is set and restored when 'bin' is reset.
4474 */
4475 if (newval)
4476 {
4477 if (!oldval) /* switched on */
4478 {
4479 if (!(opt_flags & OPT_GLOBAL))
4480 {
4481 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4482 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4483 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4484 curbuf->b_p_et_nobin = curbuf->b_p_et;
4485 }
4486 if (!(opt_flags & OPT_LOCAL))
4487 {
4488 p_tw_nobin = p_tw;
4489 p_wm_nobin = p_wm;
4490 p_ml_nobin = p_ml;
4491 p_et_nobin = p_et;
4492 }
4493 }
4494
4495 if (!(opt_flags & OPT_GLOBAL))
4496 {
4497 curbuf->b_p_tw = 0; /* no automatic line wrap */
4498 curbuf->b_p_wm = 0; /* no automatic line wrap */
4499 curbuf->b_p_ml = 0; /* no modelines */
4500 curbuf->b_p_et = 0; /* no expandtab */
4501 }
4502 if (!(opt_flags & OPT_LOCAL))
4503 {
4504 p_tw = 0;
4505 p_wm = 0;
4506 p_ml = FALSE;
4507 p_et = FALSE;
4508 p_bin = TRUE; /* needed when called for the "-b" argument */
4509 }
4510 }
4511 else if (oldval) /* switched off */
4512 {
4513 if (!(opt_flags & OPT_GLOBAL))
4514 {
4515 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4516 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4517 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4518 curbuf->b_p_et = curbuf->b_p_et_nobin;
4519 }
4520 if (!(opt_flags & OPT_LOCAL))
4521 {
4522 p_tw = p_tw_nobin;
4523 p_wm = p_wm_nobin;
4524 p_ml = p_ml_nobin;
4525 p_et = p_et_nobin;
4526 }
4527 }
4528}
4529
4530#ifdef FEAT_VIMINFO
4531/*
4532 * Find the parameter represented by the given character (eg ', :, ", or /),
4533 * and return its associated value in the 'viminfo' string.
4534 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00004535 * If the parameter is not specified in the string or there is no following
4536 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004537 */
4538 int
4539get_viminfo_parameter(type)
4540 int type;
4541{
4542 char_u *p;
4543
4544 p = find_viminfo_parameter(type);
4545 if (p != NULL && VIM_ISDIGIT(*p))
4546 return atoi((char *)p);
4547 return -1;
4548}
4549
4550/*
4551 * Find the parameter represented by the given character (eg ''', ':', '"', or
4552 * '/') in the 'viminfo' option and return a pointer to the string after it.
4553 * Return NULL if the parameter is not specified in the string.
4554 */
4555 char_u *
4556find_viminfo_parameter(type)
4557 int type;
4558{
4559 char_u *p;
4560
4561 for (p = p_viminfo; *p; ++p)
4562 {
4563 if (*p == type)
4564 return p + 1;
4565 if (*p == 'n') /* 'n' is always the last one */
4566 break;
4567 p = vim_strchr(p, ','); /* skip until next ',' */
4568 if (p == NULL) /* hit the end without finding parameter */
4569 break;
4570 }
4571 return NULL;
4572}
4573#endif
4574
4575/*
4576 * Expand environment variables for some string options.
4577 * These string options cannot be indirect!
4578 * If "val" is NULL expand the current value of the option.
4579 * Return pointer to NameBuff, or NULL when not expanded.
4580 */
4581 static char_u *
4582option_expand(opt_idx, val)
4583 int opt_idx;
4584 char_u *val;
4585{
4586 /* if option doesn't need expansion nothing to do */
4587 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4588 return NULL;
4589
4590 /* If val is longer than MAXPATHL no meaningful expansion can be done,
4591 * expand_env() would truncate the string. */
4592 if (val != NULL && STRLEN(val) > MAXPATHL)
4593 return NULL;
4594
4595 if (val == NULL)
4596 val = *(char_u **)options[opt_idx].var;
4597
4598 /*
4599 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4600 * Escape spaces when expanding 'tags', they are used to separate file
4601 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004602 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00004603 */
4604 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004605 (char_u **)options[opt_idx].var == &p_tags,
4606#ifdef FEAT_SYN_HL
4607 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
4608#endif
4609 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004610 if (STRCMP(NameBuff, val) == 0) /* they are the same */
4611 return NULL;
4612
4613 return NameBuff;
4614}
4615
4616/*
4617 * After setting various option values: recompute variables that depend on
4618 * option values.
4619 */
4620 static void
4621didset_options()
4622{
4623 /* initialize the table for 'iskeyword' et.al. */
4624 (void)init_chartab();
4625
4626 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4627 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4628#ifdef FEAT_SESSION
4629 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4630 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4631#endif
4632#ifdef FEAT_FOLDING
4633 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4634#endif
4635 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4636#ifdef FEAT_VIRTUALEDIT
4637 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4638#endif
4639#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4640 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4641#endif
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004642#ifdef FEAT_SYN_HL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004643 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00004644 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00004645 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00004646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004647#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4648 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4649#endif
4650#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4651 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4652#endif
4653#ifdef FEAT_CMDWIN
4654 /* set cedit_key */
4655 (void)check_cedit();
4656#endif
4657}
4658
4659/*
4660 * Check for string options that are NULL (normally only termcap options).
4661 */
4662 void
4663check_options()
4664{
4665 int opt_idx;
4666
4667 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4668 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4669 check_string_option((char_u **)get_varp(&(options[opt_idx])));
4670}
4671
4672/*
4673 * Check string options in a buffer for NULL value.
4674 */
4675 void
4676check_buf_options(buf)
4677 buf_T *buf;
4678{
4679#if defined(FEAT_QUICKFIX)
4680 check_string_option(&buf->b_p_bh);
4681 check_string_option(&buf->b_p_bt);
4682#endif
4683#ifdef FEAT_MBYTE
4684 check_string_option(&buf->b_p_fenc);
4685#endif
4686 check_string_option(&buf->b_p_ff);
4687#ifdef FEAT_FIND_ID
4688 check_string_option(&buf->b_p_def);
4689 check_string_option(&buf->b_p_inc);
4690# ifdef FEAT_EVAL
4691 check_string_option(&buf->b_p_inex);
4692# endif
4693#endif
4694#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4695 check_string_option(&buf->b_p_inde);
4696 check_string_option(&buf->b_p_indk);
4697#endif
4698#ifdef FEAT_CRYPT
4699 check_string_option(&buf->b_p_key);
4700#endif
4701 check_string_option(&buf->b_p_kp);
4702 check_string_option(&buf->b_p_mps);
4703 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00004704 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004705 check_string_option(&buf->b_p_isk);
4706#ifdef FEAT_COMMENTS
4707 check_string_option(&buf->b_p_com);
4708#endif
4709#ifdef FEAT_FOLDING
4710 check_string_option(&buf->b_p_cms);
4711#endif
4712 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004713#ifdef FEAT_TEXTOBJ
4714 check_string_option(&buf->b_p_qe);
4715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716#ifdef FEAT_SYN_HL
4717 check_string_option(&buf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00004718 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00004719 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00004720 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721#endif
4722#ifdef FEAT_SEARCHPATH
4723 check_string_option(&buf->b_p_sua);
4724#endif
4725#ifdef FEAT_CINDENT
4726 check_string_option(&buf->b_p_cink);
4727 check_string_option(&buf->b_p_cino);
4728#endif
4729#ifdef FEAT_AUTOCMD
4730 check_string_option(&buf->b_p_ft);
4731#endif
4732#ifdef FEAT_OSFILETYPE
4733 check_string_option(&buf->b_p_oft);
4734#endif
4735#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4736 check_string_option(&buf->b_p_cinw);
4737#endif
4738#ifdef FEAT_INS_EXPAND
4739 check_string_option(&buf->b_p_cpt);
4740#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004741#ifdef FEAT_COMPL_FUNC
4742 check_string_option(&buf->b_p_cfu);
4743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004744#ifdef FEAT_KEYMAP
4745 check_string_option(&buf->b_p_keymap);
4746#endif
4747#ifdef FEAT_QUICKFIX
4748 check_string_option(&buf->b_p_gp);
4749 check_string_option(&buf->b_p_mp);
4750 check_string_option(&buf->b_p_efm);
4751#endif
4752 check_string_option(&buf->b_p_ep);
4753 check_string_option(&buf->b_p_path);
4754 check_string_option(&buf->b_p_tags);
4755#ifdef FEAT_INS_EXPAND
4756 check_string_option(&buf->b_p_dict);
4757 check_string_option(&buf->b_p_tsr);
4758#endif
4759}
4760
4761/*
4762 * Free the string allocated for an option.
4763 * Checks for the string being empty_option. This may happen if we're out of
4764 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4765 * check_options().
4766 * Does NOT check for P_ALLOCED flag!
4767 */
4768 void
4769free_string_option(p)
4770 char_u *p;
4771{
4772 if (p != empty_option)
4773 vim_free(p);
4774}
4775
4776 void
4777clear_string_option(pp)
4778 char_u **pp;
4779{
4780 if (*pp != empty_option)
4781 vim_free(*pp);
4782 *pp = empty_option;
4783}
4784
4785 static void
4786check_string_option(pp)
4787 char_u **pp;
4788{
4789 if (*pp == NULL)
4790 *pp = empty_option;
4791}
4792
4793/*
4794 * Mark a terminal option as allocated, found by a pointer into term_strings[].
4795 */
4796 void
4797set_term_option_alloced(p)
4798 char_u **p;
4799{
4800 int opt_idx;
4801
4802 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4803 if (options[opt_idx].var == (char_u *)p)
4804 {
4805 options[opt_idx].flags |= P_ALLOCED;
4806 return;
4807 }
4808 return; /* cannot happen: didn't find it! */
4809}
4810
4811/*
4812 * Set a string option to a new value (without checking the effect).
4813 * The string is copied into allocated memory.
4814 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4815 */
4816 void
4817set_string_option_direct(name, opt_idx, val, opt_flags)
4818 char_u *name;
4819 int opt_idx;
4820 char_u *val;
4821 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4822{
4823 char_u *s;
4824 char_u **varp;
4825 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
4826
4827 if (opt_idx == -1) /* use name */
4828 {
4829 opt_idx = findoption(name);
4830 if (opt_idx == -1) /* not found (should not happen) */
4831 return;
4832 }
4833
4834 if (options[opt_idx].var == NULL) /* can't set hidden option */
4835 return;
4836
4837 s = vim_strsave(val);
4838 if (s != NULL)
4839 {
4840 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4841 both ? OPT_LOCAL : opt_flags);
4842 if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
4843 free_string_option(*varp);
4844 *varp = s;
4845
4846 /* For buffer/window local option may also set the global value. */
4847 if (both)
4848 set_string_option_global(opt_idx, varp);
4849
4850 options[opt_idx].flags |= P_ALLOCED;
4851
4852 /* When setting both values of a global option with a local value,
4853 * make the local value empty, so that the global value is used. */
4854 if ((int)options[opt_idx].indir >= PV_BOTH && both)
4855 {
4856 free_string_option(*varp);
4857 *varp = empty_option;
4858 }
4859 }
4860}
4861
4862/*
4863 * Set global value for string option when it's a local option.
4864 */
4865 static void
4866set_string_option_global(opt_idx, varp)
4867 int opt_idx; /* option index */
4868 char_u **varp; /* pointer to option variable */
4869{
4870 char_u **p, *s;
4871
4872 /* the global value is always allocated */
4873 if (options[opt_idx].var == VAR_WIN)
4874 p = (char_u **)GLOBAL_WO(varp);
4875 else
4876 p = (char_u **)options[opt_idx].var;
4877 if (options[opt_idx].indir != PV_NONE
4878 && p != varp
4879 && (s = vim_strsave(*varp)) != NULL)
4880 {
4881 free_string_option(*p);
4882 *p = s;
4883 }
4884}
4885
4886/*
4887 * Set a string option to a new value, and handle the effects.
4888 */
4889 static void
4890set_string_option(opt_idx, value, opt_flags)
4891 int opt_idx;
4892 char_u *value;
4893 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4894{
4895 char_u *s;
4896 char_u **varp;
4897 char_u *oldval;
4898
4899 if (options[opt_idx].var == NULL) /* don't set hidden option */
4900 return;
4901
4902 s = vim_strsave(value);
4903 if (s != NULL)
4904 {
4905 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4906 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4907 ? ((int)options[opt_idx].indir >= PV_BOTH
4908 ? OPT_GLOBAL : OPT_LOCAL)
4909 : opt_flags);
4910 oldval = *varp;
4911 *varp = s;
4912 options[opt_idx].flags |= P_WAS_SET;
4913 (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
4914 opt_flags);
4915 }
4916}
4917
4918/*
4919 * Handle string options that need some action to perform when changed.
4920 * Returns NULL for success, or an error message for an error.
4921 */
4922 static char_u *
4923did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
4924 opt_flags)
4925 int opt_idx; /* index in options[] table */
4926 char_u **varp; /* pointer to the option variable */
4927 int new_value_alloced; /* new value was allocated */
4928 char_u *oldval; /* previous value of the option */
4929 char_u *errbuf; /* buffer for errors, or NULL */
4930 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4931{
4932 char_u *errmsg = NULL;
4933 char_u *s, *p;
4934 int did_chartab = FALSE;
4935 char_u **gvarp;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00004936 int free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004937
4938 /* Get the global option to compare with, otherwise we would have to check
4939 * two values for all local options. */
4940 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
4941
4942 /* Disallow changing some options from secure mode */
4943 if ((secure
4944#ifdef HAVE_SANDBOX
4945 || sandbox != 0
4946#endif
4947 ) && (options[opt_idx].flags & P_SECURE))
4948 {
4949 errmsg = e_secure;
4950 }
4951
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004952 /* Check for a "normal" file name in some options. Disallow a path
4953 * separator (slash and/or backslash), wildcards and characters that are
4954 * often illegal in a file name. */
4955 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00004956 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004957 {
4958 errmsg = e_invarg;
4959 }
4960
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 /* 'term' */
4962 else if (varp == &T_NAME)
4963 {
4964 if (T_NAME[0] == NUL)
4965 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
4966#ifdef FEAT_GUI
4967 if (gui.in_use)
4968 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
4969 else if (term_is_gui(T_NAME))
4970 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
4971#endif
4972 else if (set_termname(T_NAME) == FAIL)
4973 errmsg = (char_u *)N_("E522: Not found in termcap");
4974 else
4975 /* Screen colors may have changed. */
4976 redraw_later_clear();
4977 }
4978
4979 /* 'backupcopy' */
4980 else if (varp == &p_bkc)
4981 {
4982 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
4983 errmsg = e_invarg;
4984 if (((bkc_flags & BKC_AUTO) != 0)
4985 + ((bkc_flags & BKC_YES) != 0)
4986 + ((bkc_flags & BKC_NO) != 0) != 1)
4987 {
4988 /* Must have exactly one of "auto", "yes" and "no". */
4989 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
4990 errmsg = e_invarg;
4991 }
4992 }
4993
4994 /* 'backupext' and 'patchmode' */
4995 else if (varp == &p_bex || varp == &p_pm)
4996 {
4997 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
4998 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
4999 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5000 }
5001
5002 /*
5003 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5004 * If the new option is invalid, use old value. 'lisp' option: refill
5005 * chartab[] for '-' char
5006 */
5007 else if ( varp == &p_isi
5008 || varp == &(curbuf->b_p_isk)
5009 || varp == &p_isp
5010 || varp == &p_isf)
5011 {
5012 if (init_chartab() == FAIL)
5013 {
5014 did_chartab = TRUE; /* need to restore it below */
5015 errmsg = e_invarg; /* error in value */
5016 }
5017 }
5018
5019 /* 'helpfile' */
5020 else if (varp == &p_hf)
5021 {
5022 /* May compute new values for $VIM and $VIMRUNTIME */
5023 if (didset_vim)
5024 {
5025 vim_setenv((char_u *)"VIM", (char_u *)"");
5026 didset_vim = FALSE;
5027 }
5028 if (didset_vimruntime)
5029 {
5030 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5031 didset_vimruntime = FALSE;
5032 }
5033 }
5034
5035#ifdef FEAT_MULTI_LANG
5036 /* 'helplang' */
5037 else if (varp == &p_hlg)
5038 {
5039 /* Check for "", "ab", "ab,cd", etc. */
5040 for (s = p_hlg; *s != NUL; s += 3)
5041 {
5042 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5043 {
5044 errmsg = e_invarg;
5045 break;
5046 }
5047 if (s[2] == NUL)
5048 break;
5049 }
5050 }
5051#endif
5052
5053 /* 'highlight' */
5054 else if (varp == &p_hl)
5055 {
5056 if (highlight_changed() == FAIL)
5057 errmsg = e_invarg; /* invalid flags */
5058 }
5059
5060 /* 'nrformats' */
5061 else if (gvarp == &p_nf)
5062 {
5063 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5064 errmsg = e_invarg;
5065 }
5066
5067#ifdef FEAT_SESSION
5068 /* 'sessionoptions' */
5069 else if (varp == &p_ssop)
5070 {
5071 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5072 errmsg = e_invarg;
5073 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5074 {
5075 /* Don't allow both "sesdir" and "curdir". */
5076 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5077 errmsg = e_invarg;
5078 }
5079 }
5080 /* 'viewoptions' */
5081 else if (varp == &p_vop)
5082 {
5083 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5084 errmsg = e_invarg;
5085 }
5086#endif
5087
5088 /* 'scrollopt' */
5089#ifdef FEAT_SCROLLBIND
5090 else if (varp == &p_sbo)
5091 {
5092 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5093 errmsg = e_invarg;
5094 }
5095#endif
5096
5097 /* 'ambiwidth' */
5098#ifdef FEAT_MBYTE
5099 else if (varp == &p_ambw)
5100 {
5101 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5102 errmsg = e_invarg;
5103 }
5104#endif
5105
5106 /* 'background' */
5107 else if (varp == &p_bg)
5108 {
5109 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5110 {
5111#ifdef FEAT_EVAL
5112 int dark = (*p_bg == 'd');
5113#endif
5114
5115 init_highlight(FALSE, FALSE);
5116
5117#ifdef FEAT_EVAL
5118 if (dark != (*p_bg == 'd')
5119 && get_var_value((char_u *)"g:colors_name") != NULL)
5120 {
5121 /* The color scheme must have set 'background' back to another
5122 * value, that's not what we want here. Disable the color
5123 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005124 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 free_string_option(p_bg);
5126 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5127 check_string_option(&p_bg);
5128 init_highlight(FALSE, FALSE);
5129 }
5130#endif
5131 }
5132 else
5133 errmsg = e_invarg;
5134 }
5135
5136 /* 'wildmode' */
5137 else if (varp == &p_wim)
5138 {
5139 if (check_opt_wim() == FAIL)
5140 errmsg = e_invarg;
5141 }
5142
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005143#ifdef FEAT_CMDL_COMPL
5144 /* 'wildoptions' */
5145 else if (varp == &p_wop)
5146 {
5147 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5148 errmsg = e_invarg;
5149 }
5150#endif
5151
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152#ifdef FEAT_WAK
5153 /* 'winaltkeys' */
5154 else if (varp == &p_wak)
5155 {
5156 if (*p_wak == NUL
5157 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5158 errmsg = e_invarg;
5159# ifdef FEAT_MENU
5160# ifdef FEAT_GUI_MOTIF
5161 else if (gui.in_use)
5162 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5163# else
5164# ifdef FEAT_GUI_GTK
5165 else if (gui.in_use)
5166 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5167# endif
5168# endif
5169# endif
5170 }
5171#endif
5172
5173#ifdef FEAT_AUTOCMD
5174 /* 'eventignore' */
5175 else if (varp == &p_ei)
5176 {
5177 if (check_ei() == FAIL)
5178 errmsg = e_invarg;
5179 }
5180#endif
5181
5182#ifdef FEAT_MBYTE
5183 /* 'encoding' and 'fileencoding' */
5184 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5185 {
5186 if (gvarp == &p_fenc)
5187 {
5188 if (!curbuf->b_p_ma)
5189 errmsg = e_modifiable;
5190 else if (vim_strchr(*varp, ',') != NULL)
5191 /* No comma allowed in 'fileencoding'; catches confusing it
5192 * with 'fileencodings'. */
5193 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005194 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005195 {
5196# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005197 /* May show a "+" in the title now. */
5198 need_maketitle = TRUE;
5199# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005200 /* Add 'fileencoding' to the swap file. */
5201 ml_setflags(curbuf);
5202 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005203 }
5204 if (errmsg == NULL)
5205 {
5206 /* canonize the value, so that STRCMP() can be used on it */
5207 p = enc_canonize(*varp);
5208 if (p != NULL)
5209 {
5210 vim_free(*varp);
5211 *varp = p;
5212 }
5213 if (varp == &p_enc)
5214 {
5215 errmsg = mb_init();
5216# ifdef FEAT_TITLE
5217 need_maketitle = TRUE;
5218# endif
5219 }
5220 }
5221
5222# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5223 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5224 {
5225 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5226 if (STRCMP(p_tenc, "utf-8") != 0)
5227 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5228 }
5229# endif
5230
5231 if (errmsg == NULL)
5232 {
5233# ifdef FEAT_KEYMAP
5234 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5235 * (with another encoding). */
5236 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5237 (void)keymap_init();
5238# endif
5239
5240 /* When 'termencoding' is not empty and 'encoding' changes or when
5241 * 'termencoding' changes, need to setup for keyboard input and
5242 * display output conversion. */
5243 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5244 {
5245 convert_setup(&input_conv, p_tenc, p_enc);
5246 convert_setup(&output_conv, p_enc, p_tenc);
5247 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005248
5249# if defined(WIN3264) && defined(FEAT_MBYTE)
5250 /* $HOME may have characters in active code page. */
5251 if (varp == &p_enc)
5252 init_homedir();
5253# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005254 }
5255 }
5256#endif
5257
5258#if defined(FEAT_POSTSCRIPT)
5259 else if (varp == &p_penc)
5260 {
5261 /* Canonize printencoding if VIM standard one */
5262 p = enc_canonize(p_penc);
5263 if (p != NULL)
5264 {
5265 vim_free(p_penc);
5266 p_penc = p;
5267 }
5268 else
5269 {
5270 /* Ensure lower case and '-' for '_' */
5271 for (s = p_penc; *s != NUL; s++)
5272 {
5273 if (*s == '_')
5274 *s = '-';
5275 else
5276 *s = TOLOWER_ASC(*s);
5277 }
5278 }
5279 }
5280#endif
5281
Bram Moolenaar843ee412004-06-30 16:16:41 +00005282#if defined(FEAT_XIM) && ( defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005283 else if (varp == &p_imak)
5284 {
5285 if (gui.in_use && !im_xim_isvalid_imactivate())
5286 errmsg = e_invarg;
5287 }
5288#endif
5289
5290#ifdef FEAT_KEYMAP
5291 else if (varp == &curbuf->b_p_keymap)
5292 {
5293 /* load or unload key mapping tables */
5294 errmsg = keymap_init();
5295
5296 /* When successfully installed a new keymap switch on using it. */
5297 if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
5298 {
5299 curbuf->b_p_iminsert = B_IMODE_LMAP;
5300 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5301 curbuf->b_p_imsearch = B_IMODE_LMAP;
5302 set_iminsert_global();
5303 set_imsearch_global();
5304# ifdef FEAT_WINDOWS
5305 status_redraw_curbuf();
5306# endif
5307 }
5308 }
5309#endif
5310
5311 /* 'fileformat' */
5312 else if (gvarp == &p_ff)
5313 {
5314 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5315 errmsg = e_modifiable;
5316 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5317 errmsg = e_invarg;
5318 else
5319 {
5320 /* may also change 'textmode' */
5321 if (get_fileformat(curbuf) == EOL_DOS)
5322 curbuf->b_p_tx = TRUE;
5323 else
5324 curbuf->b_p_tx = FALSE;
5325#ifdef FEAT_TITLE
5326 need_maketitle = TRUE;
5327#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005328 /* update flag in swap file */
5329 ml_setflags(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330 }
5331 }
5332
5333 /* 'fileformats' */
5334 else if (varp == &p_ffs)
5335 {
5336 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5337 errmsg = e_invarg;
5338 else
5339 {
5340 /* also change 'textauto' */
5341 if (*p_ffs == NUL)
5342 p_ta = FALSE;
5343 else
5344 p_ta = TRUE;
5345 }
5346 }
5347
5348#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5349 /* 'cryptkey' */
5350 else if (gvarp == &p_key)
5351 {
5352 /* Make sure the ":set" command doesn't show the new value in the
5353 * history. */
5354 remove_key_from_history();
5355 }
5356#endif
5357
5358 /* 'matchpairs' */
5359 else if (gvarp == &p_mps)
5360 {
5361 /* Check for "x:y,x:y" */
5362 for (p = *varp; *p != NUL; p += 4)
5363 {
5364 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5365 {
5366 errmsg = e_invarg;
5367 break;
5368 }
5369 if (p[3] == NUL)
5370 break;
5371 }
5372 }
5373
5374#ifdef FEAT_COMMENTS
5375 /* 'comments' */
5376 else if (gvarp == &p_com)
5377 {
5378 for (s = *varp; *s; )
5379 {
5380 while (*s && *s != ':')
5381 {
5382 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5383 && !VIM_ISDIGIT(*s) && *s != '-')
5384 {
5385 errmsg = illegal_char(errbuf, *s);
5386 break;
5387 }
5388 ++s;
5389 }
5390 if (*s++ == NUL)
5391 errmsg = (char_u *)N_("E524: Missing colon");
5392 else if (*s == ',' || *s == NUL)
5393 errmsg = (char_u *)N_("E525: Zero length string");
5394 if (errmsg != NULL)
5395 break;
5396 while (*s && *s != ',')
5397 {
5398 if (*s == '\\' && s[1] != NUL)
5399 ++s;
5400 ++s;
5401 }
5402 s = skip_to_option_part(s);
5403 }
5404 }
5405#endif
5406
5407 /* 'listchars' */
5408 else if (varp == &p_lcs)
5409 {
5410 errmsg = set_chars_option(varp);
5411 }
5412
5413#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5414 /* 'fillchars' */
5415 else if (varp == &p_fcs)
5416 {
5417 errmsg = set_chars_option(varp);
5418 }
5419#endif
5420
5421#ifdef FEAT_CMDWIN
5422 /* 'cedit' */
5423 else if (varp == &p_cedit)
5424 {
5425 errmsg = check_cedit();
5426 }
5427#endif
5428
Bram Moolenaar54ee7752005-05-31 22:22:17 +00005429 /* 'verbosefile' */
5430 else if (varp == &p_vfile)
5431 {
5432 verbose_stop();
5433 if (*p_vfile != NUL && verbose_open() == FAIL)
5434 errmsg = e_invarg;
5435 }
5436
Bram Moolenaar071d4272004-06-13 20:20:40 +00005437#ifdef FEAT_VIMINFO
5438 /* 'viminfo' */
5439 else if (varp == &p_viminfo)
5440 {
5441 for (s = p_viminfo; *s;)
5442 {
5443 /* Check it's a valid character */
5444 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5445 {
5446 errmsg = illegal_char(errbuf, *s);
5447 break;
5448 }
5449 if (*s == 'n') /* name is always last one */
5450 {
5451 break;
5452 }
5453 else if (*s == 'r') /* skip until next ',' */
5454 {
5455 while (*++s && *s != ',')
5456 ;
5457 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005458 else if (*s == '%')
5459 {
5460 /* optional number */
5461 while (vim_isdigit(*++s))
5462 ;
5463 }
5464 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00005465 ++s; /* no extra chars */
5466 else /* must have a number */
5467 {
5468 while (vim_isdigit(*++s))
5469 ;
5470
5471 if (!VIM_ISDIGIT(*(s - 1)))
5472 {
5473 if (errbuf != NULL)
5474 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00005475 sprintf((char *)errbuf,
5476 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005477 transchar_byte(*(s - 1)));
5478 errmsg = errbuf;
5479 }
5480 else
5481 errmsg = (char_u *)"";
5482 break;
5483 }
5484 }
5485 if (*s == ',')
5486 ++s;
5487 else if (*s)
5488 {
5489 if (errbuf != NULL)
5490 errmsg = (char_u *)N_("E527: Missing comma");
5491 else
5492 errmsg = (char_u *)"";
5493 break;
5494 }
5495 }
5496 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5497 errmsg = (char_u *)N_("E528: Must specify a ' value");
5498 }
5499#endif /* FEAT_VIMINFO */
5500
5501 /* terminal options */
5502 else if (istermoption(&options[opt_idx]) && full_screen)
5503 {
5504 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5505 if (varp == &T_CCO)
5506 {
5507 t_colors = atoi((char *)T_CCO);
5508 if (t_colors <= 1)
5509 {
5510 if (new_value_alloced)
5511 vim_free(T_CCO);
5512 T_CCO = empty_option;
5513 }
5514 /* We now have a different color setup, initialize it again. */
5515 init_highlight(TRUE, FALSE);
5516 }
5517 ttest(FALSE);
5518 if (varp == &T_ME)
5519 {
5520 out_str(T_ME);
5521 redraw_later(CLEAR);
5522#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5523 /* Since t_me has been set, this probably means that the user
5524 * wants to use this as default colors. Need to reset default
5525 * background/foreground colors. */
5526 mch_set_normal_colors();
5527#endif
5528 }
5529 }
5530
5531#ifdef FEAT_LINEBREAK
5532 /* 'showbreak' */
5533 else if (varp == &p_sbr)
5534 {
5535 for (s = p_sbr; *s; )
5536 {
5537 if (ptr2cells(s) != 1)
5538 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005539 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540 }
5541 }
5542#endif
5543
5544#ifdef FEAT_GUI
5545 /* 'guifont' */
5546 else if (varp == &p_guifont)
5547 {
5548 if (gui.in_use)
5549 {
5550 p = p_guifont;
Bram Moolenaar843ee412004-06-30 16:16:41 +00005551# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552 /*
5553 * Put up a font dialog and let the user select a new value.
5554 * If this is cancelled go back to the old value but don't
5555 * give an error message.
5556 */
5557 if (STRCMP(p, "*") == 0)
5558 {
5559 p = gui_mch_font_dialog(oldval);
5560
5561 if (new_value_alloced)
5562 free_string_option(p_guifont);
5563
5564 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5565 new_value_alloced = TRUE;
5566 }
5567# endif
5568 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5569 {
5570# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5571 if (STRCMP(p_guifont, "*") == 0)
5572 {
5573 /* Dialog was cancelled: Keep the old value without giving
5574 * an error message. */
5575 if (new_value_alloced)
5576 free_string_option(p_guifont);
5577 p_guifont = vim_strsave(oldval);
5578 new_value_alloced = TRUE;
5579 }
5580 else
5581# endif
5582 errmsg = (char_u *)N_("E596: Invalid font(s)");
5583 }
5584 }
5585 }
5586# ifdef FEAT_XFONTSET
5587 else if (varp == &p_guifontset)
5588 {
5589 if (STRCMP(p_guifontset, "*") == 0)
5590 errmsg = (char_u *)N_("E597: can't select fontset");
5591 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5592 errmsg = (char_u *)N_("E598: Invalid fontset");
5593 }
5594# endif
5595# ifdef FEAT_MBYTE
5596 else if (varp == &p_guifontwide)
5597 {
5598 if (STRCMP(p_guifontwide, "*") == 0)
5599 errmsg = (char_u *)N_("E533: can't select wide font");
5600 else if (gui_get_wide_font() == FAIL)
5601 errmsg = (char_u *)N_("E534: Invalid wide font");
5602 }
5603# endif
5604#endif
5605
5606#ifdef CURSOR_SHAPE
5607 /* 'guicursor' */
5608 else if (varp == &p_guicursor)
5609 errmsg = parse_shape_opt(SHAPE_CURSOR);
5610#endif
5611
5612#ifdef FEAT_MOUSESHAPE
5613 /* 'mouseshape' */
5614 else if (varp == &p_mouseshape)
5615 {
5616 errmsg = parse_shape_opt(SHAPE_MOUSE);
5617 update_mouseshape(-1);
5618 }
5619#endif
5620
5621#ifdef FEAT_PRINTER
5622 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005623 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00005624# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00005625 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00005626 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00005627# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628#endif
5629
5630#ifdef FEAT_LANGMAP
5631 /* 'langmap' */
5632 else if (varp == &p_langmap)
5633 langmap_set();
5634#endif
5635
5636#ifdef FEAT_LINEBREAK
5637 /* 'breakat' */
5638 else if (varp == &p_breakat)
5639 fill_breakat_flags();
5640#endif
5641
5642#ifdef FEAT_TITLE
5643 /* 'titlestring' and 'iconstring' */
5644 else if (varp == &p_titlestring || varp == &p_iconstring)
5645 {
5646# ifdef FEAT_STL_OPT
5647 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5648
5649 /* NULL => statusline syntax */
5650 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5651 stl_syntax |= flagval;
5652 else
5653 stl_syntax &= ~flagval;
5654# endif
5655 did_set_title(varp == &p_iconstring);
5656
5657 }
5658#endif
5659
5660#ifdef FEAT_GUI
5661 /* 'guioptions' */
5662 else if (varp == &p_go)
5663 gui_init_which_components(oldval);
5664#endif
5665
5666#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5667 /* 'ttymouse' */
5668 else if (varp == &p_ttym)
5669 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00005670 /* Switch the mouse off before changing the escape sequences used for
5671 * that. */
5672 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5674 errmsg = e_invarg;
5675 else
5676 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00005677 if (termcap_active)
5678 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679 }
5680#endif
5681
5682#ifdef FEAT_VISUAL
5683 /* 'selection' */
5684 else if (varp == &p_sel)
5685 {
5686 if (*p_sel == NUL
5687 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5688 errmsg = e_invarg;
5689 }
5690
5691 /* 'selectmode' */
5692 else if (varp == &p_slm)
5693 {
5694 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5695 errmsg = e_invarg;
5696 }
5697#endif
5698
5699#ifdef FEAT_BROWSE
5700 /* 'browsedir' */
5701 else if (varp == &p_bsdir)
5702 {
5703 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5704 && !mch_isdir(p_bsdir))
5705 errmsg = e_invarg;
5706 }
5707#endif
5708
5709#ifdef FEAT_VISUAL
5710 /* 'keymodel' */
5711 else if (varp == &p_km)
5712 {
5713 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5714 errmsg = e_invarg;
5715 else
5716 {
5717 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5718 km_startsel = (vim_strchr(p_km, 'a') != NULL);
5719 }
5720 }
5721#endif
5722
5723 /* 'mousemodel' */
5724 else if (varp == &p_mousem)
5725 {
5726 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5727 errmsg = e_invarg;
5728#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5729 else if (*p_mousem != *oldval)
5730 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5731 * to create or delete the popup menus. */
5732 gui_motif_update_mousemodel(root_menu);
5733#endif
5734 }
5735
5736 /* 'switchbuf' */
5737 else if (varp == &p_swb)
5738 {
5739 if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5740 errmsg = e_invarg;
5741 }
5742
5743 /* 'debug' */
5744 else if (varp == &p_debug)
5745 {
5746 if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5747 errmsg = e_invarg;
5748 }
5749
5750 /* 'display' */
5751 else if (varp == &p_dy)
5752 {
5753 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5754 errmsg = e_invarg;
5755 else
5756 (void)init_chartab();
5757
5758 }
5759
5760#ifdef FEAT_VERTSPLIT
5761 /* 'eadirection' */
5762 else if (varp == &p_ead)
5763 {
5764 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5765 errmsg = e_invarg;
5766 }
5767#endif
5768
5769#ifdef FEAT_CLIPBOARD
5770 /* 'clipboard' */
5771 else if (varp == &p_cb)
5772 errmsg = check_clipboard_option();
5773#endif
5774
Bram Moolenaar217ad922005-03-20 22:37:15 +00005775#ifdef FEAT_SYN_HL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005776 /* When 'spelllang' or 'spellfile' is set and there is a window for this
5777 * buffer in which 'spell' is set load the wordlists. */
5778 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00005779 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005780 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005781 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005782
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005783 if (varp == &(curbuf->b_p_spf))
5784 {
5785 l = STRLEN(curbuf->b_p_spf);
5786 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
5787 ".add") != 0))
5788 errmsg = e_invarg;
5789 }
5790
5791 if (errmsg == NULL)
5792 {
5793 FOR_ALL_WINDOWS(wp)
5794 if (wp->w_buffer == curbuf && wp->w_p_spell)
5795 {
5796 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005797# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005798 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00005799# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00005800 }
5801 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005802 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005803 /* When 'spellcapcheck' is set compile the regexp program. */
5804 else if (varp == &(curbuf->b_p_spc))
5805 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005806 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005807 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005808 /* 'spellsuggest' */
5809 else if (varp == &p_sps)
5810 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005811 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005812 errmsg = e_invarg;
5813 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005814 /* 'mkspellmem' */
5815 else if (varp == &p_msm)
5816 {
5817 if (spell_check_msm() != OK)
5818 errmsg = e_invarg;
5819 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00005820#endif
5821
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822#ifdef FEAT_QUICKFIX
5823 /* When 'bufhidden' is set, check for valid value. */
5824 else if (gvarp == &p_bh)
5825 {
5826 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5827 errmsg = e_invarg;
5828 }
5829
5830 /* When 'buftype' is set, check for valid value. */
5831 else if (gvarp == &p_bt)
5832 {
5833 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5834 errmsg = e_invarg;
5835 else
5836 {
5837# ifdef FEAT_WINDOWS
5838 if (curwin->w_status_height)
5839 {
5840 curwin->w_redr_status = TRUE;
5841 redraw_later(VALID);
5842 }
5843# endif
5844 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5845 }
5846 }
5847#endif
5848
5849#ifdef FEAT_STL_OPT
5850 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005851 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 {
5853 int wid;
5854
5855 if (varp == &p_ruf) /* reset ru_wid first */
5856 ru_wid = 0;
5857 s = *varp;
5858 if (varp == &p_ruf && *s == '%')
5859 {
5860 /* set ru_wid if 'ruf' starts with "%99(" */
5861 if (*++s == '-') /* ignore a '-' */
5862 s++;
5863 wid = getdigits(&s);
5864 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5865 ru_wid = wid;
5866 else
5867 errmsg = check_stl_option(p_ruf);
5868 }
5869 else
5870 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005871 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872 comp_col();
5873 }
5874#endif
5875
5876#ifdef FEAT_INS_EXPAND
5877 /* check if it is a valid value for 'complete' -- Acevedo */
5878 else if (gvarp == &p_cpt)
5879 {
5880 for (s = *varp; *s;)
5881 {
5882 while(*s == ',' || *s == ' ')
5883 s++;
5884 if (!*s)
5885 break;
5886 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5887 {
5888 errmsg = illegal_char(errbuf, *s);
5889 break;
5890 }
5891 if (*++s != NUL && *s != ',' && *s != ' ')
5892 {
5893 if (s[-1] == 'k' || s[-1] == 's')
5894 {
5895 /* skip optional filename after 'k' and 's' */
5896 while (*s && *s != ',' && *s != ' ')
5897 {
5898 if (*s == '\\')
5899 ++s;
5900 ++s;
5901 }
5902 }
5903 else
5904 {
5905 if (errbuf != NULL)
5906 {
5907 sprintf((char *)errbuf,
5908 _("E535: Illegal character after <%c>"),
5909 *--s);
5910 errmsg = errbuf;
5911 }
5912 else
5913 errmsg = (char_u *)"";
5914 break;
5915 }
5916 }
5917 }
5918 }
5919#endif /* FEAT_INS_EXPAND */
5920
5921
5922#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5923 else if (varp == &p_toolbar)
5924 {
5925 if (opt_strings_flags(p_toolbar, p_toolbar_values,
5926 &toolbar_flags, TRUE) != OK)
5927 errmsg = e_invarg;
5928 else
5929 {
5930 out_flush();
5931 gui_mch_show_toolbar((toolbar_flags &
5932 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5933 }
5934 }
5935#endif
5936
5937#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5938 /* 'toolbariconsize': GTK+ 2 only */
5939 else if (varp == &p_tbis)
5940 {
5941 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
5942 errmsg = e_invarg;
5943 else
5944 {
5945 out_flush();
5946 gui_mch_show_toolbar((toolbar_flags &
5947 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5948 }
5949 }
5950#endif
5951
5952 /* 'pastetoggle': translate key codes like in a mapping */
5953 else if (varp == &p_pt)
5954 {
5955 if (*p_pt)
5956 {
5957 (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
5958 if (p != NULL)
5959 {
5960 if (new_value_alloced)
5961 free_string_option(p_pt);
5962 p_pt = p;
5963 new_value_alloced = TRUE;
5964 }
5965 }
5966 }
5967
5968 /* 'backspace' */
5969 else if (varp == &p_bs)
5970 {
5971 if (VIM_ISDIGIT(*p_bs))
5972 {
5973 if (*p_bs >'2' || p_bs[1] != NUL)
5974 errmsg = e_invarg;
5975 }
5976 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
5977 errmsg = e_invarg;
5978 }
5979
5980 /* 'casemap' */
5981 else if (varp == &p_cmp)
5982 {
5983 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
5984 errmsg = e_invarg;
5985 }
5986
5987#ifdef FEAT_DIFF
5988 /* 'diffopt' */
5989 else if (varp == &p_dip)
5990 {
5991 if (diffopt_changed() == FAIL)
5992 errmsg = e_invarg;
5993 }
5994#endif
5995
5996#ifdef FEAT_FOLDING
5997 /* 'foldmethod' */
5998 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
5999 {
6000 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6001 || *curwin->w_p_fdm == NUL)
6002 errmsg = e_invarg;
6003 else
6004 foldUpdateAll(curwin);
6005 }
6006# ifdef FEAT_EVAL
6007 /* 'foldexpr' */
6008 else if (varp == &curwin->w_p_fde)
6009 {
6010 if (foldmethodIsExpr(curwin))
6011 foldUpdateAll(curwin);
6012 }
6013# endif
6014 /* 'foldmarker' */
6015 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6016 {
6017 p = vim_strchr(*varp, ',');
6018 if (p == NULL)
6019 errmsg = (char_u *)N_("E536: comma required");
6020 else if (p == *varp || p[1] == NUL)
6021 errmsg = e_invarg;
6022 else if (foldmethodIsMarker(curwin))
6023 foldUpdateAll(curwin);
6024 }
6025 /* 'commentstring' */
6026 else if (gvarp == &p_cms)
6027 {
6028 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6029 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6030 }
6031 /* 'foldopen' */
6032 else if (varp == &p_fdo)
6033 {
6034 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6035 errmsg = e_invarg;
6036 }
6037 /* 'foldclose' */
6038 else if (varp == &p_fcl)
6039 {
6040 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6041 errmsg = e_invarg;
6042 }
6043#endif
6044
6045#ifdef FEAT_VIRTUALEDIT
6046 /* 'virtualedit' */
6047 else if (varp == &p_ve)
6048 {
6049 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6050 errmsg = e_invarg;
6051 else if (STRCMP(p_ve, oldval) != 0)
6052 {
6053 /* Recompute cursor position in case the new 've' setting
6054 * changes something. */
6055 validate_virtcol();
6056 coladvance(curwin->w_virtcol);
6057 }
6058 }
6059#endif
6060
6061#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6062 else if (varp == &p_csqf)
6063 {
6064 if (p_csqf != NULL)
6065 {
6066 p = p_csqf;
6067 while (*p != NUL)
6068 {
6069 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6070 || p[1] == NUL
6071 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6072 || (p[2] != NUL && p[2] != ','))
6073 {
6074 errmsg = e_invarg;
6075 break;
6076 }
6077 else if (p[2] == NUL)
6078 break;
6079 else
6080 p += 3;
6081 }
6082 }
6083 }
6084#endif
6085
6086 /* Options that are a list of flags. */
6087 else
6088 {
6089 p = NULL;
6090 if (varp == &p_ww)
6091 p = (char_u *)WW_ALL;
6092 if (varp == &p_shm)
6093 p = (char_u *)SHM_ALL;
6094 else if (varp == &(p_cpo))
6095 p = (char_u *)CPO_ALL;
6096 else if (varp == &(curbuf->b_p_fo))
6097 p = (char_u *)FO_ALL;
6098 else if (varp == &p_mouse)
6099 {
6100#ifdef FEAT_MOUSE
6101 p = (char_u *)MOUSE_ALL;
6102#else
6103 if (*p_mouse != NUL)
6104 errmsg = (char_u *)N_("E538: No mouse support");
6105#endif
6106 }
6107#if defined(FEAT_GUI)
6108 else if (varp == &p_go)
6109 p = (char_u *)GO_ALL;
6110#endif
6111 if (p != NULL)
6112 {
6113 for (s = *varp; *s; ++s)
6114 if (vim_strchr(p, *s) == NULL)
6115 {
6116 errmsg = illegal_char(errbuf, *s);
6117 break;
6118 }
6119 }
6120 }
6121
6122 /*
6123 * If error detected, restore the previous value.
6124 */
6125 if (errmsg != NULL)
6126 {
6127 if (new_value_alloced)
6128 free_string_option(*varp);
6129 *varp = oldval;
6130 /*
6131 * When resetting some values, need to act on it.
6132 */
6133 if (did_chartab)
6134 (void)init_chartab();
6135 if (varp == &p_hl)
6136 (void)highlight_changed();
6137 }
6138 else
6139 {
6140#ifdef FEAT_EVAL
6141 /* Remember where the option was set. */
6142 options[opt_idx].scriptID = current_SID;
6143#endif
6144 /*
6145 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006146 * Use "free_oldval", because recursiveness may change the flags under
6147 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006149 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150 free_string_option(oldval);
6151 if (new_value_alloced)
6152 options[opt_idx].flags |= P_ALLOCED;
6153 else
6154 options[opt_idx].flags &= ~P_ALLOCED;
6155
6156 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
6157 && (int)options[opt_idx].indir >= PV_BOTH)
6158 {
6159 /* global option with local value set to use global value; free
6160 * the local value and make it empty */
6161 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6162 free_string_option(*(char_u **)p);
6163 *(char_u **)p = empty_option;
6164 }
6165
6166 /* May set global value for local option. */
6167 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6168 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006169
6170#ifdef FEAT_AUTOCMD
6171 /*
6172 * Trigger the autocommand only after setting the flags.
6173 */
6174# ifdef FEAT_SYN_HL
6175 /* When 'syntax' is set, load the syntax of that name */
6176 if (varp == &(curbuf->b_p_syn))
6177 {
6178 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6179 curbuf->b_fname, TRUE, curbuf);
6180 }
6181# endif
6182 else if (varp == &(curbuf->b_p_ft))
6183 {
6184 /* 'filetype' is set, trigger the FileType autocommand */
6185 did_filetype = TRUE;
6186 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6187 curbuf->b_fname, TRUE, curbuf);
6188 }
6189#endif
6190#ifdef FEAT_SYN_HL
6191 if (varp == &(curbuf->b_p_spl))
6192 {
6193 char_u fname[200];
6194
6195 /*
6196 * Source the spell/LANG.vim in 'runtimepath'.
6197 * They could set 'spellcapcheck' depending on the language.
6198 * Use the first name in 'spelllang' up to '_region' or
6199 * '.encoding'.
6200 */
6201 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6202 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6203 break;
6204 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6205 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6206 source_runtime(fname, TRUE);
6207 }
6208#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006209 }
6210
6211#ifdef FEAT_MOUSE
6212 if (varp == &p_mouse)
6213 {
6214# ifdef FEAT_MOUSE_TTY
6215 if (*p_mouse == NUL)
6216 mch_setmouse(FALSE); /* switch mouse off */
6217 else
6218# endif
6219 setmouse(); /* in case 'mouse' changed */
6220 }
6221#endif
6222
6223 if (curwin->w_curswant != MAXCOL)
6224 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
6225 check_redraw(options[opt_idx].flags);
6226
6227 return errmsg;
6228}
6229
6230/*
6231 * Handle setting 'listchars' or 'fillchars'.
6232 * Returns error message, NULL if it's OK.
6233 */
6234 static char_u *
6235set_chars_option(varp)
6236 char_u **varp;
6237{
6238 int round, i, len, entries;
6239 char_u *p, *s;
6240 int c1, c2 = 0;
6241 struct charstab
6242 {
6243 int *cp;
6244 char *name;
6245 };
6246#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6247 static struct charstab filltab[] =
6248 {
6249 {&fill_stl, "stl"},
6250 {&fill_stlnc, "stlnc"},
6251 {&fill_vert, "vert"},
6252 {&fill_fold, "fold"},
6253 {&fill_diff, "diff"},
6254 };
6255#endif
6256 static struct charstab lcstab[] =
6257 {
6258 {&lcs_eol, "eol"},
6259 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006260 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006261 {&lcs_prec, "precedes"},
6262 {&lcs_tab2, "tab"},
6263 {&lcs_trail, "trail"},
6264 };
6265 struct charstab *tab;
6266
6267#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6268 if (varp == &p_lcs)
6269#endif
6270 {
6271 tab = lcstab;
6272 entries = sizeof(lcstab) / sizeof(struct charstab);
6273 }
6274#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6275 else
6276 {
6277 tab = filltab;
6278 entries = sizeof(filltab) / sizeof(struct charstab);
6279 }
6280#endif
6281
6282 /* first round: check for valid value, second round: assign values */
6283 for (round = 0; round <= 1; ++round)
6284 {
6285 if (round)
6286 {
6287 /* After checking that the value is valid: set defaults: space for
6288 * 'fillchars', NUL for 'listchars' */
6289 for (i = 0; i < entries; ++i)
6290 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6291 if (varp == &p_lcs)
6292 lcs_tab1 = NUL;
6293#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6294 else
6295 fill_diff = '-';
6296#endif
6297 }
6298 p = *varp;
6299 while (*p)
6300 {
6301 for (i = 0; i < entries; ++i)
6302 {
6303 len = (int)STRLEN(tab[i].name);
6304 if (STRNCMP(p, tab[i].name, len) == 0
6305 && p[len] == ':'
6306 && p[len + 1] != NUL)
6307 {
6308 s = p + len + 1;
6309#ifdef FEAT_MBYTE
6310 c1 = mb_ptr2char_adv(&s);
6311#else
6312 c1 = *s++;
6313#endif
6314 if (tab[i].cp == &lcs_tab2)
6315 {
6316 if (*s == NUL)
6317 continue;
6318#ifdef FEAT_MBYTE
6319 c2 = mb_ptr2char_adv(&s);
6320#else
6321 c2 = *s++;
6322#endif
6323 }
6324 if (*s == ',' || *s == NUL)
6325 {
6326 if (round)
6327 {
6328 if (tab[i].cp == &lcs_tab2)
6329 {
6330 lcs_tab1 = c1;
6331 lcs_tab2 = c2;
6332 }
6333 else
6334 *(tab[i].cp) = c1;
6335
6336 }
6337 p = s;
6338 break;
6339 }
6340 }
6341 }
6342
6343 if (i == entries)
6344 return e_invarg;
6345 if (*p == ',')
6346 ++p;
6347 }
6348 }
6349
6350 return NULL; /* no error */
6351}
6352
6353#ifdef FEAT_STL_OPT
6354/*
6355 * Check validity of options with the 'statusline' format.
6356 * Return error message or NULL.
6357 */
6358 char_u *
6359check_stl_option(s)
6360 char_u *s;
6361{
6362 int itemcnt = 0;
6363 int groupdepth = 0;
6364 static char_u errbuf[80];
6365
6366 while (*s && itemcnt < STL_MAX_ITEM)
6367 {
6368 /* Check for valid keys after % sequences */
6369 while (*s && *s != '%')
6370 s++;
6371 if (!*s)
6372 break;
6373 s++;
6374 if (*s != '%' && *s != ')')
6375 ++itemcnt;
6376 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
6377 {
6378 s++;
6379 continue;
6380 }
6381 if (*s == ')')
6382 {
6383 s++;
6384 if (--groupdepth < 0)
6385 break;
6386 continue;
6387 }
6388 if (*s == '-')
6389 s++;
6390 while (VIM_ISDIGIT(*s))
6391 s++;
6392 if (*s == STL_HIGHLIGHT)
6393 continue;
6394 if (*s == '.')
6395 {
6396 s++;
6397 while (*s && VIM_ISDIGIT(*s))
6398 s++;
6399 }
6400 if (*s == '(')
6401 {
6402 groupdepth++;
6403 continue;
6404 }
6405 if (vim_strchr(STL_ALL, *s) == NULL)
6406 {
6407 return illegal_char(errbuf, *s);
6408 }
6409 if (*s == '{')
6410 {
6411 s++;
6412 while (*s != '}' && *s)
6413 s++;
6414 if (*s != '}')
6415 return (char_u *)N_("E540: Unclosed expression sequence");
6416 }
6417 }
6418 if (itemcnt >= STL_MAX_ITEM)
6419 return (char_u *)N_("E541: too many items");
6420 if (groupdepth != 0)
6421 return (char_u *)N_("E542: unbalanced groups");
6422 return NULL;
6423}
6424#endif
6425
6426#ifdef FEAT_CLIPBOARD
6427/*
6428 * Extract the items in the 'clipboard' option and set global values.
6429 */
6430 static char_u *
6431check_clipboard_option()
6432{
6433 int new_unnamed = FALSE;
6434 int new_autoselect = FALSE;
6435 int new_autoselectml = FALSE;
6436 regprog_T *new_exclude_prog = NULL;
6437 char_u *errmsg = NULL;
6438 char_u *p;
6439
6440 for (p = p_cb; *p != NUL; )
6441 {
6442 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6443 {
6444 new_unnamed = TRUE;
6445 p += 7;
6446 }
6447 else if (STRNCMP(p, "autoselect", 10) == 0
6448 && (p[10] == ',' || p[10] == NUL))
6449 {
6450 new_autoselect = TRUE;
6451 p += 10;
6452 }
6453 else if (STRNCMP(p, "autoselectml", 12) == 0
6454 && (p[12] == ',' || p[12] == NUL))
6455 {
6456 new_autoselectml = TRUE;
6457 p += 12;
6458 }
6459 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6460 {
6461 p += 8;
6462 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6463 if (new_exclude_prog == NULL)
6464 errmsg = e_invarg;
6465 break;
6466 }
6467 else
6468 {
6469 errmsg = e_invarg;
6470 break;
6471 }
6472 if (*p == ',')
6473 ++p;
6474 }
6475 if (errmsg == NULL)
6476 {
6477 clip_unnamed = new_unnamed;
6478 clip_autoselect = new_autoselect;
6479 clip_autoselectml = new_autoselectml;
6480 vim_free(clip_exclude_prog);
6481 clip_exclude_prog = new_exclude_prog;
6482 }
6483 else
6484 vim_free(new_exclude_prog);
6485
6486 return errmsg;
6487}
6488#endif
6489
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006490#ifdef FEAT_SYN_HL
6491/*
6492 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
6493 * Return error message when failed, NULL when OK.
6494 */
6495 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006496compile_cap_prog(buf)
6497 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006498{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006499 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006500
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006501 if (*buf->b_p_spc == NUL)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006502 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006503 buf->b_cap_prog = NULL;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006504 vim_free(rp);
6505 return NULL;
6506 }
6507
6508 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006509 vim_snprintf((char *)IObuff, IOSIZE, "^%s", buf->b_p_spc);
6510 buf->b_cap_prog = vim_regcomp(IObuff, RE_MAGIC);
6511 if (buf->b_cap_prog == NULL)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006512 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006513 buf->b_cap_prog = rp;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006514 return e_invarg;
6515 }
6516
6517 vim_free(rp);
6518 return NULL;
6519}
6520#endif
6521
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522/*
6523 * Set the value of a boolean option, and take care of side effects.
6524 * Returns NULL for success, or an error message for an error.
6525 */
6526 static char_u *
6527set_bool_option(opt_idx, varp, value, opt_flags)
6528 int opt_idx; /* index in options[] table */
6529 char_u *varp; /* pointer to the option variable */
6530 int value; /* new value */
6531 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
6532{
6533 int old_value = *(int *)varp;
6534
6535#ifdef FEAT_GUI
6536 need_mouse_correct = TRUE;
6537#endif
6538
6539 /* Disallow changing some options from secure mode */
6540 if ((secure
6541#ifdef HAVE_SANDBOX
6542 || sandbox != 0
6543#endif
6544 ) && (options[opt_idx].flags & P_SECURE))
6545 return e_secure;
6546
6547 *(int *)varp = value; /* set the new value */
6548#ifdef FEAT_EVAL
6549 /* Remember where the option was set. */
6550 options[opt_idx].scriptID = current_SID;
6551#endif
6552
6553 /* May set global value for local option. */
6554 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6555 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6556
6557 /*
6558 * Handle side effects of changing a bool option.
6559 */
6560
6561 /* 'compatible' */
6562 if ((int *)varp == &p_cp)
6563 {
6564 compatible_set();
6565 }
6566
6567 /* when 'readonly' is reset globally, also reset readonlymode */
6568 else if ((int *)varp == &curbuf->b_p_ro)
6569 {
6570 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6571 readonlymode = FALSE;
6572#ifdef FEAT_TITLE
6573 need_maketitle = TRUE;
6574#endif
6575 }
6576
6577#ifdef FEAT_TITLE
6578 /* when 'modifiable' is changed, redraw the window title */
6579 else if ((int *)varp == &curbuf->b_p_ma)
6580 need_maketitle = TRUE;
6581 /* when 'endofline' is changed, redraw the window title */
6582 else if ((int *)varp == &curbuf->b_p_eol)
6583 need_maketitle = TRUE;
6584#endif
6585
6586 /* when 'bin' is set also set some other options */
6587 else if ((int *)varp == &curbuf->b_p_bin)
6588 {
6589 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6590#ifdef FEAT_TITLE
6591 need_maketitle = TRUE;
6592#endif
6593 }
6594
6595#ifdef FEAT_AUTOCMD
6596 /* when 'buflisted' changes, trigger autocommands */
6597 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6598 {
6599 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6600 NULL, NULL, TRUE, curbuf);
6601 }
6602#endif
6603
6604 /* when 'swf' is set, create swapfile, when reset remove swapfile */
6605 else if ((int *)varp == &curbuf->b_p_swf)
6606 {
6607 if (curbuf->b_p_swf && p_uc)
6608 ml_open_file(curbuf); /* create the swap file */
6609 else
6610 mf_close_file(curbuf, TRUE); /* remove the swap file */
6611 }
6612
6613 /* when 'terse' is set change 'shortmess' */
6614 else if ((int *)varp == &p_terse)
6615 {
6616 char_u *p;
6617
6618 p = vim_strchr(p_shm, SHM_SEARCH);
6619
6620 /* insert 's' in p_shm */
6621 if (p_terse && p == NULL)
6622 {
6623 STRCPY(IObuff, p_shm);
6624 STRCAT(IObuff, "s");
6625 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6626 }
6627 /* remove 's' from p_shm */
6628 else if (!p_terse && p != NULL)
6629 mch_memmove(p, p + 1, STRLEN(p));
6630 }
6631
6632 /* when 'paste' is set or reset also change other options */
6633 else if ((int *)varp == &p_paste)
6634 {
6635 paste_option_changed();
6636 }
6637
6638 /* when 'insertmode' is set from an autocommand need to do work here */
6639 else if ((int *)varp == &p_im)
6640 {
6641 if (p_im)
6642 {
6643 if ((State & INSERT) == 0)
6644 need_start_insertmode = TRUE;
6645 stop_insert_mode = FALSE;
6646 }
6647 else
6648 {
6649 need_start_insertmode = FALSE;
6650 stop_insert_mode = TRUE;
6651 if (p_smd && restart_edit != 0)
6652 clear_cmdline = TRUE; /* remove "(insert)" */
6653 restart_edit = 0;
6654 }
6655 }
6656
6657 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6658 else if ((int *)varp == &p_ic && p_hls)
6659 {
6660 redraw_all_later(NOT_VALID);
6661 }
6662
6663#ifdef FEAT_SEARCH_EXTRA
6664 /* when 'hlsearch' is set or reset: reset no_hlsearch */
6665 else if ((int *)varp == &p_hls)
6666 {
6667 no_hlsearch = FALSE;
6668 }
6669#endif
6670
6671#ifdef FEAT_SCROLLBIND
6672 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6673 * at the end of normal_cmd() */
6674 else if ((int *)varp == &curwin->w_p_scb)
6675 {
6676 if (curwin->w_p_scb)
6677 do_check_scrollbind(FALSE);
6678 }
6679#endif
6680
6681#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6682 /* There can be only one window with 'previewwindow' set. */
6683 else if ((int *)varp == &curwin->w_p_pvw)
6684 {
6685 if (curwin->w_p_pvw)
6686 {
6687 win_T *win;
6688
6689 for (win = firstwin; win != NULL; win = win->w_next)
6690 if (win->w_p_pvw && win != curwin)
6691 {
6692 curwin->w_p_pvw = FALSE;
6693 return (char_u *)N_("E590: A preview window already exists");
6694 }
6695 }
6696 }
6697#endif
6698
6699 /* when 'textmode' is set or reset also change 'fileformat' */
6700 else if ((int *)varp == &curbuf->b_p_tx)
6701 {
6702 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6703 }
6704
6705 /* when 'textauto' is set or reset also change 'fileformats' */
6706 else if ((int *)varp == &p_ta)
6707 {
6708 set_string_option_direct((char_u *)"ffs", -1,
6709 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6710 OPT_FREE | opt_flags);
6711 }
6712
6713 /*
6714 * When 'lisp' option changes include/exclude '-' in
6715 * keyword characters.
6716 */
6717#ifdef FEAT_LISP
6718 else if (varp == (char_u *)&(curbuf->b_p_lisp))
6719 {
6720 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
6721 }
6722#endif
6723
6724#ifdef FEAT_TITLE
6725 /* when 'title' changed, may need to change the title; same for 'icon' */
6726 else if ((int *)varp == &p_title)
6727 {
6728 did_set_title(FALSE);
6729 }
6730
6731 else if ((int *)varp == &p_icon)
6732 {
6733 did_set_title(TRUE);
6734 }
6735#endif
6736
6737 else if ((int *)varp == &curbuf->b_changed)
6738 {
6739 if (!value)
6740 save_file_ff(curbuf); /* Buffer is unchanged */
6741#ifdef FEAT_TITLE
6742 need_maketitle = TRUE;
6743#endif
6744#ifdef FEAT_AUTOCMD
6745 modified_was_set = value;
6746#endif
6747 }
6748
6749#ifdef BACKSLASH_IN_FILENAME
6750 else if ((int *)varp == &p_ssl)
6751 {
6752 if (p_ssl)
6753 {
6754 psepc = '/';
6755 psepcN = '\\';
6756 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 }
6758 else
6759 {
6760 psepc = '\\';
6761 psepcN = '/';
6762 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00006763 }
6764
6765 /* need to adjust the file name arguments and buffer names. */
6766 buflist_slash_adjust();
6767 alist_slash_adjust();
6768# ifdef FEAT_EVAL
6769 scriptnames_slash_adjust();
6770# endif
6771 }
6772#endif
6773
6774 /* If 'wrap' is set, set w_leftcol to zero. */
6775 else if ((int *)varp == &curwin->w_p_wrap)
6776 {
6777 if (curwin->w_p_wrap)
6778 curwin->w_leftcol = 0;
6779 }
6780
6781#ifdef FEAT_WINDOWS
6782 else if ((int *)varp == &p_ea)
6783 {
6784 if (p_ea && !old_value)
6785 win_equal(curwin, FALSE, 0);
6786 }
6787#endif
6788
6789 else if ((int *)varp == &p_wiv)
6790 {
6791 /*
6792 * When 'weirdinvert' changed, set/reset 't_xs'.
6793 * Then set 'weirdinvert' according to value of 't_xs'.
6794 */
6795 if (p_wiv && !old_value)
6796 T_XS = (char_u *)"y";
6797 else if (!p_wiv && old_value)
6798 T_XS = empty_option;
6799 p_wiv = (*T_XS != NUL);
6800 }
6801
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006802#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00006803 else if ((int *)varp == &p_beval)
6804 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006805 if (p_beval == TRUE)
6806 gui_mch_enable_beval_area(balloonEval);
6807 else
6808 gui_mch_disable_beval_area(balloonEval);
6809 }
6810
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006811# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006812 else if ((int *)varp == &p_acd)
6813 {
6814 if (p_acd && curbuf->b_ffname != NULL
6815 && vim_chdirfile(curbuf->b_ffname) == OK)
6816 shorten_fnames(TRUE);
6817 }
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006818# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819#endif
6820
6821#ifdef FEAT_DIFF
6822 /* 'diff' */
6823 else if ((int *)varp == &curwin->w_p_diff)
6824 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006825 /* May add or remove the buffer from the list of diff buffers. */
6826 diff_buf_adjust(curwin);
6827# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 if (foldmethodIsDiff(curwin))
6829 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006830# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831 }
6832#endif
6833
6834#ifdef USE_IM_CONTROL
6835 /* 'imdisable' */
6836 else if ((int *)varp == &p_imdisable)
6837 {
6838 /* Only de-activate it here, it will be enabled when changing mode. */
6839 if (p_imdisable)
6840 im_set_active(FALSE);
6841 }
6842#endif
6843
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006844#ifdef FEAT_SYN_HL
6845 /* 'spell' */
6846 else if ((int *)varp == &curwin->w_p_spell)
6847 {
6848 if (curwin->w_p_spell)
6849 {
6850 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00006851
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006852 if (errmsg != NULL)
6853 EMSG(_(errmsg));
6854 }
6855 }
6856#endif
6857
Bram Moolenaar071d4272004-06-13 20:20:40 +00006858#ifdef FEAT_FKMAP
6859 else if ((int *)varp == &p_altkeymap)
6860 {
6861 if (old_value != p_altkeymap)
6862 {
6863 if (!p_altkeymap)
6864 {
6865 p_hkmap = p_fkmap;
6866 p_fkmap = 0;
6867 }
6868 else
6869 {
6870 p_fkmap = p_hkmap;
6871 p_hkmap = 0;
6872 }
6873 (void)init_chartab();
6874 }
6875 }
6876
6877 /*
6878 * In case some second language keymapping options have changed, check
6879 * and correct the setting in a consistent way.
6880 */
6881
6882 /*
6883 * If hkmap or fkmap are set, reset Arabic keymapping.
6884 */
6885 if ((p_hkmap || p_fkmap) && p_altkeymap)
6886 {
6887 p_altkeymap = p_fkmap;
6888# ifdef FEAT_ARABIC
6889 curwin->w_p_arab = FALSE;
6890# endif
6891 (void)init_chartab();
6892 }
6893
6894 /*
6895 * If hkmap set, reset Farsi keymapping.
6896 */
6897 if (p_hkmap && p_altkeymap)
6898 {
6899 p_altkeymap = 0;
6900 p_fkmap = 0;
6901# ifdef FEAT_ARABIC
6902 curwin->w_p_arab = FALSE;
6903# endif
6904 (void)init_chartab();
6905 }
6906
6907 /*
6908 * If fkmap set, reset Hebrew keymapping.
6909 */
6910 if (p_fkmap && !p_altkeymap)
6911 {
6912 p_altkeymap = 1;
6913 p_hkmap = 0;
6914# ifdef FEAT_ARABIC
6915 curwin->w_p_arab = FALSE;
6916# endif
6917 (void)init_chartab();
6918 }
6919#endif
6920
6921#ifdef FEAT_ARABIC
6922 if ((int *)varp == &curwin->w_p_arab)
6923 {
6924 if (curwin->w_p_arab)
6925 {
6926 /*
6927 * 'arabic' is set, handle various sub-settings.
6928 */
6929 if (!p_tbidi)
6930 {
6931 /* set rightleft mode */
6932 if (!curwin->w_p_rl)
6933 {
6934 curwin->w_p_rl = TRUE;
6935 changed_window_setting();
6936 }
6937
6938 /* Enable Arabic shaping (major part of what Arabic requires) */
6939 if (!p_arshape)
6940 {
6941 p_arshape = TRUE;
6942 redraw_later_clear();
6943 }
6944 }
6945
6946 /* Arabic requires a utf-8 encoding, inform the user if its not
6947 * set. */
6948 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006949 {
6950 msg_source(hl_attr(HLF_W));
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951 MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6952 hl_attr(HLF_W));
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006953 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006954
6955# ifdef FEAT_MBYTE
6956 /* set 'delcombine' */
6957 p_deco = TRUE;
6958# endif
6959
6960# ifdef FEAT_KEYMAP
6961 /* Force-set the necessary keymap for arabic */
6962 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
6963 OPT_LOCAL);
6964# endif
6965# ifdef FEAT_FKMAP
6966 p_altkeymap = 0;
6967 p_hkmap = 0;
6968 p_fkmap = 0;
6969 (void)init_chartab();
6970# endif
6971 }
6972 else
6973 {
6974 /*
6975 * 'arabic' is reset, handle various sub-settings.
6976 */
6977 if (!p_tbidi)
6978 {
6979 /* reset rightleft mode */
6980 if (curwin->w_p_rl)
6981 {
6982 curwin->w_p_rl = FALSE;
6983 changed_window_setting();
6984 }
6985
6986 /* 'arabicshape' isn't reset, it is a global option and
6987 * another window may still need it "on". */
6988 }
6989
6990 /* 'delcombine' isn't reset, it is a global option and another
6991 * window may still want it "on". */
6992
6993# ifdef FEAT_KEYMAP
6994 /* Revert to the default keymap */
6995 curbuf->b_p_iminsert = B_IMODE_NONE;
6996 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6997# endif
6998 }
6999 }
7000#endif
7001
7002 /*
7003 * End of handling side effects for bool options.
7004 */
7005
7006 options[opt_idx].flags |= P_WAS_SET;
7007
7008 comp_col(); /* in case 'ruler' or 'showcmd' changed */
7009 if (curwin->w_curswant != MAXCOL)
7010 curwin->w_set_curswant = TRUE; /* in case 'list' changed */
7011 check_redraw(options[opt_idx].flags);
7012
7013 return NULL;
7014}
7015
7016/*
7017 * Set the value of a number option, and take care of side effects.
7018 * Returns NULL for success, or an error message for an error.
7019 */
7020 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007021set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007022 int opt_idx; /* index in options[] table */
7023 char_u *varp; /* pointer to the option variable */
7024 long value; /* new value */
7025 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007026 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7028 OPT_MODELINE */
7029{
7030 char_u *errmsg = NULL;
7031 long old_value = *(long *)varp;
7032 long old_Rows = Rows; /* remember old Rows */
7033 long old_Columns = Columns; /* remember old Columns */
7034 long *pp = (long *)varp;
7035
7036#ifdef FEAT_GUI
7037 need_mouse_correct = TRUE;
7038#endif
7039
7040 *pp = value;
7041#ifdef FEAT_EVAL
7042 /* Remember where the option was set. */
7043 options[opt_idx].scriptID = current_SID;
7044#endif
7045
7046 if (curbuf->b_p_sw <= 0)
7047 {
7048 errmsg = e_positive;
7049 curbuf->b_p_sw = curbuf->b_p_ts;
7050 }
7051
7052 /*
7053 * Number options that need some action when changed
7054 */
7055#ifdef FEAT_WINDOWS
7056 if (pp == &p_wh || pp == &p_hh)
7057 {
7058 if (p_wh < 1)
7059 {
7060 errmsg = e_positive;
7061 p_wh = 1;
7062 }
7063 if (p_wmh > p_wh)
7064 {
7065 errmsg = e_winheight;
7066 p_wh = p_wmh;
7067 }
7068 if (p_hh < 0)
7069 {
7070 errmsg = e_positive;
7071 p_hh = 0;
7072 }
7073
7074 /* Change window height NOW */
7075 if (lastwin != firstwin)
7076 {
7077 if (pp == &p_wh && curwin->w_height < p_wh)
7078 win_setheight((int)p_wh);
7079 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7080 win_setheight((int)p_hh);
7081 }
7082 }
7083
7084 /* 'winminheight' */
7085 else if (pp == &p_wmh)
7086 {
7087 if (p_wmh < 0)
7088 {
7089 errmsg = e_positive;
7090 p_wmh = 0;
7091 }
7092 if (p_wmh > p_wh)
7093 {
7094 errmsg = e_winheight;
7095 p_wmh = p_wh;
7096 }
7097 win_setminheight();
7098 }
7099
7100# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007101 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102 {
7103 if (p_wiw < 1)
7104 {
7105 errmsg = e_positive;
7106 p_wiw = 1;
7107 }
7108 if (p_wmw > p_wiw)
7109 {
7110 errmsg = e_winwidth;
7111 p_wiw = p_wmw;
7112 }
7113
7114 /* Change window width NOW */
7115 if (lastwin != firstwin && curwin->w_width < p_wiw)
7116 win_setwidth((int)p_wiw);
7117 }
7118
7119 /* 'winminwidth' */
7120 else if (pp == &p_wmw)
7121 {
7122 if (p_wmw < 0)
7123 {
7124 errmsg = e_positive;
7125 p_wmw = 0;
7126 }
7127 if (p_wmw > p_wiw)
7128 {
7129 errmsg = e_winwidth;
7130 p_wmw = p_wiw;
7131 }
7132 win_setminheight();
7133 }
7134# endif
7135
7136#endif
7137
7138#ifdef FEAT_WINDOWS
7139 /* (re)set last window status line */
7140 else if (pp == &p_ls)
7141 {
7142 last_status(FALSE);
7143 }
7144#endif
7145
7146#ifdef FEAT_GUI
7147 else if (pp == &p_linespace)
7148 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007149 /* Recompute gui.char_height and resize the Vim window to keep the
7150 * same number of lines. */
7151 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007152 gui_set_shellsize(FALSE, FALSE);
7153 }
7154#endif
7155
7156#ifdef FEAT_FOLDING
7157 /* 'foldlevel' */
7158 else if (pp == &curwin->w_p_fdl)
7159 {
7160 if (curwin->w_p_fdl < 0)
7161 curwin->w_p_fdl = 0;
7162 newFoldLevel();
7163 }
7164
7165 /* 'foldminlevel' */
7166 else if (pp == &curwin->w_p_fml)
7167 {
7168 foldUpdateAll(curwin);
7169 }
7170
7171 /* 'foldnestmax' */
7172 else if (pp == &curwin->w_p_fdn)
7173 {
7174 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7175 foldUpdateAll(curwin);
7176 }
7177
7178 /* 'foldcolumn' */
7179 else if (pp == &curwin->w_p_fdc)
7180 {
7181 if (curwin->w_p_fdc < 0)
7182 {
7183 errmsg = e_positive;
7184 curwin->w_p_fdc = 0;
7185 }
7186 else if (curwin->w_p_fdc > 12)
7187 {
7188 errmsg = e_invarg;
7189 curwin->w_p_fdc = 12;
7190 }
7191 }
7192
7193 /* 'shiftwidth' or 'tabstop' */
7194 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7195 {
7196 if (foldmethodIsIndent(curwin))
7197 foldUpdateAll(curwin);
7198 }
7199#endif /* FEAT_FOLDING */
7200
7201 else if (pp == &curbuf->b_p_iminsert)
7202 {
7203 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
7204 {
7205 errmsg = e_invarg;
7206 curbuf->b_p_iminsert = B_IMODE_NONE;
7207 }
7208 p_iminsert = curbuf->b_p_iminsert;
7209 if (termcap_active) /* don't do this in the alternate screen */
7210 showmode();
7211#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
7212 /* Show/unshow value of 'keymap' in status lines. */
7213 status_redraw_curbuf();
7214#endif
7215 }
7216
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007217 else if (pp == &p_window)
7218 {
7219 if (p_window < 1)
7220 p_window = 1;
7221 else if (p_window >= Rows)
7222 p_window = Rows - 1;
7223 }
7224
Bram Moolenaar071d4272004-06-13 20:20:40 +00007225 else if (pp == &curbuf->b_p_imsearch)
7226 {
7227 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
7228 {
7229 errmsg = e_invarg;
7230 curbuf->b_p_imsearch = B_IMODE_NONE;
7231 }
7232 p_imsearch = curbuf->b_p_imsearch;
7233 }
7234
7235#ifdef FEAT_TITLE
7236 /* if 'titlelen' has changed, redraw the title */
7237 else if (pp == &p_titlelen)
7238 {
7239 if (p_titlelen < 0)
7240 {
7241 errmsg = e_positive;
7242 p_titlelen = 85;
7243 }
7244 if (starting != NO_SCREEN && old_value != p_titlelen)
7245 need_maketitle = TRUE;
7246 }
7247#endif
7248
7249 /* if p_ch changed value, change the command line height */
7250 else if (pp == &p_ch)
7251 {
7252 if (p_ch < 1)
7253 {
7254 errmsg = e_positive;
7255 p_ch = 1;
7256 }
7257
7258 /* Only compute the new window layout when startup has been
7259 * completed. Otherwise the frame sizes may be wrong. */
7260 if (p_ch != old_value && full_screen
7261#ifdef FEAT_GUI
7262 && !gui.starting
7263#endif
7264 )
7265 command_height(old_value);
7266 }
7267
7268 /* when 'updatecount' changes from zero to non-zero, open swap files */
7269 else if (pp == &p_uc)
7270 {
7271 if (p_uc < 0)
7272 {
7273 errmsg = e_positive;
7274 p_uc = 100;
7275 }
7276 if (p_uc && !old_value)
7277 ml_open_files();
7278 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007279#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007280 else if (pp == &p_mzq)
7281 mzvim_reset_timer();
7282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007283
7284 /* sync undo before 'undolevels' changes */
7285 else if (pp == &p_ul)
7286 {
7287 /* use the old value, otherwise u_sync() may not work properly */
7288 p_ul = old_value;
7289 u_sync();
7290 p_ul = value;
7291 }
7292
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007293#ifdef FEAT_LINEBREAK
7294 /* 'numberwidth' must be positive */
7295 else if (pp == &curwin->w_p_nuw)
7296 {
7297 if (curwin->w_p_nuw < 1)
7298 {
7299 errmsg = e_positive;
7300 curwin->w_p_nuw = 1;
7301 }
7302 if (curwin->w_p_nuw > 10)
7303 {
7304 errmsg = e_invarg;
7305 curwin->w_p_nuw = 10;
7306 }
7307 curwin->w_nrwidth_line_count = 0;
7308 }
7309#endif
7310
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 /*
7312 * Check the bounds for numeric options here
7313 */
7314 if (Rows < min_rows() && full_screen)
7315 {
7316 if (errbuf != NULL)
7317 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007318 vim_snprintf((char *)errbuf, errbuflen,
7319 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 errmsg = errbuf;
7321 }
7322 Rows = min_rows();
7323 }
7324 if (Columns < MIN_COLUMNS && full_screen)
7325 {
7326 if (errbuf != NULL)
7327 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00007328 vim_snprintf((char *)errbuf, errbuflen,
7329 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007330 errmsg = errbuf;
7331 }
7332 Columns = MIN_COLUMNS;
7333 }
7334
7335#ifdef DJGPP
7336 /* avoid a crash by checking for a too large value of 'columns' */
7337 if (old_Columns != Columns && full_screen && term_console)
7338 mch_check_columns();
7339#endif
7340
7341 /*
7342 * If the screen (shell) height has been changed, assume it is the
7343 * physical screenheight.
7344 */
7345 if (old_Rows != Rows || old_Columns != Columns)
7346 {
7347 /* Changing the screen size is not allowed while updating the screen. */
7348 if (updating_screen)
7349 *pp = old_value;
7350 else if (full_screen
7351#ifdef FEAT_GUI
7352 && !gui.starting
7353#endif
7354 )
7355 set_shellsize((int)Columns, (int)Rows, TRUE);
7356 else
7357 {
7358 /* Postpone the resizing; check the size and cmdline position for
7359 * messages. */
7360 check_shellsize();
7361 if (cmdline_row > Rows - p_ch && Rows > p_ch)
7362 cmdline_row = Rows - p_ch;
7363 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00007364 if (p_window >= Rows)
7365 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007366 }
7367
7368 if (curbuf->b_p_sts < 0)
7369 {
7370 errmsg = e_positive;
7371 curbuf->b_p_sts = 0;
7372 }
7373 if (curbuf->b_p_ts <= 0)
7374 {
7375 errmsg = e_positive;
7376 curbuf->b_p_ts = 8;
7377 }
7378 if (curbuf->b_p_tw < 0)
7379 {
7380 errmsg = e_positive;
7381 curbuf->b_p_tw = 0;
7382 }
7383 if (p_tm < 0)
7384 {
7385 errmsg = e_positive;
7386 p_tm = 0;
7387 }
7388 if ((curwin->w_p_scr <= 0
7389 || (curwin->w_p_scr > curwin->w_height
7390 && curwin->w_height > 0))
7391 && full_screen)
7392 {
7393 if (pp == &(curwin->w_p_scr))
7394 {
7395 if (curwin->w_p_scr != 0)
7396 errmsg = e_scroll;
7397 win_comp_scroll(curwin);
7398 }
7399 /* If 'scroll' became invalid because of a side effect silently adjust
7400 * it. */
7401 else if (curwin->w_p_scr <= 0)
7402 curwin->w_p_scr = 1;
7403 else /* curwin->w_p_scr > curwin->w_height */
7404 curwin->w_p_scr = curwin->w_height;
7405 }
7406 if (p_report < 0)
7407 {
7408 errmsg = e_positive;
7409 p_report = 1;
7410 }
7411 if ((p_sj < 0 || p_sj >= Rows) && full_screen)
7412 {
7413 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
7414 p_sj = Rows / 2;
7415 else
7416 {
7417 errmsg = e_scroll;
7418 p_sj = 1;
7419 }
7420 }
7421 if (p_so < 0 && full_screen)
7422 {
7423 errmsg = e_scroll;
7424 p_so = 0;
7425 }
7426 if (p_siso < 0 && full_screen)
7427 {
7428 errmsg = e_positive;
7429 p_siso = 0;
7430 }
7431#ifdef FEAT_CMDWIN
7432 if (p_cwh < 1)
7433 {
7434 errmsg = e_positive;
7435 p_cwh = 1;
7436 }
7437#endif
7438 if (p_ut < 0)
7439 {
7440 errmsg = e_positive;
7441 p_ut = 2000;
7442 }
7443 if (p_ss < 0)
7444 {
7445 errmsg = e_positive;
7446 p_ss = 0;
7447 }
7448
7449 /* May set global value for local option. */
7450 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7451 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
7452
7453 options[opt_idx].flags |= P_WAS_SET;
7454
7455 comp_col(); /* in case 'columns' or 'ls' changed */
7456 if (curwin->w_curswant != MAXCOL)
7457 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
7458 check_redraw(options[opt_idx].flags);
7459
7460 return errmsg;
7461}
7462
7463/*
7464 * Called after an option changed: check if something needs to be redrawn.
7465 */
7466 static void
7467check_redraw(flags)
7468 long_u flags;
7469{
7470 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
7471 int clear = (flags & P_RCLR) == P_RCLR;
7472 int all = ((flags & P_RALL) == P_RALL || clear);
7473
7474#ifdef FEAT_WINDOWS
7475 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
7476 status_redraw_all();
7477#endif
7478
7479 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7480 changed_window_setting();
7481 if (flags & P_RBUF)
7482 redraw_curbuf_later(NOT_VALID);
7483 if (clear)
7484 redraw_all_later(CLEAR);
7485 else if (all)
7486 redraw_all_later(NOT_VALID);
7487}
7488
7489/*
7490 * Find index for option 'arg'.
7491 * Return -1 if not found.
7492 */
7493 static int
7494findoption(arg)
7495 char_u *arg;
7496{
7497 int opt_idx;
7498 char *s, *p;
7499 static short quick_tab[27] = {0, 0}; /* quick access table */
7500 int is_term_opt;
7501
7502 /*
7503 * For first call: Initialize the quick-access table.
7504 * It contains the index for the first option that starts with a certain
7505 * letter. There are 26 letters, plus the first "t_" option.
7506 */
7507 if (quick_tab[1] == 0)
7508 {
7509 p = options[0].fullname;
7510 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7511 {
7512 if (s[0] != p[0])
7513 {
7514 if (s[0] == 't' && s[1] == '_')
7515 quick_tab[26] = opt_idx;
7516 else
7517 quick_tab[CharOrdLow(s[0])] = opt_idx;
7518 }
7519 p = s;
7520 }
7521 }
7522
7523 /*
7524 * Check for name starting with an illegal character.
7525 */
7526#ifdef EBCDIC
7527 if (!islower(arg[0]))
7528#else
7529 if (arg[0] < 'a' || arg[0] > 'z')
7530#endif
7531 return -1;
7532
7533 is_term_opt = (arg[0] == 't' && arg[1] == '_');
7534 if (is_term_opt)
7535 opt_idx = quick_tab[26];
7536 else
7537 opt_idx = quick_tab[CharOrdLow(arg[0])];
7538 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7539 {
7540 if (STRCMP(arg, s) == 0) /* match full name */
7541 break;
7542 }
7543 if (s == NULL && !is_term_opt)
7544 {
7545 opt_idx = quick_tab[CharOrdLow(arg[0])];
7546 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7547 {
7548 s = options[opt_idx].shortname;
7549 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
7550 break;
7551 s = NULL;
7552 }
7553 }
7554 if (s == NULL)
7555 opt_idx = -1;
7556 return opt_idx;
7557}
7558
Bram Moolenaar325b7a22004-07-05 15:58:32 +00007559#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007560/*
7561 * Get the value for an option.
7562 *
7563 * Returns:
7564 * Number or Toggle option: 1, *numval gets value.
7565 * String option: 0, *stringval gets allocated string.
7566 * Hidden Number or Toggle option: -1.
7567 * hidden String option: -2.
7568 * unknown option: -3.
7569 */
7570 int
7571get_option_value(name, numval, stringval, opt_flags)
7572 char_u *name;
7573 long *numval;
7574 char_u **stringval; /* NULL when only checking existance */
7575 int opt_flags;
7576{
7577 int opt_idx;
7578 char_u *varp;
7579
7580 opt_idx = findoption(name);
7581 if (opt_idx < 0) /* unknown option */
7582 return -3;
7583
7584 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7585
7586 if (options[opt_idx].flags & P_STRING)
7587 {
7588 if (varp == NULL) /* hidden option */
7589 return -2;
7590 if (stringval != NULL)
7591 {
7592#ifdef FEAT_CRYPT
7593 /* never return the value of the crypt key */
7594 if ((char_u **)varp == &curbuf->b_p_key)
7595 *stringval = vim_strsave((char_u *)"*****");
7596 else
7597#endif
7598 *stringval = vim_strsave(*(char_u **)(varp));
7599 }
7600 return 0;
7601 }
7602
7603 if (varp == NULL) /* hidden option */
7604 return -1;
7605 if (options[opt_idx].flags & P_NUM)
7606 *numval = *(long *)varp;
7607 else
7608 {
7609 /* Special case: 'modified' is b_changed, but we also want to consider
7610 * it set when 'ff' or 'fenc' changed. */
7611 if ((int *)varp == &curbuf->b_changed)
7612 *numval = curbufIsChanged();
7613 else
7614 *numval = *(int *)varp;
7615 }
7616 return 1;
7617}
7618#endif
7619
7620/*
7621 * Set the value of option "name".
7622 * Use "string" for string options, use "number" for other options.
7623 */
7624 void
7625set_option_value(name, number, string, opt_flags)
7626 char_u *name;
7627 long number;
7628 char_u *string;
7629 int opt_flags; /* OPT_LOCAL or 0 (both) */
7630{
7631 int opt_idx;
7632 char_u *varp;
7633 int flags;
7634
7635 opt_idx = findoption(name);
7636 if (opt_idx == -1)
7637 EMSG2(_("E355: Unknown option: %s"), name);
7638 else
7639 {
7640 flags = options[opt_idx].flags;
7641#ifdef HAVE_SANDBOX
7642 /* Disallow changing some options in the sandbox */
7643 if (sandbox > 0 && (flags & P_SECURE))
7644 EMSG(_(e_sandbox));
7645 else
7646#endif
7647 if (flags & P_STRING)
7648 set_string_option(opt_idx, string, opt_flags);
7649 else
7650 {
7651 varp = get_varp(&options[opt_idx]);
7652 if (varp != NULL) /* hidden option is not changed */
7653 {
7654 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00007655 (void)set_num_option(opt_idx, varp, number,
7656 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007657 else
7658 (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7659 }
7660 }
7661 }
7662}
7663
7664/*
7665 * Get the terminal code for a terminal option.
7666 * Returns NULL when not found.
7667 */
7668 char_u *
7669get_term_code(tname)
7670 char_u *tname;
7671{
7672 int opt_idx;
7673 char_u *varp;
7674
7675 if (tname[0] != 't' || tname[1] != '_' ||
7676 tname[2] == NUL || tname[3] == NUL)
7677 return NULL;
7678 if ((opt_idx = findoption(tname)) >= 0)
7679 {
7680 varp = get_varp(&(options[opt_idx]));
7681 if (varp != NULL)
7682 varp = *(char_u **)(varp);
7683 return varp;
7684 }
7685 return find_termcode(tname + 2);
7686}
7687
7688 char_u *
7689get_highlight_default()
7690{
7691 int i;
7692
7693 i = findoption((char_u *)"hl");
7694 if (i >= 0)
7695 return options[i].def_val[VI_DEFAULT];
7696 return (char_u *)NULL;
7697}
7698
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00007699#if defined(FEAT_MBYTE) || defined(PROTO)
7700 char_u *
7701get_encoding_default()
7702{
7703 int i;
7704
7705 i = findoption((char_u *)"enc");
7706 if (i >= 0)
7707 return options[i].def_val[VI_DEFAULT];
7708 return (char_u *)NULL;
7709}
7710#endif
7711
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712/*
7713 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7714 */
7715 static int
7716find_key_option(arg)
7717 char_u *arg;
7718{
7719 int key;
7720 int modifiers;
7721
7722 /*
7723 * Don't use get_special_key_code() for t_xx, we don't want it to call
7724 * add_termcap_entry().
7725 */
7726 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7727 key = TERMCAP2KEY(arg[2], arg[3]);
7728 else
7729 {
7730 --arg; /* put arg at the '<' */
7731 modifiers = 0;
7732 key = find_special_key(&arg, &modifiers, TRUE);
7733 if (modifiers) /* can't handle modifiers here */
7734 key = 0;
7735 }
7736 return key;
7737}
7738
7739/*
7740 * if 'all' == 0: show changed options
7741 * if 'all' == 1: show all normal options
7742 * if 'all' == 2: show all terminal options
7743 */
7744 static void
7745showoptions(all, opt_flags)
7746 int all;
7747 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7748{
7749 struct vimoption *p;
7750 int col;
7751 int isterm;
7752 char_u *varp;
7753 struct vimoption **items;
7754 int item_count;
7755 int run;
7756 int row, rows;
7757 int cols;
7758 int i;
7759 int len;
7760
7761#define INC 20
7762#define GAP 3
7763
7764 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7765 PARAM_COUNT));
7766 if (items == NULL)
7767 return;
7768
7769 /* Highlight title */
7770 if (all == 2)
7771 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7772 else if (opt_flags & OPT_GLOBAL)
7773 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7774 else if (opt_flags & OPT_LOCAL)
7775 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7776 else
7777 MSG_PUTS_TITLE(_("\n--- Options ---"));
7778
7779 /*
7780 * do the loop two times:
7781 * 1. display the short items
7782 * 2. display the long items (only strings and numbers)
7783 */
7784 for (run = 1; run <= 2 && !got_int; ++run)
7785 {
7786 /*
7787 * collect the items in items[]
7788 */
7789 item_count = 0;
7790 for (p = &options[0]; p->fullname != NULL; p++)
7791 {
7792 varp = NULL;
7793 isterm = istermoption(p);
7794 if (opt_flags != 0)
7795 {
7796 if (p->indir != PV_NONE && !isterm)
7797 varp = get_varp_scope(p, opt_flags);
7798 }
7799 else
7800 varp = get_varp(p);
7801 if (varp != NULL
7802 && ((all == 2 && isterm)
7803 || (all == 1 && !isterm)
7804 || (all == 0 && !optval_default(p, varp))))
7805 {
7806 if (p->flags & P_BOOL)
7807 len = 1; /* a toggle option fits always */
7808 else
7809 {
7810 option_value2string(p, opt_flags);
7811 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7812 }
7813 if ((len <= INC - GAP && run == 1) ||
7814 (len > INC - GAP && run == 2))
7815 items[item_count++] = p;
7816 }
7817 }
7818
7819 /*
7820 * display the items
7821 */
7822 if (run == 1)
7823 {
7824 cols = (Columns + GAP - 3) / INC;
7825 if (cols == 0)
7826 cols = 1;
7827 rows = (item_count + cols - 1) / cols;
7828 }
7829 else /* run == 2 */
7830 rows = item_count;
7831 for (row = 0; row < rows && !got_int; ++row)
7832 {
7833 msg_putchar('\n'); /* go to next line */
7834 if (got_int) /* 'q' typed in more */
7835 break;
7836 col = 0;
7837 for (i = row; i < item_count; i += rows)
7838 {
7839 msg_col = col; /* make columns */
7840 showoneopt(items[i], opt_flags);
7841 col += INC;
7842 }
7843 out_flush();
7844 ui_breakcheck();
7845 }
7846 }
7847 vim_free(items);
7848}
7849
7850/*
7851 * Return TRUE if option "p" has its default value.
7852 */
7853 static int
7854optval_default(p, varp)
7855 struct vimoption *p;
7856 char_u *varp;
7857{
7858 int dvi;
7859
7860 if (varp == NULL)
7861 return TRUE; /* hidden option is always at default */
7862 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7863 if (p->flags & P_NUM)
7864 return (*(long *)varp == (long)p->def_val[dvi]);
7865 if (p->flags & P_BOOL)
7866 /* the cast to long is required for Manx C */
7867 return (*(int *)varp == (int)(long)p->def_val[dvi]);
7868 /* P_STRING */
7869 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7870}
7871
7872/*
7873 * showoneopt: show the value of one option
7874 * must not be called with a hidden option!
7875 */
7876 static void
7877showoneopt(p, opt_flags)
7878 struct vimoption *p;
7879 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
7880{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007881 char_u *varp;
7882 int save_silent = silent_mode;
7883
7884 silent_mode = FALSE;
7885 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886
7887 varp = get_varp_scope(p, opt_flags);
7888
7889 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7890 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7891 ? !curbufIsChanged() : !*(int *)varp))
7892 MSG_PUTS("no");
7893 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7894 MSG_PUTS("--");
7895 else
7896 MSG_PUTS(" ");
7897 MSG_PUTS(p->fullname);
7898 if (!(p->flags & P_BOOL))
7899 {
7900 msg_putchar('=');
7901 /* put value string in NameBuff */
7902 option_value2string(p, opt_flags);
7903 msg_outtrans(NameBuff);
7904 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00007905
7906 silent_mode = save_silent;
7907 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908}
7909
7910/*
7911 * Write modified options as ":set" commands to a file.
7912 *
7913 * There are three values for "opt_flags":
7914 * OPT_GLOBAL: Write global option values and fresh values of
7915 * buffer-local options (used for start of a session
7916 * file).
7917 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7918 * curwin (used for a vimrc file).
7919 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
7920 * and local values for window-local options of
7921 * curwin. Local values are also written when at the
7922 * default value, because a modeline or autocommand
7923 * may have set them when doing ":edit file" and the
7924 * user has set them back at the default or fresh
7925 * value.
7926 * When "local_only" is TRUE, don't write fresh
7927 * values, only local values (for ":mkview").
7928 * (fresh value = value used for a new buffer or window for a local option).
7929 *
7930 * Return FAIL on error, OK otherwise.
7931 */
7932 int
7933makeset(fd, opt_flags, local_only)
7934 FILE *fd;
7935 int opt_flags;
7936 int local_only;
7937{
7938 struct vimoption *p;
7939 char_u *varp; /* currently used value */
7940 char_u *varp_fresh; /* local value */
7941 char_u *varp_local = NULL; /* fresh value */
7942 char *cmd;
7943 int round;
7944
7945 /*
7946 * The options that don't have a default (terminal name, columns, lines)
7947 * are never written. Terminal options are also not written.
7948 */
7949 for (p = &options[0]; !istermoption(p); p++)
7950 if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7951 {
7952 /* skip global option when only doing locals */
7953 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7954 continue;
7955
7956 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
7957 * file, they are always buffer-specific. */
7958 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
7959 continue;
7960
7961 /* Global values are only written when not at the default value. */
7962 varp = get_varp_scope(p, opt_flags);
7963 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
7964 continue;
7965
7966 round = 2;
7967 if (p->indir != PV_NONE)
7968 {
7969 if (p->var == VAR_WIN)
7970 {
7971 /* skip window-local option when only doing globals */
7972 if (!(opt_flags & OPT_LOCAL))
7973 continue;
7974 /* When fresh value of window-local option is not at the
7975 * default, need to write it too. */
7976 if (!(opt_flags & OPT_GLOBAL) && !local_only)
7977 {
7978 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
7979 if (!optval_default(p, varp_fresh))
7980 {
7981 round = 1;
7982 varp_local = varp;
7983 varp = varp_fresh;
7984 }
7985 }
7986 }
7987 }
7988
7989 /* Round 1: fresh value for window-local options.
7990 * Round 2: other values */
7991 for ( ; round <= 2; varp = varp_local, ++round)
7992 {
7993 if (round == 1 || (opt_flags & OPT_GLOBAL))
7994 cmd = "set";
7995 else
7996 cmd = "setlocal";
7997
7998 if (p->flags & P_BOOL)
7999 {
8000 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8001 return FAIL;
8002 }
8003 else if (p->flags & P_NUM)
8004 {
8005 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8006 return FAIL;
8007 }
8008 else /* P_STRING */
8009 {
8010 /* Don't set 'syntax' and 'filetype' again if the value is
8011 * already right, avoids reloading the syntax file. */
8012 if (p->indir == PV_SYN || p->indir == PV_FT)
8013 {
8014 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8015 *(char_u **)(varp)) < 0
8016 || put_eol(fd) < 0)
8017 return FAIL;
8018 }
8019 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8020 (p->flags & P_EXPAND) != 0) == FAIL)
8021 return FAIL;
8022 if (p->indir == PV_SYN || p->indir == PV_FT)
8023 {
8024 if (put_line(fd, "endif") == FAIL)
8025 return FAIL;
8026 }
8027 }
8028 }
8029 }
8030 return OK;
8031}
8032
8033#if defined(FEAT_FOLDING) || defined(PROTO)
8034/*
8035 * Generate set commands for the local fold options only. Used when
8036 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8037 */
8038 int
8039makefoldset(fd)
8040 FILE *fd;
8041{
8042 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8043# ifdef FEAT_EVAL
8044 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8045 == FAIL
8046# endif
8047 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8048 == FAIL
8049 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8050 == FAIL
8051 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8052 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8053 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8054 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8055 )
8056 return FAIL;
8057
8058 return OK;
8059}
8060#endif
8061
8062 static int
8063put_setstring(fd, cmd, name, valuep, expand)
8064 FILE *fd;
8065 char *cmd;
8066 char *name;
8067 char_u **valuep;
8068 int expand;
8069{
8070 char_u *s;
8071 char_u buf[MAXPATHL];
8072
8073 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8074 return FAIL;
8075 if (*valuep != NULL)
8076 {
8077 /* Output 'pastetoggle' as key names. For other
8078 * options some characters have to be escaped with
8079 * CTRL-V or backslash */
8080 if (valuep == &p_pt)
8081 {
8082 s = *valuep;
8083 while (*s != NUL)
8084 if (fputs((char *)str2special(&s, FALSE), fd) < 0)
8085 return FAIL;
8086 }
8087 else if (expand)
8088 {
8089 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8090 if (put_escstr(fd, buf, 2) == FAIL)
8091 return FAIL;
8092 }
8093 else if (put_escstr(fd, *valuep, 2) == FAIL)
8094 return FAIL;
8095 }
8096 if (put_eol(fd) < 0)
8097 return FAIL;
8098 return OK;
8099}
8100
8101 static int
8102put_setnum(fd, cmd, name, valuep)
8103 FILE *fd;
8104 char *cmd;
8105 char *name;
8106 long *valuep;
8107{
8108 long wc;
8109
8110 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8111 return FAIL;
8112 if (wc_use_keyname((char_u *)valuep, &wc))
8113 {
8114 /* print 'wildchar' and 'wildcharm' as a key name */
8115 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8116 return FAIL;
8117 }
8118 else if (fprintf(fd, "%ld", *valuep) < 0)
8119 return FAIL;
8120 if (put_eol(fd) < 0)
8121 return FAIL;
8122 return OK;
8123}
8124
8125 static int
8126put_setbool(fd, cmd, name, value)
8127 FILE *fd;
8128 char *cmd;
8129 char *name;
8130 int value;
8131{
8132 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
8133 || put_eol(fd) < 0)
8134 return FAIL;
8135 return OK;
8136}
8137
8138/*
8139 * Clear all the terminal options.
8140 * If the option has been allocated, free the memory.
8141 * Terminal options are never hidden or indirect.
8142 */
8143 void
8144clear_termoptions()
8145{
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 /*
8147 * Reset a few things before clearing the old options. This may cause
8148 * outputting a few things that the terminal doesn't understand, but the
8149 * screen will be cleared later, so this is OK.
8150 */
8151#ifdef FEAT_MOUSE_TTY
8152 mch_setmouse(FALSE); /* switch mouse off */
8153#endif
8154#ifdef FEAT_TITLE
8155 mch_restore_title(3); /* restore window titles */
8156#endif
8157#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
8158 /* When starting the GUI close the display opened for the clipboard.
8159 * After restoring the title, because that will need the display. */
8160 if (gui.starting)
8161 clear_xterm_clip();
8162#endif
8163#ifdef WIN3264
8164 /*
8165 * Check if this is allowed now.
8166 */
8167 if (can_end_termcap_mode(FALSE) == TRUE)
8168#endif
8169 stoptermcap(); /* stop termcap mode */
8170
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00008171 free_termoptions();
8172}
8173
8174 void
8175free_termoptions()
8176{
8177 struct vimoption *p;
8178
Bram Moolenaar071d4272004-06-13 20:20:40 +00008179 for (p = &options[0]; p->fullname != NULL; p++)
8180 if (istermoption(p))
8181 {
8182 if (p->flags & P_ALLOCED)
8183 free_string_option(*(char_u **)(p->var));
8184 if (p->flags & P_DEF_ALLOCED)
8185 free_string_option(p->def_val[VI_DEFAULT]);
8186 *(char_u **)(p->var) = empty_option;
8187 p->def_val[VI_DEFAULT] = empty_option;
8188 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
8189 }
8190 clear_termcodes();
8191}
8192
8193/*
8194 * Set the terminal option defaults to the current value.
8195 * Used after setting the terminal name.
8196 */
8197 void
8198set_term_defaults()
8199{
8200 struct vimoption *p;
8201
8202 for (p = &options[0]; p->fullname != NULL; p++)
8203 {
8204 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
8205 {
8206 if (p->flags & P_DEF_ALLOCED)
8207 {
8208 free_string_option(p->def_val[VI_DEFAULT]);
8209 p->flags &= ~P_DEF_ALLOCED;
8210 }
8211 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
8212 if (p->flags & P_ALLOCED)
8213 {
8214 p->flags |= P_DEF_ALLOCED;
8215 p->flags &= ~P_ALLOCED; /* don't free the value now */
8216 }
8217 }
8218 }
8219}
8220
8221/*
8222 * return TRUE if 'p' starts with 't_'
8223 */
8224 static int
8225istermoption(p)
8226 struct vimoption *p;
8227{
8228 return (p->fullname[0] == 't' && p->fullname[1] == '_');
8229}
8230
8231/*
8232 * Compute columns for ruler and shown command. 'sc_col' is also used to
8233 * decide what the maximum length of a message on the status line can be.
8234 * If there is a status line for the last window, 'sc_col' is independent
8235 * of 'ru_col'.
8236 */
8237
8238#define COL_RULER 17 /* columns needed by standard ruler */
8239
8240 void
8241comp_col()
8242{
8243#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
8244 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
8245
8246 sc_col = 0;
8247 ru_col = 0;
8248 if (p_ru)
8249 {
8250#ifdef FEAT_STL_OPT
8251 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
8252#else
8253 ru_col = COL_RULER + 1;
8254#endif
8255 /* no last status line, adjust sc_col */
8256 if (!last_has_status)
8257 sc_col = ru_col;
8258 }
8259 if (p_sc)
8260 {
8261 sc_col += SHOWCMD_COLS;
8262 if (!p_ru || last_has_status) /* no need for separating space */
8263 ++sc_col;
8264 }
8265 sc_col = Columns - sc_col;
8266 ru_col = Columns - ru_col;
8267 if (sc_col <= 0) /* screen too narrow, will become a mess */
8268 sc_col = 1;
8269 if (ru_col <= 0)
8270 ru_col = 1;
8271#else
8272 sc_col = Columns;
8273 ru_col = Columns;
8274#endif
8275}
8276
8277/*
8278 * Get pointer to option variable, depending on local or global scope.
8279 */
8280 static char_u *
8281get_varp_scope(p, opt_flags)
8282 struct vimoption *p;
8283 int opt_flags;
8284{
8285 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
8286 {
8287 if (p->var == VAR_WIN)
8288 return (char_u *)GLOBAL_WO(get_varp(p));
8289 return p->var;
8290 }
8291 if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
8292 {
8293 switch ((int)p->indir)
8294 {
8295#ifdef FEAT_QUICKFIX
8296 case OPT_BOTH(PV_GP): return (char_u *)&(curbuf->b_p_gp);
8297 case OPT_BOTH(PV_MP): return (char_u *)&(curbuf->b_p_mp);
8298 case OPT_BOTH(PV_EFM): return (char_u *)&(curbuf->b_p_efm);
8299#endif
8300 case OPT_BOTH(PV_EP): return (char_u *)&(curbuf->b_p_ep);
8301 case OPT_BOTH(PV_KP): return (char_u *)&(curbuf->b_p_kp);
8302 case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
8303 case OPT_BOTH(PV_AR): return (char_u *)&(curbuf->b_p_ar);
8304 case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
8305#ifdef FEAT_FIND_ID
8306 case OPT_BOTH(PV_DEF): return (char_u *)&(curbuf->b_p_def);
8307 case OPT_BOTH(PV_INC): return (char_u *)&(curbuf->b_p_inc);
8308#endif
8309#ifdef FEAT_INS_EXPAND
8310 case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
8311 case OPT_BOTH(PV_TSR): return (char_u *)&(curbuf->b_p_tsr);
8312#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008313#ifdef FEAT_STL_OPT
8314 case OPT_BOTH(PV_STL): return (char_u *)&(curwin->w_p_stl);
8315#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 }
8317 return NULL; /* "cannot happen" */
8318 }
8319 return get_varp(p);
8320}
8321
8322/*
8323 * Get pointer to option variable.
8324 */
8325 static char_u *
8326get_varp(p)
8327 struct vimoption *p;
8328{
8329 /* hidden option, always return NULL */
8330 if (p->var == NULL)
8331 return NULL;
8332
8333 switch ((int)p->indir)
8334 {
8335 case PV_NONE: return p->var;
8336
8337 /* global option with local value: use local value if it's been set */
8338 case OPT_BOTH(PV_EP): return *curbuf->b_p_ep != NUL
8339 ? (char_u *)&curbuf->b_p_ep : p->var;
8340 case OPT_BOTH(PV_KP): return *curbuf->b_p_kp != NUL
8341 ? (char_u *)&curbuf->b_p_kp : p->var;
8342 case OPT_BOTH(PV_PATH): return *curbuf->b_p_path != NUL
8343 ? (char_u *)&(curbuf->b_p_path) : p->var;
8344 case OPT_BOTH(PV_AR): return curbuf->b_p_ar >= 0
8345 ? (char_u *)&(curbuf->b_p_ar) : p->var;
8346 case OPT_BOTH(PV_TAGS): return *curbuf->b_p_tags != NUL
8347 ? (char_u *)&(curbuf->b_p_tags) : p->var;
8348#ifdef FEAT_FIND_ID
8349 case OPT_BOTH(PV_DEF): return *curbuf->b_p_def != NUL
8350 ? (char_u *)&(curbuf->b_p_def) : p->var;
8351 case OPT_BOTH(PV_INC): return *curbuf->b_p_inc != NUL
8352 ? (char_u *)&(curbuf->b_p_inc) : p->var;
8353#endif
8354#ifdef FEAT_INS_EXPAND
8355 case OPT_BOTH(PV_DICT): return *curbuf->b_p_dict != NUL
8356 ? (char_u *)&(curbuf->b_p_dict) : p->var;
8357 case OPT_BOTH(PV_TSR): return *curbuf->b_p_tsr != NUL
8358 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
8359#endif
8360#ifdef FEAT_QUICKFIX
8361 case OPT_BOTH(PV_GP): return *curbuf->b_p_gp != NUL
8362 ? (char_u *)&(curbuf->b_p_gp) : p->var;
8363 case OPT_BOTH(PV_MP): return *curbuf->b_p_mp != NUL
8364 ? (char_u *)&(curbuf->b_p_mp) : p->var;
8365 case OPT_BOTH(PV_EFM): return *curbuf->b_p_efm != NUL
8366 ? (char_u *)&(curbuf->b_p_efm) : p->var;
8367#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008368#ifdef FEAT_STL_OPT
8369 case OPT_BOTH(PV_STL): return *curwin->w_p_stl != NUL
8370 ? (char_u *)&(curwin->w_p_stl) : p->var;
8371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372
8373#ifdef FEAT_ARABIC
8374 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
8375#endif
8376 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008377#ifdef FEAT_SYN_HL
8378 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
8379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380#ifdef FEAT_DIFF
8381 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
8382#endif
8383#ifdef FEAT_FOLDING
8384 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
8385 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
8386 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
8387 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
8388 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
8389 case PV_FML: return (char_u *)&(curwin->w_p_fml);
8390 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
8391# ifdef FEAT_EVAL
8392 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
8393 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
8394# endif
8395 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
8396#endif
8397 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008398#ifdef FEAT_LINEBREAK
8399 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
8400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401#if defined(FEAT_WINDOWS)
8402 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
8403#endif
8404#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8405 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
8406#endif
8407#ifdef FEAT_RIGHTLEFT
8408 case PV_RL: return (char_u *)&(curwin->w_p_rl);
8409 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
8410#endif
8411 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
8412 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
8413#ifdef FEAT_LINEBREAK
8414 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
8415#endif
8416#ifdef FEAT_SCROLLBIND
8417 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
8418#endif
8419
8420 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
8421 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
8422#ifdef FEAT_MBYTE
8423 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
8424#endif
8425#if defined(FEAT_QUICKFIX)
8426 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
8427 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
8428#endif
8429 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
8430 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
8431#ifdef FEAT_CINDENT
8432 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
8433 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
8434 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
8435#endif
8436#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8437 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
8438#endif
8439#ifdef FEAT_COMMENTS
8440 case PV_COM: return (char_u *)&(curbuf->b_p_com);
8441#endif
8442#ifdef FEAT_FOLDING
8443 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
8444#endif
8445#ifdef FEAT_INS_EXPAND
8446 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
8447#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008448#ifdef FEAT_COMPL_FUNC
8449 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
8450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
8452 case PV_ET: return (char_u *)&(curbuf->b_p_et);
8453#ifdef FEAT_MBYTE
8454 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
8455#endif
8456 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
8457#ifdef FEAT_AUTOCMD
8458 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
8459#endif
8460 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008461 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008462 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
8463 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
8464 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
8465 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
8466#ifdef FEAT_FIND_ID
8467# ifdef FEAT_EVAL
8468 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
8469# endif
8470#endif
8471#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8472 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
8473 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
8474#endif
8475#ifdef FEAT_CRYPT
8476 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
8477#endif
8478#ifdef FEAT_LISP
8479 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
8480#endif
8481 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
8482 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
8483 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
8484 case PV_MOD: return (char_u *)&(curbuf->b_changed);
8485 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
8486#ifdef FEAT_OSFILETYPE
8487 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
8488#endif
8489 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008490#ifdef FEAT_TEXTOBJ
8491 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
8492#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
8494#ifdef FEAT_SMARTINDENT
8495 case PV_SI: return (char_u *)&(curbuf->b_p_si);
8496#endif
8497#ifndef SHORT_FNAME
8498 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
8499#endif
8500 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
8501#ifdef FEAT_SEARCHPATH
8502 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
8503#endif
8504 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
8505#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008506 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008508 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008509 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008510 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511#endif
8512 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
8513 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
8514 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
8515 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
8516 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
8517#ifdef FEAT_KEYMAP
8518 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
8519#endif
8520 default: EMSG(_("E356: get_varp ERROR"));
8521 }
8522 /* always return a valid pointer to avoid a crash! */
8523 return (char_u *)&(curbuf->b_p_wm);
8524}
8525
8526/*
8527 * Get the value of 'equalprg', either the buffer-local one or the global one.
8528 */
8529 char_u *
8530get_equalprg()
8531{
8532 if (*curbuf->b_p_ep == NUL)
8533 return p_ep;
8534 return curbuf->b_p_ep;
8535}
8536
8537#if defined(FEAT_WINDOWS) || defined(PROTO)
8538/*
8539 * Copy options from one window to another.
8540 * Used when splitting a window.
8541 */
8542 void
8543win_copy_options(wp_from, wp_to)
8544 win_T *wp_from;
8545 win_T *wp_to;
8546{
8547 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8548 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8549# ifdef FEAT_RIGHTLEFT
8550# ifdef FEAT_FKMAP
8551 /* Is this right? */
8552 wp_to->w_farsi = wp_from->w_farsi;
8553# endif
8554# endif
8555}
8556#endif
8557
8558/*
8559 * Copy the options from one winopt_T to another.
8560 * Doesn't free the old option values in "to", use clear_winopt() for that.
8561 * The 'scroll' option is not copied, because it depends on the window height.
8562 * The 'previewwindow' option is reset, there can be only one preview window.
8563 */
8564 void
8565copy_winopt(from, to)
8566 winopt_T *from;
8567 winopt_T *to;
8568{
8569#ifdef FEAT_ARABIC
8570 to->wo_arab = from->wo_arab;
8571#endif
8572 to->wo_list = from->wo_list;
8573 to->wo_nu = from->wo_nu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008574#ifdef FEAT_LINEBREAK
8575 to->wo_nuw = from->wo_nuw;
8576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577#ifdef FEAT_RIGHTLEFT
8578 to->wo_rl = from->wo_rl;
8579 to->wo_rlc = vim_strsave(from->wo_rlc);
8580#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008581#ifdef FEAT_STL_OPT
8582 to->wo_stl = vim_strsave(from->wo_stl);
8583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008584 to->wo_wrap = from->wo_wrap;
8585#ifdef FEAT_LINEBREAK
8586 to->wo_lbr = from->wo_lbr;
8587#endif
8588#ifdef FEAT_SCROLLBIND
8589 to->wo_scb = from->wo_scb;
8590#endif
Bram Moolenaar217ad922005-03-20 22:37:15 +00008591#ifdef FEAT_SYN_HL
8592 to->wo_spell = from->wo_spell;
8593#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008594#ifdef FEAT_DIFF
8595 to->wo_diff = from->wo_diff;
8596#endif
8597#ifdef FEAT_FOLDING
8598 to->wo_fdc = from->wo_fdc;
8599 to->wo_fen = from->wo_fen;
8600 to->wo_fdi = vim_strsave(from->wo_fdi);
8601 to->wo_fml = from->wo_fml;
8602 to->wo_fdl = from->wo_fdl;
8603 to->wo_fdm = vim_strsave(from->wo_fdm);
8604 to->wo_fdn = from->wo_fdn;
8605# ifdef FEAT_EVAL
8606 to->wo_fde = vim_strsave(from->wo_fde);
8607 to->wo_fdt = vim_strsave(from->wo_fdt);
8608# endif
8609 to->wo_fmr = vim_strsave(from->wo_fmr);
8610#endif
8611 check_winopt(to); /* don't want NULL pointers */
8612}
8613
8614/*
8615 * Check string options in a window for a NULL value.
8616 */
8617 void
8618check_win_options(win)
8619 win_T *win;
8620{
8621 check_winopt(&win->w_onebuf_opt);
8622 check_winopt(&win->w_allbuf_opt);
8623}
8624
8625/*
8626 * Check for NULL pointers in a winopt_T and replace them with empty_option.
8627 */
8628/*ARGSUSED*/
8629 void
8630check_winopt(wop)
8631 winopt_T *wop;
8632{
8633#ifdef FEAT_FOLDING
8634 check_string_option(&wop->wo_fdi);
8635 check_string_option(&wop->wo_fdm);
8636# ifdef FEAT_EVAL
8637 check_string_option(&wop->wo_fde);
8638 check_string_option(&wop->wo_fdt);
8639# endif
8640 check_string_option(&wop->wo_fmr);
8641#endif
8642#ifdef FEAT_RIGHTLEFT
8643 check_string_option(&wop->wo_rlc);
8644#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008645#ifdef FEAT_STL_OPT
8646 check_string_option(&wop->wo_stl);
8647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648}
8649
8650/*
8651 * Free the allocated memory inside a winopt_T.
8652 */
8653/*ARGSUSED*/
8654 void
8655clear_winopt(wop)
8656 winopt_T *wop;
8657{
8658#ifdef FEAT_FOLDING
8659 clear_string_option(&wop->wo_fdi);
8660 clear_string_option(&wop->wo_fdm);
8661# ifdef FEAT_EVAL
8662 clear_string_option(&wop->wo_fde);
8663 clear_string_option(&wop->wo_fdt);
8664# endif
8665 clear_string_option(&wop->wo_fmr);
8666#endif
8667#ifdef FEAT_RIGHTLEFT
8668 clear_string_option(&wop->wo_rlc);
8669#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00008670#ifdef FEAT_STL_OPT
8671 clear_string_option(&wop->wo_stl);
8672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673}
8674
8675/*
8676 * Copy global option values to local options for one buffer.
8677 * Used when creating a new buffer and sometimes when entering a buffer.
8678 * flags:
8679 * BCO_ENTER We will enter the buf buffer.
8680 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
8681 * appropriate.
8682 * BCO_NOHELP Don't copy the values to a help buffer.
8683 */
8684 void
8685buf_copy_options(buf, flags)
8686 buf_T *buf;
8687 int flags;
8688{
8689 int should_copy = TRUE;
8690 char_u *save_p_isk = NULL; /* init for GCC */
8691 int dont_do_help;
8692 int did_isk = FALSE;
8693
8694 /*
8695 * Don't do anything of the buffer is invalid.
8696 */
8697 if (buf == NULL || !buf_valid(buf))
8698 return;
8699
8700 /*
8701 * Skip this when the option defaults have not been set yet. Happens when
8702 * main() allocates the first buffer.
8703 */
8704 if (p_cpo != NULL)
8705 {
8706 /*
8707 * Always copy when entering and 'cpo' contains 'S'.
8708 * Don't copy when already initialized.
8709 * Don't copy when 'cpo' contains 's' and not entering.
8710 * 'S' BCO_ENTER initialized 's' should_copy
8711 * yes yes X X TRUE
8712 * yes no yes X FALSE
8713 * no X yes X FALSE
8714 * X no no yes FALSE
8715 * X no no no TRUE
8716 * no yes no X TRUE
8717 */
8718 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8719 && (buf->b_p_initialized
8720 || (!(flags & BCO_ENTER)
8721 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8722 should_copy = FALSE;
8723
8724 if (should_copy || (flags & BCO_ALWAYS))
8725 {
8726 /* Don't copy the options specific to a help buffer when
8727 * BCO_NOHELP is given or the options were initialized already
8728 * (jumping back to a help file with CTRL-T or CTRL-O) */
8729 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8730 || buf->b_p_initialized;
8731 if (dont_do_help) /* don't free b_p_isk */
8732 {
8733 save_p_isk = buf->b_p_isk;
8734 buf->b_p_isk = NULL;
8735 }
8736 /*
8737 * Always free the allocated strings.
8738 * If not already initialized, set 'readonly' and copy 'fileformat'.
8739 */
8740 if (!buf->b_p_initialized)
8741 {
8742 free_buf_options(buf, TRUE);
8743 buf->b_p_ro = FALSE; /* don't copy readonly */
8744 buf->b_p_tx = p_tx;
8745#ifdef FEAT_MBYTE
8746 buf->b_p_fenc = vim_strsave(p_fenc);
8747#endif
8748 buf->b_p_ff = vim_strsave(p_ff);
8749#if defined(FEAT_QUICKFIX)
8750 buf->b_p_bh = empty_option;
8751 buf->b_p_bt = empty_option;
8752#endif
8753 }
8754 else
8755 free_buf_options(buf, FALSE);
8756
8757 buf->b_p_ai = p_ai;
8758 buf->b_p_ai_nopaste = p_ai_nopaste;
8759 buf->b_p_sw = p_sw;
8760 buf->b_p_tw = p_tw;
8761 buf->b_p_tw_nopaste = p_tw_nopaste;
8762 buf->b_p_tw_nobin = p_tw_nobin;
8763 buf->b_p_wm = p_wm;
8764 buf->b_p_wm_nopaste = p_wm_nopaste;
8765 buf->b_p_wm_nobin = p_wm_nobin;
8766 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00008767#ifdef FEAT_MBYTE
8768 buf->b_p_bomb = p_bomb;
8769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008770 buf->b_p_et = p_et;
8771 buf->b_p_et_nobin = p_et_nobin;
8772 buf->b_p_ml = p_ml;
8773 buf->b_p_ml_nobin = p_ml_nobin;
8774 buf->b_p_inf = p_inf;
8775 buf->b_p_swf = p_swf;
8776#ifdef FEAT_INS_EXPAND
8777 buf->b_p_cpt = vim_strsave(p_cpt);
8778#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008779#ifdef FEAT_COMPL_FUNC
8780 buf->b_p_cfu = vim_strsave(p_cfu);
8781#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008782 buf->b_p_sts = p_sts;
8783 buf->b_p_sts_nopaste = p_sts_nopaste;
8784#ifndef SHORT_FNAME
8785 buf->b_p_sn = p_sn;
8786#endif
8787#ifdef FEAT_COMMENTS
8788 buf->b_p_com = vim_strsave(p_com);
8789#endif
8790#ifdef FEAT_FOLDING
8791 buf->b_p_cms = vim_strsave(p_cms);
8792#endif
8793 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00008794 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 buf->b_p_nf = vim_strsave(p_nf);
8796 buf->b_p_mps = vim_strsave(p_mps);
8797#ifdef FEAT_SMARTINDENT
8798 buf->b_p_si = p_si;
8799#endif
8800 buf->b_p_ci = p_ci;
8801#ifdef FEAT_CINDENT
8802 buf->b_p_cin = p_cin;
8803 buf->b_p_cink = vim_strsave(p_cink);
8804 buf->b_p_cino = vim_strsave(p_cino);
8805#endif
8806#ifdef FEAT_AUTOCMD
8807 /* Don't copy 'filetype', it must be detected */
8808 buf->b_p_ft = empty_option;
8809#endif
8810#ifdef FEAT_OSFILETYPE
8811 buf->b_p_oft = vim_strsave(p_oft);
8812#endif
8813 buf->b_p_pi = p_pi;
8814#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8815 buf->b_p_cinw = vim_strsave(p_cinw);
8816#endif
8817#ifdef FEAT_LISP
8818 buf->b_p_lisp = p_lisp;
8819#endif
8820#ifdef FEAT_SYN_HL
8821 /* Don't copy 'syntax', it must be set */
8822 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00008823 buf->b_p_smc = p_smc;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008824 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00008825 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00008826 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00008827 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828#endif
8829#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8830 buf->b_p_inde = vim_strsave(p_inde);
8831 buf->b_p_indk = vim_strsave(p_indk);
8832#endif
8833#ifdef FEAT_CRYPT
8834 buf->b_p_key = vim_strsave(p_key);
8835#endif
8836#ifdef FEAT_SEARCHPATH
8837 buf->b_p_sua = vim_strsave(p_sua);
8838#endif
8839#ifdef FEAT_KEYMAP
8840 buf->b_p_keymap = vim_strsave(p_keymap);
8841 buf->b_kmap_state |= KEYMAP_INIT;
8842#endif
8843 /* This isn't really an option, but copying the langmap and IME
8844 * state from the current buffer is better than resetting it. */
8845 buf->b_p_iminsert = p_iminsert;
8846 buf->b_p_imsearch = p_imsearch;
8847
8848 /* options that are normally global but also have a local value
8849 * are not copied, start using the global value */
8850 buf->b_p_ar = -1;
8851#ifdef FEAT_QUICKFIX
8852 buf->b_p_gp = empty_option;
8853 buf->b_p_mp = empty_option;
8854 buf->b_p_efm = empty_option;
8855#endif
8856 buf->b_p_ep = empty_option;
8857 buf->b_p_kp = empty_option;
8858 buf->b_p_path = empty_option;
8859 buf->b_p_tags = empty_option;
8860#ifdef FEAT_FIND_ID
8861 buf->b_p_def = empty_option;
8862 buf->b_p_inc = empty_option;
8863# ifdef FEAT_EVAL
8864 buf->b_p_inex = vim_strsave(p_inex);
8865# endif
8866#endif
8867#ifdef FEAT_INS_EXPAND
8868 buf->b_p_dict = empty_option;
8869 buf->b_p_tsr = empty_option;
8870#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008871#ifdef FEAT_TEXTOBJ
8872 buf->b_p_qe = vim_strsave(p_qe);
8873#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874
8875 /*
8876 * Don't copy the options set by ex_help(), use the saved values,
8877 * when going from a help buffer to a non-help buffer.
8878 * Don't touch these at all when BCO_NOHELP is used and going from
8879 * or to a help buffer.
8880 */
8881 if (dont_do_help)
8882 buf->b_p_isk = save_p_isk;
8883 else
8884 {
8885 buf->b_p_isk = vim_strsave(p_isk);
8886 did_isk = TRUE;
8887 buf->b_p_ts = p_ts;
8888 buf->b_help = FALSE;
8889#ifdef FEAT_QUICKFIX
8890 if (buf->b_p_bt[0] == 'h')
8891 clear_string_option(&buf->b_p_bt);
8892#endif
8893 buf->b_p_ma = p_ma;
8894 }
8895 }
8896
8897 /*
8898 * When the options should be copied (ignoring BCO_ALWAYS), set the
8899 * flag that indicates that the options have been initialized.
8900 */
8901 if (should_copy)
8902 buf->b_p_initialized = TRUE;
8903 }
8904
8905 check_buf_options(buf); /* make sure we don't have NULLs */
8906 if (did_isk)
8907 (void)buf_init_chartab(buf, FALSE);
8908}
8909
8910/*
8911 * Reset the 'modifiable' option and its default value.
8912 */
8913 void
8914reset_modifiable()
8915{
8916 int opt_idx;
8917
8918 curbuf->b_p_ma = FALSE;
8919 p_ma = FALSE;
8920 opt_idx = findoption((char_u *)"ma");
8921 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8922}
8923
8924/*
8925 * Set the global value for 'iminsert' to the local value.
8926 */
8927 void
8928set_iminsert_global()
8929{
8930 p_iminsert = curbuf->b_p_iminsert;
8931}
8932
8933/*
8934 * Set the global value for 'imsearch' to the local value.
8935 */
8936 void
8937set_imsearch_global()
8938{
8939 p_imsearch = curbuf->b_p_imsearch;
8940}
8941
8942#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8943static int expand_option_idx = -1;
8944static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8945static int expand_option_flags = 0;
8946
8947 void
8948set_context_in_set_cmd(xp, arg, opt_flags)
8949 expand_T *xp;
8950 char_u *arg;
8951 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
8952{
8953 int nextchar;
8954 long_u flags = 0; /* init for GCC */
8955 int opt_idx = 0; /* init for GCC */
8956 char_u *p;
8957 char_u *s;
8958 int is_term_option = FALSE;
8959 int key;
8960
8961 expand_option_flags = opt_flags;
8962
8963 xp->xp_context = EXPAND_SETTINGS;
8964 if (*arg == NUL)
8965 {
8966 xp->xp_pattern = arg;
8967 return;
8968 }
8969 p = arg + STRLEN(arg) - 1;
8970 if (*p == ' ' && *(p - 1) != '\\')
8971 {
8972 xp->xp_pattern = p + 1;
8973 return;
8974 }
8975 while (p > arg)
8976 {
8977 s = p;
8978 /* count number of backslashes before ' ' or ',' */
8979 if (*p == ' ' || *p == ',')
8980 {
8981 while (s > arg && *(s - 1) == '\\')
8982 --s;
8983 }
8984 /* break at a space with an even number of backslashes */
8985 if (*p == ' ' && ((p - s) & 1) == 0)
8986 {
8987 ++p;
8988 break;
8989 }
8990 --p;
8991 }
8992 if (STRNCMP(p, "no", 2) == 0)
8993 {
8994 xp->xp_context = EXPAND_BOOL_SETTINGS;
8995 p += 2;
8996 }
8997 if (STRNCMP(p, "inv", 3) == 0)
8998 {
8999 xp->xp_context = EXPAND_BOOL_SETTINGS;
9000 p += 3;
9001 }
9002 xp->xp_pattern = arg = p;
9003 if (*arg == '<')
9004 {
9005 while (*p != '>')
9006 if (*p++ == NUL) /* expand terminal option name */
9007 return;
9008 key = get_special_key_code(arg + 1);
9009 if (key == 0) /* unknown name */
9010 {
9011 xp->xp_context = EXPAND_NOTHING;
9012 return;
9013 }
9014 nextchar = *++p;
9015 is_term_option = TRUE;
9016 expand_option_name[2] = KEY2TERMCAP0(key);
9017 expand_option_name[3] = KEY2TERMCAP1(key);
9018 }
9019 else
9020 {
9021 if (p[0] == 't' && p[1] == '_')
9022 {
9023 p += 2;
9024 if (*p != NUL)
9025 ++p;
9026 if (*p == NUL)
9027 return; /* expand option name */
9028 nextchar = *++p;
9029 is_term_option = TRUE;
9030 expand_option_name[2] = p[-2];
9031 expand_option_name[3] = p[-1];
9032 }
9033 else
9034 {
9035 /* Allow * wildcard */
9036 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9037 p++;
9038 if (*p == NUL)
9039 return;
9040 nextchar = *p;
9041 *p = NUL;
9042 opt_idx = findoption(arg);
9043 *p = nextchar;
9044 if (opt_idx == -1 || options[opt_idx].var == NULL)
9045 {
9046 xp->xp_context = EXPAND_NOTHING;
9047 return;
9048 }
9049 flags = options[opt_idx].flags;
9050 if (flags & P_BOOL)
9051 {
9052 xp->xp_context = EXPAND_NOTHING;
9053 return;
9054 }
9055 }
9056 }
9057 /* handle "-=" and "+=" */
9058 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9059 {
9060 ++p;
9061 nextchar = '=';
9062 }
9063 if ((nextchar != '=' && nextchar != ':')
9064 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9065 {
9066 xp->xp_context = EXPAND_UNSUCCESSFUL;
9067 return;
9068 }
9069 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
9070 {
9071 xp->xp_context = EXPAND_OLD_SETTING;
9072 if (is_term_option)
9073 expand_option_idx = -1;
9074 else
9075 expand_option_idx = opt_idx;
9076 xp->xp_pattern = p + 1;
9077 return;
9078 }
9079 xp->xp_context = EXPAND_NOTHING;
9080 if (is_term_option || (flags & P_NUM))
9081 return;
9082
9083 xp->xp_pattern = p + 1;
9084
9085 if (flags & P_EXPAND)
9086 {
9087 p = options[opt_idx].var;
9088 if (p == (char_u *)&p_bdir
9089 || p == (char_u *)&p_dir
9090 || p == (char_u *)&p_path
9091 || p == (char_u *)&p_rtp
9092#ifdef FEAT_SEARCHPATH
9093 || p == (char_u *)&p_cdpath
9094#endif
9095#ifdef FEAT_SESSION
9096 || p == (char_u *)&p_vdir
9097#endif
9098 )
9099 {
9100 xp->xp_context = EXPAND_DIRECTORIES;
9101 if (p == (char_u *)&p_path
9102#ifdef FEAT_SEARCHPATH
9103 || p == (char_u *)&p_cdpath
9104#endif
9105 )
9106 xp->xp_backslash = XP_BS_THREE;
9107 else
9108 xp->xp_backslash = XP_BS_ONE;
9109 }
9110 else
9111 {
9112 xp->xp_context = EXPAND_FILES;
9113 /* for 'tags' need three backslashes for a space */
9114 if (p == (char_u *)&p_tags)
9115 xp->xp_backslash = XP_BS_THREE;
9116 else
9117 xp->xp_backslash = XP_BS_ONE;
9118 }
9119 }
9120
9121 /* For an option that is a list of file names, find the start of the
9122 * last file name. */
9123 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
9124 {
9125 /* count number of backslashes before ' ' or ',' */
9126 if (*p == ' ' || *p == ',')
9127 {
9128 s = p;
9129 while (s > xp->xp_pattern && *(s - 1) == '\\')
9130 --s;
9131 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
9132 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
9133 {
9134 xp->xp_pattern = p + 1;
9135 break;
9136 }
9137 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00009138
9139#ifdef FEAT_SYN_HL
9140 /* for 'spellsuggest' start at "file:" */
9141 if (options[opt_idx].var == (char_u *)&p_sps
9142 && STRNCMP(p, "file:", 5) == 0)
9143 {
9144 xp->xp_pattern = p + 5;
9145 break;
9146 }
9147#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 }
9149
9150 return;
9151}
9152
9153 int
9154ExpandSettings(xp, regmatch, num_file, file)
9155 expand_T *xp;
9156 regmatch_T *regmatch;
9157 int *num_file;
9158 char_u ***file;
9159{
9160 int num_normal = 0; /* Nr of matching non-term-code settings */
9161 int num_term = 0; /* Nr of matching terminal code settings */
9162 int opt_idx;
9163 int match;
9164 int count = 0;
9165 char_u *str;
9166 int loop;
9167 int is_term_opt;
9168 char_u name_buf[MAX_KEY_NAME_LEN];
9169 static char *(names[]) = {"all", "termcap"};
9170 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
9171
9172 /* do this loop twice:
9173 * loop == 0: count the number of matching options
9174 * loop == 1: copy the matching options into allocated memory
9175 */
9176 for (loop = 0; loop <= 1; ++loop)
9177 {
9178 regmatch->rm_ic = ic;
9179 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
9180 {
9181 for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
9182 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
9183 {
9184 if (loop == 0)
9185 num_normal++;
9186 else
9187 (*file)[count++] = vim_strsave((char_u *)names[match]);
9188 }
9189 }
9190 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
9191 opt_idx++)
9192 {
9193 if (options[opt_idx].var == NULL)
9194 continue;
9195 if (xp->xp_context == EXPAND_BOOL_SETTINGS
9196 && !(options[opt_idx].flags & P_BOOL))
9197 continue;
9198 is_term_opt = istermoption(&options[opt_idx]);
9199 if (is_term_opt && num_normal > 0)
9200 continue;
9201 match = FALSE;
9202 if (vim_regexec(regmatch, str, (colnr_T)0)
9203 || (options[opt_idx].shortname != NULL
9204 && vim_regexec(regmatch,
9205 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
9206 match = TRUE;
9207 else if (is_term_opt)
9208 {
9209 name_buf[0] = '<';
9210 name_buf[1] = 't';
9211 name_buf[2] = '_';
9212 name_buf[3] = str[2];
9213 name_buf[4] = str[3];
9214 name_buf[5] = '>';
9215 name_buf[6] = NUL;
9216 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9217 {
9218 match = TRUE;
9219 str = name_buf;
9220 }
9221 }
9222 if (match)
9223 {
9224 if (loop == 0)
9225 {
9226 if (is_term_opt)
9227 num_term++;
9228 else
9229 num_normal++;
9230 }
9231 else
9232 (*file)[count++] = vim_strsave(str);
9233 }
9234 }
9235 /*
9236 * Check terminal key codes, these are not in the option table
9237 */
9238 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
9239 {
9240 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
9241 {
9242 if (!isprint(str[0]) || !isprint(str[1]))
9243 continue;
9244
9245 name_buf[0] = 't';
9246 name_buf[1] = '_';
9247 name_buf[2] = str[0];
9248 name_buf[3] = str[1];
9249 name_buf[4] = NUL;
9250
9251 match = FALSE;
9252 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9253 match = TRUE;
9254 else
9255 {
9256 name_buf[0] = '<';
9257 name_buf[1] = 't';
9258 name_buf[2] = '_';
9259 name_buf[3] = str[0];
9260 name_buf[4] = str[1];
9261 name_buf[5] = '>';
9262 name_buf[6] = NUL;
9263
9264 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9265 match = TRUE;
9266 }
9267 if (match)
9268 {
9269 if (loop == 0)
9270 num_term++;
9271 else
9272 (*file)[count++] = vim_strsave(name_buf);
9273 }
9274 }
9275
9276 /*
9277 * Check special key names.
9278 */
9279 regmatch->rm_ic = TRUE; /* ignore case here */
9280 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
9281 {
9282 name_buf[0] = '<';
9283 STRCPY(name_buf + 1, str);
9284 STRCAT(name_buf, ">");
9285
9286 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
9287 {
9288 if (loop == 0)
9289 num_term++;
9290 else
9291 (*file)[count++] = vim_strsave(name_buf);
9292 }
9293 }
9294 }
9295 if (loop == 0)
9296 {
9297 if (num_normal > 0)
9298 *num_file = num_normal;
9299 else if (num_term > 0)
9300 *num_file = num_term;
9301 else
9302 return OK;
9303 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
9304 if (*file == NULL)
9305 {
9306 *file = (char_u **)"";
9307 return FAIL;
9308 }
9309 }
9310 }
9311 return OK;
9312}
9313
9314 int
9315ExpandOldSetting(num_file, file)
9316 int *num_file;
9317 char_u ***file;
9318{
9319 char_u *var = NULL; /* init for GCC */
9320 char_u *buf;
9321
9322 *num_file = 0;
9323 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
9324 if (*file == NULL)
9325 return FAIL;
9326
9327 /*
9328 * For a terminal key code expand_option_idx is < 0.
9329 */
9330 if (expand_option_idx < 0)
9331 {
9332 var = find_termcode(expand_option_name + 2);
9333 if (var == NULL)
9334 expand_option_idx = findoption(expand_option_name);
9335 }
9336
9337 if (expand_option_idx >= 0)
9338 {
9339 /* put string of option value in NameBuff */
9340 option_value2string(&options[expand_option_idx], expand_option_flags);
9341 var = NameBuff;
9342 }
9343 else if (var == NULL)
9344 var = (char_u *)"";
9345
9346 /* A backslash is required before some characters. This is the reverse of
9347 * what happens in do_set(). */
9348 buf = vim_strsave_escaped(var, escape_chars);
9349
9350 if (buf == NULL)
9351 {
9352 vim_free(*file);
9353 *file = NULL;
9354 return FAIL;
9355 }
9356
9357#ifdef BACKSLASH_IN_FILENAME
9358 /* For MS-Windows et al. we don't double backslashes at the start and
9359 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009360 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361 if (var[0] == '\\' && var[1] == '\\'
9362 && expand_option_idx >= 0
9363 && (options[expand_option_idx].flags & P_EXPAND)
9364 && vim_isfilec(var[2])
9365 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
9366 mch_memmove(var, var + 1, STRLEN(var));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367#endif
9368
9369 *file[0] = buf;
9370 *num_file = 1;
9371 return OK;
9372}
9373#endif
9374
9375/*
9376 * Get the value for the numeric or string option *opp in a nice format into
9377 * NameBuff[]. Must not be called with a hidden option!
9378 */
9379 static void
9380option_value2string(opp, opt_flags)
9381 struct vimoption *opp;
9382 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9383{
9384 char_u *varp;
9385
9386 varp = get_varp_scope(opp, opt_flags);
9387
9388 if (opp->flags & P_NUM)
9389 {
9390 long wc = 0;
9391
9392 if (wc_use_keyname(varp, &wc))
9393 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
9394 else if (wc != 0)
9395 STRCPY(NameBuff, transchar((int)wc));
9396 else
9397 sprintf((char *)NameBuff, "%ld", *(long *)varp);
9398 }
9399 else /* P_STRING */
9400 {
9401 varp = *(char_u **)(varp);
9402 if (varp == NULL) /* just in case */
9403 NameBuff[0] = NUL;
9404#ifdef FEAT_CRYPT
9405 /* don't show the actual value of 'key', only that it's set */
9406 if (opp->var == (char_u *)&p_key && *varp)
9407 STRCPY(NameBuff, "*****");
9408#endif
9409 else if (opp->flags & P_EXPAND)
9410 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
9411 /* Translate 'pastetoggle' into special key names */
9412 else if ((char_u **)opp->var == &p_pt)
9413 str2specialbuf(p_pt, NameBuff, MAXPATHL);
9414 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +00009415 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416 }
9417}
9418
9419/*
9420 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
9421 * printed as a keyname.
9422 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
9423 */
9424 static int
9425wc_use_keyname(varp, wcp)
9426 char_u *varp;
9427 long *wcp;
9428{
9429 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
9430 {
9431 *wcp = *(long *)varp;
9432 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
9433 return TRUE;
9434 }
9435 return FALSE;
9436}
9437
9438#ifdef FEAT_LANGMAP
9439/*
9440 * Any character has an equivalent character. This is used for keyboards that
9441 * have a special language mode that sends characters above 128 (although
9442 * other characters can be translated too).
9443 */
9444
9445/*
9446 * char_u langmap_mapchar[256];
9447 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
9448 * "translate" native lang chars in normal mode or some cases of
9449 * insert mode without having to tediously switch lang mode back&forth.
9450 */
9451
9452 static void
9453langmap_init()
9454{
9455 int i;
9456
9457 for (i = 0; i < 256; i++) /* we init with a-one-to one map */
9458 langmap_mapchar[i] = i;
9459}
9460
9461/*
9462 * Called when langmap option is set; the language map can be
9463 * changed at any time!
9464 */
9465 static void
9466langmap_set()
9467{
9468 char_u *p;
9469 char_u *p2;
9470 int from, to;
9471
9472 langmap_init(); /* back to one-to-one map first */
9473
9474 for (p = p_langmap; p[0] != NUL; )
9475 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009476 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
9477 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009478 {
9479 if (p2[0] == '\\' && p2[1] != NUL)
9480 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009481 }
9482 if (p2[0] == ';')
9483 ++p2; /* abcd;ABCD form, p2 points to A */
9484 else
9485 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
9486 while (p[0])
9487 {
9488 if (p[0] == '\\' && p[1] != NUL)
9489 ++p;
9490#ifdef FEAT_MBYTE
9491 from = (*mb_ptr2char)(p);
9492#else
9493 from = p[0];
9494#endif
9495 if (p2 == NULL)
9496 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009497 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009498 if (p[0] == '\\')
9499 ++p;
9500#ifdef FEAT_MBYTE
9501 to = (*mb_ptr2char)(p);
9502#else
9503 to = p[0];
9504#endif
9505 }
9506 else
9507 {
9508 if (p2[0] == '\\')
9509 ++p2;
9510#ifdef FEAT_MBYTE
9511 to = (*mb_ptr2char)(p2);
9512#else
9513 to = p2[0];
9514#endif
9515 }
9516 if (to == NUL)
9517 {
9518 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
9519 transchar(from));
9520 return;
9521 }
9522 langmap_mapchar[from & 255] = to;
9523
9524 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009525 mb_ptr_adv(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009526 if (p2 == NULL)
9527 {
9528 if (p[0] == ',')
9529 {
9530 ++p;
9531 break;
9532 }
9533 }
9534 else
9535 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009536 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537 if (*p == ';')
9538 {
9539 p = p2;
9540 if (p[0] != NUL)
9541 {
9542 if (p[0] != ',')
9543 {
9544 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9545 return;
9546 }
9547 ++p;
9548 }
9549 break;
9550 }
9551 }
9552 }
9553 }
9554}
9555#endif
9556
9557/*
9558 * Return TRUE if format option 'x' is in effect.
9559 * Take care of no formatting when 'paste' is set.
9560 */
9561 int
9562has_format_option(x)
9563 int x;
9564{
9565 if (p_paste)
9566 return FALSE;
9567 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9568}
9569
9570/*
9571 * Return TRUE if "x" is present in 'shortmess' option, or
9572 * 'shortmess' contains 'a' and "x" is present in SHM_A.
9573 */
9574 int
9575shortmess(x)
9576 int x;
9577{
9578 return ( vim_strchr(p_shm, x) != NULL
9579 || (vim_strchr(p_shm, 'a') != NULL
9580 && vim_strchr((char_u *)SHM_A, x) != NULL));
9581}
9582
9583/*
9584 * paste_option_changed() - Called after p_paste was set or reset.
9585 */
9586 static void
9587paste_option_changed()
9588{
9589 static int old_p_paste = FALSE;
9590 static int save_sm = 0;
9591#ifdef FEAT_CMDL_INFO
9592 static int save_ru = 0;
9593#endif
9594#ifdef FEAT_RIGHTLEFT
9595 static int save_ri = 0;
9596 static int save_hkmap = 0;
9597#endif
9598 buf_T *buf;
9599
9600 if (p_paste)
9601 {
9602 /*
9603 * Paste switched from off to on.
9604 * Save the current values, so they can be restored later.
9605 */
9606 if (!old_p_paste)
9607 {
9608 /* save options for each buffer */
9609 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9610 {
9611 buf->b_p_tw_nopaste = buf->b_p_tw;
9612 buf->b_p_wm_nopaste = buf->b_p_wm;
9613 buf->b_p_sts_nopaste = buf->b_p_sts;
9614 buf->b_p_ai_nopaste = buf->b_p_ai;
9615 }
9616
9617 /* save global options */
9618 save_sm = p_sm;
9619#ifdef FEAT_CMDL_INFO
9620 save_ru = p_ru;
9621#endif
9622#ifdef FEAT_RIGHTLEFT
9623 save_ri = p_ri;
9624 save_hkmap = p_hkmap;
9625#endif
9626 /* save global values for local buffer options */
9627 p_tw_nopaste = p_tw;
9628 p_wm_nopaste = p_wm;
9629 p_sts_nopaste = p_sts;
9630 p_ai_nopaste = p_ai;
9631 }
9632
9633 /*
9634 * Always set the option values, also when 'paste' is set when it is
9635 * already on.
9636 */
9637 /* set options for each buffer */
9638 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9639 {
9640 buf->b_p_tw = 0; /* textwidth is 0 */
9641 buf->b_p_wm = 0; /* wrapmargin is 0 */
9642 buf->b_p_sts = 0; /* softtabstop is 0 */
9643 buf->b_p_ai = 0; /* no auto-indent */
9644 }
9645
9646 /* set global options */
9647 p_sm = 0; /* no showmatch */
9648#ifdef FEAT_CMDL_INFO
9649# ifdef FEAT_WINDOWS
9650 if (p_ru)
9651 status_redraw_all(); /* redraw to remove the ruler */
9652# endif
9653 p_ru = 0; /* no ruler */
9654#endif
9655#ifdef FEAT_RIGHTLEFT
9656 p_ri = 0; /* no reverse insert */
9657 p_hkmap = 0; /* no Hebrew keyboard */
9658#endif
9659 /* set global values for local buffer options */
9660 p_tw = 0;
9661 p_wm = 0;
9662 p_sts = 0;
9663 p_ai = 0;
9664 }
9665
9666 /*
9667 * Paste switched from on to off: Restore saved values.
9668 */
9669 else if (old_p_paste)
9670 {
9671 /* restore options for each buffer */
9672 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9673 {
9674 buf->b_p_tw = buf->b_p_tw_nopaste;
9675 buf->b_p_wm = buf->b_p_wm_nopaste;
9676 buf->b_p_sts = buf->b_p_sts_nopaste;
9677 buf->b_p_ai = buf->b_p_ai_nopaste;
9678 }
9679
9680 /* restore global options */
9681 p_sm = save_sm;
9682#ifdef FEAT_CMDL_INFO
9683# ifdef FEAT_WINDOWS
9684 if (p_ru != save_ru)
9685 status_redraw_all(); /* redraw to draw the ruler */
9686# endif
9687 p_ru = save_ru;
9688#endif
9689#ifdef FEAT_RIGHTLEFT
9690 p_ri = save_ri;
9691 p_hkmap = save_hkmap;
9692#endif
9693 /* set global values for local buffer options */
9694 p_tw = p_tw_nopaste;
9695 p_wm = p_wm_nopaste;
9696 p_sts = p_sts_nopaste;
9697 p_ai = p_ai_nopaste;
9698 }
9699
9700 old_p_paste = p_paste;
9701}
9702
9703/*
9704 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9705 *
9706 * Reset 'compatible' and set the values for options that didn't get set yet
9707 * to the Vim defaults.
9708 * Don't do this if the 'compatible' option has been set or reset before.
9709 */
9710 void
9711vimrc_found()
9712{
9713 int opt_idx;
9714
9715 if (!option_was_set((char_u *)"cp"))
9716 {
9717 p_cp = FALSE;
9718 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9719 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9720 set_option_default(opt_idx, OPT_FREE, FALSE);
9721 didset_options();
9722 }
9723}
9724
9725/*
9726 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
9727 */
9728 void
9729change_compatible(on)
9730 int on;
9731{
9732 if (p_cp != on)
9733 {
9734 p_cp = on;
9735 compatible_set();
9736 }
9737 options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9738}
9739
9740/*
9741 * Return TRUE when option "name" has been set.
9742 */
9743 int
9744option_was_set(name)
9745 char_u *name;
9746{
9747 int idx;
9748
9749 idx = findoption(name);
9750 if (idx < 0) /* unknown option */
9751 return FALSE;
9752 if (options[idx].flags & P_WAS_SET)
9753 return TRUE;
9754 return FALSE;
9755}
9756
9757/*
9758 * compatible_set() - Called when 'compatible' has been set or unset.
9759 *
9760 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9761 * flag) to a Vi compatible value.
9762 * When 'compatible' is unset: Set all options that have a different default
9763 * for Vim (without the P_VI_DEF flag) to that default.
9764 */
9765 static void
9766compatible_set()
9767{
9768 int opt_idx;
9769
9770 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9771 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
9772 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9773 set_option_default(opt_idx, OPT_FREE, p_cp);
9774 didset_options();
9775}
9776
9777#ifdef FEAT_LINEBREAK
9778
9779# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9780 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009781 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782# endif
9783
9784/*
9785 * fill_breakat_flags() -- called when 'breakat' changes value.
9786 */
9787 static void
9788fill_breakat_flags()
9789{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00009790 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009791 int i;
9792
9793 for (i = 0; i < 256; i++)
9794 breakat_flags[i] = FALSE;
9795
9796 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +00009797 for (p = p_breakat; *p; p++)
9798 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009799}
9800
9801# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +00009802 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803# endif
9804
9805#endif
9806
9807/*
9808 * Check an option that can be a range of string values.
9809 *
9810 * Return OK for correct value, FAIL otherwise.
9811 * Empty is always OK.
9812 */
9813 static int
9814check_opt_strings(val, values, list)
9815 char_u *val;
9816 char **values;
9817 int list; /* when TRUE: accept a list of values */
9818{
9819 return opt_strings_flags(val, values, NULL, list);
9820}
9821
9822/*
9823 * Handle an option that can be a range of string values.
9824 * Set a flag in "*flagp" for each string present.
9825 *
9826 * Return OK for correct value, FAIL otherwise.
9827 * Empty is always OK.
9828 */
9829 static int
9830opt_strings_flags(val, values, flagp, list)
9831 char_u *val; /* new value */
9832 char **values; /* array of valid string values */
9833 unsigned *flagp;
9834 int list; /* when TRUE: accept a list of values */
9835{
9836 int i;
9837 int len;
9838 unsigned new_flags = 0;
9839
9840 while (*val)
9841 {
9842 for (i = 0; ; ++i)
9843 {
9844 if (values[i] == NULL) /* val not found in values[] */
9845 return FAIL;
9846
9847 len = (int)STRLEN(values[i]);
9848 if (STRNCMP(values[i], val, len) == 0
9849 && ((list && val[len] == ',') || val[len] == NUL))
9850 {
9851 val += len + (val[len] == ',');
9852 new_flags |= (1 << i);
9853 break; /* check next item in val list */
9854 }
9855 }
9856 }
9857 if (flagp != NULL)
9858 *flagp = new_flags;
9859
9860 return OK;
9861}
9862
9863/*
9864 * Read the 'wildmode' option, fill wim_flags[].
9865 */
9866 static int
9867check_opt_wim()
9868{
9869 char_u new_wim_flags[4];
9870 char_u *p;
9871 int i;
9872 int idx = 0;
9873
9874 for (i = 0; i < 4; ++i)
9875 new_wim_flags[i] = 0;
9876
9877 for (p = p_wim; *p; ++p)
9878 {
9879 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9880 ;
9881 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9882 return FAIL;
9883 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9884 new_wim_flags[idx] |= WIM_LONGEST;
9885 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9886 new_wim_flags[idx] |= WIM_FULL;
9887 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9888 new_wim_flags[idx] |= WIM_LIST;
9889 else
9890 return FAIL;
9891 p += i;
9892 if (*p == NUL)
9893 break;
9894 if (*p == ',')
9895 {
9896 if (idx == 3)
9897 return FAIL;
9898 ++idx;
9899 }
9900 }
9901
9902 /* fill remaining entries with last flag */
9903 while (idx < 3)
9904 {
9905 new_wim_flags[idx + 1] = new_wim_flags[idx];
9906 ++idx;
9907 }
9908
9909 /* only when there are no errors, wim_flags[] is changed */
9910 for (i = 0; i < 4; ++i)
9911 wim_flags[i] = new_wim_flags[i];
9912 return OK;
9913}
9914
9915/*
9916 * Check if backspacing over something is allowed.
9917 */
9918 int
9919can_bs(what)
9920 int what; /* BS_INDENT, BS_EOL or BS_START */
9921{
9922 switch (*p_bs)
9923 {
9924 case '2': return TRUE;
9925 case '1': return (what != BS_START);
9926 case '0': return FALSE;
9927 }
9928 return vim_strchr(p_bs, what) != NULL;
9929}
9930
9931/*
9932 * Save the current values of 'fileformat' and 'fileencoding', so that we know
9933 * the file must be considered changed when the value is different.
9934 */
9935 void
9936save_file_ff(buf)
9937 buf_T *buf;
9938{
9939 buf->b_start_ffc = *buf->b_p_ff;
9940 buf->b_start_eol = buf->b_p_eol;
9941#ifdef FEAT_MBYTE
9942 /* Only use free/alloc when necessary, they take time. */
9943 if (buf->b_start_fenc == NULL
9944 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9945 {
9946 vim_free(buf->b_start_fenc);
9947 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9948 }
9949#endif
9950}
9951
9952/*
9953 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9954 * from when editing started (save_file_ff() called).
9955 * Also when 'endofline' was changed and 'binary' is set.
9956 * Don't consider a new, empty buffer to be changed.
9957 */
9958 int
9959file_ff_differs(buf)
9960 buf_T *buf;
9961{
9962 if ((buf->b_flags & BF_NEW)
9963 && buf->b_ml.ml_line_count == 1
9964 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
9965 return FALSE;
9966 if (buf->b_start_ffc != *buf->b_p_ff)
9967 return TRUE;
9968 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
9969 return TRUE;
9970#ifdef FEAT_MBYTE
9971 if (buf->b_start_fenc == NULL)
9972 return (*buf->b_p_fenc != NUL);
9973 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
9974#else
9975 return FALSE;
9976#endif
9977}
9978
9979/*
9980 * return OK if "p" is a valid fileformat name, FAIL otherwise.
9981 */
9982 int
9983check_ff_value(p)
9984 char_u *p;
9985{
9986 return check_opt_strings(p, p_ff_values, FALSE);
9987}