blob: f78d48d2a2b8e9364bc12fe4d46e7f20bde2155b [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
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.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * 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 Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
225#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#ifdef FEAT_WINDOWS
249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200260#ifdef FEAT_SIGNS
261# define PV_SCL OPT_WIN(WV_SCL)
262#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000263
264/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265typedef enum
266{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000267 PV_NONE = 0,
268 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269} idopt_T;
270
271/*
272 * Options local to a window have a value local to a buffer and global to all
273 * buffers. Indicate this by setting "var" to VAR_WIN.
274 */
275#define VAR_WIN ((char_u *)-1)
276
277/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000278 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279 * Only to be used in option.c!
280 */
281static int p_ai;
282static int p_bin;
283#ifdef FEAT_MBYTE
284static int p_bomb;
285#endif
286#if defined(FEAT_QUICKFIX)
287static char_u *p_bh;
288static char_u *p_bt;
289#endif
290static int p_bl;
291static int p_ci;
292#ifdef FEAT_CINDENT
293static int p_cin;
294static char_u *p_cink;
295static char_u *p_cino;
296#endif
297#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298static char_u *p_cinw;
299#endif
300#ifdef FEAT_COMMENTS
301static char_u *p_com;
302#endif
303#ifdef FEAT_FOLDING
304static char_u *p_cms;
305#endif
306#ifdef FEAT_INS_EXPAND
307static char_u *p_cpt;
308#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#ifdef FEAT_COMPL_FUNC
310static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000311static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
316#ifdef FEAT_MBYTE
317static char_u *p_fenc;
318#endif
319static char_u *p_ff;
320static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000321static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322#ifdef FEAT_AUTOCMD
323static char_u *p_ft;
324#endif
325static long p_iminsert;
326static long p_imsearch;
327#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328static char_u *p_inex;
329#endif
330#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331static char_u *p_inde;
332static char_u *p_indk;
333#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000334#if defined(FEAT_EVAL)
335static char_u *p_fex;
336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_inf;
338static char_u *p_isk;
339#ifdef FEAT_CRYPT
340static char_u *p_key;
341#endif
342#ifdef FEAT_LISP
343static int p_lisp;
344#endif
345static int p_ml;
346static int p_ma;
347static int p_mod;
348static char_u *p_mps;
349static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000351#ifdef FEAT_TEXTOBJ
352static char_u *p_qe;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_ro;
355#ifdef FEAT_SMARTINDENT
356static int p_si;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static long p_sts;
360#if defined(FEAT_SEARCHPATH)
361static char_u *p_sua;
362#endif
363static long p_sw;
364static int p_swf;
365#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000366static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000368#endif
369#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000370static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000371static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000372static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#endif
374static long p_ts;
375static long p_tw;
376static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200377#ifdef FEAT_PERSISTENT_UNDO
378static int p_udf;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380static long p_wm;
381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
400 char *fullname; /* full option name */
401 char *shortname; /* permissible abbreviation */
402 long_u flags; /* see below */
403 char_u *var; /* global option: pointer to variable;
404 * window-local option: VAR_WIN;
405 * buffer-local option: global value */
406 idopt_T indir; /* global option: PV_NONE;
407 * local option: indirect option index */
408 char_u *def_val[2]; /* default values for variable (vi and vim) */
409#ifdef FEAT_EVAL
410 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411# define SCRIPTID_INIT , 0
412#else
413# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100476/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000477#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100478 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200479 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar58b85342016-08-14 19:54:54 +0200480# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@: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 +0000481#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100482# 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 +0000483#endif
484
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100485/* Default python version for pyx* commands */
486#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
487# define DEFAULT_PYTHON_VER 0
488#elif defined(FEAT_PYTHON3)
489# define DEFAULT_PYTHON_VER 3
490#elif defined(FEAT_PYTHON)
491# define DEFAULT_PYTHON_VER 2
492#else
493# define DEFAULT_PYTHON_VER 0
494#endif
495
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496/*
497 * options[] is initialized here.
498 * The order of the options MUST be alphabetic for ":set all" and findoption().
499 * All option names MUST start with a lowercase letter (for findoption()).
500 * Exception: "t_" options are at the end.
501 * The options with a NULL variable are 'hidden': a set command for them is
502 * ignored and they are not printed.
503 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100504static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200506 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507#ifdef FEAT_RIGHTLEFT
508 (char_u *)&p_aleph, PV_NONE,
509#else
510 (char_u *)NULL, PV_NONE,
511#endif
512 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100513#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)128L,
515#else
516 (char_u *)224L,
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
520#if defined(FEAT_GUI) && defined(MACOS_X)
521 (char_u *)&p_antialias, PV_NONE,
522 {(char_u *)FALSE, (char_u *)FALSE}
523#else
524 (char_u *)NULL, PV_NONE,
525 {(char_u *)FALSE, (char_u *)FALSE}
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200528 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529#ifdef FEAT_ARABIC
530 (char_u *)VAR_WIN, PV_ARAB,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
536#ifdef FEAT_ARABIC
537 (char_u *)&p_arshape, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
543#ifdef FEAT_RIGHTLEFT
544 (char_u *)&p_ari, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
550#ifdef FEAT_FKMAP
551 (char_u *)&p_altkeymap, PV_NONE,
552#else
553 (char_u *)NULL, PV_NONE,
554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
557#if defined(FEAT_MBYTE)
558 (char_u *)&p_ambw, PV_NONE,
559 {(char_u *)"single", (char_u *)0L}
560#else
561 (char_u *)NULL, PV_NONE,
562 {(char_u *)0L, (char_u *)0L}
563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100568 {(char_u *)FALSE, (char_u *)0L}
569#else
570 (char_u *)NULL, PV_NONE,
571 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100573 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autoindent", "ai", P_BOOL|P_VI_DEF,
575 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autoprint", "ap", P_BOOL|P_VI_DEF,
578 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000581 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"autowrite", "aw", P_BOOL|P_VI_DEF,
584 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"autowriteall","awa", P_BOOL|P_VI_DEF,
587 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
590 (char_u *)&p_bg, PV_NONE,
591 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100592#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)"dark",
594#else
595 (char_u *)"light",
596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200598 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
602 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200604 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200605 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606#ifdef UNIX
607 {(char_u *)"yes", (char_u *)"auto"}
608#else
609 {(char_u *)"auto", (char_u *)"auto"}
610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200612 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
613 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000616 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 (char_u *)&p_bex, PV_NONE,
618 {
619#ifdef VMS
620 (char_u *)"_",
621#else
622 (char_u *)"~",
623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200625 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#ifdef FEAT_WILDIGN
627 (char_u *)&p_bsk, PV_NONE,
628 {(char_u *)"", (char_u *)0L}
629#else
630 (char_u *)NULL, PV_NONE,
631 {(char_u *)0L, (char_u *)0L}
632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000633 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100637 {(char_u *)600L, (char_u *)0L}
638#else
639 (char_u *)NULL, PV_NONE,
640 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100642 SCRIPTID_INIT},
643 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
644#ifdef FEAT_BEVAL
645 (char_u *)&p_beval, PV_NONE,
646 {(char_u *)FALSE, (char_u *)0L}
647#else
648 (char_u *)NULL, PV_NONE,
649 {(char_u *)0L, (char_u *)0L}
650#endif
651 SCRIPTID_INIT},
652 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
653#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
654 (char_u *)&p_bexpr, PV_BEXPR,
655 {(char_u *)"", (char_u *)0L}
656#else
657 (char_u *)NULL, PV_NONE,
658 {(char_u *)0L, (char_u *)0L}
659#endif
660 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"beautify", "bf", P_BOOL|P_VI_DEF,
662 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000663 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200664 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
665 (char_u *)&p_bo, PV_NONE,
666 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
668 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000669 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
674#ifdef FEAT_MBYTE
675 (char_u *)&p_bomb, PV_BOMB,
676#else
677 (char_u *)NULL, PV_NONE,
678#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000679 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
681#ifdef FEAT_LINEBREAK
682 (char_u *)&p_breakat, PV_NONE,
683 {(char_u *)" \t!@*-+;:,./?", (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 Moolenaar597a4222014-06-25 14:39:50 +0200689 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
690#ifdef FEAT_LINEBREAK
691 (char_u *)VAR_WIN, PV_BRI,
692 {(char_u *)FALSE, (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
697 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200698 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
699 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200700#ifdef FEAT_LINEBREAK
701 (char_u *)VAR_WIN, PV_BRIOPT,
702 {(char_u *)"", (char_u *)NULL}
703#else
704 (char_u *)NULL, PV_NONE,
705 {(char_u *)"", (char_u *)NULL}
706#endif
707 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
709#ifdef FEAT_BROWSE
710 (char_u *)&p_bsdir, PV_NONE,
711 {(char_u *)"last", (char_u *)0L}
712#else
713 (char_u *)NULL, PV_NONE,
714 {(char_u *)0L, (char_u *)0L}
715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000716 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
718#if defined(FEAT_QUICKFIX)
719 (char_u *)&p_bh, PV_BH,
720 {(char_u *)"", (char_u *)0L}
721#else
722 (char_u *)NULL, PV_NONE,
723 {(char_u *)0L, (char_u *)0L}
724#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000725 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
727 (char_u *)&p_bl, PV_BL,
728 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
731#if defined(FEAT_QUICKFIX)
732 (char_u *)&p_bt, PV_BT,
733 {(char_u *)"", (char_u *)0L}
734#else
735 (char_u *)NULL, PV_NONE,
736 {(char_u *)0L, (char_u *)0L}
737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000738 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200739 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000740#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 (char_u *)&p_cmp, PV_NONE,
742 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000743#else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
749#ifdef FEAT_SEARCHPATH
750 (char_u *)&p_cdpath, PV_NONE,
751 {(char_u *)",,", (char_u *)0L}
752#else
753 (char_u *)NULL, PV_NONE,
754 {(char_u *)0L, (char_u *)0L}
755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 {"cedit", NULL, P_STRING,
758#ifdef FEAT_CMDWIN
759 (char_u *)&p_cedit, PV_NONE,
760 {(char_u *)"", (char_u *)CTRL_F_STR}
761#else
762 (char_u *)NULL, PV_NONE,
763 {(char_u *)0L, (char_u *)0L}
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
767#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
768 (char_u *)&p_ccv, PV_NONE,
769 {(char_u *)"", (char_u *)0L}
770#else
771 (char_u *)NULL, PV_NONE,
772 {(char_u *)0L, (char_u *)0L}
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
776#ifdef FEAT_CINDENT
777 (char_u *)&p_cin, PV_CIN,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000781 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200782 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783#ifdef FEAT_CINDENT
784 (char_u *)&p_cink, PV_CINK,
785 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#ifdef FEAT_CINDENT
793 (char_u *)&p_cino, PV_CINO,
794#else
795 (char_u *)NULL, PV_NONE,
796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200798 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000799#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
800 (char_u *)&p_cinw, PV_CINW,
801 {(char_u *)"if,else,while,do,for,switch",
802 (char_u *)0L}
803#else
804 (char_u *)NULL, PV_NONE,
805 {(char_u *)0L, (char_u *)0L}
806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200808 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809#ifdef FEAT_CLIPBOARD
810 (char_u *)&p_cb, PV_NONE,
811# ifdef FEAT_XCLIPBOARD
812 {(char_u *)"autoselect,exclude:cons\\|linux",
813 (char_u *)0L}
814# else
815 {(char_u *)"", (char_u *)0L}
816# endif
817#else
818 (char_u *)NULL, PV_NONE,
819 {(char_u *)"", (char_u *)0L}
820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000821 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
823 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000825 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
826#ifdef FEAT_CMDWIN
827 (char_u *)&p_cwh, PV_NONE,
828#else
829 (char_u *)NULL, PV_NONE,
830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200832 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200833#ifdef FEAT_SYN_HL
834 (char_u *)VAR_WIN, PV_CC,
835#else
836 (char_u *)NULL, PV_NONE,
837#endif
838 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
840 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000841 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200842 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
843 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844#ifdef FEAT_COMMENTS
845 (char_u *)&p_com, PV_COM,
846 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
847 (char_u *)0L}
848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200853 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000854#ifdef FEAT_FOLDING
855 (char_u *)&p_cms, PV_CMS,
856 {(char_u *)"/*%s*/", (char_u *)0L}
857#else
858 (char_u *)NULL, PV_NONE,
859 {(char_u *)0L, (char_u *)0L}
860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000861 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000862 /* P_PRI_MKRC isn't needed here, optval_default()
863 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000864 {"compatible", "cp", P_BOOL|P_RALL,
865 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200867 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868#ifdef FEAT_INS_EXPAND
869 (char_u *)&p_cpt, PV_CPT,
870 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
871#else
872 (char_u *)NULL, PV_NONE,
873 {(char_u *)0L, (char_u *)0L}
874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000875 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200876 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200877#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200878 (char_u *)VAR_WIN, PV_COCU,
879 {(char_u *)"", (char_u *)NULL}
880#else
881 (char_u *)NULL, PV_NONE,
882 {(char_u *)NULL, (char_u *)0L}
883#endif
884 SCRIPTID_INIT},
885 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
886#ifdef FEAT_CONCEAL
887 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200888#else
889 (char_u *)NULL, PV_NONE,
890#endif
891 {(char_u *)0L, (char_u *)0L}
892 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000893 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
894#ifdef FEAT_COMPL_FUNC
895 (char_u *)&p_cfu, PV_CFU,
896 {(char_u *)"", (char_u *)0L}
897#else
898 (char_u *)NULL, PV_NONE,
899 {(char_u *)0L, (char_u *)0L}
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200902 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000903#ifdef FEAT_INS_EXPAND
904 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000905 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000906#else
907 (char_u *)NULL, PV_NONE,
908 {(char_u *)0L, (char_u *)0L}
909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"confirm", "cf", P_BOOL|P_VI_DEF,
912#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
913 (char_u *)&p_confirm, PV_NONE,
914#else
915 (char_u *)NULL, PV_NONE,
916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
922 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
925 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
927 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200930 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200931 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200932#else
933 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200934 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200935#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_cspc, PV_NONE,
940#else
941 (char_u *)NULL, PV_NONE,
942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000943 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_csprg, PV_NONE,
947 {(char_u *)"cscope", (char_u *)0L}
948#else
949 (char_u *)NULL, PV_NONE,
950 {(char_u *)0L, (char_u *)0L}
951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000952 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200953 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000954#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
955 (char_u *)&p_csqf, PV_NONE,
956 {(char_u *)"", (char_u *)0L}
957#else
958 (char_u *)NULL, PV_NONE,
959 {(char_u *)0L, (char_u *)0L}
960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000961 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200962 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
963#ifdef FEAT_CSCOPE
964 (char_u *)&p_csre, PV_NONE,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
968 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
970#ifdef FEAT_CSCOPE
971 (char_u *)&p_cst, PV_NONE,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
977#ifdef FEAT_CSCOPE
978 (char_u *)&p_csto, PV_NONE,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
984#ifdef FEAT_CSCOPE
985 (char_u *)&p_csverbose, PV_NONE,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200990 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
991#ifdef FEAT_CURSORBIND
992 (char_u *)VAR_WIN, PV_CRBIND,
993#else
994 (char_u *)NULL, PV_NONE,
995#endif
996 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
998#ifdef FEAT_SYN_HL
999 (char_u *)VAR_WIN, PV_CUC,
1000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +01001004 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001005#ifdef FEAT_SYN_HL
1006 (char_u *)VAR_WIN, PV_CUL,
1007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 {"debug", NULL, P_STRING|P_VI_DEF,
1012 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001014 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001016 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001017 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018#else
1019 (char_u *)NULL, PV_NONE,
1020 {(char_u *)NULL, (char_u *)0L}
1021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001022 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1024#ifdef FEAT_MBYTE
1025 (char_u *)&p_deco, PV_NONE,
1026#else
1027 (char_u *)NULL, PV_NONE,
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001030 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001032 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1038#ifdef FEAT_DIFF
1039 (char_u *)VAR_WIN, PV_DIFF,
1040#else
1041 (char_u *)NULL, PV_NONE,
1042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001044 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1046 (char_u *)&p_dex, PV_NONE,
1047 {(char_u *)"", (char_u *)0L}
1048#else
1049 (char_u *)NULL, PV_NONE,
1050 {(char_u *)0L, (char_u *)0L}
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1054 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055#ifdef FEAT_DIFF
1056 (char_u *)&p_dip, PV_NONE,
1057 {(char_u *)"filler", (char_u *)NULL}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)"", (char_u *)NULL}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1064#ifdef FEAT_DIGRAPHS
1065 (char_u *)&p_dg, PV_NONE,
1066#else
1067 (char_u *)NULL, PV_NONE,
1068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001070 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1071 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001074 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001078#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 (char_u *)&p_ead, PV_NONE,
1080 {(char_u *)"both", (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)NULL, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1087 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001089 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1090#if defined(FEAT_MBYTE)
1091 (char_u *)&p_emoji, PV_NONE,
1092 {(char_u *)TRUE, (char_u *)0L}
1093#else
1094 (char_u *)NULL, PV_NONE,
1095 {(char_u *)0L, (char_u *)0L}
1096#endif
1097 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001098 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099#ifdef FEAT_MBYTE
1100 (char_u *)&p_enc, PV_NONE,
1101 {(char_u *)ENC_DFLT, (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)0L, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1108 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1111 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001114 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1117 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1120#ifdef FEAT_QUICKFIX
1121 (char_u *)&p_ef, PV_NONE,
1122 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)NULL, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001130 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132#else
1133 (char_u *)NULL, PV_NONE,
1134 {(char_u *)NULL, (char_u *)0L}
1135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"esckeys", "ek", P_BOOL|P_VIM,
1138 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141#ifdef FEAT_AUTOCMD
1142 (char_u *)&p_ei, PV_NONE,
1143#else
1144 (char_u *)NULL, PV_NONE,
1145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1148 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1151 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001153 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1154 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155#ifdef FEAT_MBYTE
1156 (char_u *)&p_fenc, PV_FENC,
1157 {(char_u *)"", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)0L, (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164#ifdef FEAT_MBYTE
1165 (char_u *)&p_fencs, PV_NONE,
1166 {(char_u *)"ucs-bom", (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)0L, (char_u *)0L}
1170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001172 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1173 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001174 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001176 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1179 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001180 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1181 (char_u *)&p_fic, PV_NONE,
1182 {
1183#ifdef CASE_INSENSITIVE_FILENAME
1184 (char_u *)TRUE,
1185#else
1186 (char_u *)FALSE,
1187#endif
1188 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001189 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190#ifdef FEAT_AUTOCMD
1191 (char_u *)&p_ft, PV_FT,
1192 {(char_u *)"", (char_u *)0L}
1193#else
1194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)0L, (char_u *)0L}
1196#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001198 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1200 (char_u *)&p_fcs, PV_NONE,
1201 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1202#else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)"", (char_u *)0L}
1205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001207 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1208 (char_u *)&p_fixeol, PV_FIXEOL,
1209 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1211#ifdef FEAT_FKMAP
1212 (char_u *)&p_fkmap, PV_NONE,
1213#else
1214 (char_u *)NULL, PV_NONE,
1215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"flash", "fl", P_BOOL|P_VI_DEF,
1218 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001220 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001223 {(char_u *)"", (char_u *)0L}
1224#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227#endif
1228 SCRIPTID_INIT},
1229 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1230#ifdef FEAT_FOLDING
1231 (char_u *)VAR_WIN, PV_FDC,
1232 {(char_u *)FALSE, (char_u *)0L}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
1237 SCRIPTID_INIT},
1238 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1239#ifdef FEAT_FOLDING
1240 (char_u *)VAR_WIN, PV_FEN,
1241 {(char_u *)TRUE, (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
1247 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1248#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1249 (char_u *)VAR_WIN, PV_FDE,
1250 {(char_u *)"0", (char_u *)NULL}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001259 {(char_u *)"#", (char_u *)NULL}
1260#else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)NULL, (char_u *)0L}
1263#endif
1264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001266#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001268 {(char_u *)0L, (char_u *)0L}
1269#else
1270 (char_u *)NULL, PV_NONE,
1271 {(char_u *)NULL, (char_u *)0L}
1272#endif
1273 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001274 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001275#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001277 {(char_u *)-1L, (char_u *)0L}
1278#else
1279 (char_u *)NULL, PV_NONE,
1280 {(char_u *)NULL, (char_u *)0L}
1281#endif
1282 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001284 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001285#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001288#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001292 SCRIPTID_INIT},
1293 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1294#ifdef FEAT_FOLDING
1295 (char_u *)VAR_WIN, PV_FDM,
1296 {(char_u *)"manual", (char_u *)NULL}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
1301 SCRIPTID_INIT},
1302 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1303#ifdef FEAT_FOLDING
1304 (char_u *)VAR_WIN, PV_FML,
1305 {(char_u *)1L, (char_u *)0L}
1306#else
1307 (char_u *)NULL, PV_NONE,
1308 {(char_u *)NULL, (char_u *)0L}
1309#endif
1310 SCRIPTID_INIT},
1311 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1312#ifdef FEAT_FOLDING
1313 (char_u *)VAR_WIN, PV_FDN,
1314 {(char_u *)20L, (char_u *)0L}
1315#else
1316 (char_u *)NULL, PV_NONE,
1317 {(char_u *)NULL, (char_u *)0L}
1318#endif
1319 SCRIPTID_INIT},
1320 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1321#ifdef FEAT_FOLDING
1322 (char_u *)&p_fdo, PV_NONE,
1323 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1324 (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)NULL, (char_u *)0L}
1328#endif
1329 SCRIPTID_INIT},
1330 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1331#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1332 (char_u *)VAR_WIN, PV_FDT,
1333 {(char_u *)"foldtext()", (char_u *)NULL}
1334#else
1335 (char_u *)NULL, PV_NONE,
1336 {(char_u *)NULL, (char_u *)0L}
1337#endif
1338 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001339 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001340#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001341 (char_u *)&p_fex, PV_FEX,
1342 {(char_u *)"", (char_u *)0L}
1343#else
1344 (char_u *)NULL, PV_NONE,
1345 {(char_u *)0L, (char_u *)0L}
1346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1349 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1351 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001352 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1353 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001354 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1355 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001357 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001358 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001359 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1360#ifdef HAVE_FSYNC
1361 (char_u *)&p_fs, PV_NONE,
1362 {(char_u *)TRUE, (char_u *)0L}
1363#else
1364 (char_u *)NULL, PV_NONE,
1365 {(char_u *)FALSE, (char_u *)0L}
1366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1369 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371 {"graphic", "gr", P_BOOL|P_VI_DEF,
1372 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001374 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375#ifdef FEAT_QUICKFIX
1376 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001377 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378#else
1379 (char_u *)NULL, PV_NONE,
1380 {(char_u *)NULL, (char_u *)0L}
1381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1384#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001385 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {
1387# ifdef WIN3264
1388 /* may be changed to "grep -n" in os_win32.c */
1389 (char_u *)"findstr /n",
1390# else
1391# ifdef UNIX
1392 /* Add an extra file name so that grep will always
1393 * insert a file name in the match line. */
1394 (char_u *)"grep -n $* /dev/null",
1395# else
1396# ifdef VMS
1397 (char_u *)"SEARCH/NUMBERS ",
1398# else
1399 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400# endif
1401# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#else
1405 (char_u *)NULL, PV_NONE,
1406 {(char_u *)NULL, (char_u *)0L}
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001409 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410#ifdef CURSOR_SHAPE
1411 (char_u *)&p_guicursor, PV_NONE,
1412 {
1413# ifdef FEAT_GUI
1414 (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",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001415# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1417# endif
1418 (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425#ifdef FEAT_GUI
1426 (char_u *)&p_guifont, PV_NONE,
1427 {(char_u *)"", (char_u *)0L}
1428#else
1429 (char_u *)NULL, PV_NONE,
1430 {(char_u *)NULL, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001433 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1435 (char_u *)&p_guifontset, PV_NONE,
1436 {(char_u *)"", (char_u *)0L}
1437#else
1438 (char_u *)NULL, PV_NONE,
1439 {(char_u *)NULL, (char_u *)0L}
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001442 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1444 (char_u *)&p_guifontwide, PV_NONE,
1445 {(char_u *)"", (char_u *)0L}
1446#else
1447 (char_u *)NULL, PV_NONE,
1448 {(char_u *)NULL, (char_u *)0L}
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001452#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 (char_u *)&p_ghr, PV_NONE,
1454#else
1455 (char_u *)NULL, PV_NONE,
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001459#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460 (char_u *)&p_go, PV_NONE,
1461# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001462 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001464 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465# endif
1466#else
1467 (char_u *)NULL, PV_NONE,
1468 {(char_u *)NULL, (char_u *)0L}
1469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"guipty", NULL, P_BOOL|P_VI_DEF,
1472#if defined(FEAT_GUI)
1473 (char_u *)&p_guipty, PV_NONE,
1474#else
1475 (char_u *)NULL, PV_NONE,
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001478 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001479#if defined(FEAT_GUI_TABLINE)
1480 (char_u *)&p_gtl, PV_NONE,
1481 {(char_u *)"", (char_u *)0L}
1482#else
1483 (char_u *)NULL, PV_NONE,
1484 {(char_u *)NULL, (char_u *)0L}
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001487 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001488#if defined(FEAT_GUI_TABLINE)
1489 (char_u *)&p_gtt, PV_NONE,
1490 {(char_u *)"", (char_u *)0L}
1491#else
1492 (char_u *)NULL, PV_NONE,
1493 {(char_u *)NULL, (char_u *)0L}
1494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1497 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001498 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1500 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001501 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1502 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"helpheight", "hh", P_NUM|P_VI_DEF,
1504#ifdef FEAT_WINDOWS
1505 (char_u *)&p_hh, PV_NONE,
1506#else
1507 (char_u *)NULL, PV_NONE,
1508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001509 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001510 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511#ifdef FEAT_MULTI_LANG
1512 (char_u *)&p_hlg, PV_NONE,
1513 {(char_u *)"", (char_u *)0L}
1514#else
1515 (char_u *)NULL, PV_NONE,
1516 {(char_u *)0L, (char_u *)0L}
1517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {"hidden", "hid", P_BOOL|P_VI_DEF,
1520 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001522 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001524 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1525 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001526 {"history", "hi", P_NUM|P_VIM,
1527 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001528 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1530#ifdef FEAT_RIGHTLEFT
1531 (char_u *)&p_hkmap, PV_NONE,
1532#else
1533 (char_u *)NULL, PV_NONE,
1534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1537#ifdef FEAT_RIGHTLEFT
1538 (char_u *)&p_hkmapp, PV_NONE,
1539#else
1540 (char_u *)NULL, PV_NONE,
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1544 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"icon", NULL, P_BOOL|P_VI_DEF,
1547#ifdef FEAT_TITLE
1548 (char_u *)&p_icon, PV_NONE,
1549#else
1550 (char_u *)NULL, PV_NONE,
1551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"iconstring", NULL, P_STRING|P_VI_DEF,
1554#ifdef FEAT_TITLE
1555 (char_u *)&p_iconstring, PV_NONE,
1556#else
1557 (char_u *)NULL, PV_NONE,
1558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001559 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001560 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1561 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001563 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1564# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1565 (char_u *)&p_imaf, PV_NONE,
1566 {(char_u *)"", (char_u *)NULL}
1567# else
1568 (char_u *)NULL, PV_NONE,
1569 {(char_u *)NULL, (char_u *)0L}
1570# endif
1571 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001573#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 (char_u *)&p_imak, PV_NONE,
1575#else
1576 (char_u *)NULL, PV_NONE,
1577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001578 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1580#ifdef USE_IM_CONTROL
1581 (char_u *)&p_imcmdline, PV_NONE,
1582#else
1583 (char_u *)NULL, PV_NONE,
1584#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001586 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1587#ifdef USE_IM_CONTROL
1588 (char_u *)&p_imdisable, PV_NONE,
1589#else
1590 (char_u *)NULL, PV_NONE,
1591#endif
1592#ifdef __sgi
1593 {(char_u *)TRUE, (char_u *)0L}
1594#else
1595 {(char_u *)FALSE, (char_u *)0L}
1596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"iminsert", "imi", P_NUM|P_VI_DEF,
1599 (char_u *)&p_iminsert, PV_IMI,
1600#ifdef B_IMODE_IM
1601 {(char_u *)B_IMODE_IM, (char_u *)0L}
1602#else
1603 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001605 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"imsearch", "ims", P_NUM|P_VI_DEF,
1607 (char_u *)&p_imsearch, PV_IMS,
1608#ifdef B_IMODE_IM
1609 {(char_u *)B_IMODE_IM, (char_u *)0L}
1610#else
1611 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001613 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001614 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001615# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1616 (char_u *)&p_imsf, PV_NONE,
1617 {(char_u *)"", (char_u *)NULL}
1618# else
1619 (char_u *)NULL, PV_NONE,
1620 {(char_u *)NULL, (char_u *)0L}
1621# endif
1622 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1624#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001625 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1633#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1634 (char_u *)&p_inex, PV_INEX,
1635 {(char_u *)"", (char_u *)0L}
1636#else
1637 (char_u *)NULL, PV_NONE,
1638 {(char_u *)0L, (char_u *)0L}
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1642 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1645#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1646 (char_u *)&p_inde, PV_INDE,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)0L, (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001653 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1655 (char_u *)&p_indk, PV_INDK,
1656 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1657#else
1658 (char_u *)NULL, PV_NONE,
1659 {(char_u *)0L, (char_u *)0L}
1660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 {"infercase", "inf", P_BOOL|P_VI_DEF,
1663 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1666 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1669 (char_u *)&p_isf, PV_NONE,
1670 {
1671#ifdef BACKSLASH_IN_FILENAME
1672 /* Excluded are: & and ^ are special in cmd.exe
1673 * ( and ) are used in text separating fnames */
1674 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1675#else
1676# ifdef AMIGA
1677 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1678# else
1679# ifdef VMS
1680 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1681# else /* UNIX et al. */
1682# ifdef EBCDIC
1683 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1684# else
1685 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1686# endif
1687# endif
1688# endif
1689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001690 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1692 (char_u *)&p_isi, PV_NONE,
1693 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001694#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695 (char_u *)"@,48-57,_,128-167,224-235",
1696#else
1697# ifdef EBCDIC
1698 /* TODO: EBCDIC Check this! @ == isalpha()*/
1699 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1700 "112-120,128,140-142,156,158,172,"
1701 "174,186,191,203-207,219-225,235-239,"
1702 "251-254",
1703# else
1704 (char_u *)"@,48-57,_,192-255",
1705# endif
1706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1709 (char_u *)&p_isk, PV_ISK,
1710 {
1711#ifdef EBCDIC
1712 (char_u *)"@,240-249,_",
1713 /* TODO: EBCDIC Check this! @ == isalpha()*/
1714 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1715 "112-120,128,140-142,156,158,172,"
1716 "174,186,191,203-207,219-225,235-239,"
1717 "251-254",
1718#else
1719 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001720# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721 (char_u *)"@,48-57,_,128-167,224-235"
1722# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001723 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724# endif
1725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1728 (char_u *)&p_isp, PV_NONE,
1729 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001730#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 || defined(VMS)
1732 (char_u *)"@,~-255",
1733#else
1734# ifdef EBCDIC
1735 /* all chars above 63 are printable */
1736 (char_u *)"63-255",
1737# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001738 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739# endif
1740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1743 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001744 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1746#ifdef FEAT_CRYPT
1747 (char_u *)&p_key, PV_KEY,
1748 {(char_u *)"", (char_u *)0L}
1749#else
1750 (char_u *)NULL, PV_NONE,
1751 {(char_u *)0L, (char_u *)0L}
1752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001754 {"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 +00001755#ifdef FEAT_KEYMAP
1756 (char_u *)&p_keymap, PV_KMAP,
1757 {(char_u *)"", (char_u *)0L}
1758#else
1759 (char_u *)NULL, PV_NONE,
1760 {(char_u *)"", (char_u *)0L}
1761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001762 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001763 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001765 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001767 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001769#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 (char_u *)":help",
1771#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001772# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001774# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001775# ifdef USEMAN_S
1776 (char_u *)"man -s",
1777# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001779# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780# endif
1781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001783 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784#ifdef FEAT_LANGMAP
1785 (char_u *)&p_langmap, PV_NONE,
1786 {(char_u *)"", /* unmatched } */
1787#else
1788 (char_u *)NULL, PV_NONE,
1789 {(char_u *)NULL,
1790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001792 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1794 (char_u *)&p_lm, PV_NONE,
1795#else
1796 (char_u *)NULL, PV_NONE,
1797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001798 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001799 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1800#ifdef FEAT_LANGMAP
1801 (char_u *)&p_lnr, PV_NONE,
1802#else
1803 (char_u *)NULL, PV_NONE,
1804#endif
1805 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001806 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1807#ifdef FEAT_LANGMAP
1808 (char_u *)&p_lrm, PV_NONE,
1809#else
1810 (char_u *)NULL, PV_NONE,
1811#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001812 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1814#ifdef FEAT_WINDOWS
1815 (char_u *)&p_ls, PV_NONE,
1816#else
1817 (char_u *)NULL, PV_NONE,
1818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1821 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1824#ifdef FEAT_LINEBREAK
1825 (char_u *)VAR_WIN, PV_LBR,
1826#else
1827 (char_u *)NULL, PV_NONE,
1828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001829 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1831 (char_u *)&Rows, PV_NONE,
1832 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001833#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834 (char_u *)25L,
1835#else
1836 (char_u *)24L,
1837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1840#ifdef FEAT_GUI
1841 (char_u *)&p_linespace, PV_NONE,
1842#else
1843 (char_u *)NULL, PV_NONE,
1844#endif
1845#ifdef FEAT_GUI_W32
1846 {(char_u *)1L, (char_u *)0L}
1847#else
1848 {(char_u *)0L, (char_u *)0L}
1849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"lisp", NULL, P_BOOL|P_VI_DEF,
1852#ifdef FEAT_LISP
1853 (char_u *)&p_lisp, PV_LISP,
1854#else
1855 (char_u *)NULL, PV_NONE,
1856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001858 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001860 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1862#else
1863 (char_u *)NULL, PV_NONE,
1864 {(char_u *)"", (char_u *)0L}
1865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1868 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001870 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1874 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001876 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001877#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001878 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001879 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001880#else
1881 (char_u *)NULL, PV_NONE,
1882 {(char_u *)"", (char_u *)0L}
1883#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001884 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001885 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001886#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001887 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001888 {(char_u *)TRUE, (char_u *)0L}
1889#else
1890 (char_u *)NULL, PV_NONE,
1891 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001892#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001893 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"magic", NULL, P_BOOL|P_VI_DEF,
1895 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001897 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898#ifdef FEAT_QUICKFIX
1899 (char_u *)&p_mef, PV_NONE,
1900 {(char_u *)"", (char_u *)0L}
1901#else
1902 (char_u *)NULL, PV_NONE,
1903 {(char_u *)NULL, (char_u *)0L}
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001906 {"makeencoding","menc", P_STRING|P_VI_DEF,
1907#ifdef FEAT_MBYTE
1908 (char_u *)&p_menc, PV_MENC,
1909 {(char_u *)"", (char_u *)0L}
1910#else
1911 (char_u *)NULL, PV_NONE,
1912 {(char_u *)0L, (char_u *)0L}
1913#endif
1914 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1916#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001917 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918# ifdef VMS
1919 {(char_u *)"MMS", (char_u *)0L}
1920# else
1921 {(char_u *)"make", (char_u *)0L}
1922# endif
1923#else
1924 (char_u *)NULL, PV_NONE,
1925 {(char_u *)NULL, (char_u *)0L}
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001928 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1931 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 {"matchtime", "mat", P_NUM|P_VI_DEF,
1933 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001935 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001936#ifdef FEAT_MBYTE
1937 (char_u *)&p_mco, PV_NONE,
1938#else
1939 (char_u *)NULL, PV_NONE,
1940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1943#ifdef FEAT_EVAL
1944 (char_u *)&p_mfd, PV_NONE,
1945#else
1946 (char_u *)NULL, PV_NONE,
1947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001948 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001949 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1950 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"maxmem", "mm", P_NUM|P_VI_DEF,
1953 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1955 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001956 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1957 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1962 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"menuitems", "mis", P_NUM|P_VI_DEF,
1964#ifdef FEAT_MENU
1965 (char_u *)&p_mis, PV_NONE,
1966#else
1967 (char_u *)NULL, PV_NONE,
1968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"mesg", NULL, P_BOOL|P_VI_DEF,
1971 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001973 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001974#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001975 (char_u *)&p_msm, PV_NONE,
1976 {(char_u *)"460000,2000,500", (char_u *)0L}
1977#else
1978 (char_u *)NULL, PV_NONE,
1979 {(char_u *)0L, (char_u *)0L}
1980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"modeline", "ml", P_BOOL|P_VIM,
1983 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"modelines", "mls", P_NUM|P_VI_DEF,
1986 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1989 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1992 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"more", NULL, P_BOOL|P_VIM,
1995 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1998 (char_u *)&p_mouse, PV_NONE,
1999 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002000#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)"a",
2002#else
2003 (char_u *)"",
2004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2007#ifdef FEAT_GUI
2008 (char_u *)&p_mousef, PV_NONE,
2009#else
2010 (char_u *)NULL, PV_NONE,
2011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2014#ifdef FEAT_GUI
2015 (char_u *)&p_mh, PV_NONE,
2016#else
2017 (char_u *)NULL, PV_NONE,
2018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002019 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2021 (char_u *)&p_mousem, PV_NONE,
2022 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002023#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 (char_u *)"popup",
2025#else
2026# if defined(MACOS)
2027 (char_u *)"popup_setpos",
2028# else
2029 (char_u *)"extend",
2030# endif
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002033 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034#ifdef FEAT_MOUSESHAPE
2035 (char_u *)&p_mouseshape, PV_NONE,
2036 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2037#else
2038 (char_u *)NULL, PV_NONE,
2039 {(char_u *)NULL, (char_u *)0L}
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2043 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002045 {"mzquantum", "mzq", P_NUM,
2046#ifdef FEAT_MZSCHEME
2047 (char_u *)&p_mzq, PV_NONE,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"novice", NULL, P_BOOL|P_VI_DEF,
2053 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002055 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002057 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2060 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002062 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2063#ifdef FEAT_LINEBREAK
2064 (char_u *)VAR_WIN, PV_NUW,
2065#else
2066 (char_u *)NULL, PV_NONE,
2067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002068 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002069 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002070#ifdef FEAT_COMPL_FUNC
2071 (char_u *)&p_ofu, PV_OFU,
2072 {(char_u *)"", (char_u *)0L}
2073#else
2074 (char_u *)NULL, PV_NONE,
2075 {(char_u *)0L, (char_u *)0L}
2076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"open", NULL, P_BOOL|P_VI_DEF,
2079 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002081 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002082#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002083 (char_u *)&p_odev, PV_NONE,
2084#else
2085 (char_u *)NULL, PV_NONE,
2086#endif
2087 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002089 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2090 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"optimize", "opt", P_BOOL|P_VI_DEF,
2093 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002097 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002098 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2099 |P_SECURE,
2100 (char_u *)&p_pp, PV_NONE,
2101 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2102 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"paragraphs", "para", P_STRING|P_VI_DEF,
2104 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002105 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002106 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002107 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2111 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2114#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2115 (char_u *)&p_pex, PV_NONE,
2116 {(char_u *)"", (char_u *)0L}
2117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)0L, (char_u *)0L}
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002122 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002126 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002128#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 (char_u *)".,,",
2130#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002134 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002135#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002137 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002138#else
2139 (char_u *)NULL, PV_NONE,
2140 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002141#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002142 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2144 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002146 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2148 (char_u *)&p_pvh, PV_NONE,
2149#else
2150 (char_u *)NULL, PV_NONE,
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2154#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2155 (char_u *)VAR_WIN, PV_PVW,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002160 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161#ifdef FEAT_PRINTER
2162 (char_u *)&p_pdev, PV_NONE,
2163 {(char_u *)"", (char_u *)0L}
2164#else
2165 (char_u *)NULL, PV_NONE,
2166 {(char_u *)NULL, (char_u *)0L}
2167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"printencoding", "penc", P_STRING|P_VI_DEF,
2170#ifdef FEAT_POSTSCRIPT
2171 (char_u *)&p_penc, PV_NONE,
2172 {(char_u *)"", (char_u *)0L}
2173#else
2174 (char_u *)NULL, PV_NONE,
2175 {(char_u *)NULL, (char_u *)0L}
2176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002177 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002178 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179#ifdef FEAT_POSTSCRIPT
2180 (char_u *)&p_pexpr, PV_NONE,
2181 {(char_u *)"", (char_u *)0L}
2182#else
2183 (char_u *)NULL, PV_NONE,
2184 {(char_u *)NULL, (char_u *)0L}
2185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"printfont", "pfn", P_STRING|P_VI_DEF,
2188#ifdef FEAT_PRINTER
2189 (char_u *)&p_pfn, PV_NONE,
2190 {
2191# ifdef MSWIN
2192 (char_u *)"Courier_New:h10",
2193# else
2194 (char_u *)"courier",
2195# endif
2196 (char_u *)0L}
2197#else
2198 (char_u *)NULL, PV_NONE,
2199 {(char_u *)NULL, (char_u *)0L}
2200#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002201 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002202 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2203#ifdef FEAT_PRINTER
2204 (char_u *)&p_header, PV_NONE,
2205 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2206#else
2207 (char_u *)NULL, PV_NONE,
2208 {(char_u *)NULL, (char_u *)0L}
2209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002211 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2212#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2213 (char_u *)&p_pmcs, PV_NONE,
2214 {(char_u *)"", (char_u *)0L}
2215#else
2216 (char_u *)NULL, PV_NONE,
2217 {(char_u *)NULL, (char_u *)0L}
2218#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002220 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2221#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2222 (char_u *)&p_pmfn, PV_NONE,
2223 {(char_u *)"", (char_u *)0L}
2224#else
2225 (char_u *)NULL, PV_NONE,
2226 {(char_u *)NULL, (char_u *)0L}
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002229 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230#ifdef FEAT_PRINTER
2231 (char_u *)&p_popt, PV_NONE,
2232 {(char_u *)"", (char_u *)0L}
2233#else
2234 (char_u *)NULL, PV_NONE,
2235 {(char_u *)NULL, (char_u *)0L}
2236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002239 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002241 {"pumheight", "ph", P_NUM|P_VI_DEF,
2242#ifdef FEAT_INS_EXPAND
2243 (char_u *)&p_ph, PV_NONE,
2244#else
2245 (char_u *)NULL, PV_NONE,
2246#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002247 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002248 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002249#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002250 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002251 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002252#else
2253 (char_u *)NULL, PV_NONE,
2254 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002255#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002256 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002257 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002258#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002259 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002260 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002261#else
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002264#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002265 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002266 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2267#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2268 (char_u *)&p_pyx, PV_NONE,
2269#else
2270 (char_u *)NULL, PV_NONE,
2271#endif
2272 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2273 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002274 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2275#ifdef FEAT_TEXTOBJ
2276 (char_u *)&p_qe, PV_QE,
2277 {(char_u *)"\\", (char_u *)0L}
2278#else
2279 (char_u *)NULL, PV_NONE,
2280 {(char_u *)NULL, (char_u *)0L}
2281#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2284 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"redraw", NULL, P_BOOL|P_VI_DEF,
2287 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002289 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2290#ifdef FEAT_RELTIME
2291 (char_u *)&p_rdt, PV_NONE,
2292#else
2293 (char_u *)NULL, PV_NONE,
2294#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002296 {"regexpengine", "re", P_NUM|P_VI_DEF,
2297 (char_u *)&p_re, PV_NONE,
2298 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002299 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2300 (char_u *)VAR_WIN, PV_RNU,
2301 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"remap", NULL, P_BOOL|P_VI_DEF,
2303 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002305 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002306#ifdef FEAT_RENDER_OPTIONS
2307 (char_u *)&p_rop, PV_NONE,
2308 {(char_u *)"", (char_u *)0L}
2309#else
2310 (char_u *)NULL, PV_NONE,
2311 {(char_u *)NULL, (char_u *)0L}
2312#endif
2313 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"report", NULL, P_NUM|P_VI_DEF,
2315 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2318#ifdef WIN3264
2319 (char_u *)&p_rs, PV_NONE,
2320#else
2321 (char_u *)NULL, PV_NONE,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2325#ifdef FEAT_RIGHTLEFT
2326 (char_u *)&p_ri, PV_NONE,
2327#else
2328 (char_u *)NULL, PV_NONE,
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2332#ifdef FEAT_RIGHTLEFT
2333 (char_u *)VAR_WIN, PV_RL,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2339#ifdef FEAT_RIGHTLEFT
2340 (char_u *)VAR_WIN, PV_RLC,
2341 {(char_u *)"search", (char_u *)NULL}
2342#else
2343 (char_u *)NULL, PV_NONE,
2344 {(char_u *)NULL, (char_u *)0L}
2345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002347 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002348#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002349 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002350 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002351#else
2352 (char_u *)NULL, PV_NONE,
2353 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002354#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2357#ifdef FEAT_CMDL_INFO
2358 (char_u *)&p_ru, PV_NONE,
2359#else
2360 (char_u *)NULL, PV_NONE,
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2364#ifdef FEAT_STL_OPT
2365 (char_u *)&p_ruf, PV_NONE,
2366#else
2367 (char_u *)NULL, PV_NONE,
2368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002370 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2371 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2374 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2376 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2379#ifdef FEAT_SCROLLBIND
2380 (char_u *)VAR_WIN, PV_SCBIND,
2381#else
2382 (char_u *)NULL, PV_NONE,
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2386 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2389 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002391 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392#ifdef FEAT_SCROLLBIND
2393 (char_u *)&p_sbo, PV_NONE,
2394 {(char_u *)"ver,jump", (char_u *)0L}
2395#else
2396 (char_u *)NULL, PV_NONE,
2397 {(char_u *)0L, (char_u *)0L}
2398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"sections", "sect", P_STRING|P_VI_DEF,
2401 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2403 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2405 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)"inclusive", (char_u *)0L}
2410 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002411 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002414 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415#ifdef FEAT_SESSION
2416 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002417 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 (char_u *)0L}
2419#else
2420 (char_u *)NULL, PV_NONE,
2421 {(char_u *)0L, (char_u *)0L}
2422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2425 (char_u *)&p_sh, PV_NONE,
2426 {
2427#ifdef VMS
2428 (char_u *)"-",
2429#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002430# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002432# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434# endif
2435#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2438 (char_u *)&p_shcf, PV_NONE,
2439 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002440#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 (char_u *)"/c",
2442#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2447#ifdef FEAT_QUICKFIX
2448 (char_u *)&p_sp, PV_NONE,
2449 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002450#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452#else
2453 (char_u *)">",
2454#endif
2455 (char_u *)0L}
2456#else
2457 (char_u *)NULL, PV_NONE,
2458 {(char_u *)0L, (char_u *)0L}
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2462 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002463 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2465 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2468#ifdef BACKSLASH_IN_FILENAME
2469 (char_u *)&p_ssl, PV_NONE,
2470#else
2471 (char_u *)NULL, PV_NONE,
2472#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002474 {"shelltemp", "stmp", P_BOOL,
2475 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"shelltype", "st", P_NUM|P_VI_DEF,
2478#ifdef AMIGA
2479 (char_u *)&p_st, PV_NONE,
2480#else
2481 (char_u *)NULL, PV_NONE,
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2485 (char_u *)&p_sxq, PV_NONE,
2486 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002487#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 (char_u *)"\"",
2489#else
2490 (char_u *)"",
2491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002493 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2494 (char_u *)&p_sxe, PV_NONE,
2495 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002496#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002497 (char_u *)"\"&|<>()@^",
2498#else
2499 (char_u *)"",
2500#endif
2501 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2503 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2506 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2509 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)"", (char_u *)"filnxtToO"}
2511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2516#ifdef FEAT_LINEBREAK
2517 (char_u *)&p_sbr, PV_NONE,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"showcmd", "sc", P_BOOL|P_VIM,
2523#ifdef FEAT_CMDL_INFO
2524 (char_u *)&p_sc, PV_NONE,
2525#else
2526 (char_u *)NULL, PV_NONE,
2527#endif
2528 {(char_u *)FALSE,
2529#ifdef UNIX
2530 (char_u *)FALSE
2531#else
2532 (char_u *)TRUE
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2536 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2539 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"showmode", "smd", P_BOOL|P_VIM,
2542 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002544 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2545#ifdef FEAT_WINDOWS
2546 (char_u *)&p_stal, PV_NONE,
2547#else
2548 (char_u *)NULL, PV_NONE,
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2552 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2555 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002557 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2558#ifdef FEAT_SIGNS
2559 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002560 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)NULL, (char_u *)0L}
2564#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2567 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2570 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2573#ifdef FEAT_SMARTINDENT
2574 (char_u *)&p_si, PV_SI,
2575#else
2576 (char_u *)NULL, PV_NONE,
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2580 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2583 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2586 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002588 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002589#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002590 (char_u *)VAR_WIN, PV_SPELL,
2591#else
2592 (char_u *)NULL, PV_NONE,
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002595 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002596#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002597 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002598 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002604 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2605 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002606#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002607 (char_u *)&p_spf, PV_SPF,
2608 {(char_u *)"", (char_u *)0L}
2609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002614 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2615 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002616#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002617 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002618 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002619#else
2620 (char_u *)NULL, PV_NONE,
2621 {(char_u *)0L, (char_u *)0L}
2622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002624 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002625#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002626 (char_u *)&p_sps, PV_NONE,
2627 {(char_u *)"best", (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2634#ifdef FEAT_WINDOWS
2635 (char_u *)&p_sb, PV_NONE,
2636#else
2637 (char_u *)NULL, PV_NONE,
2638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002641#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 (char_u *)&p_spr, PV_NONE,
2643#else
2644 (char_u *)NULL, PV_NONE,
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2648 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2651#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002652 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653#else
2654 (char_u *)NULL, PV_NONE,
2655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002657 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 (char_u *)&p_su, PV_NONE,
2659 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002661 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002662#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 (char_u *)&p_sua, PV_SUA,
2664 {(char_u *)"", (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2671 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {"swapsync", "sws", P_STRING|P_VI_DEF,
2674 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002676 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002679 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2680#ifdef FEAT_SYN_HL
2681 (char_u *)&p_smc, PV_SMC,
2682 {(char_u *)3000L, (char_u *)0L}
2683#else
2684 (char_u *)NULL, PV_NONE,
2685 {(char_u *)0L, (char_u *)0L}
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002688 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689#ifdef FEAT_SYN_HL
2690 (char_u *)&p_syn, PV_SYN,
2691 {(char_u *)"", (char_u *)0L}
2692#else
2693 (char_u *)NULL, PV_NONE,
2694 {(char_u *)0L, (char_u *)0L}
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002697 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2698#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002699 (char_u *)&p_tal, PV_NONE,
2700#else
2701 (char_u *)NULL, PV_NONE,
2702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002704 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2705#ifdef FEAT_WINDOWS
2706 (char_u *)&p_tpm, PV_NONE,
2707#else
2708 (char_u *)NULL, PV_NONE,
2709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2712 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2715 (char_u *)&p_tbs, PV_NONE,
2716#ifdef VMS /* binary searching doesn't appear to work on VMS */
2717 {(char_u *)0L, (char_u *)0L}
2718#else
2719 {(char_u *)TRUE, (char_u *)0L}
2720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002722 {"tagcase", "tc", P_STRING|P_VIM,
2723 (char_u *)&p_tc, PV_TC,
2724 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"taglength", "tl", P_NUM|P_VI_DEF,
2726 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"tagrelative", "tr", P_BOOL|P_VIM,
2729 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002731 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002732 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {
2734#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2735 (char_u *)"./tags,./TAGS,tags,TAGS",
2736#else
2737 (char_u *)"./tags,tags",
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2741 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002742 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002743 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002744#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002745 (char_u *)&p_tcldll, PV_NONE,
2746 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002747#else
2748 (char_u *)NULL, PV_NONE,
2749 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002750#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2753 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002754 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2756#ifdef FEAT_ARABIC
2757 (char_u *)&p_tbidi, PV_NONE,
2758#else
2759 (char_u *)NULL, PV_NONE,
2760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2763#ifdef FEAT_MBYTE
2764 (char_u *)&p_tenc, PV_NONE,
2765 {(char_u *)"", (char_u *)0L}
2766#else
2767 (char_u *)NULL, PV_NONE,
2768 {(char_u *)0L, (char_u *)0L}
2769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002771 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2772#ifdef FEAT_TERMGUICOLORS
2773 (char_u *)&p_tgc, PV_NONE,
2774 {(char_u *)FALSE, (char_u *)FALSE}
2775#else
2776 (char_u*)NULL, PV_NONE,
2777 {(char_u *)FALSE, (char_u *)FALSE}
2778#endif
2779 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"terse", NULL, P_BOOL|P_VI_DEF,
2781 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"textauto", "ta", P_BOOL|P_VIM,
2784 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2788 (char_u *)&p_tx, PV_TX,
2789 {
2790#ifdef USE_CRNL
2791 (char_u *)TRUE,
2792#else
2793 (char_u *)FALSE,
2794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002796 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002799 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002801 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802#else
2803 (char_u *)NULL, PV_NONE,
2804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2807 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"timeout", "to", P_BOOL|P_VI_DEF,
2810 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2813 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"title", NULL, P_BOOL|P_VI_DEF,
2816#ifdef FEAT_TITLE
2817 (char_u *)&p_title, PV_NONE,
2818#else
2819 (char_u *)NULL, PV_NONE,
2820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"titlelen", NULL, P_NUM|P_VI_DEF,
2823#ifdef FEAT_TITLE
2824 (char_u *)&p_titlelen, PV_NONE,
2825#else
2826 (char_u *)NULL, PV_NONE,
2827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002829 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830#ifdef FEAT_TITLE
2831 (char_u *)&p_titleold, PV_NONE,
2832 {(char_u *)N_("Thanks for flying Vim"),
2833 (char_u *)0L}
2834#else
2835 (char_u *)NULL, PV_NONE,
2836 {(char_u *)0L, (char_u *)0L}
2837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"titlestring", NULL, P_STRING|P_VI_DEF,
2840#ifdef FEAT_TITLE
2841 (char_u *)&p_titlestring, PV_NONE,
2842#else
2843 (char_u *)NULL, PV_NONE,
2844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002846 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002847#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002850#else
2851 (char_u *)NULL, PV_NONE,
2852 {(char_u *)0L, (char_u *)0L}
2853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002856#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002858 {(char_u *)"small", (char_u *)0L}
2859#else
2860 (char_u *)NULL, PV_NONE,
2861 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002863 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2865 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2868 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2871 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2874 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2877#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2878 (char_u *)&p_ttym, PV_NONE,
2879#else
2880 (char_u *)NULL, PV_NONE,
2881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2884 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2887 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002889 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2890 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002891#ifdef FEAT_PERSISTENT_UNDO
2892 (char_u *)&p_udir, PV_NONE,
2893 {(char_u *)".", (char_u *)0L}
2894#else
2895 (char_u *)NULL, PV_NONE,
2896 {(char_u *)0L, (char_u *)0L}
2897#endif
2898 SCRIPTID_INIT},
2899 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2900#ifdef FEAT_PERSISTENT_UNDO
2901 (char_u *)&p_udf, PV_UDF,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
2905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002907 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002909#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 (char_u *)1000L,
2911#else
2912 (char_u *)100L,
2913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002915 {"undoreload", "ur", P_NUM|P_VI_DEF,
2916 (char_u *)&p_ur, PV_NONE,
2917 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"updatecount", "uc", P_NUM|P_VI_DEF,
2919 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"updatetime", "ut", P_NUM|P_VI_DEF,
2922 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002923 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 {"verbose", "vbs", P_NUM|P_VI_DEF,
2925 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002927 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2928 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2931#ifdef FEAT_SESSION
2932 (char_u *)&p_vdir, PV_NONE,
2933 {(char_u *)DFLT_VDIR, (char_u *)0L}
2934#else
2935 (char_u *)NULL, PV_NONE,
2936 {(char_u *)0L, (char_u *)0L}
2937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002939 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940#ifdef FEAT_SESSION
2941 (char_u *)&p_vop, PV_NONE,
2942 {(char_u *)"folds,options,cursor", (char_u *)0L}
2943#else
2944 (char_u *)NULL, PV_NONE,
2945 {(char_u *)0L, (char_u *)0L}
2946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002948 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949#ifdef FEAT_VIMINFO
2950 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002951#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002952 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953#else
2954# ifdef AMIGA
2955 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002956 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002958 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959# endif
2960#endif
2961#else
2962 (char_u *)NULL, PV_NONE,
2963 {(char_u *)0L, (char_u *)0L}
2964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002965 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002966 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2967 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968#ifdef FEAT_VIRTUALEDIT
2969 (char_u *)&p_ve, PV_NONE,
2970 {(char_u *)"", (char_u *)""}
2971#else
2972 (char_u *)NULL, PV_NONE,
2973 {(char_u *)0L, (char_u *)0L}
2974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002975 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2977 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 {"w300", NULL, P_NUM|P_VI_DEF,
2980 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 {"w1200", NULL, P_NUM|P_VI_DEF,
2983 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002984 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"w9600", NULL, P_NUM|P_VI_DEF,
2986 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"warn", NULL, P_BOOL|P_VI_DEF,
2989 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002990 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2992 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002994 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {"wildchar", "wc", P_NUM|P_VIM,
2998 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3000 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003001 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003003 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003004 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005#ifdef FEAT_WILDIGN
3006 (char_u *)&p_wig, PV_NONE,
3007#else
3008 (char_u *)NULL, PV_NONE,
3009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003010 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003011 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3012 (char_u *)&p_wic, PV_NONE,
3013 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3015#ifdef FEAT_WILDMENU
3016 (char_u *)&p_wmnu, PV_NONE,
3017#else
3018 (char_u *)NULL, PV_NONE,
3019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003021 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003023 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003024 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3025#ifdef FEAT_CMDL_COMPL
3026 (char_u *)&p_wop, PV_NONE,
3027 {(char_u *)"", (char_u *)0L}
3028#else
3029 (char_u *)NULL, PV_NONE,
3030 {(char_u *)NULL, (char_u *)0L}
3031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003032 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3034#ifdef FEAT_WAK
3035 (char_u *)&p_wak, PV_NONE,
3036 {(char_u *)"menu", (char_u *)0L}
3037#else
3038 (char_u *)NULL, PV_NONE,
3039 {(char_u *)NULL, (char_u *)0L}
3040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003043 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003044 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 {"winheight", "wh", P_NUM|P_VI_DEF,
3046#ifdef FEAT_WINDOWS
3047 (char_u *)&p_wh, PV_NONE,
3048#else
3049 (char_u *)NULL, PV_NONE,
3050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003051 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003053#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)VAR_WIN, PV_WFH,
3055#else
3056 (char_u *)NULL, PV_NONE,
3057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003058 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003059 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003060#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003061 (char_u *)VAR_WIN, PV_WFW,
3062#else
3063 (char_u *)NULL, PV_NONE,
3064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3067#ifdef FEAT_WINDOWS
3068 (char_u *)&p_wmh, PV_NONE,
3069#else
3070 (char_u *)NULL, PV_NONE,
3071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003072 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003074#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 (char_u *)&p_wmw, PV_NONE,
3076#else
3077 (char_u *)NULL, PV_NONE,
3078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003079 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003081#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 (char_u *)&p_wiw, PV_NONE,
3083#else
3084 (char_u *)NULL, PV_NONE,
3085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003086 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3088 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003089 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3091 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003092 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3094 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003095 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 {"write", NULL, P_BOOL|P_VI_DEF,
3097 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003098 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 {"writeany", "wa", P_BOOL|P_VI_DEF,
3100 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3103 (char_u *)&p_wb, PV_NONE,
3104 {
3105#ifdef FEAT_WRITEBACKUP
3106 (char_u *)TRUE,
3107#else
3108 (char_u *)FALSE,
3109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003110 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 {"writedelay", "wd", P_NUM|P_VI_DEF,
3112 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003113 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114
3115/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003116#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003118 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119
3120 p_term("t_AB", T_CAB)
3121 p_term("t_AF", T_CAF)
3122 p_term("t_AL", T_CAL)
3123 p_term("t_al", T_AL)
3124 p_term("t_bc", T_BC)
3125 p_term("t_cd", T_CD)
3126 p_term("t_ce", T_CE)
3127 p_term("t_cl", T_CL)
3128 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003129 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 p_term("t_Co", T_CCO)
3131 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003132 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003134#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 p_term("t_CV", T_CSV)
3136#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 p_term("t_da", T_DA)
3138 p_term("t_db", T_DB)
3139 p_term("t_DL", T_CDL)
3140 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003141 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 p_term("t_fs", T_FS)
3143 p_term("t_IE", T_CIE)
3144 p_term("t_IS", T_CIS)
3145 p_term("t_ke", T_KE)
3146 p_term("t_ks", T_KS)
3147 p_term("t_le", T_LE)
3148 p_term("t_mb", T_MB)
3149 p_term("t_md", T_MD)
3150 p_term("t_me", T_ME)
3151 p_term("t_mr", T_MR)
3152 p_term("t_ms", T_MS)
3153 p_term("t_nd", T_ND)
3154 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003155 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_RI", T_CRI)
3157 p_term("t_RV", T_CRV)
3158 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003160 p_term("t_Sf", T_CSF)
3161 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003163 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_te", T_TE)
3166 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003167 p_term("t_ts", T_TS)
3168 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_ue", T_UE)
3170 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003171 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_vb", T_VB)
3173 p_term("t_ve", T_VE)
3174 p_term("t_vi", T_VI)
3175 p_term("t_vs", T_VS)
3176 p_term("t_WP", T_CWP)
3177 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003178 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_xs", T_XS)
3180 p_term("t_ZH", T_CZH)
3181 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003182 p_term("t_8f", T_8F)
3183 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003184 p_term("t_BE", T_BE)
3185 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186
3187/* terminal key codes are not in here */
3188
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003189 /* end marker */
3190 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191};
3192
3193#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3194
3195#ifdef FEAT_MBYTE
3196static char *(p_ambw_values[]) = {"single", "double", NULL};
3197#endif
3198static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003199static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003201#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003202static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003203#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003204#ifdef FEAT_CMDL_COMPL
3205static char *(p_wop_values[]) = {"tagfile", NULL};
3206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207#ifdef FEAT_WAK
3208static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3209#endif
3210static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3212static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003214#ifdef FEAT_BROWSE
3215static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3216#endif
3217#ifdef FEAT_SCROLLBIND
3218static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3219#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003220static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003221#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3223#endif
3224#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003225# ifdef FEAT_AUTOCMD
3226static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3227# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003229# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3231#endif
3232static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3233#ifdef FEAT_FOLDING
3234static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003235# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003237# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 NULL};
3239static char *(p_fcl_values[]) = {"all", NULL};
3240#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003241#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003242static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003244#ifdef FEAT_SIGNS
3245static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static void set_option_default(int, int opt_flags, int compatible);
3249static void set_options_default(int opt_flags);
3250static char_u *term_bg_default(void);
3251static void did_set_option(int opt_idx, int opt_flags, int new_value);
3252static char_u *illegal_char(char_u *, int);
3253static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003255static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#endif
3257#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003260static char_u *option_expand(int opt_idx, char_u *val);
3261static void didset_options(void);
3262static void didset_options2(void);
3263static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003264#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003265static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003266#else
3267# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3268#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static void set_string_option_global(int opt_idx, char_u **varp);
3270static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3271static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3272static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003273#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003279#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static char_u *did_set_spell_option(int is_spellfile);
3281static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003282#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003283#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003285#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003286static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3287static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3288static void check_redraw(long_u flags);
3289static int findoption(char_u *);
3290static int find_key_option(char_u *);
3291static void showoptions(int all, int opt_flags);
3292static int optval_default(struct vimoption *, char_u *varp);
3293static void showoneopt(struct vimoption *, int opt_flags);
3294static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3295static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3296static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3297static int istermoption(struct vimoption *);
3298static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3299static char_u *get_varp(struct vimoption *);
3300static void option_value2string(struct vimoption *, int opt_flags);
3301static void check_winopt(winopt_T *wop);
3302static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003304static void langmap_init(void);
3305static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003307static void paste_option_changed(void);
3308static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003310static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3313static int check_opt_strings(char_u *val, char **values, int);
3314static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003315#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003316static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318
3319/*
3320 * Initialize the options, first part.
3321 *
3322 * Called only once from main(), just after creating the first buffer.
3323 */
3324 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003325set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326{
3327 char_u *p;
3328 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003329 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
3331#ifdef FEAT_LANGMAP
3332 langmap_init();
3333#endif
3334
3335 /* Be Vi compatible by default */
3336 p_cp = TRUE;
3337
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003338 /* Use POSIX compatibility when $VIM_POSIX is set. */
3339 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003340 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003341 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003342 set_string_default("shm", (char_u *)"A");
3343 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003344
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 /*
3346 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003347 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003349 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003350#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003351 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003353 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354# endif
3355#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003356 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 set_string_default("sh", p);
3358
3359#ifdef FEAT_WILDIGN
3360 /*
3361 * Set the default for 'backupskip' to include environment variables for
3362 * temp files.
3363 */
3364 {
3365# ifdef UNIX
3366 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3367# else
3368 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3369# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003370 int len;
3371 garray_T ga;
3372 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373
3374 ga_init2(&ga, 1, 100);
3375 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3376 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003377 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378# ifdef UNIX
3379 if (*names[n] == NUL)
3380 p = (char_u *)"/tmp";
3381 else
3382# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003383 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 if (p != NULL && *p != NUL)
3385 {
3386 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003387 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 if (ga_grow(&ga, len) == OK)
3389 {
3390 if (ga.ga_len > 0)
3391 STRCAT(ga.ga_data, ",");
3392 STRCAT(ga.ga_data, p);
3393 add_pathsep(ga.ga_data);
3394 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 ga.ga_len += len;
3396 }
3397 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003398 if (mustfree)
3399 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400 }
3401 if (ga.ga_data != NULL)
3402 {
3403 set_string_default("bsk", ga.ga_data);
3404 vim_free(ga.ga_data);
3405 }
3406 }
3407#endif
3408
3409 /*
3410 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3411 */
3412 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003413 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003415#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3416 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3417#endif
3418 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003421 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422#else
3423# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003424 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003425 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003427 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428# endif
3429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431 opt_idx = findoption((char_u *)"maxmem");
3432 if (opt_idx >= 0)
3433 {
3434#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003435 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3436 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003437#endif
3438 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3439 }
3440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 }
3442
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443#ifdef FEAT_SEARCHPATH
3444 {
3445 char_u *cdpath;
3446 char_u *buf;
3447 int i;
3448 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003449 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450
3451 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003452 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453 if (cdpath != NULL)
3454 {
3455 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3456 if (buf != NULL)
3457 {
3458 buf[0] = ','; /* start with ",", current dir first */
3459 j = 1;
3460 for (i = 0; cdpath[i] != NUL; ++i)
3461 {
3462 if (vim_ispathlistsep(cdpath[i]))
3463 buf[j++] = ',';
3464 else
3465 {
3466 if (cdpath[i] == ' ' || cdpath[i] == ',')
3467 buf[j++] = '\\';
3468 buf[j++] = cdpath[i];
3469 }
3470 }
3471 buf[j] = NUL;
3472 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003473 if (opt_idx >= 0)
3474 {
3475 options[opt_idx].def_val[VI_DEFAULT] = buf;
3476 options[opt_idx].flags |= P_DEF_ALLOCED;
3477 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003478 else
3479 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003481 if (mustfree)
3482 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 }
3484 }
3485#endif
3486
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003487#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 /* Set print encoding on platforms that don't default to latin1 */
3489 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003490# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 (char_u *)"cp1252"
3492# else
3493# ifdef VMS
3494 (char_u *)"dec-mcs"
3495# else
3496# ifdef EBCDIC
3497 (char_u *)"ebcdic-uk"
3498# else
3499# ifdef MAC
3500 (char_u *)"mac-roman"
3501# else /* HPUX */
3502 (char_u *)"hp-roman8"
3503# endif
3504# endif
3505# endif
3506# endif
3507 );
3508#endif
3509
3510#ifdef FEAT_POSTSCRIPT
3511 /* 'printexpr' must be allocated to be able to evaluate it. */
3512 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003513# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003514 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515# else
3516# ifdef VMS
3517 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3518
3519# else
3520 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3521# endif
3522# endif
3523 );
3524#endif
3525
3526 /*
3527 * Set all the options (except the terminal options) to their default
3528 * value. Also set the global value for local options.
3529 */
3530 set_options_default(0);
3531
3532#ifdef FEAT_GUI
3533 if (found_reverse_arg)
3534 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3535#endif
3536
3537 curbuf->b_p_initialized = TRUE;
3538 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003539 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540 check_buf_options(curbuf);
3541 check_win_options(curwin);
3542 check_options();
3543
3544 /* Must be before option_expand(), because that one needs vim_isIDc() */
3545 didset_options();
3546
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003547#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003548 /* Use the current chartab for the generic chartab. This is not in
3549 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003550 init_spell_chartab();
3551#endif
3552
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 /*
3554 * Expand environment variables and things like "~" for the defaults.
3555 * If option_expand() returns non-NULL the variable is expanded. This can
3556 * only happen for non-indirect options.
3557 * Also set the default to the expanded value, so ":set" does not list
3558 * them.
3559 * Don't set the P_ALLOCED flag, because we don't want to free the
3560 * default.
3561 */
3562 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3563 {
3564 if ((options[opt_idx].flags & P_GETTEXT)
3565 && options[opt_idx].var != NULL)
3566 p = (char_u *)_(*(char **)options[opt_idx].var);
3567 else
3568 p = option_expand(opt_idx, NULL);
3569 if (p != NULL && (p = vim_strsave(p)) != NULL)
3570 {
3571 *(char_u **)options[opt_idx].var = p;
3572 /* VIMEXP
3573 * Defaults for all expanded options are currently the same for Vi
3574 * and Vim. When this changes, add some code here! Also need to
3575 * split P_DEF_ALLOCED in two.
3576 */
3577 if (options[opt_idx].flags & P_DEF_ALLOCED)
3578 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3579 options[opt_idx].def_val[VI_DEFAULT] = p;
3580 options[opt_idx].flags |= P_DEF_ALLOCED;
3581 }
3582 }
3583
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584 save_file_ff(curbuf); /* Buffer is unchanged */
3585
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586#if defined(FEAT_ARABIC)
3587 /* Detect use of mlterm.
3588 * Mlterm is a terminal emulator akin to xterm that has some special
3589 * abilities (bidi namely).
3590 * NOTE: mlterm's author is being asked to 'set' a variable
3591 * instead of an environment variable due to inheritance.
3592 */
3593 if (mch_getenv((char_u *)"MLTERM") != NULL)
3594 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3595#endif
3596
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003597 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598
3599#ifdef FEAT_MBYTE
3600# if defined(WIN3264) && defined(FEAT_GETTEXT)
3601 /*
3602 * If $LANG isn't set, try to get a good value for it. This makes the
3603 * right language be used automatically. Don't do this for English.
3604 */
3605 if (mch_getenv((char_u *)"LANG") == NULL)
3606 {
3607 char buf[20];
3608
3609 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3610 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3611 * only the first two. */
3612 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3613 (LPTSTR)buf, 20);
3614 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3615 {
3616 /* There are a few exceptions (probably more) */
3617 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3618 STRCPY(buf, "zh_TW");
3619 else if (STRNICMP(buf, "chs", 3) == 0
3620 || STRNICMP(buf, "zhc", 3) == 0)
3621 STRCPY(buf, "zh_CN");
3622 else if (STRNICMP(buf, "jp", 2) == 0)
3623 STRCPY(buf, "ja");
3624 else
3625 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003626 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 }
3628 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003629# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003630# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003631 /* Moved to os_mac_conv.c to avoid dependency problems. */
3632 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003633# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634# endif
3635
3636 /* enc_locale() will try to find the encoding of the current locale. */
3637 p = enc_locale();
3638 if (p != NULL)
3639 {
3640 char_u *save_enc;
3641
3642 /* Try setting 'encoding' and check if the value is valid.
3643 * If not, go back to the default "latin1". */
3644 save_enc = p_enc;
3645 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003646 if (STRCMP(p_enc, "gb18030") == 0)
3647 {
3648 /* We don't support "gb18030", but "cp936" is a good substitute
3649 * for practical purposes, thus use that. It's not an alias to
3650 * still support conversion between gb18030 and utf-8. */
3651 p_enc = vim_strsave((char_u *)"cp936");
3652 vim_free(p);
3653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 if (mb_init() == NULL)
3655 {
3656 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003657 if (opt_idx >= 0)
3658 {
3659 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3660 options[opt_idx].flags |= P_DEF_ALLOCED;
3661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003663#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003664 if (STRCMP(p_enc, "latin1") == 0
3665# ifdef FEAT_MBYTE
3666 || enc_utf8
3667# endif
3668 )
3669 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003670 /* Adjust the default for 'isprint' and 'iskeyword' to match
3671 * latin1. Also set the defaults for when 'nocompatible' is
3672 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003673 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003674 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003675 set_string_option_direct((char_u *)"isk", -1,
3676 ISK_LATIN1, OPT_FREE, SID_NONE);
3677 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003678 if (opt_idx >= 0)
3679 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003680 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003681 if (opt_idx >= 0)
3682 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003683 (void)init_chartab();
3684 }
3685#endif
3686
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687# if defined(WIN3264) && !defined(FEAT_GUI)
3688 /* Win32 console: When GetACP() returns a different value from
3689 * GetConsoleCP() set 'termencoding'. */
3690 if (GetACP() != GetConsoleCP())
3691 {
3692 char buf[50];
3693
3694 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3695 p_tenc = vim_strsave((char_u *)buf);
3696 if (p_tenc != NULL)
3697 {
3698 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 {
3701 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3702 options[opt_idx].flags |= P_DEF_ALLOCED;
3703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704 convert_setup(&input_conv, p_tenc, p_enc);
3705 convert_setup(&output_conv, p_enc, p_tenc);
3706 }
3707 else
3708 p_tenc = empty_option;
3709 }
3710# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003711# if defined(WIN3264) && defined(FEAT_MBYTE)
3712 /* $HOME may have characters in active code page. */
3713 init_homedir();
3714# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003715 }
3716 else
3717 {
3718 vim_free(p_enc);
3719 p_enc = save_enc;
3720 }
3721 }
3722#endif
3723
3724#ifdef FEAT_MULTI_LANG
3725 /* Set the default for 'helplang'. */
3726 set_helplang_default(get_mess_lang());
3727#endif
3728}
3729
3730/*
3731 * Set an option to its default value.
3732 * This does not take care of side effects!
3733 */
3734 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003735set_option_default(
3736 int opt_idx,
3737 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3738 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739{
3740 char_u *varp; /* pointer to variable for current option */
3741 int dvi; /* index in def_val[] */
3742 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003743 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3745
3746 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3747 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003748 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 {
3750 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3751 if (flags & P_STRING)
3752 {
3753 /* Use set_string_option_direct() for local options to handle
3754 * freeing and allocating the value. */
3755 if (options[opt_idx].indir != PV_NONE)
3756 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003757 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 else
3759 {
3760 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3761 free_string_option(*(char_u **)(varp));
3762 *(char_u **)varp = options[opt_idx].def_val[dvi];
3763 options[opt_idx].flags &= ~P_ALLOCED;
3764 }
3765 }
3766 else if (flags & P_NUM)
3767 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003768 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 win_comp_scroll(curwin);
3770 else
3771 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003772 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 /* May also set global value for local option. */
3774 if (both)
3775 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3776 *(long *)varp;
3777 }
3778 }
3779 else /* P_BOOL */
3780 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003781 /* the cast to long is required for Manx C, long_i is needed for
3782 * MSVC */
3783 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003784#ifdef UNIX
3785 /* 'modeline' defaults to off for root */
3786 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3787 *(int *)varp = FALSE;
3788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 /* May also set global value for local option. */
3790 if (both)
3791 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3792 *(int *)varp;
3793 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003794
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003795 /* The default value is not insecure. */
3796 flagsp = insecure_flag(opt_idx, opt_flags);
3797 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 }
3799
3800#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003801 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802#endif
3803}
3804
3805/*
3806 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003807 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 */
3809 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003810set_options_default(
3811 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812{
3813 int i;
3814#ifdef FEAT_WINDOWS
3815 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003816 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817#endif
3818
3819 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003820 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003821#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003822 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003823 || (TRUE
3824# if defined(FEAT_MBYTE)
3825 && options[i].var != (char_u *)&p_enc
3826# endif
3827# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003828 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003829 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003830# endif
3831 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003832#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003833 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 set_option_default(i, opt_flags, p_cp);
3835
3836#ifdef FEAT_WINDOWS
3837 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003838 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 win_comp_scroll(wp);
3840#else
3841 win_comp_scroll(curwin);
3842#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003843#ifdef FEAT_CINDENT
3844 parse_cino(curbuf);
3845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846}
3847
3848/*
3849 * Set the Vi-default value of a string option.
3850 * Used for 'sh', 'backupskip' and 'term'.
3851 */
3852 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003853set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854{
3855 char_u *p;
3856 int opt_idx;
3857
3858 p = vim_strsave(val);
3859 if (p != NULL) /* we don't want a NULL */
3860 {
3861 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003862 if (opt_idx >= 0)
3863 {
3864 if (options[opt_idx].flags & P_DEF_ALLOCED)
3865 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3866 options[opt_idx].def_val[VI_DEFAULT] = p;
3867 options[opt_idx].flags |= P_DEF_ALLOCED;
3868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 }
3870}
3871
3872/*
3873 * Set the Vi-default value of a number option.
3874 * Used for 'lines' and 'columns'.
3875 */
3876 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003877set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003879 int opt_idx;
3880
3881 opt_idx = findoption((char_u *)name);
3882 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003883 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884}
3885
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003886#if defined(EXITFREE) || defined(PROTO)
3887/*
3888 * Free all options.
3889 */
3890 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003891free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003892{
3893 int i;
3894
3895 for (i = 0; !istermoption(&options[i]); i++)
3896 {
3897 if (options[i].indir == PV_NONE)
3898 {
3899 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003900 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003901 free_string_option(*(char_u **)options[i].var);
3902 if (options[i].flags & P_DEF_ALLOCED)
3903 free_string_option(options[i].def_val[VI_DEFAULT]);
3904 }
3905 else if (options[i].var != VAR_WIN
3906 && (options[i].flags & P_STRING))
3907 /* buffer-local option: free global value */
3908 free_string_option(*(char_u **)options[i].var);
3909 }
3910}
3911#endif
3912
3913
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914/*
3915 * Initialize the options, part two: After getting Rows and Columns and
3916 * setting 'term'.
3917 */
3918 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003919set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003921 int idx;
3922
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 /*
3924 * 'scroll' defaults to half the window height. Note that this default is
3925 * wrong when the window height changes.
3926 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003927 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003928 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003929 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003930 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 comp_col();
3932
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003933 /*
3934 * 'window' is only for backwards compatibility with Vi.
3935 * Default is Rows - 1.
3936 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003937 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003938 p_window = Rows - 1;
3939 set_number_default("window", Rows - 1);
3940
Bram Moolenaarf740b292006-02-16 22:11:02 +00003941 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003942#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003943 /*
3944 * If 'background' wasn't set by the user, try guessing the value,
3945 * depending on the terminal name. Only need to check for terminals
3946 * with a dark background, that can handle color.
3947 */
3948 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003949 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3950 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003952 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003953 /* don't mark it as set, when starting the GUI it may be
3954 * changed again */
3955 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 }
3957#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003958
3959#ifdef CURSOR_SHAPE
3960 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3961#endif
3962#ifdef FEAT_MOUSESHAPE
3963 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3964#endif
3965#ifdef FEAT_PRINTER
3966 (void)parse_printoptions(); /* parse 'printoptions' default value */
3967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968}
3969
3970/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 * Return "dark" or "light" depending on the kind of terminal.
3972 * This is just guessing! Recognized are:
3973 * "linux" Linux console
3974 * "screen.linux" Linux console with screen
3975 * "cygwin" Cygwin shell
3976 * "putty" Putty program
3977 * We also check the COLORFGBG environment variable, which is set by
3978 * rxvt and derivatives. This variable contains either two or three
3979 * values separated by semicolons; we want the last value in either
3980 * case. If this value is 0-6 or 8, our background is dark.
3981 */
3982 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003983term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003984{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003985#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003986 /* DOS console nearly always black */
3987 return (char_u *)"dark";
3988#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003989 char_u *p;
3990
Bram Moolenaarf740b292006-02-16 22:11:02 +00003991 if (STRCMP(T_NAME, "linux") == 0
3992 || STRCMP(T_NAME, "screen.linux") == 0
3993 || STRCMP(T_NAME, "cygwin") == 0
3994 || STRCMP(T_NAME, "putty") == 0
3995 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3996 && (p = vim_strrchr(p, ';')) != NULL
3997 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3998 && p[2] == NUL))
3999 return (char_u *)"dark";
4000 return (char_u *)"light";
4001#endif
4002}
4003
4004/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 * Initialize the options, part three: After reading the .vimrc
4006 */
4007 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004008set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004010#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011/*
4012 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4013 * This is done after other initializations, where 'shell' might have been
4014 * set, but only if they have not been set before.
4015 */
4016 char_u *p;
4017 int idx_srr;
4018 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004019# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 int idx_sp;
4021 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004022# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023
4024 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004025 if (idx_srr < 0)
4026 do_srr = FALSE;
4027 else
4028 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004029# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004031 if (idx_sp < 0)
4032 do_sp = FALSE;
4033 else
4034 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004035# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004036 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 if (p != NULL)
4038 {
4039 /*
4040 * Default for p_sp is "| tee", for p_srr is ">".
4041 * For known shells it is changed here to include stderr.
4042 */
4043 if ( fnamecmp(p, "csh") == 0
4044 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004045# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 || fnamecmp(p, "csh.exe") == 0
4047 || fnamecmp(p, "tcsh.exe") == 0
4048# endif
4049 )
4050 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004051# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 if (do_sp)
4053 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004058# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4060 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if (do_srr)
4063 {
4064 p_srr = (char_u *)">&";
4065 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4066 }
4067 }
4068 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 if ( fnamecmp(p, "sh") == 0
4071 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004072 || fnamecmp(p, "mksh") == 0
4073 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004075 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004077 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 || fnamecmp(p, "cmd") == 0
4080 || fnamecmp(p, "sh.exe") == 0
4081 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004082 || fnamecmp(p, "mksh.exe") == 0
4083 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004085 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 || fnamecmp(p, "bash.exe") == 0
4087 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004091# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 if (do_sp)
4093 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004094# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4100 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004101# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 if (do_srr)
4103 {
4104 p_srr = (char_u *)">%s 2>&1";
4105 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4106 }
4107 }
4108 vim_free(p);
4109 }
4110#endif
4111
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004112#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004114 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4115 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 * This is done after other initializations, where 'shell' might have been
4117 * set, but only if they have not been set before. Default for p_shcf is
4118 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004119 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004121 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 {
4123 int idx3;
4124
4125 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128 p_shcf = (char_u *)"-c";
4129 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4130 }
4131
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 /* Somehow Win32 requires the quotes around the redirection too */
4133 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004134 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 {
4136 p_sxq = (char_u *)"\"";
4137 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004140 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4141 {
4142 int idx3;
4143
4144 /*
4145 * cmd.exe on Windows will strip the first and last double quote given
4146 * on the command line, e.g. most of the time things like:
4147 * cmd /c "my path/to/echo" "my args to echo"
4148 * become:
4149 * my path/to/echo" "my args to echo
4150 * when executed.
4151 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004152 * To avoid this, set shellxquote to surround the command in
4153 * parenthesis. This appears to make most commands work, without
4154 * breaking commands that worked previously, such as
4155 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004156 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004157 idx3 = findoption((char_u *)"sxq");
4158 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4159 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004160 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004161 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4162 }
4163
Bram Moolenaara64ba222012-02-12 23:23:31 +01004164 idx3 = findoption((char_u *)"shcf");
4165 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4166 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004167 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004168 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4169 }
4170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171#endif
4172
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004173 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004174 {
4175 int idx_ffs = findoption((char_u *)"ffs");
4176
4177 /* Apply the first entry of 'fileformats' to the initial buffer. */
4178 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4179 set_fileformat(default_fileformat(), OPT_LOCAL);
4180 }
4181
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182#ifdef FEAT_TITLE
4183 set_title_defaults();
4184#endif
4185}
4186
4187#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4188/*
4189 * When 'helplang' is still at its default value, set it to "lang".
4190 * Only the first two characters of "lang" are used.
4191 */
4192 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004193set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194{
4195 int idx;
4196
4197 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4198 return;
4199 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004200 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 {
4202 if (options[idx].flags & P_ALLOCED)
4203 free_string_option(p_hlg);
4204 p_hlg = vim_strsave(lang);
4205 if (p_hlg == NULL)
4206 p_hlg = empty_option;
4207 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004208 {
4209 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4210 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4211 {
4212 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4213 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4214 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004216 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217 options[idx].flags |= P_ALLOCED;
4218 }
4219}
4220#endif
4221
4222#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004223static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224
4225 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004226gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227{
4228 if (gui_get_lightness(gui.back_pixel) < 127)
4229 return (char_u *)"dark";
4230 return (char_u *)"light";
4231}
4232
4233/*
4234 * Option initializations that can only be done after opening the GUI window.
4235 */
4236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004237init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238{
4239 /* Set the 'background' option according to the lightness of the
4240 * background color, unless the user has set it already. */
4241 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4242 {
4243 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4244 highlight_changed();
4245 }
4246}
4247#endif
4248
4249#ifdef FEAT_TITLE
4250/*
4251 * 'title' and 'icon' only default to true if they have not been set or reset
4252 * in .vimrc and we can read the old value.
4253 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4254 * they can be reset. This reduces startup time when using X on a remote
4255 * machine.
4256 */
4257 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004258set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259{
4260 int idx1;
4261 long val;
4262
4263 /*
4264 * If GUI is (going to be) used, we can always set the window title and
4265 * icon name. Saves a bit of time, because the X11 display server does
4266 * not need to be contacted.
4267 */
4268 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004269 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270 {
4271#ifdef FEAT_GUI
4272 if (gui.starting || gui.in_use)
4273 val = TRUE;
4274 else
4275#endif
4276 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004277 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004278 p_title = val;
4279 }
4280 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004281 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282 {
4283#ifdef FEAT_GUI
4284 if (gui.starting || gui.in_use)
4285 val = TRUE;
4286 else
4287#endif
4288 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004289 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290 p_icon = val;
4291 }
4292}
4293#endif
4294
4295/*
4296 * Parse 'arg' for option settings.
4297 *
4298 * 'arg' may be IObuff, but only when no errors can be present and option
4299 * does not need to be expanded with option_expand().
4300 * "opt_flags":
4301 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004302 * OPT_GLOBAL for ":setglobal"
4303 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004304 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004305 * OPT_WINONLY to only set window-local options
4306 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004307 *
4308 * returns FAIL if an error is detected, OK otherwise
4309 */
4310 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004311do_set(
4312 char_u *arg, /* option string (may be written to!) */
4313 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314{
4315 int opt_idx;
4316 char_u *errmsg;
4317 char_u errbuf[80];
4318 char_u *startarg;
4319 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4320 int nextchar; /* next non-white char after option name */
4321 int afterchar; /* character just after option name */
4322 int len;
4323 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004324 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 int key;
4326 long_u flags; /* flags for current option */
4327 char_u *varp = NULL; /* pointer to variable for current option */
4328 int did_show = FALSE; /* already showed one value */
4329 int adding; /* "opt+=arg" */
4330 int prepending; /* "opt^=arg" */
4331 int removing; /* "opt-=arg" */
4332 int cp_val = 0;
4333 char_u key_name[2];
4334
4335 if (*arg == NUL)
4336 {
4337 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004338 did_show = TRUE;
4339 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340 }
4341
4342 while (*arg != NUL) /* loop to process all options */
4343 {
4344 errmsg = NULL;
4345 startarg = arg; /* remember for error message */
4346
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004347 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4348 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 {
4350 /*
4351 * ":set all" show all options.
4352 * ":set all&" set all options to their default value.
4353 */
4354 arg += 3;
4355 if (*arg == '&')
4356 {
4357 ++arg;
4358 /* Only for :set command set global value of local options. */
4359 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004360 didset_options();
4361 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004362 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004363 }
4364 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004365 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004366 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004367 did_show = TRUE;
4368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004369 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004370 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 {
4372 showoptions(2, opt_flags);
4373 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004374 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 arg += 7;
4376 }
4377 else
4378 {
4379 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004380 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004381 {
4382 prefix = 0;
4383 arg += 2;
4384 }
4385 else if (STRNCMP(arg, "inv", 3) == 0)
4386 {
4387 prefix = 2;
4388 arg += 3;
4389 }
4390
4391 /* find end of name */
4392 key = 0;
4393 if (*arg == '<')
4394 {
4395 nextchar = 0;
4396 opt_idx = -1;
4397 /* look out for <t_>;> */
4398 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4399 len = 5;
4400 else
4401 {
4402 len = 1;
4403 while (arg[len] != NUL && arg[len] != '>')
4404 ++len;
4405 }
4406 if (arg[len] != '>')
4407 {
4408 errmsg = e_invarg;
4409 goto skip;
4410 }
4411 arg[len] = NUL; /* put NUL after name */
4412 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4413 opt_idx = findoption(arg + 1);
4414 arg[len++] = '>'; /* restore '>' */
4415 if (opt_idx == -1)
4416 key = find_key_option(arg + 1);
4417 }
4418 else
4419 {
4420 len = 0;
4421 /*
4422 * The two characters after "t_" may not be alphanumeric.
4423 */
4424 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4425 len = 4;
4426 else
4427 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4428 ++len;
4429 nextchar = arg[len];
4430 arg[len] = NUL; /* put NUL after name */
4431 opt_idx = findoption(arg);
4432 arg[len] = nextchar; /* restore nextchar */
4433 if (opt_idx == -1)
4434 key = find_key_option(arg);
4435 }
4436
4437 /* remember character after option name */
4438 afterchar = arg[len];
4439
4440 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004441 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004442 ++len;
4443
4444 adding = FALSE;
4445 prepending = FALSE;
4446 removing = FALSE;
4447 if (arg[len] != NUL && arg[len + 1] == '=')
4448 {
4449 if (arg[len] == '+')
4450 {
4451 adding = TRUE; /* "+=" */
4452 ++len;
4453 }
4454 else if (arg[len] == '^')
4455 {
4456 prepending = TRUE; /* "^=" */
4457 ++len;
4458 }
4459 else if (arg[len] == '-')
4460 {
4461 removing = TRUE; /* "-=" */
4462 ++len;
4463 }
4464 }
4465 nextchar = arg[len];
4466
4467 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4468 {
4469 errmsg = (char_u *)N_("E518: Unknown option");
4470 goto skip;
4471 }
4472
4473 if (opt_idx >= 0)
4474 {
4475 if (options[opt_idx].var == NULL) /* hidden option: skip */
4476 {
4477 /* Only give an error message when requesting the value of
4478 * a hidden option, ignore setting it. */
4479 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4480 && (!(options[opt_idx].flags & P_BOOL)
4481 || nextchar == '?'))
4482 errmsg = (char_u *)N_("E519: Option not supported");
4483 goto skip;
4484 }
4485
4486 flags = options[opt_idx].flags;
4487 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4488 }
4489 else
4490 {
4491 flags = P_STRING;
4492 if (key < 0)
4493 {
4494 key_name[0] = KEY2TERMCAP0(key);
4495 key_name[1] = KEY2TERMCAP1(key);
4496 }
4497 else
4498 {
4499 key_name[0] = KS_KEY;
4500 key_name[1] = (key & 0xff);
4501 }
4502 }
4503
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004504 /* Skip all options that are not window-local (used when showing
4505 * an already loaded buffer in a window). */
4506 if ((opt_flags & OPT_WINONLY)
4507 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4508 goto skip;
4509
Bram Moolenaara3227e22006-03-08 21:32:40 +00004510 /* Skip all options that are window-local (used for :vimgrep). */
4511 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4512 && options[opt_idx].var == VAR_WIN)
4513 goto skip;
4514
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004515 /* Disallow changing some options from modelines. */
4516 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004517 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004518 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004519 {
4520 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4521 goto skip;
4522 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004523#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004524 /* In diff mode some options are overruled. This avoids that
4525 * 'foldmethod' becomes "marker" instead of "diff" and that
4526 * "wrap" gets set. */
4527 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004528 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004529 && (
4530#ifdef FEAT_FOLDING
4531 options[opt_idx].indir == PV_FDM ||
4532#endif
4533 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004534 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004535#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004536 }
4537
4538#ifdef HAVE_SANDBOX
4539 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004540 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004541 {
4542 errmsg = (char_u *)_(e_sandbox);
4543 goto skip;
4544 }
4545#endif
4546
4547 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4548 {
4549 arg += len;
4550 cp_val = p_cp;
4551 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4552 {
4553 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4554 {
4555 cp_val = FALSE;
4556 arg += 3;
4557 }
4558 else /* "opt&vi": set to Vi default */
4559 {
4560 cp_val = TRUE;
4561 arg += 2;
4562 }
4563 }
4564 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004565 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004566 {
4567 errmsg = e_trailing;
4568 goto skip;
4569 }
4570 }
4571
4572 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004573 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4574 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575 */
4576 if (nextchar == '?'
4577 || (prefix == 1
4578 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4579 && !(flags & P_BOOL)))
4580 {
4581 /*
4582 * print value
4583 */
4584 if (did_show)
4585 msg_putchar('\n'); /* cursor below last one */
4586 else
4587 {
4588 gotocmdline(TRUE); /* cursor at status line */
4589 did_show = TRUE; /* remember that we did a line */
4590 }
4591 if (opt_idx >= 0)
4592 {
4593 showoneopt(&options[opt_idx], opt_flags);
4594#ifdef FEAT_EVAL
4595 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004596 {
4597 /* Mention where the option was last set. */
4598 if (varp == options[opt_idx].var)
4599 last_set_msg(options[opt_idx].scriptID);
4600 else if ((int)options[opt_idx].indir & PV_WIN)
4601 last_set_msg(curwin->w_p_scriptID[
4602 (int)options[opt_idx].indir & PV_MASK]);
4603 else if ((int)options[opt_idx].indir & PV_BUF)
4604 last_set_msg(curbuf->b_p_scriptID[
4605 (int)options[opt_idx].indir & PV_MASK]);
4606 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004607#endif
4608 }
4609 else
4610 {
4611 char_u *p;
4612
4613 p = find_termcode(key_name);
4614 if (p == NULL)
4615 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004616 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 goto skip;
4618 }
4619 else
4620 (void)show_one_termcode(key_name, p, TRUE);
4621 }
4622 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004623 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004624 errmsg = e_trailing;
4625 }
4626 else
4627 {
4628 if (flags & P_BOOL) /* boolean */
4629 {
4630 if (nextchar == '=' || nextchar == ':')
4631 {
4632 errmsg = e_invarg;
4633 goto skip;
4634 }
4635
4636 /*
4637 * ":set opt!": invert
4638 * ":set opt&": reset to default value
4639 * ":set opt<": reset to global value
4640 */
4641 if (nextchar == '!')
4642 value = *(int *)(varp) ^ 1;
4643 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004644 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004645 ((flags & P_VI_DEF) || cp_val)
4646 ? VI_DEFAULT : VIM_DEFAULT];
4647 else if (nextchar == '<')
4648 {
4649 /* For 'autoread' -1 means to use global value. */
4650 if ((int *)varp == &curbuf->b_p_ar
4651 && opt_flags == OPT_LOCAL)
4652 value = -1;
4653 else
4654 value = *(int *)get_varp_scope(&(options[opt_idx]),
4655 OPT_GLOBAL);
4656 }
4657 else
4658 {
4659 /*
4660 * ":set invopt": invert
4661 * ":set opt" or ":set noopt": set or reset
4662 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004663 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004664 {
4665 errmsg = e_trailing;
4666 goto skip;
4667 }
4668 if (prefix == 2) /* inv */
4669 value = *(int *)(varp) ^ 1;
4670 else
4671 value = prefix;
4672 }
4673
4674 errmsg = set_bool_option(opt_idx, varp, (int)value,
4675 opt_flags);
4676 }
4677 else /* numeric or string */
4678 {
4679 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4680 || prefix != 1)
4681 {
4682 errmsg = e_invarg;
4683 goto skip;
4684 }
4685
4686 if (flags & P_NUM) /* numeric */
4687 {
4688 /*
4689 * Different ways to set a number option:
4690 * & set to default value
4691 * < set to global value
4692 * <xx> accept special key codes for 'wildchar'
4693 * c accept any non-digit for 'wildchar'
4694 * [-]0-9 set number
4695 * other error
4696 */
4697 ++arg;
4698 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004699 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004700 ((flags & P_VI_DEF) || cp_val)
4701 ? VI_DEFAULT : VIM_DEFAULT];
4702 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004703 {
4704 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4705 * use the global value. */
4706 if ((long *)varp == &curbuf->b_p_ul
4707 && opt_flags == OPT_LOCAL)
4708 value = NO_LOCAL_UNDOLEVEL;
4709 else
4710 value = *(long *)get_varp_scope(
4711 &(options[opt_idx]), OPT_GLOBAL);
4712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004713 else if (((long *)varp == &p_wc
4714 || (long *)varp == &p_wcm)
4715 && (*arg == '<'
4716 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004717 || (*arg != NUL
4718 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 && !VIM_ISDIGIT(*arg))))
4720 {
4721 value = string_to_key(arg);
4722 if (value == 0 && (long *)varp != &p_wcm)
4723 {
4724 errmsg = e_invarg;
4725 goto skip;
4726 }
4727 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004728 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4729 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004730 /* Allow negative (for 'undolevels'), octal and
4731 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004732 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4733 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004734 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004735 {
4736 errmsg = e_invarg;
4737 goto skip;
4738 }
4739 }
4740 else
4741 {
4742 errmsg = (char_u *)N_("E521: Number required after =");
4743 goto skip;
4744 }
4745
4746 if (adding)
4747 value = *(long *)varp + value;
4748 if (prepending)
4749 value = *(long *)varp * value;
4750 if (removing)
4751 value = *(long *)varp - value;
4752 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004753 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004754 }
4755 else if (opt_idx >= 0) /* string */
4756 {
4757 char_u *save_arg = NULL;
4758 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004759 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004761 char_u *origval = NULL;
4762#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4763 char_u *saved_origval = NULL;
4764#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004765 unsigned newlen;
4766 int comma;
4767 int bs;
4768 int new_value_alloced; /* new string option
4769 was allocated */
4770
4771 /* When using ":set opt=val" for a global option
4772 * with a local value the local value will be
4773 * reset, use the global value here. */
4774 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004775 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004776 varp = options[opt_idx].var;
4777
4778 /* The old value is kept until we are sure that the
4779 * new value is valid. */
4780 oldval = *(char_u **)varp;
4781 if (nextchar == '&') /* set to default val */
4782 {
4783 newval = options[opt_idx].def_val[
4784 ((flags & P_VI_DEF) || cp_val)
4785 ? VI_DEFAULT : VIM_DEFAULT];
4786 if ((char_u **)varp == &p_bg)
4787 {
4788 /* guess the value of 'background' */
4789#ifdef FEAT_GUI
4790 if (gui.in_use)
4791 newval = gui_bg_default();
4792 else
4793#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004794 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 }
4796
4797 /* expand environment variables and ~ (since the
4798 * default value was already expanded, only
4799 * required when an environment variable was set
4800 * later */
4801 if (newval == NULL)
4802 newval = empty_option;
4803 else
4804 {
4805 s = option_expand(opt_idx, newval);
4806 if (s == NULL)
4807 s = newval;
4808 newval = vim_strsave(s);
4809 }
4810 new_value_alloced = TRUE;
4811 }
4812 else if (nextchar == '<') /* set to global val */
4813 {
4814 newval = vim_strsave(*(char_u **)get_varp_scope(
4815 &(options[opt_idx]), OPT_GLOBAL));
4816 new_value_alloced = TRUE;
4817 }
4818 else
4819 {
4820 ++arg; /* jump to after the '=' or ':' */
4821
4822 /*
4823 * Set 'keywordprg' to ":help" if an empty
4824 * value was passed to :set by the user.
4825 * Misuse errbuf[] for the resulting string.
4826 */
4827 if (varp == (char_u *)&p_kp
4828 && (*arg == NUL || *arg == ' '))
4829 {
4830 STRCPY(errbuf, ":help");
4831 save_arg = arg;
4832 arg = errbuf;
4833 }
4834 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004835 * Convert 'backspace' number to string, for
4836 * adding, prepending and removing string.
4837 */
4838 else if (varp == (char_u *)&p_bs
4839 && VIM_ISDIGIT(**(char_u **)varp))
4840 {
4841 i = getdigits((char_u **)varp);
4842 switch (i)
4843 {
4844 case 0:
4845 *(char_u **)varp = empty_option;
4846 break;
4847 case 1:
4848 *(char_u **)varp = vim_strsave(
4849 (char_u *)"indent,eol");
4850 break;
4851 case 2:
4852 *(char_u **)varp = vim_strsave(
4853 (char_u *)"indent,eol,start");
4854 break;
4855 }
4856 vim_free(oldval);
4857 oldval = *(char_u **)varp;
4858 }
4859 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 * Convert 'whichwrap' number to string, for
4861 * backwards compatibility with Vim 3.0.
4862 * Misuse errbuf[] for the resulting string.
4863 */
4864 else if (varp == (char_u *)&p_ww
4865 && VIM_ISDIGIT(*arg))
4866 {
4867 *errbuf = NUL;
4868 i = getdigits(&arg);
4869 if (i & 1)
4870 STRCAT(errbuf, "b,");
4871 if (i & 2)
4872 STRCAT(errbuf, "s,");
4873 if (i & 4)
4874 STRCAT(errbuf, "h,l,");
4875 if (i & 8)
4876 STRCAT(errbuf, "<,>,");
4877 if (i & 16)
4878 STRCAT(errbuf, "[,],");
4879 if (*errbuf != NUL) /* remove trailing , */
4880 errbuf[STRLEN(errbuf) - 1] = NUL;
4881 save_arg = arg;
4882 arg = errbuf;
4883 }
4884 /*
4885 * Remove '>' before 'dir' and 'bdir', for
4886 * backwards compatibility with version 3.0
4887 */
4888 else if ( *arg == '>'
4889 && (varp == (char_u *)&p_dir
4890 || varp == (char_u *)&p_bdir))
4891 {
4892 ++arg;
4893 }
4894
4895 /* When setting the local value of a global
4896 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004897 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004898 && (opt_flags & OPT_LOCAL))
4899 origval = *(char_u **)get_varp(
4900 &options[opt_idx]);
4901 else
4902 origval = oldval;
4903
4904 /*
4905 * Copy the new string into allocated memory.
4906 * Can't use set_string_option_direct(), because
4907 * we need to remove the backslashes.
4908 */
4909 /* get a bit too much */
4910 newlen = (unsigned)STRLEN(arg) + 1;
4911 if (adding || prepending || removing)
4912 newlen += (unsigned)STRLEN(origval) + 1;
4913 newval = alloc(newlen);
4914 if (newval == NULL) /* out of mem, don't change */
4915 break;
4916 s = newval;
4917
4918 /*
4919 * Copy the string, skip over escaped chars.
4920 * For MS-DOS and WIN32 backslashes before normal
4921 * file name characters are not removed, and keep
4922 * backslash at start, for "\\machine\path", but
4923 * do remove it for "\\\\machine\\path".
4924 * The reverse is found in ExpandOldSetting().
4925 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004926 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004927 {
4928 if (*arg == '\\' && arg[1] != NUL
4929#ifdef BACKSLASH_IN_FILENAME
4930 && !((flags & P_EXPAND)
4931 && vim_isfilec(arg[1])
4932 && (arg[1] != '\\'
4933 || (s == newval
4934 && arg[2] != '\\')))
4935#endif
4936 )
4937 ++arg; /* remove backslash */
4938#ifdef FEAT_MBYTE
4939 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004940 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004941 {
4942 /* copy multibyte char */
4943 mch_memmove(s, arg, (size_t)i);
4944 arg += i;
4945 s += i;
4946 }
4947 else
4948#endif
4949 *s++ = *arg++;
4950 }
4951 *s = NUL;
4952
4953 /*
4954 * Expand environment variables and ~.
4955 * Don't do it when adding without inserting a
4956 * comma.
4957 */
4958 if (!(adding || prepending || removing)
4959 || (flags & P_COMMA))
4960 {
4961 s = option_expand(opt_idx, newval);
4962 if (s != NULL)
4963 {
4964 vim_free(newval);
4965 newlen = (unsigned)STRLEN(s) + 1;
4966 if (adding || prepending || removing)
4967 newlen += (unsigned)STRLEN(origval) + 1;
4968 newval = alloc(newlen);
4969 if (newval == NULL)
4970 break;
4971 STRCPY(newval, s);
4972 }
4973 }
4974
4975 /* locate newval[] in origval[] when removing it
4976 * and when adding to avoid duplicates */
4977 i = 0; /* init for GCC */
4978 if (removing || (flags & P_NODUP))
4979 {
4980 i = (int)STRLEN(newval);
4981 bs = 0;
4982 for (s = origval; *s; ++s)
4983 {
4984 if ((!(flags & P_COMMA)
4985 || s == origval
4986 || (s[-1] == ',' && !(bs & 1)))
4987 && STRNCMP(s, newval, i) == 0
4988 && (!(flags & P_COMMA)
4989 || s[i] == ','
4990 || s[i] == NUL))
4991 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004992 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004993 * even number of backslashes or a single
4994 * backslash preceded by a comma before it
4995 * is recognized as a separator */
4996 if ((s > origval + 1
4997 && s[-1] == '\\'
4998 && s[-2] != ',')
4999 || (s == origval + 1
5000 && s[-1] == '\\'))
5001
Bram Moolenaar071d4272004-06-13 20:20:40 +00005002 ++bs;
5003 else
5004 bs = 0;
5005 }
5006
5007 /* do not add if already there */
5008 if ((adding || prepending) && *s)
5009 {
5010 prepending = FALSE;
5011 adding = FALSE;
5012 STRCPY(newval, origval);
5013 }
5014 }
5015
5016 /* concatenate the two strings; add a ',' if
5017 * needed */
5018 if (adding || prepending)
5019 {
5020 comma = ((flags & P_COMMA) && *origval != NUL
5021 && *newval != NUL);
5022 if (adding)
5023 {
5024 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005025 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005026 if (comma && i > 1
5027 && (flags & P_ONECOMMA) == P_ONECOMMA
5028 && origval[i - 1] == ','
5029 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005030 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005031 mch_memmove(newval + i + comma, newval,
5032 STRLEN(newval) + 1);
5033 mch_memmove(newval, origval, (size_t)i);
5034 }
5035 else
5036 {
5037 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005038 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005039 }
5040 if (comma)
5041 newval[i] = ',';
5042 }
5043
5044 /* Remove newval[] from origval[]. (Note: "i" has
5045 * been set above and is used here). */
5046 if (removing)
5047 {
5048 STRCPY(newval, origval);
5049 if (*s)
5050 {
5051 /* may need to remove a comma */
5052 if (flags & P_COMMA)
5053 {
5054 if (s == origval)
5055 {
5056 /* include comma after string */
5057 if (s[i] == ',')
5058 ++i;
5059 }
5060 else
5061 {
5062 /* include comma before string */
5063 --s;
5064 ++i;
5065 }
5066 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005067 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005068 }
5069 }
5070
5071 if (flags & P_FLAGLIST)
5072 {
5073 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005074 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005075 {
5076 /* if options have P_FLAGLIST and
5077 * P_ONECOMMA such as 'whichwrap' */
5078 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005079 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005080 if (*s != ',' && *(s + 1) == ','
5081 && vim_strchr(s + 2, *s) != NULL)
5082 {
5083 /* Remove the duplicated value and
5084 * the next comma. */
5085 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005086 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005088 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005089 else
5090 {
5091 if ((!(flags & P_COMMA) || *s != ',')
5092 && vim_strchr(s + 1, *s) != NULL)
5093 {
5094 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005095 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005096 }
5097 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005098 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 }
5101
5102 if (save_arg != NULL) /* number for 'whichwrap' */
5103 arg = save_arg;
5104 new_value_alloced = TRUE;
5105 }
5106
5107 /* Set the new value. */
5108 *(char_u **)(varp) = newval;
5109
Bram Moolenaar53744302015-07-17 17:38:22 +02005110#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005111 if (!starting
5112# ifdef FEAT_CRYPT
5113 && options[opt_idx].indir != PV_KEY
5114# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02005115 && origval != NULL)
5116 /* origval may be freed by
5117 * did_set_string_option(), make a copy. */
5118 saved_origval = vim_strsave(origval);
5119#endif
5120
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121 /* Handle side effects, and set the global value for
5122 * ":set" on local options. */
5123 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5124 new_value_alloced, oldval, errbuf, opt_flags);
5125
5126 /* If error detected, print the error message. */
5127 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005128 {
5129#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5130 vim_free(saved_origval);
5131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005132 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005133 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005134#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5135 if (saved_origval != NULL)
5136 {
5137 char_u buf_type[7];
5138
5139 sprintf((char *)buf_type, "%s",
5140 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005141 set_vim_var_string(VV_OPTION_NEW,
5142 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005143 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5144 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5145 apply_autocmds(EVENT_OPTIONSET,
5146 (char_u *)options[opt_idx].fullname,
5147 NULL, FALSE, NULL);
5148 reset_v_option_vars();
5149 vim_free(saved_origval);
5150 }
5151#endif
5152
Bram Moolenaar071d4272004-06-13 20:20:40 +00005153 }
5154 else /* key code option */
5155 {
5156 char_u *p;
5157
5158 if (nextchar == '&')
5159 {
5160 if (add_termcap_entry(key_name, TRUE) == FAIL)
5161 errmsg = (char_u *)N_("E522: Not found in termcap");
5162 }
5163 else
5164 {
5165 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005166 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167 if (*p == '\\' && p[1] != NUL)
5168 ++p;
5169 nextchar = *p;
5170 *p = NUL;
5171 add_termcode(key_name, arg, FALSE);
5172 *p = nextchar;
5173 }
5174 if (full_screen)
5175 ttest(FALSE);
5176 redraw_all_later(CLEAR);
5177 }
5178 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005179
Bram Moolenaar071d4272004-06-13 20:20:40 +00005180 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005181 did_set_option(opt_idx, opt_flags,
5182 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005183 }
5184
5185skip:
5186 /*
5187 * Advance to next argument.
5188 * - skip until a blank found, taking care of backslashes
5189 * - skip blanks
5190 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5191 */
5192 for (i = 0; i < 2 ; ++i)
5193 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005194 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 if (*arg++ == '\\' && *arg != NUL)
5196 ++arg;
5197 arg = skipwhite(arg);
5198 if (*arg != '=')
5199 break;
5200 }
5201 }
5202
5203 if (errmsg != NULL)
5204 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005205 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005206 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005207 if (i + (arg - startarg) < IOSIZE)
5208 {
5209 /* append the argument with the error */
5210 STRCAT(IObuff, ": ");
5211 mch_memmove(IObuff + i, startarg, (arg - startarg));
5212 IObuff[i + (arg - startarg)] = NUL;
5213 }
5214 /* make sure all characters are printable */
5215 trans_characters(IObuff, IOSIZE);
5216
5217 ++no_wait_return; /* wait_return done later */
5218 emsg(IObuff); /* show error highlighted */
5219 --no_wait_return;
5220
5221 return FAIL;
5222 }
5223
5224 arg = skipwhite(arg);
5225 }
5226
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005227theend:
5228 if (silent_mode && did_show)
5229 {
5230 /* After displaying option values in silent mode. */
5231 silent_mode = FALSE;
5232 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5233 msg_putchar('\n');
5234 cursor_on(); /* msg_start() switches it off */
5235 out_flush();
5236 silent_mode = TRUE;
5237 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5238 }
5239
Bram Moolenaar071d4272004-06-13 20:20:40 +00005240 return OK;
5241}
5242
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005243/*
5244 * Call this when an option has been given a new value through a user command.
5245 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5246 */
5247 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005248did_set_option(
5249 int opt_idx,
5250 int opt_flags, /* possibly with OPT_MODELINE */
5251 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005252{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005253 long_u *p;
5254
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005255 options[opt_idx].flags |= P_WAS_SET;
5256
5257 /* When an option is set in the sandbox, from a modeline or in secure mode
5258 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005259 * flag. */
5260 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005261 if (secure
5262#ifdef HAVE_SANDBOX
5263 || sandbox != 0
5264#endif
5265 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005266 *p = *p | P_INSECURE;
5267 else if (new_value)
5268 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005269}
5270
Bram Moolenaar071d4272004-06-13 20:20:40 +00005271 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005272illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273{
5274 if (errbuf == NULL)
5275 return (char_u *)"";
5276 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005277 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005278 return errbuf;
5279}
5280
5281/*
5282 * Convert a key name or string into a key value.
5283 * Used for 'wildchar' and 'cedit' options.
5284 */
5285 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005286string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005287{
5288 if (*arg == '<')
5289 return find_key_option(arg + 1);
5290 if (*arg == '^')
5291 return Ctrl_chr(arg[1]);
5292 return *arg;
5293}
5294
5295#ifdef FEAT_CMDWIN
5296/*
5297 * Check value of 'cedit' and set cedit_key.
5298 * Returns NULL if value is OK, error message otherwise.
5299 */
5300 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005301check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005302{
5303 int n;
5304
5305 if (*p_cedit == NUL)
5306 cedit_key = -1;
5307 else
5308 {
5309 n = string_to_key(p_cedit);
5310 if (vim_isprintc(n))
5311 return e_invarg;
5312 cedit_key = n;
5313 }
5314 return NULL;
5315}
5316#endif
5317
5318#ifdef FEAT_TITLE
5319/*
5320 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5321 * maketitle() to create and display it.
5322 * When switching the title or icon off, call mch_restore_title() to get
5323 * the old value back.
5324 */
5325 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005326did_set_title(
5327 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328{
5329 if (starting != NO_SCREEN
5330#ifdef FEAT_GUI
5331 && !gui.starting
5332#endif
5333 )
5334 {
5335 maketitle();
5336 if (icon)
5337 {
5338 if (!p_icon)
5339 mch_restore_title(2);
5340 }
5341 else
5342 {
5343 if (!p_title)
5344 mch_restore_title(1);
5345 }
5346 }
5347}
5348#endif
5349
5350/*
5351 * set_options_bin - called when 'bin' changes value.
5352 */
5353 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005354set_options_bin(
5355 int oldval,
5356 int newval,
5357 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358{
5359 /*
5360 * The option values that are changed when 'bin' changes are
5361 * copied when 'bin is set and restored when 'bin' is reset.
5362 */
5363 if (newval)
5364 {
5365 if (!oldval) /* switched on */
5366 {
5367 if (!(opt_flags & OPT_GLOBAL))
5368 {
5369 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5370 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5371 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5372 curbuf->b_p_et_nobin = curbuf->b_p_et;
5373 }
5374 if (!(opt_flags & OPT_LOCAL))
5375 {
5376 p_tw_nobin = p_tw;
5377 p_wm_nobin = p_wm;
5378 p_ml_nobin = p_ml;
5379 p_et_nobin = p_et;
5380 }
5381 }
5382
5383 if (!(opt_flags & OPT_GLOBAL))
5384 {
5385 curbuf->b_p_tw = 0; /* no automatic line wrap */
5386 curbuf->b_p_wm = 0; /* no automatic line wrap */
5387 curbuf->b_p_ml = 0; /* no modelines */
5388 curbuf->b_p_et = 0; /* no expandtab */
5389 }
5390 if (!(opt_flags & OPT_LOCAL))
5391 {
5392 p_tw = 0;
5393 p_wm = 0;
5394 p_ml = FALSE;
5395 p_et = FALSE;
5396 p_bin = TRUE; /* needed when called for the "-b" argument */
5397 }
5398 }
5399 else if (oldval) /* switched off */
5400 {
5401 if (!(opt_flags & OPT_GLOBAL))
5402 {
5403 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5404 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5405 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5406 curbuf->b_p_et = curbuf->b_p_et_nobin;
5407 }
5408 if (!(opt_flags & OPT_LOCAL))
5409 {
5410 p_tw = p_tw_nobin;
5411 p_wm = p_wm_nobin;
5412 p_ml = p_ml_nobin;
5413 p_et = p_et_nobin;
5414 }
5415 }
5416}
5417
5418#ifdef FEAT_VIMINFO
5419/*
5420 * Find the parameter represented by the given character (eg ', :, ", or /),
5421 * and return its associated value in the 'viminfo' string.
5422 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005423 * If the parameter is not specified in the string or there is no following
5424 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005425 */
5426 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005427get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005428{
5429 char_u *p;
5430
5431 p = find_viminfo_parameter(type);
5432 if (p != NULL && VIM_ISDIGIT(*p))
5433 return atoi((char *)p);
5434 return -1;
5435}
5436
5437/*
5438 * Find the parameter represented by the given character (eg ''', ':', '"', or
5439 * '/') in the 'viminfo' option and return a pointer to the string after it.
5440 * Return NULL if the parameter is not specified in the string.
5441 */
5442 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005443find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005444{
5445 char_u *p;
5446
5447 for (p = p_viminfo; *p; ++p)
5448 {
5449 if (*p == type)
5450 return p + 1;
5451 if (*p == 'n') /* 'n' is always the last one */
5452 break;
5453 p = vim_strchr(p, ','); /* skip until next ',' */
5454 if (p == NULL) /* hit the end without finding parameter */
5455 break;
5456 }
5457 return NULL;
5458}
5459#endif
5460
5461/*
5462 * Expand environment variables for some string options.
5463 * These string options cannot be indirect!
5464 * If "val" is NULL expand the current value of the option.
5465 * Return pointer to NameBuff, or NULL when not expanded.
5466 */
5467 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005468option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005469{
5470 /* if option doesn't need expansion nothing to do */
5471 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5472 return NULL;
5473
5474 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5475 * expand_env() would truncate the string. */
5476 if (val != NULL && STRLEN(val) > MAXPATHL)
5477 return NULL;
5478
5479 if (val == NULL)
5480 val = *(char_u **)options[opt_idx].var;
5481
5482 /*
5483 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5484 * Escape spaces when expanding 'tags', they are used to separate file
5485 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005486 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005487 */
5488 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005489 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005490#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005491 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5492#endif
5493 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5495 return NULL;
5496
5497 return NameBuff;
5498}
5499
5500/*
5501 * After setting various option values: recompute variables that depend on
5502 * option values.
5503 */
5504 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005505didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005506{
5507 /* initialize the table for 'iskeyword' et.al. */
5508 (void)init_chartab();
5509
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005510#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005514 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005515#ifdef FEAT_SESSION
5516 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5517 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5518#endif
5519#ifdef FEAT_FOLDING
5520 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5521#endif
5522 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005523 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005524#ifdef FEAT_VIRTUALEDIT
5525 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5526#endif
5527#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5528 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5529#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005530#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005531 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005532 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005533 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005534 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005535#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5537 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5538#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005539#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5541#endif
5542#ifdef FEAT_CMDWIN
5543 /* set cedit_key */
5544 (void)check_cedit();
5545#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005546#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005547 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005548#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005549#ifdef FEAT_LINEBREAK
5550 /* initialize the table for 'breakat'. */
5551 fill_breakat_flags();
5552#endif
5553
5554}
5555
5556/*
5557 * More side effects of setting options.
5558 */
5559 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005560didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005561{
5562 /* Initialize the highlight_attr[] table. */
5563 (void)highlight_changed();
5564
5565 /* Parse default for 'wildmode' */
5566 check_opt_wim();
5567
5568 (void)set_chars_option(&p_lcs);
5569#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5570 /* Parse default for 'fillchars'. */
5571 (void)set_chars_option(&p_fcs);
5572#endif
5573
5574#ifdef FEAT_CLIPBOARD
5575 /* Parse default for 'clipboard' */
5576 (void)check_clipboard_option();
5577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578}
5579
5580/*
5581 * Check for string options that are NULL (normally only termcap options).
5582 */
5583 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005584check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585{
5586 int opt_idx;
5587
5588 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5589 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5590 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5591}
5592
5593/*
5594 * Check string options in a buffer for NULL value.
5595 */
5596 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005597check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598{
5599#if defined(FEAT_QUICKFIX)
5600 check_string_option(&buf->b_p_bh);
5601 check_string_option(&buf->b_p_bt);
5602#endif
5603#ifdef FEAT_MBYTE
5604 check_string_option(&buf->b_p_fenc);
5605#endif
5606 check_string_option(&buf->b_p_ff);
5607#ifdef FEAT_FIND_ID
5608 check_string_option(&buf->b_p_def);
5609 check_string_option(&buf->b_p_inc);
5610# ifdef FEAT_EVAL
5611 check_string_option(&buf->b_p_inex);
5612# endif
5613#endif
5614#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5615 check_string_option(&buf->b_p_inde);
5616 check_string_option(&buf->b_p_indk);
5617#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005618#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5619 check_string_option(&buf->b_p_bexpr);
5620#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005621#if defined(FEAT_CRYPT)
5622 check_string_option(&buf->b_p_cm);
5623#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005624 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005625#if defined(FEAT_EVAL)
5626 check_string_option(&buf->b_p_fex);
5627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628#ifdef FEAT_CRYPT
5629 check_string_option(&buf->b_p_key);
5630#endif
5631 check_string_option(&buf->b_p_kp);
5632 check_string_option(&buf->b_p_mps);
5633 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005634 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005635 check_string_option(&buf->b_p_isk);
5636#ifdef FEAT_COMMENTS
5637 check_string_option(&buf->b_p_com);
5638#endif
5639#ifdef FEAT_FOLDING
5640 check_string_option(&buf->b_p_cms);
5641#endif
5642 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005643#ifdef FEAT_TEXTOBJ
5644 check_string_option(&buf->b_p_qe);
5645#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646#ifdef FEAT_SYN_HL
5647 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005648 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005649#endif
5650#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005651 check_string_option(&buf->b_s.b_p_spc);
5652 check_string_option(&buf->b_s.b_p_spf);
5653 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654#endif
5655#ifdef FEAT_SEARCHPATH
5656 check_string_option(&buf->b_p_sua);
5657#endif
5658#ifdef FEAT_CINDENT
5659 check_string_option(&buf->b_p_cink);
5660 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005661 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662#endif
5663#ifdef FEAT_AUTOCMD
5664 check_string_option(&buf->b_p_ft);
5665#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5667 check_string_option(&buf->b_p_cinw);
5668#endif
5669#ifdef FEAT_INS_EXPAND
5670 check_string_option(&buf->b_p_cpt);
5671#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005672#ifdef FEAT_COMPL_FUNC
5673 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005674 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005675#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676#ifdef FEAT_KEYMAP
5677 check_string_option(&buf->b_p_keymap);
5678#endif
5679#ifdef FEAT_QUICKFIX
5680 check_string_option(&buf->b_p_gp);
5681 check_string_option(&buf->b_p_mp);
5682 check_string_option(&buf->b_p_efm);
5683#endif
5684 check_string_option(&buf->b_p_ep);
5685 check_string_option(&buf->b_p_path);
5686 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005687 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688#ifdef FEAT_INS_EXPAND
5689 check_string_option(&buf->b_p_dict);
5690 check_string_option(&buf->b_p_tsr);
5691#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005692#ifdef FEAT_LISP
5693 check_string_option(&buf->b_p_lw);
5694#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005695 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005696#ifdef FEAT_MBYTE
5697 check_string_option(&buf->b_p_menc);
5698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699}
5700
5701/*
5702 * Free the string allocated for an option.
5703 * Checks for the string being empty_option. This may happen if we're out of
5704 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5705 * check_options().
5706 * Does NOT check for P_ALLOCED flag!
5707 */
5708 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005709free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710{
5711 if (p != empty_option)
5712 vim_free(p);
5713}
5714
5715 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005716clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717{
5718 if (*pp != empty_option)
5719 vim_free(*pp);
5720 *pp = empty_option;
5721}
5722
5723 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005724check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725{
5726 if (*pp == NULL)
5727 *pp = empty_option;
5728}
5729
5730/*
5731 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5732 */
5733 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005734set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735{
5736 int opt_idx;
5737
5738 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5739 if (options[opt_idx].var == (char_u *)p)
5740 {
5741 options[opt_idx].flags |= P_ALLOCED;
5742 return;
5743 }
5744 return; /* cannot happen: didn't find it! */
5745}
5746
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005747#if defined(FEAT_EVAL) || defined(PROTO)
5748/*
5749 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5750 * Return FALSE when it wasn't.
5751 * Return -1 for an unknown option.
5752 */
5753 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005754was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005755{
5756 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005757 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005758
5759 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005760 {
5761 flagp = insecure_flag(idx, opt_flags);
5762 return (*flagp & P_INSECURE) != 0;
5763 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005764 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005765 return -1;
5766}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005767
5768/*
5769 * Get a pointer to the flags used for the P_INSECURE flag of option
5770 * "opt_idx". For some local options a local flags field is used.
5771 */
5772 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005773insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005774{
5775 if (opt_flags & OPT_LOCAL)
5776 switch ((int)options[opt_idx].indir)
5777 {
5778#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005779 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005780#endif
5781#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005782# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005783 case PV_FDE: return &curwin->w_p_fde_flags;
5784 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005785# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005786# ifdef FEAT_BEVAL
5787 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5788# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005789# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005790 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005791# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005792 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005793# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005794 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005795# endif
5796#endif
5797 }
5798
5799 /* Nothing special, return global flags field. */
5800 return &options[opt_idx].flags;
5801}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005802#endif
5803
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005804#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005805static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005806
5807/*
5808 * Redraw the window title and/or tab page text later.
5809 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005810static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005811{
5812 need_maketitle = TRUE;
5813# ifdef FEAT_WINDOWS
5814 redraw_tabline = TRUE;
5815# endif
5816}
5817#endif
5818
Bram Moolenaar071d4272004-06-13 20:20:40 +00005819/*
5820 * Set a string option to a new value (without checking the effect).
5821 * The string is copied into allocated memory.
5822 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005823 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005824 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005825 */
5826 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005827set_string_option_direct(
5828 char_u *name,
5829 int opt_idx,
5830 char_u *val,
5831 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5832 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005833{
5834 char_u *s;
5835 char_u **varp;
5836 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005837 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838
Bram Moolenaar89d40322006-08-29 15:30:07 +00005839 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005840 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005841 idx = findoption(name);
5842 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005843 {
5844 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005845 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005847 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 }
5849
Bram Moolenaar89d40322006-08-29 15:30:07 +00005850 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005851 return;
5852
5853 s = vim_strsave(val);
5854 if (s != NULL)
5855 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005856 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005858 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859 free_string_option(*varp);
5860 *varp = s;
5861
5862 /* For buffer/window local option may also set the global value. */
5863 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005864 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865
Bram Moolenaar89d40322006-08-29 15:30:07 +00005866 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867
5868 /* When setting both values of a global option with a local value,
5869 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005870 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871 {
5872 free_string_option(*varp);
5873 *varp = empty_option;
5874 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005875# ifdef FEAT_EVAL
5876 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005877 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005878 set_sid == 0 ? current_SID : set_sid);
5879# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 }
5881}
5882
5883/*
5884 * Set global value for string option when it's a local option.
5885 */
5886 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005887set_string_option_global(
5888 int opt_idx, /* option index */
5889 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890{
5891 char_u **p, *s;
5892
5893 /* the global value is always allocated */
5894 if (options[opt_idx].var == VAR_WIN)
5895 p = (char_u **)GLOBAL_WO(varp);
5896 else
5897 p = (char_u **)options[opt_idx].var;
5898 if (options[opt_idx].indir != PV_NONE
5899 && p != varp
5900 && (s = vim_strsave(*varp)) != NULL)
5901 {
5902 free_string_option(*p);
5903 *p = s;
5904 }
5905}
5906
5907/*
5908 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005909 *
5910 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005912 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005913set_string_option(
5914 int opt_idx,
5915 char_u *value,
5916 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917{
5918 char_u *s;
5919 char_u **varp;
5920 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005921#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5922 char_u *saved_oldval = NULL;
5923#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005924 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925
5926 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005927 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005928
5929 s = vim_strsave(value);
5930 if (s != NULL)
5931 {
5932 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5933 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005934 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935 ? OPT_GLOBAL : OPT_LOCAL)
5936 : opt_flags);
5937 oldval = *varp;
5938 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005939
5940#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005941 if (!starting
5942# ifdef FEAT_CRYPT
5943 && options[opt_idx].indir != PV_KEY
5944# endif
5945 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005946 saved_oldval = vim_strsave(oldval);
5947#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005948 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5949 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005950 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005951
Bram Moolenaara12e4032017-02-25 21:37:57 +01005952 /* call autocommand after handling side effects */
Bram Moolenaar53744302015-07-17 17:38:22 +02005953#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5954 if (saved_oldval != NULL)
5955 {
5956 char_u buf_type[7];
5957 sprintf((char *)buf_type, "%s",
5958 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005959 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5960 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005961 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5962 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5963 reset_v_option_vars();
5964 vim_free(saved_oldval);
5965 }
5966#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005967 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005968 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969}
5970
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005971#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005972/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005973 * Return TRUE if "val" is a valid 'filetype' name.
5974 * Also used for 'syntax' and 'keymap'.
5975 */
5976 static int
5977valid_filetype(char_u *val)
5978{
5979 char_u *s;
5980
5981 for (s = val; *s != NUL; ++s)
5982 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5983 return FALSE;
5984 return TRUE;
5985}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005986#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005987
5988/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005989 * Handle string options that need some action to perform when changed.
5990 * Returns NULL for success, or an error message for an error.
5991 */
5992 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005993did_set_string_option(
5994 int opt_idx, /* index in options[] table */
5995 char_u **varp, /* pointer to the option variable */
5996 int new_value_alloced, /* new value was allocated */
5997 char_u *oldval, /* previous value of the option */
5998 char_u *errbuf, /* buffer for errors, or NULL */
5999 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000{
6001 char_u *errmsg = NULL;
6002 char_u *s, *p;
6003 int did_chartab = FALSE;
6004 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006005 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006006#ifdef FEAT_GUI
6007 /* set when changing an option that only requires a redraw in the GUI */
6008 int redraw_gui_only = FALSE;
6009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006010
6011 /* Get the global option to compare with, otherwise we would have to check
6012 * two values for all local options. */
6013 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6014
6015 /* Disallow changing some options from secure mode */
6016 if ((secure
6017#ifdef HAVE_SANDBOX
6018 || sandbox != 0
6019#endif
6020 ) && (options[opt_idx].flags & P_SECURE))
6021 {
6022 errmsg = e_secure;
6023 }
6024
Bram Moolenaar7554da42016-11-25 22:04:13 +01006025 /* Check for a "normal" directory or file name in some options. Disallow a
6026 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006027 * are often illegal in a file name. Be more permissive if "secure" is off.
6028 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006029 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006030 && vim_strpbrk(*varp, (char_u *)(secure
6031 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006032 || ((options[opt_idx].flags & P_NDNAME)
6033 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006034 {
6035 errmsg = e_invarg;
6036 }
6037
Bram Moolenaar071d4272004-06-13 20:20:40 +00006038 /* 'term' */
6039 else if (varp == &T_NAME)
6040 {
6041 if (T_NAME[0] == NUL)
6042 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6043#ifdef FEAT_GUI
6044 if (gui.in_use)
6045 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6046 else if (term_is_gui(T_NAME))
6047 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6048#endif
6049 else if (set_termname(T_NAME) == FAIL)
6050 errmsg = (char_u *)N_("E522: Not found in termcap");
6051 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006052 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006053 /* Screen colors may have changed. */
6054 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006055
6056 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6057 * P_ALLOCED flag on 'term'. */
6058 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006059 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006061 }
6062
6063 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006064 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006065 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006066 char_u *bkc = p_bkc;
6067 unsigned int *flags = &bkc_flags;
6068
6069 if (opt_flags & OPT_LOCAL)
6070 {
6071 bkc = curbuf->b_p_bkc;
6072 flags = &curbuf->b_bkc_flags;
6073 }
6074
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006075 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6076 /* make the local value empty: use the global value */
6077 *flags = 0;
6078 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006080 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6081 errmsg = e_invarg;
6082 if ((((int)*flags & BKC_AUTO) != 0)
6083 + (((int)*flags & BKC_YES) != 0)
6084 + (((int)*flags & BKC_NO) != 0) != 1)
6085 {
6086 /* Must have exactly one of "auto", "yes" and "no". */
6087 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6088 errmsg = e_invarg;
6089 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090 }
6091 }
6092
6093 /* 'backupext' and 'patchmode' */
6094 else if (varp == &p_bex || varp == &p_pm)
6095 {
6096 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6097 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6098 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6099 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006100#ifdef FEAT_LINEBREAK
6101 /* 'breakindentopt' */
6102 else if (varp == &curwin->w_p_briopt)
6103 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006104 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006105 errmsg = e_invarg;
6106 }
6107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006108
6109 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006110 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006112 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 */
6114 else if ( varp == &p_isi
6115 || varp == &(curbuf->b_p_isk)
6116 || varp == &p_isp
6117 || varp == &p_isf)
6118 {
6119 if (init_chartab() == FAIL)
6120 {
6121 did_chartab = TRUE; /* need to restore it below */
6122 errmsg = e_invarg; /* error in value */
6123 }
6124 }
6125
6126 /* 'helpfile' */
6127 else if (varp == &p_hf)
6128 {
6129 /* May compute new values for $VIM and $VIMRUNTIME */
6130 if (didset_vim)
6131 {
6132 vim_setenv((char_u *)"VIM", (char_u *)"");
6133 didset_vim = FALSE;
6134 }
6135 if (didset_vimruntime)
6136 {
6137 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6138 didset_vimruntime = FALSE;
6139 }
6140 }
6141
Bram Moolenaar1a384422010-07-14 19:53:30 +02006142#ifdef FEAT_SYN_HL
6143 /* 'colorcolumn' */
6144 else if (varp == &curwin->w_p_cc)
6145 errmsg = check_colorcolumn(curwin);
6146#endif
6147
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148#ifdef FEAT_MULTI_LANG
6149 /* 'helplang' */
6150 else if (varp == &p_hlg)
6151 {
6152 /* Check for "", "ab", "ab,cd", etc. */
6153 for (s = p_hlg; *s != NUL; s += 3)
6154 {
6155 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6156 {
6157 errmsg = e_invarg;
6158 break;
6159 }
6160 if (s[2] == NUL)
6161 break;
6162 }
6163 }
6164#endif
6165
6166 /* 'highlight' */
6167 else if (varp == &p_hl)
6168 {
6169 if (highlight_changed() == FAIL)
6170 errmsg = e_invarg; /* invalid flags */
6171 }
6172
6173 /* 'nrformats' */
6174 else if (gvarp == &p_nf)
6175 {
6176 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6177 errmsg = e_invarg;
6178 }
6179
6180#ifdef FEAT_SESSION
6181 /* 'sessionoptions' */
6182 else if (varp == &p_ssop)
6183 {
6184 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6185 errmsg = e_invarg;
6186 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6187 {
6188 /* Don't allow both "sesdir" and "curdir". */
6189 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6190 errmsg = e_invarg;
6191 }
6192 }
6193 /* 'viewoptions' */
6194 else if (varp == &p_vop)
6195 {
6196 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6197 errmsg = e_invarg;
6198 }
6199#endif
6200
6201 /* 'scrollopt' */
6202#ifdef FEAT_SCROLLBIND
6203 else if (varp == &p_sbo)
6204 {
6205 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6206 errmsg = e_invarg;
6207 }
6208#endif
6209
6210 /* 'ambiwidth' */
6211#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006212 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006213 {
6214 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6215 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006216 else if (set_chars_option(&p_lcs) != NULL)
6217 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6218# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6219 else if (set_chars_option(&p_fcs) != NULL)
6220 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6221# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006222 }
6223#endif
6224
6225 /* 'background' */
6226 else if (varp == &p_bg)
6227 {
6228 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6229 {
6230#ifdef FEAT_EVAL
6231 int dark = (*p_bg == 'd');
6232#endif
6233
6234 init_highlight(FALSE, FALSE);
6235
6236#ifdef FEAT_EVAL
6237 if (dark != (*p_bg == 'd')
6238 && get_var_value((char_u *)"g:colors_name") != NULL)
6239 {
6240 /* The color scheme must have set 'background' back to another
6241 * value, that's not what we want here. Disable the color
6242 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006243 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244 free_string_option(p_bg);
6245 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6246 check_string_option(&p_bg);
6247 init_highlight(FALSE, FALSE);
6248 }
6249#endif
6250 }
6251 else
6252 errmsg = e_invarg;
6253 }
6254
6255 /* 'wildmode' */
6256 else if (varp == &p_wim)
6257 {
6258 if (check_opt_wim() == FAIL)
6259 errmsg = e_invarg;
6260 }
6261
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006262#ifdef FEAT_CMDL_COMPL
6263 /* 'wildoptions' */
6264 else if (varp == &p_wop)
6265 {
6266 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6267 errmsg = e_invarg;
6268 }
6269#endif
6270
Bram Moolenaar071d4272004-06-13 20:20:40 +00006271#ifdef FEAT_WAK
6272 /* 'winaltkeys' */
6273 else if (varp == &p_wak)
6274 {
6275 if (*p_wak == NUL
6276 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6277 errmsg = e_invarg;
6278# ifdef FEAT_MENU
6279# ifdef FEAT_GUI_MOTIF
6280 else if (gui.in_use)
6281 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6282# else
6283# ifdef FEAT_GUI_GTK
6284 else if (gui.in_use)
6285 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6286# endif
6287# endif
6288# endif
6289 }
6290#endif
6291
6292#ifdef FEAT_AUTOCMD
6293 /* 'eventignore' */
6294 else if (varp == &p_ei)
6295 {
6296 if (check_ei() == FAIL)
6297 errmsg = e_invarg;
6298 }
6299#endif
6300
6301#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006302 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6303 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6304 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305 {
6306 if (gvarp == &p_fenc)
6307 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006308 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006309 errmsg = e_modifiable;
6310 else if (vim_strchr(*varp, ',') != NULL)
6311 /* No comma allowed in 'fileencoding'; catches confusing it
6312 * with 'fileencodings'. */
6313 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006315 {
6316# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006317 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006318 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006320 /* Add 'fileencoding' to the swap file. */
6321 ml_setflags(curbuf);
6322 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006323 }
6324 if (errmsg == NULL)
6325 {
6326 /* canonize the value, so that STRCMP() can be used on it */
6327 p = enc_canonize(*varp);
6328 if (p != NULL)
6329 {
6330 vim_free(*varp);
6331 *varp = p;
6332 }
6333 if (varp == &p_enc)
6334 {
6335 errmsg = mb_init();
6336# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006337 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006338# endif
6339 }
6340 }
6341
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006342# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6344 {
6345 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6346 if (STRCMP(p_tenc, "utf-8") != 0)
6347 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6348 }
6349# endif
6350
6351 if (errmsg == NULL)
6352 {
6353# ifdef FEAT_KEYMAP
6354 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6355 * (with another encoding). */
6356 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6357 (void)keymap_init();
6358# endif
6359
6360 /* When 'termencoding' is not empty and 'encoding' changes or when
6361 * 'termencoding' changes, need to setup for keyboard input and
6362 * display output conversion. */
6363 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6364 {
6365 convert_setup(&input_conv, p_tenc, p_enc);
6366 convert_setup(&output_conv, p_enc, p_tenc);
6367 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006368
6369# if defined(WIN3264) && defined(FEAT_MBYTE)
6370 /* $HOME may have characters in active code page. */
6371 if (varp == &p_enc)
6372 init_homedir();
6373# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374 }
6375 }
6376#endif
6377
6378#if defined(FEAT_POSTSCRIPT)
6379 else if (varp == &p_penc)
6380 {
6381 /* Canonize printencoding if VIM standard one */
6382 p = enc_canonize(p_penc);
6383 if (p != NULL)
6384 {
6385 vim_free(p_penc);
6386 p_penc = p;
6387 }
6388 else
6389 {
6390 /* Ensure lower case and '-' for '_' */
6391 for (s = p_penc; *s != NUL; s++)
6392 {
6393 if (*s == '_')
6394 *s = '-';
6395 else
6396 *s = TOLOWER_ASC(*s);
6397 }
6398 }
6399 }
6400#endif
6401
Bram Moolenaar9372a112005-12-06 19:59:18 +00006402#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403 else if (varp == &p_imak)
6404 {
6405 if (gui.in_use && !im_xim_isvalid_imactivate())
6406 errmsg = e_invarg;
6407 }
6408#endif
6409
6410#ifdef FEAT_KEYMAP
6411 else if (varp == &curbuf->b_p_keymap)
6412 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006413 if (!valid_filetype(*varp))
6414 errmsg = e_invarg;
6415 else
6416 /* load or unload key mapping tables */
6417 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418
Bram Moolenaarfab06232009-03-04 03:13:35 +00006419 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006421 if (*curbuf->b_p_keymap != NUL)
6422 {
6423 /* Installed a new keymap, switch on using it. */
6424 curbuf->b_p_iminsert = B_IMODE_LMAP;
6425 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6426 curbuf->b_p_imsearch = B_IMODE_LMAP;
6427 }
6428 else
6429 {
6430 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6431 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6432 curbuf->b_p_iminsert = B_IMODE_NONE;
6433 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6434 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6435 }
6436 if ((opt_flags & OPT_LOCAL) == 0)
6437 {
6438 set_iminsert_global();
6439 set_imsearch_global();
6440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441# ifdef FEAT_WINDOWS
6442 status_redraw_curbuf();
6443# endif
6444 }
6445 }
6446#endif
6447
6448 /* 'fileformat' */
6449 else if (gvarp == &p_ff)
6450 {
6451 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6452 errmsg = e_modifiable;
6453 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6454 errmsg = e_invarg;
6455 else
6456 {
6457 /* may also change 'textmode' */
6458 if (get_fileformat(curbuf) == EOL_DOS)
6459 curbuf->b_p_tx = TRUE;
6460 else
6461 curbuf->b_p_tx = FALSE;
6462#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006463 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006464#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006465 /* update flag in swap file */
6466 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006467 /* Redraw needed when switching to/from "mac": a CR in the text
6468 * will be displayed differently. */
6469 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6470 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006471 }
6472 }
6473
6474 /* 'fileformats' */
6475 else if (varp == &p_ffs)
6476 {
6477 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6478 errmsg = e_invarg;
6479 else
6480 {
6481 /* also change 'textauto' */
6482 if (*p_ffs == NUL)
6483 p_ta = FALSE;
6484 else
6485 p_ta = TRUE;
6486 }
6487 }
6488
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006489#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 /* 'cryptkey' */
6491 else if (gvarp == &p_key)
6492 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006493# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006494 /* Make sure the ":set" command doesn't show the new value in the
6495 * history. */
6496 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006497# endif
6498 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6499 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006500 ml_set_crypt_key(curbuf, oldval,
6501 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006502 }
6503
6504 else if (gvarp == &p_cm)
6505 {
6506 if (opt_flags & OPT_LOCAL)
6507 p = curbuf->b_p_cm;
6508 else
6509 p = p_cm;
6510 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6511 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006512 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006513 errmsg = e_invarg;
6514 else
6515 {
6516 /* When setting the global value to empty, make it "zip". */
6517 if (*p_cm == NUL)
6518 {
6519 if (new_value_alloced)
6520 free_string_option(p_cm);
6521 p_cm = vim_strsave((char_u *)"zip");
6522 new_value_alloced = TRUE;
6523 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006524 /* When using ":set cm=name" the local value is going to be empty.
6525 * Do that here, otherwise the crypt functions will still use the
6526 * local value. */
6527 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6528 {
6529 free_string_option(curbuf->b_p_cm);
6530 curbuf->b_p_cm = empty_option;
6531 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006532
6533 /* Need to update the swapfile when the effective method changed.
6534 * Set "s" to the effective old value, "p" to the effective new
6535 * method and compare. */
6536 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6537 s = p_cm; /* was previously using the global value */
6538 else
6539 s = oldval;
6540 if (*curbuf->b_p_cm == NUL)
6541 p = p_cm; /* is now using the global value */
6542 else
6543 p = curbuf->b_p_cm;
6544 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006545 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006546
6547 /* If the global value changes need to update the swapfile for all
6548 * buffers using that value. */
6549 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6550 {
6551 buf_T *buf;
6552
Bram Moolenaar29323592016-07-24 22:04:11 +02006553 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006554 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006555 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006556 }
6557 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006558 }
6559#endif
6560
6561 /* 'matchpairs' */
6562 else if (gvarp == &p_mps)
6563 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006564#ifdef FEAT_MBYTE
6565 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006567 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006569 int x2 = -1;
6570 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006571
6572 if (*p != NUL)
6573 p += mb_ptr2len(p);
6574 if (*p != NUL)
6575 x2 = *p++;
6576 if (*p != NUL)
6577 {
6578 x3 = mb_ptr2char(p);
6579 p += mb_ptr2len(p);
6580 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006581 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006582 {
6583 errmsg = e_invarg;
6584 break;
6585 }
6586 if (*p == NUL)
6587 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006588 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006589 }
6590 else
6591#endif
6592 {
6593 /* Check for "x:y,x:y" */
6594 for (p = *varp; *p != NUL; p += 4)
6595 {
6596 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6597 {
6598 errmsg = e_invarg;
6599 break;
6600 }
6601 if (p[3] == NUL)
6602 break;
6603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 }
6605 }
6606
6607#ifdef FEAT_COMMENTS
6608 /* 'comments' */
6609 else if (gvarp == &p_com)
6610 {
6611 for (s = *varp; *s; )
6612 {
6613 while (*s && *s != ':')
6614 {
6615 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6616 && !VIM_ISDIGIT(*s) && *s != '-')
6617 {
6618 errmsg = illegal_char(errbuf, *s);
6619 break;
6620 }
6621 ++s;
6622 }
6623 if (*s++ == NUL)
6624 errmsg = (char_u *)N_("E524: Missing colon");
6625 else if (*s == ',' || *s == NUL)
6626 errmsg = (char_u *)N_("E525: Zero length string");
6627 if (errmsg != NULL)
6628 break;
6629 while (*s && *s != ',')
6630 {
6631 if (*s == '\\' && s[1] != NUL)
6632 ++s;
6633 ++s;
6634 }
6635 s = skip_to_option_part(s);
6636 }
6637 }
6638#endif
6639
6640 /* 'listchars' */
6641 else if (varp == &p_lcs)
6642 {
6643 errmsg = set_chars_option(varp);
6644 }
6645
6646#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6647 /* 'fillchars' */
6648 else if (varp == &p_fcs)
6649 {
6650 errmsg = set_chars_option(varp);
6651 }
6652#endif
6653
6654#ifdef FEAT_CMDWIN
6655 /* 'cedit' */
6656 else if (varp == &p_cedit)
6657 {
6658 errmsg = check_cedit();
6659 }
6660#endif
6661
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006662 /* 'verbosefile' */
6663 else if (varp == &p_vfile)
6664 {
6665 verbose_stop();
6666 if (*p_vfile != NUL && verbose_open() == FAIL)
6667 errmsg = e_invarg;
6668 }
6669
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670#ifdef FEAT_VIMINFO
6671 /* 'viminfo' */
6672 else if (varp == &p_viminfo)
6673 {
6674 for (s = p_viminfo; *s;)
6675 {
6676 /* Check it's a valid character */
6677 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6678 {
6679 errmsg = illegal_char(errbuf, *s);
6680 break;
6681 }
6682 if (*s == 'n') /* name is always last one */
6683 {
6684 break;
6685 }
6686 else if (*s == 'r') /* skip until next ',' */
6687 {
6688 while (*++s && *s != ',')
6689 ;
6690 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006691 else if (*s == '%')
6692 {
6693 /* optional number */
6694 while (vim_isdigit(*++s))
6695 ;
6696 }
6697 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698 ++s; /* no extra chars */
6699 else /* must have a number */
6700 {
6701 while (vim_isdigit(*++s))
6702 ;
6703
6704 if (!VIM_ISDIGIT(*(s - 1)))
6705 {
6706 if (errbuf != NULL)
6707 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006708 sprintf((char *)errbuf,
6709 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006710 transchar_byte(*(s - 1)));
6711 errmsg = errbuf;
6712 }
6713 else
6714 errmsg = (char_u *)"";
6715 break;
6716 }
6717 }
6718 if (*s == ',')
6719 ++s;
6720 else if (*s)
6721 {
6722 if (errbuf != NULL)
6723 errmsg = (char_u *)N_("E527: Missing comma");
6724 else
6725 errmsg = (char_u *)"";
6726 break;
6727 }
6728 }
6729 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6730 errmsg = (char_u *)N_("E528: Must specify a ' value");
6731 }
6732#endif /* FEAT_VIMINFO */
6733
6734 /* terminal options */
6735 else if (istermoption(&options[opt_idx]) && full_screen)
6736 {
6737 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6738 if (varp == &T_CCO)
6739 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006740 int colors = atoi((char *)T_CCO);
6741
6742 /* Only reinitialize colors if t_Co value has really changed to
6743 * avoid expensive reload of colorscheme if t_Co is set to the
6744 * same value multiple times. */
6745 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006746 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006747 t_colors = colors;
6748 if (t_colors <= 1)
6749 {
6750 if (new_value_alloced)
6751 vim_free(T_CCO);
6752 T_CCO = empty_option;
6753 }
6754 /* We now have a different color setup, initialize it again. */
6755 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 }
6758 ttest(FALSE);
6759 if (varp == &T_ME)
6760 {
6761 out_str(T_ME);
6762 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006763#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006764 /* Since t_me has been set, this probably means that the user
6765 * wants to use this as default colors. Need to reset default
6766 * background/foreground colors. */
6767 mch_set_normal_colors();
6768#endif
6769 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006770 if (varp == &T_BE && termcap_active)
6771 {
6772 if (*T_BE == NUL)
6773 /* When clearing t_BE we assume the user no longer wants
6774 * bracketed paste, thus disable it by writing t_BD. */
6775 out_str(T_BD);
6776 else
6777 out_str(T_BE);
6778 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779 }
6780
6781#ifdef FEAT_LINEBREAK
6782 /* 'showbreak' */
6783 else if (varp == &p_sbr)
6784 {
6785 for (s = p_sbr; *s; )
6786 {
6787 if (ptr2cells(s) != 1)
6788 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006789 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 }
6791 }
6792#endif
6793
6794#ifdef FEAT_GUI
6795 /* 'guifont' */
6796 else if (varp == &p_guifont)
6797 {
6798 if (gui.in_use)
6799 {
6800 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006801# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006802 /*
6803 * Put up a font dialog and let the user select a new value.
6804 * If this is cancelled go back to the old value but don't
6805 * give an error message.
6806 */
6807 if (STRCMP(p, "*") == 0)
6808 {
6809 p = gui_mch_font_dialog(oldval);
6810
6811 if (new_value_alloced)
6812 free_string_option(p_guifont);
6813
6814 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6815 new_value_alloced = TRUE;
6816 }
6817# endif
6818 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6819 {
6820# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6821 if (STRCMP(p_guifont, "*") == 0)
6822 {
6823 /* Dialog was cancelled: Keep the old value without giving
6824 * an error message. */
6825 if (new_value_alloced)
6826 free_string_option(p_guifont);
6827 p_guifont = vim_strsave(oldval);
6828 new_value_alloced = TRUE;
6829 }
6830 else
6831# endif
6832 errmsg = (char_u *)N_("E596: Invalid font(s)");
6833 }
6834 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006835 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006836 }
6837# ifdef FEAT_XFONTSET
6838 else if (varp == &p_guifontset)
6839 {
6840 if (STRCMP(p_guifontset, "*") == 0)
6841 errmsg = (char_u *)N_("E597: can't select fontset");
6842 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6843 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006844 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845 }
6846# endif
6847# ifdef FEAT_MBYTE
6848 else if (varp == &p_guifontwide)
6849 {
6850 if (STRCMP(p_guifontwide, "*") == 0)
6851 errmsg = (char_u *)N_("E533: can't select wide font");
6852 else if (gui_get_wide_font() == FAIL)
6853 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006854 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006855 }
6856# endif
6857#endif
6858
6859#ifdef CURSOR_SHAPE
6860 /* 'guicursor' */
6861 else if (varp == &p_guicursor)
6862 errmsg = parse_shape_opt(SHAPE_CURSOR);
6863#endif
6864
6865#ifdef FEAT_MOUSESHAPE
6866 /* 'mouseshape' */
6867 else if (varp == &p_mouseshape)
6868 {
6869 errmsg = parse_shape_opt(SHAPE_MOUSE);
6870 update_mouseshape(-1);
6871 }
6872#endif
6873
6874#ifdef FEAT_PRINTER
6875 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006876 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006877# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006878 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006879 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006880# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881#endif
6882
6883#ifdef FEAT_LANGMAP
6884 /* 'langmap' */
6885 else if (varp == &p_langmap)
6886 langmap_set();
6887#endif
6888
6889#ifdef FEAT_LINEBREAK
6890 /* 'breakat' */
6891 else if (varp == &p_breakat)
6892 fill_breakat_flags();
6893#endif
6894
6895#ifdef FEAT_TITLE
6896 /* 'titlestring' and 'iconstring' */
6897 else if (varp == &p_titlestring || varp == &p_iconstring)
6898 {
6899# ifdef FEAT_STL_OPT
6900 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6901
6902 /* NULL => statusline syntax */
6903 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6904 stl_syntax |= flagval;
6905 else
6906 stl_syntax &= ~flagval;
6907# endif
6908 did_set_title(varp == &p_iconstring);
6909
6910 }
6911#endif
6912
6913#ifdef FEAT_GUI
6914 /* 'guioptions' */
6915 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006916 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006918 redraw_gui_only = TRUE;
6919 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920#endif
6921
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006922#if defined(FEAT_GUI_TABLINE)
6923 /* 'guitablabel' */
6924 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006925 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006926 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006927 redraw_gui_only = TRUE;
6928 }
6929 /* 'guitabtooltip' */
6930 else if (varp == &p_gtt)
6931 {
6932 redraw_gui_only = TRUE;
6933 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006934#endif
6935
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6937 /* 'ttymouse' */
6938 else if (varp == &p_ttym)
6939 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006940 /* Switch the mouse off before changing the escape sequences used for
6941 * that. */
6942 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6944 errmsg = e_invarg;
6945 else
6946 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006947 if (termcap_active)
6948 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006949 }
6950#endif
6951
Bram Moolenaar071d4272004-06-13 20:20:40 +00006952 /* 'selection' */
6953 else if (varp == &p_sel)
6954 {
6955 if (*p_sel == NUL
6956 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6957 errmsg = e_invarg;
6958 }
6959
6960 /* 'selectmode' */
6961 else if (varp == &p_slm)
6962 {
6963 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6964 errmsg = e_invarg;
6965 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966
6967#ifdef FEAT_BROWSE
6968 /* 'browsedir' */
6969 else if (varp == &p_bsdir)
6970 {
6971 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6972 && !mch_isdir(p_bsdir))
6973 errmsg = e_invarg;
6974 }
6975#endif
6976
Bram Moolenaar071d4272004-06-13 20:20:40 +00006977 /* 'keymodel' */
6978 else if (varp == &p_km)
6979 {
6980 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6981 errmsg = e_invarg;
6982 else
6983 {
6984 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6985 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6986 }
6987 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006988
6989 /* 'mousemodel' */
6990 else if (varp == &p_mousem)
6991 {
6992 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6993 errmsg = e_invarg;
6994#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6995 else if (*p_mousem != *oldval)
6996 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6997 * to create or delete the popup menus. */
6998 gui_motif_update_mousemodel(root_menu);
6999#endif
7000 }
7001
7002 /* 'switchbuf' */
7003 else if (varp == &p_swb)
7004 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007005 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007006 errmsg = e_invarg;
7007 }
7008
7009 /* 'debug' */
7010 else if (varp == &p_debug)
7011 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007012 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013 errmsg = e_invarg;
7014 }
7015
7016 /* 'display' */
7017 else if (varp == &p_dy)
7018 {
7019 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7020 errmsg = e_invarg;
7021 else
7022 (void)init_chartab();
7023
7024 }
7025
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007026#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 /* 'eadirection' */
7028 else if (varp == &p_ead)
7029 {
7030 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7031 errmsg = e_invarg;
7032 }
7033#endif
7034
7035#ifdef FEAT_CLIPBOARD
7036 /* 'clipboard' */
7037 else if (varp == &p_cb)
7038 errmsg = check_clipboard_option();
7039#endif
7040
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007041#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007042 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7043 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007044 else if (varp == &(curwin->w_s->b_p_spl)
7045 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007046 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007047 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007048 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007049 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007050 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007051 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007052 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007053 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007054 /* 'spellsuggest' */
7055 else if (varp == &p_sps)
7056 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007057 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007058 errmsg = e_invarg;
7059 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007060 /* 'mkspellmem' */
7061 else if (varp == &p_msm)
7062 {
7063 if (spell_check_msm() != OK)
7064 errmsg = e_invarg;
7065 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007066#endif
7067
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068#ifdef FEAT_QUICKFIX
7069 /* When 'bufhidden' is set, check for valid value. */
7070 else if (gvarp == &p_bh)
7071 {
7072 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7073 errmsg = e_invarg;
7074 }
7075
7076 /* When 'buftype' is set, check for valid value. */
7077 else if (gvarp == &p_bt)
7078 {
7079 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7080 errmsg = e_invarg;
7081 else
7082 {
7083# ifdef FEAT_WINDOWS
7084 if (curwin->w_status_height)
7085 {
7086 curwin->w_redr_status = TRUE;
7087 redraw_later(VALID);
7088 }
7089# endif
7090 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007091# ifdef FEAT_TITLE
7092 redraw_titles();
7093# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007094 }
7095 }
7096#endif
7097
7098#ifdef FEAT_STL_OPT
7099 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007100 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101 {
7102 int wid;
7103
7104 if (varp == &p_ruf) /* reset ru_wid first */
7105 ru_wid = 0;
7106 s = *varp;
7107 if (varp == &p_ruf && *s == '%')
7108 {
7109 /* set ru_wid if 'ruf' starts with "%99(" */
7110 if (*++s == '-') /* ignore a '-' */
7111 s++;
7112 wid = getdigits(&s);
7113 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7114 ru_wid = wid;
7115 else
7116 errmsg = check_stl_option(p_ruf);
7117 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007118 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007119 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007121 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 comp_col();
7123 }
7124#endif
7125
7126#ifdef FEAT_INS_EXPAND
7127 /* check if it is a valid value for 'complete' -- Acevedo */
7128 else if (gvarp == &p_cpt)
7129 {
7130 for (s = *varp; *s;)
7131 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007132 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 s++;
7134 if (!*s)
7135 break;
7136 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7137 {
7138 errmsg = illegal_char(errbuf, *s);
7139 break;
7140 }
7141 if (*++s != NUL && *s != ',' && *s != ' ')
7142 {
7143 if (s[-1] == 'k' || s[-1] == 's')
7144 {
7145 /* skip optional filename after 'k' and 's' */
7146 while (*s && *s != ',' && *s != ' ')
7147 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007148 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007149 ++s;
7150 ++s;
7151 }
7152 }
7153 else
7154 {
7155 if (errbuf != NULL)
7156 {
7157 sprintf((char *)errbuf,
7158 _("E535: Illegal character after <%c>"),
7159 *--s);
7160 errmsg = errbuf;
7161 }
7162 else
7163 errmsg = (char_u *)"";
7164 break;
7165 }
7166 }
7167 }
7168 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007169
7170 /* 'completeopt' */
7171 else if (varp == &p_cot)
7172 {
7173 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7174 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007175 else
7176 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007177 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007178#endif /* FEAT_INS_EXPAND */
7179
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007180#ifdef FEAT_SIGNS
7181 /* 'signcolumn' */
7182 else if (varp == &curwin->w_p_scl)
7183 {
7184 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7185 errmsg = e_invarg;
7186 }
7187#endif
7188
Bram Moolenaar071d4272004-06-13 20:20:40 +00007189
7190#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007191 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007192 else if (varp == &p_toolbar)
7193 {
7194 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7195 &toolbar_flags, TRUE) != OK)
7196 errmsg = e_invarg;
7197 else
7198 {
7199 out_flush();
7200 gui_mch_show_toolbar((toolbar_flags &
7201 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7202 }
7203 }
7204#endif
7205
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007206#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007207 /* 'toolbariconsize': GTK+ 2 only */
7208 else if (varp == &p_tbis)
7209 {
7210 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7211 errmsg = e_invarg;
7212 else
7213 {
7214 out_flush();
7215 gui_mch_show_toolbar((toolbar_flags &
7216 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7217 }
7218 }
7219#endif
7220
7221 /* 'pastetoggle': translate key codes like in a mapping */
7222 else if (varp == &p_pt)
7223 {
7224 if (*p_pt)
7225 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007226 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227 if (p != NULL)
7228 {
7229 if (new_value_alloced)
7230 free_string_option(p_pt);
7231 p_pt = p;
7232 new_value_alloced = TRUE;
7233 }
7234 }
7235 }
7236
7237 /* 'backspace' */
7238 else if (varp == &p_bs)
7239 {
7240 if (VIM_ISDIGIT(*p_bs))
7241 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007242 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007243 errmsg = e_invarg;
7244 }
7245 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7246 errmsg = e_invarg;
7247 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007248 else if (varp == &p_bo)
7249 {
7250 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7251 errmsg = e_invarg;
7252 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007253
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007254 /* 'tagcase' */
7255 else if (gvarp == &p_tc)
7256 {
7257 unsigned int *flags;
7258
7259 if (opt_flags & OPT_LOCAL)
7260 {
7261 p = curbuf->b_p_tc;
7262 flags = &curbuf->b_tc_flags;
7263 }
7264 else
7265 {
7266 p = p_tc;
7267 flags = &tc_flags;
7268 }
7269
7270 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7271 /* make the local value empty: use the global value */
7272 *flags = 0;
7273 else if (*p == NUL
7274 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7275 errmsg = e_invarg;
7276 }
7277
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007278#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007279 /* 'casemap' */
7280 else if (varp == &p_cmp)
7281 {
7282 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7283 errmsg = e_invarg;
7284 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007286
7287#ifdef FEAT_DIFF
7288 /* 'diffopt' */
7289 else if (varp == &p_dip)
7290 {
7291 if (diffopt_changed() == FAIL)
7292 errmsg = e_invarg;
7293 }
7294#endif
7295
7296#ifdef FEAT_FOLDING
7297 /* 'foldmethod' */
7298 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7299 {
7300 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7301 || *curwin->w_p_fdm == NUL)
7302 errmsg = e_invarg;
7303 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007304 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007305 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007306 if (foldmethodIsDiff(curwin))
7307 newFoldLevel();
7308 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007309 }
7310# ifdef FEAT_EVAL
7311 /* 'foldexpr' */
7312 else if (varp == &curwin->w_p_fde)
7313 {
7314 if (foldmethodIsExpr(curwin))
7315 foldUpdateAll(curwin);
7316 }
7317# endif
7318 /* 'foldmarker' */
7319 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7320 {
7321 p = vim_strchr(*varp, ',');
7322 if (p == NULL)
7323 errmsg = (char_u *)N_("E536: comma required");
7324 else if (p == *varp || p[1] == NUL)
7325 errmsg = e_invarg;
7326 else if (foldmethodIsMarker(curwin))
7327 foldUpdateAll(curwin);
7328 }
7329 /* 'commentstring' */
7330 else if (gvarp == &p_cms)
7331 {
7332 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7333 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7334 }
7335 /* 'foldopen' */
7336 else if (varp == &p_fdo)
7337 {
7338 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7339 errmsg = e_invarg;
7340 }
7341 /* 'foldclose' */
7342 else if (varp == &p_fcl)
7343 {
7344 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7345 errmsg = e_invarg;
7346 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007347 /* 'foldignore' */
7348 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7349 {
7350 if (foldmethodIsIndent(curwin))
7351 foldUpdateAll(curwin);
7352 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007353#endif
7354
7355#ifdef FEAT_VIRTUALEDIT
7356 /* 'virtualedit' */
7357 else if (varp == &p_ve)
7358 {
7359 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7360 errmsg = e_invarg;
7361 else if (STRCMP(p_ve, oldval) != 0)
7362 {
7363 /* Recompute cursor position in case the new 've' setting
7364 * changes something. */
7365 validate_virtcol();
7366 coladvance(curwin->w_virtcol);
7367 }
7368 }
7369#endif
7370
7371#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7372 else if (varp == &p_csqf)
7373 {
7374 if (p_csqf != NULL)
7375 {
7376 p = p_csqf;
7377 while (*p != NUL)
7378 {
7379 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7380 || p[1] == NUL
7381 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7382 || (p[2] != NUL && p[2] != ','))
7383 {
7384 errmsg = e_invarg;
7385 break;
7386 }
7387 else if (p[2] == NUL)
7388 break;
7389 else
7390 p += 3;
7391 }
7392 }
7393 }
7394#endif
7395
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007396#ifdef FEAT_CINDENT
7397 /* 'cinoptions' */
7398 else if (gvarp == &p_cino)
7399 {
7400 /* TODO: recognize errors */
7401 parse_cino(curbuf);
7402 }
7403#endif
7404
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007405#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007406 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007407 else if (varp == &p_rop && gui.in_use)
7408 {
7409 if (!gui_mch_set_rendering_options(p_rop))
7410 errmsg = e_invarg;
7411 }
7412#endif
7413
Bram Moolenaard0b51382016-11-04 15:23:45 +01007414#ifdef FEAT_AUTOCMD
7415 else if (gvarp == &p_ft)
7416 {
7417 if (!valid_filetype(*varp))
7418 errmsg = e_invarg;
7419 }
7420#endif
7421
7422#ifdef FEAT_SYN_HL
7423 else if (gvarp == &p_syn)
7424 {
7425 if (!valid_filetype(*varp))
7426 errmsg = e_invarg;
7427 }
7428#endif
7429
Bram Moolenaar071d4272004-06-13 20:20:40 +00007430 /* Options that are a list of flags. */
7431 else
7432 {
7433 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007434 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007435 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007436 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007437 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007438 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007439 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007440 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007441 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007442#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007443 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007444 p = (char_u *)COCU_ALL;
7445#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007446 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007447 {
7448#ifdef FEAT_MOUSE
7449 p = (char_u *)MOUSE_ALL;
7450#else
7451 if (*p_mouse != NUL)
7452 errmsg = (char_u *)N_("E538: No mouse support");
7453#endif
7454 }
7455#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007456 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 p = (char_u *)GO_ALL;
7458#endif
7459 if (p != NULL)
7460 {
7461 for (s = *varp; *s; ++s)
7462 if (vim_strchr(p, *s) == NULL)
7463 {
7464 errmsg = illegal_char(errbuf, *s);
7465 break;
7466 }
7467 }
7468 }
7469
7470 /*
7471 * If error detected, restore the previous value.
7472 */
7473 if (errmsg != NULL)
7474 {
7475 if (new_value_alloced)
7476 free_string_option(*varp);
7477 *varp = oldval;
7478 /*
7479 * When resetting some values, need to act on it.
7480 */
7481 if (did_chartab)
7482 (void)init_chartab();
7483 if (varp == &p_hl)
7484 (void)highlight_changed();
7485 }
7486 else
7487 {
7488#ifdef FEAT_EVAL
7489 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007490 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491#endif
7492 /*
7493 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007494 * Use "free_oldval", because recursiveness may change the flags under
7495 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007497 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 free_string_option(oldval);
7499 if (new_value_alloced)
7500 options[opt_idx].flags |= P_ALLOCED;
7501 else
7502 options[opt_idx].flags &= ~P_ALLOCED;
7503
7504 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007505 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 {
7507 /* global option with local value set to use global value; free
7508 * the local value and make it empty */
7509 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7510 free_string_option(*(char_u **)p);
7511 *(char_u **)p = empty_option;
7512 }
7513
7514 /* May set global value for local option. */
7515 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7516 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007517
7518#ifdef FEAT_AUTOCMD
7519 /*
7520 * Trigger the autocommand only after setting the flags.
7521 */
7522# ifdef FEAT_SYN_HL
7523 /* When 'syntax' is set, load the syntax of that name */
7524 if (varp == &(curbuf->b_p_syn))
7525 {
7526 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7527 curbuf->b_fname, TRUE, curbuf);
7528 }
7529# endif
7530 else if (varp == &(curbuf->b_p_ft))
7531 {
7532 /* 'filetype' is set, trigger the FileType autocommand */
7533 did_filetype = TRUE;
7534 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7535 curbuf->b_fname, TRUE, curbuf);
7536 }
7537#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007538#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007539 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007540 {
7541 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007542 char_u *q = curwin->w_s->b_p_spl;
7543
7544 /* Skip the first name if it is "cjk". */
7545 if (STRNCMP(q, "cjk,", 4) == 0)
7546 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007547
7548 /*
7549 * Source the spell/LANG.vim in 'runtimepath'.
7550 * They could set 'spellcapcheck' depending on the language.
7551 * Use the first name in 'spelllang' up to '_region' or
7552 * '.encoding'.
7553 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007554 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007555 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7556 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007557 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007558 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007559 }
7560#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007561 }
7562
7563#ifdef FEAT_MOUSE
7564 if (varp == &p_mouse)
7565 {
7566# ifdef FEAT_MOUSE_TTY
7567 if (*p_mouse == NUL)
7568 mch_setmouse(FALSE); /* switch mouse off */
7569 else
7570# endif
7571 setmouse(); /* in case 'mouse' changed */
7572 }
7573#endif
7574
Bram Moolenaar913077c2012-03-28 19:59:04 +02007575 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007576 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007577 curwin->w_set_curswant = TRUE;
7578
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007579#ifdef FEAT_GUI
7580 /* check redraw when it's not a GUI option or the GUI is active. */
7581 if (!redraw_gui_only || gui.in_use)
7582#endif
7583 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007584
7585 return errmsg;
7586}
7587
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007588#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007589/*
7590 * Simple int comparison function for use with qsort()
7591 */
7592 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007593int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007594{
7595 return *(const int *)a - *(const int *)b;
7596}
7597
7598/*
7599 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7600 * Returns error message, NULL if it's OK.
7601 */
7602 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007603check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007604{
7605 char_u *s;
7606 int col;
7607 int count = 0;
7608 int color_cols[256];
7609 int i;
7610 int j = 0;
7611
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007612 if (wp->w_buffer == NULL)
7613 return NULL; /* buffer was closed */
7614
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007615 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007616 {
7617 if (*s == '-' || *s == '+')
7618 {
7619 /* -N and +N: add to 'textwidth' */
7620 col = (*s == '-') ? -1 : 1;
7621 ++s;
7622 if (!VIM_ISDIGIT(*s))
7623 return e_invarg;
7624 col = col * getdigits(&s);
7625 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007626 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007627 col += wp->w_buffer->b_p_tw;
7628 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007629 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007630 }
7631 else if (VIM_ISDIGIT(*s))
7632 col = getdigits(&s);
7633 else
7634 return e_invarg;
7635 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007636skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007637 if (*s == NUL)
7638 break;
7639 if (*s != ',')
7640 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007641 if (*++s == NUL)
7642 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007643 }
7644
7645 vim_free(wp->w_p_cc_cols);
7646 if (count == 0)
7647 wp->w_p_cc_cols = NULL;
7648 else
7649 {
7650 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7651 if (wp->w_p_cc_cols != NULL)
7652 {
7653 /* sort the columns for faster usage on screen redraw inside
7654 * win_line() */
7655 qsort(color_cols, count, sizeof(int), int_cmp);
7656
7657 for (i = 0; i < count; ++i)
7658 /* skip duplicates */
7659 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7660 wp->w_p_cc_cols[j++] = color_cols[i];
7661 wp->w_p_cc_cols[j] = -1; /* end marker */
7662 }
7663 }
7664
7665 return NULL; /* no error */
7666}
7667#endif
7668
Bram Moolenaar071d4272004-06-13 20:20:40 +00007669/*
7670 * Handle setting 'listchars' or 'fillchars'.
7671 * Returns error message, NULL if it's OK.
7672 */
7673 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007674set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007675{
7676 int round, i, len, entries;
7677 char_u *p, *s;
7678 int c1, c2 = 0;
7679 struct charstab
7680 {
7681 int *cp;
7682 char *name;
7683 };
7684#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7685 static struct charstab filltab[] =
7686 {
7687 {&fill_stl, "stl"},
7688 {&fill_stlnc, "stlnc"},
7689 {&fill_vert, "vert"},
7690 {&fill_fold, "fold"},
7691 {&fill_diff, "diff"},
7692 };
7693#endif
7694 static struct charstab lcstab[] =
7695 {
7696 {&lcs_eol, "eol"},
7697 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007698 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007699 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007700 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007701 {&lcs_tab2, "tab"},
7702 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007703#ifdef FEAT_CONCEAL
7704 {&lcs_conceal, "conceal"},
7705#else
7706 {NULL, "conceal"},
7707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708 };
7709 struct charstab *tab;
7710
7711#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7712 if (varp == &p_lcs)
7713#endif
7714 {
7715 tab = lcstab;
7716 entries = sizeof(lcstab) / sizeof(struct charstab);
7717 }
7718#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7719 else
7720 {
7721 tab = filltab;
7722 entries = sizeof(filltab) / sizeof(struct charstab);
7723 }
7724#endif
7725
7726 /* first round: check for valid value, second round: assign values */
7727 for (round = 0; round <= 1; ++round)
7728 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007729 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007730 {
7731 /* After checking that the value is valid: set defaults: space for
7732 * 'fillchars', NUL for 'listchars' */
7733 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007734 if (tab[i].cp != NULL)
7735 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 if (varp == &p_lcs)
7737 lcs_tab1 = NUL;
7738#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7739 else
7740 fill_diff = '-';
7741#endif
7742 }
7743 p = *varp;
7744 while (*p)
7745 {
7746 for (i = 0; i < entries; ++i)
7747 {
7748 len = (int)STRLEN(tab[i].name);
7749 if (STRNCMP(p, tab[i].name, len) == 0
7750 && p[len] == ':'
7751 && p[len + 1] != NUL)
7752 {
7753 s = p + len + 1;
7754#ifdef FEAT_MBYTE
7755 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007756 if (mb_char2cells(c1) > 1)
7757 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758#else
7759 c1 = *s++;
7760#endif
7761 if (tab[i].cp == &lcs_tab2)
7762 {
7763 if (*s == NUL)
7764 continue;
7765#ifdef FEAT_MBYTE
7766 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007767 if (mb_char2cells(c2) > 1)
7768 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007769#else
7770 c2 = *s++;
7771#endif
7772 }
7773 if (*s == ',' || *s == NUL)
7774 {
7775 if (round)
7776 {
7777 if (tab[i].cp == &lcs_tab2)
7778 {
7779 lcs_tab1 = c1;
7780 lcs_tab2 = c2;
7781 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007782 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 *(tab[i].cp) = c1;
7784
7785 }
7786 p = s;
7787 break;
7788 }
7789 }
7790 }
7791
7792 if (i == entries)
7793 return e_invarg;
7794 if (*p == ',')
7795 ++p;
7796 }
7797 }
7798
7799 return NULL; /* no error */
7800}
7801
7802#ifdef FEAT_STL_OPT
7803/*
7804 * Check validity of options with the 'statusline' format.
7805 * Return error message or NULL.
7806 */
7807 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007808check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007809{
7810 int itemcnt = 0;
7811 int groupdepth = 0;
7812 static char_u errbuf[80];
7813
7814 while (*s && itemcnt < STL_MAX_ITEM)
7815 {
7816 /* Check for valid keys after % sequences */
7817 while (*s && *s != '%')
7818 s++;
7819 if (!*s)
7820 break;
7821 s++;
7822 if (*s != '%' && *s != ')')
7823 ++itemcnt;
7824 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7825 {
7826 s++;
7827 continue;
7828 }
7829 if (*s == ')')
7830 {
7831 s++;
7832 if (--groupdepth < 0)
7833 break;
7834 continue;
7835 }
7836 if (*s == '-')
7837 s++;
7838 while (VIM_ISDIGIT(*s))
7839 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007840 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841 continue;
7842 if (*s == '.')
7843 {
7844 s++;
7845 while (*s && VIM_ISDIGIT(*s))
7846 s++;
7847 }
7848 if (*s == '(')
7849 {
7850 groupdepth++;
7851 continue;
7852 }
7853 if (vim_strchr(STL_ALL, *s) == NULL)
7854 {
7855 return illegal_char(errbuf, *s);
7856 }
7857 if (*s == '{')
7858 {
7859 s++;
7860 while (*s != '}' && *s)
7861 s++;
7862 if (*s != '}')
7863 return (char_u *)N_("E540: Unclosed expression sequence");
7864 }
7865 }
7866 if (itemcnt >= STL_MAX_ITEM)
7867 return (char_u *)N_("E541: too many items");
7868 if (groupdepth != 0)
7869 return (char_u *)N_("E542: unbalanced groups");
7870 return NULL;
7871}
7872#endif
7873
7874#ifdef FEAT_CLIPBOARD
7875/*
7876 * Extract the items in the 'clipboard' option and set global values.
7877 */
7878 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007879check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007880{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007881 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007882 int new_autoselect_star = FALSE;
7883 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007885 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886 regprog_T *new_exclude_prog = NULL;
7887 char_u *errmsg = NULL;
7888 char_u *p;
7889
7890 for (p = p_cb; *p != NUL; )
7891 {
7892 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7893 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007894 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895 p += 7;
7896 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007897 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007898 && (p[11] == ',' || p[11] == NUL))
7899 {
7900 new_unnamed |= CLIP_UNNAMED_PLUS;
7901 p += 11;
7902 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007904 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007906 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 p += 10;
7908 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007909 else if (STRNCMP(p, "autoselectplus", 14) == 0
7910 && (p[14] == ',' || p[14] == NUL))
7911 {
7912 new_autoselect_plus = TRUE;
7913 p += 14;
7914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007916 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 {
7918 new_autoselectml = TRUE;
7919 p += 12;
7920 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007921 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7922 {
7923 new_html = TRUE;
7924 p += 4;
7925 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7927 {
7928 p += 8;
7929 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7930 if (new_exclude_prog == NULL)
7931 errmsg = e_invarg;
7932 break;
7933 }
7934 else
7935 {
7936 errmsg = e_invarg;
7937 break;
7938 }
7939 if (*p == ',')
7940 ++p;
7941 }
7942 if (errmsg == NULL)
7943 {
7944 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007945 clip_autoselect_star = new_autoselect_star;
7946 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007948 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007949 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007951#ifdef FEAT_GUI_GTK
7952 if (gui.in_use)
7953 {
7954 gui_gtk_set_selection_targets();
7955 gui_gtk_set_dnd_targets();
7956 }
7957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 }
7959 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007960 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007961
7962 return errmsg;
7963}
7964#endif
7965
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007966#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007967 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007968did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007969{
7970 char_u *errmsg = NULL;
7971 win_T *wp;
7972 int l;
7973
7974 if (is_spellfile)
7975 {
7976 l = (int)STRLEN(curwin->w_s->b_p_spf);
7977 if (l > 0 && (l < 4
7978 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7979 errmsg = e_invarg;
7980 }
7981
7982 if (errmsg == NULL)
7983 {
7984 FOR_ALL_WINDOWS(wp)
7985 if (wp->w_buffer == curbuf && wp->w_p_spell)
7986 {
7987 errmsg = did_set_spelllang(wp);
7988# ifdef FEAT_WINDOWS
7989 break;
7990# endif
7991 }
7992 }
7993 return errmsg;
7994}
7995
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007996/*
7997 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7998 * Return error message when failed, NULL when OK.
7999 */
8000 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008001compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008002{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008003 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008004 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008005
Bram Moolenaar860cae12010-06-05 23:22:07 +02008006 if (*synblock->b_p_spc == NUL)
8007 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008008 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008009 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008010 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008011 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008012 if (re != NULL)
8013 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008014 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008015 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008016 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008017 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008018 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008019 return e_invarg;
8020 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008021 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008022 }
8023
Bram Moolenaar473de612013-06-08 18:19:48 +02008024 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008025 return NULL;
8026}
8027#endif
8028
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008029#if defined(FEAT_EVAL) || defined(PROTO)
8030/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008031 * Set the scriptID for an option, taking care of setting the buffer- or
8032 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008033 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008034 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008035set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008036{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008037 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8038 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008039
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008040 /* Remember where the option was set. For local options need to do that
8041 * in the buffer or window structure. */
8042 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008043 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008044 if (both || (opt_flags & OPT_LOCAL))
8045 {
8046 if (indir & PV_BUF)
8047 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8048 else if (indir & PV_WIN)
8049 curwin->w_p_scriptID[indir & PV_MASK] = id;
8050 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008051}
8052#endif
8053
Bram Moolenaar071d4272004-06-13 20:20:40 +00008054/*
8055 * Set the value of a boolean option, and take care of side effects.
8056 * Returns NULL for success, or an error message for an error.
8057 */
8058 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008059set_bool_option(
8060 int opt_idx, /* index in options[] table */
8061 char_u *varp, /* pointer to the option variable */
8062 int value, /* new value */
8063 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064{
8065 int old_value = *(int *)varp;
8066
Bram Moolenaar071d4272004-06-13 20:20:40 +00008067 /* Disallow changing some options from secure mode */
8068 if ((secure
8069#ifdef HAVE_SANDBOX
8070 || sandbox != 0
8071#endif
8072 ) && (options[opt_idx].flags & P_SECURE))
8073 return e_secure;
8074
8075 *(int *)varp = value; /* set the new value */
8076#ifdef FEAT_EVAL
8077 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008078 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008079#endif
8080
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008081#ifdef FEAT_GUI
8082 need_mouse_correct = TRUE;
8083#endif
8084
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 /* May set global value for local option. */
8086 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8087 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8088
8089 /*
8090 * Handle side effects of changing a bool option.
8091 */
8092
8093 /* 'compatible' */
8094 if ((int *)varp == &p_cp)
8095 {
8096 compatible_set();
8097 }
8098
Bram Moolenaar920694c2016-08-21 17:45:02 +02008099#ifdef FEAT_LANGMAP
8100 if ((int *)varp == &p_lrm)
8101 /* 'langremap' -> !'langnoremap' */
8102 p_lnr = !p_lrm;
8103 else if ((int *)varp == &p_lnr)
8104 /* 'langnoremap' -> !'langremap' */
8105 p_lrm = !p_lnr;
8106#endif
8107
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008108#ifdef FEAT_PERSISTENT_UNDO
8109 /* 'undofile' */
8110 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8111 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008112 /* Only take action when the option was set. When reset we do not
8113 * delete the undo file, the option may be set again without making
8114 * any changes in between. */
8115 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008116 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008117 char_u hash[UNDO_HASH_SIZE];
8118 buf_T *save_curbuf = curbuf;
8119
Bram Moolenaar29323592016-07-24 22:04:11 +02008120 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008121 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008122 /* When 'undofile' is set globally: for every buffer, otherwise
8123 * only for the current buffer: Try to read in the undofile,
8124 * if one exists, the buffer wasn't changed and the buffer was
8125 * loaded */
8126 if ((curbuf == save_curbuf
8127 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8128 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8129 {
8130 u_compute_hash(hash);
8131 u_read_undo(NULL, hash, curbuf->b_fname);
8132 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008133 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008134 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008135 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008136 }
8137#endif
8138
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139 else if ((int *)varp == &curbuf->b_p_ro)
8140 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008141 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8143 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008144
8145 /* when 'readonly' is set may give W10 again */
8146 if (curbuf->b_p_ro)
8147 curbuf->b_did_warn = FALSE;
8148
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008150 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151#endif
8152 }
8153
Bram Moolenaar9c449722010-07-20 18:44:27 +02008154#ifdef FEAT_GUI
8155 else if ((int *)varp == &p_mh)
8156 {
8157 if (!p_mh)
8158 gui_mch_mousehide(FALSE);
8159 }
8160#endif
8161
Bram Moolenaara539df02010-08-01 14:35:05 +02008162#ifdef FEAT_TITLE
8163 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008165 {
8166 redraw_titles();
8167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008168 /* when 'endofline' is changed, redraw the window title */
8169 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008170 {
8171 redraw_titles();
8172 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008173 /* when 'fixeol' is changed, redraw the window title */
8174 else if ((int *)varp == &curbuf->b_p_fixeol)
8175 {
8176 redraw_titles();
8177 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008178# ifdef FEAT_MBYTE
8179 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008180 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008181 {
8182 redraw_titles();
8183 }
8184# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185#endif
8186
8187 /* when 'bin' is set also set some other options */
8188 else if ((int *)varp == &curbuf->b_p_bin)
8189 {
8190 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8191#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008192 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193#endif
8194 }
8195
8196#ifdef FEAT_AUTOCMD
8197 /* when 'buflisted' changes, trigger autocommands */
8198 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8199 {
8200 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8201 NULL, NULL, TRUE, curbuf);
8202 }
8203#endif
8204
8205 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8206 else if ((int *)varp == &curbuf->b_p_swf)
8207 {
8208 if (curbuf->b_p_swf && p_uc)
8209 ml_open_file(curbuf); /* create the swap file */
8210 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008211 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8212 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008213 mf_close_file(curbuf, TRUE); /* remove the swap file */
8214 }
8215
8216 /* when 'terse' is set change 'shortmess' */
8217 else if ((int *)varp == &p_terse)
8218 {
8219 char_u *p;
8220
8221 p = vim_strchr(p_shm, SHM_SEARCH);
8222
8223 /* insert 's' in p_shm */
8224 if (p_terse && p == NULL)
8225 {
8226 STRCPY(IObuff, p_shm);
8227 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008228 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008229 }
8230 /* remove 's' from p_shm */
8231 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008232 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233 }
8234
8235 /* when 'paste' is set or reset also change other options */
8236 else if ((int *)varp == &p_paste)
8237 {
8238 paste_option_changed();
8239 }
8240
8241 /* when 'insertmode' is set from an autocommand need to do work here */
8242 else if ((int *)varp == &p_im)
8243 {
8244 if (p_im)
8245 {
8246 if ((State & INSERT) == 0)
8247 need_start_insertmode = TRUE;
8248 stop_insert_mode = FALSE;
8249 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008250 /* only reset if it was set previously */
8251 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252 {
8253 need_start_insertmode = FALSE;
8254 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008255 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008256 clear_cmdline = TRUE; /* remove "(insert)" */
8257 restart_edit = 0;
8258 }
8259 }
8260
8261 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8262 else if ((int *)varp == &p_ic && p_hls)
8263 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008264 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265 }
8266
8267#ifdef FEAT_SEARCH_EXTRA
8268 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8269 else if ((int *)varp == &p_hls)
8270 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008271 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272 }
8273#endif
8274
8275#ifdef FEAT_SCROLLBIND
8276 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8277 * at the end of normal_cmd() */
8278 else if ((int *)varp == &curwin->w_p_scb)
8279 {
8280 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008281 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008282 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008283 curwin->w_scbind_pos = curwin->w_topline;
8284 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008285 }
8286#endif
8287
8288#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8289 /* There can be only one window with 'previewwindow' set. */
8290 else if ((int *)varp == &curwin->w_p_pvw)
8291 {
8292 if (curwin->w_p_pvw)
8293 {
8294 win_T *win;
8295
Bram Moolenaar29323592016-07-24 22:04:11 +02008296 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 if (win->w_p_pvw && win != curwin)
8298 {
8299 curwin->w_p_pvw = FALSE;
8300 return (char_u *)N_("E590: A preview window already exists");
8301 }
8302 }
8303 }
8304#endif
8305
8306 /* when 'textmode' is set or reset also change 'fileformat' */
8307 else if ((int *)varp == &curbuf->b_p_tx)
8308 {
8309 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8310 }
8311
8312 /* when 'textauto' is set or reset also change 'fileformats' */
8313 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 set_string_option_direct((char_u *)"ffs", -1,
8315 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008316 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008317
8318 /*
8319 * When 'lisp' option changes include/exclude '-' in
8320 * keyword characters.
8321 */
8322#ifdef FEAT_LISP
8323 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8324 {
8325 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8326 }
8327#endif
8328
8329#ifdef FEAT_TITLE
8330 /* when 'title' changed, may need to change the title; same for 'icon' */
8331 else if ((int *)varp == &p_title)
8332 {
8333 did_set_title(FALSE);
8334 }
8335
8336 else if ((int *)varp == &p_icon)
8337 {
8338 did_set_title(TRUE);
8339 }
8340#endif
8341
8342 else if ((int *)varp == &curbuf->b_changed)
8343 {
8344 if (!value)
8345 save_file_ff(curbuf); /* Buffer is unchanged */
8346#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008347 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348#endif
8349#ifdef FEAT_AUTOCMD
8350 modified_was_set = value;
8351#endif
8352 }
8353
8354#ifdef BACKSLASH_IN_FILENAME
8355 else if ((int *)varp == &p_ssl)
8356 {
8357 if (p_ssl)
8358 {
8359 psepc = '/';
8360 psepcN = '\\';
8361 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 }
8363 else
8364 {
8365 psepc = '\\';
8366 psepcN = '/';
8367 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008368 }
8369
8370 /* need to adjust the file name arguments and buffer names. */
8371 buflist_slash_adjust();
8372 alist_slash_adjust();
8373# ifdef FEAT_EVAL
8374 scriptnames_slash_adjust();
8375# endif
8376 }
8377#endif
8378
8379 /* If 'wrap' is set, set w_leftcol to zero. */
8380 else if ((int *)varp == &curwin->w_p_wrap)
8381 {
8382 if (curwin->w_p_wrap)
8383 curwin->w_leftcol = 0;
8384 }
8385
8386#ifdef FEAT_WINDOWS
8387 else if ((int *)varp == &p_ea)
8388 {
8389 if (p_ea && !old_value)
8390 win_equal(curwin, FALSE, 0);
8391 }
8392#endif
8393
8394 else if ((int *)varp == &p_wiv)
8395 {
8396 /*
8397 * When 'weirdinvert' changed, set/reset 't_xs'.
8398 * Then set 'weirdinvert' according to value of 't_xs'.
8399 */
8400 if (p_wiv && !old_value)
8401 T_XS = (char_u *)"y";
8402 else if (!p_wiv && old_value)
8403 T_XS = empty_option;
8404 p_wiv = (*T_XS != NUL);
8405 }
8406
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008407#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 else if ((int *)varp == &p_beval)
8409 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008410 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008411 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008412 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413 gui_mch_disable_beval_area(balloonEval);
8414 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008415#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008417#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418 else if ((int *)varp == &p_acd)
8419 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008420 /* Change directories when the 'acd' option is set now. */
8421 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422 }
8423#endif
8424
8425#ifdef FEAT_DIFF
8426 /* 'diff' */
8427 else if ((int *)varp == &curwin->w_p_diff)
8428 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008429 /* May add or remove the buffer from the list of diff buffers. */
8430 diff_buf_adjust(curwin);
8431# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008432 if (foldmethodIsDiff(curwin))
8433 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008434# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008435 }
8436#endif
8437
8438#ifdef USE_IM_CONTROL
8439 /* 'imdisable' */
8440 else if ((int *)varp == &p_imdisable)
8441 {
8442 /* Only de-activate it here, it will be enabled when changing mode. */
8443 if (p_imdisable)
8444 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008445 else if (State & INSERT)
8446 /* When the option is set from an autocommand, it may need to take
8447 * effect right away. */
8448 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449 }
8450#endif
8451
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008452#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008453 /* 'spell' */
8454 else if ((int *)varp == &curwin->w_p_spell)
8455 {
8456 if (curwin->w_p_spell)
8457 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008458 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008459 if (errmsg != NULL)
8460 EMSG(_(errmsg));
8461 }
8462 }
8463#endif
8464
Bram Moolenaar071d4272004-06-13 20:20:40 +00008465#ifdef FEAT_FKMAP
8466 else if ((int *)varp == &p_altkeymap)
8467 {
8468 if (old_value != p_altkeymap)
8469 {
8470 if (!p_altkeymap)
8471 {
8472 p_hkmap = p_fkmap;
8473 p_fkmap = 0;
8474 }
8475 else
8476 {
8477 p_fkmap = p_hkmap;
8478 p_hkmap = 0;
8479 }
8480 (void)init_chartab();
8481 }
8482 }
8483
8484 /*
8485 * In case some second language keymapping options have changed, check
8486 * and correct the setting in a consistent way.
8487 */
8488
8489 /*
8490 * If hkmap or fkmap are set, reset Arabic keymapping.
8491 */
8492 if ((p_hkmap || p_fkmap) && p_altkeymap)
8493 {
8494 p_altkeymap = p_fkmap;
8495# ifdef FEAT_ARABIC
8496 curwin->w_p_arab = FALSE;
8497# endif
8498 (void)init_chartab();
8499 }
8500
8501 /*
8502 * If hkmap set, reset Farsi keymapping.
8503 */
8504 if (p_hkmap && p_altkeymap)
8505 {
8506 p_altkeymap = 0;
8507 p_fkmap = 0;
8508# ifdef FEAT_ARABIC
8509 curwin->w_p_arab = FALSE;
8510# endif
8511 (void)init_chartab();
8512 }
8513
8514 /*
8515 * If fkmap set, reset Hebrew keymapping.
8516 */
8517 if (p_fkmap && !p_altkeymap)
8518 {
8519 p_altkeymap = 1;
8520 p_hkmap = 0;
8521# ifdef FEAT_ARABIC
8522 curwin->w_p_arab = FALSE;
8523# endif
8524 (void)init_chartab();
8525 }
8526#endif
8527
8528#ifdef FEAT_ARABIC
8529 if ((int *)varp == &curwin->w_p_arab)
8530 {
8531 if (curwin->w_p_arab)
8532 {
8533 /*
8534 * 'arabic' is set, handle various sub-settings.
8535 */
8536 if (!p_tbidi)
8537 {
8538 /* set rightleft mode */
8539 if (!curwin->w_p_rl)
8540 {
8541 curwin->w_p_rl = TRUE;
8542 changed_window_setting();
8543 }
8544
8545 /* Enable Arabic shaping (major part of what Arabic requires) */
8546 if (!p_arshape)
8547 {
8548 p_arshape = TRUE;
8549 redraw_later_clear();
8550 }
8551 }
8552
8553 /* Arabic requires a utf-8 encoding, inform the user if its not
8554 * set. */
8555 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008556 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008557 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8558
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008559 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008560 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8561#ifdef FEAT_EVAL
8562 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8563#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008564 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565
8566# ifdef FEAT_MBYTE
8567 /* set 'delcombine' */
8568 p_deco = TRUE;
8569# endif
8570
8571# ifdef FEAT_KEYMAP
8572 /* Force-set the necessary keymap for arabic */
8573 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8574 OPT_LOCAL);
8575# endif
8576# ifdef FEAT_FKMAP
8577 p_altkeymap = 0;
8578 p_hkmap = 0;
8579 p_fkmap = 0;
8580 (void)init_chartab();
8581# endif
8582 }
8583 else
8584 {
8585 /*
8586 * 'arabic' is reset, handle various sub-settings.
8587 */
8588 if (!p_tbidi)
8589 {
8590 /* reset rightleft mode */
8591 if (curwin->w_p_rl)
8592 {
8593 curwin->w_p_rl = FALSE;
8594 changed_window_setting();
8595 }
8596
8597 /* 'arabicshape' isn't reset, it is a global option and
8598 * another window may still need it "on". */
8599 }
8600
8601 /* 'delcombine' isn't reset, it is a global option and another
8602 * window may still want it "on". */
8603
8604# ifdef FEAT_KEYMAP
8605 /* Revert to the default keymap */
8606 curbuf->b_p_iminsert = B_IMODE_NONE;
8607 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8608# endif
8609 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008610 }
8611
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008612#endif
8613
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008614#ifdef FEAT_TERMGUICOLORS
8615 /* 'termguicolors' */
8616 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008617 {
8618# ifdef FEAT_GUI
8619 if (!gui.in_use && !gui.starting)
8620# endif
8621 highlight_gui_started();
8622 }
8623#endif
8624
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 /*
8626 * End of handling side effects for bool options.
8627 */
8628
Bram Moolenaar53744302015-07-17 17:38:22 +02008629 /* after handling side effects, call autocommand */
8630
Bram Moolenaar071d4272004-06-13 20:20:40 +00008631 options[opt_idx].flags |= P_WAS_SET;
8632
Bram Moolenaar53744302015-07-17 17:38:22 +02008633#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8634 if (!starting)
8635 {
8636 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008637 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8638 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8639 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008640 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8641 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8642 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8643 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8644 reset_v_option_vars();
8645 }
8646#endif
8647
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008649 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008650 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008651 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 check_redraw(options[opt_idx].flags);
8653
8654 return NULL;
8655}
8656
8657/*
8658 * Set the value of a number option, and take care of side effects.
8659 * Returns NULL for success, or an error message for an error.
8660 */
8661 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008662set_num_option(
8663 int opt_idx, /* index in options[] table */
8664 char_u *varp, /* pointer to the option variable */
8665 long value, /* new value */
8666 char_u *errbuf, /* buffer for error messages */
8667 size_t errbuflen, /* length of "errbuf" */
8668 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008669 OPT_MODELINE */
8670{
8671 char_u *errmsg = NULL;
8672 long old_value = *(long *)varp;
8673 long old_Rows = Rows; /* remember old Rows */
8674 long old_Columns = Columns; /* remember old Columns */
8675 long *pp = (long *)varp;
8676
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008677 /* Disallow changing some options from secure mode. */
8678 if ((secure
8679#ifdef HAVE_SANDBOX
8680 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008681#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008682 ) && (options[opt_idx].flags & P_SECURE))
8683 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684
8685 *pp = value;
8686#ifdef FEAT_EVAL
8687 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008688 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008690#ifdef FEAT_GUI
8691 need_mouse_correct = TRUE;
8692#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693
Bram Moolenaar14f24742012-08-08 18:01:05 +02008694 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695 {
8696 errmsg = e_positive;
8697 curbuf->b_p_sw = curbuf->b_p_ts;
8698 }
8699
8700 /*
8701 * Number options that need some action when changed
8702 */
8703#ifdef FEAT_WINDOWS
8704 if (pp == &p_wh || pp == &p_hh)
8705 {
8706 if (p_wh < 1)
8707 {
8708 errmsg = e_positive;
8709 p_wh = 1;
8710 }
8711 if (p_wmh > p_wh)
8712 {
8713 errmsg = e_winheight;
8714 p_wh = p_wmh;
8715 }
8716 if (p_hh < 0)
8717 {
8718 errmsg = e_positive;
8719 p_hh = 0;
8720 }
8721
8722 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008723 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008724 {
8725 if (pp == &p_wh && curwin->w_height < p_wh)
8726 win_setheight((int)p_wh);
8727 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8728 win_setheight((int)p_hh);
8729 }
8730 }
8731
8732 /* 'winminheight' */
8733 else if (pp == &p_wmh)
8734 {
8735 if (p_wmh < 0)
8736 {
8737 errmsg = e_positive;
8738 p_wmh = 0;
8739 }
8740 if (p_wmh > p_wh)
8741 {
8742 errmsg = e_winheight;
8743 p_wmh = p_wh;
8744 }
8745 win_setminheight();
8746 }
8747
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008748# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008749 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750 {
8751 if (p_wiw < 1)
8752 {
8753 errmsg = e_positive;
8754 p_wiw = 1;
8755 }
8756 if (p_wmw > p_wiw)
8757 {
8758 errmsg = e_winwidth;
8759 p_wiw = p_wmw;
8760 }
8761
8762 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008763 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008764 win_setwidth((int)p_wiw);
8765 }
8766
8767 /* 'winminwidth' */
8768 else if (pp == &p_wmw)
8769 {
8770 if (p_wmw < 0)
8771 {
8772 errmsg = e_positive;
8773 p_wmw = 0;
8774 }
8775 if (p_wmw > p_wiw)
8776 {
8777 errmsg = e_winwidth;
8778 p_wmw = p_wiw;
8779 }
8780 win_setminheight();
8781 }
8782# endif
8783
8784#endif
8785
8786#ifdef FEAT_WINDOWS
8787 /* (re)set last window status line */
8788 else if (pp == &p_ls)
8789 {
8790 last_status(FALSE);
8791 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008792
8793 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008794 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008795 {
8796 shell_new_rows(); /* recompute window positions and heights */
8797 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798#endif
8799
8800#ifdef FEAT_GUI
8801 else if (pp == &p_linespace)
8802 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008803 /* Recompute gui.char_height and resize the Vim window to keep the
8804 * same number of lines. */
8805 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008806 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807 }
8808#endif
8809
8810#ifdef FEAT_FOLDING
8811 /* 'foldlevel' */
8812 else if (pp == &curwin->w_p_fdl)
8813 {
8814 if (curwin->w_p_fdl < 0)
8815 curwin->w_p_fdl = 0;
8816 newFoldLevel();
8817 }
8818
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008819 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008820 else if (pp == &curwin->w_p_fml)
8821 {
8822 foldUpdateAll(curwin);
8823 }
8824
8825 /* 'foldnestmax' */
8826 else if (pp == &curwin->w_p_fdn)
8827 {
8828 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8829 foldUpdateAll(curwin);
8830 }
8831
8832 /* 'foldcolumn' */
8833 else if (pp == &curwin->w_p_fdc)
8834 {
8835 if (curwin->w_p_fdc < 0)
8836 {
8837 errmsg = e_positive;
8838 curwin->w_p_fdc = 0;
8839 }
8840 else if (curwin->w_p_fdc > 12)
8841 {
8842 errmsg = e_invarg;
8843 curwin->w_p_fdc = 12;
8844 }
8845 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008846#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008848#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008849 /* 'shiftwidth' or 'tabstop' */
8850 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8851 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008852# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853 if (foldmethodIsIndent(curwin))
8854 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008855# endif
8856# ifdef FEAT_CINDENT
8857 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8858 * parse 'cinoptions'. */
8859 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8860 parse_cino(curbuf);
8861# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008865#ifdef FEAT_MBYTE
8866 /* 'maxcombine' */
8867 else if (pp == &p_mco)
8868 {
8869 if (p_mco > MAX_MCO)
8870 p_mco = MAX_MCO;
8871 else if (p_mco < 0)
8872 p_mco = 0;
8873 screenclear(); /* will re-allocate the screen */
8874 }
8875#endif
8876
Bram Moolenaar071d4272004-06-13 20:20:40 +00008877 else if (pp == &curbuf->b_p_iminsert)
8878 {
8879 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8880 {
8881 errmsg = e_invarg;
8882 curbuf->b_p_iminsert = B_IMODE_NONE;
8883 }
8884 p_iminsert = curbuf->b_p_iminsert;
8885 if (termcap_active) /* don't do this in the alternate screen */
8886 showmode();
8887#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8888 /* Show/unshow value of 'keymap' in status lines. */
8889 status_redraw_curbuf();
8890#endif
8891 }
8892
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008893 else if (pp == &p_window)
8894 {
8895 if (p_window < 1)
8896 p_window = 1;
8897 else if (p_window >= Rows)
8898 p_window = Rows - 1;
8899 }
8900
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901 else if (pp == &curbuf->b_p_imsearch)
8902 {
8903 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8904 {
8905 errmsg = e_invarg;
8906 curbuf->b_p_imsearch = B_IMODE_NONE;
8907 }
8908 p_imsearch = curbuf->b_p_imsearch;
8909 }
8910
8911#ifdef FEAT_TITLE
8912 /* if 'titlelen' has changed, redraw the title */
8913 else if (pp == &p_titlelen)
8914 {
8915 if (p_titlelen < 0)
8916 {
8917 errmsg = e_positive;
8918 p_titlelen = 85;
8919 }
8920 if (starting != NO_SCREEN && old_value != p_titlelen)
8921 need_maketitle = TRUE;
8922 }
8923#endif
8924
8925 /* if p_ch changed value, change the command line height */
8926 else if (pp == &p_ch)
8927 {
8928 if (p_ch < 1)
8929 {
8930 errmsg = e_positive;
8931 p_ch = 1;
8932 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008933 if (p_ch > Rows - min_rows() + 1)
8934 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935
8936 /* Only compute the new window layout when startup has been
8937 * completed. Otherwise the frame sizes may be wrong. */
8938 if (p_ch != old_value && full_screen
8939#ifdef FEAT_GUI
8940 && !gui.starting
8941#endif
8942 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008943 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944 }
8945
8946 /* when 'updatecount' changes from zero to non-zero, open swap files */
8947 else if (pp == &p_uc)
8948 {
8949 if (p_uc < 0)
8950 {
8951 errmsg = e_positive;
8952 p_uc = 100;
8953 }
8954 if (p_uc && !old_value)
8955 ml_open_files();
8956 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008957#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008958 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008959 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008960 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008961 {
8962 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008963 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008964 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008965 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008966 {
8967 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008968 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008969 }
8970 }
8971#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008972#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008973 else if (pp == &p_mzq)
8974 mzvim_reset_timer();
8975#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008977#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8978 /* 'pyxversion' */
8979 else if (pp == &p_pyx)
8980 {
8981 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8982 errmsg = e_invarg;
8983 }
8984#endif
8985
Bram Moolenaar071d4272004-06-13 20:20:40 +00008986 /* sync undo before 'undolevels' changes */
8987 else if (pp == &p_ul)
8988 {
8989 /* use the old value, otherwise u_sync() may not work properly */
8990 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008991 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008992 p_ul = value;
8993 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008994 else if (pp == &curbuf->b_p_ul)
8995 {
8996 /* use the old value, otherwise u_sync() may not work properly */
8997 curbuf->b_p_ul = old_value;
8998 u_sync(TRUE);
8999 curbuf->b_p_ul = value;
9000 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009001
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009002#ifdef FEAT_LINEBREAK
9003 /* 'numberwidth' must be positive */
9004 else if (pp == &curwin->w_p_nuw)
9005 {
9006 if (curwin->w_p_nuw < 1)
9007 {
9008 errmsg = e_positive;
9009 curwin->w_p_nuw = 1;
9010 }
9011 if (curwin->w_p_nuw > 10)
9012 {
9013 errmsg = e_invarg;
9014 curwin->w_p_nuw = 10;
9015 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009016 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009017 }
9018#endif
9019
Bram Moolenaar1a384422010-07-14 19:53:30 +02009020 else if (pp == &curbuf->b_p_tw)
9021 {
9022 if (curbuf->b_p_tw < 0)
9023 {
9024 errmsg = e_positive;
9025 curbuf->b_p_tw = 0;
9026 }
9027#ifdef FEAT_SYN_HL
9028# ifdef FEAT_WINDOWS
9029 {
9030 win_T *wp;
9031 tabpage_T *tp;
9032
9033 FOR_ALL_TAB_WINDOWS(tp, wp)
9034 check_colorcolumn(wp);
9035 }
9036# else
9037 check_colorcolumn(curwin);
9038# endif
9039#endif
9040 }
9041
Bram Moolenaar071d4272004-06-13 20:20:40 +00009042 /*
9043 * Check the bounds for numeric options here
9044 */
9045 if (Rows < min_rows() && full_screen)
9046 {
9047 if (errbuf != NULL)
9048 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009049 vim_snprintf((char *)errbuf, errbuflen,
9050 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009051 errmsg = errbuf;
9052 }
9053 Rows = min_rows();
9054 }
9055 if (Columns < MIN_COLUMNS && full_screen)
9056 {
9057 if (errbuf != NULL)
9058 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009059 vim_snprintf((char *)errbuf, errbuflen,
9060 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061 errmsg = errbuf;
9062 }
9063 Columns = MIN_COLUMNS;
9064 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009065 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066
Bram Moolenaar071d4272004-06-13 20:20:40 +00009067 /*
9068 * If the screen (shell) height has been changed, assume it is the
9069 * physical screenheight.
9070 */
9071 if (old_Rows != Rows || old_Columns != Columns)
9072 {
9073 /* Changing the screen size is not allowed while updating the screen. */
9074 if (updating_screen)
9075 *pp = old_value;
9076 else if (full_screen
9077#ifdef FEAT_GUI
9078 && !gui.starting
9079#endif
9080 )
9081 set_shellsize((int)Columns, (int)Rows, TRUE);
9082 else
9083 {
9084 /* Postpone the resizing; check the size and cmdline position for
9085 * messages. */
9086 check_shellsize();
9087 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9088 cmdline_row = Rows - p_ch;
9089 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009090 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009091 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092 }
9093
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094 if (curbuf->b_p_ts <= 0)
9095 {
9096 errmsg = e_positive;
9097 curbuf->b_p_ts = 8;
9098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009099 if (p_tm < 0)
9100 {
9101 errmsg = e_positive;
9102 p_tm = 0;
9103 }
9104 if ((curwin->w_p_scr <= 0
9105 || (curwin->w_p_scr > curwin->w_height
9106 && curwin->w_height > 0))
9107 && full_screen)
9108 {
9109 if (pp == &(curwin->w_p_scr))
9110 {
9111 if (curwin->w_p_scr != 0)
9112 errmsg = e_scroll;
9113 win_comp_scroll(curwin);
9114 }
9115 /* If 'scroll' became invalid because of a side effect silently adjust
9116 * it. */
9117 else if (curwin->w_p_scr <= 0)
9118 curwin->w_p_scr = 1;
9119 else /* curwin->w_p_scr > curwin->w_height */
9120 curwin->w_p_scr = curwin->w_height;
9121 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009122 if (p_hi < 0)
9123 {
9124 errmsg = e_positive;
9125 p_hi = 0;
9126 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009127 else if (p_hi > 10000)
9128 {
9129 errmsg = e_invarg;
9130 p_hi = 10000;
9131 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009132 if (p_re < 0 || p_re > 2)
9133 {
9134 errmsg = e_invarg;
9135 p_re = 0;
9136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009137 if (p_report < 0)
9138 {
9139 errmsg = e_positive;
9140 p_report = 1;
9141 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009142 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009143 {
9144 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9145 p_sj = Rows / 2;
9146 else
9147 {
9148 errmsg = e_scroll;
9149 p_sj = 1;
9150 }
9151 }
9152 if (p_so < 0 && full_screen)
9153 {
9154 errmsg = e_scroll;
9155 p_so = 0;
9156 }
9157 if (p_siso < 0 && full_screen)
9158 {
9159 errmsg = e_positive;
9160 p_siso = 0;
9161 }
9162#ifdef FEAT_CMDWIN
9163 if (p_cwh < 1)
9164 {
9165 errmsg = e_positive;
9166 p_cwh = 1;
9167 }
9168#endif
9169 if (p_ut < 0)
9170 {
9171 errmsg = e_positive;
9172 p_ut = 2000;
9173 }
9174 if (p_ss < 0)
9175 {
9176 errmsg = e_positive;
9177 p_ss = 0;
9178 }
9179
9180 /* May set global value for local option. */
9181 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9182 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9183
9184 options[opt_idx].flags |= P_WAS_SET;
9185
Bram Moolenaar53744302015-07-17 17:38:22 +02009186#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9187 if (!starting && errmsg == NULL)
9188 {
9189 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009190 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9191 vim_snprintf((char *)buf_new, 10, "%ld", value);
9192 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009193 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9194 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9195 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9196 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9197 reset_v_option_vars();
9198 }
9199#endif
9200
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009202 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009203 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009204 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009205 check_redraw(options[opt_idx].flags);
9206
9207 return errmsg;
9208}
9209
9210/*
9211 * Called after an option changed: check if something needs to be redrawn.
9212 */
9213 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009214check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009215{
9216 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009217 int doclear = (flags & P_RCLR) == P_RCLR;
9218 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009219
9220#ifdef FEAT_WINDOWS
9221 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9222 status_redraw_all();
9223#endif
9224
9225 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9226 changed_window_setting();
9227 if (flags & P_RBUF)
9228 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009229 if (flags & P_RWINONLY)
9230 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009231 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009232 redraw_all_later(CLEAR);
9233 else if (all)
9234 redraw_all_later(NOT_VALID);
9235}
9236
9237/*
9238 * Find index for option 'arg'.
9239 * Return -1 if not found.
9240 */
9241 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009242findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243{
9244 int opt_idx;
9245 char *s, *p;
9246 static short quick_tab[27] = {0, 0}; /* quick access table */
9247 int is_term_opt;
9248
9249 /*
9250 * For first call: Initialize the quick-access table.
9251 * It contains the index for the first option that starts with a certain
9252 * letter. There are 26 letters, plus the first "t_" option.
9253 */
9254 if (quick_tab[1] == 0)
9255 {
9256 p = options[0].fullname;
9257 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9258 {
9259 if (s[0] != p[0])
9260 {
9261 if (s[0] == 't' && s[1] == '_')
9262 quick_tab[26] = opt_idx;
9263 else
9264 quick_tab[CharOrdLow(s[0])] = opt_idx;
9265 }
9266 p = s;
9267 }
9268 }
9269
9270 /*
9271 * Check for name starting with an illegal character.
9272 */
9273#ifdef EBCDIC
9274 if (!islower(arg[0]))
9275#else
9276 if (arg[0] < 'a' || arg[0] > 'z')
9277#endif
9278 return -1;
9279
9280 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9281 if (is_term_opt)
9282 opt_idx = quick_tab[26];
9283 else
9284 opt_idx = quick_tab[CharOrdLow(arg[0])];
9285 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9286 {
9287 if (STRCMP(arg, s) == 0) /* match full name */
9288 break;
9289 }
9290 if (s == NULL && !is_term_opt)
9291 {
9292 opt_idx = quick_tab[CharOrdLow(arg[0])];
9293 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9294 {
9295 s = options[opt_idx].shortname;
9296 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9297 break;
9298 s = NULL;
9299 }
9300 }
9301 if (s == NULL)
9302 opt_idx = -1;
9303 return opt_idx;
9304}
9305
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009306#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307/*
9308 * Get the value for an option.
9309 *
9310 * Returns:
9311 * Number or Toggle option: 1, *numval gets value.
9312 * String option: 0, *stringval gets allocated string.
9313 * Hidden Number or Toggle option: -1.
9314 * hidden String option: -2.
9315 * unknown option: -3.
9316 */
9317 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009318get_option_value(
9319 char_u *name,
9320 long *numval,
9321 char_u **stringval, /* NULL when only checking existence */
9322 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323{
9324 int opt_idx;
9325 char_u *varp;
9326
9327 opt_idx = findoption(name);
9328 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009329 {
9330 int key;
9331
9332 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9333 && (key = find_key_option(name)) != 0)
9334 {
9335 char_u key_name[2];
9336 char_u *p;
9337
9338 if (key < 0)
9339 {
9340 key_name[0] = KEY2TERMCAP0(key);
9341 key_name[1] = KEY2TERMCAP1(key);
9342 }
9343 else
9344 {
9345 key_name[0] = KS_KEY;
9346 key_name[1] = (key & 0xff);
9347 }
9348 p = find_termcode(key_name);
9349 if (p != NULL)
9350 {
9351 if (stringval != NULL)
9352 *stringval = vim_strsave(p);
9353 return 0;
9354 }
9355 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009357 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358
9359 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9360
9361 if (options[opt_idx].flags & P_STRING)
9362 {
9363 if (varp == NULL) /* hidden option */
9364 return -2;
9365 if (stringval != NULL)
9366 {
9367#ifdef FEAT_CRYPT
9368 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009369 if ((char_u **)varp == &curbuf->b_p_key
9370 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009371 *stringval = vim_strsave((char_u *)"*****");
9372 else
9373#endif
9374 *stringval = vim_strsave(*(char_u **)(varp));
9375 }
9376 return 0;
9377 }
9378
9379 if (varp == NULL) /* hidden option */
9380 return -1;
9381 if (options[opt_idx].flags & P_NUM)
9382 *numval = *(long *)varp;
9383 else
9384 {
9385 /* Special case: 'modified' is b_changed, but we also want to consider
9386 * it set when 'ff' or 'fenc' changed. */
9387 if ((int *)varp == &curbuf->b_changed)
9388 *numval = curbufIsChanged();
9389 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009390 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009391 }
9392 return 1;
9393}
9394#endif
9395
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009396#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009397/*
9398 * Returns the option attributes and its value. Unlike the above function it
9399 * will return either global value or local value of the option depending on
9400 * what was requested, but it will never return global value if it was
9401 * requested to return local one and vice versa. Neither it will return
9402 * buffer-local value if it was requested to return window-local one.
9403 *
9404 * Pretends that option is absent if it is not present in the requested scope
9405 * (i.e. has no global, window-local or buffer-local value depending on
9406 * opt_type). Uses
9407 *
9408 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009409 * 0 hidden or unknown option, also option that does not have requested
9410 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009411 * see SOPT_* in vim.h for other flags
9412 *
9413 * Possible opt_type values: see SREQ_* in vim.h
9414 */
9415 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009416get_option_value_strict(
9417 char_u *name,
9418 long *numval,
9419 char_u **stringval, /* NULL when only obtaining attributes */
9420 int opt_type,
9421 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009422{
9423 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009424 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009425 struct vimoption *p;
9426 int r = 0;
9427
9428 opt_idx = findoption(name);
9429 if (opt_idx < 0)
9430 return 0;
9431
9432 p = &(options[opt_idx]);
9433
9434 /* Hidden option */
9435 if (p->var == NULL)
9436 return 0;
9437
9438 if (p->flags & P_BOOL)
9439 r |= SOPT_BOOL;
9440 else if (p->flags & P_NUM)
9441 r |= SOPT_NUM;
9442 else if (p->flags & P_STRING)
9443 r |= SOPT_STRING;
9444
9445 if (p->indir == PV_NONE)
9446 {
9447 if (opt_type == SREQ_GLOBAL)
9448 r |= SOPT_GLOBAL;
9449 else
9450 return 0; /* Did not request global-only option */
9451 }
9452 else
9453 {
9454 if (p->indir & PV_BOTH)
9455 r |= SOPT_GLOBAL;
9456 else if (opt_type == SREQ_GLOBAL)
9457 return 0; /* Requested global option */
9458
9459 if (p->indir & PV_WIN)
9460 {
9461 if (opt_type == SREQ_BUF)
9462 return 0; /* Did not request window-local option */
9463 else
9464 r |= SOPT_WIN;
9465 }
9466 else if (p->indir & PV_BUF)
9467 {
9468 if (opt_type == SREQ_WIN)
9469 return 0; /* Did not request buffer-local option */
9470 else
9471 r |= SOPT_BUF;
9472 }
9473 }
9474
9475 if (stringval == NULL)
9476 return r;
9477
9478 if (opt_type == SREQ_GLOBAL)
9479 varp = p->var;
9480 else
9481 {
9482 if (opt_type == SREQ_BUF)
9483 {
9484 /* Special case: 'modified' is b_changed, but we also want to
9485 * consider it set when 'ff' or 'fenc' changed. */
9486 if (p->indir == PV_MOD)
9487 {
9488 *numval = bufIsChanged((buf_T *) from);
9489 varp = NULL;
9490 }
9491#ifdef FEAT_CRYPT
9492 else if (p->indir == PV_KEY)
9493 {
9494 /* never return the value of the crypt key */
9495 *stringval = NULL;
9496 varp = NULL;
9497 }
9498#endif
9499 else
9500 {
9501 aco_save_T aco;
9502 aucmd_prepbuf(&aco, (buf_T *) from);
9503 varp = get_varp(p);
9504 aucmd_restbuf(&aco);
9505 }
9506 }
9507 else if (opt_type == SREQ_WIN)
9508 {
9509 win_T *save_curwin;
9510 save_curwin = curwin;
9511 curwin = (win_T *) from;
9512 curbuf = curwin->w_buffer;
9513 varp = get_varp(p);
9514 curwin = save_curwin;
9515 curbuf = curwin->w_buffer;
9516 }
9517 if (varp == p->var)
9518 return (r | SOPT_UNSET);
9519 }
9520
9521 if (varp != NULL)
9522 {
9523 if (p->flags & P_STRING)
9524 *stringval = vim_strsave(*(char_u **)(varp));
9525 else if (p->flags & P_NUM)
9526 *numval = *(long *) varp;
9527 else
9528 *numval = *(int *)varp;
9529 }
9530
9531 return r;
9532}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009533
9534/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009535 * Iterate over options. First argument is a pointer to a pointer to a
9536 * structure inside options[] array, second is option type like in the above
9537 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009538 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009539 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009540 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009541 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009542 * first argument to NULL.
9543 *
9544 * Returns full option name for current option on each call.
9545 */
9546 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009547option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009548{
9549 struct vimoption *ret = NULL;
9550 do
9551 {
9552 if (*option == NULL)
9553 *option = (void *) options;
9554 else if (((struct vimoption *) (*option))->fullname == NULL)
9555 {
9556 *option = NULL;
9557 return NULL;
9558 }
9559 else
9560 *option = (void *) (((struct vimoption *) (*option)) + 1);
9561
9562 ret = ((struct vimoption *) (*option));
9563
9564 /* Hidden option */
9565 if (ret->var == NULL)
9566 {
9567 ret = NULL;
9568 continue;
9569 }
9570
9571 switch (opt_type)
9572 {
9573 case SREQ_GLOBAL:
9574 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9575 ret = NULL;
9576 break;
9577 case SREQ_BUF:
9578 if (!(ret->indir & PV_BUF))
9579 ret = NULL;
9580 break;
9581 case SREQ_WIN:
9582 if (!(ret->indir & PV_WIN))
9583 ret = NULL;
9584 break;
9585 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009586 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009587 return NULL;
9588 }
9589 }
9590 while (ret == NULL);
9591
9592 return (char_u *)ret->fullname;
9593}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009594#endif
9595
Bram Moolenaar071d4272004-06-13 20:20:40 +00009596/*
9597 * Set the value of option "name".
9598 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009599 *
9600 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009601 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009602 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009603set_option_value(
9604 char_u *name,
9605 long number,
9606 char_u *string,
9607 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009608{
9609 int opt_idx;
9610 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009611 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009612
9613 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009614 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009615 {
9616 int key;
9617
9618 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9619 && (key = find_key_option(name)) != 0)
9620 {
9621 char_u key_name[2];
9622
9623 if (key < 0)
9624 {
9625 key_name[0] = KEY2TERMCAP0(key);
9626 key_name[1] = KEY2TERMCAP1(key);
9627 }
9628 else
9629 {
9630 key_name[0] = KS_KEY;
9631 key_name[1] = (key & 0xff);
9632 }
9633 add_termcode(key_name, string, FALSE);
9634 if (full_screen)
9635 ttest(FALSE);
9636 redraw_all_later(CLEAR);
9637 return NULL;
9638 }
9639
Bram Moolenaar071d4272004-06-13 20:20:40 +00009640 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009642 else
9643 {
9644 flags = options[opt_idx].flags;
9645#ifdef HAVE_SANDBOX
9646 /* Disallow changing some options in the sandbox */
9647 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009648 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009649 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009650 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009653 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009654 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009655 else
9656 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009657 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009658 if (varp != NULL) /* hidden option is not changed */
9659 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009660 if (number == 0 && string != NULL)
9661 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009662 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009663
9664 /* Either we are given a string or we are setting option
9665 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009666 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009667 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009668 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009669 {
9670 /* There's another character after zeros or the string
9671 * is empty. In both cases, we are trying to set a
9672 * num option using a string. */
9673 EMSG3(_("E521: Number required: &%s = '%s'"),
9674 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009675 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009676
9677 }
9678 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009679 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009680 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009681 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009682 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009683 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009684 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009685 }
9686 }
9687 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009688 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009689}
9690
9691/*
9692 * Get the terminal code for a terminal option.
9693 * Returns NULL when not found.
9694 */
9695 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009696get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009697{
9698 int opt_idx;
9699 char_u *varp;
9700
9701 if (tname[0] != 't' || tname[1] != '_' ||
9702 tname[2] == NUL || tname[3] == NUL)
9703 return NULL;
9704 if ((opt_idx = findoption(tname)) >= 0)
9705 {
9706 varp = get_varp(&(options[opt_idx]));
9707 if (varp != NULL)
9708 varp = *(char_u **)(varp);
9709 return varp;
9710 }
9711 return find_termcode(tname + 2);
9712}
9713
9714 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009715get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716{
9717 int i;
9718
9719 i = findoption((char_u *)"hl");
9720 if (i >= 0)
9721 return options[i].def_val[VI_DEFAULT];
9722 return (char_u *)NULL;
9723}
9724
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009725#if defined(FEAT_MBYTE) || defined(PROTO)
9726 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009727get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009728{
9729 int i;
9730
9731 i = findoption((char_u *)"enc");
9732 if (i >= 0)
9733 return options[i].def_val[VI_DEFAULT];
9734 return (char_u *)NULL;
9735}
9736#endif
9737
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738/*
9739 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9740 */
9741 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009742find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009743{
9744 int key;
9745 int modifiers;
9746
9747 /*
9748 * Don't use get_special_key_code() for t_xx, we don't want it to call
9749 * add_termcap_entry().
9750 */
9751 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9752 key = TERMCAP2KEY(arg[2], arg[3]);
9753 else
9754 {
9755 --arg; /* put arg at the '<' */
9756 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009757 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758 if (modifiers) /* can't handle modifiers here */
9759 key = 0;
9760 }
9761 return key;
9762}
9763
9764/*
9765 * if 'all' == 0: show changed options
9766 * if 'all' == 1: show all normal options
9767 * if 'all' == 2: show all terminal options
9768 */
9769 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009770showoptions(
9771 int all,
9772 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009773{
9774 struct vimoption *p;
9775 int col;
9776 int isterm;
9777 char_u *varp;
9778 struct vimoption **items;
9779 int item_count;
9780 int run;
9781 int row, rows;
9782 int cols;
9783 int i;
9784 int len;
9785
9786#define INC 20
9787#define GAP 3
9788
9789 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9790 PARAM_COUNT));
9791 if (items == NULL)
9792 return;
9793
9794 /* Highlight title */
9795 if (all == 2)
9796 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9797 else if (opt_flags & OPT_GLOBAL)
9798 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9799 else if (opt_flags & OPT_LOCAL)
9800 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9801 else
9802 MSG_PUTS_TITLE(_("\n--- Options ---"));
9803
9804 /*
9805 * do the loop two times:
9806 * 1. display the short items
9807 * 2. display the long items (only strings and numbers)
9808 */
9809 for (run = 1; run <= 2 && !got_int; ++run)
9810 {
9811 /*
9812 * collect the items in items[]
9813 */
9814 item_count = 0;
9815 for (p = &options[0]; p->fullname != NULL; p++)
9816 {
9817 varp = NULL;
9818 isterm = istermoption(p);
9819 if (opt_flags != 0)
9820 {
9821 if (p->indir != PV_NONE && !isterm)
9822 varp = get_varp_scope(p, opt_flags);
9823 }
9824 else
9825 varp = get_varp(p);
9826 if (varp != NULL
9827 && ((all == 2 && isterm)
9828 || (all == 1 && !isterm)
9829 || (all == 0 && !optval_default(p, varp))))
9830 {
9831 if (p->flags & P_BOOL)
9832 len = 1; /* a toggle option fits always */
9833 else
9834 {
9835 option_value2string(p, opt_flags);
9836 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9837 }
9838 if ((len <= INC - GAP && run == 1) ||
9839 (len > INC - GAP && run == 2))
9840 items[item_count++] = p;
9841 }
9842 }
9843
9844 /*
9845 * display the items
9846 */
9847 if (run == 1)
9848 {
9849 cols = (Columns + GAP - 3) / INC;
9850 if (cols == 0)
9851 cols = 1;
9852 rows = (item_count + cols - 1) / cols;
9853 }
9854 else /* run == 2 */
9855 rows = item_count;
9856 for (row = 0; row < rows && !got_int; ++row)
9857 {
9858 msg_putchar('\n'); /* go to next line */
9859 if (got_int) /* 'q' typed in more */
9860 break;
9861 col = 0;
9862 for (i = row; i < item_count; i += rows)
9863 {
9864 msg_col = col; /* make columns */
9865 showoneopt(items[i], opt_flags);
9866 col += INC;
9867 }
9868 out_flush();
9869 ui_breakcheck();
9870 }
9871 }
9872 vim_free(items);
9873}
9874
9875/*
9876 * Return TRUE if option "p" has its default value.
9877 */
9878 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009879optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009880{
9881 int dvi;
9882
9883 if (varp == NULL)
9884 return TRUE; /* hidden option is always at default */
9885 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9886 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009887 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009889 /* the cast to long is required for Manx C, long_i is
9890 * needed for MSVC */
9891 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892 /* P_STRING */
9893 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9894}
9895
9896/*
9897 * showoneopt: show the value of one option
9898 * must not be called with a hidden option!
9899 */
9900 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009901showoneopt(
9902 struct vimoption *p,
9903 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009904{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009905 char_u *varp;
9906 int save_silent = silent_mode;
9907
9908 silent_mode = FALSE;
9909 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910
9911 varp = get_varp_scope(p, opt_flags);
9912
9913 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9914 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9915 ? !curbufIsChanged() : !*(int *)varp))
9916 MSG_PUTS("no");
9917 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9918 MSG_PUTS("--");
9919 else
9920 MSG_PUTS(" ");
9921 MSG_PUTS(p->fullname);
9922 if (!(p->flags & P_BOOL))
9923 {
9924 msg_putchar('=');
9925 /* put value string in NameBuff */
9926 option_value2string(p, opt_flags);
9927 msg_outtrans(NameBuff);
9928 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009929
9930 silent_mode = save_silent;
9931 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932}
9933
9934/*
9935 * Write modified options as ":set" commands to a file.
9936 *
9937 * There are three values for "opt_flags":
9938 * OPT_GLOBAL: Write global option values and fresh values of
9939 * buffer-local options (used for start of a session
9940 * file).
9941 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9942 * curwin (used for a vimrc file).
9943 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9944 * and local values for window-local options of
9945 * curwin. Local values are also written when at the
9946 * default value, because a modeline or autocommand
9947 * may have set them when doing ":edit file" and the
9948 * user has set them back at the default or fresh
9949 * value.
9950 * When "local_only" is TRUE, don't write fresh
9951 * values, only local values (for ":mkview").
9952 * (fresh value = value used for a new buffer or window for a local option).
9953 *
9954 * Return FAIL on error, OK otherwise.
9955 */
9956 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009957makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958{
9959 struct vimoption *p;
9960 char_u *varp; /* currently used value */
9961 char_u *varp_fresh; /* local value */
9962 char_u *varp_local = NULL; /* fresh value */
9963 char *cmd;
9964 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009965 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966
9967 /*
9968 * The options that don't have a default (terminal name, columns, lines)
9969 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009970 * Do the loop over "options[]" twice: once for options with the
9971 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009973 for (pri = 1; pri >= 0; --pri)
9974 {
9975 for (p = &options[0]; !istermoption(p); p++)
9976 if (!(p->flags & P_NO_MKRC)
9977 && !istermoption(p)
9978 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979 {
9980 /* skip global option when only doing locals */
9981 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9982 continue;
9983
9984 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9985 * file, they are always buffer-specific. */
9986 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9987 continue;
9988
9989 /* Global values are only written when not at the default value. */
9990 varp = get_varp_scope(p, opt_flags);
9991 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9992 continue;
9993
9994 round = 2;
9995 if (p->indir != PV_NONE)
9996 {
9997 if (p->var == VAR_WIN)
9998 {
9999 /* skip window-local option when only doing globals */
10000 if (!(opt_flags & OPT_LOCAL))
10001 continue;
10002 /* When fresh value of window-local option is not at the
10003 * default, need to write it too. */
10004 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10005 {
10006 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10007 if (!optval_default(p, varp_fresh))
10008 {
10009 round = 1;
10010 varp_local = varp;
10011 varp = varp_fresh;
10012 }
10013 }
10014 }
10015 }
10016
10017 /* Round 1: fresh value for window-local options.
10018 * Round 2: other values */
10019 for ( ; round <= 2; varp = varp_local, ++round)
10020 {
10021 if (round == 1 || (opt_flags & OPT_GLOBAL))
10022 cmd = "set";
10023 else
10024 cmd = "setlocal";
10025
10026 if (p->flags & P_BOOL)
10027 {
10028 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10029 return FAIL;
10030 }
10031 else if (p->flags & P_NUM)
10032 {
10033 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10034 return FAIL;
10035 }
10036 else /* P_STRING */
10037 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010038#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10039 int do_endif = FALSE;
10040
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041 /* Don't set 'syntax' and 'filetype' again if the value is
10042 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010043 if (
10044# if defined(FEAT_SYN_HL)
10045 p->indir == PV_SYN
10046# if defined(FEAT_AUTOCMD)
10047 ||
10048# endif
10049# endif
10050# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010051 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010052# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010053 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010054 {
10055 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10056 *(char_u **)(varp)) < 0
10057 || put_eol(fd) < 0)
10058 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010059 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010060 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10063 (p->flags & P_EXPAND) != 0) == FAIL)
10064 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010065#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10066 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010067 {
10068 if (put_line(fd, "endif") == FAIL)
10069 return FAIL;
10070 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072 }
10073 }
10074 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010075 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010076 return OK;
10077}
10078
10079#if defined(FEAT_FOLDING) || defined(PROTO)
10080/*
10081 * Generate set commands for the local fold options only. Used when
10082 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10083 */
10084 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010085makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010086{
10087 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10088# ifdef FEAT_EVAL
10089 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10090 == FAIL
10091# endif
10092 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10093 == FAIL
10094 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10095 == FAIL
10096 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10097 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10098 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10099 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10100 )
10101 return FAIL;
10102
10103 return OK;
10104}
10105#endif
10106
10107 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010108put_setstring(
10109 FILE *fd,
10110 char *cmd,
10111 char *name,
10112 char_u **valuep,
10113 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114{
10115 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010116 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010117
10118 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10119 return FAIL;
10120 if (*valuep != NULL)
10121 {
10122 /* Output 'pastetoggle' as key names. For other
10123 * options some characters have to be escaped with
10124 * CTRL-V or backslash */
10125 if (valuep == &p_pt)
10126 {
10127 s = *valuep;
10128 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010129 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010130 return FAIL;
10131 }
10132 else if (expand)
10133 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010134 buf = alloc(MAXPATHL);
10135 if (buf == NULL)
10136 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10138 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010139 {
10140 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010142 }
10143 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010144 }
10145 else if (put_escstr(fd, *valuep, 2) == FAIL)
10146 return FAIL;
10147 }
10148 if (put_eol(fd) < 0)
10149 return FAIL;
10150 return OK;
10151}
10152
10153 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010154put_setnum(
10155 FILE *fd,
10156 char *cmd,
10157 char *name,
10158 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159{
10160 long wc;
10161
10162 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10163 return FAIL;
10164 if (wc_use_keyname((char_u *)valuep, &wc))
10165 {
10166 /* print 'wildchar' and 'wildcharm' as a key name */
10167 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10168 return FAIL;
10169 }
10170 else if (fprintf(fd, "%ld", *valuep) < 0)
10171 return FAIL;
10172 if (put_eol(fd) < 0)
10173 return FAIL;
10174 return OK;
10175}
10176
10177 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010178put_setbool(
10179 FILE *fd,
10180 char *cmd,
10181 char *name,
10182 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010183{
Bram Moolenaar893de922007-10-02 18:40:57 +000010184 if (value < 0) /* global/local option using global value */
10185 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10187 || put_eol(fd) < 0)
10188 return FAIL;
10189 return OK;
10190}
10191
10192/*
10193 * Clear all the terminal options.
10194 * If the option has been allocated, free the memory.
10195 * Terminal options are never hidden or indirect.
10196 */
10197 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010198clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200 /*
10201 * Reset a few things before clearing the old options. This may cause
10202 * outputting a few things that the terminal doesn't understand, but the
10203 * screen will be cleared later, so this is OK.
10204 */
10205#ifdef FEAT_MOUSE_TTY
10206 mch_setmouse(FALSE); /* switch mouse off */
10207#endif
10208#ifdef FEAT_TITLE
10209 mch_restore_title(3); /* restore window titles */
10210#endif
10211#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10212 /* When starting the GUI close the display opened for the clipboard.
10213 * After restoring the title, because that will need the display. */
10214 if (gui.starting)
10215 clear_xterm_clip();
10216#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010217 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010219 free_termoptions();
10220}
10221
10222 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010223free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010224{
10225 struct vimoption *p;
10226
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227 for (p = &options[0]; p->fullname != NULL; p++)
10228 if (istermoption(p))
10229 {
10230 if (p->flags & P_ALLOCED)
10231 free_string_option(*(char_u **)(p->var));
10232 if (p->flags & P_DEF_ALLOCED)
10233 free_string_option(p->def_val[VI_DEFAULT]);
10234 *(char_u **)(p->var) = empty_option;
10235 p->def_val[VI_DEFAULT] = empty_option;
10236 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10237 }
10238 clear_termcodes();
10239}
10240
10241/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010242 * Free the string for one term option, if it was allocated.
10243 * Set the string to empty_option and clear allocated flag.
10244 * "var" points to the option value.
10245 */
10246 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010247free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010248{
10249 struct vimoption *p;
10250
10251 for (p = &options[0]; p->fullname != NULL; p++)
10252 if (p->var == var)
10253 {
10254 if (p->flags & P_ALLOCED)
10255 free_string_option(*(char_u **)(p->var));
10256 *(char_u **)(p->var) = empty_option;
10257 p->flags &= ~P_ALLOCED;
10258 break;
10259 }
10260}
10261
10262/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010263 * Set the terminal option defaults to the current value.
10264 * Used after setting the terminal name.
10265 */
10266 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010267set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268{
10269 struct vimoption *p;
10270
10271 for (p = &options[0]; p->fullname != NULL; p++)
10272 {
10273 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10274 {
10275 if (p->flags & P_DEF_ALLOCED)
10276 {
10277 free_string_option(p->def_val[VI_DEFAULT]);
10278 p->flags &= ~P_DEF_ALLOCED;
10279 }
10280 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10281 if (p->flags & P_ALLOCED)
10282 {
10283 p->flags |= P_DEF_ALLOCED;
10284 p->flags &= ~P_ALLOCED; /* don't free the value now */
10285 }
10286 }
10287 }
10288}
10289
10290/*
10291 * return TRUE if 'p' starts with 't_'
10292 */
10293 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010294istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010295{
10296 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10297}
10298
10299/*
10300 * Compute columns for ruler and shown command. 'sc_col' is also used to
10301 * decide what the maximum length of a message on the status line can be.
10302 * If there is a status line for the last window, 'sc_col' is independent
10303 * of 'ru_col'.
10304 */
10305
10306#define COL_RULER 17 /* columns needed by standard ruler */
10307
10308 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010309comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010310{
10311#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010312 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313
10314 sc_col = 0;
10315 ru_col = 0;
10316 if (p_ru)
10317 {
10318#ifdef FEAT_STL_OPT
10319 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10320#else
10321 ru_col = COL_RULER + 1;
10322#endif
10323 /* no last status line, adjust sc_col */
10324 if (!last_has_status)
10325 sc_col = ru_col;
10326 }
10327 if (p_sc)
10328 {
10329 sc_col += SHOWCMD_COLS;
10330 if (!p_ru || last_has_status) /* no need for separating space */
10331 ++sc_col;
10332 }
10333 sc_col = Columns - sc_col;
10334 ru_col = Columns - ru_col;
10335 if (sc_col <= 0) /* screen too narrow, will become a mess */
10336 sc_col = 1;
10337 if (ru_col <= 0)
10338 ru_col = 1;
10339#else
10340 sc_col = Columns;
10341 ru_col = Columns;
10342#endif
10343}
10344
10345/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010346 * Unset local option value, similar to ":set opt<".
10347 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010348 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010349unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010350{
10351 struct vimoption *p;
10352 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010353 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010354
10355 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010356 if (opt_idx < 0)
10357 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010358 p = &(options[opt_idx]);
10359
10360 switch ((int)p->indir)
10361 {
10362 /* global option with local value: use local value if it's been set */
10363 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010364 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010365 break;
10366 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010367 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010368 break;
10369 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010370 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010371 break;
10372 case PV_AR:
10373 buf->b_p_ar = -1;
10374 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010375 case PV_BKC:
10376 clear_string_option(&buf->b_p_bkc);
10377 buf->b_bkc_flags = 0;
10378 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010379 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010380 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010381 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010382 case PV_TC:
10383 clear_string_option(&buf->b_p_tc);
10384 buf->b_tc_flags = 0;
10385 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010386#ifdef FEAT_FIND_ID
10387 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010388 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010389 break;
10390 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010391 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010392 break;
10393#endif
10394#ifdef FEAT_INS_EXPAND
10395 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010396 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010397 break;
10398 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010399 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010400 break;
10401#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010402 case PV_FP:
10403 clear_string_option(&buf->b_p_fp);
10404 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010405#ifdef FEAT_QUICKFIX
10406 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010407 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010408 break;
10409 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010410 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010411 break;
10412 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010413 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010414 break;
10415#endif
10416#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10417 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010418 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010419 break;
10420#endif
10421#if defined(FEAT_CRYPT)
10422 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010423 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010424 break;
10425#endif
10426#ifdef FEAT_STL_OPT
10427 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010428 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010429 break;
10430#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010431 case PV_UL:
10432 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10433 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010434#ifdef FEAT_LISP
10435 case PV_LW:
10436 clear_string_option(&buf->b_p_lw);
10437 break;
10438#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010439#ifdef FEAT_MBYTE
10440 case PV_MENC:
10441 clear_string_option(&buf->b_p_menc);
10442 break;
10443#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010444 }
10445}
10446
10447/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448 * Get pointer to option variable, depending on local or global scope.
10449 */
10450 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010451get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452{
10453 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10454 {
10455 if (p->var == VAR_WIN)
10456 return (char_u *)GLOBAL_WO(get_varp(p));
10457 return p->var;
10458 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010459 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460 {
10461 switch ((int)p->indir)
10462 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010463 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010465 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10466 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10467 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010468#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010469 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10470 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10471 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010472 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010473 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010474 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010476 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10477 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010478#endif
10479#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010480 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10481 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010483#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10484 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10485#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010486#if defined(FEAT_CRYPT)
10487 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10488#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010489#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010490 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010491#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010492 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010493#ifdef FEAT_LISP
10494 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10495#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010496 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010497#ifdef FEAT_MBYTE
10498 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500 }
10501 return NULL; /* "cannot happen" */
10502 }
10503 return get_varp(p);
10504}
10505
10506/*
10507 * Get pointer to option variable.
10508 */
10509 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010510get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511{
10512 /* hidden option, always return NULL */
10513 if (p->var == NULL)
10514 return NULL;
10515
10516 switch ((int)p->indir)
10517 {
10518 case PV_NONE: return p->var;
10519
10520 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010521 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010523 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010525 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010527 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010529 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010531 case PV_TC: return *curbuf->b_p_tc != NUL
10532 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010533 case PV_BKC: return *curbuf->b_p_bkc != NUL
10534 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010536 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010538 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10540#endif
10541#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010542 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010544 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10546#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010547 case PV_FP: return *curbuf->b_p_fp != NUL
10548 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010550 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010552 case PV_GP: return *curbuf->b_p_gp != NUL
10553 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10554 case PV_MP: return *curbuf->b_p_mp != NUL
10555 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010557#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10558 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10559 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10560#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010561#if defined(FEAT_CRYPT)
10562 case PV_CM: return *curbuf->b_p_cm != NUL
10563 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10564#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010565#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010566 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010567 ? (char_u *)&(curwin->w_p_stl) : p->var;
10568#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010569 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10570 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010571#ifdef FEAT_LISP
10572 case PV_LW: return *curbuf->b_p_lw != NUL
10573 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10574#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010575#ifdef FEAT_MBYTE
10576 case PV_MENC: return *curbuf->b_p_menc != NUL
10577 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10578#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579
10580#ifdef FEAT_ARABIC
10581 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10582#endif
10583 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010584#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010585 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10586#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010587#ifdef FEAT_SYN_HL
10588 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10589 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010590 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010591#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592#ifdef FEAT_DIFF
10593 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10594#endif
10595#ifdef FEAT_FOLDING
10596 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10597 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10598 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10599 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10600 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10601 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10602 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10603# ifdef FEAT_EVAL
10604 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10605 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10606# endif
10607 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10608#endif
10609 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010610 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010611#ifdef FEAT_LINEBREAK
10612 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10613#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010614#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010616 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10619 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10620#endif
10621#ifdef FEAT_RIGHTLEFT
10622 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10623 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10624#endif
10625 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10626 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10627#ifdef FEAT_LINEBREAK
10628 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010629 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10630 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631#endif
10632#ifdef FEAT_SCROLLBIND
10633 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10634#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010635#ifdef FEAT_CURSORBIND
10636 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10637#endif
10638#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010639 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10640 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642
10643 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10644 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10645#ifdef FEAT_MBYTE
10646 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10647#endif
10648#if defined(FEAT_QUICKFIX)
10649 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10650 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10651#endif
10652 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10653 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10654#ifdef FEAT_CINDENT
10655 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10656 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10657 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10658#endif
10659#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10660 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10661#endif
10662#ifdef FEAT_COMMENTS
10663 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10664#endif
10665#ifdef FEAT_FOLDING
10666 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10667#endif
10668#ifdef FEAT_INS_EXPAND
10669 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10670#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010671#ifdef FEAT_COMPL_FUNC
10672 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010673 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010674#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010675 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010676 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010677 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10678#ifdef FEAT_MBYTE
10679 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10680#endif
10681 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10682#ifdef FEAT_AUTOCMD
10683 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10684#endif
10685 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010686 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010687 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10688 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10689 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10690 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10691#ifdef FEAT_FIND_ID
10692# ifdef FEAT_EVAL
10693 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10694# endif
10695#endif
10696#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10697 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10698 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10699#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010700#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010701 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010703#ifdef FEAT_CRYPT
10704 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10705#endif
10706#ifdef FEAT_LISP
10707 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10708#endif
10709 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10710 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10711 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10712 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10713 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010714 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010715#ifdef FEAT_TEXTOBJ
10716 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10719#ifdef FEAT_SMARTINDENT
10720 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10721#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10724#ifdef FEAT_SEARCHPATH
10725 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10726#endif
10727 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10728#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010729 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010730 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10731#endif
10732#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010733 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10734 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10735 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010736#endif
10737 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10738 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10739 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10740 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010741#ifdef FEAT_PERSISTENT_UNDO
10742 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10745#ifdef FEAT_KEYMAP
10746 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10747#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010748#ifdef FEAT_SIGNS
10749 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10750#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010751 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752 }
10753 /* always return a valid pointer to avoid a crash! */
10754 return (char_u *)&(curbuf->b_p_wm);
10755}
10756
10757/*
10758 * Get the value of 'equalprg', either the buffer-local one or the global one.
10759 */
10760 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010761get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762{
10763 if (*curbuf->b_p_ep == NUL)
10764 return p_ep;
10765 return curbuf->b_p_ep;
10766}
10767
10768#if defined(FEAT_WINDOWS) || defined(PROTO)
10769/*
10770 * Copy options from one window to another.
10771 * Used when splitting a window.
10772 */
10773 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010774win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775{
10776 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10777 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10778# ifdef FEAT_RIGHTLEFT
10779# ifdef FEAT_FKMAP
10780 /* Is this right? */
10781 wp_to->w_farsi = wp_from->w_farsi;
10782# endif
10783# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010784#if defined(FEAT_LINEBREAK)
10785 briopt_check(wp_to);
10786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787}
10788#endif
10789
10790/*
10791 * Copy the options from one winopt_T to another.
10792 * Doesn't free the old option values in "to", use clear_winopt() for that.
10793 * The 'scroll' option is not copied, because it depends on the window height.
10794 * The 'previewwindow' option is reset, there can be only one preview window.
10795 */
10796 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010797copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798{
10799#ifdef FEAT_ARABIC
10800 to->wo_arab = from->wo_arab;
10801#endif
10802 to->wo_list = from->wo_list;
10803 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010804 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010805#ifdef FEAT_LINEBREAK
10806 to->wo_nuw = from->wo_nuw;
10807#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808#ifdef FEAT_RIGHTLEFT
10809 to->wo_rl = from->wo_rl;
10810 to->wo_rlc = vim_strsave(from->wo_rlc);
10811#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010812#ifdef FEAT_STL_OPT
10813 to->wo_stl = vim_strsave(from->wo_stl);
10814#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010816#ifdef FEAT_DIFF
10817 to->wo_wrap_save = from->wo_wrap_save;
10818#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819#ifdef FEAT_LINEBREAK
10820 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010821 to->wo_bri = from->wo_bri;
10822 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823#endif
10824#ifdef FEAT_SCROLLBIND
10825 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010826 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010828#ifdef FEAT_CURSORBIND
10829 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010830 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010831#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010832#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010833 to->wo_spell = from->wo_spell;
10834#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010835#ifdef FEAT_SYN_HL
10836 to->wo_cuc = from->wo_cuc;
10837 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010838 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010839#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840#ifdef FEAT_DIFF
10841 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010842 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010844#ifdef FEAT_CONCEAL
10845 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010846 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848#ifdef FEAT_FOLDING
10849 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010850 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010852 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853 to->wo_fdi = vim_strsave(from->wo_fdi);
10854 to->wo_fml = from->wo_fml;
10855 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010856 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010858 to->wo_fdm_save = from->wo_diff_saved
10859 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860 to->wo_fdn = from->wo_fdn;
10861# ifdef FEAT_EVAL
10862 to->wo_fde = vim_strsave(from->wo_fde);
10863 to->wo_fdt = vim_strsave(from->wo_fdt);
10864# endif
10865 to->wo_fmr = vim_strsave(from->wo_fmr);
10866#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010867#ifdef FEAT_SIGNS
10868 to->wo_scl = vim_strsave(from->wo_scl);
10869#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870 check_winopt(to); /* don't want NULL pointers */
10871}
10872
10873/*
10874 * Check string options in a window for a NULL value.
10875 */
10876 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010877check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878{
10879 check_winopt(&win->w_onebuf_opt);
10880 check_winopt(&win->w_allbuf_opt);
10881}
10882
10883/*
10884 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10885 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010886 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010887check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010888{
10889#ifdef FEAT_FOLDING
10890 check_string_option(&wop->wo_fdi);
10891 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010892 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010893# ifdef FEAT_EVAL
10894 check_string_option(&wop->wo_fde);
10895 check_string_option(&wop->wo_fdt);
10896# endif
10897 check_string_option(&wop->wo_fmr);
10898#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010899#ifdef FEAT_SIGNS
10900 check_string_option(&wop->wo_scl);
10901#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902#ifdef FEAT_RIGHTLEFT
10903 check_string_option(&wop->wo_rlc);
10904#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010905#ifdef FEAT_STL_OPT
10906 check_string_option(&wop->wo_stl);
10907#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010908#ifdef FEAT_SYN_HL
10909 check_string_option(&wop->wo_cc);
10910#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010911#ifdef FEAT_CONCEAL
10912 check_string_option(&wop->wo_cocu);
10913#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010914#ifdef FEAT_LINEBREAK
10915 check_string_option(&wop->wo_briopt);
10916#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010917}
10918
10919/*
10920 * Free the allocated memory inside a winopt_T.
10921 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010923clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924{
10925#ifdef FEAT_FOLDING
10926 clear_string_option(&wop->wo_fdi);
10927 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010928 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929# ifdef FEAT_EVAL
10930 clear_string_option(&wop->wo_fde);
10931 clear_string_option(&wop->wo_fdt);
10932# endif
10933 clear_string_option(&wop->wo_fmr);
10934#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010935#ifdef FEAT_SIGNS
10936 clear_string_option(&wop->wo_scl);
10937#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010938#ifdef FEAT_LINEBREAK
10939 clear_string_option(&wop->wo_briopt);
10940#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941#ifdef FEAT_RIGHTLEFT
10942 clear_string_option(&wop->wo_rlc);
10943#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010944#ifdef FEAT_STL_OPT
10945 clear_string_option(&wop->wo_stl);
10946#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010947#ifdef FEAT_SYN_HL
10948 clear_string_option(&wop->wo_cc);
10949#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010950#ifdef FEAT_CONCEAL
10951 clear_string_option(&wop->wo_cocu);
10952#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010953}
10954
10955/*
10956 * Copy global option values to local options for one buffer.
10957 * Used when creating a new buffer and sometimes when entering a buffer.
10958 * flags:
10959 * BCO_ENTER We will enter the buf buffer.
10960 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10961 * appropriate.
10962 * BCO_NOHELP Don't copy the values to a help buffer.
10963 */
10964 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010965buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010966{
10967 int should_copy = TRUE;
10968 char_u *save_p_isk = NULL; /* init for GCC */
10969 int dont_do_help;
10970 int did_isk = FALSE;
10971
10972 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010973 * Skip this when the option defaults have not been set yet. Happens when
10974 * main() allocates the first buffer.
10975 */
10976 if (p_cpo != NULL)
10977 {
10978 /*
10979 * Always copy when entering and 'cpo' contains 'S'.
10980 * Don't copy when already initialized.
10981 * Don't copy when 'cpo' contains 's' and not entering.
10982 * 'S' BCO_ENTER initialized 's' should_copy
10983 * yes yes X X TRUE
10984 * yes no yes X FALSE
10985 * no X yes X FALSE
10986 * X no no yes FALSE
10987 * X no no no TRUE
10988 * no yes no X TRUE
10989 */
10990 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10991 && (buf->b_p_initialized
10992 || (!(flags & BCO_ENTER)
10993 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10994 should_copy = FALSE;
10995
10996 if (should_copy || (flags & BCO_ALWAYS))
10997 {
10998 /* Don't copy the options specific to a help buffer when
10999 * BCO_NOHELP is given or the options were initialized already
11000 * (jumping back to a help file with CTRL-T or CTRL-O) */
11001 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11002 || buf->b_p_initialized;
11003 if (dont_do_help) /* don't free b_p_isk */
11004 {
11005 save_p_isk = buf->b_p_isk;
11006 buf->b_p_isk = NULL;
11007 }
11008 /*
11009 * Always free the allocated strings.
11010 * If not already initialized, set 'readonly' and copy 'fileformat'.
11011 */
11012 if (!buf->b_p_initialized)
11013 {
11014 free_buf_options(buf, TRUE);
11015 buf->b_p_ro = FALSE; /* don't copy readonly */
11016 buf->b_p_tx = p_tx;
11017#ifdef FEAT_MBYTE
11018 buf->b_p_fenc = vim_strsave(p_fenc);
11019#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011020 switch (*p_ffs)
11021 {
11022 case 'm':
11023 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11024 case 'd':
11025 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11026 case 'u':
11027 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11028 default:
11029 buf->b_p_ff = vim_strsave(p_ff);
11030 }
11031 if (buf->b_p_ff != NULL)
11032 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011033#if defined(FEAT_QUICKFIX)
11034 buf->b_p_bh = empty_option;
11035 buf->b_p_bt = empty_option;
11036#endif
11037 }
11038 else
11039 free_buf_options(buf, FALSE);
11040
11041 buf->b_p_ai = p_ai;
11042 buf->b_p_ai_nopaste = p_ai_nopaste;
11043 buf->b_p_sw = p_sw;
11044 buf->b_p_tw = p_tw;
11045 buf->b_p_tw_nopaste = p_tw_nopaste;
11046 buf->b_p_tw_nobin = p_tw_nobin;
11047 buf->b_p_wm = p_wm;
11048 buf->b_p_wm_nopaste = p_wm_nopaste;
11049 buf->b_p_wm_nobin = p_wm_nobin;
11050 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011051#ifdef FEAT_MBYTE
11052 buf->b_p_bomb = p_bomb;
11053#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011054 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055 buf->b_p_et = p_et;
11056 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011057 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011058 buf->b_p_ml = p_ml;
11059 buf->b_p_ml_nobin = p_ml_nobin;
11060 buf->b_p_inf = p_inf;
11061 buf->b_p_swf = p_swf;
11062#ifdef FEAT_INS_EXPAND
11063 buf->b_p_cpt = vim_strsave(p_cpt);
11064#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011065#ifdef FEAT_COMPL_FUNC
11066 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011067 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011068#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011069 buf->b_p_sts = p_sts;
11070 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011071 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072#ifdef FEAT_COMMENTS
11073 buf->b_p_com = vim_strsave(p_com);
11074#endif
11075#ifdef FEAT_FOLDING
11076 buf->b_p_cms = vim_strsave(p_cms);
11077#endif
11078 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011079 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080 buf->b_p_nf = vim_strsave(p_nf);
11081 buf->b_p_mps = vim_strsave(p_mps);
11082#ifdef FEAT_SMARTINDENT
11083 buf->b_p_si = p_si;
11084#endif
11085 buf->b_p_ci = p_ci;
11086#ifdef FEAT_CINDENT
11087 buf->b_p_cin = p_cin;
11088 buf->b_p_cink = vim_strsave(p_cink);
11089 buf->b_p_cino = vim_strsave(p_cino);
11090#endif
11091#ifdef FEAT_AUTOCMD
11092 /* Don't copy 'filetype', it must be detected */
11093 buf->b_p_ft = empty_option;
11094#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095 buf->b_p_pi = p_pi;
11096#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11097 buf->b_p_cinw = vim_strsave(p_cinw);
11098#endif
11099#ifdef FEAT_LISP
11100 buf->b_p_lisp = p_lisp;
11101#endif
11102#ifdef FEAT_SYN_HL
11103 /* Don't copy 'syntax', it must be set */
11104 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011105 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011106 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011107#endif
11108#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011109 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011110 (void)compile_cap_prog(&buf->b_s);
11111 buf->b_s.b_p_spf = vim_strsave(p_spf);
11112 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113#endif
11114#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11115 buf->b_p_inde = vim_strsave(p_inde);
11116 buf->b_p_indk = vim_strsave(p_indk);
11117#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011118 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011119#if defined(FEAT_EVAL)
11120 buf->b_p_fex = vim_strsave(p_fex);
11121#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122#ifdef FEAT_CRYPT
11123 buf->b_p_key = vim_strsave(p_key);
11124#endif
11125#ifdef FEAT_SEARCHPATH
11126 buf->b_p_sua = vim_strsave(p_sua);
11127#endif
11128#ifdef FEAT_KEYMAP
11129 buf->b_p_keymap = vim_strsave(p_keymap);
11130 buf->b_kmap_state |= KEYMAP_INIT;
11131#endif
11132 /* This isn't really an option, but copying the langmap and IME
11133 * state from the current buffer is better than resetting it. */
11134 buf->b_p_iminsert = p_iminsert;
11135 buf->b_p_imsearch = p_imsearch;
11136
11137 /* options that are normally global but also have a local value
11138 * are not copied, start using the global value */
11139 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011140 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011141 buf->b_p_bkc = empty_option;
11142 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011143#ifdef FEAT_QUICKFIX
11144 buf->b_p_gp = empty_option;
11145 buf->b_p_mp = empty_option;
11146 buf->b_p_efm = empty_option;
11147#endif
11148 buf->b_p_ep = empty_option;
11149 buf->b_p_kp = empty_option;
11150 buf->b_p_path = empty_option;
11151 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011152 buf->b_p_tc = empty_option;
11153 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154#ifdef FEAT_FIND_ID
11155 buf->b_p_def = empty_option;
11156 buf->b_p_inc = empty_option;
11157# ifdef FEAT_EVAL
11158 buf->b_p_inex = vim_strsave(p_inex);
11159# endif
11160#endif
11161#ifdef FEAT_INS_EXPAND
11162 buf->b_p_dict = empty_option;
11163 buf->b_p_tsr = empty_option;
11164#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011165#ifdef FEAT_TEXTOBJ
11166 buf->b_p_qe = vim_strsave(p_qe);
11167#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011168#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11169 buf->b_p_bexpr = empty_option;
11170#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011171#if defined(FEAT_CRYPT)
11172 buf->b_p_cm = empty_option;
11173#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011174#ifdef FEAT_PERSISTENT_UNDO
11175 buf->b_p_udf = p_udf;
11176#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011177#ifdef FEAT_LISP
11178 buf->b_p_lw = empty_option;
11179#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011180#ifdef FEAT_MBYTE
11181 buf->b_p_menc = empty_option;
11182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011183
11184 /*
11185 * Don't copy the options set by ex_help(), use the saved values,
11186 * when going from a help buffer to a non-help buffer.
11187 * Don't touch these at all when BCO_NOHELP is used and going from
11188 * or to a help buffer.
11189 */
11190 if (dont_do_help)
11191 buf->b_p_isk = save_p_isk;
11192 else
11193 {
11194 buf->b_p_isk = vim_strsave(p_isk);
11195 did_isk = TRUE;
11196 buf->b_p_ts = p_ts;
11197 buf->b_help = FALSE;
11198#ifdef FEAT_QUICKFIX
11199 if (buf->b_p_bt[0] == 'h')
11200 clear_string_option(&buf->b_p_bt);
11201#endif
11202 buf->b_p_ma = p_ma;
11203 }
11204 }
11205
11206 /*
11207 * When the options should be copied (ignoring BCO_ALWAYS), set the
11208 * flag that indicates that the options have been initialized.
11209 */
11210 if (should_copy)
11211 buf->b_p_initialized = TRUE;
11212 }
11213
11214 check_buf_options(buf); /* make sure we don't have NULLs */
11215 if (did_isk)
11216 (void)buf_init_chartab(buf, FALSE);
11217}
11218
11219/*
11220 * Reset the 'modifiable' option and its default value.
11221 */
11222 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011223reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011224{
11225 int opt_idx;
11226
11227 curbuf->b_p_ma = FALSE;
11228 p_ma = FALSE;
11229 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011230 if (opt_idx >= 0)
11231 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011232}
11233
11234/*
11235 * Set the global value for 'iminsert' to the local value.
11236 */
11237 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011238set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239{
11240 p_iminsert = curbuf->b_p_iminsert;
11241}
11242
11243/*
11244 * Set the global value for 'imsearch' to the local value.
11245 */
11246 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011247set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248{
11249 p_imsearch = curbuf->b_p_imsearch;
11250}
11251
11252#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11253static int expand_option_idx = -1;
11254static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11255static int expand_option_flags = 0;
11256
11257 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011258set_context_in_set_cmd(
11259 expand_T *xp,
11260 char_u *arg,
11261 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011262{
11263 int nextchar;
11264 long_u flags = 0; /* init for GCC */
11265 int opt_idx = 0; /* init for GCC */
11266 char_u *p;
11267 char_u *s;
11268 int is_term_option = FALSE;
11269 int key;
11270
11271 expand_option_flags = opt_flags;
11272
11273 xp->xp_context = EXPAND_SETTINGS;
11274 if (*arg == NUL)
11275 {
11276 xp->xp_pattern = arg;
11277 return;
11278 }
11279 p = arg + STRLEN(arg) - 1;
11280 if (*p == ' ' && *(p - 1) != '\\')
11281 {
11282 xp->xp_pattern = p + 1;
11283 return;
11284 }
11285 while (p > arg)
11286 {
11287 s = p;
11288 /* count number of backslashes before ' ' or ',' */
11289 if (*p == ' ' || *p == ',')
11290 {
11291 while (s > arg && *(s - 1) == '\\')
11292 --s;
11293 }
11294 /* break at a space with an even number of backslashes */
11295 if (*p == ' ' && ((p - s) & 1) == 0)
11296 {
11297 ++p;
11298 break;
11299 }
11300 --p;
11301 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011302 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303 {
11304 xp->xp_context = EXPAND_BOOL_SETTINGS;
11305 p += 2;
11306 }
11307 if (STRNCMP(p, "inv", 3) == 0)
11308 {
11309 xp->xp_context = EXPAND_BOOL_SETTINGS;
11310 p += 3;
11311 }
11312 xp->xp_pattern = arg = p;
11313 if (*arg == '<')
11314 {
11315 while (*p != '>')
11316 if (*p++ == NUL) /* expand terminal option name */
11317 return;
11318 key = get_special_key_code(arg + 1);
11319 if (key == 0) /* unknown name */
11320 {
11321 xp->xp_context = EXPAND_NOTHING;
11322 return;
11323 }
11324 nextchar = *++p;
11325 is_term_option = TRUE;
11326 expand_option_name[2] = KEY2TERMCAP0(key);
11327 expand_option_name[3] = KEY2TERMCAP1(key);
11328 }
11329 else
11330 {
11331 if (p[0] == 't' && p[1] == '_')
11332 {
11333 p += 2;
11334 if (*p != NUL)
11335 ++p;
11336 if (*p == NUL)
11337 return; /* expand option name */
11338 nextchar = *++p;
11339 is_term_option = TRUE;
11340 expand_option_name[2] = p[-2];
11341 expand_option_name[3] = p[-1];
11342 }
11343 else
11344 {
11345 /* Allow * wildcard */
11346 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11347 p++;
11348 if (*p == NUL)
11349 return;
11350 nextchar = *p;
11351 *p = NUL;
11352 opt_idx = findoption(arg);
11353 *p = nextchar;
11354 if (opt_idx == -1 || options[opt_idx].var == NULL)
11355 {
11356 xp->xp_context = EXPAND_NOTHING;
11357 return;
11358 }
11359 flags = options[opt_idx].flags;
11360 if (flags & P_BOOL)
11361 {
11362 xp->xp_context = EXPAND_NOTHING;
11363 return;
11364 }
11365 }
11366 }
11367 /* handle "-=" and "+=" */
11368 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11369 {
11370 ++p;
11371 nextchar = '=';
11372 }
11373 if ((nextchar != '=' && nextchar != ':')
11374 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11375 {
11376 xp->xp_context = EXPAND_UNSUCCESSFUL;
11377 return;
11378 }
11379 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11380 {
11381 xp->xp_context = EXPAND_OLD_SETTING;
11382 if (is_term_option)
11383 expand_option_idx = -1;
11384 else
11385 expand_option_idx = opt_idx;
11386 xp->xp_pattern = p + 1;
11387 return;
11388 }
11389 xp->xp_context = EXPAND_NOTHING;
11390 if (is_term_option || (flags & P_NUM))
11391 return;
11392
11393 xp->xp_pattern = p + 1;
11394
11395 if (flags & P_EXPAND)
11396 {
11397 p = options[opt_idx].var;
11398 if (p == (char_u *)&p_bdir
11399 || p == (char_u *)&p_dir
11400 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011401 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011402 || p == (char_u *)&p_rtp
11403#ifdef FEAT_SEARCHPATH
11404 || p == (char_u *)&p_cdpath
11405#endif
11406#ifdef FEAT_SESSION
11407 || p == (char_u *)&p_vdir
11408#endif
11409 )
11410 {
11411 xp->xp_context = EXPAND_DIRECTORIES;
11412 if (p == (char_u *)&p_path
11413#ifdef FEAT_SEARCHPATH
11414 || p == (char_u *)&p_cdpath
11415#endif
11416 )
11417 xp->xp_backslash = XP_BS_THREE;
11418 else
11419 xp->xp_backslash = XP_BS_ONE;
11420 }
11421 else
11422 {
11423 xp->xp_context = EXPAND_FILES;
11424 /* for 'tags' need three backslashes for a space */
11425 if (p == (char_u *)&p_tags)
11426 xp->xp_backslash = XP_BS_THREE;
11427 else
11428 xp->xp_backslash = XP_BS_ONE;
11429 }
11430 }
11431
11432 /* For an option that is a list of file names, find the start of the
11433 * last file name. */
11434 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11435 {
11436 /* count number of backslashes before ' ' or ',' */
11437 if (*p == ' ' || *p == ',')
11438 {
11439 s = p;
11440 while (s > xp->xp_pattern && *(s - 1) == '\\')
11441 --s;
11442 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11443 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11444 {
11445 xp->xp_pattern = p + 1;
11446 break;
11447 }
11448 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011449
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011450#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011451 /* for 'spellsuggest' start at "file:" */
11452 if (options[opt_idx].var == (char_u *)&p_sps
11453 && STRNCMP(p, "file:", 5) == 0)
11454 {
11455 xp->xp_pattern = p + 5;
11456 break;
11457 }
11458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011459 }
11460
11461 return;
11462}
11463
11464 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011465ExpandSettings(
11466 expand_T *xp,
11467 regmatch_T *regmatch,
11468 int *num_file,
11469 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011470{
11471 int num_normal = 0; /* Nr of matching non-term-code settings */
11472 int num_term = 0; /* Nr of matching terminal code settings */
11473 int opt_idx;
11474 int match;
11475 int count = 0;
11476 char_u *str;
11477 int loop;
11478 int is_term_opt;
11479 char_u name_buf[MAX_KEY_NAME_LEN];
11480 static char *(names[]) = {"all", "termcap"};
11481 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11482
11483 /* do this loop twice:
11484 * loop == 0: count the number of matching options
11485 * loop == 1: copy the matching options into allocated memory
11486 */
11487 for (loop = 0; loop <= 1; ++loop)
11488 {
11489 regmatch->rm_ic = ic;
11490 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11491 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011492 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11493 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011494 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11495 {
11496 if (loop == 0)
11497 num_normal++;
11498 else
11499 (*file)[count++] = vim_strsave((char_u *)names[match]);
11500 }
11501 }
11502 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11503 opt_idx++)
11504 {
11505 if (options[opt_idx].var == NULL)
11506 continue;
11507 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11508 && !(options[opt_idx].flags & P_BOOL))
11509 continue;
11510 is_term_opt = istermoption(&options[opt_idx]);
11511 if (is_term_opt && num_normal > 0)
11512 continue;
11513 match = FALSE;
11514 if (vim_regexec(regmatch, str, (colnr_T)0)
11515 || (options[opt_idx].shortname != NULL
11516 && vim_regexec(regmatch,
11517 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11518 match = TRUE;
11519 else if (is_term_opt)
11520 {
11521 name_buf[0] = '<';
11522 name_buf[1] = 't';
11523 name_buf[2] = '_';
11524 name_buf[3] = str[2];
11525 name_buf[4] = str[3];
11526 name_buf[5] = '>';
11527 name_buf[6] = NUL;
11528 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11529 {
11530 match = TRUE;
11531 str = name_buf;
11532 }
11533 }
11534 if (match)
11535 {
11536 if (loop == 0)
11537 {
11538 if (is_term_opt)
11539 num_term++;
11540 else
11541 num_normal++;
11542 }
11543 else
11544 (*file)[count++] = vim_strsave(str);
11545 }
11546 }
11547 /*
11548 * Check terminal key codes, these are not in the option table
11549 */
11550 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11551 {
11552 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11553 {
11554 if (!isprint(str[0]) || !isprint(str[1]))
11555 continue;
11556
11557 name_buf[0] = 't';
11558 name_buf[1] = '_';
11559 name_buf[2] = str[0];
11560 name_buf[3] = str[1];
11561 name_buf[4] = NUL;
11562
11563 match = FALSE;
11564 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11565 match = TRUE;
11566 else
11567 {
11568 name_buf[0] = '<';
11569 name_buf[1] = 't';
11570 name_buf[2] = '_';
11571 name_buf[3] = str[0];
11572 name_buf[4] = str[1];
11573 name_buf[5] = '>';
11574 name_buf[6] = NUL;
11575
11576 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11577 match = TRUE;
11578 }
11579 if (match)
11580 {
11581 if (loop == 0)
11582 num_term++;
11583 else
11584 (*file)[count++] = vim_strsave(name_buf);
11585 }
11586 }
11587
11588 /*
11589 * Check special key names.
11590 */
11591 regmatch->rm_ic = TRUE; /* ignore case here */
11592 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11593 {
11594 name_buf[0] = '<';
11595 STRCPY(name_buf + 1, str);
11596 STRCAT(name_buf, ">");
11597
11598 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11599 {
11600 if (loop == 0)
11601 num_term++;
11602 else
11603 (*file)[count++] = vim_strsave(name_buf);
11604 }
11605 }
11606 }
11607 if (loop == 0)
11608 {
11609 if (num_normal > 0)
11610 *num_file = num_normal;
11611 else if (num_term > 0)
11612 *num_file = num_term;
11613 else
11614 return OK;
11615 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11616 if (*file == NULL)
11617 {
11618 *file = (char_u **)"";
11619 return FAIL;
11620 }
11621 }
11622 }
11623 return OK;
11624}
11625
11626 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011627ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628{
11629 char_u *var = NULL; /* init for GCC */
11630 char_u *buf;
11631
11632 *num_file = 0;
11633 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11634 if (*file == NULL)
11635 return FAIL;
11636
11637 /*
11638 * For a terminal key code expand_option_idx is < 0.
11639 */
11640 if (expand_option_idx < 0)
11641 {
11642 var = find_termcode(expand_option_name + 2);
11643 if (var == NULL)
11644 expand_option_idx = findoption(expand_option_name);
11645 }
11646
11647 if (expand_option_idx >= 0)
11648 {
11649 /* put string of option value in NameBuff */
11650 option_value2string(&options[expand_option_idx], expand_option_flags);
11651 var = NameBuff;
11652 }
11653 else if (var == NULL)
11654 var = (char_u *)"";
11655
11656 /* A backslash is required before some characters. This is the reverse of
11657 * what happens in do_set(). */
11658 buf = vim_strsave_escaped(var, escape_chars);
11659
11660 if (buf == NULL)
11661 {
11662 vim_free(*file);
11663 *file = NULL;
11664 return FAIL;
11665 }
11666
11667#ifdef BACKSLASH_IN_FILENAME
11668 /* For MS-Windows et al. we don't double backslashes at the start and
11669 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011670 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011671 if (var[0] == '\\' && var[1] == '\\'
11672 && expand_option_idx >= 0
11673 && (options[expand_option_idx].flags & P_EXPAND)
11674 && vim_isfilec(var[2])
11675 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011676 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677#endif
11678
11679 *file[0] = buf;
11680 *num_file = 1;
11681 return OK;
11682}
11683#endif
11684
11685/*
11686 * Get the value for the numeric or string option *opp in a nice format into
11687 * NameBuff[]. Must not be called with a hidden option!
11688 */
11689 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011690option_value2string(
11691 struct vimoption *opp,
11692 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011693{
11694 char_u *varp;
11695
11696 varp = get_varp_scope(opp, opt_flags);
11697
11698 if (opp->flags & P_NUM)
11699 {
11700 long wc = 0;
11701
11702 if (wc_use_keyname(varp, &wc))
11703 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11704 else if (wc != 0)
11705 STRCPY(NameBuff, transchar((int)wc));
11706 else
11707 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11708 }
11709 else /* P_STRING */
11710 {
11711 varp = *(char_u **)(varp);
11712 if (varp == NULL) /* just in case */
11713 NameBuff[0] = NUL;
11714#ifdef FEAT_CRYPT
11715 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011716 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011717 STRCPY(NameBuff, "*****");
11718#endif
11719 else if (opp->flags & P_EXPAND)
11720 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11721 /* Translate 'pastetoggle' into special key names */
11722 else if ((char_u **)opp->var == &p_pt)
11723 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11724 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011725 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011726 }
11727}
11728
11729/*
11730 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11731 * printed as a keyname.
11732 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11733 */
11734 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011735wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011736{
11737 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11738 {
11739 *wcp = *(long *)varp;
11740 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11741 return TRUE;
11742 }
11743 return FALSE;
11744}
11745
Bram Moolenaar01615492015-02-03 13:00:38 +010011746#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011747/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011748 * Any character has an equivalent 'langmap' character. This is used for
11749 * keyboards that have a special language mode that sends characters above
11750 * 128 (although other characters can be translated too). The "to" field is a
11751 * Vim command character. This avoids having to switch the keyboard back to
11752 * ASCII mode when leaving Insert mode.
11753 *
11754 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11755 * commands.
11756 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11757 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11758 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011760# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011761/*
11762 * With multi-byte support use growarray for 'langmap' chars >= 256
11763 */
11764typedef struct
11765{
11766 int from;
11767 int to;
11768} langmap_entry_T;
11769
11770static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011771static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011772
11773/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011774 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11775 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011777 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011778langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011779{
11780 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011781 int a = 0;
11782 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011783
11784 /* Do a binary search for an existing entry. */
11785 while (a != b)
11786 {
11787 int i = (a + b) / 2;
11788 int d = entries[i].from - from;
11789
11790 if (d == 0)
11791 {
11792 entries[i].to = to;
11793 return;
11794 }
11795 if (d < 0)
11796 a = i + 1;
11797 else
11798 b = i;
11799 }
11800
11801 if (ga_grow(&langmap_mapga, 1) != OK)
11802 return; /* out of memory */
11803
11804 /* insert new entry at position "a" */
11805 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11806 mch_memmove(entries + 1, entries,
11807 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11808 ++langmap_mapga.ga_len;
11809 entries[0].from = from;
11810 entries[0].to = to;
11811}
11812
11813/*
11814 * Apply 'langmap' to multi-byte character "c" and return the result.
11815 */
11816 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011817langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011818{
11819 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11820 int a = 0;
11821 int b = langmap_mapga.ga_len;
11822
11823 while (a != b)
11824 {
11825 int i = (a + b) / 2;
11826 int d = entries[i].from - c;
11827
11828 if (d == 0)
11829 return entries[i].to; /* found matching entry */
11830 if (d < 0)
11831 a = i + 1;
11832 else
11833 b = i;
11834 }
11835 return c; /* no entry found, return "c" unmodified */
11836}
11837# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011838
11839 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011840langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011841{
11842 int i;
11843
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011844 for (i = 0; i < 256; i++)
11845 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11846# ifdef FEAT_MBYTE
11847 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11848# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011849}
11850
11851/*
11852 * Called when langmap option is set; the language map can be
11853 * changed at any time!
11854 */
11855 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011856langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011857{
11858 char_u *p;
11859 char_u *p2;
11860 int from, to;
11861
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011862#ifdef FEAT_MBYTE
11863 ga_clear(&langmap_mapga); /* clear the previous map first */
11864#endif
11865 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011866
11867 for (p = p_langmap; p[0] != NUL; )
11868 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011869 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011870 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011871 {
11872 if (p2[0] == '\\' && p2[1] != NUL)
11873 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011874 }
11875 if (p2[0] == ';')
11876 ++p2; /* abcd;ABCD form, p2 points to A */
11877 else
11878 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11879 while (p[0])
11880 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011881 if (p[0] == ',')
11882 {
11883 ++p;
11884 break;
11885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011886 if (p[0] == '\\' && p[1] != NUL)
11887 ++p;
11888#ifdef FEAT_MBYTE
11889 from = (*mb_ptr2char)(p);
11890#else
11891 from = p[0];
11892#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011893 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011894 if (p2 == NULL)
11895 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011896 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011897 if (p[0] != ',')
11898 {
11899 if (p[0] == '\\')
11900 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011902 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011903#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011904 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011905#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011906 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907 }
11908 else
11909 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011910 if (p2[0] != ',')
11911 {
11912 if (p2[0] == '\\')
11913 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011915 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011916#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011917 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011919 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011920 }
11921 if (to == NUL)
11922 {
11923 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11924 transchar(from));
11925 return;
11926 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011927
11928#ifdef FEAT_MBYTE
11929 if (from >= 256)
11930 langmap_set_entry(from, to);
11931 else
11932#endif
11933 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934
11935 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011936 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011937 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011939 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011940 if (*p == ';')
11941 {
11942 p = p2;
11943 if (p[0] != NUL)
11944 {
11945 if (p[0] != ',')
11946 {
11947 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11948 return;
11949 }
11950 ++p;
11951 }
11952 break;
11953 }
11954 }
11955 }
11956 }
11957}
11958#endif
11959
11960/*
11961 * Return TRUE if format option 'x' is in effect.
11962 * Take care of no formatting when 'paste' is set.
11963 */
11964 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011965has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011966{
11967 if (p_paste)
11968 return FALSE;
11969 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11970}
11971
11972/*
11973 * Return TRUE if "x" is present in 'shortmess' option, or
11974 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11975 */
11976 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011977shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011979 return p_shm != NULL &&
11980 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011981 || (vim_strchr(p_shm, 'a') != NULL
11982 && vim_strchr((char_u *)SHM_A, x) != NULL));
11983}
11984
11985/*
11986 * paste_option_changed() - Called after p_paste was set or reset.
11987 */
11988 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011989paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011990{
11991 static int old_p_paste = FALSE;
11992 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011993 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011994#ifdef FEAT_CMDL_INFO
11995 static int save_ru = 0;
11996#endif
11997#ifdef FEAT_RIGHTLEFT
11998 static int save_ri = 0;
11999 static int save_hkmap = 0;
12000#endif
12001 buf_T *buf;
12002
12003 if (p_paste)
12004 {
12005 /*
12006 * Paste switched from off to on.
12007 * Save the current values, so they can be restored later.
12008 */
12009 if (!old_p_paste)
12010 {
12011 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012012 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012013 {
12014 buf->b_p_tw_nopaste = buf->b_p_tw;
12015 buf->b_p_wm_nopaste = buf->b_p_wm;
12016 buf->b_p_sts_nopaste = buf->b_p_sts;
12017 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012018 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012019 }
12020
12021 /* save global options */
12022 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012023 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012024#ifdef FEAT_CMDL_INFO
12025 save_ru = p_ru;
12026#endif
12027#ifdef FEAT_RIGHTLEFT
12028 save_ri = p_ri;
12029 save_hkmap = p_hkmap;
12030#endif
12031 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012032 p_ai_nopaste = p_ai;
12033 p_et_nopaste = p_et;
12034 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035 p_tw_nopaste = p_tw;
12036 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012037 }
12038
12039 /*
12040 * Always set the option values, also when 'paste' is set when it is
12041 * already on.
12042 */
12043 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012044 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045 {
12046 buf->b_p_tw = 0; /* textwidth is 0 */
12047 buf->b_p_wm = 0; /* wrapmargin is 0 */
12048 buf->b_p_sts = 0; /* softtabstop is 0 */
12049 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012050 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012051 }
12052
12053 /* set global options */
12054 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012055 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056#ifdef FEAT_CMDL_INFO
12057# ifdef FEAT_WINDOWS
12058 if (p_ru)
12059 status_redraw_all(); /* redraw to remove the ruler */
12060# endif
12061 p_ru = 0; /* no ruler */
12062#endif
12063#ifdef FEAT_RIGHTLEFT
12064 p_ri = 0; /* no reverse insert */
12065 p_hkmap = 0; /* no Hebrew keyboard */
12066#endif
12067 /* set global values for local buffer options */
12068 p_tw = 0;
12069 p_wm = 0;
12070 p_sts = 0;
12071 p_ai = 0;
12072 }
12073
12074 /*
12075 * Paste switched from on to off: Restore saved values.
12076 */
12077 else if (old_p_paste)
12078 {
12079 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012080 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081 {
12082 buf->b_p_tw = buf->b_p_tw_nopaste;
12083 buf->b_p_wm = buf->b_p_wm_nopaste;
12084 buf->b_p_sts = buf->b_p_sts_nopaste;
12085 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012086 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087 }
12088
12089 /* restore global options */
12090 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012091 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092#ifdef FEAT_CMDL_INFO
12093# ifdef FEAT_WINDOWS
12094 if (p_ru != save_ru)
12095 status_redraw_all(); /* redraw to draw the ruler */
12096# endif
12097 p_ru = save_ru;
12098#endif
12099#ifdef FEAT_RIGHTLEFT
12100 p_ri = save_ri;
12101 p_hkmap = save_hkmap;
12102#endif
12103 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012104 p_ai = p_ai_nopaste;
12105 p_et = p_et_nopaste;
12106 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107 p_tw = p_tw_nopaste;
12108 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 }
12110
12111 old_p_paste = p_paste;
12112}
12113
12114/*
12115 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12116 *
12117 * Reset 'compatible' and set the values for options that didn't get set yet
12118 * to the Vim defaults.
12119 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012120 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 */
12122 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012123vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012124{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012125 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012126 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012127 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128
12129 if (!option_was_set((char_u *)"cp"))
12130 {
12131 p_cp = FALSE;
12132 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12133 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12134 set_option_default(opt_idx, OPT_FREE, FALSE);
12135 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012136 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012138
12139 if (fname != NULL)
12140 {
12141 p = vim_getenv(envname, &dofree);
12142 if (p == NULL)
12143 {
12144 /* Set $MYVIMRC to the first vimrc file found. */
12145 p = FullName_save(fname, FALSE);
12146 if (p != NULL)
12147 {
12148 vim_setenv(envname, p);
12149 vim_free(p);
12150 }
12151 }
12152 else if (dofree)
12153 vim_free(p);
12154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155}
12156
12157/*
12158 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12159 */
12160 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012161change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012162{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012163 int opt_idx;
12164
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 if (p_cp != on)
12166 {
12167 p_cp = on;
12168 compatible_set();
12169 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012170 opt_idx = findoption((char_u *)"cp");
12171 if (opt_idx >= 0)
12172 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173}
12174
12175/*
12176 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012177 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012178 */
12179 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012180option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012181{
12182 int idx;
12183
12184 idx = findoption(name);
12185 if (idx < 0) /* unknown option */
12186 return FALSE;
12187 if (options[idx].flags & P_WAS_SET)
12188 return TRUE;
12189 return FALSE;
12190}
12191
12192/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012193 * Reset the flag indicating option "name" was set.
12194 */
12195 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012196reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012197{
12198 int idx = findoption(name);
12199
12200 if (idx >= 0)
12201 options[idx].flags &= ~P_WAS_SET;
12202}
12203
12204/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012205 * compatible_set() - Called when 'compatible' has been set or unset.
12206 *
12207 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12208 * flag) to a Vi compatible value.
12209 * When 'compatible' is unset: Set all options that have a different default
12210 * for Vim (without the P_VI_DEF flag) to that default.
12211 */
12212 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012213compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012214{
12215 int opt_idx;
12216
12217 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12218 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12219 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12220 set_option_default(opt_idx, OPT_FREE, p_cp);
12221 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012222 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012223}
12224
12225#ifdef FEAT_LINEBREAK
12226
12227# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12228 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012229 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012230# endif
12231
12232/*
12233 * fill_breakat_flags() -- called when 'breakat' changes value.
12234 */
12235 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012236fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012237{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012238 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012239 int i;
12240
12241 for (i = 0; i < 256; i++)
12242 breakat_flags[i] = FALSE;
12243
12244 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012245 for (p = p_breakat; *p; p++)
12246 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012247}
12248
12249# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012250 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251# endif
12252
12253#endif
12254
12255/*
12256 * Check an option that can be a range of string values.
12257 *
12258 * Return OK for correct value, FAIL otherwise.
12259 * Empty is always OK.
12260 */
12261 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012262check_opt_strings(
12263 char_u *val,
12264 char **values,
12265 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012266{
12267 return opt_strings_flags(val, values, NULL, list);
12268}
12269
12270/*
12271 * Handle an option that can be a range of string values.
12272 * Set a flag in "*flagp" for each string present.
12273 *
12274 * Return OK for correct value, FAIL otherwise.
12275 * Empty is always OK.
12276 */
12277 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012278opt_strings_flags(
12279 char_u *val, /* new value */
12280 char **values, /* array of valid string values */
12281 unsigned *flagp,
12282 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283{
12284 int i;
12285 int len;
12286 unsigned new_flags = 0;
12287
12288 while (*val)
12289 {
12290 for (i = 0; ; ++i)
12291 {
12292 if (values[i] == NULL) /* val not found in values[] */
12293 return FAIL;
12294
12295 len = (int)STRLEN(values[i]);
12296 if (STRNCMP(values[i], val, len) == 0
12297 && ((list && val[len] == ',') || val[len] == NUL))
12298 {
12299 val += len + (val[len] == ',');
12300 new_flags |= (1 << i);
12301 break; /* check next item in val list */
12302 }
12303 }
12304 }
12305 if (flagp != NULL)
12306 *flagp = new_flags;
12307
12308 return OK;
12309}
12310
12311/*
12312 * Read the 'wildmode' option, fill wim_flags[].
12313 */
12314 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012315check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012316{
12317 char_u new_wim_flags[4];
12318 char_u *p;
12319 int i;
12320 int idx = 0;
12321
12322 for (i = 0; i < 4; ++i)
12323 new_wim_flags[i] = 0;
12324
12325 for (p = p_wim; *p; ++p)
12326 {
12327 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12328 ;
12329 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12330 return FAIL;
12331 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12332 new_wim_flags[idx] |= WIM_LONGEST;
12333 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12334 new_wim_flags[idx] |= WIM_FULL;
12335 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12336 new_wim_flags[idx] |= WIM_LIST;
12337 else
12338 return FAIL;
12339 p += i;
12340 if (*p == NUL)
12341 break;
12342 if (*p == ',')
12343 {
12344 if (idx == 3)
12345 return FAIL;
12346 ++idx;
12347 }
12348 }
12349
12350 /* fill remaining entries with last flag */
12351 while (idx < 3)
12352 {
12353 new_wim_flags[idx + 1] = new_wim_flags[idx];
12354 ++idx;
12355 }
12356
12357 /* only when there are no errors, wim_flags[] is changed */
12358 for (i = 0; i < 4; ++i)
12359 wim_flags[i] = new_wim_flags[i];
12360 return OK;
12361}
12362
12363/*
12364 * Check if backspacing over something is allowed.
12365 */
12366 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012367can_bs(
12368 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012369{
12370 switch (*p_bs)
12371 {
12372 case '2': return TRUE;
12373 case '1': return (what != BS_START);
12374 case '0': return FALSE;
12375 }
12376 return vim_strchr(p_bs, what) != NULL;
12377}
12378
12379/*
12380 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12381 * the file must be considered changed when the value is different.
12382 */
12383 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012384save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012385{
12386 buf->b_start_ffc = *buf->b_p_ff;
12387 buf->b_start_eol = buf->b_p_eol;
12388#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012389 buf->b_start_bomb = buf->b_p_bomb;
12390
Bram Moolenaar071d4272004-06-13 20:20:40 +000012391 /* Only use free/alloc when necessary, they take time. */
12392 if (buf->b_start_fenc == NULL
12393 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12394 {
12395 vim_free(buf->b_start_fenc);
12396 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12397 }
12398#endif
12399}
12400
12401/*
12402 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12403 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012404 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12405 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012406 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012407 * When "ignore_empty" is true don't consider a new, empty buffer to be
12408 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012409 */
12410 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012411file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012412{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012413 /* In a buffer that was never loaded the options are not valid. */
12414 if (buf->b_flags & BF_NEVERLOADED)
12415 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012416 if (ignore_empty
12417 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012418 && buf->b_ml.ml_line_count == 1
12419 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12420 return FALSE;
12421 if (buf->b_start_ffc != *buf->b_p_ff)
12422 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012423 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012424 return TRUE;
12425#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012426 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12427 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012428 if (buf->b_start_fenc == NULL)
12429 return (*buf->b_p_fenc != NUL);
12430 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12431#else
12432 return FALSE;
12433#endif
12434}
12435
12436/*
12437 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12438 */
12439 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012440check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012441{
12442 return check_opt_strings(p, p_ff_values, FALSE);
12443}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012444
12445/*
12446 * Return the effective shiftwidth value for current buffer, using the
12447 * 'tabstop' value when 'shiftwidth' is zero.
12448 */
12449 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012450get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012451{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012452 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012453}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012454
12455/*
12456 * Return the effective softtabstop value for the current buffer, using the
12457 * 'tabstop' value when 'softtabstop' is negative.
12458 */
12459 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012460get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012461{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012462 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012463}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012464
12465/*
12466 * Check matchpairs option for "*initc".
12467 * If there is a match set "*initc" to the matching character and "*findc" to
12468 * the opposite character. Set "*backwards" to the direction.
12469 * When "switchit" is TRUE swap the direction.
12470 */
12471 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012472find_mps_values(
12473 int *initc,
12474 int *findc,
12475 int *backwards,
12476 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012477{
12478 char_u *ptr;
12479
12480 ptr = curbuf->b_p_mps;
12481 while (*ptr != NUL)
12482 {
12483#ifdef FEAT_MBYTE
12484 if (has_mbyte)
12485 {
12486 char_u *prev;
12487
12488 if (mb_ptr2char(ptr) == *initc)
12489 {
12490 if (switchit)
12491 {
12492 *findc = *initc;
12493 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12494 *backwards = TRUE;
12495 }
12496 else
12497 {
12498 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12499 *backwards = FALSE;
12500 }
12501 return;
12502 }
12503 prev = ptr;
12504 ptr += mb_ptr2len(ptr) + 1;
12505 if (mb_ptr2char(ptr) == *initc)
12506 {
12507 if (switchit)
12508 {
12509 *findc = *initc;
12510 *initc = mb_ptr2char(prev);
12511 *backwards = FALSE;
12512 }
12513 else
12514 {
12515 *findc = mb_ptr2char(prev);
12516 *backwards = TRUE;
12517 }
12518 return;
12519 }
12520 ptr += mb_ptr2len(ptr);
12521 }
12522 else
12523#endif
12524 {
12525 if (*ptr == *initc)
12526 {
12527 if (switchit)
12528 {
12529 *backwards = TRUE;
12530 *findc = *initc;
12531 *initc = ptr[2];
12532 }
12533 else
12534 {
12535 *backwards = FALSE;
12536 *findc = ptr[2];
12537 }
12538 return;
12539 }
12540 ptr += 2;
12541 if (*ptr == *initc)
12542 {
12543 if (switchit)
12544 {
12545 *backwards = FALSE;
12546 *findc = *initc;
12547 *initc = ptr[-2];
12548 }
12549 else
12550 {
12551 *backwards = TRUE;
12552 *findc = ptr[-2];
12553 }
12554 return;
12555 }
12556 ++ptr;
12557 }
12558 if (*ptr == ',')
12559 ++ptr;
12560 }
12561}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012562
12563#if defined(FEAT_LINEBREAK) || defined(PROTO)
12564/*
12565 * This is called when 'breakindentopt' is changed and when a window is
12566 * initialized.
12567 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012568 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012569briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012570{
12571 char_u *p;
12572 int bri_shift = 0;
12573 long bri_min = 20;
12574 int bri_sbr = FALSE;
12575
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012576 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012577 while (*p != NUL)
12578 {
12579 if (STRNCMP(p, "shift:", 6) == 0
12580 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12581 {
12582 p += 6;
12583 bri_shift = getdigits(&p);
12584 }
12585 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12586 {
12587 p += 4;
12588 bri_min = getdigits(&p);
12589 }
12590 else if (STRNCMP(p, "sbr", 3) == 0)
12591 {
12592 p += 3;
12593 bri_sbr = TRUE;
12594 }
12595 if (*p != ',' && *p != NUL)
12596 return FAIL;
12597 if (*p == ',')
12598 ++p;
12599 }
12600
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012601 wp->w_p_brishift = bri_shift;
12602 wp->w_p_brimin = bri_min;
12603 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012604
12605 return OK;
12606}
12607#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012608
12609/*
12610 * Get the local or global value of 'backupcopy'.
12611 */
12612 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012613get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012614{
12615 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12616}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012617
12618#if defined(FEAT_SIGNS) || defined(PROTO)
12619/*
12620 * Return TRUE when window "wp" has a column to draw signs in.
12621 */
12622 int
12623signcolumn_on(win_T *wp)
12624{
12625 if (*wp->w_p_scl == 'n')
12626 return FALSE;
12627 if (*wp->w_p_scl == 'y')
12628 return TRUE;
12629 return (wp->w_buffer->b_signlist != NULL
12630# ifdef FEAT_NETBEANS_INTG
12631 || wp->w_buffer->b_has_sign_column
12632# endif
12633 );
12634}
12635#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012636
12637#if defined(FEAT_EVAL) || defined(PROTO)
12638/*
12639 * Get window or buffer local options.
12640 */
12641 dict_T *
12642get_winbuf_options(int bufopt)
12643{
12644 dict_T *d;
12645 int opt_idx;
12646
12647 d = dict_alloc();
12648 if (d == NULL)
12649 return NULL;
12650
12651 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12652 {
12653 struct vimoption *opt = &options[opt_idx];
12654
12655 if ((bufopt && (opt->indir & PV_BUF))
12656 || (!bufopt && (opt->indir & PV_WIN)))
12657 {
12658 char_u *varp = get_varp(opt);
12659
12660 if (varp != NULL)
12661 {
12662 if (opt->flags & P_STRING)
12663 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012664 else if (opt->flags & P_NUM)
12665 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012666 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012667 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012668 }
12669 }
12670 }
12671
12672 return d;
12673}
12674#endif