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