blob: 154c28b5a8f996347566df2f8536001e2603ba19 [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 Moolenaar21020352017-06-13 17:21:04 +0200479 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) \
480 || defined(FEAT_CONCEAL) || defined(FEAT_QUICKFIX)
481# 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,q:QuickFixLine"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000482#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100483# 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 +0000484#endif
485
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100486/* Default python version for pyx* commands */
487#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
488# define DEFAULT_PYTHON_VER 0
489#elif defined(FEAT_PYTHON3)
490# define DEFAULT_PYTHON_VER 3
491#elif defined(FEAT_PYTHON)
492# define DEFAULT_PYTHON_VER 2
493#else
494# define DEFAULT_PYTHON_VER 0
495#endif
496
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497/*
498 * options[] is initialized here.
499 * The order of the options MUST be alphabetic for ":set all" and findoption().
500 * All option names MUST start with a lowercase letter (for findoption()).
501 * Exception: "t_" options are at the end.
502 * The options with a NULL variable are 'hidden': a set command for them is
503 * ignored and they are not printed.
504 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100505static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200507 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508#ifdef FEAT_RIGHTLEFT
509 (char_u *)&p_aleph, PV_NONE,
510#else
511 (char_u *)NULL, PV_NONE,
512#endif
513 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100514#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 (char_u *)128L,
516#else
517 (char_u *)224L,
518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000519 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
521#if defined(FEAT_GUI) && defined(MACOS_X)
522 (char_u *)&p_antialias, PV_NONE,
523 {(char_u *)FALSE, (char_u *)FALSE}
524#else
525 (char_u *)NULL, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200529 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530#ifdef FEAT_ARABIC
531 (char_u *)VAR_WIN, PV_ARAB,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
537#ifdef FEAT_ARABIC
538 (char_u *)&p_arshape, PV_NONE,
539#else
540 (char_u *)NULL, PV_NONE,
541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000542 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
544#ifdef FEAT_RIGHTLEFT
545 (char_u *)&p_ari, PV_NONE,
546#else
547 (char_u *)NULL, PV_NONE,
548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
551#ifdef FEAT_FKMAP
552 (char_u *)&p_altkeymap, PV_NONE,
553#else
554 (char_u *)NULL, PV_NONE,
555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
558#if defined(FEAT_MBYTE)
559 (char_u *)&p_ambw, PV_NONE,
560 {(char_u *)"single", (char_u *)0L}
561#else
562 (char_u *)NULL, PV_NONE,
563 {(char_u *)0L, (char_u *)0L}
564#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100567#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100569 {(char_u *)FALSE, (char_u *)0L}
570#else
571 (char_u *)NULL, PV_NONE,
572 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100574 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"autoindent", "ai", P_BOOL|P_VI_DEF,
576 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autoprint", "ap", P_BOOL|P_VI_DEF,
579 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000582 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"autowrite", "aw", P_BOOL|P_VI_DEF,
585 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 {"autowriteall","awa", P_BOOL|P_VI_DEF,
588 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
591 (char_u *)&p_bg, PV_NONE,
592 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100593#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 (char_u *)"dark",
595#else
596 (char_u *)"light",
597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000598 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200599 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000601 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
603 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200606 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607#ifdef UNIX
608 {(char_u *)"yes", (char_u *)"auto"}
609#else
610 {(char_u *)"auto", (char_u *)"auto"}
611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200613 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
614 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000617 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618 (char_u *)&p_bex, PV_NONE,
619 {
620#ifdef VMS
621 (char_u *)"_",
622#else
623 (char_u *)"~",
624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200626 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627#ifdef FEAT_WILDIGN
628 (char_u *)&p_bsk, PV_NONE,
629 {(char_u *)"", (char_u *)0L}
630#else
631 (char_u *)NULL, PV_NONE,
632 {(char_u *)0L, (char_u *)0L}
633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100636#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638 {(char_u *)600L, (char_u *)0L}
639#else
640 (char_u *)NULL, PV_NONE,
641 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000642#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100643 SCRIPTID_INIT},
644 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
645#ifdef FEAT_BEVAL
646 (char_u *)&p_beval, PV_NONE,
647 {(char_u *)FALSE, (char_u *)0L}
648#else
649 (char_u *)NULL, PV_NONE,
650 {(char_u *)0L, (char_u *)0L}
651#endif
652 SCRIPTID_INIT},
653 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
654#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
655 (char_u *)&p_bexpr, PV_BEXPR,
656 {(char_u *)"", (char_u *)0L}
657#else
658 (char_u *)NULL, PV_NONE,
659 {(char_u *)0L, (char_u *)0L}
660#endif
661 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662 {"beautify", "bf", P_BOOL|P_VI_DEF,
663 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000664 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200665 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
666 (char_u *)&p_bo, PV_NONE,
667 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
669 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000670 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000673 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
675#ifdef FEAT_MBYTE
676 (char_u *)&p_bomb, PV_BOMB,
677#else
678 (char_u *)NULL, PV_NONE,
679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000680 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
682#ifdef FEAT_LINEBREAK
683 (char_u *)&p_breakat, PV_NONE,
684 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
685#else
686 (char_u *)NULL, PV_NONE,
687 {(char_u *)0L, (char_u *)0L}
688#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000689 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200690 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
691#ifdef FEAT_LINEBREAK
692 (char_u *)VAR_WIN, PV_BRI,
693 {(char_u *)FALSE, (char_u *)0L}
694#else
695 (char_u *)NULL, PV_NONE,
696 {(char_u *)0L, (char_u *)0L}
697#endif
698 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200699 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
700 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200701#ifdef FEAT_LINEBREAK
702 (char_u *)VAR_WIN, PV_BRIOPT,
703 {(char_u *)"", (char_u *)NULL}
704#else
705 (char_u *)NULL, PV_NONE,
706 {(char_u *)"", (char_u *)NULL}
707#endif
708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
710#ifdef FEAT_BROWSE
711 (char_u *)&p_bsdir, PV_NONE,
712 {(char_u *)"last", (char_u *)0L}
713#else
714 (char_u *)NULL, PV_NONE,
715 {(char_u *)0L, (char_u *)0L}
716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
719#if defined(FEAT_QUICKFIX)
720 (char_u *)&p_bh, PV_BH,
721 {(char_u *)"", (char_u *)0L}
722#else
723 (char_u *)NULL, PV_NONE,
724 {(char_u *)0L, (char_u *)0L}
725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
728 (char_u *)&p_bl, PV_BL,
729 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
732#if defined(FEAT_QUICKFIX)
733 (char_u *)&p_bt, PV_BT,
734 {(char_u *)"", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200740 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000741#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 (char_u *)&p_cmp, PV_NONE,
743 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
750#ifdef FEAT_SEARCHPATH
751 (char_u *)&p_cdpath, PV_NONE,
752 {(char_u *)",,", (char_u *)0L}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000757 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758 {"cedit", NULL, P_STRING,
759#ifdef FEAT_CMDWIN
760 (char_u *)&p_cedit, PV_NONE,
761 {(char_u *)"", (char_u *)CTRL_F_STR}
762#else
763 (char_u *)NULL, PV_NONE,
764 {(char_u *)0L, (char_u *)0L}
765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
768#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
769 (char_u *)&p_ccv, PV_NONE,
770 {(char_u *)"", (char_u *)0L}
771#else
772 (char_u *)NULL, PV_NONE,
773 {(char_u *)0L, (char_u *)0L}
774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000775 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
777#ifdef FEAT_CINDENT
778 (char_u *)&p_cin, PV_CIN,
779#else
780 (char_u *)NULL, PV_NONE,
781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#ifdef FEAT_CINDENT
785 (char_u *)&p_cink, PV_CINK,
786 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
787#else
788 (char_u *)NULL, PV_NONE,
789 {(char_u *)0L, (char_u *)0L}
790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000791 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#ifdef FEAT_CINDENT
794 (char_u *)&p_cino, PV_CINO,
795#else
796 (char_u *)NULL, PV_NONE,
797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000798 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200799 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000800#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
801 (char_u *)&p_cinw, PV_CINW,
802 {(char_u *)"if,else,while,do,for,switch",
803 (char_u *)0L}
804#else
805 (char_u *)NULL, PV_NONE,
806 {(char_u *)0L, (char_u *)0L}
807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200809 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810#ifdef FEAT_CLIPBOARD
811 (char_u *)&p_cb, PV_NONE,
812# ifdef FEAT_XCLIPBOARD
813 {(char_u *)"autoselect,exclude:cons\\|linux",
814 (char_u *)0L}
815# else
816 {(char_u *)"", (char_u *)0L}
817# endif
818#else
819 (char_u *)NULL, PV_NONE,
820 {(char_u *)"", (char_u *)0L}
821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000822 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
824 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
827#ifdef FEAT_CMDWIN
828 (char_u *)&p_cwh, PV_NONE,
829#else
830 (char_u *)NULL, PV_NONE,
831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000832 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200833 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200834#ifdef FEAT_SYN_HL
835 (char_u *)VAR_WIN, PV_CC,
836#else
837 (char_u *)NULL, PV_NONE,
838#endif
839 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000840 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
841 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000842 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200843 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
844 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845#ifdef FEAT_COMMENTS
846 (char_u *)&p_com, PV_COM,
847 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
848 (char_u *)0L}
849#else
850 (char_u *)NULL, PV_NONE,
851 {(char_u *)0L, (char_u *)0L}
852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000853 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200854 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000855#ifdef FEAT_FOLDING
856 (char_u *)&p_cms, PV_CMS,
857 {(char_u *)"/*%s*/", (char_u *)0L}
858#else
859 (char_u *)NULL, PV_NONE,
860 {(char_u *)0L, (char_u *)0L}
861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000862 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000863 /* P_PRI_MKRC isn't needed here, optval_default()
864 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000865 {"compatible", "cp", P_BOOL|P_RALL,
866 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000867 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200868 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000869#ifdef FEAT_INS_EXPAND
870 (char_u *)&p_cpt, PV_CPT,
871 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
872#else
873 (char_u *)NULL, PV_NONE,
874 {(char_u *)0L, (char_u *)0L}
875#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000876 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200877 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200878#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200879 (char_u *)VAR_WIN, PV_COCU,
880 {(char_u *)"", (char_u *)NULL}
881#else
882 (char_u *)NULL, PV_NONE,
883 {(char_u *)NULL, (char_u *)0L}
884#endif
885 SCRIPTID_INIT},
886 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
887#ifdef FEAT_CONCEAL
888 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200889#else
890 (char_u *)NULL, PV_NONE,
891#endif
892 {(char_u *)0L, (char_u *)0L}
893 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000894 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
895#ifdef FEAT_COMPL_FUNC
896 (char_u *)&p_cfu, PV_CFU,
897 {(char_u *)"", (char_u *)0L}
898#else
899 (char_u *)NULL, PV_NONE,
900 {(char_u *)0L, (char_u *)0L}
901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200903 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000904#ifdef FEAT_INS_EXPAND
905 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000906 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000907#else
908 (char_u *)NULL, PV_NONE,
909 {(char_u *)0L, (char_u *)0L}
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"confirm", "cf", P_BOOL|P_VI_DEF,
913#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
914 (char_u *)&p_confirm, PV_NONE,
915#else
916 (char_u *)NULL, PV_NONE,
917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000918 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000921 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
923 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000924 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
926 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000927 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
928 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200929 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200930#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200931 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200932 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200933#else
934 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200935 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200936#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200937 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_cspc, PV_NONE,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csprg, PV_NONE,
948 {(char_u *)"cscope", (char_u *)0L}
949#else
950 (char_u *)NULL, PV_NONE,
951 {(char_u *)0L, (char_u *)0L}
952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000953 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200954 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
956 (char_u *)&p_csqf, PV_NONE,
957 {(char_u *)"", (char_u *)0L}
958#else
959 (char_u *)NULL, PV_NONE,
960 {(char_u *)0L, (char_u *)0L}
961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000962 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200963 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
964#ifdef FEAT_CSCOPE
965 (char_u *)&p_csre, PV_NONE,
966#else
967 (char_u *)NULL, PV_NONE,
968#endif
969 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
971#ifdef FEAT_CSCOPE
972 (char_u *)&p_cst, PV_NONE,
973#else
974 (char_u *)NULL, PV_NONE,
975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000976 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
978#ifdef FEAT_CSCOPE
979 (char_u *)&p_csto, PV_NONE,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000984 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
985#ifdef FEAT_CSCOPE
986 (char_u *)&p_csverbose, PV_NONE,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200991 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
992#ifdef FEAT_CURSORBIND
993 (char_u *)VAR_WIN, PV_CRBIND,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000998 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
999#ifdef FEAT_SYN_HL
1000 (char_u *)VAR_WIN, PV_CUC,
1001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +01001005 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001006#ifdef FEAT_SYN_HL
1007 (char_u *)VAR_WIN, PV_CUL,
1008#else
1009 (char_u *)NULL, PV_NONE,
1010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001011 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012 {"debug", NULL, P_STRING|P_VI_DEF,
1013 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001014 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001015 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001017 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001018 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019#else
1020 (char_u *)NULL, PV_NONE,
1021 {(char_u *)NULL, (char_u *)0L}
1022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001023 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1025#ifdef FEAT_MBYTE
1026 (char_u *)&p_deco, PV_NONE,
1027#else
1028 (char_u *)NULL, PV_NONE,
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001031 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001033 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1039#ifdef FEAT_DIFF
1040 (char_u *)VAR_WIN, PV_DIFF,
1041#else
1042 (char_u *)NULL, PV_NONE,
1043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001045 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1047 (char_u *)&p_dex, PV_NONE,
1048 {(char_u *)"", (char_u *)0L}
1049#else
1050 (char_u *)NULL, PV_NONE,
1051 {(char_u *)0L, (char_u *)0L}
1052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001054 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1055 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056#ifdef FEAT_DIFF
1057 (char_u *)&p_dip, PV_NONE,
1058 {(char_u *)"filler", (char_u *)NULL}
1059#else
1060 (char_u *)NULL, PV_NONE,
1061 {(char_u *)"", (char_u *)NULL}
1062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1065#ifdef FEAT_DIGRAPHS
1066 (char_u *)&p_dg, PV_NONE,
1067#else
1068 (char_u *)NULL, PV_NONE,
1069#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001071 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1072 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001075 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001079#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 (char_u *)&p_ead, PV_NONE,
1081 {(char_u *)"both", (char_u *)0L}
1082#else
1083 (char_u *)NULL, PV_NONE,
1084 {(char_u *)NULL, (char_u *)0L}
1085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001086 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1088 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001090 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1091#if defined(FEAT_MBYTE)
1092 (char_u *)&p_emoji, PV_NONE,
1093 {(char_u *)TRUE, (char_u *)0L}
1094#else
1095 (char_u *)NULL, PV_NONE,
1096 {(char_u *)0L, (char_u *)0L}
1097#endif
1098 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001099 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100#ifdef FEAT_MBYTE
1101 (char_u *)&p_enc, PV_NONE,
1102 {(char_u *)ENC_DFLT, (char_u *)0L}
1103#else
1104 (char_u *)NULL, PV_NONE,
1105 {(char_u *)0L, (char_u *)0L}
1106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1109 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1112 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001113 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001114 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001115 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1118 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1121#ifdef FEAT_QUICKFIX
1122 (char_u *)&p_ef, PV_NONE,
1123 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1124#else
1125 (char_u *)NULL, PV_NONE,
1126 {(char_u *)NULL, (char_u *)0L}
1127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001128 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001129 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001131 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001132 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133#else
1134 (char_u *)NULL, PV_NONE,
1135 {(char_u *)NULL, (char_u *)0L}
1136#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001137 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138 {"esckeys", "ek", P_BOOL|P_VIM,
1139 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142#ifdef FEAT_AUTOCMD
1143 (char_u *)&p_ei, PV_NONE,
1144#else
1145 (char_u *)NULL, PV_NONE,
1146#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001147 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1149 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1152 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001154 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1155 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156#ifdef FEAT_MBYTE
1157 (char_u *)&p_fenc, PV_FENC,
1158 {(char_u *)"", (char_u *)0L}
1159#else
1160 (char_u *)NULL, PV_NONE,
1161 {(char_u *)0L, (char_u *)0L}
1162#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001163 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001164 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165#ifdef FEAT_MBYTE
1166 (char_u *)&p_fencs, PV_NONE,
1167 {(char_u *)"ucs-bom", (char_u *)0L}
1168#else
1169 (char_u *)NULL, PV_NONE,
1170 {(char_u *)0L, (char_u *)0L}
1171#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001173 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1174 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001175 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001177 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1180 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001181 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1182 (char_u *)&p_fic, PV_NONE,
1183 {
1184#ifdef CASE_INSENSITIVE_FILENAME
1185 (char_u *)TRUE,
1186#else
1187 (char_u *)FALSE,
1188#endif
1189 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001190 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191#ifdef FEAT_AUTOCMD
1192 (char_u *)&p_ft, PV_FT,
1193 {(char_u *)"", (char_u *)0L}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)0L, (char_u *)0L}
1197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001199 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1201 (char_u *)&p_fcs, PV_NONE,
1202 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1203#else
1204 (char_u *)NULL, PV_NONE,
1205 {(char_u *)"", (char_u *)0L}
1206#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001207 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001208 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1209 (char_u *)&p_fixeol, PV_FIXEOL,
1210 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1212#ifdef FEAT_FKMAP
1213 (char_u *)&p_fkmap, PV_NONE,
1214#else
1215 (char_u *)NULL, PV_NONE,
1216#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"flash", "fl", P_BOOL|P_VI_DEF,
1219 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001221 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001222#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001224 {(char_u *)"", (char_u *)0L}
1225#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 (char_u *)NULL, PV_NONE,
1227 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001228#endif
1229 SCRIPTID_INIT},
1230 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1231#ifdef FEAT_FOLDING
1232 (char_u *)VAR_WIN, PV_FDC,
1233 {(char_u *)FALSE, (char_u *)0L}
1234#else
1235 (char_u *)NULL, PV_NONE,
1236 {(char_u *)NULL, (char_u *)0L}
1237#endif
1238 SCRIPTID_INIT},
1239 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1240#ifdef FEAT_FOLDING
1241 (char_u *)VAR_WIN, PV_FEN,
1242 {(char_u *)TRUE, (char_u *)0L}
1243#else
1244 (char_u *)NULL, PV_NONE,
1245 {(char_u *)NULL, (char_u *)0L}
1246#endif
1247 SCRIPTID_INIT},
1248 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1249#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1250 (char_u *)VAR_WIN, PV_FDE,
1251 {(char_u *)"0", (char_u *)NULL}
1252#else
1253 (char_u *)NULL, PV_NONE,
1254 {(char_u *)NULL, (char_u *)0L}
1255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001258#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001260 {(char_u *)"#", (char_u *)NULL}
1261#else
1262 (char_u *)NULL, PV_NONE,
1263 {(char_u *)NULL, (char_u *)0L}
1264#endif
1265 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001267#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001269 {(char_u *)0L, (char_u *)0L}
1270#else
1271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)NULL, (char_u *)0L}
1273#endif
1274 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001275 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001276#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001278 {(char_u *)-1L, (char_u *)0L}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)NULL, (char_u *)0L}
1282#endif
1283 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001285 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001286#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001288 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001289#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 (char_u *)NULL, PV_NONE,
1291 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001292#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001293 SCRIPTID_INIT},
1294 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1295#ifdef FEAT_FOLDING
1296 (char_u *)VAR_WIN, PV_FDM,
1297 {(char_u *)"manual", (char_u *)NULL}
1298#else
1299 (char_u *)NULL, PV_NONE,
1300 {(char_u *)NULL, (char_u *)0L}
1301#endif
1302 SCRIPTID_INIT},
1303 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1304#ifdef FEAT_FOLDING
1305 (char_u *)VAR_WIN, PV_FML,
1306 {(char_u *)1L, (char_u *)0L}
1307#else
1308 (char_u *)NULL, PV_NONE,
1309 {(char_u *)NULL, (char_u *)0L}
1310#endif
1311 SCRIPTID_INIT},
1312 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1313#ifdef FEAT_FOLDING
1314 (char_u *)VAR_WIN, PV_FDN,
1315 {(char_u *)20L, (char_u *)0L}
1316#else
1317 (char_u *)NULL, PV_NONE,
1318 {(char_u *)NULL, (char_u *)0L}
1319#endif
1320 SCRIPTID_INIT},
1321 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1322#ifdef FEAT_FOLDING
1323 (char_u *)&p_fdo, PV_NONE,
1324 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1325 (char_u *)0L}
1326#else
1327 (char_u *)NULL, PV_NONE,
1328 {(char_u *)NULL, (char_u *)0L}
1329#endif
1330 SCRIPTID_INIT},
1331 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1332#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1333 (char_u *)VAR_WIN, PV_FDT,
1334 {(char_u *)"foldtext()", (char_u *)NULL}
1335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
1339 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001340 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001341#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001342 (char_u *)&p_fex, PV_FEX,
1343 {(char_u *)"", (char_u *)0L}
1344#else
1345 (char_u *)NULL, PV_NONE,
1346 {(char_u *)0L, (char_u *)0L}
1347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1350 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001351 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1352 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001353 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1354 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1356 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001358 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001360 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1361#ifdef HAVE_FSYNC
1362 (char_u *)&p_fs, PV_NONE,
1363 {(char_u *)TRUE, (char_u *)0L}
1364#else
1365 (char_u *)NULL, PV_NONE,
1366 {(char_u *)FALSE, (char_u *)0L}
1367#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001368 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1370 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372 {"graphic", "gr", P_BOOL|P_VI_DEF,
1373 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001375 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376#ifdef FEAT_QUICKFIX
1377 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001378 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379#else
1380 (char_u *)NULL, PV_NONE,
1381 {(char_u *)NULL, (char_u *)0L}
1382#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001383 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1385#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001386 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 {
1388# ifdef WIN3264
1389 /* may be changed to "grep -n" in os_win32.c */
1390 (char_u *)"findstr /n",
1391# else
1392# ifdef UNIX
1393 /* Add an extra file name so that grep will always
1394 * insert a file name in the match line. */
1395 (char_u *)"grep -n $* /dev/null",
1396# else
1397# ifdef VMS
1398 (char_u *)"SEARCH/NUMBERS ",
1399# else
1400 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001401# endif
1402# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001404 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405#else
1406 (char_u *)NULL, PV_NONE,
1407 {(char_u *)NULL, (char_u *)0L}
1408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001409 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001410 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001411#ifdef CURSOR_SHAPE
1412 (char_u *)&p_guicursor, PV_NONE,
1413 {
1414# ifdef FEAT_GUI
1415 (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 +01001416# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001417 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1418# endif
1419 (char_u *)0L}
1420#else
1421 (char_u *)NULL, PV_NONE,
1422 {(char_u *)NULL, (char_u *)0L}
1423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001424 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001425 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426#ifdef FEAT_GUI
1427 (char_u *)&p_guifont, PV_NONE,
1428 {(char_u *)"", (char_u *)0L}
1429#else
1430 (char_u *)NULL, PV_NONE,
1431 {(char_u *)NULL, (char_u *)0L}
1432#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001433 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001434 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1436 (char_u *)&p_guifontset, PV_NONE,
1437 {(char_u *)"", (char_u *)0L}
1438#else
1439 (char_u *)NULL, PV_NONE,
1440 {(char_u *)NULL, (char_u *)0L}
1441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001442 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001443 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1445 (char_u *)&p_guifontwide, PV_NONE,
1446 {(char_u *)"", (char_u *)0L}
1447#else
1448 (char_u *)NULL, PV_NONE,
1449 {(char_u *)NULL, (char_u *)0L}
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001453#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 (char_u *)&p_ghr, PV_NONE,
1455#else
1456 (char_u *)NULL, PV_NONE,
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001460#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 (char_u *)&p_go, PV_NONE,
1462# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001463 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001465 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466# endif
1467#else
1468 (char_u *)NULL, PV_NONE,
1469 {(char_u *)NULL, (char_u *)0L}
1470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"guipty", NULL, P_BOOL|P_VI_DEF,
1473#if defined(FEAT_GUI)
1474 (char_u *)&p_guipty, PV_NONE,
1475#else
1476 (char_u *)NULL, PV_NONE,
1477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001479 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001480#if defined(FEAT_GUI_TABLINE)
1481 (char_u *)&p_gtl, PV_NONE,
1482 {(char_u *)"", (char_u *)0L}
1483#else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)NULL, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001488 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001489#if defined(FEAT_GUI_TABLINE)
1490 (char_u *)&p_gtt, PV_NONE,
1491 {(char_u *)"", (char_u *)0L}
1492#else
1493 (char_u *)NULL, PV_NONE,
1494 {(char_u *)NULL, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1498 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001499 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1501 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1503 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"helpheight", "hh", P_NUM|P_VI_DEF,
1505#ifdef FEAT_WINDOWS
1506 (char_u *)&p_hh, PV_NONE,
1507#else
1508 (char_u *)NULL, PV_NONE,
1509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001510 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001511 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512#ifdef FEAT_MULTI_LANG
1513 (char_u *)&p_hlg, PV_NONE,
1514 {(char_u *)"", (char_u *)0L}
1515#else
1516 (char_u *)NULL, PV_NONE,
1517 {(char_u *)0L, (char_u *)0L}
1518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"hidden", "hid", P_BOOL|P_VI_DEF,
1521 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001522 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001523 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001525 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1526 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001527 {"history", "hi", P_NUM|P_VIM,
1528 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001529 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1531#ifdef FEAT_RIGHTLEFT
1532 (char_u *)&p_hkmap, PV_NONE,
1533#else
1534 (char_u *)NULL, PV_NONE,
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1538#ifdef FEAT_RIGHTLEFT
1539 (char_u *)&p_hkmapp, PV_NONE,
1540#else
1541 (char_u *)NULL, PV_NONE,
1542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001543 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1545 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 {"icon", NULL, P_BOOL|P_VI_DEF,
1548#ifdef FEAT_TITLE
1549 (char_u *)&p_icon, PV_NONE,
1550#else
1551 (char_u *)NULL, PV_NONE,
1552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"iconstring", NULL, P_STRING|P_VI_DEF,
1555#ifdef FEAT_TITLE
1556 (char_u *)&p_iconstring, PV_NONE,
1557#else
1558 (char_u *)NULL, PV_NONE,
1559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001560 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1562 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001564 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1565# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1566 (char_u *)&p_imaf, PV_NONE,
1567 {(char_u *)"", (char_u *)NULL}
1568# else
1569 (char_u *)NULL, PV_NONE,
1570 {(char_u *)NULL, (char_u *)0L}
1571# endif
1572 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001574#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575 (char_u *)&p_imak, PV_NONE,
1576#else
1577 (char_u *)NULL, PV_NONE,
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1581#ifdef USE_IM_CONTROL
1582 (char_u *)&p_imcmdline, PV_NONE,
1583#else
1584 (char_u *)NULL, PV_NONE,
1585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001587 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1588#ifdef USE_IM_CONTROL
1589 (char_u *)&p_imdisable, PV_NONE,
1590#else
1591 (char_u *)NULL, PV_NONE,
1592#endif
1593#ifdef __sgi
1594 {(char_u *)TRUE, (char_u *)0L}
1595#else
1596 {(char_u *)FALSE, (char_u *)0L}
1597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001598 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {"iminsert", "imi", P_NUM|P_VI_DEF,
1600 (char_u *)&p_iminsert, PV_IMI,
1601#ifdef B_IMODE_IM
1602 {(char_u *)B_IMODE_IM, (char_u *)0L}
1603#else
1604 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"imsearch", "ims", P_NUM|P_VI_DEF,
1608 (char_u *)&p_imsearch, PV_IMS,
1609#ifdef B_IMODE_IM
1610 {(char_u *)B_IMODE_IM, (char_u *)0L}
1611#else
1612 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001614 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001615 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001616# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1617 (char_u *)&p_imsf, PV_NONE,
1618 {(char_u *)"", (char_u *)NULL}
1619# else
1620 (char_u *)NULL, PV_NONE,
1621 {(char_u *)NULL, (char_u *)0L}
1622# endif
1623 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1625#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001626 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001627 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1628#else
1629 (char_u *)NULL, PV_NONE,
1630 {(char_u *)0L, (char_u *)0L}
1631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001632 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1634#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1635 (char_u *)&p_inex, PV_INEX,
1636 {(char_u *)"", (char_u *)0L}
1637#else
1638 (char_u *)NULL, PV_NONE,
1639 {(char_u *)0L, (char_u *)0L}
1640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001641 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001642 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1643 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1646#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1647 (char_u *)&p_inde, PV_INDE,
1648 {(char_u *)"", (char_u *)0L}
1649#else
1650 (char_u *)NULL, PV_NONE,
1651 {(char_u *)0L, (char_u *)0L}
1652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001653 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001654 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1656 (char_u *)&p_indk, PV_INDK,
1657 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1658#else
1659 (char_u *)NULL, PV_NONE,
1660 {(char_u *)0L, (char_u *)0L}
1661#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001662 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 {"infercase", "inf", P_BOOL|P_VI_DEF,
1664 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001665 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1667 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001668 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1670 (char_u *)&p_isf, PV_NONE,
1671 {
1672#ifdef BACKSLASH_IN_FILENAME
1673 /* Excluded are: & and ^ are special in cmd.exe
1674 * ( and ) are used in text separating fnames */
1675 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1676#else
1677# ifdef AMIGA
1678 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1679# else
1680# ifdef VMS
1681 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1682# else /* UNIX et al. */
1683# ifdef EBCDIC
1684 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1685# else
1686 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1687# endif
1688# endif
1689# endif
1690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001691 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1693 (char_u *)&p_isi, PV_NONE,
1694 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001695#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696 (char_u *)"@,48-57,_,128-167,224-235",
1697#else
1698# ifdef EBCDIC
1699 /* TODO: EBCDIC Check this! @ == isalpha()*/
1700 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1701 "112-120,128,140-142,156,158,172,"
1702 "174,186,191,203-207,219-225,235-239,"
1703 "251-254",
1704# else
1705 (char_u *)"@,48-57,_,192-255",
1706# endif
1707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001708 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1710 (char_u *)&p_isk, PV_ISK,
1711 {
1712#ifdef EBCDIC
1713 (char_u *)"@,240-249,_",
1714 /* TODO: EBCDIC Check this! @ == isalpha()*/
1715 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1716 "112-120,128,140-142,156,158,172,"
1717 "174,186,191,203-207,219-225,235-239,"
1718 "251-254",
1719#else
1720 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001721# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 (char_u *)"@,48-57,_,128-167,224-235"
1723# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001724 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725# endif
1726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001727 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001728 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1729 (char_u *)&p_isp, PV_NONE,
1730 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001731#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 || defined(VMS)
1733 (char_u *)"@,~-255",
1734#else
1735# ifdef EBCDIC
1736 /* all chars above 63 are printable */
1737 (char_u *)"63-255",
1738# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001739 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740# endif
1741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001742 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1744 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1747#ifdef FEAT_CRYPT
1748 (char_u *)&p_key, PV_KEY,
1749 {(char_u *)"", (char_u *)0L}
1750#else
1751 (char_u *)NULL, PV_NONE,
1752 {(char_u *)0L, (char_u *)0L}
1753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001755 {"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 +00001756#ifdef FEAT_KEYMAP
1757 (char_u *)&p_keymap, PV_KMAP,
1758 {(char_u *)"", (char_u *)0L}
1759#else
1760 (char_u *)NULL, PV_NONE,
1761 {(char_u *)"", (char_u *)0L}
1762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001764 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001766 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001768 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001770#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 (char_u *)":help",
1772#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001773# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001775# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001776# ifdef USEMAN_S
1777 (char_u *)"man -s",
1778# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001780# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781# endif
1782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001783 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001784 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785#ifdef FEAT_LANGMAP
1786 (char_u *)&p_langmap, PV_NONE,
1787 {(char_u *)"", /* unmatched } */
1788#else
1789 (char_u *)NULL, PV_NONE,
1790 {(char_u *)NULL,
1791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001793 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1795 (char_u *)&p_lm, PV_NONE,
1796#else
1797 (char_u *)NULL, PV_NONE,
1798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001799 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001800 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1801#ifdef FEAT_LANGMAP
1802 (char_u *)&p_lnr, PV_NONE,
1803#else
1804 (char_u *)NULL, PV_NONE,
1805#endif
1806 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001807 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1808#ifdef FEAT_LANGMAP
1809 (char_u *)&p_lrm, PV_NONE,
1810#else
1811 (char_u *)NULL, PV_NONE,
1812#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001813 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1815#ifdef FEAT_WINDOWS
1816 (char_u *)&p_ls, PV_NONE,
1817#else
1818 (char_u *)NULL, PV_NONE,
1819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1822 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1825#ifdef FEAT_LINEBREAK
1826 (char_u *)VAR_WIN, PV_LBR,
1827#else
1828 (char_u *)NULL, PV_NONE,
1829#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1832 (char_u *)&Rows, PV_NONE,
1833 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001834#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 (char_u *)25L,
1836#else
1837 (char_u *)24L,
1838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001839 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1841#ifdef FEAT_GUI
1842 (char_u *)&p_linespace, PV_NONE,
1843#else
1844 (char_u *)NULL, PV_NONE,
1845#endif
1846#ifdef FEAT_GUI_W32
1847 {(char_u *)1L, (char_u *)0L}
1848#else
1849 {(char_u *)0L, (char_u *)0L}
1850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"lisp", NULL, P_BOOL|P_VI_DEF,
1853#ifdef FEAT_LISP
1854 (char_u *)&p_lisp, PV_LISP,
1855#else
1856 (char_u *)NULL, PV_NONE,
1857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001859 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001861 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)"", (char_u *)0L}
1866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1869 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001871 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1875 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001877 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001878#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001879 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001880 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001881#else
1882 (char_u *)NULL, PV_NONE,
1883 {(char_u *)"", (char_u *)0L}
1884#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001885 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001886 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001887#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001888 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001889 {(char_u *)TRUE, (char_u *)0L}
1890#else
1891 (char_u *)NULL, PV_NONE,
1892 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001893#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001894 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"magic", NULL, P_BOOL|P_VI_DEF,
1896 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001897 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001898 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899#ifdef FEAT_QUICKFIX
1900 (char_u *)&p_mef, PV_NONE,
1901 {(char_u *)"", (char_u *)0L}
1902#else
1903 (char_u *)NULL, PV_NONE,
1904 {(char_u *)NULL, (char_u *)0L}
1905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001906 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001907 {"makeencoding","menc", P_STRING|P_VI_DEF,
1908#ifdef FEAT_MBYTE
1909 (char_u *)&p_menc, PV_MENC,
1910 {(char_u *)"", (char_u *)0L}
1911#else
1912 (char_u *)NULL, PV_NONE,
1913 {(char_u *)0L, (char_u *)0L}
1914#endif
1915 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1917#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001918 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001919# ifdef VMS
1920 {(char_u *)"MMS", (char_u *)0L}
1921# else
1922 {(char_u *)"make", (char_u *)0L}
1923# endif
1924#else
1925 (char_u *)NULL, PV_NONE,
1926 {(char_u *)NULL, (char_u *)0L}
1927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001929 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1932 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 {"matchtime", "mat", P_NUM|P_VI_DEF,
1934 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001936 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001937#ifdef FEAT_MBYTE
1938 (char_u *)&p_mco, PV_NONE,
1939#else
1940 (char_u *)NULL, PV_NONE,
1941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001942 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1944#ifdef FEAT_EVAL
1945 (char_u *)&p_mfd, PV_NONE,
1946#else
1947 (char_u *)NULL, PV_NONE,
1948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1951 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"maxmem", "mm", P_NUM|P_VI_DEF,
1954 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1956 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001957 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1958 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001960 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1961 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1963 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"menuitems", "mis", P_NUM|P_VI_DEF,
1965#ifdef FEAT_MENU
1966 (char_u *)&p_mis, PV_NONE,
1967#else
1968 (char_u *)NULL, PV_NONE,
1969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"mesg", NULL, P_BOOL|P_VI_DEF,
1972 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001973 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001974 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001975#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001976 (char_u *)&p_msm, PV_NONE,
1977 {(char_u *)"460000,2000,500", (char_u *)0L}
1978#else
1979 (char_u *)NULL, PV_NONE,
1980 {(char_u *)0L, (char_u *)0L}
1981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 {"modeline", "ml", P_BOOL|P_VIM,
1984 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"modelines", "mls", P_NUM|P_VI_DEF,
1987 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1990 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1993 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"more", NULL, P_BOOL|P_VIM,
1996 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1999 (char_u *)&p_mouse, PV_NONE,
2000 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002001#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 (char_u *)"a",
2003#else
2004 (char_u *)"",
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2008#ifdef FEAT_GUI
2009 (char_u *)&p_mousef, PV_NONE,
2010#else
2011 (char_u *)NULL, PV_NONE,
2012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002014 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2015#ifdef FEAT_GUI
2016 (char_u *)&p_mh, PV_NONE,
2017#else
2018 (char_u *)NULL, PV_NONE,
2019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002020 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2022 (char_u *)&p_mousem, PV_NONE,
2023 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002024#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 (char_u *)"popup",
2026#else
2027# if defined(MACOS)
2028 (char_u *)"popup_setpos",
2029# else
2030 (char_u *)"extend",
2031# endif
2032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002034 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035#ifdef FEAT_MOUSESHAPE
2036 (char_u *)&p_mouseshape, PV_NONE,
2037 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2038#else
2039 (char_u *)NULL, PV_NONE,
2040 {(char_u *)NULL, (char_u *)0L}
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2044 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002046 {"mzquantum", "mzq", P_NUM,
2047#ifdef FEAT_MZSCHEME
2048 (char_u *)&p_mzq, PV_NONE,
2049#else
2050 (char_u *)NULL, PV_NONE,
2051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002052 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {"novice", NULL, P_BOOL|P_VI_DEF,
2054 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002055 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002056 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002058 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2061 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002062 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002063 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2064#ifdef FEAT_LINEBREAK
2065 (char_u *)VAR_WIN, PV_NUW,
2066#else
2067 (char_u *)NULL, PV_NONE,
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002070 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002071#ifdef FEAT_COMPL_FUNC
2072 (char_u *)&p_ofu, PV_OFU,
2073 {(char_u *)"", (char_u *)0L}
2074#else
2075 (char_u *)NULL, PV_NONE,
2076 {(char_u *)0L, (char_u *)0L}
2077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 {"open", NULL, P_BOOL|P_VI_DEF,
2080 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002081 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002082 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002083#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002084 (char_u *)&p_odev, PV_NONE,
2085#else
2086 (char_u *)NULL, PV_NONE,
2087#endif
2088 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002090 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2091 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 {"optimize", "opt", P_BOOL|P_VI_DEF,
2094 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002098 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002099 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2100 |P_SECURE,
2101 (char_u *)&p_pp, PV_NONE,
2102 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2103 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002104 {"paragraphs", "para", P_STRING|P_VI_DEF,
2105 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002106 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002108 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2112 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2115#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2116 (char_u *)&p_pex, PV_NONE,
2117 {(char_u *)"", (char_u *)0L}
2118#else
2119 (char_u *)NULL, PV_NONE,
2120 {(char_u *)0L, (char_u *)0L}
2121#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002122 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002123 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002127 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002129#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 (char_u *)".,,",
2131#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002135 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002136#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002137 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002138 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002142#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002143 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2145 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002146 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002147 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2149 (char_u *)&p_pvh, PV_NONE,
2150#else
2151 (char_u *)NULL, PV_NONE,
2152#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2155#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2156 (char_u *)VAR_WIN, PV_PVW,
2157#else
2158 (char_u *)NULL, PV_NONE,
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002161 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162#ifdef FEAT_PRINTER
2163 (char_u *)&p_pdev, PV_NONE,
2164 {(char_u *)"", (char_u *)0L}
2165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 {"printencoding", "penc", P_STRING|P_VI_DEF,
2171#ifdef FEAT_POSTSCRIPT
2172 (char_u *)&p_penc, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002178 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002179 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180#ifdef FEAT_POSTSCRIPT
2181 (char_u *)&p_pexpr, PV_NONE,
2182 {(char_u *)"", (char_u *)0L}
2183#else
2184 (char_u *)NULL, PV_NONE,
2185 {(char_u *)NULL, (char_u *)0L}
2186#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"printfont", "pfn", P_STRING|P_VI_DEF,
2189#ifdef FEAT_PRINTER
2190 (char_u *)&p_pfn, PV_NONE,
2191 {
2192# ifdef MSWIN
2193 (char_u *)"Courier_New:h10",
2194# else
2195 (char_u *)"courier",
2196# endif
2197 (char_u *)0L}
2198#else
2199 (char_u *)NULL, PV_NONE,
2200 {(char_u *)NULL, (char_u *)0L}
2201#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002202 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2204#ifdef FEAT_PRINTER
2205 (char_u *)&p_header, PV_NONE,
2206 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2207#else
2208 (char_u *)NULL, PV_NONE,
2209 {(char_u *)NULL, (char_u *)0L}
2210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002212 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2213#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2214 (char_u *)&p_pmcs, PV_NONE,
2215 {(char_u *)"", (char_u *)0L}
2216#else
2217 (char_u *)NULL, PV_NONE,
2218 {(char_u *)NULL, (char_u *)0L}
2219#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002220 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002221 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2222#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2223 (char_u *)&p_pmfn, PV_NONE,
2224 {(char_u *)"", (char_u *)0L}
2225#else
2226 (char_u *)NULL, PV_NONE,
2227 {(char_u *)NULL, (char_u *)0L}
2228#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002230 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231#ifdef FEAT_PRINTER
2232 (char_u *)&p_popt, PV_NONE,
2233 {(char_u *)"", (char_u *)0L}
2234#else
2235 (char_u *)NULL, PV_NONE,
2236 {(char_u *)NULL, (char_u *)0L}
2237#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002240 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002241 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002242 {"pumheight", "ph", P_NUM|P_VI_DEF,
2243#ifdef FEAT_INS_EXPAND
2244 (char_u *)&p_ph, PV_NONE,
2245#else
2246 (char_u *)NULL, PV_NONE,
2247#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002248 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002249 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002250#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002251 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002252 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002253#else
2254 (char_u *)NULL, PV_NONE,
2255 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002256#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002257 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002258 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002259#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002260 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002261 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002262#else
2263 (char_u *)NULL, PV_NONE,
2264 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002265#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002266 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002267 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2268#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2269 (char_u *)&p_pyx, PV_NONE,
2270#else
2271 (char_u *)NULL, PV_NONE,
2272#endif
2273 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2274 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002275 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2276#ifdef FEAT_TEXTOBJ
2277 (char_u *)&p_qe, PV_QE,
2278 {(char_u *)"\\", (char_u *)0L}
2279#else
2280 (char_u *)NULL, PV_NONE,
2281 {(char_u *)NULL, (char_u *)0L}
2282#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2285 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002286 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"redraw", NULL, P_BOOL|P_VI_DEF,
2288 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002290 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2291#ifdef FEAT_RELTIME
2292 (char_u *)&p_rdt, PV_NONE,
2293#else
2294 (char_u *)NULL, PV_NONE,
2295#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002296 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002297 {"regexpengine", "re", P_NUM|P_VI_DEF,
2298 (char_u *)&p_re, PV_NONE,
2299 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002300 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2301 (char_u *)VAR_WIN, PV_RNU,
2302 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"remap", NULL, P_BOOL|P_VI_DEF,
2304 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002306 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002307#ifdef FEAT_RENDER_OPTIONS
2308 (char_u *)&p_rop, PV_NONE,
2309 {(char_u *)"", (char_u *)0L}
2310#else
2311 (char_u *)NULL, PV_NONE,
2312 {(char_u *)NULL, (char_u *)0L}
2313#endif
2314 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"report", NULL, P_NUM|P_VI_DEF,
2316 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2319#ifdef WIN3264
2320 (char_u *)&p_rs, PV_NONE,
2321#else
2322 (char_u *)NULL, PV_NONE,
2323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2326#ifdef FEAT_RIGHTLEFT
2327 (char_u *)&p_ri, PV_NONE,
2328#else
2329 (char_u *)NULL, PV_NONE,
2330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2333#ifdef FEAT_RIGHTLEFT
2334 (char_u *)VAR_WIN, PV_RL,
2335#else
2336 (char_u *)NULL, PV_NONE,
2337#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002338 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2340#ifdef FEAT_RIGHTLEFT
2341 (char_u *)VAR_WIN, PV_RLC,
2342 {(char_u *)"search", (char_u *)NULL}
2343#else
2344 (char_u *)NULL, PV_NONE,
2345 {(char_u *)NULL, (char_u *)0L}
2346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002348 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002349#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002350 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002351 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002352#else
2353 (char_u *)NULL, PV_NONE,
2354 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002355#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002356 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2358#ifdef FEAT_CMDL_INFO
2359 (char_u *)&p_ru, PV_NONE,
2360#else
2361 (char_u *)NULL, PV_NONE,
2362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2365#ifdef FEAT_STL_OPT
2366 (char_u *)&p_ruf, PV_NONE,
2367#else
2368 (char_u *)NULL, PV_NONE,
2369#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002371 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2372 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2375 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2377 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2380#ifdef FEAT_SCROLLBIND
2381 (char_u *)VAR_WIN, PV_SCBIND,
2382#else
2383 (char_u *)NULL, PV_NONE,
2384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2387 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2390 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002392 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393#ifdef FEAT_SCROLLBIND
2394 (char_u *)&p_sbo, PV_NONE,
2395 {(char_u *)"ver,jump", (char_u *)0L}
2396#else
2397 (char_u *)NULL, PV_NONE,
2398 {(char_u *)0L, (char_u *)0L}
2399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"sections", "sect", P_STRING|P_VI_DEF,
2402 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2406 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)"inclusive", (char_u *)0L}
2411 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002412 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002414 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002415 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416#ifdef FEAT_SESSION
2417 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002418 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 (char_u *)0L}
2420#else
2421 (char_u *)NULL, PV_NONE,
2422 {(char_u *)0L, (char_u *)0L}
2423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002424 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2426 (char_u *)&p_sh, PV_NONE,
2427 {
2428#ifdef VMS
2429 (char_u *)"-",
2430#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002431# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002433# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435# endif
2436#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2439 (char_u *)&p_shcf, PV_NONE,
2440 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002441#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 (char_u *)"/c",
2443#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002446 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2448#ifdef FEAT_QUICKFIX
2449 (char_u *)&p_sp, PV_NONE,
2450 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002451#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453#else
2454 (char_u *)">",
2455#endif
2456 (char_u *)0L}
2457#else
2458 (char_u *)NULL, PV_NONE,
2459 {(char_u *)0L, (char_u *)0L}
2460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2463 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2466 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2469#ifdef BACKSLASH_IN_FILENAME
2470 (char_u *)&p_ssl, PV_NONE,
2471#else
2472 (char_u *)NULL, PV_NONE,
2473#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002474 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002475 {"shelltemp", "stmp", P_BOOL,
2476 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 {"shelltype", "st", P_NUM|P_VI_DEF,
2479#ifdef AMIGA
2480 (char_u *)&p_st, PV_NONE,
2481#else
2482 (char_u *)NULL, PV_NONE,
2483#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002484 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2486 (char_u *)&p_sxq, PV_NONE,
2487 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002488#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 (char_u *)"\"",
2490#else
2491 (char_u *)"",
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002494 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2495 (char_u *)&p_sxe, PV_NONE,
2496 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002497#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002498 (char_u *)"\"&|<>()@^",
2499#else
2500 (char_u *)"",
2501#endif
2502 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2504 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2507 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2510 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)"", (char_u *)"filnxtToO"}
2512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2517#ifdef FEAT_LINEBREAK
2518 (char_u *)&p_sbr, PV_NONE,
2519#else
2520 (char_u *)NULL, PV_NONE,
2521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"showcmd", "sc", P_BOOL|P_VIM,
2524#ifdef FEAT_CMDL_INFO
2525 (char_u *)&p_sc, PV_NONE,
2526#else
2527 (char_u *)NULL, PV_NONE,
2528#endif
2529 {(char_u *)FALSE,
2530#ifdef UNIX
2531 (char_u *)FALSE
2532#else
2533 (char_u *)TRUE
2534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2537 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2540 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"showmode", "smd", P_BOOL|P_VIM,
2543 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002545 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2546#ifdef FEAT_WINDOWS
2547 (char_u *)&p_stal, PV_NONE,
2548#else
2549 (char_u *)NULL, PV_NONE,
2550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2553 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2556 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002558 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2559#ifdef FEAT_SIGNS
2560 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002561 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002562#else
2563 (char_u *)NULL, PV_NONE,
2564 {(char_u *)NULL, (char_u *)0L}
2565#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2568 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2571 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2574#ifdef FEAT_SMARTINDENT
2575 (char_u *)&p_si, PV_SI,
2576#else
2577 (char_u *)NULL, PV_NONE,
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2581 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2584 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2587 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002589 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002590#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002591 (char_u *)VAR_WIN, PV_SPELL,
2592#else
2593 (char_u *)NULL, PV_NONE,
2594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002596 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002597#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002598 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002599 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002600#else
2601 (char_u *)NULL, PV_NONE,
2602 {(char_u *)0L, (char_u *)0L}
2603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002605 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2606 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002607#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002608 (char_u *)&p_spf, PV_SPF,
2609 {(char_u *)"", (char_u *)0L}
2610#else
2611 (char_u *)NULL, PV_NONE,
2612 {(char_u *)0L, (char_u *)0L}
2613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002615 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2616 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002617#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002618 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002619 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002620#else
2621 (char_u *)NULL, PV_NONE,
2622 {(char_u *)0L, (char_u *)0L}
2623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002625 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002626#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002627 (char_u *)&p_sps, PV_NONE,
2628 {(char_u *)"best", (char_u *)0L}
2629#else
2630 (char_u *)NULL, PV_NONE,
2631 {(char_u *)0L, (char_u *)0L}
2632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2635#ifdef FEAT_WINDOWS
2636 (char_u *)&p_sb, PV_NONE,
2637#else
2638 (char_u *)NULL, PV_NONE,
2639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002640 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002642#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 (char_u *)&p_spr, PV_NONE,
2644#else
2645 (char_u *)NULL, PV_NONE,
2646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2649 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2652#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002653 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654#else
2655 (char_u *)NULL, PV_NONE,
2656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002658 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 (char_u *)&p_su, PV_NONE,
2660 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002662 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002663#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 (char_u *)&p_sua, PV_SUA,
2665 {(char_u *)"", (char_u *)0L}
2666#else
2667 (char_u *)NULL, PV_NONE,
2668 {(char_u *)0L, (char_u *)0L}
2669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2672 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 {"swapsync", "sws", P_STRING|P_VI_DEF,
2675 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002677 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002679 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002680 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2681#ifdef FEAT_SYN_HL
2682 (char_u *)&p_smc, PV_SMC,
2683 {(char_u *)3000L, (char_u *)0L}
2684#else
2685 (char_u *)NULL, PV_NONE,
2686 {(char_u *)0L, (char_u *)0L}
2687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002688 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002689 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690#ifdef FEAT_SYN_HL
2691 (char_u *)&p_syn, PV_SYN,
2692 {(char_u *)"", (char_u *)0L}
2693#else
2694 (char_u *)NULL, PV_NONE,
2695 {(char_u *)0L, (char_u *)0L}
2696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002698 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2699#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002700 (char_u *)&p_tal, PV_NONE,
2701#else
2702 (char_u *)NULL, PV_NONE,
2703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002705 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2706#ifdef FEAT_WINDOWS
2707 (char_u *)&p_tpm, PV_NONE,
2708#else
2709 (char_u *)NULL, PV_NONE,
2710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2713 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2716 (char_u *)&p_tbs, PV_NONE,
2717#ifdef VMS /* binary searching doesn't appear to work on VMS */
2718 {(char_u *)0L, (char_u *)0L}
2719#else
2720 {(char_u *)TRUE, (char_u *)0L}
2721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002723 {"tagcase", "tc", P_STRING|P_VIM,
2724 (char_u *)&p_tc, PV_TC,
2725 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"taglength", "tl", P_NUM|P_VI_DEF,
2727 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"tagrelative", "tr", P_BOOL|P_VIM,
2730 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002732 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002733 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002734 {
2735#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2736 (char_u *)"./tags,./TAGS,tags,TAGS",
2737#else
2738 (char_u *)"./tags,tags",
2739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002741 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2742 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002743 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002744 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002745#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002746 (char_u *)&p_tcldll, PV_NONE,
2747 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002748#else
2749 (char_u *)NULL, PV_NONE,
2750 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002751#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002752 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2754 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2757#ifdef FEAT_ARABIC
2758 (char_u *)&p_tbidi, PV_NONE,
2759#else
2760 (char_u *)NULL, PV_NONE,
2761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2764#ifdef FEAT_MBYTE
2765 (char_u *)&p_tenc, PV_NONE,
2766 {(char_u *)"", (char_u *)0L}
2767#else
2768 (char_u *)NULL, PV_NONE,
2769 {(char_u *)0L, (char_u *)0L}
2770#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002772 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2773#ifdef FEAT_TERMGUICOLORS
2774 (char_u *)&p_tgc, PV_NONE,
2775 {(char_u *)FALSE, (char_u *)FALSE}
2776#else
2777 (char_u*)NULL, PV_NONE,
2778 {(char_u *)FALSE, (char_u *)FALSE}
2779#endif
2780 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"terse", NULL, P_BOOL|P_VI_DEF,
2782 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"textauto", "ta", P_BOOL|P_VIM,
2785 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2787 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2789 (char_u *)&p_tx, PV_TX,
2790 {
2791#ifdef USE_CRNL
2792 (char_u *)TRUE,
2793#else
2794 (char_u *)FALSE,
2795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002797 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002800 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002802 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803#else
2804 (char_u *)NULL, PV_NONE,
2805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2808 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"timeout", "to", P_BOOL|P_VI_DEF,
2811 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2814 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 {"title", NULL, P_BOOL|P_VI_DEF,
2817#ifdef FEAT_TITLE
2818 (char_u *)&p_title, PV_NONE,
2819#else
2820 (char_u *)NULL, PV_NONE,
2821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"titlelen", NULL, P_NUM|P_VI_DEF,
2824#ifdef FEAT_TITLE
2825 (char_u *)&p_titlelen, PV_NONE,
2826#else
2827 (char_u *)NULL, PV_NONE,
2828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002830 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831#ifdef FEAT_TITLE
2832 (char_u *)&p_titleold, PV_NONE,
2833 {(char_u *)N_("Thanks for flying Vim"),
2834 (char_u *)0L}
2835#else
2836 (char_u *)NULL, PV_NONE,
2837 {(char_u *)0L, (char_u *)0L}
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"titlestring", NULL, P_STRING|P_VI_DEF,
2841#ifdef FEAT_TITLE
2842 (char_u *)&p_titlestring, PV_NONE,
2843#else
2844 (char_u *)NULL, PV_NONE,
2845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002847 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002848#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002851#else
2852 (char_u *)NULL, PV_NONE,
2853 {(char_u *)0L, (char_u *)0L}
2854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002857#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002859 {(char_u *)"small", (char_u *)0L}
2860#else
2861 (char_u *)NULL, PV_NONE,
2862 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002864 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2866 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002867 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2869 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2872 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2875 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2878#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2879 (char_u *)&p_ttym, PV_NONE,
2880#else
2881 (char_u *)NULL, PV_NONE,
2882#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2885 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2888 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002889 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002890 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2891 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002892#ifdef FEAT_PERSISTENT_UNDO
2893 (char_u *)&p_udir, PV_NONE,
2894 {(char_u *)".", (char_u *)0L}
2895#else
2896 (char_u *)NULL, PV_NONE,
2897 {(char_u *)0L, (char_u *)0L}
2898#endif
2899 SCRIPTID_INIT},
2900 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2901#ifdef FEAT_PERSISTENT_UNDO
2902 (char_u *)&p_udf, PV_UDF,
2903#else
2904 (char_u *)NULL, PV_NONE,
2905#endif
2906 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002908 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002910#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 (char_u *)1000L,
2912#else
2913 (char_u *)100L,
2914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002915 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002916 {"undoreload", "ur", P_NUM|P_VI_DEF,
2917 (char_u *)&p_ur, PV_NONE,
2918 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"updatecount", "uc", P_NUM|P_VI_DEF,
2920 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"updatetime", "ut", P_NUM|P_VI_DEF,
2923 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"verbose", "vbs", P_NUM|P_VI_DEF,
2926 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002928 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2929 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002930 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2932#ifdef FEAT_SESSION
2933 (char_u *)&p_vdir, PV_NONE,
2934 {(char_u *)DFLT_VDIR, (char_u *)0L}
2935#else
2936 (char_u *)NULL, PV_NONE,
2937 {(char_u *)0L, (char_u *)0L}
2938#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002940 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941#ifdef FEAT_SESSION
2942 (char_u *)&p_vop, PV_NONE,
2943 {(char_u *)"folds,options,cursor", (char_u *)0L}
2944#else
2945 (char_u *)NULL, PV_NONE,
2946 {(char_u *)0L, (char_u *)0L}
2947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002949 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950#ifdef FEAT_VIMINFO
2951 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002952#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002953 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954#else
2955# ifdef AMIGA
2956 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002957 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002959 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960# endif
2961#endif
2962#else
2963 (char_u *)NULL, PV_NONE,
2964 {(char_u *)0L, (char_u *)0L}
2965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002966 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002967 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2968 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969#ifdef FEAT_VIRTUALEDIT
2970 (char_u *)&p_ve, PV_NONE,
2971 {(char_u *)"", (char_u *)""}
2972#else
2973 (char_u *)NULL, PV_NONE,
2974 {(char_u *)0L, (char_u *)0L}
2975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002976 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2978 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"w300", NULL, P_NUM|P_VI_DEF,
2981 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 {"w1200", NULL, P_NUM|P_VI_DEF,
2984 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002985 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 {"w9600", NULL, P_NUM|P_VI_DEF,
2987 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 {"warn", NULL, P_BOOL|P_VI_DEF,
2990 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002991 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2993 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002995 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002997 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 {"wildchar", "wc", P_NUM|P_VIM,
2999 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003000 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3001 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003002 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003004 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003005 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006#ifdef FEAT_WILDIGN
3007 (char_u *)&p_wig, PV_NONE,
3008#else
3009 (char_u *)NULL, PV_NONE,
3010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003012 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3013 (char_u *)&p_wic, PV_NONE,
3014 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3016#ifdef FEAT_WILDMENU
3017 (char_u *)&p_wmnu, PV_NONE,
3018#else
3019 (char_u *)NULL, PV_NONE,
3020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003021 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003022 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003025 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3026#ifdef FEAT_CMDL_COMPL
3027 (char_u *)&p_wop, PV_NONE,
3028 {(char_u *)"", (char_u *)0L}
3029#else
3030 (char_u *)NULL, PV_NONE,
3031 {(char_u *)NULL, (char_u *)0L}
3032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003033 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3035#ifdef FEAT_WAK
3036 (char_u *)&p_wak, PV_NONE,
3037 {(char_u *)"menu", (char_u *)0L}
3038#else
3039 (char_u *)NULL, PV_NONE,
3040 {(char_u *)NULL, (char_u *)0L}
3041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003044 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003045 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 {"winheight", "wh", P_NUM|P_VI_DEF,
3047#ifdef FEAT_WINDOWS
3048 (char_u *)&p_wh, PV_NONE,
3049#else
3050 (char_u *)NULL, PV_NONE,
3051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003052 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003054#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 (char_u *)VAR_WIN, PV_WFH,
3056#else
3057 (char_u *)NULL, PV_NONE,
3058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003059 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003060 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003061#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003062 (char_u *)VAR_WIN, PV_WFW,
3063#else
3064 (char_u *)NULL, PV_NONE,
3065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3068#ifdef FEAT_WINDOWS
3069 (char_u *)&p_wmh, PV_NONE,
3070#else
3071 (char_u *)NULL, PV_NONE,
3072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003073 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003075#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 (char_u *)&p_wmw, PV_NONE,
3077#else
3078 (char_u *)NULL, PV_NONE,
3079#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003080 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003082#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 (char_u *)&p_wiw, PV_NONE,
3084#else
3085 (char_u *)NULL, PV_NONE,
3086#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003087 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3089 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003090 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3092 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003093 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3095 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003096 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 {"write", NULL, P_BOOL|P_VI_DEF,
3098 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003099 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 {"writeany", "wa", P_BOOL|P_VI_DEF,
3101 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003102 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3104 (char_u *)&p_wb, PV_NONE,
3105 {
3106#ifdef FEAT_WRITEBACKUP
3107 (char_u *)TRUE,
3108#else
3109 (char_u *)FALSE,
3110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003111 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112 {"writedelay", "wd", P_NUM|P_VI_DEF,
3113 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003114 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115
3116/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003117#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003119 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120
3121 p_term("t_AB", T_CAB)
3122 p_term("t_AF", T_CAF)
3123 p_term("t_AL", T_CAL)
3124 p_term("t_al", T_AL)
3125 p_term("t_bc", T_BC)
3126 p_term("t_cd", T_CD)
3127 p_term("t_ce", T_CE)
3128 p_term("t_cl", T_CL)
3129 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003130 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_Co", T_CCO)
3132 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003133 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003135#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_CV", T_CSV)
3137#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138 p_term("t_da", T_DA)
3139 p_term("t_db", T_DB)
3140 p_term("t_DL", T_CDL)
3141 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003142 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 p_term("t_fs", T_FS)
3144 p_term("t_IE", T_CIE)
3145 p_term("t_IS", T_CIS)
3146 p_term("t_ke", T_KE)
3147 p_term("t_ks", T_KS)
3148 p_term("t_le", T_LE)
3149 p_term("t_mb", T_MB)
3150 p_term("t_md", T_MD)
3151 p_term("t_me", T_ME)
3152 p_term("t_mr", T_MR)
3153 p_term("t_ms", T_MS)
3154 p_term("t_nd", T_ND)
3155 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003156 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_RI", T_CRI)
3158 p_term("t_RV", T_CRV)
3159 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003161 p_term("t_Sf", T_CSF)
3162 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003164 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_te", T_TE)
3167 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003168 p_term("t_ts", T_TS)
3169 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 p_term("t_ue", T_UE)
3171 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003172 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_vb", T_VB)
3174 p_term("t_ve", T_VE)
3175 p_term("t_vi", T_VI)
3176 p_term("t_vs", T_VS)
3177 p_term("t_WP", T_CWP)
Bram Moolenaar9f928862017-04-11 22:44:05 +02003178 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003180 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 p_term("t_xs", T_XS)
3182 p_term("t_ZH", T_CZH)
3183 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003184 p_term("t_8f", T_8F)
3185 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003186 p_term("t_BE", T_BE)
3187 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188
3189/* terminal key codes are not in here */
3190
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003191 /* end marker */
3192 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193};
3194
3195#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3196
3197#ifdef FEAT_MBYTE
3198static char *(p_ambw_values[]) = {"single", "double", NULL};
3199#endif
3200static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003201static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003203#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003204static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003205#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003206#ifdef FEAT_CMDL_COMPL
3207static char *(p_wop_values[]) = {"tagfile", NULL};
3208#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209#ifdef FEAT_WAK
3210static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3211#endif
3212static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3214static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216#ifdef FEAT_BROWSE
3217static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3218#endif
3219#ifdef FEAT_SCROLLBIND
3220static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3221#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003222static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003223#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3225#endif
3226#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003227# ifdef FEAT_AUTOCMD
3228static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3229# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003231# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3233#endif
3234static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3235#ifdef FEAT_FOLDING
3236static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003237# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003239# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240 NULL};
3241static char *(p_fcl_values[]) = {"all", NULL};
3242#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003244static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003245#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003246#ifdef FEAT_SIGNS
3247static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003250static void set_option_default(int, int opt_flags, int compatible);
3251static void set_options_default(int opt_flags);
3252static char_u *term_bg_default(void);
3253static void did_set_option(int opt_idx, int opt_flags, int new_value);
3254static char_u *illegal_char(char_u *, int);
3255static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003257static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
3259#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003260static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003262static char_u *option_expand(int opt_idx, char_u *val);
3263static void didset_options(void);
3264static void didset_options2(void);
3265static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003266#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003267static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003268#else
3269# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3270#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003271static void set_string_option_global(int opt_idx, char_u **varp);
3272static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3273static 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);
3274static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003275#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003277#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003281#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003282static char_u *did_set_spell_option(int is_spellfile);
3283static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003284#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003285#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003286static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003287#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003288static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3289static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3290static void check_redraw(long_u flags);
3291static int findoption(char_u *);
3292static int find_key_option(char_u *);
3293static void showoptions(int all, int opt_flags);
3294static int optval_default(struct vimoption *, char_u *varp);
3295static void showoneopt(struct vimoption *, int opt_flags);
3296static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3297static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3298static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3299static int istermoption(struct vimoption *);
3300static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3301static char_u *get_varp(struct vimoption *);
3302static void option_value2string(struct vimoption *, int opt_flags);
3303static void check_winopt(winopt_T *wop);
3304static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003306static void langmap_init(void);
3307static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003309static void paste_option_changed(void);
3310static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003314static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3315static int check_opt_strings(char_u *val, char **values, int);
3316static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003317#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003318static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320
3321/*
3322 * Initialize the options, first part.
3323 *
3324 * Called only once from main(), just after creating the first buffer.
3325 */
3326 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003327set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328{
3329 char_u *p;
3330 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003331 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332
3333#ifdef FEAT_LANGMAP
3334 langmap_init();
3335#endif
3336
3337 /* Be Vi compatible by default */
3338 p_cp = TRUE;
3339
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003340 /* Use POSIX compatibility when $VIM_POSIX is set. */
3341 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003342 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003343 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003344 set_string_default("shm", (char_u *)"A");
3345 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003346
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 /*
3348 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003349 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003351 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003352#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003353 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003355 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356# endif
3357#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003358 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359 set_string_default("sh", p);
3360
3361#ifdef FEAT_WILDIGN
3362 /*
3363 * Set the default for 'backupskip' to include environment variables for
3364 * temp files.
3365 */
3366 {
3367# ifdef UNIX
3368 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3369# else
3370 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3371# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003372 int len;
3373 garray_T ga;
3374 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375
3376 ga_init2(&ga, 1, 100);
3377 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3378 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003379 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380# ifdef UNIX
3381 if (*names[n] == NUL)
3382 p = (char_u *)"/tmp";
3383 else
3384# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003385 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386 if (p != NULL && *p != NUL)
3387 {
3388 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003389 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 if (ga_grow(&ga, len) == OK)
3391 {
3392 if (ga.ga_len > 0)
3393 STRCAT(ga.ga_data, ",");
3394 STRCAT(ga.ga_data, p);
3395 add_pathsep(ga.ga_data);
3396 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 ga.ga_len += len;
3398 }
3399 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003400 if (mustfree)
3401 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402 }
3403 if (ga.ga_data != NULL)
3404 {
3405 set_string_default("bsk", ga.ga_data);
3406 vim_free(ga.ga_data);
3407 }
3408 }
3409#endif
3410
3411 /*
3412 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3413 */
3414 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003415 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003417#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3418 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3419#endif
3420 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003422 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003423 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424#else
3425# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003426 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003427 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003429 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430# endif
3431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003433 opt_idx = findoption((char_u *)"maxmem");
3434 if (opt_idx >= 0)
3435 {
3436#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003437 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3438 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003439#endif
3440 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3441 }
3442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 }
3444
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445#ifdef FEAT_SEARCHPATH
3446 {
3447 char_u *cdpath;
3448 char_u *buf;
3449 int i;
3450 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003451 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452
3453 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003454 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455 if (cdpath != NULL)
3456 {
3457 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3458 if (buf != NULL)
3459 {
3460 buf[0] = ','; /* start with ",", current dir first */
3461 j = 1;
3462 for (i = 0; cdpath[i] != NUL; ++i)
3463 {
3464 if (vim_ispathlistsep(cdpath[i]))
3465 buf[j++] = ',';
3466 else
3467 {
3468 if (cdpath[i] == ' ' || cdpath[i] == ',')
3469 buf[j++] = '\\';
3470 buf[j++] = cdpath[i];
3471 }
3472 }
3473 buf[j] = NUL;
3474 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003475 if (opt_idx >= 0)
3476 {
3477 options[opt_idx].def_val[VI_DEFAULT] = buf;
3478 options[opt_idx].flags |= P_DEF_ALLOCED;
3479 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003480 else
3481 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003483 if (mustfree)
3484 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003485 }
3486 }
3487#endif
3488
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003489#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490 /* Set print encoding on platforms that don't default to latin1 */
3491 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003492# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493 (char_u *)"cp1252"
3494# else
3495# ifdef VMS
3496 (char_u *)"dec-mcs"
3497# else
3498# ifdef EBCDIC
3499 (char_u *)"ebcdic-uk"
3500# else
3501# ifdef MAC
3502 (char_u *)"mac-roman"
3503# else /* HPUX */
3504 (char_u *)"hp-roman8"
3505# endif
3506# endif
3507# endif
3508# endif
3509 );
3510#endif
3511
3512#ifdef FEAT_POSTSCRIPT
3513 /* 'printexpr' must be allocated to be able to evaluate it. */
3514 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003515# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003516 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003517# else
3518# ifdef VMS
3519 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3520
3521# else
3522 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3523# endif
3524# endif
3525 );
3526#endif
3527
3528 /*
3529 * Set all the options (except the terminal options) to their default
3530 * value. Also set the global value for local options.
3531 */
3532 set_options_default(0);
3533
3534#ifdef FEAT_GUI
3535 if (found_reverse_arg)
3536 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3537#endif
3538
3539 curbuf->b_p_initialized = TRUE;
3540 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003541 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 check_buf_options(curbuf);
3543 check_win_options(curwin);
3544 check_options();
3545
3546 /* Must be before option_expand(), because that one needs vim_isIDc() */
3547 didset_options();
3548
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003549#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003550 /* Use the current chartab for the generic chartab. This is not in
3551 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003552 init_spell_chartab();
3553#endif
3554
Bram Moolenaar071d4272004-06-13 20:20:40 +00003555 /*
3556 * Expand environment variables and things like "~" for the defaults.
3557 * If option_expand() returns non-NULL the variable is expanded. This can
3558 * only happen for non-indirect options.
3559 * Also set the default to the expanded value, so ":set" does not list
3560 * them.
3561 * Don't set the P_ALLOCED flag, because we don't want to free the
3562 * default.
3563 */
3564 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3565 {
3566 if ((options[opt_idx].flags & P_GETTEXT)
3567 && options[opt_idx].var != NULL)
3568 p = (char_u *)_(*(char **)options[opt_idx].var);
3569 else
3570 p = option_expand(opt_idx, NULL);
3571 if (p != NULL && (p = vim_strsave(p)) != NULL)
3572 {
3573 *(char_u **)options[opt_idx].var = p;
3574 /* VIMEXP
3575 * Defaults for all expanded options are currently the same for Vi
3576 * and Vim. When this changes, add some code here! Also need to
3577 * split P_DEF_ALLOCED in two.
3578 */
3579 if (options[opt_idx].flags & P_DEF_ALLOCED)
3580 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3581 options[opt_idx].def_val[VI_DEFAULT] = p;
3582 options[opt_idx].flags |= P_DEF_ALLOCED;
3583 }
3584 }
3585
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586 save_file_ff(curbuf); /* Buffer is unchanged */
3587
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588#if defined(FEAT_ARABIC)
3589 /* Detect use of mlterm.
3590 * Mlterm is a terminal emulator akin to xterm that has some special
3591 * abilities (bidi namely).
3592 * NOTE: mlterm's author is being asked to 'set' a variable
3593 * instead of an environment variable due to inheritance.
3594 */
3595 if (mch_getenv((char_u *)"MLTERM") != NULL)
3596 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3597#endif
3598
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003599 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003600
3601#ifdef FEAT_MBYTE
3602# if defined(WIN3264) && defined(FEAT_GETTEXT)
3603 /*
3604 * If $LANG isn't set, try to get a good value for it. This makes the
3605 * right language be used automatically. Don't do this for English.
3606 */
3607 if (mch_getenv((char_u *)"LANG") == NULL)
3608 {
3609 char buf[20];
3610
3611 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3612 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3613 * only the first two. */
3614 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3615 (LPTSTR)buf, 20);
3616 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3617 {
3618 /* There are a few exceptions (probably more) */
3619 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3620 STRCPY(buf, "zh_TW");
3621 else if (STRNICMP(buf, "chs", 3) == 0
3622 || STRNICMP(buf, "zhc", 3) == 0)
3623 STRCPY(buf, "zh_CN");
3624 else if (STRNICMP(buf, "jp", 2) == 0)
3625 STRCPY(buf, "ja");
3626 else
3627 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003628 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629 }
3630 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003631# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003632# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003633 /* Moved to os_mac_conv.c to avoid dependency problems. */
3634 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003635# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636# endif
3637
3638 /* enc_locale() will try to find the encoding of the current locale. */
3639 p = enc_locale();
3640 if (p != NULL)
3641 {
3642 char_u *save_enc;
3643
3644 /* Try setting 'encoding' and check if the value is valid.
3645 * If not, go back to the default "latin1". */
3646 save_enc = p_enc;
3647 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003648 if (STRCMP(p_enc, "gb18030") == 0)
3649 {
3650 /* We don't support "gb18030", but "cp936" is a good substitute
3651 * for practical purposes, thus use that. It's not an alias to
3652 * still support conversion between gb18030 and utf-8. */
3653 p_enc = vim_strsave((char_u *)"cp936");
3654 vim_free(p);
3655 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003656 if (mb_init() == NULL)
3657 {
3658 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003659 if (opt_idx >= 0)
3660 {
3661 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3662 options[opt_idx].flags |= P_DEF_ALLOCED;
3663 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003664
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003665#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003666 if (STRCMP(p_enc, "latin1") == 0
3667# ifdef FEAT_MBYTE
3668 || enc_utf8
3669# endif
3670 )
3671 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003672 /* Adjust the default for 'isprint' and 'iskeyword' to match
3673 * latin1. Also set the defaults for when 'nocompatible' is
3674 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003675 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003676 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003677 set_string_option_direct((char_u *)"isk", -1,
3678 ISK_LATIN1, OPT_FREE, SID_NONE);
3679 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003680 if (opt_idx >= 0)
3681 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003682 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003683 if (opt_idx >= 0)
3684 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003685 (void)init_chartab();
3686 }
3687#endif
3688
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689# if defined(WIN3264) && !defined(FEAT_GUI)
3690 /* Win32 console: When GetACP() returns a different value from
3691 * GetConsoleCP() set 'termencoding'. */
3692 if (GetACP() != GetConsoleCP())
3693 {
3694 char buf[50];
3695
3696 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3697 p_tenc = vim_strsave((char_u *)buf);
3698 if (p_tenc != NULL)
3699 {
3700 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003701 if (opt_idx >= 0)
3702 {
3703 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3704 options[opt_idx].flags |= P_DEF_ALLOCED;
3705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 convert_setup(&input_conv, p_tenc, p_enc);
3707 convert_setup(&output_conv, p_enc, p_tenc);
3708 }
3709 else
3710 p_tenc = empty_option;
3711 }
3712# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003713# if defined(WIN3264) && defined(FEAT_MBYTE)
3714 /* $HOME may have characters in active code page. */
3715 init_homedir();
3716# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 }
3718 else
3719 {
3720 vim_free(p_enc);
3721 p_enc = save_enc;
3722 }
3723 }
3724#endif
3725
3726#ifdef FEAT_MULTI_LANG
3727 /* Set the default for 'helplang'. */
3728 set_helplang_default(get_mess_lang());
3729#endif
3730}
3731
3732/*
3733 * Set an option to its default value.
3734 * This does not take care of side effects!
3735 */
3736 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003737set_option_default(
3738 int opt_idx,
3739 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3740 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741{
3742 char_u *varp; /* pointer to variable for current option */
3743 int dvi; /* index in def_val[] */
3744 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003745 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003746 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3747
3748 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3749 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003750 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003751 {
3752 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3753 if (flags & P_STRING)
3754 {
3755 /* Use set_string_option_direct() for local options to handle
3756 * freeing and allocating the value. */
3757 if (options[opt_idx].indir != PV_NONE)
3758 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003759 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760 else
3761 {
3762 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3763 free_string_option(*(char_u **)(varp));
3764 *(char_u **)varp = options[opt_idx].def_val[dvi];
3765 options[opt_idx].flags &= ~P_ALLOCED;
3766 }
3767 }
3768 else if (flags & P_NUM)
3769 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003770 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 win_comp_scroll(curwin);
3772 else
3773 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003774 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775 /* May also set global value for local option. */
3776 if (both)
3777 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3778 *(long *)varp;
3779 }
3780 }
3781 else /* P_BOOL */
3782 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003783 /* the cast to long is required for Manx C, long_i is needed for
3784 * MSVC */
3785 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003786#ifdef UNIX
3787 /* 'modeline' defaults to off for root */
3788 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3789 *(int *)varp = FALSE;
3790#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 /* May also set global value for local option. */
3792 if (both)
3793 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3794 *(int *)varp;
3795 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003796
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003797 /* The default value is not insecure. */
3798 flagsp = insecure_flag(opt_idx, opt_flags);
3799 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800 }
3801
3802#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003803 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003804#endif
3805}
3806
3807/*
3808 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003809 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 */
3811 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003812set_options_default(
3813 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814{
3815 int i;
3816#ifdef FEAT_WINDOWS
3817 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003818 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819#endif
3820
3821 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003822 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003823#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003824 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003825 || (TRUE
3826# if defined(FEAT_MBYTE)
3827 && options[i].var != (char_u *)&p_enc
3828# endif
3829# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003830 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003831 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003832# endif
3833 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003834#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003835 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836 set_option_default(i, opt_flags, p_cp);
3837
3838#ifdef FEAT_WINDOWS
3839 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003840 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 win_comp_scroll(wp);
3842#else
3843 win_comp_scroll(curwin);
3844#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003845#ifdef FEAT_CINDENT
3846 parse_cino(curbuf);
3847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848}
3849
3850/*
3851 * Set the Vi-default value of a string option.
3852 * Used for 'sh', 'backupskip' and 'term'.
3853 */
3854 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003855set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856{
3857 char_u *p;
3858 int opt_idx;
3859
3860 p = vim_strsave(val);
3861 if (p != NULL) /* we don't want a NULL */
3862 {
3863 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003864 if (opt_idx >= 0)
3865 {
3866 if (options[opt_idx].flags & P_DEF_ALLOCED)
3867 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3868 options[opt_idx].def_val[VI_DEFAULT] = p;
3869 options[opt_idx].flags |= P_DEF_ALLOCED;
3870 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871 }
3872}
3873
3874/*
3875 * Set the Vi-default value of a number option.
3876 * Used for 'lines' and 'columns'.
3877 */
3878 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003879set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003881 int opt_idx;
3882
3883 opt_idx = findoption((char_u *)name);
3884 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003885 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886}
3887
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003888#if defined(EXITFREE) || defined(PROTO)
3889/*
3890 * Free all options.
3891 */
3892 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003893free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003894{
3895 int i;
3896
3897 for (i = 0; !istermoption(&options[i]); i++)
3898 {
3899 if (options[i].indir == PV_NONE)
3900 {
3901 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003902 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003903 free_string_option(*(char_u **)options[i].var);
3904 if (options[i].flags & P_DEF_ALLOCED)
3905 free_string_option(options[i].def_val[VI_DEFAULT]);
3906 }
3907 else if (options[i].var != VAR_WIN
3908 && (options[i].flags & P_STRING))
3909 /* buffer-local option: free global value */
3910 free_string_option(*(char_u **)options[i].var);
3911 }
3912}
3913#endif
3914
3915
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916/*
3917 * Initialize the options, part two: After getting Rows and Columns and
3918 * setting 'term'.
3919 */
3920 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003921set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003923 int idx;
3924
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 /*
3926 * 'scroll' defaults to half the window height. Note that this default is
3927 * wrong when the window height changes.
3928 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003929 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003930 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003931 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003932 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 comp_col();
3934
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003935 /*
3936 * 'window' is only for backwards compatibility with Vi.
3937 * Default is Rows - 1.
3938 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003939 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003940 p_window = Rows - 1;
3941 set_number_default("window", Rows - 1);
3942
Bram Moolenaarf740b292006-02-16 22:11:02 +00003943 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003944#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003945 /*
3946 * If 'background' wasn't set by the user, try guessing the value,
3947 * depending on the terminal name. Only need to check for terminals
3948 * with a dark background, that can handle color.
3949 */
3950 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003951 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3952 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003954 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003955 /* don't mark it as set, when starting the GUI it may be
3956 * changed again */
3957 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 }
3959#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003960
3961#ifdef CURSOR_SHAPE
3962 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3963#endif
3964#ifdef FEAT_MOUSESHAPE
3965 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3966#endif
3967#ifdef FEAT_PRINTER
3968 (void)parse_printoptions(); /* parse 'printoptions' default value */
3969#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970}
3971
3972/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003973 * Return "dark" or "light" depending on the kind of terminal.
3974 * This is just guessing! Recognized are:
3975 * "linux" Linux console
3976 * "screen.linux" Linux console with screen
3977 * "cygwin" Cygwin shell
3978 * "putty" Putty program
3979 * We also check the COLORFGBG environment variable, which is set by
3980 * rxvt and derivatives. This variable contains either two or three
3981 * values separated by semicolons; we want the last value in either
3982 * case. If this value is 0-6 or 8, our background is dark.
3983 */
3984 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003985term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003986{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003987#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003988 /* DOS console nearly always black */
3989 return (char_u *)"dark";
3990#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003991 char_u *p;
3992
Bram Moolenaarf740b292006-02-16 22:11:02 +00003993 if (STRCMP(T_NAME, "linux") == 0
3994 || STRCMP(T_NAME, "screen.linux") == 0
3995 || STRCMP(T_NAME, "cygwin") == 0
3996 || STRCMP(T_NAME, "putty") == 0
3997 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3998 && (p = vim_strrchr(p, ';')) != NULL
3999 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4000 && p[2] == NUL))
4001 return (char_u *)"dark";
4002 return (char_u *)"light";
4003#endif
4004}
4005
4006/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007 * Initialize the options, part three: After reading the .vimrc
4008 */
4009 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004010set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004012#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004013/*
4014 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4015 * This is done after other initializations, where 'shell' might have been
4016 * set, but only if they have not been set before.
4017 */
4018 char_u *p;
4019 int idx_srr;
4020 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004021# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022 int idx_sp;
4023 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004024# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004025
4026 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004027 if (idx_srr < 0)
4028 do_srr = FALSE;
4029 else
4030 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004031# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004033 if (idx_sp < 0)
4034 do_sp = FALSE;
4035 else
4036 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004037# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004038 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 if (p != NULL)
4040 {
4041 /*
4042 * Default for p_sp is "| tee", for p_srr is ">".
4043 * For known shells it is changed here to include stderr.
4044 */
4045 if ( fnamecmp(p, "csh") == 0
4046 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004047# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 || fnamecmp(p, "csh.exe") == 0
4049 || fnamecmp(p, "tcsh.exe") == 0
4050# endif
4051 )
4052 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004053# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 if (do_sp)
4055 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004058# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4062 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004063# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 if (do_srr)
4065 {
4066 p_srr = (char_u *)">&";
4067 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4068 }
4069 }
4070 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004071 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 if ( fnamecmp(p, "sh") == 0
4073 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004074 || fnamecmp(p, "mksh") == 0
4075 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004077 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004079 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 || fnamecmp(p, "cmd") == 0
4082 || fnamecmp(p, "sh.exe") == 0
4083 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004084 || fnamecmp(p, "mksh.exe") == 0
4085 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004087 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 || fnamecmp(p, "bash.exe") == 0
4089 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004091 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 if (do_sp)
4095 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004100# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4102 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004103# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 if (do_srr)
4105 {
4106 p_srr = (char_u *)">%s 2>&1";
4107 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4108 }
4109 }
4110 vim_free(p);
4111 }
4112#endif
4113
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004114#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004116 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4117 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 * This is done after other initializations, where 'shell' might have been
4119 * set, but only if they have not been set before. Default for p_shcf is
4120 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004121 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004123 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 {
4125 int idx3;
4126
4127 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004128 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 {
4130 p_shcf = (char_u *)"-c";
4131 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4132 }
4133
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 /* Somehow Win32 requires the quotes around the redirection too */
4135 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004136 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 {
4138 p_sxq = (char_u *)"\"";
4139 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4140 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004142 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4143 {
4144 int idx3;
4145
4146 /*
4147 * cmd.exe on Windows will strip the first and last double quote given
4148 * on the command line, e.g. most of the time things like:
4149 * cmd /c "my path/to/echo" "my args to echo"
4150 * become:
4151 * my path/to/echo" "my args to echo
4152 * when executed.
4153 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004154 * To avoid this, set shellxquote to surround the command in
4155 * parenthesis. This appears to make most commands work, without
4156 * breaking commands that worked previously, such as
4157 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004158 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004159 idx3 = findoption((char_u *)"sxq");
4160 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4161 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004162 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004163 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4164 }
4165
Bram Moolenaara64ba222012-02-12 23:23:31 +01004166 idx3 = findoption((char_u *)"shcf");
4167 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4168 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004169 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004170 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4171 }
4172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004173#endif
4174
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004175 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004176 {
4177 int idx_ffs = findoption((char_u *)"ffs");
4178
4179 /* Apply the first entry of 'fileformats' to the initial buffer. */
4180 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4181 set_fileformat(default_fileformat(), OPT_LOCAL);
4182 }
4183
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184#ifdef FEAT_TITLE
4185 set_title_defaults();
4186#endif
4187}
4188
4189#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4190/*
4191 * When 'helplang' is still at its default value, set it to "lang".
4192 * Only the first two characters of "lang" are used.
4193 */
4194 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004195set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004196{
4197 int idx;
4198
4199 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4200 return;
4201 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004202 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203 {
4204 if (options[idx].flags & P_ALLOCED)
4205 free_string_option(p_hlg);
4206 p_hlg = vim_strsave(lang);
4207 if (p_hlg == NULL)
4208 p_hlg = empty_option;
4209 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004210 {
4211 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4212 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4213 {
4214 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4215 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4216 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004218 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219 options[idx].flags |= P_ALLOCED;
4220 }
4221}
4222#endif
4223
4224#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004225static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226
4227 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004228gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229{
4230 if (gui_get_lightness(gui.back_pixel) < 127)
4231 return (char_u *)"dark";
4232 return (char_u *)"light";
4233}
4234
4235/*
4236 * Option initializations that can only be done after opening the GUI window.
4237 */
4238 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004239init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240{
4241 /* Set the 'background' option according to the lightness of the
4242 * background color, unless the user has set it already. */
4243 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4244 {
4245 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4246 highlight_changed();
4247 }
4248}
4249#endif
4250
4251#ifdef FEAT_TITLE
4252/*
4253 * 'title' and 'icon' only default to true if they have not been set or reset
4254 * in .vimrc and we can read the old value.
4255 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4256 * they can be reset. This reduces startup time when using X on a remote
4257 * machine.
4258 */
4259 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004260set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004261{
4262 int idx1;
4263 long val;
4264
4265 /*
4266 * If GUI is (going to be) used, we can always set the window title and
4267 * icon name. Saves a bit of time, because the X11 display server does
4268 * not need to be contacted.
4269 */
4270 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004271 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272 {
4273#ifdef FEAT_GUI
4274 if (gui.starting || gui.in_use)
4275 val = TRUE;
4276 else
4277#endif
4278 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004279 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004280 p_title = val;
4281 }
4282 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004283 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004284 {
4285#ifdef FEAT_GUI
4286 if (gui.starting || gui.in_use)
4287 val = TRUE;
4288 else
4289#endif
4290 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004291 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004292 p_icon = val;
4293 }
4294}
4295#endif
4296
4297/*
4298 * Parse 'arg' for option settings.
4299 *
4300 * 'arg' may be IObuff, but only when no errors can be present and option
4301 * does not need to be expanded with option_expand().
4302 * "opt_flags":
4303 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004304 * OPT_GLOBAL for ":setglobal"
4305 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004306 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004307 * OPT_WINONLY to only set window-local options
4308 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309 *
4310 * returns FAIL if an error is detected, OK otherwise
4311 */
4312 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004313do_set(
4314 char_u *arg, /* option string (may be written to!) */
4315 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004316{
4317 int opt_idx;
4318 char_u *errmsg;
4319 char_u errbuf[80];
4320 char_u *startarg;
4321 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4322 int nextchar; /* next non-white char after option name */
4323 int afterchar; /* character just after option name */
4324 int len;
4325 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004326 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004327 int key;
4328 long_u flags; /* flags for current option */
4329 char_u *varp = NULL; /* pointer to variable for current option */
4330 int did_show = FALSE; /* already showed one value */
4331 int adding; /* "opt+=arg" */
4332 int prepending; /* "opt^=arg" */
4333 int removing; /* "opt-=arg" */
4334 int cp_val = 0;
4335 char_u key_name[2];
4336
4337 if (*arg == NUL)
4338 {
4339 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004340 did_show = TRUE;
4341 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004342 }
4343
4344 while (*arg != NUL) /* loop to process all options */
4345 {
4346 errmsg = NULL;
4347 startarg = arg; /* remember for error message */
4348
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004349 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4350 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004351 {
4352 /*
4353 * ":set all" show all options.
4354 * ":set all&" set all options to their default value.
4355 */
4356 arg += 3;
4357 if (*arg == '&')
4358 {
4359 ++arg;
4360 /* Only for :set command set global value of local options. */
4361 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004362 didset_options();
4363 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004364 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004365 }
4366 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004367 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004369 did_show = TRUE;
4370 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004372 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373 {
4374 showoptions(2, opt_flags);
4375 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004376 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377 arg += 7;
4378 }
4379 else
4380 {
4381 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004382 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 {
4384 prefix = 0;
4385 arg += 2;
4386 }
4387 else if (STRNCMP(arg, "inv", 3) == 0)
4388 {
4389 prefix = 2;
4390 arg += 3;
4391 }
4392
4393 /* find end of name */
4394 key = 0;
4395 if (*arg == '<')
4396 {
4397 nextchar = 0;
4398 opt_idx = -1;
4399 /* look out for <t_>;> */
4400 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4401 len = 5;
4402 else
4403 {
4404 len = 1;
4405 while (arg[len] != NUL && arg[len] != '>')
4406 ++len;
4407 }
4408 if (arg[len] != '>')
4409 {
4410 errmsg = e_invarg;
4411 goto skip;
4412 }
4413 arg[len] = NUL; /* put NUL after name */
4414 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4415 opt_idx = findoption(arg + 1);
4416 arg[len++] = '>'; /* restore '>' */
4417 if (opt_idx == -1)
4418 key = find_key_option(arg + 1);
4419 }
4420 else
4421 {
4422 len = 0;
4423 /*
4424 * The two characters after "t_" may not be alphanumeric.
4425 */
4426 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4427 len = 4;
4428 else
4429 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4430 ++len;
4431 nextchar = arg[len];
4432 arg[len] = NUL; /* put NUL after name */
4433 opt_idx = findoption(arg);
4434 arg[len] = nextchar; /* restore nextchar */
4435 if (opt_idx == -1)
4436 key = find_key_option(arg);
4437 }
4438
4439 /* remember character after option name */
4440 afterchar = arg[len];
4441
4442 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004443 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004444 ++len;
4445
4446 adding = FALSE;
4447 prepending = FALSE;
4448 removing = FALSE;
4449 if (arg[len] != NUL && arg[len + 1] == '=')
4450 {
4451 if (arg[len] == '+')
4452 {
4453 adding = TRUE; /* "+=" */
4454 ++len;
4455 }
4456 else if (arg[len] == '^')
4457 {
4458 prepending = TRUE; /* "^=" */
4459 ++len;
4460 }
4461 else if (arg[len] == '-')
4462 {
4463 removing = TRUE; /* "-=" */
4464 ++len;
4465 }
4466 }
4467 nextchar = arg[len];
4468
4469 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4470 {
4471 errmsg = (char_u *)N_("E518: Unknown option");
4472 goto skip;
4473 }
4474
4475 if (opt_idx >= 0)
4476 {
4477 if (options[opt_idx].var == NULL) /* hidden option: skip */
4478 {
4479 /* Only give an error message when requesting the value of
4480 * a hidden option, ignore setting it. */
4481 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4482 && (!(options[opt_idx].flags & P_BOOL)
4483 || nextchar == '?'))
4484 errmsg = (char_u *)N_("E519: Option not supported");
4485 goto skip;
4486 }
4487
4488 flags = options[opt_idx].flags;
4489 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4490 }
4491 else
4492 {
4493 flags = P_STRING;
4494 if (key < 0)
4495 {
4496 key_name[0] = KEY2TERMCAP0(key);
4497 key_name[1] = KEY2TERMCAP1(key);
4498 }
4499 else
4500 {
4501 key_name[0] = KS_KEY;
4502 key_name[1] = (key & 0xff);
4503 }
4504 }
4505
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004506 /* Skip all options that are not window-local (used when showing
4507 * an already loaded buffer in a window). */
4508 if ((opt_flags & OPT_WINONLY)
4509 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4510 goto skip;
4511
Bram Moolenaara3227e22006-03-08 21:32:40 +00004512 /* Skip all options that are window-local (used for :vimgrep). */
4513 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4514 && options[opt_idx].var == VAR_WIN)
4515 goto skip;
4516
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004517 /* Disallow changing some options from modelines. */
4518 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004519 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004520 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004521 {
4522 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4523 goto skip;
4524 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004525#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004526 /* In diff mode some options are overruled. This avoids that
4527 * 'foldmethod' becomes "marker" instead of "diff" and that
4528 * "wrap" gets set. */
4529 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004530 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004531 && (
4532#ifdef FEAT_FOLDING
4533 options[opt_idx].indir == PV_FDM ||
4534#endif
4535 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004536 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004537#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004538 }
4539
4540#ifdef HAVE_SANDBOX
4541 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004542 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004543 {
4544 errmsg = (char_u *)_(e_sandbox);
4545 goto skip;
4546 }
4547#endif
4548
4549 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4550 {
4551 arg += len;
4552 cp_val = p_cp;
4553 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4554 {
4555 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4556 {
4557 cp_val = FALSE;
4558 arg += 3;
4559 }
4560 else /* "opt&vi": set to Vi default */
4561 {
4562 cp_val = TRUE;
4563 arg += 2;
4564 }
4565 }
4566 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004567 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004568 {
4569 errmsg = e_trailing;
4570 goto skip;
4571 }
4572 }
4573
4574 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004575 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4576 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004577 */
4578 if (nextchar == '?'
4579 || (prefix == 1
4580 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4581 && !(flags & P_BOOL)))
4582 {
4583 /*
4584 * print value
4585 */
4586 if (did_show)
4587 msg_putchar('\n'); /* cursor below last one */
4588 else
4589 {
4590 gotocmdline(TRUE); /* cursor at status line */
4591 did_show = TRUE; /* remember that we did a line */
4592 }
4593 if (opt_idx >= 0)
4594 {
4595 showoneopt(&options[opt_idx], opt_flags);
4596#ifdef FEAT_EVAL
4597 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004598 {
4599 /* Mention where the option was last set. */
4600 if (varp == options[opt_idx].var)
4601 last_set_msg(options[opt_idx].scriptID);
4602 else if ((int)options[opt_idx].indir & PV_WIN)
4603 last_set_msg(curwin->w_p_scriptID[
4604 (int)options[opt_idx].indir & PV_MASK]);
4605 else if ((int)options[opt_idx].indir & PV_BUF)
4606 last_set_msg(curbuf->b_p_scriptID[
4607 (int)options[opt_idx].indir & PV_MASK]);
4608 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004609#endif
4610 }
4611 else
4612 {
4613 char_u *p;
4614
4615 p = find_termcode(key_name);
4616 if (p == NULL)
4617 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004618 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619 goto skip;
4620 }
4621 else
4622 (void)show_one_termcode(key_name, p, TRUE);
4623 }
4624 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004625 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004626 errmsg = e_trailing;
4627 }
4628 else
4629 {
4630 if (flags & P_BOOL) /* boolean */
4631 {
4632 if (nextchar == '=' || nextchar == ':')
4633 {
4634 errmsg = e_invarg;
4635 goto skip;
4636 }
4637
4638 /*
4639 * ":set opt!": invert
4640 * ":set opt&": reset to default value
4641 * ":set opt<": reset to global value
4642 */
4643 if (nextchar == '!')
4644 value = *(int *)(varp) ^ 1;
4645 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004646 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004647 ((flags & P_VI_DEF) || cp_val)
4648 ? VI_DEFAULT : VIM_DEFAULT];
4649 else if (nextchar == '<')
4650 {
4651 /* For 'autoread' -1 means to use global value. */
4652 if ((int *)varp == &curbuf->b_p_ar
4653 && opt_flags == OPT_LOCAL)
4654 value = -1;
4655 else
4656 value = *(int *)get_varp_scope(&(options[opt_idx]),
4657 OPT_GLOBAL);
4658 }
4659 else
4660 {
4661 /*
4662 * ":set invopt": invert
4663 * ":set opt" or ":set noopt": set or reset
4664 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004665 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004666 {
4667 errmsg = e_trailing;
4668 goto skip;
4669 }
4670 if (prefix == 2) /* inv */
4671 value = *(int *)(varp) ^ 1;
4672 else
4673 value = prefix;
4674 }
4675
4676 errmsg = set_bool_option(opt_idx, varp, (int)value,
4677 opt_flags);
4678 }
4679 else /* numeric or string */
4680 {
4681 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4682 || prefix != 1)
4683 {
4684 errmsg = e_invarg;
4685 goto skip;
4686 }
4687
4688 if (flags & P_NUM) /* numeric */
4689 {
4690 /*
4691 * Different ways to set a number option:
4692 * & set to default value
4693 * < set to global value
4694 * <xx> accept special key codes for 'wildchar'
4695 * c accept any non-digit for 'wildchar'
4696 * [-]0-9 set number
4697 * other error
4698 */
4699 ++arg;
4700 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004701 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004702 ((flags & P_VI_DEF) || cp_val)
4703 ? VI_DEFAULT : VIM_DEFAULT];
4704 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004705 {
4706 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4707 * use the global value. */
4708 if ((long *)varp == &curbuf->b_p_ul
4709 && opt_flags == OPT_LOCAL)
4710 value = NO_LOCAL_UNDOLEVEL;
4711 else
4712 value = *(long *)get_varp_scope(
4713 &(options[opt_idx]), OPT_GLOBAL);
4714 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004715 else if (((long *)varp == &p_wc
4716 || (long *)varp == &p_wcm)
4717 && (*arg == '<'
4718 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004719 || (*arg != NUL
4720 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721 && !VIM_ISDIGIT(*arg))))
4722 {
4723 value = string_to_key(arg);
4724 if (value == 0 && (long *)varp != &p_wcm)
4725 {
4726 errmsg = e_invarg;
4727 goto skip;
4728 }
4729 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004730 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4731 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004732 /* Allow negative (for 'undolevels'), octal and
4733 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004734 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4735 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004736 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004737 {
4738 errmsg = e_invarg;
4739 goto skip;
4740 }
4741 }
4742 else
4743 {
4744 errmsg = (char_u *)N_("E521: Number required after =");
4745 goto skip;
4746 }
4747
4748 if (adding)
4749 value = *(long *)varp + value;
4750 if (prepending)
4751 value = *(long *)varp * value;
4752 if (removing)
4753 value = *(long *)varp - value;
4754 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004755 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004756 }
4757 else if (opt_idx >= 0) /* string */
4758 {
4759 char_u *save_arg = NULL;
4760 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004761 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004763 char_u *origval = NULL;
4764#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4765 char_u *saved_origval = NULL;
4766#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 unsigned newlen;
4768 int comma;
4769 int bs;
4770 int new_value_alloced; /* new string option
4771 was allocated */
4772
4773 /* When using ":set opt=val" for a global option
4774 * with a local value the local value will be
4775 * reset, use the global value here. */
4776 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004777 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004778 varp = options[opt_idx].var;
4779
4780 /* The old value is kept until we are sure that the
4781 * new value is valid. */
4782 oldval = *(char_u **)varp;
4783 if (nextchar == '&') /* set to default val */
4784 {
4785 newval = options[opt_idx].def_val[
4786 ((flags & P_VI_DEF) || cp_val)
4787 ? VI_DEFAULT : VIM_DEFAULT];
4788 if ((char_u **)varp == &p_bg)
4789 {
4790 /* guess the value of 'background' */
4791#ifdef FEAT_GUI
4792 if (gui.in_use)
4793 newval = gui_bg_default();
4794 else
4795#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004796 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004797 }
4798
4799 /* expand environment variables and ~ (since the
4800 * default value was already expanded, only
4801 * required when an environment variable was set
4802 * later */
4803 if (newval == NULL)
4804 newval = empty_option;
4805 else
4806 {
4807 s = option_expand(opt_idx, newval);
4808 if (s == NULL)
4809 s = newval;
4810 newval = vim_strsave(s);
4811 }
4812 new_value_alloced = TRUE;
4813 }
4814 else if (nextchar == '<') /* set to global val */
4815 {
4816 newval = vim_strsave(*(char_u **)get_varp_scope(
4817 &(options[opt_idx]), OPT_GLOBAL));
4818 new_value_alloced = TRUE;
4819 }
4820 else
4821 {
4822 ++arg; /* jump to after the '=' or ':' */
4823
4824 /*
4825 * Set 'keywordprg' to ":help" if an empty
4826 * value was passed to :set by the user.
4827 * Misuse errbuf[] for the resulting string.
4828 */
4829 if (varp == (char_u *)&p_kp
4830 && (*arg == NUL || *arg == ' '))
4831 {
4832 STRCPY(errbuf, ":help");
4833 save_arg = arg;
4834 arg = errbuf;
4835 }
4836 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004837 * Convert 'backspace' number to string, for
4838 * adding, prepending and removing string.
4839 */
4840 else if (varp == (char_u *)&p_bs
4841 && VIM_ISDIGIT(**(char_u **)varp))
4842 {
4843 i = getdigits((char_u **)varp);
4844 switch (i)
4845 {
4846 case 0:
4847 *(char_u **)varp = empty_option;
4848 break;
4849 case 1:
4850 *(char_u **)varp = vim_strsave(
4851 (char_u *)"indent,eol");
4852 break;
4853 case 2:
4854 *(char_u **)varp = vim_strsave(
4855 (char_u *)"indent,eol,start");
4856 break;
4857 }
4858 vim_free(oldval);
4859 oldval = *(char_u **)varp;
4860 }
4861 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004862 * Convert 'whichwrap' number to string, for
4863 * backwards compatibility with Vim 3.0.
4864 * Misuse errbuf[] for the resulting string.
4865 */
4866 else if (varp == (char_u *)&p_ww
4867 && VIM_ISDIGIT(*arg))
4868 {
4869 *errbuf = NUL;
4870 i = getdigits(&arg);
4871 if (i & 1)
4872 STRCAT(errbuf, "b,");
4873 if (i & 2)
4874 STRCAT(errbuf, "s,");
4875 if (i & 4)
4876 STRCAT(errbuf, "h,l,");
4877 if (i & 8)
4878 STRCAT(errbuf, "<,>,");
4879 if (i & 16)
4880 STRCAT(errbuf, "[,],");
4881 if (*errbuf != NUL) /* remove trailing , */
4882 errbuf[STRLEN(errbuf) - 1] = NUL;
4883 save_arg = arg;
4884 arg = errbuf;
4885 }
4886 /*
4887 * Remove '>' before 'dir' and 'bdir', for
4888 * backwards compatibility with version 3.0
4889 */
4890 else if ( *arg == '>'
4891 && (varp == (char_u *)&p_dir
4892 || varp == (char_u *)&p_bdir))
4893 {
4894 ++arg;
4895 }
4896
4897 /* When setting the local value of a global
4898 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004899 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004900 && (opt_flags & OPT_LOCAL))
4901 origval = *(char_u **)get_varp(
4902 &options[opt_idx]);
4903 else
4904 origval = oldval;
4905
4906 /*
4907 * Copy the new string into allocated memory.
4908 * Can't use set_string_option_direct(), because
4909 * we need to remove the backslashes.
4910 */
4911 /* get a bit too much */
4912 newlen = (unsigned)STRLEN(arg) + 1;
4913 if (adding || prepending || removing)
4914 newlen += (unsigned)STRLEN(origval) + 1;
4915 newval = alloc(newlen);
4916 if (newval == NULL) /* out of mem, don't change */
4917 break;
4918 s = newval;
4919
4920 /*
4921 * Copy the string, skip over escaped chars.
4922 * For MS-DOS and WIN32 backslashes before normal
4923 * file name characters are not removed, and keep
4924 * backslash at start, for "\\machine\path", but
4925 * do remove it for "\\\\machine\\path".
4926 * The reverse is found in ExpandOldSetting().
4927 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004928 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004929 {
4930 if (*arg == '\\' && arg[1] != NUL
4931#ifdef BACKSLASH_IN_FILENAME
4932 && !((flags & P_EXPAND)
4933 && vim_isfilec(arg[1])
4934 && (arg[1] != '\\'
4935 || (s == newval
4936 && arg[2] != '\\')))
4937#endif
4938 )
4939 ++arg; /* remove backslash */
4940#ifdef FEAT_MBYTE
4941 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004942 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004943 {
4944 /* copy multibyte char */
4945 mch_memmove(s, arg, (size_t)i);
4946 arg += i;
4947 s += i;
4948 }
4949 else
4950#endif
4951 *s++ = *arg++;
4952 }
4953 *s = NUL;
4954
4955 /*
4956 * Expand environment variables and ~.
4957 * Don't do it when adding without inserting a
4958 * comma.
4959 */
4960 if (!(adding || prepending || removing)
4961 || (flags & P_COMMA))
4962 {
4963 s = option_expand(opt_idx, newval);
4964 if (s != NULL)
4965 {
4966 vim_free(newval);
4967 newlen = (unsigned)STRLEN(s) + 1;
4968 if (adding || prepending || removing)
4969 newlen += (unsigned)STRLEN(origval) + 1;
4970 newval = alloc(newlen);
4971 if (newval == NULL)
4972 break;
4973 STRCPY(newval, s);
4974 }
4975 }
4976
4977 /* locate newval[] in origval[] when removing it
4978 * and when adding to avoid duplicates */
4979 i = 0; /* init for GCC */
4980 if (removing || (flags & P_NODUP))
4981 {
4982 i = (int)STRLEN(newval);
4983 bs = 0;
4984 for (s = origval; *s; ++s)
4985 {
4986 if ((!(flags & P_COMMA)
4987 || s == origval
4988 || (s[-1] == ',' && !(bs & 1)))
4989 && STRNCMP(s, newval, i) == 0
4990 && (!(flags & P_COMMA)
4991 || s[i] == ','
4992 || s[i] == NUL))
4993 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004994 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004995 * even number of backslashes or a single
4996 * backslash preceded by a comma before it
4997 * is recognized as a separator */
4998 if ((s > origval + 1
4999 && s[-1] == '\\'
5000 && s[-2] != ',')
5001 || (s == origval + 1
5002 && s[-1] == '\\'))
5003
Bram Moolenaar071d4272004-06-13 20:20:40 +00005004 ++bs;
5005 else
5006 bs = 0;
5007 }
5008
5009 /* do not add if already there */
5010 if ((adding || prepending) && *s)
5011 {
5012 prepending = FALSE;
5013 adding = FALSE;
5014 STRCPY(newval, origval);
5015 }
5016 }
5017
5018 /* concatenate the two strings; add a ',' if
5019 * needed */
5020 if (adding || prepending)
5021 {
5022 comma = ((flags & P_COMMA) && *origval != NUL
5023 && *newval != NUL);
5024 if (adding)
5025 {
5026 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005027 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005028 if (comma && i > 1
5029 && (flags & P_ONECOMMA) == P_ONECOMMA
5030 && origval[i - 1] == ','
5031 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005032 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005033 mch_memmove(newval + i + comma, newval,
5034 STRLEN(newval) + 1);
5035 mch_memmove(newval, origval, (size_t)i);
5036 }
5037 else
5038 {
5039 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005040 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005041 }
5042 if (comma)
5043 newval[i] = ',';
5044 }
5045
5046 /* Remove newval[] from origval[]. (Note: "i" has
5047 * been set above and is used here). */
5048 if (removing)
5049 {
5050 STRCPY(newval, origval);
5051 if (*s)
5052 {
5053 /* may need to remove a comma */
5054 if (flags & P_COMMA)
5055 {
5056 if (s == origval)
5057 {
5058 /* include comma after string */
5059 if (s[i] == ',')
5060 ++i;
5061 }
5062 else
5063 {
5064 /* include comma before string */
5065 --s;
5066 ++i;
5067 }
5068 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005069 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005070 }
5071 }
5072
5073 if (flags & P_FLAGLIST)
5074 {
5075 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005076 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005077 {
5078 /* if options have P_FLAGLIST and
5079 * P_ONECOMMA such as 'whichwrap' */
5080 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005081 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005082 if (*s != ',' && *(s + 1) == ','
5083 && vim_strchr(s + 2, *s) != NULL)
5084 {
5085 /* Remove the duplicated value and
5086 * the next comma. */
5087 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005088 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005089 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005090 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005091 else
5092 {
5093 if ((!(flags & P_COMMA) || *s != ',')
5094 && vim_strchr(s + 1, *s) != NULL)
5095 {
5096 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005097 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005098 }
5099 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005100 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005101 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005102 }
5103
5104 if (save_arg != NULL) /* number for 'whichwrap' */
5105 arg = save_arg;
5106 new_value_alloced = TRUE;
5107 }
5108
5109 /* Set the new value. */
5110 *(char_u **)(varp) = newval;
5111
Bram Moolenaar53744302015-07-17 17:38:22 +02005112#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005113 if (!starting
5114# ifdef FEAT_CRYPT
5115 && options[opt_idx].indir != PV_KEY
5116# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02005117 && origval != NULL)
5118 /* origval may be freed by
5119 * did_set_string_option(), make a copy. */
5120 saved_origval = vim_strsave(origval);
5121#endif
5122
Bram Moolenaar071d4272004-06-13 20:20:40 +00005123 /* Handle side effects, and set the global value for
5124 * ":set" on local options. */
5125 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5126 new_value_alloced, oldval, errbuf, opt_flags);
5127
5128 /* If error detected, print the error message. */
5129 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005130 {
5131#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5132 vim_free(saved_origval);
5133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005135 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005136#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5137 if (saved_origval != NULL)
5138 {
5139 char_u buf_type[7];
5140
5141 sprintf((char *)buf_type, "%s",
5142 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005143 set_vim_var_string(VV_OPTION_NEW,
5144 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005145 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5146 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5147 apply_autocmds(EVENT_OPTIONSET,
5148 (char_u *)options[opt_idx].fullname,
5149 NULL, FALSE, NULL);
5150 reset_v_option_vars();
5151 vim_free(saved_origval);
5152 }
5153#endif
5154
Bram Moolenaar071d4272004-06-13 20:20:40 +00005155 }
5156 else /* key code option */
5157 {
5158 char_u *p;
5159
5160 if (nextchar == '&')
5161 {
5162 if (add_termcap_entry(key_name, TRUE) == FAIL)
5163 errmsg = (char_u *)N_("E522: Not found in termcap");
5164 }
5165 else
5166 {
5167 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005168 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005169 if (*p == '\\' && p[1] != NUL)
5170 ++p;
5171 nextchar = *p;
5172 *p = NUL;
5173 add_termcode(key_name, arg, FALSE);
5174 *p = nextchar;
5175 }
5176 if (full_screen)
5177 ttest(FALSE);
5178 redraw_all_later(CLEAR);
5179 }
5180 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005181
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005183 did_set_option(opt_idx, opt_flags,
5184 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185 }
5186
5187skip:
5188 /*
5189 * Advance to next argument.
5190 * - skip until a blank found, taking care of backslashes
5191 * - skip blanks
5192 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5193 */
5194 for (i = 0; i < 2 ; ++i)
5195 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005196 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005197 if (*arg++ == '\\' && *arg != NUL)
5198 ++arg;
5199 arg = skipwhite(arg);
5200 if (*arg != '=')
5201 break;
5202 }
5203 }
5204
5205 if (errmsg != NULL)
5206 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005207 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005208 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005209 if (i + (arg - startarg) < IOSIZE)
5210 {
5211 /* append the argument with the error */
5212 STRCAT(IObuff, ": ");
5213 mch_memmove(IObuff + i, startarg, (arg - startarg));
5214 IObuff[i + (arg - startarg)] = NUL;
5215 }
5216 /* make sure all characters are printable */
5217 trans_characters(IObuff, IOSIZE);
5218
5219 ++no_wait_return; /* wait_return done later */
5220 emsg(IObuff); /* show error highlighted */
5221 --no_wait_return;
5222
5223 return FAIL;
5224 }
5225
5226 arg = skipwhite(arg);
5227 }
5228
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005229theend:
5230 if (silent_mode && did_show)
5231 {
5232 /* After displaying option values in silent mode. */
5233 silent_mode = FALSE;
5234 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5235 msg_putchar('\n');
5236 cursor_on(); /* msg_start() switches it off */
5237 out_flush();
5238 silent_mode = TRUE;
5239 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5240 }
5241
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 return OK;
5243}
5244
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005245/*
5246 * Call this when an option has been given a new value through a user command.
5247 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5248 */
5249 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005250did_set_option(
5251 int opt_idx,
5252 int opt_flags, /* possibly with OPT_MODELINE */
5253 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005254{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005255 long_u *p;
5256
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005257 options[opt_idx].flags |= P_WAS_SET;
5258
5259 /* When an option is set in the sandbox, from a modeline or in secure mode
5260 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005261 * flag. */
5262 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005263 if (secure
5264#ifdef HAVE_SANDBOX
5265 || sandbox != 0
5266#endif
5267 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005268 *p = *p | P_INSECURE;
5269 else if (new_value)
5270 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005271}
5272
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005274illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275{
5276 if (errbuf == NULL)
5277 return (char_u *)"";
5278 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005279 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005280 return errbuf;
5281}
5282
5283/*
5284 * Convert a key name or string into a key value.
5285 * Used for 'wildchar' and 'cedit' options.
5286 */
5287 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005288string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005289{
5290 if (*arg == '<')
5291 return find_key_option(arg + 1);
5292 if (*arg == '^')
5293 return Ctrl_chr(arg[1]);
5294 return *arg;
5295}
5296
5297#ifdef FEAT_CMDWIN
5298/*
5299 * Check value of 'cedit' and set cedit_key.
5300 * Returns NULL if value is OK, error message otherwise.
5301 */
5302 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005303check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005304{
5305 int n;
5306
5307 if (*p_cedit == NUL)
5308 cedit_key = -1;
5309 else
5310 {
5311 n = string_to_key(p_cedit);
5312 if (vim_isprintc(n))
5313 return e_invarg;
5314 cedit_key = n;
5315 }
5316 return NULL;
5317}
5318#endif
5319
5320#ifdef FEAT_TITLE
5321/*
5322 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5323 * maketitle() to create and display it.
5324 * When switching the title or icon off, call mch_restore_title() to get
5325 * the old value back.
5326 */
5327 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005328did_set_title(
5329 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330{
5331 if (starting != NO_SCREEN
5332#ifdef FEAT_GUI
5333 && !gui.starting
5334#endif
5335 )
5336 {
5337 maketitle();
5338 if (icon)
5339 {
5340 if (!p_icon)
5341 mch_restore_title(2);
5342 }
5343 else
5344 {
5345 if (!p_title)
5346 mch_restore_title(1);
5347 }
5348 }
5349}
5350#endif
5351
5352/*
5353 * set_options_bin - called when 'bin' changes value.
5354 */
5355 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005356set_options_bin(
5357 int oldval,
5358 int newval,
5359 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360{
5361 /*
5362 * The option values that are changed when 'bin' changes are
5363 * copied when 'bin is set and restored when 'bin' is reset.
5364 */
5365 if (newval)
5366 {
5367 if (!oldval) /* switched on */
5368 {
5369 if (!(opt_flags & OPT_GLOBAL))
5370 {
5371 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5372 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5373 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5374 curbuf->b_p_et_nobin = curbuf->b_p_et;
5375 }
5376 if (!(opt_flags & OPT_LOCAL))
5377 {
5378 p_tw_nobin = p_tw;
5379 p_wm_nobin = p_wm;
5380 p_ml_nobin = p_ml;
5381 p_et_nobin = p_et;
5382 }
5383 }
5384
5385 if (!(opt_flags & OPT_GLOBAL))
5386 {
5387 curbuf->b_p_tw = 0; /* no automatic line wrap */
5388 curbuf->b_p_wm = 0; /* no automatic line wrap */
5389 curbuf->b_p_ml = 0; /* no modelines */
5390 curbuf->b_p_et = 0; /* no expandtab */
5391 }
5392 if (!(opt_flags & OPT_LOCAL))
5393 {
5394 p_tw = 0;
5395 p_wm = 0;
5396 p_ml = FALSE;
5397 p_et = FALSE;
5398 p_bin = TRUE; /* needed when called for the "-b" argument */
5399 }
5400 }
5401 else if (oldval) /* switched off */
5402 {
5403 if (!(opt_flags & OPT_GLOBAL))
5404 {
5405 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5406 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5407 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5408 curbuf->b_p_et = curbuf->b_p_et_nobin;
5409 }
5410 if (!(opt_flags & OPT_LOCAL))
5411 {
5412 p_tw = p_tw_nobin;
5413 p_wm = p_wm_nobin;
5414 p_ml = p_ml_nobin;
5415 p_et = p_et_nobin;
5416 }
5417 }
5418}
5419
5420#ifdef FEAT_VIMINFO
5421/*
5422 * Find the parameter represented by the given character (eg ', :, ", or /),
5423 * and return its associated value in the 'viminfo' string.
5424 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005425 * If the parameter is not specified in the string or there is no following
5426 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427 */
5428 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005429get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005430{
5431 char_u *p;
5432
5433 p = find_viminfo_parameter(type);
5434 if (p != NULL && VIM_ISDIGIT(*p))
5435 return atoi((char *)p);
5436 return -1;
5437}
5438
5439/*
5440 * Find the parameter represented by the given character (eg ''', ':', '"', or
5441 * '/') in the 'viminfo' option and return a pointer to the string after it.
5442 * Return NULL if the parameter is not specified in the string.
5443 */
5444 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005445find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446{
5447 char_u *p;
5448
5449 for (p = p_viminfo; *p; ++p)
5450 {
5451 if (*p == type)
5452 return p + 1;
5453 if (*p == 'n') /* 'n' is always the last one */
5454 break;
5455 p = vim_strchr(p, ','); /* skip until next ',' */
5456 if (p == NULL) /* hit the end without finding parameter */
5457 break;
5458 }
5459 return NULL;
5460}
5461#endif
5462
5463/*
5464 * Expand environment variables for some string options.
5465 * These string options cannot be indirect!
5466 * If "val" is NULL expand the current value of the option.
5467 * Return pointer to NameBuff, or NULL when not expanded.
5468 */
5469 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005470option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005471{
5472 /* if option doesn't need expansion nothing to do */
5473 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5474 return NULL;
5475
5476 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5477 * expand_env() would truncate the string. */
5478 if (val != NULL && STRLEN(val) > MAXPATHL)
5479 return NULL;
5480
5481 if (val == NULL)
5482 val = *(char_u **)options[opt_idx].var;
5483
5484 /*
5485 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5486 * Escape spaces when expanding 'tags', they are used to separate file
5487 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005488 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005489 */
5490 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005491 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005492#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005493 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5494#endif
5495 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5497 return NULL;
5498
5499 return NameBuff;
5500}
5501
5502/*
5503 * After setting various option values: recompute variables that depend on
5504 * option values.
5505 */
5506 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005507didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508{
5509 /* initialize the table for 'iskeyword' et.al. */
5510 (void)init_chartab();
5511
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005512#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005514#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005515 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005516 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517#ifdef FEAT_SESSION
5518 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5519 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5520#endif
5521#ifdef FEAT_FOLDING
5522 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5523#endif
5524 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005525 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526#ifdef FEAT_VIRTUALEDIT
5527 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5528#endif
5529#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5530 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5531#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005532#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005533 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005534 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005535 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005536 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005537#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005538#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5539 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5540#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005541#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5543#endif
5544#ifdef FEAT_CMDWIN
5545 /* set cedit_key */
5546 (void)check_cedit();
5547#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005548#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005549 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005550#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005551#ifdef FEAT_LINEBREAK
5552 /* initialize the table for 'breakat'. */
5553 fill_breakat_flags();
5554#endif
5555
5556}
5557
5558/*
5559 * More side effects of setting options.
5560 */
5561 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005562didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005563{
5564 /* Initialize the highlight_attr[] table. */
5565 (void)highlight_changed();
5566
5567 /* Parse default for 'wildmode' */
5568 check_opt_wim();
5569
5570 (void)set_chars_option(&p_lcs);
5571#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5572 /* Parse default for 'fillchars'. */
5573 (void)set_chars_option(&p_fcs);
5574#endif
5575
5576#ifdef FEAT_CLIPBOARD
5577 /* Parse default for 'clipboard' */
5578 (void)check_clipboard_option();
5579#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005580}
5581
5582/*
5583 * Check for string options that are NULL (normally only termcap options).
5584 */
5585 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005586check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005587{
5588 int opt_idx;
5589
5590 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5591 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5592 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5593}
5594
5595/*
5596 * Check string options in a buffer for NULL value.
5597 */
5598 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005599check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005600{
5601#if defined(FEAT_QUICKFIX)
5602 check_string_option(&buf->b_p_bh);
5603 check_string_option(&buf->b_p_bt);
5604#endif
5605#ifdef FEAT_MBYTE
5606 check_string_option(&buf->b_p_fenc);
5607#endif
5608 check_string_option(&buf->b_p_ff);
5609#ifdef FEAT_FIND_ID
5610 check_string_option(&buf->b_p_def);
5611 check_string_option(&buf->b_p_inc);
5612# ifdef FEAT_EVAL
5613 check_string_option(&buf->b_p_inex);
5614# endif
5615#endif
5616#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5617 check_string_option(&buf->b_p_inde);
5618 check_string_option(&buf->b_p_indk);
5619#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005620#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5621 check_string_option(&buf->b_p_bexpr);
5622#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005623#if defined(FEAT_CRYPT)
5624 check_string_option(&buf->b_p_cm);
5625#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005626 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005627#if defined(FEAT_EVAL)
5628 check_string_option(&buf->b_p_fex);
5629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630#ifdef FEAT_CRYPT
5631 check_string_option(&buf->b_p_key);
5632#endif
5633 check_string_option(&buf->b_p_kp);
5634 check_string_option(&buf->b_p_mps);
5635 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005636 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005637 check_string_option(&buf->b_p_isk);
5638#ifdef FEAT_COMMENTS
5639 check_string_option(&buf->b_p_com);
5640#endif
5641#ifdef FEAT_FOLDING
5642 check_string_option(&buf->b_p_cms);
5643#endif
5644 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005645#ifdef FEAT_TEXTOBJ
5646 check_string_option(&buf->b_p_qe);
5647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648#ifdef FEAT_SYN_HL
5649 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005650 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005651#endif
5652#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005653 check_string_option(&buf->b_s.b_p_spc);
5654 check_string_option(&buf->b_s.b_p_spf);
5655 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656#endif
5657#ifdef FEAT_SEARCHPATH
5658 check_string_option(&buf->b_p_sua);
5659#endif
5660#ifdef FEAT_CINDENT
5661 check_string_option(&buf->b_p_cink);
5662 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005663 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664#endif
5665#ifdef FEAT_AUTOCMD
5666 check_string_option(&buf->b_p_ft);
5667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5669 check_string_option(&buf->b_p_cinw);
5670#endif
5671#ifdef FEAT_INS_EXPAND
5672 check_string_option(&buf->b_p_cpt);
5673#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005674#ifdef FEAT_COMPL_FUNC
5675 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005676 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678#ifdef FEAT_KEYMAP
5679 check_string_option(&buf->b_p_keymap);
5680#endif
5681#ifdef FEAT_QUICKFIX
5682 check_string_option(&buf->b_p_gp);
5683 check_string_option(&buf->b_p_mp);
5684 check_string_option(&buf->b_p_efm);
5685#endif
5686 check_string_option(&buf->b_p_ep);
5687 check_string_option(&buf->b_p_path);
5688 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005689 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690#ifdef FEAT_INS_EXPAND
5691 check_string_option(&buf->b_p_dict);
5692 check_string_option(&buf->b_p_tsr);
5693#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005694#ifdef FEAT_LISP
5695 check_string_option(&buf->b_p_lw);
5696#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005697 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005698#ifdef FEAT_MBYTE
5699 check_string_option(&buf->b_p_menc);
5700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701}
5702
5703/*
5704 * Free the string allocated for an option.
5705 * Checks for the string being empty_option. This may happen if we're out of
5706 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5707 * check_options().
5708 * Does NOT check for P_ALLOCED flag!
5709 */
5710 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005711free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712{
5713 if (p != empty_option)
5714 vim_free(p);
5715}
5716
5717 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005718clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719{
5720 if (*pp != empty_option)
5721 vim_free(*pp);
5722 *pp = empty_option;
5723}
5724
5725 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005726check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727{
5728 if (*pp == NULL)
5729 *pp = empty_option;
5730}
5731
5732/*
5733 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5734 */
5735 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005736set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737{
5738 int opt_idx;
5739
5740 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5741 if (options[opt_idx].var == (char_u *)p)
5742 {
5743 options[opt_idx].flags |= P_ALLOCED;
5744 return;
5745 }
5746 return; /* cannot happen: didn't find it! */
5747}
5748
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005749#if defined(FEAT_EVAL) || defined(PROTO)
5750/*
5751 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5752 * Return FALSE when it wasn't.
5753 * Return -1 for an unknown option.
5754 */
5755 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005756was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005757{
5758 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005759 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005760
5761 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005762 {
5763 flagp = insecure_flag(idx, opt_flags);
5764 return (*flagp & P_INSECURE) != 0;
5765 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005766 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005767 return -1;
5768}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005769
5770/*
5771 * Get a pointer to the flags used for the P_INSECURE flag of option
5772 * "opt_idx". For some local options a local flags field is used.
5773 */
5774 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005775insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005776{
5777 if (opt_flags & OPT_LOCAL)
5778 switch ((int)options[opt_idx].indir)
5779 {
5780#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005781 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005782#endif
5783#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005784# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005785 case PV_FDE: return &curwin->w_p_fde_flags;
5786 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005787# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005788# ifdef FEAT_BEVAL
5789 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5790# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005791# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005792 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005793# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005794 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005795# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005796 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005797# endif
5798#endif
5799 }
5800
5801 /* Nothing special, return global flags field. */
5802 return &options[opt_idx].flags;
5803}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005804#endif
5805
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005806#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005807static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005808
5809/*
5810 * Redraw the window title and/or tab page text later.
5811 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005812static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005813{
5814 need_maketitle = TRUE;
5815# ifdef FEAT_WINDOWS
5816 redraw_tabline = TRUE;
5817# endif
5818}
5819#endif
5820
Bram Moolenaar071d4272004-06-13 20:20:40 +00005821/*
5822 * Set a string option to a new value (without checking the effect).
5823 * The string is copied into allocated memory.
5824 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005825 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005826 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005827 */
5828 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005829set_string_option_direct(
5830 char_u *name,
5831 int opt_idx,
5832 char_u *val,
5833 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5834 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005835{
5836 char_u *s;
5837 char_u **varp;
5838 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005839 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005840
Bram Moolenaar89d40322006-08-29 15:30:07 +00005841 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005842 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005843 idx = findoption(name);
5844 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005845 {
5846 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005847 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005849 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005850 }
5851
Bram Moolenaar89d40322006-08-29 15:30:07 +00005852 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005853 return;
5854
5855 s = vim_strsave(val);
5856 if (s != NULL)
5857 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005858 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005860 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861 free_string_option(*varp);
5862 *varp = s;
5863
5864 /* For buffer/window local option may also set the global value. */
5865 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005866 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867
Bram Moolenaar89d40322006-08-29 15:30:07 +00005868 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869
5870 /* When setting both values of a global option with a local value,
5871 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005872 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873 {
5874 free_string_option(*varp);
5875 *varp = empty_option;
5876 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005877# ifdef FEAT_EVAL
5878 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005879 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005880 set_sid == 0 ? current_SID : set_sid);
5881# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005882 }
5883}
5884
5885/*
5886 * Set global value for string option when it's a local option.
5887 */
5888 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005889set_string_option_global(
5890 int opt_idx, /* option index */
5891 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892{
5893 char_u **p, *s;
5894
5895 /* the global value is always allocated */
5896 if (options[opt_idx].var == VAR_WIN)
5897 p = (char_u **)GLOBAL_WO(varp);
5898 else
5899 p = (char_u **)options[opt_idx].var;
5900 if (options[opt_idx].indir != PV_NONE
5901 && p != varp
5902 && (s = vim_strsave(*varp)) != NULL)
5903 {
5904 free_string_option(*p);
5905 *p = s;
5906 }
5907}
5908
5909/*
5910 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005911 *
5912 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005914 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005915set_string_option(
5916 int opt_idx,
5917 char_u *value,
5918 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919{
5920 char_u *s;
5921 char_u **varp;
5922 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005923#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5924 char_u *saved_oldval = NULL;
5925#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005926 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927
5928 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005929 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930
5931 s = vim_strsave(value);
5932 if (s != NULL)
5933 {
5934 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5935 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005936 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937 ? OPT_GLOBAL : OPT_LOCAL)
5938 : opt_flags);
5939 oldval = *varp;
5940 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005941
5942#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005943 if (!starting
5944# ifdef FEAT_CRYPT
5945 && options[opt_idx].indir != PV_KEY
5946# endif
5947 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005948 saved_oldval = vim_strsave(oldval);
5949#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005950 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5951 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005952 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005953
Bram Moolenaara12e4032017-02-25 21:37:57 +01005954 /* call autocommand after handling side effects */
Bram Moolenaar53744302015-07-17 17:38:22 +02005955#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5956 if (saved_oldval != NULL)
5957 {
5958 char_u buf_type[7];
5959 sprintf((char *)buf_type, "%s",
5960 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005961 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5962 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005963 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5964 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5965 reset_v_option_vars();
5966 vim_free(saved_oldval);
5967 }
5968#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005970 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971}
5972
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005973#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005975 * Return TRUE if "val" is a valid 'filetype' name.
5976 * Also used for 'syntax' and 'keymap'.
5977 */
5978 static int
5979valid_filetype(char_u *val)
5980{
5981 char_u *s;
5982
5983 for (s = val; *s != NUL; ++s)
5984 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5985 return FALSE;
5986 return TRUE;
5987}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005988#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005989
5990/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 * Handle string options that need some action to perform when changed.
5992 * Returns NULL for success, or an error message for an error.
5993 */
5994 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005995did_set_string_option(
5996 int opt_idx, /* index in options[] table */
5997 char_u **varp, /* pointer to the option variable */
5998 int new_value_alloced, /* new value was allocated */
5999 char_u *oldval, /* previous value of the option */
6000 char_u *errbuf, /* buffer for errors, or NULL */
6001 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002{
6003 char_u *errmsg = NULL;
6004 char_u *s, *p;
6005 int did_chartab = FALSE;
6006 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006007 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006008#ifdef FEAT_GUI
6009 /* set when changing an option that only requires a redraw in the GUI */
6010 int redraw_gui_only = FALSE;
6011#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006012#ifdef FEAT_AUTOCMD
6013 int ft_changed = 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 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006410 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006411 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 Moolenaar91acfff2017-03-12 19:22:36 +01006794 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;
Bram Moolenaar90492982017-06-22 14:16:31 +02007424 else
7425 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007426 }
7427#endif
7428
7429#ifdef FEAT_SYN_HL
7430 else if (gvarp == &p_syn)
7431 {
7432 if (!valid_filetype(*varp))
7433 errmsg = e_invarg;
7434 }
7435#endif
7436
Bram Moolenaar071d4272004-06-13 20:20:40 +00007437 /* Options that are a list of flags. */
7438 else
7439 {
7440 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007441 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007442 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007443 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007444 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007445 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007446 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007447 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007449#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007450 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007451 p = (char_u *)COCU_ALL;
7452#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007453 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007454 {
7455#ifdef FEAT_MOUSE
7456 p = (char_u *)MOUSE_ALL;
7457#else
7458 if (*p_mouse != NUL)
7459 errmsg = (char_u *)N_("E538: No mouse support");
7460#endif
7461 }
7462#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007463 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464 p = (char_u *)GO_ALL;
7465#endif
7466 if (p != NULL)
7467 {
7468 for (s = *varp; *s; ++s)
7469 if (vim_strchr(p, *s) == NULL)
7470 {
7471 errmsg = illegal_char(errbuf, *s);
7472 break;
7473 }
7474 }
7475 }
7476
7477 /*
7478 * If error detected, restore the previous value.
7479 */
7480 if (errmsg != NULL)
7481 {
7482 if (new_value_alloced)
7483 free_string_option(*varp);
7484 *varp = oldval;
7485 /*
7486 * When resetting some values, need to act on it.
7487 */
7488 if (did_chartab)
7489 (void)init_chartab();
7490 if (varp == &p_hl)
7491 (void)highlight_changed();
7492 }
7493 else
7494 {
7495#ifdef FEAT_EVAL
7496 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007497 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498#endif
7499 /*
7500 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007501 * Use "free_oldval", because recursiveness may change the flags under
7502 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007503 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007504 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007505 free_string_option(oldval);
7506 if (new_value_alloced)
7507 options[opt_idx].flags |= P_ALLOCED;
7508 else
7509 options[opt_idx].flags &= ~P_ALLOCED;
7510
7511 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007512 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 {
7514 /* global option with local value set to use global value; free
7515 * the local value and make it empty */
7516 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7517 free_string_option(*(char_u **)p);
7518 *(char_u **)p = empty_option;
7519 }
7520
7521 /* May set global value for local option. */
7522 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7523 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007524
7525#ifdef FEAT_AUTOCMD
7526 /*
7527 * Trigger the autocommand only after setting the flags.
7528 */
7529# ifdef FEAT_SYN_HL
7530 /* When 'syntax' is set, load the syntax of that name */
7531 if (varp == &(curbuf->b_p_syn))
7532 {
7533 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7534 curbuf->b_fname, TRUE, curbuf);
7535 }
7536# endif
7537 else if (varp == &(curbuf->b_p_ft))
7538 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007539 /* 'filetype' is set, trigger the FileType autocommand.
7540 * Skip this when called from a modeline and the filetype was
7541 * already set to this value. */
7542 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7543 {
7544 did_filetype = TRUE;
7545 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007546 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar90492982017-06-22 14:16:31 +02007547 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007548 }
7549#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007550#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007551 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007552 {
7553 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007554 char_u *q = curwin->w_s->b_p_spl;
7555
7556 /* Skip the first name if it is "cjk". */
7557 if (STRNCMP(q, "cjk,", 4) == 0)
7558 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007559
7560 /*
7561 * Source the spell/LANG.vim in 'runtimepath'.
7562 * They could set 'spellcapcheck' depending on the language.
7563 * Use the first name in 'spelllang' up to '_region' or
7564 * '.encoding'.
7565 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007566 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007567 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7568 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007569 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007570 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007571 }
7572#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573 }
7574
7575#ifdef FEAT_MOUSE
7576 if (varp == &p_mouse)
7577 {
7578# ifdef FEAT_MOUSE_TTY
7579 if (*p_mouse == NUL)
7580 mch_setmouse(FALSE); /* switch mouse off */
7581 else
7582# endif
7583 setmouse(); /* in case 'mouse' changed */
7584 }
7585#endif
7586
Bram Moolenaar913077c2012-03-28 19:59:04 +02007587 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007588 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007589 curwin->w_set_curswant = TRUE;
7590
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007591#ifdef FEAT_GUI
7592 /* check redraw when it's not a GUI option or the GUI is active. */
7593 if (!redraw_gui_only || gui.in_use)
7594#endif
7595 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007596
7597 return errmsg;
7598}
7599
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007600#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007601/*
7602 * Simple int comparison function for use with qsort()
7603 */
7604 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007605int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007606{
7607 return *(const int *)a - *(const int *)b;
7608}
7609
7610/*
7611 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7612 * Returns error message, NULL if it's OK.
7613 */
7614 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007615check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007616{
7617 char_u *s;
7618 int col;
7619 int count = 0;
7620 int color_cols[256];
7621 int i;
7622 int j = 0;
7623
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007624 if (wp->w_buffer == NULL)
7625 return NULL; /* buffer was closed */
7626
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007627 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007628 {
7629 if (*s == '-' || *s == '+')
7630 {
7631 /* -N and +N: add to 'textwidth' */
7632 col = (*s == '-') ? -1 : 1;
7633 ++s;
7634 if (!VIM_ISDIGIT(*s))
7635 return e_invarg;
7636 col = col * getdigits(&s);
7637 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007638 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007639 col += wp->w_buffer->b_p_tw;
7640 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007641 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007642 }
7643 else if (VIM_ISDIGIT(*s))
7644 col = getdigits(&s);
7645 else
7646 return e_invarg;
7647 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007648skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007649 if (*s == NUL)
7650 break;
7651 if (*s != ',')
7652 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007653 if (*++s == NUL)
7654 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007655 }
7656
7657 vim_free(wp->w_p_cc_cols);
7658 if (count == 0)
7659 wp->w_p_cc_cols = NULL;
7660 else
7661 {
7662 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7663 if (wp->w_p_cc_cols != NULL)
7664 {
7665 /* sort the columns for faster usage on screen redraw inside
7666 * win_line() */
7667 qsort(color_cols, count, sizeof(int), int_cmp);
7668
7669 for (i = 0; i < count; ++i)
7670 /* skip duplicates */
7671 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7672 wp->w_p_cc_cols[j++] = color_cols[i];
7673 wp->w_p_cc_cols[j] = -1; /* end marker */
7674 }
7675 }
7676
7677 return NULL; /* no error */
7678}
7679#endif
7680
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681/*
7682 * Handle setting 'listchars' or 'fillchars'.
7683 * Returns error message, NULL if it's OK.
7684 */
7685 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007686set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007687{
7688 int round, i, len, entries;
7689 char_u *p, *s;
7690 int c1, c2 = 0;
7691 struct charstab
7692 {
7693 int *cp;
7694 char *name;
7695 };
7696#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7697 static struct charstab filltab[] =
7698 {
7699 {&fill_stl, "stl"},
7700 {&fill_stlnc, "stlnc"},
7701 {&fill_vert, "vert"},
7702 {&fill_fold, "fold"},
7703 {&fill_diff, "diff"},
7704 };
7705#endif
7706 static struct charstab lcstab[] =
7707 {
7708 {&lcs_eol, "eol"},
7709 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007710 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007711 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007712 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 {&lcs_tab2, "tab"},
7714 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007715#ifdef FEAT_CONCEAL
7716 {&lcs_conceal, "conceal"},
7717#else
7718 {NULL, "conceal"},
7719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720 };
7721 struct charstab *tab;
7722
7723#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7724 if (varp == &p_lcs)
7725#endif
7726 {
7727 tab = lcstab;
7728 entries = sizeof(lcstab) / sizeof(struct charstab);
7729 }
7730#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7731 else
7732 {
7733 tab = filltab;
7734 entries = sizeof(filltab) / sizeof(struct charstab);
7735 }
7736#endif
7737
7738 /* first round: check for valid value, second round: assign values */
7739 for (round = 0; round <= 1; ++round)
7740 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007741 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007742 {
7743 /* After checking that the value is valid: set defaults: space for
7744 * 'fillchars', NUL for 'listchars' */
7745 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007746 if (tab[i].cp != NULL)
7747 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 if (varp == &p_lcs)
7749 lcs_tab1 = NUL;
7750#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7751 else
7752 fill_diff = '-';
7753#endif
7754 }
7755 p = *varp;
7756 while (*p)
7757 {
7758 for (i = 0; i < entries; ++i)
7759 {
7760 len = (int)STRLEN(tab[i].name);
7761 if (STRNCMP(p, tab[i].name, len) == 0
7762 && p[len] == ':'
7763 && p[len + 1] != NUL)
7764 {
7765 s = p + len + 1;
7766#ifdef FEAT_MBYTE
7767 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007768 if (mb_char2cells(c1) > 1)
7769 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770#else
7771 c1 = *s++;
7772#endif
7773 if (tab[i].cp == &lcs_tab2)
7774 {
7775 if (*s == NUL)
7776 continue;
7777#ifdef FEAT_MBYTE
7778 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007779 if (mb_char2cells(c2) > 1)
7780 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781#else
7782 c2 = *s++;
7783#endif
7784 }
7785 if (*s == ',' || *s == NUL)
7786 {
7787 if (round)
7788 {
7789 if (tab[i].cp == &lcs_tab2)
7790 {
7791 lcs_tab1 = c1;
7792 lcs_tab2 = c2;
7793 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007794 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795 *(tab[i].cp) = c1;
7796
7797 }
7798 p = s;
7799 break;
7800 }
7801 }
7802 }
7803
7804 if (i == entries)
7805 return e_invarg;
7806 if (*p == ',')
7807 ++p;
7808 }
7809 }
7810
7811 return NULL; /* no error */
7812}
7813
7814#ifdef FEAT_STL_OPT
7815/*
7816 * Check validity of options with the 'statusline' format.
7817 * Return error message or NULL.
7818 */
7819 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007820check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007821{
7822 int itemcnt = 0;
7823 int groupdepth = 0;
7824 static char_u errbuf[80];
7825
7826 while (*s && itemcnt < STL_MAX_ITEM)
7827 {
7828 /* Check for valid keys after % sequences */
7829 while (*s && *s != '%')
7830 s++;
7831 if (!*s)
7832 break;
7833 s++;
7834 if (*s != '%' && *s != ')')
7835 ++itemcnt;
7836 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7837 {
7838 s++;
7839 continue;
7840 }
7841 if (*s == ')')
7842 {
7843 s++;
7844 if (--groupdepth < 0)
7845 break;
7846 continue;
7847 }
7848 if (*s == '-')
7849 s++;
7850 while (VIM_ISDIGIT(*s))
7851 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007852 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007853 continue;
7854 if (*s == '.')
7855 {
7856 s++;
7857 while (*s && VIM_ISDIGIT(*s))
7858 s++;
7859 }
7860 if (*s == '(')
7861 {
7862 groupdepth++;
7863 continue;
7864 }
7865 if (vim_strchr(STL_ALL, *s) == NULL)
7866 {
7867 return illegal_char(errbuf, *s);
7868 }
7869 if (*s == '{')
7870 {
7871 s++;
7872 while (*s != '}' && *s)
7873 s++;
7874 if (*s != '}')
7875 return (char_u *)N_("E540: Unclosed expression sequence");
7876 }
7877 }
7878 if (itemcnt >= STL_MAX_ITEM)
7879 return (char_u *)N_("E541: too many items");
7880 if (groupdepth != 0)
7881 return (char_u *)N_("E542: unbalanced groups");
7882 return NULL;
7883}
7884#endif
7885
7886#ifdef FEAT_CLIPBOARD
7887/*
7888 * Extract the items in the 'clipboard' option and set global values.
7889 */
7890 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007891check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007893 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007894 int new_autoselect_star = FALSE;
7895 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007897 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 regprog_T *new_exclude_prog = NULL;
7899 char_u *errmsg = NULL;
7900 char_u *p;
7901
7902 for (p = p_cb; *p != NUL; )
7903 {
7904 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7905 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007906 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 p += 7;
7908 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007909 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007910 && (p[11] == ',' || p[11] == NUL))
7911 {
7912 new_unnamed |= CLIP_UNNAMED_PLUS;
7913 p += 11;
7914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007916 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007918 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 p += 10;
7920 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007921 else if (STRNCMP(p, "autoselectplus", 14) == 0
7922 && (p[14] == ',' || p[14] == NUL))
7923 {
7924 new_autoselect_plus = TRUE;
7925 p += 14;
7926 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007928 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007929 {
7930 new_autoselectml = TRUE;
7931 p += 12;
7932 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007933 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7934 {
7935 new_html = TRUE;
7936 p += 4;
7937 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7939 {
7940 p += 8;
7941 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7942 if (new_exclude_prog == NULL)
7943 errmsg = e_invarg;
7944 break;
7945 }
7946 else
7947 {
7948 errmsg = e_invarg;
7949 break;
7950 }
7951 if (*p == ',')
7952 ++p;
7953 }
7954 if (errmsg == NULL)
7955 {
7956 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007957 clip_autoselect_star = new_autoselect_star;
7958 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007960 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007961 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007963#ifdef FEAT_GUI_GTK
7964 if (gui.in_use)
7965 {
7966 gui_gtk_set_selection_targets();
7967 gui_gtk_set_dnd_targets();
7968 }
7969#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970 }
7971 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007972 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973
7974 return errmsg;
7975}
7976#endif
7977
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007978#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007979 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007980did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007981{
7982 char_u *errmsg = NULL;
7983 win_T *wp;
7984 int l;
7985
7986 if (is_spellfile)
7987 {
7988 l = (int)STRLEN(curwin->w_s->b_p_spf);
7989 if (l > 0 && (l < 4
7990 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7991 errmsg = e_invarg;
7992 }
7993
7994 if (errmsg == NULL)
7995 {
7996 FOR_ALL_WINDOWS(wp)
7997 if (wp->w_buffer == curbuf && wp->w_p_spell)
7998 {
7999 errmsg = did_set_spelllang(wp);
8000# ifdef FEAT_WINDOWS
8001 break;
8002# endif
8003 }
8004 }
8005 return errmsg;
8006}
8007
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008008/*
8009 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8010 * Return error message when failed, NULL when OK.
8011 */
8012 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008013compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008014{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008015 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008016 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008017
Bram Moolenaar860cae12010-06-05 23:22:07 +02008018 if (*synblock->b_p_spc == NUL)
8019 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008020 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008021 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008022 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008023 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008024 if (re != NULL)
8025 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008026 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008027 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008028 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008029 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008030 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008031 return e_invarg;
8032 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008033 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008034 }
8035
Bram Moolenaar473de612013-06-08 18:19:48 +02008036 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008037 return NULL;
8038}
8039#endif
8040
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008041#if defined(FEAT_EVAL) || defined(PROTO)
8042/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008043 * Set the scriptID for an option, taking care of setting the buffer- or
8044 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008045 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008046 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008047set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008048{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008049 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8050 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008051
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008052 /* Remember where the option was set. For local options need to do that
8053 * in the buffer or window structure. */
8054 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008055 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008056 if (both || (opt_flags & OPT_LOCAL))
8057 {
8058 if (indir & PV_BUF)
8059 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8060 else if (indir & PV_WIN)
8061 curwin->w_p_scriptID[indir & PV_MASK] = id;
8062 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008063}
8064#endif
8065
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066/*
8067 * Set the value of a boolean option, and take care of side effects.
8068 * Returns NULL for success, or an error message for an error.
8069 */
8070 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008071set_bool_option(
8072 int opt_idx, /* index in options[] table */
8073 char_u *varp, /* pointer to the option variable */
8074 int value, /* new value */
8075 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008076{
8077 int old_value = *(int *)varp;
8078
Bram Moolenaar071d4272004-06-13 20:20:40 +00008079 /* Disallow changing some options from secure mode */
8080 if ((secure
8081#ifdef HAVE_SANDBOX
8082 || sandbox != 0
8083#endif
8084 ) && (options[opt_idx].flags & P_SECURE))
8085 return e_secure;
8086
8087 *(int *)varp = value; /* set the new value */
8088#ifdef FEAT_EVAL
8089 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008090 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091#endif
8092
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008093#ifdef FEAT_GUI
8094 need_mouse_correct = TRUE;
8095#endif
8096
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097 /* May set global value for local option. */
8098 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8099 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8100
8101 /*
8102 * Handle side effects of changing a bool option.
8103 */
8104
8105 /* 'compatible' */
8106 if ((int *)varp == &p_cp)
8107 {
8108 compatible_set();
8109 }
8110
Bram Moolenaar920694c2016-08-21 17:45:02 +02008111#ifdef FEAT_LANGMAP
8112 if ((int *)varp == &p_lrm)
8113 /* 'langremap' -> !'langnoremap' */
8114 p_lnr = !p_lrm;
8115 else if ((int *)varp == &p_lnr)
8116 /* 'langnoremap' -> !'langremap' */
8117 p_lrm = !p_lnr;
8118#endif
8119
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008120#ifdef FEAT_PERSISTENT_UNDO
8121 /* 'undofile' */
8122 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8123 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008124 /* Only take action when the option was set. When reset we do not
8125 * delete the undo file, the option may be set again without making
8126 * any changes in between. */
8127 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008128 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008129 char_u hash[UNDO_HASH_SIZE];
8130 buf_T *save_curbuf = curbuf;
8131
Bram Moolenaar29323592016-07-24 22:04:11 +02008132 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008133 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008134 /* When 'undofile' is set globally: for every buffer, otherwise
8135 * only for the current buffer: Try to read in the undofile,
8136 * if one exists, the buffer wasn't changed and the buffer was
8137 * loaded */
8138 if ((curbuf == save_curbuf
8139 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8140 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8141 {
8142 u_compute_hash(hash);
8143 u_read_undo(NULL, hash, curbuf->b_fname);
8144 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008145 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008146 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008147 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008148 }
8149#endif
8150
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151 else if ((int *)varp == &curbuf->b_p_ro)
8152 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008153 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008154 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8155 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008156
8157 /* when 'readonly' is set may give W10 again */
8158 if (curbuf->b_p_ro)
8159 curbuf->b_did_warn = FALSE;
8160
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008162 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163#endif
8164 }
8165
Bram Moolenaar9c449722010-07-20 18:44:27 +02008166#ifdef FEAT_GUI
8167 else if ((int *)varp == &p_mh)
8168 {
8169 if (!p_mh)
8170 gui_mch_mousehide(FALSE);
8171 }
8172#endif
8173
Bram Moolenaara539df02010-08-01 14:35:05 +02008174#ifdef FEAT_TITLE
8175 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008177 {
8178 redraw_titles();
8179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008180 /* when 'endofline' is changed, redraw the window title */
8181 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008182 {
8183 redraw_titles();
8184 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008185 /* when 'fixeol' is changed, redraw the window title */
8186 else if ((int *)varp == &curbuf->b_p_fixeol)
8187 {
8188 redraw_titles();
8189 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008190# ifdef FEAT_MBYTE
8191 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008192 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008193 {
8194 redraw_titles();
8195 }
8196# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197#endif
8198
8199 /* when 'bin' is set also set some other options */
8200 else if ((int *)varp == &curbuf->b_p_bin)
8201 {
8202 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8203#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008204 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205#endif
8206 }
8207
8208#ifdef FEAT_AUTOCMD
8209 /* when 'buflisted' changes, trigger autocommands */
8210 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8211 {
8212 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8213 NULL, NULL, TRUE, curbuf);
8214 }
8215#endif
8216
8217 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8218 else if ((int *)varp == &curbuf->b_p_swf)
8219 {
8220 if (curbuf->b_p_swf && p_uc)
8221 ml_open_file(curbuf); /* create the swap file */
8222 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008223 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8224 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225 mf_close_file(curbuf, TRUE); /* remove the swap file */
8226 }
8227
8228 /* when 'terse' is set change 'shortmess' */
8229 else if ((int *)varp == &p_terse)
8230 {
8231 char_u *p;
8232
8233 p = vim_strchr(p_shm, SHM_SEARCH);
8234
8235 /* insert 's' in p_shm */
8236 if (p_terse && p == NULL)
8237 {
8238 STRCPY(IObuff, p_shm);
8239 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008240 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241 }
8242 /* remove 's' from p_shm */
8243 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008244 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245 }
8246
8247 /* when 'paste' is set or reset also change other options */
8248 else if ((int *)varp == &p_paste)
8249 {
8250 paste_option_changed();
8251 }
8252
8253 /* when 'insertmode' is set from an autocommand need to do work here */
8254 else if ((int *)varp == &p_im)
8255 {
8256 if (p_im)
8257 {
8258 if ((State & INSERT) == 0)
8259 need_start_insertmode = TRUE;
8260 stop_insert_mode = FALSE;
8261 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008262 /* only reset if it was set previously */
8263 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008264 {
8265 need_start_insertmode = FALSE;
8266 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008267 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268 clear_cmdline = TRUE; /* remove "(insert)" */
8269 restart_edit = 0;
8270 }
8271 }
8272
8273 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8274 else if ((int *)varp == &p_ic && p_hls)
8275 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008276 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008277 }
8278
8279#ifdef FEAT_SEARCH_EXTRA
8280 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8281 else if ((int *)varp == &p_hls)
8282 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008283 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 }
8285#endif
8286
8287#ifdef FEAT_SCROLLBIND
8288 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8289 * at the end of normal_cmd() */
8290 else if ((int *)varp == &curwin->w_p_scb)
8291 {
8292 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008293 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008294 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008295 curwin->w_scbind_pos = curwin->w_topline;
8296 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 }
8298#endif
8299
8300#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8301 /* There can be only one window with 'previewwindow' set. */
8302 else if ((int *)varp == &curwin->w_p_pvw)
8303 {
8304 if (curwin->w_p_pvw)
8305 {
8306 win_T *win;
8307
Bram Moolenaar29323592016-07-24 22:04:11 +02008308 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008309 if (win->w_p_pvw && win != curwin)
8310 {
8311 curwin->w_p_pvw = FALSE;
8312 return (char_u *)N_("E590: A preview window already exists");
8313 }
8314 }
8315 }
8316#endif
8317
8318 /* when 'textmode' is set or reset also change 'fileformat' */
8319 else if ((int *)varp == &curbuf->b_p_tx)
8320 {
8321 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8322 }
8323
8324 /* when 'textauto' is set or reset also change 'fileformats' */
8325 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 set_string_option_direct((char_u *)"ffs", -1,
8327 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008328 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008329
8330 /*
8331 * When 'lisp' option changes include/exclude '-' in
8332 * keyword characters.
8333 */
8334#ifdef FEAT_LISP
8335 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8336 {
8337 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8338 }
8339#endif
8340
8341#ifdef FEAT_TITLE
8342 /* when 'title' changed, may need to change the title; same for 'icon' */
8343 else if ((int *)varp == &p_title)
8344 {
8345 did_set_title(FALSE);
8346 }
8347
8348 else if ((int *)varp == &p_icon)
8349 {
8350 did_set_title(TRUE);
8351 }
8352#endif
8353
8354 else if ((int *)varp == &curbuf->b_changed)
8355 {
8356 if (!value)
8357 save_file_ff(curbuf); /* Buffer is unchanged */
8358#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008359 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360#endif
8361#ifdef FEAT_AUTOCMD
8362 modified_was_set = value;
8363#endif
8364 }
8365
8366#ifdef BACKSLASH_IN_FILENAME
8367 else if ((int *)varp == &p_ssl)
8368 {
8369 if (p_ssl)
8370 {
8371 psepc = '/';
8372 psepcN = '\\';
8373 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374 }
8375 else
8376 {
8377 psepc = '\\';
8378 psepcN = '/';
8379 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 }
8381
8382 /* need to adjust the file name arguments and buffer names. */
8383 buflist_slash_adjust();
8384 alist_slash_adjust();
8385# ifdef FEAT_EVAL
8386 scriptnames_slash_adjust();
8387# endif
8388 }
8389#endif
8390
8391 /* If 'wrap' is set, set w_leftcol to zero. */
8392 else if ((int *)varp == &curwin->w_p_wrap)
8393 {
8394 if (curwin->w_p_wrap)
8395 curwin->w_leftcol = 0;
8396 }
8397
8398#ifdef FEAT_WINDOWS
8399 else if ((int *)varp == &p_ea)
8400 {
8401 if (p_ea && !old_value)
8402 win_equal(curwin, FALSE, 0);
8403 }
8404#endif
8405
8406 else if ((int *)varp == &p_wiv)
8407 {
8408 /*
8409 * When 'weirdinvert' changed, set/reset 't_xs'.
8410 * Then set 'weirdinvert' according to value of 't_xs'.
8411 */
8412 if (p_wiv && !old_value)
8413 T_XS = (char_u *)"y";
8414 else if (!p_wiv && old_value)
8415 T_XS = empty_option;
8416 p_wiv = (*T_XS != NUL);
8417 }
8418
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008419#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420 else if ((int *)varp == &p_beval)
8421 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008422 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008424 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425 gui_mch_disable_beval_area(balloonEval);
8426 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008427#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008429#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 else if ((int *)varp == &p_acd)
8431 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008432 /* Change directories when the 'acd' option is set now. */
8433 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 }
8435#endif
8436
8437#ifdef FEAT_DIFF
8438 /* 'diff' */
8439 else if ((int *)varp == &curwin->w_p_diff)
8440 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008441 /* May add or remove the buffer from the list of diff buffers. */
8442 diff_buf_adjust(curwin);
8443# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444 if (foldmethodIsDiff(curwin))
8445 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008446# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 }
8448#endif
8449
8450#ifdef USE_IM_CONTROL
8451 /* 'imdisable' */
8452 else if ((int *)varp == &p_imdisable)
8453 {
8454 /* Only de-activate it here, it will be enabled when changing mode. */
8455 if (p_imdisable)
8456 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008457 else if (State & INSERT)
8458 /* When the option is set from an autocommand, it may need to take
8459 * effect right away. */
8460 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008461 }
8462#endif
8463
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008464#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008465 /* 'spell' */
8466 else if ((int *)varp == &curwin->w_p_spell)
8467 {
8468 if (curwin->w_p_spell)
8469 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008470 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008471 if (errmsg != NULL)
8472 EMSG(_(errmsg));
8473 }
8474 }
8475#endif
8476
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477#ifdef FEAT_FKMAP
8478 else if ((int *)varp == &p_altkeymap)
8479 {
8480 if (old_value != p_altkeymap)
8481 {
8482 if (!p_altkeymap)
8483 {
8484 p_hkmap = p_fkmap;
8485 p_fkmap = 0;
8486 }
8487 else
8488 {
8489 p_fkmap = p_hkmap;
8490 p_hkmap = 0;
8491 }
8492 (void)init_chartab();
8493 }
8494 }
8495
8496 /*
8497 * In case some second language keymapping options have changed, check
8498 * and correct the setting in a consistent way.
8499 */
8500
8501 /*
8502 * If hkmap or fkmap are set, reset Arabic keymapping.
8503 */
8504 if ((p_hkmap || p_fkmap) && p_altkeymap)
8505 {
8506 p_altkeymap = p_fkmap;
8507# ifdef FEAT_ARABIC
8508 curwin->w_p_arab = FALSE;
8509# endif
8510 (void)init_chartab();
8511 }
8512
8513 /*
8514 * If hkmap set, reset Farsi keymapping.
8515 */
8516 if (p_hkmap && p_altkeymap)
8517 {
8518 p_altkeymap = 0;
8519 p_fkmap = 0;
8520# ifdef FEAT_ARABIC
8521 curwin->w_p_arab = FALSE;
8522# endif
8523 (void)init_chartab();
8524 }
8525
8526 /*
8527 * If fkmap set, reset Hebrew keymapping.
8528 */
8529 if (p_fkmap && !p_altkeymap)
8530 {
8531 p_altkeymap = 1;
8532 p_hkmap = 0;
8533# ifdef FEAT_ARABIC
8534 curwin->w_p_arab = FALSE;
8535# endif
8536 (void)init_chartab();
8537 }
8538#endif
8539
8540#ifdef FEAT_ARABIC
8541 if ((int *)varp == &curwin->w_p_arab)
8542 {
8543 if (curwin->w_p_arab)
8544 {
8545 /*
8546 * 'arabic' is set, handle various sub-settings.
8547 */
8548 if (!p_tbidi)
8549 {
8550 /* set rightleft mode */
8551 if (!curwin->w_p_rl)
8552 {
8553 curwin->w_p_rl = TRUE;
8554 changed_window_setting();
8555 }
8556
8557 /* Enable Arabic shaping (major part of what Arabic requires) */
8558 if (!p_arshape)
8559 {
8560 p_arshape = TRUE;
8561 redraw_later_clear();
8562 }
8563 }
8564
8565 /* Arabic requires a utf-8 encoding, inform the user if its not
8566 * set. */
8567 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008568 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008569 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8570
Bram Moolenaar8820b482017-03-16 17:23:31 +01008571 msg_source(HL_ATTR(HLF_W));
8572 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008573#ifdef FEAT_EVAL
8574 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8575#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008576 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577
8578# ifdef FEAT_MBYTE
8579 /* set 'delcombine' */
8580 p_deco = TRUE;
8581# endif
8582
8583# ifdef FEAT_KEYMAP
8584 /* Force-set the necessary keymap for arabic */
8585 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8586 OPT_LOCAL);
8587# endif
8588# ifdef FEAT_FKMAP
8589 p_altkeymap = 0;
8590 p_hkmap = 0;
8591 p_fkmap = 0;
8592 (void)init_chartab();
8593# endif
8594 }
8595 else
8596 {
8597 /*
8598 * 'arabic' is reset, handle various sub-settings.
8599 */
8600 if (!p_tbidi)
8601 {
8602 /* reset rightleft mode */
8603 if (curwin->w_p_rl)
8604 {
8605 curwin->w_p_rl = FALSE;
8606 changed_window_setting();
8607 }
8608
8609 /* 'arabicshape' isn't reset, it is a global option and
8610 * another window may still need it "on". */
8611 }
8612
8613 /* 'delcombine' isn't reset, it is a global option and another
8614 * window may still want it "on". */
8615
8616# ifdef FEAT_KEYMAP
8617 /* Revert to the default keymap */
8618 curbuf->b_p_iminsert = B_IMODE_NONE;
8619 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8620# endif
8621 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008622 }
8623
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008624#endif
8625
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008626#ifdef FEAT_TERMGUICOLORS
8627 /* 'termguicolors' */
8628 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008629 {
8630# ifdef FEAT_GUI
8631 if (!gui.in_use && !gui.starting)
8632# endif
8633 highlight_gui_started();
8634 }
8635#endif
8636
Bram Moolenaar071d4272004-06-13 20:20:40 +00008637 /*
8638 * End of handling side effects for bool options.
8639 */
8640
Bram Moolenaar53744302015-07-17 17:38:22 +02008641 /* after handling side effects, call autocommand */
8642
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643 options[opt_idx].flags |= P_WAS_SET;
8644
Bram Moolenaar53744302015-07-17 17:38:22 +02008645#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8646 if (!starting)
8647 {
8648 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008649 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8650 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8651 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008652 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8653 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8654 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8655 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8656 reset_v_option_vars();
8657 }
8658#endif
8659
Bram Moolenaar071d4272004-06-13 20:20:40 +00008660 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008661 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008662 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008663 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 check_redraw(options[opt_idx].flags);
8665
8666 return NULL;
8667}
8668
8669/*
8670 * Set the value of a number option, and take care of side effects.
8671 * Returns NULL for success, or an error message for an error.
8672 */
8673 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008674set_num_option(
8675 int opt_idx, /* index in options[] table */
8676 char_u *varp, /* pointer to the option variable */
8677 long value, /* new value */
8678 char_u *errbuf, /* buffer for error messages */
8679 size_t errbuflen, /* length of "errbuf" */
8680 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008681 OPT_MODELINE */
8682{
8683 char_u *errmsg = NULL;
8684 long old_value = *(long *)varp;
8685 long old_Rows = Rows; /* remember old Rows */
8686 long old_Columns = Columns; /* remember old Columns */
8687 long *pp = (long *)varp;
8688
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008689 /* Disallow changing some options from secure mode. */
8690 if ((secure
8691#ifdef HAVE_SANDBOX
8692 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008694 ) && (options[opt_idx].flags & P_SECURE))
8695 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008696
8697 *pp = value;
8698#ifdef FEAT_EVAL
8699 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008700 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008701#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008702#ifdef FEAT_GUI
8703 need_mouse_correct = TRUE;
8704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705
Bram Moolenaar14f24742012-08-08 18:01:05 +02008706 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008707 {
8708 errmsg = e_positive;
8709 curbuf->b_p_sw = curbuf->b_p_ts;
8710 }
8711
8712 /*
8713 * Number options that need some action when changed
8714 */
8715#ifdef FEAT_WINDOWS
8716 if (pp == &p_wh || pp == &p_hh)
8717 {
8718 if (p_wh < 1)
8719 {
8720 errmsg = e_positive;
8721 p_wh = 1;
8722 }
8723 if (p_wmh > p_wh)
8724 {
8725 errmsg = e_winheight;
8726 p_wh = p_wmh;
8727 }
8728 if (p_hh < 0)
8729 {
8730 errmsg = e_positive;
8731 p_hh = 0;
8732 }
8733
8734 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008735 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008736 {
8737 if (pp == &p_wh && curwin->w_height < p_wh)
8738 win_setheight((int)p_wh);
8739 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8740 win_setheight((int)p_hh);
8741 }
8742 }
8743
8744 /* 'winminheight' */
8745 else if (pp == &p_wmh)
8746 {
8747 if (p_wmh < 0)
8748 {
8749 errmsg = e_positive;
8750 p_wmh = 0;
8751 }
8752 if (p_wmh > p_wh)
8753 {
8754 errmsg = e_winheight;
8755 p_wmh = p_wh;
8756 }
8757 win_setminheight();
8758 }
8759
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008760# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008761 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762 {
8763 if (p_wiw < 1)
8764 {
8765 errmsg = e_positive;
8766 p_wiw = 1;
8767 }
8768 if (p_wmw > p_wiw)
8769 {
8770 errmsg = e_winwidth;
8771 p_wiw = p_wmw;
8772 }
8773
8774 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008775 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 win_setwidth((int)p_wiw);
8777 }
8778
8779 /* 'winminwidth' */
8780 else if (pp == &p_wmw)
8781 {
8782 if (p_wmw < 0)
8783 {
8784 errmsg = e_positive;
8785 p_wmw = 0;
8786 }
8787 if (p_wmw > p_wiw)
8788 {
8789 errmsg = e_winwidth;
8790 p_wmw = p_wiw;
8791 }
8792 win_setminheight();
8793 }
8794# endif
8795
8796#endif
8797
8798#ifdef FEAT_WINDOWS
8799 /* (re)set last window status line */
8800 else if (pp == &p_ls)
8801 {
8802 last_status(FALSE);
8803 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008804
8805 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008806 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008807 {
8808 shell_new_rows(); /* recompute window positions and heights */
8809 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810#endif
8811
8812#ifdef FEAT_GUI
8813 else if (pp == &p_linespace)
8814 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008815 /* Recompute gui.char_height and resize the Vim window to keep the
8816 * same number of lines. */
8817 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008818 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819 }
8820#endif
8821
8822#ifdef FEAT_FOLDING
8823 /* 'foldlevel' */
8824 else if (pp == &curwin->w_p_fdl)
8825 {
8826 if (curwin->w_p_fdl < 0)
8827 curwin->w_p_fdl = 0;
8828 newFoldLevel();
8829 }
8830
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008831 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832 else if (pp == &curwin->w_p_fml)
8833 {
8834 foldUpdateAll(curwin);
8835 }
8836
8837 /* 'foldnestmax' */
8838 else if (pp == &curwin->w_p_fdn)
8839 {
8840 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8841 foldUpdateAll(curwin);
8842 }
8843
8844 /* 'foldcolumn' */
8845 else if (pp == &curwin->w_p_fdc)
8846 {
8847 if (curwin->w_p_fdc < 0)
8848 {
8849 errmsg = e_positive;
8850 curwin->w_p_fdc = 0;
8851 }
8852 else if (curwin->w_p_fdc > 12)
8853 {
8854 errmsg = e_invarg;
8855 curwin->w_p_fdc = 12;
8856 }
8857 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008858#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008859
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008860#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 /* 'shiftwidth' or 'tabstop' */
8862 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8863 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008864# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 if (foldmethodIsIndent(curwin))
8866 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008867# endif
8868# ifdef FEAT_CINDENT
8869 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8870 * parse 'cinoptions'. */
8871 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8872 parse_cino(curbuf);
8873# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008876
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008877#ifdef FEAT_MBYTE
8878 /* 'maxcombine' */
8879 else if (pp == &p_mco)
8880 {
8881 if (p_mco > MAX_MCO)
8882 p_mco = MAX_MCO;
8883 else if (p_mco < 0)
8884 p_mco = 0;
8885 screenclear(); /* will re-allocate the screen */
8886 }
8887#endif
8888
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889 else if (pp == &curbuf->b_p_iminsert)
8890 {
8891 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8892 {
8893 errmsg = e_invarg;
8894 curbuf->b_p_iminsert = B_IMODE_NONE;
8895 }
8896 p_iminsert = curbuf->b_p_iminsert;
8897 if (termcap_active) /* don't do this in the alternate screen */
8898 showmode();
8899#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8900 /* Show/unshow value of 'keymap' in status lines. */
8901 status_redraw_curbuf();
8902#endif
8903 }
8904
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008905 else if (pp == &p_window)
8906 {
8907 if (p_window < 1)
8908 p_window = 1;
8909 else if (p_window >= Rows)
8910 p_window = Rows - 1;
8911 }
8912
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 else if (pp == &curbuf->b_p_imsearch)
8914 {
8915 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8916 {
8917 errmsg = e_invarg;
8918 curbuf->b_p_imsearch = B_IMODE_NONE;
8919 }
8920 p_imsearch = curbuf->b_p_imsearch;
8921 }
8922
8923#ifdef FEAT_TITLE
8924 /* if 'titlelen' has changed, redraw the title */
8925 else if (pp == &p_titlelen)
8926 {
8927 if (p_titlelen < 0)
8928 {
8929 errmsg = e_positive;
8930 p_titlelen = 85;
8931 }
8932 if (starting != NO_SCREEN && old_value != p_titlelen)
8933 need_maketitle = TRUE;
8934 }
8935#endif
8936
8937 /* if p_ch changed value, change the command line height */
8938 else if (pp == &p_ch)
8939 {
8940 if (p_ch < 1)
8941 {
8942 errmsg = e_positive;
8943 p_ch = 1;
8944 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008945 if (p_ch > Rows - min_rows() + 1)
8946 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008947
8948 /* Only compute the new window layout when startup has been
8949 * completed. Otherwise the frame sizes may be wrong. */
8950 if (p_ch != old_value && full_screen
8951#ifdef FEAT_GUI
8952 && !gui.starting
8953#endif
8954 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008955 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956 }
8957
8958 /* when 'updatecount' changes from zero to non-zero, open swap files */
8959 else if (pp == &p_uc)
8960 {
8961 if (p_uc < 0)
8962 {
8963 errmsg = e_positive;
8964 p_uc = 100;
8965 }
8966 if (p_uc && !old_value)
8967 ml_open_files();
8968 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008969#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008970 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008971 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008972 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008973 {
8974 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008975 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008976 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008977 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008978 {
8979 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008980 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008981 }
8982 }
8983#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008984#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008985 else if (pp == &p_mzq)
8986 mzvim_reset_timer();
8987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008988
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008989#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8990 /* 'pyxversion' */
8991 else if (pp == &p_pyx)
8992 {
8993 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8994 errmsg = e_invarg;
8995 }
8996#endif
8997
Bram Moolenaar071d4272004-06-13 20:20:40 +00008998 /* sync undo before 'undolevels' changes */
8999 else if (pp == &p_ul)
9000 {
9001 /* use the old value, otherwise u_sync() may not work properly */
9002 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009003 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004 p_ul = value;
9005 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009006 else if (pp == &curbuf->b_p_ul)
9007 {
9008 /* use the old value, otherwise u_sync() may not work properly */
9009 curbuf->b_p_ul = old_value;
9010 u_sync(TRUE);
9011 curbuf->b_p_ul = value;
9012 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009014#ifdef FEAT_LINEBREAK
9015 /* 'numberwidth' must be positive */
9016 else if (pp == &curwin->w_p_nuw)
9017 {
9018 if (curwin->w_p_nuw < 1)
9019 {
9020 errmsg = e_positive;
9021 curwin->w_p_nuw = 1;
9022 }
9023 if (curwin->w_p_nuw > 10)
9024 {
9025 errmsg = e_invarg;
9026 curwin->w_p_nuw = 10;
9027 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009028 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009029 }
9030#endif
9031
Bram Moolenaar1a384422010-07-14 19:53:30 +02009032 else if (pp == &curbuf->b_p_tw)
9033 {
9034 if (curbuf->b_p_tw < 0)
9035 {
9036 errmsg = e_positive;
9037 curbuf->b_p_tw = 0;
9038 }
9039#ifdef FEAT_SYN_HL
9040# ifdef FEAT_WINDOWS
9041 {
9042 win_T *wp;
9043 tabpage_T *tp;
9044
9045 FOR_ALL_TAB_WINDOWS(tp, wp)
9046 check_colorcolumn(wp);
9047 }
9048# else
9049 check_colorcolumn(curwin);
9050# endif
9051#endif
9052 }
9053
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 /*
9055 * Check the bounds for numeric options here
9056 */
9057 if (Rows < min_rows() && full_screen)
9058 {
9059 if (errbuf != NULL)
9060 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009061 vim_snprintf((char *)errbuf, errbuflen,
9062 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009063 errmsg = errbuf;
9064 }
9065 Rows = min_rows();
9066 }
9067 if (Columns < MIN_COLUMNS && full_screen)
9068 {
9069 if (errbuf != NULL)
9070 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009071 vim_snprintf((char *)errbuf, errbuflen,
9072 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009073 errmsg = errbuf;
9074 }
9075 Columns = MIN_COLUMNS;
9076 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009077 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078
Bram Moolenaar071d4272004-06-13 20:20:40 +00009079 /*
9080 * If the screen (shell) height has been changed, assume it is the
9081 * physical screenheight.
9082 */
9083 if (old_Rows != Rows || old_Columns != Columns)
9084 {
9085 /* Changing the screen size is not allowed while updating the screen. */
9086 if (updating_screen)
9087 *pp = old_value;
9088 else if (full_screen
9089#ifdef FEAT_GUI
9090 && !gui.starting
9091#endif
9092 )
9093 set_shellsize((int)Columns, (int)Rows, TRUE);
9094 else
9095 {
9096 /* Postpone the resizing; check the size and cmdline position for
9097 * messages. */
9098 check_shellsize();
9099 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9100 cmdline_row = Rows - p_ch;
9101 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009102 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009103 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009104 }
9105
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106 if (curbuf->b_p_ts <= 0)
9107 {
9108 errmsg = e_positive;
9109 curbuf->b_p_ts = 8;
9110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 if (p_tm < 0)
9112 {
9113 errmsg = e_positive;
9114 p_tm = 0;
9115 }
9116 if ((curwin->w_p_scr <= 0
9117 || (curwin->w_p_scr > curwin->w_height
9118 && curwin->w_height > 0))
9119 && full_screen)
9120 {
9121 if (pp == &(curwin->w_p_scr))
9122 {
9123 if (curwin->w_p_scr != 0)
9124 errmsg = e_scroll;
9125 win_comp_scroll(curwin);
9126 }
9127 /* If 'scroll' became invalid because of a side effect silently adjust
9128 * it. */
9129 else if (curwin->w_p_scr <= 0)
9130 curwin->w_p_scr = 1;
9131 else /* curwin->w_p_scr > curwin->w_height */
9132 curwin->w_p_scr = curwin->w_height;
9133 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009134 if (p_hi < 0)
9135 {
9136 errmsg = e_positive;
9137 p_hi = 0;
9138 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009139 else if (p_hi > 10000)
9140 {
9141 errmsg = e_invarg;
9142 p_hi = 10000;
9143 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009144 if (p_re < 0 || p_re > 2)
9145 {
9146 errmsg = e_invarg;
9147 p_re = 0;
9148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149 if (p_report < 0)
9150 {
9151 errmsg = e_positive;
9152 p_report = 1;
9153 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009154 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155 {
9156 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9157 p_sj = Rows / 2;
9158 else
9159 {
9160 errmsg = e_scroll;
9161 p_sj = 1;
9162 }
9163 }
9164 if (p_so < 0 && full_screen)
9165 {
9166 errmsg = e_scroll;
9167 p_so = 0;
9168 }
9169 if (p_siso < 0 && full_screen)
9170 {
9171 errmsg = e_positive;
9172 p_siso = 0;
9173 }
9174#ifdef FEAT_CMDWIN
9175 if (p_cwh < 1)
9176 {
9177 errmsg = e_positive;
9178 p_cwh = 1;
9179 }
9180#endif
9181 if (p_ut < 0)
9182 {
9183 errmsg = e_positive;
9184 p_ut = 2000;
9185 }
9186 if (p_ss < 0)
9187 {
9188 errmsg = e_positive;
9189 p_ss = 0;
9190 }
9191
9192 /* May set global value for local option. */
9193 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9194 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9195
9196 options[opt_idx].flags |= P_WAS_SET;
9197
Bram Moolenaar53744302015-07-17 17:38:22 +02009198#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9199 if (!starting && errmsg == NULL)
9200 {
9201 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009202 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9203 vim_snprintf((char *)buf_new, 10, "%ld", value);
9204 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009205 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9206 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9207 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9208 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9209 reset_v_option_vars();
9210 }
9211#endif
9212
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009214 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009215 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009216 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217 check_redraw(options[opt_idx].flags);
9218
9219 return errmsg;
9220}
9221
9222/*
9223 * Called after an option changed: check if something needs to be redrawn.
9224 */
9225 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009226check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227{
9228 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009229 int doclear = (flags & P_RCLR) == P_RCLR;
9230 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231
9232#ifdef FEAT_WINDOWS
9233 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9234 status_redraw_all();
9235#endif
9236
9237 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9238 changed_window_setting();
9239 if (flags & P_RBUF)
9240 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009241 if (flags & P_RWINONLY)
9242 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009243 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009244 redraw_all_later(CLEAR);
9245 else if (all)
9246 redraw_all_later(NOT_VALID);
9247}
9248
9249/*
9250 * Find index for option 'arg'.
9251 * Return -1 if not found.
9252 */
9253 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009254findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255{
9256 int opt_idx;
9257 char *s, *p;
9258 static short quick_tab[27] = {0, 0}; /* quick access table */
9259 int is_term_opt;
9260
9261 /*
9262 * For first call: Initialize the quick-access table.
9263 * It contains the index for the first option that starts with a certain
9264 * letter. There are 26 letters, plus the first "t_" option.
9265 */
9266 if (quick_tab[1] == 0)
9267 {
9268 p = options[0].fullname;
9269 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9270 {
9271 if (s[0] != p[0])
9272 {
9273 if (s[0] == 't' && s[1] == '_')
9274 quick_tab[26] = opt_idx;
9275 else
9276 quick_tab[CharOrdLow(s[0])] = opt_idx;
9277 }
9278 p = s;
9279 }
9280 }
9281
9282 /*
9283 * Check for name starting with an illegal character.
9284 */
9285#ifdef EBCDIC
9286 if (!islower(arg[0]))
9287#else
9288 if (arg[0] < 'a' || arg[0] > 'z')
9289#endif
9290 return -1;
9291
9292 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9293 if (is_term_opt)
9294 opt_idx = quick_tab[26];
9295 else
9296 opt_idx = quick_tab[CharOrdLow(arg[0])];
9297 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9298 {
9299 if (STRCMP(arg, s) == 0) /* match full name */
9300 break;
9301 }
9302 if (s == NULL && !is_term_opt)
9303 {
9304 opt_idx = quick_tab[CharOrdLow(arg[0])];
9305 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9306 {
9307 s = options[opt_idx].shortname;
9308 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9309 break;
9310 s = NULL;
9311 }
9312 }
9313 if (s == NULL)
9314 opt_idx = -1;
9315 return opt_idx;
9316}
9317
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009318#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009319/*
9320 * Get the value for an option.
9321 *
9322 * Returns:
9323 * Number or Toggle option: 1, *numval gets value.
9324 * String option: 0, *stringval gets allocated string.
9325 * Hidden Number or Toggle option: -1.
9326 * hidden String option: -2.
9327 * unknown option: -3.
9328 */
9329 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009330get_option_value(
9331 char_u *name,
9332 long *numval,
9333 char_u **stringval, /* NULL when only checking existence */
9334 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335{
9336 int opt_idx;
9337 char_u *varp;
9338
9339 opt_idx = findoption(name);
9340 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009341 {
9342 int key;
9343
9344 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9345 && (key = find_key_option(name)) != 0)
9346 {
9347 char_u key_name[2];
9348 char_u *p;
9349
9350 if (key < 0)
9351 {
9352 key_name[0] = KEY2TERMCAP0(key);
9353 key_name[1] = KEY2TERMCAP1(key);
9354 }
9355 else
9356 {
9357 key_name[0] = KS_KEY;
9358 key_name[1] = (key & 0xff);
9359 }
9360 p = find_termcode(key_name);
9361 if (p != NULL)
9362 {
9363 if (stringval != NULL)
9364 *stringval = vim_strsave(p);
9365 return 0;
9366 }
9367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009369 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370
9371 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9372
9373 if (options[opt_idx].flags & P_STRING)
9374 {
9375 if (varp == NULL) /* hidden option */
9376 return -2;
9377 if (stringval != NULL)
9378 {
9379#ifdef FEAT_CRYPT
9380 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009381 if ((char_u **)varp == &curbuf->b_p_key
9382 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009383 *stringval = vim_strsave((char_u *)"*****");
9384 else
9385#endif
9386 *stringval = vim_strsave(*(char_u **)(varp));
9387 }
9388 return 0;
9389 }
9390
9391 if (varp == NULL) /* hidden option */
9392 return -1;
9393 if (options[opt_idx].flags & P_NUM)
9394 *numval = *(long *)varp;
9395 else
9396 {
9397 /* Special case: 'modified' is b_changed, but we also want to consider
9398 * it set when 'ff' or 'fenc' changed. */
9399 if ((int *)varp == &curbuf->b_changed)
9400 *numval = curbufIsChanged();
9401 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009402 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009403 }
9404 return 1;
9405}
9406#endif
9407
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009408#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009409/*
9410 * Returns the option attributes and its value. Unlike the above function it
9411 * will return either global value or local value of the option depending on
9412 * what was requested, but it will never return global value if it was
9413 * requested to return local one and vice versa. Neither it will return
9414 * buffer-local value if it was requested to return window-local one.
9415 *
9416 * Pretends that option is absent if it is not present in the requested scope
9417 * (i.e. has no global, window-local or buffer-local value depending on
9418 * opt_type). Uses
9419 *
9420 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009421 * 0 hidden or unknown option, also option that does not have requested
9422 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009423 * see SOPT_* in vim.h for other flags
9424 *
9425 * Possible opt_type values: see SREQ_* in vim.h
9426 */
9427 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009428get_option_value_strict(
9429 char_u *name,
9430 long *numval,
9431 char_u **stringval, /* NULL when only obtaining attributes */
9432 int opt_type,
9433 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009434{
9435 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009436 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009437 struct vimoption *p;
9438 int r = 0;
9439
9440 opt_idx = findoption(name);
9441 if (opt_idx < 0)
9442 return 0;
9443
9444 p = &(options[opt_idx]);
9445
9446 /* Hidden option */
9447 if (p->var == NULL)
9448 return 0;
9449
9450 if (p->flags & P_BOOL)
9451 r |= SOPT_BOOL;
9452 else if (p->flags & P_NUM)
9453 r |= SOPT_NUM;
9454 else if (p->flags & P_STRING)
9455 r |= SOPT_STRING;
9456
9457 if (p->indir == PV_NONE)
9458 {
9459 if (opt_type == SREQ_GLOBAL)
9460 r |= SOPT_GLOBAL;
9461 else
9462 return 0; /* Did not request global-only option */
9463 }
9464 else
9465 {
9466 if (p->indir & PV_BOTH)
9467 r |= SOPT_GLOBAL;
9468 else if (opt_type == SREQ_GLOBAL)
9469 return 0; /* Requested global option */
9470
9471 if (p->indir & PV_WIN)
9472 {
9473 if (opt_type == SREQ_BUF)
9474 return 0; /* Did not request window-local option */
9475 else
9476 r |= SOPT_WIN;
9477 }
9478 else if (p->indir & PV_BUF)
9479 {
9480 if (opt_type == SREQ_WIN)
9481 return 0; /* Did not request buffer-local option */
9482 else
9483 r |= SOPT_BUF;
9484 }
9485 }
9486
9487 if (stringval == NULL)
9488 return r;
9489
9490 if (opt_type == SREQ_GLOBAL)
9491 varp = p->var;
9492 else
9493 {
9494 if (opt_type == SREQ_BUF)
9495 {
9496 /* Special case: 'modified' is b_changed, but we also want to
9497 * consider it set when 'ff' or 'fenc' changed. */
9498 if (p->indir == PV_MOD)
9499 {
9500 *numval = bufIsChanged((buf_T *) from);
9501 varp = NULL;
9502 }
9503#ifdef FEAT_CRYPT
9504 else if (p->indir == PV_KEY)
9505 {
9506 /* never return the value of the crypt key */
9507 *stringval = NULL;
9508 varp = NULL;
9509 }
9510#endif
9511 else
9512 {
9513 aco_save_T aco;
9514 aucmd_prepbuf(&aco, (buf_T *) from);
9515 varp = get_varp(p);
9516 aucmd_restbuf(&aco);
9517 }
9518 }
9519 else if (opt_type == SREQ_WIN)
9520 {
9521 win_T *save_curwin;
9522 save_curwin = curwin;
9523 curwin = (win_T *) from;
9524 curbuf = curwin->w_buffer;
9525 varp = get_varp(p);
9526 curwin = save_curwin;
9527 curbuf = curwin->w_buffer;
9528 }
9529 if (varp == p->var)
9530 return (r | SOPT_UNSET);
9531 }
9532
9533 if (varp != NULL)
9534 {
9535 if (p->flags & P_STRING)
9536 *stringval = vim_strsave(*(char_u **)(varp));
9537 else if (p->flags & P_NUM)
9538 *numval = *(long *) varp;
9539 else
9540 *numval = *(int *)varp;
9541 }
9542
9543 return r;
9544}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009545
9546/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009547 * Iterate over options. First argument is a pointer to a pointer to a
9548 * structure inside options[] array, second is option type like in the above
9549 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009550 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009551 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009552 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009553 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009554 * first argument to NULL.
9555 *
9556 * Returns full option name for current option on each call.
9557 */
9558 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009559option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009560{
9561 struct vimoption *ret = NULL;
9562 do
9563 {
9564 if (*option == NULL)
9565 *option = (void *) options;
9566 else if (((struct vimoption *) (*option))->fullname == NULL)
9567 {
9568 *option = NULL;
9569 return NULL;
9570 }
9571 else
9572 *option = (void *) (((struct vimoption *) (*option)) + 1);
9573
9574 ret = ((struct vimoption *) (*option));
9575
9576 /* Hidden option */
9577 if (ret->var == NULL)
9578 {
9579 ret = NULL;
9580 continue;
9581 }
9582
9583 switch (opt_type)
9584 {
9585 case SREQ_GLOBAL:
9586 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9587 ret = NULL;
9588 break;
9589 case SREQ_BUF:
9590 if (!(ret->indir & PV_BUF))
9591 ret = NULL;
9592 break;
9593 case SREQ_WIN:
9594 if (!(ret->indir & PV_WIN))
9595 ret = NULL;
9596 break;
9597 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009598 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009599 return NULL;
9600 }
9601 }
9602 while (ret == NULL);
9603
9604 return (char_u *)ret->fullname;
9605}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009606#endif
9607
Bram Moolenaar071d4272004-06-13 20:20:40 +00009608/*
9609 * Set the value of option "name".
9610 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009611 *
9612 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009613 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009614 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009615set_option_value(
9616 char_u *name,
9617 long number,
9618 char_u *string,
9619 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620{
9621 int opt_idx;
9622 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009623 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009624
9625 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009626 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009627 {
9628 int key;
9629
9630 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9631 && (key = find_key_option(name)) != 0)
9632 {
9633 char_u key_name[2];
9634
9635 if (key < 0)
9636 {
9637 key_name[0] = KEY2TERMCAP0(key);
9638 key_name[1] = KEY2TERMCAP1(key);
9639 }
9640 else
9641 {
9642 key_name[0] = KS_KEY;
9643 key_name[1] = (key & 0xff);
9644 }
9645 add_termcode(key_name, string, FALSE);
9646 if (full_screen)
9647 ttest(FALSE);
9648 redraw_all_later(CLEAR);
9649 return NULL;
9650 }
9651
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654 else
9655 {
9656 flags = options[opt_idx].flags;
9657#ifdef HAVE_SANDBOX
9658 /* Disallow changing some options in the sandbox */
9659 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009660 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009661 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009662 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009663 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009664#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009665 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009666 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009667 else
9668 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009669 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009670 if (varp != NULL) /* hidden option is not changed */
9671 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009672 if (number == 0 && string != NULL)
9673 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009674 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009675
9676 /* Either we are given a string or we are setting option
9677 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009678 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009679 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009680 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009681 {
9682 /* There's another character after zeros or the string
9683 * is empty. In both cases, we are trying to set a
9684 * num option using a string. */
9685 EMSG3(_("E521: Number required: &%s = '%s'"),
9686 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009687 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009688
9689 }
9690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009691 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009692 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009693 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009695 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009696 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009697 }
9698 }
9699 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009700 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701}
9702
9703/*
9704 * Get the terminal code for a terminal option.
9705 * Returns NULL when not found.
9706 */
9707 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009708get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009709{
9710 int opt_idx;
9711 char_u *varp;
9712
9713 if (tname[0] != 't' || tname[1] != '_' ||
9714 tname[2] == NUL || tname[3] == NUL)
9715 return NULL;
9716 if ((opt_idx = findoption(tname)) >= 0)
9717 {
9718 varp = get_varp(&(options[opt_idx]));
9719 if (varp != NULL)
9720 varp = *(char_u **)(varp);
9721 return varp;
9722 }
9723 return find_termcode(tname + 2);
9724}
9725
9726 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009727get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728{
9729 int i;
9730
9731 i = findoption((char_u *)"hl");
9732 if (i >= 0)
9733 return options[i].def_val[VI_DEFAULT];
9734 return (char_u *)NULL;
9735}
9736
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009737#if defined(FEAT_MBYTE) || defined(PROTO)
9738 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009739get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009740{
9741 int i;
9742
9743 i = findoption((char_u *)"enc");
9744 if (i >= 0)
9745 return options[i].def_val[VI_DEFAULT];
9746 return (char_u *)NULL;
9747}
9748#endif
9749
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750/*
9751 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9752 */
9753 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009754find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755{
9756 int key;
9757 int modifiers;
9758
9759 /*
9760 * Don't use get_special_key_code() for t_xx, we don't want it to call
9761 * add_termcap_entry().
9762 */
9763 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9764 key = TERMCAP2KEY(arg[2], arg[3]);
9765 else
9766 {
9767 --arg; /* put arg at the '<' */
9768 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009769 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770 if (modifiers) /* can't handle modifiers here */
9771 key = 0;
9772 }
9773 return key;
9774}
9775
9776/*
9777 * if 'all' == 0: show changed options
9778 * if 'all' == 1: show all normal options
9779 * if 'all' == 2: show all terminal options
9780 */
9781 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009782showoptions(
9783 int all,
9784 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009785{
9786 struct vimoption *p;
9787 int col;
9788 int isterm;
9789 char_u *varp;
9790 struct vimoption **items;
9791 int item_count;
9792 int run;
9793 int row, rows;
9794 int cols;
9795 int i;
9796 int len;
9797
9798#define INC 20
9799#define GAP 3
9800
9801 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9802 PARAM_COUNT));
9803 if (items == NULL)
9804 return;
9805
9806 /* Highlight title */
9807 if (all == 2)
9808 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9809 else if (opt_flags & OPT_GLOBAL)
9810 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9811 else if (opt_flags & OPT_LOCAL)
9812 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9813 else
9814 MSG_PUTS_TITLE(_("\n--- Options ---"));
9815
9816 /*
9817 * do the loop two times:
9818 * 1. display the short items
9819 * 2. display the long items (only strings and numbers)
9820 */
9821 for (run = 1; run <= 2 && !got_int; ++run)
9822 {
9823 /*
9824 * collect the items in items[]
9825 */
9826 item_count = 0;
9827 for (p = &options[0]; p->fullname != NULL; p++)
9828 {
9829 varp = NULL;
9830 isterm = istermoption(p);
9831 if (opt_flags != 0)
9832 {
9833 if (p->indir != PV_NONE && !isterm)
9834 varp = get_varp_scope(p, opt_flags);
9835 }
9836 else
9837 varp = get_varp(p);
9838 if (varp != NULL
9839 && ((all == 2 && isterm)
9840 || (all == 1 && !isterm)
9841 || (all == 0 && !optval_default(p, varp))))
9842 {
9843 if (p->flags & P_BOOL)
9844 len = 1; /* a toggle option fits always */
9845 else
9846 {
9847 option_value2string(p, opt_flags);
9848 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9849 }
9850 if ((len <= INC - GAP && run == 1) ||
9851 (len > INC - GAP && run == 2))
9852 items[item_count++] = p;
9853 }
9854 }
9855
9856 /*
9857 * display the items
9858 */
9859 if (run == 1)
9860 {
9861 cols = (Columns + GAP - 3) / INC;
9862 if (cols == 0)
9863 cols = 1;
9864 rows = (item_count + cols - 1) / cols;
9865 }
9866 else /* run == 2 */
9867 rows = item_count;
9868 for (row = 0; row < rows && !got_int; ++row)
9869 {
9870 msg_putchar('\n'); /* go to next line */
9871 if (got_int) /* 'q' typed in more */
9872 break;
9873 col = 0;
9874 for (i = row; i < item_count; i += rows)
9875 {
9876 msg_col = col; /* make columns */
9877 showoneopt(items[i], opt_flags);
9878 col += INC;
9879 }
9880 out_flush();
9881 ui_breakcheck();
9882 }
9883 }
9884 vim_free(items);
9885}
9886
9887/*
9888 * Return TRUE if option "p" has its default value.
9889 */
9890 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009891optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892{
9893 int dvi;
9894
9895 if (varp == NULL)
9896 return TRUE; /* hidden option is always at default */
9897 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9898 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009899 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009900 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009901 /* the cast to long is required for Manx C, long_i is
9902 * needed for MSVC */
9903 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009904 /* P_STRING */
9905 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9906}
9907
9908/*
9909 * showoneopt: show the value of one option
9910 * must not be called with a hidden option!
9911 */
9912 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009913showoneopt(
9914 struct vimoption *p,
9915 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009916{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009917 char_u *varp;
9918 int save_silent = silent_mode;
9919
9920 silent_mode = FALSE;
9921 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009922
9923 varp = get_varp_scope(p, opt_flags);
9924
9925 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9926 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9927 ? !curbufIsChanged() : !*(int *)varp))
9928 MSG_PUTS("no");
9929 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9930 MSG_PUTS("--");
9931 else
9932 MSG_PUTS(" ");
9933 MSG_PUTS(p->fullname);
9934 if (!(p->flags & P_BOOL))
9935 {
9936 msg_putchar('=');
9937 /* put value string in NameBuff */
9938 option_value2string(p, opt_flags);
9939 msg_outtrans(NameBuff);
9940 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009941
9942 silent_mode = save_silent;
9943 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009944}
9945
9946/*
9947 * Write modified options as ":set" commands to a file.
9948 *
9949 * There are three values for "opt_flags":
9950 * OPT_GLOBAL: Write global option values and fresh values of
9951 * buffer-local options (used for start of a session
9952 * file).
9953 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9954 * curwin (used for a vimrc file).
9955 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9956 * and local values for window-local options of
9957 * curwin. Local values are also written when at the
9958 * default value, because a modeline or autocommand
9959 * may have set them when doing ":edit file" and the
9960 * user has set them back at the default or fresh
9961 * value.
9962 * When "local_only" is TRUE, don't write fresh
9963 * values, only local values (for ":mkview").
9964 * (fresh value = value used for a new buffer or window for a local option).
9965 *
9966 * Return FAIL on error, OK otherwise.
9967 */
9968 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009969makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009970{
9971 struct vimoption *p;
9972 char_u *varp; /* currently used value */
9973 char_u *varp_fresh; /* local value */
9974 char_u *varp_local = NULL; /* fresh value */
9975 char *cmd;
9976 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009977 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978
9979 /*
9980 * The options that don't have a default (terminal name, columns, lines)
9981 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009982 * Do the loop over "options[]" twice: once for options with the
9983 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009985 for (pri = 1; pri >= 0; --pri)
9986 {
9987 for (p = &options[0]; !istermoption(p); p++)
9988 if (!(p->flags & P_NO_MKRC)
9989 && !istermoption(p)
9990 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009991 {
9992 /* skip global option when only doing locals */
9993 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9994 continue;
9995
9996 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9997 * file, they are always buffer-specific. */
9998 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9999 continue;
10000
10001 /* Global values are only written when not at the default value. */
10002 varp = get_varp_scope(p, opt_flags);
10003 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10004 continue;
10005
10006 round = 2;
10007 if (p->indir != PV_NONE)
10008 {
10009 if (p->var == VAR_WIN)
10010 {
10011 /* skip window-local option when only doing globals */
10012 if (!(opt_flags & OPT_LOCAL))
10013 continue;
10014 /* When fresh value of window-local option is not at the
10015 * default, need to write it too. */
10016 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10017 {
10018 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10019 if (!optval_default(p, varp_fresh))
10020 {
10021 round = 1;
10022 varp_local = varp;
10023 varp = varp_fresh;
10024 }
10025 }
10026 }
10027 }
10028
10029 /* Round 1: fresh value for window-local options.
10030 * Round 2: other values */
10031 for ( ; round <= 2; varp = varp_local, ++round)
10032 {
10033 if (round == 1 || (opt_flags & OPT_GLOBAL))
10034 cmd = "set";
10035 else
10036 cmd = "setlocal";
10037
10038 if (p->flags & P_BOOL)
10039 {
10040 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10041 return FAIL;
10042 }
10043 else if (p->flags & P_NUM)
10044 {
10045 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10046 return FAIL;
10047 }
10048 else /* P_STRING */
10049 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010050#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10051 int do_endif = FALSE;
10052
Bram Moolenaar071d4272004-06-13 20:20:40 +000010053 /* Don't set 'syntax' and 'filetype' again if the value is
10054 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010055 if (
10056# if defined(FEAT_SYN_HL)
10057 p->indir == PV_SYN
10058# if defined(FEAT_AUTOCMD)
10059 ||
10060# endif
10061# endif
10062# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010063 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010064# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010065 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066 {
10067 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10068 *(char_u **)(varp)) < 0
10069 || put_eol(fd) < 0)
10070 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010071 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010074 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10075 (p->flags & P_EXPAND) != 0) == FAIL)
10076 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010077#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10078 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079 {
10080 if (put_line(fd, "endif") == FAIL)
10081 return FAIL;
10082 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010083#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010084 }
10085 }
10086 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010088 return OK;
10089}
10090
10091#if defined(FEAT_FOLDING) || defined(PROTO)
10092/*
10093 * Generate set commands for the local fold options only. Used when
10094 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10095 */
10096 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010097makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010098{
10099 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10100# ifdef FEAT_EVAL
10101 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10102 == FAIL
10103# endif
10104 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10105 == FAIL
10106 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10107 == FAIL
10108 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10109 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10110 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10111 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10112 )
10113 return FAIL;
10114
10115 return OK;
10116}
10117#endif
10118
10119 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010120put_setstring(
10121 FILE *fd,
10122 char *cmd,
10123 char *name,
10124 char_u **valuep,
10125 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126{
10127 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010128 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129
10130 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10131 return FAIL;
10132 if (*valuep != NULL)
10133 {
10134 /* Output 'pastetoggle' as key names. For other
10135 * options some characters have to be escaped with
10136 * CTRL-V or backslash */
10137 if (valuep == &p_pt)
10138 {
10139 s = *valuep;
10140 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010141 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010142 return FAIL;
10143 }
10144 else if (expand)
10145 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010146 buf = alloc(MAXPATHL);
10147 if (buf == NULL)
10148 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10150 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010151 {
10152 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010154 }
10155 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010156 }
10157 else if (put_escstr(fd, *valuep, 2) == FAIL)
10158 return FAIL;
10159 }
10160 if (put_eol(fd) < 0)
10161 return FAIL;
10162 return OK;
10163}
10164
10165 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010166put_setnum(
10167 FILE *fd,
10168 char *cmd,
10169 char *name,
10170 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171{
10172 long wc;
10173
10174 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10175 return FAIL;
10176 if (wc_use_keyname((char_u *)valuep, &wc))
10177 {
10178 /* print 'wildchar' and 'wildcharm' as a key name */
10179 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10180 return FAIL;
10181 }
10182 else if (fprintf(fd, "%ld", *valuep) < 0)
10183 return FAIL;
10184 if (put_eol(fd) < 0)
10185 return FAIL;
10186 return OK;
10187}
10188
10189 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010190put_setbool(
10191 FILE *fd,
10192 char *cmd,
10193 char *name,
10194 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195{
Bram Moolenaar893de922007-10-02 18:40:57 +000010196 if (value < 0) /* global/local option using global value */
10197 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10199 || put_eol(fd) < 0)
10200 return FAIL;
10201 return OK;
10202}
10203
10204/*
10205 * Clear all the terminal options.
10206 * If the option has been allocated, free the memory.
10207 * Terminal options are never hidden or indirect.
10208 */
10209 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010210clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212 /*
10213 * Reset a few things before clearing the old options. This may cause
10214 * outputting a few things that the terminal doesn't understand, but the
10215 * screen will be cleared later, so this is OK.
10216 */
10217#ifdef FEAT_MOUSE_TTY
10218 mch_setmouse(FALSE); /* switch mouse off */
10219#endif
10220#ifdef FEAT_TITLE
10221 mch_restore_title(3); /* restore window titles */
10222#endif
10223#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10224 /* When starting the GUI close the display opened for the clipboard.
10225 * After restoring the title, because that will need the display. */
10226 if (gui.starting)
10227 clear_xterm_clip();
10228#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010229 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010230
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010231 free_termoptions();
10232}
10233
10234 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010235free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010236{
10237 struct vimoption *p;
10238
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239 for (p = &options[0]; p->fullname != NULL; p++)
10240 if (istermoption(p))
10241 {
10242 if (p->flags & P_ALLOCED)
10243 free_string_option(*(char_u **)(p->var));
10244 if (p->flags & P_DEF_ALLOCED)
10245 free_string_option(p->def_val[VI_DEFAULT]);
10246 *(char_u **)(p->var) = empty_option;
10247 p->def_val[VI_DEFAULT] = empty_option;
10248 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10249 }
10250 clear_termcodes();
10251}
10252
10253/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010254 * Free the string for one term option, if it was allocated.
10255 * Set the string to empty_option and clear allocated flag.
10256 * "var" points to the option value.
10257 */
10258 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010259free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010260{
10261 struct vimoption *p;
10262
10263 for (p = &options[0]; p->fullname != NULL; p++)
10264 if (p->var == var)
10265 {
10266 if (p->flags & P_ALLOCED)
10267 free_string_option(*(char_u **)(p->var));
10268 *(char_u **)(p->var) = empty_option;
10269 p->flags &= ~P_ALLOCED;
10270 break;
10271 }
10272}
10273
10274/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275 * Set the terminal option defaults to the current value.
10276 * Used after setting the terminal name.
10277 */
10278 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010279set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010280{
10281 struct vimoption *p;
10282
10283 for (p = &options[0]; p->fullname != NULL; p++)
10284 {
10285 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10286 {
10287 if (p->flags & P_DEF_ALLOCED)
10288 {
10289 free_string_option(p->def_val[VI_DEFAULT]);
10290 p->flags &= ~P_DEF_ALLOCED;
10291 }
10292 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10293 if (p->flags & P_ALLOCED)
10294 {
10295 p->flags |= P_DEF_ALLOCED;
10296 p->flags &= ~P_ALLOCED; /* don't free the value now */
10297 }
10298 }
10299 }
10300}
10301
10302/*
10303 * return TRUE if 'p' starts with 't_'
10304 */
10305 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010306istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307{
10308 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10309}
10310
10311/*
10312 * Compute columns for ruler and shown command. 'sc_col' is also used to
10313 * decide what the maximum length of a message on the status line can be.
10314 * If there is a status line for the last window, 'sc_col' is independent
10315 * of 'ru_col'.
10316 */
10317
10318#define COL_RULER 17 /* columns needed by standard ruler */
10319
10320 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010321comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322{
10323#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010324 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325
10326 sc_col = 0;
10327 ru_col = 0;
10328 if (p_ru)
10329 {
10330#ifdef FEAT_STL_OPT
10331 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10332#else
10333 ru_col = COL_RULER + 1;
10334#endif
10335 /* no last status line, adjust sc_col */
10336 if (!last_has_status)
10337 sc_col = ru_col;
10338 }
10339 if (p_sc)
10340 {
10341 sc_col += SHOWCMD_COLS;
10342 if (!p_ru || last_has_status) /* no need for separating space */
10343 ++sc_col;
10344 }
10345 sc_col = Columns - sc_col;
10346 ru_col = Columns - ru_col;
10347 if (sc_col <= 0) /* screen too narrow, will become a mess */
10348 sc_col = 1;
10349 if (ru_col <= 0)
10350 ru_col = 1;
10351#else
10352 sc_col = Columns;
10353 ru_col = Columns;
10354#endif
10355}
10356
10357/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010358 * Unset local option value, similar to ":set opt<".
10359 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010360 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010361unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010362{
10363 struct vimoption *p;
10364 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010365 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010366
10367 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010368 if (opt_idx < 0)
10369 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010370 p = &(options[opt_idx]);
10371
10372 switch ((int)p->indir)
10373 {
10374 /* global option with local value: use local value if it's been set */
10375 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010376 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010377 break;
10378 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010379 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010380 break;
10381 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010382 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010383 break;
10384 case PV_AR:
10385 buf->b_p_ar = -1;
10386 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010387 case PV_BKC:
10388 clear_string_option(&buf->b_p_bkc);
10389 buf->b_bkc_flags = 0;
10390 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010391 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010392 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010393 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010394 case PV_TC:
10395 clear_string_option(&buf->b_p_tc);
10396 buf->b_tc_flags = 0;
10397 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010398#ifdef FEAT_FIND_ID
10399 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010400 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010401 break;
10402 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010403 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010404 break;
10405#endif
10406#ifdef FEAT_INS_EXPAND
10407 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010408 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010409 break;
10410 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010411 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010412 break;
10413#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010414 case PV_FP:
10415 clear_string_option(&buf->b_p_fp);
10416 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010417#ifdef FEAT_QUICKFIX
10418 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010419 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010420 break;
10421 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010422 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010423 break;
10424 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010425 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010426 break;
10427#endif
10428#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10429 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010430 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 break;
10432#endif
10433#if defined(FEAT_CRYPT)
10434 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010435 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010436 break;
10437#endif
10438#ifdef FEAT_STL_OPT
10439 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010440 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010441 break;
10442#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010443 case PV_UL:
10444 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10445 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010446#ifdef FEAT_LISP
10447 case PV_LW:
10448 clear_string_option(&buf->b_p_lw);
10449 break;
10450#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010451#ifdef FEAT_MBYTE
10452 case PV_MENC:
10453 clear_string_option(&buf->b_p_menc);
10454 break;
10455#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010456 }
10457}
10458
10459/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460 * Get pointer to option variable, depending on local or global scope.
10461 */
10462 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010463get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464{
10465 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10466 {
10467 if (p->var == VAR_WIN)
10468 return (char_u *)GLOBAL_WO(get_varp(p));
10469 return p->var;
10470 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010471 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472 {
10473 switch ((int)p->indir)
10474 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010475 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010477 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10478 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10479 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010481 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10482 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10483 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010484 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010485 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010486 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010488 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10489 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490#endif
10491#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010492 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10493 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010495#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10496 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10497#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010498#if defined(FEAT_CRYPT)
10499 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10500#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010501#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010502 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010503#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010504 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010505#ifdef FEAT_LISP
10506 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10507#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010508 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010509#ifdef FEAT_MBYTE
10510 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10511#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512 }
10513 return NULL; /* "cannot happen" */
10514 }
10515 return get_varp(p);
10516}
10517
10518/*
10519 * Get pointer to option variable.
10520 */
10521 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010522get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523{
10524 /* hidden option, always return NULL */
10525 if (p->var == NULL)
10526 return NULL;
10527
10528 switch ((int)p->indir)
10529 {
10530 case PV_NONE: return p->var;
10531
10532 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010533 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010535 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010537 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010539 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010540 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010541 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010543 case PV_TC: return *curbuf->b_p_tc != NUL
10544 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010545 case PV_BKC: return *curbuf->b_p_bkc != NUL
10546 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010548 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010550 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10552#endif
10553#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010554 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010556 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010557 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10558#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010559 case PV_FP: return *curbuf->b_p_fp != NUL
10560 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010562 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010564 case PV_GP: return *curbuf->b_p_gp != NUL
10565 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10566 case PV_MP: return *curbuf->b_p_mp != NUL
10567 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010569#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10570 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10571 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10572#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010573#if defined(FEAT_CRYPT)
10574 case PV_CM: return *curbuf->b_p_cm != NUL
10575 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10576#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010577#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010578 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010579 ? (char_u *)&(curwin->w_p_stl) : p->var;
10580#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010581 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10582 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010583#ifdef FEAT_LISP
10584 case PV_LW: return *curbuf->b_p_lw != NUL
10585 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10586#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010587#ifdef FEAT_MBYTE
10588 case PV_MENC: return *curbuf->b_p_menc != NUL
10589 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10590#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591
10592#ifdef FEAT_ARABIC
10593 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10594#endif
10595 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010596#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010597 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10598#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010599#ifdef FEAT_SYN_HL
10600 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10601 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010602 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010603#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604#ifdef FEAT_DIFF
10605 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10606#endif
10607#ifdef FEAT_FOLDING
10608 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10609 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10610 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10611 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10612 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10613 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10614 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10615# ifdef FEAT_EVAL
10616 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10617 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10618# endif
10619 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10620#endif
10621 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010622 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010623#ifdef FEAT_LINEBREAK
10624 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10625#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010626#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010627 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010628 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10631 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10632#endif
10633#ifdef FEAT_RIGHTLEFT
10634 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10635 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10636#endif
10637 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10638 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10639#ifdef FEAT_LINEBREAK
10640 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010641 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10642 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643#endif
10644#ifdef FEAT_SCROLLBIND
10645 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10646#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010647#ifdef FEAT_CURSORBIND
10648 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10649#endif
10650#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010651 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10652 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010653#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010654
10655 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10656 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10657#ifdef FEAT_MBYTE
10658 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10659#endif
10660#if defined(FEAT_QUICKFIX)
10661 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10662 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10663#endif
10664 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10665 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10666#ifdef FEAT_CINDENT
10667 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10668 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10669 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10670#endif
10671#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10672 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10673#endif
10674#ifdef FEAT_COMMENTS
10675 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10676#endif
10677#ifdef FEAT_FOLDING
10678 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10679#endif
10680#ifdef FEAT_INS_EXPAND
10681 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10682#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010683#ifdef FEAT_COMPL_FUNC
10684 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010685 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010687 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010688 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10690#ifdef FEAT_MBYTE
10691 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10692#endif
10693 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10694#ifdef FEAT_AUTOCMD
10695 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10696#endif
10697 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010698 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10700 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10701 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10702 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10703#ifdef FEAT_FIND_ID
10704# ifdef FEAT_EVAL
10705 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10706# endif
10707#endif
10708#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10709 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10710 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10711#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010712#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010713 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715#ifdef FEAT_CRYPT
10716 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10717#endif
10718#ifdef FEAT_LISP
10719 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10720#endif
10721 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10722 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10723 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10724 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10725 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010727#ifdef FEAT_TEXTOBJ
10728 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10729#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10731#ifdef FEAT_SMARTINDENT
10732 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10733#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10736#ifdef FEAT_SEARCHPATH
10737 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10738#endif
10739 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10740#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010741 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010742 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10743#endif
10744#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010745 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10746 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10747 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748#endif
10749 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10750 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10751 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10752 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010753#ifdef FEAT_PERSISTENT_UNDO
10754 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10755#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010756 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10757#ifdef FEAT_KEYMAP
10758 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10759#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010760#ifdef FEAT_SIGNS
10761 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10762#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010763 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764 }
10765 /* always return a valid pointer to avoid a crash! */
10766 return (char_u *)&(curbuf->b_p_wm);
10767}
10768
10769/*
10770 * Get the value of 'equalprg', either the buffer-local one or the global one.
10771 */
10772 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010773get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774{
10775 if (*curbuf->b_p_ep == NUL)
10776 return p_ep;
10777 return curbuf->b_p_ep;
10778}
10779
10780#if defined(FEAT_WINDOWS) || defined(PROTO)
10781/*
10782 * Copy options from one window to another.
10783 * Used when splitting a window.
10784 */
10785 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010786win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787{
10788 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10789 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10790# ifdef FEAT_RIGHTLEFT
10791# ifdef FEAT_FKMAP
10792 /* Is this right? */
10793 wp_to->w_farsi = wp_from->w_farsi;
10794# endif
10795# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010796#if defined(FEAT_LINEBREAK)
10797 briopt_check(wp_to);
10798#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799}
10800#endif
10801
10802/*
10803 * Copy the options from one winopt_T to another.
10804 * Doesn't free the old option values in "to", use clear_winopt() for that.
10805 * The 'scroll' option is not copied, because it depends on the window height.
10806 * The 'previewwindow' option is reset, there can be only one preview window.
10807 */
10808 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010809copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810{
10811#ifdef FEAT_ARABIC
10812 to->wo_arab = from->wo_arab;
10813#endif
10814 to->wo_list = from->wo_list;
10815 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010816 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010817#ifdef FEAT_LINEBREAK
10818 to->wo_nuw = from->wo_nuw;
10819#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820#ifdef FEAT_RIGHTLEFT
10821 to->wo_rl = from->wo_rl;
10822 to->wo_rlc = vim_strsave(from->wo_rlc);
10823#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010824#ifdef FEAT_STL_OPT
10825 to->wo_stl = vim_strsave(from->wo_stl);
10826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010828#ifdef FEAT_DIFF
10829 to->wo_wrap_save = from->wo_wrap_save;
10830#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010831#ifdef FEAT_LINEBREAK
10832 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010833 to->wo_bri = from->wo_bri;
10834 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835#endif
10836#ifdef FEAT_SCROLLBIND
10837 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010838 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010840#ifdef FEAT_CURSORBIND
10841 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010842 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010843#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010844#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010845 to->wo_spell = from->wo_spell;
10846#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010847#ifdef FEAT_SYN_HL
10848 to->wo_cuc = from->wo_cuc;
10849 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010850 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010851#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852#ifdef FEAT_DIFF
10853 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010854 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010856#ifdef FEAT_CONCEAL
10857 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010858 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010859#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860#ifdef FEAT_FOLDING
10861 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010862 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010864 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 to->wo_fdi = vim_strsave(from->wo_fdi);
10866 to->wo_fml = from->wo_fml;
10867 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010868 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010870 to->wo_fdm_save = from->wo_diff_saved
10871 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872 to->wo_fdn = from->wo_fdn;
10873# ifdef FEAT_EVAL
10874 to->wo_fde = vim_strsave(from->wo_fde);
10875 to->wo_fdt = vim_strsave(from->wo_fdt);
10876# endif
10877 to->wo_fmr = vim_strsave(from->wo_fmr);
10878#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010879#ifdef FEAT_SIGNS
10880 to->wo_scl = vim_strsave(from->wo_scl);
10881#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882 check_winopt(to); /* don't want NULL pointers */
10883}
10884
10885/*
10886 * Check string options in a window for a NULL value.
10887 */
10888 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010889check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890{
10891 check_winopt(&win->w_onebuf_opt);
10892 check_winopt(&win->w_allbuf_opt);
10893}
10894
10895/*
10896 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10897 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010898 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010899check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900{
10901#ifdef FEAT_FOLDING
10902 check_string_option(&wop->wo_fdi);
10903 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010904 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905# ifdef FEAT_EVAL
10906 check_string_option(&wop->wo_fde);
10907 check_string_option(&wop->wo_fdt);
10908# endif
10909 check_string_option(&wop->wo_fmr);
10910#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010911#ifdef FEAT_SIGNS
10912 check_string_option(&wop->wo_scl);
10913#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914#ifdef FEAT_RIGHTLEFT
10915 check_string_option(&wop->wo_rlc);
10916#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010917#ifdef FEAT_STL_OPT
10918 check_string_option(&wop->wo_stl);
10919#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010920#ifdef FEAT_SYN_HL
10921 check_string_option(&wop->wo_cc);
10922#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010923#ifdef FEAT_CONCEAL
10924 check_string_option(&wop->wo_cocu);
10925#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010926#ifdef FEAT_LINEBREAK
10927 check_string_option(&wop->wo_briopt);
10928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929}
10930
10931/*
10932 * Free the allocated memory inside a winopt_T.
10933 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010934 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010935clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936{
10937#ifdef FEAT_FOLDING
10938 clear_string_option(&wop->wo_fdi);
10939 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010940 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941# ifdef FEAT_EVAL
10942 clear_string_option(&wop->wo_fde);
10943 clear_string_option(&wop->wo_fdt);
10944# endif
10945 clear_string_option(&wop->wo_fmr);
10946#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010947#ifdef FEAT_SIGNS
10948 clear_string_option(&wop->wo_scl);
10949#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010950#ifdef FEAT_LINEBREAK
10951 clear_string_option(&wop->wo_briopt);
10952#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010953#ifdef FEAT_RIGHTLEFT
10954 clear_string_option(&wop->wo_rlc);
10955#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010956#ifdef FEAT_STL_OPT
10957 clear_string_option(&wop->wo_stl);
10958#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010959#ifdef FEAT_SYN_HL
10960 clear_string_option(&wop->wo_cc);
10961#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010962#ifdef FEAT_CONCEAL
10963 clear_string_option(&wop->wo_cocu);
10964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010965}
10966
10967/*
10968 * Copy global option values to local options for one buffer.
10969 * Used when creating a new buffer and sometimes when entering a buffer.
10970 * flags:
10971 * BCO_ENTER We will enter the buf buffer.
10972 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10973 * appropriate.
10974 * BCO_NOHELP Don't copy the values to a help buffer.
10975 */
10976 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010977buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010978{
10979 int should_copy = TRUE;
10980 char_u *save_p_isk = NULL; /* init for GCC */
10981 int dont_do_help;
10982 int did_isk = FALSE;
10983
10984 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010985 * Skip this when the option defaults have not been set yet. Happens when
10986 * main() allocates the first buffer.
10987 */
10988 if (p_cpo != NULL)
10989 {
10990 /*
10991 * Always copy when entering and 'cpo' contains 'S'.
10992 * Don't copy when already initialized.
10993 * Don't copy when 'cpo' contains 's' and not entering.
10994 * 'S' BCO_ENTER initialized 's' should_copy
10995 * yes yes X X TRUE
10996 * yes no yes X FALSE
10997 * no X yes X FALSE
10998 * X no no yes FALSE
10999 * X no no no TRUE
11000 * no yes no X TRUE
11001 */
11002 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11003 && (buf->b_p_initialized
11004 || (!(flags & BCO_ENTER)
11005 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11006 should_copy = FALSE;
11007
11008 if (should_copy || (flags & BCO_ALWAYS))
11009 {
11010 /* Don't copy the options specific to a help buffer when
11011 * BCO_NOHELP is given or the options were initialized already
11012 * (jumping back to a help file with CTRL-T or CTRL-O) */
11013 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11014 || buf->b_p_initialized;
11015 if (dont_do_help) /* don't free b_p_isk */
11016 {
11017 save_p_isk = buf->b_p_isk;
11018 buf->b_p_isk = NULL;
11019 }
11020 /*
11021 * Always free the allocated strings.
11022 * If not already initialized, set 'readonly' and copy 'fileformat'.
11023 */
11024 if (!buf->b_p_initialized)
11025 {
11026 free_buf_options(buf, TRUE);
11027 buf->b_p_ro = FALSE; /* don't copy readonly */
11028 buf->b_p_tx = p_tx;
11029#ifdef FEAT_MBYTE
11030 buf->b_p_fenc = vim_strsave(p_fenc);
11031#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011032 switch (*p_ffs)
11033 {
11034 case 'm':
11035 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11036 case 'd':
11037 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11038 case 'u':
11039 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11040 default:
11041 buf->b_p_ff = vim_strsave(p_ff);
11042 }
11043 if (buf->b_p_ff != NULL)
11044 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011045#if defined(FEAT_QUICKFIX)
11046 buf->b_p_bh = empty_option;
11047 buf->b_p_bt = empty_option;
11048#endif
11049 }
11050 else
11051 free_buf_options(buf, FALSE);
11052
11053 buf->b_p_ai = p_ai;
11054 buf->b_p_ai_nopaste = p_ai_nopaste;
11055 buf->b_p_sw = p_sw;
11056 buf->b_p_tw = p_tw;
11057 buf->b_p_tw_nopaste = p_tw_nopaste;
11058 buf->b_p_tw_nobin = p_tw_nobin;
11059 buf->b_p_wm = p_wm;
11060 buf->b_p_wm_nopaste = p_wm_nopaste;
11061 buf->b_p_wm_nobin = p_wm_nobin;
11062 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011063#ifdef FEAT_MBYTE
11064 buf->b_p_bomb = p_bomb;
11065#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011066 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011067 buf->b_p_et = p_et;
11068 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011069 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011070 buf->b_p_ml = p_ml;
11071 buf->b_p_ml_nobin = p_ml_nobin;
11072 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011073 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074#ifdef FEAT_INS_EXPAND
11075 buf->b_p_cpt = vim_strsave(p_cpt);
11076#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011077#ifdef FEAT_COMPL_FUNC
11078 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011079 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011080#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011081 buf->b_p_sts = p_sts;
11082 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011084#ifdef FEAT_COMMENTS
11085 buf->b_p_com = vim_strsave(p_com);
11086#endif
11087#ifdef FEAT_FOLDING
11088 buf->b_p_cms = vim_strsave(p_cms);
11089#endif
11090 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011091 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011092 buf->b_p_nf = vim_strsave(p_nf);
11093 buf->b_p_mps = vim_strsave(p_mps);
11094#ifdef FEAT_SMARTINDENT
11095 buf->b_p_si = p_si;
11096#endif
11097 buf->b_p_ci = p_ci;
11098#ifdef FEAT_CINDENT
11099 buf->b_p_cin = p_cin;
11100 buf->b_p_cink = vim_strsave(p_cink);
11101 buf->b_p_cino = vim_strsave(p_cino);
11102#endif
11103#ifdef FEAT_AUTOCMD
11104 /* Don't copy 'filetype', it must be detected */
11105 buf->b_p_ft = empty_option;
11106#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107 buf->b_p_pi = p_pi;
11108#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11109 buf->b_p_cinw = vim_strsave(p_cinw);
11110#endif
11111#ifdef FEAT_LISP
11112 buf->b_p_lisp = p_lisp;
11113#endif
11114#ifdef FEAT_SYN_HL
11115 /* Don't copy 'syntax', it must be set */
11116 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011117 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011118 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011119#endif
11120#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011121 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011122 (void)compile_cap_prog(&buf->b_s);
11123 buf->b_s.b_p_spf = vim_strsave(p_spf);
11124 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011125#endif
11126#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11127 buf->b_p_inde = vim_strsave(p_inde);
11128 buf->b_p_indk = vim_strsave(p_indk);
11129#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011130 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011131#if defined(FEAT_EVAL)
11132 buf->b_p_fex = vim_strsave(p_fex);
11133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011134#ifdef FEAT_CRYPT
11135 buf->b_p_key = vim_strsave(p_key);
11136#endif
11137#ifdef FEAT_SEARCHPATH
11138 buf->b_p_sua = vim_strsave(p_sua);
11139#endif
11140#ifdef FEAT_KEYMAP
11141 buf->b_p_keymap = vim_strsave(p_keymap);
11142 buf->b_kmap_state |= KEYMAP_INIT;
11143#endif
11144 /* This isn't really an option, but copying the langmap and IME
11145 * state from the current buffer is better than resetting it. */
11146 buf->b_p_iminsert = p_iminsert;
11147 buf->b_p_imsearch = p_imsearch;
11148
11149 /* options that are normally global but also have a local value
11150 * are not copied, start using the global value */
11151 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011152 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011153 buf->b_p_bkc = empty_option;
11154 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155#ifdef FEAT_QUICKFIX
11156 buf->b_p_gp = empty_option;
11157 buf->b_p_mp = empty_option;
11158 buf->b_p_efm = empty_option;
11159#endif
11160 buf->b_p_ep = empty_option;
11161 buf->b_p_kp = empty_option;
11162 buf->b_p_path = empty_option;
11163 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011164 buf->b_p_tc = empty_option;
11165 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166#ifdef FEAT_FIND_ID
11167 buf->b_p_def = empty_option;
11168 buf->b_p_inc = empty_option;
11169# ifdef FEAT_EVAL
11170 buf->b_p_inex = vim_strsave(p_inex);
11171# endif
11172#endif
11173#ifdef FEAT_INS_EXPAND
11174 buf->b_p_dict = empty_option;
11175 buf->b_p_tsr = empty_option;
11176#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011177#ifdef FEAT_TEXTOBJ
11178 buf->b_p_qe = vim_strsave(p_qe);
11179#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011180#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11181 buf->b_p_bexpr = empty_option;
11182#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011183#if defined(FEAT_CRYPT)
11184 buf->b_p_cm = empty_option;
11185#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011186#ifdef FEAT_PERSISTENT_UNDO
11187 buf->b_p_udf = p_udf;
11188#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011189#ifdef FEAT_LISP
11190 buf->b_p_lw = empty_option;
11191#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011192#ifdef FEAT_MBYTE
11193 buf->b_p_menc = empty_option;
11194#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195
11196 /*
11197 * Don't copy the options set by ex_help(), use the saved values,
11198 * when going from a help buffer to a non-help buffer.
11199 * Don't touch these at all when BCO_NOHELP is used and going from
11200 * or to a help buffer.
11201 */
11202 if (dont_do_help)
11203 buf->b_p_isk = save_p_isk;
11204 else
11205 {
11206 buf->b_p_isk = vim_strsave(p_isk);
11207 did_isk = TRUE;
11208 buf->b_p_ts = p_ts;
11209 buf->b_help = FALSE;
11210#ifdef FEAT_QUICKFIX
11211 if (buf->b_p_bt[0] == 'h')
11212 clear_string_option(&buf->b_p_bt);
11213#endif
11214 buf->b_p_ma = p_ma;
11215 }
11216 }
11217
11218 /*
11219 * When the options should be copied (ignoring BCO_ALWAYS), set the
11220 * flag that indicates that the options have been initialized.
11221 */
11222 if (should_copy)
11223 buf->b_p_initialized = TRUE;
11224 }
11225
11226 check_buf_options(buf); /* make sure we don't have NULLs */
11227 if (did_isk)
11228 (void)buf_init_chartab(buf, FALSE);
11229}
11230
11231/*
11232 * Reset the 'modifiable' option and its default value.
11233 */
11234 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011235reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236{
11237 int opt_idx;
11238
11239 curbuf->b_p_ma = FALSE;
11240 p_ma = FALSE;
11241 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011242 if (opt_idx >= 0)
11243 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011244}
11245
11246/*
11247 * Set the global value for 'iminsert' to the local value.
11248 */
11249 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011250set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011251{
11252 p_iminsert = curbuf->b_p_iminsert;
11253}
11254
11255/*
11256 * Set the global value for 'imsearch' to the local value.
11257 */
11258 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011259set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011260{
11261 p_imsearch = curbuf->b_p_imsearch;
11262}
11263
11264#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11265static int expand_option_idx = -1;
11266static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11267static int expand_option_flags = 0;
11268
11269 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011270set_context_in_set_cmd(
11271 expand_T *xp,
11272 char_u *arg,
11273 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011274{
11275 int nextchar;
11276 long_u flags = 0; /* init for GCC */
11277 int opt_idx = 0; /* init for GCC */
11278 char_u *p;
11279 char_u *s;
11280 int is_term_option = FALSE;
11281 int key;
11282
11283 expand_option_flags = opt_flags;
11284
11285 xp->xp_context = EXPAND_SETTINGS;
11286 if (*arg == NUL)
11287 {
11288 xp->xp_pattern = arg;
11289 return;
11290 }
11291 p = arg + STRLEN(arg) - 1;
11292 if (*p == ' ' && *(p - 1) != '\\')
11293 {
11294 xp->xp_pattern = p + 1;
11295 return;
11296 }
11297 while (p > arg)
11298 {
11299 s = p;
11300 /* count number of backslashes before ' ' or ',' */
11301 if (*p == ' ' || *p == ',')
11302 {
11303 while (s > arg && *(s - 1) == '\\')
11304 --s;
11305 }
11306 /* break at a space with an even number of backslashes */
11307 if (*p == ' ' && ((p - s) & 1) == 0)
11308 {
11309 ++p;
11310 break;
11311 }
11312 --p;
11313 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011314 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315 {
11316 xp->xp_context = EXPAND_BOOL_SETTINGS;
11317 p += 2;
11318 }
11319 if (STRNCMP(p, "inv", 3) == 0)
11320 {
11321 xp->xp_context = EXPAND_BOOL_SETTINGS;
11322 p += 3;
11323 }
11324 xp->xp_pattern = arg = p;
11325 if (*arg == '<')
11326 {
11327 while (*p != '>')
11328 if (*p++ == NUL) /* expand terminal option name */
11329 return;
11330 key = get_special_key_code(arg + 1);
11331 if (key == 0) /* unknown name */
11332 {
11333 xp->xp_context = EXPAND_NOTHING;
11334 return;
11335 }
11336 nextchar = *++p;
11337 is_term_option = TRUE;
11338 expand_option_name[2] = KEY2TERMCAP0(key);
11339 expand_option_name[3] = KEY2TERMCAP1(key);
11340 }
11341 else
11342 {
11343 if (p[0] == 't' && p[1] == '_')
11344 {
11345 p += 2;
11346 if (*p != NUL)
11347 ++p;
11348 if (*p == NUL)
11349 return; /* expand option name */
11350 nextchar = *++p;
11351 is_term_option = TRUE;
11352 expand_option_name[2] = p[-2];
11353 expand_option_name[3] = p[-1];
11354 }
11355 else
11356 {
11357 /* Allow * wildcard */
11358 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11359 p++;
11360 if (*p == NUL)
11361 return;
11362 nextchar = *p;
11363 *p = NUL;
11364 opt_idx = findoption(arg);
11365 *p = nextchar;
11366 if (opt_idx == -1 || options[opt_idx].var == NULL)
11367 {
11368 xp->xp_context = EXPAND_NOTHING;
11369 return;
11370 }
11371 flags = options[opt_idx].flags;
11372 if (flags & P_BOOL)
11373 {
11374 xp->xp_context = EXPAND_NOTHING;
11375 return;
11376 }
11377 }
11378 }
11379 /* handle "-=" and "+=" */
11380 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11381 {
11382 ++p;
11383 nextchar = '=';
11384 }
11385 if ((nextchar != '=' && nextchar != ':')
11386 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11387 {
11388 xp->xp_context = EXPAND_UNSUCCESSFUL;
11389 return;
11390 }
11391 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11392 {
11393 xp->xp_context = EXPAND_OLD_SETTING;
11394 if (is_term_option)
11395 expand_option_idx = -1;
11396 else
11397 expand_option_idx = opt_idx;
11398 xp->xp_pattern = p + 1;
11399 return;
11400 }
11401 xp->xp_context = EXPAND_NOTHING;
11402 if (is_term_option || (flags & P_NUM))
11403 return;
11404
11405 xp->xp_pattern = p + 1;
11406
11407 if (flags & P_EXPAND)
11408 {
11409 p = options[opt_idx].var;
11410 if (p == (char_u *)&p_bdir
11411 || p == (char_u *)&p_dir
11412 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011413 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414 || p == (char_u *)&p_rtp
11415#ifdef FEAT_SEARCHPATH
11416 || p == (char_u *)&p_cdpath
11417#endif
11418#ifdef FEAT_SESSION
11419 || p == (char_u *)&p_vdir
11420#endif
11421 )
11422 {
11423 xp->xp_context = EXPAND_DIRECTORIES;
11424 if (p == (char_u *)&p_path
11425#ifdef FEAT_SEARCHPATH
11426 || p == (char_u *)&p_cdpath
11427#endif
11428 )
11429 xp->xp_backslash = XP_BS_THREE;
11430 else
11431 xp->xp_backslash = XP_BS_ONE;
11432 }
11433 else
11434 {
11435 xp->xp_context = EXPAND_FILES;
11436 /* for 'tags' need three backslashes for a space */
11437 if (p == (char_u *)&p_tags)
11438 xp->xp_backslash = XP_BS_THREE;
11439 else
11440 xp->xp_backslash = XP_BS_ONE;
11441 }
11442 }
11443
11444 /* For an option that is a list of file names, find the start of the
11445 * last file name. */
11446 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11447 {
11448 /* count number of backslashes before ' ' or ',' */
11449 if (*p == ' ' || *p == ',')
11450 {
11451 s = p;
11452 while (s > xp->xp_pattern && *(s - 1) == '\\')
11453 --s;
11454 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11455 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11456 {
11457 xp->xp_pattern = p + 1;
11458 break;
11459 }
11460 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011461
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011462#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011463 /* for 'spellsuggest' start at "file:" */
11464 if (options[opt_idx].var == (char_u *)&p_sps
11465 && STRNCMP(p, "file:", 5) == 0)
11466 {
11467 xp->xp_pattern = p + 5;
11468 break;
11469 }
11470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011471 }
11472
11473 return;
11474}
11475
11476 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011477ExpandSettings(
11478 expand_T *xp,
11479 regmatch_T *regmatch,
11480 int *num_file,
11481 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011482{
11483 int num_normal = 0; /* Nr of matching non-term-code settings */
11484 int num_term = 0; /* Nr of matching terminal code settings */
11485 int opt_idx;
11486 int match;
11487 int count = 0;
11488 char_u *str;
11489 int loop;
11490 int is_term_opt;
11491 char_u name_buf[MAX_KEY_NAME_LEN];
11492 static char *(names[]) = {"all", "termcap"};
11493 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11494
11495 /* do this loop twice:
11496 * loop == 0: count the number of matching options
11497 * loop == 1: copy the matching options into allocated memory
11498 */
11499 for (loop = 0; loop <= 1; ++loop)
11500 {
11501 regmatch->rm_ic = ic;
11502 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11503 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011504 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11505 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011506 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11507 {
11508 if (loop == 0)
11509 num_normal++;
11510 else
11511 (*file)[count++] = vim_strsave((char_u *)names[match]);
11512 }
11513 }
11514 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11515 opt_idx++)
11516 {
11517 if (options[opt_idx].var == NULL)
11518 continue;
11519 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11520 && !(options[opt_idx].flags & P_BOOL))
11521 continue;
11522 is_term_opt = istermoption(&options[opt_idx]);
11523 if (is_term_opt && num_normal > 0)
11524 continue;
11525 match = FALSE;
11526 if (vim_regexec(regmatch, str, (colnr_T)0)
11527 || (options[opt_idx].shortname != NULL
11528 && vim_regexec(regmatch,
11529 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11530 match = TRUE;
11531 else if (is_term_opt)
11532 {
11533 name_buf[0] = '<';
11534 name_buf[1] = 't';
11535 name_buf[2] = '_';
11536 name_buf[3] = str[2];
11537 name_buf[4] = str[3];
11538 name_buf[5] = '>';
11539 name_buf[6] = NUL;
11540 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11541 {
11542 match = TRUE;
11543 str = name_buf;
11544 }
11545 }
11546 if (match)
11547 {
11548 if (loop == 0)
11549 {
11550 if (is_term_opt)
11551 num_term++;
11552 else
11553 num_normal++;
11554 }
11555 else
11556 (*file)[count++] = vim_strsave(str);
11557 }
11558 }
11559 /*
11560 * Check terminal key codes, these are not in the option table
11561 */
11562 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11563 {
11564 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11565 {
11566 if (!isprint(str[0]) || !isprint(str[1]))
11567 continue;
11568
11569 name_buf[0] = 't';
11570 name_buf[1] = '_';
11571 name_buf[2] = str[0];
11572 name_buf[3] = str[1];
11573 name_buf[4] = NUL;
11574
11575 match = FALSE;
11576 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11577 match = TRUE;
11578 else
11579 {
11580 name_buf[0] = '<';
11581 name_buf[1] = 't';
11582 name_buf[2] = '_';
11583 name_buf[3] = str[0];
11584 name_buf[4] = str[1];
11585 name_buf[5] = '>';
11586 name_buf[6] = NUL;
11587
11588 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11589 match = TRUE;
11590 }
11591 if (match)
11592 {
11593 if (loop == 0)
11594 num_term++;
11595 else
11596 (*file)[count++] = vim_strsave(name_buf);
11597 }
11598 }
11599
11600 /*
11601 * Check special key names.
11602 */
11603 regmatch->rm_ic = TRUE; /* ignore case here */
11604 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11605 {
11606 name_buf[0] = '<';
11607 STRCPY(name_buf + 1, str);
11608 STRCAT(name_buf, ">");
11609
11610 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11611 {
11612 if (loop == 0)
11613 num_term++;
11614 else
11615 (*file)[count++] = vim_strsave(name_buf);
11616 }
11617 }
11618 }
11619 if (loop == 0)
11620 {
11621 if (num_normal > 0)
11622 *num_file = num_normal;
11623 else if (num_term > 0)
11624 *num_file = num_term;
11625 else
11626 return OK;
11627 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11628 if (*file == NULL)
11629 {
11630 *file = (char_u **)"";
11631 return FAIL;
11632 }
11633 }
11634 }
11635 return OK;
11636}
11637
11638 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011639ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640{
11641 char_u *var = NULL; /* init for GCC */
11642 char_u *buf;
11643
11644 *num_file = 0;
11645 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11646 if (*file == NULL)
11647 return FAIL;
11648
11649 /*
11650 * For a terminal key code expand_option_idx is < 0.
11651 */
11652 if (expand_option_idx < 0)
11653 {
11654 var = find_termcode(expand_option_name + 2);
11655 if (var == NULL)
11656 expand_option_idx = findoption(expand_option_name);
11657 }
11658
11659 if (expand_option_idx >= 0)
11660 {
11661 /* put string of option value in NameBuff */
11662 option_value2string(&options[expand_option_idx], expand_option_flags);
11663 var = NameBuff;
11664 }
11665 else if (var == NULL)
11666 var = (char_u *)"";
11667
11668 /* A backslash is required before some characters. This is the reverse of
11669 * what happens in do_set(). */
11670 buf = vim_strsave_escaped(var, escape_chars);
11671
11672 if (buf == NULL)
11673 {
11674 vim_free(*file);
11675 *file = NULL;
11676 return FAIL;
11677 }
11678
11679#ifdef BACKSLASH_IN_FILENAME
11680 /* For MS-Windows et al. we don't double backslashes at the start and
11681 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011682 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011683 if (var[0] == '\\' && var[1] == '\\'
11684 && expand_option_idx >= 0
11685 && (options[expand_option_idx].flags & P_EXPAND)
11686 && vim_isfilec(var[2])
11687 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011688 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689#endif
11690
11691 *file[0] = buf;
11692 *num_file = 1;
11693 return OK;
11694}
11695#endif
11696
11697/*
11698 * Get the value for the numeric or string option *opp in a nice format into
11699 * NameBuff[]. Must not be called with a hidden option!
11700 */
11701 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011702option_value2string(
11703 struct vimoption *opp,
11704 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705{
11706 char_u *varp;
11707
11708 varp = get_varp_scope(opp, opt_flags);
11709
11710 if (opp->flags & P_NUM)
11711 {
11712 long wc = 0;
11713
11714 if (wc_use_keyname(varp, &wc))
11715 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11716 else if (wc != 0)
11717 STRCPY(NameBuff, transchar((int)wc));
11718 else
11719 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11720 }
11721 else /* P_STRING */
11722 {
11723 varp = *(char_u **)(varp);
11724 if (varp == NULL) /* just in case */
11725 NameBuff[0] = NUL;
11726#ifdef FEAT_CRYPT
11727 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011728 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011729 STRCPY(NameBuff, "*****");
11730#endif
11731 else if (opp->flags & P_EXPAND)
11732 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11733 /* Translate 'pastetoggle' into special key names */
11734 else if ((char_u **)opp->var == &p_pt)
11735 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11736 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011737 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011738 }
11739}
11740
11741/*
11742 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11743 * printed as a keyname.
11744 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11745 */
11746 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011747wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011748{
11749 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11750 {
11751 *wcp = *(long *)varp;
11752 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11753 return TRUE;
11754 }
11755 return FALSE;
11756}
11757
Bram Moolenaar01615492015-02-03 13:00:38 +010011758#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011760 * Any character has an equivalent 'langmap' character. This is used for
11761 * keyboards that have a special language mode that sends characters above
11762 * 128 (although other characters can be translated too). The "to" field is a
11763 * Vim command character. This avoids having to switch the keyboard back to
11764 * ASCII mode when leaving Insert mode.
11765 *
11766 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11767 * commands.
11768 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11769 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11770 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011772# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011773/*
11774 * With multi-byte support use growarray for 'langmap' chars >= 256
11775 */
11776typedef struct
11777{
11778 int from;
11779 int to;
11780} langmap_entry_T;
11781
11782static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011783static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784
11785/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011786 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11787 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011789 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011790langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011791{
11792 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011793 int a = 0;
11794 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011795
11796 /* Do a binary search for an existing entry. */
11797 while (a != b)
11798 {
11799 int i = (a + b) / 2;
11800 int d = entries[i].from - from;
11801
11802 if (d == 0)
11803 {
11804 entries[i].to = to;
11805 return;
11806 }
11807 if (d < 0)
11808 a = i + 1;
11809 else
11810 b = i;
11811 }
11812
11813 if (ga_grow(&langmap_mapga, 1) != OK)
11814 return; /* out of memory */
11815
11816 /* insert new entry at position "a" */
11817 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11818 mch_memmove(entries + 1, entries,
11819 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11820 ++langmap_mapga.ga_len;
11821 entries[0].from = from;
11822 entries[0].to = to;
11823}
11824
11825/*
11826 * Apply 'langmap' to multi-byte character "c" and return the result.
11827 */
11828 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011829langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011830{
11831 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11832 int a = 0;
11833 int b = langmap_mapga.ga_len;
11834
11835 while (a != b)
11836 {
11837 int i = (a + b) / 2;
11838 int d = entries[i].from - c;
11839
11840 if (d == 0)
11841 return entries[i].to; /* found matching entry */
11842 if (d < 0)
11843 a = i + 1;
11844 else
11845 b = i;
11846 }
11847 return c; /* no entry found, return "c" unmodified */
11848}
11849# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011850
11851 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011852langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011853{
11854 int i;
11855
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011856 for (i = 0; i < 256; i++)
11857 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11858# ifdef FEAT_MBYTE
11859 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11860# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011861}
11862
11863/*
11864 * Called when langmap option is set; the language map can be
11865 * changed at any time!
11866 */
11867 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011868langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869{
11870 char_u *p;
11871 char_u *p2;
11872 int from, to;
11873
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011874#ifdef FEAT_MBYTE
11875 ga_clear(&langmap_mapga); /* clear the previous map first */
11876#endif
11877 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011878
11879 for (p = p_langmap; p[0] != NUL; )
11880 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011881 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011882 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883 {
11884 if (p2[0] == '\\' && p2[1] != NUL)
11885 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011886 }
11887 if (p2[0] == ';')
11888 ++p2; /* abcd;ABCD form, p2 points to A */
11889 else
11890 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11891 while (p[0])
11892 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011893 if (p[0] == ',')
11894 {
11895 ++p;
11896 break;
11897 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011898 if (p[0] == '\\' && p[1] != NUL)
11899 ++p;
11900#ifdef FEAT_MBYTE
11901 from = (*mb_ptr2char)(p);
11902#else
11903 from = p[0];
11904#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011905 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906 if (p2 == NULL)
11907 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011908 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011909 if (p[0] != ',')
11910 {
11911 if (p[0] == '\\')
11912 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011913#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011914 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011916 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011917#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919 }
11920 else
11921 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011922 if (p2[0] != ',')
11923 {
11924 if (p2[0] == '\\')
11925 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011927 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011928#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011929 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011930#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011931 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011932 }
11933 if (to == NUL)
11934 {
11935 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11936 transchar(from));
11937 return;
11938 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011939
11940#ifdef FEAT_MBYTE
11941 if (from >= 256)
11942 langmap_set_entry(from, to);
11943 else
11944#endif
11945 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011946
11947 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011948 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011949 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011950 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011951 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011952 if (*p == ';')
11953 {
11954 p = p2;
11955 if (p[0] != NUL)
11956 {
11957 if (p[0] != ',')
11958 {
11959 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11960 return;
11961 }
11962 ++p;
11963 }
11964 break;
11965 }
11966 }
11967 }
11968 }
11969}
11970#endif
11971
11972/*
11973 * Return TRUE if format option 'x' is in effect.
11974 * Take care of no formatting when 'paste' is set.
11975 */
11976 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011977has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978{
11979 if (p_paste)
11980 return FALSE;
11981 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11982}
11983
11984/*
11985 * Return TRUE if "x" is present in 'shortmess' option, or
11986 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11987 */
11988 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011989shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011990{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011991 return p_shm != NULL &&
11992 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993 || (vim_strchr(p_shm, 'a') != NULL
11994 && vim_strchr((char_u *)SHM_A, x) != NULL));
11995}
11996
11997/*
11998 * paste_option_changed() - Called after p_paste was set or reset.
11999 */
12000 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012001paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002{
12003 static int old_p_paste = FALSE;
12004 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012005 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012006#ifdef FEAT_CMDL_INFO
12007 static int save_ru = 0;
12008#endif
12009#ifdef FEAT_RIGHTLEFT
12010 static int save_ri = 0;
12011 static int save_hkmap = 0;
12012#endif
12013 buf_T *buf;
12014
12015 if (p_paste)
12016 {
12017 /*
12018 * Paste switched from off to on.
12019 * Save the current values, so they can be restored later.
12020 */
12021 if (!old_p_paste)
12022 {
12023 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012024 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025 {
12026 buf->b_p_tw_nopaste = buf->b_p_tw;
12027 buf->b_p_wm_nopaste = buf->b_p_wm;
12028 buf->b_p_sts_nopaste = buf->b_p_sts;
12029 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012030 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031 }
12032
12033 /* save global options */
12034 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012035 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036#ifdef FEAT_CMDL_INFO
12037 save_ru = p_ru;
12038#endif
12039#ifdef FEAT_RIGHTLEFT
12040 save_ri = p_ri;
12041 save_hkmap = p_hkmap;
12042#endif
12043 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012044 p_ai_nopaste = p_ai;
12045 p_et_nopaste = p_et;
12046 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012047 p_tw_nopaste = p_tw;
12048 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012049 }
12050
12051 /*
12052 * Always set the option values, also when 'paste' is set when it is
12053 * already on.
12054 */
12055 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012056 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012057 {
12058 buf->b_p_tw = 0; /* textwidth is 0 */
12059 buf->b_p_wm = 0; /* wrapmargin is 0 */
12060 buf->b_p_sts = 0; /* softtabstop is 0 */
12061 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012062 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063 }
12064
12065 /* set global options */
12066 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012067 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068#ifdef FEAT_CMDL_INFO
12069# ifdef FEAT_WINDOWS
12070 if (p_ru)
12071 status_redraw_all(); /* redraw to remove the ruler */
12072# endif
12073 p_ru = 0; /* no ruler */
12074#endif
12075#ifdef FEAT_RIGHTLEFT
12076 p_ri = 0; /* no reverse insert */
12077 p_hkmap = 0; /* no Hebrew keyboard */
12078#endif
12079 /* set global values for local buffer options */
12080 p_tw = 0;
12081 p_wm = 0;
12082 p_sts = 0;
12083 p_ai = 0;
12084 }
12085
12086 /*
12087 * Paste switched from on to off: Restore saved values.
12088 */
12089 else if (old_p_paste)
12090 {
12091 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012092 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012093 {
12094 buf->b_p_tw = buf->b_p_tw_nopaste;
12095 buf->b_p_wm = buf->b_p_wm_nopaste;
12096 buf->b_p_sts = buf->b_p_sts_nopaste;
12097 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012098 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012099 }
12100
12101 /* restore global options */
12102 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012103 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012104#ifdef FEAT_CMDL_INFO
12105# ifdef FEAT_WINDOWS
12106 if (p_ru != save_ru)
12107 status_redraw_all(); /* redraw to draw the ruler */
12108# endif
12109 p_ru = save_ru;
12110#endif
12111#ifdef FEAT_RIGHTLEFT
12112 p_ri = save_ri;
12113 p_hkmap = save_hkmap;
12114#endif
12115 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012116 p_ai = p_ai_nopaste;
12117 p_et = p_et_nopaste;
12118 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012119 p_tw = p_tw_nopaste;
12120 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 }
12122
12123 old_p_paste = p_paste;
12124}
12125
12126/*
12127 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12128 *
12129 * Reset 'compatible' and set the values for options that didn't get set yet
12130 * to the Vim defaults.
12131 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012132 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012133 */
12134 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012135vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012137 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012138 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012139 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140
12141 if (!option_was_set((char_u *)"cp"))
12142 {
12143 p_cp = FALSE;
12144 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12145 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12146 set_option_default(opt_idx, OPT_FREE, FALSE);
12147 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012148 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012150
12151 if (fname != NULL)
12152 {
12153 p = vim_getenv(envname, &dofree);
12154 if (p == NULL)
12155 {
12156 /* Set $MYVIMRC to the first vimrc file found. */
12157 p = FullName_save(fname, FALSE);
12158 if (p != NULL)
12159 {
12160 vim_setenv(envname, p);
12161 vim_free(p);
12162 }
12163 }
12164 else if (dofree)
12165 vim_free(p);
12166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167}
12168
12169/*
12170 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12171 */
12172 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012173change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012174{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012175 int opt_idx;
12176
Bram Moolenaar071d4272004-06-13 20:20:40 +000012177 if (p_cp != on)
12178 {
12179 p_cp = on;
12180 compatible_set();
12181 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012182 opt_idx = findoption((char_u *)"cp");
12183 if (opt_idx >= 0)
12184 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012185}
12186
12187/*
12188 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012189 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012190 */
12191 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012192option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193{
12194 int idx;
12195
12196 idx = findoption(name);
12197 if (idx < 0) /* unknown option */
12198 return FALSE;
12199 if (options[idx].flags & P_WAS_SET)
12200 return TRUE;
12201 return FALSE;
12202}
12203
12204/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012205 * Reset the flag indicating option "name" was set.
12206 */
12207 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012208reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012209{
12210 int idx = findoption(name);
12211
12212 if (idx >= 0)
12213 options[idx].flags &= ~P_WAS_SET;
12214}
12215
12216/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217 * compatible_set() - Called when 'compatible' has been set or unset.
12218 *
12219 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12220 * flag) to a Vi compatible value.
12221 * When 'compatible' is unset: Set all options that have a different default
12222 * for Vim (without the P_VI_DEF flag) to that default.
12223 */
12224 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012225compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012226{
12227 int opt_idx;
12228
12229 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12230 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12231 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12232 set_option_default(opt_idx, OPT_FREE, p_cp);
12233 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012234 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012235}
12236
12237#ifdef FEAT_LINEBREAK
12238
12239# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12240 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012241 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242# endif
12243
12244/*
12245 * fill_breakat_flags() -- called when 'breakat' changes value.
12246 */
12247 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012248fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012250 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251 int i;
12252
12253 for (i = 0; i < 256; i++)
12254 breakat_flags[i] = FALSE;
12255
12256 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012257 for (p = p_breakat; *p; p++)
12258 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259}
12260
12261# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012262 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012263# endif
12264
12265#endif
12266
12267/*
12268 * Check an option that can be a range of string values.
12269 *
12270 * Return OK for correct value, FAIL otherwise.
12271 * Empty is always OK.
12272 */
12273 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012274check_opt_strings(
12275 char_u *val,
12276 char **values,
12277 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012278{
12279 return opt_strings_flags(val, values, NULL, list);
12280}
12281
12282/*
12283 * Handle an option that can be a range of string values.
12284 * Set a flag in "*flagp" for each string present.
12285 *
12286 * Return OK for correct value, FAIL otherwise.
12287 * Empty is always OK.
12288 */
12289 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012290opt_strings_flags(
12291 char_u *val, /* new value */
12292 char **values, /* array of valid string values */
12293 unsigned *flagp,
12294 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295{
12296 int i;
12297 int len;
12298 unsigned new_flags = 0;
12299
12300 while (*val)
12301 {
12302 for (i = 0; ; ++i)
12303 {
12304 if (values[i] == NULL) /* val not found in values[] */
12305 return FAIL;
12306
12307 len = (int)STRLEN(values[i]);
12308 if (STRNCMP(values[i], val, len) == 0
12309 && ((list && val[len] == ',') || val[len] == NUL))
12310 {
12311 val += len + (val[len] == ',');
12312 new_flags |= (1 << i);
12313 break; /* check next item in val list */
12314 }
12315 }
12316 }
12317 if (flagp != NULL)
12318 *flagp = new_flags;
12319
12320 return OK;
12321}
12322
12323/*
12324 * Read the 'wildmode' option, fill wim_flags[].
12325 */
12326 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012327check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012328{
12329 char_u new_wim_flags[4];
12330 char_u *p;
12331 int i;
12332 int idx = 0;
12333
12334 for (i = 0; i < 4; ++i)
12335 new_wim_flags[i] = 0;
12336
12337 for (p = p_wim; *p; ++p)
12338 {
12339 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12340 ;
12341 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12342 return FAIL;
12343 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12344 new_wim_flags[idx] |= WIM_LONGEST;
12345 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12346 new_wim_flags[idx] |= WIM_FULL;
12347 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12348 new_wim_flags[idx] |= WIM_LIST;
12349 else
12350 return FAIL;
12351 p += i;
12352 if (*p == NUL)
12353 break;
12354 if (*p == ',')
12355 {
12356 if (idx == 3)
12357 return FAIL;
12358 ++idx;
12359 }
12360 }
12361
12362 /* fill remaining entries with last flag */
12363 while (idx < 3)
12364 {
12365 new_wim_flags[idx + 1] = new_wim_flags[idx];
12366 ++idx;
12367 }
12368
12369 /* only when there are no errors, wim_flags[] is changed */
12370 for (i = 0; i < 4; ++i)
12371 wim_flags[i] = new_wim_flags[i];
12372 return OK;
12373}
12374
12375/*
12376 * Check if backspacing over something is allowed.
12377 */
12378 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012379can_bs(
12380 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381{
12382 switch (*p_bs)
12383 {
12384 case '2': return TRUE;
12385 case '1': return (what != BS_START);
12386 case '0': return FALSE;
12387 }
12388 return vim_strchr(p_bs, what) != NULL;
12389}
12390
12391/*
12392 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12393 * the file must be considered changed when the value is different.
12394 */
12395 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012396save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012397{
12398 buf->b_start_ffc = *buf->b_p_ff;
12399 buf->b_start_eol = buf->b_p_eol;
12400#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012401 buf->b_start_bomb = buf->b_p_bomb;
12402
Bram Moolenaar071d4272004-06-13 20:20:40 +000012403 /* Only use free/alloc when necessary, they take time. */
12404 if (buf->b_start_fenc == NULL
12405 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12406 {
12407 vim_free(buf->b_start_fenc);
12408 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12409 }
12410#endif
12411}
12412
12413/*
12414 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12415 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012416 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12417 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012418 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012419 * When "ignore_empty" is true don't consider a new, empty buffer to be
12420 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421 */
12422 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012423file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012424{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012425 /* In a buffer that was never loaded the options are not valid. */
12426 if (buf->b_flags & BF_NEVERLOADED)
12427 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012428 if (ignore_empty
12429 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012430 && buf->b_ml.ml_line_count == 1
12431 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12432 return FALSE;
12433 if (buf->b_start_ffc != *buf->b_p_ff)
12434 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012435 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012436 return TRUE;
12437#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012438 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12439 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440 if (buf->b_start_fenc == NULL)
12441 return (*buf->b_p_fenc != NUL);
12442 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12443#else
12444 return FALSE;
12445#endif
12446}
12447
12448/*
12449 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12450 */
12451 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012452check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012453{
12454 return check_opt_strings(p, p_ff_values, FALSE);
12455}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012456
12457/*
12458 * Return the effective shiftwidth value for current buffer, using the
12459 * 'tabstop' value when 'shiftwidth' is zero.
12460 */
12461 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012462get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012463{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012464 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012465}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012466
12467/*
12468 * Return the effective softtabstop value for the current buffer, using the
12469 * 'tabstop' value when 'softtabstop' is negative.
12470 */
12471 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012472get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012473{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012474 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012475}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012476
12477/*
12478 * Check matchpairs option for "*initc".
12479 * If there is a match set "*initc" to the matching character and "*findc" to
12480 * the opposite character. Set "*backwards" to the direction.
12481 * When "switchit" is TRUE swap the direction.
12482 */
12483 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012484find_mps_values(
12485 int *initc,
12486 int *findc,
12487 int *backwards,
12488 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012489{
12490 char_u *ptr;
12491
12492 ptr = curbuf->b_p_mps;
12493 while (*ptr != NUL)
12494 {
12495#ifdef FEAT_MBYTE
12496 if (has_mbyte)
12497 {
12498 char_u *prev;
12499
12500 if (mb_ptr2char(ptr) == *initc)
12501 {
12502 if (switchit)
12503 {
12504 *findc = *initc;
12505 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12506 *backwards = TRUE;
12507 }
12508 else
12509 {
12510 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12511 *backwards = FALSE;
12512 }
12513 return;
12514 }
12515 prev = ptr;
12516 ptr += mb_ptr2len(ptr) + 1;
12517 if (mb_ptr2char(ptr) == *initc)
12518 {
12519 if (switchit)
12520 {
12521 *findc = *initc;
12522 *initc = mb_ptr2char(prev);
12523 *backwards = FALSE;
12524 }
12525 else
12526 {
12527 *findc = mb_ptr2char(prev);
12528 *backwards = TRUE;
12529 }
12530 return;
12531 }
12532 ptr += mb_ptr2len(ptr);
12533 }
12534 else
12535#endif
12536 {
12537 if (*ptr == *initc)
12538 {
12539 if (switchit)
12540 {
12541 *backwards = TRUE;
12542 *findc = *initc;
12543 *initc = ptr[2];
12544 }
12545 else
12546 {
12547 *backwards = FALSE;
12548 *findc = ptr[2];
12549 }
12550 return;
12551 }
12552 ptr += 2;
12553 if (*ptr == *initc)
12554 {
12555 if (switchit)
12556 {
12557 *backwards = FALSE;
12558 *findc = *initc;
12559 *initc = ptr[-2];
12560 }
12561 else
12562 {
12563 *backwards = TRUE;
12564 *findc = ptr[-2];
12565 }
12566 return;
12567 }
12568 ++ptr;
12569 }
12570 if (*ptr == ',')
12571 ++ptr;
12572 }
12573}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012574
12575#if defined(FEAT_LINEBREAK) || defined(PROTO)
12576/*
12577 * This is called when 'breakindentopt' is changed and when a window is
12578 * initialized.
12579 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012580 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012581briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012582{
12583 char_u *p;
12584 int bri_shift = 0;
12585 long bri_min = 20;
12586 int bri_sbr = FALSE;
12587
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012588 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012589 while (*p != NUL)
12590 {
12591 if (STRNCMP(p, "shift:", 6) == 0
12592 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12593 {
12594 p += 6;
12595 bri_shift = getdigits(&p);
12596 }
12597 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12598 {
12599 p += 4;
12600 bri_min = getdigits(&p);
12601 }
12602 else if (STRNCMP(p, "sbr", 3) == 0)
12603 {
12604 p += 3;
12605 bri_sbr = TRUE;
12606 }
12607 if (*p != ',' && *p != NUL)
12608 return FAIL;
12609 if (*p == ',')
12610 ++p;
12611 }
12612
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012613 wp->w_p_brishift = bri_shift;
12614 wp->w_p_brimin = bri_min;
12615 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012616
12617 return OK;
12618}
12619#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012620
12621/*
12622 * Get the local or global value of 'backupcopy'.
12623 */
12624 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012625get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012626{
12627 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12628}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012629
12630#if defined(FEAT_SIGNS) || defined(PROTO)
12631/*
12632 * Return TRUE when window "wp" has a column to draw signs in.
12633 */
12634 int
12635signcolumn_on(win_T *wp)
12636{
12637 if (*wp->w_p_scl == 'n')
12638 return FALSE;
12639 if (*wp->w_p_scl == 'y')
12640 return TRUE;
12641 return (wp->w_buffer->b_signlist != NULL
12642# ifdef FEAT_NETBEANS_INTG
12643 || wp->w_buffer->b_has_sign_column
12644# endif
12645 );
12646}
12647#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012648
12649#if defined(FEAT_EVAL) || defined(PROTO)
12650/*
12651 * Get window or buffer local options.
12652 */
12653 dict_T *
12654get_winbuf_options(int bufopt)
12655{
12656 dict_T *d;
12657 int opt_idx;
12658
12659 d = dict_alloc();
12660 if (d == NULL)
12661 return NULL;
12662
12663 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12664 {
12665 struct vimoption *opt = &options[opt_idx];
12666
12667 if ((bufopt && (opt->indir & PV_BUF))
12668 || (!bufopt && (opt->indir & PV_WIN)))
12669 {
12670 char_u *varp = get_varp(opt);
12671
12672 if (varp != NULL)
12673 {
12674 if (opt->flags & P_STRING)
12675 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012676 else if (opt->flags & P_NUM)
12677 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012678 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012679 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012680 }
12681 }
12682 }
12683
12684 return d;
12685}
12686#endif