blob: a4af18adfe139bf7d915bdda707368a2d867b568 [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
Bram Moolenaar40e6a712010-05-16 22:32:54 +020080#define PV_CM OPT_BUF(BV_CM)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
137#endif
138#define PV_MA OPT_BUF(BV_MA)
139#define PV_ML OPT_BUF(BV_ML)
140#define PV_MOD OPT_BUF(BV_MOD)
141#define PV_MPS OPT_BUF(BV_MPS)
142#define PV_NF OPT_BUF(BV_NF)
143#ifdef FEAT_OSFILETYPE
144# define PV_OFT OPT_BUF(BV_OFT)
145#endif
146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200180#ifdef FEAT_PERSISTENT_UNDO
181# define PV_UDF OPT_BUF(BV_UDF)
182#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184
185/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186 * Definition of the PV_ values for window-local options.
187 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189#define PV_LIST OPT_WIN(WV_LIST)
190#ifdef FEAT_ARABIC
191# define PV_ARAB OPT_WIN(WV_ARAB)
192#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000193#ifdef FEAT_DIFF
194# define PV_DIFF OPT_WIN(WV_DIFF)
195#endif
196#ifdef FEAT_FOLDING
197# define PV_FDC OPT_WIN(WV_FDC)
198# define PV_FEN OPT_WIN(WV_FEN)
199# define PV_FDI OPT_WIN(WV_FDI)
200# define PV_FDL OPT_WIN(WV_FDL)
201# define PV_FDM OPT_WIN(WV_FDM)
202# define PV_FML OPT_WIN(WV_FML)
203# define PV_FDN OPT_WIN(WV_FDN)
204# ifdef FEAT_EVAL
205# define PV_FDE OPT_WIN(WV_FDE)
206# define PV_FDT OPT_WIN(WV_FDT)
207# endif
208# define PV_FMR OPT_WIN(WV_FMR)
209#endif
210#ifdef FEAT_LINEBREAK
211# define PV_LBR OPT_WIN(WV_LBR)
212#endif
213#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200214#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000215#ifdef FEAT_LINEBREAK
216# define PV_NUW OPT_WIN(WV_NUW)
217#endif
218#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
219# define PV_PVW OPT_WIN(WV_PVW)
220#endif
221#ifdef FEAT_RIGHTLEFT
222# define PV_RL OPT_WIN(WV_RL)
223# define PV_RLC OPT_WIN(WV_RLC)
224#endif
225#ifdef FEAT_SCROLLBIND
226# define PV_SCBIND OPT_WIN(WV_SCBIND)
227#endif
228#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000229#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000230# define PV_SPELL OPT_WIN(WV_SPELL)
231#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SYN_HL
233# define PV_CUC OPT_WIN(WV_CUC)
234# define PV_CUL OPT_WIN(WV_CUL)
235#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000236#ifdef FEAT_STL_OPT
237# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
238#endif
239#ifdef FEAT_WINDOWS
240# define PV_WFH OPT_WIN(WV_WFH)
241#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000242#ifdef FEAT_VERTSPLIT
243# define PV_WFW OPT_WIN(WV_WFW)
244#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000246
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000247
248/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000249typedef enum
250{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000251 PV_NONE = 0,
252 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253} idopt_T;
254
255/*
256 * Options local to a window have a value local to a buffer and global to all
257 * buffers. Indicate this by setting "var" to VAR_WIN.
258 */
259#define VAR_WIN ((char_u *)-1)
260
261/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000262 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000263 * Only to be used in option.c!
264 */
265static int p_ai;
266static int p_bin;
267#ifdef FEAT_MBYTE
268static int p_bomb;
269#endif
270#if defined(FEAT_QUICKFIX)
271static char_u *p_bh;
272static char_u *p_bt;
273#endif
274static int p_bl;
275static int p_ci;
276#ifdef FEAT_CINDENT
277static int p_cin;
278static char_u *p_cink;
279static char_u *p_cino;
280#endif
281#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
282static char_u *p_cinw;
283#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200284#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200285static long p_cm;
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287#ifdef FEAT_COMMENTS
288static char_u *p_com;
289#endif
290#ifdef FEAT_FOLDING
291static char_u *p_cms;
292#endif
293#ifdef FEAT_INS_EXPAND
294static char_u *p_cpt;
295#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000296#ifdef FEAT_COMPL_FUNC
297static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000298static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000299#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300static int p_eol;
301static int p_et;
302#ifdef FEAT_MBYTE
303static char_u *p_fenc;
304#endif
305static char_u *p_ff;
306static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000307static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308#ifdef FEAT_AUTOCMD
309static char_u *p_ft;
310#endif
311static long p_iminsert;
312static long p_imsearch;
313#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
314static char_u *p_inex;
315#endif
316#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
317static char_u *p_inde;
318static char_u *p_indk;
319#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000320#if defined(FEAT_EVAL)
321static char_u *p_fex;
322#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000323static int p_inf;
324static char_u *p_isk;
325#ifdef FEAT_CRYPT
326static char_u *p_key;
327#endif
328#ifdef FEAT_LISP
329static int p_lisp;
330#endif
331static int p_ml;
332static int p_ma;
333static int p_mod;
334static char_u *p_mps;
335static char_u *p_nf;
336#ifdef FEAT_OSFILETYPE
337static char_u *p_oft;
338#endif
339static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000340#ifdef FEAT_TEXTOBJ
341static char_u *p_qe;
342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_ro;
344#ifdef FEAT_SMARTINDENT
345static int p_si;
346#endif
347#ifndef SHORT_FNAME
348static int p_sn;
349#endif
350static long p_sts;
351#if defined(FEAT_SEARCHPATH)
352static char_u *p_sua;
353#endif
354static long p_sw;
355static int p_swf;
356#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000357static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000359#endif
360#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000361static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000362static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000363static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364#endif
365static long p_ts;
366static long p_tw;
367static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200368#ifdef FEAT_PERSISTENT_UNDO
369static int p_udf;
370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000371static long p_wm;
372#ifdef FEAT_KEYMAP
373static char_u *p_keymap;
374#endif
375
376/* Saved values for when 'bin' is set. */
377static int p_et_nobin;
378static int p_ml_nobin;
379static long p_tw_nobin;
380static long p_wm_nobin;
381
382/* Saved values for when 'paste' is set */
383static long p_tw_nopaste;
384static long p_wm_nopaste;
385static long p_sts_nopaste;
386static int p_ai_nopaste;
387
388struct vimoption
389{
390 char *fullname; /* full option name */
391 char *shortname; /* permissible abbreviation */
392 long_u flags; /* see below */
393 char_u *var; /* global option: pointer to variable;
394 * window-local option: VAR_WIN;
395 * buffer-local option: global value */
396 idopt_T indir; /* global option: PV_NONE;
397 * local option: indirect option index */
398 char_u *def_val[2]; /* default values for variable (vi and vim) */
399#ifdef FEAT_EVAL
400 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000401# define SCRIPTID_INIT , 0
402#else
403# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404#endif
405};
406
407#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
408#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
409
410/*
411 * Flags
412 */
413#define P_BOOL 0x01 /* the option is boolean */
414#define P_NUM 0x02 /* the option is numeric */
415#define P_STRING 0x04 /* the option is a string */
416#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000417 must use free_string_option() when
418 assigning new value. Not set if default is
419 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
421 never be used for local or hidden options! */
422#define P_NODEFAULT 0x40 /* don't set to default value */
423#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
424 use vim_free() when assigning new value */
425#define P_WAS_SET 0x100 /* option has been set/reset */
426#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
427#define P_VI_DEF 0x400 /* Use Vi default for Vim */
428#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
429
430 /* when option changed, what to display: */
431#define P_RSTAT 0x1000 /* redraw status lines */
432#define P_RWIN 0x2000 /* redraw current window */
433#define P_RBUF 0x4000 /* redraw current buffer */
434#define P_RALL 0x6000 /* redraw all windows */
435#define P_RCLR 0x7000 /* clear and redraw all */
436
437#define P_COMMA 0x8000 /* comma separated list */
438#define P_NODUP 0x10000L/* don't allow duplicate strings */
439#define P_FLAGLIST 0x20000L/* list of single-char flags */
440
441#define P_SECURE 0x40000L/* cannot change in modeline or secure mode */
442#define P_GETTEXT 0x80000L/* expand default value with _() */
443#define P_NOGLOB 0x100000L/* do not use local value for global vimrc */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000444#define P_NFNAME 0x200000L/* only normal file name chars allowed */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +0000445#define P_INSECURE 0x400000L/* option was set from a modeline */
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000446#define P_PRI_MKRC 0x800000L/* priority for :mkvimrc (setting option has
447 side effects) */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000448
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000449#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
450
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000451/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
452 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000453#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000454# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000455#else
456# define ISP_LATIN1 (char_u *)"@,161-255"
457#endif
458
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000459/* The 16 bit MS-DOS version is low on space, make the string as short as
460 * possible when compiling with few features. */
461#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
462 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
463 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL)
464# define HIGHLIGHT_INIT "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,!:CursorColumn,.:CursorLine"
465#else
466# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
467#endif
468
Bram Moolenaar071d4272004-06-13 20:20:40 +0000469/*
470 * options[] is initialized here.
471 * The order of the options MUST be alphabetic for ":set all" and findoption().
472 * All option names MUST start with a lowercase letter (for findoption()).
473 * Exception: "t_" options are at the end.
474 * The options with a NULL variable are 'hidden': a set command for them is
475 * ignored and they are not printed.
476 */
477static struct vimoption
478#ifdef FEAT_GUI_W16
479 _far
480#endif
481 options[] =
482{
483 {"aleph", "al", P_NUM|P_VI_DEF,
484#ifdef FEAT_RIGHTLEFT
485 (char_u *)&p_aleph, PV_NONE,
486#else
487 (char_u *)NULL, PV_NONE,
488#endif
489 {
490#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
491 (char_u *)128L,
492#else
493 (char_u *)224L,
494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000495 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
497#if defined(FEAT_GUI) && defined(MACOS_X)
498 (char_u *)&p_antialias, PV_NONE,
499 {(char_u *)FALSE, (char_u *)FALSE}
500#else
501 (char_u *)NULL, PV_NONE,
502 {(char_u *)FALSE, (char_u *)FALSE}
503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM,
506#ifdef FEAT_ARABIC
507 (char_u *)VAR_WIN, PV_ARAB,
508#else
509 (char_u *)NULL, PV_NONE,
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
513#ifdef FEAT_ARABIC
514 (char_u *)&p_arshape, PV_NONE,
515#else
516 (char_u *)NULL, PV_NONE,
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
520#ifdef FEAT_RIGHTLEFT
521 (char_u *)&p_ari, PV_NONE,
522#else
523 (char_u *)NULL, PV_NONE,
524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000525 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
527#ifdef FEAT_FKMAP
528 (char_u *)&p_altkeymap, PV_NONE,
529#else
530 (char_u *)NULL, PV_NONE,
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
534#if defined(FEAT_MBYTE)
535 (char_u *)&p_ambw, PV_NONE,
536 {(char_u *)"single", (char_u *)0L}
537#else
538 (char_u *)NULL, PV_NONE,
539 {(char_u *)0L, (char_u *)0L}
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000542#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 {"autochdir", "acd", P_BOOL|P_VI_DEF,
544 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546#endif
547 {"autoindent", "ai", P_BOOL|P_VI_DEF,
548 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autoprint", "ap", P_BOOL|P_VI_DEF,
551 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000554 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autowrite", "aw", P_BOOL|P_VI_DEF,
557 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autowriteall","awa", P_BOOL|P_VI_DEF,
560 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
563 (char_u *)&p_bg, PV_NONE,
564 {
565#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
566 (char_u *)"dark",
567#else
568 (char_u *)"light",
569#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000570 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
572 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
575 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
578 (char_u *)&p_bkc, PV_NONE,
579#ifdef UNIX
580 {(char_u *)"yes", (char_u *)"auto"}
581#else
582 {(char_u *)"auto", (char_u *)"auto"}
583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000584 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
586 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000588 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 (char_u *)&p_bex, PV_NONE,
590 {
591#ifdef VMS
592 (char_u *)"_",
593#else
594 (char_u *)"~",
595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
598#ifdef FEAT_WILDIGN
599 (char_u *)&p_bsk, PV_NONE,
600 {(char_u *)"", (char_u *)0L}
601#else
602 (char_u *)NULL, PV_NONE,
603 {(char_u *)0L, (char_u *)0L}
604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000605 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606#ifdef FEAT_BEVAL
607 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
608 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
611 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000613# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000614 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000615 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000617# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618#endif
619 {"beautify", "bf", P_BOOL|P_VI_DEF,
620 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000621 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
623 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
626#ifdef MSDOS
627 (char_u *)&p_biosk, PV_NONE,
628#else
629 (char_u *)NULL, PV_NONE,
630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
633#ifdef FEAT_MBYTE
634 (char_u *)&p_bomb, PV_BOMB,
635#else
636 (char_u *)NULL, PV_NONE,
637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000638 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
640#ifdef FEAT_LINEBREAK
641 (char_u *)&p_breakat, PV_NONE,
642 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
643#else
644 (char_u *)NULL, PV_NONE,
645 {(char_u *)0L, (char_u *)0L}
646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000647 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000648 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
649#ifdef FEAT_BROWSE
650 (char_u *)&p_bsdir, PV_NONE,
651 {(char_u *)"last", (char_u *)0L}
652#else
653 (char_u *)NULL, PV_NONE,
654 {(char_u *)0L, (char_u *)0L}
655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000657 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
658#if defined(FEAT_QUICKFIX)
659 (char_u *)&p_bh, PV_BH,
660 {(char_u *)"", (char_u *)0L}
661#else
662 (char_u *)NULL, PV_NONE,
663 {(char_u *)0L, (char_u *)0L}
664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
667 (char_u *)&p_bl, PV_BL,
668 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
671#if defined(FEAT_QUICKFIX)
672 (char_u *)&p_bt, PV_BT,
673 {(char_u *)"", (char_u *)0L}
674#else
675 (char_u *)NULL, PV_NONE,
676 {(char_u *)0L, (char_u *)0L}
677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000679 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000680#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681 (char_u *)&p_cmp, PV_NONE,
682 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000683#else
684 (char_u *)NULL, PV_NONE,
685 {(char_u *)0L, (char_u *)0L}
686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000687 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000688 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
689#ifdef FEAT_SEARCHPATH
690 (char_u *)&p_cdpath, PV_NONE,
691 {(char_u *)",,", (char_u *)0L}
692#else
693 (char_u *)NULL, PV_NONE,
694 {(char_u *)0L, (char_u *)0L}
695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000696 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000697 {"cedit", NULL, P_STRING,
698#ifdef FEAT_CMDWIN
699 (char_u *)&p_cedit, PV_NONE,
700 {(char_u *)"", (char_u *)CTRL_F_STR}
701#else
702 (char_u *)NULL, PV_NONE,
703 {(char_u *)0L, (char_u *)0L}
704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000705 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
707#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
708 (char_u *)&p_ccv, PV_NONE,
709 {(char_u *)"", (char_u *)0L}
710#else
711 (char_u *)NULL, PV_NONE,
712 {(char_u *)0L, (char_u *)0L}
713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000714 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
716#ifdef FEAT_CINDENT
717 (char_u *)&p_cin, PV_CIN,
718#else
719 (char_u *)NULL, PV_NONE,
720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
723#ifdef FEAT_CINDENT
724 (char_u *)&p_cink, PV_CINK,
725 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
732#ifdef FEAT_CINDENT
733 (char_u *)&p_cino, PV_CINO,
734#else
735 (char_u *)NULL, PV_NONE,
736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000737 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
739#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
740 (char_u *)&p_cinw, PV_CINW,
741 {(char_u *)"if,else,while,do,for,switch",
742 (char_u *)0L}
743#else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
749#ifdef FEAT_CLIPBOARD
750 (char_u *)&p_cb, PV_NONE,
751# ifdef FEAT_XCLIPBOARD
752 {(char_u *)"autoselect,exclude:cons\\|linux",
753 (char_u *)0L}
754# else
755 {(char_u *)"", (char_u *)0L}
756# endif
757#else
758 (char_u *)NULL, PV_NONE,
759 {(char_u *)"", (char_u *)0L}
760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000761 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
763 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000764 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
766#ifdef FEAT_CMDWIN
767 (char_u *)&p_cwh, PV_NONE,
768#else
769 (char_u *)NULL, PV_NONE,
770#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000771 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
773 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
776#ifdef FEAT_COMMENTS
777 (char_u *)&p_com, PV_COM,
778 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
779 (char_u *)0L}
780#else
781 (char_u *)NULL, PV_NONE,
782 {(char_u *)0L, (char_u *)0L}
783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000785 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
786#ifdef FEAT_FOLDING
787 (char_u *)&p_cms, PV_CMS,
788 {(char_u *)"/*%s*/", (char_u *)0L}
789#else
790 (char_u *)NULL, PV_NONE,
791 {(char_u *)0L, (char_u *)0L}
792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000793 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000794 /* P_PRI_MKRC isn't needed here, optval_default()
795 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796 {"compatible", "cp", P_BOOL|P_RALL,
797 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000798 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000799 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
800#ifdef FEAT_INS_EXPAND
801 (char_u *)&p_cpt, PV_CPT,
802 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
803#else
804 (char_u *)NULL, PV_NONE,
805 {(char_u *)0L, (char_u *)0L}
806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000808 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
809#ifdef FEAT_COMPL_FUNC
810 (char_u *)&p_cfu, PV_CFU,
811 {(char_u *)"", (char_u *)0L}
812#else
813 (char_u *)NULL, PV_NONE,
814 {(char_u *)0L, (char_u *)0L}
815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000817 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
818#ifdef FEAT_INS_EXPAND
819 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000820 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000821#else
822 (char_u *)NULL, PV_NONE,
823 {(char_u *)0L, (char_u *)0L}
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826 {"confirm", "cf", P_BOOL|P_VI_DEF,
827#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
828 (char_u *)&p_confirm, PV_NONE,
829#else
830 (char_u *)NULL, PV_NONE,
831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000832 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833 {"conskey", "consk",P_BOOL|P_VI_DEF,
834#ifdef MSDOS
835 (char_u *)&p_consk, PV_NONE,
836#else
837 (char_u *)NULL, PV_NONE,
838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
841 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000842 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
844 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
846 SCRIPTID_INIT},
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200847 {"cryptmethod", "cm", P_NUM|P_VI_DEF|P_VIM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200848#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200849 (char_u *)&p_cm, PV_CM,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200850#else
851 (char_u *)NULL, PV_NONE,
852#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200853 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000854 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
855#ifdef FEAT_CSCOPE
856 (char_u *)&p_cspc, PV_NONE,
857#else
858 (char_u *)NULL, PV_NONE,
859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000860 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
862#ifdef FEAT_CSCOPE
863 (char_u *)&p_csprg, PV_NONE,
864 {(char_u *)"cscope", (char_u *)0L}
865#else
866 (char_u *)NULL, PV_NONE,
867 {(char_u *)0L, (char_u *)0L}
868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000869 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000870 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
871#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
872 (char_u *)&p_csqf, PV_NONE,
873 {(char_u *)"", (char_u *)0L}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)0L, (char_u *)0L}
877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000879 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
880#ifdef FEAT_CSCOPE
881 (char_u *)&p_cst, PV_NONE,
882#else
883 (char_u *)NULL, PV_NONE,
884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
887#ifdef FEAT_CSCOPE
888 (char_u *)&p_csto, PV_NONE,
889#else
890 (char_u *)NULL, PV_NONE,
891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000892 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
894#ifdef FEAT_CSCOPE
895 (char_u *)&p_csverbose, PV_NONE,
896#else
897 (char_u *)NULL, PV_NONE,
898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000899 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000900 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
901#ifdef FEAT_SYN_HL
902 (char_u *)VAR_WIN, PV_CUC,
903#else
904 (char_u *)NULL, PV_NONE,
905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000907 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
908#ifdef FEAT_SYN_HL
909 (char_u *)VAR_WIN, PV_CUL,
910#else
911 (char_u *)NULL, PV_NONE,
912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"debug", NULL, P_STRING|P_VI_DEF,
915 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000916 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF,
918#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000919 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000920 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921#else
922 (char_u *)NULL, PV_NONE,
923 {(char_u *)NULL, (char_u *)0L}
924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000925 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000926 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
927#ifdef FEAT_MBYTE
928 (char_u *)&p_deco, PV_NONE,
929#else
930 (char_u *)NULL, PV_NONE,
931#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000932 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000933 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
934#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000935 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000936#else
937 (char_u *)NULL, PV_NONE,
938#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000939 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000940 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
941#ifdef FEAT_DIFF
942 (char_u *)VAR_WIN, PV_DIFF,
943#else
944 (char_u *)NULL, PV_NONE,
945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000947 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE,
948#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
949 (char_u *)&p_dex, PV_NONE,
950 {(char_u *)"", (char_u *)0L}
951#else
952 (char_u *)NULL, PV_NONE,
953 {(char_u *)0L, (char_u *)0L}
954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000955 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
957#ifdef FEAT_DIFF
958 (char_u *)&p_dip, PV_NONE,
959 {(char_u *)"filler", (char_u *)NULL}
960#else
961 (char_u *)NULL, PV_NONE,
962 {(char_u *)"", (char_u *)NULL}
963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000964 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000965 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
966#ifdef FEAT_DIGRAPHS
967 (char_u *)&p_dg, PV_NONE,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000971 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000972 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
973 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000974 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
976 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000978 {"eadirection", "ead", P_STRING|P_VI_DEF,
979#ifdef FEAT_VERTSPLIT
980 (char_u *)&p_ead, PV_NONE,
981 {(char_u *)"both", (char_u *)0L}
982#else
983 (char_u *)NULL, PV_NONE,
984 {(char_u *)NULL, (char_u *)0L}
985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000986 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000987 {"edcompatible","ed", P_BOOL|P_VI_DEF,
988 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000990 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR,
991#ifdef FEAT_MBYTE
992 (char_u *)&p_enc, PV_NONE,
993 {(char_u *)ENC_DFLT, (char_u *)0L}
994#else
995 (char_u *)NULL, PV_NONE,
996 {(char_u *)0L, (char_u *)0L}
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1000 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001001 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1003 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001006 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1009 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1012#ifdef FEAT_QUICKFIX
1013 (char_u *)&p_ef, PV_NONE,
1014 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1015#else
1016 (char_u *)NULL, PV_NONE,
1017 {(char_u *)NULL, (char_u *)0L}
1018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001019 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1021#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001022 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001023 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024#else
1025 (char_u *)NULL, PV_NONE,
1026 {(char_u *)NULL, (char_u *)0L}
1027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001028 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029 {"esckeys", "ek", P_BOOL|P_VIM,
1030 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001031 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1033#ifdef FEAT_AUTOCMD
1034 (char_u *)&p_ei, PV_NONE,
1035#else
1036 (char_u *)NULL, PV_NONE,
1037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1040 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1043 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1046#ifdef FEAT_MBYTE
1047 (char_u *)&p_fenc, PV_FENC,
1048 {(char_u *)"", (char_u *)0L}
1049#else
1050 (char_u *)NULL, PV_NONE,
1051 {(char_u *)0L, (char_u *)0L}
1052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1055#ifdef FEAT_MBYTE
1056 (char_u *)&p_fencs, PV_NONE,
1057 {(char_u *)"ucs-bom", (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)0L, (char_u *)0L}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
1064 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1067 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001068 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1069 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001070 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071#ifdef FEAT_AUTOCMD
1072 (char_u *)&p_ft, PV_FT,
1073 {(char_u *)"", (char_u *)0L}
1074#else
1075 (char_u *)NULL, PV_NONE,
1076 {(char_u *)0L, (char_u *)0L}
1077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1080#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1081 (char_u *)&p_fcs, PV_NONE,
1082 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1083#else
1084 (char_u *)NULL, PV_NONE,
1085 {(char_u *)"", (char_u *)0L}
1086#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1089#ifdef FEAT_FKMAP
1090 (char_u *)&p_fkmap, PV_NONE,
1091#else
1092 (char_u *)NULL, PV_NONE,
1093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"flash", "fl", P_BOOL|P_VI_DEF,
1096 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098#ifdef FEAT_FOLDING
1099 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1100 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1103 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1106 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1109# ifdef FEAT_EVAL
1110 (char_u *)VAR_WIN, PV_FDE,
1111 {(char_u *)"0", (char_u *)NULL}
1112# else
1113 (char_u *)NULL, PV_NONE,
1114 {(char_u *)NULL, (char_u *)0L}
1115# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1118 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1121 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001122 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
1124 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1127 P_RWIN|P_COMMA|P_NODUP,
1128 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001129 {(char_u *)"{{{,}}}", (char_u *)NULL}
1130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1132 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1135 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1138 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1141 (char_u *)&p_fdo, PV_NONE,
1142 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1145# ifdef FEAT_EVAL
1146 (char_u *)VAR_WIN, PV_FDT,
1147 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001148# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 (char_u *)NULL, PV_NONE,
1150 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001151# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001154 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001155#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001156 (char_u *)&p_fex, PV_FEX,
1157 {(char_u *)"", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)0L, (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001163 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1164 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1166 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001167 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1168 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1170 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1172 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001173 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001174 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1175#ifdef HAVE_FSYNC
1176 (char_u *)&p_fs, PV_NONE,
1177 {(char_u *)TRUE, (char_u *)0L}
1178#else
1179 (char_u *)NULL, PV_NONE,
1180 {(char_u *)FALSE, (char_u *)0L}
1181#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001182 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1184 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"graphic", "gr", P_BOOL|P_VI_DEF,
1187 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1190#ifdef FEAT_QUICKFIX
1191 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001192 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193#else
1194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)NULL, (char_u *)0L}
1196#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1199#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001200 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {
1202# ifdef WIN3264
1203 /* may be changed to "grep -n" in os_win32.c */
1204 (char_u *)"findstr /n",
1205# else
1206# ifdef UNIX
1207 /* Add an extra file name so that grep will always
1208 * insert a file name in the match line. */
1209 (char_u *)"grep -n $* /dev/null",
1210# else
1211# ifdef VMS
1212 (char_u *)"SEARCH/NUMBERS ",
1213# else
1214 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001215# endif
1216# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001218 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219#else
1220 (char_u *)NULL, PV_NONE,
1221 {(char_u *)NULL, (char_u *)0L}
1222#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1225#ifdef CURSOR_SHAPE
1226 (char_u *)&p_guicursor, PV_NONE,
1227 {
1228# ifdef FEAT_GUI
1229 (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",
1230# else /* MSDOS or Win32 console */
1231 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1232# endif
1233 (char_u *)0L}
1234#else
1235 (char_u *)NULL, PV_NONE,
1236 {(char_u *)NULL, (char_u *)0L}
1237#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001238 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1240#ifdef FEAT_GUI
1241 (char_u *)&p_guifont, PV_NONE,
1242 {(char_u *)"", (char_u *)0L}
1243#else
1244 (char_u *)NULL, PV_NONE,
1245 {(char_u *)NULL, (char_u *)0L}
1246#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001247 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001248 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1249#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1250 (char_u *)&p_guifontset, PV_NONE,
1251 {(char_u *)"", (char_u *)0L}
1252#else
1253 (char_u *)NULL, PV_NONE,
1254 {(char_u *)NULL, (char_u *)0L}
1255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1258#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1259 (char_u *)&p_guifontwide, PV_NONE,
1260 {(char_u *)"", (char_u *)0L}
1261#else
1262 (char_u *)NULL, PV_NONE,
1263 {(char_u *)NULL, (char_u *)0L}
1264#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001265 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001267#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268 (char_u *)&p_ghr, PV_NONE,
1269#else
1270 (char_u *)NULL, PV_NONE,
1271#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001274#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001275 (char_u *)&p_go, PV_NONE,
1276# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001277 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001278# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001279 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280# endif
1281#else
1282 (char_u *)NULL, PV_NONE,
1283 {(char_u *)NULL, (char_u *)0L}
1284#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001285 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 {"guipty", NULL, P_BOOL|P_VI_DEF,
1287#if defined(FEAT_GUI)
1288 (char_u *)&p_guipty, PV_NONE,
1289#else
1290 (char_u *)NULL, PV_NONE,
1291#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001292 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001293 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001294#if defined(FEAT_GUI_TABLINE)
1295 (char_u *)&p_gtl, PV_NONE,
1296 {(char_u *)"", (char_u *)0L}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001301 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001302 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001303#if defined(FEAT_GUI_TABLINE)
1304 (char_u *)&p_gtt, PV_NONE,
1305 {(char_u *)"", (char_u *)0L}
1306#else
1307 (char_u *)NULL, PV_NONE,
1308 {(char_u *)NULL, (char_u *)0L}
1309#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1312 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001313 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1315 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001316 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1317 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318 {"helpheight", "hh", P_NUM|P_VI_DEF,
1319#ifdef FEAT_WINDOWS
1320 (char_u *)&p_hh, PV_NONE,
1321#else
1322 (char_u *)NULL, PV_NONE,
1323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001324 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1326#ifdef FEAT_MULTI_LANG
1327 (char_u *)&p_hlg, PV_NONE,
1328 {(char_u *)"", (char_u *)0L}
1329#else
1330 (char_u *)NULL, PV_NONE,
1331 {(char_u *)0L, (char_u *)0L}
1332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334 {"hidden", "hid", P_BOOL|P_VI_DEF,
1335 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1338 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"history", "hi", P_NUM|P_VIM,
1342 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1345#ifdef FEAT_RIGHTLEFT
1346 (char_u *)&p_hkmap, PV_NONE,
1347#else
1348 (char_u *)NULL, PV_NONE,
1349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1352#ifdef FEAT_RIGHTLEFT
1353 (char_u *)&p_hkmapp, PV_NONE,
1354#else
1355 (char_u *)NULL, PV_NONE,
1356#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001357 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1359 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001360 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 {"icon", NULL, P_BOOL|P_VI_DEF,
1362#ifdef FEAT_TITLE
1363 (char_u *)&p_icon, PV_NONE,
1364#else
1365 (char_u *)NULL, PV_NONE,
1366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {"iconstring", NULL, P_STRING|P_VI_DEF,
1369#ifdef FEAT_TITLE
1370 (char_u *)&p_iconstring, PV_NONE,
1371#else
1372 (char_u *)NULL, PV_NONE,
1373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001374 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1376 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001377 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001379#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 (char_u *)&p_imak, PV_NONE,
1381#else
1382 (char_u *)NULL, PV_NONE,
1383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001384 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1386#ifdef USE_IM_CONTROL
1387 (char_u *)&p_imcmdline, PV_NONE,
1388#else
1389 (char_u *)NULL, PV_NONE,
1390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1393#ifdef USE_IM_CONTROL
1394 (char_u *)&p_imdisable, PV_NONE,
1395#else
1396 (char_u *)NULL, PV_NONE,
1397#endif
1398#ifdef __sgi
1399 {(char_u *)TRUE, (char_u *)0L}
1400#else
1401 {(char_u *)FALSE, (char_u *)0L}
1402#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"iminsert", "imi", P_NUM|P_VI_DEF,
1405 (char_u *)&p_iminsert, PV_IMI,
1406#ifdef B_IMODE_IM
1407 {(char_u *)B_IMODE_IM, (char_u *)0L}
1408#else
1409 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"imsearch", "ims", P_NUM|P_VI_DEF,
1413 (char_u *)&p_imsearch, PV_IMS,
1414#ifdef B_IMODE_IM
1415 {(char_u *)B_IMODE_IM, (char_u *)0L}
1416#else
1417 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1418#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001419 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1421#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001422 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1424#else
1425 (char_u *)NULL, PV_NONE,
1426 {(char_u *)0L, (char_u *)0L}
1427#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001428 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1430#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1431 (char_u *)&p_inex, PV_INEX,
1432 {(char_u *)"", (char_u *)0L}
1433#else
1434 (char_u *)NULL, PV_NONE,
1435 {(char_u *)0L, (char_u *)0L}
1436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001437 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1439 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001440 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1442#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1443 (char_u *)&p_inde, PV_INDE,
1444 {(char_u *)"", (char_u *)0L}
1445#else
1446 (char_u *)NULL, PV_NONE,
1447 {(char_u *)0L, (char_u *)0L}
1448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001449 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1451#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1452 (char_u *)&p_indk, PV_INDK,
1453 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1454#else
1455 (char_u *)NULL, PV_NONE,
1456 {(char_u *)0L, (char_u *)0L}
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"infercase", "inf", P_BOOL|P_VI_DEF,
1460 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1463 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1466 (char_u *)&p_isf, PV_NONE,
1467 {
1468#ifdef BACKSLASH_IN_FILENAME
1469 /* Excluded are: & and ^ are special in cmd.exe
1470 * ( and ) are used in text separating fnames */
1471 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1472#else
1473# ifdef AMIGA
1474 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1475# else
1476# ifdef VMS
1477 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1478# else /* UNIX et al. */
1479# ifdef EBCDIC
1480 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1481# else
1482 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1483# endif
1484# endif
1485# endif
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1489 (char_u *)&p_isi, PV_NONE,
1490 {
1491#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1492 (char_u *)"@,48-57,_,128-167,224-235",
1493#else
1494# ifdef EBCDIC
1495 /* TODO: EBCDIC Check this! @ == isalpha()*/
1496 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1497 "112-120,128,140-142,156,158,172,"
1498 "174,186,191,203-207,219-225,235-239,"
1499 "251-254",
1500# else
1501 (char_u *)"@,48-57,_,192-255",
1502# endif
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1506 (char_u *)&p_isk, PV_ISK,
1507 {
1508#ifdef EBCDIC
1509 (char_u *)"@,240-249,_",
1510 /* TODO: EBCDIC Check this! @ == isalpha()*/
1511 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1512 "112-120,128,140-142,156,158,172,"
1513 "174,186,191,203-207,219-225,235-239,"
1514 "251-254",
1515#else
1516 (char_u *)"@,48-57,_",
1517# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1518 (char_u *)"@,48-57,_,128-167,224-235"
1519# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001520 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521# endif
1522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001523 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1525 (char_u *)&p_isp, PV_NONE,
1526 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001527#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1528 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 || defined(VMS)
1530 (char_u *)"@,~-255",
1531#else
1532# ifdef EBCDIC
1533 /* all chars above 63 are printable */
1534 (char_u *)"63-255",
1535# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001536 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537# endif
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1541 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1544#ifdef FEAT_CRYPT
1545 (char_u *)&p_key, PV_KEY,
1546 {(char_u *)"", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001552 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553#ifdef FEAT_KEYMAP
1554 (char_u *)&p_keymap, PV_KMAP,
1555 {(char_u *)"", (char_u *)0L}
1556#else
1557 (char_u *)NULL, PV_NONE,
1558 {(char_u *)"", (char_u *)0L}
1559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001560 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1562#ifdef FEAT_VISUAL
1563 (char_u *)&p_km, PV_NONE,
1564#else
1565 (char_u *)NULL, PV_NONE,
1566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001567 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001569 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 {
1571#if defined(MSDOS) || defined(MSWIN)
1572 (char_u *)":help",
1573#else
1574#ifdef VMS
1575 (char_u *)"help",
1576#else
1577# if defined(OS2)
1578 (char_u *)"view /",
1579# else
1580# ifdef USEMAN_S
1581 (char_u *)"man -s",
1582# else
1583 (char_u *)"man",
1584# endif
1585# endif
1586#endif
1587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001588 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001589 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1590#ifdef FEAT_LANGMAP
1591 (char_u *)&p_langmap, PV_NONE,
1592 {(char_u *)"", /* unmatched } */
1593#else
1594 (char_u *)NULL, PV_NONE,
1595 {(char_u *)NULL,
1596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001598 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1600 (char_u *)&p_lm, PV_NONE,
1601#else
1602 (char_u *)NULL, PV_NONE,
1603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001604 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001605 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1606#ifdef FEAT_WINDOWS
1607 (char_u *)&p_ls, PV_NONE,
1608#else
1609 (char_u *)NULL, PV_NONE,
1610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001611 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001612 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1613 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001614 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1616#ifdef FEAT_LINEBREAK
1617 (char_u *)VAR_WIN, PV_LBR,
1618#else
1619 (char_u *)NULL, PV_NONE,
1620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001621 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1623 (char_u *)&Rows, PV_NONE,
1624 {
1625#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1626 (char_u *)25L,
1627#else
1628 (char_u *)24L,
1629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001630 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1632#ifdef FEAT_GUI
1633 (char_u *)&p_linespace, PV_NONE,
1634#else
1635 (char_u *)NULL, PV_NONE,
1636#endif
1637#ifdef FEAT_GUI_W32
1638 {(char_u *)1L, (char_u *)0L}
1639#else
1640 {(char_u *)0L, (char_u *)0L}
1641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001642 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 {"lisp", NULL, P_BOOL|P_VI_DEF,
1644#ifdef FEAT_LISP
1645 (char_u *)&p_lisp, PV_LISP,
1646#else
1647 (char_u *)NULL, PV_NONE,
1648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1651#ifdef FEAT_LISP
1652 (char_u *)&p_lispwords, PV_NONE,
1653 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1654#else
1655 (char_u *)NULL, PV_NONE,
1656 {(char_u *)"", (char_u *)0L}
1657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1660 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1663 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1666 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001668#ifdef FEAT_GUI_MAC
1669 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1670 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001671 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673 {"magic", NULL, P_BOOL|P_VI_DEF,
1674 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001675 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001676 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001677#ifdef FEAT_QUICKFIX
1678 (char_u *)&p_mef, PV_NONE,
1679 {(char_u *)"", (char_u *)0L}
1680#else
1681 (char_u *)NULL, PV_NONE,
1682 {(char_u *)NULL, (char_u *)0L}
1683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1686#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001687 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688# ifdef VMS
1689 {(char_u *)"MMS", (char_u *)0L}
1690# else
1691 {(char_u *)"make", (char_u *)0L}
1692# endif
1693#else
1694 (char_u *)NULL, PV_NONE,
1695 {(char_u *)NULL, (char_u *)0L}
1696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001697 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1699 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1701 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702 {"matchtime", "mat", P_NUM|P_VI_DEF,
1703 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001704 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001705 {"maxcombine", "mco", P_NUM|P_VI_DEF,
1706#ifdef FEAT_MBYTE
1707 (char_u *)&p_mco, PV_NONE,
1708#else
1709 (char_u *)NULL, PV_NONE,
1710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001711 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1713#ifdef FEAT_EVAL
1714 (char_u *)&p_mfd, PV_NONE,
1715#else
1716 (char_u *)NULL, PV_NONE,
1717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001718 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1720 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"maxmem", "mm", P_NUM|P_VI_DEF,
1723 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1725 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001726 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1727 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001728 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1730 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1732 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 {"menuitems", "mis", P_NUM|P_VI_DEF,
1734#ifdef FEAT_MENU
1735 (char_u *)&p_mis, PV_NONE,
1736#else
1737 (char_u *)NULL, PV_NONE,
1738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001739 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"mesg", NULL, P_BOOL|P_VI_DEF,
1741 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001742 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001743 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001744#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001745 (char_u *)&p_msm, PV_NONE,
1746 {(char_u *)"460000,2000,500", (char_u *)0L}
1747#else
1748 (char_u *)NULL, PV_NONE,
1749 {(char_u *)0L, (char_u *)0L}
1750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001752 {"modeline", "ml", P_BOOL|P_VIM,
1753 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"modelines", "mls", P_NUM|P_VI_DEF,
1756 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001757 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1759 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1762 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {"more", NULL, P_BOOL|P_VIM,
1765 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001766 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1768 (char_u *)&p_mouse, PV_NONE,
1769 {
1770#if defined(MSDOS) || defined(WIN3264)
1771 (char_u *)"a",
1772#else
1773 (char_u *)"",
1774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1777#ifdef FEAT_GUI
1778 (char_u *)&p_mousef, PV_NONE,
1779#else
1780 (char_u *)NULL, PV_NONE,
1781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1784#ifdef FEAT_GUI
1785 (char_u *)&p_mh, PV_NONE,
1786#else
1787 (char_u *)NULL, PV_NONE,
1788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001789 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1791 (char_u *)&p_mousem, PV_NONE,
1792 {
1793#if defined(MSDOS) || defined(MSWIN)
1794 (char_u *)"popup",
1795#else
1796# if defined(MACOS)
1797 (char_u *)"popup_setpos",
1798# else
1799 (char_u *)"extend",
1800# endif
1801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001802 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1804#ifdef FEAT_MOUSESHAPE
1805 (char_u *)&p_mouseshape, PV_NONE,
1806 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1807#else
1808 (char_u *)NULL, PV_NONE,
1809 {(char_u *)NULL, (char_u *)0L}
1810#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001811 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1813 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001815 {"mzquantum", "mzq", P_NUM,
1816#ifdef FEAT_MZSCHEME
1817 (char_u *)&p_mzq, PV_NONE,
1818#else
1819 (char_u *)NULL, PV_NONE,
1820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"novice", NULL, P_BOOL|P_VI_DEF,
1823 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1826 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)"octal,hex", (char_u *)0L}
1828 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1830 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001832 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1833#ifdef FEAT_LINEBREAK
1834 (char_u *)VAR_WIN, PV_NUW,
1835#else
1836 (char_u *)NULL, PV_NONE,
1837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001839 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001840#ifdef FEAT_COMPL_FUNC
1841 (char_u *)&p_ofu, PV_OFU,
1842 {(char_u *)"", (char_u *)0L}
1843#else
1844 (char_u *)NULL, PV_NONE,
1845 {(char_u *)0L, (char_u *)0L}
1846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"open", NULL, P_BOOL|P_VI_DEF,
1849 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001851 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1852#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1853 (char_u *)&p_odev, PV_NONE,
1854#else
1855 (char_u *)NULL, PV_NONE,
1856#endif
1857 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001859 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1860 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {"optimize", "opt", P_BOOL|P_VI_DEF,
1863 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
1866#ifdef FEAT_OSFILETYPE
1867 (char_u *)&p_oft, PV_OFT,
1868 {(char_u *)DFLT_OFT, (char_u *)0L}
1869#else
1870 (char_u *)NULL, PV_NONE,
1871 {(char_u *)0L, (char_u *)0L}
1872#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"paragraphs", "para", P_STRING|P_VI_DEF,
1875 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001876 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001878 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1882 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001883 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1885#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1886 (char_u *)&p_pex, PV_NONE,
1887 {(char_u *)"", (char_u *)0L}
1888#else
1889 (char_u *)NULL, PV_NONE,
1890 {(char_u *)0L, (char_u *)0L}
1891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001892 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001893 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001897 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898 {
1899#if defined AMIGA || defined MSDOS || defined MSWIN
1900 (char_u *)".,,",
1901#else
1902# if defined(__EMX__)
1903 (char_u *)".,/emx/include,,",
1904# else /* Unix, probably */
1905 (char_u *)".,/usr/include,,",
1906# endif
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1910 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001911 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001912 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1914 (char_u *)&p_pvh, PV_NONE,
1915#else
1916 (char_u *)NULL, PV_NONE,
1917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001918 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001919 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1920#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1921 (char_u *)VAR_WIN, PV_PVW,
1922#else
1923 (char_u *)NULL, PV_NONE,
1924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001925 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001926 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927#ifdef FEAT_PRINTER
1928 (char_u *)&p_pdev, PV_NONE,
1929 {(char_u *)"", (char_u *)0L}
1930#else
1931 (char_u *)NULL, PV_NONE,
1932 {(char_u *)NULL, (char_u *)0L}
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"printencoding", "penc", P_STRING|P_VI_DEF,
1936#ifdef FEAT_POSTSCRIPT
1937 (char_u *)&p_penc, PV_NONE,
1938 {(char_u *)"", (char_u *)0L}
1939#else
1940 (char_u *)NULL, PV_NONE,
1941 {(char_u *)NULL, (char_u *)0L}
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
1945#ifdef FEAT_POSTSCRIPT
1946 (char_u *)&p_pexpr, PV_NONE,
1947 {(char_u *)"", (char_u *)0L}
1948#else
1949 (char_u *)NULL, PV_NONE,
1950 {(char_u *)NULL, (char_u *)0L}
1951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"printfont", "pfn", P_STRING|P_VI_DEF,
1954#ifdef FEAT_PRINTER
1955 (char_u *)&p_pfn, PV_NONE,
1956 {
1957# ifdef MSWIN
1958 (char_u *)"Courier_New:h10",
1959# else
1960 (char_u *)"courier",
1961# endif
1962 (char_u *)0L}
1963#else
1964 (char_u *)NULL, PV_NONE,
1965 {(char_u *)NULL, (char_u *)0L}
1966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
1969#ifdef FEAT_PRINTER
1970 (char_u *)&p_header, PV_NONE,
1971 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1972#else
1973 (char_u *)NULL, PV_NONE,
1974 {(char_u *)NULL, (char_u *)0L}
1975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001976 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001977 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
1978#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1979 (char_u *)&p_pmcs, PV_NONE,
1980 {(char_u *)"", (char_u *)0L}
1981#else
1982 (char_u *)NULL, PV_NONE,
1983 {(char_u *)NULL, (char_u *)0L}
1984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00001986 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
1987#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
1988 (char_u *)&p_pmfn, PV_NONE,
1989 {(char_u *)"", (char_u *)0L}
1990#else
1991 (char_u *)NULL, PV_NONE,
1992 {(char_u *)NULL, (char_u *)0L}
1993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1996#ifdef FEAT_PRINTER
1997 (char_u *)&p_popt, PV_NONE,
1998 {(char_u *)"", (char_u *)0L}
1999#else
2000 (char_u *)NULL, PV_NONE,
2001 {(char_u *)NULL, (char_u *)0L}
2002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002003 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002005 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002007 {"pumheight", "ph", P_NUM|P_VI_DEF,
2008#ifdef FEAT_INS_EXPAND
2009 (char_u *)&p_ph, PV_NONE,
2010#else
2011 (char_u *)NULL, PV_NONE,
2012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002014 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2015#ifdef FEAT_TEXTOBJ
2016 (char_u *)&p_qe, PV_QE,
2017 {(char_u *)"\\", (char_u *)0L}
2018#else
2019 (char_u *)NULL, PV_NONE,
2020 {(char_u *)NULL, (char_u *)0L}
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2024 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"redraw", NULL, P_BOOL|P_VI_DEF,
2027 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002028 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002029 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2030#ifdef FEAT_RELTIME
2031 (char_u *)&p_rdt, PV_NONE,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002036 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2037 (char_u *)VAR_WIN, PV_RNU,
2038 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"remap", NULL, P_BOOL|P_VI_DEF,
2040 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"report", NULL, P_NUM|P_VI_DEF,
2043 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2046#ifdef WIN3264
2047 (char_u *)&p_rs, PV_NONE,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2053#ifdef FEAT_RIGHTLEFT
2054 (char_u *)&p_ri, PV_NONE,
2055#else
2056 (char_u *)NULL, PV_NONE,
2057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2060#ifdef FEAT_RIGHTLEFT
2061 (char_u *)VAR_WIN, PV_RL,
2062#else
2063 (char_u *)NULL, PV_NONE,
2064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002065 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2067#ifdef FEAT_RIGHTLEFT
2068 (char_u *)VAR_WIN, PV_RLC,
2069 {(char_u *)"search", (char_u *)NULL}
2070#else
2071 (char_u *)NULL, PV_NONE,
2072 {(char_u *)NULL, (char_u *)0L}
2073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2076#ifdef FEAT_CMDL_INFO
2077 (char_u *)&p_ru, PV_NONE,
2078#else
2079 (char_u *)NULL, PV_NONE,
2080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002081 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2083#ifdef FEAT_STL_OPT
2084 (char_u *)&p_ruf, PV_NONE,
2085#else
2086 (char_u *)NULL, PV_NONE,
2087#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2090 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2092 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2094 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2097#ifdef FEAT_SCROLLBIND
2098 (char_u *)VAR_WIN, PV_SCBIND,
2099#else
2100 (char_u *)NULL, PV_NONE,
2101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2104 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2107 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2110#ifdef FEAT_SCROLLBIND
2111 (char_u *)&p_sbo, PV_NONE,
2112 {(char_u *)"ver,jump", (char_u *)0L}
2113#else
2114 (char_u *)NULL, PV_NONE,
2115 {(char_u *)0L, (char_u *)0L}
2116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 {"sections", "sect", P_STRING|P_VI_DEF,
2119 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2121 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2123 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 {"selection", "sel", P_STRING|P_VI_DEF,
2126#ifdef FEAT_VISUAL
2127 (char_u *)&p_sel, PV_NONE,
2128#else
2129 (char_u *)NULL, PV_NONE,
2130#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002131 {(char_u *)"inclusive", (char_u *)0L}
2132 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2134#ifdef FEAT_VISUAL
2135 (char_u *)&p_slm, PV_NONE,
2136#else
2137 (char_u *)NULL, PV_NONE,
2138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002139 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2141#ifdef FEAT_SESSION
2142 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002143 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 (char_u *)0L}
2145#else
2146 (char_u *)NULL, PV_NONE,
2147 {(char_u *)0L, (char_u *)0L}
2148#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002149 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2151 (char_u *)&p_sh, PV_NONE,
2152 {
2153#ifdef VMS
2154 (char_u *)"-",
2155#else
2156# if defined(MSDOS)
2157 (char_u *)"command",
2158# else
2159# if defined(WIN16)
2160 (char_u *)"command.com",
2161# else
2162# if defined(WIN3264)
2163 (char_u *)"", /* set in set_init_1() */
2164# else
2165# if defined(OS2)
2166 (char_u *)"cmd.exe",
2167# else
2168# if defined(ARCHIE)
2169 (char_u *)"gos",
2170# else
2171 (char_u *)"sh",
2172# endif
2173# endif
2174# endif
2175# endif
2176# endif
2177#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2180 (char_u *)&p_shcf, PV_NONE,
2181 {
2182#if defined(MSDOS) || defined(MSWIN)
2183 (char_u *)"/c",
2184#else
2185# if defined(OS2)
2186 (char_u *)"/c",
2187# else
2188 (char_u *)"-c",
2189# endif
2190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002191 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2193#ifdef FEAT_QUICKFIX
2194 (char_u *)&p_sp, PV_NONE,
2195 {
2196#if defined(UNIX) || defined(OS2)
2197# ifdef ARCHIE
2198 (char_u *)"2>",
2199# else
2200 (char_u *)"| tee",
2201# endif
2202#else
2203 (char_u *)">",
2204#endif
2205 (char_u *)0L}
2206#else
2207 (char_u *)NULL, PV_NONE,
2208 {(char_u *)0L, (char_u *)0L}
2209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2212 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002213 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002214 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2215 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2218#ifdef BACKSLASH_IN_FILENAME
2219 (char_u *)&p_ssl, PV_NONE,
2220#else
2221 (char_u *)NULL, PV_NONE,
2222#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002223 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002224 {"shelltemp", "stmp", P_BOOL,
2225 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002226 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227 {"shelltype", "st", P_NUM|P_VI_DEF,
2228#ifdef AMIGA
2229 (char_u *)&p_st, PV_NONE,
2230#else
2231 (char_u *)NULL, PV_NONE,
2232#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2235 (char_u *)&p_sxq, PV_NONE,
2236 {
2237#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2238 (char_u *)"\"",
2239#else
2240 (char_u *)"",
2241#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2244 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002245 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2247 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002248 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002249 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2250 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 {(char_u *)"", (char_u *)"filnxtToO"}
2252 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253 {"shortname", "sn", P_BOOL|P_VI_DEF,
2254#ifdef SHORT_FNAME
2255 (char_u *)NULL, PV_NONE,
2256#else
2257 (char_u *)&p_sn, PV_SN,
2258#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002259 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2261#ifdef FEAT_LINEBREAK
2262 (char_u *)&p_sbr, PV_NONE,
2263#else
2264 (char_u *)NULL, PV_NONE,
2265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002266 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"showcmd", "sc", P_BOOL|P_VIM,
2268#ifdef FEAT_CMDL_INFO
2269 (char_u *)&p_sc, PV_NONE,
2270#else
2271 (char_u *)NULL, PV_NONE,
2272#endif
2273 {(char_u *)FALSE,
2274#ifdef UNIX
2275 (char_u *)FALSE
2276#else
2277 (char_u *)TRUE
2278#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2281 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2284 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"showmode", "smd", P_BOOL|P_VIM,
2287 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002289 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2290#ifdef FEAT_WINDOWS
2291 (char_u *)&p_stal, PV_NONE,
2292#else
2293 (char_u *)NULL, PV_NONE,
2294#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2297 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002298 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2300 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2303 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2306 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2309#ifdef FEAT_SMARTINDENT
2310 (char_u *)&p_si, PV_SI,
2311#else
2312 (char_u *)NULL, PV_NONE,
2313#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2316 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2319 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2322 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002324 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002325#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002326 (char_u *)VAR_WIN, PV_SPELL,
2327#else
2328 (char_u *)NULL, PV_NONE,
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002331 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002332#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002333 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002334 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002335#else
2336 (char_u *)NULL, PV_NONE,
2337 {(char_u *)0L, (char_u *)0L}
2338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002340 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002341#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002342 (char_u *)&p_spf, PV_SPF,
2343 {(char_u *)"", (char_u *)0L}
2344#else
2345 (char_u *)NULL, PV_NONE,
2346 {(char_u *)0L, (char_u *)0L}
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002349 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002350#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002351 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002352 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002353#else
2354 (char_u *)NULL, PV_NONE,
2355 {(char_u *)0L, (char_u *)0L}
2356#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002357 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002358 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002359#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002360 (char_u *)&p_sps, PV_NONE,
2361 {(char_u *)"best", (char_u *)0L}
2362#else
2363 (char_u *)NULL, PV_NONE,
2364 {(char_u *)0L, (char_u *)0L}
2365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2368#ifdef FEAT_WINDOWS
2369 (char_u *)&p_sb, PV_NONE,
2370#else
2371 (char_u *)NULL, PV_NONE,
2372#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"splitright", "spr", P_BOOL|P_VI_DEF,
2375#ifdef FEAT_VERTSPLIT
2376 (char_u *)&p_spr, PV_NONE,
2377#else
2378 (char_u *)NULL, PV_NONE,
2379#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2382 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002383 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2385#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002386 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387#else
2388 (char_u *)NULL, PV_NONE,
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2392 (char_u *)&p_su, PV_NONE,
2393 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002396#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 (char_u *)&p_sua, PV_SUA,
2398 {(char_u *)"", (char_u *)0L}
2399#else
2400 (char_u *)NULL, PV_NONE,
2401 {(char_u *)0L, (char_u *)0L}
2402#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2405 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"swapsync", "sws", P_STRING|P_VI_DEF,
2408 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2411 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002413 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2414#ifdef FEAT_SYN_HL
2415 (char_u *)&p_smc, PV_SMC,
2416 {(char_u *)3000L, (char_u *)0L}
2417#else
2418 (char_u *)NULL, PV_NONE,
2419 {(char_u *)0L, (char_u *)0L}
2420#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002422 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423#ifdef FEAT_SYN_HL
2424 (char_u *)&p_syn, PV_SYN,
2425 {(char_u *)"", (char_u *)0L}
2426#else
2427 (char_u *)NULL, PV_NONE,
2428 {(char_u *)0L, (char_u *)0L}
2429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002431 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2432#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002433 (char_u *)&p_tal, PV_NONE,
2434#else
2435 (char_u *)NULL, PV_NONE,
2436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002438 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2439#ifdef FEAT_WINDOWS
2440 (char_u *)&p_tpm, PV_NONE,
2441#else
2442 (char_u *)NULL, PV_NONE,
2443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2446 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2449 (char_u *)&p_tbs, PV_NONE,
2450#ifdef VMS /* binary searching doesn't appear to work on VMS */
2451 {(char_u *)0L, (char_u *)0L}
2452#else
2453 {(char_u *)TRUE, (char_u *)0L}
2454#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 {"taglength", "tl", P_NUM|P_VI_DEF,
2457 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"tagrelative", "tr", P_BOOL|P_VIM,
2460 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002463 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {
2465#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2466 (char_u *)"./tags,./TAGS,tags,TAGS",
2467#else
2468 (char_u *)"./tags,tags",
2469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2472 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2475 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2478#ifdef FEAT_ARABIC
2479 (char_u *)&p_tbidi, PV_NONE,
2480#else
2481 (char_u *)NULL, PV_NONE,
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2485#ifdef FEAT_MBYTE
2486 (char_u *)&p_tenc, PV_NONE,
2487 {(char_u *)"", (char_u *)0L}
2488#else
2489 (char_u *)NULL, PV_NONE,
2490 {(char_u *)0L, (char_u *)0L}
2491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 {"terse", NULL, P_BOOL|P_VI_DEF,
2494 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"textauto", "ta", P_BOOL|P_VIM,
2497 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2499 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2501 (char_u *)&p_tx, PV_TX,
2502 {
2503#ifdef USE_CRNL
2504 (char_u *)TRUE,
2505#else
2506 (char_u *)FALSE,
2507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM,
2510 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2513#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002514 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515#else
2516 (char_u *)NULL, PV_NONE,
2517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2520 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"timeout", "to", P_BOOL|P_VI_DEF,
2523 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002524 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2526 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"title", NULL, P_BOOL|P_VI_DEF,
2529#ifdef FEAT_TITLE
2530 (char_u *)&p_title, PV_NONE,
2531#else
2532 (char_u *)NULL, PV_NONE,
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"titlelen", NULL, P_NUM|P_VI_DEF,
2536#ifdef FEAT_TITLE
2537 (char_u *)&p_titlelen, PV_NONE,
2538#else
2539 (char_u *)NULL, PV_NONE,
2540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002542 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543#ifdef FEAT_TITLE
2544 (char_u *)&p_titleold, PV_NONE,
2545 {(char_u *)N_("Thanks for flying Vim"),
2546 (char_u *)0L}
2547#else
2548 (char_u *)NULL, PV_NONE,
2549 {(char_u *)0L, (char_u *)0L}
2550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 {"titlestring", NULL, P_STRING|P_VI_DEF,
2553#ifdef FEAT_TITLE
2554 (char_u *)&p_titlestring, PV_NONE,
2555#else
2556 (char_u *)NULL, PV_NONE,
2557#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2560 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2561 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)"icons,tooltips", (char_u *)0L}
2563 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564#endif
2565#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2566 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2567 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569#endif
2570 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2571 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2574 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2577 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2580 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2583#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2584 (char_u *)&p_ttym, PV_NONE,
2585#else
2586 (char_u *)NULL, PV_NONE,
2587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2590 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2593 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002595 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2596#ifdef FEAT_PERSISTENT_UNDO
2597 (char_u *)&p_udir, PV_NONE,
2598 {(char_u *)".", (char_u *)0L}
2599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
2603 SCRIPTID_INIT},
2604 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2605#ifdef FEAT_PERSISTENT_UNDO
2606 (char_u *)&p_udf, PV_UDF,
2607#else
2608 (char_u *)NULL, PV_NONE,
2609#endif
2610 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 {"undolevels", "ul", P_NUM|P_VI_DEF,
2612 (char_u *)&p_ul, PV_NONE,
2613 {
2614#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2615 (char_u *)1000L,
2616#else
2617 (char_u *)100L,
2618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"updatecount", "uc", P_NUM|P_VI_DEF,
2621 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"updatetime", "ut", P_NUM|P_VI_DEF,
2624 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"verbose", "vbs", P_NUM|P_VI_DEF,
2627 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002629 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2630 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2633#ifdef FEAT_SESSION
2634 (char_u *)&p_vdir, PV_NONE,
2635 {(char_u *)DFLT_VDIR, (char_u *)0L}
2636#else
2637 (char_u *)NULL, PV_NONE,
2638 {(char_u *)0L, (char_u *)0L}
2639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2642#ifdef FEAT_SESSION
2643 (char_u *)&p_vop, PV_NONE,
2644 {(char_u *)"folds,options,cursor", (char_u *)0L}
2645#else
2646 (char_u *)NULL, PV_NONE,
2647 {(char_u *)0L, (char_u *)0L}
2648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2651#ifdef FEAT_VIMINFO
2652 (char_u *)&p_viminfo, PV_NONE,
2653#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002654 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655#else
2656# ifdef AMIGA
2657 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002658 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002660 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661# endif
2662#endif
2663#else
2664 (char_u *)NULL, PV_NONE,
2665 {(char_u *)0L, (char_u *)0L}
2666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2669#ifdef FEAT_VIRTUALEDIT
2670 (char_u *)&p_ve, PV_NONE,
2671 {(char_u *)"", (char_u *)""}
2672#else
2673 (char_u *)NULL, PV_NONE,
2674 {(char_u *)0L, (char_u *)0L}
2675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2678 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002679 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002680 {"w300", NULL, P_NUM|P_VI_DEF,
2681 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 {"w1200", NULL, P_NUM|P_VI_DEF,
2684 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002685 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686 {"w9600", NULL, P_NUM|P_VI_DEF,
2687 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 {"warn", NULL, P_BOOL|P_VI_DEF,
2690 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2693 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2696 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698 {"wildchar", "wc", P_NUM|P_VIM,
2699 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002700 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2701 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
2703 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2706#ifdef FEAT_WILDIGN
2707 (char_u *)&p_wig, PV_NONE,
2708#else
2709 (char_u *)NULL, PV_NONE,
2710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2713#ifdef FEAT_WILDMENU
2714 (char_u *)&p_wmnu, PV_NONE,
2715#else
2716 (char_u *)NULL, PV_NONE,
2717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2720 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002722 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2723#ifdef FEAT_CMDL_COMPL
2724 (char_u *)&p_wop, PV_NONE,
2725 {(char_u *)"", (char_u *)0L}
2726#else
2727 (char_u *)NULL, PV_NONE,
2728 {(char_u *)NULL, (char_u *)0L}
2729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2732#ifdef FEAT_WAK
2733 (char_u *)&p_wak, PV_NONE,
2734 {(char_u *)"menu", (char_u *)0L}
2735#else
2736 (char_u *)NULL, PV_NONE,
2737 {(char_u *)NULL, (char_u *)0L}
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002741 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002742 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"winheight", "wh", P_NUM|P_VI_DEF,
2744#ifdef FEAT_WINDOWS
2745 (char_u *)&p_wh, PV_NONE,
2746#else
2747 (char_u *)NULL, PV_NONE,
2748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002751#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 (char_u *)VAR_WIN, PV_WFH,
2753#else
2754 (char_u *)NULL, PV_NONE,
2755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002757 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2758#ifdef FEAT_VERTSPLIT
2759 (char_u *)VAR_WIN, PV_WFW,
2760#else
2761 (char_u *)NULL, PV_NONE,
2762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2765#ifdef FEAT_WINDOWS
2766 (char_u *)&p_wmh, PV_NONE,
2767#else
2768 (char_u *)NULL, PV_NONE,
2769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2772#ifdef FEAT_VERTSPLIT
2773 (char_u *)&p_wmw, PV_NONE,
2774#else
2775 (char_u *)NULL, PV_NONE,
2776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2779#ifdef FEAT_VERTSPLIT
2780 (char_u *)&p_wiw, PV_NONE,
2781#else
2782 (char_u *)NULL, PV_NONE,
2783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2786 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002787 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2789 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002790 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2792 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"write", NULL, P_BOOL|P_VI_DEF,
2795 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 {"writeany", "wa", P_BOOL|P_VI_DEF,
2798 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2801 (char_u *)&p_wb, PV_NONE,
2802 {
2803#ifdef FEAT_WRITEBACKUP
2804 (char_u *)TRUE,
2805#else
2806 (char_u *)FALSE,
2807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"writedelay", "wd", P_NUM|P_VI_DEF,
2810 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812
2813/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002814#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817
2818 p_term("t_AB", T_CAB)
2819 p_term("t_AF", T_CAF)
2820 p_term("t_AL", T_CAL)
2821 p_term("t_al", T_AL)
2822 p_term("t_bc", T_BC)
2823 p_term("t_cd", T_CD)
2824 p_term("t_ce", T_CE)
2825 p_term("t_cl", T_CL)
2826 p_term("t_cm", T_CM)
2827 p_term("t_Co", T_CCO)
2828 p_term("t_CS", T_CCS)
2829 p_term("t_cs", T_CS)
2830#ifdef FEAT_VERTSPLIT
2831 p_term("t_CV", T_CSV)
2832#endif
2833 p_term("t_ut", T_UT)
2834 p_term("t_da", T_DA)
2835 p_term("t_db", T_DB)
2836 p_term("t_DL", T_CDL)
2837 p_term("t_dl", T_DL)
2838 p_term("t_fs", T_FS)
2839 p_term("t_IE", T_CIE)
2840 p_term("t_IS", T_CIS)
2841 p_term("t_ke", T_KE)
2842 p_term("t_ks", T_KS)
2843 p_term("t_le", T_LE)
2844 p_term("t_mb", T_MB)
2845 p_term("t_md", T_MD)
2846 p_term("t_me", T_ME)
2847 p_term("t_mr", T_MR)
2848 p_term("t_ms", T_MS)
2849 p_term("t_nd", T_ND)
2850 p_term("t_op", T_OP)
2851 p_term("t_RI", T_CRI)
2852 p_term("t_RV", T_CRV)
2853 p_term("t_Sb", T_CSB)
2854 p_term("t_Sf", T_CSF)
2855 p_term("t_se", T_SE)
2856 p_term("t_so", T_SO)
2857 p_term("t_sr", T_SR)
2858 p_term("t_ts", T_TS)
2859 p_term("t_te", T_TE)
2860 p_term("t_ti", T_TI)
2861 p_term("t_ue", T_UE)
2862 p_term("t_us", T_US)
2863 p_term("t_vb", T_VB)
2864 p_term("t_ve", T_VE)
2865 p_term("t_vi", T_VI)
2866 p_term("t_vs", T_VS)
2867 p_term("t_WP", T_CWP)
2868 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002869 p_term("t_SI", T_CSI)
2870 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 p_term("t_xs", T_XS)
2872 p_term("t_ZH", T_CZH)
2873 p_term("t_ZR", T_CZR)
2874
2875/* terminal key codes are not in here */
2876
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 /* end marker */
2878 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879};
2880
2881#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2882
2883#ifdef FEAT_MBYTE
2884static char *(p_ambw_values[]) = {"single", "double", NULL};
2885#endif
2886static char *(p_bg_values[]) = {"light", "dark", NULL};
2887static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2888static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002889#ifdef FEAT_CMDL_COMPL
2890static char *(p_wop_values[]) = {"tagfile", NULL};
2891#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892#ifdef FEAT_WAK
2893static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2894#endif
2895static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2896#ifdef FEAT_VISUAL
2897static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2898static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2899#endif
2900#ifdef FEAT_VISUAL
2901static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2902#endif
2903#ifdef FEAT_BROWSE
2904static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2905#endif
2906#ifdef FEAT_SCROLLBIND
2907static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2908#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002909static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910#ifdef FEAT_VERTSPLIT
2911static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2912#endif
2913#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002914# ifdef FEAT_AUTOCMD
2915static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2916# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002918# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2920#endif
2921static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2922#ifdef FEAT_FOLDING
2923static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002924# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002926# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927 NULL};
2928static char *(p_fcl_values[]) = {"all", NULL};
2929#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002930#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00002931static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933
2934static void set_option_default __ARGS((int, int opt_flags, int compatible));
2935static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00002936static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00002937static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938static char_u *illegal_char __ARGS((char_u *, int));
2939static int string_to_key __ARGS((char_u *arg));
2940#ifdef FEAT_CMDWIN
2941static char_u *check_cedit __ARGS((void));
2942#endif
2943#ifdef FEAT_TITLE
2944static void did_set_title __ARGS((int icon));
2945#endif
2946static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2947static void didset_options __ARGS((void));
2948static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00002949#if defined(FEAT_EVAL) || defined(PROTO)
2950static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
2951#else
2952# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
2953#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2955static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2956static 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));
2957static char_u *set_chars_option __ARGS((char_u **varp));
2958#ifdef FEAT_CLIPBOARD
2959static char_u *check_clipboard_option __ARGS((void));
2960#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002961#ifdef FEAT_SPELL
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002962static char_u *compile_cap_prog __ARGS((buf_T *buf));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002963#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002964#ifdef FEAT_EVAL
2965static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
2966#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00002968static 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 +00002969static void check_redraw __ARGS((long_u flags));
2970static int findoption __ARGS((char_u *));
2971static int find_key_option __ARGS((char_u *));
2972static void showoptions __ARGS((int all, int opt_flags));
2973static int optval_default __ARGS((struct vimoption *, char_u *varp));
2974static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2975static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2976static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2977static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2978static int istermoption __ARGS((struct vimoption *));
2979static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2980static char_u *get_varp __ARGS((struct vimoption *));
2981static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2982static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2983#ifdef FEAT_LANGMAP
2984static void langmap_init __ARGS((void));
2985static void langmap_set __ARGS((void));
2986#endif
2987static void paste_option_changed __ARGS((void));
2988static void compatible_set __ARGS((void));
2989#ifdef FEAT_LINEBREAK
2990static void fill_breakat_flags __ARGS((void));
2991#endif
2992static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2993static int check_opt_strings __ARGS((char_u *val, char **values, int));
2994static int check_opt_wim __ARGS((void));
2995
2996/*
2997 * Initialize the options, first part.
2998 *
2999 * Called only once from main(), just after creating the first buffer.
3000 */
3001 void
3002set_init_1()
3003{
3004 char_u *p;
3005 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003006 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007
3008#ifdef FEAT_LANGMAP
3009 langmap_init();
3010#endif
3011
3012 /* Be Vi compatible by default */
3013 p_cp = TRUE;
3014
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003015 /* Use POSIX compatibility when $VIM_POSIX is set. */
3016 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003017 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003018 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003019 set_string_default("shm", (char_u *)"A");
3020 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003021
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 /*
3023 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003024 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003026 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3028# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003029 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003031 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003033 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034# endif
3035#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003036 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 set_string_default("sh", p);
3038
3039#ifdef FEAT_WILDIGN
3040 /*
3041 * Set the default for 'backupskip' to include environment variables for
3042 * temp files.
3043 */
3044 {
3045# ifdef UNIX
3046 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3047# else
3048 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3049# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003050 int len;
3051 garray_T ga;
3052 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053
3054 ga_init2(&ga, 1, 100);
3055 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3056 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003057 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058# ifdef UNIX
3059 if (*names[n] == NUL)
3060 p = (char_u *)"/tmp";
3061 else
3062# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003063 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 if (p != NULL && *p != NUL)
3065 {
3066 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003067 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 if (ga_grow(&ga, len) == OK)
3069 {
3070 if (ga.ga_len > 0)
3071 STRCAT(ga.ga_data, ",");
3072 STRCAT(ga.ga_data, p);
3073 add_pathsep(ga.ga_data);
3074 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 ga.ga_len += len;
3076 }
3077 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003078 if (mustfree)
3079 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 }
3081 if (ga.ga_data != NULL)
3082 {
3083 set_string_default("bsk", ga.ga_data);
3084 vim_free(ga.ga_data);
3085 }
3086 }
3087#endif
3088
3089 /*
3090 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3091 */
3092 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003093 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003095#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3096 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3097#endif
3098 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003100 /* Use amount of memory available at this moment. */
3101 n = (mch_avail_mem(FALSE) >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102#else
3103# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003104 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003105 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003107 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108# endif
3109#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003111 opt_idx = findoption((char_u *)"maxmem");
3112 if (opt_idx >= 0)
3113 {
3114#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3115 if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
3116 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3117#endif
3118 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3119 }
3120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 }
3122
3123#ifdef FEAT_GUI_W32
3124 /* force 'shortname' for Win32s */
3125 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003126 {
3127 opt_idx = findoption((char_u *)"shortname");
3128 if (opt_idx >= 0)
3129 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131#endif
3132
3133#ifdef FEAT_SEARCHPATH
3134 {
3135 char_u *cdpath;
3136 char_u *buf;
3137 int i;
3138 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003139 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140
3141 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003142 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 if (cdpath != NULL)
3144 {
3145 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3146 if (buf != NULL)
3147 {
3148 buf[0] = ','; /* start with ",", current dir first */
3149 j = 1;
3150 for (i = 0; cdpath[i] != NUL; ++i)
3151 {
3152 if (vim_ispathlistsep(cdpath[i]))
3153 buf[j++] = ',';
3154 else
3155 {
3156 if (cdpath[i] == ' ' || cdpath[i] == ',')
3157 buf[j++] = '\\';
3158 buf[j++] = cdpath[i];
3159 }
3160 }
3161 buf[j] = NUL;
3162 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003163 if (opt_idx >= 0)
3164 {
3165 options[opt_idx].def_val[VI_DEFAULT] = buf;
3166 options[opt_idx].flags |= P_DEF_ALLOCED;
3167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003169 if (mustfree)
3170 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 }
3172 }
3173#endif
3174
3175#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3176 /* Set print encoding on platforms that don't default to latin1 */
3177 set_string_default("penc",
3178# if defined(MSWIN) || defined(OS2)
3179 (char_u *)"cp1252"
3180# else
3181# ifdef VMS
3182 (char_u *)"dec-mcs"
3183# else
3184# ifdef EBCDIC
3185 (char_u *)"ebcdic-uk"
3186# else
3187# ifdef MAC
3188 (char_u *)"mac-roman"
3189# else /* HPUX */
3190 (char_u *)"hp-roman8"
3191# endif
3192# endif
3193# endif
3194# endif
3195 );
3196#endif
3197
3198#ifdef FEAT_POSTSCRIPT
3199 /* 'printexpr' must be allocated to be able to evaluate it. */
3200 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003201# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3202 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203# else
3204# ifdef VMS
3205 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3206
3207# else
3208 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3209# endif
3210# endif
3211 );
3212#endif
3213
3214 /*
3215 * Set all the options (except the terminal options) to their default
3216 * value. Also set the global value for local options.
3217 */
3218 set_options_default(0);
3219
3220#ifdef FEAT_GUI
3221 if (found_reverse_arg)
3222 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3223#endif
3224
3225 curbuf->b_p_initialized = TRUE;
3226 curbuf->b_p_ar = -1; /* no local 'autoread' value */
3227 check_buf_options(curbuf);
3228 check_win_options(curwin);
3229 check_options();
3230
3231 /* Must be before option_expand(), because that one needs vim_isIDc() */
3232 didset_options();
3233
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003234#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003235 /* Use the current chartab for the generic chartab. */
3236 init_spell_chartab();
3237#endif
3238
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239#ifdef FEAT_LINEBREAK
3240 /*
3241 * initialize the table for 'breakat'.
3242 */
3243 fill_breakat_flags();
3244#endif
3245
3246 /*
3247 * Expand environment variables and things like "~" for the defaults.
3248 * If option_expand() returns non-NULL the variable is expanded. This can
3249 * only happen for non-indirect options.
3250 * Also set the default to the expanded value, so ":set" does not list
3251 * them.
3252 * Don't set the P_ALLOCED flag, because we don't want to free the
3253 * default.
3254 */
3255 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3256 {
3257 if ((options[opt_idx].flags & P_GETTEXT)
3258 && options[opt_idx].var != NULL)
3259 p = (char_u *)_(*(char **)options[opt_idx].var);
3260 else
3261 p = option_expand(opt_idx, NULL);
3262 if (p != NULL && (p = vim_strsave(p)) != NULL)
3263 {
3264 *(char_u **)options[opt_idx].var = p;
3265 /* VIMEXP
3266 * Defaults for all expanded options are currently the same for Vi
3267 * and Vim. When this changes, add some code here! Also need to
3268 * split P_DEF_ALLOCED in two.
3269 */
3270 if (options[opt_idx].flags & P_DEF_ALLOCED)
3271 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3272 options[opt_idx].def_val[VI_DEFAULT] = p;
3273 options[opt_idx].flags |= P_DEF_ALLOCED;
3274 }
3275 }
3276
3277 /* Initialize the highlight_attr[] table. */
3278 highlight_changed();
3279
3280 save_file_ff(curbuf); /* Buffer is unchanged */
3281
3282 /* Parse default for 'wildmode' */
3283 check_opt_wim();
3284
3285#if defined(FEAT_ARABIC)
3286 /* Detect use of mlterm.
3287 * Mlterm is a terminal emulator akin to xterm that has some special
3288 * abilities (bidi namely).
3289 * NOTE: mlterm's author is being asked to 'set' a variable
3290 * instead of an environment variable due to inheritance.
3291 */
3292 if (mch_getenv((char_u *)"MLTERM") != NULL)
3293 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3294#endif
3295
3296#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3297 /* Parse default for 'fillchars'. */
3298 (void)set_chars_option(&p_fcs);
3299#endif
3300
3301#ifdef FEAT_CLIPBOARD
3302 /* Parse default for 'clipboard' */
3303 (void)check_clipboard_option();
3304#endif
3305
3306#ifdef FEAT_MBYTE
3307# if defined(WIN3264) && defined(FEAT_GETTEXT)
3308 /*
3309 * If $LANG isn't set, try to get a good value for it. This makes the
3310 * right language be used automatically. Don't do this for English.
3311 */
3312 if (mch_getenv((char_u *)"LANG") == NULL)
3313 {
3314 char buf[20];
3315
3316 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3317 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3318 * only the first two. */
3319 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3320 (LPTSTR)buf, 20);
3321 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3322 {
3323 /* There are a few exceptions (probably more) */
3324 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3325 STRCPY(buf, "zh_TW");
3326 else if (STRNICMP(buf, "chs", 3) == 0
3327 || STRNICMP(buf, "zhc", 3) == 0)
3328 STRCPY(buf, "zh_CN");
3329 else if (STRNICMP(buf, "jp", 2) == 0)
3330 STRCPY(buf, "ja");
3331 else
3332 buf[2] = NUL; /* truncate to two-letter code */
3333 vim_setenv("LANG", buf);
3334 }
3335 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003336# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003337# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003338 /* Moved to os_mac_conv.c to avoid dependency problems. */
3339 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003340# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341# endif
3342
3343 /* enc_locale() will try to find the encoding of the current locale. */
3344 p = enc_locale();
3345 if (p != NULL)
3346 {
3347 char_u *save_enc;
3348
3349 /* Try setting 'encoding' and check if the value is valid.
3350 * If not, go back to the default "latin1". */
3351 save_enc = p_enc;
3352 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003353 if (STRCMP(p_enc, "gb18030") == 0)
3354 {
3355 /* We don't support "gb18030", but "cp936" is a good substitute
3356 * for practical purposes, thus use that. It's not an alias to
3357 * still support conversion between gb18030 and utf-8. */
3358 p_enc = vim_strsave((char_u *)"cp936");
3359 vim_free(p);
3360 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361 if (mb_init() == NULL)
3362 {
3363 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003364 if (opt_idx >= 0)
3365 {
3366 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3367 options[opt_idx].flags |= P_DEF_ALLOCED;
3368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003370#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3371 || defined(VMS)
3372 if (STRCMP(p_enc, "latin1") == 0
3373# ifdef FEAT_MBYTE
3374 || enc_utf8
3375# endif
3376 )
3377 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003378 /* Adjust the default for 'isprint' and 'iskeyword' to match
3379 * latin1. Also set the defaults for when 'nocompatible' is
3380 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003381 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003382 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003383 set_string_option_direct((char_u *)"isk", -1,
3384 ISK_LATIN1, OPT_FREE, SID_NONE);
3385 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003386 if (opt_idx >= 0)
3387 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003388 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003389 if (opt_idx >= 0)
3390 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003391 (void)init_chartab();
3392 }
3393#endif
3394
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395# if defined(WIN3264) && !defined(FEAT_GUI)
3396 /* Win32 console: When GetACP() returns a different value from
3397 * GetConsoleCP() set 'termencoding'. */
3398 if (GetACP() != GetConsoleCP())
3399 {
3400 char buf[50];
3401
3402 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3403 p_tenc = vim_strsave((char_u *)buf);
3404 if (p_tenc != NULL)
3405 {
3406 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003407 if (opt_idx >= 0)
3408 {
3409 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3410 options[opt_idx].flags |= P_DEF_ALLOCED;
3411 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412 convert_setup(&input_conv, p_tenc, p_enc);
3413 convert_setup(&output_conv, p_enc, p_tenc);
3414 }
3415 else
3416 p_tenc = empty_option;
3417 }
3418# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003419# if defined(WIN3264) && defined(FEAT_MBYTE)
3420 /* $HOME may have characters in active code page. */
3421 init_homedir();
3422# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423 }
3424 else
3425 {
3426 vim_free(p_enc);
3427 p_enc = save_enc;
3428 }
3429 }
3430#endif
3431
3432#ifdef FEAT_MULTI_LANG
3433 /* Set the default for 'helplang'. */
3434 set_helplang_default(get_mess_lang());
3435#endif
3436}
3437
3438/*
3439 * Set an option to its default value.
3440 * This does not take care of side effects!
3441 */
3442 static void
3443set_option_default(opt_idx, opt_flags, compatible)
3444 int opt_idx;
3445 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3446 int compatible; /* use Vi default value */
3447{
3448 char_u *varp; /* pointer to variable for current option */
3449 int dvi; /* index in def_val[] */
3450 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003451 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3453
3454 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3455 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003456 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457 {
3458 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3459 if (flags & P_STRING)
3460 {
3461 /* Use set_string_option_direct() for local options to handle
3462 * freeing and allocating the value. */
3463 if (options[opt_idx].indir != PV_NONE)
3464 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003465 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 else
3467 {
3468 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3469 free_string_option(*(char_u **)(varp));
3470 *(char_u **)varp = options[opt_idx].def_val[dvi];
3471 options[opt_idx].flags &= ~P_ALLOCED;
3472 }
3473 }
3474 else if (flags & P_NUM)
3475 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003476 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477 win_comp_scroll(curwin);
3478 else
3479 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003480 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481 /* May also set global value for local option. */
3482 if (both)
3483 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3484 *(long *)varp;
3485 }
3486 }
3487 else /* P_BOOL */
3488 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003489 /* the cast to long is required for Manx C, long_i is needed for
3490 * MSVC */
3491 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003492#ifdef UNIX
3493 /* 'modeline' defaults to off for root */
3494 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3495 *(int *)varp = FALSE;
3496#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 /* May also set global value for local option. */
3498 if (both)
3499 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3500 *(int *)varp;
3501 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003502
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003503 /* The default value is not insecure. */
3504 flagsp = insecure_flag(opt_idx, opt_flags);
3505 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506 }
3507
3508#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003509 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510#endif
3511}
3512
3513/*
3514 * Set all options (except terminal options) to their default value.
3515 */
3516 static void
3517set_options_default(opt_flags)
3518 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3519{
3520 int i;
3521#ifdef FEAT_WINDOWS
3522 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003523 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524#endif
3525
3526 for (i = 0; !istermoption(&options[i]); i++)
3527 if (!(options[i].flags & P_NODEFAULT))
3528 set_option_default(i, opt_flags, p_cp);
3529
3530#ifdef FEAT_WINDOWS
3531 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003532 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533 win_comp_scroll(wp);
3534#else
3535 win_comp_scroll(curwin);
3536#endif
3537}
3538
3539/*
3540 * Set the Vi-default value of a string option.
3541 * Used for 'sh', 'backupskip' and 'term'.
3542 */
3543 void
3544set_string_default(name, val)
3545 char *name;
3546 char_u *val;
3547{
3548 char_u *p;
3549 int opt_idx;
3550
3551 p = vim_strsave(val);
3552 if (p != NULL) /* we don't want a NULL */
3553 {
3554 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003555 if (opt_idx >= 0)
3556 {
3557 if (options[opt_idx].flags & P_DEF_ALLOCED)
3558 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3559 options[opt_idx].def_val[VI_DEFAULT] = p;
3560 options[opt_idx].flags |= P_DEF_ALLOCED;
3561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003562 }
3563}
3564
3565/*
3566 * Set the Vi-default value of a number option.
3567 * Used for 'lines' and 'columns'.
3568 */
3569 void
3570set_number_default(name, val)
3571 char *name;
3572 long val;
3573{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003574 int opt_idx;
3575
3576 opt_idx = findoption((char_u *)name);
3577 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003578 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003579}
3580
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003581#if defined(EXITFREE) || defined(PROTO)
3582/*
3583 * Free all options.
3584 */
3585 void
3586free_all_options()
3587{
3588 int i;
3589
3590 for (i = 0; !istermoption(&options[i]); i++)
3591 {
3592 if (options[i].indir == PV_NONE)
3593 {
3594 /* global option: free value and default value. */
3595 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3596 free_string_option(*(char_u **)options[i].var);
3597 if (options[i].flags & P_DEF_ALLOCED)
3598 free_string_option(options[i].def_val[VI_DEFAULT]);
3599 }
3600 else if (options[i].var != VAR_WIN
3601 && (options[i].flags & P_STRING))
3602 /* buffer-local option: free global value */
3603 free_string_option(*(char_u **)options[i].var);
3604 }
3605}
3606#endif
3607
3608
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609/*
3610 * Initialize the options, part two: After getting Rows and Columns and
3611 * setting 'term'.
3612 */
3613 void
3614set_init_2()
3615{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003616 int idx;
3617
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 /*
3619 * 'scroll' defaults to half the window height. Note that this default is
3620 * wrong when the window height changes.
3621 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003622 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003623 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003624 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003625 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 comp_col();
3627
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003628 /*
3629 * 'window' is only for backwards compatibility with Vi.
3630 * Default is Rows - 1.
3631 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003632 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003633 p_window = Rows - 1;
3634 set_number_default("window", Rows - 1);
3635
Bram Moolenaarf740b292006-02-16 22:11:02 +00003636 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003637#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003638 /*
3639 * If 'background' wasn't set by the user, try guessing the value,
3640 * depending on the terminal name. Only need to check for terminals
3641 * with a dark background, that can handle color.
3642 */
3643 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003644 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3645 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003647 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003648 /* don't mark it as set, when starting the GUI it may be
3649 * changed again */
3650 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651 }
3652#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003653
3654#ifdef CURSOR_SHAPE
3655 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3656#endif
3657#ifdef FEAT_MOUSESHAPE
3658 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3659#endif
3660#ifdef FEAT_PRINTER
3661 (void)parse_printoptions(); /* parse 'printoptions' default value */
3662#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003663}
3664
3665/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003666 * Return "dark" or "light" depending on the kind of terminal.
3667 * This is just guessing! Recognized are:
3668 * "linux" Linux console
3669 * "screen.linux" Linux console with screen
3670 * "cygwin" Cygwin shell
3671 * "putty" Putty program
3672 * We also check the COLORFGBG environment variable, which is set by
3673 * rxvt and derivatives. This variable contains either two or three
3674 * values separated by semicolons; we want the last value in either
3675 * case. If this value is 0-6 or 8, our background is dark.
3676 */
3677 static char_u *
3678term_bg_default()
3679{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003680#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3681 /* DOS console nearly always black */
3682 return (char_u *)"dark";
3683#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003684 char_u *p;
3685
Bram Moolenaarf740b292006-02-16 22:11:02 +00003686 if (STRCMP(T_NAME, "linux") == 0
3687 || STRCMP(T_NAME, "screen.linux") == 0
3688 || STRCMP(T_NAME, "cygwin") == 0
3689 || STRCMP(T_NAME, "putty") == 0
3690 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3691 && (p = vim_strrchr(p, ';')) != NULL
3692 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3693 && p[2] == NUL))
3694 return (char_u *)"dark";
3695 return (char_u *)"light";
3696#endif
3697}
3698
3699/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 * Initialize the options, part three: After reading the .vimrc
3701 */
3702 void
3703set_init_3()
3704{
3705#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3706/*
3707 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3708 * This is done after other initializations, where 'shell' might have been
3709 * set, but only if they have not been set before.
3710 */
3711 char_u *p;
3712 int idx_srr;
3713 int do_srr;
3714#ifdef FEAT_QUICKFIX
3715 int idx_sp;
3716 int do_sp;
3717#endif
3718
3719 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003720 if (idx_srr < 0)
3721 do_srr = FALSE;
3722 else
3723 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724#ifdef FEAT_QUICKFIX
3725 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003726 if (idx_sp < 0)
3727 do_sp = FALSE;
3728 else
3729 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003730#endif
3731
3732 /*
3733 * Isolate the name of the shell:
3734 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3735 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003736 * But don't allow a space in the path, so that this works:
3737 * "/usr/bin/csh --rcfile ~/.cshrc"
3738 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003740#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741 p = gettail(p_sh);
3742 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003743#else
3744 p = skiptowhite(p_sh);
3745 if (*p == NUL)
3746 {
3747 /* No white space, use the tail. */
3748 p = vim_strsave(gettail(p_sh));
3749 }
3750 else
3751 {
3752 char_u *p1, *p2;
3753
3754 /* Find the last path separator before the space. */
3755 p1 = p_sh;
3756 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3757 if (vim_ispathsep(*p2))
3758 p1 = p2 + 1;
3759 p = vim_strnsave(p1, (int)(p - p1));
3760 }
3761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 if (p != NULL)
3763 {
3764 /*
3765 * Default for p_sp is "| tee", for p_srr is ">".
3766 * For known shells it is changed here to include stderr.
3767 */
3768 if ( fnamecmp(p, "csh") == 0
3769 || fnamecmp(p, "tcsh") == 0
3770# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3771 || fnamecmp(p, "csh.exe") == 0
3772 || fnamecmp(p, "tcsh.exe") == 0
3773# endif
3774 )
3775 {
3776#if defined(FEAT_QUICKFIX)
3777 if (do_sp)
3778 {
3779# ifdef WIN3264
3780 p_sp = (char_u *)">&";
3781# else
3782 p_sp = (char_u *)"|& tee";
3783# endif
3784 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3785 }
3786#endif
3787 if (do_srr)
3788 {
3789 p_srr = (char_u *)">&";
3790 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3791 }
3792 }
3793 else
3794# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3795 if ( fnamecmp(p, "sh") == 0
3796 || fnamecmp(p, "ksh") == 0
3797 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003798 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 || fnamecmp(p, "bash") == 0
3800# ifdef WIN3264
3801 || fnamecmp(p, "cmd") == 0
3802 || fnamecmp(p, "sh.exe") == 0
3803 || fnamecmp(p, "ksh.exe") == 0
3804 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003805 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806 || fnamecmp(p, "bash.exe") == 0
3807 || fnamecmp(p, "cmd.exe") == 0
3808# endif
3809 )
3810# endif
3811 {
3812#if defined(FEAT_QUICKFIX)
3813 if (do_sp)
3814 {
3815# ifdef WIN3264
3816 p_sp = (char_u *)">%s 2>&1";
3817# else
3818 p_sp = (char_u *)"2>&1| tee";
3819# endif
3820 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3821 }
3822#endif
3823 if (do_srr)
3824 {
3825 p_srr = (char_u *)">%s 2>&1";
3826 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3827 }
3828 }
3829 vim_free(p);
3830 }
3831#endif
3832
3833#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3834 /*
3835 * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3836 * This is done after other initializations, where 'shell' might have been
3837 * set, but only if they have not been set before. Default for p_shcf is
3838 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3839 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3840 * command.com. And for Win32 we need to set p_sxq instead.
3841 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003842 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 {
3844 int idx3;
3845
3846 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003847 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 {
3849 p_shcf = (char_u *)"-c";
3850 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3851 }
3852
3853# ifndef DJGPP
3854# ifdef WIN3264
3855 /* Somehow Win32 requires the quotes around the redirection too */
3856 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003857 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 {
3859 p_sxq = (char_u *)"\"";
3860 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3861 }
3862# else
3863 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003864 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865 {
3866 p_shq = (char_u *)"\"";
3867 options[idx3].def_val[VI_DEFAULT] = p_shq;
3868 }
3869# endif
3870# endif
3871 }
3872#endif
3873
3874#ifdef FEAT_TITLE
3875 set_title_defaults();
3876#endif
3877}
3878
3879#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3880/*
3881 * When 'helplang' is still at its default value, set it to "lang".
3882 * Only the first two characters of "lang" are used.
3883 */
3884 void
3885set_helplang_default(lang)
3886 char_u *lang;
3887{
3888 int idx;
3889
3890 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3891 return;
3892 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003893 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 {
3895 if (options[idx].flags & P_ALLOCED)
3896 free_string_option(p_hlg);
3897 p_hlg = vim_strsave(lang);
3898 if (p_hlg == NULL)
3899 p_hlg = empty_option;
3900 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003901 {
3902 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3903 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3904 {
3905 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3906 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3907 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003909 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 options[idx].flags |= P_ALLOCED;
3911 }
3912}
3913#endif
3914
3915#ifdef FEAT_GUI
3916static char_u *gui_bg_default __ARGS((void));
3917
3918 static char_u *
3919gui_bg_default()
3920{
3921 if (gui_get_lightness(gui.back_pixel) < 127)
3922 return (char_u *)"dark";
3923 return (char_u *)"light";
3924}
3925
3926/*
3927 * Option initializations that can only be done after opening the GUI window.
3928 */
3929 void
3930init_gui_options()
3931{
3932 /* Set the 'background' option according to the lightness of the
3933 * background color, unless the user has set it already. */
3934 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3935 {
3936 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3937 highlight_changed();
3938 }
3939}
3940#endif
3941
3942#ifdef FEAT_TITLE
3943/*
3944 * 'title' and 'icon' only default to true if they have not been set or reset
3945 * in .vimrc and we can read the old value.
3946 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3947 * they can be reset. This reduces startup time when using X on a remote
3948 * machine.
3949 */
3950 void
3951set_title_defaults()
3952{
3953 int idx1;
3954 long val;
3955
3956 /*
3957 * If GUI is (going to be) used, we can always set the window title and
3958 * icon name. Saves a bit of time, because the X11 display server does
3959 * not need to be contacted.
3960 */
3961 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003962 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 {
3964#ifdef FEAT_GUI
3965 if (gui.starting || gui.in_use)
3966 val = TRUE;
3967 else
3968#endif
3969 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003970 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 p_title = val;
3972 }
3973 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003974 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 {
3976#ifdef FEAT_GUI
3977 if (gui.starting || gui.in_use)
3978 val = TRUE;
3979 else
3980#endif
3981 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003982 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983 p_icon = val;
3984 }
3985}
3986#endif
3987
3988/*
3989 * Parse 'arg' for option settings.
3990 *
3991 * 'arg' may be IObuff, but only when no errors can be present and option
3992 * does not need to be expanded with option_expand().
3993 * "opt_flags":
3994 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00003995 * OPT_GLOBAL for ":setglobal"
3996 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00003998 * OPT_WINONLY to only set window-local options
3999 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 *
4001 * returns FAIL if an error is detected, OK otherwise
4002 */
4003 int
4004do_set(arg, opt_flags)
4005 char_u *arg; /* option string (may be written to!) */
4006 int opt_flags;
4007{
4008 int opt_idx;
4009 char_u *errmsg;
4010 char_u errbuf[80];
4011 char_u *startarg;
4012 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4013 int nextchar; /* next non-white char after option name */
4014 int afterchar; /* character just after option name */
4015 int len;
4016 int i;
4017 long value;
4018 int key;
4019 long_u flags; /* flags for current option */
4020 char_u *varp = NULL; /* pointer to variable for current option */
4021 int did_show = FALSE; /* already showed one value */
4022 int adding; /* "opt+=arg" */
4023 int prepending; /* "opt^=arg" */
4024 int removing; /* "opt-=arg" */
4025 int cp_val = 0;
4026 char_u key_name[2];
4027
4028 if (*arg == NUL)
4029 {
4030 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004031 did_show = TRUE;
4032 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033 }
4034
4035 while (*arg != NUL) /* loop to process all options */
4036 {
4037 errmsg = NULL;
4038 startarg = arg; /* remember for error message */
4039
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004040 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4041 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042 {
4043 /*
4044 * ":set all" show all options.
4045 * ":set all&" set all options to their default value.
4046 */
4047 arg += 3;
4048 if (*arg == '&')
4049 {
4050 ++arg;
4051 /* Only for :set command set global value of local options. */
4052 set_options_default(OPT_FREE | opt_flags);
4053 }
4054 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004055 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004057 did_show = TRUE;
4058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004060 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 {
4062 showoptions(2, opt_flags);
4063 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004064 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 arg += 7;
4066 }
4067 else
4068 {
4069 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004070 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 {
4072 prefix = 0;
4073 arg += 2;
4074 }
4075 else if (STRNCMP(arg, "inv", 3) == 0)
4076 {
4077 prefix = 2;
4078 arg += 3;
4079 }
4080
4081 /* find end of name */
4082 key = 0;
4083 if (*arg == '<')
4084 {
4085 nextchar = 0;
4086 opt_idx = -1;
4087 /* look out for <t_>;> */
4088 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4089 len = 5;
4090 else
4091 {
4092 len = 1;
4093 while (arg[len] != NUL && arg[len] != '>')
4094 ++len;
4095 }
4096 if (arg[len] != '>')
4097 {
4098 errmsg = e_invarg;
4099 goto skip;
4100 }
4101 arg[len] = NUL; /* put NUL after name */
4102 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4103 opt_idx = findoption(arg + 1);
4104 arg[len++] = '>'; /* restore '>' */
4105 if (opt_idx == -1)
4106 key = find_key_option(arg + 1);
4107 }
4108 else
4109 {
4110 len = 0;
4111 /*
4112 * The two characters after "t_" may not be alphanumeric.
4113 */
4114 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4115 len = 4;
4116 else
4117 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4118 ++len;
4119 nextchar = arg[len];
4120 arg[len] = NUL; /* put NUL after name */
4121 opt_idx = findoption(arg);
4122 arg[len] = nextchar; /* restore nextchar */
4123 if (opt_idx == -1)
4124 key = find_key_option(arg);
4125 }
4126
4127 /* remember character after option name */
4128 afterchar = arg[len];
4129
4130 /* skip white space, allow ":set ai ?" */
4131 while (vim_iswhite(arg[len]))
4132 ++len;
4133
4134 adding = FALSE;
4135 prepending = FALSE;
4136 removing = FALSE;
4137 if (arg[len] != NUL && arg[len + 1] == '=')
4138 {
4139 if (arg[len] == '+')
4140 {
4141 adding = TRUE; /* "+=" */
4142 ++len;
4143 }
4144 else if (arg[len] == '^')
4145 {
4146 prepending = TRUE; /* "^=" */
4147 ++len;
4148 }
4149 else if (arg[len] == '-')
4150 {
4151 removing = TRUE; /* "-=" */
4152 ++len;
4153 }
4154 }
4155 nextchar = arg[len];
4156
4157 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4158 {
4159 errmsg = (char_u *)N_("E518: Unknown option");
4160 goto skip;
4161 }
4162
4163 if (opt_idx >= 0)
4164 {
4165 if (options[opt_idx].var == NULL) /* hidden option: skip */
4166 {
4167 /* Only give an error message when requesting the value of
4168 * a hidden option, ignore setting it. */
4169 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4170 && (!(options[opt_idx].flags & P_BOOL)
4171 || nextchar == '?'))
4172 errmsg = (char_u *)N_("E519: Option not supported");
4173 goto skip;
4174 }
4175
4176 flags = options[opt_idx].flags;
4177 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4178 }
4179 else
4180 {
4181 flags = P_STRING;
4182 if (key < 0)
4183 {
4184 key_name[0] = KEY2TERMCAP0(key);
4185 key_name[1] = KEY2TERMCAP1(key);
4186 }
4187 else
4188 {
4189 key_name[0] = KS_KEY;
4190 key_name[1] = (key & 0xff);
4191 }
4192 }
4193
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004194 /* Skip all options that are not window-local (used when showing
4195 * an already loaded buffer in a window). */
4196 if ((opt_flags & OPT_WINONLY)
4197 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4198 goto skip;
4199
Bram Moolenaara3227e22006-03-08 21:32:40 +00004200 /* Skip all options that are window-local (used for :vimgrep). */
4201 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4202 && options[opt_idx].var == VAR_WIN)
4203 goto skip;
4204
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004205 /* Disallow changing some options from modelines. */
4206 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 {
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004208 if (flags & P_SECURE)
4209 {
4210 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4211 goto skip;
4212 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004213#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004214 /* In diff mode some options are overruled. This avoids that
4215 * 'foldmethod' becomes "marker" instead of "diff" and that
4216 * "wrap" gets set. */
4217 if (curwin->w_p_diff
4218 && (options[opt_idx].indir == PV_FDM
4219 || options[opt_idx].indir == PV_WRAP))
4220 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 }
4223
4224#ifdef HAVE_SANDBOX
4225 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004226 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 {
4228 errmsg = (char_u *)_(e_sandbox);
4229 goto skip;
4230 }
4231#endif
4232
4233 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4234 {
4235 arg += len;
4236 cp_val = p_cp;
4237 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4238 {
4239 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4240 {
4241 cp_val = FALSE;
4242 arg += 3;
4243 }
4244 else /* "opt&vi": set to Vi default */
4245 {
4246 cp_val = TRUE;
4247 arg += 2;
4248 }
4249 }
4250 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4251 && arg[1] != NUL && !vim_iswhite(arg[1]))
4252 {
4253 errmsg = e_trailing;
4254 goto skip;
4255 }
4256 }
4257
4258 /*
4259 * allow '=' and ':' as MSDOS command.com allows only one
4260 * '=' character per "set" command line. grrr. (jw)
4261 */
4262 if (nextchar == '?'
4263 || (prefix == 1
4264 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4265 && !(flags & P_BOOL)))
4266 {
4267 /*
4268 * print value
4269 */
4270 if (did_show)
4271 msg_putchar('\n'); /* cursor below last one */
4272 else
4273 {
4274 gotocmdline(TRUE); /* cursor at status line */
4275 did_show = TRUE; /* remember that we did a line */
4276 }
4277 if (opt_idx >= 0)
4278 {
4279 showoneopt(&options[opt_idx], opt_flags);
4280#ifdef FEAT_EVAL
4281 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004282 {
4283 /* Mention where the option was last set. */
4284 if (varp == options[opt_idx].var)
4285 last_set_msg(options[opt_idx].scriptID);
4286 else if ((int)options[opt_idx].indir & PV_WIN)
4287 last_set_msg(curwin->w_p_scriptID[
4288 (int)options[opt_idx].indir & PV_MASK]);
4289 else if ((int)options[opt_idx].indir & PV_BUF)
4290 last_set_msg(curbuf->b_p_scriptID[
4291 (int)options[opt_idx].indir & PV_MASK]);
4292 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004293#endif
4294 }
4295 else
4296 {
4297 char_u *p;
4298
4299 p = find_termcode(key_name);
4300 if (p == NULL)
4301 {
4302 errmsg = (char_u *)N_("E518: Unknown option");
4303 goto skip;
4304 }
4305 else
4306 (void)show_one_termcode(key_name, p, TRUE);
4307 }
4308 if (nextchar != '?'
4309 && nextchar != NUL && !vim_iswhite(afterchar))
4310 errmsg = e_trailing;
4311 }
4312 else
4313 {
4314 if (flags & P_BOOL) /* boolean */
4315 {
4316 if (nextchar == '=' || nextchar == ':')
4317 {
4318 errmsg = e_invarg;
4319 goto skip;
4320 }
4321
4322 /*
4323 * ":set opt!": invert
4324 * ":set opt&": reset to default value
4325 * ":set opt<": reset to global value
4326 */
4327 if (nextchar == '!')
4328 value = *(int *)(varp) ^ 1;
4329 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004330 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004331 ((flags & P_VI_DEF) || cp_val)
4332 ? VI_DEFAULT : VIM_DEFAULT];
4333 else if (nextchar == '<')
4334 {
4335 /* For 'autoread' -1 means to use global value. */
4336 if ((int *)varp == &curbuf->b_p_ar
4337 && opt_flags == OPT_LOCAL)
4338 value = -1;
4339 else
4340 value = *(int *)get_varp_scope(&(options[opt_idx]),
4341 OPT_GLOBAL);
4342 }
4343 else
4344 {
4345 /*
4346 * ":set invopt": invert
4347 * ":set opt" or ":set noopt": set or reset
4348 */
4349 if (nextchar != NUL && !vim_iswhite(afterchar))
4350 {
4351 errmsg = e_trailing;
4352 goto skip;
4353 }
4354 if (prefix == 2) /* inv */
4355 value = *(int *)(varp) ^ 1;
4356 else
4357 value = prefix;
4358 }
4359
4360 errmsg = set_bool_option(opt_idx, varp, (int)value,
4361 opt_flags);
4362 }
4363 else /* numeric or string */
4364 {
4365 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4366 || prefix != 1)
4367 {
4368 errmsg = e_invarg;
4369 goto skip;
4370 }
4371
4372 if (flags & P_NUM) /* numeric */
4373 {
4374 /*
4375 * Different ways to set a number option:
4376 * & set to default value
4377 * < set to global value
4378 * <xx> accept special key codes for 'wildchar'
4379 * c accept any non-digit for 'wildchar'
4380 * [-]0-9 set number
4381 * other error
4382 */
4383 ++arg;
4384 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004385 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004386 ((flags & P_VI_DEF) || cp_val)
4387 ? VI_DEFAULT : VIM_DEFAULT];
4388 else if (nextchar == '<')
4389 value = *(long *)get_varp_scope(&(options[opt_idx]),
4390 OPT_GLOBAL);
4391 else if (((long *)varp == &p_wc
4392 || (long *)varp == &p_wcm)
4393 && (*arg == '<'
4394 || *arg == '^'
4395 || ((!arg[1] || vim_iswhite(arg[1]))
4396 && !VIM_ISDIGIT(*arg))))
4397 {
4398 value = string_to_key(arg);
4399 if (value == 0 && (long *)varp != &p_wcm)
4400 {
4401 errmsg = e_invarg;
4402 goto skip;
4403 }
4404 }
4405 /* allow negative numbers (for 'undolevels') */
4406 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4407 {
4408 i = 0;
4409 if (*arg == '-')
4410 i = 1;
4411#ifdef HAVE_STRTOL
4412 value = strtol((char *)arg, NULL, 0);
4413 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4414 i += 2;
4415#else
4416 value = atol((char *)arg);
4417#endif
4418 while (VIM_ISDIGIT(arg[i]))
4419 ++i;
4420 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4421 {
4422 errmsg = e_invarg;
4423 goto skip;
4424 }
4425 }
4426 else
4427 {
4428 errmsg = (char_u *)N_("E521: Number required after =");
4429 goto skip;
4430 }
4431
4432 if (adding)
4433 value = *(long *)varp + value;
4434 if (prepending)
4435 value = *(long *)varp * value;
4436 if (removing)
4437 value = *(long *)varp - value;
4438 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004439 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004440 }
4441 else if (opt_idx >= 0) /* string */
4442 {
4443 char_u *save_arg = NULL;
4444 char_u *s = NULL;
4445 char_u *oldval; /* previous value if *varp */
4446 char_u *newval;
4447 char_u *origval;
4448 unsigned newlen;
4449 int comma;
4450 int bs;
4451 int new_value_alloced; /* new string option
4452 was allocated */
4453
4454 /* When using ":set opt=val" for a global option
4455 * with a local value the local value will be
4456 * reset, use the global value here. */
4457 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004458 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004459 varp = options[opt_idx].var;
4460
4461 /* The old value is kept until we are sure that the
4462 * new value is valid. */
4463 oldval = *(char_u **)varp;
4464 if (nextchar == '&') /* set to default val */
4465 {
4466 newval = options[opt_idx].def_val[
4467 ((flags & P_VI_DEF) || cp_val)
4468 ? VI_DEFAULT : VIM_DEFAULT];
4469 if ((char_u **)varp == &p_bg)
4470 {
4471 /* guess the value of 'background' */
4472#ifdef FEAT_GUI
4473 if (gui.in_use)
4474 newval = gui_bg_default();
4475 else
4476#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004477 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004478 }
4479
4480 /* expand environment variables and ~ (since the
4481 * default value was already expanded, only
4482 * required when an environment variable was set
4483 * later */
4484 if (newval == NULL)
4485 newval = empty_option;
4486 else
4487 {
4488 s = option_expand(opt_idx, newval);
4489 if (s == NULL)
4490 s = newval;
4491 newval = vim_strsave(s);
4492 }
4493 new_value_alloced = TRUE;
4494 }
4495 else if (nextchar == '<') /* set to global val */
4496 {
4497 newval = vim_strsave(*(char_u **)get_varp_scope(
4498 &(options[opt_idx]), OPT_GLOBAL));
4499 new_value_alloced = TRUE;
4500 }
4501 else
4502 {
4503 ++arg; /* jump to after the '=' or ':' */
4504
4505 /*
4506 * Set 'keywordprg' to ":help" if an empty
4507 * value was passed to :set by the user.
4508 * Misuse errbuf[] for the resulting string.
4509 */
4510 if (varp == (char_u *)&p_kp
4511 && (*arg == NUL || *arg == ' '))
4512 {
4513 STRCPY(errbuf, ":help");
4514 save_arg = arg;
4515 arg = errbuf;
4516 }
4517 /*
4518 * Convert 'whichwrap' number to string, for
4519 * backwards compatibility with Vim 3.0.
4520 * Misuse errbuf[] for the resulting string.
4521 */
4522 else if (varp == (char_u *)&p_ww
4523 && VIM_ISDIGIT(*arg))
4524 {
4525 *errbuf = NUL;
4526 i = getdigits(&arg);
4527 if (i & 1)
4528 STRCAT(errbuf, "b,");
4529 if (i & 2)
4530 STRCAT(errbuf, "s,");
4531 if (i & 4)
4532 STRCAT(errbuf, "h,l,");
4533 if (i & 8)
4534 STRCAT(errbuf, "<,>,");
4535 if (i & 16)
4536 STRCAT(errbuf, "[,],");
4537 if (*errbuf != NUL) /* remove trailing , */
4538 errbuf[STRLEN(errbuf) - 1] = NUL;
4539 save_arg = arg;
4540 arg = errbuf;
4541 }
4542 /*
4543 * Remove '>' before 'dir' and 'bdir', for
4544 * backwards compatibility with version 3.0
4545 */
4546 else if ( *arg == '>'
4547 && (varp == (char_u *)&p_dir
4548 || varp == (char_u *)&p_bdir))
4549 {
4550 ++arg;
4551 }
4552
4553 /* When setting the local value of a global
4554 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004555 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004556 && (opt_flags & OPT_LOCAL))
4557 origval = *(char_u **)get_varp(
4558 &options[opt_idx]);
4559 else
4560 origval = oldval;
4561
4562 /*
4563 * Copy the new string into allocated memory.
4564 * Can't use set_string_option_direct(), because
4565 * we need to remove the backslashes.
4566 */
4567 /* get a bit too much */
4568 newlen = (unsigned)STRLEN(arg) + 1;
4569 if (adding || prepending || removing)
4570 newlen += (unsigned)STRLEN(origval) + 1;
4571 newval = alloc(newlen);
4572 if (newval == NULL) /* out of mem, don't change */
4573 break;
4574 s = newval;
4575
4576 /*
4577 * Copy the string, skip over escaped chars.
4578 * For MS-DOS and WIN32 backslashes before normal
4579 * file name characters are not removed, and keep
4580 * backslash at start, for "\\machine\path", but
4581 * do remove it for "\\\\machine\\path".
4582 * The reverse is found in ExpandOldSetting().
4583 */
4584 while (*arg && !vim_iswhite(*arg))
4585 {
4586 if (*arg == '\\' && arg[1] != NUL
4587#ifdef BACKSLASH_IN_FILENAME
4588 && !((flags & P_EXPAND)
4589 && vim_isfilec(arg[1])
4590 && (arg[1] != '\\'
4591 || (s == newval
4592 && arg[2] != '\\')))
4593#endif
4594 )
4595 ++arg; /* remove backslash */
4596#ifdef FEAT_MBYTE
4597 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004598 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004599 {
4600 /* copy multibyte char */
4601 mch_memmove(s, arg, (size_t)i);
4602 arg += i;
4603 s += i;
4604 }
4605 else
4606#endif
4607 *s++ = *arg++;
4608 }
4609 *s = NUL;
4610
4611 /*
4612 * Expand environment variables and ~.
4613 * Don't do it when adding without inserting a
4614 * comma.
4615 */
4616 if (!(adding || prepending || removing)
4617 || (flags & P_COMMA))
4618 {
4619 s = option_expand(opt_idx, newval);
4620 if (s != NULL)
4621 {
4622 vim_free(newval);
4623 newlen = (unsigned)STRLEN(s) + 1;
4624 if (adding || prepending || removing)
4625 newlen += (unsigned)STRLEN(origval) + 1;
4626 newval = alloc(newlen);
4627 if (newval == NULL)
4628 break;
4629 STRCPY(newval, s);
4630 }
4631 }
4632
4633 /* locate newval[] in origval[] when removing it
4634 * and when adding to avoid duplicates */
4635 i = 0; /* init for GCC */
4636 if (removing || (flags & P_NODUP))
4637 {
4638 i = (int)STRLEN(newval);
4639 bs = 0;
4640 for (s = origval; *s; ++s)
4641 {
4642 if ((!(flags & P_COMMA)
4643 || s == origval
4644 || (s[-1] == ',' && !(bs & 1)))
4645 && STRNCMP(s, newval, i) == 0
4646 && (!(flags & P_COMMA)
4647 || s[i] == ','
4648 || s[i] == NUL))
4649 break;
4650 /* Count backspaces. Only a comma with an
4651 * even number of backspaces before it is
4652 * recognized as a separator */
4653 if (s > origval && s[-1] == '\\')
4654 ++bs;
4655 else
4656 bs = 0;
4657 }
4658
4659 /* do not add if already there */
4660 if ((adding || prepending) && *s)
4661 {
4662 prepending = FALSE;
4663 adding = FALSE;
4664 STRCPY(newval, origval);
4665 }
4666 }
4667
4668 /* concatenate the two strings; add a ',' if
4669 * needed */
4670 if (adding || prepending)
4671 {
4672 comma = ((flags & P_COMMA) && *origval != NUL
4673 && *newval != NUL);
4674 if (adding)
4675 {
4676 i = (int)STRLEN(origval);
4677 mch_memmove(newval + i + comma, newval,
4678 STRLEN(newval) + 1);
4679 mch_memmove(newval, origval, (size_t)i);
4680 }
4681 else
4682 {
4683 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004684 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004685 }
4686 if (comma)
4687 newval[i] = ',';
4688 }
4689
4690 /* Remove newval[] from origval[]. (Note: "i" has
4691 * been set above and is used here). */
4692 if (removing)
4693 {
4694 STRCPY(newval, origval);
4695 if (*s)
4696 {
4697 /* may need to remove a comma */
4698 if (flags & P_COMMA)
4699 {
4700 if (s == origval)
4701 {
4702 /* include comma after string */
4703 if (s[i] == ',')
4704 ++i;
4705 }
4706 else
4707 {
4708 /* include comma before string */
4709 --s;
4710 ++i;
4711 }
4712 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004713 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004714 }
4715 }
4716
4717 if (flags & P_FLAGLIST)
4718 {
4719 /* Remove flags that appear twice. */
4720 for (s = newval; *s; ++s)
4721 if ((!(flags & P_COMMA) || *s != ',')
4722 && vim_strchr(s + 1, *s) != NULL)
4723 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004724 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004725 --s;
4726 }
4727 }
4728
4729 if (save_arg != NULL) /* number for 'whichwrap' */
4730 arg = save_arg;
4731 new_value_alloced = TRUE;
4732 }
4733
4734 /* Set the new value. */
4735 *(char_u **)(varp) = newval;
4736
4737 /* Handle side effects, and set the global value for
4738 * ":set" on local options. */
4739 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4740 new_value_alloced, oldval, errbuf, opt_flags);
4741
4742 /* If error detected, print the error message. */
4743 if (errmsg != NULL)
4744 goto skip;
4745 }
4746 else /* key code option */
4747 {
4748 char_u *p;
4749
4750 if (nextchar == '&')
4751 {
4752 if (add_termcap_entry(key_name, TRUE) == FAIL)
4753 errmsg = (char_u *)N_("E522: Not found in termcap");
4754 }
4755 else
4756 {
4757 ++arg; /* jump to after the '=' or ':' */
4758 for (p = arg; *p && !vim_iswhite(*p); ++p)
4759 if (*p == '\\' && p[1] != NUL)
4760 ++p;
4761 nextchar = *p;
4762 *p = NUL;
4763 add_termcode(key_name, arg, FALSE);
4764 *p = nextchar;
4765 }
4766 if (full_screen)
4767 ttest(FALSE);
4768 redraw_all_later(CLEAR);
4769 }
4770 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004771
Bram Moolenaar071d4272004-06-13 20:20:40 +00004772 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004773 did_set_option(opt_idx, opt_flags,
4774 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004775 }
4776
4777skip:
4778 /*
4779 * Advance to next argument.
4780 * - skip until a blank found, taking care of backslashes
4781 * - skip blanks
4782 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4783 */
4784 for (i = 0; i < 2 ; ++i)
4785 {
4786 while (*arg != NUL && !vim_iswhite(*arg))
4787 if (*arg++ == '\\' && *arg != NUL)
4788 ++arg;
4789 arg = skipwhite(arg);
4790 if (*arg != '=')
4791 break;
4792 }
4793 }
4794
4795 if (errmsg != NULL)
4796 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004797 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004798 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 if (i + (arg - startarg) < IOSIZE)
4800 {
4801 /* append the argument with the error */
4802 STRCAT(IObuff, ": ");
4803 mch_memmove(IObuff + i, startarg, (arg - startarg));
4804 IObuff[i + (arg - startarg)] = NUL;
4805 }
4806 /* make sure all characters are printable */
4807 trans_characters(IObuff, IOSIZE);
4808
4809 ++no_wait_return; /* wait_return done later */
4810 emsg(IObuff); /* show error highlighted */
4811 --no_wait_return;
4812
4813 return FAIL;
4814 }
4815
4816 arg = skipwhite(arg);
4817 }
4818
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004819theend:
4820 if (silent_mode && did_show)
4821 {
4822 /* After displaying option values in silent mode. */
4823 silent_mode = FALSE;
4824 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4825 msg_putchar('\n');
4826 cursor_on(); /* msg_start() switches it off */
4827 out_flush();
4828 silent_mode = TRUE;
4829 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4830 }
4831
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832 return OK;
4833}
4834
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004835/*
4836 * Call this when an option has been given a new value through a user command.
4837 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4838 */
4839 static void
4840did_set_option(opt_idx, opt_flags, new_value)
4841 int opt_idx;
4842 int opt_flags; /* possibly with OPT_MODELINE */
4843 int new_value; /* value was replaced completely */
4844{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004845 long_u *p;
4846
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004847 options[opt_idx].flags |= P_WAS_SET;
4848
4849 /* When an option is set in the sandbox, from a modeline or in secure mode
4850 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004851 * flag. */
4852 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004853 if (secure
4854#ifdef HAVE_SANDBOX
4855 || sandbox != 0
4856#endif
4857 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004858 *p = *p | P_INSECURE;
4859 else if (new_value)
4860 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004861}
4862
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 static char_u *
4864illegal_char(errbuf, c)
4865 char_u *errbuf;
4866 int c;
4867{
4868 if (errbuf == NULL)
4869 return (char_u *)"";
4870 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004871 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004872 return errbuf;
4873}
4874
4875/*
4876 * Convert a key name or string into a key value.
4877 * Used for 'wildchar' and 'cedit' options.
4878 */
4879 static int
4880string_to_key(arg)
4881 char_u *arg;
4882{
4883 if (*arg == '<')
4884 return find_key_option(arg + 1);
4885 if (*arg == '^')
4886 return Ctrl_chr(arg[1]);
4887 return *arg;
4888}
4889
4890#ifdef FEAT_CMDWIN
4891/*
4892 * Check value of 'cedit' and set cedit_key.
4893 * Returns NULL if value is OK, error message otherwise.
4894 */
4895 static char_u *
4896check_cedit()
4897{
4898 int n;
4899
4900 if (*p_cedit == NUL)
4901 cedit_key = -1;
4902 else
4903 {
4904 n = string_to_key(p_cedit);
4905 if (vim_isprintc(n))
4906 return e_invarg;
4907 cedit_key = n;
4908 }
4909 return NULL;
4910}
4911#endif
4912
4913#ifdef FEAT_TITLE
4914/*
4915 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4916 * maketitle() to create and display it.
4917 * When switching the title or icon off, call mch_restore_title() to get
4918 * the old value back.
4919 */
4920 static void
4921did_set_title(icon)
4922 int icon; /* Did set icon instead of title */
4923{
4924 if (starting != NO_SCREEN
4925#ifdef FEAT_GUI
4926 && !gui.starting
4927#endif
4928 )
4929 {
4930 maketitle();
4931 if (icon)
4932 {
4933 if (!p_icon)
4934 mch_restore_title(2);
4935 }
4936 else
4937 {
4938 if (!p_title)
4939 mch_restore_title(1);
4940 }
4941 }
4942}
4943#endif
4944
4945/*
4946 * set_options_bin - called when 'bin' changes value.
4947 */
4948 void
4949set_options_bin(oldval, newval, opt_flags)
4950 int oldval;
4951 int newval;
4952 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
4953{
4954 /*
4955 * The option values that are changed when 'bin' changes are
4956 * copied when 'bin is set and restored when 'bin' is reset.
4957 */
4958 if (newval)
4959 {
4960 if (!oldval) /* switched on */
4961 {
4962 if (!(opt_flags & OPT_GLOBAL))
4963 {
4964 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4965 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4966 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4967 curbuf->b_p_et_nobin = curbuf->b_p_et;
4968 }
4969 if (!(opt_flags & OPT_LOCAL))
4970 {
4971 p_tw_nobin = p_tw;
4972 p_wm_nobin = p_wm;
4973 p_ml_nobin = p_ml;
4974 p_et_nobin = p_et;
4975 }
4976 }
4977
4978 if (!(opt_flags & OPT_GLOBAL))
4979 {
4980 curbuf->b_p_tw = 0; /* no automatic line wrap */
4981 curbuf->b_p_wm = 0; /* no automatic line wrap */
4982 curbuf->b_p_ml = 0; /* no modelines */
4983 curbuf->b_p_et = 0; /* no expandtab */
4984 }
4985 if (!(opt_flags & OPT_LOCAL))
4986 {
4987 p_tw = 0;
4988 p_wm = 0;
4989 p_ml = FALSE;
4990 p_et = FALSE;
4991 p_bin = TRUE; /* needed when called for the "-b" argument */
4992 }
4993 }
4994 else if (oldval) /* switched off */
4995 {
4996 if (!(opt_flags & OPT_GLOBAL))
4997 {
4998 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4999 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5000 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5001 curbuf->b_p_et = curbuf->b_p_et_nobin;
5002 }
5003 if (!(opt_flags & OPT_LOCAL))
5004 {
5005 p_tw = p_tw_nobin;
5006 p_wm = p_wm_nobin;
5007 p_ml = p_ml_nobin;
5008 p_et = p_et_nobin;
5009 }
5010 }
5011}
5012
5013#ifdef FEAT_VIMINFO
5014/*
5015 * Find the parameter represented by the given character (eg ', :, ", or /),
5016 * and return its associated value in the 'viminfo' string.
5017 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005018 * If the parameter is not specified in the string or there is no following
5019 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005020 */
5021 int
5022get_viminfo_parameter(type)
5023 int type;
5024{
5025 char_u *p;
5026
5027 p = find_viminfo_parameter(type);
5028 if (p != NULL && VIM_ISDIGIT(*p))
5029 return atoi((char *)p);
5030 return -1;
5031}
5032
5033/*
5034 * Find the parameter represented by the given character (eg ''', ':', '"', or
5035 * '/') in the 'viminfo' option and return a pointer to the string after it.
5036 * Return NULL if the parameter is not specified in the string.
5037 */
5038 char_u *
5039find_viminfo_parameter(type)
5040 int type;
5041{
5042 char_u *p;
5043
5044 for (p = p_viminfo; *p; ++p)
5045 {
5046 if (*p == type)
5047 return p + 1;
5048 if (*p == 'n') /* 'n' is always the last one */
5049 break;
5050 p = vim_strchr(p, ','); /* skip until next ',' */
5051 if (p == NULL) /* hit the end without finding parameter */
5052 break;
5053 }
5054 return NULL;
5055}
5056#endif
5057
5058/*
5059 * Expand environment variables for some string options.
5060 * These string options cannot be indirect!
5061 * If "val" is NULL expand the current value of the option.
5062 * Return pointer to NameBuff, or NULL when not expanded.
5063 */
5064 static char_u *
5065option_expand(opt_idx, val)
5066 int opt_idx;
5067 char_u *val;
5068{
5069 /* if option doesn't need expansion nothing to do */
5070 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5071 return NULL;
5072
5073 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5074 * expand_env() would truncate the string. */
5075 if (val != NULL && STRLEN(val) > MAXPATHL)
5076 return NULL;
5077
5078 if (val == NULL)
5079 val = *(char_u **)options[opt_idx].var;
5080
5081 /*
5082 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5083 * Escape spaces when expanding 'tags', they are used to separate file
5084 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005085 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005086 */
5087 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005088 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005089#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005090 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5091#endif
5092 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005093 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5094 return NULL;
5095
5096 return NameBuff;
5097}
5098
5099/*
5100 * After setting various option values: recompute variables that depend on
5101 * option values.
5102 */
5103 static void
5104didset_options()
5105{
5106 /* initialize the table for 'iskeyword' et.al. */
5107 (void)init_chartab();
5108
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005109#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005110 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005112 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5113#ifdef FEAT_SESSION
5114 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5115 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5116#endif
5117#ifdef FEAT_FOLDING
5118 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5119#endif
5120 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5121#ifdef FEAT_VIRTUALEDIT
5122 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5123#endif
5124#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5125 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5126#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005127#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005128 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005129 (void)spell_check_sps();
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00005130 (void)compile_cap_prog(curbuf);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005132#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5133 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5134#endif
5135#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5136 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5137#endif
5138#ifdef FEAT_CMDWIN
5139 /* set cedit_key */
5140 (void)check_cedit();
5141#endif
5142}
5143
5144/*
5145 * Check for string options that are NULL (normally only termcap options).
5146 */
5147 void
5148check_options()
5149{
5150 int opt_idx;
5151
5152 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5153 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5154 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5155}
5156
5157/*
5158 * Check string options in a buffer for NULL value.
5159 */
5160 void
5161check_buf_options(buf)
5162 buf_T *buf;
5163{
5164#if defined(FEAT_QUICKFIX)
5165 check_string_option(&buf->b_p_bh);
5166 check_string_option(&buf->b_p_bt);
5167#endif
5168#ifdef FEAT_MBYTE
5169 check_string_option(&buf->b_p_fenc);
5170#endif
5171 check_string_option(&buf->b_p_ff);
5172#ifdef FEAT_FIND_ID
5173 check_string_option(&buf->b_p_def);
5174 check_string_option(&buf->b_p_inc);
5175# ifdef FEAT_EVAL
5176 check_string_option(&buf->b_p_inex);
5177# endif
5178#endif
5179#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5180 check_string_option(&buf->b_p_inde);
5181 check_string_option(&buf->b_p_indk);
5182#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005183#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5184 check_string_option(&buf->b_p_bexpr);
5185#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005186#if defined(FEAT_EVAL)
5187 check_string_option(&buf->b_p_fex);
5188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189#ifdef FEAT_CRYPT
5190 check_string_option(&buf->b_p_key);
5191#endif
5192 check_string_option(&buf->b_p_kp);
5193 check_string_option(&buf->b_p_mps);
5194 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005195 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005196 check_string_option(&buf->b_p_isk);
5197#ifdef FEAT_COMMENTS
5198 check_string_option(&buf->b_p_com);
5199#endif
5200#ifdef FEAT_FOLDING
5201 check_string_option(&buf->b_p_cms);
5202#endif
5203 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005204#ifdef FEAT_TEXTOBJ
5205 check_string_option(&buf->b_p_qe);
5206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005207#ifdef FEAT_SYN_HL
5208 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005209#endif
5210#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00005211 check_string_option(&buf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00005212 check_string_option(&buf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00005213 check_string_option(&buf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005214#endif
5215#ifdef FEAT_SEARCHPATH
5216 check_string_option(&buf->b_p_sua);
5217#endif
5218#ifdef FEAT_CINDENT
5219 check_string_option(&buf->b_p_cink);
5220 check_string_option(&buf->b_p_cino);
5221#endif
5222#ifdef FEAT_AUTOCMD
5223 check_string_option(&buf->b_p_ft);
5224#endif
5225#ifdef FEAT_OSFILETYPE
5226 check_string_option(&buf->b_p_oft);
5227#endif
5228#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5229 check_string_option(&buf->b_p_cinw);
5230#endif
5231#ifdef FEAT_INS_EXPAND
5232 check_string_option(&buf->b_p_cpt);
5233#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005234#ifdef FEAT_COMPL_FUNC
5235 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005236 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005237#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005238#ifdef FEAT_KEYMAP
5239 check_string_option(&buf->b_p_keymap);
5240#endif
5241#ifdef FEAT_QUICKFIX
5242 check_string_option(&buf->b_p_gp);
5243 check_string_option(&buf->b_p_mp);
5244 check_string_option(&buf->b_p_efm);
5245#endif
5246 check_string_option(&buf->b_p_ep);
5247 check_string_option(&buf->b_p_path);
5248 check_string_option(&buf->b_p_tags);
5249#ifdef FEAT_INS_EXPAND
5250 check_string_option(&buf->b_p_dict);
5251 check_string_option(&buf->b_p_tsr);
5252#endif
5253}
5254
5255/*
5256 * Free the string allocated for an option.
5257 * Checks for the string being empty_option. This may happen if we're out of
5258 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5259 * check_options().
5260 * Does NOT check for P_ALLOCED flag!
5261 */
5262 void
5263free_string_option(p)
5264 char_u *p;
5265{
5266 if (p != empty_option)
5267 vim_free(p);
5268}
5269
5270 void
5271clear_string_option(pp)
5272 char_u **pp;
5273{
5274 if (*pp != empty_option)
5275 vim_free(*pp);
5276 *pp = empty_option;
5277}
5278
5279 static void
5280check_string_option(pp)
5281 char_u **pp;
5282{
5283 if (*pp == NULL)
5284 *pp = empty_option;
5285}
5286
5287/*
5288 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5289 */
5290 void
5291set_term_option_alloced(p)
5292 char_u **p;
5293{
5294 int opt_idx;
5295
5296 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5297 if (options[opt_idx].var == (char_u *)p)
5298 {
5299 options[opt_idx].flags |= P_ALLOCED;
5300 return;
5301 }
5302 return; /* cannot happen: didn't find it! */
5303}
5304
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005305#if defined(FEAT_EVAL) || defined(PROTO)
5306/*
5307 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5308 * Return FALSE when it wasn't.
5309 * Return -1 for an unknown option.
5310 */
5311 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005312was_set_insecurely(opt, opt_flags)
5313 char_u *opt;
5314 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005315{
5316 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005317 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005318
5319 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005320 {
5321 flagp = insecure_flag(idx, opt_flags);
5322 return (*flagp & P_INSECURE) != 0;
5323 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005324 EMSG2(_(e_intern2), "was_set_insecurely()");
5325 return -1;
5326}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005327
5328/*
5329 * Get a pointer to the flags used for the P_INSECURE flag of option
5330 * "opt_idx". For some local options a local flags field is used.
5331 */
5332 static long_u *
5333insecure_flag(opt_idx, opt_flags)
5334 int opt_idx;
5335 int opt_flags;
5336{
5337 if (opt_flags & OPT_LOCAL)
5338 switch ((int)options[opt_idx].indir)
5339 {
5340#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005341 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005342#endif
5343#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005344# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005345 case PV_FDE: return &curwin->w_p_fde_flags;
5346 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005347# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005348# ifdef FEAT_BEVAL
5349 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5350# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005351# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005352 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005353# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005354 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005355# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005356 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005357# endif
5358#endif
5359 }
5360
5361 /* Nothing special, return global flags field. */
5362 return &options[opt_idx].flags;
5363}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005364#endif
5365
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005366#ifdef FEAT_TITLE
5367static void redraw_titles __ARGS((void));
5368
5369/*
5370 * Redraw the window title and/or tab page text later.
5371 */
5372static void redraw_titles()
5373{
5374 need_maketitle = TRUE;
5375# ifdef FEAT_WINDOWS
5376 redraw_tabline = TRUE;
5377# endif
5378}
5379#endif
5380
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381/*
5382 * Set a string option to a new value (without checking the effect).
5383 * The string is copied into allocated memory.
5384 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005385 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005386 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387 */
5388 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005389set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005390 char_u *name;
5391 int opt_idx;
5392 char_u *val;
5393 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005394 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395{
5396 char_u *s;
5397 char_u **varp;
5398 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005399 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400
Bram Moolenaar89d40322006-08-29 15:30:07 +00005401 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005402 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005403 idx = findoption(name);
5404 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005405 {
5406 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005407 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005408 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005409 }
5410
Bram Moolenaar89d40322006-08-29 15:30:07 +00005411 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005412 return;
5413
5414 s = vim_strsave(val);
5415 if (s != NULL)
5416 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005417 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005418 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005419 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005420 free_string_option(*varp);
5421 *varp = s;
5422
5423 /* For buffer/window local option may also set the global value. */
5424 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005425 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005426
Bram Moolenaar89d40322006-08-29 15:30:07 +00005427 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005428
5429 /* When setting both values of a global option with a local value,
5430 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005431 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432 {
5433 free_string_option(*varp);
5434 *varp = empty_option;
5435 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005436# ifdef FEAT_EVAL
5437 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005438 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005439 set_sid == 0 ? current_SID : set_sid);
5440# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005441 }
5442}
5443
5444/*
5445 * Set global value for string option when it's a local option.
5446 */
5447 static void
5448set_string_option_global(opt_idx, varp)
5449 int opt_idx; /* option index */
5450 char_u **varp; /* pointer to option variable */
5451{
5452 char_u **p, *s;
5453
5454 /* the global value is always allocated */
5455 if (options[opt_idx].var == VAR_WIN)
5456 p = (char_u **)GLOBAL_WO(varp);
5457 else
5458 p = (char_u **)options[opt_idx].var;
5459 if (options[opt_idx].indir != PV_NONE
5460 && p != varp
5461 && (s = vim_strsave(*varp)) != NULL)
5462 {
5463 free_string_option(*p);
5464 *p = s;
5465 }
5466}
5467
5468/*
5469 * Set a string option to a new value, and handle the effects.
5470 */
5471 static void
5472set_string_option(opt_idx, value, opt_flags)
5473 int opt_idx;
5474 char_u *value;
5475 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5476{
5477 char_u *s;
5478 char_u **varp;
5479 char_u *oldval;
5480
5481 if (options[opt_idx].var == NULL) /* don't set hidden option */
5482 return;
5483
5484 s = vim_strsave(value);
5485 if (s != NULL)
5486 {
5487 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5488 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005489 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005490 ? OPT_GLOBAL : OPT_LOCAL)
5491 : opt_flags);
5492 oldval = *varp;
5493 *varp = s;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005494 if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5495 opt_flags) == NULL)
5496 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005497 }
5498}
5499
5500/*
5501 * Handle string options that need some action to perform when changed.
5502 * Returns NULL for success, or an error message for an error.
5503 */
5504 static char_u *
5505did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5506 opt_flags)
5507 int opt_idx; /* index in options[] table */
5508 char_u **varp; /* pointer to the option variable */
5509 int new_value_alloced; /* new value was allocated */
5510 char_u *oldval; /* previous value of the option */
5511 char_u *errbuf; /* buffer for errors, or NULL */
5512 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5513{
5514 char_u *errmsg = NULL;
5515 char_u *s, *p;
5516 int did_chartab = FALSE;
5517 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005518 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005519#ifdef FEAT_GUI
5520 /* set when changing an option that only requires a redraw in the GUI */
5521 int redraw_gui_only = FALSE;
5522#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005523
5524 /* Get the global option to compare with, otherwise we would have to check
5525 * two values for all local options. */
5526 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5527
5528 /* Disallow changing some options from secure mode */
5529 if ((secure
5530#ifdef HAVE_SANDBOX
5531 || sandbox != 0
5532#endif
5533 ) && (options[opt_idx].flags & P_SECURE))
5534 {
5535 errmsg = e_secure;
5536 }
5537
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005538 /* Check for a "normal" file name in some options. Disallow a path
5539 * separator (slash and/or backslash), wildcards and characters that are
5540 * often illegal in a file name. */
5541 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005542 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005543 {
5544 errmsg = e_invarg;
5545 }
5546
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547 /* 'term' */
5548 else if (varp == &T_NAME)
5549 {
5550 if (T_NAME[0] == NUL)
5551 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5552#ifdef FEAT_GUI
5553 if (gui.in_use)
5554 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5555 else if (term_is_gui(T_NAME))
5556 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5557#endif
5558 else if (set_termname(T_NAME) == FAIL)
5559 errmsg = (char_u *)N_("E522: Not found in termcap");
5560 else
5561 /* Screen colors may have changed. */
5562 redraw_later_clear();
5563 }
5564
5565 /* 'backupcopy' */
5566 else if (varp == &p_bkc)
5567 {
5568 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5569 errmsg = e_invarg;
5570 if (((bkc_flags & BKC_AUTO) != 0)
5571 + ((bkc_flags & BKC_YES) != 0)
5572 + ((bkc_flags & BKC_NO) != 0) != 1)
5573 {
5574 /* Must have exactly one of "auto", "yes" and "no". */
5575 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5576 errmsg = e_invarg;
5577 }
5578 }
5579
5580 /* 'backupext' and 'patchmode' */
5581 else if (varp == &p_bex || varp == &p_pm)
5582 {
5583 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5584 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5585 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5586 }
5587
5588 /*
5589 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5590 * If the new option is invalid, use old value. 'lisp' option: refill
5591 * chartab[] for '-' char
5592 */
5593 else if ( varp == &p_isi
5594 || varp == &(curbuf->b_p_isk)
5595 || varp == &p_isp
5596 || varp == &p_isf)
5597 {
5598 if (init_chartab() == FAIL)
5599 {
5600 did_chartab = TRUE; /* need to restore it below */
5601 errmsg = e_invarg; /* error in value */
5602 }
5603 }
5604
5605 /* 'helpfile' */
5606 else if (varp == &p_hf)
5607 {
5608 /* May compute new values for $VIM and $VIMRUNTIME */
5609 if (didset_vim)
5610 {
5611 vim_setenv((char_u *)"VIM", (char_u *)"");
5612 didset_vim = FALSE;
5613 }
5614 if (didset_vimruntime)
5615 {
5616 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5617 didset_vimruntime = FALSE;
5618 }
5619 }
5620
5621#ifdef FEAT_MULTI_LANG
5622 /* 'helplang' */
5623 else if (varp == &p_hlg)
5624 {
5625 /* Check for "", "ab", "ab,cd", etc. */
5626 for (s = p_hlg; *s != NUL; s += 3)
5627 {
5628 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5629 {
5630 errmsg = e_invarg;
5631 break;
5632 }
5633 if (s[2] == NUL)
5634 break;
5635 }
5636 }
5637#endif
5638
5639 /* 'highlight' */
5640 else if (varp == &p_hl)
5641 {
5642 if (highlight_changed() == FAIL)
5643 errmsg = e_invarg; /* invalid flags */
5644 }
5645
5646 /* 'nrformats' */
5647 else if (gvarp == &p_nf)
5648 {
5649 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5650 errmsg = e_invarg;
5651 }
5652
5653#ifdef FEAT_SESSION
5654 /* 'sessionoptions' */
5655 else if (varp == &p_ssop)
5656 {
5657 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5658 errmsg = e_invarg;
5659 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5660 {
5661 /* Don't allow both "sesdir" and "curdir". */
5662 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5663 errmsg = e_invarg;
5664 }
5665 }
5666 /* 'viewoptions' */
5667 else if (varp == &p_vop)
5668 {
5669 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5670 errmsg = e_invarg;
5671 }
5672#endif
5673
5674 /* 'scrollopt' */
5675#ifdef FEAT_SCROLLBIND
5676 else if (varp == &p_sbo)
5677 {
5678 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5679 errmsg = e_invarg;
5680 }
5681#endif
5682
5683 /* 'ambiwidth' */
5684#ifdef FEAT_MBYTE
5685 else if (varp == &p_ambw)
5686 {
5687 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5688 errmsg = e_invarg;
5689 }
5690#endif
5691
5692 /* 'background' */
5693 else if (varp == &p_bg)
5694 {
5695 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5696 {
5697#ifdef FEAT_EVAL
5698 int dark = (*p_bg == 'd');
5699#endif
5700
5701 init_highlight(FALSE, FALSE);
5702
5703#ifdef FEAT_EVAL
5704 if (dark != (*p_bg == 'd')
5705 && get_var_value((char_u *)"g:colors_name") != NULL)
5706 {
5707 /* The color scheme must have set 'background' back to another
5708 * value, that's not what we want here. Disable the color
5709 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005710 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711 free_string_option(p_bg);
5712 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5713 check_string_option(&p_bg);
5714 init_highlight(FALSE, FALSE);
5715 }
5716#endif
5717 }
5718 else
5719 errmsg = e_invarg;
5720 }
5721
5722 /* 'wildmode' */
5723 else if (varp == &p_wim)
5724 {
5725 if (check_opt_wim() == FAIL)
5726 errmsg = e_invarg;
5727 }
5728
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005729#ifdef FEAT_CMDL_COMPL
5730 /* 'wildoptions' */
5731 else if (varp == &p_wop)
5732 {
5733 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5734 errmsg = e_invarg;
5735 }
5736#endif
5737
Bram Moolenaar071d4272004-06-13 20:20:40 +00005738#ifdef FEAT_WAK
5739 /* 'winaltkeys' */
5740 else if (varp == &p_wak)
5741 {
5742 if (*p_wak == NUL
5743 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5744 errmsg = e_invarg;
5745# ifdef FEAT_MENU
5746# ifdef FEAT_GUI_MOTIF
5747 else if (gui.in_use)
5748 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5749# else
5750# ifdef FEAT_GUI_GTK
5751 else if (gui.in_use)
5752 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5753# endif
5754# endif
5755# endif
5756 }
5757#endif
5758
5759#ifdef FEAT_AUTOCMD
5760 /* 'eventignore' */
5761 else if (varp == &p_ei)
5762 {
5763 if (check_ei() == FAIL)
5764 errmsg = e_invarg;
5765 }
5766#endif
5767
5768#ifdef FEAT_MBYTE
5769 /* 'encoding' and 'fileencoding' */
5770 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5771 {
5772 if (gvarp == &p_fenc)
5773 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005774 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775 errmsg = e_modifiable;
5776 else if (vim_strchr(*varp, ',') != NULL)
5777 /* No comma allowed in 'fileencoding'; catches confusing it
5778 * with 'fileencodings'. */
5779 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005780 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005781 {
5782# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005784 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005786 /* Add 'fileencoding' to the swap file. */
5787 ml_setflags(curbuf);
5788 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005789 }
5790 if (errmsg == NULL)
5791 {
5792 /* canonize the value, so that STRCMP() can be used on it */
5793 p = enc_canonize(*varp);
5794 if (p != NULL)
5795 {
5796 vim_free(*varp);
5797 *varp = p;
5798 }
5799 if (varp == &p_enc)
5800 {
5801 errmsg = mb_init();
5802# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005803 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005804# endif
5805 }
5806 }
5807
5808# if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5809 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5810 {
5811 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5812 if (STRCMP(p_tenc, "utf-8") != 0)
5813 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5814 }
5815# endif
5816
5817 if (errmsg == NULL)
5818 {
5819# ifdef FEAT_KEYMAP
5820 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5821 * (with another encoding). */
5822 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5823 (void)keymap_init();
5824# endif
5825
5826 /* When 'termencoding' is not empty and 'encoding' changes or when
5827 * 'termencoding' changes, need to setup for keyboard input and
5828 * display output conversion. */
5829 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5830 {
5831 convert_setup(&input_conv, p_tenc, p_enc);
5832 convert_setup(&output_conv, p_enc, p_tenc);
5833 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005834
5835# if defined(WIN3264) && defined(FEAT_MBYTE)
5836 /* $HOME may have characters in active code page. */
5837 if (varp == &p_enc)
5838 init_homedir();
5839# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005840 }
5841 }
5842#endif
5843
5844#if defined(FEAT_POSTSCRIPT)
5845 else if (varp == &p_penc)
5846 {
5847 /* Canonize printencoding if VIM standard one */
5848 p = enc_canonize(p_penc);
5849 if (p != NULL)
5850 {
5851 vim_free(p_penc);
5852 p_penc = p;
5853 }
5854 else
5855 {
5856 /* Ensure lower case and '-' for '_' */
5857 for (s = p_penc; *s != NUL; s++)
5858 {
5859 if (*s == '_')
5860 *s = '-';
5861 else
5862 *s = TOLOWER_ASC(*s);
5863 }
5864 }
5865 }
5866#endif
5867
Bram Moolenaar9372a112005-12-06 19:59:18 +00005868#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 else if (varp == &p_imak)
5870 {
5871 if (gui.in_use && !im_xim_isvalid_imactivate())
5872 errmsg = e_invarg;
5873 }
5874#endif
5875
5876#ifdef FEAT_KEYMAP
5877 else if (varp == &curbuf->b_p_keymap)
5878 {
5879 /* load or unload key mapping tables */
5880 errmsg = keymap_init();
5881
Bram Moolenaarfab06232009-03-04 03:13:35 +00005882 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00005884 if (*curbuf->b_p_keymap != NUL)
5885 {
5886 /* Installed a new keymap, switch on using it. */
5887 curbuf->b_p_iminsert = B_IMODE_LMAP;
5888 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
5889 curbuf->b_p_imsearch = B_IMODE_LMAP;
5890 }
5891 else
5892 {
5893 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
5894 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
5895 curbuf->b_p_iminsert = B_IMODE_NONE;
5896 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
5897 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
5898 }
5899 if ((opt_flags & OPT_LOCAL) == 0)
5900 {
5901 set_iminsert_global();
5902 set_imsearch_global();
5903 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904# ifdef FEAT_WINDOWS
5905 status_redraw_curbuf();
5906# endif
5907 }
5908 }
5909#endif
5910
5911 /* 'fileformat' */
5912 else if (gvarp == &p_ff)
5913 {
5914 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
5915 errmsg = e_modifiable;
5916 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
5917 errmsg = e_invarg;
5918 else
5919 {
5920 /* may also change 'textmode' */
5921 if (get_fileformat(curbuf) == EOL_DOS)
5922 curbuf->b_p_tx = TRUE;
5923 else
5924 curbuf->b_p_tx = FALSE;
5925#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005926 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005928 /* update flag in swap file */
5929 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01005930 /* Redraw needed when switching to/from "mac": a CR in the text
5931 * will be displayed differently. */
5932 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
5933 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934 }
5935 }
5936
5937 /* 'fileformats' */
5938 else if (varp == &p_ffs)
5939 {
5940 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5941 errmsg = e_invarg;
5942 else
5943 {
5944 /* also change 'textauto' */
5945 if (*p_ffs == NUL)
5946 p_ta = FALSE;
5947 else
5948 p_ta = TRUE;
5949 }
5950 }
5951
5952#if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5953 /* 'cryptkey' */
5954 else if (gvarp == &p_key)
5955 {
5956 /* Make sure the ":set" command doesn't show the new value in the
5957 * history. */
5958 remove_key_from_history();
5959 }
5960#endif
5961
5962 /* 'matchpairs' */
5963 else if (gvarp == &p_mps)
5964 {
5965 /* Check for "x:y,x:y" */
5966 for (p = *varp; *p != NUL; p += 4)
5967 {
5968 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5969 {
5970 errmsg = e_invarg;
5971 break;
5972 }
5973 if (p[3] == NUL)
5974 break;
5975 }
5976 }
5977
5978#ifdef FEAT_COMMENTS
5979 /* 'comments' */
5980 else if (gvarp == &p_com)
5981 {
5982 for (s = *varp; *s; )
5983 {
5984 while (*s && *s != ':')
5985 {
5986 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5987 && !VIM_ISDIGIT(*s) && *s != '-')
5988 {
5989 errmsg = illegal_char(errbuf, *s);
5990 break;
5991 }
5992 ++s;
5993 }
5994 if (*s++ == NUL)
5995 errmsg = (char_u *)N_("E524: Missing colon");
5996 else if (*s == ',' || *s == NUL)
5997 errmsg = (char_u *)N_("E525: Zero length string");
5998 if (errmsg != NULL)
5999 break;
6000 while (*s && *s != ',')
6001 {
6002 if (*s == '\\' && s[1] != NUL)
6003 ++s;
6004 ++s;
6005 }
6006 s = skip_to_option_part(s);
6007 }
6008 }
6009#endif
6010
6011 /* 'listchars' */
6012 else if (varp == &p_lcs)
6013 {
6014 errmsg = set_chars_option(varp);
6015 }
6016
6017#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6018 /* 'fillchars' */
6019 else if (varp == &p_fcs)
6020 {
6021 errmsg = set_chars_option(varp);
6022 }
6023#endif
6024
6025#ifdef FEAT_CMDWIN
6026 /* 'cedit' */
6027 else if (varp == &p_cedit)
6028 {
6029 errmsg = check_cedit();
6030 }
6031#endif
6032
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006033 /* 'verbosefile' */
6034 else if (varp == &p_vfile)
6035 {
6036 verbose_stop();
6037 if (*p_vfile != NUL && verbose_open() == FAIL)
6038 errmsg = e_invarg;
6039 }
6040
Bram Moolenaar071d4272004-06-13 20:20:40 +00006041#ifdef FEAT_VIMINFO
6042 /* 'viminfo' */
6043 else if (varp == &p_viminfo)
6044 {
6045 for (s = p_viminfo; *s;)
6046 {
6047 /* Check it's a valid character */
6048 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6049 {
6050 errmsg = illegal_char(errbuf, *s);
6051 break;
6052 }
6053 if (*s == 'n') /* name is always last one */
6054 {
6055 break;
6056 }
6057 else if (*s == 'r') /* skip until next ',' */
6058 {
6059 while (*++s && *s != ',')
6060 ;
6061 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006062 else if (*s == '%')
6063 {
6064 /* optional number */
6065 while (vim_isdigit(*++s))
6066 ;
6067 }
6068 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006069 ++s; /* no extra chars */
6070 else /* must have a number */
6071 {
6072 while (vim_isdigit(*++s))
6073 ;
6074
6075 if (!VIM_ISDIGIT(*(s - 1)))
6076 {
6077 if (errbuf != NULL)
6078 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006079 sprintf((char *)errbuf,
6080 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006081 transchar_byte(*(s - 1)));
6082 errmsg = errbuf;
6083 }
6084 else
6085 errmsg = (char_u *)"";
6086 break;
6087 }
6088 }
6089 if (*s == ',')
6090 ++s;
6091 else if (*s)
6092 {
6093 if (errbuf != NULL)
6094 errmsg = (char_u *)N_("E527: Missing comma");
6095 else
6096 errmsg = (char_u *)"";
6097 break;
6098 }
6099 }
6100 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6101 errmsg = (char_u *)N_("E528: Must specify a ' value");
6102 }
6103#endif /* FEAT_VIMINFO */
6104
6105 /* terminal options */
6106 else if (istermoption(&options[opt_idx]) && full_screen)
6107 {
6108 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6109 if (varp == &T_CCO)
6110 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006111 int colors = atoi((char *)T_CCO);
6112
6113 /* Only reinitialize colors if t_Co value has really changed to
6114 * avoid expensive reload of colorscheme if t_Co is set to the
6115 * same value multiple times. */
6116 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006118 t_colors = colors;
6119 if (t_colors <= 1)
6120 {
6121 if (new_value_alloced)
6122 vim_free(T_CCO);
6123 T_CCO = empty_option;
6124 }
6125 /* We now have a different color setup, initialize it again. */
6126 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 }
6129 ttest(FALSE);
6130 if (varp == &T_ME)
6131 {
6132 out_str(T_ME);
6133 redraw_later(CLEAR);
6134#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6135 /* Since t_me has been set, this probably means that the user
6136 * wants to use this as default colors. Need to reset default
6137 * background/foreground colors. */
6138 mch_set_normal_colors();
6139#endif
6140 }
6141 }
6142
6143#ifdef FEAT_LINEBREAK
6144 /* 'showbreak' */
6145 else if (varp == &p_sbr)
6146 {
6147 for (s = p_sbr; *s; )
6148 {
6149 if (ptr2cells(s) != 1)
6150 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006151 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006152 }
6153 }
6154#endif
6155
6156#ifdef FEAT_GUI
6157 /* 'guifont' */
6158 else if (varp == &p_guifont)
6159 {
6160 if (gui.in_use)
6161 {
6162 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006163# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006164 /*
6165 * Put up a font dialog and let the user select a new value.
6166 * If this is cancelled go back to the old value but don't
6167 * give an error message.
6168 */
6169 if (STRCMP(p, "*") == 0)
6170 {
6171 p = gui_mch_font_dialog(oldval);
6172
6173 if (new_value_alloced)
6174 free_string_option(p_guifont);
6175
6176 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6177 new_value_alloced = TRUE;
6178 }
6179# endif
6180 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6181 {
6182# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6183 if (STRCMP(p_guifont, "*") == 0)
6184 {
6185 /* Dialog was cancelled: Keep the old value without giving
6186 * an error message. */
6187 if (new_value_alloced)
6188 free_string_option(p_guifont);
6189 p_guifont = vim_strsave(oldval);
6190 new_value_alloced = TRUE;
6191 }
6192 else
6193# endif
6194 errmsg = (char_u *)N_("E596: Invalid font(s)");
6195 }
6196 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006197 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006198 }
6199# ifdef FEAT_XFONTSET
6200 else if (varp == &p_guifontset)
6201 {
6202 if (STRCMP(p_guifontset, "*") == 0)
6203 errmsg = (char_u *)N_("E597: can't select fontset");
6204 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6205 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006206 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006207 }
6208# endif
6209# ifdef FEAT_MBYTE
6210 else if (varp == &p_guifontwide)
6211 {
6212 if (STRCMP(p_guifontwide, "*") == 0)
6213 errmsg = (char_u *)N_("E533: can't select wide font");
6214 else if (gui_get_wide_font() == FAIL)
6215 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006216 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006217 }
6218# endif
6219#endif
6220
6221#ifdef CURSOR_SHAPE
6222 /* 'guicursor' */
6223 else if (varp == &p_guicursor)
6224 errmsg = parse_shape_opt(SHAPE_CURSOR);
6225#endif
6226
6227#ifdef FEAT_MOUSESHAPE
6228 /* 'mouseshape' */
6229 else if (varp == &p_mouseshape)
6230 {
6231 errmsg = parse_shape_opt(SHAPE_MOUSE);
6232 update_mouseshape(-1);
6233 }
6234#endif
6235
6236#ifdef FEAT_PRINTER
6237 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006238 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006239# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006240 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006241 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006242# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006243#endif
6244
6245#ifdef FEAT_LANGMAP
6246 /* 'langmap' */
6247 else if (varp == &p_langmap)
6248 langmap_set();
6249#endif
6250
6251#ifdef FEAT_LINEBREAK
6252 /* 'breakat' */
6253 else if (varp == &p_breakat)
6254 fill_breakat_flags();
6255#endif
6256
6257#ifdef FEAT_TITLE
6258 /* 'titlestring' and 'iconstring' */
6259 else if (varp == &p_titlestring || varp == &p_iconstring)
6260 {
6261# ifdef FEAT_STL_OPT
6262 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6263
6264 /* NULL => statusline syntax */
6265 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6266 stl_syntax |= flagval;
6267 else
6268 stl_syntax &= ~flagval;
6269# endif
6270 did_set_title(varp == &p_iconstring);
6271
6272 }
6273#endif
6274
6275#ifdef FEAT_GUI
6276 /* 'guioptions' */
6277 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006278 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006279 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006280 redraw_gui_only = TRUE;
6281 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282#endif
6283
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006284#if defined(FEAT_GUI_TABLINE)
6285 /* 'guitablabel' */
6286 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006287 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006288 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006289 redraw_gui_only = TRUE;
6290 }
6291 /* 'guitabtooltip' */
6292 else if (varp == &p_gtt)
6293 {
6294 redraw_gui_only = TRUE;
6295 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006296#endif
6297
Bram Moolenaar071d4272004-06-13 20:20:40 +00006298#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6299 /* 'ttymouse' */
6300 else if (varp == &p_ttym)
6301 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006302 /* Switch the mouse off before changing the escape sequences used for
6303 * that. */
6304 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6306 errmsg = e_invarg;
6307 else
6308 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006309 if (termcap_active)
6310 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006311 }
6312#endif
6313
6314#ifdef FEAT_VISUAL
6315 /* 'selection' */
6316 else if (varp == &p_sel)
6317 {
6318 if (*p_sel == NUL
6319 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6320 errmsg = e_invarg;
6321 }
6322
6323 /* 'selectmode' */
6324 else if (varp == &p_slm)
6325 {
6326 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6327 errmsg = e_invarg;
6328 }
6329#endif
6330
6331#ifdef FEAT_BROWSE
6332 /* 'browsedir' */
6333 else if (varp == &p_bsdir)
6334 {
6335 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6336 && !mch_isdir(p_bsdir))
6337 errmsg = e_invarg;
6338 }
6339#endif
6340
6341#ifdef FEAT_VISUAL
6342 /* 'keymodel' */
6343 else if (varp == &p_km)
6344 {
6345 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6346 errmsg = e_invarg;
6347 else
6348 {
6349 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6350 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6351 }
6352 }
6353#endif
6354
6355 /* 'mousemodel' */
6356 else if (varp == &p_mousem)
6357 {
6358 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6359 errmsg = e_invarg;
6360#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6361 else if (*p_mousem != *oldval)
6362 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6363 * to create or delete the popup menus. */
6364 gui_motif_update_mousemodel(root_menu);
6365#endif
6366 }
6367
6368 /* 'switchbuf' */
6369 else if (varp == &p_swb)
6370 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006371 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 errmsg = e_invarg;
6373 }
6374
6375 /* 'debug' */
6376 else if (varp == &p_debug)
6377 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006378 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 errmsg = e_invarg;
6380 }
6381
6382 /* 'display' */
6383 else if (varp == &p_dy)
6384 {
6385 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6386 errmsg = e_invarg;
6387 else
6388 (void)init_chartab();
6389
6390 }
6391
6392#ifdef FEAT_VERTSPLIT
6393 /* 'eadirection' */
6394 else if (varp == &p_ead)
6395 {
6396 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6397 errmsg = e_invarg;
6398 }
6399#endif
6400
6401#ifdef FEAT_CLIPBOARD
6402 /* 'clipboard' */
6403 else if (varp == &p_cb)
6404 errmsg = check_clipboard_option();
6405#endif
6406
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006407#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006408 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6409 * buffer in which 'spell' is set load the wordlists. */
6410 else if (varp == &(curbuf->b_p_spl) || varp == &(curbuf->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006411 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006412 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006413 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006414
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006415 if (varp == &(curbuf->b_p_spf))
6416 {
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006417 l = (int)STRLEN(curbuf->b_p_spf);
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006418 if (l > 0 && (l < 4 || STRCMP(curbuf->b_p_spf + l - 4,
6419 ".add") != 0))
6420 errmsg = e_invarg;
6421 }
6422
6423 if (errmsg == NULL)
6424 {
6425 FOR_ALL_WINDOWS(wp)
6426 if (wp->w_buffer == curbuf && wp->w_p_spell)
6427 {
6428 errmsg = did_set_spelllang(curbuf);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006429# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006430 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006431# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006432 }
6433 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006434 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006435 /* When 'spellcapcheck' is set compile the regexp program. */
6436 else if (varp == &(curbuf->b_p_spc))
6437 {
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00006438 errmsg = compile_cap_prog(curbuf);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006439 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006440 /* 'spellsuggest' */
6441 else if (varp == &p_sps)
6442 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006443 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006444 errmsg = e_invarg;
6445 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006446 /* 'mkspellmem' */
6447 else if (varp == &p_msm)
6448 {
6449 if (spell_check_msm() != OK)
6450 errmsg = e_invarg;
6451 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006452#endif
6453
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454#ifdef FEAT_QUICKFIX
6455 /* When 'bufhidden' is set, check for valid value. */
6456 else if (gvarp == &p_bh)
6457 {
6458 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6459 errmsg = e_invarg;
6460 }
6461
6462 /* When 'buftype' is set, check for valid value. */
6463 else if (gvarp == &p_bt)
6464 {
6465 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6466 errmsg = e_invarg;
6467 else
6468 {
6469# ifdef FEAT_WINDOWS
6470 if (curwin->w_status_height)
6471 {
6472 curwin->w_redr_status = TRUE;
6473 redraw_later(VALID);
6474 }
6475# endif
6476 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006477# ifdef FEAT_TITLE
6478 redraw_titles();
6479# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 }
6481 }
6482#endif
6483
6484#ifdef FEAT_STL_OPT
6485 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006486 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487 {
6488 int wid;
6489
6490 if (varp == &p_ruf) /* reset ru_wid first */
6491 ru_wid = 0;
6492 s = *varp;
6493 if (varp == &p_ruf && *s == '%')
6494 {
6495 /* set ru_wid if 'ruf' starts with "%99(" */
6496 if (*++s == '-') /* ignore a '-' */
6497 s++;
6498 wid = getdigits(&s);
6499 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6500 ru_wid = wid;
6501 else
6502 errmsg = check_stl_option(p_ruf);
6503 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006504 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006505 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006506 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006507 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006508 comp_col();
6509 }
6510#endif
6511
6512#ifdef FEAT_INS_EXPAND
6513 /* check if it is a valid value for 'complete' -- Acevedo */
6514 else if (gvarp == &p_cpt)
6515 {
6516 for (s = *varp; *s;)
6517 {
6518 while(*s == ',' || *s == ' ')
6519 s++;
6520 if (!*s)
6521 break;
6522 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6523 {
6524 errmsg = illegal_char(errbuf, *s);
6525 break;
6526 }
6527 if (*++s != NUL && *s != ',' && *s != ' ')
6528 {
6529 if (s[-1] == 'k' || s[-1] == 's')
6530 {
6531 /* skip optional filename after 'k' and 's' */
6532 while (*s && *s != ',' && *s != ' ')
6533 {
6534 if (*s == '\\')
6535 ++s;
6536 ++s;
6537 }
6538 }
6539 else
6540 {
6541 if (errbuf != NULL)
6542 {
6543 sprintf((char *)errbuf,
6544 _("E535: Illegal character after <%c>"),
6545 *--s);
6546 errmsg = errbuf;
6547 }
6548 else
6549 errmsg = (char_u *)"";
6550 break;
6551 }
6552 }
6553 }
6554 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006555
6556 /* 'completeopt' */
6557 else if (varp == &p_cot)
6558 {
6559 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6560 errmsg = e_invarg;
6561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006562#endif /* FEAT_INS_EXPAND */
6563
6564
6565#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6566 else if (varp == &p_toolbar)
6567 {
6568 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6569 &toolbar_flags, TRUE) != OK)
6570 errmsg = e_invarg;
6571 else
6572 {
6573 out_flush();
6574 gui_mch_show_toolbar((toolbar_flags &
6575 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6576 }
6577 }
6578#endif
6579
6580#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
6581 /* 'toolbariconsize': GTK+ 2 only */
6582 else if (varp == &p_tbis)
6583 {
6584 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6585 errmsg = e_invarg;
6586 else
6587 {
6588 out_flush();
6589 gui_mch_show_toolbar((toolbar_flags &
6590 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6591 }
6592 }
6593#endif
6594
6595 /* 'pastetoggle': translate key codes like in a mapping */
6596 else if (varp == &p_pt)
6597 {
6598 if (*p_pt)
6599 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006600 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601 if (p != NULL)
6602 {
6603 if (new_value_alloced)
6604 free_string_option(p_pt);
6605 p_pt = p;
6606 new_value_alloced = TRUE;
6607 }
6608 }
6609 }
6610
6611 /* 'backspace' */
6612 else if (varp == &p_bs)
6613 {
6614 if (VIM_ISDIGIT(*p_bs))
6615 {
6616 if (*p_bs >'2' || p_bs[1] != NUL)
6617 errmsg = e_invarg;
6618 }
6619 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6620 errmsg = e_invarg;
6621 }
6622
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006623#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 /* 'casemap' */
6625 else if (varp == &p_cmp)
6626 {
6627 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6628 errmsg = e_invarg;
6629 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631
6632#ifdef FEAT_DIFF
6633 /* 'diffopt' */
6634 else if (varp == &p_dip)
6635 {
6636 if (diffopt_changed() == FAIL)
6637 errmsg = e_invarg;
6638 }
6639#endif
6640
6641#ifdef FEAT_FOLDING
6642 /* 'foldmethod' */
6643 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6644 {
6645 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6646 || *curwin->w_p_fdm == NUL)
6647 errmsg = e_invarg;
6648 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006649 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006651 if (foldmethodIsDiff(curwin))
6652 newFoldLevel();
6653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 }
6655# ifdef FEAT_EVAL
6656 /* 'foldexpr' */
6657 else if (varp == &curwin->w_p_fde)
6658 {
6659 if (foldmethodIsExpr(curwin))
6660 foldUpdateAll(curwin);
6661 }
6662# endif
6663 /* 'foldmarker' */
6664 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6665 {
6666 p = vim_strchr(*varp, ',');
6667 if (p == NULL)
6668 errmsg = (char_u *)N_("E536: comma required");
6669 else if (p == *varp || p[1] == NUL)
6670 errmsg = e_invarg;
6671 else if (foldmethodIsMarker(curwin))
6672 foldUpdateAll(curwin);
6673 }
6674 /* 'commentstring' */
6675 else if (gvarp == &p_cms)
6676 {
6677 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6678 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6679 }
6680 /* 'foldopen' */
6681 else if (varp == &p_fdo)
6682 {
6683 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6684 errmsg = e_invarg;
6685 }
6686 /* 'foldclose' */
6687 else if (varp == &p_fcl)
6688 {
6689 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6690 errmsg = e_invarg;
6691 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006692 /* 'foldignore' */
6693 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6694 {
6695 if (foldmethodIsIndent(curwin))
6696 foldUpdateAll(curwin);
6697 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698#endif
6699
6700#ifdef FEAT_VIRTUALEDIT
6701 /* 'virtualedit' */
6702 else if (varp == &p_ve)
6703 {
6704 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6705 errmsg = e_invarg;
6706 else if (STRCMP(p_ve, oldval) != 0)
6707 {
6708 /* Recompute cursor position in case the new 've' setting
6709 * changes something. */
6710 validate_virtcol();
6711 coladvance(curwin->w_virtcol);
6712 }
6713 }
6714#endif
6715
6716#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6717 else if (varp == &p_csqf)
6718 {
6719 if (p_csqf != NULL)
6720 {
6721 p = p_csqf;
6722 while (*p != NUL)
6723 {
6724 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6725 || p[1] == NUL
6726 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6727 || (p[2] != NUL && p[2] != ','))
6728 {
6729 errmsg = e_invarg;
6730 break;
6731 }
6732 else if (p[2] == NUL)
6733 break;
6734 else
6735 p += 3;
6736 }
6737 }
6738 }
6739#endif
6740
6741 /* Options that are a list of flags. */
6742 else
6743 {
6744 p = NULL;
6745 if (varp == &p_ww)
6746 p = (char_u *)WW_ALL;
6747 if (varp == &p_shm)
6748 p = (char_u *)SHM_ALL;
6749 else if (varp == &(p_cpo))
6750 p = (char_u *)CPO_ALL;
6751 else if (varp == &(curbuf->b_p_fo))
6752 p = (char_u *)FO_ALL;
6753 else if (varp == &p_mouse)
6754 {
6755#ifdef FEAT_MOUSE
6756 p = (char_u *)MOUSE_ALL;
6757#else
6758 if (*p_mouse != NUL)
6759 errmsg = (char_u *)N_("E538: No mouse support");
6760#endif
6761 }
6762#if defined(FEAT_GUI)
6763 else if (varp == &p_go)
6764 p = (char_u *)GO_ALL;
6765#endif
6766 if (p != NULL)
6767 {
6768 for (s = *varp; *s; ++s)
6769 if (vim_strchr(p, *s) == NULL)
6770 {
6771 errmsg = illegal_char(errbuf, *s);
6772 break;
6773 }
6774 }
6775 }
6776
6777 /*
6778 * If error detected, restore the previous value.
6779 */
6780 if (errmsg != NULL)
6781 {
6782 if (new_value_alloced)
6783 free_string_option(*varp);
6784 *varp = oldval;
6785 /*
6786 * When resetting some values, need to act on it.
6787 */
6788 if (did_chartab)
6789 (void)init_chartab();
6790 if (varp == &p_hl)
6791 (void)highlight_changed();
6792 }
6793 else
6794 {
6795#ifdef FEAT_EVAL
6796 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006797 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006798#endif
6799 /*
6800 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006801 * Use "free_oldval", because recursiveness may change the flags under
6802 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00006803 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00006804 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006805 free_string_option(oldval);
6806 if (new_value_alloced)
6807 options[opt_idx].flags |= P_ALLOCED;
6808 else
6809 options[opt_idx].flags &= ~P_ALLOCED;
6810
6811 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006812 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813 {
6814 /* global option with local value set to use global value; free
6815 * the local value and make it empty */
6816 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
6817 free_string_option(*(char_u **)p);
6818 *(char_u **)p = empty_option;
6819 }
6820
6821 /* May set global value for local option. */
6822 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
6823 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006824
6825#ifdef FEAT_AUTOCMD
6826 /*
6827 * Trigger the autocommand only after setting the flags.
6828 */
6829# ifdef FEAT_SYN_HL
6830 /* When 'syntax' is set, load the syntax of that name */
6831 if (varp == &(curbuf->b_p_syn))
6832 {
6833 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
6834 curbuf->b_fname, TRUE, curbuf);
6835 }
6836# endif
6837 else if (varp == &(curbuf->b_p_ft))
6838 {
6839 /* 'filetype' is set, trigger the FileType autocommand */
6840 did_filetype = TRUE;
6841 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
6842 curbuf->b_fname, TRUE, curbuf);
6843 }
6844#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006845#ifdef FEAT_SPELL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00006846 if (varp == &(curbuf->b_p_spl))
6847 {
6848 char_u fname[200];
6849
6850 /*
6851 * Source the spell/LANG.vim in 'runtimepath'.
6852 * They could set 'spellcapcheck' depending on the language.
6853 * Use the first name in 'spelllang' up to '_region' or
6854 * '.encoding'.
6855 */
6856 for (p = curbuf->b_p_spl; *p != NUL; ++p)
6857 if (vim_strchr((char_u *)"_.,", *p) != NULL)
6858 break;
6859 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
6860 (int)(p - curbuf->b_p_spl), curbuf->b_p_spl);
6861 source_runtime(fname, TRUE);
6862 }
6863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006864 }
6865
6866#ifdef FEAT_MOUSE
6867 if (varp == &p_mouse)
6868 {
6869# ifdef FEAT_MOUSE_TTY
6870 if (*p_mouse == NUL)
6871 mch_setmouse(FALSE); /* switch mouse off */
6872 else
6873# endif
6874 setmouse(); /* in case 'mouse' changed */
6875 }
6876#endif
6877
6878 if (curwin->w_curswant != MAXCOL)
6879 curwin->w_set_curswant = TRUE; /* in case 'showbreak' changed */
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006880#ifdef FEAT_GUI
6881 /* check redraw when it's not a GUI option or the GUI is active. */
6882 if (!redraw_gui_only || gui.in_use)
6883#endif
6884 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885
6886 return errmsg;
6887}
6888
6889/*
6890 * Handle setting 'listchars' or 'fillchars'.
6891 * Returns error message, NULL if it's OK.
6892 */
6893 static char_u *
6894set_chars_option(varp)
6895 char_u **varp;
6896{
6897 int round, i, len, entries;
6898 char_u *p, *s;
6899 int c1, c2 = 0;
6900 struct charstab
6901 {
6902 int *cp;
6903 char *name;
6904 };
6905#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6906 static struct charstab filltab[] =
6907 {
6908 {&fill_stl, "stl"},
6909 {&fill_stlnc, "stlnc"},
6910 {&fill_vert, "vert"},
6911 {&fill_fold, "fold"},
6912 {&fill_diff, "diff"},
6913 };
6914#endif
6915 static struct charstab lcstab[] =
6916 {
6917 {&lcs_eol, "eol"},
6918 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006919 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920 {&lcs_prec, "precedes"},
6921 {&lcs_tab2, "tab"},
6922 {&lcs_trail, "trail"},
6923 };
6924 struct charstab *tab;
6925
6926#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6927 if (varp == &p_lcs)
6928#endif
6929 {
6930 tab = lcstab;
6931 entries = sizeof(lcstab) / sizeof(struct charstab);
6932 }
6933#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6934 else
6935 {
6936 tab = filltab;
6937 entries = sizeof(filltab) / sizeof(struct charstab);
6938 }
6939#endif
6940
6941 /* first round: check for valid value, second round: assign values */
6942 for (round = 0; round <= 1; ++round)
6943 {
6944 if (round)
6945 {
6946 /* After checking that the value is valid: set defaults: space for
6947 * 'fillchars', NUL for 'listchars' */
6948 for (i = 0; i < entries; ++i)
6949 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
6950 if (varp == &p_lcs)
6951 lcs_tab1 = NUL;
6952#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6953 else
6954 fill_diff = '-';
6955#endif
6956 }
6957 p = *varp;
6958 while (*p)
6959 {
6960 for (i = 0; i < entries; ++i)
6961 {
6962 len = (int)STRLEN(tab[i].name);
6963 if (STRNCMP(p, tab[i].name, len) == 0
6964 && p[len] == ':'
6965 && p[len + 1] != NUL)
6966 {
6967 s = p + len + 1;
6968#ifdef FEAT_MBYTE
6969 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006970 if (mb_char2cells(c1) > 1)
6971 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972#else
6973 c1 = *s++;
6974#endif
6975 if (tab[i].cp == &lcs_tab2)
6976 {
6977 if (*s == NUL)
6978 continue;
6979#ifdef FEAT_MBYTE
6980 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00006981 if (mb_char2cells(c2) > 1)
6982 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983#else
6984 c2 = *s++;
6985#endif
6986 }
6987 if (*s == ',' || *s == NUL)
6988 {
6989 if (round)
6990 {
6991 if (tab[i].cp == &lcs_tab2)
6992 {
6993 lcs_tab1 = c1;
6994 lcs_tab2 = c2;
6995 }
6996 else
6997 *(tab[i].cp) = c1;
6998
6999 }
7000 p = s;
7001 break;
7002 }
7003 }
7004 }
7005
7006 if (i == entries)
7007 return e_invarg;
7008 if (*p == ',')
7009 ++p;
7010 }
7011 }
7012
7013 return NULL; /* no error */
7014}
7015
7016#ifdef FEAT_STL_OPT
7017/*
7018 * Check validity of options with the 'statusline' format.
7019 * Return error message or NULL.
7020 */
7021 char_u *
7022check_stl_option(s)
7023 char_u *s;
7024{
7025 int itemcnt = 0;
7026 int groupdepth = 0;
7027 static char_u errbuf[80];
7028
7029 while (*s && itemcnt < STL_MAX_ITEM)
7030 {
7031 /* Check for valid keys after % sequences */
7032 while (*s && *s != '%')
7033 s++;
7034 if (!*s)
7035 break;
7036 s++;
7037 if (*s != '%' && *s != ')')
7038 ++itemcnt;
7039 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7040 {
7041 s++;
7042 continue;
7043 }
7044 if (*s == ')')
7045 {
7046 s++;
7047 if (--groupdepth < 0)
7048 break;
7049 continue;
7050 }
7051 if (*s == '-')
7052 s++;
7053 while (VIM_ISDIGIT(*s))
7054 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007055 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056 continue;
7057 if (*s == '.')
7058 {
7059 s++;
7060 while (*s && VIM_ISDIGIT(*s))
7061 s++;
7062 }
7063 if (*s == '(')
7064 {
7065 groupdepth++;
7066 continue;
7067 }
7068 if (vim_strchr(STL_ALL, *s) == NULL)
7069 {
7070 return illegal_char(errbuf, *s);
7071 }
7072 if (*s == '{')
7073 {
7074 s++;
7075 while (*s != '}' && *s)
7076 s++;
7077 if (*s != '}')
7078 return (char_u *)N_("E540: Unclosed expression sequence");
7079 }
7080 }
7081 if (itemcnt >= STL_MAX_ITEM)
7082 return (char_u *)N_("E541: too many items");
7083 if (groupdepth != 0)
7084 return (char_u *)N_("E542: unbalanced groups");
7085 return NULL;
7086}
7087#endif
7088
7089#ifdef FEAT_CLIPBOARD
7090/*
7091 * Extract the items in the 'clipboard' option and set global values.
7092 */
7093 static char_u *
7094check_clipboard_option()
7095{
7096 int new_unnamed = FALSE;
7097 int new_autoselect = FALSE;
7098 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007099 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 regprog_T *new_exclude_prog = NULL;
7101 char_u *errmsg = NULL;
7102 char_u *p;
7103
7104 for (p = p_cb; *p != NUL; )
7105 {
7106 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7107 {
7108 new_unnamed = TRUE;
7109 p += 7;
7110 }
7111 else if (STRNCMP(p, "autoselect", 10) == 0
7112 && (p[10] == ',' || p[10] == NUL))
7113 {
7114 new_autoselect = TRUE;
7115 p += 10;
7116 }
7117 else if (STRNCMP(p, "autoselectml", 12) == 0
7118 && (p[12] == ',' || p[12] == NUL))
7119 {
7120 new_autoselectml = TRUE;
7121 p += 12;
7122 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007123 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7124 {
7125 new_html = TRUE;
7126 p += 4;
7127 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007128 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7129 {
7130 p += 8;
7131 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7132 if (new_exclude_prog == NULL)
7133 errmsg = e_invarg;
7134 break;
7135 }
7136 else
7137 {
7138 errmsg = e_invarg;
7139 break;
7140 }
7141 if (*p == ',')
7142 ++p;
7143 }
7144 if (errmsg == NULL)
7145 {
7146 clip_unnamed = new_unnamed;
7147 clip_autoselect = new_autoselect;
7148 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007149 clip_html = new_html;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007150 vim_free(clip_exclude_prog);
7151 clip_exclude_prog = new_exclude_prog;
7152 }
7153 else
7154 vim_free(new_exclude_prog);
7155
7156 return errmsg;
7157}
7158#endif
7159
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007160#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007161/*
7162 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7163 * Return error message when failed, NULL when OK.
7164 */
7165 static char_u *
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007166compile_cap_prog(buf)
7167 buf_T *buf;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007168{
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007169 regprog_T *rp = buf->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007170 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007171
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007172 if (*buf->b_p_spc == NUL)
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00007173 buf->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007174 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007175 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007176 /* Prepend a ^ so that we only match at one column */
7177 re = concat_str((char_u *)"^", buf->b_p_spc);
7178 if (re != NULL)
7179 {
7180 buf->b_cap_prog = vim_regcomp(re, RE_MAGIC);
7181 if (buf->b_cap_prog == NULL)
7182 {
7183 buf->b_cap_prog = rp; /* restore the previous program */
7184 return e_invarg;
7185 }
7186 vim_free(re);
7187 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007188 }
7189
7190 vim_free(rp);
7191 return NULL;
7192}
7193#endif
7194
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007195#if defined(FEAT_EVAL) || defined(PROTO)
7196/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007197 * Set the scriptID for an option, taking care of setting the buffer- or
7198 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007199 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007200 static void
7201set_option_scriptID_idx(opt_idx, opt_flags, id)
7202 int opt_idx;
7203 int opt_flags;
7204 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007205{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007206 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7207 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007208
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007209 /* Remember where the option was set. For local options need to do that
7210 * in the buffer or window structure. */
7211 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007212 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007213 if (both || (opt_flags & OPT_LOCAL))
7214 {
7215 if (indir & PV_BUF)
7216 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7217 else if (indir & PV_WIN)
7218 curwin->w_p_scriptID[indir & PV_MASK] = id;
7219 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007220}
7221#endif
7222
Bram Moolenaar071d4272004-06-13 20:20:40 +00007223/*
7224 * Set the value of a boolean option, and take care of side effects.
7225 * Returns NULL for success, or an error message for an error.
7226 */
7227 static char_u *
7228set_bool_option(opt_idx, varp, value, opt_flags)
7229 int opt_idx; /* index in options[] table */
7230 char_u *varp; /* pointer to the option variable */
7231 int value; /* new value */
7232 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7233{
7234 int old_value = *(int *)varp;
7235
Bram Moolenaar071d4272004-06-13 20:20:40 +00007236 /* Disallow changing some options from secure mode */
7237 if ((secure
7238#ifdef HAVE_SANDBOX
7239 || sandbox != 0
7240#endif
7241 ) && (options[opt_idx].flags & P_SECURE))
7242 return e_secure;
7243
7244 *(int *)varp = value; /* set the new value */
7245#ifdef FEAT_EVAL
7246 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007247 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007248#endif
7249
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007250#ifdef FEAT_GUI
7251 need_mouse_correct = TRUE;
7252#endif
7253
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254 /* May set global value for local option. */
7255 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7256 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7257
7258 /*
7259 * Handle side effects of changing a bool option.
7260 */
7261
7262 /* 'compatible' */
7263 if ((int *)varp == &p_cp)
7264 {
7265 compatible_set();
7266 }
7267
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007268 /* 'list', 'number' */
7269 else if ((int *)varp == &curwin->w_p_list
Bram Moolenaar64486672010-05-16 15:46:46 +02007270 || (int *)varp == &curwin->w_p_nu
7271 || (int *)varp == &curwin->w_p_rnu)
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007272 {
7273 if (curwin->w_curswant != MAXCOL)
7274 curwin->w_set_curswant = TRUE;
Bram Moolenaar64486672010-05-16 15:46:46 +02007275
7276 /* If 'number' is set, reset 'relativenumber'. */
7277 /* If 'relativenumber' is set, reset 'number'. */
7278 if ((int *)varp == &curwin->w_p_nu && curwin->w_p_nu)
7279 curwin->w_p_rnu = FALSE;
7280 if ((int *)varp == &curwin->w_p_rnu && curwin->w_p_rnu)
7281 curwin->w_p_nu = FALSE;
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007282 }
7283
Bram Moolenaar071d4272004-06-13 20:20:40 +00007284 else if ((int *)varp == &curbuf->b_p_ro)
7285 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007286 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007287 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7288 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007289
7290 /* when 'readonly' is set may give W10 again */
7291 if (curbuf->b_p_ro)
7292 curbuf->b_did_warn = FALSE;
7293
Bram Moolenaar071d4272004-06-13 20:20:40 +00007294#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007295 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296#endif
7297 }
7298
7299#ifdef FEAT_TITLE
7300 /* when 'modifiable' is changed, redraw the window title */
7301 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007302 {
7303 redraw_titles();
7304 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007305 /* when 'endofline' is changed, redraw the window title */
7306 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007307 {
7308 redraw_titles();
7309 }
7310# ifdef FEAT_MBYTE
7311 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007312 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007313 {
7314 redraw_titles();
7315 }
7316# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317#endif
7318
7319 /* when 'bin' is set also set some other options */
7320 else if ((int *)varp == &curbuf->b_p_bin)
7321 {
7322 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7323#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007324 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325#endif
7326 }
7327
7328#ifdef FEAT_AUTOCMD
7329 /* when 'buflisted' changes, trigger autocommands */
7330 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7331 {
7332 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7333 NULL, NULL, TRUE, curbuf);
7334 }
7335#endif
7336
7337 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7338 else if ((int *)varp == &curbuf->b_p_swf)
7339 {
7340 if (curbuf->b_p_swf && p_uc)
7341 ml_open_file(curbuf); /* create the swap file */
7342 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007343 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7344 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007345 mf_close_file(curbuf, TRUE); /* remove the swap file */
7346 }
7347
7348 /* when 'terse' is set change 'shortmess' */
7349 else if ((int *)varp == &p_terse)
7350 {
7351 char_u *p;
7352
7353 p = vim_strchr(p_shm, SHM_SEARCH);
7354
7355 /* insert 's' in p_shm */
7356 if (p_terse && p == NULL)
7357 {
7358 STRCPY(IObuff, p_shm);
7359 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007360 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007361 }
7362 /* remove 's' from p_shm */
7363 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007364 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007365 }
7366
7367 /* when 'paste' is set or reset also change other options */
7368 else if ((int *)varp == &p_paste)
7369 {
7370 paste_option_changed();
7371 }
7372
7373 /* when 'insertmode' is set from an autocommand need to do work here */
7374 else if ((int *)varp == &p_im)
7375 {
7376 if (p_im)
7377 {
7378 if ((State & INSERT) == 0)
7379 need_start_insertmode = TRUE;
7380 stop_insert_mode = FALSE;
7381 }
7382 else
7383 {
7384 need_start_insertmode = FALSE;
7385 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007386 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007387 clear_cmdline = TRUE; /* remove "(insert)" */
7388 restart_edit = 0;
7389 }
7390 }
7391
7392 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7393 else if ((int *)varp == &p_ic && p_hls)
7394 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007395 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007396 }
7397
7398#ifdef FEAT_SEARCH_EXTRA
7399 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7400 else if ((int *)varp == &p_hls)
7401 {
7402 no_hlsearch = FALSE;
7403 }
7404#endif
7405
7406#ifdef FEAT_SCROLLBIND
7407 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7408 * at the end of normal_cmd() */
7409 else if ((int *)varp == &curwin->w_p_scb)
7410 {
7411 if (curwin->w_p_scb)
7412 do_check_scrollbind(FALSE);
7413 }
7414#endif
7415
7416#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7417 /* There can be only one window with 'previewwindow' set. */
7418 else if ((int *)varp == &curwin->w_p_pvw)
7419 {
7420 if (curwin->w_p_pvw)
7421 {
7422 win_T *win;
7423
7424 for (win = firstwin; win != NULL; win = win->w_next)
7425 if (win->w_p_pvw && win != curwin)
7426 {
7427 curwin->w_p_pvw = FALSE;
7428 return (char_u *)N_("E590: A preview window already exists");
7429 }
7430 }
7431 }
7432#endif
7433
7434 /* when 'textmode' is set or reset also change 'fileformat' */
7435 else if ((int *)varp == &curbuf->b_p_tx)
7436 {
7437 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7438 }
7439
7440 /* when 'textauto' is set or reset also change 'fileformats' */
7441 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007442 set_string_option_direct((char_u *)"ffs", -1,
7443 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007444 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445
7446 /*
7447 * When 'lisp' option changes include/exclude '-' in
7448 * keyword characters.
7449 */
7450#ifdef FEAT_LISP
7451 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7452 {
7453 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7454 }
7455#endif
7456
7457#ifdef FEAT_TITLE
7458 /* when 'title' changed, may need to change the title; same for 'icon' */
7459 else if ((int *)varp == &p_title)
7460 {
7461 did_set_title(FALSE);
7462 }
7463
7464 else if ((int *)varp == &p_icon)
7465 {
7466 did_set_title(TRUE);
7467 }
7468#endif
7469
7470 else if ((int *)varp == &curbuf->b_changed)
7471 {
7472 if (!value)
7473 save_file_ff(curbuf); /* Buffer is unchanged */
7474#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007475 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007476#endif
7477#ifdef FEAT_AUTOCMD
7478 modified_was_set = value;
7479#endif
7480 }
7481
7482#ifdef BACKSLASH_IN_FILENAME
7483 else if ((int *)varp == &p_ssl)
7484 {
7485 if (p_ssl)
7486 {
7487 psepc = '/';
7488 psepcN = '\\';
7489 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490 }
7491 else
7492 {
7493 psepc = '\\';
7494 psepcN = '/';
7495 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 }
7497
7498 /* need to adjust the file name arguments and buffer names. */
7499 buflist_slash_adjust();
7500 alist_slash_adjust();
7501# ifdef FEAT_EVAL
7502 scriptnames_slash_adjust();
7503# endif
7504 }
7505#endif
7506
7507 /* If 'wrap' is set, set w_leftcol to zero. */
7508 else if ((int *)varp == &curwin->w_p_wrap)
7509 {
7510 if (curwin->w_p_wrap)
7511 curwin->w_leftcol = 0;
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007512 if (curwin->w_curswant != MAXCOL)
7513 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 }
7515
7516#ifdef FEAT_WINDOWS
7517 else if ((int *)varp == &p_ea)
7518 {
7519 if (p_ea && !old_value)
7520 win_equal(curwin, FALSE, 0);
7521 }
7522#endif
7523
7524 else if ((int *)varp == &p_wiv)
7525 {
7526 /*
7527 * When 'weirdinvert' changed, set/reset 't_xs'.
7528 * Then set 'weirdinvert' according to value of 't_xs'.
7529 */
7530 if (p_wiv && !old_value)
7531 T_XS = (char_u *)"y";
7532 else if (!p_wiv && old_value)
7533 T_XS = empty_option;
7534 p_wiv = (*T_XS != NUL);
7535 }
7536
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007537#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007538 else if ((int *)varp == &p_beval)
7539 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540 if (p_beval == TRUE)
7541 gui_mch_enable_beval_area(balloonEval);
7542 else
7543 gui_mch_disable_beval_area(balloonEval);
7544 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007545#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007547#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 else if ((int *)varp == &p_acd)
7549 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007550 /* Change directories when the 'acd' option is set now. */
7551 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007552 }
7553#endif
7554
7555#ifdef FEAT_DIFF
7556 /* 'diff' */
7557 else if ((int *)varp == &curwin->w_p_diff)
7558 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007559 /* May add or remove the buffer from the list of diff buffers. */
7560 diff_buf_adjust(curwin);
7561# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007562 if (foldmethodIsDiff(curwin))
7563 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007564# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007565 }
7566#endif
7567
7568#ifdef USE_IM_CONTROL
7569 /* 'imdisable' */
7570 else if ((int *)varp == &p_imdisable)
7571 {
7572 /* Only de-activate it here, it will be enabled when changing mode. */
7573 if (p_imdisable)
7574 im_set_active(FALSE);
7575 }
7576#endif
7577
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007578#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007579 /* 'spell' */
7580 else if ((int *)varp == &curwin->w_p_spell)
7581 {
7582 if (curwin->w_p_spell)
7583 {
7584 char_u *errmsg = did_set_spelllang(curbuf);
Bram Moolenaar3638c682005-06-08 22:05:14 +00007585
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007586 if (errmsg != NULL)
7587 EMSG(_(errmsg));
7588 }
7589 }
7590#endif
7591
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592#ifdef FEAT_FKMAP
7593 else if ((int *)varp == &p_altkeymap)
7594 {
7595 if (old_value != p_altkeymap)
7596 {
7597 if (!p_altkeymap)
7598 {
7599 p_hkmap = p_fkmap;
7600 p_fkmap = 0;
7601 }
7602 else
7603 {
7604 p_fkmap = p_hkmap;
7605 p_hkmap = 0;
7606 }
7607 (void)init_chartab();
7608 }
7609 }
7610
7611 /*
7612 * In case some second language keymapping options have changed, check
7613 * and correct the setting in a consistent way.
7614 */
7615
7616 /*
7617 * If hkmap or fkmap are set, reset Arabic keymapping.
7618 */
7619 if ((p_hkmap || p_fkmap) && p_altkeymap)
7620 {
7621 p_altkeymap = p_fkmap;
7622# ifdef FEAT_ARABIC
7623 curwin->w_p_arab = FALSE;
7624# endif
7625 (void)init_chartab();
7626 }
7627
7628 /*
7629 * If hkmap set, reset Farsi keymapping.
7630 */
7631 if (p_hkmap && p_altkeymap)
7632 {
7633 p_altkeymap = 0;
7634 p_fkmap = 0;
7635# ifdef FEAT_ARABIC
7636 curwin->w_p_arab = FALSE;
7637# endif
7638 (void)init_chartab();
7639 }
7640
7641 /*
7642 * If fkmap set, reset Hebrew keymapping.
7643 */
7644 if (p_fkmap && !p_altkeymap)
7645 {
7646 p_altkeymap = 1;
7647 p_hkmap = 0;
7648# ifdef FEAT_ARABIC
7649 curwin->w_p_arab = FALSE;
7650# endif
7651 (void)init_chartab();
7652 }
7653#endif
7654
7655#ifdef FEAT_ARABIC
7656 if ((int *)varp == &curwin->w_p_arab)
7657 {
7658 if (curwin->w_p_arab)
7659 {
7660 /*
7661 * 'arabic' is set, handle various sub-settings.
7662 */
7663 if (!p_tbidi)
7664 {
7665 /* set rightleft mode */
7666 if (!curwin->w_p_rl)
7667 {
7668 curwin->w_p_rl = TRUE;
7669 changed_window_setting();
7670 }
7671
7672 /* Enable Arabic shaping (major part of what Arabic requires) */
7673 if (!p_arshape)
7674 {
7675 p_arshape = TRUE;
7676 redraw_later_clear();
7677 }
7678 }
7679
7680 /* Arabic requires a utf-8 encoding, inform the user if its not
7681 * set. */
7682 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007683 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00007684 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
7685
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007686 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00007687 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
7688#ifdef FEAT_EVAL
7689 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
7690#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007692
7693# ifdef FEAT_MBYTE
7694 /* set 'delcombine' */
7695 p_deco = TRUE;
7696# endif
7697
7698# ifdef FEAT_KEYMAP
7699 /* Force-set the necessary keymap for arabic */
7700 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
7701 OPT_LOCAL);
7702# endif
7703# ifdef FEAT_FKMAP
7704 p_altkeymap = 0;
7705 p_hkmap = 0;
7706 p_fkmap = 0;
7707 (void)init_chartab();
7708# endif
7709 }
7710 else
7711 {
7712 /*
7713 * 'arabic' is reset, handle various sub-settings.
7714 */
7715 if (!p_tbidi)
7716 {
7717 /* reset rightleft mode */
7718 if (curwin->w_p_rl)
7719 {
7720 curwin->w_p_rl = FALSE;
7721 changed_window_setting();
7722 }
7723
7724 /* 'arabicshape' isn't reset, it is a global option and
7725 * another window may still need it "on". */
7726 }
7727
7728 /* 'delcombine' isn't reset, it is a global option and another
7729 * window may still want it "on". */
7730
7731# ifdef FEAT_KEYMAP
7732 /* Revert to the default keymap */
7733 curbuf->b_p_iminsert = B_IMODE_NONE;
7734 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
7735# endif
7736 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007737 if (curwin->w_curswant != MAXCOL)
7738 curwin->w_set_curswant = TRUE;
7739 }
7740
7741 else if ((int *)varp == &p_arshape)
7742 {
7743 if (curwin->w_curswant != MAXCOL)
7744 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007745 }
7746#endif
7747
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00007748#ifdef FEAT_LINEBREAK
7749 if ((int *)varp == &curwin->w_p_lbr)
7750 {
7751 if (curwin->w_curswant != MAXCOL)
7752 curwin->w_set_curswant = TRUE;
7753 }
7754#endif
7755
7756#ifdef FEAT_RIGHTLEFT
7757 if ((int *)varp == &curwin->w_p_rl)
7758 {
7759 if (curwin->w_curswant != MAXCOL)
7760 curwin->w_set_curswant = TRUE;
7761 }
7762#endif
7763
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 /*
7765 * End of handling side effects for bool options.
7766 */
7767
7768 options[opt_idx].flags |= P_WAS_SET;
7769
7770 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar801f8b82009-07-29 13:42:05 +00007771
Bram Moolenaar071d4272004-06-13 20:20:40 +00007772 check_redraw(options[opt_idx].flags);
7773
7774 return NULL;
7775}
7776
7777/*
7778 * Set the value of a number option, and take care of side effects.
7779 * Returns NULL for success, or an error message for an error.
7780 */
7781 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00007782set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 int opt_idx; /* index in options[] table */
7784 char_u *varp; /* pointer to the option variable */
7785 long value; /* new value */
7786 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00007787 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007788 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
7789 OPT_MODELINE */
7790{
7791 char_u *errmsg = NULL;
7792 long old_value = *(long *)varp;
7793 long old_Rows = Rows; /* remember old Rows */
7794 long old_Columns = Columns; /* remember old Columns */
7795 long *pp = (long *)varp;
7796
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007797 /* Disallow changing some options from secure mode. */
7798 if ((secure
7799#ifdef HAVE_SANDBOX
7800 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007802 ) && (options[opt_idx].flags & P_SECURE))
7803 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007804
7805 *pp = value;
7806#ifdef FEAT_EVAL
7807 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007808 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007809#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007810#ifdef FEAT_GUI
7811 need_mouse_correct = TRUE;
7812#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007813
7814 if (curbuf->b_p_sw <= 0)
7815 {
7816 errmsg = e_positive;
7817 curbuf->b_p_sw = curbuf->b_p_ts;
7818 }
7819
7820 /*
7821 * Number options that need some action when changed
7822 */
7823#ifdef FEAT_WINDOWS
7824 if (pp == &p_wh || pp == &p_hh)
7825 {
7826 if (p_wh < 1)
7827 {
7828 errmsg = e_positive;
7829 p_wh = 1;
7830 }
7831 if (p_wmh > p_wh)
7832 {
7833 errmsg = e_winheight;
7834 p_wh = p_wmh;
7835 }
7836 if (p_hh < 0)
7837 {
7838 errmsg = e_positive;
7839 p_hh = 0;
7840 }
7841
7842 /* Change window height NOW */
7843 if (lastwin != firstwin)
7844 {
7845 if (pp == &p_wh && curwin->w_height < p_wh)
7846 win_setheight((int)p_wh);
7847 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
7848 win_setheight((int)p_hh);
7849 }
7850 }
7851
7852 /* 'winminheight' */
7853 else if (pp == &p_wmh)
7854 {
7855 if (p_wmh < 0)
7856 {
7857 errmsg = e_positive;
7858 p_wmh = 0;
7859 }
7860 if (p_wmh > p_wh)
7861 {
7862 errmsg = e_winheight;
7863 p_wmh = p_wh;
7864 }
7865 win_setminheight();
7866 }
7867
7868# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00007869 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870 {
7871 if (p_wiw < 1)
7872 {
7873 errmsg = e_positive;
7874 p_wiw = 1;
7875 }
7876 if (p_wmw > p_wiw)
7877 {
7878 errmsg = e_winwidth;
7879 p_wiw = p_wmw;
7880 }
7881
7882 /* Change window width NOW */
7883 if (lastwin != firstwin && curwin->w_width < p_wiw)
7884 win_setwidth((int)p_wiw);
7885 }
7886
7887 /* 'winminwidth' */
7888 else if (pp == &p_wmw)
7889 {
7890 if (p_wmw < 0)
7891 {
7892 errmsg = e_positive;
7893 p_wmw = 0;
7894 }
7895 if (p_wmw > p_wiw)
7896 {
7897 errmsg = e_winwidth;
7898 p_wmw = p_wiw;
7899 }
7900 win_setminheight();
7901 }
7902# endif
7903
7904#endif
7905
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02007906#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02007907 else if (pp == &curbuf->b_p_cm)
7908 {
7909 if (curbuf->b_p_cm < 0)
7910 {
7911 errmsg = e_positive;
7912 curbuf->b_p_cm = 0;
7913 }
7914 if (curbuf->b_p_cm > 1)
7915 {
7916 errmsg = e_invarg;
7917 curbuf->b_p_cm = 1;
7918 }
7919 if (curbuf->b_p_cm > 0 && blowfish_self_test() == FAIL)
7920 curbuf->b_p_cm = 0;
7921 }
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02007922#endif
Bram Moolenaar40e6a712010-05-16 22:32:54 +02007923
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924#ifdef FEAT_WINDOWS
7925 /* (re)set last window status line */
7926 else if (pp == &p_ls)
7927 {
7928 last_status(FALSE);
7929 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007930
7931 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00007932 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00007933 {
7934 shell_new_rows(); /* recompute window positions and heights */
7935 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936#endif
7937
7938#ifdef FEAT_GUI
7939 else if (pp == &p_linespace)
7940 {
Bram Moolenaar02743632005-07-25 20:42:36 +00007941 /* Recompute gui.char_height and resize the Vim window to keep the
7942 * same number of lines. */
7943 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00007944 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 }
7946#endif
7947
7948#ifdef FEAT_FOLDING
7949 /* 'foldlevel' */
7950 else if (pp == &curwin->w_p_fdl)
7951 {
7952 if (curwin->w_p_fdl < 0)
7953 curwin->w_p_fdl = 0;
7954 newFoldLevel();
7955 }
7956
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007957 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 else if (pp == &curwin->w_p_fml)
7959 {
7960 foldUpdateAll(curwin);
7961 }
7962
7963 /* 'foldnestmax' */
7964 else if (pp == &curwin->w_p_fdn)
7965 {
7966 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
7967 foldUpdateAll(curwin);
7968 }
7969
7970 /* 'foldcolumn' */
7971 else if (pp == &curwin->w_p_fdc)
7972 {
7973 if (curwin->w_p_fdc < 0)
7974 {
7975 errmsg = e_positive;
7976 curwin->w_p_fdc = 0;
7977 }
7978 else if (curwin->w_p_fdc > 12)
7979 {
7980 errmsg = e_invarg;
7981 curwin->w_p_fdc = 12;
7982 }
7983 }
7984
7985 /* 'shiftwidth' or 'tabstop' */
7986 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
7987 {
7988 if (foldmethodIsIndent(curwin))
7989 foldUpdateAll(curwin);
7990 }
7991#endif /* FEAT_FOLDING */
7992
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007993#ifdef FEAT_MBYTE
7994 /* 'maxcombine' */
7995 else if (pp == &p_mco)
7996 {
7997 if (p_mco > MAX_MCO)
7998 p_mco = MAX_MCO;
7999 else if (p_mco < 0)
8000 p_mco = 0;
8001 screenclear(); /* will re-allocate the screen */
8002 }
8003#endif
8004
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 else if (pp == &curbuf->b_p_iminsert)
8006 {
8007 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8008 {
8009 errmsg = e_invarg;
8010 curbuf->b_p_iminsert = B_IMODE_NONE;
8011 }
8012 p_iminsert = curbuf->b_p_iminsert;
8013 if (termcap_active) /* don't do this in the alternate screen */
8014 showmode();
8015#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8016 /* Show/unshow value of 'keymap' in status lines. */
8017 status_redraw_curbuf();
8018#endif
8019 }
8020
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008021 else if (pp == &p_window)
8022 {
8023 if (p_window < 1)
8024 p_window = 1;
8025 else if (p_window >= Rows)
8026 p_window = Rows - 1;
8027 }
8028
Bram Moolenaar071d4272004-06-13 20:20:40 +00008029 else if (pp == &curbuf->b_p_imsearch)
8030 {
8031 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8032 {
8033 errmsg = e_invarg;
8034 curbuf->b_p_imsearch = B_IMODE_NONE;
8035 }
8036 p_imsearch = curbuf->b_p_imsearch;
8037 }
8038
8039#ifdef FEAT_TITLE
8040 /* if 'titlelen' has changed, redraw the title */
8041 else if (pp == &p_titlelen)
8042 {
8043 if (p_titlelen < 0)
8044 {
8045 errmsg = e_positive;
8046 p_titlelen = 85;
8047 }
8048 if (starting != NO_SCREEN && old_value != p_titlelen)
8049 need_maketitle = TRUE;
8050 }
8051#endif
8052
8053 /* if p_ch changed value, change the command line height */
8054 else if (pp == &p_ch)
8055 {
8056 if (p_ch < 1)
8057 {
8058 errmsg = e_positive;
8059 p_ch = 1;
8060 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008061 if (p_ch > Rows - min_rows() + 1)
8062 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008063
8064 /* Only compute the new window layout when startup has been
8065 * completed. Otherwise the frame sizes may be wrong. */
8066 if (p_ch != old_value && full_screen
8067#ifdef FEAT_GUI
8068 && !gui.starting
8069#endif
8070 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008071 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072 }
8073
8074 /* when 'updatecount' changes from zero to non-zero, open swap files */
8075 else if (pp == &p_uc)
8076 {
8077 if (p_uc < 0)
8078 {
8079 errmsg = e_positive;
8080 p_uc = 100;
8081 }
8082 if (p_uc && !old_value)
8083 ml_open_files();
8084 }
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008085#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008086 else if (pp == &p_mzq)
8087 mzvim_reset_timer();
8088#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008089
8090 /* sync undo before 'undolevels' changes */
8091 else if (pp == &p_ul)
8092 {
8093 /* use the old value, otherwise u_sync() may not work properly */
8094 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008095 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008096 p_ul = value;
8097 }
8098
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008099#ifdef FEAT_LINEBREAK
8100 /* 'numberwidth' must be positive */
8101 else if (pp == &curwin->w_p_nuw)
8102 {
8103 if (curwin->w_p_nuw < 1)
8104 {
8105 errmsg = e_positive;
8106 curwin->w_p_nuw = 1;
8107 }
8108 if (curwin->w_p_nuw > 10)
8109 {
8110 errmsg = e_invarg;
8111 curwin->w_p_nuw = 10;
8112 }
8113 curwin->w_nrwidth_line_count = 0;
8114 }
8115#endif
8116
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 /*
8118 * Check the bounds for numeric options here
8119 */
8120 if (Rows < min_rows() && full_screen)
8121 {
8122 if (errbuf != NULL)
8123 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008124 vim_snprintf((char *)errbuf, errbuflen,
8125 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 errmsg = errbuf;
8127 }
8128 Rows = min_rows();
8129 }
8130 if (Columns < MIN_COLUMNS && full_screen)
8131 {
8132 if (errbuf != NULL)
8133 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008134 vim_snprintf((char *)errbuf, errbuflen,
8135 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136 errmsg = errbuf;
8137 }
8138 Columns = MIN_COLUMNS;
8139 }
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00008140 /* Limit the values to avoid an overflow in Rows * Columns. */
8141 if (Columns > 10000)
8142 Columns = 10000;
8143 if (Rows > 1000)
8144 Rows = 1000;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145
8146#ifdef DJGPP
8147 /* avoid a crash by checking for a too large value of 'columns' */
8148 if (old_Columns != Columns && full_screen && term_console)
8149 mch_check_columns();
8150#endif
8151
8152 /*
8153 * If the screen (shell) height has been changed, assume it is the
8154 * physical screenheight.
8155 */
8156 if (old_Rows != Rows || old_Columns != Columns)
8157 {
8158 /* Changing the screen size is not allowed while updating the screen. */
8159 if (updating_screen)
8160 *pp = old_value;
8161 else if (full_screen
8162#ifdef FEAT_GUI
8163 && !gui.starting
8164#endif
8165 )
8166 set_shellsize((int)Columns, (int)Rows, TRUE);
8167 else
8168 {
8169 /* Postpone the resizing; check the size and cmdline position for
8170 * messages. */
8171 check_shellsize();
8172 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8173 cmdline_row = Rows - p_ch;
8174 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008175 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008176 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177 }
8178
8179 if (curbuf->b_p_sts < 0)
8180 {
8181 errmsg = e_positive;
8182 curbuf->b_p_sts = 0;
8183 }
8184 if (curbuf->b_p_ts <= 0)
8185 {
8186 errmsg = e_positive;
8187 curbuf->b_p_ts = 8;
8188 }
8189 if (curbuf->b_p_tw < 0)
8190 {
8191 errmsg = e_positive;
8192 curbuf->b_p_tw = 0;
8193 }
8194 if (p_tm < 0)
8195 {
8196 errmsg = e_positive;
8197 p_tm = 0;
8198 }
8199 if ((curwin->w_p_scr <= 0
8200 || (curwin->w_p_scr > curwin->w_height
8201 && curwin->w_height > 0))
8202 && full_screen)
8203 {
8204 if (pp == &(curwin->w_p_scr))
8205 {
8206 if (curwin->w_p_scr != 0)
8207 errmsg = e_scroll;
8208 win_comp_scroll(curwin);
8209 }
8210 /* If 'scroll' became invalid because of a side effect silently adjust
8211 * it. */
8212 else if (curwin->w_p_scr <= 0)
8213 curwin->w_p_scr = 1;
8214 else /* curwin->w_p_scr > curwin->w_height */
8215 curwin->w_p_scr = curwin->w_height;
8216 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008217 if (p_hi < 0)
8218 {
8219 errmsg = e_positive;
8220 p_hi = 0;
8221 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 if (p_report < 0)
8223 {
8224 errmsg = e_positive;
8225 p_report = 1;
8226 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008227 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008228 {
8229 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8230 p_sj = Rows / 2;
8231 else
8232 {
8233 errmsg = e_scroll;
8234 p_sj = 1;
8235 }
8236 }
8237 if (p_so < 0 && full_screen)
8238 {
8239 errmsg = e_scroll;
8240 p_so = 0;
8241 }
8242 if (p_siso < 0 && full_screen)
8243 {
8244 errmsg = e_positive;
8245 p_siso = 0;
8246 }
8247#ifdef FEAT_CMDWIN
8248 if (p_cwh < 1)
8249 {
8250 errmsg = e_positive;
8251 p_cwh = 1;
8252 }
8253#endif
8254 if (p_ut < 0)
8255 {
8256 errmsg = e_positive;
8257 p_ut = 2000;
8258 }
8259 if (p_ss < 0)
8260 {
8261 errmsg = e_positive;
8262 p_ss = 0;
8263 }
8264
8265 /* May set global value for local option. */
8266 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8267 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8268
8269 options[opt_idx].flags |= P_WAS_SET;
8270
8271 comp_col(); /* in case 'columns' or 'ls' changed */
8272 if (curwin->w_curswant != MAXCOL)
8273 curwin->w_set_curswant = TRUE; /* in case 'tabstop' changed */
8274 check_redraw(options[opt_idx].flags);
8275
8276 return errmsg;
8277}
8278
8279/*
8280 * Called after an option changed: check if something needs to be redrawn.
8281 */
8282 static void
8283check_redraw(flags)
8284 long_u flags;
8285{
8286 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
8287 int clear = (flags & P_RCLR) == P_RCLR;
8288 int all = ((flags & P_RALL) == P_RALL || clear);
8289
8290#ifdef FEAT_WINDOWS
8291 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8292 status_redraw_all();
8293#endif
8294
8295 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8296 changed_window_setting();
8297 if (flags & P_RBUF)
8298 redraw_curbuf_later(NOT_VALID);
8299 if (clear)
8300 redraw_all_later(CLEAR);
8301 else if (all)
8302 redraw_all_later(NOT_VALID);
8303}
8304
8305/*
8306 * Find index for option 'arg'.
8307 * Return -1 if not found.
8308 */
8309 static int
8310findoption(arg)
8311 char_u *arg;
8312{
8313 int opt_idx;
8314 char *s, *p;
8315 static short quick_tab[27] = {0, 0}; /* quick access table */
8316 int is_term_opt;
8317
8318 /*
8319 * For first call: Initialize the quick-access table.
8320 * It contains the index for the first option that starts with a certain
8321 * letter. There are 26 letters, plus the first "t_" option.
8322 */
8323 if (quick_tab[1] == 0)
8324 {
8325 p = options[0].fullname;
8326 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8327 {
8328 if (s[0] != p[0])
8329 {
8330 if (s[0] == 't' && s[1] == '_')
8331 quick_tab[26] = opt_idx;
8332 else
8333 quick_tab[CharOrdLow(s[0])] = opt_idx;
8334 }
8335 p = s;
8336 }
8337 }
8338
8339 /*
8340 * Check for name starting with an illegal character.
8341 */
8342#ifdef EBCDIC
8343 if (!islower(arg[0]))
8344#else
8345 if (arg[0] < 'a' || arg[0] > 'z')
8346#endif
8347 return -1;
8348
8349 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8350 if (is_term_opt)
8351 opt_idx = quick_tab[26];
8352 else
8353 opt_idx = quick_tab[CharOrdLow(arg[0])];
8354 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8355 {
8356 if (STRCMP(arg, s) == 0) /* match full name */
8357 break;
8358 }
8359 if (s == NULL && !is_term_opt)
8360 {
8361 opt_idx = quick_tab[CharOrdLow(arg[0])];
8362 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8363 {
8364 s = options[opt_idx].shortname;
8365 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8366 break;
8367 s = NULL;
8368 }
8369 }
8370 if (s == NULL)
8371 opt_idx = -1;
8372 return opt_idx;
8373}
8374
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008375#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376/*
8377 * Get the value for an option.
8378 *
8379 * Returns:
8380 * Number or Toggle option: 1, *numval gets value.
8381 * String option: 0, *stringval gets allocated string.
8382 * Hidden Number or Toggle option: -1.
8383 * hidden String option: -2.
8384 * unknown option: -3.
8385 */
8386 int
8387get_option_value(name, numval, stringval, opt_flags)
8388 char_u *name;
8389 long *numval;
8390 char_u **stringval; /* NULL when only checking existance */
8391 int opt_flags;
8392{
8393 int opt_idx;
8394 char_u *varp;
8395
8396 opt_idx = findoption(name);
8397 if (opt_idx < 0) /* unknown option */
8398 return -3;
8399
8400 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8401
8402 if (options[opt_idx].flags & P_STRING)
8403 {
8404 if (varp == NULL) /* hidden option */
8405 return -2;
8406 if (stringval != NULL)
8407 {
8408#ifdef FEAT_CRYPT
8409 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008410 if ((char_u **)varp == &curbuf->b_p_key
8411 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 *stringval = vim_strsave((char_u *)"*****");
8413 else
8414#endif
8415 *stringval = vim_strsave(*(char_u **)(varp));
8416 }
8417 return 0;
8418 }
8419
8420 if (varp == NULL) /* hidden option */
8421 return -1;
8422 if (options[opt_idx].flags & P_NUM)
8423 *numval = *(long *)varp;
8424 else
8425 {
8426 /* Special case: 'modified' is b_changed, but we also want to consider
8427 * it set when 'ff' or 'fenc' changed. */
8428 if ((int *)varp == &curbuf->b_changed)
8429 *numval = curbufIsChanged();
8430 else
8431 *numval = *(int *)varp;
8432 }
8433 return 1;
8434}
8435#endif
8436
8437/*
8438 * Set the value of option "name".
8439 * Use "string" for string options, use "number" for other options.
8440 */
8441 void
8442set_option_value(name, number, string, opt_flags)
8443 char_u *name;
8444 long number;
8445 char_u *string;
8446 int opt_flags; /* OPT_LOCAL or 0 (both) */
8447{
8448 int opt_idx;
8449 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00008450 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451
8452 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00008453 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454 EMSG2(_("E355: Unknown option: %s"), name);
8455 else
8456 {
8457 flags = options[opt_idx].flags;
8458#ifdef HAVE_SANDBOX
8459 /* Disallow changing some options in the sandbox */
8460 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008461 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008462 EMSG(_(e_sandbox));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008463 return;
8464 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008465#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008466 if (flags & P_STRING)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008467 set_string_option(opt_idx, string, opt_flags);
8468 else
8469 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00008470 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 if (varp != NULL) /* hidden option is not changed */
8472 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008473 if (number == 0 && string != NULL)
8474 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008475 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008476
8477 /* Either we are given a string or we are setting option
8478 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008479 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008480 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00008481 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00008482 {
8483 /* There's another character after zeros or the string
8484 * is empty. In both cases, we are trying to set a
8485 * num option using a string. */
8486 EMSG3(_("E521: Number required: &%s = '%s'"),
8487 name, string);
8488 return; /* do nothing as we hit an error */
8489
8490 }
8491 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492 if (flags & P_NUM)
Bram Moolenaar555b2802005-05-19 21:08:39 +00008493 (void)set_num_option(opt_idx, varp, number,
8494 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495 else
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008496 (void)set_bool_option(opt_idx, varp, (int)number,
8497 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498 }
8499 }
8500 }
8501}
8502
8503/*
8504 * Get the terminal code for a terminal option.
8505 * Returns NULL when not found.
8506 */
8507 char_u *
8508get_term_code(tname)
8509 char_u *tname;
8510{
8511 int opt_idx;
8512 char_u *varp;
8513
8514 if (tname[0] != 't' || tname[1] != '_' ||
8515 tname[2] == NUL || tname[3] == NUL)
8516 return NULL;
8517 if ((opt_idx = findoption(tname)) >= 0)
8518 {
8519 varp = get_varp(&(options[opt_idx]));
8520 if (varp != NULL)
8521 varp = *(char_u **)(varp);
8522 return varp;
8523 }
8524 return find_termcode(tname + 2);
8525}
8526
8527 char_u *
8528get_highlight_default()
8529{
8530 int i;
8531
8532 i = findoption((char_u *)"hl");
8533 if (i >= 0)
8534 return options[i].def_val[VI_DEFAULT];
8535 return (char_u *)NULL;
8536}
8537
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00008538#if defined(FEAT_MBYTE) || defined(PROTO)
8539 char_u *
8540get_encoding_default()
8541{
8542 int i;
8543
8544 i = findoption((char_u *)"enc");
8545 if (i >= 0)
8546 return options[i].def_val[VI_DEFAULT];
8547 return (char_u *)NULL;
8548}
8549#endif
8550
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551/*
8552 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
8553 */
8554 static int
8555find_key_option(arg)
8556 char_u *arg;
8557{
8558 int key;
8559 int modifiers;
8560
8561 /*
8562 * Don't use get_special_key_code() for t_xx, we don't want it to call
8563 * add_termcap_entry().
8564 */
8565 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
8566 key = TERMCAP2KEY(arg[2], arg[3]);
8567 else
8568 {
8569 --arg; /* put arg at the '<' */
8570 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00008571 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572 if (modifiers) /* can't handle modifiers here */
8573 key = 0;
8574 }
8575 return key;
8576}
8577
8578/*
8579 * if 'all' == 0: show changed options
8580 * if 'all' == 1: show all normal options
8581 * if 'all' == 2: show all terminal options
8582 */
8583 static void
8584showoptions(all, opt_flags)
8585 int all;
8586 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
8587{
8588 struct vimoption *p;
8589 int col;
8590 int isterm;
8591 char_u *varp;
8592 struct vimoption **items;
8593 int item_count;
8594 int run;
8595 int row, rows;
8596 int cols;
8597 int i;
8598 int len;
8599
8600#define INC 20
8601#define GAP 3
8602
8603 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
8604 PARAM_COUNT));
8605 if (items == NULL)
8606 return;
8607
8608 /* Highlight title */
8609 if (all == 2)
8610 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
8611 else if (opt_flags & OPT_GLOBAL)
8612 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
8613 else if (opt_flags & OPT_LOCAL)
8614 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
8615 else
8616 MSG_PUTS_TITLE(_("\n--- Options ---"));
8617
8618 /*
8619 * do the loop two times:
8620 * 1. display the short items
8621 * 2. display the long items (only strings and numbers)
8622 */
8623 for (run = 1; run <= 2 && !got_int; ++run)
8624 {
8625 /*
8626 * collect the items in items[]
8627 */
8628 item_count = 0;
8629 for (p = &options[0]; p->fullname != NULL; p++)
8630 {
8631 varp = NULL;
8632 isterm = istermoption(p);
8633 if (opt_flags != 0)
8634 {
8635 if (p->indir != PV_NONE && !isterm)
8636 varp = get_varp_scope(p, opt_flags);
8637 }
8638 else
8639 varp = get_varp(p);
8640 if (varp != NULL
8641 && ((all == 2 && isterm)
8642 || (all == 1 && !isterm)
8643 || (all == 0 && !optval_default(p, varp))))
8644 {
8645 if (p->flags & P_BOOL)
8646 len = 1; /* a toggle option fits always */
8647 else
8648 {
8649 option_value2string(p, opt_flags);
8650 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
8651 }
8652 if ((len <= INC - GAP && run == 1) ||
8653 (len > INC - GAP && run == 2))
8654 items[item_count++] = p;
8655 }
8656 }
8657
8658 /*
8659 * display the items
8660 */
8661 if (run == 1)
8662 {
8663 cols = (Columns + GAP - 3) / INC;
8664 if (cols == 0)
8665 cols = 1;
8666 rows = (item_count + cols - 1) / cols;
8667 }
8668 else /* run == 2 */
8669 rows = item_count;
8670 for (row = 0; row < rows && !got_int; ++row)
8671 {
8672 msg_putchar('\n'); /* go to next line */
8673 if (got_int) /* 'q' typed in more */
8674 break;
8675 col = 0;
8676 for (i = row; i < item_count; i += rows)
8677 {
8678 msg_col = col; /* make columns */
8679 showoneopt(items[i], opt_flags);
8680 col += INC;
8681 }
8682 out_flush();
8683 ui_breakcheck();
8684 }
8685 }
8686 vim_free(items);
8687}
8688
8689/*
8690 * Return TRUE if option "p" has its default value.
8691 */
8692 static int
8693optval_default(p, varp)
8694 struct vimoption *p;
8695 char_u *varp;
8696{
8697 int dvi;
8698
8699 if (varp == NULL)
8700 return TRUE; /* hidden option is always at default */
8701 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
8702 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008703 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00008705 /* the cast to long is required for Manx C, long_i is
8706 * needed for MSVC */
8707 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008708 /* P_STRING */
8709 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
8710}
8711
8712/*
8713 * showoneopt: show the value of one option
8714 * must not be called with a hidden option!
8715 */
8716 static void
8717showoneopt(p, opt_flags)
8718 struct vimoption *p;
8719 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
8720{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008721 char_u *varp;
8722 int save_silent = silent_mode;
8723
8724 silent_mode = FALSE;
8725 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726
8727 varp = get_varp_scope(p, opt_flags);
8728
8729 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
8730 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
8731 ? !curbufIsChanged() : !*(int *)varp))
8732 MSG_PUTS("no");
8733 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
8734 MSG_PUTS("--");
8735 else
8736 MSG_PUTS(" ");
8737 MSG_PUTS(p->fullname);
8738 if (!(p->flags & P_BOOL))
8739 {
8740 msg_putchar('=');
8741 /* put value string in NameBuff */
8742 option_value2string(p, opt_flags);
8743 msg_outtrans(NameBuff);
8744 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00008745
8746 silent_mode = save_silent;
8747 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008748}
8749
8750/*
8751 * Write modified options as ":set" commands to a file.
8752 *
8753 * There are three values for "opt_flags":
8754 * OPT_GLOBAL: Write global option values and fresh values of
8755 * buffer-local options (used for start of a session
8756 * file).
8757 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
8758 * curwin (used for a vimrc file).
8759 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
8760 * and local values for window-local options of
8761 * curwin. Local values are also written when at the
8762 * default value, because a modeline or autocommand
8763 * may have set them when doing ":edit file" and the
8764 * user has set them back at the default or fresh
8765 * value.
8766 * When "local_only" is TRUE, don't write fresh
8767 * values, only local values (for ":mkview").
8768 * (fresh value = value used for a new buffer or window for a local option).
8769 *
8770 * Return FAIL on error, OK otherwise.
8771 */
8772 int
8773makeset(fd, opt_flags, local_only)
8774 FILE *fd;
8775 int opt_flags;
8776 int local_only;
8777{
8778 struct vimoption *p;
8779 char_u *varp; /* currently used value */
8780 char_u *varp_fresh; /* local value */
8781 char_u *varp_local = NULL; /* fresh value */
8782 char *cmd;
8783 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008784 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008785
8786 /*
8787 * The options that don't have a default (terminal name, columns, lines)
8788 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008789 * Do the loop over "options[]" twice: once for options with the
8790 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008792 for (pri = 1; pri >= 0; --pri)
8793 {
8794 for (p = &options[0]; !istermoption(p); p++)
8795 if (!(p->flags & P_NO_MKRC)
8796 && !istermoption(p)
8797 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798 {
8799 /* skip global option when only doing locals */
8800 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
8801 continue;
8802
8803 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
8804 * file, they are always buffer-specific. */
8805 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
8806 continue;
8807
8808 /* Global values are only written when not at the default value. */
8809 varp = get_varp_scope(p, opt_flags);
8810 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
8811 continue;
8812
8813 round = 2;
8814 if (p->indir != PV_NONE)
8815 {
8816 if (p->var == VAR_WIN)
8817 {
8818 /* skip window-local option when only doing globals */
8819 if (!(opt_flags & OPT_LOCAL))
8820 continue;
8821 /* When fresh value of window-local option is not at the
8822 * default, need to write it too. */
8823 if (!(opt_flags & OPT_GLOBAL) && !local_only)
8824 {
8825 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
8826 if (!optval_default(p, varp_fresh))
8827 {
8828 round = 1;
8829 varp_local = varp;
8830 varp = varp_fresh;
8831 }
8832 }
8833 }
8834 }
8835
8836 /* Round 1: fresh value for window-local options.
8837 * Round 2: other values */
8838 for ( ; round <= 2; varp = varp_local, ++round)
8839 {
8840 if (round == 1 || (opt_flags & OPT_GLOBAL))
8841 cmd = "set";
8842 else
8843 cmd = "setlocal";
8844
8845 if (p->flags & P_BOOL)
8846 {
8847 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
8848 return FAIL;
8849 }
8850 else if (p->flags & P_NUM)
8851 {
8852 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
8853 return FAIL;
8854 }
8855 else /* P_STRING */
8856 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008857#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8858 int do_endif = FALSE;
8859
Bram Moolenaar071d4272004-06-13 20:20:40 +00008860 /* Don't set 'syntax' and 'filetype' again if the value is
8861 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008862 if (
8863# if defined(FEAT_SYN_HL)
8864 p->indir == PV_SYN
8865# if defined(FEAT_AUTOCMD)
8866 ||
8867# endif
8868# endif
8869# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008870 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008871# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00008872 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873 {
8874 if (fprintf(fd, "if &%s != '%s'", p->fullname,
8875 *(char_u **)(varp)) < 0
8876 || put_eol(fd) < 0)
8877 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008878 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008879 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008880#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
8882 (p->flags & P_EXPAND) != 0) == FAIL)
8883 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008884#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
8885 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008886 {
8887 if (put_line(fd, "endif") == FAIL)
8888 return FAIL;
8889 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008890#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008891 }
8892 }
8893 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00008894 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008895 return OK;
8896}
8897
8898#if defined(FEAT_FOLDING) || defined(PROTO)
8899/*
8900 * Generate set commands for the local fold options only. Used when
8901 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
8902 */
8903 int
8904makefoldset(fd)
8905 FILE *fd;
8906{
8907 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
8908# ifdef FEAT_EVAL
8909 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
8910 == FAIL
8911# endif
8912 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
8913 == FAIL
8914 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
8915 == FAIL
8916 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
8917 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
8918 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
8919 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
8920 )
8921 return FAIL;
8922
8923 return OK;
8924}
8925#endif
8926
8927 static int
8928put_setstring(fd, cmd, name, valuep, expand)
8929 FILE *fd;
8930 char *cmd;
8931 char *name;
8932 char_u **valuep;
8933 int expand;
8934{
8935 char_u *s;
8936 char_u buf[MAXPATHL];
8937
8938 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8939 return FAIL;
8940 if (*valuep != NULL)
8941 {
8942 /* Output 'pastetoggle' as key names. For other
8943 * options some characters have to be escaped with
8944 * CTRL-V or backslash */
8945 if (valuep == &p_pt)
8946 {
8947 s = *valuep;
8948 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00008949 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008950 return FAIL;
8951 }
8952 else if (expand)
8953 {
8954 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
8955 if (put_escstr(fd, buf, 2) == FAIL)
8956 return FAIL;
8957 }
8958 else if (put_escstr(fd, *valuep, 2) == FAIL)
8959 return FAIL;
8960 }
8961 if (put_eol(fd) < 0)
8962 return FAIL;
8963 return OK;
8964}
8965
8966 static int
8967put_setnum(fd, cmd, name, valuep)
8968 FILE *fd;
8969 char *cmd;
8970 char *name;
8971 long *valuep;
8972{
8973 long wc;
8974
8975 if (fprintf(fd, "%s %s=", cmd, name) < 0)
8976 return FAIL;
8977 if (wc_use_keyname((char_u *)valuep, &wc))
8978 {
8979 /* print 'wildchar' and 'wildcharm' as a key name */
8980 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
8981 return FAIL;
8982 }
8983 else if (fprintf(fd, "%ld", *valuep) < 0)
8984 return FAIL;
8985 if (put_eol(fd) < 0)
8986 return FAIL;
8987 return OK;
8988}
8989
8990 static int
8991put_setbool(fd, cmd, name, value)
8992 FILE *fd;
8993 char *cmd;
8994 char *name;
8995 int value;
8996{
Bram Moolenaar893de922007-10-02 18:40:57 +00008997 if (value < 0) /* global/local option using global value */
8998 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008999 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9000 || put_eol(fd) < 0)
9001 return FAIL;
9002 return OK;
9003}
9004
9005/*
9006 * Clear all the terminal options.
9007 * If the option has been allocated, free the memory.
9008 * Terminal options are never hidden or indirect.
9009 */
9010 void
9011clear_termoptions()
9012{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 /*
9014 * Reset a few things before clearing the old options. This may cause
9015 * outputting a few things that the terminal doesn't understand, but the
9016 * screen will be cleared later, so this is OK.
9017 */
9018#ifdef FEAT_MOUSE_TTY
9019 mch_setmouse(FALSE); /* switch mouse off */
9020#endif
9021#ifdef FEAT_TITLE
9022 mch_restore_title(3); /* restore window titles */
9023#endif
9024#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9025 /* When starting the GUI close the display opened for the clipboard.
9026 * After restoring the title, because that will need the display. */
9027 if (gui.starting)
9028 clear_xterm_clip();
9029#endif
9030#ifdef WIN3264
9031 /*
9032 * Check if this is allowed now.
9033 */
9034 if (can_end_termcap_mode(FALSE) == TRUE)
9035#endif
9036 stoptermcap(); /* stop termcap mode */
9037
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009038 free_termoptions();
9039}
9040
9041 void
9042free_termoptions()
9043{
9044 struct vimoption *p;
9045
Bram Moolenaar071d4272004-06-13 20:20:40 +00009046 for (p = &options[0]; p->fullname != NULL; p++)
9047 if (istermoption(p))
9048 {
9049 if (p->flags & P_ALLOCED)
9050 free_string_option(*(char_u **)(p->var));
9051 if (p->flags & P_DEF_ALLOCED)
9052 free_string_option(p->def_val[VI_DEFAULT]);
9053 *(char_u **)(p->var) = empty_option;
9054 p->def_val[VI_DEFAULT] = empty_option;
9055 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9056 }
9057 clear_termcodes();
9058}
9059
9060/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009061 * Free the string for one term option, if it was allocated.
9062 * Set the string to empty_option and clear allocated flag.
9063 * "var" points to the option value.
9064 */
9065 void
9066free_one_termoption(var)
9067 char_u *var;
9068{
9069 struct vimoption *p;
9070
9071 for (p = &options[0]; p->fullname != NULL; p++)
9072 if (p->var == var)
9073 {
9074 if (p->flags & P_ALLOCED)
9075 free_string_option(*(char_u **)(p->var));
9076 *(char_u **)(p->var) = empty_option;
9077 p->flags &= ~P_ALLOCED;
9078 break;
9079 }
9080}
9081
9082/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083 * Set the terminal option defaults to the current value.
9084 * Used after setting the terminal name.
9085 */
9086 void
9087set_term_defaults()
9088{
9089 struct vimoption *p;
9090
9091 for (p = &options[0]; p->fullname != NULL; p++)
9092 {
9093 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9094 {
9095 if (p->flags & P_DEF_ALLOCED)
9096 {
9097 free_string_option(p->def_val[VI_DEFAULT]);
9098 p->flags &= ~P_DEF_ALLOCED;
9099 }
9100 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9101 if (p->flags & P_ALLOCED)
9102 {
9103 p->flags |= P_DEF_ALLOCED;
9104 p->flags &= ~P_ALLOCED; /* don't free the value now */
9105 }
9106 }
9107 }
9108}
9109
9110/*
9111 * return TRUE if 'p' starts with 't_'
9112 */
9113 static int
9114istermoption(p)
9115 struct vimoption *p;
9116{
9117 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9118}
9119
9120/*
9121 * Compute columns for ruler and shown command. 'sc_col' is also used to
9122 * decide what the maximum length of a message on the status line can be.
9123 * If there is a status line for the last window, 'sc_col' is independent
9124 * of 'ru_col'.
9125 */
9126
9127#define COL_RULER 17 /* columns needed by standard ruler */
9128
9129 void
9130comp_col()
9131{
9132#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9133 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9134
9135 sc_col = 0;
9136 ru_col = 0;
9137 if (p_ru)
9138 {
9139#ifdef FEAT_STL_OPT
9140 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9141#else
9142 ru_col = COL_RULER + 1;
9143#endif
9144 /* no last status line, adjust sc_col */
9145 if (!last_has_status)
9146 sc_col = ru_col;
9147 }
9148 if (p_sc)
9149 {
9150 sc_col += SHOWCMD_COLS;
9151 if (!p_ru || last_has_status) /* no need for separating space */
9152 ++sc_col;
9153 }
9154 sc_col = Columns - sc_col;
9155 ru_col = Columns - ru_col;
9156 if (sc_col <= 0) /* screen too narrow, will become a mess */
9157 sc_col = 1;
9158 if (ru_col <= 0)
9159 ru_col = 1;
9160#else
9161 sc_col = Columns;
9162 ru_col = Columns;
9163#endif
9164}
9165
9166/*
9167 * Get pointer to option variable, depending on local or global scope.
9168 */
9169 static char_u *
9170get_varp_scope(p, opt_flags)
9171 struct vimoption *p;
9172 int opt_flags;
9173{
9174 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9175 {
9176 if (p->var == VAR_WIN)
9177 return (char_u *)GLOBAL_WO(get_varp(p));
9178 return p->var;
9179 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009180 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009181 {
9182 switch ((int)p->indir)
9183 {
9184#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009185 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9186 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9187 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009188#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009189 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9190 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9191 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009192 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009193 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009195 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9196 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009197#endif
9198#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009199 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9200 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009202#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9203 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9204#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009205#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009206 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009207#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208 }
9209 return NULL; /* "cannot happen" */
9210 }
9211 return get_varp(p);
9212}
9213
9214/*
9215 * Get pointer to option variable.
9216 */
9217 static char_u *
9218get_varp(p)
9219 struct vimoption *p;
9220{
9221 /* hidden option, always return NULL */
9222 if (p->var == NULL)
9223 return NULL;
9224
9225 switch ((int)p->indir)
9226 {
9227 case PV_NONE: return p->var;
9228
9229 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009230 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009232 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009234 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009235 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009236 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009238 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009239 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9240#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009241 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009242 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009243 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009244 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9245#endif
9246#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009247 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009248 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009249 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009250 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9251#endif
9252#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009253 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009254 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009255 case PV_GP: return *curbuf->b_p_gp != NUL
9256 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9257 case PV_MP: return *curbuf->b_p_mp != NUL
9258 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009259#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009260#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9261 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9262 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9263#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009264#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009265 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009266 ? (char_u *)&(curwin->w_p_stl) : p->var;
9267#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009268
9269#ifdef FEAT_ARABIC
9270 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9271#endif
9272 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009273#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009274 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9275#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009276#ifdef FEAT_SYN_HL
9277 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9278 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9279#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009280#ifdef FEAT_DIFF
9281 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9282#endif
9283#ifdef FEAT_FOLDING
9284 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9285 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9286 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9287 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9288 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9289 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9290 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9291# ifdef FEAT_EVAL
9292 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9293 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9294# endif
9295 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9296#endif
9297 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009298 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009299#ifdef FEAT_LINEBREAK
9300 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9301#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009302#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00009303 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
9304#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00009305#ifdef FEAT_VERTSPLIT
9306 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
9307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009308#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
9309 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
9310#endif
9311#ifdef FEAT_RIGHTLEFT
9312 case PV_RL: return (char_u *)&(curwin->w_p_rl);
9313 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
9314#endif
9315 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
9316 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
9317#ifdef FEAT_LINEBREAK
9318 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
9319#endif
9320#ifdef FEAT_SCROLLBIND
9321 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
9322#endif
9323
9324 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
9325 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
9326#ifdef FEAT_MBYTE
9327 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
9328#endif
9329#if defined(FEAT_QUICKFIX)
9330 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
9331 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
9332#endif
9333 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
9334 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
9335#ifdef FEAT_CINDENT
9336 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
9337 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
9338 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
9339#endif
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009340#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +02009341 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
Bram Moolenaar0bbabe82010-05-17 20:32:55 +02009342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9344 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
9345#endif
9346#ifdef FEAT_COMMENTS
9347 case PV_COM: return (char_u *)&(curbuf->b_p_com);
9348#endif
9349#ifdef FEAT_FOLDING
9350 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
9351#endif
9352#ifdef FEAT_INS_EXPAND
9353 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
9354#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009355#ifdef FEAT_COMPL_FUNC
9356 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009357 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
9360 case PV_ET: return (char_u *)&(curbuf->b_p_et);
9361#ifdef FEAT_MBYTE
9362 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
9363#endif
9364 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
9365#ifdef FEAT_AUTOCMD
9366 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
9367#endif
9368 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009369 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
9371 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
9372 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
9373 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
9374#ifdef FEAT_FIND_ID
9375# ifdef FEAT_EVAL
9376 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
9377# endif
9378#endif
9379#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9380 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
9381 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
9382#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009383#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009384 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
9385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009386#ifdef FEAT_CRYPT
9387 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
9388#endif
9389#ifdef FEAT_LISP
9390 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
9391#endif
9392 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
9393 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
9394 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
9395 case PV_MOD: return (char_u *)&(curbuf->b_changed);
9396 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
9397#ifdef FEAT_OSFILETYPE
9398 case PV_OFT: return (char_u *)&(curbuf->b_p_oft);
9399#endif
9400 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009401#ifdef FEAT_TEXTOBJ
9402 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
9403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009404 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
9405#ifdef FEAT_SMARTINDENT
9406 case PV_SI: return (char_u *)&(curbuf->b_p_si);
9407#endif
9408#ifndef SHORT_FNAME
9409 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
9410#endif
9411 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
9412#ifdef FEAT_SEARCHPATH
9413 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
9414#endif
9415 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
9416#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009417 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009418 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
9419#endif
9420#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009421 case PV_SPC: return (char_u *)&(curbuf->b_p_spc);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009422 case PV_SPF: return (char_u *)&(curbuf->b_p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009423 case PV_SPL: return (char_u *)&(curbuf->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009424#endif
9425 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
9426 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
9427 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
9428 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009429#ifdef FEAT_PERSISTENT_UNDO
9430 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
9431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
9433#ifdef FEAT_KEYMAP
9434 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
9435#endif
9436 default: EMSG(_("E356: get_varp ERROR"));
9437 }
9438 /* always return a valid pointer to avoid a crash! */
9439 return (char_u *)&(curbuf->b_p_wm);
9440}
9441
9442/*
9443 * Get the value of 'equalprg', either the buffer-local one or the global one.
9444 */
9445 char_u *
9446get_equalprg()
9447{
9448 if (*curbuf->b_p_ep == NUL)
9449 return p_ep;
9450 return curbuf->b_p_ep;
9451}
9452
9453#if defined(FEAT_WINDOWS) || defined(PROTO)
9454/*
9455 * Copy options from one window to another.
9456 * Used when splitting a window.
9457 */
9458 void
9459win_copy_options(wp_from, wp_to)
9460 win_T *wp_from;
9461 win_T *wp_to;
9462{
9463 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
9464 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
9465# ifdef FEAT_RIGHTLEFT
9466# ifdef FEAT_FKMAP
9467 /* Is this right? */
9468 wp_to->w_farsi = wp_from->w_farsi;
9469# endif
9470# endif
9471}
9472#endif
9473
9474/*
9475 * Copy the options from one winopt_T to another.
9476 * Doesn't free the old option values in "to", use clear_winopt() for that.
9477 * The 'scroll' option is not copied, because it depends on the window height.
9478 * The 'previewwindow' option is reset, there can be only one preview window.
9479 */
9480 void
9481copy_winopt(from, to)
9482 winopt_T *from;
9483 winopt_T *to;
9484{
9485#ifdef FEAT_ARABIC
9486 to->wo_arab = from->wo_arab;
9487#endif
9488 to->wo_list = from->wo_list;
9489 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +02009490 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009491#ifdef FEAT_LINEBREAK
9492 to->wo_nuw = from->wo_nuw;
9493#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009494#ifdef FEAT_RIGHTLEFT
9495 to->wo_rl = from->wo_rl;
9496 to->wo_rlc = vim_strsave(from->wo_rlc);
9497#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009498#ifdef FEAT_STL_OPT
9499 to->wo_stl = vim_strsave(from->wo_stl);
9500#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009501 to->wo_wrap = from->wo_wrap;
9502#ifdef FEAT_LINEBREAK
9503 to->wo_lbr = from->wo_lbr;
9504#endif
9505#ifdef FEAT_SCROLLBIND
9506 to->wo_scb = from->wo_scb;
9507#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009508#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009509 to->wo_spell = from->wo_spell;
9510#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009511#ifdef FEAT_SYN_HL
9512 to->wo_cuc = from->wo_cuc;
9513 to->wo_cul = from->wo_cul;
9514#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009515#ifdef FEAT_DIFF
9516 to->wo_diff = from->wo_diff;
9517#endif
9518#ifdef FEAT_FOLDING
9519 to->wo_fdc = from->wo_fdc;
9520 to->wo_fen = from->wo_fen;
9521 to->wo_fdi = vim_strsave(from->wo_fdi);
9522 to->wo_fml = from->wo_fml;
9523 to->wo_fdl = from->wo_fdl;
9524 to->wo_fdm = vim_strsave(from->wo_fdm);
9525 to->wo_fdn = from->wo_fdn;
9526# ifdef FEAT_EVAL
9527 to->wo_fde = vim_strsave(from->wo_fde);
9528 to->wo_fdt = vim_strsave(from->wo_fdt);
9529# endif
9530 to->wo_fmr = vim_strsave(from->wo_fmr);
9531#endif
9532 check_winopt(to); /* don't want NULL pointers */
9533}
9534
9535/*
9536 * Check string options in a window for a NULL value.
9537 */
9538 void
9539check_win_options(win)
9540 win_T *win;
9541{
9542 check_winopt(&win->w_onebuf_opt);
9543 check_winopt(&win->w_allbuf_opt);
9544}
9545
9546/*
9547 * Check for NULL pointers in a winopt_T and replace them with empty_option.
9548 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009549 void
9550check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009551 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009552{
9553#ifdef FEAT_FOLDING
9554 check_string_option(&wop->wo_fdi);
9555 check_string_option(&wop->wo_fdm);
9556# ifdef FEAT_EVAL
9557 check_string_option(&wop->wo_fde);
9558 check_string_option(&wop->wo_fdt);
9559# endif
9560 check_string_option(&wop->wo_fmr);
9561#endif
9562#ifdef FEAT_RIGHTLEFT
9563 check_string_option(&wop->wo_rlc);
9564#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009565#ifdef FEAT_STL_OPT
9566 check_string_option(&wop->wo_stl);
9567#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568}
9569
9570/*
9571 * Free the allocated memory inside a winopt_T.
9572 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009573 void
9574clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +00009575 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576{
9577#ifdef FEAT_FOLDING
9578 clear_string_option(&wop->wo_fdi);
9579 clear_string_option(&wop->wo_fdm);
9580# ifdef FEAT_EVAL
9581 clear_string_option(&wop->wo_fde);
9582 clear_string_option(&wop->wo_fdt);
9583# endif
9584 clear_string_option(&wop->wo_fmr);
9585#endif
9586#ifdef FEAT_RIGHTLEFT
9587 clear_string_option(&wop->wo_rlc);
9588#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009589#ifdef FEAT_STL_OPT
9590 clear_string_option(&wop->wo_stl);
9591#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592}
9593
9594/*
9595 * Copy global option values to local options for one buffer.
9596 * Used when creating a new buffer and sometimes when entering a buffer.
9597 * flags:
9598 * BCO_ENTER We will enter the buf buffer.
9599 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
9600 * appropriate.
9601 * BCO_NOHELP Don't copy the values to a help buffer.
9602 */
9603 void
9604buf_copy_options(buf, flags)
9605 buf_T *buf;
9606 int flags;
9607{
9608 int should_copy = TRUE;
9609 char_u *save_p_isk = NULL; /* init for GCC */
9610 int dont_do_help;
9611 int did_isk = FALSE;
9612
9613 /*
9614 * Don't do anything of the buffer is invalid.
9615 */
9616 if (buf == NULL || !buf_valid(buf))
9617 return;
9618
9619 /*
9620 * Skip this when the option defaults have not been set yet. Happens when
9621 * main() allocates the first buffer.
9622 */
9623 if (p_cpo != NULL)
9624 {
9625 /*
9626 * Always copy when entering and 'cpo' contains 'S'.
9627 * Don't copy when already initialized.
9628 * Don't copy when 'cpo' contains 's' and not entering.
9629 * 'S' BCO_ENTER initialized 's' should_copy
9630 * yes yes X X TRUE
9631 * yes no yes X FALSE
9632 * no X yes X FALSE
9633 * X no no yes FALSE
9634 * X no no no TRUE
9635 * no yes no X TRUE
9636 */
9637 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
9638 && (buf->b_p_initialized
9639 || (!(flags & BCO_ENTER)
9640 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
9641 should_copy = FALSE;
9642
9643 if (should_copy || (flags & BCO_ALWAYS))
9644 {
9645 /* Don't copy the options specific to a help buffer when
9646 * BCO_NOHELP is given or the options were initialized already
9647 * (jumping back to a help file with CTRL-T or CTRL-O) */
9648 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
9649 || buf->b_p_initialized;
9650 if (dont_do_help) /* don't free b_p_isk */
9651 {
9652 save_p_isk = buf->b_p_isk;
9653 buf->b_p_isk = NULL;
9654 }
9655 /*
9656 * Always free the allocated strings.
9657 * If not already initialized, set 'readonly' and copy 'fileformat'.
9658 */
9659 if (!buf->b_p_initialized)
9660 {
9661 free_buf_options(buf, TRUE);
9662 buf->b_p_ro = FALSE; /* don't copy readonly */
9663 buf->b_p_tx = p_tx;
9664#ifdef FEAT_MBYTE
9665 buf->b_p_fenc = vim_strsave(p_fenc);
9666#endif
9667 buf->b_p_ff = vim_strsave(p_ff);
9668#if defined(FEAT_QUICKFIX)
9669 buf->b_p_bh = empty_option;
9670 buf->b_p_bt = empty_option;
9671#endif
9672 }
9673 else
9674 free_buf_options(buf, FALSE);
9675
9676 buf->b_p_ai = p_ai;
9677 buf->b_p_ai_nopaste = p_ai_nopaste;
9678 buf->b_p_sw = p_sw;
9679 buf->b_p_tw = p_tw;
9680 buf->b_p_tw_nopaste = p_tw_nopaste;
9681 buf->b_p_tw_nobin = p_tw_nobin;
9682 buf->b_p_wm = p_wm;
9683 buf->b_p_wm_nopaste = p_wm_nopaste;
9684 buf->b_p_wm_nobin = p_wm_nobin;
9685 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +00009686#ifdef FEAT_MBYTE
9687 buf->b_p_bomb = p_bomb;
9688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009689 buf->b_p_et = p_et;
9690 buf->b_p_et_nobin = p_et_nobin;
9691 buf->b_p_ml = p_ml;
9692 buf->b_p_ml_nobin = p_ml_nobin;
9693 buf->b_p_inf = p_inf;
9694 buf->b_p_swf = p_swf;
9695#ifdef FEAT_INS_EXPAND
9696 buf->b_p_cpt = vim_strsave(p_cpt);
9697#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009698#ifdef FEAT_COMPL_FUNC
9699 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00009700 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009702 buf->b_p_sts = p_sts;
9703 buf->b_p_sts_nopaste = p_sts_nopaste;
9704#ifndef SHORT_FNAME
9705 buf->b_p_sn = p_sn;
9706#endif
9707#ifdef FEAT_COMMENTS
9708 buf->b_p_com = vim_strsave(p_com);
9709#endif
9710#ifdef FEAT_FOLDING
9711 buf->b_p_cms = vim_strsave(p_cms);
9712#endif
9713 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00009714 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715 buf->b_p_nf = vim_strsave(p_nf);
9716 buf->b_p_mps = vim_strsave(p_mps);
9717#ifdef FEAT_SMARTINDENT
9718 buf->b_p_si = p_si;
9719#endif
9720 buf->b_p_ci = p_ci;
9721#ifdef FEAT_CINDENT
9722 buf->b_p_cin = p_cin;
9723 buf->b_p_cink = vim_strsave(p_cink);
9724 buf->b_p_cino = vim_strsave(p_cino);
9725#endif
9726#ifdef FEAT_AUTOCMD
9727 /* Don't copy 'filetype', it must be detected */
9728 buf->b_p_ft = empty_option;
9729#endif
9730#ifdef FEAT_OSFILETYPE
9731 buf->b_p_oft = vim_strsave(p_oft);
9732#endif
9733 buf->b_p_pi = p_pi;
9734#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
9735 buf->b_p_cinw = vim_strsave(p_cinw);
9736#endif
9737#ifdef FEAT_LISP
9738 buf->b_p_lisp = p_lisp;
9739#endif
9740#ifdef FEAT_SYN_HL
9741 /* Don't copy 'syntax', it must be set */
9742 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00009743 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009744#endif
9745#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00009746 buf->b_p_spc = vim_strsave(p_spc);
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00009747 (void)compile_cap_prog(buf);
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00009748 buf->b_p_spf = vim_strsave(p_spf);
Bram Moolenaar217ad922005-03-20 22:37:15 +00009749 buf->b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750#endif
9751#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
9752 buf->b_p_inde = vim_strsave(p_inde);
9753 buf->b_p_indk = vim_strsave(p_indk);
9754#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00009755#if defined(FEAT_EVAL)
9756 buf->b_p_fex = vim_strsave(p_fex);
9757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758#ifdef FEAT_CRYPT
9759 buf->b_p_key = vim_strsave(p_key);
9760#endif
9761#ifdef FEAT_SEARCHPATH
9762 buf->b_p_sua = vim_strsave(p_sua);
9763#endif
9764#ifdef FEAT_KEYMAP
9765 buf->b_p_keymap = vim_strsave(p_keymap);
9766 buf->b_kmap_state |= KEYMAP_INIT;
9767#endif
9768 /* This isn't really an option, but copying the langmap and IME
9769 * state from the current buffer is better than resetting it. */
9770 buf->b_p_iminsert = p_iminsert;
9771 buf->b_p_imsearch = p_imsearch;
9772
9773 /* options that are normally global but also have a local value
9774 * are not copied, start using the global value */
9775 buf->b_p_ar = -1;
9776#ifdef FEAT_QUICKFIX
9777 buf->b_p_gp = empty_option;
9778 buf->b_p_mp = empty_option;
9779 buf->b_p_efm = empty_option;
9780#endif
9781 buf->b_p_ep = empty_option;
9782 buf->b_p_kp = empty_option;
9783 buf->b_p_path = empty_option;
9784 buf->b_p_tags = empty_option;
9785#ifdef FEAT_FIND_ID
9786 buf->b_p_def = empty_option;
9787 buf->b_p_inc = empty_option;
9788# ifdef FEAT_EVAL
9789 buf->b_p_inex = vim_strsave(p_inex);
9790# endif
9791#endif
9792#ifdef FEAT_INS_EXPAND
9793 buf->b_p_dict = empty_option;
9794 buf->b_p_tsr = empty_option;
9795#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009796#ifdef FEAT_TEXTOBJ
9797 buf->b_p_qe = vim_strsave(p_qe);
9798#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009799#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9800 buf->b_p_bexpr = empty_option;
9801#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +02009802#ifdef FEAT_PERSISTENT_UNDO
9803 buf->b_p_udf = p_udf;
9804#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009805
9806 /*
9807 * Don't copy the options set by ex_help(), use the saved values,
9808 * when going from a help buffer to a non-help buffer.
9809 * Don't touch these at all when BCO_NOHELP is used and going from
9810 * or to a help buffer.
9811 */
9812 if (dont_do_help)
9813 buf->b_p_isk = save_p_isk;
9814 else
9815 {
9816 buf->b_p_isk = vim_strsave(p_isk);
9817 did_isk = TRUE;
9818 buf->b_p_ts = p_ts;
9819 buf->b_help = FALSE;
9820#ifdef FEAT_QUICKFIX
9821 if (buf->b_p_bt[0] == 'h')
9822 clear_string_option(&buf->b_p_bt);
9823#endif
9824 buf->b_p_ma = p_ma;
9825 }
9826 }
9827
9828 /*
9829 * When the options should be copied (ignoring BCO_ALWAYS), set the
9830 * flag that indicates that the options have been initialized.
9831 */
9832 if (should_copy)
9833 buf->b_p_initialized = TRUE;
9834 }
9835
9836 check_buf_options(buf); /* make sure we don't have NULLs */
9837 if (did_isk)
9838 (void)buf_init_chartab(buf, FALSE);
9839}
9840
9841/*
9842 * Reset the 'modifiable' option and its default value.
9843 */
9844 void
9845reset_modifiable()
9846{
9847 int opt_idx;
9848
9849 curbuf->b_p_ma = FALSE;
9850 p_ma = FALSE;
9851 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009852 if (opt_idx >= 0)
9853 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009854}
9855
9856/*
9857 * Set the global value for 'iminsert' to the local value.
9858 */
9859 void
9860set_iminsert_global()
9861{
9862 p_iminsert = curbuf->b_p_iminsert;
9863}
9864
9865/*
9866 * Set the global value for 'imsearch' to the local value.
9867 */
9868 void
9869set_imsearch_global()
9870{
9871 p_imsearch = curbuf->b_p_imsearch;
9872}
9873
9874#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
9875static int expand_option_idx = -1;
9876static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
9877static int expand_option_flags = 0;
9878
9879 void
9880set_context_in_set_cmd(xp, arg, opt_flags)
9881 expand_T *xp;
9882 char_u *arg;
9883 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
9884{
9885 int nextchar;
9886 long_u flags = 0; /* init for GCC */
9887 int opt_idx = 0; /* init for GCC */
9888 char_u *p;
9889 char_u *s;
9890 int is_term_option = FALSE;
9891 int key;
9892
9893 expand_option_flags = opt_flags;
9894
9895 xp->xp_context = EXPAND_SETTINGS;
9896 if (*arg == NUL)
9897 {
9898 xp->xp_pattern = arg;
9899 return;
9900 }
9901 p = arg + STRLEN(arg) - 1;
9902 if (*p == ' ' && *(p - 1) != '\\')
9903 {
9904 xp->xp_pattern = p + 1;
9905 return;
9906 }
9907 while (p > arg)
9908 {
9909 s = p;
9910 /* count number of backslashes before ' ' or ',' */
9911 if (*p == ' ' || *p == ',')
9912 {
9913 while (s > arg && *(s - 1) == '\\')
9914 --s;
9915 }
9916 /* break at a space with an even number of backslashes */
9917 if (*p == ' ' && ((p - s) & 1) == 0)
9918 {
9919 ++p;
9920 break;
9921 }
9922 --p;
9923 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00009924 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009925 {
9926 xp->xp_context = EXPAND_BOOL_SETTINGS;
9927 p += 2;
9928 }
9929 if (STRNCMP(p, "inv", 3) == 0)
9930 {
9931 xp->xp_context = EXPAND_BOOL_SETTINGS;
9932 p += 3;
9933 }
9934 xp->xp_pattern = arg = p;
9935 if (*arg == '<')
9936 {
9937 while (*p != '>')
9938 if (*p++ == NUL) /* expand terminal option name */
9939 return;
9940 key = get_special_key_code(arg + 1);
9941 if (key == 0) /* unknown name */
9942 {
9943 xp->xp_context = EXPAND_NOTHING;
9944 return;
9945 }
9946 nextchar = *++p;
9947 is_term_option = TRUE;
9948 expand_option_name[2] = KEY2TERMCAP0(key);
9949 expand_option_name[3] = KEY2TERMCAP1(key);
9950 }
9951 else
9952 {
9953 if (p[0] == 't' && p[1] == '_')
9954 {
9955 p += 2;
9956 if (*p != NUL)
9957 ++p;
9958 if (*p == NUL)
9959 return; /* expand option name */
9960 nextchar = *++p;
9961 is_term_option = TRUE;
9962 expand_option_name[2] = p[-2];
9963 expand_option_name[3] = p[-1];
9964 }
9965 else
9966 {
9967 /* Allow * wildcard */
9968 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
9969 p++;
9970 if (*p == NUL)
9971 return;
9972 nextchar = *p;
9973 *p = NUL;
9974 opt_idx = findoption(arg);
9975 *p = nextchar;
9976 if (opt_idx == -1 || options[opt_idx].var == NULL)
9977 {
9978 xp->xp_context = EXPAND_NOTHING;
9979 return;
9980 }
9981 flags = options[opt_idx].flags;
9982 if (flags & P_BOOL)
9983 {
9984 xp->xp_context = EXPAND_NOTHING;
9985 return;
9986 }
9987 }
9988 }
9989 /* handle "-=" and "+=" */
9990 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
9991 {
9992 ++p;
9993 nextchar = '=';
9994 }
9995 if ((nextchar != '=' && nextchar != ':')
9996 || xp->xp_context == EXPAND_BOOL_SETTINGS)
9997 {
9998 xp->xp_context = EXPAND_UNSUCCESSFUL;
9999 return;
10000 }
10001 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10002 {
10003 xp->xp_context = EXPAND_OLD_SETTING;
10004 if (is_term_option)
10005 expand_option_idx = -1;
10006 else
10007 expand_option_idx = opt_idx;
10008 xp->xp_pattern = p + 1;
10009 return;
10010 }
10011 xp->xp_context = EXPAND_NOTHING;
10012 if (is_term_option || (flags & P_NUM))
10013 return;
10014
10015 xp->xp_pattern = p + 1;
10016
10017 if (flags & P_EXPAND)
10018 {
10019 p = options[opt_idx].var;
10020 if (p == (char_u *)&p_bdir
10021 || p == (char_u *)&p_dir
10022 || p == (char_u *)&p_path
10023 || p == (char_u *)&p_rtp
10024#ifdef FEAT_SEARCHPATH
10025 || p == (char_u *)&p_cdpath
10026#endif
10027#ifdef FEAT_SESSION
10028 || p == (char_u *)&p_vdir
10029#endif
10030 )
10031 {
10032 xp->xp_context = EXPAND_DIRECTORIES;
10033 if (p == (char_u *)&p_path
10034#ifdef FEAT_SEARCHPATH
10035 || p == (char_u *)&p_cdpath
10036#endif
10037 )
10038 xp->xp_backslash = XP_BS_THREE;
10039 else
10040 xp->xp_backslash = XP_BS_ONE;
10041 }
10042 else
10043 {
10044 xp->xp_context = EXPAND_FILES;
10045 /* for 'tags' need three backslashes for a space */
10046 if (p == (char_u *)&p_tags)
10047 xp->xp_backslash = XP_BS_THREE;
10048 else
10049 xp->xp_backslash = XP_BS_ONE;
10050 }
10051 }
10052
10053 /* For an option that is a list of file names, find the start of the
10054 * last file name. */
10055 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10056 {
10057 /* count number of backslashes before ' ' or ',' */
10058 if (*p == ' ' || *p == ',')
10059 {
10060 s = p;
10061 while (s > xp->xp_pattern && *(s - 1) == '\\')
10062 --s;
10063 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10064 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10065 {
10066 xp->xp_pattern = p + 1;
10067 break;
10068 }
10069 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010070
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010071#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010072 /* for 'spellsuggest' start at "file:" */
10073 if (options[opt_idx].var == (char_u *)&p_sps
10074 && STRNCMP(p, "file:", 5) == 0)
10075 {
10076 xp->xp_pattern = p + 5;
10077 break;
10078 }
10079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010080 }
10081
10082 return;
10083}
10084
10085 int
10086ExpandSettings(xp, regmatch, num_file, file)
10087 expand_T *xp;
10088 regmatch_T *regmatch;
10089 int *num_file;
10090 char_u ***file;
10091{
10092 int num_normal = 0; /* Nr of matching non-term-code settings */
10093 int num_term = 0; /* Nr of matching terminal code settings */
10094 int opt_idx;
10095 int match;
10096 int count = 0;
10097 char_u *str;
10098 int loop;
10099 int is_term_opt;
10100 char_u name_buf[MAX_KEY_NAME_LEN];
10101 static char *(names[]) = {"all", "termcap"};
10102 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10103
10104 /* do this loop twice:
10105 * loop == 0: count the number of matching options
10106 * loop == 1: copy the matching options into allocated memory
10107 */
10108 for (loop = 0; loop <= 1; ++loop)
10109 {
10110 regmatch->rm_ic = ic;
10111 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10112 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010113 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10114 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010115 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10116 {
10117 if (loop == 0)
10118 num_normal++;
10119 else
10120 (*file)[count++] = vim_strsave((char_u *)names[match]);
10121 }
10122 }
10123 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10124 opt_idx++)
10125 {
10126 if (options[opt_idx].var == NULL)
10127 continue;
10128 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10129 && !(options[opt_idx].flags & P_BOOL))
10130 continue;
10131 is_term_opt = istermoption(&options[opt_idx]);
10132 if (is_term_opt && num_normal > 0)
10133 continue;
10134 match = FALSE;
10135 if (vim_regexec(regmatch, str, (colnr_T)0)
10136 || (options[opt_idx].shortname != NULL
10137 && vim_regexec(regmatch,
10138 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10139 match = TRUE;
10140 else if (is_term_opt)
10141 {
10142 name_buf[0] = '<';
10143 name_buf[1] = 't';
10144 name_buf[2] = '_';
10145 name_buf[3] = str[2];
10146 name_buf[4] = str[3];
10147 name_buf[5] = '>';
10148 name_buf[6] = NUL;
10149 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10150 {
10151 match = TRUE;
10152 str = name_buf;
10153 }
10154 }
10155 if (match)
10156 {
10157 if (loop == 0)
10158 {
10159 if (is_term_opt)
10160 num_term++;
10161 else
10162 num_normal++;
10163 }
10164 else
10165 (*file)[count++] = vim_strsave(str);
10166 }
10167 }
10168 /*
10169 * Check terminal key codes, these are not in the option table
10170 */
10171 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10172 {
10173 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10174 {
10175 if (!isprint(str[0]) || !isprint(str[1]))
10176 continue;
10177
10178 name_buf[0] = 't';
10179 name_buf[1] = '_';
10180 name_buf[2] = str[0];
10181 name_buf[3] = str[1];
10182 name_buf[4] = NUL;
10183
10184 match = FALSE;
10185 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10186 match = TRUE;
10187 else
10188 {
10189 name_buf[0] = '<';
10190 name_buf[1] = 't';
10191 name_buf[2] = '_';
10192 name_buf[3] = str[0];
10193 name_buf[4] = str[1];
10194 name_buf[5] = '>';
10195 name_buf[6] = NUL;
10196
10197 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10198 match = TRUE;
10199 }
10200 if (match)
10201 {
10202 if (loop == 0)
10203 num_term++;
10204 else
10205 (*file)[count++] = vim_strsave(name_buf);
10206 }
10207 }
10208
10209 /*
10210 * Check special key names.
10211 */
10212 regmatch->rm_ic = TRUE; /* ignore case here */
10213 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10214 {
10215 name_buf[0] = '<';
10216 STRCPY(name_buf + 1, str);
10217 STRCAT(name_buf, ">");
10218
10219 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10220 {
10221 if (loop == 0)
10222 num_term++;
10223 else
10224 (*file)[count++] = vim_strsave(name_buf);
10225 }
10226 }
10227 }
10228 if (loop == 0)
10229 {
10230 if (num_normal > 0)
10231 *num_file = num_normal;
10232 else if (num_term > 0)
10233 *num_file = num_term;
10234 else
10235 return OK;
10236 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10237 if (*file == NULL)
10238 {
10239 *file = (char_u **)"";
10240 return FAIL;
10241 }
10242 }
10243 }
10244 return OK;
10245}
10246
10247 int
10248ExpandOldSetting(num_file, file)
10249 int *num_file;
10250 char_u ***file;
10251{
10252 char_u *var = NULL; /* init for GCC */
10253 char_u *buf;
10254
10255 *num_file = 0;
10256 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10257 if (*file == NULL)
10258 return FAIL;
10259
10260 /*
10261 * For a terminal key code expand_option_idx is < 0.
10262 */
10263 if (expand_option_idx < 0)
10264 {
10265 var = find_termcode(expand_option_name + 2);
10266 if (var == NULL)
10267 expand_option_idx = findoption(expand_option_name);
10268 }
10269
10270 if (expand_option_idx >= 0)
10271 {
10272 /* put string of option value in NameBuff */
10273 option_value2string(&options[expand_option_idx], expand_option_flags);
10274 var = NameBuff;
10275 }
10276 else if (var == NULL)
10277 var = (char_u *)"";
10278
10279 /* A backslash is required before some characters. This is the reverse of
10280 * what happens in do_set(). */
10281 buf = vim_strsave_escaped(var, escape_chars);
10282
10283 if (buf == NULL)
10284 {
10285 vim_free(*file);
10286 *file = NULL;
10287 return FAIL;
10288 }
10289
10290#ifdef BACKSLASH_IN_FILENAME
10291 /* For MS-Windows et al. we don't double backslashes at the start and
10292 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010293 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294 if (var[0] == '\\' && var[1] == '\\'
10295 && expand_option_idx >= 0
10296 && (options[expand_option_idx].flags & P_EXPAND)
10297 && vim_isfilec(var[2])
10298 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000010299 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300#endif
10301
10302 *file[0] = buf;
10303 *num_file = 1;
10304 return OK;
10305}
10306#endif
10307
10308/*
10309 * Get the value for the numeric or string option *opp in a nice format into
10310 * NameBuff[]. Must not be called with a hidden option!
10311 */
10312 static void
10313option_value2string(opp, opt_flags)
10314 struct vimoption *opp;
10315 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10316{
10317 char_u *varp;
10318
10319 varp = get_varp_scope(opp, opt_flags);
10320
10321 if (opp->flags & P_NUM)
10322 {
10323 long wc = 0;
10324
10325 if (wc_use_keyname(varp, &wc))
10326 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
10327 else if (wc != 0)
10328 STRCPY(NameBuff, transchar((int)wc));
10329 else
10330 sprintf((char *)NameBuff, "%ld", *(long *)varp);
10331 }
10332 else /* P_STRING */
10333 {
10334 varp = *(char_u **)(varp);
10335 if (varp == NULL) /* just in case */
10336 NameBuff[0] = NUL;
10337#ifdef FEAT_CRYPT
10338 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010339 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010340 STRCPY(NameBuff, "*****");
10341#endif
10342 else if (opp->flags & P_EXPAND)
10343 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
10344 /* Translate 'pastetoggle' into special key names */
10345 else if ((char_u **)opp->var == &p_pt)
10346 str2specialbuf(p_pt, NameBuff, MAXPATHL);
10347 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000010348 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349 }
10350}
10351
10352/*
10353 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
10354 * printed as a keyname.
10355 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
10356 */
10357 static int
10358wc_use_keyname(varp, wcp)
10359 char_u *varp;
10360 long *wcp;
10361{
10362 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
10363 {
10364 *wcp = *(long *)varp;
10365 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
10366 return TRUE;
10367 }
10368 return FALSE;
10369}
10370
10371#ifdef FEAT_LANGMAP
10372/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010373 * Any character has an equivalent 'langmap' character. This is used for
10374 * keyboards that have a special language mode that sends characters above
10375 * 128 (although other characters can be translated too). The "to" field is a
10376 * Vim command character. This avoids having to switch the keyboard back to
10377 * ASCII mode when leaving Insert mode.
10378 *
10379 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
10380 * commands.
10381 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
10382 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
10383 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010385# ifdef FEAT_MBYTE
10386/*
10387 * With multi-byte support use growarray for 'langmap' chars >= 256
10388 */
10389typedef struct
10390{
10391 int from;
10392 int to;
10393} langmap_entry_T;
10394
10395static garray_T langmap_mapga;
10396static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397
10398/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010399 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
10400 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010402 static void
10403langmap_set_entry(from, to)
10404 int from;
10405 int to;
10406{
10407 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10408 int a = 0;
10409 int b = langmap_mapga.ga_len;
10410
10411 /* Do a binary search for an existing entry. */
10412 while (a != b)
10413 {
10414 int i = (a + b) / 2;
10415 int d = entries[i].from - from;
10416
10417 if (d == 0)
10418 {
10419 entries[i].to = to;
10420 return;
10421 }
10422 if (d < 0)
10423 a = i + 1;
10424 else
10425 b = i;
10426 }
10427
10428 if (ga_grow(&langmap_mapga, 1) != OK)
10429 return; /* out of memory */
10430
10431 /* insert new entry at position "a" */
10432 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
10433 mch_memmove(entries + 1, entries,
10434 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
10435 ++langmap_mapga.ga_len;
10436 entries[0].from = from;
10437 entries[0].to = to;
10438}
10439
10440/*
10441 * Apply 'langmap' to multi-byte character "c" and return the result.
10442 */
10443 int
10444langmap_adjust_mb(c)
10445 int c;
10446{
10447 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
10448 int a = 0;
10449 int b = langmap_mapga.ga_len;
10450
10451 while (a != b)
10452 {
10453 int i = (a + b) / 2;
10454 int d = entries[i].from - c;
10455
10456 if (d == 0)
10457 return entries[i].to; /* found matching entry */
10458 if (d < 0)
10459 a = i + 1;
10460 else
10461 b = i;
10462 }
10463 return c; /* no entry found, return "c" unmodified */
10464}
10465# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466
10467 static void
10468langmap_init()
10469{
10470 int i;
10471
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010472 for (i = 0; i < 256; i++)
10473 langmap_mapchar[i] = i; /* we init with a one-to-one map */
10474# ifdef FEAT_MBYTE
10475 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
10476# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010477}
10478
10479/*
10480 * Called when langmap option is set; the language map can be
10481 * changed at any time!
10482 */
10483 static void
10484langmap_set()
10485{
10486 char_u *p;
10487 char_u *p2;
10488 int from, to;
10489
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010490#ifdef FEAT_MBYTE
10491 ga_clear(&langmap_mapga); /* clear the previous map first */
10492#endif
10493 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494
10495 for (p = p_langmap; p[0] != NUL; )
10496 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010497 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
10498 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499 {
10500 if (p2[0] == '\\' && p2[1] != NUL)
10501 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502 }
10503 if (p2[0] == ';')
10504 ++p2; /* abcd;ABCD form, p2 points to A */
10505 else
10506 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
10507 while (p[0])
10508 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010509 if (p[0] == ',')
10510 {
10511 ++p;
10512 break;
10513 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010514 if (p[0] == '\\' && p[1] != NUL)
10515 ++p;
10516#ifdef FEAT_MBYTE
10517 from = (*mb_ptr2char)(p);
10518#else
10519 from = p[0];
10520#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010521 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522 if (p2 == NULL)
10523 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010524 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010525 if (p[0] != ',')
10526 {
10527 if (p[0] == '\\')
10528 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010530 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010531#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010532 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010534 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 }
10536 else
10537 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020010538 if (p2[0] != ',')
10539 {
10540 if (p2[0] == '\\')
10541 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020010543 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020010545 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000010546#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020010547 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548 }
10549 if (to == NUL)
10550 {
10551 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
10552 transchar(from));
10553 return;
10554 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000010555
10556#ifdef FEAT_MBYTE
10557 if (from >= 256)
10558 langmap_set_entry(from, to);
10559 else
10560#endif
10561 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562
10563 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010564 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020010565 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010567 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 if (*p == ';')
10569 {
10570 p = p2;
10571 if (p[0] != NUL)
10572 {
10573 if (p[0] != ',')
10574 {
10575 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
10576 return;
10577 }
10578 ++p;
10579 }
10580 break;
10581 }
10582 }
10583 }
10584 }
10585}
10586#endif
10587
10588/*
10589 * Return TRUE if format option 'x' is in effect.
10590 * Take care of no formatting when 'paste' is set.
10591 */
10592 int
10593has_format_option(x)
10594 int x;
10595{
10596 if (p_paste)
10597 return FALSE;
10598 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
10599}
10600
10601/*
10602 * Return TRUE if "x" is present in 'shortmess' option, or
10603 * 'shortmess' contains 'a' and "x" is present in SHM_A.
10604 */
10605 int
10606shortmess(x)
10607 int x;
10608{
10609 return ( vim_strchr(p_shm, x) != NULL
10610 || (vim_strchr(p_shm, 'a') != NULL
10611 && vim_strchr((char_u *)SHM_A, x) != NULL));
10612}
10613
10614/*
10615 * paste_option_changed() - Called after p_paste was set or reset.
10616 */
10617 static void
10618paste_option_changed()
10619{
10620 static int old_p_paste = FALSE;
10621 static int save_sm = 0;
10622#ifdef FEAT_CMDL_INFO
10623 static int save_ru = 0;
10624#endif
10625#ifdef FEAT_RIGHTLEFT
10626 static int save_ri = 0;
10627 static int save_hkmap = 0;
10628#endif
10629 buf_T *buf;
10630
10631 if (p_paste)
10632 {
10633 /*
10634 * Paste switched from off to on.
10635 * Save the current values, so they can be restored later.
10636 */
10637 if (!old_p_paste)
10638 {
10639 /* save options for each buffer */
10640 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10641 {
10642 buf->b_p_tw_nopaste = buf->b_p_tw;
10643 buf->b_p_wm_nopaste = buf->b_p_wm;
10644 buf->b_p_sts_nopaste = buf->b_p_sts;
10645 buf->b_p_ai_nopaste = buf->b_p_ai;
10646 }
10647
10648 /* save global options */
10649 save_sm = p_sm;
10650#ifdef FEAT_CMDL_INFO
10651 save_ru = p_ru;
10652#endif
10653#ifdef FEAT_RIGHTLEFT
10654 save_ri = p_ri;
10655 save_hkmap = p_hkmap;
10656#endif
10657 /* save global values for local buffer options */
10658 p_tw_nopaste = p_tw;
10659 p_wm_nopaste = p_wm;
10660 p_sts_nopaste = p_sts;
10661 p_ai_nopaste = p_ai;
10662 }
10663
10664 /*
10665 * Always set the option values, also when 'paste' is set when it is
10666 * already on.
10667 */
10668 /* set options for each buffer */
10669 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10670 {
10671 buf->b_p_tw = 0; /* textwidth is 0 */
10672 buf->b_p_wm = 0; /* wrapmargin is 0 */
10673 buf->b_p_sts = 0; /* softtabstop is 0 */
10674 buf->b_p_ai = 0; /* no auto-indent */
10675 }
10676
10677 /* set global options */
10678 p_sm = 0; /* no showmatch */
10679#ifdef FEAT_CMDL_INFO
10680# ifdef FEAT_WINDOWS
10681 if (p_ru)
10682 status_redraw_all(); /* redraw to remove the ruler */
10683# endif
10684 p_ru = 0; /* no ruler */
10685#endif
10686#ifdef FEAT_RIGHTLEFT
10687 p_ri = 0; /* no reverse insert */
10688 p_hkmap = 0; /* no Hebrew keyboard */
10689#endif
10690 /* set global values for local buffer options */
10691 p_tw = 0;
10692 p_wm = 0;
10693 p_sts = 0;
10694 p_ai = 0;
10695 }
10696
10697 /*
10698 * Paste switched from on to off: Restore saved values.
10699 */
10700 else if (old_p_paste)
10701 {
10702 /* restore options for each buffer */
10703 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
10704 {
10705 buf->b_p_tw = buf->b_p_tw_nopaste;
10706 buf->b_p_wm = buf->b_p_wm_nopaste;
10707 buf->b_p_sts = buf->b_p_sts_nopaste;
10708 buf->b_p_ai = buf->b_p_ai_nopaste;
10709 }
10710
10711 /* restore global options */
10712 p_sm = save_sm;
10713#ifdef FEAT_CMDL_INFO
10714# ifdef FEAT_WINDOWS
10715 if (p_ru != save_ru)
10716 status_redraw_all(); /* redraw to draw the ruler */
10717# endif
10718 p_ru = save_ru;
10719#endif
10720#ifdef FEAT_RIGHTLEFT
10721 p_ri = save_ri;
10722 p_hkmap = save_hkmap;
10723#endif
10724 /* set global values for local buffer options */
10725 p_tw = p_tw_nopaste;
10726 p_wm = p_wm_nopaste;
10727 p_sts = p_sts_nopaste;
10728 p_ai = p_ai_nopaste;
10729 }
10730
10731 old_p_paste = p_paste;
10732}
10733
10734/*
10735 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
10736 *
10737 * Reset 'compatible' and set the values for options that didn't get set yet
10738 * to the Vim defaults.
10739 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010740 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 */
10742 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010743vimrc_found(fname, envname)
10744 char_u *fname;
10745 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010747 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000010748 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010749 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750
10751 if (!option_was_set((char_u *)"cp"))
10752 {
10753 p_cp = FALSE;
10754 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10755 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
10756 set_option_default(opt_idx, OPT_FREE, FALSE);
10757 didset_options();
10758 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000010759
10760 if (fname != NULL)
10761 {
10762 p = vim_getenv(envname, &dofree);
10763 if (p == NULL)
10764 {
10765 /* Set $MYVIMRC to the first vimrc file found. */
10766 p = FullName_save(fname, FALSE);
10767 if (p != NULL)
10768 {
10769 vim_setenv(envname, p);
10770 vim_free(p);
10771 }
10772 }
10773 else if (dofree)
10774 vim_free(p);
10775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010776}
10777
10778/*
10779 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
10780 */
10781 void
10782change_compatible(on)
10783 int on;
10784{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010785 int opt_idx;
10786
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787 if (p_cp != on)
10788 {
10789 p_cp = on;
10790 compatible_set();
10791 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010792 opt_idx = findoption((char_u *)"cp");
10793 if (opt_idx >= 0)
10794 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795}
10796
10797/*
10798 * Return TRUE when option "name" has been set.
10799 */
10800 int
10801option_was_set(name)
10802 char_u *name;
10803{
10804 int idx;
10805
10806 idx = findoption(name);
10807 if (idx < 0) /* unknown option */
10808 return FALSE;
10809 if (options[idx].flags & P_WAS_SET)
10810 return TRUE;
10811 return FALSE;
10812}
10813
10814/*
10815 * compatible_set() - Called when 'compatible' has been set or unset.
10816 *
10817 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
10818 * flag) to a Vi compatible value.
10819 * When 'compatible' is unset: Set all options that have a different default
10820 * for Vim (without the P_VI_DEF flag) to that default.
10821 */
10822 static void
10823compatible_set()
10824{
10825 int opt_idx;
10826
10827 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
10828 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
10829 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
10830 set_option_default(opt_idx, OPT_FREE, p_cp);
10831 didset_options();
10832}
10833
10834#ifdef FEAT_LINEBREAK
10835
10836# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
10837 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010838 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839# endif
10840
10841/*
10842 * fill_breakat_flags() -- called when 'breakat' changes value.
10843 */
10844 static void
10845fill_breakat_flags()
10846{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010847 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848 int i;
10849
10850 for (i = 0; i < 256; i++)
10851 breakat_flags[i] = FALSE;
10852
10853 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000010854 for (p = p_breakat; *p; p++)
10855 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856}
10857
10858# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000010859 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860# endif
10861
10862#endif
10863
10864/*
10865 * Check an option that can be a range of string values.
10866 *
10867 * Return OK for correct value, FAIL otherwise.
10868 * Empty is always OK.
10869 */
10870 static int
10871check_opt_strings(val, values, list)
10872 char_u *val;
10873 char **values;
10874 int list; /* when TRUE: accept a list of values */
10875{
10876 return opt_strings_flags(val, values, NULL, list);
10877}
10878
10879/*
10880 * Handle an option that can be a range of string values.
10881 * Set a flag in "*flagp" for each string present.
10882 *
10883 * Return OK for correct value, FAIL otherwise.
10884 * Empty is always OK.
10885 */
10886 static int
10887opt_strings_flags(val, values, flagp, list)
10888 char_u *val; /* new value */
10889 char **values; /* array of valid string values */
10890 unsigned *flagp;
10891 int list; /* when TRUE: accept a list of values */
10892{
10893 int i;
10894 int len;
10895 unsigned new_flags = 0;
10896
10897 while (*val)
10898 {
10899 for (i = 0; ; ++i)
10900 {
10901 if (values[i] == NULL) /* val not found in values[] */
10902 return FAIL;
10903
10904 len = (int)STRLEN(values[i]);
10905 if (STRNCMP(values[i], val, len) == 0
10906 && ((list && val[len] == ',') || val[len] == NUL))
10907 {
10908 val += len + (val[len] == ',');
10909 new_flags |= (1 << i);
10910 break; /* check next item in val list */
10911 }
10912 }
10913 }
10914 if (flagp != NULL)
10915 *flagp = new_flags;
10916
10917 return OK;
10918}
10919
10920/*
10921 * Read the 'wildmode' option, fill wim_flags[].
10922 */
10923 static int
10924check_opt_wim()
10925{
10926 char_u new_wim_flags[4];
10927 char_u *p;
10928 int i;
10929 int idx = 0;
10930
10931 for (i = 0; i < 4; ++i)
10932 new_wim_flags[i] = 0;
10933
10934 for (p = p_wim; *p; ++p)
10935 {
10936 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
10937 ;
10938 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
10939 return FAIL;
10940 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
10941 new_wim_flags[idx] |= WIM_LONGEST;
10942 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
10943 new_wim_flags[idx] |= WIM_FULL;
10944 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
10945 new_wim_flags[idx] |= WIM_LIST;
10946 else
10947 return FAIL;
10948 p += i;
10949 if (*p == NUL)
10950 break;
10951 if (*p == ',')
10952 {
10953 if (idx == 3)
10954 return FAIL;
10955 ++idx;
10956 }
10957 }
10958
10959 /* fill remaining entries with last flag */
10960 while (idx < 3)
10961 {
10962 new_wim_flags[idx + 1] = new_wim_flags[idx];
10963 ++idx;
10964 }
10965
10966 /* only when there are no errors, wim_flags[] is changed */
10967 for (i = 0; i < 4; ++i)
10968 wim_flags[i] = new_wim_flags[i];
10969 return OK;
10970}
10971
10972/*
10973 * Check if backspacing over something is allowed.
10974 */
10975 int
10976can_bs(what)
10977 int what; /* BS_INDENT, BS_EOL or BS_START */
10978{
10979 switch (*p_bs)
10980 {
10981 case '2': return TRUE;
10982 case '1': return (what != BS_START);
10983 case '0': return FALSE;
10984 }
10985 return vim_strchr(p_bs, what) != NULL;
10986}
10987
10988/*
10989 * Save the current values of 'fileformat' and 'fileencoding', so that we know
10990 * the file must be considered changed when the value is different.
10991 */
10992 void
10993save_file_ff(buf)
10994 buf_T *buf;
10995{
10996 buf->b_start_ffc = *buf->b_p_ff;
10997 buf->b_start_eol = buf->b_p_eol;
10998#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000010999 buf->b_start_bomb = buf->b_p_bomb;
11000
Bram Moolenaar071d4272004-06-13 20:20:40 +000011001 /* Only use free/alloc when necessary, they take time. */
11002 if (buf->b_start_fenc == NULL
11003 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11004 {
11005 vim_free(buf->b_start_fenc);
11006 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11007 }
11008#endif
11009}
11010
11011/*
11012 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11013 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011014 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11015 * changed and 'binary' is not set.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011016 * Don't consider a new, empty buffer to be changed.
11017 */
11018 int
11019file_ff_differs(buf)
11020 buf_T *buf;
11021{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011022 /* In a buffer that was never loaded the options are not valid. */
11023 if (buf->b_flags & BF_NEVERLOADED)
11024 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025 if ((buf->b_flags & BF_NEW)
11026 && buf->b_ml.ml_line_count == 1
11027 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11028 return FALSE;
11029 if (buf->b_start_ffc != *buf->b_p_ff)
11030 return TRUE;
11031 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11032 return TRUE;
11033#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011034 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11035 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011036 if (buf->b_start_fenc == NULL)
11037 return (*buf->b_p_fenc != NUL);
11038 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11039#else
11040 return FALSE;
11041#endif
11042}
11043
11044/*
11045 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11046 */
11047 int
11048check_ff_value(p)
11049 char_u *p;
11050{
11051 return check_opt_strings(p, p_ff_values, FALSE);
11052}