blob: 2a92bc5ae89f92e14feb4a2f4374175ff5fe86be [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 Moolenaar071d4272004-06-13 20:20:40 +00006012
6013 /* Get the global option to compare with, otherwise we would have to check
6014 * two values for all local options. */
6015 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6016
6017 /* Disallow changing some options from secure mode */
6018 if ((secure
6019#ifdef HAVE_SANDBOX
6020 || sandbox != 0
6021#endif
6022 ) && (options[opt_idx].flags & P_SECURE))
6023 {
6024 errmsg = e_secure;
6025 }
6026
Bram Moolenaar7554da42016-11-25 22:04:13 +01006027 /* Check for a "normal" directory or file name in some options. Disallow a
6028 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006029 * are often illegal in a file name. Be more permissive if "secure" is off.
6030 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006031 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006032 && vim_strpbrk(*varp, (char_u *)(secure
6033 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006034 || ((options[opt_idx].flags & P_NDNAME)
6035 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006036 {
6037 errmsg = e_invarg;
6038 }
6039
Bram Moolenaar071d4272004-06-13 20:20:40 +00006040 /* 'term' */
6041 else if (varp == &T_NAME)
6042 {
6043 if (T_NAME[0] == NUL)
6044 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6045#ifdef FEAT_GUI
6046 if (gui.in_use)
6047 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6048 else if (term_is_gui(T_NAME))
6049 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6050#endif
6051 else if (set_termname(T_NAME) == FAIL)
6052 errmsg = (char_u *)N_("E522: Not found in termcap");
6053 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006054 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006055 /* Screen colors may have changed. */
6056 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006057
6058 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6059 * P_ALLOCED flag on 'term'. */
6060 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006061 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006062 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006063 }
6064
6065 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006066 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006067 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006068 char_u *bkc = p_bkc;
6069 unsigned int *flags = &bkc_flags;
6070
6071 if (opt_flags & OPT_LOCAL)
6072 {
6073 bkc = curbuf->b_p_bkc;
6074 flags = &curbuf->b_bkc_flags;
6075 }
6076
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006077 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6078 /* make the local value empty: use the global value */
6079 *flags = 0;
6080 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006081 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006082 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6083 errmsg = e_invarg;
6084 if ((((int)*flags & BKC_AUTO) != 0)
6085 + (((int)*flags & BKC_YES) != 0)
6086 + (((int)*flags & BKC_NO) != 0) != 1)
6087 {
6088 /* Must have exactly one of "auto", "yes" and "no". */
6089 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6090 errmsg = e_invarg;
6091 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006092 }
6093 }
6094
6095 /* 'backupext' and 'patchmode' */
6096 else if (varp == &p_bex || varp == &p_pm)
6097 {
6098 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6099 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6100 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6101 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006102#ifdef FEAT_LINEBREAK
6103 /* 'breakindentopt' */
6104 else if (varp == &curwin->w_p_briopt)
6105 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006106 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006107 errmsg = e_invarg;
6108 }
6109#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110
6111 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006112 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006114 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115 */
6116 else if ( varp == &p_isi
6117 || varp == &(curbuf->b_p_isk)
6118 || varp == &p_isp
6119 || varp == &p_isf)
6120 {
6121 if (init_chartab() == FAIL)
6122 {
6123 did_chartab = TRUE; /* need to restore it below */
6124 errmsg = e_invarg; /* error in value */
6125 }
6126 }
6127
6128 /* 'helpfile' */
6129 else if (varp == &p_hf)
6130 {
6131 /* May compute new values for $VIM and $VIMRUNTIME */
6132 if (didset_vim)
6133 {
6134 vim_setenv((char_u *)"VIM", (char_u *)"");
6135 didset_vim = FALSE;
6136 }
6137 if (didset_vimruntime)
6138 {
6139 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6140 didset_vimruntime = FALSE;
6141 }
6142 }
6143
Bram Moolenaar1a384422010-07-14 19:53:30 +02006144#ifdef FEAT_SYN_HL
6145 /* 'colorcolumn' */
6146 else if (varp == &curwin->w_p_cc)
6147 errmsg = check_colorcolumn(curwin);
6148#endif
6149
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150#ifdef FEAT_MULTI_LANG
6151 /* 'helplang' */
6152 else if (varp == &p_hlg)
6153 {
6154 /* Check for "", "ab", "ab,cd", etc. */
6155 for (s = p_hlg; *s != NUL; s += 3)
6156 {
6157 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6158 {
6159 errmsg = e_invarg;
6160 break;
6161 }
6162 if (s[2] == NUL)
6163 break;
6164 }
6165 }
6166#endif
6167
6168 /* 'highlight' */
6169 else if (varp == &p_hl)
6170 {
6171 if (highlight_changed() == FAIL)
6172 errmsg = e_invarg; /* invalid flags */
6173 }
6174
6175 /* 'nrformats' */
6176 else if (gvarp == &p_nf)
6177 {
6178 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6179 errmsg = e_invarg;
6180 }
6181
6182#ifdef FEAT_SESSION
6183 /* 'sessionoptions' */
6184 else if (varp == &p_ssop)
6185 {
6186 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6187 errmsg = e_invarg;
6188 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6189 {
6190 /* Don't allow both "sesdir" and "curdir". */
6191 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6192 errmsg = e_invarg;
6193 }
6194 }
6195 /* 'viewoptions' */
6196 else if (varp == &p_vop)
6197 {
6198 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6199 errmsg = e_invarg;
6200 }
6201#endif
6202
6203 /* 'scrollopt' */
6204#ifdef FEAT_SCROLLBIND
6205 else if (varp == &p_sbo)
6206 {
6207 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6208 errmsg = e_invarg;
6209 }
6210#endif
6211
6212 /* 'ambiwidth' */
6213#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006214 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006215 {
6216 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6217 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006218 else if (set_chars_option(&p_lcs) != NULL)
6219 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6220# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6221 else if (set_chars_option(&p_fcs) != NULL)
6222 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6223# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224 }
6225#endif
6226
6227 /* 'background' */
6228 else if (varp == &p_bg)
6229 {
6230 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6231 {
6232#ifdef FEAT_EVAL
6233 int dark = (*p_bg == 'd');
6234#endif
6235
6236 init_highlight(FALSE, FALSE);
6237
6238#ifdef FEAT_EVAL
6239 if (dark != (*p_bg == 'd')
6240 && get_var_value((char_u *)"g:colors_name") != NULL)
6241 {
6242 /* The color scheme must have set 'background' back to another
6243 * value, that's not what we want here. Disable the color
6244 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006245 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006246 free_string_option(p_bg);
6247 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6248 check_string_option(&p_bg);
6249 init_highlight(FALSE, FALSE);
6250 }
6251#endif
6252 }
6253 else
6254 errmsg = e_invarg;
6255 }
6256
6257 /* 'wildmode' */
6258 else if (varp == &p_wim)
6259 {
6260 if (check_opt_wim() == FAIL)
6261 errmsg = e_invarg;
6262 }
6263
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006264#ifdef FEAT_CMDL_COMPL
6265 /* 'wildoptions' */
6266 else if (varp == &p_wop)
6267 {
6268 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6269 errmsg = e_invarg;
6270 }
6271#endif
6272
Bram Moolenaar071d4272004-06-13 20:20:40 +00006273#ifdef FEAT_WAK
6274 /* 'winaltkeys' */
6275 else if (varp == &p_wak)
6276 {
6277 if (*p_wak == NUL
6278 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6279 errmsg = e_invarg;
6280# ifdef FEAT_MENU
6281# ifdef FEAT_GUI_MOTIF
6282 else if (gui.in_use)
6283 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6284# else
6285# ifdef FEAT_GUI_GTK
6286 else if (gui.in_use)
6287 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6288# endif
6289# endif
6290# endif
6291 }
6292#endif
6293
6294#ifdef FEAT_AUTOCMD
6295 /* 'eventignore' */
6296 else if (varp == &p_ei)
6297 {
6298 if (check_ei() == FAIL)
6299 errmsg = e_invarg;
6300 }
6301#endif
6302
6303#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006304 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6305 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6306 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307 {
6308 if (gvarp == &p_fenc)
6309 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006310 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006311 errmsg = e_modifiable;
6312 else if (vim_strchr(*varp, ',') != NULL)
6313 /* No comma allowed in 'fileencoding'; catches confusing it
6314 * with 'fileencodings'. */
6315 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006317 {
6318# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006320 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006322 /* Add 'fileencoding' to the swap file. */
6323 ml_setflags(curbuf);
6324 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 }
6326 if (errmsg == NULL)
6327 {
6328 /* canonize the value, so that STRCMP() can be used on it */
6329 p = enc_canonize(*varp);
6330 if (p != NULL)
6331 {
6332 vim_free(*varp);
6333 *varp = p;
6334 }
6335 if (varp == &p_enc)
6336 {
6337 errmsg = mb_init();
6338# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006339 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006340# endif
6341 }
6342 }
6343
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006344# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6346 {
6347 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6348 if (STRCMP(p_tenc, "utf-8") != 0)
6349 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6350 }
6351# endif
6352
6353 if (errmsg == NULL)
6354 {
6355# ifdef FEAT_KEYMAP
6356 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6357 * (with another encoding). */
6358 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6359 (void)keymap_init();
6360# endif
6361
6362 /* When 'termencoding' is not empty and 'encoding' changes or when
6363 * 'termencoding' changes, need to setup for keyboard input and
6364 * display output conversion. */
6365 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6366 {
6367 convert_setup(&input_conv, p_tenc, p_enc);
6368 convert_setup(&output_conv, p_enc, p_tenc);
6369 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006370
6371# if defined(WIN3264) && defined(FEAT_MBYTE)
6372 /* $HOME may have characters in active code page. */
6373 if (varp == &p_enc)
6374 init_homedir();
6375# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006376 }
6377 }
6378#endif
6379
6380#if defined(FEAT_POSTSCRIPT)
6381 else if (varp == &p_penc)
6382 {
6383 /* Canonize printencoding if VIM standard one */
6384 p = enc_canonize(p_penc);
6385 if (p != NULL)
6386 {
6387 vim_free(p_penc);
6388 p_penc = p;
6389 }
6390 else
6391 {
6392 /* Ensure lower case and '-' for '_' */
6393 for (s = p_penc; *s != NUL; s++)
6394 {
6395 if (*s == '_')
6396 *s = '-';
6397 else
6398 *s = TOLOWER_ASC(*s);
6399 }
6400 }
6401 }
6402#endif
6403
Bram Moolenaar9372a112005-12-06 19:59:18 +00006404#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006405 else if (varp == &p_imak)
6406 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006407 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 errmsg = e_invarg;
6409 }
6410#endif
6411
6412#ifdef FEAT_KEYMAP
6413 else if (varp == &curbuf->b_p_keymap)
6414 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006415 if (!valid_filetype(*varp))
6416 errmsg = e_invarg;
6417 else
6418 /* load or unload key mapping tables */
6419 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420
Bram Moolenaarfab06232009-03-04 03:13:35 +00006421 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006422 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006423 if (*curbuf->b_p_keymap != NUL)
6424 {
6425 /* Installed a new keymap, switch on using it. */
6426 curbuf->b_p_iminsert = B_IMODE_LMAP;
6427 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6428 curbuf->b_p_imsearch = B_IMODE_LMAP;
6429 }
6430 else
6431 {
6432 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6433 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6434 curbuf->b_p_iminsert = B_IMODE_NONE;
6435 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6436 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6437 }
6438 if ((opt_flags & OPT_LOCAL) == 0)
6439 {
6440 set_iminsert_global();
6441 set_imsearch_global();
6442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443# ifdef FEAT_WINDOWS
6444 status_redraw_curbuf();
6445# endif
6446 }
6447 }
6448#endif
6449
6450 /* 'fileformat' */
6451 else if (gvarp == &p_ff)
6452 {
6453 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6454 errmsg = e_modifiable;
6455 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6456 errmsg = e_invarg;
6457 else
6458 {
6459 /* may also change 'textmode' */
6460 if (get_fileformat(curbuf) == EOL_DOS)
6461 curbuf->b_p_tx = TRUE;
6462 else
6463 curbuf->b_p_tx = FALSE;
6464#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006465 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006467 /* update flag in swap file */
6468 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006469 /* Redraw needed when switching to/from "mac": a CR in the text
6470 * will be displayed differently. */
6471 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6472 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006473 }
6474 }
6475
6476 /* 'fileformats' */
6477 else if (varp == &p_ffs)
6478 {
6479 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6480 errmsg = e_invarg;
6481 else
6482 {
6483 /* also change 'textauto' */
6484 if (*p_ffs == NUL)
6485 p_ta = FALSE;
6486 else
6487 p_ta = TRUE;
6488 }
6489 }
6490
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006491#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492 /* 'cryptkey' */
6493 else if (gvarp == &p_key)
6494 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006495# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496 /* Make sure the ":set" command doesn't show the new value in the
6497 * history. */
6498 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006499# endif
6500 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6501 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006502 ml_set_crypt_key(curbuf, oldval,
6503 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006504 }
6505
6506 else if (gvarp == &p_cm)
6507 {
6508 if (opt_flags & OPT_LOCAL)
6509 p = curbuf->b_p_cm;
6510 else
6511 p = p_cm;
6512 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6513 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006514 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006515 errmsg = e_invarg;
6516 else
6517 {
6518 /* When setting the global value to empty, make it "zip". */
6519 if (*p_cm == NUL)
6520 {
6521 if (new_value_alloced)
6522 free_string_option(p_cm);
6523 p_cm = vim_strsave((char_u *)"zip");
6524 new_value_alloced = TRUE;
6525 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006526 /* When using ":set cm=name" the local value is going to be empty.
6527 * Do that here, otherwise the crypt functions will still use the
6528 * local value. */
6529 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6530 {
6531 free_string_option(curbuf->b_p_cm);
6532 curbuf->b_p_cm = empty_option;
6533 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006534
6535 /* Need to update the swapfile when the effective method changed.
6536 * Set "s" to the effective old value, "p" to the effective new
6537 * method and compare. */
6538 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6539 s = p_cm; /* was previously using the global value */
6540 else
6541 s = oldval;
6542 if (*curbuf->b_p_cm == NUL)
6543 p = p_cm; /* is now using the global value */
6544 else
6545 p = curbuf->b_p_cm;
6546 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006547 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006548
6549 /* If the global value changes need to update the swapfile for all
6550 * buffers using that value. */
6551 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6552 {
6553 buf_T *buf;
6554
Bram Moolenaar29323592016-07-24 22:04:11 +02006555 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006556 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006557 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006558 }
6559 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006560 }
6561#endif
6562
6563 /* 'matchpairs' */
6564 else if (gvarp == &p_mps)
6565 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006566#ifdef FEAT_MBYTE
6567 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006569 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006571 int x2 = -1;
6572 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006573
6574 if (*p != NUL)
6575 p += mb_ptr2len(p);
6576 if (*p != NUL)
6577 x2 = *p++;
6578 if (*p != NUL)
6579 {
6580 x3 = mb_ptr2char(p);
6581 p += mb_ptr2len(p);
6582 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006583 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006584 {
6585 errmsg = e_invarg;
6586 break;
6587 }
6588 if (*p == NUL)
6589 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006591 }
6592 else
6593#endif
6594 {
6595 /* Check for "x:y,x:y" */
6596 for (p = *varp; *p != NUL; p += 4)
6597 {
6598 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6599 {
6600 errmsg = e_invarg;
6601 break;
6602 }
6603 if (p[3] == NUL)
6604 break;
6605 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 }
6607 }
6608
6609#ifdef FEAT_COMMENTS
6610 /* 'comments' */
6611 else if (gvarp == &p_com)
6612 {
6613 for (s = *varp; *s; )
6614 {
6615 while (*s && *s != ':')
6616 {
6617 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6618 && !VIM_ISDIGIT(*s) && *s != '-')
6619 {
6620 errmsg = illegal_char(errbuf, *s);
6621 break;
6622 }
6623 ++s;
6624 }
6625 if (*s++ == NUL)
6626 errmsg = (char_u *)N_("E524: Missing colon");
6627 else if (*s == ',' || *s == NUL)
6628 errmsg = (char_u *)N_("E525: Zero length string");
6629 if (errmsg != NULL)
6630 break;
6631 while (*s && *s != ',')
6632 {
6633 if (*s == '\\' && s[1] != NUL)
6634 ++s;
6635 ++s;
6636 }
6637 s = skip_to_option_part(s);
6638 }
6639 }
6640#endif
6641
6642 /* 'listchars' */
6643 else if (varp == &p_lcs)
6644 {
6645 errmsg = set_chars_option(varp);
6646 }
6647
6648#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6649 /* 'fillchars' */
6650 else if (varp == &p_fcs)
6651 {
6652 errmsg = set_chars_option(varp);
6653 }
6654#endif
6655
6656#ifdef FEAT_CMDWIN
6657 /* 'cedit' */
6658 else if (varp == &p_cedit)
6659 {
6660 errmsg = check_cedit();
6661 }
6662#endif
6663
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006664 /* 'verbosefile' */
6665 else if (varp == &p_vfile)
6666 {
6667 verbose_stop();
6668 if (*p_vfile != NUL && verbose_open() == FAIL)
6669 errmsg = e_invarg;
6670 }
6671
Bram Moolenaar071d4272004-06-13 20:20:40 +00006672#ifdef FEAT_VIMINFO
6673 /* 'viminfo' */
6674 else if (varp == &p_viminfo)
6675 {
6676 for (s = p_viminfo; *s;)
6677 {
6678 /* Check it's a valid character */
6679 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6680 {
6681 errmsg = illegal_char(errbuf, *s);
6682 break;
6683 }
6684 if (*s == 'n') /* name is always last one */
6685 {
6686 break;
6687 }
6688 else if (*s == 'r') /* skip until next ',' */
6689 {
6690 while (*++s && *s != ',')
6691 ;
6692 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006693 else if (*s == '%')
6694 {
6695 /* optional number */
6696 while (vim_isdigit(*++s))
6697 ;
6698 }
6699 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006700 ++s; /* no extra chars */
6701 else /* must have a number */
6702 {
6703 while (vim_isdigit(*++s))
6704 ;
6705
6706 if (!VIM_ISDIGIT(*(s - 1)))
6707 {
6708 if (errbuf != NULL)
6709 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006710 sprintf((char *)errbuf,
6711 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006712 transchar_byte(*(s - 1)));
6713 errmsg = errbuf;
6714 }
6715 else
6716 errmsg = (char_u *)"";
6717 break;
6718 }
6719 }
6720 if (*s == ',')
6721 ++s;
6722 else if (*s)
6723 {
6724 if (errbuf != NULL)
6725 errmsg = (char_u *)N_("E527: Missing comma");
6726 else
6727 errmsg = (char_u *)"";
6728 break;
6729 }
6730 }
6731 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6732 errmsg = (char_u *)N_("E528: Must specify a ' value");
6733 }
6734#endif /* FEAT_VIMINFO */
6735
6736 /* terminal options */
6737 else if (istermoption(&options[opt_idx]) && full_screen)
6738 {
6739 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6740 if (varp == &T_CCO)
6741 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006742 int colors = atoi((char *)T_CCO);
6743
6744 /* Only reinitialize colors if t_Co value has really changed to
6745 * avoid expensive reload of colorscheme if t_Co is set to the
6746 * same value multiple times. */
6747 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006749 t_colors = colors;
6750 if (t_colors <= 1)
6751 {
6752 if (new_value_alloced)
6753 vim_free(T_CCO);
6754 T_CCO = empty_option;
6755 }
6756 /* We now have a different color setup, initialize it again. */
6757 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759 }
6760 ttest(FALSE);
6761 if (varp == &T_ME)
6762 {
6763 out_str(T_ME);
6764 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006765#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766 /* Since t_me has been set, this probably means that the user
6767 * wants to use this as default colors. Need to reset default
6768 * background/foreground colors. */
6769 mch_set_normal_colors();
6770#endif
6771 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006772 if (varp == &T_BE && termcap_active)
6773 {
6774 if (*T_BE == NUL)
6775 /* When clearing t_BE we assume the user no longer wants
6776 * bracketed paste, thus disable it by writing t_BD. */
6777 out_str(T_BD);
6778 else
6779 out_str(T_BE);
6780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 }
6782
6783#ifdef FEAT_LINEBREAK
6784 /* 'showbreak' */
6785 else if (varp == &p_sbr)
6786 {
6787 for (s = p_sbr; *s; )
6788 {
6789 if (ptr2cells(s) != 1)
6790 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006791 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 }
6793 }
6794#endif
6795
6796#ifdef FEAT_GUI
6797 /* 'guifont' */
6798 else if (varp == &p_guifont)
6799 {
6800 if (gui.in_use)
6801 {
6802 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006803# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006804 /*
6805 * Put up a font dialog and let the user select a new value.
6806 * If this is cancelled go back to the old value but don't
6807 * give an error message.
6808 */
6809 if (STRCMP(p, "*") == 0)
6810 {
6811 p = gui_mch_font_dialog(oldval);
6812
6813 if (new_value_alloced)
6814 free_string_option(p_guifont);
6815
6816 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6817 new_value_alloced = TRUE;
6818 }
6819# endif
6820 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6821 {
6822# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6823 if (STRCMP(p_guifont, "*") == 0)
6824 {
6825 /* Dialog was cancelled: Keep the old value without giving
6826 * an error message. */
6827 if (new_value_alloced)
6828 free_string_option(p_guifont);
6829 p_guifont = vim_strsave(oldval);
6830 new_value_alloced = TRUE;
6831 }
6832 else
6833# endif
6834 errmsg = (char_u *)N_("E596: Invalid font(s)");
6835 }
6836 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006837 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006838 }
6839# ifdef FEAT_XFONTSET
6840 else if (varp == &p_guifontset)
6841 {
6842 if (STRCMP(p_guifontset, "*") == 0)
6843 errmsg = (char_u *)N_("E597: can't select fontset");
6844 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6845 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006846 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847 }
6848# endif
6849# ifdef FEAT_MBYTE
6850 else if (varp == &p_guifontwide)
6851 {
6852 if (STRCMP(p_guifontwide, "*") == 0)
6853 errmsg = (char_u *)N_("E533: can't select wide font");
6854 else if (gui_get_wide_font() == FAIL)
6855 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006856 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857 }
6858# endif
6859#endif
6860
6861#ifdef CURSOR_SHAPE
6862 /* 'guicursor' */
6863 else if (varp == &p_guicursor)
6864 errmsg = parse_shape_opt(SHAPE_CURSOR);
6865#endif
6866
6867#ifdef FEAT_MOUSESHAPE
6868 /* 'mouseshape' */
6869 else if (varp == &p_mouseshape)
6870 {
6871 errmsg = parse_shape_opt(SHAPE_MOUSE);
6872 update_mouseshape(-1);
6873 }
6874#endif
6875
6876#ifdef FEAT_PRINTER
6877 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006878 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006879# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006880 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006881 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006882# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883#endif
6884
6885#ifdef FEAT_LANGMAP
6886 /* 'langmap' */
6887 else if (varp == &p_langmap)
6888 langmap_set();
6889#endif
6890
6891#ifdef FEAT_LINEBREAK
6892 /* 'breakat' */
6893 else if (varp == &p_breakat)
6894 fill_breakat_flags();
6895#endif
6896
6897#ifdef FEAT_TITLE
6898 /* 'titlestring' and 'iconstring' */
6899 else if (varp == &p_titlestring || varp == &p_iconstring)
6900 {
6901# ifdef FEAT_STL_OPT
6902 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6903
6904 /* NULL => statusline syntax */
6905 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6906 stl_syntax |= flagval;
6907 else
6908 stl_syntax &= ~flagval;
6909# endif
6910 did_set_title(varp == &p_iconstring);
6911
6912 }
6913#endif
6914
6915#ifdef FEAT_GUI
6916 /* 'guioptions' */
6917 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006918 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006919 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006920 redraw_gui_only = TRUE;
6921 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006922#endif
6923
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006924#if defined(FEAT_GUI_TABLINE)
6925 /* 'guitablabel' */
6926 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006927 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006928 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006929 redraw_gui_only = TRUE;
6930 }
6931 /* 'guitabtooltip' */
6932 else if (varp == &p_gtt)
6933 {
6934 redraw_gui_only = TRUE;
6935 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006936#endif
6937
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6939 /* 'ttymouse' */
6940 else if (varp == &p_ttym)
6941 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006942 /* Switch the mouse off before changing the escape sequences used for
6943 * that. */
6944 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006945 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6946 errmsg = e_invarg;
6947 else
6948 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006949 if (termcap_active)
6950 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951 }
6952#endif
6953
Bram Moolenaar071d4272004-06-13 20:20:40 +00006954 /* 'selection' */
6955 else if (varp == &p_sel)
6956 {
6957 if (*p_sel == NUL
6958 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6959 errmsg = e_invarg;
6960 }
6961
6962 /* 'selectmode' */
6963 else if (varp == &p_slm)
6964 {
6965 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6966 errmsg = e_invarg;
6967 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006968
6969#ifdef FEAT_BROWSE
6970 /* 'browsedir' */
6971 else if (varp == &p_bsdir)
6972 {
6973 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6974 && !mch_isdir(p_bsdir))
6975 errmsg = e_invarg;
6976 }
6977#endif
6978
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 /* 'keymodel' */
6980 else if (varp == &p_km)
6981 {
6982 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6983 errmsg = e_invarg;
6984 else
6985 {
6986 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6987 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6988 }
6989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006990
6991 /* 'mousemodel' */
6992 else if (varp == &p_mousem)
6993 {
6994 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6995 errmsg = e_invarg;
6996#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6997 else if (*p_mousem != *oldval)
6998 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6999 * to create or delete the popup menus. */
7000 gui_motif_update_mousemodel(root_menu);
7001#endif
7002 }
7003
7004 /* 'switchbuf' */
7005 else if (varp == &p_swb)
7006 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007007 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008 errmsg = e_invarg;
7009 }
7010
7011 /* 'debug' */
7012 else if (varp == &p_debug)
7013 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007014 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 errmsg = e_invarg;
7016 }
7017
7018 /* 'display' */
7019 else if (varp == &p_dy)
7020 {
7021 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7022 errmsg = e_invarg;
7023 else
7024 (void)init_chartab();
7025
7026 }
7027
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007028#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029 /* 'eadirection' */
7030 else if (varp == &p_ead)
7031 {
7032 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7033 errmsg = e_invarg;
7034 }
7035#endif
7036
7037#ifdef FEAT_CLIPBOARD
7038 /* 'clipboard' */
7039 else if (varp == &p_cb)
7040 errmsg = check_clipboard_option();
7041#endif
7042
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007043#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007044 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7045 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007046 else if (varp == &(curwin->w_s->b_p_spl)
7047 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007048 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007049 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007050 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007051 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007052 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007053 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007054 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007055 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007056 /* 'spellsuggest' */
7057 else if (varp == &p_sps)
7058 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007059 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007060 errmsg = e_invarg;
7061 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007062 /* 'mkspellmem' */
7063 else if (varp == &p_msm)
7064 {
7065 if (spell_check_msm() != OK)
7066 errmsg = e_invarg;
7067 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007068#endif
7069
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070#ifdef FEAT_QUICKFIX
7071 /* When 'bufhidden' is set, check for valid value. */
7072 else if (gvarp == &p_bh)
7073 {
7074 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7075 errmsg = e_invarg;
7076 }
7077
7078 /* When 'buftype' is set, check for valid value. */
7079 else if (gvarp == &p_bt)
7080 {
7081 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7082 errmsg = e_invarg;
7083 else
7084 {
7085# ifdef FEAT_WINDOWS
7086 if (curwin->w_status_height)
7087 {
7088 curwin->w_redr_status = TRUE;
7089 redraw_later(VALID);
7090 }
7091# endif
7092 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007093# ifdef FEAT_TITLE
7094 redraw_titles();
7095# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096 }
7097 }
7098#endif
7099
7100#ifdef FEAT_STL_OPT
7101 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007102 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 {
7104 int wid;
7105
7106 if (varp == &p_ruf) /* reset ru_wid first */
7107 ru_wid = 0;
7108 s = *varp;
7109 if (varp == &p_ruf && *s == '%')
7110 {
7111 /* set ru_wid if 'ruf' starts with "%99(" */
7112 if (*++s == '-') /* ignore a '-' */
7113 s++;
7114 wid = getdigits(&s);
7115 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7116 ru_wid = wid;
7117 else
7118 errmsg = check_stl_option(p_ruf);
7119 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007120 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007121 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007123 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007124 comp_col();
7125 }
7126#endif
7127
7128#ifdef FEAT_INS_EXPAND
7129 /* check if it is a valid value for 'complete' -- Acevedo */
7130 else if (gvarp == &p_cpt)
7131 {
7132 for (s = *varp; *s;)
7133 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007134 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135 s++;
7136 if (!*s)
7137 break;
7138 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7139 {
7140 errmsg = illegal_char(errbuf, *s);
7141 break;
7142 }
7143 if (*++s != NUL && *s != ',' && *s != ' ')
7144 {
7145 if (s[-1] == 'k' || s[-1] == 's')
7146 {
7147 /* skip optional filename after 'k' and 's' */
7148 while (*s && *s != ',' && *s != ' ')
7149 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007150 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007151 ++s;
7152 ++s;
7153 }
7154 }
7155 else
7156 {
7157 if (errbuf != NULL)
7158 {
7159 sprintf((char *)errbuf,
7160 _("E535: Illegal character after <%c>"),
7161 *--s);
7162 errmsg = errbuf;
7163 }
7164 else
7165 errmsg = (char_u *)"";
7166 break;
7167 }
7168 }
7169 }
7170 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007171
7172 /* 'completeopt' */
7173 else if (varp == &p_cot)
7174 {
7175 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7176 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007177 else
7178 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180#endif /* FEAT_INS_EXPAND */
7181
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007182#ifdef FEAT_SIGNS
7183 /* 'signcolumn' */
7184 else if (varp == &curwin->w_p_scl)
7185 {
7186 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7187 errmsg = e_invarg;
7188 }
7189#endif
7190
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191
7192#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007193 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007194 else if (varp == &p_toolbar)
7195 {
7196 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7197 &toolbar_flags, TRUE) != OK)
7198 errmsg = e_invarg;
7199 else
7200 {
7201 out_flush();
7202 gui_mch_show_toolbar((toolbar_flags &
7203 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7204 }
7205 }
7206#endif
7207
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007208#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209 /* 'toolbariconsize': GTK+ 2 only */
7210 else if (varp == &p_tbis)
7211 {
7212 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7213 errmsg = e_invarg;
7214 else
7215 {
7216 out_flush();
7217 gui_mch_show_toolbar((toolbar_flags &
7218 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7219 }
7220 }
7221#endif
7222
7223 /* 'pastetoggle': translate key codes like in a mapping */
7224 else if (varp == &p_pt)
7225 {
7226 if (*p_pt)
7227 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007228 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007229 if (p != NULL)
7230 {
7231 if (new_value_alloced)
7232 free_string_option(p_pt);
7233 p_pt = p;
7234 new_value_alloced = TRUE;
7235 }
7236 }
7237 }
7238
7239 /* 'backspace' */
7240 else if (varp == &p_bs)
7241 {
7242 if (VIM_ISDIGIT(*p_bs))
7243 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007244 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007245 errmsg = e_invarg;
7246 }
7247 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7248 errmsg = e_invarg;
7249 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007250 else if (varp == &p_bo)
7251 {
7252 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7253 errmsg = e_invarg;
7254 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007256 /* 'tagcase' */
7257 else if (gvarp == &p_tc)
7258 {
7259 unsigned int *flags;
7260
7261 if (opt_flags & OPT_LOCAL)
7262 {
7263 p = curbuf->b_p_tc;
7264 flags = &curbuf->b_tc_flags;
7265 }
7266 else
7267 {
7268 p = p_tc;
7269 flags = &tc_flags;
7270 }
7271
7272 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7273 /* make the local value empty: use the global value */
7274 *flags = 0;
7275 else if (*p == NUL
7276 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7277 errmsg = e_invarg;
7278 }
7279
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007280#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007281 /* 'casemap' */
7282 else if (varp == &p_cmp)
7283 {
7284 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7285 errmsg = e_invarg;
7286 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007288
7289#ifdef FEAT_DIFF
7290 /* 'diffopt' */
7291 else if (varp == &p_dip)
7292 {
7293 if (diffopt_changed() == FAIL)
7294 errmsg = e_invarg;
7295 }
7296#endif
7297
7298#ifdef FEAT_FOLDING
7299 /* 'foldmethod' */
7300 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7301 {
7302 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7303 || *curwin->w_p_fdm == NUL)
7304 errmsg = e_invarg;
7305 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007306 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007307 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007308 if (foldmethodIsDiff(curwin))
7309 newFoldLevel();
7310 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 }
7312# ifdef FEAT_EVAL
7313 /* 'foldexpr' */
7314 else if (varp == &curwin->w_p_fde)
7315 {
7316 if (foldmethodIsExpr(curwin))
7317 foldUpdateAll(curwin);
7318 }
7319# endif
7320 /* 'foldmarker' */
7321 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7322 {
7323 p = vim_strchr(*varp, ',');
7324 if (p == NULL)
7325 errmsg = (char_u *)N_("E536: comma required");
7326 else if (p == *varp || p[1] == NUL)
7327 errmsg = e_invarg;
7328 else if (foldmethodIsMarker(curwin))
7329 foldUpdateAll(curwin);
7330 }
7331 /* 'commentstring' */
7332 else if (gvarp == &p_cms)
7333 {
7334 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7335 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7336 }
7337 /* 'foldopen' */
7338 else if (varp == &p_fdo)
7339 {
7340 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7341 errmsg = e_invarg;
7342 }
7343 /* 'foldclose' */
7344 else if (varp == &p_fcl)
7345 {
7346 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7347 errmsg = e_invarg;
7348 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007349 /* 'foldignore' */
7350 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7351 {
7352 if (foldmethodIsIndent(curwin))
7353 foldUpdateAll(curwin);
7354 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355#endif
7356
7357#ifdef FEAT_VIRTUALEDIT
7358 /* 'virtualedit' */
7359 else if (varp == &p_ve)
7360 {
7361 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7362 errmsg = e_invarg;
7363 else if (STRCMP(p_ve, oldval) != 0)
7364 {
7365 /* Recompute cursor position in case the new 've' setting
7366 * changes something. */
7367 validate_virtcol();
7368 coladvance(curwin->w_virtcol);
7369 }
7370 }
7371#endif
7372
7373#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7374 else if (varp == &p_csqf)
7375 {
7376 if (p_csqf != NULL)
7377 {
7378 p = p_csqf;
7379 while (*p != NUL)
7380 {
7381 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7382 || p[1] == NUL
7383 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7384 || (p[2] != NUL && p[2] != ','))
7385 {
7386 errmsg = e_invarg;
7387 break;
7388 }
7389 else if (p[2] == NUL)
7390 break;
7391 else
7392 p += 3;
7393 }
7394 }
7395 }
7396#endif
7397
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007398#ifdef FEAT_CINDENT
7399 /* 'cinoptions' */
7400 else if (gvarp == &p_cino)
7401 {
7402 /* TODO: recognize errors */
7403 parse_cino(curbuf);
7404 }
7405#endif
7406
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007407#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007408 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007409 else if (varp == &p_rop && gui.in_use)
7410 {
7411 if (!gui_mch_set_rendering_options(p_rop))
7412 errmsg = e_invarg;
7413 }
7414#endif
7415
Bram Moolenaard0b51382016-11-04 15:23:45 +01007416#ifdef FEAT_AUTOCMD
7417 else if (gvarp == &p_ft)
7418 {
7419 if (!valid_filetype(*varp))
7420 errmsg = e_invarg;
7421 }
7422#endif
7423
7424#ifdef FEAT_SYN_HL
7425 else if (gvarp == &p_syn)
7426 {
7427 if (!valid_filetype(*varp))
7428 errmsg = e_invarg;
7429 }
7430#endif
7431
Bram Moolenaar071d4272004-06-13 20:20:40 +00007432 /* Options that are a list of flags. */
7433 else
7434 {
7435 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007436 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007437 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007438 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007439 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007440 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007441 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007442 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007444#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007445 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007446 p = (char_u *)COCU_ALL;
7447#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007448 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449 {
7450#ifdef FEAT_MOUSE
7451 p = (char_u *)MOUSE_ALL;
7452#else
7453 if (*p_mouse != NUL)
7454 errmsg = (char_u *)N_("E538: No mouse support");
7455#endif
7456 }
7457#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007458 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459 p = (char_u *)GO_ALL;
7460#endif
7461 if (p != NULL)
7462 {
7463 for (s = *varp; *s; ++s)
7464 if (vim_strchr(p, *s) == NULL)
7465 {
7466 errmsg = illegal_char(errbuf, *s);
7467 break;
7468 }
7469 }
7470 }
7471
7472 /*
7473 * If error detected, restore the previous value.
7474 */
7475 if (errmsg != NULL)
7476 {
7477 if (new_value_alloced)
7478 free_string_option(*varp);
7479 *varp = oldval;
7480 /*
7481 * When resetting some values, need to act on it.
7482 */
7483 if (did_chartab)
7484 (void)init_chartab();
7485 if (varp == &p_hl)
7486 (void)highlight_changed();
7487 }
7488 else
7489 {
7490#ifdef FEAT_EVAL
7491 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007492 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007493#endif
7494 /*
7495 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007496 * Use "free_oldval", because recursiveness may change the flags under
7497 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007499 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007500 free_string_option(oldval);
7501 if (new_value_alloced)
7502 options[opt_idx].flags |= P_ALLOCED;
7503 else
7504 options[opt_idx].flags &= ~P_ALLOCED;
7505
7506 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007507 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 {
7509 /* global option with local value set to use global value; free
7510 * the local value and make it empty */
7511 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7512 free_string_option(*(char_u **)p);
7513 *(char_u **)p = empty_option;
7514 }
7515
7516 /* May set global value for local option. */
7517 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7518 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007519
7520#ifdef FEAT_AUTOCMD
7521 /*
7522 * Trigger the autocommand only after setting the flags.
7523 */
7524# ifdef FEAT_SYN_HL
7525 /* When 'syntax' is set, load the syntax of that name */
7526 if (varp == &(curbuf->b_p_syn))
7527 {
7528 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7529 curbuf->b_fname, TRUE, curbuf);
7530 }
7531# endif
7532 else if (varp == &(curbuf->b_p_ft))
7533 {
7534 /* 'filetype' is set, trigger the FileType autocommand */
7535 did_filetype = TRUE;
7536 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7537 curbuf->b_fname, TRUE, curbuf);
7538 }
7539#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007540#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007541 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007542 {
7543 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007544 char_u *q = curwin->w_s->b_p_spl;
7545
7546 /* Skip the first name if it is "cjk". */
7547 if (STRNCMP(q, "cjk,", 4) == 0)
7548 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007549
7550 /*
7551 * Source the spell/LANG.vim in 'runtimepath'.
7552 * They could set 'spellcapcheck' depending on the language.
7553 * Use the first name in 'spelllang' up to '_region' or
7554 * '.encoding'.
7555 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007556 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007557 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7558 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007559 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007560 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007561 }
7562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007563 }
7564
7565#ifdef FEAT_MOUSE
7566 if (varp == &p_mouse)
7567 {
7568# ifdef FEAT_MOUSE_TTY
7569 if (*p_mouse == NUL)
7570 mch_setmouse(FALSE); /* switch mouse off */
7571 else
7572# endif
7573 setmouse(); /* in case 'mouse' changed */
7574 }
7575#endif
7576
Bram Moolenaar913077c2012-03-28 19:59:04 +02007577 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007578 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007579 curwin->w_set_curswant = TRUE;
7580
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007581#ifdef FEAT_GUI
7582 /* check redraw when it's not a GUI option or the GUI is active. */
7583 if (!redraw_gui_only || gui.in_use)
7584#endif
7585 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007586
7587 return errmsg;
7588}
7589
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007590#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007591/*
7592 * Simple int comparison function for use with qsort()
7593 */
7594 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007595int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007596{
7597 return *(const int *)a - *(const int *)b;
7598}
7599
7600/*
7601 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7602 * Returns error message, NULL if it's OK.
7603 */
7604 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007605check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007606{
7607 char_u *s;
7608 int col;
7609 int count = 0;
7610 int color_cols[256];
7611 int i;
7612 int j = 0;
7613
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007614 if (wp->w_buffer == NULL)
7615 return NULL; /* buffer was closed */
7616
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007617 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007618 {
7619 if (*s == '-' || *s == '+')
7620 {
7621 /* -N and +N: add to 'textwidth' */
7622 col = (*s == '-') ? -1 : 1;
7623 ++s;
7624 if (!VIM_ISDIGIT(*s))
7625 return e_invarg;
7626 col = col * getdigits(&s);
7627 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007628 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007629 col += wp->w_buffer->b_p_tw;
7630 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007631 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007632 }
7633 else if (VIM_ISDIGIT(*s))
7634 col = getdigits(&s);
7635 else
7636 return e_invarg;
7637 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007638skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007639 if (*s == NUL)
7640 break;
7641 if (*s != ',')
7642 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007643 if (*++s == NUL)
7644 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007645 }
7646
7647 vim_free(wp->w_p_cc_cols);
7648 if (count == 0)
7649 wp->w_p_cc_cols = NULL;
7650 else
7651 {
7652 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7653 if (wp->w_p_cc_cols != NULL)
7654 {
7655 /* sort the columns for faster usage on screen redraw inside
7656 * win_line() */
7657 qsort(color_cols, count, sizeof(int), int_cmp);
7658
7659 for (i = 0; i < count; ++i)
7660 /* skip duplicates */
7661 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7662 wp->w_p_cc_cols[j++] = color_cols[i];
7663 wp->w_p_cc_cols[j] = -1; /* end marker */
7664 }
7665 }
7666
7667 return NULL; /* no error */
7668}
7669#endif
7670
Bram Moolenaar071d4272004-06-13 20:20:40 +00007671/*
7672 * Handle setting 'listchars' or 'fillchars'.
7673 * Returns error message, NULL if it's OK.
7674 */
7675 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007676set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677{
7678 int round, i, len, entries;
7679 char_u *p, *s;
7680 int c1, c2 = 0;
7681 struct charstab
7682 {
7683 int *cp;
7684 char *name;
7685 };
7686#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7687 static struct charstab filltab[] =
7688 {
7689 {&fill_stl, "stl"},
7690 {&fill_stlnc, "stlnc"},
7691 {&fill_vert, "vert"},
7692 {&fill_fold, "fold"},
7693 {&fill_diff, "diff"},
7694 };
7695#endif
7696 static struct charstab lcstab[] =
7697 {
7698 {&lcs_eol, "eol"},
7699 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007700 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007701 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007702 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007703 {&lcs_tab2, "tab"},
7704 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007705#ifdef FEAT_CONCEAL
7706 {&lcs_conceal, "conceal"},
7707#else
7708 {NULL, "conceal"},
7709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 };
7711 struct charstab *tab;
7712
7713#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7714 if (varp == &p_lcs)
7715#endif
7716 {
7717 tab = lcstab;
7718 entries = sizeof(lcstab) / sizeof(struct charstab);
7719 }
7720#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7721 else
7722 {
7723 tab = filltab;
7724 entries = sizeof(filltab) / sizeof(struct charstab);
7725 }
7726#endif
7727
7728 /* first round: check for valid value, second round: assign values */
7729 for (round = 0; round <= 1; ++round)
7730 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007731 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732 {
7733 /* After checking that the value is valid: set defaults: space for
7734 * 'fillchars', NUL for 'listchars' */
7735 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007736 if (tab[i].cp != NULL)
7737 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007738 if (varp == &p_lcs)
7739 lcs_tab1 = NUL;
7740#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7741 else
7742 fill_diff = '-';
7743#endif
7744 }
7745 p = *varp;
7746 while (*p)
7747 {
7748 for (i = 0; i < entries; ++i)
7749 {
7750 len = (int)STRLEN(tab[i].name);
7751 if (STRNCMP(p, tab[i].name, len) == 0
7752 && p[len] == ':'
7753 && p[len + 1] != NUL)
7754 {
7755 s = p + len + 1;
7756#ifdef FEAT_MBYTE
7757 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007758 if (mb_char2cells(c1) > 1)
7759 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760#else
7761 c1 = *s++;
7762#endif
7763 if (tab[i].cp == &lcs_tab2)
7764 {
7765 if (*s == NUL)
7766 continue;
7767#ifdef FEAT_MBYTE
7768 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007769 if (mb_char2cells(c2) > 1)
7770 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007771#else
7772 c2 = *s++;
7773#endif
7774 }
7775 if (*s == ',' || *s == NUL)
7776 {
7777 if (round)
7778 {
7779 if (tab[i].cp == &lcs_tab2)
7780 {
7781 lcs_tab1 = c1;
7782 lcs_tab2 = c2;
7783 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007784 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785 *(tab[i].cp) = c1;
7786
7787 }
7788 p = s;
7789 break;
7790 }
7791 }
7792 }
7793
7794 if (i == entries)
7795 return e_invarg;
7796 if (*p == ',')
7797 ++p;
7798 }
7799 }
7800
7801 return NULL; /* no error */
7802}
7803
7804#ifdef FEAT_STL_OPT
7805/*
7806 * Check validity of options with the 'statusline' format.
7807 * Return error message or NULL.
7808 */
7809 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007810check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007811{
7812 int itemcnt = 0;
7813 int groupdepth = 0;
7814 static char_u errbuf[80];
7815
7816 while (*s && itemcnt < STL_MAX_ITEM)
7817 {
7818 /* Check for valid keys after % sequences */
7819 while (*s && *s != '%')
7820 s++;
7821 if (!*s)
7822 break;
7823 s++;
7824 if (*s != '%' && *s != ')')
7825 ++itemcnt;
7826 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7827 {
7828 s++;
7829 continue;
7830 }
7831 if (*s == ')')
7832 {
7833 s++;
7834 if (--groupdepth < 0)
7835 break;
7836 continue;
7837 }
7838 if (*s == '-')
7839 s++;
7840 while (VIM_ISDIGIT(*s))
7841 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007842 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007843 continue;
7844 if (*s == '.')
7845 {
7846 s++;
7847 while (*s && VIM_ISDIGIT(*s))
7848 s++;
7849 }
7850 if (*s == '(')
7851 {
7852 groupdepth++;
7853 continue;
7854 }
7855 if (vim_strchr(STL_ALL, *s) == NULL)
7856 {
7857 return illegal_char(errbuf, *s);
7858 }
7859 if (*s == '{')
7860 {
7861 s++;
7862 while (*s != '}' && *s)
7863 s++;
7864 if (*s != '}')
7865 return (char_u *)N_("E540: Unclosed expression sequence");
7866 }
7867 }
7868 if (itemcnt >= STL_MAX_ITEM)
7869 return (char_u *)N_("E541: too many items");
7870 if (groupdepth != 0)
7871 return (char_u *)N_("E542: unbalanced groups");
7872 return NULL;
7873}
7874#endif
7875
7876#ifdef FEAT_CLIPBOARD
7877/*
7878 * Extract the items in the 'clipboard' option and set global values.
7879 */
7880 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007881check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007882{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007883 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007884 int new_autoselect_star = FALSE;
7885 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007887 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007888 regprog_T *new_exclude_prog = NULL;
7889 char_u *errmsg = NULL;
7890 char_u *p;
7891
7892 for (p = p_cb; *p != NUL; )
7893 {
7894 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7895 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007896 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007897 p += 7;
7898 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007899 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007900 && (p[11] == ',' || p[11] == NUL))
7901 {
7902 new_unnamed |= CLIP_UNNAMED_PLUS;
7903 p += 11;
7904 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007906 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007908 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909 p += 10;
7910 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007911 else if (STRNCMP(p, "autoselectplus", 14) == 0
7912 && (p[14] == ',' || p[14] == NUL))
7913 {
7914 new_autoselect_plus = TRUE;
7915 p += 14;
7916 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007918 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 {
7920 new_autoselectml = TRUE;
7921 p += 12;
7922 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007923 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7924 {
7925 new_html = TRUE;
7926 p += 4;
7927 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7929 {
7930 p += 8;
7931 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7932 if (new_exclude_prog == NULL)
7933 errmsg = e_invarg;
7934 break;
7935 }
7936 else
7937 {
7938 errmsg = e_invarg;
7939 break;
7940 }
7941 if (*p == ',')
7942 ++p;
7943 }
7944 if (errmsg == NULL)
7945 {
7946 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007947 clip_autoselect_star = new_autoselect_star;
7948 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007950 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007951 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007953#ifdef FEAT_GUI_GTK
7954 if (gui.in_use)
7955 {
7956 gui_gtk_set_selection_targets();
7957 gui_gtk_set_dnd_targets();
7958 }
7959#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960 }
7961 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007962 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963
7964 return errmsg;
7965}
7966#endif
7967
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007968#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007969 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007970did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007971{
7972 char_u *errmsg = NULL;
7973 win_T *wp;
7974 int l;
7975
7976 if (is_spellfile)
7977 {
7978 l = (int)STRLEN(curwin->w_s->b_p_spf);
7979 if (l > 0 && (l < 4
7980 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7981 errmsg = e_invarg;
7982 }
7983
7984 if (errmsg == NULL)
7985 {
7986 FOR_ALL_WINDOWS(wp)
7987 if (wp->w_buffer == curbuf && wp->w_p_spell)
7988 {
7989 errmsg = did_set_spelllang(wp);
7990# ifdef FEAT_WINDOWS
7991 break;
7992# endif
7993 }
7994 }
7995 return errmsg;
7996}
7997
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007998/*
7999 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8000 * Return error message when failed, NULL when OK.
8001 */
8002 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008003compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008004{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008005 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008006 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008007
Bram Moolenaar860cae12010-06-05 23:22:07 +02008008 if (*synblock->b_p_spc == NUL)
8009 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008010 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008011 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008012 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008013 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008014 if (re != NULL)
8015 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008016 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008017 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008018 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008019 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008020 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008021 return e_invarg;
8022 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008023 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008024 }
8025
Bram Moolenaar473de612013-06-08 18:19:48 +02008026 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008027 return NULL;
8028}
8029#endif
8030
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008031#if defined(FEAT_EVAL) || defined(PROTO)
8032/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008033 * Set the scriptID for an option, taking care of setting the buffer- or
8034 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008035 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008036 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008037set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008038{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008039 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8040 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008041
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008042 /* Remember where the option was set. For local options need to do that
8043 * in the buffer or window structure. */
8044 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008045 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008046 if (both || (opt_flags & OPT_LOCAL))
8047 {
8048 if (indir & PV_BUF)
8049 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8050 else if (indir & PV_WIN)
8051 curwin->w_p_scriptID[indir & PV_MASK] = id;
8052 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008053}
8054#endif
8055
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056/*
8057 * Set the value of a boolean option, and take care of side effects.
8058 * Returns NULL for success, or an error message for an error.
8059 */
8060 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008061set_bool_option(
8062 int opt_idx, /* index in options[] table */
8063 char_u *varp, /* pointer to the option variable */
8064 int value, /* new value */
8065 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066{
8067 int old_value = *(int *)varp;
8068
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069 /* Disallow changing some options from secure mode */
8070 if ((secure
8071#ifdef HAVE_SANDBOX
8072 || sandbox != 0
8073#endif
8074 ) && (options[opt_idx].flags & P_SECURE))
8075 return e_secure;
8076
8077 *(int *)varp = value; /* set the new value */
8078#ifdef FEAT_EVAL
8079 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008080 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008081#endif
8082
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008083#ifdef FEAT_GUI
8084 need_mouse_correct = TRUE;
8085#endif
8086
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087 /* May set global value for local option. */
8088 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8089 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8090
8091 /*
8092 * Handle side effects of changing a bool option.
8093 */
8094
8095 /* 'compatible' */
8096 if ((int *)varp == &p_cp)
8097 {
8098 compatible_set();
8099 }
8100
Bram Moolenaar920694c2016-08-21 17:45:02 +02008101#ifdef FEAT_LANGMAP
8102 if ((int *)varp == &p_lrm)
8103 /* 'langremap' -> !'langnoremap' */
8104 p_lnr = !p_lrm;
8105 else if ((int *)varp == &p_lnr)
8106 /* 'langnoremap' -> !'langremap' */
8107 p_lrm = !p_lnr;
8108#endif
8109
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008110#ifdef FEAT_PERSISTENT_UNDO
8111 /* 'undofile' */
8112 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8113 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008114 /* Only take action when the option was set. When reset we do not
8115 * delete the undo file, the option may be set again without making
8116 * any changes in between. */
8117 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008118 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008119 char_u hash[UNDO_HASH_SIZE];
8120 buf_T *save_curbuf = curbuf;
8121
Bram Moolenaar29323592016-07-24 22:04:11 +02008122 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008123 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008124 /* When 'undofile' is set globally: for every buffer, otherwise
8125 * only for the current buffer: Try to read in the undofile,
8126 * if one exists, the buffer wasn't changed and the buffer was
8127 * loaded */
8128 if ((curbuf == save_curbuf
8129 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8130 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8131 {
8132 u_compute_hash(hash);
8133 u_read_undo(NULL, hash, curbuf->b_fname);
8134 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008135 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008136 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008137 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008138 }
8139#endif
8140
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141 else if ((int *)varp == &curbuf->b_p_ro)
8142 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008143 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8145 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008146
8147 /* when 'readonly' is set may give W10 again */
8148 if (curbuf->b_p_ro)
8149 curbuf->b_did_warn = FALSE;
8150
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008152 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153#endif
8154 }
8155
Bram Moolenaar9c449722010-07-20 18:44:27 +02008156#ifdef FEAT_GUI
8157 else if ((int *)varp == &p_mh)
8158 {
8159 if (!p_mh)
8160 gui_mch_mousehide(FALSE);
8161 }
8162#endif
8163
Bram Moolenaara539df02010-08-01 14:35:05 +02008164#ifdef FEAT_TITLE
8165 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008167 {
8168 redraw_titles();
8169 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170 /* when 'endofline' is changed, redraw the window title */
8171 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008172 {
8173 redraw_titles();
8174 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008175 /* when 'fixeol' is changed, redraw the window title */
8176 else if ((int *)varp == &curbuf->b_p_fixeol)
8177 {
8178 redraw_titles();
8179 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008180# ifdef FEAT_MBYTE
8181 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008182 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008183 {
8184 redraw_titles();
8185 }
8186# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187#endif
8188
8189 /* when 'bin' is set also set some other options */
8190 else if ((int *)varp == &curbuf->b_p_bin)
8191 {
8192 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8193#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008194 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195#endif
8196 }
8197
8198#ifdef FEAT_AUTOCMD
8199 /* when 'buflisted' changes, trigger autocommands */
8200 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8201 {
8202 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8203 NULL, NULL, TRUE, curbuf);
8204 }
8205#endif
8206
8207 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8208 else if ((int *)varp == &curbuf->b_p_swf)
8209 {
8210 if (curbuf->b_p_swf && p_uc)
8211 ml_open_file(curbuf); /* create the swap file */
8212 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008213 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8214 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008215 mf_close_file(curbuf, TRUE); /* remove the swap file */
8216 }
8217
8218 /* when 'terse' is set change 'shortmess' */
8219 else if ((int *)varp == &p_terse)
8220 {
8221 char_u *p;
8222
8223 p = vim_strchr(p_shm, SHM_SEARCH);
8224
8225 /* insert 's' in p_shm */
8226 if (p_terse && p == NULL)
8227 {
8228 STRCPY(IObuff, p_shm);
8229 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008230 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231 }
8232 /* remove 's' from p_shm */
8233 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008234 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008235 }
8236
8237 /* when 'paste' is set or reset also change other options */
8238 else if ((int *)varp == &p_paste)
8239 {
8240 paste_option_changed();
8241 }
8242
8243 /* when 'insertmode' is set from an autocommand need to do work here */
8244 else if ((int *)varp == &p_im)
8245 {
8246 if (p_im)
8247 {
8248 if ((State & INSERT) == 0)
8249 need_start_insertmode = TRUE;
8250 stop_insert_mode = FALSE;
8251 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008252 /* only reset if it was set previously */
8253 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254 {
8255 need_start_insertmode = FALSE;
8256 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008257 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008258 clear_cmdline = TRUE; /* remove "(insert)" */
8259 restart_edit = 0;
8260 }
8261 }
8262
8263 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8264 else if ((int *)varp == &p_ic && p_hls)
8265 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008266 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008267 }
8268
8269#ifdef FEAT_SEARCH_EXTRA
8270 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8271 else if ((int *)varp == &p_hls)
8272 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008273 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008274 }
8275#endif
8276
8277#ifdef FEAT_SCROLLBIND
8278 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8279 * at the end of normal_cmd() */
8280 else if ((int *)varp == &curwin->w_p_scb)
8281 {
8282 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008283 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008285 curwin->w_scbind_pos = curwin->w_topline;
8286 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287 }
8288#endif
8289
8290#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8291 /* There can be only one window with 'previewwindow' set. */
8292 else if ((int *)varp == &curwin->w_p_pvw)
8293 {
8294 if (curwin->w_p_pvw)
8295 {
8296 win_T *win;
8297
Bram Moolenaar29323592016-07-24 22:04:11 +02008298 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008299 if (win->w_p_pvw && win != curwin)
8300 {
8301 curwin->w_p_pvw = FALSE;
8302 return (char_u *)N_("E590: A preview window already exists");
8303 }
8304 }
8305 }
8306#endif
8307
8308 /* when 'textmode' is set or reset also change 'fileformat' */
8309 else if ((int *)varp == &curbuf->b_p_tx)
8310 {
8311 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8312 }
8313
8314 /* when 'textauto' is set or reset also change 'fileformats' */
8315 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 set_string_option_direct((char_u *)"ffs", -1,
8317 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008318 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008319
8320 /*
8321 * When 'lisp' option changes include/exclude '-' in
8322 * keyword characters.
8323 */
8324#ifdef FEAT_LISP
8325 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8326 {
8327 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8328 }
8329#endif
8330
8331#ifdef FEAT_TITLE
8332 /* when 'title' changed, may need to change the title; same for 'icon' */
8333 else if ((int *)varp == &p_title)
8334 {
8335 did_set_title(FALSE);
8336 }
8337
8338 else if ((int *)varp == &p_icon)
8339 {
8340 did_set_title(TRUE);
8341 }
8342#endif
8343
8344 else if ((int *)varp == &curbuf->b_changed)
8345 {
8346 if (!value)
8347 save_file_ff(curbuf); /* Buffer is unchanged */
8348#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008349 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350#endif
8351#ifdef FEAT_AUTOCMD
8352 modified_was_set = value;
8353#endif
8354 }
8355
8356#ifdef BACKSLASH_IN_FILENAME
8357 else if ((int *)varp == &p_ssl)
8358 {
8359 if (p_ssl)
8360 {
8361 psepc = '/';
8362 psepcN = '\\';
8363 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 }
8365 else
8366 {
8367 psepc = '\\';
8368 psepcN = '/';
8369 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 }
8371
8372 /* need to adjust the file name arguments and buffer names. */
8373 buflist_slash_adjust();
8374 alist_slash_adjust();
8375# ifdef FEAT_EVAL
8376 scriptnames_slash_adjust();
8377# endif
8378 }
8379#endif
8380
8381 /* If 'wrap' is set, set w_leftcol to zero. */
8382 else if ((int *)varp == &curwin->w_p_wrap)
8383 {
8384 if (curwin->w_p_wrap)
8385 curwin->w_leftcol = 0;
8386 }
8387
8388#ifdef FEAT_WINDOWS
8389 else if ((int *)varp == &p_ea)
8390 {
8391 if (p_ea && !old_value)
8392 win_equal(curwin, FALSE, 0);
8393 }
8394#endif
8395
8396 else if ((int *)varp == &p_wiv)
8397 {
8398 /*
8399 * When 'weirdinvert' changed, set/reset 't_xs'.
8400 * Then set 'weirdinvert' according to value of 't_xs'.
8401 */
8402 if (p_wiv && !old_value)
8403 T_XS = (char_u *)"y";
8404 else if (!p_wiv && old_value)
8405 T_XS = empty_option;
8406 p_wiv = (*T_XS != NUL);
8407 }
8408
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008409#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410 else if ((int *)varp == &p_beval)
8411 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008412 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008414 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415 gui_mch_disable_beval_area(balloonEval);
8416 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008417#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008419#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420 else if ((int *)varp == &p_acd)
8421 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008422 /* Change directories when the 'acd' option is set now. */
8423 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424 }
8425#endif
8426
8427#ifdef FEAT_DIFF
8428 /* 'diff' */
8429 else if ((int *)varp == &curwin->w_p_diff)
8430 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008431 /* May add or remove the buffer from the list of diff buffers. */
8432 diff_buf_adjust(curwin);
8433# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 if (foldmethodIsDiff(curwin))
8435 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008436# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 }
8438#endif
8439
8440#ifdef USE_IM_CONTROL
8441 /* 'imdisable' */
8442 else if ((int *)varp == &p_imdisable)
8443 {
8444 /* Only de-activate it here, it will be enabled when changing mode. */
8445 if (p_imdisable)
8446 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008447 else if (State & INSERT)
8448 /* When the option is set from an autocommand, it may need to take
8449 * effect right away. */
8450 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451 }
8452#endif
8453
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008454#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008455 /* 'spell' */
8456 else if ((int *)varp == &curwin->w_p_spell)
8457 {
8458 if (curwin->w_p_spell)
8459 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008460 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008461 if (errmsg != NULL)
8462 EMSG(_(errmsg));
8463 }
8464 }
8465#endif
8466
Bram Moolenaar071d4272004-06-13 20:20:40 +00008467#ifdef FEAT_FKMAP
8468 else if ((int *)varp == &p_altkeymap)
8469 {
8470 if (old_value != p_altkeymap)
8471 {
8472 if (!p_altkeymap)
8473 {
8474 p_hkmap = p_fkmap;
8475 p_fkmap = 0;
8476 }
8477 else
8478 {
8479 p_fkmap = p_hkmap;
8480 p_hkmap = 0;
8481 }
8482 (void)init_chartab();
8483 }
8484 }
8485
8486 /*
8487 * In case some second language keymapping options have changed, check
8488 * and correct the setting in a consistent way.
8489 */
8490
8491 /*
8492 * If hkmap or fkmap are set, reset Arabic keymapping.
8493 */
8494 if ((p_hkmap || p_fkmap) && p_altkeymap)
8495 {
8496 p_altkeymap = p_fkmap;
8497# ifdef FEAT_ARABIC
8498 curwin->w_p_arab = FALSE;
8499# endif
8500 (void)init_chartab();
8501 }
8502
8503 /*
8504 * If hkmap set, reset Farsi keymapping.
8505 */
8506 if (p_hkmap && p_altkeymap)
8507 {
8508 p_altkeymap = 0;
8509 p_fkmap = 0;
8510# ifdef FEAT_ARABIC
8511 curwin->w_p_arab = FALSE;
8512# endif
8513 (void)init_chartab();
8514 }
8515
8516 /*
8517 * If fkmap set, reset Hebrew keymapping.
8518 */
8519 if (p_fkmap && !p_altkeymap)
8520 {
8521 p_altkeymap = 1;
8522 p_hkmap = 0;
8523# ifdef FEAT_ARABIC
8524 curwin->w_p_arab = FALSE;
8525# endif
8526 (void)init_chartab();
8527 }
8528#endif
8529
8530#ifdef FEAT_ARABIC
8531 if ((int *)varp == &curwin->w_p_arab)
8532 {
8533 if (curwin->w_p_arab)
8534 {
8535 /*
8536 * 'arabic' is set, handle various sub-settings.
8537 */
8538 if (!p_tbidi)
8539 {
8540 /* set rightleft mode */
8541 if (!curwin->w_p_rl)
8542 {
8543 curwin->w_p_rl = TRUE;
8544 changed_window_setting();
8545 }
8546
8547 /* Enable Arabic shaping (major part of what Arabic requires) */
8548 if (!p_arshape)
8549 {
8550 p_arshape = TRUE;
8551 redraw_later_clear();
8552 }
8553 }
8554
8555 /* Arabic requires a utf-8 encoding, inform the user if its not
8556 * set. */
8557 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008558 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008559 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8560
Bram Moolenaar8820b482017-03-16 17:23:31 +01008561 msg_source(HL_ATTR(HLF_W));
8562 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008563#ifdef FEAT_EVAL
8564 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8565#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567
8568# ifdef FEAT_MBYTE
8569 /* set 'delcombine' */
8570 p_deco = TRUE;
8571# endif
8572
8573# ifdef FEAT_KEYMAP
8574 /* Force-set the necessary keymap for arabic */
8575 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8576 OPT_LOCAL);
8577# endif
8578# ifdef FEAT_FKMAP
8579 p_altkeymap = 0;
8580 p_hkmap = 0;
8581 p_fkmap = 0;
8582 (void)init_chartab();
8583# endif
8584 }
8585 else
8586 {
8587 /*
8588 * 'arabic' is reset, handle various sub-settings.
8589 */
8590 if (!p_tbidi)
8591 {
8592 /* reset rightleft mode */
8593 if (curwin->w_p_rl)
8594 {
8595 curwin->w_p_rl = FALSE;
8596 changed_window_setting();
8597 }
8598
8599 /* 'arabicshape' isn't reset, it is a global option and
8600 * another window may still need it "on". */
8601 }
8602
8603 /* 'delcombine' isn't reset, it is a global option and another
8604 * window may still want it "on". */
8605
8606# ifdef FEAT_KEYMAP
8607 /* Revert to the default keymap */
8608 curbuf->b_p_iminsert = B_IMODE_NONE;
8609 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8610# endif
8611 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008612 }
8613
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008614#endif
8615
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008616#ifdef FEAT_TERMGUICOLORS
8617 /* 'termguicolors' */
8618 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008619 {
8620# ifdef FEAT_GUI
8621 if (!gui.in_use && !gui.starting)
8622# endif
8623 highlight_gui_started();
8624 }
8625#endif
8626
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627 /*
8628 * End of handling side effects for bool options.
8629 */
8630
Bram Moolenaar53744302015-07-17 17:38:22 +02008631 /* after handling side effects, call autocommand */
8632
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633 options[opt_idx].flags |= P_WAS_SET;
8634
Bram Moolenaar53744302015-07-17 17:38:22 +02008635#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8636 if (!starting)
8637 {
8638 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008639 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8640 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8641 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008642 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8643 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8644 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8645 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8646 reset_v_option_vars();
8647 }
8648#endif
8649
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008651 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008652 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008653 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654 check_redraw(options[opt_idx].flags);
8655
8656 return NULL;
8657}
8658
8659/*
8660 * Set the value of a number option, and take care of side effects.
8661 * Returns NULL for success, or an error message for an error.
8662 */
8663 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008664set_num_option(
8665 int opt_idx, /* index in options[] table */
8666 char_u *varp, /* pointer to the option variable */
8667 long value, /* new value */
8668 char_u *errbuf, /* buffer for error messages */
8669 size_t errbuflen, /* length of "errbuf" */
8670 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008671 OPT_MODELINE */
8672{
8673 char_u *errmsg = NULL;
8674 long old_value = *(long *)varp;
8675 long old_Rows = Rows; /* remember old Rows */
8676 long old_Columns = Columns; /* remember old Columns */
8677 long *pp = (long *)varp;
8678
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008679 /* Disallow changing some options from secure mode. */
8680 if ((secure
8681#ifdef HAVE_SANDBOX
8682 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008683#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008684 ) && (options[opt_idx].flags & P_SECURE))
8685 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008686
8687 *pp = value;
8688#ifdef FEAT_EVAL
8689 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008690 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008692#ifdef FEAT_GUI
8693 need_mouse_correct = TRUE;
8694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695
Bram Moolenaar14f24742012-08-08 18:01:05 +02008696 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697 {
8698 errmsg = e_positive;
8699 curbuf->b_p_sw = curbuf->b_p_ts;
8700 }
8701
8702 /*
8703 * Number options that need some action when changed
8704 */
8705#ifdef FEAT_WINDOWS
8706 if (pp == &p_wh || pp == &p_hh)
8707 {
8708 if (p_wh < 1)
8709 {
8710 errmsg = e_positive;
8711 p_wh = 1;
8712 }
8713 if (p_wmh > p_wh)
8714 {
8715 errmsg = e_winheight;
8716 p_wh = p_wmh;
8717 }
8718 if (p_hh < 0)
8719 {
8720 errmsg = e_positive;
8721 p_hh = 0;
8722 }
8723
8724 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008725 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726 {
8727 if (pp == &p_wh && curwin->w_height < p_wh)
8728 win_setheight((int)p_wh);
8729 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8730 win_setheight((int)p_hh);
8731 }
8732 }
8733
8734 /* 'winminheight' */
8735 else if (pp == &p_wmh)
8736 {
8737 if (p_wmh < 0)
8738 {
8739 errmsg = e_positive;
8740 p_wmh = 0;
8741 }
8742 if (p_wmh > p_wh)
8743 {
8744 errmsg = e_winheight;
8745 p_wmh = p_wh;
8746 }
8747 win_setminheight();
8748 }
8749
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008750# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008751 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752 {
8753 if (p_wiw < 1)
8754 {
8755 errmsg = e_positive;
8756 p_wiw = 1;
8757 }
8758 if (p_wmw > p_wiw)
8759 {
8760 errmsg = e_winwidth;
8761 p_wiw = p_wmw;
8762 }
8763
8764 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008765 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008766 win_setwidth((int)p_wiw);
8767 }
8768
8769 /* 'winminwidth' */
8770 else if (pp == &p_wmw)
8771 {
8772 if (p_wmw < 0)
8773 {
8774 errmsg = e_positive;
8775 p_wmw = 0;
8776 }
8777 if (p_wmw > p_wiw)
8778 {
8779 errmsg = e_winwidth;
8780 p_wmw = p_wiw;
8781 }
8782 win_setminheight();
8783 }
8784# endif
8785
8786#endif
8787
8788#ifdef FEAT_WINDOWS
8789 /* (re)set last window status line */
8790 else if (pp == &p_ls)
8791 {
8792 last_status(FALSE);
8793 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008794
8795 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008796 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008797 {
8798 shell_new_rows(); /* recompute window positions and heights */
8799 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800#endif
8801
8802#ifdef FEAT_GUI
8803 else if (pp == &p_linespace)
8804 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008805 /* Recompute gui.char_height and resize the Vim window to keep the
8806 * same number of lines. */
8807 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008808 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 }
8810#endif
8811
8812#ifdef FEAT_FOLDING
8813 /* 'foldlevel' */
8814 else if (pp == &curwin->w_p_fdl)
8815 {
8816 if (curwin->w_p_fdl < 0)
8817 curwin->w_p_fdl = 0;
8818 newFoldLevel();
8819 }
8820
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008821 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822 else if (pp == &curwin->w_p_fml)
8823 {
8824 foldUpdateAll(curwin);
8825 }
8826
8827 /* 'foldnestmax' */
8828 else if (pp == &curwin->w_p_fdn)
8829 {
8830 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8831 foldUpdateAll(curwin);
8832 }
8833
8834 /* 'foldcolumn' */
8835 else if (pp == &curwin->w_p_fdc)
8836 {
8837 if (curwin->w_p_fdc < 0)
8838 {
8839 errmsg = e_positive;
8840 curwin->w_p_fdc = 0;
8841 }
8842 else if (curwin->w_p_fdc > 12)
8843 {
8844 errmsg = e_invarg;
8845 curwin->w_p_fdc = 12;
8846 }
8847 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008848#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008849
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008850#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 /* 'shiftwidth' or 'tabstop' */
8852 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8853 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008854# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855 if (foldmethodIsIndent(curwin))
8856 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008857# endif
8858# ifdef FEAT_CINDENT
8859 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8860 * parse 'cinoptions'. */
8861 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8862 parse_cino(curbuf);
8863# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008865#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008866
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008867#ifdef FEAT_MBYTE
8868 /* 'maxcombine' */
8869 else if (pp == &p_mco)
8870 {
8871 if (p_mco > MAX_MCO)
8872 p_mco = MAX_MCO;
8873 else if (p_mco < 0)
8874 p_mco = 0;
8875 screenclear(); /* will re-allocate the screen */
8876 }
8877#endif
8878
Bram Moolenaar071d4272004-06-13 20:20:40 +00008879 else if (pp == &curbuf->b_p_iminsert)
8880 {
8881 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8882 {
8883 errmsg = e_invarg;
8884 curbuf->b_p_iminsert = B_IMODE_NONE;
8885 }
8886 p_iminsert = curbuf->b_p_iminsert;
8887 if (termcap_active) /* don't do this in the alternate screen */
8888 showmode();
8889#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8890 /* Show/unshow value of 'keymap' in status lines. */
8891 status_redraw_curbuf();
8892#endif
8893 }
8894
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008895 else if (pp == &p_window)
8896 {
8897 if (p_window < 1)
8898 p_window = 1;
8899 else if (p_window >= Rows)
8900 p_window = Rows - 1;
8901 }
8902
Bram Moolenaar071d4272004-06-13 20:20:40 +00008903 else if (pp == &curbuf->b_p_imsearch)
8904 {
8905 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8906 {
8907 errmsg = e_invarg;
8908 curbuf->b_p_imsearch = B_IMODE_NONE;
8909 }
8910 p_imsearch = curbuf->b_p_imsearch;
8911 }
8912
8913#ifdef FEAT_TITLE
8914 /* if 'titlelen' has changed, redraw the title */
8915 else if (pp == &p_titlelen)
8916 {
8917 if (p_titlelen < 0)
8918 {
8919 errmsg = e_positive;
8920 p_titlelen = 85;
8921 }
8922 if (starting != NO_SCREEN && old_value != p_titlelen)
8923 need_maketitle = TRUE;
8924 }
8925#endif
8926
8927 /* if p_ch changed value, change the command line height */
8928 else if (pp == &p_ch)
8929 {
8930 if (p_ch < 1)
8931 {
8932 errmsg = e_positive;
8933 p_ch = 1;
8934 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008935 if (p_ch > Rows - min_rows() + 1)
8936 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937
8938 /* Only compute the new window layout when startup has been
8939 * completed. Otherwise the frame sizes may be wrong. */
8940 if (p_ch != old_value && full_screen
8941#ifdef FEAT_GUI
8942 && !gui.starting
8943#endif
8944 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008945 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946 }
8947
8948 /* when 'updatecount' changes from zero to non-zero, open swap files */
8949 else if (pp == &p_uc)
8950 {
8951 if (p_uc < 0)
8952 {
8953 errmsg = e_positive;
8954 p_uc = 100;
8955 }
8956 if (p_uc && !old_value)
8957 ml_open_files();
8958 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008959#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008960 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008961 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008962 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008963 {
8964 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008965 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008966 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008967 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008968 {
8969 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008970 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008971 }
8972 }
8973#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008974#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008975 else if (pp == &p_mzq)
8976 mzvim_reset_timer();
8977#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008979#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8980 /* 'pyxversion' */
8981 else if (pp == &p_pyx)
8982 {
8983 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8984 errmsg = e_invarg;
8985 }
8986#endif
8987
Bram Moolenaar071d4272004-06-13 20:20:40 +00008988 /* sync undo before 'undolevels' changes */
8989 else if (pp == &p_ul)
8990 {
8991 /* use the old value, otherwise u_sync() may not work properly */
8992 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008993 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994 p_ul = value;
8995 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008996 else if (pp == &curbuf->b_p_ul)
8997 {
8998 /* use the old value, otherwise u_sync() may not work properly */
8999 curbuf->b_p_ul = old_value;
9000 u_sync(TRUE);
9001 curbuf->b_p_ul = value;
9002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009003
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009004#ifdef FEAT_LINEBREAK
9005 /* 'numberwidth' must be positive */
9006 else if (pp == &curwin->w_p_nuw)
9007 {
9008 if (curwin->w_p_nuw < 1)
9009 {
9010 errmsg = e_positive;
9011 curwin->w_p_nuw = 1;
9012 }
9013 if (curwin->w_p_nuw > 10)
9014 {
9015 errmsg = e_invarg;
9016 curwin->w_p_nuw = 10;
9017 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009018 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009019 }
9020#endif
9021
Bram Moolenaar1a384422010-07-14 19:53:30 +02009022 else if (pp == &curbuf->b_p_tw)
9023 {
9024 if (curbuf->b_p_tw < 0)
9025 {
9026 errmsg = e_positive;
9027 curbuf->b_p_tw = 0;
9028 }
9029#ifdef FEAT_SYN_HL
9030# ifdef FEAT_WINDOWS
9031 {
9032 win_T *wp;
9033 tabpage_T *tp;
9034
9035 FOR_ALL_TAB_WINDOWS(tp, wp)
9036 check_colorcolumn(wp);
9037 }
9038# else
9039 check_colorcolumn(curwin);
9040# endif
9041#endif
9042 }
9043
Bram Moolenaar071d4272004-06-13 20:20:40 +00009044 /*
9045 * Check the bounds for numeric options here
9046 */
9047 if (Rows < min_rows() && full_screen)
9048 {
9049 if (errbuf != NULL)
9050 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009051 vim_snprintf((char *)errbuf, errbuflen,
9052 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009053 errmsg = errbuf;
9054 }
9055 Rows = min_rows();
9056 }
9057 if (Columns < MIN_COLUMNS && full_screen)
9058 {
9059 if (errbuf != NULL)
9060 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009061 vim_snprintf((char *)errbuf, errbuflen,
9062 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009063 errmsg = errbuf;
9064 }
9065 Columns = MIN_COLUMNS;
9066 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009067 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009068
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069 /*
9070 * If the screen (shell) height has been changed, assume it is the
9071 * physical screenheight.
9072 */
9073 if (old_Rows != Rows || old_Columns != Columns)
9074 {
9075 /* Changing the screen size is not allowed while updating the screen. */
9076 if (updating_screen)
9077 *pp = old_value;
9078 else if (full_screen
9079#ifdef FEAT_GUI
9080 && !gui.starting
9081#endif
9082 )
9083 set_shellsize((int)Columns, (int)Rows, TRUE);
9084 else
9085 {
9086 /* Postpone the resizing; check the size and cmdline position for
9087 * messages. */
9088 check_shellsize();
9089 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9090 cmdline_row = Rows - p_ch;
9091 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009092 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009093 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094 }
9095
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 if (curbuf->b_p_ts <= 0)
9097 {
9098 errmsg = e_positive;
9099 curbuf->b_p_ts = 8;
9100 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009101 if (p_tm < 0)
9102 {
9103 errmsg = e_positive;
9104 p_tm = 0;
9105 }
9106 if ((curwin->w_p_scr <= 0
9107 || (curwin->w_p_scr > curwin->w_height
9108 && curwin->w_height > 0))
9109 && full_screen)
9110 {
9111 if (pp == &(curwin->w_p_scr))
9112 {
9113 if (curwin->w_p_scr != 0)
9114 errmsg = e_scroll;
9115 win_comp_scroll(curwin);
9116 }
9117 /* If 'scroll' became invalid because of a side effect silently adjust
9118 * it. */
9119 else if (curwin->w_p_scr <= 0)
9120 curwin->w_p_scr = 1;
9121 else /* curwin->w_p_scr > curwin->w_height */
9122 curwin->w_p_scr = curwin->w_height;
9123 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009124 if (p_hi < 0)
9125 {
9126 errmsg = e_positive;
9127 p_hi = 0;
9128 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009129 else if (p_hi > 10000)
9130 {
9131 errmsg = e_invarg;
9132 p_hi = 10000;
9133 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009134 if (p_re < 0 || p_re > 2)
9135 {
9136 errmsg = e_invarg;
9137 p_re = 0;
9138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139 if (p_report < 0)
9140 {
9141 errmsg = e_positive;
9142 p_report = 1;
9143 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009144 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009145 {
9146 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9147 p_sj = Rows / 2;
9148 else
9149 {
9150 errmsg = e_scroll;
9151 p_sj = 1;
9152 }
9153 }
9154 if (p_so < 0 && full_screen)
9155 {
9156 errmsg = e_scroll;
9157 p_so = 0;
9158 }
9159 if (p_siso < 0 && full_screen)
9160 {
9161 errmsg = e_positive;
9162 p_siso = 0;
9163 }
9164#ifdef FEAT_CMDWIN
9165 if (p_cwh < 1)
9166 {
9167 errmsg = e_positive;
9168 p_cwh = 1;
9169 }
9170#endif
9171 if (p_ut < 0)
9172 {
9173 errmsg = e_positive;
9174 p_ut = 2000;
9175 }
9176 if (p_ss < 0)
9177 {
9178 errmsg = e_positive;
9179 p_ss = 0;
9180 }
9181
9182 /* May set global value for local option. */
9183 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9184 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9185
9186 options[opt_idx].flags |= P_WAS_SET;
9187
Bram Moolenaar53744302015-07-17 17:38:22 +02009188#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9189 if (!starting && errmsg == NULL)
9190 {
9191 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009192 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9193 vim_snprintf((char *)buf_new, 10, "%ld", value);
9194 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009195 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9196 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9197 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9198 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9199 reset_v_option_vars();
9200 }
9201#endif
9202
Bram Moolenaar071d4272004-06-13 20:20:40 +00009203 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009204 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009205 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009206 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009207 check_redraw(options[opt_idx].flags);
9208
9209 return errmsg;
9210}
9211
9212/*
9213 * Called after an option changed: check if something needs to be redrawn.
9214 */
9215 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009216check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217{
9218 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009219 int doclear = (flags & P_RCLR) == P_RCLR;
9220 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009221
9222#ifdef FEAT_WINDOWS
9223 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9224 status_redraw_all();
9225#endif
9226
9227 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9228 changed_window_setting();
9229 if (flags & P_RBUF)
9230 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009231 if (flags & P_RWINONLY)
9232 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009233 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009234 redraw_all_later(CLEAR);
9235 else if (all)
9236 redraw_all_later(NOT_VALID);
9237}
9238
9239/*
9240 * Find index for option 'arg'.
9241 * Return -1 if not found.
9242 */
9243 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009244findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009245{
9246 int opt_idx;
9247 char *s, *p;
9248 static short quick_tab[27] = {0, 0}; /* quick access table */
9249 int is_term_opt;
9250
9251 /*
9252 * For first call: Initialize the quick-access table.
9253 * It contains the index for the first option that starts with a certain
9254 * letter. There are 26 letters, plus the first "t_" option.
9255 */
9256 if (quick_tab[1] == 0)
9257 {
9258 p = options[0].fullname;
9259 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9260 {
9261 if (s[0] != p[0])
9262 {
9263 if (s[0] == 't' && s[1] == '_')
9264 quick_tab[26] = opt_idx;
9265 else
9266 quick_tab[CharOrdLow(s[0])] = opt_idx;
9267 }
9268 p = s;
9269 }
9270 }
9271
9272 /*
9273 * Check for name starting with an illegal character.
9274 */
9275#ifdef EBCDIC
9276 if (!islower(arg[0]))
9277#else
9278 if (arg[0] < 'a' || arg[0] > 'z')
9279#endif
9280 return -1;
9281
9282 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9283 if (is_term_opt)
9284 opt_idx = quick_tab[26];
9285 else
9286 opt_idx = quick_tab[CharOrdLow(arg[0])];
9287 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9288 {
9289 if (STRCMP(arg, s) == 0) /* match full name */
9290 break;
9291 }
9292 if (s == NULL && !is_term_opt)
9293 {
9294 opt_idx = quick_tab[CharOrdLow(arg[0])];
9295 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9296 {
9297 s = options[opt_idx].shortname;
9298 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9299 break;
9300 s = NULL;
9301 }
9302 }
9303 if (s == NULL)
9304 opt_idx = -1;
9305 return opt_idx;
9306}
9307
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009308#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009309/*
9310 * Get the value for an option.
9311 *
9312 * Returns:
9313 * Number or Toggle option: 1, *numval gets value.
9314 * String option: 0, *stringval gets allocated string.
9315 * Hidden Number or Toggle option: -1.
9316 * hidden String option: -2.
9317 * unknown option: -3.
9318 */
9319 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009320get_option_value(
9321 char_u *name,
9322 long *numval,
9323 char_u **stringval, /* NULL when only checking existence */
9324 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009325{
9326 int opt_idx;
9327 char_u *varp;
9328
9329 opt_idx = findoption(name);
9330 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009331 {
9332 int key;
9333
9334 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9335 && (key = find_key_option(name)) != 0)
9336 {
9337 char_u key_name[2];
9338 char_u *p;
9339
9340 if (key < 0)
9341 {
9342 key_name[0] = KEY2TERMCAP0(key);
9343 key_name[1] = KEY2TERMCAP1(key);
9344 }
9345 else
9346 {
9347 key_name[0] = KS_KEY;
9348 key_name[1] = (key & 0xff);
9349 }
9350 p = find_termcode(key_name);
9351 if (p != NULL)
9352 {
9353 if (stringval != NULL)
9354 *stringval = vim_strsave(p);
9355 return 0;
9356 }
9357 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009360
9361 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9362
9363 if (options[opt_idx].flags & P_STRING)
9364 {
9365 if (varp == NULL) /* hidden option */
9366 return -2;
9367 if (stringval != NULL)
9368 {
9369#ifdef FEAT_CRYPT
9370 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009371 if ((char_u **)varp == &curbuf->b_p_key
9372 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009373 *stringval = vim_strsave((char_u *)"*****");
9374 else
9375#endif
9376 *stringval = vim_strsave(*(char_u **)(varp));
9377 }
9378 return 0;
9379 }
9380
9381 if (varp == NULL) /* hidden option */
9382 return -1;
9383 if (options[opt_idx].flags & P_NUM)
9384 *numval = *(long *)varp;
9385 else
9386 {
9387 /* Special case: 'modified' is b_changed, but we also want to consider
9388 * it set when 'ff' or 'fenc' changed. */
9389 if ((int *)varp == &curbuf->b_changed)
9390 *numval = curbufIsChanged();
9391 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009392 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009393 }
9394 return 1;
9395}
9396#endif
9397
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009398#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009399/*
9400 * Returns the option attributes and its value. Unlike the above function it
9401 * will return either global value or local value of the option depending on
9402 * what was requested, but it will never return global value if it was
9403 * requested to return local one and vice versa. Neither it will return
9404 * buffer-local value if it was requested to return window-local one.
9405 *
9406 * Pretends that option is absent if it is not present in the requested scope
9407 * (i.e. has no global, window-local or buffer-local value depending on
9408 * opt_type). Uses
9409 *
9410 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009411 * 0 hidden or unknown option, also option that does not have requested
9412 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009413 * see SOPT_* in vim.h for other flags
9414 *
9415 * Possible opt_type values: see SREQ_* in vim.h
9416 */
9417 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009418get_option_value_strict(
9419 char_u *name,
9420 long *numval,
9421 char_u **stringval, /* NULL when only obtaining attributes */
9422 int opt_type,
9423 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009424{
9425 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009426 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009427 struct vimoption *p;
9428 int r = 0;
9429
9430 opt_idx = findoption(name);
9431 if (opt_idx < 0)
9432 return 0;
9433
9434 p = &(options[opt_idx]);
9435
9436 /* Hidden option */
9437 if (p->var == NULL)
9438 return 0;
9439
9440 if (p->flags & P_BOOL)
9441 r |= SOPT_BOOL;
9442 else if (p->flags & P_NUM)
9443 r |= SOPT_NUM;
9444 else if (p->flags & P_STRING)
9445 r |= SOPT_STRING;
9446
9447 if (p->indir == PV_NONE)
9448 {
9449 if (opt_type == SREQ_GLOBAL)
9450 r |= SOPT_GLOBAL;
9451 else
9452 return 0; /* Did not request global-only option */
9453 }
9454 else
9455 {
9456 if (p->indir & PV_BOTH)
9457 r |= SOPT_GLOBAL;
9458 else if (opt_type == SREQ_GLOBAL)
9459 return 0; /* Requested global option */
9460
9461 if (p->indir & PV_WIN)
9462 {
9463 if (opt_type == SREQ_BUF)
9464 return 0; /* Did not request window-local option */
9465 else
9466 r |= SOPT_WIN;
9467 }
9468 else if (p->indir & PV_BUF)
9469 {
9470 if (opt_type == SREQ_WIN)
9471 return 0; /* Did not request buffer-local option */
9472 else
9473 r |= SOPT_BUF;
9474 }
9475 }
9476
9477 if (stringval == NULL)
9478 return r;
9479
9480 if (opt_type == SREQ_GLOBAL)
9481 varp = p->var;
9482 else
9483 {
9484 if (opt_type == SREQ_BUF)
9485 {
9486 /* Special case: 'modified' is b_changed, but we also want to
9487 * consider it set when 'ff' or 'fenc' changed. */
9488 if (p->indir == PV_MOD)
9489 {
9490 *numval = bufIsChanged((buf_T *) from);
9491 varp = NULL;
9492 }
9493#ifdef FEAT_CRYPT
9494 else if (p->indir == PV_KEY)
9495 {
9496 /* never return the value of the crypt key */
9497 *stringval = NULL;
9498 varp = NULL;
9499 }
9500#endif
9501 else
9502 {
9503 aco_save_T aco;
9504 aucmd_prepbuf(&aco, (buf_T *) from);
9505 varp = get_varp(p);
9506 aucmd_restbuf(&aco);
9507 }
9508 }
9509 else if (opt_type == SREQ_WIN)
9510 {
9511 win_T *save_curwin;
9512 save_curwin = curwin;
9513 curwin = (win_T *) from;
9514 curbuf = curwin->w_buffer;
9515 varp = get_varp(p);
9516 curwin = save_curwin;
9517 curbuf = curwin->w_buffer;
9518 }
9519 if (varp == p->var)
9520 return (r | SOPT_UNSET);
9521 }
9522
9523 if (varp != NULL)
9524 {
9525 if (p->flags & P_STRING)
9526 *stringval = vim_strsave(*(char_u **)(varp));
9527 else if (p->flags & P_NUM)
9528 *numval = *(long *) varp;
9529 else
9530 *numval = *(int *)varp;
9531 }
9532
9533 return r;
9534}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009535
9536/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009537 * Iterate over options. First argument is a pointer to a pointer to a
9538 * structure inside options[] array, second is option type like in the above
9539 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009540 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009541 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009542 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009543 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009544 * first argument to NULL.
9545 *
9546 * Returns full option name for current option on each call.
9547 */
9548 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009549option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009550{
9551 struct vimoption *ret = NULL;
9552 do
9553 {
9554 if (*option == NULL)
9555 *option = (void *) options;
9556 else if (((struct vimoption *) (*option))->fullname == NULL)
9557 {
9558 *option = NULL;
9559 return NULL;
9560 }
9561 else
9562 *option = (void *) (((struct vimoption *) (*option)) + 1);
9563
9564 ret = ((struct vimoption *) (*option));
9565
9566 /* Hidden option */
9567 if (ret->var == NULL)
9568 {
9569 ret = NULL;
9570 continue;
9571 }
9572
9573 switch (opt_type)
9574 {
9575 case SREQ_GLOBAL:
9576 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9577 ret = NULL;
9578 break;
9579 case SREQ_BUF:
9580 if (!(ret->indir & PV_BUF))
9581 ret = NULL;
9582 break;
9583 case SREQ_WIN:
9584 if (!(ret->indir & PV_WIN))
9585 ret = NULL;
9586 break;
9587 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009588 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009589 return NULL;
9590 }
9591 }
9592 while (ret == NULL);
9593
9594 return (char_u *)ret->fullname;
9595}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009596#endif
9597
Bram Moolenaar071d4272004-06-13 20:20:40 +00009598/*
9599 * Set the value of option "name".
9600 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009601 *
9602 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009603 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009604 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009605set_option_value(
9606 char_u *name,
9607 long number,
9608 char_u *string,
9609 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009610{
9611 int opt_idx;
9612 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009613 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009614
9615 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009616 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009617 {
9618 int key;
9619
9620 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9621 && (key = find_key_option(name)) != 0)
9622 {
9623 char_u key_name[2];
9624
9625 if (key < 0)
9626 {
9627 key_name[0] = KEY2TERMCAP0(key);
9628 key_name[1] = KEY2TERMCAP1(key);
9629 }
9630 else
9631 {
9632 key_name[0] = KS_KEY;
9633 key_name[1] = (key & 0xff);
9634 }
9635 add_termcode(key_name, string, FALSE);
9636 if (full_screen)
9637 ttest(FALSE);
9638 redraw_all_later(CLEAR);
9639 return NULL;
9640 }
9641
Bram Moolenaar071d4272004-06-13 20:20:40 +00009642 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009643 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644 else
9645 {
9646 flags = options[opt_idx].flags;
9647#ifdef HAVE_SANDBOX
9648 /* Disallow changing some options in the sandbox */
9649 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009650 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009652 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009655 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009656 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657 else
9658 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009659 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660 if (varp != NULL) /* hidden option is not changed */
9661 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009662 if (number == 0 && string != NULL)
9663 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009664 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009665
9666 /* Either we are given a string or we are setting option
9667 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009668 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009669 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009670 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009671 {
9672 /* There's another character after zeros or the string
9673 * is empty. In both cases, we are trying to set a
9674 * num option using a string. */
9675 EMSG3(_("E521: Number required: &%s = '%s'"),
9676 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009677 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009678
9679 }
9680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009682 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009683 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009684 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009685 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009686 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009687 }
9688 }
9689 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009690 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009691}
9692
9693/*
9694 * Get the terminal code for a terminal option.
9695 * Returns NULL when not found.
9696 */
9697 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009698get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009699{
9700 int opt_idx;
9701 char_u *varp;
9702
9703 if (tname[0] != 't' || tname[1] != '_' ||
9704 tname[2] == NUL || tname[3] == NUL)
9705 return NULL;
9706 if ((opt_idx = findoption(tname)) >= 0)
9707 {
9708 varp = get_varp(&(options[opt_idx]));
9709 if (varp != NULL)
9710 varp = *(char_u **)(varp);
9711 return varp;
9712 }
9713 return find_termcode(tname + 2);
9714}
9715
9716 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009717get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009718{
9719 int i;
9720
9721 i = findoption((char_u *)"hl");
9722 if (i >= 0)
9723 return options[i].def_val[VI_DEFAULT];
9724 return (char_u *)NULL;
9725}
9726
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009727#if defined(FEAT_MBYTE) || defined(PROTO)
9728 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009729get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009730{
9731 int i;
9732
9733 i = findoption((char_u *)"enc");
9734 if (i >= 0)
9735 return options[i].def_val[VI_DEFAULT];
9736 return (char_u *)NULL;
9737}
9738#endif
9739
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740/*
9741 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9742 */
9743 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009744find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009745{
9746 int key;
9747 int modifiers;
9748
9749 /*
9750 * Don't use get_special_key_code() for t_xx, we don't want it to call
9751 * add_termcap_entry().
9752 */
9753 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9754 key = TERMCAP2KEY(arg[2], arg[3]);
9755 else
9756 {
9757 --arg; /* put arg at the '<' */
9758 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009759 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760 if (modifiers) /* can't handle modifiers here */
9761 key = 0;
9762 }
9763 return key;
9764}
9765
9766/*
9767 * if 'all' == 0: show changed options
9768 * if 'all' == 1: show all normal options
9769 * if 'all' == 2: show all terminal options
9770 */
9771 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009772showoptions(
9773 int all,
9774 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009775{
9776 struct vimoption *p;
9777 int col;
9778 int isterm;
9779 char_u *varp;
9780 struct vimoption **items;
9781 int item_count;
9782 int run;
9783 int row, rows;
9784 int cols;
9785 int i;
9786 int len;
9787
9788#define INC 20
9789#define GAP 3
9790
9791 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9792 PARAM_COUNT));
9793 if (items == NULL)
9794 return;
9795
9796 /* Highlight title */
9797 if (all == 2)
9798 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9799 else if (opt_flags & OPT_GLOBAL)
9800 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9801 else if (opt_flags & OPT_LOCAL)
9802 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9803 else
9804 MSG_PUTS_TITLE(_("\n--- Options ---"));
9805
9806 /*
9807 * do the loop two times:
9808 * 1. display the short items
9809 * 2. display the long items (only strings and numbers)
9810 */
9811 for (run = 1; run <= 2 && !got_int; ++run)
9812 {
9813 /*
9814 * collect the items in items[]
9815 */
9816 item_count = 0;
9817 for (p = &options[0]; p->fullname != NULL; p++)
9818 {
9819 varp = NULL;
9820 isterm = istermoption(p);
9821 if (opt_flags != 0)
9822 {
9823 if (p->indir != PV_NONE && !isterm)
9824 varp = get_varp_scope(p, opt_flags);
9825 }
9826 else
9827 varp = get_varp(p);
9828 if (varp != NULL
9829 && ((all == 2 && isterm)
9830 || (all == 1 && !isterm)
9831 || (all == 0 && !optval_default(p, varp))))
9832 {
9833 if (p->flags & P_BOOL)
9834 len = 1; /* a toggle option fits always */
9835 else
9836 {
9837 option_value2string(p, opt_flags);
9838 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9839 }
9840 if ((len <= INC - GAP && run == 1) ||
9841 (len > INC - GAP && run == 2))
9842 items[item_count++] = p;
9843 }
9844 }
9845
9846 /*
9847 * display the items
9848 */
9849 if (run == 1)
9850 {
9851 cols = (Columns + GAP - 3) / INC;
9852 if (cols == 0)
9853 cols = 1;
9854 rows = (item_count + cols - 1) / cols;
9855 }
9856 else /* run == 2 */
9857 rows = item_count;
9858 for (row = 0; row < rows && !got_int; ++row)
9859 {
9860 msg_putchar('\n'); /* go to next line */
9861 if (got_int) /* 'q' typed in more */
9862 break;
9863 col = 0;
9864 for (i = row; i < item_count; i += rows)
9865 {
9866 msg_col = col; /* make columns */
9867 showoneopt(items[i], opt_flags);
9868 col += INC;
9869 }
9870 out_flush();
9871 ui_breakcheck();
9872 }
9873 }
9874 vim_free(items);
9875}
9876
9877/*
9878 * Return TRUE if option "p" has its default value.
9879 */
9880 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009881optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009882{
9883 int dvi;
9884
9885 if (varp == NULL)
9886 return TRUE; /* hidden option is always at default */
9887 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9888 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009889 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009890 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009891 /* the cast to long is required for Manx C, long_i is
9892 * needed for MSVC */
9893 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894 /* P_STRING */
9895 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9896}
9897
9898/*
9899 * showoneopt: show the value of one option
9900 * must not be called with a hidden option!
9901 */
9902 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009903showoneopt(
9904 struct vimoption *p,
9905 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009906{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009907 char_u *varp;
9908 int save_silent = silent_mode;
9909
9910 silent_mode = FALSE;
9911 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912
9913 varp = get_varp_scope(p, opt_flags);
9914
9915 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9916 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9917 ? !curbufIsChanged() : !*(int *)varp))
9918 MSG_PUTS("no");
9919 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9920 MSG_PUTS("--");
9921 else
9922 MSG_PUTS(" ");
9923 MSG_PUTS(p->fullname);
9924 if (!(p->flags & P_BOOL))
9925 {
9926 msg_putchar('=');
9927 /* put value string in NameBuff */
9928 option_value2string(p, opt_flags);
9929 msg_outtrans(NameBuff);
9930 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009931
9932 silent_mode = save_silent;
9933 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009934}
9935
9936/*
9937 * Write modified options as ":set" commands to a file.
9938 *
9939 * There are three values for "opt_flags":
9940 * OPT_GLOBAL: Write global option values and fresh values of
9941 * buffer-local options (used for start of a session
9942 * file).
9943 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9944 * curwin (used for a vimrc file).
9945 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9946 * and local values for window-local options of
9947 * curwin. Local values are also written when at the
9948 * default value, because a modeline or autocommand
9949 * may have set them when doing ":edit file" and the
9950 * user has set them back at the default or fresh
9951 * value.
9952 * When "local_only" is TRUE, don't write fresh
9953 * values, only local values (for ":mkview").
9954 * (fresh value = value used for a new buffer or window for a local option).
9955 *
9956 * Return FAIL on error, OK otherwise.
9957 */
9958 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009959makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009960{
9961 struct vimoption *p;
9962 char_u *varp; /* currently used value */
9963 char_u *varp_fresh; /* local value */
9964 char_u *varp_local = NULL; /* fresh value */
9965 char *cmd;
9966 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009967 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009968
9969 /*
9970 * The options that don't have a default (terminal name, columns, lines)
9971 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009972 * Do the loop over "options[]" twice: once for options with the
9973 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009975 for (pri = 1; pri >= 0; --pri)
9976 {
9977 for (p = &options[0]; !istermoption(p); p++)
9978 if (!(p->flags & P_NO_MKRC)
9979 && !istermoption(p)
9980 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981 {
9982 /* skip global option when only doing locals */
9983 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9984 continue;
9985
9986 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9987 * file, they are always buffer-specific. */
9988 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9989 continue;
9990
9991 /* Global values are only written when not at the default value. */
9992 varp = get_varp_scope(p, opt_flags);
9993 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9994 continue;
9995
9996 round = 2;
9997 if (p->indir != PV_NONE)
9998 {
9999 if (p->var == VAR_WIN)
10000 {
10001 /* skip window-local option when only doing globals */
10002 if (!(opt_flags & OPT_LOCAL))
10003 continue;
10004 /* When fresh value of window-local option is not at the
10005 * default, need to write it too. */
10006 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10007 {
10008 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10009 if (!optval_default(p, varp_fresh))
10010 {
10011 round = 1;
10012 varp_local = varp;
10013 varp = varp_fresh;
10014 }
10015 }
10016 }
10017 }
10018
10019 /* Round 1: fresh value for window-local options.
10020 * Round 2: other values */
10021 for ( ; round <= 2; varp = varp_local, ++round)
10022 {
10023 if (round == 1 || (opt_flags & OPT_GLOBAL))
10024 cmd = "set";
10025 else
10026 cmd = "setlocal";
10027
10028 if (p->flags & P_BOOL)
10029 {
10030 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10031 return FAIL;
10032 }
10033 else if (p->flags & P_NUM)
10034 {
10035 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10036 return FAIL;
10037 }
10038 else /* P_STRING */
10039 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010040#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10041 int do_endif = FALSE;
10042
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043 /* Don't set 'syntax' and 'filetype' again if the value is
10044 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010045 if (
10046# if defined(FEAT_SYN_HL)
10047 p->indir == PV_SYN
10048# if defined(FEAT_AUTOCMD)
10049 ||
10050# endif
10051# endif
10052# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010053 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010054# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010055 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056 {
10057 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10058 *(char_u **)(varp)) < 0
10059 || put_eol(fd) < 0)
10060 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010061 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010063#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010064 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10065 (p->flags & P_EXPAND) != 0) == FAIL)
10066 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010067#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10068 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010069 {
10070 if (put_line(fd, "endif") == FAIL)
10071 return FAIL;
10072 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010074 }
10075 }
10076 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010077 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010078 return OK;
10079}
10080
10081#if defined(FEAT_FOLDING) || defined(PROTO)
10082/*
10083 * Generate set commands for the local fold options only. Used when
10084 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10085 */
10086 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010087makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010088{
10089 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10090# ifdef FEAT_EVAL
10091 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10092 == FAIL
10093# endif
10094 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10095 == FAIL
10096 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10097 == FAIL
10098 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10099 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10100 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10101 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10102 )
10103 return FAIL;
10104
10105 return OK;
10106}
10107#endif
10108
10109 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010110put_setstring(
10111 FILE *fd,
10112 char *cmd,
10113 char *name,
10114 char_u **valuep,
10115 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116{
10117 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010118 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119
10120 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10121 return FAIL;
10122 if (*valuep != NULL)
10123 {
10124 /* Output 'pastetoggle' as key names. For other
10125 * options some characters have to be escaped with
10126 * CTRL-V or backslash */
10127 if (valuep == &p_pt)
10128 {
10129 s = *valuep;
10130 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010131 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010132 return FAIL;
10133 }
10134 else if (expand)
10135 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010136 buf = alloc(MAXPATHL);
10137 if (buf == NULL)
10138 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10140 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010141 {
10142 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010144 }
10145 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146 }
10147 else if (put_escstr(fd, *valuep, 2) == FAIL)
10148 return FAIL;
10149 }
10150 if (put_eol(fd) < 0)
10151 return FAIL;
10152 return OK;
10153}
10154
10155 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010156put_setnum(
10157 FILE *fd,
10158 char *cmd,
10159 char *name,
10160 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161{
10162 long wc;
10163
10164 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10165 return FAIL;
10166 if (wc_use_keyname((char_u *)valuep, &wc))
10167 {
10168 /* print 'wildchar' and 'wildcharm' as a key name */
10169 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10170 return FAIL;
10171 }
10172 else if (fprintf(fd, "%ld", *valuep) < 0)
10173 return FAIL;
10174 if (put_eol(fd) < 0)
10175 return FAIL;
10176 return OK;
10177}
10178
10179 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010180put_setbool(
10181 FILE *fd,
10182 char *cmd,
10183 char *name,
10184 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185{
Bram Moolenaar893de922007-10-02 18:40:57 +000010186 if (value < 0) /* global/local option using global value */
10187 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10189 || put_eol(fd) < 0)
10190 return FAIL;
10191 return OK;
10192}
10193
10194/*
10195 * Clear all the terminal options.
10196 * If the option has been allocated, free the memory.
10197 * Terminal options are never hidden or indirect.
10198 */
10199 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010200clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 /*
10203 * Reset a few things before clearing the old options. This may cause
10204 * outputting a few things that the terminal doesn't understand, but the
10205 * screen will be cleared later, so this is OK.
10206 */
10207#ifdef FEAT_MOUSE_TTY
10208 mch_setmouse(FALSE); /* switch mouse off */
10209#endif
10210#ifdef FEAT_TITLE
10211 mch_restore_title(3); /* restore window titles */
10212#endif
10213#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10214 /* When starting the GUI close the display opened for the clipboard.
10215 * After restoring the title, because that will need the display. */
10216 if (gui.starting)
10217 clear_xterm_clip();
10218#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010219 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010221 free_termoptions();
10222}
10223
10224 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010225free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010226{
10227 struct vimoption *p;
10228
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229 for (p = &options[0]; p->fullname != NULL; p++)
10230 if (istermoption(p))
10231 {
10232 if (p->flags & P_ALLOCED)
10233 free_string_option(*(char_u **)(p->var));
10234 if (p->flags & P_DEF_ALLOCED)
10235 free_string_option(p->def_val[VI_DEFAULT]);
10236 *(char_u **)(p->var) = empty_option;
10237 p->def_val[VI_DEFAULT] = empty_option;
10238 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10239 }
10240 clear_termcodes();
10241}
10242
10243/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010244 * Free the string for one term option, if it was allocated.
10245 * Set the string to empty_option and clear allocated flag.
10246 * "var" points to the option value.
10247 */
10248 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010249free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010250{
10251 struct vimoption *p;
10252
10253 for (p = &options[0]; p->fullname != NULL; p++)
10254 if (p->var == var)
10255 {
10256 if (p->flags & P_ALLOCED)
10257 free_string_option(*(char_u **)(p->var));
10258 *(char_u **)(p->var) = empty_option;
10259 p->flags &= ~P_ALLOCED;
10260 break;
10261 }
10262}
10263
10264/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265 * Set the terminal option defaults to the current value.
10266 * Used after setting the terminal name.
10267 */
10268 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010269set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270{
10271 struct vimoption *p;
10272
10273 for (p = &options[0]; p->fullname != NULL; p++)
10274 {
10275 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10276 {
10277 if (p->flags & P_DEF_ALLOCED)
10278 {
10279 free_string_option(p->def_val[VI_DEFAULT]);
10280 p->flags &= ~P_DEF_ALLOCED;
10281 }
10282 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10283 if (p->flags & P_ALLOCED)
10284 {
10285 p->flags |= P_DEF_ALLOCED;
10286 p->flags &= ~P_ALLOCED; /* don't free the value now */
10287 }
10288 }
10289 }
10290}
10291
10292/*
10293 * return TRUE if 'p' starts with 't_'
10294 */
10295 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010296istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297{
10298 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10299}
10300
10301/*
10302 * Compute columns for ruler and shown command. 'sc_col' is also used to
10303 * decide what the maximum length of a message on the status line can be.
10304 * If there is a status line for the last window, 'sc_col' is independent
10305 * of 'ru_col'.
10306 */
10307
10308#define COL_RULER 17 /* columns needed by standard ruler */
10309
10310 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010311comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312{
10313#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010314 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315
10316 sc_col = 0;
10317 ru_col = 0;
10318 if (p_ru)
10319 {
10320#ifdef FEAT_STL_OPT
10321 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10322#else
10323 ru_col = COL_RULER + 1;
10324#endif
10325 /* no last status line, adjust sc_col */
10326 if (!last_has_status)
10327 sc_col = ru_col;
10328 }
10329 if (p_sc)
10330 {
10331 sc_col += SHOWCMD_COLS;
10332 if (!p_ru || last_has_status) /* no need for separating space */
10333 ++sc_col;
10334 }
10335 sc_col = Columns - sc_col;
10336 ru_col = Columns - ru_col;
10337 if (sc_col <= 0) /* screen too narrow, will become a mess */
10338 sc_col = 1;
10339 if (ru_col <= 0)
10340 ru_col = 1;
10341#else
10342 sc_col = Columns;
10343 ru_col = Columns;
10344#endif
10345}
10346
10347/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010348 * Unset local option value, similar to ":set opt<".
10349 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010350 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010351unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010352{
10353 struct vimoption *p;
10354 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010355 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010356
10357 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010358 if (opt_idx < 0)
10359 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010360 p = &(options[opt_idx]);
10361
10362 switch ((int)p->indir)
10363 {
10364 /* global option with local value: use local value if it's been set */
10365 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010366 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010367 break;
10368 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010369 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010370 break;
10371 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010372 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010373 break;
10374 case PV_AR:
10375 buf->b_p_ar = -1;
10376 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010377 case PV_BKC:
10378 clear_string_option(&buf->b_p_bkc);
10379 buf->b_bkc_flags = 0;
10380 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010381 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010382 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010383 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010384 case PV_TC:
10385 clear_string_option(&buf->b_p_tc);
10386 buf->b_tc_flags = 0;
10387 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010388#ifdef FEAT_FIND_ID
10389 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010390 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010391 break;
10392 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010393 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010394 break;
10395#endif
10396#ifdef FEAT_INS_EXPAND
10397 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010398 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010399 break;
10400 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010401 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010402 break;
10403#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010404 case PV_FP:
10405 clear_string_option(&buf->b_p_fp);
10406 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010407#ifdef FEAT_QUICKFIX
10408 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010409 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010410 break;
10411 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010412 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413 break;
10414 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010415 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010416 break;
10417#endif
10418#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10419 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010420 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010421 break;
10422#endif
10423#if defined(FEAT_CRYPT)
10424 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010425 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010426 break;
10427#endif
10428#ifdef FEAT_STL_OPT
10429 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010430 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 break;
10432#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010433 case PV_UL:
10434 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10435 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010436#ifdef FEAT_LISP
10437 case PV_LW:
10438 clear_string_option(&buf->b_p_lw);
10439 break;
10440#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010441#ifdef FEAT_MBYTE
10442 case PV_MENC:
10443 clear_string_option(&buf->b_p_menc);
10444 break;
10445#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010446 }
10447}
10448
10449/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010450 * Get pointer to option variable, depending on local or global scope.
10451 */
10452 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010453get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010454{
10455 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10456 {
10457 if (p->var == VAR_WIN)
10458 return (char_u *)GLOBAL_WO(get_varp(p));
10459 return p->var;
10460 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010461 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462 {
10463 switch ((int)p->indir)
10464 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010465 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010467 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10468 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10469 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010470#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010471 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10472 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10473 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010474 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010475 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010476 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010477#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010478 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10479 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480#endif
10481#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010482 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10483 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010485#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10486 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10487#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010488#if defined(FEAT_CRYPT)
10489 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10490#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010491#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010492 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010493#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010494 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010495#ifdef FEAT_LISP
10496 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10497#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010498 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010499#ifdef FEAT_MBYTE
10500 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10501#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502 }
10503 return NULL; /* "cannot happen" */
10504 }
10505 return get_varp(p);
10506}
10507
10508/*
10509 * Get pointer to option variable.
10510 */
10511 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010512get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513{
10514 /* hidden option, always return NULL */
10515 if (p->var == NULL)
10516 return NULL;
10517
10518 switch ((int)p->indir)
10519 {
10520 case PV_NONE: return p->var;
10521
10522 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010523 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010525 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010527 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010529 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010531 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010533 case PV_TC: return *curbuf->b_p_tc != NUL
10534 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010535 case PV_BKC: return *curbuf->b_p_bkc != NUL
10536 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010538 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010540 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10542#endif
10543#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010544 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010546 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10548#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010549 case PV_FP: return *curbuf->b_p_fp != NUL
10550 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010552 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010554 case PV_GP: return *curbuf->b_p_gp != NUL
10555 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10556 case PV_MP: return *curbuf->b_p_mp != NUL
10557 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010559#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10560 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10561 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10562#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010563#if defined(FEAT_CRYPT)
10564 case PV_CM: return *curbuf->b_p_cm != NUL
10565 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10566#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010567#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010568 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010569 ? (char_u *)&(curwin->w_p_stl) : p->var;
10570#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010571 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10572 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010573#ifdef FEAT_LISP
10574 case PV_LW: return *curbuf->b_p_lw != NUL
10575 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10576#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010577#ifdef FEAT_MBYTE
10578 case PV_MENC: return *curbuf->b_p_menc != NUL
10579 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581
10582#ifdef FEAT_ARABIC
10583 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10584#endif
10585 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010586#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010587 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10588#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010589#ifdef FEAT_SYN_HL
10590 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10591 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010592 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010593#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594#ifdef FEAT_DIFF
10595 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10596#endif
10597#ifdef FEAT_FOLDING
10598 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10599 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10600 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10601 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10602 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10603 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10604 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10605# ifdef FEAT_EVAL
10606 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10607 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10608# endif
10609 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10610#endif
10611 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010612 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010613#ifdef FEAT_LINEBREAK
10614 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10615#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010616#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010618 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10619#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10621 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10622#endif
10623#ifdef FEAT_RIGHTLEFT
10624 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10625 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10626#endif
10627 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10628 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10629#ifdef FEAT_LINEBREAK
10630 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010631 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10632 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633#endif
10634#ifdef FEAT_SCROLLBIND
10635 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10636#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010637#ifdef FEAT_CURSORBIND
10638 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10639#endif
10640#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010641 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10642 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010643#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644
10645 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10646 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10647#ifdef FEAT_MBYTE
10648 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10649#endif
10650#if defined(FEAT_QUICKFIX)
10651 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10652 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10653#endif
10654 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10655 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10656#ifdef FEAT_CINDENT
10657 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10658 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10659 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10660#endif
10661#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10662 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10663#endif
10664#ifdef FEAT_COMMENTS
10665 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10666#endif
10667#ifdef FEAT_FOLDING
10668 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10669#endif
10670#ifdef FEAT_INS_EXPAND
10671 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10672#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010673#ifdef FEAT_COMPL_FUNC
10674 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010675 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010677 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010678 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10680#ifdef FEAT_MBYTE
10681 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10682#endif
10683 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10684#ifdef FEAT_AUTOCMD
10685 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10686#endif
10687 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010688 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10690 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10691 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10692 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10693#ifdef FEAT_FIND_ID
10694# ifdef FEAT_EVAL
10695 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10696# endif
10697#endif
10698#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10699 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10700 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10701#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010702#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010703 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705#ifdef FEAT_CRYPT
10706 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10707#endif
10708#ifdef FEAT_LISP
10709 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10710#endif
10711 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10712 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10713 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10714 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10715 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010717#ifdef FEAT_TEXTOBJ
10718 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10721#ifdef FEAT_SMARTINDENT
10722 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10723#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010724 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010725 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10726#ifdef FEAT_SEARCHPATH
10727 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10728#endif
10729 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10730#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010731 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010732 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10733#endif
10734#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010735 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10736 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10737 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738#endif
10739 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10740 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10741 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10742 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010743#ifdef FEAT_PERSISTENT_UNDO
10744 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10747#ifdef FEAT_KEYMAP
10748 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10749#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010750#ifdef FEAT_SIGNS
10751 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10752#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010753 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754 }
10755 /* always return a valid pointer to avoid a crash! */
10756 return (char_u *)&(curbuf->b_p_wm);
10757}
10758
10759/*
10760 * Get the value of 'equalprg', either the buffer-local one or the global one.
10761 */
10762 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010763get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764{
10765 if (*curbuf->b_p_ep == NUL)
10766 return p_ep;
10767 return curbuf->b_p_ep;
10768}
10769
10770#if defined(FEAT_WINDOWS) || defined(PROTO)
10771/*
10772 * Copy options from one window to another.
10773 * Used when splitting a window.
10774 */
10775 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010776win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777{
10778 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10779 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10780# ifdef FEAT_RIGHTLEFT
10781# ifdef FEAT_FKMAP
10782 /* Is this right? */
10783 wp_to->w_farsi = wp_from->w_farsi;
10784# endif
10785# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010786#if defined(FEAT_LINEBREAK)
10787 briopt_check(wp_to);
10788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789}
10790#endif
10791
10792/*
10793 * Copy the options from one winopt_T to another.
10794 * Doesn't free the old option values in "to", use clear_winopt() for that.
10795 * The 'scroll' option is not copied, because it depends on the window height.
10796 * The 'previewwindow' option is reset, there can be only one preview window.
10797 */
10798 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010799copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800{
10801#ifdef FEAT_ARABIC
10802 to->wo_arab = from->wo_arab;
10803#endif
10804 to->wo_list = from->wo_list;
10805 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010806 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010807#ifdef FEAT_LINEBREAK
10808 to->wo_nuw = from->wo_nuw;
10809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810#ifdef FEAT_RIGHTLEFT
10811 to->wo_rl = from->wo_rl;
10812 to->wo_rlc = vim_strsave(from->wo_rlc);
10813#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010814#ifdef FEAT_STL_OPT
10815 to->wo_stl = vim_strsave(from->wo_stl);
10816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010818#ifdef FEAT_DIFF
10819 to->wo_wrap_save = from->wo_wrap_save;
10820#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821#ifdef FEAT_LINEBREAK
10822 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010823 to->wo_bri = from->wo_bri;
10824 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825#endif
10826#ifdef FEAT_SCROLLBIND
10827 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010828 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010829#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010830#ifdef FEAT_CURSORBIND
10831 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010832 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010833#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010834#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010835 to->wo_spell = from->wo_spell;
10836#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010837#ifdef FEAT_SYN_HL
10838 to->wo_cuc = from->wo_cuc;
10839 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010840 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010841#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842#ifdef FEAT_DIFF
10843 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010844 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010846#ifdef FEAT_CONCEAL
10847 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010848 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010849#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850#ifdef FEAT_FOLDING
10851 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010852 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010854 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855 to->wo_fdi = vim_strsave(from->wo_fdi);
10856 to->wo_fml = from->wo_fml;
10857 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010858 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010860 to->wo_fdm_save = from->wo_diff_saved
10861 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862 to->wo_fdn = from->wo_fdn;
10863# ifdef FEAT_EVAL
10864 to->wo_fde = vim_strsave(from->wo_fde);
10865 to->wo_fdt = vim_strsave(from->wo_fdt);
10866# endif
10867 to->wo_fmr = vim_strsave(from->wo_fmr);
10868#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010869#ifdef FEAT_SIGNS
10870 to->wo_scl = vim_strsave(from->wo_scl);
10871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872 check_winopt(to); /* don't want NULL pointers */
10873}
10874
10875/*
10876 * Check string options in a window for a NULL value.
10877 */
10878 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010879check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880{
10881 check_winopt(&win->w_onebuf_opt);
10882 check_winopt(&win->w_allbuf_opt);
10883}
10884
10885/*
10886 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10887 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010888 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010889check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890{
10891#ifdef FEAT_FOLDING
10892 check_string_option(&wop->wo_fdi);
10893 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010894 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895# ifdef FEAT_EVAL
10896 check_string_option(&wop->wo_fde);
10897 check_string_option(&wop->wo_fdt);
10898# endif
10899 check_string_option(&wop->wo_fmr);
10900#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010901#ifdef FEAT_SIGNS
10902 check_string_option(&wop->wo_scl);
10903#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904#ifdef FEAT_RIGHTLEFT
10905 check_string_option(&wop->wo_rlc);
10906#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010907#ifdef FEAT_STL_OPT
10908 check_string_option(&wop->wo_stl);
10909#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010910#ifdef FEAT_SYN_HL
10911 check_string_option(&wop->wo_cc);
10912#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010913#ifdef FEAT_CONCEAL
10914 check_string_option(&wop->wo_cocu);
10915#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010916#ifdef FEAT_LINEBREAK
10917 check_string_option(&wop->wo_briopt);
10918#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010919}
10920
10921/*
10922 * Free the allocated memory inside a winopt_T.
10923 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010925clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010926{
10927#ifdef FEAT_FOLDING
10928 clear_string_option(&wop->wo_fdi);
10929 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010930 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931# ifdef FEAT_EVAL
10932 clear_string_option(&wop->wo_fde);
10933 clear_string_option(&wop->wo_fdt);
10934# endif
10935 clear_string_option(&wop->wo_fmr);
10936#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010937#ifdef FEAT_SIGNS
10938 clear_string_option(&wop->wo_scl);
10939#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010940#ifdef FEAT_LINEBREAK
10941 clear_string_option(&wop->wo_briopt);
10942#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943#ifdef FEAT_RIGHTLEFT
10944 clear_string_option(&wop->wo_rlc);
10945#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010946#ifdef FEAT_STL_OPT
10947 clear_string_option(&wop->wo_stl);
10948#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010949#ifdef FEAT_SYN_HL
10950 clear_string_option(&wop->wo_cc);
10951#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010952#ifdef FEAT_CONCEAL
10953 clear_string_option(&wop->wo_cocu);
10954#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010955}
10956
10957/*
10958 * Copy global option values to local options for one buffer.
10959 * Used when creating a new buffer and sometimes when entering a buffer.
10960 * flags:
10961 * BCO_ENTER We will enter the buf buffer.
10962 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10963 * appropriate.
10964 * BCO_NOHELP Don't copy the values to a help buffer.
10965 */
10966 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010967buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010968{
10969 int should_copy = TRUE;
10970 char_u *save_p_isk = NULL; /* init for GCC */
10971 int dont_do_help;
10972 int did_isk = FALSE;
10973
10974 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975 * Skip this when the option defaults have not been set yet. Happens when
10976 * main() allocates the first buffer.
10977 */
10978 if (p_cpo != NULL)
10979 {
10980 /*
10981 * Always copy when entering and 'cpo' contains 'S'.
10982 * Don't copy when already initialized.
10983 * Don't copy when 'cpo' contains 's' and not entering.
10984 * 'S' BCO_ENTER initialized 's' should_copy
10985 * yes yes X X TRUE
10986 * yes no yes X FALSE
10987 * no X yes X FALSE
10988 * X no no yes FALSE
10989 * X no no no TRUE
10990 * no yes no X TRUE
10991 */
10992 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10993 && (buf->b_p_initialized
10994 || (!(flags & BCO_ENTER)
10995 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10996 should_copy = FALSE;
10997
10998 if (should_copy || (flags & BCO_ALWAYS))
10999 {
11000 /* Don't copy the options specific to a help buffer when
11001 * BCO_NOHELP is given or the options were initialized already
11002 * (jumping back to a help file with CTRL-T or CTRL-O) */
11003 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11004 || buf->b_p_initialized;
11005 if (dont_do_help) /* don't free b_p_isk */
11006 {
11007 save_p_isk = buf->b_p_isk;
11008 buf->b_p_isk = NULL;
11009 }
11010 /*
11011 * Always free the allocated strings.
11012 * If not already initialized, set 'readonly' and copy 'fileformat'.
11013 */
11014 if (!buf->b_p_initialized)
11015 {
11016 free_buf_options(buf, TRUE);
11017 buf->b_p_ro = FALSE; /* don't copy readonly */
11018 buf->b_p_tx = p_tx;
11019#ifdef FEAT_MBYTE
11020 buf->b_p_fenc = vim_strsave(p_fenc);
11021#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011022 switch (*p_ffs)
11023 {
11024 case 'm':
11025 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11026 case 'd':
11027 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11028 case 'u':
11029 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11030 default:
11031 buf->b_p_ff = vim_strsave(p_ff);
11032 }
11033 if (buf->b_p_ff != NULL)
11034 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035#if defined(FEAT_QUICKFIX)
11036 buf->b_p_bh = empty_option;
11037 buf->b_p_bt = empty_option;
11038#endif
11039 }
11040 else
11041 free_buf_options(buf, FALSE);
11042
11043 buf->b_p_ai = p_ai;
11044 buf->b_p_ai_nopaste = p_ai_nopaste;
11045 buf->b_p_sw = p_sw;
11046 buf->b_p_tw = p_tw;
11047 buf->b_p_tw_nopaste = p_tw_nopaste;
11048 buf->b_p_tw_nobin = p_tw_nobin;
11049 buf->b_p_wm = p_wm;
11050 buf->b_p_wm_nopaste = p_wm_nopaste;
11051 buf->b_p_wm_nobin = p_wm_nobin;
11052 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011053#ifdef FEAT_MBYTE
11054 buf->b_p_bomb = p_bomb;
11055#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011056 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011057 buf->b_p_et = p_et;
11058 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011059 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011060 buf->b_p_ml = p_ml;
11061 buf->b_p_ml_nobin = p_ml_nobin;
11062 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011063 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011064#ifdef FEAT_INS_EXPAND
11065 buf->b_p_cpt = vim_strsave(p_cpt);
11066#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011067#ifdef FEAT_COMPL_FUNC
11068 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011069 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011071 buf->b_p_sts = p_sts;
11072 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074#ifdef FEAT_COMMENTS
11075 buf->b_p_com = vim_strsave(p_com);
11076#endif
11077#ifdef FEAT_FOLDING
11078 buf->b_p_cms = vim_strsave(p_cms);
11079#endif
11080 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011081 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082 buf->b_p_nf = vim_strsave(p_nf);
11083 buf->b_p_mps = vim_strsave(p_mps);
11084#ifdef FEAT_SMARTINDENT
11085 buf->b_p_si = p_si;
11086#endif
11087 buf->b_p_ci = p_ci;
11088#ifdef FEAT_CINDENT
11089 buf->b_p_cin = p_cin;
11090 buf->b_p_cink = vim_strsave(p_cink);
11091 buf->b_p_cino = vim_strsave(p_cino);
11092#endif
11093#ifdef FEAT_AUTOCMD
11094 /* Don't copy 'filetype', it must be detected */
11095 buf->b_p_ft = empty_option;
11096#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 buf->b_p_pi = p_pi;
11098#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11099 buf->b_p_cinw = vim_strsave(p_cinw);
11100#endif
11101#ifdef FEAT_LISP
11102 buf->b_p_lisp = p_lisp;
11103#endif
11104#ifdef FEAT_SYN_HL
11105 /* Don't copy 'syntax', it must be set */
11106 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011107 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011108 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011109#endif
11110#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011111 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011112 (void)compile_cap_prog(&buf->b_s);
11113 buf->b_s.b_p_spf = vim_strsave(p_spf);
11114 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115#endif
11116#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11117 buf->b_p_inde = vim_strsave(p_inde);
11118 buf->b_p_indk = vim_strsave(p_indk);
11119#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011120 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011121#if defined(FEAT_EVAL)
11122 buf->b_p_fex = vim_strsave(p_fex);
11123#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124#ifdef FEAT_CRYPT
11125 buf->b_p_key = vim_strsave(p_key);
11126#endif
11127#ifdef FEAT_SEARCHPATH
11128 buf->b_p_sua = vim_strsave(p_sua);
11129#endif
11130#ifdef FEAT_KEYMAP
11131 buf->b_p_keymap = vim_strsave(p_keymap);
11132 buf->b_kmap_state |= KEYMAP_INIT;
11133#endif
11134 /* This isn't really an option, but copying the langmap and IME
11135 * state from the current buffer is better than resetting it. */
11136 buf->b_p_iminsert = p_iminsert;
11137 buf->b_p_imsearch = p_imsearch;
11138
11139 /* options that are normally global but also have a local value
11140 * are not copied, start using the global value */
11141 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011142 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011143 buf->b_p_bkc = empty_option;
11144 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145#ifdef FEAT_QUICKFIX
11146 buf->b_p_gp = empty_option;
11147 buf->b_p_mp = empty_option;
11148 buf->b_p_efm = empty_option;
11149#endif
11150 buf->b_p_ep = empty_option;
11151 buf->b_p_kp = empty_option;
11152 buf->b_p_path = empty_option;
11153 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011154 buf->b_p_tc = empty_option;
11155 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156#ifdef FEAT_FIND_ID
11157 buf->b_p_def = empty_option;
11158 buf->b_p_inc = empty_option;
11159# ifdef FEAT_EVAL
11160 buf->b_p_inex = vim_strsave(p_inex);
11161# endif
11162#endif
11163#ifdef FEAT_INS_EXPAND
11164 buf->b_p_dict = empty_option;
11165 buf->b_p_tsr = empty_option;
11166#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011167#ifdef FEAT_TEXTOBJ
11168 buf->b_p_qe = vim_strsave(p_qe);
11169#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011170#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11171 buf->b_p_bexpr = empty_option;
11172#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011173#if defined(FEAT_CRYPT)
11174 buf->b_p_cm = empty_option;
11175#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011176#ifdef FEAT_PERSISTENT_UNDO
11177 buf->b_p_udf = p_udf;
11178#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011179#ifdef FEAT_LISP
11180 buf->b_p_lw = empty_option;
11181#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011182#ifdef FEAT_MBYTE
11183 buf->b_p_menc = empty_option;
11184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185
11186 /*
11187 * Don't copy the options set by ex_help(), use the saved values,
11188 * when going from a help buffer to a non-help buffer.
11189 * Don't touch these at all when BCO_NOHELP is used and going from
11190 * or to a help buffer.
11191 */
11192 if (dont_do_help)
11193 buf->b_p_isk = save_p_isk;
11194 else
11195 {
11196 buf->b_p_isk = vim_strsave(p_isk);
11197 did_isk = TRUE;
11198 buf->b_p_ts = p_ts;
11199 buf->b_help = FALSE;
11200#ifdef FEAT_QUICKFIX
11201 if (buf->b_p_bt[0] == 'h')
11202 clear_string_option(&buf->b_p_bt);
11203#endif
11204 buf->b_p_ma = p_ma;
11205 }
11206 }
11207
11208 /*
11209 * When the options should be copied (ignoring BCO_ALWAYS), set the
11210 * flag that indicates that the options have been initialized.
11211 */
11212 if (should_copy)
11213 buf->b_p_initialized = TRUE;
11214 }
11215
11216 check_buf_options(buf); /* make sure we don't have NULLs */
11217 if (did_isk)
11218 (void)buf_init_chartab(buf, FALSE);
11219}
11220
11221/*
11222 * Reset the 'modifiable' option and its default value.
11223 */
11224 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011225reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011226{
11227 int opt_idx;
11228
11229 curbuf->b_p_ma = FALSE;
11230 p_ma = FALSE;
11231 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011232 if (opt_idx >= 0)
11233 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011234}
11235
11236/*
11237 * Set the global value for 'iminsert' to the local value.
11238 */
11239 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011240set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011241{
11242 p_iminsert = curbuf->b_p_iminsert;
11243}
11244
11245/*
11246 * Set the global value for 'imsearch' to the local value.
11247 */
11248 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011249set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250{
11251 p_imsearch = curbuf->b_p_imsearch;
11252}
11253
11254#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11255static int expand_option_idx = -1;
11256static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11257static int expand_option_flags = 0;
11258
11259 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011260set_context_in_set_cmd(
11261 expand_T *xp,
11262 char_u *arg,
11263 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011264{
11265 int nextchar;
11266 long_u flags = 0; /* init for GCC */
11267 int opt_idx = 0; /* init for GCC */
11268 char_u *p;
11269 char_u *s;
11270 int is_term_option = FALSE;
11271 int key;
11272
11273 expand_option_flags = opt_flags;
11274
11275 xp->xp_context = EXPAND_SETTINGS;
11276 if (*arg == NUL)
11277 {
11278 xp->xp_pattern = arg;
11279 return;
11280 }
11281 p = arg + STRLEN(arg) - 1;
11282 if (*p == ' ' && *(p - 1) != '\\')
11283 {
11284 xp->xp_pattern = p + 1;
11285 return;
11286 }
11287 while (p > arg)
11288 {
11289 s = p;
11290 /* count number of backslashes before ' ' or ',' */
11291 if (*p == ' ' || *p == ',')
11292 {
11293 while (s > arg && *(s - 1) == '\\')
11294 --s;
11295 }
11296 /* break at a space with an even number of backslashes */
11297 if (*p == ' ' && ((p - s) & 1) == 0)
11298 {
11299 ++p;
11300 break;
11301 }
11302 --p;
11303 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011304 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011305 {
11306 xp->xp_context = EXPAND_BOOL_SETTINGS;
11307 p += 2;
11308 }
11309 if (STRNCMP(p, "inv", 3) == 0)
11310 {
11311 xp->xp_context = EXPAND_BOOL_SETTINGS;
11312 p += 3;
11313 }
11314 xp->xp_pattern = arg = p;
11315 if (*arg == '<')
11316 {
11317 while (*p != '>')
11318 if (*p++ == NUL) /* expand terminal option name */
11319 return;
11320 key = get_special_key_code(arg + 1);
11321 if (key == 0) /* unknown name */
11322 {
11323 xp->xp_context = EXPAND_NOTHING;
11324 return;
11325 }
11326 nextchar = *++p;
11327 is_term_option = TRUE;
11328 expand_option_name[2] = KEY2TERMCAP0(key);
11329 expand_option_name[3] = KEY2TERMCAP1(key);
11330 }
11331 else
11332 {
11333 if (p[0] == 't' && p[1] == '_')
11334 {
11335 p += 2;
11336 if (*p != NUL)
11337 ++p;
11338 if (*p == NUL)
11339 return; /* expand option name */
11340 nextchar = *++p;
11341 is_term_option = TRUE;
11342 expand_option_name[2] = p[-2];
11343 expand_option_name[3] = p[-1];
11344 }
11345 else
11346 {
11347 /* Allow * wildcard */
11348 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11349 p++;
11350 if (*p == NUL)
11351 return;
11352 nextchar = *p;
11353 *p = NUL;
11354 opt_idx = findoption(arg);
11355 *p = nextchar;
11356 if (opt_idx == -1 || options[opt_idx].var == NULL)
11357 {
11358 xp->xp_context = EXPAND_NOTHING;
11359 return;
11360 }
11361 flags = options[opt_idx].flags;
11362 if (flags & P_BOOL)
11363 {
11364 xp->xp_context = EXPAND_NOTHING;
11365 return;
11366 }
11367 }
11368 }
11369 /* handle "-=" and "+=" */
11370 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11371 {
11372 ++p;
11373 nextchar = '=';
11374 }
11375 if ((nextchar != '=' && nextchar != ':')
11376 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11377 {
11378 xp->xp_context = EXPAND_UNSUCCESSFUL;
11379 return;
11380 }
11381 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11382 {
11383 xp->xp_context = EXPAND_OLD_SETTING;
11384 if (is_term_option)
11385 expand_option_idx = -1;
11386 else
11387 expand_option_idx = opt_idx;
11388 xp->xp_pattern = p + 1;
11389 return;
11390 }
11391 xp->xp_context = EXPAND_NOTHING;
11392 if (is_term_option || (flags & P_NUM))
11393 return;
11394
11395 xp->xp_pattern = p + 1;
11396
11397 if (flags & P_EXPAND)
11398 {
11399 p = options[opt_idx].var;
11400 if (p == (char_u *)&p_bdir
11401 || p == (char_u *)&p_dir
11402 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011403 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011404 || p == (char_u *)&p_rtp
11405#ifdef FEAT_SEARCHPATH
11406 || p == (char_u *)&p_cdpath
11407#endif
11408#ifdef FEAT_SESSION
11409 || p == (char_u *)&p_vdir
11410#endif
11411 )
11412 {
11413 xp->xp_context = EXPAND_DIRECTORIES;
11414 if (p == (char_u *)&p_path
11415#ifdef FEAT_SEARCHPATH
11416 || p == (char_u *)&p_cdpath
11417#endif
11418 )
11419 xp->xp_backslash = XP_BS_THREE;
11420 else
11421 xp->xp_backslash = XP_BS_ONE;
11422 }
11423 else
11424 {
11425 xp->xp_context = EXPAND_FILES;
11426 /* for 'tags' need three backslashes for a space */
11427 if (p == (char_u *)&p_tags)
11428 xp->xp_backslash = XP_BS_THREE;
11429 else
11430 xp->xp_backslash = XP_BS_ONE;
11431 }
11432 }
11433
11434 /* For an option that is a list of file names, find the start of the
11435 * last file name. */
11436 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11437 {
11438 /* count number of backslashes before ' ' or ',' */
11439 if (*p == ' ' || *p == ',')
11440 {
11441 s = p;
11442 while (s > xp->xp_pattern && *(s - 1) == '\\')
11443 --s;
11444 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11445 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11446 {
11447 xp->xp_pattern = p + 1;
11448 break;
11449 }
11450 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011451
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011452#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011453 /* for 'spellsuggest' start at "file:" */
11454 if (options[opt_idx].var == (char_u *)&p_sps
11455 && STRNCMP(p, "file:", 5) == 0)
11456 {
11457 xp->xp_pattern = p + 5;
11458 break;
11459 }
11460#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011461 }
11462
11463 return;
11464}
11465
11466 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011467ExpandSettings(
11468 expand_T *xp,
11469 regmatch_T *regmatch,
11470 int *num_file,
11471 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011472{
11473 int num_normal = 0; /* Nr of matching non-term-code settings */
11474 int num_term = 0; /* Nr of matching terminal code settings */
11475 int opt_idx;
11476 int match;
11477 int count = 0;
11478 char_u *str;
11479 int loop;
11480 int is_term_opt;
11481 char_u name_buf[MAX_KEY_NAME_LEN];
11482 static char *(names[]) = {"all", "termcap"};
11483 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11484
11485 /* do this loop twice:
11486 * loop == 0: count the number of matching options
11487 * loop == 1: copy the matching options into allocated memory
11488 */
11489 for (loop = 0; loop <= 1; ++loop)
11490 {
11491 regmatch->rm_ic = ic;
11492 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11493 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011494 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11495 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011496 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11497 {
11498 if (loop == 0)
11499 num_normal++;
11500 else
11501 (*file)[count++] = vim_strsave((char_u *)names[match]);
11502 }
11503 }
11504 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11505 opt_idx++)
11506 {
11507 if (options[opt_idx].var == NULL)
11508 continue;
11509 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11510 && !(options[opt_idx].flags & P_BOOL))
11511 continue;
11512 is_term_opt = istermoption(&options[opt_idx]);
11513 if (is_term_opt && num_normal > 0)
11514 continue;
11515 match = FALSE;
11516 if (vim_regexec(regmatch, str, (colnr_T)0)
11517 || (options[opt_idx].shortname != NULL
11518 && vim_regexec(regmatch,
11519 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11520 match = TRUE;
11521 else if (is_term_opt)
11522 {
11523 name_buf[0] = '<';
11524 name_buf[1] = 't';
11525 name_buf[2] = '_';
11526 name_buf[3] = str[2];
11527 name_buf[4] = str[3];
11528 name_buf[5] = '>';
11529 name_buf[6] = NUL;
11530 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11531 {
11532 match = TRUE;
11533 str = name_buf;
11534 }
11535 }
11536 if (match)
11537 {
11538 if (loop == 0)
11539 {
11540 if (is_term_opt)
11541 num_term++;
11542 else
11543 num_normal++;
11544 }
11545 else
11546 (*file)[count++] = vim_strsave(str);
11547 }
11548 }
11549 /*
11550 * Check terminal key codes, these are not in the option table
11551 */
11552 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11553 {
11554 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11555 {
11556 if (!isprint(str[0]) || !isprint(str[1]))
11557 continue;
11558
11559 name_buf[0] = 't';
11560 name_buf[1] = '_';
11561 name_buf[2] = str[0];
11562 name_buf[3] = str[1];
11563 name_buf[4] = NUL;
11564
11565 match = FALSE;
11566 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11567 match = TRUE;
11568 else
11569 {
11570 name_buf[0] = '<';
11571 name_buf[1] = 't';
11572 name_buf[2] = '_';
11573 name_buf[3] = str[0];
11574 name_buf[4] = str[1];
11575 name_buf[5] = '>';
11576 name_buf[6] = NUL;
11577
11578 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11579 match = TRUE;
11580 }
11581 if (match)
11582 {
11583 if (loop == 0)
11584 num_term++;
11585 else
11586 (*file)[count++] = vim_strsave(name_buf);
11587 }
11588 }
11589
11590 /*
11591 * Check special key names.
11592 */
11593 regmatch->rm_ic = TRUE; /* ignore case here */
11594 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11595 {
11596 name_buf[0] = '<';
11597 STRCPY(name_buf + 1, str);
11598 STRCAT(name_buf, ">");
11599
11600 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11601 {
11602 if (loop == 0)
11603 num_term++;
11604 else
11605 (*file)[count++] = vim_strsave(name_buf);
11606 }
11607 }
11608 }
11609 if (loop == 0)
11610 {
11611 if (num_normal > 0)
11612 *num_file = num_normal;
11613 else if (num_term > 0)
11614 *num_file = num_term;
11615 else
11616 return OK;
11617 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11618 if (*file == NULL)
11619 {
11620 *file = (char_u **)"";
11621 return FAIL;
11622 }
11623 }
11624 }
11625 return OK;
11626}
11627
11628 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011629ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011630{
11631 char_u *var = NULL; /* init for GCC */
11632 char_u *buf;
11633
11634 *num_file = 0;
11635 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11636 if (*file == NULL)
11637 return FAIL;
11638
11639 /*
11640 * For a terminal key code expand_option_idx is < 0.
11641 */
11642 if (expand_option_idx < 0)
11643 {
11644 var = find_termcode(expand_option_name + 2);
11645 if (var == NULL)
11646 expand_option_idx = findoption(expand_option_name);
11647 }
11648
11649 if (expand_option_idx >= 0)
11650 {
11651 /* put string of option value in NameBuff */
11652 option_value2string(&options[expand_option_idx], expand_option_flags);
11653 var = NameBuff;
11654 }
11655 else if (var == NULL)
11656 var = (char_u *)"";
11657
11658 /* A backslash is required before some characters. This is the reverse of
11659 * what happens in do_set(). */
11660 buf = vim_strsave_escaped(var, escape_chars);
11661
11662 if (buf == NULL)
11663 {
11664 vim_free(*file);
11665 *file = NULL;
11666 return FAIL;
11667 }
11668
11669#ifdef BACKSLASH_IN_FILENAME
11670 /* For MS-Windows et al. we don't double backslashes at the start and
11671 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011672 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011673 if (var[0] == '\\' && var[1] == '\\'
11674 && expand_option_idx >= 0
11675 && (options[expand_option_idx].flags & P_EXPAND)
11676 && vim_isfilec(var[2])
11677 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011678 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011679#endif
11680
11681 *file[0] = buf;
11682 *num_file = 1;
11683 return OK;
11684}
11685#endif
11686
11687/*
11688 * Get the value for the numeric or string option *opp in a nice format into
11689 * NameBuff[]. Must not be called with a hidden option!
11690 */
11691 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011692option_value2string(
11693 struct vimoption *opp,
11694 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011695{
11696 char_u *varp;
11697
11698 varp = get_varp_scope(opp, opt_flags);
11699
11700 if (opp->flags & P_NUM)
11701 {
11702 long wc = 0;
11703
11704 if (wc_use_keyname(varp, &wc))
11705 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11706 else if (wc != 0)
11707 STRCPY(NameBuff, transchar((int)wc));
11708 else
11709 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11710 }
11711 else /* P_STRING */
11712 {
11713 varp = *(char_u **)(varp);
11714 if (varp == NULL) /* just in case */
11715 NameBuff[0] = NUL;
11716#ifdef FEAT_CRYPT
11717 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011718 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011719 STRCPY(NameBuff, "*****");
11720#endif
11721 else if (opp->flags & P_EXPAND)
11722 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11723 /* Translate 'pastetoggle' into special key names */
11724 else if ((char_u **)opp->var == &p_pt)
11725 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11726 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011727 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011728 }
11729}
11730
11731/*
11732 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11733 * printed as a keyname.
11734 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11735 */
11736 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011737wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011738{
11739 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11740 {
11741 *wcp = *(long *)varp;
11742 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11743 return TRUE;
11744 }
11745 return FALSE;
11746}
11747
Bram Moolenaar01615492015-02-03 13:00:38 +010011748#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011750 * Any character has an equivalent 'langmap' character. This is used for
11751 * keyboards that have a special language mode that sends characters above
11752 * 128 (although other characters can be translated too). The "to" field is a
11753 * Vim command character. This avoids having to switch the keyboard back to
11754 * ASCII mode when leaving Insert mode.
11755 *
11756 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11757 * commands.
11758 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11759 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11760 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011762# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011763/*
11764 * With multi-byte support use growarray for 'langmap' chars >= 256
11765 */
11766typedef struct
11767{
11768 int from;
11769 int to;
11770} langmap_entry_T;
11771
11772static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011773static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011774
11775/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011776 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11777 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011778 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011779 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011780langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011781{
11782 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011783 int a = 0;
11784 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011785
11786 /* Do a binary search for an existing entry. */
11787 while (a != b)
11788 {
11789 int i = (a + b) / 2;
11790 int d = entries[i].from - from;
11791
11792 if (d == 0)
11793 {
11794 entries[i].to = to;
11795 return;
11796 }
11797 if (d < 0)
11798 a = i + 1;
11799 else
11800 b = i;
11801 }
11802
11803 if (ga_grow(&langmap_mapga, 1) != OK)
11804 return; /* out of memory */
11805
11806 /* insert new entry at position "a" */
11807 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11808 mch_memmove(entries + 1, entries,
11809 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11810 ++langmap_mapga.ga_len;
11811 entries[0].from = from;
11812 entries[0].to = to;
11813}
11814
11815/*
11816 * Apply 'langmap' to multi-byte character "c" and return the result.
11817 */
11818 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011819langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011820{
11821 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11822 int a = 0;
11823 int b = langmap_mapga.ga_len;
11824
11825 while (a != b)
11826 {
11827 int i = (a + b) / 2;
11828 int d = entries[i].from - c;
11829
11830 if (d == 0)
11831 return entries[i].to; /* found matching entry */
11832 if (d < 0)
11833 a = i + 1;
11834 else
11835 b = i;
11836 }
11837 return c; /* no entry found, return "c" unmodified */
11838}
11839# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840
11841 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011842langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011843{
11844 int i;
11845
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011846 for (i = 0; i < 256; i++)
11847 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11848# ifdef FEAT_MBYTE
11849 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11850# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851}
11852
11853/*
11854 * Called when langmap option is set; the language map can be
11855 * changed at any time!
11856 */
11857 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011858langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859{
11860 char_u *p;
11861 char_u *p2;
11862 int from, to;
11863
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011864#ifdef FEAT_MBYTE
11865 ga_clear(&langmap_mapga); /* clear the previous map first */
11866#endif
11867 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868
11869 for (p = p_langmap; p[0] != NUL; )
11870 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011871 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011872 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873 {
11874 if (p2[0] == '\\' && p2[1] != NUL)
11875 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876 }
11877 if (p2[0] == ';')
11878 ++p2; /* abcd;ABCD form, p2 points to A */
11879 else
11880 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11881 while (p[0])
11882 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011883 if (p[0] == ',')
11884 {
11885 ++p;
11886 break;
11887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011888 if (p[0] == '\\' && p[1] != NUL)
11889 ++p;
11890#ifdef FEAT_MBYTE
11891 from = (*mb_ptr2char)(p);
11892#else
11893 from = p[0];
11894#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011895 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011896 if (p2 == NULL)
11897 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011898 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011899 if (p[0] != ',')
11900 {
11901 if (p[0] == '\\')
11902 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011903#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011904 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011905#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011906 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011908 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909 }
11910 else
11911 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011912 if (p2[0] != ',')
11913 {
11914 if (p2[0] == '\\')
11915 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011916#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011917 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011919 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011920#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011921 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922 }
11923 if (to == NUL)
11924 {
11925 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11926 transchar(from));
11927 return;
11928 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011929
11930#ifdef FEAT_MBYTE
11931 if (from >= 256)
11932 langmap_set_entry(from, to);
11933 else
11934#endif
11935 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936
11937 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011938 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011939 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011940 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011941 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942 if (*p == ';')
11943 {
11944 p = p2;
11945 if (p[0] != NUL)
11946 {
11947 if (p[0] != ',')
11948 {
11949 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11950 return;
11951 }
11952 ++p;
11953 }
11954 break;
11955 }
11956 }
11957 }
11958 }
11959}
11960#endif
11961
11962/*
11963 * Return TRUE if format option 'x' is in effect.
11964 * Take care of no formatting when 'paste' is set.
11965 */
11966 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011967has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011968{
11969 if (p_paste)
11970 return FALSE;
11971 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11972}
11973
11974/*
11975 * Return TRUE if "x" is present in 'shortmess' option, or
11976 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11977 */
11978 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011979shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011981 return p_shm != NULL &&
11982 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983 || (vim_strchr(p_shm, 'a') != NULL
11984 && vim_strchr((char_u *)SHM_A, x) != NULL));
11985}
11986
11987/*
11988 * paste_option_changed() - Called after p_paste was set or reset.
11989 */
11990 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011991paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011992{
11993 static int old_p_paste = FALSE;
11994 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011995 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996#ifdef FEAT_CMDL_INFO
11997 static int save_ru = 0;
11998#endif
11999#ifdef FEAT_RIGHTLEFT
12000 static int save_ri = 0;
12001 static int save_hkmap = 0;
12002#endif
12003 buf_T *buf;
12004
12005 if (p_paste)
12006 {
12007 /*
12008 * Paste switched from off to on.
12009 * Save the current values, so they can be restored later.
12010 */
12011 if (!old_p_paste)
12012 {
12013 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012014 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012015 {
12016 buf->b_p_tw_nopaste = buf->b_p_tw;
12017 buf->b_p_wm_nopaste = buf->b_p_wm;
12018 buf->b_p_sts_nopaste = buf->b_p_sts;
12019 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012020 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021 }
12022
12023 /* save global options */
12024 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012025 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012026#ifdef FEAT_CMDL_INFO
12027 save_ru = p_ru;
12028#endif
12029#ifdef FEAT_RIGHTLEFT
12030 save_ri = p_ri;
12031 save_hkmap = p_hkmap;
12032#endif
12033 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012034 p_ai_nopaste = p_ai;
12035 p_et_nopaste = p_et;
12036 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012037 p_tw_nopaste = p_tw;
12038 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012039 }
12040
12041 /*
12042 * Always set the option values, also when 'paste' is set when it is
12043 * already on.
12044 */
12045 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012046 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012047 {
12048 buf->b_p_tw = 0; /* textwidth is 0 */
12049 buf->b_p_wm = 0; /* wrapmargin is 0 */
12050 buf->b_p_sts = 0; /* softtabstop is 0 */
12051 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012052 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012053 }
12054
12055 /* set global options */
12056 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012057 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012058#ifdef FEAT_CMDL_INFO
12059# ifdef FEAT_WINDOWS
12060 if (p_ru)
12061 status_redraw_all(); /* redraw to remove the ruler */
12062# endif
12063 p_ru = 0; /* no ruler */
12064#endif
12065#ifdef FEAT_RIGHTLEFT
12066 p_ri = 0; /* no reverse insert */
12067 p_hkmap = 0; /* no Hebrew keyboard */
12068#endif
12069 /* set global values for local buffer options */
12070 p_tw = 0;
12071 p_wm = 0;
12072 p_sts = 0;
12073 p_ai = 0;
12074 }
12075
12076 /*
12077 * Paste switched from on to off: Restore saved values.
12078 */
12079 else if (old_p_paste)
12080 {
12081 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012082 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012083 {
12084 buf->b_p_tw = buf->b_p_tw_nopaste;
12085 buf->b_p_wm = buf->b_p_wm_nopaste;
12086 buf->b_p_sts = buf->b_p_sts_nopaste;
12087 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012088 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012089 }
12090
12091 /* restore global options */
12092 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012093 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012094#ifdef FEAT_CMDL_INFO
12095# ifdef FEAT_WINDOWS
12096 if (p_ru != save_ru)
12097 status_redraw_all(); /* redraw to draw the ruler */
12098# endif
12099 p_ru = save_ru;
12100#endif
12101#ifdef FEAT_RIGHTLEFT
12102 p_ri = save_ri;
12103 p_hkmap = save_hkmap;
12104#endif
12105 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012106 p_ai = p_ai_nopaste;
12107 p_et = p_et_nopaste;
12108 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 p_tw = p_tw_nopaste;
12110 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111 }
12112
12113 old_p_paste = p_paste;
12114}
12115
12116/*
12117 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12118 *
12119 * Reset 'compatible' and set the values for options that didn't get set yet
12120 * to the Vim defaults.
12121 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012122 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123 */
12124 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012125vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012127 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012128 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012129 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012130
12131 if (!option_was_set((char_u *)"cp"))
12132 {
12133 p_cp = FALSE;
12134 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12135 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12136 set_option_default(opt_idx, OPT_FREE, FALSE);
12137 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012138 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012140
12141 if (fname != NULL)
12142 {
12143 p = vim_getenv(envname, &dofree);
12144 if (p == NULL)
12145 {
12146 /* Set $MYVIMRC to the first vimrc file found. */
12147 p = FullName_save(fname, FALSE);
12148 if (p != NULL)
12149 {
12150 vim_setenv(envname, p);
12151 vim_free(p);
12152 }
12153 }
12154 else if (dofree)
12155 vim_free(p);
12156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012157}
12158
12159/*
12160 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12161 */
12162 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012163change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012165 int opt_idx;
12166
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167 if (p_cp != on)
12168 {
12169 p_cp = on;
12170 compatible_set();
12171 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012172 opt_idx = findoption((char_u *)"cp");
12173 if (opt_idx >= 0)
12174 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175}
12176
12177/*
12178 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012179 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012180 */
12181 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012182option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183{
12184 int idx;
12185
12186 idx = findoption(name);
12187 if (idx < 0) /* unknown option */
12188 return FALSE;
12189 if (options[idx].flags & P_WAS_SET)
12190 return TRUE;
12191 return FALSE;
12192}
12193
12194/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012195 * Reset the flag indicating option "name" was set.
12196 */
12197 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012198reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012199{
12200 int idx = findoption(name);
12201
12202 if (idx >= 0)
12203 options[idx].flags &= ~P_WAS_SET;
12204}
12205
12206/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012207 * compatible_set() - Called when 'compatible' has been set or unset.
12208 *
12209 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12210 * flag) to a Vi compatible value.
12211 * When 'compatible' is unset: Set all options that have a different default
12212 * for Vim (without the P_VI_DEF flag) to that default.
12213 */
12214 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012215compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012216{
12217 int opt_idx;
12218
12219 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12220 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12221 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12222 set_option_default(opt_idx, OPT_FREE, p_cp);
12223 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012224 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012225}
12226
12227#ifdef FEAT_LINEBREAK
12228
12229# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12230 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012231 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012232# endif
12233
12234/*
12235 * fill_breakat_flags() -- called when 'breakat' changes value.
12236 */
12237 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012238fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012239{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012240 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012241 int i;
12242
12243 for (i = 0; i < 256; i++)
12244 breakat_flags[i] = FALSE;
12245
12246 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012247 for (p = p_breakat; *p; p++)
12248 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249}
12250
12251# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012252 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012253# endif
12254
12255#endif
12256
12257/*
12258 * Check an option that can be a range of string values.
12259 *
12260 * Return OK for correct value, FAIL otherwise.
12261 * Empty is always OK.
12262 */
12263 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012264check_opt_strings(
12265 char_u *val,
12266 char **values,
12267 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012268{
12269 return opt_strings_flags(val, values, NULL, list);
12270}
12271
12272/*
12273 * Handle an option that can be a range of string values.
12274 * Set a flag in "*flagp" for each string present.
12275 *
12276 * Return OK for correct value, FAIL otherwise.
12277 * Empty is always OK.
12278 */
12279 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012280opt_strings_flags(
12281 char_u *val, /* new value */
12282 char **values, /* array of valid string values */
12283 unsigned *flagp,
12284 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012285{
12286 int i;
12287 int len;
12288 unsigned new_flags = 0;
12289
12290 while (*val)
12291 {
12292 for (i = 0; ; ++i)
12293 {
12294 if (values[i] == NULL) /* val not found in values[] */
12295 return FAIL;
12296
12297 len = (int)STRLEN(values[i]);
12298 if (STRNCMP(values[i], val, len) == 0
12299 && ((list && val[len] == ',') || val[len] == NUL))
12300 {
12301 val += len + (val[len] == ',');
12302 new_flags |= (1 << i);
12303 break; /* check next item in val list */
12304 }
12305 }
12306 }
12307 if (flagp != NULL)
12308 *flagp = new_flags;
12309
12310 return OK;
12311}
12312
12313/*
12314 * Read the 'wildmode' option, fill wim_flags[].
12315 */
12316 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012317check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012318{
12319 char_u new_wim_flags[4];
12320 char_u *p;
12321 int i;
12322 int idx = 0;
12323
12324 for (i = 0; i < 4; ++i)
12325 new_wim_flags[i] = 0;
12326
12327 for (p = p_wim; *p; ++p)
12328 {
12329 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12330 ;
12331 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12332 return FAIL;
12333 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12334 new_wim_flags[idx] |= WIM_LONGEST;
12335 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12336 new_wim_flags[idx] |= WIM_FULL;
12337 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12338 new_wim_flags[idx] |= WIM_LIST;
12339 else
12340 return FAIL;
12341 p += i;
12342 if (*p == NUL)
12343 break;
12344 if (*p == ',')
12345 {
12346 if (idx == 3)
12347 return FAIL;
12348 ++idx;
12349 }
12350 }
12351
12352 /* fill remaining entries with last flag */
12353 while (idx < 3)
12354 {
12355 new_wim_flags[idx + 1] = new_wim_flags[idx];
12356 ++idx;
12357 }
12358
12359 /* only when there are no errors, wim_flags[] is changed */
12360 for (i = 0; i < 4; ++i)
12361 wim_flags[i] = new_wim_flags[i];
12362 return OK;
12363}
12364
12365/*
12366 * Check if backspacing over something is allowed.
12367 */
12368 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012369can_bs(
12370 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012371{
12372 switch (*p_bs)
12373 {
12374 case '2': return TRUE;
12375 case '1': return (what != BS_START);
12376 case '0': return FALSE;
12377 }
12378 return vim_strchr(p_bs, what) != NULL;
12379}
12380
12381/*
12382 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12383 * the file must be considered changed when the value is different.
12384 */
12385 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012386save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012387{
12388 buf->b_start_ffc = *buf->b_p_ff;
12389 buf->b_start_eol = buf->b_p_eol;
12390#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012391 buf->b_start_bomb = buf->b_p_bomb;
12392
Bram Moolenaar071d4272004-06-13 20:20:40 +000012393 /* Only use free/alloc when necessary, they take time. */
12394 if (buf->b_start_fenc == NULL
12395 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12396 {
12397 vim_free(buf->b_start_fenc);
12398 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12399 }
12400#endif
12401}
12402
12403/*
12404 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12405 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012406 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12407 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012408 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012409 * When "ignore_empty" is true don't consider a new, empty buffer to be
12410 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012411 */
12412 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012413file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012414{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012415 /* In a buffer that was never loaded the options are not valid. */
12416 if (buf->b_flags & BF_NEVERLOADED)
12417 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012418 if (ignore_empty
12419 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012420 && buf->b_ml.ml_line_count == 1
12421 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12422 return FALSE;
12423 if (buf->b_start_ffc != *buf->b_p_ff)
12424 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012425 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012426 return TRUE;
12427#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012428 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12429 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012430 if (buf->b_start_fenc == NULL)
12431 return (*buf->b_p_fenc != NUL);
12432 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12433#else
12434 return FALSE;
12435#endif
12436}
12437
12438/*
12439 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12440 */
12441 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012442check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012443{
12444 return check_opt_strings(p, p_ff_values, FALSE);
12445}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012446
12447/*
12448 * Return the effective shiftwidth value for current buffer, using the
12449 * 'tabstop' value when 'shiftwidth' is zero.
12450 */
12451 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012452get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012453{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012454 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012455}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012456
12457/*
12458 * Return the effective softtabstop value for the current buffer, using the
12459 * 'tabstop' value when 'softtabstop' is negative.
12460 */
12461 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012462get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012463{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012464 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012465}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012466
12467/*
12468 * Check matchpairs option for "*initc".
12469 * If there is a match set "*initc" to the matching character and "*findc" to
12470 * the opposite character. Set "*backwards" to the direction.
12471 * When "switchit" is TRUE swap the direction.
12472 */
12473 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012474find_mps_values(
12475 int *initc,
12476 int *findc,
12477 int *backwards,
12478 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012479{
12480 char_u *ptr;
12481
12482 ptr = curbuf->b_p_mps;
12483 while (*ptr != NUL)
12484 {
12485#ifdef FEAT_MBYTE
12486 if (has_mbyte)
12487 {
12488 char_u *prev;
12489
12490 if (mb_ptr2char(ptr) == *initc)
12491 {
12492 if (switchit)
12493 {
12494 *findc = *initc;
12495 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12496 *backwards = TRUE;
12497 }
12498 else
12499 {
12500 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12501 *backwards = FALSE;
12502 }
12503 return;
12504 }
12505 prev = ptr;
12506 ptr += mb_ptr2len(ptr) + 1;
12507 if (mb_ptr2char(ptr) == *initc)
12508 {
12509 if (switchit)
12510 {
12511 *findc = *initc;
12512 *initc = mb_ptr2char(prev);
12513 *backwards = FALSE;
12514 }
12515 else
12516 {
12517 *findc = mb_ptr2char(prev);
12518 *backwards = TRUE;
12519 }
12520 return;
12521 }
12522 ptr += mb_ptr2len(ptr);
12523 }
12524 else
12525#endif
12526 {
12527 if (*ptr == *initc)
12528 {
12529 if (switchit)
12530 {
12531 *backwards = TRUE;
12532 *findc = *initc;
12533 *initc = ptr[2];
12534 }
12535 else
12536 {
12537 *backwards = FALSE;
12538 *findc = ptr[2];
12539 }
12540 return;
12541 }
12542 ptr += 2;
12543 if (*ptr == *initc)
12544 {
12545 if (switchit)
12546 {
12547 *backwards = FALSE;
12548 *findc = *initc;
12549 *initc = ptr[-2];
12550 }
12551 else
12552 {
12553 *backwards = TRUE;
12554 *findc = ptr[-2];
12555 }
12556 return;
12557 }
12558 ++ptr;
12559 }
12560 if (*ptr == ',')
12561 ++ptr;
12562 }
12563}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012564
12565#if defined(FEAT_LINEBREAK) || defined(PROTO)
12566/*
12567 * This is called when 'breakindentopt' is changed and when a window is
12568 * initialized.
12569 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012570 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012571briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012572{
12573 char_u *p;
12574 int bri_shift = 0;
12575 long bri_min = 20;
12576 int bri_sbr = FALSE;
12577
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012578 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012579 while (*p != NUL)
12580 {
12581 if (STRNCMP(p, "shift:", 6) == 0
12582 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12583 {
12584 p += 6;
12585 bri_shift = getdigits(&p);
12586 }
12587 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12588 {
12589 p += 4;
12590 bri_min = getdigits(&p);
12591 }
12592 else if (STRNCMP(p, "sbr", 3) == 0)
12593 {
12594 p += 3;
12595 bri_sbr = TRUE;
12596 }
12597 if (*p != ',' && *p != NUL)
12598 return FAIL;
12599 if (*p == ',')
12600 ++p;
12601 }
12602
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012603 wp->w_p_brishift = bri_shift;
12604 wp->w_p_brimin = bri_min;
12605 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012606
12607 return OK;
12608}
12609#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012610
12611/*
12612 * Get the local or global value of 'backupcopy'.
12613 */
12614 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012615get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012616{
12617 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12618}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012619
12620#if defined(FEAT_SIGNS) || defined(PROTO)
12621/*
12622 * Return TRUE when window "wp" has a column to draw signs in.
12623 */
12624 int
12625signcolumn_on(win_T *wp)
12626{
12627 if (*wp->w_p_scl == 'n')
12628 return FALSE;
12629 if (*wp->w_p_scl == 'y')
12630 return TRUE;
12631 return (wp->w_buffer->b_signlist != NULL
12632# ifdef FEAT_NETBEANS_INTG
12633 || wp->w_buffer->b_has_sign_column
12634# endif
12635 );
12636}
12637#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012638
12639#if defined(FEAT_EVAL) || defined(PROTO)
12640/*
12641 * Get window or buffer local options.
12642 */
12643 dict_T *
12644get_winbuf_options(int bufopt)
12645{
12646 dict_T *d;
12647 int opt_idx;
12648
12649 d = dict_alloc();
12650 if (d == NULL)
12651 return NULL;
12652
12653 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12654 {
12655 struct vimoption *opt = &options[opt_idx];
12656
12657 if ((bufopt && (opt->indir & PV_BUF))
12658 || (!bufopt && (opt->indir & PV_WIN)))
12659 {
12660 char_u *varp = get_varp(opt);
12661
12662 if (varp != NULL)
12663 {
12664 if (opt->flags & P_STRING)
12665 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012666 else if (opt->flags & P_NUM)
12667 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012668 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012669 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012670 }
12671 }
12672 }
12673
12674 return d;
12675}
12676#endif