blob: a36f8c0a01f5f5260d5514fb07854290d69ac76c [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 Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(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)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100137# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000138#endif
139#define PV_MA OPT_BUF(BV_MA)
140#define PV_ML OPT_BUF(BV_ML)
141#define PV_MOD OPT_BUF(BV_MOD)
142#define PV_MPS OPT_BUF(BV_MPS)
143#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000144#ifdef FEAT_COMPL_FUNC
145# define PV_OFU OPT_BUF(BV_OFU)
146#endif
147#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
148#define PV_PI OPT_BUF(BV_PI)
149#ifdef FEAT_TEXTOBJ
150# define PV_QE OPT_BUF(BV_QE)
151#endif
152#define PV_RO OPT_BUF(BV_RO)
153#ifdef FEAT_SMARTINDENT
154# define PV_SI OPT_BUF(BV_SI)
155#endif
156#ifndef SHORT_FNAME
157# define PV_SN OPT_BUF(BV_SN)
158#endif
159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
175#define PV_TS OPT_BUF(BV_TS)
176#define PV_TW OPT_BUF(BV_TW)
177#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200178#ifdef FEAT_PERSISTENT_UNDO
179# define PV_UDF OPT_BUF(BV_UDF)
180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000181#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000182
183/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184 * Definition of the PV_ values for window-local options.
185 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187#define PV_LIST OPT_WIN(WV_LIST)
188#ifdef FEAT_ARABIC
189# define PV_ARAB OPT_WIN(WV_ARAB)
190#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000191#ifdef FEAT_DIFF
192# define PV_DIFF OPT_WIN(WV_DIFF)
193#endif
194#ifdef FEAT_FOLDING
195# define PV_FDC OPT_WIN(WV_FDC)
196# define PV_FEN OPT_WIN(WV_FEN)
197# define PV_FDI OPT_WIN(WV_FDI)
198# define PV_FDL OPT_WIN(WV_FDL)
199# define PV_FDM OPT_WIN(WV_FDM)
200# define PV_FML OPT_WIN(WV_FML)
201# define PV_FDN OPT_WIN(WV_FDN)
202# ifdef FEAT_EVAL
203# define PV_FDE OPT_WIN(WV_FDE)
204# define PV_FDT OPT_WIN(WV_FDT)
205# endif
206# define PV_FMR OPT_WIN(WV_FMR)
207#endif
208#ifdef FEAT_LINEBREAK
209# define PV_LBR OPT_WIN(WV_LBR)
210#endif
211#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200212#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000213#ifdef FEAT_LINEBREAK
214# define PV_NUW OPT_WIN(WV_NUW)
215#endif
216#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
217# define PV_PVW OPT_WIN(WV_PVW)
218#endif
219#ifdef FEAT_RIGHTLEFT
220# define PV_RL OPT_WIN(WV_RL)
221# define PV_RLC OPT_WIN(WV_RLC)
222#endif
223#ifdef FEAT_SCROLLBIND
224# define PV_SCBIND OPT_WIN(WV_SCBIND)
225#endif
226#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000227#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000228# define PV_SPELL OPT_WIN(WV_SPELL)
229#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000230#ifdef FEAT_SYN_HL
231# define PV_CUC OPT_WIN(WV_CUC)
232# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200233# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000235#ifdef FEAT_STL_OPT
236# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
237#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100238#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000239#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 Moolenaar860cae12010-06-05 23:22:07 +0200246#ifdef FEAT_CURSORBIND
247# define PV_CRBIND OPT_WIN(WV_CRBIND)
248#endif
249#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200250# define PV_COCU OPT_WIN(WV_COCU)
251# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200252#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000253
254/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255typedef enum
256{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000257 PV_NONE = 0,
258 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259} idopt_T;
260
261/*
262 * Options local to a window have a value local to a buffer and global to all
263 * buffers. Indicate this by setting "var" to VAR_WIN.
264 */
265#define VAR_WIN ((char_u *)-1)
266
267/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000268 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269 * Only to be used in option.c!
270 */
271static int p_ai;
272static int p_bin;
273#ifdef FEAT_MBYTE
274static int p_bomb;
275#endif
276#if defined(FEAT_QUICKFIX)
277static char_u *p_bh;
278static char_u *p_bt;
279#endif
280static int p_bl;
281static int p_ci;
282#ifdef FEAT_CINDENT
283static int p_cin;
284static char_u *p_cink;
285static char_u *p_cino;
286#endif
287#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
288static char_u *p_cinw;
289#endif
290#ifdef FEAT_COMMENTS
291static char_u *p_com;
292#endif
293#ifdef FEAT_FOLDING
294static char_u *p_cms;
295#endif
296#ifdef FEAT_INS_EXPAND
297static char_u *p_cpt;
298#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000299#ifdef FEAT_COMPL_FUNC
300static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000301static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303static int p_eol;
304static int p_et;
305#ifdef FEAT_MBYTE
306static char_u *p_fenc;
307#endif
308static char_u *p_ff;
309static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000310static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311#ifdef FEAT_AUTOCMD
312static char_u *p_ft;
313#endif
314static long p_iminsert;
315static long p_imsearch;
316#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
317static char_u *p_inex;
318#endif
319#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
320static char_u *p_inde;
321static char_u *p_indk;
322#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000323#if defined(FEAT_EVAL)
324static char_u *p_fex;
325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326static int p_inf;
327static char_u *p_isk;
328#ifdef FEAT_CRYPT
329static char_u *p_key;
330#endif
331#ifdef FEAT_LISP
332static int p_lisp;
333#endif
334static int p_ml;
335static int p_ma;
336static int p_mod;
337static char_u *p_mps;
338static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static 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 */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200438#define P_NODUP 0x10000L /* don't allow duplicate strings */
439#define P_FLAGLIST 0x20000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440
Bram Moolenaar913077c2012-03-28 19:59:04 +0200441#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 */
444#define P_NFNAME 0x200000L /* only normal file name chars allowed */
445#define P_INSECURE 0x400000L /* option was set from a modeline */
446#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000447 side effects) */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200448#define P_NO_ML 0x1000000L /* not allowed in modeline */
449#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
450 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000452#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
453
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000454/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
455 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000456#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000457# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000458#else
459# define ISP_LATIN1 (char_u *)"@,161-255"
460#endif
461
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000462/* The 16 bit MS-DOS version is low on space, make the string as short as
463 * possible when compiling with few features. */
464#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
465 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200466 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100467# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,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,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000468#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100469# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000470#endif
471
Bram Moolenaar071d4272004-06-13 20:20:40 +0000472/*
473 * options[] is initialized here.
474 * The order of the options MUST be alphabetic for ":set all" and findoption().
475 * All option names MUST start with a lowercase letter (for findoption()).
476 * Exception: "t_" options are at the end.
477 * The options with a NULL variable are 'hidden': a set command for them is
478 * ignored and they are not printed.
479 */
480static struct vimoption
481#ifdef FEAT_GUI_W16
482 _far
483#endif
484 options[] =
485{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200486 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000487#ifdef FEAT_RIGHTLEFT
488 (char_u *)&p_aleph, PV_NONE,
489#else
490 (char_u *)NULL, PV_NONE,
491#endif
492 {
493#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
494 (char_u *)128L,
495#else
496 (char_u *)224L,
497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
500#if defined(FEAT_GUI) && defined(MACOS_X)
501 (char_u *)&p_antialias, PV_NONE,
502 {(char_u *)FALSE, (char_u *)FALSE}
503#else
504 (char_u *)NULL, PV_NONE,
505 {(char_u *)FALSE, (char_u *)FALSE}
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200508 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509#ifdef FEAT_ARABIC
510 (char_u *)VAR_WIN, PV_ARAB,
511#else
512 (char_u *)NULL, PV_NONE,
513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
516#ifdef FEAT_ARABIC
517 (char_u *)&p_arshape, PV_NONE,
518#else
519 (char_u *)NULL, PV_NONE,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
523#ifdef FEAT_RIGHTLEFT
524 (char_u *)&p_ari, PV_NONE,
525#else
526 (char_u *)NULL, PV_NONE,
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
530#ifdef FEAT_FKMAP
531 (char_u *)&p_altkeymap, PV_NONE,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
537#if defined(FEAT_MBYTE)
538 (char_u *)&p_ambw, PV_NONE,
539 {(char_u *)"single", (char_u *)0L}
540#else
541 (char_u *)NULL, PV_NONE,
542 {(char_u *)0L, (char_u *)0L}
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000545#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"autochdir", "acd", P_BOOL|P_VI_DEF,
547 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549#endif
550 {"autoindent", "ai", P_BOOL|P_VI_DEF,
551 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autoprint", "ap", P_BOOL|P_VI_DEF,
554 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000557 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autowrite", "aw", P_BOOL|P_VI_DEF,
560 (char_u *)&p_aw, 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 {"autowriteall","awa", P_BOOL|P_VI_DEF,
563 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
566 (char_u *)&p_bg, PV_NONE,
567 {
568#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
569 (char_u *)"dark",
570#else
571 (char_u *)"light",
572#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
575 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
578 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
581 (char_u *)&p_bkc, PV_NONE,
582#ifdef UNIX
583 {(char_u *)"yes", (char_u *)"auto"}
584#else
585 {(char_u *)"auto", (char_u *)"auto"}
586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
589 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000591 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bex, PV_NONE,
593 {
594#ifdef VMS
595 (char_u *)"_",
596#else
597 (char_u *)"~",
598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000599 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
601#ifdef FEAT_WILDIGN
602 (char_u *)&p_bsk, PV_NONE,
603 {(char_u *)"", (char_u *)0L}
604#else
605 (char_u *)NULL, PV_NONE,
606 {(char_u *)0L, (char_u *)0L}
607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609#ifdef FEAT_BEVAL
610 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
611 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
614 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000616# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000617 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000618 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000620# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621#endif
622 {"beautify", "bf", P_BOOL|P_VI_DEF,
623 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
626 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
629#ifdef MSDOS
630 (char_u *)&p_biosk, PV_NONE,
631#else
632 (char_u *)NULL, PV_NONE,
633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
636#ifdef FEAT_MBYTE
637 (char_u *)&p_bomb, PV_BOMB,
638#else
639 (char_u *)NULL, PV_NONE,
640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
643#ifdef FEAT_LINEBREAK
644 (char_u *)&p_breakat, PV_NONE,
645 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
646#else
647 (char_u *)NULL, PV_NONE,
648 {(char_u *)0L, (char_u *)0L}
649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000650 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
652#ifdef FEAT_BROWSE
653 (char_u *)&p_bsdir, PV_NONE,
654 {(char_u *)"last", (char_u *)0L}
655#else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000659 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
661#if defined(FEAT_QUICKFIX)
662 (char_u *)&p_bh, PV_BH,
663 {(char_u *)"", (char_u *)0L}
664#else
665 (char_u *)NULL, PV_NONE,
666 {(char_u *)0L, (char_u *)0L}
667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000668 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
670 (char_u *)&p_bl, PV_BL,
671 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
674#if defined(FEAT_QUICKFIX)
675 (char_u *)&p_bt, PV_BT,
676 {(char_u *)"", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000683#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 (char_u *)&p_cmp, PV_NONE,
685 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
692#ifdef FEAT_SEARCHPATH
693 (char_u *)&p_cdpath, PV_NONE,
694 {(char_u *)",,", (char_u *)0L}
695#else
696 (char_u *)NULL, PV_NONE,
697 {(char_u *)0L, (char_u *)0L}
698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000699 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000700 {"cedit", NULL, P_STRING,
701#ifdef FEAT_CMDWIN
702 (char_u *)&p_cedit, PV_NONE,
703 {(char_u *)"", (char_u *)CTRL_F_STR}
704#else
705 (char_u *)NULL, PV_NONE,
706 {(char_u *)0L, (char_u *)0L}
707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
710#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
711 (char_u *)&p_ccv, PV_NONE,
712 {(char_u *)"", (char_u *)0L}
713#else
714 (char_u *)NULL, PV_NONE,
715 {(char_u *)0L, (char_u *)0L}
716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
719#ifdef FEAT_CINDENT
720 (char_u *)&p_cin, PV_CIN,
721#else
722 (char_u *)NULL, PV_NONE,
723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
726#ifdef FEAT_CINDENT
727 (char_u *)&p_cink, PV_CINK,
728 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
729#else
730 (char_u *)NULL, PV_NONE,
731 {(char_u *)0L, (char_u *)0L}
732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000733 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
735#ifdef FEAT_CINDENT
736 (char_u *)&p_cino, PV_CINO,
737#else
738 (char_u *)NULL, PV_NONE,
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
742#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
743 (char_u *)&p_cinw, PV_CINW,
744 {(char_u *)"if,else,while,do,for,switch",
745 (char_u *)0L}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
752#ifdef FEAT_CLIPBOARD
753 (char_u *)&p_cb, PV_NONE,
754# ifdef FEAT_XCLIPBOARD
755 {(char_u *)"autoselect,exclude:cons\\|linux",
756 (char_u *)0L}
757# else
758 {(char_u *)"", (char_u *)0L}
759# endif
760#else
761 (char_u *)NULL, PV_NONE,
762 {(char_u *)"", (char_u *)0L}
763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000764 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
766 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
769#ifdef FEAT_CMDWIN
770 (char_u *)&p_cwh, PV_NONE,
771#else
772 (char_u *)NULL, PV_NONE,
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200775 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
776#ifdef FEAT_SYN_HL
777 (char_u *)VAR_WIN, PV_CC,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
781 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
783 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200785 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_COMMENTS
787 (char_u *)&p_com, PV_COM,
788 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
789 (char_u *)0L}
790#else
791 (char_u *)NULL, PV_NONE,
792 {(char_u *)0L, (char_u *)0L}
793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000794 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200795 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796#ifdef FEAT_FOLDING
797 (char_u *)&p_cms, PV_CMS,
798 {(char_u *)"/*%s*/", (char_u *)0L}
799#else
800 (char_u *)NULL, PV_NONE,
801 {(char_u *)0L, (char_u *)0L}
802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000804 /* P_PRI_MKRC isn't needed here, optval_default()
805 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806 {"compatible", "cp", P_BOOL|P_RALL,
807 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
810#ifdef FEAT_INS_EXPAND
811 (char_u *)&p_cpt, PV_CPT,
812 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
813#else
814 (char_u *)NULL, PV_NONE,
815 {(char_u *)0L, (char_u *)0L}
816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200818 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200819#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200820 (char_u *)VAR_WIN, PV_COCU,
821 {(char_u *)"", (char_u *)NULL}
822#else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)NULL, (char_u *)0L}
825#endif
826 SCRIPTID_INIT},
827 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
828#ifdef FEAT_CONCEAL
829 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200830#else
831 (char_u *)NULL, PV_NONE,
832#endif
833 {(char_u *)0L, (char_u *)0L}
834 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000835 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
836#ifdef FEAT_COMPL_FUNC
837 (char_u *)&p_cfu, PV_CFU,
838 {(char_u *)"", (char_u *)0L}
839#else
840 (char_u *)NULL, PV_NONE,
841 {(char_u *)0L, (char_u *)0L}
842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000843 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000844 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
845#ifdef FEAT_INS_EXPAND
846 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000847 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853 {"confirm", "cf", P_BOOL|P_VI_DEF,
854#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
855 (char_u *)&p_confirm, PV_NONE,
856#else
857 (char_u *)NULL, PV_NONE,
858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000860 {"conskey", "consk",P_BOOL|P_VI_DEF,
861#ifdef MSDOS
862 (char_u *)&p_consk, PV_NONE,
863#else
864 (char_u *)NULL, PV_NONE,
865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
868 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000870 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
871 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000872 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
873 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200874 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200875#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200876 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200877 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200878#else
879 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200880 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200881#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200882 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
884#ifdef FEAT_CSCOPE
885 (char_u *)&p_cspc, PV_NONE,
886#else
887 (char_u *)NULL, PV_NONE,
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
891#ifdef FEAT_CSCOPE
892 (char_u *)&p_csprg, PV_NONE,
893 {(char_u *)"cscope", (char_u *)0L}
894#else
895 (char_u *)NULL, PV_NONE,
896 {(char_u *)0L, (char_u *)0L}
897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
900#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
901 (char_u *)&p_csqf, PV_NONE,
902 {(char_u *)"", (char_u *)0L}
903#else
904 (char_u *)NULL, PV_NONE,
905 {(char_u *)0L, (char_u *)0L}
906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200908 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
909#ifdef FEAT_CSCOPE
910 (char_u *)&p_csre, PV_NONE,
911#else
912 (char_u *)NULL, PV_NONE,
913#endif
914 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
916#ifdef FEAT_CSCOPE
917 (char_u *)&p_cst, PV_NONE,
918#else
919 (char_u *)NULL, PV_NONE,
920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000921 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
923#ifdef FEAT_CSCOPE
924 (char_u *)&p_csto, PV_NONE,
925#else
926 (char_u *)NULL, PV_NONE,
927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000928 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
930#ifdef FEAT_CSCOPE
931 (char_u *)&p_csverbose, PV_NONE,
932#else
933 (char_u *)NULL, PV_NONE,
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200936 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
937#ifdef FEAT_CURSORBIND
938 (char_u *)VAR_WIN, PV_CRBIND,
939#else
940 (char_u *)NULL, PV_NONE,
941#endif
942 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000943 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
944#ifdef FEAT_SYN_HL
945 (char_u *)VAR_WIN, PV_CUC,
946#else
947 (char_u *)NULL, PV_NONE,
948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000949 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000950 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
951#ifdef FEAT_SYN_HL
952 (char_u *)VAR_WIN, PV_CUL,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000956 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"debug", NULL, P_STRING|P_VI_DEF,
958 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000959 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200960 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000962 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000963 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964#else
965 (char_u *)NULL, PV_NONE,
966 {(char_u *)NULL, (char_u *)0L}
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
970#ifdef FEAT_MBYTE
971 (char_u *)&p_deco, PV_NONE,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
977#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000978 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
984#ifdef FEAT_DIFF
985 (char_u *)VAR_WIN, PV_DIFF,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200990 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
992 (char_u *)&p_dex, PV_NONE,
993 {(char_u *)"", (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 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
1000#ifdef FEAT_DIFF
1001 (char_u *)&p_dip, PV_NONE,
1002 {(char_u *)"filler", (char_u *)NULL}
1003#else
1004 (char_u *)NULL, PV_NONE,
1005 {(char_u *)"", (char_u *)NULL}
1006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1009#ifdef FEAT_DIGRAPHS
1010 (char_u *)&p_dg, PV_NONE,
1011#else
1012 (char_u *)NULL, PV_NONE,
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1016 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1019 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021 {"eadirection", "ead", P_STRING|P_VI_DEF,
1022#ifdef FEAT_VERTSPLIT
1023 (char_u *)&p_ead, PV_NONE,
1024 {(char_u *)"both", (char_u *)0L}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)NULL, (char_u *)0L}
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1031 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001033 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034#ifdef FEAT_MBYTE
1035 (char_u *)&p_enc, PV_NONE,
1036 {(char_u *)ENC_DFLT, (char_u *)0L}
1037#else
1038 (char_u *)NULL, PV_NONE,
1039 {(char_u *)0L, (char_u *)0L}
1040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1043 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1046 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001049 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1052 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1055#ifdef FEAT_QUICKFIX
1056 (char_u *)&p_ef, PV_NONE,
1057 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)NULL, (char_u *)0L}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1064#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001065 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067#else
1068 (char_u *)NULL, PV_NONE,
1069 {(char_u *)NULL, (char_u *)0L}
1070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"esckeys", "ek", P_BOOL|P_VIM,
1073 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1076#ifdef FEAT_AUTOCMD
1077 (char_u *)&p_ei, PV_NONE,
1078#else
1079 (char_u *)NULL, PV_NONE,
1080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1083 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1086 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1089#ifdef FEAT_MBYTE
1090 (char_u *)&p_fenc, PV_FENC,
1091 {(char_u *)"", (char_u *)0L}
1092#else
1093 (char_u *)NULL, PV_NONE,
1094 {(char_u *)0L, (char_u *)0L}
1095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1098#ifdef FEAT_MBYTE
1099 (char_u *)&p_fencs, PV_NONE,
1100 {(char_u *)"ucs-bom", (char_u *)0L}
1101#else
1102 (char_u *)NULL, PV_NONE,
1103 {(char_u *)0L, (char_u *)0L}
1104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001106 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1110 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1112 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001113 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1114 (char_u *)&p_fic, PV_NONE,
1115 {
1116#ifdef CASE_INSENSITIVE_FILENAME
1117 (char_u *)TRUE,
1118#else
1119 (char_u *)FALSE,
1120#endif
1121 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001122 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_AUTOCMD
1124 (char_u *)&p_ft, PV_FT,
1125 {(char_u *)"", (char_u *)0L}
1126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)0L, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1132#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1133 (char_u *)&p_fcs, PV_NONE,
1134 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1135#else
1136 (char_u *)NULL, PV_NONE,
1137 {(char_u *)"", (char_u *)0L}
1138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1141#ifdef FEAT_FKMAP
1142 (char_u *)&p_fkmap, PV_NONE,
1143#else
1144 (char_u *)NULL, PV_NONE,
1145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"flash", "fl", P_BOOL|P_VI_DEF,
1148 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150#ifdef FEAT_FOLDING
1151 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1152 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1155 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1158 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001159 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1161# ifdef FEAT_EVAL
1162 (char_u *)VAR_WIN, PV_FDE,
1163 {(char_u *)"0", (char_u *)NULL}
1164# else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)NULL, (char_u *)0L}
1167# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1170 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1173 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001174 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001175 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001177 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1179 P_RWIN|P_COMMA|P_NODUP,
1180 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)"{{{,}}}", (char_u *)NULL}
1182 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1184 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1187 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1190 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001192 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193 (char_u *)&p_fdo, PV_NONE,
1194 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001195 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1197# ifdef FEAT_EVAL
1198 (char_u *)VAR_WIN, PV_FDT,
1199 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001200# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)NULL, PV_NONE,
1202 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001203# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001205#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001206 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001207#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001208 (char_u *)&p_fex, PV_FEX,
1209 {(char_u *)"", (char_u *)0L}
1210#else
1211 (char_u *)NULL, PV_NONE,
1212 {(char_u *)0L, (char_u *)0L}
1213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1216 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1218 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001219 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1220 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1222 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1224 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001225 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001226 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1227#ifdef HAVE_FSYNC
1228 (char_u *)&p_fs, PV_NONE,
1229 {(char_u *)TRUE, (char_u *)0L}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)FALSE, (char_u *)0L}
1233#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001234 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1236 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"graphic", "gr", P_BOOL|P_VI_DEF,
1239 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001240 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1242#ifdef FEAT_QUICKFIX
1243 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)NULL, (char_u *)0L}
1248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1251#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001252 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253 {
1254# ifdef WIN3264
1255 /* may be changed to "grep -n" in os_win32.c */
1256 (char_u *)"findstr /n",
1257# else
1258# ifdef UNIX
1259 /* Add an extra file name so that grep will always
1260 * insert a file name in the match line. */
1261 (char_u *)"grep -n $* /dev/null",
1262# else
1263# ifdef VMS
1264 (char_u *)"SEARCH/NUMBERS ",
1265# else
1266 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267# endif
1268# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001269# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001270 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)NULL, (char_u *)0L}
1274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1277#ifdef CURSOR_SHAPE
1278 (char_u *)&p_guicursor, PV_NONE,
1279 {
1280# ifdef FEAT_GUI
1281 (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",
1282# else /* MSDOS or Win32 console */
1283 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1284# endif
1285 (char_u *)0L}
1286#else
1287 (char_u *)NULL, PV_NONE,
1288 {(char_u *)NULL, (char_u *)0L}
1289#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001290 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1292#ifdef FEAT_GUI
1293 (char_u *)&p_guifont, PV_NONE,
1294 {(char_u *)"", (char_u *)0L}
1295#else
1296 (char_u *)NULL, PV_NONE,
1297 {(char_u *)NULL, (char_u *)0L}
1298#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001299 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1301#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1302 (char_u *)&p_guifontset, PV_NONE,
1303 {(char_u *)"", (char_u *)0L}
1304#else
1305 (char_u *)NULL, PV_NONE,
1306 {(char_u *)NULL, (char_u *)0L}
1307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1310#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1311 (char_u *)&p_guifontwide, PV_NONE,
1312 {(char_u *)"", (char_u *)0L}
1313#else
1314 (char_u *)NULL, PV_NONE,
1315 {(char_u *)NULL, (char_u *)0L}
1316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001317 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001319#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 (char_u *)&p_ghr, PV_NONE,
1321#else
1322 (char_u *)NULL, PV_NONE,
1323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001324 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001326#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327 (char_u *)&p_go, PV_NONE,
1328# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001329 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001331 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332# endif
1333#else
1334 (char_u *)NULL, PV_NONE,
1335 {(char_u *)NULL, (char_u *)0L}
1336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001337 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {"guipty", NULL, P_BOOL|P_VI_DEF,
1339#if defined(FEAT_GUI)
1340 (char_u *)&p_guipty, PV_NONE,
1341#else
1342 (char_u *)NULL, PV_NONE,
1343#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001345 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001346#if defined(FEAT_GUI_TABLINE)
1347 (char_u *)&p_gtl, PV_NONE,
1348 {(char_u *)"", (char_u *)0L}
1349#else
1350 (char_u *)NULL, PV_NONE,
1351 {(char_u *)NULL, (char_u *)0L}
1352#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001353 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001354 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001355#if defined(FEAT_GUI_TABLINE)
1356 (char_u *)&p_gtt, PV_NONE,
1357 {(char_u *)"", (char_u *)0L}
1358#else
1359 (char_u *)NULL, PV_NONE,
1360 {(char_u *)NULL, (char_u *)0L}
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1364 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001365 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1367 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001368 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1369 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370 {"helpheight", "hh", P_NUM|P_VI_DEF,
1371#ifdef FEAT_WINDOWS
1372 (char_u *)&p_hh, PV_NONE,
1373#else
1374 (char_u *)NULL, PV_NONE,
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1378#ifdef FEAT_MULTI_LANG
1379 (char_u *)&p_hlg, PV_NONE,
1380 {(char_u *)"", (char_u *)0L}
1381#else
1382 (char_u *)NULL, PV_NONE,
1383 {(char_u *)0L, (char_u *)0L}
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {"hidden", "hid", P_BOOL|P_VI_DEF,
1387 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1390 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 {"history", "hi", P_NUM|P_VIM,
1394 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001395 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1397#ifdef FEAT_RIGHTLEFT
1398 (char_u *)&p_hkmap, PV_NONE,
1399#else
1400 (char_u *)NULL, PV_NONE,
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1404#ifdef FEAT_RIGHTLEFT
1405 (char_u *)&p_hkmapp, PV_NONE,
1406#else
1407 (char_u *)NULL, PV_NONE,
1408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1411 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001412 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413 {"icon", NULL, P_BOOL|P_VI_DEF,
1414#ifdef FEAT_TITLE
1415 (char_u *)&p_icon, PV_NONE,
1416#else
1417 (char_u *)NULL, PV_NONE,
1418#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001419 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420 {"iconstring", NULL, P_STRING|P_VI_DEF,
1421#ifdef FEAT_TITLE
1422 (char_u *)&p_iconstring, PV_NONE,
1423#else
1424 (char_u *)NULL, PV_NONE,
1425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1428 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001430 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1431# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1432 (char_u *)&p_imaf, PV_NONE,
1433 {(char_u *)"", (char_u *)NULL}
1434# else
1435 (char_u *)NULL, PV_NONE,
1436 {(char_u *)NULL, (char_u *)0L}
1437# endif
1438 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001439 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001440#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441 (char_u *)&p_imak, PV_NONE,
1442#else
1443 (char_u *)NULL, PV_NONE,
1444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001445 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1447#ifdef USE_IM_CONTROL
1448 (char_u *)&p_imcmdline, PV_NONE,
1449#else
1450 (char_u *)NULL, PV_NONE,
1451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1454#ifdef USE_IM_CONTROL
1455 (char_u *)&p_imdisable, PV_NONE,
1456#else
1457 (char_u *)NULL, PV_NONE,
1458#endif
1459#ifdef __sgi
1460 {(char_u *)TRUE, (char_u *)0L}
1461#else
1462 {(char_u *)FALSE, (char_u *)0L}
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"iminsert", "imi", P_NUM|P_VI_DEF,
1466 (char_u *)&p_iminsert, PV_IMI,
1467#ifdef B_IMODE_IM
1468 {(char_u *)B_IMODE_IM, (char_u *)0L}
1469#else
1470 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001472 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {"imsearch", "ims", P_NUM|P_VI_DEF,
1474 (char_u *)&p_imsearch, PV_IMS,
1475#ifdef B_IMODE_IM
1476 {(char_u *)B_IMODE_IM, (char_u *)0L}
1477#else
1478 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001481 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001482# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1483 (char_u *)&p_imsf, PV_NONE,
1484 {(char_u *)"", (char_u *)NULL}
1485# else
1486 (char_u *)NULL, PV_NONE,
1487 {(char_u *)NULL, (char_u *)0L}
1488# endif
1489 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1491#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001492 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1494#else
1495 (char_u *)NULL, PV_NONE,
1496 {(char_u *)0L, (char_u *)0L}
1497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1500#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1501 (char_u *)&p_inex, PV_INEX,
1502 {(char_u *)"", (char_u *)0L}
1503#else
1504 (char_u *)NULL, PV_NONE,
1505 {(char_u *)0L, (char_u *)0L}
1506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001507 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1509 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001510 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1512#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1513 (char_u *)&p_inde, PV_INDE,
1514 {(char_u *)"", (char_u *)0L}
1515#else
1516 (char_u *)NULL, PV_NONE,
1517 {(char_u *)0L, (char_u *)0L}
1518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1521#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1522 (char_u *)&p_indk, PV_INDK,
1523 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1524#else
1525 (char_u *)NULL, PV_NONE,
1526 {(char_u *)0L, (char_u *)0L}
1527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001528 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"infercase", "inf", P_BOOL|P_VI_DEF,
1530 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1533 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001535 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1536 (char_u *)&p_isf, PV_NONE,
1537 {
1538#ifdef BACKSLASH_IN_FILENAME
1539 /* Excluded are: & and ^ are special in cmd.exe
1540 * ( and ) are used in text separating fnames */
1541 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1542#else
1543# ifdef AMIGA
1544 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1545# else
1546# ifdef VMS
1547 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1548# else /* UNIX et al. */
1549# ifdef EBCDIC
1550 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1551# else
1552 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1553# endif
1554# endif
1555# endif
1556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1559 (char_u *)&p_isi, PV_NONE,
1560 {
1561#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1562 (char_u *)"@,48-57,_,128-167,224-235",
1563#else
1564# ifdef EBCDIC
1565 /* TODO: EBCDIC Check this! @ == isalpha()*/
1566 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1567 "112-120,128,140-142,156,158,172,"
1568 "174,186,191,203-207,219-225,235-239,"
1569 "251-254",
1570# else
1571 (char_u *)"@,48-57,_,192-255",
1572# endif
1573#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001574 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1576 (char_u *)&p_isk, PV_ISK,
1577 {
1578#ifdef EBCDIC
1579 (char_u *)"@,240-249,_",
1580 /* TODO: EBCDIC Check this! @ == isalpha()*/
1581 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1582 "112-120,128,140-142,156,158,172,"
1583 "174,186,191,203-207,219-225,235-239,"
1584 "251-254",
1585#else
1586 (char_u *)"@,48-57,_",
1587# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1588 (char_u *)"@,48-57,_,128-167,224-235"
1589# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001590 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001591# endif
1592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001593 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1595 (char_u *)&p_isp, PV_NONE,
1596 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001597#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1598 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 || defined(VMS)
1600 (char_u *)"@,~-255",
1601#else
1602# ifdef EBCDIC
1603 /* all chars above 63 are printable */
1604 (char_u *)"63-255",
1605# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001606 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607# endif
1608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001609 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001610 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1611 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001612 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1614#ifdef FEAT_CRYPT
1615 (char_u *)&p_key, PV_KEY,
1616 {(char_u *)"", (char_u *)0L}
1617#else
1618 (char_u *)NULL, PV_NONE,
1619 {(char_u *)0L, (char_u *)0L}
1620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001621 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001622 {"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 +00001623#ifdef FEAT_KEYMAP
1624 (char_u *)&p_keymap, PV_KMAP,
1625 {(char_u *)"", (char_u *)0L}
1626#else
1627 (char_u *)NULL, PV_NONE,
1628 {(char_u *)"", (char_u *)0L}
1629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001630 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001633 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001634 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001635 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 {
1637#if defined(MSDOS) || defined(MSWIN)
1638 (char_u *)":help",
1639#else
1640#ifdef VMS
1641 (char_u *)"help",
1642#else
1643# if defined(OS2)
1644 (char_u *)"view /",
1645# else
1646# ifdef USEMAN_S
1647 (char_u *)"man -s",
1648# else
1649 (char_u *)"man",
1650# endif
1651# endif
1652#endif
1653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001654 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaared7547d2014-05-13 12:17:15 +02001655 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656#ifdef FEAT_LANGMAP
1657 (char_u *)&p_langmap, PV_NONE,
1658 {(char_u *)"", /* unmatched } */
1659#else
1660 (char_u *)NULL, PV_NONE,
1661 {(char_u *)NULL,
1662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001663 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001664 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1666 (char_u *)&p_lm, PV_NONE,
1667#else
1668 (char_u *)NULL, PV_NONE,
1669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1672#ifdef FEAT_WINDOWS
1673 (char_u *)&p_ls, PV_NONE,
1674#else
1675 (char_u *)NULL, PV_NONE,
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1679 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001680 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1682#ifdef FEAT_LINEBREAK
1683 (char_u *)VAR_WIN, PV_LBR,
1684#else
1685 (char_u *)NULL, PV_NONE,
1686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001687 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1689 (char_u *)&Rows, PV_NONE,
1690 {
1691#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1692 (char_u *)25L,
1693#else
1694 (char_u *)24L,
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1698#ifdef FEAT_GUI
1699 (char_u *)&p_linespace, PV_NONE,
1700#else
1701 (char_u *)NULL, PV_NONE,
1702#endif
1703#ifdef FEAT_GUI_W32
1704 {(char_u *)1L, (char_u *)0L}
1705#else
1706 {(char_u *)0L, (char_u *)0L}
1707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709 {"lisp", NULL, P_BOOL|P_VI_DEF,
1710#ifdef FEAT_LISP
1711 (char_u *)&p_lisp, PV_LISP,
1712#else
1713 (char_u *)NULL, PV_NONE,
1714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1717#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001718 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1720#else
1721 (char_u *)NULL, PV_NONE,
1722 {(char_u *)"", (char_u *)0L}
1723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1726 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001727 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001728 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1729 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1732 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001733 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001734#ifdef FEAT_GUI_MAC
1735 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1736 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"magic", NULL, P_BOOL|P_VI_DEF,
1740 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001742 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743#ifdef FEAT_QUICKFIX
1744 (char_u *)&p_mef, PV_NONE,
1745 {(char_u *)"", (char_u *)0L}
1746#else
1747 (char_u *)NULL, PV_NONE,
1748 {(char_u *)NULL, (char_u *)0L}
1749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1752#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001753 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754# ifdef VMS
1755 {(char_u *)"MMS", (char_u *)0L}
1756# else
1757 {(char_u *)"make", (char_u *)0L}
1758# endif
1759#else
1760 (char_u *)NULL, PV_NONE,
1761 {(char_u *)NULL, (char_u *)0L}
1762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1765 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001766 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"matchtime", "mat", P_NUM|P_VI_DEF,
1769 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001771 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001772#ifdef FEAT_MBYTE
1773 (char_u *)&p_mco, PV_NONE,
1774#else
1775 (char_u *)NULL, PV_NONE,
1776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1779#ifdef FEAT_EVAL
1780 (char_u *)&p_mfd, PV_NONE,
1781#else
1782 (char_u *)NULL, PV_NONE,
1783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1786 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001787 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"maxmem", "mm", P_NUM|P_VI_DEF,
1789 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1791 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001792 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1793 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1796 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001797 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1798 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 {"menuitems", "mis", P_NUM|P_VI_DEF,
1800#ifdef FEAT_MENU
1801 (char_u *)&p_mis, PV_NONE,
1802#else
1803 (char_u *)NULL, PV_NONE,
1804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001805 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001806 {"mesg", NULL, P_BOOL|P_VI_DEF,
1807 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001809 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001810#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001811 (char_u *)&p_msm, PV_NONE,
1812 {(char_u *)"460000,2000,500", (char_u *)0L}
1813#else
1814 (char_u *)NULL, PV_NONE,
1815 {(char_u *)0L, (char_u *)0L}
1816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"modeline", "ml", P_BOOL|P_VIM,
1819 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"modelines", "mls", P_NUM|P_VI_DEF,
1822 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1825 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001826 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1828 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001829 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"more", NULL, P_BOOL|P_VIM,
1831 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1834 (char_u *)&p_mouse, PV_NONE,
1835 {
1836#if defined(MSDOS) || defined(WIN3264)
1837 (char_u *)"a",
1838#else
1839 (char_u *)"",
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1843#ifdef FEAT_GUI
1844 (char_u *)&p_mousef, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1850#ifdef FEAT_GUI
1851 (char_u *)&p_mh, PV_NONE,
1852#else
1853 (char_u *)NULL, PV_NONE,
1854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1857 (char_u *)&p_mousem, PV_NONE,
1858 {
1859#if defined(MSDOS) || defined(MSWIN)
1860 (char_u *)"popup",
1861#else
1862# if defined(MACOS)
1863 (char_u *)"popup_setpos",
1864# else
1865 (char_u *)"extend",
1866# endif
1867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1870#ifdef FEAT_MOUSESHAPE
1871 (char_u *)&p_mouseshape, PV_NONE,
1872 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1873#else
1874 (char_u *)NULL, PV_NONE,
1875 {(char_u *)NULL, (char_u *)0L}
1876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1879 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001881 {"mzquantum", "mzq", P_NUM,
1882#ifdef FEAT_MZSCHEME
1883 (char_u *)&p_mzq, PV_NONE,
1884#else
1885 (char_u *)NULL, PV_NONE,
1886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"novice", NULL, P_BOOL|P_VI_DEF,
1889 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1892 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 {(char_u *)"octal,hex", (char_u *)0L}
1894 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1896 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001897 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001898 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1899#ifdef FEAT_LINEBREAK
1900 (char_u *)VAR_WIN, PV_NUW,
1901#else
1902 (char_u *)NULL, PV_NONE,
1903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001905 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001906#ifdef FEAT_COMPL_FUNC
1907 (char_u *)&p_ofu, PV_OFU,
1908 {(char_u *)"", (char_u *)0L}
1909#else
1910 (char_u *)NULL, PV_NONE,
1911 {(char_u *)0L, (char_u *)0L}
1912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001913 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 {"open", NULL, P_BOOL|P_VI_DEF,
1915 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001916 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001917 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1918#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1919 (char_u *)&p_odev, PV_NONE,
1920#else
1921 (char_u *)NULL, PV_NONE,
1922#endif
1923 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001925 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1926 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"optimize", "opt", P_BOOL|P_VI_DEF,
1929 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001933 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 {"paragraphs", "para", P_STRING|P_VI_DEF,
1935 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001936 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001938 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1942 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1945#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1946 (char_u *)&p_pex, PV_NONE,
1947 {(char_u *)"", (char_u *)0L}
1948#else
1949 (char_u *)NULL, PV_NONE,
1950 {(char_u *)0L, (char_u *)0L}
1951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001953 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001957 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {
1959#if defined AMIGA || defined MSDOS || defined MSWIN
1960 (char_u *)".,,",
1961#else
1962# if defined(__EMX__)
1963 (char_u *)".,/emx/include,,",
1964# else /* Unix, probably */
1965 (char_u *)".,/usr/include,,",
1966# endif
1967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001968 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001969 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1970 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001972 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1974 (char_u *)&p_pvh, PV_NONE,
1975#else
1976 (char_u *)NULL, PV_NONE,
1977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1980#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1981 (char_u *)VAR_WIN, PV_PVW,
1982#else
1983 (char_u *)NULL, PV_NONE,
1984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001986 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987#ifdef FEAT_PRINTER
1988 (char_u *)&p_pdev, 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 {"printencoding", "penc", P_STRING|P_VI_DEF,
1996#ifdef FEAT_POSTSCRIPT
1997 (char_u *)&p_penc, 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 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2005#ifdef FEAT_POSTSCRIPT
2006 (char_u *)&p_pexpr, PV_NONE,
2007 {(char_u *)"", (char_u *)0L}
2008#else
2009 (char_u *)NULL, PV_NONE,
2010 {(char_u *)NULL, (char_u *)0L}
2011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"printfont", "pfn", P_STRING|P_VI_DEF,
2014#ifdef FEAT_PRINTER
2015 (char_u *)&p_pfn, PV_NONE,
2016 {
2017# ifdef MSWIN
2018 (char_u *)"Courier_New:h10",
2019# else
2020 (char_u *)"courier",
2021# endif
2022 (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)NULL, (char_u *)0L}
2026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002027 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2029#ifdef FEAT_PRINTER
2030 (char_u *)&p_header, PV_NONE,
2031 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)NULL, (char_u *)0L}
2035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002037 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2038#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2039 (char_u *)&p_pmcs, PV_NONE,
2040 {(char_u *)"", (char_u *)0L}
2041#else
2042 (char_u *)NULL, PV_NONE,
2043 {(char_u *)NULL, (char_u *)0L}
2044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002046 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2047#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2048 (char_u *)&p_pmfn, PV_NONE,
2049 {(char_u *)"", (char_u *)0L}
2050#else
2051 (char_u *)NULL, PV_NONE,
2052 {(char_u *)NULL, (char_u *)0L}
2053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2056#ifdef FEAT_PRINTER
2057 (char_u *)&p_popt, PV_NONE,
2058 {(char_u *)"", (char_u *)0L}
2059#else
2060 (char_u *)NULL, PV_NONE,
2061 {(char_u *)NULL, (char_u *)0L}
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002065 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002067 {"pumheight", "ph", P_NUM|P_VI_DEF,
2068#ifdef FEAT_INS_EXPAND
2069 (char_u *)&p_ph, PV_NONE,
2070#else
2071 (char_u *)NULL, PV_NONE,
2072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002073 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002074 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2075#ifdef FEAT_TEXTOBJ
2076 (char_u *)&p_qe, PV_QE,
2077 {(char_u *)"\\", (char_u *)0L}
2078#else
2079 (char_u *)NULL, PV_NONE,
2080 {(char_u *)NULL, (char_u *)0L}
2081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002082 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2084 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"redraw", NULL, P_BOOL|P_VI_DEF,
2087 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002089 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2090#ifdef FEAT_RELTIME
2091 (char_u *)&p_rdt, PV_NONE,
2092#else
2093 (char_u *)NULL, PV_NONE,
2094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002096 {"regexpengine", "re", P_NUM|P_VI_DEF,
2097 (char_u *)&p_re, PV_NONE,
2098 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002099 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2100 (char_u *)VAR_WIN, PV_RNU,
2101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {"remap", NULL, P_BOOL|P_VI_DEF,
2103 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"report", NULL, P_NUM|P_VI_DEF,
2106 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2109#ifdef WIN3264
2110 (char_u *)&p_rs, PV_NONE,
2111#else
2112 (char_u *)NULL, PV_NONE,
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2116#ifdef FEAT_RIGHTLEFT
2117 (char_u *)&p_ri, PV_NONE,
2118#else
2119 (char_u *)NULL, PV_NONE,
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2123#ifdef FEAT_RIGHTLEFT
2124 (char_u *)VAR_WIN, PV_RL,
2125#else
2126 (char_u *)NULL, PV_NONE,
2127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2130#ifdef FEAT_RIGHTLEFT
2131 (char_u *)VAR_WIN, PV_RLC,
2132 {(char_u *)"search", (char_u *)NULL}
2133#else
2134 (char_u *)NULL, PV_NONE,
2135 {(char_u *)NULL, (char_u *)0L}
2136#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2139#ifdef FEAT_CMDL_INFO
2140 (char_u *)&p_ru, PV_NONE,
2141#else
2142 (char_u *)NULL, PV_NONE,
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2146#ifdef FEAT_STL_OPT
2147 (char_u *)&p_ruf, PV_NONE,
2148#else
2149 (char_u *)NULL, PV_NONE,
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2153 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2155 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2157 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002158 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2160#ifdef FEAT_SCROLLBIND
2161 (char_u *)VAR_WIN, PV_SCBIND,
2162#else
2163 (char_u *)NULL, PV_NONE,
2164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002165 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2167 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2170 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002171 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2173#ifdef FEAT_SCROLLBIND
2174 (char_u *)&p_sbo, PV_NONE,
2175 {(char_u *)"ver,jump", (char_u *)0L}
2176#else
2177 (char_u *)NULL, PV_NONE,
2178 {(char_u *)0L, (char_u *)0L}
2179#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002180 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 {"sections", "sect", P_STRING|P_VI_DEF,
2182 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002183 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2184 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2186 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002190 {(char_u *)"inclusive", (char_u *)0L}
2191 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002194 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2196#ifdef FEAT_SESSION
2197 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002198 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002199 (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)0L, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2206 (char_u *)&p_sh, PV_NONE,
2207 {
2208#ifdef VMS
2209 (char_u *)"-",
2210#else
2211# if defined(MSDOS)
2212 (char_u *)"command",
2213# else
2214# if defined(WIN16)
2215 (char_u *)"command.com",
2216# else
2217# if defined(WIN3264)
2218 (char_u *)"", /* set in set_init_1() */
2219# else
2220# if defined(OS2)
2221 (char_u *)"cmd.exe",
2222# else
2223# if defined(ARCHIE)
2224 (char_u *)"gos",
2225# else
2226 (char_u *)"sh",
2227# endif
2228# endif
2229# endif
2230# endif
2231# endif
2232#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2235 (char_u *)&p_shcf, PV_NONE,
2236 {
2237#if defined(MSDOS) || defined(MSWIN)
2238 (char_u *)"/c",
2239#else
2240# if defined(OS2)
2241 (char_u *)"/c",
2242# else
2243 (char_u *)"-c",
2244# endif
2245#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2248#ifdef FEAT_QUICKFIX
2249 (char_u *)&p_sp, PV_NONE,
2250 {
2251#if defined(UNIX) || defined(OS2)
2252# ifdef ARCHIE
2253 (char_u *)"2>",
2254# else
2255 (char_u *)"| tee",
2256# endif
2257#else
2258 (char_u *)">",
2259#endif
2260 (char_u *)0L}
2261#else
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)0L, (char_u *)0L}
2264#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2267 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2270 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2273#ifdef BACKSLASH_IN_FILENAME
2274 (char_u *)&p_ssl, PV_NONE,
2275#else
2276 (char_u *)NULL, PV_NONE,
2277#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002279 {"shelltemp", "stmp", P_BOOL,
2280 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002281 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"shelltype", "st", P_NUM|P_VI_DEF,
2283#ifdef AMIGA
2284 (char_u *)&p_st, PV_NONE,
2285#else
2286 (char_u *)NULL, PV_NONE,
2287#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2290 (char_u *)&p_sxq, PV_NONE,
2291 {
2292#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2293 (char_u *)"\"",
2294#else
2295 (char_u *)"",
2296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002298 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2299 (char_u *)&p_sxe, PV_NONE,
2300 {
2301#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2302 (char_u *)"\"&|<>()@^",
2303#else
2304 (char_u *)"",
2305#endif
2306 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2308 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2311 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002312 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2314 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 {(char_u *)"", (char_u *)"filnxtToO"}
2316 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"shortname", "sn", P_BOOL|P_VI_DEF,
2318#ifdef SHORT_FNAME
2319 (char_u *)NULL, PV_NONE,
2320#else
2321 (char_u *)&p_sn, PV_SN,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2325#ifdef FEAT_LINEBREAK
2326 (char_u *)&p_sbr, PV_NONE,
2327#else
2328 (char_u *)NULL, PV_NONE,
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"showcmd", "sc", P_BOOL|P_VIM,
2332#ifdef FEAT_CMDL_INFO
2333 (char_u *)&p_sc, PV_NONE,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
2337 {(char_u *)FALSE,
2338#ifdef UNIX
2339 (char_u *)FALSE
2340#else
2341 (char_u *)TRUE
2342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2345 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2348 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"showmode", "smd", P_BOOL|P_VIM,
2351 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002353 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2354#ifdef FEAT_WINDOWS
2355 (char_u *)&p_stal, PV_NONE,
2356#else
2357 (char_u *)NULL, PV_NONE,
2358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002359 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2361 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2364 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2367 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2370 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2373#ifdef FEAT_SMARTINDENT
2374 (char_u *)&p_si, PV_SI,
2375#else
2376 (char_u *)NULL, PV_NONE,
2377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2380 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2383 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2386 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002388 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002389#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002390 (char_u *)VAR_WIN, PV_SPELL,
2391#else
2392 (char_u *)NULL, PV_NONE,
2393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002395 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002396#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002397 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002398 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002399#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 Moolenaar0d9c26d2005-07-02 23:19:16 +00002404 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002405#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002406 (char_u *)&p_spf, PV_SPF,
2407 {(char_u *)"", (char_u *)0L}
2408#else
2409 (char_u *)NULL, PV_NONE,
2410 {(char_u *)0L, (char_u *)0L}
2411#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002413 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002414#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002415 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002416 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002417#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 Moolenaar28e4c8d2006-05-09 16:15:42 +00002422 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002423#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002424 (char_u *)&p_sps, PV_NONE,
2425 {(char_u *)"best", (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 Moolenaar071d4272004-06-13 20:20:40 +00002431 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2432#ifdef FEAT_WINDOWS
2433 (char_u *)&p_sb, PV_NONE,
2434#else
2435 (char_u *)NULL, PV_NONE,
2436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"splitright", "spr", P_BOOL|P_VI_DEF,
2439#ifdef FEAT_VERTSPLIT
2440 (char_u *)&p_spr, PV_NONE,
2441#else
2442 (char_u *)NULL, PV_NONE,
2443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2446 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2449#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002450 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451#else
2452 (char_u *)NULL, PV_NONE,
2453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2456 (char_u *)&p_su, PV_NONE,
2457 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002460#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 (char_u *)&p_sua, PV_SUA,
2462 {(char_u *)"", (char_u *)0L}
2463#else
2464 (char_u *)NULL, PV_NONE,
2465 {(char_u *)0L, (char_u *)0L}
2466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2469 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"swapsync", "sws", P_STRING|P_VI_DEF,
2472 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2475 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002477 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2478#ifdef FEAT_SYN_HL
2479 (char_u *)&p_smc, PV_SMC,
2480 {(char_u *)3000L, (char_u *)0L}
2481#else
2482 (char_u *)NULL, PV_NONE,
2483 {(char_u *)0L, (char_u *)0L}
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002486 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487#ifdef FEAT_SYN_HL
2488 (char_u *)&p_syn, PV_SYN,
2489 {(char_u *)"", (char_u *)0L}
2490#else
2491 (char_u *)NULL, PV_NONE,
2492 {(char_u *)0L, (char_u *)0L}
2493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002494 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002495 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2496#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002497 (char_u *)&p_tal, PV_NONE,
2498#else
2499 (char_u *)NULL, PV_NONE,
2500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002502 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2503#ifdef FEAT_WINDOWS
2504 (char_u *)&p_tpm, PV_NONE,
2505#else
2506 (char_u *)NULL, PV_NONE,
2507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2510 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2513 (char_u *)&p_tbs, PV_NONE,
2514#ifdef VMS /* binary searching doesn't appear to work on VMS */
2515 {(char_u *)0L, (char_u *)0L}
2516#else
2517 {(char_u *)TRUE, (char_u *)0L}
2518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"taglength", "tl", P_NUM|P_VI_DEF,
2521 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"tagrelative", "tr", P_BOOL|P_VIM,
2524 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002527 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {
2529#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2530 (char_u *)"./tags,./TAGS,tags,TAGS",
2531#else
2532 (char_u *)"./tags,tags",
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2536 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2539 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2542#ifdef FEAT_ARABIC
2543 (char_u *)&p_tbidi, PV_NONE,
2544#else
2545 (char_u *)NULL, PV_NONE,
2546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2549#ifdef FEAT_MBYTE
2550 (char_u *)&p_tenc, PV_NONE,
2551 {(char_u *)"", (char_u *)0L}
2552#else
2553 (char_u *)NULL, PV_NONE,
2554 {(char_u *)0L, (char_u *)0L}
2555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"terse", NULL, P_BOOL|P_VI_DEF,
2558 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"textauto", "ta", P_BOOL|P_VIM,
2561 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2563 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2565 (char_u *)&p_tx, PV_TX,
2566 {
2567#ifdef USE_CRNL
2568 (char_u *)TRUE,
2569#else
2570 (char_u *)FALSE,
2571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002573 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2577#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002578 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579#else
2580 (char_u *)NULL, PV_NONE,
2581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2584 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"timeout", "to", P_BOOL|P_VI_DEF,
2587 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2590 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"title", NULL, P_BOOL|P_VI_DEF,
2593#ifdef FEAT_TITLE
2594 (char_u *)&p_title, PV_NONE,
2595#else
2596 (char_u *)NULL, PV_NONE,
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"titlelen", NULL, P_NUM|P_VI_DEF,
2600#ifdef FEAT_TITLE
2601 (char_u *)&p_titlelen, PV_NONE,
2602#else
2603 (char_u *)NULL, PV_NONE,
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002606 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607#ifdef FEAT_TITLE
2608 (char_u *)&p_titleold, PV_NONE,
2609 {(char_u *)N_("Thanks for flying Vim"),
2610 (char_u *)0L}
2611#else
2612 (char_u *)NULL, PV_NONE,
2613 {(char_u *)0L, (char_u *)0L}
2614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {"titlestring", NULL, P_STRING|P_VI_DEF,
2617#ifdef FEAT_TITLE
2618 (char_u *)&p_titlestring, PV_NONE,
2619#else
2620 (char_u *)NULL, PV_NONE,
2621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2624 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2625 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)"icons,tooltips", (char_u *)0L}
2627 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002629#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2631 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633#endif
2634 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2635 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2638 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2641 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2644 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2647#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2648 (char_u *)&p_ttym, PV_NONE,
2649#else
2650 (char_u *)NULL, PV_NONE,
2651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2654 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2657 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002659 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2660#ifdef FEAT_PERSISTENT_UNDO
2661 (char_u *)&p_udir, PV_NONE,
2662 {(char_u *)".", (char_u *)0L}
2663#else
2664 (char_u *)NULL, PV_NONE,
2665 {(char_u *)0L, (char_u *)0L}
2666#endif
2667 SCRIPTID_INIT},
2668 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2669#ifdef FEAT_PERSISTENT_UNDO
2670 (char_u *)&p_udf, PV_UDF,
2671#else
2672 (char_u *)NULL, PV_NONE,
2673#endif
2674 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002676 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {
2678#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2679 (char_u *)1000L,
2680#else
2681 (char_u *)100L,
2682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002684 {"undoreload", "ur", P_NUM|P_VI_DEF,
2685 (char_u *)&p_ur, PV_NONE,
2686 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"updatecount", "uc", P_NUM|P_VI_DEF,
2688 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 {"updatetime", "ut", P_NUM|P_VI_DEF,
2691 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 {"verbose", "vbs", P_NUM|P_VI_DEF,
2694 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002696 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2697 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2700#ifdef FEAT_SESSION
2701 (char_u *)&p_vdir, PV_NONE,
2702 {(char_u *)DFLT_VDIR, (char_u *)0L}
2703#else
2704 (char_u *)NULL, PV_NONE,
2705 {(char_u *)0L, (char_u *)0L}
2706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2709#ifdef FEAT_SESSION
2710 (char_u *)&p_vop, PV_NONE,
2711 {(char_u *)"folds,options,cursor", (char_u *)0L}
2712#else
2713 (char_u *)NULL, PV_NONE,
2714 {(char_u *)0L, (char_u *)0L}
2715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2718#ifdef FEAT_VIMINFO
2719 (char_u *)&p_viminfo, PV_NONE,
2720#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002721 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722#else
2723# ifdef AMIGA
2724 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002725 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002727 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728# endif
2729#endif
2730#else
2731 (char_u *)NULL, PV_NONE,
2732 {(char_u *)0L, (char_u *)0L}
2733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002735 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736#ifdef FEAT_VIRTUALEDIT
2737 (char_u *)&p_ve, PV_NONE,
2738 {(char_u *)"", (char_u *)""}
2739#else
2740 (char_u *)NULL, PV_NONE,
2741 {(char_u *)0L, (char_u *)0L}
2742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002743 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2745 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"w300", NULL, P_NUM|P_VI_DEF,
2748 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"w1200", NULL, P_NUM|P_VI_DEF,
2751 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"w9600", NULL, P_NUM|P_VI_DEF,
2754 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"warn", NULL, P_BOOL|P_VI_DEF,
2757 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2760 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2763 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"wildchar", "wc", P_NUM|P_VIM,
2766 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2768 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002769 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2773#ifdef FEAT_WILDIGN
2774 (char_u *)&p_wig, PV_NONE,
2775#else
2776 (char_u *)NULL, PV_NONE,
2777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002779 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2780 (char_u *)&p_wic, PV_NONE,
2781 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2783#ifdef FEAT_WILDMENU
2784 (char_u *)&p_wmnu, PV_NONE,
2785#else
2786 (char_u *)NULL, PV_NONE,
2787#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2790 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002792 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2793#ifdef FEAT_CMDL_COMPL
2794 (char_u *)&p_wop, PV_NONE,
2795 {(char_u *)"", (char_u *)0L}
2796#else
2797 (char_u *)NULL, PV_NONE,
2798 {(char_u *)NULL, (char_u *)0L}
2799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2802#ifdef FEAT_WAK
2803 (char_u *)&p_wak, PV_NONE,
2804 {(char_u *)"menu", (char_u *)0L}
2805#else
2806 (char_u *)NULL, PV_NONE,
2807 {(char_u *)NULL, (char_u *)0L}
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002811 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"winheight", "wh", P_NUM|P_VI_DEF,
2814#ifdef FEAT_WINDOWS
2815 (char_u *)&p_wh, PV_NONE,
2816#else
2817 (char_u *)NULL, PV_NONE,
2818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002821#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 (char_u *)VAR_WIN, PV_WFH,
2823#else
2824 (char_u *)NULL, PV_NONE,
2825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002827 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2828#ifdef FEAT_VERTSPLIT
2829 (char_u *)VAR_WIN, PV_WFW,
2830#else
2831 (char_u *)NULL, PV_NONE,
2832#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2835#ifdef FEAT_WINDOWS
2836 (char_u *)&p_wmh, PV_NONE,
2837#else
2838 (char_u *)NULL, PV_NONE,
2839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2842#ifdef FEAT_VERTSPLIT
2843 (char_u *)&p_wmw, PV_NONE,
2844#else
2845 (char_u *)NULL, PV_NONE,
2846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002847 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2849#ifdef FEAT_VERTSPLIT
2850 (char_u *)&p_wiw, PV_NONE,
2851#else
2852 (char_u *)NULL, PV_NONE,
2853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2856 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2859 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2862 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002863 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"write", NULL, P_BOOL|P_VI_DEF,
2865 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"writeany", "wa", P_BOOL|P_VI_DEF,
2868 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2871 (char_u *)&p_wb, PV_NONE,
2872 {
2873#ifdef FEAT_WRITEBACKUP
2874 (char_u *)TRUE,
2875#else
2876 (char_u *)FALSE,
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"writedelay", "wd", P_NUM|P_VI_DEF,
2880 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882
2883/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002884#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887
2888 p_term("t_AB", T_CAB)
2889 p_term("t_AF", T_CAF)
2890 p_term("t_AL", T_CAL)
2891 p_term("t_al", T_AL)
2892 p_term("t_bc", T_BC)
2893 p_term("t_cd", T_CD)
2894 p_term("t_ce", T_CE)
2895 p_term("t_cl", T_CL)
2896 p_term("t_cm", T_CM)
2897 p_term("t_Co", T_CCO)
2898 p_term("t_CS", T_CCS)
2899 p_term("t_cs", T_CS)
2900#ifdef FEAT_VERTSPLIT
2901 p_term("t_CV", T_CSV)
2902#endif
2903 p_term("t_ut", T_UT)
2904 p_term("t_da", T_DA)
2905 p_term("t_db", T_DB)
2906 p_term("t_DL", T_CDL)
2907 p_term("t_dl", T_DL)
2908 p_term("t_fs", T_FS)
2909 p_term("t_IE", T_CIE)
2910 p_term("t_IS", T_CIS)
2911 p_term("t_ke", T_KE)
2912 p_term("t_ks", T_KS)
2913 p_term("t_le", T_LE)
2914 p_term("t_mb", T_MB)
2915 p_term("t_md", T_MD)
2916 p_term("t_me", T_ME)
2917 p_term("t_mr", T_MR)
2918 p_term("t_ms", T_MS)
2919 p_term("t_nd", T_ND)
2920 p_term("t_op", T_OP)
2921 p_term("t_RI", T_CRI)
2922 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002923 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 p_term("t_Sb", T_CSB)
2925 p_term("t_Sf", T_CSF)
2926 p_term("t_se", T_SE)
2927 p_term("t_so", T_SO)
2928 p_term("t_sr", T_SR)
2929 p_term("t_ts", T_TS)
2930 p_term("t_te", T_TE)
2931 p_term("t_ti", T_TI)
2932 p_term("t_ue", T_UE)
2933 p_term("t_us", T_US)
2934 p_term("t_vb", T_VB)
2935 p_term("t_ve", T_VE)
2936 p_term("t_vi", T_VI)
2937 p_term("t_vs", T_VS)
2938 p_term("t_WP", T_CWP)
2939 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002940 p_term("t_SI", T_CSI)
2941 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 p_term("t_xs", T_XS)
2943 p_term("t_ZH", T_CZH)
2944 p_term("t_ZR", T_CZR)
2945
2946/* terminal key codes are not in here */
2947
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 /* end marker */
2949 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950};
2951
2952#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2953
2954#ifdef FEAT_MBYTE
2955static char *(p_ambw_values[]) = {"single", "double", NULL};
2956#endif
2957static char *(p_bg_values[]) = {"light", "dark", NULL};
2958static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2959static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002960#ifdef FEAT_CRYPT
2961static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2962#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002963#ifdef FEAT_CMDL_COMPL
2964static char *(p_wop_values[]) = {"tagfile", NULL};
2965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966#ifdef FEAT_WAK
2967static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2968#endif
2969static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2971static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973#ifdef FEAT_BROWSE
2974static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2975#endif
2976#ifdef FEAT_SCROLLBIND
2977static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2978#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002979static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980#ifdef FEAT_VERTSPLIT
2981static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2982#endif
2983#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002984# ifdef FEAT_AUTOCMD
2985static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2986# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002988# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2990#endif
2991static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2992#ifdef FEAT_FOLDING
2993static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002994# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002996# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 NULL};
2998static char *(p_fcl_values[]) = {"all", NULL};
2999#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003000#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003001static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003
3004static void set_option_default __ARGS((int, int opt_flags, int compatible));
3005static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003006static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003007static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008static char_u *illegal_char __ARGS((char_u *, int));
3009static int string_to_key __ARGS((char_u *arg));
3010#ifdef FEAT_CMDWIN
3011static char_u *check_cedit __ARGS((void));
3012#endif
3013#ifdef FEAT_TITLE
3014static void did_set_title __ARGS((int icon));
3015#endif
3016static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3017static void didset_options __ARGS((void));
3018static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003019#if defined(FEAT_EVAL) || defined(PROTO)
3020static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3021#else
3022# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3023#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003025static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026static 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));
3027static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003028#ifdef FEAT_SYN_HL
3029static int int_cmp __ARGS((const void *a, const void *b));
3030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031#ifdef FEAT_CLIPBOARD
3032static char_u *check_clipboard_option __ARGS((void));
3033#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003034#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003035static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003036#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003037#ifdef FEAT_EVAL
3038static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003041static 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 +00003042static void check_redraw __ARGS((long_u flags));
3043static int findoption __ARGS((char_u *));
3044static int find_key_option __ARGS((char_u *));
3045static void showoptions __ARGS((int all, int opt_flags));
3046static int optval_default __ARGS((struct vimoption *, char_u *varp));
3047static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3048static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3049static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3050static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3051static int istermoption __ARGS((struct vimoption *));
3052static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3053static char_u *get_varp __ARGS((struct vimoption *));
3054static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3055static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3056#ifdef FEAT_LANGMAP
3057static void langmap_init __ARGS((void));
3058static void langmap_set __ARGS((void));
3059#endif
3060static void paste_option_changed __ARGS((void));
3061static void compatible_set __ARGS((void));
3062#ifdef FEAT_LINEBREAK
3063static void fill_breakat_flags __ARGS((void));
3064#endif
3065static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3066static int check_opt_strings __ARGS((char_u *val, char **values, int));
3067static int check_opt_wim __ARGS((void));
3068
3069/*
3070 * Initialize the options, first part.
3071 *
3072 * Called only once from main(), just after creating the first buffer.
3073 */
3074 void
3075set_init_1()
3076{
3077 char_u *p;
3078 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003079 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080
3081#ifdef FEAT_LANGMAP
3082 langmap_init();
3083#endif
3084
3085 /* Be Vi compatible by default */
3086 p_cp = TRUE;
3087
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003088 /* Use POSIX compatibility when $VIM_POSIX is set. */
3089 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003090 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003091 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003092 set_string_default("shm", (char_u *)"A");
3093 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003094
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 /*
3096 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003097 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003099 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3101# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003102 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003104 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003106 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107# endif
3108#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003109 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 set_string_default("sh", p);
3111
3112#ifdef FEAT_WILDIGN
3113 /*
3114 * Set the default for 'backupskip' to include environment variables for
3115 * temp files.
3116 */
3117 {
3118# ifdef UNIX
3119 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3120# else
3121 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3122# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003123 int len;
3124 garray_T ga;
3125 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126
3127 ga_init2(&ga, 1, 100);
3128 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3129 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003130 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131# ifdef UNIX
3132 if (*names[n] == NUL)
3133 p = (char_u *)"/tmp";
3134 else
3135# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003136 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 if (p != NULL && *p != NUL)
3138 {
3139 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003140 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 if (ga_grow(&ga, len) == OK)
3142 {
3143 if (ga.ga_len > 0)
3144 STRCAT(ga.ga_data, ",");
3145 STRCAT(ga.ga_data, p);
3146 add_pathsep(ga.ga_data);
3147 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 ga.ga_len += len;
3149 }
3150 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003151 if (mustfree)
3152 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 }
3154 if (ga.ga_data != NULL)
3155 {
3156 set_string_default("bsk", ga.ga_data);
3157 vim_free(ga.ga_data);
3158 }
3159 }
3160#endif
3161
3162 /*
3163 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3164 */
3165 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003166 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003168#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3169 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3170#endif
3171 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003173 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003174 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175#else
3176# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003177 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003178 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003180 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181# endif
3182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003184 opt_idx = findoption((char_u *)"maxmem");
3185 if (opt_idx >= 0)
3186 {
3187#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003188 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003189 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3190#endif
3191 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3192 }
3193 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 }
3195
3196#ifdef FEAT_GUI_W32
3197 /* force 'shortname' for Win32s */
3198 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003199 {
3200 opt_idx = findoption((char_u *)"shortname");
3201 if (opt_idx >= 0)
3202 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3203 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204#endif
3205
3206#ifdef FEAT_SEARCHPATH
3207 {
3208 char_u *cdpath;
3209 char_u *buf;
3210 int i;
3211 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003212 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213
3214 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003215 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 if (cdpath != NULL)
3217 {
3218 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3219 if (buf != NULL)
3220 {
3221 buf[0] = ','; /* start with ",", current dir first */
3222 j = 1;
3223 for (i = 0; cdpath[i] != NUL; ++i)
3224 {
3225 if (vim_ispathlistsep(cdpath[i]))
3226 buf[j++] = ',';
3227 else
3228 {
3229 if (cdpath[i] == ' ' || cdpath[i] == ',')
3230 buf[j++] = '\\';
3231 buf[j++] = cdpath[i];
3232 }
3233 }
3234 buf[j] = NUL;
3235 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003236 if (opt_idx >= 0)
3237 {
3238 options[opt_idx].def_val[VI_DEFAULT] = buf;
3239 options[opt_idx].flags |= P_DEF_ALLOCED;
3240 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003241 else
3242 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003244 if (mustfree)
3245 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 }
3247 }
3248#endif
3249
3250#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3251 /* Set print encoding on platforms that don't default to latin1 */
3252 set_string_default("penc",
3253# if defined(MSWIN) || defined(OS2)
3254 (char_u *)"cp1252"
3255# else
3256# ifdef VMS
3257 (char_u *)"dec-mcs"
3258# else
3259# ifdef EBCDIC
3260 (char_u *)"ebcdic-uk"
3261# else
3262# ifdef MAC
3263 (char_u *)"mac-roman"
3264# else /* HPUX */
3265 (char_u *)"hp-roman8"
3266# endif
3267# endif
3268# endif
3269# endif
3270 );
3271#endif
3272
3273#ifdef FEAT_POSTSCRIPT
3274 /* 'printexpr' must be allocated to be able to evaluate it. */
3275 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003276# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3277 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278# else
3279# ifdef VMS
3280 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3281
3282# else
3283 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3284# endif
3285# endif
3286 );
3287#endif
3288
3289 /*
3290 * Set all the options (except the terminal options) to their default
3291 * value. Also set the global value for local options.
3292 */
3293 set_options_default(0);
3294
3295#ifdef FEAT_GUI
3296 if (found_reverse_arg)
3297 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3298#endif
3299
3300 curbuf->b_p_initialized = TRUE;
3301 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003302 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303 check_buf_options(curbuf);
3304 check_win_options(curwin);
3305 check_options();
3306
3307 /* Must be before option_expand(), because that one needs vim_isIDc() */
3308 didset_options();
3309
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003310#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003311 /* Use the current chartab for the generic chartab. */
3312 init_spell_chartab();
3313#endif
3314
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315#ifdef FEAT_LINEBREAK
3316 /*
3317 * initialize the table for 'breakat'.
3318 */
3319 fill_breakat_flags();
3320#endif
3321
3322 /*
3323 * Expand environment variables and things like "~" for the defaults.
3324 * If option_expand() returns non-NULL the variable is expanded. This can
3325 * only happen for non-indirect options.
3326 * Also set the default to the expanded value, so ":set" does not list
3327 * them.
3328 * Don't set the P_ALLOCED flag, because we don't want to free the
3329 * default.
3330 */
3331 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3332 {
3333 if ((options[opt_idx].flags & P_GETTEXT)
3334 && options[opt_idx].var != NULL)
3335 p = (char_u *)_(*(char **)options[opt_idx].var);
3336 else
3337 p = option_expand(opt_idx, NULL);
3338 if (p != NULL && (p = vim_strsave(p)) != NULL)
3339 {
3340 *(char_u **)options[opt_idx].var = p;
3341 /* VIMEXP
3342 * Defaults for all expanded options are currently the same for Vi
3343 * and Vim. When this changes, add some code here! Also need to
3344 * split P_DEF_ALLOCED in two.
3345 */
3346 if (options[opt_idx].flags & P_DEF_ALLOCED)
3347 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3348 options[opt_idx].def_val[VI_DEFAULT] = p;
3349 options[opt_idx].flags |= P_DEF_ALLOCED;
3350 }
3351 }
3352
3353 /* Initialize the highlight_attr[] table. */
3354 highlight_changed();
3355
3356 save_file_ff(curbuf); /* Buffer is unchanged */
3357
3358 /* Parse default for 'wildmode' */
3359 check_opt_wim();
3360
3361#if defined(FEAT_ARABIC)
3362 /* Detect use of mlterm.
3363 * Mlterm is a terminal emulator akin to xterm that has some special
3364 * abilities (bidi namely).
3365 * NOTE: mlterm's author is being asked to 'set' a variable
3366 * instead of an environment variable due to inheritance.
3367 */
3368 if (mch_getenv((char_u *)"MLTERM") != NULL)
3369 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3370#endif
3371
3372#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3373 /* Parse default for 'fillchars'. */
3374 (void)set_chars_option(&p_fcs);
3375#endif
3376
3377#ifdef FEAT_CLIPBOARD
3378 /* Parse default for 'clipboard' */
3379 (void)check_clipboard_option();
3380#endif
3381
3382#ifdef FEAT_MBYTE
3383# if defined(WIN3264) && defined(FEAT_GETTEXT)
3384 /*
3385 * If $LANG isn't set, try to get a good value for it. This makes the
3386 * right language be used automatically. Don't do this for English.
3387 */
3388 if (mch_getenv((char_u *)"LANG") == NULL)
3389 {
3390 char buf[20];
3391
3392 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3393 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3394 * only the first two. */
3395 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3396 (LPTSTR)buf, 20);
3397 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3398 {
3399 /* There are a few exceptions (probably more) */
3400 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3401 STRCPY(buf, "zh_TW");
3402 else if (STRNICMP(buf, "chs", 3) == 0
3403 || STRNICMP(buf, "zhc", 3) == 0)
3404 STRCPY(buf, "zh_CN");
3405 else if (STRNICMP(buf, "jp", 2) == 0)
3406 STRCPY(buf, "ja");
3407 else
3408 buf[2] = NUL; /* truncate to two-letter code */
3409 vim_setenv("LANG", buf);
3410 }
3411 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003412# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003413# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003414 /* Moved to os_mac_conv.c to avoid dependency problems. */
3415 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003416# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417# endif
3418
3419 /* enc_locale() will try to find the encoding of the current locale. */
3420 p = enc_locale();
3421 if (p != NULL)
3422 {
3423 char_u *save_enc;
3424
3425 /* Try setting 'encoding' and check if the value is valid.
3426 * If not, go back to the default "latin1". */
3427 save_enc = p_enc;
3428 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003429 if (STRCMP(p_enc, "gb18030") == 0)
3430 {
3431 /* We don't support "gb18030", but "cp936" is a good substitute
3432 * for practical purposes, thus use that. It's not an alias to
3433 * still support conversion between gb18030 and utf-8. */
3434 p_enc = vim_strsave((char_u *)"cp936");
3435 vim_free(p);
3436 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 if (mb_init() == NULL)
3438 {
3439 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003440 if (opt_idx >= 0)
3441 {
3442 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3443 options[opt_idx].flags |= P_DEF_ALLOCED;
3444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003446#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3447 || defined(VMS)
3448 if (STRCMP(p_enc, "latin1") == 0
3449# ifdef FEAT_MBYTE
3450 || enc_utf8
3451# endif
3452 )
3453 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003454 /* Adjust the default for 'isprint' and 'iskeyword' to match
3455 * latin1. Also set the defaults for when 'nocompatible' is
3456 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003457 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003458 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003459 set_string_option_direct((char_u *)"isk", -1,
3460 ISK_LATIN1, OPT_FREE, SID_NONE);
3461 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003462 if (opt_idx >= 0)
3463 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003464 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003465 if (opt_idx >= 0)
3466 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003467 (void)init_chartab();
3468 }
3469#endif
3470
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471# if defined(WIN3264) && !defined(FEAT_GUI)
3472 /* Win32 console: When GetACP() returns a different value from
3473 * GetConsoleCP() set 'termencoding'. */
3474 if (GetACP() != GetConsoleCP())
3475 {
3476 char buf[50];
3477
3478 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3479 p_tenc = vim_strsave((char_u *)buf);
3480 if (p_tenc != NULL)
3481 {
3482 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003483 if (opt_idx >= 0)
3484 {
3485 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3486 options[opt_idx].flags |= P_DEF_ALLOCED;
3487 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 convert_setup(&input_conv, p_tenc, p_enc);
3489 convert_setup(&output_conv, p_enc, p_tenc);
3490 }
3491 else
3492 p_tenc = empty_option;
3493 }
3494# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003495# if defined(WIN3264) && defined(FEAT_MBYTE)
3496 /* $HOME may have characters in active code page. */
3497 init_homedir();
3498# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 }
3500 else
3501 {
3502 vim_free(p_enc);
3503 p_enc = save_enc;
3504 }
3505 }
3506#endif
3507
3508#ifdef FEAT_MULTI_LANG
3509 /* Set the default for 'helplang'. */
3510 set_helplang_default(get_mess_lang());
3511#endif
3512}
3513
3514/*
3515 * Set an option to its default value.
3516 * This does not take care of side effects!
3517 */
3518 static void
3519set_option_default(opt_idx, opt_flags, compatible)
3520 int opt_idx;
3521 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3522 int compatible; /* use Vi default value */
3523{
3524 char_u *varp; /* pointer to variable for current option */
3525 int dvi; /* index in def_val[] */
3526 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003527 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3529
3530 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3531 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003532 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533 {
3534 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3535 if (flags & P_STRING)
3536 {
3537 /* Use set_string_option_direct() for local options to handle
3538 * freeing and allocating the value. */
3539 if (options[opt_idx].indir != PV_NONE)
3540 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003541 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 else
3543 {
3544 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3545 free_string_option(*(char_u **)(varp));
3546 *(char_u **)varp = options[opt_idx].def_val[dvi];
3547 options[opt_idx].flags &= ~P_ALLOCED;
3548 }
3549 }
3550 else if (flags & P_NUM)
3551 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003552 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 win_comp_scroll(curwin);
3554 else
3555 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003556 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557 /* May also set global value for local option. */
3558 if (both)
3559 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3560 *(long *)varp;
3561 }
3562 }
3563 else /* P_BOOL */
3564 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003565 /* the cast to long is required for Manx C, long_i is needed for
3566 * MSVC */
3567 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003568#ifdef UNIX
3569 /* 'modeline' defaults to off for root */
3570 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3571 *(int *)varp = FALSE;
3572#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 /* May also set global value for local option. */
3574 if (both)
3575 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3576 *(int *)varp;
3577 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003578
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003579 /* The default value is not insecure. */
3580 flagsp = insecure_flag(opt_idx, opt_flags);
3581 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582 }
3583
3584#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003585 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586#endif
3587}
3588
3589/*
3590 * Set all options (except terminal options) to their default value.
3591 */
3592 static void
3593set_options_default(opt_flags)
3594 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3595{
3596 int i;
3597#ifdef FEAT_WINDOWS
3598 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003599 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003600#endif
3601
3602 for (i = 0; !istermoption(&options[i]); i++)
3603 if (!(options[i].flags & P_NODEFAULT))
3604 set_option_default(i, opt_flags, p_cp);
3605
3606#ifdef FEAT_WINDOWS
3607 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003608 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 win_comp_scroll(wp);
3610#else
3611 win_comp_scroll(curwin);
3612#endif
3613}
3614
3615/*
3616 * Set the Vi-default value of a string option.
3617 * Used for 'sh', 'backupskip' and 'term'.
3618 */
3619 void
3620set_string_default(name, val)
3621 char *name;
3622 char_u *val;
3623{
3624 char_u *p;
3625 int opt_idx;
3626
3627 p = vim_strsave(val);
3628 if (p != NULL) /* we don't want a NULL */
3629 {
3630 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003631 if (opt_idx >= 0)
3632 {
3633 if (options[opt_idx].flags & P_DEF_ALLOCED)
3634 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3635 options[opt_idx].def_val[VI_DEFAULT] = p;
3636 options[opt_idx].flags |= P_DEF_ALLOCED;
3637 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 }
3639}
3640
3641/*
3642 * Set the Vi-default value of a number option.
3643 * Used for 'lines' and 'columns'.
3644 */
3645 void
3646set_number_default(name, val)
3647 char *name;
3648 long val;
3649{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003650 int opt_idx;
3651
3652 opt_idx = findoption((char_u *)name);
3653 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003654 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655}
3656
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003657#if defined(EXITFREE) || defined(PROTO)
3658/*
3659 * Free all options.
3660 */
3661 void
3662free_all_options()
3663{
3664 int i;
3665
3666 for (i = 0; !istermoption(&options[i]); i++)
3667 {
3668 if (options[i].indir == PV_NONE)
3669 {
3670 /* global option: free value and default value. */
3671 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3672 free_string_option(*(char_u **)options[i].var);
3673 if (options[i].flags & P_DEF_ALLOCED)
3674 free_string_option(options[i].def_val[VI_DEFAULT]);
3675 }
3676 else if (options[i].var != VAR_WIN
3677 && (options[i].flags & P_STRING))
3678 /* buffer-local option: free global value */
3679 free_string_option(*(char_u **)options[i].var);
3680 }
3681}
3682#endif
3683
3684
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685/*
3686 * Initialize the options, part two: After getting Rows and Columns and
3687 * setting 'term'.
3688 */
3689 void
3690set_init_2()
3691{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003692 int idx;
3693
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 /*
3695 * 'scroll' defaults to half the window height. Note that this default is
3696 * wrong when the window height changes.
3697 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003698 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003699 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003701 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702 comp_col();
3703
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003704 /*
3705 * 'window' is only for backwards compatibility with Vi.
3706 * Default is Rows - 1.
3707 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003708 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003709 p_window = Rows - 1;
3710 set_number_default("window", Rows - 1);
3711
Bram Moolenaarf740b292006-02-16 22:11:02 +00003712 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003714 /*
3715 * If 'background' wasn't set by the user, try guessing the value,
3716 * depending on the terminal name. Only need to check for terminals
3717 * with a dark background, that can handle color.
3718 */
3719 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003720 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3721 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003723 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003724 /* don't mark it as set, when starting the GUI it may be
3725 * changed again */
3726 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 }
3728#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003729
3730#ifdef CURSOR_SHAPE
3731 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3732#endif
3733#ifdef FEAT_MOUSESHAPE
3734 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3735#endif
3736#ifdef FEAT_PRINTER
3737 (void)parse_printoptions(); /* parse 'printoptions' default value */
3738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739}
3740
3741/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003742 * Return "dark" or "light" depending on the kind of terminal.
3743 * This is just guessing! Recognized are:
3744 * "linux" Linux console
3745 * "screen.linux" Linux console with screen
3746 * "cygwin" Cygwin shell
3747 * "putty" Putty program
3748 * We also check the COLORFGBG environment variable, which is set by
3749 * rxvt and derivatives. This variable contains either two or three
3750 * values separated by semicolons; we want the last value in either
3751 * case. If this value is 0-6 or 8, our background is dark.
3752 */
3753 static char_u *
3754term_bg_default()
3755{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003756#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3757 /* DOS console nearly always black */
3758 return (char_u *)"dark";
3759#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003760 char_u *p;
3761
Bram Moolenaarf740b292006-02-16 22:11:02 +00003762 if (STRCMP(T_NAME, "linux") == 0
3763 || STRCMP(T_NAME, "screen.linux") == 0
3764 || STRCMP(T_NAME, "cygwin") == 0
3765 || STRCMP(T_NAME, "putty") == 0
3766 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3767 && (p = vim_strrchr(p, ';')) != NULL
3768 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3769 && p[2] == NUL))
3770 return (char_u *)"dark";
3771 return (char_u *)"light";
3772#endif
3773}
3774
3775/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 * Initialize the options, part three: After reading the .vimrc
3777 */
3778 void
3779set_init_3()
3780{
3781#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3782/*
3783 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3784 * This is done after other initializations, where 'shell' might have been
3785 * set, but only if they have not been set before.
3786 */
3787 char_u *p;
3788 int idx_srr;
3789 int do_srr;
3790#ifdef FEAT_QUICKFIX
3791 int idx_sp;
3792 int do_sp;
3793#endif
3794
3795 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003796 if (idx_srr < 0)
3797 do_srr = FALSE;
3798 else
3799 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800#ifdef FEAT_QUICKFIX
3801 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003802 if (idx_sp < 0)
3803 do_sp = FALSE;
3804 else
3805 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003807 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 if (p != NULL)
3809 {
3810 /*
3811 * Default for p_sp is "| tee", for p_srr is ">".
3812 * For known shells it is changed here to include stderr.
3813 */
3814 if ( fnamecmp(p, "csh") == 0
3815 || fnamecmp(p, "tcsh") == 0
3816# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3817 || fnamecmp(p, "csh.exe") == 0
3818 || fnamecmp(p, "tcsh.exe") == 0
3819# endif
3820 )
3821 {
3822#if defined(FEAT_QUICKFIX)
3823 if (do_sp)
3824 {
3825# ifdef WIN3264
3826 p_sp = (char_u *)">&";
3827# else
3828 p_sp = (char_u *)"|& tee";
3829# endif
3830 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3831 }
3832#endif
3833 if (do_srr)
3834 {
3835 p_srr = (char_u *)">&";
3836 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3837 }
3838 }
3839 else
3840# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3841 if ( fnamecmp(p, "sh") == 0
3842 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003843 || fnamecmp(p, "mksh") == 0
3844 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003845 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003846 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003848 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003849# ifdef WIN3264
3850 || fnamecmp(p, "cmd") == 0
3851 || fnamecmp(p, "sh.exe") == 0
3852 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003853 || fnamecmp(p, "mksh.exe") == 0
3854 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003856 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857 || fnamecmp(p, "bash.exe") == 0
3858 || fnamecmp(p, "cmd.exe") == 0
3859# endif
3860 )
3861# endif
3862 {
3863#if defined(FEAT_QUICKFIX)
3864 if (do_sp)
3865 {
3866# ifdef WIN3264
3867 p_sp = (char_u *)">%s 2>&1";
3868# else
3869 p_sp = (char_u *)"2>&1| tee";
3870# endif
3871 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3872 }
3873#endif
3874 if (do_srr)
3875 {
3876 p_srr = (char_u *)">%s 2>&1";
3877 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3878 }
3879 }
3880 vim_free(p);
3881 }
3882#endif
3883
3884#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3885 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003886 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3887 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 * This is done after other initializations, where 'shell' might have been
3889 * set, but only if they have not been set before. Default for p_shcf is
3890 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3891 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3892 * command.com. And for Win32 we need to set p_sxq instead.
3893 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003894 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 {
3896 int idx3;
3897
3898 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003899 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 {
3901 p_shcf = (char_u *)"-c";
3902 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3903 }
3904
3905# ifndef DJGPP
3906# ifdef WIN3264
3907 /* Somehow Win32 requires the quotes around the redirection too */
3908 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003909 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 {
3911 p_sxq = (char_u *)"\"";
3912 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3913 }
3914# else
3915 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003916 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 {
3918 p_shq = (char_u *)"\"";
3919 options[idx3].def_val[VI_DEFAULT] = p_shq;
3920 }
3921# endif
3922# endif
3923 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003924 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3925 {
3926 int idx3;
3927
3928 /*
3929 * cmd.exe on Windows will strip the first and last double quote given
3930 * on the command line, e.g. most of the time things like:
3931 * cmd /c "my path/to/echo" "my args to echo"
3932 * become:
3933 * my path/to/echo" "my args to echo
3934 * when executed.
3935 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003936 * To avoid this, set shellxquote to surround the command in
3937 * parenthesis. This appears to make most commands work, without
3938 * breaking commands that worked previously, such as
3939 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003940 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003941 idx3 = findoption((char_u *)"sxq");
3942 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3943 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003944 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003945 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3946 }
3947
Bram Moolenaara64ba222012-02-12 23:23:31 +01003948 idx3 = findoption((char_u *)"shcf");
3949 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3950 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003951 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003952 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3953 }
3954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955#endif
3956
3957#ifdef FEAT_TITLE
3958 set_title_defaults();
3959#endif
3960}
3961
3962#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3963/*
3964 * When 'helplang' is still at its default value, set it to "lang".
3965 * Only the first two characters of "lang" are used.
3966 */
3967 void
3968set_helplang_default(lang)
3969 char_u *lang;
3970{
3971 int idx;
3972
3973 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3974 return;
3975 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003976 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 {
3978 if (options[idx].flags & P_ALLOCED)
3979 free_string_option(p_hlg);
3980 p_hlg = vim_strsave(lang);
3981 if (p_hlg == NULL)
3982 p_hlg = empty_option;
3983 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003984 {
3985 /* zh_CN becomes "cn", zh_TW becomes "tw". */
3986 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
3987 {
3988 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
3989 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
3990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00003992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993 options[idx].flags |= P_ALLOCED;
3994 }
3995}
3996#endif
3997
3998#ifdef FEAT_GUI
3999static char_u *gui_bg_default __ARGS((void));
4000
4001 static char_u *
4002gui_bg_default()
4003{
4004 if (gui_get_lightness(gui.back_pixel) < 127)
4005 return (char_u *)"dark";
4006 return (char_u *)"light";
4007}
4008
4009/*
4010 * Option initializations that can only be done after opening the GUI window.
4011 */
4012 void
4013init_gui_options()
4014{
4015 /* Set the 'background' option according to the lightness of the
4016 * background color, unless the user has set it already. */
4017 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4018 {
4019 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4020 highlight_changed();
4021 }
4022}
4023#endif
4024
4025#ifdef FEAT_TITLE
4026/*
4027 * 'title' and 'icon' only default to true if they have not been set or reset
4028 * in .vimrc and we can read the old value.
4029 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4030 * they can be reset. This reduces startup time when using X on a remote
4031 * machine.
4032 */
4033 void
4034set_title_defaults()
4035{
4036 int idx1;
4037 long val;
4038
4039 /*
4040 * If GUI is (going to be) used, we can always set the window title and
4041 * icon name. Saves a bit of time, because the X11 display server does
4042 * not need to be contacted.
4043 */
4044 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004045 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 {
4047#ifdef FEAT_GUI
4048 if (gui.starting || gui.in_use)
4049 val = TRUE;
4050 else
4051#endif
4052 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004053 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 p_title = val;
4055 }
4056 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004057 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 {
4059#ifdef FEAT_GUI
4060 if (gui.starting || gui.in_use)
4061 val = TRUE;
4062 else
4063#endif
4064 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004065 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 p_icon = val;
4067 }
4068}
4069#endif
4070
4071/*
4072 * Parse 'arg' for option settings.
4073 *
4074 * 'arg' may be IObuff, but only when no errors can be present and option
4075 * does not need to be expanded with option_expand().
4076 * "opt_flags":
4077 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004078 * OPT_GLOBAL for ":setglobal"
4079 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004081 * OPT_WINONLY to only set window-local options
4082 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 *
4084 * returns FAIL if an error is detected, OK otherwise
4085 */
4086 int
4087do_set(arg, opt_flags)
4088 char_u *arg; /* option string (may be written to!) */
4089 int opt_flags;
4090{
4091 int opt_idx;
4092 char_u *errmsg;
4093 char_u errbuf[80];
4094 char_u *startarg;
4095 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4096 int nextchar; /* next non-white char after option name */
4097 int afterchar; /* character just after option name */
4098 int len;
4099 int i;
4100 long value;
4101 int key;
4102 long_u flags; /* flags for current option */
4103 char_u *varp = NULL; /* pointer to variable for current option */
4104 int did_show = FALSE; /* already showed one value */
4105 int adding; /* "opt+=arg" */
4106 int prepending; /* "opt^=arg" */
4107 int removing; /* "opt-=arg" */
4108 int cp_val = 0;
4109 char_u key_name[2];
4110
4111 if (*arg == NUL)
4112 {
4113 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004114 did_show = TRUE;
4115 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 }
4117
4118 while (*arg != NUL) /* loop to process all options */
4119 {
4120 errmsg = NULL;
4121 startarg = arg; /* remember for error message */
4122
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004123 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4124 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 {
4126 /*
4127 * ":set all" show all options.
4128 * ":set all&" set all options to their default value.
4129 */
4130 arg += 3;
4131 if (*arg == '&')
4132 {
4133 ++arg;
4134 /* Only for :set command set global value of local options. */
4135 set_options_default(OPT_FREE | opt_flags);
4136 }
4137 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004138 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004140 did_show = TRUE;
4141 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004143 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 {
4145 showoptions(2, opt_flags);
4146 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004147 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 arg += 7;
4149 }
4150 else
4151 {
4152 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004153 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 {
4155 prefix = 0;
4156 arg += 2;
4157 }
4158 else if (STRNCMP(arg, "inv", 3) == 0)
4159 {
4160 prefix = 2;
4161 arg += 3;
4162 }
4163
4164 /* find end of name */
4165 key = 0;
4166 if (*arg == '<')
4167 {
4168 nextchar = 0;
4169 opt_idx = -1;
4170 /* look out for <t_>;> */
4171 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4172 len = 5;
4173 else
4174 {
4175 len = 1;
4176 while (arg[len] != NUL && arg[len] != '>')
4177 ++len;
4178 }
4179 if (arg[len] != '>')
4180 {
4181 errmsg = e_invarg;
4182 goto skip;
4183 }
4184 arg[len] = NUL; /* put NUL after name */
4185 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4186 opt_idx = findoption(arg + 1);
4187 arg[len++] = '>'; /* restore '>' */
4188 if (opt_idx == -1)
4189 key = find_key_option(arg + 1);
4190 }
4191 else
4192 {
4193 len = 0;
4194 /*
4195 * The two characters after "t_" may not be alphanumeric.
4196 */
4197 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4198 len = 4;
4199 else
4200 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4201 ++len;
4202 nextchar = arg[len];
4203 arg[len] = NUL; /* put NUL after name */
4204 opt_idx = findoption(arg);
4205 arg[len] = nextchar; /* restore nextchar */
4206 if (opt_idx == -1)
4207 key = find_key_option(arg);
4208 }
4209
4210 /* remember character after option name */
4211 afterchar = arg[len];
4212
4213 /* skip white space, allow ":set ai ?" */
4214 while (vim_iswhite(arg[len]))
4215 ++len;
4216
4217 adding = FALSE;
4218 prepending = FALSE;
4219 removing = FALSE;
4220 if (arg[len] != NUL && arg[len + 1] == '=')
4221 {
4222 if (arg[len] == '+')
4223 {
4224 adding = TRUE; /* "+=" */
4225 ++len;
4226 }
4227 else if (arg[len] == '^')
4228 {
4229 prepending = TRUE; /* "^=" */
4230 ++len;
4231 }
4232 else if (arg[len] == '-')
4233 {
4234 removing = TRUE; /* "-=" */
4235 ++len;
4236 }
4237 }
4238 nextchar = arg[len];
4239
4240 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4241 {
4242 errmsg = (char_u *)N_("E518: Unknown option");
4243 goto skip;
4244 }
4245
4246 if (opt_idx >= 0)
4247 {
4248 if (options[opt_idx].var == NULL) /* hidden option: skip */
4249 {
4250 /* Only give an error message when requesting the value of
4251 * a hidden option, ignore setting it. */
4252 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4253 && (!(options[opt_idx].flags & P_BOOL)
4254 || nextchar == '?'))
4255 errmsg = (char_u *)N_("E519: Option not supported");
4256 goto skip;
4257 }
4258
4259 flags = options[opt_idx].flags;
4260 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4261 }
4262 else
4263 {
4264 flags = P_STRING;
4265 if (key < 0)
4266 {
4267 key_name[0] = KEY2TERMCAP0(key);
4268 key_name[1] = KEY2TERMCAP1(key);
4269 }
4270 else
4271 {
4272 key_name[0] = KS_KEY;
4273 key_name[1] = (key & 0xff);
4274 }
4275 }
4276
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004277 /* Skip all options that are not window-local (used when showing
4278 * an already loaded buffer in a window). */
4279 if ((opt_flags & OPT_WINONLY)
4280 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4281 goto skip;
4282
Bram Moolenaara3227e22006-03-08 21:32:40 +00004283 /* Skip all options that are window-local (used for :vimgrep). */
4284 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4285 && options[opt_idx].var == VAR_WIN)
4286 goto skip;
4287
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004288 /* Disallow changing some options from modelines. */
4289 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004291 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004292 {
4293 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4294 goto skip;
4295 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004296#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004297 /* In diff mode some options are overruled. This avoids that
4298 * 'foldmethod' becomes "marker" instead of "diff" and that
4299 * "wrap" gets set. */
4300 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004301 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004302 && (options[opt_idx].indir == PV_FDM
4303 || options[opt_idx].indir == PV_WRAP))
4304 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004306 }
4307
4308#ifdef HAVE_SANDBOX
4309 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004310 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311 {
4312 errmsg = (char_u *)_(e_sandbox);
4313 goto skip;
4314 }
4315#endif
4316
4317 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4318 {
4319 arg += len;
4320 cp_val = p_cp;
4321 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4322 {
4323 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4324 {
4325 cp_val = FALSE;
4326 arg += 3;
4327 }
4328 else /* "opt&vi": set to Vi default */
4329 {
4330 cp_val = TRUE;
4331 arg += 2;
4332 }
4333 }
4334 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4335 && arg[1] != NUL && !vim_iswhite(arg[1]))
4336 {
4337 errmsg = e_trailing;
4338 goto skip;
4339 }
4340 }
4341
4342 /*
4343 * allow '=' and ':' as MSDOS command.com allows only one
4344 * '=' character per "set" command line. grrr. (jw)
4345 */
4346 if (nextchar == '?'
4347 || (prefix == 1
4348 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4349 && !(flags & P_BOOL)))
4350 {
4351 /*
4352 * print value
4353 */
4354 if (did_show)
4355 msg_putchar('\n'); /* cursor below last one */
4356 else
4357 {
4358 gotocmdline(TRUE); /* cursor at status line */
4359 did_show = TRUE; /* remember that we did a line */
4360 }
4361 if (opt_idx >= 0)
4362 {
4363 showoneopt(&options[opt_idx], opt_flags);
4364#ifdef FEAT_EVAL
4365 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004366 {
4367 /* Mention where the option was last set. */
4368 if (varp == options[opt_idx].var)
4369 last_set_msg(options[opt_idx].scriptID);
4370 else if ((int)options[opt_idx].indir & PV_WIN)
4371 last_set_msg(curwin->w_p_scriptID[
4372 (int)options[opt_idx].indir & PV_MASK]);
4373 else if ((int)options[opt_idx].indir & PV_BUF)
4374 last_set_msg(curbuf->b_p_scriptID[
4375 (int)options[opt_idx].indir & PV_MASK]);
4376 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377#endif
4378 }
4379 else
4380 {
4381 char_u *p;
4382
4383 p = find_termcode(key_name);
4384 if (p == NULL)
4385 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004386 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387 goto skip;
4388 }
4389 else
4390 (void)show_one_termcode(key_name, p, TRUE);
4391 }
4392 if (nextchar != '?'
4393 && nextchar != NUL && !vim_iswhite(afterchar))
4394 errmsg = e_trailing;
4395 }
4396 else
4397 {
4398 if (flags & P_BOOL) /* boolean */
4399 {
4400 if (nextchar == '=' || nextchar == ':')
4401 {
4402 errmsg = e_invarg;
4403 goto skip;
4404 }
4405
4406 /*
4407 * ":set opt!": invert
4408 * ":set opt&": reset to default value
4409 * ":set opt<": reset to global value
4410 */
4411 if (nextchar == '!')
4412 value = *(int *)(varp) ^ 1;
4413 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004414 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415 ((flags & P_VI_DEF) || cp_val)
4416 ? VI_DEFAULT : VIM_DEFAULT];
4417 else if (nextchar == '<')
4418 {
4419 /* For 'autoread' -1 means to use global value. */
4420 if ((int *)varp == &curbuf->b_p_ar
4421 && opt_flags == OPT_LOCAL)
4422 value = -1;
4423 else
4424 value = *(int *)get_varp_scope(&(options[opt_idx]),
4425 OPT_GLOBAL);
4426 }
4427 else
4428 {
4429 /*
4430 * ":set invopt": invert
4431 * ":set opt" or ":set noopt": set or reset
4432 */
4433 if (nextchar != NUL && !vim_iswhite(afterchar))
4434 {
4435 errmsg = e_trailing;
4436 goto skip;
4437 }
4438 if (prefix == 2) /* inv */
4439 value = *(int *)(varp) ^ 1;
4440 else
4441 value = prefix;
4442 }
4443
4444 errmsg = set_bool_option(opt_idx, varp, (int)value,
4445 opt_flags);
4446 }
4447 else /* numeric or string */
4448 {
4449 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4450 || prefix != 1)
4451 {
4452 errmsg = e_invarg;
4453 goto skip;
4454 }
4455
4456 if (flags & P_NUM) /* numeric */
4457 {
4458 /*
4459 * Different ways to set a number option:
4460 * & set to default value
4461 * < set to global value
4462 * <xx> accept special key codes for 'wildchar'
4463 * c accept any non-digit for 'wildchar'
4464 * [-]0-9 set number
4465 * other error
4466 */
4467 ++arg;
4468 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004469 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004470 ((flags & P_VI_DEF) || cp_val)
4471 ? VI_DEFAULT : VIM_DEFAULT];
4472 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004473 {
4474 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4475 * use the global value. */
4476 if ((long *)varp == &curbuf->b_p_ul
4477 && opt_flags == OPT_LOCAL)
4478 value = NO_LOCAL_UNDOLEVEL;
4479 else
4480 value = *(long *)get_varp_scope(
4481 &(options[opt_idx]), OPT_GLOBAL);
4482 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004483 else if (((long *)varp == &p_wc
4484 || (long *)varp == &p_wcm)
4485 && (*arg == '<'
4486 || *arg == '^'
4487 || ((!arg[1] || vim_iswhite(arg[1]))
4488 && !VIM_ISDIGIT(*arg))))
4489 {
4490 value = string_to_key(arg);
4491 if (value == 0 && (long *)varp != &p_wcm)
4492 {
4493 errmsg = e_invarg;
4494 goto skip;
4495 }
4496 }
4497 /* allow negative numbers (for 'undolevels') */
4498 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4499 {
4500 i = 0;
4501 if (*arg == '-')
4502 i = 1;
4503#ifdef HAVE_STRTOL
4504 value = strtol((char *)arg, NULL, 0);
4505 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4506 i += 2;
4507#else
4508 value = atol((char *)arg);
4509#endif
4510 while (VIM_ISDIGIT(arg[i]))
4511 ++i;
4512 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4513 {
4514 errmsg = e_invarg;
4515 goto skip;
4516 }
4517 }
4518 else
4519 {
4520 errmsg = (char_u *)N_("E521: Number required after =");
4521 goto skip;
4522 }
4523
4524 if (adding)
4525 value = *(long *)varp + value;
4526 if (prepending)
4527 value = *(long *)varp * value;
4528 if (removing)
4529 value = *(long *)varp - value;
4530 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004531 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004532 }
4533 else if (opt_idx >= 0) /* string */
4534 {
4535 char_u *save_arg = NULL;
4536 char_u *s = NULL;
4537 char_u *oldval; /* previous value if *varp */
4538 char_u *newval;
4539 char_u *origval;
4540 unsigned newlen;
4541 int comma;
4542 int bs;
4543 int new_value_alloced; /* new string option
4544 was allocated */
4545
4546 /* When using ":set opt=val" for a global option
4547 * with a local value the local value will be
4548 * reset, use the global value here. */
4549 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004550 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004551 varp = options[opt_idx].var;
4552
4553 /* The old value is kept until we are sure that the
4554 * new value is valid. */
4555 oldval = *(char_u **)varp;
4556 if (nextchar == '&') /* set to default val */
4557 {
4558 newval = options[opt_idx].def_val[
4559 ((flags & P_VI_DEF) || cp_val)
4560 ? VI_DEFAULT : VIM_DEFAULT];
4561 if ((char_u **)varp == &p_bg)
4562 {
4563 /* guess the value of 'background' */
4564#ifdef FEAT_GUI
4565 if (gui.in_use)
4566 newval = gui_bg_default();
4567 else
4568#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004569 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 }
4571
4572 /* expand environment variables and ~ (since the
4573 * default value was already expanded, only
4574 * required when an environment variable was set
4575 * later */
4576 if (newval == NULL)
4577 newval = empty_option;
4578 else
4579 {
4580 s = option_expand(opt_idx, newval);
4581 if (s == NULL)
4582 s = newval;
4583 newval = vim_strsave(s);
4584 }
4585 new_value_alloced = TRUE;
4586 }
4587 else if (nextchar == '<') /* set to global val */
4588 {
4589 newval = vim_strsave(*(char_u **)get_varp_scope(
4590 &(options[opt_idx]), OPT_GLOBAL));
4591 new_value_alloced = TRUE;
4592 }
4593 else
4594 {
4595 ++arg; /* jump to after the '=' or ':' */
4596
4597 /*
4598 * Set 'keywordprg' to ":help" if an empty
4599 * value was passed to :set by the user.
4600 * Misuse errbuf[] for the resulting string.
4601 */
4602 if (varp == (char_u *)&p_kp
4603 && (*arg == NUL || *arg == ' '))
4604 {
4605 STRCPY(errbuf, ":help");
4606 save_arg = arg;
4607 arg = errbuf;
4608 }
4609 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004610 * Convert 'backspace' number to string, for
4611 * adding, prepending and removing string.
4612 */
4613 else if (varp == (char_u *)&p_bs
4614 && VIM_ISDIGIT(**(char_u **)varp))
4615 {
4616 i = getdigits((char_u **)varp);
4617 switch (i)
4618 {
4619 case 0:
4620 *(char_u **)varp = empty_option;
4621 break;
4622 case 1:
4623 *(char_u **)varp = vim_strsave(
4624 (char_u *)"indent,eol");
4625 break;
4626 case 2:
4627 *(char_u **)varp = vim_strsave(
4628 (char_u *)"indent,eol,start");
4629 break;
4630 }
4631 vim_free(oldval);
4632 oldval = *(char_u **)varp;
4633 }
4634 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004635 * Convert 'whichwrap' number to string, for
4636 * backwards compatibility with Vim 3.0.
4637 * Misuse errbuf[] for the resulting string.
4638 */
4639 else if (varp == (char_u *)&p_ww
4640 && VIM_ISDIGIT(*arg))
4641 {
4642 *errbuf = NUL;
4643 i = getdigits(&arg);
4644 if (i & 1)
4645 STRCAT(errbuf, "b,");
4646 if (i & 2)
4647 STRCAT(errbuf, "s,");
4648 if (i & 4)
4649 STRCAT(errbuf, "h,l,");
4650 if (i & 8)
4651 STRCAT(errbuf, "<,>,");
4652 if (i & 16)
4653 STRCAT(errbuf, "[,],");
4654 if (*errbuf != NUL) /* remove trailing , */
4655 errbuf[STRLEN(errbuf) - 1] = NUL;
4656 save_arg = arg;
4657 arg = errbuf;
4658 }
4659 /*
4660 * Remove '>' before 'dir' and 'bdir', for
4661 * backwards compatibility with version 3.0
4662 */
4663 else if ( *arg == '>'
4664 && (varp == (char_u *)&p_dir
4665 || varp == (char_u *)&p_bdir))
4666 {
4667 ++arg;
4668 }
4669
4670 /* When setting the local value of a global
4671 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004672 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004673 && (opt_flags & OPT_LOCAL))
4674 origval = *(char_u **)get_varp(
4675 &options[opt_idx]);
4676 else
4677 origval = oldval;
4678
4679 /*
4680 * Copy the new string into allocated memory.
4681 * Can't use set_string_option_direct(), because
4682 * we need to remove the backslashes.
4683 */
4684 /* get a bit too much */
4685 newlen = (unsigned)STRLEN(arg) + 1;
4686 if (adding || prepending || removing)
4687 newlen += (unsigned)STRLEN(origval) + 1;
4688 newval = alloc(newlen);
4689 if (newval == NULL) /* out of mem, don't change */
4690 break;
4691 s = newval;
4692
4693 /*
4694 * Copy the string, skip over escaped chars.
4695 * For MS-DOS and WIN32 backslashes before normal
4696 * file name characters are not removed, and keep
4697 * backslash at start, for "\\machine\path", but
4698 * do remove it for "\\\\machine\\path".
4699 * The reverse is found in ExpandOldSetting().
4700 */
4701 while (*arg && !vim_iswhite(*arg))
4702 {
4703 if (*arg == '\\' && arg[1] != NUL
4704#ifdef BACKSLASH_IN_FILENAME
4705 && !((flags & P_EXPAND)
4706 && vim_isfilec(arg[1])
4707 && (arg[1] != '\\'
4708 || (s == newval
4709 && arg[2] != '\\')))
4710#endif
4711 )
4712 ++arg; /* remove backslash */
4713#ifdef FEAT_MBYTE
4714 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004715 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 {
4717 /* copy multibyte char */
4718 mch_memmove(s, arg, (size_t)i);
4719 arg += i;
4720 s += i;
4721 }
4722 else
4723#endif
4724 *s++ = *arg++;
4725 }
4726 *s = NUL;
4727
4728 /*
4729 * Expand environment variables and ~.
4730 * Don't do it when adding without inserting a
4731 * comma.
4732 */
4733 if (!(adding || prepending || removing)
4734 || (flags & P_COMMA))
4735 {
4736 s = option_expand(opt_idx, newval);
4737 if (s != NULL)
4738 {
4739 vim_free(newval);
4740 newlen = (unsigned)STRLEN(s) + 1;
4741 if (adding || prepending || removing)
4742 newlen += (unsigned)STRLEN(origval) + 1;
4743 newval = alloc(newlen);
4744 if (newval == NULL)
4745 break;
4746 STRCPY(newval, s);
4747 }
4748 }
4749
4750 /* locate newval[] in origval[] when removing it
4751 * and when adding to avoid duplicates */
4752 i = 0; /* init for GCC */
4753 if (removing || (flags & P_NODUP))
4754 {
4755 i = (int)STRLEN(newval);
4756 bs = 0;
4757 for (s = origval; *s; ++s)
4758 {
4759 if ((!(flags & P_COMMA)
4760 || s == origval
4761 || (s[-1] == ',' && !(bs & 1)))
4762 && STRNCMP(s, newval, i) == 0
4763 && (!(flags & P_COMMA)
4764 || s[i] == ','
4765 || s[i] == NUL))
4766 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004767 /* Count backslashes. Only a comma with an
4768 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 * recognized as a separator */
4770 if (s > origval && s[-1] == '\\')
4771 ++bs;
4772 else
4773 bs = 0;
4774 }
4775
4776 /* do not add if already there */
4777 if ((adding || prepending) && *s)
4778 {
4779 prepending = FALSE;
4780 adding = FALSE;
4781 STRCPY(newval, origval);
4782 }
4783 }
4784
4785 /* concatenate the two strings; add a ',' if
4786 * needed */
4787 if (adding || prepending)
4788 {
4789 comma = ((flags & P_COMMA) && *origval != NUL
4790 && *newval != NUL);
4791 if (adding)
4792 {
4793 i = (int)STRLEN(origval);
4794 mch_memmove(newval + i + comma, newval,
4795 STRLEN(newval) + 1);
4796 mch_memmove(newval, origval, (size_t)i);
4797 }
4798 else
4799 {
4800 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004801 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004802 }
4803 if (comma)
4804 newval[i] = ',';
4805 }
4806
4807 /* Remove newval[] from origval[]. (Note: "i" has
4808 * been set above and is used here). */
4809 if (removing)
4810 {
4811 STRCPY(newval, origval);
4812 if (*s)
4813 {
4814 /* may need to remove a comma */
4815 if (flags & P_COMMA)
4816 {
4817 if (s == origval)
4818 {
4819 /* include comma after string */
4820 if (s[i] == ',')
4821 ++i;
4822 }
4823 else
4824 {
4825 /* include comma before string */
4826 --s;
4827 ++i;
4828 }
4829 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004830 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004831 }
4832 }
4833
4834 if (flags & P_FLAGLIST)
4835 {
4836 /* Remove flags that appear twice. */
4837 for (s = newval; *s; ++s)
4838 if ((!(flags & P_COMMA) || *s != ',')
4839 && vim_strchr(s + 1, *s) != NULL)
4840 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004841 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004842 --s;
4843 }
4844 }
4845
4846 if (save_arg != NULL) /* number for 'whichwrap' */
4847 arg = save_arg;
4848 new_value_alloced = TRUE;
4849 }
4850
4851 /* Set the new value. */
4852 *(char_u **)(varp) = newval;
4853
4854 /* Handle side effects, and set the global value for
4855 * ":set" on local options. */
4856 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4857 new_value_alloced, oldval, errbuf, opt_flags);
4858
4859 /* If error detected, print the error message. */
4860 if (errmsg != NULL)
4861 goto skip;
4862 }
4863 else /* key code option */
4864 {
4865 char_u *p;
4866
4867 if (nextchar == '&')
4868 {
4869 if (add_termcap_entry(key_name, TRUE) == FAIL)
4870 errmsg = (char_u *)N_("E522: Not found in termcap");
4871 }
4872 else
4873 {
4874 ++arg; /* jump to after the '=' or ':' */
4875 for (p = arg; *p && !vim_iswhite(*p); ++p)
4876 if (*p == '\\' && p[1] != NUL)
4877 ++p;
4878 nextchar = *p;
4879 *p = NUL;
4880 add_termcode(key_name, arg, FALSE);
4881 *p = nextchar;
4882 }
4883 if (full_screen)
4884 ttest(FALSE);
4885 redraw_all_later(CLEAR);
4886 }
4887 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004888
Bram Moolenaar071d4272004-06-13 20:20:40 +00004889 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004890 did_set_option(opt_idx, opt_flags,
4891 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004892 }
4893
4894skip:
4895 /*
4896 * Advance to next argument.
4897 * - skip until a blank found, taking care of backslashes
4898 * - skip blanks
4899 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4900 */
4901 for (i = 0; i < 2 ; ++i)
4902 {
4903 while (*arg != NUL && !vim_iswhite(*arg))
4904 if (*arg++ == '\\' && *arg != NUL)
4905 ++arg;
4906 arg = skipwhite(arg);
4907 if (*arg != '=')
4908 break;
4909 }
4910 }
4911
4912 if (errmsg != NULL)
4913 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004914 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004915 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004916 if (i + (arg - startarg) < IOSIZE)
4917 {
4918 /* append the argument with the error */
4919 STRCAT(IObuff, ": ");
4920 mch_memmove(IObuff + i, startarg, (arg - startarg));
4921 IObuff[i + (arg - startarg)] = NUL;
4922 }
4923 /* make sure all characters are printable */
4924 trans_characters(IObuff, IOSIZE);
4925
4926 ++no_wait_return; /* wait_return done later */
4927 emsg(IObuff); /* show error highlighted */
4928 --no_wait_return;
4929
4930 return FAIL;
4931 }
4932
4933 arg = skipwhite(arg);
4934 }
4935
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004936theend:
4937 if (silent_mode && did_show)
4938 {
4939 /* After displaying option values in silent mode. */
4940 silent_mode = FALSE;
4941 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4942 msg_putchar('\n');
4943 cursor_on(); /* msg_start() switches it off */
4944 out_flush();
4945 silent_mode = TRUE;
4946 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4947 }
4948
Bram Moolenaar071d4272004-06-13 20:20:40 +00004949 return OK;
4950}
4951
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004952/*
4953 * Call this when an option has been given a new value through a user command.
4954 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4955 */
4956 static void
4957did_set_option(opt_idx, opt_flags, new_value)
4958 int opt_idx;
4959 int opt_flags; /* possibly with OPT_MODELINE */
4960 int new_value; /* value was replaced completely */
4961{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004962 long_u *p;
4963
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004964 options[opt_idx].flags |= P_WAS_SET;
4965
4966 /* When an option is set in the sandbox, from a modeline or in secure mode
4967 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004968 * flag. */
4969 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004970 if (secure
4971#ifdef HAVE_SANDBOX
4972 || sandbox != 0
4973#endif
4974 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004975 *p = *p | P_INSECURE;
4976 else if (new_value)
4977 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004978}
4979
Bram Moolenaar071d4272004-06-13 20:20:40 +00004980 static char_u *
4981illegal_char(errbuf, c)
4982 char_u *errbuf;
4983 int c;
4984{
4985 if (errbuf == NULL)
4986 return (char_u *)"";
4987 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00004988 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00004989 return errbuf;
4990}
4991
4992/*
4993 * Convert a key name or string into a key value.
4994 * Used for 'wildchar' and 'cedit' options.
4995 */
4996 static int
4997string_to_key(arg)
4998 char_u *arg;
4999{
5000 if (*arg == '<')
5001 return find_key_option(arg + 1);
5002 if (*arg == '^')
5003 return Ctrl_chr(arg[1]);
5004 return *arg;
5005}
5006
5007#ifdef FEAT_CMDWIN
5008/*
5009 * Check value of 'cedit' and set cedit_key.
5010 * Returns NULL if value is OK, error message otherwise.
5011 */
5012 static char_u *
5013check_cedit()
5014{
5015 int n;
5016
5017 if (*p_cedit == NUL)
5018 cedit_key = -1;
5019 else
5020 {
5021 n = string_to_key(p_cedit);
5022 if (vim_isprintc(n))
5023 return e_invarg;
5024 cedit_key = n;
5025 }
5026 return NULL;
5027}
5028#endif
5029
5030#ifdef FEAT_TITLE
5031/*
5032 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5033 * maketitle() to create and display it.
5034 * When switching the title or icon off, call mch_restore_title() to get
5035 * the old value back.
5036 */
5037 static void
5038did_set_title(icon)
5039 int icon; /* Did set icon instead of title */
5040{
5041 if (starting != NO_SCREEN
5042#ifdef FEAT_GUI
5043 && !gui.starting
5044#endif
5045 )
5046 {
5047 maketitle();
5048 if (icon)
5049 {
5050 if (!p_icon)
5051 mch_restore_title(2);
5052 }
5053 else
5054 {
5055 if (!p_title)
5056 mch_restore_title(1);
5057 }
5058 }
5059}
5060#endif
5061
5062/*
5063 * set_options_bin - called when 'bin' changes value.
5064 */
5065 void
5066set_options_bin(oldval, newval, opt_flags)
5067 int oldval;
5068 int newval;
5069 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5070{
5071 /*
5072 * The option values that are changed when 'bin' changes are
5073 * copied when 'bin is set and restored when 'bin' is reset.
5074 */
5075 if (newval)
5076 {
5077 if (!oldval) /* switched on */
5078 {
5079 if (!(opt_flags & OPT_GLOBAL))
5080 {
5081 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5082 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5083 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5084 curbuf->b_p_et_nobin = curbuf->b_p_et;
5085 }
5086 if (!(opt_flags & OPT_LOCAL))
5087 {
5088 p_tw_nobin = p_tw;
5089 p_wm_nobin = p_wm;
5090 p_ml_nobin = p_ml;
5091 p_et_nobin = p_et;
5092 }
5093 }
5094
5095 if (!(opt_flags & OPT_GLOBAL))
5096 {
5097 curbuf->b_p_tw = 0; /* no automatic line wrap */
5098 curbuf->b_p_wm = 0; /* no automatic line wrap */
5099 curbuf->b_p_ml = 0; /* no modelines */
5100 curbuf->b_p_et = 0; /* no expandtab */
5101 }
5102 if (!(opt_flags & OPT_LOCAL))
5103 {
5104 p_tw = 0;
5105 p_wm = 0;
5106 p_ml = FALSE;
5107 p_et = FALSE;
5108 p_bin = TRUE; /* needed when called for the "-b" argument */
5109 }
5110 }
5111 else if (oldval) /* switched off */
5112 {
5113 if (!(opt_flags & OPT_GLOBAL))
5114 {
5115 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5116 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5117 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5118 curbuf->b_p_et = curbuf->b_p_et_nobin;
5119 }
5120 if (!(opt_flags & OPT_LOCAL))
5121 {
5122 p_tw = p_tw_nobin;
5123 p_wm = p_wm_nobin;
5124 p_ml = p_ml_nobin;
5125 p_et = p_et_nobin;
5126 }
5127 }
5128}
5129
5130#ifdef FEAT_VIMINFO
5131/*
5132 * Find the parameter represented by the given character (eg ', :, ", or /),
5133 * and return its associated value in the 'viminfo' string.
5134 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005135 * If the parameter is not specified in the string or there is no following
5136 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137 */
5138 int
5139get_viminfo_parameter(type)
5140 int type;
5141{
5142 char_u *p;
5143
5144 p = find_viminfo_parameter(type);
5145 if (p != NULL && VIM_ISDIGIT(*p))
5146 return atoi((char *)p);
5147 return -1;
5148}
5149
5150/*
5151 * Find the parameter represented by the given character (eg ''', ':', '"', or
5152 * '/') in the 'viminfo' option and return a pointer to the string after it.
5153 * Return NULL if the parameter is not specified in the string.
5154 */
5155 char_u *
5156find_viminfo_parameter(type)
5157 int type;
5158{
5159 char_u *p;
5160
5161 for (p = p_viminfo; *p; ++p)
5162 {
5163 if (*p == type)
5164 return p + 1;
5165 if (*p == 'n') /* 'n' is always the last one */
5166 break;
5167 p = vim_strchr(p, ','); /* skip until next ',' */
5168 if (p == NULL) /* hit the end without finding parameter */
5169 break;
5170 }
5171 return NULL;
5172}
5173#endif
5174
5175/*
5176 * Expand environment variables for some string options.
5177 * These string options cannot be indirect!
5178 * If "val" is NULL expand the current value of the option.
5179 * Return pointer to NameBuff, or NULL when not expanded.
5180 */
5181 static char_u *
5182option_expand(opt_idx, val)
5183 int opt_idx;
5184 char_u *val;
5185{
5186 /* if option doesn't need expansion nothing to do */
5187 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5188 return NULL;
5189
5190 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5191 * expand_env() would truncate the string. */
5192 if (val != NULL && STRLEN(val) > MAXPATHL)
5193 return NULL;
5194
5195 if (val == NULL)
5196 val = *(char_u **)options[opt_idx].var;
5197
5198 /*
5199 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5200 * Escape spaces when expanding 'tags', they are used to separate file
5201 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005202 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005203 */
5204 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005205 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005206#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005207 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5208#endif
5209 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5211 return NULL;
5212
5213 return NameBuff;
5214}
5215
5216/*
5217 * After setting various option values: recompute variables that depend on
5218 * option values.
5219 */
5220 static void
5221didset_options()
5222{
5223 /* initialize the table for 'iskeyword' et.al. */
5224 (void)init_chartab();
5225
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005226#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005227 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005228#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005229 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5230#ifdef FEAT_SESSION
5231 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5232 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5233#endif
5234#ifdef FEAT_FOLDING
5235 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5236#endif
5237 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5238#ifdef FEAT_VIRTUALEDIT
5239 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5240#endif
5241#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5242 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5243#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005244#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005245 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005246 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005247 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005249#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5250 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5251#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005252#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005253 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5254#endif
5255#ifdef FEAT_CMDWIN
5256 /* set cedit_key */
5257 (void)check_cedit();
5258#endif
5259}
5260
5261/*
5262 * Check for string options that are NULL (normally only termcap options).
5263 */
5264 void
5265check_options()
5266{
5267 int opt_idx;
5268
5269 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5270 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5271 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5272}
5273
5274/*
5275 * Check string options in a buffer for NULL value.
5276 */
5277 void
5278check_buf_options(buf)
5279 buf_T *buf;
5280{
5281#if defined(FEAT_QUICKFIX)
5282 check_string_option(&buf->b_p_bh);
5283 check_string_option(&buf->b_p_bt);
5284#endif
5285#ifdef FEAT_MBYTE
5286 check_string_option(&buf->b_p_fenc);
5287#endif
5288 check_string_option(&buf->b_p_ff);
5289#ifdef FEAT_FIND_ID
5290 check_string_option(&buf->b_p_def);
5291 check_string_option(&buf->b_p_inc);
5292# ifdef FEAT_EVAL
5293 check_string_option(&buf->b_p_inex);
5294# endif
5295#endif
5296#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5297 check_string_option(&buf->b_p_inde);
5298 check_string_option(&buf->b_p_indk);
5299#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005300#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5301 check_string_option(&buf->b_p_bexpr);
5302#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005303#if defined(FEAT_CRYPT)
5304 check_string_option(&buf->b_p_cm);
5305#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005306#if defined(FEAT_EVAL)
5307 check_string_option(&buf->b_p_fex);
5308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005309#ifdef FEAT_CRYPT
5310 check_string_option(&buf->b_p_key);
5311#endif
5312 check_string_option(&buf->b_p_kp);
5313 check_string_option(&buf->b_p_mps);
5314 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005315 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 check_string_option(&buf->b_p_isk);
5317#ifdef FEAT_COMMENTS
5318 check_string_option(&buf->b_p_com);
5319#endif
5320#ifdef FEAT_FOLDING
5321 check_string_option(&buf->b_p_cms);
5322#endif
5323 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005324#ifdef FEAT_TEXTOBJ
5325 check_string_option(&buf->b_p_qe);
5326#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327#ifdef FEAT_SYN_HL
5328 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005329#endif
5330#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005331 check_string_option(&buf->b_s.b_p_spc);
5332 check_string_option(&buf->b_s.b_p_spf);
5333 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334#endif
5335#ifdef FEAT_SEARCHPATH
5336 check_string_option(&buf->b_p_sua);
5337#endif
5338#ifdef FEAT_CINDENT
5339 check_string_option(&buf->b_p_cink);
5340 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005341 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005342#endif
5343#ifdef FEAT_AUTOCMD
5344 check_string_option(&buf->b_p_ft);
5345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5347 check_string_option(&buf->b_p_cinw);
5348#endif
5349#ifdef FEAT_INS_EXPAND
5350 check_string_option(&buf->b_p_cpt);
5351#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005352#ifdef FEAT_COMPL_FUNC
5353 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005354 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356#ifdef FEAT_KEYMAP
5357 check_string_option(&buf->b_p_keymap);
5358#endif
5359#ifdef FEAT_QUICKFIX
5360 check_string_option(&buf->b_p_gp);
5361 check_string_option(&buf->b_p_mp);
5362 check_string_option(&buf->b_p_efm);
5363#endif
5364 check_string_option(&buf->b_p_ep);
5365 check_string_option(&buf->b_p_path);
5366 check_string_option(&buf->b_p_tags);
5367#ifdef FEAT_INS_EXPAND
5368 check_string_option(&buf->b_p_dict);
5369 check_string_option(&buf->b_p_tsr);
5370#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005371#ifdef FEAT_LISP
5372 check_string_option(&buf->b_p_lw);
5373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374}
5375
5376/*
5377 * Free the string allocated for an option.
5378 * Checks for the string being empty_option. This may happen if we're out of
5379 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5380 * check_options().
5381 * Does NOT check for P_ALLOCED flag!
5382 */
5383 void
5384free_string_option(p)
5385 char_u *p;
5386{
5387 if (p != empty_option)
5388 vim_free(p);
5389}
5390
5391 void
5392clear_string_option(pp)
5393 char_u **pp;
5394{
5395 if (*pp != empty_option)
5396 vim_free(*pp);
5397 *pp = empty_option;
5398}
5399
5400 static void
5401check_string_option(pp)
5402 char_u **pp;
5403{
5404 if (*pp == NULL)
5405 *pp = empty_option;
5406}
5407
5408/*
5409 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5410 */
5411 void
5412set_term_option_alloced(p)
5413 char_u **p;
5414{
5415 int opt_idx;
5416
5417 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5418 if (options[opt_idx].var == (char_u *)p)
5419 {
5420 options[opt_idx].flags |= P_ALLOCED;
5421 return;
5422 }
5423 return; /* cannot happen: didn't find it! */
5424}
5425
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005426#if defined(FEAT_EVAL) || defined(PROTO)
5427/*
5428 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5429 * Return FALSE when it wasn't.
5430 * Return -1 for an unknown option.
5431 */
5432 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005433was_set_insecurely(opt, opt_flags)
5434 char_u *opt;
5435 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005436{
5437 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005438 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005439
5440 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005441 {
5442 flagp = insecure_flag(idx, opt_flags);
5443 return (*flagp & P_INSECURE) != 0;
5444 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005445 EMSG2(_(e_intern2), "was_set_insecurely()");
5446 return -1;
5447}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005448
5449/*
5450 * Get a pointer to the flags used for the P_INSECURE flag of option
5451 * "opt_idx". For some local options a local flags field is used.
5452 */
5453 static long_u *
5454insecure_flag(opt_idx, opt_flags)
5455 int opt_idx;
5456 int opt_flags;
5457{
5458 if (opt_flags & OPT_LOCAL)
5459 switch ((int)options[opt_idx].indir)
5460 {
5461#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005462 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005463#endif
5464#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005465# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005466 case PV_FDE: return &curwin->w_p_fde_flags;
5467 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005468# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005469# ifdef FEAT_BEVAL
5470 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5471# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005472# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005473 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005474# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005475 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005476# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005477 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005478# endif
5479#endif
5480 }
5481
5482 /* Nothing special, return global flags field. */
5483 return &options[opt_idx].flags;
5484}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005485#endif
5486
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005487#ifdef FEAT_TITLE
5488static void redraw_titles __ARGS((void));
5489
5490/*
5491 * Redraw the window title and/or tab page text later.
5492 */
5493static void redraw_titles()
5494{
5495 need_maketitle = TRUE;
5496# ifdef FEAT_WINDOWS
5497 redraw_tabline = TRUE;
5498# endif
5499}
5500#endif
5501
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502/*
5503 * Set a string option to a new value (without checking the effect).
5504 * The string is copied into allocated memory.
5505 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005506 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005507 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508 */
5509 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005510set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511 char_u *name;
5512 int opt_idx;
5513 char_u *val;
5514 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005515 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516{
5517 char_u *s;
5518 char_u **varp;
5519 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005520 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521
Bram Moolenaar89d40322006-08-29 15:30:07 +00005522 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005523 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005524 idx = findoption(name);
5525 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005526 {
5527 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005530 }
5531
Bram Moolenaar89d40322006-08-29 15:30:07 +00005532 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533 return;
5534
5535 s = vim_strsave(val);
5536 if (s != NULL)
5537 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005538 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005540 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541 free_string_option(*varp);
5542 *varp = s;
5543
5544 /* For buffer/window local option may also set the global value. */
5545 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005546 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547
Bram Moolenaar89d40322006-08-29 15:30:07 +00005548 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549
5550 /* When setting both values of a global option with a local value,
5551 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005552 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553 {
5554 free_string_option(*varp);
5555 *varp = empty_option;
5556 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005557# ifdef FEAT_EVAL
5558 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005559 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005560 set_sid == 0 ? current_SID : set_sid);
5561# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562 }
5563}
5564
5565/*
5566 * Set global value for string option when it's a local option.
5567 */
5568 static void
5569set_string_option_global(opt_idx, varp)
5570 int opt_idx; /* option index */
5571 char_u **varp; /* pointer to option variable */
5572{
5573 char_u **p, *s;
5574
5575 /* the global value is always allocated */
5576 if (options[opt_idx].var == VAR_WIN)
5577 p = (char_u **)GLOBAL_WO(varp);
5578 else
5579 p = (char_u **)options[opt_idx].var;
5580 if (options[opt_idx].indir != PV_NONE
5581 && p != varp
5582 && (s = vim_strsave(*varp)) != NULL)
5583 {
5584 free_string_option(*p);
5585 *p = s;
5586 }
5587}
5588
5589/*
5590 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005591 *
5592 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005594 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005595set_string_option(opt_idx, value, opt_flags)
5596 int opt_idx;
5597 char_u *value;
5598 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5599{
5600 char_u *s;
5601 char_u **varp;
5602 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005603 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604
5605 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005606 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607
5608 s = vim_strsave(value);
5609 if (s != NULL)
5610 {
5611 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5612 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005613 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005614 ? OPT_GLOBAL : OPT_LOCAL)
5615 : opt_flags);
5616 oldval = *varp;
5617 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005618 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5619 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005620 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005622 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005623}
5624
5625/*
5626 * Handle string options that need some action to perform when changed.
5627 * Returns NULL for success, or an error message for an error.
5628 */
5629 static char_u *
5630did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5631 opt_flags)
5632 int opt_idx; /* index in options[] table */
5633 char_u **varp; /* pointer to the option variable */
5634 int new_value_alloced; /* new value was allocated */
5635 char_u *oldval; /* previous value of the option */
5636 char_u *errbuf; /* buffer for errors, or NULL */
5637 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5638{
5639 char_u *errmsg = NULL;
5640 char_u *s, *p;
5641 int did_chartab = FALSE;
5642 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005643 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005644#ifdef FEAT_GUI
5645 /* set when changing an option that only requires a redraw in the GUI */
5646 int redraw_gui_only = FALSE;
5647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648
5649 /* Get the global option to compare with, otherwise we would have to check
5650 * two values for all local options. */
5651 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5652
5653 /* Disallow changing some options from secure mode */
5654 if ((secure
5655#ifdef HAVE_SANDBOX
5656 || sandbox != 0
5657#endif
5658 ) && (options[opt_idx].flags & P_SECURE))
5659 {
5660 errmsg = e_secure;
5661 }
5662
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005663 /* Check for a "normal" file name in some options. Disallow a path
5664 * separator (slash and/or backslash), wildcards and characters that are
5665 * often illegal in a file name. */
5666 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005667 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005668 {
5669 errmsg = e_invarg;
5670 }
5671
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672 /* 'term' */
5673 else if (varp == &T_NAME)
5674 {
5675 if (T_NAME[0] == NUL)
5676 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5677#ifdef FEAT_GUI
5678 if (gui.in_use)
5679 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5680 else if (term_is_gui(T_NAME))
5681 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5682#endif
5683 else if (set_termname(T_NAME) == FAIL)
5684 errmsg = (char_u *)N_("E522: Not found in termcap");
5685 else
5686 /* Screen colors may have changed. */
5687 redraw_later_clear();
5688 }
5689
5690 /* 'backupcopy' */
5691 else if (varp == &p_bkc)
5692 {
5693 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5694 errmsg = e_invarg;
5695 if (((bkc_flags & BKC_AUTO) != 0)
5696 + ((bkc_flags & BKC_YES) != 0)
5697 + ((bkc_flags & BKC_NO) != 0) != 1)
5698 {
5699 /* Must have exactly one of "auto", "yes" and "no". */
5700 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5701 errmsg = e_invarg;
5702 }
5703 }
5704
5705 /* 'backupext' and 'patchmode' */
5706 else if (varp == &p_bex || varp == &p_pm)
5707 {
5708 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5709 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5710 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5711 }
5712
5713 /*
5714 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5715 * If the new option is invalid, use old value. 'lisp' option: refill
5716 * chartab[] for '-' char
5717 */
5718 else if ( varp == &p_isi
5719 || varp == &(curbuf->b_p_isk)
5720 || varp == &p_isp
5721 || varp == &p_isf)
5722 {
5723 if (init_chartab() == FAIL)
5724 {
5725 did_chartab = TRUE; /* need to restore it below */
5726 errmsg = e_invarg; /* error in value */
5727 }
5728 }
5729
5730 /* 'helpfile' */
5731 else if (varp == &p_hf)
5732 {
5733 /* May compute new values for $VIM and $VIMRUNTIME */
5734 if (didset_vim)
5735 {
5736 vim_setenv((char_u *)"VIM", (char_u *)"");
5737 didset_vim = FALSE;
5738 }
5739 if (didset_vimruntime)
5740 {
5741 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5742 didset_vimruntime = FALSE;
5743 }
5744 }
5745
Bram Moolenaar1a384422010-07-14 19:53:30 +02005746#ifdef FEAT_SYN_HL
5747 /* 'colorcolumn' */
5748 else if (varp == &curwin->w_p_cc)
5749 errmsg = check_colorcolumn(curwin);
5750#endif
5751
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752#ifdef FEAT_MULTI_LANG
5753 /* 'helplang' */
5754 else if (varp == &p_hlg)
5755 {
5756 /* Check for "", "ab", "ab,cd", etc. */
5757 for (s = p_hlg; *s != NUL; s += 3)
5758 {
5759 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5760 {
5761 errmsg = e_invarg;
5762 break;
5763 }
5764 if (s[2] == NUL)
5765 break;
5766 }
5767 }
5768#endif
5769
5770 /* 'highlight' */
5771 else if (varp == &p_hl)
5772 {
5773 if (highlight_changed() == FAIL)
5774 errmsg = e_invarg; /* invalid flags */
5775 }
5776
5777 /* 'nrformats' */
5778 else if (gvarp == &p_nf)
5779 {
5780 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5781 errmsg = e_invarg;
5782 }
5783
5784#ifdef FEAT_SESSION
5785 /* 'sessionoptions' */
5786 else if (varp == &p_ssop)
5787 {
5788 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5789 errmsg = e_invarg;
5790 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5791 {
5792 /* Don't allow both "sesdir" and "curdir". */
5793 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5794 errmsg = e_invarg;
5795 }
5796 }
5797 /* 'viewoptions' */
5798 else if (varp == &p_vop)
5799 {
5800 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5801 errmsg = e_invarg;
5802 }
5803#endif
5804
5805 /* 'scrollopt' */
5806#ifdef FEAT_SCROLLBIND
5807 else if (varp == &p_sbo)
5808 {
5809 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5810 errmsg = e_invarg;
5811 }
5812#endif
5813
5814 /* 'ambiwidth' */
5815#ifdef FEAT_MBYTE
5816 else if (varp == &p_ambw)
5817 {
5818 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5819 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005820 else if (set_chars_option(&p_lcs) != NULL)
5821 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5822# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5823 else if (set_chars_option(&p_fcs) != NULL)
5824 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5825# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826 }
5827#endif
5828
5829 /* 'background' */
5830 else if (varp == &p_bg)
5831 {
5832 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5833 {
5834#ifdef FEAT_EVAL
5835 int dark = (*p_bg == 'd');
5836#endif
5837
5838 init_highlight(FALSE, FALSE);
5839
5840#ifdef FEAT_EVAL
5841 if (dark != (*p_bg == 'd')
5842 && get_var_value((char_u *)"g:colors_name") != NULL)
5843 {
5844 /* The color scheme must have set 'background' back to another
5845 * value, that's not what we want here. Disable the color
5846 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005847 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 free_string_option(p_bg);
5849 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5850 check_string_option(&p_bg);
5851 init_highlight(FALSE, FALSE);
5852 }
5853#endif
5854 }
5855 else
5856 errmsg = e_invarg;
5857 }
5858
5859 /* 'wildmode' */
5860 else if (varp == &p_wim)
5861 {
5862 if (check_opt_wim() == FAIL)
5863 errmsg = e_invarg;
5864 }
5865
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005866#ifdef FEAT_CMDL_COMPL
5867 /* 'wildoptions' */
5868 else if (varp == &p_wop)
5869 {
5870 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5871 errmsg = e_invarg;
5872 }
5873#endif
5874
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875#ifdef FEAT_WAK
5876 /* 'winaltkeys' */
5877 else if (varp == &p_wak)
5878 {
5879 if (*p_wak == NUL
5880 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5881 errmsg = e_invarg;
5882# ifdef FEAT_MENU
5883# ifdef FEAT_GUI_MOTIF
5884 else if (gui.in_use)
5885 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5886# else
5887# ifdef FEAT_GUI_GTK
5888 else if (gui.in_use)
5889 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5890# endif
5891# endif
5892# endif
5893 }
5894#endif
5895
5896#ifdef FEAT_AUTOCMD
5897 /* 'eventignore' */
5898 else if (varp == &p_ei)
5899 {
5900 if (check_ei() == FAIL)
5901 errmsg = e_invarg;
5902 }
5903#endif
5904
5905#ifdef FEAT_MBYTE
5906 /* 'encoding' and 'fileencoding' */
5907 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5908 {
5909 if (gvarp == &p_fenc)
5910 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005911 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 errmsg = e_modifiable;
5913 else if (vim_strchr(*varp, ',') != NULL)
5914 /* No comma allowed in 'fileencoding'; catches confusing it
5915 * with 'fileencodings'. */
5916 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005918 {
5919# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005921 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005922# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005923 /* Add 'fileencoding' to the swap file. */
5924 ml_setflags(curbuf);
5925 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926 }
5927 if (errmsg == NULL)
5928 {
5929 /* canonize the value, so that STRCMP() can be used on it */
5930 p = enc_canonize(*varp);
5931 if (p != NULL)
5932 {
5933 vim_free(*varp);
5934 *varp = p;
5935 }
5936 if (varp == &p_enc)
5937 {
5938 errmsg = mb_init();
5939# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005940 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941# endif
5942 }
5943 }
5944
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005945# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5947 {
5948 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5949 if (STRCMP(p_tenc, "utf-8") != 0)
5950 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5951 }
5952# endif
5953
5954 if (errmsg == NULL)
5955 {
5956# ifdef FEAT_KEYMAP
5957 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5958 * (with another encoding). */
5959 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5960 (void)keymap_init();
5961# endif
5962
5963 /* When 'termencoding' is not empty and 'encoding' changes or when
5964 * 'termencoding' changes, need to setup for keyboard input and
5965 * display output conversion. */
5966 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5967 {
5968 convert_setup(&input_conv, p_tenc, p_enc);
5969 convert_setup(&output_conv, p_enc, p_tenc);
5970 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00005971
5972# if defined(WIN3264) && defined(FEAT_MBYTE)
5973 /* $HOME may have characters in active code page. */
5974 if (varp == &p_enc)
5975 init_homedir();
5976# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977 }
5978 }
5979#endif
5980
5981#if defined(FEAT_POSTSCRIPT)
5982 else if (varp == &p_penc)
5983 {
5984 /* Canonize printencoding if VIM standard one */
5985 p = enc_canonize(p_penc);
5986 if (p != NULL)
5987 {
5988 vim_free(p_penc);
5989 p_penc = p;
5990 }
5991 else
5992 {
5993 /* Ensure lower case and '-' for '_' */
5994 for (s = p_penc; *s != NUL; s++)
5995 {
5996 if (*s == '_')
5997 *s = '-';
5998 else
5999 *s = TOLOWER_ASC(*s);
6000 }
6001 }
6002 }
6003#endif
6004
Bram Moolenaar9372a112005-12-06 19:59:18 +00006005#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006 else if (varp == &p_imak)
6007 {
6008 if (gui.in_use && !im_xim_isvalid_imactivate())
6009 errmsg = e_invarg;
6010 }
6011#endif
6012
6013#ifdef FEAT_KEYMAP
6014 else if (varp == &curbuf->b_p_keymap)
6015 {
6016 /* load or unload key mapping tables */
6017 errmsg = keymap_init();
6018
Bram Moolenaarfab06232009-03-04 03:13:35 +00006019 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006020 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006021 if (*curbuf->b_p_keymap != NUL)
6022 {
6023 /* Installed a new keymap, switch on using it. */
6024 curbuf->b_p_iminsert = B_IMODE_LMAP;
6025 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6026 curbuf->b_p_imsearch = B_IMODE_LMAP;
6027 }
6028 else
6029 {
6030 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6031 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6032 curbuf->b_p_iminsert = B_IMODE_NONE;
6033 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6034 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6035 }
6036 if ((opt_flags & OPT_LOCAL) == 0)
6037 {
6038 set_iminsert_global();
6039 set_imsearch_global();
6040 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006041# ifdef FEAT_WINDOWS
6042 status_redraw_curbuf();
6043# endif
6044 }
6045 }
6046#endif
6047
6048 /* 'fileformat' */
6049 else if (gvarp == &p_ff)
6050 {
6051 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6052 errmsg = e_modifiable;
6053 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6054 errmsg = e_invarg;
6055 else
6056 {
6057 /* may also change 'textmode' */
6058 if (get_fileformat(curbuf) == EOL_DOS)
6059 curbuf->b_p_tx = TRUE;
6060 else
6061 curbuf->b_p_tx = FALSE;
6062#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006063 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006064#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006065 /* update flag in swap file */
6066 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006067 /* Redraw needed when switching to/from "mac": a CR in the text
6068 * will be displayed differently. */
6069 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6070 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006071 }
6072 }
6073
6074 /* 'fileformats' */
6075 else if (varp == &p_ffs)
6076 {
6077 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6078 errmsg = e_invarg;
6079 else
6080 {
6081 /* also change 'textauto' */
6082 if (*p_ffs == NUL)
6083 p_ta = FALSE;
6084 else
6085 p_ta = TRUE;
6086 }
6087 }
6088
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006089#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090 /* 'cryptkey' */
6091 else if (gvarp == &p_key)
6092 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006093# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006094 /* Make sure the ":set" command doesn't show the new value in the
6095 * history. */
6096 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006097# endif
6098 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6099 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006100 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6101 }
6102
6103 else if (gvarp == &p_cm)
6104 {
6105 if (opt_flags & OPT_LOCAL)
6106 p = curbuf->b_p_cm;
6107 else
6108 p = p_cm;
6109 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6110 errmsg = e_invarg;
6111 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6112 errmsg = e_invarg;
6113 else
6114 {
6115 /* When setting the global value to empty, make it "zip". */
6116 if (*p_cm == NUL)
6117 {
6118 if (new_value_alloced)
6119 free_string_option(p_cm);
6120 p_cm = vim_strsave((char_u *)"zip");
6121 new_value_alloced = TRUE;
6122 }
6123
6124 /* Need to update the swapfile when the effective method changed.
6125 * Set "s" to the effective old value, "p" to the effective new
6126 * method and compare. */
6127 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6128 s = p_cm; /* was previously using the global value */
6129 else
6130 s = oldval;
6131 if (*curbuf->b_p_cm == NUL)
6132 p = p_cm; /* is now using the global value */
6133 else
6134 p = curbuf->b_p_cm;
6135 if (STRCMP(s, p) != 0)
6136 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6137 crypt_method_from_string(s));
6138
6139 /* If the global value changes need to update the swapfile for all
6140 * buffers using that value. */
6141 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6142 {
6143 buf_T *buf;
6144
6145 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6146 if (buf != curbuf && *buf->b_p_cm == NUL)
6147 ml_set_crypt_key(buf, buf->b_p_key,
6148 crypt_method_from_string(oldval));
6149 }
6150 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151 }
6152#endif
6153
6154 /* 'matchpairs' */
6155 else if (gvarp == &p_mps)
6156 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006157#ifdef FEAT_MBYTE
6158 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006160 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006162 int x2 = -1;
6163 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006164
6165 if (*p != NUL)
6166 p += mb_ptr2len(p);
6167 if (*p != NUL)
6168 x2 = *p++;
6169 if (*p != NUL)
6170 {
6171 x3 = mb_ptr2char(p);
6172 p += mb_ptr2len(p);
6173 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006174 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006175 {
6176 errmsg = e_invarg;
6177 break;
6178 }
6179 if (*p == NUL)
6180 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006181 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006182 }
6183 else
6184#endif
6185 {
6186 /* Check for "x:y,x:y" */
6187 for (p = *varp; *p != NUL; p += 4)
6188 {
6189 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6190 {
6191 errmsg = e_invarg;
6192 break;
6193 }
6194 if (p[3] == NUL)
6195 break;
6196 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006197 }
6198 }
6199
6200#ifdef FEAT_COMMENTS
6201 /* 'comments' */
6202 else if (gvarp == &p_com)
6203 {
6204 for (s = *varp; *s; )
6205 {
6206 while (*s && *s != ':')
6207 {
6208 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6209 && !VIM_ISDIGIT(*s) && *s != '-')
6210 {
6211 errmsg = illegal_char(errbuf, *s);
6212 break;
6213 }
6214 ++s;
6215 }
6216 if (*s++ == NUL)
6217 errmsg = (char_u *)N_("E524: Missing colon");
6218 else if (*s == ',' || *s == NUL)
6219 errmsg = (char_u *)N_("E525: Zero length string");
6220 if (errmsg != NULL)
6221 break;
6222 while (*s && *s != ',')
6223 {
6224 if (*s == '\\' && s[1] != NUL)
6225 ++s;
6226 ++s;
6227 }
6228 s = skip_to_option_part(s);
6229 }
6230 }
6231#endif
6232
6233 /* 'listchars' */
6234 else if (varp == &p_lcs)
6235 {
6236 errmsg = set_chars_option(varp);
6237 }
6238
6239#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6240 /* 'fillchars' */
6241 else if (varp == &p_fcs)
6242 {
6243 errmsg = set_chars_option(varp);
6244 }
6245#endif
6246
6247#ifdef FEAT_CMDWIN
6248 /* 'cedit' */
6249 else if (varp == &p_cedit)
6250 {
6251 errmsg = check_cedit();
6252 }
6253#endif
6254
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006255 /* 'verbosefile' */
6256 else if (varp == &p_vfile)
6257 {
6258 verbose_stop();
6259 if (*p_vfile != NUL && verbose_open() == FAIL)
6260 errmsg = e_invarg;
6261 }
6262
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263#ifdef FEAT_VIMINFO
6264 /* 'viminfo' */
6265 else if (varp == &p_viminfo)
6266 {
6267 for (s = p_viminfo; *s;)
6268 {
6269 /* Check it's a valid character */
6270 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6271 {
6272 errmsg = illegal_char(errbuf, *s);
6273 break;
6274 }
6275 if (*s == 'n') /* name is always last one */
6276 {
6277 break;
6278 }
6279 else if (*s == 'r') /* skip until next ',' */
6280 {
6281 while (*++s && *s != ',')
6282 ;
6283 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006284 else if (*s == '%')
6285 {
6286 /* optional number */
6287 while (vim_isdigit(*++s))
6288 ;
6289 }
6290 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006291 ++s; /* no extra chars */
6292 else /* must have a number */
6293 {
6294 while (vim_isdigit(*++s))
6295 ;
6296
6297 if (!VIM_ISDIGIT(*(s - 1)))
6298 {
6299 if (errbuf != NULL)
6300 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006301 sprintf((char *)errbuf,
6302 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 transchar_byte(*(s - 1)));
6304 errmsg = errbuf;
6305 }
6306 else
6307 errmsg = (char_u *)"";
6308 break;
6309 }
6310 }
6311 if (*s == ',')
6312 ++s;
6313 else if (*s)
6314 {
6315 if (errbuf != NULL)
6316 errmsg = (char_u *)N_("E527: Missing comma");
6317 else
6318 errmsg = (char_u *)"";
6319 break;
6320 }
6321 }
6322 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6323 errmsg = (char_u *)N_("E528: Must specify a ' value");
6324 }
6325#endif /* FEAT_VIMINFO */
6326
6327 /* terminal options */
6328 else if (istermoption(&options[opt_idx]) && full_screen)
6329 {
6330 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6331 if (varp == &T_CCO)
6332 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006333 int colors = atoi((char *)T_CCO);
6334
6335 /* Only reinitialize colors if t_Co value has really changed to
6336 * avoid expensive reload of colorscheme if t_Co is set to the
6337 * same value multiple times. */
6338 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006340 t_colors = colors;
6341 if (t_colors <= 1)
6342 {
6343 if (new_value_alloced)
6344 vim_free(T_CCO);
6345 T_CCO = empty_option;
6346 }
6347 /* We now have a different color setup, initialize it again. */
6348 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006349 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 }
6351 ttest(FALSE);
6352 if (varp == &T_ME)
6353 {
6354 out_str(T_ME);
6355 redraw_later(CLEAR);
6356#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6357 /* Since t_me has been set, this probably means that the user
6358 * wants to use this as default colors. Need to reset default
6359 * background/foreground colors. */
6360 mch_set_normal_colors();
6361#endif
6362 }
6363 }
6364
6365#ifdef FEAT_LINEBREAK
6366 /* 'showbreak' */
6367 else if (varp == &p_sbr)
6368 {
6369 for (s = p_sbr; *s; )
6370 {
6371 if (ptr2cells(s) != 1)
6372 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006373 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374 }
6375 }
6376#endif
6377
6378#ifdef FEAT_GUI
6379 /* 'guifont' */
6380 else if (varp == &p_guifont)
6381 {
6382 if (gui.in_use)
6383 {
6384 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006385# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 /*
6387 * Put up a font dialog and let the user select a new value.
6388 * If this is cancelled go back to the old value but don't
6389 * give an error message.
6390 */
6391 if (STRCMP(p, "*") == 0)
6392 {
6393 p = gui_mch_font_dialog(oldval);
6394
6395 if (new_value_alloced)
6396 free_string_option(p_guifont);
6397
6398 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6399 new_value_alloced = TRUE;
6400 }
6401# endif
6402 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6403 {
6404# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6405 if (STRCMP(p_guifont, "*") == 0)
6406 {
6407 /* Dialog was cancelled: Keep the old value without giving
6408 * an error message. */
6409 if (new_value_alloced)
6410 free_string_option(p_guifont);
6411 p_guifont = vim_strsave(oldval);
6412 new_value_alloced = TRUE;
6413 }
6414 else
6415# endif
6416 errmsg = (char_u *)N_("E596: Invalid font(s)");
6417 }
6418 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006419 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420 }
6421# ifdef FEAT_XFONTSET
6422 else if (varp == &p_guifontset)
6423 {
6424 if (STRCMP(p_guifontset, "*") == 0)
6425 errmsg = (char_u *)N_("E597: can't select fontset");
6426 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6427 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006428 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006429 }
6430# endif
6431# ifdef FEAT_MBYTE
6432 else if (varp == &p_guifontwide)
6433 {
6434 if (STRCMP(p_guifontwide, "*") == 0)
6435 errmsg = (char_u *)N_("E533: can't select wide font");
6436 else if (gui_get_wide_font() == FAIL)
6437 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006438 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 }
6440# endif
6441#endif
6442
6443#ifdef CURSOR_SHAPE
6444 /* 'guicursor' */
6445 else if (varp == &p_guicursor)
6446 errmsg = parse_shape_opt(SHAPE_CURSOR);
6447#endif
6448
6449#ifdef FEAT_MOUSESHAPE
6450 /* 'mouseshape' */
6451 else if (varp == &p_mouseshape)
6452 {
6453 errmsg = parse_shape_opt(SHAPE_MOUSE);
6454 update_mouseshape(-1);
6455 }
6456#endif
6457
6458#ifdef FEAT_PRINTER
6459 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006460 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006461# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006462 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006463 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006464# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006465#endif
6466
6467#ifdef FEAT_LANGMAP
6468 /* 'langmap' */
6469 else if (varp == &p_langmap)
6470 langmap_set();
6471#endif
6472
6473#ifdef FEAT_LINEBREAK
6474 /* 'breakat' */
6475 else if (varp == &p_breakat)
6476 fill_breakat_flags();
6477#endif
6478
6479#ifdef FEAT_TITLE
6480 /* 'titlestring' and 'iconstring' */
6481 else if (varp == &p_titlestring || varp == &p_iconstring)
6482 {
6483# ifdef FEAT_STL_OPT
6484 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6485
6486 /* NULL => statusline syntax */
6487 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6488 stl_syntax |= flagval;
6489 else
6490 stl_syntax &= ~flagval;
6491# endif
6492 did_set_title(varp == &p_iconstring);
6493
6494 }
6495#endif
6496
6497#ifdef FEAT_GUI
6498 /* 'guioptions' */
6499 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006500 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006501 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006502 redraw_gui_only = TRUE;
6503 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006504#endif
6505
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006506#if defined(FEAT_GUI_TABLINE)
6507 /* 'guitablabel' */
6508 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006509 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006510 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006511 redraw_gui_only = TRUE;
6512 }
6513 /* 'guitabtooltip' */
6514 else if (varp == &p_gtt)
6515 {
6516 redraw_gui_only = TRUE;
6517 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006518#endif
6519
Bram Moolenaar071d4272004-06-13 20:20:40 +00006520#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6521 /* 'ttymouse' */
6522 else if (varp == &p_ttym)
6523 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006524 /* Switch the mouse off before changing the escape sequences used for
6525 * that. */
6526 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006527 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6528 errmsg = e_invarg;
6529 else
6530 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006531 if (termcap_active)
6532 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006533 }
6534#endif
6535
Bram Moolenaar071d4272004-06-13 20:20:40 +00006536 /* 'selection' */
6537 else if (varp == &p_sel)
6538 {
6539 if (*p_sel == NUL
6540 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6541 errmsg = e_invarg;
6542 }
6543
6544 /* 'selectmode' */
6545 else if (varp == &p_slm)
6546 {
6547 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6548 errmsg = e_invarg;
6549 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006550
6551#ifdef FEAT_BROWSE
6552 /* 'browsedir' */
6553 else if (varp == &p_bsdir)
6554 {
6555 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6556 && !mch_isdir(p_bsdir))
6557 errmsg = e_invarg;
6558 }
6559#endif
6560
Bram Moolenaar071d4272004-06-13 20:20:40 +00006561 /* 'keymodel' */
6562 else if (varp == &p_km)
6563 {
6564 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6565 errmsg = e_invarg;
6566 else
6567 {
6568 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6569 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6570 }
6571 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006572
6573 /* 'mousemodel' */
6574 else if (varp == &p_mousem)
6575 {
6576 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6577 errmsg = e_invarg;
6578#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6579 else if (*p_mousem != *oldval)
6580 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6581 * to create or delete the popup menus. */
6582 gui_motif_update_mousemodel(root_menu);
6583#endif
6584 }
6585
6586 /* 'switchbuf' */
6587 else if (varp == &p_swb)
6588 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006589 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 errmsg = e_invarg;
6591 }
6592
6593 /* 'debug' */
6594 else if (varp == &p_debug)
6595 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006596 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006597 errmsg = e_invarg;
6598 }
6599
6600 /* 'display' */
6601 else if (varp == &p_dy)
6602 {
6603 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6604 errmsg = e_invarg;
6605 else
6606 (void)init_chartab();
6607
6608 }
6609
6610#ifdef FEAT_VERTSPLIT
6611 /* 'eadirection' */
6612 else if (varp == &p_ead)
6613 {
6614 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6615 errmsg = e_invarg;
6616 }
6617#endif
6618
6619#ifdef FEAT_CLIPBOARD
6620 /* 'clipboard' */
6621 else if (varp == &p_cb)
6622 errmsg = check_clipboard_option();
6623#endif
6624
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006625#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006626 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6627 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006628 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006629 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006630 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006631 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006632
Bram Moolenaar860cae12010-06-05 23:22:07 +02006633 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006634 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006635 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6636 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006637 ".add") != 0))
6638 errmsg = e_invarg;
6639 }
6640
6641 if (errmsg == NULL)
6642 {
6643 FOR_ALL_WINDOWS(wp)
6644 if (wp->w_buffer == curbuf && wp->w_p_spell)
6645 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006646 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006647# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006648 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006649# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006650 }
6651 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006652 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006653 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006654 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006655 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006656 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006657 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006658 /* 'spellsuggest' */
6659 else if (varp == &p_sps)
6660 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006661 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006662 errmsg = e_invarg;
6663 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006664 /* 'mkspellmem' */
6665 else if (varp == &p_msm)
6666 {
6667 if (spell_check_msm() != OK)
6668 errmsg = e_invarg;
6669 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006670#endif
6671
Bram Moolenaar071d4272004-06-13 20:20:40 +00006672#ifdef FEAT_QUICKFIX
6673 /* When 'bufhidden' is set, check for valid value. */
6674 else if (gvarp == &p_bh)
6675 {
6676 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6677 errmsg = e_invarg;
6678 }
6679
6680 /* When 'buftype' is set, check for valid value. */
6681 else if (gvarp == &p_bt)
6682 {
6683 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6684 errmsg = e_invarg;
6685 else
6686 {
6687# ifdef FEAT_WINDOWS
6688 if (curwin->w_status_height)
6689 {
6690 curwin->w_redr_status = TRUE;
6691 redraw_later(VALID);
6692 }
6693# endif
6694 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006695# ifdef FEAT_TITLE
6696 redraw_titles();
6697# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698 }
6699 }
6700#endif
6701
6702#ifdef FEAT_STL_OPT
6703 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006704 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006705 {
6706 int wid;
6707
6708 if (varp == &p_ruf) /* reset ru_wid first */
6709 ru_wid = 0;
6710 s = *varp;
6711 if (varp == &p_ruf && *s == '%')
6712 {
6713 /* set ru_wid if 'ruf' starts with "%99(" */
6714 if (*++s == '-') /* ignore a '-' */
6715 s++;
6716 wid = getdigits(&s);
6717 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6718 ru_wid = wid;
6719 else
6720 errmsg = check_stl_option(p_ruf);
6721 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006722 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006723 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006724 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006725 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006726 comp_col();
6727 }
6728#endif
6729
6730#ifdef FEAT_INS_EXPAND
6731 /* check if it is a valid value for 'complete' -- Acevedo */
6732 else if (gvarp == &p_cpt)
6733 {
6734 for (s = *varp; *s;)
6735 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006736 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006737 s++;
6738 if (!*s)
6739 break;
6740 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6741 {
6742 errmsg = illegal_char(errbuf, *s);
6743 break;
6744 }
6745 if (*++s != NUL && *s != ',' && *s != ' ')
6746 {
6747 if (s[-1] == 'k' || s[-1] == 's')
6748 {
6749 /* skip optional filename after 'k' and 's' */
6750 while (*s && *s != ',' && *s != ' ')
6751 {
6752 if (*s == '\\')
6753 ++s;
6754 ++s;
6755 }
6756 }
6757 else
6758 {
6759 if (errbuf != NULL)
6760 {
6761 sprintf((char *)errbuf,
6762 _("E535: Illegal character after <%c>"),
6763 *--s);
6764 errmsg = errbuf;
6765 }
6766 else
6767 errmsg = (char_u *)"";
6768 break;
6769 }
6770 }
6771 }
6772 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006773
6774 /* 'completeopt' */
6775 else if (varp == &p_cot)
6776 {
6777 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6778 errmsg = e_invarg;
6779 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780#endif /* FEAT_INS_EXPAND */
6781
6782
6783#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6784 else if (varp == &p_toolbar)
6785 {
6786 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6787 &toolbar_flags, TRUE) != OK)
6788 errmsg = e_invarg;
6789 else
6790 {
6791 out_flush();
6792 gui_mch_show_toolbar((toolbar_flags &
6793 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6794 }
6795 }
6796#endif
6797
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006798#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006799 /* 'toolbariconsize': GTK+ 2 only */
6800 else if (varp == &p_tbis)
6801 {
6802 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6803 errmsg = e_invarg;
6804 else
6805 {
6806 out_flush();
6807 gui_mch_show_toolbar((toolbar_flags &
6808 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6809 }
6810 }
6811#endif
6812
6813 /* 'pastetoggle': translate key codes like in a mapping */
6814 else if (varp == &p_pt)
6815 {
6816 if (*p_pt)
6817 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006818 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819 if (p != NULL)
6820 {
6821 if (new_value_alloced)
6822 free_string_option(p_pt);
6823 p_pt = p;
6824 new_value_alloced = TRUE;
6825 }
6826 }
6827 }
6828
6829 /* 'backspace' */
6830 else if (varp == &p_bs)
6831 {
6832 if (VIM_ISDIGIT(*p_bs))
6833 {
6834 if (*p_bs >'2' || p_bs[1] != NUL)
6835 errmsg = e_invarg;
6836 }
6837 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6838 errmsg = e_invarg;
6839 }
6840
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006841#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 /* 'casemap' */
6843 else if (varp == &p_cmp)
6844 {
6845 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6846 errmsg = e_invarg;
6847 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006848#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006849
6850#ifdef FEAT_DIFF
6851 /* 'diffopt' */
6852 else if (varp == &p_dip)
6853 {
6854 if (diffopt_changed() == FAIL)
6855 errmsg = e_invarg;
6856 }
6857#endif
6858
6859#ifdef FEAT_FOLDING
6860 /* 'foldmethod' */
6861 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6862 {
6863 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6864 || *curwin->w_p_fdm == NUL)
6865 errmsg = e_invarg;
6866 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006867 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006868 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006869 if (foldmethodIsDiff(curwin))
6870 newFoldLevel();
6871 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006872 }
6873# ifdef FEAT_EVAL
6874 /* 'foldexpr' */
6875 else if (varp == &curwin->w_p_fde)
6876 {
6877 if (foldmethodIsExpr(curwin))
6878 foldUpdateAll(curwin);
6879 }
6880# endif
6881 /* 'foldmarker' */
6882 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6883 {
6884 p = vim_strchr(*varp, ',');
6885 if (p == NULL)
6886 errmsg = (char_u *)N_("E536: comma required");
6887 else if (p == *varp || p[1] == NUL)
6888 errmsg = e_invarg;
6889 else if (foldmethodIsMarker(curwin))
6890 foldUpdateAll(curwin);
6891 }
6892 /* 'commentstring' */
6893 else if (gvarp == &p_cms)
6894 {
6895 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6896 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6897 }
6898 /* 'foldopen' */
6899 else if (varp == &p_fdo)
6900 {
6901 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6902 errmsg = e_invarg;
6903 }
6904 /* 'foldclose' */
6905 else if (varp == &p_fcl)
6906 {
6907 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6908 errmsg = e_invarg;
6909 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006910 /* 'foldignore' */
6911 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6912 {
6913 if (foldmethodIsIndent(curwin))
6914 foldUpdateAll(curwin);
6915 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006916#endif
6917
6918#ifdef FEAT_VIRTUALEDIT
6919 /* 'virtualedit' */
6920 else if (varp == &p_ve)
6921 {
6922 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6923 errmsg = e_invarg;
6924 else if (STRCMP(p_ve, oldval) != 0)
6925 {
6926 /* Recompute cursor position in case the new 've' setting
6927 * changes something. */
6928 validate_virtcol();
6929 coladvance(curwin->w_virtcol);
6930 }
6931 }
6932#endif
6933
6934#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6935 else if (varp == &p_csqf)
6936 {
6937 if (p_csqf != NULL)
6938 {
6939 p = p_csqf;
6940 while (*p != NUL)
6941 {
6942 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6943 || p[1] == NUL
6944 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6945 || (p[2] != NUL && p[2] != ','))
6946 {
6947 errmsg = e_invarg;
6948 break;
6949 }
6950 else if (p[2] == NUL)
6951 break;
6952 else
6953 p += 3;
6954 }
6955 }
6956 }
6957#endif
6958
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01006959#ifdef FEAT_CINDENT
6960 /* 'cinoptions' */
6961 else if (gvarp == &p_cino)
6962 {
6963 /* TODO: recognize errors */
6964 parse_cino(curbuf);
6965 }
6966#endif
6967
Bram Moolenaar071d4272004-06-13 20:20:40 +00006968 /* Options that are a list of flags. */
6969 else
6970 {
6971 p = NULL;
6972 if (varp == &p_ww)
6973 p = (char_u *)WW_ALL;
6974 if (varp == &p_shm)
6975 p = (char_u *)SHM_ALL;
6976 else if (varp == &(p_cpo))
6977 p = (char_u *)CPO_ALL;
6978 else if (varp == &(curbuf->b_p_fo))
6979 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02006980#ifdef FEAT_CONCEAL
6981 else if (varp == &curwin->w_p_cocu)
6982 p = (char_u *)COCU_ALL;
6983#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006984 else if (varp == &p_mouse)
6985 {
6986#ifdef FEAT_MOUSE
6987 p = (char_u *)MOUSE_ALL;
6988#else
6989 if (*p_mouse != NUL)
6990 errmsg = (char_u *)N_("E538: No mouse support");
6991#endif
6992 }
6993#if defined(FEAT_GUI)
6994 else if (varp == &p_go)
6995 p = (char_u *)GO_ALL;
6996#endif
6997 if (p != NULL)
6998 {
6999 for (s = *varp; *s; ++s)
7000 if (vim_strchr(p, *s) == NULL)
7001 {
7002 errmsg = illegal_char(errbuf, *s);
7003 break;
7004 }
7005 }
7006 }
7007
7008 /*
7009 * If error detected, restore the previous value.
7010 */
7011 if (errmsg != NULL)
7012 {
7013 if (new_value_alloced)
7014 free_string_option(*varp);
7015 *varp = oldval;
7016 /*
7017 * When resetting some values, need to act on it.
7018 */
7019 if (did_chartab)
7020 (void)init_chartab();
7021 if (varp == &p_hl)
7022 (void)highlight_changed();
7023 }
7024 else
7025 {
7026#ifdef FEAT_EVAL
7027 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007028 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029#endif
7030 /*
7031 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007032 * Use "free_oldval", because recursiveness may change the flags under
7033 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007035 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036 free_string_option(oldval);
7037 if (new_value_alloced)
7038 options[opt_idx].flags |= P_ALLOCED;
7039 else
7040 options[opt_idx].flags &= ~P_ALLOCED;
7041
7042 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007043 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044 {
7045 /* global option with local value set to use global value; free
7046 * the local value and make it empty */
7047 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7048 free_string_option(*(char_u **)p);
7049 *(char_u **)p = empty_option;
7050 }
7051
7052 /* May set global value for local option. */
7053 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7054 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007055
7056#ifdef FEAT_AUTOCMD
7057 /*
7058 * Trigger the autocommand only after setting the flags.
7059 */
7060# ifdef FEAT_SYN_HL
7061 /* When 'syntax' is set, load the syntax of that name */
7062 if (varp == &(curbuf->b_p_syn))
7063 {
7064 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7065 curbuf->b_fname, TRUE, curbuf);
7066 }
7067# endif
7068 else if (varp == &(curbuf->b_p_ft))
7069 {
7070 /* 'filetype' is set, trigger the FileType autocommand */
7071 did_filetype = TRUE;
7072 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7073 curbuf->b_fname, TRUE, curbuf);
7074 }
7075#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007076#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007077 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007078 {
7079 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007080 char_u *q = curwin->w_s->b_p_spl;
7081
7082 /* Skip the first name if it is "cjk". */
7083 if (STRNCMP(q, "cjk,", 4) == 0)
7084 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007085
7086 /*
7087 * Source the spell/LANG.vim in 'runtimepath'.
7088 * They could set 'spellcapcheck' depending on the language.
7089 * Use the first name in 'spelllang' up to '_region' or
7090 * '.encoding'.
7091 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007092 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007093 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7094 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007095 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007096 source_runtime(fname, TRUE);
7097 }
7098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099 }
7100
7101#ifdef FEAT_MOUSE
7102 if (varp == &p_mouse)
7103 {
7104# ifdef FEAT_MOUSE_TTY
7105 if (*p_mouse == NUL)
7106 mch_setmouse(FALSE); /* switch mouse off */
7107 else
7108# endif
7109 setmouse(); /* in case 'mouse' changed */
7110 }
7111#endif
7112
Bram Moolenaar913077c2012-03-28 19:59:04 +02007113 if (curwin->w_curswant != MAXCOL
7114 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7115 curwin->w_set_curswant = TRUE;
7116
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007117#ifdef FEAT_GUI
7118 /* check redraw when it's not a GUI option or the GUI is active. */
7119 if (!redraw_gui_only || gui.in_use)
7120#endif
7121 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122
7123 return errmsg;
7124}
7125
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007126#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007127/*
7128 * Simple int comparison function for use with qsort()
7129 */
7130 static int
7131int_cmp(a, b)
7132 const void *a;
7133 const void *b;
7134{
7135 return *(const int *)a - *(const int *)b;
7136}
7137
7138/*
7139 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7140 * Returns error message, NULL if it's OK.
7141 */
7142 char_u *
7143check_colorcolumn(wp)
7144 win_T *wp;
7145{
7146 char_u *s;
7147 int col;
7148 int count = 0;
7149 int color_cols[256];
7150 int i;
7151 int j = 0;
7152
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007153 if (wp->w_buffer == NULL)
7154 return NULL; /* buffer was closed */
7155
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007156 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007157 {
7158 if (*s == '-' || *s == '+')
7159 {
7160 /* -N and +N: add to 'textwidth' */
7161 col = (*s == '-') ? -1 : 1;
7162 ++s;
7163 if (!VIM_ISDIGIT(*s))
7164 return e_invarg;
7165 col = col * getdigits(&s);
7166 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007167 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007168 col += wp->w_buffer->b_p_tw;
7169 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007170 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007171 }
7172 else if (VIM_ISDIGIT(*s))
7173 col = getdigits(&s);
7174 else
7175 return e_invarg;
7176 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007177skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007178 if (*s == NUL)
7179 break;
7180 if (*s != ',')
7181 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007182 if (*++s == NUL)
7183 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007184 }
7185
7186 vim_free(wp->w_p_cc_cols);
7187 if (count == 0)
7188 wp->w_p_cc_cols = NULL;
7189 else
7190 {
7191 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7192 if (wp->w_p_cc_cols != NULL)
7193 {
7194 /* sort the columns for faster usage on screen redraw inside
7195 * win_line() */
7196 qsort(color_cols, count, sizeof(int), int_cmp);
7197
7198 for (i = 0; i < count; ++i)
7199 /* skip duplicates */
7200 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7201 wp->w_p_cc_cols[j++] = color_cols[i];
7202 wp->w_p_cc_cols[j] = -1; /* end marker */
7203 }
7204 }
7205
7206 return NULL; /* no error */
7207}
7208#endif
7209
Bram Moolenaar071d4272004-06-13 20:20:40 +00007210/*
7211 * Handle setting 'listchars' or 'fillchars'.
7212 * Returns error message, NULL if it's OK.
7213 */
7214 static char_u *
7215set_chars_option(varp)
7216 char_u **varp;
7217{
7218 int round, i, len, entries;
7219 char_u *p, *s;
7220 int c1, c2 = 0;
7221 struct charstab
7222 {
7223 int *cp;
7224 char *name;
7225 };
7226#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7227 static struct charstab filltab[] =
7228 {
7229 {&fill_stl, "stl"},
7230 {&fill_stlnc, "stlnc"},
7231 {&fill_vert, "vert"},
7232 {&fill_fold, "fold"},
7233 {&fill_diff, "diff"},
7234 };
7235#endif
7236 static struct charstab lcstab[] =
7237 {
7238 {&lcs_eol, "eol"},
7239 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007240 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007241 {&lcs_prec, "precedes"},
7242 {&lcs_tab2, "tab"},
7243 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007244#ifdef FEAT_CONCEAL
7245 {&lcs_conceal, "conceal"},
7246#else
7247 {NULL, "conceal"},
7248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007249 };
7250 struct charstab *tab;
7251
7252#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7253 if (varp == &p_lcs)
7254#endif
7255 {
7256 tab = lcstab;
7257 entries = sizeof(lcstab) / sizeof(struct charstab);
7258 }
7259#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7260 else
7261 {
7262 tab = filltab;
7263 entries = sizeof(filltab) / sizeof(struct charstab);
7264 }
7265#endif
7266
7267 /* first round: check for valid value, second round: assign values */
7268 for (round = 0; round <= 1; ++round)
7269 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007270 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007271 {
7272 /* After checking that the value is valid: set defaults: space for
7273 * 'fillchars', NUL for 'listchars' */
7274 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007275 if (tab[i].cp != NULL)
7276 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007277 if (varp == &p_lcs)
7278 lcs_tab1 = NUL;
7279#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7280 else
7281 fill_diff = '-';
7282#endif
7283 }
7284 p = *varp;
7285 while (*p)
7286 {
7287 for (i = 0; i < entries; ++i)
7288 {
7289 len = (int)STRLEN(tab[i].name);
7290 if (STRNCMP(p, tab[i].name, len) == 0
7291 && p[len] == ':'
7292 && p[len + 1] != NUL)
7293 {
7294 s = p + len + 1;
7295#ifdef FEAT_MBYTE
7296 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007297 if (mb_char2cells(c1) > 1)
7298 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007299#else
7300 c1 = *s++;
7301#endif
7302 if (tab[i].cp == &lcs_tab2)
7303 {
7304 if (*s == NUL)
7305 continue;
7306#ifdef FEAT_MBYTE
7307 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007308 if (mb_char2cells(c2) > 1)
7309 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310#else
7311 c2 = *s++;
7312#endif
7313 }
7314 if (*s == ',' || *s == NUL)
7315 {
7316 if (round)
7317 {
7318 if (tab[i].cp == &lcs_tab2)
7319 {
7320 lcs_tab1 = c1;
7321 lcs_tab2 = c2;
7322 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007323 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324 *(tab[i].cp) = c1;
7325
7326 }
7327 p = s;
7328 break;
7329 }
7330 }
7331 }
7332
7333 if (i == entries)
7334 return e_invarg;
7335 if (*p == ',')
7336 ++p;
7337 }
7338 }
7339
7340 return NULL; /* no error */
7341}
7342
7343#ifdef FEAT_STL_OPT
7344/*
7345 * Check validity of options with the 'statusline' format.
7346 * Return error message or NULL.
7347 */
7348 char_u *
7349check_stl_option(s)
7350 char_u *s;
7351{
7352 int itemcnt = 0;
7353 int groupdepth = 0;
7354 static char_u errbuf[80];
7355
7356 while (*s && itemcnt < STL_MAX_ITEM)
7357 {
7358 /* Check for valid keys after % sequences */
7359 while (*s && *s != '%')
7360 s++;
7361 if (!*s)
7362 break;
7363 s++;
7364 if (*s != '%' && *s != ')')
7365 ++itemcnt;
7366 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7367 {
7368 s++;
7369 continue;
7370 }
7371 if (*s == ')')
7372 {
7373 s++;
7374 if (--groupdepth < 0)
7375 break;
7376 continue;
7377 }
7378 if (*s == '-')
7379 s++;
7380 while (VIM_ISDIGIT(*s))
7381 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007382 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007383 continue;
7384 if (*s == '.')
7385 {
7386 s++;
7387 while (*s && VIM_ISDIGIT(*s))
7388 s++;
7389 }
7390 if (*s == '(')
7391 {
7392 groupdepth++;
7393 continue;
7394 }
7395 if (vim_strchr(STL_ALL, *s) == NULL)
7396 {
7397 return illegal_char(errbuf, *s);
7398 }
7399 if (*s == '{')
7400 {
7401 s++;
7402 while (*s != '}' && *s)
7403 s++;
7404 if (*s != '}')
7405 return (char_u *)N_("E540: Unclosed expression sequence");
7406 }
7407 }
7408 if (itemcnt >= STL_MAX_ITEM)
7409 return (char_u *)N_("E541: too many items");
7410 if (groupdepth != 0)
7411 return (char_u *)N_("E542: unbalanced groups");
7412 return NULL;
7413}
7414#endif
7415
7416#ifdef FEAT_CLIPBOARD
7417/*
7418 * Extract the items in the 'clipboard' option and set global values.
7419 */
7420 static char_u *
7421check_clipboard_option()
7422{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007423 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007424 int new_autoselect_star = FALSE;
7425 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007426 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007427 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428 regprog_T *new_exclude_prog = NULL;
7429 char_u *errmsg = NULL;
7430 char_u *p;
7431
7432 for (p = p_cb; *p != NUL; )
7433 {
7434 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7435 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007436 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007437 p += 7;
7438 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007439 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007440 && (p[11] == ',' || p[11] == NUL))
7441 {
7442 new_unnamed |= CLIP_UNNAMED_PLUS;
7443 p += 11;
7444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007446 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007447 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007448 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449 p += 10;
7450 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007451 else if (STRNCMP(p, "autoselectplus", 14) == 0
7452 && (p[14] == ',' || p[14] == NUL))
7453 {
7454 new_autoselect_plus = TRUE;
7455 p += 14;
7456 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007458 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459 {
7460 new_autoselectml = TRUE;
7461 p += 12;
7462 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007463 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7464 {
7465 new_html = TRUE;
7466 p += 4;
7467 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007468 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7469 {
7470 p += 8;
7471 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7472 if (new_exclude_prog == NULL)
7473 errmsg = e_invarg;
7474 break;
7475 }
7476 else
7477 {
7478 errmsg = e_invarg;
7479 break;
7480 }
7481 if (*p == ',')
7482 ++p;
7483 }
7484 if (errmsg == NULL)
7485 {
7486 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007487 clip_autoselect_star = new_autoselect_star;
7488 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007490 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007491 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007493#ifdef FEAT_GUI_GTK
7494 if (gui.in_use)
7495 {
7496 gui_gtk_set_selection_targets();
7497 gui_gtk_set_dnd_targets();
7498 }
7499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007500 }
7501 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007502 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007503
7504 return errmsg;
7505}
7506#endif
7507
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007508#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007509/*
7510 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7511 * Return error message when failed, NULL when OK.
7512 */
7513 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007514compile_cap_prog(synblock)
7515 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007516{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007517 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007518 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007519
Bram Moolenaar860cae12010-06-05 23:22:07 +02007520 if (*synblock->b_p_spc == NUL)
7521 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007522 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007523 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007524 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007525 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007526 if (re != NULL)
7527 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007528 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007529 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007530 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007531 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007532 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007533 return e_invarg;
7534 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007535 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007536 }
7537
Bram Moolenaar473de612013-06-08 18:19:48 +02007538 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007539 return NULL;
7540}
7541#endif
7542
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007543#if defined(FEAT_EVAL) || defined(PROTO)
7544/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007545 * Set the scriptID for an option, taking care of setting the buffer- or
7546 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007547 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007548 static void
7549set_option_scriptID_idx(opt_idx, opt_flags, id)
7550 int opt_idx;
7551 int opt_flags;
7552 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007553{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007554 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7555 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007556
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007557 /* Remember where the option was set. For local options need to do that
7558 * in the buffer or window structure. */
7559 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007560 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007561 if (both || (opt_flags & OPT_LOCAL))
7562 {
7563 if (indir & PV_BUF)
7564 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7565 else if (indir & PV_WIN)
7566 curwin->w_p_scriptID[indir & PV_MASK] = id;
7567 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007568}
7569#endif
7570
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571/*
7572 * Set the value of a boolean option, and take care of side effects.
7573 * Returns NULL for success, or an error message for an error.
7574 */
7575 static char_u *
7576set_bool_option(opt_idx, varp, value, opt_flags)
7577 int opt_idx; /* index in options[] table */
7578 char_u *varp; /* pointer to the option variable */
7579 int value; /* new value */
7580 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7581{
7582 int old_value = *(int *)varp;
7583
Bram Moolenaar071d4272004-06-13 20:20:40 +00007584 /* Disallow changing some options from secure mode */
7585 if ((secure
7586#ifdef HAVE_SANDBOX
7587 || sandbox != 0
7588#endif
7589 ) && (options[opt_idx].flags & P_SECURE))
7590 return e_secure;
7591
7592 *(int *)varp = value; /* set the new value */
7593#ifdef FEAT_EVAL
7594 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007595 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007596#endif
7597
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007598#ifdef FEAT_GUI
7599 need_mouse_correct = TRUE;
7600#endif
7601
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602 /* May set global value for local option. */
7603 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7604 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7605
7606 /*
7607 * Handle side effects of changing a bool option.
7608 */
7609
7610 /* 'compatible' */
7611 if ((int *)varp == &p_cp)
7612 {
7613 compatible_set();
7614 }
7615
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007616#ifdef FEAT_PERSISTENT_UNDO
7617 /* 'undofile' */
7618 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7619 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007620 /* Only take action when the option was set. When reset we do not
7621 * delete the undo file, the option may be set again without making
7622 * any changes in between. */
7623 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007624 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007625 char_u hash[UNDO_HASH_SIZE];
7626 buf_T *save_curbuf = curbuf;
7627
7628 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007629 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007630 /* When 'undofile' is set globally: for every buffer, otherwise
7631 * only for the current buffer: Try to read in the undofile,
7632 * if one exists, the buffer wasn't changed and the buffer was
7633 * loaded */
7634 if ((curbuf == save_curbuf
7635 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7636 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7637 {
7638 u_compute_hash(hash);
7639 u_read_undo(NULL, hash, curbuf->b_fname);
7640 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007641 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007642 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007643 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007644 }
7645#endif
7646
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647 else if ((int *)varp == &curbuf->b_p_ro)
7648 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007649 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7651 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007652
7653 /* when 'readonly' is set may give W10 again */
7654 if (curbuf->b_p_ro)
7655 curbuf->b_did_warn = FALSE;
7656
Bram Moolenaar071d4272004-06-13 20:20:40 +00007657#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007658 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659#endif
7660 }
7661
Bram Moolenaar9c449722010-07-20 18:44:27 +02007662#ifdef FEAT_GUI
7663 else if ((int *)varp == &p_mh)
7664 {
7665 if (!p_mh)
7666 gui_mch_mousehide(FALSE);
7667 }
7668#endif
7669
Bram Moolenaara539df02010-08-01 14:35:05 +02007670#ifdef FEAT_TITLE
7671 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007672 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007673 {
7674 redraw_titles();
7675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676 /* when 'endofline' is changed, redraw the window title */
7677 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007678 {
7679 redraw_titles();
7680 }
7681# ifdef FEAT_MBYTE
7682 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007683 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007684 {
7685 redraw_titles();
7686 }
7687# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007688#endif
7689
7690 /* when 'bin' is set also set some other options */
7691 else if ((int *)varp == &curbuf->b_p_bin)
7692 {
7693 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7694#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007695 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696#endif
7697 }
7698
7699#ifdef FEAT_AUTOCMD
7700 /* when 'buflisted' changes, trigger autocommands */
7701 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7702 {
7703 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7704 NULL, NULL, TRUE, curbuf);
7705 }
7706#endif
7707
7708 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7709 else if ((int *)varp == &curbuf->b_p_swf)
7710 {
7711 if (curbuf->b_p_swf && p_uc)
7712 ml_open_file(curbuf); /* create the swap file */
7713 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007714 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7715 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007716 mf_close_file(curbuf, TRUE); /* remove the swap file */
7717 }
7718
7719 /* when 'terse' is set change 'shortmess' */
7720 else if ((int *)varp == &p_terse)
7721 {
7722 char_u *p;
7723
7724 p = vim_strchr(p_shm, SHM_SEARCH);
7725
7726 /* insert 's' in p_shm */
7727 if (p_terse && p == NULL)
7728 {
7729 STRCPY(IObuff, p_shm);
7730 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007731 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732 }
7733 /* remove 's' from p_shm */
7734 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007735 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 }
7737
7738 /* when 'paste' is set or reset also change other options */
7739 else if ((int *)varp == &p_paste)
7740 {
7741 paste_option_changed();
7742 }
7743
7744 /* when 'insertmode' is set from an autocommand need to do work here */
7745 else if ((int *)varp == &p_im)
7746 {
7747 if (p_im)
7748 {
7749 if ((State & INSERT) == 0)
7750 need_start_insertmode = TRUE;
7751 stop_insert_mode = FALSE;
7752 }
7753 else
7754 {
7755 need_start_insertmode = FALSE;
7756 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007757 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 clear_cmdline = TRUE; /* remove "(insert)" */
7759 restart_edit = 0;
7760 }
7761 }
7762
7763 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7764 else if ((int *)varp == &p_ic && p_hls)
7765 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007766 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767 }
7768
7769#ifdef FEAT_SEARCH_EXTRA
7770 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7771 else if ((int *)varp == &p_hls)
7772 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007773 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 }
7775#endif
7776
7777#ifdef FEAT_SCROLLBIND
7778 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7779 * at the end of normal_cmd() */
7780 else if ((int *)varp == &curwin->w_p_scb)
7781 {
7782 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007783 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007785 curwin->w_scbind_pos = curwin->w_topline;
7786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787 }
7788#endif
7789
7790#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7791 /* There can be only one window with 'previewwindow' set. */
7792 else if ((int *)varp == &curwin->w_p_pvw)
7793 {
7794 if (curwin->w_p_pvw)
7795 {
7796 win_T *win;
7797
7798 for (win = firstwin; win != NULL; win = win->w_next)
7799 if (win->w_p_pvw && win != curwin)
7800 {
7801 curwin->w_p_pvw = FALSE;
7802 return (char_u *)N_("E590: A preview window already exists");
7803 }
7804 }
7805 }
7806#endif
7807
7808 /* when 'textmode' is set or reset also change 'fileformat' */
7809 else if ((int *)varp == &curbuf->b_p_tx)
7810 {
7811 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7812 }
7813
7814 /* when 'textauto' is set or reset also change 'fileformats' */
7815 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816 set_string_option_direct((char_u *)"ffs", -1,
7817 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007818 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819
7820 /*
7821 * When 'lisp' option changes include/exclude '-' in
7822 * keyword characters.
7823 */
7824#ifdef FEAT_LISP
7825 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7826 {
7827 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7828 }
7829#endif
7830
7831#ifdef FEAT_TITLE
7832 /* when 'title' changed, may need to change the title; same for 'icon' */
7833 else if ((int *)varp == &p_title)
7834 {
7835 did_set_title(FALSE);
7836 }
7837
7838 else if ((int *)varp == &p_icon)
7839 {
7840 did_set_title(TRUE);
7841 }
7842#endif
7843
7844 else if ((int *)varp == &curbuf->b_changed)
7845 {
7846 if (!value)
7847 save_file_ff(curbuf); /* Buffer is unchanged */
7848#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007849 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850#endif
7851#ifdef FEAT_AUTOCMD
7852 modified_was_set = value;
7853#endif
7854 }
7855
7856#ifdef BACKSLASH_IN_FILENAME
7857 else if ((int *)varp == &p_ssl)
7858 {
7859 if (p_ssl)
7860 {
7861 psepc = '/';
7862 psepcN = '\\';
7863 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 }
7865 else
7866 {
7867 psepc = '\\';
7868 psepcN = '/';
7869 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870 }
7871
7872 /* need to adjust the file name arguments and buffer names. */
7873 buflist_slash_adjust();
7874 alist_slash_adjust();
7875# ifdef FEAT_EVAL
7876 scriptnames_slash_adjust();
7877# endif
7878 }
7879#endif
7880
7881 /* If 'wrap' is set, set w_leftcol to zero. */
7882 else if ((int *)varp == &curwin->w_p_wrap)
7883 {
7884 if (curwin->w_p_wrap)
7885 curwin->w_leftcol = 0;
7886 }
7887
7888#ifdef FEAT_WINDOWS
7889 else if ((int *)varp == &p_ea)
7890 {
7891 if (p_ea && !old_value)
7892 win_equal(curwin, FALSE, 0);
7893 }
7894#endif
7895
7896 else if ((int *)varp == &p_wiv)
7897 {
7898 /*
7899 * When 'weirdinvert' changed, set/reset 't_xs'.
7900 * Then set 'weirdinvert' according to value of 't_xs'.
7901 */
7902 if (p_wiv && !old_value)
7903 T_XS = (char_u *)"y";
7904 else if (!p_wiv && old_value)
7905 T_XS = empty_option;
7906 p_wiv = (*T_XS != NUL);
7907 }
7908
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007909#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007910 else if ((int *)varp == &p_beval)
7911 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007912 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007914 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 gui_mch_disable_beval_area(balloonEval);
7916 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007917#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007919#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007920 else if ((int *)varp == &p_acd)
7921 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007922 /* Change directories when the 'acd' option is set now. */
7923 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924 }
7925#endif
7926
7927#ifdef FEAT_DIFF
7928 /* 'diff' */
7929 else if ((int *)varp == &curwin->w_p_diff)
7930 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007931 /* May add or remove the buffer from the list of diff buffers. */
7932 diff_buf_adjust(curwin);
7933# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934 if (foldmethodIsDiff(curwin))
7935 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937 }
7938#endif
7939
7940#ifdef USE_IM_CONTROL
7941 /* 'imdisable' */
7942 else if ((int *)varp == &p_imdisable)
7943 {
7944 /* Only de-activate it here, it will be enabled when changing mode. */
7945 if (p_imdisable)
7946 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007947 else if (State & INSERT)
7948 /* When the option is set from an autocommand, it may need to take
7949 * effect right away. */
7950 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951 }
7952#endif
7953
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007954#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007955 /* 'spell' */
7956 else if ((int *)varp == &curwin->w_p_spell)
7957 {
7958 if (curwin->w_p_spell)
7959 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007960 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007961 if (errmsg != NULL)
7962 EMSG(_(errmsg));
7963 }
7964 }
7965#endif
7966
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967#ifdef FEAT_FKMAP
7968 else if ((int *)varp == &p_altkeymap)
7969 {
7970 if (old_value != p_altkeymap)
7971 {
7972 if (!p_altkeymap)
7973 {
7974 p_hkmap = p_fkmap;
7975 p_fkmap = 0;
7976 }
7977 else
7978 {
7979 p_fkmap = p_hkmap;
7980 p_hkmap = 0;
7981 }
7982 (void)init_chartab();
7983 }
7984 }
7985
7986 /*
7987 * In case some second language keymapping options have changed, check
7988 * and correct the setting in a consistent way.
7989 */
7990
7991 /*
7992 * If hkmap or fkmap are set, reset Arabic keymapping.
7993 */
7994 if ((p_hkmap || p_fkmap) && p_altkeymap)
7995 {
7996 p_altkeymap = p_fkmap;
7997# ifdef FEAT_ARABIC
7998 curwin->w_p_arab = FALSE;
7999# endif
8000 (void)init_chartab();
8001 }
8002
8003 /*
8004 * If hkmap set, reset Farsi keymapping.
8005 */
8006 if (p_hkmap && p_altkeymap)
8007 {
8008 p_altkeymap = 0;
8009 p_fkmap = 0;
8010# ifdef FEAT_ARABIC
8011 curwin->w_p_arab = FALSE;
8012# endif
8013 (void)init_chartab();
8014 }
8015
8016 /*
8017 * If fkmap set, reset Hebrew keymapping.
8018 */
8019 if (p_fkmap && !p_altkeymap)
8020 {
8021 p_altkeymap = 1;
8022 p_hkmap = 0;
8023# ifdef FEAT_ARABIC
8024 curwin->w_p_arab = FALSE;
8025# endif
8026 (void)init_chartab();
8027 }
8028#endif
8029
8030#ifdef FEAT_ARABIC
8031 if ((int *)varp == &curwin->w_p_arab)
8032 {
8033 if (curwin->w_p_arab)
8034 {
8035 /*
8036 * 'arabic' is set, handle various sub-settings.
8037 */
8038 if (!p_tbidi)
8039 {
8040 /* set rightleft mode */
8041 if (!curwin->w_p_rl)
8042 {
8043 curwin->w_p_rl = TRUE;
8044 changed_window_setting();
8045 }
8046
8047 /* Enable Arabic shaping (major part of what Arabic requires) */
8048 if (!p_arshape)
8049 {
8050 p_arshape = TRUE;
8051 redraw_later_clear();
8052 }
8053 }
8054
8055 /* Arabic requires a utf-8 encoding, inform the user if its not
8056 * set. */
8057 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008058 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008059 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8060
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008061 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008062 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8063#ifdef FEAT_EVAL
8064 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8065#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008066 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008067
8068# ifdef FEAT_MBYTE
8069 /* set 'delcombine' */
8070 p_deco = TRUE;
8071# endif
8072
8073# ifdef FEAT_KEYMAP
8074 /* Force-set the necessary keymap for arabic */
8075 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8076 OPT_LOCAL);
8077# endif
8078# ifdef FEAT_FKMAP
8079 p_altkeymap = 0;
8080 p_hkmap = 0;
8081 p_fkmap = 0;
8082 (void)init_chartab();
8083# endif
8084 }
8085 else
8086 {
8087 /*
8088 * 'arabic' is reset, handle various sub-settings.
8089 */
8090 if (!p_tbidi)
8091 {
8092 /* reset rightleft mode */
8093 if (curwin->w_p_rl)
8094 {
8095 curwin->w_p_rl = FALSE;
8096 changed_window_setting();
8097 }
8098
8099 /* 'arabicshape' isn't reset, it is a global option and
8100 * another window may still need it "on". */
8101 }
8102
8103 /* 'delcombine' isn't reset, it is a global option and another
8104 * window may still want it "on". */
8105
8106# ifdef FEAT_KEYMAP
8107 /* Revert to the default keymap */
8108 curbuf->b_p_iminsert = B_IMODE_NONE;
8109 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8110# endif
8111 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008112 }
8113
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008114#endif
8115
Bram Moolenaar071d4272004-06-13 20:20:40 +00008116 /*
8117 * End of handling side effects for bool options.
8118 */
8119
8120 options[opt_idx].flags |= P_WAS_SET;
8121
8122 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008123 if (curwin->w_curswant != MAXCOL
8124 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8125 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 check_redraw(options[opt_idx].flags);
8127
8128 return NULL;
8129}
8130
8131/*
8132 * Set the value of a number option, and take care of side effects.
8133 * Returns NULL for success, or an error message for an error.
8134 */
8135 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008136set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 int opt_idx; /* index in options[] table */
8138 char_u *varp; /* pointer to the option variable */
8139 long value; /* new value */
8140 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008141 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8143 OPT_MODELINE */
8144{
8145 char_u *errmsg = NULL;
8146 long old_value = *(long *)varp;
8147 long old_Rows = Rows; /* remember old Rows */
8148 long old_Columns = Columns; /* remember old Columns */
8149 long *pp = (long *)varp;
8150
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008151 /* Disallow changing some options from secure mode. */
8152 if ((secure
8153#ifdef HAVE_SANDBOX
8154 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008156 ) && (options[opt_idx].flags & P_SECURE))
8157 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158
8159 *pp = value;
8160#ifdef FEAT_EVAL
8161 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008162 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008164#ifdef FEAT_GUI
8165 need_mouse_correct = TRUE;
8166#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167
Bram Moolenaar14f24742012-08-08 18:01:05 +02008168 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 {
8170 errmsg = e_positive;
8171 curbuf->b_p_sw = curbuf->b_p_ts;
8172 }
8173
8174 /*
8175 * Number options that need some action when changed
8176 */
8177#ifdef FEAT_WINDOWS
8178 if (pp == &p_wh || pp == &p_hh)
8179 {
8180 if (p_wh < 1)
8181 {
8182 errmsg = e_positive;
8183 p_wh = 1;
8184 }
8185 if (p_wmh > p_wh)
8186 {
8187 errmsg = e_winheight;
8188 p_wh = p_wmh;
8189 }
8190 if (p_hh < 0)
8191 {
8192 errmsg = e_positive;
8193 p_hh = 0;
8194 }
8195
8196 /* Change window height NOW */
8197 if (lastwin != firstwin)
8198 {
8199 if (pp == &p_wh && curwin->w_height < p_wh)
8200 win_setheight((int)p_wh);
8201 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8202 win_setheight((int)p_hh);
8203 }
8204 }
8205
8206 /* 'winminheight' */
8207 else if (pp == &p_wmh)
8208 {
8209 if (p_wmh < 0)
8210 {
8211 errmsg = e_positive;
8212 p_wmh = 0;
8213 }
8214 if (p_wmh > p_wh)
8215 {
8216 errmsg = e_winheight;
8217 p_wmh = p_wh;
8218 }
8219 win_setminheight();
8220 }
8221
8222# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008223 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008224 {
8225 if (p_wiw < 1)
8226 {
8227 errmsg = e_positive;
8228 p_wiw = 1;
8229 }
8230 if (p_wmw > p_wiw)
8231 {
8232 errmsg = e_winwidth;
8233 p_wiw = p_wmw;
8234 }
8235
8236 /* Change window width NOW */
8237 if (lastwin != firstwin && curwin->w_width < p_wiw)
8238 win_setwidth((int)p_wiw);
8239 }
8240
8241 /* 'winminwidth' */
8242 else if (pp == &p_wmw)
8243 {
8244 if (p_wmw < 0)
8245 {
8246 errmsg = e_positive;
8247 p_wmw = 0;
8248 }
8249 if (p_wmw > p_wiw)
8250 {
8251 errmsg = e_winwidth;
8252 p_wmw = p_wiw;
8253 }
8254 win_setminheight();
8255 }
8256# endif
8257
8258#endif
8259
8260#ifdef FEAT_WINDOWS
8261 /* (re)set last window status line */
8262 else if (pp == &p_ls)
8263 {
8264 last_status(FALSE);
8265 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008266
8267 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008268 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008269 {
8270 shell_new_rows(); /* recompute window positions and heights */
8271 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272#endif
8273
8274#ifdef FEAT_GUI
8275 else if (pp == &p_linespace)
8276 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008277 /* Recompute gui.char_height and resize the Vim window to keep the
8278 * same number of lines. */
8279 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008280 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008281 }
8282#endif
8283
8284#ifdef FEAT_FOLDING
8285 /* 'foldlevel' */
8286 else if (pp == &curwin->w_p_fdl)
8287 {
8288 if (curwin->w_p_fdl < 0)
8289 curwin->w_p_fdl = 0;
8290 newFoldLevel();
8291 }
8292
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008293 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008294 else if (pp == &curwin->w_p_fml)
8295 {
8296 foldUpdateAll(curwin);
8297 }
8298
8299 /* 'foldnestmax' */
8300 else if (pp == &curwin->w_p_fdn)
8301 {
8302 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8303 foldUpdateAll(curwin);
8304 }
8305
8306 /* 'foldcolumn' */
8307 else if (pp == &curwin->w_p_fdc)
8308 {
8309 if (curwin->w_p_fdc < 0)
8310 {
8311 errmsg = e_positive;
8312 curwin->w_p_fdc = 0;
8313 }
8314 else if (curwin->w_p_fdc > 12)
8315 {
8316 errmsg = e_invarg;
8317 curwin->w_p_fdc = 12;
8318 }
8319 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008320#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008321
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008322#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008323 /* 'shiftwidth' or 'tabstop' */
8324 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8325 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008326# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327 if (foldmethodIsIndent(curwin))
8328 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008329# endif
8330# ifdef FEAT_CINDENT
8331 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8332 * parse 'cinoptions'. */
8333 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8334 parse_cino(curbuf);
8335# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008336 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008337#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008338
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008339#ifdef FEAT_MBYTE
8340 /* 'maxcombine' */
8341 else if (pp == &p_mco)
8342 {
8343 if (p_mco > MAX_MCO)
8344 p_mco = MAX_MCO;
8345 else if (p_mco < 0)
8346 p_mco = 0;
8347 screenclear(); /* will re-allocate the screen */
8348 }
8349#endif
8350
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351 else if (pp == &curbuf->b_p_iminsert)
8352 {
8353 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8354 {
8355 errmsg = e_invarg;
8356 curbuf->b_p_iminsert = B_IMODE_NONE;
8357 }
8358 p_iminsert = curbuf->b_p_iminsert;
8359 if (termcap_active) /* don't do this in the alternate screen */
8360 showmode();
8361#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8362 /* Show/unshow value of 'keymap' in status lines. */
8363 status_redraw_curbuf();
8364#endif
8365 }
8366
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008367 else if (pp == &p_window)
8368 {
8369 if (p_window < 1)
8370 p_window = 1;
8371 else if (p_window >= Rows)
8372 p_window = Rows - 1;
8373 }
8374
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375 else if (pp == &curbuf->b_p_imsearch)
8376 {
8377 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8378 {
8379 errmsg = e_invarg;
8380 curbuf->b_p_imsearch = B_IMODE_NONE;
8381 }
8382 p_imsearch = curbuf->b_p_imsearch;
8383 }
8384
8385#ifdef FEAT_TITLE
8386 /* if 'titlelen' has changed, redraw the title */
8387 else if (pp == &p_titlelen)
8388 {
8389 if (p_titlelen < 0)
8390 {
8391 errmsg = e_positive;
8392 p_titlelen = 85;
8393 }
8394 if (starting != NO_SCREEN && old_value != p_titlelen)
8395 need_maketitle = TRUE;
8396 }
8397#endif
8398
8399 /* if p_ch changed value, change the command line height */
8400 else if (pp == &p_ch)
8401 {
8402 if (p_ch < 1)
8403 {
8404 errmsg = e_positive;
8405 p_ch = 1;
8406 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008407 if (p_ch > Rows - min_rows() + 1)
8408 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409
8410 /* Only compute the new window layout when startup has been
8411 * completed. Otherwise the frame sizes may be wrong. */
8412 if (p_ch != old_value && full_screen
8413#ifdef FEAT_GUI
8414 && !gui.starting
8415#endif
8416 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008417 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418 }
8419
8420 /* when 'updatecount' changes from zero to non-zero, open swap files */
8421 else if (pp == &p_uc)
8422 {
8423 if (p_uc < 0)
8424 {
8425 errmsg = e_positive;
8426 p_uc = 100;
8427 }
8428 if (p_uc && !old_value)
8429 ml_open_files();
8430 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008431#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008432 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008433 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008434 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008435 {
8436 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008437 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008438 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008439 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008440 {
8441 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008442 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008443 }
8444 }
8445#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008446#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008447 else if (pp == &p_mzq)
8448 mzvim_reset_timer();
8449#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450
8451 /* sync undo before 'undolevels' changes */
8452 else if (pp == &p_ul)
8453 {
8454 /* use the old value, otherwise u_sync() may not work properly */
8455 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008456 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 p_ul = value;
8458 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008459 else if (pp == &curbuf->b_p_ul)
8460 {
8461 /* use the old value, otherwise u_sync() may not work properly */
8462 curbuf->b_p_ul = old_value;
8463 u_sync(TRUE);
8464 curbuf->b_p_ul = value;
8465 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008467#ifdef FEAT_LINEBREAK
8468 /* 'numberwidth' must be positive */
8469 else if (pp == &curwin->w_p_nuw)
8470 {
8471 if (curwin->w_p_nuw < 1)
8472 {
8473 errmsg = e_positive;
8474 curwin->w_p_nuw = 1;
8475 }
8476 if (curwin->w_p_nuw > 10)
8477 {
8478 errmsg = e_invarg;
8479 curwin->w_p_nuw = 10;
8480 }
8481 curwin->w_nrwidth_line_count = 0;
8482 }
8483#endif
8484
Bram Moolenaar1a384422010-07-14 19:53:30 +02008485 else if (pp == &curbuf->b_p_tw)
8486 {
8487 if (curbuf->b_p_tw < 0)
8488 {
8489 errmsg = e_positive;
8490 curbuf->b_p_tw = 0;
8491 }
8492#ifdef FEAT_SYN_HL
8493# ifdef FEAT_WINDOWS
8494 {
8495 win_T *wp;
8496 tabpage_T *tp;
8497
8498 FOR_ALL_TAB_WINDOWS(tp, wp)
8499 check_colorcolumn(wp);
8500 }
8501# else
8502 check_colorcolumn(curwin);
8503# endif
8504#endif
8505 }
8506
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507 /*
8508 * Check the bounds for numeric options here
8509 */
8510 if (Rows < min_rows() && full_screen)
8511 {
8512 if (errbuf != NULL)
8513 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008514 vim_snprintf((char *)errbuf, errbuflen,
8515 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516 errmsg = errbuf;
8517 }
8518 Rows = min_rows();
8519 }
8520 if (Columns < MIN_COLUMNS && full_screen)
8521 {
8522 if (errbuf != NULL)
8523 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008524 vim_snprintf((char *)errbuf, errbuflen,
8525 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526 errmsg = errbuf;
8527 }
8528 Columns = MIN_COLUMNS;
8529 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008530 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531
8532#ifdef DJGPP
8533 /* avoid a crash by checking for a too large value of 'columns' */
8534 if (old_Columns != Columns && full_screen && term_console)
8535 mch_check_columns();
8536#endif
8537
8538 /*
8539 * If the screen (shell) height has been changed, assume it is the
8540 * physical screenheight.
8541 */
8542 if (old_Rows != Rows || old_Columns != Columns)
8543 {
8544 /* Changing the screen size is not allowed while updating the screen. */
8545 if (updating_screen)
8546 *pp = old_value;
8547 else if (full_screen
8548#ifdef FEAT_GUI
8549 && !gui.starting
8550#endif
8551 )
8552 set_shellsize((int)Columns, (int)Rows, TRUE);
8553 else
8554 {
8555 /* Postpone the resizing; check the size and cmdline position for
8556 * messages. */
8557 check_shellsize();
8558 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8559 cmdline_row = Rows - p_ch;
8560 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008561 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008562 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563 }
8564
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565 if (curbuf->b_p_ts <= 0)
8566 {
8567 errmsg = e_positive;
8568 curbuf->b_p_ts = 8;
8569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570 if (p_tm < 0)
8571 {
8572 errmsg = e_positive;
8573 p_tm = 0;
8574 }
8575 if ((curwin->w_p_scr <= 0
8576 || (curwin->w_p_scr > curwin->w_height
8577 && curwin->w_height > 0))
8578 && full_screen)
8579 {
8580 if (pp == &(curwin->w_p_scr))
8581 {
8582 if (curwin->w_p_scr != 0)
8583 errmsg = e_scroll;
8584 win_comp_scroll(curwin);
8585 }
8586 /* If 'scroll' became invalid because of a side effect silently adjust
8587 * it. */
8588 else if (curwin->w_p_scr <= 0)
8589 curwin->w_p_scr = 1;
8590 else /* curwin->w_p_scr > curwin->w_height */
8591 curwin->w_p_scr = curwin->w_height;
8592 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008593 if (p_hi < 0)
8594 {
8595 errmsg = e_positive;
8596 p_hi = 0;
8597 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008598 if (p_re < 0 || p_re > 2)
8599 {
8600 errmsg = e_invarg;
8601 p_re = 0;
8602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603 if (p_report < 0)
8604 {
8605 errmsg = e_positive;
8606 p_report = 1;
8607 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008608 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008609 {
8610 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8611 p_sj = Rows / 2;
8612 else
8613 {
8614 errmsg = e_scroll;
8615 p_sj = 1;
8616 }
8617 }
8618 if (p_so < 0 && full_screen)
8619 {
8620 errmsg = e_scroll;
8621 p_so = 0;
8622 }
8623 if (p_siso < 0 && full_screen)
8624 {
8625 errmsg = e_positive;
8626 p_siso = 0;
8627 }
8628#ifdef FEAT_CMDWIN
8629 if (p_cwh < 1)
8630 {
8631 errmsg = e_positive;
8632 p_cwh = 1;
8633 }
8634#endif
8635 if (p_ut < 0)
8636 {
8637 errmsg = e_positive;
8638 p_ut = 2000;
8639 }
8640 if (p_ss < 0)
8641 {
8642 errmsg = e_positive;
8643 p_ss = 0;
8644 }
8645
8646 /* May set global value for local option. */
8647 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8648 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8649
8650 options[opt_idx].flags |= P_WAS_SET;
8651
8652 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008653 if (curwin->w_curswant != MAXCOL
8654 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8655 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008656 check_redraw(options[opt_idx].flags);
8657
8658 return errmsg;
8659}
8660
8661/*
8662 * Called after an option changed: check if something needs to be redrawn.
8663 */
8664 static void
8665check_redraw(flags)
8666 long_u flags;
8667{
8668 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008669 int doclear = (flags & P_RCLR) == P_RCLR;
8670 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008671
8672#ifdef FEAT_WINDOWS
8673 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8674 status_redraw_all();
8675#endif
8676
8677 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8678 changed_window_setting();
8679 if (flags & P_RBUF)
8680 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008681 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 redraw_all_later(CLEAR);
8683 else if (all)
8684 redraw_all_later(NOT_VALID);
8685}
8686
8687/*
8688 * Find index for option 'arg'.
8689 * Return -1 if not found.
8690 */
8691 static int
8692findoption(arg)
8693 char_u *arg;
8694{
8695 int opt_idx;
8696 char *s, *p;
8697 static short quick_tab[27] = {0, 0}; /* quick access table */
8698 int is_term_opt;
8699
8700 /*
8701 * For first call: Initialize the quick-access table.
8702 * It contains the index for the first option that starts with a certain
8703 * letter. There are 26 letters, plus the first "t_" option.
8704 */
8705 if (quick_tab[1] == 0)
8706 {
8707 p = options[0].fullname;
8708 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8709 {
8710 if (s[0] != p[0])
8711 {
8712 if (s[0] == 't' && s[1] == '_')
8713 quick_tab[26] = opt_idx;
8714 else
8715 quick_tab[CharOrdLow(s[0])] = opt_idx;
8716 }
8717 p = s;
8718 }
8719 }
8720
8721 /*
8722 * Check for name starting with an illegal character.
8723 */
8724#ifdef EBCDIC
8725 if (!islower(arg[0]))
8726#else
8727 if (arg[0] < 'a' || arg[0] > 'z')
8728#endif
8729 return -1;
8730
8731 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8732 if (is_term_opt)
8733 opt_idx = quick_tab[26];
8734 else
8735 opt_idx = quick_tab[CharOrdLow(arg[0])];
8736 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8737 {
8738 if (STRCMP(arg, s) == 0) /* match full name */
8739 break;
8740 }
8741 if (s == NULL && !is_term_opt)
8742 {
8743 opt_idx = quick_tab[CharOrdLow(arg[0])];
8744 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8745 {
8746 s = options[opt_idx].shortname;
8747 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8748 break;
8749 s = NULL;
8750 }
8751 }
8752 if (s == NULL)
8753 opt_idx = -1;
8754 return opt_idx;
8755}
8756
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008757#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008758/*
8759 * Get the value for an option.
8760 *
8761 * Returns:
8762 * Number or Toggle option: 1, *numval gets value.
8763 * String option: 0, *stringval gets allocated string.
8764 * Hidden Number or Toggle option: -1.
8765 * hidden String option: -2.
8766 * unknown option: -3.
8767 */
8768 int
8769get_option_value(name, numval, stringval, opt_flags)
8770 char_u *name;
8771 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008772 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773 int opt_flags;
8774{
8775 int opt_idx;
8776 char_u *varp;
8777
8778 opt_idx = findoption(name);
8779 if (opt_idx < 0) /* unknown option */
8780 return -3;
8781
8782 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8783
8784 if (options[opt_idx].flags & P_STRING)
8785 {
8786 if (varp == NULL) /* hidden option */
8787 return -2;
8788 if (stringval != NULL)
8789 {
8790#ifdef FEAT_CRYPT
8791 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008792 if ((char_u **)varp == &curbuf->b_p_key
8793 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008794 *stringval = vim_strsave((char_u *)"*****");
8795 else
8796#endif
8797 *stringval = vim_strsave(*(char_u **)(varp));
8798 }
8799 return 0;
8800 }
8801
8802 if (varp == NULL) /* hidden option */
8803 return -1;
8804 if (options[opt_idx].flags & P_NUM)
8805 *numval = *(long *)varp;
8806 else
8807 {
8808 /* Special case: 'modified' is b_changed, but we also want to consider
8809 * it set when 'ff' or 'fenc' changed. */
8810 if ((int *)varp == &curbuf->b_changed)
8811 *numval = curbufIsChanged();
8812 else
8813 *numval = *(int *)varp;
8814 }
8815 return 1;
8816}
8817#endif
8818
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008819#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008820/*
8821 * Returns the option attributes and its value. Unlike the above function it
8822 * will return either global value or local value of the option depending on
8823 * what was requested, but it will never return global value if it was
8824 * requested to return local one and vice versa. Neither it will return
8825 * buffer-local value if it was requested to return window-local one.
8826 *
8827 * Pretends that option is absent if it is not present in the requested scope
8828 * (i.e. has no global, window-local or buffer-local value depending on
8829 * opt_type). Uses
8830 *
8831 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008832 * 0 hidden or unknown option, also option that does not have requested
8833 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008834 * see SOPT_* in vim.h for other flags
8835 *
8836 * Possible opt_type values: see SREQ_* in vim.h
8837 */
8838 int
8839get_option_value_strict(name, numval, stringval, opt_type, from)
8840 char_u *name;
8841 long *numval;
8842 char_u **stringval; /* NULL when only obtaining attributes */
8843 int opt_type;
8844 void *from;
8845{
8846 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008847 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008848 struct vimoption *p;
8849 int r = 0;
8850
8851 opt_idx = findoption(name);
8852 if (opt_idx < 0)
8853 return 0;
8854
8855 p = &(options[opt_idx]);
8856
8857 /* Hidden option */
8858 if (p->var == NULL)
8859 return 0;
8860
8861 if (p->flags & P_BOOL)
8862 r |= SOPT_BOOL;
8863 else if (p->flags & P_NUM)
8864 r |= SOPT_NUM;
8865 else if (p->flags & P_STRING)
8866 r |= SOPT_STRING;
8867
8868 if (p->indir == PV_NONE)
8869 {
8870 if (opt_type == SREQ_GLOBAL)
8871 r |= SOPT_GLOBAL;
8872 else
8873 return 0; /* Did not request global-only option */
8874 }
8875 else
8876 {
8877 if (p->indir & PV_BOTH)
8878 r |= SOPT_GLOBAL;
8879 else if (opt_type == SREQ_GLOBAL)
8880 return 0; /* Requested global option */
8881
8882 if (p->indir & PV_WIN)
8883 {
8884 if (opt_type == SREQ_BUF)
8885 return 0; /* Did not request window-local option */
8886 else
8887 r |= SOPT_WIN;
8888 }
8889 else if (p->indir & PV_BUF)
8890 {
8891 if (opt_type == SREQ_WIN)
8892 return 0; /* Did not request buffer-local option */
8893 else
8894 r |= SOPT_BUF;
8895 }
8896 }
8897
8898 if (stringval == NULL)
8899 return r;
8900
8901 if (opt_type == SREQ_GLOBAL)
8902 varp = p->var;
8903 else
8904 {
8905 if (opt_type == SREQ_BUF)
8906 {
8907 /* Special case: 'modified' is b_changed, but we also want to
8908 * consider it set when 'ff' or 'fenc' changed. */
8909 if (p->indir == PV_MOD)
8910 {
8911 *numval = bufIsChanged((buf_T *) from);
8912 varp = NULL;
8913 }
8914#ifdef FEAT_CRYPT
8915 else if (p->indir == PV_KEY)
8916 {
8917 /* never return the value of the crypt key */
8918 *stringval = NULL;
8919 varp = NULL;
8920 }
8921#endif
8922 else
8923 {
8924 aco_save_T aco;
8925 aucmd_prepbuf(&aco, (buf_T *) from);
8926 varp = get_varp(p);
8927 aucmd_restbuf(&aco);
8928 }
8929 }
8930 else if (opt_type == SREQ_WIN)
8931 {
8932 win_T *save_curwin;
8933 save_curwin = curwin;
8934 curwin = (win_T *) from;
8935 curbuf = curwin->w_buffer;
8936 varp = get_varp(p);
8937 curwin = save_curwin;
8938 curbuf = curwin->w_buffer;
8939 }
8940 if (varp == p->var)
8941 return (r | SOPT_UNSET);
8942 }
8943
8944 if (varp != NULL)
8945 {
8946 if (p->flags & P_STRING)
8947 *stringval = vim_strsave(*(char_u **)(varp));
8948 else if (p->flags & P_NUM)
8949 *numval = *(long *) varp;
8950 else
8951 *numval = *(int *)varp;
8952 }
8953
8954 return r;
8955}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008956
8957/*
8958 * Iterate over options. First argument is a pointer to a pointer to a structure
8959 * inside options[] array, second is option type like in the above function.
8960 *
8961 * If first argument points to NULL it is assumed that iteration just started
8962 * and caller needs the very first value.
8963 * If first argument points to the end marker function returns NULL and sets
8964 * first argument to NULL.
8965 *
8966 * Returns full option name for current option on each call.
8967 */
8968 char_u *
8969option_iter_next(option, opt_type)
8970 void **option;
8971 int opt_type;
8972{
8973 struct vimoption *ret = NULL;
8974 do
8975 {
8976 if (*option == NULL)
8977 *option = (void *) options;
8978 else if (((struct vimoption *) (*option))->fullname == NULL)
8979 {
8980 *option = NULL;
8981 return NULL;
8982 }
8983 else
8984 *option = (void *) (((struct vimoption *) (*option)) + 1);
8985
8986 ret = ((struct vimoption *) (*option));
8987
8988 /* Hidden option */
8989 if (ret->var == NULL)
8990 {
8991 ret = NULL;
8992 continue;
8993 }
8994
8995 switch (opt_type)
8996 {
8997 case SREQ_GLOBAL:
8998 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
8999 ret = NULL;
9000 break;
9001 case SREQ_BUF:
9002 if (!(ret->indir & PV_BUF))
9003 ret = NULL;
9004 break;
9005 case SREQ_WIN:
9006 if (!(ret->indir & PV_WIN))
9007 ret = NULL;
9008 break;
9009 default:
9010 EMSG2(_(e_intern2), "option_iter_next()");
9011 return NULL;
9012 }
9013 }
9014 while (ret == NULL);
9015
9016 return (char_u *)ret->fullname;
9017}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009018#endif
9019
Bram Moolenaar071d4272004-06-13 20:20:40 +00009020/*
9021 * Set the value of option "name".
9022 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009023 *
9024 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009025 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009026 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009027set_option_value(name, number, string, opt_flags)
9028 char_u *name;
9029 long number;
9030 char_u *string;
9031 int opt_flags; /* OPT_LOCAL or 0 (both) */
9032{
9033 int opt_idx;
9034 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009035 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009036
9037 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009038 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009039 EMSG2(_("E355: Unknown option: %s"), name);
9040 else
9041 {
9042 flags = options[opt_idx].flags;
9043#ifdef HAVE_SANDBOX
9044 /* Disallow changing some options in the sandbox */
9045 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009046 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009047 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009048 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009049 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009051 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009052 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009053 else
9054 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009055 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056 if (varp != NULL) /* hidden option is not changed */
9057 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009058 if (number == 0 && string != NULL)
9059 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009060 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009061
9062 /* Either we are given a string or we are setting option
9063 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009064 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009065 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009066 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009067 {
9068 /* There's another character after zeros or the string
9069 * is empty. In both cases, we are trying to set a
9070 * num option using a string. */
9071 EMSG3(_("E521: Number required: &%s = '%s'"),
9072 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009073 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009074
9075 }
9076 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009078 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009079 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009081 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009082 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083 }
9084 }
9085 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009086 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087}
9088
9089/*
9090 * Get the terminal code for a terminal option.
9091 * Returns NULL when not found.
9092 */
9093 char_u *
9094get_term_code(tname)
9095 char_u *tname;
9096{
9097 int opt_idx;
9098 char_u *varp;
9099
9100 if (tname[0] != 't' || tname[1] != '_' ||
9101 tname[2] == NUL || tname[3] == NUL)
9102 return NULL;
9103 if ((opt_idx = findoption(tname)) >= 0)
9104 {
9105 varp = get_varp(&(options[opt_idx]));
9106 if (varp != NULL)
9107 varp = *(char_u **)(varp);
9108 return varp;
9109 }
9110 return find_termcode(tname + 2);
9111}
9112
9113 char_u *
9114get_highlight_default()
9115{
9116 int i;
9117
9118 i = findoption((char_u *)"hl");
9119 if (i >= 0)
9120 return options[i].def_val[VI_DEFAULT];
9121 return (char_u *)NULL;
9122}
9123
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009124#if defined(FEAT_MBYTE) || defined(PROTO)
9125 char_u *
9126get_encoding_default()
9127{
9128 int i;
9129
9130 i = findoption((char_u *)"enc");
9131 if (i >= 0)
9132 return options[i].def_val[VI_DEFAULT];
9133 return (char_u *)NULL;
9134}
9135#endif
9136
Bram Moolenaar071d4272004-06-13 20:20:40 +00009137/*
9138 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9139 */
9140 static int
9141find_key_option(arg)
9142 char_u *arg;
9143{
9144 int key;
9145 int modifiers;
9146
9147 /*
9148 * Don't use get_special_key_code() for t_xx, we don't want it to call
9149 * add_termcap_entry().
9150 */
9151 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9152 key = TERMCAP2KEY(arg[2], arg[3]);
9153 else
9154 {
9155 --arg; /* put arg at the '<' */
9156 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009157 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009158 if (modifiers) /* can't handle modifiers here */
9159 key = 0;
9160 }
9161 return key;
9162}
9163
9164/*
9165 * if 'all' == 0: show changed options
9166 * if 'all' == 1: show all normal options
9167 * if 'all' == 2: show all terminal options
9168 */
9169 static void
9170showoptions(all, opt_flags)
9171 int all;
9172 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9173{
9174 struct vimoption *p;
9175 int col;
9176 int isterm;
9177 char_u *varp;
9178 struct vimoption **items;
9179 int item_count;
9180 int run;
9181 int row, rows;
9182 int cols;
9183 int i;
9184 int len;
9185
9186#define INC 20
9187#define GAP 3
9188
9189 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9190 PARAM_COUNT));
9191 if (items == NULL)
9192 return;
9193
9194 /* Highlight title */
9195 if (all == 2)
9196 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9197 else if (opt_flags & OPT_GLOBAL)
9198 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9199 else if (opt_flags & OPT_LOCAL)
9200 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9201 else
9202 MSG_PUTS_TITLE(_("\n--- Options ---"));
9203
9204 /*
9205 * do the loop two times:
9206 * 1. display the short items
9207 * 2. display the long items (only strings and numbers)
9208 */
9209 for (run = 1; run <= 2 && !got_int; ++run)
9210 {
9211 /*
9212 * collect the items in items[]
9213 */
9214 item_count = 0;
9215 for (p = &options[0]; p->fullname != NULL; p++)
9216 {
9217 varp = NULL;
9218 isterm = istermoption(p);
9219 if (opt_flags != 0)
9220 {
9221 if (p->indir != PV_NONE && !isterm)
9222 varp = get_varp_scope(p, opt_flags);
9223 }
9224 else
9225 varp = get_varp(p);
9226 if (varp != NULL
9227 && ((all == 2 && isterm)
9228 || (all == 1 && !isterm)
9229 || (all == 0 && !optval_default(p, varp))))
9230 {
9231 if (p->flags & P_BOOL)
9232 len = 1; /* a toggle option fits always */
9233 else
9234 {
9235 option_value2string(p, opt_flags);
9236 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9237 }
9238 if ((len <= INC - GAP && run == 1) ||
9239 (len > INC - GAP && run == 2))
9240 items[item_count++] = p;
9241 }
9242 }
9243
9244 /*
9245 * display the items
9246 */
9247 if (run == 1)
9248 {
9249 cols = (Columns + GAP - 3) / INC;
9250 if (cols == 0)
9251 cols = 1;
9252 rows = (item_count + cols - 1) / cols;
9253 }
9254 else /* run == 2 */
9255 rows = item_count;
9256 for (row = 0; row < rows && !got_int; ++row)
9257 {
9258 msg_putchar('\n'); /* go to next line */
9259 if (got_int) /* 'q' typed in more */
9260 break;
9261 col = 0;
9262 for (i = row; i < item_count; i += rows)
9263 {
9264 msg_col = col; /* make columns */
9265 showoneopt(items[i], opt_flags);
9266 col += INC;
9267 }
9268 out_flush();
9269 ui_breakcheck();
9270 }
9271 }
9272 vim_free(items);
9273}
9274
9275/*
9276 * Return TRUE if option "p" has its default value.
9277 */
9278 static int
9279optval_default(p, varp)
9280 struct vimoption *p;
9281 char_u *varp;
9282{
9283 int dvi;
9284
9285 if (varp == NULL)
9286 return TRUE; /* hidden option is always at default */
9287 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9288 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009289 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009290 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009291 /* the cast to long is required for Manx C, long_i is
9292 * needed for MSVC */
9293 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009294 /* P_STRING */
9295 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9296}
9297
9298/*
9299 * showoneopt: show the value of one option
9300 * must not be called with a hidden option!
9301 */
9302 static void
9303showoneopt(p, opt_flags)
9304 struct vimoption *p;
9305 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9306{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009307 char_u *varp;
9308 int save_silent = silent_mode;
9309
9310 silent_mode = FALSE;
9311 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312
9313 varp = get_varp_scope(p, opt_flags);
9314
9315 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9316 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9317 ? !curbufIsChanged() : !*(int *)varp))
9318 MSG_PUTS("no");
9319 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9320 MSG_PUTS("--");
9321 else
9322 MSG_PUTS(" ");
9323 MSG_PUTS(p->fullname);
9324 if (!(p->flags & P_BOOL))
9325 {
9326 msg_putchar('=');
9327 /* put value string in NameBuff */
9328 option_value2string(p, opt_flags);
9329 msg_outtrans(NameBuff);
9330 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009331
9332 silent_mode = save_silent;
9333 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334}
9335
9336/*
9337 * Write modified options as ":set" commands to a file.
9338 *
9339 * There are three values for "opt_flags":
9340 * OPT_GLOBAL: Write global option values and fresh values of
9341 * buffer-local options (used for start of a session
9342 * file).
9343 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9344 * curwin (used for a vimrc file).
9345 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9346 * and local values for window-local options of
9347 * curwin. Local values are also written when at the
9348 * default value, because a modeline or autocommand
9349 * may have set them when doing ":edit file" and the
9350 * user has set them back at the default or fresh
9351 * value.
9352 * When "local_only" is TRUE, don't write fresh
9353 * values, only local values (for ":mkview").
9354 * (fresh value = value used for a new buffer or window for a local option).
9355 *
9356 * Return FAIL on error, OK otherwise.
9357 */
9358 int
9359makeset(fd, opt_flags, local_only)
9360 FILE *fd;
9361 int opt_flags;
9362 int local_only;
9363{
9364 struct vimoption *p;
9365 char_u *varp; /* currently used value */
9366 char_u *varp_fresh; /* local value */
9367 char_u *varp_local = NULL; /* fresh value */
9368 char *cmd;
9369 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009370 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009371
9372 /*
9373 * The options that don't have a default (terminal name, columns, lines)
9374 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009375 * Do the loop over "options[]" twice: once for options with the
9376 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009377 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009378 for (pri = 1; pri >= 0; --pri)
9379 {
9380 for (p = &options[0]; !istermoption(p); p++)
9381 if (!(p->flags & P_NO_MKRC)
9382 && !istermoption(p)
9383 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009384 {
9385 /* skip global option when only doing locals */
9386 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9387 continue;
9388
9389 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9390 * file, they are always buffer-specific. */
9391 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9392 continue;
9393
9394 /* Global values are only written when not at the default value. */
9395 varp = get_varp_scope(p, opt_flags);
9396 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9397 continue;
9398
9399 round = 2;
9400 if (p->indir != PV_NONE)
9401 {
9402 if (p->var == VAR_WIN)
9403 {
9404 /* skip window-local option when only doing globals */
9405 if (!(opt_flags & OPT_LOCAL))
9406 continue;
9407 /* When fresh value of window-local option is not at the
9408 * default, need to write it too. */
9409 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9410 {
9411 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9412 if (!optval_default(p, varp_fresh))
9413 {
9414 round = 1;
9415 varp_local = varp;
9416 varp = varp_fresh;
9417 }
9418 }
9419 }
9420 }
9421
9422 /* Round 1: fresh value for window-local options.
9423 * Round 2: other values */
9424 for ( ; round <= 2; varp = varp_local, ++round)
9425 {
9426 if (round == 1 || (opt_flags & OPT_GLOBAL))
9427 cmd = "set";
9428 else
9429 cmd = "setlocal";
9430
9431 if (p->flags & P_BOOL)
9432 {
9433 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9434 return FAIL;
9435 }
9436 else if (p->flags & P_NUM)
9437 {
9438 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9439 return FAIL;
9440 }
9441 else /* P_STRING */
9442 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009443#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9444 int do_endif = FALSE;
9445
Bram Moolenaar071d4272004-06-13 20:20:40 +00009446 /* Don't set 'syntax' and 'filetype' again if the value is
9447 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009448 if (
9449# if defined(FEAT_SYN_HL)
9450 p->indir == PV_SYN
9451# if defined(FEAT_AUTOCMD)
9452 ||
9453# endif
9454# endif
9455# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009456 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009457# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009458 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459 {
9460 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9461 *(char_u **)(varp)) < 0
9462 || put_eol(fd) < 0)
9463 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009464 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009465 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9468 (p->flags & P_EXPAND) != 0) == FAIL)
9469 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009470#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9471 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009472 {
9473 if (put_line(fd, "endif") == FAIL)
9474 return FAIL;
9475 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009476#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009477 }
9478 }
9479 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009480 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009481 return OK;
9482}
9483
9484#if defined(FEAT_FOLDING) || defined(PROTO)
9485/*
9486 * Generate set commands for the local fold options only. Used when
9487 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9488 */
9489 int
9490makefoldset(fd)
9491 FILE *fd;
9492{
9493 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9494# ifdef FEAT_EVAL
9495 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9496 == FAIL
9497# endif
9498 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9499 == FAIL
9500 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9501 == FAIL
9502 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9503 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9504 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9505 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9506 )
9507 return FAIL;
9508
9509 return OK;
9510}
9511#endif
9512
9513 static int
9514put_setstring(fd, cmd, name, valuep, expand)
9515 FILE *fd;
9516 char *cmd;
9517 char *name;
9518 char_u **valuep;
9519 int expand;
9520{
9521 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009522 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009523
9524 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9525 return FAIL;
9526 if (*valuep != NULL)
9527 {
9528 /* Output 'pastetoggle' as key names. For other
9529 * options some characters have to be escaped with
9530 * CTRL-V or backslash */
9531 if (valuep == &p_pt)
9532 {
9533 s = *valuep;
9534 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009535 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009536 return FAIL;
9537 }
9538 else if (expand)
9539 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009540 buf = alloc(MAXPATHL);
9541 if (buf == NULL)
9542 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009543 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9544 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009545 {
9546 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009548 }
9549 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009550 }
9551 else if (put_escstr(fd, *valuep, 2) == FAIL)
9552 return FAIL;
9553 }
9554 if (put_eol(fd) < 0)
9555 return FAIL;
9556 return OK;
9557}
9558
9559 static int
9560put_setnum(fd, cmd, name, valuep)
9561 FILE *fd;
9562 char *cmd;
9563 char *name;
9564 long *valuep;
9565{
9566 long wc;
9567
9568 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9569 return FAIL;
9570 if (wc_use_keyname((char_u *)valuep, &wc))
9571 {
9572 /* print 'wildchar' and 'wildcharm' as a key name */
9573 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9574 return FAIL;
9575 }
9576 else if (fprintf(fd, "%ld", *valuep) < 0)
9577 return FAIL;
9578 if (put_eol(fd) < 0)
9579 return FAIL;
9580 return OK;
9581}
9582
9583 static int
9584put_setbool(fd, cmd, name, value)
9585 FILE *fd;
9586 char *cmd;
9587 char *name;
9588 int value;
9589{
Bram Moolenaar893de922007-10-02 18:40:57 +00009590 if (value < 0) /* global/local option using global value */
9591 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9593 || put_eol(fd) < 0)
9594 return FAIL;
9595 return OK;
9596}
9597
9598/*
9599 * Clear all the terminal options.
9600 * If the option has been allocated, free the memory.
9601 * Terminal options are never hidden or indirect.
9602 */
9603 void
9604clear_termoptions()
9605{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009606 /*
9607 * Reset a few things before clearing the old options. This may cause
9608 * outputting a few things that the terminal doesn't understand, but the
9609 * screen will be cleared later, so this is OK.
9610 */
9611#ifdef FEAT_MOUSE_TTY
9612 mch_setmouse(FALSE); /* switch mouse off */
9613#endif
9614#ifdef FEAT_TITLE
9615 mch_restore_title(3); /* restore window titles */
9616#endif
9617#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9618 /* When starting the GUI close the display opened for the clipboard.
9619 * After restoring the title, because that will need the display. */
9620 if (gui.starting)
9621 clear_xterm_clip();
9622#endif
9623#ifdef WIN3264
9624 /*
9625 * Check if this is allowed now.
9626 */
9627 if (can_end_termcap_mode(FALSE) == TRUE)
9628#endif
9629 stoptermcap(); /* stop termcap mode */
9630
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009631 free_termoptions();
9632}
9633
9634 void
9635free_termoptions()
9636{
9637 struct vimoption *p;
9638
Bram Moolenaar071d4272004-06-13 20:20:40 +00009639 for (p = &options[0]; p->fullname != NULL; p++)
9640 if (istermoption(p))
9641 {
9642 if (p->flags & P_ALLOCED)
9643 free_string_option(*(char_u **)(p->var));
9644 if (p->flags & P_DEF_ALLOCED)
9645 free_string_option(p->def_val[VI_DEFAULT]);
9646 *(char_u **)(p->var) = empty_option;
9647 p->def_val[VI_DEFAULT] = empty_option;
9648 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9649 }
9650 clear_termcodes();
9651}
9652
9653/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009654 * Free the string for one term option, if it was allocated.
9655 * Set the string to empty_option and clear allocated flag.
9656 * "var" points to the option value.
9657 */
9658 void
9659free_one_termoption(var)
9660 char_u *var;
9661{
9662 struct vimoption *p;
9663
9664 for (p = &options[0]; p->fullname != NULL; p++)
9665 if (p->var == var)
9666 {
9667 if (p->flags & P_ALLOCED)
9668 free_string_option(*(char_u **)(p->var));
9669 *(char_u **)(p->var) = empty_option;
9670 p->flags &= ~P_ALLOCED;
9671 break;
9672 }
9673}
9674
9675/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009676 * Set the terminal option defaults to the current value.
9677 * Used after setting the terminal name.
9678 */
9679 void
9680set_term_defaults()
9681{
9682 struct vimoption *p;
9683
9684 for (p = &options[0]; p->fullname != NULL; p++)
9685 {
9686 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9687 {
9688 if (p->flags & P_DEF_ALLOCED)
9689 {
9690 free_string_option(p->def_val[VI_DEFAULT]);
9691 p->flags &= ~P_DEF_ALLOCED;
9692 }
9693 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9694 if (p->flags & P_ALLOCED)
9695 {
9696 p->flags |= P_DEF_ALLOCED;
9697 p->flags &= ~P_ALLOCED; /* don't free the value now */
9698 }
9699 }
9700 }
9701}
9702
9703/*
9704 * return TRUE if 'p' starts with 't_'
9705 */
9706 static int
9707istermoption(p)
9708 struct vimoption *p;
9709{
9710 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9711}
9712
9713/*
9714 * Compute columns for ruler and shown command. 'sc_col' is also used to
9715 * decide what the maximum length of a message on the status line can be.
9716 * If there is a status line for the last window, 'sc_col' is independent
9717 * of 'ru_col'.
9718 */
9719
9720#define COL_RULER 17 /* columns needed by standard ruler */
9721
9722 void
9723comp_col()
9724{
9725#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9726 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9727
9728 sc_col = 0;
9729 ru_col = 0;
9730 if (p_ru)
9731 {
9732#ifdef FEAT_STL_OPT
9733 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9734#else
9735 ru_col = COL_RULER + 1;
9736#endif
9737 /* no last status line, adjust sc_col */
9738 if (!last_has_status)
9739 sc_col = ru_col;
9740 }
9741 if (p_sc)
9742 {
9743 sc_col += SHOWCMD_COLS;
9744 if (!p_ru || last_has_status) /* no need for separating space */
9745 ++sc_col;
9746 }
9747 sc_col = Columns - sc_col;
9748 ru_col = Columns - ru_col;
9749 if (sc_col <= 0) /* screen too narrow, will become a mess */
9750 sc_col = 1;
9751 if (ru_col <= 0)
9752 ru_col = 1;
9753#else
9754 sc_col = Columns;
9755 ru_col = Columns;
9756#endif
9757}
9758
9759/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009760 * Unset local option value, similar to ":set opt<".
9761 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009762 void
9763unset_global_local_option(name, from)
9764 char_u *name;
9765 void *from;
9766{
9767 struct vimoption *p;
9768 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009769 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009770
9771 opt_idx = findoption(name);
9772 p = &(options[opt_idx]);
9773
9774 switch ((int)p->indir)
9775 {
9776 /* global option with local value: use local value if it's been set */
9777 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009778 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009779 break;
9780 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009781 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009782 break;
9783 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009784 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009785 break;
9786 case PV_AR:
9787 buf->b_p_ar = -1;
9788 break;
9789 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009790 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009791 break;
9792#ifdef FEAT_FIND_ID
9793 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009794 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009795 break;
9796 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009797 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009798 break;
9799#endif
9800#ifdef FEAT_INS_EXPAND
9801 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009802 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009803 break;
9804 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009805 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009806 break;
9807#endif
9808#ifdef FEAT_QUICKFIX
9809 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009810 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009811 break;
9812 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009813 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009814 break;
9815 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009816 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009817 break;
9818#endif
9819#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9820 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009821 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009822 break;
9823#endif
9824#if defined(FEAT_CRYPT)
9825 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009826 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009827 break;
9828#endif
9829#ifdef FEAT_STL_OPT
9830 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009831 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009832 break;
9833#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009834 case PV_UL:
9835 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9836 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009837#ifdef FEAT_LISP
9838 case PV_LW:
9839 clear_string_option(&buf->b_p_lw);
9840 break;
9841#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009842 }
9843}
9844
9845/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009846 * Get pointer to option variable, depending on local or global scope.
9847 */
9848 static char_u *
9849get_varp_scope(p, opt_flags)
9850 struct vimoption *p;
9851 int opt_flags;
9852{
9853 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9854 {
9855 if (p->var == VAR_WIN)
9856 return (char_u *)GLOBAL_WO(get_varp(p));
9857 return p->var;
9858 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009859 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009860 {
9861 switch ((int)p->indir)
9862 {
9863#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009864 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9865 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9866 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009867#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009868 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9869 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9870 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009871 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009872 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009873#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009874 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9875 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009876#endif
9877#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009878 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9879 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009880#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009881#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9882 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9883#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009884#if defined(FEAT_CRYPT)
9885 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9886#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009887#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009888 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009889#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009890 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009891#ifdef FEAT_LISP
9892 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9893#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894 }
9895 return NULL; /* "cannot happen" */
9896 }
9897 return get_varp(p);
9898}
9899
9900/*
9901 * Get pointer to option variable.
9902 */
9903 static char_u *
9904get_varp(p)
9905 struct vimoption *p;
9906{
9907 /* hidden option, always return NULL */
9908 if (p->var == NULL)
9909 return NULL;
9910
9911 switch ((int)p->indir)
9912 {
9913 case PV_NONE: return p->var;
9914
9915 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009916 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009917 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009918 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009919 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009920 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009922 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009924 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009925 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9926#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009927 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009928 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009929 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009930 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9931#endif
9932#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009933 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009934 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009935 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009936 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9937#endif
9938#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009939 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009941 case PV_GP: return *curbuf->b_p_gp != NUL
9942 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9943 case PV_MP: return *curbuf->b_p_mp != NUL
9944 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009945#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009946#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9947 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9948 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9949#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009950#if defined(FEAT_CRYPT)
9951 case PV_CM: return *curbuf->b_p_cm != NUL
9952 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9953#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009954#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009955 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009956 ? (char_u *)&(curwin->w_p_stl) : p->var;
9957#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009958 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
9959 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009960#ifdef FEAT_LISP
9961 case PV_LW: return *curbuf->b_p_lw != NUL
9962 ? (char_u *)&(curbuf->b_p_lw) : p->var;
9963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009964
9965#ifdef FEAT_ARABIC
9966 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9967#endif
9968 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009969#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009970 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9971#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009972#ifdef FEAT_SYN_HL
9973 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9974 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +02009975 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009976#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977#ifdef FEAT_DIFF
9978 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9979#endif
9980#ifdef FEAT_FOLDING
9981 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
9982 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
9983 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
9984 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
9985 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
9986 case PV_FML: return (char_u *)&(curwin->w_p_fml);
9987 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
9988# ifdef FEAT_EVAL
9989 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
9990 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
9991# endif
9992 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
9993#endif
9994 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +02009995 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009996#ifdef FEAT_LINEBREAK
9997 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
9998#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009999#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010000 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10001#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010002#ifdef FEAT_VERTSPLIT
10003 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10004#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010005#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10006 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10007#endif
10008#ifdef FEAT_RIGHTLEFT
10009 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10010 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10011#endif
10012 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10013 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10014#ifdef FEAT_LINEBREAK
10015 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
10016#endif
10017#ifdef FEAT_SCROLLBIND
10018 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10019#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010020#ifdef FEAT_CURSORBIND
10021 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10022#endif
10023#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010024 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10025 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010027
10028 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10029 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10030#ifdef FEAT_MBYTE
10031 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10032#endif
10033#if defined(FEAT_QUICKFIX)
10034 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10035 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10036#endif
10037 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10038 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10039#ifdef FEAT_CINDENT
10040 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10041 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10042 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10043#endif
10044#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10045 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10046#endif
10047#ifdef FEAT_COMMENTS
10048 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10049#endif
10050#ifdef FEAT_FOLDING
10051 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10052#endif
10053#ifdef FEAT_INS_EXPAND
10054 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10055#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010056#ifdef FEAT_COMPL_FUNC
10057 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010058 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010059#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010060 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10061 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10062#ifdef FEAT_MBYTE
10063 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10064#endif
10065 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10066#ifdef FEAT_AUTOCMD
10067 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10068#endif
10069 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010070 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010071 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10072 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10073 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10074 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10075#ifdef FEAT_FIND_ID
10076# ifdef FEAT_EVAL
10077 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10078# endif
10079#endif
10080#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10081 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10082 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10083#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010084#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010085 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010087#ifdef FEAT_CRYPT
10088 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10089#endif
10090#ifdef FEAT_LISP
10091 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10092#endif
10093 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10094 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10095 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10096 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10097 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010098 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010099#ifdef FEAT_TEXTOBJ
10100 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10101#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010102 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10103#ifdef FEAT_SMARTINDENT
10104 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10105#endif
10106#ifndef SHORT_FNAME
10107 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10108#endif
10109 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10110#ifdef FEAT_SEARCHPATH
10111 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10112#endif
10113 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10114#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010115 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010116 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10117#endif
10118#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010119 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10120 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10121 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010122#endif
10123 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10124 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10125 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10126 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010127#ifdef FEAT_PERSISTENT_UNDO
10128 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010130 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10131#ifdef FEAT_KEYMAP
10132 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10133#endif
10134 default: EMSG(_("E356: get_varp ERROR"));
10135 }
10136 /* always return a valid pointer to avoid a crash! */
10137 return (char_u *)&(curbuf->b_p_wm);
10138}
10139
10140/*
10141 * Get the value of 'equalprg', either the buffer-local one or the global one.
10142 */
10143 char_u *
10144get_equalprg()
10145{
10146 if (*curbuf->b_p_ep == NUL)
10147 return p_ep;
10148 return curbuf->b_p_ep;
10149}
10150
10151#if defined(FEAT_WINDOWS) || defined(PROTO)
10152/*
10153 * Copy options from one window to another.
10154 * Used when splitting a window.
10155 */
10156 void
10157win_copy_options(wp_from, wp_to)
10158 win_T *wp_from;
10159 win_T *wp_to;
10160{
10161 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10162 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10163# ifdef FEAT_RIGHTLEFT
10164# ifdef FEAT_FKMAP
10165 /* Is this right? */
10166 wp_to->w_farsi = wp_from->w_farsi;
10167# endif
10168# endif
10169}
10170#endif
10171
10172/*
10173 * Copy the options from one winopt_T to another.
10174 * Doesn't free the old option values in "to", use clear_winopt() for that.
10175 * The 'scroll' option is not copied, because it depends on the window height.
10176 * The 'previewwindow' option is reset, there can be only one preview window.
10177 */
10178 void
10179copy_winopt(from, to)
10180 winopt_T *from;
10181 winopt_T *to;
10182{
10183#ifdef FEAT_ARABIC
10184 to->wo_arab = from->wo_arab;
10185#endif
10186 to->wo_list = from->wo_list;
10187 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010188 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010189#ifdef FEAT_LINEBREAK
10190 to->wo_nuw = from->wo_nuw;
10191#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192#ifdef FEAT_RIGHTLEFT
10193 to->wo_rl = from->wo_rl;
10194 to->wo_rlc = vim_strsave(from->wo_rlc);
10195#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010196#ifdef FEAT_STL_OPT
10197 to->wo_stl = vim_strsave(from->wo_stl);
10198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010200#ifdef FEAT_DIFF
10201 to->wo_wrap_save = from->wo_wrap_save;
10202#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203#ifdef FEAT_LINEBREAK
10204 to->wo_lbr = from->wo_lbr;
10205#endif
10206#ifdef FEAT_SCROLLBIND
10207 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010208 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010209#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010210#ifdef FEAT_CURSORBIND
10211 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010212 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010213#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010214#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010215 to->wo_spell = from->wo_spell;
10216#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010217#ifdef FEAT_SYN_HL
10218 to->wo_cuc = from->wo_cuc;
10219 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010220 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222#ifdef FEAT_DIFF
10223 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010224 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010226#ifdef FEAT_CONCEAL
10227 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010228 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010229#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010230#ifdef FEAT_FOLDING
10231 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010232 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010234 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010235 to->wo_fdi = vim_strsave(from->wo_fdi);
10236 to->wo_fml = from->wo_fml;
10237 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010238 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010240 to->wo_fdm_save = from->wo_diff_saved
10241 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242 to->wo_fdn = from->wo_fdn;
10243# ifdef FEAT_EVAL
10244 to->wo_fde = vim_strsave(from->wo_fde);
10245 to->wo_fdt = vim_strsave(from->wo_fdt);
10246# endif
10247 to->wo_fmr = vim_strsave(from->wo_fmr);
10248#endif
10249 check_winopt(to); /* don't want NULL pointers */
10250}
10251
10252/*
10253 * Check string options in a window for a NULL value.
10254 */
10255 void
10256check_win_options(win)
10257 win_T *win;
10258{
10259 check_winopt(&win->w_onebuf_opt);
10260 check_winopt(&win->w_allbuf_opt);
10261}
10262
10263/*
10264 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10265 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 void
10267check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010268 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269{
10270#ifdef FEAT_FOLDING
10271 check_string_option(&wop->wo_fdi);
10272 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010273 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274# ifdef FEAT_EVAL
10275 check_string_option(&wop->wo_fde);
10276 check_string_option(&wop->wo_fdt);
10277# endif
10278 check_string_option(&wop->wo_fmr);
10279#endif
10280#ifdef FEAT_RIGHTLEFT
10281 check_string_option(&wop->wo_rlc);
10282#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010283#ifdef FEAT_STL_OPT
10284 check_string_option(&wop->wo_stl);
10285#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010286#ifdef FEAT_SYN_HL
10287 check_string_option(&wop->wo_cc);
10288#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010289#ifdef FEAT_CONCEAL
10290 check_string_option(&wop->wo_cocu);
10291#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292}
10293
10294/*
10295 * Free the allocated memory inside a winopt_T.
10296 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297 void
10298clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010299 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300{
10301#ifdef FEAT_FOLDING
10302 clear_string_option(&wop->wo_fdi);
10303 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010304 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305# ifdef FEAT_EVAL
10306 clear_string_option(&wop->wo_fde);
10307 clear_string_option(&wop->wo_fdt);
10308# endif
10309 clear_string_option(&wop->wo_fmr);
10310#endif
10311#ifdef FEAT_RIGHTLEFT
10312 clear_string_option(&wop->wo_rlc);
10313#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010314#ifdef FEAT_STL_OPT
10315 clear_string_option(&wop->wo_stl);
10316#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010317#ifdef FEAT_SYN_HL
10318 clear_string_option(&wop->wo_cc);
10319#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010320#ifdef FEAT_CONCEAL
10321 clear_string_option(&wop->wo_cocu);
10322#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323}
10324
10325/*
10326 * Copy global option values to local options for one buffer.
10327 * Used when creating a new buffer and sometimes when entering a buffer.
10328 * flags:
10329 * BCO_ENTER We will enter the buf buffer.
10330 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10331 * appropriate.
10332 * BCO_NOHELP Don't copy the values to a help buffer.
10333 */
10334 void
10335buf_copy_options(buf, flags)
10336 buf_T *buf;
10337 int flags;
10338{
10339 int should_copy = TRUE;
10340 char_u *save_p_isk = NULL; /* init for GCC */
10341 int dont_do_help;
10342 int did_isk = FALSE;
10343
10344 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010345 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346 */
10347 if (buf == NULL || !buf_valid(buf))
10348 return;
10349
10350 /*
10351 * Skip this when the option defaults have not been set yet. Happens when
10352 * main() allocates the first buffer.
10353 */
10354 if (p_cpo != NULL)
10355 {
10356 /*
10357 * Always copy when entering and 'cpo' contains 'S'.
10358 * Don't copy when already initialized.
10359 * Don't copy when 'cpo' contains 's' and not entering.
10360 * 'S' BCO_ENTER initialized 's' should_copy
10361 * yes yes X X TRUE
10362 * yes no yes X FALSE
10363 * no X yes X FALSE
10364 * X no no yes FALSE
10365 * X no no no TRUE
10366 * no yes no X TRUE
10367 */
10368 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10369 && (buf->b_p_initialized
10370 || (!(flags & BCO_ENTER)
10371 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10372 should_copy = FALSE;
10373
10374 if (should_copy || (flags & BCO_ALWAYS))
10375 {
10376 /* Don't copy the options specific to a help buffer when
10377 * BCO_NOHELP is given or the options were initialized already
10378 * (jumping back to a help file with CTRL-T or CTRL-O) */
10379 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10380 || buf->b_p_initialized;
10381 if (dont_do_help) /* don't free b_p_isk */
10382 {
10383 save_p_isk = buf->b_p_isk;
10384 buf->b_p_isk = NULL;
10385 }
10386 /*
10387 * Always free the allocated strings.
10388 * If not already initialized, set 'readonly' and copy 'fileformat'.
10389 */
10390 if (!buf->b_p_initialized)
10391 {
10392 free_buf_options(buf, TRUE);
10393 buf->b_p_ro = FALSE; /* don't copy readonly */
10394 buf->b_p_tx = p_tx;
10395#ifdef FEAT_MBYTE
10396 buf->b_p_fenc = vim_strsave(p_fenc);
10397#endif
10398 buf->b_p_ff = vim_strsave(p_ff);
10399#if defined(FEAT_QUICKFIX)
10400 buf->b_p_bh = empty_option;
10401 buf->b_p_bt = empty_option;
10402#endif
10403 }
10404 else
10405 free_buf_options(buf, FALSE);
10406
10407 buf->b_p_ai = p_ai;
10408 buf->b_p_ai_nopaste = p_ai_nopaste;
10409 buf->b_p_sw = p_sw;
10410 buf->b_p_tw = p_tw;
10411 buf->b_p_tw_nopaste = p_tw_nopaste;
10412 buf->b_p_tw_nobin = p_tw_nobin;
10413 buf->b_p_wm = p_wm;
10414 buf->b_p_wm_nopaste = p_wm_nopaste;
10415 buf->b_p_wm_nobin = p_wm_nobin;
10416 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010417#ifdef FEAT_MBYTE
10418 buf->b_p_bomb = p_bomb;
10419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420 buf->b_p_et = p_et;
10421 buf->b_p_et_nobin = p_et_nobin;
10422 buf->b_p_ml = p_ml;
10423 buf->b_p_ml_nobin = p_ml_nobin;
10424 buf->b_p_inf = p_inf;
10425 buf->b_p_swf = p_swf;
10426#ifdef FEAT_INS_EXPAND
10427 buf->b_p_cpt = vim_strsave(p_cpt);
10428#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010429#ifdef FEAT_COMPL_FUNC
10430 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010431 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010433 buf->b_p_sts = p_sts;
10434 buf->b_p_sts_nopaste = p_sts_nopaste;
10435#ifndef SHORT_FNAME
10436 buf->b_p_sn = p_sn;
10437#endif
10438#ifdef FEAT_COMMENTS
10439 buf->b_p_com = vim_strsave(p_com);
10440#endif
10441#ifdef FEAT_FOLDING
10442 buf->b_p_cms = vim_strsave(p_cms);
10443#endif
10444 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010445 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010446 buf->b_p_nf = vim_strsave(p_nf);
10447 buf->b_p_mps = vim_strsave(p_mps);
10448#ifdef FEAT_SMARTINDENT
10449 buf->b_p_si = p_si;
10450#endif
10451 buf->b_p_ci = p_ci;
10452#ifdef FEAT_CINDENT
10453 buf->b_p_cin = p_cin;
10454 buf->b_p_cink = vim_strsave(p_cink);
10455 buf->b_p_cino = vim_strsave(p_cino);
10456#endif
10457#ifdef FEAT_AUTOCMD
10458 /* Don't copy 'filetype', it must be detected */
10459 buf->b_p_ft = empty_option;
10460#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010461 buf->b_p_pi = p_pi;
10462#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10463 buf->b_p_cinw = vim_strsave(p_cinw);
10464#endif
10465#ifdef FEAT_LISP
10466 buf->b_p_lisp = p_lisp;
10467#endif
10468#ifdef FEAT_SYN_HL
10469 /* Don't copy 'syntax', it must be set */
10470 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010471 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010472#endif
10473#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010474 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010475 (void)compile_cap_prog(&buf->b_s);
10476 buf->b_s.b_p_spf = vim_strsave(p_spf);
10477 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010478#endif
10479#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10480 buf->b_p_inde = vim_strsave(p_inde);
10481 buf->b_p_indk = vim_strsave(p_indk);
10482#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010483#if defined(FEAT_EVAL)
10484 buf->b_p_fex = vim_strsave(p_fex);
10485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486#ifdef FEAT_CRYPT
10487 buf->b_p_key = vim_strsave(p_key);
10488#endif
10489#ifdef FEAT_SEARCHPATH
10490 buf->b_p_sua = vim_strsave(p_sua);
10491#endif
10492#ifdef FEAT_KEYMAP
10493 buf->b_p_keymap = vim_strsave(p_keymap);
10494 buf->b_kmap_state |= KEYMAP_INIT;
10495#endif
10496 /* This isn't really an option, but copying the langmap and IME
10497 * state from the current buffer is better than resetting it. */
10498 buf->b_p_iminsert = p_iminsert;
10499 buf->b_p_imsearch = p_imsearch;
10500
10501 /* options that are normally global but also have a local value
10502 * are not copied, start using the global value */
10503 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010504 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010505#ifdef FEAT_QUICKFIX
10506 buf->b_p_gp = empty_option;
10507 buf->b_p_mp = empty_option;
10508 buf->b_p_efm = empty_option;
10509#endif
10510 buf->b_p_ep = empty_option;
10511 buf->b_p_kp = empty_option;
10512 buf->b_p_path = empty_option;
10513 buf->b_p_tags = empty_option;
10514#ifdef FEAT_FIND_ID
10515 buf->b_p_def = empty_option;
10516 buf->b_p_inc = empty_option;
10517# ifdef FEAT_EVAL
10518 buf->b_p_inex = vim_strsave(p_inex);
10519# endif
10520#endif
10521#ifdef FEAT_INS_EXPAND
10522 buf->b_p_dict = empty_option;
10523 buf->b_p_tsr = empty_option;
10524#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010525#ifdef FEAT_TEXTOBJ
10526 buf->b_p_qe = vim_strsave(p_qe);
10527#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010528#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10529 buf->b_p_bexpr = empty_option;
10530#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010531#if defined(FEAT_CRYPT)
10532 buf->b_p_cm = empty_option;
10533#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010534#ifdef FEAT_PERSISTENT_UNDO
10535 buf->b_p_udf = p_udf;
10536#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010537#ifdef FEAT_LISP
10538 buf->b_p_lw = empty_option;
10539#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540
10541 /*
10542 * Don't copy the options set by ex_help(), use the saved values,
10543 * when going from a help buffer to a non-help buffer.
10544 * Don't touch these at all when BCO_NOHELP is used and going from
10545 * or to a help buffer.
10546 */
10547 if (dont_do_help)
10548 buf->b_p_isk = save_p_isk;
10549 else
10550 {
10551 buf->b_p_isk = vim_strsave(p_isk);
10552 did_isk = TRUE;
10553 buf->b_p_ts = p_ts;
10554 buf->b_help = FALSE;
10555#ifdef FEAT_QUICKFIX
10556 if (buf->b_p_bt[0] == 'h')
10557 clear_string_option(&buf->b_p_bt);
10558#endif
10559 buf->b_p_ma = p_ma;
10560 }
10561 }
10562
10563 /*
10564 * When the options should be copied (ignoring BCO_ALWAYS), set the
10565 * flag that indicates that the options have been initialized.
10566 */
10567 if (should_copy)
10568 buf->b_p_initialized = TRUE;
10569 }
10570
10571 check_buf_options(buf); /* make sure we don't have NULLs */
10572 if (did_isk)
10573 (void)buf_init_chartab(buf, FALSE);
10574}
10575
10576/*
10577 * Reset the 'modifiable' option and its default value.
10578 */
10579 void
10580reset_modifiable()
10581{
10582 int opt_idx;
10583
10584 curbuf->b_p_ma = FALSE;
10585 p_ma = FALSE;
10586 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010587 if (opt_idx >= 0)
10588 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589}
10590
10591/*
10592 * Set the global value for 'iminsert' to the local value.
10593 */
10594 void
10595set_iminsert_global()
10596{
10597 p_iminsert = curbuf->b_p_iminsert;
10598}
10599
10600/*
10601 * Set the global value for 'imsearch' to the local value.
10602 */
10603 void
10604set_imsearch_global()
10605{
10606 p_imsearch = curbuf->b_p_imsearch;
10607}
10608
10609#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10610static int expand_option_idx = -1;
10611static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10612static int expand_option_flags = 0;
10613
10614 void
10615set_context_in_set_cmd(xp, arg, opt_flags)
10616 expand_T *xp;
10617 char_u *arg;
10618 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10619{
10620 int nextchar;
10621 long_u flags = 0; /* init for GCC */
10622 int opt_idx = 0; /* init for GCC */
10623 char_u *p;
10624 char_u *s;
10625 int is_term_option = FALSE;
10626 int key;
10627
10628 expand_option_flags = opt_flags;
10629
10630 xp->xp_context = EXPAND_SETTINGS;
10631 if (*arg == NUL)
10632 {
10633 xp->xp_pattern = arg;
10634 return;
10635 }
10636 p = arg + STRLEN(arg) - 1;
10637 if (*p == ' ' && *(p - 1) != '\\')
10638 {
10639 xp->xp_pattern = p + 1;
10640 return;
10641 }
10642 while (p > arg)
10643 {
10644 s = p;
10645 /* count number of backslashes before ' ' or ',' */
10646 if (*p == ' ' || *p == ',')
10647 {
10648 while (s > arg && *(s - 1) == '\\')
10649 --s;
10650 }
10651 /* break at a space with an even number of backslashes */
10652 if (*p == ' ' && ((p - s) & 1) == 0)
10653 {
10654 ++p;
10655 break;
10656 }
10657 --p;
10658 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010659 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010660 {
10661 xp->xp_context = EXPAND_BOOL_SETTINGS;
10662 p += 2;
10663 }
10664 if (STRNCMP(p, "inv", 3) == 0)
10665 {
10666 xp->xp_context = EXPAND_BOOL_SETTINGS;
10667 p += 3;
10668 }
10669 xp->xp_pattern = arg = p;
10670 if (*arg == '<')
10671 {
10672 while (*p != '>')
10673 if (*p++ == NUL) /* expand terminal option name */
10674 return;
10675 key = get_special_key_code(arg + 1);
10676 if (key == 0) /* unknown name */
10677 {
10678 xp->xp_context = EXPAND_NOTHING;
10679 return;
10680 }
10681 nextchar = *++p;
10682 is_term_option = TRUE;
10683 expand_option_name[2] = KEY2TERMCAP0(key);
10684 expand_option_name[3] = KEY2TERMCAP1(key);
10685 }
10686 else
10687 {
10688 if (p[0] == 't' && p[1] == '_')
10689 {
10690 p += 2;
10691 if (*p != NUL)
10692 ++p;
10693 if (*p == NUL)
10694 return; /* expand option name */
10695 nextchar = *++p;
10696 is_term_option = TRUE;
10697 expand_option_name[2] = p[-2];
10698 expand_option_name[3] = p[-1];
10699 }
10700 else
10701 {
10702 /* Allow * wildcard */
10703 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10704 p++;
10705 if (*p == NUL)
10706 return;
10707 nextchar = *p;
10708 *p = NUL;
10709 opt_idx = findoption(arg);
10710 *p = nextchar;
10711 if (opt_idx == -1 || options[opt_idx].var == NULL)
10712 {
10713 xp->xp_context = EXPAND_NOTHING;
10714 return;
10715 }
10716 flags = options[opt_idx].flags;
10717 if (flags & P_BOOL)
10718 {
10719 xp->xp_context = EXPAND_NOTHING;
10720 return;
10721 }
10722 }
10723 }
10724 /* handle "-=" and "+=" */
10725 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10726 {
10727 ++p;
10728 nextchar = '=';
10729 }
10730 if ((nextchar != '=' && nextchar != ':')
10731 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10732 {
10733 xp->xp_context = EXPAND_UNSUCCESSFUL;
10734 return;
10735 }
10736 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10737 {
10738 xp->xp_context = EXPAND_OLD_SETTING;
10739 if (is_term_option)
10740 expand_option_idx = -1;
10741 else
10742 expand_option_idx = opt_idx;
10743 xp->xp_pattern = p + 1;
10744 return;
10745 }
10746 xp->xp_context = EXPAND_NOTHING;
10747 if (is_term_option || (flags & P_NUM))
10748 return;
10749
10750 xp->xp_pattern = p + 1;
10751
10752 if (flags & P_EXPAND)
10753 {
10754 p = options[opt_idx].var;
10755 if (p == (char_u *)&p_bdir
10756 || p == (char_u *)&p_dir
10757 || p == (char_u *)&p_path
10758 || p == (char_u *)&p_rtp
10759#ifdef FEAT_SEARCHPATH
10760 || p == (char_u *)&p_cdpath
10761#endif
10762#ifdef FEAT_SESSION
10763 || p == (char_u *)&p_vdir
10764#endif
10765 )
10766 {
10767 xp->xp_context = EXPAND_DIRECTORIES;
10768 if (p == (char_u *)&p_path
10769#ifdef FEAT_SEARCHPATH
10770 || p == (char_u *)&p_cdpath
10771#endif
10772 )
10773 xp->xp_backslash = XP_BS_THREE;
10774 else
10775 xp->xp_backslash = XP_BS_ONE;
10776 }
10777 else
10778 {
10779 xp->xp_context = EXPAND_FILES;
10780 /* for 'tags' need three backslashes for a space */
10781 if (p == (char_u *)&p_tags)
10782 xp->xp_backslash = XP_BS_THREE;
10783 else
10784 xp->xp_backslash = XP_BS_ONE;
10785 }
10786 }
10787
10788 /* For an option that is a list of file names, find the start of the
10789 * last file name. */
10790 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10791 {
10792 /* count number of backslashes before ' ' or ',' */
10793 if (*p == ' ' || *p == ',')
10794 {
10795 s = p;
10796 while (s > xp->xp_pattern && *(s - 1) == '\\')
10797 --s;
10798 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10799 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10800 {
10801 xp->xp_pattern = p + 1;
10802 break;
10803 }
10804 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010805
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010806#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010807 /* for 'spellsuggest' start at "file:" */
10808 if (options[opt_idx].var == (char_u *)&p_sps
10809 && STRNCMP(p, "file:", 5) == 0)
10810 {
10811 xp->xp_pattern = p + 5;
10812 break;
10813 }
10814#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815 }
10816
10817 return;
10818}
10819
10820 int
10821ExpandSettings(xp, regmatch, num_file, file)
10822 expand_T *xp;
10823 regmatch_T *regmatch;
10824 int *num_file;
10825 char_u ***file;
10826{
10827 int num_normal = 0; /* Nr of matching non-term-code settings */
10828 int num_term = 0; /* Nr of matching terminal code settings */
10829 int opt_idx;
10830 int match;
10831 int count = 0;
10832 char_u *str;
10833 int loop;
10834 int is_term_opt;
10835 char_u name_buf[MAX_KEY_NAME_LEN];
10836 static char *(names[]) = {"all", "termcap"};
10837 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10838
10839 /* do this loop twice:
10840 * loop == 0: count the number of matching options
10841 * loop == 1: copy the matching options into allocated memory
10842 */
10843 for (loop = 0; loop <= 1; ++loop)
10844 {
10845 regmatch->rm_ic = ic;
10846 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10847 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010848 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10849 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10851 {
10852 if (loop == 0)
10853 num_normal++;
10854 else
10855 (*file)[count++] = vim_strsave((char_u *)names[match]);
10856 }
10857 }
10858 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10859 opt_idx++)
10860 {
10861 if (options[opt_idx].var == NULL)
10862 continue;
10863 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10864 && !(options[opt_idx].flags & P_BOOL))
10865 continue;
10866 is_term_opt = istermoption(&options[opt_idx]);
10867 if (is_term_opt && num_normal > 0)
10868 continue;
10869 match = FALSE;
10870 if (vim_regexec(regmatch, str, (colnr_T)0)
10871 || (options[opt_idx].shortname != NULL
10872 && vim_regexec(regmatch,
10873 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10874 match = TRUE;
10875 else if (is_term_opt)
10876 {
10877 name_buf[0] = '<';
10878 name_buf[1] = 't';
10879 name_buf[2] = '_';
10880 name_buf[3] = str[2];
10881 name_buf[4] = str[3];
10882 name_buf[5] = '>';
10883 name_buf[6] = NUL;
10884 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10885 {
10886 match = TRUE;
10887 str = name_buf;
10888 }
10889 }
10890 if (match)
10891 {
10892 if (loop == 0)
10893 {
10894 if (is_term_opt)
10895 num_term++;
10896 else
10897 num_normal++;
10898 }
10899 else
10900 (*file)[count++] = vim_strsave(str);
10901 }
10902 }
10903 /*
10904 * Check terminal key codes, these are not in the option table
10905 */
10906 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10907 {
10908 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10909 {
10910 if (!isprint(str[0]) || !isprint(str[1]))
10911 continue;
10912
10913 name_buf[0] = 't';
10914 name_buf[1] = '_';
10915 name_buf[2] = str[0];
10916 name_buf[3] = str[1];
10917 name_buf[4] = NUL;
10918
10919 match = FALSE;
10920 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10921 match = TRUE;
10922 else
10923 {
10924 name_buf[0] = '<';
10925 name_buf[1] = 't';
10926 name_buf[2] = '_';
10927 name_buf[3] = str[0];
10928 name_buf[4] = str[1];
10929 name_buf[5] = '>';
10930 name_buf[6] = NUL;
10931
10932 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10933 match = TRUE;
10934 }
10935 if (match)
10936 {
10937 if (loop == 0)
10938 num_term++;
10939 else
10940 (*file)[count++] = vim_strsave(name_buf);
10941 }
10942 }
10943
10944 /*
10945 * Check special key names.
10946 */
10947 regmatch->rm_ic = TRUE; /* ignore case here */
10948 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10949 {
10950 name_buf[0] = '<';
10951 STRCPY(name_buf + 1, str);
10952 STRCAT(name_buf, ">");
10953
10954 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10955 {
10956 if (loop == 0)
10957 num_term++;
10958 else
10959 (*file)[count++] = vim_strsave(name_buf);
10960 }
10961 }
10962 }
10963 if (loop == 0)
10964 {
10965 if (num_normal > 0)
10966 *num_file = num_normal;
10967 else if (num_term > 0)
10968 *num_file = num_term;
10969 else
10970 return OK;
10971 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
10972 if (*file == NULL)
10973 {
10974 *file = (char_u **)"";
10975 return FAIL;
10976 }
10977 }
10978 }
10979 return OK;
10980}
10981
10982 int
10983ExpandOldSetting(num_file, file)
10984 int *num_file;
10985 char_u ***file;
10986{
10987 char_u *var = NULL; /* init for GCC */
10988 char_u *buf;
10989
10990 *num_file = 0;
10991 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
10992 if (*file == NULL)
10993 return FAIL;
10994
10995 /*
10996 * For a terminal key code expand_option_idx is < 0.
10997 */
10998 if (expand_option_idx < 0)
10999 {
11000 var = find_termcode(expand_option_name + 2);
11001 if (var == NULL)
11002 expand_option_idx = findoption(expand_option_name);
11003 }
11004
11005 if (expand_option_idx >= 0)
11006 {
11007 /* put string of option value in NameBuff */
11008 option_value2string(&options[expand_option_idx], expand_option_flags);
11009 var = NameBuff;
11010 }
11011 else if (var == NULL)
11012 var = (char_u *)"";
11013
11014 /* A backslash is required before some characters. This is the reverse of
11015 * what happens in do_set(). */
11016 buf = vim_strsave_escaped(var, escape_chars);
11017
11018 if (buf == NULL)
11019 {
11020 vim_free(*file);
11021 *file = NULL;
11022 return FAIL;
11023 }
11024
11025#ifdef BACKSLASH_IN_FILENAME
11026 /* For MS-Windows et al. we don't double backslashes at the start and
11027 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011028 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029 if (var[0] == '\\' && var[1] == '\\'
11030 && expand_option_idx >= 0
11031 && (options[expand_option_idx].flags & P_EXPAND)
11032 && vim_isfilec(var[2])
11033 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011034 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035#endif
11036
11037 *file[0] = buf;
11038 *num_file = 1;
11039 return OK;
11040}
11041#endif
11042
11043/*
11044 * Get the value for the numeric or string option *opp in a nice format into
11045 * NameBuff[]. Must not be called with a hidden option!
11046 */
11047 static void
11048option_value2string(opp, opt_flags)
11049 struct vimoption *opp;
11050 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11051{
11052 char_u *varp;
11053
11054 varp = get_varp_scope(opp, opt_flags);
11055
11056 if (opp->flags & P_NUM)
11057 {
11058 long wc = 0;
11059
11060 if (wc_use_keyname(varp, &wc))
11061 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11062 else if (wc != 0)
11063 STRCPY(NameBuff, transchar((int)wc));
11064 else
11065 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11066 }
11067 else /* P_STRING */
11068 {
11069 varp = *(char_u **)(varp);
11070 if (varp == NULL) /* just in case */
11071 NameBuff[0] = NUL;
11072#ifdef FEAT_CRYPT
11073 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011074 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011075 STRCPY(NameBuff, "*****");
11076#endif
11077 else if (opp->flags & P_EXPAND)
11078 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11079 /* Translate 'pastetoggle' into special key names */
11080 else if ((char_u **)opp->var == &p_pt)
11081 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11082 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011083 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011084 }
11085}
11086
11087/*
11088 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11089 * printed as a keyname.
11090 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11091 */
11092 static int
11093wc_use_keyname(varp, wcp)
11094 char_u *varp;
11095 long *wcp;
11096{
11097 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11098 {
11099 *wcp = *(long *)varp;
11100 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11101 return TRUE;
11102 }
11103 return FALSE;
11104}
11105
11106#ifdef FEAT_LANGMAP
11107/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011108 * Any character has an equivalent 'langmap' character. This is used for
11109 * keyboards that have a special language mode that sends characters above
11110 * 128 (although other characters can be translated too). The "to" field is a
11111 * Vim command character. This avoids having to switch the keyboard back to
11112 * ASCII mode when leaving Insert mode.
11113 *
11114 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11115 * commands.
11116 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11117 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11118 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011119 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011120# ifdef FEAT_MBYTE
11121/*
11122 * With multi-byte support use growarray for 'langmap' chars >= 256
11123 */
11124typedef struct
11125{
11126 int from;
11127 int to;
11128} langmap_entry_T;
11129
11130static garray_T langmap_mapga;
11131static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132
11133/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011134 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11135 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011136 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011137 static void
11138langmap_set_entry(from, to)
11139 int from;
11140 int to;
11141{
11142 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011143 int a = 0;
11144 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011145
11146 /* Do a binary search for an existing entry. */
11147 while (a != b)
11148 {
11149 int i = (a + b) / 2;
11150 int d = entries[i].from - from;
11151
11152 if (d == 0)
11153 {
11154 entries[i].to = to;
11155 return;
11156 }
11157 if (d < 0)
11158 a = i + 1;
11159 else
11160 b = i;
11161 }
11162
11163 if (ga_grow(&langmap_mapga, 1) != OK)
11164 return; /* out of memory */
11165
11166 /* insert new entry at position "a" */
11167 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11168 mch_memmove(entries + 1, entries,
11169 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11170 ++langmap_mapga.ga_len;
11171 entries[0].from = from;
11172 entries[0].to = to;
11173}
11174
11175/*
11176 * Apply 'langmap' to multi-byte character "c" and return the result.
11177 */
11178 int
11179langmap_adjust_mb(c)
11180 int c;
11181{
11182 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11183 int a = 0;
11184 int b = langmap_mapga.ga_len;
11185
11186 while (a != b)
11187 {
11188 int i = (a + b) / 2;
11189 int d = entries[i].from - c;
11190
11191 if (d == 0)
11192 return entries[i].to; /* found matching entry */
11193 if (d < 0)
11194 a = i + 1;
11195 else
11196 b = i;
11197 }
11198 return c; /* no entry found, return "c" unmodified */
11199}
11200# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201
11202 static void
11203langmap_init()
11204{
11205 int i;
11206
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011207 for (i = 0; i < 256; i++)
11208 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11209# ifdef FEAT_MBYTE
11210 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11211# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011212}
11213
11214/*
11215 * Called when langmap option is set; the language map can be
11216 * changed at any time!
11217 */
11218 static void
11219langmap_set()
11220{
11221 char_u *p;
11222 char_u *p2;
11223 int from, to;
11224
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011225#ifdef FEAT_MBYTE
11226 ga_clear(&langmap_mapga); /* clear the previous map first */
11227#endif
11228 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229
11230 for (p = p_langmap; p[0] != NUL; )
11231 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011232 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11233 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011234 {
11235 if (p2[0] == '\\' && p2[1] != NUL)
11236 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237 }
11238 if (p2[0] == ';')
11239 ++p2; /* abcd;ABCD form, p2 points to A */
11240 else
11241 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11242 while (p[0])
11243 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011244 if (p[0] == ',')
11245 {
11246 ++p;
11247 break;
11248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249 if (p[0] == '\\' && p[1] != NUL)
11250 ++p;
11251#ifdef FEAT_MBYTE
11252 from = (*mb_ptr2char)(p);
11253#else
11254 from = p[0];
11255#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011256 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011257 if (p2 == NULL)
11258 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011259 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011260 if (p[0] != ',')
11261 {
11262 if (p[0] == '\\')
11263 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011264#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011265 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011267 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011268#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011269 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011270 }
11271 else
11272 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011273 if (p2[0] != ',')
11274 {
11275 if (p2[0] == '\\')
11276 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011278 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011279#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011280 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011281#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011282 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011283 }
11284 if (to == NUL)
11285 {
11286 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11287 transchar(from));
11288 return;
11289 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011290
11291#ifdef FEAT_MBYTE
11292 if (from >= 256)
11293 langmap_set_entry(from, to);
11294 else
11295#endif
11296 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297
11298 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011299 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011300 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011301 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011302 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303 if (*p == ';')
11304 {
11305 p = p2;
11306 if (p[0] != NUL)
11307 {
11308 if (p[0] != ',')
11309 {
11310 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11311 return;
11312 }
11313 ++p;
11314 }
11315 break;
11316 }
11317 }
11318 }
11319 }
11320}
11321#endif
11322
11323/*
11324 * Return TRUE if format option 'x' is in effect.
11325 * Take care of no formatting when 'paste' is set.
11326 */
11327 int
11328has_format_option(x)
11329 int x;
11330{
11331 if (p_paste)
11332 return FALSE;
11333 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11334}
11335
11336/*
11337 * Return TRUE if "x" is present in 'shortmess' option, or
11338 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11339 */
11340 int
11341shortmess(x)
11342 int x;
11343{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011344 return p_shm != NULL &&
11345 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011346 || (vim_strchr(p_shm, 'a') != NULL
11347 && vim_strchr((char_u *)SHM_A, x) != NULL));
11348}
11349
11350/*
11351 * paste_option_changed() - Called after p_paste was set or reset.
11352 */
11353 static void
11354paste_option_changed()
11355{
11356 static int old_p_paste = FALSE;
11357 static int save_sm = 0;
11358#ifdef FEAT_CMDL_INFO
11359 static int save_ru = 0;
11360#endif
11361#ifdef FEAT_RIGHTLEFT
11362 static int save_ri = 0;
11363 static int save_hkmap = 0;
11364#endif
11365 buf_T *buf;
11366
11367 if (p_paste)
11368 {
11369 /*
11370 * Paste switched from off to on.
11371 * Save the current values, so they can be restored later.
11372 */
11373 if (!old_p_paste)
11374 {
11375 /* save options for each buffer */
11376 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11377 {
11378 buf->b_p_tw_nopaste = buf->b_p_tw;
11379 buf->b_p_wm_nopaste = buf->b_p_wm;
11380 buf->b_p_sts_nopaste = buf->b_p_sts;
11381 buf->b_p_ai_nopaste = buf->b_p_ai;
11382 }
11383
11384 /* save global options */
11385 save_sm = p_sm;
11386#ifdef FEAT_CMDL_INFO
11387 save_ru = p_ru;
11388#endif
11389#ifdef FEAT_RIGHTLEFT
11390 save_ri = p_ri;
11391 save_hkmap = p_hkmap;
11392#endif
11393 /* save global values for local buffer options */
11394 p_tw_nopaste = p_tw;
11395 p_wm_nopaste = p_wm;
11396 p_sts_nopaste = p_sts;
11397 p_ai_nopaste = p_ai;
11398 }
11399
11400 /*
11401 * Always set the option values, also when 'paste' is set when it is
11402 * already on.
11403 */
11404 /* set options for each buffer */
11405 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11406 {
11407 buf->b_p_tw = 0; /* textwidth is 0 */
11408 buf->b_p_wm = 0; /* wrapmargin is 0 */
11409 buf->b_p_sts = 0; /* softtabstop is 0 */
11410 buf->b_p_ai = 0; /* no auto-indent */
11411 }
11412
11413 /* set global options */
11414 p_sm = 0; /* no showmatch */
11415#ifdef FEAT_CMDL_INFO
11416# ifdef FEAT_WINDOWS
11417 if (p_ru)
11418 status_redraw_all(); /* redraw to remove the ruler */
11419# endif
11420 p_ru = 0; /* no ruler */
11421#endif
11422#ifdef FEAT_RIGHTLEFT
11423 p_ri = 0; /* no reverse insert */
11424 p_hkmap = 0; /* no Hebrew keyboard */
11425#endif
11426 /* set global values for local buffer options */
11427 p_tw = 0;
11428 p_wm = 0;
11429 p_sts = 0;
11430 p_ai = 0;
11431 }
11432
11433 /*
11434 * Paste switched from on to off: Restore saved values.
11435 */
11436 else if (old_p_paste)
11437 {
11438 /* restore options for each buffer */
11439 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11440 {
11441 buf->b_p_tw = buf->b_p_tw_nopaste;
11442 buf->b_p_wm = buf->b_p_wm_nopaste;
11443 buf->b_p_sts = buf->b_p_sts_nopaste;
11444 buf->b_p_ai = buf->b_p_ai_nopaste;
11445 }
11446
11447 /* restore global options */
11448 p_sm = save_sm;
11449#ifdef FEAT_CMDL_INFO
11450# ifdef FEAT_WINDOWS
11451 if (p_ru != save_ru)
11452 status_redraw_all(); /* redraw to draw the ruler */
11453# endif
11454 p_ru = save_ru;
11455#endif
11456#ifdef FEAT_RIGHTLEFT
11457 p_ri = save_ri;
11458 p_hkmap = save_hkmap;
11459#endif
11460 /* set global values for local buffer options */
11461 p_tw = p_tw_nopaste;
11462 p_wm = p_wm_nopaste;
11463 p_sts = p_sts_nopaste;
11464 p_ai = p_ai_nopaste;
11465 }
11466
11467 old_p_paste = p_paste;
11468}
11469
11470/*
11471 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11472 *
11473 * Reset 'compatible' and set the values for options that didn't get set yet
11474 * to the Vim defaults.
11475 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011476 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011477 */
11478 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011479vimrc_found(fname, envname)
11480 char_u *fname;
11481 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011482{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011483 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011484 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011485 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486
11487 if (!option_was_set((char_u *)"cp"))
11488 {
11489 p_cp = FALSE;
11490 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11491 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11492 set_option_default(opt_idx, OPT_FREE, FALSE);
11493 didset_options();
11494 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011495
11496 if (fname != NULL)
11497 {
11498 p = vim_getenv(envname, &dofree);
11499 if (p == NULL)
11500 {
11501 /* Set $MYVIMRC to the first vimrc file found. */
11502 p = FullName_save(fname, FALSE);
11503 if (p != NULL)
11504 {
11505 vim_setenv(envname, p);
11506 vim_free(p);
11507 }
11508 }
11509 else if (dofree)
11510 vim_free(p);
11511 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011512}
11513
11514/*
11515 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11516 */
11517 void
11518change_compatible(on)
11519 int on;
11520{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011521 int opt_idx;
11522
Bram Moolenaar071d4272004-06-13 20:20:40 +000011523 if (p_cp != on)
11524 {
11525 p_cp = on;
11526 compatible_set();
11527 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011528 opt_idx = findoption((char_u *)"cp");
11529 if (opt_idx >= 0)
11530 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531}
11532
11533/*
11534 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011535 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011536 */
11537 int
11538option_was_set(name)
11539 char_u *name;
11540{
11541 int idx;
11542
11543 idx = findoption(name);
11544 if (idx < 0) /* unknown option */
11545 return FALSE;
11546 if (options[idx].flags & P_WAS_SET)
11547 return TRUE;
11548 return FALSE;
11549}
11550
11551/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011552 * Reset the flag indicating option "name" was set.
11553 */
11554 void
11555reset_option_was_set(name)
11556 char_u *name;
11557{
11558 int idx = findoption(name);
11559
11560 if (idx >= 0)
11561 options[idx].flags &= ~P_WAS_SET;
11562}
11563
11564/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011565 * compatible_set() - Called when 'compatible' has been set or unset.
11566 *
11567 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11568 * flag) to a Vi compatible value.
11569 * When 'compatible' is unset: Set all options that have a different default
11570 * for Vim (without the P_VI_DEF flag) to that default.
11571 */
11572 static void
11573compatible_set()
11574{
11575 int opt_idx;
11576
11577 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11578 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11579 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11580 set_option_default(opt_idx, OPT_FREE, p_cp);
11581 didset_options();
11582}
11583
11584#ifdef FEAT_LINEBREAK
11585
11586# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11587 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011588 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011589# endif
11590
11591/*
11592 * fill_breakat_flags() -- called when 'breakat' changes value.
11593 */
11594 static void
11595fill_breakat_flags()
11596{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011597 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598 int i;
11599
11600 for (i = 0; i < 256; i++)
11601 breakat_flags[i] = FALSE;
11602
11603 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011604 for (p = p_breakat; *p; p++)
11605 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011606}
11607
11608# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011609 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610# endif
11611
11612#endif
11613
11614/*
11615 * Check an option that can be a range of string values.
11616 *
11617 * Return OK for correct value, FAIL otherwise.
11618 * Empty is always OK.
11619 */
11620 static int
11621check_opt_strings(val, values, list)
11622 char_u *val;
11623 char **values;
11624 int list; /* when TRUE: accept a list of values */
11625{
11626 return opt_strings_flags(val, values, NULL, list);
11627}
11628
11629/*
11630 * Handle an option that can be a range of string values.
11631 * Set a flag in "*flagp" for each string present.
11632 *
11633 * Return OK for correct value, FAIL otherwise.
11634 * Empty is always OK.
11635 */
11636 static int
11637opt_strings_flags(val, values, flagp, list)
11638 char_u *val; /* new value */
11639 char **values; /* array of valid string values */
11640 unsigned *flagp;
11641 int list; /* when TRUE: accept a list of values */
11642{
11643 int i;
11644 int len;
11645 unsigned new_flags = 0;
11646
11647 while (*val)
11648 {
11649 for (i = 0; ; ++i)
11650 {
11651 if (values[i] == NULL) /* val not found in values[] */
11652 return FAIL;
11653
11654 len = (int)STRLEN(values[i]);
11655 if (STRNCMP(values[i], val, len) == 0
11656 && ((list && val[len] == ',') || val[len] == NUL))
11657 {
11658 val += len + (val[len] == ',');
11659 new_flags |= (1 << i);
11660 break; /* check next item in val list */
11661 }
11662 }
11663 }
11664 if (flagp != NULL)
11665 *flagp = new_flags;
11666
11667 return OK;
11668}
11669
11670/*
11671 * Read the 'wildmode' option, fill wim_flags[].
11672 */
11673 static int
11674check_opt_wim()
11675{
11676 char_u new_wim_flags[4];
11677 char_u *p;
11678 int i;
11679 int idx = 0;
11680
11681 for (i = 0; i < 4; ++i)
11682 new_wim_flags[i] = 0;
11683
11684 for (p = p_wim; *p; ++p)
11685 {
11686 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11687 ;
11688 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11689 return FAIL;
11690 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11691 new_wim_flags[idx] |= WIM_LONGEST;
11692 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11693 new_wim_flags[idx] |= WIM_FULL;
11694 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11695 new_wim_flags[idx] |= WIM_LIST;
11696 else
11697 return FAIL;
11698 p += i;
11699 if (*p == NUL)
11700 break;
11701 if (*p == ',')
11702 {
11703 if (idx == 3)
11704 return FAIL;
11705 ++idx;
11706 }
11707 }
11708
11709 /* fill remaining entries with last flag */
11710 while (idx < 3)
11711 {
11712 new_wim_flags[idx + 1] = new_wim_flags[idx];
11713 ++idx;
11714 }
11715
11716 /* only when there are no errors, wim_flags[] is changed */
11717 for (i = 0; i < 4; ++i)
11718 wim_flags[i] = new_wim_flags[i];
11719 return OK;
11720}
11721
11722/*
11723 * Check if backspacing over something is allowed.
11724 */
11725 int
11726can_bs(what)
11727 int what; /* BS_INDENT, BS_EOL or BS_START */
11728{
11729 switch (*p_bs)
11730 {
11731 case '2': return TRUE;
11732 case '1': return (what != BS_START);
11733 case '0': return FALSE;
11734 }
11735 return vim_strchr(p_bs, what) != NULL;
11736}
11737
11738/*
11739 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11740 * the file must be considered changed when the value is different.
11741 */
11742 void
11743save_file_ff(buf)
11744 buf_T *buf;
11745{
11746 buf->b_start_ffc = *buf->b_p_ff;
11747 buf->b_start_eol = buf->b_p_eol;
11748#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011749 buf->b_start_bomb = buf->b_p_bomb;
11750
Bram Moolenaar071d4272004-06-13 20:20:40 +000011751 /* Only use free/alloc when necessary, they take time. */
11752 if (buf->b_start_fenc == NULL
11753 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11754 {
11755 vim_free(buf->b_start_fenc);
11756 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11757 }
11758#endif
11759}
11760
11761/*
11762 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11763 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011764 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11765 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011766 * When "ignore_empty" is true don't consider a new, empty buffer to be
11767 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011768 */
11769 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011770file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011772 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011773{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011774 /* In a buffer that was never loaded the options are not valid. */
11775 if (buf->b_flags & BF_NEVERLOADED)
11776 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011777 if (ignore_empty
11778 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779 && buf->b_ml.ml_line_count == 1
11780 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11781 return FALSE;
11782 if (buf->b_start_ffc != *buf->b_p_ff)
11783 return TRUE;
11784 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11785 return TRUE;
11786#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011787 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11788 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011789 if (buf->b_start_fenc == NULL)
11790 return (*buf->b_p_fenc != NUL);
11791 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11792#else
11793 return FALSE;
11794#endif
11795}
11796
11797/*
11798 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11799 */
11800 int
11801check_ff_value(p)
11802 char_u *p;
11803{
11804 return check_opt_strings(p, p_ff_values, FALSE);
11805}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011806
11807/*
11808 * Return the effective shiftwidth value for current buffer, using the
11809 * 'tabstop' value when 'shiftwidth' is zero.
11810 */
11811 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011812get_sw_value(buf)
11813 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011814{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011815 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011816}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011817
11818/*
11819 * Return the effective softtabstop value for the current buffer, using the
11820 * 'tabstop' value when 'softtabstop' is negative.
11821 */
11822 long
11823get_sts_value()
11824{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011825 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011826}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011827
11828/*
11829 * Check matchpairs option for "*initc".
11830 * If there is a match set "*initc" to the matching character and "*findc" to
11831 * the opposite character. Set "*backwards" to the direction.
11832 * When "switchit" is TRUE swap the direction.
11833 */
11834 void
11835find_mps_values(initc, findc, backwards, switchit)
11836 int *initc;
11837 int *findc;
11838 int *backwards;
11839 int switchit;
11840{
11841 char_u *ptr;
11842
11843 ptr = curbuf->b_p_mps;
11844 while (*ptr != NUL)
11845 {
11846#ifdef FEAT_MBYTE
11847 if (has_mbyte)
11848 {
11849 char_u *prev;
11850
11851 if (mb_ptr2char(ptr) == *initc)
11852 {
11853 if (switchit)
11854 {
11855 *findc = *initc;
11856 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11857 *backwards = TRUE;
11858 }
11859 else
11860 {
11861 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11862 *backwards = FALSE;
11863 }
11864 return;
11865 }
11866 prev = ptr;
11867 ptr += mb_ptr2len(ptr) + 1;
11868 if (mb_ptr2char(ptr) == *initc)
11869 {
11870 if (switchit)
11871 {
11872 *findc = *initc;
11873 *initc = mb_ptr2char(prev);
11874 *backwards = FALSE;
11875 }
11876 else
11877 {
11878 *findc = mb_ptr2char(prev);
11879 *backwards = TRUE;
11880 }
11881 return;
11882 }
11883 ptr += mb_ptr2len(ptr);
11884 }
11885 else
11886#endif
11887 {
11888 if (*ptr == *initc)
11889 {
11890 if (switchit)
11891 {
11892 *backwards = TRUE;
11893 *findc = *initc;
11894 *initc = ptr[2];
11895 }
11896 else
11897 {
11898 *backwards = FALSE;
11899 *findc = ptr[2];
11900 }
11901 return;
11902 }
11903 ptr += 2;
11904 if (*ptr == *initc)
11905 {
11906 if (switchit)
11907 {
11908 *backwards = FALSE;
11909 *findc = *initc;
11910 *initc = ptr[-2];
11911 }
11912 else
11913 {
11914 *backwards = TRUE;
11915 *findc = ptr[-2];
11916 }
11917 return;
11918 }
11919 ++ptr;
11920 }
11921 if (*ptr == ',')
11922 ++ptr;
11923 }
11924}