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