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