blob: d4e760b89330458618d46c1c9bcbf5ea6c0417f1 [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 Moolenaar48e330a2016-02-23 14:53:34 +01004132# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 /* Somehow Win32 requires the quotes around the redirection too */
4134 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004135 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 {
4137 p_sxq = (char_u *)"\"";
4138 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4139 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004140# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004142 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 {
4144 p_shq = (char_u *)"\"";
4145 options[idx3].def_val[VI_DEFAULT] = p_shq;
4146 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147# endif
4148 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004149 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4150 {
4151 int idx3;
4152
4153 /*
4154 * cmd.exe on Windows will strip the first and last double quote given
4155 * on the command line, e.g. most of the time things like:
4156 * cmd /c "my path/to/echo" "my args to echo"
4157 * become:
4158 * my path/to/echo" "my args to echo
4159 * when executed.
4160 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004161 * To avoid this, set shellxquote to surround the command in
4162 * parenthesis. This appears to make most commands work, without
4163 * breaking commands that worked previously, such as
4164 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004165 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004166 idx3 = findoption((char_u *)"sxq");
4167 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4168 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004169 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004170 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4171 }
4172
Bram Moolenaara64ba222012-02-12 23:23:31 +01004173 idx3 = findoption((char_u *)"shcf");
4174 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4175 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004176 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004177 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4178 }
4179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180#endif
4181
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004182 if (bufempty())
4183 {
4184 int idx_ffs = findoption((char_u *)"ffs");
4185
4186 /* Apply the first entry of 'fileformats' to the initial buffer. */
4187 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4188 set_fileformat(default_fileformat(), OPT_LOCAL);
4189 }
4190
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191#ifdef FEAT_TITLE
4192 set_title_defaults();
4193#endif
4194}
4195
4196#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4197/*
4198 * When 'helplang' is still at its default value, set it to "lang".
4199 * Only the first two characters of "lang" are used.
4200 */
4201 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004202set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203{
4204 int idx;
4205
4206 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4207 return;
4208 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004209 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 {
4211 if (options[idx].flags & P_ALLOCED)
4212 free_string_option(p_hlg);
4213 p_hlg = vim_strsave(lang);
4214 if (p_hlg == NULL)
4215 p_hlg = empty_option;
4216 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004217 {
4218 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4219 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4220 {
4221 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4222 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226 options[idx].flags |= P_ALLOCED;
4227 }
4228}
4229#endif
4230
4231#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004232static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233
4234 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004235gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236{
4237 if (gui_get_lightness(gui.back_pixel) < 127)
4238 return (char_u *)"dark";
4239 return (char_u *)"light";
4240}
4241
4242/*
4243 * Option initializations that can only be done after opening the GUI window.
4244 */
4245 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004246init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004247{
4248 /* Set the 'background' option according to the lightness of the
4249 * background color, unless the user has set it already. */
4250 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4251 {
4252 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4253 highlight_changed();
4254 }
4255}
4256#endif
4257
4258#ifdef FEAT_TITLE
4259/*
4260 * 'title' and 'icon' only default to true if they have not been set or reset
4261 * in .vimrc and we can read the old value.
4262 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4263 * they can be reset. This reduces startup time when using X on a remote
4264 * machine.
4265 */
4266 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004267set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268{
4269 int idx1;
4270 long val;
4271
4272 /*
4273 * If GUI is (going to be) used, we can always set the window title and
4274 * icon name. Saves a bit of time, because the X11 display server does
4275 * not need to be contacted.
4276 */
4277 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004278 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279 {
4280#ifdef FEAT_GUI
4281 if (gui.starting || gui.in_use)
4282 val = TRUE;
4283 else
4284#endif
4285 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004286 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004287 p_title = val;
4288 }
4289 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004290 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004291 {
4292#ifdef FEAT_GUI
4293 if (gui.starting || gui.in_use)
4294 val = TRUE;
4295 else
4296#endif
4297 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004298 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004299 p_icon = val;
4300 }
4301}
4302#endif
4303
4304/*
4305 * Parse 'arg' for option settings.
4306 *
4307 * 'arg' may be IObuff, but only when no errors can be present and option
4308 * does not need to be expanded with option_expand().
4309 * "opt_flags":
4310 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004311 * OPT_GLOBAL for ":setglobal"
4312 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004313 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004314 * OPT_WINONLY to only set window-local options
4315 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004316 *
4317 * returns FAIL if an error is detected, OK otherwise
4318 */
4319 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004320do_set(
4321 char_u *arg, /* option string (may be written to!) */
4322 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004323{
4324 int opt_idx;
4325 char_u *errmsg;
4326 char_u errbuf[80];
4327 char_u *startarg;
4328 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4329 int nextchar; /* next non-white char after option name */
4330 int afterchar; /* character just after option name */
4331 int len;
4332 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004333 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 int key;
4335 long_u flags; /* flags for current option */
4336 char_u *varp = NULL; /* pointer to variable for current option */
4337 int did_show = FALSE; /* already showed one value */
4338 int adding; /* "opt+=arg" */
4339 int prepending; /* "opt^=arg" */
4340 int removing; /* "opt-=arg" */
4341 int cp_val = 0;
4342 char_u key_name[2];
4343
4344 if (*arg == NUL)
4345 {
4346 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004347 did_show = TRUE;
4348 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 }
4350
4351 while (*arg != NUL) /* loop to process all options */
4352 {
4353 errmsg = NULL;
4354 startarg = arg; /* remember for error message */
4355
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004356 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4357 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358 {
4359 /*
4360 * ":set all" show all options.
4361 * ":set all&" set all options to their default value.
4362 */
4363 arg += 3;
4364 if (*arg == '&')
4365 {
4366 ++arg;
4367 /* Only for :set command set global value of local options. */
4368 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004369 didset_options();
4370 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004371 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004372 }
4373 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004374 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004376 did_show = TRUE;
4377 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004378 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004379 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004380 {
4381 showoptions(2, opt_flags);
4382 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004383 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 arg += 7;
4385 }
4386 else
4387 {
4388 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004389 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004390 {
4391 prefix = 0;
4392 arg += 2;
4393 }
4394 else if (STRNCMP(arg, "inv", 3) == 0)
4395 {
4396 prefix = 2;
4397 arg += 3;
4398 }
4399
4400 /* find end of name */
4401 key = 0;
4402 if (*arg == '<')
4403 {
4404 nextchar = 0;
4405 opt_idx = -1;
4406 /* look out for <t_>;> */
4407 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4408 len = 5;
4409 else
4410 {
4411 len = 1;
4412 while (arg[len] != NUL && arg[len] != '>')
4413 ++len;
4414 }
4415 if (arg[len] != '>')
4416 {
4417 errmsg = e_invarg;
4418 goto skip;
4419 }
4420 arg[len] = NUL; /* put NUL after name */
4421 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4422 opt_idx = findoption(arg + 1);
4423 arg[len++] = '>'; /* restore '>' */
4424 if (opt_idx == -1)
4425 key = find_key_option(arg + 1);
4426 }
4427 else
4428 {
4429 len = 0;
4430 /*
4431 * The two characters after "t_" may not be alphanumeric.
4432 */
4433 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4434 len = 4;
4435 else
4436 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4437 ++len;
4438 nextchar = arg[len];
4439 arg[len] = NUL; /* put NUL after name */
4440 opt_idx = findoption(arg);
4441 arg[len] = nextchar; /* restore nextchar */
4442 if (opt_idx == -1)
4443 key = find_key_option(arg);
4444 }
4445
4446 /* remember character after option name */
4447 afterchar = arg[len];
4448
4449 /* skip white space, allow ":set ai ?" */
4450 while (vim_iswhite(arg[len]))
4451 ++len;
4452
4453 adding = FALSE;
4454 prepending = FALSE;
4455 removing = FALSE;
4456 if (arg[len] != NUL && arg[len + 1] == '=')
4457 {
4458 if (arg[len] == '+')
4459 {
4460 adding = TRUE; /* "+=" */
4461 ++len;
4462 }
4463 else if (arg[len] == '^')
4464 {
4465 prepending = TRUE; /* "^=" */
4466 ++len;
4467 }
4468 else if (arg[len] == '-')
4469 {
4470 removing = TRUE; /* "-=" */
4471 ++len;
4472 }
4473 }
4474 nextchar = arg[len];
4475
4476 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4477 {
4478 errmsg = (char_u *)N_("E518: Unknown option");
4479 goto skip;
4480 }
4481
4482 if (opt_idx >= 0)
4483 {
4484 if (options[opt_idx].var == NULL) /* hidden option: skip */
4485 {
4486 /* Only give an error message when requesting the value of
4487 * a hidden option, ignore setting it. */
4488 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4489 && (!(options[opt_idx].flags & P_BOOL)
4490 || nextchar == '?'))
4491 errmsg = (char_u *)N_("E519: Option not supported");
4492 goto skip;
4493 }
4494
4495 flags = options[opt_idx].flags;
4496 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4497 }
4498 else
4499 {
4500 flags = P_STRING;
4501 if (key < 0)
4502 {
4503 key_name[0] = KEY2TERMCAP0(key);
4504 key_name[1] = KEY2TERMCAP1(key);
4505 }
4506 else
4507 {
4508 key_name[0] = KS_KEY;
4509 key_name[1] = (key & 0xff);
4510 }
4511 }
4512
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004513 /* Skip all options that are not window-local (used when showing
4514 * an already loaded buffer in a window). */
4515 if ((opt_flags & OPT_WINONLY)
4516 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4517 goto skip;
4518
Bram Moolenaara3227e22006-03-08 21:32:40 +00004519 /* Skip all options that are window-local (used for :vimgrep). */
4520 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4521 && options[opt_idx].var == VAR_WIN)
4522 goto skip;
4523
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004524 /* Disallow changing some options from modelines. */
4525 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004526 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004527 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004528 {
4529 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4530 goto skip;
4531 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004532#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004533 /* In diff mode some options are overruled. This avoids that
4534 * 'foldmethod' becomes "marker" instead of "diff" and that
4535 * "wrap" gets set. */
4536 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004537 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004538 && (options[opt_idx].indir == PV_FDM
4539 || options[opt_idx].indir == PV_WRAP))
4540 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004541#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004542 }
4543
4544#ifdef HAVE_SANDBOX
4545 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004546 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004547 {
4548 errmsg = (char_u *)_(e_sandbox);
4549 goto skip;
4550 }
4551#endif
4552
4553 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4554 {
4555 arg += len;
4556 cp_val = p_cp;
4557 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4558 {
4559 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4560 {
4561 cp_val = FALSE;
4562 arg += 3;
4563 }
4564 else /* "opt&vi": set to Vi default */
4565 {
4566 cp_val = TRUE;
4567 arg += 2;
4568 }
4569 }
4570 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4571 && arg[1] != NUL && !vim_iswhite(arg[1]))
4572 {
4573 errmsg = e_trailing;
4574 goto skip;
4575 }
4576 }
4577
4578 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004579 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4580 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 */
4582 if (nextchar == '?'
4583 || (prefix == 1
4584 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4585 && !(flags & P_BOOL)))
4586 {
4587 /*
4588 * print value
4589 */
4590 if (did_show)
4591 msg_putchar('\n'); /* cursor below last one */
4592 else
4593 {
4594 gotocmdline(TRUE); /* cursor at status line */
4595 did_show = TRUE; /* remember that we did a line */
4596 }
4597 if (opt_idx >= 0)
4598 {
4599 showoneopt(&options[opt_idx], opt_flags);
4600#ifdef FEAT_EVAL
4601 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004602 {
4603 /* Mention where the option was last set. */
4604 if (varp == options[opt_idx].var)
4605 last_set_msg(options[opt_idx].scriptID);
4606 else if ((int)options[opt_idx].indir & PV_WIN)
4607 last_set_msg(curwin->w_p_scriptID[
4608 (int)options[opt_idx].indir & PV_MASK]);
4609 else if ((int)options[opt_idx].indir & PV_BUF)
4610 last_set_msg(curbuf->b_p_scriptID[
4611 (int)options[opt_idx].indir & PV_MASK]);
4612 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613#endif
4614 }
4615 else
4616 {
4617 char_u *p;
4618
4619 p = find_termcode(key_name);
4620 if (p == NULL)
4621 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004622 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 goto skip;
4624 }
4625 else
4626 (void)show_one_termcode(key_name, p, TRUE);
4627 }
4628 if (nextchar != '?'
4629 && nextchar != NUL && !vim_iswhite(afterchar))
4630 errmsg = e_trailing;
4631 }
4632 else
4633 {
4634 if (flags & P_BOOL) /* boolean */
4635 {
4636 if (nextchar == '=' || nextchar == ':')
4637 {
4638 errmsg = e_invarg;
4639 goto skip;
4640 }
4641
4642 /*
4643 * ":set opt!": invert
4644 * ":set opt&": reset to default value
4645 * ":set opt<": reset to global value
4646 */
4647 if (nextchar == '!')
4648 value = *(int *)(varp) ^ 1;
4649 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004650 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 ((flags & P_VI_DEF) || cp_val)
4652 ? VI_DEFAULT : VIM_DEFAULT];
4653 else if (nextchar == '<')
4654 {
4655 /* For 'autoread' -1 means to use global value. */
4656 if ((int *)varp == &curbuf->b_p_ar
4657 && opt_flags == OPT_LOCAL)
4658 value = -1;
4659 else
4660 value = *(int *)get_varp_scope(&(options[opt_idx]),
4661 OPT_GLOBAL);
4662 }
4663 else
4664 {
4665 /*
4666 * ":set invopt": invert
4667 * ":set opt" or ":set noopt": set or reset
4668 */
4669 if (nextchar != NUL && !vim_iswhite(afterchar))
4670 {
4671 errmsg = e_trailing;
4672 goto skip;
4673 }
4674 if (prefix == 2) /* inv */
4675 value = *(int *)(varp) ^ 1;
4676 else
4677 value = prefix;
4678 }
4679
4680 errmsg = set_bool_option(opt_idx, varp, (int)value,
4681 opt_flags);
4682 }
4683 else /* numeric or string */
4684 {
4685 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4686 || prefix != 1)
4687 {
4688 errmsg = e_invarg;
4689 goto skip;
4690 }
4691
4692 if (flags & P_NUM) /* numeric */
4693 {
4694 /*
4695 * Different ways to set a number option:
4696 * & set to default value
4697 * < set to global value
4698 * <xx> accept special key codes for 'wildchar'
4699 * c accept any non-digit for 'wildchar'
4700 * [-]0-9 set number
4701 * other error
4702 */
4703 ++arg;
4704 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004705 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004706 ((flags & P_VI_DEF) || cp_val)
4707 ? VI_DEFAULT : VIM_DEFAULT];
4708 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004709 {
4710 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4711 * use the global value. */
4712 if ((long *)varp == &curbuf->b_p_ul
4713 && opt_flags == OPT_LOCAL)
4714 value = NO_LOCAL_UNDOLEVEL;
4715 else
4716 value = *(long *)get_varp_scope(
4717 &(options[opt_idx]), OPT_GLOBAL);
4718 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 else if (((long *)varp == &p_wc
4720 || (long *)varp == &p_wcm)
4721 && (*arg == '<'
4722 || *arg == '^'
Bram Moolenaara12e4032017-02-25 21:37:57 +01004723 || (*arg != NUL && (!arg[1] || vim_iswhite(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724 && !VIM_ISDIGIT(*arg))))
4725 {
4726 value = string_to_key(arg);
4727 if (value == 0 && (long *)varp != &p_wcm)
4728 {
4729 errmsg = e_invarg;
4730 goto skip;
4731 }
4732 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004733 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4734 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004735 /* Allow negative (for 'undolevels'), octal and
4736 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004737 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4738 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004739 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4740 {
4741 errmsg = e_invarg;
4742 goto skip;
4743 }
4744 }
4745 else
4746 {
4747 errmsg = (char_u *)N_("E521: Number required after =");
4748 goto skip;
4749 }
4750
4751 if (adding)
4752 value = *(long *)varp + value;
4753 if (prepending)
4754 value = *(long *)varp * value;
4755 if (removing)
4756 value = *(long *)varp - value;
4757 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004758 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 }
4760 else if (opt_idx >= 0) /* string */
4761 {
4762 char_u *save_arg = NULL;
4763 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004764 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004765 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004766 char_u *origval = NULL;
4767#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4768 char_u *saved_origval = NULL;
4769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770 unsigned newlen;
4771 int comma;
4772 int bs;
4773 int new_value_alloced; /* new string option
4774 was allocated */
4775
4776 /* When using ":set opt=val" for a global option
4777 * with a local value the local value will be
4778 * reset, use the global value here. */
4779 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004780 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004781 varp = options[opt_idx].var;
4782
4783 /* The old value is kept until we are sure that the
4784 * new value is valid. */
4785 oldval = *(char_u **)varp;
4786 if (nextchar == '&') /* set to default val */
4787 {
4788 newval = options[opt_idx].def_val[
4789 ((flags & P_VI_DEF) || cp_val)
4790 ? VI_DEFAULT : VIM_DEFAULT];
4791 if ((char_u **)varp == &p_bg)
4792 {
4793 /* guess the value of 'background' */
4794#ifdef FEAT_GUI
4795 if (gui.in_use)
4796 newval = gui_bg_default();
4797 else
4798#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004799 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004800 }
4801
4802 /* expand environment variables and ~ (since the
4803 * default value was already expanded, only
4804 * required when an environment variable was set
4805 * later */
4806 if (newval == NULL)
4807 newval = empty_option;
4808 else
4809 {
4810 s = option_expand(opt_idx, newval);
4811 if (s == NULL)
4812 s = newval;
4813 newval = vim_strsave(s);
4814 }
4815 new_value_alloced = TRUE;
4816 }
4817 else if (nextchar == '<') /* set to global val */
4818 {
4819 newval = vim_strsave(*(char_u **)get_varp_scope(
4820 &(options[opt_idx]), OPT_GLOBAL));
4821 new_value_alloced = TRUE;
4822 }
4823 else
4824 {
4825 ++arg; /* jump to after the '=' or ':' */
4826
4827 /*
4828 * Set 'keywordprg' to ":help" if an empty
4829 * value was passed to :set by the user.
4830 * Misuse errbuf[] for the resulting string.
4831 */
4832 if (varp == (char_u *)&p_kp
4833 && (*arg == NUL || *arg == ' '))
4834 {
4835 STRCPY(errbuf, ":help");
4836 save_arg = arg;
4837 arg = errbuf;
4838 }
4839 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004840 * Convert 'backspace' number to string, for
4841 * adding, prepending and removing string.
4842 */
4843 else if (varp == (char_u *)&p_bs
4844 && VIM_ISDIGIT(**(char_u **)varp))
4845 {
4846 i = getdigits((char_u **)varp);
4847 switch (i)
4848 {
4849 case 0:
4850 *(char_u **)varp = empty_option;
4851 break;
4852 case 1:
4853 *(char_u **)varp = vim_strsave(
4854 (char_u *)"indent,eol");
4855 break;
4856 case 2:
4857 *(char_u **)varp = vim_strsave(
4858 (char_u *)"indent,eol,start");
4859 break;
4860 }
4861 vim_free(oldval);
4862 oldval = *(char_u **)varp;
4863 }
4864 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004865 * Convert 'whichwrap' number to string, for
4866 * backwards compatibility with Vim 3.0.
4867 * Misuse errbuf[] for the resulting string.
4868 */
4869 else if (varp == (char_u *)&p_ww
4870 && VIM_ISDIGIT(*arg))
4871 {
4872 *errbuf = NUL;
4873 i = getdigits(&arg);
4874 if (i & 1)
4875 STRCAT(errbuf, "b,");
4876 if (i & 2)
4877 STRCAT(errbuf, "s,");
4878 if (i & 4)
4879 STRCAT(errbuf, "h,l,");
4880 if (i & 8)
4881 STRCAT(errbuf, "<,>,");
4882 if (i & 16)
4883 STRCAT(errbuf, "[,],");
4884 if (*errbuf != NUL) /* remove trailing , */
4885 errbuf[STRLEN(errbuf) - 1] = NUL;
4886 save_arg = arg;
4887 arg = errbuf;
4888 }
4889 /*
4890 * Remove '>' before 'dir' and 'bdir', for
4891 * backwards compatibility with version 3.0
4892 */
4893 else if ( *arg == '>'
4894 && (varp == (char_u *)&p_dir
4895 || varp == (char_u *)&p_bdir))
4896 {
4897 ++arg;
4898 }
4899
4900 /* When setting the local value of a global
4901 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004902 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004903 && (opt_flags & OPT_LOCAL))
4904 origval = *(char_u **)get_varp(
4905 &options[opt_idx]);
4906 else
4907 origval = oldval;
4908
4909 /*
4910 * Copy the new string into allocated memory.
4911 * Can't use set_string_option_direct(), because
4912 * we need to remove the backslashes.
4913 */
4914 /* get a bit too much */
4915 newlen = (unsigned)STRLEN(arg) + 1;
4916 if (adding || prepending || removing)
4917 newlen += (unsigned)STRLEN(origval) + 1;
4918 newval = alloc(newlen);
4919 if (newval == NULL) /* out of mem, don't change */
4920 break;
4921 s = newval;
4922
4923 /*
4924 * Copy the string, skip over escaped chars.
4925 * For MS-DOS and WIN32 backslashes before normal
4926 * file name characters are not removed, and keep
4927 * backslash at start, for "\\machine\path", but
4928 * do remove it for "\\\\machine\\path".
4929 * The reverse is found in ExpandOldSetting().
4930 */
4931 while (*arg && !vim_iswhite(*arg))
4932 {
4933 if (*arg == '\\' && arg[1] != NUL
4934#ifdef BACKSLASH_IN_FILENAME
4935 && !((flags & P_EXPAND)
4936 && vim_isfilec(arg[1])
4937 && (arg[1] != '\\'
4938 || (s == newval
4939 && arg[2] != '\\')))
4940#endif
4941 )
4942 ++arg; /* remove backslash */
4943#ifdef FEAT_MBYTE
4944 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004945 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004946 {
4947 /* copy multibyte char */
4948 mch_memmove(s, arg, (size_t)i);
4949 arg += i;
4950 s += i;
4951 }
4952 else
4953#endif
4954 *s++ = *arg++;
4955 }
4956 *s = NUL;
4957
4958 /*
4959 * Expand environment variables and ~.
4960 * Don't do it when adding without inserting a
4961 * comma.
4962 */
4963 if (!(adding || prepending || removing)
4964 || (flags & P_COMMA))
4965 {
4966 s = option_expand(opt_idx, newval);
4967 if (s != NULL)
4968 {
4969 vim_free(newval);
4970 newlen = (unsigned)STRLEN(s) + 1;
4971 if (adding || prepending || removing)
4972 newlen += (unsigned)STRLEN(origval) + 1;
4973 newval = alloc(newlen);
4974 if (newval == NULL)
4975 break;
4976 STRCPY(newval, s);
4977 }
4978 }
4979
4980 /* locate newval[] in origval[] when removing it
4981 * and when adding to avoid duplicates */
4982 i = 0; /* init for GCC */
4983 if (removing || (flags & P_NODUP))
4984 {
4985 i = (int)STRLEN(newval);
4986 bs = 0;
4987 for (s = origval; *s; ++s)
4988 {
4989 if ((!(flags & P_COMMA)
4990 || s == origval
4991 || (s[-1] == ',' && !(bs & 1)))
4992 && STRNCMP(s, newval, i) == 0
4993 && (!(flags & P_COMMA)
4994 || s[i] == ','
4995 || s[i] == NUL))
4996 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004997 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004998 * even number of backslashes or a single
4999 * backslash preceded by a comma before it
5000 * is recognized as a separator */
5001 if ((s > origval + 1
5002 && s[-1] == '\\'
5003 && s[-2] != ',')
5004 || (s == origval + 1
5005 && s[-1] == '\\'))
5006
Bram Moolenaar071d4272004-06-13 20:20:40 +00005007 ++bs;
5008 else
5009 bs = 0;
5010 }
5011
5012 /* do not add if already there */
5013 if ((adding || prepending) && *s)
5014 {
5015 prepending = FALSE;
5016 adding = FALSE;
5017 STRCPY(newval, origval);
5018 }
5019 }
5020
5021 /* concatenate the two strings; add a ',' if
5022 * needed */
5023 if (adding || prepending)
5024 {
5025 comma = ((flags & P_COMMA) && *origval != NUL
5026 && *newval != NUL);
5027 if (adding)
5028 {
5029 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005030 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005031 if (comma && i > 1
5032 && (flags & P_ONECOMMA) == P_ONECOMMA
5033 && origval[i - 1] == ','
5034 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005035 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005036 mch_memmove(newval + i + comma, newval,
5037 STRLEN(newval) + 1);
5038 mch_memmove(newval, origval, (size_t)i);
5039 }
5040 else
5041 {
5042 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005043 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005044 }
5045 if (comma)
5046 newval[i] = ',';
5047 }
5048
5049 /* Remove newval[] from origval[]. (Note: "i" has
5050 * been set above and is used here). */
5051 if (removing)
5052 {
5053 STRCPY(newval, origval);
5054 if (*s)
5055 {
5056 /* may need to remove a comma */
5057 if (flags & P_COMMA)
5058 {
5059 if (s == origval)
5060 {
5061 /* include comma after string */
5062 if (s[i] == ',')
5063 ++i;
5064 }
5065 else
5066 {
5067 /* include comma before string */
5068 --s;
5069 ++i;
5070 }
5071 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005072 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005073 }
5074 }
5075
5076 if (flags & P_FLAGLIST)
5077 {
5078 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005079 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005080 {
5081 /* if options have P_FLAGLIST and
5082 * P_ONECOMMA such as 'whichwrap' */
5083 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005084 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005085 if (*s != ',' && *(s + 1) == ','
5086 && vim_strchr(s + 2, *s) != NULL)
5087 {
5088 /* Remove the duplicated value and
5089 * the next comma. */
5090 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005091 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005093 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005094 else
5095 {
5096 if ((!(flags & P_COMMA) || *s != ',')
5097 && vim_strchr(s + 1, *s) != NULL)
5098 {
5099 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005100 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005101 }
5102 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005103 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005105 }
5106
5107 if (save_arg != NULL) /* number for 'whichwrap' */
5108 arg = save_arg;
5109 new_value_alloced = TRUE;
5110 }
5111
5112 /* Set the new value. */
5113 *(char_u **)(varp) = newval;
5114
Bram Moolenaar53744302015-07-17 17:38:22 +02005115#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005116 if (!starting
5117# ifdef FEAT_CRYPT
5118 && options[opt_idx].indir != PV_KEY
5119# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02005120 && origval != NULL)
5121 /* origval may be freed by
5122 * did_set_string_option(), make a copy. */
5123 saved_origval = vim_strsave(origval);
5124#endif
5125
Bram Moolenaar071d4272004-06-13 20:20:40 +00005126 /* Handle side effects, and set the global value for
5127 * ":set" on local options. */
5128 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5129 new_value_alloced, oldval, errbuf, opt_flags);
5130
5131 /* If error detected, print the error message. */
5132 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005133 {
5134#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5135 vim_free(saved_origval);
5136#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005138 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005139#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5140 if (saved_origval != NULL)
5141 {
5142 char_u buf_type[7];
5143
5144 sprintf((char *)buf_type, "%s",
5145 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005146 set_vim_var_string(VV_OPTION_NEW,
5147 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005148 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5149 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5150 apply_autocmds(EVENT_OPTIONSET,
5151 (char_u *)options[opt_idx].fullname,
5152 NULL, FALSE, NULL);
5153 reset_v_option_vars();
5154 vim_free(saved_origval);
5155 }
5156#endif
5157
Bram Moolenaar071d4272004-06-13 20:20:40 +00005158 }
5159 else /* key code option */
5160 {
5161 char_u *p;
5162
5163 if (nextchar == '&')
5164 {
5165 if (add_termcap_entry(key_name, TRUE) == FAIL)
5166 errmsg = (char_u *)N_("E522: Not found in termcap");
5167 }
5168 else
5169 {
5170 ++arg; /* jump to after the '=' or ':' */
5171 for (p = arg; *p && !vim_iswhite(*p); ++p)
5172 if (*p == '\\' && p[1] != NUL)
5173 ++p;
5174 nextchar = *p;
5175 *p = NUL;
5176 add_termcode(key_name, arg, FALSE);
5177 *p = nextchar;
5178 }
5179 if (full_screen)
5180 ttest(FALSE);
5181 redraw_all_later(CLEAR);
5182 }
5183 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005184
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005186 did_set_option(opt_idx, opt_flags,
5187 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005188 }
5189
5190skip:
5191 /*
5192 * Advance to next argument.
5193 * - skip until a blank found, taking care of backslashes
5194 * - skip blanks
5195 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5196 */
5197 for (i = 0; i < 2 ; ++i)
5198 {
5199 while (*arg != NUL && !vim_iswhite(*arg))
5200 if (*arg++ == '\\' && *arg != NUL)
5201 ++arg;
5202 arg = skipwhite(arg);
5203 if (*arg != '=')
5204 break;
5205 }
5206 }
5207
5208 if (errmsg != NULL)
5209 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005210 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005211 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005212 if (i + (arg - startarg) < IOSIZE)
5213 {
5214 /* append the argument with the error */
5215 STRCAT(IObuff, ": ");
5216 mch_memmove(IObuff + i, startarg, (arg - startarg));
5217 IObuff[i + (arg - startarg)] = NUL;
5218 }
5219 /* make sure all characters are printable */
5220 trans_characters(IObuff, IOSIZE);
5221
5222 ++no_wait_return; /* wait_return done later */
5223 emsg(IObuff); /* show error highlighted */
5224 --no_wait_return;
5225
5226 return FAIL;
5227 }
5228
5229 arg = skipwhite(arg);
5230 }
5231
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005232theend:
5233 if (silent_mode && did_show)
5234 {
5235 /* After displaying option values in silent mode. */
5236 silent_mode = FALSE;
5237 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5238 msg_putchar('\n');
5239 cursor_on(); /* msg_start() switches it off */
5240 out_flush();
5241 silent_mode = TRUE;
5242 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5243 }
5244
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245 return OK;
5246}
5247
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005248/*
5249 * Call this when an option has been given a new value through a user command.
5250 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5251 */
5252 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005253did_set_option(
5254 int opt_idx,
5255 int opt_flags, /* possibly with OPT_MODELINE */
5256 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005257{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005258 long_u *p;
5259
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005260 options[opt_idx].flags |= P_WAS_SET;
5261
5262 /* When an option is set in the sandbox, from a modeline or in secure mode
5263 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005264 * flag. */
5265 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005266 if (secure
5267#ifdef HAVE_SANDBOX
5268 || sandbox != 0
5269#endif
5270 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005271 *p = *p | P_INSECURE;
5272 else if (new_value)
5273 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005274}
5275
Bram Moolenaar071d4272004-06-13 20:20:40 +00005276 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005277illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005278{
5279 if (errbuf == NULL)
5280 return (char_u *)"";
5281 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005282 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005283 return errbuf;
5284}
5285
5286/*
5287 * Convert a key name or string into a key value.
5288 * Used for 'wildchar' and 'cedit' options.
5289 */
5290 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005291string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005292{
5293 if (*arg == '<')
5294 return find_key_option(arg + 1);
5295 if (*arg == '^')
5296 return Ctrl_chr(arg[1]);
5297 return *arg;
5298}
5299
5300#ifdef FEAT_CMDWIN
5301/*
5302 * Check value of 'cedit' and set cedit_key.
5303 * Returns NULL if value is OK, error message otherwise.
5304 */
5305 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005306check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307{
5308 int n;
5309
5310 if (*p_cedit == NUL)
5311 cedit_key = -1;
5312 else
5313 {
5314 n = string_to_key(p_cedit);
5315 if (vim_isprintc(n))
5316 return e_invarg;
5317 cedit_key = n;
5318 }
5319 return NULL;
5320}
5321#endif
5322
5323#ifdef FEAT_TITLE
5324/*
5325 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5326 * maketitle() to create and display it.
5327 * When switching the title or icon off, call mch_restore_title() to get
5328 * the old value back.
5329 */
5330 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005331did_set_title(
5332 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333{
5334 if (starting != NO_SCREEN
5335#ifdef FEAT_GUI
5336 && !gui.starting
5337#endif
5338 )
5339 {
5340 maketitle();
5341 if (icon)
5342 {
5343 if (!p_icon)
5344 mch_restore_title(2);
5345 }
5346 else
5347 {
5348 if (!p_title)
5349 mch_restore_title(1);
5350 }
5351 }
5352}
5353#endif
5354
5355/*
5356 * set_options_bin - called when 'bin' changes value.
5357 */
5358 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005359set_options_bin(
5360 int oldval,
5361 int newval,
5362 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363{
5364 /*
5365 * The option values that are changed when 'bin' changes are
5366 * copied when 'bin is set and restored when 'bin' is reset.
5367 */
5368 if (newval)
5369 {
5370 if (!oldval) /* switched on */
5371 {
5372 if (!(opt_flags & OPT_GLOBAL))
5373 {
5374 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5375 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5376 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5377 curbuf->b_p_et_nobin = curbuf->b_p_et;
5378 }
5379 if (!(opt_flags & OPT_LOCAL))
5380 {
5381 p_tw_nobin = p_tw;
5382 p_wm_nobin = p_wm;
5383 p_ml_nobin = p_ml;
5384 p_et_nobin = p_et;
5385 }
5386 }
5387
5388 if (!(opt_flags & OPT_GLOBAL))
5389 {
5390 curbuf->b_p_tw = 0; /* no automatic line wrap */
5391 curbuf->b_p_wm = 0; /* no automatic line wrap */
5392 curbuf->b_p_ml = 0; /* no modelines */
5393 curbuf->b_p_et = 0; /* no expandtab */
5394 }
5395 if (!(opt_flags & OPT_LOCAL))
5396 {
5397 p_tw = 0;
5398 p_wm = 0;
5399 p_ml = FALSE;
5400 p_et = FALSE;
5401 p_bin = TRUE; /* needed when called for the "-b" argument */
5402 }
5403 }
5404 else if (oldval) /* switched off */
5405 {
5406 if (!(opt_flags & OPT_GLOBAL))
5407 {
5408 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5409 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5410 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5411 curbuf->b_p_et = curbuf->b_p_et_nobin;
5412 }
5413 if (!(opt_flags & OPT_LOCAL))
5414 {
5415 p_tw = p_tw_nobin;
5416 p_wm = p_wm_nobin;
5417 p_ml = p_ml_nobin;
5418 p_et = p_et_nobin;
5419 }
5420 }
5421}
5422
5423#ifdef FEAT_VIMINFO
5424/*
5425 * Find the parameter represented by the given character (eg ', :, ", or /),
5426 * and return its associated value in the 'viminfo' string.
5427 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005428 * If the parameter is not specified in the string or there is no following
5429 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005430 */
5431 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005432get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433{
5434 char_u *p;
5435
5436 p = find_viminfo_parameter(type);
5437 if (p != NULL && VIM_ISDIGIT(*p))
5438 return atoi((char *)p);
5439 return -1;
5440}
5441
5442/*
5443 * Find the parameter represented by the given character (eg ''', ':', '"', or
5444 * '/') in the 'viminfo' option and return a pointer to the string after it.
5445 * Return NULL if the parameter is not specified in the string.
5446 */
5447 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005448find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005449{
5450 char_u *p;
5451
5452 for (p = p_viminfo; *p; ++p)
5453 {
5454 if (*p == type)
5455 return p + 1;
5456 if (*p == 'n') /* 'n' is always the last one */
5457 break;
5458 p = vim_strchr(p, ','); /* skip until next ',' */
5459 if (p == NULL) /* hit the end without finding parameter */
5460 break;
5461 }
5462 return NULL;
5463}
5464#endif
5465
5466/*
5467 * Expand environment variables for some string options.
5468 * These string options cannot be indirect!
5469 * If "val" is NULL expand the current value of the option.
5470 * Return pointer to NameBuff, or NULL when not expanded.
5471 */
5472 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005473option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474{
5475 /* if option doesn't need expansion nothing to do */
5476 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5477 return NULL;
5478
5479 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5480 * expand_env() would truncate the string. */
5481 if (val != NULL && STRLEN(val) > MAXPATHL)
5482 return NULL;
5483
5484 if (val == NULL)
5485 val = *(char_u **)options[opt_idx].var;
5486
5487 /*
5488 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5489 * Escape spaces when expanding 'tags', they are used to separate file
5490 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005491 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492 */
5493 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005494 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005495#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005496 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5497#endif
5498 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5500 return NULL;
5501
5502 return NameBuff;
5503}
5504
5505/*
5506 * After setting various option values: recompute variables that depend on
5507 * option values.
5508 */
5509 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005510didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511{
5512 /* initialize the table for 'iskeyword' et.al. */
5513 (void)init_chartab();
5514
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005515#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005517#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005519 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520#ifdef FEAT_SESSION
5521 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5522 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5523#endif
5524#ifdef FEAT_FOLDING
5525 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5526#endif
5527 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005528 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529#ifdef FEAT_VIRTUALEDIT
5530 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5531#endif
5532#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5533 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5534#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005535#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005536 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005537 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005538 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005539 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5542 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5543#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005544#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5546#endif
5547#ifdef FEAT_CMDWIN
5548 /* set cedit_key */
5549 (void)check_cedit();
5550#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005551#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005552 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005553#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005554#ifdef FEAT_LINEBREAK
5555 /* initialize the table for 'breakat'. */
5556 fill_breakat_flags();
5557#endif
5558
5559}
5560
5561/*
5562 * More side effects of setting options.
5563 */
5564 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005565didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005566{
5567 /* Initialize the highlight_attr[] table. */
5568 (void)highlight_changed();
5569
5570 /* Parse default for 'wildmode' */
5571 check_opt_wim();
5572
5573 (void)set_chars_option(&p_lcs);
5574#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5575 /* Parse default for 'fillchars'. */
5576 (void)set_chars_option(&p_fcs);
5577#endif
5578
5579#ifdef FEAT_CLIPBOARD
5580 /* Parse default for 'clipboard' */
5581 (void)check_clipboard_option();
5582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583}
5584
5585/*
5586 * Check for string options that are NULL (normally only termcap options).
5587 */
5588 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005589check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590{
5591 int opt_idx;
5592
5593 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5594 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5595 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5596}
5597
5598/*
5599 * Check string options in a buffer for NULL value.
5600 */
5601 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005602check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005603{
5604#if defined(FEAT_QUICKFIX)
5605 check_string_option(&buf->b_p_bh);
5606 check_string_option(&buf->b_p_bt);
5607#endif
5608#ifdef FEAT_MBYTE
5609 check_string_option(&buf->b_p_fenc);
5610#endif
5611 check_string_option(&buf->b_p_ff);
5612#ifdef FEAT_FIND_ID
5613 check_string_option(&buf->b_p_def);
5614 check_string_option(&buf->b_p_inc);
5615# ifdef FEAT_EVAL
5616 check_string_option(&buf->b_p_inex);
5617# endif
5618#endif
5619#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5620 check_string_option(&buf->b_p_inde);
5621 check_string_option(&buf->b_p_indk);
5622#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005623#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5624 check_string_option(&buf->b_p_bexpr);
5625#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005626#if defined(FEAT_CRYPT)
5627 check_string_option(&buf->b_p_cm);
5628#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005629 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005630#if defined(FEAT_EVAL)
5631 check_string_option(&buf->b_p_fex);
5632#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633#ifdef FEAT_CRYPT
5634 check_string_option(&buf->b_p_key);
5635#endif
5636 check_string_option(&buf->b_p_kp);
5637 check_string_option(&buf->b_p_mps);
5638 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005639 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640 check_string_option(&buf->b_p_isk);
5641#ifdef FEAT_COMMENTS
5642 check_string_option(&buf->b_p_com);
5643#endif
5644#ifdef FEAT_FOLDING
5645 check_string_option(&buf->b_p_cms);
5646#endif
5647 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005648#ifdef FEAT_TEXTOBJ
5649 check_string_option(&buf->b_p_qe);
5650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651#ifdef FEAT_SYN_HL
5652 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005653 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005654#endif
5655#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005656 check_string_option(&buf->b_s.b_p_spc);
5657 check_string_option(&buf->b_s.b_p_spf);
5658 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005659#endif
5660#ifdef FEAT_SEARCHPATH
5661 check_string_option(&buf->b_p_sua);
5662#endif
5663#ifdef FEAT_CINDENT
5664 check_string_option(&buf->b_p_cink);
5665 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005666 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667#endif
5668#ifdef FEAT_AUTOCMD
5669 check_string_option(&buf->b_p_ft);
5670#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5672 check_string_option(&buf->b_p_cinw);
5673#endif
5674#ifdef FEAT_INS_EXPAND
5675 check_string_option(&buf->b_p_cpt);
5676#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005677#ifdef FEAT_COMPL_FUNC
5678 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005679 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681#ifdef FEAT_KEYMAP
5682 check_string_option(&buf->b_p_keymap);
5683#endif
5684#ifdef FEAT_QUICKFIX
5685 check_string_option(&buf->b_p_gp);
5686 check_string_option(&buf->b_p_mp);
5687 check_string_option(&buf->b_p_efm);
5688#endif
5689 check_string_option(&buf->b_p_ep);
5690 check_string_option(&buf->b_p_path);
5691 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005692 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693#ifdef FEAT_INS_EXPAND
5694 check_string_option(&buf->b_p_dict);
5695 check_string_option(&buf->b_p_tsr);
5696#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005697#ifdef FEAT_LISP
5698 check_string_option(&buf->b_p_lw);
5699#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005700 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005701#ifdef FEAT_MBYTE
5702 check_string_option(&buf->b_p_menc);
5703#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704}
5705
5706/*
5707 * Free the string allocated for an option.
5708 * Checks for the string being empty_option. This may happen if we're out of
5709 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5710 * check_options().
5711 * Does NOT check for P_ALLOCED flag!
5712 */
5713 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005714free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715{
5716 if (p != empty_option)
5717 vim_free(p);
5718}
5719
5720 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005721clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722{
5723 if (*pp != empty_option)
5724 vim_free(*pp);
5725 *pp = empty_option;
5726}
5727
5728 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005729check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005730{
5731 if (*pp == NULL)
5732 *pp = empty_option;
5733}
5734
5735/*
5736 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5737 */
5738 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005739set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740{
5741 int opt_idx;
5742
5743 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5744 if (options[opt_idx].var == (char_u *)p)
5745 {
5746 options[opt_idx].flags |= P_ALLOCED;
5747 return;
5748 }
5749 return; /* cannot happen: didn't find it! */
5750}
5751
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005752#if defined(FEAT_EVAL) || defined(PROTO)
5753/*
5754 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5755 * Return FALSE when it wasn't.
5756 * Return -1 for an unknown option.
5757 */
5758 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005759was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005760{
5761 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005762 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005763
5764 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005765 {
5766 flagp = insecure_flag(idx, opt_flags);
5767 return (*flagp & P_INSECURE) != 0;
5768 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005769 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005770 return -1;
5771}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005772
5773/*
5774 * Get a pointer to the flags used for the P_INSECURE flag of option
5775 * "opt_idx". For some local options a local flags field is used.
5776 */
5777 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005778insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005779{
5780 if (opt_flags & OPT_LOCAL)
5781 switch ((int)options[opt_idx].indir)
5782 {
5783#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005784 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005785#endif
5786#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005787# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005788 case PV_FDE: return &curwin->w_p_fde_flags;
5789 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005790# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005791# ifdef FEAT_BEVAL
5792 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5793# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005794# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005795 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005796# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005797 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005798# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005799 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005800# endif
5801#endif
5802 }
5803
5804 /* Nothing special, return global flags field. */
5805 return &options[opt_idx].flags;
5806}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005807#endif
5808
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005809#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005810static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005811
5812/*
5813 * Redraw the window title and/or tab page text later.
5814 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005815static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005816{
5817 need_maketitle = TRUE;
5818# ifdef FEAT_WINDOWS
5819 redraw_tabline = TRUE;
5820# endif
5821}
5822#endif
5823
Bram Moolenaar071d4272004-06-13 20:20:40 +00005824/*
5825 * Set a string option to a new value (without checking the effect).
5826 * The string is copied into allocated memory.
5827 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005828 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005829 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005830 */
5831 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005832set_string_option_direct(
5833 char_u *name,
5834 int opt_idx,
5835 char_u *val,
5836 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5837 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838{
5839 char_u *s;
5840 char_u **varp;
5841 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005842 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005843
Bram Moolenaar89d40322006-08-29 15:30:07 +00005844 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005846 idx = findoption(name);
5847 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005848 {
5849 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005850 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005851 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005852 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005853 }
5854
Bram Moolenaar89d40322006-08-29 15:30:07 +00005855 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856 return;
5857
5858 s = vim_strsave(val);
5859 if (s != NULL)
5860 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005861 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005863 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864 free_string_option(*varp);
5865 *varp = s;
5866
5867 /* For buffer/window local option may also set the global value. */
5868 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005869 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870
Bram Moolenaar89d40322006-08-29 15:30:07 +00005871 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872
5873 /* When setting both values of a global option with a local value,
5874 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005875 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876 {
5877 free_string_option(*varp);
5878 *varp = empty_option;
5879 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005880# ifdef FEAT_EVAL
5881 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005882 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005883 set_sid == 0 ? current_SID : set_sid);
5884# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885 }
5886}
5887
5888/*
5889 * Set global value for string option when it's a local option.
5890 */
5891 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005892set_string_option_global(
5893 int opt_idx, /* option index */
5894 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005895{
5896 char_u **p, *s;
5897
5898 /* the global value is always allocated */
5899 if (options[opt_idx].var == VAR_WIN)
5900 p = (char_u **)GLOBAL_WO(varp);
5901 else
5902 p = (char_u **)options[opt_idx].var;
5903 if (options[opt_idx].indir != PV_NONE
5904 && p != varp
5905 && (s = vim_strsave(*varp)) != NULL)
5906 {
5907 free_string_option(*p);
5908 *p = s;
5909 }
5910}
5911
5912/*
5913 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005914 *
5915 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005917 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005918set_string_option(
5919 int opt_idx,
5920 char_u *value,
5921 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005922{
5923 char_u *s;
5924 char_u **varp;
5925 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005926#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5927 char_u *saved_oldval = NULL;
5928#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005929 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930
5931 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005932 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005933
5934 s = vim_strsave(value);
5935 if (s != NULL)
5936 {
5937 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5938 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005939 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940 ? OPT_GLOBAL : OPT_LOCAL)
5941 : opt_flags);
5942 oldval = *varp;
5943 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005944
5945#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005946 if (!starting
5947# ifdef FEAT_CRYPT
5948 && options[opt_idx].indir != PV_KEY
5949# endif
5950 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005951 saved_oldval = vim_strsave(oldval);
5952#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005953 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5954 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005955 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005956
Bram Moolenaara12e4032017-02-25 21:37:57 +01005957 /* call autocommand after handling side effects */
Bram Moolenaar53744302015-07-17 17:38:22 +02005958#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5959 if (saved_oldval != NULL)
5960 {
5961 char_u buf_type[7];
5962 sprintf((char *)buf_type, "%s",
5963 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005964 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5965 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005966 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5967 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5968 reset_v_option_vars();
5969 vim_free(saved_oldval);
5970 }
5971#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005972 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005973 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974}
5975
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005976#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005978 * Return TRUE if "val" is a valid 'filetype' name.
5979 * Also used for 'syntax' and 'keymap'.
5980 */
5981 static int
5982valid_filetype(char_u *val)
5983{
5984 char_u *s;
5985
5986 for (s = val; *s != NUL; ++s)
5987 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5988 return FALSE;
5989 return TRUE;
5990}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005991#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005992
5993/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005994 * Handle string options that need some action to perform when changed.
5995 * Returns NULL for success, or an error message for an error.
5996 */
5997 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005998did_set_string_option(
5999 int opt_idx, /* index in options[] table */
6000 char_u **varp, /* pointer to the option variable */
6001 int new_value_alloced, /* new value was allocated */
6002 char_u *oldval, /* previous value of the option */
6003 char_u *errbuf, /* buffer for errors, or NULL */
6004 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005{
6006 char_u *errmsg = NULL;
6007 char_u *s, *p;
6008 int did_chartab = FALSE;
6009 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006010 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006011#ifdef FEAT_GUI
6012 /* set when changing an option that only requires a redraw in the GUI */
6013 int redraw_gui_only = FALSE;
6014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006015
6016 /* Get the global option to compare with, otherwise we would have to check
6017 * two values for all local options. */
6018 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6019
6020 /* Disallow changing some options from secure mode */
6021 if ((secure
6022#ifdef HAVE_SANDBOX
6023 || sandbox != 0
6024#endif
6025 ) && (options[opt_idx].flags & P_SECURE))
6026 {
6027 errmsg = e_secure;
6028 }
6029
Bram Moolenaar7554da42016-11-25 22:04:13 +01006030 /* Check for a "normal" directory or file name in some options. Disallow a
6031 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006032 * are often illegal in a file name. Be more permissive if "secure" is off.
6033 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006034 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006035 && vim_strpbrk(*varp, (char_u *)(secure
6036 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006037 || ((options[opt_idx].flags & P_NDNAME)
6038 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006039 {
6040 errmsg = e_invarg;
6041 }
6042
Bram Moolenaar071d4272004-06-13 20:20:40 +00006043 /* 'term' */
6044 else if (varp == &T_NAME)
6045 {
6046 if (T_NAME[0] == NUL)
6047 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6048#ifdef FEAT_GUI
6049 if (gui.in_use)
6050 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6051 else if (term_is_gui(T_NAME))
6052 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6053#endif
6054 else if (set_termname(T_NAME) == FAIL)
6055 errmsg = (char_u *)N_("E522: Not found in termcap");
6056 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006057 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058 /* Screen colors may have changed. */
6059 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006060
6061 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6062 * P_ALLOCED flag on 'term'. */
6063 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006064 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006065 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066 }
6067
6068 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006069 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006071 char_u *bkc = p_bkc;
6072 unsigned int *flags = &bkc_flags;
6073
6074 if (opt_flags & OPT_LOCAL)
6075 {
6076 bkc = curbuf->b_p_bkc;
6077 flags = &curbuf->b_bkc_flags;
6078 }
6079
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006080 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6081 /* make the local value empty: use the global value */
6082 *flags = 0;
6083 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006084 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006085 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6086 errmsg = e_invarg;
6087 if ((((int)*flags & BKC_AUTO) != 0)
6088 + (((int)*flags & BKC_YES) != 0)
6089 + (((int)*flags & BKC_NO) != 0) != 1)
6090 {
6091 /* Must have exactly one of "auto", "yes" and "no". */
6092 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6093 errmsg = e_invarg;
6094 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095 }
6096 }
6097
6098 /* 'backupext' and 'patchmode' */
6099 else if (varp == &p_bex || varp == &p_pm)
6100 {
6101 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6102 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6103 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6104 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006105#ifdef FEAT_LINEBREAK
6106 /* 'breakindentopt' */
6107 else if (varp == &curwin->w_p_briopt)
6108 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006109 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006110 errmsg = e_invarg;
6111 }
6112#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113
6114 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006115 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006117 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006118 */
6119 else if ( varp == &p_isi
6120 || varp == &(curbuf->b_p_isk)
6121 || varp == &p_isp
6122 || varp == &p_isf)
6123 {
6124 if (init_chartab() == FAIL)
6125 {
6126 did_chartab = TRUE; /* need to restore it below */
6127 errmsg = e_invarg; /* error in value */
6128 }
6129 }
6130
6131 /* 'helpfile' */
6132 else if (varp == &p_hf)
6133 {
6134 /* May compute new values for $VIM and $VIMRUNTIME */
6135 if (didset_vim)
6136 {
6137 vim_setenv((char_u *)"VIM", (char_u *)"");
6138 didset_vim = FALSE;
6139 }
6140 if (didset_vimruntime)
6141 {
6142 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6143 didset_vimruntime = FALSE;
6144 }
6145 }
6146
Bram Moolenaar1a384422010-07-14 19:53:30 +02006147#ifdef FEAT_SYN_HL
6148 /* 'colorcolumn' */
6149 else if (varp == &curwin->w_p_cc)
6150 errmsg = check_colorcolumn(curwin);
6151#endif
6152
Bram Moolenaar071d4272004-06-13 20:20:40 +00006153#ifdef FEAT_MULTI_LANG
6154 /* 'helplang' */
6155 else if (varp == &p_hlg)
6156 {
6157 /* Check for "", "ab", "ab,cd", etc. */
6158 for (s = p_hlg; *s != NUL; s += 3)
6159 {
6160 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6161 {
6162 errmsg = e_invarg;
6163 break;
6164 }
6165 if (s[2] == NUL)
6166 break;
6167 }
6168 }
6169#endif
6170
6171 /* 'highlight' */
6172 else if (varp == &p_hl)
6173 {
6174 if (highlight_changed() == FAIL)
6175 errmsg = e_invarg; /* invalid flags */
6176 }
6177
6178 /* 'nrformats' */
6179 else if (gvarp == &p_nf)
6180 {
6181 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6182 errmsg = e_invarg;
6183 }
6184
6185#ifdef FEAT_SESSION
6186 /* 'sessionoptions' */
6187 else if (varp == &p_ssop)
6188 {
6189 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6190 errmsg = e_invarg;
6191 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6192 {
6193 /* Don't allow both "sesdir" and "curdir". */
6194 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6195 errmsg = e_invarg;
6196 }
6197 }
6198 /* 'viewoptions' */
6199 else if (varp == &p_vop)
6200 {
6201 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6202 errmsg = e_invarg;
6203 }
6204#endif
6205
6206 /* 'scrollopt' */
6207#ifdef FEAT_SCROLLBIND
6208 else if (varp == &p_sbo)
6209 {
6210 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6211 errmsg = e_invarg;
6212 }
6213#endif
6214
6215 /* 'ambiwidth' */
6216#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006217 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006218 {
6219 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6220 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006221 else if (set_chars_option(&p_lcs) != NULL)
6222 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6223# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6224 else if (set_chars_option(&p_fcs) != NULL)
6225 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6226# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006227 }
6228#endif
6229
6230 /* 'background' */
6231 else if (varp == &p_bg)
6232 {
6233 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6234 {
6235#ifdef FEAT_EVAL
6236 int dark = (*p_bg == 'd');
6237#endif
6238
6239 init_highlight(FALSE, FALSE);
6240
6241#ifdef FEAT_EVAL
6242 if (dark != (*p_bg == 'd')
6243 && get_var_value((char_u *)"g:colors_name") != NULL)
6244 {
6245 /* The color scheme must have set 'background' back to another
6246 * value, that's not what we want here. Disable the color
6247 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006248 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249 free_string_option(p_bg);
6250 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6251 check_string_option(&p_bg);
6252 init_highlight(FALSE, FALSE);
6253 }
6254#endif
6255 }
6256 else
6257 errmsg = e_invarg;
6258 }
6259
6260 /* 'wildmode' */
6261 else if (varp == &p_wim)
6262 {
6263 if (check_opt_wim() == FAIL)
6264 errmsg = e_invarg;
6265 }
6266
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006267#ifdef FEAT_CMDL_COMPL
6268 /* 'wildoptions' */
6269 else if (varp == &p_wop)
6270 {
6271 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6272 errmsg = e_invarg;
6273 }
6274#endif
6275
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276#ifdef FEAT_WAK
6277 /* 'winaltkeys' */
6278 else if (varp == &p_wak)
6279 {
6280 if (*p_wak == NUL
6281 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6282 errmsg = e_invarg;
6283# ifdef FEAT_MENU
6284# ifdef FEAT_GUI_MOTIF
6285 else if (gui.in_use)
6286 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6287# else
6288# ifdef FEAT_GUI_GTK
6289 else if (gui.in_use)
6290 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6291# endif
6292# endif
6293# endif
6294 }
6295#endif
6296
6297#ifdef FEAT_AUTOCMD
6298 /* 'eventignore' */
6299 else if (varp == &p_ei)
6300 {
6301 if (check_ei() == FAIL)
6302 errmsg = e_invarg;
6303 }
6304#endif
6305
6306#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006307 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6308 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6309 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310 {
6311 if (gvarp == &p_fenc)
6312 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006313 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314 errmsg = e_modifiable;
6315 else if (vim_strchr(*varp, ',') != NULL)
6316 /* No comma allowed in 'fileencoding'; catches confusing it
6317 * with 'fileencodings'. */
6318 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006320 {
6321# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006322 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006323 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006324# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006325 /* Add 'fileencoding' to the swap file. */
6326 ml_setflags(curbuf);
6327 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006328 }
6329 if (errmsg == NULL)
6330 {
6331 /* canonize the value, so that STRCMP() can be used on it */
6332 p = enc_canonize(*varp);
6333 if (p != NULL)
6334 {
6335 vim_free(*varp);
6336 *varp = p;
6337 }
6338 if (varp == &p_enc)
6339 {
6340 errmsg = mb_init();
6341# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006342 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343# endif
6344 }
6345 }
6346
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006347# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6349 {
6350 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6351 if (STRCMP(p_tenc, "utf-8") != 0)
6352 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6353 }
6354# endif
6355
6356 if (errmsg == NULL)
6357 {
6358# ifdef FEAT_KEYMAP
6359 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6360 * (with another encoding). */
6361 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6362 (void)keymap_init();
6363# endif
6364
6365 /* When 'termencoding' is not empty and 'encoding' changes or when
6366 * 'termencoding' changes, need to setup for keyboard input and
6367 * display output conversion. */
6368 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6369 {
6370 convert_setup(&input_conv, p_tenc, p_enc);
6371 convert_setup(&output_conv, p_enc, p_tenc);
6372 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006373
6374# if defined(WIN3264) && defined(FEAT_MBYTE)
6375 /* $HOME may have characters in active code page. */
6376 if (varp == &p_enc)
6377 init_homedir();
6378# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 }
6380 }
6381#endif
6382
6383#if defined(FEAT_POSTSCRIPT)
6384 else if (varp == &p_penc)
6385 {
6386 /* Canonize printencoding if VIM standard one */
6387 p = enc_canonize(p_penc);
6388 if (p != NULL)
6389 {
6390 vim_free(p_penc);
6391 p_penc = p;
6392 }
6393 else
6394 {
6395 /* Ensure lower case and '-' for '_' */
6396 for (s = p_penc; *s != NUL; s++)
6397 {
6398 if (*s == '_')
6399 *s = '-';
6400 else
6401 *s = TOLOWER_ASC(*s);
6402 }
6403 }
6404 }
6405#endif
6406
Bram Moolenaar9372a112005-12-06 19:59:18 +00006407#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 else if (varp == &p_imak)
6409 {
6410 if (gui.in_use && !im_xim_isvalid_imactivate())
6411 errmsg = e_invarg;
6412 }
6413#endif
6414
6415#ifdef FEAT_KEYMAP
6416 else if (varp == &curbuf->b_p_keymap)
6417 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006418 if (!valid_filetype(*varp))
6419 errmsg = e_invarg;
6420 else
6421 /* load or unload key mapping tables */
6422 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006423
Bram Moolenaarfab06232009-03-04 03:13:35 +00006424 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006425 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006426 if (*curbuf->b_p_keymap != NUL)
6427 {
6428 /* Installed a new keymap, switch on using it. */
6429 curbuf->b_p_iminsert = B_IMODE_LMAP;
6430 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6431 curbuf->b_p_imsearch = B_IMODE_LMAP;
6432 }
6433 else
6434 {
6435 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6436 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6437 curbuf->b_p_iminsert = B_IMODE_NONE;
6438 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6439 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6440 }
6441 if ((opt_flags & OPT_LOCAL) == 0)
6442 {
6443 set_iminsert_global();
6444 set_imsearch_global();
6445 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006446# ifdef FEAT_WINDOWS
6447 status_redraw_curbuf();
6448# endif
6449 }
6450 }
6451#endif
6452
6453 /* 'fileformat' */
6454 else if (gvarp == &p_ff)
6455 {
6456 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6457 errmsg = e_modifiable;
6458 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6459 errmsg = e_invarg;
6460 else
6461 {
6462 /* may also change 'textmode' */
6463 if (get_fileformat(curbuf) == EOL_DOS)
6464 curbuf->b_p_tx = TRUE;
6465 else
6466 curbuf->b_p_tx = FALSE;
6467#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006468 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006469#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006470 /* update flag in swap file */
6471 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006472 /* Redraw needed when switching to/from "mac": a CR in the text
6473 * will be displayed differently. */
6474 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6475 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006476 }
6477 }
6478
6479 /* 'fileformats' */
6480 else if (varp == &p_ffs)
6481 {
6482 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6483 errmsg = e_invarg;
6484 else
6485 {
6486 /* also change 'textauto' */
6487 if (*p_ffs == NUL)
6488 p_ta = FALSE;
6489 else
6490 p_ta = TRUE;
6491 }
6492 }
6493
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006494#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495 /* 'cryptkey' */
6496 else if (gvarp == &p_key)
6497 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006498# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006499 /* Make sure the ":set" command doesn't show the new value in the
6500 * history. */
6501 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006502# endif
6503 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6504 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006505 ml_set_crypt_key(curbuf, oldval,
6506 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006507 }
6508
6509 else if (gvarp == &p_cm)
6510 {
6511 if (opt_flags & OPT_LOCAL)
6512 p = curbuf->b_p_cm;
6513 else
6514 p = p_cm;
6515 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6516 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006517 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006518 errmsg = e_invarg;
6519 else
6520 {
6521 /* When setting the global value to empty, make it "zip". */
6522 if (*p_cm == NUL)
6523 {
6524 if (new_value_alloced)
6525 free_string_option(p_cm);
6526 p_cm = vim_strsave((char_u *)"zip");
6527 new_value_alloced = TRUE;
6528 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006529 /* When using ":set cm=name" the local value is going to be empty.
6530 * Do that here, otherwise the crypt functions will still use the
6531 * local value. */
6532 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6533 {
6534 free_string_option(curbuf->b_p_cm);
6535 curbuf->b_p_cm = empty_option;
6536 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006537
6538 /* Need to update the swapfile when the effective method changed.
6539 * Set "s" to the effective old value, "p" to the effective new
6540 * method and compare. */
6541 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6542 s = p_cm; /* was previously using the global value */
6543 else
6544 s = oldval;
6545 if (*curbuf->b_p_cm == NUL)
6546 p = p_cm; /* is now using the global value */
6547 else
6548 p = curbuf->b_p_cm;
6549 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006550 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006551
6552 /* If the global value changes need to update the swapfile for all
6553 * buffers using that value. */
6554 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6555 {
6556 buf_T *buf;
6557
Bram Moolenaar29323592016-07-24 22:04:11 +02006558 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006559 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006560 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006561 }
6562 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563 }
6564#endif
6565
6566 /* 'matchpairs' */
6567 else if (gvarp == &p_mps)
6568 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006569#ifdef FEAT_MBYTE
6570 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006571 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006572 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006573 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006574 int x2 = -1;
6575 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006576
6577 if (*p != NUL)
6578 p += mb_ptr2len(p);
6579 if (*p != NUL)
6580 x2 = *p++;
6581 if (*p != NUL)
6582 {
6583 x3 = mb_ptr2char(p);
6584 p += mb_ptr2len(p);
6585 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006586 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006587 {
6588 errmsg = e_invarg;
6589 break;
6590 }
6591 if (*p == NUL)
6592 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006594 }
6595 else
6596#endif
6597 {
6598 /* Check for "x:y,x:y" */
6599 for (p = *varp; *p != NUL; p += 4)
6600 {
6601 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6602 {
6603 errmsg = e_invarg;
6604 break;
6605 }
6606 if (p[3] == NUL)
6607 break;
6608 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006609 }
6610 }
6611
6612#ifdef FEAT_COMMENTS
6613 /* 'comments' */
6614 else if (gvarp == &p_com)
6615 {
6616 for (s = *varp; *s; )
6617 {
6618 while (*s && *s != ':')
6619 {
6620 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6621 && !VIM_ISDIGIT(*s) && *s != '-')
6622 {
6623 errmsg = illegal_char(errbuf, *s);
6624 break;
6625 }
6626 ++s;
6627 }
6628 if (*s++ == NUL)
6629 errmsg = (char_u *)N_("E524: Missing colon");
6630 else if (*s == ',' || *s == NUL)
6631 errmsg = (char_u *)N_("E525: Zero length string");
6632 if (errmsg != NULL)
6633 break;
6634 while (*s && *s != ',')
6635 {
6636 if (*s == '\\' && s[1] != NUL)
6637 ++s;
6638 ++s;
6639 }
6640 s = skip_to_option_part(s);
6641 }
6642 }
6643#endif
6644
6645 /* 'listchars' */
6646 else if (varp == &p_lcs)
6647 {
6648 errmsg = set_chars_option(varp);
6649 }
6650
6651#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6652 /* 'fillchars' */
6653 else if (varp == &p_fcs)
6654 {
6655 errmsg = set_chars_option(varp);
6656 }
6657#endif
6658
6659#ifdef FEAT_CMDWIN
6660 /* 'cedit' */
6661 else if (varp == &p_cedit)
6662 {
6663 errmsg = check_cedit();
6664 }
6665#endif
6666
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006667 /* 'verbosefile' */
6668 else if (varp == &p_vfile)
6669 {
6670 verbose_stop();
6671 if (*p_vfile != NUL && verbose_open() == FAIL)
6672 errmsg = e_invarg;
6673 }
6674
Bram Moolenaar071d4272004-06-13 20:20:40 +00006675#ifdef FEAT_VIMINFO
6676 /* 'viminfo' */
6677 else if (varp == &p_viminfo)
6678 {
6679 for (s = p_viminfo; *s;)
6680 {
6681 /* Check it's a valid character */
6682 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6683 {
6684 errmsg = illegal_char(errbuf, *s);
6685 break;
6686 }
6687 if (*s == 'n') /* name is always last one */
6688 {
6689 break;
6690 }
6691 else if (*s == 'r') /* skip until next ',' */
6692 {
6693 while (*++s && *s != ',')
6694 ;
6695 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006696 else if (*s == '%')
6697 {
6698 /* optional number */
6699 while (vim_isdigit(*++s))
6700 ;
6701 }
6702 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006703 ++s; /* no extra chars */
6704 else /* must have a number */
6705 {
6706 while (vim_isdigit(*++s))
6707 ;
6708
6709 if (!VIM_ISDIGIT(*(s - 1)))
6710 {
6711 if (errbuf != NULL)
6712 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006713 sprintf((char *)errbuf,
6714 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006715 transchar_byte(*(s - 1)));
6716 errmsg = errbuf;
6717 }
6718 else
6719 errmsg = (char_u *)"";
6720 break;
6721 }
6722 }
6723 if (*s == ',')
6724 ++s;
6725 else if (*s)
6726 {
6727 if (errbuf != NULL)
6728 errmsg = (char_u *)N_("E527: Missing comma");
6729 else
6730 errmsg = (char_u *)"";
6731 break;
6732 }
6733 }
6734 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6735 errmsg = (char_u *)N_("E528: Must specify a ' value");
6736 }
6737#endif /* FEAT_VIMINFO */
6738
6739 /* terminal options */
6740 else if (istermoption(&options[opt_idx]) && full_screen)
6741 {
6742 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6743 if (varp == &T_CCO)
6744 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006745 int colors = atoi((char *)T_CCO);
6746
6747 /* Only reinitialize colors if t_Co value has really changed to
6748 * avoid expensive reload of colorscheme if t_Co is set to the
6749 * same value multiple times. */
6750 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006752 t_colors = colors;
6753 if (t_colors <= 1)
6754 {
6755 if (new_value_alloced)
6756 vim_free(T_CCO);
6757 T_CCO = empty_option;
6758 }
6759 /* We now have a different color setup, initialize it again. */
6760 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006761 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762 }
6763 ttest(FALSE);
6764 if (varp == &T_ME)
6765 {
6766 out_str(T_ME);
6767 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006768#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006769 /* Since t_me has been set, this probably means that the user
6770 * wants to use this as default colors. Need to reset default
6771 * background/foreground colors. */
6772 mch_set_normal_colors();
6773#endif
6774 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006775 if (varp == &T_BE && termcap_active)
6776 {
6777 if (*T_BE == NUL)
6778 /* When clearing t_BE we assume the user no longer wants
6779 * bracketed paste, thus disable it by writing t_BD. */
6780 out_str(T_BD);
6781 else
6782 out_str(T_BE);
6783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006784 }
6785
6786#ifdef FEAT_LINEBREAK
6787 /* 'showbreak' */
6788 else if (varp == &p_sbr)
6789 {
6790 for (s = p_sbr; *s; )
6791 {
6792 if (ptr2cells(s) != 1)
6793 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006794 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 }
6796 }
6797#endif
6798
6799#ifdef FEAT_GUI
6800 /* 'guifont' */
6801 else if (varp == &p_guifont)
6802 {
6803 if (gui.in_use)
6804 {
6805 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006806# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807 /*
6808 * Put up a font dialog and let the user select a new value.
6809 * If this is cancelled go back to the old value but don't
6810 * give an error message.
6811 */
6812 if (STRCMP(p, "*") == 0)
6813 {
6814 p = gui_mch_font_dialog(oldval);
6815
6816 if (new_value_alloced)
6817 free_string_option(p_guifont);
6818
6819 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6820 new_value_alloced = TRUE;
6821 }
6822# endif
6823 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6824 {
6825# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6826 if (STRCMP(p_guifont, "*") == 0)
6827 {
6828 /* Dialog was cancelled: Keep the old value without giving
6829 * an error message. */
6830 if (new_value_alloced)
6831 free_string_option(p_guifont);
6832 p_guifont = vim_strsave(oldval);
6833 new_value_alloced = TRUE;
6834 }
6835 else
6836# endif
6837 errmsg = (char_u *)N_("E596: Invalid font(s)");
6838 }
6839 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006840 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006841 }
6842# ifdef FEAT_XFONTSET
6843 else if (varp == &p_guifontset)
6844 {
6845 if (STRCMP(p_guifontset, "*") == 0)
6846 errmsg = (char_u *)N_("E597: can't select fontset");
6847 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6848 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006849 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006850 }
6851# endif
6852# ifdef FEAT_MBYTE
6853 else if (varp == &p_guifontwide)
6854 {
6855 if (STRCMP(p_guifontwide, "*") == 0)
6856 errmsg = (char_u *)N_("E533: can't select wide font");
6857 else if (gui_get_wide_font() == FAIL)
6858 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006859 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006860 }
6861# endif
6862#endif
6863
6864#ifdef CURSOR_SHAPE
6865 /* 'guicursor' */
6866 else if (varp == &p_guicursor)
6867 errmsg = parse_shape_opt(SHAPE_CURSOR);
6868#endif
6869
6870#ifdef FEAT_MOUSESHAPE
6871 /* 'mouseshape' */
6872 else if (varp == &p_mouseshape)
6873 {
6874 errmsg = parse_shape_opt(SHAPE_MOUSE);
6875 update_mouseshape(-1);
6876 }
6877#endif
6878
6879#ifdef FEAT_PRINTER
6880 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006881 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006882# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006883 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006884 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006885# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006886#endif
6887
6888#ifdef FEAT_LANGMAP
6889 /* 'langmap' */
6890 else if (varp == &p_langmap)
6891 langmap_set();
6892#endif
6893
6894#ifdef FEAT_LINEBREAK
6895 /* 'breakat' */
6896 else if (varp == &p_breakat)
6897 fill_breakat_flags();
6898#endif
6899
6900#ifdef FEAT_TITLE
6901 /* 'titlestring' and 'iconstring' */
6902 else if (varp == &p_titlestring || varp == &p_iconstring)
6903 {
6904# ifdef FEAT_STL_OPT
6905 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6906
6907 /* NULL => statusline syntax */
6908 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6909 stl_syntax |= flagval;
6910 else
6911 stl_syntax &= ~flagval;
6912# endif
6913 did_set_title(varp == &p_iconstring);
6914
6915 }
6916#endif
6917
6918#ifdef FEAT_GUI
6919 /* 'guioptions' */
6920 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006921 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006922 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006923 redraw_gui_only = TRUE;
6924 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925#endif
6926
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006927#if defined(FEAT_GUI_TABLINE)
6928 /* 'guitablabel' */
6929 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006930 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006931 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006932 redraw_gui_only = TRUE;
6933 }
6934 /* 'guitabtooltip' */
6935 else if (varp == &p_gtt)
6936 {
6937 redraw_gui_only = TRUE;
6938 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006939#endif
6940
Bram Moolenaar071d4272004-06-13 20:20:40 +00006941#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6942 /* 'ttymouse' */
6943 else if (varp == &p_ttym)
6944 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006945 /* Switch the mouse off before changing the escape sequences used for
6946 * that. */
6947 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006948 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6949 errmsg = e_invarg;
6950 else
6951 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006952 if (termcap_active)
6953 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006954 }
6955#endif
6956
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957 /* 'selection' */
6958 else if (varp == &p_sel)
6959 {
6960 if (*p_sel == NUL
6961 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6962 errmsg = e_invarg;
6963 }
6964
6965 /* 'selectmode' */
6966 else if (varp == &p_slm)
6967 {
6968 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6969 errmsg = e_invarg;
6970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006971
6972#ifdef FEAT_BROWSE
6973 /* 'browsedir' */
6974 else if (varp == &p_bsdir)
6975 {
6976 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6977 && !mch_isdir(p_bsdir))
6978 errmsg = e_invarg;
6979 }
6980#endif
6981
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982 /* 'keymodel' */
6983 else if (varp == &p_km)
6984 {
6985 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6986 errmsg = e_invarg;
6987 else
6988 {
6989 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6990 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6991 }
6992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993
6994 /* 'mousemodel' */
6995 else if (varp == &p_mousem)
6996 {
6997 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6998 errmsg = e_invarg;
6999#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7000 else if (*p_mousem != *oldval)
7001 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7002 * to create or delete the popup menus. */
7003 gui_motif_update_mousemodel(root_menu);
7004#endif
7005 }
7006
7007 /* 'switchbuf' */
7008 else if (varp == &p_swb)
7009 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007010 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011 errmsg = e_invarg;
7012 }
7013
7014 /* 'debug' */
7015 else if (varp == &p_debug)
7016 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007017 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018 errmsg = e_invarg;
7019 }
7020
7021 /* 'display' */
7022 else if (varp == &p_dy)
7023 {
7024 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7025 errmsg = e_invarg;
7026 else
7027 (void)init_chartab();
7028
7029 }
7030
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007031#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007032 /* 'eadirection' */
7033 else if (varp == &p_ead)
7034 {
7035 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7036 errmsg = e_invarg;
7037 }
7038#endif
7039
7040#ifdef FEAT_CLIPBOARD
7041 /* 'clipboard' */
7042 else if (varp == &p_cb)
7043 errmsg = check_clipboard_option();
7044#endif
7045
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007046#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007047 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7048 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007049 else if (varp == &(curwin->w_s->b_p_spl)
7050 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007051 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007052 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007053 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007054 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007055 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007056 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007057 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007058 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007059 /* 'spellsuggest' */
7060 else if (varp == &p_sps)
7061 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007062 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007063 errmsg = e_invarg;
7064 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007065 /* 'mkspellmem' */
7066 else if (varp == &p_msm)
7067 {
7068 if (spell_check_msm() != OK)
7069 errmsg = e_invarg;
7070 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007071#endif
7072
Bram Moolenaar071d4272004-06-13 20:20:40 +00007073#ifdef FEAT_QUICKFIX
7074 /* When 'bufhidden' is set, check for valid value. */
7075 else if (gvarp == &p_bh)
7076 {
7077 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7078 errmsg = e_invarg;
7079 }
7080
7081 /* When 'buftype' is set, check for valid value. */
7082 else if (gvarp == &p_bt)
7083 {
7084 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7085 errmsg = e_invarg;
7086 else
7087 {
7088# ifdef FEAT_WINDOWS
7089 if (curwin->w_status_height)
7090 {
7091 curwin->w_redr_status = TRUE;
7092 redraw_later(VALID);
7093 }
7094# endif
7095 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007096# ifdef FEAT_TITLE
7097 redraw_titles();
7098# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099 }
7100 }
7101#endif
7102
7103#ifdef FEAT_STL_OPT
7104 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007105 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 {
7107 int wid;
7108
7109 if (varp == &p_ruf) /* reset ru_wid first */
7110 ru_wid = 0;
7111 s = *varp;
7112 if (varp == &p_ruf && *s == '%')
7113 {
7114 /* set ru_wid if 'ruf' starts with "%99(" */
7115 if (*++s == '-') /* ignore a '-' */
7116 s++;
7117 wid = getdigits(&s);
7118 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7119 ru_wid = wid;
7120 else
7121 errmsg = check_stl_option(p_ruf);
7122 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007123 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007124 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007126 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127 comp_col();
7128 }
7129#endif
7130
7131#ifdef FEAT_INS_EXPAND
7132 /* check if it is a valid value for 'complete' -- Acevedo */
7133 else if (gvarp == &p_cpt)
7134 {
7135 for (s = *varp; *s;)
7136 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007137 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138 s++;
7139 if (!*s)
7140 break;
7141 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7142 {
7143 errmsg = illegal_char(errbuf, *s);
7144 break;
7145 }
7146 if (*++s != NUL && *s != ',' && *s != ' ')
7147 {
7148 if (s[-1] == 'k' || s[-1] == 's')
7149 {
7150 /* skip optional filename after 'k' and 's' */
7151 while (*s && *s != ',' && *s != ' ')
7152 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007153 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 ++s;
7155 ++s;
7156 }
7157 }
7158 else
7159 {
7160 if (errbuf != NULL)
7161 {
7162 sprintf((char *)errbuf,
7163 _("E535: Illegal character after <%c>"),
7164 *--s);
7165 errmsg = errbuf;
7166 }
7167 else
7168 errmsg = (char_u *)"";
7169 break;
7170 }
7171 }
7172 }
7173 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007174
7175 /* 'completeopt' */
7176 else if (varp == &p_cot)
7177 {
7178 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7179 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007180 else
7181 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007183#endif /* FEAT_INS_EXPAND */
7184
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007185#ifdef FEAT_SIGNS
7186 /* 'signcolumn' */
7187 else if (varp == &curwin->w_p_scl)
7188 {
7189 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7190 errmsg = e_invarg;
7191 }
7192#endif
7193
Bram Moolenaar071d4272004-06-13 20:20:40 +00007194
7195#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007196 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197 else if (varp == &p_toolbar)
7198 {
7199 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7200 &toolbar_flags, TRUE) != OK)
7201 errmsg = e_invarg;
7202 else
7203 {
7204 out_flush();
7205 gui_mch_show_toolbar((toolbar_flags &
7206 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7207 }
7208 }
7209#endif
7210
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007211#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212 /* 'toolbariconsize': GTK+ 2 only */
7213 else if (varp == &p_tbis)
7214 {
7215 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7216 errmsg = e_invarg;
7217 else
7218 {
7219 out_flush();
7220 gui_mch_show_toolbar((toolbar_flags &
7221 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7222 }
7223 }
7224#endif
7225
7226 /* 'pastetoggle': translate key codes like in a mapping */
7227 else if (varp == &p_pt)
7228 {
7229 if (*p_pt)
7230 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007231 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007232 if (p != NULL)
7233 {
7234 if (new_value_alloced)
7235 free_string_option(p_pt);
7236 p_pt = p;
7237 new_value_alloced = TRUE;
7238 }
7239 }
7240 }
7241
7242 /* 'backspace' */
7243 else if (varp == &p_bs)
7244 {
7245 if (VIM_ISDIGIT(*p_bs))
7246 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007247 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007248 errmsg = e_invarg;
7249 }
7250 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7251 errmsg = e_invarg;
7252 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007253 else if (varp == &p_bo)
7254 {
7255 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7256 errmsg = e_invarg;
7257 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007258
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007259 /* 'tagcase' */
7260 else if (gvarp == &p_tc)
7261 {
7262 unsigned int *flags;
7263
7264 if (opt_flags & OPT_LOCAL)
7265 {
7266 p = curbuf->b_p_tc;
7267 flags = &curbuf->b_tc_flags;
7268 }
7269 else
7270 {
7271 p = p_tc;
7272 flags = &tc_flags;
7273 }
7274
7275 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7276 /* make the local value empty: use the global value */
7277 *flags = 0;
7278 else if (*p == NUL
7279 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7280 errmsg = e_invarg;
7281 }
7282
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007283#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007284 /* 'casemap' */
7285 else if (varp == &p_cmp)
7286 {
7287 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7288 errmsg = e_invarg;
7289 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007290#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007291
7292#ifdef FEAT_DIFF
7293 /* 'diffopt' */
7294 else if (varp == &p_dip)
7295 {
7296 if (diffopt_changed() == FAIL)
7297 errmsg = e_invarg;
7298 }
7299#endif
7300
7301#ifdef FEAT_FOLDING
7302 /* 'foldmethod' */
7303 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7304 {
7305 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7306 || *curwin->w_p_fdm == NUL)
7307 errmsg = e_invarg;
7308 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007309 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007311 if (foldmethodIsDiff(curwin))
7312 newFoldLevel();
7313 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007314 }
7315# ifdef FEAT_EVAL
7316 /* 'foldexpr' */
7317 else if (varp == &curwin->w_p_fde)
7318 {
7319 if (foldmethodIsExpr(curwin))
7320 foldUpdateAll(curwin);
7321 }
7322# endif
7323 /* 'foldmarker' */
7324 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7325 {
7326 p = vim_strchr(*varp, ',');
7327 if (p == NULL)
7328 errmsg = (char_u *)N_("E536: comma required");
7329 else if (p == *varp || p[1] == NUL)
7330 errmsg = e_invarg;
7331 else if (foldmethodIsMarker(curwin))
7332 foldUpdateAll(curwin);
7333 }
7334 /* 'commentstring' */
7335 else if (gvarp == &p_cms)
7336 {
7337 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7338 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7339 }
7340 /* 'foldopen' */
7341 else if (varp == &p_fdo)
7342 {
7343 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7344 errmsg = e_invarg;
7345 }
7346 /* 'foldclose' */
7347 else if (varp == &p_fcl)
7348 {
7349 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7350 errmsg = e_invarg;
7351 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007352 /* 'foldignore' */
7353 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7354 {
7355 if (foldmethodIsIndent(curwin))
7356 foldUpdateAll(curwin);
7357 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358#endif
7359
7360#ifdef FEAT_VIRTUALEDIT
7361 /* 'virtualedit' */
7362 else if (varp == &p_ve)
7363 {
7364 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7365 errmsg = e_invarg;
7366 else if (STRCMP(p_ve, oldval) != 0)
7367 {
7368 /* Recompute cursor position in case the new 've' setting
7369 * changes something. */
7370 validate_virtcol();
7371 coladvance(curwin->w_virtcol);
7372 }
7373 }
7374#endif
7375
7376#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7377 else if (varp == &p_csqf)
7378 {
7379 if (p_csqf != NULL)
7380 {
7381 p = p_csqf;
7382 while (*p != NUL)
7383 {
7384 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7385 || p[1] == NUL
7386 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7387 || (p[2] != NUL && p[2] != ','))
7388 {
7389 errmsg = e_invarg;
7390 break;
7391 }
7392 else if (p[2] == NUL)
7393 break;
7394 else
7395 p += 3;
7396 }
7397 }
7398 }
7399#endif
7400
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007401#ifdef FEAT_CINDENT
7402 /* 'cinoptions' */
7403 else if (gvarp == &p_cino)
7404 {
7405 /* TODO: recognize errors */
7406 parse_cino(curbuf);
7407 }
7408#endif
7409
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007410#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007411 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007412 else if (varp == &p_rop && gui.in_use)
7413 {
7414 if (!gui_mch_set_rendering_options(p_rop))
7415 errmsg = e_invarg;
7416 }
7417#endif
7418
Bram Moolenaard0b51382016-11-04 15:23:45 +01007419#ifdef FEAT_AUTOCMD
7420 else if (gvarp == &p_ft)
7421 {
7422 if (!valid_filetype(*varp))
7423 errmsg = e_invarg;
7424 }
7425#endif
7426
7427#ifdef FEAT_SYN_HL
7428 else if (gvarp == &p_syn)
7429 {
7430 if (!valid_filetype(*varp))
7431 errmsg = e_invarg;
7432 }
7433#endif
7434
Bram Moolenaar071d4272004-06-13 20:20:40 +00007435 /* Options that are a list of flags. */
7436 else
7437 {
7438 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007439 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007440 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007441 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007442 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007443 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007444 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007445 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007446 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007447#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007448 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007449 p = (char_u *)COCU_ALL;
7450#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007451 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007452 {
7453#ifdef FEAT_MOUSE
7454 p = (char_u *)MOUSE_ALL;
7455#else
7456 if (*p_mouse != NUL)
7457 errmsg = (char_u *)N_("E538: No mouse support");
7458#endif
7459 }
7460#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007461 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 p = (char_u *)GO_ALL;
7463#endif
7464 if (p != NULL)
7465 {
7466 for (s = *varp; *s; ++s)
7467 if (vim_strchr(p, *s) == NULL)
7468 {
7469 errmsg = illegal_char(errbuf, *s);
7470 break;
7471 }
7472 }
7473 }
7474
7475 /*
7476 * If error detected, restore the previous value.
7477 */
7478 if (errmsg != NULL)
7479 {
7480 if (new_value_alloced)
7481 free_string_option(*varp);
7482 *varp = oldval;
7483 /*
7484 * When resetting some values, need to act on it.
7485 */
7486 if (did_chartab)
7487 (void)init_chartab();
7488 if (varp == &p_hl)
7489 (void)highlight_changed();
7490 }
7491 else
7492 {
7493#ifdef FEAT_EVAL
7494 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007495 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496#endif
7497 /*
7498 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007499 * Use "free_oldval", because recursiveness may change the flags under
7500 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007501 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007502 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007503 free_string_option(oldval);
7504 if (new_value_alloced)
7505 options[opt_idx].flags |= P_ALLOCED;
7506 else
7507 options[opt_idx].flags &= ~P_ALLOCED;
7508
7509 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007510 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007511 {
7512 /* global option with local value set to use global value; free
7513 * the local value and make it empty */
7514 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7515 free_string_option(*(char_u **)p);
7516 *(char_u **)p = empty_option;
7517 }
7518
7519 /* May set global value for local option. */
7520 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7521 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007522
7523#ifdef FEAT_AUTOCMD
7524 /*
7525 * Trigger the autocommand only after setting the flags.
7526 */
7527# ifdef FEAT_SYN_HL
7528 /* When 'syntax' is set, load the syntax of that name */
7529 if (varp == &(curbuf->b_p_syn))
7530 {
7531 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7532 curbuf->b_fname, TRUE, curbuf);
7533 }
7534# endif
7535 else if (varp == &(curbuf->b_p_ft))
7536 {
7537 /* 'filetype' is set, trigger the FileType autocommand */
7538 did_filetype = TRUE;
7539 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7540 curbuf->b_fname, TRUE, curbuf);
7541 }
7542#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007543#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007544 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007545 {
7546 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007547 char_u *q = curwin->w_s->b_p_spl;
7548
7549 /* Skip the first name if it is "cjk". */
7550 if (STRNCMP(q, "cjk,", 4) == 0)
7551 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007552
7553 /*
7554 * Source the spell/LANG.vim in 'runtimepath'.
7555 * They could set 'spellcapcheck' depending on the language.
7556 * Use the first name in 'spelllang' up to '_region' or
7557 * '.encoding'.
7558 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007559 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007560 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7561 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007562 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007563 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007564 }
7565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007566 }
7567
7568#ifdef FEAT_MOUSE
7569 if (varp == &p_mouse)
7570 {
7571# ifdef FEAT_MOUSE_TTY
7572 if (*p_mouse == NUL)
7573 mch_setmouse(FALSE); /* switch mouse off */
7574 else
7575# endif
7576 setmouse(); /* in case 'mouse' changed */
7577 }
7578#endif
7579
Bram Moolenaar913077c2012-03-28 19:59:04 +02007580 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007581 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007582 curwin->w_set_curswant = TRUE;
7583
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007584#ifdef FEAT_GUI
7585 /* check redraw when it's not a GUI option or the GUI is active. */
7586 if (!redraw_gui_only || gui.in_use)
7587#endif
7588 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007589
7590 return errmsg;
7591}
7592
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007593#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007594/*
7595 * Simple int comparison function for use with qsort()
7596 */
7597 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007598int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007599{
7600 return *(const int *)a - *(const int *)b;
7601}
7602
7603/*
7604 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7605 * Returns error message, NULL if it's OK.
7606 */
7607 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007608check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007609{
7610 char_u *s;
7611 int col;
7612 int count = 0;
7613 int color_cols[256];
7614 int i;
7615 int j = 0;
7616
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007617 if (wp->w_buffer == NULL)
7618 return NULL; /* buffer was closed */
7619
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007620 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007621 {
7622 if (*s == '-' || *s == '+')
7623 {
7624 /* -N and +N: add to 'textwidth' */
7625 col = (*s == '-') ? -1 : 1;
7626 ++s;
7627 if (!VIM_ISDIGIT(*s))
7628 return e_invarg;
7629 col = col * getdigits(&s);
7630 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007631 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007632 col += wp->w_buffer->b_p_tw;
7633 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007634 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007635 }
7636 else if (VIM_ISDIGIT(*s))
7637 col = getdigits(&s);
7638 else
7639 return e_invarg;
7640 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007641skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007642 if (*s == NUL)
7643 break;
7644 if (*s != ',')
7645 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007646 if (*++s == NUL)
7647 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007648 }
7649
7650 vim_free(wp->w_p_cc_cols);
7651 if (count == 0)
7652 wp->w_p_cc_cols = NULL;
7653 else
7654 {
7655 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7656 if (wp->w_p_cc_cols != NULL)
7657 {
7658 /* sort the columns for faster usage on screen redraw inside
7659 * win_line() */
7660 qsort(color_cols, count, sizeof(int), int_cmp);
7661
7662 for (i = 0; i < count; ++i)
7663 /* skip duplicates */
7664 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7665 wp->w_p_cc_cols[j++] = color_cols[i];
7666 wp->w_p_cc_cols[j] = -1; /* end marker */
7667 }
7668 }
7669
7670 return NULL; /* no error */
7671}
7672#endif
7673
Bram Moolenaar071d4272004-06-13 20:20:40 +00007674/*
7675 * Handle setting 'listchars' or 'fillchars'.
7676 * Returns error message, NULL if it's OK.
7677 */
7678 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007679set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007680{
7681 int round, i, len, entries;
7682 char_u *p, *s;
7683 int c1, c2 = 0;
7684 struct charstab
7685 {
7686 int *cp;
7687 char *name;
7688 };
7689#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7690 static struct charstab filltab[] =
7691 {
7692 {&fill_stl, "stl"},
7693 {&fill_stlnc, "stlnc"},
7694 {&fill_vert, "vert"},
7695 {&fill_fold, "fold"},
7696 {&fill_diff, "diff"},
7697 };
7698#endif
7699 static struct charstab lcstab[] =
7700 {
7701 {&lcs_eol, "eol"},
7702 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007703 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007705 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706 {&lcs_tab2, "tab"},
7707 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007708#ifdef FEAT_CONCEAL
7709 {&lcs_conceal, "conceal"},
7710#else
7711 {NULL, "conceal"},
7712#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 };
7714 struct charstab *tab;
7715
7716#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7717 if (varp == &p_lcs)
7718#endif
7719 {
7720 tab = lcstab;
7721 entries = sizeof(lcstab) / sizeof(struct charstab);
7722 }
7723#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7724 else
7725 {
7726 tab = filltab;
7727 entries = sizeof(filltab) / sizeof(struct charstab);
7728 }
7729#endif
7730
7731 /* first round: check for valid value, second round: assign values */
7732 for (round = 0; round <= 1; ++round)
7733 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007734 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735 {
7736 /* After checking that the value is valid: set defaults: space for
7737 * 'fillchars', NUL for 'listchars' */
7738 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007739 if (tab[i].cp != NULL)
7740 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 if (varp == &p_lcs)
7742 lcs_tab1 = NUL;
7743#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7744 else
7745 fill_diff = '-';
7746#endif
7747 }
7748 p = *varp;
7749 while (*p)
7750 {
7751 for (i = 0; i < entries; ++i)
7752 {
7753 len = (int)STRLEN(tab[i].name);
7754 if (STRNCMP(p, tab[i].name, len) == 0
7755 && p[len] == ':'
7756 && p[len + 1] != NUL)
7757 {
7758 s = p + len + 1;
7759#ifdef FEAT_MBYTE
7760 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007761 if (mb_char2cells(c1) > 1)
7762 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763#else
7764 c1 = *s++;
7765#endif
7766 if (tab[i].cp == &lcs_tab2)
7767 {
7768 if (*s == NUL)
7769 continue;
7770#ifdef FEAT_MBYTE
7771 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007772 if (mb_char2cells(c2) > 1)
7773 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774#else
7775 c2 = *s++;
7776#endif
7777 }
7778 if (*s == ',' || *s == NUL)
7779 {
7780 if (round)
7781 {
7782 if (tab[i].cp == &lcs_tab2)
7783 {
7784 lcs_tab1 = c1;
7785 lcs_tab2 = c2;
7786 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007787 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007788 *(tab[i].cp) = c1;
7789
7790 }
7791 p = s;
7792 break;
7793 }
7794 }
7795 }
7796
7797 if (i == entries)
7798 return e_invarg;
7799 if (*p == ',')
7800 ++p;
7801 }
7802 }
7803
7804 return NULL; /* no error */
7805}
7806
7807#ifdef FEAT_STL_OPT
7808/*
7809 * Check validity of options with the 'statusline' format.
7810 * Return error message or NULL.
7811 */
7812 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007813check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007814{
7815 int itemcnt = 0;
7816 int groupdepth = 0;
7817 static char_u errbuf[80];
7818
7819 while (*s && itemcnt < STL_MAX_ITEM)
7820 {
7821 /* Check for valid keys after % sequences */
7822 while (*s && *s != '%')
7823 s++;
7824 if (!*s)
7825 break;
7826 s++;
7827 if (*s != '%' && *s != ')')
7828 ++itemcnt;
7829 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7830 {
7831 s++;
7832 continue;
7833 }
7834 if (*s == ')')
7835 {
7836 s++;
7837 if (--groupdepth < 0)
7838 break;
7839 continue;
7840 }
7841 if (*s == '-')
7842 s++;
7843 while (VIM_ISDIGIT(*s))
7844 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007845 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 continue;
7847 if (*s == '.')
7848 {
7849 s++;
7850 while (*s && VIM_ISDIGIT(*s))
7851 s++;
7852 }
7853 if (*s == '(')
7854 {
7855 groupdepth++;
7856 continue;
7857 }
7858 if (vim_strchr(STL_ALL, *s) == NULL)
7859 {
7860 return illegal_char(errbuf, *s);
7861 }
7862 if (*s == '{')
7863 {
7864 s++;
7865 while (*s != '}' && *s)
7866 s++;
7867 if (*s != '}')
7868 return (char_u *)N_("E540: Unclosed expression sequence");
7869 }
7870 }
7871 if (itemcnt >= STL_MAX_ITEM)
7872 return (char_u *)N_("E541: too many items");
7873 if (groupdepth != 0)
7874 return (char_u *)N_("E542: unbalanced groups");
7875 return NULL;
7876}
7877#endif
7878
7879#ifdef FEAT_CLIPBOARD
7880/*
7881 * Extract the items in the 'clipboard' option and set global values.
7882 */
7883 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007884check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007885{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007886 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007887 int new_autoselect_star = FALSE;
7888 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007890 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007891 regprog_T *new_exclude_prog = NULL;
7892 char_u *errmsg = NULL;
7893 char_u *p;
7894
7895 for (p = p_cb; *p != NUL; )
7896 {
7897 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7898 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007899 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 p += 7;
7901 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007902 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007903 && (p[11] == ',' || p[11] == NUL))
7904 {
7905 new_unnamed |= CLIP_UNNAMED_PLUS;
7906 p += 11;
7907 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007909 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007910 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007911 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007912 p += 10;
7913 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007914 else if (STRNCMP(p, "autoselectplus", 14) == 0
7915 && (p[14] == ',' || p[14] == NUL))
7916 {
7917 new_autoselect_plus = TRUE;
7918 p += 14;
7919 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007920 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007921 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007922 {
7923 new_autoselectml = TRUE;
7924 p += 12;
7925 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007926 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7927 {
7928 new_html = TRUE;
7929 p += 4;
7930 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7932 {
7933 p += 8;
7934 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7935 if (new_exclude_prog == NULL)
7936 errmsg = e_invarg;
7937 break;
7938 }
7939 else
7940 {
7941 errmsg = e_invarg;
7942 break;
7943 }
7944 if (*p == ',')
7945 ++p;
7946 }
7947 if (errmsg == NULL)
7948 {
7949 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007950 clip_autoselect_star = new_autoselect_star;
7951 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007953 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007954 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007956#ifdef FEAT_GUI_GTK
7957 if (gui.in_use)
7958 {
7959 gui_gtk_set_selection_targets();
7960 gui_gtk_set_dnd_targets();
7961 }
7962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 }
7964 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007965 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966
7967 return errmsg;
7968}
7969#endif
7970
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007971#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007972 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007973did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007974{
7975 char_u *errmsg = NULL;
7976 win_T *wp;
7977 int l;
7978
7979 if (is_spellfile)
7980 {
7981 l = (int)STRLEN(curwin->w_s->b_p_spf);
7982 if (l > 0 && (l < 4
7983 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7984 errmsg = e_invarg;
7985 }
7986
7987 if (errmsg == NULL)
7988 {
7989 FOR_ALL_WINDOWS(wp)
7990 if (wp->w_buffer == curbuf && wp->w_p_spell)
7991 {
7992 errmsg = did_set_spelllang(wp);
7993# ifdef FEAT_WINDOWS
7994 break;
7995# endif
7996 }
7997 }
7998 return errmsg;
7999}
8000
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008001/*
8002 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8003 * Return error message when failed, NULL when OK.
8004 */
8005 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008006compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008007{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008008 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008009 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008010
Bram Moolenaar860cae12010-06-05 23:22:07 +02008011 if (*synblock->b_p_spc == NUL)
8012 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008013 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008014 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008015 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008016 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008017 if (re != NULL)
8018 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008019 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008020 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008021 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008022 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008023 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008024 return e_invarg;
8025 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008026 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008027 }
8028
Bram Moolenaar473de612013-06-08 18:19:48 +02008029 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008030 return NULL;
8031}
8032#endif
8033
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008034#if defined(FEAT_EVAL) || defined(PROTO)
8035/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008036 * Set the scriptID for an option, taking care of setting the buffer- or
8037 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008038 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008039 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008040set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008041{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008042 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8043 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008044
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008045 /* Remember where the option was set. For local options need to do that
8046 * in the buffer or window structure. */
8047 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008048 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008049 if (both || (opt_flags & OPT_LOCAL))
8050 {
8051 if (indir & PV_BUF)
8052 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8053 else if (indir & PV_WIN)
8054 curwin->w_p_scriptID[indir & PV_MASK] = id;
8055 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008056}
8057#endif
8058
Bram Moolenaar071d4272004-06-13 20:20:40 +00008059/*
8060 * Set the value of a boolean option, and take care of side effects.
8061 * Returns NULL for success, or an error message for an error.
8062 */
8063 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008064set_bool_option(
8065 int opt_idx, /* index in options[] table */
8066 char_u *varp, /* pointer to the option variable */
8067 int value, /* new value */
8068 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069{
8070 int old_value = *(int *)varp;
8071
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072 /* Disallow changing some options from secure mode */
8073 if ((secure
8074#ifdef HAVE_SANDBOX
8075 || sandbox != 0
8076#endif
8077 ) && (options[opt_idx].flags & P_SECURE))
8078 return e_secure;
8079
8080 *(int *)varp = value; /* set the new value */
8081#ifdef FEAT_EVAL
8082 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008083 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008084#endif
8085
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008086#ifdef FEAT_GUI
8087 need_mouse_correct = TRUE;
8088#endif
8089
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090 /* May set global value for local option. */
8091 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8092 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8093
8094 /*
8095 * Handle side effects of changing a bool option.
8096 */
8097
8098 /* 'compatible' */
8099 if ((int *)varp == &p_cp)
8100 {
8101 compatible_set();
8102 }
8103
Bram Moolenaar920694c2016-08-21 17:45:02 +02008104#ifdef FEAT_LANGMAP
8105 if ((int *)varp == &p_lrm)
8106 /* 'langremap' -> !'langnoremap' */
8107 p_lnr = !p_lrm;
8108 else if ((int *)varp == &p_lnr)
8109 /* 'langnoremap' -> !'langremap' */
8110 p_lrm = !p_lnr;
8111#endif
8112
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008113#ifdef FEAT_PERSISTENT_UNDO
8114 /* 'undofile' */
8115 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8116 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008117 /* Only take action when the option was set. When reset we do not
8118 * delete the undo file, the option may be set again without making
8119 * any changes in between. */
8120 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008121 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008122 char_u hash[UNDO_HASH_SIZE];
8123 buf_T *save_curbuf = curbuf;
8124
Bram Moolenaar29323592016-07-24 22:04:11 +02008125 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008126 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008127 /* When 'undofile' is set globally: for every buffer, otherwise
8128 * only for the current buffer: Try to read in the undofile,
8129 * if one exists, the buffer wasn't changed and the buffer was
8130 * loaded */
8131 if ((curbuf == save_curbuf
8132 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8133 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8134 {
8135 u_compute_hash(hash);
8136 u_read_undo(NULL, hash, curbuf->b_fname);
8137 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008138 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008139 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008140 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008141 }
8142#endif
8143
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 else if ((int *)varp == &curbuf->b_p_ro)
8145 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008146 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8148 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008149
8150 /* when 'readonly' is set may give W10 again */
8151 if (curbuf->b_p_ro)
8152 curbuf->b_did_warn = FALSE;
8153
Bram Moolenaar071d4272004-06-13 20:20:40 +00008154#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008155 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156#endif
8157 }
8158
Bram Moolenaar9c449722010-07-20 18:44:27 +02008159#ifdef FEAT_GUI
8160 else if ((int *)varp == &p_mh)
8161 {
8162 if (!p_mh)
8163 gui_mch_mousehide(FALSE);
8164 }
8165#endif
8166
Bram Moolenaara539df02010-08-01 14:35:05 +02008167#ifdef FEAT_TITLE
8168 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008170 {
8171 redraw_titles();
8172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 /* when 'endofline' is changed, redraw the window title */
8174 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008175 {
8176 redraw_titles();
8177 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008178 /* when 'fixeol' is changed, redraw the window title */
8179 else if ((int *)varp == &curbuf->b_p_fixeol)
8180 {
8181 redraw_titles();
8182 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008183# ifdef FEAT_MBYTE
8184 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008185 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008186 {
8187 redraw_titles();
8188 }
8189# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190#endif
8191
8192 /* when 'bin' is set also set some other options */
8193 else if ((int *)varp == &curbuf->b_p_bin)
8194 {
8195 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8196#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008197 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198#endif
8199 }
8200
8201#ifdef FEAT_AUTOCMD
8202 /* when 'buflisted' changes, trigger autocommands */
8203 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8204 {
8205 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8206 NULL, NULL, TRUE, curbuf);
8207 }
8208#endif
8209
8210 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8211 else if ((int *)varp == &curbuf->b_p_swf)
8212 {
8213 if (curbuf->b_p_swf && p_uc)
8214 ml_open_file(curbuf); /* create the swap file */
8215 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008216 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8217 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 mf_close_file(curbuf, TRUE); /* remove the swap file */
8219 }
8220
8221 /* when 'terse' is set change 'shortmess' */
8222 else if ((int *)varp == &p_terse)
8223 {
8224 char_u *p;
8225
8226 p = vim_strchr(p_shm, SHM_SEARCH);
8227
8228 /* insert 's' in p_shm */
8229 if (p_terse && p == NULL)
8230 {
8231 STRCPY(IObuff, p_shm);
8232 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008233 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234 }
8235 /* remove 's' from p_shm */
8236 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008237 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008238 }
8239
8240 /* when 'paste' is set or reset also change other options */
8241 else if ((int *)varp == &p_paste)
8242 {
8243 paste_option_changed();
8244 }
8245
8246 /* when 'insertmode' is set from an autocommand need to do work here */
8247 else if ((int *)varp == &p_im)
8248 {
8249 if (p_im)
8250 {
8251 if ((State & INSERT) == 0)
8252 need_start_insertmode = TRUE;
8253 stop_insert_mode = FALSE;
8254 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008255 /* only reset if it was set previously */
8256 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008257 {
8258 need_start_insertmode = FALSE;
8259 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008260 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 clear_cmdline = TRUE; /* remove "(insert)" */
8262 restart_edit = 0;
8263 }
8264 }
8265
8266 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8267 else if ((int *)varp == &p_ic && p_hls)
8268 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008269 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008270 }
8271
8272#ifdef FEAT_SEARCH_EXTRA
8273 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8274 else if ((int *)varp == &p_hls)
8275 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008276 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008277 }
8278#endif
8279
8280#ifdef FEAT_SCROLLBIND
8281 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8282 * at the end of normal_cmd() */
8283 else if ((int *)varp == &curwin->w_p_scb)
8284 {
8285 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008286 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008288 curwin->w_scbind_pos = curwin->w_topline;
8289 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 }
8291#endif
8292
8293#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8294 /* There can be only one window with 'previewwindow' set. */
8295 else if ((int *)varp == &curwin->w_p_pvw)
8296 {
8297 if (curwin->w_p_pvw)
8298 {
8299 win_T *win;
8300
Bram Moolenaar29323592016-07-24 22:04:11 +02008301 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008302 if (win->w_p_pvw && win != curwin)
8303 {
8304 curwin->w_p_pvw = FALSE;
8305 return (char_u *)N_("E590: A preview window already exists");
8306 }
8307 }
8308 }
8309#endif
8310
8311 /* when 'textmode' is set or reset also change 'fileformat' */
8312 else if ((int *)varp == &curbuf->b_p_tx)
8313 {
8314 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8315 }
8316
8317 /* when 'textauto' is set or reset also change 'fileformats' */
8318 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008319 set_string_option_direct((char_u *)"ffs", -1,
8320 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008321 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322
8323 /*
8324 * When 'lisp' option changes include/exclude '-' in
8325 * keyword characters.
8326 */
8327#ifdef FEAT_LISP
8328 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8329 {
8330 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8331 }
8332#endif
8333
8334#ifdef FEAT_TITLE
8335 /* when 'title' changed, may need to change the title; same for 'icon' */
8336 else if ((int *)varp == &p_title)
8337 {
8338 did_set_title(FALSE);
8339 }
8340
8341 else if ((int *)varp == &p_icon)
8342 {
8343 did_set_title(TRUE);
8344 }
8345#endif
8346
8347 else if ((int *)varp == &curbuf->b_changed)
8348 {
8349 if (!value)
8350 save_file_ff(curbuf); /* Buffer is unchanged */
8351#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008352 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353#endif
8354#ifdef FEAT_AUTOCMD
8355 modified_was_set = value;
8356#endif
8357 }
8358
8359#ifdef BACKSLASH_IN_FILENAME
8360 else if ((int *)varp == &p_ssl)
8361 {
8362 if (p_ssl)
8363 {
8364 psepc = '/';
8365 psepcN = '\\';
8366 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008367 }
8368 else
8369 {
8370 psepc = '\\';
8371 psepcN = '/';
8372 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008373 }
8374
8375 /* need to adjust the file name arguments and buffer names. */
8376 buflist_slash_adjust();
8377 alist_slash_adjust();
8378# ifdef FEAT_EVAL
8379 scriptnames_slash_adjust();
8380# endif
8381 }
8382#endif
8383
8384 /* If 'wrap' is set, set w_leftcol to zero. */
8385 else if ((int *)varp == &curwin->w_p_wrap)
8386 {
8387 if (curwin->w_p_wrap)
8388 curwin->w_leftcol = 0;
8389 }
8390
8391#ifdef FEAT_WINDOWS
8392 else if ((int *)varp == &p_ea)
8393 {
8394 if (p_ea && !old_value)
8395 win_equal(curwin, FALSE, 0);
8396 }
8397#endif
8398
8399 else if ((int *)varp == &p_wiv)
8400 {
8401 /*
8402 * When 'weirdinvert' changed, set/reset 't_xs'.
8403 * Then set 'weirdinvert' according to value of 't_xs'.
8404 */
8405 if (p_wiv && !old_value)
8406 T_XS = (char_u *)"y";
8407 else if (!p_wiv && old_value)
8408 T_XS = empty_option;
8409 p_wiv = (*T_XS != NUL);
8410 }
8411
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008412#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413 else if ((int *)varp == &p_beval)
8414 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008415 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008417 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418 gui_mch_disable_beval_area(balloonEval);
8419 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008420#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008422#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 else if ((int *)varp == &p_acd)
8424 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008425 /* Change directories when the 'acd' option is set now. */
8426 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008427 }
8428#endif
8429
8430#ifdef FEAT_DIFF
8431 /* 'diff' */
8432 else if ((int *)varp == &curwin->w_p_diff)
8433 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008434 /* May add or remove the buffer from the list of diff buffers. */
8435 diff_buf_adjust(curwin);
8436# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 if (foldmethodIsDiff(curwin))
8438 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008439# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 }
8441#endif
8442
8443#ifdef USE_IM_CONTROL
8444 /* 'imdisable' */
8445 else if ((int *)varp == &p_imdisable)
8446 {
8447 /* Only de-activate it here, it will be enabled when changing mode. */
8448 if (p_imdisable)
8449 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008450 else if (State & INSERT)
8451 /* When the option is set from an autocommand, it may need to take
8452 * effect right away. */
8453 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454 }
8455#endif
8456
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008457#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008458 /* 'spell' */
8459 else if ((int *)varp == &curwin->w_p_spell)
8460 {
8461 if (curwin->w_p_spell)
8462 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008463 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008464 if (errmsg != NULL)
8465 EMSG(_(errmsg));
8466 }
8467 }
8468#endif
8469
Bram Moolenaar071d4272004-06-13 20:20:40 +00008470#ifdef FEAT_FKMAP
8471 else if ((int *)varp == &p_altkeymap)
8472 {
8473 if (old_value != p_altkeymap)
8474 {
8475 if (!p_altkeymap)
8476 {
8477 p_hkmap = p_fkmap;
8478 p_fkmap = 0;
8479 }
8480 else
8481 {
8482 p_fkmap = p_hkmap;
8483 p_hkmap = 0;
8484 }
8485 (void)init_chartab();
8486 }
8487 }
8488
8489 /*
8490 * In case some second language keymapping options have changed, check
8491 * and correct the setting in a consistent way.
8492 */
8493
8494 /*
8495 * If hkmap or fkmap are set, reset Arabic keymapping.
8496 */
8497 if ((p_hkmap || p_fkmap) && p_altkeymap)
8498 {
8499 p_altkeymap = p_fkmap;
8500# ifdef FEAT_ARABIC
8501 curwin->w_p_arab = FALSE;
8502# endif
8503 (void)init_chartab();
8504 }
8505
8506 /*
8507 * If hkmap set, reset Farsi keymapping.
8508 */
8509 if (p_hkmap && p_altkeymap)
8510 {
8511 p_altkeymap = 0;
8512 p_fkmap = 0;
8513# ifdef FEAT_ARABIC
8514 curwin->w_p_arab = FALSE;
8515# endif
8516 (void)init_chartab();
8517 }
8518
8519 /*
8520 * If fkmap set, reset Hebrew keymapping.
8521 */
8522 if (p_fkmap && !p_altkeymap)
8523 {
8524 p_altkeymap = 1;
8525 p_hkmap = 0;
8526# ifdef FEAT_ARABIC
8527 curwin->w_p_arab = FALSE;
8528# endif
8529 (void)init_chartab();
8530 }
8531#endif
8532
8533#ifdef FEAT_ARABIC
8534 if ((int *)varp == &curwin->w_p_arab)
8535 {
8536 if (curwin->w_p_arab)
8537 {
8538 /*
8539 * 'arabic' is set, handle various sub-settings.
8540 */
8541 if (!p_tbidi)
8542 {
8543 /* set rightleft mode */
8544 if (!curwin->w_p_rl)
8545 {
8546 curwin->w_p_rl = TRUE;
8547 changed_window_setting();
8548 }
8549
8550 /* Enable Arabic shaping (major part of what Arabic requires) */
8551 if (!p_arshape)
8552 {
8553 p_arshape = TRUE;
8554 redraw_later_clear();
8555 }
8556 }
8557
8558 /* Arabic requires a utf-8 encoding, inform the user if its not
8559 * set. */
8560 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008561 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008562 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8563
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008564 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008565 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8566#ifdef FEAT_EVAL
8567 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8568#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570
8571# ifdef FEAT_MBYTE
8572 /* set 'delcombine' */
8573 p_deco = TRUE;
8574# endif
8575
8576# ifdef FEAT_KEYMAP
8577 /* Force-set the necessary keymap for arabic */
8578 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8579 OPT_LOCAL);
8580# endif
8581# ifdef FEAT_FKMAP
8582 p_altkeymap = 0;
8583 p_hkmap = 0;
8584 p_fkmap = 0;
8585 (void)init_chartab();
8586# endif
8587 }
8588 else
8589 {
8590 /*
8591 * 'arabic' is reset, handle various sub-settings.
8592 */
8593 if (!p_tbidi)
8594 {
8595 /* reset rightleft mode */
8596 if (curwin->w_p_rl)
8597 {
8598 curwin->w_p_rl = FALSE;
8599 changed_window_setting();
8600 }
8601
8602 /* 'arabicshape' isn't reset, it is a global option and
8603 * another window may still need it "on". */
8604 }
8605
8606 /* 'delcombine' isn't reset, it is a global option and another
8607 * window may still want it "on". */
8608
8609# ifdef FEAT_KEYMAP
8610 /* Revert to the default keymap */
8611 curbuf->b_p_iminsert = B_IMODE_NONE;
8612 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8613# endif
8614 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008615 }
8616
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008617#endif
8618
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008619#ifdef FEAT_TERMGUICOLORS
8620 /* 'termguicolors' */
8621 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008622 {
8623# ifdef FEAT_GUI
8624 if (!gui.in_use && !gui.starting)
8625# endif
8626 highlight_gui_started();
8627 }
8628#endif
8629
Bram Moolenaar071d4272004-06-13 20:20:40 +00008630 /*
8631 * End of handling side effects for bool options.
8632 */
8633
Bram Moolenaar53744302015-07-17 17:38:22 +02008634 /* after handling side effects, call autocommand */
8635
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636 options[opt_idx].flags |= P_WAS_SET;
8637
Bram Moolenaar53744302015-07-17 17:38:22 +02008638#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8639 if (!starting)
8640 {
8641 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008642 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8643 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8644 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008645 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8646 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8647 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8648 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8649 reset_v_option_vars();
8650 }
8651#endif
8652
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008654 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008655 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008656 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008657 check_redraw(options[opt_idx].flags);
8658
8659 return NULL;
8660}
8661
8662/*
8663 * Set the value of a number option, and take care of side effects.
8664 * Returns NULL for success, or an error message for an error.
8665 */
8666 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008667set_num_option(
8668 int opt_idx, /* index in options[] table */
8669 char_u *varp, /* pointer to the option variable */
8670 long value, /* new value */
8671 char_u *errbuf, /* buffer for error messages */
8672 size_t errbuflen, /* length of "errbuf" */
8673 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008674 OPT_MODELINE */
8675{
8676 char_u *errmsg = NULL;
8677 long old_value = *(long *)varp;
8678 long old_Rows = Rows; /* remember old Rows */
8679 long old_Columns = Columns; /* remember old Columns */
8680 long *pp = (long *)varp;
8681
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008682 /* Disallow changing some options from secure mode. */
8683 if ((secure
8684#ifdef HAVE_SANDBOX
8685 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008686#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008687 ) && (options[opt_idx].flags & P_SECURE))
8688 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689
8690 *pp = value;
8691#ifdef FEAT_EVAL
8692 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008693 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008694#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008695#ifdef FEAT_GUI
8696 need_mouse_correct = TRUE;
8697#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698
Bram Moolenaar14f24742012-08-08 18:01:05 +02008699 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008700 {
8701 errmsg = e_positive;
8702 curbuf->b_p_sw = curbuf->b_p_ts;
8703 }
8704
8705 /*
8706 * Number options that need some action when changed
8707 */
8708#ifdef FEAT_WINDOWS
8709 if (pp == &p_wh || pp == &p_hh)
8710 {
8711 if (p_wh < 1)
8712 {
8713 errmsg = e_positive;
8714 p_wh = 1;
8715 }
8716 if (p_wmh > p_wh)
8717 {
8718 errmsg = e_winheight;
8719 p_wh = p_wmh;
8720 }
8721 if (p_hh < 0)
8722 {
8723 errmsg = e_positive;
8724 p_hh = 0;
8725 }
8726
8727 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008728 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 {
8730 if (pp == &p_wh && curwin->w_height < p_wh)
8731 win_setheight((int)p_wh);
8732 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8733 win_setheight((int)p_hh);
8734 }
8735 }
8736
8737 /* 'winminheight' */
8738 else if (pp == &p_wmh)
8739 {
8740 if (p_wmh < 0)
8741 {
8742 errmsg = e_positive;
8743 p_wmh = 0;
8744 }
8745 if (p_wmh > p_wh)
8746 {
8747 errmsg = e_winheight;
8748 p_wmh = p_wh;
8749 }
8750 win_setminheight();
8751 }
8752
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008753# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008754 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 {
8756 if (p_wiw < 1)
8757 {
8758 errmsg = e_positive;
8759 p_wiw = 1;
8760 }
8761 if (p_wmw > p_wiw)
8762 {
8763 errmsg = e_winwidth;
8764 p_wiw = p_wmw;
8765 }
8766
8767 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008768 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008769 win_setwidth((int)p_wiw);
8770 }
8771
8772 /* 'winminwidth' */
8773 else if (pp == &p_wmw)
8774 {
8775 if (p_wmw < 0)
8776 {
8777 errmsg = e_positive;
8778 p_wmw = 0;
8779 }
8780 if (p_wmw > p_wiw)
8781 {
8782 errmsg = e_winwidth;
8783 p_wmw = p_wiw;
8784 }
8785 win_setminheight();
8786 }
8787# endif
8788
8789#endif
8790
8791#ifdef FEAT_WINDOWS
8792 /* (re)set last window status line */
8793 else if (pp == &p_ls)
8794 {
8795 last_status(FALSE);
8796 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008797
8798 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008799 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008800 {
8801 shell_new_rows(); /* recompute window positions and heights */
8802 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008803#endif
8804
8805#ifdef FEAT_GUI
8806 else if (pp == &p_linespace)
8807 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008808 /* Recompute gui.char_height and resize the Vim window to keep the
8809 * same number of lines. */
8810 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008811 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008812 }
8813#endif
8814
8815#ifdef FEAT_FOLDING
8816 /* 'foldlevel' */
8817 else if (pp == &curwin->w_p_fdl)
8818 {
8819 if (curwin->w_p_fdl < 0)
8820 curwin->w_p_fdl = 0;
8821 newFoldLevel();
8822 }
8823
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008824 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825 else if (pp == &curwin->w_p_fml)
8826 {
8827 foldUpdateAll(curwin);
8828 }
8829
8830 /* 'foldnestmax' */
8831 else if (pp == &curwin->w_p_fdn)
8832 {
8833 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8834 foldUpdateAll(curwin);
8835 }
8836
8837 /* 'foldcolumn' */
8838 else if (pp == &curwin->w_p_fdc)
8839 {
8840 if (curwin->w_p_fdc < 0)
8841 {
8842 errmsg = e_positive;
8843 curwin->w_p_fdc = 0;
8844 }
8845 else if (curwin->w_p_fdc > 12)
8846 {
8847 errmsg = e_invarg;
8848 curwin->w_p_fdc = 12;
8849 }
8850 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008851#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008853#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854 /* 'shiftwidth' or 'tabstop' */
8855 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8856 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008857# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 if (foldmethodIsIndent(curwin))
8859 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008860# endif
8861# ifdef FEAT_CINDENT
8862 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8863 * parse 'cinoptions'. */
8864 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8865 parse_cino(curbuf);
8866# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008870#ifdef FEAT_MBYTE
8871 /* 'maxcombine' */
8872 else if (pp == &p_mco)
8873 {
8874 if (p_mco > MAX_MCO)
8875 p_mco = MAX_MCO;
8876 else if (p_mco < 0)
8877 p_mco = 0;
8878 screenclear(); /* will re-allocate the screen */
8879 }
8880#endif
8881
Bram Moolenaar071d4272004-06-13 20:20:40 +00008882 else if (pp == &curbuf->b_p_iminsert)
8883 {
8884 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8885 {
8886 errmsg = e_invarg;
8887 curbuf->b_p_iminsert = B_IMODE_NONE;
8888 }
8889 p_iminsert = curbuf->b_p_iminsert;
8890 if (termcap_active) /* don't do this in the alternate screen */
8891 showmode();
8892#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8893 /* Show/unshow value of 'keymap' in status lines. */
8894 status_redraw_curbuf();
8895#endif
8896 }
8897
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008898 else if (pp == &p_window)
8899 {
8900 if (p_window < 1)
8901 p_window = 1;
8902 else if (p_window >= Rows)
8903 p_window = Rows - 1;
8904 }
8905
Bram Moolenaar071d4272004-06-13 20:20:40 +00008906 else if (pp == &curbuf->b_p_imsearch)
8907 {
8908 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8909 {
8910 errmsg = e_invarg;
8911 curbuf->b_p_imsearch = B_IMODE_NONE;
8912 }
8913 p_imsearch = curbuf->b_p_imsearch;
8914 }
8915
8916#ifdef FEAT_TITLE
8917 /* if 'titlelen' has changed, redraw the title */
8918 else if (pp == &p_titlelen)
8919 {
8920 if (p_titlelen < 0)
8921 {
8922 errmsg = e_positive;
8923 p_titlelen = 85;
8924 }
8925 if (starting != NO_SCREEN && old_value != p_titlelen)
8926 need_maketitle = TRUE;
8927 }
8928#endif
8929
8930 /* if p_ch changed value, change the command line height */
8931 else if (pp == &p_ch)
8932 {
8933 if (p_ch < 1)
8934 {
8935 errmsg = e_positive;
8936 p_ch = 1;
8937 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008938 if (p_ch > Rows - min_rows() + 1)
8939 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940
8941 /* Only compute the new window layout when startup has been
8942 * completed. Otherwise the frame sizes may be wrong. */
8943 if (p_ch != old_value && full_screen
8944#ifdef FEAT_GUI
8945 && !gui.starting
8946#endif
8947 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008948 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008949 }
8950
8951 /* when 'updatecount' changes from zero to non-zero, open swap files */
8952 else if (pp == &p_uc)
8953 {
8954 if (p_uc < 0)
8955 {
8956 errmsg = e_positive;
8957 p_uc = 100;
8958 }
8959 if (p_uc && !old_value)
8960 ml_open_files();
8961 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008962#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008963 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008964 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008965 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008966 {
8967 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008968 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008969 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008970 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008971 {
8972 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008973 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008974 }
8975 }
8976#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008977#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008978 else if (pp == &p_mzq)
8979 mzvim_reset_timer();
8980#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008981
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008982#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8983 /* 'pyxversion' */
8984 else if (pp == &p_pyx)
8985 {
8986 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8987 errmsg = e_invarg;
8988 }
8989#endif
8990
Bram Moolenaar071d4272004-06-13 20:20:40 +00008991 /* sync undo before 'undolevels' changes */
8992 else if (pp == &p_ul)
8993 {
8994 /* use the old value, otherwise u_sync() may not work properly */
8995 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008996 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008997 p_ul = value;
8998 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008999 else if (pp == &curbuf->b_p_ul)
9000 {
9001 /* use the old value, otherwise u_sync() may not work properly */
9002 curbuf->b_p_ul = old_value;
9003 u_sync(TRUE);
9004 curbuf->b_p_ul = value;
9005 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009006
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009007#ifdef FEAT_LINEBREAK
9008 /* 'numberwidth' must be positive */
9009 else if (pp == &curwin->w_p_nuw)
9010 {
9011 if (curwin->w_p_nuw < 1)
9012 {
9013 errmsg = e_positive;
9014 curwin->w_p_nuw = 1;
9015 }
9016 if (curwin->w_p_nuw > 10)
9017 {
9018 errmsg = e_invarg;
9019 curwin->w_p_nuw = 10;
9020 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009021 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009022 }
9023#endif
9024
Bram Moolenaar1a384422010-07-14 19:53:30 +02009025 else if (pp == &curbuf->b_p_tw)
9026 {
9027 if (curbuf->b_p_tw < 0)
9028 {
9029 errmsg = e_positive;
9030 curbuf->b_p_tw = 0;
9031 }
9032#ifdef FEAT_SYN_HL
9033# ifdef FEAT_WINDOWS
9034 {
9035 win_T *wp;
9036 tabpage_T *tp;
9037
9038 FOR_ALL_TAB_WINDOWS(tp, wp)
9039 check_colorcolumn(wp);
9040 }
9041# else
9042 check_colorcolumn(curwin);
9043# endif
9044#endif
9045 }
9046
Bram Moolenaar071d4272004-06-13 20:20:40 +00009047 /*
9048 * Check the bounds for numeric options here
9049 */
9050 if (Rows < min_rows() && full_screen)
9051 {
9052 if (errbuf != NULL)
9053 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009054 vim_snprintf((char *)errbuf, errbuflen,
9055 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056 errmsg = errbuf;
9057 }
9058 Rows = min_rows();
9059 }
9060 if (Columns < MIN_COLUMNS && full_screen)
9061 {
9062 if (errbuf != NULL)
9063 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009064 vim_snprintf((char *)errbuf, errbuflen,
9065 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066 errmsg = errbuf;
9067 }
9068 Columns = MIN_COLUMNS;
9069 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009070 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009071
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072 /*
9073 * If the screen (shell) height has been changed, assume it is the
9074 * physical screenheight.
9075 */
9076 if (old_Rows != Rows || old_Columns != Columns)
9077 {
9078 /* Changing the screen size is not allowed while updating the screen. */
9079 if (updating_screen)
9080 *pp = old_value;
9081 else if (full_screen
9082#ifdef FEAT_GUI
9083 && !gui.starting
9084#endif
9085 )
9086 set_shellsize((int)Columns, (int)Rows, TRUE);
9087 else
9088 {
9089 /* Postpone the resizing; check the size and cmdline position for
9090 * messages. */
9091 check_shellsize();
9092 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9093 cmdline_row = Rows - p_ch;
9094 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009095 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009096 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097 }
9098
Bram Moolenaar071d4272004-06-13 20:20:40 +00009099 if (curbuf->b_p_ts <= 0)
9100 {
9101 errmsg = e_positive;
9102 curbuf->b_p_ts = 8;
9103 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009104 if (p_tm < 0)
9105 {
9106 errmsg = e_positive;
9107 p_tm = 0;
9108 }
9109 if ((curwin->w_p_scr <= 0
9110 || (curwin->w_p_scr > curwin->w_height
9111 && curwin->w_height > 0))
9112 && full_screen)
9113 {
9114 if (pp == &(curwin->w_p_scr))
9115 {
9116 if (curwin->w_p_scr != 0)
9117 errmsg = e_scroll;
9118 win_comp_scroll(curwin);
9119 }
9120 /* If 'scroll' became invalid because of a side effect silently adjust
9121 * it. */
9122 else if (curwin->w_p_scr <= 0)
9123 curwin->w_p_scr = 1;
9124 else /* curwin->w_p_scr > curwin->w_height */
9125 curwin->w_p_scr = curwin->w_height;
9126 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009127 if (p_hi < 0)
9128 {
9129 errmsg = e_positive;
9130 p_hi = 0;
9131 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009132 else if (p_hi > 10000)
9133 {
9134 errmsg = e_invarg;
9135 p_hi = 10000;
9136 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009137 if (p_re < 0 || p_re > 2)
9138 {
9139 errmsg = e_invarg;
9140 p_re = 0;
9141 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 if (p_report < 0)
9143 {
9144 errmsg = e_positive;
9145 p_report = 1;
9146 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009147 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 {
9149 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9150 p_sj = Rows / 2;
9151 else
9152 {
9153 errmsg = e_scroll;
9154 p_sj = 1;
9155 }
9156 }
9157 if (p_so < 0 && full_screen)
9158 {
9159 errmsg = e_scroll;
9160 p_so = 0;
9161 }
9162 if (p_siso < 0 && full_screen)
9163 {
9164 errmsg = e_positive;
9165 p_siso = 0;
9166 }
9167#ifdef FEAT_CMDWIN
9168 if (p_cwh < 1)
9169 {
9170 errmsg = e_positive;
9171 p_cwh = 1;
9172 }
9173#endif
9174 if (p_ut < 0)
9175 {
9176 errmsg = e_positive;
9177 p_ut = 2000;
9178 }
9179 if (p_ss < 0)
9180 {
9181 errmsg = e_positive;
9182 p_ss = 0;
9183 }
9184
9185 /* May set global value for local option. */
9186 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9187 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9188
9189 options[opt_idx].flags |= P_WAS_SET;
9190
Bram Moolenaar53744302015-07-17 17:38:22 +02009191#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9192 if (!starting && errmsg == NULL)
9193 {
9194 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009195 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9196 vim_snprintf((char *)buf_new, 10, "%ld", value);
9197 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009198 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9199 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9200 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9201 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9202 reset_v_option_vars();
9203 }
9204#endif
9205
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009207 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009208 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009209 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009210 check_redraw(options[opt_idx].flags);
9211
9212 return errmsg;
9213}
9214
9215/*
9216 * Called after an option changed: check if something needs to be redrawn.
9217 */
9218 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009219check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009220{
9221 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009222 int doclear = (flags & P_RCLR) == P_RCLR;
9223 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224
9225#ifdef FEAT_WINDOWS
9226 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9227 status_redraw_all();
9228#endif
9229
9230 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9231 changed_window_setting();
9232 if (flags & P_RBUF)
9233 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009234 if (flags & P_RWINONLY)
9235 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009236 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237 redraw_all_later(CLEAR);
9238 else if (all)
9239 redraw_all_later(NOT_VALID);
9240}
9241
9242/*
9243 * Find index for option 'arg'.
9244 * Return -1 if not found.
9245 */
9246 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009247findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009248{
9249 int opt_idx;
9250 char *s, *p;
9251 static short quick_tab[27] = {0, 0}; /* quick access table */
9252 int is_term_opt;
9253
9254 /*
9255 * For first call: Initialize the quick-access table.
9256 * It contains the index for the first option that starts with a certain
9257 * letter. There are 26 letters, plus the first "t_" option.
9258 */
9259 if (quick_tab[1] == 0)
9260 {
9261 p = options[0].fullname;
9262 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9263 {
9264 if (s[0] != p[0])
9265 {
9266 if (s[0] == 't' && s[1] == '_')
9267 quick_tab[26] = opt_idx;
9268 else
9269 quick_tab[CharOrdLow(s[0])] = opt_idx;
9270 }
9271 p = s;
9272 }
9273 }
9274
9275 /*
9276 * Check for name starting with an illegal character.
9277 */
9278#ifdef EBCDIC
9279 if (!islower(arg[0]))
9280#else
9281 if (arg[0] < 'a' || arg[0] > 'z')
9282#endif
9283 return -1;
9284
9285 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9286 if (is_term_opt)
9287 opt_idx = quick_tab[26];
9288 else
9289 opt_idx = quick_tab[CharOrdLow(arg[0])];
9290 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9291 {
9292 if (STRCMP(arg, s) == 0) /* match full name */
9293 break;
9294 }
9295 if (s == NULL && !is_term_opt)
9296 {
9297 opt_idx = quick_tab[CharOrdLow(arg[0])];
9298 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9299 {
9300 s = options[opt_idx].shortname;
9301 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9302 break;
9303 s = NULL;
9304 }
9305 }
9306 if (s == NULL)
9307 opt_idx = -1;
9308 return opt_idx;
9309}
9310
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009311#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312/*
9313 * Get the value for an option.
9314 *
9315 * Returns:
9316 * Number or Toggle option: 1, *numval gets value.
9317 * String option: 0, *stringval gets allocated string.
9318 * Hidden Number or Toggle option: -1.
9319 * hidden String option: -2.
9320 * unknown option: -3.
9321 */
9322 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009323get_option_value(
9324 char_u *name,
9325 long *numval,
9326 char_u **stringval, /* NULL when only checking existence */
9327 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328{
9329 int opt_idx;
9330 char_u *varp;
9331
9332 opt_idx = findoption(name);
9333 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009334 {
9335 int key;
9336
9337 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9338 && (key = find_key_option(name)) != 0)
9339 {
9340 char_u key_name[2];
9341 char_u *p;
9342
9343 if (key < 0)
9344 {
9345 key_name[0] = KEY2TERMCAP0(key);
9346 key_name[1] = KEY2TERMCAP1(key);
9347 }
9348 else
9349 {
9350 key_name[0] = KS_KEY;
9351 key_name[1] = (key & 0xff);
9352 }
9353 p = find_termcode(key_name);
9354 if (p != NULL)
9355 {
9356 if (stringval != NULL)
9357 *stringval = vim_strsave(p);
9358 return 0;
9359 }
9360 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009363
9364 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9365
9366 if (options[opt_idx].flags & P_STRING)
9367 {
9368 if (varp == NULL) /* hidden option */
9369 return -2;
9370 if (stringval != NULL)
9371 {
9372#ifdef FEAT_CRYPT
9373 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009374 if ((char_u **)varp == &curbuf->b_p_key
9375 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376 *stringval = vim_strsave((char_u *)"*****");
9377 else
9378#endif
9379 *stringval = vim_strsave(*(char_u **)(varp));
9380 }
9381 return 0;
9382 }
9383
9384 if (varp == NULL) /* hidden option */
9385 return -1;
9386 if (options[opt_idx].flags & P_NUM)
9387 *numval = *(long *)varp;
9388 else
9389 {
9390 /* Special case: 'modified' is b_changed, but we also want to consider
9391 * it set when 'ff' or 'fenc' changed. */
9392 if ((int *)varp == &curbuf->b_changed)
9393 *numval = curbufIsChanged();
9394 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009395 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396 }
9397 return 1;
9398}
9399#endif
9400
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009401#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009402/*
9403 * Returns the option attributes and its value. Unlike the above function it
9404 * will return either global value or local value of the option depending on
9405 * what was requested, but it will never return global value if it was
9406 * requested to return local one and vice versa. Neither it will return
9407 * buffer-local value if it was requested to return window-local one.
9408 *
9409 * Pretends that option is absent if it is not present in the requested scope
9410 * (i.e. has no global, window-local or buffer-local value depending on
9411 * opt_type). Uses
9412 *
9413 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009414 * 0 hidden or unknown option, also option that does not have requested
9415 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009416 * see SOPT_* in vim.h for other flags
9417 *
9418 * Possible opt_type values: see SREQ_* in vim.h
9419 */
9420 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009421get_option_value_strict(
9422 char_u *name,
9423 long *numval,
9424 char_u **stringval, /* NULL when only obtaining attributes */
9425 int opt_type,
9426 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009427{
9428 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009429 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009430 struct vimoption *p;
9431 int r = 0;
9432
9433 opt_idx = findoption(name);
9434 if (opt_idx < 0)
9435 return 0;
9436
9437 p = &(options[opt_idx]);
9438
9439 /* Hidden option */
9440 if (p->var == NULL)
9441 return 0;
9442
9443 if (p->flags & P_BOOL)
9444 r |= SOPT_BOOL;
9445 else if (p->flags & P_NUM)
9446 r |= SOPT_NUM;
9447 else if (p->flags & P_STRING)
9448 r |= SOPT_STRING;
9449
9450 if (p->indir == PV_NONE)
9451 {
9452 if (opt_type == SREQ_GLOBAL)
9453 r |= SOPT_GLOBAL;
9454 else
9455 return 0; /* Did not request global-only option */
9456 }
9457 else
9458 {
9459 if (p->indir & PV_BOTH)
9460 r |= SOPT_GLOBAL;
9461 else if (opt_type == SREQ_GLOBAL)
9462 return 0; /* Requested global option */
9463
9464 if (p->indir & PV_WIN)
9465 {
9466 if (opt_type == SREQ_BUF)
9467 return 0; /* Did not request window-local option */
9468 else
9469 r |= SOPT_WIN;
9470 }
9471 else if (p->indir & PV_BUF)
9472 {
9473 if (opt_type == SREQ_WIN)
9474 return 0; /* Did not request buffer-local option */
9475 else
9476 r |= SOPT_BUF;
9477 }
9478 }
9479
9480 if (stringval == NULL)
9481 return r;
9482
9483 if (opt_type == SREQ_GLOBAL)
9484 varp = p->var;
9485 else
9486 {
9487 if (opt_type == SREQ_BUF)
9488 {
9489 /* Special case: 'modified' is b_changed, but we also want to
9490 * consider it set when 'ff' or 'fenc' changed. */
9491 if (p->indir == PV_MOD)
9492 {
9493 *numval = bufIsChanged((buf_T *) from);
9494 varp = NULL;
9495 }
9496#ifdef FEAT_CRYPT
9497 else if (p->indir == PV_KEY)
9498 {
9499 /* never return the value of the crypt key */
9500 *stringval = NULL;
9501 varp = NULL;
9502 }
9503#endif
9504 else
9505 {
9506 aco_save_T aco;
9507 aucmd_prepbuf(&aco, (buf_T *) from);
9508 varp = get_varp(p);
9509 aucmd_restbuf(&aco);
9510 }
9511 }
9512 else if (opt_type == SREQ_WIN)
9513 {
9514 win_T *save_curwin;
9515 save_curwin = curwin;
9516 curwin = (win_T *) from;
9517 curbuf = curwin->w_buffer;
9518 varp = get_varp(p);
9519 curwin = save_curwin;
9520 curbuf = curwin->w_buffer;
9521 }
9522 if (varp == p->var)
9523 return (r | SOPT_UNSET);
9524 }
9525
9526 if (varp != NULL)
9527 {
9528 if (p->flags & P_STRING)
9529 *stringval = vim_strsave(*(char_u **)(varp));
9530 else if (p->flags & P_NUM)
9531 *numval = *(long *) varp;
9532 else
9533 *numval = *(int *)varp;
9534 }
9535
9536 return r;
9537}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009538
9539/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009540 * Iterate over options. First argument is a pointer to a pointer to a
9541 * structure inside options[] array, second is option type like in the above
9542 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009543 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009544 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009545 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009546 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009547 * first argument to NULL.
9548 *
9549 * Returns full option name for current option on each call.
9550 */
9551 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009552option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009553{
9554 struct vimoption *ret = NULL;
9555 do
9556 {
9557 if (*option == NULL)
9558 *option = (void *) options;
9559 else if (((struct vimoption *) (*option))->fullname == NULL)
9560 {
9561 *option = NULL;
9562 return NULL;
9563 }
9564 else
9565 *option = (void *) (((struct vimoption *) (*option)) + 1);
9566
9567 ret = ((struct vimoption *) (*option));
9568
9569 /* Hidden option */
9570 if (ret->var == NULL)
9571 {
9572 ret = NULL;
9573 continue;
9574 }
9575
9576 switch (opt_type)
9577 {
9578 case SREQ_GLOBAL:
9579 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9580 ret = NULL;
9581 break;
9582 case SREQ_BUF:
9583 if (!(ret->indir & PV_BUF))
9584 ret = NULL;
9585 break;
9586 case SREQ_WIN:
9587 if (!(ret->indir & PV_WIN))
9588 ret = NULL;
9589 break;
9590 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009591 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009592 return NULL;
9593 }
9594 }
9595 while (ret == NULL);
9596
9597 return (char_u *)ret->fullname;
9598}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009599#endif
9600
Bram Moolenaar071d4272004-06-13 20:20:40 +00009601/*
9602 * Set the value of option "name".
9603 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009604 *
9605 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009606 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009607 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009608set_option_value(
9609 char_u *name,
9610 long number,
9611 char_u *string,
9612 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009613{
9614 int opt_idx;
9615 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009616 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009617
9618 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009619 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009620 {
9621 int key;
9622
9623 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9624 && (key = find_key_option(name)) != 0)
9625 {
9626 char_u key_name[2];
9627
9628 if (key < 0)
9629 {
9630 key_name[0] = KEY2TERMCAP0(key);
9631 key_name[1] = KEY2TERMCAP1(key);
9632 }
9633 else
9634 {
9635 key_name[0] = KS_KEY;
9636 key_name[1] = (key & 0xff);
9637 }
9638 add_termcode(key_name, string, FALSE);
9639 if (full_screen)
9640 ttest(FALSE);
9641 redraw_all_later(CLEAR);
9642 return NULL;
9643 }
9644
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009646 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009647 else
9648 {
9649 flags = options[opt_idx].flags;
9650#ifdef HAVE_SANDBOX
9651 /* Disallow changing some options in the sandbox */
9652 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009653 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009655 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009656 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009658 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009659 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660 else
9661 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009662 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009663 if (varp != NULL) /* hidden option is not changed */
9664 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009665 if (number == 0 && string != NULL)
9666 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009667 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009668
9669 /* Either we are given a string or we are setting option
9670 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009671 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009672 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009673 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009674 {
9675 /* There's another character after zeros or the string
9676 * is empty. In both cases, we are trying to set a
9677 * num option using a string. */
9678 EMSG3(_("E521: Number required: &%s = '%s'"),
9679 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009680 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009681
9682 }
9683 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009684 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009685 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009686 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009687 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009688 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009689 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690 }
9691 }
9692 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009693 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694}
9695
9696/*
9697 * Get the terminal code for a terminal option.
9698 * Returns NULL when not found.
9699 */
9700 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009701get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009702{
9703 int opt_idx;
9704 char_u *varp;
9705
9706 if (tname[0] != 't' || tname[1] != '_' ||
9707 tname[2] == NUL || tname[3] == NUL)
9708 return NULL;
9709 if ((opt_idx = findoption(tname)) >= 0)
9710 {
9711 varp = get_varp(&(options[opt_idx]));
9712 if (varp != NULL)
9713 varp = *(char_u **)(varp);
9714 return varp;
9715 }
9716 return find_termcode(tname + 2);
9717}
9718
9719 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009720get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721{
9722 int i;
9723
9724 i = findoption((char_u *)"hl");
9725 if (i >= 0)
9726 return options[i].def_val[VI_DEFAULT];
9727 return (char_u *)NULL;
9728}
9729
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009730#if defined(FEAT_MBYTE) || defined(PROTO)
9731 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009732get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009733{
9734 int i;
9735
9736 i = findoption((char_u *)"enc");
9737 if (i >= 0)
9738 return options[i].def_val[VI_DEFAULT];
9739 return (char_u *)NULL;
9740}
9741#endif
9742
Bram Moolenaar071d4272004-06-13 20:20:40 +00009743/*
9744 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9745 */
9746 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009747find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009748{
9749 int key;
9750 int modifiers;
9751
9752 /*
9753 * Don't use get_special_key_code() for t_xx, we don't want it to call
9754 * add_termcap_entry().
9755 */
9756 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9757 key = TERMCAP2KEY(arg[2], arg[3]);
9758 else
9759 {
9760 --arg; /* put arg at the '<' */
9761 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009762 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009763 if (modifiers) /* can't handle modifiers here */
9764 key = 0;
9765 }
9766 return key;
9767}
9768
9769/*
9770 * if 'all' == 0: show changed options
9771 * if 'all' == 1: show all normal options
9772 * if 'all' == 2: show all terminal options
9773 */
9774 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009775showoptions(
9776 int all,
9777 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009778{
9779 struct vimoption *p;
9780 int col;
9781 int isterm;
9782 char_u *varp;
9783 struct vimoption **items;
9784 int item_count;
9785 int run;
9786 int row, rows;
9787 int cols;
9788 int i;
9789 int len;
9790
9791#define INC 20
9792#define GAP 3
9793
9794 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9795 PARAM_COUNT));
9796 if (items == NULL)
9797 return;
9798
9799 /* Highlight title */
9800 if (all == 2)
9801 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9802 else if (opt_flags & OPT_GLOBAL)
9803 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9804 else if (opt_flags & OPT_LOCAL)
9805 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9806 else
9807 MSG_PUTS_TITLE(_("\n--- Options ---"));
9808
9809 /*
9810 * do the loop two times:
9811 * 1. display the short items
9812 * 2. display the long items (only strings and numbers)
9813 */
9814 for (run = 1; run <= 2 && !got_int; ++run)
9815 {
9816 /*
9817 * collect the items in items[]
9818 */
9819 item_count = 0;
9820 for (p = &options[0]; p->fullname != NULL; p++)
9821 {
9822 varp = NULL;
9823 isterm = istermoption(p);
9824 if (opt_flags != 0)
9825 {
9826 if (p->indir != PV_NONE && !isterm)
9827 varp = get_varp_scope(p, opt_flags);
9828 }
9829 else
9830 varp = get_varp(p);
9831 if (varp != NULL
9832 && ((all == 2 && isterm)
9833 || (all == 1 && !isterm)
9834 || (all == 0 && !optval_default(p, varp))))
9835 {
9836 if (p->flags & P_BOOL)
9837 len = 1; /* a toggle option fits always */
9838 else
9839 {
9840 option_value2string(p, opt_flags);
9841 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9842 }
9843 if ((len <= INC - GAP && run == 1) ||
9844 (len > INC - GAP && run == 2))
9845 items[item_count++] = p;
9846 }
9847 }
9848
9849 /*
9850 * display the items
9851 */
9852 if (run == 1)
9853 {
9854 cols = (Columns + GAP - 3) / INC;
9855 if (cols == 0)
9856 cols = 1;
9857 rows = (item_count + cols - 1) / cols;
9858 }
9859 else /* run == 2 */
9860 rows = item_count;
9861 for (row = 0; row < rows && !got_int; ++row)
9862 {
9863 msg_putchar('\n'); /* go to next line */
9864 if (got_int) /* 'q' typed in more */
9865 break;
9866 col = 0;
9867 for (i = row; i < item_count; i += rows)
9868 {
9869 msg_col = col; /* make columns */
9870 showoneopt(items[i], opt_flags);
9871 col += INC;
9872 }
9873 out_flush();
9874 ui_breakcheck();
9875 }
9876 }
9877 vim_free(items);
9878}
9879
9880/*
9881 * Return TRUE if option "p" has its default value.
9882 */
9883 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009884optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009885{
9886 int dvi;
9887
9888 if (varp == NULL)
9889 return TRUE; /* hidden option is always at default */
9890 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9891 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009892 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009893 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009894 /* the cast to long is required for Manx C, long_i is
9895 * needed for MSVC */
9896 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009897 /* P_STRING */
9898 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9899}
9900
9901/*
9902 * showoneopt: show the value of one option
9903 * must not be called with a hidden option!
9904 */
9905 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009906showoneopt(
9907 struct vimoption *p,
9908 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009910 char_u *varp;
9911 int save_silent = silent_mode;
9912
9913 silent_mode = FALSE;
9914 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915
9916 varp = get_varp_scope(p, opt_flags);
9917
9918 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9919 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9920 ? !curbufIsChanged() : !*(int *)varp))
9921 MSG_PUTS("no");
9922 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9923 MSG_PUTS("--");
9924 else
9925 MSG_PUTS(" ");
9926 MSG_PUTS(p->fullname);
9927 if (!(p->flags & P_BOOL))
9928 {
9929 msg_putchar('=');
9930 /* put value string in NameBuff */
9931 option_value2string(p, opt_flags);
9932 msg_outtrans(NameBuff);
9933 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009934
9935 silent_mode = save_silent;
9936 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009937}
9938
9939/*
9940 * Write modified options as ":set" commands to a file.
9941 *
9942 * There are three values for "opt_flags":
9943 * OPT_GLOBAL: Write global option values and fresh values of
9944 * buffer-local options (used for start of a session
9945 * file).
9946 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9947 * curwin (used for a vimrc file).
9948 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9949 * and local values for window-local options of
9950 * curwin. Local values are also written when at the
9951 * default value, because a modeline or autocommand
9952 * may have set them when doing ":edit file" and the
9953 * user has set them back at the default or fresh
9954 * value.
9955 * When "local_only" is TRUE, don't write fresh
9956 * values, only local values (for ":mkview").
9957 * (fresh value = value used for a new buffer or window for a local option).
9958 *
9959 * Return FAIL on error, OK otherwise.
9960 */
9961 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009962makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009963{
9964 struct vimoption *p;
9965 char_u *varp; /* currently used value */
9966 char_u *varp_fresh; /* local value */
9967 char_u *varp_local = NULL; /* fresh value */
9968 char *cmd;
9969 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009970 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009971
9972 /*
9973 * The options that don't have a default (terminal name, columns, lines)
9974 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009975 * Do the loop over "options[]" twice: once for options with the
9976 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009978 for (pri = 1; pri >= 0; --pri)
9979 {
9980 for (p = &options[0]; !istermoption(p); p++)
9981 if (!(p->flags & P_NO_MKRC)
9982 && !istermoption(p)
9983 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984 {
9985 /* skip global option when only doing locals */
9986 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9987 continue;
9988
9989 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9990 * file, they are always buffer-specific. */
9991 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9992 continue;
9993
9994 /* Global values are only written when not at the default value. */
9995 varp = get_varp_scope(p, opt_flags);
9996 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9997 continue;
9998
9999 round = 2;
10000 if (p->indir != PV_NONE)
10001 {
10002 if (p->var == VAR_WIN)
10003 {
10004 /* skip window-local option when only doing globals */
10005 if (!(opt_flags & OPT_LOCAL))
10006 continue;
10007 /* When fresh value of window-local option is not at the
10008 * default, need to write it too. */
10009 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10010 {
10011 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10012 if (!optval_default(p, varp_fresh))
10013 {
10014 round = 1;
10015 varp_local = varp;
10016 varp = varp_fresh;
10017 }
10018 }
10019 }
10020 }
10021
10022 /* Round 1: fresh value for window-local options.
10023 * Round 2: other values */
10024 for ( ; round <= 2; varp = varp_local, ++round)
10025 {
10026 if (round == 1 || (opt_flags & OPT_GLOBAL))
10027 cmd = "set";
10028 else
10029 cmd = "setlocal";
10030
10031 if (p->flags & P_BOOL)
10032 {
10033 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10034 return FAIL;
10035 }
10036 else if (p->flags & P_NUM)
10037 {
10038 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10039 return FAIL;
10040 }
10041 else /* P_STRING */
10042 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010043#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10044 int do_endif = FALSE;
10045
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046 /* Don't set 'syntax' and 'filetype' again if the value is
10047 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010048 if (
10049# if defined(FEAT_SYN_HL)
10050 p->indir == PV_SYN
10051# if defined(FEAT_AUTOCMD)
10052 ||
10053# endif
10054# endif
10055# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010056 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010057# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010058 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010059 {
10060 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10061 *(char_u **)(varp)) < 0
10062 || put_eol(fd) < 0)
10063 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010064 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010065 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010067 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10068 (p->flags & P_EXPAND) != 0) == FAIL)
10069 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010070#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10071 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072 {
10073 if (put_line(fd, "endif") == FAIL)
10074 return FAIL;
10075 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010076#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010077 }
10078 }
10079 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010081 return OK;
10082}
10083
10084#if defined(FEAT_FOLDING) || defined(PROTO)
10085/*
10086 * Generate set commands for the local fold options only. Used when
10087 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10088 */
10089 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010090makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010091{
10092 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10093# ifdef FEAT_EVAL
10094 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10095 == FAIL
10096# endif
10097 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10098 == FAIL
10099 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10100 == FAIL
10101 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10102 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10103 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10104 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10105 )
10106 return FAIL;
10107
10108 return OK;
10109}
10110#endif
10111
10112 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010113put_setstring(
10114 FILE *fd,
10115 char *cmd,
10116 char *name,
10117 char_u **valuep,
10118 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119{
10120 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010121 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010122
10123 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10124 return FAIL;
10125 if (*valuep != NULL)
10126 {
10127 /* Output 'pastetoggle' as key names. For other
10128 * options some characters have to be escaped with
10129 * CTRL-V or backslash */
10130 if (valuep == &p_pt)
10131 {
10132 s = *valuep;
10133 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010134 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010135 return FAIL;
10136 }
10137 else if (expand)
10138 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010139 buf = alloc(MAXPATHL);
10140 if (buf == NULL)
10141 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010142 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10143 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010144 {
10145 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010147 }
10148 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149 }
10150 else if (put_escstr(fd, *valuep, 2) == FAIL)
10151 return FAIL;
10152 }
10153 if (put_eol(fd) < 0)
10154 return FAIL;
10155 return OK;
10156}
10157
10158 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010159put_setnum(
10160 FILE *fd,
10161 char *cmd,
10162 char *name,
10163 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164{
10165 long wc;
10166
10167 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10168 return FAIL;
10169 if (wc_use_keyname((char_u *)valuep, &wc))
10170 {
10171 /* print 'wildchar' and 'wildcharm' as a key name */
10172 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10173 return FAIL;
10174 }
10175 else if (fprintf(fd, "%ld", *valuep) < 0)
10176 return FAIL;
10177 if (put_eol(fd) < 0)
10178 return FAIL;
10179 return OK;
10180}
10181
10182 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010183put_setbool(
10184 FILE *fd,
10185 char *cmd,
10186 char *name,
10187 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188{
Bram Moolenaar893de922007-10-02 18:40:57 +000010189 if (value < 0) /* global/local option using global value */
10190 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10192 || put_eol(fd) < 0)
10193 return FAIL;
10194 return OK;
10195}
10196
10197/*
10198 * Clear all the terminal options.
10199 * If the option has been allocated, free the memory.
10200 * Terminal options are never hidden or indirect.
10201 */
10202 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010203clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205 /*
10206 * Reset a few things before clearing the old options. This may cause
10207 * outputting a few things that the terminal doesn't understand, but the
10208 * screen will be cleared later, so this is OK.
10209 */
10210#ifdef FEAT_MOUSE_TTY
10211 mch_setmouse(FALSE); /* switch mouse off */
10212#endif
10213#ifdef FEAT_TITLE
10214 mch_restore_title(3); /* restore window titles */
10215#endif
10216#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10217 /* When starting the GUI close the display opened for the clipboard.
10218 * After restoring the title, because that will need the display. */
10219 if (gui.starting)
10220 clear_xterm_clip();
10221#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010222 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010223
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010224 free_termoptions();
10225}
10226
10227 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010228free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010229{
10230 struct vimoption *p;
10231
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232 for (p = &options[0]; p->fullname != NULL; p++)
10233 if (istermoption(p))
10234 {
10235 if (p->flags & P_ALLOCED)
10236 free_string_option(*(char_u **)(p->var));
10237 if (p->flags & P_DEF_ALLOCED)
10238 free_string_option(p->def_val[VI_DEFAULT]);
10239 *(char_u **)(p->var) = empty_option;
10240 p->def_val[VI_DEFAULT] = empty_option;
10241 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10242 }
10243 clear_termcodes();
10244}
10245
10246/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010247 * Free the string for one term option, if it was allocated.
10248 * Set the string to empty_option and clear allocated flag.
10249 * "var" points to the option value.
10250 */
10251 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010252free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010253{
10254 struct vimoption *p;
10255
10256 for (p = &options[0]; p->fullname != NULL; p++)
10257 if (p->var == var)
10258 {
10259 if (p->flags & P_ALLOCED)
10260 free_string_option(*(char_u **)(p->var));
10261 *(char_u **)(p->var) = empty_option;
10262 p->flags &= ~P_ALLOCED;
10263 break;
10264 }
10265}
10266
10267/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268 * Set the terminal option defaults to the current value.
10269 * Used after setting the terminal name.
10270 */
10271 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010272set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273{
10274 struct vimoption *p;
10275
10276 for (p = &options[0]; p->fullname != NULL; p++)
10277 {
10278 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10279 {
10280 if (p->flags & P_DEF_ALLOCED)
10281 {
10282 free_string_option(p->def_val[VI_DEFAULT]);
10283 p->flags &= ~P_DEF_ALLOCED;
10284 }
10285 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10286 if (p->flags & P_ALLOCED)
10287 {
10288 p->flags |= P_DEF_ALLOCED;
10289 p->flags &= ~P_ALLOCED; /* don't free the value now */
10290 }
10291 }
10292 }
10293}
10294
10295/*
10296 * return TRUE if 'p' starts with 't_'
10297 */
10298 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010299istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300{
10301 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10302}
10303
10304/*
10305 * Compute columns for ruler and shown command. 'sc_col' is also used to
10306 * decide what the maximum length of a message on the status line can be.
10307 * If there is a status line for the last window, 'sc_col' is independent
10308 * of 'ru_col'.
10309 */
10310
10311#define COL_RULER 17 /* columns needed by standard ruler */
10312
10313 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010314comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315{
10316#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010317 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318
10319 sc_col = 0;
10320 ru_col = 0;
10321 if (p_ru)
10322 {
10323#ifdef FEAT_STL_OPT
10324 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10325#else
10326 ru_col = COL_RULER + 1;
10327#endif
10328 /* no last status line, adjust sc_col */
10329 if (!last_has_status)
10330 sc_col = ru_col;
10331 }
10332 if (p_sc)
10333 {
10334 sc_col += SHOWCMD_COLS;
10335 if (!p_ru || last_has_status) /* no need for separating space */
10336 ++sc_col;
10337 }
10338 sc_col = Columns - sc_col;
10339 ru_col = Columns - ru_col;
10340 if (sc_col <= 0) /* screen too narrow, will become a mess */
10341 sc_col = 1;
10342 if (ru_col <= 0)
10343 ru_col = 1;
10344#else
10345 sc_col = Columns;
10346 ru_col = Columns;
10347#endif
10348}
10349
10350/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010351 * Unset local option value, similar to ":set opt<".
10352 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010353 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010354unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010355{
10356 struct vimoption *p;
10357 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010358 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010359
10360 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010361 if (opt_idx < 0)
10362 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010363 p = &(options[opt_idx]);
10364
10365 switch ((int)p->indir)
10366 {
10367 /* global option with local value: use local value if it's been set */
10368 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010369 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010370 break;
10371 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010372 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010373 break;
10374 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010375 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010376 break;
10377 case PV_AR:
10378 buf->b_p_ar = -1;
10379 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010380 case PV_BKC:
10381 clear_string_option(&buf->b_p_bkc);
10382 buf->b_bkc_flags = 0;
10383 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010384 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010385 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010386 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010387 case PV_TC:
10388 clear_string_option(&buf->b_p_tc);
10389 buf->b_tc_flags = 0;
10390 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010391#ifdef FEAT_FIND_ID
10392 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010393 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010394 break;
10395 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010396 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010397 break;
10398#endif
10399#ifdef FEAT_INS_EXPAND
10400 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010401 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010402 break;
10403 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010404 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010405 break;
10406#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010407 case PV_FP:
10408 clear_string_option(&buf->b_p_fp);
10409 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010410#ifdef FEAT_QUICKFIX
10411 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010412 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413 break;
10414 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010415 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010416 break;
10417 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010418 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010419 break;
10420#endif
10421#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10422 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010423 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010424 break;
10425#endif
10426#if defined(FEAT_CRYPT)
10427 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010428 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010429 break;
10430#endif
10431#ifdef FEAT_STL_OPT
10432 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010433 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434 break;
10435#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010436 case PV_UL:
10437 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10438 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010439#ifdef FEAT_LISP
10440 case PV_LW:
10441 clear_string_option(&buf->b_p_lw);
10442 break;
10443#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010444#ifdef FEAT_MBYTE
10445 case PV_MENC:
10446 clear_string_option(&buf->b_p_menc);
10447 break;
10448#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010449 }
10450}
10451
10452/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010453 * Get pointer to option variable, depending on local or global scope.
10454 */
10455 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010456get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010457{
10458 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10459 {
10460 if (p->var == VAR_WIN)
10461 return (char_u *)GLOBAL_WO(get_varp(p));
10462 return p->var;
10463 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010464 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010465 {
10466 switch ((int)p->indir)
10467 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010468 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010470 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10471 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10472 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010473#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010474 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10475 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10476 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010477 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010478 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010479 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010481 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10482 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483#endif
10484#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010485 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10486 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010488#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10489 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10490#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010491#if defined(FEAT_CRYPT)
10492 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10493#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010494#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010495 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010496#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010497 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010498#ifdef FEAT_LISP
10499 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10500#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010501 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010502#ifdef FEAT_MBYTE
10503 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10504#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010505 }
10506 return NULL; /* "cannot happen" */
10507 }
10508 return get_varp(p);
10509}
10510
10511/*
10512 * Get pointer to option variable.
10513 */
10514 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010515get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516{
10517 /* hidden option, always return NULL */
10518 if (p->var == NULL)
10519 return NULL;
10520
10521 switch ((int)p->indir)
10522 {
10523 case PV_NONE: return p->var;
10524
10525 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010526 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010528 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010530 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010531 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010532 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010534 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010536 case PV_TC: return *curbuf->b_p_tc != NUL
10537 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010538 case PV_BKC: return *curbuf->b_p_bkc != NUL
10539 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010541 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010543 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10545#endif
10546#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010547 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010549 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010550 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10551#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010552 case PV_FP: return *curbuf->b_p_fp != NUL
10553 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010555 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010557 case PV_GP: return *curbuf->b_p_gp != NUL
10558 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10559 case PV_MP: return *curbuf->b_p_mp != NUL
10560 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010562#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10563 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10564 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10565#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010566#if defined(FEAT_CRYPT)
10567 case PV_CM: return *curbuf->b_p_cm != NUL
10568 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10569#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010570#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010571 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010572 ? (char_u *)&(curwin->w_p_stl) : p->var;
10573#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010574 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10575 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010576#ifdef FEAT_LISP
10577 case PV_LW: return *curbuf->b_p_lw != NUL
10578 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10579#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010580#ifdef FEAT_MBYTE
10581 case PV_MENC: return *curbuf->b_p_menc != NUL
10582 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584
10585#ifdef FEAT_ARABIC
10586 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10587#endif
10588 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010589#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010590 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10591#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010592#ifdef FEAT_SYN_HL
10593 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10594 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010595 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010596#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597#ifdef FEAT_DIFF
10598 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10599#endif
10600#ifdef FEAT_FOLDING
10601 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10602 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10603 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10604 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10605 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10606 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10607 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10608# ifdef FEAT_EVAL
10609 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10610 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10611# endif
10612 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10613#endif
10614 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010615 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010616#ifdef FEAT_LINEBREAK
10617 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10618#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010619#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010621 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10622#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010623#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10624 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10625#endif
10626#ifdef FEAT_RIGHTLEFT
10627 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10628 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10629#endif
10630 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10631 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10632#ifdef FEAT_LINEBREAK
10633 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010634 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10635 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636#endif
10637#ifdef FEAT_SCROLLBIND
10638 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10639#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010640#ifdef FEAT_CURSORBIND
10641 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10642#endif
10643#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010644 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10645 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647
10648 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10649 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10650#ifdef FEAT_MBYTE
10651 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10652#endif
10653#if defined(FEAT_QUICKFIX)
10654 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10655 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10656#endif
10657 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10658 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10659#ifdef FEAT_CINDENT
10660 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10661 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10662 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10663#endif
10664#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10665 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10666#endif
10667#ifdef FEAT_COMMENTS
10668 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10669#endif
10670#ifdef FEAT_FOLDING
10671 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10672#endif
10673#ifdef FEAT_INS_EXPAND
10674 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10675#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010676#ifdef FEAT_COMPL_FUNC
10677 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010678 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010679#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010681 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010682 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10683#ifdef FEAT_MBYTE
10684 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10685#endif
10686 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10687#ifdef FEAT_AUTOCMD
10688 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10689#endif
10690 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010691 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010692 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10693 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10694 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10695 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10696#ifdef FEAT_FIND_ID
10697# ifdef FEAT_EVAL
10698 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10699# endif
10700#endif
10701#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10702 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10703 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10704#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010705#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010706 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708#ifdef FEAT_CRYPT
10709 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10710#endif
10711#ifdef FEAT_LISP
10712 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10713#endif
10714 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10715 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10716 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10717 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10718 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010720#ifdef FEAT_TEXTOBJ
10721 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10724#ifdef FEAT_SMARTINDENT
10725 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10726#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010728 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10729#ifdef FEAT_SEARCHPATH
10730 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10731#endif
10732 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10733#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010734 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010735 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10736#endif
10737#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010738 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10739 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10740 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741#endif
10742 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10743 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10744 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10745 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010746#ifdef FEAT_PERSISTENT_UNDO
10747 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10748#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010749 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10750#ifdef FEAT_KEYMAP
10751 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10752#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010753#ifdef FEAT_SIGNS
10754 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10755#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010756 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757 }
10758 /* always return a valid pointer to avoid a crash! */
10759 return (char_u *)&(curbuf->b_p_wm);
10760}
10761
10762/*
10763 * Get the value of 'equalprg', either the buffer-local one or the global one.
10764 */
10765 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010766get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767{
10768 if (*curbuf->b_p_ep == NUL)
10769 return p_ep;
10770 return curbuf->b_p_ep;
10771}
10772
10773#if defined(FEAT_WINDOWS) || defined(PROTO)
10774/*
10775 * Copy options from one window to another.
10776 * Used when splitting a window.
10777 */
10778 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010779win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780{
10781 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10782 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10783# ifdef FEAT_RIGHTLEFT
10784# ifdef FEAT_FKMAP
10785 /* Is this right? */
10786 wp_to->w_farsi = wp_from->w_farsi;
10787# endif
10788# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010789#if defined(FEAT_LINEBREAK)
10790 briopt_check(wp_to);
10791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010792}
10793#endif
10794
10795/*
10796 * Copy the options from one winopt_T to another.
10797 * Doesn't free the old option values in "to", use clear_winopt() for that.
10798 * The 'scroll' option is not copied, because it depends on the window height.
10799 * The 'previewwindow' option is reset, there can be only one preview window.
10800 */
10801 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010802copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803{
10804#ifdef FEAT_ARABIC
10805 to->wo_arab = from->wo_arab;
10806#endif
10807 to->wo_list = from->wo_list;
10808 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010809 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010810#ifdef FEAT_LINEBREAK
10811 to->wo_nuw = from->wo_nuw;
10812#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813#ifdef FEAT_RIGHTLEFT
10814 to->wo_rl = from->wo_rl;
10815 to->wo_rlc = vim_strsave(from->wo_rlc);
10816#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010817#ifdef FEAT_STL_OPT
10818 to->wo_stl = vim_strsave(from->wo_stl);
10819#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010821#ifdef FEAT_DIFF
10822 to->wo_wrap_save = from->wo_wrap_save;
10823#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010824#ifdef FEAT_LINEBREAK
10825 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010826 to->wo_bri = from->wo_bri;
10827 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828#endif
10829#ifdef FEAT_SCROLLBIND
10830 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010831 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010833#ifdef FEAT_CURSORBIND
10834 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010835 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010836#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010837#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010838 to->wo_spell = from->wo_spell;
10839#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010840#ifdef FEAT_SYN_HL
10841 to->wo_cuc = from->wo_cuc;
10842 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010843 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010844#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845#ifdef FEAT_DIFF
10846 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010847 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010849#ifdef FEAT_CONCEAL
10850 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010851 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010852#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853#ifdef FEAT_FOLDING
10854 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010855 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010857 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858 to->wo_fdi = vim_strsave(from->wo_fdi);
10859 to->wo_fml = from->wo_fml;
10860 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010861 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010863 to->wo_fdm_save = from->wo_diff_saved
10864 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 to->wo_fdn = from->wo_fdn;
10866# ifdef FEAT_EVAL
10867 to->wo_fde = vim_strsave(from->wo_fde);
10868 to->wo_fdt = vim_strsave(from->wo_fdt);
10869# endif
10870 to->wo_fmr = vim_strsave(from->wo_fmr);
10871#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010872#ifdef FEAT_SIGNS
10873 to->wo_scl = vim_strsave(from->wo_scl);
10874#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010875 check_winopt(to); /* don't want NULL pointers */
10876}
10877
10878/*
10879 * Check string options in a window for a NULL value.
10880 */
10881 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010882check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883{
10884 check_winopt(&win->w_onebuf_opt);
10885 check_winopt(&win->w_allbuf_opt);
10886}
10887
10888/*
10889 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10890 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010891 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010892check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010893{
10894#ifdef FEAT_FOLDING
10895 check_string_option(&wop->wo_fdi);
10896 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010897 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010898# ifdef FEAT_EVAL
10899 check_string_option(&wop->wo_fde);
10900 check_string_option(&wop->wo_fdt);
10901# endif
10902 check_string_option(&wop->wo_fmr);
10903#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010904#ifdef FEAT_SIGNS
10905 check_string_option(&wop->wo_scl);
10906#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907#ifdef FEAT_RIGHTLEFT
10908 check_string_option(&wop->wo_rlc);
10909#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010910#ifdef FEAT_STL_OPT
10911 check_string_option(&wop->wo_stl);
10912#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010913#ifdef FEAT_SYN_HL
10914 check_string_option(&wop->wo_cc);
10915#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010916#ifdef FEAT_CONCEAL
10917 check_string_option(&wop->wo_cocu);
10918#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010919#ifdef FEAT_LINEBREAK
10920 check_string_option(&wop->wo_briopt);
10921#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922}
10923
10924/*
10925 * Free the allocated memory inside a winopt_T.
10926 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010927 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010928clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929{
10930#ifdef FEAT_FOLDING
10931 clear_string_option(&wop->wo_fdi);
10932 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010933 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010934# ifdef FEAT_EVAL
10935 clear_string_option(&wop->wo_fde);
10936 clear_string_option(&wop->wo_fdt);
10937# endif
10938 clear_string_option(&wop->wo_fmr);
10939#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010940#ifdef FEAT_SIGNS
10941 clear_string_option(&wop->wo_scl);
10942#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010943#ifdef FEAT_LINEBREAK
10944 clear_string_option(&wop->wo_briopt);
10945#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946#ifdef FEAT_RIGHTLEFT
10947 clear_string_option(&wop->wo_rlc);
10948#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010949#ifdef FEAT_STL_OPT
10950 clear_string_option(&wop->wo_stl);
10951#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010952#ifdef FEAT_SYN_HL
10953 clear_string_option(&wop->wo_cc);
10954#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010955#ifdef FEAT_CONCEAL
10956 clear_string_option(&wop->wo_cocu);
10957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010958}
10959
10960/*
10961 * Copy global option values to local options for one buffer.
10962 * Used when creating a new buffer and sometimes when entering a buffer.
10963 * flags:
10964 * BCO_ENTER We will enter the buf buffer.
10965 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10966 * appropriate.
10967 * BCO_NOHELP Don't copy the values to a help buffer.
10968 */
10969 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010970buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971{
10972 int should_copy = TRUE;
10973 char_u *save_p_isk = NULL; /* init for GCC */
10974 int dont_do_help;
10975 int did_isk = FALSE;
10976
10977 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010978 * Skip this when the option defaults have not been set yet. Happens when
10979 * main() allocates the first buffer.
10980 */
10981 if (p_cpo != NULL)
10982 {
10983 /*
10984 * Always copy when entering and 'cpo' contains 'S'.
10985 * Don't copy when already initialized.
10986 * Don't copy when 'cpo' contains 's' and not entering.
10987 * 'S' BCO_ENTER initialized 's' should_copy
10988 * yes yes X X TRUE
10989 * yes no yes X FALSE
10990 * no X yes X FALSE
10991 * X no no yes FALSE
10992 * X no no no TRUE
10993 * no yes no X TRUE
10994 */
10995 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10996 && (buf->b_p_initialized
10997 || (!(flags & BCO_ENTER)
10998 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10999 should_copy = FALSE;
11000
11001 if (should_copy || (flags & BCO_ALWAYS))
11002 {
11003 /* Don't copy the options specific to a help buffer when
11004 * BCO_NOHELP is given or the options were initialized already
11005 * (jumping back to a help file with CTRL-T or CTRL-O) */
11006 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11007 || buf->b_p_initialized;
11008 if (dont_do_help) /* don't free b_p_isk */
11009 {
11010 save_p_isk = buf->b_p_isk;
11011 buf->b_p_isk = NULL;
11012 }
11013 /*
11014 * Always free the allocated strings.
11015 * If not already initialized, set 'readonly' and copy 'fileformat'.
11016 */
11017 if (!buf->b_p_initialized)
11018 {
11019 free_buf_options(buf, TRUE);
11020 buf->b_p_ro = FALSE; /* don't copy readonly */
11021 buf->b_p_tx = p_tx;
11022#ifdef FEAT_MBYTE
11023 buf->b_p_fenc = vim_strsave(p_fenc);
11024#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011025 switch (*p_ffs)
11026 {
11027 case 'm':
11028 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11029 case 'd':
11030 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11031 case 'u':
11032 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11033 default:
11034 buf->b_p_ff = vim_strsave(p_ff);
11035 }
11036 if (buf->b_p_ff != NULL)
11037 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038#if defined(FEAT_QUICKFIX)
11039 buf->b_p_bh = empty_option;
11040 buf->b_p_bt = empty_option;
11041#endif
11042 }
11043 else
11044 free_buf_options(buf, FALSE);
11045
11046 buf->b_p_ai = p_ai;
11047 buf->b_p_ai_nopaste = p_ai_nopaste;
11048 buf->b_p_sw = p_sw;
11049 buf->b_p_tw = p_tw;
11050 buf->b_p_tw_nopaste = p_tw_nopaste;
11051 buf->b_p_tw_nobin = p_tw_nobin;
11052 buf->b_p_wm = p_wm;
11053 buf->b_p_wm_nopaste = p_wm_nopaste;
11054 buf->b_p_wm_nobin = p_wm_nobin;
11055 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011056#ifdef FEAT_MBYTE
11057 buf->b_p_bomb = p_bomb;
11058#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011059 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011060 buf->b_p_et = p_et;
11061 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011062 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063 buf->b_p_ml = p_ml;
11064 buf->b_p_ml_nobin = p_ml_nobin;
11065 buf->b_p_inf = p_inf;
11066 buf->b_p_swf = p_swf;
11067#ifdef FEAT_INS_EXPAND
11068 buf->b_p_cpt = vim_strsave(p_cpt);
11069#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011070#ifdef FEAT_COMPL_FUNC
11071 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011072 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 buf->b_p_sts = p_sts;
11075 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077#ifdef FEAT_COMMENTS
11078 buf->b_p_com = vim_strsave(p_com);
11079#endif
11080#ifdef FEAT_FOLDING
11081 buf->b_p_cms = vim_strsave(p_cms);
11082#endif
11083 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011084 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085 buf->b_p_nf = vim_strsave(p_nf);
11086 buf->b_p_mps = vim_strsave(p_mps);
11087#ifdef FEAT_SMARTINDENT
11088 buf->b_p_si = p_si;
11089#endif
11090 buf->b_p_ci = p_ci;
11091#ifdef FEAT_CINDENT
11092 buf->b_p_cin = p_cin;
11093 buf->b_p_cink = vim_strsave(p_cink);
11094 buf->b_p_cino = vim_strsave(p_cino);
11095#endif
11096#ifdef FEAT_AUTOCMD
11097 /* Don't copy 'filetype', it must be detected */
11098 buf->b_p_ft = empty_option;
11099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011100 buf->b_p_pi = p_pi;
11101#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11102 buf->b_p_cinw = vim_strsave(p_cinw);
11103#endif
11104#ifdef FEAT_LISP
11105 buf->b_p_lisp = p_lisp;
11106#endif
11107#ifdef FEAT_SYN_HL
11108 /* Don't copy 'syntax', it must be set */
11109 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011110 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011111 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011112#endif
11113#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011114 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011115 (void)compile_cap_prog(&buf->b_s);
11116 buf->b_s.b_p_spf = vim_strsave(p_spf);
11117 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118#endif
11119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11120 buf->b_p_inde = vim_strsave(p_inde);
11121 buf->b_p_indk = vim_strsave(p_indk);
11122#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011123 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011124#if defined(FEAT_EVAL)
11125 buf->b_p_fex = vim_strsave(p_fex);
11126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011127#ifdef FEAT_CRYPT
11128 buf->b_p_key = vim_strsave(p_key);
11129#endif
11130#ifdef FEAT_SEARCHPATH
11131 buf->b_p_sua = vim_strsave(p_sua);
11132#endif
11133#ifdef FEAT_KEYMAP
11134 buf->b_p_keymap = vim_strsave(p_keymap);
11135 buf->b_kmap_state |= KEYMAP_INIT;
11136#endif
11137 /* This isn't really an option, but copying the langmap and IME
11138 * state from the current buffer is better than resetting it. */
11139 buf->b_p_iminsert = p_iminsert;
11140 buf->b_p_imsearch = p_imsearch;
11141
11142 /* options that are normally global but also have a local value
11143 * are not copied, start using the global value */
11144 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011145 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011146 buf->b_p_bkc = empty_option;
11147 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148#ifdef FEAT_QUICKFIX
11149 buf->b_p_gp = empty_option;
11150 buf->b_p_mp = empty_option;
11151 buf->b_p_efm = empty_option;
11152#endif
11153 buf->b_p_ep = empty_option;
11154 buf->b_p_kp = empty_option;
11155 buf->b_p_path = empty_option;
11156 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011157 buf->b_p_tc = empty_option;
11158 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011159#ifdef FEAT_FIND_ID
11160 buf->b_p_def = empty_option;
11161 buf->b_p_inc = empty_option;
11162# ifdef FEAT_EVAL
11163 buf->b_p_inex = vim_strsave(p_inex);
11164# endif
11165#endif
11166#ifdef FEAT_INS_EXPAND
11167 buf->b_p_dict = empty_option;
11168 buf->b_p_tsr = empty_option;
11169#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011170#ifdef FEAT_TEXTOBJ
11171 buf->b_p_qe = vim_strsave(p_qe);
11172#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011173#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11174 buf->b_p_bexpr = empty_option;
11175#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011176#if defined(FEAT_CRYPT)
11177 buf->b_p_cm = empty_option;
11178#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011179#ifdef FEAT_PERSISTENT_UNDO
11180 buf->b_p_udf = p_udf;
11181#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011182#ifdef FEAT_LISP
11183 buf->b_p_lw = empty_option;
11184#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011185#ifdef FEAT_MBYTE
11186 buf->b_p_menc = empty_option;
11187#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188
11189 /*
11190 * Don't copy the options set by ex_help(), use the saved values,
11191 * when going from a help buffer to a non-help buffer.
11192 * Don't touch these at all when BCO_NOHELP is used and going from
11193 * or to a help buffer.
11194 */
11195 if (dont_do_help)
11196 buf->b_p_isk = save_p_isk;
11197 else
11198 {
11199 buf->b_p_isk = vim_strsave(p_isk);
11200 did_isk = TRUE;
11201 buf->b_p_ts = p_ts;
11202 buf->b_help = FALSE;
11203#ifdef FEAT_QUICKFIX
11204 if (buf->b_p_bt[0] == 'h')
11205 clear_string_option(&buf->b_p_bt);
11206#endif
11207 buf->b_p_ma = p_ma;
11208 }
11209 }
11210
11211 /*
11212 * When the options should be copied (ignoring BCO_ALWAYS), set the
11213 * flag that indicates that the options have been initialized.
11214 */
11215 if (should_copy)
11216 buf->b_p_initialized = TRUE;
11217 }
11218
11219 check_buf_options(buf); /* make sure we don't have NULLs */
11220 if (did_isk)
11221 (void)buf_init_chartab(buf, FALSE);
11222}
11223
11224/*
11225 * Reset the 'modifiable' option and its default value.
11226 */
11227 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011228reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229{
11230 int opt_idx;
11231
11232 curbuf->b_p_ma = FALSE;
11233 p_ma = FALSE;
11234 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011235 if (opt_idx >= 0)
11236 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237}
11238
11239/*
11240 * Set the global value for 'iminsert' to the local value.
11241 */
11242 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011243set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011244{
11245 p_iminsert = curbuf->b_p_iminsert;
11246}
11247
11248/*
11249 * Set the global value for 'imsearch' to the local value.
11250 */
11251 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011252set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011253{
11254 p_imsearch = curbuf->b_p_imsearch;
11255}
11256
11257#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11258static int expand_option_idx = -1;
11259static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11260static int expand_option_flags = 0;
11261
11262 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011263set_context_in_set_cmd(
11264 expand_T *xp,
11265 char_u *arg,
11266 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267{
11268 int nextchar;
11269 long_u flags = 0; /* init for GCC */
11270 int opt_idx = 0; /* init for GCC */
11271 char_u *p;
11272 char_u *s;
11273 int is_term_option = FALSE;
11274 int key;
11275
11276 expand_option_flags = opt_flags;
11277
11278 xp->xp_context = EXPAND_SETTINGS;
11279 if (*arg == NUL)
11280 {
11281 xp->xp_pattern = arg;
11282 return;
11283 }
11284 p = arg + STRLEN(arg) - 1;
11285 if (*p == ' ' && *(p - 1) != '\\')
11286 {
11287 xp->xp_pattern = p + 1;
11288 return;
11289 }
11290 while (p > arg)
11291 {
11292 s = p;
11293 /* count number of backslashes before ' ' or ',' */
11294 if (*p == ' ' || *p == ',')
11295 {
11296 while (s > arg && *(s - 1) == '\\')
11297 --s;
11298 }
11299 /* break at a space with an even number of backslashes */
11300 if (*p == ' ' && ((p - s) & 1) == 0)
11301 {
11302 ++p;
11303 break;
11304 }
11305 --p;
11306 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011307 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308 {
11309 xp->xp_context = EXPAND_BOOL_SETTINGS;
11310 p += 2;
11311 }
11312 if (STRNCMP(p, "inv", 3) == 0)
11313 {
11314 xp->xp_context = EXPAND_BOOL_SETTINGS;
11315 p += 3;
11316 }
11317 xp->xp_pattern = arg = p;
11318 if (*arg == '<')
11319 {
11320 while (*p != '>')
11321 if (*p++ == NUL) /* expand terminal option name */
11322 return;
11323 key = get_special_key_code(arg + 1);
11324 if (key == 0) /* unknown name */
11325 {
11326 xp->xp_context = EXPAND_NOTHING;
11327 return;
11328 }
11329 nextchar = *++p;
11330 is_term_option = TRUE;
11331 expand_option_name[2] = KEY2TERMCAP0(key);
11332 expand_option_name[3] = KEY2TERMCAP1(key);
11333 }
11334 else
11335 {
11336 if (p[0] == 't' && p[1] == '_')
11337 {
11338 p += 2;
11339 if (*p != NUL)
11340 ++p;
11341 if (*p == NUL)
11342 return; /* expand option name */
11343 nextchar = *++p;
11344 is_term_option = TRUE;
11345 expand_option_name[2] = p[-2];
11346 expand_option_name[3] = p[-1];
11347 }
11348 else
11349 {
11350 /* Allow * wildcard */
11351 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11352 p++;
11353 if (*p == NUL)
11354 return;
11355 nextchar = *p;
11356 *p = NUL;
11357 opt_idx = findoption(arg);
11358 *p = nextchar;
11359 if (opt_idx == -1 || options[opt_idx].var == NULL)
11360 {
11361 xp->xp_context = EXPAND_NOTHING;
11362 return;
11363 }
11364 flags = options[opt_idx].flags;
11365 if (flags & P_BOOL)
11366 {
11367 xp->xp_context = EXPAND_NOTHING;
11368 return;
11369 }
11370 }
11371 }
11372 /* handle "-=" and "+=" */
11373 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11374 {
11375 ++p;
11376 nextchar = '=';
11377 }
11378 if ((nextchar != '=' && nextchar != ':')
11379 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11380 {
11381 xp->xp_context = EXPAND_UNSUCCESSFUL;
11382 return;
11383 }
11384 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11385 {
11386 xp->xp_context = EXPAND_OLD_SETTING;
11387 if (is_term_option)
11388 expand_option_idx = -1;
11389 else
11390 expand_option_idx = opt_idx;
11391 xp->xp_pattern = p + 1;
11392 return;
11393 }
11394 xp->xp_context = EXPAND_NOTHING;
11395 if (is_term_option || (flags & P_NUM))
11396 return;
11397
11398 xp->xp_pattern = p + 1;
11399
11400 if (flags & P_EXPAND)
11401 {
11402 p = options[opt_idx].var;
11403 if (p == (char_u *)&p_bdir
11404 || p == (char_u *)&p_dir
11405 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011406 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011407 || p == (char_u *)&p_rtp
11408#ifdef FEAT_SEARCHPATH
11409 || p == (char_u *)&p_cdpath
11410#endif
11411#ifdef FEAT_SESSION
11412 || p == (char_u *)&p_vdir
11413#endif
11414 )
11415 {
11416 xp->xp_context = EXPAND_DIRECTORIES;
11417 if (p == (char_u *)&p_path
11418#ifdef FEAT_SEARCHPATH
11419 || p == (char_u *)&p_cdpath
11420#endif
11421 )
11422 xp->xp_backslash = XP_BS_THREE;
11423 else
11424 xp->xp_backslash = XP_BS_ONE;
11425 }
11426 else
11427 {
11428 xp->xp_context = EXPAND_FILES;
11429 /* for 'tags' need three backslashes for a space */
11430 if (p == (char_u *)&p_tags)
11431 xp->xp_backslash = XP_BS_THREE;
11432 else
11433 xp->xp_backslash = XP_BS_ONE;
11434 }
11435 }
11436
11437 /* For an option that is a list of file names, find the start of the
11438 * last file name. */
11439 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11440 {
11441 /* count number of backslashes before ' ' or ',' */
11442 if (*p == ' ' || *p == ',')
11443 {
11444 s = p;
11445 while (s > xp->xp_pattern && *(s - 1) == '\\')
11446 --s;
11447 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11448 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11449 {
11450 xp->xp_pattern = p + 1;
11451 break;
11452 }
11453 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011454
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011455#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011456 /* for 'spellsuggest' start at "file:" */
11457 if (options[opt_idx].var == (char_u *)&p_sps
11458 && STRNCMP(p, "file:", 5) == 0)
11459 {
11460 xp->xp_pattern = p + 5;
11461 break;
11462 }
11463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464 }
11465
11466 return;
11467}
11468
11469 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011470ExpandSettings(
11471 expand_T *xp,
11472 regmatch_T *regmatch,
11473 int *num_file,
11474 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011475{
11476 int num_normal = 0; /* Nr of matching non-term-code settings */
11477 int num_term = 0; /* Nr of matching terminal code settings */
11478 int opt_idx;
11479 int match;
11480 int count = 0;
11481 char_u *str;
11482 int loop;
11483 int is_term_opt;
11484 char_u name_buf[MAX_KEY_NAME_LEN];
11485 static char *(names[]) = {"all", "termcap"};
11486 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11487
11488 /* do this loop twice:
11489 * loop == 0: count the number of matching options
11490 * loop == 1: copy the matching options into allocated memory
11491 */
11492 for (loop = 0; loop <= 1; ++loop)
11493 {
11494 regmatch->rm_ic = ic;
11495 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11496 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011497 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11498 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11500 {
11501 if (loop == 0)
11502 num_normal++;
11503 else
11504 (*file)[count++] = vim_strsave((char_u *)names[match]);
11505 }
11506 }
11507 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11508 opt_idx++)
11509 {
11510 if (options[opt_idx].var == NULL)
11511 continue;
11512 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11513 && !(options[opt_idx].flags & P_BOOL))
11514 continue;
11515 is_term_opt = istermoption(&options[opt_idx]);
11516 if (is_term_opt && num_normal > 0)
11517 continue;
11518 match = FALSE;
11519 if (vim_regexec(regmatch, str, (colnr_T)0)
11520 || (options[opt_idx].shortname != NULL
11521 && vim_regexec(regmatch,
11522 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11523 match = TRUE;
11524 else if (is_term_opt)
11525 {
11526 name_buf[0] = '<';
11527 name_buf[1] = 't';
11528 name_buf[2] = '_';
11529 name_buf[3] = str[2];
11530 name_buf[4] = str[3];
11531 name_buf[5] = '>';
11532 name_buf[6] = NUL;
11533 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11534 {
11535 match = TRUE;
11536 str = name_buf;
11537 }
11538 }
11539 if (match)
11540 {
11541 if (loop == 0)
11542 {
11543 if (is_term_opt)
11544 num_term++;
11545 else
11546 num_normal++;
11547 }
11548 else
11549 (*file)[count++] = vim_strsave(str);
11550 }
11551 }
11552 /*
11553 * Check terminal key codes, these are not in the option table
11554 */
11555 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11556 {
11557 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11558 {
11559 if (!isprint(str[0]) || !isprint(str[1]))
11560 continue;
11561
11562 name_buf[0] = 't';
11563 name_buf[1] = '_';
11564 name_buf[2] = str[0];
11565 name_buf[3] = str[1];
11566 name_buf[4] = NUL;
11567
11568 match = FALSE;
11569 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11570 match = TRUE;
11571 else
11572 {
11573 name_buf[0] = '<';
11574 name_buf[1] = 't';
11575 name_buf[2] = '_';
11576 name_buf[3] = str[0];
11577 name_buf[4] = str[1];
11578 name_buf[5] = '>';
11579 name_buf[6] = NUL;
11580
11581 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11582 match = TRUE;
11583 }
11584 if (match)
11585 {
11586 if (loop == 0)
11587 num_term++;
11588 else
11589 (*file)[count++] = vim_strsave(name_buf);
11590 }
11591 }
11592
11593 /*
11594 * Check special key names.
11595 */
11596 regmatch->rm_ic = TRUE; /* ignore case here */
11597 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11598 {
11599 name_buf[0] = '<';
11600 STRCPY(name_buf + 1, str);
11601 STRCAT(name_buf, ">");
11602
11603 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11604 {
11605 if (loop == 0)
11606 num_term++;
11607 else
11608 (*file)[count++] = vim_strsave(name_buf);
11609 }
11610 }
11611 }
11612 if (loop == 0)
11613 {
11614 if (num_normal > 0)
11615 *num_file = num_normal;
11616 else if (num_term > 0)
11617 *num_file = num_term;
11618 else
11619 return OK;
11620 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11621 if (*file == NULL)
11622 {
11623 *file = (char_u **)"";
11624 return FAIL;
11625 }
11626 }
11627 }
11628 return OK;
11629}
11630
11631 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011632ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633{
11634 char_u *var = NULL; /* init for GCC */
11635 char_u *buf;
11636
11637 *num_file = 0;
11638 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11639 if (*file == NULL)
11640 return FAIL;
11641
11642 /*
11643 * For a terminal key code expand_option_idx is < 0.
11644 */
11645 if (expand_option_idx < 0)
11646 {
11647 var = find_termcode(expand_option_name + 2);
11648 if (var == NULL)
11649 expand_option_idx = findoption(expand_option_name);
11650 }
11651
11652 if (expand_option_idx >= 0)
11653 {
11654 /* put string of option value in NameBuff */
11655 option_value2string(&options[expand_option_idx], expand_option_flags);
11656 var = NameBuff;
11657 }
11658 else if (var == NULL)
11659 var = (char_u *)"";
11660
11661 /* A backslash is required before some characters. This is the reverse of
11662 * what happens in do_set(). */
11663 buf = vim_strsave_escaped(var, escape_chars);
11664
11665 if (buf == NULL)
11666 {
11667 vim_free(*file);
11668 *file = NULL;
11669 return FAIL;
11670 }
11671
11672#ifdef BACKSLASH_IN_FILENAME
11673 /* For MS-Windows et al. we don't double backslashes at the start and
11674 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011675 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676 if (var[0] == '\\' && var[1] == '\\'
11677 && expand_option_idx >= 0
11678 && (options[expand_option_idx].flags & P_EXPAND)
11679 && vim_isfilec(var[2])
11680 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011681 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011682#endif
11683
11684 *file[0] = buf;
11685 *num_file = 1;
11686 return OK;
11687}
11688#endif
11689
11690/*
11691 * Get the value for the numeric or string option *opp in a nice format into
11692 * NameBuff[]. Must not be called with a hidden option!
11693 */
11694 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011695option_value2string(
11696 struct vimoption *opp,
11697 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011698{
11699 char_u *varp;
11700
11701 varp = get_varp_scope(opp, opt_flags);
11702
11703 if (opp->flags & P_NUM)
11704 {
11705 long wc = 0;
11706
11707 if (wc_use_keyname(varp, &wc))
11708 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11709 else if (wc != 0)
11710 STRCPY(NameBuff, transchar((int)wc));
11711 else
11712 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11713 }
11714 else /* P_STRING */
11715 {
11716 varp = *(char_u **)(varp);
11717 if (varp == NULL) /* just in case */
11718 NameBuff[0] = NUL;
11719#ifdef FEAT_CRYPT
11720 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011721 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011722 STRCPY(NameBuff, "*****");
11723#endif
11724 else if (opp->flags & P_EXPAND)
11725 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11726 /* Translate 'pastetoggle' into special key names */
11727 else if ((char_u **)opp->var == &p_pt)
11728 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11729 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011730 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731 }
11732}
11733
11734/*
11735 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11736 * printed as a keyname.
11737 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11738 */
11739 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011740wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741{
11742 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11743 {
11744 *wcp = *(long *)varp;
11745 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11746 return TRUE;
11747 }
11748 return FALSE;
11749}
11750
Bram Moolenaar01615492015-02-03 13:00:38 +010011751#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011753 * Any character has an equivalent 'langmap' character. This is used for
11754 * keyboards that have a special language mode that sends characters above
11755 * 128 (although other characters can be translated too). The "to" field is a
11756 * Vim command character. This avoids having to switch the keyboard back to
11757 * ASCII mode when leaving Insert mode.
11758 *
11759 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11760 * commands.
11761 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11762 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11763 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011765# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011766/*
11767 * With multi-byte support use growarray for 'langmap' chars >= 256
11768 */
11769typedef struct
11770{
11771 int from;
11772 int to;
11773} langmap_entry_T;
11774
11775static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011776static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777
11778/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011779 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11780 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011782 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011783langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011784{
11785 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011786 int a = 0;
11787 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011788
11789 /* Do a binary search for an existing entry. */
11790 while (a != b)
11791 {
11792 int i = (a + b) / 2;
11793 int d = entries[i].from - from;
11794
11795 if (d == 0)
11796 {
11797 entries[i].to = to;
11798 return;
11799 }
11800 if (d < 0)
11801 a = i + 1;
11802 else
11803 b = i;
11804 }
11805
11806 if (ga_grow(&langmap_mapga, 1) != OK)
11807 return; /* out of memory */
11808
11809 /* insert new entry at position "a" */
11810 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11811 mch_memmove(entries + 1, entries,
11812 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11813 ++langmap_mapga.ga_len;
11814 entries[0].from = from;
11815 entries[0].to = to;
11816}
11817
11818/*
11819 * Apply 'langmap' to multi-byte character "c" and return the result.
11820 */
11821 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011822langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011823{
11824 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11825 int a = 0;
11826 int b = langmap_mapga.ga_len;
11827
11828 while (a != b)
11829 {
11830 int i = (a + b) / 2;
11831 int d = entries[i].from - c;
11832
11833 if (d == 0)
11834 return entries[i].to; /* found matching entry */
11835 if (d < 0)
11836 a = i + 1;
11837 else
11838 b = i;
11839 }
11840 return c; /* no entry found, return "c" unmodified */
11841}
11842# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011843
11844 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011845langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011846{
11847 int i;
11848
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011849 for (i = 0; i < 256; i++)
11850 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11851# ifdef FEAT_MBYTE
11852 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11853# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011854}
11855
11856/*
11857 * Called when langmap option is set; the language map can be
11858 * changed at any time!
11859 */
11860 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011861langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011862{
11863 char_u *p;
11864 char_u *p2;
11865 int from, to;
11866
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011867#ifdef FEAT_MBYTE
11868 ga_clear(&langmap_mapga); /* clear the previous map first */
11869#endif
11870 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011871
11872 for (p = p_langmap; p[0] != NUL; )
11873 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011874 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11875 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876 {
11877 if (p2[0] == '\\' && p2[1] != NUL)
11878 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879 }
11880 if (p2[0] == ';')
11881 ++p2; /* abcd;ABCD form, p2 points to A */
11882 else
11883 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11884 while (p[0])
11885 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011886 if (p[0] == ',')
11887 {
11888 ++p;
11889 break;
11890 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011891 if (p[0] == '\\' && p[1] != NUL)
11892 ++p;
11893#ifdef FEAT_MBYTE
11894 from = (*mb_ptr2char)(p);
11895#else
11896 from = p[0];
11897#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011898 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011899 if (p2 == NULL)
11900 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011901 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011902 if (p[0] != ',')
11903 {
11904 if (p[0] == '\\')
11905 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011907 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011908#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011909 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011910#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011912 }
11913 else
11914 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011915 if (p2[0] != ',')
11916 {
11917 if (p2[0] == '\\')
11918 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011920 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011922 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011923#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011924 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925 }
11926 if (to == NUL)
11927 {
11928 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11929 transchar(from));
11930 return;
11931 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011932
11933#ifdef FEAT_MBYTE
11934 if (from >= 256)
11935 langmap_set_entry(from, to);
11936 else
11937#endif
11938 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011939
11940 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011941 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011942 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011943 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011944 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011945 if (*p == ';')
11946 {
11947 p = p2;
11948 if (p[0] != NUL)
11949 {
11950 if (p[0] != ',')
11951 {
11952 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11953 return;
11954 }
11955 ++p;
11956 }
11957 break;
11958 }
11959 }
11960 }
11961 }
11962}
11963#endif
11964
11965/*
11966 * Return TRUE if format option 'x' is in effect.
11967 * Take care of no formatting when 'paste' is set.
11968 */
11969 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011970has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011971{
11972 if (p_paste)
11973 return FALSE;
11974 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11975}
11976
11977/*
11978 * Return TRUE if "x" is present in 'shortmess' option, or
11979 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11980 */
11981 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011982shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011984 return p_shm != NULL &&
11985 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011986 || (vim_strchr(p_shm, 'a') != NULL
11987 && vim_strchr((char_u *)SHM_A, x) != NULL));
11988}
11989
11990/*
11991 * paste_option_changed() - Called after p_paste was set or reset.
11992 */
11993 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011994paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995{
11996 static int old_p_paste = FALSE;
11997 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011998 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999#ifdef FEAT_CMDL_INFO
12000 static int save_ru = 0;
12001#endif
12002#ifdef FEAT_RIGHTLEFT
12003 static int save_ri = 0;
12004 static int save_hkmap = 0;
12005#endif
12006 buf_T *buf;
12007
12008 if (p_paste)
12009 {
12010 /*
12011 * Paste switched from off to on.
12012 * Save the current values, so they can be restored later.
12013 */
12014 if (!old_p_paste)
12015 {
12016 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012017 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012018 {
12019 buf->b_p_tw_nopaste = buf->b_p_tw;
12020 buf->b_p_wm_nopaste = buf->b_p_wm;
12021 buf->b_p_sts_nopaste = buf->b_p_sts;
12022 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012023 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012024 }
12025
12026 /* save global options */
12027 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012028 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029#ifdef FEAT_CMDL_INFO
12030 save_ru = p_ru;
12031#endif
12032#ifdef FEAT_RIGHTLEFT
12033 save_ri = p_ri;
12034 save_hkmap = p_hkmap;
12035#endif
12036 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012037 p_ai_nopaste = p_ai;
12038 p_et_nopaste = p_et;
12039 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012040 p_tw_nopaste = p_tw;
12041 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012042 }
12043
12044 /*
12045 * Always set the option values, also when 'paste' is set when it is
12046 * already on.
12047 */
12048 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012049 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 {
12051 buf->b_p_tw = 0; /* textwidth is 0 */
12052 buf->b_p_wm = 0; /* wrapmargin is 0 */
12053 buf->b_p_sts = 0; /* softtabstop is 0 */
12054 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012055 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056 }
12057
12058 /* set global options */
12059 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012060 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061#ifdef FEAT_CMDL_INFO
12062# ifdef FEAT_WINDOWS
12063 if (p_ru)
12064 status_redraw_all(); /* redraw to remove the ruler */
12065# endif
12066 p_ru = 0; /* no ruler */
12067#endif
12068#ifdef FEAT_RIGHTLEFT
12069 p_ri = 0; /* no reverse insert */
12070 p_hkmap = 0; /* no Hebrew keyboard */
12071#endif
12072 /* set global values for local buffer options */
12073 p_tw = 0;
12074 p_wm = 0;
12075 p_sts = 0;
12076 p_ai = 0;
12077 }
12078
12079 /*
12080 * Paste switched from on to off: Restore saved values.
12081 */
12082 else if (old_p_paste)
12083 {
12084 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012085 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086 {
12087 buf->b_p_tw = buf->b_p_tw_nopaste;
12088 buf->b_p_wm = buf->b_p_wm_nopaste;
12089 buf->b_p_sts = buf->b_p_sts_nopaste;
12090 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012091 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092 }
12093
12094 /* restore global options */
12095 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012096 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012097#ifdef FEAT_CMDL_INFO
12098# ifdef FEAT_WINDOWS
12099 if (p_ru != save_ru)
12100 status_redraw_all(); /* redraw to draw the ruler */
12101# endif
12102 p_ru = save_ru;
12103#endif
12104#ifdef FEAT_RIGHTLEFT
12105 p_ri = save_ri;
12106 p_hkmap = save_hkmap;
12107#endif
12108 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012109 p_ai = p_ai_nopaste;
12110 p_et = p_et_nopaste;
12111 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012112 p_tw = p_tw_nopaste;
12113 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114 }
12115
12116 old_p_paste = p_paste;
12117}
12118
12119/*
12120 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12121 *
12122 * Reset 'compatible' and set the values for options that didn't get set yet
12123 * to the Vim defaults.
12124 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012125 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126 */
12127 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012128vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012130 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012131 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012132 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012133
12134 if (!option_was_set((char_u *)"cp"))
12135 {
12136 p_cp = FALSE;
12137 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12138 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12139 set_option_default(opt_idx, OPT_FREE, FALSE);
12140 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012141 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012142 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012143
12144 if (fname != NULL)
12145 {
12146 p = vim_getenv(envname, &dofree);
12147 if (p == NULL)
12148 {
12149 /* Set $MYVIMRC to the first vimrc file found. */
12150 p = FullName_save(fname, FALSE);
12151 if (p != NULL)
12152 {
12153 vim_setenv(envname, p);
12154 vim_free(p);
12155 }
12156 }
12157 else if (dofree)
12158 vim_free(p);
12159 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012160}
12161
12162/*
12163 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12164 */
12165 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012166change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012168 int opt_idx;
12169
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170 if (p_cp != on)
12171 {
12172 p_cp = on;
12173 compatible_set();
12174 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012175 opt_idx = findoption((char_u *)"cp");
12176 if (opt_idx >= 0)
12177 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012178}
12179
12180/*
12181 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012182 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183 */
12184 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012185option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186{
12187 int idx;
12188
12189 idx = findoption(name);
12190 if (idx < 0) /* unknown option */
12191 return FALSE;
12192 if (options[idx].flags & P_WAS_SET)
12193 return TRUE;
12194 return FALSE;
12195}
12196
12197/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012198 * Reset the flag indicating option "name" was set.
12199 */
12200 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012201reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012202{
12203 int idx = findoption(name);
12204
12205 if (idx >= 0)
12206 options[idx].flags &= ~P_WAS_SET;
12207}
12208
12209/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012210 * compatible_set() - Called when 'compatible' has been set or unset.
12211 *
12212 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12213 * flag) to a Vi compatible value.
12214 * When 'compatible' is unset: Set all options that have a different default
12215 * for Vim (without the P_VI_DEF flag) to that default.
12216 */
12217 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012218compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012219{
12220 int opt_idx;
12221
12222 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12223 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12224 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12225 set_option_default(opt_idx, OPT_FREE, p_cp);
12226 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012227 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012228}
12229
12230#ifdef FEAT_LINEBREAK
12231
12232# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12233 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012234 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012235# endif
12236
12237/*
12238 * fill_breakat_flags() -- called when 'breakat' changes value.
12239 */
12240 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012241fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012243 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012244 int i;
12245
12246 for (i = 0; i < 256; i++)
12247 breakat_flags[i] = FALSE;
12248
12249 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012250 for (p = p_breakat; *p; p++)
12251 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012252}
12253
12254# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012255 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012256# endif
12257
12258#endif
12259
12260/*
12261 * Check an option that can be a range of string values.
12262 *
12263 * Return OK for correct value, FAIL otherwise.
12264 * Empty is always OK.
12265 */
12266 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012267check_opt_strings(
12268 char_u *val,
12269 char **values,
12270 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012271{
12272 return opt_strings_flags(val, values, NULL, list);
12273}
12274
12275/*
12276 * Handle an option that can be a range of string values.
12277 * Set a flag in "*flagp" for each string present.
12278 *
12279 * Return OK for correct value, FAIL otherwise.
12280 * Empty is always OK.
12281 */
12282 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012283opt_strings_flags(
12284 char_u *val, /* new value */
12285 char **values, /* array of valid string values */
12286 unsigned *flagp,
12287 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288{
12289 int i;
12290 int len;
12291 unsigned new_flags = 0;
12292
12293 while (*val)
12294 {
12295 for (i = 0; ; ++i)
12296 {
12297 if (values[i] == NULL) /* val not found in values[] */
12298 return FAIL;
12299
12300 len = (int)STRLEN(values[i]);
12301 if (STRNCMP(values[i], val, len) == 0
12302 && ((list && val[len] == ',') || val[len] == NUL))
12303 {
12304 val += len + (val[len] == ',');
12305 new_flags |= (1 << i);
12306 break; /* check next item in val list */
12307 }
12308 }
12309 }
12310 if (flagp != NULL)
12311 *flagp = new_flags;
12312
12313 return OK;
12314}
12315
12316/*
12317 * Read the 'wildmode' option, fill wim_flags[].
12318 */
12319 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012320check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012321{
12322 char_u new_wim_flags[4];
12323 char_u *p;
12324 int i;
12325 int idx = 0;
12326
12327 for (i = 0; i < 4; ++i)
12328 new_wim_flags[i] = 0;
12329
12330 for (p = p_wim; *p; ++p)
12331 {
12332 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12333 ;
12334 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12335 return FAIL;
12336 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12337 new_wim_flags[idx] |= WIM_LONGEST;
12338 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12339 new_wim_flags[idx] |= WIM_FULL;
12340 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12341 new_wim_flags[idx] |= WIM_LIST;
12342 else
12343 return FAIL;
12344 p += i;
12345 if (*p == NUL)
12346 break;
12347 if (*p == ',')
12348 {
12349 if (idx == 3)
12350 return FAIL;
12351 ++idx;
12352 }
12353 }
12354
12355 /* fill remaining entries with last flag */
12356 while (idx < 3)
12357 {
12358 new_wim_flags[idx + 1] = new_wim_flags[idx];
12359 ++idx;
12360 }
12361
12362 /* only when there are no errors, wim_flags[] is changed */
12363 for (i = 0; i < 4; ++i)
12364 wim_flags[i] = new_wim_flags[i];
12365 return OK;
12366}
12367
12368/*
12369 * Check if backspacing over something is allowed.
12370 */
12371 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012372can_bs(
12373 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012374{
12375 switch (*p_bs)
12376 {
12377 case '2': return TRUE;
12378 case '1': return (what != BS_START);
12379 case '0': return FALSE;
12380 }
12381 return vim_strchr(p_bs, what) != NULL;
12382}
12383
12384/*
12385 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12386 * the file must be considered changed when the value is different.
12387 */
12388 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012389save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012390{
12391 buf->b_start_ffc = *buf->b_p_ff;
12392 buf->b_start_eol = buf->b_p_eol;
12393#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012394 buf->b_start_bomb = buf->b_p_bomb;
12395
Bram Moolenaar071d4272004-06-13 20:20:40 +000012396 /* Only use free/alloc when necessary, they take time. */
12397 if (buf->b_start_fenc == NULL
12398 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12399 {
12400 vim_free(buf->b_start_fenc);
12401 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12402 }
12403#endif
12404}
12405
12406/*
12407 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12408 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012409 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12410 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012411 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012412 * When "ignore_empty" is true don't consider a new, empty buffer to be
12413 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012414 */
12415 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012416file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012417{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012418 /* In a buffer that was never loaded the options are not valid. */
12419 if (buf->b_flags & BF_NEVERLOADED)
12420 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012421 if (ignore_empty
12422 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423 && buf->b_ml.ml_line_count == 1
12424 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12425 return FALSE;
12426 if (buf->b_start_ffc != *buf->b_p_ff)
12427 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012428 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012429 return TRUE;
12430#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012431 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12432 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012433 if (buf->b_start_fenc == NULL)
12434 return (*buf->b_p_fenc != NUL);
12435 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12436#else
12437 return FALSE;
12438#endif
12439}
12440
12441/*
12442 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12443 */
12444 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012445check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012446{
12447 return check_opt_strings(p, p_ff_values, FALSE);
12448}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012449
12450/*
12451 * Return the effective shiftwidth value for current buffer, using the
12452 * 'tabstop' value when 'shiftwidth' is zero.
12453 */
12454 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012455get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012456{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012457 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012458}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012459
12460/*
12461 * Return the effective softtabstop value for the current buffer, using the
12462 * 'tabstop' value when 'softtabstop' is negative.
12463 */
12464 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012465get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012466{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012467 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012468}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012469
12470/*
12471 * Check matchpairs option for "*initc".
12472 * If there is a match set "*initc" to the matching character and "*findc" to
12473 * the opposite character. Set "*backwards" to the direction.
12474 * When "switchit" is TRUE swap the direction.
12475 */
12476 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012477find_mps_values(
12478 int *initc,
12479 int *findc,
12480 int *backwards,
12481 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012482{
12483 char_u *ptr;
12484
12485 ptr = curbuf->b_p_mps;
12486 while (*ptr != NUL)
12487 {
12488#ifdef FEAT_MBYTE
12489 if (has_mbyte)
12490 {
12491 char_u *prev;
12492
12493 if (mb_ptr2char(ptr) == *initc)
12494 {
12495 if (switchit)
12496 {
12497 *findc = *initc;
12498 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12499 *backwards = TRUE;
12500 }
12501 else
12502 {
12503 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12504 *backwards = FALSE;
12505 }
12506 return;
12507 }
12508 prev = ptr;
12509 ptr += mb_ptr2len(ptr) + 1;
12510 if (mb_ptr2char(ptr) == *initc)
12511 {
12512 if (switchit)
12513 {
12514 *findc = *initc;
12515 *initc = mb_ptr2char(prev);
12516 *backwards = FALSE;
12517 }
12518 else
12519 {
12520 *findc = mb_ptr2char(prev);
12521 *backwards = TRUE;
12522 }
12523 return;
12524 }
12525 ptr += mb_ptr2len(ptr);
12526 }
12527 else
12528#endif
12529 {
12530 if (*ptr == *initc)
12531 {
12532 if (switchit)
12533 {
12534 *backwards = TRUE;
12535 *findc = *initc;
12536 *initc = ptr[2];
12537 }
12538 else
12539 {
12540 *backwards = FALSE;
12541 *findc = ptr[2];
12542 }
12543 return;
12544 }
12545 ptr += 2;
12546 if (*ptr == *initc)
12547 {
12548 if (switchit)
12549 {
12550 *backwards = FALSE;
12551 *findc = *initc;
12552 *initc = ptr[-2];
12553 }
12554 else
12555 {
12556 *backwards = TRUE;
12557 *findc = ptr[-2];
12558 }
12559 return;
12560 }
12561 ++ptr;
12562 }
12563 if (*ptr == ',')
12564 ++ptr;
12565 }
12566}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012567
12568#if defined(FEAT_LINEBREAK) || defined(PROTO)
12569/*
12570 * This is called when 'breakindentopt' is changed and when a window is
12571 * initialized.
12572 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012573 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012574briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012575{
12576 char_u *p;
12577 int bri_shift = 0;
12578 long bri_min = 20;
12579 int bri_sbr = FALSE;
12580
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012581 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012582 while (*p != NUL)
12583 {
12584 if (STRNCMP(p, "shift:", 6) == 0
12585 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12586 {
12587 p += 6;
12588 bri_shift = getdigits(&p);
12589 }
12590 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12591 {
12592 p += 4;
12593 bri_min = getdigits(&p);
12594 }
12595 else if (STRNCMP(p, "sbr", 3) == 0)
12596 {
12597 p += 3;
12598 bri_sbr = TRUE;
12599 }
12600 if (*p != ',' && *p != NUL)
12601 return FAIL;
12602 if (*p == ',')
12603 ++p;
12604 }
12605
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012606 wp->w_p_brishift = bri_shift;
12607 wp->w_p_brimin = bri_min;
12608 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012609
12610 return OK;
12611}
12612#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012613
12614/*
12615 * Get the local or global value of 'backupcopy'.
12616 */
12617 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012618get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012619{
12620 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12621}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012622
12623#if defined(FEAT_SIGNS) || defined(PROTO)
12624/*
12625 * Return TRUE when window "wp" has a column to draw signs in.
12626 */
12627 int
12628signcolumn_on(win_T *wp)
12629{
12630 if (*wp->w_p_scl == 'n')
12631 return FALSE;
12632 if (*wp->w_p_scl == 'y')
12633 return TRUE;
12634 return (wp->w_buffer->b_signlist != NULL
12635# ifdef FEAT_NETBEANS_INTG
12636 || wp->w_buffer->b_has_sign_column
12637# endif
12638 );
12639}
12640#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012641
12642#if defined(FEAT_EVAL) || defined(PROTO)
12643/*
12644 * Get window or buffer local options.
12645 */
12646 dict_T *
12647get_winbuf_options(int bufopt)
12648{
12649 dict_T *d;
12650 int opt_idx;
12651
12652 d = dict_alloc();
12653 if (d == NULL)
12654 return NULL;
12655
12656 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12657 {
12658 struct vimoption *opt = &options[opt_idx];
12659
12660 if ((bufopt && (opt->indir & PV_BUF))
12661 || (!bufopt && (opt->indir & PV_WIN)))
12662 {
12663 char_u *varp = get_varp(opt);
12664
12665 if (varp != NULL)
12666 {
12667 if (opt->flags & P_STRING)
12668 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012669 else if (opt->flags & P_NUM)
12670 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012671 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012672 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012673 }
12674 }
12675 }
12676
12677 return d;
12678}
12679#endif