blob: cbaa763683a7781b771088820c836ffdda1a4917 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100137# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000138#endif
139#define PV_MA OPT_BUF(BV_MA)
140#define PV_ML OPT_BUF(BV_ML)
141#define PV_MOD OPT_BUF(BV_MOD)
142#define PV_MPS OPT_BUF(BV_MPS)
143#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000144#ifdef FEAT_COMPL_FUNC
145# define PV_OFU OPT_BUF(BV_OFU)
146#endif
147#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
148#define PV_PI OPT_BUF(BV_PI)
149#ifdef FEAT_TEXTOBJ
150# define PV_QE OPT_BUF(BV_QE)
151#endif
152#define PV_RO OPT_BUF(BV_RO)
153#ifdef FEAT_SMARTINDENT
154# define PV_SI OPT_BUF(BV_SI)
155#endif
156#ifndef SHORT_FNAME
157# define PV_SN OPT_BUF(BV_SN)
158#endif
159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
175#define PV_TS OPT_BUF(BV_TS)
176#define PV_TW OPT_BUF(BV_TW)
177#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200178#ifdef FEAT_PERSISTENT_UNDO
179# define PV_UDF OPT_BUF(BV_UDF)
180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000181#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000182
183/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184 * Definition of the PV_ values for window-local options.
185 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187#define PV_LIST OPT_WIN(WV_LIST)
188#ifdef FEAT_ARABIC
189# define PV_ARAB OPT_WIN(WV_ARAB)
190#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000191#ifdef FEAT_DIFF
192# define PV_DIFF OPT_WIN(WV_DIFF)
193#endif
194#ifdef FEAT_FOLDING
195# define PV_FDC OPT_WIN(WV_FDC)
196# define PV_FEN OPT_WIN(WV_FEN)
197# define PV_FDI OPT_WIN(WV_FDI)
198# define PV_FDL OPT_WIN(WV_FDL)
199# define PV_FDM OPT_WIN(WV_FDM)
200# define PV_FML OPT_WIN(WV_FML)
201# define PV_FDN OPT_WIN(WV_FDN)
202# ifdef FEAT_EVAL
203# define PV_FDE OPT_WIN(WV_FDE)
204# define PV_FDT OPT_WIN(WV_FDT)
205# endif
206# define PV_FMR OPT_WIN(WV_FMR)
207#endif
208#ifdef FEAT_LINEBREAK
209# define PV_LBR OPT_WIN(WV_LBR)
210#endif
211#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200212#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000213#ifdef FEAT_LINEBREAK
214# define PV_NUW OPT_WIN(WV_NUW)
215#endif
216#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
217# define PV_PVW OPT_WIN(WV_PVW)
218#endif
219#ifdef FEAT_RIGHTLEFT
220# define PV_RL OPT_WIN(WV_RL)
221# define PV_RLC OPT_WIN(WV_RLC)
222#endif
223#ifdef FEAT_SCROLLBIND
224# define PV_SCBIND OPT_WIN(WV_SCBIND)
225#endif
226#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000227#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000228# define PV_SPELL OPT_WIN(WV_SPELL)
229#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000230#ifdef FEAT_SYN_HL
231# define PV_CUC OPT_WIN(WV_CUC)
232# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200233# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000235#ifdef FEAT_STL_OPT
236# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
237#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100238#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000239#ifdef FEAT_WINDOWS
240# define PV_WFH OPT_WIN(WV_WFH)
241#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000242#ifdef FEAT_VERTSPLIT
243# define PV_WFW OPT_WIN(WV_WFW)
244#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200246#ifdef FEAT_CURSORBIND
247# define PV_CRBIND OPT_WIN(WV_CRBIND)
248#endif
249#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200250# define PV_COCU OPT_WIN(WV_COCU)
251# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200252#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000253
254/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255typedef enum
256{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000257 PV_NONE = 0,
258 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259} idopt_T;
260
261/*
262 * Options local to a window have a value local to a buffer and global to all
263 * buffers. Indicate this by setting "var" to VAR_WIN.
264 */
265#define VAR_WIN ((char_u *)-1)
266
267/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000268 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269 * Only to be used in option.c!
270 */
271static int p_ai;
272static int p_bin;
273#ifdef FEAT_MBYTE
274static int p_bomb;
275#endif
276#if defined(FEAT_QUICKFIX)
277static char_u *p_bh;
278static char_u *p_bt;
279#endif
280static int p_bl;
281static int p_ci;
282#ifdef FEAT_CINDENT
283static int p_cin;
284static char_u *p_cink;
285static char_u *p_cino;
286#endif
287#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
288static char_u *p_cinw;
289#endif
290#ifdef FEAT_COMMENTS
291static char_u *p_com;
292#endif
293#ifdef FEAT_FOLDING
294static char_u *p_cms;
295#endif
296#ifdef FEAT_INS_EXPAND
297static char_u *p_cpt;
298#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000299#ifdef FEAT_COMPL_FUNC
300static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000301static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303static int p_eol;
304static int p_et;
305#ifdef FEAT_MBYTE
306static char_u *p_fenc;
307#endif
308static char_u *p_ff;
309static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000310static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311#ifdef FEAT_AUTOCMD
312static char_u *p_ft;
313#endif
314static long p_iminsert;
315static long p_imsearch;
316#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
317static char_u *p_inex;
318#endif
319#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
320static char_u *p_inde;
321static char_u *p_indk;
322#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000323#if defined(FEAT_EVAL)
324static char_u *p_fex;
325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326static int p_inf;
327static char_u *p_isk;
328#ifdef FEAT_CRYPT
329static char_u *p_key;
330#endif
331#ifdef FEAT_LISP
332static int p_lisp;
333#endif
334static int p_ml;
335static int p_ma;
336static int p_mod;
337static char_u *p_mps;
338static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000340#ifdef FEAT_TEXTOBJ
341static char_u *p_qe;
342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_ro;
344#ifdef FEAT_SMARTINDENT
345static int p_si;
346#endif
347#ifndef SHORT_FNAME
348static int p_sn;
349#endif
350static long p_sts;
351#if defined(FEAT_SEARCHPATH)
352static char_u *p_sua;
353#endif
354static long p_sw;
355static int p_swf;
356#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000357static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000359#endif
360#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000361static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000362static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000363static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364#endif
365static long p_ts;
366static long p_tw;
367static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200368#ifdef FEAT_PERSISTENT_UNDO
369static int p_udf;
370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000371static long p_wm;
372#ifdef FEAT_KEYMAP
373static char_u *p_keymap;
374#endif
375
376/* Saved values for when 'bin' is set. */
377static int p_et_nobin;
378static int p_ml_nobin;
379static long p_tw_nobin;
380static long p_wm_nobin;
381
382/* Saved values for when 'paste' is set */
383static long p_tw_nopaste;
384static long p_wm_nopaste;
385static long p_sts_nopaste;
386static int p_ai_nopaste;
387
388struct vimoption
389{
390 char *fullname; /* full option name */
391 char *shortname; /* permissible abbreviation */
392 long_u flags; /* see below */
393 char_u *var; /* global option: pointer to variable;
394 * window-local option: VAR_WIN;
395 * buffer-local option: global value */
396 idopt_T indir; /* global option: PV_NONE;
397 * local option: indirect option index */
398 char_u *def_val[2]; /* default values for variable (vi and vim) */
399#ifdef FEAT_EVAL
400 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000401# define SCRIPTID_INIT , 0
402#else
403# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404#endif
405};
406
407#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
408#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
409
410/*
411 * Flags
412 */
413#define P_BOOL 0x01 /* the option is boolean */
414#define P_NUM 0x02 /* the option is numeric */
415#define P_STRING 0x04 /* the option is a string */
416#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000417 must use free_string_option() when
418 assigning new value. Not set if default is
419 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
421 never be used for local or hidden options! */
422#define P_NODEFAULT 0x40 /* don't set to default value */
423#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
424 use vim_free() when assigning new value */
425#define P_WAS_SET 0x100 /* option has been set/reset */
426#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
427#define P_VI_DEF 0x400 /* Use Vi default for Vim */
428#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
429
430 /* when option changed, what to display: */
431#define P_RSTAT 0x1000 /* redraw status lines */
432#define P_RWIN 0x2000 /* redraw current window */
433#define P_RBUF 0x4000 /* redraw current buffer */
434#define P_RALL 0x6000 /* redraw all windows */
435#define P_RCLR 0x7000 /* clear and redraw all */
436
437#define P_COMMA 0x8000 /* comma separated list */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200438#define P_NODUP 0x10000L /* don't allow duplicate strings */
439#define P_FLAGLIST 0x20000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440
Bram Moolenaar913077c2012-03-28 19:59:04 +0200441#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */
442#define P_GETTEXT 0x80000L /* expand default value with _() */
443#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */
444#define P_NFNAME 0x200000L /* only normal file name chars allowed */
445#define P_INSECURE 0x400000L /* option was set from a modeline */
446#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000447 side effects) */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200448#define P_NO_ML 0x1000000L /* not allowed in modeline */
449#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
450 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000452#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
453
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000454/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
455 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000456#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000457# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000458#else
459# define ISP_LATIN1 (char_u *)"@,161-255"
460#endif
461
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000462/* The 16 bit MS-DOS version is low on space, make the string as short as
463 * possible when compiling with few features. */
464#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
465 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200466 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100467# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000468#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100469# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000470#endif
471
Bram Moolenaar071d4272004-06-13 20:20:40 +0000472/*
473 * options[] is initialized here.
474 * The order of the options MUST be alphabetic for ":set all" and findoption().
475 * All option names MUST start with a lowercase letter (for findoption()).
476 * Exception: "t_" options are at the end.
477 * The options with a NULL variable are 'hidden': a set command for them is
478 * ignored and they are not printed.
479 */
480static struct vimoption
481#ifdef FEAT_GUI_W16
482 _far
483#endif
484 options[] =
485{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200486 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000487#ifdef FEAT_RIGHTLEFT
488 (char_u *)&p_aleph, PV_NONE,
489#else
490 (char_u *)NULL, PV_NONE,
491#endif
492 {
493#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
494 (char_u *)128L,
495#else
496 (char_u *)224L,
497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000498 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
500#if defined(FEAT_GUI) && defined(MACOS_X)
501 (char_u *)&p_antialias, PV_NONE,
502 {(char_u *)FALSE, (char_u *)FALSE}
503#else
504 (char_u *)NULL, PV_NONE,
505 {(char_u *)FALSE, (char_u *)FALSE}
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200508 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509#ifdef FEAT_ARABIC
510 (char_u *)VAR_WIN, PV_ARAB,
511#else
512 (char_u *)NULL, PV_NONE,
513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
516#ifdef FEAT_ARABIC
517 (char_u *)&p_arshape, PV_NONE,
518#else
519 (char_u *)NULL, PV_NONE,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
523#ifdef FEAT_RIGHTLEFT
524 (char_u *)&p_ari, PV_NONE,
525#else
526 (char_u *)NULL, PV_NONE,
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
530#ifdef FEAT_FKMAP
531 (char_u *)&p_altkeymap, PV_NONE,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
537#if defined(FEAT_MBYTE)
538 (char_u *)&p_ambw, PV_NONE,
539 {(char_u *)"single", (char_u *)0L}
540#else
541 (char_u *)NULL, PV_NONE,
542 {(char_u *)0L, (char_u *)0L}
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000545#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"autochdir", "acd", P_BOOL|P_VI_DEF,
547 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549#endif
550 {"autoindent", "ai", P_BOOL|P_VI_DEF,
551 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autoprint", "ap", P_BOOL|P_VI_DEF,
554 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000557 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autowrite", "aw", P_BOOL|P_VI_DEF,
560 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autowriteall","awa", P_BOOL|P_VI_DEF,
563 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
566 (char_u *)&p_bg, PV_NONE,
567 {
568#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
569 (char_u *)"dark",
570#else
571 (char_u *)"light",
572#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
575 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
578 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
581 (char_u *)&p_bkc, PV_NONE,
582#ifdef UNIX
583 {(char_u *)"yes", (char_u *)"auto"}
584#else
585 {(char_u *)"auto", (char_u *)"auto"}
586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
589 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000591 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bex, PV_NONE,
593 {
594#ifdef VMS
595 (char_u *)"_",
596#else
597 (char_u *)"~",
598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000599 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
601#ifdef FEAT_WILDIGN
602 (char_u *)&p_bsk, PV_NONE,
603 {(char_u *)"", (char_u *)0L}
604#else
605 (char_u *)NULL, PV_NONE,
606 {(char_u *)0L, (char_u *)0L}
607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609#ifdef FEAT_BEVAL
610 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
611 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
614 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000616# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000617 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000618 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000620# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621#endif
622 {"beautify", "bf", P_BOOL|P_VI_DEF,
623 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
626 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
629#ifdef MSDOS
630 (char_u *)&p_biosk, PV_NONE,
631#else
632 (char_u *)NULL, PV_NONE,
633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
636#ifdef FEAT_MBYTE
637 (char_u *)&p_bomb, PV_BOMB,
638#else
639 (char_u *)NULL, PV_NONE,
640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
643#ifdef FEAT_LINEBREAK
644 (char_u *)&p_breakat, PV_NONE,
645 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
646#else
647 (char_u *)NULL, PV_NONE,
648 {(char_u *)0L, (char_u *)0L}
649#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000650 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
652#ifdef FEAT_BROWSE
653 (char_u *)&p_bsdir, PV_NONE,
654 {(char_u *)"last", (char_u *)0L}
655#else
656 (char_u *)NULL, PV_NONE,
657 {(char_u *)0L, (char_u *)0L}
658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000659 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
661#if defined(FEAT_QUICKFIX)
662 (char_u *)&p_bh, PV_BH,
663 {(char_u *)"", (char_u *)0L}
664#else
665 (char_u *)NULL, PV_NONE,
666 {(char_u *)0L, (char_u *)0L}
667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000668 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
670 (char_u *)&p_bl, PV_BL,
671 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
674#if defined(FEAT_QUICKFIX)
675 (char_u *)&p_bt, PV_BT,
676 {(char_u *)"", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000683#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 (char_u *)&p_cmp, PV_NONE,
685 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
692#ifdef FEAT_SEARCHPATH
693 (char_u *)&p_cdpath, PV_NONE,
694 {(char_u *)",,", (char_u *)0L}
695#else
696 (char_u *)NULL, PV_NONE,
697 {(char_u *)0L, (char_u *)0L}
698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000699 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000700 {"cedit", NULL, P_STRING,
701#ifdef FEAT_CMDWIN
702 (char_u *)&p_cedit, PV_NONE,
703 {(char_u *)"", (char_u *)CTRL_F_STR}
704#else
705 (char_u *)NULL, PV_NONE,
706 {(char_u *)0L, (char_u *)0L}
707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
710#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
711 (char_u *)&p_ccv, PV_NONE,
712 {(char_u *)"", (char_u *)0L}
713#else
714 (char_u *)NULL, PV_NONE,
715 {(char_u *)0L, (char_u *)0L}
716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
719#ifdef FEAT_CINDENT
720 (char_u *)&p_cin, PV_CIN,
721#else
722 (char_u *)NULL, PV_NONE,
723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
726#ifdef FEAT_CINDENT
727 (char_u *)&p_cink, PV_CINK,
728 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
729#else
730 (char_u *)NULL, PV_NONE,
731 {(char_u *)0L, (char_u *)0L}
732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000733 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
735#ifdef FEAT_CINDENT
736 (char_u *)&p_cino, PV_CINO,
737#else
738 (char_u *)NULL, PV_NONE,
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
742#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
743 (char_u *)&p_cinw, PV_CINW,
744 {(char_u *)"if,else,while,do,for,switch",
745 (char_u *)0L}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
752#ifdef FEAT_CLIPBOARD
753 (char_u *)&p_cb, PV_NONE,
754# ifdef FEAT_XCLIPBOARD
755 {(char_u *)"autoselect,exclude:cons\\|linux",
756 (char_u *)0L}
757# else
758 {(char_u *)"", (char_u *)0L}
759# endif
760#else
761 (char_u *)NULL, PV_NONE,
762 {(char_u *)"", (char_u *)0L}
763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000764 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
766 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
769#ifdef FEAT_CMDWIN
770 (char_u *)&p_cwh, PV_NONE,
771#else
772 (char_u *)NULL, PV_NONE,
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200775 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
776#ifdef FEAT_SYN_HL
777 (char_u *)VAR_WIN, PV_CC,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
781 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
783 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200785 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_COMMENTS
787 (char_u *)&p_com, PV_COM,
788 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
789 (char_u *)0L}
790#else
791 (char_u *)NULL, PV_NONE,
792 {(char_u *)0L, (char_u *)0L}
793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000794 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200795 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796#ifdef FEAT_FOLDING
797 (char_u *)&p_cms, PV_CMS,
798 {(char_u *)"/*%s*/", (char_u *)0L}
799#else
800 (char_u *)NULL, PV_NONE,
801 {(char_u *)0L, (char_u *)0L}
802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000804 /* P_PRI_MKRC isn't needed here, optval_default()
805 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806 {"compatible", "cp", P_BOOL|P_RALL,
807 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
810#ifdef FEAT_INS_EXPAND
811 (char_u *)&p_cpt, PV_CPT,
812 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
813#else
814 (char_u *)NULL, PV_NONE,
815 {(char_u *)0L, (char_u *)0L}
816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200818 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200819#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200820 (char_u *)VAR_WIN, PV_COCU,
821 {(char_u *)"", (char_u *)NULL}
822#else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)NULL, (char_u *)0L}
825#endif
826 SCRIPTID_INIT},
827 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
828#ifdef FEAT_CONCEAL
829 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200830#else
831 (char_u *)NULL, PV_NONE,
832#endif
833 {(char_u *)0L, (char_u *)0L}
834 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000835 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
836#ifdef FEAT_COMPL_FUNC
837 (char_u *)&p_cfu, PV_CFU,
838 {(char_u *)"", (char_u *)0L}
839#else
840 (char_u *)NULL, PV_NONE,
841 {(char_u *)0L, (char_u *)0L}
842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000843 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000844 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
845#ifdef FEAT_INS_EXPAND
846 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000847 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853 {"confirm", "cf", P_BOOL|P_VI_DEF,
854#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
855 (char_u *)&p_confirm, PV_NONE,
856#else
857 (char_u *)NULL, PV_NONE,
858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000860 {"conskey", "consk",P_BOOL|P_VI_DEF,
861#ifdef MSDOS
862 (char_u *)&p_consk, PV_NONE,
863#else
864 (char_u *)NULL, PV_NONE,
865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000867 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
868 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000870 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
871 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000872 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
873 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200874 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200875#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200876 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200877 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200878#else
879 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200880 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200881#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200882 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
884#ifdef FEAT_CSCOPE
885 (char_u *)&p_cspc, PV_NONE,
886#else
887 (char_u *)NULL, PV_NONE,
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
891#ifdef FEAT_CSCOPE
892 (char_u *)&p_csprg, PV_NONE,
893 {(char_u *)"cscope", (char_u *)0L}
894#else
895 (char_u *)NULL, PV_NONE,
896 {(char_u *)0L, (char_u *)0L}
897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
900#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
901 (char_u *)&p_csqf, PV_NONE,
902 {(char_u *)"", (char_u *)0L}
903#else
904 (char_u *)NULL, PV_NONE,
905 {(char_u *)0L, (char_u *)0L}
906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200908 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
909#ifdef FEAT_CSCOPE
910 (char_u *)&p_csre, PV_NONE,
911#else
912 (char_u *)NULL, PV_NONE,
913#endif
914 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
916#ifdef FEAT_CSCOPE
917 (char_u *)&p_cst, PV_NONE,
918#else
919 (char_u *)NULL, PV_NONE,
920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000921 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
923#ifdef FEAT_CSCOPE
924 (char_u *)&p_csto, PV_NONE,
925#else
926 (char_u *)NULL, PV_NONE,
927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000928 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
930#ifdef FEAT_CSCOPE
931 (char_u *)&p_csverbose, PV_NONE,
932#else
933 (char_u *)NULL, PV_NONE,
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200936 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
937#ifdef FEAT_CURSORBIND
938 (char_u *)VAR_WIN, PV_CRBIND,
939#else
940 (char_u *)NULL, PV_NONE,
941#endif
942 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000943 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
944#ifdef FEAT_SYN_HL
945 (char_u *)VAR_WIN, PV_CUC,
946#else
947 (char_u *)NULL, PV_NONE,
948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000949 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000950 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
951#ifdef FEAT_SYN_HL
952 (char_u *)VAR_WIN, PV_CUL,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000956 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"debug", NULL, P_STRING|P_VI_DEF,
958 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000959 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200960 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000961#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000962 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000963 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964#else
965 (char_u *)NULL, PV_NONE,
966 {(char_u *)NULL, (char_u *)0L}
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
970#ifdef FEAT_MBYTE
971 (char_u *)&p_deco, PV_NONE,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
977#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000978 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
984#ifdef FEAT_DIFF
985 (char_u *)VAR_WIN, PV_DIFF,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200990 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
992 (char_u *)&p_dex, PV_NONE,
993 {(char_u *)"", (char_u *)0L}
994#else
995 (char_u *)NULL, PV_NONE,
996 {(char_u *)0L, (char_u *)0L}
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
1000#ifdef FEAT_DIFF
1001 (char_u *)&p_dip, PV_NONE,
1002 {(char_u *)"filler", (char_u *)NULL}
1003#else
1004 (char_u *)NULL, PV_NONE,
1005 {(char_u *)"", (char_u *)NULL}
1006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1009#ifdef FEAT_DIGRAPHS
1010 (char_u *)&p_dg, PV_NONE,
1011#else
1012 (char_u *)NULL, PV_NONE,
1013#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1016 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1019 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021 {"eadirection", "ead", P_STRING|P_VI_DEF,
1022#ifdef FEAT_VERTSPLIT
1023 (char_u *)&p_ead, PV_NONE,
1024 {(char_u *)"both", (char_u *)0L}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)NULL, (char_u *)0L}
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1031 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001033 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034#ifdef FEAT_MBYTE
1035 (char_u *)&p_enc, PV_NONE,
1036 {(char_u *)ENC_DFLT, (char_u *)0L}
1037#else
1038 (char_u *)NULL, PV_NONE,
1039 {(char_u *)0L, (char_u *)0L}
1040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1043 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1046 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001049 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1052 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1055#ifdef FEAT_QUICKFIX
1056 (char_u *)&p_ef, PV_NONE,
1057 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)NULL, (char_u *)0L}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1064#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001065 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067#else
1068 (char_u *)NULL, PV_NONE,
1069 {(char_u *)NULL, (char_u *)0L}
1070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"esckeys", "ek", P_BOOL|P_VIM,
1073 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1076#ifdef FEAT_AUTOCMD
1077 (char_u *)&p_ei, PV_NONE,
1078#else
1079 (char_u *)NULL, PV_NONE,
1080#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1083 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1086 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1089#ifdef FEAT_MBYTE
1090 (char_u *)&p_fenc, PV_FENC,
1091 {(char_u *)"", (char_u *)0L}
1092#else
1093 (char_u *)NULL, PV_NONE,
1094 {(char_u *)0L, (char_u *)0L}
1095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1098#ifdef FEAT_MBYTE
1099 (char_u *)&p_fencs, PV_NONE,
1100 {(char_u *)"ucs-bom", (char_u *)0L}
1101#else
1102 (char_u *)NULL, PV_NONE,
1103 {(char_u *)0L, (char_u *)0L}
1104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001106 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1110 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1112 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001113 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1114 (char_u *)&p_fic, PV_NONE,
1115 {
1116#ifdef CASE_INSENSITIVE_FILENAME
1117 (char_u *)TRUE,
1118#else
1119 (char_u *)FALSE,
1120#endif
1121 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001122 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_AUTOCMD
1124 (char_u *)&p_ft, PV_FT,
1125 {(char_u *)"", (char_u *)0L}
1126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)0L, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1132#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1133 (char_u *)&p_fcs, PV_NONE,
1134 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1135#else
1136 (char_u *)NULL, PV_NONE,
1137 {(char_u *)"", (char_u *)0L}
1138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1141#ifdef FEAT_FKMAP
1142 (char_u *)&p_fkmap, PV_NONE,
1143#else
1144 (char_u *)NULL, PV_NONE,
1145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"flash", "fl", P_BOOL|P_VI_DEF,
1148 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150#ifdef FEAT_FOLDING
1151 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1152 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1155 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1158 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001159 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1161# ifdef FEAT_EVAL
1162 (char_u *)VAR_WIN, PV_FDE,
1163 {(char_u *)"0", (char_u *)NULL}
1164# else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)NULL, (char_u *)0L}
1167# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1170 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1173 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001174 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001175 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001177 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1179 P_RWIN|P_COMMA|P_NODUP,
1180 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)"{{{,}}}", (char_u *)NULL}
1182 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1184 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1187 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1190 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001192 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193 (char_u *)&p_fdo, PV_NONE,
1194 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001195 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1197# ifdef FEAT_EVAL
1198 (char_u *)VAR_WIN, PV_FDT,
1199 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001200# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)NULL, PV_NONE,
1202 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001203# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001205#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001206 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001207#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001208 (char_u *)&p_fex, PV_FEX,
1209 {(char_u *)"", (char_u *)0L}
1210#else
1211 (char_u *)NULL, PV_NONE,
1212 {(char_u *)0L, (char_u *)0L}
1213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1216 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1218 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001219 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1220 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1222 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1224 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001225 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001226 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1227#ifdef HAVE_FSYNC
1228 (char_u *)&p_fs, PV_NONE,
1229 {(char_u *)TRUE, (char_u *)0L}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)FALSE, (char_u *)0L}
1233#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001234 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1236 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"graphic", "gr", P_BOOL|P_VI_DEF,
1239 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001240 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1242#ifdef FEAT_QUICKFIX
1243 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)NULL, (char_u *)0L}
1248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1251#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001252 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253 {
1254# ifdef WIN3264
1255 /* may be changed to "grep -n" in os_win32.c */
1256 (char_u *)"findstr /n",
1257# else
1258# ifdef UNIX
1259 /* Add an extra file name so that grep will always
1260 * insert a file name in the match line. */
1261 (char_u *)"grep -n $* /dev/null",
1262# else
1263# ifdef VMS
1264 (char_u *)"SEARCH/NUMBERS ",
1265# else
1266 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267# endif
1268# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001269# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001270 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)NULL, (char_u *)0L}
1274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1277#ifdef CURSOR_SHAPE
1278 (char_u *)&p_guicursor, PV_NONE,
1279 {
1280# ifdef FEAT_GUI
1281 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
1282# else /* MSDOS or Win32 console */
1283 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1284# endif
1285 (char_u *)0L}
1286#else
1287 (char_u *)NULL, PV_NONE,
1288 {(char_u *)NULL, (char_u *)0L}
1289#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001290 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1292#ifdef FEAT_GUI
1293 (char_u *)&p_guifont, PV_NONE,
1294 {(char_u *)"", (char_u *)0L}
1295#else
1296 (char_u *)NULL, PV_NONE,
1297 {(char_u *)NULL, (char_u *)0L}
1298#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001299 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1301#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1302 (char_u *)&p_guifontset, PV_NONE,
1303 {(char_u *)"", (char_u *)0L}
1304#else
1305 (char_u *)NULL, PV_NONE,
1306 {(char_u *)NULL, (char_u *)0L}
1307#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1310#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1311 (char_u *)&p_guifontwide, PV_NONE,
1312 {(char_u *)"", (char_u *)0L}
1313#else
1314 (char_u *)NULL, PV_NONE,
1315 {(char_u *)NULL, (char_u *)0L}
1316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001317 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001319#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 (char_u *)&p_ghr, PV_NONE,
1321#else
1322 (char_u *)NULL, PV_NONE,
1323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001324 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001326#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327 (char_u *)&p_go, PV_NONE,
1328# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001329 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001331 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332# endif
1333#else
1334 (char_u *)NULL, PV_NONE,
1335 {(char_u *)NULL, (char_u *)0L}
1336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001337 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 {"guipty", NULL, P_BOOL|P_VI_DEF,
1339#if defined(FEAT_GUI)
1340 (char_u *)&p_guipty, PV_NONE,
1341#else
1342 (char_u *)NULL, PV_NONE,
1343#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001345 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001346#if defined(FEAT_GUI_TABLINE)
1347 (char_u *)&p_gtl, PV_NONE,
1348 {(char_u *)"", (char_u *)0L}
1349#else
1350 (char_u *)NULL, PV_NONE,
1351 {(char_u *)NULL, (char_u *)0L}
1352#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001353 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001354 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001355#if defined(FEAT_GUI_TABLINE)
1356 (char_u *)&p_gtt, PV_NONE,
1357 {(char_u *)"", (char_u *)0L}
1358#else
1359 (char_u *)NULL, PV_NONE,
1360 {(char_u *)NULL, (char_u *)0L}
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1364 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001365 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1367 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001368 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1369 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370 {"helpheight", "hh", P_NUM|P_VI_DEF,
1371#ifdef FEAT_WINDOWS
1372 (char_u *)&p_hh, PV_NONE,
1373#else
1374 (char_u *)NULL, PV_NONE,
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1378#ifdef FEAT_MULTI_LANG
1379 (char_u *)&p_hlg, PV_NONE,
1380 {(char_u *)"", (char_u *)0L}
1381#else
1382 (char_u *)NULL, PV_NONE,
1383 {(char_u *)0L, (char_u *)0L}
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {"hidden", "hid", P_BOOL|P_VI_DEF,
1387 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1390 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 {"history", "hi", P_NUM|P_VIM,
1394 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001395 {(char_u *)0L, (char_u *)20L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1397#ifdef FEAT_RIGHTLEFT
1398 (char_u *)&p_hkmap, PV_NONE,
1399#else
1400 (char_u *)NULL, PV_NONE,
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1404#ifdef FEAT_RIGHTLEFT
1405 (char_u *)&p_hkmapp, PV_NONE,
1406#else
1407 (char_u *)NULL, PV_NONE,
1408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1411 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001412 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413 {"icon", NULL, P_BOOL|P_VI_DEF,
1414#ifdef FEAT_TITLE
1415 (char_u *)&p_icon, PV_NONE,
1416#else
1417 (char_u *)NULL, PV_NONE,
1418#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001419 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420 {"iconstring", NULL, P_STRING|P_VI_DEF,
1421#ifdef FEAT_TITLE
1422 (char_u *)&p_iconstring, PV_NONE,
1423#else
1424 (char_u *)NULL, PV_NONE,
1425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1428 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001430 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1431# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1432 (char_u *)&p_imaf, PV_NONE,
1433 {(char_u *)"", (char_u *)NULL}
1434# else
1435 (char_u *)NULL, PV_NONE,
1436 {(char_u *)NULL, (char_u *)0L}
1437# endif
1438 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001439 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001440#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441 (char_u *)&p_imak, PV_NONE,
1442#else
1443 (char_u *)NULL, PV_NONE,
1444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001445 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1447#ifdef USE_IM_CONTROL
1448 (char_u *)&p_imcmdline, PV_NONE,
1449#else
1450 (char_u *)NULL, PV_NONE,
1451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1454#ifdef USE_IM_CONTROL
1455 (char_u *)&p_imdisable, PV_NONE,
1456#else
1457 (char_u *)NULL, PV_NONE,
1458#endif
1459#ifdef __sgi
1460 {(char_u *)TRUE, (char_u *)0L}
1461#else
1462 {(char_u *)FALSE, (char_u *)0L}
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"iminsert", "imi", P_NUM|P_VI_DEF,
1466 (char_u *)&p_iminsert, PV_IMI,
1467#ifdef B_IMODE_IM
1468 {(char_u *)B_IMODE_IM, (char_u *)0L}
1469#else
1470 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001472 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {"imsearch", "ims", P_NUM|P_VI_DEF,
1474 (char_u *)&p_imsearch, PV_IMS,
1475#ifdef B_IMODE_IM
1476 {(char_u *)B_IMODE_IM, (char_u *)0L}
1477#else
1478 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001481 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001482# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1483 (char_u *)&p_imsf, PV_NONE,
1484 {(char_u *)"", (char_u *)NULL}
1485# else
1486 (char_u *)NULL, PV_NONE,
1487 {(char_u *)NULL, (char_u *)0L}
1488# endif
1489 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1491#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001492 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1494#else
1495 (char_u *)NULL, PV_NONE,
1496 {(char_u *)0L, (char_u *)0L}
1497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1500#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1501 (char_u *)&p_inex, PV_INEX,
1502 {(char_u *)"", (char_u *)0L}
1503#else
1504 (char_u *)NULL, PV_NONE,
1505 {(char_u *)0L, (char_u *)0L}
1506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001507 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1509 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001510 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1512#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1513 (char_u *)&p_inde, PV_INDE,
1514 {(char_u *)"", (char_u *)0L}
1515#else
1516 (char_u *)NULL, PV_NONE,
1517 {(char_u *)0L, (char_u *)0L}
1518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1521#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1522 (char_u *)&p_indk, PV_INDK,
1523 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1524#else
1525 (char_u *)NULL, PV_NONE,
1526 {(char_u *)0L, (char_u *)0L}
1527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001528 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"infercase", "inf", P_BOOL|P_VI_DEF,
1530 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1533 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001535 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1536 (char_u *)&p_isf, PV_NONE,
1537 {
1538#ifdef BACKSLASH_IN_FILENAME
1539 /* Excluded are: & and ^ are special in cmd.exe
1540 * ( and ) are used in text separating fnames */
1541 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1542#else
1543# ifdef AMIGA
1544 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1545# else
1546# ifdef VMS
1547 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1548# else /* UNIX et al. */
1549# ifdef EBCDIC
1550 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1551# else
1552 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1553# endif
1554# endif
1555# endif
1556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1559 (char_u *)&p_isi, PV_NONE,
1560 {
1561#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1562 (char_u *)"@,48-57,_,128-167,224-235",
1563#else
1564# ifdef EBCDIC
1565 /* TODO: EBCDIC Check this! @ == isalpha()*/
1566 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1567 "112-120,128,140-142,156,158,172,"
1568 "174,186,191,203-207,219-225,235-239,"
1569 "251-254",
1570# else
1571 (char_u *)"@,48-57,_,192-255",
1572# endif
1573#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001574 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1576 (char_u *)&p_isk, PV_ISK,
1577 {
1578#ifdef EBCDIC
1579 (char_u *)"@,240-249,_",
1580 /* TODO: EBCDIC Check this! @ == isalpha()*/
1581 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1582 "112-120,128,140-142,156,158,172,"
1583 "174,186,191,203-207,219-225,235-239,"
1584 "251-254",
1585#else
1586 (char_u *)"@,48-57,_",
1587# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1588 (char_u *)"@,48-57,_,128-167,224-235"
1589# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001590 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001591# endif
1592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001593 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001594 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1595 (char_u *)&p_isp, PV_NONE,
1596 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001597#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1598 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 || defined(VMS)
1600 (char_u *)"@,~-255",
1601#else
1602# ifdef EBCDIC
1603 /* all chars above 63 are printable */
1604 (char_u *)"63-255",
1605# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001606 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607# endif
1608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001609 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001610 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1611 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001612 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1614#ifdef FEAT_CRYPT
1615 (char_u *)&p_key, PV_KEY,
1616 {(char_u *)"", (char_u *)0L}
1617#else
1618 (char_u *)NULL, PV_NONE,
1619 {(char_u *)0L, (char_u *)0L}
1620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001621 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001622 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623#ifdef FEAT_KEYMAP
1624 (char_u *)&p_keymap, PV_KMAP,
1625 {(char_u *)"", (char_u *)0L}
1626#else
1627 (char_u *)NULL, PV_NONE,
1628 {(char_u *)"", (char_u *)0L}
1629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001630 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001633 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001634 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001635 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 {
1637#if defined(MSDOS) || defined(MSWIN)
1638 (char_u *)":help",
1639#else
1640#ifdef VMS
1641 (char_u *)"help",
1642#else
1643# if defined(OS2)
1644 (char_u *)"view /",
1645# else
1646# ifdef USEMAN_S
1647 (char_u *)"man -s",
1648# else
1649 (char_u *)"man",
1650# endif
1651# endif
1652#endif
1653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001654 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1656#ifdef FEAT_LANGMAP
1657 (char_u *)&p_langmap, PV_NONE,
1658 {(char_u *)"", /* unmatched } */
1659#else
1660 (char_u *)NULL, PV_NONE,
1661 {(char_u *)NULL,
1662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001663 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001664 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1666 (char_u *)&p_lm, PV_NONE,
1667#else
1668 (char_u *)NULL, PV_NONE,
1669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1672#ifdef FEAT_WINDOWS
1673 (char_u *)&p_ls, PV_NONE,
1674#else
1675 (char_u *)NULL, PV_NONE,
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1679 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001680 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001681 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1682#ifdef FEAT_LINEBREAK
1683 (char_u *)VAR_WIN, PV_LBR,
1684#else
1685 (char_u *)NULL, PV_NONE,
1686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001687 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1689 (char_u *)&Rows, PV_NONE,
1690 {
1691#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1692 (char_u *)25L,
1693#else
1694 (char_u *)24L,
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1698#ifdef FEAT_GUI
1699 (char_u *)&p_linespace, PV_NONE,
1700#else
1701 (char_u *)NULL, PV_NONE,
1702#endif
1703#ifdef FEAT_GUI_W32
1704 {(char_u *)1L, (char_u *)0L}
1705#else
1706 {(char_u *)0L, (char_u *)0L}
1707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709 {"lisp", NULL, P_BOOL|P_VI_DEF,
1710#ifdef FEAT_LISP
1711 (char_u *)&p_lisp, PV_LISP,
1712#else
1713 (char_u *)NULL, PV_NONE,
1714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1717#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001718 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1720#else
1721 (char_u *)NULL, PV_NONE,
1722 {(char_u *)"", (char_u *)0L}
1723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1726 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001727 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001728 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1729 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1732 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001733 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001734#ifdef FEAT_GUI_MAC
1735 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1736 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"magic", NULL, P_BOOL|P_VI_DEF,
1740 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001742 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743#ifdef FEAT_QUICKFIX
1744 (char_u *)&p_mef, PV_NONE,
1745 {(char_u *)"", (char_u *)0L}
1746#else
1747 (char_u *)NULL, PV_NONE,
1748 {(char_u *)NULL, (char_u *)0L}
1749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1752#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001753 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754# ifdef VMS
1755 {(char_u *)"MMS", (char_u *)0L}
1756# else
1757 {(char_u *)"make", (char_u *)0L}
1758# endif
1759#else
1760 (char_u *)NULL, PV_NONE,
1761 {(char_u *)NULL, (char_u *)0L}
1762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1765 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001766 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"matchtime", "mat", P_NUM|P_VI_DEF,
1769 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001771 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001772#ifdef FEAT_MBYTE
1773 (char_u *)&p_mco, PV_NONE,
1774#else
1775 (char_u *)NULL, PV_NONE,
1776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1779#ifdef FEAT_EVAL
1780 (char_u *)&p_mfd, PV_NONE,
1781#else
1782 (char_u *)NULL, PV_NONE,
1783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1786 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001787 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"maxmem", "mm", P_NUM|P_VI_DEF,
1789 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1791 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001792 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1793 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1796 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001797 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1798 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 {"menuitems", "mis", P_NUM|P_VI_DEF,
1800#ifdef FEAT_MENU
1801 (char_u *)&p_mis, PV_NONE,
1802#else
1803 (char_u *)NULL, PV_NONE,
1804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001805 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001806 {"mesg", NULL, P_BOOL|P_VI_DEF,
1807 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001809 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001810#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001811 (char_u *)&p_msm, PV_NONE,
1812 {(char_u *)"460000,2000,500", (char_u *)0L}
1813#else
1814 (char_u *)NULL, PV_NONE,
1815 {(char_u *)0L, (char_u *)0L}
1816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"modeline", "ml", P_BOOL|P_VIM,
1819 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"modelines", "mls", P_NUM|P_VI_DEF,
1822 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1825 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001826 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1828 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001829 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"more", NULL, P_BOOL|P_VIM,
1831 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1834 (char_u *)&p_mouse, PV_NONE,
1835 {
1836#if defined(MSDOS) || defined(WIN3264)
1837 (char_u *)"a",
1838#else
1839 (char_u *)"",
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1843#ifdef FEAT_GUI
1844 (char_u *)&p_mousef, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1850#ifdef FEAT_GUI
1851 (char_u *)&p_mh, PV_NONE,
1852#else
1853 (char_u *)NULL, PV_NONE,
1854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1857 (char_u *)&p_mousem, PV_NONE,
1858 {
1859#if defined(MSDOS) || defined(MSWIN)
1860 (char_u *)"popup",
1861#else
1862# if defined(MACOS)
1863 (char_u *)"popup_setpos",
1864# else
1865 (char_u *)"extend",
1866# endif
1867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1870#ifdef FEAT_MOUSESHAPE
1871 (char_u *)&p_mouseshape, PV_NONE,
1872 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1873#else
1874 (char_u *)NULL, PV_NONE,
1875 {(char_u *)NULL, (char_u *)0L}
1876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1879 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001881 {"mzquantum", "mzq", P_NUM,
1882#ifdef FEAT_MZSCHEME
1883 (char_u *)&p_mzq, PV_NONE,
1884#else
1885 (char_u *)NULL, PV_NONE,
1886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"novice", NULL, P_BOOL|P_VI_DEF,
1889 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1892 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 {(char_u *)"octal,hex", (char_u *)0L}
1894 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1896 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001897 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001898 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1899#ifdef FEAT_LINEBREAK
1900 (char_u *)VAR_WIN, PV_NUW,
1901#else
1902 (char_u *)NULL, PV_NONE,
1903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001905 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001906#ifdef FEAT_COMPL_FUNC
1907 (char_u *)&p_ofu, PV_OFU,
1908 {(char_u *)"", (char_u *)0L}
1909#else
1910 (char_u *)NULL, PV_NONE,
1911 {(char_u *)0L, (char_u *)0L}
1912#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001913 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 {"open", NULL, P_BOOL|P_VI_DEF,
1915 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001916 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001917 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1918#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1919 (char_u *)&p_odev, PV_NONE,
1920#else
1921 (char_u *)NULL, PV_NONE,
1922#endif
1923 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001925 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1926 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"optimize", "opt", P_BOOL|P_VI_DEF,
1929 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001933 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 {"paragraphs", "para", P_STRING|P_VI_DEF,
1935 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001936 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001938 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1942 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1945#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1946 (char_u *)&p_pex, PV_NONE,
1947 {(char_u *)"", (char_u *)0L}
1948#else
1949 (char_u *)NULL, PV_NONE,
1950 {(char_u *)0L, (char_u *)0L}
1951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001953 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001957 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {
1959#if defined AMIGA || defined MSDOS || defined MSWIN
1960 (char_u *)".,,",
1961#else
1962# if defined(__EMX__)
1963 (char_u *)".,/emx/include,,",
1964# else /* Unix, probably */
1965 (char_u *)".,/usr/include,,",
1966# endif
1967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001968 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001969 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1970 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001972 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1974 (char_u *)&p_pvh, PV_NONE,
1975#else
1976 (char_u *)NULL, PV_NONE,
1977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1980#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1981 (char_u *)VAR_WIN, PV_PVW,
1982#else
1983 (char_u *)NULL, PV_NONE,
1984#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001986 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987#ifdef FEAT_PRINTER
1988 (char_u *)&p_pdev, PV_NONE,
1989 {(char_u *)"", (char_u *)0L}
1990#else
1991 (char_u *)NULL, PV_NONE,
1992 {(char_u *)NULL, (char_u *)0L}
1993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"printencoding", "penc", P_STRING|P_VI_DEF,
1996#ifdef FEAT_POSTSCRIPT
1997 (char_u *)&p_penc, PV_NONE,
1998 {(char_u *)"", (char_u *)0L}
1999#else
2000 (char_u *)NULL, PV_NONE,
2001 {(char_u *)NULL, (char_u *)0L}
2002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002003 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2005#ifdef FEAT_POSTSCRIPT
2006 (char_u *)&p_pexpr, PV_NONE,
2007 {(char_u *)"", (char_u *)0L}
2008#else
2009 (char_u *)NULL, PV_NONE,
2010 {(char_u *)NULL, (char_u *)0L}
2011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"printfont", "pfn", P_STRING|P_VI_DEF,
2014#ifdef FEAT_PRINTER
2015 (char_u *)&p_pfn, PV_NONE,
2016 {
2017# ifdef MSWIN
2018 (char_u *)"Courier_New:h10",
2019# else
2020 (char_u *)"courier",
2021# endif
2022 (char_u *)0L}
2023#else
2024 (char_u *)NULL, PV_NONE,
2025 {(char_u *)NULL, (char_u *)0L}
2026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002027 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2029#ifdef FEAT_PRINTER
2030 (char_u *)&p_header, PV_NONE,
2031 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2032#else
2033 (char_u *)NULL, PV_NONE,
2034 {(char_u *)NULL, (char_u *)0L}
2035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002037 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2038#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2039 (char_u *)&p_pmcs, PV_NONE,
2040 {(char_u *)"", (char_u *)0L}
2041#else
2042 (char_u *)NULL, PV_NONE,
2043 {(char_u *)NULL, (char_u *)0L}
2044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002046 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2047#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2048 (char_u *)&p_pmfn, PV_NONE,
2049 {(char_u *)"", (char_u *)0L}
2050#else
2051 (char_u *)NULL, PV_NONE,
2052 {(char_u *)NULL, (char_u *)0L}
2053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2056#ifdef FEAT_PRINTER
2057 (char_u *)&p_popt, PV_NONE,
2058 {(char_u *)"", (char_u *)0L}
2059#else
2060 (char_u *)NULL, PV_NONE,
2061 {(char_u *)NULL, (char_u *)0L}
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002065 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002067 {"pumheight", "ph", P_NUM|P_VI_DEF,
2068#ifdef FEAT_INS_EXPAND
2069 (char_u *)&p_ph, PV_NONE,
2070#else
2071 (char_u *)NULL, PV_NONE,
2072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002073 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002074 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2075#ifdef FEAT_TEXTOBJ
2076 (char_u *)&p_qe, PV_QE,
2077 {(char_u *)"\\", (char_u *)0L}
2078#else
2079 (char_u *)NULL, PV_NONE,
2080 {(char_u *)NULL, (char_u *)0L}
2081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002082 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2084 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"redraw", NULL, P_BOOL|P_VI_DEF,
2087 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002089 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2090#ifdef FEAT_RELTIME
2091 (char_u *)&p_rdt, PV_NONE,
2092#else
2093 (char_u *)NULL, PV_NONE,
2094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002096 {"regexpengine", "re", P_NUM|P_VI_DEF,
2097 (char_u *)&p_re, PV_NONE,
2098 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002099 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2100 (char_u *)VAR_WIN, PV_RNU,
2101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 {"remap", NULL, P_BOOL|P_VI_DEF,
2103 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"report", NULL, P_NUM|P_VI_DEF,
2106 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2109#ifdef WIN3264
2110 (char_u *)&p_rs, PV_NONE,
2111#else
2112 (char_u *)NULL, PV_NONE,
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2116#ifdef FEAT_RIGHTLEFT
2117 (char_u *)&p_ri, PV_NONE,
2118#else
2119 (char_u *)NULL, PV_NONE,
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2123#ifdef FEAT_RIGHTLEFT
2124 (char_u *)VAR_WIN, PV_RL,
2125#else
2126 (char_u *)NULL, PV_NONE,
2127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2130#ifdef FEAT_RIGHTLEFT
2131 (char_u *)VAR_WIN, PV_RLC,
2132 {(char_u *)"search", (char_u *)NULL}
2133#else
2134 (char_u *)NULL, PV_NONE,
2135 {(char_u *)NULL, (char_u *)0L}
2136#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2139#ifdef FEAT_CMDL_INFO
2140 (char_u *)&p_ru, PV_NONE,
2141#else
2142 (char_u *)NULL, PV_NONE,
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002145 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2146#ifdef FEAT_STL_OPT
2147 (char_u *)&p_ruf, PV_NONE,
2148#else
2149 (char_u *)NULL, PV_NONE,
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2153 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2155 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2157 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002158 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002159 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2160#ifdef FEAT_SCROLLBIND
2161 (char_u *)VAR_WIN, PV_SCBIND,
2162#else
2163 (char_u *)NULL, PV_NONE,
2164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002165 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2167 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2170 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002171 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2173#ifdef FEAT_SCROLLBIND
2174 (char_u *)&p_sbo, PV_NONE,
2175 {(char_u *)"ver,jump", (char_u *)0L}
2176#else
2177 (char_u *)NULL, PV_NONE,
2178 {(char_u *)0L, (char_u *)0L}
2179#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002180 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 {"sections", "sect", P_STRING|P_VI_DEF,
2182 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002183 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2184 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2186 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002190 {(char_u *)"inclusive", (char_u *)0L}
2191 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002194 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2196#ifdef FEAT_SESSION
2197 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002198 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002199 (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)0L, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2206 (char_u *)&p_sh, PV_NONE,
2207 {
2208#ifdef VMS
2209 (char_u *)"-",
2210#else
2211# if defined(MSDOS)
2212 (char_u *)"command",
2213# else
2214# if defined(WIN16)
2215 (char_u *)"command.com",
2216# else
2217# if defined(WIN3264)
2218 (char_u *)"", /* set in set_init_1() */
2219# else
2220# if defined(OS2)
2221 (char_u *)"cmd.exe",
2222# else
2223# if defined(ARCHIE)
2224 (char_u *)"gos",
2225# else
2226 (char_u *)"sh",
2227# endif
2228# endif
2229# endif
2230# endif
2231# endif
2232#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2235 (char_u *)&p_shcf, PV_NONE,
2236 {
2237#if defined(MSDOS) || defined(MSWIN)
2238 (char_u *)"/c",
2239#else
2240# if defined(OS2)
2241 (char_u *)"/c",
2242# else
2243 (char_u *)"-c",
2244# endif
2245#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2248#ifdef FEAT_QUICKFIX
2249 (char_u *)&p_sp, PV_NONE,
2250 {
2251#if defined(UNIX) || defined(OS2)
2252# ifdef ARCHIE
2253 (char_u *)"2>",
2254# else
2255 (char_u *)"| tee",
2256# endif
2257#else
2258 (char_u *)">",
2259#endif
2260 (char_u *)0L}
2261#else
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)0L, (char_u *)0L}
2264#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2267 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2270 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2273#ifdef BACKSLASH_IN_FILENAME
2274 (char_u *)&p_ssl, PV_NONE,
2275#else
2276 (char_u *)NULL, PV_NONE,
2277#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002279 {"shelltemp", "stmp", P_BOOL,
2280 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002281 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"shelltype", "st", P_NUM|P_VI_DEF,
2283#ifdef AMIGA
2284 (char_u *)&p_st, PV_NONE,
2285#else
2286 (char_u *)NULL, PV_NONE,
2287#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2290 (char_u *)&p_sxq, PV_NONE,
2291 {
2292#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2293 (char_u *)"\"",
2294#else
2295 (char_u *)"",
2296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002298 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2299 (char_u *)&p_sxe, PV_NONE,
2300 {
2301#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2302 (char_u *)"\"&|<>()@^",
2303#else
2304 (char_u *)"",
2305#endif
2306 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2308 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2311 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002312 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2314 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 {(char_u *)"", (char_u *)"filnxtToO"}
2316 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"shortname", "sn", P_BOOL|P_VI_DEF,
2318#ifdef SHORT_FNAME
2319 (char_u *)NULL, PV_NONE,
2320#else
2321 (char_u *)&p_sn, PV_SN,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2325#ifdef FEAT_LINEBREAK
2326 (char_u *)&p_sbr, PV_NONE,
2327#else
2328 (char_u *)NULL, PV_NONE,
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"showcmd", "sc", P_BOOL|P_VIM,
2332#ifdef FEAT_CMDL_INFO
2333 (char_u *)&p_sc, PV_NONE,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
2337 {(char_u *)FALSE,
2338#ifdef UNIX
2339 (char_u *)FALSE
2340#else
2341 (char_u *)TRUE
2342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2345 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2348 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"showmode", "smd", P_BOOL|P_VIM,
2351 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002353 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2354#ifdef FEAT_WINDOWS
2355 (char_u *)&p_stal, PV_NONE,
2356#else
2357 (char_u *)NULL, PV_NONE,
2358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002359 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2361 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2364 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2367 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2370 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2373#ifdef FEAT_SMARTINDENT
2374 (char_u *)&p_si, PV_SI,
2375#else
2376 (char_u *)NULL, PV_NONE,
2377#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2380 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2383 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2386 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002388 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002389#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002390 (char_u *)VAR_WIN, PV_SPELL,
2391#else
2392 (char_u *)NULL, PV_NONE,
2393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002395 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002396#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002397 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002398 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002399#else
2400 (char_u *)NULL, PV_NONE,
2401 {(char_u *)0L, (char_u *)0L}
2402#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002404 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002405#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002406 (char_u *)&p_spf, PV_SPF,
2407 {(char_u *)"", (char_u *)0L}
2408#else
2409 (char_u *)NULL, PV_NONE,
2410 {(char_u *)0L, (char_u *)0L}
2411#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002413 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002414#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002415 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002416 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002417#else
2418 (char_u *)NULL, PV_NONE,
2419 {(char_u *)0L, (char_u *)0L}
2420#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002422 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002423#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002424 (char_u *)&p_sps, PV_NONE,
2425 {(char_u *)"best", (char_u *)0L}
2426#else
2427 (char_u *)NULL, PV_NONE,
2428 {(char_u *)0L, (char_u *)0L}
2429#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2432#ifdef FEAT_WINDOWS
2433 (char_u *)&p_sb, PV_NONE,
2434#else
2435 (char_u *)NULL, PV_NONE,
2436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"splitright", "spr", P_BOOL|P_VI_DEF,
2439#ifdef FEAT_VERTSPLIT
2440 (char_u *)&p_spr, PV_NONE,
2441#else
2442 (char_u *)NULL, PV_NONE,
2443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2446 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2449#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002450 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451#else
2452 (char_u *)NULL, PV_NONE,
2453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2456 (char_u *)&p_su, PV_NONE,
2457 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002460#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 (char_u *)&p_sua, PV_SUA,
2462 {(char_u *)"", (char_u *)0L}
2463#else
2464 (char_u *)NULL, PV_NONE,
2465 {(char_u *)0L, (char_u *)0L}
2466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2469 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"swapsync", "sws", P_STRING|P_VI_DEF,
2472 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2475 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002477 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2478#ifdef FEAT_SYN_HL
2479 (char_u *)&p_smc, PV_SMC,
2480 {(char_u *)3000L, (char_u *)0L}
2481#else
2482 (char_u *)NULL, PV_NONE,
2483 {(char_u *)0L, (char_u *)0L}
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002486 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487#ifdef FEAT_SYN_HL
2488 (char_u *)&p_syn, PV_SYN,
2489 {(char_u *)"", (char_u *)0L}
2490#else
2491 (char_u *)NULL, PV_NONE,
2492 {(char_u *)0L, (char_u *)0L}
2493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002494 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002495 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2496#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002497 (char_u *)&p_tal, PV_NONE,
2498#else
2499 (char_u *)NULL, PV_NONE,
2500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002502 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2503#ifdef FEAT_WINDOWS
2504 (char_u *)&p_tpm, PV_NONE,
2505#else
2506 (char_u *)NULL, PV_NONE,
2507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2510 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2513 (char_u *)&p_tbs, PV_NONE,
2514#ifdef VMS /* binary searching doesn't appear to work on VMS */
2515 {(char_u *)0L, (char_u *)0L}
2516#else
2517 {(char_u *)TRUE, (char_u *)0L}
2518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"taglength", "tl", P_NUM|P_VI_DEF,
2521 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"tagrelative", "tr", P_BOOL|P_VIM,
2524 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002527 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {
2529#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2530 (char_u *)"./tags,./TAGS,tags,TAGS",
2531#else
2532 (char_u *)"./tags,tags",
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2536 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2539 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2542#ifdef FEAT_ARABIC
2543 (char_u *)&p_tbidi, PV_NONE,
2544#else
2545 (char_u *)NULL, PV_NONE,
2546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2549#ifdef FEAT_MBYTE
2550 (char_u *)&p_tenc, PV_NONE,
2551 {(char_u *)"", (char_u *)0L}
2552#else
2553 (char_u *)NULL, PV_NONE,
2554 {(char_u *)0L, (char_u *)0L}
2555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"terse", NULL, P_BOOL|P_VI_DEF,
2558 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"textauto", "ta", P_BOOL|P_VIM,
2561 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2563 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2565 (char_u *)&p_tx, PV_TX,
2566 {
2567#ifdef USE_CRNL
2568 (char_u *)TRUE,
2569#else
2570 (char_u *)FALSE,
2571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002573 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2577#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002578 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579#else
2580 (char_u *)NULL, PV_NONE,
2581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2584 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"timeout", "to", P_BOOL|P_VI_DEF,
2587 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2590 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"title", NULL, P_BOOL|P_VI_DEF,
2593#ifdef FEAT_TITLE
2594 (char_u *)&p_title, PV_NONE,
2595#else
2596 (char_u *)NULL, PV_NONE,
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"titlelen", NULL, P_NUM|P_VI_DEF,
2600#ifdef FEAT_TITLE
2601 (char_u *)&p_titlelen, PV_NONE,
2602#else
2603 (char_u *)NULL, PV_NONE,
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002606 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607#ifdef FEAT_TITLE
2608 (char_u *)&p_titleold, PV_NONE,
2609 {(char_u *)N_("Thanks for flying Vim"),
2610 (char_u *)0L}
2611#else
2612 (char_u *)NULL, PV_NONE,
2613 {(char_u *)0L, (char_u *)0L}
2614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {"titlestring", NULL, P_STRING|P_VI_DEF,
2617#ifdef FEAT_TITLE
2618 (char_u *)&p_titlestring, PV_NONE,
2619#else
2620 (char_u *)NULL, PV_NONE,
2621#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2624 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2625 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)"icons,tooltips", (char_u *)0L}
2627 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002629#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2631 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633#endif
2634 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2635 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2638 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2641 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2644 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2647#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2648 (char_u *)&p_ttym, PV_NONE,
2649#else
2650 (char_u *)NULL, PV_NONE,
2651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2654 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2657 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002659 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2660#ifdef FEAT_PERSISTENT_UNDO
2661 (char_u *)&p_udir, PV_NONE,
2662 {(char_u *)".", (char_u *)0L}
2663#else
2664 (char_u *)NULL, PV_NONE,
2665 {(char_u *)0L, (char_u *)0L}
2666#endif
2667 SCRIPTID_INIT},
2668 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2669#ifdef FEAT_PERSISTENT_UNDO
2670 (char_u *)&p_udf, PV_UDF,
2671#else
2672 (char_u *)NULL, PV_NONE,
2673#endif
2674 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002676 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {
2678#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2679 (char_u *)1000L,
2680#else
2681 (char_u *)100L,
2682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002684 {"undoreload", "ur", P_NUM|P_VI_DEF,
2685 (char_u *)&p_ur, PV_NONE,
2686 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"updatecount", "uc", P_NUM|P_VI_DEF,
2688 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 {"updatetime", "ut", P_NUM|P_VI_DEF,
2691 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 {"verbose", "vbs", P_NUM|P_VI_DEF,
2694 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002696 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2697 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2700#ifdef FEAT_SESSION
2701 (char_u *)&p_vdir, PV_NONE,
2702 {(char_u *)DFLT_VDIR, (char_u *)0L}
2703#else
2704 (char_u *)NULL, PV_NONE,
2705 {(char_u *)0L, (char_u *)0L}
2706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2709#ifdef FEAT_SESSION
2710 (char_u *)&p_vop, PV_NONE,
2711 {(char_u *)"folds,options,cursor", (char_u *)0L}
2712#else
2713 (char_u *)NULL, PV_NONE,
2714 {(char_u *)0L, (char_u *)0L}
2715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2718#ifdef FEAT_VIMINFO
2719 (char_u *)&p_viminfo, PV_NONE,
2720#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002721 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722#else
2723# ifdef AMIGA
2724 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002725 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002727 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728# endif
2729#endif
2730#else
2731 (char_u *)NULL, PV_NONE,
2732 {(char_u *)0L, (char_u *)0L}
2733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002735 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736#ifdef FEAT_VIRTUALEDIT
2737 (char_u *)&p_ve, PV_NONE,
2738 {(char_u *)"", (char_u *)""}
2739#else
2740 (char_u *)NULL, PV_NONE,
2741 {(char_u *)0L, (char_u *)0L}
2742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002743 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2745 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"w300", NULL, P_NUM|P_VI_DEF,
2748 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"w1200", NULL, P_NUM|P_VI_DEF,
2751 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"w9600", NULL, P_NUM|P_VI_DEF,
2754 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"warn", NULL, P_BOOL|P_VI_DEF,
2757 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2760 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2763 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"wildchar", "wc", P_NUM|P_VIM,
2766 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2768 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002769 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2773#ifdef FEAT_WILDIGN
2774 (char_u *)&p_wig, PV_NONE,
2775#else
2776 (char_u *)NULL, PV_NONE,
2777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002779 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2780 (char_u *)&p_wic, PV_NONE,
2781 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2783#ifdef FEAT_WILDMENU
2784 (char_u *)&p_wmnu, PV_NONE,
2785#else
2786 (char_u *)NULL, PV_NONE,
2787#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2790 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002792 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2793#ifdef FEAT_CMDL_COMPL
2794 (char_u *)&p_wop, PV_NONE,
2795 {(char_u *)"", (char_u *)0L}
2796#else
2797 (char_u *)NULL, PV_NONE,
2798 {(char_u *)NULL, (char_u *)0L}
2799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2802#ifdef FEAT_WAK
2803 (char_u *)&p_wak, PV_NONE,
2804 {(char_u *)"menu", (char_u *)0L}
2805#else
2806 (char_u *)NULL, PV_NONE,
2807 {(char_u *)NULL, (char_u *)0L}
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002811 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"winheight", "wh", P_NUM|P_VI_DEF,
2814#ifdef FEAT_WINDOWS
2815 (char_u *)&p_wh, PV_NONE,
2816#else
2817 (char_u *)NULL, PV_NONE,
2818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002821#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 (char_u *)VAR_WIN, PV_WFH,
2823#else
2824 (char_u *)NULL, PV_NONE,
2825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002827 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2828#ifdef FEAT_VERTSPLIT
2829 (char_u *)VAR_WIN, PV_WFW,
2830#else
2831 (char_u *)NULL, PV_NONE,
2832#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2835#ifdef FEAT_WINDOWS
2836 (char_u *)&p_wmh, PV_NONE,
2837#else
2838 (char_u *)NULL, PV_NONE,
2839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2842#ifdef FEAT_VERTSPLIT
2843 (char_u *)&p_wmw, PV_NONE,
2844#else
2845 (char_u *)NULL, PV_NONE,
2846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002847 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2849#ifdef FEAT_VERTSPLIT
2850 (char_u *)&p_wiw, PV_NONE,
2851#else
2852 (char_u *)NULL, PV_NONE,
2853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2856 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2859 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2862 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002863 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"write", NULL, P_BOOL|P_VI_DEF,
2865 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"writeany", "wa", P_BOOL|P_VI_DEF,
2868 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2871 (char_u *)&p_wb, PV_NONE,
2872 {
2873#ifdef FEAT_WRITEBACKUP
2874 (char_u *)TRUE,
2875#else
2876 (char_u *)FALSE,
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"writedelay", "wd", P_NUM|P_VI_DEF,
2880 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002882
2883/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002884#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887
2888 p_term("t_AB", T_CAB)
2889 p_term("t_AF", T_CAF)
2890 p_term("t_AL", T_CAL)
2891 p_term("t_al", T_AL)
2892 p_term("t_bc", T_BC)
2893 p_term("t_cd", T_CD)
2894 p_term("t_ce", T_CE)
2895 p_term("t_cl", T_CL)
2896 p_term("t_cm", T_CM)
2897 p_term("t_Co", T_CCO)
2898 p_term("t_CS", T_CCS)
2899 p_term("t_cs", T_CS)
2900#ifdef FEAT_VERTSPLIT
2901 p_term("t_CV", T_CSV)
2902#endif
2903 p_term("t_ut", T_UT)
2904 p_term("t_da", T_DA)
2905 p_term("t_db", T_DB)
2906 p_term("t_DL", T_CDL)
2907 p_term("t_dl", T_DL)
2908 p_term("t_fs", T_FS)
2909 p_term("t_IE", T_CIE)
2910 p_term("t_IS", T_CIS)
2911 p_term("t_ke", T_KE)
2912 p_term("t_ks", T_KS)
2913 p_term("t_le", T_LE)
2914 p_term("t_mb", T_MB)
2915 p_term("t_md", T_MD)
2916 p_term("t_me", T_ME)
2917 p_term("t_mr", T_MR)
2918 p_term("t_ms", T_MS)
2919 p_term("t_nd", T_ND)
2920 p_term("t_op", T_OP)
2921 p_term("t_RI", T_CRI)
2922 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002923 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 p_term("t_Sb", T_CSB)
2925 p_term("t_Sf", T_CSF)
2926 p_term("t_se", T_SE)
2927 p_term("t_so", T_SO)
2928 p_term("t_sr", T_SR)
2929 p_term("t_ts", T_TS)
2930 p_term("t_te", T_TE)
2931 p_term("t_ti", T_TI)
2932 p_term("t_ue", T_UE)
2933 p_term("t_us", T_US)
2934 p_term("t_vb", T_VB)
2935 p_term("t_ve", T_VE)
2936 p_term("t_vi", T_VI)
2937 p_term("t_vs", T_VS)
2938 p_term("t_WP", T_CWP)
2939 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002940 p_term("t_SI", T_CSI)
2941 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 p_term("t_xs", T_XS)
2943 p_term("t_ZH", T_CZH)
2944 p_term("t_ZR", T_CZR)
2945
2946/* terminal key codes are not in here */
2947
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 /* end marker */
2949 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950};
2951
2952#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2953
2954#ifdef FEAT_MBYTE
2955static char *(p_ambw_values[]) = {"single", "double", NULL};
2956#endif
2957static char *(p_bg_values[]) = {"light", "dark", NULL};
2958static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2959static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002960#ifdef FEAT_CRYPT
2961static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2962#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002963#ifdef FEAT_CMDL_COMPL
2964static char *(p_wop_values[]) = {"tagfile", NULL};
2965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966#ifdef FEAT_WAK
2967static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2968#endif
2969static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2971static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973#ifdef FEAT_BROWSE
2974static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2975#endif
2976#ifdef FEAT_SCROLLBIND
2977static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2978#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002979static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980#ifdef FEAT_VERTSPLIT
2981static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2982#endif
2983#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002984# ifdef FEAT_AUTOCMD
2985static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
2986# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00002988# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2990#endif
2991static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2992#ifdef FEAT_FOLDING
2993static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002994# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00002996# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 NULL};
2998static char *(p_fcl_values[]) = {"all", NULL};
2999#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003000#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003001static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003
3004static void set_option_default __ARGS((int, int opt_flags, int compatible));
3005static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003006static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003007static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008static char_u *illegal_char __ARGS((char_u *, int));
3009static int string_to_key __ARGS((char_u *arg));
3010#ifdef FEAT_CMDWIN
3011static char_u *check_cedit __ARGS((void));
3012#endif
3013#ifdef FEAT_TITLE
3014static void did_set_title __ARGS((int icon));
3015#endif
3016static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3017static void didset_options __ARGS((void));
3018static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003019#if defined(FEAT_EVAL) || defined(PROTO)
3020static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3021#else
3022# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3023#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003025static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
3027static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003028#ifdef FEAT_SYN_HL
3029static int int_cmp __ARGS((const void *a, const void *b));
3030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031#ifdef FEAT_CLIPBOARD
3032static char_u *check_clipboard_option __ARGS((void));
3033#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003034#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003035static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003036#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003037#ifdef FEAT_EVAL
3038static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003041static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042static void check_redraw __ARGS((long_u flags));
3043static int findoption __ARGS((char_u *));
3044static int find_key_option __ARGS((char_u *));
3045static void showoptions __ARGS((int all, int opt_flags));
3046static int optval_default __ARGS((struct vimoption *, char_u *varp));
3047static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3048static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3049static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3050static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3051static int istermoption __ARGS((struct vimoption *));
3052static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3053static char_u *get_varp __ARGS((struct vimoption *));
3054static void option_value2string __ARGS((struct vimoption *, int opt_flags));
3055static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3056#ifdef FEAT_LANGMAP
3057static void langmap_init __ARGS((void));
3058static void langmap_set __ARGS((void));
3059#endif
3060static void paste_option_changed __ARGS((void));
3061static void compatible_set __ARGS((void));
3062#ifdef FEAT_LINEBREAK
3063static void fill_breakat_flags __ARGS((void));
3064#endif
3065static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3066static int check_opt_strings __ARGS((char_u *val, char **values, int));
3067static int check_opt_wim __ARGS((void));
3068
3069/*
3070 * Initialize the options, first part.
3071 *
3072 * Called only once from main(), just after creating the first buffer.
3073 */
3074 void
3075set_init_1()
3076{
3077 char_u *p;
3078 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003079 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080
3081#ifdef FEAT_LANGMAP
3082 langmap_init();
3083#endif
3084
3085 /* Be Vi compatible by default */
3086 p_cp = TRUE;
3087
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003088 /* Use POSIX compatibility when $VIM_POSIX is set. */
3089 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003090 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003091 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003092 set_string_default("shm", (char_u *)"A");
3093 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003094
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 /*
3096 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003097 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003099 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3101# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003102 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003104 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003106 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107# endif
3108#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003109 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 set_string_default("sh", p);
3111
3112#ifdef FEAT_WILDIGN
3113 /*
3114 * Set the default for 'backupskip' to include environment variables for
3115 * temp files.
3116 */
3117 {
3118# ifdef UNIX
3119 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3120# else
3121 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3122# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003123 int len;
3124 garray_T ga;
3125 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126
3127 ga_init2(&ga, 1, 100);
3128 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3129 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003130 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131# ifdef UNIX
3132 if (*names[n] == NUL)
3133 p = (char_u *)"/tmp";
3134 else
3135# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003136 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 if (p != NULL && *p != NUL)
3138 {
3139 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003140 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 if (ga_grow(&ga, len) == OK)
3142 {
3143 if (ga.ga_len > 0)
3144 STRCAT(ga.ga_data, ",");
3145 STRCAT(ga.ga_data, p);
3146 add_pathsep(ga.ga_data);
3147 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 ga.ga_len += len;
3149 }
3150 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003151 if (mustfree)
3152 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 }
3154 if (ga.ga_data != NULL)
3155 {
3156 set_string_default("bsk", ga.ga_data);
3157 vim_free(ga.ga_data);
3158 }
3159 }
3160#endif
3161
3162 /*
3163 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3164 */
3165 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003166 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003168#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3169 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3170#endif
3171 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003173 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003174 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175#else
3176# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003177 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003178 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003180 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181# endif
3182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003184 opt_idx = findoption((char_u *)"maxmem");
3185 if (opt_idx >= 0)
3186 {
3187#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003188 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003189 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3190#endif
3191 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3192 }
3193 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 }
3195
3196#ifdef FEAT_GUI_W32
3197 /* force 'shortname' for Win32s */
3198 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003199 {
3200 opt_idx = findoption((char_u *)"shortname");
3201 if (opt_idx >= 0)
3202 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3203 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204#endif
3205
3206#ifdef FEAT_SEARCHPATH
3207 {
3208 char_u *cdpath;
3209 char_u *buf;
3210 int i;
3211 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003212 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213
3214 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003215 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 if (cdpath != NULL)
3217 {
3218 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3219 if (buf != NULL)
3220 {
3221 buf[0] = ','; /* start with ",", current dir first */
3222 j = 1;
3223 for (i = 0; cdpath[i] != NUL; ++i)
3224 {
3225 if (vim_ispathlistsep(cdpath[i]))
3226 buf[j++] = ',';
3227 else
3228 {
3229 if (cdpath[i] == ' ' || cdpath[i] == ',')
3230 buf[j++] = '\\';
3231 buf[j++] = cdpath[i];
3232 }
3233 }
3234 buf[j] = NUL;
3235 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003236 if (opt_idx >= 0)
3237 {
3238 options[opt_idx].def_val[VI_DEFAULT] = buf;
3239 options[opt_idx].flags |= P_DEF_ALLOCED;
3240 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003241 else
3242 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003244 if (mustfree)
3245 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 }
3247 }
3248#endif
3249
3250#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3251 /* Set print encoding on platforms that don't default to latin1 */
3252 set_string_default("penc",
3253# if defined(MSWIN) || defined(OS2)
3254 (char_u *)"cp1252"
3255# else
3256# ifdef VMS
3257 (char_u *)"dec-mcs"
3258# else
3259# ifdef EBCDIC
3260 (char_u *)"ebcdic-uk"
3261# else
3262# ifdef MAC
3263 (char_u *)"mac-roman"
3264# else /* HPUX */
3265 (char_u *)"hp-roman8"
3266# endif
3267# endif
3268# endif
3269# endif
3270 );
3271#endif
3272
3273#ifdef FEAT_POSTSCRIPT
3274 /* 'printexpr' must be allocated to be able to evaluate it. */
3275 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003276# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3277 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278# else
3279# ifdef VMS
3280 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3281
3282# else
3283 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3284# endif
3285# endif
3286 );
3287#endif
3288
3289 /*
3290 * Set all the options (except the terminal options) to their default
3291 * value. Also set the global value for local options.
3292 */
3293 set_options_default(0);
3294
3295#ifdef FEAT_GUI
3296 if (found_reverse_arg)
3297 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3298#endif
3299
3300 curbuf->b_p_initialized = TRUE;
3301 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003302 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303 check_buf_options(curbuf);
3304 check_win_options(curwin);
3305 check_options();
3306
3307 /* Must be before option_expand(), because that one needs vim_isIDc() */
3308 didset_options();
3309
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003310#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003311 /* Use the current chartab for the generic chartab. */
3312 init_spell_chartab();
3313#endif
3314
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315#ifdef FEAT_LINEBREAK
3316 /*
3317 * initialize the table for 'breakat'.
3318 */
3319 fill_breakat_flags();
3320#endif
3321
3322 /*
3323 * Expand environment variables and things like "~" for the defaults.
3324 * If option_expand() returns non-NULL the variable is expanded. This can
3325 * only happen for non-indirect options.
3326 * Also set the default to the expanded value, so ":set" does not list
3327 * them.
3328 * Don't set the P_ALLOCED flag, because we don't want to free the
3329 * default.
3330 */
3331 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3332 {
3333 if ((options[opt_idx].flags & P_GETTEXT)
3334 && options[opt_idx].var != NULL)
3335 p = (char_u *)_(*(char **)options[opt_idx].var);
3336 else
3337 p = option_expand(opt_idx, NULL);
3338 if (p != NULL && (p = vim_strsave(p)) != NULL)
3339 {
3340 *(char_u **)options[opt_idx].var = p;
3341 /* VIMEXP
3342 * Defaults for all expanded options are currently the same for Vi
3343 * and Vim. When this changes, add some code here! Also need to
3344 * split P_DEF_ALLOCED in two.
3345 */
3346 if (options[opt_idx].flags & P_DEF_ALLOCED)
3347 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3348 options[opt_idx].def_val[VI_DEFAULT] = p;
3349 options[opt_idx].flags |= P_DEF_ALLOCED;
3350 }
3351 }
3352
3353 /* Initialize the highlight_attr[] table. */
3354 highlight_changed();
3355
3356 save_file_ff(curbuf); /* Buffer is unchanged */
3357
3358 /* Parse default for 'wildmode' */
3359 check_opt_wim();
3360
3361#if defined(FEAT_ARABIC)
3362 /* Detect use of mlterm.
3363 * Mlterm is a terminal emulator akin to xterm that has some special
3364 * abilities (bidi namely).
3365 * NOTE: mlterm's author is being asked to 'set' a variable
3366 * instead of an environment variable due to inheritance.
3367 */
3368 if (mch_getenv((char_u *)"MLTERM") != NULL)
3369 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3370#endif
3371
3372#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3373 /* Parse default for 'fillchars'. */
3374 (void)set_chars_option(&p_fcs);
3375#endif
3376
3377#ifdef FEAT_CLIPBOARD
3378 /* Parse default for 'clipboard' */
3379 (void)check_clipboard_option();
3380#endif
3381
3382#ifdef FEAT_MBYTE
3383# if defined(WIN3264) && defined(FEAT_GETTEXT)
3384 /*
3385 * If $LANG isn't set, try to get a good value for it. This makes the
3386 * right language be used automatically. Don't do this for English.
3387 */
3388 if (mch_getenv((char_u *)"LANG") == NULL)
3389 {
3390 char buf[20];
3391
3392 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3393 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3394 * only the first two. */
3395 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3396 (LPTSTR)buf, 20);
3397 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3398 {
3399 /* There are a few exceptions (probably more) */
3400 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3401 STRCPY(buf, "zh_TW");
3402 else if (STRNICMP(buf, "chs", 3) == 0
3403 || STRNICMP(buf, "zhc", 3) == 0)
3404 STRCPY(buf, "zh_CN");
3405 else if (STRNICMP(buf, "jp", 2) == 0)
3406 STRCPY(buf, "ja");
3407 else
3408 buf[2] = NUL; /* truncate to two-letter code */
3409 vim_setenv("LANG", buf);
3410 }
3411 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003412# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003413# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003414 /* Moved to os_mac_conv.c to avoid dependency problems. */
3415 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003416# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417# endif
3418
3419 /* enc_locale() will try to find the encoding of the current locale. */
3420 p = enc_locale();
3421 if (p != NULL)
3422 {
3423 char_u *save_enc;
3424
3425 /* Try setting 'encoding' and check if the value is valid.
3426 * If not, go back to the default "latin1". */
3427 save_enc = p_enc;
3428 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003429 if (STRCMP(p_enc, "gb18030") == 0)
3430 {
3431 /* We don't support "gb18030", but "cp936" is a good substitute
3432 * for practical purposes, thus use that. It's not an alias to
3433 * still support conversion between gb18030 and utf-8. */
3434 p_enc = vim_strsave((char_u *)"cp936");
3435 vim_free(p);
3436 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 if (mb_init() == NULL)
3438 {
3439 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003440 if (opt_idx >= 0)
3441 {
3442 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3443 options[opt_idx].flags |= P_DEF_ALLOCED;
3444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003446#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3447 || defined(VMS)
3448 if (STRCMP(p_enc, "latin1") == 0
3449# ifdef FEAT_MBYTE
3450 || enc_utf8
3451# endif
3452 )
3453 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003454 /* Adjust the default for 'isprint' and 'iskeyword' to match
3455 * latin1. Also set the defaults for when 'nocompatible' is
3456 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003457 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003458 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003459 set_string_option_direct((char_u *)"isk", -1,
3460 ISK_LATIN1, OPT_FREE, SID_NONE);
3461 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003462 if (opt_idx >= 0)
3463 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003464 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003465 if (opt_idx >= 0)
3466 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003467 (void)init_chartab();
3468 }
3469#endif
3470
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471# if defined(WIN3264) && !defined(FEAT_GUI)
3472 /* Win32 console: When GetACP() returns a different value from
3473 * GetConsoleCP() set 'termencoding'. */
3474 if (GetACP() != GetConsoleCP())
3475 {
3476 char buf[50];
3477
3478 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3479 p_tenc = vim_strsave((char_u *)buf);
3480 if (p_tenc != NULL)
3481 {
3482 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003483 if (opt_idx >= 0)
3484 {
3485 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3486 options[opt_idx].flags |= P_DEF_ALLOCED;
3487 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 convert_setup(&input_conv, p_tenc, p_enc);
3489 convert_setup(&output_conv, p_enc, p_tenc);
3490 }
3491 else
3492 p_tenc = empty_option;
3493 }
3494# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003495# if defined(WIN3264) && defined(FEAT_MBYTE)
3496 /* $HOME may have characters in active code page. */
3497 init_homedir();
3498# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 }
3500 else
3501 {
3502 vim_free(p_enc);
3503 p_enc = save_enc;
3504 }
3505 }
3506#endif
3507
3508#ifdef FEAT_MULTI_LANG
3509 /* Set the default for 'helplang'. */
3510 set_helplang_default(get_mess_lang());
3511#endif
3512}
3513
3514/*
3515 * Set an option to its default value.
3516 * This does not take care of side effects!
3517 */
3518 static void
3519set_option_default(opt_idx, opt_flags, compatible)
3520 int opt_idx;
3521 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3522 int compatible; /* use Vi default value */
3523{
3524 char_u *varp; /* pointer to variable for current option */
3525 int dvi; /* index in def_val[] */
3526 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003527 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3529
3530 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3531 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003532 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533 {
3534 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3535 if (flags & P_STRING)
3536 {
3537 /* Use set_string_option_direct() for local options to handle
3538 * freeing and allocating the value. */
3539 if (options[opt_idx].indir != PV_NONE)
3540 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003541 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 else
3543 {
3544 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3545 free_string_option(*(char_u **)(varp));
3546 *(char_u **)varp = options[opt_idx].def_val[dvi];
3547 options[opt_idx].flags &= ~P_ALLOCED;
3548 }
3549 }
3550 else if (flags & P_NUM)
3551 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003552 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 win_comp_scroll(curwin);
3554 else
3555 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003556 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557 /* May also set global value for local option. */
3558 if (both)
3559 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3560 *(long *)varp;
3561 }
3562 }
3563 else /* P_BOOL */
3564 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003565 /* the cast to long is required for Manx C, long_i is needed for
3566 * MSVC */
3567 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003568#ifdef UNIX
3569 /* 'modeline' defaults to off for root */
3570 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3571 *(int *)varp = FALSE;
3572#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 /* May also set global value for local option. */
3574 if (both)
3575 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3576 *(int *)varp;
3577 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003578
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003579 /* The default value is not insecure. */
3580 flagsp = insecure_flag(opt_idx, opt_flags);
3581 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582 }
3583
3584#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003585 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586#endif
3587}
3588
3589/*
3590 * Set all options (except terminal options) to their default value.
3591 */
3592 static void
3593set_options_default(opt_flags)
3594 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3595{
3596 int i;
3597#ifdef FEAT_WINDOWS
3598 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003599 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003600#endif
3601
3602 for (i = 0; !istermoption(&options[i]); i++)
3603 if (!(options[i].flags & P_NODEFAULT))
3604 set_option_default(i, opt_flags, p_cp);
3605
3606#ifdef FEAT_WINDOWS
3607 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003608 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 win_comp_scroll(wp);
3610#else
3611 win_comp_scroll(curwin);
3612#endif
3613}
3614
3615/*
3616 * Set the Vi-default value of a string option.
3617 * Used for 'sh', 'backupskip' and 'term'.
3618 */
3619 void
3620set_string_default(name, val)
3621 char *name;
3622 char_u *val;
3623{
3624 char_u *p;
3625 int opt_idx;
3626
3627 p = vim_strsave(val);
3628 if (p != NULL) /* we don't want a NULL */
3629 {
3630 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003631 if (opt_idx >= 0)
3632 {
3633 if (options[opt_idx].flags & P_DEF_ALLOCED)
3634 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3635 options[opt_idx].def_val[VI_DEFAULT] = p;
3636 options[opt_idx].flags |= P_DEF_ALLOCED;
3637 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 }
3639}
3640
3641/*
3642 * Set the Vi-default value of a number option.
3643 * Used for 'lines' and 'columns'.
3644 */
3645 void
3646set_number_default(name, val)
3647 char *name;
3648 long val;
3649{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003650 int opt_idx;
3651
3652 opt_idx = findoption((char_u *)name);
3653 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003654 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655}
3656
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003657#if defined(EXITFREE) || defined(PROTO)
3658/*
3659 * Free all options.
3660 */
3661 void
3662free_all_options()
3663{
3664 int i;
3665
3666 for (i = 0; !istermoption(&options[i]); i++)
3667 {
3668 if (options[i].indir == PV_NONE)
3669 {
3670 /* global option: free value and default value. */
3671 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3672 free_string_option(*(char_u **)options[i].var);
3673 if (options[i].flags & P_DEF_ALLOCED)
3674 free_string_option(options[i].def_val[VI_DEFAULT]);
3675 }
3676 else if (options[i].var != VAR_WIN
3677 && (options[i].flags & P_STRING))
3678 /* buffer-local option: free global value */
3679 free_string_option(*(char_u **)options[i].var);
3680 }
3681}
3682#endif
3683
3684
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685/*
3686 * Initialize the options, part two: After getting Rows and Columns and
3687 * setting 'term'.
3688 */
3689 void
3690set_init_2()
3691{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003692 int idx;
3693
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694 /*
3695 * 'scroll' defaults to half the window height. Note that this default is
3696 * wrong when the window height changes.
3697 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003698 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003699 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003701 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702 comp_col();
3703
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003704 /*
3705 * 'window' is only for backwards compatibility with Vi.
3706 * Default is Rows - 1.
3707 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003708 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003709 p_window = Rows - 1;
3710 set_number_default("window", Rows - 1);
3711
Bram Moolenaarf740b292006-02-16 22:11:02 +00003712 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003714 /*
3715 * If 'background' wasn't set by the user, try guessing the value,
3716 * depending on the terminal name. Only need to check for terminals
3717 * with a dark background, that can handle color.
3718 */
3719 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003720 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3721 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003723 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003724 /* don't mark it as set, when starting the GUI it may be
3725 * changed again */
3726 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727 }
3728#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003729
3730#ifdef CURSOR_SHAPE
3731 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3732#endif
3733#ifdef FEAT_MOUSESHAPE
3734 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3735#endif
3736#ifdef FEAT_PRINTER
3737 (void)parse_printoptions(); /* parse 'printoptions' default value */
3738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739}
3740
3741/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003742 * Return "dark" or "light" depending on the kind of terminal.
3743 * This is just guessing! Recognized are:
3744 * "linux" Linux console
3745 * "screen.linux" Linux console with screen
3746 * "cygwin" Cygwin shell
3747 * "putty" Putty program
3748 * We also check the COLORFGBG environment variable, which is set by
3749 * rxvt and derivatives. This variable contains either two or three
3750 * values separated by semicolons; we want the last value in either
3751 * case. If this value is 0-6 or 8, our background is dark.
3752 */
3753 static char_u *
3754term_bg_default()
3755{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003756#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3757 /* DOS console nearly always black */
3758 return (char_u *)"dark";
3759#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003760 char_u *p;
3761
Bram Moolenaarf740b292006-02-16 22:11:02 +00003762 if (STRCMP(T_NAME, "linux") == 0
3763 || STRCMP(T_NAME, "screen.linux") == 0
3764 || STRCMP(T_NAME, "cygwin") == 0
3765 || STRCMP(T_NAME, "putty") == 0
3766 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3767 && (p = vim_strrchr(p, ';')) != NULL
3768 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3769 && p[2] == NUL))
3770 return (char_u *)"dark";
3771 return (char_u *)"light";
3772#endif
3773}
3774
3775/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 * Initialize the options, part three: After reading the .vimrc
3777 */
3778 void
3779set_init_3()
3780{
3781#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3782/*
3783 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3784 * This is done after other initializations, where 'shell' might have been
3785 * set, but only if they have not been set before.
3786 */
3787 char_u *p;
3788 int idx_srr;
3789 int do_srr;
3790#ifdef FEAT_QUICKFIX
3791 int idx_sp;
3792 int do_sp;
3793#endif
3794
3795 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003796 if (idx_srr < 0)
3797 do_srr = FALSE;
3798 else
3799 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800#ifdef FEAT_QUICKFIX
3801 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003802 if (idx_sp < 0)
3803 do_sp = FALSE;
3804 else
3805 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806#endif
3807
3808 /*
3809 * Isolate the name of the shell:
3810 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
3811 * - Remove any argument. E.g., "csh -f" -> "csh".
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003812 * But don't allow a space in the path, so that this works:
3813 * "/usr/bin/csh --rcfile ~/.cshrc"
3814 * But don't do that for Windows, it's common to have a space in the path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 */
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003816#ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 p = gettail(p_sh);
3818 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
Bram Moolenaarae61bcf2010-05-13 13:12:06 +02003819#else
3820 p = skiptowhite(p_sh);
3821 if (*p == NUL)
3822 {
3823 /* No white space, use the tail. */
3824 p = vim_strsave(gettail(p_sh));
3825 }
3826 else
3827 {
3828 char_u *p1, *p2;
3829
3830 /* Find the last path separator before the space. */
3831 p1 = p_sh;
3832 for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
3833 if (vim_ispathsep(*p2))
3834 p1 = p2 + 1;
3835 p = vim_strnsave(p1, (int)(p - p1));
3836 }
3837#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 if (p != NULL)
3839 {
3840 /*
3841 * Default for p_sp is "| tee", for p_srr is ">".
3842 * For known shells it is changed here to include stderr.
3843 */
3844 if ( fnamecmp(p, "csh") == 0
3845 || fnamecmp(p, "tcsh") == 0
3846# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3847 || fnamecmp(p, "csh.exe") == 0
3848 || fnamecmp(p, "tcsh.exe") == 0
3849# endif
3850 )
3851 {
3852#if defined(FEAT_QUICKFIX)
3853 if (do_sp)
3854 {
3855# ifdef WIN3264
3856 p_sp = (char_u *)">&";
3857# else
3858 p_sp = (char_u *)"|& tee";
3859# endif
3860 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3861 }
3862#endif
3863 if (do_srr)
3864 {
3865 p_srr = (char_u *)">&";
3866 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3867 }
3868 }
3869 else
3870# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3871 if ( fnamecmp(p, "sh") == 0
3872 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003873 || fnamecmp(p, "mksh") == 0
3874 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003876 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 || fnamecmp(p, "bash") == 0
3878# ifdef WIN3264
3879 || fnamecmp(p, "cmd") == 0
3880 || fnamecmp(p, "sh.exe") == 0
3881 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003882 || fnamecmp(p, "mksh.exe") == 0
3883 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003885 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886 || fnamecmp(p, "bash.exe") == 0
3887 || fnamecmp(p, "cmd.exe") == 0
3888# endif
3889 )
3890# endif
3891 {
3892#if defined(FEAT_QUICKFIX)
3893 if (do_sp)
3894 {
3895# ifdef WIN3264
3896 p_sp = (char_u *)">%s 2>&1";
3897# else
3898 p_sp = (char_u *)"2>&1| tee";
3899# endif
3900 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3901 }
3902#endif
3903 if (do_srr)
3904 {
3905 p_srr = (char_u *)">%s 2>&1";
3906 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3907 }
3908 }
3909 vim_free(p);
3910 }
3911#endif
3912
3913#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3914 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003915 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3916 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 * This is done after other initializations, where 'shell' might have been
3918 * set, but only if they have not been set before. Default for p_shcf is
3919 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3920 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3921 * command.com. And for Win32 we need to set p_sxq instead.
3922 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003923 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 {
3925 int idx3;
3926
3927 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003928 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929 {
3930 p_shcf = (char_u *)"-c";
3931 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3932 }
3933
3934# ifndef DJGPP
3935# ifdef WIN3264
3936 /* Somehow Win32 requires the quotes around the redirection too */
3937 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003938 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 {
3940 p_sxq = (char_u *)"\"";
3941 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3942 }
3943# else
3944 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003945 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946 {
3947 p_shq = (char_u *)"\"";
3948 options[idx3].def_val[VI_DEFAULT] = p_shq;
3949 }
3950# endif
3951# endif
3952 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003953 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3954 {
3955 int idx3;
3956
3957 /*
3958 * cmd.exe on Windows will strip the first and last double quote given
3959 * on the command line, e.g. most of the time things like:
3960 * cmd /c "my path/to/echo" "my args to echo"
3961 * become:
3962 * my path/to/echo" "my args to echo
3963 * when executed.
3964 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003965 * To avoid this, set shellxquote to surround the command in
3966 * parenthesis. This appears to make most commands work, without
3967 * breaking commands that worked previously, such as
3968 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003969 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003970 idx3 = findoption((char_u *)"sxq");
3971 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3972 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003973 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003974 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3975 }
3976
Bram Moolenaara64ba222012-02-12 23:23:31 +01003977 idx3 = findoption((char_u *)"shcf");
3978 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3979 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003980 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003981 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3982 }
3983 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984#endif
3985
3986#ifdef FEAT_TITLE
3987 set_title_defaults();
3988#endif
3989}
3990
3991#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3992/*
3993 * When 'helplang' is still at its default value, set it to "lang".
3994 * Only the first two characters of "lang" are used.
3995 */
3996 void
3997set_helplang_default(lang)
3998 char_u *lang;
3999{
4000 int idx;
4001
4002 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4003 return;
4004 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004005 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004006 {
4007 if (options[idx].flags & P_ALLOCED)
4008 free_string_option(p_hlg);
4009 p_hlg = vim_strsave(lang);
4010 if (p_hlg == NULL)
4011 p_hlg = empty_option;
4012 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004013 {
4014 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4015 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4016 {
4017 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4018 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4019 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022 options[idx].flags |= P_ALLOCED;
4023 }
4024}
4025#endif
4026
4027#ifdef FEAT_GUI
4028static char_u *gui_bg_default __ARGS((void));
4029
4030 static char_u *
4031gui_bg_default()
4032{
4033 if (gui_get_lightness(gui.back_pixel) < 127)
4034 return (char_u *)"dark";
4035 return (char_u *)"light";
4036}
4037
4038/*
4039 * Option initializations that can only be done after opening the GUI window.
4040 */
4041 void
4042init_gui_options()
4043{
4044 /* Set the 'background' option according to the lightness of the
4045 * background color, unless the user has set it already. */
4046 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4047 {
4048 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4049 highlight_changed();
4050 }
4051}
4052#endif
4053
4054#ifdef FEAT_TITLE
4055/*
4056 * 'title' and 'icon' only default to true if they have not been set or reset
4057 * in .vimrc and we can read the old value.
4058 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4059 * they can be reset. This reduces startup time when using X on a remote
4060 * machine.
4061 */
4062 void
4063set_title_defaults()
4064{
4065 int idx1;
4066 long val;
4067
4068 /*
4069 * If GUI is (going to be) used, we can always set the window title and
4070 * icon name. Saves a bit of time, because the X11 display server does
4071 * not need to be contacted.
4072 */
4073 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004074 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075 {
4076#ifdef FEAT_GUI
4077 if (gui.starting || gui.in_use)
4078 val = TRUE;
4079 else
4080#endif
4081 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004082 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 p_title = val;
4084 }
4085 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004086 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 {
4088#ifdef FEAT_GUI
4089 if (gui.starting || gui.in_use)
4090 val = TRUE;
4091 else
4092#endif
4093 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004094 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 p_icon = val;
4096 }
4097}
4098#endif
4099
4100/*
4101 * Parse 'arg' for option settings.
4102 *
4103 * 'arg' may be IObuff, but only when no errors can be present and option
4104 * does not need to be expanded with option_expand().
4105 * "opt_flags":
4106 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004107 * OPT_GLOBAL for ":setglobal"
4108 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004110 * OPT_WINONLY to only set window-local options
4111 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 *
4113 * returns FAIL if an error is detected, OK otherwise
4114 */
4115 int
4116do_set(arg, opt_flags)
4117 char_u *arg; /* option string (may be written to!) */
4118 int opt_flags;
4119{
4120 int opt_idx;
4121 char_u *errmsg;
4122 char_u errbuf[80];
4123 char_u *startarg;
4124 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4125 int nextchar; /* next non-white char after option name */
4126 int afterchar; /* character just after option name */
4127 int len;
4128 int i;
4129 long value;
4130 int key;
4131 long_u flags; /* flags for current option */
4132 char_u *varp = NULL; /* pointer to variable for current option */
4133 int did_show = FALSE; /* already showed one value */
4134 int adding; /* "opt+=arg" */
4135 int prepending; /* "opt^=arg" */
4136 int removing; /* "opt-=arg" */
4137 int cp_val = 0;
4138 char_u key_name[2];
4139
4140 if (*arg == NUL)
4141 {
4142 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004143 did_show = TRUE;
4144 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 }
4146
4147 while (*arg != NUL) /* loop to process all options */
4148 {
4149 errmsg = NULL;
4150 startarg = arg; /* remember for error message */
4151
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004152 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4153 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 {
4155 /*
4156 * ":set all" show all options.
4157 * ":set all&" set all options to their default value.
4158 */
4159 arg += 3;
4160 if (*arg == '&')
4161 {
4162 ++arg;
4163 /* Only for :set command set global value of local options. */
4164 set_options_default(OPT_FREE | opt_flags);
4165 }
4166 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004167 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004168 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004169 did_show = TRUE;
4170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004172 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004173 {
4174 showoptions(2, opt_flags);
4175 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004176 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 arg += 7;
4178 }
4179 else
4180 {
4181 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004182 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 {
4184 prefix = 0;
4185 arg += 2;
4186 }
4187 else if (STRNCMP(arg, "inv", 3) == 0)
4188 {
4189 prefix = 2;
4190 arg += 3;
4191 }
4192
4193 /* find end of name */
4194 key = 0;
4195 if (*arg == '<')
4196 {
4197 nextchar = 0;
4198 opt_idx = -1;
4199 /* look out for <t_>;> */
4200 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4201 len = 5;
4202 else
4203 {
4204 len = 1;
4205 while (arg[len] != NUL && arg[len] != '>')
4206 ++len;
4207 }
4208 if (arg[len] != '>')
4209 {
4210 errmsg = e_invarg;
4211 goto skip;
4212 }
4213 arg[len] = NUL; /* put NUL after name */
4214 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4215 opt_idx = findoption(arg + 1);
4216 arg[len++] = '>'; /* restore '>' */
4217 if (opt_idx == -1)
4218 key = find_key_option(arg + 1);
4219 }
4220 else
4221 {
4222 len = 0;
4223 /*
4224 * The two characters after "t_" may not be alphanumeric.
4225 */
4226 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4227 len = 4;
4228 else
4229 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4230 ++len;
4231 nextchar = arg[len];
4232 arg[len] = NUL; /* put NUL after name */
4233 opt_idx = findoption(arg);
4234 arg[len] = nextchar; /* restore nextchar */
4235 if (opt_idx == -1)
4236 key = find_key_option(arg);
4237 }
4238
4239 /* remember character after option name */
4240 afterchar = arg[len];
4241
4242 /* skip white space, allow ":set ai ?" */
4243 while (vim_iswhite(arg[len]))
4244 ++len;
4245
4246 adding = FALSE;
4247 prepending = FALSE;
4248 removing = FALSE;
4249 if (arg[len] != NUL && arg[len + 1] == '=')
4250 {
4251 if (arg[len] == '+')
4252 {
4253 adding = TRUE; /* "+=" */
4254 ++len;
4255 }
4256 else if (arg[len] == '^')
4257 {
4258 prepending = TRUE; /* "^=" */
4259 ++len;
4260 }
4261 else if (arg[len] == '-')
4262 {
4263 removing = TRUE; /* "-=" */
4264 ++len;
4265 }
4266 }
4267 nextchar = arg[len];
4268
4269 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4270 {
4271 errmsg = (char_u *)N_("E518: Unknown option");
4272 goto skip;
4273 }
4274
4275 if (opt_idx >= 0)
4276 {
4277 if (options[opt_idx].var == NULL) /* hidden option: skip */
4278 {
4279 /* Only give an error message when requesting the value of
4280 * a hidden option, ignore setting it. */
4281 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4282 && (!(options[opt_idx].flags & P_BOOL)
4283 || nextchar == '?'))
4284 errmsg = (char_u *)N_("E519: Option not supported");
4285 goto skip;
4286 }
4287
4288 flags = options[opt_idx].flags;
4289 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4290 }
4291 else
4292 {
4293 flags = P_STRING;
4294 if (key < 0)
4295 {
4296 key_name[0] = KEY2TERMCAP0(key);
4297 key_name[1] = KEY2TERMCAP1(key);
4298 }
4299 else
4300 {
4301 key_name[0] = KS_KEY;
4302 key_name[1] = (key & 0xff);
4303 }
4304 }
4305
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004306 /* Skip all options that are not window-local (used when showing
4307 * an already loaded buffer in a window). */
4308 if ((opt_flags & OPT_WINONLY)
4309 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4310 goto skip;
4311
Bram Moolenaara3227e22006-03-08 21:32:40 +00004312 /* Skip all options that are window-local (used for :vimgrep). */
4313 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4314 && options[opt_idx].var == VAR_WIN)
4315 goto skip;
4316
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004317 /* Disallow changing some options from modelines. */
4318 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004319 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004320 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004321 {
4322 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4323 goto skip;
4324 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004325#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004326 /* In diff mode some options are overruled. This avoids that
4327 * 'foldmethod' becomes "marker" instead of "diff" and that
4328 * "wrap" gets set. */
4329 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004330 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004331 && (options[opt_idx].indir == PV_FDM
4332 || options[opt_idx].indir == PV_WRAP))
4333 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004335 }
4336
4337#ifdef HAVE_SANDBOX
4338 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004339 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340 {
4341 errmsg = (char_u *)_(e_sandbox);
4342 goto skip;
4343 }
4344#endif
4345
4346 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4347 {
4348 arg += len;
4349 cp_val = p_cp;
4350 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4351 {
4352 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4353 {
4354 cp_val = FALSE;
4355 arg += 3;
4356 }
4357 else /* "opt&vi": set to Vi default */
4358 {
4359 cp_val = TRUE;
4360 arg += 2;
4361 }
4362 }
4363 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4364 && arg[1] != NUL && !vim_iswhite(arg[1]))
4365 {
4366 errmsg = e_trailing;
4367 goto skip;
4368 }
4369 }
4370
4371 /*
4372 * allow '=' and ':' as MSDOS command.com allows only one
4373 * '=' character per "set" command line. grrr. (jw)
4374 */
4375 if (nextchar == '?'
4376 || (prefix == 1
4377 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4378 && !(flags & P_BOOL)))
4379 {
4380 /*
4381 * print value
4382 */
4383 if (did_show)
4384 msg_putchar('\n'); /* cursor below last one */
4385 else
4386 {
4387 gotocmdline(TRUE); /* cursor at status line */
4388 did_show = TRUE; /* remember that we did a line */
4389 }
4390 if (opt_idx >= 0)
4391 {
4392 showoneopt(&options[opt_idx], opt_flags);
4393#ifdef FEAT_EVAL
4394 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004395 {
4396 /* Mention where the option was last set. */
4397 if (varp == options[opt_idx].var)
4398 last_set_msg(options[opt_idx].scriptID);
4399 else if ((int)options[opt_idx].indir & PV_WIN)
4400 last_set_msg(curwin->w_p_scriptID[
4401 (int)options[opt_idx].indir & PV_MASK]);
4402 else if ((int)options[opt_idx].indir & PV_BUF)
4403 last_set_msg(curbuf->b_p_scriptID[
4404 (int)options[opt_idx].indir & PV_MASK]);
4405 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004406#endif
4407 }
4408 else
4409 {
4410 char_u *p;
4411
4412 p = find_termcode(key_name);
4413 if (p == NULL)
4414 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004415 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004416 goto skip;
4417 }
4418 else
4419 (void)show_one_termcode(key_name, p, TRUE);
4420 }
4421 if (nextchar != '?'
4422 && nextchar != NUL && !vim_iswhite(afterchar))
4423 errmsg = e_trailing;
4424 }
4425 else
4426 {
4427 if (flags & P_BOOL) /* boolean */
4428 {
4429 if (nextchar == '=' || nextchar == ':')
4430 {
4431 errmsg = e_invarg;
4432 goto skip;
4433 }
4434
4435 /*
4436 * ":set opt!": invert
4437 * ":set opt&": reset to default value
4438 * ":set opt<": reset to global value
4439 */
4440 if (nextchar == '!')
4441 value = *(int *)(varp) ^ 1;
4442 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004443 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004444 ((flags & P_VI_DEF) || cp_val)
4445 ? VI_DEFAULT : VIM_DEFAULT];
4446 else if (nextchar == '<')
4447 {
4448 /* For 'autoread' -1 means to use global value. */
4449 if ((int *)varp == &curbuf->b_p_ar
4450 && opt_flags == OPT_LOCAL)
4451 value = -1;
4452 else
4453 value = *(int *)get_varp_scope(&(options[opt_idx]),
4454 OPT_GLOBAL);
4455 }
4456 else
4457 {
4458 /*
4459 * ":set invopt": invert
4460 * ":set opt" or ":set noopt": set or reset
4461 */
4462 if (nextchar != NUL && !vim_iswhite(afterchar))
4463 {
4464 errmsg = e_trailing;
4465 goto skip;
4466 }
4467 if (prefix == 2) /* inv */
4468 value = *(int *)(varp) ^ 1;
4469 else
4470 value = prefix;
4471 }
4472
4473 errmsg = set_bool_option(opt_idx, varp, (int)value,
4474 opt_flags);
4475 }
4476 else /* numeric or string */
4477 {
4478 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4479 || prefix != 1)
4480 {
4481 errmsg = e_invarg;
4482 goto skip;
4483 }
4484
4485 if (flags & P_NUM) /* numeric */
4486 {
4487 /*
4488 * Different ways to set a number option:
4489 * & set to default value
4490 * < set to global value
4491 * <xx> accept special key codes for 'wildchar'
4492 * c accept any non-digit for 'wildchar'
4493 * [-]0-9 set number
4494 * other error
4495 */
4496 ++arg;
4497 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004498 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004499 ((flags & P_VI_DEF) || cp_val)
4500 ? VI_DEFAULT : VIM_DEFAULT];
4501 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004502 {
4503 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4504 * use the global value. */
4505 if ((long *)varp == &curbuf->b_p_ul
4506 && opt_flags == OPT_LOCAL)
4507 value = NO_LOCAL_UNDOLEVEL;
4508 else
4509 value = *(long *)get_varp_scope(
4510 &(options[opt_idx]), OPT_GLOBAL);
4511 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004512 else if (((long *)varp == &p_wc
4513 || (long *)varp == &p_wcm)
4514 && (*arg == '<'
4515 || *arg == '^'
4516 || ((!arg[1] || vim_iswhite(arg[1]))
4517 && !VIM_ISDIGIT(*arg))))
4518 {
4519 value = string_to_key(arg);
4520 if (value == 0 && (long *)varp != &p_wcm)
4521 {
4522 errmsg = e_invarg;
4523 goto skip;
4524 }
4525 }
4526 /* allow negative numbers (for 'undolevels') */
4527 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4528 {
4529 i = 0;
4530 if (*arg == '-')
4531 i = 1;
4532#ifdef HAVE_STRTOL
4533 value = strtol((char *)arg, NULL, 0);
4534 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4535 i += 2;
4536#else
4537 value = atol((char *)arg);
4538#endif
4539 while (VIM_ISDIGIT(arg[i]))
4540 ++i;
4541 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4542 {
4543 errmsg = e_invarg;
4544 goto skip;
4545 }
4546 }
4547 else
4548 {
4549 errmsg = (char_u *)N_("E521: Number required after =");
4550 goto skip;
4551 }
4552
4553 if (adding)
4554 value = *(long *)varp + value;
4555 if (prepending)
4556 value = *(long *)varp * value;
4557 if (removing)
4558 value = *(long *)varp - value;
4559 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004560 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004561 }
4562 else if (opt_idx >= 0) /* string */
4563 {
4564 char_u *save_arg = NULL;
4565 char_u *s = NULL;
4566 char_u *oldval; /* previous value if *varp */
4567 char_u *newval;
4568 char_u *origval;
4569 unsigned newlen;
4570 int comma;
4571 int bs;
4572 int new_value_alloced; /* new string option
4573 was allocated */
4574
4575 /* When using ":set opt=val" for a global option
4576 * with a local value the local value will be
4577 * reset, use the global value here. */
4578 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004579 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004580 varp = options[opt_idx].var;
4581
4582 /* The old value is kept until we are sure that the
4583 * new value is valid. */
4584 oldval = *(char_u **)varp;
4585 if (nextchar == '&') /* set to default val */
4586 {
4587 newval = options[opt_idx].def_val[
4588 ((flags & P_VI_DEF) || cp_val)
4589 ? VI_DEFAULT : VIM_DEFAULT];
4590 if ((char_u **)varp == &p_bg)
4591 {
4592 /* guess the value of 'background' */
4593#ifdef FEAT_GUI
4594 if (gui.in_use)
4595 newval = gui_bg_default();
4596 else
4597#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004598 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004599 }
4600
4601 /* expand environment variables and ~ (since the
4602 * default value was already expanded, only
4603 * required when an environment variable was set
4604 * later */
4605 if (newval == NULL)
4606 newval = empty_option;
4607 else
4608 {
4609 s = option_expand(opt_idx, newval);
4610 if (s == NULL)
4611 s = newval;
4612 newval = vim_strsave(s);
4613 }
4614 new_value_alloced = TRUE;
4615 }
4616 else if (nextchar == '<') /* set to global val */
4617 {
4618 newval = vim_strsave(*(char_u **)get_varp_scope(
4619 &(options[opt_idx]), OPT_GLOBAL));
4620 new_value_alloced = TRUE;
4621 }
4622 else
4623 {
4624 ++arg; /* jump to after the '=' or ':' */
4625
4626 /*
4627 * Set 'keywordprg' to ":help" if an empty
4628 * value was passed to :set by the user.
4629 * Misuse errbuf[] for the resulting string.
4630 */
4631 if (varp == (char_u *)&p_kp
4632 && (*arg == NUL || *arg == ' '))
4633 {
4634 STRCPY(errbuf, ":help");
4635 save_arg = arg;
4636 arg = errbuf;
4637 }
4638 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004639 * Convert 'backspace' number to string, for
4640 * adding, prepending and removing string.
4641 */
4642 else if (varp == (char_u *)&p_bs
4643 && VIM_ISDIGIT(**(char_u **)varp))
4644 {
4645 i = getdigits((char_u **)varp);
4646 switch (i)
4647 {
4648 case 0:
4649 *(char_u **)varp = empty_option;
4650 break;
4651 case 1:
4652 *(char_u **)varp = vim_strsave(
4653 (char_u *)"indent,eol");
4654 break;
4655 case 2:
4656 *(char_u **)varp = vim_strsave(
4657 (char_u *)"indent,eol,start");
4658 break;
4659 }
4660 vim_free(oldval);
4661 oldval = *(char_u **)varp;
4662 }
4663 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004664 * Convert 'whichwrap' number to string, for
4665 * backwards compatibility with Vim 3.0.
4666 * Misuse errbuf[] for the resulting string.
4667 */
4668 else if (varp == (char_u *)&p_ww
4669 && VIM_ISDIGIT(*arg))
4670 {
4671 *errbuf = NUL;
4672 i = getdigits(&arg);
4673 if (i & 1)
4674 STRCAT(errbuf, "b,");
4675 if (i & 2)
4676 STRCAT(errbuf, "s,");
4677 if (i & 4)
4678 STRCAT(errbuf, "h,l,");
4679 if (i & 8)
4680 STRCAT(errbuf, "<,>,");
4681 if (i & 16)
4682 STRCAT(errbuf, "[,],");
4683 if (*errbuf != NUL) /* remove trailing , */
4684 errbuf[STRLEN(errbuf) - 1] = NUL;
4685 save_arg = arg;
4686 arg = errbuf;
4687 }
4688 /*
4689 * Remove '>' before 'dir' and 'bdir', for
4690 * backwards compatibility with version 3.0
4691 */
4692 else if ( *arg == '>'
4693 && (varp == (char_u *)&p_dir
4694 || varp == (char_u *)&p_bdir))
4695 {
4696 ++arg;
4697 }
4698
4699 /* When setting the local value of a global
4700 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004701 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004702 && (opt_flags & OPT_LOCAL))
4703 origval = *(char_u **)get_varp(
4704 &options[opt_idx]);
4705 else
4706 origval = oldval;
4707
4708 /*
4709 * Copy the new string into allocated memory.
4710 * Can't use set_string_option_direct(), because
4711 * we need to remove the backslashes.
4712 */
4713 /* get a bit too much */
4714 newlen = (unsigned)STRLEN(arg) + 1;
4715 if (adding || prepending || removing)
4716 newlen += (unsigned)STRLEN(origval) + 1;
4717 newval = alloc(newlen);
4718 if (newval == NULL) /* out of mem, don't change */
4719 break;
4720 s = newval;
4721
4722 /*
4723 * Copy the string, skip over escaped chars.
4724 * For MS-DOS and WIN32 backslashes before normal
4725 * file name characters are not removed, and keep
4726 * backslash at start, for "\\machine\path", but
4727 * do remove it for "\\\\machine\\path".
4728 * The reverse is found in ExpandOldSetting().
4729 */
4730 while (*arg && !vim_iswhite(*arg))
4731 {
4732 if (*arg == '\\' && arg[1] != NUL
4733#ifdef BACKSLASH_IN_FILENAME
4734 && !((flags & P_EXPAND)
4735 && vim_isfilec(arg[1])
4736 && (arg[1] != '\\'
4737 || (s == newval
4738 && arg[2] != '\\')))
4739#endif
4740 )
4741 ++arg; /* remove backslash */
4742#ifdef FEAT_MBYTE
4743 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004744 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 {
4746 /* copy multibyte char */
4747 mch_memmove(s, arg, (size_t)i);
4748 arg += i;
4749 s += i;
4750 }
4751 else
4752#endif
4753 *s++ = *arg++;
4754 }
4755 *s = NUL;
4756
4757 /*
4758 * Expand environment variables and ~.
4759 * Don't do it when adding without inserting a
4760 * comma.
4761 */
4762 if (!(adding || prepending || removing)
4763 || (flags & P_COMMA))
4764 {
4765 s = option_expand(opt_idx, newval);
4766 if (s != NULL)
4767 {
4768 vim_free(newval);
4769 newlen = (unsigned)STRLEN(s) + 1;
4770 if (adding || prepending || removing)
4771 newlen += (unsigned)STRLEN(origval) + 1;
4772 newval = alloc(newlen);
4773 if (newval == NULL)
4774 break;
4775 STRCPY(newval, s);
4776 }
4777 }
4778
4779 /* locate newval[] in origval[] when removing it
4780 * and when adding to avoid duplicates */
4781 i = 0; /* init for GCC */
4782 if (removing || (flags & P_NODUP))
4783 {
4784 i = (int)STRLEN(newval);
4785 bs = 0;
4786 for (s = origval; *s; ++s)
4787 {
4788 if ((!(flags & P_COMMA)
4789 || s == origval
4790 || (s[-1] == ',' && !(bs & 1)))
4791 && STRNCMP(s, newval, i) == 0
4792 && (!(flags & P_COMMA)
4793 || s[i] == ','
4794 || s[i] == NUL))
4795 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004796 /* Count backslashes. Only a comma with an
4797 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 * recognized as a separator */
4799 if (s > origval && s[-1] == '\\')
4800 ++bs;
4801 else
4802 bs = 0;
4803 }
4804
4805 /* do not add if already there */
4806 if ((adding || prepending) && *s)
4807 {
4808 prepending = FALSE;
4809 adding = FALSE;
4810 STRCPY(newval, origval);
4811 }
4812 }
4813
4814 /* concatenate the two strings; add a ',' if
4815 * needed */
4816 if (adding || prepending)
4817 {
4818 comma = ((flags & P_COMMA) && *origval != NUL
4819 && *newval != NUL);
4820 if (adding)
4821 {
4822 i = (int)STRLEN(origval);
4823 mch_memmove(newval + i + comma, newval,
4824 STRLEN(newval) + 1);
4825 mch_memmove(newval, origval, (size_t)i);
4826 }
4827 else
4828 {
4829 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004830 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004831 }
4832 if (comma)
4833 newval[i] = ',';
4834 }
4835
4836 /* Remove newval[] from origval[]. (Note: "i" has
4837 * been set above and is used here). */
4838 if (removing)
4839 {
4840 STRCPY(newval, origval);
4841 if (*s)
4842 {
4843 /* may need to remove a comma */
4844 if (flags & P_COMMA)
4845 {
4846 if (s == origval)
4847 {
4848 /* include comma after string */
4849 if (s[i] == ',')
4850 ++i;
4851 }
4852 else
4853 {
4854 /* include comma before string */
4855 --s;
4856 ++i;
4857 }
4858 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004859 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 }
4861 }
4862
4863 if (flags & P_FLAGLIST)
4864 {
4865 /* Remove flags that appear twice. */
4866 for (s = newval; *s; ++s)
4867 if ((!(flags & P_COMMA) || *s != ',')
4868 && vim_strchr(s + 1, *s) != NULL)
4869 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004870 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004871 --s;
4872 }
4873 }
4874
4875 if (save_arg != NULL) /* number for 'whichwrap' */
4876 arg = save_arg;
4877 new_value_alloced = TRUE;
4878 }
4879
4880 /* Set the new value. */
4881 *(char_u **)(varp) = newval;
4882
4883 /* Handle side effects, and set the global value for
4884 * ":set" on local options. */
4885 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4886 new_value_alloced, oldval, errbuf, opt_flags);
4887
4888 /* If error detected, print the error message. */
4889 if (errmsg != NULL)
4890 goto skip;
4891 }
4892 else /* key code option */
4893 {
4894 char_u *p;
4895
4896 if (nextchar == '&')
4897 {
4898 if (add_termcap_entry(key_name, TRUE) == FAIL)
4899 errmsg = (char_u *)N_("E522: Not found in termcap");
4900 }
4901 else
4902 {
4903 ++arg; /* jump to after the '=' or ':' */
4904 for (p = arg; *p && !vim_iswhite(*p); ++p)
4905 if (*p == '\\' && p[1] != NUL)
4906 ++p;
4907 nextchar = *p;
4908 *p = NUL;
4909 add_termcode(key_name, arg, FALSE);
4910 *p = nextchar;
4911 }
4912 if (full_screen)
4913 ttest(FALSE);
4914 redraw_all_later(CLEAR);
4915 }
4916 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004917
Bram Moolenaar071d4272004-06-13 20:20:40 +00004918 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004919 did_set_option(opt_idx, opt_flags,
4920 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004921 }
4922
4923skip:
4924 /*
4925 * Advance to next argument.
4926 * - skip until a blank found, taking care of backslashes
4927 * - skip blanks
4928 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4929 */
4930 for (i = 0; i < 2 ; ++i)
4931 {
4932 while (*arg != NUL && !vim_iswhite(*arg))
4933 if (*arg++ == '\\' && *arg != NUL)
4934 ++arg;
4935 arg = skipwhite(arg);
4936 if (*arg != '=')
4937 break;
4938 }
4939 }
4940
4941 if (errmsg != NULL)
4942 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004943 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004944 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004945 if (i + (arg - startarg) < IOSIZE)
4946 {
4947 /* append the argument with the error */
4948 STRCAT(IObuff, ": ");
4949 mch_memmove(IObuff + i, startarg, (arg - startarg));
4950 IObuff[i + (arg - startarg)] = NUL;
4951 }
4952 /* make sure all characters are printable */
4953 trans_characters(IObuff, IOSIZE);
4954
4955 ++no_wait_return; /* wait_return done later */
4956 emsg(IObuff); /* show error highlighted */
4957 --no_wait_return;
4958
4959 return FAIL;
4960 }
4961
4962 arg = skipwhite(arg);
4963 }
4964
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004965theend:
4966 if (silent_mode && did_show)
4967 {
4968 /* After displaying option values in silent mode. */
4969 silent_mode = FALSE;
4970 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4971 msg_putchar('\n');
4972 cursor_on(); /* msg_start() switches it off */
4973 out_flush();
4974 silent_mode = TRUE;
4975 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4976 }
4977
Bram Moolenaar071d4272004-06-13 20:20:40 +00004978 return OK;
4979}
4980
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004981/*
4982 * Call this when an option has been given a new value through a user command.
4983 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4984 */
4985 static void
4986did_set_option(opt_idx, opt_flags, new_value)
4987 int opt_idx;
4988 int opt_flags; /* possibly with OPT_MODELINE */
4989 int new_value; /* value was replaced completely */
4990{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004991 long_u *p;
4992
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004993 options[opt_idx].flags |= P_WAS_SET;
4994
4995 /* When an option is set in the sandbox, from a modeline or in secure mode
4996 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004997 * flag. */
4998 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004999 if (secure
5000#ifdef HAVE_SANDBOX
5001 || sandbox != 0
5002#endif
5003 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005004 *p = *p | P_INSECURE;
5005 else if (new_value)
5006 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005007}
5008
Bram Moolenaar071d4272004-06-13 20:20:40 +00005009 static char_u *
5010illegal_char(errbuf, c)
5011 char_u *errbuf;
5012 int c;
5013{
5014 if (errbuf == NULL)
5015 return (char_u *)"";
5016 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005017 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005018 return errbuf;
5019}
5020
5021/*
5022 * Convert a key name or string into a key value.
5023 * Used for 'wildchar' and 'cedit' options.
5024 */
5025 static int
5026string_to_key(arg)
5027 char_u *arg;
5028{
5029 if (*arg == '<')
5030 return find_key_option(arg + 1);
5031 if (*arg == '^')
5032 return Ctrl_chr(arg[1]);
5033 return *arg;
5034}
5035
5036#ifdef FEAT_CMDWIN
5037/*
5038 * Check value of 'cedit' and set cedit_key.
5039 * Returns NULL if value is OK, error message otherwise.
5040 */
5041 static char_u *
5042check_cedit()
5043{
5044 int n;
5045
5046 if (*p_cedit == NUL)
5047 cedit_key = -1;
5048 else
5049 {
5050 n = string_to_key(p_cedit);
5051 if (vim_isprintc(n))
5052 return e_invarg;
5053 cedit_key = n;
5054 }
5055 return NULL;
5056}
5057#endif
5058
5059#ifdef FEAT_TITLE
5060/*
5061 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5062 * maketitle() to create and display it.
5063 * When switching the title or icon off, call mch_restore_title() to get
5064 * the old value back.
5065 */
5066 static void
5067did_set_title(icon)
5068 int icon; /* Did set icon instead of title */
5069{
5070 if (starting != NO_SCREEN
5071#ifdef FEAT_GUI
5072 && !gui.starting
5073#endif
5074 )
5075 {
5076 maketitle();
5077 if (icon)
5078 {
5079 if (!p_icon)
5080 mch_restore_title(2);
5081 }
5082 else
5083 {
5084 if (!p_title)
5085 mch_restore_title(1);
5086 }
5087 }
5088}
5089#endif
5090
5091/*
5092 * set_options_bin - called when 'bin' changes value.
5093 */
5094 void
5095set_options_bin(oldval, newval, opt_flags)
5096 int oldval;
5097 int newval;
5098 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5099{
5100 /*
5101 * The option values that are changed when 'bin' changes are
5102 * copied when 'bin is set and restored when 'bin' is reset.
5103 */
5104 if (newval)
5105 {
5106 if (!oldval) /* switched on */
5107 {
5108 if (!(opt_flags & OPT_GLOBAL))
5109 {
5110 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5111 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5112 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5113 curbuf->b_p_et_nobin = curbuf->b_p_et;
5114 }
5115 if (!(opt_flags & OPT_LOCAL))
5116 {
5117 p_tw_nobin = p_tw;
5118 p_wm_nobin = p_wm;
5119 p_ml_nobin = p_ml;
5120 p_et_nobin = p_et;
5121 }
5122 }
5123
5124 if (!(opt_flags & OPT_GLOBAL))
5125 {
5126 curbuf->b_p_tw = 0; /* no automatic line wrap */
5127 curbuf->b_p_wm = 0; /* no automatic line wrap */
5128 curbuf->b_p_ml = 0; /* no modelines */
5129 curbuf->b_p_et = 0; /* no expandtab */
5130 }
5131 if (!(opt_flags & OPT_LOCAL))
5132 {
5133 p_tw = 0;
5134 p_wm = 0;
5135 p_ml = FALSE;
5136 p_et = FALSE;
5137 p_bin = TRUE; /* needed when called for the "-b" argument */
5138 }
5139 }
5140 else if (oldval) /* switched off */
5141 {
5142 if (!(opt_flags & OPT_GLOBAL))
5143 {
5144 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5145 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5146 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5147 curbuf->b_p_et = curbuf->b_p_et_nobin;
5148 }
5149 if (!(opt_flags & OPT_LOCAL))
5150 {
5151 p_tw = p_tw_nobin;
5152 p_wm = p_wm_nobin;
5153 p_ml = p_ml_nobin;
5154 p_et = p_et_nobin;
5155 }
5156 }
5157}
5158
5159#ifdef FEAT_VIMINFO
5160/*
5161 * Find the parameter represented by the given character (eg ', :, ", or /),
5162 * and return its associated value in the 'viminfo' string.
5163 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005164 * If the parameter is not specified in the string or there is no following
5165 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005166 */
5167 int
5168get_viminfo_parameter(type)
5169 int type;
5170{
5171 char_u *p;
5172
5173 p = find_viminfo_parameter(type);
5174 if (p != NULL && VIM_ISDIGIT(*p))
5175 return atoi((char *)p);
5176 return -1;
5177}
5178
5179/*
5180 * Find the parameter represented by the given character (eg ''', ':', '"', or
5181 * '/') in the 'viminfo' option and return a pointer to the string after it.
5182 * Return NULL if the parameter is not specified in the string.
5183 */
5184 char_u *
5185find_viminfo_parameter(type)
5186 int type;
5187{
5188 char_u *p;
5189
5190 for (p = p_viminfo; *p; ++p)
5191 {
5192 if (*p == type)
5193 return p + 1;
5194 if (*p == 'n') /* 'n' is always the last one */
5195 break;
5196 p = vim_strchr(p, ','); /* skip until next ',' */
5197 if (p == NULL) /* hit the end without finding parameter */
5198 break;
5199 }
5200 return NULL;
5201}
5202#endif
5203
5204/*
5205 * Expand environment variables for some string options.
5206 * These string options cannot be indirect!
5207 * If "val" is NULL expand the current value of the option.
5208 * Return pointer to NameBuff, or NULL when not expanded.
5209 */
5210 static char_u *
5211option_expand(opt_idx, val)
5212 int opt_idx;
5213 char_u *val;
5214{
5215 /* if option doesn't need expansion nothing to do */
5216 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5217 return NULL;
5218
5219 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5220 * expand_env() would truncate the string. */
5221 if (val != NULL && STRLEN(val) > MAXPATHL)
5222 return NULL;
5223
5224 if (val == NULL)
5225 val = *(char_u **)options[opt_idx].var;
5226
5227 /*
5228 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5229 * Escape spaces when expanding 'tags', they are used to separate file
5230 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005231 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005232 */
5233 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005234 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005235#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005236 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5237#endif
5238 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005239 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5240 return NULL;
5241
5242 return NameBuff;
5243}
5244
5245/*
5246 * After setting various option values: recompute variables that depend on
5247 * option values.
5248 */
5249 static void
5250didset_options()
5251{
5252 /* initialize the table for 'iskeyword' et.al. */
5253 (void)init_chartab();
5254
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005255#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005256 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005258 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5259#ifdef FEAT_SESSION
5260 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5261 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5262#endif
5263#ifdef FEAT_FOLDING
5264 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5265#endif
5266 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5267#ifdef FEAT_VIRTUALEDIT
5268 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5269#endif
5270#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5271 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5272#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005273#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005274 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005275 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005276 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005277#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005278#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5279 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5280#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005281#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005282 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5283#endif
5284#ifdef FEAT_CMDWIN
5285 /* set cedit_key */
5286 (void)check_cedit();
5287#endif
5288}
5289
5290/*
5291 * Check for string options that are NULL (normally only termcap options).
5292 */
5293 void
5294check_options()
5295{
5296 int opt_idx;
5297
5298 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5299 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5300 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5301}
5302
5303/*
5304 * Check string options in a buffer for NULL value.
5305 */
5306 void
5307check_buf_options(buf)
5308 buf_T *buf;
5309{
5310#if defined(FEAT_QUICKFIX)
5311 check_string_option(&buf->b_p_bh);
5312 check_string_option(&buf->b_p_bt);
5313#endif
5314#ifdef FEAT_MBYTE
5315 check_string_option(&buf->b_p_fenc);
5316#endif
5317 check_string_option(&buf->b_p_ff);
5318#ifdef FEAT_FIND_ID
5319 check_string_option(&buf->b_p_def);
5320 check_string_option(&buf->b_p_inc);
5321# ifdef FEAT_EVAL
5322 check_string_option(&buf->b_p_inex);
5323# endif
5324#endif
5325#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5326 check_string_option(&buf->b_p_inde);
5327 check_string_option(&buf->b_p_indk);
5328#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005329#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5330 check_string_option(&buf->b_p_bexpr);
5331#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005332#if defined(FEAT_CRYPT)
5333 check_string_option(&buf->b_p_cm);
5334#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005335#if defined(FEAT_EVAL)
5336 check_string_option(&buf->b_p_fex);
5337#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005338#ifdef FEAT_CRYPT
5339 check_string_option(&buf->b_p_key);
5340#endif
5341 check_string_option(&buf->b_p_kp);
5342 check_string_option(&buf->b_p_mps);
5343 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005344 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345 check_string_option(&buf->b_p_isk);
5346#ifdef FEAT_COMMENTS
5347 check_string_option(&buf->b_p_com);
5348#endif
5349#ifdef FEAT_FOLDING
5350 check_string_option(&buf->b_p_cms);
5351#endif
5352 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005353#ifdef FEAT_TEXTOBJ
5354 check_string_option(&buf->b_p_qe);
5355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356#ifdef FEAT_SYN_HL
5357 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005358#endif
5359#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005360 check_string_option(&buf->b_s.b_p_spc);
5361 check_string_option(&buf->b_s.b_p_spf);
5362 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363#endif
5364#ifdef FEAT_SEARCHPATH
5365 check_string_option(&buf->b_p_sua);
5366#endif
5367#ifdef FEAT_CINDENT
5368 check_string_option(&buf->b_p_cink);
5369 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005370 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005371#endif
5372#ifdef FEAT_AUTOCMD
5373 check_string_option(&buf->b_p_ft);
5374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5376 check_string_option(&buf->b_p_cinw);
5377#endif
5378#ifdef FEAT_INS_EXPAND
5379 check_string_option(&buf->b_p_cpt);
5380#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005381#ifdef FEAT_COMPL_FUNC
5382 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005383 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005384#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385#ifdef FEAT_KEYMAP
5386 check_string_option(&buf->b_p_keymap);
5387#endif
5388#ifdef FEAT_QUICKFIX
5389 check_string_option(&buf->b_p_gp);
5390 check_string_option(&buf->b_p_mp);
5391 check_string_option(&buf->b_p_efm);
5392#endif
5393 check_string_option(&buf->b_p_ep);
5394 check_string_option(&buf->b_p_path);
5395 check_string_option(&buf->b_p_tags);
5396#ifdef FEAT_INS_EXPAND
5397 check_string_option(&buf->b_p_dict);
5398 check_string_option(&buf->b_p_tsr);
5399#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005400#ifdef FEAT_LISP
5401 check_string_option(&buf->b_p_lw);
5402#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005403}
5404
5405/*
5406 * Free the string allocated for an option.
5407 * Checks for the string being empty_option. This may happen if we're out of
5408 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5409 * check_options().
5410 * Does NOT check for P_ALLOCED flag!
5411 */
5412 void
5413free_string_option(p)
5414 char_u *p;
5415{
5416 if (p != empty_option)
5417 vim_free(p);
5418}
5419
5420 void
5421clear_string_option(pp)
5422 char_u **pp;
5423{
5424 if (*pp != empty_option)
5425 vim_free(*pp);
5426 *pp = empty_option;
5427}
5428
5429 static void
5430check_string_option(pp)
5431 char_u **pp;
5432{
5433 if (*pp == NULL)
5434 *pp = empty_option;
5435}
5436
5437/*
5438 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5439 */
5440 void
5441set_term_option_alloced(p)
5442 char_u **p;
5443{
5444 int opt_idx;
5445
5446 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5447 if (options[opt_idx].var == (char_u *)p)
5448 {
5449 options[opt_idx].flags |= P_ALLOCED;
5450 return;
5451 }
5452 return; /* cannot happen: didn't find it! */
5453}
5454
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005455#if defined(FEAT_EVAL) || defined(PROTO)
5456/*
5457 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5458 * Return FALSE when it wasn't.
5459 * Return -1 for an unknown option.
5460 */
5461 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005462was_set_insecurely(opt, opt_flags)
5463 char_u *opt;
5464 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005465{
5466 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005467 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005468
5469 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005470 {
5471 flagp = insecure_flag(idx, opt_flags);
5472 return (*flagp & P_INSECURE) != 0;
5473 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005474 EMSG2(_(e_intern2), "was_set_insecurely()");
5475 return -1;
5476}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005477
5478/*
5479 * Get a pointer to the flags used for the P_INSECURE flag of option
5480 * "opt_idx". For some local options a local flags field is used.
5481 */
5482 static long_u *
5483insecure_flag(opt_idx, opt_flags)
5484 int opt_idx;
5485 int opt_flags;
5486{
5487 if (opt_flags & OPT_LOCAL)
5488 switch ((int)options[opt_idx].indir)
5489 {
5490#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005491 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005492#endif
5493#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005494# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005495 case PV_FDE: return &curwin->w_p_fde_flags;
5496 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005497# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005498# ifdef FEAT_BEVAL
5499 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5500# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005501# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005502 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005503# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005504 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005505# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005506 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005507# endif
5508#endif
5509 }
5510
5511 /* Nothing special, return global flags field. */
5512 return &options[opt_idx].flags;
5513}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005514#endif
5515
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005516#ifdef FEAT_TITLE
5517static void redraw_titles __ARGS((void));
5518
5519/*
5520 * Redraw the window title and/or tab page text later.
5521 */
5522static void redraw_titles()
5523{
5524 need_maketitle = TRUE;
5525# ifdef FEAT_WINDOWS
5526 redraw_tabline = TRUE;
5527# endif
5528}
5529#endif
5530
Bram Moolenaar071d4272004-06-13 20:20:40 +00005531/*
5532 * Set a string option to a new value (without checking the effect).
5533 * The string is copied into allocated memory.
5534 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005535 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005536 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537 */
5538 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005539set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540 char_u *name;
5541 int opt_idx;
5542 char_u *val;
5543 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005544 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545{
5546 char_u *s;
5547 char_u **varp;
5548 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005549 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550
Bram Moolenaar89d40322006-08-29 15:30:07 +00005551 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005553 idx = findoption(name);
5554 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005555 {
5556 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005558 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559 }
5560
Bram Moolenaar89d40322006-08-29 15:30:07 +00005561 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562 return;
5563
5564 s = vim_strsave(val);
5565 if (s != NULL)
5566 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005567 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005569 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570 free_string_option(*varp);
5571 *varp = s;
5572
5573 /* For buffer/window local option may also set the global value. */
5574 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005575 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005576
Bram Moolenaar89d40322006-08-29 15:30:07 +00005577 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578
5579 /* When setting both values of a global option with a local value,
5580 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005581 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582 {
5583 free_string_option(*varp);
5584 *varp = empty_option;
5585 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005586# ifdef FEAT_EVAL
5587 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005588 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005589 set_sid == 0 ? current_SID : set_sid);
5590# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591 }
5592}
5593
5594/*
5595 * Set global value for string option when it's a local option.
5596 */
5597 static void
5598set_string_option_global(opt_idx, varp)
5599 int opt_idx; /* option index */
5600 char_u **varp; /* pointer to option variable */
5601{
5602 char_u **p, *s;
5603
5604 /* the global value is always allocated */
5605 if (options[opt_idx].var == VAR_WIN)
5606 p = (char_u **)GLOBAL_WO(varp);
5607 else
5608 p = (char_u **)options[opt_idx].var;
5609 if (options[opt_idx].indir != PV_NONE
5610 && p != varp
5611 && (s = vim_strsave(*varp)) != NULL)
5612 {
5613 free_string_option(*p);
5614 *p = s;
5615 }
5616}
5617
5618/*
5619 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005620 *
5621 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005622 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005623 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624set_string_option(opt_idx, value, opt_flags)
5625 int opt_idx;
5626 char_u *value;
5627 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5628{
5629 char_u *s;
5630 char_u **varp;
5631 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005632 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633
5634 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005635 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636
5637 s = vim_strsave(value);
5638 if (s != NULL)
5639 {
5640 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5641 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005642 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643 ? OPT_GLOBAL : OPT_LOCAL)
5644 : opt_flags);
5645 oldval = *varp;
5646 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005647 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5648 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005649 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005651 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652}
5653
5654/*
5655 * Handle string options that need some action to perform when changed.
5656 * Returns NULL for success, or an error message for an error.
5657 */
5658 static char_u *
5659did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5660 opt_flags)
5661 int opt_idx; /* index in options[] table */
5662 char_u **varp; /* pointer to the option variable */
5663 int new_value_alloced; /* new value was allocated */
5664 char_u *oldval; /* previous value of the option */
5665 char_u *errbuf; /* buffer for errors, or NULL */
5666 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5667{
5668 char_u *errmsg = NULL;
5669 char_u *s, *p;
5670 int did_chartab = FALSE;
5671 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005672 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005673#ifdef FEAT_GUI
5674 /* set when changing an option that only requires a redraw in the GUI */
5675 int redraw_gui_only = FALSE;
5676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677
5678 /* Get the global option to compare with, otherwise we would have to check
5679 * two values for all local options. */
5680 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5681
5682 /* Disallow changing some options from secure mode */
5683 if ((secure
5684#ifdef HAVE_SANDBOX
5685 || sandbox != 0
5686#endif
5687 ) && (options[opt_idx].flags & P_SECURE))
5688 {
5689 errmsg = e_secure;
5690 }
5691
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005692 /* Check for a "normal" file name in some options. Disallow a path
5693 * separator (slash and/or backslash), wildcards and characters that are
5694 * often illegal in a file name. */
5695 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005696 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005697 {
5698 errmsg = e_invarg;
5699 }
5700
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 /* 'term' */
5702 else if (varp == &T_NAME)
5703 {
5704 if (T_NAME[0] == NUL)
5705 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5706#ifdef FEAT_GUI
5707 if (gui.in_use)
5708 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5709 else if (term_is_gui(T_NAME))
5710 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5711#endif
5712 else if (set_termname(T_NAME) == FAIL)
5713 errmsg = (char_u *)N_("E522: Not found in termcap");
5714 else
5715 /* Screen colors may have changed. */
5716 redraw_later_clear();
5717 }
5718
5719 /* 'backupcopy' */
5720 else if (varp == &p_bkc)
5721 {
5722 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5723 errmsg = e_invarg;
5724 if (((bkc_flags & BKC_AUTO) != 0)
5725 + ((bkc_flags & BKC_YES) != 0)
5726 + ((bkc_flags & BKC_NO) != 0) != 1)
5727 {
5728 /* Must have exactly one of "auto", "yes" and "no". */
5729 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5730 errmsg = e_invarg;
5731 }
5732 }
5733
5734 /* 'backupext' and 'patchmode' */
5735 else if (varp == &p_bex || varp == &p_pm)
5736 {
5737 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5738 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5739 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5740 }
5741
5742 /*
5743 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5744 * If the new option is invalid, use old value. 'lisp' option: refill
5745 * chartab[] for '-' char
5746 */
5747 else if ( varp == &p_isi
5748 || varp == &(curbuf->b_p_isk)
5749 || varp == &p_isp
5750 || varp == &p_isf)
5751 {
5752 if (init_chartab() == FAIL)
5753 {
5754 did_chartab = TRUE; /* need to restore it below */
5755 errmsg = e_invarg; /* error in value */
5756 }
5757 }
5758
5759 /* 'helpfile' */
5760 else if (varp == &p_hf)
5761 {
5762 /* May compute new values for $VIM and $VIMRUNTIME */
5763 if (didset_vim)
5764 {
5765 vim_setenv((char_u *)"VIM", (char_u *)"");
5766 didset_vim = FALSE;
5767 }
5768 if (didset_vimruntime)
5769 {
5770 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5771 didset_vimruntime = FALSE;
5772 }
5773 }
5774
Bram Moolenaar1a384422010-07-14 19:53:30 +02005775#ifdef FEAT_SYN_HL
5776 /* 'colorcolumn' */
5777 else if (varp == &curwin->w_p_cc)
5778 errmsg = check_colorcolumn(curwin);
5779#endif
5780
Bram Moolenaar071d4272004-06-13 20:20:40 +00005781#ifdef FEAT_MULTI_LANG
5782 /* 'helplang' */
5783 else if (varp == &p_hlg)
5784 {
5785 /* Check for "", "ab", "ab,cd", etc. */
5786 for (s = p_hlg; *s != NUL; s += 3)
5787 {
5788 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5789 {
5790 errmsg = e_invarg;
5791 break;
5792 }
5793 if (s[2] == NUL)
5794 break;
5795 }
5796 }
5797#endif
5798
5799 /* 'highlight' */
5800 else if (varp == &p_hl)
5801 {
5802 if (highlight_changed() == FAIL)
5803 errmsg = e_invarg; /* invalid flags */
5804 }
5805
5806 /* 'nrformats' */
5807 else if (gvarp == &p_nf)
5808 {
5809 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5810 errmsg = e_invarg;
5811 }
5812
5813#ifdef FEAT_SESSION
5814 /* 'sessionoptions' */
5815 else if (varp == &p_ssop)
5816 {
5817 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5818 errmsg = e_invarg;
5819 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5820 {
5821 /* Don't allow both "sesdir" and "curdir". */
5822 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5823 errmsg = e_invarg;
5824 }
5825 }
5826 /* 'viewoptions' */
5827 else if (varp == &p_vop)
5828 {
5829 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5830 errmsg = e_invarg;
5831 }
5832#endif
5833
5834 /* 'scrollopt' */
5835#ifdef FEAT_SCROLLBIND
5836 else if (varp == &p_sbo)
5837 {
5838 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5839 errmsg = e_invarg;
5840 }
5841#endif
5842
5843 /* 'ambiwidth' */
5844#ifdef FEAT_MBYTE
5845 else if (varp == &p_ambw)
5846 {
5847 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5848 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005849 else if (set_chars_option(&p_lcs) != NULL)
5850 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5851# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5852 else if (set_chars_option(&p_fcs) != NULL)
5853 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5854# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005855 }
5856#endif
5857
5858 /* 'background' */
5859 else if (varp == &p_bg)
5860 {
5861 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5862 {
5863#ifdef FEAT_EVAL
5864 int dark = (*p_bg == 'd');
5865#endif
5866
5867 init_highlight(FALSE, FALSE);
5868
5869#ifdef FEAT_EVAL
5870 if (dark != (*p_bg == 'd')
5871 && get_var_value((char_u *)"g:colors_name") != NULL)
5872 {
5873 /* The color scheme must have set 'background' back to another
5874 * value, that's not what we want here. Disable the color
5875 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005876 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005877 free_string_option(p_bg);
5878 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5879 check_string_option(&p_bg);
5880 init_highlight(FALSE, FALSE);
5881 }
5882#endif
5883 }
5884 else
5885 errmsg = e_invarg;
5886 }
5887
5888 /* 'wildmode' */
5889 else if (varp == &p_wim)
5890 {
5891 if (check_opt_wim() == FAIL)
5892 errmsg = e_invarg;
5893 }
5894
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005895#ifdef FEAT_CMDL_COMPL
5896 /* 'wildoptions' */
5897 else if (varp == &p_wop)
5898 {
5899 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5900 errmsg = e_invarg;
5901 }
5902#endif
5903
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904#ifdef FEAT_WAK
5905 /* 'winaltkeys' */
5906 else if (varp == &p_wak)
5907 {
5908 if (*p_wak == NUL
5909 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5910 errmsg = e_invarg;
5911# ifdef FEAT_MENU
5912# ifdef FEAT_GUI_MOTIF
5913 else if (gui.in_use)
5914 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5915# else
5916# ifdef FEAT_GUI_GTK
5917 else if (gui.in_use)
5918 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5919# endif
5920# endif
5921# endif
5922 }
5923#endif
5924
5925#ifdef FEAT_AUTOCMD
5926 /* 'eventignore' */
5927 else if (varp == &p_ei)
5928 {
5929 if (check_ei() == FAIL)
5930 errmsg = e_invarg;
5931 }
5932#endif
5933
5934#ifdef FEAT_MBYTE
5935 /* 'encoding' and 'fileencoding' */
5936 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5937 {
5938 if (gvarp == &p_fenc)
5939 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005940 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941 errmsg = e_modifiable;
5942 else if (vim_strchr(*varp, ',') != NULL)
5943 /* No comma allowed in 'fileencoding'; catches confusing it
5944 * with 'fileencodings'. */
5945 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005947 {
5948# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005949 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005950 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005951# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005952 /* Add 'fileencoding' to the swap file. */
5953 ml_setflags(curbuf);
5954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955 }
5956 if (errmsg == NULL)
5957 {
5958 /* canonize the value, so that STRCMP() can be used on it */
5959 p = enc_canonize(*varp);
5960 if (p != NULL)
5961 {
5962 vim_free(*varp);
5963 *varp = p;
5964 }
5965 if (varp == &p_enc)
5966 {
5967 errmsg = mb_init();
5968# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005969 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005970# endif
5971 }
5972 }
5973
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005974# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5976 {
5977 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5978 if (STRCMP(p_tenc, "utf-8") != 0)
5979 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5980 }
5981# endif
5982
5983 if (errmsg == NULL)
5984 {
5985# ifdef FEAT_KEYMAP
5986 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5987 * (with another encoding). */
5988 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5989 (void)keymap_init();
5990# endif
5991
5992 /* When 'termencoding' is not empty and 'encoding' changes or when
5993 * 'termencoding' changes, need to setup for keyboard input and
5994 * display output conversion. */
5995 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
5996 {
5997 convert_setup(&input_conv, p_tenc, p_enc);
5998 convert_setup(&output_conv, p_enc, p_tenc);
5999 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006000
6001# if defined(WIN3264) && defined(FEAT_MBYTE)
6002 /* $HOME may have characters in active code page. */
6003 if (varp == &p_enc)
6004 init_homedir();
6005# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006 }
6007 }
6008#endif
6009
6010#if defined(FEAT_POSTSCRIPT)
6011 else if (varp == &p_penc)
6012 {
6013 /* Canonize printencoding if VIM standard one */
6014 p = enc_canonize(p_penc);
6015 if (p != NULL)
6016 {
6017 vim_free(p_penc);
6018 p_penc = p;
6019 }
6020 else
6021 {
6022 /* Ensure lower case and '-' for '_' */
6023 for (s = p_penc; *s != NUL; s++)
6024 {
6025 if (*s == '_')
6026 *s = '-';
6027 else
6028 *s = TOLOWER_ASC(*s);
6029 }
6030 }
6031 }
6032#endif
6033
Bram Moolenaar9372a112005-12-06 19:59:18 +00006034#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006035 else if (varp == &p_imak)
6036 {
6037 if (gui.in_use && !im_xim_isvalid_imactivate())
6038 errmsg = e_invarg;
6039 }
6040#endif
6041
6042#ifdef FEAT_KEYMAP
6043 else if (varp == &curbuf->b_p_keymap)
6044 {
6045 /* load or unload key mapping tables */
6046 errmsg = keymap_init();
6047
Bram Moolenaarfab06232009-03-04 03:13:35 +00006048 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006049 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006050 if (*curbuf->b_p_keymap != NUL)
6051 {
6052 /* Installed a new keymap, switch on using it. */
6053 curbuf->b_p_iminsert = B_IMODE_LMAP;
6054 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6055 curbuf->b_p_imsearch = B_IMODE_LMAP;
6056 }
6057 else
6058 {
6059 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6060 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6061 curbuf->b_p_iminsert = B_IMODE_NONE;
6062 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6063 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6064 }
6065 if ((opt_flags & OPT_LOCAL) == 0)
6066 {
6067 set_iminsert_global();
6068 set_imsearch_global();
6069 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070# ifdef FEAT_WINDOWS
6071 status_redraw_curbuf();
6072# endif
6073 }
6074 }
6075#endif
6076
6077 /* 'fileformat' */
6078 else if (gvarp == &p_ff)
6079 {
6080 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6081 errmsg = e_modifiable;
6082 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6083 errmsg = e_invarg;
6084 else
6085 {
6086 /* may also change 'textmode' */
6087 if (get_fileformat(curbuf) == EOL_DOS)
6088 curbuf->b_p_tx = TRUE;
6089 else
6090 curbuf->b_p_tx = FALSE;
6091#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006092 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006093#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006094 /* update flag in swap file */
6095 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006096 /* Redraw needed when switching to/from "mac": a CR in the text
6097 * will be displayed differently. */
6098 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6099 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100 }
6101 }
6102
6103 /* 'fileformats' */
6104 else if (varp == &p_ffs)
6105 {
6106 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6107 errmsg = e_invarg;
6108 else
6109 {
6110 /* also change 'textauto' */
6111 if (*p_ffs == NUL)
6112 p_ta = FALSE;
6113 else
6114 p_ta = TRUE;
6115 }
6116 }
6117
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006118#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 /* 'cryptkey' */
6120 else if (gvarp == &p_key)
6121 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006122# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 /* Make sure the ":set" command doesn't show the new value in the
6124 * history. */
6125 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006126# endif
6127 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6128 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006129 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6130 }
6131
6132 else if (gvarp == &p_cm)
6133 {
6134 if (opt_flags & OPT_LOCAL)
6135 p = curbuf->b_p_cm;
6136 else
6137 p = p_cm;
6138 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6139 errmsg = e_invarg;
6140 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6141 errmsg = e_invarg;
6142 else
6143 {
6144 /* When setting the global value to empty, make it "zip". */
6145 if (*p_cm == NUL)
6146 {
6147 if (new_value_alloced)
6148 free_string_option(p_cm);
6149 p_cm = vim_strsave((char_u *)"zip");
6150 new_value_alloced = TRUE;
6151 }
6152
6153 /* Need to update the swapfile when the effective method changed.
6154 * Set "s" to the effective old value, "p" to the effective new
6155 * method and compare. */
6156 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6157 s = p_cm; /* was previously using the global value */
6158 else
6159 s = oldval;
6160 if (*curbuf->b_p_cm == NUL)
6161 p = p_cm; /* is now using the global value */
6162 else
6163 p = curbuf->b_p_cm;
6164 if (STRCMP(s, p) != 0)
6165 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6166 crypt_method_from_string(s));
6167
6168 /* If the global value changes need to update the swapfile for all
6169 * buffers using that value. */
6170 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6171 {
6172 buf_T *buf;
6173
6174 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6175 if (buf != curbuf && *buf->b_p_cm == NUL)
6176 ml_set_crypt_key(buf, buf->b_p_key,
6177 crypt_method_from_string(oldval));
6178 }
6179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006180 }
6181#endif
6182
6183 /* 'matchpairs' */
6184 else if (gvarp == &p_mps)
6185 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006186#ifdef FEAT_MBYTE
6187 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006189 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006190 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006191 int x2 = -1;
6192 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006193
6194 if (*p != NUL)
6195 p += mb_ptr2len(p);
6196 if (*p != NUL)
6197 x2 = *p++;
6198 if (*p != NUL)
6199 {
6200 x3 = mb_ptr2char(p);
6201 p += mb_ptr2len(p);
6202 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006203 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006204 {
6205 errmsg = e_invarg;
6206 break;
6207 }
6208 if (*p == NUL)
6209 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006210 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006211 }
6212 else
6213#endif
6214 {
6215 /* Check for "x:y,x:y" */
6216 for (p = *varp; *p != NUL; p += 4)
6217 {
6218 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6219 {
6220 errmsg = e_invarg;
6221 break;
6222 }
6223 if (p[3] == NUL)
6224 break;
6225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006226 }
6227 }
6228
6229#ifdef FEAT_COMMENTS
6230 /* 'comments' */
6231 else if (gvarp == &p_com)
6232 {
6233 for (s = *varp; *s; )
6234 {
6235 while (*s && *s != ':')
6236 {
6237 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6238 && !VIM_ISDIGIT(*s) && *s != '-')
6239 {
6240 errmsg = illegal_char(errbuf, *s);
6241 break;
6242 }
6243 ++s;
6244 }
6245 if (*s++ == NUL)
6246 errmsg = (char_u *)N_("E524: Missing colon");
6247 else if (*s == ',' || *s == NUL)
6248 errmsg = (char_u *)N_("E525: Zero length string");
6249 if (errmsg != NULL)
6250 break;
6251 while (*s && *s != ',')
6252 {
6253 if (*s == '\\' && s[1] != NUL)
6254 ++s;
6255 ++s;
6256 }
6257 s = skip_to_option_part(s);
6258 }
6259 }
6260#endif
6261
6262 /* 'listchars' */
6263 else if (varp == &p_lcs)
6264 {
6265 errmsg = set_chars_option(varp);
6266 }
6267
6268#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6269 /* 'fillchars' */
6270 else if (varp == &p_fcs)
6271 {
6272 errmsg = set_chars_option(varp);
6273 }
6274#endif
6275
6276#ifdef FEAT_CMDWIN
6277 /* 'cedit' */
6278 else if (varp == &p_cedit)
6279 {
6280 errmsg = check_cedit();
6281 }
6282#endif
6283
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006284 /* 'verbosefile' */
6285 else if (varp == &p_vfile)
6286 {
6287 verbose_stop();
6288 if (*p_vfile != NUL && verbose_open() == FAIL)
6289 errmsg = e_invarg;
6290 }
6291
Bram Moolenaar071d4272004-06-13 20:20:40 +00006292#ifdef FEAT_VIMINFO
6293 /* 'viminfo' */
6294 else if (varp == &p_viminfo)
6295 {
6296 for (s = p_viminfo; *s;)
6297 {
6298 /* Check it's a valid character */
6299 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6300 {
6301 errmsg = illegal_char(errbuf, *s);
6302 break;
6303 }
6304 if (*s == 'n') /* name is always last one */
6305 {
6306 break;
6307 }
6308 else if (*s == 'r') /* skip until next ',' */
6309 {
6310 while (*++s && *s != ',')
6311 ;
6312 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006313 else if (*s == '%')
6314 {
6315 /* optional number */
6316 while (vim_isdigit(*++s))
6317 ;
6318 }
6319 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006320 ++s; /* no extra chars */
6321 else /* must have a number */
6322 {
6323 while (vim_isdigit(*++s))
6324 ;
6325
6326 if (!VIM_ISDIGIT(*(s - 1)))
6327 {
6328 if (errbuf != NULL)
6329 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006330 sprintf((char *)errbuf,
6331 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006332 transchar_byte(*(s - 1)));
6333 errmsg = errbuf;
6334 }
6335 else
6336 errmsg = (char_u *)"";
6337 break;
6338 }
6339 }
6340 if (*s == ',')
6341 ++s;
6342 else if (*s)
6343 {
6344 if (errbuf != NULL)
6345 errmsg = (char_u *)N_("E527: Missing comma");
6346 else
6347 errmsg = (char_u *)"";
6348 break;
6349 }
6350 }
6351 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6352 errmsg = (char_u *)N_("E528: Must specify a ' value");
6353 }
6354#endif /* FEAT_VIMINFO */
6355
6356 /* terminal options */
6357 else if (istermoption(&options[opt_idx]) && full_screen)
6358 {
6359 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6360 if (varp == &T_CCO)
6361 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006362 int colors = atoi((char *)T_CCO);
6363
6364 /* Only reinitialize colors if t_Co value has really changed to
6365 * avoid expensive reload of colorscheme if t_Co is set to the
6366 * same value multiple times. */
6367 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006368 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006369 t_colors = colors;
6370 if (t_colors <= 1)
6371 {
6372 if (new_value_alloced)
6373 vim_free(T_CCO);
6374 T_CCO = empty_option;
6375 }
6376 /* We now have a different color setup, initialize it again. */
6377 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006378 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 }
6380 ttest(FALSE);
6381 if (varp == &T_ME)
6382 {
6383 out_str(T_ME);
6384 redraw_later(CLEAR);
6385#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6386 /* Since t_me has been set, this probably means that the user
6387 * wants to use this as default colors. Need to reset default
6388 * background/foreground colors. */
6389 mch_set_normal_colors();
6390#endif
6391 }
6392 }
6393
6394#ifdef FEAT_LINEBREAK
6395 /* 'showbreak' */
6396 else if (varp == &p_sbr)
6397 {
6398 for (s = p_sbr; *s; )
6399 {
6400 if (ptr2cells(s) != 1)
6401 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006402 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403 }
6404 }
6405#endif
6406
6407#ifdef FEAT_GUI
6408 /* 'guifont' */
6409 else if (varp == &p_guifont)
6410 {
6411 if (gui.in_use)
6412 {
6413 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006414# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415 /*
6416 * Put up a font dialog and let the user select a new value.
6417 * If this is cancelled go back to the old value but don't
6418 * give an error message.
6419 */
6420 if (STRCMP(p, "*") == 0)
6421 {
6422 p = gui_mch_font_dialog(oldval);
6423
6424 if (new_value_alloced)
6425 free_string_option(p_guifont);
6426
6427 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6428 new_value_alloced = TRUE;
6429 }
6430# endif
6431 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6432 {
6433# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6434 if (STRCMP(p_guifont, "*") == 0)
6435 {
6436 /* Dialog was cancelled: Keep the old value without giving
6437 * an error message. */
6438 if (new_value_alloced)
6439 free_string_option(p_guifont);
6440 p_guifont = vim_strsave(oldval);
6441 new_value_alloced = TRUE;
6442 }
6443 else
6444# endif
6445 errmsg = (char_u *)N_("E596: Invalid font(s)");
6446 }
6447 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006448 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449 }
6450# ifdef FEAT_XFONTSET
6451 else if (varp == &p_guifontset)
6452 {
6453 if (STRCMP(p_guifontset, "*") == 0)
6454 errmsg = (char_u *)N_("E597: can't select fontset");
6455 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6456 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006457 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458 }
6459# endif
6460# ifdef FEAT_MBYTE
6461 else if (varp == &p_guifontwide)
6462 {
6463 if (STRCMP(p_guifontwide, "*") == 0)
6464 errmsg = (char_u *)N_("E533: can't select wide font");
6465 else if (gui_get_wide_font() == FAIL)
6466 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006467 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468 }
6469# endif
6470#endif
6471
6472#ifdef CURSOR_SHAPE
6473 /* 'guicursor' */
6474 else if (varp == &p_guicursor)
6475 errmsg = parse_shape_opt(SHAPE_CURSOR);
6476#endif
6477
6478#ifdef FEAT_MOUSESHAPE
6479 /* 'mouseshape' */
6480 else if (varp == &p_mouseshape)
6481 {
6482 errmsg = parse_shape_opt(SHAPE_MOUSE);
6483 update_mouseshape(-1);
6484 }
6485#endif
6486
6487#ifdef FEAT_PRINTER
6488 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006489 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006490# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006491 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006492 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006493# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006494#endif
6495
6496#ifdef FEAT_LANGMAP
6497 /* 'langmap' */
6498 else if (varp == &p_langmap)
6499 langmap_set();
6500#endif
6501
6502#ifdef FEAT_LINEBREAK
6503 /* 'breakat' */
6504 else if (varp == &p_breakat)
6505 fill_breakat_flags();
6506#endif
6507
6508#ifdef FEAT_TITLE
6509 /* 'titlestring' and 'iconstring' */
6510 else if (varp == &p_titlestring || varp == &p_iconstring)
6511 {
6512# ifdef FEAT_STL_OPT
6513 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6514
6515 /* NULL => statusline syntax */
6516 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6517 stl_syntax |= flagval;
6518 else
6519 stl_syntax &= ~flagval;
6520# endif
6521 did_set_title(varp == &p_iconstring);
6522
6523 }
6524#endif
6525
6526#ifdef FEAT_GUI
6527 /* 'guioptions' */
6528 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006529 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006531 redraw_gui_only = TRUE;
6532 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006533#endif
6534
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006535#if defined(FEAT_GUI_TABLINE)
6536 /* 'guitablabel' */
6537 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006538 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006539 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006540 redraw_gui_only = TRUE;
6541 }
6542 /* 'guitabtooltip' */
6543 else if (varp == &p_gtt)
6544 {
6545 redraw_gui_only = TRUE;
6546 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006547#endif
6548
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6550 /* 'ttymouse' */
6551 else if (varp == &p_ttym)
6552 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006553 /* Switch the mouse off before changing the escape sequences used for
6554 * that. */
6555 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6557 errmsg = e_invarg;
6558 else
6559 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006560 if (termcap_active)
6561 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006562 }
6563#endif
6564
Bram Moolenaar071d4272004-06-13 20:20:40 +00006565 /* 'selection' */
6566 else if (varp == &p_sel)
6567 {
6568 if (*p_sel == NUL
6569 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6570 errmsg = e_invarg;
6571 }
6572
6573 /* 'selectmode' */
6574 else if (varp == &p_slm)
6575 {
6576 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6577 errmsg = e_invarg;
6578 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006579
6580#ifdef FEAT_BROWSE
6581 /* 'browsedir' */
6582 else if (varp == &p_bsdir)
6583 {
6584 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6585 && !mch_isdir(p_bsdir))
6586 errmsg = e_invarg;
6587 }
6588#endif
6589
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 /* 'keymodel' */
6591 else if (varp == &p_km)
6592 {
6593 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6594 errmsg = e_invarg;
6595 else
6596 {
6597 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6598 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6599 }
6600 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601
6602 /* 'mousemodel' */
6603 else if (varp == &p_mousem)
6604 {
6605 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6606 errmsg = e_invarg;
6607#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6608 else if (*p_mousem != *oldval)
6609 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6610 * to create or delete the popup menus. */
6611 gui_motif_update_mousemodel(root_menu);
6612#endif
6613 }
6614
6615 /* 'switchbuf' */
6616 else if (varp == &p_swb)
6617 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006618 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619 errmsg = e_invarg;
6620 }
6621
6622 /* 'debug' */
6623 else if (varp == &p_debug)
6624 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006625 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006626 errmsg = e_invarg;
6627 }
6628
6629 /* 'display' */
6630 else if (varp == &p_dy)
6631 {
6632 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6633 errmsg = e_invarg;
6634 else
6635 (void)init_chartab();
6636
6637 }
6638
6639#ifdef FEAT_VERTSPLIT
6640 /* 'eadirection' */
6641 else if (varp == &p_ead)
6642 {
6643 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6644 errmsg = e_invarg;
6645 }
6646#endif
6647
6648#ifdef FEAT_CLIPBOARD
6649 /* 'clipboard' */
6650 else if (varp == &p_cb)
6651 errmsg = check_clipboard_option();
6652#endif
6653
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006654#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006655 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6656 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006657 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006658 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006659 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006660 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006661
Bram Moolenaar860cae12010-06-05 23:22:07 +02006662 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006663 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006664 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6665 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006666 ".add") != 0))
6667 errmsg = e_invarg;
6668 }
6669
6670 if (errmsg == NULL)
6671 {
6672 FOR_ALL_WINDOWS(wp)
6673 if (wp->w_buffer == curbuf && wp->w_p_spell)
6674 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006675 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006676# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006677 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006678# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006679 }
6680 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006681 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006682 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006683 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006684 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006685 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006686 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006687 /* 'spellsuggest' */
6688 else if (varp == &p_sps)
6689 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006690 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006691 errmsg = e_invarg;
6692 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006693 /* 'mkspellmem' */
6694 else if (varp == &p_msm)
6695 {
6696 if (spell_check_msm() != OK)
6697 errmsg = e_invarg;
6698 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006699#endif
6700
Bram Moolenaar071d4272004-06-13 20:20:40 +00006701#ifdef FEAT_QUICKFIX
6702 /* When 'bufhidden' is set, check for valid value. */
6703 else if (gvarp == &p_bh)
6704 {
6705 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6706 errmsg = e_invarg;
6707 }
6708
6709 /* When 'buftype' is set, check for valid value. */
6710 else if (gvarp == &p_bt)
6711 {
6712 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6713 errmsg = e_invarg;
6714 else
6715 {
6716# ifdef FEAT_WINDOWS
6717 if (curwin->w_status_height)
6718 {
6719 curwin->w_redr_status = TRUE;
6720 redraw_later(VALID);
6721 }
6722# endif
6723 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006724# ifdef FEAT_TITLE
6725 redraw_titles();
6726# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006727 }
6728 }
6729#endif
6730
6731#ifdef FEAT_STL_OPT
6732 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006733 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006734 {
6735 int wid;
6736
6737 if (varp == &p_ruf) /* reset ru_wid first */
6738 ru_wid = 0;
6739 s = *varp;
6740 if (varp == &p_ruf && *s == '%')
6741 {
6742 /* set ru_wid if 'ruf' starts with "%99(" */
6743 if (*++s == '-') /* ignore a '-' */
6744 s++;
6745 wid = getdigits(&s);
6746 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6747 ru_wid = wid;
6748 else
6749 errmsg = check_stl_option(p_ruf);
6750 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006751 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006752 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006754 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755 comp_col();
6756 }
6757#endif
6758
6759#ifdef FEAT_INS_EXPAND
6760 /* check if it is a valid value for 'complete' -- Acevedo */
6761 else if (gvarp == &p_cpt)
6762 {
6763 for (s = *varp; *s;)
6764 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006765 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766 s++;
6767 if (!*s)
6768 break;
6769 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6770 {
6771 errmsg = illegal_char(errbuf, *s);
6772 break;
6773 }
6774 if (*++s != NUL && *s != ',' && *s != ' ')
6775 {
6776 if (s[-1] == 'k' || s[-1] == 's')
6777 {
6778 /* skip optional filename after 'k' and 's' */
6779 while (*s && *s != ',' && *s != ' ')
6780 {
6781 if (*s == '\\')
6782 ++s;
6783 ++s;
6784 }
6785 }
6786 else
6787 {
6788 if (errbuf != NULL)
6789 {
6790 sprintf((char *)errbuf,
6791 _("E535: Illegal character after <%c>"),
6792 *--s);
6793 errmsg = errbuf;
6794 }
6795 else
6796 errmsg = (char_u *)"";
6797 break;
6798 }
6799 }
6800 }
6801 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006802
6803 /* 'completeopt' */
6804 else if (varp == &p_cot)
6805 {
6806 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6807 errmsg = e_invarg;
6808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006809#endif /* FEAT_INS_EXPAND */
6810
6811
6812#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6813 else if (varp == &p_toolbar)
6814 {
6815 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6816 &toolbar_flags, TRUE) != OK)
6817 errmsg = e_invarg;
6818 else
6819 {
6820 out_flush();
6821 gui_mch_show_toolbar((toolbar_flags &
6822 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6823 }
6824 }
6825#endif
6826
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006827#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 /* 'toolbariconsize': GTK+ 2 only */
6829 else if (varp == &p_tbis)
6830 {
6831 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6832 errmsg = e_invarg;
6833 else
6834 {
6835 out_flush();
6836 gui_mch_show_toolbar((toolbar_flags &
6837 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6838 }
6839 }
6840#endif
6841
6842 /* 'pastetoggle': translate key codes like in a mapping */
6843 else if (varp == &p_pt)
6844 {
6845 if (*p_pt)
6846 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006847 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006848 if (p != NULL)
6849 {
6850 if (new_value_alloced)
6851 free_string_option(p_pt);
6852 p_pt = p;
6853 new_value_alloced = TRUE;
6854 }
6855 }
6856 }
6857
6858 /* 'backspace' */
6859 else if (varp == &p_bs)
6860 {
6861 if (VIM_ISDIGIT(*p_bs))
6862 {
6863 if (*p_bs >'2' || p_bs[1] != NUL)
6864 errmsg = e_invarg;
6865 }
6866 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6867 errmsg = e_invarg;
6868 }
6869
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006870#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871 /* 'casemap' */
6872 else if (varp == &p_cmp)
6873 {
6874 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6875 errmsg = e_invarg;
6876 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006877#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006878
6879#ifdef FEAT_DIFF
6880 /* 'diffopt' */
6881 else if (varp == &p_dip)
6882 {
6883 if (diffopt_changed() == FAIL)
6884 errmsg = e_invarg;
6885 }
6886#endif
6887
6888#ifdef FEAT_FOLDING
6889 /* 'foldmethod' */
6890 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6891 {
6892 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6893 || *curwin->w_p_fdm == NUL)
6894 errmsg = e_invarg;
6895 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006896 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006897 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006898 if (foldmethodIsDiff(curwin))
6899 newFoldLevel();
6900 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006901 }
6902# ifdef FEAT_EVAL
6903 /* 'foldexpr' */
6904 else if (varp == &curwin->w_p_fde)
6905 {
6906 if (foldmethodIsExpr(curwin))
6907 foldUpdateAll(curwin);
6908 }
6909# endif
6910 /* 'foldmarker' */
6911 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6912 {
6913 p = vim_strchr(*varp, ',');
6914 if (p == NULL)
6915 errmsg = (char_u *)N_("E536: comma required");
6916 else if (p == *varp || p[1] == NUL)
6917 errmsg = e_invarg;
6918 else if (foldmethodIsMarker(curwin))
6919 foldUpdateAll(curwin);
6920 }
6921 /* 'commentstring' */
6922 else if (gvarp == &p_cms)
6923 {
6924 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6925 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6926 }
6927 /* 'foldopen' */
6928 else if (varp == &p_fdo)
6929 {
6930 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6931 errmsg = e_invarg;
6932 }
6933 /* 'foldclose' */
6934 else if (varp == &p_fcl)
6935 {
6936 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6937 errmsg = e_invarg;
6938 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006939 /* 'foldignore' */
6940 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6941 {
6942 if (foldmethodIsIndent(curwin))
6943 foldUpdateAll(curwin);
6944 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006945#endif
6946
6947#ifdef FEAT_VIRTUALEDIT
6948 /* 'virtualedit' */
6949 else if (varp == &p_ve)
6950 {
6951 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6952 errmsg = e_invarg;
6953 else if (STRCMP(p_ve, oldval) != 0)
6954 {
6955 /* Recompute cursor position in case the new 've' setting
6956 * changes something. */
6957 validate_virtcol();
6958 coladvance(curwin->w_virtcol);
6959 }
6960 }
6961#endif
6962
6963#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6964 else if (varp == &p_csqf)
6965 {
6966 if (p_csqf != NULL)
6967 {
6968 p = p_csqf;
6969 while (*p != NUL)
6970 {
6971 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6972 || p[1] == NUL
6973 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6974 || (p[2] != NUL && p[2] != ','))
6975 {
6976 errmsg = e_invarg;
6977 break;
6978 }
6979 else if (p[2] == NUL)
6980 break;
6981 else
6982 p += 3;
6983 }
6984 }
6985 }
6986#endif
6987
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01006988#ifdef FEAT_CINDENT
6989 /* 'cinoptions' */
6990 else if (gvarp == &p_cino)
6991 {
6992 /* TODO: recognize errors */
6993 parse_cino(curbuf);
6994 }
6995#endif
6996
Bram Moolenaar071d4272004-06-13 20:20:40 +00006997 /* Options that are a list of flags. */
6998 else
6999 {
7000 p = NULL;
7001 if (varp == &p_ww)
7002 p = (char_u *)WW_ALL;
7003 if (varp == &p_shm)
7004 p = (char_u *)SHM_ALL;
7005 else if (varp == &(p_cpo))
7006 p = (char_u *)CPO_ALL;
7007 else if (varp == &(curbuf->b_p_fo))
7008 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007009#ifdef FEAT_CONCEAL
7010 else if (varp == &curwin->w_p_cocu)
7011 p = (char_u *)COCU_ALL;
7012#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013 else if (varp == &p_mouse)
7014 {
7015#ifdef FEAT_MOUSE
7016 p = (char_u *)MOUSE_ALL;
7017#else
7018 if (*p_mouse != NUL)
7019 errmsg = (char_u *)N_("E538: No mouse support");
7020#endif
7021 }
7022#if defined(FEAT_GUI)
7023 else if (varp == &p_go)
7024 p = (char_u *)GO_ALL;
7025#endif
7026 if (p != NULL)
7027 {
7028 for (s = *varp; *s; ++s)
7029 if (vim_strchr(p, *s) == NULL)
7030 {
7031 errmsg = illegal_char(errbuf, *s);
7032 break;
7033 }
7034 }
7035 }
7036
7037 /*
7038 * If error detected, restore the previous value.
7039 */
7040 if (errmsg != NULL)
7041 {
7042 if (new_value_alloced)
7043 free_string_option(*varp);
7044 *varp = oldval;
7045 /*
7046 * When resetting some values, need to act on it.
7047 */
7048 if (did_chartab)
7049 (void)init_chartab();
7050 if (varp == &p_hl)
7051 (void)highlight_changed();
7052 }
7053 else
7054 {
7055#ifdef FEAT_EVAL
7056 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007057 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007058#endif
7059 /*
7060 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007061 * Use "free_oldval", because recursiveness may change the flags under
7062 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007064 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007065 free_string_option(oldval);
7066 if (new_value_alloced)
7067 options[opt_idx].flags |= P_ALLOCED;
7068 else
7069 options[opt_idx].flags &= ~P_ALLOCED;
7070
7071 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007072 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007073 {
7074 /* global option with local value set to use global value; free
7075 * the local value and make it empty */
7076 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7077 free_string_option(*(char_u **)p);
7078 *(char_u **)p = empty_option;
7079 }
7080
7081 /* May set global value for local option. */
7082 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7083 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007084
7085#ifdef FEAT_AUTOCMD
7086 /*
7087 * Trigger the autocommand only after setting the flags.
7088 */
7089# ifdef FEAT_SYN_HL
7090 /* When 'syntax' is set, load the syntax of that name */
7091 if (varp == &(curbuf->b_p_syn))
7092 {
7093 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7094 curbuf->b_fname, TRUE, curbuf);
7095 }
7096# endif
7097 else if (varp == &(curbuf->b_p_ft))
7098 {
7099 /* 'filetype' is set, trigger the FileType autocommand */
7100 did_filetype = TRUE;
7101 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7102 curbuf->b_fname, TRUE, curbuf);
7103 }
7104#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007105#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007106 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007107 {
7108 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007109 char_u *q = curwin->w_s->b_p_spl;
7110
7111 /* Skip the first name if it is "cjk". */
7112 if (STRNCMP(q, "cjk,", 4) == 0)
7113 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007114
7115 /*
7116 * Source the spell/LANG.vim in 'runtimepath'.
7117 * They could set 'spellcapcheck' depending on the language.
7118 * Use the first name in 'spelllang' up to '_region' or
7119 * '.encoding'.
7120 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007121 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007122 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7123 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007124 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007125 source_runtime(fname, TRUE);
7126 }
7127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007128 }
7129
7130#ifdef FEAT_MOUSE
7131 if (varp == &p_mouse)
7132 {
7133# ifdef FEAT_MOUSE_TTY
7134 if (*p_mouse == NUL)
7135 mch_setmouse(FALSE); /* switch mouse off */
7136 else
7137# endif
7138 setmouse(); /* in case 'mouse' changed */
7139 }
7140#endif
7141
Bram Moolenaar913077c2012-03-28 19:59:04 +02007142 if (curwin->w_curswant != MAXCOL
7143 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7144 curwin->w_set_curswant = TRUE;
7145
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007146#ifdef FEAT_GUI
7147 /* check redraw when it's not a GUI option or the GUI is active. */
7148 if (!redraw_gui_only || gui.in_use)
7149#endif
7150 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007151
7152 return errmsg;
7153}
7154
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007155#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007156/*
7157 * Simple int comparison function for use with qsort()
7158 */
7159 static int
7160int_cmp(a, b)
7161 const void *a;
7162 const void *b;
7163{
7164 return *(const int *)a - *(const int *)b;
7165}
7166
7167/*
7168 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7169 * Returns error message, NULL if it's OK.
7170 */
7171 char_u *
7172check_colorcolumn(wp)
7173 win_T *wp;
7174{
7175 char_u *s;
7176 int col;
7177 int count = 0;
7178 int color_cols[256];
7179 int i;
7180 int j = 0;
7181
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007182 if (wp->w_buffer == NULL)
7183 return NULL; /* buffer was closed */
7184
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007185 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007186 {
7187 if (*s == '-' || *s == '+')
7188 {
7189 /* -N and +N: add to 'textwidth' */
7190 col = (*s == '-') ? -1 : 1;
7191 ++s;
7192 if (!VIM_ISDIGIT(*s))
7193 return e_invarg;
7194 col = col * getdigits(&s);
7195 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007196 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007197 col += wp->w_buffer->b_p_tw;
7198 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007199 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007200 }
7201 else if (VIM_ISDIGIT(*s))
7202 col = getdigits(&s);
7203 else
7204 return e_invarg;
7205 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007206skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007207 if (*s == NUL)
7208 break;
7209 if (*s != ',')
7210 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007211 if (*++s == NUL)
7212 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007213 }
7214
7215 vim_free(wp->w_p_cc_cols);
7216 if (count == 0)
7217 wp->w_p_cc_cols = NULL;
7218 else
7219 {
7220 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7221 if (wp->w_p_cc_cols != NULL)
7222 {
7223 /* sort the columns for faster usage on screen redraw inside
7224 * win_line() */
7225 qsort(color_cols, count, sizeof(int), int_cmp);
7226
7227 for (i = 0; i < count; ++i)
7228 /* skip duplicates */
7229 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7230 wp->w_p_cc_cols[j++] = color_cols[i];
7231 wp->w_p_cc_cols[j] = -1; /* end marker */
7232 }
7233 }
7234
7235 return NULL; /* no error */
7236}
7237#endif
7238
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239/*
7240 * Handle setting 'listchars' or 'fillchars'.
7241 * Returns error message, NULL if it's OK.
7242 */
7243 static char_u *
7244set_chars_option(varp)
7245 char_u **varp;
7246{
7247 int round, i, len, entries;
7248 char_u *p, *s;
7249 int c1, c2 = 0;
7250 struct charstab
7251 {
7252 int *cp;
7253 char *name;
7254 };
7255#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7256 static struct charstab filltab[] =
7257 {
7258 {&fill_stl, "stl"},
7259 {&fill_stlnc, "stlnc"},
7260 {&fill_vert, "vert"},
7261 {&fill_fold, "fold"},
7262 {&fill_diff, "diff"},
7263 };
7264#endif
7265 static struct charstab lcstab[] =
7266 {
7267 {&lcs_eol, "eol"},
7268 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007269 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007270 {&lcs_prec, "precedes"},
7271 {&lcs_tab2, "tab"},
7272 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007273#ifdef FEAT_CONCEAL
7274 {&lcs_conceal, "conceal"},
7275#else
7276 {NULL, "conceal"},
7277#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007278 };
7279 struct charstab *tab;
7280
7281#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7282 if (varp == &p_lcs)
7283#endif
7284 {
7285 tab = lcstab;
7286 entries = sizeof(lcstab) / sizeof(struct charstab);
7287 }
7288#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7289 else
7290 {
7291 tab = filltab;
7292 entries = sizeof(filltab) / sizeof(struct charstab);
7293 }
7294#endif
7295
7296 /* first round: check for valid value, second round: assign values */
7297 for (round = 0; round <= 1; ++round)
7298 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007299 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300 {
7301 /* After checking that the value is valid: set defaults: space for
7302 * 'fillchars', NUL for 'listchars' */
7303 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007304 if (tab[i].cp != NULL)
7305 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007306 if (varp == &p_lcs)
7307 lcs_tab1 = NUL;
7308#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7309 else
7310 fill_diff = '-';
7311#endif
7312 }
7313 p = *varp;
7314 while (*p)
7315 {
7316 for (i = 0; i < entries; ++i)
7317 {
7318 len = (int)STRLEN(tab[i].name);
7319 if (STRNCMP(p, tab[i].name, len) == 0
7320 && p[len] == ':'
7321 && p[len + 1] != NUL)
7322 {
7323 s = p + len + 1;
7324#ifdef FEAT_MBYTE
7325 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007326 if (mb_char2cells(c1) > 1)
7327 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007328#else
7329 c1 = *s++;
7330#endif
7331 if (tab[i].cp == &lcs_tab2)
7332 {
7333 if (*s == NUL)
7334 continue;
7335#ifdef FEAT_MBYTE
7336 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007337 if (mb_char2cells(c2) > 1)
7338 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007339#else
7340 c2 = *s++;
7341#endif
7342 }
7343 if (*s == ',' || *s == NUL)
7344 {
7345 if (round)
7346 {
7347 if (tab[i].cp == &lcs_tab2)
7348 {
7349 lcs_tab1 = c1;
7350 lcs_tab2 = c2;
7351 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007352 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007353 *(tab[i].cp) = c1;
7354
7355 }
7356 p = s;
7357 break;
7358 }
7359 }
7360 }
7361
7362 if (i == entries)
7363 return e_invarg;
7364 if (*p == ',')
7365 ++p;
7366 }
7367 }
7368
7369 return NULL; /* no error */
7370}
7371
7372#ifdef FEAT_STL_OPT
7373/*
7374 * Check validity of options with the 'statusline' format.
7375 * Return error message or NULL.
7376 */
7377 char_u *
7378check_stl_option(s)
7379 char_u *s;
7380{
7381 int itemcnt = 0;
7382 int groupdepth = 0;
7383 static char_u errbuf[80];
7384
7385 while (*s && itemcnt < STL_MAX_ITEM)
7386 {
7387 /* Check for valid keys after % sequences */
7388 while (*s && *s != '%')
7389 s++;
7390 if (!*s)
7391 break;
7392 s++;
7393 if (*s != '%' && *s != ')')
7394 ++itemcnt;
7395 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7396 {
7397 s++;
7398 continue;
7399 }
7400 if (*s == ')')
7401 {
7402 s++;
7403 if (--groupdepth < 0)
7404 break;
7405 continue;
7406 }
7407 if (*s == '-')
7408 s++;
7409 while (VIM_ISDIGIT(*s))
7410 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007411 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007412 continue;
7413 if (*s == '.')
7414 {
7415 s++;
7416 while (*s && VIM_ISDIGIT(*s))
7417 s++;
7418 }
7419 if (*s == '(')
7420 {
7421 groupdepth++;
7422 continue;
7423 }
7424 if (vim_strchr(STL_ALL, *s) == NULL)
7425 {
7426 return illegal_char(errbuf, *s);
7427 }
7428 if (*s == '{')
7429 {
7430 s++;
7431 while (*s != '}' && *s)
7432 s++;
7433 if (*s != '}')
7434 return (char_u *)N_("E540: Unclosed expression sequence");
7435 }
7436 }
7437 if (itemcnt >= STL_MAX_ITEM)
7438 return (char_u *)N_("E541: too many items");
7439 if (groupdepth != 0)
7440 return (char_u *)N_("E542: unbalanced groups");
7441 return NULL;
7442}
7443#endif
7444
7445#ifdef FEAT_CLIPBOARD
7446/*
7447 * Extract the items in the 'clipboard' option and set global values.
7448 */
7449 static char_u *
7450check_clipboard_option()
7451{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007452 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007453 int new_autoselect_star = FALSE;
7454 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007455 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007456 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 regprog_T *new_exclude_prog = NULL;
7458 char_u *errmsg = NULL;
7459 char_u *p;
7460
7461 for (p = p_cb; *p != NUL; )
7462 {
7463 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7464 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007465 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007466 p += 7;
7467 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007468 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007469 && (p[11] == ',' || p[11] == NUL))
7470 {
7471 new_unnamed |= CLIP_UNNAMED_PLUS;
7472 p += 11;
7473 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007474 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007475 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007476 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007477 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007478 p += 10;
7479 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007480 else if (STRNCMP(p, "autoselectplus", 14) == 0
7481 && (p[14] == ',' || p[14] == NUL))
7482 {
7483 new_autoselect_plus = TRUE;
7484 p += 14;
7485 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007487 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 {
7489 new_autoselectml = TRUE;
7490 p += 12;
7491 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007492 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7493 {
7494 new_html = TRUE;
7495 p += 4;
7496 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007497 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7498 {
7499 p += 8;
7500 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7501 if (new_exclude_prog == NULL)
7502 errmsg = e_invarg;
7503 break;
7504 }
7505 else
7506 {
7507 errmsg = e_invarg;
7508 break;
7509 }
7510 if (*p == ',')
7511 ++p;
7512 }
7513 if (errmsg == NULL)
7514 {
7515 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007516 clip_autoselect_star = new_autoselect_star;
7517 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007519 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007520 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007522#ifdef FEAT_GUI_GTK
7523 if (gui.in_use)
7524 {
7525 gui_gtk_set_selection_targets();
7526 gui_gtk_set_dnd_targets();
7527 }
7528#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 }
7530 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007531 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007532
7533 return errmsg;
7534}
7535#endif
7536
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007537#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007538/*
7539 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7540 * Return error message when failed, NULL when OK.
7541 */
7542 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007543compile_cap_prog(synblock)
7544 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007545{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007546 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007547 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007548
Bram Moolenaar860cae12010-06-05 23:22:07 +02007549 if (*synblock->b_p_spc == NUL)
7550 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007551 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007552 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007553 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007554 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007555 if (re != NULL)
7556 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007557 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007558 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007559 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007560 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007561 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007562 return e_invarg;
7563 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007564 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007565 }
7566
Bram Moolenaar473de612013-06-08 18:19:48 +02007567 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007568 return NULL;
7569}
7570#endif
7571
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007572#if defined(FEAT_EVAL) || defined(PROTO)
7573/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007574 * Set the scriptID for an option, taking care of setting the buffer- or
7575 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007576 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007577 static void
7578set_option_scriptID_idx(opt_idx, opt_flags, id)
7579 int opt_idx;
7580 int opt_flags;
7581 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007582{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007583 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7584 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007585
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007586 /* Remember where the option was set. For local options need to do that
7587 * in the buffer or window structure. */
7588 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007589 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007590 if (both || (opt_flags & OPT_LOCAL))
7591 {
7592 if (indir & PV_BUF)
7593 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7594 else if (indir & PV_WIN)
7595 curwin->w_p_scriptID[indir & PV_MASK] = id;
7596 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007597}
7598#endif
7599
Bram Moolenaar071d4272004-06-13 20:20:40 +00007600/*
7601 * Set the value of a boolean option, and take care of side effects.
7602 * Returns NULL for success, or an error message for an error.
7603 */
7604 static char_u *
7605set_bool_option(opt_idx, varp, value, opt_flags)
7606 int opt_idx; /* index in options[] table */
7607 char_u *varp; /* pointer to the option variable */
7608 int value; /* new value */
7609 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7610{
7611 int old_value = *(int *)varp;
7612
Bram Moolenaar071d4272004-06-13 20:20:40 +00007613 /* Disallow changing some options from secure mode */
7614 if ((secure
7615#ifdef HAVE_SANDBOX
7616 || sandbox != 0
7617#endif
7618 ) && (options[opt_idx].flags & P_SECURE))
7619 return e_secure;
7620
7621 *(int *)varp = value; /* set the new value */
7622#ifdef FEAT_EVAL
7623 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007624 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007625#endif
7626
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007627#ifdef FEAT_GUI
7628 need_mouse_correct = TRUE;
7629#endif
7630
Bram Moolenaar071d4272004-06-13 20:20:40 +00007631 /* May set global value for local option. */
7632 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7633 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7634
7635 /*
7636 * Handle side effects of changing a bool option.
7637 */
7638
7639 /* 'compatible' */
7640 if ((int *)varp == &p_cp)
7641 {
7642 compatible_set();
7643 }
7644
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007645#ifdef FEAT_PERSISTENT_UNDO
7646 /* 'undofile' */
7647 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7648 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007649 /* Only take action when the option was set. When reset we do not
7650 * delete the undo file, the option may be set again without making
7651 * any changes in between. */
7652 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007653 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007654 char_u hash[UNDO_HASH_SIZE];
7655 buf_T *save_curbuf = curbuf;
7656
7657 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007658 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007659 /* When 'undofile' is set globally: for every buffer, otherwise
7660 * only for the current buffer: Try to read in the undofile,
7661 * if one exists, the buffer wasn't changed and the buffer was
7662 * loaded */
7663 if ((curbuf == save_curbuf
7664 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7665 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7666 {
7667 u_compute_hash(hash);
7668 u_read_undo(NULL, hash, curbuf->b_fname);
7669 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007670 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007671 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007672 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007673 }
7674#endif
7675
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676 else if ((int *)varp == &curbuf->b_p_ro)
7677 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007678 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007679 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7680 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007681
7682 /* when 'readonly' is set may give W10 again */
7683 if (curbuf->b_p_ro)
7684 curbuf->b_did_warn = FALSE;
7685
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007687 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007688#endif
7689 }
7690
Bram Moolenaar9c449722010-07-20 18:44:27 +02007691#ifdef FEAT_GUI
7692 else if ((int *)varp == &p_mh)
7693 {
7694 if (!p_mh)
7695 gui_mch_mousehide(FALSE);
7696 }
7697#endif
7698
Bram Moolenaara539df02010-08-01 14:35:05 +02007699#ifdef FEAT_TITLE
7700 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007701 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007702 {
7703 redraw_titles();
7704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 /* when 'endofline' is changed, redraw the window title */
7706 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007707 {
7708 redraw_titles();
7709 }
7710# ifdef FEAT_MBYTE
7711 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007712 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007713 {
7714 redraw_titles();
7715 }
7716# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007717#endif
7718
7719 /* when 'bin' is set also set some other options */
7720 else if ((int *)varp == &curbuf->b_p_bin)
7721 {
7722 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7723#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007724 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007725#endif
7726 }
7727
7728#ifdef FEAT_AUTOCMD
7729 /* when 'buflisted' changes, trigger autocommands */
7730 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7731 {
7732 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7733 NULL, NULL, TRUE, curbuf);
7734 }
7735#endif
7736
7737 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7738 else if ((int *)varp == &curbuf->b_p_swf)
7739 {
7740 if (curbuf->b_p_swf && p_uc)
7741 ml_open_file(curbuf); /* create the swap file */
7742 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007743 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7744 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007745 mf_close_file(curbuf, TRUE); /* remove the swap file */
7746 }
7747
7748 /* when 'terse' is set change 'shortmess' */
7749 else if ((int *)varp == &p_terse)
7750 {
7751 char_u *p;
7752
7753 p = vim_strchr(p_shm, SHM_SEARCH);
7754
7755 /* insert 's' in p_shm */
7756 if (p_terse && p == NULL)
7757 {
7758 STRCPY(IObuff, p_shm);
7759 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007760 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761 }
7762 /* remove 's' from p_shm */
7763 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007764 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765 }
7766
7767 /* when 'paste' is set or reset also change other options */
7768 else if ((int *)varp == &p_paste)
7769 {
7770 paste_option_changed();
7771 }
7772
7773 /* when 'insertmode' is set from an autocommand need to do work here */
7774 else if ((int *)varp == &p_im)
7775 {
7776 if (p_im)
7777 {
7778 if ((State & INSERT) == 0)
7779 need_start_insertmode = TRUE;
7780 stop_insert_mode = FALSE;
7781 }
7782 else
7783 {
7784 need_start_insertmode = FALSE;
7785 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007786 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787 clear_cmdline = TRUE; /* remove "(insert)" */
7788 restart_edit = 0;
7789 }
7790 }
7791
7792 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7793 else if ((int *)varp == &p_ic && p_hls)
7794 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007795 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007796 }
7797
7798#ifdef FEAT_SEARCH_EXTRA
7799 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7800 else if ((int *)varp == &p_hls)
7801 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007802 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007803 }
7804#endif
7805
7806#ifdef FEAT_SCROLLBIND
7807 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7808 * at the end of normal_cmd() */
7809 else if ((int *)varp == &curwin->w_p_scb)
7810 {
7811 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007812 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007813 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007814 curwin->w_scbind_pos = curwin->w_topline;
7815 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816 }
7817#endif
7818
7819#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7820 /* There can be only one window with 'previewwindow' set. */
7821 else if ((int *)varp == &curwin->w_p_pvw)
7822 {
7823 if (curwin->w_p_pvw)
7824 {
7825 win_T *win;
7826
7827 for (win = firstwin; win != NULL; win = win->w_next)
7828 if (win->w_p_pvw && win != curwin)
7829 {
7830 curwin->w_p_pvw = FALSE;
7831 return (char_u *)N_("E590: A preview window already exists");
7832 }
7833 }
7834 }
7835#endif
7836
7837 /* when 'textmode' is set or reset also change 'fileformat' */
7838 else if ((int *)varp == &curbuf->b_p_tx)
7839 {
7840 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7841 }
7842
7843 /* when 'textauto' is set or reset also change 'fileformats' */
7844 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007845 set_string_option_direct((char_u *)"ffs", -1,
7846 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007847 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848
7849 /*
7850 * When 'lisp' option changes include/exclude '-' in
7851 * keyword characters.
7852 */
7853#ifdef FEAT_LISP
7854 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7855 {
7856 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7857 }
7858#endif
7859
7860#ifdef FEAT_TITLE
7861 /* when 'title' changed, may need to change the title; same for 'icon' */
7862 else if ((int *)varp == &p_title)
7863 {
7864 did_set_title(FALSE);
7865 }
7866
7867 else if ((int *)varp == &p_icon)
7868 {
7869 did_set_title(TRUE);
7870 }
7871#endif
7872
7873 else if ((int *)varp == &curbuf->b_changed)
7874 {
7875 if (!value)
7876 save_file_ff(curbuf); /* Buffer is unchanged */
7877#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007878 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007879#endif
7880#ifdef FEAT_AUTOCMD
7881 modified_was_set = value;
7882#endif
7883 }
7884
7885#ifdef BACKSLASH_IN_FILENAME
7886 else if ((int *)varp == &p_ssl)
7887 {
7888 if (p_ssl)
7889 {
7890 psepc = '/';
7891 psepcN = '\\';
7892 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893 }
7894 else
7895 {
7896 psepc = '\\';
7897 psepcN = '/';
7898 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899 }
7900
7901 /* need to adjust the file name arguments and buffer names. */
7902 buflist_slash_adjust();
7903 alist_slash_adjust();
7904# ifdef FEAT_EVAL
7905 scriptnames_slash_adjust();
7906# endif
7907 }
7908#endif
7909
7910 /* If 'wrap' is set, set w_leftcol to zero. */
7911 else if ((int *)varp == &curwin->w_p_wrap)
7912 {
7913 if (curwin->w_p_wrap)
7914 curwin->w_leftcol = 0;
7915 }
7916
7917#ifdef FEAT_WINDOWS
7918 else if ((int *)varp == &p_ea)
7919 {
7920 if (p_ea && !old_value)
7921 win_equal(curwin, FALSE, 0);
7922 }
7923#endif
7924
7925 else if ((int *)varp == &p_wiv)
7926 {
7927 /*
7928 * When 'weirdinvert' changed, set/reset 't_xs'.
7929 * Then set 'weirdinvert' according to value of 't_xs'.
7930 */
7931 if (p_wiv && !old_value)
7932 T_XS = (char_u *)"y";
7933 else if (!p_wiv && old_value)
7934 T_XS = empty_option;
7935 p_wiv = (*T_XS != NUL);
7936 }
7937
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007938#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 else if ((int *)varp == &p_beval)
7940 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007941 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007942 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007943 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 gui_mch_disable_beval_area(balloonEval);
7945 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007946#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007948#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 else if ((int *)varp == &p_acd)
7950 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007951 /* Change directories when the 'acd' option is set now. */
7952 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 }
7954#endif
7955
7956#ifdef FEAT_DIFF
7957 /* 'diff' */
7958 else if ((int *)varp == &curwin->w_p_diff)
7959 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007960 /* May add or remove the buffer from the list of diff buffers. */
7961 diff_buf_adjust(curwin);
7962# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 if (foldmethodIsDiff(curwin))
7964 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007965# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 }
7967#endif
7968
7969#ifdef USE_IM_CONTROL
7970 /* 'imdisable' */
7971 else if ((int *)varp == &p_imdisable)
7972 {
7973 /* Only de-activate it here, it will be enabled when changing mode. */
7974 if (p_imdisable)
7975 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007976 else if (State & INSERT)
7977 /* When the option is set from an autocommand, it may need to take
7978 * effect right away. */
7979 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 }
7981#endif
7982
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007983#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007984 /* 'spell' */
7985 else if ((int *)varp == &curwin->w_p_spell)
7986 {
7987 if (curwin->w_p_spell)
7988 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007989 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007990 if (errmsg != NULL)
7991 EMSG(_(errmsg));
7992 }
7993 }
7994#endif
7995
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996#ifdef FEAT_FKMAP
7997 else if ((int *)varp == &p_altkeymap)
7998 {
7999 if (old_value != p_altkeymap)
8000 {
8001 if (!p_altkeymap)
8002 {
8003 p_hkmap = p_fkmap;
8004 p_fkmap = 0;
8005 }
8006 else
8007 {
8008 p_fkmap = p_hkmap;
8009 p_hkmap = 0;
8010 }
8011 (void)init_chartab();
8012 }
8013 }
8014
8015 /*
8016 * In case some second language keymapping options have changed, check
8017 * and correct the setting in a consistent way.
8018 */
8019
8020 /*
8021 * If hkmap or fkmap are set, reset Arabic keymapping.
8022 */
8023 if ((p_hkmap || p_fkmap) && p_altkeymap)
8024 {
8025 p_altkeymap = p_fkmap;
8026# ifdef FEAT_ARABIC
8027 curwin->w_p_arab = FALSE;
8028# endif
8029 (void)init_chartab();
8030 }
8031
8032 /*
8033 * If hkmap set, reset Farsi keymapping.
8034 */
8035 if (p_hkmap && p_altkeymap)
8036 {
8037 p_altkeymap = 0;
8038 p_fkmap = 0;
8039# ifdef FEAT_ARABIC
8040 curwin->w_p_arab = FALSE;
8041# endif
8042 (void)init_chartab();
8043 }
8044
8045 /*
8046 * If fkmap set, reset Hebrew keymapping.
8047 */
8048 if (p_fkmap && !p_altkeymap)
8049 {
8050 p_altkeymap = 1;
8051 p_hkmap = 0;
8052# ifdef FEAT_ARABIC
8053 curwin->w_p_arab = FALSE;
8054# endif
8055 (void)init_chartab();
8056 }
8057#endif
8058
8059#ifdef FEAT_ARABIC
8060 if ((int *)varp == &curwin->w_p_arab)
8061 {
8062 if (curwin->w_p_arab)
8063 {
8064 /*
8065 * 'arabic' is set, handle various sub-settings.
8066 */
8067 if (!p_tbidi)
8068 {
8069 /* set rightleft mode */
8070 if (!curwin->w_p_rl)
8071 {
8072 curwin->w_p_rl = TRUE;
8073 changed_window_setting();
8074 }
8075
8076 /* Enable Arabic shaping (major part of what Arabic requires) */
8077 if (!p_arshape)
8078 {
8079 p_arshape = TRUE;
8080 redraw_later_clear();
8081 }
8082 }
8083
8084 /* Arabic requires a utf-8 encoding, inform the user if its not
8085 * set. */
8086 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008087 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008088 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8089
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008090 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008091 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8092#ifdef FEAT_EVAL
8093 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8094#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008095 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008096
8097# ifdef FEAT_MBYTE
8098 /* set 'delcombine' */
8099 p_deco = TRUE;
8100# endif
8101
8102# ifdef FEAT_KEYMAP
8103 /* Force-set the necessary keymap for arabic */
8104 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8105 OPT_LOCAL);
8106# endif
8107# ifdef FEAT_FKMAP
8108 p_altkeymap = 0;
8109 p_hkmap = 0;
8110 p_fkmap = 0;
8111 (void)init_chartab();
8112# endif
8113 }
8114 else
8115 {
8116 /*
8117 * 'arabic' is reset, handle various sub-settings.
8118 */
8119 if (!p_tbidi)
8120 {
8121 /* reset rightleft mode */
8122 if (curwin->w_p_rl)
8123 {
8124 curwin->w_p_rl = FALSE;
8125 changed_window_setting();
8126 }
8127
8128 /* 'arabicshape' isn't reset, it is a global option and
8129 * another window may still need it "on". */
8130 }
8131
8132 /* 'delcombine' isn't reset, it is a global option and another
8133 * window may still want it "on". */
8134
8135# ifdef FEAT_KEYMAP
8136 /* Revert to the default keymap */
8137 curbuf->b_p_iminsert = B_IMODE_NONE;
8138 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8139# endif
8140 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008141 }
8142
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008143#endif
8144
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 /*
8146 * End of handling side effects for bool options.
8147 */
8148
8149 options[opt_idx].flags |= P_WAS_SET;
8150
8151 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008152 if (curwin->w_curswant != MAXCOL
8153 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8154 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 check_redraw(options[opt_idx].flags);
8156
8157 return NULL;
8158}
8159
8160/*
8161 * Set the value of a number option, and take care of side effects.
8162 * Returns NULL for success, or an error message for an error.
8163 */
8164 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008165set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166 int opt_idx; /* index in options[] table */
8167 char_u *varp; /* pointer to the option variable */
8168 long value; /* new value */
8169 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008170 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8172 OPT_MODELINE */
8173{
8174 char_u *errmsg = NULL;
8175 long old_value = *(long *)varp;
8176 long old_Rows = Rows; /* remember old Rows */
8177 long old_Columns = Columns; /* remember old Columns */
8178 long *pp = (long *)varp;
8179
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008180 /* Disallow changing some options from secure mode. */
8181 if ((secure
8182#ifdef HAVE_SANDBOX
8183 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008185 ) && (options[opt_idx].flags & P_SECURE))
8186 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187
8188 *pp = value;
8189#ifdef FEAT_EVAL
8190 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008191 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008193#ifdef FEAT_GUI
8194 need_mouse_correct = TRUE;
8195#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196
Bram Moolenaar14f24742012-08-08 18:01:05 +02008197 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 {
8199 errmsg = e_positive;
8200 curbuf->b_p_sw = curbuf->b_p_ts;
8201 }
8202
8203 /*
8204 * Number options that need some action when changed
8205 */
8206#ifdef FEAT_WINDOWS
8207 if (pp == &p_wh || pp == &p_hh)
8208 {
8209 if (p_wh < 1)
8210 {
8211 errmsg = e_positive;
8212 p_wh = 1;
8213 }
8214 if (p_wmh > p_wh)
8215 {
8216 errmsg = e_winheight;
8217 p_wh = p_wmh;
8218 }
8219 if (p_hh < 0)
8220 {
8221 errmsg = e_positive;
8222 p_hh = 0;
8223 }
8224
8225 /* Change window height NOW */
8226 if (lastwin != firstwin)
8227 {
8228 if (pp == &p_wh && curwin->w_height < p_wh)
8229 win_setheight((int)p_wh);
8230 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8231 win_setheight((int)p_hh);
8232 }
8233 }
8234
8235 /* 'winminheight' */
8236 else if (pp == &p_wmh)
8237 {
8238 if (p_wmh < 0)
8239 {
8240 errmsg = e_positive;
8241 p_wmh = 0;
8242 }
8243 if (p_wmh > p_wh)
8244 {
8245 errmsg = e_winheight;
8246 p_wmh = p_wh;
8247 }
8248 win_setminheight();
8249 }
8250
8251# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008252 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253 {
8254 if (p_wiw < 1)
8255 {
8256 errmsg = e_positive;
8257 p_wiw = 1;
8258 }
8259 if (p_wmw > p_wiw)
8260 {
8261 errmsg = e_winwidth;
8262 p_wiw = p_wmw;
8263 }
8264
8265 /* Change window width NOW */
8266 if (lastwin != firstwin && curwin->w_width < p_wiw)
8267 win_setwidth((int)p_wiw);
8268 }
8269
8270 /* 'winminwidth' */
8271 else if (pp == &p_wmw)
8272 {
8273 if (p_wmw < 0)
8274 {
8275 errmsg = e_positive;
8276 p_wmw = 0;
8277 }
8278 if (p_wmw > p_wiw)
8279 {
8280 errmsg = e_winwidth;
8281 p_wmw = p_wiw;
8282 }
8283 win_setminheight();
8284 }
8285# endif
8286
8287#endif
8288
8289#ifdef FEAT_WINDOWS
8290 /* (re)set last window status line */
8291 else if (pp == &p_ls)
8292 {
8293 last_status(FALSE);
8294 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008295
8296 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008297 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008298 {
8299 shell_new_rows(); /* recompute window positions and heights */
8300 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301#endif
8302
8303#ifdef FEAT_GUI
8304 else if (pp == &p_linespace)
8305 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008306 /* Recompute gui.char_height and resize the Vim window to keep the
8307 * same number of lines. */
8308 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008309 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008310 }
8311#endif
8312
8313#ifdef FEAT_FOLDING
8314 /* 'foldlevel' */
8315 else if (pp == &curwin->w_p_fdl)
8316 {
8317 if (curwin->w_p_fdl < 0)
8318 curwin->w_p_fdl = 0;
8319 newFoldLevel();
8320 }
8321
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008322 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008323 else if (pp == &curwin->w_p_fml)
8324 {
8325 foldUpdateAll(curwin);
8326 }
8327
8328 /* 'foldnestmax' */
8329 else if (pp == &curwin->w_p_fdn)
8330 {
8331 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8332 foldUpdateAll(curwin);
8333 }
8334
8335 /* 'foldcolumn' */
8336 else if (pp == &curwin->w_p_fdc)
8337 {
8338 if (curwin->w_p_fdc < 0)
8339 {
8340 errmsg = e_positive;
8341 curwin->w_p_fdc = 0;
8342 }
8343 else if (curwin->w_p_fdc > 12)
8344 {
8345 errmsg = e_invarg;
8346 curwin->w_p_fdc = 12;
8347 }
8348 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008349#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008351#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 /* 'shiftwidth' or 'tabstop' */
8353 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8354 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008355# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 if (foldmethodIsIndent(curwin))
8357 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008358# endif
8359# ifdef FEAT_CINDENT
8360 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8361 * parse 'cinoptions'. */
8362 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8363 parse_cino(curbuf);
8364# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008366#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008367
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008368#ifdef FEAT_MBYTE
8369 /* 'maxcombine' */
8370 else if (pp == &p_mco)
8371 {
8372 if (p_mco > MAX_MCO)
8373 p_mco = MAX_MCO;
8374 else if (p_mco < 0)
8375 p_mco = 0;
8376 screenclear(); /* will re-allocate the screen */
8377 }
8378#endif
8379
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 else if (pp == &curbuf->b_p_iminsert)
8381 {
8382 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8383 {
8384 errmsg = e_invarg;
8385 curbuf->b_p_iminsert = B_IMODE_NONE;
8386 }
8387 p_iminsert = curbuf->b_p_iminsert;
8388 if (termcap_active) /* don't do this in the alternate screen */
8389 showmode();
8390#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8391 /* Show/unshow value of 'keymap' in status lines. */
8392 status_redraw_curbuf();
8393#endif
8394 }
8395
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008396 else if (pp == &p_window)
8397 {
8398 if (p_window < 1)
8399 p_window = 1;
8400 else if (p_window >= Rows)
8401 p_window = Rows - 1;
8402 }
8403
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404 else if (pp == &curbuf->b_p_imsearch)
8405 {
8406 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8407 {
8408 errmsg = e_invarg;
8409 curbuf->b_p_imsearch = B_IMODE_NONE;
8410 }
8411 p_imsearch = curbuf->b_p_imsearch;
8412 }
8413
8414#ifdef FEAT_TITLE
8415 /* if 'titlelen' has changed, redraw the title */
8416 else if (pp == &p_titlelen)
8417 {
8418 if (p_titlelen < 0)
8419 {
8420 errmsg = e_positive;
8421 p_titlelen = 85;
8422 }
8423 if (starting != NO_SCREEN && old_value != p_titlelen)
8424 need_maketitle = TRUE;
8425 }
8426#endif
8427
8428 /* if p_ch changed value, change the command line height */
8429 else if (pp == &p_ch)
8430 {
8431 if (p_ch < 1)
8432 {
8433 errmsg = e_positive;
8434 p_ch = 1;
8435 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008436 if (p_ch > Rows - min_rows() + 1)
8437 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008438
8439 /* Only compute the new window layout when startup has been
8440 * completed. Otherwise the frame sizes may be wrong. */
8441 if (p_ch != old_value && full_screen
8442#ifdef FEAT_GUI
8443 && !gui.starting
8444#endif
8445 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008446 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 }
8448
8449 /* when 'updatecount' changes from zero to non-zero, open swap files */
8450 else if (pp == &p_uc)
8451 {
8452 if (p_uc < 0)
8453 {
8454 errmsg = e_positive;
8455 p_uc = 100;
8456 }
8457 if (p_uc && !old_value)
8458 ml_open_files();
8459 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008460#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008461 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008462 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008463 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008464 {
8465 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008466 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008467 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008468 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008469 {
8470 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008471 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008472 }
8473 }
8474#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008475#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008476 else if (pp == &p_mzq)
8477 mzvim_reset_timer();
8478#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008479
8480 /* sync undo before 'undolevels' changes */
8481 else if (pp == &p_ul)
8482 {
8483 /* use the old value, otherwise u_sync() may not work properly */
8484 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008485 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486 p_ul = value;
8487 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008488 else if (pp == &curbuf->b_p_ul)
8489 {
8490 /* use the old value, otherwise u_sync() may not work properly */
8491 curbuf->b_p_ul = old_value;
8492 u_sync(TRUE);
8493 curbuf->b_p_ul = value;
8494 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008496#ifdef FEAT_LINEBREAK
8497 /* 'numberwidth' must be positive */
8498 else if (pp == &curwin->w_p_nuw)
8499 {
8500 if (curwin->w_p_nuw < 1)
8501 {
8502 errmsg = e_positive;
8503 curwin->w_p_nuw = 1;
8504 }
8505 if (curwin->w_p_nuw > 10)
8506 {
8507 errmsg = e_invarg;
8508 curwin->w_p_nuw = 10;
8509 }
8510 curwin->w_nrwidth_line_count = 0;
8511 }
8512#endif
8513
Bram Moolenaar1a384422010-07-14 19:53:30 +02008514 else if (pp == &curbuf->b_p_tw)
8515 {
8516 if (curbuf->b_p_tw < 0)
8517 {
8518 errmsg = e_positive;
8519 curbuf->b_p_tw = 0;
8520 }
8521#ifdef FEAT_SYN_HL
8522# ifdef FEAT_WINDOWS
8523 {
8524 win_T *wp;
8525 tabpage_T *tp;
8526
8527 FOR_ALL_TAB_WINDOWS(tp, wp)
8528 check_colorcolumn(wp);
8529 }
8530# else
8531 check_colorcolumn(curwin);
8532# endif
8533#endif
8534 }
8535
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536 /*
8537 * Check the bounds for numeric options here
8538 */
8539 if (Rows < min_rows() && full_screen)
8540 {
8541 if (errbuf != NULL)
8542 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008543 vim_snprintf((char *)errbuf, errbuflen,
8544 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 errmsg = errbuf;
8546 }
8547 Rows = min_rows();
8548 }
8549 if (Columns < MIN_COLUMNS && full_screen)
8550 {
8551 if (errbuf != NULL)
8552 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008553 vim_snprintf((char *)errbuf, errbuflen,
8554 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555 errmsg = errbuf;
8556 }
8557 Columns = MIN_COLUMNS;
8558 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008559 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560
8561#ifdef DJGPP
8562 /* avoid a crash by checking for a too large value of 'columns' */
8563 if (old_Columns != Columns && full_screen && term_console)
8564 mch_check_columns();
8565#endif
8566
8567 /*
8568 * If the screen (shell) height has been changed, assume it is the
8569 * physical screenheight.
8570 */
8571 if (old_Rows != Rows || old_Columns != Columns)
8572 {
8573 /* Changing the screen size is not allowed while updating the screen. */
8574 if (updating_screen)
8575 *pp = old_value;
8576 else if (full_screen
8577#ifdef FEAT_GUI
8578 && !gui.starting
8579#endif
8580 )
8581 set_shellsize((int)Columns, (int)Rows, TRUE);
8582 else
8583 {
8584 /* Postpone the resizing; check the size and cmdline position for
8585 * messages. */
8586 check_shellsize();
8587 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8588 cmdline_row = Rows - p_ch;
8589 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008590 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008591 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008592 }
8593
Bram Moolenaar071d4272004-06-13 20:20:40 +00008594 if (curbuf->b_p_ts <= 0)
8595 {
8596 errmsg = e_positive;
8597 curbuf->b_p_ts = 8;
8598 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008599 if (p_tm < 0)
8600 {
8601 errmsg = e_positive;
8602 p_tm = 0;
8603 }
8604 if ((curwin->w_p_scr <= 0
8605 || (curwin->w_p_scr > curwin->w_height
8606 && curwin->w_height > 0))
8607 && full_screen)
8608 {
8609 if (pp == &(curwin->w_p_scr))
8610 {
8611 if (curwin->w_p_scr != 0)
8612 errmsg = e_scroll;
8613 win_comp_scroll(curwin);
8614 }
8615 /* If 'scroll' became invalid because of a side effect silently adjust
8616 * it. */
8617 else if (curwin->w_p_scr <= 0)
8618 curwin->w_p_scr = 1;
8619 else /* curwin->w_p_scr > curwin->w_height */
8620 curwin->w_p_scr = curwin->w_height;
8621 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008622 if (p_hi < 0)
8623 {
8624 errmsg = e_positive;
8625 p_hi = 0;
8626 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008627 if (p_re < 0 || p_re > 2)
8628 {
8629 errmsg = e_invarg;
8630 p_re = 0;
8631 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008632 if (p_report < 0)
8633 {
8634 errmsg = e_positive;
8635 p_report = 1;
8636 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008637 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638 {
8639 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8640 p_sj = Rows / 2;
8641 else
8642 {
8643 errmsg = e_scroll;
8644 p_sj = 1;
8645 }
8646 }
8647 if (p_so < 0 && full_screen)
8648 {
8649 errmsg = e_scroll;
8650 p_so = 0;
8651 }
8652 if (p_siso < 0 && full_screen)
8653 {
8654 errmsg = e_positive;
8655 p_siso = 0;
8656 }
8657#ifdef FEAT_CMDWIN
8658 if (p_cwh < 1)
8659 {
8660 errmsg = e_positive;
8661 p_cwh = 1;
8662 }
8663#endif
8664 if (p_ut < 0)
8665 {
8666 errmsg = e_positive;
8667 p_ut = 2000;
8668 }
8669 if (p_ss < 0)
8670 {
8671 errmsg = e_positive;
8672 p_ss = 0;
8673 }
8674
8675 /* May set global value for local option. */
8676 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8677 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8678
8679 options[opt_idx].flags |= P_WAS_SET;
8680
8681 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008682 if (curwin->w_curswant != MAXCOL
8683 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8684 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008685 check_redraw(options[opt_idx].flags);
8686
8687 return errmsg;
8688}
8689
8690/*
8691 * Called after an option changed: check if something needs to be redrawn.
8692 */
8693 static void
8694check_redraw(flags)
8695 long_u flags;
8696{
8697 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008698 int doclear = (flags & P_RCLR) == P_RCLR;
8699 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008700
8701#ifdef FEAT_WINDOWS
8702 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8703 status_redraw_all();
8704#endif
8705
8706 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8707 changed_window_setting();
8708 if (flags & P_RBUF)
8709 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008710 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008711 redraw_all_later(CLEAR);
8712 else if (all)
8713 redraw_all_later(NOT_VALID);
8714}
8715
8716/*
8717 * Find index for option 'arg'.
8718 * Return -1 if not found.
8719 */
8720 static int
8721findoption(arg)
8722 char_u *arg;
8723{
8724 int opt_idx;
8725 char *s, *p;
8726 static short quick_tab[27] = {0, 0}; /* quick access table */
8727 int is_term_opt;
8728
8729 /*
8730 * For first call: Initialize the quick-access table.
8731 * It contains the index for the first option that starts with a certain
8732 * letter. There are 26 letters, plus the first "t_" option.
8733 */
8734 if (quick_tab[1] == 0)
8735 {
8736 p = options[0].fullname;
8737 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8738 {
8739 if (s[0] != p[0])
8740 {
8741 if (s[0] == 't' && s[1] == '_')
8742 quick_tab[26] = opt_idx;
8743 else
8744 quick_tab[CharOrdLow(s[0])] = opt_idx;
8745 }
8746 p = s;
8747 }
8748 }
8749
8750 /*
8751 * Check for name starting with an illegal character.
8752 */
8753#ifdef EBCDIC
8754 if (!islower(arg[0]))
8755#else
8756 if (arg[0] < 'a' || arg[0] > 'z')
8757#endif
8758 return -1;
8759
8760 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8761 if (is_term_opt)
8762 opt_idx = quick_tab[26];
8763 else
8764 opt_idx = quick_tab[CharOrdLow(arg[0])];
8765 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8766 {
8767 if (STRCMP(arg, s) == 0) /* match full name */
8768 break;
8769 }
8770 if (s == NULL && !is_term_opt)
8771 {
8772 opt_idx = quick_tab[CharOrdLow(arg[0])];
8773 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8774 {
8775 s = options[opt_idx].shortname;
8776 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8777 break;
8778 s = NULL;
8779 }
8780 }
8781 if (s == NULL)
8782 opt_idx = -1;
8783 return opt_idx;
8784}
8785
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008786#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787/*
8788 * Get the value for an option.
8789 *
8790 * Returns:
8791 * Number or Toggle option: 1, *numval gets value.
8792 * String option: 0, *stringval gets allocated string.
8793 * Hidden Number or Toggle option: -1.
8794 * hidden String option: -2.
8795 * unknown option: -3.
8796 */
8797 int
8798get_option_value(name, numval, stringval, opt_flags)
8799 char_u *name;
8800 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008801 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802 int opt_flags;
8803{
8804 int opt_idx;
8805 char_u *varp;
8806
8807 opt_idx = findoption(name);
8808 if (opt_idx < 0) /* unknown option */
8809 return -3;
8810
8811 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8812
8813 if (options[opt_idx].flags & P_STRING)
8814 {
8815 if (varp == NULL) /* hidden option */
8816 return -2;
8817 if (stringval != NULL)
8818 {
8819#ifdef FEAT_CRYPT
8820 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008821 if ((char_u **)varp == &curbuf->b_p_key
8822 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 *stringval = vim_strsave((char_u *)"*****");
8824 else
8825#endif
8826 *stringval = vim_strsave(*(char_u **)(varp));
8827 }
8828 return 0;
8829 }
8830
8831 if (varp == NULL) /* hidden option */
8832 return -1;
8833 if (options[opt_idx].flags & P_NUM)
8834 *numval = *(long *)varp;
8835 else
8836 {
8837 /* Special case: 'modified' is b_changed, but we also want to consider
8838 * it set when 'ff' or 'fenc' changed. */
8839 if ((int *)varp == &curbuf->b_changed)
8840 *numval = curbufIsChanged();
8841 else
8842 *numval = *(int *)varp;
8843 }
8844 return 1;
8845}
8846#endif
8847
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008848#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008849/*
8850 * Returns the option attributes and its value. Unlike the above function it
8851 * will return either global value or local value of the option depending on
8852 * what was requested, but it will never return global value if it was
8853 * requested to return local one and vice versa. Neither it will return
8854 * buffer-local value if it was requested to return window-local one.
8855 *
8856 * Pretends that option is absent if it is not present in the requested scope
8857 * (i.e. has no global, window-local or buffer-local value depending on
8858 * opt_type). Uses
8859 *
8860 * Returned flags:
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008861 * 0 hidden or unknown option, also option that does not have requested
8862 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008863 * see SOPT_* in vim.h for other flags
8864 *
8865 * Possible opt_type values: see SREQ_* in vim.h
8866 */
8867 int
8868get_option_value_strict(name, numval, stringval, opt_type, from)
8869 char_u *name;
8870 long *numval;
8871 char_u **stringval; /* NULL when only obtaining attributes */
8872 int opt_type;
8873 void *from;
8874{
8875 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008876 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008877 struct vimoption *p;
8878 int r = 0;
8879
8880 opt_idx = findoption(name);
8881 if (opt_idx < 0)
8882 return 0;
8883
8884 p = &(options[opt_idx]);
8885
8886 /* Hidden option */
8887 if (p->var == NULL)
8888 return 0;
8889
8890 if (p->flags & P_BOOL)
8891 r |= SOPT_BOOL;
8892 else if (p->flags & P_NUM)
8893 r |= SOPT_NUM;
8894 else if (p->flags & P_STRING)
8895 r |= SOPT_STRING;
8896
8897 if (p->indir == PV_NONE)
8898 {
8899 if (opt_type == SREQ_GLOBAL)
8900 r |= SOPT_GLOBAL;
8901 else
8902 return 0; /* Did not request global-only option */
8903 }
8904 else
8905 {
8906 if (p->indir & PV_BOTH)
8907 r |= SOPT_GLOBAL;
8908 else if (opt_type == SREQ_GLOBAL)
8909 return 0; /* Requested global option */
8910
8911 if (p->indir & PV_WIN)
8912 {
8913 if (opt_type == SREQ_BUF)
8914 return 0; /* Did not request window-local option */
8915 else
8916 r |= SOPT_WIN;
8917 }
8918 else if (p->indir & PV_BUF)
8919 {
8920 if (opt_type == SREQ_WIN)
8921 return 0; /* Did not request buffer-local option */
8922 else
8923 r |= SOPT_BUF;
8924 }
8925 }
8926
8927 if (stringval == NULL)
8928 return r;
8929
8930 if (opt_type == SREQ_GLOBAL)
8931 varp = p->var;
8932 else
8933 {
8934 if (opt_type == SREQ_BUF)
8935 {
8936 /* Special case: 'modified' is b_changed, but we also want to
8937 * consider it set when 'ff' or 'fenc' changed. */
8938 if (p->indir == PV_MOD)
8939 {
8940 *numval = bufIsChanged((buf_T *) from);
8941 varp = NULL;
8942 }
8943#ifdef FEAT_CRYPT
8944 else if (p->indir == PV_KEY)
8945 {
8946 /* never return the value of the crypt key */
8947 *stringval = NULL;
8948 varp = NULL;
8949 }
8950#endif
8951 else
8952 {
8953 aco_save_T aco;
8954 aucmd_prepbuf(&aco, (buf_T *) from);
8955 varp = get_varp(p);
8956 aucmd_restbuf(&aco);
8957 }
8958 }
8959 else if (opt_type == SREQ_WIN)
8960 {
8961 win_T *save_curwin;
8962 save_curwin = curwin;
8963 curwin = (win_T *) from;
8964 curbuf = curwin->w_buffer;
8965 varp = get_varp(p);
8966 curwin = save_curwin;
8967 curbuf = curwin->w_buffer;
8968 }
8969 if (varp == p->var)
8970 return (r | SOPT_UNSET);
8971 }
8972
8973 if (varp != NULL)
8974 {
8975 if (p->flags & P_STRING)
8976 *stringval = vim_strsave(*(char_u **)(varp));
8977 else if (p->flags & P_NUM)
8978 *numval = *(long *) varp;
8979 else
8980 *numval = *(int *)varp;
8981 }
8982
8983 return r;
8984}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008985
8986/*
8987 * Iterate over options. First argument is a pointer to a pointer to a structure
8988 * inside options[] array, second is option type like in the above function.
8989 *
8990 * If first argument points to NULL it is assumed that iteration just started
8991 * and caller needs the very first value.
8992 * If first argument points to the end marker function returns NULL and sets
8993 * first argument to NULL.
8994 *
8995 * Returns full option name for current option on each call.
8996 */
8997 char_u *
8998option_iter_next(option, opt_type)
8999 void **option;
9000 int opt_type;
9001{
9002 struct vimoption *ret = NULL;
9003 do
9004 {
9005 if (*option == NULL)
9006 *option = (void *) options;
9007 else if (((struct vimoption *) (*option))->fullname == NULL)
9008 {
9009 *option = NULL;
9010 return NULL;
9011 }
9012 else
9013 *option = (void *) (((struct vimoption *) (*option)) + 1);
9014
9015 ret = ((struct vimoption *) (*option));
9016
9017 /* Hidden option */
9018 if (ret->var == NULL)
9019 {
9020 ret = NULL;
9021 continue;
9022 }
9023
9024 switch (opt_type)
9025 {
9026 case SREQ_GLOBAL:
9027 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9028 ret = NULL;
9029 break;
9030 case SREQ_BUF:
9031 if (!(ret->indir & PV_BUF))
9032 ret = NULL;
9033 break;
9034 case SREQ_WIN:
9035 if (!(ret->indir & PV_WIN))
9036 ret = NULL;
9037 break;
9038 default:
9039 EMSG2(_(e_intern2), "option_iter_next()");
9040 return NULL;
9041 }
9042 }
9043 while (ret == NULL);
9044
9045 return (char_u *)ret->fullname;
9046}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009047#endif
9048
Bram Moolenaar071d4272004-06-13 20:20:40 +00009049/*
9050 * Set the value of option "name".
9051 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009052 *
9053 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009055 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056set_option_value(name, number, string, opt_flags)
9057 char_u *name;
9058 long number;
9059 char_u *string;
9060 int opt_flags; /* OPT_LOCAL or 0 (both) */
9061{
9062 int opt_idx;
9063 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009064 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009065
9066 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009067 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009068 EMSG2(_("E355: Unknown option: %s"), name);
9069 else
9070 {
9071 flags = options[opt_idx].flags;
9072#ifdef HAVE_SANDBOX
9073 /* Disallow changing some options in the sandbox */
9074 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009075 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009077 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009078 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009079#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009080 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009081 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009082 else
9083 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009084 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085 if (varp != NULL) /* hidden option is not changed */
9086 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009087 if (number == 0 && string != NULL)
9088 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009089 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009090
9091 /* Either we are given a string or we are setting option
9092 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009093 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009094 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009095 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009096 {
9097 /* There's another character after zeros or the string
9098 * is empty. In both cases, we are trying to set a
9099 * num option using a string. */
9100 EMSG3(_("E521: Number required: &%s = '%s'"),
9101 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009102 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009103
9104 }
9105 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009107 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009108 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009110 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009111 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 }
9113 }
9114 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009115 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116}
9117
9118/*
9119 * Get the terminal code for a terminal option.
9120 * Returns NULL when not found.
9121 */
9122 char_u *
9123get_term_code(tname)
9124 char_u *tname;
9125{
9126 int opt_idx;
9127 char_u *varp;
9128
9129 if (tname[0] != 't' || tname[1] != '_' ||
9130 tname[2] == NUL || tname[3] == NUL)
9131 return NULL;
9132 if ((opt_idx = findoption(tname)) >= 0)
9133 {
9134 varp = get_varp(&(options[opt_idx]));
9135 if (varp != NULL)
9136 varp = *(char_u **)(varp);
9137 return varp;
9138 }
9139 return find_termcode(tname + 2);
9140}
9141
9142 char_u *
9143get_highlight_default()
9144{
9145 int i;
9146
9147 i = findoption((char_u *)"hl");
9148 if (i >= 0)
9149 return options[i].def_val[VI_DEFAULT];
9150 return (char_u *)NULL;
9151}
9152
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009153#if defined(FEAT_MBYTE) || defined(PROTO)
9154 char_u *
9155get_encoding_default()
9156{
9157 int i;
9158
9159 i = findoption((char_u *)"enc");
9160 if (i >= 0)
9161 return options[i].def_val[VI_DEFAULT];
9162 return (char_u *)NULL;
9163}
9164#endif
9165
Bram Moolenaar071d4272004-06-13 20:20:40 +00009166/*
9167 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9168 */
9169 static int
9170find_key_option(arg)
9171 char_u *arg;
9172{
9173 int key;
9174 int modifiers;
9175
9176 /*
9177 * Don't use get_special_key_code() for t_xx, we don't want it to call
9178 * add_termcap_entry().
9179 */
9180 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9181 key = TERMCAP2KEY(arg[2], arg[3]);
9182 else
9183 {
9184 --arg; /* put arg at the '<' */
9185 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009186 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009187 if (modifiers) /* can't handle modifiers here */
9188 key = 0;
9189 }
9190 return key;
9191}
9192
9193/*
9194 * if 'all' == 0: show changed options
9195 * if 'all' == 1: show all normal options
9196 * if 'all' == 2: show all terminal options
9197 */
9198 static void
9199showoptions(all, opt_flags)
9200 int all;
9201 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9202{
9203 struct vimoption *p;
9204 int col;
9205 int isterm;
9206 char_u *varp;
9207 struct vimoption **items;
9208 int item_count;
9209 int run;
9210 int row, rows;
9211 int cols;
9212 int i;
9213 int len;
9214
9215#define INC 20
9216#define GAP 3
9217
9218 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9219 PARAM_COUNT));
9220 if (items == NULL)
9221 return;
9222
9223 /* Highlight title */
9224 if (all == 2)
9225 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9226 else if (opt_flags & OPT_GLOBAL)
9227 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9228 else if (opt_flags & OPT_LOCAL)
9229 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9230 else
9231 MSG_PUTS_TITLE(_("\n--- Options ---"));
9232
9233 /*
9234 * do the loop two times:
9235 * 1. display the short items
9236 * 2. display the long items (only strings and numbers)
9237 */
9238 for (run = 1; run <= 2 && !got_int; ++run)
9239 {
9240 /*
9241 * collect the items in items[]
9242 */
9243 item_count = 0;
9244 for (p = &options[0]; p->fullname != NULL; p++)
9245 {
9246 varp = NULL;
9247 isterm = istermoption(p);
9248 if (opt_flags != 0)
9249 {
9250 if (p->indir != PV_NONE && !isterm)
9251 varp = get_varp_scope(p, opt_flags);
9252 }
9253 else
9254 varp = get_varp(p);
9255 if (varp != NULL
9256 && ((all == 2 && isterm)
9257 || (all == 1 && !isterm)
9258 || (all == 0 && !optval_default(p, varp))))
9259 {
9260 if (p->flags & P_BOOL)
9261 len = 1; /* a toggle option fits always */
9262 else
9263 {
9264 option_value2string(p, opt_flags);
9265 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9266 }
9267 if ((len <= INC - GAP && run == 1) ||
9268 (len > INC - GAP && run == 2))
9269 items[item_count++] = p;
9270 }
9271 }
9272
9273 /*
9274 * display the items
9275 */
9276 if (run == 1)
9277 {
9278 cols = (Columns + GAP - 3) / INC;
9279 if (cols == 0)
9280 cols = 1;
9281 rows = (item_count + cols - 1) / cols;
9282 }
9283 else /* run == 2 */
9284 rows = item_count;
9285 for (row = 0; row < rows && !got_int; ++row)
9286 {
9287 msg_putchar('\n'); /* go to next line */
9288 if (got_int) /* 'q' typed in more */
9289 break;
9290 col = 0;
9291 for (i = row; i < item_count; i += rows)
9292 {
9293 msg_col = col; /* make columns */
9294 showoneopt(items[i], opt_flags);
9295 col += INC;
9296 }
9297 out_flush();
9298 ui_breakcheck();
9299 }
9300 }
9301 vim_free(items);
9302}
9303
9304/*
9305 * Return TRUE if option "p" has its default value.
9306 */
9307 static int
9308optval_default(p, varp)
9309 struct vimoption *p;
9310 char_u *varp;
9311{
9312 int dvi;
9313
9314 if (varp == NULL)
9315 return TRUE; /* hidden option is always at default */
9316 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9317 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009318 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009319 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009320 /* the cast to long is required for Manx C, long_i is
9321 * needed for MSVC */
9322 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323 /* P_STRING */
9324 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9325}
9326
9327/*
9328 * showoneopt: show the value of one option
9329 * must not be called with a hidden option!
9330 */
9331 static void
9332showoneopt(p, opt_flags)
9333 struct vimoption *p;
9334 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9335{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009336 char_u *varp;
9337 int save_silent = silent_mode;
9338
9339 silent_mode = FALSE;
9340 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009341
9342 varp = get_varp_scope(p, opt_flags);
9343
9344 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9345 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9346 ? !curbufIsChanged() : !*(int *)varp))
9347 MSG_PUTS("no");
9348 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9349 MSG_PUTS("--");
9350 else
9351 MSG_PUTS(" ");
9352 MSG_PUTS(p->fullname);
9353 if (!(p->flags & P_BOOL))
9354 {
9355 msg_putchar('=');
9356 /* put value string in NameBuff */
9357 option_value2string(p, opt_flags);
9358 msg_outtrans(NameBuff);
9359 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009360
9361 silent_mode = save_silent;
9362 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009363}
9364
9365/*
9366 * Write modified options as ":set" commands to a file.
9367 *
9368 * There are three values for "opt_flags":
9369 * OPT_GLOBAL: Write global option values and fresh values of
9370 * buffer-local options (used for start of a session
9371 * file).
9372 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9373 * curwin (used for a vimrc file).
9374 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9375 * and local values for window-local options of
9376 * curwin. Local values are also written when at the
9377 * default value, because a modeline or autocommand
9378 * may have set them when doing ":edit file" and the
9379 * user has set them back at the default or fresh
9380 * value.
9381 * When "local_only" is TRUE, don't write fresh
9382 * values, only local values (for ":mkview").
9383 * (fresh value = value used for a new buffer or window for a local option).
9384 *
9385 * Return FAIL on error, OK otherwise.
9386 */
9387 int
9388makeset(fd, opt_flags, local_only)
9389 FILE *fd;
9390 int opt_flags;
9391 int local_only;
9392{
9393 struct vimoption *p;
9394 char_u *varp; /* currently used value */
9395 char_u *varp_fresh; /* local value */
9396 char_u *varp_local = NULL; /* fresh value */
9397 char *cmd;
9398 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009399 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009400
9401 /*
9402 * The options that don't have a default (terminal name, columns, lines)
9403 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009404 * Do the loop over "options[]" twice: once for options with the
9405 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009406 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009407 for (pri = 1; pri >= 0; --pri)
9408 {
9409 for (p = &options[0]; !istermoption(p); p++)
9410 if (!(p->flags & P_NO_MKRC)
9411 && !istermoption(p)
9412 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413 {
9414 /* skip global option when only doing locals */
9415 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9416 continue;
9417
9418 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9419 * file, they are always buffer-specific. */
9420 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9421 continue;
9422
9423 /* Global values are only written when not at the default value. */
9424 varp = get_varp_scope(p, opt_flags);
9425 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9426 continue;
9427
9428 round = 2;
9429 if (p->indir != PV_NONE)
9430 {
9431 if (p->var == VAR_WIN)
9432 {
9433 /* skip window-local option when only doing globals */
9434 if (!(opt_flags & OPT_LOCAL))
9435 continue;
9436 /* When fresh value of window-local option is not at the
9437 * default, need to write it too. */
9438 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9439 {
9440 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9441 if (!optval_default(p, varp_fresh))
9442 {
9443 round = 1;
9444 varp_local = varp;
9445 varp = varp_fresh;
9446 }
9447 }
9448 }
9449 }
9450
9451 /* Round 1: fresh value for window-local options.
9452 * Round 2: other values */
9453 for ( ; round <= 2; varp = varp_local, ++round)
9454 {
9455 if (round == 1 || (opt_flags & OPT_GLOBAL))
9456 cmd = "set";
9457 else
9458 cmd = "setlocal";
9459
9460 if (p->flags & P_BOOL)
9461 {
9462 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9463 return FAIL;
9464 }
9465 else if (p->flags & P_NUM)
9466 {
9467 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9468 return FAIL;
9469 }
9470 else /* P_STRING */
9471 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009472#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9473 int do_endif = FALSE;
9474
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475 /* Don't set 'syntax' and 'filetype' again if the value is
9476 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009477 if (
9478# if defined(FEAT_SYN_HL)
9479 p->indir == PV_SYN
9480# if defined(FEAT_AUTOCMD)
9481 ||
9482# endif
9483# endif
9484# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009485 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009486# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009487 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009488 {
9489 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9490 *(char_u **)(varp)) < 0
9491 || put_eol(fd) < 0)
9492 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009493 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009494 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009495#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009496 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9497 (p->flags & P_EXPAND) != 0) == FAIL)
9498 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009499#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9500 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009501 {
9502 if (put_line(fd, "endif") == FAIL)
9503 return FAIL;
9504 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009506 }
9507 }
9508 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009510 return OK;
9511}
9512
9513#if defined(FEAT_FOLDING) || defined(PROTO)
9514/*
9515 * Generate set commands for the local fold options only. Used when
9516 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9517 */
9518 int
9519makefoldset(fd)
9520 FILE *fd;
9521{
9522 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9523# ifdef FEAT_EVAL
9524 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9525 == FAIL
9526# endif
9527 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9528 == FAIL
9529 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9530 == FAIL
9531 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9532 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9533 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9534 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9535 )
9536 return FAIL;
9537
9538 return OK;
9539}
9540#endif
9541
9542 static int
9543put_setstring(fd, cmd, name, valuep, expand)
9544 FILE *fd;
9545 char *cmd;
9546 char *name;
9547 char_u **valuep;
9548 int expand;
9549{
9550 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009551 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009552
9553 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9554 return FAIL;
9555 if (*valuep != NULL)
9556 {
9557 /* Output 'pastetoggle' as key names. For other
9558 * options some characters have to be escaped with
9559 * CTRL-V or backslash */
9560 if (valuep == &p_pt)
9561 {
9562 s = *valuep;
9563 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009564 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009565 return FAIL;
9566 }
9567 else if (expand)
9568 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009569 buf = alloc(MAXPATHL);
9570 if (buf == NULL)
9571 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009572 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9573 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009574 {
9575 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009577 }
9578 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009579 }
9580 else if (put_escstr(fd, *valuep, 2) == FAIL)
9581 return FAIL;
9582 }
9583 if (put_eol(fd) < 0)
9584 return FAIL;
9585 return OK;
9586}
9587
9588 static int
9589put_setnum(fd, cmd, name, valuep)
9590 FILE *fd;
9591 char *cmd;
9592 char *name;
9593 long *valuep;
9594{
9595 long wc;
9596
9597 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9598 return FAIL;
9599 if (wc_use_keyname((char_u *)valuep, &wc))
9600 {
9601 /* print 'wildchar' and 'wildcharm' as a key name */
9602 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9603 return FAIL;
9604 }
9605 else if (fprintf(fd, "%ld", *valuep) < 0)
9606 return FAIL;
9607 if (put_eol(fd) < 0)
9608 return FAIL;
9609 return OK;
9610}
9611
9612 static int
9613put_setbool(fd, cmd, name, value)
9614 FILE *fd;
9615 char *cmd;
9616 char *name;
9617 int value;
9618{
Bram Moolenaar893de922007-10-02 18:40:57 +00009619 if (value < 0) /* global/local option using global value */
9620 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9622 || put_eol(fd) < 0)
9623 return FAIL;
9624 return OK;
9625}
9626
9627/*
9628 * Clear all the terminal options.
9629 * If the option has been allocated, free the memory.
9630 * Terminal options are never hidden or indirect.
9631 */
9632 void
9633clear_termoptions()
9634{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009635 /*
9636 * Reset a few things before clearing the old options. This may cause
9637 * outputting a few things that the terminal doesn't understand, but the
9638 * screen will be cleared later, so this is OK.
9639 */
9640#ifdef FEAT_MOUSE_TTY
9641 mch_setmouse(FALSE); /* switch mouse off */
9642#endif
9643#ifdef FEAT_TITLE
9644 mch_restore_title(3); /* restore window titles */
9645#endif
9646#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9647 /* When starting the GUI close the display opened for the clipboard.
9648 * After restoring the title, because that will need the display. */
9649 if (gui.starting)
9650 clear_xterm_clip();
9651#endif
9652#ifdef WIN3264
9653 /*
9654 * Check if this is allowed now.
9655 */
9656 if (can_end_termcap_mode(FALSE) == TRUE)
9657#endif
9658 stoptermcap(); /* stop termcap mode */
9659
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009660 free_termoptions();
9661}
9662
9663 void
9664free_termoptions()
9665{
9666 struct vimoption *p;
9667
Bram Moolenaar071d4272004-06-13 20:20:40 +00009668 for (p = &options[0]; p->fullname != NULL; p++)
9669 if (istermoption(p))
9670 {
9671 if (p->flags & P_ALLOCED)
9672 free_string_option(*(char_u **)(p->var));
9673 if (p->flags & P_DEF_ALLOCED)
9674 free_string_option(p->def_val[VI_DEFAULT]);
9675 *(char_u **)(p->var) = empty_option;
9676 p->def_val[VI_DEFAULT] = empty_option;
9677 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9678 }
9679 clear_termcodes();
9680}
9681
9682/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009683 * Free the string for one term option, if it was allocated.
9684 * Set the string to empty_option and clear allocated flag.
9685 * "var" points to the option value.
9686 */
9687 void
9688free_one_termoption(var)
9689 char_u *var;
9690{
9691 struct vimoption *p;
9692
9693 for (p = &options[0]; p->fullname != NULL; p++)
9694 if (p->var == var)
9695 {
9696 if (p->flags & P_ALLOCED)
9697 free_string_option(*(char_u **)(p->var));
9698 *(char_u **)(p->var) = empty_option;
9699 p->flags &= ~P_ALLOCED;
9700 break;
9701 }
9702}
9703
9704/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009705 * Set the terminal option defaults to the current value.
9706 * Used after setting the terminal name.
9707 */
9708 void
9709set_term_defaults()
9710{
9711 struct vimoption *p;
9712
9713 for (p = &options[0]; p->fullname != NULL; p++)
9714 {
9715 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9716 {
9717 if (p->flags & P_DEF_ALLOCED)
9718 {
9719 free_string_option(p->def_val[VI_DEFAULT]);
9720 p->flags &= ~P_DEF_ALLOCED;
9721 }
9722 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9723 if (p->flags & P_ALLOCED)
9724 {
9725 p->flags |= P_DEF_ALLOCED;
9726 p->flags &= ~P_ALLOCED; /* don't free the value now */
9727 }
9728 }
9729 }
9730}
9731
9732/*
9733 * return TRUE if 'p' starts with 't_'
9734 */
9735 static int
9736istermoption(p)
9737 struct vimoption *p;
9738{
9739 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9740}
9741
9742/*
9743 * Compute columns for ruler and shown command. 'sc_col' is also used to
9744 * decide what the maximum length of a message on the status line can be.
9745 * If there is a status line for the last window, 'sc_col' is independent
9746 * of 'ru_col'.
9747 */
9748
9749#define COL_RULER 17 /* columns needed by standard ruler */
9750
9751 void
9752comp_col()
9753{
9754#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9755 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9756
9757 sc_col = 0;
9758 ru_col = 0;
9759 if (p_ru)
9760 {
9761#ifdef FEAT_STL_OPT
9762 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9763#else
9764 ru_col = COL_RULER + 1;
9765#endif
9766 /* no last status line, adjust sc_col */
9767 if (!last_has_status)
9768 sc_col = ru_col;
9769 }
9770 if (p_sc)
9771 {
9772 sc_col += SHOWCMD_COLS;
9773 if (!p_ru || last_has_status) /* no need for separating space */
9774 ++sc_col;
9775 }
9776 sc_col = Columns - sc_col;
9777 ru_col = Columns - ru_col;
9778 if (sc_col <= 0) /* screen too narrow, will become a mess */
9779 sc_col = 1;
9780 if (ru_col <= 0)
9781 ru_col = 1;
9782#else
9783 sc_col = Columns;
9784 ru_col = Columns;
9785#endif
9786}
9787
9788/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009789 * Unset local option value, similar to ":set opt<".
9790 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009791 void
9792unset_global_local_option(name, from)
9793 char_u *name;
9794 void *from;
9795{
9796 struct vimoption *p;
9797 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009798 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009799
9800 opt_idx = findoption(name);
9801 p = &(options[opt_idx]);
9802
9803 switch ((int)p->indir)
9804 {
9805 /* global option with local value: use local value if it's been set */
9806 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009807 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009808 break;
9809 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009810 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009811 break;
9812 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009813 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009814 break;
9815 case PV_AR:
9816 buf->b_p_ar = -1;
9817 break;
9818 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009819 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009820 break;
9821#ifdef FEAT_FIND_ID
9822 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009823 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009824 break;
9825 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009826 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009827 break;
9828#endif
9829#ifdef FEAT_INS_EXPAND
9830 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009831 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009832 break;
9833 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009834 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009835 break;
9836#endif
9837#ifdef FEAT_QUICKFIX
9838 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009839 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009840 break;
9841 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009842 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009843 break;
9844 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009845 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009846 break;
9847#endif
9848#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9849 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009850 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009851 break;
9852#endif
9853#if defined(FEAT_CRYPT)
9854 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009855 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009856 break;
9857#endif
9858#ifdef FEAT_STL_OPT
9859 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009860 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009861 break;
9862#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009863 case PV_UL:
9864 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9865 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009866#ifdef FEAT_LISP
9867 case PV_LW:
9868 clear_string_option(&buf->b_p_lw);
9869 break;
9870#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009871 }
9872}
9873
9874/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009875 * Get pointer to option variable, depending on local or global scope.
9876 */
9877 static char_u *
9878get_varp_scope(p, opt_flags)
9879 struct vimoption *p;
9880 int opt_flags;
9881{
9882 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9883 {
9884 if (p->var == VAR_WIN)
9885 return (char_u *)GLOBAL_WO(get_varp(p));
9886 return p->var;
9887 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009888 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009889 {
9890 switch ((int)p->indir)
9891 {
9892#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009893 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9894 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9895 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009896#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009897 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9898 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9899 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009900 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009901 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009902#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009903 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9904 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009905#endif
9906#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009907 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9908 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009910#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9911 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9912#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009913#if defined(FEAT_CRYPT)
9914 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9915#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009916#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009917 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009918#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009919 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009920#ifdef FEAT_LISP
9921 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9922#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923 }
9924 return NULL; /* "cannot happen" */
9925 }
9926 return get_varp(p);
9927}
9928
9929/*
9930 * Get pointer to option variable.
9931 */
9932 static char_u *
9933get_varp(p)
9934 struct vimoption *p;
9935{
9936 /* hidden option, always return NULL */
9937 if (p->var == NULL)
9938 return NULL;
9939
9940 switch ((int)p->indir)
9941 {
9942 case PV_NONE: return p->var;
9943
9944 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009945 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009946 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009947 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009949 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009951 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009952 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009953 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009954 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9955#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009956 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009958 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9960#endif
9961#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009962 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009963 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009964 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9966#endif
9967#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009968 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009969 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009970 case PV_GP: return *curbuf->b_p_gp != NUL
9971 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9972 case PV_MP: return *curbuf->b_p_mp != NUL
9973 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009975#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9976 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9977 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9978#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009979#if defined(FEAT_CRYPT)
9980 case PV_CM: return *curbuf->b_p_cm != NUL
9981 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9982#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009983#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009984 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009985 ? (char_u *)&(curwin->w_p_stl) : p->var;
9986#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009987 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
9988 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009989#ifdef FEAT_LISP
9990 case PV_LW: return *curbuf->b_p_lw != NUL
9991 ? (char_u *)&(curbuf->b_p_lw) : p->var;
9992#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993
9994#ifdef FEAT_ARABIC
9995 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
9996#endif
9997 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00009998#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00009999 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10000#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010001#ifdef FEAT_SYN_HL
10002 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10003 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010004 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010005#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006#ifdef FEAT_DIFF
10007 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10008#endif
10009#ifdef FEAT_FOLDING
10010 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10011 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10012 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10013 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10014 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10015 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10016 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10017# ifdef FEAT_EVAL
10018 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10019 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10020# endif
10021 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10022#endif
10023 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010024 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010025#ifdef FEAT_LINEBREAK
10026 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10027#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010028#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10030#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010031#ifdef FEAT_VERTSPLIT
10032 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10035 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10036#endif
10037#ifdef FEAT_RIGHTLEFT
10038 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10039 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10040#endif
10041 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10042 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10043#ifdef FEAT_LINEBREAK
10044 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
10045#endif
10046#ifdef FEAT_SCROLLBIND
10047 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10048#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010049#ifdef FEAT_CURSORBIND
10050 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10051#endif
10052#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010053 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10054 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010055#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056
10057 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10058 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10059#ifdef FEAT_MBYTE
10060 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10061#endif
10062#if defined(FEAT_QUICKFIX)
10063 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10064 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10065#endif
10066 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10067 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10068#ifdef FEAT_CINDENT
10069 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10070 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10071 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10072#endif
10073#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10074 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10075#endif
10076#ifdef FEAT_COMMENTS
10077 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10078#endif
10079#ifdef FEAT_FOLDING
10080 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10081#endif
10082#ifdef FEAT_INS_EXPAND
10083 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10084#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010085#ifdef FEAT_COMPL_FUNC
10086 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010087 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010088#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010089 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10090 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10091#ifdef FEAT_MBYTE
10092 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10093#endif
10094 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10095#ifdef FEAT_AUTOCMD
10096 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10097#endif
10098 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010099 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010100 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10101 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10102 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10103 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10104#ifdef FEAT_FIND_ID
10105# ifdef FEAT_EVAL
10106 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10107# endif
10108#endif
10109#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10110 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10111 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10112#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010113#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010114 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10115#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116#ifdef FEAT_CRYPT
10117 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10118#endif
10119#ifdef FEAT_LISP
10120 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10121#endif
10122 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10123 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10124 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10125 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10126 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010128#ifdef FEAT_TEXTOBJ
10129 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10130#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10132#ifdef FEAT_SMARTINDENT
10133 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10134#endif
10135#ifndef SHORT_FNAME
10136 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10137#endif
10138 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10139#ifdef FEAT_SEARCHPATH
10140 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10141#endif
10142 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10143#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010144 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010145 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10146#endif
10147#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010148 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10149 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10150 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151#endif
10152 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10153 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10154 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10155 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010156#ifdef FEAT_PERSISTENT_UNDO
10157 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10158#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10160#ifdef FEAT_KEYMAP
10161 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10162#endif
10163 default: EMSG(_("E356: get_varp ERROR"));
10164 }
10165 /* always return a valid pointer to avoid a crash! */
10166 return (char_u *)&(curbuf->b_p_wm);
10167}
10168
10169/*
10170 * Get the value of 'equalprg', either the buffer-local one or the global one.
10171 */
10172 char_u *
10173get_equalprg()
10174{
10175 if (*curbuf->b_p_ep == NUL)
10176 return p_ep;
10177 return curbuf->b_p_ep;
10178}
10179
10180#if defined(FEAT_WINDOWS) || defined(PROTO)
10181/*
10182 * Copy options from one window to another.
10183 * Used when splitting a window.
10184 */
10185 void
10186win_copy_options(wp_from, wp_to)
10187 win_T *wp_from;
10188 win_T *wp_to;
10189{
10190 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10191 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10192# ifdef FEAT_RIGHTLEFT
10193# ifdef FEAT_FKMAP
10194 /* Is this right? */
10195 wp_to->w_farsi = wp_from->w_farsi;
10196# endif
10197# endif
10198}
10199#endif
10200
10201/*
10202 * Copy the options from one winopt_T to another.
10203 * Doesn't free the old option values in "to", use clear_winopt() for that.
10204 * The 'scroll' option is not copied, because it depends on the window height.
10205 * The 'previewwindow' option is reset, there can be only one preview window.
10206 */
10207 void
10208copy_winopt(from, to)
10209 winopt_T *from;
10210 winopt_T *to;
10211{
10212#ifdef FEAT_ARABIC
10213 to->wo_arab = from->wo_arab;
10214#endif
10215 to->wo_list = from->wo_list;
10216 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010217 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010218#ifdef FEAT_LINEBREAK
10219 to->wo_nuw = from->wo_nuw;
10220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221#ifdef FEAT_RIGHTLEFT
10222 to->wo_rl = from->wo_rl;
10223 to->wo_rlc = vim_strsave(from->wo_rlc);
10224#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010225#ifdef FEAT_STL_OPT
10226 to->wo_stl = vim_strsave(from->wo_stl);
10227#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010229#ifdef FEAT_DIFF
10230 to->wo_wrap_save = from->wo_wrap_save;
10231#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232#ifdef FEAT_LINEBREAK
10233 to->wo_lbr = from->wo_lbr;
10234#endif
10235#ifdef FEAT_SCROLLBIND
10236 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010237 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010238#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010239#ifdef FEAT_CURSORBIND
10240 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010241 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010242#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010243#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010244 to->wo_spell = from->wo_spell;
10245#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010246#ifdef FEAT_SYN_HL
10247 to->wo_cuc = from->wo_cuc;
10248 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010249 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010250#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251#ifdef FEAT_DIFF
10252 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010253 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010254#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010255#ifdef FEAT_CONCEAL
10256 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010257 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259#ifdef FEAT_FOLDING
10260 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010261 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010263 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264 to->wo_fdi = vim_strsave(from->wo_fdi);
10265 to->wo_fml = from->wo_fml;
10266 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010267 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010269 to->wo_fdm_save = from->wo_diff_saved
10270 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271 to->wo_fdn = from->wo_fdn;
10272# ifdef FEAT_EVAL
10273 to->wo_fde = vim_strsave(from->wo_fde);
10274 to->wo_fdt = vim_strsave(from->wo_fdt);
10275# endif
10276 to->wo_fmr = vim_strsave(from->wo_fmr);
10277#endif
10278 check_winopt(to); /* don't want NULL pointers */
10279}
10280
10281/*
10282 * Check string options in a window for a NULL value.
10283 */
10284 void
10285check_win_options(win)
10286 win_T *win;
10287{
10288 check_winopt(&win->w_onebuf_opt);
10289 check_winopt(&win->w_allbuf_opt);
10290}
10291
10292/*
10293 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10294 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010295 void
10296check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010297 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298{
10299#ifdef FEAT_FOLDING
10300 check_string_option(&wop->wo_fdi);
10301 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010302 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303# ifdef FEAT_EVAL
10304 check_string_option(&wop->wo_fde);
10305 check_string_option(&wop->wo_fdt);
10306# endif
10307 check_string_option(&wop->wo_fmr);
10308#endif
10309#ifdef FEAT_RIGHTLEFT
10310 check_string_option(&wop->wo_rlc);
10311#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010312#ifdef FEAT_STL_OPT
10313 check_string_option(&wop->wo_stl);
10314#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010315#ifdef FEAT_SYN_HL
10316 check_string_option(&wop->wo_cc);
10317#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010318#ifdef FEAT_CONCEAL
10319 check_string_option(&wop->wo_cocu);
10320#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321}
10322
10323/*
10324 * Free the allocated memory inside a winopt_T.
10325 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 void
10327clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010328 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329{
10330#ifdef FEAT_FOLDING
10331 clear_string_option(&wop->wo_fdi);
10332 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010333 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334# ifdef FEAT_EVAL
10335 clear_string_option(&wop->wo_fde);
10336 clear_string_option(&wop->wo_fdt);
10337# endif
10338 clear_string_option(&wop->wo_fmr);
10339#endif
10340#ifdef FEAT_RIGHTLEFT
10341 clear_string_option(&wop->wo_rlc);
10342#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010343#ifdef FEAT_STL_OPT
10344 clear_string_option(&wop->wo_stl);
10345#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010346#ifdef FEAT_SYN_HL
10347 clear_string_option(&wop->wo_cc);
10348#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010349#ifdef FEAT_CONCEAL
10350 clear_string_option(&wop->wo_cocu);
10351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352}
10353
10354/*
10355 * Copy global option values to local options for one buffer.
10356 * Used when creating a new buffer and sometimes when entering a buffer.
10357 * flags:
10358 * BCO_ENTER We will enter the buf buffer.
10359 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10360 * appropriate.
10361 * BCO_NOHELP Don't copy the values to a help buffer.
10362 */
10363 void
10364buf_copy_options(buf, flags)
10365 buf_T *buf;
10366 int flags;
10367{
10368 int should_copy = TRUE;
10369 char_u *save_p_isk = NULL; /* init for GCC */
10370 int dont_do_help;
10371 int did_isk = FALSE;
10372
10373 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010374 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375 */
10376 if (buf == NULL || !buf_valid(buf))
10377 return;
10378
10379 /*
10380 * Skip this when the option defaults have not been set yet. Happens when
10381 * main() allocates the first buffer.
10382 */
10383 if (p_cpo != NULL)
10384 {
10385 /*
10386 * Always copy when entering and 'cpo' contains 'S'.
10387 * Don't copy when already initialized.
10388 * Don't copy when 'cpo' contains 's' and not entering.
10389 * 'S' BCO_ENTER initialized 's' should_copy
10390 * yes yes X X TRUE
10391 * yes no yes X FALSE
10392 * no X yes X FALSE
10393 * X no no yes FALSE
10394 * X no no no TRUE
10395 * no yes no X TRUE
10396 */
10397 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10398 && (buf->b_p_initialized
10399 || (!(flags & BCO_ENTER)
10400 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10401 should_copy = FALSE;
10402
10403 if (should_copy || (flags & BCO_ALWAYS))
10404 {
10405 /* Don't copy the options specific to a help buffer when
10406 * BCO_NOHELP is given or the options were initialized already
10407 * (jumping back to a help file with CTRL-T or CTRL-O) */
10408 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10409 || buf->b_p_initialized;
10410 if (dont_do_help) /* don't free b_p_isk */
10411 {
10412 save_p_isk = buf->b_p_isk;
10413 buf->b_p_isk = NULL;
10414 }
10415 /*
10416 * Always free the allocated strings.
10417 * If not already initialized, set 'readonly' and copy 'fileformat'.
10418 */
10419 if (!buf->b_p_initialized)
10420 {
10421 free_buf_options(buf, TRUE);
10422 buf->b_p_ro = FALSE; /* don't copy readonly */
10423 buf->b_p_tx = p_tx;
10424#ifdef FEAT_MBYTE
10425 buf->b_p_fenc = vim_strsave(p_fenc);
10426#endif
10427 buf->b_p_ff = vim_strsave(p_ff);
10428#if defined(FEAT_QUICKFIX)
10429 buf->b_p_bh = empty_option;
10430 buf->b_p_bt = empty_option;
10431#endif
10432 }
10433 else
10434 free_buf_options(buf, FALSE);
10435
10436 buf->b_p_ai = p_ai;
10437 buf->b_p_ai_nopaste = p_ai_nopaste;
10438 buf->b_p_sw = p_sw;
10439 buf->b_p_tw = p_tw;
10440 buf->b_p_tw_nopaste = p_tw_nopaste;
10441 buf->b_p_tw_nobin = p_tw_nobin;
10442 buf->b_p_wm = p_wm;
10443 buf->b_p_wm_nopaste = p_wm_nopaste;
10444 buf->b_p_wm_nobin = p_wm_nobin;
10445 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010446#ifdef FEAT_MBYTE
10447 buf->b_p_bomb = p_bomb;
10448#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010449 buf->b_p_et = p_et;
10450 buf->b_p_et_nobin = p_et_nobin;
10451 buf->b_p_ml = p_ml;
10452 buf->b_p_ml_nobin = p_ml_nobin;
10453 buf->b_p_inf = p_inf;
10454 buf->b_p_swf = p_swf;
10455#ifdef FEAT_INS_EXPAND
10456 buf->b_p_cpt = vim_strsave(p_cpt);
10457#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010458#ifdef FEAT_COMPL_FUNC
10459 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010460 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010461#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462 buf->b_p_sts = p_sts;
10463 buf->b_p_sts_nopaste = p_sts_nopaste;
10464#ifndef SHORT_FNAME
10465 buf->b_p_sn = p_sn;
10466#endif
10467#ifdef FEAT_COMMENTS
10468 buf->b_p_com = vim_strsave(p_com);
10469#endif
10470#ifdef FEAT_FOLDING
10471 buf->b_p_cms = vim_strsave(p_cms);
10472#endif
10473 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010474 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475 buf->b_p_nf = vim_strsave(p_nf);
10476 buf->b_p_mps = vim_strsave(p_mps);
10477#ifdef FEAT_SMARTINDENT
10478 buf->b_p_si = p_si;
10479#endif
10480 buf->b_p_ci = p_ci;
10481#ifdef FEAT_CINDENT
10482 buf->b_p_cin = p_cin;
10483 buf->b_p_cink = vim_strsave(p_cink);
10484 buf->b_p_cino = vim_strsave(p_cino);
10485#endif
10486#ifdef FEAT_AUTOCMD
10487 /* Don't copy 'filetype', it must be detected */
10488 buf->b_p_ft = empty_option;
10489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490 buf->b_p_pi = p_pi;
10491#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10492 buf->b_p_cinw = vim_strsave(p_cinw);
10493#endif
10494#ifdef FEAT_LISP
10495 buf->b_p_lisp = p_lisp;
10496#endif
10497#ifdef FEAT_SYN_HL
10498 /* Don't copy 'syntax', it must be set */
10499 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010500 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010501#endif
10502#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010503 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010504 (void)compile_cap_prog(&buf->b_s);
10505 buf->b_s.b_p_spf = vim_strsave(p_spf);
10506 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507#endif
10508#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10509 buf->b_p_inde = vim_strsave(p_inde);
10510 buf->b_p_indk = vim_strsave(p_indk);
10511#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010512#if defined(FEAT_EVAL)
10513 buf->b_p_fex = vim_strsave(p_fex);
10514#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515#ifdef FEAT_CRYPT
10516 buf->b_p_key = vim_strsave(p_key);
10517#endif
10518#ifdef FEAT_SEARCHPATH
10519 buf->b_p_sua = vim_strsave(p_sua);
10520#endif
10521#ifdef FEAT_KEYMAP
10522 buf->b_p_keymap = vim_strsave(p_keymap);
10523 buf->b_kmap_state |= KEYMAP_INIT;
10524#endif
10525 /* This isn't really an option, but copying the langmap and IME
10526 * state from the current buffer is better than resetting it. */
10527 buf->b_p_iminsert = p_iminsert;
10528 buf->b_p_imsearch = p_imsearch;
10529
10530 /* options that are normally global but also have a local value
10531 * are not copied, start using the global value */
10532 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010533 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534#ifdef FEAT_QUICKFIX
10535 buf->b_p_gp = empty_option;
10536 buf->b_p_mp = empty_option;
10537 buf->b_p_efm = empty_option;
10538#endif
10539 buf->b_p_ep = empty_option;
10540 buf->b_p_kp = empty_option;
10541 buf->b_p_path = empty_option;
10542 buf->b_p_tags = empty_option;
10543#ifdef FEAT_FIND_ID
10544 buf->b_p_def = empty_option;
10545 buf->b_p_inc = empty_option;
10546# ifdef FEAT_EVAL
10547 buf->b_p_inex = vim_strsave(p_inex);
10548# endif
10549#endif
10550#ifdef FEAT_INS_EXPAND
10551 buf->b_p_dict = empty_option;
10552 buf->b_p_tsr = empty_option;
10553#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010554#ifdef FEAT_TEXTOBJ
10555 buf->b_p_qe = vim_strsave(p_qe);
10556#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010557#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10558 buf->b_p_bexpr = empty_option;
10559#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010560#if defined(FEAT_CRYPT)
10561 buf->b_p_cm = empty_option;
10562#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010563#ifdef FEAT_PERSISTENT_UNDO
10564 buf->b_p_udf = p_udf;
10565#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010566#ifdef FEAT_LISP
10567 buf->b_p_lw = empty_option;
10568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569
10570 /*
10571 * Don't copy the options set by ex_help(), use the saved values,
10572 * when going from a help buffer to a non-help buffer.
10573 * Don't touch these at all when BCO_NOHELP is used and going from
10574 * or to a help buffer.
10575 */
10576 if (dont_do_help)
10577 buf->b_p_isk = save_p_isk;
10578 else
10579 {
10580 buf->b_p_isk = vim_strsave(p_isk);
10581 did_isk = TRUE;
10582 buf->b_p_ts = p_ts;
10583 buf->b_help = FALSE;
10584#ifdef FEAT_QUICKFIX
10585 if (buf->b_p_bt[0] == 'h')
10586 clear_string_option(&buf->b_p_bt);
10587#endif
10588 buf->b_p_ma = p_ma;
10589 }
10590 }
10591
10592 /*
10593 * When the options should be copied (ignoring BCO_ALWAYS), set the
10594 * flag that indicates that the options have been initialized.
10595 */
10596 if (should_copy)
10597 buf->b_p_initialized = TRUE;
10598 }
10599
10600 check_buf_options(buf); /* make sure we don't have NULLs */
10601 if (did_isk)
10602 (void)buf_init_chartab(buf, FALSE);
10603}
10604
10605/*
10606 * Reset the 'modifiable' option and its default value.
10607 */
10608 void
10609reset_modifiable()
10610{
10611 int opt_idx;
10612
10613 curbuf->b_p_ma = FALSE;
10614 p_ma = FALSE;
10615 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010616 if (opt_idx >= 0)
10617 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618}
10619
10620/*
10621 * Set the global value for 'iminsert' to the local value.
10622 */
10623 void
10624set_iminsert_global()
10625{
10626 p_iminsert = curbuf->b_p_iminsert;
10627}
10628
10629/*
10630 * Set the global value for 'imsearch' to the local value.
10631 */
10632 void
10633set_imsearch_global()
10634{
10635 p_imsearch = curbuf->b_p_imsearch;
10636}
10637
10638#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10639static int expand_option_idx = -1;
10640static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10641static int expand_option_flags = 0;
10642
10643 void
10644set_context_in_set_cmd(xp, arg, opt_flags)
10645 expand_T *xp;
10646 char_u *arg;
10647 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10648{
10649 int nextchar;
10650 long_u flags = 0; /* init for GCC */
10651 int opt_idx = 0; /* init for GCC */
10652 char_u *p;
10653 char_u *s;
10654 int is_term_option = FALSE;
10655 int key;
10656
10657 expand_option_flags = opt_flags;
10658
10659 xp->xp_context = EXPAND_SETTINGS;
10660 if (*arg == NUL)
10661 {
10662 xp->xp_pattern = arg;
10663 return;
10664 }
10665 p = arg + STRLEN(arg) - 1;
10666 if (*p == ' ' && *(p - 1) != '\\')
10667 {
10668 xp->xp_pattern = p + 1;
10669 return;
10670 }
10671 while (p > arg)
10672 {
10673 s = p;
10674 /* count number of backslashes before ' ' or ',' */
10675 if (*p == ' ' || *p == ',')
10676 {
10677 while (s > arg && *(s - 1) == '\\')
10678 --s;
10679 }
10680 /* break at a space with an even number of backslashes */
10681 if (*p == ' ' && ((p - s) & 1) == 0)
10682 {
10683 ++p;
10684 break;
10685 }
10686 --p;
10687 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010688 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689 {
10690 xp->xp_context = EXPAND_BOOL_SETTINGS;
10691 p += 2;
10692 }
10693 if (STRNCMP(p, "inv", 3) == 0)
10694 {
10695 xp->xp_context = EXPAND_BOOL_SETTINGS;
10696 p += 3;
10697 }
10698 xp->xp_pattern = arg = p;
10699 if (*arg == '<')
10700 {
10701 while (*p != '>')
10702 if (*p++ == NUL) /* expand terminal option name */
10703 return;
10704 key = get_special_key_code(arg + 1);
10705 if (key == 0) /* unknown name */
10706 {
10707 xp->xp_context = EXPAND_NOTHING;
10708 return;
10709 }
10710 nextchar = *++p;
10711 is_term_option = TRUE;
10712 expand_option_name[2] = KEY2TERMCAP0(key);
10713 expand_option_name[3] = KEY2TERMCAP1(key);
10714 }
10715 else
10716 {
10717 if (p[0] == 't' && p[1] == '_')
10718 {
10719 p += 2;
10720 if (*p != NUL)
10721 ++p;
10722 if (*p == NUL)
10723 return; /* expand option name */
10724 nextchar = *++p;
10725 is_term_option = TRUE;
10726 expand_option_name[2] = p[-2];
10727 expand_option_name[3] = p[-1];
10728 }
10729 else
10730 {
10731 /* Allow * wildcard */
10732 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10733 p++;
10734 if (*p == NUL)
10735 return;
10736 nextchar = *p;
10737 *p = NUL;
10738 opt_idx = findoption(arg);
10739 *p = nextchar;
10740 if (opt_idx == -1 || options[opt_idx].var == NULL)
10741 {
10742 xp->xp_context = EXPAND_NOTHING;
10743 return;
10744 }
10745 flags = options[opt_idx].flags;
10746 if (flags & P_BOOL)
10747 {
10748 xp->xp_context = EXPAND_NOTHING;
10749 return;
10750 }
10751 }
10752 }
10753 /* handle "-=" and "+=" */
10754 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10755 {
10756 ++p;
10757 nextchar = '=';
10758 }
10759 if ((nextchar != '=' && nextchar != ':')
10760 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10761 {
10762 xp->xp_context = EXPAND_UNSUCCESSFUL;
10763 return;
10764 }
10765 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10766 {
10767 xp->xp_context = EXPAND_OLD_SETTING;
10768 if (is_term_option)
10769 expand_option_idx = -1;
10770 else
10771 expand_option_idx = opt_idx;
10772 xp->xp_pattern = p + 1;
10773 return;
10774 }
10775 xp->xp_context = EXPAND_NOTHING;
10776 if (is_term_option || (flags & P_NUM))
10777 return;
10778
10779 xp->xp_pattern = p + 1;
10780
10781 if (flags & P_EXPAND)
10782 {
10783 p = options[opt_idx].var;
10784 if (p == (char_u *)&p_bdir
10785 || p == (char_u *)&p_dir
10786 || p == (char_u *)&p_path
10787 || p == (char_u *)&p_rtp
10788#ifdef FEAT_SEARCHPATH
10789 || p == (char_u *)&p_cdpath
10790#endif
10791#ifdef FEAT_SESSION
10792 || p == (char_u *)&p_vdir
10793#endif
10794 )
10795 {
10796 xp->xp_context = EXPAND_DIRECTORIES;
10797 if (p == (char_u *)&p_path
10798#ifdef FEAT_SEARCHPATH
10799 || p == (char_u *)&p_cdpath
10800#endif
10801 )
10802 xp->xp_backslash = XP_BS_THREE;
10803 else
10804 xp->xp_backslash = XP_BS_ONE;
10805 }
10806 else
10807 {
10808 xp->xp_context = EXPAND_FILES;
10809 /* for 'tags' need three backslashes for a space */
10810 if (p == (char_u *)&p_tags)
10811 xp->xp_backslash = XP_BS_THREE;
10812 else
10813 xp->xp_backslash = XP_BS_ONE;
10814 }
10815 }
10816
10817 /* For an option that is a list of file names, find the start of the
10818 * last file name. */
10819 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10820 {
10821 /* count number of backslashes before ' ' or ',' */
10822 if (*p == ' ' || *p == ',')
10823 {
10824 s = p;
10825 while (s > xp->xp_pattern && *(s - 1) == '\\')
10826 --s;
10827 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10828 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10829 {
10830 xp->xp_pattern = p + 1;
10831 break;
10832 }
10833 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010834
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010835#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010836 /* for 'spellsuggest' start at "file:" */
10837 if (options[opt_idx].var == (char_u *)&p_sps
10838 && STRNCMP(p, "file:", 5) == 0)
10839 {
10840 xp->xp_pattern = p + 5;
10841 break;
10842 }
10843#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010844 }
10845
10846 return;
10847}
10848
10849 int
10850ExpandSettings(xp, regmatch, num_file, file)
10851 expand_T *xp;
10852 regmatch_T *regmatch;
10853 int *num_file;
10854 char_u ***file;
10855{
10856 int num_normal = 0; /* Nr of matching non-term-code settings */
10857 int num_term = 0; /* Nr of matching terminal code settings */
10858 int opt_idx;
10859 int match;
10860 int count = 0;
10861 char_u *str;
10862 int loop;
10863 int is_term_opt;
10864 char_u name_buf[MAX_KEY_NAME_LEN];
10865 static char *(names[]) = {"all", "termcap"};
10866 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10867
10868 /* do this loop twice:
10869 * loop == 0: count the number of matching options
10870 * loop == 1: copy the matching options into allocated memory
10871 */
10872 for (loop = 0; loop <= 1; ++loop)
10873 {
10874 regmatch->rm_ic = ic;
10875 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10876 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010877 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10878 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10880 {
10881 if (loop == 0)
10882 num_normal++;
10883 else
10884 (*file)[count++] = vim_strsave((char_u *)names[match]);
10885 }
10886 }
10887 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10888 opt_idx++)
10889 {
10890 if (options[opt_idx].var == NULL)
10891 continue;
10892 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10893 && !(options[opt_idx].flags & P_BOOL))
10894 continue;
10895 is_term_opt = istermoption(&options[opt_idx]);
10896 if (is_term_opt && num_normal > 0)
10897 continue;
10898 match = FALSE;
10899 if (vim_regexec(regmatch, str, (colnr_T)0)
10900 || (options[opt_idx].shortname != NULL
10901 && vim_regexec(regmatch,
10902 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10903 match = TRUE;
10904 else if (is_term_opt)
10905 {
10906 name_buf[0] = '<';
10907 name_buf[1] = 't';
10908 name_buf[2] = '_';
10909 name_buf[3] = str[2];
10910 name_buf[4] = str[3];
10911 name_buf[5] = '>';
10912 name_buf[6] = NUL;
10913 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10914 {
10915 match = TRUE;
10916 str = name_buf;
10917 }
10918 }
10919 if (match)
10920 {
10921 if (loop == 0)
10922 {
10923 if (is_term_opt)
10924 num_term++;
10925 else
10926 num_normal++;
10927 }
10928 else
10929 (*file)[count++] = vim_strsave(str);
10930 }
10931 }
10932 /*
10933 * Check terminal key codes, these are not in the option table
10934 */
10935 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10936 {
10937 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10938 {
10939 if (!isprint(str[0]) || !isprint(str[1]))
10940 continue;
10941
10942 name_buf[0] = 't';
10943 name_buf[1] = '_';
10944 name_buf[2] = str[0];
10945 name_buf[3] = str[1];
10946 name_buf[4] = NUL;
10947
10948 match = FALSE;
10949 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10950 match = TRUE;
10951 else
10952 {
10953 name_buf[0] = '<';
10954 name_buf[1] = 't';
10955 name_buf[2] = '_';
10956 name_buf[3] = str[0];
10957 name_buf[4] = str[1];
10958 name_buf[5] = '>';
10959 name_buf[6] = NUL;
10960
10961 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10962 match = TRUE;
10963 }
10964 if (match)
10965 {
10966 if (loop == 0)
10967 num_term++;
10968 else
10969 (*file)[count++] = vim_strsave(name_buf);
10970 }
10971 }
10972
10973 /*
10974 * Check special key names.
10975 */
10976 regmatch->rm_ic = TRUE; /* ignore case here */
10977 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10978 {
10979 name_buf[0] = '<';
10980 STRCPY(name_buf + 1, str);
10981 STRCAT(name_buf, ">");
10982
10983 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10984 {
10985 if (loop == 0)
10986 num_term++;
10987 else
10988 (*file)[count++] = vim_strsave(name_buf);
10989 }
10990 }
10991 }
10992 if (loop == 0)
10993 {
10994 if (num_normal > 0)
10995 *num_file = num_normal;
10996 else if (num_term > 0)
10997 *num_file = num_term;
10998 else
10999 return OK;
11000 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11001 if (*file == NULL)
11002 {
11003 *file = (char_u **)"";
11004 return FAIL;
11005 }
11006 }
11007 }
11008 return OK;
11009}
11010
11011 int
11012ExpandOldSetting(num_file, file)
11013 int *num_file;
11014 char_u ***file;
11015{
11016 char_u *var = NULL; /* init for GCC */
11017 char_u *buf;
11018
11019 *num_file = 0;
11020 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11021 if (*file == NULL)
11022 return FAIL;
11023
11024 /*
11025 * For a terminal key code expand_option_idx is < 0.
11026 */
11027 if (expand_option_idx < 0)
11028 {
11029 var = find_termcode(expand_option_name + 2);
11030 if (var == NULL)
11031 expand_option_idx = findoption(expand_option_name);
11032 }
11033
11034 if (expand_option_idx >= 0)
11035 {
11036 /* put string of option value in NameBuff */
11037 option_value2string(&options[expand_option_idx], expand_option_flags);
11038 var = NameBuff;
11039 }
11040 else if (var == NULL)
11041 var = (char_u *)"";
11042
11043 /* A backslash is required before some characters. This is the reverse of
11044 * what happens in do_set(). */
11045 buf = vim_strsave_escaped(var, escape_chars);
11046
11047 if (buf == NULL)
11048 {
11049 vim_free(*file);
11050 *file = NULL;
11051 return FAIL;
11052 }
11053
11054#ifdef BACKSLASH_IN_FILENAME
11055 /* For MS-Windows et al. we don't double backslashes at the start and
11056 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011057 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011058 if (var[0] == '\\' && var[1] == '\\'
11059 && expand_option_idx >= 0
11060 && (options[expand_option_idx].flags & P_EXPAND)
11061 && vim_isfilec(var[2])
11062 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011063 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011064#endif
11065
11066 *file[0] = buf;
11067 *num_file = 1;
11068 return OK;
11069}
11070#endif
11071
11072/*
11073 * Get the value for the numeric or string option *opp in a nice format into
11074 * NameBuff[]. Must not be called with a hidden option!
11075 */
11076 static void
11077option_value2string(opp, opt_flags)
11078 struct vimoption *opp;
11079 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11080{
11081 char_u *varp;
11082
11083 varp = get_varp_scope(opp, opt_flags);
11084
11085 if (opp->flags & P_NUM)
11086 {
11087 long wc = 0;
11088
11089 if (wc_use_keyname(varp, &wc))
11090 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11091 else if (wc != 0)
11092 STRCPY(NameBuff, transchar((int)wc));
11093 else
11094 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11095 }
11096 else /* P_STRING */
11097 {
11098 varp = *(char_u **)(varp);
11099 if (varp == NULL) /* just in case */
11100 NameBuff[0] = NUL;
11101#ifdef FEAT_CRYPT
11102 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011103 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104 STRCPY(NameBuff, "*****");
11105#endif
11106 else if (opp->flags & P_EXPAND)
11107 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11108 /* Translate 'pastetoggle' into special key names */
11109 else if ((char_u **)opp->var == &p_pt)
11110 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11111 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011112 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113 }
11114}
11115
11116/*
11117 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11118 * printed as a keyname.
11119 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11120 */
11121 static int
11122wc_use_keyname(varp, wcp)
11123 char_u *varp;
11124 long *wcp;
11125{
11126 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11127 {
11128 *wcp = *(long *)varp;
11129 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11130 return TRUE;
11131 }
11132 return FALSE;
11133}
11134
11135#ifdef FEAT_LANGMAP
11136/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011137 * Any character has an equivalent 'langmap' character. This is used for
11138 * keyboards that have a special language mode that sends characters above
11139 * 128 (although other characters can be translated too). The "to" field is a
11140 * Vim command character. This avoids having to switch the keyboard back to
11141 * ASCII mode when leaving Insert mode.
11142 *
11143 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11144 * commands.
11145 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11146 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11147 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011149# ifdef FEAT_MBYTE
11150/*
11151 * With multi-byte support use growarray for 'langmap' chars >= 256
11152 */
11153typedef struct
11154{
11155 int from;
11156 int to;
11157} langmap_entry_T;
11158
11159static garray_T langmap_mapga;
11160static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011161
11162/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011163 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11164 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011166 static void
11167langmap_set_entry(from, to)
11168 int from;
11169 int to;
11170{
11171 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011172 int a = 0;
11173 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011174
11175 /* Do a binary search for an existing entry. */
11176 while (a != b)
11177 {
11178 int i = (a + b) / 2;
11179 int d = entries[i].from - from;
11180
11181 if (d == 0)
11182 {
11183 entries[i].to = to;
11184 return;
11185 }
11186 if (d < 0)
11187 a = i + 1;
11188 else
11189 b = i;
11190 }
11191
11192 if (ga_grow(&langmap_mapga, 1) != OK)
11193 return; /* out of memory */
11194
11195 /* insert new entry at position "a" */
11196 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11197 mch_memmove(entries + 1, entries,
11198 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11199 ++langmap_mapga.ga_len;
11200 entries[0].from = from;
11201 entries[0].to = to;
11202}
11203
11204/*
11205 * Apply 'langmap' to multi-byte character "c" and return the result.
11206 */
11207 int
11208langmap_adjust_mb(c)
11209 int c;
11210{
11211 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11212 int a = 0;
11213 int b = langmap_mapga.ga_len;
11214
11215 while (a != b)
11216 {
11217 int i = (a + b) / 2;
11218 int d = entries[i].from - c;
11219
11220 if (d == 0)
11221 return entries[i].to; /* found matching entry */
11222 if (d < 0)
11223 a = i + 1;
11224 else
11225 b = i;
11226 }
11227 return c; /* no entry found, return "c" unmodified */
11228}
11229# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011230
11231 static void
11232langmap_init()
11233{
11234 int i;
11235
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011236 for (i = 0; i < 256; i++)
11237 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11238# ifdef FEAT_MBYTE
11239 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11240# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011241}
11242
11243/*
11244 * Called when langmap option is set; the language map can be
11245 * changed at any time!
11246 */
11247 static void
11248langmap_set()
11249{
11250 char_u *p;
11251 char_u *p2;
11252 int from, to;
11253
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011254#ifdef FEAT_MBYTE
11255 ga_clear(&langmap_mapga); /* clear the previous map first */
11256#endif
11257 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011258
11259 for (p = p_langmap; p[0] != NUL; )
11260 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011261 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11262 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011263 {
11264 if (p2[0] == '\\' && p2[1] != NUL)
11265 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266 }
11267 if (p2[0] == ';')
11268 ++p2; /* abcd;ABCD form, p2 points to A */
11269 else
11270 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11271 while (p[0])
11272 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011273 if (p[0] == ',')
11274 {
11275 ++p;
11276 break;
11277 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278 if (p[0] == '\\' && p[1] != NUL)
11279 ++p;
11280#ifdef FEAT_MBYTE
11281 from = (*mb_ptr2char)(p);
11282#else
11283 from = p[0];
11284#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011285 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286 if (p2 == NULL)
11287 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011288 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011289 if (p[0] != ',')
11290 {
11291 if (p[0] == '\\')
11292 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011293#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011294 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011295#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011296 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011298 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011299 }
11300 else
11301 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011302 if (p2[0] != ',')
11303 {
11304 if (p2[0] == '\\')
11305 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011306#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011307 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011309 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011311 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011312 }
11313 if (to == NUL)
11314 {
11315 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11316 transchar(from));
11317 return;
11318 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011319
11320#ifdef FEAT_MBYTE
11321 if (from >= 256)
11322 langmap_set_entry(from, to);
11323 else
11324#endif
11325 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326
11327 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011328 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011329 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011331 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332 if (*p == ';')
11333 {
11334 p = p2;
11335 if (p[0] != NUL)
11336 {
11337 if (p[0] != ',')
11338 {
11339 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11340 return;
11341 }
11342 ++p;
11343 }
11344 break;
11345 }
11346 }
11347 }
11348 }
11349}
11350#endif
11351
11352/*
11353 * Return TRUE if format option 'x' is in effect.
11354 * Take care of no formatting when 'paste' is set.
11355 */
11356 int
11357has_format_option(x)
11358 int x;
11359{
11360 if (p_paste)
11361 return FALSE;
11362 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11363}
11364
11365/*
11366 * Return TRUE if "x" is present in 'shortmess' option, or
11367 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11368 */
11369 int
11370shortmess(x)
11371 int x;
11372{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011373 return p_shm != NULL &&
11374 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011375 || (vim_strchr(p_shm, 'a') != NULL
11376 && vim_strchr((char_u *)SHM_A, x) != NULL));
11377}
11378
11379/*
11380 * paste_option_changed() - Called after p_paste was set or reset.
11381 */
11382 static void
11383paste_option_changed()
11384{
11385 static int old_p_paste = FALSE;
11386 static int save_sm = 0;
11387#ifdef FEAT_CMDL_INFO
11388 static int save_ru = 0;
11389#endif
11390#ifdef FEAT_RIGHTLEFT
11391 static int save_ri = 0;
11392 static int save_hkmap = 0;
11393#endif
11394 buf_T *buf;
11395
11396 if (p_paste)
11397 {
11398 /*
11399 * Paste switched from off to on.
11400 * Save the current values, so they can be restored later.
11401 */
11402 if (!old_p_paste)
11403 {
11404 /* save options for each buffer */
11405 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11406 {
11407 buf->b_p_tw_nopaste = buf->b_p_tw;
11408 buf->b_p_wm_nopaste = buf->b_p_wm;
11409 buf->b_p_sts_nopaste = buf->b_p_sts;
11410 buf->b_p_ai_nopaste = buf->b_p_ai;
11411 }
11412
11413 /* save global options */
11414 save_sm = p_sm;
11415#ifdef FEAT_CMDL_INFO
11416 save_ru = p_ru;
11417#endif
11418#ifdef FEAT_RIGHTLEFT
11419 save_ri = p_ri;
11420 save_hkmap = p_hkmap;
11421#endif
11422 /* save global values for local buffer options */
11423 p_tw_nopaste = p_tw;
11424 p_wm_nopaste = p_wm;
11425 p_sts_nopaste = p_sts;
11426 p_ai_nopaste = p_ai;
11427 }
11428
11429 /*
11430 * Always set the option values, also when 'paste' is set when it is
11431 * already on.
11432 */
11433 /* set options for each buffer */
11434 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11435 {
11436 buf->b_p_tw = 0; /* textwidth is 0 */
11437 buf->b_p_wm = 0; /* wrapmargin is 0 */
11438 buf->b_p_sts = 0; /* softtabstop is 0 */
11439 buf->b_p_ai = 0; /* no auto-indent */
11440 }
11441
11442 /* set global options */
11443 p_sm = 0; /* no showmatch */
11444#ifdef FEAT_CMDL_INFO
11445# ifdef FEAT_WINDOWS
11446 if (p_ru)
11447 status_redraw_all(); /* redraw to remove the ruler */
11448# endif
11449 p_ru = 0; /* no ruler */
11450#endif
11451#ifdef FEAT_RIGHTLEFT
11452 p_ri = 0; /* no reverse insert */
11453 p_hkmap = 0; /* no Hebrew keyboard */
11454#endif
11455 /* set global values for local buffer options */
11456 p_tw = 0;
11457 p_wm = 0;
11458 p_sts = 0;
11459 p_ai = 0;
11460 }
11461
11462 /*
11463 * Paste switched from on to off: Restore saved values.
11464 */
11465 else if (old_p_paste)
11466 {
11467 /* restore options for each buffer */
11468 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11469 {
11470 buf->b_p_tw = buf->b_p_tw_nopaste;
11471 buf->b_p_wm = buf->b_p_wm_nopaste;
11472 buf->b_p_sts = buf->b_p_sts_nopaste;
11473 buf->b_p_ai = buf->b_p_ai_nopaste;
11474 }
11475
11476 /* restore global options */
11477 p_sm = save_sm;
11478#ifdef FEAT_CMDL_INFO
11479# ifdef FEAT_WINDOWS
11480 if (p_ru != save_ru)
11481 status_redraw_all(); /* redraw to draw the ruler */
11482# endif
11483 p_ru = save_ru;
11484#endif
11485#ifdef FEAT_RIGHTLEFT
11486 p_ri = save_ri;
11487 p_hkmap = save_hkmap;
11488#endif
11489 /* set global values for local buffer options */
11490 p_tw = p_tw_nopaste;
11491 p_wm = p_wm_nopaste;
11492 p_sts = p_sts_nopaste;
11493 p_ai = p_ai_nopaste;
11494 }
11495
11496 old_p_paste = p_paste;
11497}
11498
11499/*
11500 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11501 *
11502 * Reset 'compatible' and set the values for options that didn't get set yet
11503 * to the Vim defaults.
11504 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011505 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011506 */
11507 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011508vimrc_found(fname, envname)
11509 char_u *fname;
11510 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011512 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011513 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011514 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011515
11516 if (!option_was_set((char_u *)"cp"))
11517 {
11518 p_cp = FALSE;
11519 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11520 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11521 set_option_default(opt_idx, OPT_FREE, FALSE);
11522 didset_options();
11523 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011524
11525 if (fname != NULL)
11526 {
11527 p = vim_getenv(envname, &dofree);
11528 if (p == NULL)
11529 {
11530 /* Set $MYVIMRC to the first vimrc file found. */
11531 p = FullName_save(fname, FALSE);
11532 if (p != NULL)
11533 {
11534 vim_setenv(envname, p);
11535 vim_free(p);
11536 }
11537 }
11538 else if (dofree)
11539 vim_free(p);
11540 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011541}
11542
11543/*
11544 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11545 */
11546 void
11547change_compatible(on)
11548 int on;
11549{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011550 int opt_idx;
11551
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552 if (p_cp != on)
11553 {
11554 p_cp = on;
11555 compatible_set();
11556 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011557 opt_idx = findoption((char_u *)"cp");
11558 if (opt_idx >= 0)
11559 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011560}
11561
11562/*
11563 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011564 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011565 */
11566 int
11567option_was_set(name)
11568 char_u *name;
11569{
11570 int idx;
11571
11572 idx = findoption(name);
11573 if (idx < 0) /* unknown option */
11574 return FALSE;
11575 if (options[idx].flags & P_WAS_SET)
11576 return TRUE;
11577 return FALSE;
11578}
11579
11580/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011581 * Reset the flag indicating option "name" was set.
11582 */
11583 void
11584reset_option_was_set(name)
11585 char_u *name;
11586{
11587 int idx = findoption(name);
11588
11589 if (idx >= 0)
11590 options[idx].flags &= ~P_WAS_SET;
11591}
11592
11593/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594 * compatible_set() - Called when 'compatible' has been set or unset.
11595 *
11596 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11597 * flag) to a Vi compatible value.
11598 * When 'compatible' is unset: Set all options that have a different default
11599 * for Vim (without the P_VI_DEF flag) to that default.
11600 */
11601 static void
11602compatible_set()
11603{
11604 int opt_idx;
11605
11606 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11607 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11608 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11609 set_option_default(opt_idx, OPT_FREE, p_cp);
11610 didset_options();
11611}
11612
11613#ifdef FEAT_LINEBREAK
11614
11615# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11616 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011617 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011618# endif
11619
11620/*
11621 * fill_breakat_flags() -- called when 'breakat' changes value.
11622 */
11623 static void
11624fill_breakat_flags()
11625{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011626 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011627 int i;
11628
11629 for (i = 0; i < 256; i++)
11630 breakat_flags[i] = FALSE;
11631
11632 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011633 for (p = p_breakat; *p; p++)
11634 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635}
11636
11637# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011638 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011639# endif
11640
11641#endif
11642
11643/*
11644 * Check an option that can be a range of string values.
11645 *
11646 * Return OK for correct value, FAIL otherwise.
11647 * Empty is always OK.
11648 */
11649 static int
11650check_opt_strings(val, values, list)
11651 char_u *val;
11652 char **values;
11653 int list; /* when TRUE: accept a list of values */
11654{
11655 return opt_strings_flags(val, values, NULL, list);
11656}
11657
11658/*
11659 * Handle an option that can be a range of string values.
11660 * Set a flag in "*flagp" for each string present.
11661 *
11662 * Return OK for correct value, FAIL otherwise.
11663 * Empty is always OK.
11664 */
11665 static int
11666opt_strings_flags(val, values, flagp, list)
11667 char_u *val; /* new value */
11668 char **values; /* array of valid string values */
11669 unsigned *flagp;
11670 int list; /* when TRUE: accept a list of values */
11671{
11672 int i;
11673 int len;
11674 unsigned new_flags = 0;
11675
11676 while (*val)
11677 {
11678 for (i = 0; ; ++i)
11679 {
11680 if (values[i] == NULL) /* val not found in values[] */
11681 return FAIL;
11682
11683 len = (int)STRLEN(values[i]);
11684 if (STRNCMP(values[i], val, len) == 0
11685 && ((list && val[len] == ',') || val[len] == NUL))
11686 {
11687 val += len + (val[len] == ',');
11688 new_flags |= (1 << i);
11689 break; /* check next item in val list */
11690 }
11691 }
11692 }
11693 if (flagp != NULL)
11694 *flagp = new_flags;
11695
11696 return OK;
11697}
11698
11699/*
11700 * Read the 'wildmode' option, fill wim_flags[].
11701 */
11702 static int
11703check_opt_wim()
11704{
11705 char_u new_wim_flags[4];
11706 char_u *p;
11707 int i;
11708 int idx = 0;
11709
11710 for (i = 0; i < 4; ++i)
11711 new_wim_flags[i] = 0;
11712
11713 for (p = p_wim; *p; ++p)
11714 {
11715 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11716 ;
11717 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11718 return FAIL;
11719 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11720 new_wim_flags[idx] |= WIM_LONGEST;
11721 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11722 new_wim_flags[idx] |= WIM_FULL;
11723 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11724 new_wim_flags[idx] |= WIM_LIST;
11725 else
11726 return FAIL;
11727 p += i;
11728 if (*p == NUL)
11729 break;
11730 if (*p == ',')
11731 {
11732 if (idx == 3)
11733 return FAIL;
11734 ++idx;
11735 }
11736 }
11737
11738 /* fill remaining entries with last flag */
11739 while (idx < 3)
11740 {
11741 new_wim_flags[idx + 1] = new_wim_flags[idx];
11742 ++idx;
11743 }
11744
11745 /* only when there are no errors, wim_flags[] is changed */
11746 for (i = 0; i < 4; ++i)
11747 wim_flags[i] = new_wim_flags[i];
11748 return OK;
11749}
11750
11751/*
11752 * Check if backspacing over something is allowed.
11753 */
11754 int
11755can_bs(what)
11756 int what; /* BS_INDENT, BS_EOL or BS_START */
11757{
11758 switch (*p_bs)
11759 {
11760 case '2': return TRUE;
11761 case '1': return (what != BS_START);
11762 case '0': return FALSE;
11763 }
11764 return vim_strchr(p_bs, what) != NULL;
11765}
11766
11767/*
11768 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11769 * the file must be considered changed when the value is different.
11770 */
11771 void
11772save_file_ff(buf)
11773 buf_T *buf;
11774{
11775 buf->b_start_ffc = *buf->b_p_ff;
11776 buf->b_start_eol = buf->b_p_eol;
11777#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011778 buf->b_start_bomb = buf->b_p_bomb;
11779
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780 /* Only use free/alloc when necessary, they take time. */
11781 if (buf->b_start_fenc == NULL
11782 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11783 {
11784 vim_free(buf->b_start_fenc);
11785 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11786 }
11787#endif
11788}
11789
11790/*
11791 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11792 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011793 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11794 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011795 * When "ignore_empty" is true don't consider a new, empty buffer to be
11796 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011797 */
11798 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011799file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011800 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011801 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011803 /* In a buffer that was never loaded the options are not valid. */
11804 if (buf->b_flags & BF_NEVERLOADED)
11805 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011806 if (ignore_empty
11807 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011808 && buf->b_ml.ml_line_count == 1
11809 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11810 return FALSE;
11811 if (buf->b_start_ffc != *buf->b_p_ff)
11812 return TRUE;
11813 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11814 return TRUE;
11815#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011816 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11817 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011818 if (buf->b_start_fenc == NULL)
11819 return (*buf->b_p_fenc != NUL);
11820 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11821#else
11822 return FALSE;
11823#endif
11824}
11825
11826/*
11827 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11828 */
11829 int
11830check_ff_value(p)
11831 char_u *p;
11832{
11833 return check_opt_strings(p, p_ff_values, FALSE);
11834}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011835
11836/*
11837 * Return the effective shiftwidth value for current buffer, using the
11838 * 'tabstop' value when 'shiftwidth' is zero.
11839 */
11840 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011841get_sw_value(buf)
11842 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011843{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011844 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011845}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011846
11847/*
11848 * Return the effective softtabstop value for the current buffer, using the
11849 * 'tabstop' value when 'softtabstop' is negative.
11850 */
11851 long
11852get_sts_value()
11853{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011854 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011855}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011856
11857/*
11858 * Check matchpairs option for "*initc".
11859 * If there is a match set "*initc" to the matching character and "*findc" to
11860 * the opposite character. Set "*backwards" to the direction.
11861 * When "switchit" is TRUE swap the direction.
11862 */
11863 void
11864find_mps_values(initc, findc, backwards, switchit)
11865 int *initc;
11866 int *findc;
11867 int *backwards;
11868 int switchit;
11869{
11870 char_u *ptr;
11871
11872 ptr = curbuf->b_p_mps;
11873 while (*ptr != NUL)
11874 {
11875#ifdef FEAT_MBYTE
11876 if (has_mbyte)
11877 {
11878 char_u *prev;
11879
11880 if (mb_ptr2char(ptr) == *initc)
11881 {
11882 if (switchit)
11883 {
11884 *findc = *initc;
11885 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11886 *backwards = TRUE;
11887 }
11888 else
11889 {
11890 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11891 *backwards = FALSE;
11892 }
11893 return;
11894 }
11895 prev = ptr;
11896 ptr += mb_ptr2len(ptr) + 1;
11897 if (mb_ptr2char(ptr) == *initc)
11898 {
11899 if (switchit)
11900 {
11901 *findc = *initc;
11902 *initc = mb_ptr2char(prev);
11903 *backwards = FALSE;
11904 }
11905 else
11906 {
11907 *findc = mb_ptr2char(prev);
11908 *backwards = TRUE;
11909 }
11910 return;
11911 }
11912 ptr += mb_ptr2len(ptr);
11913 }
11914 else
11915#endif
11916 {
11917 if (*ptr == *initc)
11918 {
11919 if (switchit)
11920 {
11921 *backwards = TRUE;
11922 *findc = *initc;
11923 *initc = ptr[2];
11924 }
11925 else
11926 {
11927 *backwards = FALSE;
11928 *findc = ptr[2];
11929 }
11930 return;
11931 }
11932 ptr += 2;
11933 if (*ptr == *initc)
11934 {
11935 if (switchit)
11936 {
11937 *backwards = FALSE;
11938 *findc = *initc;
11939 *initc = ptr[-2];
11940 }
11941 else
11942 {
11943 *backwards = TRUE;
11944 *findc = ptr[-2];
11945 }
11946 return;
11947 }
11948 ++ptr;
11949 }
11950 if (*ptr == ',')
11951 ++ptr;
11952 }
11953}