blob: b1c888d8ca818da6fa5464b82597c88e676e7c25 [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,
1632#ifdef FEAT_VISUAL
1633 (char_u *)&p_km, PV_NONE,
1634#else
1635 (char_u *)NULL, PV_NONE,
1636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001639 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640 {
1641#if defined(MSDOS) || defined(MSWIN)
1642 (char_u *)":help",
1643#else
1644#ifdef VMS
1645 (char_u *)"help",
1646#else
1647# if defined(OS2)
1648 (char_u *)"view /",
1649# else
1650# ifdef USEMAN_S
1651 (char_u *)"man -s",
1652# else
1653 (char_u *)"man",
1654# endif
1655# endif
1656#endif
1657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1660#ifdef FEAT_LANGMAP
1661 (char_u *)&p_langmap, PV_NONE,
1662 {(char_u *)"", /* unmatched } */
1663#else
1664 (char_u *)NULL, PV_NONE,
1665 {(char_u *)NULL,
1666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001668 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1670 (char_u *)&p_lm, PV_NONE,
1671#else
1672 (char_u *)NULL, PV_NONE,
1673#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001674 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1676#ifdef FEAT_WINDOWS
1677 (char_u *)&p_ls, PV_NONE,
1678#else
1679 (char_u *)NULL, PV_NONE,
1680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1683 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001684 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1686#ifdef FEAT_LINEBREAK
1687 (char_u *)VAR_WIN, PV_LBR,
1688#else
1689 (char_u *)NULL, PV_NONE,
1690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001691 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1693 (char_u *)&Rows, PV_NONE,
1694 {
1695#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1696 (char_u *)25L,
1697#else
1698 (char_u *)24L,
1699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1702#ifdef FEAT_GUI
1703 (char_u *)&p_linespace, PV_NONE,
1704#else
1705 (char_u *)NULL, PV_NONE,
1706#endif
1707#ifdef FEAT_GUI_W32
1708 {(char_u *)1L, (char_u *)0L}
1709#else
1710 {(char_u *)0L, (char_u *)0L}
1711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 {"lisp", NULL, P_BOOL|P_VI_DEF,
1714#ifdef FEAT_LISP
1715 (char_u *)&p_lisp, PV_LISP,
1716#else
1717 (char_u *)NULL, PV_NONE,
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1721#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001722 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1724#else
1725 (char_u *)NULL, PV_NONE,
1726 {(char_u *)"", (char_u *)0L}
1727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1730 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1733 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001734 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1736 (char_u *)&p_lpl, 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#ifdef FEAT_GUI_MAC
1739 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1740 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001742#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {"magic", NULL, P_BOOL|P_VI_DEF,
1744 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001746 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747#ifdef FEAT_QUICKFIX
1748 (char_u *)&p_mef, PV_NONE,
1749 {(char_u *)"", (char_u *)0L}
1750#else
1751 (char_u *)NULL, PV_NONE,
1752 {(char_u *)NULL, (char_u *)0L}
1753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1756#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001757 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758# ifdef VMS
1759 {(char_u *)"MMS", (char_u *)0L}
1760# else
1761 {(char_u *)"make", (char_u *)0L}
1762# endif
1763#else
1764 (char_u *)NULL, PV_NONE,
1765 {(char_u *)NULL, (char_u *)0L}
1766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1769 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1771 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"matchtime", "mat", P_NUM|P_VI_DEF,
1773 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001775 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001776#ifdef FEAT_MBYTE
1777 (char_u *)&p_mco, PV_NONE,
1778#else
1779 (char_u *)NULL, PV_NONE,
1780#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001781 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1783#ifdef FEAT_EVAL
1784 (char_u *)&p_mfd, PV_NONE,
1785#else
1786 (char_u *)NULL, PV_NONE,
1787#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1790 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 {"maxmem", "mm", P_NUM|P_VI_DEF,
1793 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1795 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001796 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1797 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001798 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1800 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1802 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"menuitems", "mis", P_NUM|P_VI_DEF,
1804#ifdef FEAT_MENU
1805 (char_u *)&p_mis, PV_NONE,
1806#else
1807 (char_u *)NULL, PV_NONE,
1808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 {"mesg", NULL, P_BOOL|P_VI_DEF,
1811 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001813 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001814#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001815 (char_u *)&p_msm, PV_NONE,
1816 {(char_u *)"460000,2000,500", (char_u *)0L}
1817#else
1818 (char_u *)NULL, PV_NONE,
1819 {(char_u *)0L, (char_u *)0L}
1820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"modeline", "ml", P_BOOL|P_VIM,
1823 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"modelines", "mls", P_NUM|P_VI_DEF,
1826 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1829 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1832 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001833 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834 {"more", NULL, P_BOOL|P_VIM,
1835 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001836 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1838 (char_u *)&p_mouse, PV_NONE,
1839 {
1840#if defined(MSDOS) || defined(WIN3264)
1841 (char_u *)"a",
1842#else
1843 (char_u *)"",
1844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1847#ifdef FEAT_GUI
1848 (char_u *)&p_mousef, PV_NONE,
1849#else
1850 (char_u *)NULL, PV_NONE,
1851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1854#ifdef FEAT_GUI
1855 (char_u *)&p_mh, PV_NONE,
1856#else
1857 (char_u *)NULL, PV_NONE,
1858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1861 (char_u *)&p_mousem, PV_NONE,
1862 {
1863#if defined(MSDOS) || defined(MSWIN)
1864 (char_u *)"popup",
1865#else
1866# if defined(MACOS)
1867 (char_u *)"popup_setpos",
1868# else
1869 (char_u *)"extend",
1870# endif
1871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1874#ifdef FEAT_MOUSESHAPE
1875 (char_u *)&p_mouseshape, PV_NONE,
1876 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1877#else
1878 (char_u *)NULL, PV_NONE,
1879 {(char_u *)NULL, (char_u *)0L}
1880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1883 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001884 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001885 {"mzquantum", "mzq", P_NUM,
1886#ifdef FEAT_MZSCHEME
1887 (char_u *)&p_mzq, PV_NONE,
1888#else
1889 (char_u *)NULL, PV_NONE,
1890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 {"novice", NULL, P_BOOL|P_VI_DEF,
1893 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001894 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1896 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001897 {(char_u *)"octal,hex", (char_u *)0L}
1898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1900 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001902 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1903#ifdef FEAT_LINEBREAK
1904 (char_u *)VAR_WIN, PV_NUW,
1905#else
1906 (char_u *)NULL, PV_NONE,
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001909 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001910#ifdef FEAT_COMPL_FUNC
1911 (char_u *)&p_ofu, PV_OFU,
1912 {(char_u *)"", (char_u *)0L}
1913#else
1914 (char_u *)NULL, PV_NONE,
1915 {(char_u *)0L, (char_u *)0L}
1916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"open", NULL, P_BOOL|P_VI_DEF,
1919 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001921 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1922#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1923 (char_u *)&p_odev, PV_NONE,
1924#else
1925 (char_u *)NULL, PV_NONE,
1926#endif
1927 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001929 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1930 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 {"optimize", "opt", P_BOOL|P_VI_DEF,
1933 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"paragraphs", "para", P_STRING|P_VI_DEF,
1939 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001940 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001942 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1946 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1949#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1950 (char_u *)&p_pex, PV_NONE,
1951 {(char_u *)"", (char_u *)0L}
1952#else
1953 (char_u *)NULL, PV_NONE,
1954 {(char_u *)0L, (char_u *)0L}
1955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001957 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001960 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001961 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {
1963#if defined AMIGA || defined MSDOS || defined MSWIN
1964 (char_u *)".,,",
1965#else
1966# if defined(__EMX__)
1967 (char_u *)".,/emx/include,,",
1968# else /* Unix, probably */
1969 (char_u *)".,/usr/include,,",
1970# endif
1971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1974 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001976 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1978 (char_u *)&p_pvh, PV_NONE,
1979#else
1980 (char_u *)NULL, PV_NONE,
1981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1984#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1985 (char_u *)VAR_WIN, PV_PVW,
1986#else
1987 (char_u *)NULL, PV_NONE,
1988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001990 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991#ifdef FEAT_PRINTER
1992 (char_u *)&p_pdev, PV_NONE,
1993 {(char_u *)"", (char_u *)0L}
1994#else
1995 (char_u *)NULL, PV_NONE,
1996 {(char_u *)NULL, (char_u *)0L}
1997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"printencoding", "penc", P_STRING|P_VI_DEF,
2000#ifdef FEAT_POSTSCRIPT
2001 (char_u *)&p_penc, PV_NONE,
2002 {(char_u *)"", (char_u *)0L}
2003#else
2004 (char_u *)NULL, PV_NONE,
2005 {(char_u *)NULL, (char_u *)0L}
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2009#ifdef FEAT_POSTSCRIPT
2010 (char_u *)&p_pexpr, PV_NONE,
2011 {(char_u *)"", (char_u *)0L}
2012#else
2013 (char_u *)NULL, PV_NONE,
2014 {(char_u *)NULL, (char_u *)0L}
2015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 {"printfont", "pfn", P_STRING|P_VI_DEF,
2018#ifdef FEAT_PRINTER
2019 (char_u *)&p_pfn, PV_NONE,
2020 {
2021# ifdef MSWIN
2022 (char_u *)"Courier_New:h10",
2023# else
2024 (char_u *)"courier",
2025# endif
2026 (char_u *)0L}
2027#else
2028 (char_u *)NULL, PV_NONE,
2029 {(char_u *)NULL, (char_u *)0L}
2030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002031 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2033#ifdef FEAT_PRINTER
2034 (char_u *)&p_header, PV_NONE,
2035 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2036#else
2037 (char_u *)NULL, PV_NONE,
2038 {(char_u *)NULL, (char_u *)0L}
2039#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002040 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002041 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2042#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2043 (char_u *)&p_pmcs, PV_NONE,
2044 {(char_u *)"", (char_u *)0L}
2045#else
2046 (char_u *)NULL, PV_NONE,
2047 {(char_u *)NULL, (char_u *)0L}
2048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002050 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2051#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2052 (char_u *)&p_pmfn, PV_NONE,
2053 {(char_u *)"", (char_u *)0L}
2054#else
2055 (char_u *)NULL, PV_NONE,
2056 {(char_u *)NULL, (char_u *)0L}
2057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2060#ifdef FEAT_PRINTER
2061 (char_u *)&p_popt, PV_NONE,
2062 {(char_u *)"", (char_u *)0L}
2063#else
2064 (char_u *)NULL, PV_NONE,
2065 {(char_u *)NULL, (char_u *)0L}
2066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002067 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002068 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002069 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002070 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002071 {"pumheight", "ph", P_NUM|P_VI_DEF,
2072#ifdef FEAT_INS_EXPAND
2073 (char_u *)&p_ph, PV_NONE,
2074#else
2075 (char_u *)NULL, PV_NONE,
2076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002078 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2079#ifdef FEAT_TEXTOBJ
2080 (char_u *)&p_qe, PV_QE,
2081 {(char_u *)"\\", (char_u *)0L}
2082#else
2083 (char_u *)NULL, PV_NONE,
2084 {(char_u *)NULL, (char_u *)0L}
2085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2088 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090 {"redraw", NULL, P_BOOL|P_VI_DEF,
2091 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002093 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2094#ifdef FEAT_RELTIME
2095 (char_u *)&p_rdt, PV_NONE,
2096#else
2097 (char_u *)NULL, PV_NONE,
2098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002099 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002100 {"regexpengine", "re", P_NUM|P_VI_DEF,
2101 (char_u *)&p_re, PV_NONE,
2102 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002103 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2104 (char_u *)VAR_WIN, PV_RNU,
2105 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {"remap", NULL, P_BOOL|P_VI_DEF,
2107 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 {"report", NULL, P_NUM|P_VI_DEF,
2110 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002112 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2113#ifdef WIN3264
2114 (char_u *)&p_rs, PV_NONE,
2115#else
2116 (char_u *)NULL, PV_NONE,
2117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2120#ifdef FEAT_RIGHTLEFT
2121 (char_u *)&p_ri, PV_NONE,
2122#else
2123 (char_u *)NULL, PV_NONE,
2124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2127#ifdef FEAT_RIGHTLEFT
2128 (char_u *)VAR_WIN, PV_RL,
2129#else
2130 (char_u *)NULL, PV_NONE,
2131#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002132 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2134#ifdef FEAT_RIGHTLEFT
2135 (char_u *)VAR_WIN, PV_RLC,
2136 {(char_u *)"search", (char_u *)NULL}
2137#else
2138 (char_u *)NULL, PV_NONE,
2139 {(char_u *)NULL, (char_u *)0L}
2140#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002141 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2143#ifdef FEAT_CMDL_INFO
2144 (char_u *)&p_ru, PV_NONE,
2145#else
2146 (char_u *)NULL, PV_NONE,
2147#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2150#ifdef FEAT_STL_OPT
2151 (char_u *)&p_ruf, PV_NONE,
2152#else
2153 (char_u *)NULL, PV_NONE,
2154#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002155 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2157 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002158 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2159 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2161 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002162 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002163 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2164#ifdef FEAT_SCROLLBIND
2165 (char_u *)VAR_WIN, PV_SCBIND,
2166#else
2167 (char_u *)NULL, PV_NONE,
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2171 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002172 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002173 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2174 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002175 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2177#ifdef FEAT_SCROLLBIND
2178 (char_u *)&p_sbo, PV_NONE,
2179 {(char_u *)"ver,jump", (char_u *)0L}
2180#else
2181 (char_u *)NULL, PV_NONE,
2182 {(char_u *)0L, (char_u *)0L}
2183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002184 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 {"sections", "sect", P_STRING|P_VI_DEF,
2186 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2188 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2190 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002191 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192 {"selection", "sel", P_STRING|P_VI_DEF,
2193#ifdef FEAT_VISUAL
2194 (char_u *)&p_sel, PV_NONE,
2195#else
2196 (char_u *)NULL, PV_NONE,
2197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002198 {(char_u *)"inclusive", (char_u *)0L}
2199 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2201#ifdef FEAT_VISUAL
2202 (char_u *)&p_slm, PV_NONE,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002206 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2208#ifdef FEAT_SESSION
2209 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002210 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 (char_u *)0L}
2212#else
2213 (char_u *)NULL, PV_NONE,
2214 {(char_u *)0L, (char_u *)0L}
2215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2218 (char_u *)&p_sh, PV_NONE,
2219 {
2220#ifdef VMS
2221 (char_u *)"-",
2222#else
2223# if defined(MSDOS)
2224 (char_u *)"command",
2225# else
2226# if defined(WIN16)
2227 (char_u *)"command.com",
2228# else
2229# if defined(WIN3264)
2230 (char_u *)"", /* set in set_init_1() */
2231# else
2232# if defined(OS2)
2233 (char_u *)"cmd.exe",
2234# else
2235# if defined(ARCHIE)
2236 (char_u *)"gos",
2237# else
2238 (char_u *)"sh",
2239# endif
2240# endif
2241# endif
2242# endif
2243# endif
2244#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002245 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2247 (char_u *)&p_shcf, PV_NONE,
2248 {
2249#if defined(MSDOS) || defined(MSWIN)
2250 (char_u *)"/c",
2251#else
2252# if defined(OS2)
2253 (char_u *)"/c",
2254# else
2255 (char_u *)"-c",
2256# endif
2257#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002258 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002259 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2260#ifdef FEAT_QUICKFIX
2261 (char_u *)&p_sp, PV_NONE,
2262 {
2263#if defined(UNIX) || defined(OS2)
2264# ifdef ARCHIE
2265 (char_u *)"2>",
2266# else
2267 (char_u *)"| tee",
2268# endif
2269#else
2270 (char_u *)">",
2271#endif
2272 (char_u *)0L}
2273#else
2274 (char_u *)NULL, PV_NONE,
2275 {(char_u *)0L, (char_u *)0L}
2276#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002277 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2279 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2282 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2285#ifdef BACKSLASH_IN_FILENAME
2286 (char_u *)&p_ssl, PV_NONE,
2287#else
2288 (char_u *)NULL, PV_NONE,
2289#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002291 {"shelltemp", "stmp", P_BOOL,
2292 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002293 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294 {"shelltype", "st", P_NUM|P_VI_DEF,
2295#ifdef AMIGA
2296 (char_u *)&p_st, PV_NONE,
2297#else
2298 (char_u *)NULL, PV_NONE,
2299#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002300 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2302 (char_u *)&p_sxq, PV_NONE,
2303 {
2304#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2305 (char_u *)"\"",
2306#else
2307 (char_u *)"",
2308#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002310 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2311 (char_u *)&p_sxe, PV_NONE,
2312 {
2313#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2314 (char_u *)"\"&|<>()@^",
2315#else
2316 (char_u *)"",
2317#endif
2318 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2320 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2323 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2326 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)"", (char_u *)"filnxtToO"}
2328 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"shortname", "sn", P_BOOL|P_VI_DEF,
2330#ifdef SHORT_FNAME
2331 (char_u *)NULL, PV_NONE,
2332#else
2333 (char_u *)&p_sn, PV_SN,
2334#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2337#ifdef FEAT_LINEBREAK
2338 (char_u *)&p_sbr, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"showcmd", "sc", P_BOOL|P_VIM,
2344#ifdef FEAT_CMDL_INFO
2345 (char_u *)&p_sc, PV_NONE,
2346#else
2347 (char_u *)NULL, PV_NONE,
2348#endif
2349 {(char_u *)FALSE,
2350#ifdef UNIX
2351 (char_u *)FALSE
2352#else
2353 (char_u *)TRUE
2354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2357 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2360 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"showmode", "smd", P_BOOL|P_VIM,
2363 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002365 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2366#ifdef FEAT_WINDOWS
2367 (char_u *)&p_stal, PV_NONE,
2368#else
2369 (char_u *)NULL, PV_NONE,
2370#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2373 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2376 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2379 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2382 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002383 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2385#ifdef FEAT_SMARTINDENT
2386 (char_u *)&p_si, PV_SI,
2387#else
2388 (char_u *)NULL, PV_NONE,
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2392 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2395 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2398 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002400 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002401#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002402 (char_u *)VAR_WIN, PV_SPELL,
2403#else
2404 (char_u *)NULL, PV_NONE,
2405#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002407 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002408#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002409 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002410 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002411#else
2412 (char_u *)NULL, PV_NONE,
2413 {(char_u *)0L, (char_u *)0L}
2414#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002416 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002417#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002418 (char_u *)&p_spf, PV_SPF,
2419 {(char_u *)"", (char_u *)0L}
2420#else
2421 (char_u *)NULL, PV_NONE,
2422 {(char_u *)0L, (char_u *)0L}
2423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002424 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002425 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002426#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002427 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002428 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002429#else
2430 (char_u *)NULL, PV_NONE,
2431 {(char_u *)0L, (char_u *)0L}
2432#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002433 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002434 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002435#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002436 (char_u *)&p_sps, PV_NONE,
2437 {(char_u *)"best", (char_u *)0L}
2438#else
2439 (char_u *)NULL, PV_NONE,
2440 {(char_u *)0L, (char_u *)0L}
2441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2444#ifdef FEAT_WINDOWS
2445 (char_u *)&p_sb, PV_NONE,
2446#else
2447 (char_u *)NULL, PV_NONE,
2448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"splitright", "spr", P_BOOL|P_VI_DEF,
2451#ifdef FEAT_VERTSPLIT
2452 (char_u *)&p_spr, PV_NONE,
2453#else
2454 (char_u *)NULL, PV_NONE,
2455#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2458 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2461#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002462 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2468 (char_u *)&p_su, PV_NONE,
2469 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002472#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 (char_u *)&p_sua, PV_SUA,
2474 {(char_u *)"", (char_u *)0L}
2475#else
2476 (char_u *)NULL, PV_NONE,
2477 {(char_u *)0L, (char_u *)0L}
2478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2481 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"swapsync", "sws", P_STRING|P_VI_DEF,
2484 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2487 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002488 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002489 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2490#ifdef FEAT_SYN_HL
2491 (char_u *)&p_smc, PV_SMC,
2492 {(char_u *)3000L, (char_u *)0L}
2493#else
2494 (char_u *)NULL, PV_NONE,
2495 {(char_u *)0L, (char_u *)0L}
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002498 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499#ifdef FEAT_SYN_HL
2500 (char_u *)&p_syn, PV_SYN,
2501 {(char_u *)"", (char_u *)0L}
2502#else
2503 (char_u *)NULL, PV_NONE,
2504 {(char_u *)0L, (char_u *)0L}
2505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002507 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2508#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002509 (char_u *)&p_tal, PV_NONE,
2510#else
2511 (char_u *)NULL, PV_NONE,
2512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002513 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002514 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2515#ifdef FEAT_WINDOWS
2516 (char_u *)&p_tpm, PV_NONE,
2517#else
2518 (char_u *)NULL, PV_NONE,
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2522 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2525 (char_u *)&p_tbs, PV_NONE,
2526#ifdef VMS /* binary searching doesn't appear to work on VMS */
2527 {(char_u *)0L, (char_u *)0L}
2528#else
2529 {(char_u *)TRUE, (char_u *)0L}
2530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"taglength", "tl", P_NUM|P_VI_DEF,
2533 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"tagrelative", "tr", P_BOOL|P_VIM,
2536 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002539 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {
2541#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2542 (char_u *)"./tags,./TAGS,tags,TAGS",
2543#else
2544 (char_u *)"./tags,tags",
2545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2548 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002549 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2551 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2554#ifdef FEAT_ARABIC
2555 (char_u *)&p_tbidi, PV_NONE,
2556#else
2557 (char_u *)NULL, PV_NONE,
2558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2561#ifdef FEAT_MBYTE
2562 (char_u *)&p_tenc, PV_NONE,
2563 {(char_u *)"", (char_u *)0L}
2564#else
2565 (char_u *)NULL, PV_NONE,
2566 {(char_u *)0L, (char_u *)0L}
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"terse", NULL, P_BOOL|P_VI_DEF,
2570 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"textauto", "ta", P_BOOL|P_VIM,
2573 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2575 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2577 (char_u *)&p_tx, PV_TX,
2578 {
2579#ifdef USE_CRNL
2580 (char_u *)TRUE,
2581#else
2582 (char_u *)FALSE,
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002585 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2589#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002590 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591#else
2592 (char_u *)NULL, PV_NONE,
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2596 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {"timeout", "to", P_BOOL|P_VI_DEF,
2599 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2602 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"title", NULL, P_BOOL|P_VI_DEF,
2605#ifdef FEAT_TITLE
2606 (char_u *)&p_title, PV_NONE,
2607#else
2608 (char_u *)NULL, PV_NONE,
2609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 {"titlelen", NULL, P_NUM|P_VI_DEF,
2612#ifdef FEAT_TITLE
2613 (char_u *)&p_titlelen, PV_NONE,
2614#else
2615 (char_u *)NULL, PV_NONE,
2616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002618 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619#ifdef FEAT_TITLE
2620 (char_u *)&p_titleold, PV_NONE,
2621 {(char_u *)N_("Thanks for flying Vim"),
2622 (char_u *)0L}
2623#else
2624 (char_u *)NULL, PV_NONE,
2625 {(char_u *)0L, (char_u *)0L}
2626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"titlestring", NULL, P_STRING|P_VI_DEF,
2629#ifdef FEAT_TITLE
2630 (char_u *)&p_titlestring, PV_NONE,
2631#else
2632 (char_u *)NULL, PV_NONE,
2633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2636 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2637 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002638 {(char_u *)"icons,tooltips", (char_u *)0L}
2639 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002641#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2643 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645#endif
2646 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2647 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2650 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2653 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2656 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2659#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2660 (char_u *)&p_ttym, PV_NONE,
2661#else
2662 (char_u *)NULL, PV_NONE,
2663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2666 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2669 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002671 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2672#ifdef FEAT_PERSISTENT_UNDO
2673 (char_u *)&p_udir, PV_NONE,
2674 {(char_u *)".", (char_u *)0L}
2675#else
2676 (char_u *)NULL, PV_NONE,
2677 {(char_u *)0L, (char_u *)0L}
2678#endif
2679 SCRIPTID_INIT},
2680 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2681#ifdef FEAT_PERSISTENT_UNDO
2682 (char_u *)&p_udf, PV_UDF,
2683#else
2684 (char_u *)NULL, PV_NONE,
2685#endif
2686 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002688 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 {
2690#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2691 (char_u *)1000L,
2692#else
2693 (char_u *)100L,
2694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002696 {"undoreload", "ur", P_NUM|P_VI_DEF,
2697 (char_u *)&p_ur, PV_NONE,
2698 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"updatecount", "uc", P_NUM|P_VI_DEF,
2700 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"updatetime", "ut", P_NUM|P_VI_DEF,
2703 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"verbose", "vbs", P_NUM|P_VI_DEF,
2706 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002708 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2709 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2712#ifdef FEAT_SESSION
2713 (char_u *)&p_vdir, PV_NONE,
2714 {(char_u *)DFLT_VDIR, (char_u *)0L}
2715#else
2716 (char_u *)NULL, PV_NONE,
2717 {(char_u *)0L, (char_u *)0L}
2718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2721#ifdef FEAT_SESSION
2722 (char_u *)&p_vop, PV_NONE,
2723 {(char_u *)"folds,options,cursor", (char_u *)0L}
2724#else
2725 (char_u *)NULL, PV_NONE,
2726 {(char_u *)0L, (char_u *)0L}
2727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2730#ifdef FEAT_VIMINFO
2731 (char_u *)&p_viminfo, PV_NONE,
2732#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002733 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734#else
2735# ifdef AMIGA
2736 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002737 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002739 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740# endif
2741#endif
2742#else
2743 (char_u *)NULL, PV_NONE,
2744 {(char_u *)0L, (char_u *)0L}
2745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002747 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748#ifdef FEAT_VIRTUALEDIT
2749 (char_u *)&p_ve, PV_NONE,
2750 {(char_u *)"", (char_u *)""}
2751#else
2752 (char_u *)NULL, PV_NONE,
2753 {(char_u *)0L, (char_u *)0L}
2754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2757 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"w300", NULL, P_NUM|P_VI_DEF,
2760 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"w1200", NULL, P_NUM|P_VI_DEF,
2763 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"w9600", NULL, P_NUM|P_VI_DEF,
2766 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"warn", NULL, P_BOOL|P_VI_DEF,
2769 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2772 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2775 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"wildchar", "wc", P_NUM|P_VIM,
2778 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002779 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2780 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002781 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2785#ifdef FEAT_WILDIGN
2786 (char_u *)&p_wig, PV_NONE,
2787#else
2788 (char_u *)NULL, PV_NONE,
2789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002790 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002791 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2792 (char_u *)&p_wic, PV_NONE,
2793 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2795#ifdef FEAT_WILDMENU
2796 (char_u *)&p_wmnu, PV_NONE,
2797#else
2798 (char_u *)NULL, PV_NONE,
2799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2802 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002803 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002804 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2805#ifdef FEAT_CMDL_COMPL
2806 (char_u *)&p_wop, PV_NONE,
2807 {(char_u *)"", (char_u *)0L}
2808#else
2809 (char_u *)NULL, PV_NONE,
2810 {(char_u *)NULL, (char_u *)0L}
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2814#ifdef FEAT_WAK
2815 (char_u *)&p_wak, PV_NONE,
2816 {(char_u *)"menu", (char_u *)0L}
2817#else
2818 (char_u *)NULL, PV_NONE,
2819 {(char_u *)NULL, (char_u *)0L}
2820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002823 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"winheight", "wh", P_NUM|P_VI_DEF,
2826#ifdef FEAT_WINDOWS
2827 (char_u *)&p_wh, PV_NONE,
2828#else
2829 (char_u *)NULL, PV_NONE,
2830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002833#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 (char_u *)VAR_WIN, PV_WFH,
2835#else
2836 (char_u *)NULL, PV_NONE,
2837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002839 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2840#ifdef FEAT_VERTSPLIT
2841 (char_u *)VAR_WIN, PV_WFW,
2842#else
2843 (char_u *)NULL, PV_NONE,
2844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2847#ifdef FEAT_WINDOWS
2848 (char_u *)&p_wmh, PV_NONE,
2849#else
2850 (char_u *)NULL, PV_NONE,
2851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2854#ifdef FEAT_VERTSPLIT
2855 (char_u *)&p_wmw, PV_NONE,
2856#else
2857 (char_u *)NULL, PV_NONE,
2858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2861#ifdef FEAT_VERTSPLIT
2862 (char_u *)&p_wiw, PV_NONE,
2863#else
2864 (char_u *)NULL, PV_NONE,
2865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2868 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2871 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2874 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"write", NULL, P_BOOL|P_VI_DEF,
2877 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"writeany", "wa", P_BOOL|P_VI_DEF,
2880 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2883 (char_u *)&p_wb, PV_NONE,
2884 {
2885#ifdef FEAT_WRITEBACKUP
2886 (char_u *)TRUE,
2887#else
2888 (char_u *)FALSE,
2889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"writedelay", "wd", P_NUM|P_VI_DEF,
2892 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894
2895/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002896#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899
2900 p_term("t_AB", T_CAB)
2901 p_term("t_AF", T_CAF)
2902 p_term("t_AL", T_CAL)
2903 p_term("t_al", T_AL)
2904 p_term("t_bc", T_BC)
2905 p_term("t_cd", T_CD)
2906 p_term("t_ce", T_CE)
2907 p_term("t_cl", T_CL)
2908 p_term("t_cm", T_CM)
2909 p_term("t_Co", T_CCO)
2910 p_term("t_CS", T_CCS)
2911 p_term("t_cs", T_CS)
2912#ifdef FEAT_VERTSPLIT
2913 p_term("t_CV", T_CSV)
2914#endif
2915 p_term("t_ut", T_UT)
2916 p_term("t_da", T_DA)
2917 p_term("t_db", T_DB)
2918 p_term("t_DL", T_CDL)
2919 p_term("t_dl", T_DL)
2920 p_term("t_fs", T_FS)
2921 p_term("t_IE", T_CIE)
2922 p_term("t_IS", T_CIS)
2923 p_term("t_ke", T_KE)
2924 p_term("t_ks", T_KS)
2925 p_term("t_le", T_LE)
2926 p_term("t_mb", T_MB)
2927 p_term("t_md", T_MD)
2928 p_term("t_me", T_ME)
2929 p_term("t_mr", T_MR)
2930 p_term("t_ms", T_MS)
2931 p_term("t_nd", T_ND)
2932 p_term("t_op", T_OP)
2933 p_term("t_RI", T_CRI)
2934 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002935 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 p_term("t_Sb", T_CSB)
2937 p_term("t_Sf", T_CSF)
2938 p_term("t_se", T_SE)
2939 p_term("t_so", T_SO)
2940 p_term("t_sr", T_SR)
2941 p_term("t_ts", T_TS)
2942 p_term("t_te", T_TE)
2943 p_term("t_ti", T_TI)
2944 p_term("t_ue", T_UE)
2945 p_term("t_us", T_US)
2946 p_term("t_vb", T_VB)
2947 p_term("t_ve", T_VE)
2948 p_term("t_vi", T_VI)
2949 p_term("t_vs", T_VS)
2950 p_term("t_WP", T_CWP)
2951 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002952 p_term("t_SI", T_CSI)
2953 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 p_term("t_xs", T_XS)
2955 p_term("t_ZH", T_CZH)
2956 p_term("t_ZR", T_CZR)
2957
2958/* terminal key codes are not in here */
2959
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 /* end marker */
2961 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962};
2963
2964#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2965
2966#ifdef FEAT_MBYTE
2967static char *(p_ambw_values[]) = {"single", "double", NULL};
2968#endif
2969static char *(p_bg_values[]) = {"light", "dark", NULL};
2970static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2971static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002972#ifdef FEAT_CRYPT
2973static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2974#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002975#ifdef FEAT_CMDL_COMPL
2976static char *(p_wop_values[]) = {"tagfile", NULL};
2977#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978#ifdef FEAT_WAK
2979static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2980#endif
2981static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2982#ifdef FEAT_VISUAL
2983static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2984static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2985#endif
2986#ifdef FEAT_VISUAL
2987static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2988#endif
2989#ifdef FEAT_BROWSE
2990static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2991#endif
2992#ifdef FEAT_SCROLLBIND
2993static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2994#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002995static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996#ifdef FEAT_VERTSPLIT
2997static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2998#endif
2999#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003000# ifdef FEAT_AUTOCMD
3001static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3002# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003004# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3006#endif
3007static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3008#ifdef FEAT_FOLDING
3009static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003010# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003012# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 NULL};
3014static char *(p_fcl_values[]) = {"all", NULL};
3015#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003016#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003017static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003018#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019
3020static void set_option_default __ARGS((int, int opt_flags, int compatible));
3021static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003022static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003023static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024static char_u *illegal_char __ARGS((char_u *, int));
3025static int string_to_key __ARGS((char_u *arg));
3026#ifdef FEAT_CMDWIN
3027static char_u *check_cedit __ARGS((void));
3028#endif
3029#ifdef FEAT_TITLE
3030static void did_set_title __ARGS((int icon));
3031#endif
3032static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3033static void didset_options __ARGS((void));
3034static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003035#if defined(FEAT_EVAL) || defined(PROTO)
3036static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3037#else
3038# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003041static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042static 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));
3043static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003044#ifdef FEAT_SYN_HL
3045static int int_cmp __ARGS((const void *a, const void *b));
3046#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047#ifdef FEAT_CLIPBOARD
3048static char_u *check_clipboard_option __ARGS((void));
3049#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003050#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003051static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003052#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003053#ifdef FEAT_EVAL
3054static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3055#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003057static 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 +00003058static void check_redraw __ARGS((long_u flags));
3059static int findoption __ARGS((char_u *));
3060static int find_key_option __ARGS((char_u *));
3061static void showoptions __ARGS((int all, int opt_flags));
3062static int optval_default __ARGS((struct vimoption *, char_u *varp));
3063static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3064static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3065static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3066static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3067static int istermoption __ARGS((struct vimoption *));
3068static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3069static char_u *get_varp __ARGS((struct vimoption *));
3070static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3071static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3072#ifdef FEAT_LANGMAP
3073static void langmap_init __ARGS((void));
3074static void langmap_set __ARGS((void));
3075#endif
3076static void paste_option_changed __ARGS((void));
3077static void compatible_set __ARGS((void));
3078#ifdef FEAT_LINEBREAK
3079static void fill_breakat_flags __ARGS((void));
3080#endif
3081static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3082static int check_opt_strings __ARGS((char_u *val, char **values, int));
3083static int check_opt_wim __ARGS((void));
3084
3085/*
3086 * Initialize the options, first part.
3087 *
3088 * Called only once from main(), just after creating the first buffer.
3089 */
3090 void
3091set_init_1()
3092{
3093 char_u *p;
3094 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003095 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096
3097#ifdef FEAT_LANGMAP
3098 langmap_init();
3099#endif
3100
3101 /* Be Vi compatible by default */
3102 p_cp = TRUE;
3103
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003104 /* Use POSIX compatibility when $VIM_POSIX is set. */
3105 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003106 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003107 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003108 set_string_default("shm", (char_u *)"A");
3109 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003110
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 /*
3112 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003113 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003115 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3117# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003118 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003120 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003122 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123# endif
3124#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003125 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 set_string_default("sh", p);
3127
3128#ifdef FEAT_WILDIGN
3129 /*
3130 * Set the default for 'backupskip' to include environment variables for
3131 * temp files.
3132 */
3133 {
3134# ifdef UNIX
3135 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3136# else
3137 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3138# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003139 int len;
3140 garray_T ga;
3141 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142
3143 ga_init2(&ga, 1, 100);
3144 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3145 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003146 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147# ifdef UNIX
3148 if (*names[n] == NUL)
3149 p = (char_u *)"/tmp";
3150 else
3151# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003152 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 if (p != NULL && *p != NUL)
3154 {
3155 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003156 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 if (ga_grow(&ga, len) == OK)
3158 {
3159 if (ga.ga_len > 0)
3160 STRCAT(ga.ga_data, ",");
3161 STRCAT(ga.ga_data, p);
3162 add_pathsep(ga.ga_data);
3163 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 ga.ga_len += len;
3165 }
3166 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003167 if (mustfree)
3168 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 }
3170 if (ga.ga_data != NULL)
3171 {
3172 set_string_default("bsk", ga.ga_data);
3173 vim_free(ga.ga_data);
3174 }
3175 }
3176#endif
3177
3178 /*
3179 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3180 */
3181 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003182 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003184#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3185 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3186#endif
3187 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003189 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003190 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191#else
3192# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003193 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003194 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003196 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197# endif
3198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003200 opt_idx = findoption((char_u *)"maxmem");
3201 if (opt_idx >= 0)
3202 {
3203#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003204 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003205 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3206#endif
3207 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3208 }
3209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210 }
3211
3212#ifdef FEAT_GUI_W32
3213 /* force 'shortname' for Win32s */
3214 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003215 {
3216 opt_idx = findoption((char_u *)"shortname");
3217 if (opt_idx >= 0)
3218 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220#endif
3221
3222#ifdef FEAT_SEARCHPATH
3223 {
3224 char_u *cdpath;
3225 char_u *buf;
3226 int i;
3227 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003228 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229
3230 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003231 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232 if (cdpath != NULL)
3233 {
3234 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3235 if (buf != NULL)
3236 {
3237 buf[0] = ','; /* start with ",", current dir first */
3238 j = 1;
3239 for (i = 0; cdpath[i] != NUL; ++i)
3240 {
3241 if (vim_ispathlistsep(cdpath[i]))
3242 buf[j++] = ',';
3243 else
3244 {
3245 if (cdpath[i] == ' ' || cdpath[i] == ',')
3246 buf[j++] = '\\';
3247 buf[j++] = cdpath[i];
3248 }
3249 }
3250 buf[j] = NUL;
3251 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003252 if (opt_idx >= 0)
3253 {
3254 options[opt_idx].def_val[VI_DEFAULT] = buf;
3255 options[opt_idx].flags |= P_DEF_ALLOCED;
3256 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003257 else
3258 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003260 if (mustfree)
3261 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262 }
3263 }
3264#endif
3265
3266#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3267 /* Set print encoding on platforms that don't default to latin1 */
3268 set_string_default("penc",
3269# if defined(MSWIN) || defined(OS2)
3270 (char_u *)"cp1252"
3271# else
3272# ifdef VMS
3273 (char_u *)"dec-mcs"
3274# else
3275# ifdef EBCDIC
3276 (char_u *)"ebcdic-uk"
3277# else
3278# ifdef MAC
3279 (char_u *)"mac-roman"
3280# else /* HPUX */
3281 (char_u *)"hp-roman8"
3282# endif
3283# endif
3284# endif
3285# endif
3286 );
3287#endif
3288
3289#ifdef FEAT_POSTSCRIPT
3290 /* 'printexpr' must be allocated to be able to evaluate it. */
3291 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003292# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3293 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294# else
3295# ifdef VMS
3296 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3297
3298# else
3299 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3300# endif
3301# endif
3302 );
3303#endif
3304
3305 /*
3306 * Set all the options (except the terminal options) to their default
3307 * value. Also set the global value for local options.
3308 */
3309 set_options_default(0);
3310
3311#ifdef FEAT_GUI
3312 if (found_reverse_arg)
3313 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3314#endif
3315
3316 curbuf->b_p_initialized = TRUE;
3317 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003318 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319 check_buf_options(curbuf);
3320 check_win_options(curwin);
3321 check_options();
3322
3323 /* Must be before option_expand(), because that one needs vim_isIDc() */
3324 didset_options();
3325
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003326#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003327 /* Use the current chartab for the generic chartab. */
3328 init_spell_chartab();
3329#endif
3330
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331#ifdef FEAT_LINEBREAK
3332 /*
3333 * initialize the table for 'breakat'.
3334 */
3335 fill_breakat_flags();
3336#endif
3337
3338 /*
3339 * Expand environment variables and things like "~" for the defaults.
3340 * If option_expand() returns non-NULL the variable is expanded. This can
3341 * only happen for non-indirect options.
3342 * Also set the default to the expanded value, so ":set" does not list
3343 * them.
3344 * Don't set the P_ALLOCED flag, because we don't want to free the
3345 * default.
3346 */
3347 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3348 {
3349 if ((options[opt_idx].flags & P_GETTEXT)
3350 && options[opt_idx].var != NULL)
3351 p = (char_u *)_(*(char **)options[opt_idx].var);
3352 else
3353 p = option_expand(opt_idx, NULL);
3354 if (p != NULL && (p = vim_strsave(p)) != NULL)
3355 {
3356 *(char_u **)options[opt_idx].var = p;
3357 /* VIMEXP
3358 * Defaults for all expanded options are currently the same for Vi
3359 * and Vim. When this changes, add some code here! Also need to
3360 * split P_DEF_ALLOCED in two.
3361 */
3362 if (options[opt_idx].flags & P_DEF_ALLOCED)
3363 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3364 options[opt_idx].def_val[VI_DEFAULT] = p;
3365 options[opt_idx].flags |= P_DEF_ALLOCED;
3366 }
3367 }
3368
3369 /* Initialize the highlight_attr[] table. */
3370 highlight_changed();
3371
3372 save_file_ff(curbuf); /* Buffer is unchanged */
3373
3374 /* Parse default for 'wildmode' */
3375 check_opt_wim();
3376
3377#if defined(FEAT_ARABIC)
3378 /* Detect use of mlterm.
3379 * Mlterm is a terminal emulator akin to xterm that has some special
3380 * abilities (bidi namely).
3381 * NOTE: mlterm's author is being asked to 'set' a variable
3382 * instead of an environment variable due to inheritance.
3383 */
3384 if (mch_getenv((char_u *)"MLTERM") != NULL)
3385 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3386#endif
3387
3388#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3389 /* Parse default for 'fillchars'. */
3390 (void)set_chars_option(&p_fcs);
3391#endif
3392
3393#ifdef FEAT_CLIPBOARD
3394 /* Parse default for 'clipboard' */
3395 (void)check_clipboard_option();
3396#endif
3397
3398#ifdef FEAT_MBYTE
3399# if defined(WIN3264) && defined(FEAT_GETTEXT)
3400 /*
3401 * If $LANG isn't set, try to get a good value for it. This makes the
3402 * right language be used automatically. Don't do this for English.
3403 */
3404 if (mch_getenv((char_u *)"LANG") == NULL)
3405 {
3406 char buf[20];
3407
3408 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3409 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3410 * only the first two. */
3411 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3412 (LPTSTR)buf, 20);
3413 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3414 {
3415 /* There are a few exceptions (probably more) */
3416 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3417 STRCPY(buf, "zh_TW");
3418 else if (STRNICMP(buf, "chs", 3) == 0
3419 || STRNICMP(buf, "zhc", 3) == 0)
3420 STRCPY(buf, "zh_CN");
3421 else if (STRNICMP(buf, "jp", 2) == 0)
3422 STRCPY(buf, "ja");
3423 else
3424 buf[2] = NUL; /* truncate to two-letter code */
3425 vim_setenv("LANG", buf);
3426 }
3427 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003428# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003429# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003430 /* Moved to os_mac_conv.c to avoid dependency problems. */
3431 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003432# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433# endif
3434
3435 /* enc_locale() will try to find the encoding of the current locale. */
3436 p = enc_locale();
3437 if (p != NULL)
3438 {
3439 char_u *save_enc;
3440
3441 /* Try setting 'encoding' and check if the value is valid.
3442 * If not, go back to the default "latin1". */
3443 save_enc = p_enc;
3444 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003445 if (STRCMP(p_enc, "gb18030") == 0)
3446 {
3447 /* We don't support "gb18030", but "cp936" is a good substitute
3448 * for practical purposes, thus use that. It's not an alias to
3449 * still support conversion between gb18030 and utf-8. */
3450 p_enc = vim_strsave((char_u *)"cp936");
3451 vim_free(p);
3452 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453 if (mb_init() == NULL)
3454 {
3455 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003456 if (opt_idx >= 0)
3457 {
3458 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3459 options[opt_idx].flags |= P_DEF_ALLOCED;
3460 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003462#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3463 || defined(VMS)
3464 if (STRCMP(p_enc, "latin1") == 0
3465# ifdef FEAT_MBYTE
3466 || enc_utf8
3467# endif
3468 )
3469 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003470 /* Adjust the default for 'isprint' and 'iskeyword' to match
3471 * latin1. Also set the defaults for when 'nocompatible' is
3472 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003473 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003474 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003475 set_string_option_direct((char_u *)"isk", -1,
3476 ISK_LATIN1, OPT_FREE, SID_NONE);
3477 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003478 if (opt_idx >= 0)
3479 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003480 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003481 if (opt_idx >= 0)
3482 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003483 (void)init_chartab();
3484 }
3485#endif
3486
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487# if defined(WIN3264) && !defined(FEAT_GUI)
3488 /* Win32 console: When GetACP() returns a different value from
3489 * GetConsoleCP() set 'termencoding'. */
3490 if (GetACP() != GetConsoleCP())
3491 {
3492 char buf[50];
3493
3494 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3495 p_tenc = vim_strsave((char_u *)buf);
3496 if (p_tenc != NULL)
3497 {
3498 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003499 if (opt_idx >= 0)
3500 {
3501 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3502 options[opt_idx].flags |= P_DEF_ALLOCED;
3503 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504 convert_setup(&input_conv, p_tenc, p_enc);
3505 convert_setup(&output_conv, p_enc, p_tenc);
3506 }
3507 else
3508 p_tenc = empty_option;
3509 }
3510# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003511# if defined(WIN3264) && defined(FEAT_MBYTE)
3512 /* $HOME may have characters in active code page. */
3513 init_homedir();
3514# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515 }
3516 else
3517 {
3518 vim_free(p_enc);
3519 p_enc = save_enc;
3520 }
3521 }
3522#endif
3523
3524#ifdef FEAT_MULTI_LANG
3525 /* Set the default for 'helplang'. */
3526 set_helplang_default(get_mess_lang());
3527#endif
3528}
3529
3530/*
3531 * Set an option to its default value.
3532 * This does not take care of side effects!
3533 */
3534 static void
3535set_option_default(opt_idx, opt_flags, compatible)
3536 int opt_idx;
3537 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3538 int compatible; /* use Vi default value */
3539{
3540 char_u *varp; /* pointer to variable for current option */
3541 int dvi; /* index in def_val[] */
3542 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003543 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3545
3546 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3547 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003548 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003549 {
3550 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3551 if (flags & P_STRING)
3552 {
3553 /* Use set_string_option_direct() for local options to handle
3554 * freeing and allocating the value. */
3555 if (options[opt_idx].indir != PV_NONE)
3556 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003557 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558 else
3559 {
3560 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3561 free_string_option(*(char_u **)(varp));
3562 *(char_u **)varp = options[opt_idx].def_val[dvi];
3563 options[opt_idx].flags &= ~P_ALLOCED;
3564 }
3565 }
3566 else if (flags & P_NUM)
3567 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003568 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569 win_comp_scroll(curwin);
3570 else
3571 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003572 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 /* May also set global value for local option. */
3574 if (both)
3575 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3576 *(long *)varp;
3577 }
3578 }
3579 else /* P_BOOL */
3580 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003581 /* the cast to long is required for Manx C, long_i is needed for
3582 * MSVC */
3583 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003584#ifdef UNIX
3585 /* 'modeline' defaults to off for root */
3586 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3587 *(int *)varp = FALSE;
3588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003589 /* May also set global value for local option. */
3590 if (both)
3591 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3592 *(int *)varp;
3593 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003594
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003595 /* The default value is not insecure. */
3596 flagsp = insecure_flag(opt_idx, opt_flags);
3597 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 }
3599
3600#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003601 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602#endif
3603}
3604
3605/*
3606 * Set all options (except terminal options) to their default value.
3607 */
3608 static void
3609set_options_default(opt_flags)
3610 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3611{
3612 int i;
3613#ifdef FEAT_WINDOWS
3614 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003615 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616#endif
3617
3618 for (i = 0; !istermoption(&options[i]); i++)
3619 if (!(options[i].flags & P_NODEFAULT))
3620 set_option_default(i, opt_flags, p_cp);
3621
3622#ifdef FEAT_WINDOWS
3623 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003624 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625 win_comp_scroll(wp);
3626#else
3627 win_comp_scroll(curwin);
3628#endif
3629}
3630
3631/*
3632 * Set the Vi-default value of a string option.
3633 * Used for 'sh', 'backupskip' and 'term'.
3634 */
3635 void
3636set_string_default(name, val)
3637 char *name;
3638 char_u *val;
3639{
3640 char_u *p;
3641 int opt_idx;
3642
3643 p = vim_strsave(val);
3644 if (p != NULL) /* we don't want a NULL */
3645 {
3646 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003647 if (opt_idx >= 0)
3648 {
3649 if (options[opt_idx].flags & P_DEF_ALLOCED)
3650 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3651 options[opt_idx].def_val[VI_DEFAULT] = p;
3652 options[opt_idx].flags |= P_DEF_ALLOCED;
3653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 }
3655}
3656
3657/*
3658 * Set the Vi-default value of a number option.
3659 * Used for 'lines' and 'columns'.
3660 */
3661 void
3662set_number_default(name, val)
3663 char *name;
3664 long val;
3665{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003666 int opt_idx;
3667
3668 opt_idx = findoption((char_u *)name);
3669 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003670 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671}
3672
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003673#if defined(EXITFREE) || defined(PROTO)
3674/*
3675 * Free all options.
3676 */
3677 void
3678free_all_options()
3679{
3680 int i;
3681
3682 for (i = 0; !istermoption(&options[i]); i++)
3683 {
3684 if (options[i].indir == PV_NONE)
3685 {
3686 /* global option: free value and default value. */
3687 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3688 free_string_option(*(char_u **)options[i].var);
3689 if (options[i].flags & P_DEF_ALLOCED)
3690 free_string_option(options[i].def_val[VI_DEFAULT]);
3691 }
3692 else if (options[i].var != VAR_WIN
3693 && (options[i].flags & P_STRING))
3694 /* buffer-local option: free global value */
3695 free_string_option(*(char_u **)options[i].var);
3696 }
3697}
3698#endif
3699
3700
Bram Moolenaar071d4272004-06-13 20:20:40 +00003701/*
3702 * Initialize the options, part two: After getting Rows and Columns and
3703 * setting 'term'.
3704 */
3705 void
3706set_init_2()
3707{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003708 int idx;
3709
Bram Moolenaar071d4272004-06-13 20:20:40 +00003710 /*
3711 * 'scroll' defaults to half the window height. Note that this default is
3712 * wrong when the window height changes.
3713 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003714 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003715 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003716 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003717 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 comp_col();
3719
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003720 /*
3721 * 'window' is only for backwards compatibility with Vi.
3722 * Default is Rows - 1.
3723 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003724 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003725 p_window = Rows - 1;
3726 set_number_default("window", Rows - 1);
3727
Bram Moolenaarf740b292006-02-16 22:11:02 +00003728 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003730 /*
3731 * If 'background' wasn't set by the user, try guessing the value,
3732 * depending on the terminal name. Only need to check for terminals
3733 * with a dark background, that can handle color.
3734 */
3735 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003736 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3737 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003739 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003740 /* don't mark it as set, when starting the GUI it may be
3741 * changed again */
3742 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743 }
3744#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003745
3746#ifdef CURSOR_SHAPE
3747 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3748#endif
3749#ifdef FEAT_MOUSESHAPE
3750 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3751#endif
3752#ifdef FEAT_PRINTER
3753 (void)parse_printoptions(); /* parse 'printoptions' default value */
3754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755}
3756
3757/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003758 * Return "dark" or "light" depending on the kind of terminal.
3759 * This is just guessing! Recognized are:
3760 * "linux" Linux console
3761 * "screen.linux" Linux console with screen
3762 * "cygwin" Cygwin shell
3763 * "putty" Putty program
3764 * We also check the COLORFGBG environment variable, which is set by
3765 * rxvt and derivatives. This variable contains either two or three
3766 * values separated by semicolons; we want the last value in either
3767 * case. If this value is 0-6 or 8, our background is dark.
3768 */
3769 static char_u *
3770term_bg_default()
3771{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003772#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3773 /* DOS console nearly always black */
3774 return (char_u *)"dark";
3775#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003776 char_u *p;
3777
Bram Moolenaarf740b292006-02-16 22:11:02 +00003778 if (STRCMP(T_NAME, "linux") == 0
3779 || STRCMP(T_NAME, "screen.linux") == 0
3780 || STRCMP(T_NAME, "cygwin") == 0
3781 || STRCMP(T_NAME, "putty") == 0
3782 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3783 && (p = vim_strrchr(p, ';')) != NULL
3784 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3785 && p[2] == NUL))
3786 return (char_u *)"dark";
3787 return (char_u *)"light";
3788#endif
3789}
3790
3791/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 * Initialize the options, part three: After reading the .vimrc
3793 */
3794 void
3795set_init_3()
3796{
3797#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3798/*
3799 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3800 * This is done after other initializations, where 'shell' might have been
3801 * set, but only if they have not been set before.
3802 */
3803 char_u *p;
3804 int idx_srr;
3805 int do_srr;
3806#ifdef FEAT_QUICKFIX
3807 int idx_sp;
3808 int do_sp;
3809#endif
3810
3811 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003812 if (idx_srr < 0)
3813 do_srr = FALSE;
3814 else
3815 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816#ifdef FEAT_QUICKFIX
3817 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003818 if (idx_sp < 0)
3819 do_sp = FALSE;
3820 else
3821 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822#endif
3823
3824 /*
3825 * Isolate the name of the shell:
3826 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3827 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003828 * But don't allow a space in the path, so that this works:
3829 * "/usr/bin/csh --rcfile ~/.cshrc"
3830 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003832#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 p = gettail(p_sh);
3834 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003835#else
3836 p = skiptowhite(p_sh);
3837 if (*p == NUL)
3838 {
3839 /* No white space, use the tail. */
3840 p = vim_strsave(gettail(p_sh));
3841 }
3842 else
3843 {
3844 char_u *p1, *p2;
3845
3846 /* Find the last path separator before the space. */
3847 p1 = p_sh;
3848 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3849 if (vim_ispathsep(*p2))
3850 p1 = p2 + 1;
3851 p = vim_strnsave(p1, (int)(p - p1));
3852 }
3853#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 if (p != NULL)
3855 {
3856 /*
3857 * Default for p_sp is "| tee", for p_srr is ">".
3858 * For known shells it is changed here to include stderr.
3859 */
3860 if ( fnamecmp(p, "csh") == 0
3861 || fnamecmp(p, "tcsh") == 0
3862# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3863 || fnamecmp(p, "csh.exe") == 0
3864 || fnamecmp(p, "tcsh.exe") == 0
3865# endif
3866 )
3867 {
3868#if defined(FEAT_QUICKFIX)
3869 if (do_sp)
3870 {
3871# ifdef WIN3264
3872 p_sp = (char_u *)">&";
3873# else
3874 p_sp = (char_u *)"|& tee";
3875# endif
3876 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3877 }
3878#endif
3879 if (do_srr)
3880 {
3881 p_srr = (char_u *)">&";
3882 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3883 }
3884 }
3885 else
3886# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3887 if ( fnamecmp(p, "sh") == 0
3888 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003889 || fnamecmp(p, "mksh") == 0
3890 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003892 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 || fnamecmp(p, "bash") == 0
3894# ifdef WIN3264
3895 || fnamecmp(p, "cmd") == 0
3896 || fnamecmp(p, "sh.exe") == 0
3897 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003898 || fnamecmp(p, "mksh.exe") == 0
3899 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003901 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 || fnamecmp(p, "bash.exe") == 0
3903 || fnamecmp(p, "cmd.exe") == 0
3904# endif
3905 )
3906# endif
3907 {
3908#if defined(FEAT_QUICKFIX)
3909 if (do_sp)
3910 {
3911# ifdef WIN3264
3912 p_sp = (char_u *)">%s 2>&1";
3913# else
3914 p_sp = (char_u *)"2>&1| tee";
3915# endif
3916 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3917 }
3918#endif
3919 if (do_srr)
3920 {
3921 p_srr = (char_u *)">%s 2>&1";
3922 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3923 }
3924 }
3925 vim_free(p);
3926 }
3927#endif
3928
3929#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3930 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003931 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3932 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 * This is done after other initializations, where 'shell' might have been
3934 * set, but only if they have not been set before. Default for p_shcf is
3935 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3936 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3937 * command.com. And for Win32 we need to set p_sxq instead.
3938 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003939 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 {
3941 int idx3;
3942
3943 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003944 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945 {
3946 p_shcf = (char_u *)"-c";
3947 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3948 }
3949
3950# ifndef DJGPP
3951# ifdef WIN3264
3952 /* Somehow Win32 requires the quotes around the redirection too */
3953 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003954 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 {
3956 p_sxq = (char_u *)"\"";
3957 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3958 }
3959# else
3960 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003961 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 {
3963 p_shq = (char_u *)"\"";
3964 options[idx3].def_val[VI_DEFAULT] = p_shq;
3965 }
3966# endif
3967# endif
3968 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003969 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3970 {
3971 int idx3;
3972
3973 /*
3974 * cmd.exe on Windows will strip the first and last double quote given
3975 * on the command line, e.g. most of the time things like:
3976 * cmd /c "my path/to/echo" "my args to echo"
3977 * become:
3978 * my path/to/echo" "my args to echo
3979 * when executed.
3980 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003981 * To avoid this, set shellxquote to surround the command in
3982 * parenthesis. This appears to make most commands work, without
3983 * breaking commands that worked previously, such as
3984 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003985 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003986 idx3 = findoption((char_u *)"sxq");
3987 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3988 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003989 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003990 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3991 }
3992
Bram Moolenaara64ba222012-02-12 23:23:31 +01003993 idx3 = findoption((char_u *)"shcf");
3994 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3995 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003996 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003997 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3998 }
3999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000#endif
4001
4002#ifdef FEAT_TITLE
4003 set_title_defaults();
4004#endif
4005}
4006
4007#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4008/*
4009 * When 'helplang' is still at its default value, set it to "lang".
4010 * Only the first two characters of "lang" are used.
4011 */
4012 void
4013set_helplang_default(lang)
4014 char_u *lang;
4015{
4016 int idx;
4017
4018 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4019 return;
4020 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004021 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022 {
4023 if (options[idx].flags & P_ALLOCED)
4024 free_string_option(p_hlg);
4025 p_hlg = vim_strsave(lang);
4026 if (p_hlg == NULL)
4027 p_hlg = empty_option;
4028 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004029 {
4030 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4031 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4032 {
4033 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4034 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4035 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004036 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004037 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 options[idx].flags |= P_ALLOCED;
4039 }
4040}
4041#endif
4042
4043#ifdef FEAT_GUI
4044static char_u *gui_bg_default __ARGS((void));
4045
4046 static char_u *
4047gui_bg_default()
4048{
4049 if (gui_get_lightness(gui.back_pixel) < 127)
4050 return (char_u *)"dark";
4051 return (char_u *)"light";
4052}
4053
4054/*
4055 * Option initializations that can only be done after opening the GUI window.
4056 */
4057 void
4058init_gui_options()
4059{
4060 /* Set the 'background' option according to the lightness of the
4061 * background color, unless the user has set it already. */
4062 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4063 {
4064 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4065 highlight_changed();
4066 }
4067}
4068#endif
4069
4070#ifdef FEAT_TITLE
4071/*
4072 * 'title' and 'icon' only default to true if they have not been set or reset
4073 * in .vimrc and we can read the old value.
4074 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4075 * they can be reset. This reduces startup time when using X on a remote
4076 * machine.
4077 */
4078 void
4079set_title_defaults()
4080{
4081 int idx1;
4082 long val;
4083
4084 /*
4085 * If GUI is (going to be) used, we can always set the window title and
4086 * icon name. Saves a bit of time, because the X11 display server does
4087 * not need to be contacted.
4088 */
4089 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004090 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 {
4092#ifdef FEAT_GUI
4093 if (gui.starting || gui.in_use)
4094 val = TRUE;
4095 else
4096#endif
4097 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004098 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 p_title = val;
4100 }
4101 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004102 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 {
4104#ifdef FEAT_GUI
4105 if (gui.starting || gui.in_use)
4106 val = TRUE;
4107 else
4108#endif
4109 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004110 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 p_icon = val;
4112 }
4113}
4114#endif
4115
4116/*
4117 * Parse 'arg' for option settings.
4118 *
4119 * 'arg' may be IObuff, but only when no errors can be present and option
4120 * does not need to be expanded with option_expand().
4121 * "opt_flags":
4122 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004123 * OPT_GLOBAL for ":setglobal"
4124 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004126 * OPT_WINONLY to only set window-local options
4127 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 *
4129 * returns FAIL if an error is detected, OK otherwise
4130 */
4131 int
4132do_set(arg, opt_flags)
4133 char_u *arg; /* option string (may be written to!) */
4134 int opt_flags;
4135{
4136 int opt_idx;
4137 char_u *errmsg;
4138 char_u errbuf[80];
4139 char_u *startarg;
4140 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4141 int nextchar; /* next non-white char after option name */
4142 int afterchar; /* character just after option name */
4143 int len;
4144 int i;
4145 long value;
4146 int key;
4147 long_u flags; /* flags for current option */
4148 char_u *varp = NULL; /* pointer to variable for current option */
4149 int did_show = FALSE; /* already showed one value */
4150 int adding; /* "opt+=arg" */
4151 int prepending; /* "opt^=arg" */
4152 int removing; /* "opt-=arg" */
4153 int cp_val = 0;
4154 char_u key_name[2];
4155
4156 if (*arg == NUL)
4157 {
4158 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004159 did_show = TRUE;
4160 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 }
4162
4163 while (*arg != NUL) /* loop to process all options */
4164 {
4165 errmsg = NULL;
4166 startarg = arg; /* remember for error message */
4167
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004168 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4169 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170 {
4171 /*
4172 * ":set all" show all options.
4173 * ":set all&" set all options to their default value.
4174 */
4175 arg += 3;
4176 if (*arg == '&')
4177 {
4178 ++arg;
4179 /* Only for :set command set global value of local options. */
4180 set_options_default(OPT_FREE | opt_flags);
4181 }
4182 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004183 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004185 did_show = TRUE;
4186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004188 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189 {
4190 showoptions(2, opt_flags);
4191 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004192 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 arg += 7;
4194 }
4195 else
4196 {
4197 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004198 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199 {
4200 prefix = 0;
4201 arg += 2;
4202 }
4203 else if (STRNCMP(arg, "inv", 3) == 0)
4204 {
4205 prefix = 2;
4206 arg += 3;
4207 }
4208
4209 /* find end of name */
4210 key = 0;
4211 if (*arg == '<')
4212 {
4213 nextchar = 0;
4214 opt_idx = -1;
4215 /* look out for <t_>;> */
4216 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4217 len = 5;
4218 else
4219 {
4220 len = 1;
4221 while (arg[len] != NUL && arg[len] != '>')
4222 ++len;
4223 }
4224 if (arg[len] != '>')
4225 {
4226 errmsg = e_invarg;
4227 goto skip;
4228 }
4229 arg[len] = NUL; /* put NUL after name */
4230 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4231 opt_idx = findoption(arg + 1);
4232 arg[len++] = '>'; /* restore '>' */
4233 if (opt_idx == -1)
4234 key = find_key_option(arg + 1);
4235 }
4236 else
4237 {
4238 len = 0;
4239 /*
4240 * The two characters after "t_" may not be alphanumeric.
4241 */
4242 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4243 len = 4;
4244 else
4245 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4246 ++len;
4247 nextchar = arg[len];
4248 arg[len] = NUL; /* put NUL after name */
4249 opt_idx = findoption(arg);
4250 arg[len] = nextchar; /* restore nextchar */
4251 if (opt_idx == -1)
4252 key = find_key_option(arg);
4253 }
4254
4255 /* remember character after option name */
4256 afterchar = arg[len];
4257
4258 /* skip white space, allow ":set ai ?" */
4259 while (vim_iswhite(arg[len]))
4260 ++len;
4261
4262 adding = FALSE;
4263 prepending = FALSE;
4264 removing = FALSE;
4265 if (arg[len] != NUL && arg[len + 1] == '=')
4266 {
4267 if (arg[len] == '+')
4268 {
4269 adding = TRUE; /* "+=" */
4270 ++len;
4271 }
4272 else if (arg[len] == '^')
4273 {
4274 prepending = TRUE; /* "^=" */
4275 ++len;
4276 }
4277 else if (arg[len] == '-')
4278 {
4279 removing = TRUE; /* "-=" */
4280 ++len;
4281 }
4282 }
4283 nextchar = arg[len];
4284
4285 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4286 {
4287 errmsg = (char_u *)N_("E518: Unknown option");
4288 goto skip;
4289 }
4290
4291 if (opt_idx >= 0)
4292 {
4293 if (options[opt_idx].var == NULL) /* hidden option: skip */
4294 {
4295 /* Only give an error message when requesting the value of
4296 * a hidden option, ignore setting it. */
4297 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4298 && (!(options[opt_idx].flags & P_BOOL)
4299 || nextchar == '?'))
4300 errmsg = (char_u *)N_("E519: Option not supported");
4301 goto skip;
4302 }
4303
4304 flags = options[opt_idx].flags;
4305 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4306 }
4307 else
4308 {
4309 flags = P_STRING;
4310 if (key < 0)
4311 {
4312 key_name[0] = KEY2TERMCAP0(key);
4313 key_name[1] = KEY2TERMCAP1(key);
4314 }
4315 else
4316 {
4317 key_name[0] = KS_KEY;
4318 key_name[1] = (key & 0xff);
4319 }
4320 }
4321
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004322 /* Skip all options that are not window-local (used when showing
4323 * an already loaded buffer in a window). */
4324 if ((opt_flags & OPT_WINONLY)
4325 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4326 goto skip;
4327
Bram Moolenaara3227e22006-03-08 21:32:40 +00004328 /* Skip all options that are window-local (used for :vimgrep). */
4329 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4330 && options[opt_idx].var == VAR_WIN)
4331 goto skip;
4332
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004333 /* Disallow changing some options from modelines. */
4334 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004335 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004336 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004337 {
4338 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4339 goto skip;
4340 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004341#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004342 /* In diff mode some options are overruled. This avoids that
4343 * 'foldmethod' becomes "marker" instead of "diff" and that
4344 * "wrap" gets set. */
4345 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004346 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004347 && (options[opt_idx].indir == PV_FDM
4348 || options[opt_idx].indir == PV_WRAP))
4349 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004351 }
4352
4353#ifdef HAVE_SANDBOX
4354 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004355 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004356 {
4357 errmsg = (char_u *)_(e_sandbox);
4358 goto skip;
4359 }
4360#endif
4361
4362 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4363 {
4364 arg += len;
4365 cp_val = p_cp;
4366 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4367 {
4368 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4369 {
4370 cp_val = FALSE;
4371 arg += 3;
4372 }
4373 else /* "opt&vi": set to Vi default */
4374 {
4375 cp_val = TRUE;
4376 arg += 2;
4377 }
4378 }
4379 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4380 && arg[1] != NUL && !vim_iswhite(arg[1]))
4381 {
4382 errmsg = e_trailing;
4383 goto skip;
4384 }
4385 }
4386
4387 /*
4388 * allow '=' and ':' as MSDOS command.com allows only one
4389 * '=' character per "set" command line. grrr. (jw)
4390 */
4391 if (nextchar == '?'
4392 || (prefix == 1
4393 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4394 && !(flags & P_BOOL)))
4395 {
4396 /*
4397 * print value
4398 */
4399 if (did_show)
4400 msg_putchar('\n'); /* cursor below last one */
4401 else
4402 {
4403 gotocmdline(TRUE); /* cursor at status line */
4404 did_show = TRUE; /* remember that we did a line */
4405 }
4406 if (opt_idx >= 0)
4407 {
4408 showoneopt(&options[opt_idx], opt_flags);
4409#ifdef FEAT_EVAL
4410 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004411 {
4412 /* Mention where the option was last set. */
4413 if (varp == options[opt_idx].var)
4414 last_set_msg(options[opt_idx].scriptID);
4415 else if ((int)options[opt_idx].indir & PV_WIN)
4416 last_set_msg(curwin->w_p_scriptID[
4417 (int)options[opt_idx].indir & PV_MASK]);
4418 else if ((int)options[opt_idx].indir & PV_BUF)
4419 last_set_msg(curbuf->b_p_scriptID[
4420 (int)options[opt_idx].indir & PV_MASK]);
4421 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004422#endif
4423 }
4424 else
4425 {
4426 char_u *p;
4427
4428 p = find_termcode(key_name);
4429 if (p == NULL)
4430 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004431 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004432 goto skip;
4433 }
4434 else
4435 (void)show_one_termcode(key_name, p, TRUE);
4436 }
4437 if (nextchar != '?'
4438 && nextchar != NUL && !vim_iswhite(afterchar))
4439 errmsg = e_trailing;
4440 }
4441 else
4442 {
4443 if (flags & P_BOOL) /* boolean */
4444 {
4445 if (nextchar == '=' || nextchar == ':')
4446 {
4447 errmsg = e_invarg;
4448 goto skip;
4449 }
4450
4451 /*
4452 * ":set opt!": invert
4453 * ":set opt&": reset to default value
4454 * ":set opt<": reset to global value
4455 */
4456 if (nextchar == '!')
4457 value = *(int *)(varp) ^ 1;
4458 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004459 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004460 ((flags & P_VI_DEF) || cp_val)
4461 ? VI_DEFAULT : VIM_DEFAULT];
4462 else if (nextchar == '<')
4463 {
4464 /* For 'autoread' -1 means to use global value. */
4465 if ((int *)varp == &curbuf->b_p_ar
4466 && opt_flags == OPT_LOCAL)
4467 value = -1;
4468 else
4469 value = *(int *)get_varp_scope(&(options[opt_idx]),
4470 OPT_GLOBAL);
4471 }
4472 else
4473 {
4474 /*
4475 * ":set invopt": invert
4476 * ":set opt" or ":set noopt": set or reset
4477 */
4478 if (nextchar != NUL && !vim_iswhite(afterchar))
4479 {
4480 errmsg = e_trailing;
4481 goto skip;
4482 }
4483 if (prefix == 2) /* inv */
4484 value = *(int *)(varp) ^ 1;
4485 else
4486 value = prefix;
4487 }
4488
4489 errmsg = set_bool_option(opt_idx, varp, (int)value,
4490 opt_flags);
4491 }
4492 else /* numeric or string */
4493 {
4494 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4495 || prefix != 1)
4496 {
4497 errmsg = e_invarg;
4498 goto skip;
4499 }
4500
4501 if (flags & P_NUM) /* numeric */
4502 {
4503 /*
4504 * Different ways to set a number option:
4505 * & set to default value
4506 * < set to global value
4507 * <xx> accept special key codes for 'wildchar'
4508 * c accept any non-digit for 'wildchar'
4509 * [-]0-9 set number
4510 * other error
4511 */
4512 ++arg;
4513 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004514 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004515 ((flags & P_VI_DEF) || cp_val)
4516 ? VI_DEFAULT : VIM_DEFAULT];
4517 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004518 {
4519 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4520 * use the global value. */
4521 if ((long *)varp == &curbuf->b_p_ul
4522 && opt_flags == OPT_LOCAL)
4523 value = NO_LOCAL_UNDOLEVEL;
4524 else
4525 value = *(long *)get_varp_scope(
4526 &(options[opt_idx]), OPT_GLOBAL);
4527 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004528 else if (((long *)varp == &p_wc
4529 || (long *)varp == &p_wcm)
4530 && (*arg == '<'
4531 || *arg == '^'
4532 || ((!arg[1] || vim_iswhite(arg[1]))
4533 && !VIM_ISDIGIT(*arg))))
4534 {
4535 value = string_to_key(arg);
4536 if (value == 0 && (long *)varp != &p_wcm)
4537 {
4538 errmsg = e_invarg;
4539 goto skip;
4540 }
4541 }
4542 /* allow negative numbers (for 'undolevels') */
4543 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4544 {
4545 i = 0;
4546 if (*arg == '-')
4547 i = 1;
4548#ifdef HAVE_STRTOL
4549 value = strtol((char *)arg, NULL, 0);
4550 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4551 i += 2;
4552#else
4553 value = atol((char *)arg);
4554#endif
4555 while (VIM_ISDIGIT(arg[i]))
4556 ++i;
4557 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4558 {
4559 errmsg = e_invarg;
4560 goto skip;
4561 }
4562 }
4563 else
4564 {
4565 errmsg = (char_u *)N_("E521: Number required after =");
4566 goto skip;
4567 }
4568
4569 if (adding)
4570 value = *(long *)varp + value;
4571 if (prepending)
4572 value = *(long *)varp * value;
4573 if (removing)
4574 value = *(long *)varp - value;
4575 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004576 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004577 }
4578 else if (opt_idx >= 0) /* string */
4579 {
4580 char_u *save_arg = NULL;
4581 char_u *s = NULL;
4582 char_u *oldval; /* previous value if *varp */
4583 char_u *newval;
4584 char_u *origval;
4585 unsigned newlen;
4586 int comma;
4587 int bs;
4588 int new_value_alloced; /* new string option
4589 was allocated */
4590
4591 /* When using ":set opt=val" for a global option
4592 * with a local value the local value will be
4593 * reset, use the global value here. */
4594 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004595 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004596 varp = options[opt_idx].var;
4597
4598 /* The old value is kept until we are sure that the
4599 * new value is valid. */
4600 oldval = *(char_u **)varp;
4601 if (nextchar == '&') /* set to default val */
4602 {
4603 newval = options[opt_idx].def_val[
4604 ((flags & P_VI_DEF) || cp_val)
4605 ? VI_DEFAULT : VIM_DEFAULT];
4606 if ((char_u **)varp == &p_bg)
4607 {
4608 /* guess the value of 'background' */
4609#ifdef FEAT_GUI
4610 if (gui.in_use)
4611 newval = gui_bg_default();
4612 else
4613#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004614 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 }
4616
4617 /* expand environment variables and ~ (since the
4618 * default value was already expanded, only
4619 * required when an environment variable was set
4620 * later */
4621 if (newval == NULL)
4622 newval = empty_option;
4623 else
4624 {
4625 s = option_expand(opt_idx, newval);
4626 if (s == NULL)
4627 s = newval;
4628 newval = vim_strsave(s);
4629 }
4630 new_value_alloced = TRUE;
4631 }
4632 else if (nextchar == '<') /* set to global val */
4633 {
4634 newval = vim_strsave(*(char_u **)get_varp_scope(
4635 &(options[opt_idx]), OPT_GLOBAL));
4636 new_value_alloced = TRUE;
4637 }
4638 else
4639 {
4640 ++arg; /* jump to after the '=' or ':' */
4641
4642 /*
4643 * Set 'keywordprg' to ":help" if an empty
4644 * value was passed to :set by the user.
4645 * Misuse errbuf[] for the resulting string.
4646 */
4647 if (varp == (char_u *)&p_kp
4648 && (*arg == NUL || *arg == ' '))
4649 {
4650 STRCPY(errbuf, ":help");
4651 save_arg = arg;
4652 arg = errbuf;
4653 }
4654 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004655 * Convert 'backspace' number to string, for
4656 * adding, prepending and removing string.
4657 */
4658 else if (varp == (char_u *)&p_bs
4659 && VIM_ISDIGIT(**(char_u **)varp))
4660 {
4661 i = getdigits((char_u **)varp);
4662 switch (i)
4663 {
4664 case 0:
4665 *(char_u **)varp = empty_option;
4666 break;
4667 case 1:
4668 *(char_u **)varp = vim_strsave(
4669 (char_u *)"indent,eol");
4670 break;
4671 case 2:
4672 *(char_u **)varp = vim_strsave(
4673 (char_u *)"indent,eol,start");
4674 break;
4675 }
4676 vim_free(oldval);
4677 oldval = *(char_u **)varp;
4678 }
4679 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004680 * Convert 'whichwrap' number to string, for
4681 * backwards compatibility with Vim 3.0.
4682 * Misuse errbuf[] for the resulting string.
4683 */
4684 else if (varp == (char_u *)&p_ww
4685 && VIM_ISDIGIT(*arg))
4686 {
4687 *errbuf = NUL;
4688 i = getdigits(&arg);
4689 if (i & 1)
4690 STRCAT(errbuf, "b,");
4691 if (i & 2)
4692 STRCAT(errbuf, "s,");
4693 if (i & 4)
4694 STRCAT(errbuf, "h,l,");
4695 if (i & 8)
4696 STRCAT(errbuf, "<,>,");
4697 if (i & 16)
4698 STRCAT(errbuf, "[,],");
4699 if (*errbuf != NUL) /* remove trailing , */
4700 errbuf[STRLEN(errbuf) - 1] = NUL;
4701 save_arg = arg;
4702 arg = errbuf;
4703 }
4704 /*
4705 * Remove '>' before 'dir' and 'bdir', for
4706 * backwards compatibility with version 3.0
4707 */
4708 else if ( *arg == '>'
4709 && (varp == (char_u *)&p_dir
4710 || varp == (char_u *)&p_bdir))
4711 {
4712 ++arg;
4713 }
4714
4715 /* When setting the local value of a global
4716 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004717 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004718 && (opt_flags & OPT_LOCAL))
4719 origval = *(char_u **)get_varp(
4720 &options[opt_idx]);
4721 else
4722 origval = oldval;
4723
4724 /*
4725 * Copy the new string into allocated memory.
4726 * Can't use set_string_option_direct(), because
4727 * we need to remove the backslashes.
4728 */
4729 /* get a bit too much */
4730 newlen = (unsigned)STRLEN(arg) + 1;
4731 if (adding || prepending || removing)
4732 newlen += (unsigned)STRLEN(origval) + 1;
4733 newval = alloc(newlen);
4734 if (newval == NULL) /* out of mem, don't change */
4735 break;
4736 s = newval;
4737
4738 /*
4739 * Copy the string, skip over escaped chars.
4740 * For MS-DOS and WIN32 backslashes before normal
4741 * file name characters are not removed, and keep
4742 * backslash at start, for "\\machine\path", but
4743 * do remove it for "\\\\machine\\path".
4744 * The reverse is found in ExpandOldSetting().
4745 */
4746 while (*arg && !vim_iswhite(*arg))
4747 {
4748 if (*arg == '\\' && arg[1] != NUL
4749#ifdef BACKSLASH_IN_FILENAME
4750 && !((flags & P_EXPAND)
4751 && vim_isfilec(arg[1])
4752 && (arg[1] != '\\'
4753 || (s == newval
4754 && arg[2] != '\\')))
4755#endif
4756 )
4757 ++arg; /* remove backslash */
4758#ifdef FEAT_MBYTE
4759 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004760 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004761 {
4762 /* copy multibyte char */
4763 mch_memmove(s, arg, (size_t)i);
4764 arg += i;
4765 s += i;
4766 }
4767 else
4768#endif
4769 *s++ = *arg++;
4770 }
4771 *s = NUL;
4772
4773 /*
4774 * Expand environment variables and ~.
4775 * Don't do it when adding without inserting a
4776 * comma.
4777 */
4778 if (!(adding || prepending || removing)
4779 || (flags & P_COMMA))
4780 {
4781 s = option_expand(opt_idx, newval);
4782 if (s != NULL)
4783 {
4784 vim_free(newval);
4785 newlen = (unsigned)STRLEN(s) + 1;
4786 if (adding || prepending || removing)
4787 newlen += (unsigned)STRLEN(origval) + 1;
4788 newval = alloc(newlen);
4789 if (newval == NULL)
4790 break;
4791 STRCPY(newval, s);
4792 }
4793 }
4794
4795 /* locate newval[] in origval[] when removing it
4796 * and when adding to avoid duplicates */
4797 i = 0; /* init for GCC */
4798 if (removing || (flags & P_NODUP))
4799 {
4800 i = (int)STRLEN(newval);
4801 bs = 0;
4802 for (s = origval; *s; ++s)
4803 {
4804 if ((!(flags & P_COMMA)
4805 || s == origval
4806 || (s[-1] == ',' && !(bs & 1)))
4807 && STRNCMP(s, newval, i) == 0
4808 && (!(flags & P_COMMA)
4809 || s[i] == ','
4810 || s[i] == NUL))
4811 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004812 /* Count backslashes. Only a comma with an
4813 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004814 * recognized as a separator */
4815 if (s > origval && s[-1] == '\\')
4816 ++bs;
4817 else
4818 bs = 0;
4819 }
4820
4821 /* do not add if already there */
4822 if ((adding || prepending) && *s)
4823 {
4824 prepending = FALSE;
4825 adding = FALSE;
4826 STRCPY(newval, origval);
4827 }
4828 }
4829
4830 /* concatenate the two strings; add a ',' if
4831 * needed */
4832 if (adding || prepending)
4833 {
4834 comma = ((flags & P_COMMA) && *origval != NUL
4835 && *newval != NUL);
4836 if (adding)
4837 {
4838 i = (int)STRLEN(origval);
4839 mch_memmove(newval + i + comma, newval,
4840 STRLEN(newval) + 1);
4841 mch_memmove(newval, origval, (size_t)i);
4842 }
4843 else
4844 {
4845 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004846 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004847 }
4848 if (comma)
4849 newval[i] = ',';
4850 }
4851
4852 /* Remove newval[] from origval[]. (Note: "i" has
4853 * been set above and is used here). */
4854 if (removing)
4855 {
4856 STRCPY(newval, origval);
4857 if (*s)
4858 {
4859 /* may need to remove a comma */
4860 if (flags & P_COMMA)
4861 {
4862 if (s == origval)
4863 {
4864 /* include comma after string */
4865 if (s[i] == ',')
4866 ++i;
4867 }
4868 else
4869 {
4870 /* include comma before string */
4871 --s;
4872 ++i;
4873 }
4874 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004875 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004876 }
4877 }
4878
4879 if (flags & P_FLAGLIST)
4880 {
4881 /* Remove flags that appear twice. */
4882 for (s = newval; *s; ++s)
4883 if ((!(flags & P_COMMA) || *s != ',')
4884 && vim_strchr(s + 1, *s) != NULL)
4885 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004886 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004887 --s;
4888 }
4889 }
4890
4891 if (save_arg != NULL) /* number for 'whichwrap' */
4892 arg = save_arg;
4893 new_value_alloced = TRUE;
4894 }
4895
4896 /* Set the new value. */
4897 *(char_u **)(varp) = newval;
4898
4899 /* Handle side effects, and set the global value for
4900 * ":set" on local options. */
4901 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4902 new_value_alloced, oldval, errbuf, opt_flags);
4903
4904 /* If error detected, print the error message. */
4905 if (errmsg != NULL)
4906 goto skip;
4907 }
4908 else /* key code option */
4909 {
4910 char_u *p;
4911
4912 if (nextchar == '&')
4913 {
4914 if (add_termcap_entry(key_name, TRUE) == FAIL)
4915 errmsg = (char_u *)N_("E522: Not found in termcap");
4916 }
4917 else
4918 {
4919 ++arg; /* jump to after the '=' or ':' */
4920 for (p = arg; *p && !vim_iswhite(*p); ++p)
4921 if (*p == '\\' && p[1] != NUL)
4922 ++p;
4923 nextchar = *p;
4924 *p = NUL;
4925 add_termcode(key_name, arg, FALSE);
4926 *p = nextchar;
4927 }
4928 if (full_screen)
4929 ttest(FALSE);
4930 redraw_all_later(CLEAR);
4931 }
4932 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004933
Bram Moolenaar071d4272004-06-13 20:20:40 +00004934 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004935 did_set_option(opt_idx, opt_flags,
4936 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004937 }
4938
4939skip:
4940 /*
4941 * Advance to next argument.
4942 * - skip until a blank found, taking care of backslashes
4943 * - skip blanks
4944 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4945 */
4946 for (i = 0; i < 2 ; ++i)
4947 {
4948 while (*arg != NUL && !vim_iswhite(*arg))
4949 if (*arg++ == '\\' && *arg != NUL)
4950 ++arg;
4951 arg = skipwhite(arg);
4952 if (*arg != '=')
4953 break;
4954 }
4955 }
4956
4957 if (errmsg != NULL)
4958 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004959 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004960 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 if (i + (arg - startarg) < IOSIZE)
4962 {
4963 /* append the argument with the error */
4964 STRCAT(IObuff, ": ");
4965 mch_memmove(IObuff + i, startarg, (arg - startarg));
4966 IObuff[i + (arg - startarg)] = NUL;
4967 }
4968 /* make sure all characters are printable */
4969 trans_characters(IObuff, IOSIZE);
4970
4971 ++no_wait_return; /* wait_return done later */
4972 emsg(IObuff); /* show error highlighted */
4973 --no_wait_return;
4974
4975 return FAIL;
4976 }
4977
4978 arg = skipwhite(arg);
4979 }
4980
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004981theend:
4982 if (silent_mode && did_show)
4983 {
4984 /* After displaying option values in silent mode. */
4985 silent_mode = FALSE;
4986 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4987 msg_putchar('\n');
4988 cursor_on(); /* msg_start() switches it off */
4989 out_flush();
4990 silent_mode = TRUE;
4991 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4992 }
4993
Bram Moolenaar071d4272004-06-13 20:20:40 +00004994 return OK;
4995}
4996
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004997/*
4998 * Call this when an option has been given a new value through a user command.
4999 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5000 */
5001 static void
5002did_set_option(opt_idx, opt_flags, new_value)
5003 int opt_idx;
5004 int opt_flags; /* possibly with OPT_MODELINE */
5005 int new_value; /* value was replaced completely */
5006{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005007 long_u *p;
5008
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005009 options[opt_idx].flags |= P_WAS_SET;
5010
5011 /* When an option is set in the sandbox, from a modeline or in secure mode
5012 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005013 * flag. */
5014 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005015 if (secure
5016#ifdef HAVE_SANDBOX
5017 || sandbox != 0
5018#endif
5019 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005020 *p = *p | P_INSECURE;
5021 else if (new_value)
5022 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005023}
5024
Bram Moolenaar071d4272004-06-13 20:20:40 +00005025 static char_u *
5026illegal_char(errbuf, c)
5027 char_u *errbuf;
5028 int c;
5029{
5030 if (errbuf == NULL)
5031 return (char_u *)"";
5032 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005033 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005034 return errbuf;
5035}
5036
5037/*
5038 * Convert a key name or string into a key value.
5039 * Used for 'wildchar' and 'cedit' options.
5040 */
5041 static int
5042string_to_key(arg)
5043 char_u *arg;
5044{
5045 if (*arg == '<')
5046 return find_key_option(arg + 1);
5047 if (*arg == '^')
5048 return Ctrl_chr(arg[1]);
5049 return *arg;
5050}
5051
5052#ifdef FEAT_CMDWIN
5053/*
5054 * Check value of 'cedit' and set cedit_key.
5055 * Returns NULL if value is OK, error message otherwise.
5056 */
5057 static char_u *
5058check_cedit()
5059{
5060 int n;
5061
5062 if (*p_cedit == NUL)
5063 cedit_key = -1;
5064 else
5065 {
5066 n = string_to_key(p_cedit);
5067 if (vim_isprintc(n))
5068 return e_invarg;
5069 cedit_key = n;
5070 }
5071 return NULL;
5072}
5073#endif
5074
5075#ifdef FEAT_TITLE
5076/*
5077 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5078 * maketitle() to create and display it.
5079 * When switching the title or icon off, call mch_restore_title() to get
5080 * the old value back.
5081 */
5082 static void
5083did_set_title(icon)
5084 int icon; /* Did set icon instead of title */
5085{
5086 if (starting != NO_SCREEN
5087#ifdef FEAT_GUI
5088 && !gui.starting
5089#endif
5090 )
5091 {
5092 maketitle();
5093 if (icon)
5094 {
5095 if (!p_icon)
5096 mch_restore_title(2);
5097 }
5098 else
5099 {
5100 if (!p_title)
5101 mch_restore_title(1);
5102 }
5103 }
5104}
5105#endif
5106
5107/*
5108 * set_options_bin - called when 'bin' changes value.
5109 */
5110 void
5111set_options_bin(oldval, newval, opt_flags)
5112 int oldval;
5113 int newval;
5114 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5115{
5116 /*
5117 * The option values that are changed when 'bin' changes are
5118 * copied when 'bin is set and restored when 'bin' is reset.
5119 */
5120 if (newval)
5121 {
5122 if (!oldval) /* switched on */
5123 {
5124 if (!(opt_flags & OPT_GLOBAL))
5125 {
5126 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5127 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5128 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5129 curbuf->b_p_et_nobin = curbuf->b_p_et;
5130 }
5131 if (!(opt_flags & OPT_LOCAL))
5132 {
5133 p_tw_nobin = p_tw;
5134 p_wm_nobin = p_wm;
5135 p_ml_nobin = p_ml;
5136 p_et_nobin = p_et;
5137 }
5138 }
5139
5140 if (!(opt_flags & OPT_GLOBAL))
5141 {
5142 curbuf->b_p_tw = 0; /* no automatic line wrap */
5143 curbuf->b_p_wm = 0; /* no automatic line wrap */
5144 curbuf->b_p_ml = 0; /* no modelines */
5145 curbuf->b_p_et = 0; /* no expandtab */
5146 }
5147 if (!(opt_flags & OPT_LOCAL))
5148 {
5149 p_tw = 0;
5150 p_wm = 0;
5151 p_ml = FALSE;
5152 p_et = FALSE;
5153 p_bin = TRUE; /* needed when called for the "-b" argument */
5154 }
5155 }
5156 else if (oldval) /* switched off */
5157 {
5158 if (!(opt_flags & OPT_GLOBAL))
5159 {
5160 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5161 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5162 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5163 curbuf->b_p_et = curbuf->b_p_et_nobin;
5164 }
5165 if (!(opt_flags & OPT_LOCAL))
5166 {
5167 p_tw = p_tw_nobin;
5168 p_wm = p_wm_nobin;
5169 p_ml = p_ml_nobin;
5170 p_et = p_et_nobin;
5171 }
5172 }
5173}
5174
5175#ifdef FEAT_VIMINFO
5176/*
5177 * Find the parameter represented by the given character (eg ', :, ", or /),
5178 * and return its associated value in the 'viminfo' string.
5179 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005180 * If the parameter is not specified in the string or there is no following
5181 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182 */
5183 int
5184get_viminfo_parameter(type)
5185 int type;
5186{
5187 char_u *p;
5188
5189 p = find_viminfo_parameter(type);
5190 if (p != NULL && VIM_ISDIGIT(*p))
5191 return atoi((char *)p);
5192 return -1;
5193}
5194
5195/*
5196 * Find the parameter represented by the given character (eg ''', ':', '"', or
5197 * '/') in the 'viminfo' option and return a pointer to the string after it.
5198 * Return NULL if the parameter is not specified in the string.
5199 */
5200 char_u *
5201find_viminfo_parameter(type)
5202 int type;
5203{
5204 char_u *p;
5205
5206 for (p = p_viminfo; *p; ++p)
5207 {
5208 if (*p == type)
5209 return p + 1;
5210 if (*p == 'n') /* 'n' is always the last one */
5211 break;
5212 p = vim_strchr(p, ','); /* skip until next ',' */
5213 if (p == NULL) /* hit the end without finding parameter */
5214 break;
5215 }
5216 return NULL;
5217}
5218#endif
5219
5220/*
5221 * Expand environment variables for some string options.
5222 * These string options cannot be indirect!
5223 * If "val" is NULL expand the current value of the option.
5224 * Return pointer to NameBuff, or NULL when not expanded.
5225 */
5226 static char_u *
5227option_expand(opt_idx, val)
5228 int opt_idx;
5229 char_u *val;
5230{
5231 /* if option doesn't need expansion nothing to do */
5232 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5233 return NULL;
5234
5235 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5236 * expand_env() would truncate the string. */
5237 if (val != NULL && STRLEN(val) > MAXPATHL)
5238 return NULL;
5239
5240 if (val == NULL)
5241 val = *(char_u **)options[opt_idx].var;
5242
5243 /*
5244 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5245 * Escape spaces when expanding 'tags', they are used to separate file
5246 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005247 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 */
5249 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005250 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005251#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005252 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5253#endif
5254 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5256 return NULL;
5257
5258 return NameBuff;
5259}
5260
5261/*
5262 * After setting various option values: recompute variables that depend on
5263 * option values.
5264 */
5265 static void
5266didset_options()
5267{
5268 /* initialize the table for 'iskeyword' et.al. */
5269 (void)init_chartab();
5270
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005271#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005272 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005273#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005274 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5275#ifdef FEAT_SESSION
5276 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5277 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5278#endif
5279#ifdef FEAT_FOLDING
5280 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5281#endif
5282 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5283#ifdef FEAT_VIRTUALEDIT
5284 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5285#endif
5286#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5287 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5288#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005289#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005290 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005291 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005292 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005294#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5295 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5296#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005297#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005298 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5299#endif
5300#ifdef FEAT_CMDWIN
5301 /* set cedit_key */
5302 (void)check_cedit();
5303#endif
5304}
5305
5306/*
5307 * Check for string options that are NULL (normally only termcap options).
5308 */
5309 void
5310check_options()
5311{
5312 int opt_idx;
5313
5314 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5315 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5316 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5317}
5318
5319/*
5320 * Check string options in a buffer for NULL value.
5321 */
5322 void
5323check_buf_options(buf)
5324 buf_T *buf;
5325{
5326#if defined(FEAT_QUICKFIX)
5327 check_string_option(&buf->b_p_bh);
5328 check_string_option(&buf->b_p_bt);
5329#endif
5330#ifdef FEAT_MBYTE
5331 check_string_option(&buf->b_p_fenc);
5332#endif
5333 check_string_option(&buf->b_p_ff);
5334#ifdef FEAT_FIND_ID
5335 check_string_option(&buf->b_p_def);
5336 check_string_option(&buf->b_p_inc);
5337# ifdef FEAT_EVAL
5338 check_string_option(&buf->b_p_inex);
5339# endif
5340#endif
5341#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5342 check_string_option(&buf->b_p_inde);
5343 check_string_option(&buf->b_p_indk);
5344#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005345#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5346 check_string_option(&buf->b_p_bexpr);
5347#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005348#if defined(FEAT_CRYPT)
5349 check_string_option(&buf->b_p_cm);
5350#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005351#if defined(FEAT_EVAL)
5352 check_string_option(&buf->b_p_fex);
5353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354#ifdef FEAT_CRYPT
5355 check_string_option(&buf->b_p_key);
5356#endif
5357 check_string_option(&buf->b_p_kp);
5358 check_string_option(&buf->b_p_mps);
5359 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005360 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005361 check_string_option(&buf->b_p_isk);
5362#ifdef FEAT_COMMENTS
5363 check_string_option(&buf->b_p_com);
5364#endif
5365#ifdef FEAT_FOLDING
5366 check_string_option(&buf->b_p_cms);
5367#endif
5368 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005369#ifdef FEAT_TEXTOBJ
5370 check_string_option(&buf->b_p_qe);
5371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372#ifdef FEAT_SYN_HL
5373 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005374#endif
5375#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005376 check_string_option(&buf->b_s.b_p_spc);
5377 check_string_option(&buf->b_s.b_p_spf);
5378 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379#endif
5380#ifdef FEAT_SEARCHPATH
5381 check_string_option(&buf->b_p_sua);
5382#endif
5383#ifdef FEAT_CINDENT
5384 check_string_option(&buf->b_p_cink);
5385 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005386 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387#endif
5388#ifdef FEAT_AUTOCMD
5389 check_string_option(&buf->b_p_ft);
5390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005391#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5392 check_string_option(&buf->b_p_cinw);
5393#endif
5394#ifdef FEAT_INS_EXPAND
5395 check_string_option(&buf->b_p_cpt);
5396#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005397#ifdef FEAT_COMPL_FUNC
5398 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005399 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005401#ifdef FEAT_KEYMAP
5402 check_string_option(&buf->b_p_keymap);
5403#endif
5404#ifdef FEAT_QUICKFIX
5405 check_string_option(&buf->b_p_gp);
5406 check_string_option(&buf->b_p_mp);
5407 check_string_option(&buf->b_p_efm);
5408#endif
5409 check_string_option(&buf->b_p_ep);
5410 check_string_option(&buf->b_p_path);
5411 check_string_option(&buf->b_p_tags);
5412#ifdef FEAT_INS_EXPAND
5413 check_string_option(&buf->b_p_dict);
5414 check_string_option(&buf->b_p_tsr);
5415#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005416#ifdef FEAT_LISP
5417 check_string_option(&buf->b_p_lw);
5418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005419}
5420
5421/*
5422 * Free the string allocated for an option.
5423 * Checks for the string being empty_option. This may happen if we're out of
5424 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5425 * check_options().
5426 * Does NOT check for P_ALLOCED flag!
5427 */
5428 void
5429free_string_option(p)
5430 char_u *p;
5431{
5432 if (p != empty_option)
5433 vim_free(p);
5434}
5435
5436 void
5437clear_string_option(pp)
5438 char_u **pp;
5439{
5440 if (*pp != empty_option)
5441 vim_free(*pp);
5442 *pp = empty_option;
5443}
5444
5445 static void
5446check_string_option(pp)
5447 char_u **pp;
5448{
5449 if (*pp == NULL)
5450 *pp = empty_option;
5451}
5452
5453/*
5454 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5455 */
5456 void
5457set_term_option_alloced(p)
5458 char_u **p;
5459{
5460 int opt_idx;
5461
5462 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5463 if (options[opt_idx].var == (char_u *)p)
5464 {
5465 options[opt_idx].flags |= P_ALLOCED;
5466 return;
5467 }
5468 return; /* cannot happen: didn't find it! */
5469}
5470
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005471#if defined(FEAT_EVAL) || defined(PROTO)
5472/*
5473 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5474 * Return FALSE when it wasn't.
5475 * Return -1 for an unknown option.
5476 */
5477 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005478was_set_insecurely(opt, opt_flags)
5479 char_u *opt;
5480 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005481{
5482 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005483 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005484
5485 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005486 {
5487 flagp = insecure_flag(idx, opt_flags);
5488 return (*flagp & P_INSECURE) != 0;
5489 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005490 EMSG2(_(e_intern2), "was_set_insecurely()");
5491 return -1;
5492}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005493
5494/*
5495 * Get a pointer to the flags used for the P_INSECURE flag of option
5496 * "opt_idx". For some local options a local flags field is used.
5497 */
5498 static long_u *
5499insecure_flag(opt_idx, opt_flags)
5500 int opt_idx;
5501 int opt_flags;
5502{
5503 if (opt_flags & OPT_LOCAL)
5504 switch ((int)options[opt_idx].indir)
5505 {
5506#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005507 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005508#endif
5509#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005510# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005511 case PV_FDE: return &curwin->w_p_fde_flags;
5512 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005513# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005514# ifdef FEAT_BEVAL
5515 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5516# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005517# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005518 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005519# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005520 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005521# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005522 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005523# endif
5524#endif
5525 }
5526
5527 /* Nothing special, return global flags field. */
5528 return &options[opt_idx].flags;
5529}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005530#endif
5531
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005532#ifdef FEAT_TITLE
5533static void redraw_titles __ARGS((void));
5534
5535/*
5536 * Redraw the window title and/or tab page text later.
5537 */
5538static void redraw_titles()
5539{
5540 need_maketitle = TRUE;
5541# ifdef FEAT_WINDOWS
5542 redraw_tabline = TRUE;
5543# endif
5544}
5545#endif
5546
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547/*
5548 * Set a string option to a new value (without checking the effect).
5549 * The string is copied into allocated memory.
5550 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005551 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005552 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553 */
5554 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005555set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556 char_u *name;
5557 int opt_idx;
5558 char_u *val;
5559 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005560 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005561{
5562 char_u *s;
5563 char_u **varp;
5564 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005565 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566
Bram Moolenaar89d40322006-08-29 15:30:07 +00005567 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005569 idx = findoption(name);
5570 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005571 {
5572 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575 }
5576
Bram Moolenaar89d40322006-08-29 15:30:07 +00005577 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 return;
5579
5580 s = vim_strsave(val);
5581 if (s != NULL)
5582 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005583 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005585 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005586 free_string_option(*varp);
5587 *varp = s;
5588
5589 /* For buffer/window local option may also set the global value. */
5590 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005591 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005592
Bram Moolenaar89d40322006-08-29 15:30:07 +00005593 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005594
5595 /* When setting both values of a global option with a local value,
5596 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005597 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598 {
5599 free_string_option(*varp);
5600 *varp = empty_option;
5601 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005602# ifdef FEAT_EVAL
5603 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005604 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005605 set_sid == 0 ? current_SID : set_sid);
5606# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607 }
5608}
5609
5610/*
5611 * Set global value for string option when it's a local option.
5612 */
5613 static void
5614set_string_option_global(opt_idx, varp)
5615 int opt_idx; /* option index */
5616 char_u **varp; /* pointer to option variable */
5617{
5618 char_u **p, *s;
5619
5620 /* the global value is always allocated */
5621 if (options[opt_idx].var == VAR_WIN)
5622 p = (char_u **)GLOBAL_WO(varp);
5623 else
5624 p = (char_u **)options[opt_idx].var;
5625 if (options[opt_idx].indir != PV_NONE
5626 && p != varp
5627 && (s = vim_strsave(*varp)) != NULL)
5628 {
5629 free_string_option(*p);
5630 *p = s;
5631 }
5632}
5633
5634/*
5635 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005636 *
5637 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005639 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640set_string_option(opt_idx, value, opt_flags)
5641 int opt_idx;
5642 char_u *value;
5643 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5644{
5645 char_u *s;
5646 char_u **varp;
5647 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005648 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649
5650 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005651 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652
5653 s = vim_strsave(value);
5654 if (s != NULL)
5655 {
5656 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5657 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005658 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005659 ? OPT_GLOBAL : OPT_LOCAL)
5660 : opt_flags);
5661 oldval = *varp;
5662 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005663 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5664 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005665 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005667 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668}
5669
5670/*
5671 * Handle string options that need some action to perform when changed.
5672 * Returns NULL for success, or an error message for an error.
5673 */
5674 static char_u *
5675did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5676 opt_flags)
5677 int opt_idx; /* index in options[] table */
5678 char_u **varp; /* pointer to the option variable */
5679 int new_value_alloced; /* new value was allocated */
5680 char_u *oldval; /* previous value of the option */
5681 char_u *errbuf; /* buffer for errors, or NULL */
5682 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5683{
5684 char_u *errmsg = NULL;
5685 char_u *s, *p;
5686 int did_chartab = FALSE;
5687 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005688 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005689#ifdef FEAT_GUI
5690 /* set when changing an option that only requires a redraw in the GUI */
5691 int redraw_gui_only = FALSE;
5692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693
5694 /* Get the global option to compare with, otherwise we would have to check
5695 * two values for all local options. */
5696 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5697
5698 /* Disallow changing some options from secure mode */
5699 if ((secure
5700#ifdef HAVE_SANDBOX
5701 || sandbox != 0
5702#endif
5703 ) && (options[opt_idx].flags & P_SECURE))
5704 {
5705 errmsg = e_secure;
5706 }
5707
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005708 /* Check for a "normal" file name in some options. Disallow a path
5709 * separator (slash and/or backslash), wildcards and characters that are
5710 * often illegal in a file name. */
5711 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005712 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005713 {
5714 errmsg = e_invarg;
5715 }
5716
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717 /* 'term' */
5718 else if (varp == &T_NAME)
5719 {
5720 if (T_NAME[0] == NUL)
5721 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5722#ifdef FEAT_GUI
5723 if (gui.in_use)
5724 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5725 else if (term_is_gui(T_NAME))
5726 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5727#endif
5728 else if (set_termname(T_NAME) == FAIL)
5729 errmsg = (char_u *)N_("E522: Not found in termcap");
5730 else
5731 /* Screen colors may have changed. */
5732 redraw_later_clear();
5733 }
5734
5735 /* 'backupcopy' */
5736 else if (varp == &p_bkc)
5737 {
5738 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5739 errmsg = e_invarg;
5740 if (((bkc_flags & BKC_AUTO) != 0)
5741 + ((bkc_flags & BKC_YES) != 0)
5742 + ((bkc_flags & BKC_NO) != 0) != 1)
5743 {
5744 /* Must have exactly one of "auto", "yes" and "no". */
5745 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5746 errmsg = e_invarg;
5747 }
5748 }
5749
5750 /* 'backupext' and 'patchmode' */
5751 else if (varp == &p_bex || varp == &p_pm)
5752 {
5753 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5754 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5755 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5756 }
5757
5758 /*
5759 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5760 * If the new option is invalid, use old value. 'lisp' option: refill
5761 * chartab[] for '-' char
5762 */
5763 else if ( varp == &p_isi
5764 || varp == &(curbuf->b_p_isk)
5765 || varp == &p_isp
5766 || varp == &p_isf)
5767 {
5768 if (init_chartab() == FAIL)
5769 {
5770 did_chartab = TRUE; /* need to restore it below */
5771 errmsg = e_invarg; /* error in value */
5772 }
5773 }
5774
5775 /* 'helpfile' */
5776 else if (varp == &p_hf)
5777 {
5778 /* May compute new values for $VIM and $VIMRUNTIME */
5779 if (didset_vim)
5780 {
5781 vim_setenv((char_u *)"VIM", (char_u *)"");
5782 didset_vim = FALSE;
5783 }
5784 if (didset_vimruntime)
5785 {
5786 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5787 didset_vimruntime = FALSE;
5788 }
5789 }
5790
Bram Moolenaar1a384422010-07-14 19:53:30 +02005791#ifdef FEAT_SYN_HL
5792 /* 'colorcolumn' */
5793 else if (varp == &curwin->w_p_cc)
5794 errmsg = check_colorcolumn(curwin);
5795#endif
5796
Bram Moolenaar071d4272004-06-13 20:20:40 +00005797#ifdef FEAT_MULTI_LANG
5798 /* 'helplang' */
5799 else if (varp == &p_hlg)
5800 {
5801 /* Check for "", "ab", "ab,cd", etc. */
5802 for (s = p_hlg; *s != NUL; s += 3)
5803 {
5804 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5805 {
5806 errmsg = e_invarg;
5807 break;
5808 }
5809 if (s[2] == NUL)
5810 break;
5811 }
5812 }
5813#endif
5814
5815 /* 'highlight' */
5816 else if (varp == &p_hl)
5817 {
5818 if (highlight_changed() == FAIL)
5819 errmsg = e_invarg; /* invalid flags */
5820 }
5821
5822 /* 'nrformats' */
5823 else if (gvarp == &p_nf)
5824 {
5825 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5826 errmsg = e_invarg;
5827 }
5828
5829#ifdef FEAT_SESSION
5830 /* 'sessionoptions' */
5831 else if (varp == &p_ssop)
5832 {
5833 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5834 errmsg = e_invarg;
5835 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5836 {
5837 /* Don't allow both "sesdir" and "curdir". */
5838 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5839 errmsg = e_invarg;
5840 }
5841 }
5842 /* 'viewoptions' */
5843 else if (varp == &p_vop)
5844 {
5845 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5846 errmsg = e_invarg;
5847 }
5848#endif
5849
5850 /* 'scrollopt' */
5851#ifdef FEAT_SCROLLBIND
5852 else if (varp == &p_sbo)
5853 {
5854 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5855 errmsg = e_invarg;
5856 }
5857#endif
5858
5859 /* 'ambiwidth' */
5860#ifdef FEAT_MBYTE
5861 else if (varp == &p_ambw)
5862 {
5863 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5864 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005865 else if (set_chars_option(&p_lcs) != NULL)
5866 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5867# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5868 else if (set_chars_option(&p_fcs) != NULL)
5869 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5870# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871 }
5872#endif
5873
5874 /* 'background' */
5875 else if (varp == &p_bg)
5876 {
5877 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5878 {
5879#ifdef FEAT_EVAL
5880 int dark = (*p_bg == 'd');
5881#endif
5882
5883 init_highlight(FALSE, FALSE);
5884
5885#ifdef FEAT_EVAL
5886 if (dark != (*p_bg == 'd')
5887 && get_var_value((char_u *)"g:colors_name") != NULL)
5888 {
5889 /* The color scheme must have set 'background' back to another
5890 * value, that's not what we want here. Disable the color
5891 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005892 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 free_string_option(p_bg);
5894 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5895 check_string_option(&p_bg);
5896 init_highlight(FALSE, FALSE);
5897 }
5898#endif
5899 }
5900 else
5901 errmsg = e_invarg;
5902 }
5903
5904 /* 'wildmode' */
5905 else if (varp == &p_wim)
5906 {
5907 if (check_opt_wim() == FAIL)
5908 errmsg = e_invarg;
5909 }
5910
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005911#ifdef FEAT_CMDL_COMPL
5912 /* 'wildoptions' */
5913 else if (varp == &p_wop)
5914 {
5915 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5916 errmsg = e_invarg;
5917 }
5918#endif
5919
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920#ifdef FEAT_WAK
5921 /* 'winaltkeys' */
5922 else if (varp == &p_wak)
5923 {
5924 if (*p_wak == NUL
5925 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5926 errmsg = e_invarg;
5927# ifdef FEAT_MENU
5928# ifdef FEAT_GUI_MOTIF
5929 else if (gui.in_use)
5930 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5931# else
5932# ifdef FEAT_GUI_GTK
5933 else if (gui.in_use)
5934 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5935# endif
5936# endif
5937# endif
5938 }
5939#endif
5940
5941#ifdef FEAT_AUTOCMD
5942 /* 'eventignore' */
5943 else if (varp == &p_ei)
5944 {
5945 if (check_ei() == FAIL)
5946 errmsg = e_invarg;
5947 }
5948#endif
5949
5950#ifdef FEAT_MBYTE
5951 /* 'encoding' and 'fileencoding' */
5952 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5953 {
5954 if (gvarp == &p_fenc)
5955 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005956 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005957 errmsg = e_modifiable;
5958 else if (vim_strchr(*varp, ',') != NULL)
5959 /* No comma allowed in 'fileencoding'; catches confusing it
5960 * with 'fileencodings'. */
5961 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005963 {
5964# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005966 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005967# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005968 /* Add 'fileencoding' to the swap file. */
5969 ml_setflags(curbuf);
5970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971 }
5972 if (errmsg == NULL)
5973 {
5974 /* canonize the value, so that STRCMP() can be used on it */
5975 p = enc_canonize(*varp);
5976 if (p != NULL)
5977 {
5978 vim_free(*varp);
5979 *varp = p;
5980 }
5981 if (varp == &p_enc)
5982 {
5983 errmsg = mb_init();
5984# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005985 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005986# endif
5987 }
5988 }
5989
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005990# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5992 {
5993 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5994 if (STRCMP(p_tenc, "utf-8") != 0)
5995 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5996 }
5997# endif
5998
5999 if (errmsg == NULL)
6000 {
6001# ifdef FEAT_KEYMAP
6002 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6003 * (with another encoding). */
6004 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6005 (void)keymap_init();
6006# endif
6007
6008 /* When 'termencoding' is not empty and 'encoding' changes or when
6009 * 'termencoding' changes, need to setup for keyboard input and
6010 * display output conversion. */
6011 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6012 {
6013 convert_setup(&input_conv, p_tenc, p_enc);
6014 convert_setup(&output_conv, p_enc, p_tenc);
6015 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006016
6017# if defined(WIN3264) && defined(FEAT_MBYTE)
6018 /* $HOME may have characters in active code page. */
6019 if (varp == &p_enc)
6020 init_homedir();
6021# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006022 }
6023 }
6024#endif
6025
6026#if defined(FEAT_POSTSCRIPT)
6027 else if (varp == &p_penc)
6028 {
6029 /* Canonize printencoding if VIM standard one */
6030 p = enc_canonize(p_penc);
6031 if (p != NULL)
6032 {
6033 vim_free(p_penc);
6034 p_penc = p;
6035 }
6036 else
6037 {
6038 /* Ensure lower case and '-' for '_' */
6039 for (s = p_penc; *s != NUL; s++)
6040 {
6041 if (*s == '_')
6042 *s = '-';
6043 else
6044 *s = TOLOWER_ASC(*s);
6045 }
6046 }
6047 }
6048#endif
6049
Bram Moolenaar9372a112005-12-06 19:59:18 +00006050#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006051 else if (varp == &p_imak)
6052 {
6053 if (gui.in_use && !im_xim_isvalid_imactivate())
6054 errmsg = e_invarg;
6055 }
6056#endif
6057
6058#ifdef FEAT_KEYMAP
6059 else if (varp == &curbuf->b_p_keymap)
6060 {
6061 /* load or unload key mapping tables */
6062 errmsg = keymap_init();
6063
Bram Moolenaarfab06232009-03-04 03:13:35 +00006064 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006065 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006066 if (*curbuf->b_p_keymap != NUL)
6067 {
6068 /* Installed a new keymap, switch on using it. */
6069 curbuf->b_p_iminsert = B_IMODE_LMAP;
6070 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6071 curbuf->b_p_imsearch = B_IMODE_LMAP;
6072 }
6073 else
6074 {
6075 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6076 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6077 curbuf->b_p_iminsert = B_IMODE_NONE;
6078 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6079 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6080 }
6081 if ((opt_flags & OPT_LOCAL) == 0)
6082 {
6083 set_iminsert_global();
6084 set_imsearch_global();
6085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086# ifdef FEAT_WINDOWS
6087 status_redraw_curbuf();
6088# endif
6089 }
6090 }
6091#endif
6092
6093 /* 'fileformat' */
6094 else if (gvarp == &p_ff)
6095 {
6096 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6097 errmsg = e_modifiable;
6098 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6099 errmsg = e_invarg;
6100 else
6101 {
6102 /* may also change 'textmode' */
6103 if (get_fileformat(curbuf) == EOL_DOS)
6104 curbuf->b_p_tx = TRUE;
6105 else
6106 curbuf->b_p_tx = FALSE;
6107#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006108 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006110 /* update flag in swap file */
6111 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006112 /* Redraw needed when switching to/from "mac": a CR in the text
6113 * will be displayed differently. */
6114 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6115 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 }
6117 }
6118
6119 /* 'fileformats' */
6120 else if (varp == &p_ffs)
6121 {
6122 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6123 errmsg = e_invarg;
6124 else
6125 {
6126 /* also change 'textauto' */
6127 if (*p_ffs == NUL)
6128 p_ta = FALSE;
6129 else
6130 p_ta = TRUE;
6131 }
6132 }
6133
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006134#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135 /* 'cryptkey' */
6136 else if (gvarp == &p_key)
6137 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006138# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139 /* Make sure the ":set" command doesn't show the new value in the
6140 * history. */
6141 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006142# endif
6143 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6144 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006145 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6146 }
6147
6148 else if (gvarp == &p_cm)
6149 {
6150 if (opt_flags & OPT_LOCAL)
6151 p = curbuf->b_p_cm;
6152 else
6153 p = p_cm;
6154 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6155 errmsg = e_invarg;
6156 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6157 errmsg = e_invarg;
6158 else
6159 {
6160 /* When setting the global value to empty, make it "zip". */
6161 if (*p_cm == NUL)
6162 {
6163 if (new_value_alloced)
6164 free_string_option(p_cm);
6165 p_cm = vim_strsave((char_u *)"zip");
6166 new_value_alloced = TRUE;
6167 }
6168
6169 /* Need to update the swapfile when the effective method changed.
6170 * Set "s" to the effective old value, "p" to the effective new
6171 * method and compare. */
6172 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6173 s = p_cm; /* was previously using the global value */
6174 else
6175 s = oldval;
6176 if (*curbuf->b_p_cm == NUL)
6177 p = p_cm; /* is now using the global value */
6178 else
6179 p = curbuf->b_p_cm;
6180 if (STRCMP(s, p) != 0)
6181 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6182 crypt_method_from_string(s));
6183
6184 /* If the global value changes need to update the swapfile for all
6185 * buffers using that value. */
6186 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6187 {
6188 buf_T *buf;
6189
6190 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6191 if (buf != curbuf && *buf->b_p_cm == NUL)
6192 ml_set_crypt_key(buf, buf->b_p_key,
6193 crypt_method_from_string(oldval));
6194 }
6195 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006196 }
6197#endif
6198
6199 /* 'matchpairs' */
6200 else if (gvarp == &p_mps)
6201 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006202#ifdef FEAT_MBYTE
6203 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006204 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006205 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006206 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006207 int x2 = -1;
6208 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006209
6210 if (*p != NUL)
6211 p += mb_ptr2len(p);
6212 if (*p != NUL)
6213 x2 = *p++;
6214 if (*p != NUL)
6215 {
6216 x3 = mb_ptr2char(p);
6217 p += mb_ptr2len(p);
6218 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006219 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006220 {
6221 errmsg = e_invarg;
6222 break;
6223 }
6224 if (*p == NUL)
6225 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006226 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006227 }
6228 else
6229#endif
6230 {
6231 /* Check for "x:y,x:y" */
6232 for (p = *varp; *p != NUL; p += 4)
6233 {
6234 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6235 {
6236 errmsg = e_invarg;
6237 break;
6238 }
6239 if (p[3] == NUL)
6240 break;
6241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006242 }
6243 }
6244
6245#ifdef FEAT_COMMENTS
6246 /* 'comments' */
6247 else if (gvarp == &p_com)
6248 {
6249 for (s = *varp; *s; )
6250 {
6251 while (*s && *s != ':')
6252 {
6253 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6254 && !VIM_ISDIGIT(*s) && *s != '-')
6255 {
6256 errmsg = illegal_char(errbuf, *s);
6257 break;
6258 }
6259 ++s;
6260 }
6261 if (*s++ == NUL)
6262 errmsg = (char_u *)N_("E524: Missing colon");
6263 else if (*s == ',' || *s == NUL)
6264 errmsg = (char_u *)N_("E525: Zero length string");
6265 if (errmsg != NULL)
6266 break;
6267 while (*s && *s != ',')
6268 {
6269 if (*s == '\\' && s[1] != NUL)
6270 ++s;
6271 ++s;
6272 }
6273 s = skip_to_option_part(s);
6274 }
6275 }
6276#endif
6277
6278 /* 'listchars' */
6279 else if (varp == &p_lcs)
6280 {
6281 errmsg = set_chars_option(varp);
6282 }
6283
6284#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6285 /* 'fillchars' */
6286 else if (varp == &p_fcs)
6287 {
6288 errmsg = set_chars_option(varp);
6289 }
6290#endif
6291
6292#ifdef FEAT_CMDWIN
6293 /* 'cedit' */
6294 else if (varp == &p_cedit)
6295 {
6296 errmsg = check_cedit();
6297 }
6298#endif
6299
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006300 /* 'verbosefile' */
6301 else if (varp == &p_vfile)
6302 {
6303 verbose_stop();
6304 if (*p_vfile != NUL && verbose_open() == FAIL)
6305 errmsg = e_invarg;
6306 }
6307
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308#ifdef FEAT_VIMINFO
6309 /* 'viminfo' */
6310 else if (varp == &p_viminfo)
6311 {
6312 for (s = p_viminfo; *s;)
6313 {
6314 /* Check it's a valid character */
6315 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6316 {
6317 errmsg = illegal_char(errbuf, *s);
6318 break;
6319 }
6320 if (*s == 'n') /* name is always last one */
6321 {
6322 break;
6323 }
6324 else if (*s == 'r') /* skip until next ',' */
6325 {
6326 while (*++s && *s != ',')
6327 ;
6328 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006329 else if (*s == '%')
6330 {
6331 /* optional number */
6332 while (vim_isdigit(*++s))
6333 ;
6334 }
6335 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006336 ++s; /* no extra chars */
6337 else /* must have a number */
6338 {
6339 while (vim_isdigit(*++s))
6340 ;
6341
6342 if (!VIM_ISDIGIT(*(s - 1)))
6343 {
6344 if (errbuf != NULL)
6345 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006346 sprintf((char *)errbuf,
6347 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 transchar_byte(*(s - 1)));
6349 errmsg = errbuf;
6350 }
6351 else
6352 errmsg = (char_u *)"";
6353 break;
6354 }
6355 }
6356 if (*s == ',')
6357 ++s;
6358 else if (*s)
6359 {
6360 if (errbuf != NULL)
6361 errmsg = (char_u *)N_("E527: Missing comma");
6362 else
6363 errmsg = (char_u *)"";
6364 break;
6365 }
6366 }
6367 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6368 errmsg = (char_u *)N_("E528: Must specify a ' value");
6369 }
6370#endif /* FEAT_VIMINFO */
6371
6372 /* terminal options */
6373 else if (istermoption(&options[opt_idx]) && full_screen)
6374 {
6375 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6376 if (varp == &T_CCO)
6377 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006378 int colors = atoi((char *)T_CCO);
6379
6380 /* Only reinitialize colors if t_Co value has really changed to
6381 * avoid expensive reload of colorscheme if t_Co is set to the
6382 * same value multiple times. */
6383 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006384 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006385 t_colors = colors;
6386 if (t_colors <= 1)
6387 {
6388 if (new_value_alloced)
6389 vim_free(T_CCO);
6390 T_CCO = empty_option;
6391 }
6392 /* We now have a different color setup, initialize it again. */
6393 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006394 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006395 }
6396 ttest(FALSE);
6397 if (varp == &T_ME)
6398 {
6399 out_str(T_ME);
6400 redraw_later(CLEAR);
6401#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6402 /* Since t_me has been set, this probably means that the user
6403 * wants to use this as default colors. Need to reset default
6404 * background/foreground colors. */
6405 mch_set_normal_colors();
6406#endif
6407 }
6408 }
6409
6410#ifdef FEAT_LINEBREAK
6411 /* 'showbreak' */
6412 else if (varp == &p_sbr)
6413 {
6414 for (s = p_sbr; *s; )
6415 {
6416 if (ptr2cells(s) != 1)
6417 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006418 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006419 }
6420 }
6421#endif
6422
6423#ifdef FEAT_GUI
6424 /* 'guifont' */
6425 else if (varp == &p_guifont)
6426 {
6427 if (gui.in_use)
6428 {
6429 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006430# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006431 /*
6432 * Put up a font dialog and let the user select a new value.
6433 * If this is cancelled go back to the old value but don't
6434 * give an error message.
6435 */
6436 if (STRCMP(p, "*") == 0)
6437 {
6438 p = gui_mch_font_dialog(oldval);
6439
6440 if (new_value_alloced)
6441 free_string_option(p_guifont);
6442
6443 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6444 new_value_alloced = TRUE;
6445 }
6446# endif
6447 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6448 {
6449# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6450 if (STRCMP(p_guifont, "*") == 0)
6451 {
6452 /* Dialog was cancelled: Keep the old value without giving
6453 * an error message. */
6454 if (new_value_alloced)
6455 free_string_option(p_guifont);
6456 p_guifont = vim_strsave(oldval);
6457 new_value_alloced = TRUE;
6458 }
6459 else
6460# endif
6461 errmsg = (char_u *)N_("E596: Invalid font(s)");
6462 }
6463 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006464 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006465 }
6466# ifdef FEAT_XFONTSET
6467 else if (varp == &p_guifontset)
6468 {
6469 if (STRCMP(p_guifontset, "*") == 0)
6470 errmsg = (char_u *)N_("E597: can't select fontset");
6471 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6472 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006473 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006474 }
6475# endif
6476# ifdef FEAT_MBYTE
6477 else if (varp == &p_guifontwide)
6478 {
6479 if (STRCMP(p_guifontwide, "*") == 0)
6480 errmsg = (char_u *)N_("E533: can't select wide font");
6481 else if (gui_get_wide_font() == FAIL)
6482 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006483 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484 }
6485# endif
6486#endif
6487
6488#ifdef CURSOR_SHAPE
6489 /* 'guicursor' */
6490 else if (varp == &p_guicursor)
6491 errmsg = parse_shape_opt(SHAPE_CURSOR);
6492#endif
6493
6494#ifdef FEAT_MOUSESHAPE
6495 /* 'mouseshape' */
6496 else if (varp == &p_mouseshape)
6497 {
6498 errmsg = parse_shape_opt(SHAPE_MOUSE);
6499 update_mouseshape(-1);
6500 }
6501#endif
6502
6503#ifdef FEAT_PRINTER
6504 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006505 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006506# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006507 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006508 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006509# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006510#endif
6511
6512#ifdef FEAT_LANGMAP
6513 /* 'langmap' */
6514 else if (varp == &p_langmap)
6515 langmap_set();
6516#endif
6517
6518#ifdef FEAT_LINEBREAK
6519 /* 'breakat' */
6520 else if (varp == &p_breakat)
6521 fill_breakat_flags();
6522#endif
6523
6524#ifdef FEAT_TITLE
6525 /* 'titlestring' and 'iconstring' */
6526 else if (varp == &p_titlestring || varp == &p_iconstring)
6527 {
6528# ifdef FEAT_STL_OPT
6529 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6530
6531 /* NULL => statusline syntax */
6532 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6533 stl_syntax |= flagval;
6534 else
6535 stl_syntax &= ~flagval;
6536# endif
6537 did_set_title(varp == &p_iconstring);
6538
6539 }
6540#endif
6541
6542#ifdef FEAT_GUI
6543 /* 'guioptions' */
6544 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006545 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006546 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006547 redraw_gui_only = TRUE;
6548 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549#endif
6550
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006551#if defined(FEAT_GUI_TABLINE)
6552 /* 'guitablabel' */
6553 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006554 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006555 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006556 redraw_gui_only = TRUE;
6557 }
6558 /* 'guitabtooltip' */
6559 else if (varp == &p_gtt)
6560 {
6561 redraw_gui_only = TRUE;
6562 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006563#endif
6564
Bram Moolenaar071d4272004-06-13 20:20:40 +00006565#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6566 /* 'ttymouse' */
6567 else if (varp == &p_ttym)
6568 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006569 /* Switch the mouse off before changing the escape sequences used for
6570 * that. */
6571 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006572 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6573 errmsg = e_invarg;
6574 else
6575 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006576 if (termcap_active)
6577 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 }
6579#endif
6580
6581#ifdef FEAT_VISUAL
6582 /* 'selection' */
6583 else if (varp == &p_sel)
6584 {
6585 if (*p_sel == NUL
6586 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6587 errmsg = e_invarg;
6588 }
6589
6590 /* 'selectmode' */
6591 else if (varp == &p_slm)
6592 {
6593 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6594 errmsg = e_invarg;
6595 }
6596#endif
6597
6598#ifdef FEAT_BROWSE
6599 /* 'browsedir' */
6600 else if (varp == &p_bsdir)
6601 {
6602 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6603 && !mch_isdir(p_bsdir))
6604 errmsg = e_invarg;
6605 }
6606#endif
6607
6608#ifdef FEAT_VISUAL
6609 /* 'keymodel' */
6610 else if (varp == &p_km)
6611 {
6612 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6613 errmsg = e_invarg;
6614 else
6615 {
6616 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6617 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6618 }
6619 }
6620#endif
6621
6622 /* 'mousemodel' */
6623 else if (varp == &p_mousem)
6624 {
6625 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6626 errmsg = e_invarg;
6627#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6628 else if (*p_mousem != *oldval)
6629 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6630 * to create or delete the popup menus. */
6631 gui_motif_update_mousemodel(root_menu);
6632#endif
6633 }
6634
6635 /* 'switchbuf' */
6636 else if (varp == &p_swb)
6637 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006638 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006639 errmsg = e_invarg;
6640 }
6641
6642 /* 'debug' */
6643 else if (varp == &p_debug)
6644 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006645 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006646 errmsg = e_invarg;
6647 }
6648
6649 /* 'display' */
6650 else if (varp == &p_dy)
6651 {
6652 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6653 errmsg = e_invarg;
6654 else
6655 (void)init_chartab();
6656
6657 }
6658
6659#ifdef FEAT_VERTSPLIT
6660 /* 'eadirection' */
6661 else if (varp == &p_ead)
6662 {
6663 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6664 errmsg = e_invarg;
6665 }
6666#endif
6667
6668#ifdef FEAT_CLIPBOARD
6669 /* 'clipboard' */
6670 else if (varp == &p_cb)
6671 errmsg = check_clipboard_option();
6672#endif
6673
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006674#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006675 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6676 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006677 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006678 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006679 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006680 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006681
Bram Moolenaar860cae12010-06-05 23:22:07 +02006682 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006683 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006684 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6685 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006686 ".add") != 0))
6687 errmsg = e_invarg;
6688 }
6689
6690 if (errmsg == NULL)
6691 {
6692 FOR_ALL_WINDOWS(wp)
6693 if (wp->w_buffer == curbuf && wp->w_p_spell)
6694 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006695 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006696# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006697 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006698# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006699 }
6700 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006701 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006702 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006703 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006704 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006705 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006706 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006707 /* 'spellsuggest' */
6708 else if (varp == &p_sps)
6709 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006710 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006711 errmsg = e_invarg;
6712 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006713 /* 'mkspellmem' */
6714 else if (varp == &p_msm)
6715 {
6716 if (spell_check_msm() != OK)
6717 errmsg = e_invarg;
6718 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006719#endif
6720
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721#ifdef FEAT_QUICKFIX
6722 /* When 'bufhidden' is set, check for valid value. */
6723 else if (gvarp == &p_bh)
6724 {
6725 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6726 errmsg = e_invarg;
6727 }
6728
6729 /* When 'buftype' is set, check for valid value. */
6730 else if (gvarp == &p_bt)
6731 {
6732 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6733 errmsg = e_invarg;
6734 else
6735 {
6736# ifdef FEAT_WINDOWS
6737 if (curwin->w_status_height)
6738 {
6739 curwin->w_redr_status = TRUE;
6740 redraw_later(VALID);
6741 }
6742# endif
6743 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006744# ifdef FEAT_TITLE
6745 redraw_titles();
6746# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747 }
6748 }
6749#endif
6750
6751#ifdef FEAT_STL_OPT
6752 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006753 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 {
6755 int wid;
6756
6757 if (varp == &p_ruf) /* reset ru_wid first */
6758 ru_wid = 0;
6759 s = *varp;
6760 if (varp == &p_ruf && *s == '%')
6761 {
6762 /* set ru_wid if 'ruf' starts with "%99(" */
6763 if (*++s == '-') /* ignore a '-' */
6764 s++;
6765 wid = getdigits(&s);
6766 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6767 ru_wid = wid;
6768 else
6769 errmsg = check_stl_option(p_ruf);
6770 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006771 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006772 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006774 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 comp_col();
6776 }
6777#endif
6778
6779#ifdef FEAT_INS_EXPAND
6780 /* check if it is a valid value for 'complete' -- Acevedo */
6781 else if (gvarp == &p_cpt)
6782 {
6783 for (s = *varp; *s;)
6784 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006785 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 s++;
6787 if (!*s)
6788 break;
6789 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6790 {
6791 errmsg = illegal_char(errbuf, *s);
6792 break;
6793 }
6794 if (*++s != NUL && *s != ',' && *s != ' ')
6795 {
6796 if (s[-1] == 'k' || s[-1] == 's')
6797 {
6798 /* skip optional filename after 'k' and 's' */
6799 while (*s && *s != ',' && *s != ' ')
6800 {
6801 if (*s == '\\')
6802 ++s;
6803 ++s;
6804 }
6805 }
6806 else
6807 {
6808 if (errbuf != NULL)
6809 {
6810 sprintf((char *)errbuf,
6811 _("E535: Illegal character after <%c>"),
6812 *--s);
6813 errmsg = errbuf;
6814 }
6815 else
6816 errmsg = (char_u *)"";
6817 break;
6818 }
6819 }
6820 }
6821 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006822
6823 /* 'completeopt' */
6824 else if (varp == &p_cot)
6825 {
6826 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6827 errmsg = e_invarg;
6828 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829#endif /* FEAT_INS_EXPAND */
6830
6831
6832#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6833 else if (varp == &p_toolbar)
6834 {
6835 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6836 &toolbar_flags, TRUE) != OK)
6837 errmsg = e_invarg;
6838 else
6839 {
6840 out_flush();
6841 gui_mch_show_toolbar((toolbar_flags &
6842 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6843 }
6844 }
6845#endif
6846
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006847#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006848 /* 'toolbariconsize': GTK+ 2 only */
6849 else if (varp == &p_tbis)
6850 {
6851 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6852 errmsg = e_invarg;
6853 else
6854 {
6855 out_flush();
6856 gui_mch_show_toolbar((toolbar_flags &
6857 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6858 }
6859 }
6860#endif
6861
6862 /* 'pastetoggle': translate key codes like in a mapping */
6863 else if (varp == &p_pt)
6864 {
6865 if (*p_pt)
6866 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006867 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006868 if (p != NULL)
6869 {
6870 if (new_value_alloced)
6871 free_string_option(p_pt);
6872 p_pt = p;
6873 new_value_alloced = TRUE;
6874 }
6875 }
6876 }
6877
6878 /* 'backspace' */
6879 else if (varp == &p_bs)
6880 {
6881 if (VIM_ISDIGIT(*p_bs))
6882 {
6883 if (*p_bs >'2' || p_bs[1] != NUL)
6884 errmsg = e_invarg;
6885 }
6886 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6887 errmsg = e_invarg;
6888 }
6889
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006890#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006891 /* 'casemap' */
6892 else if (varp == &p_cmp)
6893 {
6894 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6895 errmsg = e_invarg;
6896 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006897#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898
6899#ifdef FEAT_DIFF
6900 /* 'diffopt' */
6901 else if (varp == &p_dip)
6902 {
6903 if (diffopt_changed() == FAIL)
6904 errmsg = e_invarg;
6905 }
6906#endif
6907
6908#ifdef FEAT_FOLDING
6909 /* 'foldmethod' */
6910 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6911 {
6912 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6913 || *curwin->w_p_fdm == NUL)
6914 errmsg = e_invarg;
6915 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006916 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006918 if (foldmethodIsDiff(curwin))
6919 newFoldLevel();
6920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006921 }
6922# ifdef FEAT_EVAL
6923 /* 'foldexpr' */
6924 else if (varp == &curwin->w_p_fde)
6925 {
6926 if (foldmethodIsExpr(curwin))
6927 foldUpdateAll(curwin);
6928 }
6929# endif
6930 /* 'foldmarker' */
6931 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6932 {
6933 p = vim_strchr(*varp, ',');
6934 if (p == NULL)
6935 errmsg = (char_u *)N_("E536: comma required");
6936 else if (p == *varp || p[1] == NUL)
6937 errmsg = e_invarg;
6938 else if (foldmethodIsMarker(curwin))
6939 foldUpdateAll(curwin);
6940 }
6941 /* 'commentstring' */
6942 else if (gvarp == &p_cms)
6943 {
6944 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6945 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6946 }
6947 /* 'foldopen' */
6948 else if (varp == &p_fdo)
6949 {
6950 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6951 errmsg = e_invarg;
6952 }
6953 /* 'foldclose' */
6954 else if (varp == &p_fcl)
6955 {
6956 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6957 errmsg = e_invarg;
6958 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006959 /* 'foldignore' */
6960 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6961 {
6962 if (foldmethodIsIndent(curwin))
6963 foldUpdateAll(curwin);
6964 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965#endif
6966
6967#ifdef FEAT_VIRTUALEDIT
6968 /* 'virtualedit' */
6969 else if (varp == &p_ve)
6970 {
6971 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6972 errmsg = e_invarg;
6973 else if (STRCMP(p_ve, oldval) != 0)
6974 {
6975 /* Recompute cursor position in case the new 've' setting
6976 * changes something. */
6977 validate_virtcol();
6978 coladvance(curwin->w_virtcol);
6979 }
6980 }
6981#endif
6982
6983#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6984 else if (varp == &p_csqf)
6985 {
6986 if (p_csqf != NULL)
6987 {
6988 p = p_csqf;
6989 while (*p != NUL)
6990 {
6991 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6992 || p[1] == NUL
6993 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6994 || (p[2] != NUL && p[2] != ','))
6995 {
6996 errmsg = e_invarg;
6997 break;
6998 }
6999 else if (p[2] == NUL)
7000 break;
7001 else
7002 p += 3;
7003 }
7004 }
7005 }
7006#endif
7007
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007008#ifdef FEAT_CINDENT
7009 /* 'cinoptions' */
7010 else if (gvarp == &p_cino)
7011 {
7012 /* TODO: recognize errors */
7013 parse_cino(curbuf);
7014 }
7015#endif
7016
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 /* Options that are a list of flags. */
7018 else
7019 {
7020 p = NULL;
7021 if (varp == &p_ww)
7022 p = (char_u *)WW_ALL;
7023 if (varp == &p_shm)
7024 p = (char_u *)SHM_ALL;
7025 else if (varp == &(p_cpo))
7026 p = (char_u *)CPO_ALL;
7027 else if (varp == &(curbuf->b_p_fo))
7028 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007029#ifdef FEAT_CONCEAL
7030 else if (varp == &curwin->w_p_cocu)
7031 p = (char_u *)COCU_ALL;
7032#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007033 else if (varp == &p_mouse)
7034 {
7035#ifdef FEAT_MOUSE
7036 p = (char_u *)MOUSE_ALL;
7037#else
7038 if (*p_mouse != NUL)
7039 errmsg = (char_u *)N_("E538: No mouse support");
7040#endif
7041 }
7042#if defined(FEAT_GUI)
7043 else if (varp == &p_go)
7044 p = (char_u *)GO_ALL;
7045#endif
7046 if (p != NULL)
7047 {
7048 for (s = *varp; *s; ++s)
7049 if (vim_strchr(p, *s) == NULL)
7050 {
7051 errmsg = illegal_char(errbuf, *s);
7052 break;
7053 }
7054 }
7055 }
7056
7057 /*
7058 * If error detected, restore the previous value.
7059 */
7060 if (errmsg != NULL)
7061 {
7062 if (new_value_alloced)
7063 free_string_option(*varp);
7064 *varp = oldval;
7065 /*
7066 * When resetting some values, need to act on it.
7067 */
7068 if (did_chartab)
7069 (void)init_chartab();
7070 if (varp == &p_hl)
7071 (void)highlight_changed();
7072 }
7073 else
7074 {
7075#ifdef FEAT_EVAL
7076 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007077 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078#endif
7079 /*
7080 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007081 * Use "free_oldval", because recursiveness may change the flags under
7082 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007083 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007084 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085 free_string_option(oldval);
7086 if (new_value_alloced)
7087 options[opt_idx].flags |= P_ALLOCED;
7088 else
7089 options[opt_idx].flags &= ~P_ALLOCED;
7090
7091 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007092 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007093 {
7094 /* global option with local value set to use global value; free
7095 * the local value and make it empty */
7096 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7097 free_string_option(*(char_u **)p);
7098 *(char_u **)p = empty_option;
7099 }
7100
7101 /* May set global value for local option. */
7102 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7103 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007104
7105#ifdef FEAT_AUTOCMD
7106 /*
7107 * Trigger the autocommand only after setting the flags.
7108 */
7109# ifdef FEAT_SYN_HL
7110 /* When 'syntax' is set, load the syntax of that name */
7111 if (varp == &(curbuf->b_p_syn))
7112 {
7113 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7114 curbuf->b_fname, TRUE, curbuf);
7115 }
7116# endif
7117 else if (varp == &(curbuf->b_p_ft))
7118 {
7119 /* 'filetype' is set, trigger the FileType autocommand */
7120 did_filetype = TRUE;
7121 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7122 curbuf->b_fname, TRUE, curbuf);
7123 }
7124#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007125#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007126 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007127 {
7128 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007129 char_u *q = curwin->w_s->b_p_spl;
7130
7131 /* Skip the first name if it is "cjk". */
7132 if (STRNCMP(q, "cjk,", 4) == 0)
7133 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007134
7135 /*
7136 * Source the spell/LANG.vim in 'runtimepath'.
7137 * They could set 'spellcapcheck' depending on the language.
7138 * Use the first name in 'spelllang' up to '_region' or
7139 * '.encoding'.
7140 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007141 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007142 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7143 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007144 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007145 source_runtime(fname, TRUE);
7146 }
7147#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 }
7149
7150#ifdef FEAT_MOUSE
7151 if (varp == &p_mouse)
7152 {
7153# ifdef FEAT_MOUSE_TTY
7154 if (*p_mouse == NUL)
7155 mch_setmouse(FALSE); /* switch mouse off */
7156 else
7157# endif
7158 setmouse(); /* in case 'mouse' changed */
7159 }
7160#endif
7161
Bram Moolenaar913077c2012-03-28 19:59:04 +02007162 if (curwin->w_curswant != MAXCOL
7163 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7164 curwin->w_set_curswant = TRUE;
7165
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007166#ifdef FEAT_GUI
7167 /* check redraw when it's not a GUI option or the GUI is active. */
7168 if (!redraw_gui_only || gui.in_use)
7169#endif
7170 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007171
7172 return errmsg;
7173}
7174
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007175#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007176/*
7177 * Simple int comparison function for use with qsort()
7178 */
7179 static int
7180int_cmp(a, b)
7181 const void *a;
7182 const void *b;
7183{
7184 return *(const int *)a - *(const int *)b;
7185}
7186
7187/*
7188 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7189 * Returns error message, NULL if it's OK.
7190 */
7191 char_u *
7192check_colorcolumn(wp)
7193 win_T *wp;
7194{
7195 char_u *s;
7196 int col;
7197 int count = 0;
7198 int color_cols[256];
7199 int i;
7200 int j = 0;
7201
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007202 if (wp->w_buffer == NULL)
7203 return NULL; /* buffer was closed */
7204
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007205 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007206 {
7207 if (*s == '-' || *s == '+')
7208 {
7209 /* -N and +N: add to 'textwidth' */
7210 col = (*s == '-') ? -1 : 1;
7211 ++s;
7212 if (!VIM_ISDIGIT(*s))
7213 return e_invarg;
7214 col = col * getdigits(&s);
7215 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007216 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007217 col += wp->w_buffer->b_p_tw;
7218 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007219 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007220 }
7221 else if (VIM_ISDIGIT(*s))
7222 col = getdigits(&s);
7223 else
7224 return e_invarg;
7225 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007226skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007227 if (*s == NUL)
7228 break;
7229 if (*s != ',')
7230 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007231 if (*++s == NUL)
7232 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007233 }
7234
7235 vim_free(wp->w_p_cc_cols);
7236 if (count == 0)
7237 wp->w_p_cc_cols = NULL;
7238 else
7239 {
7240 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7241 if (wp->w_p_cc_cols != NULL)
7242 {
7243 /* sort the columns for faster usage on screen redraw inside
7244 * win_line() */
7245 qsort(color_cols, count, sizeof(int), int_cmp);
7246
7247 for (i = 0; i < count; ++i)
7248 /* skip duplicates */
7249 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7250 wp->w_p_cc_cols[j++] = color_cols[i];
7251 wp->w_p_cc_cols[j] = -1; /* end marker */
7252 }
7253 }
7254
7255 return NULL; /* no error */
7256}
7257#endif
7258
Bram Moolenaar071d4272004-06-13 20:20:40 +00007259/*
7260 * Handle setting 'listchars' or 'fillchars'.
7261 * Returns error message, NULL if it's OK.
7262 */
7263 static char_u *
7264set_chars_option(varp)
7265 char_u **varp;
7266{
7267 int round, i, len, entries;
7268 char_u *p, *s;
7269 int c1, c2 = 0;
7270 struct charstab
7271 {
7272 int *cp;
7273 char *name;
7274 };
7275#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7276 static struct charstab filltab[] =
7277 {
7278 {&fill_stl, "stl"},
7279 {&fill_stlnc, "stlnc"},
7280 {&fill_vert, "vert"},
7281 {&fill_fold, "fold"},
7282 {&fill_diff, "diff"},
7283 };
7284#endif
7285 static struct charstab lcstab[] =
7286 {
7287 {&lcs_eol, "eol"},
7288 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007289 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007290 {&lcs_prec, "precedes"},
7291 {&lcs_tab2, "tab"},
7292 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007293#ifdef FEAT_CONCEAL
7294 {&lcs_conceal, "conceal"},
7295#else
7296 {NULL, "conceal"},
7297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007298 };
7299 struct charstab *tab;
7300
7301#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7302 if (varp == &p_lcs)
7303#endif
7304 {
7305 tab = lcstab;
7306 entries = sizeof(lcstab) / sizeof(struct charstab);
7307 }
7308#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7309 else
7310 {
7311 tab = filltab;
7312 entries = sizeof(filltab) / sizeof(struct charstab);
7313 }
7314#endif
7315
7316 /* first round: check for valid value, second round: assign values */
7317 for (round = 0; round <= 1; ++round)
7318 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007319 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 {
7321 /* After checking that the value is valid: set defaults: space for
7322 * 'fillchars', NUL for 'listchars' */
7323 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007324 if (tab[i].cp != NULL)
7325 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007326 if (varp == &p_lcs)
7327 lcs_tab1 = NUL;
7328#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7329 else
7330 fill_diff = '-';
7331#endif
7332 }
7333 p = *varp;
7334 while (*p)
7335 {
7336 for (i = 0; i < entries; ++i)
7337 {
7338 len = (int)STRLEN(tab[i].name);
7339 if (STRNCMP(p, tab[i].name, len) == 0
7340 && p[len] == ':'
7341 && p[len + 1] != NUL)
7342 {
7343 s = p + len + 1;
7344#ifdef FEAT_MBYTE
7345 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007346 if (mb_char2cells(c1) > 1)
7347 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007348#else
7349 c1 = *s++;
7350#endif
7351 if (tab[i].cp == &lcs_tab2)
7352 {
7353 if (*s == NUL)
7354 continue;
7355#ifdef FEAT_MBYTE
7356 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007357 if (mb_char2cells(c2) > 1)
7358 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359#else
7360 c2 = *s++;
7361#endif
7362 }
7363 if (*s == ',' || *s == NUL)
7364 {
7365 if (round)
7366 {
7367 if (tab[i].cp == &lcs_tab2)
7368 {
7369 lcs_tab1 = c1;
7370 lcs_tab2 = c2;
7371 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007372 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007373 *(tab[i].cp) = c1;
7374
7375 }
7376 p = s;
7377 break;
7378 }
7379 }
7380 }
7381
7382 if (i == entries)
7383 return e_invarg;
7384 if (*p == ',')
7385 ++p;
7386 }
7387 }
7388
7389 return NULL; /* no error */
7390}
7391
7392#ifdef FEAT_STL_OPT
7393/*
7394 * Check validity of options with the 'statusline' format.
7395 * Return error message or NULL.
7396 */
7397 char_u *
7398check_stl_option(s)
7399 char_u *s;
7400{
7401 int itemcnt = 0;
7402 int groupdepth = 0;
7403 static char_u errbuf[80];
7404
7405 while (*s && itemcnt < STL_MAX_ITEM)
7406 {
7407 /* Check for valid keys after % sequences */
7408 while (*s && *s != '%')
7409 s++;
7410 if (!*s)
7411 break;
7412 s++;
7413 if (*s != '%' && *s != ')')
7414 ++itemcnt;
7415 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7416 {
7417 s++;
7418 continue;
7419 }
7420 if (*s == ')')
7421 {
7422 s++;
7423 if (--groupdepth < 0)
7424 break;
7425 continue;
7426 }
7427 if (*s == '-')
7428 s++;
7429 while (VIM_ISDIGIT(*s))
7430 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007431 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007432 continue;
7433 if (*s == '.')
7434 {
7435 s++;
7436 while (*s && VIM_ISDIGIT(*s))
7437 s++;
7438 }
7439 if (*s == '(')
7440 {
7441 groupdepth++;
7442 continue;
7443 }
7444 if (vim_strchr(STL_ALL, *s) == NULL)
7445 {
7446 return illegal_char(errbuf, *s);
7447 }
7448 if (*s == '{')
7449 {
7450 s++;
7451 while (*s != '}' && *s)
7452 s++;
7453 if (*s != '}')
7454 return (char_u *)N_("E540: Unclosed expression sequence");
7455 }
7456 }
7457 if (itemcnt >= STL_MAX_ITEM)
7458 return (char_u *)N_("E541: too many items");
7459 if (groupdepth != 0)
7460 return (char_u *)N_("E542: unbalanced groups");
7461 return NULL;
7462}
7463#endif
7464
7465#ifdef FEAT_CLIPBOARD
7466/*
7467 * Extract the items in the 'clipboard' option and set global values.
7468 */
7469 static char_u *
7470check_clipboard_option()
7471{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007472 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007473 int new_autoselect_star = FALSE;
7474 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007475 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007476 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477 regprog_T *new_exclude_prog = NULL;
7478 char_u *errmsg = NULL;
7479 char_u *p;
7480
7481 for (p = p_cb; *p != NUL; )
7482 {
7483 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7484 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007485 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 p += 7;
7487 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007488 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007489 && (p[11] == ',' || p[11] == NUL))
7490 {
7491 new_unnamed |= CLIP_UNNAMED_PLUS;
7492 p += 11;
7493 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007494 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007495 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007497 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 p += 10;
7499 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007500 else if (STRNCMP(p, "autoselectplus", 14) == 0
7501 && (p[14] == ',' || p[14] == NUL))
7502 {
7503 new_autoselect_plus = TRUE;
7504 p += 14;
7505 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007507 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 {
7509 new_autoselectml = TRUE;
7510 p += 12;
7511 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007512 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7513 {
7514 new_html = TRUE;
7515 p += 4;
7516 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007517 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7518 {
7519 p += 8;
7520 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7521 if (new_exclude_prog == NULL)
7522 errmsg = e_invarg;
7523 break;
7524 }
7525 else
7526 {
7527 errmsg = e_invarg;
7528 break;
7529 }
7530 if (*p == ',')
7531 ++p;
7532 }
7533 if (errmsg == NULL)
7534 {
7535 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007536 clip_autoselect_star = new_autoselect_star;
7537 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007538 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007539 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007540 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007542#ifdef FEAT_GUI_GTK
7543 if (gui.in_use)
7544 {
7545 gui_gtk_set_selection_targets();
7546 gui_gtk_set_dnd_targets();
7547 }
7548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549 }
7550 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007551 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007552
7553 return errmsg;
7554}
7555#endif
7556
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007557#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007558/*
7559 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7560 * Return error message when failed, NULL when OK.
7561 */
7562 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007563compile_cap_prog(synblock)
7564 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007565{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007566 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007567 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007568
Bram Moolenaar860cae12010-06-05 23:22:07 +02007569 if (*synblock->b_p_spc == NUL)
7570 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007571 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007572 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007573 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007574 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007575 if (re != NULL)
7576 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007577 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007578 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007579 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007580 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007581 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007582 return e_invarg;
7583 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007584 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007585 }
7586
Bram Moolenaar473de612013-06-08 18:19:48 +02007587 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007588 return NULL;
7589}
7590#endif
7591
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007592#if defined(FEAT_EVAL) || defined(PROTO)
7593/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007594 * Set the scriptID for an option, taking care of setting the buffer- or
7595 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007596 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007597 static void
7598set_option_scriptID_idx(opt_idx, opt_flags, id)
7599 int opt_idx;
7600 int opt_flags;
7601 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007602{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007603 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7604 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007605
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007606 /* Remember where the option was set. For local options need to do that
7607 * in the buffer or window structure. */
7608 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007609 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007610 if (both || (opt_flags & OPT_LOCAL))
7611 {
7612 if (indir & PV_BUF)
7613 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7614 else if (indir & PV_WIN)
7615 curwin->w_p_scriptID[indir & PV_MASK] = id;
7616 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007617}
7618#endif
7619
Bram Moolenaar071d4272004-06-13 20:20:40 +00007620/*
7621 * Set the value of a boolean option, and take care of side effects.
7622 * Returns NULL for success, or an error message for an error.
7623 */
7624 static char_u *
7625set_bool_option(opt_idx, varp, value, opt_flags)
7626 int opt_idx; /* index in options[] table */
7627 char_u *varp; /* pointer to the option variable */
7628 int value; /* new value */
7629 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7630{
7631 int old_value = *(int *)varp;
7632
Bram Moolenaar071d4272004-06-13 20:20:40 +00007633 /* Disallow changing some options from secure mode */
7634 if ((secure
7635#ifdef HAVE_SANDBOX
7636 || sandbox != 0
7637#endif
7638 ) && (options[opt_idx].flags & P_SECURE))
7639 return e_secure;
7640
7641 *(int *)varp = value; /* set the new value */
7642#ifdef FEAT_EVAL
7643 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007644 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007645#endif
7646
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007647#ifdef FEAT_GUI
7648 need_mouse_correct = TRUE;
7649#endif
7650
Bram Moolenaar071d4272004-06-13 20:20:40 +00007651 /* May set global value for local option. */
7652 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7653 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7654
7655 /*
7656 * Handle side effects of changing a bool option.
7657 */
7658
7659 /* 'compatible' */
7660 if ((int *)varp == &p_cp)
7661 {
7662 compatible_set();
7663 }
7664
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007665#ifdef FEAT_PERSISTENT_UNDO
7666 /* 'undofile' */
7667 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7668 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007669 /* Only take action when the option was set. When reset we do not
7670 * delete the undo file, the option may be set again without making
7671 * any changes in between. */
7672 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007673 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007674 char_u hash[UNDO_HASH_SIZE];
7675 buf_T *save_curbuf = curbuf;
7676
7677 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007678 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007679 /* When 'undofile' is set globally: for every buffer, otherwise
7680 * only for the current buffer: Try to read in the undofile,
7681 * if one exists, the buffer wasn't changed and the buffer was
7682 * loaded */
7683 if ((curbuf == save_curbuf
7684 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7685 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7686 {
7687 u_compute_hash(hash);
7688 u_read_undo(NULL, hash, curbuf->b_fname);
7689 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007690 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007691 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007692 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007693 }
7694#endif
7695
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696 else if ((int *)varp == &curbuf->b_p_ro)
7697 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007698 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007699 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7700 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007701
7702 /* when 'readonly' is set may give W10 again */
7703 if (curbuf->b_p_ro)
7704 curbuf->b_did_warn = FALSE;
7705
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007707 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708#endif
7709 }
7710
Bram Moolenaar9c449722010-07-20 18:44:27 +02007711#ifdef FEAT_GUI
7712 else if ((int *)varp == &p_mh)
7713 {
7714 if (!p_mh)
7715 gui_mch_mousehide(FALSE);
7716 }
7717#endif
7718
Bram Moolenaara539df02010-08-01 14:35:05 +02007719#ifdef FEAT_TITLE
7720 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007722 {
7723 redraw_titles();
7724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007725 /* when 'endofline' is changed, redraw the window title */
7726 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007727 {
7728 redraw_titles();
7729 }
7730# ifdef FEAT_MBYTE
7731 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007732 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007733 {
7734 redraw_titles();
7735 }
7736# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737#endif
7738
7739 /* when 'bin' is set also set some other options */
7740 else if ((int *)varp == &curbuf->b_p_bin)
7741 {
7742 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7743#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007744 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007745#endif
7746 }
7747
7748#ifdef FEAT_AUTOCMD
7749 /* when 'buflisted' changes, trigger autocommands */
7750 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7751 {
7752 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7753 NULL, NULL, TRUE, curbuf);
7754 }
7755#endif
7756
7757 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7758 else if ((int *)varp == &curbuf->b_p_swf)
7759 {
7760 if (curbuf->b_p_swf && p_uc)
7761 ml_open_file(curbuf); /* create the swap file */
7762 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007763 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7764 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765 mf_close_file(curbuf, TRUE); /* remove the swap file */
7766 }
7767
7768 /* when 'terse' is set change 'shortmess' */
7769 else if ((int *)varp == &p_terse)
7770 {
7771 char_u *p;
7772
7773 p = vim_strchr(p_shm, SHM_SEARCH);
7774
7775 /* insert 's' in p_shm */
7776 if (p_terse && p == NULL)
7777 {
7778 STRCPY(IObuff, p_shm);
7779 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007780 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781 }
7782 /* remove 's' from p_shm */
7783 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007784 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785 }
7786
7787 /* when 'paste' is set or reset also change other options */
7788 else if ((int *)varp == &p_paste)
7789 {
7790 paste_option_changed();
7791 }
7792
7793 /* when 'insertmode' is set from an autocommand need to do work here */
7794 else if ((int *)varp == &p_im)
7795 {
7796 if (p_im)
7797 {
7798 if ((State & INSERT) == 0)
7799 need_start_insertmode = TRUE;
7800 stop_insert_mode = FALSE;
7801 }
7802 else
7803 {
7804 need_start_insertmode = FALSE;
7805 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007806 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007807 clear_cmdline = TRUE; /* remove "(insert)" */
7808 restart_edit = 0;
7809 }
7810 }
7811
7812 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7813 else if ((int *)varp == &p_ic && p_hls)
7814 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007815 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816 }
7817
7818#ifdef FEAT_SEARCH_EXTRA
7819 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7820 else if ((int *)varp == &p_hls)
7821 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007822 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007823 }
7824#endif
7825
7826#ifdef FEAT_SCROLLBIND
7827 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7828 * at the end of normal_cmd() */
7829 else if ((int *)varp == &curwin->w_p_scb)
7830 {
7831 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007832 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007833 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007834 curwin->w_scbind_pos = curwin->w_topline;
7835 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836 }
7837#endif
7838
7839#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7840 /* There can be only one window with 'previewwindow' set. */
7841 else if ((int *)varp == &curwin->w_p_pvw)
7842 {
7843 if (curwin->w_p_pvw)
7844 {
7845 win_T *win;
7846
7847 for (win = firstwin; win != NULL; win = win->w_next)
7848 if (win->w_p_pvw && win != curwin)
7849 {
7850 curwin->w_p_pvw = FALSE;
7851 return (char_u *)N_("E590: A preview window already exists");
7852 }
7853 }
7854 }
7855#endif
7856
7857 /* when 'textmode' is set or reset also change 'fileformat' */
7858 else if ((int *)varp == &curbuf->b_p_tx)
7859 {
7860 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7861 }
7862
7863 /* when 'textauto' is set or reset also change 'fileformats' */
7864 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007865 set_string_option_direct((char_u *)"ffs", -1,
7866 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007867 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868
7869 /*
7870 * When 'lisp' option changes include/exclude '-' in
7871 * keyword characters.
7872 */
7873#ifdef FEAT_LISP
7874 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7875 {
7876 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7877 }
7878#endif
7879
7880#ifdef FEAT_TITLE
7881 /* when 'title' changed, may need to change the title; same for 'icon' */
7882 else if ((int *)varp == &p_title)
7883 {
7884 did_set_title(FALSE);
7885 }
7886
7887 else if ((int *)varp == &p_icon)
7888 {
7889 did_set_title(TRUE);
7890 }
7891#endif
7892
7893 else if ((int *)varp == &curbuf->b_changed)
7894 {
7895 if (!value)
7896 save_file_ff(curbuf); /* Buffer is unchanged */
7897#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007898 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899#endif
7900#ifdef FEAT_AUTOCMD
7901 modified_was_set = value;
7902#endif
7903 }
7904
7905#ifdef BACKSLASH_IN_FILENAME
7906 else if ((int *)varp == &p_ssl)
7907 {
7908 if (p_ssl)
7909 {
7910 psepc = '/';
7911 psepcN = '\\';
7912 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 }
7914 else
7915 {
7916 psepc = '\\';
7917 psepcN = '/';
7918 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 }
7920
7921 /* need to adjust the file name arguments and buffer names. */
7922 buflist_slash_adjust();
7923 alist_slash_adjust();
7924# ifdef FEAT_EVAL
7925 scriptnames_slash_adjust();
7926# endif
7927 }
7928#endif
7929
7930 /* If 'wrap' is set, set w_leftcol to zero. */
7931 else if ((int *)varp == &curwin->w_p_wrap)
7932 {
7933 if (curwin->w_p_wrap)
7934 curwin->w_leftcol = 0;
7935 }
7936
7937#ifdef FEAT_WINDOWS
7938 else if ((int *)varp == &p_ea)
7939 {
7940 if (p_ea && !old_value)
7941 win_equal(curwin, FALSE, 0);
7942 }
7943#endif
7944
7945 else if ((int *)varp == &p_wiv)
7946 {
7947 /*
7948 * When 'weirdinvert' changed, set/reset 't_xs'.
7949 * Then set 'weirdinvert' according to value of 't_xs'.
7950 */
7951 if (p_wiv && !old_value)
7952 T_XS = (char_u *)"y";
7953 else if (!p_wiv && old_value)
7954 T_XS = empty_option;
7955 p_wiv = (*T_XS != NUL);
7956 }
7957
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007958#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 else if ((int *)varp == &p_beval)
7960 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007961 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007963 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 gui_mch_disable_beval_area(balloonEval);
7965 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007966#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007968#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969 else if ((int *)varp == &p_acd)
7970 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007971 /* Change directories when the 'acd' option is set now. */
7972 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973 }
7974#endif
7975
7976#ifdef FEAT_DIFF
7977 /* 'diff' */
7978 else if ((int *)varp == &curwin->w_p_diff)
7979 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007980 /* May add or remove the buffer from the list of diff buffers. */
7981 diff_buf_adjust(curwin);
7982# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 if (foldmethodIsDiff(curwin))
7984 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007985# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986 }
7987#endif
7988
7989#ifdef USE_IM_CONTROL
7990 /* 'imdisable' */
7991 else if ((int *)varp == &p_imdisable)
7992 {
7993 /* Only de-activate it here, it will be enabled when changing mode. */
7994 if (p_imdisable)
7995 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007996 else if (State & INSERT)
7997 /* When the option is set from an autocommand, it may need to take
7998 * effect right away. */
7999 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008000 }
8001#endif
8002
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008003#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008004 /* 'spell' */
8005 else if ((int *)varp == &curwin->w_p_spell)
8006 {
8007 if (curwin->w_p_spell)
8008 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008009 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008010 if (errmsg != NULL)
8011 EMSG(_(errmsg));
8012 }
8013 }
8014#endif
8015
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016#ifdef FEAT_FKMAP
8017 else if ((int *)varp == &p_altkeymap)
8018 {
8019 if (old_value != p_altkeymap)
8020 {
8021 if (!p_altkeymap)
8022 {
8023 p_hkmap = p_fkmap;
8024 p_fkmap = 0;
8025 }
8026 else
8027 {
8028 p_fkmap = p_hkmap;
8029 p_hkmap = 0;
8030 }
8031 (void)init_chartab();
8032 }
8033 }
8034
8035 /*
8036 * In case some second language keymapping options have changed, check
8037 * and correct the setting in a consistent way.
8038 */
8039
8040 /*
8041 * If hkmap or fkmap are set, reset Arabic keymapping.
8042 */
8043 if ((p_hkmap || p_fkmap) && p_altkeymap)
8044 {
8045 p_altkeymap = p_fkmap;
8046# ifdef FEAT_ARABIC
8047 curwin->w_p_arab = FALSE;
8048# endif
8049 (void)init_chartab();
8050 }
8051
8052 /*
8053 * If hkmap set, reset Farsi keymapping.
8054 */
8055 if (p_hkmap && p_altkeymap)
8056 {
8057 p_altkeymap = 0;
8058 p_fkmap = 0;
8059# ifdef FEAT_ARABIC
8060 curwin->w_p_arab = FALSE;
8061# endif
8062 (void)init_chartab();
8063 }
8064
8065 /*
8066 * If fkmap set, reset Hebrew keymapping.
8067 */
8068 if (p_fkmap && !p_altkeymap)
8069 {
8070 p_altkeymap = 1;
8071 p_hkmap = 0;
8072# ifdef FEAT_ARABIC
8073 curwin->w_p_arab = FALSE;
8074# endif
8075 (void)init_chartab();
8076 }
8077#endif
8078
8079#ifdef FEAT_ARABIC
8080 if ((int *)varp == &curwin->w_p_arab)
8081 {
8082 if (curwin->w_p_arab)
8083 {
8084 /*
8085 * 'arabic' is set, handle various sub-settings.
8086 */
8087 if (!p_tbidi)
8088 {
8089 /* set rightleft mode */
8090 if (!curwin->w_p_rl)
8091 {
8092 curwin->w_p_rl = TRUE;
8093 changed_window_setting();
8094 }
8095
8096 /* Enable Arabic shaping (major part of what Arabic requires) */
8097 if (!p_arshape)
8098 {
8099 p_arshape = TRUE;
8100 redraw_later_clear();
8101 }
8102 }
8103
8104 /* Arabic requires a utf-8 encoding, inform the user if its not
8105 * set. */
8106 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008107 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008108 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8109
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008110 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008111 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8112#ifdef FEAT_EVAL
8113 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8114#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008115 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008116
8117# ifdef FEAT_MBYTE
8118 /* set 'delcombine' */
8119 p_deco = TRUE;
8120# endif
8121
8122# ifdef FEAT_KEYMAP
8123 /* Force-set the necessary keymap for arabic */
8124 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8125 OPT_LOCAL);
8126# endif
8127# ifdef FEAT_FKMAP
8128 p_altkeymap = 0;
8129 p_hkmap = 0;
8130 p_fkmap = 0;
8131 (void)init_chartab();
8132# endif
8133 }
8134 else
8135 {
8136 /*
8137 * 'arabic' is reset, handle various sub-settings.
8138 */
8139 if (!p_tbidi)
8140 {
8141 /* reset rightleft mode */
8142 if (curwin->w_p_rl)
8143 {
8144 curwin->w_p_rl = FALSE;
8145 changed_window_setting();
8146 }
8147
8148 /* 'arabicshape' isn't reset, it is a global option and
8149 * another window may still need it "on". */
8150 }
8151
8152 /* 'delcombine' isn't reset, it is a global option and another
8153 * window may still want it "on". */
8154
8155# ifdef FEAT_KEYMAP
8156 /* Revert to the default keymap */
8157 curbuf->b_p_iminsert = B_IMODE_NONE;
8158 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8159# endif
8160 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008161 }
8162
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008163#endif
8164
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 /*
8166 * End of handling side effects for bool options.
8167 */
8168
8169 options[opt_idx].flags |= P_WAS_SET;
8170
8171 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008172 if (curwin->w_curswant != MAXCOL
8173 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8174 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 check_redraw(options[opt_idx].flags);
8176
8177 return NULL;
8178}
8179
8180/*
8181 * Set the value of a number option, and take care of side effects.
8182 * Returns NULL for success, or an error message for an error.
8183 */
8184 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008185set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008186 int opt_idx; /* index in options[] table */
8187 char_u *varp; /* pointer to the option variable */
8188 long value; /* new value */
8189 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008190 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008191 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8192 OPT_MODELINE */
8193{
8194 char_u *errmsg = NULL;
8195 long old_value = *(long *)varp;
8196 long old_Rows = Rows; /* remember old Rows */
8197 long old_Columns = Columns; /* remember old Columns */
8198 long *pp = (long *)varp;
8199
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008200 /* Disallow changing some options from secure mode. */
8201 if ((secure
8202#ifdef HAVE_SANDBOX
8203 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008205 ) && (options[opt_idx].flags & P_SECURE))
8206 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207
8208 *pp = value;
8209#ifdef FEAT_EVAL
8210 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008211 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008213#ifdef FEAT_GUI
8214 need_mouse_correct = TRUE;
8215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008216
Bram Moolenaar14f24742012-08-08 18:01:05 +02008217 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 {
8219 errmsg = e_positive;
8220 curbuf->b_p_sw = curbuf->b_p_ts;
8221 }
8222
8223 /*
8224 * Number options that need some action when changed
8225 */
8226#ifdef FEAT_WINDOWS
8227 if (pp == &p_wh || pp == &p_hh)
8228 {
8229 if (p_wh < 1)
8230 {
8231 errmsg = e_positive;
8232 p_wh = 1;
8233 }
8234 if (p_wmh > p_wh)
8235 {
8236 errmsg = e_winheight;
8237 p_wh = p_wmh;
8238 }
8239 if (p_hh < 0)
8240 {
8241 errmsg = e_positive;
8242 p_hh = 0;
8243 }
8244
8245 /* Change window height NOW */
8246 if (lastwin != firstwin)
8247 {
8248 if (pp == &p_wh && curwin->w_height < p_wh)
8249 win_setheight((int)p_wh);
8250 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8251 win_setheight((int)p_hh);
8252 }
8253 }
8254
8255 /* 'winminheight' */
8256 else if (pp == &p_wmh)
8257 {
8258 if (p_wmh < 0)
8259 {
8260 errmsg = e_positive;
8261 p_wmh = 0;
8262 }
8263 if (p_wmh > p_wh)
8264 {
8265 errmsg = e_winheight;
8266 p_wmh = p_wh;
8267 }
8268 win_setminheight();
8269 }
8270
8271# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008272 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008273 {
8274 if (p_wiw < 1)
8275 {
8276 errmsg = e_positive;
8277 p_wiw = 1;
8278 }
8279 if (p_wmw > p_wiw)
8280 {
8281 errmsg = e_winwidth;
8282 p_wiw = p_wmw;
8283 }
8284
8285 /* Change window width NOW */
8286 if (lastwin != firstwin && curwin->w_width < p_wiw)
8287 win_setwidth((int)p_wiw);
8288 }
8289
8290 /* 'winminwidth' */
8291 else if (pp == &p_wmw)
8292 {
8293 if (p_wmw < 0)
8294 {
8295 errmsg = e_positive;
8296 p_wmw = 0;
8297 }
8298 if (p_wmw > p_wiw)
8299 {
8300 errmsg = e_winwidth;
8301 p_wmw = p_wiw;
8302 }
8303 win_setminheight();
8304 }
8305# endif
8306
8307#endif
8308
8309#ifdef FEAT_WINDOWS
8310 /* (re)set last window status line */
8311 else if (pp == &p_ls)
8312 {
8313 last_status(FALSE);
8314 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008315
8316 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008317 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008318 {
8319 shell_new_rows(); /* recompute window positions and heights */
8320 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008321#endif
8322
8323#ifdef FEAT_GUI
8324 else if (pp == &p_linespace)
8325 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008326 /* Recompute gui.char_height and resize the Vim window to keep the
8327 * same number of lines. */
8328 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008329 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008330 }
8331#endif
8332
8333#ifdef FEAT_FOLDING
8334 /* 'foldlevel' */
8335 else if (pp == &curwin->w_p_fdl)
8336 {
8337 if (curwin->w_p_fdl < 0)
8338 curwin->w_p_fdl = 0;
8339 newFoldLevel();
8340 }
8341
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008342 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 else if (pp == &curwin->w_p_fml)
8344 {
8345 foldUpdateAll(curwin);
8346 }
8347
8348 /* 'foldnestmax' */
8349 else if (pp == &curwin->w_p_fdn)
8350 {
8351 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8352 foldUpdateAll(curwin);
8353 }
8354
8355 /* 'foldcolumn' */
8356 else if (pp == &curwin->w_p_fdc)
8357 {
8358 if (curwin->w_p_fdc < 0)
8359 {
8360 errmsg = e_positive;
8361 curwin->w_p_fdc = 0;
8362 }
8363 else if (curwin->w_p_fdc > 12)
8364 {
8365 errmsg = e_invarg;
8366 curwin->w_p_fdc = 12;
8367 }
8368 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008369#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008371#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 /* 'shiftwidth' or 'tabstop' */
8373 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8374 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008375# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376 if (foldmethodIsIndent(curwin))
8377 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008378# endif
8379# ifdef FEAT_CINDENT
8380 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8381 * parse 'cinoptions'. */
8382 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8383 parse_cino(curbuf);
8384# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008388#ifdef FEAT_MBYTE
8389 /* 'maxcombine' */
8390 else if (pp == &p_mco)
8391 {
8392 if (p_mco > MAX_MCO)
8393 p_mco = MAX_MCO;
8394 else if (p_mco < 0)
8395 p_mco = 0;
8396 screenclear(); /* will re-allocate the screen */
8397 }
8398#endif
8399
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400 else if (pp == &curbuf->b_p_iminsert)
8401 {
8402 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8403 {
8404 errmsg = e_invarg;
8405 curbuf->b_p_iminsert = B_IMODE_NONE;
8406 }
8407 p_iminsert = curbuf->b_p_iminsert;
8408 if (termcap_active) /* don't do this in the alternate screen */
8409 showmode();
8410#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8411 /* Show/unshow value of 'keymap' in status lines. */
8412 status_redraw_curbuf();
8413#endif
8414 }
8415
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008416 else if (pp == &p_window)
8417 {
8418 if (p_window < 1)
8419 p_window = 1;
8420 else if (p_window >= Rows)
8421 p_window = Rows - 1;
8422 }
8423
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424 else if (pp == &curbuf->b_p_imsearch)
8425 {
8426 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8427 {
8428 errmsg = e_invarg;
8429 curbuf->b_p_imsearch = B_IMODE_NONE;
8430 }
8431 p_imsearch = curbuf->b_p_imsearch;
8432 }
8433
8434#ifdef FEAT_TITLE
8435 /* if 'titlelen' has changed, redraw the title */
8436 else if (pp == &p_titlelen)
8437 {
8438 if (p_titlelen < 0)
8439 {
8440 errmsg = e_positive;
8441 p_titlelen = 85;
8442 }
8443 if (starting != NO_SCREEN && old_value != p_titlelen)
8444 need_maketitle = TRUE;
8445 }
8446#endif
8447
8448 /* if p_ch changed value, change the command line height */
8449 else if (pp == &p_ch)
8450 {
8451 if (p_ch < 1)
8452 {
8453 errmsg = e_positive;
8454 p_ch = 1;
8455 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008456 if (p_ch > Rows - min_rows() + 1)
8457 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458
8459 /* Only compute the new window layout when startup has been
8460 * completed. Otherwise the frame sizes may be wrong. */
8461 if (p_ch != old_value && full_screen
8462#ifdef FEAT_GUI
8463 && !gui.starting
8464#endif
8465 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008466 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008467 }
8468
8469 /* when 'updatecount' changes from zero to non-zero, open swap files */
8470 else if (pp == &p_uc)
8471 {
8472 if (p_uc < 0)
8473 {
8474 errmsg = e_positive;
8475 p_uc = 100;
8476 }
8477 if (p_uc && !old_value)
8478 ml_open_files();
8479 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008480#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008481 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008482 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008483 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008484 {
8485 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008486 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008487 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008488 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008489 {
8490 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008491 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008492 }
8493 }
8494#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008495#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008496 else if (pp == &p_mzq)
8497 mzvim_reset_timer();
8498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008499
8500 /* sync undo before 'undolevels' changes */
8501 else if (pp == &p_ul)
8502 {
8503 /* use the old value, otherwise u_sync() may not work properly */
8504 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008505 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506 p_ul = value;
8507 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008508 else if (pp == &curbuf->b_p_ul)
8509 {
8510 /* use the old value, otherwise u_sync() may not work properly */
8511 curbuf->b_p_ul = old_value;
8512 u_sync(TRUE);
8513 curbuf->b_p_ul = value;
8514 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008515
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008516#ifdef FEAT_LINEBREAK
8517 /* 'numberwidth' must be positive */
8518 else if (pp == &curwin->w_p_nuw)
8519 {
8520 if (curwin->w_p_nuw < 1)
8521 {
8522 errmsg = e_positive;
8523 curwin->w_p_nuw = 1;
8524 }
8525 if (curwin->w_p_nuw > 10)
8526 {
8527 errmsg = e_invarg;
8528 curwin->w_p_nuw = 10;
8529 }
8530 curwin->w_nrwidth_line_count = 0;
8531 }
8532#endif
8533
Bram Moolenaar1a384422010-07-14 19:53:30 +02008534 else if (pp == &curbuf->b_p_tw)
8535 {
8536 if (curbuf->b_p_tw < 0)
8537 {
8538 errmsg = e_positive;
8539 curbuf->b_p_tw = 0;
8540 }
8541#ifdef FEAT_SYN_HL
8542# ifdef FEAT_WINDOWS
8543 {
8544 win_T *wp;
8545 tabpage_T *tp;
8546
8547 FOR_ALL_TAB_WINDOWS(tp, wp)
8548 check_colorcolumn(wp);
8549 }
8550# else
8551 check_colorcolumn(curwin);
8552# endif
8553#endif
8554 }
8555
Bram Moolenaar071d4272004-06-13 20:20:40 +00008556 /*
8557 * Check the bounds for numeric options here
8558 */
8559 if (Rows < min_rows() && full_screen)
8560 {
8561 if (errbuf != NULL)
8562 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008563 vim_snprintf((char *)errbuf, errbuflen,
8564 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565 errmsg = errbuf;
8566 }
8567 Rows = min_rows();
8568 }
8569 if (Columns < MIN_COLUMNS && full_screen)
8570 {
8571 if (errbuf != NULL)
8572 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008573 vim_snprintf((char *)errbuf, errbuflen,
8574 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 errmsg = errbuf;
8576 }
8577 Columns = MIN_COLUMNS;
8578 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008579 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008580
8581#ifdef DJGPP
8582 /* avoid a crash by checking for a too large value of 'columns' */
8583 if (old_Columns != Columns && full_screen && term_console)
8584 mch_check_columns();
8585#endif
8586
8587 /*
8588 * If the screen (shell) height has been changed, assume it is the
8589 * physical screenheight.
8590 */
8591 if (old_Rows != Rows || old_Columns != Columns)
8592 {
8593 /* Changing the screen size is not allowed while updating the screen. */
8594 if (updating_screen)
8595 *pp = old_value;
8596 else if (full_screen
8597#ifdef FEAT_GUI
8598 && !gui.starting
8599#endif
8600 )
8601 set_shellsize((int)Columns, (int)Rows, TRUE);
8602 else
8603 {
8604 /* Postpone the resizing; check the size and cmdline position for
8605 * messages. */
8606 check_shellsize();
8607 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8608 cmdline_row = Rows - p_ch;
8609 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008610 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008611 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008612 }
8613
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614 if (curbuf->b_p_ts <= 0)
8615 {
8616 errmsg = e_positive;
8617 curbuf->b_p_ts = 8;
8618 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008619 if (p_tm < 0)
8620 {
8621 errmsg = e_positive;
8622 p_tm = 0;
8623 }
8624 if ((curwin->w_p_scr <= 0
8625 || (curwin->w_p_scr > curwin->w_height
8626 && curwin->w_height > 0))
8627 && full_screen)
8628 {
8629 if (pp == &(curwin->w_p_scr))
8630 {
8631 if (curwin->w_p_scr != 0)
8632 errmsg = e_scroll;
8633 win_comp_scroll(curwin);
8634 }
8635 /* If 'scroll' became invalid because of a side effect silently adjust
8636 * it. */
8637 else if (curwin->w_p_scr <= 0)
8638 curwin->w_p_scr = 1;
8639 else /* curwin->w_p_scr > curwin->w_height */
8640 curwin->w_p_scr = curwin->w_height;
8641 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008642 if (p_hi < 0)
8643 {
8644 errmsg = e_positive;
8645 p_hi = 0;
8646 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008647 if (p_re < 0 || p_re > 2)
8648 {
8649 errmsg = e_invarg;
8650 p_re = 0;
8651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 if (p_report < 0)
8653 {
8654 errmsg = e_positive;
8655 p_report = 1;
8656 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008657 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658 {
8659 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8660 p_sj = Rows / 2;
8661 else
8662 {
8663 errmsg = e_scroll;
8664 p_sj = 1;
8665 }
8666 }
8667 if (p_so < 0 && full_screen)
8668 {
8669 errmsg = e_scroll;
8670 p_so = 0;
8671 }
8672 if (p_siso < 0 && full_screen)
8673 {
8674 errmsg = e_positive;
8675 p_siso = 0;
8676 }
8677#ifdef FEAT_CMDWIN
8678 if (p_cwh < 1)
8679 {
8680 errmsg = e_positive;
8681 p_cwh = 1;
8682 }
8683#endif
8684 if (p_ut < 0)
8685 {
8686 errmsg = e_positive;
8687 p_ut = 2000;
8688 }
8689 if (p_ss < 0)
8690 {
8691 errmsg = e_positive;
8692 p_ss = 0;
8693 }
8694
8695 /* May set global value for local option. */
8696 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8697 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8698
8699 options[opt_idx].flags |= P_WAS_SET;
8700
8701 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008702 if (curwin->w_curswant != MAXCOL
8703 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8704 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 check_redraw(options[opt_idx].flags);
8706
8707 return errmsg;
8708}
8709
8710/*
8711 * Called after an option changed: check if something needs to be redrawn.
8712 */
8713 static void
8714check_redraw(flags)
8715 long_u flags;
8716{
8717 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008718 int doclear = (flags & P_RCLR) == P_RCLR;
8719 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720
8721#ifdef FEAT_WINDOWS
8722 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8723 status_redraw_all();
8724#endif
8725
8726 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8727 changed_window_setting();
8728 if (flags & P_RBUF)
8729 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008730 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008731 redraw_all_later(CLEAR);
8732 else if (all)
8733 redraw_all_later(NOT_VALID);
8734}
8735
8736/*
8737 * Find index for option 'arg'.
8738 * Return -1 if not found.
8739 */
8740 static int
8741findoption(arg)
8742 char_u *arg;
8743{
8744 int opt_idx;
8745 char *s, *p;
8746 static short quick_tab[27] = {0, 0}; /* quick access table */
8747 int is_term_opt;
8748
8749 /*
8750 * For first call: Initialize the quick-access table.
8751 * It contains the index for the first option that starts with a certain
8752 * letter. There are 26 letters, plus the first "t_" option.
8753 */
8754 if (quick_tab[1] == 0)
8755 {
8756 p = options[0].fullname;
8757 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8758 {
8759 if (s[0] != p[0])
8760 {
8761 if (s[0] == 't' && s[1] == '_')
8762 quick_tab[26] = opt_idx;
8763 else
8764 quick_tab[CharOrdLow(s[0])] = opt_idx;
8765 }
8766 p = s;
8767 }
8768 }
8769
8770 /*
8771 * Check for name starting with an illegal character.
8772 */
8773#ifdef EBCDIC
8774 if (!islower(arg[0]))
8775#else
8776 if (arg[0] < 'a' || arg[0] > 'z')
8777#endif
8778 return -1;
8779
8780 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8781 if (is_term_opt)
8782 opt_idx = quick_tab[26];
8783 else
8784 opt_idx = quick_tab[CharOrdLow(arg[0])];
8785 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8786 {
8787 if (STRCMP(arg, s) == 0) /* match full name */
8788 break;
8789 }
8790 if (s == NULL && !is_term_opt)
8791 {
8792 opt_idx = quick_tab[CharOrdLow(arg[0])];
8793 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8794 {
8795 s = options[opt_idx].shortname;
8796 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8797 break;
8798 s = NULL;
8799 }
8800 }
8801 if (s == NULL)
8802 opt_idx = -1;
8803 return opt_idx;
8804}
8805
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008806#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807/*
8808 * Get the value for an option.
8809 *
8810 * Returns:
8811 * Number or Toggle option: 1, *numval gets value.
8812 * String option: 0, *stringval gets allocated string.
8813 * Hidden Number or Toggle option: -1.
8814 * hidden String option: -2.
8815 * unknown option: -3.
8816 */
8817 int
8818get_option_value(name, numval, stringval, opt_flags)
8819 char_u *name;
8820 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008821 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822 int opt_flags;
8823{
8824 int opt_idx;
8825 char_u *varp;
8826
8827 opt_idx = findoption(name);
8828 if (opt_idx < 0) /* unknown option */
8829 return -3;
8830
8831 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8832
8833 if (options[opt_idx].flags & P_STRING)
8834 {
8835 if (varp == NULL) /* hidden option */
8836 return -2;
8837 if (stringval != NULL)
8838 {
8839#ifdef FEAT_CRYPT
8840 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008841 if ((char_u **)varp == &curbuf->b_p_key
8842 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008843 *stringval = vim_strsave((char_u *)"*****");
8844 else
8845#endif
8846 *stringval = vim_strsave(*(char_u **)(varp));
8847 }
8848 return 0;
8849 }
8850
8851 if (varp == NULL) /* hidden option */
8852 return -1;
8853 if (options[opt_idx].flags & P_NUM)
8854 *numval = *(long *)varp;
8855 else
8856 {
8857 /* Special case: 'modified' is b_changed, but we also want to consider
8858 * it set when 'ff' or 'fenc' changed. */
8859 if ((int *)varp == &curbuf->b_changed)
8860 *numval = curbufIsChanged();
8861 else
8862 *numval = *(int *)varp;
8863 }
8864 return 1;
8865}
8866#endif
8867
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008868#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008869/*
8870 * Returns the option attributes and its value. Unlike the above function it
8871 * will return either global value or local value of the option depending on
8872 * what was requested, but it will never return global value if it was
8873 * requested to return local one and vice versa. Neither it will return
8874 * buffer-local value if it was requested to return window-local one.
8875 *
8876 * Pretends that option is absent if it is not present in the requested scope
8877 * (i.e. has no global, window-local or buffer-local value depending on
8878 * opt_type). Uses
8879 *
8880 * Returned flags:
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008881 * 0 hidden or unknown option, also option that does not have requested
8882 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008883 * see SOPT_* in vim.h for other flags
8884 *
8885 * Possible opt_type values: see SREQ_* in vim.h
8886 */
8887 int
8888get_option_value_strict(name, numval, stringval, opt_type, from)
8889 char_u *name;
8890 long *numval;
8891 char_u **stringval; /* NULL when only obtaining attributes */
8892 int opt_type;
8893 void *from;
8894{
8895 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008896 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008897 struct vimoption *p;
8898 int r = 0;
8899
8900 opt_idx = findoption(name);
8901 if (opt_idx < 0)
8902 return 0;
8903
8904 p = &(options[opt_idx]);
8905
8906 /* Hidden option */
8907 if (p->var == NULL)
8908 return 0;
8909
8910 if (p->flags & P_BOOL)
8911 r |= SOPT_BOOL;
8912 else if (p->flags & P_NUM)
8913 r |= SOPT_NUM;
8914 else if (p->flags & P_STRING)
8915 r |= SOPT_STRING;
8916
8917 if (p->indir == PV_NONE)
8918 {
8919 if (opt_type == SREQ_GLOBAL)
8920 r |= SOPT_GLOBAL;
8921 else
8922 return 0; /* Did not request global-only option */
8923 }
8924 else
8925 {
8926 if (p->indir & PV_BOTH)
8927 r |= SOPT_GLOBAL;
8928 else if (opt_type == SREQ_GLOBAL)
8929 return 0; /* Requested global option */
8930
8931 if (p->indir & PV_WIN)
8932 {
8933 if (opt_type == SREQ_BUF)
8934 return 0; /* Did not request window-local option */
8935 else
8936 r |= SOPT_WIN;
8937 }
8938 else if (p->indir & PV_BUF)
8939 {
8940 if (opt_type == SREQ_WIN)
8941 return 0; /* Did not request buffer-local option */
8942 else
8943 r |= SOPT_BUF;
8944 }
8945 }
8946
8947 if (stringval == NULL)
8948 return r;
8949
8950 if (opt_type == SREQ_GLOBAL)
8951 varp = p->var;
8952 else
8953 {
8954 if (opt_type == SREQ_BUF)
8955 {
8956 /* Special case: 'modified' is b_changed, but we also want to
8957 * consider it set when 'ff' or 'fenc' changed. */
8958 if (p->indir == PV_MOD)
8959 {
8960 *numval = bufIsChanged((buf_T *) from);
8961 varp = NULL;
8962 }
8963#ifdef FEAT_CRYPT
8964 else if (p->indir == PV_KEY)
8965 {
8966 /* never return the value of the crypt key */
8967 *stringval = NULL;
8968 varp = NULL;
8969 }
8970#endif
8971 else
8972 {
8973 aco_save_T aco;
8974 aucmd_prepbuf(&aco, (buf_T *) from);
8975 varp = get_varp(p);
8976 aucmd_restbuf(&aco);
8977 }
8978 }
8979 else if (opt_type == SREQ_WIN)
8980 {
8981 win_T *save_curwin;
8982 save_curwin = curwin;
8983 curwin = (win_T *) from;
8984 curbuf = curwin->w_buffer;
8985 varp = get_varp(p);
8986 curwin = save_curwin;
8987 curbuf = curwin->w_buffer;
8988 }
8989 if (varp == p->var)
8990 return (r | SOPT_UNSET);
8991 }
8992
8993 if (varp != NULL)
8994 {
8995 if (p->flags & P_STRING)
8996 *stringval = vim_strsave(*(char_u **)(varp));
8997 else if (p->flags & P_NUM)
8998 *numval = *(long *) varp;
8999 else
9000 *numval = *(int *)varp;
9001 }
9002
9003 return r;
9004}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009005
9006/*
9007 * Iterate over options. First argument is a pointer to a pointer to a structure
9008 * inside options[] array, second is option type like in the above function.
9009 *
9010 * If first argument points to NULL it is assumed that iteration just started
9011 * and caller needs the very first value.
9012 * If first argument points to the end marker function returns NULL and sets
9013 * first argument to NULL.
9014 *
9015 * Returns full option name for current option on each call.
9016 */
9017 char_u *
9018option_iter_next(option, opt_type)
9019 void **option;
9020 int opt_type;
9021{
9022 struct vimoption *ret = NULL;
9023 do
9024 {
9025 if (*option == NULL)
9026 *option = (void *) options;
9027 else if (((struct vimoption *) (*option))->fullname == NULL)
9028 {
9029 *option = NULL;
9030 return NULL;
9031 }
9032 else
9033 *option = (void *) (((struct vimoption *) (*option)) + 1);
9034
9035 ret = ((struct vimoption *) (*option));
9036
9037 /* Hidden option */
9038 if (ret->var == NULL)
9039 {
9040 ret = NULL;
9041 continue;
9042 }
9043
9044 switch (opt_type)
9045 {
9046 case SREQ_GLOBAL:
9047 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9048 ret = NULL;
9049 break;
9050 case SREQ_BUF:
9051 if (!(ret->indir & PV_BUF))
9052 ret = NULL;
9053 break;
9054 case SREQ_WIN:
9055 if (!(ret->indir & PV_WIN))
9056 ret = NULL;
9057 break;
9058 default:
9059 EMSG2(_(e_intern2), "option_iter_next()");
9060 return NULL;
9061 }
9062 }
9063 while (ret == NULL);
9064
9065 return (char_u *)ret->fullname;
9066}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009067#endif
9068
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069/*
9070 * Set the value of option "name".
9071 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009072 *
9073 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009075 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076set_option_value(name, number, string, opt_flags)
9077 char_u *name;
9078 long number;
9079 char_u *string;
9080 int opt_flags; /* OPT_LOCAL or 0 (both) */
9081{
9082 int opt_idx;
9083 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009084 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085
9086 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009087 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009088 EMSG2(_("E355: Unknown option: %s"), name);
9089 else
9090 {
9091 flags = options[opt_idx].flags;
9092#ifdef HAVE_SANDBOX
9093 /* Disallow changing some options in the sandbox */
9094 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009095 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009097 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009099#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009100 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009101 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102 else
9103 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009104 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105 if (varp != NULL) /* hidden option is not changed */
9106 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009107 if (number == 0 && string != NULL)
9108 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009109 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009110
9111 /* Either we are given a string or we are setting option
9112 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009113 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009114 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009115 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009116 {
9117 /* There's another character after zeros or the string
9118 * is empty. In both cases, we are trying to set a
9119 * num option using a string. */
9120 EMSG3(_("E521: Number required: &%s = '%s'"),
9121 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009122 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009123
9124 }
9125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009126 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009127 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009128 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009129 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009130 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009131 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132 }
9133 }
9134 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009135 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136}
9137
9138/*
9139 * Get the terminal code for a terminal option.
9140 * Returns NULL when not found.
9141 */
9142 char_u *
9143get_term_code(tname)
9144 char_u *tname;
9145{
9146 int opt_idx;
9147 char_u *varp;
9148
9149 if (tname[0] != 't' || tname[1] != '_' ||
9150 tname[2] == NUL || tname[3] == NUL)
9151 return NULL;
9152 if ((opt_idx = findoption(tname)) >= 0)
9153 {
9154 varp = get_varp(&(options[opt_idx]));
9155 if (varp != NULL)
9156 varp = *(char_u **)(varp);
9157 return varp;
9158 }
9159 return find_termcode(tname + 2);
9160}
9161
9162 char_u *
9163get_highlight_default()
9164{
9165 int i;
9166
9167 i = findoption((char_u *)"hl");
9168 if (i >= 0)
9169 return options[i].def_val[VI_DEFAULT];
9170 return (char_u *)NULL;
9171}
9172
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009173#if defined(FEAT_MBYTE) || defined(PROTO)
9174 char_u *
9175get_encoding_default()
9176{
9177 int i;
9178
9179 i = findoption((char_u *)"enc");
9180 if (i >= 0)
9181 return options[i].def_val[VI_DEFAULT];
9182 return (char_u *)NULL;
9183}
9184#endif
9185
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186/*
9187 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9188 */
9189 static int
9190find_key_option(arg)
9191 char_u *arg;
9192{
9193 int key;
9194 int modifiers;
9195
9196 /*
9197 * Don't use get_special_key_code() for t_xx, we don't want it to call
9198 * add_termcap_entry().
9199 */
9200 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9201 key = TERMCAP2KEY(arg[2], arg[3]);
9202 else
9203 {
9204 --arg; /* put arg at the '<' */
9205 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009206 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009207 if (modifiers) /* can't handle modifiers here */
9208 key = 0;
9209 }
9210 return key;
9211}
9212
9213/*
9214 * if 'all' == 0: show changed options
9215 * if 'all' == 1: show all normal options
9216 * if 'all' == 2: show all terminal options
9217 */
9218 static void
9219showoptions(all, opt_flags)
9220 int all;
9221 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9222{
9223 struct vimoption *p;
9224 int col;
9225 int isterm;
9226 char_u *varp;
9227 struct vimoption **items;
9228 int item_count;
9229 int run;
9230 int row, rows;
9231 int cols;
9232 int i;
9233 int len;
9234
9235#define INC 20
9236#define GAP 3
9237
9238 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9239 PARAM_COUNT));
9240 if (items == NULL)
9241 return;
9242
9243 /* Highlight title */
9244 if (all == 2)
9245 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9246 else if (opt_flags & OPT_GLOBAL)
9247 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9248 else if (opt_flags & OPT_LOCAL)
9249 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9250 else
9251 MSG_PUTS_TITLE(_("\n--- Options ---"));
9252
9253 /*
9254 * do the loop two times:
9255 * 1. display the short items
9256 * 2. display the long items (only strings and numbers)
9257 */
9258 for (run = 1; run <= 2 && !got_int; ++run)
9259 {
9260 /*
9261 * collect the items in items[]
9262 */
9263 item_count = 0;
9264 for (p = &options[0]; p->fullname != NULL; p++)
9265 {
9266 varp = NULL;
9267 isterm = istermoption(p);
9268 if (opt_flags != 0)
9269 {
9270 if (p->indir != PV_NONE && !isterm)
9271 varp = get_varp_scope(p, opt_flags);
9272 }
9273 else
9274 varp = get_varp(p);
9275 if (varp != NULL
9276 && ((all == 2 && isterm)
9277 || (all == 1 && !isterm)
9278 || (all == 0 && !optval_default(p, varp))))
9279 {
9280 if (p->flags & P_BOOL)
9281 len = 1; /* a toggle option fits always */
9282 else
9283 {
9284 option_value2string(p, opt_flags);
9285 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9286 }
9287 if ((len <= INC - GAP && run == 1) ||
9288 (len > INC - GAP && run == 2))
9289 items[item_count++] = p;
9290 }
9291 }
9292
9293 /*
9294 * display the items
9295 */
9296 if (run == 1)
9297 {
9298 cols = (Columns + GAP - 3) / INC;
9299 if (cols == 0)
9300 cols = 1;
9301 rows = (item_count + cols - 1) / cols;
9302 }
9303 else /* run == 2 */
9304 rows = item_count;
9305 for (row = 0; row < rows && !got_int; ++row)
9306 {
9307 msg_putchar('\n'); /* go to next line */
9308 if (got_int) /* 'q' typed in more */
9309 break;
9310 col = 0;
9311 for (i = row; i < item_count; i += rows)
9312 {
9313 msg_col = col; /* make columns */
9314 showoneopt(items[i], opt_flags);
9315 col += INC;
9316 }
9317 out_flush();
9318 ui_breakcheck();
9319 }
9320 }
9321 vim_free(items);
9322}
9323
9324/*
9325 * Return TRUE if option "p" has its default value.
9326 */
9327 static int
9328optval_default(p, varp)
9329 struct vimoption *p;
9330 char_u *varp;
9331{
9332 int dvi;
9333
9334 if (varp == NULL)
9335 return TRUE; /* hidden option is always at default */
9336 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9337 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009338 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009339 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009340 /* the cast to long is required for Manx C, long_i is
9341 * needed for MSVC */
9342 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 /* P_STRING */
9344 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9345}
9346
9347/*
9348 * showoneopt: show the value of one option
9349 * must not be called with a hidden option!
9350 */
9351 static void
9352showoneopt(p, opt_flags)
9353 struct vimoption *p;
9354 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9355{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009356 char_u *varp;
9357 int save_silent = silent_mode;
9358
9359 silent_mode = FALSE;
9360 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361
9362 varp = get_varp_scope(p, opt_flags);
9363
9364 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9365 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9366 ? !curbufIsChanged() : !*(int *)varp))
9367 MSG_PUTS("no");
9368 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9369 MSG_PUTS("--");
9370 else
9371 MSG_PUTS(" ");
9372 MSG_PUTS(p->fullname);
9373 if (!(p->flags & P_BOOL))
9374 {
9375 msg_putchar('=');
9376 /* put value string in NameBuff */
9377 option_value2string(p, opt_flags);
9378 msg_outtrans(NameBuff);
9379 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009380
9381 silent_mode = save_silent;
9382 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009383}
9384
9385/*
9386 * Write modified options as ":set" commands to a file.
9387 *
9388 * There are three values for "opt_flags":
9389 * OPT_GLOBAL: Write global option values and fresh values of
9390 * buffer-local options (used for start of a session
9391 * file).
9392 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9393 * curwin (used for a vimrc file).
9394 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9395 * and local values for window-local options of
9396 * curwin. Local values are also written when at the
9397 * default value, because a modeline or autocommand
9398 * may have set them when doing ":edit file" and the
9399 * user has set them back at the default or fresh
9400 * value.
9401 * When "local_only" is TRUE, don't write fresh
9402 * values, only local values (for ":mkview").
9403 * (fresh value = value used for a new buffer or window for a local option).
9404 *
9405 * Return FAIL on error, OK otherwise.
9406 */
9407 int
9408makeset(fd, opt_flags, local_only)
9409 FILE *fd;
9410 int opt_flags;
9411 int local_only;
9412{
9413 struct vimoption *p;
9414 char_u *varp; /* currently used value */
9415 char_u *varp_fresh; /* local value */
9416 char_u *varp_local = NULL; /* fresh value */
9417 char *cmd;
9418 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009419 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420
9421 /*
9422 * The options that don't have a default (terminal name, columns, lines)
9423 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009424 * Do the loop over "options[]" twice: once for options with the
9425 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009426 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009427 for (pri = 1; pri >= 0; --pri)
9428 {
9429 for (p = &options[0]; !istermoption(p); p++)
9430 if (!(p->flags & P_NO_MKRC)
9431 && !istermoption(p)
9432 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 {
9434 /* skip global option when only doing locals */
9435 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9436 continue;
9437
9438 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9439 * file, they are always buffer-specific. */
9440 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9441 continue;
9442
9443 /* Global values are only written when not at the default value. */
9444 varp = get_varp_scope(p, opt_flags);
9445 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9446 continue;
9447
9448 round = 2;
9449 if (p->indir != PV_NONE)
9450 {
9451 if (p->var == VAR_WIN)
9452 {
9453 /* skip window-local option when only doing globals */
9454 if (!(opt_flags & OPT_LOCAL))
9455 continue;
9456 /* When fresh value of window-local option is not at the
9457 * default, need to write it too. */
9458 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9459 {
9460 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9461 if (!optval_default(p, varp_fresh))
9462 {
9463 round = 1;
9464 varp_local = varp;
9465 varp = varp_fresh;
9466 }
9467 }
9468 }
9469 }
9470
9471 /* Round 1: fresh value for window-local options.
9472 * Round 2: other values */
9473 for ( ; round <= 2; varp = varp_local, ++round)
9474 {
9475 if (round == 1 || (opt_flags & OPT_GLOBAL))
9476 cmd = "set";
9477 else
9478 cmd = "setlocal";
9479
9480 if (p->flags & P_BOOL)
9481 {
9482 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9483 return FAIL;
9484 }
9485 else if (p->flags & P_NUM)
9486 {
9487 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9488 return FAIL;
9489 }
9490 else /* P_STRING */
9491 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009492#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9493 int do_endif = FALSE;
9494
Bram Moolenaar071d4272004-06-13 20:20:40 +00009495 /* Don't set 'syntax' and 'filetype' again if the value is
9496 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009497 if (
9498# if defined(FEAT_SYN_HL)
9499 p->indir == PV_SYN
9500# if defined(FEAT_AUTOCMD)
9501 ||
9502# endif
9503# endif
9504# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009505 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009506# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009507 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009508 {
9509 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9510 *(char_u **)(varp)) < 0
9511 || put_eol(fd) < 0)
9512 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009513 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009514 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009515#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009516 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9517 (p->flags & P_EXPAND) != 0) == FAIL)
9518 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009519#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9520 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009521 {
9522 if (put_line(fd, "endif") == FAIL)
9523 return FAIL;
9524 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009525#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009526 }
9527 }
9528 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009530 return OK;
9531}
9532
9533#if defined(FEAT_FOLDING) || defined(PROTO)
9534/*
9535 * Generate set commands for the local fold options only. Used when
9536 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9537 */
9538 int
9539makefoldset(fd)
9540 FILE *fd;
9541{
9542 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9543# ifdef FEAT_EVAL
9544 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9545 == FAIL
9546# endif
9547 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9548 == FAIL
9549 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9550 == FAIL
9551 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9552 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9553 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9554 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9555 )
9556 return FAIL;
9557
9558 return OK;
9559}
9560#endif
9561
9562 static int
9563put_setstring(fd, cmd, name, valuep, expand)
9564 FILE *fd;
9565 char *cmd;
9566 char *name;
9567 char_u **valuep;
9568 int expand;
9569{
9570 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009571 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009572
9573 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9574 return FAIL;
9575 if (*valuep != NULL)
9576 {
9577 /* Output 'pastetoggle' as key names. For other
9578 * options some characters have to be escaped with
9579 * CTRL-V or backslash */
9580 if (valuep == &p_pt)
9581 {
9582 s = *valuep;
9583 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009584 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585 return FAIL;
9586 }
9587 else if (expand)
9588 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009589 buf = alloc(MAXPATHL);
9590 if (buf == NULL)
9591 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9593 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009594 {
9595 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009596 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009597 }
9598 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009599 }
9600 else if (put_escstr(fd, *valuep, 2) == FAIL)
9601 return FAIL;
9602 }
9603 if (put_eol(fd) < 0)
9604 return FAIL;
9605 return OK;
9606}
9607
9608 static int
9609put_setnum(fd, cmd, name, valuep)
9610 FILE *fd;
9611 char *cmd;
9612 char *name;
9613 long *valuep;
9614{
9615 long wc;
9616
9617 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9618 return FAIL;
9619 if (wc_use_keyname((char_u *)valuep, &wc))
9620 {
9621 /* print 'wildchar' and 'wildcharm' as a key name */
9622 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9623 return FAIL;
9624 }
9625 else if (fprintf(fd, "%ld", *valuep) < 0)
9626 return FAIL;
9627 if (put_eol(fd) < 0)
9628 return FAIL;
9629 return OK;
9630}
9631
9632 static int
9633put_setbool(fd, cmd, name, value)
9634 FILE *fd;
9635 char *cmd;
9636 char *name;
9637 int value;
9638{
Bram Moolenaar893de922007-10-02 18:40:57 +00009639 if (value < 0) /* global/local option using global value */
9640 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009641 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9642 || put_eol(fd) < 0)
9643 return FAIL;
9644 return OK;
9645}
9646
9647/*
9648 * Clear all the terminal options.
9649 * If the option has been allocated, free the memory.
9650 * Terminal options are never hidden or indirect.
9651 */
9652 void
9653clear_termoptions()
9654{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009655 /*
9656 * Reset a few things before clearing the old options. This may cause
9657 * outputting a few things that the terminal doesn't understand, but the
9658 * screen will be cleared later, so this is OK.
9659 */
9660#ifdef FEAT_MOUSE_TTY
9661 mch_setmouse(FALSE); /* switch mouse off */
9662#endif
9663#ifdef FEAT_TITLE
9664 mch_restore_title(3); /* restore window titles */
9665#endif
9666#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9667 /* When starting the GUI close the display opened for the clipboard.
9668 * After restoring the title, because that will need the display. */
9669 if (gui.starting)
9670 clear_xterm_clip();
9671#endif
9672#ifdef WIN3264
9673 /*
9674 * Check if this is allowed now.
9675 */
9676 if (can_end_termcap_mode(FALSE) == TRUE)
9677#endif
9678 stoptermcap(); /* stop termcap mode */
9679
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009680 free_termoptions();
9681}
9682
9683 void
9684free_termoptions()
9685{
9686 struct vimoption *p;
9687
Bram Moolenaar071d4272004-06-13 20:20:40 +00009688 for (p = &options[0]; p->fullname != NULL; p++)
9689 if (istermoption(p))
9690 {
9691 if (p->flags & P_ALLOCED)
9692 free_string_option(*(char_u **)(p->var));
9693 if (p->flags & P_DEF_ALLOCED)
9694 free_string_option(p->def_val[VI_DEFAULT]);
9695 *(char_u **)(p->var) = empty_option;
9696 p->def_val[VI_DEFAULT] = empty_option;
9697 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9698 }
9699 clear_termcodes();
9700}
9701
9702/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009703 * Free the string for one term option, if it was allocated.
9704 * Set the string to empty_option and clear allocated flag.
9705 * "var" points to the option value.
9706 */
9707 void
9708free_one_termoption(var)
9709 char_u *var;
9710{
9711 struct vimoption *p;
9712
9713 for (p = &options[0]; p->fullname != NULL; p++)
9714 if (p->var == var)
9715 {
9716 if (p->flags & P_ALLOCED)
9717 free_string_option(*(char_u **)(p->var));
9718 *(char_u **)(p->var) = empty_option;
9719 p->flags &= ~P_ALLOCED;
9720 break;
9721 }
9722}
9723
9724/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725 * Set the terminal option defaults to the current value.
9726 * Used after setting the terminal name.
9727 */
9728 void
9729set_term_defaults()
9730{
9731 struct vimoption *p;
9732
9733 for (p = &options[0]; p->fullname != NULL; p++)
9734 {
9735 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9736 {
9737 if (p->flags & P_DEF_ALLOCED)
9738 {
9739 free_string_option(p->def_val[VI_DEFAULT]);
9740 p->flags &= ~P_DEF_ALLOCED;
9741 }
9742 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9743 if (p->flags & P_ALLOCED)
9744 {
9745 p->flags |= P_DEF_ALLOCED;
9746 p->flags &= ~P_ALLOCED; /* don't free the value now */
9747 }
9748 }
9749 }
9750}
9751
9752/*
9753 * return TRUE if 'p' starts with 't_'
9754 */
9755 static int
9756istermoption(p)
9757 struct vimoption *p;
9758{
9759 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9760}
9761
9762/*
9763 * Compute columns for ruler and shown command. 'sc_col' is also used to
9764 * decide what the maximum length of a message on the status line can be.
9765 * If there is a status line for the last window, 'sc_col' is independent
9766 * of 'ru_col'.
9767 */
9768
9769#define COL_RULER 17 /* columns needed by standard ruler */
9770
9771 void
9772comp_col()
9773{
9774#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9775 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9776
9777 sc_col = 0;
9778 ru_col = 0;
9779 if (p_ru)
9780 {
9781#ifdef FEAT_STL_OPT
9782 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9783#else
9784 ru_col = COL_RULER + 1;
9785#endif
9786 /* no last status line, adjust sc_col */
9787 if (!last_has_status)
9788 sc_col = ru_col;
9789 }
9790 if (p_sc)
9791 {
9792 sc_col += SHOWCMD_COLS;
9793 if (!p_ru || last_has_status) /* no need for separating space */
9794 ++sc_col;
9795 }
9796 sc_col = Columns - sc_col;
9797 ru_col = Columns - ru_col;
9798 if (sc_col <= 0) /* screen too narrow, will become a mess */
9799 sc_col = 1;
9800 if (ru_col <= 0)
9801 ru_col = 1;
9802#else
9803 sc_col = Columns;
9804 ru_col = Columns;
9805#endif
9806}
9807
9808/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009809 * Unset local option value, similar to ":set opt<".
9810 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009811 void
9812unset_global_local_option(name, from)
9813 char_u *name;
9814 void *from;
9815{
9816 struct vimoption *p;
9817 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009818 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009819
9820 opt_idx = findoption(name);
9821 p = &(options[opt_idx]);
9822
9823 switch ((int)p->indir)
9824 {
9825 /* global option with local value: use local value if it's been set */
9826 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009827 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009828 break;
9829 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009830 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009831 break;
9832 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009833 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009834 break;
9835 case PV_AR:
9836 buf->b_p_ar = -1;
9837 break;
9838 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009839 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009840 break;
9841#ifdef FEAT_FIND_ID
9842 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009843 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009844 break;
9845 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009846 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009847 break;
9848#endif
9849#ifdef FEAT_INS_EXPAND
9850 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009851 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009852 break;
9853 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009854 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009855 break;
9856#endif
9857#ifdef FEAT_QUICKFIX
9858 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009859 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009860 break;
9861 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009862 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009863 break;
9864 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009865 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009866 break;
9867#endif
9868#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9869 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009870 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009871 break;
9872#endif
9873#if defined(FEAT_CRYPT)
9874 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009875 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009876 break;
9877#endif
9878#ifdef FEAT_STL_OPT
9879 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009880 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009881 break;
9882#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009883 case PV_UL:
9884 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9885 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009886#ifdef FEAT_LISP
9887 case PV_LW:
9888 clear_string_option(&buf->b_p_lw);
9889 break;
9890#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009891 }
9892}
9893
9894/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009895 * Get pointer to option variable, depending on local or global scope.
9896 */
9897 static char_u *
9898get_varp_scope(p, opt_flags)
9899 struct vimoption *p;
9900 int opt_flags;
9901{
9902 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9903 {
9904 if (p->var == VAR_WIN)
9905 return (char_u *)GLOBAL_WO(get_varp(p));
9906 return p->var;
9907 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009908 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909 {
9910 switch ((int)p->indir)
9911 {
9912#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009913 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9914 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9915 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009916#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009917 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9918 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9919 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009920 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009921 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009922#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009923 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9924 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009925#endif
9926#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009927 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9928 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009929#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009930#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9931 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9932#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009933#if defined(FEAT_CRYPT)
9934 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9935#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009936#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009937 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009938#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009939 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009940#ifdef FEAT_LISP
9941 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9942#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009943 }
9944 return NULL; /* "cannot happen" */
9945 }
9946 return get_varp(p);
9947}
9948
9949/*
9950 * Get pointer to option variable.
9951 */
9952 static char_u *
9953get_varp(p)
9954 struct vimoption *p;
9955{
9956 /* hidden option, always return NULL */
9957 if (p->var == NULL)
9958 return NULL;
9959
9960 switch ((int)p->indir)
9961 {
9962 case PV_NONE: return p->var;
9963
9964 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009965 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009967 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009968 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009969 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009970 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009971 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009973 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9975#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009976 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009978 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9980#endif
9981#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009982 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009984 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9986#endif
9987#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009988 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009990 case PV_GP: return *curbuf->b_p_gp != NUL
9991 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9992 case PV_MP: return *curbuf->b_p_mp != NUL
9993 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009994#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009995#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9996 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9997 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9998#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009999#if defined(FEAT_CRYPT)
10000 case PV_CM: return *curbuf->b_p_cm != NUL
10001 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10002#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010003#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010004 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010005 ? (char_u *)&(curwin->w_p_stl) : p->var;
10006#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010007 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10008 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010009#ifdef FEAT_LISP
10010 case PV_LW: return *curbuf->b_p_lw != NUL
10011 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10012#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010013
10014#ifdef FEAT_ARABIC
10015 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10016#endif
10017 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010018#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010019 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10020#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010021#ifdef FEAT_SYN_HL
10022 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10023 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010024 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010026#ifdef FEAT_DIFF
10027 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10028#endif
10029#ifdef FEAT_FOLDING
10030 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10031 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10032 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10033 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10034 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10035 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10036 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10037# ifdef FEAT_EVAL
10038 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10039 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10040# endif
10041 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10042#endif
10043 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010044 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010045#ifdef FEAT_LINEBREAK
10046 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10047#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010048#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10050#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010051#ifdef FEAT_VERTSPLIT
10052 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10053#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010054#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10055 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10056#endif
10057#ifdef FEAT_RIGHTLEFT
10058 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10059 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10060#endif
10061 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10062 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10063#ifdef FEAT_LINEBREAK
10064 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
10065#endif
10066#ifdef FEAT_SCROLLBIND
10067 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10068#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010069#ifdef FEAT_CURSORBIND
10070 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10071#endif
10072#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010073 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10074 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010075#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010076
10077 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10078 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10079#ifdef FEAT_MBYTE
10080 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10081#endif
10082#if defined(FEAT_QUICKFIX)
10083 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10084 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10085#endif
10086 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10087 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10088#ifdef FEAT_CINDENT
10089 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10090 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10091 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10092#endif
10093#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10094 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10095#endif
10096#ifdef FEAT_COMMENTS
10097 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10098#endif
10099#ifdef FEAT_FOLDING
10100 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10101#endif
10102#ifdef FEAT_INS_EXPAND
10103 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10104#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010105#ifdef FEAT_COMPL_FUNC
10106 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010107 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010109 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10110 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10111#ifdef FEAT_MBYTE
10112 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10113#endif
10114 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10115#ifdef FEAT_AUTOCMD
10116 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10117#endif
10118 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010119 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10121 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10122 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10123 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10124#ifdef FEAT_FIND_ID
10125# ifdef FEAT_EVAL
10126 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10127# endif
10128#endif
10129#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10130 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10131 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10132#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010133#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010134 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10135#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010136#ifdef FEAT_CRYPT
10137 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10138#endif
10139#ifdef FEAT_LISP
10140 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10141#endif
10142 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10143 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10144 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10145 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10146 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010148#ifdef FEAT_TEXTOBJ
10149 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10150#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10152#ifdef FEAT_SMARTINDENT
10153 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10154#endif
10155#ifndef SHORT_FNAME
10156 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10157#endif
10158 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10159#ifdef FEAT_SEARCHPATH
10160 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10161#endif
10162 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10163#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010164 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010165 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10166#endif
10167#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010168 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10169 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10170 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171#endif
10172 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10173 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10174 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10175 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010176#ifdef FEAT_PERSISTENT_UNDO
10177 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10180#ifdef FEAT_KEYMAP
10181 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10182#endif
10183 default: EMSG(_("E356: get_varp ERROR"));
10184 }
10185 /* always return a valid pointer to avoid a crash! */
10186 return (char_u *)&(curbuf->b_p_wm);
10187}
10188
10189/*
10190 * Get the value of 'equalprg', either the buffer-local one or the global one.
10191 */
10192 char_u *
10193get_equalprg()
10194{
10195 if (*curbuf->b_p_ep == NUL)
10196 return p_ep;
10197 return curbuf->b_p_ep;
10198}
10199
10200#if defined(FEAT_WINDOWS) || defined(PROTO)
10201/*
10202 * Copy options from one window to another.
10203 * Used when splitting a window.
10204 */
10205 void
10206win_copy_options(wp_from, wp_to)
10207 win_T *wp_from;
10208 win_T *wp_to;
10209{
10210 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10211 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10212# ifdef FEAT_RIGHTLEFT
10213# ifdef FEAT_FKMAP
10214 /* Is this right? */
10215 wp_to->w_farsi = wp_from->w_farsi;
10216# endif
10217# endif
10218}
10219#endif
10220
10221/*
10222 * Copy the options from one winopt_T to another.
10223 * Doesn't free the old option values in "to", use clear_winopt() for that.
10224 * The 'scroll' option is not copied, because it depends on the window height.
10225 * The 'previewwindow' option is reset, there can be only one preview window.
10226 */
10227 void
10228copy_winopt(from, to)
10229 winopt_T *from;
10230 winopt_T *to;
10231{
10232#ifdef FEAT_ARABIC
10233 to->wo_arab = from->wo_arab;
10234#endif
10235 to->wo_list = from->wo_list;
10236 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010237 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010238#ifdef FEAT_LINEBREAK
10239 to->wo_nuw = from->wo_nuw;
10240#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241#ifdef FEAT_RIGHTLEFT
10242 to->wo_rl = from->wo_rl;
10243 to->wo_rlc = vim_strsave(from->wo_rlc);
10244#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010245#ifdef FEAT_STL_OPT
10246 to->wo_stl = vim_strsave(from->wo_stl);
10247#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010249#ifdef FEAT_DIFF
10250 to->wo_wrap_save = from->wo_wrap_save;
10251#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252#ifdef FEAT_LINEBREAK
10253 to->wo_lbr = from->wo_lbr;
10254#endif
10255#ifdef FEAT_SCROLLBIND
10256 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010257 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010259#ifdef FEAT_CURSORBIND
10260 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010261 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010262#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010263#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010264 to->wo_spell = from->wo_spell;
10265#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010266#ifdef FEAT_SYN_HL
10267 to->wo_cuc = from->wo_cuc;
10268 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010269 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010270#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271#ifdef FEAT_DIFF
10272 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010273 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010275#ifdef FEAT_CONCEAL
10276 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010277 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010278#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279#ifdef FEAT_FOLDING
10280 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010281 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010283 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010284 to->wo_fdi = vim_strsave(from->wo_fdi);
10285 to->wo_fml = from->wo_fml;
10286 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010287 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010288 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010289 to->wo_fdm_save = from->wo_diff_saved
10290 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010291 to->wo_fdn = from->wo_fdn;
10292# ifdef FEAT_EVAL
10293 to->wo_fde = vim_strsave(from->wo_fde);
10294 to->wo_fdt = vim_strsave(from->wo_fdt);
10295# endif
10296 to->wo_fmr = vim_strsave(from->wo_fmr);
10297#endif
10298 check_winopt(to); /* don't want NULL pointers */
10299}
10300
10301/*
10302 * Check string options in a window for a NULL value.
10303 */
10304 void
10305check_win_options(win)
10306 win_T *win;
10307{
10308 check_winopt(&win->w_onebuf_opt);
10309 check_winopt(&win->w_allbuf_opt);
10310}
10311
10312/*
10313 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10314 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 void
10316check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010317 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318{
10319#ifdef FEAT_FOLDING
10320 check_string_option(&wop->wo_fdi);
10321 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010322 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323# ifdef FEAT_EVAL
10324 check_string_option(&wop->wo_fde);
10325 check_string_option(&wop->wo_fdt);
10326# endif
10327 check_string_option(&wop->wo_fmr);
10328#endif
10329#ifdef FEAT_RIGHTLEFT
10330 check_string_option(&wop->wo_rlc);
10331#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010332#ifdef FEAT_STL_OPT
10333 check_string_option(&wop->wo_stl);
10334#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010335#ifdef FEAT_SYN_HL
10336 check_string_option(&wop->wo_cc);
10337#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010338#ifdef FEAT_CONCEAL
10339 check_string_option(&wop->wo_cocu);
10340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341}
10342
10343/*
10344 * Free the allocated memory inside a winopt_T.
10345 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346 void
10347clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010348 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349{
10350#ifdef FEAT_FOLDING
10351 clear_string_option(&wop->wo_fdi);
10352 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010353 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010354# ifdef FEAT_EVAL
10355 clear_string_option(&wop->wo_fde);
10356 clear_string_option(&wop->wo_fdt);
10357# endif
10358 clear_string_option(&wop->wo_fmr);
10359#endif
10360#ifdef FEAT_RIGHTLEFT
10361 clear_string_option(&wop->wo_rlc);
10362#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010363#ifdef FEAT_STL_OPT
10364 clear_string_option(&wop->wo_stl);
10365#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010366#ifdef FEAT_SYN_HL
10367 clear_string_option(&wop->wo_cc);
10368#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010369#ifdef FEAT_CONCEAL
10370 clear_string_option(&wop->wo_cocu);
10371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372}
10373
10374/*
10375 * Copy global option values to local options for one buffer.
10376 * Used when creating a new buffer and sometimes when entering a buffer.
10377 * flags:
10378 * BCO_ENTER We will enter the buf buffer.
10379 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10380 * appropriate.
10381 * BCO_NOHELP Don't copy the values to a help buffer.
10382 */
10383 void
10384buf_copy_options(buf, flags)
10385 buf_T *buf;
10386 int flags;
10387{
10388 int should_copy = TRUE;
10389 char_u *save_p_isk = NULL; /* init for GCC */
10390 int dont_do_help;
10391 int did_isk = FALSE;
10392
10393 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010394 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395 */
10396 if (buf == NULL || !buf_valid(buf))
10397 return;
10398
10399 /*
10400 * Skip this when the option defaults have not been set yet. Happens when
10401 * main() allocates the first buffer.
10402 */
10403 if (p_cpo != NULL)
10404 {
10405 /*
10406 * Always copy when entering and 'cpo' contains 'S'.
10407 * Don't copy when already initialized.
10408 * Don't copy when 'cpo' contains 's' and not entering.
10409 * 'S' BCO_ENTER initialized 's' should_copy
10410 * yes yes X X TRUE
10411 * yes no yes X FALSE
10412 * no X yes X FALSE
10413 * X no no yes FALSE
10414 * X no no no TRUE
10415 * no yes no X TRUE
10416 */
10417 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10418 && (buf->b_p_initialized
10419 || (!(flags & BCO_ENTER)
10420 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10421 should_copy = FALSE;
10422
10423 if (should_copy || (flags & BCO_ALWAYS))
10424 {
10425 /* Don't copy the options specific to a help buffer when
10426 * BCO_NOHELP is given or the options were initialized already
10427 * (jumping back to a help file with CTRL-T or CTRL-O) */
10428 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10429 || buf->b_p_initialized;
10430 if (dont_do_help) /* don't free b_p_isk */
10431 {
10432 save_p_isk = buf->b_p_isk;
10433 buf->b_p_isk = NULL;
10434 }
10435 /*
10436 * Always free the allocated strings.
10437 * If not already initialized, set 'readonly' and copy 'fileformat'.
10438 */
10439 if (!buf->b_p_initialized)
10440 {
10441 free_buf_options(buf, TRUE);
10442 buf->b_p_ro = FALSE; /* don't copy readonly */
10443 buf->b_p_tx = p_tx;
10444#ifdef FEAT_MBYTE
10445 buf->b_p_fenc = vim_strsave(p_fenc);
10446#endif
10447 buf->b_p_ff = vim_strsave(p_ff);
10448#if defined(FEAT_QUICKFIX)
10449 buf->b_p_bh = empty_option;
10450 buf->b_p_bt = empty_option;
10451#endif
10452 }
10453 else
10454 free_buf_options(buf, FALSE);
10455
10456 buf->b_p_ai = p_ai;
10457 buf->b_p_ai_nopaste = p_ai_nopaste;
10458 buf->b_p_sw = p_sw;
10459 buf->b_p_tw = p_tw;
10460 buf->b_p_tw_nopaste = p_tw_nopaste;
10461 buf->b_p_tw_nobin = p_tw_nobin;
10462 buf->b_p_wm = p_wm;
10463 buf->b_p_wm_nopaste = p_wm_nopaste;
10464 buf->b_p_wm_nobin = p_wm_nobin;
10465 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010466#ifdef FEAT_MBYTE
10467 buf->b_p_bomb = p_bomb;
10468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469 buf->b_p_et = p_et;
10470 buf->b_p_et_nobin = p_et_nobin;
10471 buf->b_p_ml = p_ml;
10472 buf->b_p_ml_nobin = p_ml_nobin;
10473 buf->b_p_inf = p_inf;
10474 buf->b_p_swf = p_swf;
10475#ifdef FEAT_INS_EXPAND
10476 buf->b_p_cpt = vim_strsave(p_cpt);
10477#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010478#ifdef FEAT_COMPL_FUNC
10479 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010480 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010481#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482 buf->b_p_sts = p_sts;
10483 buf->b_p_sts_nopaste = p_sts_nopaste;
10484#ifndef SHORT_FNAME
10485 buf->b_p_sn = p_sn;
10486#endif
10487#ifdef FEAT_COMMENTS
10488 buf->b_p_com = vim_strsave(p_com);
10489#endif
10490#ifdef FEAT_FOLDING
10491 buf->b_p_cms = vim_strsave(p_cms);
10492#endif
10493 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010494 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010495 buf->b_p_nf = vim_strsave(p_nf);
10496 buf->b_p_mps = vim_strsave(p_mps);
10497#ifdef FEAT_SMARTINDENT
10498 buf->b_p_si = p_si;
10499#endif
10500 buf->b_p_ci = p_ci;
10501#ifdef FEAT_CINDENT
10502 buf->b_p_cin = p_cin;
10503 buf->b_p_cink = vim_strsave(p_cink);
10504 buf->b_p_cino = vim_strsave(p_cino);
10505#endif
10506#ifdef FEAT_AUTOCMD
10507 /* Don't copy 'filetype', it must be detected */
10508 buf->b_p_ft = empty_option;
10509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510 buf->b_p_pi = p_pi;
10511#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10512 buf->b_p_cinw = vim_strsave(p_cinw);
10513#endif
10514#ifdef FEAT_LISP
10515 buf->b_p_lisp = p_lisp;
10516#endif
10517#ifdef FEAT_SYN_HL
10518 /* Don't copy 'syntax', it must be set */
10519 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010520 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010521#endif
10522#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010523 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010524 (void)compile_cap_prog(&buf->b_s);
10525 buf->b_s.b_p_spf = vim_strsave(p_spf);
10526 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527#endif
10528#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10529 buf->b_p_inde = vim_strsave(p_inde);
10530 buf->b_p_indk = vim_strsave(p_indk);
10531#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010532#if defined(FEAT_EVAL)
10533 buf->b_p_fex = vim_strsave(p_fex);
10534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535#ifdef FEAT_CRYPT
10536 buf->b_p_key = vim_strsave(p_key);
10537#endif
10538#ifdef FEAT_SEARCHPATH
10539 buf->b_p_sua = vim_strsave(p_sua);
10540#endif
10541#ifdef FEAT_KEYMAP
10542 buf->b_p_keymap = vim_strsave(p_keymap);
10543 buf->b_kmap_state |= KEYMAP_INIT;
10544#endif
10545 /* This isn't really an option, but copying the langmap and IME
10546 * state from the current buffer is better than resetting it. */
10547 buf->b_p_iminsert = p_iminsert;
10548 buf->b_p_imsearch = p_imsearch;
10549
10550 /* options that are normally global but also have a local value
10551 * are not copied, start using the global value */
10552 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010553 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554#ifdef FEAT_QUICKFIX
10555 buf->b_p_gp = empty_option;
10556 buf->b_p_mp = empty_option;
10557 buf->b_p_efm = empty_option;
10558#endif
10559 buf->b_p_ep = empty_option;
10560 buf->b_p_kp = empty_option;
10561 buf->b_p_path = empty_option;
10562 buf->b_p_tags = empty_option;
10563#ifdef FEAT_FIND_ID
10564 buf->b_p_def = empty_option;
10565 buf->b_p_inc = empty_option;
10566# ifdef FEAT_EVAL
10567 buf->b_p_inex = vim_strsave(p_inex);
10568# endif
10569#endif
10570#ifdef FEAT_INS_EXPAND
10571 buf->b_p_dict = empty_option;
10572 buf->b_p_tsr = empty_option;
10573#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010574#ifdef FEAT_TEXTOBJ
10575 buf->b_p_qe = vim_strsave(p_qe);
10576#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010577#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10578 buf->b_p_bexpr = empty_option;
10579#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010580#if defined(FEAT_CRYPT)
10581 buf->b_p_cm = empty_option;
10582#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010583#ifdef FEAT_PERSISTENT_UNDO
10584 buf->b_p_udf = p_udf;
10585#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010586#ifdef FEAT_LISP
10587 buf->b_p_lw = empty_option;
10588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589
10590 /*
10591 * Don't copy the options set by ex_help(), use the saved values,
10592 * when going from a help buffer to a non-help buffer.
10593 * Don't touch these at all when BCO_NOHELP is used and going from
10594 * or to a help buffer.
10595 */
10596 if (dont_do_help)
10597 buf->b_p_isk = save_p_isk;
10598 else
10599 {
10600 buf->b_p_isk = vim_strsave(p_isk);
10601 did_isk = TRUE;
10602 buf->b_p_ts = p_ts;
10603 buf->b_help = FALSE;
10604#ifdef FEAT_QUICKFIX
10605 if (buf->b_p_bt[0] == 'h')
10606 clear_string_option(&buf->b_p_bt);
10607#endif
10608 buf->b_p_ma = p_ma;
10609 }
10610 }
10611
10612 /*
10613 * When the options should be copied (ignoring BCO_ALWAYS), set the
10614 * flag that indicates that the options have been initialized.
10615 */
10616 if (should_copy)
10617 buf->b_p_initialized = TRUE;
10618 }
10619
10620 check_buf_options(buf); /* make sure we don't have NULLs */
10621 if (did_isk)
10622 (void)buf_init_chartab(buf, FALSE);
10623}
10624
10625/*
10626 * Reset the 'modifiable' option and its default value.
10627 */
10628 void
10629reset_modifiable()
10630{
10631 int opt_idx;
10632
10633 curbuf->b_p_ma = FALSE;
10634 p_ma = FALSE;
10635 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010636 if (opt_idx >= 0)
10637 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010638}
10639
10640/*
10641 * Set the global value for 'iminsert' to the local value.
10642 */
10643 void
10644set_iminsert_global()
10645{
10646 p_iminsert = curbuf->b_p_iminsert;
10647}
10648
10649/*
10650 * Set the global value for 'imsearch' to the local value.
10651 */
10652 void
10653set_imsearch_global()
10654{
10655 p_imsearch = curbuf->b_p_imsearch;
10656}
10657
10658#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10659static int expand_option_idx = -1;
10660static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10661static int expand_option_flags = 0;
10662
10663 void
10664set_context_in_set_cmd(xp, arg, opt_flags)
10665 expand_T *xp;
10666 char_u *arg;
10667 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10668{
10669 int nextchar;
10670 long_u flags = 0; /* init for GCC */
10671 int opt_idx = 0; /* init for GCC */
10672 char_u *p;
10673 char_u *s;
10674 int is_term_option = FALSE;
10675 int key;
10676
10677 expand_option_flags = opt_flags;
10678
10679 xp->xp_context = EXPAND_SETTINGS;
10680 if (*arg == NUL)
10681 {
10682 xp->xp_pattern = arg;
10683 return;
10684 }
10685 p = arg + STRLEN(arg) - 1;
10686 if (*p == ' ' && *(p - 1) != '\\')
10687 {
10688 xp->xp_pattern = p + 1;
10689 return;
10690 }
10691 while (p > arg)
10692 {
10693 s = p;
10694 /* count number of backslashes before ' ' or ',' */
10695 if (*p == ' ' || *p == ',')
10696 {
10697 while (s > arg && *(s - 1) == '\\')
10698 --s;
10699 }
10700 /* break at a space with an even number of backslashes */
10701 if (*p == ' ' && ((p - s) & 1) == 0)
10702 {
10703 ++p;
10704 break;
10705 }
10706 --p;
10707 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010708 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 {
10710 xp->xp_context = EXPAND_BOOL_SETTINGS;
10711 p += 2;
10712 }
10713 if (STRNCMP(p, "inv", 3) == 0)
10714 {
10715 xp->xp_context = EXPAND_BOOL_SETTINGS;
10716 p += 3;
10717 }
10718 xp->xp_pattern = arg = p;
10719 if (*arg == '<')
10720 {
10721 while (*p != '>')
10722 if (*p++ == NUL) /* expand terminal option name */
10723 return;
10724 key = get_special_key_code(arg + 1);
10725 if (key == 0) /* unknown name */
10726 {
10727 xp->xp_context = EXPAND_NOTHING;
10728 return;
10729 }
10730 nextchar = *++p;
10731 is_term_option = TRUE;
10732 expand_option_name[2] = KEY2TERMCAP0(key);
10733 expand_option_name[3] = KEY2TERMCAP1(key);
10734 }
10735 else
10736 {
10737 if (p[0] == 't' && p[1] == '_')
10738 {
10739 p += 2;
10740 if (*p != NUL)
10741 ++p;
10742 if (*p == NUL)
10743 return; /* expand option name */
10744 nextchar = *++p;
10745 is_term_option = TRUE;
10746 expand_option_name[2] = p[-2];
10747 expand_option_name[3] = p[-1];
10748 }
10749 else
10750 {
10751 /* Allow * wildcard */
10752 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10753 p++;
10754 if (*p == NUL)
10755 return;
10756 nextchar = *p;
10757 *p = NUL;
10758 opt_idx = findoption(arg);
10759 *p = nextchar;
10760 if (opt_idx == -1 || options[opt_idx].var == NULL)
10761 {
10762 xp->xp_context = EXPAND_NOTHING;
10763 return;
10764 }
10765 flags = options[opt_idx].flags;
10766 if (flags & P_BOOL)
10767 {
10768 xp->xp_context = EXPAND_NOTHING;
10769 return;
10770 }
10771 }
10772 }
10773 /* handle "-=" and "+=" */
10774 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10775 {
10776 ++p;
10777 nextchar = '=';
10778 }
10779 if ((nextchar != '=' && nextchar != ':')
10780 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10781 {
10782 xp->xp_context = EXPAND_UNSUCCESSFUL;
10783 return;
10784 }
10785 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10786 {
10787 xp->xp_context = EXPAND_OLD_SETTING;
10788 if (is_term_option)
10789 expand_option_idx = -1;
10790 else
10791 expand_option_idx = opt_idx;
10792 xp->xp_pattern = p + 1;
10793 return;
10794 }
10795 xp->xp_context = EXPAND_NOTHING;
10796 if (is_term_option || (flags & P_NUM))
10797 return;
10798
10799 xp->xp_pattern = p + 1;
10800
10801 if (flags & P_EXPAND)
10802 {
10803 p = options[opt_idx].var;
10804 if (p == (char_u *)&p_bdir
10805 || p == (char_u *)&p_dir
10806 || p == (char_u *)&p_path
10807 || p == (char_u *)&p_rtp
10808#ifdef FEAT_SEARCHPATH
10809 || p == (char_u *)&p_cdpath
10810#endif
10811#ifdef FEAT_SESSION
10812 || p == (char_u *)&p_vdir
10813#endif
10814 )
10815 {
10816 xp->xp_context = EXPAND_DIRECTORIES;
10817 if (p == (char_u *)&p_path
10818#ifdef FEAT_SEARCHPATH
10819 || p == (char_u *)&p_cdpath
10820#endif
10821 )
10822 xp->xp_backslash = XP_BS_THREE;
10823 else
10824 xp->xp_backslash = XP_BS_ONE;
10825 }
10826 else
10827 {
10828 xp->xp_context = EXPAND_FILES;
10829 /* for 'tags' need three backslashes for a space */
10830 if (p == (char_u *)&p_tags)
10831 xp->xp_backslash = XP_BS_THREE;
10832 else
10833 xp->xp_backslash = XP_BS_ONE;
10834 }
10835 }
10836
10837 /* For an option that is a list of file names, find the start of the
10838 * last file name. */
10839 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10840 {
10841 /* count number of backslashes before ' ' or ',' */
10842 if (*p == ' ' || *p == ',')
10843 {
10844 s = p;
10845 while (s > xp->xp_pattern && *(s - 1) == '\\')
10846 --s;
10847 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10848 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10849 {
10850 xp->xp_pattern = p + 1;
10851 break;
10852 }
10853 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010854
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010855#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010856 /* for 'spellsuggest' start at "file:" */
10857 if (options[opt_idx].var == (char_u *)&p_sps
10858 && STRNCMP(p, "file:", 5) == 0)
10859 {
10860 xp->xp_pattern = p + 5;
10861 break;
10862 }
10863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864 }
10865
10866 return;
10867}
10868
10869 int
10870ExpandSettings(xp, regmatch, num_file, file)
10871 expand_T *xp;
10872 regmatch_T *regmatch;
10873 int *num_file;
10874 char_u ***file;
10875{
10876 int num_normal = 0; /* Nr of matching non-term-code settings */
10877 int num_term = 0; /* Nr of matching terminal code settings */
10878 int opt_idx;
10879 int match;
10880 int count = 0;
10881 char_u *str;
10882 int loop;
10883 int is_term_opt;
10884 char_u name_buf[MAX_KEY_NAME_LEN];
10885 static char *(names[]) = {"all", "termcap"};
10886 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10887
10888 /* do this loop twice:
10889 * loop == 0: count the number of matching options
10890 * loop == 1: copy the matching options into allocated memory
10891 */
10892 for (loop = 0; loop <= 1; ++loop)
10893 {
10894 regmatch->rm_ic = ic;
10895 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10896 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010897 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10898 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10900 {
10901 if (loop == 0)
10902 num_normal++;
10903 else
10904 (*file)[count++] = vim_strsave((char_u *)names[match]);
10905 }
10906 }
10907 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10908 opt_idx++)
10909 {
10910 if (options[opt_idx].var == NULL)
10911 continue;
10912 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10913 && !(options[opt_idx].flags & P_BOOL))
10914 continue;
10915 is_term_opt = istermoption(&options[opt_idx]);
10916 if (is_term_opt && num_normal > 0)
10917 continue;
10918 match = FALSE;
10919 if (vim_regexec(regmatch, str, (colnr_T)0)
10920 || (options[opt_idx].shortname != NULL
10921 && vim_regexec(regmatch,
10922 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10923 match = TRUE;
10924 else if (is_term_opt)
10925 {
10926 name_buf[0] = '<';
10927 name_buf[1] = 't';
10928 name_buf[2] = '_';
10929 name_buf[3] = str[2];
10930 name_buf[4] = str[3];
10931 name_buf[5] = '>';
10932 name_buf[6] = NUL;
10933 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10934 {
10935 match = TRUE;
10936 str = name_buf;
10937 }
10938 }
10939 if (match)
10940 {
10941 if (loop == 0)
10942 {
10943 if (is_term_opt)
10944 num_term++;
10945 else
10946 num_normal++;
10947 }
10948 else
10949 (*file)[count++] = vim_strsave(str);
10950 }
10951 }
10952 /*
10953 * Check terminal key codes, these are not in the option table
10954 */
10955 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10956 {
10957 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10958 {
10959 if (!isprint(str[0]) || !isprint(str[1]))
10960 continue;
10961
10962 name_buf[0] = 't';
10963 name_buf[1] = '_';
10964 name_buf[2] = str[0];
10965 name_buf[3] = str[1];
10966 name_buf[4] = NUL;
10967
10968 match = FALSE;
10969 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10970 match = TRUE;
10971 else
10972 {
10973 name_buf[0] = '<';
10974 name_buf[1] = 't';
10975 name_buf[2] = '_';
10976 name_buf[3] = str[0];
10977 name_buf[4] = str[1];
10978 name_buf[5] = '>';
10979 name_buf[6] = NUL;
10980
10981 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10982 match = TRUE;
10983 }
10984 if (match)
10985 {
10986 if (loop == 0)
10987 num_term++;
10988 else
10989 (*file)[count++] = vim_strsave(name_buf);
10990 }
10991 }
10992
10993 /*
10994 * Check special key names.
10995 */
10996 regmatch->rm_ic = TRUE; /* ignore case here */
10997 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10998 {
10999 name_buf[0] = '<';
11000 STRCPY(name_buf + 1, str);
11001 STRCAT(name_buf, ">");
11002
11003 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11004 {
11005 if (loop == 0)
11006 num_term++;
11007 else
11008 (*file)[count++] = vim_strsave(name_buf);
11009 }
11010 }
11011 }
11012 if (loop == 0)
11013 {
11014 if (num_normal > 0)
11015 *num_file = num_normal;
11016 else if (num_term > 0)
11017 *num_file = num_term;
11018 else
11019 return OK;
11020 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11021 if (*file == NULL)
11022 {
11023 *file = (char_u **)"";
11024 return FAIL;
11025 }
11026 }
11027 }
11028 return OK;
11029}
11030
11031 int
11032ExpandOldSetting(num_file, file)
11033 int *num_file;
11034 char_u ***file;
11035{
11036 char_u *var = NULL; /* init for GCC */
11037 char_u *buf;
11038
11039 *num_file = 0;
11040 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11041 if (*file == NULL)
11042 return FAIL;
11043
11044 /*
11045 * For a terminal key code expand_option_idx is < 0.
11046 */
11047 if (expand_option_idx < 0)
11048 {
11049 var = find_termcode(expand_option_name + 2);
11050 if (var == NULL)
11051 expand_option_idx = findoption(expand_option_name);
11052 }
11053
11054 if (expand_option_idx >= 0)
11055 {
11056 /* put string of option value in NameBuff */
11057 option_value2string(&options[expand_option_idx], expand_option_flags);
11058 var = NameBuff;
11059 }
11060 else if (var == NULL)
11061 var = (char_u *)"";
11062
11063 /* A backslash is required before some characters. This is the reverse of
11064 * what happens in do_set(). */
11065 buf = vim_strsave_escaped(var, escape_chars);
11066
11067 if (buf == NULL)
11068 {
11069 vim_free(*file);
11070 *file = NULL;
11071 return FAIL;
11072 }
11073
11074#ifdef BACKSLASH_IN_FILENAME
11075 /* For MS-Windows et al. we don't double backslashes at the start and
11076 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011077 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 if (var[0] == '\\' && var[1] == '\\'
11079 && expand_option_idx >= 0
11080 && (options[expand_option_idx].flags & P_EXPAND)
11081 && vim_isfilec(var[2])
11082 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011083 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011084#endif
11085
11086 *file[0] = buf;
11087 *num_file = 1;
11088 return OK;
11089}
11090#endif
11091
11092/*
11093 * Get the value for the numeric or string option *opp in a nice format into
11094 * NameBuff[]. Must not be called with a hidden option!
11095 */
11096 static void
11097option_value2string(opp, opt_flags)
11098 struct vimoption *opp;
11099 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11100{
11101 char_u *varp;
11102
11103 varp = get_varp_scope(opp, opt_flags);
11104
11105 if (opp->flags & P_NUM)
11106 {
11107 long wc = 0;
11108
11109 if (wc_use_keyname(varp, &wc))
11110 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11111 else if (wc != 0)
11112 STRCPY(NameBuff, transchar((int)wc));
11113 else
11114 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11115 }
11116 else /* P_STRING */
11117 {
11118 varp = *(char_u **)(varp);
11119 if (varp == NULL) /* just in case */
11120 NameBuff[0] = NUL;
11121#ifdef FEAT_CRYPT
11122 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011123 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124 STRCPY(NameBuff, "*****");
11125#endif
11126 else if (opp->flags & P_EXPAND)
11127 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11128 /* Translate 'pastetoggle' into special key names */
11129 else if ((char_u **)opp->var == &p_pt)
11130 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11131 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011132 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133 }
11134}
11135
11136/*
11137 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11138 * printed as a keyname.
11139 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11140 */
11141 static int
11142wc_use_keyname(varp, wcp)
11143 char_u *varp;
11144 long *wcp;
11145{
11146 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11147 {
11148 *wcp = *(long *)varp;
11149 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11150 return TRUE;
11151 }
11152 return FALSE;
11153}
11154
11155#ifdef FEAT_LANGMAP
11156/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011157 * Any character has an equivalent 'langmap' character. This is used for
11158 * keyboards that have a special language mode that sends characters above
11159 * 128 (although other characters can be translated too). The "to" field is a
11160 * Vim command character. This avoids having to switch the keyboard back to
11161 * ASCII mode when leaving Insert mode.
11162 *
11163 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11164 * commands.
11165 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11166 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11167 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011168 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011169# ifdef FEAT_MBYTE
11170/*
11171 * With multi-byte support use growarray for 'langmap' chars >= 256
11172 */
11173typedef struct
11174{
11175 int from;
11176 int to;
11177} langmap_entry_T;
11178
11179static garray_T langmap_mapga;
11180static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181
11182/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011183 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11184 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011186 static void
11187langmap_set_entry(from, to)
11188 int from;
11189 int to;
11190{
11191 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011192 int a = 0;
11193 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011194
11195 /* Do a binary search for an existing entry. */
11196 while (a != b)
11197 {
11198 int i = (a + b) / 2;
11199 int d = entries[i].from - from;
11200
11201 if (d == 0)
11202 {
11203 entries[i].to = to;
11204 return;
11205 }
11206 if (d < 0)
11207 a = i + 1;
11208 else
11209 b = i;
11210 }
11211
11212 if (ga_grow(&langmap_mapga, 1) != OK)
11213 return; /* out of memory */
11214
11215 /* insert new entry at position "a" */
11216 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11217 mch_memmove(entries + 1, entries,
11218 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11219 ++langmap_mapga.ga_len;
11220 entries[0].from = from;
11221 entries[0].to = to;
11222}
11223
11224/*
11225 * Apply 'langmap' to multi-byte character "c" and return the result.
11226 */
11227 int
11228langmap_adjust_mb(c)
11229 int c;
11230{
11231 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11232 int a = 0;
11233 int b = langmap_mapga.ga_len;
11234
11235 while (a != b)
11236 {
11237 int i = (a + b) / 2;
11238 int d = entries[i].from - c;
11239
11240 if (d == 0)
11241 return entries[i].to; /* found matching entry */
11242 if (d < 0)
11243 a = i + 1;
11244 else
11245 b = i;
11246 }
11247 return c; /* no entry found, return "c" unmodified */
11248}
11249# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250
11251 static void
11252langmap_init()
11253{
11254 int i;
11255
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011256 for (i = 0; i < 256; i++)
11257 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11258# ifdef FEAT_MBYTE
11259 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11260# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011261}
11262
11263/*
11264 * Called when langmap option is set; the language map can be
11265 * changed at any time!
11266 */
11267 static void
11268langmap_set()
11269{
11270 char_u *p;
11271 char_u *p2;
11272 int from, to;
11273
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011274#ifdef FEAT_MBYTE
11275 ga_clear(&langmap_mapga); /* clear the previous map first */
11276#endif
11277 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278
11279 for (p = p_langmap; p[0] != NUL; )
11280 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011281 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11282 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011283 {
11284 if (p2[0] == '\\' && p2[1] != NUL)
11285 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286 }
11287 if (p2[0] == ';')
11288 ++p2; /* abcd;ABCD form, p2 points to A */
11289 else
11290 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11291 while (p[0])
11292 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011293 if (p[0] == ',')
11294 {
11295 ++p;
11296 break;
11297 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011298 if (p[0] == '\\' && p[1] != NUL)
11299 ++p;
11300#ifdef FEAT_MBYTE
11301 from = (*mb_ptr2char)(p);
11302#else
11303 from = p[0];
11304#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011305 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011306 if (p2 == NULL)
11307 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011308 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011309 if (p[0] != ',')
11310 {
11311 if (p[0] == '\\')
11312 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011313#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011314 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011316 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011317#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319 }
11320 else
11321 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011322 if (p2[0] != ',')
11323 {
11324 if (p2[0] == '\\')
11325 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011327 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011329 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011331 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332 }
11333 if (to == NUL)
11334 {
11335 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11336 transchar(from));
11337 return;
11338 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011339
11340#ifdef FEAT_MBYTE
11341 if (from >= 256)
11342 langmap_set_entry(from, to);
11343 else
11344#endif
11345 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011346
11347 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011348 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011349 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011351 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011352 if (*p == ';')
11353 {
11354 p = p2;
11355 if (p[0] != NUL)
11356 {
11357 if (p[0] != ',')
11358 {
11359 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11360 return;
11361 }
11362 ++p;
11363 }
11364 break;
11365 }
11366 }
11367 }
11368 }
11369}
11370#endif
11371
11372/*
11373 * Return TRUE if format option 'x' is in effect.
11374 * Take care of no formatting when 'paste' is set.
11375 */
11376 int
11377has_format_option(x)
11378 int x;
11379{
11380 if (p_paste)
11381 return FALSE;
11382 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11383}
11384
11385/*
11386 * Return TRUE if "x" is present in 'shortmess' option, or
11387 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11388 */
11389 int
11390shortmess(x)
11391 int x;
11392{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011393 return p_shm != NULL &&
11394 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011395 || (vim_strchr(p_shm, 'a') != NULL
11396 && vim_strchr((char_u *)SHM_A, x) != NULL));
11397}
11398
11399/*
11400 * paste_option_changed() - Called after p_paste was set or reset.
11401 */
11402 static void
11403paste_option_changed()
11404{
11405 static int old_p_paste = FALSE;
11406 static int save_sm = 0;
11407#ifdef FEAT_CMDL_INFO
11408 static int save_ru = 0;
11409#endif
11410#ifdef FEAT_RIGHTLEFT
11411 static int save_ri = 0;
11412 static int save_hkmap = 0;
11413#endif
11414 buf_T *buf;
11415
11416 if (p_paste)
11417 {
11418 /*
11419 * Paste switched from off to on.
11420 * Save the current values, so they can be restored later.
11421 */
11422 if (!old_p_paste)
11423 {
11424 /* save options for each buffer */
11425 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11426 {
11427 buf->b_p_tw_nopaste = buf->b_p_tw;
11428 buf->b_p_wm_nopaste = buf->b_p_wm;
11429 buf->b_p_sts_nopaste = buf->b_p_sts;
11430 buf->b_p_ai_nopaste = buf->b_p_ai;
11431 }
11432
11433 /* save global options */
11434 save_sm = p_sm;
11435#ifdef FEAT_CMDL_INFO
11436 save_ru = p_ru;
11437#endif
11438#ifdef FEAT_RIGHTLEFT
11439 save_ri = p_ri;
11440 save_hkmap = p_hkmap;
11441#endif
11442 /* save global values for local buffer options */
11443 p_tw_nopaste = p_tw;
11444 p_wm_nopaste = p_wm;
11445 p_sts_nopaste = p_sts;
11446 p_ai_nopaste = p_ai;
11447 }
11448
11449 /*
11450 * Always set the option values, also when 'paste' is set when it is
11451 * already on.
11452 */
11453 /* set options for each buffer */
11454 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11455 {
11456 buf->b_p_tw = 0; /* textwidth is 0 */
11457 buf->b_p_wm = 0; /* wrapmargin is 0 */
11458 buf->b_p_sts = 0; /* softtabstop is 0 */
11459 buf->b_p_ai = 0; /* no auto-indent */
11460 }
11461
11462 /* set global options */
11463 p_sm = 0; /* no showmatch */
11464#ifdef FEAT_CMDL_INFO
11465# ifdef FEAT_WINDOWS
11466 if (p_ru)
11467 status_redraw_all(); /* redraw to remove the ruler */
11468# endif
11469 p_ru = 0; /* no ruler */
11470#endif
11471#ifdef FEAT_RIGHTLEFT
11472 p_ri = 0; /* no reverse insert */
11473 p_hkmap = 0; /* no Hebrew keyboard */
11474#endif
11475 /* set global values for local buffer options */
11476 p_tw = 0;
11477 p_wm = 0;
11478 p_sts = 0;
11479 p_ai = 0;
11480 }
11481
11482 /*
11483 * Paste switched from on to off: Restore saved values.
11484 */
11485 else if (old_p_paste)
11486 {
11487 /* restore options for each buffer */
11488 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11489 {
11490 buf->b_p_tw = buf->b_p_tw_nopaste;
11491 buf->b_p_wm = buf->b_p_wm_nopaste;
11492 buf->b_p_sts = buf->b_p_sts_nopaste;
11493 buf->b_p_ai = buf->b_p_ai_nopaste;
11494 }
11495
11496 /* restore global options */
11497 p_sm = save_sm;
11498#ifdef FEAT_CMDL_INFO
11499# ifdef FEAT_WINDOWS
11500 if (p_ru != save_ru)
11501 status_redraw_all(); /* redraw to draw the ruler */
11502# endif
11503 p_ru = save_ru;
11504#endif
11505#ifdef FEAT_RIGHTLEFT
11506 p_ri = save_ri;
11507 p_hkmap = save_hkmap;
11508#endif
11509 /* set global values for local buffer options */
11510 p_tw = p_tw_nopaste;
11511 p_wm = p_wm_nopaste;
11512 p_sts = p_sts_nopaste;
11513 p_ai = p_ai_nopaste;
11514 }
11515
11516 old_p_paste = p_paste;
11517}
11518
11519/*
11520 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11521 *
11522 * Reset 'compatible' and set the values for options that didn't get set yet
11523 * to the Vim defaults.
11524 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011525 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526 */
11527 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011528vimrc_found(fname, envname)
11529 char_u *fname;
11530 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011532 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011533 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011534 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535
11536 if (!option_was_set((char_u *)"cp"))
11537 {
11538 p_cp = FALSE;
11539 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11540 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11541 set_option_default(opt_idx, OPT_FREE, FALSE);
11542 didset_options();
11543 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011544
11545 if (fname != NULL)
11546 {
11547 p = vim_getenv(envname, &dofree);
11548 if (p == NULL)
11549 {
11550 /* Set $MYVIMRC to the first vimrc file found. */
11551 p = FullName_save(fname, FALSE);
11552 if (p != NULL)
11553 {
11554 vim_setenv(envname, p);
11555 vim_free(p);
11556 }
11557 }
11558 else if (dofree)
11559 vim_free(p);
11560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561}
11562
11563/*
11564 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11565 */
11566 void
11567change_compatible(on)
11568 int on;
11569{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011570 int opt_idx;
11571
Bram Moolenaar071d4272004-06-13 20:20:40 +000011572 if (p_cp != on)
11573 {
11574 p_cp = on;
11575 compatible_set();
11576 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011577 opt_idx = findoption((char_u *)"cp");
11578 if (opt_idx >= 0)
11579 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580}
11581
11582/*
11583 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011584 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011585 */
11586 int
11587option_was_set(name)
11588 char_u *name;
11589{
11590 int idx;
11591
11592 idx = findoption(name);
11593 if (idx < 0) /* unknown option */
11594 return FALSE;
11595 if (options[idx].flags & P_WAS_SET)
11596 return TRUE;
11597 return FALSE;
11598}
11599
11600/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011601 * Reset the flag indicating option "name" was set.
11602 */
11603 void
11604reset_option_was_set(name)
11605 char_u *name;
11606{
11607 int idx = findoption(name);
11608
11609 if (idx >= 0)
11610 options[idx].flags &= ~P_WAS_SET;
11611}
11612
11613/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614 * compatible_set() - Called when 'compatible' has been set or unset.
11615 *
11616 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11617 * flag) to a Vi compatible value.
11618 * When 'compatible' is unset: Set all options that have a different default
11619 * for Vim (without the P_VI_DEF flag) to that default.
11620 */
11621 static void
11622compatible_set()
11623{
11624 int opt_idx;
11625
11626 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11627 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11628 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11629 set_option_default(opt_idx, OPT_FREE, p_cp);
11630 didset_options();
11631}
11632
11633#ifdef FEAT_LINEBREAK
11634
11635# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11636 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011637 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011638# endif
11639
11640/*
11641 * fill_breakat_flags() -- called when 'breakat' changes value.
11642 */
11643 static void
11644fill_breakat_flags()
11645{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011646 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011647 int i;
11648
11649 for (i = 0; i < 256; i++)
11650 breakat_flags[i] = FALSE;
11651
11652 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011653 for (p = p_breakat; *p; p++)
11654 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011655}
11656
11657# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011658 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011659# endif
11660
11661#endif
11662
11663/*
11664 * Check an option that can be a range of string values.
11665 *
11666 * Return OK for correct value, FAIL otherwise.
11667 * Empty is always OK.
11668 */
11669 static int
11670check_opt_strings(val, values, list)
11671 char_u *val;
11672 char **values;
11673 int list; /* when TRUE: accept a list of values */
11674{
11675 return opt_strings_flags(val, values, NULL, list);
11676}
11677
11678/*
11679 * Handle an option that can be a range of string values.
11680 * Set a flag in "*flagp" for each string present.
11681 *
11682 * Return OK for correct value, FAIL otherwise.
11683 * Empty is always OK.
11684 */
11685 static int
11686opt_strings_flags(val, values, flagp, list)
11687 char_u *val; /* new value */
11688 char **values; /* array of valid string values */
11689 unsigned *flagp;
11690 int list; /* when TRUE: accept a list of values */
11691{
11692 int i;
11693 int len;
11694 unsigned new_flags = 0;
11695
11696 while (*val)
11697 {
11698 for (i = 0; ; ++i)
11699 {
11700 if (values[i] == NULL) /* val not found in values[] */
11701 return FAIL;
11702
11703 len = (int)STRLEN(values[i]);
11704 if (STRNCMP(values[i], val, len) == 0
11705 && ((list && val[len] == ',') || val[len] == NUL))
11706 {
11707 val += len + (val[len] == ',');
11708 new_flags |= (1 << i);
11709 break; /* check next item in val list */
11710 }
11711 }
11712 }
11713 if (flagp != NULL)
11714 *flagp = new_flags;
11715
11716 return OK;
11717}
11718
11719/*
11720 * Read the 'wildmode' option, fill wim_flags[].
11721 */
11722 static int
11723check_opt_wim()
11724{
11725 char_u new_wim_flags[4];
11726 char_u *p;
11727 int i;
11728 int idx = 0;
11729
11730 for (i = 0; i < 4; ++i)
11731 new_wim_flags[i] = 0;
11732
11733 for (p = p_wim; *p; ++p)
11734 {
11735 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11736 ;
11737 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11738 return FAIL;
11739 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11740 new_wim_flags[idx] |= WIM_LONGEST;
11741 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11742 new_wim_flags[idx] |= WIM_FULL;
11743 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11744 new_wim_flags[idx] |= WIM_LIST;
11745 else
11746 return FAIL;
11747 p += i;
11748 if (*p == NUL)
11749 break;
11750 if (*p == ',')
11751 {
11752 if (idx == 3)
11753 return FAIL;
11754 ++idx;
11755 }
11756 }
11757
11758 /* fill remaining entries with last flag */
11759 while (idx < 3)
11760 {
11761 new_wim_flags[idx + 1] = new_wim_flags[idx];
11762 ++idx;
11763 }
11764
11765 /* only when there are no errors, wim_flags[] is changed */
11766 for (i = 0; i < 4; ++i)
11767 wim_flags[i] = new_wim_flags[i];
11768 return OK;
11769}
11770
11771/*
11772 * Check if backspacing over something is allowed.
11773 */
11774 int
11775can_bs(what)
11776 int what; /* BS_INDENT, BS_EOL or BS_START */
11777{
11778 switch (*p_bs)
11779 {
11780 case '2': return TRUE;
11781 case '1': return (what != BS_START);
11782 case '0': return FALSE;
11783 }
11784 return vim_strchr(p_bs, what) != NULL;
11785}
11786
11787/*
11788 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11789 * the file must be considered changed when the value is different.
11790 */
11791 void
11792save_file_ff(buf)
11793 buf_T *buf;
11794{
11795 buf->b_start_ffc = *buf->b_p_ff;
11796 buf->b_start_eol = buf->b_p_eol;
11797#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011798 buf->b_start_bomb = buf->b_p_bomb;
11799
Bram Moolenaar071d4272004-06-13 20:20:40 +000011800 /* Only use free/alloc when necessary, they take time. */
11801 if (buf->b_start_fenc == NULL
11802 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11803 {
11804 vim_free(buf->b_start_fenc);
11805 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11806 }
11807#endif
11808}
11809
11810/*
11811 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11812 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011813 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11814 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011815 * When "ignore_empty" is true don't consider a new, empty buffer to be
11816 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817 */
11818 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011819file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011821 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011822{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011823 /* In a buffer that was never loaded the options are not valid. */
11824 if (buf->b_flags & BF_NEVERLOADED)
11825 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011826 if (ignore_empty
11827 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011828 && buf->b_ml.ml_line_count == 1
11829 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11830 return FALSE;
11831 if (buf->b_start_ffc != *buf->b_p_ff)
11832 return TRUE;
11833 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11834 return TRUE;
11835#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011836 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11837 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011838 if (buf->b_start_fenc == NULL)
11839 return (*buf->b_p_fenc != NUL);
11840 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11841#else
11842 return FALSE;
11843#endif
11844}
11845
11846/*
11847 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11848 */
11849 int
11850check_ff_value(p)
11851 char_u *p;
11852{
11853 return check_opt_strings(p, p_ff_values, FALSE);
11854}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011855
11856/*
11857 * Return the effective shiftwidth value for current buffer, using the
11858 * 'tabstop' value when 'shiftwidth' is zero.
11859 */
11860 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011861get_sw_value(buf)
11862 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011863{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011864 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011865}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011866
11867/*
11868 * Return the effective softtabstop value for the current buffer, using the
11869 * 'tabstop' value when 'softtabstop' is negative.
11870 */
11871 long
11872get_sts_value()
11873{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011874 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011875}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011876
11877/*
11878 * Check matchpairs option for "*initc".
11879 * If there is a match set "*initc" to the matching character and "*findc" to
11880 * the opposite character. Set "*backwards" to the direction.
11881 * When "switchit" is TRUE swap the direction.
11882 */
11883 void
11884find_mps_values(initc, findc, backwards, switchit)
11885 int *initc;
11886 int *findc;
11887 int *backwards;
11888 int switchit;
11889{
11890 char_u *ptr;
11891
11892 ptr = curbuf->b_p_mps;
11893 while (*ptr != NUL)
11894 {
11895#ifdef FEAT_MBYTE
11896 if (has_mbyte)
11897 {
11898 char_u *prev;
11899
11900 if (mb_ptr2char(ptr) == *initc)
11901 {
11902 if (switchit)
11903 {
11904 *findc = *initc;
11905 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11906 *backwards = TRUE;
11907 }
11908 else
11909 {
11910 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11911 *backwards = FALSE;
11912 }
11913 return;
11914 }
11915 prev = ptr;
11916 ptr += mb_ptr2len(ptr) + 1;
11917 if (mb_ptr2char(ptr) == *initc)
11918 {
11919 if (switchit)
11920 {
11921 *findc = *initc;
11922 *initc = mb_ptr2char(prev);
11923 *backwards = FALSE;
11924 }
11925 else
11926 {
11927 *findc = mb_ptr2char(prev);
11928 *backwards = TRUE;
11929 }
11930 return;
11931 }
11932 ptr += mb_ptr2len(ptr);
11933 }
11934 else
11935#endif
11936 {
11937 if (*ptr == *initc)
11938 {
11939 if (switchit)
11940 {
11941 *backwards = TRUE;
11942 *findc = *initc;
11943 *initc = ptr[2];
11944 }
11945 else
11946 {
11947 *backwards = FALSE;
11948 *findc = ptr[2];
11949 }
11950 return;
11951 }
11952 ptr += 2;
11953 if (*ptr == *initc)
11954 {
11955 if (switchit)
11956 {
11957 *backwards = FALSE;
11958 *findc = *initc;
11959 *initc = ptr[-2];
11960 }
11961 else
11962 {
11963 *backwards = TRUE;
11964 *findc = ptr[-2];
11965 }
11966 return;
11967 }
11968 ++ptr;
11969 }
11970 if (*ptr == ',')
11971 ++ptr;
11972 }
11973}