blob: 40dcc8d7b9f2bea053412cb40a9d35e4ebdb63b2 [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 Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000110#ifdef FEAT_EVAL
111# define PV_FEX OPT_BUF(BV_FEX)
112#endif
113#define PV_FF OPT_BUF(BV_FF)
114#define PV_FLP OPT_BUF(BV_FLP)
115#define PV_FO OPT_BUF(BV_FO)
116#ifdef FEAT_AUTOCMD
117# define PV_FT OPT_BUF(BV_FT)
118#endif
119#define PV_IMI OPT_BUF(BV_IMI)
120#define PV_IMS OPT_BUF(BV_IMS)
121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
122# define PV_INDE OPT_BUF(BV_INDE)
123# define PV_INDK OPT_BUF(BV_INDK)
124#endif
125#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
126# define PV_INEX OPT_BUF(BV_INEX)
127#endif
128#define PV_INF OPT_BUF(BV_INF)
129#define PV_ISK OPT_BUF(BV_ISK)
130#ifdef FEAT_CRYPT
131# define PV_KEY OPT_BUF(BV_KEY)
132#endif
133#ifdef FEAT_KEYMAP
134# define PV_KMAP OPT_BUF(BV_KMAP)
135#endif
136#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
137#ifdef FEAT_LISP
138# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100139# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000140#endif
141#define PV_MA OPT_BUF(BV_MA)
142#define PV_ML OPT_BUF(BV_ML)
143#define PV_MOD OPT_BUF(BV_MOD)
144#define PV_MPS OPT_BUF(BV_MPS)
145#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200180#ifdef FEAT_PERSISTENT_UNDO
181# define PV_UDF OPT_BUF(BV_UDF)
182#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184
185/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186 * Definition of the PV_ values for window-local options.
187 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189#define PV_LIST OPT_WIN(WV_LIST)
190#ifdef FEAT_ARABIC
191# define PV_ARAB OPT_WIN(WV_ARAB)
192#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200193#ifdef FEAT_LINEBREAK
194# define PV_BRI OPT_WIN(WV_BRI)
195# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
196#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000197#ifdef FEAT_DIFF
198# define PV_DIFF OPT_WIN(WV_DIFF)
199#endif
200#ifdef FEAT_FOLDING
201# define PV_FDC OPT_WIN(WV_FDC)
202# define PV_FEN OPT_WIN(WV_FEN)
203# define PV_FDI OPT_WIN(WV_FDI)
204# define PV_FDL OPT_WIN(WV_FDL)
205# define PV_FDM OPT_WIN(WV_FDM)
206# define PV_FML OPT_WIN(WV_FML)
207# define PV_FDN OPT_WIN(WV_FDN)
208# ifdef FEAT_EVAL
209# define PV_FDE OPT_WIN(WV_FDE)
210# define PV_FDT OPT_WIN(WV_FDT)
211# endif
212# define PV_FMR OPT_WIN(WV_FMR)
213#endif
214#ifdef FEAT_LINEBREAK
215# define PV_LBR OPT_WIN(WV_LBR)
216#endif
217#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200218#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000219#ifdef FEAT_LINEBREAK
220# define PV_NUW OPT_WIN(WV_NUW)
221#endif
222#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
223# define PV_PVW OPT_WIN(WV_PVW)
224#endif
225#ifdef FEAT_RIGHTLEFT
226# define PV_RL OPT_WIN(WV_RL)
227# define PV_RLC OPT_WIN(WV_RLC)
228#endif
229#ifdef FEAT_SCROLLBIND
230# define PV_SCBIND OPT_WIN(WV_SCBIND)
231#endif
232#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234# define PV_SPELL OPT_WIN(WV_SPELL)
235#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SYN_HL
237# define PV_CUC OPT_WIN(WV_CUC)
238# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200239# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000240#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000241#ifdef FEAT_STL_OPT
242# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
243#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100244#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#ifdef FEAT_WINDOWS
246# define PV_WFH OPT_WIN(WV_WFH)
247#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000248#ifdef FEAT_VERTSPLIT
249# define PV_WFW OPT_WIN(WV_WFW)
250#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000251#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200252#ifdef FEAT_CURSORBIND
253# define PV_CRBIND OPT_WIN(WV_CRBIND)
254#endif
255#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200256# define PV_COCU OPT_WIN(WV_COCU)
257# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200258#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000259
260/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261typedef enum
262{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000263 PV_NONE = 0,
264 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265} idopt_T;
266
267/*
268 * Options local to a window have a value local to a buffer and global to all
269 * buffers. Indicate this by setting "var" to VAR_WIN.
270 */
271#define VAR_WIN ((char_u *)-1)
272
273/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000274 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275 * Only to be used in option.c!
276 */
277static int p_ai;
278static int p_bin;
279#ifdef FEAT_MBYTE
280static int p_bomb;
281#endif
282#if defined(FEAT_QUICKFIX)
283static char_u *p_bh;
284static char_u *p_bt;
285#endif
286static int p_bl;
287static int p_ci;
288#ifdef FEAT_CINDENT
289static int p_cin;
290static char_u *p_cink;
291static char_u *p_cino;
292#endif
293#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
294static char_u *p_cinw;
295#endif
296#ifdef FEAT_COMMENTS
297static char_u *p_com;
298#endif
299#ifdef FEAT_FOLDING
300static char_u *p_cms;
301#endif
302#ifdef FEAT_INS_EXPAND
303static char_u *p_cpt;
304#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#ifdef FEAT_COMPL_FUNC
306static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000307static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000309static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200310static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311static int p_et;
312#ifdef FEAT_MBYTE
313static char_u *p_fenc;
314#endif
315static char_u *p_ff;
316static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000317static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318#ifdef FEAT_AUTOCMD
319static char_u *p_ft;
320#endif
321static long p_iminsert;
322static long p_imsearch;
323#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
324static char_u *p_inex;
325#endif
326#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
327static char_u *p_inde;
328static char_u *p_indk;
329#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000330#if defined(FEAT_EVAL)
331static char_u *p_fex;
332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333static int p_inf;
334static char_u *p_isk;
335#ifdef FEAT_CRYPT
336static char_u *p_key;
337#endif
338#ifdef FEAT_LISP
339static int p_lisp;
340#endif
341static int p_ml;
342static int p_ma;
343static int p_mod;
344static char_u *p_mps;
345static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000347#ifdef FEAT_TEXTOBJ
348static char_u *p_qe;
349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_ro;
351#ifdef FEAT_SMARTINDENT
352static int p_si;
353#endif
354#ifndef SHORT_FNAME
355static int p_sn;
356#endif
357static long p_sts;
358#if defined(FEAT_SEARCHPATH)
359static char_u *p_sua;
360#endif
361static long p_sw;
362static int p_swf;
363#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000364static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000365static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000366#endif
367#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000368static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000369static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000370static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000371#endif
372static long p_ts;
373static long p_tw;
374static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200375#ifdef FEAT_PERSISTENT_UNDO
376static int p_udf;
377#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378static long p_wm;
379#ifdef FEAT_KEYMAP
380static char_u *p_keymap;
381#endif
382
383/* Saved values for when 'bin' is set. */
384static int p_et_nobin;
385static int p_ml_nobin;
386static long p_tw_nobin;
387static long p_wm_nobin;
388
389/* Saved values for when 'paste' is set */
390static long p_tw_nopaste;
391static long p_wm_nopaste;
392static long p_sts_nopaste;
393static int p_ai_nopaste;
394
395struct vimoption
396{
397 char *fullname; /* full option name */
398 char *shortname; /* permissible abbreviation */
399 long_u flags; /* see below */
400 char_u *var; /* global option: pointer to variable;
401 * window-local option: VAR_WIN;
402 * buffer-local option: global value */
403 idopt_T indir; /* global option: PV_NONE;
404 * local option: indirect option index */
405 char_u *def_val[2]; /* default values for variable (vi and vim) */
406#ifdef FEAT_EVAL
407 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000408# define SCRIPTID_INIT , 0
409#else
410# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411#endif
412};
413
414#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
415#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
416
417/*
418 * Flags
419 */
420#define P_BOOL 0x01 /* the option is boolean */
421#define P_NUM 0x02 /* the option is numeric */
422#define P_STRING 0x04 /* the option is a string */
423#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000424 must use free_string_option() when
425 assigning new value. Not set if default is
426 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
428 never be used for local or hidden options! */
429#define P_NODEFAULT 0x40 /* don't set to default value */
430#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
431 use vim_free() when assigning new value */
432#define P_WAS_SET 0x100 /* option has been set/reset */
433#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
434#define P_VI_DEF 0x400 /* Use Vi default for Vim */
435#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
436
437 /* when option changed, what to display: */
438#define P_RSTAT 0x1000 /* redraw status lines */
439#define P_RWIN 0x2000 /* redraw current window */
440#define P_RBUF 0x4000 /* redraw current buffer */
441#define P_RALL 0x6000 /* redraw all windows */
442#define P_RCLR 0x7000 /* clear and redraw all */
443
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200444#define P_COMMA 0x8000 /* comma separated list */
445#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
446 * commas */
447#define P_NODUP 0x20000L /* don't allow duplicate strings */
448#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200450#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
451#define P_GETTEXT 0x100000L /* expand default value with _() */
452#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
453#define P_NFNAME 0x400000L /* only normal file name chars allowed */
454#define P_INSECURE 0x800000L /* option was set from a modeline */
455#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000456 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200457#define P_NO_ML 0x2000000L /* not allowed in modeline */
458#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200459 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000460
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000461#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
462
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000463/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
464 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000465#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000466# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000467#else
468# define ISP_LATIN1 (char_u *)"@,161-255"
469#endif
470
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000471/* The 16 bit MS-DOS version is low on space, make the string as short as
472 * possible when compiling with few features. */
473#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
474 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200475 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100476# 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 +0000477#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100478# 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 +0000479#endif
480
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481/*
482 * options[] is initialized here.
483 * The order of the options MUST be alphabetic for ":set all" and findoption().
484 * All option names MUST start with a lowercase letter (for findoption()).
485 * Exception: "t_" options are at the end.
486 * The options with a NULL variable are 'hidden': a set command for them is
487 * ignored and they are not printed.
488 */
489static struct vimoption
490#ifdef FEAT_GUI_W16
491 _far
492#endif
493 options[] =
494{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200495 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496#ifdef FEAT_RIGHTLEFT
497 (char_u *)&p_aleph, PV_NONE,
498#else
499 (char_u *)NULL, PV_NONE,
500#endif
501 {
502#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
503 (char_u *)128L,
504#else
505 (char_u *)224L,
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
509#if defined(FEAT_GUI) && defined(MACOS_X)
510 (char_u *)&p_antialias, PV_NONE,
511 {(char_u *)FALSE, (char_u *)FALSE}
512#else
513 (char_u *)NULL, PV_NONE,
514 {(char_u *)FALSE, (char_u *)FALSE}
515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000516 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200517 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518#ifdef FEAT_ARABIC
519 (char_u *)VAR_WIN, PV_ARAB,
520#else
521 (char_u *)NULL, PV_NONE,
522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
525#ifdef FEAT_ARABIC
526 (char_u *)&p_arshape, PV_NONE,
527#else
528 (char_u *)NULL, PV_NONE,
529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000530 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
532#ifdef FEAT_RIGHTLEFT
533 (char_u *)&p_ari, PV_NONE,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
539#ifdef FEAT_FKMAP
540 (char_u *)&p_altkeymap, PV_NONE,
541#else
542 (char_u *)NULL, PV_NONE,
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
546#if defined(FEAT_MBYTE)
547 (char_u *)&p_ambw, PV_NONE,
548 {(char_u *)"single", (char_u *)0L}
549#else
550 (char_u *)NULL, PV_NONE,
551 {(char_u *)0L, (char_u *)0L}
552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000554#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 {"autochdir", "acd", P_BOOL|P_VI_DEF,
556 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558#endif
559 {"autoindent", "ai", P_BOOL|P_VI_DEF,
560 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autoprint", "ap", P_BOOL|P_VI_DEF,
563 (char_u *)NULL, 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 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000566 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autowrite", "aw", P_BOOL|P_VI_DEF,
569 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autowriteall","awa", P_BOOL|P_VI_DEF,
572 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
575 (char_u *)&p_bg, PV_NONE,
576 {
577#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
578 (char_u *)"dark",
579#else
580 (char_u *)"light",
581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200583 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
587 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200589 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200590 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591#ifdef UNIX
592 {(char_u *)"yes", (char_u *)"auto"}
593#else
594 {(char_u *)"auto", (char_u *)"auto"}
595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
598 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000601 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 (char_u *)&p_bex, PV_NONE,
603 {
604#ifdef VMS
605 (char_u *)"_",
606#else
607 (char_u *)"~",
608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200610 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611#ifdef FEAT_WILDIGN
612 (char_u *)&p_bsk, PV_NONE,
613 {(char_u *)"", (char_u *)0L}
614#else
615 (char_u *)NULL, PV_NONE,
616 {(char_u *)0L, (char_u *)0L}
617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000618 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_BEVAL
620 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
621 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000622 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
624 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000626# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000627 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000628 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000629 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000630# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631#endif
632 {"beautify", "bf", P_BOOL|P_VI_DEF,
633 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
636 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
639#ifdef MSDOS
640 (char_u *)&p_biosk, PV_NONE,
641#else
642 (char_u *)NULL, PV_NONE,
643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000644 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
646#ifdef FEAT_MBYTE
647 (char_u *)&p_bomb, PV_BOMB,
648#else
649 (char_u *)NULL, PV_NONE,
650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000651 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
653#ifdef FEAT_LINEBREAK
654 (char_u *)&p_breakat, PV_NONE,
655 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
656#else
657 (char_u *)NULL, PV_NONE,
658 {(char_u *)0L, (char_u *)0L}
659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000660 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200661 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
662#ifdef FEAT_LINEBREAK
663 (char_u *)VAR_WIN, PV_BRI,
664 {(char_u *)FALSE, (char_u *)0L}
665#else
666 (char_u *)NULL, PV_NONE,
667 {(char_u *)0L, (char_u *)0L}
668#endif
669 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200670 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
671 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200672#ifdef FEAT_LINEBREAK
673 (char_u *)VAR_WIN, PV_BRIOPT,
674 {(char_u *)"", (char_u *)NULL}
675#else
676 (char_u *)NULL, PV_NONE,
677 {(char_u *)"", (char_u *)NULL}
678#endif
679 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
681#ifdef FEAT_BROWSE
682 (char_u *)&p_bsdir, PV_NONE,
683 {(char_u *)"last", (char_u *)0L}
684#else
685 (char_u *)NULL, PV_NONE,
686 {(char_u *)0L, (char_u *)0L}
687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000688 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000689 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
690#if defined(FEAT_QUICKFIX)
691 (char_u *)&p_bh, PV_BH,
692 {(char_u *)"", (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000697 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
699 (char_u *)&p_bl, PV_BL,
700 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000701 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
703#if defined(FEAT_QUICKFIX)
704 (char_u *)&p_bt, PV_BT,
705 {(char_u *)"", (char_u *)0L}
706#else
707 (char_u *)NULL, PV_NONE,
708 {(char_u *)0L, (char_u *)0L}
709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000710 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200711 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000712#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 (char_u *)&p_cmp, PV_NONE,
714 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000715#else
716 (char_u *)NULL, PV_NONE,
717 {(char_u *)0L, (char_u *)0L}
718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000719 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
721#ifdef FEAT_SEARCHPATH
722 (char_u *)&p_cdpath, PV_NONE,
723 {(char_u *)",,", (char_u *)0L}
724#else
725 (char_u *)NULL, PV_NONE,
726 {(char_u *)0L, (char_u *)0L}
727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 {"cedit", NULL, P_STRING,
730#ifdef FEAT_CMDWIN
731 (char_u *)&p_cedit, PV_NONE,
732 {(char_u *)"", (char_u *)CTRL_F_STR}
733#else
734 (char_u *)NULL, PV_NONE,
735 {(char_u *)0L, (char_u *)0L}
736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000737 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
739#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
740 (char_u *)&p_ccv, PV_NONE,
741 {(char_u *)"", (char_u *)0L}
742#else
743 (char_u *)NULL, PV_NONE,
744 {(char_u *)0L, (char_u *)0L}
745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000746 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
748#ifdef FEAT_CINDENT
749 (char_u *)&p_cin, PV_CIN,
750#else
751 (char_u *)NULL, PV_NONE,
752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000753 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200754 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755#ifdef FEAT_CINDENT
756 (char_u *)&p_cink, PV_CINK,
757 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
758#else
759 (char_u *)NULL, PV_NONE,
760 {(char_u *)0L, (char_u *)0L}
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200763 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764#ifdef FEAT_CINDENT
765 (char_u *)&p_cino, PV_CINO,
766#else
767 (char_u *)NULL, PV_NONE,
768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200770 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
772 (char_u *)&p_cinw, PV_CINW,
773 {(char_u *)"if,else,while,do,for,switch",
774 (char_u *)0L}
775#else
776 (char_u *)NULL, PV_NONE,
777 {(char_u *)0L, (char_u *)0L}
778#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000779 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200780 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000781#ifdef FEAT_CLIPBOARD
782 (char_u *)&p_cb, PV_NONE,
783# ifdef FEAT_XCLIPBOARD
784 {(char_u *)"autoselect,exclude:cons\\|linux",
785 (char_u *)0L}
786# else
787 {(char_u *)"", (char_u *)0L}
788# endif
789#else
790 (char_u *)NULL, PV_NONE,
791 {(char_u *)"", (char_u *)0L}
792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000793 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000794 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
795 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000796 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
798#ifdef FEAT_CMDWIN
799 (char_u *)&p_cwh, PV_NONE,
800#else
801 (char_u *)NULL, PV_NONE,
802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200804 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200805#ifdef FEAT_SYN_HL
806 (char_u *)VAR_WIN, PV_CC,
807#else
808 (char_u *)NULL, PV_NONE,
809#endif
810 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000811 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
812 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000813 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200814 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
815 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816#ifdef FEAT_COMMENTS
817 (char_u *)&p_com, PV_COM,
818 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
819 (char_u *)0L}
820#else
821 (char_u *)NULL, PV_NONE,
822 {(char_u *)0L, (char_u *)0L}
823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200825 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826#ifdef FEAT_FOLDING
827 (char_u *)&p_cms, PV_CMS,
828 {(char_u *)"/*%s*/", (char_u *)0L}
829#else
830 (char_u *)NULL, PV_NONE,
831 {(char_u *)0L, (char_u *)0L}
832#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000833 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000834 /* P_PRI_MKRC isn't needed here, optval_default()
835 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836 {"compatible", "cp", P_BOOL|P_RALL,
837 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000838 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200839 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840#ifdef FEAT_INS_EXPAND
841 (char_u *)&p_cpt, PV_CPT,
842 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
843#else
844 (char_u *)NULL, PV_NONE,
845 {(char_u *)0L, (char_u *)0L}
846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000847 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200848 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200849#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200850 (char_u *)VAR_WIN, PV_COCU,
851 {(char_u *)"", (char_u *)NULL}
852#else
853 (char_u *)NULL, PV_NONE,
854 {(char_u *)NULL, (char_u *)0L}
855#endif
856 SCRIPTID_INIT},
857 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
858#ifdef FEAT_CONCEAL
859 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200860#else
861 (char_u *)NULL, PV_NONE,
862#endif
863 {(char_u *)0L, (char_u *)0L}
864 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000865 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
866#ifdef FEAT_COMPL_FUNC
867 (char_u *)&p_cfu, PV_CFU,
868 {(char_u *)"", (char_u *)0L}
869#else
870 (char_u *)NULL, PV_NONE,
871 {(char_u *)0L, (char_u *)0L}
872#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000873 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200874 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000875#ifdef FEAT_INS_EXPAND
876 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000877 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000878#else
879 (char_u *)NULL, PV_NONE,
880 {(char_u *)0L, (char_u *)0L}
881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"confirm", "cf", P_BOOL|P_VI_DEF,
884#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
885 (char_u *)&p_confirm, PV_NONE,
886#else
887 (char_u *)NULL, PV_NONE,
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"conskey", "consk",P_BOOL|P_VI_DEF,
891#ifdef MSDOS
892 (char_u *)&p_consk, PV_NONE,
893#else
894 (char_u *)NULL, PV_NONE,
895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
898 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000899 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
901 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
903 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200904 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200905#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200906 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200907 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200908#else
909 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200910 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200911#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
914#ifdef FEAT_CSCOPE
915 (char_u *)&p_cspc, PV_NONE,
916#else
917 (char_u *)NULL, PV_NONE,
918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000919 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
921#ifdef FEAT_CSCOPE
922 (char_u *)&p_csprg, PV_NONE,
923 {(char_u *)"cscope", (char_u *)0L}
924#else
925 (char_u *)NULL, PV_NONE,
926 {(char_u *)0L, (char_u *)0L}
927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000928 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200929 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000930#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
931 (char_u *)&p_csqf, PV_NONE,
932 {(char_u *)"", (char_u *)0L}
933#else
934 (char_u *)NULL, PV_NONE,
935 {(char_u *)0L, (char_u *)0L}
936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000937 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200938 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csre, PV_NONE,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
944 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_cst, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_csto, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_csverbose, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000965 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200966 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
967#ifdef FEAT_CURSORBIND
968 (char_u *)VAR_WIN, PV_CRBIND,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000973 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
974#ifdef FEAT_SYN_HL
975 (char_u *)VAR_WIN, PV_CUC,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000980 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
981#ifdef FEAT_SYN_HL
982 (char_u *)VAR_WIN, PV_CUL,
983#else
984 (char_u *)NULL, PV_NONE,
985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000987 {"debug", NULL, P_STRING|P_VI_DEF,
988 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200990 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000992 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000993 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994#else
995 (char_u *)NULL, PV_NONE,
996 {(char_u *)NULL, (char_u *)0L}
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1000#ifdef FEAT_MBYTE
1001 (char_u *)&p_deco, PV_NONE,
1002#else
1003 (char_u *)NULL, PV_NONE,
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001006 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001008 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1014#ifdef FEAT_DIFF
1015 (char_u *)VAR_WIN, PV_DIFF,
1016#else
1017 (char_u *)NULL, PV_NONE,
1018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001019 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001020 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1022 (char_u *)&p_dex, PV_NONE,
1023 {(char_u *)"", (char_u *)0L}
1024#else
1025 (char_u *)NULL, PV_NONE,
1026 {(char_u *)0L, (char_u *)0L}
1027#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001028 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001029 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1030 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031#ifdef FEAT_DIFF
1032 (char_u *)&p_dip, PV_NONE,
1033 {(char_u *)"filler", (char_u *)NULL}
1034#else
1035 (char_u *)NULL, PV_NONE,
1036 {(char_u *)"", (char_u *)NULL}
1037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001038 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1040#ifdef FEAT_DIGRAPHS
1041 (char_u *)&p_dg, PV_NONE,
1042#else
1043 (char_u *)NULL, PV_NONE,
1044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001046 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1047 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001049 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001050 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 {"eadirection", "ead", P_STRING|P_VI_DEF,
1054#ifdef FEAT_VERTSPLIT
1055 (char_u *)&p_ead, PV_NONE,
1056 {(char_u *)"both", (char_u *)0L}
1057#else
1058 (char_u *)NULL, PV_NONE,
1059 {(char_u *)NULL, (char_u *)0L}
1060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001061 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1063 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001065 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066#ifdef FEAT_MBYTE
1067 (char_u *)&p_enc, PV_NONE,
1068 {(char_u *)ENC_DFLT, (char_u *)0L}
1069#else
1070 (char_u *)NULL, PV_NONE,
1071 {(char_u *)0L, (char_u *)0L}
1072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1075 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1078 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001079 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001081 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1084 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1087#ifdef FEAT_QUICKFIX
1088 (char_u *)&p_ef, PV_NONE,
1089 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1090#else
1091 (char_u *)NULL, PV_NONE,
1092 {(char_u *)NULL, (char_u *)0L}
1093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001095 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001097 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001098 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099#else
1100 (char_u *)NULL, PV_NONE,
1101 {(char_u *)NULL, (char_u *)0L}
1102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"esckeys", "ek", P_BOOL|P_VIM,
1105 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001107 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108#ifdef FEAT_AUTOCMD
1109 (char_u *)&p_ei, PV_NONE,
1110#else
1111 (char_u *)NULL, PV_NONE,
1112#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001113 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001114 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1115 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1118 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001120 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1121 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122#ifdef FEAT_MBYTE
1123 (char_u *)&p_fenc, PV_FENC,
1124 {(char_u *)"", (char_u *)0L}
1125#else
1126 (char_u *)NULL, PV_NONE,
1127 {(char_u *)0L, (char_u *)0L}
1128#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001129 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001130 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131#ifdef FEAT_MBYTE
1132 (char_u *)&p_fencs, PV_NONE,
1133 {(char_u *)"ucs-bom", (char_u *)0L}
1134#else
1135 (char_u *)NULL, PV_NONE,
1136 {(char_u *)0L, (char_u *)0L}
1137#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001138 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001139 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1140 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001142 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001143 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001145 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1146 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001147 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1148 (char_u *)&p_fic, PV_NONE,
1149 {
1150#ifdef CASE_INSENSITIVE_FILENAME
1151 (char_u *)TRUE,
1152#else
1153 (char_u *)FALSE,
1154#endif
1155 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001156 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157#ifdef FEAT_AUTOCMD
1158 (char_u *)&p_ft, PV_FT,
1159 {(char_u *)"", (char_u *)0L}
1160#else
1161 (char_u *)NULL, PV_NONE,
1162 {(char_u *)0L, (char_u *)0L}
1163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001164 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001165 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001166#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1167 (char_u *)&p_fcs, PV_NONE,
1168 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1169#else
1170 (char_u *)NULL, PV_NONE,
1171 {(char_u *)"", (char_u *)0L}
1172#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001173 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001174 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1175 (char_u *)&p_fixeol, PV_FIXEOL,
1176 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1178#ifdef FEAT_FKMAP
1179 (char_u *)&p_fkmap, PV_NONE,
1180#else
1181 (char_u *)NULL, PV_NONE,
1182#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001183 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 {"flash", "fl", P_BOOL|P_VI_DEF,
1185 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001186 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001188 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1192 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1195 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001196 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001197 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1198# ifdef FEAT_EVAL
1199 (char_u *)VAR_WIN, PV_FDE,
1200 {(char_u *)"0", (char_u *)NULL}
1201# else
1202 (char_u *)NULL, PV_NONE,
1203 {(char_u *)NULL, (char_u *)0L}
1204# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001205 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001206 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1207 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001208 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1210 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001212 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001216 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001218 {(char_u *)"{{{,}}}", (char_u *)NULL}
1219 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1221 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001222 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1224 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001225 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1227 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001228 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001229 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001230 (char_u *)&p_fdo, PV_NONE,
1231 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001232 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1234# ifdef FEAT_EVAL
1235 (char_u *)VAR_WIN, PV_FDT,
1236 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001237# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 (char_u *)NULL, PV_NONE,
1239 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001240# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001241 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001243 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001244#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001245 (char_u *)&p_fex, PV_FEX,
1246 {(char_u *)"", (char_u *)0L}
1247#else
1248 (char_u *)NULL, PV_NONE,
1249 {(char_u *)0L, (char_u *)0L}
1250#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001251 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1253 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001254 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1255 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001256 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1257 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001258 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1259 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1261 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001262 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001263 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1264#ifdef HAVE_FSYNC
1265 (char_u *)&p_fs, PV_NONE,
1266 {(char_u *)TRUE, (char_u *)0L}
1267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)FALSE, (char_u *)0L}
1270#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001271 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001272 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1273 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001274 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001275 {"graphic", "gr", P_BOOL|P_VI_DEF,
1276 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001277 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001278 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001279#ifdef FEAT_QUICKFIX
1280 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282#else
1283 (char_u *)NULL, PV_NONE,
1284 {(char_u *)NULL, (char_u *)0L}
1285#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1288#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001289 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 {
1291# ifdef WIN3264
1292 /* may be changed to "grep -n" in os_win32.c */
1293 (char_u *)"findstr /n",
1294# else
1295# ifdef UNIX
1296 /* Add an extra file name so that grep will always
1297 * insert a file name in the match line. */
1298 (char_u *)"grep -n $* /dev/null",
1299# else
1300# ifdef VMS
1301 (char_u *)"SEARCH/NUMBERS ",
1302# else
1303 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001304# endif
1305# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308#else
1309 (char_u *)NULL, PV_NONE,
1310 {(char_u *)NULL, (char_u *)0L}
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001313 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314#ifdef CURSOR_SHAPE
1315 (char_u *)&p_guicursor, PV_NONE,
1316 {
1317# ifdef FEAT_GUI
1318 (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",
1319# else /* MSDOS or Win32 console */
1320 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1321# endif
1322 (char_u *)0L}
1323#else
1324 (char_u *)NULL, PV_NONE,
1325 {(char_u *)NULL, (char_u *)0L}
1326#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001327 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001328 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329#ifdef FEAT_GUI
1330 (char_u *)&p_guifont, PV_NONE,
1331 {(char_u *)"", (char_u *)0L}
1332#else
1333 (char_u *)NULL, PV_NONE,
1334 {(char_u *)NULL, (char_u *)0L}
1335#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001337 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1339 (char_u *)&p_guifontset, PV_NONE,
1340 {(char_u *)"", (char_u *)0L}
1341#else
1342 (char_u *)NULL, PV_NONE,
1343 {(char_u *)NULL, (char_u *)0L}
1344#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001345 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001346 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1348 (char_u *)&p_guifontwide, PV_NONE,
1349 {(char_u *)"", (char_u *)0L}
1350#else
1351 (char_u *)NULL, PV_NONE,
1352 {(char_u *)NULL, (char_u *)0L}
1353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001354 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001355 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001356#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 (char_u *)&p_ghr, PV_NONE,
1358#else
1359 (char_u *)NULL, PV_NONE,
1360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001363#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364 (char_u *)&p_go, PV_NONE,
1365# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001366 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001368 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369# endif
1370#else
1371 (char_u *)NULL, PV_NONE,
1372 {(char_u *)NULL, (char_u *)0L}
1373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001374 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375 {"guipty", NULL, P_BOOL|P_VI_DEF,
1376#if defined(FEAT_GUI)
1377 (char_u *)&p_guipty, PV_NONE,
1378#else
1379 (char_u *)NULL, PV_NONE,
1380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001381 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001382 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001383#if defined(FEAT_GUI_TABLINE)
1384 (char_u *)&p_gtl, PV_NONE,
1385 {(char_u *)"", (char_u *)0L}
1386#else
1387 (char_u *)NULL, PV_NONE,
1388 {(char_u *)NULL, (char_u *)0L}
1389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001390 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001391 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001392#if defined(FEAT_GUI_TABLINE)
1393 (char_u *)&p_gtt, PV_NONE,
1394 {(char_u *)"", (char_u *)0L}
1395#else
1396 (char_u *)NULL, PV_NONE,
1397 {(char_u *)NULL, (char_u *)0L}
1398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001400 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1401 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1404 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1406 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407 {"helpheight", "hh", P_NUM|P_VI_DEF,
1408#ifdef FEAT_WINDOWS
1409 (char_u *)&p_hh, PV_NONE,
1410#else
1411 (char_u *)NULL, PV_NONE,
1412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001413 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001414 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415#ifdef FEAT_MULTI_LANG
1416 (char_u *)&p_hlg, PV_NONE,
1417 {(char_u *)"", (char_u *)0L}
1418#else
1419 (char_u *)NULL, PV_NONE,
1420 {(char_u *)0L, (char_u *)0L}
1421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001422 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001423 {"hidden", "hid", P_BOOL|P_VI_DEF,
1424 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001426 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001428 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1429 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430 {"history", "hi", P_NUM|P_VIM,
1431 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001432 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1434#ifdef FEAT_RIGHTLEFT
1435 (char_u *)&p_hkmap, PV_NONE,
1436#else
1437 (char_u *)NULL, PV_NONE,
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1441#ifdef FEAT_RIGHTLEFT
1442 (char_u *)&p_hkmapp, PV_NONE,
1443#else
1444 (char_u *)NULL, PV_NONE,
1445#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001446 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1448 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001449 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"icon", NULL, P_BOOL|P_VI_DEF,
1451#ifdef FEAT_TITLE
1452 (char_u *)&p_icon, PV_NONE,
1453#else
1454 (char_u *)NULL, PV_NONE,
1455#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001456 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 {"iconstring", NULL, P_STRING|P_VI_DEF,
1458#ifdef FEAT_TITLE
1459 (char_u *)&p_iconstring, PV_NONE,
1460#else
1461 (char_u *)NULL, PV_NONE,
1462#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001463 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1465 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001467 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1468# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1469 (char_u *)&p_imaf, PV_NONE,
1470 {(char_u *)"", (char_u *)NULL}
1471# else
1472 (char_u *)NULL, PV_NONE,
1473 {(char_u *)NULL, (char_u *)0L}
1474# endif
1475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001477#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 (char_u *)&p_imak, PV_NONE,
1479#else
1480 (char_u *)NULL, PV_NONE,
1481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001482 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1484#ifdef USE_IM_CONTROL
1485 (char_u *)&p_imcmdline, PV_NONE,
1486#else
1487 (char_u *)NULL, PV_NONE,
1488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1491#ifdef USE_IM_CONTROL
1492 (char_u *)&p_imdisable, PV_NONE,
1493#else
1494 (char_u *)NULL, PV_NONE,
1495#endif
1496#ifdef __sgi
1497 {(char_u *)TRUE, (char_u *)0L}
1498#else
1499 {(char_u *)FALSE, (char_u *)0L}
1500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001501 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502 {"iminsert", "imi", P_NUM|P_VI_DEF,
1503 (char_u *)&p_iminsert, PV_IMI,
1504#ifdef B_IMODE_IM
1505 {(char_u *)B_IMODE_IM, (char_u *)0L}
1506#else
1507 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001509 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 {"imsearch", "ims", P_NUM|P_VI_DEF,
1511 (char_u *)&p_imsearch, PV_IMS,
1512#ifdef B_IMODE_IM
1513 {(char_u *)B_IMODE_IM, (char_u *)0L}
1514#else
1515 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001517 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001518 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001519# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1520 (char_u *)&p_imsf, PV_NONE,
1521 {(char_u *)"", (char_u *)NULL}
1522# else
1523 (char_u *)NULL, PV_NONE,
1524 {(char_u *)NULL, (char_u *)0L}
1525# endif
1526 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001527 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1528#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001529 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1531#else
1532 (char_u *)NULL, PV_NONE,
1533 {(char_u *)0L, (char_u *)0L}
1534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001535 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1537#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1538 (char_u *)&p_inex, PV_INEX,
1539 {(char_u *)"", (char_u *)0L}
1540#else
1541 (char_u *)NULL, PV_NONE,
1542 {(char_u *)0L, (char_u *)0L}
1543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001544 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001545 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1546 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1549#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1550 (char_u *)&p_inde, PV_INDE,
1551 {(char_u *)"", (char_u *)0L}
1552#else
1553 (char_u *)NULL, PV_NONE,
1554 {(char_u *)0L, (char_u *)0L}
1555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001557 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1559 (char_u *)&p_indk, PV_INDK,
1560 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1561#else
1562 (char_u *)NULL, PV_NONE,
1563 {(char_u *)0L, (char_u *)0L}
1564#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 {"infercase", "inf", P_BOOL|P_VI_DEF,
1567 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1570 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1573 (char_u *)&p_isf, PV_NONE,
1574 {
1575#ifdef BACKSLASH_IN_FILENAME
1576 /* Excluded are: & and ^ are special in cmd.exe
1577 * ( and ) are used in text separating fnames */
1578 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1579#else
1580# ifdef AMIGA
1581 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1582# else
1583# ifdef VMS
1584 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1585# else /* UNIX et al. */
1586# ifdef EBCDIC
1587 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1588# else
1589 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1590# endif
1591# endif
1592# endif
1593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001594 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1596 (char_u *)&p_isi, PV_NONE,
1597 {
1598#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1599 (char_u *)"@,48-57,_,128-167,224-235",
1600#else
1601# ifdef EBCDIC
1602 /* TODO: EBCDIC Check this! @ == isalpha()*/
1603 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1604 "112-120,128,140-142,156,158,172,"
1605 "174,186,191,203-207,219-225,235-239,"
1606 "251-254",
1607# else
1608 (char_u *)"@,48-57,_,192-255",
1609# endif
1610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001611 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001612 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1613 (char_u *)&p_isk, PV_ISK,
1614 {
1615#ifdef EBCDIC
1616 (char_u *)"@,240-249,_",
1617 /* TODO: EBCDIC Check this! @ == isalpha()*/
1618 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1619 "112-120,128,140-142,156,158,172,"
1620 "174,186,191,203-207,219-225,235-239,"
1621 "251-254",
1622#else
1623 (char_u *)"@,48-57,_",
1624# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1625 (char_u *)"@,48-57,_,128-167,224-235"
1626# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001627 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001628# endif
1629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001630 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1632 (char_u *)&p_isp, PV_NONE,
1633 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001634#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1635 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 || defined(VMS)
1637 (char_u *)"@,~-255",
1638#else
1639# ifdef EBCDIC
1640 /* all chars above 63 are printable */
1641 (char_u *)"63-255",
1642# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001643 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644# endif
1645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1648 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1651#ifdef FEAT_CRYPT
1652 (char_u *)&p_key, PV_KEY,
1653 {(char_u *)"", (char_u *)0L}
1654#else
1655 (char_u *)NULL, PV_NONE,
1656 {(char_u *)0L, (char_u *)0L}
1657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001659 {"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 +00001660#ifdef FEAT_KEYMAP
1661 (char_u *)&p_keymap, PV_KMAP,
1662 {(char_u *)"", (char_u *)0L}
1663#else
1664 (char_u *)NULL, PV_NONE,
1665 {(char_u *)"", (char_u *)0L}
1666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001668 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001672 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673 {
1674#if defined(MSDOS) || defined(MSWIN)
1675 (char_u *)":help",
1676#else
1677#ifdef VMS
1678 (char_u *)"help",
1679#else
1680# if defined(OS2)
1681 (char_u *)"view /",
1682# else
1683# ifdef USEMAN_S
1684 (char_u *)"man -s",
1685# else
1686 (char_u *)"man",
1687# endif
1688# endif
1689#endif
1690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001691 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001692 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693#ifdef FEAT_LANGMAP
1694 (char_u *)&p_langmap, PV_NONE,
1695 {(char_u *)"", /* unmatched } */
1696#else
1697 (char_u *)NULL, PV_NONE,
1698 {(char_u *)NULL,
1699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001701 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1703 (char_u *)&p_lm, PV_NONE,
1704#else
1705 (char_u *)NULL, PV_NONE,
1706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001708 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1709#ifdef FEAT_LANGMAP
1710 (char_u *)&p_lnr, PV_NONE,
1711#else
1712 (char_u *)NULL, PV_NONE,
1713#endif
1714 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1716#ifdef FEAT_WINDOWS
1717 (char_u *)&p_ls, PV_NONE,
1718#else
1719 (char_u *)NULL, PV_NONE,
1720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1723 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1726#ifdef FEAT_LINEBREAK
1727 (char_u *)VAR_WIN, PV_LBR,
1728#else
1729 (char_u *)NULL, PV_NONE,
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1733 (char_u *)&Rows, PV_NONE,
1734 {
1735#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1736 (char_u *)25L,
1737#else
1738 (char_u *)24L,
1739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001740 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1742#ifdef FEAT_GUI
1743 (char_u *)&p_linespace, PV_NONE,
1744#else
1745 (char_u *)NULL, PV_NONE,
1746#endif
1747#ifdef FEAT_GUI_W32
1748 {(char_u *)1L, (char_u *)0L}
1749#else
1750 {(char_u *)0L, (char_u *)0L}
1751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"lisp", NULL, P_BOOL|P_VI_DEF,
1754#ifdef FEAT_LISP
1755 (char_u *)&p_lisp, PV_LISP,
1756#else
1757 (char_u *)NULL, PV_NONE,
1758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001760 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001762 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1764#else
1765 (char_u *)NULL, PV_NONE,
1766 {(char_u *)"", (char_u *)0L}
1767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1770 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001772 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1776 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001778#ifdef FEAT_GUI_MAC
1779 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1780 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001781 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"magic", NULL, P_BOOL|P_VI_DEF,
1784 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001786 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787#ifdef FEAT_QUICKFIX
1788 (char_u *)&p_mef, PV_NONE,
1789 {(char_u *)"", (char_u *)0L}
1790#else
1791 (char_u *)NULL, PV_NONE,
1792 {(char_u *)NULL, (char_u *)0L}
1793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001795 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1796#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001797 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798# ifdef VMS
1799 {(char_u *)"MMS", (char_u *)0L}
1800# else
1801 {(char_u *)"make", (char_u *)0L}
1802# endif
1803#else
1804 (char_u *)NULL, PV_NONE,
1805 {(char_u *)NULL, (char_u *)0L}
1806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001808 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001809 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1811 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 {"matchtime", "mat", P_NUM|P_VI_DEF,
1813 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001815 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001816#ifdef FEAT_MBYTE
1817 (char_u *)&p_mco, PV_NONE,
1818#else
1819 (char_u *)NULL, PV_NONE,
1820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1823#ifdef FEAT_EVAL
1824 (char_u *)&p_mfd, PV_NONE,
1825#else
1826 (char_u *)NULL, PV_NONE,
1827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1830 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"maxmem", "mm", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1835 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001836 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1837 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1840 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1842 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843 {"menuitems", "mis", P_NUM|P_VI_DEF,
1844#ifdef FEAT_MENU
1845 (char_u *)&p_mis, PV_NONE,
1846#else
1847 (char_u *)NULL, PV_NONE,
1848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"mesg", NULL, P_BOOL|P_VI_DEF,
1851 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001853 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001854#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001855 (char_u *)&p_msm, PV_NONE,
1856 {(char_u *)"460000,2000,500", (char_u *)0L}
1857#else
1858 (char_u *)NULL, PV_NONE,
1859 {(char_u *)0L, (char_u *)0L}
1860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {"modeline", "ml", P_BOOL|P_VIM,
1863 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 {"modelines", "mls", P_NUM|P_VI_DEF,
1866 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1869 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1872 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"more", NULL, P_BOOL|P_VIM,
1875 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1878 (char_u *)&p_mouse, PV_NONE,
1879 {
1880#if defined(MSDOS) || defined(WIN3264)
1881 (char_u *)"a",
1882#else
1883 (char_u *)"",
1884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001885 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1887#ifdef FEAT_GUI
1888 (char_u *)&p_mousef, PV_NONE,
1889#else
1890 (char_u *)NULL, PV_NONE,
1891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001892 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1894#ifdef FEAT_GUI
1895 (char_u *)&p_mh, PV_NONE,
1896#else
1897 (char_u *)NULL, PV_NONE,
1898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1901 (char_u *)&p_mousem, PV_NONE,
1902 {
1903#if defined(MSDOS) || defined(MSWIN)
1904 (char_u *)"popup",
1905#else
1906# if defined(MACOS)
1907 (char_u *)"popup_setpos",
1908# else
1909 (char_u *)"extend",
1910# endif
1911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001913 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914#ifdef FEAT_MOUSESHAPE
1915 (char_u *)&p_mouseshape, PV_NONE,
1916 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1917#else
1918 (char_u *)NULL, PV_NONE,
1919 {(char_u *)NULL, (char_u *)0L}
1920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1923 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001925 {"mzquantum", "mzq", P_NUM,
1926#ifdef FEAT_MZSCHEME
1927 (char_u *)&p_mzq, PV_NONE,
1928#else
1929 (char_u *)NULL, PV_NONE,
1930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 {"novice", NULL, P_BOOL|P_VI_DEF,
1933 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001935 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)"octal,hex", (char_u *)0L}
1938 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1940 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001942 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1943#ifdef FEAT_LINEBREAK
1944 (char_u *)VAR_WIN, PV_NUW,
1945#else
1946 (char_u *)NULL, PV_NONE,
1947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001948 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001949 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001950#ifdef FEAT_COMPL_FUNC
1951 (char_u *)&p_ofu, PV_OFU,
1952 {(char_u *)"", (char_u *)0L}
1953#else
1954 (char_u *)NULL, PV_NONE,
1955 {(char_u *)0L, (char_u *)0L}
1956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {"open", NULL, P_BOOL|P_VI_DEF,
1959 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001961 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1962#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1963 (char_u *)&p_odev, PV_NONE,
1964#else
1965 (char_u *)NULL, PV_NONE,
1966#endif
1967 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001968 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001969 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1970 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001972 {"optimize", "opt", P_BOOL|P_VI_DEF,
1973 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001977 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"paragraphs", "para", P_STRING|P_VI_DEF,
1979 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001980 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001982 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1986 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1989#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1990 (char_u *)&p_pex, PV_NONE,
1991 {(char_u *)"", (char_u *)0L}
1992#else
1993 (char_u *)NULL, PV_NONE,
1994 {(char_u *)0L, (char_u *)0L}
1995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001997 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001999 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002001 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 {
2003#if defined AMIGA || defined MSDOS || defined MSWIN
2004 (char_u *)".,,",
2005#else
2006# if defined(__EMX__)
2007 (char_u *)".,/emx/include,,",
2008# else /* Unix, probably */
2009 (char_u *)".,/usr/include,,",
2010# endif
2011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2014 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002016 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2018 (char_u *)&p_pvh, PV_NONE,
2019#else
2020 (char_u *)NULL, PV_NONE,
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2024#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2025 (char_u *)VAR_WIN, PV_PVW,
2026#else
2027 (char_u *)NULL, PV_NONE,
2028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002030 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031#ifdef FEAT_PRINTER
2032 (char_u *)&p_pdev, PV_NONE,
2033 {(char_u *)"", (char_u *)0L}
2034#else
2035 (char_u *)NULL, PV_NONE,
2036 {(char_u *)NULL, (char_u *)0L}
2037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002038 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"printencoding", "penc", P_STRING|P_VI_DEF,
2040#ifdef FEAT_POSTSCRIPT
2041 (char_u *)&p_penc, PV_NONE,
2042 {(char_u *)"", (char_u *)0L}
2043#else
2044 (char_u *)NULL, PV_NONE,
2045 {(char_u *)NULL, (char_u *)0L}
2046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2049#ifdef FEAT_POSTSCRIPT
2050 (char_u *)&p_pexpr, PV_NONE,
2051 {(char_u *)"", (char_u *)0L}
2052#else
2053 (char_u *)NULL, PV_NONE,
2054 {(char_u *)NULL, (char_u *)0L}
2055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 {"printfont", "pfn", P_STRING|P_VI_DEF,
2058#ifdef FEAT_PRINTER
2059 (char_u *)&p_pfn, PV_NONE,
2060 {
2061# ifdef MSWIN
2062 (char_u *)"Courier_New:h10",
2063# else
2064 (char_u *)"courier",
2065# endif
2066 (char_u *)0L}
2067#else
2068 (char_u *)NULL, PV_NONE,
2069 {(char_u *)NULL, (char_u *)0L}
2070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2073#ifdef FEAT_PRINTER
2074 (char_u *)&p_header, PV_NONE,
2075 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2076#else
2077 (char_u *)NULL, PV_NONE,
2078 {(char_u *)NULL, (char_u *)0L}
2079#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002081 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2082#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2083 (char_u *)&p_pmcs, PV_NONE,
2084 {(char_u *)"", (char_u *)0L}
2085#else
2086 (char_u *)NULL, PV_NONE,
2087 {(char_u *)NULL, (char_u *)0L}
2088#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002090 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2091#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2092 (char_u *)&p_pmfn, PV_NONE,
2093 {(char_u *)"", (char_u *)0L}
2094#else
2095 (char_u *)NULL, PV_NONE,
2096 {(char_u *)NULL, (char_u *)0L}
2097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002099 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100#ifdef FEAT_PRINTER
2101 (char_u *)&p_popt, PV_NONE,
2102 {(char_u *)"", (char_u *)0L}
2103#else
2104 (char_u *)NULL, PV_NONE,
2105 {(char_u *)NULL, (char_u *)0L}
2106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002109 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002111 {"pumheight", "ph", P_NUM|P_VI_DEF,
2112#ifdef FEAT_INS_EXPAND
2113 (char_u *)&p_ph, PV_NONE,
2114#else
2115 (char_u *)NULL, PV_NONE,
2116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002118 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2119#ifdef FEAT_TEXTOBJ
2120 (char_u *)&p_qe, PV_QE,
2121 {(char_u *)"\\", (char_u *)0L}
2122#else
2123 (char_u *)NULL, PV_NONE,
2124 {(char_u *)NULL, (char_u *)0L}
2125#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2128 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002129 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 {"redraw", NULL, P_BOOL|P_VI_DEF,
2131 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002132 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002133 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2134#ifdef FEAT_RELTIME
2135 (char_u *)&p_rdt, PV_NONE,
2136#else
2137 (char_u *)NULL, PV_NONE,
2138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002139 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002140 {"regexpengine", "re", P_NUM|P_VI_DEF,
2141 (char_u *)&p_re, PV_NONE,
2142 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002143 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2144 (char_u *)VAR_WIN, PV_RNU,
2145 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"remap", NULL, P_BOOL|P_VI_DEF,
2147 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002149 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002150#ifdef FEAT_RENDER_OPTIONS
2151 (char_u *)&p_rop, PV_NONE,
2152 {(char_u *)"", (char_u *)0L}
2153#else
2154 (char_u *)NULL, PV_NONE,
2155 {(char_u *)NULL, (char_u *)0L}
2156#endif
2157 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 {"report", NULL, P_NUM|P_VI_DEF,
2159 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2162#ifdef WIN3264
2163 (char_u *)&p_rs, PV_NONE,
2164#else
2165 (char_u *)NULL, PV_NONE,
2166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2169#ifdef FEAT_RIGHTLEFT
2170 (char_u *)&p_ri, PV_NONE,
2171#else
2172 (char_u *)NULL, PV_NONE,
2173#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002174 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2176#ifdef FEAT_RIGHTLEFT
2177 (char_u *)VAR_WIN, PV_RL,
2178#else
2179 (char_u *)NULL, PV_NONE,
2180#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2183#ifdef FEAT_RIGHTLEFT
2184 (char_u *)VAR_WIN, PV_RLC,
2185 {(char_u *)"search", (char_u *)NULL}
2186#else
2187 (char_u *)NULL, PV_NONE,
2188 {(char_u *)NULL, (char_u *)0L}
2189#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002190 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2192#ifdef FEAT_CMDL_INFO
2193 (char_u *)&p_ru, PV_NONE,
2194#else
2195 (char_u *)NULL, PV_NONE,
2196#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002197 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002198 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2199#ifdef FEAT_STL_OPT
2200 (char_u *)&p_ruf, PV_NONE,
2201#else
2202 (char_u *)NULL, PV_NONE,
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002205 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2206 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002208 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2209 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002210 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2211 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002212 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002213 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2214#ifdef FEAT_SCROLLBIND
2215 (char_u *)VAR_WIN, PV_SCBIND,
2216#else
2217 (char_u *)NULL, PV_NONE,
2218#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2221 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2224 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002226 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227#ifdef FEAT_SCROLLBIND
2228 (char_u *)&p_sbo, PV_NONE,
2229 {(char_u *)"ver,jump", (char_u *)0L}
2230#else
2231 (char_u *)NULL, PV_NONE,
2232 {(char_u *)0L, (char_u *)0L}
2233#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002235 {"sections", "sect", P_STRING|P_VI_DEF,
2236 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2238 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2240 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)"inclusive", (char_u *)0L}
2245 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002246 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002248 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002249 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250#ifdef FEAT_SESSION
2251 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002252 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253 (char_u *)0L}
2254#else
2255 (char_u *)NULL, PV_NONE,
2256 {(char_u *)0L, (char_u *)0L}
2257#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002258 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002259 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2260 (char_u *)&p_sh, PV_NONE,
2261 {
2262#ifdef VMS
2263 (char_u *)"-",
2264#else
2265# if defined(MSDOS)
2266 (char_u *)"command",
2267# else
2268# if defined(WIN16)
2269 (char_u *)"command.com",
2270# else
2271# if defined(WIN3264)
2272 (char_u *)"", /* set in set_init_1() */
2273# else
2274# if defined(OS2)
2275 (char_u *)"cmd.exe",
2276# else
2277# if defined(ARCHIE)
2278 (char_u *)"gos",
2279# else
2280 (char_u *)"sh",
2281# endif
2282# endif
2283# endif
2284# endif
2285# endif
2286#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2289 (char_u *)&p_shcf, PV_NONE,
2290 {
2291#if defined(MSDOS) || defined(MSWIN)
2292 (char_u *)"/c",
2293#else
2294# if defined(OS2)
2295 (char_u *)"/c",
2296# else
2297 (char_u *)"-c",
2298# endif
2299#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002300 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2302#ifdef FEAT_QUICKFIX
2303 (char_u *)&p_sp, PV_NONE,
2304 {
2305#if defined(UNIX) || defined(OS2)
2306# ifdef ARCHIE
2307 (char_u *)"2>",
2308# else
2309 (char_u *)"| tee",
2310# endif
2311#else
2312 (char_u *)">",
2313#endif
2314 (char_u *)0L}
2315#else
2316 (char_u *)NULL, PV_NONE,
2317 {(char_u *)0L, (char_u *)0L}
2318#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2324 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002325 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2327#ifdef BACKSLASH_IN_FILENAME
2328 (char_u *)&p_ssl, PV_NONE,
2329#else
2330 (char_u *)NULL, PV_NONE,
2331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002333 {"shelltemp", "stmp", P_BOOL,
2334 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"shelltype", "st", P_NUM|P_VI_DEF,
2337#ifdef AMIGA
2338 (char_u *)&p_st, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2344 (char_u *)&p_sxq, PV_NONE,
2345 {
2346#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2347 (char_u *)"\"",
2348#else
2349 (char_u *)"",
2350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002352 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2353 (char_u *)&p_sxe, PV_NONE,
2354 {
2355#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2356 (char_u *)"\"&|<>()@^",
2357#else
2358 (char_u *)"",
2359#endif
2360 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2362 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2365 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2368 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)"", (char_u *)"filnxtToO"}
2370 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shortname", "sn", P_BOOL|P_VI_DEF,
2372#ifdef SHORT_FNAME
2373 (char_u *)NULL, PV_NONE,
2374#else
2375 (char_u *)&p_sn, PV_SN,
2376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2379#ifdef FEAT_LINEBREAK
2380 (char_u *)&p_sbr, PV_NONE,
2381#else
2382 (char_u *)NULL, PV_NONE,
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"showcmd", "sc", P_BOOL|P_VIM,
2386#ifdef FEAT_CMDL_INFO
2387 (char_u *)&p_sc, PV_NONE,
2388#else
2389 (char_u *)NULL, PV_NONE,
2390#endif
2391 {(char_u *)FALSE,
2392#ifdef UNIX
2393 (char_u *)FALSE
2394#else
2395 (char_u *)TRUE
2396#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2399 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2402 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"showmode", "smd", P_BOOL|P_VIM,
2405 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002407 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2408#ifdef FEAT_WINDOWS
2409 (char_u *)&p_stal, PV_NONE,
2410#else
2411 (char_u *)NULL, PV_NONE,
2412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2415 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2418 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2421 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2424 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2427#ifdef FEAT_SMARTINDENT
2428 (char_u *)&p_si, PV_SI,
2429#else
2430 (char_u *)NULL, PV_NONE,
2431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2434 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2437 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2440 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002442 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002443#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002444 (char_u *)VAR_WIN, PV_SPELL,
2445#else
2446 (char_u *)NULL, PV_NONE,
2447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002449 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002450#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002451 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002452 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002453#else
2454 (char_u *)NULL, PV_NONE,
2455 {(char_u *)0L, (char_u *)0L}
2456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002457 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002458 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2459 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002460#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002461 (char_u *)&p_spf, PV_SPF,
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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002468 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2469 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002470#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002471 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002472 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002473#else
2474 (char_u *)NULL, PV_NONE,
2475 {(char_u *)0L, (char_u *)0L}
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002478 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002479#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002480 (char_u *)&p_sps, PV_NONE,
2481 {(char_u *)"best", (char_u *)0L}
2482#else
2483 (char_u *)NULL, PV_NONE,
2484 {(char_u *)0L, (char_u *)0L}
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2488#ifdef FEAT_WINDOWS
2489 (char_u *)&p_sb, PV_NONE,
2490#else
2491 (char_u *)NULL, PV_NONE,
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"splitright", "spr", P_BOOL|P_VI_DEF,
2495#ifdef FEAT_VERTSPLIT
2496 (char_u *)&p_spr, PV_NONE,
2497#else
2498 (char_u *)NULL, PV_NONE,
2499#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2502 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2505#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002506 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507#else
2508 (char_u *)NULL, PV_NONE,
2509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002511 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 (char_u *)&p_su, PV_NONE,
2513 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002515 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002516#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 (char_u *)&p_sua, PV_SUA,
2518 {(char_u *)"", (char_u *)0L}
2519#else
2520 (char_u *)NULL, PV_NONE,
2521 {(char_u *)0L, (char_u *)0L}
2522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2525 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"swapsync", "sws", P_STRING|P_VI_DEF,
2528 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002530 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002533 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2534#ifdef FEAT_SYN_HL
2535 (char_u *)&p_smc, PV_SMC,
2536 {(char_u *)3000L, (char_u *)0L}
2537#else
2538 (char_u *)NULL, PV_NONE,
2539 {(char_u *)0L, (char_u *)0L}
2540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002542 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543#ifdef FEAT_SYN_HL
2544 (char_u *)&p_syn, PV_SYN,
2545 {(char_u *)"", (char_u *)0L}
2546#else
2547 (char_u *)NULL, PV_NONE,
2548 {(char_u *)0L, (char_u *)0L}
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002551 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2552#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002553 (char_u *)&p_tal, PV_NONE,
2554#else
2555 (char_u *)NULL, PV_NONE,
2556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002558 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2559#ifdef FEAT_WINDOWS
2560 (char_u *)&p_tpm, PV_NONE,
2561#else
2562 (char_u *)NULL, PV_NONE,
2563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2566 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2569 (char_u *)&p_tbs, PV_NONE,
2570#ifdef VMS /* binary searching doesn't appear to work on VMS */
2571 {(char_u *)0L, (char_u *)0L}
2572#else
2573 {(char_u *)TRUE, (char_u *)0L}
2574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"taglength", "tl", P_NUM|P_VI_DEF,
2577 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"tagrelative", "tr", P_BOOL|P_VIM,
2580 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002582 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002583 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {
2585#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2586 (char_u *)"./tags,./TAGS,tags,TAGS",
2587#else
2588 (char_u *)"./tags,tags",
2589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2592 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2595 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2598#ifdef FEAT_ARABIC
2599 (char_u *)&p_tbidi, PV_NONE,
2600#else
2601 (char_u *)NULL, PV_NONE,
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2605#ifdef FEAT_MBYTE
2606 (char_u *)&p_tenc, PV_NONE,
2607 {(char_u *)"", (char_u *)0L}
2608#else
2609 (char_u *)NULL, PV_NONE,
2610 {(char_u *)0L, (char_u *)0L}
2611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {"terse", NULL, P_BOOL|P_VI_DEF,
2614 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {"textauto", "ta", P_BOOL|P_VIM,
2617 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2621 (char_u *)&p_tx, PV_TX,
2622 {
2623#ifdef USE_CRNL
2624 (char_u *)TRUE,
2625#else
2626 (char_u *)FALSE,
2627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002629 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002632 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002634 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635#else
2636 (char_u *)NULL, PV_NONE,
2637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002638 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2640 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"timeout", "to", P_BOOL|P_VI_DEF,
2643 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2646 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"title", NULL, P_BOOL|P_VI_DEF,
2649#ifdef FEAT_TITLE
2650 (char_u *)&p_title, PV_NONE,
2651#else
2652 (char_u *)NULL, PV_NONE,
2653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"titlelen", NULL, P_NUM|P_VI_DEF,
2656#ifdef FEAT_TITLE
2657 (char_u *)&p_titlelen, PV_NONE,
2658#else
2659 (char_u *)NULL, PV_NONE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002662 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663#ifdef FEAT_TITLE
2664 (char_u *)&p_titleold, PV_NONE,
2665 {(char_u *)N_("Thanks for flying Vim"),
2666 (char_u *)0L}
2667#else
2668 (char_u *)NULL, PV_NONE,
2669 {(char_u *)0L, (char_u *)0L}
2670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"titlestring", NULL, P_STRING|P_VI_DEF,
2673#ifdef FEAT_TITLE
2674 (char_u *)&p_titlestring, PV_NONE,
2675#else
2676 (char_u *)NULL, PV_NONE,
2677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002680 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)"icons,tooltips", (char_u *)0L}
2683 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002685#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2687 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689#endif
2690 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2691 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2694 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2697 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2700 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2703#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2704 (char_u *)&p_ttym, PV_NONE,
2705#else
2706 (char_u *)NULL, PV_NONE,
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2710 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2713 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002715 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2716 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002717#ifdef FEAT_PERSISTENT_UNDO
2718 (char_u *)&p_udir, PV_NONE,
2719 {(char_u *)".", (char_u *)0L}
2720#else
2721 (char_u *)NULL, PV_NONE,
2722 {(char_u *)0L, (char_u *)0L}
2723#endif
2724 SCRIPTID_INIT},
2725 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2726#ifdef FEAT_PERSISTENT_UNDO
2727 (char_u *)&p_udf, PV_UDF,
2728#else
2729 (char_u *)NULL, PV_NONE,
2730#endif
2731 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002733 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {
2735#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2736 (char_u *)1000L,
2737#else
2738 (char_u *)100L,
2739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002741 {"undoreload", "ur", P_NUM|P_VI_DEF,
2742 (char_u *)&p_ur, PV_NONE,
2743 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744 {"updatecount", "uc", P_NUM|P_VI_DEF,
2745 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"updatetime", "ut", P_NUM|P_VI_DEF,
2748 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"verbose", "vbs", P_NUM|P_VI_DEF,
2751 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002753 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2754 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2757#ifdef FEAT_SESSION
2758 (char_u *)&p_vdir, PV_NONE,
2759 {(char_u *)DFLT_VDIR, (char_u *)0L}
2760#else
2761 (char_u *)NULL, PV_NONE,
2762 {(char_u *)0L, (char_u *)0L}
2763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002765 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766#ifdef FEAT_SESSION
2767 (char_u *)&p_vop, PV_NONE,
2768 {(char_u *)"folds,options,cursor", (char_u *)0L}
2769#else
2770 (char_u *)NULL, PV_NONE,
2771 {(char_u *)0L, (char_u *)0L}
2772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002774 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775#ifdef FEAT_VIMINFO
2776 (char_u *)&p_viminfo, PV_NONE,
2777#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002778 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779#else
2780# ifdef AMIGA
2781 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002782 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002784 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785# endif
2786#endif
2787#else
2788 (char_u *)NULL, PV_NONE,
2789 {(char_u *)0L, (char_u *)0L}
2790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002792 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2793 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794#ifdef FEAT_VIRTUALEDIT
2795 (char_u *)&p_ve, PV_NONE,
2796 {(char_u *)"", (char_u *)""}
2797#else
2798 (char_u *)NULL, PV_NONE,
2799 {(char_u *)0L, (char_u *)0L}
2800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2803 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"w300", NULL, P_NUM|P_VI_DEF,
2806 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"w1200", NULL, P_NUM|P_VI_DEF,
2809 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"w9600", NULL, P_NUM|P_VI_DEF,
2812 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"warn", NULL, P_BOOL|P_VI_DEF,
2815 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2818 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002820 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"wildchar", "wc", P_NUM|P_VIM,
2824 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2826 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002827 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002830 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831#ifdef FEAT_WILDIGN
2832 (char_u *)&p_wig, PV_NONE,
2833#else
2834 (char_u *)NULL, PV_NONE,
2835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002837 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2838 (char_u *)&p_wic, PV_NONE,
2839 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2841#ifdef FEAT_WILDMENU
2842 (char_u *)&p_wmnu, PV_NONE,
2843#else
2844 (char_u *)NULL, PV_NONE,
2845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002847 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002850 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2851#ifdef FEAT_CMDL_COMPL
2852 (char_u *)&p_wop, PV_NONE,
2853 {(char_u *)"", (char_u *)0L}
2854#else
2855 (char_u *)NULL, PV_NONE,
2856 {(char_u *)NULL, (char_u *)0L}
2857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2860#ifdef FEAT_WAK
2861 (char_u *)&p_wak, PV_NONE,
2862 {(char_u *)"menu", (char_u *)0L}
2863#else
2864 (char_u *)NULL, PV_NONE,
2865 {(char_u *)NULL, (char_u *)0L}
2866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002869 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"winheight", "wh", P_NUM|P_VI_DEF,
2872#ifdef FEAT_WINDOWS
2873 (char_u *)&p_wh, PV_NONE,
2874#else
2875 (char_u *)NULL, PV_NONE,
2876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002879#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 (char_u *)VAR_WIN, PV_WFH,
2881#else
2882 (char_u *)NULL, PV_NONE,
2883#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002884 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002885 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2886#ifdef FEAT_VERTSPLIT
2887 (char_u *)VAR_WIN, PV_WFW,
2888#else
2889 (char_u *)NULL, PV_NONE,
2890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2893#ifdef FEAT_WINDOWS
2894 (char_u *)&p_wmh, PV_NONE,
2895#else
2896 (char_u *)NULL, PV_NONE,
2897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2900#ifdef FEAT_VERTSPLIT
2901 (char_u *)&p_wmw, PV_NONE,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2907#ifdef FEAT_VERTSPLIT
2908 (char_u *)&p_wiw, PV_NONE,
2909#else
2910 (char_u *)NULL, PV_NONE,
2911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002912 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2914 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002915 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2917 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2920 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"write", NULL, P_BOOL|P_VI_DEF,
2923 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"writeany", "wa", P_BOOL|P_VI_DEF,
2926 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2929 (char_u *)&p_wb, PV_NONE,
2930 {
2931#ifdef FEAT_WRITEBACKUP
2932 (char_u *)TRUE,
2933#else
2934 (char_u *)FALSE,
2935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {"writedelay", "wd", P_NUM|P_VI_DEF,
2938 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940
2941/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002942#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945
2946 p_term("t_AB", T_CAB)
2947 p_term("t_AF", T_CAF)
2948 p_term("t_AL", T_CAL)
2949 p_term("t_al", T_AL)
2950 p_term("t_bc", T_BC)
2951 p_term("t_cd", T_CD)
2952 p_term("t_ce", T_CE)
2953 p_term("t_cl", T_CL)
2954 p_term("t_cm", T_CM)
2955 p_term("t_Co", T_CCO)
2956 p_term("t_CS", T_CCS)
2957 p_term("t_cs", T_CS)
2958#ifdef FEAT_VERTSPLIT
2959 p_term("t_CV", T_CSV)
2960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 p_term("t_da", T_DA)
2962 p_term("t_db", T_DB)
2963 p_term("t_DL", T_CDL)
2964 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002965 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 p_term("t_fs", T_FS)
2967 p_term("t_IE", T_CIE)
2968 p_term("t_IS", T_CIS)
2969 p_term("t_ke", T_KE)
2970 p_term("t_ks", T_KS)
2971 p_term("t_le", T_LE)
2972 p_term("t_mb", T_MB)
2973 p_term("t_md", T_MD)
2974 p_term("t_me", T_ME)
2975 p_term("t_mr", T_MR)
2976 p_term("t_ms", T_MS)
2977 p_term("t_nd", T_ND)
2978 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002979 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 p_term("t_RI", T_CRI)
2981 p_term("t_RV", T_CRV)
2982 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002984 p_term("t_Sf", T_CSF)
2985 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02002987 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 p_term("t_te", T_TE)
2990 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02002991 p_term("t_ts", T_TS)
2992 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993 p_term("t_ue", T_UE)
2994 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02002995 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 p_term("t_vb", T_VB)
2997 p_term("t_ve", T_VE)
2998 p_term("t_vi", T_VI)
2999 p_term("t_vs", T_VS)
3000 p_term("t_WP", T_CWP)
3001 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003002 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 p_term("t_xs", T_XS)
3004 p_term("t_ZH", T_CZH)
3005 p_term("t_ZR", T_CZR)
3006
3007/* terminal key codes are not in here */
3008
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003009 /* end marker */
3010 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011};
3012
3013#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3014
3015#ifdef FEAT_MBYTE
3016static char *(p_ambw_values[]) = {"single", "double", NULL};
3017#endif
3018static char *(p_bg_values[]) = {"light", "dark", NULL};
3019static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3020static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003021#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003022static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003023#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003024#ifdef FEAT_CMDL_COMPL
3025static char *(p_wop_values[]) = {"tagfile", NULL};
3026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027#ifdef FEAT_WAK
3028static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3029#endif
3030static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3032static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034#ifdef FEAT_BROWSE
3035static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3036#endif
3037#ifdef FEAT_SCROLLBIND
3038static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3039#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003040static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041#ifdef FEAT_VERTSPLIT
3042static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3043#endif
3044#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003045# ifdef FEAT_AUTOCMD
3046static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3047# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003049# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3051#endif
3052static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3053#ifdef FEAT_FOLDING
3054static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003055# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003057# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 NULL};
3059static char *(p_fcl_values[]) = {"all", NULL};
3060#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003061#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003062static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003063#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064
3065static void set_option_default __ARGS((int, int opt_flags, int compatible));
3066static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003067static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003068static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069static char_u *illegal_char __ARGS((char_u *, int));
3070static int string_to_key __ARGS((char_u *arg));
3071#ifdef FEAT_CMDWIN
3072static char_u *check_cedit __ARGS((void));
3073#endif
3074#ifdef FEAT_TITLE
3075static void did_set_title __ARGS((int icon));
3076#endif
3077static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3078static void didset_options __ARGS((void));
3079static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003080#if defined(FEAT_EVAL) || defined(PROTO)
3081static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3082#else
3083# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003086static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087static 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));
3088static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003089#ifdef FEAT_SYN_HL
3090static int int_cmp __ARGS((const void *a, const void *b));
3091#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092#ifdef FEAT_CLIPBOARD
3093static char_u *check_clipboard_option __ARGS((void));
3094#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003095#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003096static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003097#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003098#ifdef FEAT_EVAL
3099static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003102static 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 +00003103static void check_redraw __ARGS((long_u flags));
3104static int findoption __ARGS((char_u *));
3105static int find_key_option __ARGS((char_u *));
3106static void showoptions __ARGS((int all, int opt_flags));
3107static int optval_default __ARGS((struct vimoption *, char_u *varp));
3108static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3109static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3110static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3111static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3112static int istermoption __ARGS((struct vimoption *));
3113static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3114static char_u *get_varp __ARGS((struct vimoption *));
3115static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003116static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3118#ifdef FEAT_LANGMAP
3119static void langmap_init __ARGS((void));
3120static void langmap_set __ARGS((void));
3121#endif
3122static void paste_option_changed __ARGS((void));
3123static void compatible_set __ARGS((void));
3124#ifdef FEAT_LINEBREAK
3125static void fill_breakat_flags __ARGS((void));
3126#endif
3127static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3128static int check_opt_strings __ARGS((char_u *val, char **values, int));
3129static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003130#ifdef FEAT_LINEBREAK
3131static int briopt_check __ARGS((win_T *wp));
3132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133
3134/*
3135 * Initialize the options, first part.
3136 *
3137 * Called only once from main(), just after creating the first buffer.
3138 */
3139 void
3140set_init_1()
3141{
3142 char_u *p;
3143 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003144 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145
3146#ifdef FEAT_LANGMAP
3147 langmap_init();
3148#endif
3149
3150 /* Be Vi compatible by default */
3151 p_cp = TRUE;
3152
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003153 /* Use POSIX compatibility when $VIM_POSIX is set. */
3154 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003155 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003156 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003157 set_string_default("shm", (char_u *)"A");
3158 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003159
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 /*
3161 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003162 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003164 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3166# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003167 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003169 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003171 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172# endif
3173#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003174 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 set_string_default("sh", p);
3176
3177#ifdef FEAT_WILDIGN
3178 /*
3179 * Set the default for 'backupskip' to include environment variables for
3180 * temp files.
3181 */
3182 {
3183# ifdef UNIX
3184 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3185# else
3186 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3187# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003188 int len;
3189 garray_T ga;
3190 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191
3192 ga_init2(&ga, 1, 100);
3193 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3194 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003195 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196# ifdef UNIX
3197 if (*names[n] == NUL)
3198 p = (char_u *)"/tmp";
3199 else
3200# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003201 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 if (p != NULL && *p != NUL)
3203 {
3204 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003205 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206 if (ga_grow(&ga, len) == OK)
3207 {
3208 if (ga.ga_len > 0)
3209 STRCAT(ga.ga_data, ",");
3210 STRCAT(ga.ga_data, p);
3211 add_pathsep(ga.ga_data);
3212 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213 ga.ga_len += len;
3214 }
3215 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003216 if (mustfree)
3217 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 }
3219 if (ga.ga_data != NULL)
3220 {
3221 set_string_default("bsk", ga.ga_data);
3222 vim_free(ga.ga_data);
3223 }
3224 }
3225#endif
3226
3227 /*
3228 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3229 */
3230 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003231 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003233#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3234 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3235#endif
3236 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003238 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003239 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240#else
3241# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003242 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003243 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003245 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246# endif
3247#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003249 opt_idx = findoption((char_u *)"maxmem");
3250 if (opt_idx >= 0)
3251 {
3252#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003253 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003254 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3255#endif
3256 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3257 }
3258 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259 }
3260
3261#ifdef FEAT_GUI_W32
3262 /* force 'shortname' for Win32s */
3263 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003264 {
3265 opt_idx = findoption((char_u *)"shortname");
3266 if (opt_idx >= 0)
3267 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3268 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269#endif
3270
3271#ifdef FEAT_SEARCHPATH
3272 {
3273 char_u *cdpath;
3274 char_u *buf;
3275 int i;
3276 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003277 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278
3279 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003280 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281 if (cdpath != NULL)
3282 {
3283 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3284 if (buf != NULL)
3285 {
3286 buf[0] = ','; /* start with ",", current dir first */
3287 j = 1;
3288 for (i = 0; cdpath[i] != NUL; ++i)
3289 {
3290 if (vim_ispathlistsep(cdpath[i]))
3291 buf[j++] = ',';
3292 else
3293 {
3294 if (cdpath[i] == ' ' || cdpath[i] == ',')
3295 buf[j++] = '\\';
3296 buf[j++] = cdpath[i];
3297 }
3298 }
3299 buf[j] = NUL;
3300 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003301 if (opt_idx >= 0)
3302 {
3303 options[opt_idx].def_val[VI_DEFAULT] = buf;
3304 options[opt_idx].flags |= P_DEF_ALLOCED;
3305 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003306 else
3307 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003309 if (mustfree)
3310 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311 }
3312 }
3313#endif
3314
3315#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3316 /* Set print encoding on platforms that don't default to latin1 */
3317 set_string_default("penc",
3318# if defined(MSWIN) || defined(OS2)
3319 (char_u *)"cp1252"
3320# else
3321# ifdef VMS
3322 (char_u *)"dec-mcs"
3323# else
3324# ifdef EBCDIC
3325 (char_u *)"ebcdic-uk"
3326# else
3327# ifdef MAC
3328 (char_u *)"mac-roman"
3329# else /* HPUX */
3330 (char_u *)"hp-roman8"
3331# endif
3332# endif
3333# endif
3334# endif
3335 );
3336#endif
3337
3338#ifdef FEAT_POSTSCRIPT
3339 /* 'printexpr' must be allocated to be able to evaluate it. */
3340 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003341# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3342 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343# else
3344# ifdef VMS
3345 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3346
3347# else
3348 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3349# endif
3350# endif
3351 );
3352#endif
3353
3354 /*
3355 * Set all the options (except the terminal options) to their default
3356 * value. Also set the global value for local options.
3357 */
3358 set_options_default(0);
3359
3360#ifdef FEAT_GUI
3361 if (found_reverse_arg)
3362 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3363#endif
3364
3365 curbuf->b_p_initialized = TRUE;
3366 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003367 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368 check_buf_options(curbuf);
3369 check_win_options(curwin);
3370 check_options();
3371
3372 /* Must be before option_expand(), because that one needs vim_isIDc() */
3373 didset_options();
3374
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003375#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003376 /* Use the current chartab for the generic chartab. */
3377 init_spell_chartab();
3378#endif
3379
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380#ifdef FEAT_LINEBREAK
3381 /*
3382 * initialize the table for 'breakat'.
3383 */
3384 fill_breakat_flags();
3385#endif
3386
3387 /*
3388 * Expand environment variables and things like "~" for the defaults.
3389 * If option_expand() returns non-NULL the variable is expanded. This can
3390 * only happen for non-indirect options.
3391 * Also set the default to the expanded value, so ":set" does not list
3392 * them.
3393 * Don't set the P_ALLOCED flag, because we don't want to free the
3394 * default.
3395 */
3396 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3397 {
3398 if ((options[opt_idx].flags & P_GETTEXT)
3399 && options[opt_idx].var != NULL)
3400 p = (char_u *)_(*(char **)options[opt_idx].var);
3401 else
3402 p = option_expand(opt_idx, NULL);
3403 if (p != NULL && (p = vim_strsave(p)) != NULL)
3404 {
3405 *(char_u **)options[opt_idx].var = p;
3406 /* VIMEXP
3407 * Defaults for all expanded options are currently the same for Vi
3408 * and Vim. When this changes, add some code here! Also need to
3409 * split P_DEF_ALLOCED in two.
3410 */
3411 if (options[opt_idx].flags & P_DEF_ALLOCED)
3412 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3413 options[opt_idx].def_val[VI_DEFAULT] = p;
3414 options[opt_idx].flags |= P_DEF_ALLOCED;
3415 }
3416 }
3417
3418 /* Initialize the highlight_attr[] table. */
3419 highlight_changed();
3420
3421 save_file_ff(curbuf); /* Buffer is unchanged */
3422
3423 /* Parse default for 'wildmode' */
3424 check_opt_wim();
3425
3426#if defined(FEAT_ARABIC)
3427 /* Detect use of mlterm.
3428 * Mlterm is a terminal emulator akin to xterm that has some special
3429 * abilities (bidi namely).
3430 * NOTE: mlterm's author is being asked to 'set' a variable
3431 * instead of an environment variable due to inheritance.
3432 */
3433 if (mch_getenv((char_u *)"MLTERM") != NULL)
3434 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3435#endif
3436
3437#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3438 /* Parse default for 'fillchars'. */
3439 (void)set_chars_option(&p_fcs);
3440#endif
3441
3442#ifdef FEAT_CLIPBOARD
3443 /* Parse default for 'clipboard' */
3444 (void)check_clipboard_option();
3445#endif
3446
3447#ifdef FEAT_MBYTE
3448# if defined(WIN3264) && defined(FEAT_GETTEXT)
3449 /*
3450 * If $LANG isn't set, try to get a good value for it. This makes the
3451 * right language be used automatically. Don't do this for English.
3452 */
3453 if (mch_getenv((char_u *)"LANG") == NULL)
3454 {
3455 char buf[20];
3456
3457 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3458 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3459 * only the first two. */
3460 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3461 (LPTSTR)buf, 20);
3462 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3463 {
3464 /* There are a few exceptions (probably more) */
3465 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3466 STRCPY(buf, "zh_TW");
3467 else if (STRNICMP(buf, "chs", 3) == 0
3468 || STRNICMP(buf, "zhc", 3) == 0)
3469 STRCPY(buf, "zh_CN");
3470 else if (STRNICMP(buf, "jp", 2) == 0)
3471 STRCPY(buf, "ja");
3472 else
3473 buf[2] = NUL; /* truncate to two-letter code */
3474 vim_setenv("LANG", buf);
3475 }
3476 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003477# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003478# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003479 /* Moved to os_mac_conv.c to avoid dependency problems. */
3480 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003481# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482# endif
3483
3484 /* enc_locale() will try to find the encoding of the current locale. */
3485 p = enc_locale();
3486 if (p != NULL)
3487 {
3488 char_u *save_enc;
3489
3490 /* Try setting 'encoding' and check if the value is valid.
3491 * If not, go back to the default "latin1". */
3492 save_enc = p_enc;
3493 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003494 if (STRCMP(p_enc, "gb18030") == 0)
3495 {
3496 /* We don't support "gb18030", but "cp936" is a good substitute
3497 * for practical purposes, thus use that. It's not an alias to
3498 * still support conversion between gb18030 and utf-8. */
3499 p_enc = vim_strsave((char_u *)"cp936");
3500 vim_free(p);
3501 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502 if (mb_init() == NULL)
3503 {
3504 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003505 if (opt_idx >= 0)
3506 {
3507 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3508 options[opt_idx].flags |= P_DEF_ALLOCED;
3509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003511#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3512 || defined(VMS)
3513 if (STRCMP(p_enc, "latin1") == 0
3514# ifdef FEAT_MBYTE
3515 || enc_utf8
3516# endif
3517 )
3518 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003519 /* Adjust the default for 'isprint' and 'iskeyword' to match
3520 * latin1. Also set the defaults for when 'nocompatible' is
3521 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003522 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003523 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003524 set_string_option_direct((char_u *)"isk", -1,
3525 ISK_LATIN1, OPT_FREE, SID_NONE);
3526 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003527 if (opt_idx >= 0)
3528 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003529 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003530 if (opt_idx >= 0)
3531 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003532 (void)init_chartab();
3533 }
3534#endif
3535
Bram Moolenaar071d4272004-06-13 20:20:40 +00003536# if defined(WIN3264) && !defined(FEAT_GUI)
3537 /* Win32 console: When GetACP() returns a different value from
3538 * GetConsoleCP() set 'termencoding'. */
3539 if (GetACP() != GetConsoleCP())
3540 {
3541 char buf[50];
3542
3543 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3544 p_tenc = vim_strsave((char_u *)buf);
3545 if (p_tenc != NULL)
3546 {
3547 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003548 if (opt_idx >= 0)
3549 {
3550 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3551 options[opt_idx].flags |= P_DEF_ALLOCED;
3552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 convert_setup(&input_conv, p_tenc, p_enc);
3554 convert_setup(&output_conv, p_enc, p_tenc);
3555 }
3556 else
3557 p_tenc = empty_option;
3558 }
3559# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003560# if defined(WIN3264) && defined(FEAT_MBYTE)
3561 /* $HOME may have characters in active code page. */
3562 init_homedir();
3563# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564 }
3565 else
3566 {
3567 vim_free(p_enc);
3568 p_enc = save_enc;
3569 }
3570 }
3571#endif
3572
3573#ifdef FEAT_MULTI_LANG
3574 /* Set the default for 'helplang'. */
3575 set_helplang_default(get_mess_lang());
3576#endif
3577}
3578
3579/*
3580 * Set an option to its default value.
3581 * This does not take care of side effects!
3582 */
3583 static void
3584set_option_default(opt_idx, opt_flags, compatible)
3585 int opt_idx;
3586 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3587 int compatible; /* use Vi default value */
3588{
3589 char_u *varp; /* pointer to variable for current option */
3590 int dvi; /* index in def_val[] */
3591 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003592 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3594
3595 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3596 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003597 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 {
3599 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3600 if (flags & P_STRING)
3601 {
3602 /* Use set_string_option_direct() for local options to handle
3603 * freeing and allocating the value. */
3604 if (options[opt_idx].indir != PV_NONE)
3605 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003606 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 else
3608 {
3609 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3610 free_string_option(*(char_u **)(varp));
3611 *(char_u **)varp = options[opt_idx].def_val[dvi];
3612 options[opt_idx].flags &= ~P_ALLOCED;
3613 }
3614 }
3615 else if (flags & P_NUM)
3616 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003617 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 win_comp_scroll(curwin);
3619 else
3620 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003621 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 /* May also set global value for local option. */
3623 if (both)
3624 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3625 *(long *)varp;
3626 }
3627 }
3628 else /* P_BOOL */
3629 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003630 /* the cast to long is required for Manx C, long_i is needed for
3631 * MSVC */
3632 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003633#ifdef UNIX
3634 /* 'modeline' defaults to off for root */
3635 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3636 *(int *)varp = FALSE;
3637#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 /* May also set global value for local option. */
3639 if (both)
3640 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3641 *(int *)varp;
3642 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003643
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003644 /* The default value is not insecure. */
3645 flagsp = insecure_flag(opt_idx, opt_flags);
3646 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003647 }
3648
3649#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003650 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651#endif
3652}
3653
3654/*
3655 * Set all options (except terminal options) to their default value.
3656 */
3657 static void
3658set_options_default(opt_flags)
3659 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3660{
3661 int i;
3662#ifdef FEAT_WINDOWS
3663 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003664 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665#endif
3666
3667 for (i = 0; !istermoption(&options[i]); i++)
3668 if (!(options[i].flags & P_NODEFAULT))
3669 set_option_default(i, opt_flags, p_cp);
3670
3671#ifdef FEAT_WINDOWS
3672 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003673 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674 win_comp_scroll(wp);
3675#else
3676 win_comp_scroll(curwin);
3677#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003678#ifdef FEAT_CINDENT
3679 parse_cino(curbuf);
3680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681}
3682
3683/*
3684 * Set the Vi-default value of a string option.
3685 * Used for 'sh', 'backupskip' and 'term'.
3686 */
3687 void
3688set_string_default(name, val)
3689 char *name;
3690 char_u *val;
3691{
3692 char_u *p;
3693 int opt_idx;
3694
3695 p = vim_strsave(val);
3696 if (p != NULL) /* we don't want a NULL */
3697 {
3698 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 {
3701 if (options[opt_idx].flags & P_DEF_ALLOCED)
3702 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3703 options[opt_idx].def_val[VI_DEFAULT] = p;
3704 options[opt_idx].flags |= P_DEF_ALLOCED;
3705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 }
3707}
3708
3709/*
3710 * Set the Vi-default value of a number option.
3711 * Used for 'lines' and 'columns'.
3712 */
3713 void
3714set_number_default(name, val)
3715 char *name;
3716 long val;
3717{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003718 int opt_idx;
3719
3720 opt_idx = findoption((char_u *)name);
3721 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003722 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723}
3724
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003725#if defined(EXITFREE) || defined(PROTO)
3726/*
3727 * Free all options.
3728 */
3729 void
3730free_all_options()
3731{
3732 int i;
3733
3734 for (i = 0; !istermoption(&options[i]); i++)
3735 {
3736 if (options[i].indir == PV_NONE)
3737 {
3738 /* global option: free value and default value. */
3739 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3740 free_string_option(*(char_u **)options[i].var);
3741 if (options[i].flags & P_DEF_ALLOCED)
3742 free_string_option(options[i].def_val[VI_DEFAULT]);
3743 }
3744 else if (options[i].var != VAR_WIN
3745 && (options[i].flags & P_STRING))
3746 /* buffer-local option: free global value */
3747 free_string_option(*(char_u **)options[i].var);
3748 }
3749}
3750#endif
3751
3752
Bram Moolenaar071d4272004-06-13 20:20:40 +00003753/*
3754 * Initialize the options, part two: After getting Rows and Columns and
3755 * setting 'term'.
3756 */
3757 void
3758set_init_2()
3759{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003760 int idx;
3761
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 /*
3763 * 'scroll' defaults to half the window height. Note that this default is
3764 * wrong when the window height changes.
3765 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003766 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003767 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003768 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003769 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 comp_col();
3771
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003772 /*
3773 * 'window' is only for backwards compatibility with Vi.
3774 * Default is Rows - 1.
3775 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003776 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003777 p_window = Rows - 1;
3778 set_number_default("window", Rows - 1);
3779
Bram Moolenaarf740b292006-02-16 22:11:02 +00003780 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003782 /*
3783 * If 'background' wasn't set by the user, try guessing the value,
3784 * depending on the terminal name. Only need to check for terminals
3785 * with a dark background, that can handle color.
3786 */
3787 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003788 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3789 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003791 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003792 /* don't mark it as set, when starting the GUI it may be
3793 * changed again */
3794 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 }
3796#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003797
3798#ifdef CURSOR_SHAPE
3799 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3800#endif
3801#ifdef FEAT_MOUSESHAPE
3802 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3803#endif
3804#ifdef FEAT_PRINTER
3805 (void)parse_printoptions(); /* parse 'printoptions' default value */
3806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807}
3808
3809/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003810 * Return "dark" or "light" depending on the kind of terminal.
3811 * This is just guessing! Recognized are:
3812 * "linux" Linux console
3813 * "screen.linux" Linux console with screen
3814 * "cygwin" Cygwin shell
3815 * "putty" Putty program
3816 * We also check the COLORFGBG environment variable, which is set by
3817 * rxvt and derivatives. This variable contains either two or three
3818 * values separated by semicolons; we want the last value in either
3819 * case. If this value is 0-6 or 8, our background is dark.
3820 */
3821 static char_u *
3822term_bg_default()
3823{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3825 /* DOS console nearly always black */
3826 return (char_u *)"dark";
3827#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003828 char_u *p;
3829
Bram Moolenaarf740b292006-02-16 22:11:02 +00003830 if (STRCMP(T_NAME, "linux") == 0
3831 || STRCMP(T_NAME, "screen.linux") == 0
3832 || STRCMP(T_NAME, "cygwin") == 0
3833 || STRCMP(T_NAME, "putty") == 0
3834 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3835 && (p = vim_strrchr(p, ';')) != NULL
3836 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3837 && p[2] == NUL))
3838 return (char_u *)"dark";
3839 return (char_u *)"light";
3840#endif
3841}
3842
3843/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844 * Initialize the options, part three: After reading the .vimrc
3845 */
3846 void
3847set_init_3()
3848{
3849#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3850/*
3851 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3852 * This is done after other initializations, where 'shell' might have been
3853 * set, but only if they have not been set before.
3854 */
3855 char_u *p;
3856 int idx_srr;
3857 int do_srr;
3858#ifdef FEAT_QUICKFIX
3859 int idx_sp;
3860 int do_sp;
3861#endif
3862
3863 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003864 if (idx_srr < 0)
3865 do_srr = FALSE;
3866 else
3867 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868#ifdef FEAT_QUICKFIX
3869 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003870 if (idx_sp < 0)
3871 do_sp = FALSE;
3872 else
3873 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003875 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876 if (p != NULL)
3877 {
3878 /*
3879 * Default for p_sp is "| tee", for p_srr is ">".
3880 * For known shells it is changed here to include stderr.
3881 */
3882 if ( fnamecmp(p, "csh") == 0
3883 || fnamecmp(p, "tcsh") == 0
3884# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3885 || fnamecmp(p, "csh.exe") == 0
3886 || fnamecmp(p, "tcsh.exe") == 0
3887# endif
3888 )
3889 {
3890#if defined(FEAT_QUICKFIX)
3891 if (do_sp)
3892 {
3893# ifdef WIN3264
3894 p_sp = (char_u *)">&";
3895# else
3896 p_sp = (char_u *)"|& tee";
3897# endif
3898 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3899 }
3900#endif
3901 if (do_srr)
3902 {
3903 p_srr = (char_u *)">&";
3904 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3905 }
3906 }
3907 else
3908# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3909 if ( fnamecmp(p, "sh") == 0
3910 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003911 || fnamecmp(p, "mksh") == 0
3912 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003914 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003916 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917# ifdef WIN3264
3918 || fnamecmp(p, "cmd") == 0
3919 || fnamecmp(p, "sh.exe") == 0
3920 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003921 || fnamecmp(p, "mksh.exe") == 0
3922 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003924 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 || fnamecmp(p, "bash.exe") == 0
3926 || fnamecmp(p, "cmd.exe") == 0
3927# endif
3928 )
3929# endif
3930 {
3931#if defined(FEAT_QUICKFIX)
3932 if (do_sp)
3933 {
3934# ifdef WIN3264
3935 p_sp = (char_u *)">%s 2>&1";
3936# else
3937 p_sp = (char_u *)"2>&1| tee";
3938# endif
3939 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3940 }
3941#endif
3942 if (do_srr)
3943 {
3944 p_srr = (char_u *)">%s 2>&1";
3945 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3946 }
3947 }
3948 vim_free(p);
3949 }
3950#endif
3951
3952#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3953 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003954 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3955 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 * This is done after other initializations, where 'shell' might have been
3957 * set, but only if they have not been set before. Default for p_shcf is
3958 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3959 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3960 * command.com. And for Win32 we need to set p_sxq instead.
3961 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003962 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 {
3964 int idx3;
3965
3966 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003967 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968 {
3969 p_shcf = (char_u *)"-c";
3970 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3971 }
3972
3973# ifndef DJGPP
3974# ifdef WIN3264
3975 /* Somehow Win32 requires the quotes around the redirection too */
3976 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003977 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 {
3979 p_sxq = (char_u *)"\"";
3980 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3981 }
3982# else
3983 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003984 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003985 {
3986 p_shq = (char_u *)"\"";
3987 options[idx3].def_val[VI_DEFAULT] = p_shq;
3988 }
3989# endif
3990# endif
3991 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003992 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3993 {
3994 int idx3;
3995
3996 /*
3997 * cmd.exe on Windows will strip the first and last double quote given
3998 * on the command line, e.g. most of the time things like:
3999 * cmd /c "my path/to/echo" "my args to echo"
4000 * become:
4001 * my path/to/echo" "my args to echo
4002 * when executed.
4003 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004004 * To avoid this, set shellxquote to surround the command in
4005 * parenthesis. This appears to make most commands work, without
4006 * breaking commands that worked previously, such as
4007 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004009 idx3 = findoption((char_u *)"sxq");
4010 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4011 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004012 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004013 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4014 }
4015
Bram Moolenaara64ba222012-02-12 23:23:31 +01004016 idx3 = findoption((char_u *)"shcf");
4017 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4018 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004019 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004020 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4021 }
4022 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023#endif
4024
4025#ifdef FEAT_TITLE
4026 set_title_defaults();
4027#endif
4028}
4029
4030#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4031/*
4032 * When 'helplang' is still at its default value, set it to "lang".
4033 * Only the first two characters of "lang" are used.
4034 */
4035 void
4036set_helplang_default(lang)
4037 char_u *lang;
4038{
4039 int idx;
4040
4041 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4042 return;
4043 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004044 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 {
4046 if (options[idx].flags & P_ALLOCED)
4047 free_string_option(p_hlg);
4048 p_hlg = vim_strsave(lang);
4049 if (p_hlg == NULL)
4050 p_hlg = empty_option;
4051 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004052 {
4053 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4054 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4055 {
4056 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4057 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 options[idx].flags |= P_ALLOCED;
4062 }
4063}
4064#endif
4065
4066#ifdef FEAT_GUI
4067static char_u *gui_bg_default __ARGS((void));
4068
4069 static char_u *
4070gui_bg_default()
4071{
4072 if (gui_get_lightness(gui.back_pixel) < 127)
4073 return (char_u *)"dark";
4074 return (char_u *)"light";
4075}
4076
4077/*
4078 * Option initializations that can only be done after opening the GUI window.
4079 */
4080 void
4081init_gui_options()
4082{
4083 /* Set the 'background' option according to the lightness of the
4084 * background color, unless the user has set it already. */
4085 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4086 {
4087 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4088 highlight_changed();
4089 }
4090}
4091#endif
4092
4093#ifdef FEAT_TITLE
4094/*
4095 * 'title' and 'icon' only default to true if they have not been set or reset
4096 * in .vimrc and we can read the old value.
4097 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4098 * they can be reset. This reduces startup time when using X on a remote
4099 * machine.
4100 */
4101 void
4102set_title_defaults()
4103{
4104 int idx1;
4105 long val;
4106
4107 /*
4108 * If GUI is (going to be) used, we can always set the window title and
4109 * icon name. Saves a bit of time, because the X11 display server does
4110 * not need to be contacted.
4111 */
4112 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004113 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 {
4115#ifdef FEAT_GUI
4116 if (gui.starting || gui.in_use)
4117 val = TRUE;
4118 else
4119#endif
4120 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004121 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 p_title = val;
4123 }
4124 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004125 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 {
4127#ifdef FEAT_GUI
4128 if (gui.starting || gui.in_use)
4129 val = TRUE;
4130 else
4131#endif
4132 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004133 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 p_icon = val;
4135 }
4136}
4137#endif
4138
4139/*
4140 * Parse 'arg' for option settings.
4141 *
4142 * 'arg' may be IObuff, but only when no errors can be present and option
4143 * does not need to be expanded with option_expand().
4144 * "opt_flags":
4145 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004146 * OPT_GLOBAL for ":setglobal"
4147 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004149 * OPT_WINONLY to only set window-local options
4150 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 *
4152 * returns FAIL if an error is detected, OK otherwise
4153 */
4154 int
4155do_set(arg, opt_flags)
4156 char_u *arg; /* option string (may be written to!) */
4157 int opt_flags;
4158{
4159 int opt_idx;
4160 char_u *errmsg;
4161 char_u errbuf[80];
4162 char_u *startarg;
4163 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4164 int nextchar; /* next non-white char after option name */
4165 int afterchar; /* character just after option name */
4166 int len;
4167 int i;
4168 long value;
4169 int key;
4170 long_u flags; /* flags for current option */
4171 char_u *varp = NULL; /* pointer to variable for current option */
4172 int did_show = FALSE; /* already showed one value */
4173 int adding; /* "opt+=arg" */
4174 int prepending; /* "opt^=arg" */
4175 int removing; /* "opt-=arg" */
4176 int cp_val = 0;
4177 char_u key_name[2];
4178
4179 if (*arg == NUL)
4180 {
4181 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004182 did_show = TRUE;
4183 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 }
4185
4186 while (*arg != NUL) /* loop to process all options */
4187 {
4188 errmsg = NULL;
4189 startarg = arg; /* remember for error message */
4190
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004191 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4192 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 {
4194 /*
4195 * ":set all" show all options.
4196 * ":set all&" set all options to their default value.
4197 */
4198 arg += 3;
4199 if (*arg == '&')
4200 {
4201 ++arg;
4202 /* Only for :set command set global value of local options. */
4203 set_options_default(OPT_FREE | opt_flags);
4204 }
4205 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004206 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004208 did_show = TRUE;
4209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004211 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 {
4213 showoptions(2, opt_flags);
4214 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004215 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216 arg += 7;
4217 }
4218 else
4219 {
4220 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004221 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 {
4223 prefix = 0;
4224 arg += 2;
4225 }
4226 else if (STRNCMP(arg, "inv", 3) == 0)
4227 {
4228 prefix = 2;
4229 arg += 3;
4230 }
4231
4232 /* find end of name */
4233 key = 0;
4234 if (*arg == '<')
4235 {
4236 nextchar = 0;
4237 opt_idx = -1;
4238 /* look out for <t_>;> */
4239 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4240 len = 5;
4241 else
4242 {
4243 len = 1;
4244 while (arg[len] != NUL && arg[len] != '>')
4245 ++len;
4246 }
4247 if (arg[len] != '>')
4248 {
4249 errmsg = e_invarg;
4250 goto skip;
4251 }
4252 arg[len] = NUL; /* put NUL after name */
4253 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4254 opt_idx = findoption(arg + 1);
4255 arg[len++] = '>'; /* restore '>' */
4256 if (opt_idx == -1)
4257 key = find_key_option(arg + 1);
4258 }
4259 else
4260 {
4261 len = 0;
4262 /*
4263 * The two characters after "t_" may not be alphanumeric.
4264 */
4265 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4266 len = 4;
4267 else
4268 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4269 ++len;
4270 nextchar = arg[len];
4271 arg[len] = NUL; /* put NUL after name */
4272 opt_idx = findoption(arg);
4273 arg[len] = nextchar; /* restore nextchar */
4274 if (opt_idx == -1)
4275 key = find_key_option(arg);
4276 }
4277
4278 /* remember character after option name */
4279 afterchar = arg[len];
4280
4281 /* skip white space, allow ":set ai ?" */
4282 while (vim_iswhite(arg[len]))
4283 ++len;
4284
4285 adding = FALSE;
4286 prepending = FALSE;
4287 removing = FALSE;
4288 if (arg[len] != NUL && arg[len + 1] == '=')
4289 {
4290 if (arg[len] == '+')
4291 {
4292 adding = TRUE; /* "+=" */
4293 ++len;
4294 }
4295 else if (arg[len] == '^')
4296 {
4297 prepending = TRUE; /* "^=" */
4298 ++len;
4299 }
4300 else if (arg[len] == '-')
4301 {
4302 removing = TRUE; /* "-=" */
4303 ++len;
4304 }
4305 }
4306 nextchar = arg[len];
4307
4308 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4309 {
4310 errmsg = (char_u *)N_("E518: Unknown option");
4311 goto skip;
4312 }
4313
4314 if (opt_idx >= 0)
4315 {
4316 if (options[opt_idx].var == NULL) /* hidden option: skip */
4317 {
4318 /* Only give an error message when requesting the value of
4319 * a hidden option, ignore setting it. */
4320 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4321 && (!(options[opt_idx].flags & P_BOOL)
4322 || nextchar == '?'))
4323 errmsg = (char_u *)N_("E519: Option not supported");
4324 goto skip;
4325 }
4326
4327 flags = options[opt_idx].flags;
4328 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4329 }
4330 else
4331 {
4332 flags = P_STRING;
4333 if (key < 0)
4334 {
4335 key_name[0] = KEY2TERMCAP0(key);
4336 key_name[1] = KEY2TERMCAP1(key);
4337 }
4338 else
4339 {
4340 key_name[0] = KS_KEY;
4341 key_name[1] = (key & 0xff);
4342 }
4343 }
4344
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004345 /* Skip all options that are not window-local (used when showing
4346 * an already loaded buffer in a window). */
4347 if ((opt_flags & OPT_WINONLY)
4348 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4349 goto skip;
4350
Bram Moolenaara3227e22006-03-08 21:32:40 +00004351 /* Skip all options that are window-local (used for :vimgrep). */
4352 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4353 && options[opt_idx].var == VAR_WIN)
4354 goto skip;
4355
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004356 /* Disallow changing some options from modelines. */
4357 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004359 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004360 {
4361 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4362 goto skip;
4363 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004364#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004365 /* In diff mode some options are overruled. This avoids that
4366 * 'foldmethod' becomes "marker" instead of "diff" and that
4367 * "wrap" gets set. */
4368 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004369 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004370 && (options[opt_idx].indir == PV_FDM
4371 || options[opt_idx].indir == PV_WRAP))
4372 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374 }
4375
4376#ifdef HAVE_SANDBOX
4377 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004378 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 {
4380 errmsg = (char_u *)_(e_sandbox);
4381 goto skip;
4382 }
4383#endif
4384
4385 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4386 {
4387 arg += len;
4388 cp_val = p_cp;
4389 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4390 {
4391 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4392 {
4393 cp_val = FALSE;
4394 arg += 3;
4395 }
4396 else /* "opt&vi": set to Vi default */
4397 {
4398 cp_val = TRUE;
4399 arg += 2;
4400 }
4401 }
4402 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4403 && arg[1] != NUL && !vim_iswhite(arg[1]))
4404 {
4405 errmsg = e_trailing;
4406 goto skip;
4407 }
4408 }
4409
4410 /*
4411 * allow '=' and ':' as MSDOS command.com allows only one
4412 * '=' character per "set" command line. grrr. (jw)
4413 */
4414 if (nextchar == '?'
4415 || (prefix == 1
4416 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4417 && !(flags & P_BOOL)))
4418 {
4419 /*
4420 * print value
4421 */
4422 if (did_show)
4423 msg_putchar('\n'); /* cursor below last one */
4424 else
4425 {
4426 gotocmdline(TRUE); /* cursor at status line */
4427 did_show = TRUE; /* remember that we did a line */
4428 }
4429 if (opt_idx >= 0)
4430 {
4431 showoneopt(&options[opt_idx], opt_flags);
4432#ifdef FEAT_EVAL
4433 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004434 {
4435 /* Mention where the option was last set. */
4436 if (varp == options[opt_idx].var)
4437 last_set_msg(options[opt_idx].scriptID);
4438 else if ((int)options[opt_idx].indir & PV_WIN)
4439 last_set_msg(curwin->w_p_scriptID[
4440 (int)options[opt_idx].indir & PV_MASK]);
4441 else if ((int)options[opt_idx].indir & PV_BUF)
4442 last_set_msg(curbuf->b_p_scriptID[
4443 (int)options[opt_idx].indir & PV_MASK]);
4444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445#endif
4446 }
4447 else
4448 {
4449 char_u *p;
4450
4451 p = find_termcode(key_name);
4452 if (p == NULL)
4453 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004454 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004455 goto skip;
4456 }
4457 else
4458 (void)show_one_termcode(key_name, p, TRUE);
4459 }
4460 if (nextchar != '?'
4461 && nextchar != NUL && !vim_iswhite(afterchar))
4462 errmsg = e_trailing;
4463 }
4464 else
4465 {
4466 if (flags & P_BOOL) /* boolean */
4467 {
4468 if (nextchar == '=' || nextchar == ':')
4469 {
4470 errmsg = e_invarg;
4471 goto skip;
4472 }
4473
4474 /*
4475 * ":set opt!": invert
4476 * ":set opt&": reset to default value
4477 * ":set opt<": reset to global value
4478 */
4479 if (nextchar == '!')
4480 value = *(int *)(varp) ^ 1;
4481 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004482 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004483 ((flags & P_VI_DEF) || cp_val)
4484 ? VI_DEFAULT : VIM_DEFAULT];
4485 else if (nextchar == '<')
4486 {
4487 /* For 'autoread' -1 means to use global value. */
4488 if ((int *)varp == &curbuf->b_p_ar
4489 && opt_flags == OPT_LOCAL)
4490 value = -1;
4491 else
4492 value = *(int *)get_varp_scope(&(options[opt_idx]),
4493 OPT_GLOBAL);
4494 }
4495 else
4496 {
4497 /*
4498 * ":set invopt": invert
4499 * ":set opt" or ":set noopt": set or reset
4500 */
4501 if (nextchar != NUL && !vim_iswhite(afterchar))
4502 {
4503 errmsg = e_trailing;
4504 goto skip;
4505 }
4506 if (prefix == 2) /* inv */
4507 value = *(int *)(varp) ^ 1;
4508 else
4509 value = prefix;
4510 }
4511
4512 errmsg = set_bool_option(opt_idx, varp, (int)value,
4513 opt_flags);
4514 }
4515 else /* numeric or string */
4516 {
4517 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4518 || prefix != 1)
4519 {
4520 errmsg = e_invarg;
4521 goto skip;
4522 }
4523
4524 if (flags & P_NUM) /* numeric */
4525 {
4526 /*
4527 * Different ways to set a number option:
4528 * & set to default value
4529 * < set to global value
4530 * <xx> accept special key codes for 'wildchar'
4531 * c accept any non-digit for 'wildchar'
4532 * [-]0-9 set number
4533 * other error
4534 */
4535 ++arg;
4536 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004537 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004538 ((flags & P_VI_DEF) || cp_val)
4539 ? VI_DEFAULT : VIM_DEFAULT];
4540 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004541 {
4542 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4543 * use the global value. */
4544 if ((long *)varp == &curbuf->b_p_ul
4545 && opt_flags == OPT_LOCAL)
4546 value = NO_LOCAL_UNDOLEVEL;
4547 else
4548 value = *(long *)get_varp_scope(
4549 &(options[opt_idx]), OPT_GLOBAL);
4550 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004551 else if (((long *)varp == &p_wc
4552 || (long *)varp == &p_wcm)
4553 && (*arg == '<'
4554 || *arg == '^'
4555 || ((!arg[1] || vim_iswhite(arg[1]))
4556 && !VIM_ISDIGIT(*arg))))
4557 {
4558 value = string_to_key(arg);
4559 if (value == 0 && (long *)varp != &p_wcm)
4560 {
4561 errmsg = e_invarg;
4562 goto skip;
4563 }
4564 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4566 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004567 /* Allow negative (for 'undolevels'), octal and
4568 * hex numbers. */
Bram Moolenaar5d1bc782015-07-17 13:03:48 +02004569 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4571 {
4572 errmsg = e_invarg;
4573 goto skip;
4574 }
4575 }
4576 else
4577 {
4578 errmsg = (char_u *)N_("E521: Number required after =");
4579 goto skip;
4580 }
4581
4582 if (adding)
4583 value = *(long *)varp + value;
4584 if (prepending)
4585 value = *(long *)varp * value;
4586 if (removing)
4587 value = *(long *)varp - value;
4588 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004589 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004590 }
4591 else if (opt_idx >= 0) /* string */
4592 {
4593 char_u *save_arg = NULL;
4594 char_u *s = NULL;
4595 char_u *oldval; /* previous value if *varp */
4596 char_u *newval;
4597 char_u *origval;
4598 unsigned newlen;
4599 int comma;
4600 int bs;
4601 int new_value_alloced; /* new string option
4602 was allocated */
4603
4604 /* When using ":set opt=val" for a global option
4605 * with a local value the local value will be
4606 * reset, use the global value here. */
4607 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004608 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004609 varp = options[opt_idx].var;
4610
4611 /* The old value is kept until we are sure that the
4612 * new value is valid. */
4613 oldval = *(char_u **)varp;
4614 if (nextchar == '&') /* set to default val */
4615 {
4616 newval = options[opt_idx].def_val[
4617 ((flags & P_VI_DEF) || cp_val)
4618 ? VI_DEFAULT : VIM_DEFAULT];
4619 if ((char_u **)varp == &p_bg)
4620 {
4621 /* guess the value of 'background' */
4622#ifdef FEAT_GUI
4623 if (gui.in_use)
4624 newval = gui_bg_default();
4625 else
4626#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004627 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004628 }
4629
4630 /* expand environment variables and ~ (since the
4631 * default value was already expanded, only
4632 * required when an environment variable was set
4633 * later */
4634 if (newval == NULL)
4635 newval = empty_option;
4636 else
4637 {
4638 s = option_expand(opt_idx, newval);
4639 if (s == NULL)
4640 s = newval;
4641 newval = vim_strsave(s);
4642 }
4643 new_value_alloced = TRUE;
4644 }
4645 else if (nextchar == '<') /* set to global val */
4646 {
4647 newval = vim_strsave(*(char_u **)get_varp_scope(
4648 &(options[opt_idx]), OPT_GLOBAL));
4649 new_value_alloced = TRUE;
4650 }
4651 else
4652 {
4653 ++arg; /* jump to after the '=' or ':' */
4654
4655 /*
4656 * Set 'keywordprg' to ":help" if an empty
4657 * value was passed to :set by the user.
4658 * Misuse errbuf[] for the resulting string.
4659 */
4660 if (varp == (char_u *)&p_kp
4661 && (*arg == NUL || *arg == ' '))
4662 {
4663 STRCPY(errbuf, ":help");
4664 save_arg = arg;
4665 arg = errbuf;
4666 }
4667 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004668 * Convert 'backspace' number to string, for
4669 * adding, prepending and removing string.
4670 */
4671 else if (varp == (char_u *)&p_bs
4672 && VIM_ISDIGIT(**(char_u **)varp))
4673 {
4674 i = getdigits((char_u **)varp);
4675 switch (i)
4676 {
4677 case 0:
4678 *(char_u **)varp = empty_option;
4679 break;
4680 case 1:
4681 *(char_u **)varp = vim_strsave(
4682 (char_u *)"indent,eol");
4683 break;
4684 case 2:
4685 *(char_u **)varp = vim_strsave(
4686 (char_u *)"indent,eol,start");
4687 break;
4688 }
4689 vim_free(oldval);
4690 oldval = *(char_u **)varp;
4691 }
4692 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004693 * Convert 'whichwrap' number to string, for
4694 * backwards compatibility with Vim 3.0.
4695 * Misuse errbuf[] for the resulting string.
4696 */
4697 else if (varp == (char_u *)&p_ww
4698 && VIM_ISDIGIT(*arg))
4699 {
4700 *errbuf = NUL;
4701 i = getdigits(&arg);
4702 if (i & 1)
4703 STRCAT(errbuf, "b,");
4704 if (i & 2)
4705 STRCAT(errbuf, "s,");
4706 if (i & 4)
4707 STRCAT(errbuf, "h,l,");
4708 if (i & 8)
4709 STRCAT(errbuf, "<,>,");
4710 if (i & 16)
4711 STRCAT(errbuf, "[,],");
4712 if (*errbuf != NUL) /* remove trailing , */
4713 errbuf[STRLEN(errbuf) - 1] = NUL;
4714 save_arg = arg;
4715 arg = errbuf;
4716 }
4717 /*
4718 * Remove '>' before 'dir' and 'bdir', for
4719 * backwards compatibility with version 3.0
4720 */
4721 else if ( *arg == '>'
4722 && (varp == (char_u *)&p_dir
4723 || varp == (char_u *)&p_bdir))
4724 {
4725 ++arg;
4726 }
4727
4728 /* When setting the local value of a global
4729 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004730 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004731 && (opt_flags & OPT_LOCAL))
4732 origval = *(char_u **)get_varp(
4733 &options[opt_idx]);
4734 else
4735 origval = oldval;
4736
4737 /*
4738 * Copy the new string into allocated memory.
4739 * Can't use set_string_option_direct(), because
4740 * we need to remove the backslashes.
4741 */
4742 /* get a bit too much */
4743 newlen = (unsigned)STRLEN(arg) + 1;
4744 if (adding || prepending || removing)
4745 newlen += (unsigned)STRLEN(origval) + 1;
4746 newval = alloc(newlen);
4747 if (newval == NULL) /* out of mem, don't change */
4748 break;
4749 s = newval;
4750
4751 /*
4752 * Copy the string, skip over escaped chars.
4753 * For MS-DOS and WIN32 backslashes before normal
4754 * file name characters are not removed, and keep
4755 * backslash at start, for "\\machine\path", but
4756 * do remove it for "\\\\machine\\path".
4757 * The reverse is found in ExpandOldSetting().
4758 */
4759 while (*arg && !vim_iswhite(*arg))
4760 {
4761 if (*arg == '\\' && arg[1] != NUL
4762#ifdef BACKSLASH_IN_FILENAME
4763 && !((flags & P_EXPAND)
4764 && vim_isfilec(arg[1])
4765 && (arg[1] != '\\'
4766 || (s == newval
4767 && arg[2] != '\\')))
4768#endif
4769 )
4770 ++arg; /* remove backslash */
4771#ifdef FEAT_MBYTE
4772 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004773 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004774 {
4775 /* copy multibyte char */
4776 mch_memmove(s, arg, (size_t)i);
4777 arg += i;
4778 s += i;
4779 }
4780 else
4781#endif
4782 *s++ = *arg++;
4783 }
4784 *s = NUL;
4785
4786 /*
4787 * Expand environment variables and ~.
4788 * Don't do it when adding without inserting a
4789 * comma.
4790 */
4791 if (!(adding || prepending || removing)
4792 || (flags & P_COMMA))
4793 {
4794 s = option_expand(opt_idx, newval);
4795 if (s != NULL)
4796 {
4797 vim_free(newval);
4798 newlen = (unsigned)STRLEN(s) + 1;
4799 if (adding || prepending || removing)
4800 newlen += (unsigned)STRLEN(origval) + 1;
4801 newval = alloc(newlen);
4802 if (newval == NULL)
4803 break;
4804 STRCPY(newval, s);
4805 }
4806 }
4807
4808 /* locate newval[] in origval[] when removing it
4809 * and when adding to avoid duplicates */
4810 i = 0; /* init for GCC */
4811 if (removing || (flags & P_NODUP))
4812 {
4813 i = (int)STRLEN(newval);
4814 bs = 0;
4815 for (s = origval; *s; ++s)
4816 {
4817 if ((!(flags & P_COMMA)
4818 || s == origval
4819 || (s[-1] == ',' && !(bs & 1)))
4820 && STRNCMP(s, newval, i) == 0
4821 && (!(flags & P_COMMA)
4822 || s[i] == ','
4823 || s[i] == NUL))
4824 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004825 /* Count backslashes. Only a comma with an
4826 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004827 * recognized as a separator */
4828 if (s > origval && s[-1] == '\\')
4829 ++bs;
4830 else
4831 bs = 0;
4832 }
4833
4834 /* do not add if already there */
4835 if ((adding || prepending) && *s)
4836 {
4837 prepending = FALSE;
4838 adding = FALSE;
4839 STRCPY(newval, origval);
4840 }
4841 }
4842
4843 /* concatenate the two strings; add a ',' if
4844 * needed */
4845 if (adding || prepending)
4846 {
4847 comma = ((flags & P_COMMA) && *origval != NUL
4848 && *newval != NUL);
4849 if (adding)
4850 {
4851 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004852 /* strip a trailing comma, would get 2 */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02004853 if (comma && (flags & P_ONECOMMA) && i > 1
4854 && origval[i - 1] == ','
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004855 && origval[i - 2] != '\\')
4856 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004857 mch_memmove(newval + i + comma, newval,
4858 STRLEN(newval) + 1);
4859 mch_memmove(newval, origval, (size_t)i);
4860 }
4861 else
4862 {
4863 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004864 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004865 }
4866 if (comma)
4867 newval[i] = ',';
4868 }
4869
4870 /* Remove newval[] from origval[]. (Note: "i" has
4871 * been set above and is used here). */
4872 if (removing)
4873 {
4874 STRCPY(newval, origval);
4875 if (*s)
4876 {
4877 /* may need to remove a comma */
4878 if (flags & P_COMMA)
4879 {
4880 if (s == origval)
4881 {
4882 /* include comma after string */
4883 if (s[i] == ',')
4884 ++i;
4885 }
4886 else
4887 {
4888 /* include comma before string */
4889 --s;
4890 ++i;
4891 }
4892 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004893 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004894 }
4895 }
4896
4897 if (flags & P_FLAGLIST)
4898 {
4899 /* Remove flags that appear twice. */
4900 for (s = newval; *s; ++s)
4901 if ((!(flags & P_COMMA) || *s != ',')
4902 && vim_strchr(s + 1, *s) != NULL)
4903 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004904 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004905 --s;
4906 }
4907 }
4908
4909 if (save_arg != NULL) /* number for 'whichwrap' */
4910 arg = save_arg;
4911 new_value_alloced = TRUE;
4912 }
4913
4914 /* Set the new value. */
4915 *(char_u **)(varp) = newval;
4916
4917 /* Handle side effects, and set the global value for
4918 * ":set" on local options. */
4919 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4920 new_value_alloced, oldval, errbuf, opt_flags);
4921
4922 /* If error detected, print the error message. */
4923 if (errmsg != NULL)
4924 goto skip;
4925 }
4926 else /* key code option */
4927 {
4928 char_u *p;
4929
4930 if (nextchar == '&')
4931 {
4932 if (add_termcap_entry(key_name, TRUE) == FAIL)
4933 errmsg = (char_u *)N_("E522: Not found in termcap");
4934 }
4935 else
4936 {
4937 ++arg; /* jump to after the '=' or ':' */
4938 for (p = arg; *p && !vim_iswhite(*p); ++p)
4939 if (*p == '\\' && p[1] != NUL)
4940 ++p;
4941 nextchar = *p;
4942 *p = NUL;
4943 add_termcode(key_name, arg, FALSE);
4944 *p = nextchar;
4945 }
4946 if (full_screen)
4947 ttest(FALSE);
4948 redraw_all_later(CLEAR);
4949 }
4950 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004951
Bram Moolenaar071d4272004-06-13 20:20:40 +00004952 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004953 did_set_option(opt_idx, opt_flags,
4954 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004955 }
4956
4957skip:
4958 /*
4959 * Advance to next argument.
4960 * - skip until a blank found, taking care of backslashes
4961 * - skip blanks
4962 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4963 */
4964 for (i = 0; i < 2 ; ++i)
4965 {
4966 while (*arg != NUL && !vim_iswhite(*arg))
4967 if (*arg++ == '\\' && *arg != NUL)
4968 ++arg;
4969 arg = skipwhite(arg);
4970 if (*arg != '=')
4971 break;
4972 }
4973 }
4974
4975 if (errmsg != NULL)
4976 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004977 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004978 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004979 if (i + (arg - startarg) < IOSIZE)
4980 {
4981 /* append the argument with the error */
4982 STRCAT(IObuff, ": ");
4983 mch_memmove(IObuff + i, startarg, (arg - startarg));
4984 IObuff[i + (arg - startarg)] = NUL;
4985 }
4986 /* make sure all characters are printable */
4987 trans_characters(IObuff, IOSIZE);
4988
4989 ++no_wait_return; /* wait_return done later */
4990 emsg(IObuff); /* show error highlighted */
4991 --no_wait_return;
4992
4993 return FAIL;
4994 }
4995
4996 arg = skipwhite(arg);
4997 }
4998
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004999theend:
5000 if (silent_mode && did_show)
5001 {
5002 /* After displaying option values in silent mode. */
5003 silent_mode = FALSE;
5004 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5005 msg_putchar('\n');
5006 cursor_on(); /* msg_start() switches it off */
5007 out_flush();
5008 silent_mode = TRUE;
5009 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5010 }
5011
Bram Moolenaar071d4272004-06-13 20:20:40 +00005012 return OK;
5013}
5014
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005015/*
5016 * Call this when an option has been given a new value through a user command.
5017 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5018 */
5019 static void
5020did_set_option(opt_idx, opt_flags, new_value)
5021 int opt_idx;
5022 int opt_flags; /* possibly with OPT_MODELINE */
5023 int new_value; /* value was replaced completely */
5024{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005025 long_u *p;
5026
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005027 options[opt_idx].flags |= P_WAS_SET;
5028
5029 /* When an option is set in the sandbox, from a modeline or in secure mode
5030 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005031 * flag. */
5032 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005033 if (secure
5034#ifdef HAVE_SANDBOX
5035 || sandbox != 0
5036#endif
5037 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005038 *p = *p | P_INSECURE;
5039 else if (new_value)
5040 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005041}
5042
Bram Moolenaar071d4272004-06-13 20:20:40 +00005043 static char_u *
5044illegal_char(errbuf, c)
5045 char_u *errbuf;
5046 int c;
5047{
5048 if (errbuf == NULL)
5049 return (char_u *)"";
5050 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005051 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005052 return errbuf;
5053}
5054
5055/*
5056 * Convert a key name or string into a key value.
5057 * Used for 'wildchar' and 'cedit' options.
5058 */
5059 static int
5060string_to_key(arg)
5061 char_u *arg;
5062{
5063 if (*arg == '<')
5064 return find_key_option(arg + 1);
5065 if (*arg == '^')
5066 return Ctrl_chr(arg[1]);
5067 return *arg;
5068}
5069
5070#ifdef FEAT_CMDWIN
5071/*
5072 * Check value of 'cedit' and set cedit_key.
5073 * Returns NULL if value is OK, error message otherwise.
5074 */
5075 static char_u *
5076check_cedit()
5077{
5078 int n;
5079
5080 if (*p_cedit == NUL)
5081 cedit_key = -1;
5082 else
5083 {
5084 n = string_to_key(p_cedit);
5085 if (vim_isprintc(n))
5086 return e_invarg;
5087 cedit_key = n;
5088 }
5089 return NULL;
5090}
5091#endif
5092
5093#ifdef FEAT_TITLE
5094/*
5095 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5096 * maketitle() to create and display it.
5097 * When switching the title or icon off, call mch_restore_title() to get
5098 * the old value back.
5099 */
5100 static void
5101did_set_title(icon)
5102 int icon; /* Did set icon instead of title */
5103{
5104 if (starting != NO_SCREEN
5105#ifdef FEAT_GUI
5106 && !gui.starting
5107#endif
5108 )
5109 {
5110 maketitle();
5111 if (icon)
5112 {
5113 if (!p_icon)
5114 mch_restore_title(2);
5115 }
5116 else
5117 {
5118 if (!p_title)
5119 mch_restore_title(1);
5120 }
5121 }
5122}
5123#endif
5124
5125/*
5126 * set_options_bin - called when 'bin' changes value.
5127 */
5128 void
5129set_options_bin(oldval, newval, opt_flags)
5130 int oldval;
5131 int newval;
5132 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5133{
5134 /*
5135 * The option values that are changed when 'bin' changes are
5136 * copied when 'bin is set and restored when 'bin' is reset.
5137 */
5138 if (newval)
5139 {
5140 if (!oldval) /* switched on */
5141 {
5142 if (!(opt_flags & OPT_GLOBAL))
5143 {
5144 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5145 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5146 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5147 curbuf->b_p_et_nobin = curbuf->b_p_et;
5148 }
5149 if (!(opt_flags & OPT_LOCAL))
5150 {
5151 p_tw_nobin = p_tw;
5152 p_wm_nobin = p_wm;
5153 p_ml_nobin = p_ml;
5154 p_et_nobin = p_et;
5155 }
5156 }
5157
5158 if (!(opt_flags & OPT_GLOBAL))
5159 {
5160 curbuf->b_p_tw = 0; /* no automatic line wrap */
5161 curbuf->b_p_wm = 0; /* no automatic line wrap */
5162 curbuf->b_p_ml = 0; /* no modelines */
5163 curbuf->b_p_et = 0; /* no expandtab */
5164 }
5165 if (!(opt_flags & OPT_LOCAL))
5166 {
5167 p_tw = 0;
5168 p_wm = 0;
5169 p_ml = FALSE;
5170 p_et = FALSE;
5171 p_bin = TRUE; /* needed when called for the "-b" argument */
5172 }
5173 }
5174 else if (oldval) /* switched off */
5175 {
5176 if (!(opt_flags & OPT_GLOBAL))
5177 {
5178 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5179 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5180 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5181 curbuf->b_p_et = curbuf->b_p_et_nobin;
5182 }
5183 if (!(opt_flags & OPT_LOCAL))
5184 {
5185 p_tw = p_tw_nobin;
5186 p_wm = p_wm_nobin;
5187 p_ml = p_ml_nobin;
5188 p_et = p_et_nobin;
5189 }
5190 }
5191}
5192
5193#ifdef FEAT_VIMINFO
5194/*
5195 * Find the parameter represented by the given character (eg ', :, ", or /),
5196 * and return its associated value in the 'viminfo' string.
5197 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005198 * If the parameter is not specified in the string or there is no following
5199 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005200 */
5201 int
5202get_viminfo_parameter(type)
5203 int type;
5204{
5205 char_u *p;
5206
5207 p = find_viminfo_parameter(type);
5208 if (p != NULL && VIM_ISDIGIT(*p))
5209 return atoi((char *)p);
5210 return -1;
5211}
5212
5213/*
5214 * Find the parameter represented by the given character (eg ''', ':', '"', or
5215 * '/') in the 'viminfo' option and return a pointer to the string after it.
5216 * Return NULL if the parameter is not specified in the string.
5217 */
5218 char_u *
5219find_viminfo_parameter(type)
5220 int type;
5221{
5222 char_u *p;
5223
5224 for (p = p_viminfo; *p; ++p)
5225 {
5226 if (*p == type)
5227 return p + 1;
5228 if (*p == 'n') /* 'n' is always the last one */
5229 break;
5230 p = vim_strchr(p, ','); /* skip until next ',' */
5231 if (p == NULL) /* hit the end without finding parameter */
5232 break;
5233 }
5234 return NULL;
5235}
5236#endif
5237
5238/*
5239 * Expand environment variables for some string options.
5240 * These string options cannot be indirect!
5241 * If "val" is NULL expand the current value of the option.
5242 * Return pointer to NameBuff, or NULL when not expanded.
5243 */
5244 static char_u *
5245option_expand(opt_idx, val)
5246 int opt_idx;
5247 char_u *val;
5248{
5249 /* if option doesn't need expansion nothing to do */
5250 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5251 return NULL;
5252
5253 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5254 * expand_env() would truncate the string. */
5255 if (val != NULL && STRLEN(val) > MAXPATHL)
5256 return NULL;
5257
5258 if (val == NULL)
5259 val = *(char_u **)options[opt_idx].var;
5260
5261 /*
5262 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5263 * Escape spaces when expanding 'tags', they are used to separate file
5264 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005265 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005266 */
5267 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005268 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005269#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005270 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5271#endif
5272 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5274 return NULL;
5275
5276 return NameBuff;
5277}
5278
5279/*
5280 * After setting various option values: recompute variables that depend on
5281 * option values.
5282 */
5283 static void
5284didset_options()
5285{
5286 /* initialize the table for 'iskeyword' et.al. */
5287 (void)init_chartab();
5288
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005289#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005291#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005292 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5293#ifdef FEAT_SESSION
5294 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5295 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5296#endif
5297#ifdef FEAT_FOLDING
5298 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5299#endif
5300 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5301#ifdef FEAT_VIRTUALEDIT
5302 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5303#endif
5304#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5305 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5306#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005307#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005308 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005309 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005310 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5313 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5314#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005315#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5317#endif
5318#ifdef FEAT_CMDWIN
5319 /* set cedit_key */
5320 (void)check_cedit();
5321#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005322#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005323 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005324#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325}
5326
5327/*
5328 * Check for string options that are NULL (normally only termcap options).
5329 */
5330 void
5331check_options()
5332{
5333 int opt_idx;
5334
5335 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5336 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5337 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5338}
5339
5340/*
5341 * Check string options in a buffer for NULL value.
5342 */
5343 void
5344check_buf_options(buf)
5345 buf_T *buf;
5346{
5347#if defined(FEAT_QUICKFIX)
5348 check_string_option(&buf->b_p_bh);
5349 check_string_option(&buf->b_p_bt);
5350#endif
5351#ifdef FEAT_MBYTE
5352 check_string_option(&buf->b_p_fenc);
5353#endif
5354 check_string_option(&buf->b_p_ff);
5355#ifdef FEAT_FIND_ID
5356 check_string_option(&buf->b_p_def);
5357 check_string_option(&buf->b_p_inc);
5358# ifdef FEAT_EVAL
5359 check_string_option(&buf->b_p_inex);
5360# endif
5361#endif
5362#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5363 check_string_option(&buf->b_p_inde);
5364 check_string_option(&buf->b_p_indk);
5365#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005366#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5367 check_string_option(&buf->b_p_bexpr);
5368#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005369#if defined(FEAT_CRYPT)
5370 check_string_option(&buf->b_p_cm);
5371#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005372#if defined(FEAT_EVAL)
5373 check_string_option(&buf->b_p_fex);
5374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375#ifdef FEAT_CRYPT
5376 check_string_option(&buf->b_p_key);
5377#endif
5378 check_string_option(&buf->b_p_kp);
5379 check_string_option(&buf->b_p_mps);
5380 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005381 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005382 check_string_option(&buf->b_p_isk);
5383#ifdef FEAT_COMMENTS
5384 check_string_option(&buf->b_p_com);
5385#endif
5386#ifdef FEAT_FOLDING
5387 check_string_option(&buf->b_p_cms);
5388#endif
5389 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005390#ifdef FEAT_TEXTOBJ
5391 check_string_option(&buf->b_p_qe);
5392#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005393#ifdef FEAT_SYN_HL
5394 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005395#endif
5396#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005397 check_string_option(&buf->b_s.b_p_spc);
5398 check_string_option(&buf->b_s.b_p_spf);
5399 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400#endif
5401#ifdef FEAT_SEARCHPATH
5402 check_string_option(&buf->b_p_sua);
5403#endif
5404#ifdef FEAT_CINDENT
5405 check_string_option(&buf->b_p_cink);
5406 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005407 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005408#endif
5409#ifdef FEAT_AUTOCMD
5410 check_string_option(&buf->b_p_ft);
5411#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005412#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5413 check_string_option(&buf->b_p_cinw);
5414#endif
5415#ifdef FEAT_INS_EXPAND
5416 check_string_option(&buf->b_p_cpt);
5417#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005418#ifdef FEAT_COMPL_FUNC
5419 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005420 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005421#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005422#ifdef FEAT_KEYMAP
5423 check_string_option(&buf->b_p_keymap);
5424#endif
5425#ifdef FEAT_QUICKFIX
5426 check_string_option(&buf->b_p_gp);
5427 check_string_option(&buf->b_p_mp);
5428 check_string_option(&buf->b_p_efm);
5429#endif
5430 check_string_option(&buf->b_p_ep);
5431 check_string_option(&buf->b_p_path);
5432 check_string_option(&buf->b_p_tags);
5433#ifdef FEAT_INS_EXPAND
5434 check_string_option(&buf->b_p_dict);
5435 check_string_option(&buf->b_p_tsr);
5436#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005437#ifdef FEAT_LISP
5438 check_string_option(&buf->b_p_lw);
5439#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005440 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005441}
5442
5443/*
5444 * Free the string allocated for an option.
5445 * Checks for the string being empty_option. This may happen if we're out of
5446 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5447 * check_options().
5448 * Does NOT check for P_ALLOCED flag!
5449 */
5450 void
5451free_string_option(p)
5452 char_u *p;
5453{
5454 if (p != empty_option)
5455 vim_free(p);
5456}
5457
5458 void
5459clear_string_option(pp)
5460 char_u **pp;
5461{
5462 if (*pp != empty_option)
5463 vim_free(*pp);
5464 *pp = empty_option;
5465}
5466
5467 static void
5468check_string_option(pp)
5469 char_u **pp;
5470{
5471 if (*pp == NULL)
5472 *pp = empty_option;
5473}
5474
5475/*
5476 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5477 */
5478 void
5479set_term_option_alloced(p)
5480 char_u **p;
5481{
5482 int opt_idx;
5483
5484 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5485 if (options[opt_idx].var == (char_u *)p)
5486 {
5487 options[opt_idx].flags |= P_ALLOCED;
5488 return;
5489 }
5490 return; /* cannot happen: didn't find it! */
5491}
5492
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005493#if defined(FEAT_EVAL) || defined(PROTO)
5494/*
5495 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5496 * Return FALSE when it wasn't.
5497 * Return -1 for an unknown option.
5498 */
5499 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005500was_set_insecurely(opt, opt_flags)
5501 char_u *opt;
5502 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005503{
5504 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005505 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005506
5507 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005508 {
5509 flagp = insecure_flag(idx, opt_flags);
5510 return (*flagp & P_INSECURE) != 0;
5511 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005512 EMSG2(_(e_intern2), "was_set_insecurely()");
5513 return -1;
5514}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005515
5516/*
5517 * Get a pointer to the flags used for the P_INSECURE flag of option
5518 * "opt_idx". For some local options a local flags field is used.
5519 */
5520 static long_u *
5521insecure_flag(opt_idx, opt_flags)
5522 int opt_idx;
5523 int opt_flags;
5524{
5525 if (opt_flags & OPT_LOCAL)
5526 switch ((int)options[opt_idx].indir)
5527 {
5528#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005529 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005530#endif
5531#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005532# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005533 case PV_FDE: return &curwin->w_p_fde_flags;
5534 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005535# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005536# ifdef FEAT_BEVAL
5537 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5538# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005539# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005540 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005541# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005542 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005543# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005544 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005545# endif
5546#endif
5547 }
5548
5549 /* Nothing special, return global flags field. */
5550 return &options[opt_idx].flags;
5551}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005552#endif
5553
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005554#ifdef FEAT_TITLE
5555static void redraw_titles __ARGS((void));
5556
5557/*
5558 * Redraw the window title and/or tab page text later.
5559 */
5560static void redraw_titles()
5561{
5562 need_maketitle = TRUE;
5563# ifdef FEAT_WINDOWS
5564 redraw_tabline = TRUE;
5565# endif
5566}
5567#endif
5568
Bram Moolenaar071d4272004-06-13 20:20:40 +00005569/*
5570 * Set a string option to a new value (without checking the effect).
5571 * The string is copied into allocated memory.
5572 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005573 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005574 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575 */
5576 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005577set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 char_u *name;
5579 int opt_idx;
5580 char_u *val;
5581 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005582 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583{
5584 char_u *s;
5585 char_u **varp;
5586 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005587 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588
Bram Moolenaar89d40322006-08-29 15:30:07 +00005589 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005591 idx = findoption(name);
5592 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005593 {
5594 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005595 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005596 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005597 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598 }
5599
Bram Moolenaar89d40322006-08-29 15:30:07 +00005600 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005601 return;
5602
5603 s = vim_strsave(val);
5604 if (s != NULL)
5605 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005606 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005607 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005608 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005609 free_string_option(*varp);
5610 *varp = s;
5611
5612 /* For buffer/window local option may also set the global value. */
5613 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005614 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615
Bram Moolenaar89d40322006-08-29 15:30:07 +00005616 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617
5618 /* When setting both values of a global option with a local value,
5619 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005620 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621 {
5622 free_string_option(*varp);
5623 *varp = empty_option;
5624 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005625# ifdef FEAT_EVAL
5626 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005627 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005628 set_sid == 0 ? current_SID : set_sid);
5629# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630 }
5631}
5632
5633/*
5634 * Set global value for string option when it's a local option.
5635 */
5636 static void
5637set_string_option_global(opt_idx, varp)
5638 int opt_idx; /* option index */
5639 char_u **varp; /* pointer to option variable */
5640{
5641 char_u **p, *s;
5642
5643 /* the global value is always allocated */
5644 if (options[opt_idx].var == VAR_WIN)
5645 p = (char_u **)GLOBAL_WO(varp);
5646 else
5647 p = (char_u **)options[opt_idx].var;
5648 if (options[opt_idx].indir != PV_NONE
5649 && p != varp
5650 && (s = vim_strsave(*varp)) != NULL)
5651 {
5652 free_string_option(*p);
5653 *p = s;
5654 }
5655}
5656
5657/*
5658 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005659 *
5660 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005662 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663set_string_option(opt_idx, value, opt_flags)
5664 int opt_idx;
5665 char_u *value;
5666 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5667{
5668 char_u *s;
5669 char_u **varp;
5670 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005671 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672
5673 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005674 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675
5676 s = vim_strsave(value);
5677 if (s != NULL)
5678 {
5679 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5680 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005681 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 ? OPT_GLOBAL : OPT_LOCAL)
5683 : opt_flags);
5684 oldval = *varp;
5685 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005686 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5687 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005688 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005690 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691}
5692
5693/*
5694 * Handle string options that need some action to perform when changed.
5695 * Returns NULL for success, or an error message for an error.
5696 */
5697 static char_u *
5698did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5699 opt_flags)
5700 int opt_idx; /* index in options[] table */
5701 char_u **varp; /* pointer to the option variable */
5702 int new_value_alloced; /* new value was allocated */
5703 char_u *oldval; /* previous value of the option */
5704 char_u *errbuf; /* buffer for errors, or NULL */
5705 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5706{
5707 char_u *errmsg = NULL;
5708 char_u *s, *p;
5709 int did_chartab = FALSE;
5710 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005711 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005712#ifdef FEAT_GUI
5713 /* set when changing an option that only requires a redraw in the GUI */
5714 int redraw_gui_only = FALSE;
5715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716
5717 /* Get the global option to compare with, otherwise we would have to check
5718 * two values for all local options. */
5719 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5720
5721 /* Disallow changing some options from secure mode */
5722 if ((secure
5723#ifdef HAVE_SANDBOX
5724 || sandbox != 0
5725#endif
5726 ) && (options[opt_idx].flags & P_SECURE))
5727 {
5728 errmsg = e_secure;
5729 }
5730
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005731 /* Check for a "normal" file name in some options. Disallow a path
5732 * separator (slash and/or backslash), wildcards and characters that are
5733 * often illegal in a file name. */
5734 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005735 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005736 {
5737 errmsg = e_invarg;
5738 }
5739
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740 /* 'term' */
5741 else if (varp == &T_NAME)
5742 {
5743 if (T_NAME[0] == NUL)
5744 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5745#ifdef FEAT_GUI
5746 if (gui.in_use)
5747 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5748 else if (term_is_gui(T_NAME))
5749 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5750#endif
5751 else if (set_termname(T_NAME) == FAIL)
5752 errmsg = (char_u *)N_("E522: Not found in termcap");
5753 else
5754 /* Screen colors may have changed. */
5755 redraw_later_clear();
5756 }
5757
5758 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005759 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005761 char_u *bkc = p_bkc;
5762 unsigned int *flags = &bkc_flags;
5763
5764 if (opt_flags & OPT_LOCAL)
5765 {
5766 bkc = curbuf->b_p_bkc;
5767 flags = &curbuf->b_bkc_flags;
5768 }
5769
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005770 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5771 /* make the local value empty: use the global value */
5772 *flags = 0;
5773 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005774 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005775 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5776 errmsg = e_invarg;
5777 if ((((int)*flags & BKC_AUTO) != 0)
5778 + (((int)*flags & BKC_YES) != 0)
5779 + (((int)*flags & BKC_NO) != 0) != 1)
5780 {
5781 /* Must have exactly one of "auto", "yes" and "no". */
5782 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5783 errmsg = e_invarg;
5784 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785 }
5786 }
5787
5788 /* 'backupext' and 'patchmode' */
5789 else if (varp == &p_bex || varp == &p_pm)
5790 {
5791 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5792 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5793 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5794 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005795#ifdef FEAT_LINEBREAK
5796 /* 'breakindentopt' */
5797 else if (varp == &curwin->w_p_briopt)
5798 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005799 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005800 errmsg = e_invarg;
5801 }
5802#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005803
5804 /*
5805 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5806 * If the new option is invalid, use old value. 'lisp' option: refill
5807 * chartab[] for '-' char
5808 */
5809 else if ( varp == &p_isi
5810 || varp == &(curbuf->b_p_isk)
5811 || varp == &p_isp
5812 || varp == &p_isf)
5813 {
5814 if (init_chartab() == FAIL)
5815 {
5816 did_chartab = TRUE; /* need to restore it below */
5817 errmsg = e_invarg; /* error in value */
5818 }
5819 }
5820
5821 /* 'helpfile' */
5822 else if (varp == &p_hf)
5823 {
5824 /* May compute new values for $VIM and $VIMRUNTIME */
5825 if (didset_vim)
5826 {
5827 vim_setenv((char_u *)"VIM", (char_u *)"");
5828 didset_vim = FALSE;
5829 }
5830 if (didset_vimruntime)
5831 {
5832 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5833 didset_vimruntime = FALSE;
5834 }
5835 }
5836
Bram Moolenaar1a384422010-07-14 19:53:30 +02005837#ifdef FEAT_SYN_HL
5838 /* 'colorcolumn' */
5839 else if (varp == &curwin->w_p_cc)
5840 errmsg = check_colorcolumn(curwin);
5841#endif
5842
Bram Moolenaar071d4272004-06-13 20:20:40 +00005843#ifdef FEAT_MULTI_LANG
5844 /* 'helplang' */
5845 else if (varp == &p_hlg)
5846 {
5847 /* Check for "", "ab", "ab,cd", etc. */
5848 for (s = p_hlg; *s != NUL; s += 3)
5849 {
5850 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5851 {
5852 errmsg = e_invarg;
5853 break;
5854 }
5855 if (s[2] == NUL)
5856 break;
5857 }
5858 }
5859#endif
5860
5861 /* 'highlight' */
5862 else if (varp == &p_hl)
5863 {
5864 if (highlight_changed() == FAIL)
5865 errmsg = e_invarg; /* invalid flags */
5866 }
5867
5868 /* 'nrformats' */
5869 else if (gvarp == &p_nf)
5870 {
5871 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5872 errmsg = e_invarg;
5873 }
5874
5875#ifdef FEAT_SESSION
5876 /* 'sessionoptions' */
5877 else if (varp == &p_ssop)
5878 {
5879 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5880 errmsg = e_invarg;
5881 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5882 {
5883 /* Don't allow both "sesdir" and "curdir". */
5884 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5885 errmsg = e_invarg;
5886 }
5887 }
5888 /* 'viewoptions' */
5889 else if (varp == &p_vop)
5890 {
5891 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5892 errmsg = e_invarg;
5893 }
5894#endif
5895
5896 /* 'scrollopt' */
5897#ifdef FEAT_SCROLLBIND
5898 else if (varp == &p_sbo)
5899 {
5900 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5901 errmsg = e_invarg;
5902 }
5903#endif
5904
5905 /* 'ambiwidth' */
5906#ifdef FEAT_MBYTE
5907 else if (varp == &p_ambw)
5908 {
5909 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5910 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005911 else if (set_chars_option(&p_lcs) != NULL)
5912 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5913# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5914 else if (set_chars_option(&p_fcs) != NULL)
5915 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5916# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917 }
5918#endif
5919
5920 /* 'background' */
5921 else if (varp == &p_bg)
5922 {
5923 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5924 {
5925#ifdef FEAT_EVAL
5926 int dark = (*p_bg == 'd');
5927#endif
5928
5929 init_highlight(FALSE, FALSE);
5930
5931#ifdef FEAT_EVAL
5932 if (dark != (*p_bg == 'd')
5933 && get_var_value((char_u *)"g:colors_name") != NULL)
5934 {
5935 /* The color scheme must have set 'background' back to another
5936 * value, that's not what we want here. Disable the color
5937 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005938 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939 free_string_option(p_bg);
5940 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5941 check_string_option(&p_bg);
5942 init_highlight(FALSE, FALSE);
5943 }
5944#endif
5945 }
5946 else
5947 errmsg = e_invarg;
5948 }
5949
5950 /* 'wildmode' */
5951 else if (varp == &p_wim)
5952 {
5953 if (check_opt_wim() == FAIL)
5954 errmsg = e_invarg;
5955 }
5956
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005957#ifdef FEAT_CMDL_COMPL
5958 /* 'wildoptions' */
5959 else if (varp == &p_wop)
5960 {
5961 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5962 errmsg = e_invarg;
5963 }
5964#endif
5965
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966#ifdef FEAT_WAK
5967 /* 'winaltkeys' */
5968 else if (varp == &p_wak)
5969 {
5970 if (*p_wak == NUL
5971 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5972 errmsg = e_invarg;
5973# ifdef FEAT_MENU
5974# ifdef FEAT_GUI_MOTIF
5975 else if (gui.in_use)
5976 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5977# else
5978# ifdef FEAT_GUI_GTK
5979 else if (gui.in_use)
5980 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5981# endif
5982# endif
5983# endif
5984 }
5985#endif
5986
5987#ifdef FEAT_AUTOCMD
5988 /* 'eventignore' */
5989 else if (varp == &p_ei)
5990 {
5991 if (check_ei() == FAIL)
5992 errmsg = e_invarg;
5993 }
5994#endif
5995
5996#ifdef FEAT_MBYTE
5997 /* 'encoding' and 'fileencoding' */
5998 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5999 {
6000 if (gvarp == &p_fenc)
6001 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006002 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006003 errmsg = e_modifiable;
6004 else if (vim_strchr(*varp, ',') != NULL)
6005 /* No comma allowed in 'fileencoding'; catches confusing it
6006 * with 'fileencodings'. */
6007 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006008 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006009 {
6010# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006012 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006013# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006014 /* Add 'fileencoding' to the swap file. */
6015 ml_setflags(curbuf);
6016 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006017 }
6018 if (errmsg == NULL)
6019 {
6020 /* canonize the value, so that STRCMP() can be used on it */
6021 p = enc_canonize(*varp);
6022 if (p != NULL)
6023 {
6024 vim_free(*varp);
6025 *varp = p;
6026 }
6027 if (varp == &p_enc)
6028 {
6029 errmsg = mb_init();
6030# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006031 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006032# endif
6033 }
6034 }
6035
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006036# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6038 {
6039 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6040 if (STRCMP(p_tenc, "utf-8") != 0)
6041 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6042 }
6043# endif
6044
6045 if (errmsg == NULL)
6046 {
6047# ifdef FEAT_KEYMAP
6048 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6049 * (with another encoding). */
6050 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6051 (void)keymap_init();
6052# endif
6053
6054 /* When 'termencoding' is not empty and 'encoding' changes or when
6055 * 'termencoding' changes, need to setup for keyboard input and
6056 * display output conversion. */
6057 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6058 {
6059 convert_setup(&input_conv, p_tenc, p_enc);
6060 convert_setup(&output_conv, p_enc, p_tenc);
6061 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006062
6063# if defined(WIN3264) && defined(FEAT_MBYTE)
6064 /* $HOME may have characters in active code page. */
6065 if (varp == &p_enc)
6066 init_homedir();
6067# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006068 }
6069 }
6070#endif
6071
6072#if defined(FEAT_POSTSCRIPT)
6073 else if (varp == &p_penc)
6074 {
6075 /* Canonize printencoding if VIM standard one */
6076 p = enc_canonize(p_penc);
6077 if (p != NULL)
6078 {
6079 vim_free(p_penc);
6080 p_penc = p;
6081 }
6082 else
6083 {
6084 /* Ensure lower case and '-' for '_' */
6085 for (s = p_penc; *s != NUL; s++)
6086 {
6087 if (*s == '_')
6088 *s = '-';
6089 else
6090 *s = TOLOWER_ASC(*s);
6091 }
6092 }
6093 }
6094#endif
6095
Bram Moolenaar9372a112005-12-06 19:59:18 +00006096#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097 else if (varp == &p_imak)
6098 {
6099 if (gui.in_use && !im_xim_isvalid_imactivate())
6100 errmsg = e_invarg;
6101 }
6102#endif
6103
6104#ifdef FEAT_KEYMAP
6105 else if (varp == &curbuf->b_p_keymap)
6106 {
6107 /* load or unload key mapping tables */
6108 errmsg = keymap_init();
6109
Bram Moolenaarfab06232009-03-04 03:13:35 +00006110 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006112 if (*curbuf->b_p_keymap != NUL)
6113 {
6114 /* Installed a new keymap, switch on using it. */
6115 curbuf->b_p_iminsert = B_IMODE_LMAP;
6116 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6117 curbuf->b_p_imsearch = B_IMODE_LMAP;
6118 }
6119 else
6120 {
6121 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6122 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6123 curbuf->b_p_iminsert = B_IMODE_NONE;
6124 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6125 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6126 }
6127 if ((opt_flags & OPT_LOCAL) == 0)
6128 {
6129 set_iminsert_global();
6130 set_imsearch_global();
6131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132# ifdef FEAT_WINDOWS
6133 status_redraw_curbuf();
6134# endif
6135 }
6136 }
6137#endif
6138
6139 /* 'fileformat' */
6140 else if (gvarp == &p_ff)
6141 {
6142 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6143 errmsg = e_modifiable;
6144 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6145 errmsg = e_invarg;
6146 else
6147 {
6148 /* may also change 'textmode' */
6149 if (get_fileformat(curbuf) == EOL_DOS)
6150 curbuf->b_p_tx = TRUE;
6151 else
6152 curbuf->b_p_tx = FALSE;
6153#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006154 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006155#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006156 /* update flag in swap file */
6157 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006158 /* Redraw needed when switching to/from "mac": a CR in the text
6159 * will be displayed differently. */
6160 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6161 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006162 }
6163 }
6164
6165 /* 'fileformats' */
6166 else if (varp == &p_ffs)
6167 {
6168 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6169 errmsg = e_invarg;
6170 else
6171 {
6172 /* also change 'textauto' */
6173 if (*p_ffs == NUL)
6174 p_ta = FALSE;
6175 else
6176 p_ta = TRUE;
6177 }
6178 }
6179
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006180#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006181 /* 'cryptkey' */
6182 else if (gvarp == &p_key)
6183 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006184# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185 /* Make sure the ":set" command doesn't show the new value in the
6186 * history. */
6187 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006188# endif
6189 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6190 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006191 ml_set_crypt_key(curbuf, oldval,
6192 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006193 }
6194
6195 else if (gvarp == &p_cm)
6196 {
6197 if (opt_flags & OPT_LOCAL)
6198 p = curbuf->b_p_cm;
6199 else
6200 p = p_cm;
6201 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6202 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006203 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006204 errmsg = e_invarg;
6205 else
6206 {
6207 /* When setting the global value to empty, make it "zip". */
6208 if (*p_cm == NUL)
6209 {
6210 if (new_value_alloced)
6211 free_string_option(p_cm);
6212 p_cm = vim_strsave((char_u *)"zip");
6213 new_value_alloced = TRUE;
6214 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006215 /* When using ":set cm=name" the local value is going to be empty.
6216 * Do that here, otherwise the crypt functions will still use the
6217 * local value. */
6218 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6219 {
6220 free_string_option(curbuf->b_p_cm);
6221 curbuf->b_p_cm = empty_option;
6222 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006223
6224 /* Need to update the swapfile when the effective method changed.
6225 * Set "s" to the effective old value, "p" to the effective new
6226 * method and compare. */
6227 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6228 s = p_cm; /* was previously using the global value */
6229 else
6230 s = oldval;
6231 if (*curbuf->b_p_cm == NUL)
6232 p = p_cm; /* is now using the global value */
6233 else
6234 p = curbuf->b_p_cm;
6235 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006236 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006237
6238 /* If the global value changes need to update the swapfile for all
6239 * buffers using that value. */
6240 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6241 {
6242 buf_T *buf;
6243
6244 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6245 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006246 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006247 }
6248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249 }
6250#endif
6251
6252 /* 'matchpairs' */
6253 else if (gvarp == &p_mps)
6254 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006255#ifdef FEAT_MBYTE
6256 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006257 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006258 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006259 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006260 int x2 = -1;
6261 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006262
6263 if (*p != NUL)
6264 p += mb_ptr2len(p);
6265 if (*p != NUL)
6266 x2 = *p++;
6267 if (*p != NUL)
6268 {
6269 x3 = mb_ptr2char(p);
6270 p += mb_ptr2len(p);
6271 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006272 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006273 {
6274 errmsg = e_invarg;
6275 break;
6276 }
6277 if (*p == NUL)
6278 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006279 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006280 }
6281 else
6282#endif
6283 {
6284 /* Check for "x:y,x:y" */
6285 for (p = *varp; *p != NUL; p += 4)
6286 {
6287 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6288 {
6289 errmsg = e_invarg;
6290 break;
6291 }
6292 if (p[3] == NUL)
6293 break;
6294 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006295 }
6296 }
6297
6298#ifdef FEAT_COMMENTS
6299 /* 'comments' */
6300 else if (gvarp == &p_com)
6301 {
6302 for (s = *varp; *s; )
6303 {
6304 while (*s && *s != ':')
6305 {
6306 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6307 && !VIM_ISDIGIT(*s) && *s != '-')
6308 {
6309 errmsg = illegal_char(errbuf, *s);
6310 break;
6311 }
6312 ++s;
6313 }
6314 if (*s++ == NUL)
6315 errmsg = (char_u *)N_("E524: Missing colon");
6316 else if (*s == ',' || *s == NUL)
6317 errmsg = (char_u *)N_("E525: Zero length string");
6318 if (errmsg != NULL)
6319 break;
6320 while (*s && *s != ',')
6321 {
6322 if (*s == '\\' && s[1] != NUL)
6323 ++s;
6324 ++s;
6325 }
6326 s = skip_to_option_part(s);
6327 }
6328 }
6329#endif
6330
6331 /* 'listchars' */
6332 else if (varp == &p_lcs)
6333 {
6334 errmsg = set_chars_option(varp);
6335 }
6336
6337#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6338 /* 'fillchars' */
6339 else if (varp == &p_fcs)
6340 {
6341 errmsg = set_chars_option(varp);
6342 }
6343#endif
6344
6345#ifdef FEAT_CMDWIN
6346 /* 'cedit' */
6347 else if (varp == &p_cedit)
6348 {
6349 errmsg = check_cedit();
6350 }
6351#endif
6352
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006353 /* 'verbosefile' */
6354 else if (varp == &p_vfile)
6355 {
6356 verbose_stop();
6357 if (*p_vfile != NUL && verbose_open() == FAIL)
6358 errmsg = e_invarg;
6359 }
6360
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361#ifdef FEAT_VIMINFO
6362 /* 'viminfo' */
6363 else if (varp == &p_viminfo)
6364 {
6365 for (s = p_viminfo; *s;)
6366 {
6367 /* Check it's a valid character */
6368 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6369 {
6370 errmsg = illegal_char(errbuf, *s);
6371 break;
6372 }
6373 if (*s == 'n') /* name is always last one */
6374 {
6375 break;
6376 }
6377 else if (*s == 'r') /* skip until next ',' */
6378 {
6379 while (*++s && *s != ',')
6380 ;
6381 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006382 else if (*s == '%')
6383 {
6384 /* optional number */
6385 while (vim_isdigit(*++s))
6386 ;
6387 }
6388 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006389 ++s; /* no extra chars */
6390 else /* must have a number */
6391 {
6392 while (vim_isdigit(*++s))
6393 ;
6394
6395 if (!VIM_ISDIGIT(*(s - 1)))
6396 {
6397 if (errbuf != NULL)
6398 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006399 sprintf((char *)errbuf,
6400 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 transchar_byte(*(s - 1)));
6402 errmsg = errbuf;
6403 }
6404 else
6405 errmsg = (char_u *)"";
6406 break;
6407 }
6408 }
6409 if (*s == ',')
6410 ++s;
6411 else if (*s)
6412 {
6413 if (errbuf != NULL)
6414 errmsg = (char_u *)N_("E527: Missing comma");
6415 else
6416 errmsg = (char_u *)"";
6417 break;
6418 }
6419 }
6420 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6421 errmsg = (char_u *)N_("E528: Must specify a ' value");
6422 }
6423#endif /* FEAT_VIMINFO */
6424
6425 /* terminal options */
6426 else if (istermoption(&options[opt_idx]) && full_screen)
6427 {
6428 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6429 if (varp == &T_CCO)
6430 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006431 int colors = atoi((char *)T_CCO);
6432
6433 /* Only reinitialize colors if t_Co value has really changed to
6434 * avoid expensive reload of colorscheme if t_Co is set to the
6435 * same value multiple times. */
6436 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006438 t_colors = colors;
6439 if (t_colors <= 1)
6440 {
6441 if (new_value_alloced)
6442 vim_free(T_CCO);
6443 T_CCO = empty_option;
6444 }
6445 /* We now have a different color setup, initialize it again. */
6446 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006447 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448 }
6449 ttest(FALSE);
6450 if (varp == &T_ME)
6451 {
6452 out_str(T_ME);
6453 redraw_later(CLEAR);
6454#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6455 /* Since t_me has been set, this probably means that the user
6456 * wants to use this as default colors. Need to reset default
6457 * background/foreground colors. */
6458 mch_set_normal_colors();
6459#endif
6460 }
6461 }
6462
6463#ifdef FEAT_LINEBREAK
6464 /* 'showbreak' */
6465 else if (varp == &p_sbr)
6466 {
6467 for (s = p_sbr; *s; )
6468 {
6469 if (ptr2cells(s) != 1)
6470 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006471 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472 }
6473 }
6474#endif
6475
6476#ifdef FEAT_GUI
6477 /* 'guifont' */
6478 else if (varp == &p_guifont)
6479 {
6480 if (gui.in_use)
6481 {
6482 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006483# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484 /*
6485 * Put up a font dialog and let the user select a new value.
6486 * If this is cancelled go back to the old value but don't
6487 * give an error message.
6488 */
6489 if (STRCMP(p, "*") == 0)
6490 {
6491 p = gui_mch_font_dialog(oldval);
6492
6493 if (new_value_alloced)
6494 free_string_option(p_guifont);
6495
6496 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6497 new_value_alloced = TRUE;
6498 }
6499# endif
6500 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6501 {
6502# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6503 if (STRCMP(p_guifont, "*") == 0)
6504 {
6505 /* Dialog was cancelled: Keep the old value without giving
6506 * an error message. */
6507 if (new_value_alloced)
6508 free_string_option(p_guifont);
6509 p_guifont = vim_strsave(oldval);
6510 new_value_alloced = TRUE;
6511 }
6512 else
6513# endif
6514 errmsg = (char_u *)N_("E596: Invalid font(s)");
6515 }
6516 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006517 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 }
6519# ifdef FEAT_XFONTSET
6520 else if (varp == &p_guifontset)
6521 {
6522 if (STRCMP(p_guifontset, "*") == 0)
6523 errmsg = (char_u *)N_("E597: can't select fontset");
6524 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6525 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006526 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006527 }
6528# endif
6529# ifdef FEAT_MBYTE
6530 else if (varp == &p_guifontwide)
6531 {
6532 if (STRCMP(p_guifontwide, "*") == 0)
6533 errmsg = (char_u *)N_("E533: can't select wide font");
6534 else if (gui_get_wide_font() == FAIL)
6535 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006536 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006537 }
6538# endif
6539#endif
6540
6541#ifdef CURSOR_SHAPE
6542 /* 'guicursor' */
6543 else if (varp == &p_guicursor)
6544 errmsg = parse_shape_opt(SHAPE_CURSOR);
6545#endif
6546
6547#ifdef FEAT_MOUSESHAPE
6548 /* 'mouseshape' */
6549 else if (varp == &p_mouseshape)
6550 {
6551 errmsg = parse_shape_opt(SHAPE_MOUSE);
6552 update_mouseshape(-1);
6553 }
6554#endif
6555
6556#ifdef FEAT_PRINTER
6557 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006558 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006559# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006560 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006561 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006562# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563#endif
6564
6565#ifdef FEAT_LANGMAP
6566 /* 'langmap' */
6567 else if (varp == &p_langmap)
6568 langmap_set();
6569#endif
6570
6571#ifdef FEAT_LINEBREAK
6572 /* 'breakat' */
6573 else if (varp == &p_breakat)
6574 fill_breakat_flags();
6575#endif
6576
6577#ifdef FEAT_TITLE
6578 /* 'titlestring' and 'iconstring' */
6579 else if (varp == &p_titlestring || varp == &p_iconstring)
6580 {
6581# ifdef FEAT_STL_OPT
6582 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6583
6584 /* NULL => statusline syntax */
6585 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6586 stl_syntax |= flagval;
6587 else
6588 stl_syntax &= ~flagval;
6589# endif
6590 did_set_title(varp == &p_iconstring);
6591
6592 }
6593#endif
6594
6595#ifdef FEAT_GUI
6596 /* 'guioptions' */
6597 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006598 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006599 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006600 redraw_gui_only = TRUE;
6601 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006602#endif
6603
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006604#if defined(FEAT_GUI_TABLINE)
6605 /* 'guitablabel' */
6606 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006607 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006608 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006609 redraw_gui_only = TRUE;
6610 }
6611 /* 'guitabtooltip' */
6612 else if (varp == &p_gtt)
6613 {
6614 redraw_gui_only = TRUE;
6615 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006616#endif
6617
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6619 /* 'ttymouse' */
6620 else if (varp == &p_ttym)
6621 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006622 /* Switch the mouse off before changing the escape sequences used for
6623 * that. */
6624 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006625 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6626 errmsg = e_invarg;
6627 else
6628 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006629 if (termcap_active)
6630 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 }
6632#endif
6633
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 /* 'selection' */
6635 else if (varp == &p_sel)
6636 {
6637 if (*p_sel == NUL
6638 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6639 errmsg = e_invarg;
6640 }
6641
6642 /* 'selectmode' */
6643 else if (varp == &p_slm)
6644 {
6645 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6646 errmsg = e_invarg;
6647 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006648
6649#ifdef FEAT_BROWSE
6650 /* 'browsedir' */
6651 else if (varp == &p_bsdir)
6652 {
6653 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6654 && !mch_isdir(p_bsdir))
6655 errmsg = e_invarg;
6656 }
6657#endif
6658
Bram Moolenaar071d4272004-06-13 20:20:40 +00006659 /* 'keymodel' */
6660 else if (varp == &p_km)
6661 {
6662 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6663 errmsg = e_invarg;
6664 else
6665 {
6666 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6667 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6668 }
6669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670
6671 /* 'mousemodel' */
6672 else if (varp == &p_mousem)
6673 {
6674 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6675 errmsg = e_invarg;
6676#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6677 else if (*p_mousem != *oldval)
6678 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6679 * to create or delete the popup menus. */
6680 gui_motif_update_mousemodel(root_menu);
6681#endif
6682 }
6683
6684 /* 'switchbuf' */
6685 else if (varp == &p_swb)
6686 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006687 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006688 errmsg = e_invarg;
6689 }
6690
6691 /* 'debug' */
6692 else if (varp == &p_debug)
6693 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006694 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006695 errmsg = e_invarg;
6696 }
6697
6698 /* 'display' */
6699 else if (varp == &p_dy)
6700 {
6701 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6702 errmsg = e_invarg;
6703 else
6704 (void)init_chartab();
6705
6706 }
6707
6708#ifdef FEAT_VERTSPLIT
6709 /* 'eadirection' */
6710 else if (varp == &p_ead)
6711 {
6712 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6713 errmsg = e_invarg;
6714 }
6715#endif
6716
6717#ifdef FEAT_CLIPBOARD
6718 /* 'clipboard' */
6719 else if (varp == &p_cb)
6720 errmsg = check_clipboard_option();
6721#endif
6722
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006723#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006724 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6725 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006726 else if (varp == &(curwin->w_s->b_p_spl)
6727 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006728 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006729 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006730 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006731
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006732 if (varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006733 {
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006734 l = (int)STRLEN(curwin->w_s->b_p_spf);
6735 if (l > 0 && (l < 4 || STRCMP(curwin->w_s->b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006736 ".add") != 0))
6737 errmsg = e_invarg;
6738 }
6739
6740 if (errmsg == NULL)
6741 {
6742 FOR_ALL_WINDOWS(wp)
6743 if (wp->w_buffer == curbuf && wp->w_p_spell)
6744 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006745 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006746# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006747 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006748# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006749 }
6750 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006751 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006752 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006753 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006754 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006755 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006756 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006757 /* 'spellsuggest' */
6758 else if (varp == &p_sps)
6759 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006760 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006761 errmsg = e_invarg;
6762 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006763 /* 'mkspellmem' */
6764 else if (varp == &p_msm)
6765 {
6766 if (spell_check_msm() != OK)
6767 errmsg = e_invarg;
6768 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006769#endif
6770
Bram Moolenaar071d4272004-06-13 20:20:40 +00006771#ifdef FEAT_QUICKFIX
6772 /* When 'bufhidden' is set, check for valid value. */
6773 else if (gvarp == &p_bh)
6774 {
6775 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6776 errmsg = e_invarg;
6777 }
6778
6779 /* When 'buftype' is set, check for valid value. */
6780 else if (gvarp == &p_bt)
6781 {
6782 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6783 errmsg = e_invarg;
6784 else
6785 {
6786# ifdef FEAT_WINDOWS
6787 if (curwin->w_status_height)
6788 {
6789 curwin->w_redr_status = TRUE;
6790 redraw_later(VALID);
6791 }
6792# endif
6793 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006794# ifdef FEAT_TITLE
6795 redraw_titles();
6796# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006797 }
6798 }
6799#endif
6800
6801#ifdef FEAT_STL_OPT
6802 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006803 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006804 {
6805 int wid;
6806
6807 if (varp == &p_ruf) /* reset ru_wid first */
6808 ru_wid = 0;
6809 s = *varp;
6810 if (varp == &p_ruf && *s == '%')
6811 {
6812 /* set ru_wid if 'ruf' starts with "%99(" */
6813 if (*++s == '-') /* ignore a '-' */
6814 s++;
6815 wid = getdigits(&s);
6816 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6817 ru_wid = wid;
6818 else
6819 errmsg = check_stl_option(p_ruf);
6820 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006821 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006822 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006824 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006825 comp_col();
6826 }
6827#endif
6828
6829#ifdef FEAT_INS_EXPAND
6830 /* check if it is a valid value for 'complete' -- Acevedo */
6831 else if (gvarp == &p_cpt)
6832 {
6833 for (s = *varp; *s;)
6834 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006835 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006836 s++;
6837 if (!*s)
6838 break;
6839 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6840 {
6841 errmsg = illegal_char(errbuf, *s);
6842 break;
6843 }
6844 if (*++s != NUL && *s != ',' && *s != ' ')
6845 {
6846 if (s[-1] == 'k' || s[-1] == 's')
6847 {
6848 /* skip optional filename after 'k' and 's' */
6849 while (*s && *s != ',' && *s != ' ')
6850 {
6851 if (*s == '\\')
6852 ++s;
6853 ++s;
6854 }
6855 }
6856 else
6857 {
6858 if (errbuf != NULL)
6859 {
6860 sprintf((char *)errbuf,
6861 _("E535: Illegal character after <%c>"),
6862 *--s);
6863 errmsg = errbuf;
6864 }
6865 else
6866 errmsg = (char_u *)"";
6867 break;
6868 }
6869 }
6870 }
6871 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006872
6873 /* 'completeopt' */
6874 else if (varp == &p_cot)
6875 {
6876 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6877 errmsg = e_invarg;
6878 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006879#endif /* FEAT_INS_EXPAND */
6880
6881
6882#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6883 else if (varp == &p_toolbar)
6884 {
6885 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6886 &toolbar_flags, TRUE) != OK)
6887 errmsg = e_invarg;
6888 else
6889 {
6890 out_flush();
6891 gui_mch_show_toolbar((toolbar_flags &
6892 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6893 }
6894 }
6895#endif
6896
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006897#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 /* 'toolbariconsize': GTK+ 2 only */
6899 else if (varp == &p_tbis)
6900 {
6901 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6902 errmsg = e_invarg;
6903 else
6904 {
6905 out_flush();
6906 gui_mch_show_toolbar((toolbar_flags &
6907 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6908 }
6909 }
6910#endif
6911
6912 /* 'pastetoggle': translate key codes like in a mapping */
6913 else if (varp == &p_pt)
6914 {
6915 if (*p_pt)
6916 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006917 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918 if (p != NULL)
6919 {
6920 if (new_value_alloced)
6921 free_string_option(p_pt);
6922 p_pt = p;
6923 new_value_alloced = TRUE;
6924 }
6925 }
6926 }
6927
6928 /* 'backspace' */
6929 else if (varp == &p_bs)
6930 {
6931 if (VIM_ISDIGIT(*p_bs))
6932 {
6933 if (*p_bs >'2' || p_bs[1] != NUL)
6934 errmsg = e_invarg;
6935 }
6936 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6937 errmsg = e_invarg;
6938 }
6939
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006940#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006941 /* 'casemap' */
6942 else if (varp == &p_cmp)
6943 {
6944 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6945 errmsg = e_invarg;
6946 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006947#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006948
6949#ifdef FEAT_DIFF
6950 /* 'diffopt' */
6951 else if (varp == &p_dip)
6952 {
6953 if (diffopt_changed() == FAIL)
6954 errmsg = e_invarg;
6955 }
6956#endif
6957
6958#ifdef FEAT_FOLDING
6959 /* 'foldmethod' */
6960 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6961 {
6962 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6963 || *curwin->w_p_fdm == NUL)
6964 errmsg = e_invarg;
6965 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006966 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006967 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006968 if (foldmethodIsDiff(curwin))
6969 newFoldLevel();
6970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006971 }
6972# ifdef FEAT_EVAL
6973 /* 'foldexpr' */
6974 else if (varp == &curwin->w_p_fde)
6975 {
6976 if (foldmethodIsExpr(curwin))
6977 foldUpdateAll(curwin);
6978 }
6979# endif
6980 /* 'foldmarker' */
6981 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6982 {
6983 p = vim_strchr(*varp, ',');
6984 if (p == NULL)
6985 errmsg = (char_u *)N_("E536: comma required");
6986 else if (p == *varp || p[1] == NUL)
6987 errmsg = e_invarg;
6988 else if (foldmethodIsMarker(curwin))
6989 foldUpdateAll(curwin);
6990 }
6991 /* 'commentstring' */
6992 else if (gvarp == &p_cms)
6993 {
6994 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6995 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6996 }
6997 /* 'foldopen' */
6998 else if (varp == &p_fdo)
6999 {
7000 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7001 errmsg = e_invarg;
7002 }
7003 /* 'foldclose' */
7004 else if (varp == &p_fcl)
7005 {
7006 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7007 errmsg = e_invarg;
7008 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007009 /* 'foldignore' */
7010 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7011 {
7012 if (foldmethodIsIndent(curwin))
7013 foldUpdateAll(curwin);
7014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015#endif
7016
7017#ifdef FEAT_VIRTUALEDIT
7018 /* 'virtualedit' */
7019 else if (varp == &p_ve)
7020 {
7021 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7022 errmsg = e_invarg;
7023 else if (STRCMP(p_ve, oldval) != 0)
7024 {
7025 /* Recompute cursor position in case the new 've' setting
7026 * changes something. */
7027 validate_virtcol();
7028 coladvance(curwin->w_virtcol);
7029 }
7030 }
7031#endif
7032
7033#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7034 else if (varp == &p_csqf)
7035 {
7036 if (p_csqf != NULL)
7037 {
7038 p = p_csqf;
7039 while (*p != NUL)
7040 {
7041 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7042 || p[1] == NUL
7043 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7044 || (p[2] != NUL && p[2] != ','))
7045 {
7046 errmsg = e_invarg;
7047 break;
7048 }
7049 else if (p[2] == NUL)
7050 break;
7051 else
7052 p += 3;
7053 }
7054 }
7055 }
7056#endif
7057
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007058#ifdef FEAT_CINDENT
7059 /* 'cinoptions' */
7060 else if (gvarp == &p_cino)
7061 {
7062 /* TODO: recognize errors */
7063 parse_cino(curbuf);
7064 }
7065#endif
7066
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007067#if defined(FEAT_RENDER_OPTIONS)
7068 else if (varp == &p_rop && gui.in_use)
7069 {
7070 if (!gui_mch_set_rendering_options(p_rop))
7071 errmsg = e_invarg;
7072 }
7073#endif
7074
Bram Moolenaar071d4272004-06-13 20:20:40 +00007075 /* Options that are a list of flags. */
7076 else
7077 {
7078 p = NULL;
7079 if (varp == &p_ww)
7080 p = (char_u *)WW_ALL;
7081 if (varp == &p_shm)
7082 p = (char_u *)SHM_ALL;
7083 else if (varp == &(p_cpo))
7084 p = (char_u *)CPO_ALL;
7085 else if (varp == &(curbuf->b_p_fo))
7086 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007087#ifdef FEAT_CONCEAL
7088 else if (varp == &curwin->w_p_cocu)
7089 p = (char_u *)COCU_ALL;
7090#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007091 else if (varp == &p_mouse)
7092 {
7093#ifdef FEAT_MOUSE
7094 p = (char_u *)MOUSE_ALL;
7095#else
7096 if (*p_mouse != NUL)
7097 errmsg = (char_u *)N_("E538: No mouse support");
7098#endif
7099 }
7100#if defined(FEAT_GUI)
7101 else if (varp == &p_go)
7102 p = (char_u *)GO_ALL;
7103#endif
7104 if (p != NULL)
7105 {
7106 for (s = *varp; *s; ++s)
7107 if (vim_strchr(p, *s) == NULL)
7108 {
7109 errmsg = illegal_char(errbuf, *s);
7110 break;
7111 }
7112 }
7113 }
7114
7115 /*
7116 * If error detected, restore the previous value.
7117 */
7118 if (errmsg != NULL)
7119 {
7120 if (new_value_alloced)
7121 free_string_option(*varp);
7122 *varp = oldval;
7123 /*
7124 * When resetting some values, need to act on it.
7125 */
7126 if (did_chartab)
7127 (void)init_chartab();
7128 if (varp == &p_hl)
7129 (void)highlight_changed();
7130 }
7131 else
7132 {
7133#ifdef FEAT_EVAL
7134 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007135 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007136#endif
7137 /*
7138 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007139 * Use "free_oldval", because recursiveness may change the flags under
7140 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007141 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007142 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143 free_string_option(oldval);
7144 if (new_value_alloced)
7145 options[opt_idx].flags |= P_ALLOCED;
7146 else
7147 options[opt_idx].flags &= ~P_ALLOCED;
7148
7149 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007150 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007151 {
7152 /* global option with local value set to use global value; free
7153 * the local value and make it empty */
7154 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7155 free_string_option(*(char_u **)p);
7156 *(char_u **)p = empty_option;
7157 }
7158
7159 /* May set global value for local option. */
7160 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7161 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007162
7163#ifdef FEAT_AUTOCMD
7164 /*
7165 * Trigger the autocommand only after setting the flags.
7166 */
7167# ifdef FEAT_SYN_HL
7168 /* When 'syntax' is set, load the syntax of that name */
7169 if (varp == &(curbuf->b_p_syn))
7170 {
7171 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7172 curbuf->b_fname, TRUE, curbuf);
7173 }
7174# endif
7175 else if (varp == &(curbuf->b_p_ft))
7176 {
7177 /* 'filetype' is set, trigger the FileType autocommand */
7178 did_filetype = TRUE;
7179 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7180 curbuf->b_fname, TRUE, curbuf);
7181 }
7182#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007183#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007184 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007185 {
7186 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007187 char_u *q = curwin->w_s->b_p_spl;
7188
7189 /* Skip the first name if it is "cjk". */
7190 if (STRNCMP(q, "cjk,", 4) == 0)
7191 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007192
7193 /*
7194 * Source the spell/LANG.vim in 'runtimepath'.
7195 * They could set 'spellcapcheck' depending on the language.
7196 * Use the first name in 'spelllang' up to '_region' or
7197 * '.encoding'.
7198 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007199 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007200 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7201 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007202 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007203 source_runtime(fname, TRUE);
7204 }
7205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206 }
7207
7208#ifdef FEAT_MOUSE
7209 if (varp == &p_mouse)
7210 {
7211# ifdef FEAT_MOUSE_TTY
7212 if (*p_mouse == NUL)
7213 mch_setmouse(FALSE); /* switch mouse off */
7214 else
7215# endif
7216 setmouse(); /* in case 'mouse' changed */
7217 }
7218#endif
7219
Bram Moolenaar913077c2012-03-28 19:59:04 +02007220 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007221 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007222 curwin->w_set_curswant = TRUE;
7223
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007224#ifdef FEAT_GUI
7225 /* check redraw when it's not a GUI option or the GUI is active. */
7226 if (!redraw_gui_only || gui.in_use)
7227#endif
7228 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007229
7230 return errmsg;
7231}
7232
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007233#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007234/*
7235 * Simple int comparison function for use with qsort()
7236 */
7237 static int
7238int_cmp(a, b)
7239 const void *a;
7240 const void *b;
7241{
7242 return *(const int *)a - *(const int *)b;
7243}
7244
7245/*
7246 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7247 * Returns error message, NULL if it's OK.
7248 */
7249 char_u *
7250check_colorcolumn(wp)
7251 win_T *wp;
7252{
7253 char_u *s;
7254 int col;
7255 int count = 0;
7256 int color_cols[256];
7257 int i;
7258 int j = 0;
7259
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007260 if (wp->w_buffer == NULL)
7261 return NULL; /* buffer was closed */
7262
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007263 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007264 {
7265 if (*s == '-' || *s == '+')
7266 {
7267 /* -N and +N: add to 'textwidth' */
7268 col = (*s == '-') ? -1 : 1;
7269 ++s;
7270 if (!VIM_ISDIGIT(*s))
7271 return e_invarg;
7272 col = col * getdigits(&s);
7273 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007274 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007275 col += wp->w_buffer->b_p_tw;
7276 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007277 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007278 }
7279 else if (VIM_ISDIGIT(*s))
7280 col = getdigits(&s);
7281 else
7282 return e_invarg;
7283 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007284skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007285 if (*s == NUL)
7286 break;
7287 if (*s != ',')
7288 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007289 if (*++s == NUL)
7290 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007291 }
7292
7293 vim_free(wp->w_p_cc_cols);
7294 if (count == 0)
7295 wp->w_p_cc_cols = NULL;
7296 else
7297 {
7298 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7299 if (wp->w_p_cc_cols != NULL)
7300 {
7301 /* sort the columns for faster usage on screen redraw inside
7302 * win_line() */
7303 qsort(color_cols, count, sizeof(int), int_cmp);
7304
7305 for (i = 0; i < count; ++i)
7306 /* skip duplicates */
7307 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7308 wp->w_p_cc_cols[j++] = color_cols[i];
7309 wp->w_p_cc_cols[j] = -1; /* end marker */
7310 }
7311 }
7312
7313 return NULL; /* no error */
7314}
7315#endif
7316
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317/*
7318 * Handle setting 'listchars' or 'fillchars'.
7319 * Returns error message, NULL if it's OK.
7320 */
7321 static char_u *
7322set_chars_option(varp)
7323 char_u **varp;
7324{
7325 int round, i, len, entries;
7326 char_u *p, *s;
7327 int c1, c2 = 0;
7328 struct charstab
7329 {
7330 int *cp;
7331 char *name;
7332 };
7333#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7334 static struct charstab filltab[] =
7335 {
7336 {&fill_stl, "stl"},
7337 {&fill_stlnc, "stlnc"},
7338 {&fill_vert, "vert"},
7339 {&fill_fold, "fold"},
7340 {&fill_diff, "diff"},
7341 };
7342#endif
7343 static struct charstab lcstab[] =
7344 {
7345 {&lcs_eol, "eol"},
7346 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007347 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007348 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007349 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 {&lcs_tab2, "tab"},
7351 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007352#ifdef FEAT_CONCEAL
7353 {&lcs_conceal, "conceal"},
7354#else
7355 {NULL, "conceal"},
7356#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357 };
7358 struct charstab *tab;
7359
7360#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7361 if (varp == &p_lcs)
7362#endif
7363 {
7364 tab = lcstab;
7365 entries = sizeof(lcstab) / sizeof(struct charstab);
7366 }
7367#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7368 else
7369 {
7370 tab = filltab;
7371 entries = sizeof(filltab) / sizeof(struct charstab);
7372 }
7373#endif
7374
7375 /* first round: check for valid value, second round: assign values */
7376 for (round = 0; round <= 1; ++round)
7377 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007378 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007379 {
7380 /* After checking that the value is valid: set defaults: space for
7381 * 'fillchars', NUL for 'listchars' */
7382 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007383 if (tab[i].cp != NULL)
7384 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385 if (varp == &p_lcs)
7386 lcs_tab1 = NUL;
7387#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7388 else
7389 fill_diff = '-';
7390#endif
7391 }
7392 p = *varp;
7393 while (*p)
7394 {
7395 for (i = 0; i < entries; ++i)
7396 {
7397 len = (int)STRLEN(tab[i].name);
7398 if (STRNCMP(p, tab[i].name, len) == 0
7399 && p[len] == ':'
7400 && p[len + 1] != NUL)
7401 {
7402 s = p + len + 1;
7403#ifdef FEAT_MBYTE
7404 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007405 if (mb_char2cells(c1) > 1)
7406 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007407#else
7408 c1 = *s++;
7409#endif
7410 if (tab[i].cp == &lcs_tab2)
7411 {
7412 if (*s == NUL)
7413 continue;
7414#ifdef FEAT_MBYTE
7415 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007416 if (mb_char2cells(c2) > 1)
7417 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007418#else
7419 c2 = *s++;
7420#endif
7421 }
7422 if (*s == ',' || *s == NUL)
7423 {
7424 if (round)
7425 {
7426 if (tab[i].cp == &lcs_tab2)
7427 {
7428 lcs_tab1 = c1;
7429 lcs_tab2 = c2;
7430 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007431 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007432 *(tab[i].cp) = c1;
7433
7434 }
7435 p = s;
7436 break;
7437 }
7438 }
7439 }
7440
7441 if (i == entries)
7442 return e_invarg;
7443 if (*p == ',')
7444 ++p;
7445 }
7446 }
7447
7448 return NULL; /* no error */
7449}
7450
7451#ifdef FEAT_STL_OPT
7452/*
7453 * Check validity of options with the 'statusline' format.
7454 * Return error message or NULL.
7455 */
7456 char_u *
7457check_stl_option(s)
7458 char_u *s;
7459{
7460 int itemcnt = 0;
7461 int groupdepth = 0;
7462 static char_u errbuf[80];
7463
7464 while (*s && itemcnt < STL_MAX_ITEM)
7465 {
7466 /* Check for valid keys after % sequences */
7467 while (*s && *s != '%')
7468 s++;
7469 if (!*s)
7470 break;
7471 s++;
7472 if (*s != '%' && *s != ')')
7473 ++itemcnt;
7474 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7475 {
7476 s++;
7477 continue;
7478 }
7479 if (*s == ')')
7480 {
7481 s++;
7482 if (--groupdepth < 0)
7483 break;
7484 continue;
7485 }
7486 if (*s == '-')
7487 s++;
7488 while (VIM_ISDIGIT(*s))
7489 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007490 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 continue;
7492 if (*s == '.')
7493 {
7494 s++;
7495 while (*s && VIM_ISDIGIT(*s))
7496 s++;
7497 }
7498 if (*s == '(')
7499 {
7500 groupdepth++;
7501 continue;
7502 }
7503 if (vim_strchr(STL_ALL, *s) == NULL)
7504 {
7505 return illegal_char(errbuf, *s);
7506 }
7507 if (*s == '{')
7508 {
7509 s++;
7510 while (*s != '}' && *s)
7511 s++;
7512 if (*s != '}')
7513 return (char_u *)N_("E540: Unclosed expression sequence");
7514 }
7515 }
7516 if (itemcnt >= STL_MAX_ITEM)
7517 return (char_u *)N_("E541: too many items");
7518 if (groupdepth != 0)
7519 return (char_u *)N_("E542: unbalanced groups");
7520 return NULL;
7521}
7522#endif
7523
7524#ifdef FEAT_CLIPBOARD
7525/*
7526 * Extract the items in the 'clipboard' option and set global values.
7527 */
7528 static char_u *
7529check_clipboard_option()
7530{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007531 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007532 int new_autoselect_star = FALSE;
7533 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007535 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007536 regprog_T *new_exclude_prog = NULL;
7537 char_u *errmsg = NULL;
7538 char_u *p;
7539
7540 for (p = p_cb; *p != NUL; )
7541 {
7542 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7543 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007544 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007545 p += 7;
7546 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007547 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007548 && (p[11] == ',' || p[11] == NUL))
7549 {
7550 new_unnamed |= CLIP_UNNAMED_PLUS;
7551 p += 11;
7552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007553 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007554 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007555 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007556 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557 p += 10;
7558 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007559 else if (STRNCMP(p, "autoselectplus", 14) == 0
7560 && (p[14] == ',' || p[14] == NUL))
7561 {
7562 new_autoselect_plus = TRUE;
7563 p += 14;
7564 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007565 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007566 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007567 {
7568 new_autoselectml = TRUE;
7569 p += 12;
7570 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007571 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7572 {
7573 new_html = TRUE;
7574 p += 4;
7575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007576 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7577 {
7578 p += 8;
7579 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7580 if (new_exclude_prog == NULL)
7581 errmsg = e_invarg;
7582 break;
7583 }
7584 else
7585 {
7586 errmsg = e_invarg;
7587 break;
7588 }
7589 if (*p == ',')
7590 ++p;
7591 }
7592 if (errmsg == NULL)
7593 {
7594 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007595 clip_autoselect_star = new_autoselect_star;
7596 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007598 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007599 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007600 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007601#ifdef FEAT_GUI_GTK
7602 if (gui.in_use)
7603 {
7604 gui_gtk_set_selection_targets();
7605 gui_gtk_set_dnd_targets();
7606 }
7607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007608 }
7609 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007610 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007611
7612 return errmsg;
7613}
7614#endif
7615
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007616#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007617/*
7618 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7619 * Return error message when failed, NULL when OK.
7620 */
7621 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007622compile_cap_prog(synblock)
7623 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007624{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007625 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007626 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007627
Bram Moolenaar860cae12010-06-05 23:22:07 +02007628 if (*synblock->b_p_spc == NUL)
7629 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007630 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007631 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007632 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007633 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007634 if (re != NULL)
7635 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007636 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007637 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007638 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007639 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007640 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007641 return e_invarg;
7642 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007643 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007644 }
7645
Bram Moolenaar473de612013-06-08 18:19:48 +02007646 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007647 return NULL;
7648}
7649#endif
7650
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007651#if defined(FEAT_EVAL) || defined(PROTO)
7652/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007653 * Set the scriptID for an option, taking care of setting the buffer- or
7654 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007655 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007656 static void
7657set_option_scriptID_idx(opt_idx, opt_flags, id)
7658 int opt_idx;
7659 int opt_flags;
7660 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007661{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007662 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7663 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007664
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007665 /* Remember where the option was set. For local options need to do that
7666 * in the buffer or window structure. */
7667 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007668 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007669 if (both || (opt_flags & OPT_LOCAL))
7670 {
7671 if (indir & PV_BUF)
7672 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7673 else if (indir & PV_WIN)
7674 curwin->w_p_scriptID[indir & PV_MASK] = id;
7675 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007676}
7677#endif
7678
Bram Moolenaar071d4272004-06-13 20:20:40 +00007679/*
7680 * Set the value of a boolean option, and take care of side effects.
7681 * Returns NULL for success, or an error message for an error.
7682 */
7683 static char_u *
7684set_bool_option(opt_idx, varp, value, opt_flags)
7685 int opt_idx; /* index in options[] table */
7686 char_u *varp; /* pointer to the option variable */
7687 int value; /* new value */
7688 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7689{
7690 int old_value = *(int *)varp;
7691
Bram Moolenaar071d4272004-06-13 20:20:40 +00007692 /* Disallow changing some options from secure mode */
7693 if ((secure
7694#ifdef HAVE_SANDBOX
7695 || sandbox != 0
7696#endif
7697 ) && (options[opt_idx].flags & P_SECURE))
7698 return e_secure;
7699
7700 *(int *)varp = value; /* set the new value */
7701#ifdef FEAT_EVAL
7702 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007703 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704#endif
7705
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007706#ifdef FEAT_GUI
7707 need_mouse_correct = TRUE;
7708#endif
7709
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 /* May set global value for local option. */
7711 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7712 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7713
7714 /*
7715 * Handle side effects of changing a bool option.
7716 */
7717
7718 /* 'compatible' */
7719 if ((int *)varp == &p_cp)
7720 {
7721 compatible_set();
7722 }
7723
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007724#ifdef FEAT_PERSISTENT_UNDO
7725 /* 'undofile' */
7726 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7727 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007728 /* Only take action when the option was set. When reset we do not
7729 * delete the undo file, the option may be set again without making
7730 * any changes in between. */
7731 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007732 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007733 char_u hash[UNDO_HASH_SIZE];
7734 buf_T *save_curbuf = curbuf;
7735
7736 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007737 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007738 /* When 'undofile' is set globally: for every buffer, otherwise
7739 * only for the current buffer: Try to read in the undofile,
7740 * if one exists, the buffer wasn't changed and the buffer was
7741 * loaded */
7742 if ((curbuf == save_curbuf
7743 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7744 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7745 {
7746 u_compute_hash(hash);
7747 u_read_undo(NULL, hash, curbuf->b_fname);
7748 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007749 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007750 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007751 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007752 }
7753#endif
7754
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 else if ((int *)varp == &curbuf->b_p_ro)
7756 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007757 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7759 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007760
7761 /* when 'readonly' is set may give W10 again */
7762 if (curbuf->b_p_ro)
7763 curbuf->b_did_warn = FALSE;
7764
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007766 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767#endif
7768 }
7769
Bram Moolenaar9c449722010-07-20 18:44:27 +02007770#ifdef FEAT_GUI
7771 else if ((int *)varp == &p_mh)
7772 {
7773 if (!p_mh)
7774 gui_mch_mousehide(FALSE);
7775 }
7776#endif
7777
Bram Moolenaara539df02010-08-01 14:35:05 +02007778#ifdef FEAT_TITLE
7779 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007780 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007781 {
7782 redraw_titles();
7783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784 /* when 'endofline' is changed, redraw the window title */
7785 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007786 {
7787 redraw_titles();
7788 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007789 /* when 'fixeol' is changed, redraw the window title */
7790 else if ((int *)varp == &curbuf->b_p_fixeol)
7791 {
7792 redraw_titles();
7793 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007794# ifdef FEAT_MBYTE
7795 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007796 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007797 {
7798 redraw_titles();
7799 }
7800# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801#endif
7802
7803 /* when 'bin' is set also set some other options */
7804 else if ((int *)varp == &curbuf->b_p_bin)
7805 {
7806 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7807#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007808 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007809#endif
7810 }
7811
7812#ifdef FEAT_AUTOCMD
7813 /* when 'buflisted' changes, trigger autocommands */
7814 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7815 {
7816 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7817 NULL, NULL, TRUE, curbuf);
7818 }
7819#endif
7820
7821 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7822 else if ((int *)varp == &curbuf->b_p_swf)
7823 {
7824 if (curbuf->b_p_swf && p_uc)
7825 ml_open_file(curbuf); /* create the swap file */
7826 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007827 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7828 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007829 mf_close_file(curbuf, TRUE); /* remove the swap file */
7830 }
7831
7832 /* when 'terse' is set change 'shortmess' */
7833 else if ((int *)varp == &p_terse)
7834 {
7835 char_u *p;
7836
7837 p = vim_strchr(p_shm, SHM_SEARCH);
7838
7839 /* insert 's' in p_shm */
7840 if (p_terse && p == NULL)
7841 {
7842 STRCPY(IObuff, p_shm);
7843 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007844 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007845 }
7846 /* remove 's' from p_shm */
7847 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007848 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 }
7850
7851 /* when 'paste' is set or reset also change other options */
7852 else if ((int *)varp == &p_paste)
7853 {
7854 paste_option_changed();
7855 }
7856
7857 /* when 'insertmode' is set from an autocommand need to do work here */
7858 else if ((int *)varp == &p_im)
7859 {
7860 if (p_im)
7861 {
7862 if ((State & INSERT) == 0)
7863 need_start_insertmode = TRUE;
7864 stop_insert_mode = FALSE;
7865 }
7866 else
7867 {
7868 need_start_insertmode = FALSE;
7869 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007870 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007871 clear_cmdline = TRUE; /* remove "(insert)" */
7872 restart_edit = 0;
7873 }
7874 }
7875
7876 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7877 else if ((int *)varp == &p_ic && p_hls)
7878 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007879 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007880 }
7881
7882#ifdef FEAT_SEARCH_EXTRA
7883 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7884 else if ((int *)varp == &p_hls)
7885 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007886 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007887 }
7888#endif
7889
7890#ifdef FEAT_SCROLLBIND
7891 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7892 * at the end of normal_cmd() */
7893 else if ((int *)varp == &curwin->w_p_scb)
7894 {
7895 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007896 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007897 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007898 curwin->w_scbind_pos = curwin->w_topline;
7899 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 }
7901#endif
7902
7903#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7904 /* There can be only one window with 'previewwindow' set. */
7905 else if ((int *)varp == &curwin->w_p_pvw)
7906 {
7907 if (curwin->w_p_pvw)
7908 {
7909 win_T *win;
7910
7911 for (win = firstwin; win != NULL; win = win->w_next)
7912 if (win->w_p_pvw && win != curwin)
7913 {
7914 curwin->w_p_pvw = FALSE;
7915 return (char_u *)N_("E590: A preview window already exists");
7916 }
7917 }
7918 }
7919#endif
7920
7921 /* when 'textmode' is set or reset also change 'fileformat' */
7922 else if ((int *)varp == &curbuf->b_p_tx)
7923 {
7924 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7925 }
7926
7927 /* when 'textauto' is set or reset also change 'fileformats' */
7928 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007929 set_string_option_direct((char_u *)"ffs", -1,
7930 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007931 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932
7933 /*
7934 * When 'lisp' option changes include/exclude '-' in
7935 * keyword characters.
7936 */
7937#ifdef FEAT_LISP
7938 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7939 {
7940 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7941 }
7942#endif
7943
7944#ifdef FEAT_TITLE
7945 /* when 'title' changed, may need to change the title; same for 'icon' */
7946 else if ((int *)varp == &p_title)
7947 {
7948 did_set_title(FALSE);
7949 }
7950
7951 else if ((int *)varp == &p_icon)
7952 {
7953 did_set_title(TRUE);
7954 }
7955#endif
7956
7957 else if ((int *)varp == &curbuf->b_changed)
7958 {
7959 if (!value)
7960 save_file_ff(curbuf); /* Buffer is unchanged */
7961#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007962 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963#endif
7964#ifdef FEAT_AUTOCMD
7965 modified_was_set = value;
7966#endif
7967 }
7968
7969#ifdef BACKSLASH_IN_FILENAME
7970 else if ((int *)varp == &p_ssl)
7971 {
7972 if (p_ssl)
7973 {
7974 psepc = '/';
7975 psepcN = '\\';
7976 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007977 }
7978 else
7979 {
7980 psepc = '\\';
7981 psepcN = '/';
7982 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 }
7984
7985 /* need to adjust the file name arguments and buffer names. */
7986 buflist_slash_adjust();
7987 alist_slash_adjust();
7988# ifdef FEAT_EVAL
7989 scriptnames_slash_adjust();
7990# endif
7991 }
7992#endif
7993
7994 /* If 'wrap' is set, set w_leftcol to zero. */
7995 else if ((int *)varp == &curwin->w_p_wrap)
7996 {
7997 if (curwin->w_p_wrap)
7998 curwin->w_leftcol = 0;
7999 }
8000
8001#ifdef FEAT_WINDOWS
8002 else if ((int *)varp == &p_ea)
8003 {
8004 if (p_ea && !old_value)
8005 win_equal(curwin, FALSE, 0);
8006 }
8007#endif
8008
8009 else if ((int *)varp == &p_wiv)
8010 {
8011 /*
8012 * When 'weirdinvert' changed, set/reset 't_xs'.
8013 * Then set 'weirdinvert' according to value of 't_xs'.
8014 */
8015 if (p_wiv && !old_value)
8016 T_XS = (char_u *)"y";
8017 else if (!p_wiv && old_value)
8018 T_XS = empty_option;
8019 p_wiv = (*T_XS != NUL);
8020 }
8021
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008022#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008023 else if ((int *)varp == &p_beval)
8024 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008025 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008027 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008028 gui_mch_disable_beval_area(balloonEval);
8029 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008031
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008032#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008033 else if ((int *)varp == &p_acd)
8034 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008035 /* Change directories when the 'acd' option is set now. */
8036 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 }
8038#endif
8039
8040#ifdef FEAT_DIFF
8041 /* 'diff' */
8042 else if ((int *)varp == &curwin->w_p_diff)
8043 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008044 /* May add or remove the buffer from the list of diff buffers. */
8045 diff_buf_adjust(curwin);
8046# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047 if (foldmethodIsDiff(curwin))
8048 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008049# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008050 }
8051#endif
8052
8053#ifdef USE_IM_CONTROL
8054 /* 'imdisable' */
8055 else if ((int *)varp == &p_imdisable)
8056 {
8057 /* Only de-activate it here, it will be enabled when changing mode. */
8058 if (p_imdisable)
8059 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008060 else if (State & INSERT)
8061 /* When the option is set from an autocommand, it may need to take
8062 * effect right away. */
8063 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064 }
8065#endif
8066
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008067#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008068 /* 'spell' */
8069 else if ((int *)varp == &curwin->w_p_spell)
8070 {
8071 if (curwin->w_p_spell)
8072 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008073 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008074 if (errmsg != NULL)
8075 EMSG(_(errmsg));
8076 }
8077 }
8078#endif
8079
Bram Moolenaar071d4272004-06-13 20:20:40 +00008080#ifdef FEAT_FKMAP
8081 else if ((int *)varp == &p_altkeymap)
8082 {
8083 if (old_value != p_altkeymap)
8084 {
8085 if (!p_altkeymap)
8086 {
8087 p_hkmap = p_fkmap;
8088 p_fkmap = 0;
8089 }
8090 else
8091 {
8092 p_fkmap = p_hkmap;
8093 p_hkmap = 0;
8094 }
8095 (void)init_chartab();
8096 }
8097 }
8098
8099 /*
8100 * In case some second language keymapping options have changed, check
8101 * and correct the setting in a consistent way.
8102 */
8103
8104 /*
8105 * If hkmap or fkmap are set, reset Arabic keymapping.
8106 */
8107 if ((p_hkmap || p_fkmap) && p_altkeymap)
8108 {
8109 p_altkeymap = p_fkmap;
8110# ifdef FEAT_ARABIC
8111 curwin->w_p_arab = FALSE;
8112# endif
8113 (void)init_chartab();
8114 }
8115
8116 /*
8117 * If hkmap set, reset Farsi keymapping.
8118 */
8119 if (p_hkmap && p_altkeymap)
8120 {
8121 p_altkeymap = 0;
8122 p_fkmap = 0;
8123# ifdef FEAT_ARABIC
8124 curwin->w_p_arab = FALSE;
8125# endif
8126 (void)init_chartab();
8127 }
8128
8129 /*
8130 * If fkmap set, reset Hebrew keymapping.
8131 */
8132 if (p_fkmap && !p_altkeymap)
8133 {
8134 p_altkeymap = 1;
8135 p_hkmap = 0;
8136# ifdef FEAT_ARABIC
8137 curwin->w_p_arab = FALSE;
8138# endif
8139 (void)init_chartab();
8140 }
8141#endif
8142
8143#ifdef FEAT_ARABIC
8144 if ((int *)varp == &curwin->w_p_arab)
8145 {
8146 if (curwin->w_p_arab)
8147 {
8148 /*
8149 * 'arabic' is set, handle various sub-settings.
8150 */
8151 if (!p_tbidi)
8152 {
8153 /* set rightleft mode */
8154 if (!curwin->w_p_rl)
8155 {
8156 curwin->w_p_rl = TRUE;
8157 changed_window_setting();
8158 }
8159
8160 /* Enable Arabic shaping (major part of what Arabic requires) */
8161 if (!p_arshape)
8162 {
8163 p_arshape = TRUE;
8164 redraw_later_clear();
8165 }
8166 }
8167
8168 /* Arabic requires a utf-8 encoding, inform the user if its not
8169 * set. */
8170 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008171 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008172 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8173
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008174 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008175 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8176#ifdef FEAT_EVAL
8177 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8178#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008180
8181# ifdef FEAT_MBYTE
8182 /* set 'delcombine' */
8183 p_deco = TRUE;
8184# endif
8185
8186# ifdef FEAT_KEYMAP
8187 /* Force-set the necessary keymap for arabic */
8188 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8189 OPT_LOCAL);
8190# endif
8191# ifdef FEAT_FKMAP
8192 p_altkeymap = 0;
8193 p_hkmap = 0;
8194 p_fkmap = 0;
8195 (void)init_chartab();
8196# endif
8197 }
8198 else
8199 {
8200 /*
8201 * 'arabic' is reset, handle various sub-settings.
8202 */
8203 if (!p_tbidi)
8204 {
8205 /* reset rightleft mode */
8206 if (curwin->w_p_rl)
8207 {
8208 curwin->w_p_rl = FALSE;
8209 changed_window_setting();
8210 }
8211
8212 /* 'arabicshape' isn't reset, it is a global option and
8213 * another window may still need it "on". */
8214 }
8215
8216 /* 'delcombine' isn't reset, it is a global option and another
8217 * window may still want it "on". */
8218
8219# ifdef FEAT_KEYMAP
8220 /* Revert to the default keymap */
8221 curbuf->b_p_iminsert = B_IMODE_NONE;
8222 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8223# endif
8224 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008225 }
8226
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008227#endif
8228
Bram Moolenaar071d4272004-06-13 20:20:40 +00008229 /*
8230 * End of handling side effects for bool options.
8231 */
8232
8233 options[opt_idx].flags |= P_WAS_SET;
8234
8235 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008236 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008237 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008238 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239 check_redraw(options[opt_idx].flags);
8240
8241 return NULL;
8242}
8243
8244/*
8245 * Set the value of a number option, and take care of side effects.
8246 * Returns NULL for success, or an error message for an error.
8247 */
8248 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008249set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008250 int opt_idx; /* index in options[] table */
8251 char_u *varp; /* pointer to the option variable */
8252 long value; /* new value */
8253 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008254 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8256 OPT_MODELINE */
8257{
8258 char_u *errmsg = NULL;
8259 long old_value = *(long *)varp;
8260 long old_Rows = Rows; /* remember old Rows */
8261 long old_Columns = Columns; /* remember old Columns */
8262 long *pp = (long *)varp;
8263
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008264 /* Disallow changing some options from secure mode. */
8265 if ((secure
8266#ifdef HAVE_SANDBOX
8267 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008269 ) && (options[opt_idx].flags & P_SECURE))
8270 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008271
8272 *pp = value;
8273#ifdef FEAT_EVAL
8274 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008275 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008276#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008277#ifdef FEAT_GUI
8278 need_mouse_correct = TRUE;
8279#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008280
Bram Moolenaar14f24742012-08-08 18:01:05 +02008281 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008282 {
8283 errmsg = e_positive;
8284 curbuf->b_p_sw = curbuf->b_p_ts;
8285 }
8286
8287 /*
8288 * Number options that need some action when changed
8289 */
8290#ifdef FEAT_WINDOWS
8291 if (pp == &p_wh || pp == &p_hh)
8292 {
8293 if (p_wh < 1)
8294 {
8295 errmsg = e_positive;
8296 p_wh = 1;
8297 }
8298 if (p_wmh > p_wh)
8299 {
8300 errmsg = e_winheight;
8301 p_wh = p_wmh;
8302 }
8303 if (p_hh < 0)
8304 {
8305 errmsg = e_positive;
8306 p_hh = 0;
8307 }
8308
8309 /* Change window height NOW */
8310 if (lastwin != firstwin)
8311 {
8312 if (pp == &p_wh && curwin->w_height < p_wh)
8313 win_setheight((int)p_wh);
8314 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8315 win_setheight((int)p_hh);
8316 }
8317 }
8318
8319 /* 'winminheight' */
8320 else if (pp == &p_wmh)
8321 {
8322 if (p_wmh < 0)
8323 {
8324 errmsg = e_positive;
8325 p_wmh = 0;
8326 }
8327 if (p_wmh > p_wh)
8328 {
8329 errmsg = e_winheight;
8330 p_wmh = p_wh;
8331 }
8332 win_setminheight();
8333 }
8334
8335# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008336 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337 {
8338 if (p_wiw < 1)
8339 {
8340 errmsg = e_positive;
8341 p_wiw = 1;
8342 }
8343 if (p_wmw > p_wiw)
8344 {
8345 errmsg = e_winwidth;
8346 p_wiw = p_wmw;
8347 }
8348
8349 /* Change window width NOW */
8350 if (lastwin != firstwin && curwin->w_width < p_wiw)
8351 win_setwidth((int)p_wiw);
8352 }
8353
8354 /* 'winminwidth' */
8355 else if (pp == &p_wmw)
8356 {
8357 if (p_wmw < 0)
8358 {
8359 errmsg = e_positive;
8360 p_wmw = 0;
8361 }
8362 if (p_wmw > p_wiw)
8363 {
8364 errmsg = e_winwidth;
8365 p_wmw = p_wiw;
8366 }
8367 win_setminheight();
8368 }
8369# endif
8370
8371#endif
8372
8373#ifdef FEAT_WINDOWS
8374 /* (re)set last window status line */
8375 else if (pp == &p_ls)
8376 {
8377 last_status(FALSE);
8378 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008379
8380 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008381 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008382 {
8383 shell_new_rows(); /* recompute window positions and heights */
8384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385#endif
8386
8387#ifdef FEAT_GUI
8388 else if (pp == &p_linespace)
8389 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008390 /* Recompute gui.char_height and resize the Vim window to keep the
8391 * same number of lines. */
8392 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008393 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394 }
8395#endif
8396
8397#ifdef FEAT_FOLDING
8398 /* 'foldlevel' */
8399 else if (pp == &curwin->w_p_fdl)
8400 {
8401 if (curwin->w_p_fdl < 0)
8402 curwin->w_p_fdl = 0;
8403 newFoldLevel();
8404 }
8405
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008406 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 else if (pp == &curwin->w_p_fml)
8408 {
8409 foldUpdateAll(curwin);
8410 }
8411
8412 /* 'foldnestmax' */
8413 else if (pp == &curwin->w_p_fdn)
8414 {
8415 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8416 foldUpdateAll(curwin);
8417 }
8418
8419 /* 'foldcolumn' */
8420 else if (pp == &curwin->w_p_fdc)
8421 {
8422 if (curwin->w_p_fdc < 0)
8423 {
8424 errmsg = e_positive;
8425 curwin->w_p_fdc = 0;
8426 }
8427 else if (curwin->w_p_fdc > 12)
8428 {
8429 errmsg = e_invarg;
8430 curwin->w_p_fdc = 12;
8431 }
8432 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008433#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008435#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 /* 'shiftwidth' or 'tabstop' */
8437 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8438 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008439# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 if (foldmethodIsIndent(curwin))
8441 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008442# endif
8443# ifdef FEAT_CINDENT
8444 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8445 * parse 'cinoptions'. */
8446 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8447 parse_cino(curbuf);
8448# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008452#ifdef FEAT_MBYTE
8453 /* 'maxcombine' */
8454 else if (pp == &p_mco)
8455 {
8456 if (p_mco > MAX_MCO)
8457 p_mco = MAX_MCO;
8458 else if (p_mco < 0)
8459 p_mco = 0;
8460 screenclear(); /* will re-allocate the screen */
8461 }
8462#endif
8463
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 else if (pp == &curbuf->b_p_iminsert)
8465 {
8466 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8467 {
8468 errmsg = e_invarg;
8469 curbuf->b_p_iminsert = B_IMODE_NONE;
8470 }
8471 p_iminsert = curbuf->b_p_iminsert;
8472 if (termcap_active) /* don't do this in the alternate screen */
8473 showmode();
8474#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8475 /* Show/unshow value of 'keymap' in status lines. */
8476 status_redraw_curbuf();
8477#endif
8478 }
8479
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008480 else if (pp == &p_window)
8481 {
8482 if (p_window < 1)
8483 p_window = 1;
8484 else if (p_window >= Rows)
8485 p_window = Rows - 1;
8486 }
8487
Bram Moolenaar071d4272004-06-13 20:20:40 +00008488 else if (pp == &curbuf->b_p_imsearch)
8489 {
8490 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8491 {
8492 errmsg = e_invarg;
8493 curbuf->b_p_imsearch = B_IMODE_NONE;
8494 }
8495 p_imsearch = curbuf->b_p_imsearch;
8496 }
8497
8498#ifdef FEAT_TITLE
8499 /* if 'titlelen' has changed, redraw the title */
8500 else if (pp == &p_titlelen)
8501 {
8502 if (p_titlelen < 0)
8503 {
8504 errmsg = e_positive;
8505 p_titlelen = 85;
8506 }
8507 if (starting != NO_SCREEN && old_value != p_titlelen)
8508 need_maketitle = TRUE;
8509 }
8510#endif
8511
8512 /* if p_ch changed value, change the command line height */
8513 else if (pp == &p_ch)
8514 {
8515 if (p_ch < 1)
8516 {
8517 errmsg = e_positive;
8518 p_ch = 1;
8519 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008520 if (p_ch > Rows - min_rows() + 1)
8521 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522
8523 /* Only compute the new window layout when startup has been
8524 * completed. Otherwise the frame sizes may be wrong. */
8525 if (p_ch != old_value && full_screen
8526#ifdef FEAT_GUI
8527 && !gui.starting
8528#endif
8529 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008530 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531 }
8532
8533 /* when 'updatecount' changes from zero to non-zero, open swap files */
8534 else if (pp == &p_uc)
8535 {
8536 if (p_uc < 0)
8537 {
8538 errmsg = e_positive;
8539 p_uc = 100;
8540 }
8541 if (p_uc && !old_value)
8542 ml_open_files();
8543 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008544#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008545 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008546 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008547 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008548 {
8549 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008550 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008551 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008552 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008553 {
8554 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008555 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008556 }
8557 }
8558#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008559#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008560 else if (pp == &p_mzq)
8561 mzvim_reset_timer();
8562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563
8564 /* sync undo before 'undolevels' changes */
8565 else if (pp == &p_ul)
8566 {
8567 /* use the old value, otherwise u_sync() may not work properly */
8568 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008569 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570 p_ul = value;
8571 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008572 else if (pp == &curbuf->b_p_ul)
8573 {
8574 /* use the old value, otherwise u_sync() may not work properly */
8575 curbuf->b_p_ul = old_value;
8576 u_sync(TRUE);
8577 curbuf->b_p_ul = value;
8578 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008579
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008580#ifdef FEAT_LINEBREAK
8581 /* 'numberwidth' must be positive */
8582 else if (pp == &curwin->w_p_nuw)
8583 {
8584 if (curwin->w_p_nuw < 1)
8585 {
8586 errmsg = e_positive;
8587 curwin->w_p_nuw = 1;
8588 }
8589 if (curwin->w_p_nuw > 10)
8590 {
8591 errmsg = e_invarg;
8592 curwin->w_p_nuw = 10;
8593 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008594 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008595 }
8596#endif
8597
Bram Moolenaar1a384422010-07-14 19:53:30 +02008598 else if (pp == &curbuf->b_p_tw)
8599 {
8600 if (curbuf->b_p_tw < 0)
8601 {
8602 errmsg = e_positive;
8603 curbuf->b_p_tw = 0;
8604 }
8605#ifdef FEAT_SYN_HL
8606# ifdef FEAT_WINDOWS
8607 {
8608 win_T *wp;
8609 tabpage_T *tp;
8610
8611 FOR_ALL_TAB_WINDOWS(tp, wp)
8612 check_colorcolumn(wp);
8613 }
8614# else
8615 check_colorcolumn(curwin);
8616# endif
8617#endif
8618 }
8619
Bram Moolenaar071d4272004-06-13 20:20:40 +00008620 /*
8621 * Check the bounds for numeric options here
8622 */
8623 if (Rows < min_rows() && full_screen)
8624 {
8625 if (errbuf != NULL)
8626 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008627 vim_snprintf((char *)errbuf, errbuflen,
8628 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629 errmsg = errbuf;
8630 }
8631 Rows = min_rows();
8632 }
8633 if (Columns < MIN_COLUMNS && full_screen)
8634 {
8635 if (errbuf != NULL)
8636 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008637 vim_snprintf((char *)errbuf, errbuflen,
8638 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 errmsg = errbuf;
8640 }
8641 Columns = MIN_COLUMNS;
8642 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008643 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008644
8645#ifdef DJGPP
8646 /* avoid a crash by checking for a too large value of 'columns' */
8647 if (old_Columns != Columns && full_screen && term_console)
8648 mch_check_columns();
8649#endif
8650
8651 /*
8652 * If the screen (shell) height has been changed, assume it is the
8653 * physical screenheight.
8654 */
8655 if (old_Rows != Rows || old_Columns != Columns)
8656 {
8657 /* Changing the screen size is not allowed while updating the screen. */
8658 if (updating_screen)
8659 *pp = old_value;
8660 else if (full_screen
8661#ifdef FEAT_GUI
8662 && !gui.starting
8663#endif
8664 )
8665 set_shellsize((int)Columns, (int)Rows, TRUE);
8666 else
8667 {
8668 /* Postpone the resizing; check the size and cmdline position for
8669 * messages. */
8670 check_shellsize();
8671 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8672 cmdline_row = Rows - p_ch;
8673 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008674 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008675 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676 }
8677
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678 if (curbuf->b_p_ts <= 0)
8679 {
8680 errmsg = e_positive;
8681 curbuf->b_p_ts = 8;
8682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008683 if (p_tm < 0)
8684 {
8685 errmsg = e_positive;
8686 p_tm = 0;
8687 }
8688 if ((curwin->w_p_scr <= 0
8689 || (curwin->w_p_scr > curwin->w_height
8690 && curwin->w_height > 0))
8691 && full_screen)
8692 {
8693 if (pp == &(curwin->w_p_scr))
8694 {
8695 if (curwin->w_p_scr != 0)
8696 errmsg = e_scroll;
8697 win_comp_scroll(curwin);
8698 }
8699 /* If 'scroll' became invalid because of a side effect silently adjust
8700 * it. */
8701 else if (curwin->w_p_scr <= 0)
8702 curwin->w_p_scr = 1;
8703 else /* curwin->w_p_scr > curwin->w_height */
8704 curwin->w_p_scr = curwin->w_height;
8705 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008706 if (p_hi < 0)
8707 {
8708 errmsg = e_positive;
8709 p_hi = 0;
8710 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008711 else if (p_hi > 10000)
8712 {
8713 errmsg = e_invarg;
8714 p_hi = 10000;
8715 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008716 if (p_re < 0 || p_re > 2)
8717 {
8718 errmsg = e_invarg;
8719 p_re = 0;
8720 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 if (p_report < 0)
8722 {
8723 errmsg = e_positive;
8724 p_report = 1;
8725 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008726 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008727 {
8728 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8729 p_sj = Rows / 2;
8730 else
8731 {
8732 errmsg = e_scroll;
8733 p_sj = 1;
8734 }
8735 }
8736 if (p_so < 0 && full_screen)
8737 {
8738 errmsg = e_scroll;
8739 p_so = 0;
8740 }
8741 if (p_siso < 0 && full_screen)
8742 {
8743 errmsg = e_positive;
8744 p_siso = 0;
8745 }
8746#ifdef FEAT_CMDWIN
8747 if (p_cwh < 1)
8748 {
8749 errmsg = e_positive;
8750 p_cwh = 1;
8751 }
8752#endif
8753 if (p_ut < 0)
8754 {
8755 errmsg = e_positive;
8756 p_ut = 2000;
8757 }
8758 if (p_ss < 0)
8759 {
8760 errmsg = e_positive;
8761 p_ss = 0;
8762 }
8763
8764 /* May set global value for local option. */
8765 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8766 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8767
8768 options[opt_idx].flags |= P_WAS_SET;
8769
8770 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008771 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008772 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008773 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008774 check_redraw(options[opt_idx].flags);
8775
8776 return errmsg;
8777}
8778
8779/*
8780 * Called after an option changed: check if something needs to be redrawn.
8781 */
8782 static void
8783check_redraw(flags)
8784 long_u flags;
8785{
8786 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008787 int doclear = (flags & P_RCLR) == P_RCLR;
8788 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789
8790#ifdef FEAT_WINDOWS
8791 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8792 status_redraw_all();
8793#endif
8794
8795 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8796 changed_window_setting();
8797 if (flags & P_RBUF)
8798 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008799 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 redraw_all_later(CLEAR);
8801 else if (all)
8802 redraw_all_later(NOT_VALID);
8803}
8804
8805/*
8806 * Find index for option 'arg'.
8807 * Return -1 if not found.
8808 */
8809 static int
8810findoption(arg)
8811 char_u *arg;
8812{
8813 int opt_idx;
8814 char *s, *p;
8815 static short quick_tab[27] = {0, 0}; /* quick access table */
8816 int is_term_opt;
8817
8818 /*
8819 * For first call: Initialize the quick-access table.
8820 * It contains the index for the first option that starts with a certain
8821 * letter. There are 26 letters, plus the first "t_" option.
8822 */
8823 if (quick_tab[1] == 0)
8824 {
8825 p = options[0].fullname;
8826 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8827 {
8828 if (s[0] != p[0])
8829 {
8830 if (s[0] == 't' && s[1] == '_')
8831 quick_tab[26] = opt_idx;
8832 else
8833 quick_tab[CharOrdLow(s[0])] = opt_idx;
8834 }
8835 p = s;
8836 }
8837 }
8838
8839 /*
8840 * Check for name starting with an illegal character.
8841 */
8842#ifdef EBCDIC
8843 if (!islower(arg[0]))
8844#else
8845 if (arg[0] < 'a' || arg[0] > 'z')
8846#endif
8847 return -1;
8848
8849 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8850 if (is_term_opt)
8851 opt_idx = quick_tab[26];
8852 else
8853 opt_idx = quick_tab[CharOrdLow(arg[0])];
8854 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8855 {
8856 if (STRCMP(arg, s) == 0) /* match full name */
8857 break;
8858 }
8859 if (s == NULL && !is_term_opt)
8860 {
8861 opt_idx = quick_tab[CharOrdLow(arg[0])];
8862 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8863 {
8864 s = options[opt_idx].shortname;
8865 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8866 break;
8867 s = NULL;
8868 }
8869 }
8870 if (s == NULL)
8871 opt_idx = -1;
8872 return opt_idx;
8873}
8874
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008875#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008876/*
8877 * Get the value for an option.
8878 *
8879 * Returns:
8880 * Number or Toggle option: 1, *numval gets value.
8881 * String option: 0, *stringval gets allocated string.
8882 * Hidden Number or Toggle option: -1.
8883 * hidden String option: -2.
8884 * unknown option: -3.
8885 */
8886 int
8887get_option_value(name, numval, stringval, opt_flags)
8888 char_u *name;
8889 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008890 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008891 int opt_flags;
8892{
8893 int opt_idx;
8894 char_u *varp;
8895
8896 opt_idx = findoption(name);
8897 if (opt_idx < 0) /* unknown option */
8898 return -3;
8899
8900 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8901
8902 if (options[opt_idx].flags & P_STRING)
8903 {
8904 if (varp == NULL) /* hidden option */
8905 return -2;
8906 if (stringval != NULL)
8907 {
8908#ifdef FEAT_CRYPT
8909 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008910 if ((char_u **)varp == &curbuf->b_p_key
8911 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008912 *stringval = vim_strsave((char_u *)"*****");
8913 else
8914#endif
8915 *stringval = vim_strsave(*(char_u **)(varp));
8916 }
8917 return 0;
8918 }
8919
8920 if (varp == NULL) /* hidden option */
8921 return -1;
8922 if (options[opt_idx].flags & P_NUM)
8923 *numval = *(long *)varp;
8924 else
8925 {
8926 /* Special case: 'modified' is b_changed, but we also want to consider
8927 * it set when 'ff' or 'fenc' changed. */
8928 if ((int *)varp == &curbuf->b_changed)
8929 *numval = curbufIsChanged();
8930 else
8931 *numval = *(int *)varp;
8932 }
8933 return 1;
8934}
8935#endif
8936
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008937#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008938/*
8939 * Returns the option attributes and its value. Unlike the above function it
8940 * will return either global value or local value of the option depending on
8941 * what was requested, but it will never return global value if it was
8942 * requested to return local one and vice versa. Neither it will return
8943 * buffer-local value if it was requested to return window-local one.
8944 *
8945 * Pretends that option is absent if it is not present in the requested scope
8946 * (i.e. has no global, window-local or buffer-local value depending on
8947 * opt_type). Uses
8948 *
8949 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008950 * 0 hidden or unknown option, also option that does not have requested
8951 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008952 * see SOPT_* in vim.h for other flags
8953 *
8954 * Possible opt_type values: see SREQ_* in vim.h
8955 */
8956 int
8957get_option_value_strict(name, numval, stringval, opt_type, from)
8958 char_u *name;
8959 long *numval;
8960 char_u **stringval; /* NULL when only obtaining attributes */
8961 int opt_type;
8962 void *from;
8963{
8964 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008965 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008966 struct vimoption *p;
8967 int r = 0;
8968
8969 opt_idx = findoption(name);
8970 if (opt_idx < 0)
8971 return 0;
8972
8973 p = &(options[opt_idx]);
8974
8975 /* Hidden option */
8976 if (p->var == NULL)
8977 return 0;
8978
8979 if (p->flags & P_BOOL)
8980 r |= SOPT_BOOL;
8981 else if (p->flags & P_NUM)
8982 r |= SOPT_NUM;
8983 else if (p->flags & P_STRING)
8984 r |= SOPT_STRING;
8985
8986 if (p->indir == PV_NONE)
8987 {
8988 if (opt_type == SREQ_GLOBAL)
8989 r |= SOPT_GLOBAL;
8990 else
8991 return 0; /* Did not request global-only option */
8992 }
8993 else
8994 {
8995 if (p->indir & PV_BOTH)
8996 r |= SOPT_GLOBAL;
8997 else if (opt_type == SREQ_GLOBAL)
8998 return 0; /* Requested global option */
8999
9000 if (p->indir & PV_WIN)
9001 {
9002 if (opt_type == SREQ_BUF)
9003 return 0; /* Did not request window-local option */
9004 else
9005 r |= SOPT_WIN;
9006 }
9007 else if (p->indir & PV_BUF)
9008 {
9009 if (opt_type == SREQ_WIN)
9010 return 0; /* Did not request buffer-local option */
9011 else
9012 r |= SOPT_BUF;
9013 }
9014 }
9015
9016 if (stringval == NULL)
9017 return r;
9018
9019 if (opt_type == SREQ_GLOBAL)
9020 varp = p->var;
9021 else
9022 {
9023 if (opt_type == SREQ_BUF)
9024 {
9025 /* Special case: 'modified' is b_changed, but we also want to
9026 * consider it set when 'ff' or 'fenc' changed. */
9027 if (p->indir == PV_MOD)
9028 {
9029 *numval = bufIsChanged((buf_T *) from);
9030 varp = NULL;
9031 }
9032#ifdef FEAT_CRYPT
9033 else if (p->indir == PV_KEY)
9034 {
9035 /* never return the value of the crypt key */
9036 *stringval = NULL;
9037 varp = NULL;
9038 }
9039#endif
9040 else
9041 {
9042 aco_save_T aco;
9043 aucmd_prepbuf(&aco, (buf_T *) from);
9044 varp = get_varp(p);
9045 aucmd_restbuf(&aco);
9046 }
9047 }
9048 else if (opt_type == SREQ_WIN)
9049 {
9050 win_T *save_curwin;
9051 save_curwin = curwin;
9052 curwin = (win_T *) from;
9053 curbuf = curwin->w_buffer;
9054 varp = get_varp(p);
9055 curwin = save_curwin;
9056 curbuf = curwin->w_buffer;
9057 }
9058 if (varp == p->var)
9059 return (r | SOPT_UNSET);
9060 }
9061
9062 if (varp != NULL)
9063 {
9064 if (p->flags & P_STRING)
9065 *stringval = vim_strsave(*(char_u **)(varp));
9066 else if (p->flags & P_NUM)
9067 *numval = *(long *) varp;
9068 else
9069 *numval = *(int *)varp;
9070 }
9071
9072 return r;
9073}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009074
9075/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009076 * Iterate over options. First argument is a pointer to a pointer to a
9077 * structure inside options[] array, second is option type like in the above
9078 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009079 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009080 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009081 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009082 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009083 * first argument to NULL.
9084 *
9085 * Returns full option name for current option on each call.
9086 */
9087 char_u *
9088option_iter_next(option, opt_type)
9089 void **option;
9090 int opt_type;
9091{
9092 struct vimoption *ret = NULL;
9093 do
9094 {
9095 if (*option == NULL)
9096 *option = (void *) options;
9097 else if (((struct vimoption *) (*option))->fullname == NULL)
9098 {
9099 *option = NULL;
9100 return NULL;
9101 }
9102 else
9103 *option = (void *) (((struct vimoption *) (*option)) + 1);
9104
9105 ret = ((struct vimoption *) (*option));
9106
9107 /* Hidden option */
9108 if (ret->var == NULL)
9109 {
9110 ret = NULL;
9111 continue;
9112 }
9113
9114 switch (opt_type)
9115 {
9116 case SREQ_GLOBAL:
9117 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9118 ret = NULL;
9119 break;
9120 case SREQ_BUF:
9121 if (!(ret->indir & PV_BUF))
9122 ret = NULL;
9123 break;
9124 case SREQ_WIN:
9125 if (!(ret->indir & PV_WIN))
9126 ret = NULL;
9127 break;
9128 default:
9129 EMSG2(_(e_intern2), "option_iter_next()");
9130 return NULL;
9131 }
9132 }
9133 while (ret == NULL);
9134
9135 return (char_u *)ret->fullname;
9136}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009137#endif
9138
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139/*
9140 * Set the value of option "name".
9141 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009142 *
9143 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009144 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009145 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009146set_option_value(name, number, string, opt_flags)
9147 char_u *name;
9148 long number;
9149 char_u *string;
9150 int opt_flags; /* OPT_LOCAL or 0 (both) */
9151{
9152 int opt_idx;
9153 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009154 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155
9156 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009157 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009158 EMSG2(_("E355: Unknown option: %s"), name);
9159 else
9160 {
9161 flags = options[opt_idx].flags;
9162#ifdef HAVE_SANDBOX
9163 /* Disallow changing some options in the sandbox */
9164 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009165 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009166 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009167 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009168 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009170 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009171 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172 else
9173 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009174 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009175 if (varp != NULL) /* hidden option is not changed */
9176 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009177 if (number == 0 && string != NULL)
9178 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009179 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009180
9181 /* Either we are given a string or we are setting option
9182 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009183 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009184 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009185 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009186 {
9187 /* There's another character after zeros or the string
9188 * is empty. In both cases, we are trying to set a
9189 * num option using a string. */
9190 EMSG3(_("E521: Number required: &%s = '%s'"),
9191 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009192 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009193
9194 }
9195 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009196 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009197 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009198 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009199 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009200 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009201 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009202 }
9203 }
9204 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009205 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206}
9207
9208/*
9209 * Get the terminal code for a terminal option.
9210 * Returns NULL when not found.
9211 */
9212 char_u *
9213get_term_code(tname)
9214 char_u *tname;
9215{
9216 int opt_idx;
9217 char_u *varp;
9218
9219 if (tname[0] != 't' || tname[1] != '_' ||
9220 tname[2] == NUL || tname[3] == NUL)
9221 return NULL;
9222 if ((opt_idx = findoption(tname)) >= 0)
9223 {
9224 varp = get_varp(&(options[opt_idx]));
9225 if (varp != NULL)
9226 varp = *(char_u **)(varp);
9227 return varp;
9228 }
9229 return find_termcode(tname + 2);
9230}
9231
9232 char_u *
9233get_highlight_default()
9234{
9235 int i;
9236
9237 i = findoption((char_u *)"hl");
9238 if (i >= 0)
9239 return options[i].def_val[VI_DEFAULT];
9240 return (char_u *)NULL;
9241}
9242
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009243#if defined(FEAT_MBYTE) || defined(PROTO)
9244 char_u *
9245get_encoding_default()
9246{
9247 int i;
9248
9249 i = findoption((char_u *)"enc");
9250 if (i >= 0)
9251 return options[i].def_val[VI_DEFAULT];
9252 return (char_u *)NULL;
9253}
9254#endif
9255
Bram Moolenaar071d4272004-06-13 20:20:40 +00009256/*
9257 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9258 */
9259 static int
9260find_key_option(arg)
9261 char_u *arg;
9262{
9263 int key;
9264 int modifiers;
9265
9266 /*
9267 * Don't use get_special_key_code() for t_xx, we don't want it to call
9268 * add_termcap_entry().
9269 */
9270 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9271 key = TERMCAP2KEY(arg[2], arg[3]);
9272 else
9273 {
9274 --arg; /* put arg at the '<' */
9275 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009276 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009277 if (modifiers) /* can't handle modifiers here */
9278 key = 0;
9279 }
9280 return key;
9281}
9282
9283/*
9284 * if 'all' == 0: show changed options
9285 * if 'all' == 1: show all normal options
9286 * if 'all' == 2: show all terminal options
9287 */
9288 static void
9289showoptions(all, opt_flags)
9290 int all;
9291 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9292{
9293 struct vimoption *p;
9294 int col;
9295 int isterm;
9296 char_u *varp;
9297 struct vimoption **items;
9298 int item_count;
9299 int run;
9300 int row, rows;
9301 int cols;
9302 int i;
9303 int len;
9304
9305#define INC 20
9306#define GAP 3
9307
9308 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9309 PARAM_COUNT));
9310 if (items == NULL)
9311 return;
9312
9313 /* Highlight title */
9314 if (all == 2)
9315 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9316 else if (opt_flags & OPT_GLOBAL)
9317 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9318 else if (opt_flags & OPT_LOCAL)
9319 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9320 else
9321 MSG_PUTS_TITLE(_("\n--- Options ---"));
9322
9323 /*
9324 * do the loop two times:
9325 * 1. display the short items
9326 * 2. display the long items (only strings and numbers)
9327 */
9328 for (run = 1; run <= 2 && !got_int; ++run)
9329 {
9330 /*
9331 * collect the items in items[]
9332 */
9333 item_count = 0;
9334 for (p = &options[0]; p->fullname != NULL; p++)
9335 {
9336 varp = NULL;
9337 isterm = istermoption(p);
9338 if (opt_flags != 0)
9339 {
9340 if (p->indir != PV_NONE && !isterm)
9341 varp = get_varp_scope(p, opt_flags);
9342 }
9343 else
9344 varp = get_varp(p);
9345 if (varp != NULL
9346 && ((all == 2 && isterm)
9347 || (all == 1 && !isterm)
9348 || (all == 0 && !optval_default(p, varp))))
9349 {
9350 if (p->flags & P_BOOL)
9351 len = 1; /* a toggle option fits always */
9352 else
9353 {
9354 option_value2string(p, opt_flags);
9355 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9356 }
9357 if ((len <= INC - GAP && run == 1) ||
9358 (len > INC - GAP && run == 2))
9359 items[item_count++] = p;
9360 }
9361 }
9362
9363 /*
9364 * display the items
9365 */
9366 if (run == 1)
9367 {
9368 cols = (Columns + GAP - 3) / INC;
9369 if (cols == 0)
9370 cols = 1;
9371 rows = (item_count + cols - 1) / cols;
9372 }
9373 else /* run == 2 */
9374 rows = item_count;
9375 for (row = 0; row < rows && !got_int; ++row)
9376 {
9377 msg_putchar('\n'); /* go to next line */
9378 if (got_int) /* 'q' typed in more */
9379 break;
9380 col = 0;
9381 for (i = row; i < item_count; i += rows)
9382 {
9383 msg_col = col; /* make columns */
9384 showoneopt(items[i], opt_flags);
9385 col += INC;
9386 }
9387 out_flush();
9388 ui_breakcheck();
9389 }
9390 }
9391 vim_free(items);
9392}
9393
9394/*
9395 * Return TRUE if option "p" has its default value.
9396 */
9397 static int
9398optval_default(p, varp)
9399 struct vimoption *p;
9400 char_u *varp;
9401{
9402 int dvi;
9403
9404 if (varp == NULL)
9405 return TRUE; /* hidden option is always at default */
9406 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9407 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009408 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009410 /* the cast to long is required for Manx C, long_i is
9411 * needed for MSVC */
9412 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413 /* P_STRING */
9414 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9415}
9416
9417/*
9418 * showoneopt: show the value of one option
9419 * must not be called with a hidden option!
9420 */
9421 static void
9422showoneopt(p, opt_flags)
9423 struct vimoption *p;
9424 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9425{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009426 char_u *varp;
9427 int save_silent = silent_mode;
9428
9429 silent_mode = FALSE;
9430 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009431
9432 varp = get_varp_scope(p, opt_flags);
9433
9434 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9435 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9436 ? !curbufIsChanged() : !*(int *)varp))
9437 MSG_PUTS("no");
9438 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9439 MSG_PUTS("--");
9440 else
9441 MSG_PUTS(" ");
9442 MSG_PUTS(p->fullname);
9443 if (!(p->flags & P_BOOL))
9444 {
9445 msg_putchar('=');
9446 /* put value string in NameBuff */
9447 option_value2string(p, opt_flags);
9448 msg_outtrans(NameBuff);
9449 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009450
9451 silent_mode = save_silent;
9452 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009453}
9454
9455/*
9456 * Write modified options as ":set" commands to a file.
9457 *
9458 * There are three values for "opt_flags":
9459 * OPT_GLOBAL: Write global option values and fresh values of
9460 * buffer-local options (used for start of a session
9461 * file).
9462 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9463 * curwin (used for a vimrc file).
9464 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9465 * and local values for window-local options of
9466 * curwin. Local values are also written when at the
9467 * default value, because a modeline or autocommand
9468 * may have set them when doing ":edit file" and the
9469 * user has set them back at the default or fresh
9470 * value.
9471 * When "local_only" is TRUE, don't write fresh
9472 * values, only local values (for ":mkview").
9473 * (fresh value = value used for a new buffer or window for a local option).
9474 *
9475 * Return FAIL on error, OK otherwise.
9476 */
9477 int
9478makeset(fd, opt_flags, local_only)
9479 FILE *fd;
9480 int opt_flags;
9481 int local_only;
9482{
9483 struct vimoption *p;
9484 char_u *varp; /* currently used value */
9485 char_u *varp_fresh; /* local value */
9486 char_u *varp_local = NULL; /* fresh value */
9487 char *cmd;
9488 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009489 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009490
9491 /*
9492 * The options that don't have a default (terminal name, columns, lines)
9493 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009494 * Do the loop over "options[]" twice: once for options with the
9495 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009496 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009497 for (pri = 1; pri >= 0; --pri)
9498 {
9499 for (p = &options[0]; !istermoption(p); p++)
9500 if (!(p->flags & P_NO_MKRC)
9501 && !istermoption(p)
9502 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009503 {
9504 /* skip global option when only doing locals */
9505 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9506 continue;
9507
9508 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9509 * file, they are always buffer-specific. */
9510 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9511 continue;
9512
9513 /* Global values are only written when not at the default value. */
9514 varp = get_varp_scope(p, opt_flags);
9515 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9516 continue;
9517
9518 round = 2;
9519 if (p->indir != PV_NONE)
9520 {
9521 if (p->var == VAR_WIN)
9522 {
9523 /* skip window-local option when only doing globals */
9524 if (!(opt_flags & OPT_LOCAL))
9525 continue;
9526 /* When fresh value of window-local option is not at the
9527 * default, need to write it too. */
9528 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9529 {
9530 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9531 if (!optval_default(p, varp_fresh))
9532 {
9533 round = 1;
9534 varp_local = varp;
9535 varp = varp_fresh;
9536 }
9537 }
9538 }
9539 }
9540
9541 /* Round 1: fresh value for window-local options.
9542 * Round 2: other values */
9543 for ( ; round <= 2; varp = varp_local, ++round)
9544 {
9545 if (round == 1 || (opt_flags & OPT_GLOBAL))
9546 cmd = "set";
9547 else
9548 cmd = "setlocal";
9549
9550 if (p->flags & P_BOOL)
9551 {
9552 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9553 return FAIL;
9554 }
9555 else if (p->flags & P_NUM)
9556 {
9557 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9558 return FAIL;
9559 }
9560 else /* P_STRING */
9561 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009562#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9563 int do_endif = FALSE;
9564
Bram Moolenaar071d4272004-06-13 20:20:40 +00009565 /* Don't set 'syntax' and 'filetype' again if the value is
9566 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009567 if (
9568# if defined(FEAT_SYN_HL)
9569 p->indir == PV_SYN
9570# if defined(FEAT_AUTOCMD)
9571 ||
9572# endif
9573# endif
9574# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009575 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009576# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009577 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009578 {
9579 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9580 *(char_u **)(varp)) < 0
9581 || put_eol(fd) < 0)
9582 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009583 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009584 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009585#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009586 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9587 (p->flags & P_EXPAND) != 0) == FAIL)
9588 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009589#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9590 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009591 {
9592 if (put_line(fd, "endif") == FAIL)
9593 return FAIL;
9594 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009595#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009596 }
9597 }
9598 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009599 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009600 return OK;
9601}
9602
9603#if defined(FEAT_FOLDING) || defined(PROTO)
9604/*
9605 * Generate set commands for the local fold options only. Used when
9606 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9607 */
9608 int
9609makefoldset(fd)
9610 FILE *fd;
9611{
9612 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9613# ifdef FEAT_EVAL
9614 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9615 == FAIL
9616# endif
9617 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9618 == FAIL
9619 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9620 == FAIL
9621 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9622 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9623 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9624 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9625 )
9626 return FAIL;
9627
9628 return OK;
9629}
9630#endif
9631
9632 static int
9633put_setstring(fd, cmd, name, valuep, expand)
9634 FILE *fd;
9635 char *cmd;
9636 char *name;
9637 char_u **valuep;
9638 int expand;
9639{
9640 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009641 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009642
9643 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9644 return FAIL;
9645 if (*valuep != NULL)
9646 {
9647 /* Output 'pastetoggle' as key names. For other
9648 * options some characters have to be escaped with
9649 * CTRL-V or backslash */
9650 if (valuep == &p_pt)
9651 {
9652 s = *valuep;
9653 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009654 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009655 return FAIL;
9656 }
9657 else if (expand)
9658 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009659 buf = alloc(MAXPATHL);
9660 if (buf == NULL)
9661 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009662 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9663 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009664 {
9665 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009666 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009667 }
9668 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669 }
9670 else if (put_escstr(fd, *valuep, 2) == FAIL)
9671 return FAIL;
9672 }
9673 if (put_eol(fd) < 0)
9674 return FAIL;
9675 return OK;
9676}
9677
9678 static int
9679put_setnum(fd, cmd, name, valuep)
9680 FILE *fd;
9681 char *cmd;
9682 char *name;
9683 long *valuep;
9684{
9685 long wc;
9686
9687 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9688 return FAIL;
9689 if (wc_use_keyname((char_u *)valuep, &wc))
9690 {
9691 /* print 'wildchar' and 'wildcharm' as a key name */
9692 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9693 return FAIL;
9694 }
9695 else if (fprintf(fd, "%ld", *valuep) < 0)
9696 return FAIL;
9697 if (put_eol(fd) < 0)
9698 return FAIL;
9699 return OK;
9700}
9701
9702 static int
9703put_setbool(fd, cmd, name, value)
9704 FILE *fd;
9705 char *cmd;
9706 char *name;
9707 int value;
9708{
Bram Moolenaar893de922007-10-02 18:40:57 +00009709 if (value < 0) /* global/local option using global value */
9710 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009711 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9712 || put_eol(fd) < 0)
9713 return FAIL;
9714 return OK;
9715}
9716
9717/*
9718 * Clear all the terminal options.
9719 * If the option has been allocated, free the memory.
9720 * Terminal options are never hidden or indirect.
9721 */
9722 void
9723clear_termoptions()
9724{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725 /*
9726 * Reset a few things before clearing the old options. This may cause
9727 * outputting a few things that the terminal doesn't understand, but the
9728 * screen will be cleared later, so this is OK.
9729 */
9730#ifdef FEAT_MOUSE_TTY
9731 mch_setmouse(FALSE); /* switch mouse off */
9732#endif
9733#ifdef FEAT_TITLE
9734 mch_restore_title(3); /* restore window titles */
9735#endif
9736#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9737 /* When starting the GUI close the display opened for the clipboard.
9738 * After restoring the title, because that will need the display. */
9739 if (gui.starting)
9740 clear_xterm_clip();
9741#endif
9742#ifdef WIN3264
9743 /*
9744 * Check if this is allowed now.
9745 */
9746 if (can_end_termcap_mode(FALSE) == TRUE)
9747#endif
9748 stoptermcap(); /* stop termcap mode */
9749
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009750 free_termoptions();
9751}
9752
9753 void
9754free_termoptions()
9755{
9756 struct vimoption *p;
9757
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758 for (p = &options[0]; p->fullname != NULL; p++)
9759 if (istermoption(p))
9760 {
9761 if (p->flags & P_ALLOCED)
9762 free_string_option(*(char_u **)(p->var));
9763 if (p->flags & P_DEF_ALLOCED)
9764 free_string_option(p->def_val[VI_DEFAULT]);
9765 *(char_u **)(p->var) = empty_option;
9766 p->def_val[VI_DEFAULT] = empty_option;
9767 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9768 }
9769 clear_termcodes();
9770}
9771
9772/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009773 * Free the string for one term option, if it was allocated.
9774 * Set the string to empty_option and clear allocated flag.
9775 * "var" points to the option value.
9776 */
9777 void
9778free_one_termoption(var)
9779 char_u *var;
9780{
9781 struct vimoption *p;
9782
9783 for (p = &options[0]; p->fullname != NULL; p++)
9784 if (p->var == var)
9785 {
9786 if (p->flags & P_ALLOCED)
9787 free_string_option(*(char_u **)(p->var));
9788 *(char_u **)(p->var) = empty_option;
9789 p->flags &= ~P_ALLOCED;
9790 break;
9791 }
9792}
9793
9794/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795 * Set the terminal option defaults to the current value.
9796 * Used after setting the terminal name.
9797 */
9798 void
9799set_term_defaults()
9800{
9801 struct vimoption *p;
9802
9803 for (p = &options[0]; p->fullname != NULL; p++)
9804 {
9805 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9806 {
9807 if (p->flags & P_DEF_ALLOCED)
9808 {
9809 free_string_option(p->def_val[VI_DEFAULT]);
9810 p->flags &= ~P_DEF_ALLOCED;
9811 }
9812 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9813 if (p->flags & P_ALLOCED)
9814 {
9815 p->flags |= P_DEF_ALLOCED;
9816 p->flags &= ~P_ALLOCED; /* don't free the value now */
9817 }
9818 }
9819 }
9820}
9821
9822/*
9823 * return TRUE if 'p' starts with 't_'
9824 */
9825 static int
9826istermoption(p)
9827 struct vimoption *p;
9828{
9829 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9830}
9831
9832/*
9833 * Compute columns for ruler and shown command. 'sc_col' is also used to
9834 * decide what the maximum length of a message on the status line can be.
9835 * If there is a status line for the last window, 'sc_col' is independent
9836 * of 'ru_col'.
9837 */
9838
9839#define COL_RULER 17 /* columns needed by standard ruler */
9840
9841 void
9842comp_col()
9843{
9844#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9845 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9846
9847 sc_col = 0;
9848 ru_col = 0;
9849 if (p_ru)
9850 {
9851#ifdef FEAT_STL_OPT
9852 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9853#else
9854 ru_col = COL_RULER + 1;
9855#endif
9856 /* no last status line, adjust sc_col */
9857 if (!last_has_status)
9858 sc_col = ru_col;
9859 }
9860 if (p_sc)
9861 {
9862 sc_col += SHOWCMD_COLS;
9863 if (!p_ru || last_has_status) /* no need for separating space */
9864 ++sc_col;
9865 }
9866 sc_col = Columns - sc_col;
9867 ru_col = Columns - ru_col;
9868 if (sc_col <= 0) /* screen too narrow, will become a mess */
9869 sc_col = 1;
9870 if (ru_col <= 0)
9871 ru_col = 1;
9872#else
9873 sc_col = Columns;
9874 ru_col = Columns;
9875#endif
9876}
9877
9878/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009879 * Unset local option value, similar to ":set opt<".
9880 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009881 void
9882unset_global_local_option(name, from)
9883 char_u *name;
9884 void *from;
9885{
9886 struct vimoption *p;
9887 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009888 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009889
9890 opt_idx = findoption(name);
9891 p = &(options[opt_idx]);
9892
9893 switch ((int)p->indir)
9894 {
9895 /* global option with local value: use local value if it's been set */
9896 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009897 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009898 break;
9899 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009900 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009901 break;
9902 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009903 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009904 break;
9905 case PV_AR:
9906 buf->b_p_ar = -1;
9907 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009908 case PV_BKC:
9909 clear_string_option(&buf->b_p_bkc);
9910 buf->b_bkc_flags = 0;
9911 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009912 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009913 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009914 break;
9915#ifdef FEAT_FIND_ID
9916 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009917 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009918 break;
9919 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009920 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009921 break;
9922#endif
9923#ifdef FEAT_INS_EXPAND
9924 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009925 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009926 break;
9927 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009928 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009929 break;
9930#endif
9931#ifdef FEAT_QUICKFIX
9932 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009933 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009934 break;
9935 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009936 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009937 break;
9938 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009939 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009940 break;
9941#endif
9942#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9943 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009944 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009945 break;
9946#endif
9947#if defined(FEAT_CRYPT)
9948 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009949 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009950 break;
9951#endif
9952#ifdef FEAT_STL_OPT
9953 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009954 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009955 break;
9956#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009957 case PV_UL:
9958 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9959 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009960#ifdef FEAT_LISP
9961 case PV_LW:
9962 clear_string_option(&buf->b_p_lw);
9963 break;
9964#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009965 }
9966}
9967
9968/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009969 * Get pointer to option variable, depending on local or global scope.
9970 */
9971 static char_u *
9972get_varp_scope(p, opt_flags)
9973 struct vimoption *p;
9974 int opt_flags;
9975{
9976 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9977 {
9978 if (p->var == VAR_WIN)
9979 return (char_u *)GLOBAL_WO(get_varp(p));
9980 return p->var;
9981 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009982 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983 {
9984 switch ((int)p->indir)
9985 {
9986#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009987 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9988 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9989 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009990#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009991 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9992 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9993 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009994 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009995 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009997 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9998 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009999#endif
10000#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010001 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10002 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010004#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10005 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10006#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010007#if defined(FEAT_CRYPT)
10008 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10009#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010010#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010011 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010012#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010013 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010014#ifdef FEAT_LISP
10015 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10016#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010017 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010018 }
10019 return NULL; /* "cannot happen" */
10020 }
10021 return get_varp(p);
10022}
10023
10024/*
10025 * Get pointer to option variable.
10026 */
10027 static char_u *
10028get_varp(p)
10029 struct vimoption *p;
10030{
10031 /* hidden option, always return NULL */
10032 if (p->var == NULL)
10033 return NULL;
10034
10035 switch ((int)p->indir)
10036 {
10037 case PV_NONE: return p->var;
10038
10039 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010040 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010042 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010044 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010045 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010046 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010047 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010048 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010050 case PV_BKC: return *curbuf->b_p_bkc != NUL
10051 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010053 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010054 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010055 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10057#endif
10058#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010059 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010060 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010061 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10063#endif
10064#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010065 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010067 case PV_GP: return *curbuf->b_p_gp != NUL
10068 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10069 case PV_MP: return *curbuf->b_p_mp != NUL
10070 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010071#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010072#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10073 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10074 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10075#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010076#if defined(FEAT_CRYPT)
10077 case PV_CM: return *curbuf->b_p_cm != NUL
10078 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10079#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010080#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010081 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010082 ? (char_u *)&(curwin->w_p_stl) : p->var;
10083#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010084 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10085 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010086#ifdef FEAT_LISP
10087 case PV_LW: return *curbuf->b_p_lw != NUL
10088 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10089#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010090
10091#ifdef FEAT_ARABIC
10092 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10093#endif
10094 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010095#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010096 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10097#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010098#ifdef FEAT_SYN_HL
10099 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10100 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010101 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010102#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010103#ifdef FEAT_DIFF
10104 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10105#endif
10106#ifdef FEAT_FOLDING
10107 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10108 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10109 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10110 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10111 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10112 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10113 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10114# ifdef FEAT_EVAL
10115 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10116 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10117# endif
10118 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10119#endif
10120 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010121 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010122#ifdef FEAT_LINEBREAK
10123 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10124#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010125#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10127#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010128#ifdef FEAT_VERTSPLIT
10129 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10130#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10132 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10133#endif
10134#ifdef FEAT_RIGHTLEFT
10135 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10136 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10137#endif
10138 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10139 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10140#ifdef FEAT_LINEBREAK
10141 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010142 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10143 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010144#endif
10145#ifdef FEAT_SCROLLBIND
10146 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10147#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010148#ifdef FEAT_CURSORBIND
10149 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10150#endif
10151#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010152 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10153 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155
10156 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10157 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10158#ifdef FEAT_MBYTE
10159 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10160#endif
10161#if defined(FEAT_QUICKFIX)
10162 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10163 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10164#endif
10165 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10166 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10167#ifdef FEAT_CINDENT
10168 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10169 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10170 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10171#endif
10172#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10173 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10174#endif
10175#ifdef FEAT_COMMENTS
10176 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10177#endif
10178#ifdef FEAT_FOLDING
10179 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10180#endif
10181#ifdef FEAT_INS_EXPAND
10182 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10183#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010184#ifdef FEAT_COMPL_FUNC
10185 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010186 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010187#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010189 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10191#ifdef FEAT_MBYTE
10192 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10193#endif
10194 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10195#ifdef FEAT_AUTOCMD
10196 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10197#endif
10198 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010199 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10201 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10202 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10203 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10204#ifdef FEAT_FIND_ID
10205# ifdef FEAT_EVAL
10206 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10207# endif
10208#endif
10209#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10210 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10211 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10212#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010213#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010214 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216#ifdef FEAT_CRYPT
10217 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10218#endif
10219#ifdef FEAT_LISP
10220 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10221#endif
10222 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10223 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10224 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10225 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10226 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010228#ifdef FEAT_TEXTOBJ
10229 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10230#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010231 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10232#ifdef FEAT_SMARTINDENT
10233 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10234#endif
10235#ifndef SHORT_FNAME
10236 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10237#endif
10238 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10239#ifdef FEAT_SEARCHPATH
10240 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10241#endif
10242 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10243#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010244 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010245 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10246#endif
10247#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010248 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10249 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10250 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251#endif
10252 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10253 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10254 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10255 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010256#ifdef FEAT_PERSISTENT_UNDO
10257 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10260#ifdef FEAT_KEYMAP
10261 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10262#endif
10263 default: EMSG(_("E356: get_varp ERROR"));
10264 }
10265 /* always return a valid pointer to avoid a crash! */
10266 return (char_u *)&(curbuf->b_p_wm);
10267}
10268
10269/*
10270 * Get the value of 'equalprg', either the buffer-local one or the global one.
10271 */
10272 char_u *
10273get_equalprg()
10274{
10275 if (*curbuf->b_p_ep == NUL)
10276 return p_ep;
10277 return curbuf->b_p_ep;
10278}
10279
10280#if defined(FEAT_WINDOWS) || defined(PROTO)
10281/*
10282 * Copy options from one window to another.
10283 * Used when splitting a window.
10284 */
10285 void
10286win_copy_options(wp_from, wp_to)
10287 win_T *wp_from;
10288 win_T *wp_to;
10289{
10290 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10291 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10292# ifdef FEAT_RIGHTLEFT
10293# ifdef FEAT_FKMAP
10294 /* Is this right? */
10295 wp_to->w_farsi = wp_from->w_farsi;
10296# endif
10297# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010298#if defined(FEAT_LINEBREAK)
10299 briopt_check(wp_to);
10300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301}
10302#endif
10303
10304/*
10305 * Copy the options from one winopt_T to another.
10306 * Doesn't free the old option values in "to", use clear_winopt() for that.
10307 * The 'scroll' option is not copied, because it depends on the window height.
10308 * The 'previewwindow' option is reset, there can be only one preview window.
10309 */
10310 void
10311copy_winopt(from, to)
10312 winopt_T *from;
10313 winopt_T *to;
10314{
10315#ifdef FEAT_ARABIC
10316 to->wo_arab = from->wo_arab;
10317#endif
10318 to->wo_list = from->wo_list;
10319 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010320 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010321#ifdef FEAT_LINEBREAK
10322 to->wo_nuw = from->wo_nuw;
10323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324#ifdef FEAT_RIGHTLEFT
10325 to->wo_rl = from->wo_rl;
10326 to->wo_rlc = vim_strsave(from->wo_rlc);
10327#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010328#ifdef FEAT_STL_OPT
10329 to->wo_stl = vim_strsave(from->wo_stl);
10330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010332#ifdef FEAT_DIFF
10333 to->wo_wrap_save = from->wo_wrap_save;
10334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335#ifdef FEAT_LINEBREAK
10336 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010337 to->wo_bri = from->wo_bri;
10338 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339#endif
10340#ifdef FEAT_SCROLLBIND
10341 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010342 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010344#ifdef FEAT_CURSORBIND
10345 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010346 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010347#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010348#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010349 to->wo_spell = from->wo_spell;
10350#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010351#ifdef FEAT_SYN_HL
10352 to->wo_cuc = from->wo_cuc;
10353 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010354 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356#ifdef FEAT_DIFF
10357 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010358 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010360#ifdef FEAT_CONCEAL
10361 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010362 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010363#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010364#ifdef FEAT_FOLDING
10365 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010366 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010367 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010368 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369 to->wo_fdi = vim_strsave(from->wo_fdi);
10370 to->wo_fml = from->wo_fml;
10371 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010372 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010374 to->wo_fdm_save = from->wo_diff_saved
10375 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376 to->wo_fdn = from->wo_fdn;
10377# ifdef FEAT_EVAL
10378 to->wo_fde = vim_strsave(from->wo_fde);
10379 to->wo_fdt = vim_strsave(from->wo_fdt);
10380# endif
10381 to->wo_fmr = vim_strsave(from->wo_fmr);
10382#endif
10383 check_winopt(to); /* don't want NULL pointers */
10384}
10385
10386/*
10387 * Check string options in a window for a NULL value.
10388 */
10389 void
10390check_win_options(win)
10391 win_T *win;
10392{
10393 check_winopt(&win->w_onebuf_opt);
10394 check_winopt(&win->w_allbuf_opt);
10395}
10396
10397/*
10398 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10399 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010400 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010402 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403{
10404#ifdef FEAT_FOLDING
10405 check_string_option(&wop->wo_fdi);
10406 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010407 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408# ifdef FEAT_EVAL
10409 check_string_option(&wop->wo_fde);
10410 check_string_option(&wop->wo_fdt);
10411# endif
10412 check_string_option(&wop->wo_fmr);
10413#endif
10414#ifdef FEAT_RIGHTLEFT
10415 check_string_option(&wop->wo_rlc);
10416#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010417#ifdef FEAT_STL_OPT
10418 check_string_option(&wop->wo_stl);
10419#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010420#ifdef FEAT_SYN_HL
10421 check_string_option(&wop->wo_cc);
10422#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010423#ifdef FEAT_CONCEAL
10424 check_string_option(&wop->wo_cocu);
10425#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010426#ifdef FEAT_LINEBREAK
10427 check_string_option(&wop->wo_briopt);
10428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429}
10430
10431/*
10432 * Free the allocated memory inside a winopt_T.
10433 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434 void
10435clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010436 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010437{
10438#ifdef FEAT_FOLDING
10439 clear_string_option(&wop->wo_fdi);
10440 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010441 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010442# ifdef FEAT_EVAL
10443 clear_string_option(&wop->wo_fde);
10444 clear_string_option(&wop->wo_fdt);
10445# endif
10446 clear_string_option(&wop->wo_fmr);
10447#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010448#ifdef FEAT_LINEBREAK
10449 clear_string_option(&wop->wo_briopt);
10450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451#ifdef FEAT_RIGHTLEFT
10452 clear_string_option(&wop->wo_rlc);
10453#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010454#ifdef FEAT_STL_OPT
10455 clear_string_option(&wop->wo_stl);
10456#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010457#ifdef FEAT_SYN_HL
10458 clear_string_option(&wop->wo_cc);
10459#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010460#ifdef FEAT_CONCEAL
10461 clear_string_option(&wop->wo_cocu);
10462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463}
10464
10465/*
10466 * Copy global option values to local options for one buffer.
10467 * Used when creating a new buffer and sometimes when entering a buffer.
10468 * flags:
10469 * BCO_ENTER We will enter the buf buffer.
10470 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10471 * appropriate.
10472 * BCO_NOHELP Don't copy the values to a help buffer.
10473 */
10474 void
10475buf_copy_options(buf, flags)
10476 buf_T *buf;
10477 int flags;
10478{
10479 int should_copy = TRUE;
10480 char_u *save_p_isk = NULL; /* init for GCC */
10481 int dont_do_help;
10482 int did_isk = FALSE;
10483
10484 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010485 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486 */
10487 if (buf == NULL || !buf_valid(buf))
10488 return;
10489
10490 /*
10491 * Skip this when the option defaults have not been set yet. Happens when
10492 * main() allocates the first buffer.
10493 */
10494 if (p_cpo != NULL)
10495 {
10496 /*
10497 * Always copy when entering and 'cpo' contains 'S'.
10498 * Don't copy when already initialized.
10499 * Don't copy when 'cpo' contains 's' and not entering.
10500 * 'S' BCO_ENTER initialized 's' should_copy
10501 * yes yes X X TRUE
10502 * yes no yes X FALSE
10503 * no X yes X FALSE
10504 * X no no yes FALSE
10505 * X no no no TRUE
10506 * no yes no X TRUE
10507 */
10508 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10509 && (buf->b_p_initialized
10510 || (!(flags & BCO_ENTER)
10511 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10512 should_copy = FALSE;
10513
10514 if (should_copy || (flags & BCO_ALWAYS))
10515 {
10516 /* Don't copy the options specific to a help buffer when
10517 * BCO_NOHELP is given or the options were initialized already
10518 * (jumping back to a help file with CTRL-T or CTRL-O) */
10519 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10520 || buf->b_p_initialized;
10521 if (dont_do_help) /* don't free b_p_isk */
10522 {
10523 save_p_isk = buf->b_p_isk;
10524 buf->b_p_isk = NULL;
10525 }
10526 /*
10527 * Always free the allocated strings.
10528 * If not already initialized, set 'readonly' and copy 'fileformat'.
10529 */
10530 if (!buf->b_p_initialized)
10531 {
10532 free_buf_options(buf, TRUE);
10533 buf->b_p_ro = FALSE; /* don't copy readonly */
10534 buf->b_p_tx = p_tx;
10535#ifdef FEAT_MBYTE
10536 buf->b_p_fenc = vim_strsave(p_fenc);
10537#endif
10538 buf->b_p_ff = vim_strsave(p_ff);
10539#if defined(FEAT_QUICKFIX)
10540 buf->b_p_bh = empty_option;
10541 buf->b_p_bt = empty_option;
10542#endif
10543 }
10544 else
10545 free_buf_options(buf, FALSE);
10546
10547 buf->b_p_ai = p_ai;
10548 buf->b_p_ai_nopaste = p_ai_nopaste;
10549 buf->b_p_sw = p_sw;
10550 buf->b_p_tw = p_tw;
10551 buf->b_p_tw_nopaste = p_tw_nopaste;
10552 buf->b_p_tw_nobin = p_tw_nobin;
10553 buf->b_p_wm = p_wm;
10554 buf->b_p_wm_nopaste = p_wm_nopaste;
10555 buf->b_p_wm_nobin = p_wm_nobin;
10556 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010557#ifdef FEAT_MBYTE
10558 buf->b_p_bomb = p_bomb;
10559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560 buf->b_p_et = p_et;
10561 buf->b_p_et_nobin = p_et_nobin;
10562 buf->b_p_ml = p_ml;
10563 buf->b_p_ml_nobin = p_ml_nobin;
10564 buf->b_p_inf = p_inf;
10565 buf->b_p_swf = p_swf;
10566#ifdef FEAT_INS_EXPAND
10567 buf->b_p_cpt = vim_strsave(p_cpt);
10568#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010569#ifdef FEAT_COMPL_FUNC
10570 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010571 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010572#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573 buf->b_p_sts = p_sts;
10574 buf->b_p_sts_nopaste = p_sts_nopaste;
10575#ifndef SHORT_FNAME
10576 buf->b_p_sn = p_sn;
10577#endif
10578#ifdef FEAT_COMMENTS
10579 buf->b_p_com = vim_strsave(p_com);
10580#endif
10581#ifdef FEAT_FOLDING
10582 buf->b_p_cms = vim_strsave(p_cms);
10583#endif
10584 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010585 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586 buf->b_p_nf = vim_strsave(p_nf);
10587 buf->b_p_mps = vim_strsave(p_mps);
10588#ifdef FEAT_SMARTINDENT
10589 buf->b_p_si = p_si;
10590#endif
10591 buf->b_p_ci = p_ci;
10592#ifdef FEAT_CINDENT
10593 buf->b_p_cin = p_cin;
10594 buf->b_p_cink = vim_strsave(p_cink);
10595 buf->b_p_cino = vim_strsave(p_cino);
10596#endif
10597#ifdef FEAT_AUTOCMD
10598 /* Don't copy 'filetype', it must be detected */
10599 buf->b_p_ft = empty_option;
10600#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 buf->b_p_pi = p_pi;
10602#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10603 buf->b_p_cinw = vim_strsave(p_cinw);
10604#endif
10605#ifdef FEAT_LISP
10606 buf->b_p_lisp = p_lisp;
10607#endif
10608#ifdef FEAT_SYN_HL
10609 /* Don't copy 'syntax', it must be set */
10610 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010611 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010612#endif
10613#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010614 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010615 (void)compile_cap_prog(&buf->b_s);
10616 buf->b_s.b_p_spf = vim_strsave(p_spf);
10617 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618#endif
10619#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10620 buf->b_p_inde = vim_strsave(p_inde);
10621 buf->b_p_indk = vim_strsave(p_indk);
10622#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010623#if defined(FEAT_EVAL)
10624 buf->b_p_fex = vim_strsave(p_fex);
10625#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626#ifdef FEAT_CRYPT
10627 buf->b_p_key = vim_strsave(p_key);
10628#endif
10629#ifdef FEAT_SEARCHPATH
10630 buf->b_p_sua = vim_strsave(p_sua);
10631#endif
10632#ifdef FEAT_KEYMAP
10633 buf->b_p_keymap = vim_strsave(p_keymap);
10634 buf->b_kmap_state |= KEYMAP_INIT;
10635#endif
10636 /* This isn't really an option, but copying the langmap and IME
10637 * state from the current buffer is better than resetting it. */
10638 buf->b_p_iminsert = p_iminsert;
10639 buf->b_p_imsearch = p_imsearch;
10640
10641 /* options that are normally global but also have a local value
10642 * are not copied, start using the global value */
10643 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010644 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010645 buf->b_p_bkc = empty_option;
10646 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647#ifdef FEAT_QUICKFIX
10648 buf->b_p_gp = empty_option;
10649 buf->b_p_mp = empty_option;
10650 buf->b_p_efm = empty_option;
10651#endif
10652 buf->b_p_ep = empty_option;
10653 buf->b_p_kp = empty_option;
10654 buf->b_p_path = empty_option;
10655 buf->b_p_tags = empty_option;
10656#ifdef FEAT_FIND_ID
10657 buf->b_p_def = empty_option;
10658 buf->b_p_inc = empty_option;
10659# ifdef FEAT_EVAL
10660 buf->b_p_inex = vim_strsave(p_inex);
10661# endif
10662#endif
10663#ifdef FEAT_INS_EXPAND
10664 buf->b_p_dict = empty_option;
10665 buf->b_p_tsr = empty_option;
10666#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010667#ifdef FEAT_TEXTOBJ
10668 buf->b_p_qe = vim_strsave(p_qe);
10669#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010670#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10671 buf->b_p_bexpr = empty_option;
10672#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010673#if defined(FEAT_CRYPT)
10674 buf->b_p_cm = empty_option;
10675#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010676#ifdef FEAT_PERSISTENT_UNDO
10677 buf->b_p_udf = p_udf;
10678#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010679#ifdef FEAT_LISP
10680 buf->b_p_lw = empty_option;
10681#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010682
10683 /*
10684 * Don't copy the options set by ex_help(), use the saved values,
10685 * when going from a help buffer to a non-help buffer.
10686 * Don't touch these at all when BCO_NOHELP is used and going from
10687 * or to a help buffer.
10688 */
10689 if (dont_do_help)
10690 buf->b_p_isk = save_p_isk;
10691 else
10692 {
10693 buf->b_p_isk = vim_strsave(p_isk);
10694 did_isk = TRUE;
10695 buf->b_p_ts = p_ts;
10696 buf->b_help = FALSE;
10697#ifdef FEAT_QUICKFIX
10698 if (buf->b_p_bt[0] == 'h')
10699 clear_string_option(&buf->b_p_bt);
10700#endif
10701 buf->b_p_ma = p_ma;
10702 }
10703 }
10704
10705 /*
10706 * When the options should be copied (ignoring BCO_ALWAYS), set the
10707 * flag that indicates that the options have been initialized.
10708 */
10709 if (should_copy)
10710 buf->b_p_initialized = TRUE;
10711 }
10712
10713 check_buf_options(buf); /* make sure we don't have NULLs */
10714 if (did_isk)
10715 (void)buf_init_chartab(buf, FALSE);
10716}
10717
10718/*
10719 * Reset the 'modifiable' option and its default value.
10720 */
10721 void
10722reset_modifiable()
10723{
10724 int opt_idx;
10725
10726 curbuf->b_p_ma = FALSE;
10727 p_ma = FALSE;
10728 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010729 if (opt_idx >= 0)
10730 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731}
10732
10733/*
10734 * Set the global value for 'iminsert' to the local value.
10735 */
10736 void
10737set_iminsert_global()
10738{
10739 p_iminsert = curbuf->b_p_iminsert;
10740}
10741
10742/*
10743 * Set the global value for 'imsearch' to the local value.
10744 */
10745 void
10746set_imsearch_global()
10747{
10748 p_imsearch = curbuf->b_p_imsearch;
10749}
10750
10751#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10752static int expand_option_idx = -1;
10753static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10754static int expand_option_flags = 0;
10755
10756 void
10757set_context_in_set_cmd(xp, arg, opt_flags)
10758 expand_T *xp;
10759 char_u *arg;
10760 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10761{
10762 int nextchar;
10763 long_u flags = 0; /* init for GCC */
10764 int opt_idx = 0; /* init for GCC */
10765 char_u *p;
10766 char_u *s;
10767 int is_term_option = FALSE;
10768 int key;
10769
10770 expand_option_flags = opt_flags;
10771
10772 xp->xp_context = EXPAND_SETTINGS;
10773 if (*arg == NUL)
10774 {
10775 xp->xp_pattern = arg;
10776 return;
10777 }
10778 p = arg + STRLEN(arg) - 1;
10779 if (*p == ' ' && *(p - 1) != '\\')
10780 {
10781 xp->xp_pattern = p + 1;
10782 return;
10783 }
10784 while (p > arg)
10785 {
10786 s = p;
10787 /* count number of backslashes before ' ' or ',' */
10788 if (*p == ' ' || *p == ',')
10789 {
10790 while (s > arg && *(s - 1) == '\\')
10791 --s;
10792 }
10793 /* break at a space with an even number of backslashes */
10794 if (*p == ' ' && ((p - s) & 1) == 0)
10795 {
10796 ++p;
10797 break;
10798 }
10799 --p;
10800 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010801 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010802 {
10803 xp->xp_context = EXPAND_BOOL_SETTINGS;
10804 p += 2;
10805 }
10806 if (STRNCMP(p, "inv", 3) == 0)
10807 {
10808 xp->xp_context = EXPAND_BOOL_SETTINGS;
10809 p += 3;
10810 }
10811 xp->xp_pattern = arg = p;
10812 if (*arg == '<')
10813 {
10814 while (*p != '>')
10815 if (*p++ == NUL) /* expand terminal option name */
10816 return;
10817 key = get_special_key_code(arg + 1);
10818 if (key == 0) /* unknown name */
10819 {
10820 xp->xp_context = EXPAND_NOTHING;
10821 return;
10822 }
10823 nextchar = *++p;
10824 is_term_option = TRUE;
10825 expand_option_name[2] = KEY2TERMCAP0(key);
10826 expand_option_name[3] = KEY2TERMCAP1(key);
10827 }
10828 else
10829 {
10830 if (p[0] == 't' && p[1] == '_')
10831 {
10832 p += 2;
10833 if (*p != NUL)
10834 ++p;
10835 if (*p == NUL)
10836 return; /* expand option name */
10837 nextchar = *++p;
10838 is_term_option = TRUE;
10839 expand_option_name[2] = p[-2];
10840 expand_option_name[3] = p[-1];
10841 }
10842 else
10843 {
10844 /* Allow * wildcard */
10845 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10846 p++;
10847 if (*p == NUL)
10848 return;
10849 nextchar = *p;
10850 *p = NUL;
10851 opt_idx = findoption(arg);
10852 *p = nextchar;
10853 if (opt_idx == -1 || options[opt_idx].var == NULL)
10854 {
10855 xp->xp_context = EXPAND_NOTHING;
10856 return;
10857 }
10858 flags = options[opt_idx].flags;
10859 if (flags & P_BOOL)
10860 {
10861 xp->xp_context = EXPAND_NOTHING;
10862 return;
10863 }
10864 }
10865 }
10866 /* handle "-=" and "+=" */
10867 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10868 {
10869 ++p;
10870 nextchar = '=';
10871 }
10872 if ((nextchar != '=' && nextchar != ':')
10873 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10874 {
10875 xp->xp_context = EXPAND_UNSUCCESSFUL;
10876 return;
10877 }
10878 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10879 {
10880 xp->xp_context = EXPAND_OLD_SETTING;
10881 if (is_term_option)
10882 expand_option_idx = -1;
10883 else
10884 expand_option_idx = opt_idx;
10885 xp->xp_pattern = p + 1;
10886 return;
10887 }
10888 xp->xp_context = EXPAND_NOTHING;
10889 if (is_term_option || (flags & P_NUM))
10890 return;
10891
10892 xp->xp_pattern = p + 1;
10893
10894 if (flags & P_EXPAND)
10895 {
10896 p = options[opt_idx].var;
10897 if (p == (char_u *)&p_bdir
10898 || p == (char_u *)&p_dir
10899 || p == (char_u *)&p_path
10900 || p == (char_u *)&p_rtp
10901#ifdef FEAT_SEARCHPATH
10902 || p == (char_u *)&p_cdpath
10903#endif
10904#ifdef FEAT_SESSION
10905 || p == (char_u *)&p_vdir
10906#endif
10907 )
10908 {
10909 xp->xp_context = EXPAND_DIRECTORIES;
10910 if (p == (char_u *)&p_path
10911#ifdef FEAT_SEARCHPATH
10912 || p == (char_u *)&p_cdpath
10913#endif
10914 )
10915 xp->xp_backslash = XP_BS_THREE;
10916 else
10917 xp->xp_backslash = XP_BS_ONE;
10918 }
10919 else
10920 {
10921 xp->xp_context = EXPAND_FILES;
10922 /* for 'tags' need three backslashes for a space */
10923 if (p == (char_u *)&p_tags)
10924 xp->xp_backslash = XP_BS_THREE;
10925 else
10926 xp->xp_backslash = XP_BS_ONE;
10927 }
10928 }
10929
10930 /* For an option that is a list of file names, find the start of the
10931 * last file name. */
10932 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10933 {
10934 /* count number of backslashes before ' ' or ',' */
10935 if (*p == ' ' || *p == ',')
10936 {
10937 s = p;
10938 while (s > xp->xp_pattern && *(s - 1) == '\\')
10939 --s;
10940 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10941 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10942 {
10943 xp->xp_pattern = p + 1;
10944 break;
10945 }
10946 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010947
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010948#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010949 /* for 'spellsuggest' start at "file:" */
10950 if (options[opt_idx].var == (char_u *)&p_sps
10951 && STRNCMP(p, "file:", 5) == 0)
10952 {
10953 xp->xp_pattern = p + 5;
10954 break;
10955 }
10956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957 }
10958
10959 return;
10960}
10961
10962 int
10963ExpandSettings(xp, regmatch, num_file, file)
10964 expand_T *xp;
10965 regmatch_T *regmatch;
10966 int *num_file;
10967 char_u ***file;
10968{
10969 int num_normal = 0; /* Nr of matching non-term-code settings */
10970 int num_term = 0; /* Nr of matching terminal code settings */
10971 int opt_idx;
10972 int match;
10973 int count = 0;
10974 char_u *str;
10975 int loop;
10976 int is_term_opt;
10977 char_u name_buf[MAX_KEY_NAME_LEN];
10978 static char *(names[]) = {"all", "termcap"};
10979 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10980
10981 /* do this loop twice:
10982 * loop == 0: count the number of matching options
10983 * loop == 1: copy the matching options into allocated memory
10984 */
10985 for (loop = 0; loop <= 1; ++loop)
10986 {
10987 regmatch->rm_ic = ic;
10988 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10989 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010990 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10991 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010992 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10993 {
10994 if (loop == 0)
10995 num_normal++;
10996 else
10997 (*file)[count++] = vim_strsave((char_u *)names[match]);
10998 }
10999 }
11000 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11001 opt_idx++)
11002 {
11003 if (options[opt_idx].var == NULL)
11004 continue;
11005 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11006 && !(options[opt_idx].flags & P_BOOL))
11007 continue;
11008 is_term_opt = istermoption(&options[opt_idx]);
11009 if (is_term_opt && num_normal > 0)
11010 continue;
11011 match = FALSE;
11012 if (vim_regexec(regmatch, str, (colnr_T)0)
11013 || (options[opt_idx].shortname != NULL
11014 && vim_regexec(regmatch,
11015 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11016 match = TRUE;
11017 else if (is_term_opt)
11018 {
11019 name_buf[0] = '<';
11020 name_buf[1] = 't';
11021 name_buf[2] = '_';
11022 name_buf[3] = str[2];
11023 name_buf[4] = str[3];
11024 name_buf[5] = '>';
11025 name_buf[6] = NUL;
11026 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11027 {
11028 match = TRUE;
11029 str = name_buf;
11030 }
11031 }
11032 if (match)
11033 {
11034 if (loop == 0)
11035 {
11036 if (is_term_opt)
11037 num_term++;
11038 else
11039 num_normal++;
11040 }
11041 else
11042 (*file)[count++] = vim_strsave(str);
11043 }
11044 }
11045 /*
11046 * Check terminal key codes, these are not in the option table
11047 */
11048 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11049 {
11050 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11051 {
11052 if (!isprint(str[0]) || !isprint(str[1]))
11053 continue;
11054
11055 name_buf[0] = 't';
11056 name_buf[1] = '_';
11057 name_buf[2] = str[0];
11058 name_buf[3] = str[1];
11059 name_buf[4] = NUL;
11060
11061 match = FALSE;
11062 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11063 match = TRUE;
11064 else
11065 {
11066 name_buf[0] = '<';
11067 name_buf[1] = 't';
11068 name_buf[2] = '_';
11069 name_buf[3] = str[0];
11070 name_buf[4] = str[1];
11071 name_buf[5] = '>';
11072 name_buf[6] = NUL;
11073
11074 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11075 match = TRUE;
11076 }
11077 if (match)
11078 {
11079 if (loop == 0)
11080 num_term++;
11081 else
11082 (*file)[count++] = vim_strsave(name_buf);
11083 }
11084 }
11085
11086 /*
11087 * Check special key names.
11088 */
11089 regmatch->rm_ic = TRUE; /* ignore case here */
11090 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11091 {
11092 name_buf[0] = '<';
11093 STRCPY(name_buf + 1, str);
11094 STRCAT(name_buf, ">");
11095
11096 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11097 {
11098 if (loop == 0)
11099 num_term++;
11100 else
11101 (*file)[count++] = vim_strsave(name_buf);
11102 }
11103 }
11104 }
11105 if (loop == 0)
11106 {
11107 if (num_normal > 0)
11108 *num_file = num_normal;
11109 else if (num_term > 0)
11110 *num_file = num_term;
11111 else
11112 return OK;
11113 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11114 if (*file == NULL)
11115 {
11116 *file = (char_u **)"";
11117 return FAIL;
11118 }
11119 }
11120 }
11121 return OK;
11122}
11123
11124 int
11125ExpandOldSetting(num_file, file)
11126 int *num_file;
11127 char_u ***file;
11128{
11129 char_u *var = NULL; /* init for GCC */
11130 char_u *buf;
11131
11132 *num_file = 0;
11133 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11134 if (*file == NULL)
11135 return FAIL;
11136
11137 /*
11138 * For a terminal key code expand_option_idx is < 0.
11139 */
11140 if (expand_option_idx < 0)
11141 {
11142 var = find_termcode(expand_option_name + 2);
11143 if (var == NULL)
11144 expand_option_idx = findoption(expand_option_name);
11145 }
11146
11147 if (expand_option_idx >= 0)
11148 {
11149 /* put string of option value in NameBuff */
11150 option_value2string(&options[expand_option_idx], expand_option_flags);
11151 var = NameBuff;
11152 }
11153 else if (var == NULL)
11154 var = (char_u *)"";
11155
11156 /* A backslash is required before some characters. This is the reverse of
11157 * what happens in do_set(). */
11158 buf = vim_strsave_escaped(var, escape_chars);
11159
11160 if (buf == NULL)
11161 {
11162 vim_free(*file);
11163 *file = NULL;
11164 return FAIL;
11165 }
11166
11167#ifdef BACKSLASH_IN_FILENAME
11168 /* For MS-Windows et al. we don't double backslashes at the start and
11169 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011170 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011171 if (var[0] == '\\' && var[1] == '\\'
11172 && expand_option_idx >= 0
11173 && (options[expand_option_idx].flags & P_EXPAND)
11174 && vim_isfilec(var[2])
11175 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011176 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011177#endif
11178
11179 *file[0] = buf;
11180 *num_file = 1;
11181 return OK;
11182}
11183#endif
11184
11185/*
11186 * Get the value for the numeric or string option *opp in a nice format into
11187 * NameBuff[]. Must not be called with a hidden option!
11188 */
11189 static void
11190option_value2string(opp, opt_flags)
11191 struct vimoption *opp;
11192 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11193{
11194 char_u *varp;
11195
11196 varp = get_varp_scope(opp, opt_flags);
11197
11198 if (opp->flags & P_NUM)
11199 {
11200 long wc = 0;
11201
11202 if (wc_use_keyname(varp, &wc))
11203 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11204 else if (wc != 0)
11205 STRCPY(NameBuff, transchar((int)wc));
11206 else
11207 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11208 }
11209 else /* P_STRING */
11210 {
11211 varp = *(char_u **)(varp);
11212 if (varp == NULL) /* just in case */
11213 NameBuff[0] = NUL;
11214#ifdef FEAT_CRYPT
11215 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011216 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217 STRCPY(NameBuff, "*****");
11218#endif
11219 else if (opp->flags & P_EXPAND)
11220 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11221 /* Translate 'pastetoggle' into special key names */
11222 else if ((char_u **)opp->var == &p_pt)
11223 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11224 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011225 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011226 }
11227}
11228
11229/*
11230 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11231 * printed as a keyname.
11232 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11233 */
11234 static int
11235wc_use_keyname(varp, wcp)
11236 char_u *varp;
11237 long *wcp;
11238{
11239 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11240 {
11241 *wcp = *(long *)varp;
11242 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11243 return TRUE;
11244 }
11245 return FALSE;
11246}
11247
Bram Moolenaar01615492015-02-03 13:00:38 +010011248#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011250 * Any character has an equivalent 'langmap' character. This is used for
11251 * keyboards that have a special language mode that sends characters above
11252 * 128 (although other characters can be translated too). The "to" field is a
11253 * Vim command character. This avoids having to switch the keyboard back to
11254 * ASCII mode when leaving Insert mode.
11255 *
11256 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11257 * commands.
11258 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11259 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11260 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011261 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011262# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011263/*
11264 * With multi-byte support use growarray for 'langmap' chars >= 256
11265 */
11266typedef struct
11267{
11268 int from;
11269 int to;
11270} langmap_entry_T;
11271
11272static garray_T langmap_mapga;
11273static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011274
11275/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011276 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11277 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011279 static void
11280langmap_set_entry(from, to)
11281 int from;
11282 int to;
11283{
11284 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011285 int a = 0;
11286 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011287
11288 /* Do a binary search for an existing entry. */
11289 while (a != b)
11290 {
11291 int i = (a + b) / 2;
11292 int d = entries[i].from - from;
11293
11294 if (d == 0)
11295 {
11296 entries[i].to = to;
11297 return;
11298 }
11299 if (d < 0)
11300 a = i + 1;
11301 else
11302 b = i;
11303 }
11304
11305 if (ga_grow(&langmap_mapga, 1) != OK)
11306 return; /* out of memory */
11307
11308 /* insert new entry at position "a" */
11309 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11310 mch_memmove(entries + 1, entries,
11311 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11312 ++langmap_mapga.ga_len;
11313 entries[0].from = from;
11314 entries[0].to = to;
11315}
11316
11317/*
11318 * Apply 'langmap' to multi-byte character "c" and return the result.
11319 */
11320 int
11321langmap_adjust_mb(c)
11322 int c;
11323{
11324 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11325 int a = 0;
11326 int b = langmap_mapga.ga_len;
11327
11328 while (a != b)
11329 {
11330 int i = (a + b) / 2;
11331 int d = entries[i].from - c;
11332
11333 if (d == 0)
11334 return entries[i].to; /* found matching entry */
11335 if (d < 0)
11336 a = i + 1;
11337 else
11338 b = i;
11339 }
11340 return c; /* no entry found, return "c" unmodified */
11341}
11342# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011343
11344 static void
11345langmap_init()
11346{
11347 int i;
11348
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011349 for (i = 0; i < 256; i++)
11350 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11351# ifdef FEAT_MBYTE
11352 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11353# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011354}
11355
11356/*
11357 * Called when langmap option is set; the language map can be
11358 * changed at any time!
11359 */
11360 static void
11361langmap_set()
11362{
11363 char_u *p;
11364 char_u *p2;
11365 int from, to;
11366
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011367#ifdef FEAT_MBYTE
11368 ga_clear(&langmap_mapga); /* clear the previous map first */
11369#endif
11370 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371
11372 for (p = p_langmap; p[0] != NUL; )
11373 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011374 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11375 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376 {
11377 if (p2[0] == '\\' && p2[1] != NUL)
11378 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379 }
11380 if (p2[0] == ';')
11381 ++p2; /* abcd;ABCD form, p2 points to A */
11382 else
11383 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11384 while (p[0])
11385 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011386 if (p[0] == ',')
11387 {
11388 ++p;
11389 break;
11390 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391 if (p[0] == '\\' && p[1] != NUL)
11392 ++p;
11393#ifdef FEAT_MBYTE
11394 from = (*mb_ptr2char)(p);
11395#else
11396 from = p[0];
11397#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011398 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011399 if (p2 == NULL)
11400 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011401 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011402 if (p[0] != ',')
11403 {
11404 if (p[0] == '\\')
11405 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011406#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011407 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011409 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011411 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011412 }
11413 else
11414 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011415 if (p2[0] != ',')
11416 {
11417 if (p2[0] == '\\')
11418 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011420 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011421#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011422 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011423#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011424 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011425 }
11426 if (to == NUL)
11427 {
11428 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11429 transchar(from));
11430 return;
11431 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011432
11433#ifdef FEAT_MBYTE
11434 if (from >= 256)
11435 langmap_set_entry(from, to);
11436 else
11437#endif
11438 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011439
11440 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011441 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011442 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011443 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011444 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011445 if (*p == ';')
11446 {
11447 p = p2;
11448 if (p[0] != NUL)
11449 {
11450 if (p[0] != ',')
11451 {
11452 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11453 return;
11454 }
11455 ++p;
11456 }
11457 break;
11458 }
11459 }
11460 }
11461 }
11462}
11463#endif
11464
11465/*
11466 * Return TRUE if format option 'x' is in effect.
11467 * Take care of no formatting when 'paste' is set.
11468 */
11469 int
11470has_format_option(x)
11471 int x;
11472{
11473 if (p_paste)
11474 return FALSE;
11475 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11476}
11477
11478/*
11479 * Return TRUE if "x" is present in 'shortmess' option, or
11480 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11481 */
11482 int
11483shortmess(x)
11484 int x;
11485{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011486 return p_shm != NULL &&
11487 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488 || (vim_strchr(p_shm, 'a') != NULL
11489 && vim_strchr((char_u *)SHM_A, x) != NULL));
11490}
11491
11492/*
11493 * paste_option_changed() - Called after p_paste was set or reset.
11494 */
11495 static void
11496paste_option_changed()
11497{
11498 static int old_p_paste = FALSE;
11499 static int save_sm = 0;
11500#ifdef FEAT_CMDL_INFO
11501 static int save_ru = 0;
11502#endif
11503#ifdef FEAT_RIGHTLEFT
11504 static int save_ri = 0;
11505 static int save_hkmap = 0;
11506#endif
11507 buf_T *buf;
11508
11509 if (p_paste)
11510 {
11511 /*
11512 * Paste switched from off to on.
11513 * Save the current values, so they can be restored later.
11514 */
11515 if (!old_p_paste)
11516 {
11517 /* save options for each buffer */
11518 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11519 {
11520 buf->b_p_tw_nopaste = buf->b_p_tw;
11521 buf->b_p_wm_nopaste = buf->b_p_wm;
11522 buf->b_p_sts_nopaste = buf->b_p_sts;
11523 buf->b_p_ai_nopaste = buf->b_p_ai;
11524 }
11525
11526 /* save global options */
11527 save_sm = p_sm;
11528#ifdef FEAT_CMDL_INFO
11529 save_ru = p_ru;
11530#endif
11531#ifdef FEAT_RIGHTLEFT
11532 save_ri = p_ri;
11533 save_hkmap = p_hkmap;
11534#endif
11535 /* save global values for local buffer options */
11536 p_tw_nopaste = p_tw;
11537 p_wm_nopaste = p_wm;
11538 p_sts_nopaste = p_sts;
11539 p_ai_nopaste = p_ai;
11540 }
11541
11542 /*
11543 * Always set the option values, also when 'paste' is set when it is
11544 * already on.
11545 */
11546 /* set options for each buffer */
11547 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11548 {
11549 buf->b_p_tw = 0; /* textwidth is 0 */
11550 buf->b_p_wm = 0; /* wrapmargin is 0 */
11551 buf->b_p_sts = 0; /* softtabstop is 0 */
11552 buf->b_p_ai = 0; /* no auto-indent */
11553 }
11554
11555 /* set global options */
11556 p_sm = 0; /* no showmatch */
11557#ifdef FEAT_CMDL_INFO
11558# ifdef FEAT_WINDOWS
11559 if (p_ru)
11560 status_redraw_all(); /* redraw to remove the ruler */
11561# endif
11562 p_ru = 0; /* no ruler */
11563#endif
11564#ifdef FEAT_RIGHTLEFT
11565 p_ri = 0; /* no reverse insert */
11566 p_hkmap = 0; /* no Hebrew keyboard */
11567#endif
11568 /* set global values for local buffer options */
11569 p_tw = 0;
11570 p_wm = 0;
11571 p_sts = 0;
11572 p_ai = 0;
11573 }
11574
11575 /*
11576 * Paste switched from on to off: Restore saved values.
11577 */
11578 else if (old_p_paste)
11579 {
11580 /* restore options for each buffer */
11581 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11582 {
11583 buf->b_p_tw = buf->b_p_tw_nopaste;
11584 buf->b_p_wm = buf->b_p_wm_nopaste;
11585 buf->b_p_sts = buf->b_p_sts_nopaste;
11586 buf->b_p_ai = buf->b_p_ai_nopaste;
11587 }
11588
11589 /* restore global options */
11590 p_sm = save_sm;
11591#ifdef FEAT_CMDL_INFO
11592# ifdef FEAT_WINDOWS
11593 if (p_ru != save_ru)
11594 status_redraw_all(); /* redraw to draw the ruler */
11595# endif
11596 p_ru = save_ru;
11597#endif
11598#ifdef FEAT_RIGHTLEFT
11599 p_ri = save_ri;
11600 p_hkmap = save_hkmap;
11601#endif
11602 /* set global values for local buffer options */
11603 p_tw = p_tw_nopaste;
11604 p_wm = p_wm_nopaste;
11605 p_sts = p_sts_nopaste;
11606 p_ai = p_ai_nopaste;
11607 }
11608
11609 old_p_paste = p_paste;
11610}
11611
11612/*
11613 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11614 *
11615 * Reset 'compatible' and set the values for options that didn't get set yet
11616 * to the Vim defaults.
11617 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011618 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011619 */
11620 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011621vimrc_found(fname, envname)
11622 char_u *fname;
11623 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011624{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011625 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011626 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011627 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628
11629 if (!option_was_set((char_u *)"cp"))
11630 {
11631 p_cp = FALSE;
11632 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11633 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11634 set_option_default(opt_idx, OPT_FREE, FALSE);
11635 didset_options();
11636 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011637
11638 if (fname != NULL)
11639 {
11640 p = vim_getenv(envname, &dofree);
11641 if (p == NULL)
11642 {
11643 /* Set $MYVIMRC to the first vimrc file found. */
11644 p = FullName_save(fname, FALSE);
11645 if (p != NULL)
11646 {
11647 vim_setenv(envname, p);
11648 vim_free(p);
11649 }
11650 }
11651 else if (dofree)
11652 vim_free(p);
11653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011654}
11655
11656/*
11657 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11658 */
11659 void
11660change_compatible(on)
11661 int on;
11662{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011663 int opt_idx;
11664
Bram Moolenaar071d4272004-06-13 20:20:40 +000011665 if (p_cp != on)
11666 {
11667 p_cp = on;
11668 compatible_set();
11669 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011670 opt_idx = findoption((char_u *)"cp");
11671 if (opt_idx >= 0)
11672 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673}
11674
11675/*
11676 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011677 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011678 */
11679 int
11680option_was_set(name)
11681 char_u *name;
11682{
11683 int idx;
11684
11685 idx = findoption(name);
11686 if (idx < 0) /* unknown option */
11687 return FALSE;
11688 if (options[idx].flags & P_WAS_SET)
11689 return TRUE;
11690 return FALSE;
11691}
11692
11693/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011694 * Reset the flag indicating option "name" was set.
11695 */
11696 void
11697reset_option_was_set(name)
11698 char_u *name;
11699{
11700 int idx = findoption(name);
11701
11702 if (idx >= 0)
11703 options[idx].flags &= ~P_WAS_SET;
11704}
11705
11706/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011707 * compatible_set() - Called when 'compatible' has been set or unset.
11708 *
11709 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11710 * flag) to a Vi compatible value.
11711 * When 'compatible' is unset: Set all options that have a different default
11712 * for Vim (without the P_VI_DEF flag) to that default.
11713 */
11714 static void
11715compatible_set()
11716{
11717 int opt_idx;
11718
11719 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11720 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11721 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11722 set_option_default(opt_idx, OPT_FREE, p_cp);
11723 didset_options();
11724}
11725
11726#ifdef FEAT_LINEBREAK
11727
11728# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11729 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011730 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731# endif
11732
11733/*
11734 * fill_breakat_flags() -- called when 'breakat' changes value.
11735 */
11736 static void
11737fill_breakat_flags()
11738{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011739 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011740 int i;
11741
11742 for (i = 0; i < 256; i++)
11743 breakat_flags[i] = FALSE;
11744
11745 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011746 for (p = p_breakat; *p; p++)
11747 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011748}
11749
11750# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011751 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752# endif
11753
11754#endif
11755
11756/*
11757 * Check an option that can be a range of string values.
11758 *
11759 * Return OK for correct value, FAIL otherwise.
11760 * Empty is always OK.
11761 */
11762 static int
11763check_opt_strings(val, values, list)
11764 char_u *val;
11765 char **values;
11766 int list; /* when TRUE: accept a list of values */
11767{
11768 return opt_strings_flags(val, values, NULL, list);
11769}
11770
11771/*
11772 * Handle an option that can be a range of string values.
11773 * Set a flag in "*flagp" for each string present.
11774 *
11775 * Return OK for correct value, FAIL otherwise.
11776 * Empty is always OK.
11777 */
11778 static int
11779opt_strings_flags(val, values, flagp, list)
11780 char_u *val; /* new value */
11781 char **values; /* array of valid string values */
11782 unsigned *flagp;
11783 int list; /* when TRUE: accept a list of values */
11784{
11785 int i;
11786 int len;
11787 unsigned new_flags = 0;
11788
11789 while (*val)
11790 {
11791 for (i = 0; ; ++i)
11792 {
11793 if (values[i] == NULL) /* val not found in values[] */
11794 return FAIL;
11795
11796 len = (int)STRLEN(values[i]);
11797 if (STRNCMP(values[i], val, len) == 0
11798 && ((list && val[len] == ',') || val[len] == NUL))
11799 {
11800 val += len + (val[len] == ',');
11801 new_flags |= (1 << i);
11802 break; /* check next item in val list */
11803 }
11804 }
11805 }
11806 if (flagp != NULL)
11807 *flagp = new_flags;
11808
11809 return OK;
11810}
11811
11812/*
11813 * Read the 'wildmode' option, fill wim_flags[].
11814 */
11815 static int
11816check_opt_wim()
11817{
11818 char_u new_wim_flags[4];
11819 char_u *p;
11820 int i;
11821 int idx = 0;
11822
11823 for (i = 0; i < 4; ++i)
11824 new_wim_flags[i] = 0;
11825
11826 for (p = p_wim; *p; ++p)
11827 {
11828 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11829 ;
11830 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11831 return FAIL;
11832 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11833 new_wim_flags[idx] |= WIM_LONGEST;
11834 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11835 new_wim_flags[idx] |= WIM_FULL;
11836 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11837 new_wim_flags[idx] |= WIM_LIST;
11838 else
11839 return FAIL;
11840 p += i;
11841 if (*p == NUL)
11842 break;
11843 if (*p == ',')
11844 {
11845 if (idx == 3)
11846 return FAIL;
11847 ++idx;
11848 }
11849 }
11850
11851 /* fill remaining entries with last flag */
11852 while (idx < 3)
11853 {
11854 new_wim_flags[idx + 1] = new_wim_flags[idx];
11855 ++idx;
11856 }
11857
11858 /* only when there are no errors, wim_flags[] is changed */
11859 for (i = 0; i < 4; ++i)
11860 wim_flags[i] = new_wim_flags[i];
11861 return OK;
11862}
11863
11864/*
11865 * Check if backspacing over something is allowed.
11866 */
11867 int
11868can_bs(what)
11869 int what; /* BS_INDENT, BS_EOL or BS_START */
11870{
11871 switch (*p_bs)
11872 {
11873 case '2': return TRUE;
11874 case '1': return (what != BS_START);
11875 case '0': return FALSE;
11876 }
11877 return vim_strchr(p_bs, what) != NULL;
11878}
11879
11880/*
11881 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11882 * the file must be considered changed when the value is different.
11883 */
11884 void
11885save_file_ff(buf)
11886 buf_T *buf;
11887{
11888 buf->b_start_ffc = *buf->b_p_ff;
11889 buf->b_start_eol = buf->b_p_eol;
11890#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011891 buf->b_start_bomb = buf->b_p_bomb;
11892
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893 /* Only use free/alloc when necessary, they take time. */
11894 if (buf->b_start_fenc == NULL
11895 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11896 {
11897 vim_free(buf->b_start_fenc);
11898 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11899 }
11900#endif
11901}
11902
11903/*
11904 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11905 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011906 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11907 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011908 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011909 * When "ignore_empty" is true don't consider a new, empty buffer to be
11910 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011911 */
11912 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011913file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011915 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011916{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011917 /* In a buffer that was never loaded the options are not valid. */
11918 if (buf->b_flags & BF_NEVERLOADED)
11919 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011920 if (ignore_empty
11921 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922 && buf->b_ml.ml_line_count == 1
11923 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11924 return FALSE;
11925 if (buf->b_start_ffc != *buf->b_p_ff)
11926 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011927 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011928 return TRUE;
11929#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011930 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11931 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932 if (buf->b_start_fenc == NULL)
11933 return (*buf->b_p_fenc != NUL);
11934 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11935#else
11936 return FALSE;
11937#endif
11938}
11939
11940/*
11941 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11942 */
11943 int
11944check_ff_value(p)
11945 char_u *p;
11946{
11947 return check_opt_strings(p, p_ff_values, FALSE);
11948}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011949
11950/*
11951 * Return the effective shiftwidth value for current buffer, using the
11952 * 'tabstop' value when 'shiftwidth' is zero.
11953 */
11954 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011955get_sw_value(buf)
11956 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011957{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011958 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011959}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011960
11961/*
11962 * Return the effective softtabstop value for the current buffer, using the
11963 * 'tabstop' value when 'softtabstop' is negative.
11964 */
11965 long
11966get_sts_value()
11967{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011968 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011969}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011970
11971/*
11972 * Check matchpairs option for "*initc".
11973 * If there is a match set "*initc" to the matching character and "*findc" to
11974 * the opposite character. Set "*backwards" to the direction.
11975 * When "switchit" is TRUE swap the direction.
11976 */
11977 void
11978find_mps_values(initc, findc, backwards, switchit)
11979 int *initc;
11980 int *findc;
11981 int *backwards;
11982 int switchit;
11983{
11984 char_u *ptr;
11985
11986 ptr = curbuf->b_p_mps;
11987 while (*ptr != NUL)
11988 {
11989#ifdef FEAT_MBYTE
11990 if (has_mbyte)
11991 {
11992 char_u *prev;
11993
11994 if (mb_ptr2char(ptr) == *initc)
11995 {
11996 if (switchit)
11997 {
11998 *findc = *initc;
11999 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12000 *backwards = TRUE;
12001 }
12002 else
12003 {
12004 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12005 *backwards = FALSE;
12006 }
12007 return;
12008 }
12009 prev = ptr;
12010 ptr += mb_ptr2len(ptr) + 1;
12011 if (mb_ptr2char(ptr) == *initc)
12012 {
12013 if (switchit)
12014 {
12015 *findc = *initc;
12016 *initc = mb_ptr2char(prev);
12017 *backwards = FALSE;
12018 }
12019 else
12020 {
12021 *findc = mb_ptr2char(prev);
12022 *backwards = TRUE;
12023 }
12024 return;
12025 }
12026 ptr += mb_ptr2len(ptr);
12027 }
12028 else
12029#endif
12030 {
12031 if (*ptr == *initc)
12032 {
12033 if (switchit)
12034 {
12035 *backwards = TRUE;
12036 *findc = *initc;
12037 *initc = ptr[2];
12038 }
12039 else
12040 {
12041 *backwards = FALSE;
12042 *findc = ptr[2];
12043 }
12044 return;
12045 }
12046 ptr += 2;
12047 if (*ptr == *initc)
12048 {
12049 if (switchit)
12050 {
12051 *backwards = FALSE;
12052 *findc = *initc;
12053 *initc = ptr[-2];
12054 }
12055 else
12056 {
12057 *backwards = TRUE;
12058 *findc = ptr[-2];
12059 }
12060 return;
12061 }
12062 ++ptr;
12063 }
12064 if (*ptr == ',')
12065 ++ptr;
12066 }
12067}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012068
12069#if defined(FEAT_LINEBREAK) || defined(PROTO)
12070/*
12071 * This is called when 'breakindentopt' is changed and when a window is
12072 * initialized.
12073 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012074 static int
12075briopt_check(wp)
12076 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012077{
12078 char_u *p;
12079 int bri_shift = 0;
12080 long bri_min = 20;
12081 int bri_sbr = FALSE;
12082
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012083 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012084 while (*p != NUL)
12085 {
12086 if (STRNCMP(p, "shift:", 6) == 0
12087 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12088 {
12089 p += 6;
12090 bri_shift = getdigits(&p);
12091 }
12092 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12093 {
12094 p += 4;
12095 bri_min = getdigits(&p);
12096 }
12097 else if (STRNCMP(p, "sbr", 3) == 0)
12098 {
12099 p += 3;
12100 bri_sbr = TRUE;
12101 }
12102 if (*p != ',' && *p != NUL)
12103 return FAIL;
12104 if (*p == ',')
12105 ++p;
12106 }
12107
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012108 wp->w_p_brishift = bri_shift;
12109 wp->w_p_brimin = bri_min;
12110 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012111
12112 return OK;
12113}
12114#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012115
12116/*
12117 * Get the local or global value of 'backupcopy'.
12118 */
12119 unsigned int
12120get_bkc_value(buf)
12121 buf_T *buf;
12122{
12123 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12124}