blob: b0baf501854de9a15f6467872790af5da21d6937 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
225#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#ifdef FEAT_WINDOWS
249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200260#ifdef FEAT_SIGNS
261# define PV_SCL OPT_WIN(WV_SCL)
262#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000263
264/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265typedef enum
266{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000267 PV_NONE = 0,
268 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269} idopt_T;
270
271/*
272 * Options local to a window have a value local to a buffer and global to all
273 * buffers. Indicate this by setting "var" to VAR_WIN.
274 */
275#define VAR_WIN ((char_u *)-1)
276
277/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000278 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279 * Only to be used in option.c!
280 */
281static int p_ai;
282static int p_bin;
283#ifdef FEAT_MBYTE
284static int p_bomb;
285#endif
286#if defined(FEAT_QUICKFIX)
287static char_u *p_bh;
288static char_u *p_bt;
289#endif
290static int p_bl;
291static int p_ci;
292#ifdef FEAT_CINDENT
293static int p_cin;
294static char_u *p_cink;
295static char_u *p_cino;
296#endif
297#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298static char_u *p_cinw;
299#endif
300#ifdef FEAT_COMMENTS
301static char_u *p_com;
302#endif
303#ifdef FEAT_FOLDING
304static char_u *p_cms;
305#endif
306#ifdef FEAT_INS_EXPAND
307static char_u *p_cpt;
308#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#ifdef FEAT_COMPL_FUNC
310static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000311static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
316#ifdef FEAT_MBYTE
317static char_u *p_fenc;
318#endif
319static char_u *p_ff;
320static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000321static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322#ifdef FEAT_AUTOCMD
323static char_u *p_ft;
324#endif
325static long p_iminsert;
326static long p_imsearch;
327#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328static char_u *p_inex;
329#endif
330#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331static char_u *p_inde;
332static char_u *p_indk;
333#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000334#if defined(FEAT_EVAL)
335static char_u *p_fex;
336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_inf;
338static char_u *p_isk;
339#ifdef FEAT_CRYPT
340static char_u *p_key;
341#endif
342#ifdef FEAT_LISP
343static int p_lisp;
344#endif
345static int p_ml;
346static int p_ma;
347static int p_mod;
348static char_u *p_mps;
349static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000351#ifdef FEAT_TEXTOBJ
352static char_u *p_qe;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_ro;
355#ifdef FEAT_SMARTINDENT
356static int p_si;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static long p_sts;
360#if defined(FEAT_SEARCHPATH)
361static char_u *p_sua;
362#endif
363static long p_sw;
364static int p_swf;
365#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000366static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000368#endif
369#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000370static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000371static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000372static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#endif
374static long p_ts;
375static long p_tw;
376static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200377#ifdef FEAT_PERSISTENT_UNDO
378static int p_udf;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380static long p_wm;
381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
400 char *fullname; /* full option name */
401 char *shortname; /* permissible abbreviation */
402 long_u flags; /* see below */
403 char_u *var; /* global option: pointer to variable;
404 * window-local option: VAR_WIN;
405 * buffer-local option: global value */
406 idopt_T indir; /* global option: PV_NONE;
407 * local option: indirect option index */
408 char_u *def_val[2]; /* default values for variable (vi and vim) */
409#ifdef FEAT_EVAL
410 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411# define SCRIPTID_INIT , 0
412#else
413# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100476/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000477#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100478 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200479 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar58b85342016-08-14 19:54:54 +0200480# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000481#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100482# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000483#endif
484
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100485/* Default python version for pyx* commands */
486#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
487# define DEFAULT_PYTHON_VER 0
488#elif defined(FEAT_PYTHON3)
489# define DEFAULT_PYTHON_VER 3
490#elif defined(FEAT_PYTHON)
491# define DEFAULT_PYTHON_VER 2
492#else
493# define DEFAULT_PYTHON_VER 0
494#endif
495
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496/*
497 * options[] is initialized here.
498 * The order of the options MUST be alphabetic for ":set all" and findoption().
499 * All option names MUST start with a lowercase letter (for findoption()).
500 * Exception: "t_" options are at the end.
501 * The options with a NULL variable are 'hidden': a set command for them is
502 * ignored and they are not printed.
503 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100504static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200506 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507#ifdef FEAT_RIGHTLEFT
508 (char_u *)&p_aleph, PV_NONE,
509#else
510 (char_u *)NULL, PV_NONE,
511#endif
512 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100513#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)128L,
515#else
516 (char_u *)224L,
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
520#if defined(FEAT_GUI) && defined(MACOS_X)
521 (char_u *)&p_antialias, PV_NONE,
522 {(char_u *)FALSE, (char_u *)FALSE}
523#else
524 (char_u *)NULL, PV_NONE,
525 {(char_u *)FALSE, (char_u *)FALSE}
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200528 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529#ifdef FEAT_ARABIC
530 (char_u *)VAR_WIN, PV_ARAB,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
536#ifdef FEAT_ARABIC
537 (char_u *)&p_arshape, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
543#ifdef FEAT_RIGHTLEFT
544 (char_u *)&p_ari, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
550#ifdef FEAT_FKMAP
551 (char_u *)&p_altkeymap, PV_NONE,
552#else
553 (char_u *)NULL, PV_NONE,
554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
557#if defined(FEAT_MBYTE)
558 (char_u *)&p_ambw, PV_NONE,
559 {(char_u *)"single", (char_u *)0L}
560#else
561 (char_u *)NULL, PV_NONE,
562 {(char_u *)0L, (char_u *)0L}
563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100568 {(char_u *)FALSE, (char_u *)0L}
569#else
570 (char_u *)NULL, PV_NONE,
571 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100573 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autoindent", "ai", P_BOOL|P_VI_DEF,
575 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autoprint", "ap", P_BOOL|P_VI_DEF,
578 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000581 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"autowrite", "aw", P_BOOL|P_VI_DEF,
584 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"autowriteall","awa", P_BOOL|P_VI_DEF,
587 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
590 (char_u *)&p_bg, PV_NONE,
591 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100592#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)"dark",
594#else
595 (char_u *)"light",
596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200598 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
602 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200604 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200605 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606#ifdef UNIX
607 {(char_u *)"yes", (char_u *)"auto"}
608#else
609 {(char_u *)"auto", (char_u *)"auto"}
610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200612 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
613 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000616 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 (char_u *)&p_bex, PV_NONE,
618 {
619#ifdef VMS
620 (char_u *)"_",
621#else
622 (char_u *)"~",
623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200625 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#ifdef FEAT_WILDIGN
627 (char_u *)&p_bsk, PV_NONE,
628 {(char_u *)"", (char_u *)0L}
629#else
630 (char_u *)NULL, PV_NONE,
631 {(char_u *)0L, (char_u *)0L}
632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000633 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100637 {(char_u *)600L, (char_u *)0L}
638#else
639 (char_u *)NULL, PV_NONE,
640 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100642 SCRIPTID_INIT},
643 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
644#ifdef FEAT_BEVAL
645 (char_u *)&p_beval, PV_NONE,
646 {(char_u *)FALSE, (char_u *)0L}
647#else
648 (char_u *)NULL, PV_NONE,
649 {(char_u *)0L, (char_u *)0L}
650#endif
651 SCRIPTID_INIT},
652 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
653#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
654 (char_u *)&p_bexpr, PV_BEXPR,
655 {(char_u *)"", (char_u *)0L}
656#else
657 (char_u *)NULL, PV_NONE,
658 {(char_u *)0L, (char_u *)0L}
659#endif
660 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"beautify", "bf", P_BOOL|P_VI_DEF,
662 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000663 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200664 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
665 (char_u *)&p_bo, PV_NONE,
666 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
668 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000669 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
674#ifdef FEAT_MBYTE
675 (char_u *)&p_bomb, PV_BOMB,
676#else
677 (char_u *)NULL, PV_NONE,
678#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000679 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
681#ifdef FEAT_LINEBREAK
682 (char_u *)&p_breakat, PV_NONE,
683 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
684#else
685 (char_u *)NULL, PV_NONE,
686 {(char_u *)0L, (char_u *)0L}
687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000688 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200689 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
690#ifdef FEAT_LINEBREAK
691 (char_u *)VAR_WIN, PV_BRI,
692 {(char_u *)FALSE, (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
697 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200698 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
699 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200700#ifdef FEAT_LINEBREAK
701 (char_u *)VAR_WIN, PV_BRIOPT,
702 {(char_u *)"", (char_u *)NULL}
703#else
704 (char_u *)NULL, PV_NONE,
705 {(char_u *)"", (char_u *)NULL}
706#endif
707 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
709#ifdef FEAT_BROWSE
710 (char_u *)&p_bsdir, PV_NONE,
711 {(char_u *)"last", (char_u *)0L}
712#else
713 (char_u *)NULL, PV_NONE,
714 {(char_u *)0L, (char_u *)0L}
715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000716 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
718#if defined(FEAT_QUICKFIX)
719 (char_u *)&p_bh, PV_BH,
720 {(char_u *)"", (char_u *)0L}
721#else
722 (char_u *)NULL, PV_NONE,
723 {(char_u *)0L, (char_u *)0L}
724#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000725 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
727 (char_u *)&p_bl, PV_BL,
728 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
731#if defined(FEAT_QUICKFIX)
732 (char_u *)&p_bt, PV_BT,
733 {(char_u *)"", (char_u *)0L}
734#else
735 (char_u *)NULL, PV_NONE,
736 {(char_u *)0L, (char_u *)0L}
737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000738 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200739 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000740#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 (char_u *)&p_cmp, PV_NONE,
742 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000743#else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
749#ifdef FEAT_SEARCHPATH
750 (char_u *)&p_cdpath, PV_NONE,
751 {(char_u *)",,", (char_u *)0L}
752#else
753 (char_u *)NULL, PV_NONE,
754 {(char_u *)0L, (char_u *)0L}
755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 {"cedit", NULL, P_STRING,
758#ifdef FEAT_CMDWIN
759 (char_u *)&p_cedit, PV_NONE,
760 {(char_u *)"", (char_u *)CTRL_F_STR}
761#else
762 (char_u *)NULL, PV_NONE,
763 {(char_u *)0L, (char_u *)0L}
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
767#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
768 (char_u *)&p_ccv, PV_NONE,
769 {(char_u *)"", (char_u *)0L}
770#else
771 (char_u *)NULL, PV_NONE,
772 {(char_u *)0L, (char_u *)0L}
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
776#ifdef FEAT_CINDENT
777 (char_u *)&p_cin, PV_CIN,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000781 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200782 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783#ifdef FEAT_CINDENT
784 (char_u *)&p_cink, PV_CINK,
785 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#ifdef FEAT_CINDENT
793 (char_u *)&p_cino, PV_CINO,
794#else
795 (char_u *)NULL, PV_NONE,
796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200798 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000799#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
800 (char_u *)&p_cinw, PV_CINW,
801 {(char_u *)"if,else,while,do,for,switch",
802 (char_u *)0L}
803#else
804 (char_u *)NULL, PV_NONE,
805 {(char_u *)0L, (char_u *)0L}
806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200808 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809#ifdef FEAT_CLIPBOARD
810 (char_u *)&p_cb, PV_NONE,
811# ifdef FEAT_XCLIPBOARD
812 {(char_u *)"autoselect,exclude:cons\\|linux",
813 (char_u *)0L}
814# else
815 {(char_u *)"", (char_u *)0L}
816# endif
817#else
818 (char_u *)NULL, PV_NONE,
819 {(char_u *)"", (char_u *)0L}
820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000821 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
823 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000825 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
826#ifdef FEAT_CMDWIN
827 (char_u *)&p_cwh, PV_NONE,
828#else
829 (char_u *)NULL, PV_NONE,
830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200832 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200833#ifdef FEAT_SYN_HL
834 (char_u *)VAR_WIN, PV_CC,
835#else
836 (char_u *)NULL, PV_NONE,
837#endif
838 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
840 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000841 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200842 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
843 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844#ifdef FEAT_COMMENTS
845 (char_u *)&p_com, PV_COM,
846 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
847 (char_u *)0L}
848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200853 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000854#ifdef FEAT_FOLDING
855 (char_u *)&p_cms, PV_CMS,
856 {(char_u *)"/*%s*/", (char_u *)0L}
857#else
858 (char_u *)NULL, PV_NONE,
859 {(char_u *)0L, (char_u *)0L}
860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000861 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000862 /* P_PRI_MKRC isn't needed here, optval_default()
863 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000864 {"compatible", "cp", P_BOOL|P_RALL,
865 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200867 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868#ifdef FEAT_INS_EXPAND
869 (char_u *)&p_cpt, PV_CPT,
870 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
871#else
872 (char_u *)NULL, PV_NONE,
873 {(char_u *)0L, (char_u *)0L}
874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000875 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200876 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200877#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200878 (char_u *)VAR_WIN, PV_COCU,
879 {(char_u *)"", (char_u *)NULL}
880#else
881 (char_u *)NULL, PV_NONE,
882 {(char_u *)NULL, (char_u *)0L}
883#endif
884 SCRIPTID_INIT},
885 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
886#ifdef FEAT_CONCEAL
887 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200888#else
889 (char_u *)NULL, PV_NONE,
890#endif
891 {(char_u *)0L, (char_u *)0L}
892 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000893 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
894#ifdef FEAT_COMPL_FUNC
895 (char_u *)&p_cfu, PV_CFU,
896 {(char_u *)"", (char_u *)0L}
897#else
898 (char_u *)NULL, PV_NONE,
899 {(char_u *)0L, (char_u *)0L}
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200902 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000903#ifdef FEAT_INS_EXPAND
904 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000905 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000906#else
907 (char_u *)NULL, PV_NONE,
908 {(char_u *)0L, (char_u *)0L}
909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"confirm", "cf", P_BOOL|P_VI_DEF,
912#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
913 (char_u *)&p_confirm, PV_NONE,
914#else
915 (char_u *)NULL, PV_NONE,
916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
922 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
925 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
927 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200930 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200931 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200932#else
933 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200934 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200935#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_cspc, PV_NONE,
940#else
941 (char_u *)NULL, PV_NONE,
942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000943 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_csprg, PV_NONE,
947 {(char_u *)"cscope", (char_u *)0L}
948#else
949 (char_u *)NULL, PV_NONE,
950 {(char_u *)0L, (char_u *)0L}
951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000952 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200953 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000954#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
955 (char_u *)&p_csqf, PV_NONE,
956 {(char_u *)"", (char_u *)0L}
957#else
958 (char_u *)NULL, PV_NONE,
959 {(char_u *)0L, (char_u *)0L}
960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000961 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200962 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
963#ifdef FEAT_CSCOPE
964 (char_u *)&p_csre, PV_NONE,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
968 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
970#ifdef FEAT_CSCOPE
971 (char_u *)&p_cst, PV_NONE,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
977#ifdef FEAT_CSCOPE
978 (char_u *)&p_csto, PV_NONE,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
984#ifdef FEAT_CSCOPE
985 (char_u *)&p_csverbose, PV_NONE,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200990 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
991#ifdef FEAT_CURSORBIND
992 (char_u *)VAR_WIN, PV_CRBIND,
993#else
994 (char_u *)NULL, PV_NONE,
995#endif
996 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
998#ifdef FEAT_SYN_HL
999 (char_u *)VAR_WIN, PV_CUC,
1000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +01001004 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001005#ifdef FEAT_SYN_HL
1006 (char_u *)VAR_WIN, PV_CUL,
1007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 {"debug", NULL, P_STRING|P_VI_DEF,
1012 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001014 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001016 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001017 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018#else
1019 (char_u *)NULL, PV_NONE,
1020 {(char_u *)NULL, (char_u *)0L}
1021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001022 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1024#ifdef FEAT_MBYTE
1025 (char_u *)&p_deco, PV_NONE,
1026#else
1027 (char_u *)NULL, PV_NONE,
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001030 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001032 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1038#ifdef FEAT_DIFF
1039 (char_u *)VAR_WIN, PV_DIFF,
1040#else
1041 (char_u *)NULL, PV_NONE,
1042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001044 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1046 (char_u *)&p_dex, PV_NONE,
1047 {(char_u *)"", (char_u *)0L}
1048#else
1049 (char_u *)NULL, PV_NONE,
1050 {(char_u *)0L, (char_u *)0L}
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1054 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055#ifdef FEAT_DIFF
1056 (char_u *)&p_dip, PV_NONE,
1057 {(char_u *)"filler", (char_u *)NULL}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)"", (char_u *)NULL}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1064#ifdef FEAT_DIGRAPHS
1065 (char_u *)&p_dg, PV_NONE,
1066#else
1067 (char_u *)NULL, PV_NONE,
1068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001070 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1071 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001074 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001078#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 (char_u *)&p_ead, PV_NONE,
1080 {(char_u *)"both", (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)NULL, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1087 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001089 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1090#if defined(FEAT_MBYTE)
1091 (char_u *)&p_emoji, PV_NONE,
1092 {(char_u *)TRUE, (char_u *)0L}
1093#else
1094 (char_u *)NULL, PV_NONE,
1095 {(char_u *)0L, (char_u *)0L}
1096#endif
1097 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001098 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099#ifdef FEAT_MBYTE
1100 (char_u *)&p_enc, PV_NONE,
1101 {(char_u *)ENC_DFLT, (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)0L, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1108 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1111 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001114 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1117 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1120#ifdef FEAT_QUICKFIX
1121 (char_u *)&p_ef, PV_NONE,
1122 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)NULL, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001130 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132#else
1133 (char_u *)NULL, PV_NONE,
1134 {(char_u *)NULL, (char_u *)0L}
1135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"esckeys", "ek", P_BOOL|P_VIM,
1138 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141#ifdef FEAT_AUTOCMD
1142 (char_u *)&p_ei, PV_NONE,
1143#else
1144 (char_u *)NULL, PV_NONE,
1145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1148 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1151 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001153 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1154 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155#ifdef FEAT_MBYTE
1156 (char_u *)&p_fenc, PV_FENC,
1157 {(char_u *)"", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)0L, (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164#ifdef FEAT_MBYTE
1165 (char_u *)&p_fencs, PV_NONE,
1166 {(char_u *)"ucs-bom", (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)0L, (char_u *)0L}
1170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001172 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1173 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001174 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001176 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1179 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001180 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1181 (char_u *)&p_fic, PV_NONE,
1182 {
1183#ifdef CASE_INSENSITIVE_FILENAME
1184 (char_u *)TRUE,
1185#else
1186 (char_u *)FALSE,
1187#endif
1188 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001189 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190#ifdef FEAT_AUTOCMD
1191 (char_u *)&p_ft, PV_FT,
1192 {(char_u *)"", (char_u *)0L}
1193#else
1194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)0L, (char_u *)0L}
1196#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001198 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1200 (char_u *)&p_fcs, PV_NONE,
1201 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1202#else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)"", (char_u *)0L}
1205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001207 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1208 (char_u *)&p_fixeol, PV_FIXEOL,
1209 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1211#ifdef FEAT_FKMAP
1212 (char_u *)&p_fkmap, PV_NONE,
1213#else
1214 (char_u *)NULL, PV_NONE,
1215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"flash", "fl", P_BOOL|P_VI_DEF,
1218 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001220 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001223 {(char_u *)"", (char_u *)0L}
1224#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227#endif
1228 SCRIPTID_INIT},
1229 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1230#ifdef FEAT_FOLDING
1231 (char_u *)VAR_WIN, PV_FDC,
1232 {(char_u *)FALSE, (char_u *)0L}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
1237 SCRIPTID_INIT},
1238 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1239#ifdef FEAT_FOLDING
1240 (char_u *)VAR_WIN, PV_FEN,
1241 {(char_u *)TRUE, (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
1247 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1248#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1249 (char_u *)VAR_WIN, PV_FDE,
1250 {(char_u *)"0", (char_u *)NULL}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001259 {(char_u *)"#", (char_u *)NULL}
1260#else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)NULL, (char_u *)0L}
1263#endif
1264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001266#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001268 {(char_u *)0L, (char_u *)0L}
1269#else
1270 (char_u *)NULL, PV_NONE,
1271 {(char_u *)NULL, (char_u *)0L}
1272#endif
1273 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001274 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001275#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001277 {(char_u *)-1L, (char_u *)0L}
1278#else
1279 (char_u *)NULL, PV_NONE,
1280 {(char_u *)NULL, (char_u *)0L}
1281#endif
1282 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001284 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001285#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001288#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001292 SCRIPTID_INIT},
1293 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1294#ifdef FEAT_FOLDING
1295 (char_u *)VAR_WIN, PV_FDM,
1296 {(char_u *)"manual", (char_u *)NULL}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
1301 SCRIPTID_INIT},
1302 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1303#ifdef FEAT_FOLDING
1304 (char_u *)VAR_WIN, PV_FML,
1305 {(char_u *)1L, (char_u *)0L}
1306#else
1307 (char_u *)NULL, PV_NONE,
1308 {(char_u *)NULL, (char_u *)0L}
1309#endif
1310 SCRIPTID_INIT},
1311 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1312#ifdef FEAT_FOLDING
1313 (char_u *)VAR_WIN, PV_FDN,
1314 {(char_u *)20L, (char_u *)0L}
1315#else
1316 (char_u *)NULL, PV_NONE,
1317 {(char_u *)NULL, (char_u *)0L}
1318#endif
1319 SCRIPTID_INIT},
1320 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1321#ifdef FEAT_FOLDING
1322 (char_u *)&p_fdo, PV_NONE,
1323 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1324 (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)NULL, (char_u *)0L}
1328#endif
1329 SCRIPTID_INIT},
1330 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1331#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1332 (char_u *)VAR_WIN, PV_FDT,
1333 {(char_u *)"foldtext()", (char_u *)NULL}
1334#else
1335 (char_u *)NULL, PV_NONE,
1336 {(char_u *)NULL, (char_u *)0L}
1337#endif
1338 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001339 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001340#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001341 (char_u *)&p_fex, PV_FEX,
1342 {(char_u *)"", (char_u *)0L}
1343#else
1344 (char_u *)NULL, PV_NONE,
1345 {(char_u *)0L, (char_u *)0L}
1346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1349 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1351 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001352 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1353 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001354 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1355 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001357 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001358 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001359 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1360#ifdef HAVE_FSYNC
1361 (char_u *)&p_fs, PV_NONE,
1362 {(char_u *)TRUE, (char_u *)0L}
1363#else
1364 (char_u *)NULL, PV_NONE,
1365 {(char_u *)FALSE, (char_u *)0L}
1366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1369 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371 {"graphic", "gr", P_BOOL|P_VI_DEF,
1372 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001374 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375#ifdef FEAT_QUICKFIX
1376 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001377 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378#else
1379 (char_u *)NULL, PV_NONE,
1380 {(char_u *)NULL, (char_u *)0L}
1381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1384#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001385 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {
1387# ifdef WIN3264
1388 /* may be changed to "grep -n" in os_win32.c */
1389 (char_u *)"findstr /n",
1390# else
1391# ifdef UNIX
1392 /* Add an extra file name so that grep will always
1393 * insert a file name in the match line. */
1394 (char_u *)"grep -n $* /dev/null",
1395# else
1396# ifdef VMS
1397 (char_u *)"SEARCH/NUMBERS ",
1398# else
1399 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400# endif
1401# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#else
1405 (char_u *)NULL, PV_NONE,
1406 {(char_u *)NULL, (char_u *)0L}
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001409 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410#ifdef CURSOR_SHAPE
1411 (char_u *)&p_guicursor, PV_NONE,
1412 {
1413# ifdef FEAT_GUI
1414 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001415# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1417# endif
1418 (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425#ifdef FEAT_GUI
1426 (char_u *)&p_guifont, PV_NONE,
1427 {(char_u *)"", (char_u *)0L}
1428#else
1429 (char_u *)NULL, PV_NONE,
1430 {(char_u *)NULL, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001433 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1435 (char_u *)&p_guifontset, PV_NONE,
1436 {(char_u *)"", (char_u *)0L}
1437#else
1438 (char_u *)NULL, PV_NONE,
1439 {(char_u *)NULL, (char_u *)0L}
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001442 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1444 (char_u *)&p_guifontwide, PV_NONE,
1445 {(char_u *)"", (char_u *)0L}
1446#else
1447 (char_u *)NULL, PV_NONE,
1448 {(char_u *)NULL, (char_u *)0L}
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001452#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 (char_u *)&p_ghr, PV_NONE,
1454#else
1455 (char_u *)NULL, PV_NONE,
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001459#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460 (char_u *)&p_go, PV_NONE,
1461# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001462 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001464 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465# endif
1466#else
1467 (char_u *)NULL, PV_NONE,
1468 {(char_u *)NULL, (char_u *)0L}
1469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"guipty", NULL, P_BOOL|P_VI_DEF,
1472#if defined(FEAT_GUI)
1473 (char_u *)&p_guipty, PV_NONE,
1474#else
1475 (char_u *)NULL, PV_NONE,
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001478 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001479#if defined(FEAT_GUI_TABLINE)
1480 (char_u *)&p_gtl, PV_NONE,
1481 {(char_u *)"", (char_u *)0L}
1482#else
1483 (char_u *)NULL, PV_NONE,
1484 {(char_u *)NULL, (char_u *)0L}
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001487 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001488#if defined(FEAT_GUI_TABLINE)
1489 (char_u *)&p_gtt, PV_NONE,
1490 {(char_u *)"", (char_u *)0L}
1491#else
1492 (char_u *)NULL, PV_NONE,
1493 {(char_u *)NULL, (char_u *)0L}
1494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1497 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001498 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1500 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001501 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1502 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"helpheight", "hh", P_NUM|P_VI_DEF,
1504#ifdef FEAT_WINDOWS
1505 (char_u *)&p_hh, PV_NONE,
1506#else
1507 (char_u *)NULL, PV_NONE,
1508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001509 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001510 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511#ifdef FEAT_MULTI_LANG
1512 (char_u *)&p_hlg, PV_NONE,
1513 {(char_u *)"", (char_u *)0L}
1514#else
1515 (char_u *)NULL, PV_NONE,
1516 {(char_u *)0L, (char_u *)0L}
1517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {"hidden", "hid", P_BOOL|P_VI_DEF,
1520 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001522 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001524 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1525 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001526 {"history", "hi", P_NUM|P_VIM,
1527 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001528 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1530#ifdef FEAT_RIGHTLEFT
1531 (char_u *)&p_hkmap, PV_NONE,
1532#else
1533 (char_u *)NULL, PV_NONE,
1534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1537#ifdef FEAT_RIGHTLEFT
1538 (char_u *)&p_hkmapp, PV_NONE,
1539#else
1540 (char_u *)NULL, PV_NONE,
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1544 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"icon", NULL, P_BOOL|P_VI_DEF,
1547#ifdef FEAT_TITLE
1548 (char_u *)&p_icon, PV_NONE,
1549#else
1550 (char_u *)NULL, PV_NONE,
1551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"iconstring", NULL, P_STRING|P_VI_DEF,
1554#ifdef FEAT_TITLE
1555 (char_u *)&p_iconstring, PV_NONE,
1556#else
1557 (char_u *)NULL, PV_NONE,
1558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001559 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001560 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1561 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001563 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1564# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1565 (char_u *)&p_imaf, PV_NONE,
1566 {(char_u *)"", (char_u *)NULL}
1567# else
1568 (char_u *)NULL, PV_NONE,
1569 {(char_u *)NULL, (char_u *)0L}
1570# endif
1571 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001573#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 (char_u *)&p_imak, PV_NONE,
1575#else
1576 (char_u *)NULL, PV_NONE,
1577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001578 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1580#ifdef USE_IM_CONTROL
1581 (char_u *)&p_imcmdline, PV_NONE,
1582#else
1583 (char_u *)NULL, PV_NONE,
1584#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001586 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1587#ifdef USE_IM_CONTROL
1588 (char_u *)&p_imdisable, PV_NONE,
1589#else
1590 (char_u *)NULL, PV_NONE,
1591#endif
1592#ifdef __sgi
1593 {(char_u *)TRUE, (char_u *)0L}
1594#else
1595 {(char_u *)FALSE, (char_u *)0L}
1596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"iminsert", "imi", P_NUM|P_VI_DEF,
1599 (char_u *)&p_iminsert, PV_IMI,
1600#ifdef B_IMODE_IM
1601 {(char_u *)B_IMODE_IM, (char_u *)0L}
1602#else
1603 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001605 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"imsearch", "ims", P_NUM|P_VI_DEF,
1607 (char_u *)&p_imsearch, PV_IMS,
1608#ifdef B_IMODE_IM
1609 {(char_u *)B_IMODE_IM, (char_u *)0L}
1610#else
1611 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001613 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001614 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001615# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1616 (char_u *)&p_imsf, PV_NONE,
1617 {(char_u *)"", (char_u *)NULL}
1618# else
1619 (char_u *)NULL, PV_NONE,
1620 {(char_u *)NULL, (char_u *)0L}
1621# endif
1622 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1624#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001625 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1633#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1634 (char_u *)&p_inex, PV_INEX,
1635 {(char_u *)"", (char_u *)0L}
1636#else
1637 (char_u *)NULL, PV_NONE,
1638 {(char_u *)0L, (char_u *)0L}
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1642 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1645#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1646 (char_u *)&p_inde, PV_INDE,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)0L, (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001653 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1655 (char_u *)&p_indk, PV_INDK,
1656 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1657#else
1658 (char_u *)NULL, PV_NONE,
1659 {(char_u *)0L, (char_u *)0L}
1660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 {"infercase", "inf", P_BOOL|P_VI_DEF,
1663 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1666 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1669 (char_u *)&p_isf, PV_NONE,
1670 {
1671#ifdef BACKSLASH_IN_FILENAME
1672 /* Excluded are: & and ^ are special in cmd.exe
1673 * ( and ) are used in text separating fnames */
1674 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1675#else
1676# ifdef AMIGA
1677 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1678# else
1679# ifdef VMS
1680 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1681# else /* UNIX et al. */
1682# ifdef EBCDIC
1683 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1684# else
1685 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1686# endif
1687# endif
1688# endif
1689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001690 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1692 (char_u *)&p_isi, PV_NONE,
1693 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001694#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695 (char_u *)"@,48-57,_,128-167,224-235",
1696#else
1697# ifdef EBCDIC
1698 /* TODO: EBCDIC Check this! @ == isalpha()*/
1699 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1700 "112-120,128,140-142,156,158,172,"
1701 "174,186,191,203-207,219-225,235-239,"
1702 "251-254",
1703# else
1704 (char_u *)"@,48-57,_,192-255",
1705# endif
1706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1709 (char_u *)&p_isk, PV_ISK,
1710 {
1711#ifdef EBCDIC
1712 (char_u *)"@,240-249,_",
1713 /* TODO: EBCDIC Check this! @ == isalpha()*/
1714 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1715 "112-120,128,140-142,156,158,172,"
1716 "174,186,191,203-207,219-225,235-239,"
1717 "251-254",
1718#else
1719 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001720# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721 (char_u *)"@,48-57,_,128-167,224-235"
1722# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001723 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724# endif
1725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1728 (char_u *)&p_isp, PV_NONE,
1729 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001730#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 || defined(VMS)
1732 (char_u *)"@,~-255",
1733#else
1734# ifdef EBCDIC
1735 /* all chars above 63 are printable */
1736 (char_u *)"63-255",
1737# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001738 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739# endif
1740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1743 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001744 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1746#ifdef FEAT_CRYPT
1747 (char_u *)&p_key, PV_KEY,
1748 {(char_u *)"", (char_u *)0L}
1749#else
1750 (char_u *)NULL, PV_NONE,
1751 {(char_u *)0L, (char_u *)0L}
1752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001754 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755#ifdef FEAT_KEYMAP
1756 (char_u *)&p_keymap, PV_KMAP,
1757 {(char_u *)"", (char_u *)0L}
1758#else
1759 (char_u *)NULL, PV_NONE,
1760 {(char_u *)"", (char_u *)0L}
1761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001762 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001763 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001765 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001767 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001769#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 (char_u *)":help",
1771#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001772# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001774# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001775# ifdef USEMAN_S
1776 (char_u *)"man -s",
1777# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001779# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780# endif
1781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001783 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784#ifdef FEAT_LANGMAP
1785 (char_u *)&p_langmap, PV_NONE,
1786 {(char_u *)"", /* unmatched } */
1787#else
1788 (char_u *)NULL, PV_NONE,
1789 {(char_u *)NULL,
1790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001792 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1794 (char_u *)&p_lm, PV_NONE,
1795#else
1796 (char_u *)NULL, PV_NONE,
1797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001798 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001799 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1800#ifdef FEAT_LANGMAP
1801 (char_u *)&p_lnr, PV_NONE,
1802#else
1803 (char_u *)NULL, PV_NONE,
1804#endif
1805 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001806 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1807#ifdef FEAT_LANGMAP
1808 (char_u *)&p_lrm, PV_NONE,
1809#else
1810 (char_u *)NULL, PV_NONE,
1811#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001812 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1814#ifdef FEAT_WINDOWS
1815 (char_u *)&p_ls, PV_NONE,
1816#else
1817 (char_u *)NULL, PV_NONE,
1818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1821 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1824#ifdef FEAT_LINEBREAK
1825 (char_u *)VAR_WIN, PV_LBR,
1826#else
1827 (char_u *)NULL, PV_NONE,
1828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001829 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1831 (char_u *)&Rows, PV_NONE,
1832 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001833#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834 (char_u *)25L,
1835#else
1836 (char_u *)24L,
1837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1840#ifdef FEAT_GUI
1841 (char_u *)&p_linespace, PV_NONE,
1842#else
1843 (char_u *)NULL, PV_NONE,
1844#endif
1845#ifdef FEAT_GUI_W32
1846 {(char_u *)1L, (char_u *)0L}
1847#else
1848 {(char_u *)0L, (char_u *)0L}
1849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"lisp", NULL, P_BOOL|P_VI_DEF,
1852#ifdef FEAT_LISP
1853 (char_u *)&p_lisp, PV_LISP,
1854#else
1855 (char_u *)NULL, PV_NONE,
1856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001858 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001860 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1862#else
1863 (char_u *)NULL, PV_NONE,
1864 {(char_u *)"", (char_u *)0L}
1865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1868 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001870 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1874 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001876 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001877#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001878 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001879 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001880#else
1881 (char_u *)NULL, PV_NONE,
1882 {(char_u *)"", (char_u *)0L}
1883#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001884 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001885 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001886#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001887 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001888 {(char_u *)TRUE, (char_u *)0L}
1889#else
1890 (char_u *)NULL, PV_NONE,
1891 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001892#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001893 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"magic", NULL, P_BOOL|P_VI_DEF,
1895 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001897 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898#ifdef FEAT_QUICKFIX
1899 (char_u *)&p_mef, PV_NONE,
1900 {(char_u *)"", (char_u *)0L}
1901#else
1902 (char_u *)NULL, PV_NONE,
1903 {(char_u *)NULL, (char_u *)0L}
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001906 {"makeencoding","menc", P_STRING|P_VI_DEF,
1907#ifdef FEAT_MBYTE
1908 (char_u *)&p_menc, PV_MENC,
1909 {(char_u *)"", (char_u *)0L}
1910#else
1911 (char_u *)NULL, PV_NONE,
1912 {(char_u *)0L, (char_u *)0L}
1913#endif
1914 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1916#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001917 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918# ifdef VMS
1919 {(char_u *)"MMS", (char_u *)0L}
1920# else
1921 {(char_u *)"make", (char_u *)0L}
1922# endif
1923#else
1924 (char_u *)NULL, PV_NONE,
1925 {(char_u *)NULL, (char_u *)0L}
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001928 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1931 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 {"matchtime", "mat", P_NUM|P_VI_DEF,
1933 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001935 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001936#ifdef FEAT_MBYTE
1937 (char_u *)&p_mco, PV_NONE,
1938#else
1939 (char_u *)NULL, PV_NONE,
1940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1943#ifdef FEAT_EVAL
1944 (char_u *)&p_mfd, PV_NONE,
1945#else
1946 (char_u *)NULL, PV_NONE,
1947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001948 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001949 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1950 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"maxmem", "mm", P_NUM|P_VI_DEF,
1953 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1955 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001956 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1957 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1962 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"menuitems", "mis", P_NUM|P_VI_DEF,
1964#ifdef FEAT_MENU
1965 (char_u *)&p_mis, PV_NONE,
1966#else
1967 (char_u *)NULL, PV_NONE,
1968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"mesg", NULL, P_BOOL|P_VI_DEF,
1971 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001973 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001974#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001975 (char_u *)&p_msm, PV_NONE,
1976 {(char_u *)"460000,2000,500", (char_u *)0L}
1977#else
1978 (char_u *)NULL, PV_NONE,
1979 {(char_u *)0L, (char_u *)0L}
1980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"modeline", "ml", P_BOOL|P_VIM,
1983 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"modelines", "mls", P_NUM|P_VI_DEF,
1986 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1989 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1992 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"more", NULL, P_BOOL|P_VIM,
1995 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1998 (char_u *)&p_mouse, PV_NONE,
1999 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002000#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)"a",
2002#else
2003 (char_u *)"",
2004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2007#ifdef FEAT_GUI
2008 (char_u *)&p_mousef, PV_NONE,
2009#else
2010 (char_u *)NULL, PV_NONE,
2011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2014#ifdef FEAT_GUI
2015 (char_u *)&p_mh, PV_NONE,
2016#else
2017 (char_u *)NULL, PV_NONE,
2018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002019 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2021 (char_u *)&p_mousem, PV_NONE,
2022 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002023#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 (char_u *)"popup",
2025#else
2026# if defined(MACOS)
2027 (char_u *)"popup_setpos",
2028# else
2029 (char_u *)"extend",
2030# endif
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002033 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034#ifdef FEAT_MOUSESHAPE
2035 (char_u *)&p_mouseshape, PV_NONE,
2036 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2037#else
2038 (char_u *)NULL, PV_NONE,
2039 {(char_u *)NULL, (char_u *)0L}
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2043 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002045 {"mzquantum", "mzq", P_NUM,
2046#ifdef FEAT_MZSCHEME
2047 (char_u *)&p_mzq, PV_NONE,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"novice", NULL, P_BOOL|P_VI_DEF,
2053 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002055 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002057 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2060 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002062 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2063#ifdef FEAT_LINEBREAK
2064 (char_u *)VAR_WIN, PV_NUW,
2065#else
2066 (char_u *)NULL, PV_NONE,
2067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002068 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002069 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002070#ifdef FEAT_COMPL_FUNC
2071 (char_u *)&p_ofu, PV_OFU,
2072 {(char_u *)"", (char_u *)0L}
2073#else
2074 (char_u *)NULL, PV_NONE,
2075 {(char_u *)0L, (char_u *)0L}
2076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"open", NULL, P_BOOL|P_VI_DEF,
2079 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002081 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002082#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002083 (char_u *)&p_odev, PV_NONE,
2084#else
2085 (char_u *)NULL, PV_NONE,
2086#endif
2087 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002089 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2090 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"optimize", "opt", P_BOOL|P_VI_DEF,
2093 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002097 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002098 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2099 |P_SECURE,
2100 (char_u *)&p_pp, PV_NONE,
2101 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2102 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"paragraphs", "para", P_STRING|P_VI_DEF,
2104 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002105 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002106 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002107 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2111 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2114#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2115 (char_u *)&p_pex, PV_NONE,
2116 {(char_u *)"", (char_u *)0L}
2117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)0L, (char_u *)0L}
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002122 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002126 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002128#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 (char_u *)".,,",
2130#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002134 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002135#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002137 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002138#else
2139 (char_u *)NULL, PV_NONE,
2140 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002141#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002142 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2144 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002146 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2148 (char_u *)&p_pvh, PV_NONE,
2149#else
2150 (char_u *)NULL, PV_NONE,
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2154#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2155 (char_u *)VAR_WIN, PV_PVW,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002160 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161#ifdef FEAT_PRINTER
2162 (char_u *)&p_pdev, PV_NONE,
2163 {(char_u *)"", (char_u *)0L}
2164#else
2165 (char_u *)NULL, PV_NONE,
2166 {(char_u *)NULL, (char_u *)0L}
2167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"printencoding", "penc", P_STRING|P_VI_DEF,
2170#ifdef FEAT_POSTSCRIPT
2171 (char_u *)&p_penc, PV_NONE,
2172 {(char_u *)"", (char_u *)0L}
2173#else
2174 (char_u *)NULL, PV_NONE,
2175 {(char_u *)NULL, (char_u *)0L}
2176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002177 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002178 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179#ifdef FEAT_POSTSCRIPT
2180 (char_u *)&p_pexpr, PV_NONE,
2181 {(char_u *)"", (char_u *)0L}
2182#else
2183 (char_u *)NULL, PV_NONE,
2184 {(char_u *)NULL, (char_u *)0L}
2185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"printfont", "pfn", P_STRING|P_VI_DEF,
2188#ifdef FEAT_PRINTER
2189 (char_u *)&p_pfn, PV_NONE,
2190 {
2191# ifdef MSWIN
2192 (char_u *)"Courier_New:h10",
2193# else
2194 (char_u *)"courier",
2195# endif
2196 (char_u *)0L}
2197#else
2198 (char_u *)NULL, PV_NONE,
2199 {(char_u *)NULL, (char_u *)0L}
2200#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002201 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002202 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2203#ifdef FEAT_PRINTER
2204 (char_u *)&p_header, PV_NONE,
2205 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2206#else
2207 (char_u *)NULL, PV_NONE,
2208 {(char_u *)NULL, (char_u *)0L}
2209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002211 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2212#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2213 (char_u *)&p_pmcs, PV_NONE,
2214 {(char_u *)"", (char_u *)0L}
2215#else
2216 (char_u *)NULL, PV_NONE,
2217 {(char_u *)NULL, (char_u *)0L}
2218#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002220 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2221#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2222 (char_u *)&p_pmfn, PV_NONE,
2223 {(char_u *)"", (char_u *)0L}
2224#else
2225 (char_u *)NULL, PV_NONE,
2226 {(char_u *)NULL, (char_u *)0L}
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002229 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230#ifdef FEAT_PRINTER
2231 (char_u *)&p_popt, PV_NONE,
2232 {(char_u *)"", (char_u *)0L}
2233#else
2234 (char_u *)NULL, PV_NONE,
2235 {(char_u *)NULL, (char_u *)0L}
2236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002239 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002241 {"pumheight", "ph", P_NUM|P_VI_DEF,
2242#ifdef FEAT_INS_EXPAND
2243 (char_u *)&p_ph, PV_NONE,
2244#else
2245 (char_u *)NULL, PV_NONE,
2246#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002247 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002248 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002249#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002250 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002251 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002252#else
2253 (char_u *)NULL, PV_NONE,
2254 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002255#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002256 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002257 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002258#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002259 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002260 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002261#else
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002264#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002265 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002266 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2267#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2268 (char_u *)&p_pyx, PV_NONE,
2269#else
2270 (char_u *)NULL, PV_NONE,
2271#endif
2272 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2273 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002274 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2275#ifdef FEAT_TEXTOBJ
2276 (char_u *)&p_qe, PV_QE,
2277 {(char_u *)"\\", (char_u *)0L}
2278#else
2279 (char_u *)NULL, PV_NONE,
2280 {(char_u *)NULL, (char_u *)0L}
2281#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2284 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"redraw", NULL, P_BOOL|P_VI_DEF,
2287 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002289 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2290#ifdef FEAT_RELTIME
2291 (char_u *)&p_rdt, PV_NONE,
2292#else
2293 (char_u *)NULL, PV_NONE,
2294#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002296 {"regexpengine", "re", P_NUM|P_VI_DEF,
2297 (char_u *)&p_re, PV_NONE,
2298 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002299 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2300 (char_u *)VAR_WIN, PV_RNU,
2301 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"remap", NULL, P_BOOL|P_VI_DEF,
2303 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002305 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002306#ifdef FEAT_RENDER_OPTIONS
2307 (char_u *)&p_rop, PV_NONE,
2308 {(char_u *)"", (char_u *)0L}
2309#else
2310 (char_u *)NULL, PV_NONE,
2311 {(char_u *)NULL, (char_u *)0L}
2312#endif
2313 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"report", NULL, P_NUM|P_VI_DEF,
2315 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2318#ifdef WIN3264
2319 (char_u *)&p_rs, PV_NONE,
2320#else
2321 (char_u *)NULL, PV_NONE,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2325#ifdef FEAT_RIGHTLEFT
2326 (char_u *)&p_ri, PV_NONE,
2327#else
2328 (char_u *)NULL, PV_NONE,
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2332#ifdef FEAT_RIGHTLEFT
2333 (char_u *)VAR_WIN, PV_RL,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2339#ifdef FEAT_RIGHTLEFT
2340 (char_u *)VAR_WIN, PV_RLC,
2341 {(char_u *)"search", (char_u *)NULL}
2342#else
2343 (char_u *)NULL, PV_NONE,
2344 {(char_u *)NULL, (char_u *)0L}
2345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002347 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002348#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002349 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002350 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002351#else
2352 (char_u *)NULL, PV_NONE,
2353 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002354#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2357#ifdef FEAT_CMDL_INFO
2358 (char_u *)&p_ru, PV_NONE,
2359#else
2360 (char_u *)NULL, PV_NONE,
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2364#ifdef FEAT_STL_OPT
2365 (char_u *)&p_ruf, PV_NONE,
2366#else
2367 (char_u *)NULL, PV_NONE,
2368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002370 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2371 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2374 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2376 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2379#ifdef FEAT_SCROLLBIND
2380 (char_u *)VAR_WIN, PV_SCBIND,
2381#else
2382 (char_u *)NULL, PV_NONE,
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2386 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2389 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002391 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392#ifdef FEAT_SCROLLBIND
2393 (char_u *)&p_sbo, PV_NONE,
2394 {(char_u *)"ver,jump", (char_u *)0L}
2395#else
2396 (char_u *)NULL, PV_NONE,
2397 {(char_u *)0L, (char_u *)0L}
2398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"sections", "sect", P_STRING|P_VI_DEF,
2401 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2403 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2405 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)"inclusive", (char_u *)0L}
2410 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002411 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002414 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415#ifdef FEAT_SESSION
2416 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002417 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 (char_u *)0L}
2419#else
2420 (char_u *)NULL, PV_NONE,
2421 {(char_u *)0L, (char_u *)0L}
2422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2425 (char_u *)&p_sh, PV_NONE,
2426 {
2427#ifdef VMS
2428 (char_u *)"-",
2429#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002430# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002432# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434# endif
2435#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2438 (char_u *)&p_shcf, PV_NONE,
2439 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002440#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 (char_u *)"/c",
2442#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2447#ifdef FEAT_QUICKFIX
2448 (char_u *)&p_sp, PV_NONE,
2449 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002450#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452#else
2453 (char_u *)">",
2454#endif
2455 (char_u *)0L}
2456#else
2457 (char_u *)NULL, PV_NONE,
2458 {(char_u *)0L, (char_u *)0L}
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2462 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002463 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2465 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2468#ifdef BACKSLASH_IN_FILENAME
2469 (char_u *)&p_ssl, PV_NONE,
2470#else
2471 (char_u *)NULL, PV_NONE,
2472#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002474 {"shelltemp", "stmp", P_BOOL,
2475 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"shelltype", "st", P_NUM|P_VI_DEF,
2478#ifdef AMIGA
2479 (char_u *)&p_st, PV_NONE,
2480#else
2481 (char_u *)NULL, PV_NONE,
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2485 (char_u *)&p_sxq, PV_NONE,
2486 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002487#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 (char_u *)"\"",
2489#else
2490 (char_u *)"",
2491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002493 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2494 (char_u *)&p_sxe, PV_NONE,
2495 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002496#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002497 (char_u *)"\"&|<>()@^",
2498#else
2499 (char_u *)"",
2500#endif
2501 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2503 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2506 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2509 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)"", (char_u *)"filnxtToO"}
2511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2516#ifdef FEAT_LINEBREAK
2517 (char_u *)&p_sbr, PV_NONE,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"showcmd", "sc", P_BOOL|P_VIM,
2523#ifdef FEAT_CMDL_INFO
2524 (char_u *)&p_sc, PV_NONE,
2525#else
2526 (char_u *)NULL, PV_NONE,
2527#endif
2528 {(char_u *)FALSE,
2529#ifdef UNIX
2530 (char_u *)FALSE
2531#else
2532 (char_u *)TRUE
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2536 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2539 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"showmode", "smd", P_BOOL|P_VIM,
2542 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002544 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2545#ifdef FEAT_WINDOWS
2546 (char_u *)&p_stal, PV_NONE,
2547#else
2548 (char_u *)NULL, PV_NONE,
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2552 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2555 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002557 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2558#ifdef FEAT_SIGNS
2559 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002560 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)NULL, (char_u *)0L}
2564#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2567 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2570 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2573#ifdef FEAT_SMARTINDENT
2574 (char_u *)&p_si, PV_SI,
2575#else
2576 (char_u *)NULL, PV_NONE,
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2580 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2583 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2586 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002588 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002589#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002590 (char_u *)VAR_WIN, PV_SPELL,
2591#else
2592 (char_u *)NULL, PV_NONE,
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002595 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002596#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002597 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002598 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002604 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2605 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002606#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002607 (char_u *)&p_spf, PV_SPF,
2608 {(char_u *)"", (char_u *)0L}
2609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002614 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2615 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002616#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002617 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002618 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002619#else
2620 (char_u *)NULL, PV_NONE,
2621 {(char_u *)0L, (char_u *)0L}
2622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002624 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002625#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002626 (char_u *)&p_sps, PV_NONE,
2627 {(char_u *)"best", (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2634#ifdef FEAT_WINDOWS
2635 (char_u *)&p_sb, PV_NONE,
2636#else
2637 (char_u *)NULL, PV_NONE,
2638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002641#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 (char_u *)&p_spr, PV_NONE,
2643#else
2644 (char_u *)NULL, PV_NONE,
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2648 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2651#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002652 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653#else
2654 (char_u *)NULL, PV_NONE,
2655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002657 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 (char_u *)&p_su, PV_NONE,
2659 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002661 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002662#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 (char_u *)&p_sua, PV_SUA,
2664 {(char_u *)"", (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2671 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {"swapsync", "sws", P_STRING|P_VI_DEF,
2674 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002676 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002679 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2680#ifdef FEAT_SYN_HL
2681 (char_u *)&p_smc, PV_SMC,
2682 {(char_u *)3000L, (char_u *)0L}
2683#else
2684 (char_u *)NULL, PV_NONE,
2685 {(char_u *)0L, (char_u *)0L}
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002688 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689#ifdef FEAT_SYN_HL
2690 (char_u *)&p_syn, PV_SYN,
2691 {(char_u *)"", (char_u *)0L}
2692#else
2693 (char_u *)NULL, PV_NONE,
2694 {(char_u *)0L, (char_u *)0L}
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002697 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2698#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002699 (char_u *)&p_tal, PV_NONE,
2700#else
2701 (char_u *)NULL, PV_NONE,
2702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002704 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2705#ifdef FEAT_WINDOWS
2706 (char_u *)&p_tpm, PV_NONE,
2707#else
2708 (char_u *)NULL, PV_NONE,
2709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2712 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2715 (char_u *)&p_tbs, PV_NONE,
2716#ifdef VMS /* binary searching doesn't appear to work on VMS */
2717 {(char_u *)0L, (char_u *)0L}
2718#else
2719 {(char_u *)TRUE, (char_u *)0L}
2720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002722 {"tagcase", "tc", P_STRING|P_VIM,
2723 (char_u *)&p_tc, PV_TC,
2724 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"taglength", "tl", P_NUM|P_VI_DEF,
2726 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"tagrelative", "tr", P_BOOL|P_VIM,
2729 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002731 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002732 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {
2734#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2735 (char_u *)"./tags,./TAGS,tags,TAGS",
2736#else
2737 (char_u *)"./tags,tags",
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2741 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002742 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002743 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002744#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002745 (char_u *)&p_tcldll, PV_NONE,
2746 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002747#else
2748 (char_u *)NULL, PV_NONE,
2749 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002750#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2753 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002754 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2756#ifdef FEAT_ARABIC
2757 (char_u *)&p_tbidi, PV_NONE,
2758#else
2759 (char_u *)NULL, PV_NONE,
2760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2763#ifdef FEAT_MBYTE
2764 (char_u *)&p_tenc, PV_NONE,
2765 {(char_u *)"", (char_u *)0L}
2766#else
2767 (char_u *)NULL, PV_NONE,
2768 {(char_u *)0L, (char_u *)0L}
2769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002771 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2772#ifdef FEAT_TERMGUICOLORS
2773 (char_u *)&p_tgc, PV_NONE,
2774 {(char_u *)FALSE, (char_u *)FALSE}
2775#else
2776 (char_u*)NULL, PV_NONE,
2777 {(char_u *)FALSE, (char_u *)FALSE}
2778#endif
2779 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"terse", NULL, P_BOOL|P_VI_DEF,
2781 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"textauto", "ta", P_BOOL|P_VIM,
2784 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2788 (char_u *)&p_tx, PV_TX,
2789 {
2790#ifdef USE_CRNL
2791 (char_u *)TRUE,
2792#else
2793 (char_u *)FALSE,
2794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002796 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002799 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002801 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802#else
2803 (char_u *)NULL, PV_NONE,
2804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2807 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"timeout", "to", P_BOOL|P_VI_DEF,
2810 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2813 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"title", NULL, P_BOOL|P_VI_DEF,
2816#ifdef FEAT_TITLE
2817 (char_u *)&p_title, PV_NONE,
2818#else
2819 (char_u *)NULL, PV_NONE,
2820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"titlelen", NULL, P_NUM|P_VI_DEF,
2823#ifdef FEAT_TITLE
2824 (char_u *)&p_titlelen, PV_NONE,
2825#else
2826 (char_u *)NULL, PV_NONE,
2827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002829 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830#ifdef FEAT_TITLE
2831 (char_u *)&p_titleold, PV_NONE,
2832 {(char_u *)N_("Thanks for flying Vim"),
2833 (char_u *)0L}
2834#else
2835 (char_u *)NULL, PV_NONE,
2836 {(char_u *)0L, (char_u *)0L}
2837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"titlestring", NULL, P_STRING|P_VI_DEF,
2840#ifdef FEAT_TITLE
2841 (char_u *)&p_titlestring, PV_NONE,
2842#else
2843 (char_u *)NULL, PV_NONE,
2844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002846 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002847#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002850#else
2851 (char_u *)NULL, PV_NONE,
2852 {(char_u *)0L, (char_u *)0L}
2853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002856#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002858 {(char_u *)"small", (char_u *)0L}
2859#else
2860 (char_u *)NULL, PV_NONE,
2861 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002863 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2865 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2868 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2871 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2874 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2877#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2878 (char_u *)&p_ttym, PV_NONE,
2879#else
2880 (char_u *)NULL, PV_NONE,
2881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2884 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2887 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002889 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2890 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002891#ifdef FEAT_PERSISTENT_UNDO
2892 (char_u *)&p_udir, PV_NONE,
2893 {(char_u *)".", (char_u *)0L}
2894#else
2895 (char_u *)NULL, PV_NONE,
2896 {(char_u *)0L, (char_u *)0L}
2897#endif
2898 SCRIPTID_INIT},
2899 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2900#ifdef FEAT_PERSISTENT_UNDO
2901 (char_u *)&p_udf, PV_UDF,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
2905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002907 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002909#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 (char_u *)1000L,
2911#else
2912 (char_u *)100L,
2913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002915 {"undoreload", "ur", P_NUM|P_VI_DEF,
2916 (char_u *)&p_ur, PV_NONE,
2917 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"updatecount", "uc", P_NUM|P_VI_DEF,
2919 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"updatetime", "ut", P_NUM|P_VI_DEF,
2922 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002923 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 {"verbose", "vbs", P_NUM|P_VI_DEF,
2925 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002927 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2928 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2931#ifdef FEAT_SESSION
2932 (char_u *)&p_vdir, PV_NONE,
2933 {(char_u *)DFLT_VDIR, (char_u *)0L}
2934#else
2935 (char_u *)NULL, PV_NONE,
2936 {(char_u *)0L, (char_u *)0L}
2937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002939 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940#ifdef FEAT_SESSION
2941 (char_u *)&p_vop, PV_NONE,
2942 {(char_u *)"folds,options,cursor", (char_u *)0L}
2943#else
2944 (char_u *)NULL, PV_NONE,
2945 {(char_u *)0L, (char_u *)0L}
2946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002948 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949#ifdef FEAT_VIMINFO
2950 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002951#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002952 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953#else
2954# ifdef AMIGA
2955 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002956 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002958 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959# endif
2960#endif
2961#else
2962 (char_u *)NULL, PV_NONE,
2963 {(char_u *)0L, (char_u *)0L}
2964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002965 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002966 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2967 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968#ifdef FEAT_VIRTUALEDIT
2969 (char_u *)&p_ve, PV_NONE,
2970 {(char_u *)"", (char_u *)""}
2971#else
2972 (char_u *)NULL, PV_NONE,
2973 {(char_u *)0L, (char_u *)0L}
2974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002975 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2977 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 {"w300", NULL, P_NUM|P_VI_DEF,
2980 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 {"w1200", NULL, P_NUM|P_VI_DEF,
2983 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002984 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"w9600", NULL, P_NUM|P_VI_DEF,
2986 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"warn", NULL, P_BOOL|P_VI_DEF,
2989 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002990 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2992 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002994 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {"wildchar", "wc", P_NUM|P_VIM,
2998 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3000 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003001 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003003 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003004 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005#ifdef FEAT_WILDIGN
3006 (char_u *)&p_wig, PV_NONE,
3007#else
3008 (char_u *)NULL, PV_NONE,
3009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003010 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003011 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3012 (char_u *)&p_wic, PV_NONE,
3013 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3015#ifdef FEAT_WILDMENU
3016 (char_u *)&p_wmnu, PV_NONE,
3017#else
3018 (char_u *)NULL, PV_NONE,
3019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003021 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003023 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003024 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3025#ifdef FEAT_CMDL_COMPL
3026 (char_u *)&p_wop, PV_NONE,
3027 {(char_u *)"", (char_u *)0L}
3028#else
3029 (char_u *)NULL, PV_NONE,
3030 {(char_u *)NULL, (char_u *)0L}
3031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003032 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3034#ifdef FEAT_WAK
3035 (char_u *)&p_wak, PV_NONE,
3036 {(char_u *)"menu", (char_u *)0L}
3037#else
3038 (char_u *)NULL, PV_NONE,
3039 {(char_u *)NULL, (char_u *)0L}
3040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003043 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003044 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 {"winheight", "wh", P_NUM|P_VI_DEF,
3046#ifdef FEAT_WINDOWS
3047 (char_u *)&p_wh, PV_NONE,
3048#else
3049 (char_u *)NULL, PV_NONE,
3050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003051 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003053#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)VAR_WIN, PV_WFH,
3055#else
3056 (char_u *)NULL, PV_NONE,
3057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003058 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003059 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003060#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003061 (char_u *)VAR_WIN, PV_WFW,
3062#else
3063 (char_u *)NULL, PV_NONE,
3064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3067#ifdef FEAT_WINDOWS
3068 (char_u *)&p_wmh, PV_NONE,
3069#else
3070 (char_u *)NULL, PV_NONE,
3071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003072 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003074#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 (char_u *)&p_wmw, PV_NONE,
3076#else
3077 (char_u *)NULL, PV_NONE,
3078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003079 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003081#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 (char_u *)&p_wiw, PV_NONE,
3083#else
3084 (char_u *)NULL, PV_NONE,
3085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003086 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3088 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003089 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3091 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003092 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3094 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003095 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 {"write", NULL, P_BOOL|P_VI_DEF,
3097 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003098 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 {"writeany", "wa", P_BOOL|P_VI_DEF,
3100 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3103 (char_u *)&p_wb, PV_NONE,
3104 {
3105#ifdef FEAT_WRITEBACKUP
3106 (char_u *)TRUE,
3107#else
3108 (char_u *)FALSE,
3109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003110 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 {"writedelay", "wd", P_NUM|P_VI_DEF,
3112 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003113 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114
3115/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003116#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003118 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119
3120 p_term("t_AB", T_CAB)
3121 p_term("t_AF", T_CAF)
3122 p_term("t_AL", T_CAL)
3123 p_term("t_al", T_AL)
3124 p_term("t_bc", T_BC)
3125 p_term("t_cd", T_CD)
3126 p_term("t_ce", T_CE)
3127 p_term("t_cl", T_CL)
3128 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003129 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 p_term("t_Co", T_CCO)
3131 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003132 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003134#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 p_term("t_CV", T_CSV)
3136#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 p_term("t_da", T_DA)
3138 p_term("t_db", T_DB)
3139 p_term("t_DL", T_CDL)
3140 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003141 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 p_term("t_fs", T_FS)
3143 p_term("t_IE", T_CIE)
3144 p_term("t_IS", T_CIS)
3145 p_term("t_ke", T_KE)
3146 p_term("t_ks", T_KS)
3147 p_term("t_le", T_LE)
3148 p_term("t_mb", T_MB)
3149 p_term("t_md", T_MD)
3150 p_term("t_me", T_ME)
3151 p_term("t_mr", T_MR)
3152 p_term("t_ms", T_MS)
3153 p_term("t_nd", T_ND)
3154 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003155 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_RI", T_CRI)
3157 p_term("t_RV", T_CRV)
3158 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003160 p_term("t_Sf", T_CSF)
3161 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003163 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_te", T_TE)
3166 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003167 p_term("t_ts", T_TS)
3168 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_ue", T_UE)
3170 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003171 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_vb", T_VB)
3173 p_term("t_ve", T_VE)
3174 p_term("t_vi", T_VI)
3175 p_term("t_vs", T_VS)
3176 p_term("t_WP", T_CWP)
3177 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003178 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_xs", T_XS)
3180 p_term("t_ZH", T_CZH)
3181 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003182 p_term("t_8f", T_8F)
3183 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003184 p_term("t_BE", T_BE)
3185 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186
3187/* terminal key codes are not in here */
3188
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003189 /* end marker */
3190 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191};
3192
3193#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3194
3195#ifdef FEAT_MBYTE
3196static char *(p_ambw_values[]) = {"single", "double", NULL};
3197#endif
3198static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003199static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003201#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003202static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003203#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003204#ifdef FEAT_CMDL_COMPL
3205static char *(p_wop_values[]) = {"tagfile", NULL};
3206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207#ifdef FEAT_WAK
3208static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3209#endif
3210static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3212static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003214#ifdef FEAT_BROWSE
3215static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3216#endif
3217#ifdef FEAT_SCROLLBIND
3218static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3219#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003220static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003221#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3223#endif
3224#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003225# ifdef FEAT_AUTOCMD
3226static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3227# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003229# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3231#endif
3232static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3233#ifdef FEAT_FOLDING
3234static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003235# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003237# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 NULL};
3239static char *(p_fcl_values[]) = {"all", NULL};
3240#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003241#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003242static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003244#ifdef FEAT_SIGNS
3245static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static void set_option_default(int, int opt_flags, int compatible);
3249static void set_options_default(int opt_flags);
3250static char_u *term_bg_default(void);
3251static void did_set_option(int opt_idx, int opt_flags, int new_value);
3252static char_u *illegal_char(char_u *, int);
3253static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003255static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#endif
3257#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003260static char_u *option_expand(int opt_idx, char_u *val);
3261static void didset_options(void);
3262static void didset_options2(void);
3263static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003264#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003265static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003266#else
3267# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3268#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static void set_string_option_global(int opt_idx, char_u **varp);
3270static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3271static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3272static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003273#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003279#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static char_u *did_set_spell_option(int is_spellfile);
3281static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003282#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003283#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003285#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003286static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3287static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3288static void check_redraw(long_u flags);
3289static int findoption(char_u *);
3290static int find_key_option(char_u *);
3291static void showoptions(int all, int opt_flags);
3292static int optval_default(struct vimoption *, char_u *varp);
3293static void showoneopt(struct vimoption *, int opt_flags);
3294static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3295static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3296static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3297static int istermoption(struct vimoption *);
3298static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3299static char_u *get_varp(struct vimoption *);
3300static void option_value2string(struct vimoption *, int opt_flags);
3301static void check_winopt(winopt_T *wop);
3302static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003304static void langmap_init(void);
3305static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003307static void paste_option_changed(void);
3308static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003310static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3313static int check_opt_strings(char_u *val, char **values, int);
3314static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003315#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003316static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318
3319/*
3320 * Initialize the options, first part.
3321 *
3322 * Called only once from main(), just after creating the first buffer.
3323 */
3324 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003325set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326{
3327 char_u *p;
3328 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003329 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
3331#ifdef FEAT_LANGMAP
3332 langmap_init();
3333#endif
3334
3335 /* Be Vi compatible by default */
3336 p_cp = TRUE;
3337
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003338 /* Use POSIX compatibility when $VIM_POSIX is set. */
3339 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003340 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003341 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003342 set_string_default("shm", (char_u *)"A");
3343 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003344
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 /*
3346 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003347 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003349 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003350#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003351 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003353 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354# endif
3355#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003356 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 set_string_default("sh", p);
3358
3359#ifdef FEAT_WILDIGN
3360 /*
3361 * Set the default for 'backupskip' to include environment variables for
3362 * temp files.
3363 */
3364 {
3365# ifdef UNIX
3366 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3367# else
3368 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3369# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003370 int len;
3371 garray_T ga;
3372 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373
3374 ga_init2(&ga, 1, 100);
3375 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3376 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003377 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378# ifdef UNIX
3379 if (*names[n] == NUL)
3380 p = (char_u *)"/tmp";
3381 else
3382# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003383 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 if (p != NULL && *p != NUL)
3385 {
3386 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003387 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 if (ga_grow(&ga, len) == OK)
3389 {
3390 if (ga.ga_len > 0)
3391 STRCAT(ga.ga_data, ",");
3392 STRCAT(ga.ga_data, p);
3393 add_pathsep(ga.ga_data);
3394 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 ga.ga_len += len;
3396 }
3397 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003398 if (mustfree)
3399 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400 }
3401 if (ga.ga_data != NULL)
3402 {
3403 set_string_default("bsk", ga.ga_data);
3404 vim_free(ga.ga_data);
3405 }
3406 }
3407#endif
3408
3409 /*
3410 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3411 */
3412 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003413 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003415#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3416 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3417#endif
3418 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003421 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422#else
3423# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003424 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003425 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003427 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428# endif
3429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431 opt_idx = findoption((char_u *)"maxmem");
3432 if (opt_idx >= 0)
3433 {
3434#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003435 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3436 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003437#endif
3438 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3439 }
3440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 }
3442
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443#ifdef FEAT_SEARCHPATH
3444 {
3445 char_u *cdpath;
3446 char_u *buf;
3447 int i;
3448 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003449 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450
3451 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003452 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453 if (cdpath != NULL)
3454 {
3455 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3456 if (buf != NULL)
3457 {
3458 buf[0] = ','; /* start with ",", current dir first */
3459 j = 1;
3460 for (i = 0; cdpath[i] != NUL; ++i)
3461 {
3462 if (vim_ispathlistsep(cdpath[i]))
3463 buf[j++] = ',';
3464 else
3465 {
3466 if (cdpath[i] == ' ' || cdpath[i] == ',')
3467 buf[j++] = '\\';
3468 buf[j++] = cdpath[i];
3469 }
3470 }
3471 buf[j] = NUL;
3472 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003473 if (opt_idx >= 0)
3474 {
3475 options[opt_idx].def_val[VI_DEFAULT] = buf;
3476 options[opt_idx].flags |= P_DEF_ALLOCED;
3477 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003478 else
3479 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003481 if (mustfree)
3482 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 }
3484 }
3485#endif
3486
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003487#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 /* Set print encoding on platforms that don't default to latin1 */
3489 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003490# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 (char_u *)"cp1252"
3492# else
3493# ifdef VMS
3494 (char_u *)"dec-mcs"
3495# else
3496# ifdef EBCDIC
3497 (char_u *)"ebcdic-uk"
3498# else
3499# ifdef MAC
3500 (char_u *)"mac-roman"
3501# else /* HPUX */
3502 (char_u *)"hp-roman8"
3503# endif
3504# endif
3505# endif
3506# endif
3507 );
3508#endif
3509
3510#ifdef FEAT_POSTSCRIPT
3511 /* 'printexpr' must be allocated to be able to evaluate it. */
3512 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003513# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003514 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515# else
3516# ifdef VMS
3517 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3518
3519# else
3520 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3521# endif
3522# endif
3523 );
3524#endif
3525
3526 /*
3527 * Set all the options (except the terminal options) to their default
3528 * value. Also set the global value for local options.
3529 */
3530 set_options_default(0);
3531
3532#ifdef FEAT_GUI
3533 if (found_reverse_arg)
3534 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3535#endif
3536
3537 curbuf->b_p_initialized = TRUE;
3538 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003539 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540 check_buf_options(curbuf);
3541 check_win_options(curwin);
3542 check_options();
3543
3544 /* Must be before option_expand(), because that one needs vim_isIDc() */
3545 didset_options();
3546
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003547#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003548 /* Use the current chartab for the generic chartab. This is not in
3549 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003550 init_spell_chartab();
3551#endif
3552
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 /*
3554 * Expand environment variables and things like "~" for the defaults.
3555 * If option_expand() returns non-NULL the variable is expanded. This can
3556 * only happen for non-indirect options.
3557 * Also set the default to the expanded value, so ":set" does not list
3558 * them.
3559 * Don't set the P_ALLOCED flag, because we don't want to free the
3560 * default.
3561 */
3562 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3563 {
3564 if ((options[opt_idx].flags & P_GETTEXT)
3565 && options[opt_idx].var != NULL)
3566 p = (char_u *)_(*(char **)options[opt_idx].var);
3567 else
3568 p = option_expand(opt_idx, NULL);
3569 if (p != NULL && (p = vim_strsave(p)) != NULL)
3570 {
3571 *(char_u **)options[opt_idx].var = p;
3572 /* VIMEXP
3573 * Defaults for all expanded options are currently the same for Vi
3574 * and Vim. When this changes, add some code here! Also need to
3575 * split P_DEF_ALLOCED in two.
3576 */
3577 if (options[opt_idx].flags & P_DEF_ALLOCED)
3578 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3579 options[opt_idx].def_val[VI_DEFAULT] = p;
3580 options[opt_idx].flags |= P_DEF_ALLOCED;
3581 }
3582 }
3583
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584 save_file_ff(curbuf); /* Buffer is unchanged */
3585
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586#if defined(FEAT_ARABIC)
3587 /* Detect use of mlterm.
3588 * Mlterm is a terminal emulator akin to xterm that has some special
3589 * abilities (bidi namely).
3590 * NOTE: mlterm's author is being asked to 'set' a variable
3591 * instead of an environment variable due to inheritance.
3592 */
3593 if (mch_getenv((char_u *)"MLTERM") != NULL)
3594 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3595#endif
3596
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003597 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598
3599#ifdef FEAT_MBYTE
3600# if defined(WIN3264) && defined(FEAT_GETTEXT)
3601 /*
3602 * If $LANG isn't set, try to get a good value for it. This makes the
3603 * right language be used automatically. Don't do this for English.
3604 */
3605 if (mch_getenv((char_u *)"LANG") == NULL)
3606 {
3607 char buf[20];
3608
3609 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3610 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3611 * only the first two. */
3612 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3613 (LPTSTR)buf, 20);
3614 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3615 {
3616 /* There are a few exceptions (probably more) */
3617 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3618 STRCPY(buf, "zh_TW");
3619 else if (STRNICMP(buf, "chs", 3) == 0
3620 || STRNICMP(buf, "zhc", 3) == 0)
3621 STRCPY(buf, "zh_CN");
3622 else if (STRNICMP(buf, "jp", 2) == 0)
3623 STRCPY(buf, "ja");
3624 else
3625 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003626 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 }
3628 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003629# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003630# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003631 /* Moved to os_mac_conv.c to avoid dependency problems. */
3632 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003633# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634# endif
3635
3636 /* enc_locale() will try to find the encoding of the current locale. */
3637 p = enc_locale();
3638 if (p != NULL)
3639 {
3640 char_u *save_enc;
3641
3642 /* Try setting 'encoding' and check if the value is valid.
3643 * If not, go back to the default "latin1". */
3644 save_enc = p_enc;
3645 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003646 if (STRCMP(p_enc, "gb18030") == 0)
3647 {
3648 /* We don't support "gb18030", but "cp936" is a good substitute
3649 * for practical purposes, thus use that. It's not an alias to
3650 * still support conversion between gb18030 and utf-8. */
3651 p_enc = vim_strsave((char_u *)"cp936");
3652 vim_free(p);
3653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 if (mb_init() == NULL)
3655 {
3656 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003657 if (opt_idx >= 0)
3658 {
3659 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3660 options[opt_idx].flags |= P_DEF_ALLOCED;
3661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003663#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003664 if (STRCMP(p_enc, "latin1") == 0
3665# ifdef FEAT_MBYTE
3666 || enc_utf8
3667# endif
3668 )
3669 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003670 /* Adjust the default for 'isprint' and 'iskeyword' to match
3671 * latin1. Also set the defaults for when 'nocompatible' is
3672 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003673 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003674 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003675 set_string_option_direct((char_u *)"isk", -1,
3676 ISK_LATIN1, OPT_FREE, SID_NONE);
3677 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003678 if (opt_idx >= 0)
3679 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003680 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003681 if (opt_idx >= 0)
3682 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003683 (void)init_chartab();
3684 }
3685#endif
3686
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687# if defined(WIN3264) && !defined(FEAT_GUI)
3688 /* Win32 console: When GetACP() returns a different value from
3689 * GetConsoleCP() set 'termencoding'. */
3690 if (GetACP() != GetConsoleCP())
3691 {
3692 char buf[50];
3693
3694 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3695 p_tenc = vim_strsave((char_u *)buf);
3696 if (p_tenc != NULL)
3697 {
3698 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 {
3701 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3702 options[opt_idx].flags |= P_DEF_ALLOCED;
3703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704 convert_setup(&input_conv, p_tenc, p_enc);
3705 convert_setup(&output_conv, p_enc, p_tenc);
3706 }
3707 else
3708 p_tenc = empty_option;
3709 }
3710# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003711# if defined(WIN3264) && defined(FEAT_MBYTE)
3712 /* $HOME may have characters in active code page. */
3713 init_homedir();
3714# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003715 }
3716 else
3717 {
3718 vim_free(p_enc);
3719 p_enc = save_enc;
3720 }
3721 }
3722#endif
3723
3724#ifdef FEAT_MULTI_LANG
3725 /* Set the default for 'helplang'. */
3726 set_helplang_default(get_mess_lang());
3727#endif
3728}
3729
3730/*
3731 * Set an option to its default value.
3732 * This does not take care of side effects!
3733 */
3734 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003735set_option_default(
3736 int opt_idx,
3737 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3738 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739{
3740 char_u *varp; /* pointer to variable for current option */
3741 int dvi; /* index in def_val[] */
3742 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003743 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3745
3746 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3747 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003748 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 {
3750 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3751 if (flags & P_STRING)
3752 {
3753 /* Use set_string_option_direct() for local options to handle
3754 * freeing and allocating the value. */
3755 if (options[opt_idx].indir != PV_NONE)
3756 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003757 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 else
3759 {
3760 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3761 free_string_option(*(char_u **)(varp));
3762 *(char_u **)varp = options[opt_idx].def_val[dvi];
3763 options[opt_idx].flags &= ~P_ALLOCED;
3764 }
3765 }
3766 else if (flags & P_NUM)
3767 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003768 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 win_comp_scroll(curwin);
3770 else
3771 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003772 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 /* May also set global value for local option. */
3774 if (both)
3775 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3776 *(long *)varp;
3777 }
3778 }
3779 else /* P_BOOL */
3780 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003781 /* the cast to long is required for Manx C, long_i is needed for
3782 * MSVC */
3783 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003784#ifdef UNIX
3785 /* 'modeline' defaults to off for root */
3786 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3787 *(int *)varp = FALSE;
3788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 /* May also set global value for local option. */
3790 if (both)
3791 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3792 *(int *)varp;
3793 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003794
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003795 /* The default value is not insecure. */
3796 flagsp = insecure_flag(opt_idx, opt_flags);
3797 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 }
3799
3800#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003801 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802#endif
3803}
3804
3805/*
3806 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003807 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 */
3809 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003810set_options_default(
3811 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812{
3813 int i;
3814#ifdef FEAT_WINDOWS
3815 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003816 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817#endif
3818
3819 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003820 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003821#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003822 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003823 || (TRUE
3824# if defined(FEAT_MBYTE)
3825 && options[i].var != (char_u *)&p_enc
3826# endif
3827# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003828 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003829 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003830# endif
3831 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003832#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003833 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 set_option_default(i, opt_flags, p_cp);
3835
3836#ifdef FEAT_WINDOWS
3837 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003838 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 win_comp_scroll(wp);
3840#else
3841 win_comp_scroll(curwin);
3842#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003843#ifdef FEAT_CINDENT
3844 parse_cino(curbuf);
3845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846}
3847
3848/*
3849 * Set the Vi-default value of a string option.
3850 * Used for 'sh', 'backupskip' and 'term'.
3851 */
3852 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003853set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854{
3855 char_u *p;
3856 int opt_idx;
3857
3858 p = vim_strsave(val);
3859 if (p != NULL) /* we don't want a NULL */
3860 {
3861 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003862 if (opt_idx >= 0)
3863 {
3864 if (options[opt_idx].flags & P_DEF_ALLOCED)
3865 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3866 options[opt_idx].def_val[VI_DEFAULT] = p;
3867 options[opt_idx].flags |= P_DEF_ALLOCED;
3868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 }
3870}
3871
3872/*
3873 * Set the Vi-default value of a number option.
3874 * Used for 'lines' and 'columns'.
3875 */
3876 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003877set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003879 int opt_idx;
3880
3881 opt_idx = findoption((char_u *)name);
3882 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003883 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884}
3885
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003886#if defined(EXITFREE) || defined(PROTO)
3887/*
3888 * Free all options.
3889 */
3890 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003891free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003892{
3893 int i;
3894
3895 for (i = 0; !istermoption(&options[i]); i++)
3896 {
3897 if (options[i].indir == PV_NONE)
3898 {
3899 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003900 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003901 free_string_option(*(char_u **)options[i].var);
3902 if (options[i].flags & P_DEF_ALLOCED)
3903 free_string_option(options[i].def_val[VI_DEFAULT]);
3904 }
3905 else if (options[i].var != VAR_WIN
3906 && (options[i].flags & P_STRING))
3907 /* buffer-local option: free global value */
3908 free_string_option(*(char_u **)options[i].var);
3909 }
3910}
3911#endif
3912
3913
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914/*
3915 * Initialize the options, part two: After getting Rows and Columns and
3916 * setting 'term'.
3917 */
3918 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003919set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003921 int idx;
3922
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 /*
3924 * 'scroll' defaults to half the window height. Note that this default is
3925 * wrong when the window height changes.
3926 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003927 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003928 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003929 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003930 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 comp_col();
3932
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003933 /*
3934 * 'window' is only for backwards compatibility with Vi.
3935 * Default is Rows - 1.
3936 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003937 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003938 p_window = Rows - 1;
3939 set_number_default("window", Rows - 1);
3940
Bram Moolenaarf740b292006-02-16 22:11:02 +00003941 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003942#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003943 /*
3944 * If 'background' wasn't set by the user, try guessing the value,
3945 * depending on the terminal name. Only need to check for terminals
3946 * with a dark background, that can handle color.
3947 */
3948 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003949 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3950 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003952 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003953 /* don't mark it as set, when starting the GUI it may be
3954 * changed again */
3955 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 }
3957#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003958
3959#ifdef CURSOR_SHAPE
3960 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3961#endif
3962#ifdef FEAT_MOUSESHAPE
3963 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3964#endif
3965#ifdef FEAT_PRINTER
3966 (void)parse_printoptions(); /* parse 'printoptions' default value */
3967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968}
3969
3970/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 * Return "dark" or "light" depending on the kind of terminal.
3972 * This is just guessing! Recognized are:
3973 * "linux" Linux console
3974 * "screen.linux" Linux console with screen
3975 * "cygwin" Cygwin shell
3976 * "putty" Putty program
3977 * We also check the COLORFGBG environment variable, which is set by
3978 * rxvt and derivatives. This variable contains either two or three
3979 * values separated by semicolons; we want the last value in either
3980 * case. If this value is 0-6 or 8, our background is dark.
3981 */
3982 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003983term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003984{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003985#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003986 /* DOS console nearly always black */
3987 return (char_u *)"dark";
3988#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003989 char_u *p;
3990
Bram Moolenaarf740b292006-02-16 22:11:02 +00003991 if (STRCMP(T_NAME, "linux") == 0
3992 || STRCMP(T_NAME, "screen.linux") == 0
3993 || STRCMP(T_NAME, "cygwin") == 0
3994 || STRCMP(T_NAME, "putty") == 0
3995 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3996 && (p = vim_strrchr(p, ';')) != NULL
3997 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3998 && p[2] == NUL))
3999 return (char_u *)"dark";
4000 return (char_u *)"light";
4001#endif
4002}
4003
4004/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 * Initialize the options, part three: After reading the .vimrc
4006 */
4007 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004008set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004010#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011/*
4012 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4013 * This is done after other initializations, where 'shell' might have been
4014 * set, but only if they have not been set before.
4015 */
4016 char_u *p;
4017 int idx_srr;
4018 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004019# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 int idx_sp;
4021 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004022# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023
4024 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004025 if (idx_srr < 0)
4026 do_srr = FALSE;
4027 else
4028 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004029# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004031 if (idx_sp < 0)
4032 do_sp = FALSE;
4033 else
4034 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004035# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004036 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 if (p != NULL)
4038 {
4039 /*
4040 * Default for p_sp is "| tee", for p_srr is ">".
4041 * For known shells it is changed here to include stderr.
4042 */
4043 if ( fnamecmp(p, "csh") == 0
4044 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004045# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 || fnamecmp(p, "csh.exe") == 0
4047 || fnamecmp(p, "tcsh.exe") == 0
4048# endif
4049 )
4050 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004051# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 if (do_sp)
4053 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004058# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4060 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if (do_srr)
4063 {
4064 p_srr = (char_u *)">&";
4065 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4066 }
4067 }
4068 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 if ( fnamecmp(p, "sh") == 0
4071 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004072 || fnamecmp(p, "mksh") == 0
4073 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004075 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004077 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 || fnamecmp(p, "cmd") == 0
4080 || fnamecmp(p, "sh.exe") == 0
4081 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004082 || fnamecmp(p, "mksh.exe") == 0
4083 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004085 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 || fnamecmp(p, "bash.exe") == 0
4087 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004091# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 if (do_sp)
4093 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004094# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4100 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004101# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 if (do_srr)
4103 {
4104 p_srr = (char_u *)">%s 2>&1";
4105 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4106 }
4107 }
4108 vim_free(p);
4109 }
4110#endif
4111
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004112#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004114 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4115 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 * This is done after other initializations, where 'shell' might have been
4117 * set, but only if they have not been set before. Default for p_shcf is
4118 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004119 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004121 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 {
4123 int idx3;
4124
4125 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128 p_shcf = (char_u *)"-c";
4129 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4130 }
4131
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004132# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 /* Somehow Win32 requires the quotes around the redirection too */
4134 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004135 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 {
4137 p_sxq = (char_u *)"\"";
4138 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4139 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004140# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004142 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 {
4144 p_shq = (char_u *)"\"";
4145 options[idx3].def_val[VI_DEFAULT] = p_shq;
4146 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147# endif
4148 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004149 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4150 {
4151 int idx3;
4152
4153 /*
4154 * cmd.exe on Windows will strip the first and last double quote given
4155 * on the command line, e.g. most of the time things like:
4156 * cmd /c "my path/to/echo" "my args to echo"
4157 * become:
4158 * my path/to/echo" "my args to echo
4159 * when executed.
4160 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004161 * To avoid this, set shellxquote to surround the command in
4162 * parenthesis. This appears to make most commands work, without
4163 * breaking commands that worked previously, such as
4164 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004165 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004166 idx3 = findoption((char_u *)"sxq");
4167 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4168 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004169 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004170 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4171 }
4172
Bram Moolenaara64ba222012-02-12 23:23:31 +01004173 idx3 = findoption((char_u *)"shcf");
4174 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4175 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004176 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004177 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4178 }
4179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180#endif
4181
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004182 if (bufempty())
4183 {
4184 int idx_ffs = findoption((char_u *)"ffs");
4185
4186 /* Apply the first entry of 'fileformats' to the initial buffer. */
4187 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4188 set_fileformat(default_fileformat(), OPT_LOCAL);
4189 }
4190
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191#ifdef FEAT_TITLE
4192 set_title_defaults();
4193#endif
4194}
4195
4196#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4197/*
4198 * When 'helplang' is still at its default value, set it to "lang".
4199 * Only the first two characters of "lang" are used.
4200 */
4201 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004202set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203{
4204 int idx;
4205
4206 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4207 return;
4208 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004209 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 {
4211 if (options[idx].flags & P_ALLOCED)
4212 free_string_option(p_hlg);
4213 p_hlg = vim_strsave(lang);
4214 if (p_hlg == NULL)
4215 p_hlg = empty_option;
4216 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004217 {
4218 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4219 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4220 {
4221 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4222 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226 options[idx].flags |= P_ALLOCED;
4227 }
4228}
4229#endif
4230
4231#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004232static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233
4234 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004235gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236{
4237 if (gui_get_lightness(gui.back_pixel) < 127)
4238 return (char_u *)"dark";
4239 return (char_u *)"light";
4240}
4241
4242/*
4243 * Option initializations that can only be done after opening the GUI window.
4244 */
4245 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004246init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004247{
4248 /* Set the 'background' option according to the lightness of the
4249 * background color, unless the user has set it already. */
4250 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4251 {
4252 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4253 highlight_changed();
4254 }
4255}
4256#endif
4257
4258#ifdef FEAT_TITLE
4259/*
4260 * 'title' and 'icon' only default to true if they have not been set or reset
4261 * in .vimrc and we can read the old value.
4262 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4263 * they can be reset. This reduces startup time when using X on a remote
4264 * machine.
4265 */
4266 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004267set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268{
4269 int idx1;
4270 long val;
4271
4272 /*
4273 * If GUI is (going to be) used, we can always set the window title and
4274 * icon name. Saves a bit of time, because the X11 display server does
4275 * not need to be contacted.
4276 */
4277 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004278 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279 {
4280#ifdef FEAT_GUI
4281 if (gui.starting || gui.in_use)
4282 val = TRUE;
4283 else
4284#endif
4285 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004286 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004287 p_title = val;
4288 }
4289 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004290 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004291 {
4292#ifdef FEAT_GUI
4293 if (gui.starting || gui.in_use)
4294 val = TRUE;
4295 else
4296#endif
4297 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004298 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004299 p_icon = val;
4300 }
4301}
4302#endif
4303
4304/*
4305 * Parse 'arg' for option settings.
4306 *
4307 * 'arg' may be IObuff, but only when no errors can be present and option
4308 * does not need to be expanded with option_expand().
4309 * "opt_flags":
4310 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004311 * OPT_GLOBAL for ":setglobal"
4312 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004313 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004314 * OPT_WINONLY to only set window-local options
4315 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004316 *
4317 * returns FAIL if an error is detected, OK otherwise
4318 */
4319 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004320do_set(
4321 char_u *arg, /* option string (may be written to!) */
4322 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004323{
4324 int opt_idx;
4325 char_u *errmsg;
4326 char_u errbuf[80];
4327 char_u *startarg;
4328 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4329 int nextchar; /* next non-white char after option name */
4330 int afterchar; /* character just after option name */
4331 int len;
4332 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004333 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 int key;
4335 long_u flags; /* flags for current option */
4336 char_u *varp = NULL; /* pointer to variable for current option */
4337 int did_show = FALSE; /* already showed one value */
4338 int adding; /* "opt+=arg" */
4339 int prepending; /* "opt^=arg" */
4340 int removing; /* "opt-=arg" */
4341 int cp_val = 0;
4342 char_u key_name[2];
4343
4344 if (*arg == NUL)
4345 {
4346 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004347 did_show = TRUE;
4348 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 }
4350
4351 while (*arg != NUL) /* loop to process all options */
4352 {
4353 errmsg = NULL;
4354 startarg = arg; /* remember for error message */
4355
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004356 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4357 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358 {
4359 /*
4360 * ":set all" show all options.
4361 * ":set all&" set all options to their default value.
4362 */
4363 arg += 3;
4364 if (*arg == '&')
4365 {
4366 ++arg;
4367 /* Only for :set command set global value of local options. */
4368 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004369 didset_options();
4370 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004371 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004372 }
4373 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004374 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004376 did_show = TRUE;
4377 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004378 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004379 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004380 {
4381 showoptions(2, opt_flags);
4382 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004383 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 arg += 7;
4385 }
4386 else
4387 {
4388 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004389 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004390 {
4391 prefix = 0;
4392 arg += 2;
4393 }
4394 else if (STRNCMP(arg, "inv", 3) == 0)
4395 {
4396 prefix = 2;
4397 arg += 3;
4398 }
4399
4400 /* find end of name */
4401 key = 0;
4402 if (*arg == '<')
4403 {
4404 nextchar = 0;
4405 opt_idx = -1;
4406 /* look out for <t_>;> */
4407 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4408 len = 5;
4409 else
4410 {
4411 len = 1;
4412 while (arg[len] != NUL && arg[len] != '>')
4413 ++len;
4414 }
4415 if (arg[len] != '>')
4416 {
4417 errmsg = e_invarg;
4418 goto skip;
4419 }
4420 arg[len] = NUL; /* put NUL after name */
4421 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4422 opt_idx = findoption(arg + 1);
4423 arg[len++] = '>'; /* restore '>' */
4424 if (opt_idx == -1)
4425 key = find_key_option(arg + 1);
4426 }
4427 else
4428 {
4429 len = 0;
4430 /*
4431 * The two characters after "t_" may not be alphanumeric.
4432 */
4433 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4434 len = 4;
4435 else
4436 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4437 ++len;
4438 nextchar = arg[len];
4439 arg[len] = NUL; /* put NUL after name */
4440 opt_idx = findoption(arg);
4441 arg[len] = nextchar; /* restore nextchar */
4442 if (opt_idx == -1)
4443 key = find_key_option(arg);
4444 }
4445
4446 /* remember character after option name */
4447 afterchar = arg[len];
4448
4449 /* skip white space, allow ":set ai ?" */
4450 while (vim_iswhite(arg[len]))
4451 ++len;
4452
4453 adding = FALSE;
4454 prepending = FALSE;
4455 removing = FALSE;
4456 if (arg[len] != NUL && arg[len + 1] == '=')
4457 {
4458 if (arg[len] == '+')
4459 {
4460 adding = TRUE; /* "+=" */
4461 ++len;
4462 }
4463 else if (arg[len] == '^')
4464 {
4465 prepending = TRUE; /* "^=" */
4466 ++len;
4467 }
4468 else if (arg[len] == '-')
4469 {
4470 removing = TRUE; /* "-=" */
4471 ++len;
4472 }
4473 }
4474 nextchar = arg[len];
4475
4476 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4477 {
4478 errmsg = (char_u *)N_("E518: Unknown option");
4479 goto skip;
4480 }
4481
4482 if (opt_idx >= 0)
4483 {
4484 if (options[opt_idx].var == NULL) /* hidden option: skip */
4485 {
4486 /* Only give an error message when requesting the value of
4487 * a hidden option, ignore setting it. */
4488 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4489 && (!(options[opt_idx].flags & P_BOOL)
4490 || nextchar == '?'))
4491 errmsg = (char_u *)N_("E519: Option not supported");
4492 goto skip;
4493 }
4494
4495 flags = options[opt_idx].flags;
4496 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4497 }
4498 else
4499 {
4500 flags = P_STRING;
4501 if (key < 0)
4502 {
4503 key_name[0] = KEY2TERMCAP0(key);
4504 key_name[1] = KEY2TERMCAP1(key);
4505 }
4506 else
4507 {
4508 key_name[0] = KS_KEY;
4509 key_name[1] = (key & 0xff);
4510 }
4511 }
4512
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004513 /* Skip all options that are not window-local (used when showing
4514 * an already loaded buffer in a window). */
4515 if ((opt_flags & OPT_WINONLY)
4516 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4517 goto skip;
4518
Bram Moolenaara3227e22006-03-08 21:32:40 +00004519 /* Skip all options that are window-local (used for :vimgrep). */
4520 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4521 && options[opt_idx].var == VAR_WIN)
4522 goto skip;
4523
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004524 /* Disallow changing some options from modelines. */
4525 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004526 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004527 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004528 {
4529 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4530 goto skip;
4531 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004532#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004533 /* In diff mode some options are overruled. This avoids that
4534 * 'foldmethod' becomes "marker" instead of "diff" and that
4535 * "wrap" gets set. */
4536 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004537 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004538 && (
4539#ifdef FEAT_FOLDING
4540 options[opt_idx].indir == PV_FDM ||
4541#endif
4542 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004543 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004544#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004545 }
4546
4547#ifdef HAVE_SANDBOX
4548 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004549 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004550 {
4551 errmsg = (char_u *)_(e_sandbox);
4552 goto skip;
4553 }
4554#endif
4555
4556 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4557 {
4558 arg += len;
4559 cp_val = p_cp;
4560 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4561 {
4562 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4563 {
4564 cp_val = FALSE;
4565 arg += 3;
4566 }
4567 else /* "opt&vi": set to Vi default */
4568 {
4569 cp_val = TRUE;
4570 arg += 2;
4571 }
4572 }
4573 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4574 && arg[1] != NUL && !vim_iswhite(arg[1]))
4575 {
4576 errmsg = e_trailing;
4577 goto skip;
4578 }
4579 }
4580
4581 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004582 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4583 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004584 */
4585 if (nextchar == '?'
4586 || (prefix == 1
4587 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4588 && !(flags & P_BOOL)))
4589 {
4590 /*
4591 * print value
4592 */
4593 if (did_show)
4594 msg_putchar('\n'); /* cursor below last one */
4595 else
4596 {
4597 gotocmdline(TRUE); /* cursor at status line */
4598 did_show = TRUE; /* remember that we did a line */
4599 }
4600 if (opt_idx >= 0)
4601 {
4602 showoneopt(&options[opt_idx], opt_flags);
4603#ifdef FEAT_EVAL
4604 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004605 {
4606 /* Mention where the option was last set. */
4607 if (varp == options[opt_idx].var)
4608 last_set_msg(options[opt_idx].scriptID);
4609 else if ((int)options[opt_idx].indir & PV_WIN)
4610 last_set_msg(curwin->w_p_scriptID[
4611 (int)options[opt_idx].indir & PV_MASK]);
4612 else if ((int)options[opt_idx].indir & PV_BUF)
4613 last_set_msg(curbuf->b_p_scriptID[
4614 (int)options[opt_idx].indir & PV_MASK]);
4615 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004616#endif
4617 }
4618 else
4619 {
4620 char_u *p;
4621
4622 p = find_termcode(key_name);
4623 if (p == NULL)
4624 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004625 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004626 goto skip;
4627 }
4628 else
4629 (void)show_one_termcode(key_name, p, TRUE);
4630 }
4631 if (nextchar != '?'
4632 && nextchar != NUL && !vim_iswhite(afterchar))
4633 errmsg = e_trailing;
4634 }
4635 else
4636 {
4637 if (flags & P_BOOL) /* boolean */
4638 {
4639 if (nextchar == '=' || nextchar == ':')
4640 {
4641 errmsg = e_invarg;
4642 goto skip;
4643 }
4644
4645 /*
4646 * ":set opt!": invert
4647 * ":set opt&": reset to default value
4648 * ":set opt<": reset to global value
4649 */
4650 if (nextchar == '!')
4651 value = *(int *)(varp) ^ 1;
4652 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004653 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004654 ((flags & P_VI_DEF) || cp_val)
4655 ? VI_DEFAULT : VIM_DEFAULT];
4656 else if (nextchar == '<')
4657 {
4658 /* For 'autoread' -1 means to use global value. */
4659 if ((int *)varp == &curbuf->b_p_ar
4660 && opt_flags == OPT_LOCAL)
4661 value = -1;
4662 else
4663 value = *(int *)get_varp_scope(&(options[opt_idx]),
4664 OPT_GLOBAL);
4665 }
4666 else
4667 {
4668 /*
4669 * ":set invopt": invert
4670 * ":set opt" or ":set noopt": set or reset
4671 */
4672 if (nextchar != NUL && !vim_iswhite(afterchar))
4673 {
4674 errmsg = e_trailing;
4675 goto skip;
4676 }
4677 if (prefix == 2) /* inv */
4678 value = *(int *)(varp) ^ 1;
4679 else
4680 value = prefix;
4681 }
4682
4683 errmsg = set_bool_option(opt_idx, varp, (int)value,
4684 opt_flags);
4685 }
4686 else /* numeric or string */
4687 {
4688 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4689 || prefix != 1)
4690 {
4691 errmsg = e_invarg;
4692 goto skip;
4693 }
4694
4695 if (flags & P_NUM) /* numeric */
4696 {
4697 /*
4698 * Different ways to set a number option:
4699 * & set to default value
4700 * < set to global value
4701 * <xx> accept special key codes for 'wildchar'
4702 * c accept any non-digit for 'wildchar'
4703 * [-]0-9 set number
4704 * other error
4705 */
4706 ++arg;
4707 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004708 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004709 ((flags & P_VI_DEF) || cp_val)
4710 ? VI_DEFAULT : VIM_DEFAULT];
4711 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004712 {
4713 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4714 * use the global value. */
4715 if ((long *)varp == &curbuf->b_p_ul
4716 && opt_flags == OPT_LOCAL)
4717 value = NO_LOCAL_UNDOLEVEL;
4718 else
4719 value = *(long *)get_varp_scope(
4720 &(options[opt_idx]), OPT_GLOBAL);
4721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004722 else if (((long *)varp == &p_wc
4723 || (long *)varp == &p_wcm)
4724 && (*arg == '<'
4725 || *arg == '^'
Bram Moolenaara12e4032017-02-25 21:37:57 +01004726 || (*arg != NUL && (!arg[1] || vim_iswhite(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727 && !VIM_ISDIGIT(*arg))))
4728 {
4729 value = string_to_key(arg);
4730 if (value == 0 && (long *)varp != &p_wcm)
4731 {
4732 errmsg = e_invarg;
4733 goto skip;
4734 }
4735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004736 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4737 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004738 /* Allow negative (for 'undolevels'), octal and
4739 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004740 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4741 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004742 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4743 {
4744 errmsg = e_invarg;
4745 goto skip;
4746 }
4747 }
4748 else
4749 {
4750 errmsg = (char_u *)N_("E521: Number required after =");
4751 goto skip;
4752 }
4753
4754 if (adding)
4755 value = *(long *)varp + value;
4756 if (prepending)
4757 value = *(long *)varp * value;
4758 if (removing)
4759 value = *(long *)varp - value;
4760 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004761 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 }
4763 else if (opt_idx >= 0) /* string */
4764 {
4765 char_u *save_arg = NULL;
4766 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004767 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004768 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004769 char_u *origval = NULL;
4770#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4771 char_u *saved_origval = NULL;
4772#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004773 unsigned newlen;
4774 int comma;
4775 int bs;
4776 int new_value_alloced; /* new string option
4777 was allocated */
4778
4779 /* When using ":set opt=val" for a global option
4780 * with a local value the local value will be
4781 * reset, use the global value here. */
4782 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004783 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004784 varp = options[opt_idx].var;
4785
4786 /* The old value is kept until we are sure that the
4787 * new value is valid. */
4788 oldval = *(char_u **)varp;
4789 if (nextchar == '&') /* set to default val */
4790 {
4791 newval = options[opt_idx].def_val[
4792 ((flags & P_VI_DEF) || cp_val)
4793 ? VI_DEFAULT : VIM_DEFAULT];
4794 if ((char_u **)varp == &p_bg)
4795 {
4796 /* guess the value of 'background' */
4797#ifdef FEAT_GUI
4798 if (gui.in_use)
4799 newval = gui_bg_default();
4800 else
4801#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004802 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004803 }
4804
4805 /* expand environment variables and ~ (since the
4806 * default value was already expanded, only
4807 * required when an environment variable was set
4808 * later */
4809 if (newval == NULL)
4810 newval = empty_option;
4811 else
4812 {
4813 s = option_expand(opt_idx, newval);
4814 if (s == NULL)
4815 s = newval;
4816 newval = vim_strsave(s);
4817 }
4818 new_value_alloced = TRUE;
4819 }
4820 else if (nextchar == '<') /* set to global val */
4821 {
4822 newval = vim_strsave(*(char_u **)get_varp_scope(
4823 &(options[opt_idx]), OPT_GLOBAL));
4824 new_value_alloced = TRUE;
4825 }
4826 else
4827 {
4828 ++arg; /* jump to after the '=' or ':' */
4829
4830 /*
4831 * Set 'keywordprg' to ":help" if an empty
4832 * value was passed to :set by the user.
4833 * Misuse errbuf[] for the resulting string.
4834 */
4835 if (varp == (char_u *)&p_kp
4836 && (*arg == NUL || *arg == ' '))
4837 {
4838 STRCPY(errbuf, ":help");
4839 save_arg = arg;
4840 arg = errbuf;
4841 }
4842 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004843 * Convert 'backspace' number to string, for
4844 * adding, prepending and removing string.
4845 */
4846 else if (varp == (char_u *)&p_bs
4847 && VIM_ISDIGIT(**(char_u **)varp))
4848 {
4849 i = getdigits((char_u **)varp);
4850 switch (i)
4851 {
4852 case 0:
4853 *(char_u **)varp = empty_option;
4854 break;
4855 case 1:
4856 *(char_u **)varp = vim_strsave(
4857 (char_u *)"indent,eol");
4858 break;
4859 case 2:
4860 *(char_u **)varp = vim_strsave(
4861 (char_u *)"indent,eol,start");
4862 break;
4863 }
4864 vim_free(oldval);
4865 oldval = *(char_u **)varp;
4866 }
4867 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004868 * Convert 'whichwrap' number to string, for
4869 * backwards compatibility with Vim 3.0.
4870 * Misuse errbuf[] for the resulting string.
4871 */
4872 else if (varp == (char_u *)&p_ww
4873 && VIM_ISDIGIT(*arg))
4874 {
4875 *errbuf = NUL;
4876 i = getdigits(&arg);
4877 if (i & 1)
4878 STRCAT(errbuf, "b,");
4879 if (i & 2)
4880 STRCAT(errbuf, "s,");
4881 if (i & 4)
4882 STRCAT(errbuf, "h,l,");
4883 if (i & 8)
4884 STRCAT(errbuf, "<,>,");
4885 if (i & 16)
4886 STRCAT(errbuf, "[,],");
4887 if (*errbuf != NUL) /* remove trailing , */
4888 errbuf[STRLEN(errbuf) - 1] = NUL;
4889 save_arg = arg;
4890 arg = errbuf;
4891 }
4892 /*
4893 * Remove '>' before 'dir' and 'bdir', for
4894 * backwards compatibility with version 3.0
4895 */
4896 else if ( *arg == '>'
4897 && (varp == (char_u *)&p_dir
4898 || varp == (char_u *)&p_bdir))
4899 {
4900 ++arg;
4901 }
4902
4903 /* When setting the local value of a global
4904 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004905 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004906 && (opt_flags & OPT_LOCAL))
4907 origval = *(char_u **)get_varp(
4908 &options[opt_idx]);
4909 else
4910 origval = oldval;
4911
4912 /*
4913 * Copy the new string into allocated memory.
4914 * Can't use set_string_option_direct(), because
4915 * we need to remove the backslashes.
4916 */
4917 /* get a bit too much */
4918 newlen = (unsigned)STRLEN(arg) + 1;
4919 if (adding || prepending || removing)
4920 newlen += (unsigned)STRLEN(origval) + 1;
4921 newval = alloc(newlen);
4922 if (newval == NULL) /* out of mem, don't change */
4923 break;
4924 s = newval;
4925
4926 /*
4927 * Copy the string, skip over escaped chars.
4928 * For MS-DOS and WIN32 backslashes before normal
4929 * file name characters are not removed, and keep
4930 * backslash at start, for "\\machine\path", but
4931 * do remove it for "\\\\machine\\path".
4932 * The reverse is found in ExpandOldSetting().
4933 */
4934 while (*arg && !vim_iswhite(*arg))
4935 {
4936 if (*arg == '\\' && arg[1] != NUL
4937#ifdef BACKSLASH_IN_FILENAME
4938 && !((flags & P_EXPAND)
4939 && vim_isfilec(arg[1])
4940 && (arg[1] != '\\'
4941 || (s == newval
4942 && arg[2] != '\\')))
4943#endif
4944 )
4945 ++arg; /* remove backslash */
4946#ifdef FEAT_MBYTE
4947 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004948 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004949 {
4950 /* copy multibyte char */
4951 mch_memmove(s, arg, (size_t)i);
4952 arg += i;
4953 s += i;
4954 }
4955 else
4956#endif
4957 *s++ = *arg++;
4958 }
4959 *s = NUL;
4960
4961 /*
4962 * Expand environment variables and ~.
4963 * Don't do it when adding without inserting a
4964 * comma.
4965 */
4966 if (!(adding || prepending || removing)
4967 || (flags & P_COMMA))
4968 {
4969 s = option_expand(opt_idx, newval);
4970 if (s != NULL)
4971 {
4972 vim_free(newval);
4973 newlen = (unsigned)STRLEN(s) + 1;
4974 if (adding || prepending || removing)
4975 newlen += (unsigned)STRLEN(origval) + 1;
4976 newval = alloc(newlen);
4977 if (newval == NULL)
4978 break;
4979 STRCPY(newval, s);
4980 }
4981 }
4982
4983 /* locate newval[] in origval[] when removing it
4984 * and when adding to avoid duplicates */
4985 i = 0; /* init for GCC */
4986 if (removing || (flags & P_NODUP))
4987 {
4988 i = (int)STRLEN(newval);
4989 bs = 0;
4990 for (s = origval; *s; ++s)
4991 {
4992 if ((!(flags & P_COMMA)
4993 || s == origval
4994 || (s[-1] == ',' && !(bs & 1)))
4995 && STRNCMP(s, newval, i) == 0
4996 && (!(flags & P_COMMA)
4997 || s[i] == ','
4998 || s[i] == NUL))
4999 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005000 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005001 * even number of backslashes or a single
5002 * backslash preceded by a comma before it
5003 * is recognized as a separator */
5004 if ((s > origval + 1
5005 && s[-1] == '\\'
5006 && s[-2] != ',')
5007 || (s == origval + 1
5008 && s[-1] == '\\'))
5009
Bram Moolenaar071d4272004-06-13 20:20:40 +00005010 ++bs;
5011 else
5012 bs = 0;
5013 }
5014
5015 /* do not add if already there */
5016 if ((adding || prepending) && *s)
5017 {
5018 prepending = FALSE;
5019 adding = FALSE;
5020 STRCPY(newval, origval);
5021 }
5022 }
5023
5024 /* concatenate the two strings; add a ',' if
5025 * needed */
5026 if (adding || prepending)
5027 {
5028 comma = ((flags & P_COMMA) && *origval != NUL
5029 && *newval != NUL);
5030 if (adding)
5031 {
5032 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005033 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005034 if (comma && i > 1
5035 && (flags & P_ONECOMMA) == P_ONECOMMA
5036 && origval[i - 1] == ','
5037 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005038 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005039 mch_memmove(newval + i + comma, newval,
5040 STRLEN(newval) + 1);
5041 mch_memmove(newval, origval, (size_t)i);
5042 }
5043 else
5044 {
5045 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005046 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005047 }
5048 if (comma)
5049 newval[i] = ',';
5050 }
5051
5052 /* Remove newval[] from origval[]. (Note: "i" has
5053 * been set above and is used here). */
5054 if (removing)
5055 {
5056 STRCPY(newval, origval);
5057 if (*s)
5058 {
5059 /* may need to remove a comma */
5060 if (flags & P_COMMA)
5061 {
5062 if (s == origval)
5063 {
5064 /* include comma after string */
5065 if (s[i] == ',')
5066 ++i;
5067 }
5068 else
5069 {
5070 /* include comma before string */
5071 --s;
5072 ++i;
5073 }
5074 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005075 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005076 }
5077 }
5078
5079 if (flags & P_FLAGLIST)
5080 {
5081 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005082 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005083 {
5084 /* if options have P_FLAGLIST and
5085 * P_ONECOMMA such as 'whichwrap' */
5086 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005088 if (*s != ',' && *(s + 1) == ','
5089 && vim_strchr(s + 2, *s) != NULL)
5090 {
5091 /* Remove the duplicated value and
5092 * the next comma. */
5093 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005094 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005095 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005096 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005097 else
5098 {
5099 if ((!(flags & P_COMMA) || *s != ',')
5100 && vim_strchr(s + 1, *s) != NULL)
5101 {
5102 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005103 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005104 }
5105 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005106 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005108 }
5109
5110 if (save_arg != NULL) /* number for 'whichwrap' */
5111 arg = save_arg;
5112 new_value_alloced = TRUE;
5113 }
5114
5115 /* Set the new value. */
5116 *(char_u **)(varp) = newval;
5117
Bram Moolenaar53744302015-07-17 17:38:22 +02005118#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005119 if (!starting
5120# ifdef FEAT_CRYPT
5121 && options[opt_idx].indir != PV_KEY
5122# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02005123 && origval != NULL)
5124 /* origval may be freed by
5125 * did_set_string_option(), make a copy. */
5126 saved_origval = vim_strsave(origval);
5127#endif
5128
Bram Moolenaar071d4272004-06-13 20:20:40 +00005129 /* Handle side effects, and set the global value for
5130 * ":set" on local options. */
5131 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5132 new_value_alloced, oldval, errbuf, opt_flags);
5133
5134 /* If error detected, print the error message. */
5135 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005136 {
5137#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5138 vim_free(saved_origval);
5139#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005140 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005141 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005142#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5143 if (saved_origval != NULL)
5144 {
5145 char_u buf_type[7];
5146
5147 sprintf((char *)buf_type, "%s",
5148 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005149 set_vim_var_string(VV_OPTION_NEW,
5150 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005151 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5152 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5153 apply_autocmds(EVENT_OPTIONSET,
5154 (char_u *)options[opt_idx].fullname,
5155 NULL, FALSE, NULL);
5156 reset_v_option_vars();
5157 vim_free(saved_origval);
5158 }
5159#endif
5160
Bram Moolenaar071d4272004-06-13 20:20:40 +00005161 }
5162 else /* key code option */
5163 {
5164 char_u *p;
5165
5166 if (nextchar == '&')
5167 {
5168 if (add_termcap_entry(key_name, TRUE) == FAIL)
5169 errmsg = (char_u *)N_("E522: Not found in termcap");
5170 }
5171 else
5172 {
5173 ++arg; /* jump to after the '=' or ':' */
5174 for (p = arg; *p && !vim_iswhite(*p); ++p)
5175 if (*p == '\\' && p[1] != NUL)
5176 ++p;
5177 nextchar = *p;
5178 *p = NUL;
5179 add_termcode(key_name, arg, FALSE);
5180 *p = nextchar;
5181 }
5182 if (full_screen)
5183 ttest(FALSE);
5184 redraw_all_later(CLEAR);
5185 }
5186 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005187
Bram Moolenaar071d4272004-06-13 20:20:40 +00005188 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005189 did_set_option(opt_idx, opt_flags,
5190 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005191 }
5192
5193skip:
5194 /*
5195 * Advance to next argument.
5196 * - skip until a blank found, taking care of backslashes
5197 * - skip blanks
5198 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5199 */
5200 for (i = 0; i < 2 ; ++i)
5201 {
5202 while (*arg != NUL && !vim_iswhite(*arg))
5203 if (*arg++ == '\\' && *arg != NUL)
5204 ++arg;
5205 arg = skipwhite(arg);
5206 if (*arg != '=')
5207 break;
5208 }
5209 }
5210
5211 if (errmsg != NULL)
5212 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005213 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005214 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005215 if (i + (arg - startarg) < IOSIZE)
5216 {
5217 /* append the argument with the error */
5218 STRCAT(IObuff, ": ");
5219 mch_memmove(IObuff + i, startarg, (arg - startarg));
5220 IObuff[i + (arg - startarg)] = NUL;
5221 }
5222 /* make sure all characters are printable */
5223 trans_characters(IObuff, IOSIZE);
5224
5225 ++no_wait_return; /* wait_return done later */
5226 emsg(IObuff); /* show error highlighted */
5227 --no_wait_return;
5228
5229 return FAIL;
5230 }
5231
5232 arg = skipwhite(arg);
5233 }
5234
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005235theend:
5236 if (silent_mode && did_show)
5237 {
5238 /* After displaying option values in silent mode. */
5239 silent_mode = FALSE;
5240 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5241 msg_putchar('\n');
5242 cursor_on(); /* msg_start() switches it off */
5243 out_flush();
5244 silent_mode = TRUE;
5245 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5246 }
5247
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 return OK;
5249}
5250
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005251/*
5252 * Call this when an option has been given a new value through a user command.
5253 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5254 */
5255 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005256did_set_option(
5257 int opt_idx,
5258 int opt_flags, /* possibly with OPT_MODELINE */
5259 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005260{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005261 long_u *p;
5262
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005263 options[opt_idx].flags |= P_WAS_SET;
5264
5265 /* When an option is set in the sandbox, from a modeline or in secure mode
5266 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005267 * flag. */
5268 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005269 if (secure
5270#ifdef HAVE_SANDBOX
5271 || sandbox != 0
5272#endif
5273 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005274 *p = *p | P_INSECURE;
5275 else if (new_value)
5276 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005277}
5278
Bram Moolenaar071d4272004-06-13 20:20:40 +00005279 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005280illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005281{
5282 if (errbuf == NULL)
5283 return (char_u *)"";
5284 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005285 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005286 return errbuf;
5287}
5288
5289/*
5290 * Convert a key name or string into a key value.
5291 * Used for 'wildchar' and 'cedit' options.
5292 */
5293 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005294string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005295{
5296 if (*arg == '<')
5297 return find_key_option(arg + 1);
5298 if (*arg == '^')
5299 return Ctrl_chr(arg[1]);
5300 return *arg;
5301}
5302
5303#ifdef FEAT_CMDWIN
5304/*
5305 * Check value of 'cedit' and set cedit_key.
5306 * Returns NULL if value is OK, error message otherwise.
5307 */
5308 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005309check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310{
5311 int n;
5312
5313 if (*p_cedit == NUL)
5314 cedit_key = -1;
5315 else
5316 {
5317 n = string_to_key(p_cedit);
5318 if (vim_isprintc(n))
5319 return e_invarg;
5320 cedit_key = n;
5321 }
5322 return NULL;
5323}
5324#endif
5325
5326#ifdef FEAT_TITLE
5327/*
5328 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5329 * maketitle() to create and display it.
5330 * When switching the title or icon off, call mch_restore_title() to get
5331 * the old value back.
5332 */
5333 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005334did_set_title(
5335 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336{
5337 if (starting != NO_SCREEN
5338#ifdef FEAT_GUI
5339 && !gui.starting
5340#endif
5341 )
5342 {
5343 maketitle();
5344 if (icon)
5345 {
5346 if (!p_icon)
5347 mch_restore_title(2);
5348 }
5349 else
5350 {
5351 if (!p_title)
5352 mch_restore_title(1);
5353 }
5354 }
5355}
5356#endif
5357
5358/*
5359 * set_options_bin - called when 'bin' changes value.
5360 */
5361 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005362set_options_bin(
5363 int oldval,
5364 int newval,
5365 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005366{
5367 /*
5368 * The option values that are changed when 'bin' changes are
5369 * copied when 'bin is set and restored when 'bin' is reset.
5370 */
5371 if (newval)
5372 {
5373 if (!oldval) /* switched on */
5374 {
5375 if (!(opt_flags & OPT_GLOBAL))
5376 {
5377 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5378 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5379 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5380 curbuf->b_p_et_nobin = curbuf->b_p_et;
5381 }
5382 if (!(opt_flags & OPT_LOCAL))
5383 {
5384 p_tw_nobin = p_tw;
5385 p_wm_nobin = p_wm;
5386 p_ml_nobin = p_ml;
5387 p_et_nobin = p_et;
5388 }
5389 }
5390
5391 if (!(opt_flags & OPT_GLOBAL))
5392 {
5393 curbuf->b_p_tw = 0; /* no automatic line wrap */
5394 curbuf->b_p_wm = 0; /* no automatic line wrap */
5395 curbuf->b_p_ml = 0; /* no modelines */
5396 curbuf->b_p_et = 0; /* no expandtab */
5397 }
5398 if (!(opt_flags & OPT_LOCAL))
5399 {
5400 p_tw = 0;
5401 p_wm = 0;
5402 p_ml = FALSE;
5403 p_et = FALSE;
5404 p_bin = TRUE; /* needed when called for the "-b" argument */
5405 }
5406 }
5407 else if (oldval) /* switched off */
5408 {
5409 if (!(opt_flags & OPT_GLOBAL))
5410 {
5411 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5412 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5413 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5414 curbuf->b_p_et = curbuf->b_p_et_nobin;
5415 }
5416 if (!(opt_flags & OPT_LOCAL))
5417 {
5418 p_tw = p_tw_nobin;
5419 p_wm = p_wm_nobin;
5420 p_ml = p_ml_nobin;
5421 p_et = p_et_nobin;
5422 }
5423 }
5424}
5425
5426#ifdef FEAT_VIMINFO
5427/*
5428 * Find the parameter represented by the given character (eg ', :, ", or /),
5429 * and return its associated value in the 'viminfo' string.
5430 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005431 * If the parameter is not specified in the string or there is no following
5432 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433 */
5434 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005435get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005436{
5437 char_u *p;
5438
5439 p = find_viminfo_parameter(type);
5440 if (p != NULL && VIM_ISDIGIT(*p))
5441 return atoi((char *)p);
5442 return -1;
5443}
5444
5445/*
5446 * Find the parameter represented by the given character (eg ''', ':', '"', or
5447 * '/') in the 'viminfo' option and return a pointer to the string after it.
5448 * Return NULL if the parameter is not specified in the string.
5449 */
5450 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005451find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005452{
5453 char_u *p;
5454
5455 for (p = p_viminfo; *p; ++p)
5456 {
5457 if (*p == type)
5458 return p + 1;
5459 if (*p == 'n') /* 'n' is always the last one */
5460 break;
5461 p = vim_strchr(p, ','); /* skip until next ',' */
5462 if (p == NULL) /* hit the end without finding parameter */
5463 break;
5464 }
5465 return NULL;
5466}
5467#endif
5468
5469/*
5470 * Expand environment variables for some string options.
5471 * These string options cannot be indirect!
5472 * If "val" is NULL expand the current value of the option.
5473 * Return pointer to NameBuff, or NULL when not expanded.
5474 */
5475 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005476option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005477{
5478 /* if option doesn't need expansion nothing to do */
5479 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5480 return NULL;
5481
5482 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5483 * expand_env() would truncate the string. */
5484 if (val != NULL && STRLEN(val) > MAXPATHL)
5485 return NULL;
5486
5487 if (val == NULL)
5488 val = *(char_u **)options[opt_idx].var;
5489
5490 /*
5491 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5492 * Escape spaces when expanding 'tags', they are used to separate file
5493 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005494 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495 */
5496 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005497 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005498#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005499 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5500#endif
5501 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5503 return NULL;
5504
5505 return NameBuff;
5506}
5507
5508/*
5509 * After setting various option values: recompute variables that depend on
5510 * option values.
5511 */
5512 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005513didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514{
5515 /* initialize the table for 'iskeyword' et.al. */
5516 (void)init_chartab();
5517
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005518#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005519 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005520#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005522 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005523#ifdef FEAT_SESSION
5524 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5525 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5526#endif
5527#ifdef FEAT_FOLDING
5528 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5529#endif
5530 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005531 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005532#ifdef FEAT_VIRTUALEDIT
5533 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5534#endif
5535#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5536 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5537#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005538#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005539 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005540 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005541 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005542 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005543#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5545 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5546#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005547#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005548 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5549#endif
5550#ifdef FEAT_CMDWIN
5551 /* set cedit_key */
5552 (void)check_cedit();
5553#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005554#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005555 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005556#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005557#ifdef FEAT_LINEBREAK
5558 /* initialize the table for 'breakat'. */
5559 fill_breakat_flags();
5560#endif
5561
5562}
5563
5564/*
5565 * More side effects of setting options.
5566 */
5567 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005568didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005569{
5570 /* Initialize the highlight_attr[] table. */
5571 (void)highlight_changed();
5572
5573 /* Parse default for 'wildmode' */
5574 check_opt_wim();
5575
5576 (void)set_chars_option(&p_lcs);
5577#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5578 /* Parse default for 'fillchars'. */
5579 (void)set_chars_option(&p_fcs);
5580#endif
5581
5582#ifdef FEAT_CLIPBOARD
5583 /* Parse default for 'clipboard' */
5584 (void)check_clipboard_option();
5585#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005586}
5587
5588/*
5589 * Check for string options that are NULL (normally only termcap options).
5590 */
5591 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005592check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593{
5594 int opt_idx;
5595
5596 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5597 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5598 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5599}
5600
5601/*
5602 * Check string options in a buffer for NULL value.
5603 */
5604 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005605check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005606{
5607#if defined(FEAT_QUICKFIX)
5608 check_string_option(&buf->b_p_bh);
5609 check_string_option(&buf->b_p_bt);
5610#endif
5611#ifdef FEAT_MBYTE
5612 check_string_option(&buf->b_p_fenc);
5613#endif
5614 check_string_option(&buf->b_p_ff);
5615#ifdef FEAT_FIND_ID
5616 check_string_option(&buf->b_p_def);
5617 check_string_option(&buf->b_p_inc);
5618# ifdef FEAT_EVAL
5619 check_string_option(&buf->b_p_inex);
5620# endif
5621#endif
5622#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5623 check_string_option(&buf->b_p_inde);
5624 check_string_option(&buf->b_p_indk);
5625#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005626#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5627 check_string_option(&buf->b_p_bexpr);
5628#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005629#if defined(FEAT_CRYPT)
5630 check_string_option(&buf->b_p_cm);
5631#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005632 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005633#if defined(FEAT_EVAL)
5634 check_string_option(&buf->b_p_fex);
5635#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636#ifdef FEAT_CRYPT
5637 check_string_option(&buf->b_p_key);
5638#endif
5639 check_string_option(&buf->b_p_kp);
5640 check_string_option(&buf->b_p_mps);
5641 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005642 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643 check_string_option(&buf->b_p_isk);
5644#ifdef FEAT_COMMENTS
5645 check_string_option(&buf->b_p_com);
5646#endif
5647#ifdef FEAT_FOLDING
5648 check_string_option(&buf->b_p_cms);
5649#endif
5650 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005651#ifdef FEAT_TEXTOBJ
5652 check_string_option(&buf->b_p_qe);
5653#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654#ifdef FEAT_SYN_HL
5655 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005656 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005657#endif
5658#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005659 check_string_option(&buf->b_s.b_p_spc);
5660 check_string_option(&buf->b_s.b_p_spf);
5661 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662#endif
5663#ifdef FEAT_SEARCHPATH
5664 check_string_option(&buf->b_p_sua);
5665#endif
5666#ifdef FEAT_CINDENT
5667 check_string_option(&buf->b_p_cink);
5668 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005669 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670#endif
5671#ifdef FEAT_AUTOCMD
5672 check_string_option(&buf->b_p_ft);
5673#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005674#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5675 check_string_option(&buf->b_p_cinw);
5676#endif
5677#ifdef FEAT_INS_EXPAND
5678 check_string_option(&buf->b_p_cpt);
5679#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005680#ifdef FEAT_COMPL_FUNC
5681 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005682 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005683#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684#ifdef FEAT_KEYMAP
5685 check_string_option(&buf->b_p_keymap);
5686#endif
5687#ifdef FEAT_QUICKFIX
5688 check_string_option(&buf->b_p_gp);
5689 check_string_option(&buf->b_p_mp);
5690 check_string_option(&buf->b_p_efm);
5691#endif
5692 check_string_option(&buf->b_p_ep);
5693 check_string_option(&buf->b_p_path);
5694 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005695 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696#ifdef FEAT_INS_EXPAND
5697 check_string_option(&buf->b_p_dict);
5698 check_string_option(&buf->b_p_tsr);
5699#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005700#ifdef FEAT_LISP
5701 check_string_option(&buf->b_p_lw);
5702#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005703 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005704#ifdef FEAT_MBYTE
5705 check_string_option(&buf->b_p_menc);
5706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707}
5708
5709/*
5710 * Free the string allocated for an option.
5711 * Checks for the string being empty_option. This may happen if we're out of
5712 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5713 * check_options().
5714 * Does NOT check for P_ALLOCED flag!
5715 */
5716 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005717free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005718{
5719 if (p != empty_option)
5720 vim_free(p);
5721}
5722
5723 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005724clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725{
5726 if (*pp != empty_option)
5727 vim_free(*pp);
5728 *pp = empty_option;
5729}
5730
5731 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005732check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733{
5734 if (*pp == NULL)
5735 *pp = empty_option;
5736}
5737
5738/*
5739 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5740 */
5741 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005742set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005743{
5744 int opt_idx;
5745
5746 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5747 if (options[opt_idx].var == (char_u *)p)
5748 {
5749 options[opt_idx].flags |= P_ALLOCED;
5750 return;
5751 }
5752 return; /* cannot happen: didn't find it! */
5753}
5754
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005755#if defined(FEAT_EVAL) || defined(PROTO)
5756/*
5757 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5758 * Return FALSE when it wasn't.
5759 * Return -1 for an unknown option.
5760 */
5761 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005762was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005763{
5764 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005765 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005766
5767 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005768 {
5769 flagp = insecure_flag(idx, opt_flags);
5770 return (*flagp & P_INSECURE) != 0;
5771 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005772 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005773 return -1;
5774}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005775
5776/*
5777 * Get a pointer to the flags used for the P_INSECURE flag of option
5778 * "opt_idx". For some local options a local flags field is used.
5779 */
5780 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005781insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005782{
5783 if (opt_flags & OPT_LOCAL)
5784 switch ((int)options[opt_idx].indir)
5785 {
5786#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005787 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005788#endif
5789#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005790# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005791 case PV_FDE: return &curwin->w_p_fde_flags;
5792 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005793# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005794# ifdef FEAT_BEVAL
5795 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5796# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005797# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005798 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005799# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005800 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005801# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005802 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005803# endif
5804#endif
5805 }
5806
5807 /* Nothing special, return global flags field. */
5808 return &options[opt_idx].flags;
5809}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005810#endif
5811
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005812#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005813static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005814
5815/*
5816 * Redraw the window title and/or tab page text later.
5817 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005818static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005819{
5820 need_maketitle = TRUE;
5821# ifdef FEAT_WINDOWS
5822 redraw_tabline = TRUE;
5823# endif
5824}
5825#endif
5826
Bram Moolenaar071d4272004-06-13 20:20:40 +00005827/*
5828 * Set a string option to a new value (without checking the effect).
5829 * The string is copied into allocated memory.
5830 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005831 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005832 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005833 */
5834 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005835set_string_option_direct(
5836 char_u *name,
5837 int opt_idx,
5838 char_u *val,
5839 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5840 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841{
5842 char_u *s;
5843 char_u **varp;
5844 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005845 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846
Bram Moolenaar89d40322006-08-29 15:30:07 +00005847 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005849 idx = findoption(name);
5850 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005851 {
5852 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005853 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005854 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005855 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856 }
5857
Bram Moolenaar89d40322006-08-29 15:30:07 +00005858 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859 return;
5860
5861 s = vim_strsave(val);
5862 if (s != NULL)
5863 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005864 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005866 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867 free_string_option(*varp);
5868 *varp = s;
5869
5870 /* For buffer/window local option may also set the global value. */
5871 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005872 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005873
Bram Moolenaar89d40322006-08-29 15:30:07 +00005874 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875
5876 /* When setting both values of a global option with a local value,
5877 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005878 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 {
5880 free_string_option(*varp);
5881 *varp = empty_option;
5882 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005883# ifdef FEAT_EVAL
5884 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005885 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005886 set_sid == 0 ? current_SID : set_sid);
5887# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005888 }
5889}
5890
5891/*
5892 * Set global value for string option when it's a local option.
5893 */
5894 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005895set_string_option_global(
5896 int opt_idx, /* option index */
5897 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898{
5899 char_u **p, *s;
5900
5901 /* the global value is always allocated */
5902 if (options[opt_idx].var == VAR_WIN)
5903 p = (char_u **)GLOBAL_WO(varp);
5904 else
5905 p = (char_u **)options[opt_idx].var;
5906 if (options[opt_idx].indir != PV_NONE
5907 && p != varp
5908 && (s = vim_strsave(*varp)) != NULL)
5909 {
5910 free_string_option(*p);
5911 *p = s;
5912 }
5913}
5914
5915/*
5916 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005917 *
5918 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005920 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005921set_string_option(
5922 int opt_idx,
5923 char_u *value,
5924 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925{
5926 char_u *s;
5927 char_u **varp;
5928 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005929#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5930 char_u *saved_oldval = NULL;
5931#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005932 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005933
5934 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005935 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936
5937 s = vim_strsave(value);
5938 if (s != NULL)
5939 {
5940 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5941 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005942 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005943 ? OPT_GLOBAL : OPT_LOCAL)
5944 : opt_flags);
5945 oldval = *varp;
5946 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005947
5948#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005949 if (!starting
5950# ifdef FEAT_CRYPT
5951 && options[opt_idx].indir != PV_KEY
5952# endif
5953 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005954 saved_oldval = vim_strsave(oldval);
5955#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005956 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5957 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005958 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005959
Bram Moolenaara12e4032017-02-25 21:37:57 +01005960 /* call autocommand after handling side effects */
Bram Moolenaar53744302015-07-17 17:38:22 +02005961#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5962 if (saved_oldval != NULL)
5963 {
5964 char_u buf_type[7];
5965 sprintf((char *)buf_type, "%s",
5966 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005967 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5968 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005969 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5970 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5971 reset_v_option_vars();
5972 vim_free(saved_oldval);
5973 }
5974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005976 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977}
5978
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005979#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005980/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005981 * Return TRUE if "val" is a valid 'filetype' name.
5982 * Also used for 'syntax' and 'keymap'.
5983 */
5984 static int
5985valid_filetype(char_u *val)
5986{
5987 char_u *s;
5988
5989 for (s = val; *s != NUL; ++s)
5990 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5991 return FALSE;
5992 return TRUE;
5993}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005994#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005995
5996/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005997 * Handle string options that need some action to perform when changed.
5998 * Returns NULL for success, or an error message for an error.
5999 */
6000 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006001did_set_string_option(
6002 int opt_idx, /* index in options[] table */
6003 char_u **varp, /* pointer to the option variable */
6004 int new_value_alloced, /* new value was allocated */
6005 char_u *oldval, /* previous value of the option */
6006 char_u *errbuf, /* buffer for errors, or NULL */
6007 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006008{
6009 char_u *errmsg = NULL;
6010 char_u *s, *p;
6011 int did_chartab = FALSE;
6012 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006013 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006014#ifdef FEAT_GUI
6015 /* set when changing an option that only requires a redraw in the GUI */
6016 int redraw_gui_only = FALSE;
6017#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006018
6019 /* Get the global option to compare with, otherwise we would have to check
6020 * two values for all local options. */
6021 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6022
6023 /* Disallow changing some options from secure mode */
6024 if ((secure
6025#ifdef HAVE_SANDBOX
6026 || sandbox != 0
6027#endif
6028 ) && (options[opt_idx].flags & P_SECURE))
6029 {
6030 errmsg = e_secure;
6031 }
6032
Bram Moolenaar7554da42016-11-25 22:04:13 +01006033 /* Check for a "normal" directory or file name in some options. Disallow a
6034 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006035 * are often illegal in a file name. Be more permissive if "secure" is off.
6036 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006037 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006038 && vim_strpbrk(*varp, (char_u *)(secure
6039 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006040 || ((options[opt_idx].flags & P_NDNAME)
6041 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006042 {
6043 errmsg = e_invarg;
6044 }
6045
Bram Moolenaar071d4272004-06-13 20:20:40 +00006046 /* 'term' */
6047 else if (varp == &T_NAME)
6048 {
6049 if (T_NAME[0] == NUL)
6050 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6051#ifdef FEAT_GUI
6052 if (gui.in_use)
6053 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6054 else if (term_is_gui(T_NAME))
6055 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6056#endif
6057 else if (set_termname(T_NAME) == FAIL)
6058 errmsg = (char_u *)N_("E522: Not found in termcap");
6059 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006060 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006061 /* Screen colors may have changed. */
6062 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006063
6064 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6065 * P_ALLOCED flag on 'term'. */
6066 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006067 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006068 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006069 }
6070
6071 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006072 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006074 char_u *bkc = p_bkc;
6075 unsigned int *flags = &bkc_flags;
6076
6077 if (opt_flags & OPT_LOCAL)
6078 {
6079 bkc = curbuf->b_p_bkc;
6080 flags = &curbuf->b_bkc_flags;
6081 }
6082
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006083 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6084 /* make the local value empty: use the global value */
6085 *flags = 0;
6086 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006088 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6089 errmsg = e_invarg;
6090 if ((((int)*flags & BKC_AUTO) != 0)
6091 + (((int)*flags & BKC_YES) != 0)
6092 + (((int)*flags & BKC_NO) != 0) != 1)
6093 {
6094 /* Must have exactly one of "auto", "yes" and "no". */
6095 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6096 errmsg = e_invarg;
6097 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006098 }
6099 }
6100
6101 /* 'backupext' and 'patchmode' */
6102 else if (varp == &p_bex || varp == &p_pm)
6103 {
6104 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6105 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6106 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6107 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006108#ifdef FEAT_LINEBREAK
6109 /* 'breakindentopt' */
6110 else if (varp == &curwin->w_p_briopt)
6111 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006112 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006113 errmsg = e_invarg;
6114 }
6115#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116
6117 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006118 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006120 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006121 */
6122 else if ( varp == &p_isi
6123 || varp == &(curbuf->b_p_isk)
6124 || varp == &p_isp
6125 || varp == &p_isf)
6126 {
6127 if (init_chartab() == FAIL)
6128 {
6129 did_chartab = TRUE; /* need to restore it below */
6130 errmsg = e_invarg; /* error in value */
6131 }
6132 }
6133
6134 /* 'helpfile' */
6135 else if (varp == &p_hf)
6136 {
6137 /* May compute new values for $VIM and $VIMRUNTIME */
6138 if (didset_vim)
6139 {
6140 vim_setenv((char_u *)"VIM", (char_u *)"");
6141 didset_vim = FALSE;
6142 }
6143 if (didset_vimruntime)
6144 {
6145 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6146 didset_vimruntime = FALSE;
6147 }
6148 }
6149
Bram Moolenaar1a384422010-07-14 19:53:30 +02006150#ifdef FEAT_SYN_HL
6151 /* 'colorcolumn' */
6152 else if (varp == &curwin->w_p_cc)
6153 errmsg = check_colorcolumn(curwin);
6154#endif
6155
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156#ifdef FEAT_MULTI_LANG
6157 /* 'helplang' */
6158 else if (varp == &p_hlg)
6159 {
6160 /* Check for "", "ab", "ab,cd", etc. */
6161 for (s = p_hlg; *s != NUL; s += 3)
6162 {
6163 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6164 {
6165 errmsg = e_invarg;
6166 break;
6167 }
6168 if (s[2] == NUL)
6169 break;
6170 }
6171 }
6172#endif
6173
6174 /* 'highlight' */
6175 else if (varp == &p_hl)
6176 {
6177 if (highlight_changed() == FAIL)
6178 errmsg = e_invarg; /* invalid flags */
6179 }
6180
6181 /* 'nrformats' */
6182 else if (gvarp == &p_nf)
6183 {
6184 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6185 errmsg = e_invarg;
6186 }
6187
6188#ifdef FEAT_SESSION
6189 /* 'sessionoptions' */
6190 else if (varp == &p_ssop)
6191 {
6192 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6193 errmsg = e_invarg;
6194 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6195 {
6196 /* Don't allow both "sesdir" and "curdir". */
6197 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6198 errmsg = e_invarg;
6199 }
6200 }
6201 /* 'viewoptions' */
6202 else if (varp == &p_vop)
6203 {
6204 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6205 errmsg = e_invarg;
6206 }
6207#endif
6208
6209 /* 'scrollopt' */
6210#ifdef FEAT_SCROLLBIND
6211 else if (varp == &p_sbo)
6212 {
6213 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6214 errmsg = e_invarg;
6215 }
6216#endif
6217
6218 /* 'ambiwidth' */
6219#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006220 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221 {
6222 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6223 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006224 else if (set_chars_option(&p_lcs) != NULL)
6225 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6226# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6227 else if (set_chars_option(&p_fcs) != NULL)
6228 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6229# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006230 }
6231#endif
6232
6233 /* 'background' */
6234 else if (varp == &p_bg)
6235 {
6236 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6237 {
6238#ifdef FEAT_EVAL
6239 int dark = (*p_bg == 'd');
6240#endif
6241
6242 init_highlight(FALSE, FALSE);
6243
6244#ifdef FEAT_EVAL
6245 if (dark != (*p_bg == 'd')
6246 && get_var_value((char_u *)"g:colors_name") != NULL)
6247 {
6248 /* The color scheme must have set 'background' back to another
6249 * value, that's not what we want here. Disable the color
6250 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006251 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252 free_string_option(p_bg);
6253 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6254 check_string_option(&p_bg);
6255 init_highlight(FALSE, FALSE);
6256 }
6257#endif
6258 }
6259 else
6260 errmsg = e_invarg;
6261 }
6262
6263 /* 'wildmode' */
6264 else if (varp == &p_wim)
6265 {
6266 if (check_opt_wim() == FAIL)
6267 errmsg = e_invarg;
6268 }
6269
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006270#ifdef FEAT_CMDL_COMPL
6271 /* 'wildoptions' */
6272 else if (varp == &p_wop)
6273 {
6274 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6275 errmsg = e_invarg;
6276 }
6277#endif
6278
Bram Moolenaar071d4272004-06-13 20:20:40 +00006279#ifdef FEAT_WAK
6280 /* 'winaltkeys' */
6281 else if (varp == &p_wak)
6282 {
6283 if (*p_wak == NUL
6284 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6285 errmsg = e_invarg;
6286# ifdef FEAT_MENU
6287# ifdef FEAT_GUI_MOTIF
6288 else if (gui.in_use)
6289 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6290# else
6291# ifdef FEAT_GUI_GTK
6292 else if (gui.in_use)
6293 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6294# endif
6295# endif
6296# endif
6297 }
6298#endif
6299
6300#ifdef FEAT_AUTOCMD
6301 /* 'eventignore' */
6302 else if (varp == &p_ei)
6303 {
6304 if (check_ei() == FAIL)
6305 errmsg = e_invarg;
6306 }
6307#endif
6308
6309#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006310 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6311 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6312 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313 {
6314 if (gvarp == &p_fenc)
6315 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006316 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006317 errmsg = e_modifiable;
6318 else if (vim_strchr(*varp, ',') != NULL)
6319 /* No comma allowed in 'fileencoding'; catches confusing it
6320 * with 'fileencodings'. */
6321 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006322 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006323 {
6324# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006326 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006327# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006328 /* Add 'fileencoding' to the swap file. */
6329 ml_setflags(curbuf);
6330 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331 }
6332 if (errmsg == NULL)
6333 {
6334 /* canonize the value, so that STRCMP() can be used on it */
6335 p = enc_canonize(*varp);
6336 if (p != NULL)
6337 {
6338 vim_free(*varp);
6339 *varp = p;
6340 }
6341 if (varp == &p_enc)
6342 {
6343 errmsg = mb_init();
6344# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006345 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006346# endif
6347 }
6348 }
6349
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006350# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6352 {
6353 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6354 if (STRCMP(p_tenc, "utf-8") != 0)
6355 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6356 }
6357# endif
6358
6359 if (errmsg == NULL)
6360 {
6361# ifdef FEAT_KEYMAP
6362 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6363 * (with another encoding). */
6364 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6365 (void)keymap_init();
6366# endif
6367
6368 /* When 'termencoding' is not empty and 'encoding' changes or when
6369 * 'termencoding' changes, need to setup for keyboard input and
6370 * display output conversion. */
6371 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6372 {
6373 convert_setup(&input_conv, p_tenc, p_enc);
6374 convert_setup(&output_conv, p_enc, p_tenc);
6375 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006376
6377# if defined(WIN3264) && defined(FEAT_MBYTE)
6378 /* $HOME may have characters in active code page. */
6379 if (varp == &p_enc)
6380 init_homedir();
6381# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382 }
6383 }
6384#endif
6385
6386#if defined(FEAT_POSTSCRIPT)
6387 else if (varp == &p_penc)
6388 {
6389 /* Canonize printencoding if VIM standard one */
6390 p = enc_canonize(p_penc);
6391 if (p != NULL)
6392 {
6393 vim_free(p_penc);
6394 p_penc = p;
6395 }
6396 else
6397 {
6398 /* Ensure lower case and '-' for '_' */
6399 for (s = p_penc; *s != NUL; s++)
6400 {
6401 if (*s == '_')
6402 *s = '-';
6403 else
6404 *s = TOLOWER_ASC(*s);
6405 }
6406 }
6407 }
6408#endif
6409
Bram Moolenaar9372a112005-12-06 19:59:18 +00006410#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006411 else if (varp == &p_imak)
6412 {
6413 if (gui.in_use && !im_xim_isvalid_imactivate())
6414 errmsg = e_invarg;
6415 }
6416#endif
6417
6418#ifdef FEAT_KEYMAP
6419 else if (varp == &curbuf->b_p_keymap)
6420 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006421 if (!valid_filetype(*varp))
6422 errmsg = e_invarg;
6423 else
6424 /* load or unload key mapping tables */
6425 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006426
Bram Moolenaarfab06232009-03-04 03:13:35 +00006427 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006429 if (*curbuf->b_p_keymap != NUL)
6430 {
6431 /* Installed a new keymap, switch on using it. */
6432 curbuf->b_p_iminsert = B_IMODE_LMAP;
6433 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6434 curbuf->b_p_imsearch = B_IMODE_LMAP;
6435 }
6436 else
6437 {
6438 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6439 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6440 curbuf->b_p_iminsert = B_IMODE_NONE;
6441 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6442 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6443 }
6444 if ((opt_flags & OPT_LOCAL) == 0)
6445 {
6446 set_iminsert_global();
6447 set_imsearch_global();
6448 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449# ifdef FEAT_WINDOWS
6450 status_redraw_curbuf();
6451# endif
6452 }
6453 }
6454#endif
6455
6456 /* 'fileformat' */
6457 else if (gvarp == &p_ff)
6458 {
6459 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6460 errmsg = e_modifiable;
6461 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6462 errmsg = e_invarg;
6463 else
6464 {
6465 /* may also change 'textmode' */
6466 if (get_fileformat(curbuf) == EOL_DOS)
6467 curbuf->b_p_tx = TRUE;
6468 else
6469 curbuf->b_p_tx = FALSE;
6470#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006471 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006473 /* update flag in swap file */
6474 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006475 /* Redraw needed when switching to/from "mac": a CR in the text
6476 * will be displayed differently. */
6477 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6478 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006479 }
6480 }
6481
6482 /* 'fileformats' */
6483 else if (varp == &p_ffs)
6484 {
6485 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6486 errmsg = e_invarg;
6487 else
6488 {
6489 /* also change 'textauto' */
6490 if (*p_ffs == NUL)
6491 p_ta = FALSE;
6492 else
6493 p_ta = TRUE;
6494 }
6495 }
6496
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006497#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 /* 'cryptkey' */
6499 else if (gvarp == &p_key)
6500 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006501# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006502 /* Make sure the ":set" command doesn't show the new value in the
6503 * history. */
6504 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006505# endif
6506 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6507 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006508 ml_set_crypt_key(curbuf, oldval,
6509 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006510 }
6511
6512 else if (gvarp == &p_cm)
6513 {
6514 if (opt_flags & OPT_LOCAL)
6515 p = curbuf->b_p_cm;
6516 else
6517 p = p_cm;
6518 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6519 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006520 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006521 errmsg = e_invarg;
6522 else
6523 {
6524 /* When setting the global value to empty, make it "zip". */
6525 if (*p_cm == NUL)
6526 {
6527 if (new_value_alloced)
6528 free_string_option(p_cm);
6529 p_cm = vim_strsave((char_u *)"zip");
6530 new_value_alloced = TRUE;
6531 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006532 /* When using ":set cm=name" the local value is going to be empty.
6533 * Do that here, otherwise the crypt functions will still use the
6534 * local value. */
6535 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6536 {
6537 free_string_option(curbuf->b_p_cm);
6538 curbuf->b_p_cm = empty_option;
6539 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006540
6541 /* Need to update the swapfile when the effective method changed.
6542 * Set "s" to the effective old value, "p" to the effective new
6543 * method and compare. */
6544 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6545 s = p_cm; /* was previously using the global value */
6546 else
6547 s = oldval;
6548 if (*curbuf->b_p_cm == NUL)
6549 p = p_cm; /* is now using the global value */
6550 else
6551 p = curbuf->b_p_cm;
6552 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006553 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006554
6555 /* If the global value changes need to update the swapfile for all
6556 * buffers using that value. */
6557 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6558 {
6559 buf_T *buf;
6560
Bram Moolenaar29323592016-07-24 22:04:11 +02006561 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006562 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006563 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006564 }
6565 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 }
6567#endif
6568
6569 /* 'matchpairs' */
6570 else if (gvarp == &p_mps)
6571 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006572#ifdef FEAT_MBYTE
6573 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006574 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006575 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006576 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006577 int x2 = -1;
6578 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006579
6580 if (*p != NUL)
6581 p += mb_ptr2len(p);
6582 if (*p != NUL)
6583 x2 = *p++;
6584 if (*p != NUL)
6585 {
6586 x3 = mb_ptr2char(p);
6587 p += mb_ptr2len(p);
6588 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006589 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006590 {
6591 errmsg = e_invarg;
6592 break;
6593 }
6594 if (*p == NUL)
6595 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006596 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006597 }
6598 else
6599#endif
6600 {
6601 /* Check for "x:y,x:y" */
6602 for (p = *varp; *p != NUL; p += 4)
6603 {
6604 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6605 {
6606 errmsg = e_invarg;
6607 break;
6608 }
6609 if (p[3] == NUL)
6610 break;
6611 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006612 }
6613 }
6614
6615#ifdef FEAT_COMMENTS
6616 /* 'comments' */
6617 else if (gvarp == &p_com)
6618 {
6619 for (s = *varp; *s; )
6620 {
6621 while (*s && *s != ':')
6622 {
6623 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6624 && !VIM_ISDIGIT(*s) && *s != '-')
6625 {
6626 errmsg = illegal_char(errbuf, *s);
6627 break;
6628 }
6629 ++s;
6630 }
6631 if (*s++ == NUL)
6632 errmsg = (char_u *)N_("E524: Missing colon");
6633 else if (*s == ',' || *s == NUL)
6634 errmsg = (char_u *)N_("E525: Zero length string");
6635 if (errmsg != NULL)
6636 break;
6637 while (*s && *s != ',')
6638 {
6639 if (*s == '\\' && s[1] != NUL)
6640 ++s;
6641 ++s;
6642 }
6643 s = skip_to_option_part(s);
6644 }
6645 }
6646#endif
6647
6648 /* 'listchars' */
6649 else if (varp == &p_lcs)
6650 {
6651 errmsg = set_chars_option(varp);
6652 }
6653
6654#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6655 /* 'fillchars' */
6656 else if (varp == &p_fcs)
6657 {
6658 errmsg = set_chars_option(varp);
6659 }
6660#endif
6661
6662#ifdef FEAT_CMDWIN
6663 /* 'cedit' */
6664 else if (varp == &p_cedit)
6665 {
6666 errmsg = check_cedit();
6667 }
6668#endif
6669
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006670 /* 'verbosefile' */
6671 else if (varp == &p_vfile)
6672 {
6673 verbose_stop();
6674 if (*p_vfile != NUL && verbose_open() == FAIL)
6675 errmsg = e_invarg;
6676 }
6677
Bram Moolenaar071d4272004-06-13 20:20:40 +00006678#ifdef FEAT_VIMINFO
6679 /* 'viminfo' */
6680 else if (varp == &p_viminfo)
6681 {
6682 for (s = p_viminfo; *s;)
6683 {
6684 /* Check it's a valid character */
6685 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6686 {
6687 errmsg = illegal_char(errbuf, *s);
6688 break;
6689 }
6690 if (*s == 'n') /* name is always last one */
6691 {
6692 break;
6693 }
6694 else if (*s == 'r') /* skip until next ',' */
6695 {
6696 while (*++s && *s != ',')
6697 ;
6698 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006699 else if (*s == '%')
6700 {
6701 /* optional number */
6702 while (vim_isdigit(*++s))
6703 ;
6704 }
6705 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006706 ++s; /* no extra chars */
6707 else /* must have a number */
6708 {
6709 while (vim_isdigit(*++s))
6710 ;
6711
6712 if (!VIM_ISDIGIT(*(s - 1)))
6713 {
6714 if (errbuf != NULL)
6715 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006716 sprintf((char *)errbuf,
6717 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718 transchar_byte(*(s - 1)));
6719 errmsg = errbuf;
6720 }
6721 else
6722 errmsg = (char_u *)"";
6723 break;
6724 }
6725 }
6726 if (*s == ',')
6727 ++s;
6728 else if (*s)
6729 {
6730 if (errbuf != NULL)
6731 errmsg = (char_u *)N_("E527: Missing comma");
6732 else
6733 errmsg = (char_u *)"";
6734 break;
6735 }
6736 }
6737 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6738 errmsg = (char_u *)N_("E528: Must specify a ' value");
6739 }
6740#endif /* FEAT_VIMINFO */
6741
6742 /* terminal options */
6743 else if (istermoption(&options[opt_idx]) && full_screen)
6744 {
6745 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6746 if (varp == &T_CCO)
6747 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006748 int colors = atoi((char *)T_CCO);
6749
6750 /* Only reinitialize colors if t_Co value has really changed to
6751 * avoid expensive reload of colorscheme if t_Co is set to the
6752 * same value multiple times. */
6753 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006755 t_colors = colors;
6756 if (t_colors <= 1)
6757 {
6758 if (new_value_alloced)
6759 vim_free(T_CCO);
6760 T_CCO = empty_option;
6761 }
6762 /* We now have a different color setup, initialize it again. */
6763 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006764 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765 }
6766 ttest(FALSE);
6767 if (varp == &T_ME)
6768 {
6769 out_str(T_ME);
6770 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006771#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772 /* Since t_me has been set, this probably means that the user
6773 * wants to use this as default colors. Need to reset default
6774 * background/foreground colors. */
6775 mch_set_normal_colors();
6776#endif
6777 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006778 if (varp == &T_BE && termcap_active)
6779 {
6780 if (*T_BE == NUL)
6781 /* When clearing t_BE we assume the user no longer wants
6782 * bracketed paste, thus disable it by writing t_BD. */
6783 out_str(T_BD);
6784 else
6785 out_str(T_BE);
6786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006787 }
6788
6789#ifdef FEAT_LINEBREAK
6790 /* 'showbreak' */
6791 else if (varp == &p_sbr)
6792 {
6793 for (s = p_sbr; *s; )
6794 {
6795 if (ptr2cells(s) != 1)
6796 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006797 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006798 }
6799 }
6800#endif
6801
6802#ifdef FEAT_GUI
6803 /* 'guifont' */
6804 else if (varp == &p_guifont)
6805 {
6806 if (gui.in_use)
6807 {
6808 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006809# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006810 /*
6811 * Put up a font dialog and let the user select a new value.
6812 * If this is cancelled go back to the old value but don't
6813 * give an error message.
6814 */
6815 if (STRCMP(p, "*") == 0)
6816 {
6817 p = gui_mch_font_dialog(oldval);
6818
6819 if (new_value_alloced)
6820 free_string_option(p_guifont);
6821
6822 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6823 new_value_alloced = TRUE;
6824 }
6825# endif
6826 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6827 {
6828# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6829 if (STRCMP(p_guifont, "*") == 0)
6830 {
6831 /* Dialog was cancelled: Keep the old value without giving
6832 * an error message. */
6833 if (new_value_alloced)
6834 free_string_option(p_guifont);
6835 p_guifont = vim_strsave(oldval);
6836 new_value_alloced = TRUE;
6837 }
6838 else
6839# endif
6840 errmsg = (char_u *)N_("E596: Invalid font(s)");
6841 }
6842 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006843 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844 }
6845# ifdef FEAT_XFONTSET
6846 else if (varp == &p_guifontset)
6847 {
6848 if (STRCMP(p_guifontset, "*") == 0)
6849 errmsg = (char_u *)N_("E597: can't select fontset");
6850 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6851 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006852 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006853 }
6854# endif
6855# ifdef FEAT_MBYTE
6856 else if (varp == &p_guifontwide)
6857 {
6858 if (STRCMP(p_guifontwide, "*") == 0)
6859 errmsg = (char_u *)N_("E533: can't select wide font");
6860 else if (gui_get_wide_font() == FAIL)
6861 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006862 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006863 }
6864# endif
6865#endif
6866
6867#ifdef CURSOR_SHAPE
6868 /* 'guicursor' */
6869 else if (varp == &p_guicursor)
6870 errmsg = parse_shape_opt(SHAPE_CURSOR);
6871#endif
6872
6873#ifdef FEAT_MOUSESHAPE
6874 /* 'mouseshape' */
6875 else if (varp == &p_mouseshape)
6876 {
6877 errmsg = parse_shape_opt(SHAPE_MOUSE);
6878 update_mouseshape(-1);
6879 }
6880#endif
6881
6882#ifdef FEAT_PRINTER
6883 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006884 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006885# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006886 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006887 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006888# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006889#endif
6890
6891#ifdef FEAT_LANGMAP
6892 /* 'langmap' */
6893 else if (varp == &p_langmap)
6894 langmap_set();
6895#endif
6896
6897#ifdef FEAT_LINEBREAK
6898 /* 'breakat' */
6899 else if (varp == &p_breakat)
6900 fill_breakat_flags();
6901#endif
6902
6903#ifdef FEAT_TITLE
6904 /* 'titlestring' and 'iconstring' */
6905 else if (varp == &p_titlestring || varp == &p_iconstring)
6906 {
6907# ifdef FEAT_STL_OPT
6908 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6909
6910 /* NULL => statusline syntax */
6911 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6912 stl_syntax |= flagval;
6913 else
6914 stl_syntax &= ~flagval;
6915# endif
6916 did_set_title(varp == &p_iconstring);
6917
6918 }
6919#endif
6920
6921#ifdef FEAT_GUI
6922 /* 'guioptions' */
6923 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006924 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006926 redraw_gui_only = TRUE;
6927 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006928#endif
6929
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006930#if defined(FEAT_GUI_TABLINE)
6931 /* 'guitablabel' */
6932 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006933 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006934 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006935 redraw_gui_only = TRUE;
6936 }
6937 /* 'guitabtooltip' */
6938 else if (varp == &p_gtt)
6939 {
6940 redraw_gui_only = TRUE;
6941 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006942#endif
6943
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6945 /* 'ttymouse' */
6946 else if (varp == &p_ttym)
6947 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006948 /* Switch the mouse off before changing the escape sequences used for
6949 * that. */
6950 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6952 errmsg = e_invarg;
6953 else
6954 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006955 if (termcap_active)
6956 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957 }
6958#endif
6959
Bram Moolenaar071d4272004-06-13 20:20:40 +00006960 /* 'selection' */
6961 else if (varp == &p_sel)
6962 {
6963 if (*p_sel == NUL
6964 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6965 errmsg = e_invarg;
6966 }
6967
6968 /* 'selectmode' */
6969 else if (varp == &p_slm)
6970 {
6971 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6972 errmsg = e_invarg;
6973 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974
6975#ifdef FEAT_BROWSE
6976 /* 'browsedir' */
6977 else if (varp == &p_bsdir)
6978 {
6979 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6980 && !mch_isdir(p_bsdir))
6981 errmsg = e_invarg;
6982 }
6983#endif
6984
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985 /* 'keymodel' */
6986 else if (varp == &p_km)
6987 {
6988 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6989 errmsg = e_invarg;
6990 else
6991 {
6992 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6993 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6994 }
6995 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996
6997 /* 'mousemodel' */
6998 else if (varp == &p_mousem)
6999 {
7000 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7001 errmsg = e_invarg;
7002#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7003 else if (*p_mousem != *oldval)
7004 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7005 * to create or delete the popup menus. */
7006 gui_motif_update_mousemodel(root_menu);
7007#endif
7008 }
7009
7010 /* 'switchbuf' */
7011 else if (varp == &p_swb)
7012 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007013 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 errmsg = e_invarg;
7015 }
7016
7017 /* 'debug' */
7018 else if (varp == &p_debug)
7019 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007020 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007021 errmsg = e_invarg;
7022 }
7023
7024 /* 'display' */
7025 else if (varp == &p_dy)
7026 {
7027 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7028 errmsg = e_invarg;
7029 else
7030 (void)init_chartab();
7031
7032 }
7033
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007034#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007035 /* 'eadirection' */
7036 else if (varp == &p_ead)
7037 {
7038 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7039 errmsg = e_invarg;
7040 }
7041#endif
7042
7043#ifdef FEAT_CLIPBOARD
7044 /* 'clipboard' */
7045 else if (varp == &p_cb)
7046 errmsg = check_clipboard_option();
7047#endif
7048
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007049#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007050 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7051 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007052 else if (varp == &(curwin->w_s->b_p_spl)
7053 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007054 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007055 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007056 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007057 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007058 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007059 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007060 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007061 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007062 /* 'spellsuggest' */
7063 else if (varp == &p_sps)
7064 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007065 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007066 errmsg = e_invarg;
7067 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007068 /* 'mkspellmem' */
7069 else if (varp == &p_msm)
7070 {
7071 if (spell_check_msm() != OK)
7072 errmsg = e_invarg;
7073 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007074#endif
7075
Bram Moolenaar071d4272004-06-13 20:20:40 +00007076#ifdef FEAT_QUICKFIX
7077 /* When 'bufhidden' is set, check for valid value. */
7078 else if (gvarp == &p_bh)
7079 {
7080 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7081 errmsg = e_invarg;
7082 }
7083
7084 /* When 'buftype' is set, check for valid value. */
7085 else if (gvarp == &p_bt)
7086 {
7087 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7088 errmsg = e_invarg;
7089 else
7090 {
7091# ifdef FEAT_WINDOWS
7092 if (curwin->w_status_height)
7093 {
7094 curwin->w_redr_status = TRUE;
7095 redraw_later(VALID);
7096 }
7097# endif
7098 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007099# ifdef FEAT_TITLE
7100 redraw_titles();
7101# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102 }
7103 }
7104#endif
7105
7106#ifdef FEAT_STL_OPT
7107 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007108 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007109 {
7110 int wid;
7111
7112 if (varp == &p_ruf) /* reset ru_wid first */
7113 ru_wid = 0;
7114 s = *varp;
7115 if (varp == &p_ruf && *s == '%')
7116 {
7117 /* set ru_wid if 'ruf' starts with "%99(" */
7118 if (*++s == '-') /* ignore a '-' */
7119 s++;
7120 wid = getdigits(&s);
7121 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7122 ru_wid = wid;
7123 else
7124 errmsg = check_stl_option(p_ruf);
7125 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007126 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007127 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007128 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007129 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130 comp_col();
7131 }
7132#endif
7133
7134#ifdef FEAT_INS_EXPAND
7135 /* check if it is a valid value for 'complete' -- Acevedo */
7136 else if (gvarp == &p_cpt)
7137 {
7138 for (s = *varp; *s;)
7139 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007140 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007141 s++;
7142 if (!*s)
7143 break;
7144 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7145 {
7146 errmsg = illegal_char(errbuf, *s);
7147 break;
7148 }
7149 if (*++s != NUL && *s != ',' && *s != ' ')
7150 {
7151 if (s[-1] == 'k' || s[-1] == 's')
7152 {
7153 /* skip optional filename after 'k' and 's' */
7154 while (*s && *s != ',' && *s != ' ')
7155 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007156 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157 ++s;
7158 ++s;
7159 }
7160 }
7161 else
7162 {
7163 if (errbuf != NULL)
7164 {
7165 sprintf((char *)errbuf,
7166 _("E535: Illegal character after <%c>"),
7167 *--s);
7168 errmsg = errbuf;
7169 }
7170 else
7171 errmsg = (char_u *)"";
7172 break;
7173 }
7174 }
7175 }
7176 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007177
7178 /* 'completeopt' */
7179 else if (varp == &p_cot)
7180 {
7181 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7182 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007183 else
7184 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007185 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007186#endif /* FEAT_INS_EXPAND */
7187
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007188#ifdef FEAT_SIGNS
7189 /* 'signcolumn' */
7190 else if (varp == &curwin->w_p_scl)
7191 {
7192 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7193 errmsg = e_invarg;
7194 }
7195#endif
7196
Bram Moolenaar071d4272004-06-13 20:20:40 +00007197
7198#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007199 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007200 else if (varp == &p_toolbar)
7201 {
7202 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7203 &toolbar_flags, TRUE) != OK)
7204 errmsg = e_invarg;
7205 else
7206 {
7207 out_flush();
7208 gui_mch_show_toolbar((toolbar_flags &
7209 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7210 }
7211 }
7212#endif
7213
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007214#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007215 /* 'toolbariconsize': GTK+ 2 only */
7216 else if (varp == &p_tbis)
7217 {
7218 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7219 errmsg = e_invarg;
7220 else
7221 {
7222 out_flush();
7223 gui_mch_show_toolbar((toolbar_flags &
7224 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7225 }
7226 }
7227#endif
7228
7229 /* 'pastetoggle': translate key codes like in a mapping */
7230 else if (varp == &p_pt)
7231 {
7232 if (*p_pt)
7233 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007234 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007235 if (p != NULL)
7236 {
7237 if (new_value_alloced)
7238 free_string_option(p_pt);
7239 p_pt = p;
7240 new_value_alloced = TRUE;
7241 }
7242 }
7243 }
7244
7245 /* 'backspace' */
7246 else if (varp == &p_bs)
7247 {
7248 if (VIM_ISDIGIT(*p_bs))
7249 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007250 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 errmsg = e_invarg;
7252 }
7253 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7254 errmsg = e_invarg;
7255 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007256 else if (varp == &p_bo)
7257 {
7258 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7259 errmsg = e_invarg;
7260 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007262 /* 'tagcase' */
7263 else if (gvarp == &p_tc)
7264 {
7265 unsigned int *flags;
7266
7267 if (opt_flags & OPT_LOCAL)
7268 {
7269 p = curbuf->b_p_tc;
7270 flags = &curbuf->b_tc_flags;
7271 }
7272 else
7273 {
7274 p = p_tc;
7275 flags = &tc_flags;
7276 }
7277
7278 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7279 /* make the local value empty: use the global value */
7280 *flags = 0;
7281 else if (*p == NUL
7282 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7283 errmsg = e_invarg;
7284 }
7285
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007286#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007287 /* 'casemap' */
7288 else if (varp == &p_cmp)
7289 {
7290 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7291 errmsg = e_invarg;
7292 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007294
7295#ifdef FEAT_DIFF
7296 /* 'diffopt' */
7297 else if (varp == &p_dip)
7298 {
7299 if (diffopt_changed() == FAIL)
7300 errmsg = e_invarg;
7301 }
7302#endif
7303
7304#ifdef FEAT_FOLDING
7305 /* 'foldmethod' */
7306 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7307 {
7308 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7309 || *curwin->w_p_fdm == NUL)
7310 errmsg = e_invarg;
7311 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007312 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007314 if (foldmethodIsDiff(curwin))
7315 newFoldLevel();
7316 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 }
7318# ifdef FEAT_EVAL
7319 /* 'foldexpr' */
7320 else if (varp == &curwin->w_p_fde)
7321 {
7322 if (foldmethodIsExpr(curwin))
7323 foldUpdateAll(curwin);
7324 }
7325# endif
7326 /* 'foldmarker' */
7327 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7328 {
7329 p = vim_strchr(*varp, ',');
7330 if (p == NULL)
7331 errmsg = (char_u *)N_("E536: comma required");
7332 else if (p == *varp || p[1] == NUL)
7333 errmsg = e_invarg;
7334 else if (foldmethodIsMarker(curwin))
7335 foldUpdateAll(curwin);
7336 }
7337 /* 'commentstring' */
7338 else if (gvarp == &p_cms)
7339 {
7340 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7341 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7342 }
7343 /* 'foldopen' */
7344 else if (varp == &p_fdo)
7345 {
7346 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7347 errmsg = e_invarg;
7348 }
7349 /* 'foldclose' */
7350 else if (varp == &p_fcl)
7351 {
7352 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7353 errmsg = e_invarg;
7354 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007355 /* 'foldignore' */
7356 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7357 {
7358 if (foldmethodIsIndent(curwin))
7359 foldUpdateAll(curwin);
7360 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007361#endif
7362
7363#ifdef FEAT_VIRTUALEDIT
7364 /* 'virtualedit' */
7365 else if (varp == &p_ve)
7366 {
7367 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7368 errmsg = e_invarg;
7369 else if (STRCMP(p_ve, oldval) != 0)
7370 {
7371 /* Recompute cursor position in case the new 've' setting
7372 * changes something. */
7373 validate_virtcol();
7374 coladvance(curwin->w_virtcol);
7375 }
7376 }
7377#endif
7378
7379#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7380 else if (varp == &p_csqf)
7381 {
7382 if (p_csqf != NULL)
7383 {
7384 p = p_csqf;
7385 while (*p != NUL)
7386 {
7387 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7388 || p[1] == NUL
7389 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7390 || (p[2] != NUL && p[2] != ','))
7391 {
7392 errmsg = e_invarg;
7393 break;
7394 }
7395 else if (p[2] == NUL)
7396 break;
7397 else
7398 p += 3;
7399 }
7400 }
7401 }
7402#endif
7403
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007404#ifdef FEAT_CINDENT
7405 /* 'cinoptions' */
7406 else if (gvarp == &p_cino)
7407 {
7408 /* TODO: recognize errors */
7409 parse_cino(curbuf);
7410 }
7411#endif
7412
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007413#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007414 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007415 else if (varp == &p_rop && gui.in_use)
7416 {
7417 if (!gui_mch_set_rendering_options(p_rop))
7418 errmsg = e_invarg;
7419 }
7420#endif
7421
Bram Moolenaard0b51382016-11-04 15:23:45 +01007422#ifdef FEAT_AUTOCMD
7423 else if (gvarp == &p_ft)
7424 {
7425 if (!valid_filetype(*varp))
7426 errmsg = e_invarg;
7427 }
7428#endif
7429
7430#ifdef FEAT_SYN_HL
7431 else if (gvarp == &p_syn)
7432 {
7433 if (!valid_filetype(*varp))
7434 errmsg = e_invarg;
7435 }
7436#endif
7437
Bram Moolenaar071d4272004-06-13 20:20:40 +00007438 /* Options that are a list of flags. */
7439 else
7440 {
7441 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007442 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007444 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007446 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007447 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007448 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007450#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007451 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007452 p = (char_u *)COCU_ALL;
7453#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007454 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007455 {
7456#ifdef FEAT_MOUSE
7457 p = (char_u *)MOUSE_ALL;
7458#else
7459 if (*p_mouse != NUL)
7460 errmsg = (char_u *)N_("E538: No mouse support");
7461#endif
7462 }
7463#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007464 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007465 p = (char_u *)GO_ALL;
7466#endif
7467 if (p != NULL)
7468 {
7469 for (s = *varp; *s; ++s)
7470 if (vim_strchr(p, *s) == NULL)
7471 {
7472 errmsg = illegal_char(errbuf, *s);
7473 break;
7474 }
7475 }
7476 }
7477
7478 /*
7479 * If error detected, restore the previous value.
7480 */
7481 if (errmsg != NULL)
7482 {
7483 if (new_value_alloced)
7484 free_string_option(*varp);
7485 *varp = oldval;
7486 /*
7487 * When resetting some values, need to act on it.
7488 */
7489 if (did_chartab)
7490 (void)init_chartab();
7491 if (varp == &p_hl)
7492 (void)highlight_changed();
7493 }
7494 else
7495 {
7496#ifdef FEAT_EVAL
7497 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007498 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499#endif
7500 /*
7501 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007502 * Use "free_oldval", because recursiveness may change the flags under
7503 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007505 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 free_string_option(oldval);
7507 if (new_value_alloced)
7508 options[opt_idx].flags |= P_ALLOCED;
7509 else
7510 options[opt_idx].flags &= ~P_ALLOCED;
7511
7512 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007513 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 {
7515 /* global option with local value set to use global value; free
7516 * the local value and make it empty */
7517 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7518 free_string_option(*(char_u **)p);
7519 *(char_u **)p = empty_option;
7520 }
7521
7522 /* May set global value for local option. */
7523 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7524 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007525
7526#ifdef FEAT_AUTOCMD
7527 /*
7528 * Trigger the autocommand only after setting the flags.
7529 */
7530# ifdef FEAT_SYN_HL
7531 /* When 'syntax' is set, load the syntax of that name */
7532 if (varp == &(curbuf->b_p_syn))
7533 {
7534 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7535 curbuf->b_fname, TRUE, curbuf);
7536 }
7537# endif
7538 else if (varp == &(curbuf->b_p_ft))
7539 {
7540 /* 'filetype' is set, trigger the FileType autocommand */
7541 did_filetype = TRUE;
7542 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7543 curbuf->b_fname, TRUE, curbuf);
7544 }
7545#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007546#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007547 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007548 {
7549 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007550 char_u *q = curwin->w_s->b_p_spl;
7551
7552 /* Skip the first name if it is "cjk". */
7553 if (STRNCMP(q, "cjk,", 4) == 0)
7554 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007555
7556 /*
7557 * Source the spell/LANG.vim in 'runtimepath'.
7558 * They could set 'spellcapcheck' depending on the language.
7559 * Use the first name in 'spelllang' up to '_region' or
7560 * '.encoding'.
7561 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007562 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007563 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7564 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007565 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007566 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007567 }
7568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007569 }
7570
7571#ifdef FEAT_MOUSE
7572 if (varp == &p_mouse)
7573 {
7574# ifdef FEAT_MOUSE_TTY
7575 if (*p_mouse == NUL)
7576 mch_setmouse(FALSE); /* switch mouse off */
7577 else
7578# endif
7579 setmouse(); /* in case 'mouse' changed */
7580 }
7581#endif
7582
Bram Moolenaar913077c2012-03-28 19:59:04 +02007583 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007584 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007585 curwin->w_set_curswant = TRUE;
7586
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007587#ifdef FEAT_GUI
7588 /* check redraw when it's not a GUI option or the GUI is active. */
7589 if (!redraw_gui_only || gui.in_use)
7590#endif
7591 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592
7593 return errmsg;
7594}
7595
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007596#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007597/*
7598 * Simple int comparison function for use with qsort()
7599 */
7600 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007601int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007602{
7603 return *(const int *)a - *(const int *)b;
7604}
7605
7606/*
7607 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7608 * Returns error message, NULL if it's OK.
7609 */
7610 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007611check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007612{
7613 char_u *s;
7614 int col;
7615 int count = 0;
7616 int color_cols[256];
7617 int i;
7618 int j = 0;
7619
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007620 if (wp->w_buffer == NULL)
7621 return NULL; /* buffer was closed */
7622
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007623 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007624 {
7625 if (*s == '-' || *s == '+')
7626 {
7627 /* -N and +N: add to 'textwidth' */
7628 col = (*s == '-') ? -1 : 1;
7629 ++s;
7630 if (!VIM_ISDIGIT(*s))
7631 return e_invarg;
7632 col = col * getdigits(&s);
7633 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007634 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007635 col += wp->w_buffer->b_p_tw;
7636 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007637 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007638 }
7639 else if (VIM_ISDIGIT(*s))
7640 col = getdigits(&s);
7641 else
7642 return e_invarg;
7643 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007644skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007645 if (*s == NUL)
7646 break;
7647 if (*s != ',')
7648 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007649 if (*++s == NUL)
7650 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007651 }
7652
7653 vim_free(wp->w_p_cc_cols);
7654 if (count == 0)
7655 wp->w_p_cc_cols = NULL;
7656 else
7657 {
7658 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7659 if (wp->w_p_cc_cols != NULL)
7660 {
7661 /* sort the columns for faster usage on screen redraw inside
7662 * win_line() */
7663 qsort(color_cols, count, sizeof(int), int_cmp);
7664
7665 for (i = 0; i < count; ++i)
7666 /* skip duplicates */
7667 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7668 wp->w_p_cc_cols[j++] = color_cols[i];
7669 wp->w_p_cc_cols[j] = -1; /* end marker */
7670 }
7671 }
7672
7673 return NULL; /* no error */
7674}
7675#endif
7676
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677/*
7678 * Handle setting 'listchars' or 'fillchars'.
7679 * Returns error message, NULL if it's OK.
7680 */
7681 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007682set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007683{
7684 int round, i, len, entries;
7685 char_u *p, *s;
7686 int c1, c2 = 0;
7687 struct charstab
7688 {
7689 int *cp;
7690 char *name;
7691 };
7692#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7693 static struct charstab filltab[] =
7694 {
7695 {&fill_stl, "stl"},
7696 {&fill_stlnc, "stlnc"},
7697 {&fill_vert, "vert"},
7698 {&fill_fold, "fold"},
7699 {&fill_diff, "diff"},
7700 };
7701#endif
7702 static struct charstab lcstab[] =
7703 {
7704 {&lcs_eol, "eol"},
7705 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007706 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007707 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007708 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709 {&lcs_tab2, "tab"},
7710 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007711#ifdef FEAT_CONCEAL
7712 {&lcs_conceal, "conceal"},
7713#else
7714 {NULL, "conceal"},
7715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007716 };
7717 struct charstab *tab;
7718
7719#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7720 if (varp == &p_lcs)
7721#endif
7722 {
7723 tab = lcstab;
7724 entries = sizeof(lcstab) / sizeof(struct charstab);
7725 }
7726#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7727 else
7728 {
7729 tab = filltab;
7730 entries = sizeof(filltab) / sizeof(struct charstab);
7731 }
7732#endif
7733
7734 /* first round: check for valid value, second round: assign values */
7735 for (round = 0; round <= 1; ++round)
7736 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007737 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007738 {
7739 /* After checking that the value is valid: set defaults: space for
7740 * 'fillchars', NUL for 'listchars' */
7741 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007742 if (tab[i].cp != NULL)
7743 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007744 if (varp == &p_lcs)
7745 lcs_tab1 = NUL;
7746#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7747 else
7748 fill_diff = '-';
7749#endif
7750 }
7751 p = *varp;
7752 while (*p)
7753 {
7754 for (i = 0; i < entries; ++i)
7755 {
7756 len = (int)STRLEN(tab[i].name);
7757 if (STRNCMP(p, tab[i].name, len) == 0
7758 && p[len] == ':'
7759 && p[len + 1] != NUL)
7760 {
7761 s = p + len + 1;
7762#ifdef FEAT_MBYTE
7763 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007764 if (mb_char2cells(c1) > 1)
7765 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766#else
7767 c1 = *s++;
7768#endif
7769 if (tab[i].cp == &lcs_tab2)
7770 {
7771 if (*s == NUL)
7772 continue;
7773#ifdef FEAT_MBYTE
7774 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007775 if (mb_char2cells(c2) > 1)
7776 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777#else
7778 c2 = *s++;
7779#endif
7780 }
7781 if (*s == ',' || *s == NUL)
7782 {
7783 if (round)
7784 {
7785 if (tab[i].cp == &lcs_tab2)
7786 {
7787 lcs_tab1 = c1;
7788 lcs_tab2 = c2;
7789 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007790 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 *(tab[i].cp) = c1;
7792
7793 }
7794 p = s;
7795 break;
7796 }
7797 }
7798 }
7799
7800 if (i == entries)
7801 return e_invarg;
7802 if (*p == ',')
7803 ++p;
7804 }
7805 }
7806
7807 return NULL; /* no error */
7808}
7809
7810#ifdef FEAT_STL_OPT
7811/*
7812 * Check validity of options with the 'statusline' format.
7813 * Return error message or NULL.
7814 */
7815 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007816check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007817{
7818 int itemcnt = 0;
7819 int groupdepth = 0;
7820 static char_u errbuf[80];
7821
7822 while (*s && itemcnt < STL_MAX_ITEM)
7823 {
7824 /* Check for valid keys after % sequences */
7825 while (*s && *s != '%')
7826 s++;
7827 if (!*s)
7828 break;
7829 s++;
7830 if (*s != '%' && *s != ')')
7831 ++itemcnt;
7832 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7833 {
7834 s++;
7835 continue;
7836 }
7837 if (*s == ')')
7838 {
7839 s++;
7840 if (--groupdepth < 0)
7841 break;
7842 continue;
7843 }
7844 if (*s == '-')
7845 s++;
7846 while (VIM_ISDIGIT(*s))
7847 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007848 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 continue;
7850 if (*s == '.')
7851 {
7852 s++;
7853 while (*s && VIM_ISDIGIT(*s))
7854 s++;
7855 }
7856 if (*s == '(')
7857 {
7858 groupdepth++;
7859 continue;
7860 }
7861 if (vim_strchr(STL_ALL, *s) == NULL)
7862 {
7863 return illegal_char(errbuf, *s);
7864 }
7865 if (*s == '{')
7866 {
7867 s++;
7868 while (*s != '}' && *s)
7869 s++;
7870 if (*s != '}')
7871 return (char_u *)N_("E540: Unclosed expression sequence");
7872 }
7873 }
7874 if (itemcnt >= STL_MAX_ITEM)
7875 return (char_u *)N_("E541: too many items");
7876 if (groupdepth != 0)
7877 return (char_u *)N_("E542: unbalanced groups");
7878 return NULL;
7879}
7880#endif
7881
7882#ifdef FEAT_CLIPBOARD
7883/*
7884 * Extract the items in the 'clipboard' option and set global values.
7885 */
7886 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007887check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007888{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007889 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007890 int new_autoselect_star = FALSE;
7891 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007893 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 regprog_T *new_exclude_prog = NULL;
7895 char_u *errmsg = NULL;
7896 char_u *p;
7897
7898 for (p = p_cb; *p != NUL; )
7899 {
7900 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7901 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007902 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 p += 7;
7904 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007905 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007906 && (p[11] == ',' || p[11] == NUL))
7907 {
7908 new_unnamed |= CLIP_UNNAMED_PLUS;
7909 p += 11;
7910 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007911 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007912 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007914 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 p += 10;
7916 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007917 else if (STRNCMP(p, "autoselectplus", 14) == 0
7918 && (p[14] == ',' || p[14] == NUL))
7919 {
7920 new_autoselect_plus = TRUE;
7921 p += 14;
7922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007924 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 {
7926 new_autoselectml = TRUE;
7927 p += 12;
7928 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007929 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7930 {
7931 new_html = TRUE;
7932 p += 4;
7933 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7935 {
7936 p += 8;
7937 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7938 if (new_exclude_prog == NULL)
7939 errmsg = e_invarg;
7940 break;
7941 }
7942 else
7943 {
7944 errmsg = e_invarg;
7945 break;
7946 }
7947 if (*p == ',')
7948 ++p;
7949 }
7950 if (errmsg == NULL)
7951 {
7952 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007953 clip_autoselect_star = new_autoselect_star;
7954 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007956 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007957 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007959#ifdef FEAT_GUI_GTK
7960 if (gui.in_use)
7961 {
7962 gui_gtk_set_selection_targets();
7963 gui_gtk_set_dnd_targets();
7964 }
7965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 }
7967 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007968 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969
7970 return errmsg;
7971}
7972#endif
7973
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007974#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007975 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007976did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007977{
7978 char_u *errmsg = NULL;
7979 win_T *wp;
7980 int l;
7981
7982 if (is_spellfile)
7983 {
7984 l = (int)STRLEN(curwin->w_s->b_p_spf);
7985 if (l > 0 && (l < 4
7986 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7987 errmsg = e_invarg;
7988 }
7989
7990 if (errmsg == NULL)
7991 {
7992 FOR_ALL_WINDOWS(wp)
7993 if (wp->w_buffer == curbuf && wp->w_p_spell)
7994 {
7995 errmsg = did_set_spelllang(wp);
7996# ifdef FEAT_WINDOWS
7997 break;
7998# endif
7999 }
8000 }
8001 return errmsg;
8002}
8003
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008004/*
8005 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8006 * Return error message when failed, NULL when OK.
8007 */
8008 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008009compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008010{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008011 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008012 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008013
Bram Moolenaar860cae12010-06-05 23:22:07 +02008014 if (*synblock->b_p_spc == NUL)
8015 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008016 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008017 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008018 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008019 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008020 if (re != NULL)
8021 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008022 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008023 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008024 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008025 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008026 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008027 return e_invarg;
8028 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008029 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008030 }
8031
Bram Moolenaar473de612013-06-08 18:19:48 +02008032 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008033 return NULL;
8034}
8035#endif
8036
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008037#if defined(FEAT_EVAL) || defined(PROTO)
8038/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008039 * Set the scriptID for an option, taking care of setting the buffer- or
8040 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008041 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008042 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008043set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008044{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008045 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8046 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008047
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008048 /* Remember where the option was set. For local options need to do that
8049 * in the buffer or window structure. */
8050 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008051 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008052 if (both || (opt_flags & OPT_LOCAL))
8053 {
8054 if (indir & PV_BUF)
8055 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8056 else if (indir & PV_WIN)
8057 curwin->w_p_scriptID[indir & PV_MASK] = id;
8058 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008059}
8060#endif
8061
Bram Moolenaar071d4272004-06-13 20:20:40 +00008062/*
8063 * Set the value of a boolean option, and take care of side effects.
8064 * Returns NULL for success, or an error message for an error.
8065 */
8066 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008067set_bool_option(
8068 int opt_idx, /* index in options[] table */
8069 char_u *varp, /* pointer to the option variable */
8070 int value, /* new value */
8071 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072{
8073 int old_value = *(int *)varp;
8074
Bram Moolenaar071d4272004-06-13 20:20:40 +00008075 /* Disallow changing some options from secure mode */
8076 if ((secure
8077#ifdef HAVE_SANDBOX
8078 || sandbox != 0
8079#endif
8080 ) && (options[opt_idx].flags & P_SECURE))
8081 return e_secure;
8082
8083 *(int *)varp = value; /* set the new value */
8084#ifdef FEAT_EVAL
8085 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008086 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087#endif
8088
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008089#ifdef FEAT_GUI
8090 need_mouse_correct = TRUE;
8091#endif
8092
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 /* May set global value for local option. */
8094 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8095 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8096
8097 /*
8098 * Handle side effects of changing a bool option.
8099 */
8100
8101 /* 'compatible' */
8102 if ((int *)varp == &p_cp)
8103 {
8104 compatible_set();
8105 }
8106
Bram Moolenaar920694c2016-08-21 17:45:02 +02008107#ifdef FEAT_LANGMAP
8108 if ((int *)varp == &p_lrm)
8109 /* 'langremap' -> !'langnoremap' */
8110 p_lnr = !p_lrm;
8111 else if ((int *)varp == &p_lnr)
8112 /* 'langnoremap' -> !'langremap' */
8113 p_lrm = !p_lnr;
8114#endif
8115
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008116#ifdef FEAT_PERSISTENT_UNDO
8117 /* 'undofile' */
8118 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8119 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008120 /* Only take action when the option was set. When reset we do not
8121 * delete the undo file, the option may be set again without making
8122 * any changes in between. */
8123 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008124 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008125 char_u hash[UNDO_HASH_SIZE];
8126 buf_T *save_curbuf = curbuf;
8127
Bram Moolenaar29323592016-07-24 22:04:11 +02008128 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008129 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008130 /* When 'undofile' is set globally: for every buffer, otherwise
8131 * only for the current buffer: Try to read in the undofile,
8132 * if one exists, the buffer wasn't changed and the buffer was
8133 * loaded */
8134 if ((curbuf == save_curbuf
8135 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8136 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8137 {
8138 u_compute_hash(hash);
8139 u_read_undo(NULL, hash, curbuf->b_fname);
8140 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008141 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008142 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008143 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008144 }
8145#endif
8146
Bram Moolenaar071d4272004-06-13 20:20:40 +00008147 else if ((int *)varp == &curbuf->b_p_ro)
8148 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008149 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8151 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008152
8153 /* when 'readonly' is set may give W10 again */
8154 if (curbuf->b_p_ro)
8155 curbuf->b_did_warn = FALSE;
8156
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008158 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159#endif
8160 }
8161
Bram Moolenaar9c449722010-07-20 18:44:27 +02008162#ifdef FEAT_GUI
8163 else if ((int *)varp == &p_mh)
8164 {
8165 if (!p_mh)
8166 gui_mch_mousehide(FALSE);
8167 }
8168#endif
8169
Bram Moolenaara539df02010-08-01 14:35:05 +02008170#ifdef FEAT_TITLE
8171 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008173 {
8174 redraw_titles();
8175 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 /* when 'endofline' is changed, redraw the window title */
8177 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008178 {
8179 redraw_titles();
8180 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008181 /* when 'fixeol' is changed, redraw the window title */
8182 else if ((int *)varp == &curbuf->b_p_fixeol)
8183 {
8184 redraw_titles();
8185 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008186# ifdef FEAT_MBYTE
8187 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008188 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008189 {
8190 redraw_titles();
8191 }
8192# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193#endif
8194
8195 /* when 'bin' is set also set some other options */
8196 else if ((int *)varp == &curbuf->b_p_bin)
8197 {
8198 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8199#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008200 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008201#endif
8202 }
8203
8204#ifdef FEAT_AUTOCMD
8205 /* when 'buflisted' changes, trigger autocommands */
8206 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8207 {
8208 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8209 NULL, NULL, TRUE, curbuf);
8210 }
8211#endif
8212
8213 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8214 else if ((int *)varp == &curbuf->b_p_swf)
8215 {
8216 if (curbuf->b_p_swf && p_uc)
8217 ml_open_file(curbuf); /* create the swap file */
8218 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008219 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8220 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008221 mf_close_file(curbuf, TRUE); /* remove the swap file */
8222 }
8223
8224 /* when 'terse' is set change 'shortmess' */
8225 else if ((int *)varp == &p_terse)
8226 {
8227 char_u *p;
8228
8229 p = vim_strchr(p_shm, SHM_SEARCH);
8230
8231 /* insert 's' in p_shm */
8232 if (p_terse && p == NULL)
8233 {
8234 STRCPY(IObuff, p_shm);
8235 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008236 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237 }
8238 /* remove 's' from p_shm */
8239 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008240 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241 }
8242
8243 /* when 'paste' is set or reset also change other options */
8244 else if ((int *)varp == &p_paste)
8245 {
8246 paste_option_changed();
8247 }
8248
8249 /* when 'insertmode' is set from an autocommand need to do work here */
8250 else if ((int *)varp == &p_im)
8251 {
8252 if (p_im)
8253 {
8254 if ((State & INSERT) == 0)
8255 need_start_insertmode = TRUE;
8256 stop_insert_mode = FALSE;
8257 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008258 /* only reset if it was set previously */
8259 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260 {
8261 need_start_insertmode = FALSE;
8262 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008263 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008264 clear_cmdline = TRUE; /* remove "(insert)" */
8265 restart_edit = 0;
8266 }
8267 }
8268
8269 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8270 else if ((int *)varp == &p_ic && p_hls)
8271 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008272 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008273 }
8274
8275#ifdef FEAT_SEARCH_EXTRA
8276 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8277 else if ((int *)varp == &p_hls)
8278 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008279 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008280 }
8281#endif
8282
8283#ifdef FEAT_SCROLLBIND
8284 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8285 * at the end of normal_cmd() */
8286 else if ((int *)varp == &curwin->w_p_scb)
8287 {
8288 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008289 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008291 curwin->w_scbind_pos = curwin->w_topline;
8292 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008293 }
8294#endif
8295
8296#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8297 /* There can be only one window with 'previewwindow' set. */
8298 else if ((int *)varp == &curwin->w_p_pvw)
8299 {
8300 if (curwin->w_p_pvw)
8301 {
8302 win_T *win;
8303
Bram Moolenaar29323592016-07-24 22:04:11 +02008304 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008305 if (win->w_p_pvw && win != curwin)
8306 {
8307 curwin->w_p_pvw = FALSE;
8308 return (char_u *)N_("E590: A preview window already exists");
8309 }
8310 }
8311 }
8312#endif
8313
8314 /* when 'textmode' is set or reset also change 'fileformat' */
8315 else if ((int *)varp == &curbuf->b_p_tx)
8316 {
8317 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8318 }
8319
8320 /* when 'textauto' is set or reset also change 'fileformats' */
8321 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322 set_string_option_direct((char_u *)"ffs", -1,
8323 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008324 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008325
8326 /*
8327 * When 'lisp' option changes include/exclude '-' in
8328 * keyword characters.
8329 */
8330#ifdef FEAT_LISP
8331 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8332 {
8333 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8334 }
8335#endif
8336
8337#ifdef FEAT_TITLE
8338 /* when 'title' changed, may need to change the title; same for 'icon' */
8339 else if ((int *)varp == &p_title)
8340 {
8341 did_set_title(FALSE);
8342 }
8343
8344 else if ((int *)varp == &p_icon)
8345 {
8346 did_set_title(TRUE);
8347 }
8348#endif
8349
8350 else if ((int *)varp == &curbuf->b_changed)
8351 {
8352 if (!value)
8353 save_file_ff(curbuf); /* Buffer is unchanged */
8354#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008355 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356#endif
8357#ifdef FEAT_AUTOCMD
8358 modified_was_set = value;
8359#endif
8360 }
8361
8362#ifdef BACKSLASH_IN_FILENAME
8363 else if ((int *)varp == &p_ssl)
8364 {
8365 if (p_ssl)
8366 {
8367 psepc = '/';
8368 psepcN = '\\';
8369 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 }
8371 else
8372 {
8373 psepc = '\\';
8374 psepcN = '/';
8375 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376 }
8377
8378 /* need to adjust the file name arguments and buffer names. */
8379 buflist_slash_adjust();
8380 alist_slash_adjust();
8381# ifdef FEAT_EVAL
8382 scriptnames_slash_adjust();
8383# endif
8384 }
8385#endif
8386
8387 /* If 'wrap' is set, set w_leftcol to zero. */
8388 else if ((int *)varp == &curwin->w_p_wrap)
8389 {
8390 if (curwin->w_p_wrap)
8391 curwin->w_leftcol = 0;
8392 }
8393
8394#ifdef FEAT_WINDOWS
8395 else if ((int *)varp == &p_ea)
8396 {
8397 if (p_ea && !old_value)
8398 win_equal(curwin, FALSE, 0);
8399 }
8400#endif
8401
8402 else if ((int *)varp == &p_wiv)
8403 {
8404 /*
8405 * When 'weirdinvert' changed, set/reset 't_xs'.
8406 * Then set 'weirdinvert' according to value of 't_xs'.
8407 */
8408 if (p_wiv && !old_value)
8409 T_XS = (char_u *)"y";
8410 else if (!p_wiv && old_value)
8411 T_XS = empty_option;
8412 p_wiv = (*T_XS != NUL);
8413 }
8414
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008415#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 else if ((int *)varp == &p_beval)
8417 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008418 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008419 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008420 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 gui_mch_disable_beval_area(balloonEval);
8422 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008423#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008425#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426 else if ((int *)varp == &p_acd)
8427 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008428 /* Change directories when the 'acd' option is set now. */
8429 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 }
8431#endif
8432
8433#ifdef FEAT_DIFF
8434 /* 'diff' */
8435 else if ((int *)varp == &curwin->w_p_diff)
8436 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008437 /* May add or remove the buffer from the list of diff buffers. */
8438 diff_buf_adjust(curwin);
8439# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 if (foldmethodIsDiff(curwin))
8441 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008442# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443 }
8444#endif
8445
8446#ifdef USE_IM_CONTROL
8447 /* 'imdisable' */
8448 else if ((int *)varp == &p_imdisable)
8449 {
8450 /* Only de-activate it here, it will be enabled when changing mode. */
8451 if (p_imdisable)
8452 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008453 else if (State & INSERT)
8454 /* When the option is set from an autocommand, it may need to take
8455 * effect right away. */
8456 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 }
8458#endif
8459
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008460#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008461 /* 'spell' */
8462 else if ((int *)varp == &curwin->w_p_spell)
8463 {
8464 if (curwin->w_p_spell)
8465 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008466 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008467 if (errmsg != NULL)
8468 EMSG(_(errmsg));
8469 }
8470 }
8471#endif
8472
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473#ifdef FEAT_FKMAP
8474 else if ((int *)varp == &p_altkeymap)
8475 {
8476 if (old_value != p_altkeymap)
8477 {
8478 if (!p_altkeymap)
8479 {
8480 p_hkmap = p_fkmap;
8481 p_fkmap = 0;
8482 }
8483 else
8484 {
8485 p_fkmap = p_hkmap;
8486 p_hkmap = 0;
8487 }
8488 (void)init_chartab();
8489 }
8490 }
8491
8492 /*
8493 * In case some second language keymapping options have changed, check
8494 * and correct the setting in a consistent way.
8495 */
8496
8497 /*
8498 * If hkmap or fkmap are set, reset Arabic keymapping.
8499 */
8500 if ((p_hkmap || p_fkmap) && p_altkeymap)
8501 {
8502 p_altkeymap = p_fkmap;
8503# ifdef FEAT_ARABIC
8504 curwin->w_p_arab = FALSE;
8505# endif
8506 (void)init_chartab();
8507 }
8508
8509 /*
8510 * If hkmap set, reset Farsi keymapping.
8511 */
8512 if (p_hkmap && p_altkeymap)
8513 {
8514 p_altkeymap = 0;
8515 p_fkmap = 0;
8516# ifdef FEAT_ARABIC
8517 curwin->w_p_arab = FALSE;
8518# endif
8519 (void)init_chartab();
8520 }
8521
8522 /*
8523 * If fkmap set, reset Hebrew keymapping.
8524 */
8525 if (p_fkmap && !p_altkeymap)
8526 {
8527 p_altkeymap = 1;
8528 p_hkmap = 0;
8529# ifdef FEAT_ARABIC
8530 curwin->w_p_arab = FALSE;
8531# endif
8532 (void)init_chartab();
8533 }
8534#endif
8535
8536#ifdef FEAT_ARABIC
8537 if ((int *)varp == &curwin->w_p_arab)
8538 {
8539 if (curwin->w_p_arab)
8540 {
8541 /*
8542 * 'arabic' is set, handle various sub-settings.
8543 */
8544 if (!p_tbidi)
8545 {
8546 /* set rightleft mode */
8547 if (!curwin->w_p_rl)
8548 {
8549 curwin->w_p_rl = TRUE;
8550 changed_window_setting();
8551 }
8552
8553 /* Enable Arabic shaping (major part of what Arabic requires) */
8554 if (!p_arshape)
8555 {
8556 p_arshape = TRUE;
8557 redraw_later_clear();
8558 }
8559 }
8560
8561 /* Arabic requires a utf-8 encoding, inform the user if its not
8562 * set. */
8563 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008564 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008565 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8566
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008567 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008568 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8569#ifdef FEAT_EVAL
8570 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8571#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008572 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008573
8574# ifdef FEAT_MBYTE
8575 /* set 'delcombine' */
8576 p_deco = TRUE;
8577# endif
8578
8579# ifdef FEAT_KEYMAP
8580 /* Force-set the necessary keymap for arabic */
8581 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8582 OPT_LOCAL);
8583# endif
8584# ifdef FEAT_FKMAP
8585 p_altkeymap = 0;
8586 p_hkmap = 0;
8587 p_fkmap = 0;
8588 (void)init_chartab();
8589# endif
8590 }
8591 else
8592 {
8593 /*
8594 * 'arabic' is reset, handle various sub-settings.
8595 */
8596 if (!p_tbidi)
8597 {
8598 /* reset rightleft mode */
8599 if (curwin->w_p_rl)
8600 {
8601 curwin->w_p_rl = FALSE;
8602 changed_window_setting();
8603 }
8604
8605 /* 'arabicshape' isn't reset, it is a global option and
8606 * another window may still need it "on". */
8607 }
8608
8609 /* 'delcombine' isn't reset, it is a global option and another
8610 * window may still want it "on". */
8611
8612# ifdef FEAT_KEYMAP
8613 /* Revert to the default keymap */
8614 curbuf->b_p_iminsert = B_IMODE_NONE;
8615 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8616# endif
8617 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008618 }
8619
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008620#endif
8621
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008622#ifdef FEAT_TERMGUICOLORS
8623 /* 'termguicolors' */
8624 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008625 {
8626# ifdef FEAT_GUI
8627 if (!gui.in_use && !gui.starting)
8628# endif
8629 highlight_gui_started();
8630 }
8631#endif
8632
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633 /*
8634 * End of handling side effects for bool options.
8635 */
8636
Bram Moolenaar53744302015-07-17 17:38:22 +02008637 /* after handling side effects, call autocommand */
8638
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 options[opt_idx].flags |= P_WAS_SET;
8640
Bram Moolenaar53744302015-07-17 17:38:22 +02008641#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8642 if (!starting)
8643 {
8644 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008645 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8646 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8647 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008648 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8649 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8650 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8651 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8652 reset_v_option_vars();
8653 }
8654#endif
8655
Bram Moolenaar071d4272004-06-13 20:20:40 +00008656 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008657 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008658 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008659 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008660 check_redraw(options[opt_idx].flags);
8661
8662 return NULL;
8663}
8664
8665/*
8666 * Set the value of a number option, and take care of side effects.
8667 * Returns NULL for success, or an error message for an error.
8668 */
8669 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008670set_num_option(
8671 int opt_idx, /* index in options[] table */
8672 char_u *varp, /* pointer to the option variable */
8673 long value, /* new value */
8674 char_u *errbuf, /* buffer for error messages */
8675 size_t errbuflen, /* length of "errbuf" */
8676 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008677 OPT_MODELINE */
8678{
8679 char_u *errmsg = NULL;
8680 long old_value = *(long *)varp;
8681 long old_Rows = Rows; /* remember old Rows */
8682 long old_Columns = Columns; /* remember old Columns */
8683 long *pp = (long *)varp;
8684
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008685 /* Disallow changing some options from secure mode. */
8686 if ((secure
8687#ifdef HAVE_SANDBOX
8688 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008690 ) && (options[opt_idx].flags & P_SECURE))
8691 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008692
8693 *pp = value;
8694#ifdef FEAT_EVAL
8695 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008696 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008698#ifdef FEAT_GUI
8699 need_mouse_correct = TRUE;
8700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008701
Bram Moolenaar14f24742012-08-08 18:01:05 +02008702 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 {
8704 errmsg = e_positive;
8705 curbuf->b_p_sw = curbuf->b_p_ts;
8706 }
8707
8708 /*
8709 * Number options that need some action when changed
8710 */
8711#ifdef FEAT_WINDOWS
8712 if (pp == &p_wh || pp == &p_hh)
8713 {
8714 if (p_wh < 1)
8715 {
8716 errmsg = e_positive;
8717 p_wh = 1;
8718 }
8719 if (p_wmh > p_wh)
8720 {
8721 errmsg = e_winheight;
8722 p_wh = p_wmh;
8723 }
8724 if (p_hh < 0)
8725 {
8726 errmsg = e_positive;
8727 p_hh = 0;
8728 }
8729
8730 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008731 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732 {
8733 if (pp == &p_wh && curwin->w_height < p_wh)
8734 win_setheight((int)p_wh);
8735 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8736 win_setheight((int)p_hh);
8737 }
8738 }
8739
8740 /* 'winminheight' */
8741 else if (pp == &p_wmh)
8742 {
8743 if (p_wmh < 0)
8744 {
8745 errmsg = e_positive;
8746 p_wmh = 0;
8747 }
8748 if (p_wmh > p_wh)
8749 {
8750 errmsg = e_winheight;
8751 p_wmh = p_wh;
8752 }
8753 win_setminheight();
8754 }
8755
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008756# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008757 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008758 {
8759 if (p_wiw < 1)
8760 {
8761 errmsg = e_positive;
8762 p_wiw = 1;
8763 }
8764 if (p_wmw > p_wiw)
8765 {
8766 errmsg = e_winwidth;
8767 p_wiw = p_wmw;
8768 }
8769
8770 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008771 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 win_setwidth((int)p_wiw);
8773 }
8774
8775 /* 'winminwidth' */
8776 else if (pp == &p_wmw)
8777 {
8778 if (p_wmw < 0)
8779 {
8780 errmsg = e_positive;
8781 p_wmw = 0;
8782 }
8783 if (p_wmw > p_wiw)
8784 {
8785 errmsg = e_winwidth;
8786 p_wmw = p_wiw;
8787 }
8788 win_setminheight();
8789 }
8790# endif
8791
8792#endif
8793
8794#ifdef FEAT_WINDOWS
8795 /* (re)set last window status line */
8796 else if (pp == &p_ls)
8797 {
8798 last_status(FALSE);
8799 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008800
8801 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008802 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008803 {
8804 shell_new_rows(); /* recompute window positions and heights */
8805 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806#endif
8807
8808#ifdef FEAT_GUI
8809 else if (pp == &p_linespace)
8810 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008811 /* Recompute gui.char_height and resize the Vim window to keep the
8812 * same number of lines. */
8813 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008814 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008815 }
8816#endif
8817
8818#ifdef FEAT_FOLDING
8819 /* 'foldlevel' */
8820 else if (pp == &curwin->w_p_fdl)
8821 {
8822 if (curwin->w_p_fdl < 0)
8823 curwin->w_p_fdl = 0;
8824 newFoldLevel();
8825 }
8826
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008827 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828 else if (pp == &curwin->w_p_fml)
8829 {
8830 foldUpdateAll(curwin);
8831 }
8832
8833 /* 'foldnestmax' */
8834 else if (pp == &curwin->w_p_fdn)
8835 {
8836 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8837 foldUpdateAll(curwin);
8838 }
8839
8840 /* 'foldcolumn' */
8841 else if (pp == &curwin->w_p_fdc)
8842 {
8843 if (curwin->w_p_fdc < 0)
8844 {
8845 errmsg = e_positive;
8846 curwin->w_p_fdc = 0;
8847 }
8848 else if (curwin->w_p_fdc > 12)
8849 {
8850 errmsg = e_invarg;
8851 curwin->w_p_fdc = 12;
8852 }
8853 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008854#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008856#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 /* 'shiftwidth' or 'tabstop' */
8858 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8859 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008860# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 if (foldmethodIsIndent(curwin))
8862 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008863# endif
8864# ifdef FEAT_CINDENT
8865 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8866 * parse 'cinoptions'. */
8867 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8868 parse_cino(curbuf);
8869# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008873#ifdef FEAT_MBYTE
8874 /* 'maxcombine' */
8875 else if (pp == &p_mco)
8876 {
8877 if (p_mco > MAX_MCO)
8878 p_mco = MAX_MCO;
8879 else if (p_mco < 0)
8880 p_mco = 0;
8881 screenclear(); /* will re-allocate the screen */
8882 }
8883#endif
8884
Bram Moolenaar071d4272004-06-13 20:20:40 +00008885 else if (pp == &curbuf->b_p_iminsert)
8886 {
8887 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8888 {
8889 errmsg = e_invarg;
8890 curbuf->b_p_iminsert = B_IMODE_NONE;
8891 }
8892 p_iminsert = curbuf->b_p_iminsert;
8893 if (termcap_active) /* don't do this in the alternate screen */
8894 showmode();
8895#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8896 /* Show/unshow value of 'keymap' in status lines. */
8897 status_redraw_curbuf();
8898#endif
8899 }
8900
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008901 else if (pp == &p_window)
8902 {
8903 if (p_window < 1)
8904 p_window = 1;
8905 else if (p_window >= Rows)
8906 p_window = Rows - 1;
8907 }
8908
Bram Moolenaar071d4272004-06-13 20:20:40 +00008909 else if (pp == &curbuf->b_p_imsearch)
8910 {
8911 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8912 {
8913 errmsg = e_invarg;
8914 curbuf->b_p_imsearch = B_IMODE_NONE;
8915 }
8916 p_imsearch = curbuf->b_p_imsearch;
8917 }
8918
8919#ifdef FEAT_TITLE
8920 /* if 'titlelen' has changed, redraw the title */
8921 else if (pp == &p_titlelen)
8922 {
8923 if (p_titlelen < 0)
8924 {
8925 errmsg = e_positive;
8926 p_titlelen = 85;
8927 }
8928 if (starting != NO_SCREEN && old_value != p_titlelen)
8929 need_maketitle = TRUE;
8930 }
8931#endif
8932
8933 /* if p_ch changed value, change the command line height */
8934 else if (pp == &p_ch)
8935 {
8936 if (p_ch < 1)
8937 {
8938 errmsg = e_positive;
8939 p_ch = 1;
8940 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008941 if (p_ch > Rows - min_rows() + 1)
8942 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008943
8944 /* Only compute the new window layout when startup has been
8945 * completed. Otherwise the frame sizes may be wrong. */
8946 if (p_ch != old_value && full_screen
8947#ifdef FEAT_GUI
8948 && !gui.starting
8949#endif
8950 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008951 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952 }
8953
8954 /* when 'updatecount' changes from zero to non-zero, open swap files */
8955 else if (pp == &p_uc)
8956 {
8957 if (p_uc < 0)
8958 {
8959 errmsg = e_positive;
8960 p_uc = 100;
8961 }
8962 if (p_uc && !old_value)
8963 ml_open_files();
8964 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008965#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008966 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008967 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008968 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008969 {
8970 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008971 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008972 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008973 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008974 {
8975 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008976 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008977 }
8978 }
8979#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008980#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008981 else if (pp == &p_mzq)
8982 mzvim_reset_timer();
8983#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008984
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008985#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8986 /* 'pyxversion' */
8987 else if (pp == &p_pyx)
8988 {
8989 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8990 errmsg = e_invarg;
8991 }
8992#endif
8993
Bram Moolenaar071d4272004-06-13 20:20:40 +00008994 /* sync undo before 'undolevels' changes */
8995 else if (pp == &p_ul)
8996 {
8997 /* use the old value, otherwise u_sync() may not work properly */
8998 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008999 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000 p_ul = value;
9001 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009002 else if (pp == &curbuf->b_p_ul)
9003 {
9004 /* use the old value, otherwise u_sync() may not work properly */
9005 curbuf->b_p_ul = old_value;
9006 u_sync(TRUE);
9007 curbuf->b_p_ul = value;
9008 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009010#ifdef FEAT_LINEBREAK
9011 /* 'numberwidth' must be positive */
9012 else if (pp == &curwin->w_p_nuw)
9013 {
9014 if (curwin->w_p_nuw < 1)
9015 {
9016 errmsg = e_positive;
9017 curwin->w_p_nuw = 1;
9018 }
9019 if (curwin->w_p_nuw > 10)
9020 {
9021 errmsg = e_invarg;
9022 curwin->w_p_nuw = 10;
9023 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009024 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009025 }
9026#endif
9027
Bram Moolenaar1a384422010-07-14 19:53:30 +02009028 else if (pp == &curbuf->b_p_tw)
9029 {
9030 if (curbuf->b_p_tw < 0)
9031 {
9032 errmsg = e_positive;
9033 curbuf->b_p_tw = 0;
9034 }
9035#ifdef FEAT_SYN_HL
9036# ifdef FEAT_WINDOWS
9037 {
9038 win_T *wp;
9039 tabpage_T *tp;
9040
9041 FOR_ALL_TAB_WINDOWS(tp, wp)
9042 check_colorcolumn(wp);
9043 }
9044# else
9045 check_colorcolumn(curwin);
9046# endif
9047#endif
9048 }
9049
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 /*
9051 * Check the bounds for numeric options here
9052 */
9053 if (Rows < min_rows() && full_screen)
9054 {
9055 if (errbuf != NULL)
9056 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009057 vim_snprintf((char *)errbuf, errbuflen,
9058 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059 errmsg = errbuf;
9060 }
9061 Rows = min_rows();
9062 }
9063 if (Columns < MIN_COLUMNS && full_screen)
9064 {
9065 if (errbuf != NULL)
9066 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009067 vim_snprintf((char *)errbuf, errbuflen,
9068 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009069 errmsg = errbuf;
9070 }
9071 Columns = MIN_COLUMNS;
9072 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009073 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075 /*
9076 * If the screen (shell) height has been changed, assume it is the
9077 * physical screenheight.
9078 */
9079 if (old_Rows != Rows || old_Columns != Columns)
9080 {
9081 /* Changing the screen size is not allowed while updating the screen. */
9082 if (updating_screen)
9083 *pp = old_value;
9084 else if (full_screen
9085#ifdef FEAT_GUI
9086 && !gui.starting
9087#endif
9088 )
9089 set_shellsize((int)Columns, (int)Rows, TRUE);
9090 else
9091 {
9092 /* Postpone the resizing; check the size and cmdline position for
9093 * messages. */
9094 check_shellsize();
9095 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9096 cmdline_row = Rows - p_ch;
9097 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009098 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009099 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100 }
9101
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102 if (curbuf->b_p_ts <= 0)
9103 {
9104 errmsg = e_positive;
9105 curbuf->b_p_ts = 8;
9106 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009107 if (p_tm < 0)
9108 {
9109 errmsg = e_positive;
9110 p_tm = 0;
9111 }
9112 if ((curwin->w_p_scr <= 0
9113 || (curwin->w_p_scr > curwin->w_height
9114 && curwin->w_height > 0))
9115 && full_screen)
9116 {
9117 if (pp == &(curwin->w_p_scr))
9118 {
9119 if (curwin->w_p_scr != 0)
9120 errmsg = e_scroll;
9121 win_comp_scroll(curwin);
9122 }
9123 /* If 'scroll' became invalid because of a side effect silently adjust
9124 * it. */
9125 else if (curwin->w_p_scr <= 0)
9126 curwin->w_p_scr = 1;
9127 else /* curwin->w_p_scr > curwin->w_height */
9128 curwin->w_p_scr = curwin->w_height;
9129 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009130 if (p_hi < 0)
9131 {
9132 errmsg = e_positive;
9133 p_hi = 0;
9134 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009135 else if (p_hi > 10000)
9136 {
9137 errmsg = e_invarg;
9138 p_hi = 10000;
9139 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009140 if (p_re < 0 || p_re > 2)
9141 {
9142 errmsg = e_invarg;
9143 p_re = 0;
9144 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009145 if (p_report < 0)
9146 {
9147 errmsg = e_positive;
9148 p_report = 1;
9149 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009150 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009151 {
9152 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9153 p_sj = Rows / 2;
9154 else
9155 {
9156 errmsg = e_scroll;
9157 p_sj = 1;
9158 }
9159 }
9160 if (p_so < 0 && full_screen)
9161 {
9162 errmsg = e_scroll;
9163 p_so = 0;
9164 }
9165 if (p_siso < 0 && full_screen)
9166 {
9167 errmsg = e_positive;
9168 p_siso = 0;
9169 }
9170#ifdef FEAT_CMDWIN
9171 if (p_cwh < 1)
9172 {
9173 errmsg = e_positive;
9174 p_cwh = 1;
9175 }
9176#endif
9177 if (p_ut < 0)
9178 {
9179 errmsg = e_positive;
9180 p_ut = 2000;
9181 }
9182 if (p_ss < 0)
9183 {
9184 errmsg = e_positive;
9185 p_ss = 0;
9186 }
9187
9188 /* May set global value for local option. */
9189 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9190 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9191
9192 options[opt_idx].flags |= P_WAS_SET;
9193
Bram Moolenaar53744302015-07-17 17:38:22 +02009194#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9195 if (!starting && errmsg == NULL)
9196 {
9197 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009198 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9199 vim_snprintf((char *)buf_new, 10, "%ld", value);
9200 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009201 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9202 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9203 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9204 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9205 reset_v_option_vars();
9206 }
9207#endif
9208
Bram Moolenaar071d4272004-06-13 20:20:40 +00009209 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009210 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009211 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009212 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 check_redraw(options[opt_idx].flags);
9214
9215 return errmsg;
9216}
9217
9218/*
9219 * Called after an option changed: check if something needs to be redrawn.
9220 */
9221 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009222check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009223{
9224 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009225 int doclear = (flags & P_RCLR) == P_RCLR;
9226 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227
9228#ifdef FEAT_WINDOWS
9229 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9230 status_redraw_all();
9231#endif
9232
9233 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9234 changed_window_setting();
9235 if (flags & P_RBUF)
9236 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009237 if (flags & P_RWINONLY)
9238 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009239 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009240 redraw_all_later(CLEAR);
9241 else if (all)
9242 redraw_all_later(NOT_VALID);
9243}
9244
9245/*
9246 * Find index for option 'arg'.
9247 * Return -1 if not found.
9248 */
9249 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009250findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251{
9252 int opt_idx;
9253 char *s, *p;
9254 static short quick_tab[27] = {0, 0}; /* quick access table */
9255 int is_term_opt;
9256
9257 /*
9258 * For first call: Initialize the quick-access table.
9259 * It contains the index for the first option that starts with a certain
9260 * letter. There are 26 letters, plus the first "t_" option.
9261 */
9262 if (quick_tab[1] == 0)
9263 {
9264 p = options[0].fullname;
9265 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9266 {
9267 if (s[0] != p[0])
9268 {
9269 if (s[0] == 't' && s[1] == '_')
9270 quick_tab[26] = opt_idx;
9271 else
9272 quick_tab[CharOrdLow(s[0])] = opt_idx;
9273 }
9274 p = s;
9275 }
9276 }
9277
9278 /*
9279 * Check for name starting with an illegal character.
9280 */
9281#ifdef EBCDIC
9282 if (!islower(arg[0]))
9283#else
9284 if (arg[0] < 'a' || arg[0] > 'z')
9285#endif
9286 return -1;
9287
9288 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9289 if (is_term_opt)
9290 opt_idx = quick_tab[26];
9291 else
9292 opt_idx = quick_tab[CharOrdLow(arg[0])];
9293 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9294 {
9295 if (STRCMP(arg, s) == 0) /* match full name */
9296 break;
9297 }
9298 if (s == NULL && !is_term_opt)
9299 {
9300 opt_idx = quick_tab[CharOrdLow(arg[0])];
9301 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9302 {
9303 s = options[opt_idx].shortname;
9304 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9305 break;
9306 s = NULL;
9307 }
9308 }
9309 if (s == NULL)
9310 opt_idx = -1;
9311 return opt_idx;
9312}
9313
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009314#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009315/*
9316 * Get the value for an option.
9317 *
9318 * Returns:
9319 * Number or Toggle option: 1, *numval gets value.
9320 * String option: 0, *stringval gets allocated string.
9321 * Hidden Number or Toggle option: -1.
9322 * hidden String option: -2.
9323 * unknown option: -3.
9324 */
9325 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009326get_option_value(
9327 char_u *name,
9328 long *numval,
9329 char_u **stringval, /* NULL when only checking existence */
9330 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331{
9332 int opt_idx;
9333 char_u *varp;
9334
9335 opt_idx = findoption(name);
9336 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009337 {
9338 int key;
9339
9340 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9341 && (key = find_key_option(name)) != 0)
9342 {
9343 char_u key_name[2];
9344 char_u *p;
9345
9346 if (key < 0)
9347 {
9348 key_name[0] = KEY2TERMCAP0(key);
9349 key_name[1] = KEY2TERMCAP1(key);
9350 }
9351 else
9352 {
9353 key_name[0] = KS_KEY;
9354 key_name[1] = (key & 0xff);
9355 }
9356 p = find_termcode(key_name);
9357 if (p != NULL)
9358 {
9359 if (stringval != NULL)
9360 *stringval = vim_strsave(p);
9361 return 0;
9362 }
9363 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009365 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009366
9367 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9368
9369 if (options[opt_idx].flags & P_STRING)
9370 {
9371 if (varp == NULL) /* hidden option */
9372 return -2;
9373 if (stringval != NULL)
9374 {
9375#ifdef FEAT_CRYPT
9376 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009377 if ((char_u **)varp == &curbuf->b_p_key
9378 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379 *stringval = vim_strsave((char_u *)"*****");
9380 else
9381#endif
9382 *stringval = vim_strsave(*(char_u **)(varp));
9383 }
9384 return 0;
9385 }
9386
9387 if (varp == NULL) /* hidden option */
9388 return -1;
9389 if (options[opt_idx].flags & P_NUM)
9390 *numval = *(long *)varp;
9391 else
9392 {
9393 /* Special case: 'modified' is b_changed, but we also want to consider
9394 * it set when 'ff' or 'fenc' changed. */
9395 if ((int *)varp == &curbuf->b_changed)
9396 *numval = curbufIsChanged();
9397 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009398 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009399 }
9400 return 1;
9401}
9402#endif
9403
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009404#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009405/*
9406 * Returns the option attributes and its value. Unlike the above function it
9407 * will return either global value or local value of the option depending on
9408 * what was requested, but it will never return global value if it was
9409 * requested to return local one and vice versa. Neither it will return
9410 * buffer-local value if it was requested to return window-local one.
9411 *
9412 * Pretends that option is absent if it is not present in the requested scope
9413 * (i.e. has no global, window-local or buffer-local value depending on
9414 * opt_type). Uses
9415 *
9416 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009417 * 0 hidden or unknown option, also option that does not have requested
9418 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009419 * see SOPT_* in vim.h for other flags
9420 *
9421 * Possible opt_type values: see SREQ_* in vim.h
9422 */
9423 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009424get_option_value_strict(
9425 char_u *name,
9426 long *numval,
9427 char_u **stringval, /* NULL when only obtaining attributes */
9428 int opt_type,
9429 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009430{
9431 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009432 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009433 struct vimoption *p;
9434 int r = 0;
9435
9436 opt_idx = findoption(name);
9437 if (opt_idx < 0)
9438 return 0;
9439
9440 p = &(options[opt_idx]);
9441
9442 /* Hidden option */
9443 if (p->var == NULL)
9444 return 0;
9445
9446 if (p->flags & P_BOOL)
9447 r |= SOPT_BOOL;
9448 else if (p->flags & P_NUM)
9449 r |= SOPT_NUM;
9450 else if (p->flags & P_STRING)
9451 r |= SOPT_STRING;
9452
9453 if (p->indir == PV_NONE)
9454 {
9455 if (opt_type == SREQ_GLOBAL)
9456 r |= SOPT_GLOBAL;
9457 else
9458 return 0; /* Did not request global-only option */
9459 }
9460 else
9461 {
9462 if (p->indir & PV_BOTH)
9463 r |= SOPT_GLOBAL;
9464 else if (opt_type == SREQ_GLOBAL)
9465 return 0; /* Requested global option */
9466
9467 if (p->indir & PV_WIN)
9468 {
9469 if (opt_type == SREQ_BUF)
9470 return 0; /* Did not request window-local option */
9471 else
9472 r |= SOPT_WIN;
9473 }
9474 else if (p->indir & PV_BUF)
9475 {
9476 if (opt_type == SREQ_WIN)
9477 return 0; /* Did not request buffer-local option */
9478 else
9479 r |= SOPT_BUF;
9480 }
9481 }
9482
9483 if (stringval == NULL)
9484 return r;
9485
9486 if (opt_type == SREQ_GLOBAL)
9487 varp = p->var;
9488 else
9489 {
9490 if (opt_type == SREQ_BUF)
9491 {
9492 /* Special case: 'modified' is b_changed, but we also want to
9493 * consider it set when 'ff' or 'fenc' changed. */
9494 if (p->indir == PV_MOD)
9495 {
9496 *numval = bufIsChanged((buf_T *) from);
9497 varp = NULL;
9498 }
9499#ifdef FEAT_CRYPT
9500 else if (p->indir == PV_KEY)
9501 {
9502 /* never return the value of the crypt key */
9503 *stringval = NULL;
9504 varp = NULL;
9505 }
9506#endif
9507 else
9508 {
9509 aco_save_T aco;
9510 aucmd_prepbuf(&aco, (buf_T *) from);
9511 varp = get_varp(p);
9512 aucmd_restbuf(&aco);
9513 }
9514 }
9515 else if (opt_type == SREQ_WIN)
9516 {
9517 win_T *save_curwin;
9518 save_curwin = curwin;
9519 curwin = (win_T *) from;
9520 curbuf = curwin->w_buffer;
9521 varp = get_varp(p);
9522 curwin = save_curwin;
9523 curbuf = curwin->w_buffer;
9524 }
9525 if (varp == p->var)
9526 return (r | SOPT_UNSET);
9527 }
9528
9529 if (varp != NULL)
9530 {
9531 if (p->flags & P_STRING)
9532 *stringval = vim_strsave(*(char_u **)(varp));
9533 else if (p->flags & P_NUM)
9534 *numval = *(long *) varp;
9535 else
9536 *numval = *(int *)varp;
9537 }
9538
9539 return r;
9540}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009541
9542/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009543 * Iterate over options. First argument is a pointer to a pointer to a
9544 * structure inside options[] array, second is option type like in the above
9545 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009546 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009547 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009548 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009549 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009550 * first argument to NULL.
9551 *
9552 * Returns full option name for current option on each call.
9553 */
9554 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009555option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009556{
9557 struct vimoption *ret = NULL;
9558 do
9559 {
9560 if (*option == NULL)
9561 *option = (void *) options;
9562 else if (((struct vimoption *) (*option))->fullname == NULL)
9563 {
9564 *option = NULL;
9565 return NULL;
9566 }
9567 else
9568 *option = (void *) (((struct vimoption *) (*option)) + 1);
9569
9570 ret = ((struct vimoption *) (*option));
9571
9572 /* Hidden option */
9573 if (ret->var == NULL)
9574 {
9575 ret = NULL;
9576 continue;
9577 }
9578
9579 switch (opt_type)
9580 {
9581 case SREQ_GLOBAL:
9582 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9583 ret = NULL;
9584 break;
9585 case SREQ_BUF:
9586 if (!(ret->indir & PV_BUF))
9587 ret = NULL;
9588 break;
9589 case SREQ_WIN:
9590 if (!(ret->indir & PV_WIN))
9591 ret = NULL;
9592 break;
9593 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009594 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009595 return NULL;
9596 }
9597 }
9598 while (ret == NULL);
9599
9600 return (char_u *)ret->fullname;
9601}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009602#endif
9603
Bram Moolenaar071d4272004-06-13 20:20:40 +00009604/*
9605 * Set the value of option "name".
9606 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009607 *
9608 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009609 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009610 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009611set_option_value(
9612 char_u *name,
9613 long number,
9614 char_u *string,
9615 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009616{
9617 int opt_idx;
9618 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009619 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620
9621 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009622 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009623 {
9624 int key;
9625
9626 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9627 && (key = find_key_option(name)) != 0)
9628 {
9629 char_u key_name[2];
9630
9631 if (key < 0)
9632 {
9633 key_name[0] = KEY2TERMCAP0(key);
9634 key_name[1] = KEY2TERMCAP1(key);
9635 }
9636 else
9637 {
9638 key_name[0] = KS_KEY;
9639 key_name[1] = (key & 0xff);
9640 }
9641 add_termcode(key_name, string, FALSE);
9642 if (full_screen)
9643 ttest(FALSE);
9644 redraw_all_later(CLEAR);
9645 return NULL;
9646 }
9647
Bram Moolenaar071d4272004-06-13 20:20:40 +00009648 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009650 else
9651 {
9652 flags = options[opt_idx].flags;
9653#ifdef HAVE_SANDBOX
9654 /* Disallow changing some options in the sandbox */
9655 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009656 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009658 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009659 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009661 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009662 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009663 else
9664 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009665 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009666 if (varp != NULL) /* hidden option is not changed */
9667 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009668 if (number == 0 && string != NULL)
9669 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009670 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009671
9672 /* Either we are given a string or we are setting option
9673 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009674 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009675 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009676 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009677 {
9678 /* There's another character after zeros or the string
9679 * is empty. In both cases, we are trying to set a
9680 * num option using a string. */
9681 EMSG3(_("E521: Number required: &%s = '%s'"),
9682 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009683 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009684
9685 }
9686 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009687 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009688 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009689 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009691 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009692 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009693 }
9694 }
9695 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009696 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009697}
9698
9699/*
9700 * Get the terminal code for a terminal option.
9701 * Returns NULL when not found.
9702 */
9703 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009704get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009705{
9706 int opt_idx;
9707 char_u *varp;
9708
9709 if (tname[0] != 't' || tname[1] != '_' ||
9710 tname[2] == NUL || tname[3] == NUL)
9711 return NULL;
9712 if ((opt_idx = findoption(tname)) >= 0)
9713 {
9714 varp = get_varp(&(options[opt_idx]));
9715 if (varp != NULL)
9716 varp = *(char_u **)(varp);
9717 return varp;
9718 }
9719 return find_termcode(tname + 2);
9720}
9721
9722 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009723get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009724{
9725 int i;
9726
9727 i = findoption((char_u *)"hl");
9728 if (i >= 0)
9729 return options[i].def_val[VI_DEFAULT];
9730 return (char_u *)NULL;
9731}
9732
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009733#if defined(FEAT_MBYTE) || defined(PROTO)
9734 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009735get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009736{
9737 int i;
9738
9739 i = findoption((char_u *)"enc");
9740 if (i >= 0)
9741 return options[i].def_val[VI_DEFAULT];
9742 return (char_u *)NULL;
9743}
9744#endif
9745
Bram Moolenaar071d4272004-06-13 20:20:40 +00009746/*
9747 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9748 */
9749 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009750find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751{
9752 int key;
9753 int modifiers;
9754
9755 /*
9756 * Don't use get_special_key_code() for t_xx, we don't want it to call
9757 * add_termcap_entry().
9758 */
9759 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9760 key = TERMCAP2KEY(arg[2], arg[3]);
9761 else
9762 {
9763 --arg; /* put arg at the '<' */
9764 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009765 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009766 if (modifiers) /* can't handle modifiers here */
9767 key = 0;
9768 }
9769 return key;
9770}
9771
9772/*
9773 * if 'all' == 0: show changed options
9774 * if 'all' == 1: show all normal options
9775 * if 'all' == 2: show all terminal options
9776 */
9777 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009778showoptions(
9779 int all,
9780 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009781{
9782 struct vimoption *p;
9783 int col;
9784 int isterm;
9785 char_u *varp;
9786 struct vimoption **items;
9787 int item_count;
9788 int run;
9789 int row, rows;
9790 int cols;
9791 int i;
9792 int len;
9793
9794#define INC 20
9795#define GAP 3
9796
9797 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9798 PARAM_COUNT));
9799 if (items == NULL)
9800 return;
9801
9802 /* Highlight title */
9803 if (all == 2)
9804 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9805 else if (opt_flags & OPT_GLOBAL)
9806 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9807 else if (opt_flags & OPT_LOCAL)
9808 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9809 else
9810 MSG_PUTS_TITLE(_("\n--- Options ---"));
9811
9812 /*
9813 * do the loop two times:
9814 * 1. display the short items
9815 * 2. display the long items (only strings and numbers)
9816 */
9817 for (run = 1; run <= 2 && !got_int; ++run)
9818 {
9819 /*
9820 * collect the items in items[]
9821 */
9822 item_count = 0;
9823 for (p = &options[0]; p->fullname != NULL; p++)
9824 {
9825 varp = NULL;
9826 isterm = istermoption(p);
9827 if (opt_flags != 0)
9828 {
9829 if (p->indir != PV_NONE && !isterm)
9830 varp = get_varp_scope(p, opt_flags);
9831 }
9832 else
9833 varp = get_varp(p);
9834 if (varp != NULL
9835 && ((all == 2 && isterm)
9836 || (all == 1 && !isterm)
9837 || (all == 0 && !optval_default(p, varp))))
9838 {
9839 if (p->flags & P_BOOL)
9840 len = 1; /* a toggle option fits always */
9841 else
9842 {
9843 option_value2string(p, opt_flags);
9844 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9845 }
9846 if ((len <= INC - GAP && run == 1) ||
9847 (len > INC - GAP && run == 2))
9848 items[item_count++] = p;
9849 }
9850 }
9851
9852 /*
9853 * display the items
9854 */
9855 if (run == 1)
9856 {
9857 cols = (Columns + GAP - 3) / INC;
9858 if (cols == 0)
9859 cols = 1;
9860 rows = (item_count + cols - 1) / cols;
9861 }
9862 else /* run == 2 */
9863 rows = item_count;
9864 for (row = 0; row < rows && !got_int; ++row)
9865 {
9866 msg_putchar('\n'); /* go to next line */
9867 if (got_int) /* 'q' typed in more */
9868 break;
9869 col = 0;
9870 for (i = row; i < item_count; i += rows)
9871 {
9872 msg_col = col; /* make columns */
9873 showoneopt(items[i], opt_flags);
9874 col += INC;
9875 }
9876 out_flush();
9877 ui_breakcheck();
9878 }
9879 }
9880 vim_free(items);
9881}
9882
9883/*
9884 * Return TRUE if option "p" has its default value.
9885 */
9886 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009887optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009888{
9889 int dvi;
9890
9891 if (varp == NULL)
9892 return TRUE; /* hidden option is always at default */
9893 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9894 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009895 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009896 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009897 /* the cast to long is required for Manx C, long_i is
9898 * needed for MSVC */
9899 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009900 /* P_STRING */
9901 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9902}
9903
9904/*
9905 * showoneopt: show the value of one option
9906 * must not be called with a hidden option!
9907 */
9908 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009909showoneopt(
9910 struct vimoption *p,
9911 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009913 char_u *varp;
9914 int save_silent = silent_mode;
9915
9916 silent_mode = FALSE;
9917 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009918
9919 varp = get_varp_scope(p, opt_flags);
9920
9921 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9922 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9923 ? !curbufIsChanged() : !*(int *)varp))
9924 MSG_PUTS("no");
9925 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9926 MSG_PUTS("--");
9927 else
9928 MSG_PUTS(" ");
9929 MSG_PUTS(p->fullname);
9930 if (!(p->flags & P_BOOL))
9931 {
9932 msg_putchar('=');
9933 /* put value string in NameBuff */
9934 option_value2string(p, opt_flags);
9935 msg_outtrans(NameBuff);
9936 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009937
9938 silent_mode = save_silent;
9939 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940}
9941
9942/*
9943 * Write modified options as ":set" commands to a file.
9944 *
9945 * There are three values for "opt_flags":
9946 * OPT_GLOBAL: Write global option values and fresh values of
9947 * buffer-local options (used for start of a session
9948 * file).
9949 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9950 * curwin (used for a vimrc file).
9951 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9952 * and local values for window-local options of
9953 * curwin. Local values are also written when at the
9954 * default value, because a modeline or autocommand
9955 * may have set them when doing ":edit file" and the
9956 * user has set them back at the default or fresh
9957 * value.
9958 * When "local_only" is TRUE, don't write fresh
9959 * values, only local values (for ":mkview").
9960 * (fresh value = value used for a new buffer or window for a local option).
9961 *
9962 * Return FAIL on error, OK otherwise.
9963 */
9964 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009965makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966{
9967 struct vimoption *p;
9968 char_u *varp; /* currently used value */
9969 char_u *varp_fresh; /* local value */
9970 char_u *varp_local = NULL; /* fresh value */
9971 char *cmd;
9972 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009973 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974
9975 /*
9976 * The options that don't have a default (terminal name, columns, lines)
9977 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009978 * Do the loop over "options[]" twice: once for options with the
9979 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009980 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009981 for (pri = 1; pri >= 0; --pri)
9982 {
9983 for (p = &options[0]; !istermoption(p); p++)
9984 if (!(p->flags & P_NO_MKRC)
9985 && !istermoption(p)
9986 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987 {
9988 /* skip global option when only doing locals */
9989 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9990 continue;
9991
9992 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9993 * file, they are always buffer-specific. */
9994 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9995 continue;
9996
9997 /* Global values are only written when not at the default value. */
9998 varp = get_varp_scope(p, opt_flags);
9999 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10000 continue;
10001
10002 round = 2;
10003 if (p->indir != PV_NONE)
10004 {
10005 if (p->var == VAR_WIN)
10006 {
10007 /* skip window-local option when only doing globals */
10008 if (!(opt_flags & OPT_LOCAL))
10009 continue;
10010 /* When fresh value of window-local option is not at the
10011 * default, need to write it too. */
10012 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10013 {
10014 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10015 if (!optval_default(p, varp_fresh))
10016 {
10017 round = 1;
10018 varp_local = varp;
10019 varp = varp_fresh;
10020 }
10021 }
10022 }
10023 }
10024
10025 /* Round 1: fresh value for window-local options.
10026 * Round 2: other values */
10027 for ( ; round <= 2; varp = varp_local, ++round)
10028 {
10029 if (round == 1 || (opt_flags & OPT_GLOBAL))
10030 cmd = "set";
10031 else
10032 cmd = "setlocal";
10033
10034 if (p->flags & P_BOOL)
10035 {
10036 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10037 return FAIL;
10038 }
10039 else if (p->flags & P_NUM)
10040 {
10041 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10042 return FAIL;
10043 }
10044 else /* P_STRING */
10045 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010046#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10047 int do_endif = FALSE;
10048
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049 /* Don't set 'syntax' and 'filetype' again if the value is
10050 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010051 if (
10052# if defined(FEAT_SYN_HL)
10053 p->indir == PV_SYN
10054# if defined(FEAT_AUTOCMD)
10055 ||
10056# endif
10057# endif
10058# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010059 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010060# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010061 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062 {
10063 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10064 *(char_u **)(varp)) < 0
10065 || put_eol(fd) < 0)
10066 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010067 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010068 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010069#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10071 (p->flags & P_EXPAND) != 0) == FAIL)
10072 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010073#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10074 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010075 {
10076 if (put_line(fd, "endif") == FAIL)
10077 return FAIL;
10078 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010080 }
10081 }
10082 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010083 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010084 return OK;
10085}
10086
10087#if defined(FEAT_FOLDING) || defined(PROTO)
10088/*
10089 * Generate set commands for the local fold options only. Used when
10090 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10091 */
10092 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010093makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010094{
10095 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10096# ifdef FEAT_EVAL
10097 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10098 == FAIL
10099# endif
10100 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10101 == FAIL
10102 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10103 == FAIL
10104 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10105 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10106 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10107 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10108 )
10109 return FAIL;
10110
10111 return OK;
10112}
10113#endif
10114
10115 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010116put_setstring(
10117 FILE *fd,
10118 char *cmd,
10119 char *name,
10120 char_u **valuep,
10121 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010122{
10123 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010124 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125
10126 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10127 return FAIL;
10128 if (*valuep != NULL)
10129 {
10130 /* Output 'pastetoggle' as key names. For other
10131 * options some characters have to be escaped with
10132 * CTRL-V or backslash */
10133 if (valuep == &p_pt)
10134 {
10135 s = *valuep;
10136 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010137 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138 return FAIL;
10139 }
10140 else if (expand)
10141 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010142 buf = alloc(MAXPATHL);
10143 if (buf == NULL)
10144 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10146 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010147 {
10148 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010150 }
10151 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152 }
10153 else if (put_escstr(fd, *valuep, 2) == FAIL)
10154 return FAIL;
10155 }
10156 if (put_eol(fd) < 0)
10157 return FAIL;
10158 return OK;
10159}
10160
10161 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010162put_setnum(
10163 FILE *fd,
10164 char *cmd,
10165 char *name,
10166 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167{
10168 long wc;
10169
10170 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10171 return FAIL;
10172 if (wc_use_keyname((char_u *)valuep, &wc))
10173 {
10174 /* print 'wildchar' and 'wildcharm' as a key name */
10175 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10176 return FAIL;
10177 }
10178 else if (fprintf(fd, "%ld", *valuep) < 0)
10179 return FAIL;
10180 if (put_eol(fd) < 0)
10181 return FAIL;
10182 return OK;
10183}
10184
10185 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010186put_setbool(
10187 FILE *fd,
10188 char *cmd,
10189 char *name,
10190 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191{
Bram Moolenaar893de922007-10-02 18:40:57 +000010192 if (value < 0) /* global/local option using global value */
10193 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10195 || put_eol(fd) < 0)
10196 return FAIL;
10197 return OK;
10198}
10199
10200/*
10201 * Clear all the terminal options.
10202 * If the option has been allocated, free the memory.
10203 * Terminal options are never hidden or indirect.
10204 */
10205 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010206clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208 /*
10209 * Reset a few things before clearing the old options. This may cause
10210 * outputting a few things that the terminal doesn't understand, but the
10211 * screen will be cleared later, so this is OK.
10212 */
10213#ifdef FEAT_MOUSE_TTY
10214 mch_setmouse(FALSE); /* switch mouse off */
10215#endif
10216#ifdef FEAT_TITLE
10217 mch_restore_title(3); /* restore window titles */
10218#endif
10219#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10220 /* When starting the GUI close the display opened for the clipboard.
10221 * After restoring the title, because that will need the display. */
10222 if (gui.starting)
10223 clear_xterm_clip();
10224#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010225 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010227 free_termoptions();
10228}
10229
10230 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010231free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010232{
10233 struct vimoption *p;
10234
Bram Moolenaar071d4272004-06-13 20:20:40 +000010235 for (p = &options[0]; p->fullname != NULL; p++)
10236 if (istermoption(p))
10237 {
10238 if (p->flags & P_ALLOCED)
10239 free_string_option(*(char_u **)(p->var));
10240 if (p->flags & P_DEF_ALLOCED)
10241 free_string_option(p->def_val[VI_DEFAULT]);
10242 *(char_u **)(p->var) = empty_option;
10243 p->def_val[VI_DEFAULT] = empty_option;
10244 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10245 }
10246 clear_termcodes();
10247}
10248
10249/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010250 * Free the string for one term option, if it was allocated.
10251 * Set the string to empty_option and clear allocated flag.
10252 * "var" points to the option value.
10253 */
10254 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010255free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010256{
10257 struct vimoption *p;
10258
10259 for (p = &options[0]; p->fullname != NULL; p++)
10260 if (p->var == var)
10261 {
10262 if (p->flags & P_ALLOCED)
10263 free_string_option(*(char_u **)(p->var));
10264 *(char_u **)(p->var) = empty_option;
10265 p->flags &= ~P_ALLOCED;
10266 break;
10267 }
10268}
10269
10270/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271 * Set the terminal option defaults to the current value.
10272 * Used after setting the terminal name.
10273 */
10274 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010275set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276{
10277 struct vimoption *p;
10278
10279 for (p = &options[0]; p->fullname != NULL; p++)
10280 {
10281 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10282 {
10283 if (p->flags & P_DEF_ALLOCED)
10284 {
10285 free_string_option(p->def_val[VI_DEFAULT]);
10286 p->flags &= ~P_DEF_ALLOCED;
10287 }
10288 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10289 if (p->flags & P_ALLOCED)
10290 {
10291 p->flags |= P_DEF_ALLOCED;
10292 p->flags &= ~P_ALLOCED; /* don't free the value now */
10293 }
10294 }
10295 }
10296}
10297
10298/*
10299 * return TRUE if 'p' starts with 't_'
10300 */
10301 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010302istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303{
10304 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10305}
10306
10307/*
10308 * Compute columns for ruler and shown command. 'sc_col' is also used to
10309 * decide what the maximum length of a message on the status line can be.
10310 * If there is a status line for the last window, 'sc_col' is independent
10311 * of 'ru_col'.
10312 */
10313
10314#define COL_RULER 17 /* columns needed by standard ruler */
10315
10316 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010317comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318{
10319#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010320 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321
10322 sc_col = 0;
10323 ru_col = 0;
10324 if (p_ru)
10325 {
10326#ifdef FEAT_STL_OPT
10327 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10328#else
10329 ru_col = COL_RULER + 1;
10330#endif
10331 /* no last status line, adjust sc_col */
10332 if (!last_has_status)
10333 sc_col = ru_col;
10334 }
10335 if (p_sc)
10336 {
10337 sc_col += SHOWCMD_COLS;
10338 if (!p_ru || last_has_status) /* no need for separating space */
10339 ++sc_col;
10340 }
10341 sc_col = Columns - sc_col;
10342 ru_col = Columns - ru_col;
10343 if (sc_col <= 0) /* screen too narrow, will become a mess */
10344 sc_col = 1;
10345 if (ru_col <= 0)
10346 ru_col = 1;
10347#else
10348 sc_col = Columns;
10349 ru_col = Columns;
10350#endif
10351}
10352
10353/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010354 * Unset local option value, similar to ":set opt<".
10355 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010356 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010357unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010358{
10359 struct vimoption *p;
10360 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010361 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010362
10363 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010364 if (opt_idx < 0)
10365 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010366 p = &(options[opt_idx]);
10367
10368 switch ((int)p->indir)
10369 {
10370 /* global option with local value: use local value if it's been set */
10371 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010372 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010373 break;
10374 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010375 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010376 break;
10377 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010378 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010379 break;
10380 case PV_AR:
10381 buf->b_p_ar = -1;
10382 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010383 case PV_BKC:
10384 clear_string_option(&buf->b_p_bkc);
10385 buf->b_bkc_flags = 0;
10386 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010387 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010388 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010389 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010390 case PV_TC:
10391 clear_string_option(&buf->b_p_tc);
10392 buf->b_tc_flags = 0;
10393 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010394#ifdef FEAT_FIND_ID
10395 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010396 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010397 break;
10398 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010399 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010400 break;
10401#endif
10402#ifdef FEAT_INS_EXPAND
10403 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010404 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010405 break;
10406 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010407 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010408 break;
10409#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010410 case PV_FP:
10411 clear_string_option(&buf->b_p_fp);
10412 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413#ifdef FEAT_QUICKFIX
10414 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010415 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010416 break;
10417 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010418 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010419 break;
10420 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010421 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010422 break;
10423#endif
10424#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10425 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010426 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010427 break;
10428#endif
10429#if defined(FEAT_CRYPT)
10430 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010431 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010432 break;
10433#endif
10434#ifdef FEAT_STL_OPT
10435 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010436 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010437 break;
10438#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010439 case PV_UL:
10440 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10441 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010442#ifdef FEAT_LISP
10443 case PV_LW:
10444 clear_string_option(&buf->b_p_lw);
10445 break;
10446#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010447#ifdef FEAT_MBYTE
10448 case PV_MENC:
10449 clear_string_option(&buf->b_p_menc);
10450 break;
10451#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 }
10453}
10454
10455/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010456 * Get pointer to option variable, depending on local or global scope.
10457 */
10458 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010459get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460{
10461 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10462 {
10463 if (p->var == VAR_WIN)
10464 return (char_u *)GLOBAL_WO(get_varp(p));
10465 return p->var;
10466 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010467 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010468 {
10469 switch ((int)p->indir)
10470 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010471 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010473 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10474 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10475 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010477 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10478 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10479 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010480 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010481 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010482 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010484 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10485 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486#endif
10487#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010488 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10489 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010491#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10492 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10493#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010494#if defined(FEAT_CRYPT)
10495 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10496#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010497#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010498 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010499#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010500 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010501#ifdef FEAT_LISP
10502 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10503#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010504 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010505#ifdef FEAT_MBYTE
10506 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10507#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508 }
10509 return NULL; /* "cannot happen" */
10510 }
10511 return get_varp(p);
10512}
10513
10514/*
10515 * Get pointer to option variable.
10516 */
10517 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010518get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519{
10520 /* hidden option, always return NULL */
10521 if (p->var == NULL)
10522 return NULL;
10523
10524 switch ((int)p->indir)
10525 {
10526 case PV_NONE: return p->var;
10527
10528 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010529 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010531 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010533 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010535 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010537 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010539 case PV_TC: return *curbuf->b_p_tc != NUL
10540 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010541 case PV_BKC: return *curbuf->b_p_bkc != NUL
10542 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010544 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010546 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10548#endif
10549#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010550 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010552 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10554#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010555 case PV_FP: return *curbuf->b_p_fp != NUL
10556 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010557#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010558 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010560 case PV_GP: return *curbuf->b_p_gp != NUL
10561 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10562 case PV_MP: return *curbuf->b_p_mp != NUL
10563 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010565#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10566 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10567 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10568#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010569#if defined(FEAT_CRYPT)
10570 case PV_CM: return *curbuf->b_p_cm != NUL
10571 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10572#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010573#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010574 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010575 ? (char_u *)&(curwin->w_p_stl) : p->var;
10576#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010577 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10578 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010579#ifdef FEAT_LISP
10580 case PV_LW: return *curbuf->b_p_lw != NUL
10581 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10582#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010583#ifdef FEAT_MBYTE
10584 case PV_MENC: return *curbuf->b_p_menc != NUL
10585 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587
10588#ifdef FEAT_ARABIC
10589 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10590#endif
10591 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010592#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010593 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10594#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010595#ifdef FEAT_SYN_HL
10596 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10597 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010598 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600#ifdef FEAT_DIFF
10601 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10602#endif
10603#ifdef FEAT_FOLDING
10604 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10605 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10606 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10607 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10608 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10609 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10610 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10611# ifdef FEAT_EVAL
10612 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10613 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10614# endif
10615 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10616#endif
10617 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010618 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010619#ifdef FEAT_LINEBREAK
10620 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10621#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010622#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010623 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010624 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10625#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10627 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10628#endif
10629#ifdef FEAT_RIGHTLEFT
10630 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10631 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10632#endif
10633 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10634 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10635#ifdef FEAT_LINEBREAK
10636 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010637 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10638 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639#endif
10640#ifdef FEAT_SCROLLBIND
10641 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10642#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010643#ifdef FEAT_CURSORBIND
10644 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10645#endif
10646#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010647 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10648 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010649#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010650
10651 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10652 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10653#ifdef FEAT_MBYTE
10654 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10655#endif
10656#if defined(FEAT_QUICKFIX)
10657 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10658 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10659#endif
10660 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10661 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10662#ifdef FEAT_CINDENT
10663 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10664 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10665 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10666#endif
10667#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10668 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10669#endif
10670#ifdef FEAT_COMMENTS
10671 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10672#endif
10673#ifdef FEAT_FOLDING
10674 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10675#endif
10676#ifdef FEAT_INS_EXPAND
10677 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10678#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010679#ifdef FEAT_COMPL_FUNC
10680 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010681 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010683 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010684 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10686#ifdef FEAT_MBYTE
10687 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10688#endif
10689 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10690#ifdef FEAT_AUTOCMD
10691 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10692#endif
10693 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010694 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010695 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10696 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10697 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10698 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10699#ifdef FEAT_FIND_ID
10700# ifdef FEAT_EVAL
10701 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10702# endif
10703#endif
10704#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10705 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10706 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10707#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010708#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010709 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711#ifdef FEAT_CRYPT
10712 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10713#endif
10714#ifdef FEAT_LISP
10715 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10716#endif
10717 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10718 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10719 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10720 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10721 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010723#ifdef FEAT_TEXTOBJ
10724 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10727#ifdef FEAT_SMARTINDENT
10728 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10729#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10732#ifdef FEAT_SEARCHPATH
10733 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10734#endif
10735 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10736#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010737 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010738 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10739#endif
10740#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010741 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10742 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10743 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744#endif
10745 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10746 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10747 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10748 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010749#ifdef FEAT_PERSISTENT_UNDO
10750 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10751#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10753#ifdef FEAT_KEYMAP
10754 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10755#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010756#ifdef FEAT_SIGNS
10757 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10758#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010759 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760 }
10761 /* always return a valid pointer to avoid a crash! */
10762 return (char_u *)&(curbuf->b_p_wm);
10763}
10764
10765/*
10766 * Get the value of 'equalprg', either the buffer-local one or the global one.
10767 */
10768 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010769get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770{
10771 if (*curbuf->b_p_ep == NUL)
10772 return p_ep;
10773 return curbuf->b_p_ep;
10774}
10775
10776#if defined(FEAT_WINDOWS) || defined(PROTO)
10777/*
10778 * Copy options from one window to another.
10779 * Used when splitting a window.
10780 */
10781 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010782win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783{
10784 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10785 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10786# ifdef FEAT_RIGHTLEFT
10787# ifdef FEAT_FKMAP
10788 /* Is this right? */
10789 wp_to->w_farsi = wp_from->w_farsi;
10790# endif
10791# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010792#if defined(FEAT_LINEBREAK)
10793 briopt_check(wp_to);
10794#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795}
10796#endif
10797
10798/*
10799 * Copy the options from one winopt_T to another.
10800 * Doesn't free the old option values in "to", use clear_winopt() for that.
10801 * The 'scroll' option is not copied, because it depends on the window height.
10802 * The 'previewwindow' option is reset, there can be only one preview window.
10803 */
10804 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010805copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806{
10807#ifdef FEAT_ARABIC
10808 to->wo_arab = from->wo_arab;
10809#endif
10810 to->wo_list = from->wo_list;
10811 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010812 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010813#ifdef FEAT_LINEBREAK
10814 to->wo_nuw = from->wo_nuw;
10815#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816#ifdef FEAT_RIGHTLEFT
10817 to->wo_rl = from->wo_rl;
10818 to->wo_rlc = vim_strsave(from->wo_rlc);
10819#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010820#ifdef FEAT_STL_OPT
10821 to->wo_stl = vim_strsave(from->wo_stl);
10822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010824#ifdef FEAT_DIFF
10825 to->wo_wrap_save = from->wo_wrap_save;
10826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827#ifdef FEAT_LINEBREAK
10828 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010829 to->wo_bri = from->wo_bri;
10830 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010831#endif
10832#ifdef FEAT_SCROLLBIND
10833 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010834 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010836#ifdef FEAT_CURSORBIND
10837 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010838 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010839#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010840#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010841 to->wo_spell = from->wo_spell;
10842#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010843#ifdef FEAT_SYN_HL
10844 to->wo_cuc = from->wo_cuc;
10845 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010846 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848#ifdef FEAT_DIFF
10849 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010850 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010852#ifdef FEAT_CONCEAL
10853 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010854 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010855#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856#ifdef FEAT_FOLDING
10857 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010858 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010860 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010861 to->wo_fdi = vim_strsave(from->wo_fdi);
10862 to->wo_fml = from->wo_fml;
10863 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010864 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010866 to->wo_fdm_save = from->wo_diff_saved
10867 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010868 to->wo_fdn = from->wo_fdn;
10869# ifdef FEAT_EVAL
10870 to->wo_fde = vim_strsave(from->wo_fde);
10871 to->wo_fdt = vim_strsave(from->wo_fdt);
10872# endif
10873 to->wo_fmr = vim_strsave(from->wo_fmr);
10874#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010875#ifdef FEAT_SIGNS
10876 to->wo_scl = vim_strsave(from->wo_scl);
10877#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010878 check_winopt(to); /* don't want NULL pointers */
10879}
10880
10881/*
10882 * Check string options in a window for a NULL value.
10883 */
10884 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010885check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010886{
10887 check_winopt(&win->w_onebuf_opt);
10888 check_winopt(&win->w_allbuf_opt);
10889}
10890
10891/*
10892 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10893 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010894 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010895check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896{
10897#ifdef FEAT_FOLDING
10898 check_string_option(&wop->wo_fdi);
10899 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010900 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901# ifdef FEAT_EVAL
10902 check_string_option(&wop->wo_fde);
10903 check_string_option(&wop->wo_fdt);
10904# endif
10905 check_string_option(&wop->wo_fmr);
10906#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010907#ifdef FEAT_SIGNS
10908 check_string_option(&wop->wo_scl);
10909#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010910#ifdef FEAT_RIGHTLEFT
10911 check_string_option(&wop->wo_rlc);
10912#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010913#ifdef FEAT_STL_OPT
10914 check_string_option(&wop->wo_stl);
10915#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010916#ifdef FEAT_SYN_HL
10917 check_string_option(&wop->wo_cc);
10918#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010919#ifdef FEAT_CONCEAL
10920 check_string_option(&wop->wo_cocu);
10921#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010922#ifdef FEAT_LINEBREAK
10923 check_string_option(&wop->wo_briopt);
10924#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010925}
10926
10927/*
10928 * Free the allocated memory inside a winopt_T.
10929 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010931clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932{
10933#ifdef FEAT_FOLDING
10934 clear_string_option(&wop->wo_fdi);
10935 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010936 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010937# ifdef FEAT_EVAL
10938 clear_string_option(&wop->wo_fde);
10939 clear_string_option(&wop->wo_fdt);
10940# endif
10941 clear_string_option(&wop->wo_fmr);
10942#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010943#ifdef FEAT_SIGNS
10944 clear_string_option(&wop->wo_scl);
10945#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010946#ifdef FEAT_LINEBREAK
10947 clear_string_option(&wop->wo_briopt);
10948#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949#ifdef FEAT_RIGHTLEFT
10950 clear_string_option(&wop->wo_rlc);
10951#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010952#ifdef FEAT_STL_OPT
10953 clear_string_option(&wop->wo_stl);
10954#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010955#ifdef FEAT_SYN_HL
10956 clear_string_option(&wop->wo_cc);
10957#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010958#ifdef FEAT_CONCEAL
10959 clear_string_option(&wop->wo_cocu);
10960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961}
10962
10963/*
10964 * Copy global option values to local options for one buffer.
10965 * Used when creating a new buffer and sometimes when entering a buffer.
10966 * flags:
10967 * BCO_ENTER We will enter the buf buffer.
10968 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10969 * appropriate.
10970 * BCO_NOHELP Don't copy the values to a help buffer.
10971 */
10972 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010973buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974{
10975 int should_copy = TRUE;
10976 char_u *save_p_isk = NULL; /* init for GCC */
10977 int dont_do_help;
10978 int did_isk = FALSE;
10979
10980 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010981 * Skip this when the option defaults have not been set yet. Happens when
10982 * main() allocates the first buffer.
10983 */
10984 if (p_cpo != NULL)
10985 {
10986 /*
10987 * Always copy when entering and 'cpo' contains 'S'.
10988 * Don't copy when already initialized.
10989 * Don't copy when 'cpo' contains 's' and not entering.
10990 * 'S' BCO_ENTER initialized 's' should_copy
10991 * yes yes X X TRUE
10992 * yes no yes X FALSE
10993 * no X yes X FALSE
10994 * X no no yes FALSE
10995 * X no no no TRUE
10996 * no yes no X TRUE
10997 */
10998 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10999 && (buf->b_p_initialized
11000 || (!(flags & BCO_ENTER)
11001 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11002 should_copy = FALSE;
11003
11004 if (should_copy || (flags & BCO_ALWAYS))
11005 {
11006 /* Don't copy the options specific to a help buffer when
11007 * BCO_NOHELP is given or the options were initialized already
11008 * (jumping back to a help file with CTRL-T or CTRL-O) */
11009 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11010 || buf->b_p_initialized;
11011 if (dont_do_help) /* don't free b_p_isk */
11012 {
11013 save_p_isk = buf->b_p_isk;
11014 buf->b_p_isk = NULL;
11015 }
11016 /*
11017 * Always free the allocated strings.
11018 * If not already initialized, set 'readonly' and copy 'fileformat'.
11019 */
11020 if (!buf->b_p_initialized)
11021 {
11022 free_buf_options(buf, TRUE);
11023 buf->b_p_ro = FALSE; /* don't copy readonly */
11024 buf->b_p_tx = p_tx;
11025#ifdef FEAT_MBYTE
11026 buf->b_p_fenc = vim_strsave(p_fenc);
11027#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011028 switch (*p_ffs)
11029 {
11030 case 'm':
11031 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11032 case 'd':
11033 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11034 case 'u':
11035 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11036 default:
11037 buf->b_p_ff = vim_strsave(p_ff);
11038 }
11039 if (buf->b_p_ff != NULL)
11040 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011041#if defined(FEAT_QUICKFIX)
11042 buf->b_p_bh = empty_option;
11043 buf->b_p_bt = empty_option;
11044#endif
11045 }
11046 else
11047 free_buf_options(buf, FALSE);
11048
11049 buf->b_p_ai = p_ai;
11050 buf->b_p_ai_nopaste = p_ai_nopaste;
11051 buf->b_p_sw = p_sw;
11052 buf->b_p_tw = p_tw;
11053 buf->b_p_tw_nopaste = p_tw_nopaste;
11054 buf->b_p_tw_nobin = p_tw_nobin;
11055 buf->b_p_wm = p_wm;
11056 buf->b_p_wm_nopaste = p_wm_nopaste;
11057 buf->b_p_wm_nobin = p_wm_nobin;
11058 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011059#ifdef FEAT_MBYTE
11060 buf->b_p_bomb = p_bomb;
11061#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011062 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063 buf->b_p_et = p_et;
11064 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011065 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011066 buf->b_p_ml = p_ml;
11067 buf->b_p_ml_nobin = p_ml_nobin;
11068 buf->b_p_inf = p_inf;
11069 buf->b_p_swf = p_swf;
11070#ifdef FEAT_INS_EXPAND
11071 buf->b_p_cpt = vim_strsave(p_cpt);
11072#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011073#ifdef FEAT_COMPL_FUNC
11074 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011075 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011076#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 buf->b_p_sts = p_sts;
11078 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080#ifdef FEAT_COMMENTS
11081 buf->b_p_com = vim_strsave(p_com);
11082#endif
11083#ifdef FEAT_FOLDING
11084 buf->b_p_cms = vim_strsave(p_cms);
11085#endif
11086 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011087 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011088 buf->b_p_nf = vim_strsave(p_nf);
11089 buf->b_p_mps = vim_strsave(p_mps);
11090#ifdef FEAT_SMARTINDENT
11091 buf->b_p_si = p_si;
11092#endif
11093 buf->b_p_ci = p_ci;
11094#ifdef FEAT_CINDENT
11095 buf->b_p_cin = p_cin;
11096 buf->b_p_cink = vim_strsave(p_cink);
11097 buf->b_p_cino = vim_strsave(p_cino);
11098#endif
11099#ifdef FEAT_AUTOCMD
11100 /* Don't copy 'filetype', it must be detected */
11101 buf->b_p_ft = empty_option;
11102#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103 buf->b_p_pi = p_pi;
11104#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11105 buf->b_p_cinw = vim_strsave(p_cinw);
11106#endif
11107#ifdef FEAT_LISP
11108 buf->b_p_lisp = p_lisp;
11109#endif
11110#ifdef FEAT_SYN_HL
11111 /* Don't copy 'syntax', it must be set */
11112 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011113 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011114 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011115#endif
11116#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011117 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011118 (void)compile_cap_prog(&buf->b_s);
11119 buf->b_s.b_p_spf = vim_strsave(p_spf);
11120 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121#endif
11122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11123 buf->b_p_inde = vim_strsave(p_inde);
11124 buf->b_p_indk = vim_strsave(p_indk);
11125#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011126 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011127#if defined(FEAT_EVAL)
11128 buf->b_p_fex = vim_strsave(p_fex);
11129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130#ifdef FEAT_CRYPT
11131 buf->b_p_key = vim_strsave(p_key);
11132#endif
11133#ifdef FEAT_SEARCHPATH
11134 buf->b_p_sua = vim_strsave(p_sua);
11135#endif
11136#ifdef FEAT_KEYMAP
11137 buf->b_p_keymap = vim_strsave(p_keymap);
11138 buf->b_kmap_state |= KEYMAP_INIT;
11139#endif
11140 /* This isn't really an option, but copying the langmap and IME
11141 * state from the current buffer is better than resetting it. */
11142 buf->b_p_iminsert = p_iminsert;
11143 buf->b_p_imsearch = p_imsearch;
11144
11145 /* options that are normally global but also have a local value
11146 * are not copied, start using the global value */
11147 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011148 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011149 buf->b_p_bkc = empty_option;
11150 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011151#ifdef FEAT_QUICKFIX
11152 buf->b_p_gp = empty_option;
11153 buf->b_p_mp = empty_option;
11154 buf->b_p_efm = empty_option;
11155#endif
11156 buf->b_p_ep = empty_option;
11157 buf->b_p_kp = empty_option;
11158 buf->b_p_path = empty_option;
11159 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011160 buf->b_p_tc = empty_option;
11161 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162#ifdef FEAT_FIND_ID
11163 buf->b_p_def = empty_option;
11164 buf->b_p_inc = empty_option;
11165# ifdef FEAT_EVAL
11166 buf->b_p_inex = vim_strsave(p_inex);
11167# endif
11168#endif
11169#ifdef FEAT_INS_EXPAND
11170 buf->b_p_dict = empty_option;
11171 buf->b_p_tsr = empty_option;
11172#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011173#ifdef FEAT_TEXTOBJ
11174 buf->b_p_qe = vim_strsave(p_qe);
11175#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011176#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11177 buf->b_p_bexpr = empty_option;
11178#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011179#if defined(FEAT_CRYPT)
11180 buf->b_p_cm = empty_option;
11181#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011182#ifdef FEAT_PERSISTENT_UNDO
11183 buf->b_p_udf = p_udf;
11184#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011185#ifdef FEAT_LISP
11186 buf->b_p_lw = empty_option;
11187#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011188#ifdef FEAT_MBYTE
11189 buf->b_p_menc = empty_option;
11190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011191
11192 /*
11193 * Don't copy the options set by ex_help(), use the saved values,
11194 * when going from a help buffer to a non-help buffer.
11195 * Don't touch these at all when BCO_NOHELP is used and going from
11196 * or to a help buffer.
11197 */
11198 if (dont_do_help)
11199 buf->b_p_isk = save_p_isk;
11200 else
11201 {
11202 buf->b_p_isk = vim_strsave(p_isk);
11203 did_isk = TRUE;
11204 buf->b_p_ts = p_ts;
11205 buf->b_help = FALSE;
11206#ifdef FEAT_QUICKFIX
11207 if (buf->b_p_bt[0] == 'h')
11208 clear_string_option(&buf->b_p_bt);
11209#endif
11210 buf->b_p_ma = p_ma;
11211 }
11212 }
11213
11214 /*
11215 * When the options should be copied (ignoring BCO_ALWAYS), set the
11216 * flag that indicates that the options have been initialized.
11217 */
11218 if (should_copy)
11219 buf->b_p_initialized = TRUE;
11220 }
11221
11222 check_buf_options(buf); /* make sure we don't have NULLs */
11223 if (did_isk)
11224 (void)buf_init_chartab(buf, FALSE);
11225}
11226
11227/*
11228 * Reset the 'modifiable' option and its default value.
11229 */
11230 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011231reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011232{
11233 int opt_idx;
11234
11235 curbuf->b_p_ma = FALSE;
11236 p_ma = FALSE;
11237 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011238 if (opt_idx >= 0)
11239 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240}
11241
11242/*
11243 * Set the global value for 'iminsert' to the local value.
11244 */
11245 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011246set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247{
11248 p_iminsert = curbuf->b_p_iminsert;
11249}
11250
11251/*
11252 * Set the global value for 'imsearch' to the local value.
11253 */
11254 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011255set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011256{
11257 p_imsearch = curbuf->b_p_imsearch;
11258}
11259
11260#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11261static int expand_option_idx = -1;
11262static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11263static int expand_option_flags = 0;
11264
11265 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011266set_context_in_set_cmd(
11267 expand_T *xp,
11268 char_u *arg,
11269 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011270{
11271 int nextchar;
11272 long_u flags = 0; /* init for GCC */
11273 int opt_idx = 0; /* init for GCC */
11274 char_u *p;
11275 char_u *s;
11276 int is_term_option = FALSE;
11277 int key;
11278
11279 expand_option_flags = opt_flags;
11280
11281 xp->xp_context = EXPAND_SETTINGS;
11282 if (*arg == NUL)
11283 {
11284 xp->xp_pattern = arg;
11285 return;
11286 }
11287 p = arg + STRLEN(arg) - 1;
11288 if (*p == ' ' && *(p - 1) != '\\')
11289 {
11290 xp->xp_pattern = p + 1;
11291 return;
11292 }
11293 while (p > arg)
11294 {
11295 s = p;
11296 /* count number of backslashes before ' ' or ',' */
11297 if (*p == ' ' || *p == ',')
11298 {
11299 while (s > arg && *(s - 1) == '\\')
11300 --s;
11301 }
11302 /* break at a space with an even number of backslashes */
11303 if (*p == ' ' && ((p - s) & 1) == 0)
11304 {
11305 ++p;
11306 break;
11307 }
11308 --p;
11309 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011310 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011311 {
11312 xp->xp_context = EXPAND_BOOL_SETTINGS;
11313 p += 2;
11314 }
11315 if (STRNCMP(p, "inv", 3) == 0)
11316 {
11317 xp->xp_context = EXPAND_BOOL_SETTINGS;
11318 p += 3;
11319 }
11320 xp->xp_pattern = arg = p;
11321 if (*arg == '<')
11322 {
11323 while (*p != '>')
11324 if (*p++ == NUL) /* expand terminal option name */
11325 return;
11326 key = get_special_key_code(arg + 1);
11327 if (key == 0) /* unknown name */
11328 {
11329 xp->xp_context = EXPAND_NOTHING;
11330 return;
11331 }
11332 nextchar = *++p;
11333 is_term_option = TRUE;
11334 expand_option_name[2] = KEY2TERMCAP0(key);
11335 expand_option_name[3] = KEY2TERMCAP1(key);
11336 }
11337 else
11338 {
11339 if (p[0] == 't' && p[1] == '_')
11340 {
11341 p += 2;
11342 if (*p != NUL)
11343 ++p;
11344 if (*p == NUL)
11345 return; /* expand option name */
11346 nextchar = *++p;
11347 is_term_option = TRUE;
11348 expand_option_name[2] = p[-2];
11349 expand_option_name[3] = p[-1];
11350 }
11351 else
11352 {
11353 /* Allow * wildcard */
11354 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11355 p++;
11356 if (*p == NUL)
11357 return;
11358 nextchar = *p;
11359 *p = NUL;
11360 opt_idx = findoption(arg);
11361 *p = nextchar;
11362 if (opt_idx == -1 || options[opt_idx].var == NULL)
11363 {
11364 xp->xp_context = EXPAND_NOTHING;
11365 return;
11366 }
11367 flags = options[opt_idx].flags;
11368 if (flags & P_BOOL)
11369 {
11370 xp->xp_context = EXPAND_NOTHING;
11371 return;
11372 }
11373 }
11374 }
11375 /* handle "-=" and "+=" */
11376 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11377 {
11378 ++p;
11379 nextchar = '=';
11380 }
11381 if ((nextchar != '=' && nextchar != ':')
11382 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11383 {
11384 xp->xp_context = EXPAND_UNSUCCESSFUL;
11385 return;
11386 }
11387 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11388 {
11389 xp->xp_context = EXPAND_OLD_SETTING;
11390 if (is_term_option)
11391 expand_option_idx = -1;
11392 else
11393 expand_option_idx = opt_idx;
11394 xp->xp_pattern = p + 1;
11395 return;
11396 }
11397 xp->xp_context = EXPAND_NOTHING;
11398 if (is_term_option || (flags & P_NUM))
11399 return;
11400
11401 xp->xp_pattern = p + 1;
11402
11403 if (flags & P_EXPAND)
11404 {
11405 p = options[opt_idx].var;
11406 if (p == (char_u *)&p_bdir
11407 || p == (char_u *)&p_dir
11408 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011409 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410 || p == (char_u *)&p_rtp
11411#ifdef FEAT_SEARCHPATH
11412 || p == (char_u *)&p_cdpath
11413#endif
11414#ifdef FEAT_SESSION
11415 || p == (char_u *)&p_vdir
11416#endif
11417 )
11418 {
11419 xp->xp_context = EXPAND_DIRECTORIES;
11420 if (p == (char_u *)&p_path
11421#ifdef FEAT_SEARCHPATH
11422 || p == (char_u *)&p_cdpath
11423#endif
11424 )
11425 xp->xp_backslash = XP_BS_THREE;
11426 else
11427 xp->xp_backslash = XP_BS_ONE;
11428 }
11429 else
11430 {
11431 xp->xp_context = EXPAND_FILES;
11432 /* for 'tags' need three backslashes for a space */
11433 if (p == (char_u *)&p_tags)
11434 xp->xp_backslash = XP_BS_THREE;
11435 else
11436 xp->xp_backslash = XP_BS_ONE;
11437 }
11438 }
11439
11440 /* For an option that is a list of file names, find the start of the
11441 * last file name. */
11442 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11443 {
11444 /* count number of backslashes before ' ' or ',' */
11445 if (*p == ' ' || *p == ',')
11446 {
11447 s = p;
11448 while (s > xp->xp_pattern && *(s - 1) == '\\')
11449 --s;
11450 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11451 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11452 {
11453 xp->xp_pattern = p + 1;
11454 break;
11455 }
11456 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011457
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011458#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011459 /* for 'spellsuggest' start at "file:" */
11460 if (options[opt_idx].var == (char_u *)&p_sps
11461 && STRNCMP(p, "file:", 5) == 0)
11462 {
11463 xp->xp_pattern = p + 5;
11464 break;
11465 }
11466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011467 }
11468
11469 return;
11470}
11471
11472 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011473ExpandSettings(
11474 expand_T *xp,
11475 regmatch_T *regmatch,
11476 int *num_file,
11477 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478{
11479 int num_normal = 0; /* Nr of matching non-term-code settings */
11480 int num_term = 0; /* Nr of matching terminal code settings */
11481 int opt_idx;
11482 int match;
11483 int count = 0;
11484 char_u *str;
11485 int loop;
11486 int is_term_opt;
11487 char_u name_buf[MAX_KEY_NAME_LEN];
11488 static char *(names[]) = {"all", "termcap"};
11489 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11490
11491 /* do this loop twice:
11492 * loop == 0: count the number of matching options
11493 * loop == 1: copy the matching options into allocated memory
11494 */
11495 for (loop = 0; loop <= 1; ++loop)
11496 {
11497 regmatch->rm_ic = ic;
11498 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11499 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011500 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11501 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011502 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11503 {
11504 if (loop == 0)
11505 num_normal++;
11506 else
11507 (*file)[count++] = vim_strsave((char_u *)names[match]);
11508 }
11509 }
11510 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11511 opt_idx++)
11512 {
11513 if (options[opt_idx].var == NULL)
11514 continue;
11515 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11516 && !(options[opt_idx].flags & P_BOOL))
11517 continue;
11518 is_term_opt = istermoption(&options[opt_idx]);
11519 if (is_term_opt && num_normal > 0)
11520 continue;
11521 match = FALSE;
11522 if (vim_regexec(regmatch, str, (colnr_T)0)
11523 || (options[opt_idx].shortname != NULL
11524 && vim_regexec(regmatch,
11525 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11526 match = TRUE;
11527 else if (is_term_opt)
11528 {
11529 name_buf[0] = '<';
11530 name_buf[1] = 't';
11531 name_buf[2] = '_';
11532 name_buf[3] = str[2];
11533 name_buf[4] = str[3];
11534 name_buf[5] = '>';
11535 name_buf[6] = NUL;
11536 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11537 {
11538 match = TRUE;
11539 str = name_buf;
11540 }
11541 }
11542 if (match)
11543 {
11544 if (loop == 0)
11545 {
11546 if (is_term_opt)
11547 num_term++;
11548 else
11549 num_normal++;
11550 }
11551 else
11552 (*file)[count++] = vim_strsave(str);
11553 }
11554 }
11555 /*
11556 * Check terminal key codes, these are not in the option table
11557 */
11558 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11559 {
11560 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11561 {
11562 if (!isprint(str[0]) || !isprint(str[1]))
11563 continue;
11564
11565 name_buf[0] = 't';
11566 name_buf[1] = '_';
11567 name_buf[2] = str[0];
11568 name_buf[3] = str[1];
11569 name_buf[4] = NUL;
11570
11571 match = FALSE;
11572 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11573 match = TRUE;
11574 else
11575 {
11576 name_buf[0] = '<';
11577 name_buf[1] = 't';
11578 name_buf[2] = '_';
11579 name_buf[3] = str[0];
11580 name_buf[4] = str[1];
11581 name_buf[5] = '>';
11582 name_buf[6] = NUL;
11583
11584 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11585 match = TRUE;
11586 }
11587 if (match)
11588 {
11589 if (loop == 0)
11590 num_term++;
11591 else
11592 (*file)[count++] = vim_strsave(name_buf);
11593 }
11594 }
11595
11596 /*
11597 * Check special key names.
11598 */
11599 regmatch->rm_ic = TRUE; /* ignore case here */
11600 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11601 {
11602 name_buf[0] = '<';
11603 STRCPY(name_buf + 1, str);
11604 STRCAT(name_buf, ">");
11605
11606 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11607 {
11608 if (loop == 0)
11609 num_term++;
11610 else
11611 (*file)[count++] = vim_strsave(name_buf);
11612 }
11613 }
11614 }
11615 if (loop == 0)
11616 {
11617 if (num_normal > 0)
11618 *num_file = num_normal;
11619 else if (num_term > 0)
11620 *num_file = num_term;
11621 else
11622 return OK;
11623 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11624 if (*file == NULL)
11625 {
11626 *file = (char_u **)"";
11627 return FAIL;
11628 }
11629 }
11630 }
11631 return OK;
11632}
11633
11634 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011635ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636{
11637 char_u *var = NULL; /* init for GCC */
11638 char_u *buf;
11639
11640 *num_file = 0;
11641 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11642 if (*file == NULL)
11643 return FAIL;
11644
11645 /*
11646 * For a terminal key code expand_option_idx is < 0.
11647 */
11648 if (expand_option_idx < 0)
11649 {
11650 var = find_termcode(expand_option_name + 2);
11651 if (var == NULL)
11652 expand_option_idx = findoption(expand_option_name);
11653 }
11654
11655 if (expand_option_idx >= 0)
11656 {
11657 /* put string of option value in NameBuff */
11658 option_value2string(&options[expand_option_idx], expand_option_flags);
11659 var = NameBuff;
11660 }
11661 else if (var == NULL)
11662 var = (char_u *)"";
11663
11664 /* A backslash is required before some characters. This is the reverse of
11665 * what happens in do_set(). */
11666 buf = vim_strsave_escaped(var, escape_chars);
11667
11668 if (buf == NULL)
11669 {
11670 vim_free(*file);
11671 *file = NULL;
11672 return FAIL;
11673 }
11674
11675#ifdef BACKSLASH_IN_FILENAME
11676 /* For MS-Windows et al. we don't double backslashes at the start and
11677 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011678 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011679 if (var[0] == '\\' && var[1] == '\\'
11680 && expand_option_idx >= 0
11681 && (options[expand_option_idx].flags & P_EXPAND)
11682 && vim_isfilec(var[2])
11683 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011684 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011685#endif
11686
11687 *file[0] = buf;
11688 *num_file = 1;
11689 return OK;
11690}
11691#endif
11692
11693/*
11694 * Get the value for the numeric or string option *opp in a nice format into
11695 * NameBuff[]. Must not be called with a hidden option!
11696 */
11697 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011698option_value2string(
11699 struct vimoption *opp,
11700 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701{
11702 char_u *varp;
11703
11704 varp = get_varp_scope(opp, opt_flags);
11705
11706 if (opp->flags & P_NUM)
11707 {
11708 long wc = 0;
11709
11710 if (wc_use_keyname(varp, &wc))
11711 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11712 else if (wc != 0)
11713 STRCPY(NameBuff, transchar((int)wc));
11714 else
11715 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11716 }
11717 else /* P_STRING */
11718 {
11719 varp = *(char_u **)(varp);
11720 if (varp == NULL) /* just in case */
11721 NameBuff[0] = NUL;
11722#ifdef FEAT_CRYPT
11723 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011724 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011725 STRCPY(NameBuff, "*****");
11726#endif
11727 else if (opp->flags & P_EXPAND)
11728 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11729 /* Translate 'pastetoggle' into special key names */
11730 else if ((char_u **)opp->var == &p_pt)
11731 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11732 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011733 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011734 }
11735}
11736
11737/*
11738 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11739 * printed as a keyname.
11740 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11741 */
11742 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011743wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011744{
11745 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11746 {
11747 *wcp = *(long *)varp;
11748 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11749 return TRUE;
11750 }
11751 return FALSE;
11752}
11753
Bram Moolenaar01615492015-02-03 13:00:38 +010011754#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011755/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011756 * Any character has an equivalent 'langmap' character. This is used for
11757 * keyboards that have a special language mode that sends characters above
11758 * 128 (although other characters can be translated too). The "to" field is a
11759 * Vim command character. This avoids having to switch the keyboard back to
11760 * ASCII mode when leaving Insert mode.
11761 *
11762 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11763 * commands.
11764 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11765 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11766 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011768# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011769/*
11770 * With multi-byte support use growarray for 'langmap' chars >= 256
11771 */
11772typedef struct
11773{
11774 int from;
11775 int to;
11776} langmap_entry_T;
11777
11778static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011779static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780
11781/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011782 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11783 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011785 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011786langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011787{
11788 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011789 int a = 0;
11790 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011791
11792 /* Do a binary search for an existing entry. */
11793 while (a != b)
11794 {
11795 int i = (a + b) / 2;
11796 int d = entries[i].from - from;
11797
11798 if (d == 0)
11799 {
11800 entries[i].to = to;
11801 return;
11802 }
11803 if (d < 0)
11804 a = i + 1;
11805 else
11806 b = i;
11807 }
11808
11809 if (ga_grow(&langmap_mapga, 1) != OK)
11810 return; /* out of memory */
11811
11812 /* insert new entry at position "a" */
11813 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11814 mch_memmove(entries + 1, entries,
11815 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11816 ++langmap_mapga.ga_len;
11817 entries[0].from = from;
11818 entries[0].to = to;
11819}
11820
11821/*
11822 * Apply 'langmap' to multi-byte character "c" and return the result.
11823 */
11824 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011825langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011826{
11827 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11828 int a = 0;
11829 int b = langmap_mapga.ga_len;
11830
11831 while (a != b)
11832 {
11833 int i = (a + b) / 2;
11834 int d = entries[i].from - c;
11835
11836 if (d == 0)
11837 return entries[i].to; /* found matching entry */
11838 if (d < 0)
11839 a = i + 1;
11840 else
11841 b = i;
11842 }
11843 return c; /* no entry found, return "c" unmodified */
11844}
11845# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011846
11847 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011848langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011849{
11850 int i;
11851
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011852 for (i = 0; i < 256; i++)
11853 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11854# ifdef FEAT_MBYTE
11855 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11856# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011857}
11858
11859/*
11860 * Called when langmap option is set; the language map can be
11861 * changed at any time!
11862 */
11863 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011864langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011865{
11866 char_u *p;
11867 char_u *p2;
11868 int from, to;
11869
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011870#ifdef FEAT_MBYTE
11871 ga_clear(&langmap_mapga); /* clear the previous map first */
11872#endif
11873 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011874
11875 for (p = p_langmap; p[0] != NUL; )
11876 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011877 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11878 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879 {
11880 if (p2[0] == '\\' && p2[1] != NUL)
11881 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011882 }
11883 if (p2[0] == ';')
11884 ++p2; /* abcd;ABCD form, p2 points to A */
11885 else
11886 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11887 while (p[0])
11888 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011889 if (p[0] == ',')
11890 {
11891 ++p;
11892 break;
11893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011894 if (p[0] == '\\' && p[1] != NUL)
11895 ++p;
11896#ifdef FEAT_MBYTE
11897 from = (*mb_ptr2char)(p);
11898#else
11899 from = p[0];
11900#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011901 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902 if (p2 == NULL)
11903 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011904 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011905 if (p[0] != ',')
11906 {
11907 if (p[0] == '\\')
11908 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011910 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011911#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011912 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011913#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915 }
11916 else
11917 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011918 if (p2[0] != ',')
11919 {
11920 if (p2[0] == '\\')
11921 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011923 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011924#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011925 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011926#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011927 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011928 }
11929 if (to == NUL)
11930 {
11931 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11932 transchar(from));
11933 return;
11934 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011935
11936#ifdef FEAT_MBYTE
11937 if (from >= 256)
11938 langmap_set_entry(from, to);
11939 else
11940#endif
11941 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942
11943 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011944 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011945 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011946 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011947 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011948 if (*p == ';')
11949 {
11950 p = p2;
11951 if (p[0] != NUL)
11952 {
11953 if (p[0] != ',')
11954 {
11955 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11956 return;
11957 }
11958 ++p;
11959 }
11960 break;
11961 }
11962 }
11963 }
11964 }
11965}
11966#endif
11967
11968/*
11969 * Return TRUE if format option 'x' is in effect.
11970 * Take care of no formatting when 'paste' is set.
11971 */
11972 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011973has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011974{
11975 if (p_paste)
11976 return FALSE;
11977 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11978}
11979
11980/*
11981 * Return TRUE if "x" is present in 'shortmess' option, or
11982 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11983 */
11984 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011985shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011986{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011987 return p_shm != NULL &&
11988 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011989 || (vim_strchr(p_shm, 'a') != NULL
11990 && vim_strchr((char_u *)SHM_A, x) != NULL));
11991}
11992
11993/*
11994 * paste_option_changed() - Called after p_paste was set or reset.
11995 */
11996 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011997paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998{
11999 static int old_p_paste = FALSE;
12000 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012001 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002#ifdef FEAT_CMDL_INFO
12003 static int save_ru = 0;
12004#endif
12005#ifdef FEAT_RIGHTLEFT
12006 static int save_ri = 0;
12007 static int save_hkmap = 0;
12008#endif
12009 buf_T *buf;
12010
12011 if (p_paste)
12012 {
12013 /*
12014 * Paste switched from off to on.
12015 * Save the current values, so they can be restored later.
12016 */
12017 if (!old_p_paste)
12018 {
12019 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012020 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021 {
12022 buf->b_p_tw_nopaste = buf->b_p_tw;
12023 buf->b_p_wm_nopaste = buf->b_p_wm;
12024 buf->b_p_sts_nopaste = buf->b_p_sts;
12025 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012026 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012027 }
12028
12029 /* save global options */
12030 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012031 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012032#ifdef FEAT_CMDL_INFO
12033 save_ru = p_ru;
12034#endif
12035#ifdef FEAT_RIGHTLEFT
12036 save_ri = p_ri;
12037 save_hkmap = p_hkmap;
12038#endif
12039 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012040 p_ai_nopaste = p_ai;
12041 p_et_nopaste = p_et;
12042 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012043 p_tw_nopaste = p_tw;
12044 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045 }
12046
12047 /*
12048 * Always set the option values, also when 'paste' is set when it is
12049 * already on.
12050 */
12051 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012052 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012053 {
12054 buf->b_p_tw = 0; /* textwidth is 0 */
12055 buf->b_p_wm = 0; /* wrapmargin is 0 */
12056 buf->b_p_sts = 0; /* softtabstop is 0 */
12057 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012058 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059 }
12060
12061 /* set global options */
12062 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012063 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012064#ifdef FEAT_CMDL_INFO
12065# ifdef FEAT_WINDOWS
12066 if (p_ru)
12067 status_redraw_all(); /* redraw to remove the ruler */
12068# endif
12069 p_ru = 0; /* no ruler */
12070#endif
12071#ifdef FEAT_RIGHTLEFT
12072 p_ri = 0; /* no reverse insert */
12073 p_hkmap = 0; /* no Hebrew keyboard */
12074#endif
12075 /* set global values for local buffer options */
12076 p_tw = 0;
12077 p_wm = 0;
12078 p_sts = 0;
12079 p_ai = 0;
12080 }
12081
12082 /*
12083 * Paste switched from on to off: Restore saved values.
12084 */
12085 else if (old_p_paste)
12086 {
12087 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012088 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012089 {
12090 buf->b_p_tw = buf->b_p_tw_nopaste;
12091 buf->b_p_wm = buf->b_p_wm_nopaste;
12092 buf->b_p_sts = buf->b_p_sts_nopaste;
12093 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012094 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 }
12096
12097 /* restore global options */
12098 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012099 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100#ifdef FEAT_CMDL_INFO
12101# ifdef FEAT_WINDOWS
12102 if (p_ru != save_ru)
12103 status_redraw_all(); /* redraw to draw the ruler */
12104# endif
12105 p_ru = save_ru;
12106#endif
12107#ifdef FEAT_RIGHTLEFT
12108 p_ri = save_ri;
12109 p_hkmap = save_hkmap;
12110#endif
12111 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012112 p_ai = p_ai_nopaste;
12113 p_et = p_et_nopaste;
12114 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115 p_tw = p_tw_nopaste;
12116 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012117 }
12118
12119 old_p_paste = p_paste;
12120}
12121
12122/*
12123 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12124 *
12125 * Reset 'compatible' and set the values for options that didn't get set yet
12126 * to the Vim defaults.
12127 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012128 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129 */
12130 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012131vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012132{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012133 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012134 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012135 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136
12137 if (!option_was_set((char_u *)"cp"))
12138 {
12139 p_cp = FALSE;
12140 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12141 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12142 set_option_default(opt_idx, OPT_FREE, FALSE);
12143 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012144 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012145 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012146
12147 if (fname != NULL)
12148 {
12149 p = vim_getenv(envname, &dofree);
12150 if (p == NULL)
12151 {
12152 /* Set $MYVIMRC to the first vimrc file found. */
12153 p = FullName_save(fname, FALSE);
12154 if (p != NULL)
12155 {
12156 vim_setenv(envname, p);
12157 vim_free(p);
12158 }
12159 }
12160 else if (dofree)
12161 vim_free(p);
12162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163}
12164
12165/*
12166 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12167 */
12168 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012169change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012171 int opt_idx;
12172
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173 if (p_cp != on)
12174 {
12175 p_cp = on;
12176 compatible_set();
12177 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012178 opt_idx = findoption((char_u *)"cp");
12179 if (opt_idx >= 0)
12180 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012181}
12182
12183/*
12184 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012185 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186 */
12187 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012188option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189{
12190 int idx;
12191
12192 idx = findoption(name);
12193 if (idx < 0) /* unknown option */
12194 return FALSE;
12195 if (options[idx].flags & P_WAS_SET)
12196 return TRUE;
12197 return FALSE;
12198}
12199
12200/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012201 * Reset the flag indicating option "name" was set.
12202 */
12203 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012204reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012205{
12206 int idx = findoption(name);
12207
12208 if (idx >= 0)
12209 options[idx].flags &= ~P_WAS_SET;
12210}
12211
12212/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213 * compatible_set() - Called when 'compatible' has been set or unset.
12214 *
12215 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12216 * flag) to a Vi compatible value.
12217 * When 'compatible' is unset: Set all options that have a different default
12218 * for Vim (without the P_VI_DEF flag) to that default.
12219 */
12220 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012221compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012222{
12223 int opt_idx;
12224
12225 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12226 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12227 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12228 set_option_default(opt_idx, OPT_FREE, p_cp);
12229 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012230 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012231}
12232
12233#ifdef FEAT_LINEBREAK
12234
12235# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12236 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012237 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012238# endif
12239
12240/*
12241 * fill_breakat_flags() -- called when 'breakat' changes value.
12242 */
12243 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012244fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012245{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012246 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012247 int i;
12248
12249 for (i = 0; i < 256; i++)
12250 breakat_flags[i] = FALSE;
12251
12252 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012253 for (p = p_breakat; *p; p++)
12254 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012255}
12256
12257# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012258 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259# endif
12260
12261#endif
12262
12263/*
12264 * Check an option that can be a range of string values.
12265 *
12266 * Return OK for correct value, FAIL otherwise.
12267 * Empty is always OK.
12268 */
12269 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012270check_opt_strings(
12271 char_u *val,
12272 char **values,
12273 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274{
12275 return opt_strings_flags(val, values, NULL, list);
12276}
12277
12278/*
12279 * Handle an option that can be a range of string values.
12280 * Set a flag in "*flagp" for each string present.
12281 *
12282 * Return OK for correct value, FAIL otherwise.
12283 * Empty is always OK.
12284 */
12285 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012286opt_strings_flags(
12287 char_u *val, /* new value */
12288 char **values, /* array of valid string values */
12289 unsigned *flagp,
12290 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012291{
12292 int i;
12293 int len;
12294 unsigned new_flags = 0;
12295
12296 while (*val)
12297 {
12298 for (i = 0; ; ++i)
12299 {
12300 if (values[i] == NULL) /* val not found in values[] */
12301 return FAIL;
12302
12303 len = (int)STRLEN(values[i]);
12304 if (STRNCMP(values[i], val, len) == 0
12305 && ((list && val[len] == ',') || val[len] == NUL))
12306 {
12307 val += len + (val[len] == ',');
12308 new_flags |= (1 << i);
12309 break; /* check next item in val list */
12310 }
12311 }
12312 }
12313 if (flagp != NULL)
12314 *flagp = new_flags;
12315
12316 return OK;
12317}
12318
12319/*
12320 * Read the 'wildmode' option, fill wim_flags[].
12321 */
12322 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012323check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012324{
12325 char_u new_wim_flags[4];
12326 char_u *p;
12327 int i;
12328 int idx = 0;
12329
12330 for (i = 0; i < 4; ++i)
12331 new_wim_flags[i] = 0;
12332
12333 for (p = p_wim; *p; ++p)
12334 {
12335 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12336 ;
12337 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12338 return FAIL;
12339 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12340 new_wim_flags[idx] |= WIM_LONGEST;
12341 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12342 new_wim_flags[idx] |= WIM_FULL;
12343 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12344 new_wim_flags[idx] |= WIM_LIST;
12345 else
12346 return FAIL;
12347 p += i;
12348 if (*p == NUL)
12349 break;
12350 if (*p == ',')
12351 {
12352 if (idx == 3)
12353 return FAIL;
12354 ++idx;
12355 }
12356 }
12357
12358 /* fill remaining entries with last flag */
12359 while (idx < 3)
12360 {
12361 new_wim_flags[idx + 1] = new_wim_flags[idx];
12362 ++idx;
12363 }
12364
12365 /* only when there are no errors, wim_flags[] is changed */
12366 for (i = 0; i < 4; ++i)
12367 wim_flags[i] = new_wim_flags[i];
12368 return OK;
12369}
12370
12371/*
12372 * Check if backspacing over something is allowed.
12373 */
12374 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012375can_bs(
12376 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012377{
12378 switch (*p_bs)
12379 {
12380 case '2': return TRUE;
12381 case '1': return (what != BS_START);
12382 case '0': return FALSE;
12383 }
12384 return vim_strchr(p_bs, what) != NULL;
12385}
12386
12387/*
12388 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12389 * the file must be considered changed when the value is different.
12390 */
12391 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012392save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012393{
12394 buf->b_start_ffc = *buf->b_p_ff;
12395 buf->b_start_eol = buf->b_p_eol;
12396#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012397 buf->b_start_bomb = buf->b_p_bomb;
12398
Bram Moolenaar071d4272004-06-13 20:20:40 +000012399 /* Only use free/alloc when necessary, they take time. */
12400 if (buf->b_start_fenc == NULL
12401 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12402 {
12403 vim_free(buf->b_start_fenc);
12404 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12405 }
12406#endif
12407}
12408
12409/*
12410 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12411 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012412 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12413 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012414 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012415 * When "ignore_empty" is true don't consider a new, empty buffer to be
12416 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012417 */
12418 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012419file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012420{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012421 /* In a buffer that was never loaded the options are not valid. */
12422 if (buf->b_flags & BF_NEVERLOADED)
12423 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012424 if (ignore_empty
12425 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012426 && buf->b_ml.ml_line_count == 1
12427 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12428 return FALSE;
12429 if (buf->b_start_ffc != *buf->b_p_ff)
12430 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012431 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012432 return TRUE;
12433#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012434 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12435 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012436 if (buf->b_start_fenc == NULL)
12437 return (*buf->b_p_fenc != NUL);
12438 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12439#else
12440 return FALSE;
12441#endif
12442}
12443
12444/*
12445 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12446 */
12447 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012448check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012449{
12450 return check_opt_strings(p, p_ff_values, FALSE);
12451}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012452
12453/*
12454 * Return the effective shiftwidth value for current buffer, using the
12455 * 'tabstop' value when 'shiftwidth' is zero.
12456 */
12457 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012458get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012459{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012460 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012461}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012462
12463/*
12464 * Return the effective softtabstop value for the current buffer, using the
12465 * 'tabstop' value when 'softtabstop' is negative.
12466 */
12467 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012468get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012469{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012470 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012471}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012472
12473/*
12474 * Check matchpairs option for "*initc".
12475 * If there is a match set "*initc" to the matching character and "*findc" to
12476 * the opposite character. Set "*backwards" to the direction.
12477 * When "switchit" is TRUE swap the direction.
12478 */
12479 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012480find_mps_values(
12481 int *initc,
12482 int *findc,
12483 int *backwards,
12484 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012485{
12486 char_u *ptr;
12487
12488 ptr = curbuf->b_p_mps;
12489 while (*ptr != NUL)
12490 {
12491#ifdef FEAT_MBYTE
12492 if (has_mbyte)
12493 {
12494 char_u *prev;
12495
12496 if (mb_ptr2char(ptr) == *initc)
12497 {
12498 if (switchit)
12499 {
12500 *findc = *initc;
12501 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12502 *backwards = TRUE;
12503 }
12504 else
12505 {
12506 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12507 *backwards = FALSE;
12508 }
12509 return;
12510 }
12511 prev = ptr;
12512 ptr += mb_ptr2len(ptr) + 1;
12513 if (mb_ptr2char(ptr) == *initc)
12514 {
12515 if (switchit)
12516 {
12517 *findc = *initc;
12518 *initc = mb_ptr2char(prev);
12519 *backwards = FALSE;
12520 }
12521 else
12522 {
12523 *findc = mb_ptr2char(prev);
12524 *backwards = TRUE;
12525 }
12526 return;
12527 }
12528 ptr += mb_ptr2len(ptr);
12529 }
12530 else
12531#endif
12532 {
12533 if (*ptr == *initc)
12534 {
12535 if (switchit)
12536 {
12537 *backwards = TRUE;
12538 *findc = *initc;
12539 *initc = ptr[2];
12540 }
12541 else
12542 {
12543 *backwards = FALSE;
12544 *findc = ptr[2];
12545 }
12546 return;
12547 }
12548 ptr += 2;
12549 if (*ptr == *initc)
12550 {
12551 if (switchit)
12552 {
12553 *backwards = FALSE;
12554 *findc = *initc;
12555 *initc = ptr[-2];
12556 }
12557 else
12558 {
12559 *backwards = TRUE;
12560 *findc = ptr[-2];
12561 }
12562 return;
12563 }
12564 ++ptr;
12565 }
12566 if (*ptr == ',')
12567 ++ptr;
12568 }
12569}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012570
12571#if defined(FEAT_LINEBREAK) || defined(PROTO)
12572/*
12573 * This is called when 'breakindentopt' is changed and when a window is
12574 * initialized.
12575 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012576 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012577briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012578{
12579 char_u *p;
12580 int bri_shift = 0;
12581 long bri_min = 20;
12582 int bri_sbr = FALSE;
12583
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012584 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012585 while (*p != NUL)
12586 {
12587 if (STRNCMP(p, "shift:", 6) == 0
12588 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12589 {
12590 p += 6;
12591 bri_shift = getdigits(&p);
12592 }
12593 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12594 {
12595 p += 4;
12596 bri_min = getdigits(&p);
12597 }
12598 else if (STRNCMP(p, "sbr", 3) == 0)
12599 {
12600 p += 3;
12601 bri_sbr = TRUE;
12602 }
12603 if (*p != ',' && *p != NUL)
12604 return FAIL;
12605 if (*p == ',')
12606 ++p;
12607 }
12608
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012609 wp->w_p_brishift = bri_shift;
12610 wp->w_p_brimin = bri_min;
12611 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012612
12613 return OK;
12614}
12615#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012616
12617/*
12618 * Get the local or global value of 'backupcopy'.
12619 */
12620 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012621get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012622{
12623 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12624}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012625
12626#if defined(FEAT_SIGNS) || defined(PROTO)
12627/*
12628 * Return TRUE when window "wp" has a column to draw signs in.
12629 */
12630 int
12631signcolumn_on(win_T *wp)
12632{
12633 if (*wp->w_p_scl == 'n')
12634 return FALSE;
12635 if (*wp->w_p_scl == 'y')
12636 return TRUE;
12637 return (wp->w_buffer->b_signlist != NULL
12638# ifdef FEAT_NETBEANS_INTG
12639 || wp->w_buffer->b_has_sign_column
12640# endif
12641 );
12642}
12643#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012644
12645#if defined(FEAT_EVAL) || defined(PROTO)
12646/*
12647 * Get window or buffer local options.
12648 */
12649 dict_T *
12650get_winbuf_options(int bufopt)
12651{
12652 dict_T *d;
12653 int opt_idx;
12654
12655 d = dict_alloc();
12656 if (d == NULL)
12657 return NULL;
12658
12659 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12660 {
12661 struct vimoption *opt = &options[opt_idx];
12662
12663 if ((bufopt && (opt->indir & PV_BUF))
12664 || (!bufopt && (opt->indir & PV_WIN)))
12665 {
12666 char_u *varp = get_varp(opt);
12667
12668 if (varp != NULL)
12669 {
12670 if (opt->flags & P_STRING)
12671 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012672 else if (opt->flags & P_NUM)
12673 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012674 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012675 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012676 }
12677 }
12678 }
12679
12680 return d;
12681}
12682#endif